丽知:仅退款区分tob、toc

This commit is contained in:
zhengyf 2024-11-20 17:48:48 +08:00
parent 56a6ecb615
commit a5dd7d10a7
2 changed files with 1624 additions and 0 deletions

View File

@ -0,0 +1,811 @@
package com.hzya.frame.plugin.lets.plugin.sales;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
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.dao.IOnlyAfterSalesBDao;
import com.hzya.frame.plugin.lets.dao.IOnlyAfterSalesHDao;
import com.hzya.frame.plugin.lets.entity.BdCubasdocEntity;
import com.hzya.frame.plugin.lets.entity.OnlyAfterSalesBEntity;
import com.hzya.frame.plugin.lets.entity.OnlyAfterSalesHEntity;
import com.hzya.frame.plugin.lets.ofsvo.QueryOfsSoSaleOutVo;
import com.hzya.frame.plugin.lets.ofsvo.QueryReturnOrderRequestVO;
import com.hzya.frame.plugin.lets.u8cdto.ArapDjzb;
import com.hzya.frame.plugin.lets.u8cdto.ArapDjzbVO;
import com.hzya.frame.plugin.lets.u8cdto.ReusltStrDto;
import com.hzya.frame.plugin.lets.util.OfsOrderAfterSalesAmountAllocationUtil;
import com.hzya.frame.plugin.lets.util.QueryU8CEntityUtil;
import com.hzya.frame.plugin.lets.util.SaveOrUpdateBusinessLogUtil;
import com.hzya.frame.plugin.lets.util.ShopTobOrToCUtil;
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.dto.InterfaceParamDto;
import com.hzya.frame.ttxofs.dto.ofssalesordersearch.SaleOrderMessageDto;
import com.hzya.frame.ttxofs.dto.returngoodordersearch.RerturnGoodsOrderSearchData;
import com.hzya.frame.ttxofs.dto.returngoodordersearch.RerturnGoodsOrderSearchDetails;
import com.hzya.frame.ttxofs.dto.returngoodordersearch.RerturnGoodsOrderSearchHeader;
import com.hzya.frame.ttxofs.dto.returngoodordersearch.RerturnGoodsOrderSearchJsonRootBean;
import com.hzya.frame.ttxofs.service.OfsUnifiedService;
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;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
/**
* add by zyd
* O售后订单(ToB仅退款) -> U8C红字应收单
* <p>(取售中售后)
* returnType:0 不退货
* exchangeType:0 不换货
* refundInd:1 退款
* <p>
* 按天推送
*
* @Date2024/9/21 17:19
*/
@Service("refundOnlyPluginInitializerToB")
public class RefundOnlyPluginInitializerToB extends PluginBaseEntity {
Logger logger = LoggerFactory.getLogger(RefundOnlyPluginInitializerToB.class);
@Override
public void initialize() {
logger.info(getPluginLabel() + "執行初始化方法initialize()");
}
@Override
public void destroy() {
logger.info(getPluginLabel() + "執行銷毀方法destroy()");
}
@Override
public String getPluginId() {
return "sales.refundOnlyPluginInitializerToB";
}
@Override
public String getPluginName() {
return "丽知:售后订单(ToB仅退款)--->U8C红字应收单";
}
@Override
public String getPluginLabel() {
return "丽知:售后订单(ToB仅退款)--->U8C红字应收单";
}
@Override
public String getPluginType() {
return "3";
}
@Autowired
private OfsUnifiedService ofsUnifiedService;
@Autowired
private IIntegrationTaskLivingDetailsDao iIntegrationTaskLivingDetailsDao;
@Autowired
private PushU8CByApiCode pushU8CByApiCode;
@Autowired
private SaveOrUpdateBusinessLogUtil saveOrUpdateBusinessLogUtil;
@Autowired
private QueryU8CEntityUtil queryU8CEntityUtil;
@Autowired
private IOnlyAfterSalesHDao onlyAfterSalesHDao;
@Autowired
private IOnlyAfterSalesBDao onlyAfterSalesBDao;
@Autowired
private OfsOrderAfterSalesAmountAllocationUtil ofsOrderAfterSalesAmountAllocationUtil;
@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 BaseResult.getSuccessMessageEntity("插件执行成功");
}
public void start() {
try {
// 获取当前日期
LocalDate today = LocalDate.now();
// 计算前一天的日期
String previousDay = today.minusDays(1).toString();
QueryReturnOrderRequestVO queryReturnOrderRequestVO = new QueryReturnOrderRequestVO();
queryReturnOrderRequestVO.setRefundedAt_start(previousDay+" 00:00:00");
queryReturnOrderRequestVO.setRefundedAt_end(previousDay+" 23:59:59");
List<RerturnGoodsOrderSearchData> returnGoodsOrders = queryOfsOnlyReturnOrders(queryReturnOrderRequestVO);
if (returnGoodsOrders == null || returnGoodsOrders.size() == 0) {
return;
}
//过滤仅退款 returnType:0 不退货exchangeType:0 不换货refundInd:1 退款 returnnode:300/200 售后/售中
List<RerturnGoodsOrderSearchData> refundOnlyData = filterRefundOnly(returnGoodsOrders);
//保存数据
saveData(refundOnlyData);
//过滤日志
List<RerturnGoodsOrderSearchData> filterReturnGoodsOrders = filterData(refundOnlyData);
if (filterReturnGoodsOrders == null || filterReturnGoodsOrders.size() == 0) {
return;
}
//推送
implement(filterReturnGoodsOrders);
} catch (Exception e) {
logger.error("丽知:售后订单(ToB仅退款)--->U8C红字应收单,start()方法报错:" + e);
}
}
/**
* @param ofsCode 售后订单号
*/
public void start(String ofsCode) {
String[] split = ofsCode.split("_");
try {
QueryReturnOrderRequestVO queryReturnOrderRequestVO = new QueryReturnOrderRequestVO();
queryReturnOrderRequestVO.setCode(split[0]);
List<RerturnGoodsOrderSearchData> returnGoodsOrders = queryOfsOnlyReturnOrders(queryReturnOrderRequestVO);
if (returnGoodsOrders == null || returnGoodsOrders.size() == 0) {
Assert.state(false, "丽知:售后订单(ToB仅退款):{} --->U8C红字应收单未查询到OFS售后订单(ToB仅退款)", ofsCode);
}
//过滤仅退款 returnType:0 不退货exchangeType:0 不换货refundInd:1 退款
List<RerturnGoodsOrderSearchData> refundOnlyData = filterRefundOnly(returnGoodsOrders);
//保存数据
saveData(refundOnlyData);
//过滤日志
List<RerturnGoodsOrderSearchData> filterReturnGoodsOrders = filterData(refundOnlyData);
if (filterReturnGoodsOrders == null || filterReturnGoodsOrders.size() == 0) {
Assert.state(false, "丽知:售后订单(ToB仅退款):{} --->U8C红字应收单该售后订单(ToB仅退款)已被推送成功,请勿重新推送", ofsCode);
}
//推送
implement(filterReturnGoodsOrders);
} catch (Exception e) {
logger.error("丽知:售后订单(ToB仅退款)--->U8C红字应收单,start(String ofsCode)方法报错:" + e);
}
}
/**
* 退款时间区间
*
* @param startTime
* @param endTime
*/
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";
QueryReturnOrderRequestVO queryReturnOrderRequestVO = new QueryReturnOrderRequestVO();
queryReturnOrderRequestVO.setRefundedAt_start(start);
queryReturnOrderRequestVO.setRefundedAt_end(end);
List<RerturnGoodsOrderSearchData> returnGoodsOrders = queryOfsOnlyReturnOrders(queryReturnOrderRequestVO);
if (returnGoodsOrders == null || returnGoodsOrders.size() == 0) {
return;
}
//过滤仅退款 returnType:0 不退货exchangeType:0 不换货refundInd:1 退款
List<RerturnGoodsOrderSearchData> refundOnlyData = filterRefundOnly(returnGoodsOrders);
//保存数据
saveData(refundOnlyData);
//过滤日志
List<RerturnGoodsOrderSearchData> filterReturnGoodsOrders = filterData(refundOnlyData);
if (filterReturnGoodsOrders == null || filterReturnGoodsOrders.size() == 0) {
return;
}
//推送
implement(filterReturnGoodsOrders);
} catch (Exception e) {
logger.error("丽知:售后订单(ToB仅退款)--->U8C红字应收单,start(String startTime, String endTime)方法报错:" + e);
}
}
/**
* 保存数据
*/
public void saveData(List<RerturnGoodsOrderSearchData> refundOnlyData) {
//过滤原始表
List<RerturnGoodsOrderSearchData> filterOriginalOrders = filterOriginal(refundOnlyData);
//底表存数据库
if (filterOriginalOrders.size() != 0) {
save(filterOriginalOrders);
}
}
/**
* 过滤元数据底表只过滤表头
*
* @param returnGoodsOrders
* @return
*/
private List<RerturnGoodsOrderSearchData> filterOriginal(List<RerturnGoodsOrderSearchData> returnGoodsOrders) {
List<RerturnGoodsOrderSearchData> filterOriginal = new ArrayList<>();
for (RerturnGoodsOrderSearchData goodsOrder : returnGoodsOrders) {
OnlyAfterSalesHEntity onlyAfterSalesHEntity = new OnlyAfterSalesHEntity();
onlyAfterSalesHEntity.setCode(goodsOrder.getHeader().getCode());
List<OnlyAfterSalesHEntity> query = onlyAfterSalesHDao.query(onlyAfterSalesHEntity);
if (query.size() != 0) {
continue;
} else {
filterOriginal.add(goodsOrder);
}
}
return filterOriginal;
}
/**
* returnType:0 不退货exchangeType:0 不换货refundInd:1 退款returnNode:300/200 售后/售中
*
* @param rerturnGoodsOrderSearchData
* @return
*/
public List<RerturnGoodsOrderSearchData> filterRefundOnly(List<RerturnGoodsOrderSearchData> rerturnGoodsOrderSearchData) {
List<RerturnGoodsOrderSearchData> filterRefundOnly = new ArrayList<>();
for (RerturnGoodsOrderSearchData rerturnGoodsOrderSearchDatum : rerturnGoodsOrderSearchData) {
RerturnGoodsOrderSearchHeader header = rerturnGoodsOrderSearchDatum.getHeader();
if ("0".equals(header.getReturnType()) && "0".equals(header.getExchangeType()) && "1".equals(header.getRefundInd())&&("300".equals(header.getReturnNode())||"200".equals(header.getReturnNode()))) {
filterRefundOnly.add(rerturnGoodsOrderSearchDatum);
}
}
return filterRefundOnly;
}
/**
* 单据号+skuCode
* 过滤成功日志,并且过滤子表退款金额==0的数据
*/
public List<RerturnGoodsOrderSearchData> filterData(List<RerturnGoodsOrderSearchData> returnGoodsOrders) {
List<RerturnGoodsOrderSearchData> filterReturnGoodsOrders = new ArrayList<>();
for (RerturnGoodsOrderSearchData returnGoodsOrder : returnGoodsOrders) {
RerturnGoodsOrderSearchHeader header = returnGoodsOrder.getHeader();
List<RerturnGoodsOrderSearchDetails> filterDetails = new ArrayList<>();
List<RerturnGoodsOrderSearchDetails> details = returnGoodsOrder.getDetails();
for (RerturnGoodsOrderSearchDetails detail : details) {
if (detail.getTotalAmount() == null || "0".equals(detail.getTotalAmount()) || 0 == Double.parseDouble(detail.getTotalAmount())) {
continue;
}
String rootAppPk = header.getCode() + "_" + detail.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) {
filterDetails.add(detail);
}
}
if (filterDetails.size() == 0) {
continue;
} else {
returnGoodsOrder.setDetails(filterDetails);
filterReturnGoodsOrders.add(returnGoodsOrder);
}
}
return filterReturnGoodsOrders;
}
/**
* 具体实现推送U8C红字应收单
* <p>
* 公司+店铺+仓库+SKU+收发类别+部门 分组
* <p>
* 因为优惠金额在表头先按单据便利一变具体分摊金额拆到每行在去汇总
*/
public void implement(List<RerturnGoodsOrderSearchData> filterReturnGoodsOrders) throws Exception {
//分摊分摊后的子表
List<RerturnGoodsOrderSearchDetails> allDetail = new ArrayList<>();
List<RerturnGoodsOrderSearchHeader> allHeader = new ArrayList<>();
//分摊
for (RerturnGoodsOrderSearchData filterReturnGoodsOrder : filterReturnGoodsOrders) {
// ofsOrderAfterSalesAmountAllocationUtil.tocSalesAmountAllocation(filterReturnGoodsOrder);
//查询部门
String refOrderCode = filterReturnGoodsOrder.getHeader().getRefOrderCode();
SaleOrderMessageDto ofsSaleOrder = getOfsOrder(refOrderCode);
String deptCode = "002";
if (ofsSaleOrder != null) {
// Assert.state(false,"根据仅退款:{},查询销售订单:{},失败!未查询到对应销售订单",filterReturnGoodsOrder.getHeader().getCode(),refOrderCode);
if (ofsSaleOrder.getData().get(0).getHeader().getDepartmentType() != null && !"".equals((ofsSaleOrder.getData().get(0).getHeader().getDepartmentType()))) {
deptCode = ofsSaleOrder.getData().get(0).getHeader().getDepartmentType();
}
}
filterReturnGoodsOrder.getHeader().setSaleDeptCode(deptCode);
allHeader.add(filterReturnGoodsOrder.getHeader());
allDetail.addAll(filterReturnGoodsOrder.getDetails());
}
//分组公司+店铺+部门+单据日期(退款日期),仅退款没有仓库固不去
Map<String, List<RerturnGoodsOrderSearchHeader>> collect = allHeader.stream().collect(Collectors.groupingBy(index -> index.getCompanyCode() + "_" + index.getStoreCode() + "_" + index.getSaleDeptCode() + "_" + index.getRefundedAt().substring(0, 10)));
for (Map.Entry<String, List<RerturnGoodsOrderSearchHeader>> entry : collect.entrySet()) {
;
String[] split = entry.getKey().split("_");//[0]公司 [1]店铺 [2]部门 [3]单据日期
//v:header列表, header.code == details.returnOrderCode
String mapStr = "";
String format = "";//暂时取创建时间refundAt没返回
String response = "";
// String ofsCode = v.get(0).getCode();
// String ofsId = v.get(0).getId();
//日志记录使用
List<RerturnGoodsOrderSearchDetails> logDetails = new ArrayList<>();
List<RerturnGoodsOrderSearchDetails> r1 = new ArrayList<>();
try {
ArapDjzbVO arapDjzbVO = new ArapDjzbVO();
//主表 在表头先
ArapDjzbVO.Parentt parentvo = new ArapDjzbVO.Parentt();
//djrq 单据日期
format = split[3];//暂时取创建时间refundAt没返回
// format = "2024-09-30";
parentvo.setDjrq(format);
//dwbm 公司
String corpCode = queryU8CEntityUtil.queryBdDefDocByPkDefDocList(split[0]);
parentvo.setDwbm(corpCode);
//lrr 录入人
parentvo.setLrr(OverallConstant.getOverAllValue("u8cApiZdrCode"));
//wldx 往来对象标识 (0 客户 2部门 3业务员)
parentvo.setWldx("0");
//hbbm 客商==店铺,根据店铺区分tobtoc,,,编码需要转换转换称自定义项
BdCubasdocEntity entity = queryU8CEntityUtil.getFuzzyQueryCustomers(split[1]);
if(entity==null){
Assert.state(false,"根据客商自定义项1{},未查询到客商基本档案,请假查。",split[1]);
}
parentvo.setHbbm(entity.getCustcode());
//根据店铺区分tobtoc,区分业务流程
String s = checkFlow(parentvo, split[1]);
if("TOC".equals(s)){
continue;
}
//deptid 部门
parentvo.setDeptid(split[2]);
//ywybm 业务员编码 ,不传喽
//shr 审核人
parentvo.setShr(OverallConstant.getOverAllValue("u8cApiZdrCode"));
//shrq 审核日
parentvo.setShrq(format);
//scomment 备注 returnNote 客服备注 sellerNote 卖家备注
//parentvo.setScomment(header.getReturnNote());
//djlxbm 单据类型编码交易类型编码使用此字段如D0D1D2
parentvo.setDjlxbm("D0");
// //xslxbm 业务流程
parentvo.setXslxbm("BJTK");//TOC仅退款:JTK TOB仅退款:BJTK
//feinvstatus 开票状态
parentvo.setFeinvstatus("0");
//zyx1店铺
parentvo.setZyx1(split[1]);
//zyx2来源平台
parentvo.setZyx2(entry.getValue().get(0).getSourcePlatformCode());
//zyx3 收发类别 销售出库写死SALES
parentvo.setZyx3("SALES");
//zyx16 单据红字标识 1Y 2N
parentvo.setZyx16("1");
//子表,需要通过多个主表的id找到多个子表,且退货金额==0的不要
List<RerturnGoodsOrderSearchDetails> ofsDetails = new ArrayList<>();
for (RerturnGoodsOrderSearchHeader rerturnGoodsOrderSearchHeader : entry.getValue()) {
allDetail.stream().forEach(index -> {
if (rerturnGoodsOrderSearchHeader.getCode().equals(index.getReturnOrderCode()) && index.getTotalAmount() != null && !"0".equals(index.getTotalAmount())) {
ofsDetails.add(index);
}
});
}
logDetails.addAll(ofsDetails);
//没有sku编码的报错
r1.clear();
for (RerturnGoodsOrderSearchDetails logDetail : logDetails) {
if(logDetail.getSkuCode()==null||"".equals(logDetail.getSkuCode())) {
IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity();
integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_N);
integrationTaskLivingDetailsEntity.setRootAppNewData(null);
integrationTaskLivingDetailsEntity.setNewTransmitInfo(logDetail.getReturnOrderCode() + ",没有SKU编码请检查OFS系统订单");
integrationTaskLivingDetailsEntity.setNewPushDate(new Date());
integrationTaskLivingDetailsEntity.setBusinessDate(format);
integrationTaskLivingDetailsEntity.setRootAppPk(logDetail.getReturnOrderCode() + "_" + logDetail.getSkuCode());
integrationTaskLivingDetailsEntity.setRootAppBill(logDetail.getReturnOrderCode());
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity);
}else {
r1.add(logDetail);
}
}
//按sku分组
Map<String, List<RerturnGoodsOrderSearchDetails>> collectSKU = r1.stream().collect(Collectors.groupingBy(index -> index.getSkuCode()));
List<ArapDjzbVO.Childrenn> children = new ArrayList<>();
Set<Map.Entry<String, List<RerturnGoodsOrderSearchDetails>>> entries = collectSKU.entrySet();
for (Map.Entry<String, List<RerturnGoodsOrderSearchDetails>> entry1 : entries) {
children.clear();
String kk = entry1.getKey();
List<RerturnGoodsOrderSearchDetails> vv = entry1.getValue();
//kk是sku编码,vv是sku相同的子表
try {
ArapDjzbVO.Childrenn childrenn = new ArapDjzbVO.Childrenn();
//cinventoryid 存货
childrenn.setCinventoryid(kk);
//sum:jfbbje jfybje 借方本币金额/借方原币金额
BigDecimal sum_jfbbje = new BigDecimal(0);
//sum:jfbbsj jfybsj 借方本币税金/借方原币税金 默认0.13
BigDecimal sum_jfbbsj = new BigDecimal(0);
//sum:wbfbbje jfybwsje 借方本币无税金额/借方原币无税金额
BigDecimal sum_wbfbbje = new BigDecimal(0);
//sum:zyx4 平台优惠 platformDiscounts
BigDecimal sum_zyx4 = new BigDecimal(0);
//sum:zyx5 支付优惠 payDiscounts
BigDecimal sum_zyx5 = new BigDecimal(0);
//sum:zyx6 达人优惠 expertDiscounts
BigDecimal sum_zyx6 = new BigDecimal(0);
//sum:zyx7 商家优惠
// BigDecimal sum_zyx7 = new BigDecimal(0);
//金额计算
for (RerturnGoodsOrderSearchDetails detail : vv) {
sum_jfbbje = sum_jfbbje.add(new BigDecimal(detail.getTotalAmount()));
BigDecimal sj = new BigDecimal(detail.getTotalAmount()).multiply(new BigDecimal(0.13)).setScale(2, RoundingMode.FLOOR);
sum_jfbbsj = sum_jfbbsj.add(sj);
BigDecimal ws = new BigDecimal(detail.getTotalAmount()).subtract(sj);
sum_wbfbbje = sum_wbfbbje.add(ws);
// if (detail.getShareTargetPlatformDiscounts() != null) {
// sum_zyx4 = sum_zyx4.add(detail.getShareTargetPlatformDiscounts());
// }
// if (detail.getShareTargetMerchantDiscounts() != null) {
// sum_zyx5 = sum_zyx5.add(detail.getShareTargetMerchantDiscounts());
// }
// if (detail.getShareTargetExpertDiscounts() != null) {
// sum_zyx6 = sum_zyx6.add(detail.getShareTargetExpertDiscounts());
// }
// if (detail.getShareTargetPayDiscounts() != null) {
// sum_zyx7 = sum_zyx7.add(detail.getShareTargetPayDiscounts());
// }
if (detail.getPlatformDiscounts() != null) {
sum_zyx4 = sum_zyx4.add(new BigDecimal(detail.getPlatformDiscounts()));
}
if (detail.getPayDiscounts() != null) {
sum_zyx5 = sum_zyx5.add(new BigDecimal(detail.getPayDiscounts()));
}
if (detail.getExpertDiscounts() != null) {
sum_zyx6 = sum_zyx6.add(new BigDecimal(detail.getExpertDiscounts()));
}
}
childrenn.setJfbbje("-" + sum_jfbbje);
childrenn.setJfybje("-" + sum_jfbbje);
childrenn.setJfbbsj("-" + sum_jfbbsj);
childrenn.setJfybsj("-" + sum_jfbbsj);
childrenn.setWbfbbje("-" + sum_wbfbbje);
childrenn.setJfybwsje("-" + sum_wbfbbje);
childrenn.setZyx4(String.valueOf(sum_zyx4));
childrenn.setZyx5(String.valueOf(sum_zyx5));
childrenn.setZyx6(String.valueOf(sum_zyx6));
children.add(childrenn);
//推送
arapDjzbVO.setParentvo(parentvo);
arapDjzbVO.setChildren(children);
mapStr = "{\"djzbvo\":[" + JSONUtil.toJsonStr(arapDjzbVO) + "]}";
//推送
ZTResult ztResult = pushU8CByApiCode.pushByCode(OverallConstant.getOverAllValue("arapYsInsertApproveCode"), mapStr);
//两层判断,一层中台转发,一层u8c返回
if ("false".equals(ztResult.getFlag())) {
//转发失败
response = JSONUtil.toJsonStr(ztResult.getAttribute());
Assert.state(false, "丽知:售后订单(ToB仅退款)--->U8C红字应收单中台转发失败,失败原因:{}", ztResult.getAttribute());
}
Attribute attribute = ztResult.getAttribute();
boolean isSuccess = false;
String djbh = "";
String vouchid = "";
if ("success".equals(attribute.getStatus())) {
isSuccess = true;
String data = attribute.getData();
ArapDjzb arapDj = resultDataHandle(data);
djbh = arapDj.getParentvo().getDjbh();
vouchid = arapDj.getParentvo().getVouchid();
}
if (!isSuccess) {
Assert.state(false, "推送U8C--> 丽知:售后订单(ToB仅退款)--->U8C红字应收单 失败 接口返回结果:{} 接口入参:{}", response, mapStr);
}
//成功
for (RerturnGoodsOrderSearchDetails ofsDetail : vv) {
IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity();
integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_Y);
integrationTaskLivingDetailsEntity.setRootAppNewData(mapStr);
integrationTaskLivingDetailsEntity.setNewTransmitInfo(response);
integrationTaskLivingDetailsEntity.setNewPushDate(new Date());
integrationTaskLivingDetailsEntity.setBusinessDate(format);
integrationTaskLivingDetailsEntity.setRootAppPk(ofsDetail.getReturnOrderCode() + "_" + ofsDetail.getSkuCode());
integrationTaskLivingDetailsEntity.setRootAppBill(ofsDetail.getReturnOrderCode());//仅退款单号
integrationTaskLivingDetailsEntity.setNewSystemNumber(djbh);
integrationTaskLivingDetailsEntity.setNewSystemPrimary(vouchid);
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity);
}
} catch (Exception e) {
logger.error("推送U8C丽知售后订单(ToB仅退款)--->U8C红字应收单失败失败原因" + e);
//失败则该k下的所有子表记录失败
ReusltStrDto reusltStrDto = JSON.parseObject(response, ReusltStrDto.class);
String ErrMessage = "";
if (reusltStrDto != null) {
ErrMessage = "推送U8C丽知售后订单(ToB仅退款)--->U8C红字应收单失败失败原因" + reusltStrDto.getErrormsg();
} else {
ErrMessage = "推送U8C丽知售后订单(ToB仅退款)--->U8C红字应收单失败失败原因" + e.getMessage();
}
//失败 批量新增 ofsDetails
for (RerturnGoodsOrderSearchDetails logDetail : vv) {
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(logDetail.getReturnOrderCode() + "_" + logDetail.getSkuCode());
integrationTaskLivingDetailsEntity.setRootAppBill(logDetail.getReturnOrderCode());
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity);
}
}
}
} catch (Exception e) {
logger.error("推送U8C丽知售后订单(ToB仅退款)--->U8C红字应收单最外层失败失败原因" + e);
//失败,最外层则该k下的所有子表记录失败
ReusltStrDto reusltStrDto = JSON.parseObject(response, ReusltStrDto.class);
String ErrMessage = "";
if (reusltStrDto != null) {
ErrMessage = "推送U8C丽知售后订单(ToB仅退款)--->U8C红字应收单最外层失败失败原因" + reusltStrDto.getErrormsg();
} else {
ErrMessage = "推送U8C丽知售后订单(ToB仅退款)--->U8C红字应收单最外层失败失败原因" + e.getMessage();
}
//失败 批量新增 ofsDetails
for (RerturnGoodsOrderSearchDetails logDetail : r1) {
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(logDetail.getReturnOrderCode() + "_" + logDetail.getSkuCode());
integrationTaskLivingDetailsEntity.setRootAppBill(logDetail.getReturnOrderCode());
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity);
}
}
}
}
/**
* 公司转换
* @param allHeader
*/
public void transCorp(List<RerturnGoodsOrderSearchHeader> allHeader){
if(allHeader.size()==0){
return;
}
}
/**
* 根据店铺区分tob toc业务流程
* TOC仅退款:JTK TOB仅退款:BJTK
* parentvo.setXslxbm("JTK");
* 非b及c
* @param parentvo
* @param shop
*/
@Autowired
private ShopTobOrToCUtil shopTobOrToCUtil;
public String checkFlow(ArapDjzbVO.Parentt parentvo,String shop){
String tobShop = shopTobOrToCUtil.getCommaShop("TOB");
String tocShop = shopTobOrToCUtil.getCommaShop("TOC");
System.out.println(tobShop);
System.out.println(tocShop);
if(tobShop.contains(shop)){
// parentvo.setXslxbm("BJTK");//TOB
return "TOB";
}else {
// parentvo.setXslxbm("JTK");//TOC
return "TOC";
}
}
/**
* ofs仅退款数据存中台mysql数据库
* 表头表体分别存忽略大小写 BeanUtil.copyPropreties(a,b,Copyoptions.create().ignoreCase())
*
* @param returnGoodsOrders
*/
public void save(List<RerturnGoodsOrderSearchData> returnGoodsOrders) {
// List<OnlyAfterSalesHEntity> allH=new ArrayList<>();
// List<OnlyAfterSalesBEntity> allB=new ArrayList<>();
for (RerturnGoodsOrderSearchData returnGoodsOrder : returnGoodsOrders) {
RerturnGoodsOrderSearchHeader header = returnGoodsOrder.getHeader();
OnlyAfterSalesHEntity onlyAfterSalesHEntity = new OnlyAfterSalesHEntity();
BeanUtil.copyProperties(header, onlyAfterSalesHEntity, CopyOptions.create().ignoreCase());
// allH.add(onlyAfterSalesHEntity);
onlyAfterSalesHEntity.setId(null);
onlyAfterSalesHEntity.setOfsid(header.getId());
OnlyAfterSalesHEntity save = onlyAfterSalesHDao.save(onlyAfterSalesHEntity);
String HId = save.getId();
List<RerturnGoodsOrderSearchDetails> details = returnGoodsOrder.getDetails();
for (RerturnGoodsOrderSearchDetails detail : details) {
OnlyAfterSalesBEntity onlyAfterSalesBEntity = new OnlyAfterSalesBEntity();
BeanUtil.copyProperties(detail, onlyAfterSalesBEntity, CopyOptions.create().ignoreCase());
// allB.add(onlyAfterSalesBEntity);
onlyAfterSalesBEntity.setId(null);
onlyAfterSalesBEntity.setHid(HId);
onlyAfterSalesBEntity.setOfsid(detail.getId());
//四个优惠platformDiscounts 平台优惠merchantDiscounts 商家优惠expertDiscounts 达人优惠payDiscounts 支付优惠
onlyAfterSalesBEntity.setPlatformDiscounts(header.getPlatformDiscounts());
onlyAfterSalesBEntity.setMerchantDiscounts(header.getMerchantDiscounts());
onlyAfterSalesBEntity.setExpertDiscounts(header.getExpertDiscounts());
onlyAfterSalesBEntity.setPayDiscounts(header.getPayDiscounts());
onlyAfterSalesBDao.save(onlyAfterSalesBEntity);
}
}
}
/**
* 查询OFS销售订单
*/
public SaleOrderMessageDto getOfsOrder(String code) throws Exception {
Long pageSize = 200L;
Long pageNo = 1L;
QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo();
queryOfsSoSaleOutVo.setPageNo(pageNo);
queryOfsSoSaleOutVo.setPageSize(pageSize);
queryOfsSoSaleOutVo.setCode(code);
InterfaceParamDto interfaceParamDto = new InterfaceParamDto();
interfaceParamDto.setApi("ofs.salesOrder.search");
interfaceParamDto.setData(JSON.toJSONString(queryOfsSoSaleOutVo));
SaleOrderMessageDto saleOrderMessageDto = (SaleOrderMessageDto) ofsUnifiedService.unified(interfaceParamDto);
if (saleOrderMessageDto.getData().size() == 0) {
return null;
}
return saleOrderMessageDto;
}
/**
* 查询ofs仅退款订单 销售退货单查询ofs.returnOrder. search)
* <p>
* 查询条件refundedAt_startrefundedAt_endcode
* returnType:0 不退货
* exchangeType:0 不换货
* refundInd:1 退款
*/
public List<RerturnGoodsOrderSearchData> queryOfsOnlyReturnOrders(QueryReturnOrderRequestVO queryReturnOrderRequestVO) throws Exception {
Long pageNo = 1L;
List<RerturnGoodsOrderSearchData> all = new ArrayList<>();
InterfaceParamDto interfaceParamDto = new InterfaceParamDto();
interfaceParamDto.setApi("ofs.returnOrder.search");
queryReturnOrderRequestVO.setClientCode("LETS");
//100订单池 500待同步 510已同步 900售后成功 400待合单 800已入库 999作废 700收货中 0待完善
// queryReturnOrderRequestVO.setStatus("900");
queryReturnOrderRequestVO.setPageNo(pageNo);
queryReturnOrderRequestVO.setPageSize(500L);
interfaceParamDto.setData(JSON.toJSONString(queryReturnOrderRequestVO));
RerturnGoodsOrderSearchJsonRootBean rerturnGoodsOrderSearchJsonRootBean = (RerturnGoodsOrderSearchJsonRootBean) ofsUnifiedService.unified(interfaceParamDto);
if (rerturnGoodsOrderSearchJsonRootBean.getData() == null || rerturnGoodsOrderSearchJsonRootBean.getData().size() == 0) {
return null;
}
all.addAll(rerturnGoodsOrderSearchJsonRootBean.getData());
int count = rerturnGoodsOrderSearchJsonRootBean.getData().size();
while (count >= 500) {//>=500,可能还有下一页
//还有下一页
pageNo++;
queryReturnOrderRequestVO.setPageNo(pageNo);
interfaceParamDto.setData(JSON.toJSONString(queryReturnOrderRequestVO));
RerturnGoodsOrderSearchJsonRootBean rerturnGoodsOrderSearchJsonRootBean1 = (RerturnGoodsOrderSearchJsonRootBean) ofsUnifiedService.unified(interfaceParamDto);
all.addAll(rerturnGoodsOrderSearchJsonRootBean1.getData());
count = rerturnGoodsOrderSearchJsonRootBean1.getData().size();
}
return all;
}
private ArapDjzb resultDataHandle(String resultData) {
try {
if (resultData != null && !"".equals(resultData)) {
if (resultData.contains("[")) {
resultData = resultData.substring(1, resultData.length() - 1);
}
return JSON.parseObject(resultData, ArapDjzb.class);
}
} catch (Exception e) {
e.printStackTrace();
logger.error("解析返回参数失败的错误", e);
//如果解析失败记录原因但是不能影响结果的记录
}
return null;
}
}

View File

@ -0,0 +1,813 @@
package com.hzya.frame.plugin.lets.plugin.sales;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
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.dao.IOnlyAfterSalesBDao;
import com.hzya.frame.plugin.lets.dao.IOnlyAfterSalesHDao;
import com.hzya.frame.plugin.lets.entity.BdCubasdocEntity;
import com.hzya.frame.plugin.lets.entity.OnlyAfterSalesBEntity;
import com.hzya.frame.plugin.lets.entity.OnlyAfterSalesHEntity;
import com.hzya.frame.plugin.lets.ofsvo.QueryOfsSoSaleOutVo;
import com.hzya.frame.plugin.lets.ofsvo.QueryReturnOrderRequestVO;
import com.hzya.frame.plugin.lets.u8cdto.ArapDjzb;
import com.hzya.frame.plugin.lets.u8cdto.ArapDjzbVO;
import com.hzya.frame.plugin.lets.u8cdto.ReusltStrDto;
import com.hzya.frame.plugin.lets.util.OfsOrderAfterSalesAmountAllocationUtil;
import com.hzya.frame.plugin.lets.util.QueryU8CEntityUtil;
import com.hzya.frame.plugin.lets.util.SaveOrUpdateBusinessLogUtil;
import com.hzya.frame.plugin.lets.util.ShopTobOrToCUtil;
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.dto.InterfaceParamDto;
import com.hzya.frame.ttxofs.dto.ofssalesordersearch.SaleOrderMessageDto;
import com.hzya.frame.ttxofs.dto.returngoodordersearch.RerturnGoodsOrderSearchData;
import com.hzya.frame.ttxofs.dto.returngoodordersearch.RerturnGoodsOrderSearchDetails;
import com.hzya.frame.ttxofs.dto.returngoodordersearch.RerturnGoodsOrderSearchHeader;
import com.hzya.frame.ttxofs.dto.returngoodordersearch.RerturnGoodsOrderSearchJsonRootBean;
import com.hzya.frame.ttxofs.service.OfsUnifiedService;
import com.hzya.frame.web.entity.BaseResult;
import com.hzya.frame.web.entity.JsonResultEntity;
import dm.jdbc.d.V;
import org.checkerframework.checker.units.qual.K;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
/**
* add by zyd
* O售后订单(ToC仅退款) -> U8C红字应收单
* <p>(取售中售后)
* returnType:0 不退货
* exchangeType:0 不换货
* refundInd:1 退款
* <p>
* 按天推送
*
* @Date2024/9/21 17:19
*/
@Service("refundOnlyPluginInitializerToC")
public class RefundOnlyPluginInitializerToC extends PluginBaseEntity {
Logger logger = LoggerFactory.getLogger(RefundOnlyPluginInitializerToC.class);
@Override
public void initialize() {
logger.info(getPluginLabel() + "執行初始化方法initialize()");
}
@Override
public void destroy() {
logger.info(getPluginLabel() + "執行銷毀方法destroy()");
}
@Override
public String getPluginId() {
return "sales.RefundOnlyPluginInitializerToC";
}
@Override
public String getPluginName() {
return "丽知:售后订单(ToC仅退款)--->U8C红字应收单";
}
@Override
public String getPluginLabel() {
return "丽知:售后订单(ToC仅退款)--->U8C红字应收单";
}
@Override
public String getPluginType() {
return "3";
}
@Autowired
private OfsUnifiedService ofsUnifiedService;
@Autowired
private IIntegrationTaskLivingDetailsDao iIntegrationTaskLivingDetailsDao;
@Autowired
private PushU8CByApiCode pushU8CByApiCode;
@Autowired
private SaveOrUpdateBusinessLogUtil saveOrUpdateBusinessLogUtil;
@Autowired
private QueryU8CEntityUtil queryU8CEntityUtil;
@Autowired
private IOnlyAfterSalesHDao onlyAfterSalesHDao;
@Autowired
private IOnlyAfterSalesBDao onlyAfterSalesBDao;
@Autowired
private OfsOrderAfterSalesAmountAllocationUtil ofsOrderAfterSalesAmountAllocationUtil;
@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 BaseResult.getSuccessMessageEntity("插件执行成功");
}
public void start() {
try {
// 获取当前日期
LocalDate today = LocalDate.now();
// 计算前一天的日期
String previousDay = today.minusDays(1).toString();
QueryReturnOrderRequestVO queryReturnOrderRequestVO = new QueryReturnOrderRequestVO();
queryReturnOrderRequestVO.setRefundedAt_start(previousDay+" 00:00:00");
queryReturnOrderRequestVO.setRefundedAt_end(previousDay+" 23:59:59");
List<RerturnGoodsOrderSearchData> returnGoodsOrders = queryOfsOnlyReturnOrders(queryReturnOrderRequestVO);
if (returnGoodsOrders == null || returnGoodsOrders.size() == 0) {
return;
}
//过滤仅退款 returnType:0 不退货exchangeType:0 不换货refundInd:1 退款 returnnode:300/200 售后/售中
List<RerturnGoodsOrderSearchData> refundOnlyData = filterRefundOnly(returnGoodsOrders);
//保存数据
saveData(refundOnlyData);
//过滤日志
List<RerturnGoodsOrderSearchData> filterReturnGoodsOrders = filterData(refundOnlyData);
if (filterReturnGoodsOrders == null || filterReturnGoodsOrders.size() == 0) {
return;
}
//推送
implement(filterReturnGoodsOrders);
} catch (Exception e) {
logger.error("丽知:售后订单(ToC仅退款)--->U8C红字应收单,start()方法报错:" + e);
}
}
/**
* @param ofsCode 售后订单号
*/
public void start(String ofsCode) {
String[] split = ofsCode.split("_");
try {
QueryReturnOrderRequestVO queryReturnOrderRequestVO = new QueryReturnOrderRequestVO();
queryReturnOrderRequestVO.setCode(split[0]);
List<RerturnGoodsOrderSearchData> returnGoodsOrders = queryOfsOnlyReturnOrders(queryReturnOrderRequestVO);
if (returnGoodsOrders == null || returnGoodsOrders.size() == 0) {
Assert.state(false, "丽知:售后订单(ToC仅退款):{} --->U8C红字应收单未查询到OFS售后订单(ToC仅退款)", ofsCode);
}
//过滤仅退款 returnType:0 不退货exchangeType:0 不换货refundInd:1 退款
List<RerturnGoodsOrderSearchData> refundOnlyData = filterRefundOnly(returnGoodsOrders);
//保存数据
saveData(refundOnlyData);
//过滤日志
List<RerturnGoodsOrderSearchData> filterReturnGoodsOrders = filterData(refundOnlyData);
if (filterReturnGoodsOrders == null || filterReturnGoodsOrders.size() == 0) {
Assert.state(false, "丽知:售后订单(ToC仅退款):{} --->U8C红字应收单该售后订单(ToC仅退款)已被推送成功,请勿重新推送", ofsCode);
}
//推送
implement(filterReturnGoodsOrders);
} catch (Exception e) {
logger.error("丽知:售后订单(ToC仅退款)--->U8C红字应收单,start(String ofsCode)方法报错:" + e);
}
}
/**
* 退款时间区间
*
* @param startTime
* @param endTime
*/
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";
QueryReturnOrderRequestVO queryReturnOrderRequestVO = new QueryReturnOrderRequestVO();
queryReturnOrderRequestVO.setRefundedAt_start(start);
queryReturnOrderRequestVO.setRefundedAt_end(end);
List<RerturnGoodsOrderSearchData> returnGoodsOrders = queryOfsOnlyReturnOrders(queryReturnOrderRequestVO);
if (returnGoodsOrders == null || returnGoodsOrders.size() == 0) {
return;
}
//过滤仅退款 returnType:0 不退货exchangeType:0 不换货refundInd:1 退款
List<RerturnGoodsOrderSearchData> refundOnlyData = filterRefundOnly(returnGoodsOrders);
//保存数据
saveData(refundOnlyData);
//过滤日志
List<RerturnGoodsOrderSearchData> filterReturnGoodsOrders = filterData(refundOnlyData);
if (filterReturnGoodsOrders == null || filterReturnGoodsOrders.size() == 0) {
return;
}
//推送
implement(filterReturnGoodsOrders);
} catch (Exception e) {
logger.error("丽知:售后订单(ToC仅退款)--->U8C红字应收单,start(String startTime, String endTime)方法报错:" + e);
}
}
/**
* 保存数据
*/
public void saveData(List<RerturnGoodsOrderSearchData> refundOnlyData) {
//过滤原始表
List<RerturnGoodsOrderSearchData> filterOriginalOrders = filterOriginal(refundOnlyData);
//底表存数据库
if (filterOriginalOrders.size() != 0) {
save(filterOriginalOrders);
}
}
/**
* 过滤元数据底表只过滤表头
*
* @param returnGoodsOrders
* @return
*/
private List<RerturnGoodsOrderSearchData> filterOriginal(List<RerturnGoodsOrderSearchData> returnGoodsOrders) {
List<RerturnGoodsOrderSearchData> filterOriginal = new ArrayList<>();
for (RerturnGoodsOrderSearchData goodsOrder : returnGoodsOrders) {
OnlyAfterSalesHEntity onlyAfterSalesHEntity = new OnlyAfterSalesHEntity();
onlyAfterSalesHEntity.setCode(goodsOrder.getHeader().getCode());
List<OnlyAfterSalesHEntity> query = onlyAfterSalesHDao.query(onlyAfterSalesHEntity);
if (query.size() != 0) {
continue;
} else {
filterOriginal.add(goodsOrder);
}
}
return filterOriginal;
}
/**
* returnType:0 不退货exchangeType:0 不换货refundInd:1 退款returnNode:300/200 售后/售中
*
* @param rerturnGoodsOrderSearchData
* @return
*/
public List<RerturnGoodsOrderSearchData> filterRefundOnly(List<RerturnGoodsOrderSearchData> rerturnGoodsOrderSearchData) {
List<RerturnGoodsOrderSearchData> filterRefundOnly = new ArrayList<>();
for (RerturnGoodsOrderSearchData rerturnGoodsOrderSearchDatum : rerturnGoodsOrderSearchData) {
RerturnGoodsOrderSearchHeader header = rerturnGoodsOrderSearchDatum.getHeader();
if ("0".equals(header.getReturnType()) && "0".equals(header.getExchangeType()) && "1".equals(header.getRefundInd())&&("300".equals(header.getReturnNode())||"200".equals(header.getReturnNode()))) {
filterRefundOnly.add(rerturnGoodsOrderSearchDatum);
}
}
return filterRefundOnly;
}
/**
* 单据号+skuCode
* 过滤成功日志,并且过滤子表退款金额==0的数据
*/
public List<RerturnGoodsOrderSearchData> filterData(List<RerturnGoodsOrderSearchData> returnGoodsOrders) {
List<RerturnGoodsOrderSearchData> filterReturnGoodsOrders = new ArrayList<>();
for (RerturnGoodsOrderSearchData returnGoodsOrder : returnGoodsOrders) {
RerturnGoodsOrderSearchHeader header = returnGoodsOrder.getHeader();
List<RerturnGoodsOrderSearchDetails> filterDetails = new ArrayList<>();
List<RerturnGoodsOrderSearchDetails> details = returnGoodsOrder.getDetails();
for (RerturnGoodsOrderSearchDetails detail : details) {
if (detail.getTotalAmount() == null || "0".equals(detail.getTotalAmount()) || 0 == Double.parseDouble(detail.getTotalAmount())) {
continue;
}
String rootAppPk = header.getCode() + "_" + detail.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) {
filterDetails.add(detail);
}
}
if (filterDetails.size() == 0) {
continue;
} else {
returnGoodsOrder.setDetails(filterDetails);
filterReturnGoodsOrders.add(returnGoodsOrder);
}
}
return filterReturnGoodsOrders;
}
/**
* 具体实现推送U8C红字应收单
* <p>
* 公司+店铺+仓库+SKU+收发类别+部门 分组
* <p>
* 因为优惠金额在表头先按单据便利一变具体分摊金额拆到每行在去汇总
*/
public void implement(List<RerturnGoodsOrderSearchData> filterReturnGoodsOrders) throws Exception {
//分摊分摊后的子表
List<RerturnGoodsOrderSearchDetails> allDetail = new ArrayList<>();
List<RerturnGoodsOrderSearchHeader> allHeader = new ArrayList<>();
//分摊
for (RerturnGoodsOrderSearchData filterReturnGoodsOrder : filterReturnGoodsOrders) {
// ofsOrderAfterSalesAmountAllocationUtil.tocSalesAmountAllocation(filterReturnGoodsOrder);
//查询部门
String refOrderCode = filterReturnGoodsOrder.getHeader().getRefOrderCode();
SaleOrderMessageDto ofsSaleOrder = getOfsOrder(refOrderCode);
String deptCode = "002";
if (ofsSaleOrder != null) {
// Assert.state(false,"根据仅退款:{},查询销售订单:{},失败!未查询到对应销售订单",filterReturnGoodsOrder.getHeader().getCode(),refOrderCode);
if (ofsSaleOrder.getData().get(0).getHeader().getDepartmentType() != null && !"".equals((ofsSaleOrder.getData().get(0).getHeader().getDepartmentType()))) {
deptCode = ofsSaleOrder.getData().get(0).getHeader().getDepartmentType();
}
}
filterReturnGoodsOrder.getHeader().setSaleDeptCode(deptCode);
allHeader.add(filterReturnGoodsOrder.getHeader());
allDetail.addAll(filterReturnGoodsOrder.getDetails());
}
//分组公司+店铺+部门+单据日期(退款日期),仅退款没有仓库固不去
Map<String, List<RerturnGoodsOrderSearchHeader>> collect = allHeader.stream().collect(Collectors.groupingBy(index -> index.getCompanyCode() + "_" + index.getStoreCode() + "_" + index.getSaleDeptCode() + "_" + index.getRefundedAt().substring(0, 10)));
for (Map.Entry<String, List<RerturnGoodsOrderSearchHeader>> entry : collect.entrySet()) {
;
String[] split = entry.getKey().split("_");//[0]公司 [1]店铺 [2]部门 [3]单据日期
//v:header列表, header.code == details.returnOrderCode
String mapStr = "";
String format = "";//暂时取创建时间refundAt没返回
String response = "";
// String ofsCode = v.get(0).getCode();
// String ofsId = v.get(0).getId();
//日志记录使用
List<RerturnGoodsOrderSearchDetails> logDetails = new ArrayList<>();
List<RerturnGoodsOrderSearchDetails> r1 = new ArrayList<>();
try {
ArapDjzbVO arapDjzbVO = new ArapDjzbVO();
//主表 在表头先
ArapDjzbVO.Parentt parentvo = new ArapDjzbVO.Parentt();
//djrq 单据日期
format = split[3];//暂时取创建时间refundAt没返回
// format = "2024-09-30";
parentvo.setDjrq(format);
//dwbm 公司
String corpCode = queryU8CEntityUtil.queryBdDefDocByPkDefDocList(split[0]);
parentvo.setDwbm(corpCode);
//lrr 录入人
parentvo.setLrr(OverallConstant.getOverAllValue("u8cApiZdrCode"));
//wldx 往来对象标识 (0 客户 2部门 3业务员)
parentvo.setWldx("0");
//hbbm 客商==店铺,根据店铺区分tobtoc,,,编码需要转换转换称自定义项
BdCubasdocEntity entity = queryU8CEntityUtil.getFuzzyQueryCustomers(split[1]);
if(entity==null){
Assert.state(false,"根据客商自定义项1{},未查询到客商基本档案,请假查。",split[1]);
}
parentvo.setHbbm(entity.getCustcode());
//根据店铺区分tobtoc,区分业务流程
String s = checkFlow(parentvo, split[1]);
if("TOB".equals(s)){
continue;
}
//deptid 部门
parentvo.setDeptid(split[2]);
//ywybm 业务员编码 ,不传喽
//shr 审核人
parentvo.setShr(OverallConstant.getOverAllValue("u8cApiZdrCode"));
//shrq 审核日
parentvo.setShrq(format);
//scomment 备注 returnNote 客服备注 sellerNote 卖家备注
//parentvo.setScomment(header.getReturnNote());
//djlxbm 单据类型编码交易类型编码使用此字段如D0D1D2
parentvo.setDjlxbm("D0");
// //xslxbm 业务流程
parentvo.setXslxbm("JTK");//TOC仅退款:JTK TOB仅退款:BJTK
//feinvstatus 开票状态
parentvo.setFeinvstatus("0");
//zyx1店铺
parentvo.setZyx1(split[1]);
//zyx2来源平台
parentvo.setZyx2(entry.getValue().get(0).getSourcePlatformCode());
//zyx3 收发类别 销售出库写死SALES
parentvo.setZyx3("SALES");
//zyx16 单据红字标识 1Y 2N
parentvo.setZyx16("1");
//子表,需要通过多个主表的id找到多个子表,且退货金额==0的不要
List<RerturnGoodsOrderSearchDetails> ofsDetails = new ArrayList<>();
for (RerturnGoodsOrderSearchHeader rerturnGoodsOrderSearchHeader : entry.getValue()) {
allDetail.stream().forEach(index -> {
if (rerturnGoodsOrderSearchHeader.getCode().equals(index.getReturnOrderCode()) && index.getTotalAmount() != null && !"0".equals(index.getTotalAmount())) {
ofsDetails.add(index);
}
});
}
logDetails.addAll(ofsDetails);
//没有sku编码的报错
r1.clear();
for (RerturnGoodsOrderSearchDetails logDetail : logDetails) {
if(logDetail.getSkuCode()==null||"".equals(logDetail.getSkuCode())) {
IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity();
integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_N);
integrationTaskLivingDetailsEntity.setRootAppNewData(null);
integrationTaskLivingDetailsEntity.setNewTransmitInfo(logDetail.getReturnOrderCode() + ",没有SKU编码请检查OFS系统订单");
integrationTaskLivingDetailsEntity.setNewPushDate(new Date());
integrationTaskLivingDetailsEntity.setBusinessDate(format);
integrationTaskLivingDetailsEntity.setRootAppPk(logDetail.getReturnOrderCode() + "_" + logDetail.getSkuCode());
integrationTaskLivingDetailsEntity.setRootAppBill(logDetail.getReturnOrderCode());
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity);
}else {
r1.add(logDetail);
}
}
//按sku分组
Map<String, List<RerturnGoodsOrderSearchDetails>> collectSKU = r1.stream().collect(Collectors.groupingBy(index -> index.getSkuCode()));
List<ArapDjzbVO.Childrenn> children = new ArrayList<>();
Set<Map.Entry<String, List<RerturnGoodsOrderSearchDetails>>> entries = collectSKU.entrySet();
for (Map.Entry<String, List<RerturnGoodsOrderSearchDetails>> entry1 : entries) {
children.clear();
String kk = entry1.getKey();
List<RerturnGoodsOrderSearchDetails> vv = entry1.getValue();
//kk是sku编码,vv是sku相同的子表
try {
ArapDjzbVO.Childrenn childrenn = new ArapDjzbVO.Childrenn();
//cinventoryid 存货
childrenn.setCinventoryid(kk);
//sum:jfbbje jfybje 借方本币金额/借方原币金额
BigDecimal sum_jfbbje = new BigDecimal(0);
//sum:jfbbsj jfybsj 借方本币税金/借方原币税金 默认0.13
BigDecimal sum_jfbbsj = new BigDecimal(0);
//sum:wbfbbje jfybwsje 借方本币无税金额/借方原币无税金额
BigDecimal sum_wbfbbje = new BigDecimal(0);
//sum:zyx4 平台优惠 platformDiscounts
BigDecimal sum_zyx4 = new BigDecimal(0);
//sum:zyx5 支付优惠 payDiscounts
BigDecimal sum_zyx5 = new BigDecimal(0);
//sum:zyx6 达人优惠 expertDiscounts
BigDecimal sum_zyx6 = new BigDecimal(0);
//sum:zyx7 商家优惠
// BigDecimal sum_zyx7 = new BigDecimal(0);
//金额计算
for (RerturnGoodsOrderSearchDetails detail : vv) {
sum_jfbbje = sum_jfbbje.add(new BigDecimal(detail.getTotalAmount()));
BigDecimal sj = new BigDecimal(detail.getTotalAmount()).multiply(new BigDecimal(0.13)).setScale(2, RoundingMode.FLOOR);
sum_jfbbsj = sum_jfbbsj.add(sj);
BigDecimal ws = new BigDecimal(detail.getTotalAmount()).subtract(sj);
sum_wbfbbje = sum_wbfbbje.add(ws);
// if (detail.getShareTargetPlatformDiscounts() != null) {
// sum_zyx4 = sum_zyx4.add(detail.getShareTargetPlatformDiscounts());
// }
// if (detail.getShareTargetMerchantDiscounts() != null) {
// sum_zyx5 = sum_zyx5.add(detail.getShareTargetMerchantDiscounts());
// }
// if (detail.getShareTargetExpertDiscounts() != null) {
// sum_zyx6 = sum_zyx6.add(detail.getShareTargetExpertDiscounts());
// }
// if (detail.getShareTargetPayDiscounts() != null) {
// sum_zyx7 = sum_zyx7.add(detail.getShareTargetPayDiscounts());
// }
if (detail.getPlatformDiscounts() != null) {
sum_zyx4 = sum_zyx4.add(new BigDecimal(detail.getPlatformDiscounts()));
}
if (detail.getPayDiscounts() != null) {
sum_zyx5 = sum_zyx5.add(new BigDecimal(detail.getPayDiscounts()));
}
if (detail.getExpertDiscounts() != null) {
sum_zyx6 = sum_zyx6.add(new BigDecimal(detail.getExpertDiscounts()));
}
}
childrenn.setJfbbje("-" + sum_jfbbje);
childrenn.setJfybje("-" + sum_jfbbje);
childrenn.setJfbbsj("-" + sum_jfbbsj);
childrenn.setJfybsj("-" + sum_jfbbsj);
childrenn.setWbfbbje("-" + sum_wbfbbje);
childrenn.setJfybwsje("-" + sum_wbfbbje);
childrenn.setZyx4(String.valueOf(sum_zyx4));
childrenn.setZyx5(String.valueOf(sum_zyx5));
childrenn.setZyx6(String.valueOf(sum_zyx6));
children.add(childrenn);
//推送
arapDjzbVO.setParentvo(parentvo);
arapDjzbVO.setChildren(children);
mapStr = "{\"djzbvo\":[" + JSONUtil.toJsonStr(arapDjzbVO) + "]}";
//推送
ZTResult ztResult = pushU8CByApiCode.pushByCode(OverallConstant.getOverAllValue("arapYsInsertApproveCode"), mapStr);
//两层判断,一层中台转发,一层u8c返回
if ("false".equals(ztResult.getFlag())) {
//转发失败
response = JSONUtil.toJsonStr(ztResult.getAttribute());
Assert.state(false, "丽知:售后订单(ToC仅退款)--->U8C红字应收单中台转发失败,失败原因:{}", ztResult.getAttribute());
}
Attribute attribute = ztResult.getAttribute();
boolean isSuccess = false;
String djbh = "";
String vouchid = "";
if ("success".equals(attribute.getStatus())) {
isSuccess = true;
String data = attribute.getData();
ArapDjzb arapDj = resultDataHandle(data);
djbh = arapDj.getParentvo().getDjbh();
vouchid = arapDj.getParentvo().getVouchid();
}
if (!isSuccess) {
Assert.state(false, "推送U8C--> 丽知:售后订单(ToC仅退款)--->U8C红字应收单 失败 接口返回结果:{} 接口入参:{}", response, mapStr);
}
//成功
for (RerturnGoodsOrderSearchDetails ofsDetail : vv) {
IntegrationTaskLivingDetailsEntity integrationTaskLivingDetailsEntity = new IntegrationTaskLivingDetailsEntity();
integrationTaskLivingDetailsEntity.setNewState(ProfilesActiveConstant.LOG_STATUS_Y);
integrationTaskLivingDetailsEntity.setRootAppNewData(mapStr);
integrationTaskLivingDetailsEntity.setNewTransmitInfo(response);
integrationTaskLivingDetailsEntity.setNewPushDate(new Date());
integrationTaskLivingDetailsEntity.setBusinessDate(format);
integrationTaskLivingDetailsEntity.setRootAppPk(ofsDetail.getReturnOrderCode() + "_" + ofsDetail.getSkuCode());
integrationTaskLivingDetailsEntity.setRootAppBill(ofsDetail.getReturnOrderCode());//仅退款单号
integrationTaskLivingDetailsEntity.setNewSystemNumber(djbh);
integrationTaskLivingDetailsEntity.setNewSystemPrimary(vouchid);
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity);
}
} catch (Exception e) {
logger.error("推送U8C丽知售后订单(ToC仅退款)--->U8C红字应收单失败失败原因" + e);
//失败则该k下的所有子表记录失败
ReusltStrDto reusltStrDto = JSON.parseObject(response, ReusltStrDto.class);
String ErrMessage = "";
if (reusltStrDto != null) {
ErrMessage = "推送U8C丽知售后订单(ToC仅退款)--->U8C红字应收单失败失败原因" + reusltStrDto.getErrormsg();
} else {
ErrMessage = "推送U8C丽知售后订单(ToC仅退款)--->U8C红字应收单失败失败原因" + e.getMessage();
}
//失败 批量新增 ofsDetails
for (RerturnGoodsOrderSearchDetails logDetail : vv) {
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(logDetail.getReturnOrderCode() + "_" + logDetail.getSkuCode());
integrationTaskLivingDetailsEntity.setRootAppBill(logDetail.getReturnOrderCode());
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity);
}
}
}
} catch (Exception e) {
logger.error("推送U8C丽知售后订单(ToC仅退款)--->U8C红字应收单最外层失败失败原因" + e);
//失败,最外层则该k下的所有子表记录失败
ReusltStrDto reusltStrDto = JSON.parseObject(response, ReusltStrDto.class);
String ErrMessage = "";
if (reusltStrDto != null) {
ErrMessage = "推送U8C丽知售后订单(ToC仅退款)--->U8C红字应收单最外层失败失败原因" + reusltStrDto.getErrormsg();
} else {
ErrMessage = "推送U8C丽知售后订单(ToC仅退款)--->U8C红字应收单最外层失败失败原因" + e.getMessage();
}
//失败 批量新增 ofsDetails
for (RerturnGoodsOrderSearchDetails logDetail : r1) {
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(logDetail.getReturnOrderCode() + "_" + logDetail.getSkuCode());
integrationTaskLivingDetailsEntity.setRootAppBill(logDetail.getReturnOrderCode());
integrationTaskLivingDetailsEntity.setPluginId(getPluginId());
saveOrUpdateBusinessLogUtil.saveOrUpdate(integrationTaskLivingDetailsEntity);
}
}
}
}
/**
* 公司转换
* @param allHeader
*/
public void transCorp(List<RerturnGoodsOrderSearchHeader> allHeader){
if(allHeader.size()==0){
return;
}
}
/**
* 根据店铺区分tob toc业务流程
* TOC仅退款:JTK TOB仅退款:BJTK
* parentvo.setXslxbm("JTK");
* 非b及c
* @param parentvo
* @param shop
*/
@Autowired
private ShopTobOrToCUtil shopTobOrToCUtil;
public String checkFlow(ArapDjzbVO.Parentt parentvo,String shop){
String tobShop = shopTobOrToCUtil.getCommaShop("TOB");
String tocShop = shopTobOrToCUtil.getCommaShop("TOC");
System.out.println(tobShop);
System.out.println(tocShop);
if(tobShop.contains(shop)){
// parentvo.setXslxbm("BJTK");//TOB
return "TOB";
}else {
// parentvo.setXslxbm("JTK");//TOC
return "TOC";
}
}
/**
* ofs仅退款数据存中台mysql数据库
* 表头表体分别存忽略大小写 BeanUtil.copyPropreties(a,b,Copyoptions.create().ignoreCase())
*
* @param returnGoodsOrders
*/
public void save(List<RerturnGoodsOrderSearchData> returnGoodsOrders) {
// List<OnlyAfterSalesHEntity> allH=new ArrayList<>();
// List<OnlyAfterSalesBEntity> allB=new ArrayList<>();
for (RerturnGoodsOrderSearchData returnGoodsOrder : returnGoodsOrders) {
RerturnGoodsOrderSearchHeader header = returnGoodsOrder.getHeader();
OnlyAfterSalesHEntity onlyAfterSalesHEntity = new OnlyAfterSalesHEntity();
BeanUtil.copyProperties(header, onlyAfterSalesHEntity, CopyOptions.create().ignoreCase());
// allH.add(onlyAfterSalesHEntity);
onlyAfterSalesHEntity.setId(null);
onlyAfterSalesHEntity.setOfsid(header.getId());
OnlyAfterSalesHEntity save = onlyAfterSalesHDao.save(onlyAfterSalesHEntity);
String HId = save.getId();
List<RerturnGoodsOrderSearchDetails> details = returnGoodsOrder.getDetails();
for (RerturnGoodsOrderSearchDetails detail : details) {
OnlyAfterSalesBEntity onlyAfterSalesBEntity = new OnlyAfterSalesBEntity();
BeanUtil.copyProperties(detail, onlyAfterSalesBEntity, CopyOptions.create().ignoreCase());
// allB.add(onlyAfterSalesBEntity);
onlyAfterSalesBEntity.setId(null);
onlyAfterSalesBEntity.setHid(HId);
onlyAfterSalesBEntity.setOfsid(detail.getId());
//四个优惠platformDiscounts 平台优惠merchantDiscounts 商家优惠expertDiscounts 达人优惠payDiscounts 支付优惠
onlyAfterSalesBEntity.setPlatformDiscounts(header.getPlatformDiscounts());
onlyAfterSalesBEntity.setMerchantDiscounts(header.getMerchantDiscounts());
onlyAfterSalesBEntity.setExpertDiscounts(header.getExpertDiscounts());
onlyAfterSalesBEntity.setPayDiscounts(header.getPayDiscounts());
onlyAfterSalesBDao.save(onlyAfterSalesBEntity);
}
}
}
/**
* 查询OFS销售订单
*/
public SaleOrderMessageDto getOfsOrder(String code) throws Exception {
Long pageSize = 200L;
Long pageNo = 1L;
QueryOfsSoSaleOutVo queryOfsSoSaleOutVo = new QueryOfsSoSaleOutVo();
queryOfsSoSaleOutVo.setPageNo(pageNo);
queryOfsSoSaleOutVo.setPageSize(pageSize);
queryOfsSoSaleOutVo.setCode(code);
InterfaceParamDto interfaceParamDto = new InterfaceParamDto();
interfaceParamDto.setApi("ofs.salesOrder.search");
interfaceParamDto.setData(JSON.toJSONString(queryOfsSoSaleOutVo));
SaleOrderMessageDto saleOrderMessageDto = (SaleOrderMessageDto) ofsUnifiedService.unified(interfaceParamDto);
if (saleOrderMessageDto.getData().size() == 0) {
return null;
}
return saleOrderMessageDto;
}
/**
* 查询ofs仅退款订单 销售退货单查询ofs.returnOrder. search)
* <p>
* 查询条件refundedAt_startrefundedAt_endcode
* returnType:0 不退货
* exchangeType:0 不换货
* refundInd:1 退款
*/
public List<RerturnGoodsOrderSearchData> queryOfsOnlyReturnOrders(QueryReturnOrderRequestVO queryReturnOrderRequestVO) throws Exception {
Long pageNo = 1L;
List<RerturnGoodsOrderSearchData> all = new ArrayList<>();
InterfaceParamDto interfaceParamDto = new InterfaceParamDto();
interfaceParamDto.setApi("ofs.returnOrder.search");
queryReturnOrderRequestVO.setClientCode("LETS");
//100订单池 500待同步 510已同步 900售后成功 400待合单 800已入库 999作废 700收货中 0待完善
// queryReturnOrderRequestVO.setStatus("900");
queryReturnOrderRequestVO.setPageNo(pageNo);
queryReturnOrderRequestVO.setPageSize(500L);
interfaceParamDto.setData(JSON.toJSONString(queryReturnOrderRequestVO));
RerturnGoodsOrderSearchJsonRootBean rerturnGoodsOrderSearchJsonRootBean = (RerturnGoodsOrderSearchJsonRootBean) ofsUnifiedService.unified(interfaceParamDto);
if (rerturnGoodsOrderSearchJsonRootBean.getData() == null || rerturnGoodsOrderSearchJsonRootBean.getData().size() == 0) {
return null;
}
all.addAll(rerturnGoodsOrderSearchJsonRootBean.getData());
int count = rerturnGoodsOrderSearchJsonRootBean.getData().size();
while (count >= 500) {//>=500,可能还有下一页
//还有下一页
pageNo++;
queryReturnOrderRequestVO.setPageNo(pageNo);
interfaceParamDto.setData(JSON.toJSONString(queryReturnOrderRequestVO));
RerturnGoodsOrderSearchJsonRootBean rerturnGoodsOrderSearchJsonRootBean1 = (RerturnGoodsOrderSearchJsonRootBean) ofsUnifiedService.unified(interfaceParamDto);
all.addAll(rerturnGoodsOrderSearchJsonRootBean1.getData());
count = rerturnGoodsOrderSearchJsonRootBean1.getData().size();
}
return all;
}
private ArapDjzb resultDataHandle(String resultData) {
try {
if (resultData != null && !"".equals(resultData)) {
if (resultData.contains("[")) {
resultData = resultData.substring(1, resultData.length() - 1);
}
return JSON.parseObject(resultData, ArapDjzb.class);
}
} catch (Exception e) {
e.printStackTrace();
logger.error("解析返回参数失败的错误", e);
//如果解析失败记录原因但是不能影响结果的记录
}
return null;
}
}