修改测试

This commit is contained in:
wuweihua
2026-09-10 14:23:58 +08:00
parent 05c8d3f90d
commit 6d718320e6
24 changed files with 475 additions and 210 deletions
@@ -20,5 +20,5 @@ public interface ITmsPriceQuoteService
List<PrcQuote> selectQuoteList(PrcQuote query);
TmsPriceQuoteResult getQuote(Long quoteId);
TmsPriceQuoteResult getQuote(String quoteId);
}
@@ -1,11 +1,13 @@
package com.ruoyi.price.service.impl;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.zip.CRC32;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -406,21 +408,21 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
}
List<PrcCustomerPriceSet> customers = filterCustomers(set.getCustomers());
Set<Long> seenCustomers = new HashSet<Long>();
Set<String> seenCustomers = new HashSet<String>();
int bound = 0;
boolean dupInSet = false;
for (PrcCustomerPriceSet c : customers)
{
if (c.getCustomerId() == null)
if (StringUtils.isEmpty(c.getCustomerCode()))
{
continue;
}
if (!seenCustomers.add(c.getCustomerId()))
if (!seenCustomers.add(c.getCustomerCode()))
{
dupInSet = true;
continue;
}
bound += customerMapper.countByCustomerId(c.getCustomerId(), c.getCustomerPricesetId(),
bound += customerMapper.countByCustomerCode(c.getCustomerCode(), c.getCustomerPricesetId(),
set.getPriceSetId());
}
if (dupInSet || bound > 0)
@@ -581,10 +583,10 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
if (set.getCustomers() != null)
{
customerMapper.deletePrcCustomerPriceSetByPriceSetId(set.getPriceSetId());
Set<Long> seenCustomers = new HashSet<Long>();
Set<String> seenCustomers = new HashSet<String>();
for (PrcCustomerPriceSet c : filterCustomers(set.getCustomers()))
{
if (c.getCustomerId() != null && !seenCustomers.add(c.getCustomerId()))
if (StringUtils.isNotEmpty(c.getCustomerCode()) && !seenCustomers.add(c.getCustomerCode()))
{
throw new ServiceException(MessageUtils.message("price.set.customer.alreadyBound"));
}
@@ -759,7 +761,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
private void validateCustomer(PrcCustomerPriceSet customer, PrcPriceSet set)
{
if (customer.getCustomerId() == null || customer.getCustomerId().longValue() <= 0)
if (StringUtils.isEmpty(customer.getCustomerCode()))
{
throw new ServiceException(MessageUtils.message("price.set.customer.customerId.empty"));
}
@@ -779,12 +781,30 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
{
throw new ServiceException(MessageUtils.message("price.set.customer.priority.invalid"));
}
int exists = customerMapper.countByCustomerId(customer.getCustomerId(),
int exists = customerMapper.countByCustomerCode(customer.getCustomerCode(),
customer.getCustomerPricesetId(), null);
if (exists > 0)
{
throw new ServiceException(MessageUtils.message("price.set.customer.alreadyBound"));
}
customer.setCustomerId(resolveNumericCustomerId(customer));
}
private Long resolveNumericCustomerId(PrcCustomerPriceSet customer)
{
if (customer.getCustomerId() != null && customer.getCustomerId().longValue() > 0)
{
return customer.getCustomerId();
}
return hashCustomerCode(customer.getCustomerCode());
}
private static Long hashCustomerCode(String customerCode)
{
CRC32 crc = new CRC32();
crc.update(customerCode.getBytes(StandardCharsets.UTF_8));
long v = crc.getValue();
return v == 0L ? Long.valueOf(1L) : Long.valueOf(v);
}
private void assertBasicEditable(PrcPriceSet db)
@@ -882,7 +902,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
}
for (PrcCustomerPriceSet c : customers)
{
if (c != null && c.getCustomerId() != null && c.getCustomerId().longValue() > 0)
if (c != null && StringUtils.isNotEmpty(c.getCustomerCode()))
{
list.add(c);
}
@@ -9,6 +9,7 @@ import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
@@ -119,7 +120,7 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
}
@Override
public TmsPriceQuoteResult getQuote(Long quoteId)
public TmsPriceQuoteResult getQuote(String quoteId)
{
if (quoteId == null)
{
@@ -152,8 +153,17 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
}
String productName = resolveProductName(productCode, bizDate);
List<PrcCustomerPriceSet> binds = customerPriceSetMapper.selectEffectiveByCustomer(
request.getCustomerId(), bizDate);
List<PrcCustomerPriceSet> binds;
if (StringUtils.isNotEmpty(request.getCustomerCode()))
{
binds = customerPriceSetMapper.selectEffectiveByCustomerCode(
request.getCustomerCode(), bizDate);
}
else
{
binds = customerPriceSetMapper.selectEffectiveByCustomer(
request.getCustomerId(), bizDate);
}
if (binds != null)
{
@@ -455,8 +465,9 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
Date bizDate, TmsPriceQuoteResult result)
{
PrcQuote quote = new PrcQuote();
quote.setQuoteId(UUID.randomUUID().toString());
quote.setQuoteKey(quoteKey);
quote.setCustomerId(request.getCustomerId());
quote.setCustomerId(request.getCustomerId() == null ? Long.valueOf(0L) : request.getCustomerId());
quote.setProductCode(result.getProductCode());
quote.setProductName(result.getProductName());
quote.setCountryCode(result.getCountryCode());
@@ -538,7 +549,7 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
return false;
}
private void replaceQuoteFees(Long quoteId, TmsPriceQuoteResult result)
private void replaceQuoteFees(String quoteId, TmsPriceQuoteResult result)
{
quoteFeeMapper.deleteByQuoteId(quoteId);
List<PrcQuoteFee> fees = toFeeRows(quoteId, result);
@@ -549,7 +560,7 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
quoteMapper.updateQuoteAmounts(quoteId, result.getSurchargeAmount(), result.getPayableTotal());
}
private List<PrcQuoteFee> toFeeRows(Long quoteId, TmsPriceQuoteResult result)
private List<PrcQuoteFee> toFeeRows(String quoteId, TmsPriceQuoteResult result)
{
List<PrcQuoteFee> fees = new ArrayList<PrcQuoteFee>();
if (result.getFeeDetails() == null)
@@ -664,7 +675,8 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
}
String countryName = emptyToNull(request.getCountryName());
String biz = new SimpleDateFormat("yyyy-MM-dd").format(bizDate);
String raw = request.getCustomerId() + "|"
String raw = (StringUtils.isNotEmpty(request.getCustomerCode())
? request.getCustomerCode() : String.valueOf(request.getCustomerId())) + "|"
+ request.getProductCode().trim() + "|"
+ nvlStr(countryCode) + "|"
+ nvlStr(countryName) + "|"
@@ -758,7 +770,7 @@ public class TmsPriceQuoteServiceImpl implements ITmsPriceQuoteService
{
throw new ServiceException(MessageUtils.message("price.quote.requestBodyRequired"));
}
if (request.getCustomerId() == null)
if (StringUtils.isEmpty(request.getCustomerCode()) && request.getCustomerId() == null)
{
throw new ServiceException(MessageUtils.message("price.quote.customerIdRequired"));
}