diff --git a/uapbd/src/private/nccloud/api/uapbd/supplier/tms/listene/SupplierVoListener.java b/uapbd/src/private/nccloud/api/uapbd/supplier/tms/listene/SupplierVoListener.java new file mode 100644 index 0000000..d1db6c5 --- /dev/null +++ b/uapbd/src/private/nccloud/api/uapbd/supplier/tms/listene/SupplierVoListener.java @@ -0,0 +1,104 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package nccloud.api.uapbd.supplier.tms.listene; + +import java.util.*; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import nc.bs.bd.baseservice.ArrayClassConvertUtil; +import nc.bs.bd.baseservice.md.VOArrayUtil; +import nc.bs.businessevent.IBusinessEvent; +import nc.bs.businessevent.IBusinessListener; +import nc.bs.businessevent.bd.BDCommonEvent; +import nc.bs.dao.BaseDAO; +import nc.bs.logging.Log; +import nc.bs.trade.business.HYPubBO; +import nc.bs.uapbd.util.MyHelper; +import nc.bs.uapbd.util.ThirdPartyPostRequestUtil; +import nc.vo.bd.supplier.SupplierVO; +import nc.vo.pub.BusinessException; +import nccloud.baseapp.core.log.NCCForUAPLogger; +import nccloud.commons.lang.ArrayUtils; + +public class SupplierVoListener implements IBusinessListener { + private static final String LOG_INFO_NAME = "dldzlog"; + private static final Log logDl = Log.getInstance(LOG_INFO_NAME); + private static final String reqUrl = "/prj-v5-web/ext/api/supplier"; + private Map configParams; + public SupplierVoListener() { + } + + public void doAction(IBusinessEvent event) throws BusinessException { + BDCommonEvent e = (BDCommonEvent)event; + configParams = MyHelper.getConfigParams("Dldz-config", null); + String modifyType = ""; +// EventType是事件编码 1002-新增后 1004-修改后 1006-删除后 + if ("1002".equals(e.getEventType())) { + modifyType = "I"; + SupplierVO[] newvos = ArrayClassConvertUtil.convert(e.getObjs(), SupplierVO.class); + this.putSupplier(newvos, modifyType); + }else if("1004".equals(e.getEventType())) { + modifyType = "U"; + SupplierVO[] newvos = ArrayClassConvertUtil.convert(e.getObjs(), SupplierVO.class); + this.putSupplier(newvos, modifyType); + }else if("1006".equals(e.getEventType())) { + modifyType = "D"; + SupplierVO[] newvos = ArrayClassConvertUtil.convert(e.getObjs(), SupplierVO.class); + this.putSupplier(newvos, modifyType); + } + + + + } + + private void putSupplier(SupplierVO[] objs, String modifyType) throws BusinessException { + if (!ArrayUtils.isEmpty(objs)) { + List> list = new ArrayList>(); + JSONObject jsonObject=new JSONObject(); + for (SupplierVO obj : objs) { + Map map = new HashMap(); + map.put("supplierName", obj.getName()); + map.put("supplierCode", obj.getCode()); + String supplierTypeId=obj.getPk_supplierclass(); + HYPubBO hy = new HYPubBO(); +// OrgVO orgvo = (OrgVO)hy.queryByPrimaryKey(OrgVO.class, ); + + String supplierType = (String) hy.findColValue("bd_supplierclass", "code", "code = '"+supplierTypeId+"' "); + map.put("supplierType", supplierType.substring(0,1)); + map.put("status", modifyType); + list.add(map); + } + JSONObject result = JSONObject.parseObject(JSONObject.toJSONString(list)); + pushData(result); + } + } + /** + * 推送同步数据 + */ + private void pushData(JSONObject param) throws BusinessException { + // String jsonString = param.toJSONString(); + // 转json字符串的时候保留null值 + String jsonStr = JSON.toJSONString(param, + SerializerFeature.WriteMapNullValue, + SerializerFeature.WriteNullStringAsEmpty + ); + logDl.error("EpicMes-Supplier-param = " + jsonStr); + NCCForUAPLogger.debug("EpicMes-Supplier-param = " + jsonStr); + String baseUrl = configParams.get("epicMesUrl"); + String requestUrl = baseUrl + reqUrl; + logDl.error("EpicMes-Supplier-url = " + requestUrl); + String result = ThirdPartyPostRequestUtil.sendPostRequest(requestUrl, jsonStr); + JSONObject resultObj = JSONObject.parseObject(result); + logDl.error("EpicMes-Supplier-res = " + result); + + if (!"1".equals(resultObj.getString("flag"))) { + // throw new BusinessException("EpicMes-Supplier-error:" + resultObj.getString("msg")); + logDl.error("EpicMes-Supplier-error,result[" + resultObj.toJSONString() + "]"); + } + } +}