Browse Source

feat(all): 车次成本计算

1 修改车次成本公里数成本计算错误问题
dev
zhaoqiaobo 1 month ago
parent
commit
bc4b1b5807
  1. 2
      blade-biz-common/src/main/java/org/springblade/common/utils/GaoDeApiUtil.java
  2. 42
      blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/DeliverFinishReportListener.java

2
blade-biz-common/src/main/java/org/springblade/common/utils/GaoDeApiUtil.java

@ -85,6 +85,7 @@ public class GaoDeApiUtil {
* @Author zqb 2024/9/14 * @Author zqb 2024/9/14
**/ **/
public static Long measureDistance(String origins, String destination) { public static Long measureDistance(String origins, String destination) {
// 计算距离服务高德每秒钟只能接收3次,需要评估每秒请求次数
// lat 小 log 大 // lat 小 log 大
String key = "40448f21dfc7a531e9db4c405d955bea"; String key = "40448f21dfc7a531e9db4c405d955bea";
String urlString = "https://restapi.amap.com/v3/distance?key=" + key + "&origins=" + origins + "&destination=" + destination; String urlString = "https://restapi.amap.com/v3/distance?key=" + key + "&origins=" + origins + "&destination=" + destination;
@ -102,6 +103,7 @@ public class GaoDeApiUtil {
in.close(); in.close();
// 解析结果 // 解析结果
JSONObject jsonObject = JSONObject.parseObject(res); JSONObject jsonObject = JSONObject.parseObject(res);
log.info("根据经纬度测量路径获取成功:{}", jsonObject.toJSONString());
JSONArray results = jsonObject.getJSONArray("results"); JSONArray results = jsonObject.getJSONArray("results");
if (CollUtil.isNotEmpty(results)) { if (CollUtil.isNotEmpty(results)) {
return results.getJSONObject(0).getLong("distance"); return results.getJSONObject(0).getLong("distance");

42
blade-service/logpm-distribution/src/main/java/com/logpm/distribution/receiver/report/DeliverFinishReportListener.java

@ -80,7 +80,18 @@ public class DeliverFinishReportListener implements ReportService {
FinishDistributionTrainVO vo = JSONUtil.toBean(entries, FinishDistributionTrainVO.class); FinishDistributionTrainVO vo = JSONUtil.toBean(entries, FinishDistributionTrainVO.class);
String trainNumber = vo.getTrainNumber(); String trainNumber = vo.getTrainNumber();
String deliveryKind = vo.getDeliveryKind(); String deliveryKind = vo.getDeliveryKind();
calculateTripCost(trainNumber, deliveryKind); Map<String, TrunklineWaybillOrderEntity> waybillOrderMap = calculateTripCost(trainNumber, deliveryKind);
// 生成订单 发送延时消息生成报表
if (CollUtil.isNotEmpty(waybillOrderMap)) {
for (Map.Entry<String, TrunklineWaybillOrderEntity> entityEntry : waybillOrderMap.entrySet()) {
factoryDataClient.sendMessage(SendMsg.builder()
.exchange(ReportConstants.REPORT_EXPENSE_ORDER_EXCHANGE)
.routingKey(ReportConstants.REPORT_EXPENSE_ORDER_ROUTINGKEY)
.message(JSONUtil.toJsonStr(entityEntry.getValue()))
.delay(10000)
.build());
}
}
// 生成车辆车次成本 发送延时消息生成报表 // 生成车辆车次成本 发送延时消息生成报表
factoryDataClient.sendMessage(SendMsg.builder() factoryDataClient.sendMessage(SendMsg.builder()
.exchange(ReportConstants.REPORT_QUALITY_CAR_FINAL_EXCHANGE) .exchange(ReportConstants.REPORT_QUALITY_CAR_FINAL_EXCHANGE)
@ -92,7 +103,7 @@ public class DeliverFinishReportListener implements ReportService {
} }
public void calculateTripCost(String trainNumber, String deliveryKindParam) { public Map<String, TrunklineWaybillOrderEntity> calculateTripCost(String trainNumber, String deliveryKindParam) {
// 根据车次查询出包件明细,然后计算对应的成本 // 根据车次查询出包件明细,然后计算对应的成本
List<QualityDeliverEntity> entities = qualityDeliverService.list(Wrappers.<QualityDeliverEntity>lambdaQuery() List<QualityDeliverEntity> entities = qualityDeliverService.list(Wrappers.<QualityDeliverEntity>lambdaQuery()
.eq(QualityDeliverEntity::getSignTrainNumber, trainNumber) .eq(QualityDeliverEntity::getSignTrainNumber, trainNumber)
@ -142,7 +153,7 @@ public class DeliverFinishReportListener implements ReportService {
for (QualityDeliverEntity qualityDeliverEntity : value) { for (QualityDeliverEntity qualityDeliverEntity : value) {
QualityDeliverEntity entity = new QualityDeliverEntity(); QualityDeliverEntity entity = new QualityDeliverEntity();
entity.setId(qualityDeliverEntity.getId()); entity.setId(qualityDeliverEntity.getId());
if(ObjectUtil.isEmpty(entity.getCarComplateTime())){ if(ObjectUtil.isEmpty(qualityDeliverEntity.getCarComplateTime())){
entity.setCarComplateTime(new Date()); entity.setCarComplateTime(new Date());
} }
entity.setOrderCode(qualityDeliverEntity.getOrderCode()); entity.setOrderCode(qualityDeliverEntity.getOrderCode());
@ -381,6 +392,7 @@ public class DeliverFinishReportListener implements ReportService {
String key = allEntry.getKey(); String key = allEntry.getKey();
lastCode = key; lastCode = key;
if (StrUtil.isNotEmpty(allEntry.getValue())) { if (StrUtil.isNotEmpty(allEntry.getValue())) {
log.info("公里数成本 总公里数:{},{}",key, allEntry.getValue());
total = NumberUtil.add(total, new BigDecimal(allEntry.getValue())); total = NumberUtil.add(total, new BigDecimal(allEntry.getValue()));
} }
} }
@ -391,6 +403,7 @@ public class DeliverFinishReportListener implements ReportService {
if (CollUtil.isNotEmpty(firstRouteMap)) { if (CollUtil.isNotEmpty(firstRouteMap)) {
String s = firstRouteMap.get(lastCode); String s = firstRouteMap.get(lastCode);
if (StrUtil.isNotEmpty(s)) { if (StrUtil.isNotEmpty(s)) {
log.info("公里数成本 返程公里数:{}", s);
total = total.add(new BigDecimal(s)); total = total.add(new BigDecimal(s));
} }
} }
@ -908,23 +921,13 @@ public class DeliverFinishReportListener implements ReportService {
waybillOrderMap.put(key, waybillOrderEntity); waybillOrderMap.put(key, waybillOrderEntity);
} }
} }
// 生成订单 发送延时消息生成报表 return waybillOrderMap;
if (CollUtil.isNotEmpty(waybillOrderMap)) {
for (Map.Entry<String, TrunklineWaybillOrderEntity> entityEntry : waybillOrderMap.entrySet()) {
factoryDataClient.sendMessage(SendMsg.builder()
.exchange(ReportConstants.REPORT_EXPENSE_ORDER_EXCHANGE)
.routingKey(ReportConstants.REPORT_EXPENSE_ORDER_ROUTINGKEY)
.message(JSONUtil.toJsonStr(entityEntry.getValue()))
.delay(10000)
.build());
}
}
} }
} }
} }
} }
} }
return null;
} }
private static BigDecimal buildDisCost(QualityDeliverEntity entity, ExpenseDispatchPriceCategoryVO expenseDispatchPriceCategoryVO, QualityDeliverEntity entity1, BigDecimal totalFreight) { private static BigDecimal buildDisCost(QualityDeliverEntity entity, ExpenseDispatchPriceCategoryVO expenseDispatchPriceCategoryVO, QualityDeliverEntity entity1, BigDecimal totalFreight) {
@ -1036,6 +1039,7 @@ public class DeliverFinishReportListener implements ReportService {
private static void buildKilometerCost(ExpenseDispatchPriceVO priceVO, BigDecimal total, Map<Long, QualityDeliverEntity> valueMap, Integer totalNum) { private static void buildKilometerCost(ExpenseDispatchPriceVO priceVO, BigDecimal total, Map<Long, QualityDeliverEntity> valueMap, Integer totalNum) {
String kilometerCost = StrUtil.isEmpty(priceVO.getKilometerCost()) ? "0" : priceVO.getKilometerCost(); String kilometerCost = StrUtil.isEmpty(priceVO.getKilometerCost()) ? "0" : priceVO.getKilometerCost();
BigDecimal mul = NumberUtil.mul(total, new BigDecimal(kilometerCost)); BigDecimal mul = NumberUtil.mul(total, new BigDecimal(kilometerCost));
log.info("公里数成本:{},{},{}", kilometerCost, Convert.toStr(total), Convert.toStr(mul));
BigDecimal deliveryFeeSum = BigDecimal.ZERO; BigDecimal deliveryFeeSum = BigDecimal.ZERO;
int idex = 0; int idex = 0;
int size = valueMap.size(); int size = valueMap.size();
@ -1097,12 +1101,20 @@ public class DeliverFinishReportListener implements ReportService {
if (StrUtil.isNotEmpty(arrivePositioning)) { if (StrUtil.isNotEmpty(arrivePositioning)) {
// A-B A-C A-D 仓库为起点到每一个点的距离 // A-B A-C A-D 仓库为起点到每一个点的距离
Long first = GaoDeApiUtil.measureDistance(firstPositioning, arrivePositioning); Long first = GaoDeApiUtil.measureDistance(firstPositioning, arrivePositioning);
log.info("点位计算结果 first:{}", first);
firstRouteMap.put(value1.getSignReservationCode(), Convert.toStr(ObjectUtil.isNotEmpty(first) ? NumberUtil.div(new BigDecimal(first), 1000) : 0L / 1000)); firstRouteMap.put(value1.getSignReservationCode(), Convert.toStr(ObjectUtil.isNotEmpty(first) ? NumberUtil.div(new BigDecimal(first), 1000) : 0L / 1000));
if (StrUtil.isEmpty(beforePositioning)) { if (StrUtil.isEmpty(beforePositioning)) {
beforePositioning = firstPositioning; beforePositioning = firstPositioning;
} }
// 等500毫秒再次调用
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
// A-B B-C C-D 每一个点为起点到下一个点的距离 // A-B B-C C-D 每一个点为起点到下一个点的距离
Long distance = GaoDeApiUtil.measureDistance(beforePositioning, arrivePositioning); Long distance = GaoDeApiUtil.measureDistance(beforePositioning, arrivePositioning);
log.info("点位计算结果 distance:{}", distance);
String str = Convert.toStr(ObjectUtil.isNotEmpty(distance) ? NumberUtil.div(new BigDecimal(distance), 1000) : 0L / 1000); String str = Convert.toStr(ObjectUtil.isNotEmpty(distance) ? NumberUtil.div(new BigDecimal(distance), 1000) : 0L / 1000);
// 获取上一个点位的总距离 // 获取上一个点位的总距离
// reduce = NumberUtil.add(reduce, new BigDecimal(str)); // reduce = NumberUtil.add(reduce, new BigDecimal(str));

Loading…
Cancel
Save