Compare commits

..

2 Commits

Author SHA1 Message Date
PQZ
743f529c31 Merge branch 'master' of http://122.51.230.86:3000/dianliang/lanan-system 2024-08-07 12:00:52 +08:00
PQZ
0b05d6399b 调整 2024-08-07 12:00:49 +08:00
12 changed files with 146 additions and 28 deletions

View File

@ -7,10 +7,20 @@ package cn.iocoder.yudao.common;
public class BaseConstants { public class BaseConstants {
/**政企客户经办人*/ /**政企客户经办人*/
public static final String CUS_TYPE_CORP_ATTN = "04"; 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_CUSTOMER = "customer";
/**车辆标识*/ /**车辆标识*/
public static final String CUS_SIGN_CAR = "car"; public static final String CUS_SIGN_CAR = "car";
/**客户信息表名称*/ /**客户信息表名称*/
public static final String TABLE_BASE_CUSTOMER_MAIN = "base_customer_main"; 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 = "政企客户";
} }

View File

@ -21,7 +21,7 @@ import javax.validation.Valid;
import java.util.List; 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; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
/** /**
@ -72,7 +72,7 @@ public class CustomerMainController {
@Operation(summary = "创建客户管理") @Operation(summary = "创建客户管理")
@PreAuthorize("@ss.hasPermission('base:customer-main:create')") @PreAuthorize("@ss.hasPermission('base:customer-main:create')")
public CommonResult<Boolean> createCustomerMain(@Valid @RequestBody CustomerMainSaveReqVO saveReqVO) { public CommonResult<Boolean> createCustomerMain(@Valid @RequestBody CustomerMainSaveReqVO saveReqVO) {
customerMainService.saveCustomer(saveReqVO); customerMainService.saveCustomer(saveReqVO,SIGN_CREATE);
return success(true); return success(true);
} }
@ -88,7 +88,7 @@ public class CustomerMainController {
@Operation(summary = "更新客户管理") @Operation(summary = "更新客户管理")
@PreAuthorize("@ss.hasPermission('base:customer-main:update')") @PreAuthorize("@ss.hasPermission('base:customer-main:update')")
public CommonResult<Boolean> updateCustomerMain(@Valid @RequestBody CustomerMainSaveReqVO saveReqVO) { public CommonResult<Boolean> updateCustomerMain(@Valid @RequestBody CustomerMainSaveReqVO saveReqVO) {
customerMainService.saveCustomer(saveReqVO); customerMainService.saveCustomer(saveReqVO,SIGN_UPDATE);
return success(true); return success(true);
} }

View File

@ -33,7 +33,7 @@ public class CustomerMain extends TenantBaseDO {
/** /**
* sys_user表id * sys_user表id
*/ */
private String userId; private Long userId;
/** /**
* 用户类型 * 用户类型
*/ */
@ -42,7 +42,7 @@ public class CustomerMain extends TenantBaseDO {
/** /**
* 所属企业code部门表code * 所属企业code部门表code
*/ */
private String deptCode; private Long deptCode;
/** /**
* 客户名称政企客户填企业名称 * 客户名称政企客户填企业名称
*/ */

View File

@ -33,11 +33,12 @@ public interface CustomerMainService extends IService<CustomerMain> {
* 保存客户信息 * 保存客户信息
* *
* @param saveReqVO 保存客户信息扩展实体 * @param saveReqVO 保存客户信息扩展实体
* @param sign 标识(新增客户created/编辑客户update)
* @return void * @return void
* @author PQZ * @author PQZ
* @date 15:46 2024/8/1 * @date 15:46 2024/8/1
**/ **/
void saveCustomer(CustomerMainSaveReqVO saveReqVO); void saveCustomer(CustomerMainSaveReqVO saveReqVO, String sign);
/** /**
* 根据客户id查询客户信息 * 根据客户id查询客户信息

View File

@ -1,17 +1,16 @@
package cn.iocoder.yudao.module.custom.service.impl; package cn.iocoder.yudao.module.custom.service.impl;
import cn.hutool.json.JSONUtil; 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.ServiceException;
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; 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.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.CustomerCar;
import cn.iocoder.yudao.module.custom.entity.CustomerItem; import cn.iocoder.yudao.module.custom.entity.CustomerItem;
import cn.iocoder.yudao.module.custom.entity.CustomerMain; 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.CustomerCarMapper;
import cn.iocoder.yudao.module.custom.mapper.CustomerMainMapper; 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.CustomerCarService;
import cn.iocoder.yudao.module.custom.service.CustomerItemService; import cn.iocoder.yudao.module.custom.service.CustomerItemService;
import cn.iocoder.yudao.module.custom.service.CustomerMainService; 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.custom.vo.CustomerMainSaveReqVO;
import cn.iocoder.yudao.module.label.entity.BusiLabel; import cn.iocoder.yudao.module.label.entity.BusiLabel;
import cn.iocoder.yudao.module.label.service.BusiLabelService; 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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.UUID;
import static cn.iocoder.yudao.common.BaseConstants.CUS_SIGN_CUSTOMER; import static cn.iocoder.yudao.common.BaseConstants.*;
import static cn.iocoder.yudao.common.BaseConstants.CUS_TYPE_CORP_ATTN; import static cn.iocoder.yudao.common.DictBaseConstants.DICT_CUS_TYPE;
/** /**
* 客户管理 Service 实现类 * 客户管理 Service 实现类
@ -55,9 +62,16 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
@Resource @Resource
private CustomerCarMapper customerCarMapper; private CustomerCarMapper customerCarMapper;
@Resource @Resource
private CarMainMapper carMainMapper;
@Resource
private BusiLabelService busiLabelService; 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 saveReqVO 保存客户信息扩展实体
* @param sign 标识(新增客户created/编辑客户update)
* @return void * @return void
* @author PQZ * @author PQZ
* @date 15:46 2024/8/1 * @date 15:46 2024/8/1
**/ **/
@Override @Override
@Transactional(rollbackFor = Exception.class) @DSTransactional
public void saveCustomer(CustomerMainSaveReqVO saveReqVO) { public void saveCustomer(CustomerMainSaveReqVO saveReqVO, String sign) {
try { try {
/*1、保存主表信息*/ /*1、入参及基础参数值设置*/
CustomerMain main = JSONUtil.toBean(JSONUtil.parseObj(saveReqVO).toJSONString(0), CustomerMain.class); CustomerMain main = JSONUtil.toBean(JSONUtil.parseObj(saveReqVO).toJSONString(0), CustomerMain.class);
//新增情况下非政企客户经办人deptCode设置为id方便分组查询 Long userId;
if (null == main.getId() && !CUS_TYPE_CORP_ATTN.equals(main.getTypeCode())) { UserDTO user;
String id = String.valueOf(UUID.randomUUID()); /*2、新增客户时绑定绑定客户信息*/
main.setId(id); if (SIGN_CREATE.equals(sign)){
main.setDeptCode(id); //查询数据字典根据客户类型匹配出预设角色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); this.saveOrUpdate(main);
/*2、保存扩展表信息*/ /*4、保存扩展表信息*/
if (!saveReqVO.getItemList().isEmpty()) { if (!saveReqVO.getItemList().isEmpty()) {
customerItemService.saveCutomItem(main.getId(), saveReqVO.getItemList()); customerItemService.saveCutomItem(main.getId(), saveReqVO.getItemList());
} }
@ -156,11 +211,11 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
* @date 18:42 2024/8/3 * @date 18:42 2024/8/3
**/ **/
@Override @Override
@Transactional(rollbackFor = Exception.class) @DSTransactional
public void bindCustomAndCar(CustomerMainSaveReqVO saveReqVO) { public void bindCustomAndCar(CustomerMainSaveReqVO saveReqVO) {
List<CustomerCar> customerCars = new ArrayList<>(); List<CustomerCar> customerCars = new ArrayList<>();
List<CarMainRespVO> carList = saveReqVO.getCarList(); List<CarMainRespVO> carList = saveReqVO.getCarList();
if (null != carList){ if (null != carList) {
//组装数据 //组装数据
carList.forEach(item -> { carList.forEach(item -> {
CustomerCar customerCar = new CustomerCar(); CustomerCar customerCar = new CustomerCar();
@ -170,6 +225,6 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
customerCars.add(customerCar); customerCars.add(customerCar);
}); });
} }
customerCarService.bindCustomerCar(saveReqVO.getId(),CUS_SIGN_CUSTOMER,customerCars); customerCarService.bindCustomerCar(saveReqVO.getId(), CUS_SIGN_CUSTOMER, customerCars);
} }
} }

View File

@ -11,6 +11,7 @@
--> -->
<resultMap id="CustomerMainMap" type="cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO"> <resultMap id="CustomerMainMap" type="cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO">
<id column="id" property="id"/> <id column="id" property="id"/>
<id column="deptCode" property="deptCode"/>
<collection select="getAttn" property="attnList" javaType="list" <collection select="getAttn" property="attnList" javaType="list"
column="deptCode" column="deptCode"
ofType="cn.iocoder.yudao.module.custom.entity.CustomerMain"> ofType="cn.iocoder.yudao.module.custom.entity.CustomerMain">

View File

@ -54,6 +54,15 @@ public interface DeptApi {
*/ */
DeptRespDTO getDeptByParentIdAndName(Long parentId,String name); 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);
/** /**
* 获得部门信息数组 * 获得部门信息数组
* *

View File

@ -29,5 +29,7 @@ public class DictDataRespDTO {
* 枚举 {@link CommonStatusEnum} * 枚举 {@link CommonStatusEnum}
*/ */
private Integer status; private Integer status;
/**备注*/
private String remark;
} }

View File

@ -80,6 +80,20 @@ public class DeptApiImpl implements DeptApi {
return BeanUtils.toBean(dept, DeptRespDTO.class); 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 @Override
public List<DeptRespDTO> getDeptList(Collection<Long> ids) { public List<DeptRespDTO> getDeptList(Collection<Long> ids) {
List<DeptDO> depts = deptService.getDeptList(ids); List<DeptDO> depts = deptService.getDeptList(ids);

View File

@ -22,6 +22,10 @@ public interface DeptMapper extends BaseMapperX<DeptDO> {
return selectOne(DeptDO::getParentId, parentId, DeptDO::getName, name); return selectOne(DeptDO::getParentId, parentId, DeptDO::getName, name);
} }
default DeptDO selectByDeptName(String name) {
return selectOne( DeptDO::getName, name);
}
default DeptDO selectByParentId(Long parentId) { default DeptDO selectByParentId(Long parentId) {
return selectOne(DeptDO::getParentId, parentId); return selectOne(DeptDO::getParentId, parentId);
} }

View File

@ -70,6 +70,15 @@ public interface DeptService {
*/ */
DeptDO getDeptByParentIdAndName(Long parentId,String name); 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);
/** /**
* 获得部门信息数组 * 获得部门信息数组
* *

View File

@ -193,6 +193,19 @@ public class DeptServiceImpl implements DeptService {
return deptMapper.selectByParentIdAndName(parentId, name); 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 @Override
public List<DeptDO> getDeptList(Collection<Long> ids) { public List<DeptDO> getDeptList(Collection<Long> ids) {