箱变-启源-质检报告回传接口-增加审批收回逻辑、增行逻辑、回传标识、调整子表字段
This commit is contained in:
parent
832e648ee9
commit
91928b4a6f
|
|
@ -1,29 +1,23 @@
|
|||
package nc.api.qc.resource;
|
||||
|
||||
import nc.bs.dao.BaseDAO;
|
||||
import nc.bs.framework.common.InvocationInfoProxy;
|
||||
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.jdbc.framework.processor.ColumnProcessor;
|
||||
import nc.vo.pub.BusinessException;
|
||||
import nc.vo.pub.VOStatus;
|
||||
import nc.vo.pub.lang.UFBoolean;
|
||||
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.ReportVO;
|
||||
import nc.vo.qc.c003.util.ReportVOInfoUtils;
|
||||
import nc.vo.scmpub.res.billtype.QCBillType;
|
||||
import nc.vo.scmpub.util.ArrayUtil;
|
||||
import nc.vo.scmpub.util.CollectionUtils;
|
||||
import nc.vo.util.CloneUtil;
|
||||
import nccloud.api.rest.utils.NCCRestUtils;
|
||||
import nccloud.api.rest.utils.ResultMessageUtil;
|
||||
import nccloud.base.exception.ExceptionUtils;
|
||||
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.ICloudScriptPFlowService;
|
||||
import nccloud.pubitf.scmpub.commit.service.IBatchRunScriptService;
|
||||
import nccloud.pubitf.scmpub.pub.service.ISCMPubQueryService;
|
||||
import org.json.JSONString;
|
||||
|
|
@ -32,10 +26,7 @@ import javax.ws.rs.Consumes;
|
|||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* QMS将检验结果回传至ERP质检报告中
|
||||
|
|
@ -43,14 +34,7 @@ import java.util.Map;
|
|||
@Path("qc/qcconclusion")
|
||||
public class QcconclusionRestResource extends QcBaseRestResource {
|
||||
|
||||
HYSuperDMO dmo = null;
|
||||
|
||||
public HYSuperDMO getSuperDMO() {
|
||||
if (dmo == null) {
|
||||
dmo = new HYSuperDMO();
|
||||
}
|
||||
return dmo;
|
||||
}
|
||||
private static BaseDAO dao = new BaseDAO();
|
||||
|
||||
/**
|
||||
* QMS将检验结果回传至ERP质检报告中
|
||||
|
|
@ -68,14 +52,23 @@ public class QcconclusionRestResource extends QcBaseRestResource {
|
|||
NCCRestUtils.initInvocationInfo();
|
||||
String json = str.toJSONString();
|
||||
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<String> list=new ArrayList<String>();
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Map<String, Object> itemMap : itemMaps) {
|
||||
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. 创建新数组(长度与原数组一致)
|
||||
ReportVO[] updatevos = new ReportVO[vos.length];
|
||||
|
||||
|
|
@ -88,10 +81,11 @@ public class QcconclusionRestResource extends QcBaseRestResource {
|
|||
}
|
||||
for (ReportVO vo : vos) {
|
||||
// 先判断vo和其HVO是否为null(避免NPE)
|
||||
if (vo == null || vo.getHVO() == null) {
|
||||
ReportHeaderVO hvo = vo.getHVO();
|
||||
if (vo == null || hvo == null) {
|
||||
continue;
|
||||
}
|
||||
Object pkReportbill = vo.getHVO().getPk_reportbill();
|
||||
String pkReportbill = (String) hvo.getPk_reportbill();
|
||||
// 校验HVO的pk_reportbill是否为必填(不为null)
|
||||
if (pkReportbill == null) {
|
||||
continue;
|
||||
|
|
@ -108,32 +102,33 @@ public class QcconclusionRestResource extends QcBaseRestResource {
|
|||
}
|
||||
|
||||
// 匹配成功,更新状态
|
||||
vo.getHVO().setStatus(VOStatus.UPDATED);
|
||||
hvo.setStatus(VOStatus.UPDATED);
|
||||
hvo.setVdef10(flag);// 回传标识
|
||||
|
||||
// 处理数量字段(存在且不为null才赋值)
|
||||
// 检验主数量
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
vo.getHVO().setNuneligiastnum(new UFDouble((Double) itemMap.get("nuneligiastnum")));
|
||||
hvo.setNuneligiastnum(new UFDouble((Double) itemMap.get("nuneligiastnum")));
|
||||
}
|
||||
|
||||
this.appendPseudoColumn(vo);
|
||||
|
|
@ -153,7 +148,7 @@ public class QcconclusionRestResource extends QcBaseRestResource {
|
|||
if (bvos == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<Map<String, Object>> newList = new ArrayList<>();
|
||||
for (int i = 0; i < bvos.length; i++) {
|
||||
ReportItemVO bvo = bvos[i];
|
||||
// 跳过null的BVO
|
||||
|
|
@ -168,9 +163,11 @@ public class QcconclusionRestResource extends QcBaseRestResource {
|
|||
|
||||
for (Map<String, Object> childMap : mapList) {
|
||||
// 校验childMap的reportbill_b是否为必填(存在且不为null)
|
||||
if (childMap == null || !childMap.containsKey("reportbill_b") || childMap.get("reportbill_b") == null) {
|
||||
continue;
|
||||
}
|
||||
if (childMap == null || !childMap.containsKey("reportbill_b") || childMap.get("reportbill_b") == null || "".equals(childMap.get("reportbill_b"))) {
|
||||
// 走新增逻辑
|
||||
newList.add(childMap);
|
||||
} else {
|
||||
// 走修改逻辑
|
||||
// 比较reportbill_b是否匹配
|
||||
if (!bvoCrowno.equals(childMap.get("reportbill_b"))) {
|
||||
continue;
|
||||
|
|
@ -180,72 +177,102 @@ public class QcconclusionRestResource extends QcBaseRestResource {
|
|||
bvo.setStatus(VOStatus.UPDATED);
|
||||
// 子项数量
|
||||
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) {
|
||||
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);
|
||||
IReportMaintain reportMaintain=((IReportMaintain) NCLocator.getInstance().lookup(IReportMaintain.class));
|
||||
ReportVO[] resultVos= reportMaintain.saveBase(vos,new Object(),updatevos);
|
||||
// IReportApprove iReportApprove=((IReportApprove) NCLocator.getInstance().lookup(IReportApprove.class));
|
||||
// iReportApprove.approveReport(resultVos,);
|
||||
List<ReportItemVO> itemVOList = new ArrayList<>(Arrays.asList(bvos));
|
||||
if (!newList.isEmpty()) {
|
||||
ReportItemVO bvo1 = bvos[0];
|
||||
for (Map<String, Object> childMap : newList) {
|
||||
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);
|
||||
|
||||
// 质检报告更新
|
||||
Map<String, Object> returnMap = new HashMap<String, Object>();
|
||||
Map<String, Object> returnMap = new HashMap<>();
|
||||
returnMap.put("data", resultVos);
|
||||
returnMap.put("success", true);
|
||||
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) {
|
||||
ReportItemVO[] bodyvos = vo.getBVO();
|
||||
if (bodyvos != null && bodyvos.length > 0) {
|
||||
|
|
@ -255,10 +282,11 @@ public class QcconclusionRestResource extends QcBaseRestResource {
|
|||
}
|
||||
|
||||
}
|
||||
private CloudPFlowContext generatePFContext(ReportVO[] reports) {
|
||||
|
||||
private CloudPFlowContext generatePFContext(ReportVO[] reports, String actionName) {
|
||||
CloudPFlowContext context = new CloudPFlowContext();
|
||||
context.setBillType(QCBillType.ReportBill.getCode());
|
||||
context.setActionName("N_C003_APPROVE");
|
||||
context.setActionName(actionName);
|
||||
context.setBillVos(reports);
|
||||
return context;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue