修改打单套餐功能

This commit is contained in:
wuweihua
2026-11-11 10:12:11 +08:00
parent b6718f9361
commit 02763f092e
12 changed files with 4 additions and 424 deletions
@@ -217,54 +217,6 @@ public class LabelPackageController extends BaseController
return toAjax(payProductService.removeLabelProducts(priceSetId, productIds));
}
@PreAuthorize("@ss.hasPermi('price:label:query')")
@GetMapping("/{priceSetId}/channels")
public AjaxResult listChannels(@PathVariable Long priceSetId)
{
priceSetService.assertSetCategory(priceSetId, PrcPriceSet.CATEGORY_LABEL);
return success(payProductService.listLabelChannels(priceSetId));
}
@PreAuthorize("@ss.hasPermi('price:label:edit')")
@Log(title = "打单套餐绑定渠道", businessType = BusinessType.UPDATE)
@PutMapping("/{priceSetId}/channels")
public AjaxResult bindChannels(@PathVariable Long priceSetId, @RequestBody Map<String, Object> body)
{
priceSetService.assertSetCategory(priceSetId, PrcPriceSet.CATEGORY_LABEL);
List<String> channelIds = new ArrayList<String>();
Object rawIds = body == null ? null : body.get("channelIds");
if (rawIds instanceof List<?>)
{
for (Object item : (List<?>) rawIds)
{
if (item != null && !String.valueOf(item).trim().isEmpty())
{
channelIds.add(String.valueOf(item).trim());
}
}
}
Long productId = null;
Object rawProductId = body == null ? null : body.get("productId");
if (rawProductId instanceof Number)
{
productId = ((Number) rawProductId).longValue();
}
else if (rawProductId != null && !String.valueOf(rawProductId).trim().isEmpty()
&& !"null".equalsIgnoreCase(String.valueOf(rawProductId).trim()))
{
productId = Long.valueOf(String.valueOf(rawProductId).trim());
}
return success(payProductService.bindLabelChannels(priceSetId, channelIds, productId));
}
@PreAuthorize("@ss.hasPermi('price:label:edit')")
@Log(title = "打单套餐解绑渠道", businessType = BusinessType.DELETE)
@DeleteMapping("/{priceSetId}/channels/{channelId}")
public AjaxResult unbindChannel(@PathVariable Long priceSetId, @PathVariable String channelId)
{
priceSetService.assertSetCategory(priceSetId, PrcPriceSet.CATEGORY_LABEL);
return toAjax(payProductService.unbindLabelChannel(priceSetId, channelId));
}
@PreAuthorize("@ss.hasPermi('price:label:list')")
@GetMapping("/customer/list")
@@ -20,9 +20,6 @@ public class ChannelProductMap
private Long productId;
/** 打单套餐 ID,对应 prc_price_set.price_set_id(应收可填) */
private Long priceSetId;
/** 渠道名称(列表回显) */
private String channelName;
@@ -1,24 +1,19 @@
package com.bms.price.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.price.domain.ChannelProductMap;
/**
* 渠道产品关系映射
* Channel-product pay-type mapping.
*/
public interface ChannelProductMapMapper
{
ChannelProductMap selectByChannelAndType(@Param("channelId") String channelId, @Param("payType") String payType);
List<ChannelProductMap> selectByPriceSetId(@Param("priceSetId") Long priceSetId);
int upsert(ChannelProductMap row);
int deleteByChannelAndType(@Param("channelId") String channelId, @Param("payType") String payType);
int deleteByChannelTypeAndPriceSet(@Param("channelId") String channelId, @Param("payType") String payType,
@Param("priceSetId") Long priceSetId);
int deleteByProductId(@Param("productId") Long productId);
}
@@ -17,8 +17,6 @@ public interface PayProductTermMapper
PayProductTerm selectByProductId(Long productId);
/** 打单产品所属套餐 ID */
Long selectLabelPriceSetIdByProduct(@Param("productId") Long productId);
List<PayProductTerm> selectByPriceSetId(@Param("priceSetId") Long priceSetId);
@@ -91,14 +91,6 @@ public interface IPayProductService
/** 从打单套餐移除产品(失效/清理对应 term 明细) */
int removeLabelProducts(Long priceSetId, Long[] productIds);
/** 打单套餐已绑定渠道列表 */
java.util.List<ChannelProductMap> listLabelChannels(Long priceSetId);
/** 打单套餐批量绑定渠道(写 AR + price_set_id) */
String bindLabelChannels(Long priceSetId, java.util.List<String> channelIds, Long productId);
/** 打单套餐解绑渠道 */
int unbindLabelChannel(Long priceSetId, String channelId);
/** 取消渠道上指定收付类型的产品。payType 为空时按应付 AP */
void unbindChannel(String channelId, String payType);
@@ -1056,103 +1056,6 @@ public class PayProductServiceImpl implements IPayProductService
return n;
}
@Override
public List<ChannelProductMap> listLabelChannels(Long priceSetId)
{
if (priceSetId == null)
{
return Collections.emptyList();
}
List<ChannelProductMap> list = channelProductMapMapper.selectByPriceSetId(priceSetId);
return list == null ? Collections.emptyList() : list;
}
@Override
@Transactional(rollbackFor = Exception.class)
public String bindLabelChannels(Long priceSetId, List<String> channelIds, Long productId)
{
if (priceSetId == null)
{
throw new ServiceException("请选择打单套餐");
}
if (channelIds == null || channelIds.isEmpty())
{
throw new ServiceException("请选择要绑定的渠道");
}
if (productId == null)
{
throw new ServiceException("请选择套餐内应收产品");
}
PrcPriceSet set = priceSetMapper.selectPrcPriceSetById(priceSetId);
if (set == null || !PrcPriceSet.CATEGORY_LABEL.equalsIgnoreCase(String.valueOf(set.getSetCategory())))
{
throw new ServiceException("打单套餐不存在");
}
Long root = resolveRoot(productId);
boolean inSet = false;
List<PayProduct> products = selectLabelProducts(priceSetId);
for (PayProduct p : products)
{
if (p != null && root.equals(p.getProductId()))
{
inSet = true;
break;
}
}
if (!inSet)
{
throw new ServiceException("所选产品不属于本打单套餐");
}
String operator = SecurityUtils.getUsername();
int n = 0;
for (String channelId : channelIds)
{
if (isBlank(channelId))
{
continue;
}
ServiceChannel channel = serviceChannelMapper.selectServiceChannelById(channelId.trim());
if (channel == null || isBlank(channel.getChannelCode()))
{
throw new ServiceException("渠道不存在或渠道编码为空:" + channelId);
}
ChannelProductMap row = new ChannelProductMap();
row.setChannelId(channelId.trim());
row.setChannelCode(channel.getChannelCode());
row.setProductId(root);
row.setPriceSetId(priceSetId);
row.setPayType(PAY_TYPE_AR);
row.setCreateBy(operator);
row.setUpdateBy(operator);
channelProductMapMapper.upsert(row);
n++;
}
if (n <= 0)
{
throw new ServiceException("没有可绑定的渠道");
}
return "已绑定 " + n + " 个渠道";
}
@Override
@Transactional(rollbackFor = Exception.class)
public int unbindLabelChannel(Long priceSetId, String channelId)
{
if (priceSetId == null || isBlank(channelId))
{
return 0;
}
return channelProductMapMapper.deleteByChannelTypeAndPriceSet(channelId.trim(), PAY_TYPE_AR, priceSetId);
}
private Long resolveLabelPriceSetId(Long productId)
{
if (productId == null)
{
return null;
}
return payProductTermMapper.selectLabelPriceSetIdByProduct(productId);
}
@Override
public List<PayProduct> selectLabelProducts(Long priceSetId)
@@ -1756,10 +1659,6 @@ public class PayProductServiceImpl implements IPayProductService
row.setChannelCode(channel.getChannelCode());
row.setProductId(storedId);
row.setPayType(type);
if (PAY_TYPE_AR.equals(type))
{
row.setPriceSetId(resolveLabelPriceSetId(storedId));
}
String operator = SecurityUtils.getUsername();
row.setCreateBy(operator);
row.setUpdateBy(operator);
@@ -6,37 +6,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectByChannelAndType" resultType="com.bms.price.domain.ChannelProductMap">
select id, channel_id as channelId, channel_code as channelCode, product_id as productId,
price_set_id as priceSetId, pay_type as payType, create_by as createBy, create_time as createTime,
pay_type as payType, create_by as createBy, create_time as createTime,
update_by as updateBy, update_time as updateTime
from srv_channel_product_map
where channel_id = #{channelId} and pay_type = #{payType}
limit 1
</select>
<select id="selectByPriceSetId" resultType="com.bms.price.domain.ChannelProductMap">
select m.id, m.channel_id as channelId, m.channel_code as channelCode, m.product_id as productId,
m.price_set_id as priceSetId, m.pay_type as payType,
c.channel_name as channelName, p.product_name as productName,
m.create_by as createBy, m.create_time as createTime,
m.update_by as updateBy, m.update_time as updateTime
from srv_channel_product_map m
left join srv_service_channel c on c.id = m.channel_id
left join pay_product p on p.product_id = m.product_id
where m.price_set_id = #{priceSetId}
and m.pay_type = 'AR'
order by m.update_time desc, m.id desc
</select>
<insert id="upsert">
insert into srv_channel_product_map (
channel_id, channel_code, product_id, price_set_id, pay_type, create_by, create_time, update_by, update_time
channel_id, channel_code, product_id, pay_type, create_by, create_time, update_by, update_time
) values (
#{channelId}, #{channelCode}, #{productId}, #{priceSetId}, #{payType}, #{createBy}, sysdate(), #{updateBy}, sysdate()
#{channelId}, #{channelCode}, #{productId}, #{payType}, #{createBy}, sysdate(), #{updateBy}, sysdate()
)
on duplicate key update
channel_code = values(channel_code),
product_id = values(product_id),
price_set_id = values(price_set_id),
update_by = values(update_by),
update_time = sysdate()
</insert>
@@ -46,13 +32,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where channel_id = #{channelId} and pay_type = #{payType}
</delete>
<delete id="deleteByChannelTypeAndPriceSet">
delete from srv_channel_product_map
where channel_id = #{channelId}
and pay_type = #{payType}
and price_set_id = #{priceSetId}
</delete>
<delete id="deleteByProductId">
delete from srv_channel_product_map where product_id = #{productId}
</delete>
@@ -41,15 +41,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
limit 1
</select>
<select id="selectLabelPriceSetIdByProduct" resultType="long">
select price_set_id
from pay_product_term
where product_id = #{productId}
and price_set_id is not null
order by case when status = '1' then 0 when status = '0' then 1 else 2 end, version_no desc, term_id desc
limit 1
</select>
<!-- 打单套餐产品列表:待生效+生效 -->
<select id="selectByPriceSetId" resultType="com.bms.price.domain.PayProductTerm">
select t.term_id as termId, t.dict_value as dictValue, t.product_id as productId, t.price_set_id as priceSetId,
@@ -6,7 +6,6 @@ CREATE TABLE IF NOT EXISTS `srv_channel_product_map` (
`channel_id` varchar(50) NOT NULL COMMENT '渠道ID,对应 srv_service_channel.id',
`channel_code` varchar(64) DEFAULT NULL COMMENT '渠道编码,对应 srv_service_channel.channel_code',
`product_id` bigint(20) NOT NULL COMMENT '产品ID,应付/应收时为价卡产品编号',
`price_set_id` bigint(20) DEFAULT NULL COMMENT '应收套餐ID,对应 prc_price_set.price_set_id',
`pay_type` varchar(10) NOT NULL COMMENT '收付类型,字典 bms_pay_type:AR应收 AP应付',
`create_by` varchar(64) DEFAULT NULL COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
@@ -15,23 +14,9 @@ CREATE TABLE IF NOT EXISTS `srv_channel_product_map` (
PRIMARY KEY (`id`),
UNIQUE KEY `uk_channel_pay_type` (`channel_id`, `pay_type`),
KEY `idx_channel_product_map_product` (`product_id`),
KEY `idx_channel_product_map_price_set` (`price_set_id`),
KEY `idx_channel_product_map_channel_code` (`channel_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='渠道产品关系映射';
SET @sql = (
SELECT IF(
COUNT(*) = 0,
'ALTER TABLE srv_channel_product_map ADD COLUMN price_set_id bigint(20) DEFAULT NULL COMMENT ''应收套餐ID,对应 prc_price_set.price_set_id'' AFTER product_id, ADD KEY idx_channel_product_map_price_set (price_set_id)',
'SELECT 1'
)
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'srv_channel_product_map' AND COLUMN_NAME = 'price_set_id'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql_channel_code = (
SELECT IF(
COUNT(*) = 0,