增加基础模块-业务渠道和来源
This commit is contained in:
parent
17be414b84
commit
79c5ac04d4
@ -0,0 +1,93 @@
|
|||||||
|
package cn.iocoder.yudao.module.business.controller.admin;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.module.business.entity.DlBusinessChannel;
|
||||||
|
import cn.iocoder.yudao.module.business.service.BusinessChannelService;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/business")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BusinessChannelController {
|
||||||
|
|
||||||
|
private final BusinessChannelService businessChannelService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 许
|
||||||
|
* @Description 获取客户来源和业务渠道
|
||||||
|
* @Date 13:54 2025/9/8
|
||||||
|
* @Param [channel]
|
||||||
|
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<java.util.List<cn.iocoder.yudao.module.business.entity.DlBusinessChannel>>
|
||||||
|
**/
|
||||||
|
@GetMapping("/list")
|
||||||
|
public CommonResult<List<DlBusinessChannel>> list(DlBusinessChannel channel) {
|
||||||
|
return CommonResult.success(businessChannelService.list(Wrappers.<DlBusinessChannel>lambdaQuery()
|
||||||
|
.eq(ObjectUtil.isNotEmpty(channel.getType()), DlBusinessChannel::getType, channel.getType())
|
||||||
|
.like(ObjectUtil.isNotEmpty(channel.getName()), DlBusinessChannel::getName, channel.getName())
|
||||||
|
.orderByAsc(DlBusinessChannel::getSort)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增业务渠道或客户来源
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
public boolean addChannel(@RequestBody DlBusinessChannel channel) {
|
||||||
|
if (ObjectUtil.isNotEmpty(channel.getUserIdList())) {
|
||||||
|
String userIds = channel.getUserIdList().stream()
|
||||||
|
.map(String::valueOf)
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
channel.setUserIds(userIds);
|
||||||
|
|
||||||
|
}
|
||||||
|
return businessChannelService.save(channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取业务渠道或客户来源
|
||||||
|
*/
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public CommonResult<DlBusinessChannel> getChannelById(@PathVariable("id") Long id) {
|
||||||
|
DlBusinessChannel info = businessChannelService.getById(id);
|
||||||
|
|
||||||
|
//将字符串转为集合
|
||||||
|
if (ObjectUtil.isNotEmpty(info.getUserIds())) {
|
||||||
|
List<Long> userIdList = Arrays.stream(info.getUserIds().split(","))
|
||||||
|
.filter(s -> s != null && !s.isEmpty()) // 可选:避免空字符串
|
||||||
|
.map(Long::valueOf)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
info.setUserIdList(userIdList);
|
||||||
|
}
|
||||||
|
return CommonResult.success(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改业务渠道或客户来源
|
||||||
|
*/
|
||||||
|
@PutMapping("/update")
|
||||||
|
public CommonResult<?> updateChannel(@RequestBody DlBusinessChannel channel) {
|
||||||
|
if (ObjectUtil.isNotEmpty(channel.getUserIdList())) {
|
||||||
|
String userIds = channel.getUserIdList().stream()
|
||||||
|
.map(String::valueOf)
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
channel.setUserIds(userIds);
|
||||||
|
}else if (ObjectUtil.isEmpty(channel.getUserIds())) {
|
||||||
|
channel.setUserIds("");
|
||||||
|
}
|
||||||
|
return CommonResult.success(businessChannelService.updateById(channel));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除业务渠道或客户来源
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
public CommonResult<?> deleteChannel(@PathVariable("id") Long id) {
|
||||||
|
return CommonResult.success(businessChannelService.removeById(id));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package cn.iocoder.yudao.module.business.entity;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("inspection_business_channel")
|
||||||
|
public class DlBusinessChannel extends TenantBaseDO {
|
||||||
|
|
||||||
|
private Integer id; // 主键ID
|
||||||
|
|
||||||
|
private Integer pid; // 父ID
|
||||||
|
|
||||||
|
private String name; // 名称
|
||||||
|
|
||||||
|
private Integer type; // 0-业务渠道 1-客户来源
|
||||||
|
|
||||||
|
private String userIds; // 绑定的用户ID
|
||||||
|
|
||||||
|
private Integer sort; // 排序
|
||||||
|
|
||||||
|
private String systemCode; // 系统标识
|
||||||
|
|
||||||
|
// 子节点
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<DlBusinessChannel> children;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<Long> userIdList;
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package cn.iocoder.yudao.module.business.mapper;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.business.entity.DlBusinessChannel;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface BusinessChannelMapper extends BaseMapper<DlBusinessChannel> {
|
||||||
|
/**
|
||||||
|
* 获取业务渠道 和 客户来源
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
DlBusinessChannel getBusinessChannelByUserId(Long userId);
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package cn.iocoder.yudao.module.business.service;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.business.entity.DlBusinessChannel;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface BusinessChannelService extends IService<DlBusinessChannel> {
|
||||||
|
/**
|
||||||
|
* 获取业务渠道和客户来源
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Map<String, Object> getBusinessChannelByUserId(Long userId);
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package cn.iocoder.yudao.module.business.service.impl;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.module.business.entity.DlBusinessChannel;
|
||||||
|
import cn.iocoder.yudao.module.business.mapper.BusinessChannelMapper;
|
||||||
|
import cn.iocoder.yudao.module.business.service.BusinessChannelService;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class BusinessChannelServiceImpl extends ServiceImpl<BusinessChannelMapper, DlBusinessChannel> implements BusinessChannelService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取业务渠道和客户来源
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getBusinessChannelByUserId(Long userId) {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
// 客户来源
|
||||||
|
DlBusinessChannel channel = baseMapper.getBusinessChannelByUserId(userId);
|
||||||
|
if (channel == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
map.put("channel", channel);
|
||||||
|
// 根据客户来源的父id查询业务渠道
|
||||||
|
DlBusinessChannel business = getOne(Wrappers.<DlBusinessChannel>lambdaQuery()
|
||||||
|
.eq(DlBusinessChannel::getId, channel.getPid()));
|
||||||
|
if (business != null) {
|
||||||
|
map.put("business", business);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -21,6 +21,8 @@ public class InspectionBusinessChannel extends TenantBaseDO {
|
|||||||
|
|
||||||
private Integer sort; // 排序
|
private Integer sort; // 排序
|
||||||
|
|
||||||
|
private String systemCode; // 系统编码
|
||||||
|
|
||||||
// 子节点
|
// 子节点
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private List<InspectionBusinessChannel> children;
|
private List<InspectionBusinessChannel> children;
|
||||||
|
Loading…
Reference in New Issue
Block a user