package org.springblade.modules.eCallEventTwo.service.impl; import cn.hutool.core.convert.Convert; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springblade.common.utils.SpringUtils; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.modules.eCallEventTwo.dto.*; import org.springblade.modules.eCallEventTwo.entity.ECallEventTwoEntity; import org.springblade.modules.eCallEventTwo.entity.EcOrder; import org.springblade.modules.eCallEventTwo.mapper.EcOrderMapper; import org.springblade.modules.eCallEventTwo.service.EcOrderService; import org.springblade.modules.eCallEventTwo.service.IECallEventTwoService; import org.springblade.modules.grid.entity.GridEntity; import org.springblade.modules.grid.service.IGridService; import org.springblade.modules.police.entity.PoliceAffairsGridEntity; import org.springblade.modules.police.service.IPoliceAffairsGridService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Arrays; import java.util.List; import java.util.Map; /** * EcOrderService业务层处理 * * @author ${context.author} * @date 2024-05-27 16:26:59 */ @Service public class EcOrderServiceImpl extends ServiceImpl implements EcOrderService { private static final int DEFAULT_SCALE = 2; // 默认保留两位小数 private static final RoundingMode DEFAULT_ROUNDING_MODE = RoundingMode.HALF_UP; // 默认四舍五入 @Autowired private IECallEventTwoService ecOrderService; protected static final Logger log = LoggerFactory.getLogger(EcOrderServiceImpl.class); /** * 查询工单 * * @param orderId 工单ID * @return 工单 */ @Override public EcOrderDTO selectEcOrderById(Long orderId) { return this.baseMapper.selectEcOrderById(orderId); } /** * 查询工单列表 * * @param ecOrderDTO 工单 * @return 工单集合 */ @Override public List selectEcOrderList(EcOrderDTO ecOrderDTO) { return this.baseMapper.selectEcOrderList(ecOrderDTO); } /** * 新增工单 * * @param ecOrderDTO 工单 * @return 结果 */ @Override public int insertEcOrder(EcOrderDTO ecOrderDTO) { return this.baseMapper.insert(ecOrderDTO); } /** * 修改工单 * * @param ecOrderDTO 工单 * @return 结果 */ @Override public int updateEcOrder(EcOrderDTO ecOrderDTO) { return this.baseMapper.updateById(ecOrderDTO); } /** * 删除工单对象 * * @param ids 需要删除的数据ID * @return 结果 */ @Override public int deleteEcOrderByIds(String ids) { return this.removeByIds(Arrays.asList(Convert.toStrArray(ids))) ? 1 : 0; } /** * 删除工单信息 * * @param orderId 工单ID * @return 结果 */ @Override public int deleteEcOrderById(Long orderId) { return this.removeById(orderId) ? 1 : 0; } @Override @Transactional(rollbackFor = Exception.class) @DS("slave_1") public boolean SynchronizeData(EcOrderParamDTO ecOrderParamDTO) { processPages(100, ecOrderParamDTO); return true; } public void processPages(int pageSize, EcOrderParamDTO ecOrderParamDTO) { QueryWrapper ecOrderQueryWrapper = new QueryWrapper<>(); if (ecOrderParamDTO.getStartTime() != null) { ecOrderQueryWrapper.between("import_time", ecOrderParamDTO.getStartTime(), ecOrderParamDTO.getEndTime()); } long count = count(ecOrderQueryWrapper); int totalPages = (int) Math.ceil((double) count / pageSize); // 计算总页数 for (int pageNum = 1; pageNum <= totalPages; pageNum++) { Page page = new Page<>(pageNum, pageSize); QueryWrapper objectQueryWrapper = new QueryWrapper<>(); IPage resultPage = page(page, objectQueryWrapper); List records = resultPage.getRecords(); List recordEntityList = BeanUtil.copy(records, ECallEventTwoEntity.class); recordEntityList.forEach(ecOrderEntity -> { // 点落面 设置警格网格信息 setGridInfo(ecOrderEntity); }); boolean b = saveEcOrder(recordEntityList); System.out.println("更新第" + pageNum + "页" + b); } } @Override @DS("master") public boolean saveEcOrder(List recordEntityList) { return ecOrderService.saveOrUpdateBatch(recordEntityList); } /** * 设置警格网格信息 * * @param ecOrderEntity */ public void setGridInfo(ECallEventTwoEntity ecOrderEntity) { if (ecOrderEntity.getSceneGeoLng() == null || ecOrderEntity.getSceneGeoLat() == null) { return; } // 根据位置设置网格,警格编号 IGridService gridService = SpringUtils.getBean(IGridService.class); IPoliceAffairsGridService policeAffairsGridService = SpringUtils.getBean(IPoliceAffairsGridService.class); String point = "'POINT(" + ecOrderEntity.getSceneGeoLng().toString() + " " + ecOrderEntity.getSceneGeoLat().toString() + ")'"; // 点坐标解析网格 List gridEntityList = gridService.spatialAnalysis(point); if (gridEntityList.size() > 0) { GridEntity gridEntity = gridEntityList.get(0); ecOrderEntity.setGridCode(gridEntity.getGridCode()); } // 点坐标解析警格 List policeAffairsGridEntityList = policeAffairsGridService.spatialAnalysis(point); if (policeAffairsGridEntityList.size() > 0) { PoliceAffairsGridEntity policeAffairsGridEntity = policeAffairsGridEntityList.get(0); ecOrderEntity.setJwGridCode(policeAffairsGridEntity.getJwGridCode()); } } /** * 获取单位考核指标 * * @return */ @Override public List> getUnitAssessmentIndicators() { List> result = baseMapper.getUnitAssessmentIndicators(); return result; } /** * 统计办结率 */ @Override public IPage getCount(IPage page, EcOrderParamDTO ecOrderParamDTO) { // acpt_org_code List result = baseMapper.getOrgCode(page, ecOrderParamDTO); for (EcOrderDTO ecOrderDTO : result) { if (ecOrderParamDTO.getTagMain().equals("Y")) { ecOrderParamDTO.setSinkOrgCode(ecOrderDTO.getSinkOrgCode()); } else { ecOrderParamDTO.setSubjectOrgCode(ecOrderDTO.getSubjectOrgCode()); } // 统计办结率 buildRate(ecOrderParamDTO, ecOrderDTO); // 获取单位名称 if (ecOrderParamDTO.getTagMain().equals("Y")) { ecOrderDTO.setOrgCode(ecOrderDTO.getSinkOrgCode()); ecOrderDTO.setOrgName(ecOrderDTO.getSinkOrgName()); } else { ecOrderDTO.setOrgCode(ecOrderDTO.getSubjectOrgCode()); ecOrderDTO.setOrgName(ecOrderDTO.getSubjectOrgName()); } } return page.setRecords(result); } @NotNull private void buildRate(EcOrderParamDTO ecOrderParamDTO, EcOrderDTO ecOrder) { // 统计订单 EcOrderDTO ecOrderDTO = BeanUtil.copy(ecOrderParamDTO, EcOrderDTO.class); int i = baseMapper.selectEcOrderCount(ecOrderDTO); // 统计派发 EcDispatchDTO ecDispatchDTO = BeanUtil.copy(ecOrderParamDTO, EcDispatchDTO.class); int i1 = baseMapper.selectEcDispatchCount(ecDispatchDTO); // 统计处理 EcHandleDTO ecHandleDTO = BeanUtil.copy(ecOrderParamDTO, EcHandleDTO.class); int i2 = baseMapper.selectEcHandleCount(ecHandleDTO); // 统计回访 EcOrderCheckDTO ecOrderCheckDTO = BeanUtil.copy(ecOrderParamDTO, EcOrderCheckDTO.class); int i3 = baseMapper.selectEcOrderCheckCount(ecOrderCheckDTO); // 统计办结 EcOrderDoneDTO ecOrderDoneDTO = BeanUtil.copy(ecOrderParamDTO, EcOrderDoneDTO.class); int i4 = baseMapper.selectEcOrderDoneCount(ecOrderDoneDTO); // 统计答复 EcOrderRespDTO ecOrderRespDTO = BeanUtil.copy(ecOrderParamDTO, EcOrderRespDTO.class); int i5 = baseMapper.selectEcOrderRespCount(ecOrderRespDTO); // 统计核实 EcOrderReviewDTO ecOrderReviewDTO = BeanUtil.copy(ecOrderParamDTO, EcOrderReviewDTO.class); int i6 = baseMapper.selectEcOrderReviewCount(ecOrderReviewDTO); // 统计督办 EcOrderSuperviseDTO ecOrderSuperviseDTO = BeanUtil.copy(ecOrderParamDTO, EcOrderSuperviseDTO.class); int i7 = baseMapper.selectEcOrderSuperviseCount(ecOrderSuperviseDTO); // 工单数 派发单数 办理单数(率) 办结单数(率) 答复单数(率) 回访单数(率) 核实单数 督办单数 // Map result = new HashMap<>(); // 工单数 // result.put("orderNumber", String.valueOf(i)); ecOrder.setOrderNumber(String.valueOf(i)); // 派发单数(率) // result.put("dispatchRate", getRate(i1, i)); ecOrder.setDispatchRate(getRate(i1, i)); // result.put("dispatchNumber", String.valueOf(i1)); ecOrder.setDispatchNumber(String.valueOf(i1)); // 办理单数(率) // result.put("handRate", getRate(i2, i)); ecOrder.setHandRate(getRate(i2, i)); // result.put("handNumber", String.valueOf(i2)); // 办结单数(率) // result.put("checkRate", getRate(i3, i)); ecOrder.setCheckRate(getRate(i3, i)); // result.put("checkNumber", String.valueOf(i3)); // 答复单数(率) // result.put("doneRate", getRate(i4, i)); ecOrder.setDoneRate(getRate(i4, i)); // result.put("doneNumber", String.valueOf(i4)); // 回访单数(率) // result.put("respRate", getRate(i5, i)); ecOrder.setRespRate(getRate(i5, i)); // result.put("respNumber", String.valueOf(i5)); // 核实单数(率) // result.put("reviewRate", getRate(i6, i)); ecOrder.setReviewRate(getRate(i6, i)); // result.put("reviewNumber", String.valueOf(i6)); // 督办单数 // result.put("superviseNumber", String.valueOf(i7)); ecOrder.setSuperviseNumber(String.valueOf(i7)); // 返回结果 // return result; } public static String getRate(int dividend, int divisor) { // 检查除数是否为0 if (divisor == 0) { return "0"; } // 将int转换为BigDecimal BigDecimal bdDividend = BigDecimal.valueOf(dividend); BigDecimal bdDivisor = BigDecimal.valueOf(divisor); // 执行除法操作,设置精度(scale)和舍入模式(RoundingMode) int scale = DEFAULT_SCALE; RoundingMode roundingMode = DEFAULT_ROUNDING_MODE; // 进行除法运算 BigDecimal result; try { result = bdDividend.divide(bdDivisor, scale, roundingMode); } catch (ArithmeticException e) { // 处理因除数为0或其他原因引发的算术异常 throw new RuntimeException("除法运算出错", e); } return result.toString(); } }