|
|
@@ -0,0 +1,316 @@
|
|
|
+package com.xunmei.system.service.impl;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
+import com.xunmei.common.core.exception.ServiceException;
|
|
|
+import com.xunmei.common.core.utils.DateUtils;
|
|
|
+import com.xunmei.common.core.utils.IDHelper;
|
|
|
+import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
+import com.xunmei.core.question.QuestionConfirmEnum;
|
|
|
+import com.xunmei.core.question.QuestionReformEnum;
|
|
|
+import com.xunmei.core.question.dto.QuestionConfirmDto;
|
|
|
+import com.xunmei.core.question.dto.QuestionPageDto;
|
|
|
+import com.xunmei.core.question.dto.QuestionReformDto;
|
|
|
+import com.xunmei.core.question.vo.QuestionFlowVo;
|
|
|
+import com.xunmei.core.question.QuestionSrcType;
|
|
|
+import com.xunmei.core.question.vo.QuestionVo;
|
|
|
+import com.xunmei.system.api.RemoteOrgService;
|
|
|
+import com.xunmei.system.domain.QuestionFlow;
|
|
|
+import com.xunmei.system.mapper.QuestionFlowMapper;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
+import com.xunmei.system.mapper.QuestionMapper;
|
|
|
+import com.xunmei.system.domain.Question;
|
|
|
+import com.xunmei.system.service.IQuestionService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 隐患问题清单Service业务层处理
|
|
|
+ *
|
|
|
+ * @author xunmei
|
|
|
+ * @date 2023-09-12
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> implements IQuestionService {
|
|
|
+ @Autowired
|
|
|
+ private QuestionFlowMapper questionFlowMapper;
|
|
|
+ @Autowired
|
|
|
+ private RemoteOrgService orgService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<Question> selectPage(QuestionPageDto query) {
|
|
|
+ //未删除
|
|
|
+ Page<Question> page = query.toPage();
|
|
|
+
|
|
|
+ //查询条件
|
|
|
+ LambdaQueryWrapper<Question> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ //下穿
|
|
|
+ if (query.getCheckSub()) {
|
|
|
+ List<Long> ids = orgService.selectCheckSubOrgIdList(query.getOrgId(), SecurityConstants.INNER);
|
|
|
+ //添加in条件
|
|
|
+ wrapper.in(Question::getOrgId, ids);
|
|
|
+ } else {
|
|
|
+ wrapper.eq(Question::getOrgId, query.getOrgId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(query.getConfirmStatus())) {
|
|
|
+ wrapper.eq(Question::getConfirmStatus, query.getConfirmStatus());
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(query.getReformStatus())) {
|
|
|
+ wrapper.eq(Question::getReformStatus, query.getReformStatus());
|
|
|
+ }
|
|
|
+ //时间范围查询
|
|
|
+ if (ObjectUtil.isNotEmpty(query.getSubmitRange()) && query.getSubmitRange().length == 2) {
|
|
|
+ LocalDateTime start = LocalDateTimeUtil.beginOfDay(query.getSubmitRange()[0]);
|
|
|
+ LocalDateTime end = LocalDateTimeUtil.endOfDay(query.getSubmitRange()[1]);
|
|
|
+ wrapper.between(Question::getSubmitTime, start, end);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(query.getSearchKey())) {
|
|
|
+ wrapper.and(w ->
|
|
|
+ w.like(Question::getCheckContent, query.getSearchKey()).or().like(Question::getSrcTaskName, query.getSearchKey())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取数据
|
|
|
+ page = baseMapper.selectPage(page, wrapper);
|
|
|
+// Page<QuestionPageDto> r =page.
|
|
|
+ //抓换为TableDataInfo适配前端
|
|
|
+ return TableDataInfo.build(page);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询隐患问题清单
|
|
|
+ *
|
|
|
+ * @param id 隐患问题清单主键
|
|
|
+ * @return 隐患问题清单
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public QuestionVo selectQuestionById(Long id) {
|
|
|
+ QuestionVo vo = new QuestionVo();
|
|
|
+ Question q = baseMapper.selectById(id);
|
|
|
+ BeanUtils.copyProperties(q, vo);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<QuestionFlow> flowWrapper = new LambdaQueryWrapper<QuestionFlow>();
|
|
|
+ flowWrapper.eq(QuestionFlow::getQuestionId, id);
|
|
|
+ List<QuestionFlow> flows = questionFlowMapper.selectList(flowWrapper);
|
|
|
+
|
|
|
+ vo.setFlows(flows.stream().map(f -> {
|
|
|
+ QuestionFlowVo fvo = new QuestionFlowVo();
|
|
|
+ BeanUtils.copyProperties(f, fvo);
|
|
|
+ return fvo;
|
|
|
+ }).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询隐患问题清单列表
|
|
|
+ *
|
|
|
+ * @param coreQuestion 隐患问题清单
|
|
|
+ * @return 隐患问题清单
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Question> selectQuestionList(Question coreQuestion) {
|
|
|
+ return baseMapper.selectList(new QueryWrapper<>(coreQuestion));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增隐患问题清单
|
|
|
+ *
|
|
|
+ * @param question 隐患问题清单
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public int insertQuestion(Question question) {
|
|
|
+ question.setId(IDHelper.id());
|
|
|
+ question.setReformStatus(QuestionReformEnum.Unreform.getValue());
|
|
|
+ if (ObjectUtil.equal(question.getSrcType(), QuestionSrcType.Resumption.getValue())) {
|
|
|
+ question.setConfirmStatus(QuestionConfirmEnum.Confirmed.getValue());
|
|
|
+ QuestionFlow flow = new QuestionFlow();
|
|
|
+ flow.setQuestionId(question.getId());
|
|
|
+ flow.setExecuteTime(new Date());
|
|
|
+ flow.setExecutorId(SecurityUtils.getUserId());
|
|
|
+ flow.setExecutorName(SecurityUtils.getLoginUser().getName());
|
|
|
+ flow.setExecuteStatus(QuestionConfirmEnum.Confirmed.getValue());
|
|
|
+ questionFlowMapper.insert(flow);
|
|
|
+ } else {
|
|
|
+ question.setConfirmStatus(QuestionConfirmEnum.Unconfirm.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ return baseMapper.insert(question);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改隐患问题清单
|
|
|
+ *
|
|
|
+ * @param coreQuestion 隐患问题清单
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public int updateQuestion(Question coreQuestion) {
|
|
|
+ coreQuestion.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ return baseMapper.updateById(coreQuestion);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除隐患问题清单
|
|
|
+ *
|
|
|
+ * @param ids 需要删除的隐患问题清单主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteQuestionByIds(Long[] ids) {
|
|
|
+ return baseMapper.deleteBatchIds(Arrays.asList((ids)));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除隐患问题清单信息
|
|
|
+ *
|
|
|
+ * @param id 隐患问题清单主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteQuestionById(Long id) {
|
|
|
+ return baseMapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Boolean confirm(QuestionConfirmDto confirmDto) {
|
|
|
+ Question question = baseMapper.selectById(confirmDto.getId());
|
|
|
+ if (ObjectUtil.isNull(question)) {
|
|
|
+ throw new ServiceException("隐患问题不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.equal(question.getConfirmStatus(), QuestionConfirmEnum.Confirmed.getValue())) {
|
|
|
+ throw new ServiceException("隐患问题已确认");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.equal(question.getConfirmStatus(), QuestionConfirmEnum.Closed.getValue())) {
|
|
|
+ throw new ServiceException("隐患问题已关闭");
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<Question> updateWrapper = new LambdaUpdateWrapper();
|
|
|
+ QuestionFlow flow = new QuestionFlow();
|
|
|
+ flow.setQuestionId(confirmDto.getId());
|
|
|
+ flow.setDescription(confirmDto.getDescription());
|
|
|
+ flow.setExecuteTime(new Date());
|
|
|
+ flow.setExecutorId(SecurityUtils.getUserId());
|
|
|
+ flow.setExecutorName(SecurityUtils.getLoginUser().getName());
|
|
|
+
|
|
|
+ updateWrapper.eq(Question::getId, confirmDto.getId());
|
|
|
+ if (ObjectUtil.equal(confirmDto.getStatus(), 0)) {
|
|
|
+ flow.setExecuteStatus(QuestionConfirmEnum.Confirmed.getValue());
|
|
|
+ updateWrapper.set(Question::getConfirmStatus, QuestionConfirmEnum.Confirmed);
|
|
|
+ } else {
|
|
|
+ flow.setExecuteStatus(QuestionConfirmEnum.Dissent.getValue());
|
|
|
+ updateWrapper.set(Question::getConfirmStatus, QuestionConfirmEnum.Dissent);
|
|
|
+ }
|
|
|
+
|
|
|
+ questionFlowMapper.insert(flow);
|
|
|
+ int count = baseMapper.update(null, updateWrapper);
|
|
|
+
|
|
|
+ return count > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Boolean confirmDissent(QuestionConfirmDto confirmDto) {
|
|
|
+ Question question = baseMapper.selectById(confirmDto.getId());
|
|
|
+ if (ObjectUtil.isNull(question)) {
|
|
|
+ throw new ServiceException("隐患问题不存在");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.notEqual(question.getConfirmStatus(), QuestionConfirmEnum.Dissent.getValue())) {
|
|
|
+ throw new ServiceException("隐患问题未处于异议状态");
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<Question> updateWrapper = new LambdaUpdateWrapper();
|
|
|
+ QuestionFlow flow = new QuestionFlow();
|
|
|
+ flow.setQuestionId(confirmDto.getId());
|
|
|
+ flow.setDescription(confirmDto.getDescription());
|
|
|
+ flow.setExecuteTime(new Date());
|
|
|
+ flow.setExecutorId(SecurityUtils.getUserId());
|
|
|
+ flow.setExecutorName(SecurityUtils.getLoginUser().getName());
|
|
|
+
|
|
|
+ updateWrapper.eq(Question::getId, confirmDto.getId());
|
|
|
+ flow.setExecuteStatus(QuestionConfirmEnum.Confirmed.getValue());
|
|
|
+ updateWrapper.set(Question::getConfirmStatus, QuestionConfirmEnum.Confirmed);
|
|
|
+
|
|
|
+ questionFlowMapper.insert(flow);
|
|
|
+ int count = baseMapper.update(null, updateWrapper);
|
|
|
+
|
|
|
+ return count > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 整改
|
|
|
+ *
|
|
|
+ * @param reformDto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Boolean reform(QuestionReformDto reformDto) {
|
|
|
+ Question question = baseMapper.selectById(reformDto.getId());
|
|
|
+ if (ObjectUtil.isNull(question)) {
|
|
|
+ throw new ServiceException("隐患问题不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.notEqual(question.getConfirmStatus(), QuestionConfirmEnum.Confirmed.getValue())) {
|
|
|
+ throw new ServiceException("隐患问题未确认");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.equal(question.getConfirmStatus(), QuestionConfirmEnum.Closed.getValue())) {
|
|
|
+ throw new ServiceException("隐患问题已关闭");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.equal(question.getReformStatus(), QuestionReformEnum.Reformed.getValue())) {
|
|
|
+ throw new ServiceException("隐患问题已整改");
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<Question> updateWrapper = new LambdaUpdateWrapper();
|
|
|
+ updateWrapper.eq(Question::getId, reformDto.getId());
|
|
|
+ updateWrapper.set(Question::getReformStatus, QuestionReformEnum.Reformed.getValue())
|
|
|
+ .set(Question::getConfirmStatus, QuestionConfirmEnum.Closed.getValue());
|
|
|
+
|
|
|
+ QuestionFlow flow = new QuestionFlow();
|
|
|
+ flow.setQuestionId(reformDto.getId());
|
|
|
+ flow.setDescription(reformDto.getDescription());
|
|
|
+ flow.setExecuteTime(new Date());
|
|
|
+ flow.setExecutorId(SecurityUtils.getUserId());
|
|
|
+ flow.setExecutorName(SecurityUtils.getLoginUser().getName());
|
|
|
+ flow.setImages(JSON.toJSONString(reformDto.getImages()));
|
|
|
+
|
|
|
+ questionFlowMapper.insert(flow);
|
|
|
+ int count = baseMapper.update(null, updateWrapper);
|
|
|
+
|
|
|
+ return count > 0;
|
|
|
+ }
|
|
|
+}
|