丽知:新增存货基本档案自动分配全公司插件

This commit is contained in:
zhengyf 2024-08-08 18:21:42 +08:00
parent dd75e2cecc
commit 14fa78f169
7 changed files with 296 additions and 1 deletions

View File

@ -37,6 +37,7 @@ public class OverallConstant {
prodOverPublic.put("bdinvclUpdate", "/u8cloud/api/uapbd/invbasdoc/update");//存货基本档案修改
prodOverPublic.put("bdinvclSeal", "/u8cloud/api/uapbd/invbasdoc/seal");//存货基本档案封存
prodOverPublic.put("bdinvclUnseal", "/u8cloud/api/uapbd/invbasdoc/unseal");//存货基本档案取消封存
prodOverPublic.put("bdinvclAllot", "/u8cloud/api/uapbd/invbasdoc/assign");//存货基本档案自动分配

View File

@ -5,6 +5,7 @@ package com.hzya.frame.plugin.lets.constant;
*/
public class ProfilesActiveConstant {
public static final String LETS_DATE_SOURCE = "lets_u8c";
public static final String LETS_PROFILES_ACTIVE = "dev";
public static final String LOG_STATUS_Y = "Y";

View File

@ -0,0 +1,275 @@
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.google.common.collect.Lists;
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.dao.IBdInvbasdocDao;
import com.hzya.frame.plugin.lets.entity.BdInvbasdocEntity;
import com.hzya.frame.plugin.lets.u8cdto.GoodsAutoAllotVO;
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.u8c.ax.entity.Ass;
import com.hzya.frame.web.entity.JsonResultEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
/**
* U8C->存货基本档案自动分配全公司
* add by zyd 20240808
* <p>
* 存货基本档案分配 /u8cloud/api/uapbd/invbasdoc/assign
*/
public class GoodsAutoAllotPluginInitializer extends PluginBaseEntity {
Logger logger = LoggerFactory.getLogger(GoodsAutoAllotPluginInitializer.class);
private static final ReentrantLock LOCK = new ReentrantLock(true);
@Override
public void initialize() {
logger.info(getPluginLabel() + "執行初始化方法initialize()");
}
@Override
public void destroy() {
logger.info(getPluginLabel() + "執行銷毀方法destroy()");
}
@Override
public String getPluginId() {
return "com.hzya.frame.plugin.lets.plugin.base.GoodsAutoAllotPluginInitializer";
}
@Override
public String getPluginName() {
return "丽知U8C->存货基本档案自动分配全公司";
}
@Override
public String getPluginLabel() {
return "丽知U8C->存货基本档案自动分配全公司";
}
@Override
public String getPluginType() {
return "1";
}
@Autowired
private IIntegrationTaskLivingDetailsDao iIntegrationTaskLivingDetailsDao;
@Autowired
private IBdInvbasdocDao bdInvbasdocDao;
@Autowired
private PushDataByU8cUtil pushDataByU8cUtil;
@Autowired
private SaveOrUpdateBusinessLogUtil saveOrUpdateBusinessLogUtil;
@Override
public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception {
return null;
}
/**
* 默认推送
*/
public void start() {
try {
//获取当前时间
Date currentDate = new Date();
Date startTime = DateUtil.offset(currentDate, DateField.MINUTE, -10);
Date endTime = DateUtil.offset(currentDate, DateField.MINUTE, -2);
String startTimeStr = DateUtil.format(startTime, "yyyy-MM-dd HH:mm:ss");
String endTimeStr = DateUtil.format(endTime, "yyyy-MM-dd HH:mm:ss");
BdInvbasdocEntity bdInvbasdocEntity = new BdInvbasdocEntity();
bdInvbasdocEntity.setCreatetime_start_time(startTimeStr);
bdInvbasdocEntity.setCreatetime_end_time(endTimeStr);
bdInvbasdocEntity.setDataSourceCode(ProfilesActiveConstant.LETS_DATE_SOURCE);
List<BdInvbasdocEntity> bdInvbasdocEntityList = bdInvbasdocDao.query(bdInvbasdocEntity);
if (bdInvbasdocEntityList.size() == 0) {
return;
}
//过滤日志
List<BdInvbasdocEntity> filterInvbasdocList = filter(bdInvbasdocEntityList);
if (filterInvbasdocList.size() == 0 || filterInvbasdocList == null) {
return;
}
//推送自动分配
implement(filterInvbasdocList);
} catch (Exception e) {
logger.error("丽知U8C->存货基本档案自动分配全公司,start()方法报错:", e);
}
}
/**
* 按存货基本档案主键
*/
public void start(String pkInvbasdoc) {
try {
BdInvbasdocEntity bdInvbasdocEntity = new BdInvbasdocEntity();
bdInvbasdocEntity.setPkInvbasdoc(pkInvbasdoc);
bdInvbasdocEntity.setDataSourceCode(ProfilesActiveConstant.LETS_DATE_SOURCE);
List<BdInvbasdocEntity> bdInvbasdocEntityList = bdInvbasdocDao.query(bdInvbasdocEntity);
if (bdInvbasdocEntityList.size() == 0) {
Assert.state(false, "U8C->存货基本档案自动分配全公司,存货基本档案主键:{},不存在。", pkInvbasdoc);
}
//过滤日志
List<BdInvbasdocEntity> filterInvbasdocList = filter(bdInvbasdocEntityList);
if (filterInvbasdocList.size() == 0 || filterInvbasdocList == null) {
Assert.state(false, "U8C->存货基本档案自动分配全公司,存货基本档案主键:{},已被分配,请检查。", pkInvbasdoc);
}
//推送自动分配
implement(filterInvbasdocList);
} catch (Exception e) {
logger.error("丽知U8C->存货基本档案自动分配全公司,start(String pkInvbasdoc)方法报错:", e);
}
}
/**
* 按时间区间
*/
public void start(String startTime, String endTime) {
try {
Date business_start = DateUtil.parse(startTime);
Date business_end = DateUtil.parse(endTime);
String start = DateUtil.format(business_start, "yyyy-MM-dd") + " 00:00:00";
String end = DateUtil.format(business_end, "yyyy-MM-dd") + " 23:59:59";
BdInvbasdocEntity bdInvbasdocEntity = new BdInvbasdocEntity();
bdInvbasdocEntity.setCreatetime_start_time(start);
bdInvbasdocEntity.setCreatetime_end_time(end);
bdInvbasdocEntity.setDataSourceCode(ProfilesActiveConstant.LETS_DATE_SOURCE);
List<BdInvbasdocEntity> bdInvbasdocEntityList = bdInvbasdocDao.query(bdInvbasdocEntity);
if (bdInvbasdocEntityList.size() == 0) {
Assert.state(false, "U8C->存货基本档案自动分配全公司,按日期:{} - {},未查到存货基本档案。", startTime,endTime);
}
//过滤日志
List<BdInvbasdocEntity> filterInvbasdocList = filter(bdInvbasdocEntityList);
if (filterInvbasdocList.size() == 0 || filterInvbasdocList == null) {
Assert.state(false, "U8C->存货基本档案自动分配全公司,按日期:{} - {},已被分配,请检查。", startTime,endTime);
}
//推送自动分配
implement(filterInvbasdocList);
} catch (Exception e) {
logger.error("丽知U8C->存货基本档案自动分配全公司,start(String startTime, String endTime)方法报错:", e);
}
}
/**
* 过滤成功日志
*
* @return
*/
public List<BdInvbasdocEntity> filter(List<BdInvbasdocEntity> bdInvbasdocEntityList) {
List<BdInvbasdocEntity> filterInvbasdocList = new ArrayList<>();
for (BdInvbasdocEntity bdInvbasdocEntity : bdInvbasdocEntityList) {
String rootAppPk = bdInvbasdocEntity.getPkInvbasdoc();
boolean isExis = true;
IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity();
integrationTaskLivingDetailsEntity.setRootAppPk(rootAppPk);
integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_Y);
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
List<IntegrationTaskLivingDetailsEntity> integrationTaskLivingDetailsEntities = iIntegrationTaskLivingDetailsDao.query(integrationTaskLivingDetailsEntity);
if (integrationTaskLivingDetailsEntities == null || integrationTaskLivingDetailsEntities.size() == 0) {
isExis = false;
}
if (!isExis) {
filterInvbasdocList.add(bdInvbasdocEntity);
}
}
return filterInvbasdocList;
}
/**
* U8C->存货基本档案自动分配全公司
*
* @param filterInvbasdocList
*/
public void implement(List<BdInvbasdocEntity> filterInvbasdocList) {
for (BdInvbasdocEntity bdInvbasdocEntity : filterInvbasdocList) {
//创建日期
String createtime = bdInvbasdocEntity.getCreatetime();
//存货档案主键
String pkInvbasdoc = bdInvbasdocEntity.getPkInvbasdoc();
String mapStr = "";
try {
List<GoodsAutoAllotVO> goodsAutoAllotVOS = new ArrayList<>();
GoodsAutoAllotVO goodsAutoAllotVO = new GoodsAutoAllotVO();
//存货基本档案主键
goodsAutoAllotVO.setPk_invbasdoc(pkInvbasdoc);
goodsAutoAllotVOS.add(goodsAutoAllotVO);
Map<String, Object> map = new HashMap<>();
String jsonStr = JSONUtil.toJsonStr(goodsAutoAllotVOS);
map.put("invbasdocvo", jsonStr);
mapStr = JSONUtil.toJsonStr(map);
String response = pushDataByU8cUtil.pushU8CByPK(OverallConstant.getOverAllValue("bdinvclAllot"), 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--> 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(createtime);
integrationTaskLivingDetailsEntity.setRootAppPk(pkInvbasdoc);
integrationTaskLivingDetailsEntity.setRootAppBill(pkInvbasdoc);
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity);
} catch (Exception e) {
e.printStackTrace();
logger.error("U8C->存货基本档案自动分配全公司implement(List<BdInvbasdocEntity> filterInvbasdocList)方法失败");
//失败
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(createtime);
integrationTaskLivingDetailsEntity.setRootAppPk(pkInvbasdoc);
integrationTaskLivingDetailsEntity.setRootAppBill(pkInvbasdoc);
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity);
}
}
}
}

View File

@ -0,0 +1,9 @@
package com.hzya.frame.plugin.lets.u8cdto;
import lombok.Data;
@Data
public class GoodsAutoAllotVO {
private String pk_invbasdoc;
private String pk_corp="all";
}

View File

@ -34,7 +34,8 @@ spring:
# use-suffix-pattern: true
profiles:
# active: @profileActive@
active: @profile.active@
active: lets
# active: @profile.active@
# active: dev
servlet:
multipart:

View File

@ -6,5 +6,6 @@
<!--基础档案-->
<bean name="goodsPluginInitializer" class="com.hzya.frame.plugin.lets.plugin.base.GoodsPluginInitializer"/>
<bean name="goodsAutoAllotPluginInitializer" class="com.hzya.frame.plugin.lets.plugin.base.GoodsAutoAllotPluginInitializer"/>
<bean name="goodsClassPluginInitializer" class="com.hzya.frame.plugin.lets.plugin.base.GoodsClassPluginInitializer"/>
</beans>

View File

@ -13,9 +13,16 @@ public class BaseTest {
@Autowired
private GoodsClassPluginInitializer goodsClassPluginInitializer;
@Autowired
private GoodsAutoAllotPluginInitializer goodsAutoAllotPluginInitializer;
@Test
public void t00(){
goodsClassPluginInitializer.start("666");
}
@Test
public void t01(){
goodsAutoAllotPluginInitializer.start("0001A210000000000JOC");
}
}