Commit 98741085 authored by Allen Chen's avatar Allen Chen

commit

parent a6c1253b
......@@ -134,48 +134,53 @@ public class PddOpenController {
PddServiceConsoFeeQueryRequest queryRequest = JSON.parseObject(body, PddServiceConsoFeeQueryRequest.class);
FeeQuery(queryRequest);
log.info("pdd.service.conso.fee.query 集运费用查询");
List<PddServiceConsoFeeQueryRequest.MailDetail> list = queryRequest.getMailDetails();
int freightFee = 0;
long freightFee = 0L;
int rentFee = 0;
int weight = 0;
log.info("订单数量 = {}", list.size());
LogOrderEntity logOrderEntity = null;
LogOrderMailDetailEntity mailDetailEntity = null;
for (PddServiceConsoFeeQueryRequest.MailDetail mailDetail : list) {
mailDetailEntity = orderMailDetailImpl.getByMailNo(mailDetail.getMailNo());
if (logOrderEntity == null) {
logOrderEntity = orderImpl.getByOrderCode(mailDetailEntity.getLogisticsOrderCode());
List<String> orderCodes = queryRequest.getLogisticsOrderCodes();
for (String orderCode : orderCodes) {
LogOrderEntity logOrderEntity = orderImpl.getByOrderCode(orderCode);
if (logOrderEntity.getStatus() >= 50) {
// 已合包
// 每个计算重量,每个计算运费
List<LogOrderMailDetailEntity> mailDetailEntityList = orderMailDetailImpl.getListByCode(orderCode);
for (LogOrderMailDetailEntity mailDetailEntity : mailDetailEntityList) {
int currWeight = PddJYPriceTool.calculateWeight(mailDetailEntity.getLength(),
mailDetailEntity.getWidth(),
mailDetailEntity.getHeight(),
mailDetailEntity.getWeight(),
"SENDTORECEVER".equals(queryRequest.getSegmentCode()));
freightFee = PddJYPriceTool.calculateFreightFee(currWeight,
queryRequest.getGoodsType(),
1,
"SENDTORECEVER".equals(queryRequest.getSegmentCode())
);
weight += currWeight;
}
} else {
// 不合包
// 按照所有包裹计算重量,计算运费
List<LogOrderMailDetailEntity> mailDetailEntityList = orderMailDetailImpl.getListByCode(orderCode);
for (LogOrderMailDetailEntity mailDetailEntity : mailDetailEntityList) {
weight += PddJYPriceTool.calculateWeight(mailDetailEntity.getLength(),
mailDetailEntity.getWidth(),
mailDetailEntity.getHeight(),
mailDetailEntity.getWeight(),
"SENDTORECEVER".equals(queryRequest.getSegmentCode()));
}
freightFee = PddJYPriceTool.calculateFreightFee(weight,
queryRequest.getGoodsType(),
1,
"SENDTORECEVER".equals(queryRequest.getSegmentCode())
);
}
PddJYPriceTool.FeeResult result = PddJYPriceTool.getTotalFee(queryRequest.getGoodsType(),
mailDetailEntity.getLength(),
mailDetailEntity.getWidth(),
mailDetailEntity.getHeight(),
mailDetailEntity.getWeight(),
"SENDTORECEVER".equals(queryRequest.getSegmentCode()),
mailDetailEntity.getEnterTime()
);
if (result == null) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("success", false);
jsonObject.put("code", 11);
jsonObject.put("message", "包裹" + mailDetail.getMailNo() + "费用查询失败");
return jsonObject;
}
freightFee += result.getFreightFee();
rentFee += result.getRentFee();
weight += result.getWeight();
}
if (logOrderEntity.getStatus() < 50) {
PddJYPriceTool.FeeResult result = PddJYPriceTool.getTotalFee(queryRequest.getGoodsType(),
mailDetailEntity.getLength(),
mailDetailEntity.getWidth(),
mailDetailEntity.getHeight(),
weight,
"SENDTORECEVER".equals(queryRequest.getSegmentCode()),
mailDetailEntity.getEnterTime()
);
freightFee = result.getFreightFee();
// 拆包之前的租金
for (PddServiceConsoFeeQueryRequest.MailDetail mailDetail : queryRequest.getMailDetails()) {
LogOrderMailDetailEntity mailDetailEntity = orderMailDetailImpl.getByMailNo(mailDetail.getMailNo());
rentFee += PddJYPriceTool.calculateRent(mailDetailEntity.getEnterTime(), "SENDTORECEVER".equals(queryRequest.getSegmentCode()));
}
JSONObject jsonObject = new JSONObject();
......@@ -233,7 +238,7 @@ public class PddOpenController {
UserIdentify(identifyRequest);
log.info("pdd.service.conso.user.identify");
IdentityErrorType errorType = WorldexUtil.verifyIdentity(identifyRequest.getName(), identifyRequest.getMobileNo(), identifyRequest.getIdNumber());
if(!errorType.equals(IdentityErrorType.Correct)) {
if (!errorType.equals(IdentityErrorType.Correct)) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("success", false);
jsonObject.put("code", errorType.getValue());
......
......@@ -23,6 +23,8 @@ public interface LogOrderMailDetailMapper extends BaseMapper<LogOrderMailDetailE
@Select("SELECT * FROM `log_order_mail_detail` WHERE `mailNo` = #{mailNo} AND `state` > 0;")
LogOrderMailDetailEntity findByMailNo(String mailNo);
@Select("SELECT * FROM `log_order_package` WHERE `logisticsOrderCode` = #{logisticsOrderCode} AND `state` > 0;")
List<LogOrderMailDetailEntity> getNewPackListByCode(String logisticsOrderCode);
@Select("SELECT count(t.uid) FROM ( SELECT a.uid FROM `log_order_mail_detail` a WHERE `logisticsOrderCode` LIKE '%${logisticsOrderCode}%' AND `mailNo` LIKE '%${mailNo}%' AND `status` LIKE '%${status}%' AND `state` > 0 ) t")
Integer countUsable(LogOrderMailDetailListRequest param);
......
......@@ -31,6 +31,10 @@ public class LogOrderMailDetailImpl extends ServiceImpl<LogOrderMailDetailMapper
return baseMapper.findByMailNo(mailNo);
}
public List<LogOrderMailDetailEntity> getNewPackListByCode(String logisticsOrderCode) {
return baseMapper.getNewPackListByCode(logisticsOrderCode);
}
......
......@@ -6,8 +6,37 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class PddJYPriceTool {
public static int calculateWeight( int length, int width, int height, int weight, boolean international) {
if (international) {
// 国际件
return PddOverseaPriceTool.calculateWeight(length, width, height, weight);
} else {
// 国内件 属于退件
return PddNationalPriceTool.calculateWeight(length, width, height, weight);
}
}
public static long calculateFreightFee(int weight, String type, int exchange, boolean international) {
if (international) {
return PddOverseaPriceTool.calculatePrice(exchange, weight, type);
}
else {
return PddNationalPriceTool.calculatePrice(weight);
}
}
public static FeeResult getTotalFee(String type, int length, int width, int height, int weight, boolean international,String enterTime) {
public static long calculateRent(String enterTime, boolean international) {
if (international) {
return PddOverseaPriceTool.calculateRent(enterTime);
}
else {
return PddNationalPriceTool.calculateRent(enterTime);
}
}
/*
public static FeeResult getTotalFee(String type, int length, int width, int height, int weight, boolean international, String enterTime) {
log.info("length = {}, width = {}, height={}, weight = {}", length, width, height, weight);
if (international) {
// 国际件
......@@ -20,9 +49,11 @@ public class PddJYPriceTool {
}
@Data
public static class FeeResult{
public static class FeeResult {
int weight;
int rentFee;
int freightFee;
}
*/
}
......@@ -33,10 +33,52 @@ public class PddNationalPriceTool {
//标准三边之和
private static int maxStandard = 160;
public static int calculateWeight(int length, int width, int height, int weight) {
if (weight > maxWeight)
return -1;
return weight;
}
public static long calculatePrice(int weight) {
int price = initalPrice;
if (weight > initialWeight) {
int pw = weight - initialWeight;
int pc = pw / excessWeight;
if (pw % excessWeight != 0) {
pc += 1;
}
price = price + pc * excessPrice;
// log.info("续重数量:{}", pc);
}
return price;
}
public static long calculateRent(String enterTime) {
int rent = 0;
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = sdf.parse(enterTime);
Date date2 = new Date();
// 将Date转换为LocalDate
LocalDate localDate1 = date1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate localDate2 = date2.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
// 计算两个日期之间的天数差异
long daysBetween = Math.abs(java.time.temporal.ChronoUnit.DAYS.between(localDate2, localDate1));
if (daysBetween > 180) {
rent = (int) daysBetween - 180;
}
} catch (Exception e) {
e.printStackTrace();
}
return rent;
}
/*
* 根据类型、重量(g) 计算运费
* */
/*
public static PddJYPriceTool.FeeResult FreightCostCalculation(int length, int width, int height, int weight, String enterTime) {
PddJYPriceTool.FeeResult result = new PddJYPriceTool.FeeResult();
int price = initalPrice;
......@@ -61,7 +103,7 @@ public class PddNationalPriceTool {
// 计算两个日期之间的天数差异
long daysBetween = Math.abs(java.time.temporal.ChronoUnit.DAYS.between(localDate2, localDate1));
if (daysBetween > 180) {
rent = (int)daysBetween - 180;
rent = (int) daysBetween - 180;
}
} catch (Exception e) {
e.printStackTrace();
......@@ -73,4 +115,6 @@ public class PddNationalPriceTool {
result.setWeight(weight);
return result;
}
*/
}
......@@ -38,11 +38,84 @@ public class PddOverseaPriceTool {
//最大三边之和
private static int maxSumLength = 250;
public static int calculateWeight(int length, int width, int height, int weight) {
int max = length + width + height;
if (length > maxSingleLength || width > maxSingleLength || height > maxSingleLength || max > maxSumLength) {
//三边各超100或者和超160
return -1;
}
if (weight > maxWeight) {
//超重无法计算
return -1;
}
int compWeight = weight;
if (weight > baseMaxWeight || length > baseSingleLength || width > baseSingleLength || height > baseSingleLength || max > baseSumLength) {
//三边各超100或者和超160
int newWeight = length * width * height / 6000 + 1;
compWeight = Math.max(compWeight, newWeight);
}
return compWeight;
}
public static long calculatePrice(int exchange, int weight, String type) {
int price = 0;
if (exchange == 2) {
// 改派
price = 2400;
}
if (exchange == 3) {
price = 1200;
}
int excess = 0;
// 判断重量是否超重
//分析重量
if (weight > initialWeight) {
//计算超出重量
weight = weight - initialWeight;
excess = excessPrice * ((int) Math.ceil(1.0 * weight / excessWeight));
}
//计算价格
if (type.equals("NORMAL")) {
//普货
price = price + gInitalPrice + excess;
} else {
price = price + sInitalPrice + excess;
}
return price;
}
public static long calculateRent(String enterTime) {
int rent = 0;
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = sdf.parse(enterTime);
Date date2 = new Date();
// 将Date转换为LocalDate
LocalDate localDate1 = date1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
LocalDate localDate2 = date2.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
// 计算两个日期之间的天数差异
long daysBetween = Math.abs(java.time.temporal.ChronoUnit.DAYS.between(localDate2, localDate1));
if (daysBetween > 180) {
rent = (int) daysBetween - 180;
}
} catch (Exception e) {
e.printStackTrace();
}
return rent;
}
/*
* 根据类型、重量(g) 计算运费
* */
public static PddJYPriceTool.FeeResult FreightCostCalculation(String type, int length, int width, int height, int weight, int exchange,String enterTime) {
/*
public static PddJYPriceTool.FeeResult FreightCostCalculation(String type, int length, int width, int height, int weight, int exchange, String enterTime) {
int max = length + width + height;
if (length > maxSingleLength || width > maxSingleLength || height > maxSingleLength || max > maxSumLength) {
......@@ -103,7 +176,7 @@ public class PddOverseaPriceTool {
// 计算两个日期之间的天数差异
long daysBetween = Math.abs(java.time.temporal.ChronoUnit.DAYS.between(localDate2, localDate1));
if (daysBetween > 180) {
rent = (int)daysBetween - 180;
rent = (int) daysBetween - 180;
}
} catch (Exception e) {
e.printStackTrace();
......@@ -114,4 +187,6 @@ public class PddOverseaPriceTool {
result.setFreightFee(price);
return result;
}
*/
}
......@@ -3,12 +3,10 @@ package org.ta.pddserver;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.ta.pddserver.entity.LogOrderMailDetailEntity;
import org.ta.pddserver.model.enums.OrderProblemType;
import org.ta.pddserver.model.pddjy.request.*;
import org.ta.pddserver.model.pddjy.response.PddServiceConsoDerelictionResponse;
import org.ta.pddserver.utils.PddHttpTool;
import org.ta.pddserver.utils.PddJYPriceTool;
import org.ta.pddserver.utils.PddSignTool;
import java.text.SimpleDateFormat;
......@@ -92,8 +90,8 @@ public class CommonTest {
*/
@Test
public void receive() {
String LogisticsOrderCode = "PC25110314221207142437527";
String mailNo = "TT773010635902734";
String LogisticsOrderCode = "PC25110315105366425637527";
String mailNo = "773888539989914";
String expressCode = "STO";
String action = "warehouse_sign";
PddServiceConsoFirstBizActionNotifyRequest notifyRequest = new PddServiceConsoFirstBizActionNotifyRequest();
......@@ -110,7 +108,6 @@ public class CommonTest {
notifyResult.setCode(0);
} else if (action == "warehouse_reject_sign") {
notifyRequest.setBizActionDesc("仓库拒签");
notifyResult.setCode(22);
notifyResult.setDesc("运输品类限制");
notifyResult.setRemark("运输品类限制");
......@@ -143,8 +140,8 @@ public class CommonTest {
*/
@Test
public void reject() {
String LogisticsOrderCode = "PC25102916466837504518059";
String mailNo = "773763730734477";
String LogisticsOrderCode = "PC25110309183009177837527";
String mailNo = "773074032778146";
String expressCode = "STO";
String action = "warehouse_reject_sign";
PddServiceConsoFirstBizActionNotifyRequest notifyRequest = new PddServiceConsoFirstBizActionNotifyRequest();
......@@ -161,10 +158,17 @@ public class CommonTest {
notifyResult.setCode(0);
} else if (action == "warehouse_reject_sign") {
notifyRequest.setBizActionDesc("仓库拒签");
notifyResult.setCode(22);
notifyResult.setDesc("运输品类限制");
notifyResult.setRemark("运输品类限制");
notifyResult.setCode(20);
notifyResult.setDesc("超大");
notifyResult.setRemark("超大");
notifyRequest.setResult(notifyResult);
PddServiceConsoFirstBizActionNotifyRequest.PackageInfo packageInfo = new PddServiceConsoFirstBizActionNotifyRequest.PackageInfo();
notifyRequest.setPackageInfo(packageInfo);
packageInfo.setWidth(100L);
packageInfo.setHeight(100L);
packageInfo.setLength(100L);
packageInfo.setWeight(30000L);
packageInfo.setActualWeight(30000L);
} else if (action == "destroy") {
notifyRequest.setBizActionDesc("包裹销毁");
notifyResult.setCode(0);
......@@ -194,9 +198,8 @@ public class CommonTest {
@Test
public void inBound() {
String LogisticsOrderCode = "PC25110314221207142437527";
String mailNo = "TT773010635902734";
// String mailNo = "773608936457954";
String LogisticsOrderCode = "PC25110315105366425637527";
String mailNo = "773888539989914";
String expressCode = "STO";
PddServiceConsoInboundRequest notifyRequest = new PddServiceConsoInboundRequest();
......@@ -210,7 +213,7 @@ public class CommonTest {
notifyRequest.setStatus("FULL_INBOUND");
// notifyRequest.setStatus("PART_INBOUND");
notifyRequest.setPackageQuantity(3L);
notifyRequest.setPackageQuantity(1L);
notifyRequest.setPackageInfo(new PddServiceConsoInboundRequest.PackageInfo());
notifyRequest.getPackageInfo().setMailNo(mailNo);
......@@ -218,8 +221,8 @@ public class CommonTest {
notifyRequest.getPackageInfo().setLength(30L);
notifyRequest.getPackageInfo().setWidth(30L);
notifyRequest.getPackageInfo().setHeight(30L);
notifyRequest.getPackageInfo().setWeight(400L);
notifyRequest.getPackageInfo().setActualWeight(400L);
notifyRequest.getPackageInfo().setWeight(1000L);
notifyRequest.getPackageInfo().setActualWeight(1000L);
notifyRequest.getPackageInfo().setGoodsType("NORMAL");
notifyRequest.setResult(new PddServiceConsoInboundRequest.Result());
......@@ -246,8 +249,8 @@ public class CommonTest {
*/
@Test
public void beginPick() {
String LogisticsOrderCode = "PP25110308781194855037527";
String mailNo = "773554917225751";
String LogisticsOrderCode = "PP25110323338785177837527";
String mailNo = "773129289243424";
String expressCode = "STO";
String action = "begin_pick";
PddServiceConsoCoBizActionNotifyRequest notifyRequest = new PddServiceConsoCoBizActionNotifyRequest();
......@@ -296,8 +299,8 @@ public class CommonTest {
*/
@Test
public void finishPick() {
String LogisticsOrderCode = "PP25110308781194855037527";
String mailNo = "773554917225751";
String LogisticsOrderCode = "PP25110323338785177837527";
String mailNo = "773129289243424";
String expressCode = "STO";
String action = "finish_pick";
PddServiceConsoCoBizActionNotifyRequest notifyRequest = new PddServiceConsoCoBizActionNotifyRequest();
......@@ -324,13 +327,13 @@ public class CommonTest {
notifyRequest.setPackageInfos(new ArrayList<>());
PddServiceConsoCoBizActionNotifyRequest.PackageInfo packageInfo = new PddServiceConsoCoBizActionNotifyRequest.PackageInfo();
notifyRequest.getPackageInfos().add(packageInfo);
packageInfo.setWeight(1000L);
packageInfo.setWidth(40L);
packageInfo.setWeight(1100L);
packageInfo.setWidth(30L);
packageInfo.setLength(30L);
packageInfo.setHeight(20L);
packageInfo.setActualWeight(1000L);
packageInfo.setHeight(30L);
packageInfo.setActualWeight(1100L);
packageInfo.setConsoType("SEA");
packageInfo.setGoodsType("NORMAL");
packageInfo.setGoodsType("SPECIAL");
}
notifyRequest.setResult(notifyResult);
......@@ -358,9 +361,9 @@ public class CommonTest {
@Test
public void outBound() {
String mailNo = "BK-773448654218243";
String mailNo = "BK-773129289243424";
String expressCode = "KR_JD";
String orderCode = "PP25110314698518937737527";
String orderCode = "PP25110323338785177837527";
// String segmentCode = "RETURNSELLER";
String segmentCode = "SENDTORECEVER";
......@@ -380,8 +383,8 @@ public class CommonTest {
packageInfo.setPackageType("2");
packageInfo.setLength(30L);
packageInfo.setWidth(30L);
packageInfo.setHeight(20L);
packageInfo.setWeight(1000L);
packageInfo.setHeight(30L);
packageInfo.setWeight(1100L);
notifyRequest.setSenderDetail(new PddServiceConsoOutboundRequest.SenderDetail());
notifyRequest.getSenderDetail().setName("海际集货仓");
......@@ -428,9 +431,8 @@ public class CommonTest {
*/
@Test
public void finishUnpack() {
String LogisticsOrderCode = "PP25110314698518937737527";
String mailNo = "773448654218243";
String expressCode = "STO";
String LogisticsOrderCode = "PP25110323338785177837527";
// String mailNo = "773129289243424";
String action = "finish_unpack";
PddServiceConsoCoBizActionNotifyRequest notifyRequest = new PddServiceConsoCoBizActionNotifyRequest();
notifyRequest.setProviderCode(PROVIDER_CODE);
......@@ -454,13 +456,23 @@ public class CommonTest {
notifyRequest.setUnpackRemark("");
notifyResult.setCode(0);
notifyRequest.setPackageInfos(new ArrayList<>());
PddServiceConsoCoBizActionNotifyRequest.PackageInfo packageInfo0 = new PddServiceConsoCoBizActionNotifyRequest.PackageInfo();
notifyRequest.getPackageInfos().add(packageInfo0);
packageInfo0.setWeight(1500L);
packageInfo0.setWidth(30L);
packageInfo0.setHeight(30L);
packageInfo0.setLength(20L);
packageInfo0.setActualWeight(1500L);
packageInfo0.setConsoType("SEA");
packageInfo0.setGoodsType("NORMAL");
PddServiceConsoCoBizActionNotifyRequest.PackageInfo packageInfo = new PddServiceConsoCoBizActionNotifyRequest.PackageInfo();
notifyRequest.getPackageInfos().add(packageInfo);
packageInfo.setWeight(1000L);
packageInfo.setWeight(1500L);
packageInfo.setWidth(30L);
packageInfo.setHeight(30L);
packageInfo.setLength(20L);
packageInfo.setActualWeight(1000L);
packageInfo.setActualWeight(1500L);
packageInfo.setConsoType("SEA");
packageInfo.setGoodsType("SPECIAL");
}
......@@ -558,15 +570,7 @@ public class CommonTest {
@Test
public void testFee() {
PddJYPriceTool.FeeResult result = PddJYPriceTool.getTotalFee("NORMAL",
30,
30,
30,
1300,
true,
"2025-11-03"
);
log.info("result:{}", JSON.toJSONString(result));
}
......
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