高压IMS同步优化

This commit is contained in:
mzr 2025-11-05 19:27:02 +08:00
parent 596e3d74bf
commit 7b681a606e
2 changed files with 107 additions and 99 deletions

View File

@ -10,6 +10,7 @@ import nc.bs.pub.taskcenter.BgWorkingContext;
import nc.bs.pub.taskcenter.IBackgroundWorkPlugin;
import nc.bs.uapbd.util.ImsDaoUtil;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.jdbc.framework.processor.MapProcessor;
import nc.vo.fi.pub.SqlUtils;
import nc.vo.ic.m45.entity.PurchaseInVO;
import nc.vo.pub.BusinessException;
@ -102,9 +103,13 @@ public class ErpIaI2billFromGyImsPlugin implements IBackgroundWorkPlugin {
JSONArray bodyJsonArr = new JSONArray();
for (Map<String, Object> body : bodyList) {
JSONObject bodyJson = new JSONObject();
bodyJson.put("cmaterialvid", body.get("cmaterialvid"));// 膠죕긍쯤
// bodyJson.put("castunitid", body.get("castunitid"));// 데貫
// bodyJson.put("cunitid", body.get("cunitid"));// 寮데貫
Object cmaterialvid = body.get("cmaterialvid");
Map goodsMap = getGoodsInfo(cmaterialvid + "");
bodyJson.put("cmaterialvid", cmaterialvid);// 膠죕긍쯤
if (goodsMap != null) {
bodyJson.put("castunitid", goodsMap.get("unitcode"));// 데貫
bodyJson.put("cunitid", goodsMap.get("unitcode"));// 寮데貫
}
bodyJson.put("nshouldnum", body.get("nshouldnum"));// 应收主数量
bodyJson.put("nshouldassistnum", body.get("nshouldassistnum"));// 应收数量
bodyJson.put("nnum", body.get("nnum"));// 实收主数量
@ -130,7 +135,7 @@ public class ErpIaI2billFromGyImsPlugin implements IBackgroundWorkPlugin {
bodyJson.put("norigtaxmny", body.get("norigtaxmny"));// 价税合计
bodyJson.put("nmny", body.get("norigmny"));// 本币无税金额
bodyJson.put("ntaxmny", body.get("norigtaxmny"));// 本币价税合计
bodyJson.put("ntaxrate", body.get("ntaxrate"));// 江쪽
// bodyJson.put("ntaxrate", body.get("ntaxrate"));// 江쪽
bodyJson.put("vnotebody", body.get("vnotebody"));// 行备注
bodyJsonArr.add(bodyJson);
@ -142,13 +147,15 @@ public class ErpIaI2billFromGyImsPlugin implements IBackgroundWorkPlugin {
paramList.add(param);
imsIdSet.add(cgeneralhid);
}
// String jsonString = JSONArray.toJSONString(paramList);
// NCCForUAPLogger.debug("jsonString = " + jsonString);
IAPIPurchaseInMaitain purchaseInMaitain = NCLocator.getInstance().lookup(IAPIPurchaseInMaitain.class);
PurchaseInVO[] resultvos = purchaseInMaitain.save(paramList);
if (!imsIdSet.isEmpty()) {
if (!imsIdSet.isEmpty() && resultvos != null) {
// 修改状态为 完成
String inSql = SqlUtils.getInStr("cgeneralhid", imsIdSet.toArray(new String[0]), Boolean.TRUE);
String updateSql = "update BIPInputMainTab set status = '2',err_msg = null where " + inSql;
ImsDaoUtil.executeUpdate(updateSql, imsIdSet.toString());
getImsDao().executeUpdate(updateSql);
}
} catch (Exception e) {
Logger.error("ErpIaI2billFromGyImsPlugin Error: ", e);
@ -162,4 +169,15 @@ public class ErpIaI2billFromGyImsPlugin implements IBackgroundWorkPlugin {
}
return null;
}
private Map getGoodsInfo(String materialCode) throws BusinessException {
String sql = " select a.pk_measdoc, c.code unitcode, b.pk_measdoc deputyunit " +
"from bd_material a " +
"left join bd_materialconvert b on a.pk_material = b.pk_material " +
"left join bd_measdoc c on a.pk_measdoc = c.pk_measdoc " +
"where a.code = '" + materialCode + "' ";
Map map = (Map) new BaseDAO().executeQuery(sql, new MapProcessor());
return map;
}
}

View File

@ -27,7 +27,6 @@ import nc.vo.pub.lang.UFDateTime;
import nc.vo.pub.lang.UFDouble;
import nc.vo.scmpub.res.billtype.ICBillType;
import nc.vo.scmpub.res.billtype.MMBillType;
import nccloud.baseapp.core.log.NCCForUAPLogger;
import java.math.BigDecimal;
import java.sql.Timestamp;
@ -79,111 +78,101 @@ public class MaterialOutGyImsPlugin implements IBackgroundWorkPlugin {
imsIdFailSet.add(cgeneralhid);
// 同步状态IMS:C-创建;U-修改; 4-BIP审核出库MES接收确认 BIP:2-BIP审核出库
String status = mainMap.get("status") + "";
try {
String pkSql = "select * from BIPOutDetailTab where cgeneralhid = '" + cgeneralhid + "'";
List<Map<String, Object>> detailList = (List<Map<String, Object>>) getImsDao().executeQuery(pkSql, new MapListProcessor());
Map<String, Map<String, Object>> detailIdMap = new HashMap<>();
for (Map<String, Object> detailMap : detailList) {
detailIdMap.put(detailMap.get("vbdef17") + "", detailMap);
}
if (detailList.isEmpty()) {
String pkSql = "select * from BIPOutDetailTab where cgeneralhid = '" + cgeneralhid + "'";
List<Map<String, Object>> detailList = (List<Map<String, Object>>) getImsDao().executeQuery(pkSql, new MapListProcessor());
Map<String, Map<String, Object>> detailIdMap = new HashMap<>();
for (Map<String, Object> detailMap : detailList) {
detailIdMap.put(detailMap.get("vbdef17") + "", detailMap);
}
if (detailList.isEmpty()) {
continue;
}
String csourcebillhid = detailList.get(0).get("vbdef16") + "";// 备料计划主键
// 查询备料计划的VO
AggPickmVO[] pickmVOS = queryService.queryBillsByPks(new String[]{csourcebillhid});
// 调用单据转换规则转换出流程材料出库的VO
MaterialOutVO[] vos = (MaterialOutVO[]) PFPubService.runChangeData(MMBillType.PickMo.getCode(), ICBillType.MaterialOut.getCode(),
pickmVOS, null, PfButtonClickContext.ClassifyByItfdef);
if (MMValueCheck.isEmpty(vos)) {
continue;
}
// 设置行号
setMaterialOutRowNum(vos);
// 根据IMS字段赋值
for (MaterialOutVO vo : vos) {
MaterialOutHeadVO hvo = vo.getHead();
MaterialOutBodyVO[] bodys = vo.getBodys();
hvo.setVbillcode(mainMap.get("vbillcode") + "");
hvo.setCreator("BIP");
hvo.setBillmaker("BIP");
hvo.setVtrantypecode("4D-01");
if (MMValueCheck.isEmpty(mainMap.get("cwarehouseid"))) {
continue;
}
String csourcebillhid = detailList.get(0).get("vbdef16") + "";// 备料计划主键
// 查询备料计划的VO
AggPickmVO[] pickmVOS = queryService.queryBillsByPks(new String[]{csourcebillhid});
// 调用单据转换规则转换出流程材料出库的VO
MaterialOutVO[] vos = (MaterialOutVO[]) PFPubService.runChangeData(MMBillType.PickMo.getCode(), ICBillType.MaterialOut.getCode(),
pickmVOS, null, PfButtonClickContext.ClassifyByItfdef);
if (MMValueCheck.isEmpty(vos)) {
continue;
// 仓库编码
String cwarehouseid = mainMap.get("cwarehouseid") + "";
String whereStorSql = StordocVO.CODE + " = '" + cwarehouseid + "'" + " and pk_org = '" + hvo.getPk_org() + "'";
String warehousePk = MyHelper.getStrValByCondition(StordocVO.getDefaultTableName(), StordocVO.PK_STORDOC,
whereStorSql);
// NCCForUAPLogger.debug("cwarehouseid = " + cwarehouseid);
hvo.setCwarehouseid(warehousePk);
if (mainMap.get("dbilldate") != null && mainMap.get("dbilldate") instanceof Timestamp dbilldate) {
String dbilldateStr = DATETIME_FORMATTER.format(dbilldate);
UFDate dbilldate1 = new UFDate(dbilldateStr);
hvo.setDbilldate(dbilldate1);
}
// 设置行号
setMaterialOutRowNum(vos);
// 根据IMS字段赋值
for (MaterialOutVO vo : vos) {
MaterialOutHeadVO hvo = vo.getHead();
MaterialOutBodyVO[] bodys = vo.getBodys();
hvo.setVbillcode(mainMap.get("vbillcode") + "");
hvo.setCreator("BIP");
hvo.setBillmaker("BIP");
hvo.setVtrantypecode("4D-01");
if (MMValueCheck.isEmpty(mainMap.get("cwarehouseid"))) {
continue;
}
// 仓库编码
String cwarehouseid = mainMap.get("cwarehouseid") + "";
String whereStorSql = StordocVO.CODE + " = '" + cwarehouseid + "'" + " and pk_org = '" + hvo.getPk_org() + "'";
String warehousePk = MyHelper.getStrValByCondition(StordocVO.getDefaultTableName(), StordocVO.PK_STORDOC,
whereStorSql);
// NCCForUAPLogger.debug("cwarehouseid = " + cwarehouseid);
hvo.setCwarehouseid(warehousePk);
if (mainMap.get("dbilldate") != null && mainMap.get("dbilldate") instanceof Timestamp dbilldate) {
String dbilldateStr = DATETIME_FORMATTER.format(dbilldate);
UFDate dbilldate1 = new UFDate(dbilldateStr);
hvo.setDbilldate(dbilldate1);
}
if (mainMap.get("dmakedate") != null && mainMap.get("dmakedate") instanceof Timestamp dmakedate1) {
String dmakedateStr = DATE_FORMATTER.format(dmakedate1);
UFDate dmakedate = new UFDate(dmakedateStr);
hvo.setDmakedate(dmakedate);
}
if (mainMap.get("creationtime") != null && mainMap.get("creationtime") instanceof Timestamp creationtime1) {
String creationtimeStr = DATETIME_FORMATTER.format(creationtime1);
UFDateTime creationtime = new UFDateTime(creationtimeStr);
hvo.setCreationtime(creationtime);
}
for (MaterialOutBodyVO bvo : bodys) {
String getCsourcebillbid = bvo.getCsourcebillbid();// 备料计划明细id
Map<String, Object> detailMap = detailIdMap.get(getCsourcebillbid);
if (detailMap != null) {
// 物料或数量替换
bvo.setNshouldnum(skipNullNum(detailMap.get("nshouldnum"), bvo.getNshouldnum()));// 应发主数量
bvo.setNshouldassistnum(skipNullNum(detailMap.get("nshouldassistnum"), bvo.getNshouldassistnum()));// 应发数量
bvo.setNnum(skipNullNum(detailMap.get("nnum"), bvo.getNshouldnum()));// 实发主数量
bvo.setNassistnum(skipNullNum(detailMap.get("nassistnum"), bvo.getNshouldassistnum()));// 实发数量
// bvo.setNnum(skipNullNum(detailMap.get("nnum"), bvo.getNnum()));// 实发主数量
if (mainMap.get("dmakedate") != null && mainMap.get("dmakedate") instanceof Timestamp dmakedate1) {
String dmakedateStr = DATE_FORMATTER.format(dmakedate1);
UFDate dmakedate = new UFDate(dmakedateStr);
hvo.setDmakedate(dmakedate);
}
if (mainMap.get("creationtime") != null && mainMap.get("creationtime") instanceof Timestamp creationtime1) {
String creationtimeStr = DATETIME_FORMATTER.format(creationtime1);
UFDateTime creationtime = new UFDateTime(creationtimeStr);
hvo.setCreationtime(creationtime);
}
for (MaterialOutBodyVO bvo : bodys) {
String getCsourcebillbid = bvo.getCsourcebillbid();// 备料计划明细id
Map<String, Object> detailMap = detailIdMap.get(getCsourcebillbid);
if (detailMap != null) {
// 物料或数量替换
bvo.setNshouldnum(skipNullNum(detailMap.get("nshouldnum"), bvo.getNshouldnum()));// 应发主数量
bvo.setNshouldassistnum(skipNullNum(detailMap.get("nshouldassistnum"), bvo.getNshouldassistnum()));// 应发数量
bvo.setNnum(skipNullNum(detailMap.get("nnum"), bvo.getNshouldnum()));// 实发主数量
bvo.setNassistnum(skipNullNum(detailMap.get("nassistnum"), bvo.getNshouldassistnum()));// 实发数量
// bvo.setNnum(skipNullNum(detailMap.get("nnum"), bvo.getNnum()));// 实发主数量
// bvo.setNassistnum(skipNullNum(detailMap.get("nassistnum"), bvo.getNassistnum()));// 实发数量
// 如果物料不相等则BIP物料替换为IMS物料
String cmaterialvid = bvo.getCmaterialvid();
String goodsCode = detailMap.get("cmaterialvid") + "";
String pkOrg = hvo.getPk_org();
String goodsSql = " SELECT b.pk_material" +
" FROM bd_materialstock a" +
" LEFT JOIN bd_material b ON a.pk_material = b.pk_material" +
" WHERE b.code = '[code]' AND a.pk_org = '[pk_org]'";
goodsSql = goodsSql.replace("[code]", goodsCode);
goodsSql = goodsSql.replace("[pk_org]", pkOrg);
String goodsId = (String) baseDAO.executeQuery(goodsSql, new ColumnProcessor());
if (!cmaterialvid.equals(goodsId)) {
bvo.setCmaterialvid(goodsId);
}
// 如果物料不相等则BIP物料替换为IMS物料
String cmaterialvid = bvo.getCmaterialvid();
String goodsCode = detailMap.get("cmaterialvid") + "";
String pkOrg = hvo.getPk_org();
String goodsSql = " SELECT b.pk_material" +
" FROM bd_materialstock a" +
" LEFT JOIN bd_material b ON a.pk_material = b.pk_material" +
" WHERE b.code = '[code]' AND a.pk_org = '[pk_org]'";
goodsSql = goodsSql.replace("[code]", goodsCode);
goodsSql = goodsSql.replace("[pk_org]", pkOrg);
String goodsId = (String) baseDAO.executeQuery(goodsSql, new ColumnProcessor());
if (!cmaterialvid.equals(goodsId)) {
bvo.setCmaterialvid(goodsId);
}
}
}
IMaterialOutMaintainAPI materialOut = NCLocator.getInstance().lookup(IMaterialOutMaintainAPI.class);
MaterialOutVO[] resultvos = materialOut.insertBills(vos);
if (MMValueCheck.isEmpty(resultvos)) {
continue;
}
// NCCForUAPLogger.debug("code = " + resultvos[0].getHead().getVbillcode());
imsIdSet.add(cgeneralhid);
} catch (BusinessException e) {
logger.error("MaterialOutGyImsPlugin Error: ", e);
NCCForUAPLogger.debug("MaterialOutGyImsPlugin Error: " + e.getMessage());
String updateSql = "update BIPOutMainTab set err_msg = '[err_msg]' where cgeneralhid = '[cgeneralhid]'";
updateSql = updateSql.replace("[err_msg]", e.getMessage());
updateSql = updateSql.replace("[cgeneralhid]", cgeneralhid);
NCCForUAPLogger.debug("MaterialOutGyImsPlugin-updateSql = " + updateSql);
int rows = ImsDaoUtil.executeUpdate(updateSql, cgeneralhid);
NCCForUAPLogger.debug("MaterialOutGyImsPlugin-rows = " + rows);
}
IMaterialOutMaintainAPI materialOut = NCLocator.getInstance().lookup(IMaterialOutMaintainAPI.class);
MaterialOutVO[] resultvos = materialOut.insertBills(vos);
if (MMValueCheck.isEmpty(resultvos)) {
continue;
}
imsIdSet.add(cgeneralhid);
}
if (!imsIdSet.isEmpty()) {
// 修改状态为 完成
String inSql = SqlUtils.getInStr("cgeneralhid", imsIdSet.toArray(new String[0]), Boolean.TRUE);
String updateSql = "update BIPOutMainTab set status = '2',err_msg = null where " + inSql;
ImsDaoUtil.executeUpdate(updateSql, imsIdSet.toString());
// NCCForUAPLogger.debug("updateSql-suc = " + updateSql);
int rows = ImsDaoUtil.executeUpdate(updateSql, imsIdSet.toString());
}
logger.error("---end----任务结束运行--");
} catch (Exception e) {
@ -191,6 +180,7 @@ public class MaterialOutGyImsPlugin implements IBackgroundWorkPlugin {
String inSql = SqlUtils.getInStr("cgeneralhid", imsIdFailSet.toArray(new String[0]), Boolean.TRUE);
String updateSql = "update BIPOutMainTab set err_msg = '[err_msg]' where " + inSql;
updateSql = updateSql.replace("[err_msg]", e.getMessage());
// NCCForUAPLogger.debug("updateSql-fail = " + updateSql);
int rows = ImsDaoUtil.executeUpdate(updateSql, imsIdFailSet.toString());
}
return null;