Commit c1e59458 authored by hanbing's avatar hanbing

方案管理-运行计划,支持多个特殊日期

parent cb4412e5
......@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.ws.rs.core.MediaType;
import java.text.ParseException;
/**
* 方案管理-运行计划
......@@ -40,7 +41,7 @@ public class RunningPlanController {
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = JsonViewObject.class),
})
public JsonViewObject saveRunningPlan(@RequestBody RunningPlanDTO runningPlanDTO) {
public JsonViewObject saveRunningPlan(@RequestBody RunningPlanDTO runningPlanDTO) throws ParseException {
runningPlanService.saveRunningPlan(runningPlanDTO);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
......
package net.wanji.web.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
/**
......@@ -70,9 +68,8 @@ public class RunningPlanDTO {
private String name;
@ApiModelProperty(value = "星期:1周一,2周二,3周三,4周四,5周五,6周六,7周日", required = true)
private List<Integer> week;
@ApiModelProperty(value = "特殊日期,格式 2023-01-28", required = true)
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
private Date specialDate;
@ApiModelProperty(value = "特殊日期列表,格式 2023-01-28", required = true)
private List<String> specialDateList;
@ApiModelProperty(value = "执行日计划名", required = true)
private String planName;
}
......
......@@ -3,12 +3,14 @@ package net.wanji.web.service.scheme;
import net.wanji.web.dto.CrossIdDTO;
import net.wanji.web.dto.RunningPlanDTO;
import java.text.ParseException;
/**
* @author Kent HAN
* @date 2023/1/28 16:41
*/
public interface RunningPlanService {
void saveRunningPlan(RunningPlanDTO runningPlanDTO);
void saveRunningPlan(RunningPlanDTO runningPlanDTO) throws ParseException;
RunningPlanDTO listRunningPlan(CrossIdDTO crossIdDTO);
}
package net.wanji.web.service.scheme.impl;
import cn.hutool.core.collection.CollectionUtil;
import net.wanji.web.common.exception.WeekException;
import net.wanji.web.dto.CrossIdDTO;
import net.wanji.web.dto.RunningPlanDTO;
......@@ -18,6 +19,8 @@ import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -28,6 +31,8 @@ import java.util.List;
*/
@Service
public class RunningPlanServiceImpl implements RunningPlanService {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
private final CrossPlanMapper crossPlanMapper;
private final CrossSchemeMapper crossSchemeMapper;
private final CrossSectionMapper crossSectionMapper;
......@@ -46,7 +51,7 @@ public class RunningPlanServiceImpl implements RunningPlanService {
@Override
@Transactional
public void saveRunningPlan(RunningPlanDTO runningPlanDTO) {
public void saveRunningPlan(RunningPlanDTO runningPlanDTO) throws ParseException {
String crossId = runningPlanDTO.getCrossId();
// 验证特殊日期
checkSpecialDate(runningPlanDTO);
......@@ -93,17 +98,20 @@ public class RunningPlanServiceImpl implements RunningPlanService {
schedulesPlan.setScheduleNo(scheduleNo);
schedulesPlan.setName(name);
List<Integer> week = new ArrayList<>();
List<String> specialDateList = new ArrayList<>();
Integer planId = 0;
for (CrossSchedulesPlanPO crossSchedulesPlanPO : crossSchedulesPlanPOList) {
Integer day = crossSchedulesPlanPO.getWeek();
if (day == 0) { // 特殊日期
schedulesPlan.setSpecialDate(crossSchedulesPlanPO.getSpecialDate());
Date specialDate = crossSchedulesPlanPO.getSpecialDate();
specialDateList.add(sdf.format(specialDate));
} else {
week.add(day);
}
planId = crossSchedulesPlanPO.getPlanId();
}
schedulesPlan.setWeek(week);
schedulesPlan.setSpecialDateList(specialDateList);
CrossPlanPO crossPlanPO = crossPlanMapper.selectById(planId);
schedulesPlan.setPlanName(crossPlanPO.getName());
schedulesPlanList.add(schedulesPlan);
......@@ -117,7 +125,7 @@ public class RunningPlanServiceImpl implements RunningPlanService {
return dailyPlanList;
}
private void saveCrossSchedules(RunningPlanDTO runningPlanDTO, String crossId) {
private void saveCrossSchedules(RunningPlanDTO runningPlanDTO, String crossId) throws ParseException {
List<RunningPlanDTO.SchedulesPlanListElement> schedulesPlanList = runningPlanDTO.getSchedulesPlanList();
for (RunningPlanDTO.SchedulesPlanListElement schedulesPlan : schedulesPlanList) {
// 更新调度表获取调度ID
......@@ -138,13 +146,16 @@ public class RunningPlanServiceImpl implements RunningPlanService {
}
private void updateCrossSchedulesPlan(String crossId, RunningPlanDTO.SchedulesPlanListElement schedulesPlan,
Integer crossSchedulesId, Integer planId) {
Integer crossSchedulesId, Integer planId) throws ParseException {
List<Integer> week = schedulesPlan.getWeek();
if (week == null || week.size() == 0) { // 特殊日期
CrossSchedulesPlanPO crossSchedulesPlanPO = initData(crossId, crossSchedulesId, planId);
crossSchedulesPlanPO.setSpecialDate(schedulesPlan.getSpecialDate());
crossSchedulesPlanPO.setWeek(0);
crossSchedulesPlanMapper.insertOne(crossSchedulesPlanPO);
List<String> specialDateList = schedulesPlan.getSpecialDateList();
for (String date : specialDateList) {
CrossSchedulesPlanPO crossSchedulesPlanPO = initData(crossId, crossSchedulesId, planId);
crossSchedulesPlanPO.setSpecialDate(sdf.parse(date));
crossSchedulesPlanPO.setWeek(0);
crossSchedulesPlanMapper.insertOne(crossSchedulesPlanPO);
}
} else {
for (Integer day : week) {
CrossSchedulesPlanPO crossSchedulesPlanPO = initData(crossId, crossSchedulesId, planId);
......@@ -207,8 +218,8 @@ public class RunningPlanServiceImpl implements RunningPlanService {
List<RunningPlanDTO.SchedulesPlanListElement> schedulesPlanList = runningPlanDTO.getSchedulesPlanList();
for (RunningPlanDTO.SchedulesPlanListElement schedulesPlan : schedulesPlanList) {
List<Integer> week = schedulesPlan.getWeek();
Date specialDate = schedulesPlan.getSpecialDate();
if (week != null && week.size() > 0 && specialDate != null) {
List<String> specialDateList = schedulesPlan.getSpecialDateList();
if (week != null && week.size() > 0 && !CollectionUtil.isEmpty(specialDateList)) {
throw new WeekException("不能同时有星期选择和日期选择");
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment