Skip to content

Commit

Permalink
chore: 优化个人中心部分参数命名
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed May 9, 2024
1 parent 1de2a8f commit 61dd3a4
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ public PageResp<TableResp> pageTable(TableQuery query, PageQuery pageQuery) thro
tableList.removeIf(table -> !StrUtil.containsAny(table.getTableName(), tableName));
}
tableList.removeIf(table -> StrUtil.equalsAnyIgnoreCase(table.getTableName(), generatorProperties
.getExcludeTables()));
.getExcludeTables()));
CollUtil.sort(tableList, Comparator.comparing(Table::getCreateTime)
.thenComparing(table -> Optional.ofNullable(table.getUpdateTime()).orElse(table.getCreateTime()))
.reversed());
.thenComparing(table -> Optional.ofNullable(table.getUpdateTime()).orElse(table.getCreateTime()))
.reversed());
List<TableResp> tableRespList = BeanUtil.copyToList(tableList, TableResp.class);
PageResp<TableResp> pageResp = PageResp.build(pageQuery.getPage(), pageQuery.getSize(), tableRespList);
for (TableResp tableResp : pageResp.getList()) {
long count = genConfigMapper.selectCount(Wrappers.lambdaQuery(GenConfigDO.class)
.eq(GenConfigDO::getTableName, tableResp.getTableName()));
.eq(GenConfigDO::getTableName, tableResp.getTableName()));
tableResp.setIsConfiged(count > 0);
}
return pageResp;
Expand All @@ -118,8 +118,8 @@ public GenConfigDO getGenConfig(String tableName) throws SQLException {
}
// 默认作者名称(上次保存使用的作者名称)
GenConfigDO lastGenConfig = genConfigMapper.selectOne(Wrappers.lambdaQuery(GenConfigDO.class)
.orderByDesc(GenConfigDO::getCreateTime)
.last("LIMIT 1"));
.orderByDesc(GenConfigDO::getCreateTime)
.last("LIMIT 1"));
if (null != lastGenConfig) {
genConfig.setAuthor(lastGenConfig.getAuthor());
}
Expand Down Expand Up @@ -148,22 +148,22 @@ public List<FieldConfigDO> listFieldConfig(String tableName, Boolean requireSync
Set<Map.Entry<String, List<String>>> typeMappingEntrySet = typeMappingMap.entrySet();
// 新增或更新字段配置
Map<String, FieldConfigDO> fieldConfigMap = fieldConfigList.stream()
.collect(Collectors.toMap(FieldConfigDO::getColumnName, Function.identity(), (key1, key2) -> key2));
.collect(Collectors.toMap(FieldConfigDO::getColumnName, Function.identity(), (key1, key2) -> key2));
int i = 1;
for (Column column : columnList) {
FieldConfigDO fieldConfig = Optional.ofNullable(fieldConfigMap.get(column.getName()))
.orElseGet(() -> new FieldConfigDO(column));
.orElseGet(() -> new FieldConfigDO(column));
// 更新已有字段配置
if (null != fieldConfig.getCreateTime()) {
String columnType = StrUtil.splitToArray(column.getTypeName(), StringConstants.SPACE)[0].toLowerCase();
fieldConfig.setColumnType(columnType);
fieldConfig.setColumnSize(Convert.toStr(column.getSize()));
}
String fieldType = typeMappingEntrySet.stream()
.filter(entry -> entry.getValue().contains(fieldConfig.getColumnType()))
.map(Map.Entry::getKey)
.findFirst()
.orElse(null);
.filter(entry -> entry.getValue().contains(fieldConfig.getColumnType()))
.map(Map.Entry::getKey)
.findFirst()
.orElse(null);
fieldConfig.setFieldType(fieldType);
fieldConfig.setFieldSort(i++);
latestFieldConfigList.add(fieldConfig);
Expand Down Expand Up @@ -193,7 +193,7 @@ public void saveConfig(GenConfigReq req, String tableName) {
}
// 既不在表单也不在查询中显示,不需要设置表单类型
if (Boolean.FALSE.equals(fieldConfig.getShowInForm()) && Boolean.FALSE.equals(fieldConfig
.getShowInQuery())) {
.getShowInQuery())) {
fieldConfig.setFormType(null);
}
fieldConfig.setTableName(tableName);
Expand Down Expand Up @@ -222,7 +222,7 @@ public List<GeneratePreviewResp> preview(String tableName) {
genConfigMap.put("date", DateUtil.date().toString("yyyy/MM/dd HH:mm"));
String packageName = genConfig.getPackageName();
String apiModuleName = StrUtil.subSuf(packageName, StrUtil
.lastIndexOfIgnoreCase(packageName, StringConstants.DOT) + 1);
.lastIndexOfIgnoreCase(packageName, StringConstants.DOT) + 1);
genConfigMap.put("apiModuleName", apiModuleName);
genConfigMap.put("apiName", StrUtil.lowerFirst(genConfig.getClassNamePrefix()));
// 渲染代码
Expand All @@ -243,8 +243,8 @@ public List<GeneratePreviewResp> preview(String tableName) {
generatePreview.setContent(TemplateUtils.render(templateConfig.getTemplatePath(), genConfigMap));
} else {
generatePreview.setFileName(".vue".equals(extension) && "index".equals(templateConfigEntry.getKey())
? "index.vue"
: this.getFrontendFileName(classNamePrefix, className, extension));
? "index.vue"
: this.getFrontendFileName(classNamePrefix, className, extension));
genConfigMap.put("fieldConfigs", fieldConfigList);
generatePreview.setContent(TemplateUtils.render(templateConfig.getTemplatePath(), genConfigMap));
}
Expand All @@ -253,26 +253,29 @@ public List<GeneratePreviewResp> preview(String tableName) {
return generatePreviewList;
}

private void setPreviewPath(GeneratePreviewResp generatePreview, GenConfigDO genConfig, GeneratorProperties.TemplateConfig templateConfig) {
private void setPreviewPath(GeneratePreviewResp generatePreview,
GenConfigDO genConfig,
GeneratorProperties.TemplateConfig templateConfig) {
// 获取前后端基础路径
String backendBasicPackagePath = this.buildBackendBasicPackagePath(genConfig);
String frontendBasicPackagePath = String.join(File.separator, projectProperties.getAppName(), projectProperties.getAppName() + "-ui");
String frontendBasicPackagePath = String.join(File.separator, projectProperties.getAppName(), projectProperties
.getAppName() + "-ui");
String packageName = genConfig.getPackageName();
String moduleName = StrUtil.subSuf(packageName, StrUtil
.lastIndexOfIgnoreCase(packageName, StringConstants.DOT) + 1);
.lastIndexOfIgnoreCase(packageName, StringConstants.DOT) + 1);
String packagePath;
if (generatePreview.isBackend()) {
// 例如:continew-admin/continew-system/src/main/java/top/continew/admin/system/service/impl
packagePath = String.join(File.separator, backendBasicPackagePath, templateConfig.getPackageName()
.replace(StringConstants.DOT, File.separator));
.replace(StringConstants.DOT, File.separator));
} else {
// 例如:continew-admin/continew-admin-ui/src/views/system
packagePath = String.join(File.separator, frontendBasicPackagePath, templateConfig.getPackageName()
.replace(StringConstants.SLASH, File.separator), moduleName);
.replace(StringConstants.SLASH, File.separator), moduleName);
// 例如:continew-admin/continew-admin-ui/src/views/system/user
packagePath = ".vue".equals(templateConfig.getExtension())
? packagePath + File.separator + StrUtil.lowerFirst(genConfig.getClassNamePrefix())
: packagePath;
? packagePath + File.separator + StrUtil.lowerFirst(genConfig.getClassNamePrefix())
: packagePath;
}
generatePreview.setPath(packagePath);
}
Expand Down Expand Up @@ -310,7 +313,8 @@ private void generateCode(List<GeneratePreviewResp> generatePreviewList, GenConf
for (GeneratePreviewResp generatePreview : generatePreviewList) {
// 后端:continew-admin/continew-system/src/main/java/top/continew/admin/system/service/impl/XxxServiceImpl.java
// 前端:continew-admin/continew-admin-ui/src/views/system/user/index.vue
File file = new File(SystemUtil.getUserInfo().getTempDir() + generatePreview.getPath(), generatePreview.getFileName());
File file = new File(SystemUtil.getUserInfo().getTempDir() + generatePreview.getPath(), generatePreview
.getFileName());
// 如果已经存在,且不允许覆盖,则跳过
if (!file.exists() || Boolean.TRUE.equals(genConfig.getIsOverride())) {
FileUtil.writeUtf8String(generatePreview.getContent(), file);
Expand All @@ -326,9 +330,8 @@ private void generateCode(List<GeneratePreviewResp> generatePreviewList, GenConf
*/
private String buildBackendBasicPackagePath(GenConfigDO genConfig) {
// 例如:continew-admin/continew-system/src/main/java/top/continew/admin/system
return String.join(File.separator, projectProperties
.getAppName(), projectProperties.getAppName(), genConfig.getModuleName(), "src", "main", "java", genConfig
.getPackageName()
return String.join(File.separator, projectProperties.getAppName(), projectProperties.getAppName(), genConfig
.getModuleName(), "src", "main", "java", genConfig.getPackageName()
.replace(StringConstants.DOT, File.separator));
}

Expand Down Expand Up @@ -357,8 +360,8 @@ private void pretreatment(Map<String, Object> genConfigMap,
GeneratorProperties.TemplateConfig templateConfig = templateConfigEntry.getValue();
// 移除需要忽略的字段
List<FieldConfigDO> fieldConfigList = originFieldConfigList.stream()
.filter(fieldConfig -> !StrUtil.equalsAny(fieldConfig.getFieldName(), templateConfig.getExcludeFields()))
.toList();
.filter(fieldConfig -> !StrUtil.equalsAny(fieldConfig.getFieldName(), templateConfig.getExcludeFields()))
.toList();
genConfigMap.put("fieldConfigs", fieldConfigList);
// 统计部分特殊字段特征
genConfigMap.put("hasLocalDateTime", false);
Expand All @@ -378,7 +381,7 @@ private void pretreatment(Map<String, Object> genConfigMap,
}
QueryTypeEnum queryType = fieldConfig.getQueryType();
if (null != queryType && StrUtil.equalsAny(queryType.name(), QueryTypeEnum.IN.name(), QueryTypeEnum.NOT_IN
.name(), QueryTypeEnum.BETWEEN.name())) {
.name(), QueryTypeEnum.BETWEEN.name())) {
genConfigMap.put("hasListQueryField", true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class UserInfoResp implements Serializable {
* 密码是否已过期
*/
@Schema(description = "密码是否已过期", example = "true")
private Boolean passwordExpired;
private Boolean pwdExpired;

/**
* 创建时间
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class UserEmailUpdateRequest implements Serializable {
@Schema(description = "新邮箱", example = "123456789@qq.com")
@NotBlank(message = "新邮箱不能为空")
@Pattern(regexp = RegexPool.EMAIL, message = "邮箱格式错误")
private String newEmail;
private String email;

/**
* 验证码
Expand All @@ -60,5 +60,5 @@ public class UserEmailUpdateRequest implements Serializable {
*/
@Schema(description = "当前密码(加密)", example = "SYRLSszQGcMv4kP2Yolou9zf28B9GDakR9u91khxmR7V++i5A384kwnNZxqgvT6bjT4zqpIDuMFLWSt92hQJJA==")
@NotBlank(message = "当前密码不能为空")
private String currentPassword;
private String oldPassword;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class UserPhoneUpdateReq implements Serializable {
@Schema(description = "新手机号", example = "13811111111")
@NotBlank(message = "新手机号不能为空")
@Pattern(regexp = RegexPool.MOBILE, message = "手机号格式错误")
private String newPhone;
private String phone;

/**
* 验证码
Expand All @@ -60,5 +60,5 @@ public class UserPhoneUpdateReq implements Serializable {
*/
@Schema(description = "当前密码(加密)", example = "SYRLSszQGcMv4kP2Yolou9zf28B9GDakR9u91khxmR7V++i5A384kwnNZxqgvT6bjT4zqpIDuMFLWSt92hQJJA==")
@NotBlank(message = "当前密码不能为空")
private String currentPassword;
private String oldPassword;
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,20 @@ public interface UserService extends BaseService<UserResp, UserDetailResp, UserQ
/**
* 修改手机号
*
* @param newPhone 新手机号
* @param currentPassword 当前密码
* @param id ID
* @param newPhone 新手机号
* @param oldPassword 当前密码
* @param id ID
*/
void updatePhone(String newPhone, String currentPassword, Long id);
void updatePhone(String newPhone, String oldPassword, Long id);

/**
* 修改邮箱
*
* @param newEmail 新邮箱
* @param currentPassword 当前密码
* @param id ID
* @param newEmail 新邮箱
* @param oldPassword 当前密码
* @param id ID
*/
void updateEmail(String newEmail, String currentPassword, Long id);
void updateEmail(String newEmail, String oldPassword, Long id);

/**
* 重置密码
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,19 @@ public Boolean isPasswordExpired(LocalDateTime pwdResetTime) {
}

@Override
public void updatePhone(String newPhone, String currentPassword, Long id) {
public void updatePhone(String newPhone, String oldPassword, Long id) {
UserDO user = super.getById(id);
CheckUtils.throwIf(!passwordEncoder.matches(currentPassword, user.getPassword()), "当前密码错误");
CheckUtils.throwIf(!passwordEncoder.matches(oldPassword, user.getPassword()), "当前密码错误");
CheckUtils.throwIf(this.isPhoneExists(newPhone, id), "手机号已绑定其他账号,请更换其他手机号");
CheckUtils.throwIfEqual(newPhone, user.getPhone(), "新手机号不能与当前手机号相同");
// 更新手机号
baseMapper.lambdaUpdate().set(UserDO::getPhone, newPhone).eq(UserDO::getId, id).update();
}

@Override
public void updateEmail(String newEmail, String currentPassword, Long id) {
public void updateEmail(String newEmail, String oldPassword, Long id) {
UserDO user = super.getById(id);
CheckUtils.throwIf(!passwordEncoder.matches(currentPassword, user.getPassword()), "当前密码错误");
CheckUtils.throwIf(!passwordEncoder.matches(oldPassword, user.getPassword()), "当前密码错误");
CheckUtils.throwIf(this.isEmailExists(newEmail, id), "邮箱已绑定其他账号,请更换其他邮箱");
CheckUtils.throwIfEqual(newEmail, user.getEmail(), "新邮箱不能与当前邮箱相同");
// 更新邮箱
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public R<UserInfoResp> getUserInfo() {
UserInfoResp userInfoResp = BeanUtil.copyProperties(userDetailResp, UserInfoResp.class);
userInfoResp.setPermissions(loginUser.getPermissions());
userInfoResp.setRoles(loginUser.getRoleCodes());
userInfoResp.setPasswordExpired(userService.isPasswordExpired(userDetailResp.getPwdResetTime()));
userInfoResp.setPwdExpired(userService.isPasswordExpired(userDetailResp.getPwdResetTime()));
return R.ok(userInfoResp);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,30 @@ public R<Void> updatePassword(@Validated @RequestBody UserPasswordUpdateReq upda
@Operation(summary = "修改手机号", description = "修改手机号")
@PatchMapping("/phone")
public R<Void> updatePhone(@Validated @RequestBody UserPhoneUpdateReq updateReq) {
String rawCurrentPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq
.getCurrentPassword()));
ValidationUtils.throwIfBlank(rawCurrentPassword, DECRYPT_FAILED);
String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + updateReq.getNewPhone();
String rawOldPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq
.getOldPassword()));
ValidationUtils.throwIfBlank(rawOldPassword, DECRYPT_FAILED);
String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + updateReq.getPhone();
String captcha = RedisUtils.get(captchaKey);
ValidationUtils.throwIfBlank(captcha, CAPTCHA_EXPIRED);
ValidationUtils.throwIfNotEqualIgnoreCase(updateReq.getCaptcha(), captcha, "验证码错误");
RedisUtils.delete(captchaKey);
userService.updatePhone(updateReq.getNewPhone(), rawCurrentPassword, LoginHelper.getUserId());
userService.updatePhone(updateReq.getPhone(), rawOldPassword, LoginHelper.getUserId());
return R.ok("修改成功");
}

@Operation(summary = "修改邮箱", description = "修改用户邮箱")
@PatchMapping("/email")
public R<Void> updateEmail(@Validated @RequestBody UserEmailUpdateRequest updateReq) {
String rawCurrentPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq
.getCurrentPassword()));
ValidationUtils.throwIfBlank(rawCurrentPassword, DECRYPT_FAILED);
String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + updateReq.getNewEmail();
String rawOldPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq
.getOldPassword()));
ValidationUtils.throwIfBlank(rawOldPassword, DECRYPT_FAILED);
String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + updateReq.getEmail();
String captcha = RedisUtils.get(captchaKey);
ValidationUtils.throwIfBlank(captcha, CAPTCHA_EXPIRED);
ValidationUtils.throwIfNotEqualIgnoreCase(updateReq.getCaptcha(), captcha, "验证码错误");
RedisUtils.delete(captchaKey);
userService.updateEmail(updateReq.getNewEmail(), rawCurrentPassword, LoginHelper.getUserId());
userService.updateEmail(updateReq.getEmail(), rawOldPassword, LoginHelper.getUserId());
return R.ok("修改成功");
}

Expand Down

0 comments on commit 61dd3a4

Please sign in to comment.