|  |  | @ -2,19 +2,33 @@ package com.epmet.service.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.AppClientConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.FieldConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.ServiceConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.EpmetErrorCode; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.EpmetException; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.feign.ResultDataResolver; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.dto.form.FileCommonDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.enums.DictTypeEnum; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.page.PageData; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.redis.common.CustomerOrgRedis; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.redis.common.bean.GridInfoCache; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.ConvertUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.EpmetRequestHolder; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.Result; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.IcEventDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.CustomerAgencyDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.IcEventDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.AgencyInfoFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.IcEventListFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.AllGridsByUserIdResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.IcEventListResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.IcMoveInListResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.IcEventEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.enums.EcEventProcessStatusEnum; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.EpmetAdminOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.GovOrgOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.EpmetAdminOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.GovOrgOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.IcEventService; | 
			
		
	
	
		
			
				
					|  |  | @ -27,6 +41,11 @@ import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.util.CollectionUtils; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import java.math.BigDecimal; | 
			
		
	
		
			
				
					|  |  |  | import java.util.Arrays; | 
			
		
	
		
			
				
					|  |  |  | import java.util.Date; | 
			
		
	
		
			
				
					|  |  |  | import java.util.List; | 
			
		
	
		
			
				
					|  |  |  | import java.util.Map; | 
			
		
	
		
			
				
					|  |  |  | import java.util.*; | 
			
		
	
		
			
				
					|  |  |  | import java.util.stream.Collectors; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -37,13 +56,14 @@ import java.util.stream.Collectors; | 
			
		
	
		
			
				
					|  |  |  |  * @since v1.0.0 2022-05-17 | 
			
		
	
		
			
				
					|  |  |  |  */ | 
			
		
	
		
			
				
					|  |  |  | @Service | 
			
		
	
		
			
				
					|  |  |  | public class IcEventServiceImpl extends BaseServiceImpl<IcEventDao, IcEventEntity> implements IcEventService { | 
			
		
	
		
			
				
					|  |  |  | public class IcEventServiceImpl extends BaseServiceImpl<IcEventDao, IcEventEntity> implements IcEventService, ResultDataResolver { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private GovOrgOpenFeignClient govOrgOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private EpmetAdminOpenFeignClient adminOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public PageData<IcEventListResultDTO> list(IcEventListFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize(), formDTO.getIsPage()); | 
			
		
	
	
		
			
				
					|  |  | @ -121,4 +141,120 @@ public class IcEventServiceImpl extends BaseServiceImpl<IcEventDao, IcEventEntit | 
			
		
	
		
			
				
					|  |  |  |         baseDao.deleteBatchIds(Arrays.asList(ids)); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 查询时间的grid_pids | 
			
		
	
		
			
				
					|  |  |  |      * @param agencyId | 
			
		
	
		
			
				
					|  |  |  |      * @return | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     public String getEventGridPids(String agencyId) { | 
			
		
	
		
			
				
					|  |  |  |         String gridPids; | 
			
		
	
		
			
				
					|  |  |  |         String errorMsg = "查询组织信息失败"; | 
			
		
	
		
			
				
					|  |  |  |         CustomerAgencyDTO agencyInfo = getResultDataOrThrowsException(govOrgOpenFeignClient.getAgencyById(agencyId), | 
			
		
	
		
			
				
					|  |  |  |                 ServiceConstant.GOV_ORG_SERVER, | 
			
		
	
		
			
				
					|  |  |  |                 EpmetErrorCode.SERVER_ERROR.getCode(), | 
			
		
	
		
			
				
					|  |  |  |                 errorMsg, | 
			
		
	
		
			
				
					|  |  |  |                 errorMsg); | 
			
		
	
		
			
				
					|  |  |  |         if (agencyInfo == null) { | 
			
		
	
		
			
				
					|  |  |  |             throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "组织信息未找到", "网格信息未找到"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         String purePids = agencyInfo.getPids(); | 
			
		
	
		
			
				
					|  |  |  |         if ("0".equals(purePids) || StringUtils.isBlank(purePids)) { | 
			
		
	
		
			
				
					|  |  |  |             gridPids = agencyInfo.getId(); | 
			
		
	
		
			
				
					|  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |             gridPids = purePids.concat(":").concat(agencyInfo.getId()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return gridPids; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public ProcessStatusRatioResultDTO getProcessStatusRatio(String orgId, String orgType, Date queryStartTime, Date queryEndTime) { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         AgencyInfoFormDTO form = new AgencyInfoFormDTO(); | 
			
		
	
		
			
				
					|  |  |  |         form.setOrgId(orgId); | 
			
		
	
		
			
				
					|  |  |  |         form.setOrgType(orgType); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         String gridPids = null; | 
			
		
	
		
			
				
					|  |  |  |         if ("agency".equals(orgType)) { | 
			
		
	
		
			
				
					|  |  |  |             gridPids = getEventGridPids(orgId); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         List<Map<String, Long>> m = baseDao.getProcessStatusRatio( | 
			
		
	
		
			
				
					|  |  |  |                 EpmetRequestHolder.getHeader(AppClientConstant.CUSTOMER_ID), orgType, orgId, gridPids, queryStartTime, queryEndTime); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         ProcessStatusRatioResultDTO r = new ProcessStatusRatioResultDTO(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         BigDecimal processingCount = new BigDecimal(0); | 
			
		
	
		
			
				
					|  |  |  |         BigDecimal closedCount = new BigDecimal(0);; | 
			
		
	
		
			
				
					|  |  |  |         BigDecimal processingRatio = null; | 
			
		
	
		
			
				
					|  |  |  |         BigDecimal closedRatio = null; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         for (Map<String, Long> entry : m) { | 
			
		
	
		
			
				
					|  |  |  |             if ("processing".equals(entry.get("status"))) { | 
			
		
	
		
			
				
					|  |  |  |                 processingCount = new BigDecimal(entry.get("eventCount")); | 
			
		
	
		
			
				
					|  |  |  |             } else if ("closed_case".equals(entry.get("status"))) { | 
			
		
	
		
			
				
					|  |  |  |                 closedCount = new BigDecimal(entry.get("eventCount")); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 根据个数,计算比例
 | 
			
		
	
		
			
				
					|  |  |  |         BigDecimal total = processingCount.add(closedCount); | 
			
		
	
		
			
				
					|  |  |  |         processingRatio = processingCount.divide(total, 2, BigDecimal.ROUND_HALF_UP); | 
			
		
	
		
			
				
					|  |  |  |         closedRatio = new BigDecimal(1).subtract(processingRatio); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         r.setProcessingCount(processingCount.longValue()); | 
			
		
	
		
			
				
					|  |  |  |         r.setClosedCount(closedCount.longValue()); | 
			
		
	
		
			
				
					|  |  |  |         r.setProcessingRatio(processingRatio.doubleValue()); | 
			
		
	
		
			
				
					|  |  |  |         r.setClosedRatio(closedRatio.doubleValue()); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return r; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public PageData<IcEventResultDTO> listProcessAnalysisEvents(String orgId, String orgType, String categoryCode, String processStatus, | 
			
		
	
		
			
				
					|  |  |  |                                                                 Date queryStartTime, Date queryEndTime, Integer pageNo, | 
			
		
	
		
			
				
					|  |  |  |                                                                 Integer pageSize) { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 1.分类字典
 | 
			
		
	
		
			
				
					|  |  |  |         Map<String, String> eventSourceTypeDict = getResultDataOrThrowsException(adminOpenFeignClient.dictMap("ic_event_source_type"), | 
			
		
	
		
			
				
					|  |  |  |                 ServiceConstant.EPMET_ADMIN_SERVER, | 
			
		
	
		
			
				
					|  |  |  |                 EpmetErrorCode.SERVER_ERROR.getCode(), | 
			
		
	
		
			
				
					|  |  |  |                 "【IC事件分析】查询上报渠道字典失败", | 
			
		
	
		
			
				
					|  |  |  |                 "【IC事件分析】查询上报渠道字典失败"); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         String gridPids = null; | 
			
		
	
		
			
				
					|  |  |  |         if ("agency".equals(orgType)) { | 
			
		
	
		
			
				
					|  |  |  |             gridPids = getEventGridPids(orgId); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 2.分页查询
 | 
			
		
	
		
			
				
					|  |  |  |         PageHelper.startPage(pageNo, pageSize); | 
			
		
	
		
			
				
					|  |  |  |         List<IcEventResultDTO> list = baseDao.listProcessAnalysisEvents( | 
			
		
	
		
			
				
					|  |  |  |                 EpmetRequestHolder.getHeader(AppClientConstant.CUSTOMER_ID), orgType, orgId, gridPids, categoryCode, processStatus, queryStartTime | 
			
		
	
		
			
				
					|  |  |  |                 ,queryEndTime); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 3.补充数据
 | 
			
		
	
		
			
				
					|  |  |  |         for (IcEventResultDTO event : list) { | 
			
		
	
		
			
				
					|  |  |  |             // 网格信息
 | 
			
		
	
		
			
				
					|  |  |  |             GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(event.getGridId()); | 
			
		
	
		
			
				
					|  |  |  |             if (gridInfo != null) { | 
			
		
	
		
			
				
					|  |  |  |                 event.setGridName(gridInfo.getGridName()); | 
			
		
	
		
			
				
					|  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |                 logger.error("【IC事件分析】网格ID[{}]查询网格信息失败", event.getGridId()); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 上报渠道
 | 
			
		
	
		
			
				
					|  |  |  |             event.setSourceTypeName(eventSourceTypeDict.get(event.getSourceType())); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             // 状态
 | 
			
		
	
		
			
				
					|  |  |  |             EcEventProcessStatusEnum sourceTypeEnum = EcEventProcessStatusEnum.getObjectBySourceType(event.getProcessStatus()); | 
			
		
	
		
			
				
					|  |  |  |             if (sourceTypeEnum != null) { | 
			
		
	
		
			
				
					|  |  |  |                 event.setProcessStatusName(sourceTypeEnum.getProcessStatusName()); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         PageInfo<IcEventResultDTO> pageInfo = new PageInfo<>(list); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return new PageData<>(list, pageInfo.getTotal()); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | } |