备料重算或预留后推送高压MES-V1
This commit is contained in:
parent
9d71f6ab34
commit
6b1ba337ff
|
|
@ -0,0 +1,138 @@
|
||||||
|
//
|
||||||
|
// Source code recreated from a .class file by IntelliJ IDEA
|
||||||
|
// (powered by FernFlower decompiler)
|
||||||
|
//
|
||||||
|
|
||||||
|
package nccloud.web.mmpac.pickm.action;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import nc.util.mmf.framework.base.MMArrayUtil;
|
||||||
|
import nc.util.mmf.framework.base.MMMapUtil;
|
||||||
|
import nc.util.mmf.framework.base.MMValueCheck;
|
||||||
|
import nc.vo.mmpac.mo.param.MoQueryParam4Pickm;
|
||||||
|
import nc.vo.mmpac.pickm.consts.PickmLangConsts;
|
||||||
|
import nc.vo.mmpac.pickm.entity.AggPickmVO;
|
||||||
|
import nc.vo.mmpac.pickm.entity.PickmHeadVO;
|
||||||
|
import nc.vo.mmpac.pickm.entity.PickmItemVO;
|
||||||
|
import nc.vo.mmpac.pickm.enumeration.FsourcetypeEnum;
|
||||||
|
import nc.vo.pub.BusinessException;
|
||||||
|
import nc.vo.pub.lang.UFBoolean;
|
||||||
|
import nccloud.framework.core.exception.ExceptionUtils;
|
||||||
|
import nccloud.framework.core.util.GridCompareUtils;
|
||||||
|
import nccloud.framework.web.action.itf.ICommonAction;
|
||||||
|
import nccloud.framework.web.container.IRequest;
|
||||||
|
import nccloud.framework.web.ui.pattern.billcard.BillCard;
|
||||||
|
import nccloud.framework.web.ui.pattern.billcard.BillCardOperator;
|
||||||
|
import nccloud.web.mmpac.pickm.serviceproxy.PickmBusinessProxyNcc;
|
||||||
|
import nccloud.web.mmpac.pickm.serviceproxy.PickmMaterialInfoProxyNcc;
|
||||||
|
import nccloud.web.mmpac.pickm.serviceproxy.PickmQueryMOProxyNcc;
|
||||||
|
import nccloud.web.mmpac.pickm.serviceproxy.PickmQueryPscorderProxyNcc;
|
||||||
|
import nccloud.web.mmpac.pickm.util.PickmScaleUtil;
|
||||||
|
|
||||||
|
public class PickmSubItemAction implements ICommonAction {
|
||||||
|
public PickmSubItemAction() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object doAction(IRequest request) {
|
||||||
|
BillCard card = null;
|
||||||
|
BillCard oldCard = null;
|
||||||
|
BillCard returnCard = null;
|
||||||
|
BillCardOperator operator = new BillCardOperator();
|
||||||
|
|
||||||
|
try {
|
||||||
|
AggPickmVO vo = (AggPickmVO)operator.toBill(request);
|
||||||
|
oldCard = operator.toCard(vo);
|
||||||
|
this.afterProcess(oldCard);
|
||||||
|
this.validate(vo);
|
||||||
|
PickmBusinessProxyNcc proxy = new PickmBusinessProxyNcc();
|
||||||
|
AggPickmVO aggPickmVO = proxy.createSubPickmByMaterial(vo, false, false);
|
||||||
|
PickmItemVO[] pickmItemVOs = (PickmItemVO[])aggPickmVO.getChildrenVO();
|
||||||
|
if (MMArrayUtil.isEmpty(pickmItemVOs)) {
|
||||||
|
ExceptionUtils.wrapBusinessException(PickmLangConsts.getHIT_NOITEMS());
|
||||||
|
}
|
||||||
|
|
||||||
|
AggPickmVO newAggPickmVO = new AggPickmVO();
|
||||||
|
newAggPickmVO.setChildren(PickmItemVO.class, pickmItemVOs);
|
||||||
|
newAggPickmVO.setParentVO(aggPickmVO.getParentVO());
|
||||||
|
card = operator.toCard(newAggPickmVO);
|
||||||
|
this.afterProcess(card);
|
||||||
|
returnCard = GridCompareUtils.compareBillCardGrid(operator.getOriginBillcard(), card);
|
||||||
|
} catch (Exception e) {
|
||||||
|
ExceptionUtils.wrapException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnCard;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validate(AggPickmVO vo) {
|
||||||
|
if (!MMValueCheck.isEmpty(vo)) {
|
||||||
|
PickmHeadVO headVO = vo.getParentVO();
|
||||||
|
if (FsourcetypeEnum.PSCBILL_STATE.equalsValue(headVO.getFsourcetype())) {
|
||||||
|
if (MMValueCheck.isEmpty(headVO.getCmaterialvid()) || MMValueCheck.isEmpty(headVO.getNnumber()) || MMValueCheck.isEmpty(headVO.getNastnum())) {
|
||||||
|
ExceptionUtils.wrapBusinessException(PickmLangConsts.getHIT_DATANULLFORPSCMAKEITEM());
|
||||||
|
}
|
||||||
|
|
||||||
|
String moid = MMValueCheck.isEmpty(headVO.getCsourcebillrowid()) ? headVO.getCsourcebillid() : headVO.getCsourcebillrowid();
|
||||||
|
Map<String, UFBoolean> isPscOrderClose = PickmQueryPscorderProxyNcc.getPscOrderIsClosed(new String[]{moid});
|
||||||
|
if (MMMapUtil.isNotEmpty(isPscOrderClose) && isPscOrderClose.containsKey(headVO.getCsourcebillrowid()) && ((UFBoolean)isPscOrderClose.get(headVO.getCsourcebillrowid())).booleanValue()) {
|
||||||
|
ExceptionUtils.wrapBusinessException(PickmLangConsts.getErrPSCorderClosed());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (FsourcetypeEnum.MOBILL_STATE.equalsValue(headVO.getFsourcetype())) {
|
||||||
|
MoQueryParam4Pickm param = new MoQueryParam4Pickm();
|
||||||
|
param.setProdMode(headVO.getFprodmode());
|
||||||
|
String moid = MMValueCheck.isEmpty(headVO.getCsourcebillrowid()) ? headVO.getCsourcebillid() : headVO.getCsourcebillrowid();
|
||||||
|
param.setIds(new String[]{moid});
|
||||||
|
Map<String, UFBoolean> isMoFinishOrClose = PickmQueryMOProxyNcc.isMoCloseOrCompleteOrParComplete(new MoQueryParam4Pickm[]{param});
|
||||||
|
if (MMMapUtil.isNotEmpty(isMoFinishOrClose) && isMoFinishOrClose.containsKey(moid) && ((UFBoolean)isMoFinishOrClose.get(moid)).booleanValue()) {
|
||||||
|
ExceptionUtils.wrapBusinessException(PickmLangConsts.getHIT_FINISHORCLOSEMONOTMAKEITEM());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.checkDataForMakeItem(headVO)) {
|
||||||
|
ExceptionUtils.wrapBusinessException(PickmLangConsts.getHIT_DATANULLFORTMAKEITEM());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkDataForMakeItem(PickmHeadVO headVO) {
|
||||||
|
if (MMValueCheck.isEmpty(headVO.getCmaterialvid())) {
|
||||||
|
return false;
|
||||||
|
} else if (!MMValueCheck.isEmpty(headVO.getNnumber()) && !MMValueCheck.isEmpty(headVO.getNastnum())) {
|
||||||
|
if (FsourcetypeEnum.PSCBILL_STATE.equalsValue(headVO.getFsourcetype())) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
if (FsourcetypeEnum.MOBILL_STATE.equalsValue(headVO.getFsourcetype())) {
|
||||||
|
PickmMaterialInfoProxyNcc proxy = new PickmMaterialInfoProxyNcc();
|
||||||
|
Map<String, UFBoolean> map = new HashMap();
|
||||||
|
|
||||||
|
try {
|
||||||
|
map = proxy.isWorkprocemanage(new String[]{headVO.getCmaterialvid()}, headVO.getPk_org());
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
ExceptionUtils.wrapException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MMValueCheck.isNotEmpty(map) && map.containsKey(headVO.getCmaterialvid()) && ((UFBoolean)map.get(headVO.getCmaterialvid())).booleanValue()) {
|
||||||
|
if (MMValueCheck.isEmpty(headVO.getVrtversion())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return !MMValueCheck.isEmpty(headVO.getVbomversion()) || !MMValueCheck.isEmpty(headVO.getVpbomversion());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afterProcess(BillCard card) {
|
||||||
|
PickmScaleUtil stoUtil = new PickmScaleUtil();
|
||||||
|
stoUtil.processBillCard(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,39 +1,12 @@
|
||||||
package nc.bs.mmpac.pickm.bp.rule;
|
package nc.bs.mmpac.pickm.bp.rule;
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
||||||
import nc.bs.dao.BaseDAO;
|
|
||||||
import nc.bs.dao.DAOException;
|
|
||||||
import nc.bs.framework.common.NCLocator;
|
|
||||||
import nc.bs.logging.Log;
|
import nc.bs.logging.Log;
|
||||||
import nc.bs.trade.business.HYPubBO;
|
|
||||||
import nc.bs.trade.business.HYSuperDMO;
|
|
||||||
import nc.bs.uapbd.util.MyHelper;
|
|
||||||
import nc.bs.uapbd.util.ThirdPartyPostRequestUtil;
|
|
||||||
import nc.impl.pubapp.pattern.rule.IRule;
|
import nc.impl.pubapp.pattern.rule.IRule;
|
||||||
import nc.jdbc.framework.processor.ColumnProcessor;
|
|
||||||
import nc.jdbc.framework.processor.MapProcessor;
|
|
||||||
import nc.pubitf.uapbd.IMaterialPubService;
|
|
||||||
import nc.util.mmf.framework.base.MMValueCheck;
|
|
||||||
import nc.vo.bd.defdoc.DefdocVO;
|
|
||||||
import nc.vo.bd.material.plan.MaterialPlanVO;
|
|
||||||
import nc.vo.mmpac.pickm.entity.AggPickmVO;
|
import nc.vo.mmpac.pickm.entity.AggPickmVO;
|
||||||
import nc.vo.mmpac.pickm.entity.PickmHeadVO;
|
|
||||||
import nc.vo.mmpac.pickm.entity.PickmItemVO;
|
|
||||||
import nc.vo.org.OrgVO;
|
|
||||||
import nc.vo.pmpub.project.ProjectHeadVO;
|
|
||||||
import nc.vo.pub.BusinessException;
|
|
||||||
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
||||||
import nc.vo.scmpub.util.ArrayUtil;
|
import nc.vo.scmpub.util.ArrayUtil;
|
||||||
|
import nccloud.web.mmpac.pickm.service.SyncGyMesPickmUtil;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 备料修改后推送高压MES
|
* 备料修改后推送高压MES
|
||||||
|
|
@ -45,193 +18,19 @@ public class AfterQtyUpdRuleHighpressureMes implements IRule<AggPickmVO> {
|
||||||
|
|
||||||
private static final String LOG_INFO_NAME = "gymeslog";
|
private static final String LOG_INFO_NAME = "gymeslog";
|
||||||
private static final Log logger = Log.getInstance(LOG_INFO_NAME);
|
private static final Log logger = Log.getInstance(LOG_INFO_NAME);
|
||||||
private Map<String, String> configParams;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(AggPickmVO[] aggPickmVOS) {
|
public void process(AggPickmVO[] aggPickmVOS) {
|
||||||
if (ArrayUtil.isEmpty(aggPickmVOS)) {
|
if (ArrayUtil.isEmpty(aggPickmVOS)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
configParams = MyHelper.getConfigParams("gy-config", null);
|
|
||||||
try {
|
try {
|
||||||
buildSyncData(aggPickmVOS);
|
SyncGyMesPickmUtil pickmUtil = new SyncGyMesPickmUtil();
|
||||||
|
pickmUtil.process(aggPickmVOS);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("同步备料计划到高压MES系统失败: " + e.getMessage(), e);
|
logger.error("同步备料计划到高压MES系统失败: " + e.getMessage(), e);
|
||||||
ExceptionUtils.wrappException(e);
|
ExceptionUtils.wrappException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建同步数据
|
|
||||||
*/
|
|
||||||
private void buildSyncData(AggPickmVO[] useVOs) throws BusinessException {
|
|
||||||
BaseDAO baseDAO = new BaseDAO();
|
|
||||||
|
|
||||||
HYPubBO hybo = new HYPubBO();
|
|
||||||
JSONObject list = new JSONObject();
|
|
||||||
JSONArray jsonArray = new JSONArray();
|
|
||||||
for (AggPickmVO vo : useVOs) {
|
|
||||||
PickmHeadVO pickmHeadVO = vo.getParentVO();
|
|
||||||
PickmItemVO[] itemVOS = (PickmItemVO[]) vo.getChildrenVO();
|
|
||||||
// 判断物料的业务单元是否是高压公司,不是则跳过
|
|
||||||
String pkOrg = pickmHeadVO.getPk_org();
|
|
||||||
String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
|
|
||||||
if (checkIfOrg(orgCode, configParams)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
JSONObject singleObj = new JSONObject();
|
|
||||||
// 创建子项数组
|
|
||||||
JSONArray contentArray = new JSONArray();
|
|
||||||
|
|
||||||
singleObj.put("materialPreparationPlanNumber", pickmHeadVO.getVbillcode());// 备料计划单号
|
|
||||||
singleObj.put("bipId", pickmHeadVO.getCpickmid());// 主键ID
|
|
||||||
// 生产部门
|
|
||||||
String deptsql = " select code,name from org_dept where pk_dept='" + pickmHeadVO.getCdeptid() + "' and dr=0 ";
|
|
||||||
Map<String, Object> dept = (Map<String, Object>) baseDAO.executeQuery(deptsql, new MapProcessor());
|
|
||||||
singleObj.put("bipDeptName", dept.get("name")); // 生产部门
|
|
||||||
singleObj.put("bipDeptId", dept.get("code")); // 生产部门编码
|
|
||||||
|
|
||||||
singleObj.put("bipProcessProductionOrderId", pickmHeadVO.getVsourcemocode()); // 流程生产订单号
|
|
||||||
singleObj.put("bipProcessProductionOrderRowNum", pickmHeadVO.getVsourcemorowcode()); // 来源单据号行号
|
|
||||||
singleObj.put("bipParentProcessProductionOrderId", pickmHeadVO.getVfirstbillcode()); // 上级来源单据号
|
|
||||||
singleObj.put("bipParentProcessProductionOrderRowNum", pickmHeadVO.getVfirstbillrowno()); // 上级来源单据行号
|
|
||||||
singleObj.put("bipOriginProcessProductionOrderId", pickmHeadVO.getVsalebillcode()); // 顶级来源单据号
|
|
||||||
singleObj.put("bipOriginProcessProductionOrderRowNum", ""); // 顶级来源单据行号
|
|
||||||
singleObj.put("orderQuantity", pickmHeadVO.getNastnum() != null ? pickmHeadVO.getNastnum().doubleValue() : null); // 订单数量(计划数量)
|
|
||||||
singleObj.put("bomVersion", pickmHeadVO.getVbomversionnumber()); // bom版本
|
|
||||||
// 物料信息
|
|
||||||
String cpsql = "select code,name,graphid,pk_measdoc,materialtype from bd_material where pk_material = '" + pickmHeadVO.getCmaterialvid() + "' ";
|
|
||||||
Map<String, Object> mrl = (Map<String, Object>) baseDAO.executeQuery(cpsql, new MapProcessor());
|
|
||||||
singleObj.put("productCode", mrl.get("code")); // 产品编码
|
|
||||||
singleObj.put("productName", mrl.get("name")); // 产品名称
|
|
||||||
|
|
||||||
singleObj.put("processCode", "(物料的自定义字段)"); // 产品编码的工序(物料的自定义字段)
|
|
||||||
singleObj.put("requiredDate", pickmHeadVO.getDmakedate().toString()); // 需用日期
|
|
||||||
String sql1 = " select user_name from sm_user where cuserid = '" + pickmHeadVO.getModifier() + "' ";
|
|
||||||
String bipCreateBy = (String) baseDAO.executeQuery(sql1, new ColumnProcessor());
|
|
||||||
|
|
||||||
singleObj.put("bipUpdateBy", bipCreateBy); // 修改人ID
|
|
||||||
|
|
||||||
// 创建子项数组
|
|
||||||
for (PickmItemVO item : itemVOS) {
|
|
||||||
String cmaterialvid = item.getCbmaterialid();
|
|
||||||
Map<String, MaterialPlanVO> planMap = queryMaterialPlanInfoByPks(new String[]{cmaterialvid}, pkOrg,
|
|
||||||
new String[]{MaterialPlanVO.DEF1});
|
|
||||||
String drawingNumber = "";
|
|
||||||
if (MMValueCheck.isNotEmpty(planMap) &&
|
|
||||||
MMValueCheck.isNotEmpty(planMap.get(cmaterialvid))) {
|
|
||||||
drawingNumber = planMap.get(cmaterialvid).getDef1();
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject itemObj = new JSONObject();
|
|
||||||
|
|
||||||
itemObj.put("bipChildId", item.getCpickm_bid()); // 子项主键ID
|
|
||||||
itemObj.put("quantityPerSet", item.getNunituseastnum() != null ? item.getNunituseastnum().doubleValue() : null); // 单套数量(单位用量)
|
|
||||||
itemObj.put("reservedQuantity", item.getNatpastnum() != null ? item.getNatpastnum().doubleValue() : null); // 预留数量
|
|
||||||
itemObj.put("cumulativePendingQuantity", item.getNshouldastnum() != null ? item.getNshouldastnum().doubleValue() : null); // 累计待发数量
|
|
||||||
itemObj.put("cumulativeIssuedQuantity", item.getNaccoutastnum() != null ? item.getNaccoutastnum().doubleValue() : null); // 累计出库数量
|
|
||||||
itemObj.put("totalQuantity", item.getNplanoutnum() != null ? item.getNplanoutnum().doubleValue() : null); // 总数量(计划出库主数量)
|
|
||||||
|
|
||||||
// 物料信息
|
|
||||||
String mrlsql = "select code,name,graphid,pk_measdoc,materialtype from bd_material where pk_material = '" + item.getCbmaterialid() + "' ";
|
|
||||||
Map<String, Object> material = (Map<String, Object>) baseDAO.executeQuery(mrlsql, new MapProcessor());
|
|
||||||
itemObj.put("materialCode", material.get("code")); // 物料编码
|
|
||||||
itemObj.put("materialName", material.get("name")); // 物料名称
|
|
||||||
itemObj.put("drawingNumber", drawingNumber);
|
|
||||||
|
|
||||||
Object unit = hybo.findColValue("bd_measdoc", "code", " pk_measdoc = '" + material.get("pk_measdoc") + "' ");
|
|
||||||
itemObj.put("unit", unit); // 规格单位
|
|
||||||
// 生产信息
|
|
||||||
itemObj.put("intervalModel", material.get("materialtype")); // 产品类型
|
|
||||||
itemObj.put("lineNumber", String.valueOf(item.getVrowno())); // 行号
|
|
||||||
// 项目编码
|
|
||||||
String cprojectid = item.getCbprojectid();// 项目id
|
|
||||||
String projectCode = MyHelper.getStrValByCondition(ProjectHeadVO.getDefaultTableName(), ProjectHeadVO.PROJECT_CODE,
|
|
||||||
ProjectHeadVO.PK_PROJECT + " = '" + cprojectid + "'");
|
|
||||||
itemObj.put("cbprojectid", projectCode);
|
|
||||||
// 生产厂商
|
|
||||||
String productorCode = getDefCode("BD006_0xx", item.getCbproductorid());
|
|
||||||
itemObj.put("cbproductorid", productorCode);
|
|
||||||
|
|
||||||
contentArray.add(itemObj); // 将子项添加到数组
|
|
||||||
}
|
|
||||||
singleObj.put("itemList", contentArray); // 将子项数组添加到主对象
|
|
||||||
jsonArray.add(singleObj);
|
|
||||||
list.put("list", jsonArray);
|
|
||||||
}
|
|
||||||
if (!list.isEmpty()) {
|
|
||||||
pushData(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取自定义项信息
|
|
||||||
*/
|
|
||||||
private String getDefCode(String code, String pk_defdoc) {
|
|
||||||
String res = "";
|
|
||||||
String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='" + code + "' and dr=0 ) and dr = 0 and pk_defdoc = '" + pk_defdoc + "'";
|
|
||||||
try {
|
|
||||||
DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere);
|
|
||||||
if (defdocVOs != null && defdocVOs.length > 0) {
|
|
||||||
res = defdocVOs[0].getCode().trim();
|
|
||||||
}
|
|
||||||
} catch (DAOException e) {
|
|
||||||
logger.error("gyMes-SaleOrder-error,getDefCode[" + e.getMessage() + "]");
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 推送同步数据
|
|
||||||
*/
|
|
||||||
private void pushData(JSONObject param) throws BusinessException {
|
|
||||||
// 转json字符串的时候保留null值
|
|
||||||
String jsonStr = JSON.toJSONString(param,
|
|
||||||
SerializerFeature.WriteMapNullValue,
|
|
||||||
SerializerFeature.WriteNullStringAsEmpty
|
|
||||||
);
|
|
||||||
logger.error("gyMes-Pickm-param = " + jsonStr);
|
|
||||||
String baseUrl = configParams.get("mesBaseUrl");
|
|
||||||
String requestUrl = baseUrl + configParams.get("materialRequirementsUpdate");
|
|
||||||
logger.error("gyMes-Pickm-url = " + requestUrl);
|
|
||||||
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr);
|
|
||||||
JSONObject resultObj = JSONObject.parseObject(result);
|
|
||||||
logger.error("gyMes-Pickm-res = " + result);
|
|
||||||
|
|
||||||
if (!"200".equals(resultObj.getString("code"))) {
|
|
||||||
logger.error("gyMes-Pickm-error,result[" + resultObj.toJSONString() + "]");
|
|
||||||
throw new BusinessException("备料计划推送高压MES错误:" + resultObj.getString("msg"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException {
|
|
||||||
String targetCode = configParams.get("gyOrg");
|
|
||||||
if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) {
|
|
||||||
throw new BusinessException("未配置组织参数");
|
|
||||||
}
|
|
||||||
String[] orgItem = targetCode.split(",");
|
|
||||||
for (String orgCode : orgItem) {
|
|
||||||
if (!orgCode.isEmpty() && orgCode.equals(code)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String, MaterialPlanVO> queryMaterialPlanInfoByPks(String[] pks, String pk_stockorg,
|
|
||||||
String[] fields) throws BusinessException {
|
|
||||||
Map<String, MaterialPlanVO> map = null;
|
|
||||||
List<String> vids = Stream.of(pks).filter(Objects::nonNull).distinct().toList();
|
|
||||||
if (vids.isEmpty()) {
|
|
||||||
map = new HashMap<>();
|
|
||||||
} else {
|
|
||||||
map = NCLocator.getInstance().lookup(IMaterialPubService.class)
|
|
||||||
.queryMaterialPlanInfoByPks(vids.toArray(new String[0]), pk_stockorg, fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,229 @@
|
||||||
|
package nccloud.web.mmpac.pickm.service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||||
|
import nc.bs.dao.BaseDAO;
|
||||||
|
import nc.bs.dao.DAOException;
|
||||||
|
import nc.bs.framework.common.NCLocator;
|
||||||
|
import nc.bs.logging.Log;
|
||||||
|
import nc.bs.trade.business.HYPubBO;
|
||||||
|
import nc.bs.trade.business.HYSuperDMO;
|
||||||
|
import nc.bs.uapbd.util.MyHelper;
|
||||||
|
import nc.bs.uapbd.util.ThirdPartyPostRequestUtil;
|
||||||
|
import nc.jdbc.framework.processor.ColumnProcessor;
|
||||||
|
import nc.jdbc.framework.processor.MapProcessor;
|
||||||
|
import nc.pubitf.uapbd.IMaterialPubService;
|
||||||
|
import nc.util.mmf.framework.base.MMValueCheck;
|
||||||
|
import nc.vo.bd.defdoc.DefdocVO;
|
||||||
|
import nc.vo.bd.material.plan.MaterialPlanVO;
|
||||||
|
import nc.vo.mmpac.pickm.entity.AggPickmVO;
|
||||||
|
import nc.vo.mmpac.pickm.entity.PickmHeadVO;
|
||||||
|
import nc.vo.mmpac.pickm.entity.PickmItemVO;
|
||||||
|
import nc.vo.org.OrgVO;
|
||||||
|
import nc.vo.pmpub.project.ProjectHeadVO;
|
||||||
|
import nc.vo.pub.BusinessException;
|
||||||
|
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
||||||
|
import nc.vo.scmpub.util.ArrayUtil;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 备料重算或预留后推送高压MES
|
||||||
|
*/
|
||||||
|
public class SyncGyMesPickmUtil {
|
||||||
|
private static final String LOG_INFO_NAME = "gymeslog";
|
||||||
|
private static final Log logger = Log.getInstance(LOG_INFO_NAME);
|
||||||
|
private Map<String, String> configParams;
|
||||||
|
|
||||||
|
public void process(AggPickmVO[] aggPickmVOS) {
|
||||||
|
if (ArrayUtil.isEmpty(aggPickmVOS)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
configParams = MyHelper.getConfigParams("gy-config", null);
|
||||||
|
try {
|
||||||
|
buildSyncData(aggPickmVOS);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("同步备料计划到高压MES系统失败: " + e.getMessage(), e);
|
||||||
|
ExceptionUtils.wrappException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建同步数据
|
||||||
|
*/
|
||||||
|
private void buildSyncData(AggPickmVO[] useVOs) throws BusinessException {
|
||||||
|
BaseDAO baseDAO = new BaseDAO();
|
||||||
|
|
||||||
|
HYPubBO hybo = new HYPubBO();
|
||||||
|
JSONObject list = new JSONObject();
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
for (AggPickmVO vo : useVOs) {
|
||||||
|
PickmHeadVO pickmHeadVO = vo.getParentVO();
|
||||||
|
PickmItemVO[] itemVOS = (PickmItemVO[]) vo.getChildrenVO();
|
||||||
|
// 判断物料的业务单元是否是高压公司,不是则跳过
|
||||||
|
String pkOrg = pickmHeadVO.getPk_org();
|
||||||
|
String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
|
||||||
|
if (checkIfOrg(orgCode, configParams)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JSONObject singleObj = new JSONObject();
|
||||||
|
// 创建子项数组
|
||||||
|
JSONArray contentArray = new JSONArray();
|
||||||
|
|
||||||
|
singleObj.put("materialPreparationPlanNumber", pickmHeadVO.getVbillcode());// 备料计划单号
|
||||||
|
singleObj.put("bipId", pickmHeadVO.getCpickmid());// 主键ID
|
||||||
|
// 生产部门
|
||||||
|
String deptsql = " select code,name from org_dept where pk_dept='" + pickmHeadVO.getCdeptid() + "' and dr=0 ";
|
||||||
|
Map<String, Object> dept = (Map<String, Object>) baseDAO.executeQuery(deptsql, new MapProcessor());
|
||||||
|
singleObj.put("bipDeptName", dept.get("name")); // 生产部门
|
||||||
|
singleObj.put("bipDeptId", dept.get("code")); // 生产部门编码
|
||||||
|
|
||||||
|
singleObj.put("bipProcessProductionOrderId", pickmHeadVO.getVsourcemocode()); // 流程生产订单号
|
||||||
|
singleObj.put("bipProcessProductionOrderRowNum", pickmHeadVO.getVsourcemorowcode()); // 来源单据号行号
|
||||||
|
singleObj.put("bipParentProcessProductionOrderId", pickmHeadVO.getVfirstbillcode()); // 上级来源单据号
|
||||||
|
singleObj.put("bipParentProcessProductionOrderRowNum", pickmHeadVO.getVfirstbillrowno()); // 上级来源单据行号
|
||||||
|
singleObj.put("bipOriginProcessProductionOrderId", pickmHeadVO.getVsalebillcode()); // 顶级来源单据号
|
||||||
|
singleObj.put("bipOriginProcessProductionOrderRowNum", ""); // 顶级来源单据行号
|
||||||
|
singleObj.put("orderQuantity", pickmHeadVO.getNastnum() != null ? pickmHeadVO.getNastnum().doubleValue() : null); // 订单数量(计划数量)
|
||||||
|
singleObj.put("bomVersion", pickmHeadVO.getVbomversionnumber()); // bom版本
|
||||||
|
// 物料信息
|
||||||
|
String cpsql = "select code,name,graphid,pk_measdoc,materialtype from bd_material where pk_material = '" + pickmHeadVO.getCmaterialvid() + "' ";
|
||||||
|
Map<String, Object> mrl = (Map<String, Object>) baseDAO.executeQuery(cpsql, new MapProcessor());
|
||||||
|
singleObj.put("productCode", mrl.get("code")); // 产品编码
|
||||||
|
singleObj.put("productName", mrl.get("name")); // 产品名称
|
||||||
|
|
||||||
|
singleObj.put("processCode", "(物料的自定义字段)"); // 产品编码的工序(物料的自定义字段)
|
||||||
|
singleObj.put("requiredDate", pickmHeadVO.getDmakedate().toString()); // 需用日期
|
||||||
|
String sql1 = " select user_name from sm_user where cuserid = '" + pickmHeadVO.getModifier() + "' ";
|
||||||
|
String bipCreateBy = (String) baseDAO.executeQuery(sql1, new ColumnProcessor());
|
||||||
|
|
||||||
|
singleObj.put("bipUpdateBy", bipCreateBy); // 修改人ID
|
||||||
|
|
||||||
|
// 创建子项数组
|
||||||
|
for (PickmItemVO item : itemVOS) {
|
||||||
|
String cmaterialvid = item.getCbmaterialid();
|
||||||
|
Map<String, MaterialPlanVO> planMap = queryMaterialPlanInfoByPks(new String[]{cmaterialvid}, pkOrg,
|
||||||
|
new String[]{MaterialPlanVO.DEF1});
|
||||||
|
String drawingNumber = "";
|
||||||
|
if (MMValueCheck.isNotEmpty(planMap) &&
|
||||||
|
MMValueCheck.isNotEmpty(planMap.get(cmaterialvid))) {
|
||||||
|
drawingNumber = planMap.get(cmaterialvid).getDef1();
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject itemObj = new JSONObject();
|
||||||
|
|
||||||
|
itemObj.put("bipChildId", item.getCpickm_bid()); // 子项主键ID
|
||||||
|
itemObj.put("quantityPerSet", item.getNunituseastnum() != null ? item.getNunituseastnum().doubleValue() : null); // 单套数量(单位用量)
|
||||||
|
itemObj.put("reservedQuantity", item.getNatpastnum() != null ? item.getNatpastnum().doubleValue() : null); // 预留数量
|
||||||
|
itemObj.put("cumulativePendingQuantity", item.getNshouldastnum() != null ? item.getNshouldastnum().doubleValue() : null); // 累计待发数量
|
||||||
|
itemObj.put("cumulativeIssuedQuantity", item.getNaccoutastnum() != null ? item.getNaccoutastnum().doubleValue() : null); // 累计出库数量
|
||||||
|
itemObj.put("totalQuantity", item.getNplanoutnum() != null ? item.getNplanoutnum().doubleValue() : null); // 总数量(计划出库主数量)
|
||||||
|
|
||||||
|
// 物料信息
|
||||||
|
String mrlsql = "select code,name,graphid,pk_measdoc,materialtype from bd_material where pk_material = '" + item.getCbmaterialid() + "' ";
|
||||||
|
Map<String, Object> material = (Map<String, Object>) baseDAO.executeQuery(mrlsql, new MapProcessor());
|
||||||
|
itemObj.put("materialCode", material.get("code")); // 物料编码
|
||||||
|
itemObj.put("materialName", material.get("name")); // 物料名称
|
||||||
|
itemObj.put("drawingNumber", drawingNumber);
|
||||||
|
|
||||||
|
Object unit = hybo.findColValue("bd_measdoc", "code", " pk_measdoc = '" + material.get("pk_measdoc") + "' ");
|
||||||
|
itemObj.put("unit", unit); // 规格单位
|
||||||
|
// 生产信息
|
||||||
|
itemObj.put("intervalModel", material.get("materialtype")); // 产品类型
|
||||||
|
itemObj.put("lineNumber", String.valueOf(item.getVrowno())); // 行号
|
||||||
|
// 项目编码
|
||||||
|
String cprojectid = item.getCbprojectid();// 项目id
|
||||||
|
String projectCode = MyHelper.getStrValByCondition(ProjectHeadVO.getDefaultTableName(), ProjectHeadVO.PROJECT_CODE,
|
||||||
|
ProjectHeadVO.PK_PROJECT + " = '" + cprojectid + "'");
|
||||||
|
itemObj.put("cbprojectid", projectCode);
|
||||||
|
// 生产厂商
|
||||||
|
String productorCode = getDefCode("BD006_0xx", item.getCbproductorid());
|
||||||
|
itemObj.put("cbproductorid", productorCode);
|
||||||
|
|
||||||
|
contentArray.add(itemObj); // 将子项添加到数组
|
||||||
|
}
|
||||||
|
singleObj.put("itemList", contentArray); // 将子项数组添加到主对象
|
||||||
|
jsonArray.add(singleObj);
|
||||||
|
list.put("list", jsonArray);
|
||||||
|
}
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
pushData(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取自定义项信息
|
||||||
|
*/
|
||||||
|
private String getDefCode(String code, String pk_defdoc) {
|
||||||
|
String res = "";
|
||||||
|
String strWhere = " pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code='" + code + "' and dr=0 ) and dr = 0 and pk_defdoc = '" + pk_defdoc + "'";
|
||||||
|
try {
|
||||||
|
DefdocVO[] defdocVOs = (DefdocVO[]) new HYSuperDMO().queryByWhereClause(DefdocVO.class, strWhere);
|
||||||
|
if (defdocVOs != null && defdocVOs.length > 0) {
|
||||||
|
res = defdocVOs[0].getCode().trim();
|
||||||
|
}
|
||||||
|
} catch (DAOException e) {
|
||||||
|
logger.error("gyMes-SaleOrder-error,getDefCode[" + e.getMessage() + "]");
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推送同步数据
|
||||||
|
*/
|
||||||
|
private void pushData(JSONObject param) throws BusinessException {
|
||||||
|
// 转json字符串的时候保留null值
|
||||||
|
String jsonStr = JSON.toJSONString(param,
|
||||||
|
SerializerFeature.WriteMapNullValue,
|
||||||
|
SerializerFeature.WriteNullStringAsEmpty
|
||||||
|
);
|
||||||
|
logger.error("gyMes-Pickm-param = " + jsonStr);
|
||||||
|
String baseUrl = configParams.get("mesBaseUrl");
|
||||||
|
String requestUrl = baseUrl + configParams.get("materialRequirementsUpdate");
|
||||||
|
logger.error("gyMes-Pickm-url = " + requestUrl);
|
||||||
|
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr);
|
||||||
|
JSONObject resultObj = JSONObject.parseObject(result);
|
||||||
|
logger.error("gyMes-Pickm-res = " + result);
|
||||||
|
|
||||||
|
if (!"200".equals(resultObj.getString("code"))) {
|
||||||
|
logger.error("gyMes-Pickm-error,result[" + resultObj.toJSONString() + "]");
|
||||||
|
throw new BusinessException("备料计划推送高压MES错误:" + resultObj.getString("msg"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException {
|
||||||
|
String targetCode = configParams.get("gyOrg");
|
||||||
|
if (targetCode == null || nc.vo.am.common.util.StringUtils.isEmpty(targetCode)) {
|
||||||
|
throw new BusinessException("未配置组织参数");
|
||||||
|
}
|
||||||
|
String[] orgItem = targetCode.split(",");
|
||||||
|
for (String orgCode : orgItem) {
|
||||||
|
if (!orgCode.isEmpty() && orgCode.equals(code)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, MaterialPlanVO> queryMaterialPlanInfoByPks(String[] pks, String pk_stockorg,
|
||||||
|
String[] fields) throws BusinessException {
|
||||||
|
Map<String, MaterialPlanVO> map = null;
|
||||||
|
List<String> vids = Stream.of(pks).filter(Objects::nonNull).distinct().toList();
|
||||||
|
if (vids.isEmpty()) {
|
||||||
|
map = new HashMap<>();
|
||||||
|
} else {
|
||||||
|
map = NCLocator.getInstance().lookup(IMaterialPubService.class)
|
||||||
|
.queryMaterialPlanInfoByPks(vids.toArray(new String[0]), pk_stockorg, fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue