|
@@ -16,15 +16,10 @@ import com.shkpr.service.aimodelpower.dbdao.services.intef.WODispatchCmdBatchIte
|
|
|
import com.shkpr.service.aimodelpower.dbdao.services.intef.WODispatchPlanDBService;
|
|
|
import com.shkpr.service.aimodelpower.dbdao.tables.WODispatchPlanInfoTable;
|
|
|
import com.shkpr.service.aimodelpower.dto.*;
|
|
|
-import com.shkpr.service.aimodelpower.dto.woDispatchPlanModel.DispatchCmdBatchItemModel;
|
|
|
-import com.shkpr.service.aimodelpower.dto.woDispatchPlanModel.DispatchPlanInfoDetailsModel;
|
|
|
-import com.shkpr.service.aimodelpower.dto.woDispatchPlanModel.DispatchPlanInfoModel;
|
|
|
-import com.shkpr.service.aimodelpower.dto.woDispatchPlanModel.DispatchPlanInfoSSModel;
|
|
|
+import com.shkpr.service.aimodelpower.dto.woDispatchPlanModel.*;
|
|
|
import com.shkpr.service.aimodelpower.globalmgr.AsyncTaskQueueMgr;
|
|
|
-import com.shkpr.service.aimodelpower.jsonbean.woDispatchPlan.JPDispatchCmdBatchItem;
|
|
|
-import com.shkpr.service.aimodelpower.jsonbean.woDispatchPlan.JPDispatchPlanInfoDetailsSS;
|
|
|
-import com.shkpr.service.aimodelpower.jsonbean.woDispatchPlan.JPDispatchPlanInfoSS;
|
|
|
-import com.shkpr.service.aimodelpower.jsonbean.woDispatchPlan.JPDispatchPlanInfoSave;
|
|
|
+import com.shkpr.service.aimodelpower.jsonbean.woDispatchPlan.*;
|
|
|
+import javafx.beans.binding.ObjectExpression;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
@@ -206,14 +201,14 @@ public class WODispatchPlanTmDoBizFun {
|
|
|
}
|
|
|
try{
|
|
|
Map<String,Object> map = getThisDBService().viewInfo("","",oJsonParam.getPlanId());
|
|
|
- if(map!=null){
|
|
|
+ if(map!=null||map.size()>0){
|
|
|
DispatchPlanInfoDetailsModel model = FastJsonUtil.map2Obj(map,DispatchPlanInfoDetailsModel.class,true);
|
|
|
|
|
|
//TODO 查询相关联的排班项信息
|
|
|
Map<String,Object> andWheres = new HashMap<>();
|
|
|
andWheres.put("plan_id",oJsonParam.getPlanId());
|
|
|
- List<DispatchCmdBatchItemModel> itemModels = getItemDBService().listAllWithsExByDispoal("","",1,0
|
|
|
- ,andWheres,new HashMap<>(),"handle_start_time","");
|
|
|
+ List<DispatchCmdBatchItemModel> itemModels = getItemDBService()
|
|
|
+ .listAllWithsExByDispoal("","",andWheres,new HashMap<>(),"handle_start_time","");
|
|
|
|
|
|
model.setItemModels(itemModels);
|
|
|
|
|
@@ -261,6 +256,223 @@ public class WODispatchPlanTmDoBizFun {
|
|
|
return timestampMillis;
|
|
|
}
|
|
|
|
|
|
+ //TODO 公用计算下次生效时间的方法
|
|
|
+ //TODO 分是否排班
|
|
|
+ public static Long returnNextTakeTime(DispatchPlanInfoNextTimeModel model){
|
|
|
+ Long nextTakeTime = 0L;
|
|
|
+ if(!CollectionUtils.isEmpty(model.getItemsList())){
|
|
|
+ List<JPDispatchCmdBatchItem> newList = model.getItemsList().stream()
|
|
|
+ .sorted(Comparator.comparing(JPDispatchCmdBatchItem::getHandleStartTime))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if(model.getPlanType()==0) {
|
|
|
+ //TODO 临时计划
|
|
|
+ Instant nowTime = Instant.ofEpochMilli(
|
|
|
+ TimeTool.convertDateStr2UTC
|
|
|
+ (
|
|
|
+ JSONArray.parseArray(model.getCycles()).getString(0)
|
|
|
+ +" "+
|
|
|
+ newList.get(0).getHandleStartTime()));
|
|
|
+ if(model.getDispatchLeadTime()==0) {
|
|
|
+ nextTakeTime = nowTime.toEpochMilli();
|
|
|
+ }else if(model.getDispatchLeadTime()>0){
|
|
|
+ nextTakeTime = nowTime.minus(-model.getDispatchLeadTime(), ChronoUnit.MINUTES).toEpochMilli();
|
|
|
+ }else if(model.getDispatchLeadTime()<0){
|
|
|
+ nextTakeTime = nowTime.minus(model.getDispatchLeadTime(), ChronoUnit.MINUTES).toEpochMilli();
|
|
|
+ }
|
|
|
+ //TODO 如果当前时间与下次生效时间是同一天,但是时刻已经是过去时,那么则返回失败信息
|
|
|
+ Long nowTimeLong = TimeTool.getCurMsUTC();
|
|
|
+ if(nowTimeLong>nextTakeTime&&isSameDay(nowTimeLong,nextTakeTime)){
|
|
|
+ throw new RuntimeException(ResponseCode.STATUS_ERROR_JSON_FORMAT.toStrCode());
|
|
|
+ }
|
|
|
+ }else if(model.getPlanType()==1){
|
|
|
+ //TODO 日计划
|
|
|
+ boolean isToDay = false;//生效时间是否小于等于当前时刻
|
|
|
+ for (JPDispatchCmdBatchItem item:newList){
|
|
|
+ Instant nowTime = Instant.ofEpochMilli(
|
|
|
+ TimeTool.convertDateStr2UTC
|
|
|
+ (JSONArray.parseArray(model.getCycles()).getString(0)
|
|
|
+ +" "+item.getHandleStartTime()));
|
|
|
+ if(nowTime.isBefore(Instant.now()) || nowTime.equals(Instant.now())){
|
|
|
+ isToDay = true;
|
|
|
+ if(model.getDispatchLeadTime()==0) {
|
|
|
+ nextTakeTime = nowTime.toEpochMilli();
|
|
|
+ }else if(model.getDispatchLeadTime()>0){
|
|
|
+ nextTakeTime = nowTime.minus(-model.getDispatchLeadTime(), ChronoUnit.MINUTES).toEpochMilli();
|
|
|
+ }else if(model.getDispatchLeadTime()<0){
|
|
|
+ nextTakeTime = nowTime.minus(model.getDispatchLeadTime(), ChronoUnit.MINUTES).toEpochMilli();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!isToDay){
|
|
|
+ //说明当天并没有满足条件的时刻,那么在日期上加一天,并且用最小时刻
|
|
|
+ nextTakeTime = Instant.ofEpochMilli(
|
|
|
+ TimeTool.convertDateStr2UTC
|
|
|
+ (JSONArray.parseArray(model.getCycles()).getString(0)
|
|
|
+ +" "+newList.get(0).getHandleStartTime())).toEpochMilli();
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO 如果当前时间大于生效时间,说明生效时间过期,则加一天
|
|
|
+ if(nextTakeTime<TimeTool.getCurMsUTC()){
|
|
|
+ nextTakeTime = Instant.ofEpochMilli(nextTakeTime)
|
|
|
+ .plus(1, ChronoUnit.DAYS).toEpochMilli();
|
|
|
+ }
|
|
|
+ }else if(model.getPlanType()==2){
|
|
|
+ //TODO 周计划
|
|
|
+ //TODO 先取周期值里最小的数,新集合里最小的值就是最早的周几数
|
|
|
+ JSONArray newJSONArray = JSONArray.parseArray(model.getCycles()).stream().sorted(
|
|
|
+ // 根据
|
|
|
+ Comparator.comparingLong(
|
|
|
+ e -> Long.valueOf(e.toString())
|
|
|
+ )
|
|
|
+ // 放开下面的注释,使用reversed()方法,就是降序 大到小
|
|
|
+ // .reversed()
|
|
|
+ ).collect(Collectors.toCollection(JSONArray::new));
|
|
|
+
|
|
|
+ //TODO 先得到所有集合对应的当前周的所有符合条件的时间
|
|
|
+ List<String> dateTimeStrings = new ArrayList<>();
|
|
|
+ for (Object obj:newJSONArray){
|
|
|
+ LocalDateTime nowDate = LocalDateTime.now().with(DayOfWeek.of(Integer.valueOf(obj.toString())));
|
|
|
+ for (JPDispatchCmdBatchItem item : newList){
|
|
|
+ String[] times = item.getHandleStartTime().split(":");
|
|
|
+ dateTimeStrings.add(nowDate.withHour(Integer.valueOf(times[0]))
|
|
|
+ .withMinute(Integer.valueOf(times[1])).withSecond(Integer.valueOf(times[2])).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LocalDateTime nextDateTime = findNextTime(dateTimeStrings);
|
|
|
+
|
|
|
+ if(nextDateTime!=null){
|
|
|
+ if (model.getDispatchLeadTime() == 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime);
|
|
|
+ } else if (model.getDispatchLeadTime() > 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMinutes(-model.getDispatchLeadTime()));
|
|
|
+ } else if (model.getDispatchLeadTime() < 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMinutes(model.getDispatchLeadTime()));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ LocalTime localTime = LocalTime.parse(newList.get(0).getHandleStartTime(), DateTimeFormatter.ofPattern("HH:mm:ss"));
|
|
|
+ nextDateTime = LocalDateTime.now()
|
|
|
+ .with(DayOfWeek.of(Integer.valueOf(newJSONArray.get(0).toString())));
|
|
|
+ if (model.getDispatchLeadTime() == 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusWeeks(-1).withHour(localTime.getHour())
|
|
|
+ .withMinute(localTime.getMinute())
|
|
|
+ .withSecond(localTime.getSecond()));
|
|
|
+ } else if (model.getDispatchLeadTime() > 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusWeeks(-1).withHour(localTime.getHour())
|
|
|
+ .withMinute(localTime.getMinute())
|
|
|
+ .withSecond(localTime.getSecond()).minusMinutes(-model.getDispatchLeadTime()));
|
|
|
+ } else if (model.getDispatchLeadTime() < 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusWeeks(-1).withHour(localTime.getHour())
|
|
|
+ .withMinute(localTime.getMinute())
|
|
|
+ .withSecond(localTime.getSecond()).minusMinutes(model.getDispatchLeadTime()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if(model.getPlanType()==3){
|
|
|
+ //TODO 月计划
|
|
|
+ JSONArray newJSONArray = JSONArray.parseArray(model.getCycles()).stream().sorted(
|
|
|
+ // 根据
|
|
|
+ Comparator.comparingLong(
|
|
|
+ e -> Long.valueOf(e.toString())
|
|
|
+ )
|
|
|
+ // 放开下面的注释,使用reversed()方法,就是降序 大到小
|
|
|
+ // .reversed()
|
|
|
+ ).collect(Collectors.toCollection(JSONArray::new));
|
|
|
+
|
|
|
+ //TODO 先得到所有集合对应的当前周的所有符合条件的时间
|
|
|
+ List<String> dateTimeStrings = new ArrayList<>();
|
|
|
+ for (Object obj:newJSONArray){
|
|
|
+ LocalDateTime nowDate = LocalDateTime.now().withDayOfMonth(Integer.valueOf(obj.toString()));
|
|
|
+ for (JPDispatchCmdBatchItem item : newList){
|
|
|
+ String[] times = item.getHandleStartTime().split(":");
|
|
|
+ dateTimeStrings.add(nowDate.withHour(Integer.valueOf(times[0]))
|
|
|
+ .withMinute(Integer.valueOf(times[1])).withSecond(Integer.valueOf(times[2])).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDateTime nextDateTime = findNextTime(dateTimeStrings);
|
|
|
+
|
|
|
+ if(nextDateTime!=null){
|
|
|
+ if (model.getDispatchLeadTime() == 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime);
|
|
|
+ } else if (model.getDispatchLeadTime() > 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMinutes(-model.getDispatchLeadTime()));
|
|
|
+ } else if (model.getDispatchLeadTime() < 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMinutes(model.getDispatchLeadTime()));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ LocalTime localTime = LocalTime.parse(newList.get(0).getHandleStartTime(), DateTimeFormatter.ofPattern("HH:mm:ss"));
|
|
|
+ nextDateTime = LocalDateTime.now()
|
|
|
+ .withDayOfMonth(newJSONArray.getInteger(0));
|
|
|
+ if (model.getDispatchLeadTime() == 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMonths(-1).withHour(localTime.getHour())
|
|
|
+ .withMinute(localTime.getMinute())
|
|
|
+ .withSecond(localTime.getSecond()));
|
|
|
+ } else if (model.getDispatchLeadTime() > 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMonths(-1).withHour(localTime.getHour())
|
|
|
+ .withMinute(localTime.getMinute())
|
|
|
+ .withSecond(localTime.getSecond()).minusMinutes(-model.getDispatchLeadTime()));
|
|
|
+ } else if (model.getDispatchLeadTime() < 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMonths(-1).withHour(localTime.getHour())
|
|
|
+ .withMinute(localTime.getMinute())
|
|
|
+ .withSecond(localTime.getSecond()).minusMinutes(model.getDispatchLeadTime()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if(model.getPlanType()==4){
|
|
|
+ //TODO 年计划
|
|
|
+ JSONArray newJSONArray = JSONArray.parseArray(model.getCycles()).stream().sorted(
|
|
|
+ // 根据
|
|
|
+ Comparator.comparing(
|
|
|
+ e -> e.toString()
|
|
|
+ )
|
|
|
+ // 放开下面的注释,使用reversed()方法,就是降序 大到小
|
|
|
+ // .reversed()
|
|
|
+ ).collect(Collectors.toCollection(JSONArray::new));
|
|
|
+
|
|
|
+ //TODO 先得到所有集合对应的当前周的所有符合条件的时间
|
|
|
+ List<String> dateTimeStrings = new ArrayList<>();
|
|
|
+ for (Object obj:newJSONArray){
|
|
|
+ String[] monthDays = obj.toString().split("-");
|
|
|
+ LocalDateTime nowDate = LocalDateTime.now().withMonth(Integer.valueOf(monthDays[0]))
|
|
|
+ .withDayOfMonth(Integer.valueOf(monthDays[1]));
|
|
|
+ for (JPDispatchCmdBatchItem item : newList){
|
|
|
+ String[] times = item.getHandleStartTime().split(":");
|
|
|
+ dateTimeStrings.add(nowDate.withHour(Integer.valueOf(times[0]))
|
|
|
+ .withMinute(Integer.valueOf(times[1])).withSecond(Integer.valueOf(times[2])).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDateTime nextDateTime = findNextTime(dateTimeStrings);
|
|
|
+ if(nextDateTime!=null){
|
|
|
+ if (model.getDispatchLeadTime() == 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime);
|
|
|
+ } else if (model.getDispatchLeadTime() > 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMinutes(-model.getDispatchLeadTime()));
|
|
|
+ } else if (model.getDispatchLeadTime() < 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMinutes(model.getDispatchLeadTime()));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ LocalTime localTime = LocalTime.parse(newList.get(0).getHandleStartTime(), DateTimeFormatter.ofPattern("HH:mm:ss"));
|
|
|
+ nextDateTime = LocalDateTime.now()
|
|
|
+ .withMonth(Integer.valueOf(newJSONArray.get(0).toString().split("-")[0]))
|
|
|
+ .withDayOfMonth(Integer.valueOf(newJSONArray.get(0).toString().split("-")[1]));
|
|
|
+ if (model.getDispatchLeadTime() == 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusYears(-1).withHour(localTime.getHour())
|
|
|
+ .withMinute(localTime.getMinute())
|
|
|
+ .withSecond(localTime.getSecond()));
|
|
|
+ } else if (model.getDispatchLeadTime() > 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusYears(-1).withHour(localTime.getHour())
|
|
|
+ .withMinute(localTime.getMinute())
|
|
|
+ .withSecond(localTime.getSecond()).minusMinutes(-model.getDispatchLeadTime()));
|
|
|
+ } else if (model.getDispatchLeadTime() < 0) {
|
|
|
+ nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusYears(-1).withHour(localTime.getHour())
|
|
|
+ .withMinute(localTime.getMinute())
|
|
|
+ .withSecond(localTime.getSecond()).minusMinutes(model.getDispatchLeadTime()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nextTakeTime;
|
|
|
+ }
|
|
|
+
|
|
|
//TODO 新增计划
|
|
|
public static ResponseCode savePlan(JPDispatchPlanInfoSave oJsonParam){
|
|
|
try{
|
|
@@ -280,217 +492,14 @@ public class WODispatchPlanTmDoBizFun {
|
|
|
//TODO 开始计算时间字段并设置
|
|
|
Long lastTakeTime = 0L;
|
|
|
Long nextTakeTime = 0L;//下一次生效时间
|
|
|
- //TODO 分是否排班
|
|
|
- if(!CollectionUtils.isEmpty(oJsonParam.getItemsList())){
|
|
|
- List<JPDispatchCmdBatchItem> newList = oJsonParam.getItemsList().stream()
|
|
|
- .sorted(Comparator.comparing(JPDispatchCmdBatchItem::getHandleStartTime))
|
|
|
- .collect(Collectors.toList());
|
|
|
- if(model.getPlanType()==0) {
|
|
|
- //TODO 临时计划
|
|
|
- Instant nowTime = Instant.ofEpochMilli(
|
|
|
- TimeTool.convertDateStr2UTC
|
|
|
- (
|
|
|
- JSONArray.parseArray(model.getCycles()).getString(0)
|
|
|
- +" "+
|
|
|
- newList.get(0).getHandleStartTime()));
|
|
|
- if(model.getDispatchLeadTime()==0) {
|
|
|
- nextTakeTime = nowTime.toEpochMilli();
|
|
|
- }else if(model.getDispatchLeadTime()>0){
|
|
|
- nextTakeTime = nowTime.minus(-model.getDispatchLeadTime(), ChronoUnit.MINUTES).toEpochMilli();
|
|
|
- }else if(model.getDispatchLeadTime()<0){
|
|
|
- nextTakeTime = nowTime.minus(model.getDispatchLeadTime(), ChronoUnit.MINUTES).toEpochMilli();
|
|
|
- }
|
|
|
- //TODO 如果当前时间与下次生效时间是同一天,但是时刻已经是过去时,那么则返回失败信息
|
|
|
- Long nowTimeLong = TimeTool.getCurMsUTC();
|
|
|
- if(nowTimeLong>nextTakeTime&&isSameDay(nowTimeLong,nextTakeTime)){
|
|
|
- return ResponseCode.STATUS_ERROR_JSON_FORMAT;
|
|
|
- }
|
|
|
- }else if(model.getPlanType()==1){
|
|
|
- //TODO 日计划
|
|
|
- boolean isToDay = false;//生效时间是否小于等于当前时刻
|
|
|
- for (JPDispatchCmdBatchItem item:newList){
|
|
|
- Instant nowTime = Instant.ofEpochMilli(
|
|
|
- TimeTool.convertDateStr2UTC
|
|
|
- (JSONArray.parseArray(model.getCycles()).getString(0)
|
|
|
- +" "+item.getHandleStartTime()));
|
|
|
- if(nowTime.isBefore(Instant.now()) || nowTime.equals(Instant.now())){
|
|
|
- isToDay = true;
|
|
|
- if(model.getDispatchLeadTime()==0) {
|
|
|
- nextTakeTime = nowTime.toEpochMilli();
|
|
|
- }else if(model.getDispatchLeadTime()>0){
|
|
|
- nextTakeTime = nowTime.minus(-model.getDispatchLeadTime(), ChronoUnit.MINUTES).toEpochMilli();
|
|
|
- }else if(model.getDispatchLeadTime()<0){
|
|
|
- nextTakeTime = nowTime.minus(model.getDispatchLeadTime(), ChronoUnit.MINUTES).toEpochMilli();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(!isToDay){
|
|
|
- //说明当天并没有满足条件的时刻,那么在日期上加一天,并且用最小时刻
|
|
|
- nextTakeTime = Instant.ofEpochMilli(
|
|
|
- TimeTool.convertDateStr2UTC
|
|
|
- (JSONArray.parseArray(model.getCycles()).getString(0)
|
|
|
- +" "+newList.get(0).getHandleStartTime())).toEpochMilli();
|
|
|
- }
|
|
|
|
|
|
- //TODO 如果当前时间大于生效时间,说明生效时间过期,则加一天
|
|
|
- if(nextTakeTime<TimeTool.getCurMsUTC()){
|
|
|
- nextTakeTime = Instant.ofEpochMilli(nextTakeTime)
|
|
|
- .plus(1, ChronoUnit.DAYS).toEpochMilli();
|
|
|
- }
|
|
|
- }else if(model.getPlanType()==2){
|
|
|
- //TODO 周计划
|
|
|
- //TODO 先取周期值里最小的数,新集合里最小的值就是最早的周几数
|
|
|
- JSONArray newJSONArray = JSONArray.parseArray(model.getCycles()).stream().sorted(
|
|
|
- // 根据
|
|
|
- Comparator.comparingLong(
|
|
|
- e -> Long.valueOf(e.toString())
|
|
|
- )
|
|
|
- // 放开下面的注释,使用reversed()方法,就是降序 大到小
|
|
|
- // .reversed()
|
|
|
- ).collect(Collectors.toCollection(JSONArray::new));
|
|
|
-
|
|
|
- //TODO 先得到所有集合对应的当前周的所有符合条件的时间
|
|
|
- List<String> dateTimeStrings = new ArrayList<>();
|
|
|
- for (Object obj:newJSONArray){
|
|
|
- LocalDateTime nowDate = LocalDateTime.now().with(DayOfWeek.of(Integer.valueOf(obj.toString())));
|
|
|
- for (JPDispatchCmdBatchItem item : newList){
|
|
|
- String[] times = item.getHandleStartTime().split(":");
|
|
|
- dateTimeStrings.add(nowDate.withHour(Integer.valueOf(times[0]))
|
|
|
- .withMinute(Integer.valueOf(times[1])).withSecond(Integer.valueOf(times[2])).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- }
|
|
|
- }
|
|
|
- LocalDateTime nextDateTime = findNextTime(dateTimeStrings);
|
|
|
-
|
|
|
- if(nextDateTime!=null){
|
|
|
- if (model.getDispatchLeadTime() == 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime);
|
|
|
- } else if (model.getDispatchLeadTime() > 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMinutes(-model.getDispatchLeadTime()));
|
|
|
- } else if (model.getDispatchLeadTime() < 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMinutes(model.getDispatchLeadTime()));
|
|
|
- }
|
|
|
- }else{
|
|
|
- LocalTime localTime = LocalTime.parse(newList.get(0).getHandleStartTime(), DateTimeFormatter.ofPattern("HH:mm:ss"));
|
|
|
- nextDateTime = LocalDateTime.now()
|
|
|
- .with(DayOfWeek.of(Integer.valueOf(newJSONArray.get(0).toString())));
|
|
|
- if (model.getDispatchLeadTime() == 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusWeeks(-1).withHour(localTime.getHour())
|
|
|
- .withMinute(localTime.getMinute())
|
|
|
- .withSecond(localTime.getSecond()));
|
|
|
- } else if (model.getDispatchLeadTime() > 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusWeeks(-1).withHour(localTime.getHour())
|
|
|
- .withMinute(localTime.getMinute())
|
|
|
- .withSecond(localTime.getSecond()).minusMinutes(-model.getDispatchLeadTime()));
|
|
|
- } else if (model.getDispatchLeadTime() < 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusWeeks(-1).withHour(localTime.getHour())
|
|
|
- .withMinute(localTime.getMinute())
|
|
|
- .withSecond(localTime.getSecond()).minusMinutes(model.getDispatchLeadTime()));
|
|
|
- }
|
|
|
- }
|
|
|
- }else if(model.getPlanType()==3){
|
|
|
- //TODO 月计划
|
|
|
- JSONArray newJSONArray = JSONArray.parseArray(model.getCycles()).stream().sorted(
|
|
|
- // 根据
|
|
|
- Comparator.comparingLong(
|
|
|
- e -> Long.valueOf(e.toString())
|
|
|
- )
|
|
|
- // 放开下面的注释,使用reversed()方法,就是降序 大到小
|
|
|
- // .reversed()
|
|
|
- ).collect(Collectors.toCollection(JSONArray::new));
|
|
|
-
|
|
|
- //TODO 先得到所有集合对应的当前周的所有符合条件的时间
|
|
|
- List<String> dateTimeStrings = new ArrayList<>();
|
|
|
- for (Object obj:newJSONArray){
|
|
|
- LocalDateTime nowDate = LocalDateTime.now().withDayOfMonth(Integer.valueOf(obj.toString()));
|
|
|
- for (JPDispatchCmdBatchItem item : newList){
|
|
|
- String[] times = item.getHandleStartTime().split(":");
|
|
|
- dateTimeStrings.add(nowDate.withHour(Integer.valueOf(times[0]))
|
|
|
- .withMinute(Integer.valueOf(times[1])).withSecond(Integer.valueOf(times[2])).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- }
|
|
|
- }
|
|
|
+ DispatchPlanInfoNextTimeModel nextTimeModel = new DispatchPlanInfoNextTimeModel();
|
|
|
+ nextTimeModel.setPlanType(oJsonParam.getPlanType());
|
|
|
+ nextTimeModel.setItemsList(oJsonParam.getItemsList());
|
|
|
+ nextTimeModel.setDispatchLeadTime(oJsonParam.getDispatchLeadTime());
|
|
|
+ nextTimeModel.setCycles(oJsonParam.getCycles());
|
|
|
+ nextTakeTime = returnNextTakeTime(nextTimeModel);
|
|
|
|
|
|
- LocalDateTime nextDateTime = findNextTime(dateTimeStrings);
|
|
|
-
|
|
|
- if(nextDateTime!=null){
|
|
|
- if (model.getDispatchLeadTime() == 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime);
|
|
|
- } else if (model.getDispatchLeadTime() > 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMinutes(-model.getDispatchLeadTime()));
|
|
|
- } else if (model.getDispatchLeadTime() < 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMinutes(model.getDispatchLeadTime()));
|
|
|
- }
|
|
|
- }else{
|
|
|
- LocalTime localTime = LocalTime.parse(newList.get(0).getHandleStartTime(), DateTimeFormatter.ofPattern("HH:mm:ss"));
|
|
|
- nextDateTime = LocalDateTime.now()
|
|
|
- .withDayOfMonth(newJSONArray.getInteger(0));
|
|
|
- if (model.getDispatchLeadTime() == 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMonths(-1).withHour(localTime.getHour())
|
|
|
- .withMinute(localTime.getMinute())
|
|
|
- .withSecond(localTime.getSecond()));
|
|
|
- } else if (model.getDispatchLeadTime() > 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMonths(-1).withHour(localTime.getHour())
|
|
|
- .withMinute(localTime.getMinute())
|
|
|
- .withSecond(localTime.getSecond()).minusMinutes(-model.getDispatchLeadTime()));
|
|
|
- } else if (model.getDispatchLeadTime() < 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMonths(-1).withHour(localTime.getHour())
|
|
|
- .withMinute(localTime.getMinute())
|
|
|
- .withSecond(localTime.getSecond()).minusMinutes(model.getDispatchLeadTime()));
|
|
|
- }
|
|
|
- }
|
|
|
- }else if(model.getPlanType()==4){
|
|
|
- //TODO 年计划
|
|
|
- JSONArray newJSONArray = JSONArray.parseArray(model.getCycles()).stream().sorted(
|
|
|
- // 根据
|
|
|
- Comparator.comparing(
|
|
|
- e -> e.toString()
|
|
|
- )
|
|
|
- // 放开下面的注释,使用reversed()方法,就是降序 大到小
|
|
|
- // .reversed()
|
|
|
- ).collect(Collectors.toCollection(JSONArray::new));
|
|
|
-
|
|
|
- //TODO 先得到所有集合对应的当前周的所有符合条件的时间
|
|
|
- List<String> dateTimeStrings = new ArrayList<>();
|
|
|
- for (Object obj:newJSONArray){
|
|
|
- String[] monthDays = obj.toString().split("-");
|
|
|
- LocalDateTime nowDate = LocalDateTime.now().withMonth(Integer.valueOf(monthDays[0]))
|
|
|
- .withDayOfMonth(Integer.valueOf(monthDays[1]));
|
|
|
- for (JPDispatchCmdBatchItem item : newList){
|
|
|
- String[] times = item.getHandleStartTime().split(":");
|
|
|
- dateTimeStrings.add(nowDate.withHour(Integer.valueOf(times[0]))
|
|
|
- .withMinute(Integer.valueOf(times[1])).withSecond(Integer.valueOf(times[2])).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- LocalDateTime nextDateTime = findNextTime(dateTimeStrings);
|
|
|
- if(nextDateTime!=null){
|
|
|
- if (model.getDispatchLeadTime() == 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime);
|
|
|
- } else if (model.getDispatchLeadTime() > 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMinutes(-model.getDispatchLeadTime()));
|
|
|
- } else if (model.getDispatchLeadTime() < 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusMinutes(model.getDispatchLeadTime()));
|
|
|
- }
|
|
|
- }else{
|
|
|
- LocalTime localTime = LocalTime.parse(newList.get(0).getHandleStartTime(), DateTimeFormatter.ofPattern("HH:mm:ss"));
|
|
|
- nextDateTime = LocalDateTime.now()
|
|
|
- .withMonth(Integer.valueOf(newJSONArray.get(0).toString().split("-")[0]))
|
|
|
- .withDayOfMonth(Integer.valueOf(newJSONArray.get(0).toString().split("-")[1]));
|
|
|
- if (model.getDispatchLeadTime() == 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusYears(-1).withHour(localTime.getHour())
|
|
|
- .withMinute(localTime.getMinute())
|
|
|
- .withSecond(localTime.getSecond()));
|
|
|
- } else if (model.getDispatchLeadTime() > 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusYears(-1).withHour(localTime.getHour())
|
|
|
- .withMinute(localTime.getMinute())
|
|
|
- .withSecond(localTime.getSecond()).minusMinutes(-model.getDispatchLeadTime()));
|
|
|
- } else if (model.getDispatchLeadTime() < 0) {
|
|
|
- nextTakeTime = reloadLocalDateTimeToLong(nextDateTime.minusYears(-1).withHour(localTime.getHour())
|
|
|
- .withMinute(localTime.getMinute())
|
|
|
- .withSecond(localTime.getSecond()).minusMinutes(model.getDispatchLeadTime()));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
model.setLastTakeTime(lastTakeTime);
|
|
|
model.setNextTakeTime(nextTakeTime);
|
|
@@ -510,6 +519,41 @@ public class WODispatchPlanTmDoBizFun {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //TODO 修改计划
|
|
|
+ public static ResponseCode updatePlan(JPDispatchPlanInfoUpdate oJsonParam){
|
|
|
+ try {
|
|
|
+ //TODO 根据计划类型计算计划的下次生效时间
|
|
|
+ //TODO 查询原计划是否还存在,若存在比对planType是否一致
|
|
|
+ Map<String,Object> oldPlan = getThisDBService().getOne(oJsonParam.getPlanId());
|
|
|
+ if(oldPlan==null){
|
|
|
+ return ResponseCode.RESULT_REFERENCE_NOT_EXIST;
|
|
|
+ }
|
|
|
+ if(!oJsonParam.getPlanType().equals(Integer.valueOf(oldPlan.get("plan_type").toString()))){
|
|
|
+ return ResponseCode.STATUS_ERROR_JSON_FORMAT;
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO 开始计算时间字段并设置
|
|
|
+ Long nextTakeTime = 0L;//下一次生效时间
|
|
|
+
|
|
|
+ DispatchPlanInfoNextTimeModel nextTimeModel = new DispatchPlanInfoNextTimeModel();
|
|
|
+ nextTimeModel.setPlanType(oJsonParam.getPlanType());
|
|
|
+ nextTimeModel.setItemsList(oJsonParam.getItemsList());
|
|
|
+ nextTimeModel.setDispatchLeadTime(oJsonParam.getDispatchLeadTime());
|
|
|
+ nextTimeModel.setCycles(oJsonParam.getCycles());
|
|
|
+ nextTakeTime = returnNextTakeTime(nextTimeModel);
|
|
|
+
|
|
|
+
|
|
|
+ ResponseCode updateRes = getThisDBService().updatePlanInfoByCount(oJsonParam,nextTakeTime, oJsonParam.getRulesList(),
|
|
|
+ oJsonParam.getTagsList(), oJsonParam.getItemsList());
|
|
|
+ return updateRes;
|
|
|
+ }catch(Exception ex){
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mStrClassName, mStrClassName
|
|
|
+ ,String.format("update planInfo errorMsg:%s end<====",
|
|
|
+ ex.getLocalizedMessage()));
|
|
|
+ return ResponseCode.RESULT_BAD;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private static boolean isSameDay(long timestamp1, long timestamp2) {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
// 确保时区设置正确,以避免因夏令时导致的问题
|