|
@@ -0,0 +1,570 @@
|
|
|
+package com.usky.fire.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.usky.common.core.bean.CommonPage;
|
|
|
+import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import com.usky.common.security.utils.SecurityUtils;
|
|
|
+import com.usky.fire.domain.*;
|
|
|
+import com.usky.fire.mapper.PatrolInspectionPlanMapper;
|
|
|
+import com.usky.fire.service.*;
|
|
|
+import com.usky.fire.service.util.OnlineMethod;
|
|
|
+import com.usky.fire.service.vo.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author JCB
|
|
|
+ * @since 2022-07-18
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PatrolInspectionPlanServiceImpl extends AbstractCrudService<PatrolInspectionPlanMapper, PatrolInspectionPlan> implements PatrolInspectionPlanService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionAreaService patrolInspectionAreaService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PlanSiteService planSiteService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionPlanSonService patrolInspectionPlanSonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PlanScheduleService planScheduleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PlanSiteSonService planSiteSonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SpecialRestDayService specialRestDayService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionSiteService patrolInspectionSiteService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PatrolInspectionAreaVo> planLeftList() {
|
|
|
+ LambdaQueryWrapper<PatrolInspectionArea> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PatrolInspectionArea::getTenantId, SecurityUtils.getTenantId())
|
|
|
+ .eq(PatrolInspectionArea::getEnable, 1);
|
|
|
+ List<PatrolInspectionArea> patrolInspectionAreaList = patrolInspectionAreaService.list(queryWrapper);
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPlan> queryWrapperOne = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperOne.eq(PatrolInspectionPlan::getEnable, 1).eq(PatrolInspectionPlan::getTenantId, SecurityUtils.getTenantId());
|
|
|
+ List<PatrolInspectionPlan> list = this.list(queryWrapperOne);
|
|
|
+ Map<Integer, List<PatrolInspectionPlan>> grouypByAreaId = list.stream().collect(
|
|
|
+ Collectors.groupingBy(o -> o.getAreaId())
|
|
|
+ );
|
|
|
+ List<DataCountVo> dataCountVoList = new ArrayList<>();
|
|
|
+ grouypByAreaId.forEach((k, v) -> {
|
|
|
+ DataCountVo dataCountVo = new DataCountVo();
|
|
|
+ dataCountVo.setListCount(v.size());
|
|
|
+ dataCountVo.setId(k);
|
|
|
+ dataCountVoList.add(dataCountVo);
|
|
|
+ });
|
|
|
+ List<PatrolInspectionAreaVo> patrolInspectionAreaVoList = new ArrayList<>();
|
|
|
+ if (patrolInspectionAreaList.size() > 0) {
|
|
|
+ for (int i = 0; i < patrolInspectionAreaList.size(); i++) {
|
|
|
+ PatrolInspectionAreaVo patrolInspectionAreaVo = new PatrolInspectionAreaVo();
|
|
|
+ patrolInspectionAreaVo.setId(patrolInspectionAreaList.get(i).getId());
|
|
|
+ patrolInspectionAreaVo.setAreaName(patrolInspectionAreaList.get(i).getAreaName());
|
|
|
+ patrolInspectionAreaVo.setAreaFid(patrolInspectionAreaList.get(i).getAreaFid());
|
|
|
+ patrolInspectionAreaVo.setCompanyId(patrolInspectionAreaList.get(i).getCompanyId());
|
|
|
+ patrolInspectionAreaVo.setTenantId(patrolInspectionAreaList.get(i).getTenantId());
|
|
|
+ patrolInspectionAreaVo.setCreator(patrolInspectionAreaList.get(i).getCreator());
|
|
|
+ patrolInspectionAreaVo.setCreateTime(patrolInspectionAreaList.get(i).getCreateTime());
|
|
|
+ patrolInspectionAreaVo.setEnable(patrolInspectionAreaList.get(i).getEnable());
|
|
|
+ patrolInspectionAreaVo.setSiteCount(0);
|
|
|
+ for (int j = 0; j < dataCountVoList.size(); j++) {
|
|
|
+ if (patrolInspectionAreaList.get(i).getId() == dataCountVoList.get(j).getId()) {
|
|
|
+ patrolInspectionAreaVo.setPlanCount(dataCountVoList.get(j).getListCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ patrolInspectionAreaVoList.add(patrolInspectionAreaVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<PatrolInspectionAreaVo> patrolInspectionAreaVoListOne = new ArrayList<>();
|
|
|
+ if (patrolInspectionAreaVoList.size() > 0) {
|
|
|
+ patrolInspectionAreaVoListOne = OnlineMethod.getChildPerms(patrolInspectionAreaVoList, 0);
|
|
|
+ }
|
|
|
+ return patrolInspectionAreaVoListOne;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void addPatrolInspectionPlan(PatrolInspectionPlanVo patrolInspectionPlanVo) {
|
|
|
+ //主表数据添加
|
|
|
+ PatrolInspectionPlan patrolInspectionPlan = new PatrolInspectionPlan();
|
|
|
+ patrolInspectionPlan.setPlanName(patrolInspectionPlanVo.getPlanName());
|
|
|
+ patrolInspectionPlan.setStartDate(patrolInspectionPlanVo.getStartDate());
|
|
|
+ if (patrolInspectionPlanVo.getPlanType() == 1) {
|
|
|
+ patrolInspectionPlan.setEndDate(patrolInspectionPlanVo.getEndDate());
|
|
|
+ } else {
|
|
|
+ String timeStr = patrolInspectionPlanVo.getStartDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ LocalDate ss = OnlineMethod.getDate(timeStr, "yyyy-MM-dd", true, 7 * patrolInspectionPlanVo.getWeekCount());
|
|
|
+ patrolInspectionPlan.setEndDate(ss);
|
|
|
+ }
|
|
|
+ patrolInspectionPlan.setAreaId(patrolInspectionPlanVo.getAreaId());
|
|
|
+ patrolInspectionPlan.setPlanType(patrolInspectionPlanVo.getPlanType());
|
|
|
+ patrolInspectionPlan.setPlanCycle(patrolInspectionPlanVo.getPlanCycle());
|
|
|
+ patrolInspectionPlan.setPlanFrequency(patrolInspectionPlanVo.getPlanFrequency());
|
|
|
+ patrolInspectionPlan.setLapTime(patrolInspectionPlanVo.getLapTime());
|
|
|
+ patrolInspectionPlan.setIntervalTime(patrolInspectionPlanVo.getIntervalTime());
|
|
|
+ patrolInspectionPlan.setPlanDescribe(patrolInspectionPlanVo.getPlanDescribe());
|
|
|
+ patrolInspectionPlan.setCreateTime(LocalDateTime.now());
|
|
|
+ patrolInspectionPlan.setCreator(SecurityUtils.getUsername());
|
|
|
+ patrolInspectionPlan.setEnable(1);
|
|
|
+ patrolInspectionPlan.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ patrolInspectionPlan.setCompanyId(patrolInspectionPlanVo.getCompanyId());
|
|
|
+ this.save(patrolInspectionPlan);
|
|
|
+ Integer fid = patrolInspectionPlan.getId();
|
|
|
+ //巡检日程添加
|
|
|
+ for (int i = 0; i < patrolInspectionPlanVo.getPlanScheduleList().size(); i++) {
|
|
|
+ patrolInspectionPlanVo.getPlanScheduleList().get(i).setPlanId(fid);
|
|
|
+ planScheduleService.save(patrolInspectionPlanVo.getPlanScheduleList().get(i));
|
|
|
+ }
|
|
|
+ //主计划地点添加
|
|
|
+ for (int i = 0; i < patrolInspectionPlanVo.getSiteArray().length; i++) {
|
|
|
+ PlanSite planSite = new PlanSite();
|
|
|
+ planSite.setPlanId(fid);
|
|
|
+ planSite.setSiteId(patrolInspectionPlanVo.getSiteArray()[i]);
|
|
|
+ planSiteService.save(planSite);
|
|
|
+ }
|
|
|
+
|
|
|
+ //特殊休息日关联信息添加
|
|
|
+ String timeStr3 = patrolInspectionPlanVo.getStartDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ int days = 0;
|
|
|
+ if (patrolInspectionPlanVo.getPlanType() == 1) {
|
|
|
+ days = OnlineMethod.fun(patrolInspectionPlanVo.getStartDate(), patrolInspectionPlanVo.getEndDate());
|
|
|
+ } else {
|
|
|
+ LocalDate date = OnlineMethod.getDate(timeStr3, "yyyy-MM-dd", true, 7 * (patrolInspectionPlanVo.getWeekCount() + 1));
|
|
|
+ days = OnlineMethod.fun(patrolInspectionPlanVo.getStartDate(), date);
|
|
|
+ }
|
|
|
+ for (int i = 0; i < days; i++) {
|
|
|
+ LocalDate date1 = OnlineMethod.getDate(timeStr3, "yyyy-MM-dd", true, i);
|
|
|
+ Date date = Date.from(date1.atStartOfDay(ZoneOffset.ofHours(8)).toInstant());
|
|
|
+ String week1 = OnlineMethod.getWeekOfDate(date);
|
|
|
+ if (patrolInspectionPlanVo.getRestDay().contains(week1)) {
|
|
|
+ SpecialRestDay specialRestDay = new SpecialRestDay();
|
|
|
+ specialRestDay.setPlanId(fid);
|
|
|
+ specialRestDay.setRestDate(date1);
|
|
|
+ specialRestDayService.save(specialRestDay);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //子表数据添加
|
|
|
+ if (patrolInspectionPlanVo.getPlanType() == 1) {//普通计划
|
|
|
+ //计算两时间天数
|
|
|
+ int day = OnlineMethod.fun(patrolInspectionPlanVo.getStartDate(), patrolInspectionPlanVo.getEndDate());
|
|
|
+ String timeStr1 = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ for (int i = 0; i < day; i++) {
|
|
|
+ for (int j = 0; j < patrolInspectionPlanVo.getPlanScheduleList().size(); j++) {
|
|
|
+ LocalDate s = OnlineMethod.getDate(timeStr1, "yyyy-MM-dd", true, i);
|
|
|
+ Date date = Date.from(s.atStartOfDay(ZoneOffset.ofHours(8)).toInstant());
|
|
|
+ String week = OnlineMethod.getWeekOfDate(date);
|
|
|
+ if (!patrolInspectionPlanVo.getRestDay().contains(week)) {
|
|
|
+ PatrolInspectionPlanSon patrolInspectionPlanSon = new PatrolInspectionPlanSon();
|
|
|
+ patrolInspectionPlanSon.setPlanId(fid);
|
|
|
+ patrolInspectionPlanSon.setInspectionDate(s);
|
|
|
+ patrolInspectionPlanSon.setStartTime(patrolInspectionPlanVo.getPlanScheduleList().get(j).getStartTime());
|
|
|
+ patrolInspectionPlanSon.setEndTime(patrolInspectionPlanVo.getPlanScheduleList().get(j).getEndTime());
|
|
|
+ patrolInspectionPlanSon.setPersonnelId(patrolInspectionPlanVo.getPlanScheduleList().get(j).getPersonnelId());
|
|
|
+ patrolInspectionPlanSon.setAreaId(patrolInspectionPlanVo.getAreaId());
|
|
|
+ patrolInspectionPlanSon.setPlanType(patrolInspectionPlanVo.getPlanType());
|
|
|
+ patrolInspectionPlanSon.setPlanCycle(patrolInspectionPlanVo.getPlanCycle());
|
|
|
+ patrolInspectionPlanSon.setPlanFrequency(patrolInspectionPlanVo.getPlanFrequency());
|
|
|
+ patrolInspectionPlanSon.setLapTime(patrolInspectionPlanVo.getLapTime());
|
|
|
+ patrolInspectionPlanSon.setIntervalTime(patrolInspectionPlanVo.getIntervalTime());
|
|
|
+ patrolInspectionPlanSon.setPlanDescribe(patrolInspectionPlanVo.getPlanDescribe());
|
|
|
+ patrolInspectionPlanSon.setCompletion(0);
|
|
|
+ patrolInspectionPlanSon.setCreateTime(LocalDateTime.now());
|
|
|
+ patrolInspectionPlanSon.setCreator(SecurityUtils.getUsername());
|
|
|
+ patrolInspectionPlanSon.setAlternateField("0");
|
|
|
+ patrolInspectionPlanSon.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ patrolInspectionPlanSon.setCompanyId(patrolInspectionPlanVo.getCompanyId());
|
|
|
+ patrolInspectionPlanSonService.save(patrolInspectionPlanSon);
|
|
|
+ Integer zfid = patrolInspectionPlanSon.getId();
|
|
|
+ for (int k = 0; k < patrolInspectionPlanVo.getSiteArray().length; k++) {
|
|
|
+ PlanSiteSon planSiteSon = new PlanSiteSon();
|
|
|
+ planSiteSon.setPlanId(zfid);
|
|
|
+ planSiteSon.setSiteId(patrolInspectionPlanVo.getSiteArray()[k]);
|
|
|
+ planSiteSon.setInspectionStatus(1);
|
|
|
+ planSiteSonService.save(planSiteSon);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {//按次计划
|
|
|
+ for (int i = 0; i < patrolInspectionPlanVo.getWeekCount(); i++) {
|
|
|
+ String timeStr2 = patrolInspectionPlanVo.getStartDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ LocalDate sss = OnlineMethod.getDate(timeStr2, "yyyy-MM-dd", true, 7 * (i + 1));
|
|
|
+ PatrolInspectionPlanSon patrolInspectionPlanSon = new PatrolInspectionPlanSon();
|
|
|
+ patrolInspectionPlanSon.setPlanId(fid);
|
|
|
+ if (i == 0) {
|
|
|
+ patrolInspectionPlanSon.setStartDate(patrolInspectionPlanVo.getStartDate());
|
|
|
+ } else {
|
|
|
+ LocalDate ssss = OnlineMethod.getDate(timeStr2, "yyyy-MM-dd", true, 7 * i + 1);
|
|
|
+ patrolInspectionPlanSon.setStartDate(ssss);
|
|
|
+ }
|
|
|
+ patrolInspectionPlanSon.setEndDate(sss);
|
|
|
+ patrolInspectionPlanSon.setPersonnelId(patrolInspectionPlanVo.getPlanScheduleList().get(0).getPersonnelId());
|
|
|
+ patrolInspectionPlanSon.setAreaId(patrolInspectionPlanVo.getAreaId());
|
|
|
+ patrolInspectionPlanSon.setPlanType(patrolInspectionPlanVo.getPlanType());
|
|
|
+ patrolInspectionPlanSon.setPlanCycle(patrolInspectionPlanVo.getPlanCycle());
|
|
|
+ patrolInspectionPlanSon.setPlanFrequency(patrolInspectionPlanVo.getPlanFrequency());
|
|
|
+ patrolInspectionPlanSon.setLapTime(patrolInspectionPlanVo.getLapTime());
|
|
|
+ patrolInspectionPlanSon.setIntervalTime(patrolInspectionPlanVo.getIntervalTime());
|
|
|
+ patrolInspectionPlanSon.setPlanDescribe(patrolInspectionPlanVo.getPlanDescribe());
|
|
|
+ patrolInspectionPlanSon.setCompletion(0);
|
|
|
+ patrolInspectionPlanSon.setCreateTime(LocalDateTime.now());
|
|
|
+ patrolInspectionPlanSon.setCreator(SecurityUtils.getUsername());
|
|
|
+ patrolInspectionPlanSon.setAlternateField("0");
|
|
|
+ patrolInspectionPlanSon.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ patrolInspectionPlanSon.setCompanyId(patrolInspectionPlanVo.getCompanyId());
|
|
|
+ patrolInspectionPlanSonService.save(patrolInspectionPlanSon);
|
|
|
+ Integer zfid = patrolInspectionPlanSon.getId();
|
|
|
+ for (int k = 0; k < patrolInspectionPlanVo.getSiteArray().length; k++) {
|
|
|
+ PlanSiteSon planSiteSon = new PlanSiteSon();
|
|
|
+ planSiteSon.setPlanId(zfid);
|
|
|
+ planSiteSon.setSiteId(patrolInspectionPlanVo.getSiteArray()[k]);
|
|
|
+ planSiteSon.setInspectionStatus(1);
|
|
|
+ planSiteSonService.save(planSiteSon);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void updatePatrolInspectionPlan(PatrolInspectionPlanVo patrolInspectionPlanVo) {
|
|
|
+ //主表数据修改
|
|
|
+ PatrolInspectionPlan patrolInspectionPlan = new PatrolInspectionPlan();
|
|
|
+ patrolInspectionPlan.setId(patrolInspectionPlanVo.getId());
|
|
|
+ patrolInspectionPlan.setPlanName(patrolInspectionPlanVo.getPlanName());
|
|
|
+ patrolInspectionPlan.setStartDate(patrolInspectionPlanVo.getStartDate());
|
|
|
+ if (patrolInspectionPlanVo.getPlanType() == 1) {
|
|
|
+ patrolInspectionPlan.setEndDate(patrolInspectionPlanVo.getEndDate());
|
|
|
+ } else {
|
|
|
+ String timeStr = patrolInspectionPlanVo.getStartDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ LocalDate ss = OnlineMethod.getDate(timeStr, "yyyy-MM-dd", true, 7 * patrolInspectionPlanVo.getWeekCount());
|
|
|
+ patrolInspectionPlan.setEndDate(ss);
|
|
|
+ }
|
|
|
+ patrolInspectionPlan.setAreaId(patrolInspectionPlanVo.getAreaId());
|
|
|
+ patrolInspectionPlan.setPlanType(patrolInspectionPlanVo.getPlanType());
|
|
|
+ patrolInspectionPlan.setPlanCycle(patrolInspectionPlanVo.getPlanCycle());
|
|
|
+ patrolInspectionPlan.setPlanFrequency(patrolInspectionPlanVo.getPlanFrequency());
|
|
|
+ patrolInspectionPlan.setLapTime(patrolInspectionPlanVo.getLapTime());
|
|
|
+ patrolInspectionPlan.setIntervalTime(patrolInspectionPlanVo.getIntervalTime());
|
|
|
+ patrolInspectionPlan.setPlanDescribe(patrolInspectionPlanVo.getPlanDescribe());
|
|
|
+ patrolInspectionPlan.setCompanyId(patrolInspectionPlanVo.getCompanyId());
|
|
|
+ this.updateById(patrolInspectionPlan);
|
|
|
+ //巡检日程更新
|
|
|
+ LambdaQueryWrapper<PlanSchedule> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PlanSchedule::getPlanId, patrolInspectionPlanVo.getId());
|
|
|
+ List<PlanSchedule> planScheduleList = planScheduleService.list(queryWrapper);
|
|
|
+ for (int i = 0; i < planScheduleList.size(); i++) {
|
|
|
+ planScheduleService.removeById(planScheduleList.get(i).getId());
|
|
|
+ }
|
|
|
+ for (int i = 0; i < patrolInspectionPlanVo.getPlanScheduleList().size(); i++) {
|
|
|
+ patrolInspectionPlanVo.getPlanScheduleList().get(i).setPlanId(patrolInspectionPlanVo.getId());
|
|
|
+ planScheduleService.save(patrolInspectionPlanVo.getPlanScheduleList().get(i));
|
|
|
+ }
|
|
|
+ //主计划地点更新
|
|
|
+ LambdaQueryWrapper<PlanSite> queryWrapperOne = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperOne.eq(PlanSite::getPlanId, patrolInspectionPlanVo.getId());
|
|
|
+ List<PlanSite> planSiteList = planSiteService.list(queryWrapperOne);
|
|
|
+ for (int i = 0; i < planSiteList.size(); i++) {
|
|
|
+ planSiteService.removeById(planSiteList.get(i).getId());
|
|
|
+ }
|
|
|
+ for (int i = 0; i < patrolInspectionPlanVo.getSiteArray().length; i++) {
|
|
|
+ PlanSite planSite = new PlanSite();
|
|
|
+ planSite.setPlanId(patrolInspectionPlanVo.getId());
|
|
|
+ planSite.setSiteId(patrolInspectionPlanVo.getSiteArray()[i]);
|
|
|
+ planSiteService.save(planSite);
|
|
|
+ }
|
|
|
+
|
|
|
+ //特殊休息日关联信息更改
|
|
|
+ LambdaQueryWrapper<SpecialRestDay> queryWrapperFour = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperFour.eq(SpecialRestDay::getPlanId, patrolInspectionPlanVo.getId());
|
|
|
+ List<SpecialRestDay> specialRestDayList = specialRestDayService.list(queryWrapperFour);
|
|
|
+ for (int i = 0; i < specialRestDayList.size(); i++) {
|
|
|
+ specialRestDayService.removeById(specialRestDayList.get(i).getId());
|
|
|
+ }
|
|
|
+ String timeStr3 = patrolInspectionPlanVo.getStartDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ int days = 0;
|
|
|
+ if (patrolInspectionPlanVo.getPlanType() == 1) {
|
|
|
+ days = OnlineMethod.fun(patrolInspectionPlanVo.getStartDate(), patrolInspectionPlanVo.getEndDate());
|
|
|
+ } else {
|
|
|
+ LocalDate date = OnlineMethod.getDate(timeStr3, "yyyy-MM-dd", true, 7 * (patrolInspectionPlanVo.getWeekCount() + 1));
|
|
|
+ days = OnlineMethod.fun(patrolInspectionPlanVo.getStartDate(), date);
|
|
|
+ }
|
|
|
+ for (int i = 0; i < days; i++) {
|
|
|
+ LocalDate date1 = OnlineMethod.getDate(timeStr3, "yyyy-MM-dd", true, i);
|
|
|
+ Date date = Date.from(date1.atStartOfDay(ZoneOffset.ofHours(8)).toInstant());
|
|
|
+ String week1 = OnlineMethod.getWeekOfDate(date);
|
|
|
+ if (patrolInspectionPlanVo.getRestDay().contains(week1)) {
|
|
|
+ SpecialRestDay specialRestDay = new SpecialRestDay();
|
|
|
+ specialRestDay.setPlanId(patrolInspectionPlanVo.getId());
|
|
|
+ specialRestDay.setRestDate(date1);
|
|
|
+ specialRestDayService.save(specialRestDay);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //子表数据更新
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPlanSon> queryWrapperTwo = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperTwo.eq(PatrolInspectionPlanSon::getPlanId, patrolInspectionPlanVo.getId());
|
|
|
+ List<PatrolInspectionPlanSon> patrolInspectionPlanSonList = patrolInspectionPlanSonService.list(queryWrapperTwo);
|
|
|
+ for (int i = 0; i < patrolInspectionPlanSonList.size(); i++) {
|
|
|
+ LambdaQueryWrapper<PlanSiteSon> queryWrapperThree = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperThree.eq(PlanSiteSon::getPlanId, patrolInspectionPlanSonList.get(i).getId());
|
|
|
+ List<PlanSiteSon> planSiteSonList = planSiteSonService.list(queryWrapperThree);
|
|
|
+ for (int j = 0; j < planSiteSonList.size(); j++) {
|
|
|
+ planSiteSonService.removeById(planSiteSonList.get(j).getId());
|
|
|
+ }
|
|
|
+ patrolInspectionPlanSonService.removeById(patrolInspectionPlanSonList.get(i).getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (patrolInspectionPlanVo.getPlanType() == 1) {//普通计划
|
|
|
+ //计算两时间天数
|
|
|
+ int day = OnlineMethod.fun(patrolInspectionPlanVo.getStartDate(), patrolInspectionPlanVo.getEndDate());
|
|
|
+ String timeStr1 = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ for (int i = 0; i < day; i++) {
|
|
|
+ for (int j = 0; j < patrolInspectionPlanVo.getPlanScheduleList().size(); j++) {
|
|
|
+ LocalDate s = OnlineMethod.getDate(timeStr1, "yyyy-MM-dd", true, i);
|
|
|
+ Date date = Date.from(s.atStartOfDay(ZoneOffset.ofHours(8)).toInstant());
|
|
|
+ String week = OnlineMethod.getWeekOfDate(date);
|
|
|
+ if (!patrolInspectionPlanVo.getRestDay().contains(week)) {
|
|
|
+ PatrolInspectionPlanSon patrolInspectionPlanSon = new PatrolInspectionPlanSon();
|
|
|
+ patrolInspectionPlanSon.setPlanId(patrolInspectionPlanVo.getId());
|
|
|
+ patrolInspectionPlanSon.setInspectionDate(s);
|
|
|
+ patrolInspectionPlanSon.setStartTime(patrolInspectionPlanVo.getPlanScheduleList().get(j).getStartTime());
|
|
|
+ patrolInspectionPlanSon.setEndTime(patrolInspectionPlanVo.getPlanScheduleList().get(j).getEndTime());
|
|
|
+ patrolInspectionPlanSon.setPersonnelId(patrolInspectionPlanVo.getPlanScheduleList().get(j).getPersonnelId());
|
|
|
+ patrolInspectionPlanSon.setAreaId(patrolInspectionPlanVo.getAreaId());
|
|
|
+ patrolInspectionPlanSon.setPlanType(patrolInspectionPlanVo.getPlanType());
|
|
|
+ patrolInspectionPlanSon.setPlanCycle(patrolInspectionPlanVo.getPlanCycle());
|
|
|
+ patrolInspectionPlanSon.setPlanFrequency(patrolInspectionPlanVo.getPlanFrequency());
|
|
|
+ patrolInspectionPlanSon.setLapTime(patrolInspectionPlanVo.getLapTime());
|
|
|
+ patrolInspectionPlanSon.setIntervalTime(patrolInspectionPlanVo.getIntervalTime());
|
|
|
+ patrolInspectionPlanSon.setPlanDescribe(patrolInspectionPlanVo.getPlanDescribe());
|
|
|
+ patrolInspectionPlanSon.setCompletion(0);
|
|
|
+ patrolInspectionPlanSon.setCreateTime(LocalDateTime.now());
|
|
|
+ patrolInspectionPlanSon.setCreator(SecurityUtils.getUsername());
|
|
|
+ patrolInspectionPlanSon.setAlternateField("0");
|
|
|
+ patrolInspectionPlanSon.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ patrolInspectionPlanSon.setCompanyId(patrolInspectionPlanVo.getCompanyId());
|
|
|
+ patrolInspectionPlanSonService.save(patrolInspectionPlanSon);
|
|
|
+ Integer zfid = patrolInspectionPlanSon.getId();
|
|
|
+ for (int k = 0; k < patrolInspectionPlanVo.getSiteArray().length; k++) {
|
|
|
+ PlanSiteSon planSiteSon = new PlanSiteSon();
|
|
|
+ planSiteSon.setPlanId(zfid);
|
|
|
+ planSiteSon.setSiteId(patrolInspectionPlanVo.getSiteArray()[k]);
|
|
|
+ planSiteSon.setInspectionStatus(1);
|
|
|
+ planSiteSonService.save(planSiteSon);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {//按次计划
|
|
|
+ for (int i = 0; i < patrolInspectionPlanVo.getWeekCount(); i++) {
|
|
|
+ String timeStr2 = patrolInspectionPlanVo.getStartDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ LocalDate sss = OnlineMethod.getDate(timeStr2, "yyyy-MM-dd", true, 7 * (i + 1));
|
|
|
+ PatrolInspectionPlanSon patrolInspectionPlanSon = new PatrolInspectionPlanSon();
|
|
|
+ patrolInspectionPlanSon.setPlanId(patrolInspectionPlanVo.getId());
|
|
|
+ if (i == 0) {
|
|
|
+ patrolInspectionPlanSon.setStartDate(patrolInspectionPlanVo.getStartDate());
|
|
|
+ } else {
|
|
|
+ LocalDate ssss = OnlineMethod.getDate(timeStr2, "yyyy-MM-dd", true, 7 * i + 1);
|
|
|
+ patrolInspectionPlanSon.setStartDate(ssss);
|
|
|
+ }
|
|
|
+ patrolInspectionPlanSon.setEndDate(sss);
|
|
|
+ patrolInspectionPlanSon.setPersonnelId(patrolInspectionPlanVo.getPlanScheduleList().get(0).getPersonnelId());
|
|
|
+ patrolInspectionPlanSon.setAreaId(patrolInspectionPlanVo.getAreaId());
|
|
|
+ patrolInspectionPlanSon.setPlanType(patrolInspectionPlanVo.getPlanType());
|
|
|
+ patrolInspectionPlanSon.setPlanCycle(patrolInspectionPlanVo.getPlanCycle());
|
|
|
+ patrolInspectionPlanSon.setPlanFrequency(patrolInspectionPlanVo.getPlanFrequency());
|
|
|
+ patrolInspectionPlanSon.setLapTime(patrolInspectionPlanVo.getLapTime());
|
|
|
+ patrolInspectionPlanSon.setIntervalTime(patrolInspectionPlanVo.getIntervalTime());
|
|
|
+ patrolInspectionPlanSon.setPlanDescribe(patrolInspectionPlanVo.getPlanDescribe());
|
|
|
+ patrolInspectionPlanSon.setCompletion(0);
|
|
|
+ patrolInspectionPlanSon.setCreateTime(LocalDateTime.now());
|
|
|
+ patrolInspectionPlanSon.setCreator(SecurityUtils.getUsername());
|
|
|
+ patrolInspectionPlanSon.setAlternateField("0");
|
|
|
+ patrolInspectionPlanSon.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ patrolInspectionPlanSon.setCompanyId(patrolInspectionPlanVo.getCompanyId());
|
|
|
+ patrolInspectionPlanSonService.save(patrolInspectionPlanSon);
|
|
|
+ Integer zfid = patrolInspectionPlanSon.getId();
|
|
|
+ for (int k = 0; k < patrolInspectionPlanVo.getSiteArray().length; k++) {
|
|
|
+ PlanSiteSon planSiteSon = new PlanSiteSon();
|
|
|
+ planSiteSon.setPlanId(zfid);
|
|
|
+ planSiteSon.setSiteId(patrolInspectionPlanVo.getSiteArray()[k]);
|
|
|
+ planSiteSon.setInspectionStatus(1);
|
|
|
+ planSiteSonService.save(planSiteSon);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void delPatrolInspectionPlan(Integer id) {
|
|
|
+ PatrolInspectionPlan patrolInspectionPlan = new PatrolInspectionPlan();
|
|
|
+ patrolInspectionPlan.setId(id);
|
|
|
+ patrolInspectionPlan.setEnable(0);
|
|
|
+ this.updateById(patrolInspectionPlan);
|
|
|
+// //特殊休息日关联信息更改
|
|
|
+// LambdaQueryWrapper<SpecialRestDay> queryWrapperFour= Wrappers.lambdaQuery();
|
|
|
+// queryWrapperFour.eq(SpecialRestDay::getPlanId, id);
|
|
|
+// List<SpecialRestDay> specialRestDayList = specialRestDayService.list(queryWrapperFour);
|
|
|
+// for (int i = 0; i < specialRestDayList.size(); i++) {
|
|
|
+// specialRestDayService.removeById(specialRestDayList.get(i).getId());
|
|
|
+// }
|
|
|
+// //巡检日程删除
|
|
|
+// LambdaQueryWrapper<PlanSchedule> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+// queryWrapper.eq(PlanSchedule::getPlanId, id);
|
|
|
+// List<PlanSchedule> planScheduleList = planScheduleService.list(queryWrapper);
|
|
|
+// for (int i = 0; i < planScheduleList.size(); i++) {
|
|
|
+// planScheduleService.removeById(planScheduleList.get(i).getId());
|
|
|
+// }
|
|
|
+// //主计划地点删除
|
|
|
+// LambdaQueryWrapper<PlanSite> queryWrapperOne = Wrappers.lambdaQuery();
|
|
|
+// queryWrapperOne.eq(PlanSite::getPlanId, id);
|
|
|
+// List<PlanSite> planSiteList = planSiteService.list(queryWrapperOne);
|
|
|
+// for (int i = 0; i < planSiteList.size(); i++) {
|
|
|
+// planSiteService.removeById(planSiteList.get(i).getId());
|
|
|
+// }
|
|
|
+// //子表数据删除
|
|
|
+// LambdaQueryWrapper<PatrolInspectionPlanSon> queryWrapperTwo = Wrappers.lambdaQuery();
|
|
|
+// queryWrapperTwo.eq(PatrolInspectionPlanSon::getPlanId,id);
|
|
|
+// List<PatrolInspectionPlanSon> patrolInspectionPlanSonList = patrolInspectionPlanSonService.list(queryWrapperTwo);
|
|
|
+// for (int i = 0; i < patrolInspectionPlanSonList.size(); i++) {
|
|
|
+// LambdaQueryWrapper<PlanSiteSon> queryWrapperThree = Wrappers.lambdaQuery();
|
|
|
+// queryWrapperThree.eq(PlanSiteSon::getPlanId, patrolInspectionPlanSonList.get(i).getId());
|
|
|
+// List<PlanSiteSon> planSiteSonList = planSiteSonService.list(queryWrapperThree);
|
|
|
+// for (int j = 0; j < planSiteSonList.size(); j++) {
|
|
|
+// planSiteSonService.removeById(planSiteSonList.get(j).getId());
|
|
|
+// }
|
|
|
+// patrolInspectionPlanSonService.removeById(patrolInspectionPlanSonList.get(i).getId());
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public CommonPage<PatrolInspectionPlanDataVo> patrolInspectionPlanList(String planName, Integer planType, Integer areaId, Integer pageNum, Integer pageSize, Integer id) {
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPlan> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PatrolInspectionPlan::getEnable, 1)
|
|
|
+ .eq(PatrolInspectionPlan::getTenantId, SecurityUtils.getTenantId());
|
|
|
+ if (planName != null && "".equals(planName)) {
|
|
|
+ queryWrapper.like(PatrolInspectionPlan::getPlanName, planName);
|
|
|
+ }
|
|
|
+ if (id != null && id != 0) {
|
|
|
+ queryWrapper.eq(PatrolInspectionPlan::getId, id);
|
|
|
+ }
|
|
|
+ if (planType != null && planType != 0) {
|
|
|
+ queryWrapper.eq(PatrolInspectionPlan::getPlanType, planType);
|
|
|
+ }
|
|
|
+ if (areaId != null && areaId != 0) {
|
|
|
+ queryWrapper.eq(PatrolInspectionPlan::getAreaId, areaId);
|
|
|
+ }
|
|
|
+ List<PatrolInspectionPlan> patrolInspectionPlanSonList = this.list(queryWrapper);
|
|
|
+ List<PlanSchedule> planScheduleList = planScheduleService.list();
|
|
|
+
|
|
|
+ List<PlanScheduleVo> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < planScheduleList.size(); i++) {
|
|
|
+ PlanScheduleVo planScheduleVo = new PlanScheduleVo();
|
|
|
+ planScheduleVo.setTime(planScheduleList.get(i).getStartTime() + "~" + planScheduleList.get(i).getEndTime());
|
|
|
+ planScheduleVo.setPersonnelId(planScheduleList.get(i).getPersonnelId());
|
|
|
+ planScheduleVo.setPersonnelName("未定义");
|
|
|
+ planScheduleVo.setPlanId(planScheduleList.get(i).getPlanId());
|
|
|
+ list.add(planScheduleVo);
|
|
|
+ }
|
|
|
+ List<PatrolInspectionPlanDataVo> list1 = new ArrayList<>();
|
|
|
+ for (int i = 0; i < patrolInspectionPlanSonList.size(); i++) {
|
|
|
+ PatrolInspectionPlanDataVo patrolInspectionPlanDataVo = new PatrolInspectionPlanDataVo();
|
|
|
+ patrolInspectionPlanDataVo.setId(patrolInspectionPlanSonList.get(i).getId());
|
|
|
+ patrolInspectionPlanDataVo.setPlanName(patrolInspectionPlanSonList.get(i).getPlanName());
|
|
|
+ patrolInspectionPlanDataVo.setStartDate(patrolInspectionPlanSonList.get(i).getStartDate());
|
|
|
+ patrolInspectionPlanDataVo.setEndDate(patrolInspectionPlanSonList.get(i).getEndDate());
|
|
|
+ patrolInspectionPlanDataVo.setAreaId(patrolInspectionPlanSonList.get(i).getAreaId());
|
|
|
+ patrolInspectionPlanDataVo.setPlanType(patrolInspectionPlanSonList.get(i).getPlanType());
|
|
|
+ patrolInspectionPlanDataVo.setPlanCycle(patrolInspectionPlanSonList.get(i).getPlanCycle());
|
|
|
+ patrolInspectionPlanDataVo.setPlanFrequency(patrolInspectionPlanSonList.get(i).getPlanFrequency());
|
|
|
+ patrolInspectionPlanDataVo.setLapTime(patrolInspectionPlanSonList.get(i).getLapTime());
|
|
|
+ patrolInspectionPlanDataVo.setIntervalTime(patrolInspectionPlanSonList.get(i).getIntervalTime());
|
|
|
+ patrolInspectionPlanDataVo.setPlanDescribe(patrolInspectionPlanSonList.get(i).getPlanDescribe());
|
|
|
+ patrolInspectionPlanDataVo.setCreateTime(patrolInspectionPlanSonList.get(i).getCreateTime());
|
|
|
+ patrolInspectionPlanDataVo.setCreator(patrolInspectionPlanSonList.get(i).getCreator());
|
|
|
+ patrolInspectionPlanDataVo.setEnable(patrolInspectionPlanSonList.get(i).getEnable());
|
|
|
+ patrolInspectionPlanDataVo.setTenantId(patrolInspectionPlanSonList.get(i).getTenantId());
|
|
|
+ patrolInspectionPlanDataVo.setCompanyId(patrolInspectionPlanSonList.get(i).getCompanyId());
|
|
|
+ patrolInspectionPlanDataVo.setRestDay(patrolInspectionPlanSonList.get(i).getRestDay());
|
|
|
+ patrolInspectionPlanDataVo.setWeekCount(patrolInspectionPlanSonList.get(i).getWeekCount());
|
|
|
+ List<PlanScheduleVo> list2 = new ArrayList<>();
|
|
|
+ for (int j = 0; j < list.size(); j++) {
|
|
|
+ if (patrolInspectionPlanSonList.get(i).getId() == list.get(j).getPlanId()) {
|
|
|
+ list.get(j).setWeekOne(patrolInspectionPlanSonList.get(i).getRestDay().contains("星期一") ? true : false);
|
|
|
+ list.get(j).setWeekTwo(patrolInspectionPlanSonList.get(i).getRestDay().contains("星期二") ? true : false);
|
|
|
+ list.get(j).setWeekThree(patrolInspectionPlanSonList.get(i).getRestDay().contains("星期三") ? true : false);
|
|
|
+ list.get(j).setWeekFour(patrolInspectionPlanSonList.get(i).getRestDay().contains("星期四") ? true : false);
|
|
|
+ list.get(j).setWeekFive(patrolInspectionPlanSonList.get(i).getRestDay().contains("星期五") ? true : false);
|
|
|
+ list.get(j).setWeekSix(patrolInspectionPlanSonList.get(i).getRestDay().contains("星期六") ? true : false);
|
|
|
+ list.get(j).setWeekSeven(patrolInspectionPlanSonList.get(i).getRestDay().contains("星期日") ? true : false);
|
|
|
+ list2.add(list.get(j));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ patrolInspectionPlanDataVo.setChildrenList(list2);
|
|
|
+ list1.add(patrolInspectionPlanDataVo);
|
|
|
+ }
|
|
|
+ List<PatrolInspectionPlanDataVo> list3 = list1.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
|
|
|
+ return new CommonPage<>(list3, list1.size(), pageNum, pageSize);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<PatrolInspectionSiteVo> patrolInspectionSiteVoList(Integer planId, Integer areaId) {
|
|
|
+ LambdaQueryWrapper<PatrolInspectionSite> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PatrolInspectionSite::getEnable, 1)
|
|
|
+ .eq(PatrolInspectionSite::getAreaId, areaId)
|
|
|
+ .eq(PatrolInspectionSite::getTenantId, SecurityUtils.getTenantId());
|
|
|
+ List<PatrolInspectionSite> patrolInspectionSiteList = patrolInspectionSiteService.list();
|
|
|
+ LambdaQueryWrapper<PlanSite> queryWrapperOne = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperOne.eq(PlanSite::getPlanId, planId);
|
|
|
+ List<PlanSite> planSiteList = planSiteService.list(queryWrapperOne);
|
|
|
+ LambdaQueryWrapper<PatrolInspectionArea> queryWrapperTwo = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperTwo.eq(PatrolInspectionArea::getEnable, 1)
|
|
|
+ .eq(PatrolInspectionArea::getTenantId, SecurityUtils.getTenantId());
|
|
|
+ List<PatrolInspectionArea> PatrolInspectionAreaList = patrolInspectionAreaService.list(queryWrapperTwo);
|
|
|
+ List<PatrolInspectionSiteVo> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < patrolInspectionSiteList.size(); i++) {
|
|
|
+ PatrolInspectionSiteVo patrolInspectionSiteVo = new PatrolInspectionSiteVo();
|
|
|
+ patrolInspectionSiteVo.setSiteName(patrolInspectionSiteList.get(i).getSiteName());
|
|
|
+ patrolInspectionSiteVo.setAreaId(patrolInspectionSiteList.get(i).getAreaId());
|
|
|
+ for (int j = 0; j < PatrolInspectionAreaList.size(); j++) {
|
|
|
+ if (patrolInspectionSiteList.get(i).getAreaId() == PatrolInspectionAreaList.get(j).getId()) {
|
|
|
+ patrolInspectionSiteVo.setAreaName(PatrolInspectionAreaList.get(j).getAreaName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ patrolInspectionSiteVo.setId(patrolInspectionSiteList.get(i).getId());
|
|
|
+ patrolInspectionSiteVo.setSiteStatus(false);
|
|
|
+ for (int j = 0; j < planSiteList.size(); j++) {
|
|
|
+ if (patrolInspectionSiteList.get(i).getId() == planSiteList.get(j).getSiteId()) {
|
|
|
+ patrolInspectionSiteVo.setSiteStatus(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list.add(patrolInspectionSiteVo);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+}
|