客户编辑添加绑定套餐

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,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);
}
}