| | |
| | | import cn.iocoder.yudao.module.system.api.storage.dto.StorageBlobRespDTO; |
| | | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| | | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserCreateReqDTO; |
| | | import cn.iocoder.yudao.module.system.service.social.SocialUserService; |
| | | import cn.iocoder.yudao.module.system.service.permission.RoleService; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; |
| | | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| | | import cn.iocoder.yudao.module.ums.controller.admin.member.vo.UmsMemberPageReqVO; |
| | | import cn.iocoder.yudao.module.ums.controller.admin.member.vo.UmsMemberSaveReqVO; |
| | | import cn.iocoder.yudao.module.ums.dal.dataobject.application.UmsApplicationDO; |
| | | import cn.iocoder.yudao.module.ums.dal.dataobject.member.UmsMemberDO; |
| | | import cn.iocoder.yudao.module.ums.dal.mysql.application.UmsApplicationMapper; |
| | | import cn.iocoder.yudao.module.ums.dal.mysql.member.UmsMemberMapper; |
| | | import cn.iocoder.yudao.module.ums.dal.redis.UmsNoRedisDAO; |
| | | import jakarta.annotation.Resource; |
| | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.UUID; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | |
| | | private static final Long MEMBER_DEPT_ID = 129L; |
| | | |
| | | /** |
| | | * 普通会员角色 ID(system_role「普通会员」) |
| | | * |
| | | * <p>该角色只分配「我的资料」菜单,不包含档案管理等后台菜单,用于实现权限隔离。 |
| | | * 企业微信扫码用户角色编码;按编码查询,避免不同环境角色编号不一致。 |
| | | */ |
| | | private static final Long MEMBER_ROLE_ID = 9100L; |
| | | private static final String MEMBER_ROLE_CODE = "wxcp_user"; |
| | | |
| | | public static final String MEMBER_RECORD_TYPE = "ums_member"; |
| | | |
| | |
| | | |
| | | @Resource |
| | | private UmsMemberMapper memberMapper; |
| | | @Resource |
| | | private UmsApplicationMapper applicationMapper; |
| | | @Resource |
| | | private SocialUserService socialUserService; |
| | | @Resource |
| | | private RoleService roleService; |
| | | |
| | | @Resource |
| | | private UmsNoRedisDAO noRedisDAO; |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public UmsMemberDO createMemberFromApplication(UmsApplicationDO application) { |
| | | UmsMemberDO existing = memberMapper.selectByApplicationId(application.getId()); |
| | | if (existing != null) return existing; |
| | | // 1. 生成会员编号 |
| | | String no = noRedisDAO.generate(UmsNoRedisDAO.MEMBER_NO_PREFIX); |
| | | if (memberMapper.selectByNo(no) != null) { |
| | |
| | | |
| | | // 2. 创建系统用户账号 |
| | | Long userId = createSystemUser(application); |
| | | if (StrUtil.isNotBlank(application.getWxcpOpenid())) { |
| | | socialUserService.bindApprovedWxcpUser(application.getWxcpOpenid(), userId); |
| | | } |
| | | |
| | | // 3. 创建会员记录 |
| | | UmsMemberDO member = UmsMemberDO.builder() |
| | |
| | | .applicationId(application.getId()) |
| | | .memberType(application.getMemberType()) |
| | | .memberGrade(application.getMemberGrade()) |
| | | .feePaid(application.getFeePaid()) |
| | | .passwordSetupRequired(StrUtil.isBlank(application.getContactPhone())) |
| | | .name(application.getApplicantName()) |
| | | .contactPhone(application.getContactPhone()) |
| | | .contactEmail(application.getContactEmail()) |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateMember(UmsMemberSaveReqVO updateReqVO) { |
| | | validateMemberExists(updateReqVO.getId()); |
| | | UmsMemberDO existingMember = validateMemberExists(updateReqVO.getId()); |
| | | validateMemberGrade(updateReqVO.getMemberType(), updateReqVO.getMemberGrade()); |
| | | validateFeePaid(updateReqVO); |
| | | |
| | |
| | | |
| | | UmsMemberDO updateObj = BeanUtils.toBean(updateReqVO, UmsMemberDO.class); |
| | | memberMapper.updateById(updateObj); |
| | | if (existingMember.getApplicationId() != null && updateReqVO.getFeePaid() != null) { |
| | | applicationMapper.updateById(new UmsApplicationDO() |
| | | .setId(existingMember.getApplicationId()).setFeePaid(updateReqVO.getFeePaid())); |
| | | } |
| | | if (clearFeeYear) { |
| | | memberMapper.update(null, new LambdaUpdateWrapper<UmsMemberDO>() |
| | | .eq(UmsMemberDO::getId, updateReqVO.getId()) |
| | |
| | | |
| | | private Long createSystemUser(UmsApplicationDO application) { |
| | | // 手机号可作为用户名/密码(参考 HRM 员工模式) |
| | | String mobile = StrUtil.blankToDefault(application.getContactPhone(), "unknown"); |
| | | String username = mobile; |
| | | String nickname = application.getApplicantName(); |
| | | String mobile = StrUtil.trim(application.getContactPhone()); |
| | | if ((StrUtil.isBlank(mobile) && StrUtil.isBlank(application.getWxcpOpenid())) |
| | | || (StrUtil.isNotBlank(mobile) && !mobile.matches("^1[3-9]\\d{9}$"))) { |
| | | throw exception(APPLICATION_WXCP_INFO_REQUIRED); |
| | | } |
| | | RoleDO role = roleService.getRoleByCode(MEMBER_ROLE_CODE); |
| | | if (role == null || CommonStatusEnum.isDisable(role.getStatus())) { |
| | | throw exception(MEMBER_WXCP_ROLE_NOT_AVAILABLE); |
| | | } |
| | | boolean hasMobile = StrUtil.isNotBlank(mobile); |
| | | String username = hasMobile ? mobile : "wx" + UUID.randomUUID().toString().replace("-", "").substring(0, 16); |
| | | String password = hasMobile ? mobile : UUID.randomUUID().toString().replace("-", "").substring(0, 16); |
| | | String nickname = StrUtil.maxLength(application.getApplicantName(), 30); |
| | | |
| | | try { |
| | | return adminUserApi.createUser(new AdminUserCreateReqDTO() |
| | |
| | | .setNickname(nickname) |
| | | .setDeptId(MEMBER_DEPT_ID) |
| | | .setPostIds(Collections.emptySet()) |
| | | .setRoleIds(Collections.singleton(MEMBER_ROLE_ID)) |
| | | .setMobile(mobile) |
| | | .setPassword(mobile) // 默认密码为手机号 |
| | | .setRoleIds(Collections.singleton(role.getId())) |
| | | .setMobile(hasMobile ? mobile : null) |
| | | .setPassword(password) |
| | | .setEmail(application.getContactEmail()) |
| | | .setRemark("由入会申请自动创建:" + application.getNo())); |
| | | } catch (Exception e) { |