产品列表配置附加费
This commit is contained in:
+38
@@ -18,6 +18,8 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.price.domain.PrcSurcharge;
|
||||
import com.ruoyi.price.domain.PrcSurchargeRel;
|
||||
import com.ruoyi.price.service.IPrcSurchargeRelService;
|
||||
import com.ruoyi.price.service.IPrcSurchargeService;
|
||||
|
||||
/**
|
||||
@@ -32,6 +34,9 @@ public class SurchargeController extends BaseController
|
||||
@Autowired
|
||||
private IPrcSurchargeService surchargeService;
|
||||
|
||||
@Autowired
|
||||
private IPrcSurchargeRelService surchargeRelService;
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('price:surcharge:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(PrcSurcharge surcharge)
|
||||
@@ -48,6 +53,39 @@ public class SurchargeController extends BaseController
|
||||
return success(surchargeService.selectPrcSurchargeById(scId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定产品已关联的附加费(非分页,供产品列表抽屉使用)
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:surcharge:query')")
|
||||
@GetMapping("/byProduct/{productCode}")
|
||||
public AjaxResult listByProduct(@PathVariable String productCode)
|
||||
{
|
||||
return success(surchargeRelService.selectRelByProductCode(productCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定附加费到产品/明细(body: scId, productId, productCode, detailId;detailId 空=产品级)
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:surcharge:add')")
|
||||
@Log(title = "附加费关联", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/rel")
|
||||
public AjaxResult addRel(@RequestBody PrcSurchargeRel rel)
|
||||
{
|
||||
rel.setCreateBy(getUsername());
|
||||
return toAjax(surchargeRelService.insertPrcSurchargeRel(rel));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑(删除关联记录,不删除附加费本身)
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('price:surcharge:remove')")
|
||||
@Log(title = "附加费关联", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/rel/{relIds}")
|
||||
public AjaxResult removeRel(@PathVariable Long[] relIds)
|
||||
{
|
||||
return toAjax(surchargeRelService.deletePrcSurchargeRelByIds(relIds));
|
||||
}
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('price:surcharge:add')")
|
||||
@Log(title = "附加费配置", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
|
||||
@@ -30,6 +30,7 @@ public class BmsProduct extends BaseEntity
|
||||
private String sourceSheet;
|
||||
private Long tmsId;
|
||||
private Integer countryCount;
|
||||
private Integer surchargeCount;
|
||||
private List<BmsProductCountry> countries;
|
||||
/**
|
||||
* 查询用:ACTIVE已生效 / PENDING待生效 / EXPIRED已失效
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.ruoyi.price.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 附加费与产品/明细关联 prc_surcharge_rel
|
||||
* 同时携带附加费展示字段(JOIN prc_surcharge)与明细展示字段(LEFT JOIN bms_product_country),
|
||||
* 便于产品列表抽屉直接渲染。
|
||||
*
|
||||
* 语义:
|
||||
* detail_id 为空 = 产品级附加费(作用于该产品全部明细)
|
||||
* detail_id 有值 = 明细级附加费(作用于该产品某个 国家×重量段 明细)
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PrcSurchargeRel extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long relId;
|
||||
private Long scId;
|
||||
private Long productId;
|
||||
private String productCode;
|
||||
private Long detailId;
|
||||
|
||||
/** 附加费冗余展示字段 */
|
||||
private String scName;
|
||||
private String feeType;
|
||||
private String chargeType;
|
||||
private BigDecimal chargeValue;
|
||||
private String currency;
|
||||
private String roundMode;
|
||||
private String ssCode;
|
||||
private String countryCode;
|
||||
private String scNote;
|
||||
|
||||
/** 明细展示字段 */
|
||||
private String countryName;
|
||||
private BigDecimal weightMin;
|
||||
private BigDecimal weightMax;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.ruoyi.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.price.domain.PrcSurchargeRel;
|
||||
|
||||
/**
|
||||
* 附加费与产品/明细关联 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface PrcSurchargeRelMapper
|
||||
{
|
||||
/**
|
||||
* 查询关联列表(JOIN 附加费 + 明细),支持按 productCode / scId 过滤
|
||||
*/
|
||||
public List<PrcSurchargeRel> selectPrcSurchargeRelList(PrcSurchargeRel rel);
|
||||
|
||||
public int insertPrcSurchargeRel(PrcSurchargeRel rel);
|
||||
|
||||
public int deletePrcSurchargeRelByIds(Long[] relIds);
|
||||
|
||||
/** 删除产品时清理其关联 */
|
||||
public int deleteRelByProductCodes(String[] productCodes);
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.ruoyi.price.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.price.domain.PrcSurchargeRel;
|
||||
|
||||
/**
|
||||
* 附加费与产品/明细关联 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IPrcSurchargeRelService
|
||||
{
|
||||
/** 查询某产品已关联的附加费(含附加费与明细展示字段) */
|
||||
public List<PrcSurchargeRel> selectRelByProductCode(String productCode);
|
||||
|
||||
public List<PrcSurchargeRel> selectPrcSurchargeRelList(PrcSurchargeRel rel);
|
||||
|
||||
public int insertPrcSurchargeRel(PrcSurchargeRel rel);
|
||||
|
||||
public int deletePrcSurchargeRelByIds(Long[] relIds);
|
||||
|
||||
/** 删除产品时清理其关联 */
|
||||
public int deleteRelByProductCodes(String[] productCodes);
|
||||
}
|
||||
+5
@@ -32,6 +32,7 @@ import com.ruoyi.price.domain.BmsProductCountry;
|
||||
import com.ruoyi.price.mapper.BmsProductCountryMapper;
|
||||
import com.ruoyi.price.mapper.BmsProductMapper;
|
||||
import com.ruoyi.price.service.IBmsProductService;
|
||||
import com.ruoyi.price.service.IPrcSurchargeRelService;
|
||||
import com.ruoyi.system.domain.BmsRegion;
|
||||
import com.ruoyi.system.mapper.BmsRegionMapper;
|
||||
|
||||
@@ -64,6 +65,9 @@ public class BmsProductServiceImpl implements IBmsProductService
|
||||
@Autowired
|
||||
private BmsRegionMapper regionMapper;
|
||||
|
||||
@Autowired
|
||||
private IPrcSurchargeRelService surchargeRelService;
|
||||
|
||||
@Override
|
||||
public BmsProduct selectBmsProductById(Long productId)
|
||||
{
|
||||
@@ -116,6 +120,7 @@ public class BmsProductServiceImpl implements IBmsProductService
|
||||
if (!codes.isEmpty())
|
||||
{
|
||||
countryMapper.deleteByProductCodes(codes.toArray(new String[0]));
|
||||
surchargeRelService.deleteRelByProductCodes(codes.toArray(new String[0]));
|
||||
}
|
||||
return productMapper.deleteBmsProductByIds(productIds);
|
||||
}
|
||||
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package com.ruoyi.price.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.price.domain.PrcSurchargeRel;
|
||||
import com.ruoyi.price.mapper.PrcSurchargeRelMapper;
|
||||
import com.ruoyi.price.service.IPrcSurchargeRelService;
|
||||
|
||||
/**
|
||||
* 附加费与产品/明细关联 服务层实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class PrcSurchargeRelServiceImpl implements IPrcSurchargeRelService
|
||||
{
|
||||
@Autowired
|
||||
private PrcSurchargeRelMapper relMapper;
|
||||
|
||||
@Override
|
||||
public List<PrcSurchargeRel> selectRelByProductCode(String productCode)
|
||||
{
|
||||
PrcSurchargeRel query = new PrcSurchargeRel();
|
||||
query.setProductCode(productCode);
|
||||
return relMapper.selectPrcSurchargeRelList(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PrcSurchargeRel> selectPrcSurchargeRelList(PrcSurchargeRel rel)
|
||||
{
|
||||
return relMapper.selectPrcSurchargeRelList(rel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertPrcSurchargeRel(PrcSurchargeRel rel)
|
||||
{
|
||||
validate(rel);
|
||||
return relMapper.insertPrcSurchargeRel(rel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deletePrcSurchargeRelByIds(Long[] relIds)
|
||||
{
|
||||
if (relIds == null || relIds.length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return relMapper.deletePrcSurchargeRelByIds(relIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteRelByProductCodes(String[] productCodes)
|
||||
{
|
||||
if (productCodes == null || productCodes.length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return relMapper.deleteRelByProductCodes(productCodes);
|
||||
}
|
||||
|
||||
private void validate(PrcSurchargeRel rel)
|
||||
{
|
||||
if (rel.getScId() == null)
|
||||
{
|
||||
throw new ServiceException("附加费ID不能为空");
|
||||
}
|
||||
if (rel.getProductId() == null)
|
||||
{
|
||||
throw new ServiceException("产品ID不能为空");
|
||||
}
|
||||
if (StringUtils.isEmpty(rel.getProductCode()))
|
||||
{
|
||||
throw new ServiceException("产品代码不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,13 +23,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="updateBy" column="updated_by" />
|
||||
<result property="updateTime" column="updated_at" />
|
||||
<result property="countryCount" column="country_count" />
|
||||
<result property="surchargeCount" column="surcharge_count" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectBmsProductVo">
|
||||
select p.product_id, p.product_code, p.product_name, p.service_level, p.cargo_attr,
|
||||
p.dest_region, p.update_note, p.tax_mode, p.effective_date, p.status,
|
||||
p.source_sheet, p.remark, p.tms_id, p.created_by, p.created_at, p.updated_by, p.updated_at,
|
||||
(select count(distinct c.country_name) from bms_product_country c where c.product_code = p.product_code) as country_count
|
||||
(select count(distinct c.country_name) from bms_product_country c where c.product_code = p.product_code) as country_count,
|
||||
(select count(*) from prc_surcharge_rel r where r.product_id = p.product_id) as surcharge_count
|
||||
from bms_product p
|
||||
</sql>
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.price.mapper.PrcSurchargeRelMapper">
|
||||
|
||||
<resultMap type="PrcSurchargeRel" id="PrcSurchargeRelResult">
|
||||
<id property="relId" column="rel_id" />
|
||||
<result property="scId" column="sc_id" />
|
||||
<result property="productId" column="product_id" />
|
||||
<result property="productCode" column="product_code" />
|
||||
<result property="detailId" column="detail_id" />
|
||||
<result property="scName" column="sc_name" />
|
||||
<result property="feeType" column="fee_type" />
|
||||
<result property="chargeType" column="charge_type" />
|
||||
<result property="chargeValue" column="charge_value" />
|
||||
<result property="currency" column="currency" />
|
||||
<result property="roundMode" column="round_mode" />
|
||||
<result property="ssCode" column="ss_code" />
|
||||
<result property="countryCode" column="country_code" />
|
||||
<result property="scNote" column="sc_note" />
|
||||
<result property="countryName" column="country_name" />
|
||||
<result property="weightMin" column="weight_min" />
|
||||
<result property="weightMax" column="weight_max" />
|
||||
<result property="createBy" column="created_by" />
|
||||
<result property="createTime" column="created_at" />
|
||||
<result property="updateBy" column="updated_by" />
|
||||
<result property="updateTime" column="updated_at" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectPrcSurchargeRelVo">
|
||||
select r.rel_id, r.sc_id, r.product_id, r.product_code, r.detail_id,
|
||||
r.created_by, r.created_at, r.updated_by, r.updated_at,
|
||||
s.sc_name, s.fee_type, s.charge_type, s.charge_value, s.currency,
|
||||
s.round_mode, s.ss_code, s.country_code, s.sc_note,
|
||||
c.country_name, c.weight_min, c.weight_max
|
||||
from prc_surcharge_rel r
|
||||
join prc_surcharge s on s.sc_id = r.sc_id
|
||||
left join bms_product_country c on c.detail_id = r.detail_id
|
||||
</sql>
|
||||
|
||||
<select id="selectPrcSurchargeRelList" parameterType="PrcSurchargeRel" resultMap="PrcSurchargeRelResult">
|
||||
<include refid="selectPrcSurchargeRelVo"/>
|
||||
<where>
|
||||
<if test="productId != null">
|
||||
AND r.product_id = #{productId}
|
||||
</if>
|
||||
<if test="productCode != null and productCode != ''">
|
||||
AND r.product_code = #{productCode}
|
||||
</if>
|
||||
<if test="scId != null">
|
||||
AND r.sc_id = #{scId}
|
||||
</if>
|
||||
</where>
|
||||
order by r.detail_id is not null, r.rel_id asc
|
||||
</select>
|
||||
|
||||
<insert id="insertPrcSurchargeRel" parameterType="PrcSurchargeRel" useGeneratedKeys="true" keyProperty="relId">
|
||||
insert into prc_surcharge_rel (
|
||||
sc_id, product_id, product_code, detail_id,
|
||||
<if test="createBy != null and createBy != ''">created_by,</if>
|
||||
created_at
|
||||
) values (
|
||||
#{scId}, #{productId}, #{productCode}, #{detailId},
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<delete id="deletePrcSurchargeRelByIds" parameterType="Long">
|
||||
delete from prc_surcharge_rel where rel_id in
|
||||
<foreach item="relId" collection="array" open="(" separator="," close=")">
|
||||
#{relId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRelByProductCodes">
|
||||
delete from prc_surcharge_rel where product_code in
|
||||
<foreach item="code" collection="array" open="(" separator="," close=")">
|
||||
#{code}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,39 @@
|
||||
-- 附加费关联表:维护 prc_surcharge 与 bms_product(产品表) / bms_product_country(明细表) 的关系
|
||||
-- 语义:
|
||||
-- product_id 产品主键(外键关联 bms_product.product_id,与 product_code 一一对应)
|
||||
-- product_code 产品对接代码(便于与明细表 bms_product_country 及前端交互)
|
||||
-- detail_id 为空 = 产品级附加费(作用于该产品全部明细)
|
||||
-- 有值 = 明细级附加费(作用于该产品某个 国家×重量段 明细)
|
||||
-- 一个附加费可关联多个产品/明细;一个产品/明细可挂多个附加费(多对多)
|
||||
-- 执行后即可在「产品列表」按产品/明细维护附加费关联
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS prc_surcharge_rel (
|
||||
rel_id BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '关联ID',
|
||||
sc_id BIGINT(20) NOT NULL COMMENT '附加费配置ID prc_surcharge.sc_id',
|
||||
product_id BIGINT(20) NOT NULL COMMENT '产品ID bms_product.product_id',
|
||||
product_code VARCHAR(20) NOT NULL COMMENT '产品对接代码 bms_product.product_code',
|
||||
detail_id BIGINT(20) DEFAULT NULL COMMENT '产品明细ID bms_product_country.detail_id(空=作用于产品全部明细)',
|
||||
created_by VARCHAR(64) DEFAULT '' COMMENT '创建人',
|
||||
created_at DATETIME DEFAULT NULL COMMENT '创建时间',
|
||||
updated_by VARCHAR(64) DEFAULT '' COMMENT '更新人',
|
||||
updated_at DATETIME DEFAULT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (rel_id),
|
||||
UNIQUE KEY uk_rel_scope (sc_id, product_id, detail_id),
|
||||
INDEX idx_rel_sc (sc_id),
|
||||
INDEX idx_rel_product (product_id),
|
||||
INDEX idx_rel_product_code (product_code),
|
||||
INDEX idx_rel_detail (detail_id),
|
||||
CONSTRAINT fk_rel_sc FOREIGN KEY (sc_id) REFERENCES prc_surcharge (sc_id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_rel_product FOREIGN KEY (product_id) REFERENCES bms_product (product_id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='附加费与产品/明细关联表';
|
||||
|
||||
-- 若已按旧版(无 product_id)建表且已有数据,升级步骤:
|
||||
-- ALTER TABLE prc_surcharge_rel ADD COLUMN product_id BIGINT(20) DEFAULT NULL COMMENT '产品ID' AFTER sc_id;
|
||||
-- UPDATE prc_surcharge_rel r JOIN bms_product p ON p.product_code = r.product_code SET r.product_id = p.product_id;
|
||||
-- ALTER TABLE prc_surcharge_rel MODIFY COLUMN product_id BIGINT(20) NOT NULL COMMENT '产品ID bms_product.product_id';
|
||||
-- ALTER TABLE prc_surcharge_rel ADD INDEX idx_rel_product (product_id);
|
||||
-- ALTER TABLE prc_surcharge_rel ADD CONSTRAINT fk_rel_product FOREIGN KEY (product_id) REFERENCES bms_product (product_id) ON DELETE CASCADE;
|
||||
|
||||
-- 若上一版方案(prc_surcharge 加 product_code 字段)已执行,可手动回退(MySQL 5.7 不支持 DROP COLUMN IF EXISTS):
|
||||
-- ALTER TABLE prc_surcharge DROP COLUMN product_code;
|
||||
Reference in New Issue
Block a user