丽知:新增ofs实物组套同步u8c成套件

This commit is contained in:
zhengyf 2024-09-10 15:45:46 +08:00
parent 1bbcea9586
commit 87b7cca320
7 changed files with 439 additions and 0 deletions

View File

@ -45,6 +45,11 @@ public class OverallConstant {
prodOverPublic.put("bdinvclUnseal", "/u8cloud/api/uapbd/invbasdoc/unseal");//存货基本档案取消封存
prodOverPublic.put("bdinvclAllotCode", "8000370003");//存货基本档案自动分配
prodOverPublic.put("bdinvclAllot", "/u8cloud/api/uapbd/invbasdoc/assign");//存货基本档案自动分配
//成套件
prodOverPublic.put("setpartInsertCode", "8000370063");//成套件新增
prodOverPublic.put("setpartDeleteCode", "8000370064");//成套件删除
prodOverPublic.put("setpartQueryCode", "8000370065");//成套件查询
//调拨
prodOverPublic.put("approveqzCode", "8000370009");//调拨订单保存即审批
prodOverPublic.put("approveqz", "/u8cloud/api/to/transorder/saveapprove");//调拨订单保存即审批

View File

@ -0,0 +1,26 @@
package com.hzya.frame.plugin.lets.ofsvo;
import lombok.Data;
/**
* OFS 实物组套入参查询
*/
@Data
public class QueryOfsKitRequestVO {
/** 开始时间 */
private String created_start;
/** 结束时间 */
private String created_end;
/** 组织 */
private String clientCode;
private String lastUpdated_start;
private String lastUpdated_end;
private String companyCode;
private String status;
private String skuCode;
private String pageNo;
private String pageSize;
}

View File

@ -0,0 +1,332 @@
package com.hzya.frame.plugin.lets.plugin.base;
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.dao.IBdInvbasdocDao;
import com.hzya.frame.plugin.lets.entity.BdCorpEntity;
import com.hzya.frame.plugin.lets.ofsvo.QueryOfsKitRequestVO;
import com.hzya.frame.plugin.lets.u8cdto.InvBasDocVO;
import com.hzya.frame.plugin.lets.u8cdto.ReusltStrDto;
import com.hzya.frame.plugin.lets.u8cdto.SetpartVO;
import com.hzya.frame.plugin.lets.util.PushDataByU8cUtil;
import com.hzya.frame.plugin.lets.util.QueryU8CEntityUtil;
import com.hzya.frame.plugin.lets.util.SaveOrUpdateBusinessLogUtil;
import com.hzya.frame.plugin.lets.util.pushData.Attribute;
import com.hzya.frame.plugin.lets.util.pushData.PushU8CByApiCode;
import com.hzya.frame.plugin.lets.util.pushData.ZTResult;
import com.hzya.frame.sysnew.integtationTaskLivingDetails.dao.IIntegrationTaskLivingDetailsDao;
import com.hzya.frame.sysnew.integtationTaskLivingDetails.entity.IntegrationTaskLivingDetailsEntity;
import com.hzya.frame.ttxofs.basics.ReturnMessageBasics;
import com.hzya.frame.ttxofs.dto.InterfaceParamByU8CApiDto;
import com.hzya.frame.ttxofs.dto.kit.OfsKitOrderSearchResponse;
import com.hzya.frame.ttxofs.service.OfsUnifiedService;
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.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
/**
* OFS实物组套同步U8C成套件档案
* <p>
* U8C成套件没有修改只有删除和新增
*/
public class KitPluginInitializer extends PluginBaseEntity {
Logger logger = LoggerFactory.getLogger(KitPluginInitializer.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 "base.KitPluginInitializer";
}
@Override
public String getPluginName() {
return "丽知OFS实物组套--->U8C成套件档案";
}
@Override
public String getPluginLabel() {
return "丽知OFS实物组套--->U8C成套件档案";
}
@Override
public String getPluginType() {
return "1";
}
@Autowired
private IIntegrationTaskLivingDetailsDao iIntegrationTaskLivingDetailsDao;
@Autowired
private PushDataByU8cUtil pushDataByU8cUtil;
@Autowired
private PushU8CByApiCode pushU8CByApiCode;
@Autowired
private SaveOrUpdateBusinessLogUtil saveOrUpdateBusinessLogUtil;
@Autowired
private OfsUnifiedService ofsUnifiedService;
@Autowired
private IBdInvbasdocDao bdInvbasdocDao;
@Autowired
private QueryU8CEntityUtil queryU8CEntityUtil;
@Override
public JsonResultEntity executeBusiness(JSONObject requestJson) throws Exception {
try {
logger.info("调用:" + getPluginName() + "-插件");
String prod = "prod";
String param = String.valueOf(requestJson.get("param"));
if (requestJson != null && ProfilesActiveConstant.TYPE_DATE.equals(requestJson.get("type"))) {
//按日期
if (param != null && !"".equals(param)) {
String[] split = param.split("/");
if (!(split.length == 2)) {
Assert.state(false, "时间格式传递不正确");
}
Assert.notNull(split[0], "开始时间不能为空");
Assert.notNull(split[1], "结束时间不能为空");
start(split[0], split[1]);
}
} else if (requestJson != null && ProfilesActiveConstant.TYPE_VBILLCODE.equals(requestJson.get("type"))) {
//按单号
if (param != null && !"".equals(param)) {
start(param);
}
} else if (ProfilesActiveConstant.TYPE_DETAIL_ERROR.equals(requestJson.get("type"))) {
String integrationTaskLivingDetails = (String) requestJson.get("integration_task_living_details_id");
IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = saveOrUpdateBusinessLogUtil.queryIntegrationTaskLivingDetailsEntity(integrationTaskLivingDetails);
start(integrationTaskLivingDetailsEntity.getRootAppPk());
} else if (ProfilesActiveConstant.LETS_PROFILES_ACTIVE.equals(prod)) {
//默认
start();
}
} catch (Exception e) {
e.printStackTrace();
logger.error("executeBusiness方法抛出异常", e);
}
return null;
}
public void start() {
try {
} catch (Exception e) {
logger.error("丽知OFS实物组套--->U8C成套件档案,start()方法报错:", e);
}
}
public void start(String SkuCode) {
try {
QueryOfsKitRequestVO queryOfsKitRequestVO = new QueryOfsKitRequestVO();
queryOfsKitRequestVO.setSkuCode(SkuCode);
List<OfsKitOrderSearchResponse.OfsKit> ofsKits = queryOfsKits(queryOfsKitRequestVO);
if(ofsKits.size()==0){
Assert.state(false,"根据OFS实物组套sku编码{}未查询到OFS实物组套请检查。",SkuCode);
}
//过滤
List<OfsKitOrderSearchResponse.OfsKit> filterKits = filterData(ofsKits);
if(filterKits.size()==0){
Assert.state(false,"根据OFS实物组套sku编码{},已被推送成功,请勿重新推送。",SkuCode);
}
//实现
implement(filterKits);
} catch (Exception e) {
logger.error("丽知OFS实物组套--->U8C成套件档案,start(String SkuCode)方法报错:", e);
}
}
public void start(String startTime, String endTim) {
try {
} catch (Exception e) {
logger.error("丽知OFS实物组套--->U8C成套件档案,start(String startTime, String endTim)方法报错:", e);
}
}
/**
* 过滤成功日志
*
* @param ofsKits
* @return
*/
public List<OfsKitOrderSearchResponse.OfsKit> filterData(List<OfsKitOrderSearchResponse.OfsKit> ofsKits) {
List<OfsKitOrderSearchResponse.OfsKit> filterKits = new ArrayList<>();
for (OfsKitOrderSearchResponse.OfsKit ofsKit : ofsKits) {
String rootAppPk = ofsKit.getHeader().getSkuCode();
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) {
filterKits.add(ofsKit);
}
}
return filterKits;
}
/**
* 全公司分配
*
* pk_corp 公司
* childsnum 父含子数
* partpercent 单件单价权数
* pk_invmandocpart 配件编码
* pk_invmandocset 成套件编码
* @param filterKits
*/
public void implement(List<OfsKitOrderSearchResponse.OfsKit> filterKits){
//查询所有公司
List<BdCorpEntity> bdCorpEntities = queryU8CEntityUtil.queryBdCorp();
System.out.println(bdCorpEntities);
//ofsKit列表
for (OfsKitOrderSearchResponse.OfsKit ofsKit : filterKits) {
System.out.println(ofsKit);
String mapStr="";
String response="";
String format=ofsKit.getHeader().getLastUpdated();
List<SetpartVO> setpartVOS=new ArrayList<>();
try {
//ofsKit表体
for (OfsKitOrderSearchResponse.OfsKit.KitDetail detail : ofsKit.getDetails()) {
//每个物料给每个公司一份
for (BdCorpEntity bdCorpEntity : bdCorpEntities) {
SetpartVO setpart = new SetpartVO();
//pk_invmandocset 成套件编码
setpart.setPk_invmandocset(ofsKit.getHeader().getSkuCode());
//pk_invmandocpart 配件编码
setpart.setPk_invmandocpart(detail.getSkuCode());
//childsnum 父含子数
setpart.setChildsnum(detail.getQuantity());
//partpercent 单件单价权数,妮妮姐说的全传1
setpart.setPartpercent("1");
//pk_corp 公司
setpart.setPk_corp(bdCorpEntity.getUnitcode());
setpartVOS.add(setpart);
}
}
System.out.println(setpartVOS);
System.out.println(JSONUtil.toJsonStr(setpartVOS));
String jsonStr = JSONUtil.toJsonStr(setpartVOS);
mapStr= "{\"setpartvo\":" + jsonStr + "}";
ZTResult ztResult = pushU8CByApiCode.pushByCode(OverallConstant.getOverAllValue("setpartInsertCode"), mapStr);
//两层判断,一层中台转发,一层u8c返回
Attribute attribute = ztResult.getAttribute();
if ("false".equals(ztResult.getFlag())) {
//转发失败
response=JSONUtil.toJsonStr(ztResult.getAttribute());
Assert.state(false, "丽知丽知OFS实物组套--->U8C成套件档案中台转发失败,失败原因:{}", ztResult.getAttribute());
}
boolean isSuccess = false;
if ("success".equals(attribute.getStatus())) {
isSuccess = true;
String data = attribute.getData();
}
if (!isSuccess) {
Assert.state(false, "丽知丽知OFS实物组套--->U8C成套件档案 失败 接口返回结果:{} 接口入参:{}", attribute.getErrormsg(), mapStr);
}
//成功
IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity();
integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_Y);
integrationTaskLivingDetailsEntity.setRootAppNewData(mapStr);
integrationTaskLivingDetailsEntity.setNewTransmitInfo(attribute.getData());
integrationTaskLivingDetailsEntity.setNewPushDate(new Date());
integrationTaskLivingDetailsEntity.setBusinessDate(format);
integrationTaskLivingDetailsEntity.setRootAppPk(ofsKit.getHeader().getSkuCode());
integrationTaskLivingDetailsEntity.setRootAppBill(ofsKit.getHeader().getSkuCode());
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
integrationTaskLivingDetailsEntity.setDef1(ofsKit.getHeader().getId());
saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity);
}catch (Exception e){
e.printStackTrace();
logger.error("推送U8C丽知OFS实物组套--->U8C成套件档案失败失败原因" + e);
ReusltStrDto reusltStrDto = JSON.parseObject(response, ReusltStrDto.class);
String ErrMessage = "推送U8C丽知OFS实物组套--->U8C成套件档案失败失败原因" + reusltStrDto.getErrormsg();
//失败
IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity();
integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_N);
integrationTaskLivingDetailsEntity.setRootAppNewData(mapStr);
integrationTaskLivingDetailsEntity.setNewTransmitInfo(ErrMessage);
integrationTaskLivingDetailsEntity.setNewPushDate(new Date());
integrationTaskLivingDetailsEntity.setBusinessDate(format);
integrationTaskLivingDetailsEntity.setRootAppPk(ofsKit.getHeader().getSkuCode());
integrationTaskLivingDetailsEntity.setRootAppBill(ofsKit.getHeader().getSkuCode());
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
integrationTaskLivingDetailsEntity.setDef1(ofsKit.getHeader().getId());
saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity);
}
}
}
public List<OfsKitOrderSearchResponse.OfsKit> queryOfsKits(QueryOfsKitRequestVO queryOfsKitRequestVO) throws Exception {
int pageNo = 1;
int pageSize = 500;
List<OfsKitOrderSearchResponse.OfsKit> all = new ArrayList<>();
InterfaceParamByU8CApiDto interfaceParamDto = new InterfaceParamByU8CApiDto();
interfaceParamDto.setApi("ofs.actual.bom.search");
queryOfsKitRequestVO.setClientCode("LETS");
queryOfsKitRequestVO.setPageNo(String.valueOf(pageNo));
queryOfsKitRequestVO.setPageSize(String.valueOf(pageSize));
interfaceParamDto.setData(JSON.toJSONString(queryOfsKitRequestVO));
OfsKitOrderSearchResponse ofsKitOrderSearchResponse = (OfsKitOrderSearchResponse) ofsUnifiedService.unifiedByU8CApi(interfaceParamDto);
System.out.println(ofsKitOrderSearchResponse);
all.addAll(ofsKitOrderSearchResponse.getData());
int count = ofsKitOrderSearchResponse.getData().size();
while (count >= pageSize) {//>=500,可能还有下一页
//还有下一页
pageNo++;
queryOfsKitRequestVO.setPageNo(String.valueOf(pageNo));
interfaceParamDto.setData(JSON.toJSONString(queryOfsKitRequestVO));
OfsKitOrderSearchResponse ofsKitOrderSearchResponse1 = (OfsKitOrderSearchResponse) ofsUnifiedService.unifiedByU8CApi(interfaceParamDto);
all.addAll(ofsKitOrderSearchResponse1.getData());
count = ofsKitOrderSearchResponse1.getData().size();
}
if (all == null || all.size() == 0) {
return null;
}
return all;
}
}

View File

@ -0,0 +1,20 @@
package com.hzya.frame.plugin.lets.u8cdto;
import lombok.Data;
/**
* U8C成套件信息
*/
@Data
public class SetpartVO {
/** 父含子数 */
private String childsnum;
/** 单件单价权数 */
private String partpercent;
/** 公司 */
private String pk_corp;
/** 配件编码 */
private String pk_invmandocpart;
/** 成套件编码 */
private String pk_invmandocset;
}

View File

@ -11,6 +11,7 @@
<bean name="skuClassPluginInitializer" class="com.hzya.frame.plugin.lets.plugin.base.SKUClassPluginInitializer"/>
<bean name="sKUSealPluginInitializer" class="com.hzya.frame.plugin.lets.plugin.base.SKUSealPluginInitializer"/>
<bean name="kitPluginInitializer" class="com.hzya.frame.plugin.lets.plugin.base.KitPluginInitializer"/>
<bean name="CustdocAutoAllotPluginInitializer" class="com.hzya.frame.plugin.lets.plugin.base.CustdocAutoAllotPluginInitializer"/>

View File

@ -1,5 +1,6 @@
package com.hzya.frame.ttxofs.basics;
import com.hzya.frame.ttxofs.dto.kit.OfsKitOrderSearchResponse;
import com.hzya.frame.ttxofs.dto.ofsBaseSearch.OFSSKUClassSearchResponse;
import com.hzya.frame.ttxofs.dto.ofsBaseSearch.OFSSKUSearchResponse;
import com.hzya.frame.ttxofs.dto.ofsBaseSearch.OfsShopReturnMessageDto;
@ -42,6 +43,8 @@ public class ApiDtoCacheMap {
apiDtoCacheMap.put("ofs.sku.search", new OFSSKUSearchResponse());//OFS存货档案查询接口
apiDtoCacheMap.put("ofs.inventory.class.search", new OFSSKUClassSearchResponse());//OFS存货分类查询接口
apiDtoCacheMap.put("ofs.actual.bom.search", new OfsKitOrderSearchResponse());//OFS实物组套查询接口
apiDtoCacheMap.put("ofs.returnOrder.search", new RerturnGoodsOrderSearchJsonRootBean());//售后订单
apiDtoCacheMap.put("ofs.purchaseOrder.search", new OfsPoOrderBean());//采购订单

View File

@ -0,0 +1,52 @@
package com.hzya.frame.ttxofs.dto.kit;
import com.hzya.frame.ttxofs.basics.ReturnMessageBasics;
import lombok.Data;
import java.util.List;
/**
* ofs实物组套查询响应结果
*/
@Data
public class OfsKitOrderSearchResponse extends ReturnMessageBasics {
public List<OfsKit> data;
@Data
public static class OfsKit {
public KitHeader header;
public List<KitDetail> details;
@Data
public static class KitHeader {
private String id;
private String clientCode;
private String companyCode;
private String skuCode;
private String skuName;
private String finishedGoodsQty;
private String status;
private String bomType;
private String buildInstructions;
private String created;
private String createdBy;
private String lastUpdated;
private String lastUpdatedBy;
}
@Data
public static class KitDetail {
private String id;
private String clientCode;
private String companyCode;
private String skuCode;
private String skuName;
private String quantityUM;
private String quantity;
private String created;
private String createdBy;
private String lastUpdated;
private String lastUpdatedBy;
}
}
}