feat(mes):优化失败推送物料同步的定时任务-电力电子-艾普
This commit is contained in:
parent
258d1b5f15
commit
677b785f96
|
|
@ -19,19 +19,26 @@ import nc.vo.bd.material.MaterialVO;
|
|||
import nc.vo.fi.pub.SqlUtils;
|
||||
import nc.vo.org.OrgVO;
|
||||
import nc.vo.pub.BusinessException;
|
||||
import nc.vo.pubapp.pattern.data.ValueUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 物料-艾普MES-定时重推失败的数据
|
||||
*
|
||||
* @author mzr
|
||||
* @date 20251006
|
||||
* @date 2025-10-06
|
||||
*/
|
||||
public class MaterialToEpicMesPlugin implements IBackgroundWorkPlugin {
|
||||
private static final String LOG_INFO_NAME = "syscron";
|
||||
private static final Log logDl = Log.getInstance(LOG_INFO_NAME);
|
||||
private static final String reqUrl = "/prj-v5-web/ext/api/mrl";
|
||||
private String startDate = "";
|
||||
private Map<String, String> configParams;
|
||||
private BaseDAO dao;
|
||||
|
||||
|
|
@ -45,45 +52,75 @@ public class MaterialToEpicMesPlugin implements IBackgroundWorkPlugin {
|
|||
@Override
|
||||
public PreAlertObject executeTask(BgWorkingContext bgWorkingContext) throws BusinessException {
|
||||
try {
|
||||
String sql = " select * from v_mes_material_cron";
|
||||
List<Map<String, String>> pkList = (List<Map<String, String>>) getDao().executeQuery(sql.toString(), new MapListProcessor());
|
||||
if (pkList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
this.initParams(bgWorkingContext);
|
||||
configParams = MyHelper.getConfigParams("Dldz-config", null);
|
||||
if (configParams.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
List<Map<String, String>> pkList = this.getPkList();
|
||||
if (pkList == null || pkList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
HYPubBO hyPub = new HYPubBO();
|
||||
List<MaterialVO> voList = new ArrayList<>();
|
||||
for (Map<String, String> map : pkList) {
|
||||
String pkMaterial = map.get("pk_material");
|
||||
MaterialVO materialVO = (MaterialVO) hyPub.queryByPrimaryKey(MaterialVO.class, pkMaterial);
|
||||
voList.add(materialVO);
|
||||
if (materialVO != null) {
|
||||
voList.add(materialVO);
|
||||
}
|
||||
}
|
||||
if (!voList.isEmpty()) {
|
||||
MaterialVO[] useVOs = voList.toArray(new MaterialVO[0]);
|
||||
buildSyncData(useVOs);
|
||||
buildSyncData(voList);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logDl.error("BomToEpicMesPlugin-exp:" + e.getMessage(), e);
|
||||
logDl.error("MaterialToEpicMesPlugin-exp:" + e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Map<String, String>> getPkList() throws BusinessException {
|
||||
String targetCode = configParams.get("dldzOrg");
|
||||
if (targetCode == null || MMValueCheck.isEmpty(targetCode)) {
|
||||
throw new BusinessException("未配置组织参数");
|
||||
}
|
||||
String[] orgItem = targetCode.split(",");
|
||||
String inStr = SqlUtils.getInStr("code", orgItem, true);
|
||||
String orgSql = " SELECT pk_stockorg,code,name FROM org_stockorg WHERE DR = 0 AND " + inStr;
|
||||
List<Map<String, String>> orgList = (List<Map<String, String>>) getDao().executeQuery(orgSql, new MapListProcessor());
|
||||
if (orgList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
String[] stockorgs = orgList.stream().map(map -> map.get("pk_stockorg")).distinct().toArray(String[]::new);
|
||||
String inStrPkOrg = SqlUtils.getInStr("b.pk_org", stockorgs, true);
|
||||
// 查询最近改过基本信息和库存信息的物料
|
||||
LocalDateTime nowTime = LocalDateTime.now();
|
||||
String timeString = nowTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
String rangeTimeString = timeString + " 00:00:00";
|
||||
if (MMValueCheck.isNotEmpty(startDate)) {
|
||||
// 如果有指定的开始时间,使用指定的时间限制查询条件
|
||||
rangeTimeString = startDate;
|
||||
}
|
||||
String sql = " SELECT DISTINCT b.pk_material" +
|
||||
" FROM bd_materialstock b" +
|
||||
" LEFT JOIN bd_material a ON a.pk_material = b.pk_material" +
|
||||
" WHERE b.dr = 0 AND a.dr = 0 AND def30 != 'Y'" +
|
||||
" AND " + inStrPkOrg +
|
||||
" AND (b.ts > '" + rangeTimeString + "' OR a.ts > '" + rangeTimeString + "')";
|
||||
List<Map<String, String>> pkList = (List<Map<String, String>>) getDao().executeQuery(sql, new MapListProcessor());
|
||||
return pkList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建同步数据
|
||||
*/
|
||||
private void buildSyncData(MaterialVO[] useVOs) throws BusinessException {
|
||||
private void buildSyncData(List<MaterialVO> useVOs) throws BusinessException {
|
||||
for (MaterialVO vo : useVOs) {
|
||||
String pkMaterial = vo.getPk_material();
|
||||
// 判断物料的业务单元是否是电力电子公司,不是则跳过
|
||||
String pkOrg = vo.getPk_org();
|
||||
String orgCode = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.CODE, OrgVO.PK_ORG, pkOrg);
|
||||
// 字段值翻译
|
||||
// String pk_marbasclass = vo.getPk_marbasclass();
|
||||
// String mrlTypeCOde = MyHelper.transferField(MarBasClassVO.getDefaultTableName(), MarBasClassVO.CODE, MarBasClassVO.PK_MARBASCLASS, pk_marbasclass);
|
||||
// 计量单位
|
||||
Map unitMap = getGoodsInfo(pkMaterial);
|
||||
|
||||
|
|
@ -107,14 +144,14 @@ public class MaterialToEpicMesPlugin implements IBackgroundWorkPlugin {
|
|||
singleObj.put("mrlType", getGoodsType(pkMaterial));// 物料分类 制造1 其它0
|
||||
singleObj.put("convertRate", unitMap.getOrDefault("convertRate", "1"));// 单位换算率
|
||||
// singleObj.put("isCheck", "1");// 是否选中(1:是,0:否)
|
||||
pushData(singleObj, useVOs);
|
||||
pushData(singleObj, pkMaterial);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送同步数据
|
||||
*/
|
||||
private void pushData(JSONObject param, MaterialVO[] useVOs) throws BusinessException {
|
||||
private void pushData(JSONObject param, String pkMaterial) throws BusinessException {
|
||||
// String jsonString = param.toJSONString();
|
||||
// 转json字符串的时候保留null值
|
||||
String jsonStr = JSON.toJSONString(param,
|
||||
|
|
@ -133,9 +170,8 @@ public class MaterialToEpicMesPlugin implements IBackgroundWorkPlugin {
|
|||
if (!"1".equals(resultObj.getString("flag"))) {
|
||||
// throw new BusinessException("EpicMes-Material-error:" + resultObj.getString("msg"));
|
||||
logDl.error("EpicMes-Material-error,result[" + resultObj.toJSONString() + "]");
|
||||
handleSyncMaterialExp(useVOs, "N", resultObj.getString("msg"));
|
||||
} else {
|
||||
handleSyncMaterialExp(useVOs, "Y", "");
|
||||
handleSyncMaterialExp(pkMaterial, "Y");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -202,33 +238,22 @@ public class MaterialToEpicMesPlugin implements IBackgroundWorkPlugin {
|
|||
/**
|
||||
* 更新错误信息
|
||||
*/
|
||||
private void handleSyncMaterialExp(MaterialVO[] vos, String errorCode, String errorMsg) {
|
||||
if (MMValueCheck.isEmpty(vos)) {
|
||||
private void handleSyncMaterialExp(String pk_material, String errorCode) {
|
||||
if (MMValueCheck.isEmpty(pk_material)) {
|
||||
return;
|
||||
}
|
||||
Set<String> ids = new HashSet<>();
|
||||
for (MaterialVO vo : vos) {
|
||||
String pkMaterial = vo.getPk_material();
|
||||
ids.add(pkMaterial);
|
||||
}
|
||||
// 定义每批次处理的最大数量
|
||||
int batchSize = 500;
|
||||
try {
|
||||
List<String> idList = new ArrayList<>(ids);
|
||||
for (int i = 0; i < idList.size(); i += batchSize) {
|
||||
// 取出当前批次的ID
|
||||
List<String> batchIds = idList.subList(i, Math.min(i + batchSize, idList.size()));
|
||||
|
||||
// 构造并执行SQL
|
||||
String inSql = SqlUtils.getInStr("pk_material", batchIds.toArray(new String[0]), Boolean.TRUE);
|
||||
String updateSql = "update bd_material set def30 = '[errorCode]' where " + inSql;
|
||||
updateSql = updateSql.replace("[errorCode]", errorCode);
|
||||
// NCCForUAPLogger.debug("EpicMes-handleSyncMaterialExp-updateSql = " + updateSql);
|
||||
int updatedRows = getDao().executeUpdate(updateSql);
|
||||
// NCCForUAPLogger.debug("EpicMes-Material-handleSyncMaterialExp-updateRows = " + updatedRows);
|
||||
}
|
||||
String updateSql = "update bd_material set def30 = '[errorCode]' where pk_material = '[pk_material]'";
|
||||
updateSql = updateSql.replace("[pk_material]", pk_material);
|
||||
updateSql = updateSql.replace("[errorCode]", errorCode);
|
||||
int updatedRows = getDao().executeUpdate(updateSql);
|
||||
} catch (BusinessException e) {
|
||||
logDl.error("EpicMes-Material-handleSyncMaterialExp = " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void initParams(BgWorkingContext bgwc) {
|
||||
this.startDate = ValueUtils.getString(bgwc.getKeyMap().get("startDate"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue