修改附加费操作

This commit is contained in:
wuweihua
2026-09-22 10:15:17 +08:00
parent 33a29e32c1
commit ba81700463
14 changed files with 397 additions and 98 deletions
@@ -1,11 +1,14 @@
package com.ruoyi.price.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.price.domain.PrcSurcharge;
/**
* 附加费配置 数据层
*
* 附加费为计费主数据:不做物理修改/删除,编辑=作废旧记录插入新记录,删除=仅作废。
*
* @author ruoyi
*/
public interface PrcSurchargeMapper
@@ -16,7 +19,6 @@ public interface PrcSurchargeMapper
public int insertPrcSurcharge(PrcSurcharge surcharge);
public int updatePrcSurcharge(PrcSurcharge surcharge);
public int deletePrcSurchargeByIds(Long[] scIds);
/** 状态原地更新(不新增数据):停用置 of,版本化作废旧记录置 vd */
public int updateSsCodeByIds(@Param("scIds") Long[] scIds, @Param("ssCode") String ssCode, @Param("operator") String operator);
}
@@ -1,6 +1,7 @@
package com.ruoyi.price.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.price.domain.PrcSurchargeRel;
/**
@@ -21,4 +22,7 @@ public interface PrcSurchargeRelMapper
/** 删除产品时清理其关联 */
public int deleteRelByProductCodes(String[] productCodes);
/** 附加费版本化编辑后,把产品关联从旧记录重指向新记录 */
public int rebindRelScId(@Param("oldScId") Long oldScId, @Param("newScId") Long newScId, @Param("operator") String operator);
}
@@ -6,6 +6,8 @@ import com.ruoyi.price.domain.PrcSurcharge;
/**
* 附加费配置 服务层
*
* 附加费为计费主数据:编辑=原记录作废+插入新记录(版本化),删除=仅作废不物理删除。
*
* @author ruoyi
*/
public interface IPrcSurchargeService
@@ -16,7 +18,12 @@ public interface IPrcSurchargeService
public int insertPrcSurcharge(PrcSurcharge surcharge);
/** 版本化更新:原记录作废(ss_code=vd),插入新记录,产品关联重指向新记录;状态继承原记录 */
public int updatePrcSurcharge(PrcSurcharge surcharge);
public int deletePrcSurchargeByIds(Long[] scIds);
/** 停用(原地修改 ss_code=of,不新增数据) */
public int disablePrcSurchargeByIds(Long[] scIds, String operator);
/** 启用(原地修改 ss_code=on,不新增数据) */
public int enablePrcSurchargeByIds(Long[] scIds, String operator);
}
@@ -3,24 +3,36 @@ package com.ruoyi.price.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.price.domain.PrcSurcharge;
import com.ruoyi.price.mapper.PrcSurchargeMapper;
import com.ruoyi.price.mapper.PrcSurchargeRelMapper;
import com.ruoyi.price.service.IPrcSurchargeService;
/**
* 附加费配置 服务层实现
*
* 附加费为计费主数据,不做物理修改/删除:
* - 编辑 = 原记录作废(ss_code=vd)+ 插入新记录(状态继承),产品关联重指向新记录(保留变更历史)
* - 停用 = 原地修改 ss_code=of,不新增数据
*
* @author ruoyi
*/
@Service
public class PrcSurchargeServiceImpl implements IPrcSurchargeService
{
/** 作废状态:区别于启用(on)/停用(of),列表默认不显示 */
public static final String SS_CODE_VOID = "vd";
@Autowired
private PrcSurchargeMapper surchargeMapper;
@Autowired
private PrcSurchargeRelMapper surchargeRelMapper;
@Override
public PrcSurcharge selectPrcSurchargeById(Long scId)
{
@@ -37,6 +49,106 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
public int insertPrcSurcharge(PrcSurcharge surcharge)
{
validate(surcharge);
applyInsertDefaults(surcharge);
return surchargeMapper.insertPrcSurcharge(surcharge);
}
/**
* 版本化更新:内容无变化时返回 -1(不产生新版本),否则原记录作废 + 插入新记录 + 产品关联重指向。
*/
@Override
@Transactional
public int updatePrcSurcharge(PrcSurcharge surcharge)
{
validate(surcharge);
PrcSurcharge old = surchargeMapper.selectPrcSurchargeById(surcharge.getScId());
if (old == null)
{
throw new ServiceException("附加费不存在或已被作废,无法修改");
}
// 无实际变化:不置作废、不插新记录,返回 -1 由 Controller 提示"未修改"
if (isUnchanged(old, surcharge))
{
return -1;
}
String operator = StringUtils.isNotEmpty(surcharge.getUpdateBy()) ? surcharge.getUpdateBy() : surcharge.getCreateBy();
// 1. 原记录作废(保留历史)
surchargeMapper.updateSsCodeByIds(new Long[] { surcharge.getScId() }, SS_CODE_VOID, operator);
// 2. 按表单内容插入新记录(状态继承原记录,状态变更只能走列表停用操作)
PrcSurcharge fresh = new PrcSurcharge();
fresh.setScName(surcharge.getScName());
fresh.setFeeType(StringUtils.isNotEmpty(surcharge.getFeeType()) ? surcharge.getFeeType() : old.getFeeType());
fresh.setChargeType(surcharge.getChargeType());
fresh.setChargeValue(surcharge.getChargeValue());
fresh.setCurrency(surcharge.getCurrency());
fresh.setRoundMode(surcharge.getRoundMode());
fresh.setSsCode(old.getSsCode());
fresh.setCountryCode(surcharge.getCountryCode());
fresh.setScNote(surcharge.getScNote());
applyInsertDefaults(fresh);
fresh.setCreateBy(operator);
int rows = surchargeMapper.insertPrcSurcharge(fresh);
// 3. 产品关联重指向新记录,保持产品附加费配置不失效
surchargeRelMapper.rebindRelScId(surcharge.getScId(), fresh.getScId(), operator);
return rows;
}
/** 逐字段比对编辑内容与原记录是否一致(字符串 trim 后比较,数值统一 BigDecimal 比较) */
private boolean isUnchanged(PrcSurcharge old, PrcSurcharge updated)
{
return eq(old.getScName(), updated.getScName())
&& eq(old.getFeeType(), updated.getFeeType())
&& eq(old.getChargeType(), updated.getChargeType())
&& eqDecimal(old.getChargeValue(), updated.getChargeValue())
&& eq(old.getCurrency(), updated.getCurrency())
&& eq(old.getRoundMode(), updated.getRoundMode())
&& eq(old.getCountryCode(), updated.getCountryCode())
&& eq(old.getScNote(), updated.getScNote());
}
private boolean eq(String a, String b)
{
String sa = a == null ? "" : a.trim();
String sb = b == null ? "" : b.trim();
return sa.equals(sb);
}
private boolean eqDecimal(java.math.BigDecimal a, java.math.BigDecimal b)
{
if (a == null && b == null) return true;
if (a == null || b == null) return false;
return a.compareTo(b) == 0;
}
/**
* 停用(原地修改 ss_code=of,不新增数据、不动产品关联)。
*/
@Override
public int disablePrcSurchargeByIds(Long[] scIds, String operator)
{
return updateStatusByIds(scIds, "of", operator);
}
/**
* 启用(原地修改 ss_code=on,不新增数据)。
*/
@Override
public int enablePrcSurchargeByIds(Long[] scIds, String operator)
{
return updateStatusByIds(scIds, "on", operator);
}
private int updateStatusByIds(Long[] scIds, String ssCode, String operator)
{
if (scIds == null || scIds.length == 0)
{
return 0;
}
return surchargeMapper.updateSsCodeByIds(scIds, ssCode, operator);
}
private void applyInsertDefaults(PrcSurcharge surcharge)
{
if (StringUtils.isEmpty(surcharge.getSsCode()))
{
surcharge.setSsCode("on");
@@ -49,20 +161,6 @@ public class PrcSurchargeServiceImpl implements IPrcSurchargeService
{
surcharge.setRoundMode("HALF_UP");
}
return surchargeMapper.insertPrcSurcharge(surcharge);
}
@Override
public int updatePrcSurcharge(PrcSurcharge surcharge)
{
validate(surcharge);
return surchargeMapper.updatePrcSurcharge(surcharge);
}
@Override
public int deletePrcSurchargeByIds(Long[] scIds)
{
return surchargeMapper.deletePrcSurchargeByIds(scIds);
}
private void validate(PrcSurcharge surcharge)