diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/common/InviterTypeEnum.java b/dl-module-base/src/main/java/cn/iocoder/yudao/common/InviterTypeEnum.java index 8947d0c8..f41ed922 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/common/InviterTypeEnum.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/common/InviterTypeEnum.java @@ -12,13 +12,17 @@ import lombok.Getter; @Getter public enum InviterTypeEnum { /** - * 员工邀请 + * 自主创建 */ - STAFF("1","员工邀请"), + SELF("01","自主创建"), /** - * 客户邀请 + * 客户转介绍 */ - CUSTOMER("2","客户邀请"); + CUSTOMER("02","客户转介绍"), + /** + * 员工转介绍 + */ + STAFF("03","员工转介绍"); /** * code diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/common/SystemEnum.java b/dl-module-base/src/main/java/cn/iocoder/yudao/common/SystemEnum.java index ba8b8191..b8b198f1 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/common/SystemEnum.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/common/SystemEnum.java @@ -14,28 +14,32 @@ public enum SystemEnum { /** * 维修系统 */ - REPAIR("weixiu","维修系统"), + REPAIR("weixiu","04","维修系统"), /** * 救援系统 */ - RESCUE("jiuyuan","救援系统"), + RESCUE("jiuyuan","02","救援系统"), /** * 驾校系统 */ - SCHOOL("jiaxiao","驾校系统"), + SCHOOL("jiaxiao","03","驾校系统"), /** * 检测系统 */ - INSPECTION("jiance","检测系统"), + INSPECTION("jiance","01","检测系统"), /** * 保险系统 */ - INSURE("baoxian","保险系统"); + INSURE("baoxian","06","保险系统"); /** * 系统标识 */ private String code; + /** + * 对应的客户来源字典值 + */ + private String dataFrom; /** * 系统名称 */ diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/app/UserCarController.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/app/UserCarController.java index 39fda59e..a1f2df9e 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/app/UserCarController.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/app/UserCarController.java @@ -27,7 +27,7 @@ public class UserCarController { @GetMapping("/getMyCar") @Operation(summary = "查询个人车辆列表") public CommonResult getMyCar() { - return CommonResult.success(userCarService.getMyCar()); + return CommonResult.success(userCarService.getMyCar(null)); } @@ -38,8 +38,8 @@ public class UserCarController { **/ @GetMapping("/empowerUserInfo") @Operation(summary = "授权个人信息到某企业") - public CommonResult empowerUserInfo(@RequestParam("tenantId") Long tenantId) { - userCarService.empowerUserInfo(tenantId); + public CommonResult empowerUserInfo(@RequestParam("tenantId") Long tenantId,@RequestParam("systemCode") String systemCode) { + userCarService.empowerUserInfo(tenantId,systemCode,null,null,null); return CommonResult.success(true); } diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerMain.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerMain.java index e5279f05..4a78cbcb 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerMain.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CustomerMain.java @@ -107,7 +107,7 @@ public class CustomerMain extends TenantBaseDO { private String memberLevelId; /** - * 是否挂账 + * 是否允许挂账 */ private String isHangAccount; diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/UserCarService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/UserCarService.java index f4d7fda0..01ad0bc3 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/UserCarService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/UserCarService.java @@ -30,7 +30,7 @@ public interface UserCarService extends IService { * @date 14:28 2024/10/11 * @return java.util.List **/ - List getMyCar(); + List getMyCar(Long userId); /** * @@ -46,6 +46,10 @@ public interface UserCarService extends IService { * @author PQZ * @date 12:40 2024/10/12 * @param tenantId 租户id + * @param dataFrom 客户来源 + * @param userId 邀请者的用户ID + * @param newUserId 被邀请者的用户ID + * @param inviteType 邀请类型 **/ - void empowerUserInfo(Long tenantId); + void empowerUserInfo(Long tenantId,String dataFrom,Long userId,Long newUserId,String inviteType); } diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerMainServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerMainServiceImpl.java index 3892b26b..f33d9e9b 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerMainServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerMainServiceImpl.java @@ -167,37 +167,6 @@ public class CustomerMainServiceImpl extends ServiceImpl roleCodes = new HashSet<>(); roleCodes.add(dict.getRemark()); permissionApi.assignUserRole(userId, roleCodes); - }else if(INVITE_CREATE.equals(sign)){ - //邀请注册/授权给某个租户 - //查询数据字典,根据客户类型匹配出预设角色code; - DictDataRespDTO dict = dictDataApi.getDictData(DICT_CUS_TYPE, main.getTypeCode()); - if (CUS_TYPE_CORP.equals(main.getTypeCode())) { - //查询当前登录用户所属租户的政企客户部门id(父级部门) - DeptRespDTO parentDept = deptApi.getDeptByName(DEPT_NAME_CORP_NAME); - //在部门表下新增一个部门 - DeptRespDTO deptRespDTO = new DeptRespDTO(); - deptRespDTO.setName(main.getCusName()); - deptRespDTO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - //上级部门为本租户顶级部门 - deptRespDTO.setParentId(parentDept.getId()); - Long deptId = deptApi.saveDept(deptRespDTO); - //客户信息表绑定deptCode - main.setDeptCode(deptId); - }else{ - //私人客户和代办客户归属到默认的部门中 - String deptName = ""; - if(CUS_TYPE_PRIVATE.equals(main.getTypeCode())){ - deptName =DEPT_NAME_PRIVATE_NAME; - }else if(CUS_TYPE_AGENT.equals(main.getTypeCode())){ - deptName = DEPT_NAME_AGENT_NAME; - } - DeptRespDTO parentDept = deptApi.getDeptByName(deptName); - main.setDeptCode(parentDept.getId()); - } - //绑定角色 - Set roleCodes = new HashSet<>(); - roleCodes.add(dict.getRemark()); - permissionApi.assignUserRole(main.getUserId(), roleCodes); } /*3、保存客户主表信息*/ //暂时写死会员id TODO diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/UserCarServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/UserCarServiceImpl.java index 053a66f1..b161d015 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/UserCarServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/UserCarServiceImpl.java @@ -86,9 +86,9 @@ public class UserCarServiceImpl extends ServiceImpl impl * @date 14:28 2024/10/11 **/ @Override - public List getMyCar() { + public List getMyCar(Long userId) { LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); - return userCarMapper.selectByUserId(loginUser.getId()); + return userCarMapper.selectByUserId(null==userId?loginUser.getId():userId); } /** @@ -110,23 +110,26 @@ public class UserCarServiceImpl extends ServiceImpl impl /** * 将客户信息授权给某个修理厂 - * - * @param tenantId 租户id * @author PQZ * @date 12:40 2024/10/12 + * @param tenantId 租户id + * @param dataFrom 客户来源 + * @param userId 邀请者的用户ID + * @param newUserId 被邀请者的用户ID + * @param inviteType 邀请类型 **/ @Override @Transactional(rollbackFor = Exception.class) @TenantIgnore - public void empowerUserInfo(Long tenantId) { + public void empowerUserInfo(Long tenantId,String dataFrom,Long userId,Long newUserId,String inviteType) { /*1、基础数据准备*/ + if(null==newUserId){ + newUserId = SecurityFrameworkUtils.getLoginUserId(); + } //获取当前登录用户信息 - Long userId = SecurityFrameworkUtils.getLoginUserId(); - AdminUserRespDTO loginUser = userApi.getUser(userId); + AdminUserRespDTO loginUser = userApi.getUser(newUserId); //获取当前登录用户车辆信息 - List carList = this.getMyCar(); - //所有车牌号list - List licenseNoList = carList.stream().map(UserCar::getLicenseNumber).collect(Collectors.toList()); + List carList = this.getMyCar(newUserId); //需要保存的关联关系 List saveCustomerCarList = new ArrayList<>(); //需要保存的车辆信息 @@ -135,11 +138,12 @@ public class UserCarServiceImpl extends ServiceImpl impl final CustomerMain[] oldMain = {null}; //查已有的车辆信息,若有则更新,没有则插入 final Map[] carMap = new Map[]{new HashMap<>()}; + Long finalNewUserId = newUserId; TenantUtils.execute(tenantId, () -> { //客户在这个租户下的信息 - oldMain[0] = customerMainService.getCustomerByUserId(userId); + oldMain[0] = customerMainService.getCustomerByUserId(finalNewUserId); //客户在这个租户下的车辆信息 - List oldCarMainList=carMainService.selectListByUserId(userId); + List oldCarMainList=carMainService.selectListByUserId(finalNewUserId); carMap[0] = oldCarMainList.stream().collect(Collectors.toMap(CarMain::getLicenseNumber, Function.identity())); }); String customerId; @@ -147,22 +151,32 @@ public class UserCarServiceImpl extends ServiceImpl impl /*2、数据转换,将用户表关联信息转换成客户表关联信息 */ //转换客户数据 if(null== oldMain[0]){ + //新增客户 customerId = UUID.randomUUID().toString().replace("-", ""); customerMain = new CustomerMain(); customerMain.setId(customerId); + customerMain.setUserId(newUserId); + //客户租户 + customerMain.setTenantId(tenantId); + //统一为个人客户 + customerMain.setTypeCode("01"); + //客户初始来源系统 + customerMain.setDataFrom(dataFrom); + //默认不允许挂账 + customerMain.setIsHangAccount("0"); + if(null!=userId){ + //是被邀请的,设置邀请者信息 + customerMain.setInviter(userId.toString()); + customerMain.setInviterType(inviteType); + } }else{ + //更新客户信息 customerId = oldMain[0].getId(); customerMain = oldMain[0]; } - //提前为客户id赋值 - customerMain.setUserId(userId); customerMain.setCusName(loginUser.getNickname()); customerMain.setSex(String.valueOf(loginUser.getSex())); customerMain.setPhoneNumber(loginUser.getMobile()); - customerMain.setTenantId(tenantId); - customerMain.setTypeCode("01"); - customerMain.setDataFrom("04"); - customerMain.setIsHangAccount("0"); //转换车辆及关联关系数据 if (CollUtil.isNotEmpty(carList)){ carList.forEach(item ->{ @@ -185,7 +199,7 @@ public class UserCarServiceImpl extends ServiceImpl impl //车辆信息 carItem.setEngineNumber(item.getEngineNumber()); carItem.setVin(item.getVin()); - carItem.setUserId(userId); + carItem.setUserId(finalNewUserId); carItem.setLicenseNumber(item.getLicenseNumber()); carItem.setCarModel(item.getCarModel()); carItem.setMaintenanceDate(convertToLocalDateTime(item.getMaintenanceDate())); diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/controller/admin/CompanyStaffController.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/controller/admin/CompanyStaffController.java index ba34acf9..3a169f47 100644 --- a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/controller/admin/CompanyStaffController.java +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/controller/admin/CompanyStaffController.java @@ -128,6 +128,19 @@ public class CompanyStaffController { return success(staffRespVO); } + /** + * 给所有没有推广码的员工设置推广码 + * @author vinjor-M + * @date 17:29 2024/10/15 + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult + **/ + @GetMapping("/setStaffUnicode") + @Operation(summary = "给所有没有推广码的员工设置推广码") + public CommonResult setStaffUnicode() { + staffService.setStaffUnicode(); + return CommonResult.ok(); + } + /** * 查询员工单个 没有附加属性 * diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/CompanyStaffService.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/CompanyStaffService.java index 6bc071ad..96e7ec0f 100644 --- a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/CompanyStaffService.java +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/CompanyStaffService.java @@ -117,10 +117,18 @@ public interface CompanyStaffService extends IService { * 新增推广记录 * @author vinjor-m * @date 12:26 2024/8/14 + * @param dataFrom 客户来源 * @param uniqueCode 推广码 * @param user 被推广用户 * @param promotionChannel 推广渠道 * @param registerTime 被推广用户注册的时间 **/ - Boolean createPromotion(String uniqueCode, AdminUserDO user, String promotionChannel, Date registerTime); + Boolean createPromotion(String dataFrom,String uniqueCode, AdminUserDO user, String promotionChannel, Date registerTime); + + /** + * 给所有没有推广码的员工设置推广码 + * @author vinjor-M + * @date 17:23 2024/10/15 + **/ + void setStaffUnicode(); } diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/CompanyStaffServiceImpl.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/CompanyStaffServiceImpl.java index 145704c9..dc1ddcb8 100644 --- a/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/CompanyStaffServiceImpl.java +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/staff/service/impl/CompanyStaffServiceImpl.java @@ -9,9 +9,10 @@ import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import cn.iocoder.yudao.module.custom.entity.BasePromotion; +import cn.iocoder.yudao.module.custom.entity.CustomerMain; import cn.iocoder.yudao.module.custom.service.BasePromotionService; import cn.iocoder.yudao.module.custom.service.CustomerMainService; -import cn.iocoder.yudao.module.custom.vo.CustomerMainSaveReqVO; +import cn.iocoder.yudao.module.custom.service.UserCarService; import cn.iocoder.yudao.module.label.entity.BusiLabel; import cn.iocoder.yudao.module.label.entity.Label; import cn.iocoder.yudao.module.label.service.BusiLabelService; @@ -51,7 +52,6 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import static cn.iocoder.yudao.common.BaseConstants.INVITE_CREATE; import static cn.iocoder.yudao.framework.common.config.CommonStr.USER_TYPE_STAFF; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -94,6 +94,8 @@ public class CompanyStaffServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper() .eq(CompanyStaff::getUniqueCode,uniqueCode); @@ -547,39 +550,59 @@ public class CompanyStaffServiceImpl extends ServiceImpl { - CustomerMainSaveReqVO saveReqVO = new CustomerMainSaveReqVO(); - saveReqVO.setUserId(user.getId()); - saveReqVO.setPhoneNumber(user.getMobile()); - saveReqVO.setSex(user.getSex().toString()); - saveReqVO.setCusName(user.getNickname()); - //客户类型,统一为私人客户 - saveReqVO.setTypeCode("01"); - //客户来源,统一为04-维修 - saveReqVO.setDataFrom("04"); - //注册方式,统一为自主创建 - saveReqVO.setInviterType("01"); - //邀请者id - saveReqVO.setInviter(staff.getUserId().toString()); - //邀请者类型 - saveReqVO.setInviterType(InviterTypeEnum.STAFF.getCode()); - //邀请注册添加客户 - customerMainService.saveCustomer(saveReqVO,INVITE_CREATE); + thisCus[0] = customerMainService.getCustomerByUserId(user.getId()); }); + if(null==thisCus[0]){ + // 插入推广记录 + BasePromotion basePromotion = new BasePromotion(); + basePromotion.setOldUserId(staff.getUserId()); + basePromotion.setOldUserName(staff.getName()); + basePromotion.setPromotionChannel(promotionChannel); + basePromotion.setNewUserId(user.getId()); + basePromotion.setNewUserName(user.getNickname()); + basePromotion.setRegisterTime(registerTime); + basePromotion.setUniqueCode(uniqueCode); + basePromotionService.save(basePromotion); + //将客户信息授权给员工所属的租户 + userCarService.empowerUserInfo(staff.getTenantId(),dataFrom,staff.getUserId(),user.getId(),InviterTypeEnum.STAFF.getCode()); + } }else{ /*2.不是员工推广,再查是否是客户推广*/ } return true; } + + /** + * 给所有没有推广码的员工设置推广码 + * + * @author vinjor-M + * @date 17:23 2024/10/15 + **/ + @Override + @TenantIgnore + public void setStaffUnicode() { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .isNull(CompanyStaff::getUniqueCode); + List list = this.list(queryWrapper); + if(!list.isEmpty()){ + for (CompanyStaff staff:list){ + try { + // 2 生成唯一推广码 + String uniqueCode = uniqueCodeService.createUniqueCode(); + if (!ObjectUtil.isNotEmpty(uniqueCode)) { + throw exception(CommonErrorCodeConstants.UNIQUE_CODE_CREATE_REPEAT); + } + staff.setUniqueCode(uniqueCode); + }catch (Exception e){ + //记录日志,不能影响程序执行 + log.error(e.getMessage()); + } + } + this.updateBatchById(list); + } + } } diff --git a/dl-module-company/src/main/java/cn/iocoder/yudao/module/wechat/service/impl/WechatServiceImpl.java b/dl-module-company/src/main/java/cn/iocoder/yudao/module/wechat/service/impl/WechatServiceImpl.java index 7781dca9..fe273933 100644 --- a/dl-module-company/src/main/java/cn/iocoder/yudao/module/wechat/service/impl/WechatServiceImpl.java +++ b/dl-module-company/src/main/java/cn/iocoder/yudao/module/wechat/service/impl/WechatServiceImpl.java @@ -137,21 +137,28 @@ public class WechatServiceImpl implements WechatService { //更新 user.setId(wxUser.getId()); } + String dataFrom = ""; //设置微信openId if(SystemEnum.REPAIR.getCode().equals(sysCode)){ //维修业务系统 user.setRepairOpenId(openId); + dataFrom = SystemEnum.REPAIR.getDataFrom(); }else if(SystemEnum.INSPECTION.getCode().equals(sysCode)){ //检测业务系统 + dataFrom = SystemEnum.INSPECTION.getDataFrom(); }else if(SystemEnum.SCHOOL.getCode().equals(sysCode)){ //驾校业务系统 + dataFrom = SystemEnum.SCHOOL.getDataFrom(); }else if(SystemEnum.RESCUE.getCode().equals(sysCode)){ //救援业务系统 + dataFrom = SystemEnum.RESCUE.getDataFrom(); }else if(SystemEnum.INSURE.getCode().equals(sysCode)){ //保险业务系统 + dataFrom = SystemEnum.INSURE.getDataFrom(); }else { //默认维修业务 user.setRepairOpenId(openId); + dataFrom = SystemEnum.REPAIR.getDataFrom(); } if(null!=user.getId()){ //更新 @@ -167,7 +174,7 @@ public class WechatServiceImpl implements WechatService { /*如果携带了邀请码,需要插入邀请记录并自动复制用户信息到邀请者的租户下 */ if(!StringUtils.isEmpty(inviteId)){ //邀请注册,自动注册客户信息 - companyStaffService.createPromotion(inviteId,wxUser, PromotionEnum.WeChat.getCode(), new Date()); + companyStaffService.createPromotion(dataFrom,inviteId,wxUser, PromotionEnum.WeChat.getCode(), new Date()); } return wxUser; }