diff --git a/src/main/java/com/spring/common/utils/Constant.java b/src/main/java/com/spring/common/utils/Constant.java index 02b296d7..b9ff48e7 100644 --- a/src/main/java/com/spring/common/utils/Constant.java +++ b/src/main/java/com/spring/common/utils/Constant.java @@ -49,6 +49,7 @@ public class Constant { public static final String DY_PR = "PROOFING"; public static final String ECN = "ECN"; public static final String ROHS = "rohs"; + public static final String LAB = "lab"; 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/lab/controller/LabController.java b/src/main/java/com/spring/modules/lab/controller/LabController.java new file mode 100644 index 00000000..ba43e025 --- /dev/null +++ b/src/main/java/com/spring/modules/lab/controller/LabController.java @@ -0,0 +1,237 @@ +package com.spring.modules.lab.controller; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.spring.common.utils.PageUtils; +import com.spring.common.utils.R; +import com.spring.modules.base.service.TransNoControlService; +import com.spring.modules.change.vo.ProcessFormVo; +import com.spring.modules.lab.entity.LabEntity; +import com.spring.modules.lab.service.LabService; +import com.spring.modules.lab.vo.LabSubmitVo; +import com.spring.modules.oss.entity.SysOssEntity; +import com.spring.modules.oss.service.SysOssService; +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.*; + +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * Lab Controller + */ +@RestController +@RequestMapping("/lab") +public class LabController { + + private static final String REFERENCE_NO_TRANS_TYPE = "reference_no"; + + @Autowired + private LabService labService; + + @Autowired + private SysOssService sysOssService; + + @Autowired + private TransNoControlService transNoControlService; + + /** + * 列表查询 + */ + @GetMapping("/list") + public R list(@RequestParam Map params) { + PageUtils page = labService.queryPage(params); + return R.ok().put("page", page); + } + + /** + * 详情查询 + */ + @GetMapping("/info") + public R info(@RequestParam("site") String site, @RequestParam("referenceNo") String referenceNo) { + if (StringUtils.isBlank(site) || StringUtils.isBlank(referenceNo)) { + return R.error("工厂(site)和序列号(referenceNo)不能为空"); + } + LabEntity lab = labService.getDetail(site, referenceNo); + return R.ok().put("data", lab); + } + + /** + * 保存 + */ + @PostMapping("/save") + @Transactional + public R save(@RequestBody LabEntity lab) { + if (StringUtils.isBlank(lab.getSite()) || StringUtils.isBlank(lab.getReferenceNo())) { + return R.error("工厂(site)和序列号(referenceNo)不能为空"); + } + String currentUserName = getCurrentUserName(); + + String originalReferenceNo = lab.getReferenceNo(); + String newReferenceNo = originalReferenceNo; + + if (originalReferenceNo.startsWith("TEMP-")) { + newReferenceNo = transNoControlService.transNo(lab.getSite(), REFERENCE_NO_TRANS_TYPE); + if (StringUtils.isBlank(newReferenceNo)) { + return R.error("请维护编码生成规则(TransNoControl)!"); + } + lab.setReferenceNo(newReferenceNo); + + SysOssEntity updateOss = new SysOssEntity(); + updateOss.setOrderRef1(lab.getSite()); + updateOss.setOrderRef2(newReferenceNo); + + QueryWrapper ossWrapper = new QueryWrapper<>(); + ossWrapper.eq("order_ref1", lab.getSite()); + ossWrapper.eq("order_ref2", originalReferenceNo); + sysOssService.update(updateOss, ossWrapper); + } else { + LabEntity exist = labService.getDetail(lab.getSite(), lab.getReferenceNo()); + if (exist != null) { + return R.error("该序列号(referenceNo)的申请记录已存在"); + } + } + + if (lab.getApplicationDate() == null) { + lab.setApplicationDate(new Date()); + } + if (StringUtils.isBlank(lab.getStatus())) { + lab.setStatus("草稿"); + } + if (lab.getCreateDate() == null) { + lab.setCreateDate(new Date()); + } + if (StringUtils.isBlank(lab.getCreateBy())) { + lab.setCreateBy(currentUserName); + } + if (lab.getStepId() == null) { + lab.setStepId(10); + } + if (StringUtils.isBlank(lab.getRejectFlag())) { + lab.setRejectFlag("N"); + } + labService.save(lab); + return R.ok().put("referenceNo", newReferenceNo); + } + + /** + * 修改 + */ + @PostMapping("/update") + public R update(@RequestBody LabEntity lab) { + if (StringUtils.isBlank(lab.getSite()) || StringUtils.isBlank(lab.getReferenceNo())) { + return R.error("工厂(site)和序列号(referenceNo)不能为空"); + } + String currentUserName = getCurrentUserName(); + LabEntity exists = labService.getDetail(lab.getSite(), lab.getReferenceNo()); + if (exists == null) { + return R.error("未找到对应Lab单据"); + } + if ("已完成".equals(exists.getStatus())) { + return R.error("已完成状态的单据不允许修改"); + } + if (StringUtils.isBlank(lab.getStatus())) { + lab.setStatus(exists.getStatus()); + } + lab.setUpdateDate(new Date()); + if (StringUtils.isBlank(lab.getUpdateBy())) { + lab.setUpdateBy(currentUserName); + } + + QueryWrapper updateWrapper = new QueryWrapper<>(); + updateWrapper.eq("site", lab.getSite()).eq("reference_no", lab.getReferenceNo()); + labService.update(lab, updateWrapper); + return R.ok(); + } + + /** + * 下达 + */ + @PostMapping("/issue") + public R issue(@RequestBody LabSubmitVo data) { + if (StringUtils.isBlank(data.getSite()) || StringUtils.isBlank(data.getReferenceNo()) || StringUtils.isBlank(data.getMenuId())) { + return R.error("工厂(site)、序列号(referenceNo)和菜单ID(menuId)不能为空"); + } + try { + SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); + String userName = user == null ? null : user.getUsername(); + labService.issue(data.getSite(), data.getReferenceNo(), userName, data.getMenuId()); + } catch (RuntimeException e) { + return R.error(e.getMessage()); + } + return R.ok(); + } + + /** + * 审批提交(同意/驳回) + */ + @PostMapping("/submit") + public R submit(@RequestBody LabSubmitVo data) { + if (StringUtils.isBlank(data.getSite()) || StringUtils.isBlank(data.getReferenceNo())) { + return R.error("工厂(site)和序列号(referenceNo)不能为空"); + } + try { + SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); + String userName = user == null ? null : user.getUsername(); + labService.submit(data, userName); + } catch (RuntimeException e) { + return R.error(e.getMessage()); + } + return R.ok(); + } + + /** + * 查询审批信息 + */ + @PostMapping("/approvalList") + public R approvalList(@RequestBody LabSubmitVo data) { + if (StringUtils.isBlank(data.getSite()) || StringUtils.isBlank(data.getMenuId()) || StringUtils.isBlank(data.getDocumentNo())) { + return R.ok().put("rows", Collections.emptyList()); + } + List list = labService.getApprovalList(data.getSite(), data.getMenuId(), data.getDocumentNo()); + return R.ok().put("rows", list); + } + + /** + * 查询按钮控制信息 + */ + @PostMapping("/buttonCondition") + public R buttonCondition(@RequestBody LabSubmitVo data) { + if (StringUtils.isBlank(data.getSite()) || StringUtils.isBlank(data.getReferenceNo())) { + return R.error("工厂(site)和序列号(referenceNo)不能为空"); + } + return R.ok().put("data", labService.getButtonCondition(data.getSite(), data.getReferenceNo())); + } + + /** + * 删除 + */ + @PostMapping("/delete") + @Transactional + public R delete(@RequestBody LabEntity lab) { + if (StringUtils.isBlank(lab.getSite()) || StringUtils.isBlank(lab.getReferenceNo())) { + return R.error("工厂(site)和序列号(referenceNo)不能为空"); + } + + QueryWrapper deleteWrapper = new QueryWrapper<>(); + deleteWrapper.eq("site", lab.getSite()).eq("reference_no", lab.getReferenceNo()); + labService.remove(deleteWrapper); + + QueryWrapper ossWrapper = new QueryWrapper<>(); + ossWrapper.eq("order_ref1", lab.getSite()); + ossWrapper.eq("order_ref2", lab.getReferenceNo()); + sysOssService.remove(ossWrapper); + + return R.ok(); + } + + private String getCurrentUserName() { + SysUserEntity user = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); + return user == null ? "" : user.getUsername(); + } +} diff --git a/src/main/java/com/spring/modules/lab/entity/LabEntity.java b/src/main/java/com/spring/modules/lab/entity/LabEntity.java new file mode 100644 index 00000000..f14217eb --- /dev/null +++ b/src/main/java/com/spring/modules/lab/entity/LabEntity.java @@ -0,0 +1,248 @@ +package com.spring.modules.lab.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; + +/** + * Lab 实验室申请实体类 + */ +@Data +@TableName("plm_lab") +public class LabEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 工厂 + */ + private String site; + + /** + * 序列号 + */ + private String referenceNo; + + /** + * 申请人 + */ + private String applicant; + + /** + * 申请日期 + */ + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date applicationDate; + + /** + * 申请部门 + */ + private String applyDepartment; + + /** + * 需求日期 + */ + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date requestedDate; + + /** + * 项目编码 + */ + private String projectId; + + /** + * 客户编码 + */ + private String customerId; + + /** + * 样品名称 + */ + private String sampleName; + + /** + * 样品型号 + */ + private String sampleModel; + + /** + * 样品数量 + */ + private String sampleQty; + + /** + * 测试目的 + */ + private String testPurpose; + + /** + * 产品阶段 + */ + private String productStage; + + /** + * 测试类型 + */ + private String testType; + + /** + * 报告出具 + */ + private String reportDocument; + + /** + * 样品退回 + */ + private String returnSample; + + /** + * 应用表面 + */ + private String applicationSurface; + + /** + * 测试实验室 + */ + private String testLab; + + /** + * 注意事项 + */ + private String attention; + + /** + * 测试开始时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date testStartDate; + + /** + * 测试完成日期 + */ + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date completedDate; + + /** + * 异常情况及说明 + */ + private String unnormalSymptomAndDescription; + + /** + * 测试编码 + */ + private String testNumber; + + /** + * 备注(测试员) + */ + private String testerComments; + + /** + * 备注(部门经理) + */ + private String departmentManagerComments; + + /** + * 备注(实验室) + */ + private String labComments; + + /** + * 测试人(;分隔) + */ + private String tester; + + /** + * 单据状态(草稿/审批中/已完成) + */ + private String status; + + /** + * 创建时间 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createDate; + + /** + * 创建人 + */ + private String createBy; + + /** + * 修改时间 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date updateDate; + + /** + * 修改人 + */ + private String updateBy; + + /** + * 流程步骤 + */ + private Integer stepId; + + /** + * 驳回标识 + */ + private String rejectFlag; + + /** + * 驳回步骤 + */ + private Integer rejectStepId; + + /** + * 当前节点 ID + */ + @TableField(exist = false) + private String nodeId; + + /** + * 当前节点名称 + */ + @TableField(exist = false) + private String nodeName; + + /** + * 当前节点审批人 + */ + @TableField(exist = false) + private String currentApprover; + + /** + * 申请人名称 + */ + @TableField(exist = false) + private String applicantName; + + /** + * 客户名称 + */ + @TableField(exist = false) + private String customerName; + + /** + * 项目名称 + */ + @TableField(exist = false) + private String projectName; + + /** + * 测试人名称 + */ + @TableField(exist = false) + private String testerName; +} diff --git a/src/main/java/com/spring/modules/lab/mapper/LabMapper.java b/src/main/java/com/spring/modules/lab/mapper/LabMapper.java new file mode 100644 index 00000000..becf7da8 --- /dev/null +++ b/src/main/java/com/spring/modules/lab/mapper/LabMapper.java @@ -0,0 +1,24 @@ +package com.spring.modules.lab.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.spring.modules.change.vo.ProcessFormVo; +import com.spring.modules.lab.entity.LabEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; +import java.util.Map; + +/** + * Lab Mapper + */ +@Mapper +public interface LabMapper extends BaseMapper { + + List getApprovalList(@Param("site") String site, @Param("menuId") String menuId, @Param("documentNo") String documentNo); + + IPage queryPageWithNames(IPage page, @Param("params") Map params); + + LabEntity getDetailWithNames(@Param("site") String site, @Param("referenceNo") String referenceNo); +} diff --git a/src/main/java/com/spring/modules/lab/service/LabService.java b/src/main/java/com/spring/modules/lab/service/LabService.java new file mode 100644 index 00000000..bdb651c0 --- /dev/null +++ b/src/main/java/com/spring/modules/lab/service/LabService.java @@ -0,0 +1,47 @@ +package com.spring.modules.lab.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.spring.common.utils.PageUtils; +import com.spring.modules.change.vo.ProcessFormVo; +import com.spring.modules.lab.entity.LabEntity; +import com.spring.modules.lab.vo.LabSubmitVo; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Lab Service + */ +public interface LabService extends IService { + + /** + * 分页查询 + */ + PageUtils queryPage(Map params); + + /** + * 详情查询 + */ + LabEntity getDetail(String site, String referenceNo); + + /** + * 下达 + */ + void issue(String site, String referenceNo, String userName, String menuId); + + /** + * 提交审批结论 + */ + void submit(LabSubmitVo data, String userName); + + /** + * 查询审批记录 + */ + List getApprovalList(String site, String menuId, String documentNo); + + /** + * 查询当前按钮控制信息 + */ + HashMap getButtonCondition(String site, String referenceNo); +} diff --git a/src/main/java/com/spring/modules/lab/service/impl/LabServiceImpl.java b/src/main/java/com/spring/modules/lab/service/impl/LabServiceImpl.java new file mode 100644 index 00000000..544e8c13 --- /dev/null +++ b/src/main/java/com/spring/modules/lab/service/impl/LabServiceImpl.java @@ -0,0 +1,411 @@ +package com.spring.modules.lab.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.base.utils.HttpClientUtil; +import com.spring.modules.base.utils.ResponseData; +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; +import com.spring.modules.change.service.impl.ChangeManagementServiceImpl; +import com.spring.modules.change.vo.ProcessFormVo; +import com.spring.modules.lab.entity.LabEntity; +import com.spring.modules.lab.mapper.LabMapper; +import com.spring.modules.lab.service.LabService; +import com.spring.modules.lab.vo.LabSubmitVo; +import com.spring.modules.request.vo.PlmRequestDetailVo; +import com.spring.modules.sys.dao.SysUserDao; +import com.spring.modules.sys.entity.SysUserEntity; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.BeanUtils; +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("labService") +public class LabServiceImpl extends ServiceImpl implements LabService { + + @Autowired + private SysUserDao sysUserDao; + + @Autowired + private ChangeManagementMapper changeManagementMapper; + + @Autowired + private ChangeManagementServiceImpl changeManagementService; + + @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"))); + params.put("applicant", toLikeParam((String) params.get("applicant"))); + params.put("currentApprover", toLikeParam((String) params.get("currentApprover"))); + + IPage page = this.baseMapper.queryPageWithNames( + new Query().getPage(params), + params + ); + return new PageUtils(page); + } + + @Override + public LabEntity getDetail(String site, String referenceNo) { + return this.baseMapper.getDetailWithNames(site, referenceNo); + } + + @Override + @Transactional + public void issue(String site, String referenceNo, String userName, String menuId) { + LabEntity lab = this.getDetail(site, referenceNo); + if (lab == null) { + throw new RuntimeException("未找到对应Lab单据"); + } + if (!"草稿".equals(lab.getStatus())) { + throw new RuntimeException("仅草稿状态的单据允许下达"); + } + if (StringUtils.isBlank(userName)) { + throw new RuntimeException("下达人不能为空"); + } + if (StringUtils.isBlank(menuId)) { + throw new RuntimeException("菜单ID不能为空"); + } + + if (!dataUrlOa) { + LabEntity updateEntity = new LabEntity(); + 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("流程节点信息获取异常!"); + } + + 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_lab".equals(nodeDetail.getPlmTable())) { + Object valueObj = getPropertyValue(lab, 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); + } + + 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_lab", "reference_no", "status"); + + try { + changeManagementService.issueFunction(paramData, Constant.LAB); + if ("已完成".equals(paramData.getStatus())) { + return; + } + } catch (Exception e) { + changeManagementService.rollBackFunction(paramData, e); + throw new RuntimeException(e.getMessage()); + } + + LabEntity updateEntity = new LabEntity(); + updateEntity.setStatus("审批中"); + QueryWrapper updateWrapper = new QueryWrapper<>(); + updateWrapper.eq("site", site).eq("reference_no", referenceNo); + this.update(updateEntity, updateWrapper); + } + + @Override + @Transactional + public void submit(LabSubmitVo 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(); + + LabEntity current = this.getDetail(site, referenceNo); + if (current == null) { + throw new RuntimeException("未找到对应Lab单据"); + } + 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(驳回)"); + } + + LabEntity updateEntity = new LabEntity(); + 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); + QueryWrapper updateWrapper = new QueryWrapper<>(); + updateWrapper.eq("site", site).eq("reference_no", referenceNo); + this.update(updateEntity, updateWrapper); + + if (!dataUrlOa) { + LabEntity statusEntity = new LabEntity(); + 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; + } + + LabEntity lab = this.getDetail(site, referenceNo); + if (lab == null) { + throw new RuntimeException("更新后未找到对应Lab单据"); + } + + 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_lab", "reference_no", "status", lab.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, lab); + 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.LAB); + } 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.LAB); + } catch (Exception e) { + handleSubmitRollback(paramData, e); + } + } + } + + @Override + public List getApprovalList(String site, String menuId, String documentNo) { + if (StringUtils.isBlank(site) || StringUtils.isBlank(menuId) || StringUtils.isBlank(documentNo)) { + return Collections.emptyList(); + } + 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 List getSubmitMainData(String site, Map baseData, LabEntity lab) { + 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_lab".equals(nodeDetail.getPlmTable())) { + Object valueObj = getPropertyValue(lab, 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; + } + return "%" + value.trim() + "%"; + } + + private String convertFieldValue(Object valueObj) { + if (valueObj == null) { + return ""; + } + if (valueObj instanceof Date) { + return DateUtils.format((Date) valueObj); + } + return String.valueOf(valueObj); + } +} diff --git a/src/main/java/com/spring/modules/lab/vo/LabSubmitVo.java b/src/main/java/com/spring/modules/lab/vo/LabSubmitVo.java new file mode 100644 index 00000000..da5eb7e7 --- /dev/null +++ b/src/main/java/com/spring/modules/lab/vo/LabSubmitVo.java @@ -0,0 +1,29 @@ +package com.spring.modules.lab.vo; + +import com.spring.modules.lab.entity.LabEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Lab 提交流程参数 + */ +@Data +@EqualsAndHashCode(callSuper = true) +public class LabSubmitVo extends LabEntity { + private static final long serialVersionUID = 1L; + + private String site; + + private String referenceNo; + + /** + * Y=同意, N=驳回 + */ + private String nodeConclusion; + + private String rejectOpinion; + + private String menuId; + + private String documentNo; +} diff --git a/src/main/resources/mapper/lab/LabMapper.xml b/src/main/resources/mapper/lab/LabMapper.xml new file mode 100644 index 00000000..2ac1b560 --- /dev/null +++ b/src/main/resources/mapper/lab/LabMapper.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a.site, a.reference_no, a.applicant, a.application_date, a.apply_department, a.requested_date, + a.project_id, a.customer_id, a.sample_name, a.sample_model, a.sample_qty, a.test_purpose, + a.product_stage, a.test_type, a.report_document, a.return_sample, a.application_surface, a.test_lab, + a.attention, a.test_start_date, a.completed_date, a.unnormal_symptom_and_description, a.test_number, + a.tester_comments, a.department_manager_comments, a.lab_comments, a.tester, a.status, a.create_date, + a.create_by, a.update_date, a.update_by, a.step_id, a.reject_flag, a.reject_step_id + + + + + + + + +