|
@@ -0,0 +1,279 @@
|
|
|
+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.PatrolInspectionRecordMapper;
|
|
|
+import com.usky.fire.service.*;
|
|
|
+import com.usky.fire.service.vo.ContentOptionVo;
|
|
|
+import com.usky.fire.service.vo.PatrolInspectionContentVo;
|
|
|
+import com.usky.fire.service.vo.PatrolInspectionRecordVo;
|
|
|
+import com.usky.fire.service.vo.RecordStatisticsVo;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 巡检记录表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author JCB
|
|
|
+ * @since 2022-07-21
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PatrolInspectionRecordServiceImpl extends AbstractCrudService<PatrolInspectionRecordMapper, PatrolInspectionRecord> implements PatrolInspectionRecordService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionRecordPictureService patrolInspectionRecordPictureService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionRecordOptionService patrolInspectionRecordOptionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SiteContentService siteContentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionContentService patrolInspectionContentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ContentOptionService contentOptionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionPlanSonService patrolInspectionPlanSonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PlanSiteSonService planSiteSonService;
|
|
|
+
|
|
|
+ public CommonPage<PatrolInspectionRecord> patrolInspectionRecordLsit(String areaName, String siteName, String name,
|
|
|
+ Integer planType, String startDateTime, String endDateTime,
|
|
|
+ Integer pageNum, Integer pageSize) {
|
|
|
+ LambdaQueryWrapper<PatrolInspectionRecord> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PatrolInspectionRecord::getTenantId, SecurityUtils.getTenantId());
|
|
|
+ if (areaName != null && "".equals(areaName)) {
|
|
|
+ queryWrapper.like(PatrolInspectionRecord::getAreaName, areaName);
|
|
|
+ }
|
|
|
+ if (siteName != null && "".equals(siteName)) {
|
|
|
+ queryWrapper.like(PatrolInspectionRecord::getSiteName, siteName);
|
|
|
+ }
|
|
|
+ if (name != null && "".equals(name)) {
|
|
|
+ queryWrapper.like(PatrolInspectionRecord::getName, name);
|
|
|
+ }
|
|
|
+ if (planType != null && planType != 0) {
|
|
|
+ queryWrapper.eq(PatrolInspectionRecord::getPlanType, planType);
|
|
|
+ }
|
|
|
+ if (startDateTime != null && "".equals(startDateTime) && endDateTime != null && "".equals(endDateTime)) {
|
|
|
+ queryWrapper.between(PatrolInspectionRecord::getCreateTime, startDateTime, endDateTime);
|
|
|
+ }
|
|
|
+ queryWrapper.orderByDesc(PatrolInspectionRecord::getId);
|
|
|
+ List<PatrolInspectionRecord> patrolInspectionRecordList = this.list(queryWrapper);
|
|
|
+ List<PatrolInspectionRecord> list = patrolInspectionRecordList.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
|
|
|
+ return new CommonPage<>(list, patrolInspectionRecordList.size(), pageSize, pageNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<PatrolInspectionRecordVo> patrolInspectionRecordDetails(Integer id) {
|
|
|
+ //记录查询
|
|
|
+ LambdaQueryWrapper<PatrolInspectionRecord> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PatrolInspectionRecord::getTenantId, SecurityUtils.getTenantId())
|
|
|
+ .eq(PatrolInspectionRecord::getId, id);
|
|
|
+ List<PatrolInspectionRecord> patrolInspectionRecordList = this.list(queryWrapper);
|
|
|
+
|
|
|
+ //上传图片查询
|
|
|
+ LambdaQueryWrapper<PatrolInspectionRecordPicture> queryWrapperOne = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperOne.eq(PatrolInspectionRecordPicture::getRecordId, id);
|
|
|
+ List<PatrolInspectionRecordPicture> patrolInspectionRecordPictureList = patrolInspectionRecordPictureService.list(queryWrapperOne);
|
|
|
+
|
|
|
+ //内容选中项查询
|
|
|
+ LambdaQueryWrapper<PatrolInspectionRecordOption> queryWrapperTwo = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperTwo.eq(PatrolInspectionRecordOption::getRecordId, id);
|
|
|
+ List<PatrolInspectionRecordOption> patrolInspectionRecordOptionList = patrolInspectionRecordOptionService.list(queryWrapperTwo);
|
|
|
+
|
|
|
+ //地点内容ID查询
|
|
|
+ LambdaQueryWrapper<SiteContent> queryWrapperThree = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperThree.in(SiteContent::getSiteId, patrolInspectionRecordList.get(0).getSiteId());
|
|
|
+ List<SiteContent> siteContentList = siteContentService.list(queryWrapperThree);
|
|
|
+
|
|
|
+ //内容ID重组
|
|
|
+ List<Integer> contentIdList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < siteContentList.size(); i++) {
|
|
|
+ contentIdList.add(siteContentList.get(i).getContentId());
|
|
|
+ }
|
|
|
+
|
|
|
+ //内容查询
|
|
|
+ LambdaQueryWrapper<PatrolInspectionContent> queryWrapperFour = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperFour.in(PatrolInspectionContent::getId, contentIdList)
|
|
|
+ .eq(PatrolInspectionContent::getEnable, 1);
|
|
|
+ List<PatrolInspectionContent> patrolInspectionContentList = patrolInspectionContentService.list(queryWrapperFour);
|
|
|
+
|
|
|
+ //内容选择项查询
|
|
|
+ LambdaQueryWrapper<ContentOption> queryWrapperFive = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperFive.in(ContentOption::getContentId, contentIdList)
|
|
|
+ .eq(ContentOption::getEnable, 1);
|
|
|
+ List<ContentOption> contentOptionList = contentOptionService.list(queryWrapperFive);
|
|
|
+
|
|
|
+ //重组内容选项
|
|
|
+ List<ContentOptionVo> contentOptionVoList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < contentOptionList.size(); i++) {
|
|
|
+ ContentOptionVo contentOptionVo = new ContentOptionVo();
|
|
|
+ contentOptionVo.setId(contentOptionList.get(i).getId());
|
|
|
+ contentOptionVo.setContentId(contentOptionList.get(i).getContentId());
|
|
|
+ contentOptionVo.setOptionName(contentOptionList.get(i).getOptionName());
|
|
|
+ contentOptionVo.setEnable(contentOptionList.get(i).getEnable());
|
|
|
+ contentOptionVo.setCreator(contentOptionList.get(i).getCreator());
|
|
|
+ contentOptionVo.setCreateTime(contentOptionList.get(i).getCreateTime());
|
|
|
+ contentOptionVo.setSelectStatus(false);
|
|
|
+ for (int j = 0; j < patrolInspectionRecordOptionList.size(); j++) {
|
|
|
+ contentOptionVo.setRemarks(patrolInspectionRecordOptionList.get(j).getRemarks());
|
|
|
+ if (contentOptionList.get(i).getId() == patrolInspectionRecordOptionList.get(j).getContentOptionId()) {
|
|
|
+ contentOptionVo.setSelectStatus(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ contentOptionVoList.add(contentOptionVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ //重组内容
|
|
|
+ List<PatrolInspectionContentVo> patrolInspectionContentVoList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < patrolInspectionContentList.size(); i++) {
|
|
|
+ PatrolInspectionContentVo patrolInspectionContentVo = new PatrolInspectionContentVo();
|
|
|
+ patrolInspectionContentVo.setId(patrolInspectionContentList.get(i).getId());
|
|
|
+ patrolInspectionContentVo.setContentTitle(patrolInspectionContentList.get(i).getContentTitle());
|
|
|
+ patrolInspectionContentVo.setContentDescribe(patrolInspectionContentList.get(i).getContentDescribe());
|
|
|
+ patrolInspectionContentVo.setSubmissionMethod(patrolInspectionContentList.get(i).getSubmissionMethod());
|
|
|
+ patrolInspectionContentVo.setTenantId(patrolInspectionContentList.get(i).getTenantId());
|
|
|
+ patrolInspectionContentVo.setCreateTime(patrolInspectionContentList.get(i).getCreateTime());
|
|
|
+ patrolInspectionContentVo.setCreator(patrolInspectionContentList.get(i).getCreator());
|
|
|
+ patrolInspectionContentVo.setEnable(patrolInspectionContentList.get(i).getEnable());
|
|
|
+ patrolInspectionContentVo.setCompanyId(patrolInspectionContentList.get(i).getCompanyId());
|
|
|
+ List<ContentOptionVo> contentOptionVoListOne = new ArrayList<>();
|
|
|
+ for (int j = 0; j < contentOptionVoList.size(); j++) {
|
|
|
+ if (patrolInspectionContentList.get(i).getId() == contentOptionVoList.get(j).getContentId()) {
|
|
|
+ patrolInspectionContentVo.setRemarks(contentOptionVoList.get(j).getRemarks());
|
|
|
+ contentOptionVoListOne.add(contentOptionVoList.get(j));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ patrolInspectionContentVo.setContentOptionVoList(contentOptionVoListOne);
|
|
|
+ patrolInspectionContentVoList.add(patrolInspectionContentVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ //重组巡检记录
|
|
|
+ List<PatrolInspectionRecordVo> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < patrolInspectionRecordList.size(); i++) {
|
|
|
+ PatrolInspectionRecordVo patrolInspectionRecordVo = new PatrolInspectionRecordVo();
|
|
|
+ patrolInspectionRecordVo.setId(patrolInspectionRecordList.get(i).getId());
|
|
|
+ patrolInspectionRecordVo.setSiteNubmber(patrolInspectionRecordList.get(i).getSiteNubmber());
|
|
|
+ patrolInspectionRecordVo.setSiteType(patrolInspectionRecordList.get(i).getSiteType());
|
|
|
+ patrolInspectionRecordVo.setAreaName(patrolInspectionRecordList.get(i).getAreaName());
|
|
|
+ patrolInspectionRecordVo.setSiteName(patrolInspectionRecordList.get(i).getSiteName());
|
|
|
+ patrolInspectionRecordVo.setName(patrolInspectionRecordList.get(i).getName());
|
|
|
+ patrolInspectionRecordVo.setPhone(patrolInspectionRecordList.get(i).getPhone());
|
|
|
+ patrolInspectionRecordVo.setPlanType(patrolInspectionRecordList.get(i).getPlanType());
|
|
|
+ patrolInspectionRecordVo.setSiteStatus(patrolInspectionRecordList.get(i).getSiteStatus());
|
|
|
+ patrolInspectionRecordVo.setLongitude(patrolInspectionRecordList.get(i).getLongitude());
|
|
|
+ patrolInspectionRecordVo.setLatitude(patrolInspectionRecordList.get(i).getLatitude());
|
|
|
+ patrolInspectionRecordVo.setStartDate(patrolInspectionRecordList.get(i).getStartDate());
|
|
|
+ patrolInspectionRecordVo.setEndDate(patrolInspectionRecordList.get(i).getEndDate());
|
|
|
+ patrolInspectionRecordVo.setCreateTime(patrolInspectionRecordList.get(i).getCreateTime());
|
|
|
+ patrolInspectionRecordVo.setPlanId(patrolInspectionRecordList.get(i).getPlanId());
|
|
|
+ patrolInspectionRecordVo.setPlanSonId(patrolInspectionRecordList.get(i).getPlanSonId());
|
|
|
+ patrolInspectionRecordVo.setSiteId(patrolInspectionRecordList.get(i).getSiteId());
|
|
|
+ patrolInspectionRecordVo.setTenantId(patrolInspectionRecordList.get(i).getTenantId());
|
|
|
+ patrolInspectionRecordVo.setCompanyId(patrolInspectionRecordList.get(i).getCompanyId());
|
|
|
+ patrolInspectionRecordVo.setRecordPictureList(patrolInspectionRecordPictureList);
|
|
|
+ patrolInspectionRecordVo.setContentVoList(patrolInspectionContentVoList);
|
|
|
+ list.add(patrolInspectionRecordVo);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RecordStatisticsVo recordStatistics(String startDate, String endDate) {
|
|
|
+ List<Integer> planSonidListOne = this.getPlanSon(startDate, endDate);
|
|
|
+ Integer taskCount = 0;
|
|
|
+ Integer taskCountLeak = 0;
|
|
|
+ Integer taskCountComplete = 0;
|
|
|
+ Integer siteCount = 0;
|
|
|
+ Integer siteCountLeak = 0;
|
|
|
+ Integer planCount = 0;
|
|
|
+ if (planSonidListOne.size() > 0) {
|
|
|
+ planCount = planSonidListOne.size();
|
|
|
+ taskCount = this.getPlanSiteSonCount(planSonidListOne, 0);
|
|
|
+ taskCountLeak = this.getPlanSiteSonCount(planSonidListOne, 1);
|
|
|
+ taskCountComplete = this.getPlanSiteSonCount(planSonidListOne, 2);
|
|
|
+ }
|
|
|
+ List<Integer> planSonidListTwo = this.getPlanSon(null, null);
|
|
|
+ if (planSonidListTwo.size() > 0) {
|
|
|
+ siteCount = this.getPlanSiteSonCount(planSonidListOne, 0);
|
|
|
+ siteCountLeak = this.getPlanSiteSonCount(planSonidListOne, 1);
|
|
|
+ }
|
|
|
+ RecordStatisticsVo recordStatisticsVo = new RecordStatisticsVo();
|
|
|
+ recordStatisticsVo.setTaskCount(taskCount);
|
|
|
+ recordStatisticsVo.setTaskCountLeak(taskCountLeak);
|
|
|
+ recordStatisticsVo.setTaskCountComplete(taskCountComplete);
|
|
|
+ recordStatisticsVo.setSiteCount(siteCount);
|
|
|
+ recordStatisticsVo.setSiteCountLeak(siteCountLeak);
|
|
|
+ recordStatisticsVo.setPlanCount(planCount);
|
|
|
+ return recordStatisticsVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 子计划点位表总数统计
|
|
|
+ *
|
|
|
+ * @param planSonidList 子计划ID
|
|
|
+ * @param inspectionStatus 巡检状态(1 未巡检,2 已巡检)
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Integer getPlanSiteSonCount(List<Integer> planSonidList, Integer inspectionStatus) {
|
|
|
+ LambdaQueryWrapper<PlanSiteSon> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.in(PlanSiteSon::getPlanId, planSonidList);
|
|
|
+ if (inspectionStatus != 0 && inspectionStatus != null) {
|
|
|
+ queryWrapper.eq(PlanSiteSon::getInspectionStatus, inspectionStatus);
|
|
|
+ }
|
|
|
+ Integer taskCount = planSiteSonService.count(queryWrapper);
|
|
|
+ return taskCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 子计划数据查询
|
|
|
+ *
|
|
|
+ * @param startDate 开始时间 yyyy-MM-dd
|
|
|
+ * @param endDate 结束时间 yyyy-MM-dd
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Integer> getPlanSon(String startDate, String endDate) {
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPlanSon> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PatrolInspectionPlanSon::getPlanType, 1)
|
|
|
+ .eq(PatrolInspectionPlanSon::getTenantId, SecurityUtils.getTenantId());
|
|
|
+ if (!"".equals(startDate) && startDate != null && !"".equals(endDate) && endDate != null) {
|
|
|
+ queryWrapper.between(PatrolInspectionPlanSon::getInspectionDate, startDate, endDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PatrolInspectionPlanSon> planCountListOne = patrolInspectionPlanSonService.list(queryWrapper);
|
|
|
+ List<Integer> planSonidListOne = new ArrayList<>();
|
|
|
+ for (int i = 0; i < planCountListOne.size(); i++) {
|
|
|
+ planSonidListOne.add(planCountListOne.get(i).getId());
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPlanSon> queryWrapperOne = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperOne.eq(PatrolInspectionPlanSon::getPlanType, 2)
|
|
|
+ .eq(PatrolInspectionPlanSon::getTenantId, SecurityUtils.getTenantId());
|
|
|
+ if (!"".equals(startDate) && startDate != null && !"".equals(endDate) && endDate != null) {
|
|
|
+ queryWrapperOne.and(wq -> wq
|
|
|
+ .between(PatrolInspectionPlanSon::getStartDate, startDate, endDate)
|
|
|
+ .or()
|
|
|
+ .between(PatrolInspectionPlanSon::getEndDate, startDate, endDate)
|
|
|
+ ).groupBy(PatrolInspectionPlanSon::getId);
|
|
|
+ }
|
|
|
+ List<PatrolInspectionPlanSon> planCountListTwo = patrolInspectionPlanSonService.list(queryWrapperOne);
|
|
|
+ for (int i = 0; i < planCountListTwo.size(); i++) {
|
|
|
+ planSonidListOne.add(planCountListTwo.get(i).getId());
|
|
|
+ }
|
|
|
+ return planSonidListOne;
|
|
|
+ }
|
|
|
+}
|