|
|
@ -1,8 +1,11 @@ |
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|
|
|
import com.epmet.commons.feignclient.dtos.form.JiMuReportFormDTO; |
|
|
|
import com.epmet.commons.feignclient.dtos.result.JiMuReportResultDTO; |
|
|
|
import com.epmet.commons.feignclient.feigns.JiMuReportOpenFeignClient; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
@ -12,6 +15,8 @@ import com.epmet.commons.tools.dto.result.DictListResultDTO; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.EpmetRequestHolder; |
|
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constant.CustomerFunctionConstant; |
|
|
|
import com.epmet.dao.IcCustomerReportDao; |
|
|
@ -27,16 +32,15 @@ import com.epmet.feign.EpmetAdminOpenFeignClient; |
|
|
|
import com.epmet.feign.OperCrmOpenFeignClient; |
|
|
|
import com.epmet.service.IcCustomerReportService; |
|
|
|
import com.epmet.service.IcReportFunService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.net.InetAddress; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -46,6 +50,7 @@ import java.util.stream.Collectors; |
|
|
|
* @since v1.0.0 2022-08-08 |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerReportDao, IcCustomerReportEntity> implements IcCustomerReportService { |
|
|
|
@Autowired |
|
|
|
private RedisUtils redisUtils; |
|
|
@ -56,6 +61,8 @@ public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerRepor |
|
|
|
private OperCrmOpenFeignClient operCrmOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private IcReportFunService reportFunService; |
|
|
|
@Autowired |
|
|
|
private JiMuReportOpenFeignClient jiMuReportOpenFeignClient; |
|
|
|
|
|
|
|
|
|
|
|
private QueryWrapper<IcCustomerReportEntity> getWrapper(Map<String, Object> params){ |
|
|
@ -75,10 +82,30 @@ public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerRepor |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<ReportResultDTO> reportList() { |
|
|
|
List<ReportResultDTO> reportList = baseDao.reportList(); |
|
|
|
if (CollectionUtils.isEmpty(reportList)){ |
|
|
|
Result<String> list = jiMuReportOpenFeignClient.getList(1,10000,"datainfo", EpmetRequestHolder.getHeader("Authorization")); |
|
|
|
Result<String> url = getUrl(2, null); |
|
|
|
log.info(url.toString()); |
|
|
|
Map<String,Object> map = JSON.parseObject(url.getData(), Map.class); |
|
|
|
Map<String,Object> map2 = (Map<String,Object>)map.get("result"); |
|
|
|
List<Map<String,Object>> map3 = (List<Map<String,Object>>) map2.get("records"); |
|
|
|
List<JiMuReportResultDTO> allReports = new ArrayList<>(); |
|
|
|
map3.forEach(m -> { |
|
|
|
allReports.add(ConvertUtils.mapToEntity(m,JiMuReportResultDTO.class)); |
|
|
|
}); |
|
|
|
if (CollectionUtils.isEmpty(allReports)){ |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
List<ReportResultDTO> allReportList = new ArrayList<>(); |
|
|
|
allReports.forEach(r -> { |
|
|
|
ReportResultDTO dto = new ReportResultDTO(); |
|
|
|
dto.setReportId(r.getId()); |
|
|
|
dto.setReportName(r.getName()); |
|
|
|
allReportList.add(dto); |
|
|
|
}); |
|
|
|
List<ReportResultDTO> reportList = baseDao.reportList(null); |
|
|
|
if (CollectionUtils.isEmpty(reportList)){ |
|
|
|
return allReportList; |
|
|
|
} |
|
|
|
Result<List<DictListResultDTO>> dictList = adminOpenFeignClient.dictList(new DictListFormDTO(CustomerFunctionConstant.REPORT_CATEGORY)); |
|
|
|
if (!dictList.success()){ |
|
|
|
throw new EpmetException("查询字典信息失败:" + CustomerFunctionConstant.REPORT_CATEGORY); |
|
|
@ -93,17 +120,9 @@ public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerRepor |
|
|
|
if (CollectionUtils.isNotEmpty(allCustomerList.getData())){ |
|
|
|
allCustomerList.getData().forEach(c -> reportList.stream().filter(r -> c.getId().equals(r.getCustomerId())).forEach(r -> r.setCustomerName(c.getCustomerName()))); |
|
|
|
} |
|
|
|
// todo 报表
|
|
|
|
List<ReportResultDTO> result = new ArrayList<>(); |
|
|
|
Map<String, List<ReportResultDTO>> groupByReport = reportList.stream().collect(Collectors.groupingBy(ReportResultDTO::getReportId)); |
|
|
|
groupByReport.forEach((reportId,l) -> { |
|
|
|
ReportResultDTO dto = new ReportResultDTO(); |
|
|
|
dto.setReportId(reportId); |
|
|
|
dto.setReportName(l.get(NumConstant.ZERO).getReportName()); |
|
|
|
dto.setCustomerList(ConvertUtils.sourceToTarget(l, ReportResultDTO.CustomerList.class)); |
|
|
|
result.add(dto); |
|
|
|
}); |
|
|
|
return result; |
|
|
|
groupByReport.forEach((reportId,l) -> allReportList.stream().filter(a -> a.getReportId().equals(reportId)).forEach(a -> a.setCustomerList(ConvertUtils.sourceToTarget(l, ReportResultDTO.CustomerList.class)))); |
|
|
|
return allReportList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -173,7 +192,25 @@ public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerRepor |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<JiMuReportResultDTO> reportIdAndName(ReportListFormDTO formDTO) { |
|
|
|
return null; |
|
|
|
List<ReportResultDTO> reportList = baseDao.reportList(formDTO.getCategoryKeys()); |
|
|
|
if (CollectionUtils.isEmpty(reportList)){ |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
List<String> recordIds = reportList.stream().map(m -> m.getReportId()).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList()); |
|
|
|
List<JiMuReportResultDTO> result = new ArrayList<>(); |
|
|
|
recordIds.forEach(r -> { |
|
|
|
JiMuReportFormDTO form = new JiMuReportFormDTO(); |
|
|
|
form.setId(r); |
|
|
|
// Result<String> url = getUrl(NumConstant.ONE, r);
|
|
|
|
// if (!report.success()){
|
|
|
|
// throw new EpmetException("查询报表失败:"+r);
|
|
|
|
// }
|
|
|
|
// JiMuReportResultDTO data = report.getData();
|
|
|
|
// data.setReportId(data.getId());
|
|
|
|
// data.setReportName(data.getReportName());
|
|
|
|
// result.add(data);
|
|
|
|
}); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@ -186,4 +223,46 @@ public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerRepor |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Desc: |
|
|
|
* @param type 1:代表根据ID查询;2查询全部 |
|
|
|
* @author zxc |
|
|
|
* @date 2022/8/9 10:14 |
|
|
|
*/ |
|
|
|
public Result<String> getUrl(Integer type,String id) { |
|
|
|
String add = ""; |
|
|
|
Result<String> result; |
|
|
|
try { |
|
|
|
InetAddress localHost = InetAddress.getLocalHost(); |
|
|
|
// add = localHost.getHostAddress();
|
|
|
|
add = "http://192.168.1.141:8118"; |
|
|
|
System.out.println(add); |
|
|
|
}catch (Exception e){ |
|
|
|
log.warn("获取url失败"); |
|
|
|
} |
|
|
|
if (type.compareTo(NumConstant.TWO) == NumConstant.ZERO){ |
|
|
|
add = add.concat("/jmreport/excelQuery"); |
|
|
|
Map<String,Object> params = new HashMap<>(16); |
|
|
|
params.put("pageNo",1); |
|
|
|
params.put("pageSize",10000); |
|
|
|
params.put("reportType","datainfo"); |
|
|
|
params.put("name",""); |
|
|
|
params.put("token", EpmetRequestHolder.getHeader("Authorization")); |
|
|
|
Map<String,Object> headers = new HashMap<>(16); |
|
|
|
headers.put("token", EpmetRequestHolder.getHeader("Authorization")); |
|
|
|
headers.put("X-Access-Token", EpmetRequestHolder.getHeader("Authorization")); |
|
|
|
headers.put("Accept", "application/json, text/plain, */*"); |
|
|
|
headers.put("Content-Type", "application/json;charset=utf-8"); |
|
|
|
result = HttpClientManager.getInstance().sendGet(add, params, headers); |
|
|
|
}else { |
|
|
|
add.concat("/jmreport/show"); |
|
|
|
Map<String,Object> params = new HashMap<>(16); |
|
|
|
params.put("id",id); |
|
|
|
Map<String,String> headers = new HashMap<>(16); |
|
|
|
headers.put("token", EpmetRequestHolder.getHeader("Authorization")); |
|
|
|
result = HttpClientManager.getInstance().sendPostAndHeader(add, params, headers); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
} |