Compare commits
2 Commits
f6b29d08e8
...
743f529c31
Author | SHA1 | Date | |
---|---|---|---|
|
743f529c31 | ||
|
0b05d6399b |
@ -7,10 +7,20 @@ package cn.iocoder.yudao.common;
|
||||
public class BaseConstants {
|
||||
/**政企客户经办人*/
|
||||
public static final String CUS_TYPE_CORP_ATTN = "04";
|
||||
/**政企客户*/
|
||||
public static final String CUS_TYPE_CORP = "03";
|
||||
/**客户标识*/
|
||||
public static final String CUS_SIGN_CUSTOMER = "customer";
|
||||
/**车辆标识*/
|
||||
public static final String CUS_SIGN_CAR = "car";
|
||||
/**客户信息表名称*/
|
||||
public static final String TABLE_BASE_CUSTOMER_MAIN = "base_customer_main";
|
||||
/**新增标识*/
|
||||
public static final String SIGN_CREATE = "create";
|
||||
/**编辑标识*/
|
||||
public static final String SIGN_UPDATE = "update";
|
||||
/**默认密码*/
|
||||
public static final String PASSWORD_DEFAULT = "123456";
|
||||
/**租户下部门名称*/
|
||||
public static final String DEPT_NAME_CORP_NAME = "政企客户";
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import javax.validation.Valid;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.common.BaseConstants.TABLE_BASE_CUSTOMER_MAIN;
|
||||
import static cn.iocoder.yudao.common.BaseConstants.*;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
@ -72,7 +72,7 @@ public class CustomerMainController {
|
||||
@Operation(summary = "创建客户管理")
|
||||
@PreAuthorize("@ss.hasPermission('base:customer-main:create')")
|
||||
public CommonResult<Boolean> createCustomerMain(@Valid @RequestBody CustomerMainSaveReqVO saveReqVO) {
|
||||
customerMainService.saveCustomer(saveReqVO);
|
||||
customerMainService.saveCustomer(saveReqVO,SIGN_CREATE);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ public class CustomerMainController {
|
||||
@Operation(summary = "更新客户管理")
|
||||
@PreAuthorize("@ss.hasPermission('base:customer-main:update')")
|
||||
public CommonResult<Boolean> updateCustomerMain(@Valid @RequestBody CustomerMainSaveReqVO saveReqVO) {
|
||||
customerMainService.saveCustomer(saveReqVO);
|
||||
customerMainService.saveCustomer(saveReqVO,SIGN_UPDATE);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class CustomerMain extends TenantBaseDO {
|
||||
/**
|
||||
* sys_user表id
|
||||
*/
|
||||
private String userId;
|
||||
private Long userId;
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
@ -42,7 +42,7 @@ public class CustomerMain extends TenantBaseDO {
|
||||
/**
|
||||
* 所属企业code(部门表code)
|
||||
*/
|
||||
private String deptCode;
|
||||
private Long deptCode;
|
||||
/**
|
||||
* 客户名称(政企客户填企业名称)
|
||||
*/
|
||||
|
@ -33,11 +33,12 @@ public interface CustomerMainService extends IService<CustomerMain> {
|
||||
* 保存客户信息
|
||||
*
|
||||
* @param saveReqVO 保存客户信息扩展实体
|
||||
* @param sign 标识(新增客户created/编辑客户update)
|
||||
* @return void
|
||||
* @author PQZ
|
||||
* @date 15:46 2024/8/1
|
||||
**/
|
||||
void saveCustomer(CustomerMainSaveReqVO saveReqVO);
|
||||
void saveCustomer(CustomerMainSaveReqVO saveReqVO, String sign);
|
||||
|
||||
/**
|
||||
* 根据客户id查询客户信息
|
||||
|
@ -1,17 +1,16 @@
|
||||
package cn.iocoder.yudao.module.custom.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.custom.entity.CarMain;
|
||||
import cn.iocoder.yudao.module.custom.entity.CustomerCar;
|
||||
import cn.iocoder.yudao.module.custom.entity.CustomerItem;
|
||||
import cn.iocoder.yudao.module.custom.entity.CustomerMain;
|
||||
import cn.iocoder.yudao.module.custom.mapper.CarMainMapper;
|
||||
import cn.iocoder.yudao.module.custom.mapper.CustomerCarMapper;
|
||||
import cn.iocoder.yudao.module.custom.mapper.CustomerMainMapper;
|
||||
import cn.iocoder.yudao.module.custom.service.CarMainService;
|
||||
import cn.iocoder.yudao.module.custom.service.CustomerCarService;
|
||||
import cn.iocoder.yudao.module.custom.service.CustomerItemService;
|
||||
import cn.iocoder.yudao.module.custom.service.CustomerMainService;
|
||||
@ -21,21 +20,29 @@ import cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO;
|
||||
import cn.iocoder.yudao.module.custom.vo.CustomerMainSaveReqVO;
|
||||
import cn.iocoder.yudao.module.label.entity.BusiLabel;
|
||||
import cn.iocoder.yudao.module.label.service.BusiLabelService;
|
||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
|
||||
import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
|
||||
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.common.BaseConstants.CUS_SIGN_CUSTOMER;
|
||||
import static cn.iocoder.yudao.common.BaseConstants.CUS_TYPE_CORP_ATTN;
|
||||
import static cn.iocoder.yudao.common.BaseConstants.*;
|
||||
import static cn.iocoder.yudao.common.DictBaseConstants.DICT_CUS_TYPE;
|
||||
|
||||
/**
|
||||
* 客户管理 Service 实现类
|
||||
@ -55,9 +62,16 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
|
||||
@Resource
|
||||
private CustomerCarMapper customerCarMapper;
|
||||
@Resource
|
||||
private CarMainMapper carMainMapper;
|
||||
@Resource
|
||||
private BusiLabelService busiLabelService;
|
||||
@Resource
|
||||
private DictDataApi dictDataApi;
|
||||
@Resource
|
||||
@Lazy
|
||||
private AdminUserApi adminUserApi;
|
||||
@Resource
|
||||
private PermissionApi permissionApi;
|
||||
@Resource
|
||||
private DeptApi deptApi;
|
||||
|
||||
/**
|
||||
* 客户管理分页列表查询
|
||||
@ -77,24 +91,65 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
|
||||
* 保存客户信息
|
||||
*
|
||||
* @param saveReqVO 保存客户信息扩展实体
|
||||
* @param sign 标识(新增客户created/编辑客户update)
|
||||
* @return void
|
||||
* @author PQZ
|
||||
* @date 15:46 2024/8/1
|
||||
**/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveCustomer(CustomerMainSaveReqVO saveReqVO) {
|
||||
@DSTransactional
|
||||
public void saveCustomer(CustomerMainSaveReqVO saveReqVO, String sign) {
|
||||
try {
|
||||
/*1、保存主表信息*/
|
||||
/*1、入参及基础参数值设置*/
|
||||
CustomerMain main = JSONUtil.toBean(JSONUtil.parseObj(saveReqVO).toJSONString(0), CustomerMain.class);
|
||||
//新增情况下,非政企客户经办人,deptCode设置为id,方便分组查询
|
||||
if (null == main.getId() && !CUS_TYPE_CORP_ATTN.equals(main.getTypeCode())) {
|
||||
String id = String.valueOf(UUID.randomUUID());
|
||||
main.setId(id);
|
||||
main.setDeptCode(id);
|
||||
Long userId;
|
||||
UserDTO user;
|
||||
/*2、新增客户时绑定绑定客户信息*/
|
||||
if (SIGN_CREATE.equals(sign)){
|
||||
//查询数据字典,根据客户类型匹配出预设角色code;
|
||||
DictDataRespDTO dict = dictDataApi.getDictData(DICT_CUS_TYPE, main.getTypeCode());
|
||||
AdminUserRespDTO userDTO = adminUserApi.getUserByUsername(saveReqVO.getPhoneNumber());
|
||||
user = BeanUtils.toBean(userDTO, UserDTO.class);
|
||||
//存在两种情况,一是该用户已经注册,二是该用户未注册
|
||||
if (null == user){
|
||||
user = new UserDTO();
|
||||
//如果不存在创建用户;
|
||||
user.setUsername(saveReqVO.getPhoneNumber());
|
||||
user.setNickname(saveReqVO.getCusName());
|
||||
//默认密码
|
||||
user.setPassword(PASSWORD_DEFAULT);
|
||||
user.setMobile(saveReqVO.getPhoneNumber());
|
||||
//该用户未注册情况下,如果是政企客户,需要在部门表中创建部门,并给用户绑定
|
||||
if (CUS_TYPE_CORP.equals(main.getTypeCode())) {
|
||||
//查询当前登录用户所属租户的政企客户部门id(父级部门)
|
||||
DeptRespDTO parentDept = deptApi.getDeptByName(DEPT_NAME_CORP_NAME);
|
||||
//在部门表下新增一个部门
|
||||
DeptRespDTO deptRespDTO = new DeptRespDTO();
|
||||
deptRespDTO.setName(saveReqVO.getCusName());
|
||||
deptRespDTO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
//上级部门为本租户顶级部门
|
||||
deptRespDTO.setParentId(parentDept.getId());
|
||||
Long deptId = deptApi.saveDept(deptRespDTO);
|
||||
//为用户绑定deptId
|
||||
user.setDeptId(deptId);
|
||||
//客户信息表绑定deptCode
|
||||
main.setDeptCode(deptId);
|
||||
}
|
||||
//创建客户
|
||||
userId = adminUserApi.createUser(user);
|
||||
} else {
|
||||
userId = user.getId();
|
||||
}
|
||||
//客户表绑定用户id
|
||||
main.setUserId(userId);
|
||||
//绑定角色
|
||||
Set<String> roleCodes = new HashSet<>();
|
||||
roleCodes.add(dict.getRemark());
|
||||
permissionApi.assignUserRole(userId, roleCodes);
|
||||
}
|
||||
/*3、保存客户主表信息*/
|
||||
this.saveOrUpdate(main);
|
||||
/*2、保存扩展表信息*/
|
||||
/*4、保存扩展表信息*/
|
||||
if (!saveReqVO.getItemList().isEmpty()) {
|
||||
customerItemService.saveCutomItem(main.getId(), saveReqVO.getItemList());
|
||||
}
|
||||
@ -156,7 +211,7 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
|
||||
* @date 18:42 2024/8/3
|
||||
**/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@DSTransactional
|
||||
public void bindCustomAndCar(CustomerMainSaveReqVO saveReqVO) {
|
||||
List<CustomerCar> customerCars = new ArrayList<>();
|
||||
List<CarMainRespVO> carList = saveReqVO.getCarList();
|
||||
|
@ -11,6 +11,7 @@
|
||||
-->
|
||||
<resultMap id="CustomerMainMap" type="cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO">
|
||||
<id column="id" property="id"/>
|
||||
<id column="deptCode" property="deptCode"/>
|
||||
<collection select="getAttn" property="attnList" javaType="list"
|
||||
column="deptCode"
|
||||
ofType="cn.iocoder.yudao.module.custom.entity.CustomerMain">
|
||||
|
@ -54,6 +54,15 @@ public interface DeptApi {
|
||||
*/
|
||||
DeptRespDTO getDeptByParentIdAndName(Long parentId,String name);
|
||||
|
||||
/**
|
||||
* 查询部门名称是xx的部门
|
||||
* @author PQZ
|
||||
* @date 10:49 2024/8/7
|
||||
* @param name 部门名称
|
||||
* @return cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO
|
||||
**/
|
||||
DeptRespDTO getDeptByName(String name);
|
||||
|
||||
/**
|
||||
* 获得部门信息数组
|
||||
*
|
||||
|
@ -29,5 +29,7 @@ public class DictDataRespDTO {
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
/**备注*/
|
||||
private String remark;
|
||||
|
||||
}
|
||||
|
@ -80,6 +80,20 @@ public class DeptApiImpl implements DeptApi {
|
||||
return BeanUtils.toBean(dept, DeptRespDTO.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询部门名称是xx的部门
|
||||
*
|
||||
* @param name 部门名称
|
||||
* @return cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO
|
||||
* @author PQZ
|
||||
* @date 10:49 2024/8/7
|
||||
**/
|
||||
@Override
|
||||
public DeptRespDTO getDeptByName(String name) {
|
||||
DeptDO dept = deptService.selectDeptByName(name);
|
||||
return BeanUtils.toBean(dept, DeptRespDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptRespDTO> getDeptList(Collection<Long> ids) {
|
||||
List<DeptDO> depts = deptService.getDeptList(ids);
|
||||
|
@ -22,6 +22,10 @@ public interface DeptMapper extends BaseMapperX<DeptDO> {
|
||||
return selectOne(DeptDO::getParentId, parentId, DeptDO::getName, name);
|
||||
}
|
||||
|
||||
default DeptDO selectByDeptName(String name) {
|
||||
return selectOne( DeptDO::getName, name);
|
||||
}
|
||||
|
||||
default DeptDO selectByParentId(Long parentId) {
|
||||
return selectOne(DeptDO::getParentId, parentId);
|
||||
}
|
||||
|
@ -70,6 +70,15 @@ public interface DeptService {
|
||||
*/
|
||||
DeptDO getDeptByParentIdAndName(Long parentId,String name);
|
||||
|
||||
/**
|
||||
* 根据部门名称查询部门
|
||||
* @author PQZ
|
||||
* @date 10:51 2024/8/7
|
||||
* @param name 部门名称
|
||||
* @return cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO
|
||||
**/
|
||||
DeptDO selectDeptByName(String name);
|
||||
|
||||
/**
|
||||
* 获得部门信息数组
|
||||
*
|
||||
|
@ -193,6 +193,19 @@ public class DeptServiceImpl implements DeptService {
|
||||
return deptMapper.selectByParentIdAndName(parentId, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门名称查询部门
|
||||
*
|
||||
* @param name 部门名称
|
||||
* @return cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO
|
||||
* @author PQZ
|
||||
* @date 10:51 2024/8/7
|
||||
**/
|
||||
@Override
|
||||
public DeptDO selectDeptByName(String name) {
|
||||
return deptMapper.selectByDeptName(name);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<DeptDO> getDeptList(Collection<Long> ids) {
|
||||
|
Loading…
Reference in New Issue
Block a user