Commit 68c7f886579a33a2913b860e9fdd3a2a1e6a4c70
1 parent
10ec917d
app首页统计修改
Showing
4 changed files
with
43 additions
and
35 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/homepage/vo/WorkOrderTrendRespVo.java
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/dal/mysql/homepage/HomepageSummaryMapper.java
| @@ -99,7 +99,7 @@ public interface HomepageSummaryMapper extends BaseMapperX<DepartmentCostDO> { | @@ -99,7 +99,7 @@ public interface HomepageSummaryMapper extends BaseMapperX<DepartmentCostDO> { | ||
| 99 | * @Description 工单趋势 | 99 | * @Description 工单趋势 |
| 100 | * @Date 2025/12/30 23:40 | 100 | * @Date 2025/12/30 23:40 |
| 101 | */ | 101 | */ |
| 102 | - List<WorkOrderTrendRespVo> countWorkOrderTrend(@Param("companyId") Long companyId, @Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("queryState") String queryState); | 102 | + List<WorkOrderTrendRespVo> countWorkOrderTrend(@Param("companyId") Long companyId, @Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("queryState") String queryState, @Param("currentDate") String currentDate); |
| 103 | 103 | ||
| 104 | /** | 104 | /** |
| 105 | * @Author wangqian | 105 | * @Author wangqian |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/homepage/MaintainSummaryServiceImpl.java
| @@ -3,6 +3,7 @@ package com.zteits.urbanops.module.garden.service.homepage; | @@ -3,6 +3,7 @@ package com.zteits.urbanops.module.garden.service.homepage; | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | import cn.hutool.core.util.ObjectUtil; | 4 | import cn.hutool.core.util.ObjectUtil; |
| 5 | import com.zteits.urbanops.framework.common.biz.system.dict.dto.DictDataRespDTO; | 5 | import com.zteits.urbanops.framework.common.biz.system.dict.dto.DictDataRespDTO; |
| 6 | +import com.zteits.urbanops.framework.common.util.date.DateUtils; | ||
| 6 | import com.zteits.urbanops.framework.common.util.object.BeanUtils; | 7 | import com.zteits.urbanops.framework.common.util.object.BeanUtils; |
| 7 | import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; | 8 | import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils; |
| 8 | import com.zteits.urbanops.module.garden.controller.admin.homepage.vo.*; | 9 | import com.zteits.urbanops.module.garden.controller.admin.homepage.vo.*; |
| @@ -20,6 +21,9 @@ import org.springframework.stereotype.Service; | @@ -20,6 +21,9 @@ import org.springframework.stereotype.Service; | ||
| 20 | import java.text.DateFormat; | 21 | import java.text.DateFormat; |
| 21 | import java.text.ParseException; | 22 | import java.text.ParseException; |
| 22 | import java.text.SimpleDateFormat; | 23 | import java.text.SimpleDateFormat; |
| 24 | +import java.time.LocalDate; | ||
| 25 | +import java.time.ZoneId; | ||
| 26 | +import java.time.format.DateTimeFormatter; | ||
| 23 | import java.util.*; | 27 | import java.util.*; |
| 24 | import java.util.function.Function; | 28 | import java.util.function.Function; |
| 25 | import java.util.stream.Collectors; | 29 | import java.util.stream.Collectors; |
| @@ -38,9 +42,12 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | @@ -38,9 +42,12 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | ||
| 38 | @Resource | 42 | @Resource |
| 39 | private DictDataApi dictDataApi; | 43 | private DictDataApi dictDataApi; |
| 40 | 44 | ||
| 45 | + private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd") | ||
| 46 | + .withZone(ZoneId.of("Asia/Shanghai")); | ||
| 47 | + | ||
| 41 | @Override | 48 | @Override |
| 42 | public Map<String, Object> getSummary() { | 49 | public Map<String, Object> getSummary() { |
| 43 | - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId(); | 50 | + Long companyId = SecurityFrameworkUtils.getCompanyId(); |
| 44 | if(null == companyId || companyId == 0L || companyId == 100L){ | 51 | if(null == companyId || companyId == 0L || companyId == 100L){ |
| 45 | companyId = null; | 52 | companyId = null; |
| 46 | } | 53 | } |
| @@ -65,13 +72,13 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | @@ -65,13 +72,13 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | ||
| 65 | 72 | ||
| 66 | @Override | 73 | @Override |
| 67 | public Map<String, Object> getWorkTaskTrend(HomePageSummaryReqVO req) { | 74 | public Map<String, Object> getWorkTaskTrend(HomePageSummaryReqVO req) { |
| 68 | - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId(); | 75 | + Long companyId = SecurityFrameworkUtils.getCompanyId(); |
| 69 | if(null == companyId || companyId == 0L || companyId == 100L){ | 76 | if(null == companyId || companyId == 0L || companyId == 100L){ |
| 70 | companyId = null; | 77 | companyId = null; |
| 71 | } | 78 | } |
| 72 | Map<String,Object> chartData = new HashMap<>(); | 79 | Map<String,Object> chartData = new HashMap<>(); |
| 73 | //1、数据结构初始化 | 80 | //1、数据结构初始化 |
| 74 | - List<String> days = getDays(req.beginTime, req.endTime); | 81 | + List<String> days = getDays(req.getBeginTime(), req.getEndTime()); |
| 75 | List<DictDataRespDTO> dictDataList = dictDataApi.getDictDataList(DictTypeConstants.BUSINESS_LINE); | 82 | List<DictDataRespDTO> dictDataList = dictDataApi.getDictDataList(DictTypeConstants.BUSINESS_LINE); |
| 76 | List<String> allBusiLines = dictDataList.stream().map(DictDataRespDTO::getValue).collect(Collectors.toList()); | 83 | List<String> allBusiLines = dictDataList.stream().map(DictDataRespDTO::getValue).collect(Collectors.toList()); |
| 77 | Map<String, List<CommitTaskStatisticsRespVo>> defaultData = addTaskDefaultData(req, days, dictDataList); | 84 | Map<String, List<CommitTaskStatisticsRespVo>> defaultData = addTaskDefaultData(req, days, dictDataList); |
| @@ -188,7 +195,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | @@ -188,7 +195,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | ||
| 188 | */ | 195 | */ |
| 189 | @Override | 196 | @Override |
| 190 | public Map<String, Object> getWorkOrderRatio(HomePageSummaryReqVO req) { | 197 | public Map<String, Object> getWorkOrderRatio(HomePageSummaryReqVO req) { |
| 191 | - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId(); | 198 | + Long companyId = SecurityFrameworkUtils.getCompanyId(); |
| 192 | if(null == companyId || companyId == 0L || companyId == 100L){ | 199 | if(null == companyId || companyId == 0L || companyId == 100L){ |
| 193 | companyId = null; | 200 | companyId = null; |
| 194 | } | 201 | } |
| @@ -279,7 +286,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | @@ -279,7 +286,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | ||
| 279 | */ | 286 | */ |
| 280 | @Override | 287 | @Override |
| 281 | public Map<String, CommitWorkOrderRespVo> getWorkOrderDistribution(HomePageSummaryReqVO req) { | 288 | public Map<String, CommitWorkOrderRespVo> getWorkOrderDistribution(HomePageSummaryReqVO req) { |
| 282 | - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId(); | 289 | + Long companyId = SecurityFrameworkUtils.getCompanyId(); |
| 283 | if(null == companyId || companyId == 0L || companyId == 100L){ | 290 | if(null == companyId || companyId == 0L || companyId == 100L){ |
| 284 | companyId = null; | 291 | companyId = null; |
| 285 | } | 292 | } |
| @@ -345,7 +352,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | @@ -345,7 +352,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | ||
| 345 | 352 | ||
| 346 | @Override | 353 | @Override |
| 347 | public Map<String, CommitWorkOrderSourceRespVo> getWorkOrderDistributionBySource(HomePageSummaryReqVO req) { | 354 | public Map<String, CommitWorkOrderSourceRespVo> getWorkOrderDistributionBySource(HomePageSummaryReqVO req) { |
| 348 | - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId(); | 355 | + Long companyId = SecurityFrameworkUtils.getCompanyId(); |
| 349 | if(null == companyId || companyId == 0L || companyId == 100L){ | 356 | if(null == companyId || companyId == 0L || companyId == 100L){ |
| 350 | companyId = null; | 357 | companyId = null; |
| 351 | } | 358 | } |
| @@ -419,7 +426,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | @@ -419,7 +426,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | ||
| 419 | */ | 426 | */ |
| 420 | @Override | 427 | @Override |
| 421 | public List<Map<String, Object>> getWorkOrderHeatmap() { | 428 | public List<Map<String, Object>> getWorkOrderHeatmap() { |
| 422 | - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId(); | 429 | + Long companyId = SecurityFrameworkUtils.getCompanyId(); |
| 423 | if(null == companyId || companyId == 0L || companyId == 100L){ | 430 | if(null == companyId || companyId == 0L || companyId == 100L){ |
| 424 | companyId = null; | 431 | companyId = null; |
| 425 | } | 432 | } |
| @@ -433,7 +440,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | @@ -433,7 +440,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | ||
| 433 | */ | 440 | */ |
| 434 | @Override | 441 | @Override |
| 435 | public Map<String, Object> getWorkOrderTrend(HomePageSummaryReqVO req) { | 442 | public Map<String, Object> getWorkOrderTrend(HomePageSummaryReqVO req) { |
| 436 | - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId(); | 443 | + Long companyId = SecurityFrameworkUtils.getCompanyId(); |
| 437 | if(null == companyId || companyId == 0L || companyId == 100L){ | 444 | if(null == companyId || companyId == 0L || companyId == 100L){ |
| 438 | companyId = null; | 445 | companyId = null; |
| 439 | } | 446 | } |
| @@ -445,7 +452,10 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | @@ -445,7 +452,10 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | ||
| 445 | // 1. 初始化响应Map | 452 | // 1. 初始化响应Map |
| 446 | Map<String, List<WorkOrderTrendRespVo>> respMap = addDefaultData(req); | 453 | Map<String, List<WorkOrderTrendRespVo>> respMap = addDefaultData(req); |
| 447 | // 2、汇总工单数量 | 454 | // 2、汇总工单数量 |
| 448 | - List<WorkOrderTrendRespVo> countList = homepageSummaryMapper.countWorkOrderTrend(companyId, req.getBeginTime(), req.getEndTime(), req.getQueryState()); | 455 | + LocalDate currentLocalDate = LocalDate.now(ZoneId.of("Asia/Shanghai")); |
| 456 | + // 2. 格式化为yyyy-MM-dd字符串 | ||
| 457 | + String currentDate = currentLocalDate.format(DATE_FORMATTER); | ||
| 458 | + List<WorkOrderTrendRespVo> countList = homepageSummaryMapper.countWorkOrderTrend(companyId, req.getBeginTime(), req.getEndTime(), req.getQueryState(), currentDate); | ||
| 449 | Map<String, List<WorkOrderTrendRespVo>> busiLineGroup; | 459 | Map<String, List<WorkOrderTrendRespVo>> busiLineGroup; |
| 450 | if (CollectionUtils.isNotEmpty(countList)) { | 460 | if (CollectionUtils.isNotEmpty(countList)) { |
| 451 | busiLineGroup = countList.stream() | 461 | busiLineGroup = countList.stream() |
| @@ -475,7 +485,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | @@ -475,7 +485,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | ||
| 475 | 485 | ||
| 476 | // 3.2 构建「联合标识-真实totalCount」的Map,提高匹配效率 | 486 | // 3.2 构建「联合标识-真实totalCount」的Map,提高匹配效率 |
| 477 | // 联合标识:companyId_dateValue(因为busiLine已匹配,内部无需重复拼接) | 487 | // 联合标识:companyId_dateValue(因为busiLine已匹配,内部无需重复拼接) |
| 478 | - Map<String, String> realCountMap = realVoList.stream() | 488 | + Map<String, Integer> realCountMap = realVoList.stream() |
| 479 | .filter(realVo -> realVo.getCompanyId() != null && realVo.getDateValue() != null) // 过滤空值,避免异常 | 489 | .filter(realVo -> realVo.getCompanyId() != null && realVo.getDateValue() != null) // 过滤空值,避免异常 |
| 480 | .collect(Collectors.toMap( | 490 | .collect(Collectors.toMap( |
| 481 | // 键:companyId + "_" + dateValue(唯一标识) | 491 | // 键:companyId + "_" + dateValue(唯一标识) |
| @@ -513,18 +523,17 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | @@ -513,18 +523,17 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService { | ||
| 513 | companyList.forEach(resp ->{ | 523 | companyList.forEach(resp ->{ |
| 514 | WorkOrderTrendRespVo type = new WorkOrderTrendRespVo(); | 524 | WorkOrderTrendRespVo type = new WorkOrderTrendRespVo(); |
| 515 | type.setDateValue(dayy); | 525 | type.setDateValue(dayy); |
| 516 | - type.setTotalCount("0"); // 默认总数为0 | 526 | + type.setTotalCount(0); // 默认总数为0 |
| 517 | type.setCompanyId(String.valueOf(resp.getId())); | 527 | type.setCompanyId(String.valueOf(resp.getId())); |
| 518 | type.setCompanyName(resp.getName()); | 528 | type.setCompanyName(resp.getName()); |
| 519 | newList.add(type); | 529 | newList.add(type); |
| 520 | }); | 530 | }); |
| 521 | }); | 531 | }); |
| 522 | 532 | ||
| 523 | - List<DictDataRespDTO> dictDataList = dictDataApi.getDictDataList(DictTypeConstants.BUSINESS_LINE); | ||
| 524 | - List<String> busiLines = dictDataList.stream().map(DictDataRespDTO::getValue).collect(Collectors.toList()); | ||
| 525 | - | 533 | + String busiLines = SecurityFrameworkUtils.getBusiLine(); |
| 534 | + String[] busiLineArray = busiLines.split(","); | ||
| 526 | // 6. 为每个业务线生成专属列表并赋值busiLine | 535 | // 6. 为每个业务线生成专属列表并赋值busiLine |
| 527 | - for (String type : busiLines) { | 536 | + for (String type : busiLineArray) { |
| 528 | // 核心:通过map拷贝对象并设置busiLine,避免引用共享 | 537 | // 核心:通过map拷贝对象并设置busiLine,避免引用共享 |
| 529 | List<WorkOrderTrendRespVo> busiLineList = newList.stream() | 538 | List<WorkOrderTrendRespVo> busiLineList = newList.stream() |
| 530 | // 拷贝原对象,创建新对象并设置当前业务线 | 539 | // 拷贝原对象,创建新对象并设置当前业务线 |
urbanops-module-garden/src/main/resources/mapper/homepage/HomepageSummaryMapper.xml
| @@ -254,35 +254,34 @@ | @@ -254,35 +254,34 @@ | ||
| 254 | </select> | 254 | </select> |
| 255 | 255 | ||
| 256 | <select id="countWorkOrderTrend" resultType="com.zteits.urbanops.module.garden.controller.admin.homepage.vo.WorkOrderTrendRespVo"> | 256 | <select id="countWorkOrderTrend" resultType="com.zteits.urbanops.module.garden.controller.admin.homepage.vo.WorkOrderTrendRespVo"> |
| 257 | - select v.date_value as dateValue, | 257 | + SELECT |
| 258 | + DATE_FORMAT(t.create_time , '%Y-%m-%d') as dateValue, | ||
| 258 | t.busi_line as busiLine, | 259 | t.busi_line as busiLine, |
| 259 | t.worker_company_id as companyId, | 260 | t.worker_company_id as companyId, |
| 260 | <choose> | 261 | <choose> |
| 261 | <when test='queryState != null and queryState eq "1"'> | 262 | <when test='queryState != null and queryState eq "1"'> |
| 262 | - sum(case when v.date_value = DATE_FORMAT(t.create_time , '%Y-%m-%d') then 1 else 0 end) as totalCount | 263 | + sum(CASE WHEN DATE_FORMAT(t.create_time , '%Y-%m-%d') = #{currentDate} THEN 1 ELSE 0 END) as totalCount |
| 263 | </when> | 264 | </when> |
| 264 | <when test='queryState != null and queryState eq "2"'> | 265 | <when test='queryState != null and queryState eq "2"'> |
| 265 | - sum(case when t.buz_status != '200' then 1 else 0 end) as totalCount | 266 | + sum(CASE WHEN t.buz_status != '200' THEN 1 ELSE 0 END) as totalCount |
| 266 | </when> | 267 | </when> |
| 267 | <when test='queryState != null and queryState eq "3"'> | 268 | <when test='queryState != null and queryState eq "3"'> |
| 268 | - sum(case when t.buz_status = '200' then 1 else 0 end) as totalCount | 269 | + sum(CASE WHEN t.buz_status = '200' THEN 1 ELSE 0 END) as totalCount |
| 269 | </when> | 270 | </when> |
| 270 | </choose> | 271 | </choose> |
| 271 | - from view_statics_times v | ||
| 272 | - left join workorder_main_info t | ||
| 273 | - on v.date_value = DATE_FORMAT(t.create_time , '%Y-%m-%d') and deleted =0 | ||
| 274 | - <if test="companyId != null"> | ||
| 275 | - and t.worker_company_id = #{companyId} | 272 | + FROM workorder_main_info t |
| 273 | + WHERE deleted = 0 | ||
| 274 | + <if test="companyId != null and companyId != ''"> | ||
| 275 | + AND t.worker_company_id = #{companyId} | ||
| 276 | </if> | 276 | </if> |
| 277 | - <where> | ||
| 278 | - <if test="beginTime != null and beginTime != ''"> | ||
| 279 | - AND v.date_value >= #{beginTime} | ||
| 280 | - </if> | ||
| 281 | - <if test="endTime != null and endTime != ''"> | ||
| 282 | - AND v.date_value <= #{endTime} | ||
| 283 | - </if> | ||
| 284 | - </where> | ||
| 285 | - group by v.date_value,t.busi_line,t.worker_company_id | 277 | + <if test="beginTime != null and beginTime != ''"> |
| 278 | + AND t.create_time >= STR_TO_DATE(#{beginTime}, '%Y-%m-%d') | ||
| 279 | + </if> | ||
| 280 | + <if test="endTime != null and endTime != ''"> | ||
| 281 | + <!-- 优化:结束时间匹配到当日23:59:59,覆盖全天 --> | ||
| 282 | + AND t.create_time <= STR_TO_DATE(#{endTime}, '%Y-%m-%d') | ||
| 283 | + </if> | ||
| 284 | + GROUP BY DATE_FORMAT(t.create_time , '%Y-%m-%d'), t.busi_line, t.worker_company_id | ||
| 286 | </select> | 285 | </select> |
| 287 | 286 | ||
| 288 | <!--已完成任务数量--> | 287 | <!--已完成任务数量--> |