客户编辑添加绑定套餐

This commit is contained in:
luojiaquan
2026-09-16 17:06:50 +08:00
parent b1ceae4776
commit 6fbb9049bf
9 changed files with 761 additions and 0 deletions
@@ -0,0 +1,78 @@
package com.ruoyi.web.controller.customer.customerinfo;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.customer.customerinfo.domain.BmsCustomerPriceSet;
import com.ruoyi.customer.customerinfo.domain.BmsPriceSetOption;
import com.ruoyi.customer.customerinfo.service.IBmsCustomerPriceSetService;
/**
* 客户套餐绑定Controller(客户管理-客户编辑-绑定套餐)
*
* @author ruoyi
* @date 2026-09-16
*/
@RestController
@RequestMapping("/customersupplier/customerinfo/priceset")
public class BmsCustomerPriceSetController extends BaseController
{
@Autowired
private IBmsCustomerPriceSetService customerPriceSetService;
/**
* 查询客户已绑定的套餐列表
*/
@PreAuthorize("@ss.hasPermi('customersupplier:customerinfo:list')")
@GetMapping("/bind/list")
public AjaxResult bindList(Long customerId)
{
List<BmsCustomerPriceSet> list = customerPriceSetService.selectBindList(customerId);
return success(list);
}
/**
* 查询可绑定的生效套餐选项
*/
@PreAuthorize("@ss.hasPermi('customersupplier:customerinfo:list')")
@GetMapping("/option/list")
public AjaxResult optionList(BmsPriceSetOption query)
{
return success(customerPriceSetService.selectOptionList(query));
}
/**
* 保存客户套餐绑定(已绑定则更新/更换套餐,未绑定则新增)
*/
@PreAuthorize("@ss.hasPermi('customersupplier:customerinfo:edit')")
@Log(title = "客户套餐绑定", businessType = BusinessType.INSERT)
@PostMapping("/bind")
public AjaxResult saveBind(@RequestBody BmsCustomerPriceSet bind)
{
bind.setCreateBy(getUsername());
bind.setUpdateBy(getUsername());
return toAjax(customerPriceSetService.saveBind(bind));
}
/**
* 解绑客户套餐
*/
@PreAuthorize("@ss.hasPermi('customersupplier:customerinfo:edit')")
@Log(title = "客户套餐解绑", businessType = BusinessType.DELETE)
@DeleteMapping("/bind/{customerPricesetIds}")
public AjaxResult removeBind(@PathVariable Long[] customerPricesetIds)
{
return toAjax(customerPriceSetService.deleteBindByIds(customerPricesetIds));
}
}
@@ -0,0 +1,72 @@
package com.ruoyi.customer.customerinfo.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 客户套餐绑定对象 prc_customer_price_set
* 客户管理-客户编辑-绑定套餐 使用;关联 prc_price_set 的字段仅用于页面展示
*
* @author ruoyi
* @date 2026-09-16
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class BmsCustomerPriceSet extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 客户价格套餐ID */
private Long customerPricesetId;
/** 价格套餐ID */
private Long priceSetId;
/** 客户ID */
private Long customerId;
/** 客户代码 */
private String customerCode;
/** 客户名称 */
private String customerName;
/** 绑定优先级,数字越小越优先 */
private Integer bindPriority;
/** 价格开始生效日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
private Date prBegindate;
/** 价格失效日期(空=长期) */
@JsonFormat(pattern = "yyyy-MM-dd")
private Date prEnddate;
/** 绑定备注 */
private String priceSetNote;
/* -------- 关联 prc_price_set 展示字段 -------- */
/** 套餐编码 */
private String priceSetCode;
/** 套餐名称 */
private String priceSetName;
/** 计价类型 FIXED=固定价 DISCOUNT=折扣 */
private String setType;
/** 套餐状态 D草稿 A审核中 E生效 R驳回 S停用 */
private String priceSetStatus;
/** 套餐生效日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
private Date setEffectiveDate;
/** 套餐失效日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
private Date setExpireDate;
}
@@ -0,0 +1,42 @@
package com.ruoyi.customer.customerinfo.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
/**
* 价格套餐(prc_price_set)简要对象
* 仅用于客户编辑-绑定套餐的套餐下拉选择,不参与套餐维护
*
* @author ruoyi
* @date 2026-09-16
*/
@Data
public class BmsPriceSetOption
{
/** 价格套餐ID */
private Long priceSetId;
/** 套餐编码 */
private String priceSetCode;
/** 套餐名称 */
private String priceSetName;
/** 计价类型 FIXED=固定价 DISCOUNT=折扣 */
private String setType;
/** 套餐状态 D草稿 A审核中 E生效 R驳回 S停用 */
private String status;
/** 生效日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
private Date effectiveDate;
/** 失效日期(空=长期) */
@JsonFormat(pattern = "yyyy-MM-dd")
private Date expireDate;
/** 关键字(编码/名称模糊) */
private String keyword;
}
@@ -0,0 +1,39 @@
package com.ruoyi.customer.customerinfo.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.customer.customerinfo.domain.BmsCustomerPriceSet;
import com.ruoyi.customer.customerinfo.domain.BmsPriceSetOption;
/**
* 客户套餐绑定 数据层(客户管理侧独立实现,操作 prc_customer_price_set)
*
* @author ruoyi
* @date 2026-09-16
*/
public interface BmsCustomerPriceSetMapper
{
/** 按客户查绑定列表(join prc_price_set 取套餐展示字段) */
public List<BmsCustomerPriceSet> selectBindListByCustomerId(@Param("customerId") Long customerId);
/** 按主键查绑定 */
public BmsCustomerPriceSet selectBindById(Long customerPricesetId);
/** 按客户ID查绑定(uk_customer_one_set 保证至多一条) */
public BmsCustomerPriceSet selectBindByCustomerId(@Param("customerId") Long customerId);
/** 新增绑定 */
public int insertBind(BmsCustomerPriceSet bind);
/** 更新绑定(允许更换套餐 price_set_id 与生效区间/优先级/备注) */
public int updateBind(BmsCustomerPriceSet bind);
/** 按主键批量解绑 */
public int deleteBindByIds(Long[] customerPricesetIds);
/** 套餐下拉选项(只列生效中套餐,可按关键字/类型过滤) */
public List<BmsPriceSetOption> selectPriceSetOptionList(BmsPriceSetOption query);
/** 按主键查套餐简要信息 */
public BmsPriceSetOption selectPriceSetOptionById(@Param("priceSetId") Long priceSetId);
}
@@ -0,0 +1,28 @@
package com.ruoyi.customer.customerinfo.service;
import java.util.List;
import com.ruoyi.customer.customerinfo.domain.BmsCustomerPriceSet;
import com.ruoyi.customer.customerinfo.domain.BmsPriceSetOption;
/**
* 客户套餐绑定 服务层(客户管理侧)
*
* @author ruoyi
* @date 2026-09-16
*/
public interface IBmsCustomerPriceSetService
{
/** 查询某客户的套餐绑定列表 */
public List<BmsCustomerPriceSet> selectBindList(Long customerId);
/** 查询可绑定的生效套餐选项 */
public List<BmsPriceSetOption> selectOptionList(BmsPriceSetOption query);
/**
* 保存客户套餐绑定(一个客户一条记录):已绑定则更新(支持更换套餐),未绑定则新增
*/
public int saveBind(BmsCustomerPriceSet bind);
/** 按绑定主键解绑 */
public int deleteBindByIds(Long[] customerPricesetIds);
}
@@ -0,0 +1,116 @@
package com.ruoyi.customer.customerinfo.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.customer.customerinfo.domain.BmsCustomer;
import com.ruoyi.customer.customerinfo.domain.BmsCustomerPriceSet;
import com.ruoyi.customer.customerinfo.domain.BmsPriceSetOption;
import com.ruoyi.customer.customerinfo.mapper.BmsCustomerPriceSetMapper;
import com.ruoyi.customer.customerinfo.service.IBmsCustomerPriceSetService;
import com.ruoyi.customer.customerinfo.service.IBmsCustomerService;
/**
* 客户套餐绑定 服务实现(客户管理侧,独立于价格套餐维护模块)
*
* @author ruoyi
* @date 2026-09-16
*/
@Service
public class BmsCustomerPriceSetServiceImpl implements IBmsCustomerPriceSetService
{
@Autowired
private BmsCustomerPriceSetMapper bindMapper;
@Autowired
private IBmsCustomerService customerService;
@Override
public List<BmsCustomerPriceSet> selectBindList(Long customerId)
{
if (customerId == null)
{
return List.of();
}
return bindMapper.selectBindListByCustomerId(customerId);
}
@Override
public List<BmsPriceSetOption> selectOptionList(BmsPriceSetOption query)
{
return bindMapper.selectPriceSetOptionList(query);
}
@Override
public int saveBind(BmsCustomerPriceSet bind)
{
if (bind.getCustomerId() == null)
{
throw new ServiceException("客户ID不能为空");
}
if (bind.getPriceSetId() == null)
{
throw new ServiceException("请选择要绑定的套餐");
}
BmsCustomer customer = customerService.selectBmsCustomerByCustomerId(bind.getCustomerId());
if (customer == null)
{
throw new ServiceException("客户不存在或已被删除");
}
BmsPriceSetOption set = bindMapper.selectPriceSetOptionById(bind.getPriceSetId());
if (set == null)
{
throw new ServiceException("所选套餐不存在");
}
if (!"E".equals(set.getStatus()))
{
throw new ServiceException("仅生效中的套餐允许绑定,当前套餐状态不可用");
}
if (bind.getPrBegindate() == null)
{
bind.setPrBegindate(set.getEffectiveDate());
}
if (bind.getPrBegindate() == null)
{
throw new ServiceException("绑定生效日期不能为空");
}
if (bind.getPrEnddate() != null && bind.getPrBegindate().after(bind.getPrEnddate()))
{
throw new ServiceException("失效日期不能早于生效日期");
}
if (bind.getBindPriority() == null || bind.getBindPriority() < 1)
{
bind.setBindPriority(1);
}
bind.setCustomerCode(customer.getCustomerCode());
bind.setCustomerName(customer.getCustomerName());
BmsCustomerPriceSet existing = bindMapper.selectBindByCustomerId(bind.getCustomerId());
try
{
if (existing != null)
{
bind.setCustomerPricesetId(existing.getCustomerPricesetId());
return bindMapper.updateBind(bind);
}
return bindMapper.insertBind(bind);
}
catch (DuplicateKeyException e)
{
throw new ServiceException("该客户已存在套餐绑定,请勿重复绑定");
}
}
@Override
public int deleteBindByIds(Long[] customerPricesetIds)
{
if (customerPricesetIds == null || customerPricesetIds.length == 0)
{
throw new ServiceException("请选择要解绑的记录");
}
return bindMapper.deleteBindByIds(customerPricesetIds);
}
}
@@ -0,0 +1,128 @@
<?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.customer.customerinfo.mapper.BmsCustomerPriceSetMapper">
<resultMap type="com.ruoyi.customer.customerinfo.domain.BmsCustomerPriceSet" id="BmsCustomerPriceSetResult">
<id property="customerPricesetId" column="customer_priceset_id" />
<result property="priceSetId" column="price_set_id" />
<result property="customerId" column="customer_id" />
<result property="customerCode" column="customer_code" />
<result property="customerName" column="customer_name" />
<result property="bindPriority" column="bind_priority" />
<result property="prBegindate" column="pr_begindate" />
<result property="prEnddate" column="pr_enddate" />
<result property="priceSetNote" column="price_set_note" />
<result property="createBy" column="created_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="updated_by" />
<result property="updateTime" column="update_time" />
<result property="priceSetCode" column="price_set_code" />
<result property="priceSetName" column="price_set_name" />
<result property="setType" column="set_type" />
<result property="priceSetStatus" column="price_set_status" />
<result property="setEffectiveDate" column="set_effective_date" />
<result property="setExpireDate" column="set_expire_date" />
</resultMap>
<resultMap type="com.ruoyi.customer.customerinfo.domain.BmsPriceSetOption" id="BmsPriceSetOptionResult">
<id property="priceSetId" column="price_set_id" />
<result property="priceSetCode" column="price_set_code" />
<result property="priceSetName" column="price_set_name" />
<result property="setType" column="set_type" />
<result property="status" column="status" />
<result property="effectiveDate" column="effective_date" />
<result property="expireDate" column="expire_date" />
</resultMap>
<sql id="bindVo">
select c.customer_priceset_id, c.price_set_id, c.customer_id, c.customer_code, c.customer_name,
c.bind_priority, c.pr_begindate, c.pr_enddate, c.price_set_note,
c.created_by, c.create_time, c.updated_by, c.update_time,
s.price_set_code, s.price_set_name, s.set_type,
s.status as price_set_status,
s.effective_date as set_effective_date, s.expire_date as set_expire_date
from prc_customer_price_set c
left join prc_price_set s on s.price_set_id = c.price_set_id
</sql>
<select id="selectBindListByCustomerId" resultMap="BmsCustomerPriceSetResult">
<include refid="bindVo"/>
where c.customer_id = #{customerId}
order by c.bind_priority asc, c.customer_priceset_id asc
</select>
<select id="selectBindById" parameterType="Long" resultMap="BmsCustomerPriceSetResult">
<include refid="bindVo"/>
where c.customer_priceset_id = #{customerPricesetId}
</select>
<select id="selectBindByCustomerId" resultMap="BmsCustomerPriceSetResult">
select customer_priceset_id, price_set_id, customer_id, customer_code, customer_name,
bind_priority, pr_begindate, pr_enddate, price_set_note,
created_by, create_time, updated_by, update_time
from prc_customer_price_set
where customer_id = #{customerId}
limit 1
</select>
<insert id="insertBind" parameterType="com.ruoyi.customer.customerinfo.domain.BmsCustomerPriceSet"
useGeneratedKeys="true" keyProperty="customerPricesetId">
insert into prc_customer_price_set (
price_set_id, customer_id, customer_code, customer_name,
bind_priority, pr_begindate, pr_enddate, price_set_note,
created_by, create_time
) values (
#{priceSetId}, #{customerId}, #{customerCode}, #{customerName},
#{bindPriority}, #{prBegindate}, #{prEnddate}, #{priceSetNote},
#{createBy}, sysdate()
)
</insert>
<update id="updateBind" parameterType="com.ruoyi.customer.customerinfo.domain.BmsCustomerPriceSet">
update prc_customer_price_set
set price_set_id = #{priceSetId},
customer_code = #{customerCode},
customer_name = #{customerName},
bind_priority = #{bindPriority},
pr_begindate = #{prBegindate},
pr_enddate = #{prEnddate},
price_set_note = #{priceSetNote},
updated_by = #{updateBy},
update_time = sysdate()
where customer_priceset_id = #{customerPricesetId}
</update>
<delete id="deleteBindByIds" parameterType="Long">
delete from prc_customer_price_set where customer_priceset_id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="selectPriceSetOptionList"
parameterType="com.ruoyi.customer.customerinfo.domain.BmsPriceSetOption"
resultMap="BmsPriceSetOptionResult">
select price_set_id, price_set_code, price_set_name, set_type, status, effective_date, expire_date
from prc_price_set
<where>
status = 'E'
<if test="setType != null and setType != ''">
and set_type = #{setType}
</if>
<if test="keyword != null and keyword != ''">
and (price_set_code like concat('%', #{keyword}, '%')
or price_set_name like concat('%', #{keyword}, '%'))
</if>
</where>
order by price_set_id desc
</select>
<select id="selectPriceSetOptionById" resultMap="BmsPriceSetOptionResult">
select price_set_id, price_set_code, price_set_name, set_type, status, effective_date, expire_date
from prc_price_set
where price_set_id = #{priceSetId}
</select>
</mapper>