Compare commits
No commits in common. "f9ae3fd1db13a041a144cdfc9ff6554e90230168" and "2bcc2b385878046bd7537d4b809292c36fa394fd" have entirely different histories.
f9ae3fd1db
...
2bcc2b3858
|
@ -1,40 +0,0 @@
|
||||||
package org.jeecg.modules.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成规则实体类
|
|
||||||
*
|
|
||||||
* @author Xubx
|
|
||||||
* @date 2025/04/27
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@TableName("cees_generative_rules")
|
|
||||||
@ApiModel(value = "cees_generative_rules对象", description = "生成规则表")
|
|
||||||
public class CeesGenerativeRules {
|
|
||||||
/**
|
|
||||||
* 主键
|
|
||||||
*/
|
|
||||||
@ApiModelProperty(value = "主键")
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 账号类型的位置(第几位,1-8)
|
|
||||||
* 生成时位置顺序:管理员- 学生 -本校老师 -外校老师
|
|
||||||
*/
|
|
||||||
private Integer groupType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 学科类型的位置(第几位,1-8)
|
|
||||||
* 生成时位置顺序
|
|
||||||
*/
|
|
||||||
private Integer majorId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为了唯一查询
|
|
||||||
*/
|
|
||||||
private String Is_default;
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package org.jeecg.modules.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import org.jeecg.modules.entity.CeesGenerativeRules;
|
|
||||||
|
|
||||||
public interface CeesGenerativeRulesMapper extends BaseMapper<CeesGenerativeRules> {
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="org.jeecg.modules.mapper.CeesGenerativeRulesMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
|
@ -6,7 +6,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
import org.jeecg.modules.entity.*;
|
import org.jeecg.modules.entity.CeesLocalTeacher;
|
||||||
|
import org.jeecg.modules.entity.CeesUser;
|
||||||
|
import org.jeecg.modules.entity.CeesWaiTeacher;
|
||||||
|
import org.jeecg.modules.entity.Student;
|
||||||
import org.jeecg.modules.entity.dto.CreateAccountDto;
|
import org.jeecg.modules.entity.dto.CreateAccountDto;
|
||||||
import org.jeecg.modules.enums.identity.MajorLetterEnum;
|
import org.jeecg.modules.enums.identity.MajorLetterEnum;
|
||||||
import org.jeecg.modules.enums.identity.StudentLetterEnum;
|
import org.jeecg.modules.enums.identity.StudentLetterEnum;
|
||||||
|
@ -41,8 +44,6 @@ public class CeesUserServiceImpl extends ServiceImpl<CeesUserMapper, CeesUser> i
|
||||||
CeesLocalTeacherMapper ceesLocalTeacherMapper;
|
CeesLocalTeacherMapper ceesLocalTeacherMapper;
|
||||||
@Resource
|
@Resource
|
||||||
CeesWaiTeacherMapper ceesWaiTeacherMapper;
|
CeesWaiTeacherMapper ceesWaiTeacherMapper;
|
||||||
@Resource
|
|
||||||
CeesGenerativeRulesMapper ceesGenerativeRulesMapper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ceesUser
|
* @param ceesUser
|
||||||
|
@ -269,12 +270,6 @@ public class CeesUserServiceImpl extends ServiceImpl<CeesUserMapper, CeesUser> i
|
||||||
throw new IllegalArgumentException("参数无效");
|
throw new IllegalArgumentException("参数无效");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取生成规则
|
|
||||||
CeesGenerativeRules rules = getGenerativeRules();
|
|
||||||
if (rules == null) {
|
|
||||||
throw new IllegalArgumentException("找不到对应的账号生成规则");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 存储已存在的用户ID
|
// 存储已存在的用户ID
|
||||||
Set<String> set = new HashSet<>();
|
Set<String> set = new HashSet<>();
|
||||||
// 存储与majorID相关的用户专业id
|
// 存储与majorID相关的用户专业id
|
||||||
|
@ -295,7 +290,7 @@ public class CeesUserServiceImpl extends ServiceImpl<CeesUserMapper, CeesUser> i
|
||||||
// 根据专业 ID 生成账号
|
// 根据专业 ID 生成账号
|
||||||
String prefix = getPrefixByMajorId(majorId);
|
String prefix = getPrefixByMajorId(majorId);
|
||||||
String startId = userMIDList.isEmpty() ? getDefaultStartId(majorId) : userMIDList.get(userMIDList.size() - 1);
|
String startId = userMIDList.isEmpty() ? getDefaultStartId(majorId) : userMIDList.get(userMIDList.size() - 1);
|
||||||
saveAccount(num, set, groupType, h5Users, majorId, startId, prefix, rules);
|
saveAccount(num, set, groupType, h5Users, majorId, startId, prefix);
|
||||||
|
|
||||||
// 保存生成的用户账号
|
// 保存生成的用户账号
|
||||||
this.saveBatch(h5Users);
|
this.saveBatch(h5Users);
|
||||||
|
@ -314,13 +309,6 @@ public class CeesUserServiceImpl extends ServiceImpl<CeesUserMapper, CeesUser> i
|
||||||
userMIDList.clear();
|
userMIDList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取生成规则
|
|
||||||
private CeesGenerativeRules getGenerativeRules() {
|
|
||||||
LambdaQueryWrapper<CeesGenerativeRules> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
queryWrapper.eq(CeesGenerativeRules::getIs_default, "1");
|
|
||||||
return ceesGenerativeRulesMapper.selectOne(queryWrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPrefixByMajorId(Integer majorId) {
|
private String getPrefixByMajorId(Integer majorId) {
|
||||||
switch (majorId) {
|
switch (majorId) {
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -352,7 +340,7 @@ public class CeesUserServiceImpl extends ServiceImpl<CeesUserMapper, CeesUser> i
|
||||||
}
|
}
|
||||||
public void saveAccount(
|
public void saveAccount(
|
||||||
Integer num, Set<String> set, Integer groupType, List<CeesUser> h5Users,
|
Integer num, Set<String> set, Integer groupType, List<CeesUser> h5Users,
|
||||||
Integer majorId, @NotNull String code, String label, CeesGenerativeRules rules
|
Integer majorId, @NotNull String code, String label
|
||||||
) {
|
) {
|
||||||
// 参数校验
|
// 参数校验
|
||||||
if (num == null || num <= 0) {
|
if (num == null || num <= 0) {
|
||||||
|
@ -364,16 +352,13 @@ public class CeesUserServiceImpl extends ServiceImpl<CeesUserMapper, CeesUser> i
|
||||||
if (code == null || code.isEmpty()) {
|
if (code == null || code.isEmpty()) {
|
||||||
throw new IllegalArgumentException("起始用户专业 ID 不能为空");
|
throw new IllegalArgumentException("起始用户专业 ID 不能为空");
|
||||||
}
|
}
|
||||||
if (rules == null) {
|
|
||||||
throw new IllegalArgumentException("生成规则不能为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
int newCode = Integer.parseInt(code.substring(1)); // 提取数字部分
|
int newCode = Integer.parseInt(code.substring(1)); // 提取数字部分
|
||||||
|
|
||||||
while (num != 0) {
|
while (num != 0) {
|
||||||
String randomNum = getRandomNum(8);
|
String randomNum = getRandomNum(8);
|
||||||
// 生成账号 - 使用规则中的位置信息
|
// 生成账号
|
||||||
String account = generateAccount(randomNum, groupType, majorId, rules);
|
String account = generateAccount(randomNum, groupType, majorId);
|
||||||
|
|
||||||
if (!set.contains(account)) {
|
if (!set.contains(account)) {
|
||||||
num--;
|
num--;
|
||||||
|
@ -392,34 +377,11 @@ public class CeesUserServiceImpl extends ServiceImpl<CeesUserMapper, CeesUser> i
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用规则中的位置信息
|
private String generateAccount(String randomNum, Integer groupType, Integer majorId) {
|
||||||
private String generateAccount(String randomNum, Integer groupType, Integer majorId, CeesGenerativeRules rules) {
|
//从随机数中提取前 3 位和后 3 位,拼接 groupType 和 majorId,生成 account。
|
||||||
// 根据规则中的位置信息构建账号
|
String prefix = randomNum.substring(0, 3);
|
||||||
char[] accountParts = new char[8]; // 账号长度为8
|
String suffix = randomNum.substring(5, 8);
|
||||||
char[] randomDigits = randomNum.toCharArray();
|
return prefix + groupType + majorId + suffix;
|
||||||
|
|
||||||
// 填充随机数部分
|
|
||||||
int randomIndex = 0;
|
|
||||||
for (int i = 0; i < accountParts.length; i++) {
|
|
||||||
// 检查当前位置是否被规则占用
|
|
||||||
boolean isGroupTypePos = (i + 1) == rules.getGroupType();
|
|
||||||
boolean isMajorIdPos = (i + 1) == rules.getMajorId();
|
|
||||||
|
|
||||||
if (isGroupTypePos) {
|
|
||||||
accountParts[i] = groupType.toString().charAt(0);
|
|
||||||
} else if (isMajorIdPos) {
|
|
||||||
accountParts[i] = majorId.toString().charAt(0);
|
|
||||||
} else {
|
|
||||||
// 使用随机数填充
|
|
||||||
if (randomIndex < randomDigits.length) {
|
|
||||||
accountParts[i] = randomDigits[randomIndex++];
|
|
||||||
} else {
|
|
||||||
accountParts[i] = '0'; // 默认值,理论上不会走到这里
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new String(accountParts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CeesUser createH5User(String account, Integer groupType, Integer majorId, String label, int newCode) {
|
private CeesUser createH5User(String account, Integer groupType, Integer majorId, String label, int newCode) {
|
||||||
|
|
Loading…
Reference in New Issue