高压加工车间-IMS-定时获取采购入库数据

This commit is contained in:
mzr 2025-10-09 17:16:24 +08:00
parent 67acc7b3fb
commit 721fdb22c2
2 changed files with 143 additions and 467 deletions

View File

@ -1,467 +0,0 @@
package nc.bs.uapbd.bip.workplugin;
import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.ic.m45.insert.InsertBP;
import nc.bs.pub.pa.PreAlertObject;
import nc.bs.pub.taskcenter.BgWorkingContext;
import nc.bs.pub.taskcenter.IBackgroundWorkPlugin;
import nc.bs.trade.business.HYPubBO;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.pubimpl.ic.api.maintain.BillMaintainTool;
import nc.vo.ia.mi2.entity.I2BillVO;
import nc.vo.ia.mi2.entity.I2HeadVO;
import nc.vo.ic.m45.entity.PurchaseInBodyVO;
import nc.vo.ic.m45.entity.PurchaseInHeadVO;
import nc.vo.ic.m45.entity.PurchaseInVO;
import nc.vo.ic.org.OrgInfoQuery;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.scmpub.check.billvalidate.BillVOsCheckRule;
import nc.vo.scmpub.res.billtype.ICBillType;
import nccloud.api.impl.ic.m45.check.CheckPurchaseInSaveValidator;
import nccloud.api.impl.ic.m45.fill.PurchaseInSaveFillValue;
import nccloud.openapi.ic.util.ICAPILocationVOUtils;
import nccloud.openapi.scmpub.pub.TransferCodeToPKTool;
import org.eclipse.swt.internal.C;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ErpIaI2billFromGyImsPlugin implements IBackgroundWorkPlugin {
@Override
public PreAlertObject executeTask(BgWorkingContext bgWorkingContext) throws BusinessException {
BaseDAO imsDao= new BaseDAO("gyims");
// 禁用时间戳ts
imsDao.setAddTimeStamp(false);
// 查询高压ims中间表需要同步的数据
String sql = " \t\tSELECT\n" +
"\t* \n" +
"from BIPInputMainTab a " +
"where a.status !='2'";
List<Map<String,Object>> remain = (List<Map<String, Object>>) imsDao.executeQuery(sql, new MapListProcessor());
if (remain != null && remain.size() > 0) {
try{
List<PurchaseInVO> list = new ArrayList<PurchaseInVO>();
for (Map<String, Object> map : remain) {
HYPubBO hy = new HYPubBO();
PurchaseInVO vo = new PurchaseInVO();
PurchaseInHeadVO head = new PurchaseInHeadVO();
// 按数据库字段名直接调用对应setter方法set+字段名
head.setCgeneralhid((String) map.get("cgeneralhid"));
head.setPk_group(InvocationInfoProxy.getInstance().getGroupId());
map.put("pk_org","C047");
map.put("pk_org_v","C047");
// OrgVO orgvo = (OrgVO)hy.queryByPrimaryKey(OrgVO.class, );
Object pk_org = hy.findColValue("org_stockorg", "pk_org", "code = '"+map.get("pk_org")+"' and nvl(dr,0)=0 and islastversion='Y' ");
head.setPk_org((String) pk_org); // 对应字段pk_org
// Object pk_org_v = hy.findColValue("org_stockorg_v", "pk_vid", "pk_stockorg = '"+pk_org+"' ");
Object pk_org_v = hy.findColValue("org_stockorg_v", "pk_vid", "code = '"+map.get("pk_org")+"' ");
head.setPk_org_v((String) pk_org_v); // 对应字段pk_org_v
Object busicode = hy.findColValue("bd_busitype", "pk_busitype", "busicode = '"+map.get("busicode")+"' ");
head.setCbiztype((String) busicode);
head.setVbillcode((String) map.get("vbillcode"));
// Object cwarehouseid = hy.findColValue("bd_stordoc", "pk_stordoc", " code = '"+map.get("cwarehouseid")+"' ");
Object cwarehouseid = hy.findColValue("bd_stordoc", "pk_stordoc", " code = '"+"C047002"+"' ");
head.setCwarehouseid((String) cwarehouseid);
head.setDbilldate(new UFDate(String.valueOf(map.get("dbilldate"))) ); // 日期类型
map.put("vtrantypecode","45-Cxx-CI02");
head.setVtrantypecode((String) map.get("vtrantypecode"));
Object ctrantypeid = hy.findColValue("bd_billtype", "pk_billtypeid", " pk_billtypecode = '"+map.get("vtrantypecode")+"' and dr='0' ");
head.setCtrantypeid((String) ctrantypeid);
Object cwhsmanagerid = hy.findColValue("bd_psndoc", "pk_psndoc", " code = '"+map.get("cwhsmanagerid")+"' and dr='0' ");
head.setCwhsmanagerid((String)cwhsmanagerid);
Object cdptid = hy.findColValue("org_dept", "pk_dept", " code = '"+map.get("cdptid")+"' and dr='0' ");
head.setCdptid((String) cdptid);
Object cbizid = hy.findColValue("bd_psndoc", "pk_psndoc", " code = '"+map.get("cbizid")+"' and dr='0' ");
head.setCbizid((String) cbizid);
head.setNtotalnum(new UFDouble(String.valueOf(map.get("ntotalnum")))); // 数字类型
head.setVnote((String) map.get("vnote"));
// head.setStatus((Integer) map.get("status"));
head.setFbillflag(2);
Object billmaker = hy.findColValue("sm_user", "cuserid", " user_code = '"+map.get("billmaker")+"' and dr='0' ");
head.setBillmaker((String) billmaker);
Object approver = hy.findColValue("sm_user", "cuserid", " user_code = '"+map.get("approver")+"' and dr='0' ");
head.setApprover((String)approver);
if(map.get("taudittime") !=null){
head.setTaudittime(new UFDate(String.valueOf(map.get("taudittime"))) ); // 日期类型
}
map.put("cpayfinorgoid","C003");
Object cpayfinorgoid = hy.findColValue("org_financeorg", "pk_financeorg", " code = '"+map.get("cpayfinorgoid")+"' and dr='0' ");
if(cpayfinorgoid !=null){
head.setCpayfinorgoid((String) cpayfinorgoid);
}
Object cfanaceorgoid = hy.findColValue("org_financeorg", "pk_financeorg", " code = '"+map.get("cfanaceorgoid")+"' and dr='0' ");
head.setCfanaceorgoid((String) cfanaceorgoid); // 注意原字段名是否正确org_financeorg
Object cpurorgoid = hy.findColValue("org_purchaseorg", "pk_purchaseorg", " code = '"+map.get("cpurorgoid")+"' and dr='0' ");
head.setCpurorgoid((String) cpurorgoid);
Object cvendorid = hy.findColValue("bd_supplier", "pk_supplier", " code = '"+map.get("cvendorvid")+"' and dr='0' ");
head.setCvendorid((String)cvendorid);
Object cvendorvid = hy.findColValue("bd_supplier_v", "pk_supplier_v", " pk_supplier = '"+cvendorid+"' and dr='0' ");
head.setCvendorvid((String)cvendorvid);
head.setDmakedate(new UFDate(String.valueOf(map.get("dmakedate")))); // 日期类型
Object csendcountryid = hy.findColValue("bd_countryzone", "pk_country", " code = '"+"CN"+"' and dr='0' ");
head.setCsendcountryid((String) csendcountryid);
Object crececountryid = hy.findColValue("bd_countryzone", "pk_country", " code = '"+"CN"+"' and dr='0' ");
head.setCrececountryid((String) crececountryid);
Object ctaxcountryid = hy.findColValue("bd_countryzone", "pk_country", " code = '"+"CN"+"' and dr='0' ");
head.setCtaxcountryid((String) ctaxcountryid);
head.setFbuysellflag(2 ); // 数值类型按需调整
// 将head设置到vo中
vo.setParent(head);
String bodysql = " \t\tSELECT\n" +
"\t* \n" +
"from BIPInputDetailTab a " +
"where a.cgeneralhid ='"+map.get("cgeneralhid")+"'";
List<Map<String,Object>> bodys = (List<Map<String, Object>>) imsDao.executeQuery(bodysql, new MapListProcessor());
List<PurchaseInBodyVO> list1 = new ArrayList<>();
for(Map<String,Object> body : bodys) {
HYPubBO hy1 = new HYPubBO();
PurchaseInBodyVO bodyVO = new PurchaseInBodyVO();
// 主键及关联字段
bodyVO.setCgeneralbid((String) body.get("cgeneralbid")); // 主键(UFID)org_corp
bodyVO.setCgeneralhid((String) body.get("cgeneralhid")); // 关联主表ID
body.put("corpoid","C003");
Object corpoid = hy1.findColValue("org_corp", "pk_corp", " code = '"+body.get("corpoid")+"' and dr='0' ");
bodyVO.setCorpoid((String)corpoid); // 组织_业务单元_公司
Object cfanaceorgoid1 = hy1.findColValue("org_financeorg", "pk_financeorg", " code = '"+"C003"+"' and dr='0' ");
bodyVO.setCfanaceorgoid((String) cfanaceorgoid1); // 组织_业务单元_财务组织org_financeorg
// bodyVO.setVbillcode((String) body.get("vbillcode")); // 字符串
bodyVO.setCrowno((String) body.get("crowno")); // 字符串
Object cmaterialvid = hy1.findColValue("bd_material", "pk_material", " code = '"+body.get("cmaterialvid")+"' and dr='0' ");
bodyVO.setCmaterialvid((String)cmaterialvid); // 物料基本信息
Object cunitid = hy1.findColValue("bd_material", "pk_measdoc", " code = '"+body.get("cmaterialvid")+"' and dr='0' ");
bodyVO.setCunitid((String)cunitid); // 计量单位bd_measdoc
// Object castunitid = hy1.findColValue("bd_measdoc", "pk_measdoc", " code = '"+body.get("castunitid")+"' and dr='0' ");
bodyVO.setCastunitid((String)cunitid); // 计量单位
bodyVO.setVchangerate((String) body.get("vchangerate")); // 字符串
bodyVO.setVbatchcode((String) body.get("vbatchcode")); // 字符串
// 数值类型UFDouble
bodyVO.setNshouldassistnum(new UFDouble(String.valueOf(body.get("nshouldassistnum")))); // 数值
bodyVO.setNshouldnum(new UFDouble(String.valueOf(body.get("nshouldnum")))); // 数值
bodyVO.setNassistnum(new UFDouble(String.valueOf(body.get("nassistnum")))); // 数值
bodyVO.setNnum(new UFDouble(String.valueOf(body.get("nnum")))); // 数值
if(body.get("cprojectid")!=null){
Object cprojectid = hy1.findColValue("bd_project", "pk_project", " code = '"+body.get("cprojectid")+"' and dr='0' ");
bodyVO.setCprojectid((String) cprojectid); // 项目
}
bodyVO.setVnotebody((String) body.get("vnotebody")); // 字符串
Object cbodytranstypecode = hy1.findColValue("bd_billtype", "pk_billtypeid", " pk_billtypecode = '"+body.get("cbodytranstypecode")+"' and dr='0' ");
bodyVO.setCbodytranstypecode((String)cbodytranstypecode); // 单据类型
// Object cbodywarehouseid = hy1.findColValue("bd_stordoc", "pk_stordoc", " code = '"+body.get("cbodywarehouseid")+"' and dr='0' ");
bodyVO.setCbodywarehouseid(head.getCwarehouseid()); // 仓库
Object cproductorid = hy1.findColValue("bd_defdoc", "pk_defdoc", " code = '" + body.get("cproductorid") + "' and dr='0' ");
bodyVO.setCproductorid((String) cproductorid); // 生产厂商
// Object pk_creqwareid = hy1.findColValue("bd_stordoc", "pk_stordoc", " code = '"+body.get("pk_creqwareid")+"' and dr='0' ");
bodyVO.setPk_creqwareid(head.getCwarehouseid()); // 仓库
Object creqstoorgoid = hy1.findColValue("org_stockorg", "pk_org", "code = '"+"C047"+"' and nvl(dr,0)=0 and islastversion='Y' ");
bodyVO.setCreqstoorgoid((String) creqstoorgoid); // 组织_业务单元_库存组织
Object corigcurrencyid = hy1.findColValue("bd_currtype", "pk_currtype", "code = '"+"CNY"+"' and nvl(dr,0)=0 ");
bodyVO.setCorigcurrencyid((String) corigcurrencyid); // 币种
bodyVO.setNchangestdrate(new UFDouble(1)); // 数值
Object ccurrencyid = hy1.findColValue("bd_currtype", "pk_currtype", "code = '"+"CNY"+"' and nvl(dr,0)=0 ");
bodyVO.setCcurrencyid((String) ccurrencyid); // 币种
// 价格相关数值UFDouble
// 处理UFDouble类型属性值非null时才赋值
Object norignetpriceVal = body.get("norignetprice");
if (norignetpriceVal != null) {
bodyVO.setNorignetprice(new UFDouble(String.valueOf(norignetpriceVal)));
}
Object norigtaxnetpriceVal = body.get("norigtaxnetprice");
if (norigtaxnetpriceVal != null) {
bodyVO.setNorigtaxnetprice(new UFDouble(String.valueOf(norigtaxnetpriceVal)));
}
Object nnetpriceVal = body.get("nnetprice");
if (nnetpriceVal != null) {
bodyVO.setNnetprice(new UFDouble(String.valueOf(nnetpriceVal)));
}
Object ntaxnetpriceVal = body.get("ntaxnetprice");
if (ntaxnetpriceVal != null) {
bodyVO.setNtaxnetprice(new UFDouble(String.valueOf(ntaxnetpriceVal)));
}
// 计量单位非null时赋值
Object cqtunitidVal = body.get("cqtunitid");
if (cqtunitidVal != null) {
bodyVO.setCqtunitid((String) cqtunitidVal);
}
// 数值UFDouble类型非null时赋值
Object nqtunitnumVal = body.get("nqtunitnum");
if (nqtunitnumVal != null) {
bodyVO.setNqtunitnum(new UFDouble(String.valueOf(nqtunitnumVal)));
}
// 字符串非null时赋值
Object vqtunitrateVal = body.get("vqtunitrate");
if (vqtunitrateVal != null) {
bodyVO.setVqtunitrate((String) vqtunitrateVal);
}
// 继续处理其他UFDouble类型属性
Object nqtorignetpriceVal = body.get("nqtorignetprice");
if (nqtorignetpriceVal != null) {
bodyVO.setNqtorignetprice(new UFDouble(String.valueOf(nqtorignetpriceVal)));
}
Object nqtorigtaxnetpriceVal = body.get("nqtorigtaxnetprice");
if (nqtorigtaxnetpriceVal != null) {
bodyVO.setNqtorigtaxnetprice(new UFDouble(String.valueOf(nqtorigtaxnetpriceVal)));
}
Object nqtnetpriceVal = body.get("nqtnetprice");
if (nqtnetpriceVal != null) {
bodyVO.setNqtnetprice(new UFDouble(String.valueOf(nqtnetpriceVal)));
}
Object nqttaxnetpriceVal = body.get("nqttaxnetprice");
if (nqttaxnetpriceVal != null) {
bodyVO.setNqttaxnetprice(new UFDouble(String.valueOf(nqttaxnetpriceVal)));
}
Object norigpriceVal = body.get("norigprice");
if (norigpriceVal != null) {
bodyVO.setNorigprice(new UFDouble(String.valueOf(norigpriceVal)));
}
Object norigtaxpriceVal = body.get("norigtaxprice");
if (norigtaxpriceVal != null) {
bodyVO.setNorigtaxprice(new UFDouble(String.valueOf(norigtaxpriceVal)));
}
Object npriceVal = body.get("nprice");
if (npriceVal != null) {
bodyVO.setNprice(new UFDouble(String.valueOf(npriceVal)));
}
Object ntaxpriceVal = body.get("ntaxprice");
if (ntaxpriceVal != null) {
bodyVO.setNtaxprice(new UFDouble(String.valueOf(ntaxpriceVal)));
}
Object nqtorigpriceVal = body.get("nqtorigprice");
if (nqtorigpriceVal != null) {
bodyVO.setNqtorigprice(new UFDouble(String.valueOf(nqtorigpriceVal)));
}
Object nqtorigtaxpriceVal = body.get("nqtorigtaxprice");
if (nqtorigtaxpriceVal != null) {
bodyVO.setNqtorigtaxprice(new UFDouble(String.valueOf(nqtorigtaxpriceVal)));
}
Object nqtpriceVal = body.get("nqtprice");
if (nqtpriceVal != null) {
bodyVO.setNqtprice(new UFDouble(String.valueOf(nqtpriceVal)));
}
Object nqttaxpriceVal = body.get("nqttaxprice");
if (nqttaxpriceVal != null) {
bodyVO.setNqttaxprice(new UFDouble(String.valueOf(nqttaxpriceVal)));
}
Object nitemdiscountrateVal = body.get("nitemdiscountrate");
if (nitemdiscountrateVal != null) {
bodyVO.setNitemdiscountrate(new UFDouble(String.valueOf(nitemdiscountrateVal)));
}
// 金额及税额相关UFDouble类型非null时赋值
Object norigmnyVal = body.get("norigmny");
if (norigmnyVal != null) {
bodyVO.setNorigmny(new UFDouble(String.valueOf(norigmnyVal)));
}
Object norigtaxmnyVal = body.get("norigtaxmny");
if (norigtaxmnyVal != null) {
bodyVO.setNorigtaxmny(new UFDouble(String.valueOf(norigtaxmnyVal)));
}
Object nmnyVal = body.get("nmny");
if (nmnyVal != null) {
bodyVO.setNmny(new UFDouble(String.valueOf(nmnyVal)));
}
Object ntaxmnyVal = body.get("ntaxmny");
if (ntaxmnyVal != null) {
bodyVO.setNtaxmny(new UFDouble(String.valueOf(ntaxmnyVal)));
}
Object ntaxVal = body.get("ntax");
if (ntaxVal != null) {
bodyVO.setNtax(new UFDouble(String.valueOf(ntaxVal)));
}
// 增值税税码税率查询结果非null时赋值
Object ctaxcodeid = hy1.findColValue("bd_taxcode", "pk_taxcode",
"code = '" + "CN13" + "' and dr=0 ");
if (ctaxcodeid != null) {
bodyVO.setCtaxcodeid((String) ctaxcodeid);
}
String sql1 ="select taxrate from bd_taxrate where pk_taxcode = '1002Z01000000001CNE2' and dr=0 ";
Object ntaxrateVal =new BaseDAO().executeQuery(sql1, new ColumnProcessor());
// Object ntaxrateVal = hy1.findColValue("bd_taxrate", "taxrate",
// " pk_taxcode = '" + ctaxcodeid+ "' and dr=0 ");
if (ntaxrateVal != null) {
bodyVO.setNtaxrate(new UFDouble(String.valueOf(ntaxrateVal)));
}
// 继续处理其他UFDouble类型
Object ncaltaxmnyVal = body.get("ncaltaxmny");
if (ncaltaxmnyVal != null) {
bodyVO.setNcaltaxmny(new UFDouble(String.valueOf(ncaltaxmnyVal)));
}
// 扣税类别非null时转换并赋值
Object ftaxtypeflagVal = body.get("ftaxtypeflag");
if (ftaxtypeflagVal != null) {
bodyVO.setFtaxtypeflag(Integer.valueOf((String) ftaxtypeflagVal));
}
Object ncalcostmnyVal = body.get("ncalcostmny");
if (ncalcostmnyVal != null) {
bodyVO.setNcalcostmny(new UFDouble(String.valueOf(ncalcostmnyVal)));
}
// 供应商基本信息查询结果非null时赋值
String cvendorid1 = (String) hy1.findColValue("bd_supplier", "pk_supplier",
" code = '" + body.get("cvendorid") + "' and dr=0 ");
if (cvendorid1 != null) {
bodyVO.setCvendorid(cvendorid1);
}
list1.add(bodyVO);
}
vo.setChildrenVO(list1.toArray(new PurchaseInBodyVO[list1.size()]));
// 添加到集合
list.add(vo);
}
PurchaseInVO[] vos =list.toArray(new PurchaseInVO[list.size()]) ;
// InsertBP insertBP=new InsertBP();
// insertBP.insert(list.toArray(new PurchaseInVO[list.size()]));
ICAPILocationVOUtils.setLocationVO(ICBillType.PurchaseIn.getCode(), vos);
// 1传入数据基本非空校验
BillVOsCheckRule checker =
new BillVOsCheckRule(new CheckPurchaseInSaveValidator());
//2025年4月23日15点10分 采购入库单接口项目字段为波浪则清空 sdlizheng --start
for (PurchaseInVO vo : vos) {
PurchaseInBodyVO[] bodys = vo.getBodys();
if (bodys != null && bodys.length > 0) {
String[] attributeNames = bodys[0].getAttributeNames();
for (PurchaseInBodyVO body : bodys) {
for (String fildName : attributeNames) {
if (body.getAttributeValue(fildName) != null && "~".equals(body.getAttributeValue(fildName))) {
body.setAttributeValue(fildName, null);
}
}
}
}
}
//2025年4月23日15点10分 采购入库单接口项目字段为波浪则清空 sdlizheng --end
//添加供应商和交易类型为空赋值
checker.check(vos);
// 翻译货位
ICAPILocationVOUtils.translate(vos);
//begin没取到财务组织导致的报错在这里给财务组织赋值为库存组织
// for (PurchaseInVO vo : vos) {
// if (vo.getHead().getCfanaceorgoid() != null) {
// continue;
// }
// String cfinanceoid = (new OrgInfoQuery()).getFinanceOrgIDByCalBodyID(vo.getHead().getPk_org());
// String cfinancevid = (new OrgInfoQuery()).getFinanceOrgVIDByCalBodyID(vo.getHead().getPk_org());
// vo.getHead().setCfanaceorgoid(cfinanceoid);
// vo.getHead().setCfanaceorgvid(cfinancevid);
// }
//end
// 3其他数据填充
// new PurchaseInSaveFillValue().setDefaultValue(vos);
BillMaintainTool<PurchaseInVO> tool = new BillMaintainTool<PurchaseInVO>(
PurchaseInVO.class, ICBillType.PurchaseIn.getCode());
tool.insert(list.toArray(new PurchaseInVO[list.size()]));
} catch (Exception e) {
throw new BusinessException("同步失败:" + e.getMessage(), e);
}
}
return null;
}
}

View File

@ -0,0 +1,143 @@
package nc.bs.uapbd.task.ims;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.bs.pub.pa.PreAlertObject;
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.vo.fi.pub.SqlUtils;
import nc.vo.ic.m45.entity.PurchaseInVO;
import nc.vo.pub.BusinessException;
import nccloud.api.ic.m45.IAPIPurchaseInMaitain;
import nccloud.baseapp.core.log.NCCForUAPLogger;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 高压加工车间-IMS-定时获取采购入库数据
*
* @author lihao
* @date 2025/10/01
*/
public class ErpIaI2billFromGyImsPlugin implements IBackgroundWorkPlugin {
private SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
private SimpleDateFormat DATETIME_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// IMS数据源
public BaseDAO imsDao;
/**
* 获取IMS数据源
*/
public BaseDAO getImsDao() {
if (imsDao == null) {
imsDao = new BaseDAO("gyims");
// 禁用时间戳ts
imsDao.setAddTimeStamp(false);
}
return imsDao;
}
@Override
public PreAlertObject executeTask(BgWorkingContext bgWorkingContext) throws BusinessException {
// 查询高压ims中间表需要同步的数据
String sql = "SELECT * FROM BIPInputMainTab a WHERE a.status != '2'";
List<Map<String, Object>> remain = (List<Map<String, Object>>) getImsDao().executeQuery(sql, new MapListProcessor());
if (remain == null || remain.isEmpty()) {
return null;
}
Set<String> imsIdSet = new HashSet<>();
try {
List<Map<String, Object>> paramList = new ArrayList<>();
for (Map<String, Object> map : remain) {
String cgeneralhid = (String) map.get("cgeneralhid");
String bodySql = " SELECT *" + " from BIPInputDetailTab a " + " where a.cgeneralhid ='" + cgeneralhid + "'";
List<Map<String, Object>> bodyList = (List<Map<String, Object>>) getImsDao().executeQuery(bodySql, new MapListProcessor());
if (bodyList == null || bodyList.isEmpty()) {
continue;
}
JSONObject headJson = new JSONObject();
headJson.put("pk_group", "00");
headJson.put("pk_org", "C047");
headJson.put("pk_org_v", "C047");
headJson.put("cbiztype", "45-Cxx-CI02");
headJson.put("ctrantypeid", "45-Cxx-CI02");
headJson.put("vtrantypecode", "45-Cxx-CI02");
headJson.put("vbillcode", map.get("vbillcode"));// 单据号
headJson.put("dbilldate", map.get("dbilldate"));// 单据日期
headJson.put("cvendorid", map.get("cvendorid"));// 供应商
headJson.put("cwarehouseid", map.get("cwarehouseid"));// 仓库编码
headJson.put("cfanaceorgvid", map.get("cfanaceorgvid"));// 结算财务组织
headJson.put("ccostdomainid", map.get("ccostdomainid"));// 结算成本域
headJson.put("cdptvid", map.get("cdptvid"));// 采购部门
headJson.put("cbizid", map.get("cbizid"));// 采购员
headJson.put("vnote", map.get("vnote"));// 备注
headJson.put("cpurorgoid", map.get("cpurorgoid"));// 采购组织
// 购销类型 2=国内采购;
headJson.put("fbuysellflag", 2);
headJson.put("cpayfinorgoid", "C003");// 应付财务组织最新版本
headJson.put("creator", "BIP");
headJson.put("billmaker", "BIP");
if (map.get("dmakedate") != null && map.get("dmakedate") instanceof Timestamp dmakedate1) {
String dmakedateStr = DATE_FORMATTER.format(dmakedate1);
headJson.put("dmakedate", dmakedateStr);
}
if (map.get("creationtime") != null && map.get("creationtime") instanceof Timestamp creationtime1) {
String creationtimeStr = DATETIME_FORMATTER.format(creationtime1);
headJson.put("creationtime", creationtimeStr);
}
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"));// 主单位
bodyJson.put("nshouldnum", body.get("nshouldnum"));// 应收主数量
bodyJson.put("nshouldassistnum", body.get("nshouldassistnum"));// 应收数量
bodyJson.put("nnum", body.get("nnum"));// 实收主数量
bodyJson.put("nassistnum", body.get("nassistnum"));// 实收数量
bodyJson.put("vchangerate", "1/1");// 换算率
// bodyJson.put("nqtprice", body.get("nqtprice"));//
// bodyJson.put("nqttaxprice", body.get("nqttaxprice"));//
// bodyJson.put("norigtaxmny", body.get("norigtaxmny"));//
// bodyJson.put("ntaxmny", body.get("ntaxmny"));//
// bodyJson.put("nmny", body.get("nmny"));//
// bodyJson.put("ntax", body.get("ntax"));//
bodyJson.put("vnotebody", body.get("vnotebody"));// 行备注
bodyJsonArr.add(bodyJson);
}
Map<String, Object> param = new HashMap<>();
param.put("ic_purchasein_h", headJson);
param.put("ic_purchasein_b", bodyJsonArr);
// 添加到集合
paramList.add(param);
imsIdSet.add(cgeneralhid);
}
IAPIPurchaseInMaitain purchaseInMaitain = NCLocator.getInstance().lookup(IAPIPurchaseInMaitain.class);
PurchaseInVO[] resultvos = purchaseInMaitain.save(paramList);
} catch (Exception e) {
Logger.error("ErpIaI2billFromGyImsPlugin Error: ", e);
NCCForUAPLogger.debug("ErpIaI2billFromGyImsPlugin Error: " + e.getMessage());
String inSql = SqlUtils.getInStr("cgeneralhid", imsIdSet.toArray(new String[0]), Boolean.TRUE);
String updateSql = "update BIPInputMainTab set err_msg = '[err_msg]' where " + inSql;
updateSql = updateSql.replace("[err_msg]", e.getMessage());
NCCForUAPLogger.debug("ErpIaI2billFromGyImsPlugin-updateSql = " + updateSql);
int rows = ImsDaoUtil.executeUpdate(updateSql, imsIdSet.toString());
NCCForUAPLogger.debug("ErpIaI2billFromGyImsPlugin-rows = " + rows);
}
if (!imsIdSet.isEmpty()) {
// 修改状态为 完成
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());
}
return null;
}
}