|
|
@@ -572,6 +572,127 @@ public class PatrolInspectionPlanServiceImpl extends AbstractCrudService<PatrolI
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询近七天(今天 ~ 今天+6)符合时间段的主计划,按日检查子计划是否存在;
|
|
|
+ * 不存在则补插子计划及地点关联,已存在则跳过
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void supplementNearSevenDaysPlanSon() {
|
|
|
+ String todayStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ LocalDate startOfNearSeven = LocalDate.now();
|
|
|
+ LocalDate endOfNearSeven = OnlineMethod.getDate(todayStr, "yyyy-MM-dd", true, 6);
|
|
|
+
|
|
|
+ // 查询近七天时间范围内生效的主计划:开始日期 <= 近七天末天,结束日期 >= 今天
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPlan> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.le(PatrolInspectionPlan::getStartDate, endOfNearSeven)
|
|
|
+ .ge(PatrolInspectionPlan::getEndDate, startOfNearSeven)
|
|
|
+ .eq(PatrolInspectionPlan::getEnable, 1)
|
|
|
+ .eq(PatrolInspectionPlan::getPlanType, 1);
|
|
|
+ List<PatrolInspectionPlan> list = this.list(queryWrapper);
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Integer> planIdList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ planIdList.add(list.get(i).getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 巡检日程关联信息
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPlanSchedule> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper1.in(PatrolInspectionPlanSchedule::getPlanId, planIdList);
|
|
|
+ List<PatrolInspectionPlanSchedule> scheduleList = planScheduleService.list(queryWrapper1);
|
|
|
+ if (CollectionUtils.isEmpty(scheduleList)) {
|
|
|
+ throw new BusinessException("无巡检日程关联信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 主计划地点关联
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPlanSite> queryWrapper2 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper2.in(PatrolInspectionPlanSite::getPlanId, planIdList);
|
|
|
+ List<PatrolInspectionPlanSite> siteList = planSiteService.list(queryWrapper2);
|
|
|
+ if (CollectionUtils.isEmpty(siteList)) {
|
|
|
+ throw new BusinessException("无主计划地点关联信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询近七天已存在的子计划(按主计划id + 巡检日期判断是否存在)
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPlanSon> queryWrapper3 = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper3.select(PatrolInspectionPlanSon::getPlanId, PatrolInspectionPlanSon::getInspectionDate)
|
|
|
+ .in(PatrolInspectionPlanSon::getPlanId, planIdList)
|
|
|
+ .ge(PatrolInspectionPlanSon::getInspectionDate, startOfNearSeven)
|
|
|
+ .le(PatrolInspectionPlanSon::getInspectionDate, endOfNearSeven);
|
|
|
+ List<PatrolInspectionPlanSon> planSonList = patrolInspectionPlanSonService.list(queryWrapper3);
|
|
|
+ List<String> existPlanSonKeyList = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(planSonList)) {
|
|
|
+ for (int i = 0; i < planSonList.size(); i++) {
|
|
|
+ existPlanSonKeyList.add(planSonList.get(i).getPlanId() + "_" + planSonList.get(i).getInspectionDate());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 逐日检查并补插缺失的子计划
|
|
|
+ for (int dayOffset = 0; dayOffset < 7; dayOffset++) {
|
|
|
+ LocalDate targetDate = dayOffset == 0 ? startOfNearSeven
|
|
|
+ : OnlineMethod.getDate(todayStr, "yyyy-MM-dd", true, dayOffset);
|
|
|
+ Date date = Date.from(targetDate.atStartOfDay(ZoneOffset.ofHours(8)).toInstant());
|
|
|
+ String week = OnlineMethod.getWeekOfDate(date);
|
|
|
+
|
|
|
+ for (int m = 0; m < list.size(); m++) {
|
|
|
+ PatrolInspectionPlan plan = list.get(m);
|
|
|
+ // 目标日期需落在该主计划有效期内
|
|
|
+ if (plan.getStartDate().isAfter(targetDate) || plan.getEndDate().isBefore(targetDate)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String existKey = plan.getId() + "_" + targetDate;
|
|
|
+ // 已存在则不做任何操作
|
|
|
+ if (existPlanSonKeyList.contains(existKey)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 休息日不生成子计划
|
|
|
+ if (plan.getRestDay() != null && plan.getRestDay().contains(week)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int j = 0; j < scheduleList.size(); j++) {
|
|
|
+ if (!plan.getId().equals(scheduleList.get(j).getPlanId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ PatrolInspectionPlanSon patrolInspectionPlanSon = new PatrolInspectionPlanSon();
|
|
|
+ patrolInspectionPlanSon.setPlanId(plan.getId());
|
|
|
+ patrolInspectionPlanSon.setInspectionDate(targetDate);
|
|
|
+ patrolInspectionPlanSon.setStartTime(scheduleList.get(j).getStartTime());
|
|
|
+ patrolInspectionPlanSon.setEndTime(scheduleList.get(j).getEndTime());
|
|
|
+ patrolInspectionPlanSon.setPersonnelId(scheduleList.get(j).getPersonnelId());
|
|
|
+ patrolInspectionPlanSon.setAreaId(plan.getAreaId());
|
|
|
+ patrolInspectionPlanSon.setPlanType(plan.getPlanType());
|
|
|
+ patrolInspectionPlanSon.setPlanCycle(plan.getPlanCycle());
|
|
|
+ patrolInspectionPlanSon.setPlanFrequency(plan.getPlanFrequency());
|
|
|
+ patrolInspectionPlanSon.setLapTime(plan.getLapTime());
|
|
|
+ patrolInspectionPlanSon.setIntervalTime(plan.getIntervalTime());
|
|
|
+ patrolInspectionPlanSon.setPlanDescribe(plan.getPlanDescribe());
|
|
|
+ patrolInspectionPlanSon.setCompletion(0);
|
|
|
+ patrolInspectionPlanSon.setCreateTime(LocalDateTime.now());
|
|
|
+ patrolInspectionPlanSon.setCreator(plan.getCreator());
|
|
|
+ patrolInspectionPlanSon.setAlternateField("0");
|
|
|
+ patrolInspectionPlanSon.setTenantId(plan.getTenantId());
|
|
|
+ patrolInspectionPlanSon.setCompanyId(plan.getCompanyId());
|
|
|
+ patrolInspectionPlanSonService.save(patrolInspectionPlanSon);
|
|
|
+ Integer zfid = patrolInspectionPlanSon.getId();
|
|
|
+ for (int k = 0; k < siteList.size(); k++) {
|
|
|
+ if (plan.getId().equals(siteList.get(k).getPlanId())) {
|
|
|
+ PatrolInspectionPlanSiteSon planSiteSon = new PatrolInspectionPlanSiteSon();
|
|
|
+ planSiteSon.setPlanId(zfid);
|
|
|
+ planSiteSon.setSiteId(siteList.get(k).getSiteId());
|
|
|
+ planSiteSon.setInspectionStatus(1);
|
|
|
+ planSiteSonService.save(planSiteSon);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 补插后加入已存在标记,避免同日重复创建
|
|
|
+ existPlanSonKeyList.add(existKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void delPatrolInspectionPlan(Integer id) {
|