JPDispatchPlanInfoSave.java 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package com.shkpr.service.aimodelpower.jsonbean.woDispatchPlan;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.fasterxml.jackson.annotation.JsonInclude;
  4. import com.shkpr.service.aimodelpower.commtools.TimeTool;
  5. import com.shkpr.service.aimodelpower.controllervalid.CommonParamValidNew;
  6. import lombok.Data;
  7. import org.springframework.util.CollectionUtils;
  8. import org.springframework.util.StringUtils;
  9. import javax.validation.constraints.NotBlank;
  10. import javax.validation.constraints.Size;
  11. import java.sql.Time;
  12. import java.time.LocalDate;
  13. import java.time.LocalDateTime;
  14. import java.time.format.DateTimeFormatter;
  15. import java.time.format.DateTimeParseException;
  16. import java.util.List;
  17. import java.util.regex.Pattern;
  18. /**
  19. * @ClassName JPDispatchPlanInfoSave
  20. * @Description: TODO 添加调度计划参数
  21. * @Author LX
  22. * @Date 2024/6/27
  23. * @Version V1.0
  24. **/
  25. @Data
  26. public class JPDispatchPlanInfoSave {
  27. private Integer planType = 0;//类型:0--临时;1--日循环;2--周循环;3--月循环;4--年循环
  28. //注:该字段新建时定义,后期不可再随意变更
  29. //TODO casualValue和casualHsm在排班有的时候排班的时刻优先级更高
  30. private String casualValue;//用户选择计划生成时间(此参数用于cycles值的插入):
  31. // 如果为临时计划,值为yyyy-MM-dd
  32. // 如果为日计划,值为HH:mm:ss
  33. // 如果为周,值为1-7的数字
  34. // 如果为月,值为1-31号数,如果设置为31且循环月没有31号,则默认为该月的最后一天,值为dd
  35. // 如果为年,值为mm-dd
  36. private String cycles="";//TODO 根据参数casualTime处理后的具体周期值,决定循环计划的生效时间
  37. private Integer planStatus = 1;//状态:-1--注销;0--停用;1--启用
  38. @NotBlank(groups = { CommonParamValidNew.class})
  39. @Size(min = 1,max = 255, groups = { CommonParamValidNew.class})
  40. private String title;//计划标题
  41. private Integer urgentLevel=1;//紧急程度(优先级)紧急级别:1 -- 一般;2 --重要;4 -- 紧急
  42. private String dispatchRemark;//调度计划描述
  43. private Integer dispatchLeadTime = 0;//派单时间提前量设定(单位分钟)
  44. // 提前或推迟的校正时间(存储单位:分钟)
  45. //*) =0则不推迟也不提前
  46. //*) >0则推迟触发
  47. //*) <0则提前触发
  48. //TODO 创建人ID
  49. @NotBlank(groups = { CommonParamValidNew.class})
  50. @Size(min = 1,max = 255, groups = { CommonParamValidNew.class})
  51. private String creatorId;
  52. //TODO 监测分区id
  53. @NotBlank(groups = { CommonParamValidNew.class})
  54. @Size(min = 1,max = 255, groups = { CommonParamValidNew.class})
  55. private String zoneId;
  56. private Integer sendway = 1;//派单提醒方式:1--app通知;2--短信通知;3--app&短信通知
  57. private Integer chufaRulsFlag = 1;//是否触发保存规则 0否 1是 默认值1
  58. //TODO 判断是否是时间格式
  59. public static boolean isValidDateFormat(String dateTimeStr,String fomatter) {
  60. try {
  61. DateTimeFormatter formatter = DateTimeFormatter.ofPattern(fomatter);
  62. formatter.parse(dateTimeStr);
  63. return true;
  64. } catch (DateTimeParseException e) {
  65. return false;
  66. }
  67. }
  68. private static final Pattern TIME_PATTERN =
  69. Pattern.compile("^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$");
  70. //TODO 判断是否为HH:mm:ss格式
  71. public static boolean isValidTimeFormat(String time) {
  72. if (time == null) {
  73. return false;
  74. }
  75. return TIME_PATTERN.matcher(time).matches();
  76. }
  77. //TODO 判断是否为1=7的数字
  78. public static boolean isOneToSeven(String str) {
  79. return str.matches("[1-7]+");
  80. }
  81. //TODO 判断是否为1=31的数字
  82. public static boolean isOneToThirtyOne(String str) {
  83. return str.matches("[1-31]+");
  84. }
  85. //TODO 判断是否为mm-dd格式
  86. public static boolean isMonthDay(String str) {
  87. // 正则表达式匹配 mm-dd 格式,其中 mm 是1-12,dd 是1-31
  88. return str.matches("(0?[1-9]|1[0-2])-((0?[1-9])|([1-2][0-9])|3[01])");
  89. }
  90. //TODO 相关关联子对象参数
  91. //① 计划相关触发规则
  92. private List<JPDispatchPlanInfoRuleSave> rulesList;
  93. //② 计划附加标签项
  94. private List<JPDispatchPlanInfoTagsSave> tagsList;
  95. //③ 排班班次项
  96. private List<JPDispatchCmdBatchItem> itemsList;
  97. public boolean checkValid(){
  98. try {
  99. if (planType == null ||
  100. (planType != 0 && planType != 1 && planType != 2 && planType != 3 && planType != 4)) {
  101. return false;
  102. }
  103. if (!StringUtils.isEmpty(casualValue)) {
  104. //TODO 检查参数是否符合规格
  105. if (planType == 0) {
  106. //TODO 说明是临时计划
  107. cycles += "[\"";
  108. for (Object objValue : JSONArray.parseArray(casualValue)) {
  109. if (!isValidDateFormat(objValue.toString(), "yyyy-MM-dd")) {
  110. return false;
  111. }
  112. if (LocalDate.now()
  113. .isAfter(LocalDate
  114. .parse(objValue.toString(),
  115. DateTimeFormatter.ofPattern("yyyy-MM-dd")))) {
  116. //TODO 如果当前时间在设置时间之后返回false
  117. return false;
  118. }
  119. cycles += objValue.toString();
  120. }
  121. cycles += "\"]";
  122. } else if (planType == 1) {
  123. //TODO 说明是日循环计划
  124. //TODO 在外面代码逻辑中去设置默认为今天开始
  125. cycles = "[\"" + TimeTool.convertUTC2DateStr(TimeTool.getCurMsUTC(), "yyyy-MM-dd") + "\"]";
  126. } else if (planType == 2) {
  127. //TODO 说明是周计划
  128. cycles += "[";
  129. int i = 0;
  130. for (Object objValue : JSONArray.parseArray(casualValue)) {
  131. if (!isOneToSeven(objValue.toString())) {
  132. return false;
  133. }
  134. cycles += objValue.toString();
  135. if (i!=(JSONArray.parseArray(casualValue).size()-1)){
  136. cycles += ",";
  137. }
  138. i++;
  139. }
  140. cycles += "]";
  141. } else if (planType == 3) {
  142. cycles += "[";
  143. int i = 0;
  144. for (Object objValue : JSONArray.parseArray(casualValue)) {
  145. if (!isOneToThirtyOne(objValue.toString())) {
  146. return false;
  147. }
  148. cycles += objValue.toString();
  149. if (i!=(JSONArray.parseArray(casualValue).size()-1)){
  150. cycles += ",";
  151. }
  152. i++;
  153. }
  154. cycles += "]";
  155. } else if (planType == 4) {
  156. cycles += "[";
  157. int i = 0;
  158. for (Object objValue : JSONArray.parseArray(casualValue)) {
  159. if (!isMonthDay(objValue.toString())) {
  160. return false;
  161. }
  162. cycles += "\""+objValue.toString()+"\"";
  163. if (i!=(JSONArray.parseArray(casualValue).size()-1)){
  164. cycles += ",";
  165. }
  166. i++;
  167. }
  168. cycles += "]";
  169. }
  170. }
  171. if (planStatus == null || (planStatus != -1 && planStatus != 0 && planStatus != 1)) {
  172. return false;
  173. }
  174. if (urgentLevel == null || (urgentLevel != 1 && urgentLevel != 2 && urgentLevel != 4)) {
  175. return false;
  176. }
  177. if (dispatchLeadTime == null) {
  178. return false;
  179. }
  180. if (sendway == null || (sendway != 1 && sendway != 2 && sendway != 3)) {
  181. return false;
  182. }
  183. //TODO 检查关联数据完整性
  184. if (!CollectionUtils.isEmpty(rulesList)) {
  185. if (rulesList.stream().anyMatch(x -> !x.checkValid())) {
  186. return false;
  187. }
  188. }
  189. if (!CollectionUtils.isEmpty(tagsList)) {
  190. if (tagsList.stream().anyMatch(x -> !x.checkValid())) {
  191. return false;
  192. }
  193. }
  194. if (!CollectionUtils.isEmpty(itemsList)) {
  195. if (itemsList.stream().anyMatch(x -> !x.checkValid())) {
  196. return false;
  197. }
  198. }
  199. return true;
  200. }catch(Exception ex){
  201. return false;
  202. }
  203. }
  204. }