箱变-启源-质检报告回传接口-增加审批收回逻辑、增行逻辑、回传标识、调整子表字段

This commit is contained in:
mzr 2025-10-23 14:52:43 +08:00
parent 832e648ee9
commit 91928b4a6f
1 changed files with 198 additions and 170 deletions

View File

@ -1,29 +1,23 @@
package nc.api.qc.resource; package nc.api.qc.resource;
import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.InvocationInfoProxy; import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator; import nc.bs.framework.common.NCLocator;
import nc.bs.trade.business.HYSuperDMO;
import nc.impl.qc.c003.maintain.ReportMaintainImpl;
import nc.itf.qc.c003.approve.IReportApprove;
import nc.itf.qc.c003.maintain.IReportMaintain; import nc.itf.qc.c003.maintain.IReportMaintain;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.vo.pub.BusinessException; import nc.vo.pub.BusinessException;
import nc.vo.pub.VOStatus; import nc.vo.pub.VOStatus;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDouble; import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.pattern.model.transfer.bill.ClientBillCombinServer; import nc.vo.qc.c003.entity.ReportHeaderVO;
import nc.vo.qc.c003.entity.ReportItemVO; import nc.vo.qc.c003.entity.ReportItemVO;
import nc.vo.qc.c003.entity.ReportVO; import nc.vo.qc.c003.entity.ReportVO;
import nc.vo.qc.c003.util.ReportVOInfoUtils;
import nc.vo.scmpub.res.billtype.QCBillType; import nc.vo.scmpub.res.billtype.QCBillType;
import nc.vo.scmpub.util.ArrayUtil; import nc.vo.util.CloneUtil;
import nc.vo.scmpub.util.CollectionUtils;
import nccloud.api.rest.utils.NCCRestUtils; import nccloud.api.rest.utils.NCCRestUtils;
import nccloud.api.rest.utils.ResultMessageUtil; import nccloud.api.rest.utils.ResultMessageUtil;
import nccloud.base.exception.ExceptionUtils;
import nccloud.dto.scmpub.script.entity.SCMScriptResultDTO; import nccloud.dto.scmpub.script.entity.SCMScriptResultDTO;
import nccloud.framework.service.ServiceLocator;
import nccloud.pubitf.arap.arappub.IArapBillPubUtilService;
import nccloud.pubitf.riart.pflow.CloudPFlowContext; import nccloud.pubitf.riart.pflow.CloudPFlowContext;
import nccloud.pubitf.riart.pflow.ICloudScriptPFlowService;
import nccloud.pubitf.scmpub.commit.service.IBatchRunScriptService; import nccloud.pubitf.scmpub.commit.service.IBatchRunScriptService;
import nccloud.pubitf.scmpub.pub.service.ISCMPubQueryService; import nccloud.pubitf.scmpub.pub.service.ISCMPubQueryService;
import org.json.JSONString; import org.json.JSONString;
@ -32,10 +26,7 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* QMS将检验结果回传至ERP质检报告中 * QMS将检验结果回传至ERP质检报告中
@ -43,14 +34,7 @@ import java.util.Map;
@Path("qc/qcconclusion") @Path("qc/qcconclusion")
public class QcconclusionRestResource extends QcBaseRestResource { public class QcconclusionRestResource extends QcBaseRestResource {
HYSuperDMO dmo = null; private static BaseDAO dao = new BaseDAO();
public HYSuperDMO getSuperDMO() {
if (dmo == null) {
dmo = new HYSuperDMO();
}
return dmo;
}
/** /**
* QMS将检验结果回传至ERP质检报告中 * QMS将检验结果回传至ERP质检报告中
@ -68,18 +52,27 @@ public class QcconclusionRestResource extends QcBaseRestResource {
NCCRestUtils.initInvocationInfo(); NCCRestUtils.initInvocationInfo();
String json = str.toJSONString(); String json = str.toJSONString();
Map<String, Object> billMap = (Map) fromJson(json, Map.class); Map<String, Object> billMap = (Map) fromJson(json, Map.class);
// List<ReportVO> list = (List<ReportVO>) billMap.get("list"); String flag = (String) billMap.get("flag");
//获取全部质检报告 if (!"Y".equals(flag) && !"N".equals(flag)) {
return ResultMessageUtil.exceptionToJSON(new BusinessException("flag字段未正确传值"));
}
// 获取全部质检报告
List<Map<String, Object>> itemMaps = (List) billMap.get("items"); List<Map<String, Object>> itemMaps = (List) billMap.get("items");
List<String> list=new ArrayList<String>(); List<String> list = new ArrayList<>();
for (Map<String, Object> itemMap : itemMaps) { for (Map<String, Object> itemMap : itemMaps) {
list.add((String) itemMap.get("id")); list.add((String) itemMap.get("id"));
} }
ReportVO[] vos = (ReportVO[])((ISCMPubQueryService) NCLocator.getInstance().lookup(ISCMPubQueryService.class)).billquery(ReportVO.class, list.toArray(new String[list.size()])); String[] idArr = list.toArray(new String[0]);
ReportVO[] vos = NCLocator.getInstance().lookup(ISCMPubQueryService.class).billquery(ReportVO.class, idArr);
if (vos == null || vos.length == 0) {
return ResultMessageUtil.exceptionToJSON(new BusinessException("未查询到质检报告"));
}
ReportVO[] resultVos = null;
if ("Y".equals(flag)) {
// 1. 创建新数组长度与原数组一致 // 1. 创建新数组长度与原数组一致
ReportVO[] updatevos = new ReportVO[vos.length]; ReportVO[] updatevos = new ReportVO[vos.length];
// 2. 遍历原数组对每个元素进行深度克隆 // 2. 遍历原数组对每个元素进行深度克隆
for (int i = 0; i < vos.length; i++) { for (int i = 0; i < vos.length; i++) {
if (vos[i] != null) { if (vos[i] != null) {
// 假设ReportVO重写了clone()方法实现深度克隆 // 假设ReportVO重写了clone()方法实现深度克隆
@ -88,10 +81,11 @@ public class QcconclusionRestResource extends QcBaseRestResource {
} }
for (ReportVO vo : vos) { for (ReportVO vo : vos) {
// 先判断vo和其HVO是否为null避免NPE // 先判断vo和其HVO是否为null避免NPE
if (vo == null || vo.getHVO() == null) { ReportHeaderVO hvo = vo.getHVO();
if (vo == null || hvo == null) {
continue; continue;
} }
Object pkReportbill = vo.getHVO().getPk_reportbill(); String pkReportbill = (String) hvo.getPk_reportbill();
// 校验HVO的pk_reportbill是否为必填不为null // 校验HVO的pk_reportbill是否为必填不为null
if (pkReportbill == null) { if (pkReportbill == null) {
continue; continue;
@ -108,32 +102,33 @@ public class QcconclusionRestResource extends QcBaseRestResource {
} }
// 匹配成功更新状态 // 匹配成功更新状态
vo.getHVO().setStatus(VOStatus.UPDATED); hvo.setStatus(VOStatus.UPDATED);
hvo.setVdef10(flag);// 回传标识
// 处理数量字段存在且不为null才赋值 // 处理数量字段存在且不为null才赋值
// 检验主数量 // 检验主数量
if (itemMap.containsKey("nchecknum") && itemMap.get("nchecknum") instanceof Double) { if (itemMap.containsKey("nchecknum") && itemMap.get("nchecknum") instanceof Double) {
vo.getHVO().setNchecknum(new UFDouble((Double) itemMap.get("nchecknum"))); hvo.setNchecknum(new UFDouble((Double) itemMap.get("nchecknum")));
} }
// 检验数量 // 检验数量
if (itemMap.containsKey("ncheckastnum") && itemMap.get("ncheckastnum") instanceof Double) { if (itemMap.containsKey("ncheckastnum") && itemMap.get("ncheckastnum") instanceof Double) {
vo.getHVO().setNcheckastnum(new UFDouble((Double) itemMap.get("ncheckastnum"))); hvo.setNcheckastnum(new UFDouble((Double) itemMap.get("ncheckastnum")));
} }
// 合格主数量 // 合格主数量
if (itemMap.containsKey("neliginum") && itemMap.get("neliginum") instanceof Double) { if (itemMap.containsKey("neliginum") && itemMap.get("neliginum") instanceof Double) {
vo.getHVO().setNeliginum(new UFDouble((Double) itemMap.get("neliginum"))); hvo.setNeliginum(new UFDouble((Double) itemMap.get("neliginum")));
} }
// 合格数量 // 合格数量
if (itemMap.containsKey("neligiastnum") && itemMap.get("neligiastnum") instanceof Double) { if (itemMap.containsKey("neligiastnum") && itemMap.get("neligiastnum") instanceof Double) {
vo.getHVO().setNeligiastnum(new UFDouble((Double) itemMap.get("neligiastnum"))); hvo.setNeligiastnum(new UFDouble((Double) itemMap.get("neligiastnum")));
} }
// 不合格主数量 // 不合格主数量
if (itemMap.containsKey("nuneliginum") && itemMap.get("nuneliginum") instanceof Double) { if (itemMap.containsKey("nuneliginum") && itemMap.get("nuneliginum") instanceof Double) {
vo.getHVO().setNuneliginum(new UFDouble((Double) itemMap.get("nuneliginum"))); hvo.setNuneliginum(new UFDouble((Double) itemMap.get("nuneliginum")));
} }
// 不合格数量 // 不合格数量
if (itemMap.containsKey("nuneligiastnum") && itemMap.get("nuneligiastnum") instanceof Double) { if (itemMap.containsKey("nuneligiastnum") && itemMap.get("nuneligiastnum") instanceof Double) {
vo.getHVO().setNuneligiastnum(new UFDouble((Double) itemMap.get("nuneligiastnum"))); hvo.setNuneligiastnum(new UFDouble((Double) itemMap.get("nuneligiastnum")));
} }
this.appendPseudoColumn(vo); this.appendPseudoColumn(vo);
@ -153,7 +148,7 @@ public class QcconclusionRestResource extends QcBaseRestResource {
if (bvos == null) { if (bvos == null) {
continue; continue;
} }
List<Map<String, Object>> newList = new ArrayList<>();
for (int i = 0; i < bvos.length; i++) { for (int i = 0; i < bvos.length; i++) {
ReportItemVO bvo = bvos[i]; ReportItemVO bvo = bvos[i];
// 跳过null的BVO // 跳过null的BVO
@ -168,9 +163,11 @@ public class QcconclusionRestResource extends QcBaseRestResource {
for (Map<String, Object> childMap : mapList) { for (Map<String, Object> childMap : mapList) {
// 校验childMap的reportbill_b是否为必填存在且不为null // 校验childMap的reportbill_b是否为必填存在且不为null
if (childMap == null || !childMap.containsKey("reportbill_b") || childMap.get("reportbill_b") == null) { if (childMap == null || !childMap.containsKey("reportbill_b") || childMap.get("reportbill_b") == null || "".equals(childMap.get("reportbill_b"))) {
continue; // 走新增逻辑
} newList.add(childMap);
} else {
// 走修改逻辑
// 比较reportbill_b是否匹配 // 比较reportbill_b是否匹配
if (!bvoCrowno.equals(childMap.get("reportbill_b"))) { if (!bvoCrowno.equals(childMap.get("reportbill_b"))) {
continue; continue;
@ -180,85 +177,116 @@ public class QcconclusionRestResource extends QcBaseRestResource {
bvo.setStatus(VOStatus.UPDATED); bvo.setStatus(VOStatus.UPDATED);
// 子项数量 // 子项数量
if (childMap.containsKey("nnum") && childMap.get("nnum") instanceof Double) { if (childMap.containsKey("nnum") && childMap.get("nnum") instanceof Double) {
bvo.setNnum(new UFDouble((Double) childMap.get("nnum"))); UFDouble nnum = new UFDouble((Double) childMap.get("nnum"));
bvo.setNnum(nnum);// 主数量
bvo.setNastnum(nnum);// 数量
} }
// 处理判断状态 // 处理判断状态
if (childMap.containsKey("fprocessjudge") && childMap.get("fprocessjudge") instanceof Double) { if (childMap.containsKey("fprocessjudge") && childMap.get("fprocessjudge") instanceof Double) {
bvo.setFprocessjudge(((Double) childMap.get("fprocessjudge")).intValue()); bvo.setFprocessjudge(((Double) childMap.get("fprocessjudge")).intValue());
} }
// 质量等级
if (childMap.containsKey("pk_qualitylv_b") && childMap.get("pk_qualitylv_b") instanceof String pkQualitylvB) {
String zldjSql = "select pk_qualitylv_b from scm_qualitylevel_b where dr = 0 and cqualitylvcode = '" + pkQualitylvB + "'";
Object zldj = dao.executeQuery(zldjSql, new ColumnProcessor());
if (zldj != null) {
bvo.setPk_qualitylv_b(zldj.toString());
}
}
// 质量等级
if (childMap.containsKey("beligible") && childMap.get("beligible") instanceof String beligible) {
UFBoolean beligible1 = new UFBoolean(beligible);
bvo.setBeligible(beligible1);
} }
} }
} }
} }
// this.doSaveAndCombine(vos); List<ReportItemVO> itemVOList = new ArrayList<>(Arrays.asList(bvos));
IReportMaintain reportMaintain=((IReportMaintain) NCLocator.getInstance().lookup(IReportMaintain.class)); if (!newList.isEmpty()) {
ReportVO[] resultVos= reportMaintain.saveBase(vos,new Object(),updatevos); ReportItemVO bvo1 = bvos[0];
// IReportApprove iReportApprove=((IReportApprove) NCLocator.getInstance().lookup(IReportApprove.class)); for (Map<String, Object> childMap : newList) {
// iReportApprove.approveReport(resultVos,); ReportItemVO bvo = (ReportItemVO) CloneUtil.deepClone(bvo1);
bvo.setPk_reportbill_b(null);
bvo.setStatus(VOStatus.NEW);
bvo.setPk_reportbill(pkReportbill);
bvo.setCrowno("20");
// 子项数量
if (childMap.containsKey("nnum") && childMap.get("nnum") instanceof Double) {
UFDouble nnum = new UFDouble((Double) childMap.get("nnum"));
bvo.setNnum(nnum);// 主数量
bvo.setNastnum(nnum);// 数量
}
// 处理判断状态
if (childMap.containsKey("fprocessjudge") && childMap.get("fprocessjudge") instanceof Double) {
bvo.setFprocessjudge(((Double) childMap.get("fprocessjudge")).intValue());
}
// 质量等级
if (childMap.containsKey("pk_qualitylv_b") && childMap.get("pk_qualitylv_b") instanceof String pkQualitylvB) {
String zldjSql = "select pk_qualitylv_b from scm_qualitylevel_b where dr = 0 and cqualitylvcode = '" + pkQualitylvB + "'";
Object zldj = dao.executeQuery(zldjSql, new ColumnProcessor());
if (zldj != null) {
bvo.setPk_qualitylv_b(zldj.toString());
}
}
// 质量等级
if (childMap.containsKey("beligible") && childMap.get("beligible") instanceof String beligible) {
UFBoolean beligible1 = new UFBoolean(beligible);
bvo.setBeligible(beligible1);
}
itemVOList.add(bvo);
}
CloudPFlowContext context = this.generatePFContext(resultVos); }
IBatchRunScriptService iReportApprove=((IBatchRunScriptService) NCLocator.getInstance().lookup(IBatchRunScriptService.class)); vo.setBVO(itemVOList.toArray(new ReportItemVO[0]));
}
}
IReportMaintain reportMaintain = NCLocator.getInstance().lookup(IReportMaintain.class);
try {
resultVos = reportMaintain.saveBase(vos, new Object(), updatevos);
} catch (BusinessException e) {
return ResultMessageUtil.exceptionToJSON(e);
}
} else {
for (ReportVO vo : vos) {
ReportHeaderVO hvo = vo.getHVO();
hvo.setVdef10(flag);
// 回传标识
String updateSql = "update scm_report_b set vdef10 = '" + flag + "' where pk_reportbill = '" + hvo.getPk_reportbill() + "'";
int num = dao.executeUpdate(updateSql);
}
resultVos = vos;
}
// 审批
String actionName = "SAVE";
if ("N".equals(flag)) {
actionName = "UNSAVE";
}
CloudPFlowContext context = this.generatePFContext(resultVos, actionName);
IBatchRunScriptService iReportApprove = NCLocator.getInstance().lookup(IBatchRunScriptService.class);
SCMScriptResultDTO obj = iReportApprove.runBacth(context, ReportVO.class); SCMScriptResultDTO obj = iReportApprove.runBacth(context, ReportVO.class);
//质检报告更新 // 质检报告更新
Map<String, Object> returnMap = new HashMap<String, Object>(); Map<String, Object> returnMap = new HashMap<>();
returnMap.put("data", resultVos); returnMap.put("data", resultVos);
returnMap.put("success", true); returnMap.put("success", true);
return ResultMessageUtil.toJSON(returnMap); return ResultMessageUtil.toJSON(returnMap);
} }
private void doSaveAndCombine(ReportVO[] billVos) {
CloudPFlowContext context = new CloudPFlowContext();
context.setBillType(QCBillType.ReportBill.getCode());
context.setTrantype(billVos[0].getHVO().getVtrantypecode());
context.setBillVos(billVos);
context.setActionName("SAVEBASE");
ICloudScriptPFlowService service = (ICloudScriptPFlowService) NCLocator.getInstance().lookup(ICloudScriptPFlowService.class);
ReportVO[] retVOs = null;
try {
Object ret = service.exeScriptPFlow(context);
if (ret instanceof ReportVO[]) {
retVOs = (ReportVO[]) ret;
} else {
retVOs = (ReportVO[]) ((Object[]) ret)[0];
}
} catch (Exception e) {
ExceptionUtils.wrapException(e);
}
if (!ArrayUtil.isEmpty(retVOs)) {
ClientBillCombinServer<ReportVO> util = new ClientBillCombinServer();
this.processDelBody(billVos);
util.combine(billVos, retVOs);
retVOs = ReportVOInfoUtils.synchBatchCodeData(billVos);
}
}
private void processDelBody(ReportVO[] vos) {
ReportItemVO[] bodys = vos[0].getBVO();
List<ReportItemVO> realbody = new ArrayList();
for(ReportItemVO body : bodys) {
if (body.getStatus() != 3) {
realbody.add(body);
}
}
vos[0].setBVO((ReportItemVO[]) CollectionUtils.listToArray(realbody));
}
private void appendPseudoColumn(ReportVO vo) { private void appendPseudoColumn(ReportVO vo) {
ReportItemVO[] bodyvos = vo.getBVO(); ReportItemVO[] bodyvos = vo.getBVO();
if (bodyvos != null && bodyvos.length > 0) { if (bodyvos != null && bodyvos.length > 0) {
for(int i = 0; i < bodyvos.length; ++i) { for (int i = 0; i < bodyvos.length; ++i) {
bodyvos[i].setAttributeValue("pseudocolumn", i); bodyvos[i].setAttributeValue("pseudocolumn", i);
} }
} }
} }
private CloudPFlowContext generatePFContext(ReportVO[] reports) {
private CloudPFlowContext generatePFContext(ReportVO[] reports, String actionName) {
CloudPFlowContext context = new CloudPFlowContext(); CloudPFlowContext context = new CloudPFlowContext();
context.setBillType(QCBillType.ReportBill.getCode()); context.setBillType(QCBillType.ReportBill.getCode());
context.setActionName("N_C003_APPROVE"); context.setActionName(actionName);
context.setBillVos(reports); context.setBillVos(reports);
return context; return context;
} }