This commit is contained in:
xiao-fajia 2024-08-07 15:54:44 +08:00
commit 3e73aa8ab9
19 changed files with 248 additions and 73 deletions

View File

@ -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 = "政企客户";
}

View File

@ -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);
}

View File

@ -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;
/**
* 客户名称政企客户填企业名称
*/

View File

@ -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查询客户信息

View File

@ -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,11 +211,11 @@ 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();
if (null != carList){
if (null != carList) {
//组装数据
carList.forEach(item -> {
CustomerCar customerCar = new CustomerCar();
@ -170,6 +225,6 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
customerCars.add(customerCar);
});
}
customerCarService.bindCustomerCar(saveReqVO.getId(),CUS_SIGN_CUSTOMER,customerCars);
customerCarService.bindCustomerCar(saveReqVO.getId(), CUS_SIGN_CUSTOMER, customerCars);
}
}

View File

@ -37,5 +37,7 @@ public class Label extends TenantBaseDO {
private String systemCode;
/**标签样式*/
private String labelType;
/**分类*/
private String type;
}

View File

@ -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">
@ -51,10 +52,7 @@
AND item.system_code = #{entity.systemCode}
</if>
<if test="entity.phoneNumber != null and entity.phoneNumber != ''">
AND main.phoneNumber LIKE concat('%',#{entity.phoneNumber},'%')
</if>
<if test="entity.idCard != null and entity.idCard != ''">
AND main.idCard LIKE concat('%',#{entity.idCard},'%')
AND main.phone_number LIKE concat('%',#{entity.phoneNumber},'%')
</if>
</where>
GROUP BY main.id

View File

@ -12,6 +12,9 @@
<if test="entity.labelName != null and entity.cusName != ''">
AND label_name LIKE concat('%',#{entity.labelName},'%')
</if>
<if test="entity.type != null and entity.type != ''">
AND type = #{entity.type}
</if>
</where>
</select>
</mapper>

79
pom.xml
View File

@ -15,7 +15,7 @@
<module>yudao-module-infra</module>
<!-- <module>yudao-module-member</module>-->
<module>yudao-module-bpm</module>
<!-- <module>yudao-module-report</module>-->
<module>yudao-module-report</module>
<!-- <module>yudao-module-mp</module>-->
<!-- <module>yudao-module-pay</module>-->
<!-- <module>yudao-module-mall</module>-->
@ -136,36 +136,51 @@
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>aliyun</id>
<name>aliyun Repository</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- 积木报表部分依赖需要从jeecg仓库中下载 -->
<repository>
<id>jeecg</id>
<name>jeecg Repository</name>
<url>http://maven.jeecg.org/nexus/content/repositories/jeecg</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- 使用 huawei / aliyun 的 Maven 源,提升下载速度 -->
<repository>
<id>huaweicloud</id>
<name>huawei</name>
<url>https://mirrors.huaweicloud.com/repository/maven/</url>
</repository>
<repository>
<id>aliyunmaven</id>
<name>aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
</repository>
<!-- 使用 huawei / aliyun 的 Maven 源,提升下载速度 -->
<!-- <repositories>-->
<!-- <repository>-->
<!-- <id>huaweicloud</id>-->
<!-- <name>huawei</name>-->
<!-- <url>https://mirrors.huaweicloud.com/repository/maven/</url>-->
<!-- </repository>-->
<!-- <repository>-->
<!-- <id>aliyunmaven</id>-->
<!-- <name>aliyun</name>-->
<!-- <url>https://maven.aliyun.com/repository/public</url>-->
<!-- </repository>-->
<!-- <repository>-->
<!-- <id>spring-milestones</id>-->
<!-- <name>Spring Milestones</name>-->
<!-- <url>https://repo.spring.io/milestone</url>-->
<!-- <snapshots>-->
<!-- <enabled>false</enabled>-->
<!-- </snapshots>-->
<!-- </repository>-->
<!-- <repository>-->
<!-- <id>spring-snapshots</id>-->
<!-- <name>Spring Snapshots</name>-->
<!-- <url>https://repo.spring.io/snapshot</url>-->
<!-- <releases>-->
<!-- <enabled>false</enabled>-->
<!-- </releases>-->
<!-- </repository>-->
<!-- </repositories>-->
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
</project>

View File

@ -63,6 +63,7 @@
<dependency>
<groupId>org.jeecgframework.jimureport</groupId>
<artifactId>jimureport-spring-boot-starter</artifactId>
<!-- <version>1.4.0</version>-->
</dependency>
<!-- 单独依赖升级版本解决低版本validator失败问题 -->
<dependency>

View File

@ -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);
/**
* 获得部门信息数组
*

View File

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

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.system.enums.common;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 性别的枚举值
*
* @author 芋道源码
*/
@Getter
@AllArgsConstructor
public enum DeptEnum {
/** 私人客户 */
PRIVATE_CUS("私人客户"),
/** 代办客户 */
AGENT_CUS("代办客户"),
/** 政企客户 */
GOV_CUS("政企客户");
/**
* 名称
*/
private final String name;
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
/**
* 获得部门信息数组
*

View File

@ -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) {

View File

@ -51,6 +51,7 @@ import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.system.enums.common.DeptEnum.*;
import static java.util.Collections.singleton;
/**
@ -131,7 +132,11 @@ public class TenantServiceImpl implements TenantService {
// 修改租户的管理员
tenantMapper.updateById(new TenantDO().setId(tenant.getId()).setContactUserId(userId));
//创建租户顶级部门
Long deptId = createDept(userId,createReqVO.getName(),createReqVO.getContactMobile());
Long deptId = createDept(userId,createReqVO.getName(),createReqVO.getContactMobile(),null);
//创建三个客户部门私人客户代办客户政企客户
createDept(null,PRIVATE_CUS.getName(),null,deptId);
createDept(null,AGENT_CUS.getName(),null,deptId);
createDept(null,GOV_CUS.getName(),null,deptId);
//拉取本租户配置的服务套餐对应的角色和权限存入本租户对应信息
createServiceRole(createReqVO.getPackageId());
});
@ -158,13 +163,20 @@ public class TenantServiceImpl implements TenantService {
}
}
private Long createDept(Long userId,String deptName,String phone){
private Long createDept(Long userId,String deptName,String phone,Long parentId){
DeptSaveReqVO deptSaveReqVO = new DeptSaveReqVO();
deptSaveReqVO.setName(deptName);
deptSaveReqVO.setSort(0);
deptSaveReqVO.setPhone(phone);
deptSaveReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
deptSaveReqVO.setLeaderUserId(userId);
if(null!=phone){
deptSaveReqVO.setPhone(phone);
}
if(null!=userId){
deptSaveReqVO.setLeaderUserId(userId);
}
if(null!=parentId){
deptSaveReqVO.setParentId(parentId);
}
return deptService.createDept(deptSaveReqVO);
}

View File

@ -51,11 +51,11 @@
<!-- </dependency>-->
<!-- 数据报表。默认注释,保证编译速度 -->
<!-- <dependency>-->
<!-- <groupId>cn.iocoder.boot</groupId>-->
<!-- <artifactId>yudao-module-report-biz</artifactId>-->
<!-- <version>${revision}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-report-biz</artifactId>
<version>${revision}</version>
</dependency>
<!-- 工作流。默认注释,保证编译速度 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>