|
|
@@ -0,0 +1,273 @@
|
|
|
+package cn.start.tz.module.pressure2.service.pipeuseregistrationreport;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.start.tz.framework.common.exception.ErrorCode;
|
|
|
+import cn.start.tz.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
|
+import cn.start.tz.framework.security.core.service.SecurityFrameworkService;
|
|
|
+import cn.start.tz.module.bpm.api.task.dto.BpmUserGroupDTO;
|
|
|
+import cn.start.tz.module.member.api.user.MemberUserApi;
|
|
|
+import cn.start.tz.module.member.api.user.dto.MemberUserRespDTO;
|
|
|
+import cn.start.tz.module.pressure2.constant.TemplateIdConstants;
|
|
|
+import cn.start.tz.module.pressure2.controller.admin.dynamictbins.vo.CreateInstantiateWithRuleVO;
|
|
|
+import cn.start.tz.module.pressure2.controller.admin.pipetaskorder.vo.PipeOrderItemPageRespVO;
|
|
|
+import cn.start.tz.module.pressure2.dal.dataobject.boilerconnecttbservice.BoilerConnectTbServiceDO;
|
|
|
+import cn.start.tz.module.pressure2.dal.dataobject.dynamictb.DynamicTbDO;
|
|
|
+import cn.start.tz.module.pressure2.dal.dataobject.equippipe.EquipPipeDO;
|
|
|
+import cn.start.tz.module.pressure2.dal.dataobject.pipetaskorder.PipeTaskOrderDO;
|
|
|
+import cn.start.tz.module.pressure2.dal.dataobject.pipetaskorderitem.PipeTaskOrderItemDO;
|
|
|
+import cn.start.tz.module.pressure2.dal.mysql.boilerconnecttbservice.BoilerConnectTbServiceMapper;
|
|
|
+import cn.start.tz.module.pressure2.dal.mysql.dynamictb.DynamicTbMapper;
|
|
|
+import cn.start.tz.module.pressure2.dal.mysql.equippipe.EquipPipeMapper;
|
|
|
+import cn.start.tz.module.pressure2.dal.mysql.pipetaskorder.PipeTaskOrderMapper;
|
|
|
+import cn.start.tz.module.pressure2.dal.mysql.pipetaskorderitem.PipeTaskOrderItemMapper;
|
|
|
+import cn.start.tz.module.pressure2.dal.mysql.pipetaskorderitemreport.PipeTaskOrderItemReportMapper;
|
|
|
+import cn.start.tz.module.pressure2.service.dynamictbins.DynamicTbInsService;
|
|
|
+import cn.start.tz.module.system.api.dept.DeptApi;
|
|
|
+import cn.start.tz.module.system.api.dept.dto.DeptRespDTO;
|
|
|
+import cn.start.tz.module.system.api.user.AdminUserApi;
|
|
|
+import cn.start.tz.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+import cn.start.tz.module.pressure2.controller.admin.pipeuseregistrationreport.vo.*;
|
|
|
+import cn.start.tz.module.pressure2.dal.dataobject.pipeuseregistrationreport.PipeUseRegistrationReportDO;
|
|
|
+import cn.start.tz.framework.common.pojo.PageResult;
|
|
|
+import cn.start.tz.framework.common.pojo.PageParam;
|
|
|
+import cn.start.tz.framework.common.util.object.BeanUtils;
|
|
|
+
|
|
|
+import cn.start.tz.module.pressure2.dal.mysql.pipeuseregistrationreport.PipeUseRegistrationReportMapper;
|
|
|
+
|
|
|
+import static cn.start.tz.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
+import static cn.start.tz.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
|
+import static cn.start.tz.module.pressure2.enums.ErrorCodeConstants.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 管道使用登记 Service 实现类
|
|
|
+ *
|
|
|
+ * @author 特种管理员
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Validated
|
|
|
+public class PipeUseRegistrationReportServiceImpl extends ServiceImpl<PipeUseRegistrationReportMapper, PipeUseRegistrationReportDO> implements PipeUseRegistrationReportService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PipeUseRegistrationReportMapper pipeUseRegistrationReportMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PipeTaskOrderMapper pipeTaskOrderMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PipeTaskOrderItemMapper pipeTaskOrderItemMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PipeTaskOrderItemReportMapper pipeTaskOrderItemReportMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private EquipPipeMapper equipPipeMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DynamicTbMapper dynamicTbMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DeptApi deptApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AdminUserApi adminUserApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DynamicTbInsService dynamicTbInsService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BoilerConnectTbServiceMapper boilerConnectTbServiceMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SecurityFrameworkService securityFrameworkService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String createPipeUseRegistrationReport(PipeUseRegistrationReportSaveReqVO createReqVO) {
|
|
|
+
|
|
|
+ // 插入
|
|
|
+ PipeUseRegistrationReportDO pipeUseRegistrationReport = BeanUtils.toBean(createReqVO, PipeUseRegistrationReportDO.class);
|
|
|
+ pipeUseRegistrationReportMapper.insert(pipeUseRegistrationReport);
|
|
|
+ // 返回
|
|
|
+ return pipeUseRegistrationReport.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updatePipeUseRegistrationReport(PipeUseRegistrationReportSaveReqVO updateReqVO) {
|
|
|
+ // 校验存在
|
|
|
+ validatePipeUseRegistrationReportExists(updateReqVO.getId());
|
|
|
+ // 更新
|
|
|
+ PipeUseRegistrationReportDO updateObj = BeanUtils.toBean(updateReqVO, PipeUseRegistrationReportDO.class);
|
|
|
+ pipeUseRegistrationReportMapper.updateById(updateObj);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deletePipeUseRegistrationReport(String id) {
|
|
|
+ // 校验存在
|
|
|
+ validatePipeUseRegistrationReportExists(id);
|
|
|
+ // 删除
|
|
|
+ pipeUseRegistrationReportMapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void validatePipeUseRegistrationReportExists(String id) {
|
|
|
+ if (pipeUseRegistrationReportMapper.selectById(id) == null) {
|
|
|
+ throw exception(PIPE_USE_REGISTRATION_REPORT_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PipeUseRegistrationReportDO getPipeUseRegistrationReport(String id) {
|
|
|
+ return pipeUseRegistrationReportMapper.selectById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<PipeUseRegistrationReportRespVO> getPipeUseRegistrationReportPage(PipeUseRegistrationReportPageReqVO pageReqVO) {
|
|
|
+
|
|
|
+ PageResult<PipeUseRegistrationReportDO> pageResult = pipeUseRegistrationReportMapper.selectPage(pageReqVO);
|
|
|
+ PageResult<PipeUseRegistrationReportRespVO> result = BeanUtils.toBean(pageResult, PipeUseRegistrationReportRespVO.class);
|
|
|
+
|
|
|
+ List<String> deptIds = result.getList().stream().map(PipeUseRegistrationReportRespVO::getDeptId)
|
|
|
+ .filter(Objects::nonNull).toList();
|
|
|
+ List<DeptRespDTO> deptRespDTOS = new ArrayList<>();
|
|
|
+ if (!deptIds.isEmpty()){
|
|
|
+ deptRespDTOS = deptApi.getDeptList(deptIds).getCheckedData();
|
|
|
+ }
|
|
|
+ List<DeptRespDTO> finalDepts = deptRespDTOS;
|
|
|
+ result.getList().forEach(item -> {
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(finalDepts)) {
|
|
|
+ List<DeptRespDTO> list = finalDepts.stream().filter(dept -> dept.getId().equals(item.getDeptId())).toList();
|
|
|
+ if (CollUtil.isNotEmpty(list)) {
|
|
|
+ item.setDeptName(list.get(0).getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void generatePipeUseRegistrationReport(String orderId) {
|
|
|
+
|
|
|
+ String templateId = TemplateIdConstants.G_D_S_Y_D_J_B;
|
|
|
+ PipeTaskOrderDO taskOrderDO = pipeTaskOrderMapper.selectById(orderId);
|
|
|
+ if (taskOrderDO == null){
|
|
|
+ throw exception(new ErrorCode(500, "管道任务单不存在"));
|
|
|
+ }
|
|
|
+ List<PipeTaskOrderItemDO> taskOrderItemDOList = pipeTaskOrderItemMapper.selectList(PipeTaskOrderItemDO::getOrderId, orderId);
|
|
|
+ if (taskOrderItemDOList.isEmpty()){
|
|
|
+ throw exception(new ErrorCode(500, "管道检验设备不存在"));
|
|
|
+ }
|
|
|
+ DynamicTbDO dynamicTbDO = dynamicTbMapper.selectById(templateId);
|
|
|
+ if (dynamicTbDO == null){
|
|
|
+ throw exception(new ErrorCode(500, "管道使用登记表模板不存在"));
|
|
|
+ }
|
|
|
+
|
|
|
+ taskOrderItemDOList.forEach(taskOrderItemDO -> {
|
|
|
+
|
|
|
+ EquipPipeDO equipPipeDO = equipPipeMapper.selectById(taskOrderItemDO.getEquipId());
|
|
|
+ if (equipPipeDO != null){
|
|
|
+
|
|
|
+ //清除掉旧的使用登记表
|
|
|
+ List<PipeUseRegistrationReportDO> oldList = pipeUseRegistrationReportMapper.selectList(new LambdaQueryWrapperX<PipeUseRegistrationReportDO>()
|
|
|
+ .eq(PipeUseRegistrationReportDO::getProjectNo, equipPipeDO.getProjectNo()));
|
|
|
+ pipeUseRegistrationReportMapper.deleteByIds(oldList);
|
|
|
+
|
|
|
+ PipeUseRegistrationReportDO useReportDO = new PipeUseRegistrationReportDO();
|
|
|
+ useReportDO.setTaskOrderId(orderId);
|
|
|
+ useReportDO.setTemplateId(dynamicTbDO.getId());
|
|
|
+ useReportDO.setReportName(dynamicTbDO.getTbName());
|
|
|
+
|
|
|
+ useReportDO.setProjectNo(equipPipeDO.getProjectNo());
|
|
|
+ useReportDO.setUnitName(equipPipeDO.getUnitName());
|
|
|
+ useReportDO.setCertificateNo(equipPipeDO.getCertificateNo());
|
|
|
+
|
|
|
+ useReportDO.setReportNo(taskOrderItemDO.getReportNo());
|
|
|
+ useReportDO.setDeptId(taskOrderDO.getDeptId());
|
|
|
+
|
|
|
+ pipeUseRegistrationReportMapper.insert(useReportDO);
|
|
|
+
|
|
|
+ //生成报表
|
|
|
+ CreateInstantiateWithRuleVO ruleVO = new CreateInstantiateWithRuleVO();
|
|
|
+ ruleVO.setTemplateId(dynamicTbDO.getId());
|
|
|
+ ruleVO.setRefId(useReportDO.getId());
|
|
|
+ ruleVO.setReportType(1);
|
|
|
+ com.alibaba.fastjson2.JSONObject params = new com.alibaba.fastjson2.JSONObject();
|
|
|
+ params.put("equipMainType","pipe");
|
|
|
+ ruleVO.setParams(params);
|
|
|
+ //获取tbCode的服务方法名
|
|
|
+ BoilerConnectTbServiceDO tbServiceDO = boilerConnectTbServiceMapper.selectOne(BoilerConnectTbServiceDO::getTbId,dynamicTbDO.getId());
|
|
|
+ if (tbServiceDO != null){
|
|
|
+ ruleVO.setServiceName(tbServiceDO.getInitServiceName());
|
|
|
+ dynamicTbInsService.createInstantiateWithRule(ruleVO);
|
|
|
+ }else{
|
|
|
+ ruleVO.setServiceName("");
|
|
|
+ dynamicTbInsService.createInstantiateWithRule(ruleVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void auditPipeUseRegistrationReport(PipeUseRegistrationReportAuditReqVO auditReqVO) {
|
|
|
+
|
|
|
+ PipeUseRegistrationReportDO useReportDO = pipeUseRegistrationReportMapper.selectById(auditReqVO.getId());
|
|
|
+ if (useReportDO == null){
|
|
|
+ throw exception(new ErrorCode(500, "管道使用登记表记录不存在"));
|
|
|
+ }
|
|
|
+
|
|
|
+ String userId = getLoginUserId();
|
|
|
+ AdminUserRespDTO userRespDTO = adminUserApi.getUser(userId).getCheckedData();
|
|
|
+
|
|
|
+ useReportDO.setStatus(100);
|
|
|
+ useReportDO.setSubmitId(userId);
|
|
|
+ if (userRespDTO != null){
|
|
|
+ useReportDO.setSubmitName(userRespDTO.getNickname());
|
|
|
+ }
|
|
|
+ useReportDO.setSubmitTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ pipeUseRegistrationReportMapper.updateById(useReportDO);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void approvePipeUseRegistrationReport(PipeUseRegistrationReportAuditReqVO auditReqVO) {
|
|
|
+
|
|
|
+ String userId = getLoginUserId();
|
|
|
+
|
|
|
+ PipeUseRegistrationReportDO useReportDO = pipeUseRegistrationReportMapper.selectById(auditReqVO.getId());
|
|
|
+ if (useReportDO == null){
|
|
|
+ throw exception(new ErrorCode(500, "管道使用登记表记录不存在"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!securityFrameworkService.hasRole("registrationAuditor")) {
|
|
|
+ throw exception(new ErrorCode(403, "仅登记表审核人角色可以审核"));
|
|
|
+ }
|
|
|
+
|
|
|
+ AdminUserRespDTO userRespDTO = adminUserApi.getUser(userId).getCheckedData();
|
|
|
+
|
|
|
+ useReportDO.setStatus(auditReqVO.getStatus());
|
|
|
+ useReportDO.setApprovalId(userId);
|
|
|
+ if (userRespDTO != null){
|
|
|
+ useReportDO.setApprovalName(userRespDTO.getNickname());
|
|
|
+ }
|
|
|
+ useReportDO.setApprovalTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ pipeUseRegistrationReportMapper.updateById(useReportDO);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|