Quellcode durchsuchen

河南郸城调度计划列表 详情 新增接口初版提交

1037015548@qq.com vor 11 Monaten
Ursprung
Commit
fbe7a3e109

+ 225 - 0
src/main/java/com/shkpr/service/aimodelpower/jsonbean/woDispatchPlan/JPDispatchPlanInfoUpdate.java

@@ -0,0 +1,225 @@
+package com.shkpr.service.aimodelpower.jsonbean.woDispatchPlan;
+
+import com.alibaba.fastjson.JSONArray;
+import com.shkpr.service.aimodelpower.commtools.TimeTool;
+import com.shkpr.service.aimodelpower.controllervalid.CommonParamValidNew;
+import lombok.Data;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.Size;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
+import java.util.List;
+import java.util.regex.Pattern;
+
+/**
+ * @ClassName JPDispatchPlanInfoSave
+ * @Description: TODO 添加调度计划参数
+ * @Author LX
+ * @Date 2024/6/27
+ * @Version V1.0
+ **/
+@Data
+public class JPDispatchPlanInfoUpdate {
+    private Integer planType = 0;//类型:0--临时;1--日循环;2--周循环;3--月循环;4--年循环
+                                //注:该字段新建时定义,后期不可再随意变更
+
+    //TODO casualValue和casualHsm在排班有的时候排班的时刻优先级更高
+    private String casualValue;//用户选择计划生成时间(此参数用于cycles值的插入):
+                    // 如果为临时计划,值为yyyy-MM-dd
+                    // 如果为日计划,值为HH:mm:ss
+                    // 如果为周,值为1-7的数字
+                    // 如果为月,值为1-31号数,如果设置为31且循环月没有31号,则默认为该月的最后一天,值为dd
+                    // 如果为年,值为mm-dd
+
+    private String cycles="";//TODO 根据参数casualTime处理后的具体周期值,决定循环计划的生效时间
+
+    private Integer planStatus = 1;//状态:-1--注销;0--停用;1--启用
+
+    @NotBlank(groups = { CommonParamValidNew.class})
+    @Size(min = 1,max = 255, groups = { CommonParamValidNew.class})
+    private String title;//计划标题
+
+    private Integer urgentLevel=1;//紧急程度(优先级)紧急级别:1 -- 一般;2 --重要;4 -- 紧急
+
+    private String dispatchRemark;//调度计划描述
+
+    private Integer dispatchLeadTime = 0;//派单时间提前量设定(单位分钟)
+                                    //    提前或推迟的校正时间(存储单位:分钟)
+                                    //*) =0则不推迟也不提前
+                                    //*) >0则推迟触发
+                                    //*) <0则提前触发
+
+    //TODO 创建人ID
+    @NotBlank(groups = { CommonParamValidNew.class})
+    @Size(min = 1,max = 255, groups = { CommonParamValidNew.class})
+    private String updaterId;
+
+    //TODO 监测分区id
+    @NotBlank(groups = { CommonParamValidNew.class})
+    @Size(min = 1,max = 255, groups = { CommonParamValidNew.class})
+    private String zoneId;
+
+    private Integer sendway = 1;//派单提醒方式:1--app通知;2--短信通知;3--app&短信通知
+
+    private Integer chufaRulsFlag = 1;//是否触发保存规则 0否 1是 默认值1
+
+    //TODO 判断是否是时间格式
+    public static boolean isValidDateFormat(String dateTimeStr,String fomatter) {
+        try {
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(fomatter);
+            formatter.parse(dateTimeStr);
+            return true;
+        } catch (DateTimeParseException e) {
+            return false;
+        }
+    }
+
+    private static final Pattern TIME_PATTERN =
+            Pattern.compile("^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$");
+    //TODO 判断是否为HH:mm:ss格式
+    public static boolean isValidTimeFormat(String time) {
+        if (time == null) {
+            return false;
+        }
+        return TIME_PATTERN.matcher(time).matches();
+    }
+    //TODO 判断是否为1=7的数字
+    public static boolean isOneToSeven(String str) {
+        return str.matches("[1-7]+");
+    }
+    //TODO 判断是否为1=31的数字
+    public static boolean isOneToThirtyOne(String str) {
+        return str.matches("[1-31]+");
+    }
+    //TODO 判断是否为mm-dd格式
+    public static boolean isMonthDay(String str) {
+        // 正则表达式匹配 mm-dd 格式,其中 mm 是1-12,dd 是1-31
+        return str.matches("(0?[1-9]|1[0-2])-((0?[1-9])|([1-2][0-9])|3[01])");
+    }
+
+    //TODO 相关关联子对象参数
+    //① 计划相关触发规则
+    private List<JPDispatchPlanInfoRuleSave> rulesList;
+    //② 计划附加标签项
+    private List<JPDispatchPlanInfoTagsSave> tagsList;
+    //③ 排班班次项
+    private List<JPDispatchCmdBatchItem> itemsList;
+
+    public boolean checkValid(){
+        try {
+            if (planType == null ||
+                    (planType != 0 && planType != 1 && planType != 2 && planType != 3 && planType != 4)) {
+                return false;
+            }
+            if(!CollectionUtils.isEmpty(itemsList)){
+                if(StringUtils.isEmpty(itemsList)){
+                    return false;
+                }
+            }
+            if (!StringUtils.isEmpty(casualValue)) {
+                //TODO 检查参数是否符合规格
+                if (planType == 0) {
+                    //TODO 说明是临时计划
+                    cycles += "[\"";
+                    for (Object objValue : JSONArray.parseArray(casualValue)) {
+                        if (!isValidDateFormat(objValue.toString(), "yyyy-MM-dd")) {
+                            return false;
+                        }
+                        if (LocalDate.now()
+                                .isAfter(LocalDate
+                                        .parse(objValue.toString(),
+                                                DateTimeFormatter.ofPattern("yyyy-MM-dd")))) {
+                            //TODO 如果当前时间在设置时间之后返回false
+                            return false;
+                        }
+                        cycles += objValue.toString();
+                    }
+                    cycles += "\"]";
+                } else if (planType == 1) {
+                    //TODO 说明是日循环计划
+                    //TODO 在外面代码逻辑中去设置默认为今天开始
+                    cycles = "[\"" + TimeTool.convertUTC2DateStr(TimeTool.getCurMsUTC(), "yyyy-MM-dd") + "\"]";
+                } else if (planType == 2) {
+                    //TODO 说明是周计划
+                    cycles += "[";
+                    int i = 0;
+                    for (Object objValue : JSONArray.parseArray(casualValue)) {
+                        if (!isOneToSeven(objValue.toString())) {
+                            return false;
+                        }
+                        cycles += objValue.toString();
+                        if (i!=(JSONArray.parseArray(casualValue).size()-1)){
+                            cycles += ",";
+                        }
+                        i++;
+                    }
+                    cycles += "]";
+                } else if (planType == 3) {
+                    cycles += "[";
+                    int i = 0;
+                    for (Object objValue : JSONArray.parseArray(casualValue)) {
+                        if (!isOneToThirtyOne(objValue.toString())) {
+                            return false;
+                        }
+                        cycles += objValue.toString();
+                        if (i!=(JSONArray.parseArray(casualValue).size()-1)){
+                            cycles += ",";
+                        }
+                        i++;
+                    }
+                    cycles += "]";
+                } else if (planType == 4) {
+                    cycles += "[";
+                    int i = 0;
+                    for (Object objValue : JSONArray.parseArray(casualValue)) {
+                        if (!isMonthDay(objValue.toString())) {
+                            return false;
+                        }
+                        cycles += "\""+objValue.toString()+"\"";
+                        if (i!=(JSONArray.parseArray(casualValue).size()-1)){
+                            cycles += ",";
+                        }
+                        i++;
+                    }
+                    cycles += "]";
+                }
+            }
+            if (planStatus == null || (planStatus != -1 && planStatus != 0 && planStatus != 1)) {
+                return false;
+            }
+            if (urgentLevel == null || (urgentLevel != 1 && urgentLevel != 2 && urgentLevel != 4)) {
+                return false;
+            }
+            if (dispatchLeadTime == null) {
+                return false;
+            }
+            if (sendway == null || (sendway != 1 && sendway != 2 && sendway != 3)) {
+                return false;
+            }
+
+            //TODO 检查关联数据完整性
+            if (!CollectionUtils.isEmpty(rulesList)) {
+                if (rulesList.stream().anyMatch(x -> !x.checkValid())) {
+                    return false;
+                }
+            }
+            if (!CollectionUtils.isEmpty(tagsList)) {
+                if (tagsList.stream().anyMatch(x -> !x.checkValid())) {
+                    return false;
+                }
+            }
+            if (!CollectionUtils.isEmpty(itemsList)) {
+                if (itemsList.stream().anyMatch(x -> !x.checkValid())) {
+                    return false;
+                }
+            }
+            return true;
+        }catch(Exception ex){
+            return false;
+        }
+    }
+}