|
@@ -0,0 +1,188 @@
|
|
|
+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.core.exception.BusinessException;
|
|
|
+import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import com.usky.common.security.utils.SecurityUtils;
|
|
|
+import com.usky.fire.domain.ContentOption;
|
|
|
+import com.usky.fire.domain.PatrolInspectionContent;
|
|
|
+import com.usky.fire.domain.SiteContent;
|
|
|
+import com.usky.fire.mapper.PatrolInspectionContentMapper;
|
|
|
+import com.usky.fire.service.ContentOptionService;
|
|
|
+import com.usky.fire.service.PatrolInspectionContentService;
|
|
|
+import com.usky.fire.service.SiteContentService;
|
|
|
+import com.usky.fire.service.vo.PatrolInspectionContentVo;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author JCB
|
|
|
+ * @since 2022-07-15
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PatrolInspectionContentServiceImpl extends AbstractCrudService<PatrolInspectionContentMapper, PatrolInspectionContent> implements PatrolInspectionContentService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ContentOptionService contentOptionService;
|
|
|
+ @Autowired
|
|
|
+ private SiteContentService siteContentService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void addPatrolInspectionContent(PatrolInspectionContentVo patrolInspectionContentVo) {
|
|
|
+ PatrolInspectionContent patrolInspectionContent = new PatrolInspectionContent();
|
|
|
+ patrolInspectionContent.setContentTitle(patrolInspectionContentVo.getContentTitle());
|
|
|
+ patrolInspectionContent.setContentDescribe(patrolInspectionContentVo.getContentDescribe());
|
|
|
+ patrolInspectionContent.setSubmissionMethod(patrolInspectionContentVo.getSubmissionMethod());
|
|
|
+ patrolInspectionContent.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ patrolInspectionContent.setCompanyId(patrolInspectionContentVo.getCompanyId());
|
|
|
+ patrolInspectionContent.setCreateTime(LocalDateTime.now());
|
|
|
+ patrolInspectionContent.setCreator(SecurityUtils.getUsername());
|
|
|
+ patrolInspectionContent.setEnable(1);
|
|
|
+ this.save(patrolInspectionContent);
|
|
|
+ if (patrolInspectionContentVo.getContentOptionList().size() > 0) {
|
|
|
+ Integer fid = patrolInspectionContent.getId();
|
|
|
+ for (int i = 0; i < patrolInspectionContentVo.getContentOptionList().size(); i++) {
|
|
|
+ ContentOption contentOption = new ContentOption();
|
|
|
+ contentOption.setOptionName(patrolInspectionContentVo.getContentOptionList().get(i).getOptionName());
|
|
|
+ contentOption.setContentId(fid);
|
|
|
+ contentOption.setEnable(1);
|
|
|
+ contentOption.setCreator(SecurityUtils.getUsername());
|
|
|
+ contentOption.setCreateTime(LocalDateTime.now());
|
|
|
+ contentOptionService.save(contentOption);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void updatePatrolInspectionContent(PatrolInspectionContentVo patrolInspectionContentVo) {
|
|
|
+ PatrolInspectionContent patrolInspectionContent = new PatrolInspectionContent();
|
|
|
+ patrolInspectionContent.setId(patrolInspectionContentVo.getId());
|
|
|
+ patrolInspectionContent.setContentTitle(patrolInspectionContentVo.getContentTitle());
|
|
|
+ patrolInspectionContent.setContentDescribe(patrolInspectionContentVo.getContentDescribe());
|
|
|
+ patrolInspectionContent.setSubmissionMethod(patrolInspectionContentVo.getSubmissionMethod());
|
|
|
+ patrolInspectionContent.setCompanyId(patrolInspectionContentVo.getCompanyId());
|
|
|
+ this.updateById(patrolInspectionContent);
|
|
|
+ LambdaQueryWrapper<ContentOption> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(ContentOption::getEnable, 1)
|
|
|
+ .eq(ContentOption::getContentId,patrolInspectionContentVo.getId());
|
|
|
+ List<ContentOption> ContentOptionList = contentOptionService.list(queryWrapper);
|
|
|
+ if (ContentOptionList.size() > 0) {
|
|
|
+ for (int i = 0; i < ContentOptionList.size(); i++) {
|
|
|
+ ContentOptionList.get(i).setEnable(0);
|
|
|
+ contentOptionService.updateById(ContentOptionList.get(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (patrolInspectionContentVo.getContentOptionList().size() > 0) {
|
|
|
+ for (int i = 0; i < patrolInspectionContentVo.getContentOptionList().size(); i++) {
|
|
|
+ ContentOption contentOption = new ContentOption();
|
|
|
+ contentOption.setOptionName(patrolInspectionContentVo.getContentOptionList().get(i).getOptionName());
|
|
|
+ contentOption.setContentId(patrolInspectionContentVo.getId());
|
|
|
+ if (patrolInspectionContentVo.getContentOptionList().get(i).getId() != 0 &&
|
|
|
+ patrolInspectionContentVo.getContentOptionList().get(i).getId() != null) {
|
|
|
+ contentOption.setId(patrolInspectionContentVo.getContentOptionList().get(i).getId());
|
|
|
+ contentOption.setEnable(1);
|
|
|
+ contentOptionService.updateById(contentOption);
|
|
|
+ } else {
|
|
|
+ contentOption.setEnable(1);
|
|
|
+ contentOption.setCreator(SecurityUtils.getUsername());
|
|
|
+ contentOption.setCreateTime(LocalDateTime.now());
|
|
|
+ contentOptionService.save(contentOption);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void delPatrolInspectionContent(Integer id) {
|
|
|
+ LambdaQueryWrapper<SiteContent> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(SiteContent::getContentId, id);
|
|
|
+ List<SiteContent> siteContentList = siteContentService.list(queryWrapper);
|
|
|
+ if (siteContentList.size() > 0) {
|
|
|
+ throw new BusinessException("巡检内容正在使用中不可删除");
|
|
|
+ }
|
|
|
+ PatrolInspectionContent patrolInspectionContent = new PatrolInspectionContent();
|
|
|
+ patrolInspectionContent.setId(id);
|
|
|
+ patrolInspectionContent.setEnable(0);
|
|
|
+ this.updateById(patrolInspectionContent);
|
|
|
+ LambdaQueryWrapper<ContentOption> queryWrapperOne = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperOne.eq(ContentOption::getContentId, id)
|
|
|
+ .eq(ContentOption::getEnable, 1);
|
|
|
+ List<ContentOption> contentOptionList = contentOptionService.list(queryWrapperOne);
|
|
|
+ if (contentOptionList.size() > 0) {
|
|
|
+ for (int i = 0; i < contentOptionList.size(); i++) {
|
|
|
+ ContentOption contentOption = new ContentOption();
|
|
|
+ contentOption.setId(contentOptionList.get(i).getId());
|
|
|
+ contentOption.setEnable(0);
|
|
|
+ contentOptionService.updateById(contentOption);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonPage<PatrolInspectionContentVo> patrolInspectionContentList(String contentTitle, Integer pageNum, Integer pageSize, Integer id) {
|
|
|
+ LambdaQueryWrapper<PatrolInspectionContent> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PatrolInspectionContent::getTenantId, SecurityUtils.getTenantId())
|
|
|
+ .eq(PatrolInspectionContent::getEnable, 1);
|
|
|
+ if (contentTitle != null && !"".equals(contentTitle)) {
|
|
|
+ queryWrapper.like(PatrolInspectionContent::getContentTitle, contentTitle);
|
|
|
+ }
|
|
|
+ if (id != 0 && id != null) {
|
|
|
+ queryWrapper.eq(PatrolInspectionContent::getId, id);
|
|
|
+ }
|
|
|
+ List<PatrolInspectionContent> patrolInspectionContentList = this.list(queryWrapper);
|
|
|
+ List<PatrolInspectionContentVo> list = new ArrayList<>();
|
|
|
+ List<PatrolInspectionContentVo> patrolInspectionContentVoList = new ArrayList<>();
|
|
|
+ if (patrolInspectionContentList.size() > 0) {
|
|
|
+ List<Integer> idList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < patrolInspectionContentList.size(); i++) {
|
|
|
+ idList.add(patrolInspectionContentList.get(i).getId());
|
|
|
+
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<ContentOption> queryWrapperOne = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperOne.eq(ContentOption::getEnable, 1)
|
|
|
+ .in(ContentOption::getContentId, idList);
|
|
|
+ List<ContentOption> contentOptionList = contentOptionService.list(queryWrapperOne);
|
|
|
+ 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.setCompanyId(patrolInspectionContentList.get(i).getCompanyId());
|
|
|
+ patrolInspectionContentVo.setCreator(patrolInspectionContentList.get(i).getCreator());
|
|
|
+ patrolInspectionContentVo.setCreateTime(patrolInspectionContentList.get(i).getCreateTime());
|
|
|
+ patrolInspectionContentVo.setEnable(patrolInspectionContentList.get(i).getEnable());
|
|
|
+ List<ContentOption> contentOptionListOne = new ArrayList<>();
|
|
|
+ for (int j = 0; j < contentOptionList.size(); j++) {
|
|
|
+ if (patrolInspectionContentList.get(i).getId() == contentOptionList.get(j).getContentId()) {
|
|
|
+ contentOptionListOne.add(contentOptionList.get(j));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ patrolInspectionContentVo.setContentOptionList(contentOptionListOne);
|
|
|
+ patrolInspectionContentVoList.add(patrolInspectionContentVo);
|
|
|
+ }
|
|
|
+ list = patrolInspectionContentVoList.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
|
|
|
+
|
|
|
+ }
|
|
|
+ return new CommonPage<>(list, patrolInspectionContentVoList.size(), pageNum, pageSize);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|