From 2967785a57b970ca5535906c2aab2451a20487c8 Mon Sep 17 00:00:00 2001 From: fengyuan_yang <1976974459@qq.com> Date: Wed, 6 May 2026 15:25:58 +0800 Subject: [PATCH] =?UTF-8?q?2026-05-06=20RoHs=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/spring/common/utils/Constant.java | 1 + .../rohs/controller/RohsController.java | 21 ++- .../modules/rohs/service/RohsService.java | 8 +- .../rohs/service/impl/RohsServiceImpl.java | 173 +++++++++++++++++- 4 files changed, 198 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/spring/common/utils/Constant.java b/src/main/java/com/spring/common/utils/Constant.java index ef23cbfe..02b296d7 100644 --- a/src/main/java/com/spring/common/utils/Constant.java +++ b/src/main/java/com/spring/common/utils/Constant.java @@ -48,6 +48,7 @@ public class Constant { public static final Integer TEN = 10; public static final String DY_PR = "PROOFING"; public static final String ECN = "ECN"; + public static final String ROHS = "rohs"; public static final String TOOL = "TOOL"; public static final String QUOTATION = "QUOTATION"; public static final String TEST = "TEST"; 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 cdc23da1..a8d872fc 100644 --- a/src/main/java/com/spring/modules/rohs/controller/RohsController.java +++ b/src/main/java/com/spring/modules/rohs/controller/RohsController.java @@ -9,7 +9,9 @@ import com.spring.modules.oss.service.SysOssService; import com.spring.modules.rohs.entity.RohsEntity; import com.spring.modules.rohs.service.RohsService; import com.spring.modules.rohs.vo.RohsSubmitVo; +import com.spring.modules.sys.entity.SysUserEntity; import org.apache.commons.lang.StringUtils; +import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; @@ -161,11 +163,13 @@ public class RohsController { @PostMapping("/issue") @Transactional public R issue(@RequestBody RohsSubmitVo data) { - if (StringUtils.isBlank(data.getSite()) || StringUtils.isBlank(data.getReferenceNo())) { - return R.error("工厂(site)和序列号(referenceNo)不能为空"); + if (StringUtils.isBlank(data.getSite()) || StringUtils.isBlank(data.getReferenceNo()) || StringUtils.isBlank(data.getMenuId())) { + return R.error("工厂(site)、序列号(referenceNo)和菜单ID(menuId)不能为空"); } try { - rohsService.issue(data.getSite(), data.getReferenceNo()); + SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); + String userName = user == null ? null : user.getUsername(); + rohsService.issue(data.getSite(), data.getReferenceNo(), userName, data.getMenuId()); } catch (RuntimeException e) { return R.error(e.getMessage()); } @@ -201,6 +205,17 @@ public class RohsController { return R.ok().put("rows", list); } + /** + * 查询按钮控制信息 + */ + @PostMapping("/buttonCondition") + public R buttonCondition(@RequestBody RohsSubmitVo data) { + if (StringUtils.isBlank(data.getSite()) || StringUtils.isBlank(data.getReferenceNo())) { + return R.error("工厂(site)和序列号(referenceNo)不能为空"); + } + return R.ok().put("data", rohsService.getButtonCondition(data.getSite(), data.getReferenceNo())); + } + /** * 删除 (扩展) */ 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 8ef92061..082d7cf0 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 java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,7 +32,7 @@ public interface RohsService extends IService { /** * 下达 */ - void issue(String site, String referenceNo); + void issue(String site, String referenceNo, String userName, String menuId); /** * 提交审批结论 @@ -42,4 +43,9 @@ public interface RohsService extends IService { * 查询审批记录 */ List getApprovalList(String site, String menuId, String documentNo); + + /** + * 查询当前按钮控制信息 + */ + HashMap getButtonCondition(String site, String referenceNo); } 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 6171ab8a..607aedfa 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 @@ -3,22 +3,55 @@ package com.spring.modules.rohs.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +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.data.OaUserData; +import com.spring.modules.change.entity.APIEntity.MainData; +import com.spring.modules.change.entity.ParamData; +import com.spring.modules.change.entity.ProcessFormEntity; +import com.spring.modules.change.mapper.ChangeManagementMapper; +import com.spring.modules.change.service.impl.ChangeManagementServiceImpl; import com.spring.modules.change.vo.ProcessFormVo; +import com.spring.modules.request.vo.PlmRequestDetailVo; import com.spring.modules.rohs.entity.RohsEntity; import com.spring.modules.rohs.mapper.RohsMapper; import com.spring.modules.rohs.service.RohsService; +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.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Set; + +import static com.spring.modules.base.utils.CommonUtils.getPropertyValue; @Service("rohsService") public class RohsServiceImpl extends ServiceImpl implements RohsService { + @Autowired + private SysUserDao sysUserDao; + + @Autowired + private ChangeManagementMapper changeManagementMapper; + + @Autowired + private ChangeManagementServiceImpl changeManagementService; + + @Value("${oa-control.control-flag}") + private Boolean dataUrlOa; + @Override public PageUtils queryPage(Map params) { String site = (String) params.get("site"); @@ -55,7 +88,8 @@ public class RohsServiceImpl extends ServiceImpl impleme } @Override - public void issue(String site, String referenceNo) { + @Transactional + public void issue(String site, String referenceNo, String userName, String menuId) { RohsEntity rohs = this.getDetail(site, referenceNo); if (rohs == null) { throw new RuntimeException("未找到对应RoHs单据"); @@ -63,6 +97,97 @@ public class RohsServiceImpl extends ServiceImpl impleme if (!"草稿".equals(rohs.getStatus())) { throw new RuntimeException("仅草稿状态的单据允许下达"); } + if (StringUtils.isBlank(userName)) { + throw new RuntimeException("下达人不能为空"); + } + if (StringUtils.isBlank(menuId)) { + throw new RuntimeException("菜单ID不能为空"); + } + + // 关闭调用OA接口时,反刷单据状态为"已完成"(与变更下达一致) + if (!dataUrlOa) { + RohsEntity updateEntity = new RohsEntity(); + updateEntity.setStatus("已完成"); + QueryWrapper updateWrapper = new QueryWrapper<>(); + updateWrapper.eq("site", site).eq("reference_no", referenceNo); + this.update(updateEntity, updateWrapper); + return; + } + + // 获取审批基础数据 + Map baseData = changeManagementService.getReleaseBaseData(site, userName, menuId, referenceNo); + List nodeDetails = changeManagementMapper.queryNodeDetailFirst(site, baseData.get("workflowId"), menuId); + if (nodeDetails == null || nodeDetails.isEmpty()) { + throw new RuntimeException("流程节点信息获取异常!"); + } + + // RoHs仅主信息表:plm_rohs + List mainData = new ArrayList<>(); + 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())) { + // 人员字段:PLM用户 -> 域控账号 -> OA人员ID + SysUserEntity sysUser = sysUserDao.selectOne(new QueryWrapper().eq("username", fieldValue)); + if (sysUser == null) { + throw new RuntimeException("未找到PLM用户信息,用户编码: " + fieldValue); + } + String account = sysUser.getDomainControlAccount(); + if (StringUtils.isBlank(account)) { + throw new RuntimeException("未获取到PLM人员域控账号,用户编码: " + fieldValue); + } + List oaIds = sysUserDao.selectOaIdByAccount(account); + if (oaIds == null || oaIds.isEmpty()) { + throw new RuntimeException("未获取到域控账号对应的OA人员,域控账号: " + account); + } + fieldValue = oaIds.get(0).getId(); + } + } + + 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); + } + + ParamData paramData = new ParamData(site, baseData.get("domainControlAccount"), nodeDetails.get(0).getNodeId(), nodeDetails.get(0).getNodeName(), + referenceNo, userName, baseData.get("classificationNo"), nodeDetails.get(0).getStepId(), baseData.get("menuId"), baseData.get("menuName"), + baseData.get("userId"), baseData.get("workflowId"), baseData.get("workflowname"), baseData.get("requestName"), mainData, baseData.get("path"), + "", "plm_rohs", "reference_no", "status"); + + try { + changeManagementService.issueFunction(paramData, Constant.ROHS); + // 正常下达后,状态更新为"审批中" + if ("已完成".equals(paramData.getStatus())) { + return; + } + } catch (Exception e) { + changeManagementService.rollBackFunction(paramData, e); + throw new RuntimeException(e.getMessage()); + } + RohsEntity updateEntity = new RohsEntity(); updateEntity.setStatus("审批中"); QueryWrapper updateWrapper = new QueryWrapper<>(); @@ -104,4 +229,50 @@ public class RohsServiceImpl extends ServiceImpl impleme } return this.baseMapper.getApprovalList(site, menuId, documentNo); } + + @Override + public HashMap getButtonCondition(String site, String referenceNo) { + HashMap result = new HashMap<>(); + result.put("createBy2", ""); + result.put("isReject", "Y"); + result.put("tpProcessControl", "N"); + result.put("csProcessControl", "N"); + + if (StringUtils.isBlank(site) || StringUtils.isBlank(referenceNo)) { + return result; + } + + List currentProcessList = changeManagementMapper.queryRequestId(site, "", referenceNo); + if (currentProcessList == null || currentProcessList.isEmpty()) { + return result; + } + + Set approvers = new LinkedHashSet<>(); + for (ProcessFormEntity processForm : currentProcessList) { + String approver = processForm.getUpdateBy(); + if (StringUtils.isBlank(approver) && StringUtils.isNotBlank(processForm.getDomainControlAccount())) { + SysUserEntity sysUser = sysUserDao.selectOne( + new QueryWrapper().eq("domain_control_account", processForm.getDomainControlAccount()) + ); + if (sysUser != null) { + approver = sysUser.getUsername(); + } + } + if (StringUtils.isNotBlank(approver)) { + approvers.add(approver); + } + } + result.put("createBy2", String.join(";", approvers)); + return result; + } + + private String convertFieldValue(Object valueObj) { + if (valueObj == null) { + return ""; + } + if (valueObj instanceof Date) { + return DateUtils.format((Date) valueObj); + } + return String.valueOf(valueObj); + } }