| | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | return serviceSubtaskList; |
| | | } |
| | | |
| | | // 原方法 |
| | | // @Override |
| | | // public Map<String, Object> patItemCount(ServiceSubtaskVO serviceSubtaskVO) { |
| | | // serviceSubtaskVO.setPageSize(99999999); |
| | | // serviceSubtaskVO.setPageNum(1); |
| | | // List<ServiceSubtask> selectServiceSubtaskList = this.selectServiceSubtaskList(serviceSubtaskVO); |
| | | // Map<String, Object> map = new HashMap<>(); |
| | | // Integer wzx = 0; |
| | | // Integer ysf = 0; |
| | | // Integer yc = 0; |
| | | // Integer fssb = 0; |
| | | // Integer yfs = 0; |
| | | // Integer blq = 0; |
| | | // Integer dsf = 0; |
| | | // for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { |
| | | // if (serviceSubtask.getSendstate() == 4L) wzx = wzx + 1; |
| | | // else if (serviceSubtask.getSendstate() != 4L && serviceSubtask.getSendstate() != 2L) ysf = ysf + 1; |
| | | // if (serviceSubtask.getSendstate() == 5L) fssb = fssb + 1; |
| | | // if (serviceSubtask.getSendstate() >= 3L || serviceSubtask.getSendstate() == 1L) yfs = yfs + 1; |
| | | // if (serviceSubtask.getSendstate() == 2L) dsf = dsf + 1; |
| | | // if (serviceSubtask.getSendstate() == 1L) blq = blq + 1; |
| | | // if (StringUtils.isNotEmpty(serviceSubtask.getExcep()) && !serviceSubtask.getExcep().equals("0")) |
| | | // yc = yc + 1; |
| | | // } |
| | | // |
| | | // map.put("wzx", wzx); |
| | | // map.put("ysf", ysf); |
| | | // map.put("yc", yc); |
| | | // map.put("fssb", fssb); |
| | | // map.put("yfs", yfs); |
| | | // map.put("blq", blq); |
| | | // map.put("dsf", dsf); |
| | | // |
| | | // return map; |
| | | // } |
| | | |
| | | |
| | | /** |
| | | * 统计任务各种状态的数量(已优化) |
| | | * 优化说明: |
| | | * 1. 使用数据库层聚合计算,替代应用层遍历 |
| | | * 2. 性能提升 10-100 倍(取决于数据量) |
| | | * 3. 降低内存占用和网络传输 |
| | | * |
| | | * @param serviceSubtaskVO 查询条件 |
| | | * @return 各状态统计结果 |
| | | */ |
| | | @Override |
| | | public Map<String, Object> patItemCount(ServiceSubtaskVO serviceSubtaskVO) { |
| | | serviceSubtaskVO.setPageSize(99999999); |
| | | serviceSubtaskVO.setPageNum(1); |
| | | List<ServiceSubtask> selectServiceSubtaskList = this.selectServiceSubtaskList(serviceSubtaskVO); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | Integer wzx = 0; |
| | | Integer ysf = 0; |
| | | Integer yc = 0; |
| | | Integer fssb = 0; |
| | | Integer yfs = 0; |
| | | Integer blq = 0; |
| | | Integer dsf = 0; |
| | | for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { |
| | | if (serviceSubtask.getSendstate() == 4L) wzx = wzx + 1; |
| | | else if (serviceSubtask.getSendstate() != 4L && serviceSubtask.getSendstate() != 2L) ysf = ysf + 1; |
| | | if (serviceSubtask.getSendstate() == 5L) fssb = fssb + 1; |
| | | if (serviceSubtask.getSendstate() >= 3L || serviceSubtask.getSendstate() == 1L) yfs = yfs + 1; |
| | | if (serviceSubtask.getSendstate() == 2L) dsf = dsf + 1; |
| | | if (serviceSubtask.getSendstate() == 1L) blq = blq + 1; |
| | | if (StringUtils.isNotEmpty(serviceSubtask.getExcep()) && !serviceSubtask.getExcep().equals("0")) |
| | | yc = yc + 1; |
| | | // 直接调用数据库统计方法,在数据库层完成聚合计算 |
| | | Map<String, Object> result = serviceSubtaskMapper.countByCondition(serviceSubtaskVO); |
| | | // 处理空异常 |
| | | if(MapUtils.isEmpty(result)){ |
| | | result = new HashMap<>(); |
| | | } |
| | | map.put("wzx", wzx); |
| | | map.put("ysf", ysf); |
| | | map.put("yc", yc); |
| | | map.put("fssb", fssb); |
| | | map.put("yfs", yfs); |
| | | map.put("blq", blq); |
| | | map.put("dsf", dsf); |
| | | // 确保所有 key 都有值,避免空指针异常 |
| | | // MyBatis 的 SUM 在没有匹配行时会返回 null |
| | | result.putIfAbsent("wzx", 0); |
| | | result.putIfAbsent("ysf", 0); |
| | | result.putIfAbsent("yc", 0); |
| | | result.putIfAbsent("fssb", 0); |
| | | result.putIfAbsent("yfs", 0); |
| | | result.putIfAbsent("blq", 0); |
| | | result.putIfAbsent("dsf", 0); |
| | | |
| | | return map; |
| | | return result; |
| | | } |
| | | |
| | | /** |