From 7d2ae4c2fd8d45f0896b9accf84ff4177638fbcd Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期四, 17 七月 2025 20:38:01 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusDeactivateServiceImpl.java | 383 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 380 insertions(+), 3 deletions(-) diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusDeactivateServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusDeactivateServiceImpl.java index 0aabdba..4a50a08 100644 --- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusDeactivateServiceImpl.java +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusDeactivateServiceImpl.java @@ -1,11 +1,55 @@ package org.jeecg.modules.eam.service.impl; +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.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.TranslateDictTextUtils; +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.TechnicalStatusDeactivateStatusEnum; +import org.jeecg.modules.eam.constant.TechnicalStatusEvaluationOrderChangeStatusEnum; +import org.jeecg.modules.eam.entity.EamBaseHFCode; +import org.jeecg.modules.eam.entity.EamEquipment; import org.jeecg.modules.eam.entity.EamTechnicalStatusDeactivate; import org.jeecg.modules.eam.mapper.EamTechnicalStatusDeactivateMapper; +import org.jeecg.modules.eam.request.EamTechnicalStatusDeactivateQuery; +import org.jeecg.modules.eam.request.EamTechnicalStatusDeactivateRequest; +import org.jeecg.modules.eam.service.IEamBaseHFCodeService; +import org.jeecg.modules.eam.service.IEamEquipmentService; +import org.jeecg.modules.eam.service.IEamTechnicalStatusDeactivateDetailService; import org.jeecg.modules.eam.service.IEamTechnicalStatusDeactivateService; +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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.util.*; +import java.util.stream.Collectors; /** * @Description: 鍋滅敤鍔犲伐璁惧鐢宠鍗� @@ -13,7 +57,340 @@ * @Date: 2025-07-09 * @Version: V1.0 */ -@Service -public class EamTechnicalStatusDeactivateServiceImpl extends ServiceImpl<EamTechnicalStatusDeactivateMapper, EamTechnicalStatusDeactivate> implements IEamTechnicalStatusDeactivateService { +@Service("IEamTechnicalStatusDeactivateService") +public class EamTechnicalStatusDeactivateServiceImpl extends ServiceImpl<EamTechnicalStatusDeactivateMapper, EamTechnicalStatusDeactivate> implements IEamTechnicalStatusDeactivateService, FlowCallBackServiceI { + @Autowired + private IBaseFactoryUserService baseFactoryUserService; + @Autowired + private IBaseFactoryService baseFactoryService; + @Autowired + private ISysBusinessCodeRuleService businessCodeRuleService; + @Autowired + private IEamBaseHFCodeService hfCodeService; + @Autowired + private IEamTechnicalStatusDeactivateDetailService deactivateDetailService; + @Autowired + private IEamEquipmentService equipmentService; + @Autowired + private ISysUserService sysUserService; + @Autowired + private FlowCommonService flowCommonService; + @Autowired + private IFlowDefinitionService flowDefinitionService; + @Autowired + private IFlowMyBusinessService flowMyBusinessService; + @Autowired + private IFlowTaskService flowTaskService; + @Autowired + private TranslateDictTextUtils translateDictTextUtils; + @Override + public IPage<EamTechnicalStatusDeactivate> queryPageList(Page<EamTechnicalStatusDeactivate> page, EamTechnicalStatusDeactivateQuery query) { + QueryWrapper<EamTechnicalStatusDeactivate> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_0); + //鐢ㄦ埛鏁版嵁鏉冮檺 + LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + if (sysUser == null) { + return page; + } + //鏍规嵁涓績杩囨护鏁版嵁鏉冮檺 + 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("factory_org_code", factoryCodeList); + } else { + return page; + } + if (query != null) { + //缂栫爜 妯$硦鏌ヨ + if (StringUtils.isNotBlank(query.getDeactivateOrderNum())) { + queryWrapper.like("deactivate_order_num", query.getDeactivateOrderNum()); + } + //淇濆吇鍒嗙被 + if (StringUtils.isNotBlank(query.getApplicationStatus())) { + queryWrapper.eq("application_status", query.getApplicationStatus()); + } + if (query.getDateBegin() != null && query.getDateEnd() != null) { + queryWrapper.between("apply_date", query.getDateBegin(), query.getDateEnd()); + } + //鐢宠鍗曚綅 + if (StringUtils.isNotBlank(query.getFactoryOrgCode())) { + queryWrapper.eq("factory_org_code", query.getFactoryOrgCode()); + } + //鎺掑簭 + 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(oConvertUtils.camelToUnderline(column)); + } else { + queryWrapper.orderByDesc(oConvertUtils.camelToUnderline(column)); + } + } else { + queryWrapper.orderByDesc("create_time"); + } + } else { + queryWrapper.orderByDesc("create_time"); + } + return this.getBaseMapper().selectPage(page, queryWrapper); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean addTechnicalStatusDeactivate(EamTechnicalStatusDeactivateRequest request) { + //鐢ㄦ埛鏁版嵁鏉冮檺 + LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + if (sysUser == null) { + throw new JeecgBootException("鑾峰彇鐧诲綍鐢ㄦ埛淇℃伅澶辫触锛�"); + } + EamTechnicalStatusDeactivate order = new EamTechnicalStatusDeactivate(); + order.setApplicant(sysUser.getUsername()); + order.setApplyDate(new Date()); + order.setRemark(request.getRemark()); + order.setApplicationStatus(TechnicalStatusDeactivateStatusEnum.WAIT_SUBMIT.name()); + order.setFactoryOrgCode(request.getFactoryOrgCode()); + String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_DEACTIVATE_CODE_RULE); + order.setDeactivateOrderNum(codeSeq); + //鍒犻櫎鏍囪 + order.setDelFlag(CommonConstant.DEL_FLAG_0); + //鍋滅敤鍔犲伐璁惧鐢宠鍗� + EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_DEACTIVATE.name()); + if (eamBaseHFCode == null) { + throw new JeecgBootException("鏈厤缃仠鐢ㄥ姞宸ヨ澶囩敵璇峰崟鐨凥F缂栫爜锛屾坊鍔犲け璐ワ紒"); + } + order.setHfCode(eamBaseHFCode.getHfCode()); + this.getBaseMapper().insert(order); + //澶勭悊鏄庣粏鏁版嵁 + request.getTableDetailList().forEach(detail -> { + EamEquipment equipment = equipmentService.getById(detail.getEquipmentId()); + if (equipment == null) { + throw new JeecgBootException("璁惧[" + detail.getEquipmentCode() + "]涓嶅瓨鍦紒"); + } + detail.setId(null); + detail.setCreateBy(null); + detail.setCreateTime(null); + detail.setUpdateBy(null); + detail.setUpdateTime(null); + }); + deactivateDetailService.saveBatch(request.getTableDetailList()); + return true; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean editTechnicalStatusDeactivate(EamTechnicalStatusDeactivateRequest request) { + EamTechnicalStatusDeactivate entity = this.getBaseMapper().selectById(request.getId()); + if(entity == null) { + throw new JeecgBootException("瑕佺紪杈戠殑鏁版嵁涓嶅瓨鍦紒"); + } + if(!TechnicalStatusDeactivateStatusEnum.WAIT_SUBMIT.name().equals(entity.getApplicationStatus())) { + throw new JeecgBootException("鍙湁寰呮彁浜ょ殑鐘舵�佹墠鏀寔缂栬緫锛�"); + } + //鐢ㄦ埛鏁版嵁鏉冮檺 + LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + if (sysUser == null) { + throw new JeecgBootException("鑾峰彇鐧诲綍鐢ㄦ埛淇℃伅澶辫触锛�"); + } + entity.setRemark(request.getRemark()); + entity.setFactoryOrgCode(request.getFactoryOrgCode()); + this.getBaseMapper().updateById(entity); + //鍒犻櫎鍘熸潵鐨勮澶囨槑缁� + deactivateDetailService.removeByChangeId(entity.getId()); + //澶勭悊鏄庣粏鏁版嵁 + request.getTableDetailList().forEach(detail -> { + EamEquipment equipment = equipmentService.getById(detail.getEquipmentId()); + if (equipment == null) { + throw new JeecgBootException("璁惧[" + detail.getEquipmentCode() + "]涓嶅瓨鍦紒"); + } + detail.setId(null); + detail.setCreateBy(null); + detail.setCreateTime(null); + detail.setUpdateBy(null); + detail.setUpdateTime(null); + }); + deactivateDetailService.saveBatch(request.getTableDetailList()); + return true; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean submit(String id) { + EamTechnicalStatusDeactivate entity = this.getBaseMapper().selectById(id); + if (entity == null) { + throw new JeecgBootException("瑕佹彁浜ょ殑宸ュ崟涓嶅瓨鍦紝璇峰埛鏂伴噸璇曪紒"); + } + if (!TechnicalStatusDeactivateStatusEnum.WAIT_SUBMIT.name().equals(entity.getApplicationStatus())) { + throw new JeecgBootException("璇ュ伐鍗曞凡杩涜杩囨彁浜わ紒"); + } + LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + if(sysUser == null || !sysUser.getUsername().equals(entity.getApplicant())) { + throw new JeecgBootException("涓嶆槸鏈汉锛屼笉鑳芥彁浜ゆ宸ュ崟锛�"); + } + entity.setApplicationStatus(TechnicalStatusDeactivateStatusEnum.DEPART_HEADER_SIGNING.name()); + //鏌ヨ涓嬬骇瀹℃壒浜哄憳 + List<UserSelector> userSelectors = sysUserService.selectOperatorList(null, entity.getFactoryOrgCode(), BusinessCodeConst.PCR0011); + if (CollectionUtil.isEmpty(userSelectors)) { + throw new JeecgBootException("璁惧鏈垎閰嶇粰浣跨敤鍗曚綅涓荤瀹ょ骇棰嗗锛屾棤娉曟彁浜わ紒"); + } + List<String> userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); + //鏇存柊瀹炰綋 + this.getBaseMapper().updateById(entity); + //浣跨敤鍗曚綅缈昏瘧 + String factoryName = translateDictTextUtils.translateField("factory_org_code", entity.getFactoryOrgCode(), "eam_base_factory, factory_name, org_code"); + //鍚姩娴佺▼ + flowCommonService.initActBusiness("宸ュ崟鍙�: " + entity.getDeactivateOrderNum() + ";鐢宠鍗曚綅: " + factoryName, + entity.getId(), "IEamTechnicalStatusDeactivateService", "technical_status_deactivate_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); + variables.put("NextAssignee", userApprovalList); + Result<?> result = flowDefinitionService.startProcessInstanceByKey("technical_status_deactivate_process", variables); + if(result == null || !result.isSuccess()) { + throw new JeecgBootException("鍚姩娴佺▼澶辫触锛�"); + } + return true; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public EamTechnicalStatusDeactivate approval(EamTechnicalStatusDeactivateRequest request) { + EamTechnicalStatusDeactivate entity = this.getBaseMapper().selectById(request.getId()); + if (entity == null) { + throw new JeecgBootException("瀹℃壒鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�"); + } + // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛 + LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + if (user == null || StrUtil.isBlank(user.getId())) { + throw new JeecgBootException("鏈幏鍙栧埌鐧诲綍鐢ㄦ埛锛岃閲嶆柊鐧诲綍鍚庡啀璇曪紒"); + } + request.setAssignee(user.getUsername()); + // 鑾峰彇娴佺▼涓氬姟璁板綍 + FlowMyBusiness flowMyBusiness = flowMyBusinessService.getFlowMyBusiness(request.getInstanceId(), request.getTaskId()); + if (flowMyBusiness == null) { + throw new JeecgBootException("娴佺▼瀹炰緥涓嶅瓨鍦紝璇峰埛鏂板悗閲嶈瘯锛�"); + } + + boolean userAuthorized = flowMyBusinessService.isUserAuthorized(flowMyBusiness, user); + if (!userAuthorized) { + throw new JeecgBootException("鐢ㄦ埛鏃犳潈鎿嶄綔姝や换鍔★紝璇峰埛鏂板悗閲嶈瘯锛�"); + } + // 璁ら浠诲姟 + if (!flowMyBusinessService.claimTask(flowMyBusiness.getTaskId(), user)) { + throw new JeecgBootException("浠诲姟涓嶅瓨鍦ㄣ�佸凡瀹屾垚鎴栧凡琚粬浜鸿棰嗭紒"); + } + + TechnicalStatusDeactivateStatusEnum status = TechnicalStatusDeactivateStatusEnum.getInstance(entity.getApplicationStatus()); + if (status == null) { + return null; + } + //娴佺▼鍙橀噺 + Map<String, Object> values = new HashMap<>(); + List<String> userApprovalList; + List<UserSelector> userSelectors; + switch (status) { + case DEPART_HEADER_SIGNING: + userSelectors = sysUserService.selectOperatorList(null, entity.getFactoryOrgCode(), BusinessCodeConst.PCR0018); + if (CollectionUtil.isEmpty(userSelectors)) { + throw new JeecgBootException("璁惧鏈垎閰嶇粰浣跨敤鍗曚綅涓荤閮ㄧ骇棰嗗锛屾棤娉曡繘鍏ヤ笅绾у鎵癸紒"); + } + userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList()); + values.put("dataId", entity.getId()); + if(StringUtils.isBlank(request.getDepartHeaderComment())) { + values.put("organization", "鍋滅敤鍔犲伐璁惧鐢宠浣跨敤鍗曚綅涓荤瀹ょ骇棰嗗"); + values.put("comment", "鍋滅敤鍔犲伐璁惧鐢宠浣跨敤鍗曚綅涓荤瀹ょ骇棰嗗"); + request.setComment("鍋滅敤鍔犲伐璁惧鐢宠浣跨敤鍗曚綅涓荤瀹ょ骇棰嗗"); + } else { + values.put("organization", request.getDepartHeaderComment()); + values.put("comment", request.getDepartHeaderComment()); + request.setComment(request.getDepartHeaderComment()); + } + + //璁剧疆entity + entity.setDepartHeaderSignature(user.getUsername()); + entity.setDepartHeaderSignatureTime(new Date()); + entity.setDepartHeaderComment(request.getDepartHeaderComment()); + entity.setDepartHeaderSignatureResult(request.getDepartHeaderSignatureResult()); + values.put("departHeaderConfirmFlag", request.getDepartHeaderSignatureResult()); + if(BusinessCodeConst.APPROVED.equals(request.getDepartHeaderSignatureResult())) { + //閫氳繃 + entity.setApplicationStatus(TechnicalStatusDeactivateStatusEnum.DEPART_LEADER_SIGNING.name()); + values.put("NextAssignee", userApprovalList); + }else { + //椹冲洖 + entity.setApplicationStatus(TechnicalStatusDeactivateStatusEnum.REJECTED.name()); + } + break; + case DEPART_LEADER_SIGNING: + //閮ㄩ棬棰嗗瀹℃牳 + values.put("dataId", entity.getId()); + if(StringUtils.isBlank(request.getDepartLeaderComment())) { + values.put("organization", "鍋滅敤鍔犲伐璁惧鐢宠閮ㄧ骇棰嗗瀹℃牳"); + values.put("comment", "鍋滅敤鍔犲伐璁惧鐢宠閮ㄧ骇棰嗗瀹℃牳"); + request.setComment("鍋滅敤鍔犲伐璁惧鐢宠閮ㄧ骇棰嗗瀹℃牳"); + } else { + values.put("organization", request.getDepartLeaderComment()); + values.put("comment", request.getDepartLeaderComment()); + request.setComment(request.getDepartLeaderComment()); + } + //璁剧疆entity + entity.setDepartLeaderSignature(user.getUsername()); + entity.setDepartLeaderSignatureTime(new Date()); + entity.setDepartLeaderSignatureResult(request.getDepartLeaderSignatureResult()); + entity.setDepartLeaderComment(request.getDepartLeaderComment()); + if(BusinessCodeConst.APPROVED.equals(request.getDepartLeaderSignatureResult())) { + //閫氳繃 + entity.setApplicationStatus(TechnicalStatusEvaluationOrderChangeStatusEnum.COMPLETED.name()); + }else { + //椹冲洖 + entity.setApplicationStatus(TechnicalStatusEvaluationOrderChangeStatusEnum.REJECTED.name()); + } + break; + } + request.setValues(values); + + // 瀹屾垚娴佺▼浠诲姟 + Result<?> result = flowTaskService.complete(request); + if (!result.isSuccess()) { + throw new JeecgBootException("瀹℃壒澶辫触锛岃鍒锋柊鏌ョ湅锛�"); + } + //淇濆瓨宸ュ崟 + this.getBaseMapper().updateById(entity); + return entity; + } + + @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; + } } -- Gitblit v1.9.3