diff --git a/src/main/java/com/spring/modules/change/service/impl/ChangeManagementServiceImpl.java b/src/main/java/com/spring/modules/change/service/impl/ChangeManagementServiceImpl.java index e6827910..c4ea9430 100644 --- a/src/main/java/com/spring/modules/change/service/impl/ChangeManagementServiceImpl.java +++ b/src/main/java/com/spring/modules/change/service/impl/ChangeManagementServiceImpl.java @@ -1368,6 +1368,9 @@ public class ChangeManagementServiceImpl extends ServiceImpl baseData = getSubmitBaseData(data.getSite(), data.getUserName(), data.getChangeNo()); diff --git a/src/main/java/com/spring/modules/rohs/controller/RohsController.java b/src/main/java/com/spring/modules/rohs/controller/RohsController.java index ba4f966b..ee0ea50a 100644 --- a/src/main/java/com/spring/modules/rohs/controller/RohsController.java +++ b/src/main/java/com/spring/modules/rohs/controller/RohsController.java @@ -249,7 +249,9 @@ public class RohsController { return R.error("工厂(site)和序列号(referenceNo)不能为空"); } try { - rohsService.submit(data.getSite(), data.getReferenceNo(), data.getNodeConclusion(), data.getRejectOpinion()); + SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); + String userName = user == null ? null : user.getUsername(); + rohsService.submit(data, userName); } catch (RuntimeException e) { return R.error(e.getMessage()); } diff --git a/src/main/java/com/spring/modules/rohs/service/RohsService.java b/src/main/java/com/spring/modules/rohs/service/RohsService.java index ef93088c..d5659aa8 100644 --- a/src/main/java/com/spring/modules/rohs/service/RohsService.java +++ b/src/main/java/com/spring/modules/rohs/service/RohsService.java @@ -5,6 +5,7 @@ import com.spring.common.utils.PageUtils; import com.spring.modules.change.vo.ProcessFormVo; import com.spring.modules.rohs.entity.RohsEntity; import com.spring.modules.rohs.entity.RohsMaterialEntity; +import com.spring.modules.rohs.vo.RohsSubmitVo; import java.util.HashMap; import java.util.List; @@ -38,7 +39,7 @@ public interface RohsService extends IService { /** * 提交审批结论 */ - void submit(String site, String referenceNo, String nodeConclusion, String rejectOpinion); + void submit(RohsSubmitVo data, String userName); /** * 查询审批记录 diff --git a/src/main/java/com/spring/modules/rohs/service/impl/RohsServiceImpl.java b/src/main/java/com/spring/modules/rohs/service/impl/RohsServiceImpl.java index fc640757..ed2302c4 100644 --- a/src/main/java/com/spring/modules/rohs/service/impl/RohsServiceImpl.java +++ b/src/main/java/com/spring/modules/rohs/service/impl/RohsServiceImpl.java @@ -7,8 +7,12 @@ import com.spring.common.utils.Constant; import com.spring.common.utils.DateUtils; import com.spring.common.utils.PageUtils; import com.spring.common.utils.Query; +import com.spring.modules.base.utils.HttpClientUtil; +import com.spring.modules.base.utils.ResponseData; import com.spring.modules.base.data.OaUserData; +import com.spring.modules.change.entity.APIEntity.DoForceDrawBackParam; import com.spring.modules.change.entity.APIEntity.MainData; +import com.spring.modules.change.entity.APIEntity.SubmitRequestParam; import com.spring.modules.change.entity.ParamData; import com.spring.modules.change.entity.ProcessFormEntity; import com.spring.modules.change.mapper.ChangeManagementMapper; @@ -20,10 +24,12 @@ import com.spring.modules.rohs.entity.RohsMaterialEntity; import com.spring.modules.rohs.mapper.RohsMapper; import com.spring.modules.rohs.service.RohsMaterialService; import com.spring.modules.rohs.service.RohsService; +import com.spring.modules.rohs.vo.RohsSubmitVo; import com.spring.modules.sys.dao.SysUserDao; import com.spring.modules.sys.entity.SysUserEntity; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -57,6 +63,9 @@ public class RohsServiceImpl extends ServiceImpl impleme @Value("${oa-control.control-flag}") private Boolean dataUrlOa; + @Value("${oa-api.api-url}") + private String apiUrlOa; + @Override public PageUtils queryPage(Map params) { params.put("referenceNo", toLikeParam((String) params.get("referenceNo"))); @@ -188,30 +197,119 @@ public class RohsServiceImpl extends ServiceImpl impleme } @Override - public void submit(String site, String referenceNo, String nodeConclusion, String rejectOpinion) { - RohsEntity rohs = this.getDetail(site, referenceNo); - if (rohs == null) { + @Transactional + public void submit(RohsSubmitVo data, String userName) { + if (data == null || StringUtils.isBlank(data.getSite()) || StringUtils.isBlank(data.getReferenceNo())) { + throw new RuntimeException("工厂(site)和序列号(referenceNo)不能为空"); + } + String site = data.getSite(); + String referenceNo = data.getReferenceNo(); + String nodeConclusion = data.getNodeConclusion(); + String rejectOpinion = data.getRejectOpinion(); + + RohsEntity current = this.getDetail(site, referenceNo); + if (current == null) { throw new RuntimeException("未找到对应RoHs单据"); } - if (!"审批中".equals(rohs.getStatus())) { + if (!"审批中".equals(current.getStatus())) { throw new RuntimeException("仅审批中状态的单据允许提交审批结论"); } + if (StringUtils.isBlank(userName)) { + throw new RuntimeException("提交人不能为空"); + } if (!"Y".equals(nodeConclusion) && !"N".equals(nodeConclusion)) { throw new RuntimeException("审批结论仅支持Y(同意)或N(驳回)"); } + + // 1) 先更新用户页面编辑的数据(参考工程变更submitChange) RohsEntity updateEntity = new RohsEntity(); - if ("Y".equals(nodeConclusion)) { - updateEntity.setStatus("已完成"); - } else { - updateEntity.setStatus("草稿"); - if (StringUtils.isNotBlank(rejectOpinion)) { - String oldRemark = rohs.getRemark(); - updateEntity.setRemark(StringUtils.isNotBlank(oldRemark) ? oldRemark + "\n" + rejectOpinion : rejectOpinion); + BeanUtils.copyProperties(data, updateEntity); + // 状态及流程字段交给流程逻辑处理,避免被前端脏数据覆盖 + updateEntity.setStatus(null); + updateEntity.setStepId(null); + updateEntity.setRejectFlag(null); + updateEntity.setRejectStepId(null); + updateEntity.setCreateDate(null); + updateEntity.setCreateBy(null); + updateEntity.setUpdateDate(new Date()); + updateEntity.setUpdateBy(userName); + // ifsPartNo 与材料保持一致 + if (data.getMaterialList() != null) { + if (data.getMaterialList().isEmpty()) { + updateEntity.setIfsPartNo(null); + } else { + updateEntity.setIfsPartNo(data.getMaterialList().get(0).getTestPartNo()); } } QueryWrapper updateWrapper = new QueryWrapper<>(); updateWrapper.eq("site", site).eq("reference_no", referenceNo); this.update(updateEntity, updateWrapper); + if (data.getMaterialList() != null) { + RohsEntity materialEntity = new RohsEntity(); + materialEntity.setSite(site); + materialEntity.setReferenceNo(referenceNo); + materialEntity.setProjectId(data.getProjectId()); + materialEntity.setMaterialList(data.getMaterialList()); + this.saveOrUpdateMaterials(materialEntity); + } + + // 关闭调用OA接口时,反刷单据状态为"已完成"(与工程变更提交一致) + if (!dataUrlOa) { + RohsEntity statusEntity = new RohsEntity(); + statusEntity.setStatus("已完成"); + statusEntity.setUpdateDate(new Date()); + statusEntity.setUpdateBy(userName); + QueryWrapper statusWrapper = new QueryWrapper<>(); + statusWrapper.eq("site", site).eq("reference_no", referenceNo); + this.update(statusEntity, statusWrapper); + return; + } + + // 重新读取最新数据用于组装OA主数据 + RohsEntity rohs = this.getDetail(site, referenceNo); + if (rohs == null) { + throw new RuntimeException("更新后未找到对应RoHs单据"); + } + // 获取审批基础数据 + Map baseData = changeManagementService.getSubmitBaseData(site, userName, referenceNo); + ParamData paramData = new ParamData(site, baseData.get("nodeId"), baseData.get("nodeName"), referenceNo, userName, baseData.get("classificationNo"), + baseData.get("userId"), baseData.get("workflowId"), baseData.get("workflowname"), baseData.get("requestName"), baseData.get("path"), baseData.get("requestId"), + "plm_rohs", "reference_no", "status", rohs.getStepId(), "", + baseData.get("domainControlAccount"), baseData.get("menuId"), baseData.get("menuName"), nodeConclusion, StringUtils.defaultString(rejectOpinion), baseData.get("nodeId")); + + if ("Y".equals(nodeConclusion)) { + List mainData = getSubmitMainData(site, baseData, rohs); + paramData.setMainData(mainData); + + SubmitRequestParam submitRequestParam = new SubmitRequestParam(); + submitRequestParam.setUserId(paramData.getUserId()); + submitRequestParam.setRequestId(paramData.getRequestId()); + submitRequestParam.setMainData(paramData.getMainData()); + String submitRequestURL = apiUrlOa + "/oa/interface/submitRequest"; + ResponseData submitRequestResponses = HttpClientUtil.doPostByRawWithOA(submitRequestURL, submitRequestParam); + if (!"0".equals(submitRequestResponses.getCode())) { + throw new RuntimeException("OA提交流程异常信息:" + submitRequestResponses.getMsg()); + } + try { + changeManagementService.agreeFunction(paramData, Constant.ROHS); + } catch (Exception e) { + handleSubmitRollback(paramData, e); + } + } else { + SubmitRequestParam submitRequestParam = new SubmitRequestParam(); + submitRequestParam.setUserId(paramData.getUserId()); + submitRequestParam.setRequestId(paramData.getRequestId()); + String submitRequestURL = apiUrlOa + "/oa/interface/rejectRequest"; + ResponseData submitRequestResponses = HttpClientUtil.doPostByRawWithOA(submitRequestURL, submitRequestParam); + if (!"0".equals(submitRequestResponses.getCode())) { + throw new RuntimeException("OA流程退回异常信息:" + submitRequestResponses.getMsg()); + } + try { + changeManagementService.rejectFunction(paramData, Constant.ROHS); + } catch (Exception e) { + handleSubmitRollback(paramData, e); + } + } } @Override @@ -345,6 +443,89 @@ public class RohsServiceImpl extends ServiceImpl impleme rohsMaterialService.remove(removeWrapper); } + private List getSubmitMainData(String site, Map baseData, RohsEntity rohs) { + List mainData = new ArrayList<>(); + List nodeDetails = changeManagementMapper.queryNodeDetails(site, baseData.get("workflowId"), baseData.get("nodeId"), baseData.get("classificationNo")); + if (nodeDetails == null || nodeDetails.isEmpty()) { + return mainData; + } + for (PlmRequestDetailVo nodeDetail : nodeDetails) { + if (nodeDetail.getId() == null) { + continue; + } + MainData md = new MainData(); + md.setFieldName(nodeDetail.getOaField()); + String fieldValue = ""; + if (StringUtils.isNotBlank(nodeDetail.getFieldValue())) { + md.setFieldValue(nodeDetail.getFieldValue()); + mainData.add(md); + continue; + } + if ("plm_rohs".equals(nodeDetail.getPlmTable())) { + Object valueObj = getPropertyValue(rohs, nodeDetail.getPlmField()); + fieldValue = convertFieldValue(valueObj); + if (StringUtils.isNotBlank(fieldValue) && "A".equals(nodeDetail.getFieldType())) { + fieldValue = convertUserFieldToOaIds(fieldValue); + } + } + + if (StringUtils.isNotBlank(fieldValue)) { + md.setFieldValue(fieldValue); + } else { + if ("Y".equals(nodeDetail.getReview())) { + String fieldName = changeManagementService.getFieldName(nodeDetail.getPlmTable(), nodeDetail.getPlmField()); + throw new RuntimeException("[" + fieldName + "] 参数在当前节点是必填项,无法下达/提交该流程!"); + } else if ("N".equals(nodeDetail.getReview()) && "A".equals(nodeDetail.getFieldType())) { + continue; + } else { + md.setFieldValue(""); + } + } + mainData.add(md); + } + return mainData; + } + + private String convertUserFieldToOaIds(String fieldValue) { + String[] users = fieldValue.replace(";", ",").split(","); + StringBuilder oaIdList = new StringBuilder(); + for (String userCode : users) { + String username = StringUtils.trim(userCode); + if (StringUtils.isBlank(username)) { + continue; + } + SysUserEntity sysUser = sysUserDao.selectOne(new QueryWrapper().eq("username", username)); + if (sysUser == null) { + throw new RuntimeException("未找到PLM用户信息,用户编码: " + username); + } + String account = sysUser.getDomainControlAccount(); + if (StringUtils.isBlank(account)) { + throw new RuntimeException("未获取到PLM人员域控账号,用户编码: " + username); + } + List oaIds = sysUserDao.selectOaIdByAccount(account); + if (oaIds == null || oaIds.isEmpty()) { + throw new RuntimeException("未获取到域控账号对应的OA人员,域控账号: " + account); + } + oaIdList.append(oaIds.get(0).getId()).append(","); + } + return oaIdList.length() > 0 ? oaIdList.substring(0, oaIdList.length() - 1) : ""; + } + + private void handleSubmitRollback(ParamData paramData, Exception e) { + DoForceDrawBackParam doForceDrawBackParam = new DoForceDrawBackParam(); + doForceDrawBackParam.setUserId(paramData.getUserId()); + doForceDrawBackParam.setRequestId(paramData.getRequestId()); + String doForceDrawBackURL = apiUrlOa + "/oa/interface/doForceDrawBack"; + ResponseData doForceDrawBackResponses = HttpClientUtil.doPostByRawWithOA(doForceDrawBackURL, doForceDrawBackParam); + if (!"0".equals(doForceDrawBackResponses.getCode())) { + if ("NO_PERMISSION".equals(doForceDrawBackResponses.getCode())) { + throw new RuntimeException("OA撤回流程异常信息:流程提交异常,无撤回权限,请联系管理员! 导致OA撤回的PLM异常:" + e.getMessage()); + } + throw new RuntimeException("OA撤回流程异常信息:" + doForceDrawBackResponses.getMsg() + " 导致OA撤回的PLM异常:" + e.getMessage()); + } + throw new RuntimeException(e.getMessage()); + } + private String toLikeParam(String value) { if (StringUtils.isBlank(value)) { return null; diff --git a/src/main/java/com/spring/modules/rohs/vo/RohsSubmitVo.java b/src/main/java/com/spring/modules/rohs/vo/RohsSubmitVo.java index be0c3525..3b42dca5 100644 --- a/src/main/java/com/spring/modules/rohs/vo/RohsSubmitVo.java +++ b/src/main/java/com/spring/modules/rohs/vo/RohsSubmitVo.java @@ -1,14 +1,15 @@ package com.spring.modules.rohs.vo; +import com.spring.modules.rohs.entity.RohsEntity; import lombok.Data; - -import java.io.Serializable; +import lombok.EqualsAndHashCode; /** * RoHs 提交流程参数 */ @Data -public class RohsSubmitVo implements Serializable { +@EqualsAndHashCode(callSuper = true) +public class RohsSubmitVo extends RohsEntity { private static final long serialVersionUID = 1L; private String site;