Commit 48ec7fb5 by huluobin

# 周转匹配平台规则

parent 85ce7b89
...@@ -153,5 +153,6 @@ public interface DcBaseOmsSkuMapper { ...@@ -153,5 +153,6 @@ public interface DcBaseOmsSkuMapper {
@Param("upperTime") LocalDateTime upperTime, @Param("upperTime") LocalDateTime upperTime,
@Param("bailunSku") String bailunSku, @Param("bailunSku") String bailunSku,
@Param("warehouseCode") String warehouseCode, @Param("warehouseCode") String warehouseCode,
@Param("days") Integer days); @Param("days") Integer days,
@Param("platform") String platform);
} }
...@@ -3759,6 +3759,9 @@ ...@@ -3759,6 +3759,9 @@
and t1.has_platsku_remark = 0 and t1.has_platsku_remark = 0
and t1.has_innersale = 0 and t1.has_innersale = 0
and t1.bailun_order_status != 'Canceled' and t1.bailun_order_status != 'Canceled'
<if test="platform!=null and platform !=''">
and t1.platform_type = #{platform}
</if>
and t1.platform_order_type != '手工单' and t1.platform_order_type != '手工单'
GROUP BY DATE_FORMAT(paid_time, '%y%m%d')) tt1 on tt1.paid_date = tt2.date_str) GROUP BY DATE_FORMAT(paid_time, '%y%m%d')) tt1 on tt1.paid_date = tt2.date_str)
where tt2.bailun_sku =#{bailunSku} where tt2.bailun_sku =#{bailunSku}
...@@ -3786,6 +3789,9 @@ ...@@ -3786,6 +3789,9 @@
and t1.has_innersale = 0 and t1.has_innersale = 0
and t1.bailun_order_status != 'Canceled' and t1.bailun_order_status != 'Canceled'
and t1.platform_order_type != '手工单' and t1.platform_order_type != '手工单'
<if test="platform!=null and platform !=''">
and t1.platform_type = #{platform}
</if>
GROUP BY DATE_FORMAT(paid_time, '%y%m%d')) tt1 on tt1.paid_date = tt2.date_str)) GROUP BY DATE_FORMAT(paid_time, '%y%m%d')) tt1 on tt1.paid_date = tt2.date_str))
/ #{days} / #{days}
- -
...@@ -3808,6 +3814,9 @@ ...@@ -3808,6 +3814,9 @@
and t1.has_innersale = 0 and t1.has_innersale = 0
and t1.bailun_order_status != 'Canceled' and t1.bailun_order_status != 'Canceled'
and t1.platform_order_type != '手工单' and t1.platform_order_type != '手工单'
<if test="platform!=null and platform !=''">
and t1.platform_type = #{platform}
</if>
GROUP BY DATE_FORMAT(paid_time, '%y%m%d')) tt1 on tt1.paid_date = tt2.date_str) GROUP BY DATE_FORMAT(paid_time, '%y%m%d')) tt1 on tt1.paid_date = tt2.date_str)
where tt2.bailun_sku =#{bailunSku} where tt2.bailun_sku =#{bailunSku}
and tt2.warehouse_code = #{warehouseCode} and tt2.warehouse_code = #{warehouseCode}
......
...@@ -4,206 +4,29 @@ import com.alibaba.fastjson.JSON; ...@@ -4,206 +4,29 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.bailuntec.domain.constant.CommonConstant; import com.bailuntec.domain.constant.CommonConstant;
import com.bailuntec.domain.entity.DcBaseSku;
import com.bailuntec.domain.entity.DcExchangeRate; import com.bailuntec.domain.entity.DcExchangeRate;
import com.bailuntec.domain.enumerate.PlatformType;
import com.bailuntec.domain.example.DcExchangeRateExample; import com.bailuntec.domain.example.DcExchangeRateExample;
import com.bailuntec.domain.pojo.*; import com.bailuntec.domain.pojo.AccountNoToken;
import com.bailuntec.mapper.DcExchangeRateMapper; import com.bailuntec.mapper.DcExchangeRateMapper;
import com.bailuntec.utils.DigestUtils;
import com.bailuntec.utils.OkHttpUtil; import com.bailuntec.utils.OkHttpUtil;
import com.bailuntec.utils.SessionUtil; import com.bailuntec.utils.SessionUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.*; import okhttp3.OkHttpClient;
import org.apache.commons.beanutils.BeanUtils; import okhttp3.Request;
import org.apache.commons.lang3.StringUtils; import okhttp3.Response;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@Slf4j @Slf4j
public class CallBailunSystem { public class CallBailunSystem {
/** /**
* 拿SKU映射
*/
public static DcBaseSku getSkuInfo(String skus) {
//SKUMS接口需要的请求参数
CommonSkuCondition commonSkuConditionDto = new CommonSkuCondition();
commonSkuConditionDto.setResultType(2);//分页
commonSkuConditionDto.setStatus(-1);
commonSkuConditionDto.setIsFinish(-1);
commonSkuConditionDto.setPage(1);
commonSkuConditionDto.setPageSize(1);
//有ResultWare返回发货仓库信息
// commonSkuConditionDto.setIsResultWare(1);
//有SKU只查提供的SKU
commonSkuConditionDto.setSkus(skus);
OkHttpClient client = OkHttpUtil.getInstance();
SkuData skuDataDto = new SkuData();
skuDataDto.setCode(CommonConstant.OBJPRO_CODE);
skuDataDto.setKey(CommonConstant.ALL_OBJPRO_KEY);
String data = null;
try {
skuDataDto.setData(URLEncoder.encode(JSON.toJSONString(commonSkuConditionDto), "utf8"));//将请求参数转为JSON 再Url编码
data = URLEncoder.encode(JSON.toJSONString(skuDataDto), "utf8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException("同步SKU信息JSON解析失败", e);
}
//第一次MD5加密
String str = DigestUtils.md5DigestAsHex((CommonConstant.ALL_OBJPRO_KEY + skuDataDto.getData()).getBytes());
//第二次MD5加密
String sign = DigestUtils.md5DigestAsHex((CommonConstant.SKU_APPKEY + CommonConstant.OBJPRO_CODE + str).getBytes());
//真正请求的参数
LinkedHashMap<String, String> map = new LinkedHashMap<>(3);
map.put("data", data);
map.put("appId", CommonConstant.SKU_APPID);
map.put("sign", sign);
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(map));
Response response = null;
String skuStr = null;
try {
Request request = new Request.Builder()
.url(CommonConstant.SKU_URL)
.post(body)
.addHeader("Content-Type", "application/json")
.build();
response = client.newCall(request).execute();
skuStr = response.body().string();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("调用同步SKU信息接口失败", e);
} finally {
if (response != null) {
response.close();
}
}
if (StringUtils.isNotBlank(skuStr)) {
JSONObject jsonNode = JSON.parseObject(skuStr);
Integer resultCode = jsonNode.getIntValue("result_code");
if (resultCode != null && resultCode == 1) {
String resultUrlSku = jsonNode.getString("data");
JSONObject jsonObject1 = null;
try {
jsonObject1 = JSON.parseObject(URLDecoder.decode(resultUrlSku, "utf8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("同步SKU信息JSON解URL编码失败", e);
}
List<CommonSkuProductInfo> commonSkuProductInfoList = jsonObject1.getObject("Items", new TypeReference<List<CommonSkuProductInfo>>() {
});
if (commonSkuProductInfoList != null && commonSkuProductInfoList.size() > 0) {
for (CommonSkuProductInfo skuProductInfo : commonSkuProductInfoList) {
DcBaseSku dcBaseSku = new DcBaseSku();
try {
BeanUtils.copyProperties(dcBaseSku, skuProductInfo);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException();
}
String[] split = null;
if (skuProductInfo.getPackingSize() != null) {
split = skuProductInfo.getPackingSize().split(",");
}
dcBaseSku.setBussinessId(dcBaseSku.getSellerId());
dcBaseSku.setBussinessName(dcBaseSku.getSellerName());
dcBaseSku.setLength((split != null && split.length > 0 && CommonConstant.NUMBER_AND_DECIMAL.matcher(split[0]).matches()) ? new BigDecimal(split[0]) : BigDecimal.ZERO);
dcBaseSku.setWidth((split != null && split.length > 1 && CommonConstant.NUMBER_AND_DECIMAL.matcher(split[1]).matches()) ? new BigDecimal(split[1]) : BigDecimal.ZERO);
dcBaseSku.setHeight((split != null && split.length > 2 && CommonConstant.NUMBER_AND_DECIMAL.matcher(split[2]).matches()) ? new BigDecimal(split[2]) : BigDecimal.ZERO);
dcBaseSku.setWeight(skuProductInfo.getWeight() != null ? skuProductInfo.getWeight() : BigDecimal.ZERO.add(skuProductInfo.getPackingWeight() != null ? skuProductInfo.getPackingWeight() : BigDecimal.ZERO));
dcBaseSku.setGmtModified(LocalDateTime.now());
return dcBaseSku;
}
}
}
}
return null;
}
/**
* 拿SKU映射
*/
public static BigDecimal skuMapping() {
//SKUMS接口需要的请求参数
SkuMappingCondition skuConditionDto = new SkuMappingCondition();
skuConditionDto.setResultType(3);
skuConditionDto.setPlat(PlatformType.Amazon.value());
skuConditionDto.setPlatSku("UK-FBA-N-8ML-G2-C008,UK-FBA-N-8ML-G2-C018,F4-ARM6-YNMU");
OkHttpClient client = OkHttpUtil.getInstance();
SkuData skuDataDto = new SkuData();
skuDataDto.setCode(CommonConstant.OBJPRO_CODE);
skuDataDto.setKey(CommonConstant.MAP_OBJPRO_KEY);
String data = null;
try {
skuDataDto.setData(URLEncoder.encode(JSON.toJSONString(skuConditionDto), "utf8"));//将请求参数转为JSON 再Url编码
data = URLEncoder.encode(JSON.toJSONString(skuDataDto), "utf8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new RuntimeException("取SKU映射参数编码失败", e);
}
//第一次MD5加密
String str = DigestUtils.md5DigestAsHex((CommonConstant.MAP_OBJPRO_KEY + skuDataDto.getData()).getBytes());
//第二次MD5加密
String sign = DigestUtils.md5DigestAsHex((CommonConstant.SKU_APPKEY + CommonConstant.OBJPRO_CODE + str).getBytes());
//真正请求的参数
JSONObject jsonObject = new JSONObject();
jsonObject.put("sign", sign);
jsonObject.put("appId", CommonConstant.SKU_APPID);
jsonObject.put("data", data);
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, jsonObject.toString());
Request request = new Request.Builder()
.url(CommonConstant.SKUMAPPING_URL)
.post(body)
.addHeader("Content-Type", "application/json")
.build();
Response response = null;
try {
response = client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
if (response != null && response.isSuccessful()) {
JSONObject jsonNode = null;
try {
jsonNode = JSON.parseObject(response.body().string());
} catch (IOException e) {
throw new RuntimeException("同步SKU信息JSON解析失败", e);
} finally {
if (response != null) {
response.close();
}
}
Integer resultCode = jsonNode.getIntValue("result_code");
if (resultCode != null && resultCode == 1) {
String resultUrlSku = jsonNode.getString("data");
List<SkuMappingInfo> skuMappingInfoList = null;
try {
skuMappingInfoList = JSON.parseObject(URLDecoder.decode(resultUrlSku, "utf8"), new TypeReference<List<SkuMappingInfo>>() {
});
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("同步SKU信息JSON解URL编码失败", e);
}
if (skuMappingInfoList != null && skuMappingInfoList.size() > 0) {
System.out.println("...");
}
}
}
return null;
}
/**
* 获取每月月初的汇率 * 获取每月月初的汇率
* *
* @param fromCurrency * @param fromCurrency
...@@ -269,7 +92,7 @@ public class CallBailunSystem { ...@@ -269,7 +92,7 @@ public class CallBailunSystem {
.build(); .build();
responseEntity = client.newCall(request).execute(); responseEntity = client.newCall(request).execute();
exchangeRate = null; exchangeRate = null;
if (responseEntity != null && responseEntity.isSuccessful()) { if (responseEntity.isSuccessful()) {
JSONObject jsonObject = JSON.parseObject(responseEntity.body().string()); JSONObject jsonObject = JSON.parseObject(responseEntity.body().string());
exchangeRate = (BigDecimal) jsonObject.get("rate"); exchangeRate = (BigDecimal) jsonObject.get("rate");
dcExchangeRate = new DcExchangeRate(); dcExchangeRate = new DcExchangeRate();
...@@ -330,64 +153,4 @@ public class CallBailunSystem { ...@@ -330,64 +153,4 @@ public class CallBailunSystem {
return null; return null;
} }
/**
* 返回百伦估算的头程费信息
*
* @return
*/
public static BigDecimal callCostFirstFee(String countryCode, BigDecimal length, BigDecimal width, BigDecimal hight, BigDecimal weight, String lineCode) {
HashMap<String, String> map = new HashMap<>();
map.put("endCountries", countryCode);
map.put("Long", length.toString());
map.put("width", width.toString());
map.put("high", hight.toString());
map.put("WeightKg", weight.toString());
map.put("electrifiedType", "0");
map.put("LineCodes", lineCode);
Response response = null;
String resultStr = null;
OkHttpClient client = OkHttpUtil.getInstance();
try {
Request request = new Request.Builder()
.url(OkHttpUtil.attachHttpGetParams(CommonConstant.FIRST_FEE_URL, map))
.get()
.build();
response = client.newCall(request).execute();
resultStr = response.body().string();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("调用百伦头程费接口失败" + map, e);
} finally {
if (response != null) {
response.close();
}
}
BigDecimal minLogistics = BigDecimal.ZERO;
if (response != null && response.isSuccessful()) {
JSONObject jsonObject = JSON.parseObject(resultStr);
if (jsonObject.get("Data") != null) {
List<CostFirstModels> costFirstModelsList = jsonObject.getObject("Data", new TypeReference<List<CostFirstModels>>() {
});
// 取最低的头程费
if (costFirstModelsList != null && costFirstModelsList.size() > 0) {
BigDecimal min = costFirstModelsList.get(0).getPrice();
for (int j = 0; j < costFirstModelsList.size(); j++) {
if (min.compareTo(costFirstModelsList.get(j).getPrice()) == 1)
min = costFirstModelsList.get(j).getPrice();
}
minLogistics = min;
}
}
return minLogistics;
} else {
throw new RuntimeException("调用百伦LMS系统接口失败" + map);
}
}
/**
* 拿百伦账号信息
*
* @param bailunAccountId
* @return
*/
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<configuration> <configuration>
<!--<properties resource="db-tj.properties"/>--> <!--<properties resource="db-tj.properties"/>-->
<!-- <properties resource="db-dev.properties"/>--> <!-- <properties resource="db-dev.properties"/>-->
<properties resource="db-prod.properties"/> <properties resource="db-prod.properties"/>
<settings> <settings>
<setting name="mapUnderscoreToCamelCase" value="true"/> <setting name="mapUnderscoreToCamelCase" value="true"/>
......
...@@ -30,9 +30,6 @@ import java.util.*; ...@@ -30,9 +30,6 @@ import java.util.*;
@Slf4j @Slf4j
public class AutoTurnoverServiceImpl implements AutoTurnoverService { public class AutoTurnoverServiceImpl implements AutoTurnoverService {
private BigDecimal omsSkuSellerCount(String bailunSku, String wareshouseCode) {
return BigDecimal.ZERO;
}
@Override @Override
public List<BigDecimal> getAutoTurnoverSaleDetails(DcAutoTurnover dcAutoTurnover, int turnoverDays, int autoForecastDay) { public List<BigDecimal> getAutoTurnoverSaleDetails(DcAutoTurnover dcAutoTurnover, int turnoverDays, int autoForecastDay) {
...@@ -95,11 +92,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -95,11 +92,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
int threeN5 = dcAutoSalesForecastStageConfig.getThreeN5().intValue(); int threeN5 = dcAutoSalesForecastStageConfig.getThreeN5().intValue();
/*第一部分预测*/ /*第一部分预测*/
BigDecimal duration1ForecastSellerNum = Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN1().intValue()), midNight, bailunSku, warehouseCode, oneN1 == 0 ? 1 : oneN1)).orElse(BigDecimal.ZERO) BigDecimal duration1ForecastSellerNum = Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN1().intValue()), midNight, bailunSku, warehouseCode, oneN1 == 0 ? 1 : oneN1, dcAutoSalesForecastConfig.getDataSourcePlatform())).orElse(BigDecimal.ZERO)
.multiply(dcAutoSalesForecastStageConfig.getOneN2()) .multiply(dcAutoSalesForecastStageConfig.getOneN2())
.add(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN3().intValue()), midNight, bailunSku, warehouseCode, oneN3 == 0 ? 1 : oneN3)).orElse(BigDecimal.ZERO) .add(Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN3().intValue()), midNight, bailunSku, warehouseCode, oneN3 == 0 ? 1 : oneN3, dcAutoSalesForecastConfig.getDataSourcePlatform())).orElse(BigDecimal.ZERO)
.multiply(dcAutoSalesForecastStageConfig.getOneN4())) .multiply(dcAutoSalesForecastStageConfig.getOneN4()))
.add(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN5().intValue()), midNight, bailunSku, warehouseCode, oneN5 == 0 ? 1 : oneN5) .add(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN5().intValue()), midNight, bailunSku, warehouseCode, oneN5 == 0 ? 1 : oneN5, dcAutoSalesForecastConfig.getDataSourcePlatform())
.multiply(dcAutoSalesForecastStageConfig.getOneN6())); .multiply(dcAutoSalesForecastStageConfig.getOneN6()));
for (int i = 0; i < duration1; i++) { for (int i = 0; i < duration1; i++) {
...@@ -109,11 +106,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -109,11 +106,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
} }
/*第二部分预测*/ /*第二部分预测*/
BigDecimal duration2ForecastSellerNum = dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN1().intValue()), midNight, bailunSku, warehouseCode, twoN1 == 0 ? 1 : twoN1) BigDecimal duration2ForecastSellerNum = dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN1().intValue()), midNight, bailunSku, warehouseCode, twoN1 == 0 ? 1 : twoN1, dcAutoSalesForecastConfig.getDataSourcePlatform())
.multiply(dcAutoSalesForecastStageConfig.getTwoN2()) .multiply(dcAutoSalesForecastStageConfig.getTwoN2())
.add(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN3().intValue()), midNight, bailunSku, warehouseCode, twoN3 == 0 ? 1 : twoN3) .add(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN3().intValue()), midNight, bailunSku, warehouseCode, twoN3 == 0 ? 1 : twoN3, dcAutoSalesForecastConfig.getDataSourcePlatform())
.multiply(dcAutoSalesForecastStageConfig.getTwoN4())) .multiply(dcAutoSalesForecastStageConfig.getTwoN4()))
.add(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN5().intValue()), midNight, bailunSku, warehouseCode, twoN5 == 0 ? 1 : twoN5) .add(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN5().intValue()), midNight, bailunSku, warehouseCode, twoN5 == 0 ? 1 : twoN5, dcAutoSalesForecastConfig.getDataSourcePlatform())
.multiply(dcAutoSalesForecastStageConfig.getTwoN6())); .multiply(dcAutoSalesForecastStageConfig.getTwoN6()));
for (int i = 0; i < duration2; i++) { for (int i = 0; i < duration2; i++) {
...@@ -124,11 +121,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -124,11 +121,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
/*第三部分预测*/ /*第三部分预测*/
BigDecimal duration3ForecastSellerNum = dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN1().intValue()), midNight, bailunSku, warehouseCode, threeN1 == 0 ? 1 : threeN1) BigDecimal duration3ForecastSellerNum = dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN1().intValue()), midNight, bailunSku, warehouseCode, threeN1 == 0 ? 1 : threeN1, dcAutoSalesForecastConfig.getDataSourcePlatform())
.multiply(dcAutoSalesForecastStageConfig.getThreeN2()) .multiply(dcAutoSalesForecastStageConfig.getThreeN2())
.add(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN3().intValue()), midNight, bailunSku, warehouseCode, threeN3 == 0 ? 1 : threeN3) .add(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN3().intValue()), midNight, bailunSku, warehouseCode, threeN3 == 0 ? 1 : threeN3, dcAutoSalesForecastConfig.getDataSourcePlatform())
.multiply(dcAutoSalesForecastStageConfig.getThreeN4())) .multiply(dcAutoSalesForecastStageConfig.getThreeN4()))
.add(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN5().intValue()), midNight, bailunSku, warehouseCode, threeN5 == 0 ? 1 : threeN5)) .add(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN5().intValue()), midNight, bailunSku, warehouseCode, threeN5 == 0 ? 1 : threeN5, dcAutoSalesForecastConfig.getDataSourcePlatform()))
.multiply(dcAutoSalesForecastStageConfig.getThreeN6()); .multiply(dcAutoSalesForecastStageConfig.getThreeN6());
for (int i = 0; i < duration3; i++) { for (int i = 0; i < duration3; i++) {
...@@ -169,6 +166,7 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -169,6 +166,7 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
DcAutoSalesForecastStageConfigMapper dcAutoSalesForecastStageConfigMapper = session.getMapper(DcAutoSalesForecastStageConfigMapper.class); DcAutoSalesForecastStageConfigMapper dcAutoSalesForecastStageConfigMapper = session.getMapper(DcAutoSalesForecastStageConfigMapper.class);
DcBaseOmsSkuMapper dcBaseOmsSkuMapper = session.getMapper(DcBaseOmsSkuMapper.class); DcBaseOmsSkuMapper dcBaseOmsSkuMapper = session.getMapper(DcBaseOmsSkuMapper.class);
DcAutoSalesForecastConfigMapper dcAutoSalesForecastConfigMapper = session.getMapper(DcAutoSalesForecastConfigMapper.class);
DcBaseOmsSku orderFirstCreateTime = dcAutoSalesForecastStageConfigMapper.firsOrder(dcAutoTurnover.getBailunSku(), dcAutoTurnover.getWarehouseCode()); DcBaseOmsSku orderFirstCreateTime = dcAutoSalesForecastStageConfigMapper.firsOrder(dcAutoTurnover.getBailunSku(), dcAutoTurnover.getWarehouseCode());
Integer day = Optional.ofNullable(orderFirstCreateTime).map(var -> Period.between(var.getCreateTime().toLocalDate(), LocalDateTime.now().toLocalDate()).getDays()).orElse(null); Integer day = Optional.ofNullable(orderFirstCreateTime).map(var -> Period.between(var.getCreateTime().toLocalDate(), LocalDateTime.now().toLocalDate()).getDays()).orElse(null);
...@@ -187,6 +185,7 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -187,6 +185,7 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
if (dcAutoSalesForecastStageConfig != null) { if (dcAutoSalesForecastStageConfig != null) {
log.info("匹配到一条规则 id:{}", dcAutoSalesForecastStageConfig.getConfigId()); log.info("匹配到一条规则 id:{}", dcAutoSalesForecastStageConfig.getConfigId());
DcAutoSalesForecastConfig dcAutoSalesForecastConfig = dcAutoSalesForecastConfigMapper.selectById(dcAutoSalesForecastStageConfig.getConfigId());
int duration1 = BigDecimal.valueOf(turnoverDays).multiply(dcAutoSalesForecastStageConfig.getOneRatio()).intValue(); int duration1 = BigDecimal.valueOf(turnoverDays).multiply(dcAutoSalesForecastStageConfig.getOneRatio()).intValue();
int duration2 = BigDecimal.valueOf(turnoverDays).multiply(dcAutoSalesForecastStageConfig.getTwoRatio()).intValue(); int duration2 = BigDecimal.valueOf(turnoverDays).multiply(dcAutoSalesForecastStageConfig.getTwoRatio()).intValue();
...@@ -206,11 +205,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -206,11 +205,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
for (int i = 0; i < duration1; i++) { for (int i = 0; i < duration1; i++) {
if (autoForecastDay >= forecastSalesDetailsFormula.size()) { if (autoForecastDay >= forecastSalesDetailsFormula.size()) {
forecastSalesDetailsFormula.offer("(" + dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN1().intValue()), midNight, bailunSku, warehouseCode, oneN1 == 0 ? 1 : oneN1).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getOneN2() + ")" forecastSalesDetailsFormula.offer("(" + dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN1().intValue()), midNight, bailunSku, warehouseCode, oneN1 == 0 ? 1 : oneN1, dcAutoSalesForecastConfig.getDataSourcePlatform()).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getOneN2() + ")"
+ "+" + "+"
+ "(" + Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN3().intValue()), midNight, bailunSku, warehouseCode, oneN3 == 0 ? 1 : oneN3)).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getOneN4() + ")" + "(" + Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN3().intValue()), midNight, bailunSku, warehouseCode, oneN3 == 0 ? 1 : oneN3, dcAutoSalesForecastConfig.getDataSourcePlatform())).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getOneN4() + ")"
+ "+" + "+"
+ "(" + Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN5().intValue()), midNight, bailunSku, warehouseCode, oneN5 == 0 ? 1 : oneN5)).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getOneN6() + ")"); + "(" + Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getOneN5().intValue()), midNight, bailunSku, warehouseCode, oneN5 == 0 ? 1 : oneN5, dcAutoSalesForecastConfig.getDataSourcePlatform())).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getOneN6() + ")");
} }
} }
...@@ -218,11 +217,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -218,11 +217,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
for (int i = 0; i < duration2; i++) { for (int i = 0; i < duration2; i++) {
if (autoForecastDay >= forecastSalesDetailsFormula.size()) { if (autoForecastDay >= forecastSalesDetailsFormula.size()) {
forecastSalesDetailsFormula.offer("(" + dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN1().intValue()), midNight, bailunSku, warehouseCode, twoN1 == 0 ? 1 : twoN1).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getTwoN2() + ")" forecastSalesDetailsFormula.offer("(" + dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN1().intValue()), midNight, bailunSku, warehouseCode, twoN1 == 0 ? 1 : twoN1, dcAutoSalesForecastConfig.getDataSourcePlatform()).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getTwoN2() + ")"
+ "+" + "+"
+ "(" + Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN3().intValue()), midNight, bailunSku, warehouseCode, twoN3 == 0 ? 1 : twoN3)).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getTwoN4() + ")" + "(" + Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN3().intValue()), midNight, bailunSku, warehouseCode, twoN3 == 0 ? 1 : twoN3, dcAutoSalesForecastConfig.getDataSourcePlatform())).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getTwoN4() + ")"
+ "+" + "+"
+ "(" + Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN5().intValue()), midNight, bailunSku, warehouseCode, twoN5 == 0 ? 1 : twoN5)).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getTwoN6() + ")"); + "(" + Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getTwoN5().intValue()), midNight, bailunSku, warehouseCode, twoN5 == 0 ? 1 : twoN5, dcAutoSalesForecastConfig.getDataSourcePlatform())).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getTwoN6() + ")");
} }
} }
...@@ -231,11 +230,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService { ...@@ -231,11 +230,11 @@ public class AutoTurnoverServiceImpl implements AutoTurnoverService {
for (int i = 0; i < duration3; i++) { for (int i = 0; i < duration3; i++) {
if (autoForecastDay >= forecastSalesDetailsFormula.size()) { if (autoForecastDay >= forecastSalesDetailsFormula.size()) {
forecastSalesDetailsFormula.offer("(" + dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN1().intValue()), midNight, bailunSku, warehouseCode, threeN1 == 0 ? 1 : threeN1).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getThreeN2() + ")" forecastSalesDetailsFormula.offer("(" + dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN1().intValue()), midNight, bailunSku, warehouseCode, threeN1 == 0 ? 1 : threeN1, dcAutoSalesForecastConfig.getDataSourcePlatform()).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getThreeN2() + ")"
+ "+" + "+"
+ "(" + Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN3().intValue()), midNight, bailunSku, warehouseCode, threeN3 == 0 ? 1 : threeN3)).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getThreeN4() + ")" + "(" + Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN3().intValue()), midNight, bailunSku, warehouseCode, threeN3 == 0 ? 1 : threeN3, dcAutoSalesForecastConfig.getDataSourcePlatform())).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getThreeN4() + ")"
+ "+" + "+"
+ "(" + Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN5().intValue()), midNight, bailunSku, warehouseCode, threeN5 == 0 ? 1 : threeN5)).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getThreeN6() + ")"); + "(" + Optional.ofNullable(dcBaseOmsSkuMapper.omsSkuSellerCount(midNight.minusDays(dcAutoSalesForecastStageConfig.getThreeN5().intValue()), midNight, bailunSku, warehouseCode, threeN5 == 0 ? 1 : threeN5, dcAutoSalesForecastConfig.getDataSourcePlatform())).orElse(BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP) + "*" + dcAutoSalesForecastStageConfig.getThreeN6() + ")");
} }
} }
......
...@@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test; ...@@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test;
import org.junit.platform.commons.util.StringUtils; import org.junit.platform.commons.util.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDate; import java.time.LocalDate;
...@@ -251,16 +252,16 @@ public class AutoTurnoverTest { ...@@ -251,16 +252,16 @@ public class AutoTurnoverTest {
} }
//LM-EO-007,MMDUSFBA
//LM-EO-007,MMDUSFBA
@Transactional
@Test @Test
public void testXX2() { public void testXX2() {
DcBaseStock dcBaseStock = SessionUtil.getSession().getMapper(DcBaseStockMapper.class) DcBaseStock dcBaseStock = SessionUtil.getSession().getMapper(DcBaseStockMapper.class)
.selectOneByExample(DcBaseStockExample.newAndCreateCriteria() .selectOneByExample(DcBaseStockExample.newAndCreateCriteria()
.andBailunSkuEqualTo("950643503") .andBailunSkuEqualTo("944579124")
.andWarehouseCodeEqualTo("GZBLWH") .andWarehouseCodeEqualTo("GZBLWH")
.example()); .example());
try { try {
AutoTurnoverJob autoTurnoverJob = new AutoTurnoverJob(); AutoTurnoverJob autoTurnoverJob = new AutoTurnoverJob();
autoTurnoverJob.autoTurnoverFromStock(DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT).format(LocalDate.now()), dcBaseStock); autoTurnoverJob.autoTurnoverFromStock(DateTimeFormatter.ofPattern(CommonConstant.DATE_FORMAT).format(LocalDate.now()), dcBaseStock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment