152 lines
6.5 KiB
Java
152 lines
6.5 KiB
Java
package nc.bs.sc.m61.referred.rule.pm;
|
||
|
||
|
||
import com.alibaba.fastjson.JSONArray;
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import nc.bs.dao.BaseDAO;
|
||
import nc.bs.logging.Log;
|
||
import nc.bs.uapbd.util.ThirdPartyPostRequestUtil;
|
||
import nc.impl.pubapp.pattern.rule.IRule;
|
||
import nc.jdbc.framework.processor.ColumnProcessor;
|
||
import nc.pubitf.para.SysInitQuery;
|
||
import nc.vo.bd.material.MaterialVO;
|
||
import nc.vo.bd.psn.PsndocVO;
|
||
import nc.vo.bd.stordoc.StordocVO;
|
||
import nc.vo.bd.supplier.SupplierVO;
|
||
import nc.vo.cmp.util.StringUtils;
|
||
import nc.vo.org.OrgVO;
|
||
import nc.vo.pub.BusinessException;
|
||
import nc.vo.pub.lang.UFDouble;
|
||
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
||
import nc.vo.pubapp.pattern.pub.SqlBuilder;
|
||
import nc.vo.sc.m61.entity.SCOrderHeaderVO;
|
||
import nc.vo.sc.m61.entity.SCOrderItemVO;
|
||
import nc.vo.sc.m61.entity.SCOrderVO;
|
||
import nc.vo.scmpub.util.ArrayUtil;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
|
||
public class AfterApproceRuleSyncRZWMSProcess implements IRule<SCOrderVO> {
|
||
|
||
private static Log log = Log.getInstance("rzmomlog");
|
||
|
||
private static BaseDAO dao = new BaseDAO();
|
||
|
||
@Override
|
||
public void process(SCOrderVO[] vos) {
|
||
if (ArrayUtil.isEmpty(vos)) {
|
||
return;
|
||
}
|
||
try {
|
||
//检查并筛选销售出库单据为互感器公司
|
||
List<SCOrderVO> newSCOrderVOS = checkAndFilterBillSrcOrg(vos);
|
||
if (newSCOrderVOS == null || newSCOrderVOS.size() < 1) {
|
||
return;
|
||
}
|
||
pushToRZMOM(newSCOrderVOS.toArray(new SCOrderVO[0]));
|
||
} catch (Exception e) {
|
||
ExceptionUtils.wrappException(e);
|
||
}
|
||
}
|
||
|
||
private void buildSyncData(SCOrderHeaderVO head, SCOrderItemVO[] bodys, JSONArray details) throws BusinessException {
|
||
|
||
for (SCOrderItemVO body : bodys) {
|
||
JSONObject singleObj = new JSONObject();
|
||
//操作状态 1新增/修改、2删除(删除时只需上传wbid)
|
||
singleObj.put("operate", 1);
|
||
// 单据类型
|
||
singleObj.put("cgjh_wbid", body.getVsrctrantype()); // 第三方系统采购计划id
|
||
singleObj.put("cgxh", body.getVsrcrowno()); // 采购计划序号
|
||
singleObj.put("cgbh", body.getVsrccode()); // 采购计划编号
|
||
singleObj.put("bzsm", body.getVbmemo()); // 备注说明
|
||
singleObj.put("cght_wbid", head.getVbillcode()); // 第三方系统合同ID
|
||
singleObj.put("htxsbh", head.getVbillcode()); // 合同编号
|
||
// 供应商
|
||
singleObj.put("zbxx_gycs_wbid", transferCodeByPk(SupplierVO.getDefaultTableName(), SupplierVO.CODE, SupplierVO.PK_SUPPLIER, head.getPk_supplier())); // 第三方系统厂商id
|
||
// 仓库
|
||
singleObj.put("sdck", transferCodeByPk(StordocVO.getDefaultTableName(), StordocVO.CODE, StordocVO.PK_STORDOC, body.getPk_recvstordoc())); // 送达仓库
|
||
// 物料
|
||
singleObj.put("wlbm_wbid", transferCodeByPk(MaterialVO.getDefaultTableName(), MaterialVO.CODE, MaterialVO.PK_MATERIAL, body.getPk_material())); // 第三方系统材料id
|
||
|
||
UFDouble nqtunitnum = body.getNqtunitnum() == null ? UFDouble.ZERO_DBL : body.getNqtunitnum();
|
||
singleObj.put("cgsl", nqtunitnum.getDouble()); // 采购数量
|
||
if (body.getDplanarrvdate() != null) {
|
||
singleObj.put("jhrq", body.getDplanarrvdate().toString()); // 交货日期
|
||
}
|
||
if (head.getDbilldate() != null) {
|
||
singleObj.put("zbxx_cgrq", head.getDbilldate().toString()); // 采购日期
|
||
}
|
||
if (head.getDbilldate() != null) {
|
||
singleObj.put("cgrq", head.getDbilldate().toString()); // 采购日期
|
||
}
|
||
|
||
singleObj.put("htxh", body.getCrowno()); // 合同序号
|
||
singleObj.put("zbxx_cgy_wbid", transferCodeByPk(PsndocVO.getDefaultTableName(), PsndocVO.CODE, PsndocVO.PK_PSNDOC, head.getCemployeeid())); // 第三方系统采购员id
|
||
|
||
|
||
details.add(singleObj);
|
||
}
|
||
}
|
||
|
||
private List<SCOrderVO> checkAndFilterBillSrcOrg(SCOrderVO[] SCOrderVOS) throws BusinessException {
|
||
List<SCOrderVO> aggvoList = new ArrayList<>();
|
||
for (SCOrderVO aggvo : SCOrderVOS) {
|
||
String pkOrg = aggvo.getParentVO().getPk_org();
|
||
Integer fstatusflag = aggvo.getParentVO().getFstatusflag();
|
||
String orgCode = transferCodeByPk(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
|
||
if ("30401".equals(orgCode) && 3 == fstatusflag) {
|
||
aggvoList.add(aggvo);
|
||
}
|
||
}
|
||
return aggvoList;
|
||
}
|
||
|
||
private void pushToRZMOM(SCOrderVO[] SCOrderVOS) throws BusinessException {
|
||
String rzwmsip = SysInitQuery.getParaString("GLOBLE00000000000000", "RZWMSIP");
|
||
JSONObject jsonObject = new JSONObject();
|
||
JSONObject data = new JSONObject();
|
||
JSONObject dataIn = new JSONObject();
|
||
JSONObject dataIn2 = new JSONObject();
|
||
JSONArray details = new JSONArray();
|
||
jsonObject.put("dataflow", "泰开BIP→RZMOMv6");
|
||
jsonObject.put("actionCode", "cpfhtzdb");
|
||
//单笔/批量按明细传
|
||
for (SCOrderVO SCOrderVO : SCOrderVOS) {
|
||
SCOrderHeaderVO head = SCOrderVO.getParentVO();
|
||
SCOrderItemVO[] bodys = SCOrderVO.getChildrenVO();
|
||
// 构建需要同步的数据
|
||
buildSyncData(head, bodys, details);
|
||
}
|
||
dataIn2.put("Details", details);
|
||
dataIn.put("Data", dataIn2);
|
||
data.put("data", dataIn);
|
||
jsonObject.put("data", data);
|
||
log.error("委外订单推送锐制请求报文:" + jsonObject.toJSONString());
|
||
String result = ThirdPartyPostRequestUtil.sendPostRequest(rzwmsip, jsonObject.toJSONString());
|
||
JSONObject resultObj = JSONObject.parseObject(result);
|
||
if ("false".equals(resultObj.getString("success"))) {
|
||
throw new BusinessException("RZMOM同步失败,原因:" + resultObj.getString("msg"));
|
||
}
|
||
}
|
||
|
||
private String transferCodeByPk(String tableName, String selectField, String pkField, String pk) throws BusinessException {
|
||
if (StringUtils.isEmpty(pk)) {
|
||
return null;
|
||
}
|
||
SqlBuilder sqlBuilder = new SqlBuilder();
|
||
sqlBuilder.append(" select " + selectField);
|
||
sqlBuilder.append(" from " + tableName);
|
||
sqlBuilder.append(" where ");
|
||
sqlBuilder.append(pkField, pk);
|
||
Object o = dao.executeQuery(sqlBuilder.toString(), new ColumnProcessor());
|
||
if (o == null) {
|
||
throw new BusinessException("未查询到编码信息,sql【" + sqlBuilder + "】");
|
||
}
|
||
return o.toString();
|
||
}
|
||
|
||
|
||
}
|