定时同步高压加工车间IMS的生产报告
This commit is contained in:
parent
be49a4f6f4
commit
80133551ca
|
|
@ -0,0 +1,171 @@
|
|||
package nc.bs.uapbd.task;
|
||||
|
||||
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.MyHelper;
|
||||
import nc.itf.mmpac.pmo.pac0002.IPMOQueryService;
|
||||
import nc.itf.mmpac.wr.IWrMaintainService;
|
||||
import nc.itf.uap.pf.busiflow.PfButtonClickContext;
|
||||
import nc.jdbc.framework.processor.MapListProcessor;
|
||||
import nc.util.mmf.busi.service.PFPubService;
|
||||
import nc.util.mmf.framework.base.MMValueCheck;
|
||||
import nc.vo.bd.material.MaterialVO;
|
||||
import nc.vo.fi.pub.SqlUtils;
|
||||
import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO;
|
||||
import nc.vo.mmpac.wr.entity.AggWrVO;
|
||||
import nc.vo.mmpac.wr.entity.WrItemVO;
|
||||
import nc.vo.mmpac.wr.entity.WrVO;
|
||||
import nc.vo.pub.BusinessException;
|
||||
import nc.vo.pub.lang.UFDate;
|
||||
import nc.vo.pub.lang.UFDateTime;
|
||||
import nc.vo.pub.lang.UFDouble;
|
||||
import nc.vo.scmpub.res.billtype.MMBillType;
|
||||
import nccloud.baseapp.core.log.NCCForUAPLogger;
|
||||
import uap.mw.trans.TransactionFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 定时同步高压加工车间IMS的生产报告
|
||||
*
|
||||
* @author mzr
|
||||
* @date 20250929
|
||||
*/
|
||||
public class ProductReportGyImsPlugin implements IBackgroundWorkPlugin {
|
||||
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
private SimpleDateFormat sdf_ts = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
// BIP数据源
|
||||
public static final BaseDAO baseDAO = new BaseDAO();
|
||||
// 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 arg0) {
|
||||
Logger.error("---start----任务开始运行--");
|
||||
try {
|
||||
IPMOQueryService pmoQueryService = NCLocator.getInstance().lookup(IPMOQueryService.class);
|
||||
IWrMaintainService wrService = NCLocator.getInstance().lookup(IWrMaintainService.class);
|
||||
// 手动开启事务
|
||||
TransactionFactory.getTMProxy().begin(3, 0);
|
||||
// IMS:C-创建;U-修改 BIP:2-BIP单据接收完成
|
||||
String selSql = "select * from BIPReportMainTab where status != '2'";
|
||||
List<Map<String, Object>> mainList = (List<Map<String, Object>>) getImsDao().executeQuery(selSql, new MapListProcessor());
|
||||
Set<String> pkWrSet = new HashSet<>();
|
||||
for (Map<String, Object> mainMap : mainList) {
|
||||
String pkWr = mainMap.get("pk_wr").toString();
|
||||
String pkWrSql = "select * from BIPReportDetailTab where pk_wr = '" + pkWr + "'";
|
||||
List<Map<String, Object>> detailList = (List<Map<String, Object>>) getImsDao().executeQuery(pkWrSql, new MapListProcessor());
|
||||
Map<String, Map<String, Object>> detailIdMap = new HashMap<>();
|
||||
for (Map<String, Object> detailMap : detailList) {
|
||||
detailIdMap.put(detailMap.get("vbdef23").toString(), detailMap);
|
||||
}
|
||||
if (detailList.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
String vbdef22 = detailList.get(0).get("vbdef22") + "";// 流程生产订单主键
|
||||
// 查询流程生产订单的VO
|
||||
PMOAggVO[] pmoAggVOS = pmoQueryService.queryByPks(new String[]{vbdef22});
|
||||
// 调用单据转换规则转换出流程生产报告的VO
|
||||
AggWrVO[] vos = (AggWrVO[]) PFPubService.runChangeData(MMBillType.ProduceOrder.getCode(), MMBillType.ProduceReport.getCode(),
|
||||
pmoAggVOS, null, PfButtonClickContext.ClassifyByItfdef);
|
||||
if (MMValueCheck.isEmpty(vos)) {
|
||||
continue;
|
||||
}
|
||||
// 根据IMS字段赋值
|
||||
for (AggWrVO vo : vos) {
|
||||
WrVO hvo = vo.getParentVO();
|
||||
WrItemVO[] bvos = vo.getChildrenVO();
|
||||
hvo.setVbillcode(mainMap.get("vbillcode") + "");
|
||||
hvo.setCreator("BIP");
|
||||
hvo.setBillmaker("BIP");
|
||||
String dmakedateStr = "";
|
||||
if (mainMap.get("dmakedate") != null) {
|
||||
Timestamp dmakedate1 = (Timestamp) mainMap.get("dmakedate");
|
||||
dmakedateStr = sdf.format(dmakedate1);
|
||||
UFDate dmakedate = new UFDate(dmakedateStr);
|
||||
hvo.setDmakedate(dmakedate);
|
||||
}
|
||||
if (mainMap.get("creationtime") != null) {
|
||||
Timestamp creationtime1 = (Timestamp) mainMap.get("creationtime");
|
||||
String creationtimeStr = sdf_ts.format(creationtime1);
|
||||
UFDateTime creationtime = new UFDateTime(creationtimeStr);
|
||||
hvo.setCreationtime(creationtime);
|
||||
}
|
||||
for (WrItemVO bvo : bvos) {
|
||||
bvo.setFbproducttype(1);// 产品类型 1.主产品
|
||||
bvo.setTbstarttime(new UFDateTime(dmakedateStr + " 00:00:00"));// 开始时间
|
||||
bvo.setTbendtime(new UFDateTime(dmakedateStr + " 23:59:59"));// 结束时间
|
||||
String cbmobid = bvo.getCbmobid();// 流程生产订单明细id
|
||||
Map<String, Object> detailMap = detailIdMap.get(cbmobid);
|
||||
if (detailMap != null) {
|
||||
// 物料或数量替换
|
||||
bvo.setNbplanwrnum(new UFDouble((BigDecimal) detailMap.get("nbplanwrnum")));// 计划完工主数量
|
||||
bvo.setNbplanwrastnum(new UFDouble((BigDecimal) detailMap.get("nbplanwrastnum")));// 计划完工数量
|
||||
bvo.setNbwrnum(new UFDouble((BigDecimal) detailMap.get("nbwrnum")));// 完工主数量
|
||||
bvo.setNbwrastnum(new UFDouble((BigDecimal) detailMap.get("nbwrastnum")));// 完工数量
|
||||
// 如果物料不相等,则BIP物料替换为IMS物料
|
||||
String cbmaterialvid = bvo.getCbmaterialvid();
|
||||
String goodsCode = detailMap.get("cbmaterialvid") + "";
|
||||
String goodsId = MyHelper.getStrValByCondition(MaterialVO.getDefaultTableName(), MaterialVO.PK_MATERIAL,
|
||||
MaterialVO.CODE + " = '" + goodsCode + "'");
|
||||
if (!cbmaterialvid.equals(goodsId)) {
|
||||
bvo.setCbmaterialvid(goodsId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
AggWrVO[] resultvos = null;
|
||||
try {
|
||||
resultvos = wrService.insert(vos);
|
||||
} catch (BusinessException e) {
|
||||
Logger.error("ProductReportGyImsPlugin Error: ", e);
|
||||
NCCForUAPLogger.debug("ProductReportGyImsPlugin Error: " + e.getMessage());
|
||||
String updateSql = "update BIPReportMainTab set err_msg = '[err_msg]' where pk_wr = '[pkWr]'";
|
||||
updateSql = updateSql.replace("[err_msg]", e.getMessage());
|
||||
updateSql = updateSql.replace("[pkWr]", pkWr);
|
||||
NCCForUAPLogger.debug("ProductReportGyImsPlugin-updateSql = " + updateSql);
|
||||
getImsDao().executeUpdate(updateSql);
|
||||
}
|
||||
if (MMValueCheck.isEmpty(resultvos)) {
|
||||
continue;
|
||||
}
|
||||
pkWrSet.add(pkWr);
|
||||
}
|
||||
if (!pkWrSet.isEmpty()) {
|
||||
// 修改状态为 完成
|
||||
String inSql = SqlUtils.getInStr("pk_wr", pkWrSet.toArray(new String[0]), Boolean.TRUE);
|
||||
String updateSql = "update BIPReportMainTab set status = '2' where " + inSql;
|
||||
getImsDao().executeUpdate(updateSql);
|
||||
}
|
||||
// 正常结束
|
||||
TransactionFactory.getTMProxy().end(null);
|
||||
Logger.error("---end----任务结束运行--");
|
||||
} catch (Exception e) {
|
||||
// 异常回滚
|
||||
TransactionFactory.getTMProxy().end(e);
|
||||
Logger.error("ProductReportGyImsPlugin Error: ", e);
|
||||
NCCForUAPLogger.debug("ProductReportGyImsPlugin Error: " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue