diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/dao/IWsCustomerSynchronizationEventDao.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/dao/IWsCustomerSynchronizationEventDao.java new file mode 100644 index 00000000..83745d46 --- /dev/null +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/dao/IWsCustomerSynchronizationEventDao.java @@ -0,0 +1,18 @@ +package com.hzya.frame.plugin.wscustomersynchronizationevent.dao; + + +import com.hzya.frame.basedao.dao.IBaseDao; +import com.hzya.frame.plugin.wscustomersynchronizationevent.entity.WsCustomerSynchronizationEventEntity; + +/**** + * 万盛客商档案同步插件 + * @content: + * @author 👻👻👻👻👻👻👻👻 gjh + * @date 2025-03-03 10:57 + * @param + * @return + **/ +public interface IWsCustomerSynchronizationEventDao extends IBaseDao { + +} + diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/dao/impl/WsCustomerSynchronizationEventDaoImpl.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/dao/impl/WsCustomerSynchronizationEventDaoImpl.java new file mode 100644 index 00000000..e6839c9e --- /dev/null +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/dao/impl/WsCustomerSynchronizationEventDaoImpl.java @@ -0,0 +1,18 @@ +package com.hzya.frame.plugin.wscustomersynchronizationevent.dao.impl; + +import com.hzya.frame.basedao.dao.MybatisGenericDao; +import com.hzya.frame.plugin.wscustomersynchronizationevent.dao.IWsCustomerSynchronizationEventDao; +import com.hzya.frame.plugin.wscustomersynchronizationevent.entity.WsCustomerSynchronizationEventEntity; + + /*** + * 万盛客商 + * @content: + * @author 👻👻👻👻👻👻👻👻 gjh + * @date 2025-03-03 11:12 + * @param + * @return + **/ +public class WsCustomerSynchronizationEventDaoImpl extends MybatisGenericDao implements IWsCustomerSynchronizationEventDao { + +} + diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/entity/WsCustomerSynchronizationEventEntity.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/entity/WsCustomerSynchronizationEventEntity.java new file mode 100644 index 00000000..787a82dc --- /dev/null +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/entity/WsCustomerSynchronizationEventEntity.java @@ -0,0 +1,16 @@ +package com.hzya.frame.plugin.wscustomersynchronizationevent.entity; + +import com.hzya.frame.web.entity.BaseEntity; + +/**** + * 万盛客商档案实体类 + * @content: + * @author 👻👻👻👻👻👻👻👻 gjh + * @date 2025-03-03 10:53 + * @param + * @return + **/ +public class WsCustomerSynchronizationEventEntity extends BaseEntity { + +} + diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/entity/WsCustomerSynchronizationEventEntity.xml b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/entity/WsCustomerSynchronizationEventEntity.xml new file mode 100644 index 00000000..d2179ee8 --- /dev/null +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/entity/WsCustomerSynchronizationEventEntity.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + id + + + + + + + + + + diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/plugin/WsCustomerSynchronizationEventPluginInitializer.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/plugin/WsCustomerSynchronizationEventPluginInitializer.java new file mode 100644 index 00000000..41412122 --- /dev/null +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/plugin/WsCustomerSynchronizationEventPluginInitializer.java @@ -0,0 +1,64 @@ +package com.hzya.frame.plugin.wscustomersynchronizationevent.plugin; +import com.alibaba.fastjson.JSONObject; +import com.hzya.frame.base.PluginBaseEntity; +import com.hzya.frame.plugin.wscustomersynchronizationevent.service.IWsCustomerSynchronizationEventService; +import com.hzya.frame.sysnew.comparison.masterData.service.IMasterDataService; +import com.hzya.frame.web.entity.BaseResult; +import com.hzya.frame.web.entity.JsonResultEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * 主数据同步 + * + * @author makejava + * @since 2024-06-21 13:52:35 + */ +public class WsCustomerSynchronizationEventPluginInitializer extends PluginBaseEntity{ + Logger logger = LoggerFactory.getLogger(WsCustomerSynchronizationEventPluginInitializer.class); + @Autowired + private IWsCustomerSynchronizationEventService customerSynchronizationEventService; + + @Override + public void initialize() { + logger.info(getPluginLabel() + "執行初始化方法initialize()"); + } + + @Override + public void destroy() { + logger.info(getPluginLabel() + "執行銷毀方法destroy()"); + } + + @Override + public String getPluginId() { + return "WsCustomerSynchronizationEventPluginInitializer"; + } + + @Override + public String getPluginName() { + return "万盛A8客商接收数据插件"; + } + + @Override + public String getPluginLabel() { + return "WsCustomerSynchronizationEventPluginInitializer"; + } + + @Override + public String getPluginType() { + return "1"; + } + @Override + public JsonResultEntity executeBusiness(JSONObject requestJson) { + try { + logger.info("======开始执行客商档案同步========"); + return customerSynchronizationEventService.customerSynchronization(requestJson); +// return masterDataService.queryArchives(requestJson); + }catch (Exception e){ + logger.info("======客商档案同步失败:{}========",e.getMessage()); + e.printStackTrace(); + } + return null; + } +} diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/service/IWsCustomerSynchronizationEventService.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/service/IWsCustomerSynchronizationEventService.java new file mode 100644 index 00000000..a0599e57 --- /dev/null +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/service/IWsCustomerSynchronizationEventService.java @@ -0,0 +1,28 @@ +package com.hzya.frame.plugin.wscustomersynchronizationevent.service; + +import com.alibaba.fastjson.JSONObject; +import com.hzya.frame.basedao.service.IBaseService; +import com.hzya.frame.plugin.wscustomersynchronizationevent.entity.WsCustomerSynchronizationEventEntity; +import com.hzya.frame.web.entity.JsonResultEntity; + +/*** + * 万盛客商档案同步插件 + * @content: + * @author 👻👻👻👻👻👻👻👻 gjh + * @date 2025-03-03 10:55 + * @param + * @return + **/ +public interface IWsCustomerSynchronizationEventService extends IBaseService { + + /**** + * 万盛客商档案同步插件,根据不同类型事件处理客商信息 + * @content: onBeforeStart 发起前验证供应商重复 onProcessFinished 结束后同步数据到U8C + * @author 👻👻👻👻👻👻👻👻 gjh + * @date 2025-03-03 14:11 + * @param + * @return com.hzya.frame.web.entity.JsonResultEntity + **/ + JsonResultEntity customerSynchronization(JSONObject requestJson); + +} diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/service/impl/WsCustomerSynchronizationEventServiceImpl.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/service/impl/WsCustomerSynchronizationEventServiceImpl.java new file mode 100644 index 00000000..23a7c1d2 --- /dev/null +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/wscustomersynchronizationevent/service/impl/WsCustomerSynchronizationEventServiceImpl.java @@ -0,0 +1,434 @@ +package com.hzya.frame.plugin.wscustomersynchronizationevent.service.impl; + +import cn.hutool.core.map.MapBuilder; +import cn.hutool.crypto.SecureUtil; +import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.hzya.frame.basedao.service.impl.BaseService; +import com.hzya.frame.plugin.wscustomersynchronizationevent.dao.IWsCustomerSynchronizationEventDao; +import com.hzya.frame.plugin.wscustomersynchronizationevent.entity.WsCustomerSynchronizationEventEntity; +import com.hzya.frame.plugin.wscustomersynchronizationevent.service.IWsCustomerSynchronizationEventService; +import com.hzya.frame.web.entity.BaseResult; +import com.hzya.frame.web.entity.JsonResultEntity; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.HashMap; +import java.util.Map; + +/*** + * 万盛客商档案同步插件 + * @content: + * @author 👻👻👻👻👻👻👻👻 gjh + * @date 2025-03-03 10:56 + * @param + * @return + **/ +public class WsCustomerSynchronizationEventServiceImpl extends BaseService implements IWsCustomerSynchronizationEventService { + + private IWsCustomerSynchronizationEventDao wsCustomerSynchronizationEventDao; + + @Autowired + public void setWsCustomerSynchronizationEventDao(IWsCustomerSynchronizationEventDao wsCustomerSynchronizationEventDao) { + this.wsCustomerSynchronizationEventDao = wsCustomerSynchronizationEventDao; + this.dao = wsCustomerSynchronizationEventDao; + } + + @Override + public JsonResultEntity customerSynchronization(JSONObject requestJson) { + JSONObject reqJson = new JSONObject(); + JSONObject jsonStr = requestJson.getJSONObject("jsonStr"); + JSONObject businessDataStr = jsonStr.getJSONObject("businessDataStr"); + String formAppId = requestJson.getString("formAppId"); + String eventType = requestJson.getString("eventType"); + switch (eventType){ + case "onBeforeStart": + //发起前事件,验证供应商重复 + return validateCustomerName( businessDataStr); + case "onBeforeFinishWorkitem": + //发起前事件,OA插件错误,临时配置事件 + return validateCustomerName( businessDataStr); + case "onProcessFinished": + //流程结束事件,同步客商到U8C + return optionCustomerSynchronization(businessDataStr); + default: + return BaseResult.getFailureMessageEntity("未匹配到流程监听事件!当前传入的eventType:"+eventType); + } + + } + + /**** + * 验证客商档案重复 + * @content: + * @author 👻👻👻👻👻👻👻👻 gjh + * @date 2025-03-03 15:22 + * @param + * @return com.hzya.frame.web.entity.JsonResultEntity + **/ + private JsonResultEntity validateCustomerName(JSONObject data){ + JSONObject formBean = data.getJSONObject("formmain_4389"); + //客商名称 + String field0006 = formBean.getString("field0006"); + //纳税人登记号 + String field0007 = formBean.getString("field0007"); + JSONObject requestJson = new JSONObject(); + requestJson.put("custname",field0006); + requestJson.put("taxpayer",field0007); + String body = requestApi("validateCustomerName",requestJson, "800054","8000540095",null); + JSONObject req = JSON.parseObject(body); + boolean flag = req.getBoolean("flag"); + if(flag){ + JSONObject attribute = req.getJSONObject("attribute"); + String status = attribute.getString("status"); + if("success".equals(status)){ + JSONObject detailsData = attribute.getJSONObject("data"); + Integer allcount = detailsData.getInteger("allcount"); + if(allcount>0){ + return BaseResult.getFailureMessageEntity("客商名称+纳税人识别号重复!"); + }else{ + return BaseResult.getSuccessMessageEntity("客商未重复!"); + } + }else{ + return BaseResult.getFailureMessageEntity("转发失败!"); + } + }else{ + + return BaseResult.getFailureMessageEntity("转发失败!"+req.getString("msg")); + } + + } + + + /**** + * 执行客商同步新增和分配 + * @content: + * @author 👻👻👻👻👻👻👻👻 gjh + * @date 2025-03-04 10:45 + * @param + * @return com.hzya.frame.web.entity.JsonResultEntity + **/ + private JsonResultEntity optionCustomerSynchronization(JSONObject data) { + + JSONObject formBean = data.getJSONObject("formmain_4389"); + //客商名称 + String field0006 = formBean.getString("field0006"); + //纳税人登记号 + String field0007 = formBean.getString("field0007"); + //绑定客商参数 + JSONObject requestJson = bindMerchantParameters(data); + String apiCode = "8000540093"; + String body = requestApi("optionCustomerSynchronization客商新增",requestJson, "800054",apiCode,null); + JSONObject req = JSON.parseObject(body); + boolean flag = req.getBoolean("flag"); + String pk_cubasdoc = null; + if (flag) { + JSONObject attribute = req.getJSONObject("attribute"); + String status = attribute.getString("status"); + if ("success".equals(status)) { + JSONArray returnData = attribute.getJSONArray("data"); + if(null != returnData && returnData.size() >0){ + pk_cubasdoc = returnData.getJSONObject(0).getJSONObject("parentvo").getString("pk_cubasdoc"); + String custcode = returnData.getJSONObject(0).getJSONObject("parentvo").getString("custcode"); + //执行客商档案编码回传OA + updateCustomerCode(custcode); + + } + logger.info("客商新增成功!返回数据",body); + } else { + logger.info("客商新增失败!返回数据",body); + } + } else { + return BaseResult.getFailureMessageEntity("转发失败!" + req.getJSONObject("attribute").getString("errormsg")); + } + //绑定客商分配参数 + requestJson = bindMerchantDefineParameters(data,pk_cubasdoc); + body = requestApi("optionCustomerSynchronization客商分配",requestJson, "800054","8000540094",null); + req = JSON.parseObject(body); + flag = req.getBoolean("flag"); + if (flag) { + JSONObject attribute = req.getJSONObject("attribute"); + String status = attribute.getString("status"); + if ("success".equals(status)) { + logger.info("客商分配成功!返回数据",body); + } else { + logger.info("客商分配失败!返回数据",body); + } + } else { + return BaseResult.getFailureMessageEntity("转发失败!" + req.getJSONObject("attribute").getString("errormsg")); + } + return BaseResult.getSuccessMessageEntity("执行客商同步方法成功"); + + } + + /*** + * 更新OA客商编码 + * @content: + * @author 👻👻👻👻👻👻👻👻 gjh + * @date 2025-03-07 16:43 + * @param + * @return com.alibaba.fastjson.JSONObject + **/ + private JSONObject updateCustomerCode(String code) { + String sql="update formmain_0013 set field0002 = '222' where id = '-1747569164838812797' "; + String md5 = SecureUtil.md5(sql); + System.out.println("明文摘要"+md5); + String key = "`o7eotan9ws8c:aj"; + String encrypt = SecureUtil.aes(key.getBytes()).encryptHex(sql); + JSONObject requestJson = new JSONObject(); + requestJson.put("userName","hzya_rest"); + requestJson.put("password","45562434-8459-47b4-8df0-78fad8405bc4"); + requestJson.put("data",md5); + requestJson.put("sign",encrypt); + String tokenRest = requestApi("获取token", requestJson,"800055", "8000550010",null); + String token = JSON.parseObject(tokenRest).getJSONObject("attribute").getString("id"); + String result = requestApi("更新A8客商档案", requestJson,"800055", "8000550000",token); + //调用OArest接口 + logger.info("更新A8客商档案结果:"+result); + + return null; + } + + /*** + * 绑定客商分配参数 + * @content: + * @author 👻👻👻👻👻👻👻👻 gjh + * @date 2025-03-05 15:02 + * @param + * @param pk_cubasdoc + * @return com.alibaba.fastjson.JSONObject + **/ + private JSONObject bindMerchantDefineParameters(JSONObject data, String pk_cubasdoc) { + JSONObject formBean = data.getJSONObject("formmain_4389"); + JSONObject returnData = new JSONObject(); + JSONArray custbasvo = new JSONArray(); + //客商档案 + JSONObject customer = new JSONObject(); + //币种类别 + String pk_currtype = formBean.getString("field0028"); + switch (pk_currtype){ + case "-4050088431526461175": + //欧元 + pk_currtype = "EUR"; + break; + case "-715249687436703161": + //港币 + pk_currtype = "HKD"; + break; + case "-608291659984190122": + //日元 + pk_currtype = "IPY"; + break; + case "-7769974812583704757": + //英镑 + pk_currtype = "GBP"; + break; + case "169453635852845727": + //新台币 + pk_currtype = "NTD"; + break; + case "-4870779097911440184": + //比素 + pk_currtype = "MXN"; + break; + case "-3124898727237565150": + //人民币 + pk_currtype = "CNY"; + break; + case "-7439566099063946667": + //美元 + pk_currtype = "USD."; + break; + case "-5937286571420073707": + //泰铢 + pk_currtype = "THB"; + break; + default: + pk_currtype = null; + break; + } + customer.put("pk_currtype1",pk_currtype); + //公司 TODO 修改为取编码 pk_corp +// customer.put("pk_corp",formBean.getString("field0056")); + customer.put("pk_corp",formBean.getString("field0056")); + String custprop = formBean.getString("field0027"); + //客商属性 0:客户,1:供应商,2 :客商 + switch (custprop){ + case "4109154014131407336": + //客户 + custprop = "0"; + break; + case "-6536959240623403744": + //供应商 + custprop = "1"; + break; + case "5695613751532077780": + //客商 + custprop = "2"; + break; + default: + custprop = null; + break; + } + customer.put("custprop",custprop); + //客商ID + customer.put("pk_cubasdoc",pk_cubasdoc); + custbasvo.add(customer); + returnData.put("custbasvo",custbasvo); + return returnData; + } + + /**** + * 请求API + * @content: + * @author 👻👻👻👻👻👻👻👻 gjh + * @date 2025-03-04 16:52 + * @param + * @return java.lang.String + **/ + private String requestApi(String method, JSONObject requestJson, String appId,String apiCode,String token) { + Map headerMap = MapBuilder.create(true) + .put("apiCode", String.valueOf(apiCode)) + //这里用中台做为发送方 + .put("publicKey", "ZJYAWb7lhAUTYqekPkU+uHJv1/ObJxb7dT7sD8HPRDGAgyhCe7eDIk+3zDUT+v578prj") + .put("secretKey", "fviZnLBsQUAGF8w8FSOdJi7XlIm/XAZclMxRagDLfTyJFlvnIBF3w66Hrpfzs8cYj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=") + .put("appId",appId) + .build(); + if(null != token){ + headerMap .put("token",token); + } + String body = HttpRequest.post("http://127.0.0.1:10086/kangarooDataCenterV3/entranceController/externalCallInterface").addHeaders(headerMap).body(requestJson.toJSONString()).timeout(60000).execute().body(); + logger.info("中台转发到ESB"+method+":{}", body); + return body; + } + + /**** + * 绑定OA和U8C客商参数 + * @content: + * @author 👻👻👻👻👻👻👻👻 gjh + * @date 2025-03-04 10:53 + * @param + * @return com.alibaba.fastjson.JSONObject + **/ + private JSONObject bindMerchantParameters(JSONObject data) { + JSONObject formBean = data.getJSONObject("formmain_4389"); + JSONObject returnData = new JSONObject(); + JSONArray cbdocvo = new JSONArray(); + //客商档案 + JSONObject customer = new JSONObject(); + JSONArray banks = new JSONArray(); + JSONObject bank = new JSONObject(); + bank.put("accaddr", "银行地址"); + //银行账号 + bank.put("account", formBean.getString("field0011")); + //账户名称 + bank.put("accountname", formBean.getString("field0012")); + bank.put("defflag", "Y"); + bank.put("memo", formBean.getString("field0054")); + //开户银行 + bank.put("pk_bankdoc", formBean.getString("field0013")); + //银行类别 TODO 修改为取编码 + bank.put("banktypename", formBean.getString("field0014")); + //公司 TODO 修改为取编码 pk_corp + bank.put("pk_corp",formBean.getString("field0056")); + //币种类别 + String pk_currtype = formBean.getString("field0028"); + switch (pk_currtype){ + case "-4050088431526461175": + //欧元 + pk_currtype = "EUR"; + break; + case "-715249687436703161": + //港币 + pk_currtype = "HKD"; + break; + case "-608291659984190122": + //日元 + pk_currtype = "IPY"; + break; + case "-7769974812583704757": + //英镑 + pk_currtype = "GBP"; + break; + case "169453635852845727": + //新台币 + pk_currtype = "NTD"; + break; + case "-4870779097911440184": + //比素 + pk_currtype = "MXN"; + break; + case "-3124898727237565150": + //人民币 + pk_currtype = "CNY"; + break; + case "-7439566099063946667": + //美元 + pk_currtype = "USD."; + break; + case "-5937286571420073707": + //泰铢 + pk_currtype = "THB"; + break; + default: + pk_currtype = null; + break; + } + bank.put("pk_currtype",pk_currtype); + banks.add(bank); + JSONObject parentvo = new JSONObject(); + //创建人 TODO 修改为取编码 + parentvo.put("creator",formBean.getString("field0019")); + //客商名称 + parentvo.put("custname",formBean.getString("field0006")); + + //客商类型(0 - 外部单位1 - 内部核算单位2 - 内部法人单位3 - 内部渠道成员) + String custprop = formBean.getString("field0026"); + switch (custprop){ + case "-5116388890160378443": + custprop = "0"; + break; + case "8996290534573949076": + custprop = "1"; + break; + case "-2495523144656008721": + custprop = "2"; + break; + case "7042886455598794854": + custprop = "3"; + break; + default: + custprop = null; + break; + } + + parentvo.put("custprop", custprop); + //客商简称 + parentvo.put("custshortname",formBean.getString("field0001")); + //币种 + parentvo.put("def1111",formBean.getString("field0028")); + //邮箱 + parentvo.put("email",formBean.getString("field0052")); + //联系人1 + parentvo.put("linkman1",formBean.getString("field0010")); + parentvo.put("memo",formBean.getString("field0054")); + //手机 + parentvo.put("mobilephone1",formBean.getString("field0008")); + //所属地区编码 TODO 修改为取编码 + parentvo.put("pk_areacl",formBean.getString("field0034")); + //对应公司 + parentvo.put("pk_corp1",formBean.getString("field0056")); + //总公司名称 TODO 修改为取编码 + parentvo.put("pk_cubasdoc1",formBean.getString("field0022")); + //纳税人识别号 + parentvo.put("taxpayerid",formBean.getString("field0007")); + customer.put("parentvo",parentvo); + customer.put("banks",banks); + cbdocvo.add(customer); + returnData.put("cbdocvo",cbdocvo); + return returnData; + } + + + +}