Commit bab40751b3bb69f89a7c20ba314c45aa70a2fda8

Authored by 王富生
1 parent eb36f943

app养护计划明细提交

urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/inspectionplan/InspectionPlanController.java
1 package com.zteits.urbanops.module.garden.controller.admin.inspectionplan; 1 package com.zteits.urbanops.module.garden.controller.admin.inspectionplan;
2 2
  3 +import com.zteits.urbanops.module.garden.util.StringValidateUtil;
3 import jakarta.validation.constraints.NotBlank; 4 import jakarta.validation.constraints.NotBlank;
4 import lombok.extern.slf4j.Slf4j; 5 import lombok.extern.slf4j.Slf4j;
5 import org.springframework.web.bind.annotation.*; 6 import org.springframework.web.bind.annotation.*;
@@ -29,6 +30,7 @@ import com.zteits.urbanops.framework.excel.core.util.ExcelUtils; @@ -29,6 +30,7 @@ import com.zteits.urbanops.framework.excel.core.util.ExcelUtils;
29 import com.zteits.urbanops.framework.apilog.core.annotation.ApiAccessLog; 30 import com.zteits.urbanops.framework.apilog.core.annotation.ApiAccessLog;
30 import static com.zteits.urbanops.framework.apilog.core.enums.OperateTypeEnum.*; 31 import static com.zteits.urbanops.framework.apilog.core.enums.OperateTypeEnum.*;
31 import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RATE_VALUE_ERROR; 32 import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RATE_VALUE_ERROR;
  33 +import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RATE_VALUE_INTEGER_ERROR;
32 34
33 import com.zteits.urbanops.module.garden.controller.admin.inspectionplan.vo.*; 35 import com.zteits.urbanops.module.garden.controller.admin.inspectionplan.vo.*;
34 import com.zteits.urbanops.module.garden.dal.dataobject.inspectionplan.InspectionPlanDO; 36 import com.zteits.urbanops.module.garden.dal.dataobject.inspectionplan.InspectionPlanDO;
@@ -52,6 +54,12 @@ public class InspectionPlanController { @@ -52,6 +54,12 @@ public class InspectionPlanController {
52 log.warn("次数值范围:1-10或者分数格式:1/3, rateValue={}", createReqVO.getRateValue()); 54 log.warn("次数值范围:1-10或者分数格式:1/3, rateValue={}", createReqVO.getRateValue());
53 return error(PLAN_RATE_VALUE_ERROR); 55 return error(PLAN_RATE_VALUE_ERROR);
54 } 56 }
  57 + //3002 临时计划
  58 + if(createReqVO.getPlanTypeId().equals(3002)){
  59 + if(!StringValidateUtil.isValidNumberStr(createReqVO.getRateValue())){
  60 + return error(PLAN_RATE_VALUE_INTEGER_ERROR);
  61 + }
  62 + }
55 63
56 return inspectionPlanService.createInspectionPlan(createReqVO); 64 return inspectionPlanService.createInspectionPlan(createReqVO);
57 } 65 }
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/maintainplan/MaintainPlanController.java
1 package com.zteits.urbanops.module.garden.controller.admin.maintainplan; 1 package com.zteits.urbanops.module.garden.controller.admin.maintainplan;
2 2
  3 +import com.zteits.urbanops.module.garden.util.StringValidateUtil;
3 import jakarta.validation.constraints.NotBlank; 4 import jakarta.validation.constraints.NotBlank;
4 import lombok.extern.slf4j.Slf4j; 5 import lombok.extern.slf4j.Slf4j;
5 import org.springframework.web.bind.annotation.*; 6 import org.springframework.web.bind.annotation.*;
@@ -28,6 +29,7 @@ import com.zteits.urbanops.framework.excel.core.util.ExcelUtils; @@ -28,6 +29,7 @@ import com.zteits.urbanops.framework.excel.core.util.ExcelUtils;
28 import com.zteits.urbanops.framework.apilog.core.annotation.ApiAccessLog; 29 import com.zteits.urbanops.framework.apilog.core.annotation.ApiAccessLog;
29 import static com.zteits.urbanops.framework.apilog.core.enums.OperateTypeEnum.*; 30 import static com.zteits.urbanops.framework.apilog.core.enums.OperateTypeEnum.*;
30 import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RATE_VALUE_ERROR; 31 import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RATE_VALUE_ERROR;
  32 +import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RATE_VALUE_INTEGER_ERROR;
31 33
32 import com.zteits.urbanops.module.garden.controller.admin.maintainplan.vo.*; 34 import com.zteits.urbanops.module.garden.controller.admin.maintainplan.vo.*;
33 import com.zteits.urbanops.module.garden.dal.dataobject.maintainplan.MaintainPlanDO; 35 import com.zteits.urbanops.module.garden.dal.dataobject.maintainplan.MaintainPlanDO;
@@ -51,6 +53,14 @@ public class MaintainPlanController { @@ -51,6 +53,14 @@ public class MaintainPlanController {
51 log.warn("次数值范围:1-10或者分数格式:1/3, rateValue={}", createReqVO.getRateValue()); 53 log.warn("次数值范围:1-10或者分数格式:1/3, rateValue={}", createReqVO.getRateValue());
52 return error(PLAN_RATE_VALUE_ERROR); 54 return error(PLAN_RATE_VALUE_ERROR);
53 } 55 }
  56 +
  57 + //3002 临时计划
  58 + if(createReqVO.getPlanTypeId().equals(20010)){
  59 + if(!StringValidateUtil.isValidNumberStr(createReqVO.getRateValue())){
  60 + return error(PLAN_RATE_VALUE_INTEGER_ERROR);
  61 + }
  62 + }
  63 +
54 return maintainPlanService.createMaintainPlan(createReqVO); 64 return maintainPlanService.createMaintainPlan(createReqVO);
55 } 65 }
56 66
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/enums/ErrorCodeConstants.java
@@ -97,6 +97,7 @@ public interface ErrorCodeConstants { @@ -97,6 +97,7 @@ public interface ErrorCodeConstants {
97 ErrorCode PLAN_RATE_NOT_EXISTS = new ErrorCode(1-100-007-002, "未配置计划频次"); 97 ErrorCode PLAN_RATE_NOT_EXISTS = new ErrorCode(1-100-007-002, "未配置计划频次");
98 ErrorCode PLAN_RATE_DETAIL_EXISTS = new ErrorCode(1-100-007-003, "计划频次已存在"); 98 ErrorCode PLAN_RATE_DETAIL_EXISTS = new ErrorCode(1-100-007-003, "计划频次已存在");
99 ErrorCode PLAN_RATE_VALUE_ERROR = new ErrorCode(1-100-007-004, "次数值范围:1-10或者分数格式:1/3"); 99 ErrorCode PLAN_RATE_VALUE_ERROR = new ErrorCode(1-100-007-004, "次数值范围:1-10或者分数格式:1/3");
  100 + ErrorCode PLAN_RATE_VALUE_INTEGER_ERROR = new ErrorCode(1-100-007-005, "临时计划-次数值范围:1-20的整数");
100 101
101 ErrorCode MATERIAL_TYPE_NOT_EXISTS = new ErrorCode(1-100-004-001, "物料类型不存在"); 102 ErrorCode MATERIAL_TYPE_NOT_EXISTS = new ErrorCode(1-100-004-001, "物料类型不存在");
102 ErrorCode MATERIAL_TYPE_MANAGER_NOT_EXISTS = new ErrorCode(1-100-004-002, "耗材类别管理不存在"); 103 ErrorCode MATERIAL_TYPE_MANAGER_NOT_EXISTS = new ErrorCode(1-100-004-002, "耗材类别管理不存在");
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/inspectionplan/InspectionPlanServiceImpl.java
@@ -92,17 +92,29 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { @@ -92,17 +92,29 @@ public class InspectionPlanServiceImpl implements InspectionPlanService {
92 if (createReqVO.getRateValue().contains("/")) { 92 if (createReqVO.getRateValue().contains("/")) {
93 rateValue = createReqVO.getRateValue().trim(); 93 rateValue = createReqVO.getRateValue().trim();
94 } else { 94 } else {
95 - rateValue = createReqVO.getRateValue().trim()+"/1"; 95 + rateValue = createReqVO.getRateValue().trim() + "/1";
96 } 96 }
97 //计算开始和计算时间 在间隔周期下每天的次数 97 //计算开始和计算时间 在间隔周期下每天的次数
98 - List<PeriodResult> calculate = TimeIntervalFrequencyUtil.calculate(createReqVO.getBeginTime().toString(), createReqVO.getEndTime().toString(), rateValue, createReqVO.getCycleId());  
99 - if (CollectionUtils.isEmpty(calculate)) {  
100 - log.warn("获取两个时间之间间隔天数错误");  
101 - return CommonResult.error(INSPECTION_CYCLE_ERROR); 98 + List<PeriodResult> calculate;
  99 + //计算计划次数
  100 + int planNum;
  101 + //临时计划
  102 + if (createReqVO.getPlanTypeId().equals(3002)) {
  103 + calculate = new ArrayList<>();
  104 + PeriodResult periodResult = new PeriodResult(createReqVO.getBeginTime(), createReqVO.getEndTime(), Integer.parseInt(createReqVO.getRateValue()));
  105 + calculate.add(periodResult);
  106 + planNum = Integer.parseInt(createReqVO.getRateValue());
  107 + }else{
  108 + calculate= TimeIntervalFrequencyUtil.calculate(createReqVO.getBeginTime().toString(), createReqVO.getEndTime().toString(), rateValue, createReqVO.getCycleId());
  109 + if (CollectionUtils.isEmpty(calculate)) {
  110 + log.warn("获取两个时间之间间隔天数错误");
  111 + return CommonResult.error(INSPECTION_CYCLE_ERROR);
  112 + }
  113 + //计算计划次数
  114 + planNum = calculate.stream().mapToInt(PeriodResult::getCount).sum();
102 } 115 }
103 116
104 - //计算计划次数  
105 - int planNum = calculate.stream().mapToInt(PeriodResult::getCount).sum(); 117 +
106 //巡检计划list 118 //巡检计划list
107 List<InspectionPlanDO> inspectionPlanList = new ArrayList<>(); 119 List<InspectionPlanDO> inspectionPlanList = new ArrayList<>();
108 //角色列表 120 //角色列表
@@ -112,7 +124,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { @@ -112,7 +124,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService {
112 //按照道路创建计划 124 //按照道路创建计划
113 createReqVO.getRoadListReqVO().forEach(roadReqVO -> { 125 createReqVO.getRoadListReqVO().forEach(roadReqVO -> {
114 InspectionPlanDO inspectionPlan = BeanUtils.toBean(createReqVO, InspectionPlanDO.class); 126 InspectionPlanDO inspectionPlan = BeanUtils.toBean(createReqVO, InspectionPlanDO.class);
115 - String batchNo = "BN" + System.currentTimeMillis() + RandomUtil.randomInt(1000 , 9999) + roadReqVO.getRoadId(); 127 + String batchNo = "BN" + System.currentTimeMillis() + RandomUtil.randomInt(1000, 9999) + roadReqVO.getRoadId();
116 inspectionPlan.setBatchNo(batchNo); 128 inspectionPlan.setBatchNo(batchNo);
117 inspectionPlan.setPlanFinishNum(0); 129 inspectionPlan.setPlanFinishNum(0);
118 inspectionPlan.setFinishState(FinishStateEnum.NOT_FINISHED.getStatus()); 130 inspectionPlan.setFinishState(FinishStateEnum.NOT_FINISHED.getStatus());
@@ -130,7 +142,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { @@ -130,7 +142,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService {
130 //计划属性label 142 //计划属性label
131 String planAttrLabel = DictFrameworkUtils.parseDictDataLabel(PlanConstants.GARDEN_PLAN_ATTR_REDIS_KEY, createReqVO.getPlanAttr()); 143 String planAttrLabel = DictFrameworkUtils.parseDictDataLabel(PlanConstants.GARDEN_PLAN_ATTR_REDIS_KEY, createReqVO.getPlanAttr());
132 String planTypeIdLabel = DictFrameworkUtils.parseDictDataLabel(PlanConstants.INSPECTION_MAINTAIN_TYPE, createReqVO.getPlanTypeId()); 144 String planTypeIdLabel = DictFrameworkUtils.parseDictDataLabel(PlanConstants.INSPECTION_MAINTAIN_TYPE, createReqVO.getPlanTypeId());
133 - String planNameSuffix = StringUtil.isNotEmpty(createReqVO.getPlanNameSuffix()) ? createReqVO.getPlanNameSuffix() :""; 145 + String planNameSuffix = StringUtil.isNotEmpty(createReqVO.getPlanNameSuffix()) ? createReqVO.getPlanNameSuffix() : "";
134 inspectionPlan.setPlanName(roadReqVO.getRoadName() + planAttrLabel + planTypeIdLabel + planNameSuffix); 146 inspectionPlan.setPlanName(roadReqVO.getRoadName() + planAttrLabel + planTypeIdLabel + planNameSuffix);
135 inspectionPlanList.add(inspectionPlan); 147 inspectionPlanList.add(inspectionPlan);
136 /*2.插入角色*/ 148 /*2.插入角色*/
@@ -174,7 +186,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { @@ -174,7 +186,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService {
174 String userName = SecurityFrameworkUtils.getLoginUserNickname(); 186 String userName = SecurityFrameworkUtils.getLoginUserNickname();
175 InspectionPlanDetailDO entity = new InspectionPlanDetailDO(); 187 InspectionPlanDetailDO entity = new InspectionPlanDetailDO();
176 entity.setBatchNo(batchNo); 188 entity.setBatchNo(batchNo);
177 - entity.setPlanNo("X" + System.currentTimeMillis() + RandomUtil.randomInt(1000 , 9999)); 189 + entity.setPlanNo("X" + System.currentTimeMillis() + RandomUtil.randomInt(1000, 9999));
178 entity.setBusiLine(saveReqVO.getBusiLine()); 190 entity.setBusiLine(saveReqVO.getBusiLine());
179 entity.setCompanyId(saveReqVO.getCompanyId()); 191 entity.setCompanyId(saveReqVO.getCompanyId());
180 entity.setDeptId(roadReqVO.getDeptId()); 192 entity.setDeptId(roadReqVO.getDeptId());
@@ -265,11 +277,12 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { @@ -265,11 +277,12 @@ public class InspectionPlanServiceImpl implements InspectionPlanService {
265 277
266 /** 278 /**
267 * 回填部门/公司/角色 279 * 回填部门/公司/角色
  280 + *
268 * @param list 分页对象 281 * @param list 分页对象
269 */ 282 */
270 - private void addDataInspectionPlan(List<InspectionPlanRespVO> list ){  
271 - if(CollectionUtils.isEmpty(list)){  
272 - return ; 283 + private void addDataInspectionPlan(List<InspectionPlanRespVO> list) {
  284 + if (CollectionUtils.isEmpty(list)) {
  285 + return;
273 } 286 }
274 //公司 287 //公司
275 Set<Long> companyIds = list.stream().map(InspectionPlanRespVO::getCompanyId).collect(Collectors.toSet()); 288 Set<Long> companyIds = list.stream().map(InspectionPlanRespVO::getCompanyId).collect(Collectors.toSet());
@@ -280,22 +293,22 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { @@ -280,22 +293,22 @@ public class InspectionPlanServiceImpl implements InspectionPlanService {
280 Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(deptIds); 293 Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(deptIds);
281 294
282 list.forEach(plan -> { 295 list.forEach(plan -> {
283 - DeptRespDTO dept = deptMap.get(plan.getDeptId()); 296 + DeptRespDTO dept = deptMap.get(plan.getDeptId());
284 if (dept != null) { 297 if (dept != null) {
285 plan.setDeptName(dept.getName()); 298 plan.setDeptName(dept.getName());
286 299
287 } 300 }
288 - DeptRespDTO company = deptMap.get(plan.getCompanyId());  
289 - if(company != null){ 301 + DeptRespDTO company = deptMap.get(plan.getCompanyId());
  302 + if (company != null) {
290 plan.setCompanyName(company.getName()); 303 plan.setCompanyName(company.getName());
291 } 304 }
292 List<InspectionPlanRoleDO> roleList = inspectionPlanRoleMapper.selectList(new QueryWrapper<InspectionPlanRoleDO>().lambda() 305 List<InspectionPlanRoleDO> roleList = inspectionPlanRoleMapper.selectList(new QueryWrapper<InspectionPlanRoleDO>().lambda()
293 .eq(InspectionPlanRoleDO::getBatchNo, plan.getBatchNo())); 306 .eq(InspectionPlanRoleDO::getBatchNo, plan.getBatchNo()));
294 307
295 Set<Long> roleIds = roleList.stream().map(InspectionPlanRoleDO::getRoleId).collect(Collectors.toSet()); 308 Set<Long> roleIds = roleList.stream().map(InspectionPlanRoleDO::getRoleId).collect(Collectors.toSet());
296 - if(!CollectionUtils.isEmpty(roleIds)){ 309 + if (!CollectionUtils.isEmpty(roleIds)) {
297 List<RoleDO> roles = roleApi.getRoleList(roleIds); 310 List<RoleDO> roles = roleApi.getRoleList(roleIds);
298 - if(!CollectionUtils.isEmpty(roles)){ 311 + if (!CollectionUtils.isEmpty(roles)) {
299 plan.setRoleNameList(roles.stream().map(RoleDO::getName).collect(Collectors.toList())); 312 plan.setRoleNameList(roles.stream().map(RoleDO::getName).collect(Collectors.toList()));
300 } 313 }
301 } 314 }
@@ -341,9 +354,9 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { @@ -341,9 +354,9 @@ public class InspectionPlanServiceImpl implements InspectionPlanService {
341 return new PageResult<>(page.getRecords(), page.getTotal()); 354 return new PageResult<>(page.getRecords(), page.getTotal());
342 } 355 }
343 356
344 - private void addStreetInfo(List<AppInspectionPlanRespVO> list){  
345 - if(CollectionUtils.isEmpty(list)){  
346 - return ; 357 + private void addStreetInfo(List<AppInspectionPlanRespVO> list) {
  358 + if (CollectionUtils.isEmpty(list)) {
  359 + return;
347 } 360 }
348 Set<Long> roadIds = list.stream().map(AppInspectionPlanRespVO::getRoadId).collect(Collectors.toSet()); 361 Set<Long> roadIds = list.stream().map(AppInspectionPlanRespVO::getRoadId).collect(Collectors.toSet());
349 362
@@ -354,7 +367,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { @@ -354,7 +367,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService {
354 367
355 list.forEach(plan -> { 368 list.forEach(plan -> {
356 RoadDO road = roadMap.get(plan.getRoadId()); 369 RoadDO road = roadMap.get(plan.getRoadId());
357 - if(road != null){ 370 + if (road != null) {
358 plan.setStreetId(road.getStreetId()); 371 plan.setStreetId(road.getStreetId());
359 plan.setStreetName(road.getStreetName()); 372 plan.setStreetName(road.getStreetName());
360 } 373 }
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/maintainplan/MaintainPlanServiceImpl.java
@@ -102,13 +102,24 @@ public class MaintainPlanServiceImpl implements MaintainPlanService { @@ -102,13 +102,24 @@ public class MaintainPlanServiceImpl implements MaintainPlanService {
102 rateValue = createReqVO.getRateValue().trim() + "/1"; 102 rateValue = createReqVO.getRateValue().trim() + "/1";
103 } 103 }
104 //计算开始和计算时间 在间隔周期下每天的次数 104 //计算开始和计算时间 在间隔周期下每天的次数
105 - List<PeriodResult> calculate = TimeIntervalFrequencyUtil.calculate(createReqVO.getBeginTime().toString(), createReqVO.getEndTime().toString(), rateValue, createReqVO.getCycleId());  
106 - if (CollectionUtils.isEmpty(calculate)) {  
107 - log.warn("获取两个时间之间间隔天数错误");  
108 - return CommonResult.error(INSPECTION_CYCLE_ERROR);  
109 - } 105 + List<PeriodResult> calculate;
110 //计算计划次数 106 //计算计划次数
111 - int planNum = calculate.stream().mapToInt(PeriodResult::getCount).sum(); 107 + int planNum;
  108 + //临时计划比较特殊
  109 + if (createReqVO.getPlanTypeId().equals(20010)) {
  110 + calculate = new ArrayList<>();
  111 + PeriodResult periodResult = new PeriodResult(createReqVO.getBeginTime(), createReqVO.getEndTime(), Integer.parseInt(createReqVO.getRateValue()));
  112 + calculate.add(periodResult);
  113 + planNum = Integer.parseInt(createReqVO.getRateValue());
  114 + }else{
  115 + calculate= TimeIntervalFrequencyUtil.calculate(createReqVO.getBeginTime().toString(), createReqVO.getEndTime().toString(), rateValue, createReqVO.getCycleId());
  116 + if (CollectionUtils.isEmpty(calculate)) {
  117 + log.warn("获取两个时间之间间隔天数错误");
  118 + return CommonResult.error(INSPECTION_CYCLE_ERROR);
  119 + }
  120 + //计算计划次数
  121 + planNum = calculate.stream().mapToInt(PeriodResult::getCount).sum();
  122 + }
112 //巡检计划list 123 //巡检计划list
113 List<MaintainPlanDO> maintainPlanList = new ArrayList<>(); 124 List<MaintainPlanDO> maintainPlanList = new ArrayList<>();
114 //角色列表 125 //角色列表
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/util/StringValidateUtil.java
@@ -88,6 +88,33 @@ public class StringValidateUtil { @@ -88,6 +88,33 @@ public class StringValidateUtil {
88 return true; 88 return true;
89 } 89 }
90 90
  91 + /**
  92 + * 校验字符串是否为 1-20 的整数(包含1和20)
  93 + * @param str 待校验的字符串(允许null/空串)
  94 + * @return 校验通过返回true,否则false
  95 + */
  96 + public static boolean isValidNumberStr(String str) {
  97 + // 1. 空值/空串校验
  98 + if (str == null || str.trim().isEmpty()) {
  99 + return false;
  100 + }
  101 +
  102 + // 2. 校验是否为纯数字(排除字母、符号、小数)
  103 + if (!str.matches("^\\d+$")) {
  104 + return false;
  105 + }
  106 +
  107 + // 3. 转换为数字并校验范围
  108 + try {
  109 + int number = Integer.parseInt(str);
  110 + return number >= 1 && number <= 20;
  111 + } catch (NumberFormatException e) {
  112 + // 理论上不会走到这里(已通过正则校验),兜底处理
  113 + return false;
  114 + }
  115 + }
  116 +
  117 +
91 // 测试用例 118 // 测试用例
92 public static void main(String[] args) { 119 public static void main(String[] args) {
93 // 测试符合规则的情况 120 // 测试符合规则的情况