优化记录日志功能

This commit is contained in:
wuweihua
2026-09-11 16:12:01 +08:00
parent 06211adaac
commit 719d8c7208
13 changed files with 346 additions and 161 deletions
@@ -23,7 +23,7 @@ import com.ruoyi.price.domain.vo.TmsPriceQuoteFeeLine;
import com.ruoyi.price.domain.vo.TmsPriceQuoteResult;
import com.ruoyi.price.mapper.PrcBillFeeMapper;
import com.ruoyi.price.mapper.PrcBillMapper;
import com.ruoyi.price.search.BillSyncSnapshot;
import com.ruoyi.price.search.EsBizLogSupport;
import com.ruoyi.price.search.EsLogType;
import com.ruoyi.price.search.IBillSearchStore;
import com.ruoyi.price.service.IPrcBillService;
@@ -48,20 +48,28 @@ public class PrcBillServiceImpl implements IPrcBillService
@Transactional(rollbackFor = Exception.class)
public TmsPriceQuoteResult bill(TmsPriceBillRequest request)
{
if (request == null || StringUtils.isEmpty(request.getOrderNo()))
try
{
throw new ServiceException(MessageUtils.message("price.bill.orderNoRequired"));
if (request == null || StringUtils.isEmpty(request.getOrderNo()))
{
throw new ServiceException(MessageUtils.message("price.bill.orderNoRequired"));
}
request.setOrderNo(request.getOrderNo().trim());
if (StringUtils.isEmpty(request.getBizDate()))
{
throw new ServiceException(MessageUtils.message("price.bill.bizDateRequired"));
}
Date bizDate = resolveBizDate(request.getBizDate());
BigDecimal weight = request.getWeight();
TmsPriceQuoteResult result = tmsPriceQuoteService.calculate(request);
persistBill(request, weight, bizDate, result);
return result;
}
request.setOrderNo(request.getOrderNo().trim());
if (StringUtils.isEmpty(request.getBizDate()))
catch (RuntimeException e)
{
throw new ServiceException(MessageUtils.message("price.bill.bizDateRequired"));
EsBizLogSupport.saveFail(billSearchStore, EsLogType.BILL, EsBizLogSupport.billFailBizId(request), request, e);
throw e;
}
Date bizDate = resolveBizDate(request.getBizDate());
BigDecimal weight = request.getWeight();
TmsPriceQuoteResult result = tmsPriceQuoteService.calculate(request);
persistBill(request, weight, bizDate, result);
return result;
}
@Override
@@ -261,31 +269,9 @@ public class PrcBillServiceImpl implements IPrcBillService
}
}
r.setFeeDetails(lines);
fillSnapshotFromSearch(r, bill);
return r;
}
private void fillSnapshotFromSearch(TmsPriceQuoteResult r, PrcBill bill)
{
BillSyncSnapshot snap = billSearchStore.get(EsLogType.BILL, bill.getOrderNo());
if (snap != null && StringUtils.isNotEmpty(snap.getRequestJson()))
{
r.setRequestJson(snap.getRequestJson());
}
else
{
r.setRequestJson(rebuildRequestJson(bill));
}
if (snap != null && StringUtils.isNotEmpty(snap.getResponseJson()))
{
r.setResponseJson(snap.getResponseJson());
}
else
{
r.setResponseJson(toResponseJson(r));
}
}
private void fillResultOrder(TmsPriceQuoteResult r, PrcBill bill)
{
r.setTrackingNo(bill.getTrackingNo());
@@ -328,42 +314,6 @@ public class PrcBillServiceImpl implements IPrcBillService
return obj.toJSONString();
}
private String rebuildRequestJson(PrcBill bill)
{
JSONObject obj = new JSONObject();
putIfNotNull(obj, "orderNo", bill.getOrderNo());
putIfNotNull(obj, "trackingNo", bill.getTrackingNo());
putIfNotNull(obj, "customerId", bill.getCustomerId());
putIfNotNull(obj, "customerCode", bill.getCustomerCode());
putIfNotNull(obj, "customerName", bill.getCustomerName());
putIfNotNull(obj, "productCode", bill.getProductCode());
putIfNotNull(obj, "countryCode", bill.getCountryCode());
putIfNotNull(obj, "countryName", bill.getCountryName());
putIfNotNull(obj, "weight", bill.getWeight());
if (bill.getBizDate() != null)
{
obj.put("bizDate", new SimpleDateFormat("yyyy-MM-dd").format(bill.getBizDate()));
}
putIfNotNull(obj, "tmsId", bill.getTmsId());
putIfNotNull(obj, "pieces", bill.getPieces());
putIfNotNull(obj, "actualWeight", bill.getActualWeight());
putIfNotNull(obj, "volume", bill.getVolume());
putIfNotNull(obj, "volumeWeight", bill.getVolumeWeight());
putIfNotNull(obj, "pkgLength", bill.getPkgLength());
putIfNotNull(obj, "pkgWidth", bill.getPkgWidth());
putIfNotNull(obj, "pkgHeight", bill.getPkgHeight());
putIfNotNull(obj, "shipperName", bill.getShipperName());
putIfNotNull(obj, "consigneeName", bill.getConsigneeName());
putIfNotNull(obj, "destPostcode", bill.getDestPostcode());
putIfNotNull(obj, "warehouseCode", bill.getWarehouseCode());
if (bill.getOrderTime() != null)
{
obj.put("orderTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(bill.getOrderTime()));
}
putIfNotNull(obj, "orderRemark", bill.getOrderRemark());
return obj.toJSONString();
}
private JSONObject parseJsonObject(String json)
{
if (StringUtils.isEmpty(json))
@@ -380,14 +330,6 @@ public class PrcBillServiceImpl implements IPrcBillService
}
}
private void putIfNotNull(JSONObject obj, String key, Object value)
{
if (value != null && !(value instanceof String && ((String) value).isEmpty()))
{
obj.put(key, value);
}
}
private Date resolveBizDate(String bizDate)
{
if (StringUtils.isEmpty(bizDate))
@@ -39,6 +39,7 @@ import com.ruoyi.price.mapper.PrcPriceSetMapper;
import com.ruoyi.price.mapper.PrcQuoteFeeMapper;
import com.ruoyi.price.mapper.PrcQuoteMapper;
import com.ruoyi.price.mapper.PrcSurchargeRelMapper;
import com.ruoyi.price.search.EsBizLogSupport;
import com.ruoyi.price.search.EsLogType;
import com.ruoyi.price.search.IBillSearchStore;
import com.ruoyi.price.service.ITmsPriceQuoteService;
@@ -92,6 +93,20 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
@Override
@Transactional(rollbackFor = Exception.class)
public TmsPriceQuoteResult quote(TmsPriceQuoteRequest request)
{
try
{
return quoteInternal(request);
}
catch (RuntimeException e)
{
EsBizLogSupport.saveFail(billSearchStore, EsLogType.QUOTE, EsBizLogSupport.quoteFailBizId(request),
request, e);
throw e;
}
}
private TmsPriceQuoteResult quoteInternal(TmsPriceQuoteRequest request)
{
validateRequest(request);
Date bizDate = resolveBizDate(request.getBizDate());