diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/inspectionplan/InspectionPlanController.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/inspectionplan/InspectionPlanController.java index b11bc59..773f303 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/inspectionplan/InspectionPlanController.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/inspectionplan/InspectionPlanController.java @@ -1,5 +1,6 @@ package com.zteits.urbanops.module.garden.controller.admin.inspectionplan; +import com.zteits.urbanops.module.garden.util.StringValidateUtil; import jakarta.validation.constraints.NotBlank; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; @@ -29,6 +30,7 @@ import com.zteits.urbanops.framework.excel.core.util.ExcelUtils; import com.zteits.urbanops.framework.apilog.core.annotation.ApiAccessLog; import static com.zteits.urbanops.framework.apilog.core.enums.OperateTypeEnum.*; import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RATE_VALUE_ERROR; +import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RATE_VALUE_INTEGER_ERROR; import com.zteits.urbanops.module.garden.controller.admin.inspectionplan.vo.*; import com.zteits.urbanops.module.garden.dal.dataobject.inspectionplan.InspectionPlanDO; @@ -52,6 +54,12 @@ public class InspectionPlanController { log.warn("次数值范围:1-10或者分数格式:1/3, rateValue={}", createReqVO.getRateValue()); return error(PLAN_RATE_VALUE_ERROR); } + //3002 临时计划 + if(createReqVO.getPlanTypeId().equals(3002)){ + if(!StringValidateUtil.isValidNumberStr(createReqVO.getRateValue())){ + return error(PLAN_RATE_VALUE_INTEGER_ERROR); + } + } return inspectionPlanService.createInspectionPlan(createReqVO); } diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/maintainplan/MaintainPlanController.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/maintainplan/MaintainPlanController.java index cbcd97d..a74205f 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/maintainplan/MaintainPlanController.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/maintainplan/MaintainPlanController.java @@ -1,5 +1,6 @@ package com.zteits.urbanops.module.garden.controller.admin.maintainplan; +import com.zteits.urbanops.module.garden.util.StringValidateUtil; import jakarta.validation.constraints.NotBlank; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; @@ -28,6 +29,7 @@ import com.zteits.urbanops.framework.excel.core.util.ExcelUtils; import com.zteits.urbanops.framework.apilog.core.annotation.ApiAccessLog; import static com.zteits.urbanops.framework.apilog.core.enums.OperateTypeEnum.*; import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RATE_VALUE_ERROR; +import static com.zteits.urbanops.module.garden.enums.ErrorCodeConstants.PLAN_RATE_VALUE_INTEGER_ERROR; import com.zteits.urbanops.module.garden.controller.admin.maintainplan.vo.*; import com.zteits.urbanops.module.garden.dal.dataobject.maintainplan.MaintainPlanDO; @@ -51,6 +53,14 @@ public class MaintainPlanController { log.warn("次数值范围:1-10或者分数格式:1/3, rateValue={}", createReqVO.getRateValue()); return error(PLAN_RATE_VALUE_ERROR); } + + //3002 临时计划 + if(createReqVO.getPlanTypeId().equals(20010)){ + if(!StringValidateUtil.isValidNumberStr(createReqVO.getRateValue())){ + return error(PLAN_RATE_VALUE_INTEGER_ERROR); + } + } + return maintainPlanService.createMaintainPlan(createReqVO); } diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/enums/ErrorCodeConstants.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/enums/ErrorCodeConstants.java index fac65a8..f7e2af6 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/enums/ErrorCodeConstants.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/enums/ErrorCodeConstants.java @@ -97,6 +97,7 @@ public interface ErrorCodeConstants { ErrorCode PLAN_RATE_NOT_EXISTS = new ErrorCode(1-100-007-002, "未配置计划频次"); ErrorCode PLAN_RATE_DETAIL_EXISTS = new ErrorCode(1-100-007-003, "计划频次已存在"); ErrorCode PLAN_RATE_VALUE_ERROR = new ErrorCode(1-100-007-004, "次数值范围:1-10或者分数格式:1/3"); + ErrorCode PLAN_RATE_VALUE_INTEGER_ERROR = new ErrorCode(1-100-007-005, "临时计划-次数值范围:1-20的整数"); ErrorCode MATERIAL_TYPE_NOT_EXISTS = new ErrorCode(1-100-004-001, "物料类型不存在"); ErrorCode MATERIAL_TYPE_MANAGER_NOT_EXISTS = new ErrorCode(1-100-004-002, "耗材类别管理不存在"); diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/inspectionplan/InspectionPlanServiceImpl.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/inspectionplan/InspectionPlanServiceImpl.java index 6f15c50..62f9dfc 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/inspectionplan/InspectionPlanServiceImpl.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/inspectionplan/InspectionPlanServiceImpl.java @@ -92,17 +92,29 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { if (createReqVO.getRateValue().contains("/")) { rateValue = createReqVO.getRateValue().trim(); } else { - rateValue = createReqVO.getRateValue().trim()+"/1"; + rateValue = createReqVO.getRateValue().trim() + "/1"; } //计算开始和计算时间 在间隔周期下每天的次数 - List calculate = TimeIntervalFrequencyUtil.calculate(createReqVO.getBeginTime().toString(), createReqVO.getEndTime().toString(), rateValue, createReqVO.getCycleId()); - if (CollectionUtils.isEmpty(calculate)) { - log.warn("获取两个时间之间间隔天数错误"); - return CommonResult.error(INSPECTION_CYCLE_ERROR); + List calculate; + //计算计划次数 + int planNum; + //临时计划 + if (createReqVO.getPlanTypeId().equals(3002)) { + calculate = new ArrayList<>(); + PeriodResult periodResult = new PeriodResult(createReqVO.getBeginTime(), createReqVO.getEndTime(), Integer.parseInt(createReqVO.getRateValue())); + calculate.add(periodResult); + planNum = Integer.parseInt(createReqVO.getRateValue()); + }else{ + calculate= TimeIntervalFrequencyUtil.calculate(createReqVO.getBeginTime().toString(), createReqVO.getEndTime().toString(), rateValue, createReqVO.getCycleId()); + if (CollectionUtils.isEmpty(calculate)) { + log.warn("获取两个时间之间间隔天数错误"); + return CommonResult.error(INSPECTION_CYCLE_ERROR); + } + //计算计划次数 + planNum = calculate.stream().mapToInt(PeriodResult::getCount).sum(); } - //计算计划次数 - int planNum = calculate.stream().mapToInt(PeriodResult::getCount).sum(); + //巡检计划list List inspectionPlanList = new ArrayList<>(); //角色列表 @@ -112,7 +124,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { //按照道路创建计划 createReqVO.getRoadListReqVO().forEach(roadReqVO -> { InspectionPlanDO inspectionPlan = BeanUtils.toBean(createReqVO, InspectionPlanDO.class); - String batchNo = "BN" + System.currentTimeMillis() + RandomUtil.randomInt(1000 , 9999) + roadReqVO.getRoadId(); + String batchNo = "BN" + System.currentTimeMillis() + RandomUtil.randomInt(1000, 9999) + roadReqVO.getRoadId(); inspectionPlan.setBatchNo(batchNo); inspectionPlan.setPlanFinishNum(0); inspectionPlan.setFinishState(FinishStateEnum.NOT_FINISHED.getStatus()); @@ -130,7 +142,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { //计划属性label String planAttrLabel = DictFrameworkUtils.parseDictDataLabel(PlanConstants.GARDEN_PLAN_ATTR_REDIS_KEY, createReqVO.getPlanAttr()); String planTypeIdLabel = DictFrameworkUtils.parseDictDataLabel(PlanConstants.INSPECTION_MAINTAIN_TYPE, createReqVO.getPlanTypeId()); - String planNameSuffix = StringUtil.isNotEmpty(createReqVO.getPlanNameSuffix()) ? createReqVO.getPlanNameSuffix() :""; + String planNameSuffix = StringUtil.isNotEmpty(createReqVO.getPlanNameSuffix()) ? createReqVO.getPlanNameSuffix() : ""; inspectionPlan.setPlanName(roadReqVO.getRoadName() + planAttrLabel + planTypeIdLabel + planNameSuffix); inspectionPlanList.add(inspectionPlan); /*2.插入角色*/ @@ -174,7 +186,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { String userName = SecurityFrameworkUtils.getLoginUserNickname(); InspectionPlanDetailDO entity = new InspectionPlanDetailDO(); entity.setBatchNo(batchNo); - entity.setPlanNo("X" + System.currentTimeMillis() + RandomUtil.randomInt(1000 , 9999)); + entity.setPlanNo("X" + System.currentTimeMillis() + RandomUtil.randomInt(1000, 9999)); entity.setBusiLine(saveReqVO.getBusiLine()); entity.setCompanyId(saveReqVO.getCompanyId()); entity.setDeptId(roadReqVO.getDeptId()); @@ -265,11 +277,12 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { /** * 回填部门/公司/角色 + * * @param list 分页对象 */ - private void addDataInspectionPlan(List list ){ - if(CollectionUtils.isEmpty(list)){ - return ; + private void addDataInspectionPlan(List list) { + if (CollectionUtils.isEmpty(list)) { + return; } //公司 Set companyIds = list.stream().map(InspectionPlanRespVO::getCompanyId).collect(Collectors.toSet()); @@ -280,22 +293,22 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { Map deptMap = deptApi.getDeptMap(deptIds); list.forEach(plan -> { - DeptRespDTO dept = deptMap.get(plan.getDeptId()); + DeptRespDTO dept = deptMap.get(plan.getDeptId()); if (dept != null) { plan.setDeptName(dept.getName()); } - DeptRespDTO company = deptMap.get(plan.getCompanyId()); - if(company != null){ + DeptRespDTO company = deptMap.get(plan.getCompanyId()); + if (company != null) { plan.setCompanyName(company.getName()); } List roleList = inspectionPlanRoleMapper.selectList(new QueryWrapper().lambda() .eq(InspectionPlanRoleDO::getBatchNo, plan.getBatchNo())); Set roleIds = roleList.stream().map(InspectionPlanRoleDO::getRoleId).collect(Collectors.toSet()); - if(!CollectionUtils.isEmpty(roleIds)){ + if (!CollectionUtils.isEmpty(roleIds)) { List roles = roleApi.getRoleList(roleIds); - if(!CollectionUtils.isEmpty(roles)){ + if (!CollectionUtils.isEmpty(roles)) { plan.setRoleNameList(roles.stream().map(RoleDO::getName).collect(Collectors.toList())); } } @@ -341,9 +354,9 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { return new PageResult<>(page.getRecords(), page.getTotal()); } - private void addStreetInfo(List list){ - if(CollectionUtils.isEmpty(list)){ - return ; + private void addStreetInfo(List list) { + if (CollectionUtils.isEmpty(list)) { + return; } Set roadIds = list.stream().map(AppInspectionPlanRespVO::getRoadId).collect(Collectors.toSet()); @@ -354,7 +367,7 @@ public class InspectionPlanServiceImpl implements InspectionPlanService { list.forEach(plan -> { RoadDO road = roadMap.get(plan.getRoadId()); - if(road != null){ + if (road != null) { plan.setStreetId(road.getStreetId()); plan.setStreetName(road.getStreetName()); } diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/maintainplan/MaintainPlanServiceImpl.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/maintainplan/MaintainPlanServiceImpl.java index 03cca94..3d70561 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/maintainplan/MaintainPlanServiceImpl.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/maintainplan/MaintainPlanServiceImpl.java @@ -102,13 +102,24 @@ public class MaintainPlanServiceImpl implements MaintainPlanService { rateValue = createReqVO.getRateValue().trim() + "/1"; } //计算开始和计算时间 在间隔周期下每天的次数 - List calculate = TimeIntervalFrequencyUtil.calculate(createReqVO.getBeginTime().toString(), createReqVO.getEndTime().toString(), rateValue, createReqVO.getCycleId()); - if (CollectionUtils.isEmpty(calculate)) { - log.warn("获取两个时间之间间隔天数错误"); - return CommonResult.error(INSPECTION_CYCLE_ERROR); - } + List calculate; //计算计划次数 - int planNum = calculate.stream().mapToInt(PeriodResult::getCount).sum(); + int planNum; + //临时计划比较特殊 + if (createReqVO.getPlanTypeId().equals(20010)) { + calculate = new ArrayList<>(); + PeriodResult periodResult = new PeriodResult(createReqVO.getBeginTime(), createReqVO.getEndTime(), Integer.parseInt(createReqVO.getRateValue())); + calculate.add(periodResult); + planNum = Integer.parseInt(createReqVO.getRateValue()); + }else{ + calculate= TimeIntervalFrequencyUtil.calculate(createReqVO.getBeginTime().toString(), createReqVO.getEndTime().toString(), rateValue, createReqVO.getCycleId()); + if (CollectionUtils.isEmpty(calculate)) { + log.warn("获取两个时间之间间隔天数错误"); + return CommonResult.error(INSPECTION_CYCLE_ERROR); + } + //计算计划次数 + planNum = calculate.stream().mapToInt(PeriodResult::getCount).sum(); + } //巡检计划list List maintainPlanList = new ArrayList<>(); //角色列表 diff --git a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/util/StringValidateUtil.java b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/util/StringValidateUtil.java index 6c99d2c..38bc032 100644 --- a/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/util/StringValidateUtil.java +++ b/urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/util/StringValidateUtil.java @@ -88,6 +88,33 @@ public class StringValidateUtil { return true; } + /** + * 校验字符串是否为 1-20 的整数(包含1和20) + * @param str 待校验的字符串(允许null/空串) + * @return 校验通过返回true,否则false + */ + public static boolean isValidNumberStr(String str) { + // 1. 空值/空串校验 + if (str == null || str.trim().isEmpty()) { + return false; + } + + // 2. 校验是否为纯数字(排除字母、符号、小数) + if (!str.matches("^\\d+$")) { + return false; + } + + // 3. 转换为数字并校验范围 + try { + int number = Integer.parseInt(str); + return number >= 1 && number <= 20; + } catch (NumberFormatException e) { + // 理论上不会走到这里(已通过正则校验),兜底处理 + return false; + } + } + + // 测试用例 public static void main(String[] args) { // 测试符合规则的情况