增加价格变更日志

This commit is contained in:
wuweihua
2026-11-06 10:11:15 +08:00
parent 1090d838a6
commit e415843b14
12 changed files with 487 additions and 58 deletions
@@ -450,6 +450,11 @@ public class BmsCustomerLogServiceImpl implements IBmsCustomerLogService
realChanges.add(c);
}
}
// Rebind/update with no field diff: skip empty UPDATE noise (full package save upsert)
if (existing != null && realChanges.isEmpty())
{
return;
}
saveLog(bind.getCustomerId(), customer == null ? null : customer.getCustomerCode(),
customer == null ? null : customer.getCustomerName(),
BmsCustomerLog.MODULE_PRICE_SET, newSet.getPriceSetName(),
@@ -44,6 +44,9 @@ public interface PrcPriceSetDetailMapper
public int countByPsvId(Long psvId);
/** Count detail rows including soft-deleted (for deleted-version tab). */
public int countByPsvIdAll(Long psvId);
public int copyDetailsFromVersion(@Param("srcPsvId") Long srcPsvId, @Param("newPsvId") Long newPsvId);
/** Copy version effective time, expire time and status onto catalog detail rows. */
@@ -173,6 +173,15 @@ public class EsBillSearchStore implements IBillSearchStore
@Override
public BillSearchPage search(String logType, String bizId, String status, Long psvId, String priceKind,
String productCode, String updateTime, String updateTimePrefix, int pageNum, int pageSize)
{
return search(logType, bizId, status, psvId, priceKind, productCode, updateTime, updateTimePrefix,
null, pageNum, pageSize);
}
@Override
public BillSearchPage search(String logType, String bizId, String status, Long psvId, String priceKind,
String productCode, String updateTime, String updateTimePrefix, String countryKeyword,
int pageNum, int pageSize)
{
BillSearchPage page = new BillSearchPage();
if (pageNum < 1)
@@ -197,7 +206,7 @@ public class EsBillSearchStore implements IBillSearchStore
sort.add(sortItem);
body.put("sort", sort);
body.put("query", buildQuery(logType, bizId, status, psvId, priceKind, productCode, updateTime,
updateTimePrefix));
updateTimePrefix, countryKeyword));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<String>(body.toJSONString(), headers);
@@ -378,7 +387,7 @@ public class EsBillSearchStore implements IBillSearchStore
}
private JSONObject buildQuery(String logType, String bizId, String status, Long psvId, String priceKind,
String productCode, String updateTime, String updateTimePrefix)
String productCode, String updateTime, String updateTimePrefix, String countryKeyword)
{
JSONArray filters = new JSONArray();
addTerm(filters, "logType", logType);
@@ -387,6 +396,7 @@ public class EsBillSearchStore implements IBillSearchStore
addPsvIdFilter(filters, psvId);
addTerm(filters, "request.priceKind", priceKind);
addProductCodeFilter(filters, productCode);
addCountryKeywordFilter(filters, countryKeyword);
addUpdateTimeFilter(filters, updateTime);
addUpdateTimePrefixFilter(filters, updateTimePrefix);
if (filters.isEmpty())
@@ -430,6 +440,65 @@ public class EsBillSearchStore implements IBillSearchStore
filters.add(boolWrap);
}
/** Match country code / name (exact or contains). */
private void addCountryKeywordFilter(JSONArray filters, String countryKeyword)
{
if (StringUtils.isEmpty(countryKeyword))
{
return;
}
String kw = countryKeyword.trim();
String wild = "*" + escapeWildcard(kw) + "*";
JSONArray should = new JSONArray();
addShouldTerm(should, "request.bizKeys.countryCode.keyword", kw);
addShouldTerm(should, "request.bizKeys.countryCode", kw);
addShouldWildcard(should, "request.bizKeys.countryCode.keyword", wild);
addShouldWildcard(should, "request.bizKeys.countryCode", wild);
addShouldWildcard(should, "request.bizKeys.countryName.keyword", wild);
addShouldWildcard(should, "request.bizKeys.countryName", wild);
JSONObject matchName = new JSONObject();
JSONObject matchField = new JSONObject();
matchField.put("query", kw);
matchName.put("request.bizKeys.countryName", matchField);
JSONObject matchWrap = new JSONObject();
matchWrap.put("match", matchName);
should.add(matchWrap);
JSONObject inner = new JSONObject();
inner.put("should", should);
inner.put("minimum_should_match", Integer.valueOf(1));
JSONObject boolWrap = new JSONObject();
boolWrap.put("bool", inner);
filters.add(boolWrap);
}
private void addShouldTerm(JSONArray should, String field, String value)
{
JSONObject term = new JSONObject();
term.put(field, value);
JSONObject wrap = new JSONObject();
wrap.put("term", term);
should.add(wrap);
}
private void addShouldWildcard(JSONArray should, String field, String value)
{
JSONObject wild = new JSONObject();
wild.put(field, value);
JSONObject wrap = new JSONObject();
wrap.put("wildcard", wild);
should.add(wrap);
}
private static String escapeWildcard(String raw)
{
if (raw == null)
{
return "";
}
return raw.replace("\\", "\\\\").replace("*", "\\*").replace("?", "\\?");
}
private void addUpdateTimeFilter(JSONArray filters, String updateTime)
{
if (StringUtils.isEmpty(updateTime))
@@ -38,6 +38,17 @@ public interface IBillSearchStore
default BillSearchPage search(String logType, String bizId, String status, Long psvId, String priceKind,
String productCode, String updateTime, String updateTimePrefix, int pageNum, int pageSize)
{
return search(logType, bizId, status, psvId, priceKind, productCode, updateTime, updateTimePrefix,
null, pageNum, pageSize);
}
/**
* Search with optional countryKeyword (matches bizKeys.countryCode / countryName).
*/
default BillSearchPage search(String logType, String bizId, String status, Long psvId, String priceKind,
String productCode, String updateTime, String updateTimePrefix, String countryKeyword,
int pageNum, int pageSize)
{
return search(logType, bizId, status, pageNum, pageSize);
}
@@ -152,11 +152,31 @@ public final class PriceChangeEsLog
keys.put("countryCode", d.getCountryCode());
keys.put("countryName", d.getCountryName());
keys.put("zoneCode", d.getZoneCode());
keys.put("zoneName", d.getZoneName());
keys.put("weightMin", d.getWeightMin());
keys.put("weightMax", d.getWeightMax());
keys.put("weightLabel", weightBandOf(d));
return keys;
}
/** Display weight band for sales detail logs (e.g. 0&lt;W≤0.5). */
public static String weightBandOf(PrcPriceSetDetail d)
{
if (d == null)
{
return "";
}
if (StringUtils.isNotEmpty(d.getWeightLabel()))
{
return d.getWeightLabel();
}
if (d.getWeightMin() == null && d.getWeightMax() == null)
{
return "";
}
return stringify(d.getWeightMin()) + "<W\u2264" + stringify(d.getWeightMax());
}
public static void save(IBillSearchStore store, String bizId, String priceKind, String action,
Map<String, Object> bizKeys, List<Map<String, String>> changes)
{
@@ -53,6 +53,11 @@ import com.bms.price.search.PriceChangeEsLog;
import com.bms.price.service.IPrcPriceExcelFileService;
import com.bms.price.service.IPrcPriceSetService;
import com.bms.price.task.PrcPriceSetSaveAsyncRunner;
import com.bms.customer.customerinfo.domain.BmsCustomer;
import com.bms.customer.customerinfo.domain.BmsCustomerPriceSet;
import com.bms.customer.customerinfo.domain.BmsPriceSetOption;
import com.bms.customer.customerinfo.service.IBmsCustomerLogService;
import com.bms.customer.customerinfo.service.IBmsCustomerService;
/**
* 价格套餐 服务层实现
@@ -130,6 +135,12 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
@Autowired
private IBillSearchStore billSearchStore;
@Autowired
private IBmsCustomerLogService customerLogService;
@Autowired
private IBmsCustomerService bmsCustomerService;
@Override
public PrcPriceSet selectPrcPriceSetById(Long priceSetId)
{
@@ -2511,7 +2522,12 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
}
try
{
return customerMapper.insertPrcCustomerPriceSet(customer);
int rows = customerMapper.insertPrcCustomerPriceSet(customer);
if (rows > 0)
{
logCustomerPriceSetBind(null, customer, db);
}
return rows;
}
catch (Exception e)
{
@@ -2610,6 +2626,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
}
validateCustomer(row, db);
customerMapper.updatePrcCustomerPriceSet(row);
logCustomerPriceSetBind(existing, row, db);
replaced++;
}
else
@@ -2630,6 +2647,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
}
throw e;
}
logCustomerPriceSetBind(null, row, db);
inserted++;
}
}
@@ -2657,12 +2675,30 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
assertChildEditable(db);
customer.setPriceSetId(old.getPriceSetId());
validateCustomer(customer, db);
return customerMapper.updatePrcCustomerPriceSet(customer);
int rows = customerMapper.updatePrcCustomerPriceSet(customer);
if (rows > 0)
{
if (customer.getCustomerId() == null)
{
customer.setCustomerId(old.getCustomerId());
}
if (StringUtils.isEmpty(customer.getCustomerCode()))
{
customer.setCustomerCode(old.getCustomerCode());
}
if (StringUtils.isEmpty(customer.getCustomerName()))
{
customer.setCustomerName(old.getCustomerName());
}
logCustomerPriceSetBind(old, customer, db);
}
return rows;
}
@Override
public int deleteCustomerByIds(Long[] customerPricesetIds)
{
List<PrcCustomerPriceSet> snapshots = new ArrayList<PrcCustomerPriceSet>();
for (Long id : customerPricesetIds)
{
PrcCustomerPriceSet old = customerMapper.selectPrcCustomerPriceSetById(id);
@@ -2675,8 +2711,17 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
{
throw new ServiceException(MessageUtils.message("price.set.customer.unbindAudit"));
}
snapshots.add(old);
}
return customerMapper.deletePrcCustomerPriceSetByIds(customerPricesetIds);
int rows = customerMapper.deletePrcCustomerPriceSetByIds(customerPricesetIds);
if (rows > 0)
{
for (PrcCustomerPriceSet snapshot : snapshots)
{
logCustomerPriceSetUnbind(snapshot);
}
}
return rows;
}
private void replaceChildren(PrcPriceSet set)
@@ -2747,6 +2792,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
c.setUpdateBy(set.getUpdateBy());
customerMapper.updatePrcCustomerPriceSet(c);
keepIds.add(hit.getCustomerPricesetId());
logCustomerPriceSetBind(hit, c, set);
}
else
{
@@ -2757,6 +2803,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
{
keepIds.add(c.getCustomerPricesetId());
}
logCustomerPriceSetBind(null, c, set);
}
}
catch (Exception e)
@@ -2778,10 +2825,99 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
}
if (!orphanIds.isEmpty())
{
for (Long orphanId : orphanIds)
{
PrcCustomerPriceSet snapshot = byId.get(orphanId);
if (snapshot != null)
{
logCustomerPriceSetUnbind(snapshot);
}
}
customerMapper.deletePrcCustomerPriceSetByIds(orphanIds.toArray(new Long[0]));
}
}
/** Write customer biz log for package bind / rebind (visible in customer info Logs). */
private void logCustomerPriceSetBind(PrcCustomerPriceSet existing, PrcCustomerPriceSet bind, PrcPriceSet set)
{
if (customerLogService == null || bind == null || set == null)
{
return;
}
BmsCustomer customer = resolveCustomerForLog(bind);
if (customer == null && bind.getCustomerId() != null)
{
customer = new BmsCustomer();
customer.setCustomerId(bind.getCustomerId());
customer.setCustomerCode(bind.getCustomerCode());
customer.setCustomerName(bind.getCustomerName());
}
BmsCustomerPriceSet existingLog = toBmsCustomerPriceSet(existing, resolvePriceSetName(existing));
BmsCustomerPriceSet bindLog = toBmsCustomerPriceSet(bind, set.getPriceSetName());
if (bindLog.getCustomerId() == null && customer != null)
{
bindLog.setCustomerId(customer.getCustomerId());
}
BmsPriceSetOption option = new BmsPriceSetOption();
option.setPriceSetId(set.getPriceSetId());
option.setPriceSetCode(set.getPriceSetCode());
option.setPriceSetName(set.getPriceSetName());
customerLogService.recordPriceSetBind(customer, existingLog, bindLog, option);
}
private void logCustomerPriceSetUnbind(PrcCustomerPriceSet bind)
{
if (customerLogService == null || bind == null)
{
return;
}
BmsCustomerPriceSet snapshot = toBmsCustomerPriceSet(bind, resolvePriceSetName(bind));
customerLogService.recordPriceSetUnbind(snapshot);
}
private BmsCustomer resolveCustomerForLog(PrcCustomerPriceSet bind)
{
if (bind == null || bmsCustomerService == null)
{
return null;
}
if (bind.getCustomerId() != null)
{
return bmsCustomerService.selectBmsCustomerByCustomerId(bind.getCustomerId());
}
return null;
}
private String resolvePriceSetName(PrcCustomerPriceSet bind)
{
if (bind == null || bind.getPriceSetId() == null)
{
return null;
}
PrcPriceSet set = setMapper.selectPrcPriceSetById(bind.getPriceSetId());
return set == null ? null : set.getPriceSetName();
}
private BmsCustomerPriceSet toBmsCustomerPriceSet(PrcCustomerPriceSet src, String priceSetName)
{
if (src == null)
{
return null;
}
BmsCustomerPriceSet dest = new BmsCustomerPriceSet();
dest.setCustomerPricesetId(src.getCustomerPricesetId());
dest.setPriceSetId(src.getPriceSetId());
dest.setCustomerId(src.getCustomerId());
dest.setCustomerCode(src.getCustomerCode());
dest.setCustomerName(src.getCustomerName());
dest.setBindPriority(src.getBindPriority());
dest.setPrBegindate(src.getPrBegindate());
dest.setPrEnddate(src.getPrEnddate());
dest.setPriceSetNote(src.getPriceSetNote());
dest.setPriceSetName(priceSetName);
return dest;
}
private void reportSaveProgress(PrcPriceSet set, int percent, String message)
{
if (set == null || StringUtils.isEmpty(set.getSaveTaskId()) || saveAsyncRunner == null)
@@ -3482,6 +3618,22 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
{
fillVersionChildren(version);
}
// Soft-deleted EFFECT versions for the "deleted" tab (status may still be EFFECT)
PrcPriceSetVersion dq = new PrcPriceSetVersion();
dq.setPriceSetId(priceSetId);
dq.setPriceType(com.bms.price.domain.PriceType.SALES);
dq.setIsDel("1");
List<PrcPriceSetVersion> deleted = versionMapper.selectPrcPriceSetVersionList(dq);
if (deleted != null)
{
for (PrcPriceSetVersion version : deleted)
{
version.setProducts(new ArrayList<PrcPriceSetProduct>());
version.setDetails(new ArrayList<PrcPriceSetDetail>());
version.setDetailCount(Integer.valueOf(detailMapper.countByPsvIdAll(version.getPsvId())));
versions.add(version);
}
}
set.setVersions(versions);
PrcPriceSetVersion current = pickCurrentVersion(versions);
set.setVersion(current);
@@ -3508,14 +3660,23 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
{
return null;
}
PrcPriceSetVersion firstAlive = null;
for (PrcPriceSetVersion v : versions)
{
if (v == null || "1".equals(v.getIsDel()))
{
continue;
}
if (firstAlive == null)
{
firstAlive = v;
}
if (VER_EFFECT.equals(v.getStatus()))
{
return v;
}
}
return versions.get(0);
return firstAlive;
}
private void saveOrUpdateVersion(PrcPriceSet set)
@@ -158,6 +158,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select count(1) from prc_price_set_detail where psv_id = #{psvId} and ifnull(is_del, '0') = '0'
</select>
<select id="countByPsvIdAll" parameterType="Long" resultType="int">
select count(1) from prc_price_set_detail where psv_id = #{psvId}
</select>
<select id="selectDetailOptionRows" resultMap="PrcPriceSetDetailResult">
select distinct product_code, product_name, country_code, country_name, zone_code, zone_name
from prc_price_set_detail
@@ -37,7 +37,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectPrcPriceSetVersionList" parameterType="PrcPriceSetVersion" resultMap="PrcPriceSetVersionResult">
<include refid="selectPrcPriceSetVersionVo"/>
<where>
and ifnull(is_del, '0') = '0'
<choose>
<when test="isDel != null and isDel != ''">
and ifnull(is_del, '0') = #{isDel}
</when>
<otherwise>
and ifnull(is_del, '0') = '0'
</otherwise>
</choose>
<if test="priceSetId != null">
AND price_set_id = #{priceSetId}
</if>