Browse Source

2026-05-06

RoHs功能优化
master
fengyuan_yang 1 month ago
parent
commit
2967785a57
  1. 1
      src/main/java/com/spring/common/utils/Constant.java
  2. 21
      src/main/java/com/spring/modules/rohs/controller/RohsController.java
  3. 8
      src/main/java/com/spring/modules/rohs/service/RohsService.java
  4. 173
      src/main/java/com/spring/modules/rohs/service/impl/RohsServiceImpl.java

1
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";

21
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()));
}
/**
* 删除 (扩展)
*/

8
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<RohsEntity> {
/**
* 下达
*/
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<RohsEntity> {
* 查询审批记录
*/
List<ProcessFormVo> getApprovalList(String site, String menuId, String documentNo);
/**
* 查询当前按钮控制信息
*/
HashMap<String, String> getButtonCondition(String site, String referenceNo);
}

173
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<RohsMapper, RohsEntity> 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<String, Object> params) {
String site = (String) params.get("site");
@ -55,7 +88,8 @@ public class RohsServiceImpl extends ServiceImpl<RohsMapper, RohsEntity> 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<RohsMapper, RohsEntity> 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<RohsEntity> updateWrapper = new QueryWrapper<>();
updateWrapper.eq("site", site).eq("reference_no", referenceNo);
this.update(updateEntity, updateWrapper);
return;
}
// 获取审批基础数据
Map<String, String> baseData = changeManagementService.getReleaseBaseData(site, userName, menuId, referenceNo);
List<PlmRequestDetailVo> nodeDetails = changeManagementMapper.queryNodeDetailFirst(site, baseData.get("workflowId"), menuId);
if (nodeDetails == null || nodeDetails.isEmpty()) {
throw new RuntimeException("流程节点信息获取异常!");
}
// RoHs仅主信息表plm_rohs
List<MainData> 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<SysUserEntity>().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<OaUserData> 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<RohsEntity> updateWrapper = new QueryWrapper<>();
@ -104,4 +229,50 @@ public class RohsServiceImpl extends ServiceImpl<RohsMapper, RohsEntity> impleme
}
return this.baseMapper.getApprovalList(site, menuId, documentNo);
}
@Override
public HashMap<String, String> getButtonCondition(String site, String referenceNo) {
HashMap<String, String> 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<ProcessFormEntity> currentProcessList = changeManagementMapper.queryRequestId(site, "", referenceNo);
if (currentProcessList == null || currentProcessList.isEmpty()) {
return result;
}
Set<String> 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<SysUserEntity>().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);
}
}
Loading…
Cancel
Save