修改附加费操作
This commit is contained in:
+27
-5
@@ -108,20 +108,42 @@ public class SurchargeController extends BaseController
|
||||
return toAjax(surchargeService.insertPrcSurcharge(surcharge));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改(版本化):内容无变化时返回 warn 提示,否则原记录作废 + 插入新记录,产品关联自动重指向新记录。
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:surcharge:edit')")
|
||||
@Log(title = "附加费配置", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody PrcSurcharge surcharge)
|
||||
{
|
||||
surcharge.setUpdateBy(getUsername());
|
||||
return toAjax(surchargeService.updatePrcSurcharge(surcharge));
|
||||
int rows = surchargeService.updatePrcSurcharge(surcharge);
|
||||
if (rows == -1)
|
||||
{
|
||||
return AjaxResult.warn("未做任何修改");
|
||||
}
|
||||
return toAjax(rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停用(原地修改 ss_code=of,不新增数据,不物理删除)。
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:surcharge:remove')")
|
||||
@Log(title = "附加费配置", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{scIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] scIds)
|
||||
@Log(title = "附加费停用", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/disable/{scIds}")
|
||||
public AjaxResult disable(@PathVariable Long[] scIds)
|
||||
{
|
||||
return toAjax(surchargeService.deletePrcSurchargeByIds(scIds));
|
||||
return toAjax(surchargeService.disablePrcSurchargeByIds(scIds, getUsername()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用(原地修改 ss_code=on,不新增数据)。
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:surcharge:remove')")
|
||||
@Log(title = "附加费启用", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/enable/{scIds}")
|
||||
public AjaxResult enable(@PathVariable Long[] scIds)
|
||||
{
|
||||
return toAjax(surchargeService.enablePrcSurchargeByIds(scIds, getUsername()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+8
-1
@@ -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);
|
||||
}
|
||||
|
||||
+112
-14
@@ -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)
|
||||
|
||||
+1
-1
@@ -161,7 +161,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
where d.psv_id = #{psvId}
|
||||
and ifnull(s.sc_name, '') <> ''
|
||||
and s.charge_value is not null
|
||||
and lower(ifnull(s.ss_code, '')) <> 'of'
|
||||
and lower(ifnull(s.ss_code, '')) not in ('of', 'vd')
|
||||
and (r.detail_id is null or r.detail_id = d.product_country_id)
|
||||
and (
|
||||
s.country_code is null or s.country_code = ''
|
||||
|
||||
@@ -48,9 +48,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="roundMode != null and roundMode != ''">
|
||||
AND round_mode = #{roundMode}
|
||||
</if>
|
||||
<if test="ssCode != null and ssCode != ''">
|
||||
AND ss_code = #{ssCode}
|
||||
</if>
|
||||
<choose>
|
||||
<when test="ssCode != null and ssCode != ''">
|
||||
AND lower(ss_code) = lower(#{ssCode})
|
||||
</when>
|
||||
<otherwise>
|
||||
<!-- 默认排除已作废记录,可在状态筛选中选择作废查看历史 -->
|
||||
AND lower(ifnull(ss_code, '')) <> 'vd'
|
||||
</otherwise>
|
||||
</choose>
|
||||
<if test="countryCode != null and countryCode != ''">
|
||||
AND country_code = #{countryCode}
|
||||
</if>
|
||||
@@ -91,30 +97,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updatePrcSurcharge" parameterType="PrcSurcharge">
|
||||
<!-- 状态原地更新(不新增数据):停用置 of,版本化作废旧记录置 vd -->
|
||||
<update id="updateSsCodeByIds">
|
||||
update prc_surcharge
|
||||
<set>
|
||||
<if test="scName != null and scName != ''">sc_name = #{scName},</if>
|
||||
<if test="feeType != null and feeType != ''">fee_type = #{feeType},</if>
|
||||
<if test="chargeType != null and chargeType != ''">charge_type = #{chargeType},</if>
|
||||
<if test="chargeValue != null">charge_value = #{chargeValue},</if>
|
||||
<if test="currency != null and currency != ''">currency = #{currency},</if>
|
||||
<if test="roundMode != null and roundMode != ''">round_mode = #{roundMode},</if>
|
||||
<if test="ssCode != null and ssCode != ''">ss_code = #{ssCode},</if>
|
||||
country_code = #{countryCode},
|
||||
<if test="scNote != null">sc_note = #{scNote},</if>
|
||||
<if test="tmsId != null">tms_id = #{tmsId},</if>
|
||||
<if test="updateBy != null and updateBy != ''">updated_by = #{updateBy},</if>
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
where sc_id = #{scId}
|
||||
</update>
|
||||
|
||||
<delete id="deletePrcSurchargeByIds" parameterType="Long">
|
||||
delete from prc_surcharge where sc_id in
|
||||
<foreach item="scId" collection="array" open="(" separator="," close=")">
|
||||
set ss_code = #{ssCode}, updated_by = #{operator}, update_time = sysdate()
|
||||
where sc_id in
|
||||
<foreach item="scId" collection="scIds" open="(" separator="," close=")">
|
||||
#{scId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -81,4 +81,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- 附加费版本化编辑后,产品关联重指向新记录 -->
|
||||
<update id="rebindRelScId">
|
||||
update prc_surcharge_rel
|
||||
set sc_id = #{newScId}, updated_by = #{operator}, update_time = sysdate()
|
||||
where sc_id = #{oldScId}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user