|
|
@ -1,6 +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; |
|
|
@ -10,27 +15,32 @@ 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; |
|
|
|
import com.epmet.dto.CustomerDTO; |
|
|
|
import com.epmet.dto.form.PreviewReportFormDTO; |
|
|
|
import com.epmet.dto.result.PreviewReportResDTO; |
|
|
|
import com.epmet.dto.IcCustomerReportDTO; |
|
|
|
import com.epmet.dto.form.ReportEditFormDTO; |
|
|
|
import com.epmet.dto.form.ReportListFormDTO; |
|
|
|
import com.epmet.dto.result.PreviewReportResDTO; |
|
|
|
import com.epmet.dto.result.ReportResultDTO; |
|
|
|
import com.epmet.entity.IcCustomerReportEntity; |
|
|
|
import com.epmet.entity.IcReportFunEntity; |
|
|
|
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.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.net.InetAddress; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -40,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; |
|
|
@ -48,6 +59,10 @@ public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerRepor |
|
|
|
private EpmetAdminOpenFeignClient adminOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private OperCrmOpenFeignClient operCrmOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private IcReportFunService reportFunService; |
|
|
|
@Autowired |
|
|
|
private JiMuReportOpenFeignClient jiMuReportOpenFeignClient; |
|
|
|
|
|
|
|
|
|
|
|
private QueryWrapper<IcCustomerReportEntity> getWrapper(Map<String, Object> params){ |
|
|
@ -67,10 +82,33 @@ 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("所有jm报表"+url); |
|
|
|
Map<String,Object> map = JSON.parseObject(url.getData(), Map.class); |
|
|
|
if (!map.containsValue(true)){ |
|
|
|
throw new EpmetException("获取所有jm报表失败"); |
|
|
|
} |
|
|
|
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,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); |
|
|
@ -85,17 +123,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; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -111,6 +141,7 @@ public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerRepor |
|
|
|
reportResDTO.setReportId(formDTO.getReportId()); |
|
|
|
String key = formDTO.getCustomerId().concat(StrConstant.COLON).concat(formDTO.getReportId()).concat(StrConstant.COLON).concat(formDTO.getCategoryKey()).concat(StrConstant.COLON).concat(formDTO.getStaffId()); |
|
|
|
redisUtils.hMSet(key, formDTO.getParamMap(), RedisUtils.DEFAULT_EXPIRE); |
|
|
|
reportResDTO.setParamKey(key); |
|
|
|
return reportResDTO; |
|
|
|
} |
|
|
|
|
|
|
@ -123,7 +154,125 @@ public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerRepor |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Override |
|
|
|
public void reportEdit(ReportEditFormDTO formDTO) { |
|
|
|
List<String> reportIds = new ArrayList<>(); |
|
|
|
if (CollectionUtils.isNotEmpty(formDTO.getCustomerList())){ |
|
|
|
reportIds = baseDao.getIdsByCustomer(formDTO.getCustomerList().stream().map(m -> m.getCustomerId()).collect(Collectors.toList()), formDTO.getReportId()); |
|
|
|
} |
|
|
|
if (formDTO.getType().equals(CustomerFunctionConstant.REPORT_EDIT)){ |
|
|
|
// 单个编辑
|
|
|
|
baseDao.delCustomerReport(Arrays.asList(formDTO.getCustomerList().get(NumConstant.ZERO).getCustomerId())); |
|
|
|
}else if (formDTO.getType().equals(CustomerFunctionConstant.REPORT_ADD)){ |
|
|
|
baseDao.delCustomerReport(null); |
|
|
|
} |
|
|
|
baseDao.delCustomerReportFun(reportIds); |
|
|
|
if (CollectionUtils.isNotEmpty(formDTO.getCustomerList())){ |
|
|
|
List<IcCustomerReportEntity> entities = new ArrayList<>(); |
|
|
|
List<IcReportFunEntity> funEntities = new ArrayList<>(); |
|
|
|
formDTO.getCustomerList().forEach(c -> { |
|
|
|
IcCustomerReportEntity reportEntity = new IcCustomerReportEntity(); |
|
|
|
reportEntity.setReportId(formDTO.getReportId()); |
|
|
|
reportEntity.setCustomerId(c.getCustomerId()); |
|
|
|
reportEntity.setId(IdWorker.getIdStr()); |
|
|
|
if (CollectionUtils.isNotEmpty(c.getCategoryKeys())){ |
|
|
|
c.getCategoryKeys().forEach(key -> { |
|
|
|
IcReportFunEntity funEntity = new IcReportFunEntity(); |
|
|
|
funEntity.setCustomerReportId(reportEntity.getId()); |
|
|
|
funEntity.setFunCategoryKey(key); |
|
|
|
funEntities.add(funEntity); |
|
|
|
}); |
|
|
|
} |
|
|
|
entities.add(reportEntity); |
|
|
|
}); |
|
|
|
insetCustomerReportAndFun(entities,funEntities); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Desc: 居民信息/房屋信息-查询报表 |
|
|
|
* @param formDTO |
|
|
|
* @author zxc |
|
|
|
* @date 2022/8/8 15:20 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<JiMuReportResultDTO> reportIdAndName(ReportListFormDTO formDTO) { |
|
|
|
List<ReportResultDTO> reportList = baseDao.reportList(formDTO.getCategoryKeys(), formDTO.getCustomerId()); |
|
|
|
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); |
|
|
|
log.info("模板详情"+url); |
|
|
|
Map<String,Object> map = JSON.parseObject(url.getData(), Map.class); |
|
|
|
if (!map.containsValue(true)){ |
|
|
|
throw new EpmetException("获取jm报表详情失败:"+r); |
|
|
|
} |
|
|
|
Map<String,Object> map2 = (Map<String,Object>)map.get("result"); |
|
|
|
JiMuReportResultDTO data = ConvertUtils.mapToEntity(map2, JiMuReportResultDTO.class); |
|
|
|
data.setReportId(data.getId()); |
|
|
|
data.setReportName(data.getName()); |
|
|
|
result.add(data); |
|
|
|
}); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void insetCustomerReportAndFun(List<IcCustomerReportEntity> reportEntities,List<IcReportFunEntity> funEntities){ |
|
|
|
if (CollectionUtils.isNotEmpty(reportEntities)){ |
|
|
|
insertBatch(reportEntities); |
|
|
|
} |
|
|
|
if (CollectionUtils.isNotEmpty(funEntities)){ |
|
|
|
reportFunService.insertBatch(funEntities); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 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 = "http://"+localHost.getHostAddress()+":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 = add.concat("/jmreport/show"); |
|
|
|
Map<String,Object> params = new HashMap<>(16); |
|
|
|
params.put("id",id); |
|
|
|
params.put("apiUrl",""); |
|
|
|
params.put("params",""); |
|
|
|
Map<String,String> 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().sendPostByJSONAndHeader(add, JSON.toJSONString(params), headers); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
} |