Commit 68c7f886579a33a2913b860e9fdd3a2a1e6a4c70

Authored by wangqian
1 parent 10ec917d

app首页统计修改

urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/homepage/vo/WorkOrderTrendRespVo.java
... ... @@ -19,7 +19,7 @@ public class WorkOrderTrendRespVo {
19 19  
20 20 private String companyName;
21 21  
22   - private String totalCount;
  22 + private Integer totalCount;
23 23  
24 24  
25 25 }
... ...
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 99 * @Description 工单趋势
100 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 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 3 import cn.hutool.core.bean.BeanUtil;
4 4 import cn.hutool.core.util.ObjectUtil;
5 5 import com.zteits.urbanops.framework.common.biz.system.dict.dto.DictDataRespDTO;
  6 +import com.zteits.urbanops.framework.common.util.date.DateUtils;
6 7 import com.zteits.urbanops.framework.common.util.object.BeanUtils;
7 8 import com.zteits.urbanops.framework.security.core.util.SecurityFrameworkUtils;
8 9 import com.zteits.urbanops.module.garden.controller.admin.homepage.vo.*;
... ... @@ -20,6 +21,9 @@ import org.springframework.stereotype.Service;
20 21 import java.text.DateFormat;
21 22 import java.text.ParseException;
22 23 import java.text.SimpleDateFormat;
  24 +import java.time.LocalDate;
  25 +import java.time.ZoneId;
  26 +import java.time.format.DateTimeFormatter;
23 27 import java.util.*;
24 28 import java.util.function.Function;
25 29 import java.util.stream.Collectors;
... ... @@ -38,9 +42,12 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService {
38 42 @Resource
39 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 48 @Override
42 49 public Map<String, Object> getSummary() {
43   - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId();
  50 + Long companyId = SecurityFrameworkUtils.getCompanyId();
44 51 if(null == companyId || companyId == 0L || companyId == 100L){
45 52 companyId = null;
46 53 }
... ... @@ -65,13 +72,13 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService {
65 72  
66 73 @Override
67 74 public Map<String, Object> getWorkTaskTrend(HomePageSummaryReqVO req) {
68   - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId();
  75 + Long companyId = SecurityFrameworkUtils.getCompanyId();
69 76 if(null == companyId || companyId == 0L || companyId == 100L){
70 77 companyId = null;
71 78 }
72 79 Map<String,Object> chartData = new HashMap<>();
73 80 //1、数据结构初始化
74   - List<String> days = getDays(req.beginTime, req.endTime);
  81 + List<String> days = getDays(req.getBeginTime(), req.getEndTime());
75 82 List<DictDataRespDTO> dictDataList = dictDataApi.getDictDataList(DictTypeConstants.BUSINESS_LINE);
76 83 List<String> allBusiLines = dictDataList.stream().map(DictDataRespDTO::getValue).collect(Collectors.toList());
77 84 Map<String, List<CommitTaskStatisticsRespVo>> defaultData = addTaskDefaultData(req, days, dictDataList);
... ... @@ -188,7 +195,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService {
188 195 */
189 196 @Override
190 197 public Map<String, Object> getWorkOrderRatio(HomePageSummaryReqVO req) {
191   - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId();
  198 + Long companyId = SecurityFrameworkUtils.getCompanyId();
192 199 if(null == companyId || companyId == 0L || companyId == 100L){
193 200 companyId = null;
194 201 }
... ... @@ -279,7 +286,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService {
279 286 */
280 287 @Override
281 288 public Map<String, CommitWorkOrderRespVo> getWorkOrderDistribution(HomePageSummaryReqVO req) {
282   - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId();
  289 + Long companyId = SecurityFrameworkUtils.getCompanyId();
283 290 if(null == companyId || companyId == 0L || companyId == 100L){
284 291 companyId = null;
285 292 }
... ... @@ -345,7 +352,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService {
345 352  
346 353 @Override
347 354 public Map<String, CommitWorkOrderSourceRespVo> getWorkOrderDistributionBySource(HomePageSummaryReqVO req) {
348   - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId();
  355 + Long companyId = SecurityFrameworkUtils.getCompanyId();
349 356 if(null == companyId || companyId == 0L || companyId == 100L){
350 357 companyId = null;
351 358 }
... ... @@ -419,7 +426,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService {
419 426 */
420 427 @Override
421 428 public List<Map<String, Object>> getWorkOrderHeatmap() {
422   - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId();
  429 + Long companyId = SecurityFrameworkUtils.getCompanyId();
423 430 if(null == companyId || companyId == 0L || companyId == 100L){
424 431 companyId = null;
425 432 }
... ... @@ -433,7 +440,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService {
433 440 */
434 441 @Override
435 442 public Map<String, Object> getWorkOrderTrend(HomePageSummaryReqVO req) {
436   - Long companyId = SecurityFrameworkUtils.getLoginUserDeptId();
  443 + Long companyId = SecurityFrameworkUtils.getCompanyId();
437 444 if(null == companyId || companyId == 0L || companyId == 100L){
438 445 companyId = null;
439 446 }
... ... @@ -445,7 +452,10 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService {
445 452 // 1. 初始化响应Map
446 453 Map<String, List<WorkOrderTrendRespVo>> respMap = addDefaultData(req);
447 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 459 Map<String, List<WorkOrderTrendRespVo>> busiLineGroup;
450 460 if (CollectionUtils.isNotEmpty(countList)) {
451 461 busiLineGroup = countList.stream()
... ... @@ -475,7 +485,7 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService {
475 485  
476 486 // 3.2 构建「联合标识-真实totalCount」的Map,提高匹配效率
477 487 // 联合标识:companyId_dateValue(因为busiLine已匹配,内部无需重复拼接)
478   - Map<String, String> realCountMap = realVoList.stream()
  488 + Map<String, Integer> realCountMap = realVoList.stream()
479 489 .filter(realVo -> realVo.getCompanyId() != null && realVo.getDateValue() != null) // 过滤空值,避免异常
480 490 .collect(Collectors.toMap(
481 491 // 键:companyId + "_" + dateValue(唯一标识)
... ... @@ -513,18 +523,17 @@ public class MaintainSummaryServiceImpl implements MaintainSummaryService {
513 523 companyList.forEach(resp ->{
514 524 WorkOrderTrendRespVo type = new WorkOrderTrendRespVo();
515 525 type.setDateValue(dayy);
516   - type.setTotalCount("0"); // 默认总数为0
  526 + type.setTotalCount(0); // 默认总数为0
517 527 type.setCompanyId(String.valueOf(resp.getId()));
518 528 type.setCompanyName(resp.getName());
519 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 535 // 6. 为每个业务线生成专属列表并赋值busiLine
527   - for (String type : busiLines) {
  536 + for (String type : busiLineArray) {
528 537 // 核心:通过map拷贝对象并设置busiLine,避免引用共享
529 538 List<WorkOrderTrendRespVo> busiLineList = newList.stream()
530 539 // 拷贝原对象,创建新对象并设置当前业务线
... ...
urbanops-module-garden/src/main/resources/mapper/homepage/HomepageSummaryMapper.xml
... ... @@ -254,35 +254,34 @@
254 254 </select>
255 255  
256 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 259 t.busi_line as busiLine,
259 260 t.worker_company_id as companyId,
260 261 <choose>
261 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 264 </when>
264 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 267 </when>
267 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 270 </when>
270 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 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 &lt;= #{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 &lt;= 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 285 </select>
287 286  
288 287 <!--已完成任务数量-->
... ...