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 158 maintainPlan.setRoadName(roadReqVO.getRoadName());
159 159 //计划属性label
160 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 162 String planNameSuffix = StringUtil.isNotEmpty(createReqVO.getPlanNameSuffix()) ? createReqVO.getPlanNameSuffix() : "";
163 163 maintainPlan.setPlanName(roadReqVO.getRoadName() + planAttrLabel + planTypeIdLabel + planNameSuffix);
164 164 maintainPlanList.add(maintainPlan);
... ...
urbanops-module-garden/src/main/resources/mapper/inspectionplan/InspectionPlanMapper.xml
... ... @@ -24,8 +24,10 @@
24 24 a.finish_state,
25 25 a.begin_time,
26 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 31 WHERE a.deleted = 0
30 32 <if test="req.roadName != null and req.roadName !=''">
31 33 AND a.road_name LIKE CONCAT('%',#{req.roadName},'%')
... ... @@ -44,14 +46,17 @@
44 46 </if>
45 47 <!--状态 1:未完成;2:已完成;3:已失效-->
46 48 <if test="req.finishState == 3">
  49 + and b.finish_state = #{req.finishState}
47 50 <![CDATA[and a.end_time < #{req.localDate}]]>
48 51 </if>
49 52 <if test="req.finishState == 2">
50   - and a.finish_state = #{req.finishState}
  53 + and b.finish_state = #{req.finishState}
51 54 </if>
52 55 <if test="req.finishState == 1">
53   - and a.finish_state = #{req.finishState}
  56 + and b.finish_state = #{req.finishState}
54 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 60 </if>
56 61 </select>
57   -</mapper>
58 62 \ No newline at end of file
  63 +</mapper>
... ...
urbanops-module-garden/src/main/resources/mapper/maintainplan/MaintainPlanDetailMapper.xml
... ... @@ -59,6 +59,8 @@
59 59 <if test="req.finishState == 1">
60 60 and c.finish_state = #{req.finishState}
61 61 <![CDATA[and c.end_time >= #{req.localDateTime}]]>
  62 + <![CDATA[and c.begin_time <= #{req.localDateTime}]]>
  63 +
62 64 </if>
63 65 </select>
64 66  
... ...
urbanops-module-garden/src/main/resources/mapper/maintainplan/MaintainPlanMapper.xml
... ... @@ -26,8 +26,12 @@
26 26 a.end_time
27 27 FROM
28 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 35 AND a.road_name LIKE CONCAT('%',#{req.roadName},'%')
32 36 </if>
33 37 <if test="req.batchNos != null and req.batchNos.size() > 0">
... ... @@ -44,15 +48,17 @@
44 48 </if>
45 49 <!--状态 1:未完成;2:已完成;3:已失效-->
46 50 <if test="req.finishState == 3">
47   - and a.finish_state = #{req.finishState}
  51 + and b.finish_state = #{req.finishState}
48 52 <![CDATA[and a.end_time < #{req.localDate}]]>
49 53 </if>
50 54 <if test="req.finishState == 2">
51   - and a.finish_state = #{req.finishState}
  55 + and b.finish_state = #{req.finishState}
52 56 </if>
53 57 <if test="req.finishState == 1">
54   - and a.finish_state = #{req.finishState}
  58 + and b.finish_state = #{req.finishState}
55 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 62 </if>
57 63 </select>
58 64  
... ... @@ -103,6 +109,8 @@
103 109 <if test="req.finishState == 1">
104 110 and c.finish_state = #{req.finishState}
105 111 <![CDATA[and c.end_time >= #{req.localDateTime}]]>
  112 + <![CDATA[and c.begin_time <= #{req.localDateTime}]]>
  113 +
106 114 </if>
107 115 </select>
108 116  
... ...