提交修改 下一步进行机构用户登录改造
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
package com.xinda.itsm.service.impl;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.xinda.common.utils.DateUtils;
|
||||
import com.xinda.itsm.domain.InspectionRecord;
|
||||
import com.xinda.itsm.mapper.InspectionRecordMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.xinda.itsm.mapper.InspectionPlanMapper;
|
||||
@@ -19,7 +28,8 @@ public class InspectionPlanServiceImpl implements IInspectionPlanService
|
||||
{
|
||||
@Autowired
|
||||
private InspectionPlanMapper inspectionPlanMapper;
|
||||
|
||||
@Autowired
|
||||
private InspectionRecordMapper inspectionRecordMapper;
|
||||
/**
|
||||
* 查询巡检计划
|
||||
*
|
||||
@@ -53,8 +63,17 @@ public class InspectionPlanServiceImpl implements IInspectionPlanService
|
||||
@Override
|
||||
public int insertInspectionPlan(InspectionPlan inspectionPlan)
|
||||
{
|
||||
|
||||
inspectionPlan.setCreateTime(DateUtils.getNowDate());
|
||||
return inspectionPlanMapper.insertInspectionPlan(inspectionPlan);
|
||||
int num = inspectionPlanMapper.insertInspectionPlan(inspectionPlan);
|
||||
// 收集日期范围内的所有日期
|
||||
List<Date> dateList = new ArrayList<>();
|
||||
processDateRange(inspectionPlan.getStartDate(), inspectionPlan.getEndDate(), dateList::add);
|
||||
for(Date date : dateList){
|
||||
InspectionRecord inspectionRecord = getBasicRecord(inspectionPlan, date, "日");
|
||||
inspectionRecordMapper.insertInspectionRecord(inspectionRecord);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,4 +112,44 @@ public class InspectionPlanServiceImpl implements IInspectionPlanService
|
||||
{
|
||||
return inspectionPlanMapper.deleteInspectionPlanById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理指定日期范围内的每一天(使用java.util.Date类型)
|
||||
* @param startDate 开始日期
|
||||
* @param endDate 结束日期
|
||||
* @param dateConsumer 处理每一天的函数式接口
|
||||
*/
|
||||
public static void processDateRange(Date startDate, Date endDate, Consumer<Date> dateConsumer) {
|
||||
// 验证日期顺序
|
||||
if (startDate.after(endDate)) {
|
||||
throw new IllegalArgumentException("开始日期不能晚于结束日期");
|
||||
}
|
||||
|
||||
// 使用Calendar进行日期计算
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(startDate);
|
||||
|
||||
Date currentDate = startDate;
|
||||
while (!currentDate.after(endDate)) {
|
||||
dateConsumer.accept(currentDate);
|
||||
// 增加一天
|
||||
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
||||
currentDate = calendar.getTime();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private InspectionRecord getBasicRecord(InspectionPlan inspectionPlan, Date now, String cycle) {
|
||||
InspectionRecord record = new InspectionRecord();
|
||||
record.setPlanName(inspectionPlan.getPlanName());
|
||||
record.setPlanContent(inspectionPlan.getPlanContent());
|
||||
record.setProjectName(inspectionPlan.getProjectName());
|
||||
record.setPlanTime(DateUtils.parseDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, now) + " " + inspectionPlan.getSetTime()));
|
||||
record.setInspectionPerson(inspectionPlan.getInspectionPerson());
|
||||
record.setPlanId(inspectionPlan.getId());
|
||||
record.setUserId(inspectionPlan.getUserId());
|
||||
record.setInspectionCycle(cycle);
|
||||
record.setCycle(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, now));
|
||||
return record;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user