物料推送高压优化
This commit is contained in:
parent
f749970424
commit
029a9d9966
|
|
@ -0,0 +1,245 @@
|
|||
package nc.impl.bd.material.baseinfo;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import nc.bs.bd.baseservice.ArrayClassConvertUtil;
|
||||
import nc.bs.businessevent.IBusinessEvent;
|
||||
import nc.bs.businessevent.IBusinessListener;
|
||||
import nc.bs.businessevent.bd.BDCommonEvent;
|
||||
import nc.bs.dao.BaseDAO;
|
||||
import nc.bs.framework.common.NCLocator;
|
||||
import nc.bs.logging.Log;
|
||||
import nc.bs.uapbd.util.MyHelper;
|
||||
import nc.bs.uapbd.util.ThirdPartyPostRequestUtil;
|
||||
import nc.itf.scmpub.reference.uap.bd.material.MaterialPubService;
|
||||
import nc.jdbc.framework.processor.MapProcessor;
|
||||
import nc.pubitf.uapbd.IMaterialPubService;
|
||||
import nc.util.mmf.framework.base.MMValueCheck;
|
||||
import nc.vo.am.common.util.StringUtils;
|
||||
import nc.vo.bd.material.MaterialVO;
|
||||
import nc.vo.bd.material.marbasclass.MarBasClassVO;
|
||||
import nc.vo.bd.material.plan.MaterialPlanVO;
|
||||
import nc.vo.bd.material.stock.MaterialStockVO;
|
||||
import nc.vo.bd.pub.BDCacheQueryUtil;
|
||||
import nc.vo.org.OrgVO;
|
||||
import nc.vo.pub.BusinessException;
|
||||
import nc.vo.pub.lang.UFBoolean;
|
||||
import nc.vo.sm.UserVO;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class MaterialToGyMesListener implements IBusinessListener {
|
||||
private static final String LOG_INFO_NAME = "gyMesLog";
|
||||
private static final Log logger = Log.getInstance(LOG_INFO_NAME);
|
||||
private static final String addUrl = "/bip/order/materialAdd";
|
||||
private static final String updateUrl = "/bip/order/materialUpdate";
|
||||
private Map<String, String> configParams;
|
||||
private BaseDAO baseDAO = new BaseDAO();
|
||||
public void doAction(IBusinessEvent event) throws BusinessException {
|
||||
BDCommonEvent e = (BDCommonEvent) event;
|
||||
String eventType = event.getEventType();
|
||||
Object[] objs = e.getObjs();
|
||||
String materialid = ((MaterialStockVO) objs[0]).getPk_material();
|
||||
MaterialVO[] useVOs = (MaterialVO[]) BDCacheQueryUtil.queryVOsByIDs(
|
||||
MaterialVO.class,
|
||||
MaterialVO.PK_MATERIAL,
|
||||
new String[]{materialid},
|
||||
new String[]{MaterialVO.PK_MEASDOC});
|
||||
configParams = MyHelper.getConfigParams("gy-config", null);
|
||||
if (configParams.isEmpty()) {
|
||||
throw new BusinessException("高压的gymes接口缺少配置");
|
||||
}
|
||||
buildSyncData(useVOs, eventType);
|
||||
}
|
||||
/**
|
||||
* 构建同步数据
|
||||
*/
|
||||
private void buildSyncData(MaterialVO[] useVOs, String eventType) throws BusinessException {
|
||||
String orgId = MyHelper.transferField(OrgVO.getDefaultTableName(), OrgVO.PK_ORG, OrgVO.CODE, "C003");
|
||||
JSONArray dataArr = new JSONArray();
|
||||
for (MaterialVO vo : useVOs) {
|
||||
String pkMaterial = vo.getPk_material();
|
||||
// 判断物料的业务单元是否是高压公司,不是则跳过
|
||||
// String pkOrg = vo.getPk_org();
|
||||
Integer num = MyHelper.checkIfOrg(configParams, pkMaterial, "gyOrg");
|
||||
if (!"1009".equals(eventType) && (num <= 0)) {
|
||||
continue;
|
||||
}
|
||||
// 字段值翻译
|
||||
String pk_marbasclass = vo.getPk_marbasclass();
|
||||
String mrlTypeName = MyHelper.getStrValByCondition(MarBasClassVO.getDefaultTableName(), MarBasClassVO.NAME,
|
||||
"pk_marbasclass = '" + pk_marbasclass + "'");
|
||||
// 计量单位
|
||||
Map unitMap = getGoodsInfo(pkMaterial);
|
||||
Map<String, MaterialPlanVO> planMap = queryMaterialPlanInfoByPks(new String[]{pkMaterial}, orgId,
|
||||
new String[]{MaterialPlanVO.ISVIRTUAL});
|
||||
UFBoolean isvirtual = new UFBoolean(false);
|
||||
if (MMValueCheck.isNotEmpty(planMap) &&
|
||||
MMValueCheck.isNotEmpty(planMap.get(pkMaterial))) {
|
||||
isvirtual = planMap.get(pkMaterial).getIsvirtual();
|
||||
}
|
||||
// 库存
|
||||
Map stockMap = getStockInfo(pkMaterial);
|
||||
// 生产报告
|
||||
Map prodMap = getProdInfo(pkMaterial);
|
||||
// creator 创建人
|
||||
String creator = vo.getCreator();
|
||||
String creatorName = MyHelper.getStrValByCondition("sm_user", UserVO.USER_NAME,
|
||||
UserVO.CUSERID + " = '" + creator + "'");
|
||||
// 1=未启用;2=已启用;3=已停用;
|
||||
Integer enablestate = vo.getEnablestate() != null ? vo.getEnablestate() : 1;
|
||||
// 组装数据
|
||||
JSONObject singleObj = new JSONObject();
|
||||
singleObj.put("materialCode", vo.getCode()); // 物料编码
|
||||
singleObj.put("bipMaterialId", pkMaterial); // 物料主键
|
||||
singleObj.put("materialName", vo.getName()); // 物料名称
|
||||
singleObj.put("materialCategory", pk_marbasclass); // 物料分类
|
||||
singleObj.put("specification", vo.getMaterialspec()); // 规格
|
||||
singleObj.put("model", vo.getMaterialtype()); // 型号文字
|
||||
singleObj.put("intervalModel", "(物料自定义字段)"); // 产品类型 例如35-KV-断路器(物料自定义字段)
|
||||
singleObj.put("primaryUnit", unitMap.get("measrate").toString().split("/")[0]);
|
||||
// 主单位
|
||||
singleObj.put("materialUnit", unitMap.get("measrate").toString().split("/")[1]); // 单位
|
||||
singleObj.put("drawingNumber", vo.getGraphid()); // 图号编码
|
||||
singleObj.put("enableStatus", enablestate - 1); // 启用状态 0 未启动 1 已启动 2 已停用
|
||||
singleObj.put("materialType", stockMap.get("martype")); // 物料类型编码
|
||||
singleObj.put("batchManagement", stockMap.get("wholemanaflag")); // 批次管理
|
||||
singleObj.put("outboundPriority", stockMap.get("outpriority")); // 出库优先级
|
||||
singleObj.put("mainWarehouse", stockMap.get("pk_stordoc")); // 主仓库
|
||||
singleObj.put("reservation", stockMap.get("remain")); // 预留
|
||||
singleObj.put("virtualItem", isvirtual.toString()); // 虚项
|
||||
singleObj.put("productionDepartment", prodMap.get("deptCode")); // 生产部门编码
|
||||
singleObj.put("matchingComponents", prodMap.get("iscreatesonprodorder")); // 配套子件
|
||||
singleObj.put("issuance", prodMap.get("issend")); // 发料
|
||||
singleObj.put("backflushMethod", prodMap.get("conversemethod")); // 倒冲方式
|
||||
singleObj.put("postCompletionProcessing", prodMap.get("wghxcl")); // 完工后续处理
|
||||
singleObj.put("bipCreateBy", creatorName); // 创建人
|
||||
dataArr.add(singleObj);
|
||||
/**
|
||||
* {
|
||||
* "list": [
|
||||
* {
|
||||
* "materialCode": "物料编码",
|
||||
* "bipMaterialId": "物料主键",
|
||||
* "materialName": "物料名称",
|
||||
* "materialCategory": "物料分类",
|
||||
* "specification": "规格例如 台 件",
|
||||
* "intervalModel": "产品类型 例如35-KV-断路器(物料自定义字段)",
|
||||
* "primaryUnit": "主单位例如 1 ",
|
||||
* "materialUnit": "单位例如 1 ",
|
||||
* "drawingNumber": "图号编码 如 X56434 高压",
|
||||
* "enableStatus": "启用状态 0 未启动 1 已启动 2 已停用",
|
||||
* "materialType": "物料类型编码",
|
||||
* "batchManagement": "批次管理",
|
||||
* "outboundPriority": "出库优先级 按BIP类型",
|
||||
* "mainWarehouse": "主仓库 按BIP类型",
|
||||
* "reservation": "预留 按BIP类型",
|
||||
* "virtualItem": "虚项 按BIP类型",
|
||||
* "productionDepartment": "生产部门编码 按BIP类型",
|
||||
* "matchingComponents": "配套子件 按BIP类型",
|
||||
* "issuance": "发料 按BIP类型",
|
||||
* "backflushMethod": "倒冲方式 按BIP类型",
|
||||
* "postCompletionProcessing": "完工后续处理 按BIP类型",
|
||||
* "bipCreateBy": "创建人"
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
}
|
||||
if (!dataArr.isEmpty()) {
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put("list", dataArr);
|
||||
pushData(jsonObj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送同步数据
|
||||
*/
|
||||
private void pushData(JSONObject param) throws BusinessException {
|
||||
// String jsonString = param.toJSONString();
|
||||
// 转json字符串的时候保留null值
|
||||
String jsonStr = JSON.toJSONString(param,
|
||||
SerializerFeature.WriteMapNullValue,
|
||||
SerializerFeature.WriteNullStringAsEmpty
|
||||
);
|
||||
logger.error("gymes-Material-param = " + jsonStr);
|
||||
// NCCForUAPLogger.debug("gymes-Material-param = " + jsonStr);
|
||||
String baseUrl = configParams.get("mesBaseUrl");
|
||||
String requestUrl = baseUrl + addUrl;
|
||||
logger.error("gymes-Material-url = " + requestUrl);
|
||||
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr);
|
||||
JSONObject resultObj = JSONObject.parseObject(result);
|
||||
logger.error("gymes-Material-res = " + result);
|
||||
|
||||
if (!"200".equals(resultObj.getString("code"))) {
|
||||
// throw new BusinessException("gymes-Material-error:" + resultObj.getString("msg"));
|
||||
logger.error("gymes-Material-error,result[" + resultObj.toJSONString() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
private Map getGoodsInfo(String pkMaterial) throws BusinessException {
|
||||
String sql = " select a.pk_measdoc, c.name unitname, b.pk_measdoc deputyUnit, d.name deputy_unitname, nvl(b.measrate, '1/1') measrate " +
|
||||
"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 " +
|
||||
"left join bd_measdoc d on b.pk_measdoc = d.pk_measdoc " +
|
||||
"where a.pk_material = '" + pkMaterial + "' ";
|
||||
Map map = (Map) new BaseDAO().executeQuery(sql, new MapProcessor());
|
||||
// map.put("convertRate", MyHelper.transferSpecialField(map.get("measrate") + ""));
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map getStockInfo(String pkMaterial) throws BusinessException {
|
||||
String sql = " select martype, wholemanaflag, outpriority, remain,bd_stordoc.code as pk_stordoc" +
|
||||
" from bd_materialstock left join bd_stordoc on bd_stordoc.pk_stordoc = bd_materialstock.pk_stordoc " +
|
||||
" where pk_material = '" + pkMaterial + "' ";
|
||||
Map map = (Map) new BaseDAO().executeQuery(sql, new MapProcessor());
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map getProdInfo(String pkMaterial) throws BusinessException {
|
||||
String sql = "SELECT b.code deptCode, a.iscreatesonprodorder, a.issend, a.conversemethod, a.converstime, a.wghxcl" +
|
||||
" pk_materialprod " +
|
||||
"FROM " +
|
||||
" bd_materialprod a" +
|
||||
" left join org_dept b on a.pk_prodeptdoc = b.pk_dept " +
|
||||
" where a.pk_material = '" + pkMaterial + "' ";
|
||||
Map map = (Map) new BaseDAO().executeQuery(sql, new MapProcessor());
|
||||
return map;
|
||||
}
|
||||
|
||||
private boolean checkIfOrg(String code, Map<String, String> configParams) throws BusinessException {
|
||||
String targetCode = configParams.get("mesBaseUrl");
|
||||
if (targetCode == null || StringUtils.isEmpty(targetCode)) {
|
||||
throw new BusinessException("未配置组织参数");
|
||||
}
|
||||
String[] orgItem = targetCode.split(",");
|
||||
for (String orgCode : orgItem) {
|
||||
if (!orgCode.isEmpty() && orgCode.equals(code)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Map<String, MaterialPlanVO> queryMaterialPlanInfoByPks(String[] pks, String pk_stockorg,
|
||||
String[] fields) throws BusinessException {
|
||||
Map<String, MaterialPlanVO> map = null;
|
||||
List<String> vids = Stream.of(pks).filter(Objects::nonNull).distinct().toList();
|
||||
if (vids.isEmpty()) {
|
||||
map = new HashMap<>();
|
||||
} else {
|
||||
map = NCLocator.getInstance().lookup(IMaterialPubService.class)
|
||||
.queryMaterialPlanInfoByPks(vids.toArray(new String[0]), pk_stockorg, fields);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
@ -207,7 +207,7 @@ public class MaterialToGyMesListener implements IBusinessListener {
|
|||
logger.error("gymes-Material-param = " + jsonStr);
|
||||
// NCCForUAPLogger.debug("gymes-Material-param = " + jsonStr);
|
||||
String baseUrl = configParams.get("mesBaseUrl");
|
||||
String requestUrl = baseUrl + addUrl;
|
||||
String requestUrl = baseUrl + updateUrl;
|
||||
logger.error("gymes-Material-url = " + requestUrl);
|
||||
String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr);
|
||||
JSONObject resultObj = JSONObject.parseObject(result);
|
||||
|
|
|
|||
Loading…
Reference in New Issue