| | |
| | | package org.jeecg.modules.eam.service.impl; |
| | | |
| | | import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationOrder; |
| | | import org.jeecg.modules.eam.mapper.EamTechnicalStatusEvaluationOrderMapper; |
| | | import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationOrderService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.flowable.engine.TaskService; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.constant.DataBaseConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.constant.BusinessCodeConst; |
| | | import org.jeecg.modules.eam.constant.HfTemplateCategoryEnum; |
| | | import org.jeecg.modules.eam.constant.OrderCreationMethodEnum; |
| | | import org.jeecg.modules.eam.constant.TechnicalStatusEvaluationOrderStatusEnum; |
| | | import org.jeecg.modules.eam.entity.EamBaseHFCode; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationOrder; |
| | | import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationStandard; |
| | | import org.jeecg.modules.eam.mapper.EamTechnicalStatusEvaluationOrderMapper; |
| | | import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationOrderQuery; |
| | | import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationOrderRequest; |
| | | import org.jeecg.modules.eam.service.*; |
| | | import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; |
| | | import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService; |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI; |
| | | import org.jeecg.modules.flowable.apithird.service.FlowCommonService; |
| | | import org.jeecg.modules.flowable.service.IFlowDefinitionService; |
| | | import org.jeecg.modules.flowable.service.IFlowTaskService; |
| | | import org.jeecg.modules.system.entity.BaseFactory; |
| | | import org.jeecg.modules.system.entity.BaseFactoryUser; |
| | | import org.jeecg.modules.system.service.IBaseFactoryService; |
| | | import org.jeecg.modules.system.service.IBaseFactoryUserService; |
| | | import org.jeecg.modules.system.service.ISysBusinessCodeRuleService; |
| | | import org.jeecg.modules.system.service.ISysUserService; |
| | | import org.jeecg.modules.system.vo.UserSelector; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: 技术状态鉴定工单 |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-07-09 |
| | | * @Date: 2025-07-09 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service |
| | | public class EamTechnicalStatusEvaluationOrderServiceImpl extends ServiceImpl<EamTechnicalStatusEvaluationOrderMapper, EamTechnicalStatusEvaluationOrder> implements IEamTechnicalStatusEvaluationOrderService { |
| | | @Service("IEamTechnicalStatusEvaluationOrderService") |
| | | public class EamTechnicalStatusEvaluationOrderServiceImpl extends ServiceImpl<EamTechnicalStatusEvaluationOrderMapper, EamTechnicalStatusEvaluationOrder> implements IEamTechnicalStatusEvaluationOrderService, FlowCallBackServiceI { |
| | | |
| | | @Autowired |
| | | private IBaseFactoryUserService baseFactoryUserService; |
| | | @Autowired |
| | | private IBaseFactoryService baseFactoryService; |
| | | @Autowired |
| | | private IEamTechnicalStatusEvaluationOrderDetailService orderDetailService; |
| | | @Autowired |
| | | private IEamEquipmentService equipmentService; |
| | | @Autowired |
| | | private ISysBusinessCodeRuleService businessCodeRuleService; |
| | | @Autowired |
| | | private IEamTechnicalStatusEvaluationStandardService standardService; |
| | | @Autowired |
| | | private IEamBaseHFCodeService hfCodeService; |
| | | @Autowired |
| | | private FlowCommonService flowCommonService; |
| | | @Autowired |
| | | private IFlowDefinitionService flowDefinitionService; |
| | | @Autowired |
| | | private IFlowMyBusinessService flowMyBusinessService; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private IFlowTaskService flowTaskService; |
| | | |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | @Autowired |
| | | private IEamEquipmentExtendService equipmentExtendService; |
| | | |
| | | @Override |
| | | public IPage<EamTechnicalStatusEvaluationOrder> queryPageList(Page<EamTechnicalStatusEvaluationOrder> page, EamTechnicalStatusEvaluationOrderQuery query) { |
| | | QueryWrapper<EamTechnicalStatusEvaluationOrder> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("ems.del_flag", CommonConstant.DEL_FLAG_0); |
| | | //用户数据权限 |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (sysUser == null) { |
| | | return page; |
| | | } |
| | | if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) { |
| | | //选择了设备,根据设备id过滤设备 |
| | | List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(",")); |
| | | queryWrapper.in("e.equipment_code", equipArr); |
| | | } else { |
| | | //没有选择设备,根据中心过滤设备 |
| | | List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService. |
| | | list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId())); |
| | | if (!CollectionUtils.isEmpty(baseFactoryUserList)) { |
| | | Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet()); |
| | | Set<String> factoryCodeList = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet()); |
| | | queryWrapper.in("e.factory_org_code", factoryCodeList); |
| | | } else { |
| | | return page; |
| | | } |
| | | } |
| | | if (query != null) { |
| | | //编码 模糊查询 |
| | | if (StringUtils.isNotBlank(query.getOrderNum())) { |
| | | queryWrapper.like("ems.order_num", query.getOrderNum()); |
| | | } |
| | | //设备 |
| | | if (StringUtils.isNotBlank(query.getEquipmentId())) { |
| | | queryWrapper.eq("ems.equipment_id", query.getEquipmentId()); |
| | | } |
| | | |
| | | //保养分类 |
| | | if (StringUtils.isNotBlank(query.getEvaluationStatus())) { |
| | | queryWrapper.eq("ems.evaluation_status", query.getEvaluationStatus()); |
| | | } |
| | | if (query.getDateBegin() != null && query.getDateEnd() != null) { |
| | | queryWrapper.between("ems.evaluation_date", query.getDateBegin(), query.getDateEnd()); |
| | | } |
| | | //排序 |
| | | if (StringUtils.isNotBlank(query.getColumn()) && StringUtils.isNotBlank(query.getOrder())) { |
| | | String column = query.getColumn(); |
| | | if (column.endsWith(CommonConstant.DICT_TEXT_SUFFIX)) { |
| | | column = column.substring(0, column.lastIndexOf(CommonConstant.DICT_TEXT_SUFFIX)); |
| | | } |
| | | if (DataBaseConstant.SQL_ASC.equalsIgnoreCase(query.getOrder())) { |
| | | queryWrapper.orderByAsc("ems." + oConvertUtils.camelToUnderline(column)); |
| | | } else { |
| | | queryWrapper.orderByDesc("ems." + oConvertUtils.camelToUnderline(column)); |
| | | } |
| | | } else { |
| | | queryWrapper.orderByDesc("ems.create_time"); |
| | | } |
| | | } else { |
| | | queryWrapper.orderByDesc("ems.create_time"); |
| | | } |
| | | queryWrapper.orderByDesc("ems.create_time"); |
| | | return this.getBaseMapper().queryPageList(page, queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean addTechnicalStatusEvaluationOrder(EamTechnicalStatusEvaluationOrderRequest request) { |
| | | EamEquipment equipment = equipmentService.getById(request.getEquipmentId()); |
| | | if (equipment == null) { |
| | | throw new JeecgBootException("设备不存在,添加失败!"); |
| | | } |
| | | EamTechnicalStatusEvaluationStandard standard = standardService.getById(request.getStandardId()); |
| | | if(standard == null) { |
| | | throw new JeecgBootException("技术状态鉴定规范不存在,添加失败!"); |
| | | } |
| | | EamTechnicalStatusEvaluationOrder order = new EamTechnicalStatusEvaluationOrder(); |
| | | order.setOrderNum(request.getOrderNum()); |
| | | order.setEquipmentId(request.getEquipmentId()); |
| | | order.setStandardId(request.getStandardId()); |
| | | order.setEvaluationDate(request.getEvaluationDate()); |
| | | order.setRemark(request.getRemark()); |
| | | String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_ORDER_CODE_RULE); |
| | | request.setOrderNum(codeSeq); |
| | | request.setCreationMethod(OrderCreationMethodEnum.MANUAL.name()); |
| | | //状态初始化 |
| | | order.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.WAIT_EVALUATION.name()); |
| | | order.setCreationMethod(request.getCreationMethod()); |
| | | //删除标记 |
| | | order.setDelFlag(CommonConstant.DEL_FLAG_0); |
| | | //技术状态鉴定表 |
| | | EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_EVALUATION.name()); |
| | | if(eamBaseHFCode == null) { |
| | | throw new JeecgBootException("未配置技术状态鉴定表的HF编码,添加失败!"); |
| | | } |
| | | order.setHfCodeA(eamBaseHFCode.getHfCode()); |
| | | //技术状态鉴定安全装置检查表 |
| | | eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_EVALUATION_SAFETY_CHECK.name()); |
| | | if(eamBaseHFCode == null) { |
| | | throw new JeecgBootException("未配置安全装置检查表的HF编码,添加失败!"); |
| | | } |
| | | order.setHfCodeB(eamBaseHFCode.getHfCode()); |
| | | //技术状态鉴定其他检查表 |
| | | eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_EVALUATION_OTHER_CHECK.name()); |
| | | if(eamBaseHFCode == null) { |
| | | throw new JeecgBootException("未配置其他检查表的HF编码,添加失败!"); |
| | | } |
| | | order.setHfCodeD(eamBaseHFCode.getHfCode()); |
| | | //技术状态鉴定设备精度检查表 |
| | | eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_EVALUATION_PRECISION_CHECK.name()); |
| | | if(eamBaseHFCode == null) { |
| | | throw new JeecgBootException("未配置设备精度检查表的HF编码,添加失败!"); |
| | | } |
| | | order.setHfCodeC(eamBaseHFCode.getHfCode()); |
| | | this.getBaseMapper().insert(order); |
| | | //处理明细数据 |
| | | if (CollectionUtil.isNotEmpty(request.getTableDetailList())) { |
| | | request.getTableDetailList().forEach(tableDetail -> { |
| | | tableDetail.setId(null); |
| | | tableDetail.setOrderId(order.getId()); |
| | | }); |
| | | orderDetailService.saveBatch(request.getTableDetailList()); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean collect(String id) { |
| | | EamTechnicalStatusEvaluationOrder entity = super.getBaseMapper().selectById(id); |
| | | if (entity == null) { |
| | | throw new JeecgBootException("要领取的工单不存在,请刷新重试!"); |
| | | } |
| | | if (!TechnicalStatusEvaluationOrderStatusEnum.WAIT_EVALUATION.name().equals(entity.getEvaluationStatus())) { |
| | | throw new JeecgBootException("该工单已进行过领取!"); |
| | | } |
| | | EamTechnicalStatusEvaluationStandard standard = standardService.getById(entity.getStandardId()); |
| | | if(standard == null) { |
| | | throw new JeecgBootException("设备保养标准不存在,请检查!"); |
| | | } |
| | | EamEquipment equipment = equipmentService.getById(entity.getEquipmentId()); |
| | | if (equipment == null) { |
| | | throw new JeecgBootException("设备不存在,添加失败!"); |
| | | } |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if(sysUser == null) { |
| | | throw new JeecgBootException("不是维修工,无法领取此工单!"); |
| | | } |
| | | List<UserSelector> userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0002); |
| | | if (CollectionUtil.isEmpty(userSelectors)) { |
| | | throw new JeecgBootException("设备未分配给维修工,无法领取!"); |
| | | } |
| | | List<String> userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); |
| | | entity.setEvaluator(sysUser.getUsername()); |
| | | entity.setEvaluationStatus(TechnicalStatusEvaluationOrderStatusEnum.UNDER_EVALUATION.name()); |
| | | entity.setActualStartTime(new Date()); |
| | | this.getBaseMapper().updateById(entity); |
| | | |
| | | //启动流程 |
| | | flowCommonService.initActBusiness("工单号: " + entity.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode() + ";安装位置" + equipment.getInstallationPosition(), |
| | | entity.getId(), "IEamTechnicalStatusEvaluationOrderService", "technical_status_evaluation_process", null); |
| | | Map<String, Object> variables = new HashMap<>(); |
| | | variables.put("dataId", entity.getId()); |
| | | if (StrUtil.isEmpty(entity.getRemark())) { |
| | | variables.put("organization", "技术状态鉴定工单默认启动流程"); |
| | | variables.put("comment", "技术状态鉴定工单默认启动流程"); |
| | | } else { |
| | | variables.put("organization", entity.getRemark()); |
| | | variables.put("comment", entity.getRemark()); |
| | | } |
| | | variables.put("proofreading", true); |
| | | if(CommonConstant.STATUS_1.equals(standard.getHasSafetyEquipmentCheck())) { |
| | | variables.put("hasSafetyEquipmentCheck", CommonConstant.STATUS_1); |
| | | variables.put("safety_equipment_check", userApprovalList); |
| | | entity.setSafetyCheckCompleted(CommonConstant.STATUS_0); |
| | | } else { |
| | | variables.put("hasSafetyEquipmentCheck", CommonConstant.STATUS_0); |
| | | variables.put("safety_equipment_check", userApprovalList); |
| | | } |
| | | if(CommonConstant.STATUS_1.equals(standard.getHasPrecisionCheck())) { |
| | | variables.put("hasPrecisionCheck", CommonConstant.STATUS_1); |
| | | variables.put("equipment_precision_check", userApprovalList); |
| | | entity.setPrecisionCheckCompleted(CommonConstant.STATUS_0); |
| | | } else { |
| | | variables.put("hasPrecisionCheck", CommonConstant.STATUS_0); |
| | | variables.put("equipment_precision_check", userApprovalList); |
| | | } |
| | | if(CommonConstant.STATUS_1.equals(standard.getHasOtherCheck())) { |
| | | variables.put("hasOtherCheck", CommonConstant.STATUS_1); |
| | | variables.put("other_check", userApprovalList); |
| | | entity.setOtherCheckCompleted(CommonConstant.STATUS_0); |
| | | } else { |
| | | variables.put("hasOtherCheck ", CommonConstant.STATUS_0); |
| | | variables.put("other_check", userApprovalList); |
| | | } |
| | | Result<?> result = flowDefinitionService.startProcessInstanceByKey("technical_status_evaluation_process", variables); |
| | | if(result == null || !result.isSuccess()) { |
| | | throw new JeecgBootException("启动流程失败,领取失败"); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public void afterFlowHandle(FlowMyBusiness business) { |
| | | business.getTaskNameId();//接下来审批的节点 |
| | | business.getValues();//前端传进来的参数 |
| | | business.getActStatus(); |
| | | } |
| | | |
| | | @Override |
| | | public Object getBusinessDataById(String dataId) { |
| | | return this.getById(dataId); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> flowValuesOfTask(String taskNameId, Map<String, Object> values) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) { |
| | | //业务是否干预流程,业务干预,流程干预,指定人员进行处理 |
| | | //获取下一步处理人 |
| | | Object object = values.get("NextAssignee"); |
| | | return (List<String>) object; |
| | | } |
| | | } |