Commit 49862a555a6077aa449313ca01f5f7d5b8671f4a

Authored by 王彪总
1 parent 0b01801a

refactor(garden): 优化巡查养护计划查询逻辑

- 显式JOIN替代隐式连接,提升SQL可读性
- 调整计划状态判断条件,关联明细表字段
- 补充时间范围过滤条件,确保数据准确性
- 修正养护计划类型字典键引用错误
- 统一未完成状态的时间区间判定逻辑
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/maintainplan/MaintainPlanServiceImpl.java
@@ -158,7 +158,7 @@ public class MaintainPlanServiceImpl implements MaintainPlanService { @@ -158,7 +158,7 @@ public class MaintainPlanServiceImpl implements MaintainPlanService {
158 maintainPlan.setRoadName(roadReqVO.getRoadName()); 158 maintainPlan.setRoadName(roadReqVO.getRoadName());
159 //计划属性label 159 //计划属性label
160 String planAttrLabel = DictFrameworkUtils.parseDictDataLabel(PlanConstants.GARDEN_PLAN_ATTR_REDIS_KEY, createReqVO.getPlanAttr()); 160 String planAttrLabel = DictFrameworkUtils.parseDictDataLabel(PlanConstants.GARDEN_PLAN_ATTR_REDIS_KEY, createReqVO.getPlanAttr());
161 - String planTypeIdLabel = DictFrameworkUtils.parseDictDataLabel(PlanConstants.INSPECTION_MAINTAIN_TYPE, createReqVO.getPlanTypeId()); 161 + String planTypeIdLabel = DictFrameworkUtils.parseDictDataLabel(PlanConstants.MAINTAIN_TYPE, createReqVO.getPlanTypeId());
162 String planNameSuffix = StringUtil.isNotEmpty(createReqVO.getPlanNameSuffix()) ? createReqVO.getPlanNameSuffix() : ""; 162 String planNameSuffix = StringUtil.isNotEmpty(createReqVO.getPlanNameSuffix()) ? createReqVO.getPlanNameSuffix() : "";
163 maintainPlan.setPlanName(roadReqVO.getRoadName() + planAttrLabel + planTypeIdLabel + planNameSuffix); 163 maintainPlan.setPlanName(roadReqVO.getRoadName() + planAttrLabel + planTypeIdLabel + planNameSuffix);
164 maintainPlanList.add(maintainPlan); 164 maintainPlanList.add(maintainPlan);
urbanops-module-garden/src/main/resources/mapper/inspectionplan/InspectionPlanMapper.xml
@@ -24,8 +24,10 @@ @@ -24,8 +24,10 @@
24 a.finish_state, 24 a.finish_state,
25 a.begin_time, 25 a.begin_time,
26 a.end_time 26 a.end_time
27 - FROM  
28 - garden_inspection_plan a 27 + FROM garden_inspection_plan a JOIN -- 建议用显式JOIN代替隐式连接,可读性更高
  28 + garden_inspection_plan_detail b ON
  29 + a.batch_no = b.batch_no
  30 + AND a.deleted = b.deleted
29 WHERE a.deleted = 0 31 WHERE a.deleted = 0
30 <if test="req.roadName != null and req.roadName !=''"> 32 <if test="req.roadName != null and req.roadName !=''">
31 AND a.road_name LIKE CONCAT('%',#{req.roadName},'%') 33 AND a.road_name LIKE CONCAT('%',#{req.roadName},'%')
@@ -44,14 +46,17 @@ @@ -44,14 +46,17 @@
44 </if> 46 </if>
45 <!--状态 1:未完成;2:已完成;3:已失效--> 47 <!--状态 1:未完成;2:已完成;3:已失效-->
46 <if test="req.finishState == 3"> 48 <if test="req.finishState == 3">
  49 + and b.finish_state = #{req.finishState}
47 <![CDATA[and a.end_time < #{req.localDate}]]> 50 <![CDATA[and a.end_time < #{req.localDate}]]>
48 </if> 51 </if>
49 <if test="req.finishState == 2"> 52 <if test="req.finishState == 2">
50 - and a.finish_state = #{req.finishState} 53 + and b.finish_state = #{req.finishState}
51 </if> 54 </if>
52 <if test="req.finishState == 1"> 55 <if test="req.finishState == 1">
53 - and a.finish_state = #{req.finishState} 56 + and b.finish_state = #{req.finishState}
54 <![CDATA[and a.end_time >= #{req.localDate}]]> 57 <![CDATA[and a.end_time >= #{req.localDate}]]>
  58 + <![CDATA[and b.end_time >= #{req.localDate}]]>
  59 + <![CDATA[and b.begin_time <= #{req.localDate}]]>
55 </if> 60 </if>
56 </select> 61 </select>
57 -</mapper>  
58 \ No newline at end of file 62 \ No newline at end of file
  63 +</mapper>
urbanops-module-garden/src/main/resources/mapper/maintainplan/MaintainPlanDetailMapper.xml
@@ -59,6 +59,8 @@ @@ -59,6 +59,8 @@
59 <if test="req.finishState == 1"> 59 <if test="req.finishState == 1">
60 and c.finish_state = #{req.finishState} 60 and c.finish_state = #{req.finishState}
61 <![CDATA[and c.end_time >= #{req.localDateTime}]]> 61 <![CDATA[and c.end_time >= #{req.localDateTime}]]>
  62 + <![CDATA[and c.begin_time <= #{req.localDateTime}]]>
  63 +
62 </if> 64 </if>
63 </select> 65 </select>
64 66
urbanops-module-garden/src/main/resources/mapper/maintainplan/MaintainPlanMapper.xml
@@ -26,8 +26,12 @@ @@ -26,8 +26,12 @@
26 a.end_time 26 a.end_time
27 FROM 27 FROM
28 garden_maintain_plan a 28 garden_maintain_plan a
29 - WHERE a.deleted=0  
30 - <if test="req.roadName != null and req.roadName !=''"> 29 + JOIN -- 建议用显式JOIN代替隐式连接,可读性更高
  30 + garden_maintain_plan_detail b ON
  31 + a.batch_no = b.batch_no
  32 + AND a.deleted = b.deleted
  33 + WHERE a.deleted = 0
  34 + <if test="req.roadName != null and req.roadName !=''">
31 AND a.road_name LIKE CONCAT('%',#{req.roadName},'%') 35 AND a.road_name LIKE CONCAT('%',#{req.roadName},'%')
32 </if> 36 </if>
33 <if test="req.batchNos != null and req.batchNos.size() > 0"> 37 <if test="req.batchNos != null and req.batchNos.size() > 0">
@@ -44,15 +48,17 @@ @@ -44,15 +48,17 @@
44 </if> 48 </if>
45 <!--状态 1:未完成;2:已完成;3:已失效--> 49 <!--状态 1:未完成;2:已完成;3:已失效-->
46 <if test="req.finishState == 3"> 50 <if test="req.finishState == 3">
47 - and a.finish_state = #{req.finishState} 51 + and b.finish_state = #{req.finishState}
48 <![CDATA[and a.end_time < #{req.localDate}]]> 52 <![CDATA[and a.end_time < #{req.localDate}]]>
49 </if> 53 </if>
50 <if test="req.finishState == 2"> 54 <if test="req.finishState == 2">
51 - and a.finish_state = #{req.finishState} 55 + and b.finish_state = #{req.finishState}
52 </if> 56 </if>
53 <if test="req.finishState == 1"> 57 <if test="req.finishState == 1">
54 - and a.finish_state = #{req.finishState} 58 + and b.finish_state = #{req.finishState}
55 <![CDATA[and a.end_time >= #{req.localDate}]]> 59 <![CDATA[and a.end_time >= #{req.localDate}]]>
  60 + <![CDATA[and b.end_time >= #{req.localDate}]]>
  61 + <![CDATA[and b.begin_time <= #{req.localDate}]]>
56 </if> 62 </if>
57 </select> 63 </select>
58 64
@@ -103,6 +109,8 @@ @@ -103,6 +109,8 @@
103 <if test="req.finishState == 1"> 109 <if test="req.finishState == 1">
104 and c.finish_state = #{req.finishState} 110 and c.finish_state = #{req.finishState}
105 <![CDATA[and c.end_time >= #{req.localDateTime}]]> 111 <![CDATA[and c.end_time >= #{req.localDateTime}]]>
  112 + <![CDATA[and c.begin_time <= #{req.localDateTime}]]>
  113 +
106 </if> 114 </if>
107 </select> 115 </select>
108 116