Skip to content

Commit

Permalink
chore: continew-starter 2.0.0 => 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed May 13, 2024
1 parent d320c95 commit fac7c86
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import lombok.Setter;
import org.hibernate.validator.constraints.Length;
import top.continew.admin.common.constant.RegexConstants;
import top.continew.starter.core.util.StrUtils;

import java.io.Serial;
import java.io.Serializable;
Expand Down Expand Up @@ -130,9 +131,8 @@ public GenConfigDO(String tableName) {
}

public String getClassNamePrefix() {
String rawClassName = StrUtil.isNotBlank(this.tablePrefix)
? StrUtil.removePrefix(this.tableName, this.tablePrefix)
: this.tableName;
String rawClassName = StrUtils.blankToDefault(this.tablePrefix, this.tableName, prefix -> StrUtil
.removePrefix(this.tableName, prefix));
return StrUtil.upperFirst(StrUtil.toCamelCase(rawClassName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,14 @@ private void isPasswordLocked(String username, boolean isError) {
if (maxErrorCount <= 0) {
return;
}
String key = CacheConstants.USER_KEY_PREFIX + "PASSWORD-ERROR:" + username;
Long currentErrorCount = RedisUtils.get(key);
currentErrorCount = currentErrorCount == null ? 0 : currentErrorCount;
int lockMinutes = optionService.getValueByCode2Int(OptionCodeEnum.PASSWORD_LOCK_MINUTES);
String key = CacheConstants.USER_KEY_PREFIX + "PASSWORD-ERROR:" + username;
long currentErrorCount = 0;
if (isError) {
// 密码错误自增次数,并重置时间
currentErrorCount = currentErrorCount + 1;
RedisUtils.set(key, currentErrorCount, Duration.ofMinutes(lockMinutes));
currentErrorCount = RedisUtils.incr(key);
RedisUtils.expire(key, Duration.ofMinutes(lockMinutes));
}
CheckUtils.throwIf(currentErrorCount >= maxErrorCount, "密码错误已达 {} 次,账户锁定 {} 分钟", maxErrorCount, lockMinutes);
CheckUtils.throwIf(currentErrorCount > maxErrorCount, "密码错误已达 {} 次,账户锁定 {} 分钟", maxErrorCount, lockMinutes);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import top.continew.admin.system.service.UserService;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.ExceptionUtils;
import top.continew.starter.core.util.StrUtils;
import top.continew.starter.log.core.dao.LogDao;
import top.continew.starter.log.core.model.LogRecord;
import top.continew.starter.log.core.model.LogRequest;
Expand Down Expand Up @@ -67,9 +68,7 @@ public void add(LogRecord logRecord) {
LogDO logDO = new LogDO();
logDO.setDescription(logRecord.getDescription());
String module = logRecord.getModule();
logDO.setModule(StrUtil.isNotBlank(module)
? logRecord.getModule().replace("API", StringConstants.EMPTY).trim()
: null);
logDO.setModule(StrUtils.blankToDefault(module, null, m -> m.replace("API", StringConstants.EMPTY).trim()));
logDO.setCreateTime(LocalDateTime.ofInstant(logRecord.getTimestamp(), ZoneId.systemDefault()));
logDO.setTimeTaken(logRecord.getTimeTaken().toMillis());
// 请求信息
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.dromara.x.file.storage.core.FileInfo;
import top.continew.admin.system.enums.FileTypeEnum;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.StrUtils;
import top.continew.starter.core.util.URLUtils;
import top.continew.starter.extension.crud.model.entity.BaseDO;

Expand Down Expand Up @@ -93,9 +94,8 @@ public class FileDO extends BaseDO {
*/
public FileInfo toFileInfo(String storageCode) {
FileInfo fileInfo = new FileInfo();
fileInfo.setOriginalFilename(StrUtil.isNotBlank(this.extension)
? this.name + StringConstants.DOT + this.extension
: this.name);
fileInfo.setOriginalFilename(StrUtils
.blankToDefault(this.extension, this.name, ex -> this.name + StringConstants.DOT + ex));
fileInfo.setSize(this.size);
fileInfo.setUrl(this.url);
fileInfo.setExt(this.extension);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public FileInfo upload(MultipartFile file, String storageCode) {
storage = storageService.getByCode(storageCode);
CheckUtils.throwIfNotExists(storage, "StorageDO", "Code", storageCode);
}

UploadPretreatment uploadPretreatment = fileStorageService.of(file)
.thumbnail(img -> img.size(100, 100))
.setPlatform(storage.getCode())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ public void delete(List<Long> ids) {
}

@Override
@Transactional(rollbackFor = Exception.class)
public String uploadAvatar(MultipartFile avatarFile, Long id) {
String avatarImageType = FileNameUtil.extName(avatarFile.getOriginalFilename());
CheckUtils.throwIf(!StrUtil.equalsAnyIgnoreCase(avatarImageType, avatarSupportSuffix), "头像仅支持 {} 格式的图片", String
Expand Down Expand Up @@ -290,7 +289,6 @@ public void resetPassword(UserPasswordResetReq req, Long id) {
}

@Override
@Transactional(rollbackFor = Exception.class)
public void updateRole(UserRoleUpdateReq updateReq, Long id) {
super.getById(id);
// 保存用户和角色关联
Expand Down Expand Up @@ -335,31 +333,7 @@ protected void fill(Object obj) {
}

@Override
protected void beforeAdd(UserReq req) {
final String errorMsgTemplate = "新增失败,[{}] 已存在";
String username = req.getUsername();
CheckUtils.throwIf(this.isNameExists(username, null), errorMsgTemplate, username);
String email = req.getEmail();
CheckUtils.throwIf(StrUtil.isNotBlank(email) && this.isEmailExists(email, null), errorMsgTemplate, email);
String phone = req.getPhone();
CheckUtils.throwIf(StrUtil.isNotBlank(phone) && this.isPhoneExists(phone, null), errorMsgTemplate, phone);
}

@Override
protected void afterAdd(UserReq req, UserDO user) {
Long userId = user.getId();
baseMapper.lambdaUpdate().set(UserDO::getPwdResetTime, LocalDateTime.now()).eq(UserDO::getId, userId).update();
// 保存用户和角色关联
userRoleService.add(req.getRoleIds(), userId);
}

/**
* 构建 QueryWrapper
*
* @param query 查询条件
* @return QueryWrapper
*/
private QueryWrapper<UserDO> buildQueryWrapper(UserQuery query) {
protected QueryWrapper<UserDO> buildQueryWrapper(UserQuery query) {
String description = query.getDescription();
Integer status = query.getStatus();
List<Date> createTimeList = query.getCreateTime();
Expand All @@ -382,6 +356,25 @@ private QueryWrapper<UserDO> buildQueryWrapper(UserQuery query) {
});
}

@Override
protected void beforeAdd(UserReq req) {
final String errorMsgTemplate = "新增失败,[{}] 已存在";
String username = req.getUsername();
CheckUtils.throwIf(this.isNameExists(username, null), errorMsgTemplate, username);
String email = req.getEmail();
CheckUtils.throwIf(StrUtil.isNotBlank(email) && this.isEmailExists(email, null), errorMsgTemplate, email);
String phone = req.getPhone();
CheckUtils.throwIf(StrUtil.isNotBlank(phone) && this.isPhoneExists(phone, null), errorMsgTemplate, phone);
}

@Override
protected void afterAdd(UserReq req, UserDO user) {
Long userId = user.getId();
baseMapper.lambdaUpdate().set(UserDO::getPwdResetTime, LocalDateTime.now()).eq(UserDO::getId, userId).update();
// 保存用户和角色关联
userRoleService.add(req.getRoleIds(), userId);
}

/**
* 名称是否存在
*
Expand Down
2 changes: 1 addition & 1 deletion continew-admin-webapi/src/main/resources/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
\____|\___/ |_| |_| \__||_||_| \_| \___| \_/\_/ /_/ \_\\__,_||_| |_| |_||_||_| |_|

:: ${project.name} :: v${project.version}
:: ContiNew Starter :: v2.0.0
:: ContiNew Starter :: v2.0.1
:: Spring Boot :: v${spring-boot.version}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>top.continew</groupId>
<artifactId>continew-starter</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
</parent>

<groupId>top.continew</groupId>
Expand Down

0 comments on commit fac7c86

Please sign in to comment.