From 72d28c22014787b8289f738b60a7e98c8045b8f0 Mon Sep 17 00:00:00 2001 From: zhengyf Date: Wed, 7 Aug 2024 17:51:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BD=E7=9F=A5=EF=BC=9A=E5=AD=98=E8=B4=A7?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/lets/entity/BdInvclEntity.java | 150 +++--------------- .../base/GoodsClassPluginInitializer.java | 121 +++++++++++++- .../util/SaveOrUpdateBusinessLogUtil.java | 126 +++++++++++++++ .../plugin/lets/plugin/base/BaseTest.java | 21 +++ 4 files changed, 288 insertions(+), 130 deletions(-) create mode 100644 buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/SaveOrUpdateBusinessLogUtil.java create mode 100644 buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/base/BaseTest.java diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/entity/BdInvclEntity.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/entity/BdInvclEntity.java index 3d2a2ea3..48612dc6 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/entity/BdInvclEntity.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/entity/BdInvclEntity.java @@ -1,159 +1,51 @@ package com.hzya.frame.plugin.lets.entity; import com.hzya.frame.web.entity.BaseEntity; +import lombok.Data; + /** * (BdInvcl)实体类 * * @author makejava * @since 2024-01-09 15:08:19 */ +@Data public class BdInvclEntity extends BaseEntity { - + + /** 平均成本 */ private Double averagecost; + /** 平均生产提前期 */ private Integer averagemmahead; + /** 平均采购提前期 */ private Integer averagepurahead; + /** 平均采购提前期 */ private Double avgprice; + /** 删除标志 */ private Integer dr; + /** 末级标志 */ private String endflag; + /** 外文名 */ private String forinvname; + /** 分类编码 */ private String invclasscode; + /** 编码级次 */ private Integer invclasslev; + /** 类别名称 */ private String invclassname; + /** 电子采购分类 */ private String iselectrans; + /** 是否红火台 */ private String ishuo; + /** 公司主键 */ private String pkCorp; + private String pk_corp; + /** 存货分类主键 */ private String pkInvcl; + /** 封存标志 */ private String sealdate; + /** 时间戳 */ private String ts; - public Double getAveragecost() { - return averagecost; - } - - public void setAveragecost(Double averagecost) { - this.averagecost = averagecost; - } - - public Integer getAveragemmahead() { - return averagemmahead; - } - - public void setAveragemmahead(Integer averagemmahead) { - this.averagemmahead = averagemmahead; - } - - public Integer getAveragepurahead() { - return averagepurahead; - } - - public void setAveragepurahead(Integer averagepurahead) { - this.averagepurahead = averagepurahead; - } - - public Double getAvgprice() { - return avgprice; - } - - public void setAvgprice(Double avgprice) { - this.avgprice = avgprice; - } - - public Integer getDr() { - return dr; - } - - public void setDr(Integer dr) { - this.dr = dr; - } - - public String getEndflag() { - return endflag; - } - - public void setEndflag(String endflag) { - this.endflag = endflag; - } - - public String getForinvname() { - return forinvname; - } - - public void setForinvname(String forinvname) { - this.forinvname = forinvname; - } - - public String getInvclasscode() { - return invclasscode; - } - - public void setInvclasscode(String invclasscode) { - this.invclasscode = invclasscode; - } - - public Integer getInvclasslev() { - return invclasslev; - } - - public void setInvclasslev(Integer invclasslev) { - this.invclasslev = invclasslev; - } - - public String getInvclassname() { - return invclassname; - } - - public void setInvclassname(String invclassname) { - this.invclassname = invclassname; - } - - public String getIselectrans() { - return iselectrans; - } - - public void setIselectrans(String iselectrans) { - this.iselectrans = iselectrans; - } - - public String getIshuo() { - return ishuo; - } - - public void setIshuo(String ishuo) { - this.ishuo = ishuo; - } - - public String getPkCorp() { - return pkCorp; - } - - public void setPkCorp(String pkCorp) { - this.pkCorp = pkCorp; - } - - public String getPkInvcl() { - return pkInvcl; - } - - public void setPkInvcl(String pkInvcl) { - this.pkInvcl = pkInvcl; - } - - public String getSealdate() { - return sealdate; - } - - public void setSealdate(String sealdate) { - this.sealdate = sealdate; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - } diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/base/GoodsClassPluginInitializer.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/base/GoodsClassPluginInitializer.java index cf03a2f8..c9476da2 100644 --- a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/base/GoodsClassPluginInitializer.java +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/plugin/base/GoodsClassPluginInitializer.java @@ -2,12 +2,25 @@ package com.hzya.frame.plugin.lets.plugin.base; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.lang.Assert; +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.hzya.frame.base.PluginBaseEntity; +import com.hzya.frame.plugin.lets.constant.OverallConstant; +import com.hzya.frame.plugin.lets.constant.ProfilesActiveConstant; +import com.hzya.frame.plugin.lets.entity.BdInvclEntity; import com.hzya.frame.plugin.lets.plugin.sales.SoSaleOutPluginInitializerToC; +import com.hzya.frame.plugin.lets.u8cdto.ReusltStrDto; +import com.hzya.frame.plugin.lets.util.PushDataByU8cUtil; +import com.hzya.frame.plugin.lets.util.SaveOrUpdateBusinessLogUtil; +import com.hzya.frame.sysnew.integtationTaskLivingDetails.dao.IIntegrationTaskLivingDetailsDao; +import com.hzya.frame.sysnew.integtationTaskLivingDetails.entity.IntegrationTaskLivingDetailsEntity; import com.hzya.frame.web.entity.JsonResultEntity; +import com.zaxxer.hikari.util.FastList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; /** * OFS->U8C货品档案分类 新增,修改,删除 @@ -23,7 +36,9 @@ import org.slf4j.LoggerFactory; * 二级:AA001,自动识别为AA的下级 * 三级:AA00101自动识别为AA001的下级 */ -import java.util.Date; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.util.*; import java.util.concurrent.locks.ReentrantLock; public class GoodsClassPluginInitializer extends PluginBaseEntity { @@ -62,6 +77,13 @@ public class GoodsClassPluginInitializer extends PluginBaseEntity { return "1"; } + @Autowired + private PushDataByU8cUtil pushDataByU8cUtil; + @Autowired + private IIntegrationTaskLivingDetailsDao iIntegrationTaskLivingDetailsDao; + @Autowired + private SaveOrUpdateBusinessLogUtil saveOrUpdateBusinessLogUtil; + @Override public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception { return null; @@ -89,6 +111,7 @@ public class GoodsClassPluginInitializer extends PluginBaseEntity { */ public void start(String className) { try { + implement(); } catch (Exception e) { logger.error("丽知:OFS货品档案分类--->U8C货品档案分类,start(String className)方法报错:", e); } @@ -109,6 +132,102 @@ public class GoodsClassPluginInitializer extends PluginBaseEntity { } } + public void filterGoodsClass() { + return; + } + + /** + * U8C分类规则 XX-XXX-XX,自动截断 + * eg: + * 一级:AA + * 二级:AA001,自动识别为AA的下级 + * 三级:AA00101自动识别为AA001的下级 + */ + public void implement() { + + //生成业务日期 + String businessFormat = ""; + String mapStr=""; + + + String invclasscode=null; + String invclassname=null; + try { + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 定义日期格式 + Date date = new Date(System.currentTimeMillis()); // 创建Date对象 + businessFormat = sdf.format(date); // 将Date对象格式化为字符串 + + + + + List bdInvclEntities = new ArrayList<>(); + + BdInvclEntity bdInvclEntity = new BdInvclEntity(); + + //分类编码-invclasscode + invclasscode = "AA004"; + bdInvclEntity.setInvclasscode(invclasscode); + + //分类名称-invclassname + invclassname = "分类名称:AA004"; + + bdInvclEntity.setInvclassname(invclassname); + //公司编码-pk_corp + String pk_corp = "1001"; + bdInvclEntity.setPk_corp(pk_corp); + //分类级别-invclasslevel + bdInvclEntities.add(bdInvclEntity); + + String jsonStr = JSONUtil.toJsonStr(bdInvclEntities); + + Map map = new HashMap<>(); + map.put("invcl", jsonStr); + mapStr = JSONUtil.toJsonStr(map); + + String response = pushDataByU8cUtil.pushU8CByPK(OverallConstant.getOverAllValue("bdinvclSave"), mapStr); + System.out.println(response); + boolean isSuccess = false; + if (response != null && !"".equals(response)) { + ReusltStrDto reusltStrDto = JSON.parseObject(response, ReusltStrDto.class); + if ("success".equals(reusltStrDto.getStatus())) { + isSuccess = true; + } + } + if (!isSuccess) { + Assert.state(false, "推送U8C-->丽知:OFS货品档案分类--->U8C货品档案分类失败 接口返回结果:{} 接口入参:{}", response, jsonStr); + } + //成功 + IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity(); + integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_Y); + integrationTaskLivingDetailsEntity.setRootAppNewData(mapStr); + integrationTaskLivingDetailsEntity.setNewTransmitInfo(response); + integrationTaskLivingDetailsEntity.setNewPushDate(new Date()); + integrationTaskLivingDetailsEntity.setBusinessDate(businessFormat); + integrationTaskLivingDetailsEntity.setRootAppPk(invclasscode); + integrationTaskLivingDetailsEntity.setRootAppBill(invclassname); + integrationTaskLivingDetailsEntity.setPluginId(getPluginId()); + saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity); + + + } catch (Exception e) { + e.printStackTrace(); + logger.error("丽知:OFS货品档案分类--->U8C货品档案分类,implement()方法报错:", e); + //失败 + String ErrMessage = e.getMessage(); + IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity(); + integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_N); + integrationTaskLivingDetailsEntity.setRootAppNewData(mapStr); + integrationTaskLivingDetailsEntity.setNewTransmitInfo(ErrMessage); + integrationTaskLivingDetailsEntity.setNewPushDate(new Date()); + integrationTaskLivingDetailsEntity.setBusinessDate(businessFormat); + integrationTaskLivingDetailsEntity.setRootAppPk(invclasscode); + integrationTaskLivingDetailsEntity.setRootAppBill(invclassname); + integrationTaskLivingDetailsEntity.setPluginId(getPluginId()); + saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity); + } + + } } diff --git a/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/SaveOrUpdateBusinessLogUtil.java b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/SaveOrUpdateBusinessLogUtil.java new file mode 100644 index 00000000..2afb5f00 --- /dev/null +++ b/buildpackage/src/main/java/com/hzya/frame/plugin/lets/util/SaveOrUpdateBusinessLogUtil.java @@ -0,0 +1,126 @@ +package com.hzya.frame.plugin.lets.util; + + +import cn.hutool.core.lang.Assert; + +import com.hzya.frame.sysnew.integtationTaskLivingDetails.dao.IIntegrationTaskLivingDetailsDao; +import com.hzya.frame.sysnew.integtationTaskLivingDetails.entity.IntegrationTaskLivingDetailsEntity; +import com.hzya.frame.uuid.UUIDLong; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 保存或者更新业务日志 + * + * @author liuyang + */ +@Component +public class SaveOrUpdateBusinessLogUtil { + + @Autowired + private IIntegrationTaskLivingDetailsDao iIntegrationTaskLivingDetailsDao; + + private static final Object insertOrUpdateLock = new Object(); + + /** + * 保存或者更新 + * + * @param integrationTaskLivingDetailsEntity 提交参数 + */ + public void saveOrUpdate(IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity) { + Assert.notNull(integrationTaskLivingDetailsEntity, "integrationTaskLivingDetailsEntity不能为空"); + Assert.notNull(integrationTaskLivingDetailsEntity.getRootAppPk(), "源系统单号不能为空"); + Assert.notNull(integrationTaskLivingDetailsEntity.getPluginId(), "场景id不能为空"); + +// Thread thread = new Thread(new Runnable() { +// @Override +// public void run() { +// synchronized (insertOrUpdateLock) { +// IntegrationTaskLivingDetailsEntity integrationTaskLivingDetails = null; +// IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity1 = new IntegrationTaskLivingDetailsEntity(); +// integrationTaskLivingDetailsEntity1.setRoot_app_pk(integrationTaskLivingDetailsEntity.getRoot_app_pk()); +// integrationTaskLivingDetailsEntity1.setPlugin_id(integrationTaskLivingDetailsEntity.getPlugin_id()); +// List integrationTaskLivingDetailsEntities = iIntegrationTaskLivingDetailsDao.query(integrationTaskLivingDetailsEntity1); +// if (integrationTaskLivingDetailsEntities != null && integrationTaskLivingDetailsEntities.size() > 0) { +// integrationTaskLivingDetails = integrationTaskLivingDetailsEntities.get(0); +// } +// +// if (integrationTaskLivingDetails != null) { +// //存在 +// integrationTaskLivingDetailsEntity.setId(integrationTaskLivingDetails.getId()); +// updateSuccessMessage(integrationTaskLivingDetailsEntity); +// iIntegrationTaskLivingDetailsDao.update("com.hzya.frame.sys.integrationtask.living.dao.impl.IntegrationTaskLivingDetailsDaoImpl.entity_updatebyid", integrationTaskLivingDetailsEntity); +// } else { +// //不存在 +// Long uuid = UUIDLong.longUUID(); +// integrationTaskLivingDetailsEntity.setId(String.valueOf(uuid)); +// updateSuccessMessage(integrationTaskLivingDetailsEntity); +// iIntegrationTaskLivingDetailsDao.save(integrationTaskLivingDetailsEntity); +// } +// } +// } +// }); +// thread.start(); +// try { +// thread.join(); +// } catch (Exception e) { +// e.printStackTrace(); +// } + + IntegrationTaskLivingDetailsEntity integrationTaskLivingDetails = null; + IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity1 = new IntegrationTaskLivingDetailsEntity(); + integrationTaskLivingDetailsEntity1.setRootAppPk(integrationTaskLivingDetailsEntity.getRootAppPk()); + integrationTaskLivingDetailsEntity1.setPluginId(integrationTaskLivingDetailsEntity.getPluginId()); + List integrationTaskLivingDetailsEntities = iIntegrationTaskLivingDetailsDao.query(integrationTaskLivingDetailsEntity1); + if (integrationTaskLivingDetailsEntities != null && integrationTaskLivingDetailsEntities.size() > 0) { + integrationTaskLivingDetails = integrationTaskLivingDetailsEntities.get(0); + } + if (integrationTaskLivingDetails != null) { + //存在 + synchronized (insertOrUpdateLock) { + integrationTaskLivingDetailsEntity.setId(integrationTaskLivingDetails.getId()); + updateSuccessMessage(integrationTaskLivingDetailsEntity); + iIntegrationTaskLivingDetailsDao.update("com.hzya.frame.sys.integrationtask.living.dao.impl.IntegrationTaskLivingDetailsDaoImpl.entity_updatebyid", integrationTaskLivingDetailsEntity); + } + } else { + //不存在 + Long uuid = UUIDLong.longUUID(); + integrationTaskLivingDetailsEntity.setId(String.valueOf(uuid)); + updateSuccessMessage(integrationTaskLivingDetailsEntity); + iIntegrationTaskLivingDetailsDao.save(integrationTaskLivingDetailsEntity); + } + } + + /** + * 修改成功消息 + * + * @author liuyang + */ + private void updateSuccessMessage(IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity) { + if (integrationTaskLivingDetailsEntity != null) { + if ("Y".equals(integrationTaskLivingDetailsEntity.getNewState())) { + //成功 + integrationTaskLivingDetailsEntity.setRootAppNewData("success"); + integrationTaskLivingDetailsEntity.setNewTransmitInfo("success"); + /** + * integrationTaskLivingDetailsEntity.setRoot_app_new_data(JSON.toJSONString(searchPurchaseReceiptOrder)); + * integrationTaskLivingDetailsEntity.setNew_transmit_info(cgrkApi); + */ + } + } + } + + /** + * 根据明细id查询明细信息 + * + * @author liuyang + */ + public IntegrationTaskLivingDetailsEntity queryIntegrationTaskLivingDetailsEntity(String integration_task_living_details_id) { + Assert.notNull(integration_task_living_details_id, "业务明细id不能为空"); + IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = iIntegrationTaskLivingDetailsDao.get(integration_task_living_details_id); + Assert.notNull(integrationTaskLivingDetailsEntity, "根据主键id没有查询到明细信息"); + return integrationTaskLivingDetailsEntity; + } +} \ No newline at end of file diff --git a/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/base/BaseTest.java b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/base/BaseTest.java new file mode 100644 index 00000000..5c60217c --- /dev/null +++ b/buildpackage/src/test/java/com/hzya/frame/plugin/lets/plugin/base/BaseTest.java @@ -0,0 +1,21 @@ +package com.hzya.frame.plugin.lets.plugin.base; + +import com.hzya.frame.WebappApplication; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = WebappApplication.class) +public class BaseTest { + + @Autowired + private GoodsClassPluginInitializer goodsClassPluginInitializer; + + @Test + public void t00(){ + goodsClassPluginInitializer.start("666"); + } +}