记录同步数据日志功能
This commit is contained in:
+119
-5
@@ -10,6 +10,8 @@ import java.util.UUID;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
@@ -21,6 +23,9 @@ 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.EsLogType;
|
||||
import com.ruoyi.price.search.IBillSearchStore;
|
||||
import com.ruoyi.price.service.IPrcBillService;
|
||||
import com.ruoyi.price.service.ITmsPriceQuoteService;
|
||||
|
||||
@@ -36,6 +41,9 @@ public class PrcBillServiceImpl implements IPrcBillService
|
||||
@Autowired
|
||||
private PrcBillFeeMapper billFeeMapper;
|
||||
|
||||
@Autowired
|
||||
private IBillSearchStore billSearchStore;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public TmsPriceQuoteResult bill(TmsPriceBillRequest request)
|
||||
@@ -152,6 +160,11 @@ public class PrcBillServiceImpl implements IPrcBillService
|
||||
bill.setPayableTotal(result.getPayableTotal());
|
||||
bill.setCurrency(result.getCurrency());
|
||||
bill.setRoundMode(result.getRoundMode());
|
||||
result.setBillId(bill.getBillId());
|
||||
result.setOrderNo(orderNo);
|
||||
result.setCustomerCode(request.getCustomerCode());
|
||||
fillResultOrder(result, bill);
|
||||
result.setFromCache(Boolean.valueOf(existed != null));
|
||||
if (existed == null)
|
||||
{
|
||||
billMapper.insertPrcBill(bill);
|
||||
@@ -166,11 +179,7 @@ public class PrcBillServiceImpl implements IPrcBillService
|
||||
{
|
||||
billFeeMapper.insertBatch(fees);
|
||||
}
|
||||
result.setBillId(bill.getBillId());
|
||||
result.setOrderNo(orderNo);
|
||||
result.setCustomerCode(request.getCustomerCode());
|
||||
fillResultOrder(result, bill);
|
||||
result.setFromCache(Boolean.valueOf(existed != null));
|
||||
billSearchStore.save(EsLogType.BILL, orderNo, toRequestJson(request), toResponseJson(result));
|
||||
}
|
||||
|
||||
private List<PrcBillFee> toFeeRows(String billId, TmsPriceQuoteResult result)
|
||||
@@ -252,9 +261,31 @@ 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());
|
||||
@@ -274,6 +305,89 @@ public class PrcBillServiceImpl implements IPrcBillService
|
||||
r.setOrderRemark(bill.getOrderRemark());
|
||||
}
|
||||
|
||||
private String toRequestJson(TmsPriceBillRequest request)
|
||||
{
|
||||
JSONObject obj = parseJsonObject(JSON.toJSONString(request));
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
obj.remove("apiCode");
|
||||
return obj.toJSONString();
|
||||
}
|
||||
|
||||
private String toResponseJson(TmsPriceQuoteResult result)
|
||||
{
|
||||
JSONObject obj = parseJsonObject(JSON.toJSONString(result));
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
obj.remove("requestJson");
|
||||
obj.remove("responseJson");
|
||||
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))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
return JSON.parseObject(json);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
|
||||
+33
@@ -14,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
@@ -37,6 +39,8 @@ 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.EsLogType;
|
||||
import com.ruoyi.price.search.IBillSearchStore;
|
||||
import com.ruoyi.price.service.ITmsPriceQuoteService;
|
||||
|
||||
/**
|
||||
@@ -82,6 +86,9 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
|
||||
@Autowired
|
||||
private PrcQuoteFeeMapper quoteFeeMapper;
|
||||
|
||||
@Autowired
|
||||
private IBillSearchStore billSearchStore;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public TmsPriceQuoteResult quote(TmsPriceQuoteRequest request)
|
||||
@@ -104,6 +111,7 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
|
||||
replaceQuoteFees(cached.getQuoteId(), refreshed);
|
||||
refreshed.setQuoteId(cached.getQuoteId());
|
||||
refreshed.setFromCache(false);
|
||||
billSearchStore.save(EsLogType.QUOTE, cached.getQuoteId(), toEsRequest(request), toEsResponse(refreshed));
|
||||
return refreshed;
|
||||
}
|
||||
|
||||
@@ -531,6 +539,7 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
|
||||
}
|
||||
result.setQuoteId(quote.getQuoteId());
|
||||
result.setFromCache(false);
|
||||
billSearchStore.save(EsLogType.QUOTE, quote.getQuoteId(), toEsRequest(request), toEsResponse(result));
|
||||
}
|
||||
|
||||
private boolean isStaleSurchargeFees(List<PrcQuoteFee> fees)
|
||||
@@ -580,6 +589,7 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
|
||||
for (TmsPriceQuoteFeeLine line : result.getFeeDetails())
|
||||
{
|
||||
PrcQuoteFee fee = new PrcQuoteFee();
|
||||
fee.setFeeId(UUID.randomUUID().toString());
|
||||
fee.setQuoteId(quoteId);
|
||||
fee.setFeeType(line.getFeeType());
|
||||
fee.setFeeName(line.getFeeName());
|
||||
@@ -832,6 +842,29 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
|
||||
return p == null ? null : p.getProductName();
|
||||
}
|
||||
|
||||
private String toEsRequest(TmsPriceQuoteRequest request)
|
||||
{
|
||||
JSONObject obj = JSON.parseObject(JSON.toJSONString(request));
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
obj.remove("apiCode");
|
||||
return obj.toJSONString();
|
||||
}
|
||||
|
||||
private String toEsResponse(TmsPriceQuoteResult result)
|
||||
{
|
||||
JSONObject obj = JSON.parseObject(JSON.toJSONString(result));
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
obj.remove("requestJson");
|
||||
obj.remove("responseJson");
|
||||
return obj.toJSONString();
|
||||
}
|
||||
|
||||
private static String emptyToNull(String s)
|
||||
{
|
||||
return StringUtils.isEmpty(s) ? null : s.trim();
|
||||
|
||||
Reference in New Issue
Block a user