新增渠道管理
This commit is contained in:
+27
-2
@@ -4,7 +4,7 @@ import java.util.List;
|
||||
import com.bms.masterdata.domain.ServiceChannel;
|
||||
|
||||
/**
|
||||
* 服务渠道镜像 服务层
|
||||
* 服务渠道 服务层
|
||||
*
|
||||
* @author bms
|
||||
* @date 2026-10-12
|
||||
@@ -12,7 +12,32 @@ import com.bms.masterdata.domain.ServiceChannel;
|
||||
public interface IServiceChannelService
|
||||
{
|
||||
/**
|
||||
* 查询服务渠道列表(非分页,供供应商绑定渠道等下拉选择场景)
|
||||
* 查询服务渠道列表(分页由调用方 startPage 控制;下拉场景不传分页)
|
||||
*/
|
||||
List<ServiceChannel> selectServiceChannelList(ServiceChannel query);
|
||||
|
||||
/**
|
||||
* 查询渠道详情
|
||||
*/
|
||||
ServiceChannel selectServiceChannelById(String id);
|
||||
|
||||
/**
|
||||
* 新增渠道
|
||||
*/
|
||||
int insertServiceChannel(ServiceChannel channel);
|
||||
|
||||
/**
|
||||
* 修改渠道
|
||||
*/
|
||||
int updateServiceChannel(ServiceChannel channel);
|
||||
|
||||
/**
|
||||
* 启用或停用渠道(只改 bl_open)
|
||||
*/
|
||||
int updateServiceChannelStatus(ServiceChannel channel);
|
||||
|
||||
/**
|
||||
* 批量删除渠道。已被产品渠道或供应商引用时拒绝删除。
|
||||
*/
|
||||
int deleteServiceChannelByIds(String[] ids);
|
||||
}
|
||||
|
||||
+169
-1
@@ -3,12 +3,15 @@ package com.bms.masterdata.service.impl;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.bms.common.exception.ServiceException;
|
||||
import com.bms.common.utils.StringUtils;
|
||||
import com.bms.common.utils.uuid.IdUtils;
|
||||
import com.bms.masterdata.domain.ServiceChannel;
|
||||
import com.bms.masterdata.mapper.ServiceChannelMapper;
|
||||
import com.bms.masterdata.service.IServiceChannelService;
|
||||
|
||||
/**
|
||||
* 服务渠道镜像 服务实现
|
||||
* 服务渠道 服务实现
|
||||
*
|
||||
* @author bms
|
||||
* @date 2026-10-12
|
||||
@@ -24,4 +27,169 @@ public class ServiceChannelServiceImpl implements IServiceChannelService
|
||||
{
|
||||
return serviceChannelMapper.selectServiceChannelList(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceChannel selectServiceChannelById(String id)
|
||||
{
|
||||
return serviceChannelMapper.selectServiceChannelById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertServiceChannel(ServiceChannel channel)
|
||||
{
|
||||
prepare(channel, true);
|
||||
assertCodeUnique(channel);
|
||||
channel.setId(IdUtils.fastSimpleUUID());
|
||||
if (StringUtils.isEmpty(channel.getDataFrom()))
|
||||
{
|
||||
channel.setDataFrom("BMS");
|
||||
}
|
||||
return serviceChannelMapper.insertServiceChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateServiceChannel(ServiceChannel channel)
|
||||
{
|
||||
if (channel == null || StringUtils.isEmpty(channel.getId()))
|
||||
{
|
||||
throw new ServiceException("渠道ID不能为空");
|
||||
}
|
||||
ServiceChannel existing = serviceChannelMapper.selectServiceChannelById(channel.getId());
|
||||
if (existing == null)
|
||||
{
|
||||
throw new ServiceException("渠道不存在或已被删除");
|
||||
}
|
||||
prepare(channel, false);
|
||||
assertCodeUnique(channel);
|
||||
if (!StringUtils.equals(existing.getChannelCode(), channel.getChannelCode())
|
||||
&& countUsage(existing.getChannelCode()) > 0)
|
||||
{
|
||||
throw new ServiceException("渠道「" + existing.getChannelName() + "」已被产品渠道或供应商引用,不能修改渠道编码");
|
||||
}
|
||||
return serviceChannelMapper.updateServiceChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateServiceChannelStatus(ServiceChannel channel)
|
||||
{
|
||||
if (channel == null || StringUtils.isEmpty(channel.getId()))
|
||||
{
|
||||
throw new ServiceException("渠道ID不能为空");
|
||||
}
|
||||
if (!"0".equals(channel.getBlOpen()) && !"1".equals(channel.getBlOpen()))
|
||||
{
|
||||
throw new ServiceException("启用状态只能是启用或停用");
|
||||
}
|
||||
ServiceChannel existing = serviceChannelMapper.selectServiceChannelById(channel.getId());
|
||||
if (existing == null)
|
||||
{
|
||||
throw new ServiceException("渠道不存在或已被删除");
|
||||
}
|
||||
return serviceChannelMapper.updateServiceChannelStatus(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteServiceChannelByIds(String[] ids)
|
||||
{
|
||||
if (ids == null || ids.length == 0)
|
||||
{
|
||||
throw new ServiceException("请选择要删除的渠道");
|
||||
}
|
||||
for (String id : ids)
|
||||
{
|
||||
if (StringUtils.isEmpty(id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ServiceChannel existing = serviceChannelMapper.selectServiceChannelById(id);
|
||||
if (existing == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (countUsage(existing.getChannelCode()) > 0)
|
||||
{
|
||||
throw new ServiceException("渠道「" + existing.getChannelName() + "」已被产品渠道或供应商引用,不能删除,请改为停用");
|
||||
}
|
||||
}
|
||||
return serviceChannelMapper.deleteServiceChannelByIds(ids);
|
||||
}
|
||||
|
||||
private void prepare(ServiceChannel channel, boolean creating)
|
||||
{
|
||||
if (channel == null)
|
||||
{
|
||||
throw new ServiceException("渠道信息不能为空");
|
||||
}
|
||||
channel.setChannelCode(StringUtils.trim(channel.getChannelCode()));
|
||||
channel.setChannelName(StringUtils.trim(channel.getChannelName()));
|
||||
channel.setServiceCode(trimToNull(channel.getServiceCode()));
|
||||
channel.setServiceName(trimToNull(channel.getServiceName()));
|
||||
channel.setShipperName(trimToNull(channel.getShipperName()));
|
||||
channel.setDesPort(trimToNull(channel.getDesPort()));
|
||||
if (StringUtils.isEmpty(channel.getChannelCode()))
|
||||
{
|
||||
throw new ServiceException("渠道编码不能为空");
|
||||
}
|
||||
if (channel.getChannelCode().length() > 64)
|
||||
{
|
||||
throw new ServiceException("渠道编码不能超过64个字符");
|
||||
}
|
||||
if (StringUtils.isEmpty(channel.getChannelName()))
|
||||
{
|
||||
throw new ServiceException("渠道名称不能为空");
|
||||
}
|
||||
if (channel.getChannelName().length() > 200)
|
||||
{
|
||||
throw new ServiceException("渠道名称不能超过200个字符");
|
||||
}
|
||||
if (StringUtils.isEmpty(channel.getBlOpen()))
|
||||
{
|
||||
if (creating)
|
||||
{
|
||||
channel.setBlOpen("1");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ServiceException("请选择启用状态");
|
||||
}
|
||||
}
|
||||
if (!"0".equals(channel.getBlOpen()) && !"1".equals(channel.getBlOpen()))
|
||||
{
|
||||
throw new ServiceException("启用状态只能是启用或停用");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(channel.getBlMultiple())
|
||||
&& !"0".equals(channel.getBlMultiple()) && !"1".equals(channel.getBlMultiple()))
|
||||
{
|
||||
throw new ServiceException("是否多票只能是是或否");
|
||||
}
|
||||
if (channel.getDimDivisor() != null && channel.getDimDivisor() < 0)
|
||||
{
|
||||
throw new ServiceException("抛货系数不能为负数");
|
||||
}
|
||||
}
|
||||
|
||||
private void assertCodeUnique(ServiceChannel channel)
|
||||
{
|
||||
ServiceChannel same = serviceChannelMapper.selectServiceChannelByCode(channel.getChannelCode());
|
||||
if (same != null && !StringUtils.equals(same.getId(), channel.getId()))
|
||||
{
|
||||
throw new ServiceException("渠道编码「" + channel.getChannelCode() + "」已存在");
|
||||
}
|
||||
}
|
||||
|
||||
private int countUsage(String channelCode)
|
||||
{
|
||||
if (StringUtils.isEmpty(channelCode))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return serviceChannelMapper.countProductChannelByCode(channelCode)
|
||||
+ serviceChannelMapper.countSupplierByChannelCode(channelCode);
|
||||
}
|
||||
|
||||
private String trimToNull(String value)
|
||||
{
|
||||
String text = StringUtils.trim(value);
|
||||
return StringUtils.isEmpty(text) ? null : text;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user