v1.0.3
CI / build-deploy (pull_request) Failing after 2m52s
CI / notify-on-failure (pull_request) Successful in 0s

This commit is contained in:
Timi
2026-08-01 01:13:08 +08:00
parent ce22661a9b
commit 15bf9bd688
31 changed files with 131 additions and 145 deletions
+7 -2
View File
@@ -173,7 +173,7 @@
<dependency>
<groupId>com.imyeyu.spring</groupId>
<artifactId>timi-spring</artifactId>
<version>0.0.16</version>
<version>0.0.17</version>
</dependency>
<dependency>
<groupId>com.imyeyu.network</groupId>
@@ -183,7 +183,12 @@
<dependency>
<groupId>com.imyeyu.lang</groupId>
<artifactId>timi-lang</artifactId>
<version>0.0.4</version>
<version>0.0.5</version>
</dependency>
<dependency>
<groupId>com.imyeyu.java</groupId>
<artifactId>timi-java</artifactId>
<version>0.0.6</version>
</dependency>
<dependency>
<groupId>com.imyeyu.utils</groupId>
@@ -40,7 +40,7 @@ public class RequestRateLimitInterceptor extends RequestRateLimitAbstractInterce
redis.setAndKeepTTL(key, ++count);
} else {
log.warn("请求频率过高:[" + key + "].C" + count + "L" + limit);
throw new TimiException(TimiCode.REQUEST_BAD).msgKey("request_rate_limit");
throw new TimiException(TimiCode.REQUEST_BAD, "request_rate_limit");
}
}
return true;
@@ -97,7 +97,7 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
}
} catch (Exception e) {
log.error("delete mongo file error, id={}", attach.getId(), e);
throw new TimiException(TimiCode.ERROR).msgKey("TODO delete mongo file error");
throw new TimiException(TimiCode.ERROR, "TODO delete mongo file error");
}
};
mapper.selectThumbsBySourceId(id).forEach(doDestroy::handler);
@@ -145,7 +145,7 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(mongoId)));
}
log.error("create error", e);
throw new TimiException(TimiCode.ARG_BAD).msgKey("TODO read attachment input stream error");
throw new TimiException(TimiCode.ARG_BAD, "TODO read attachment input stream error");
}
}
@@ -200,7 +200,7 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
gridFsTemplate.delete(Query.query(Criteria.where("_id").is(newMongoId)));
}
log.error("update error", e);
throw new TimiException(TimiCode.ERROR).msgKey("TODO update file error");
throw new TimiException(TimiCode.ERROR, "TODO update file error");
}
}
@@ -271,7 +271,7 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
return thumb;
} catch (Exception e) {
log.error("create thumbnail error", e);
throw new TimiException(TimiCode.ERROR).msgKey("exception.attachment.create.error");
throw new TimiException(TimiCode.ERROR, "exception.attachment.create.error");
}
}
@@ -354,7 +354,7 @@ public class AttachmentServiceImplement extends AbstractEntityService<Attachment
if (isNew) {
// 请求有、数据库无:将临时文件记录直接转存为永久附件
if (TimiJava.isEmpty(tempFileId)) {
throw new TimiException(TimiCode.ERROR).msgKey("exception.attachment.file.required");
throw new TimiException(TimiCode.ERROR, "exception.attachment.file.required");
}
Attachment tempFile = mapper.selectRaw(tempFileId);
tempFile.setBizType(bizType);
@@ -51,11 +51,11 @@ public class ClipboardServiceImplement implements ClipboardService {
public void setContent(String id, String content) {
validateId(id);
if (content == null) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("剪切板内容不能为空");
throw new TimiException(TimiCode.ARG_MISS, "剪切板内容不能为空");
}
byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
if (MAX_CONTENT_SIZE < contentBytes.length) {
throw new TimiException(TimiCode.ARG_BAD).msgKey("剪切板内容不能超过 10MB");
throw new TimiException(TimiCode.ARG_BAD, "剪切板内容不能超过 10MB");
}
redisClipboard.set(getKey(id), content, Time.D * 7);
notifySubscribers(id, content);
@@ -78,7 +78,7 @@ public class ClipboardServiceImplement implements ClipboardService {
private void validateId(String id) {
if (TimiJava.isEmpty(id)) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("id 不能为空");
throw new TimiException(TimiCode.ARG_MISS, "id 不能为空");
}
}
@@ -39,7 +39,9 @@ public class MultilingualServiceImplement extends AbstractEntityService<Multilin
Multilingual result = redisLanguage.get(getKey(id));
if (result == null) {
result = super.get(id);
redisLanguage.set(getKey(id), result, Time.D * 7);
if (result != null) {
redisLanguage.set(getKey(id), result, Time.D * 7);
}
}
return result;
}
@@ -18,6 +18,9 @@ public interface GaoCustomerMapper extends BaseMapper<GaoCustomer, String> {
@Select("SELECT * FROM `gao_customer` WHERE `code` = #{code} AND `deleted_at` IS NULL LIMIT 1")
GaoCustomer selectByCode(@Param("code") String code);
@Select("SELECT * FROM `gao_customer` WHERE `name` = #{name} AND `deleted_at` IS NULL LIMIT 1")
GaoCustomer selectByName(@Param("name") String name);
List<GaoCustomer> search(@Param("keyword") String keyword, @Param("introducerCustomerId") String introducerCustomerId);
Long countSearch(@Param("keyword") String keyword, @Param("introducerCustomerId") String introducerCustomerId);
@@ -258,10 +258,16 @@ public class GaoCustomerServiceImplement extends AbstractEntityService<GaoCustom
TimiException.required(entity.getId(), "not found customer.id");
}
TimiException.required(entity.getName(), "not found customer.name");
entity.setName(entity.getName().trim());
TimiException.requiredTrue(!entity.getName().isEmpty(), "not found customer.name");
GaoCustomer dbCustomer = mapper.selectByName(entity.getName());
if (dbCustomer != null && !dbCustomer.getId().equals(entity.getId())) {
throw new TimiException(TimiCode.ARG_BAD, "客户姓名已存在");
}
if (TimiJava.isNotEmpty(entity.getCode())) {
GaoCustomer dbCustomer = mapper.selectByCode(entity.getCode());
dbCustomer = mapper.selectByCode(entity.getCode());
if (dbCustomer != null && !dbCustomer.getId().equals(entity.getId())) {
throw new TimiException(TimiCode.ARG_BAD).msgKey("客户编码已存在");
throw new TimiException(TimiCode.ARG_BAD, "客户编码已存在");
}
}
if (TimiJava.isNotEmpty(entity.getIntroducerCustomerId())) {
@@ -99,7 +99,7 @@ public class GaoUserServiceImplement extends AbstractEntityService<GaoUser, Stri
TimiException.required(userMapper.select(entity.getUserId()), "not found user");
GaoUser dbGaoUser = mapper.selectByUserId(entity.getUserId());
if (dbGaoUser != null && !dbGaoUser.getId().equals(entity.getId())) {
throw new TimiException(TimiCode.ARG_BAD).msgKey("GAO 用户已存在");
throw new TimiException(TimiCode.ARG_BAD, "GAO 用户已存在");
}
if (entity.getEnabled() == null) {
entity.setEnabled(true);
@@ -45,7 +45,7 @@ public class JournalAPIInterceptor implements HandlerInterceptor {
requiredUploadPermission = handlerMethod.getMethodAnnotation(RequiredUploadPermission.class) != null;
}
if (!canAccess()) {
throw new TimiException(TimiCode.PERMISSION_MISS).msgKey("invalid.key");
throw new TimiException(TimiCode.PERMISSION_MISS, "invalid.key");
}
return !requiredUploadPermission || canUploadKey();
}
@@ -37,7 +37,7 @@ public class LyricController {
// @PostMapping("/correct")
// public long correctRequest(CaptchaData<LyricCorrectRequest> request) {
// if (IOSize.MB * 120 < request.getData().getFile().getSize()) {
// throw new TimiException(TimiCode.ARG_BAD).msgKey("lyric.correct_request.too_big");
// throw new TimiException(TimiCode.ARG_BAD, "lyric.correct_request.too_big");
// }
// return correctService.correctRequest(request.getData());
// }
@@ -135,7 +135,7 @@ public class LyricServiceImplement extends AbstractEntityService<Lyric, String>
return lyric;
} catch (Exception e) {
log.error("fetch lyric fail", e);
throw new TimiException(TimiCode.ERROR).msgKey("无法获取歌词");
throw new TimiException(TimiCode.ERROR, "无法获取歌词");
}
}
}
@@ -94,7 +94,7 @@ abstract class AbstractMirror {
onException(mirror, e);
if (e instanceof TimiException te) {
log.warn("[%s] Fail: %s".formatted(mirror.getBean(), te.getMsg()));
log.warn("[%s] Fail: %s".formatted(mirror.getBean(), te.getMessage()));
} else {
log.error("[%s] Error".formatted(mirror.getBean()), e);
}
@@ -132,7 +132,7 @@ public class TerminalPipe implements TimiJava {
*/
public void exec(CallbackArg<String> callback, String command) {
if (status == Status.DIED) {
throw new TimiException(TimiCode.RESULT_BAD).msgKey("该会话已终止");
throw new TimiException(TimiCode.RESULT_BAD, "该会话已终止");
}
this.status = Status.RUNNING;
this.callback = callback;
@@ -87,7 +87,7 @@ public class FileController implements TimiJava, OS.FileSystem {
public ServerFile object(HttpServletRequest req, HttpServletResponse resp) {
String path = req.getServletPath().substring("/system/file/object".length());
if (TimiJava.isEmpty(path)) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("TODO 缺少参数:object");
throw new TimiException(TimiCode.ARG_MISS, "TODO 缺少参数:object");
}
ServerFile file = new ServerFile(new File(path));
service.checkAccessPermission(file.getAbsolutePath());
@@ -105,10 +105,10 @@ public class FileController implements TimiJava, OS.FileSystem {
@PostMapping("/search")
public List<ServerFile> search(@RequestBody Map<String, String> params) {
if (TimiJava.isEmpty(params.get("path"))) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:path");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:path");
}
if (TimiJava.isEmpty(params.get("keyword"))) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:keyword");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:keyword");
}
return service.doFilter(service.search(params.get("path"), params.get("keyword")));
}
@@ -126,7 +126,7 @@ public class FileController implements TimiJava, OS.FileSystem {
public boolean exist(HttpServletRequest req, HttpServletResponse resp) {
String path = req.getServletPath().substring("/system/file/exist".length());
if (TimiJava.isEmpty(path)) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:path");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:path");
}
return service.canAccess(path) && service.isExist(path);
}
@@ -237,10 +237,10 @@ public class FileController implements TimiJava, OS.FileSystem {
@PostMapping("/mkdir")
public String mkdir(@RequestBody Map<String, String> params) {
if (TimiJava.isEmpty(params.get("path"))) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:path");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:path");
}
if (TimiJava.isEmpty(params.get("name"))) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:name");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:name");
}
return service.mkdir(params.get("path"), params.get("name")).getAbsolutePath();
}
@@ -256,10 +256,10 @@ public class FileController implements TimiJava, OS.FileSystem {
@PostMapping("/rename")
public boolean rename(@RequestBody Map<String, String> params) {
if (TimiJava.isEmpty(params.get("from"))) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:from");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:from");
}
if (TimiJava.isEmpty(params.get("to"))) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:to");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:to");
}
return service.rename(params.get("from"), params.get("to"));
}
@@ -275,10 +275,10 @@ public class FileController implements TimiJava, OS.FileSystem {
@PostMapping("/zip")
public String zip(@RequestBody ListFileToRequest listFileToRequest) {
if (TimiJava.isEmpty(listFileToRequest.getList())) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:list[]");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:list[]");
}
if (TimiJava.isEmpty(listFileToRequest.getTo())) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:to");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:to");
}
// 异步任务
FileZipAsyncTask task = new FileZipAsyncTask(listFileToRequest.getList(), listFileToRequest.getTo());
@@ -298,14 +298,14 @@ public class FileController implements TimiJava, OS.FileSystem {
public String unzip(@RequestBody Map<String, String> params) {
String zipFilePath = params.get("zipFile");
if (TimiJava.isEmpty(zipFilePath)) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:zipFile");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:zipFile");
}
File zipFile = new File(zipFilePath);
if (!zipFile.exists()) {
throw new TimiException(TimiCode.ARG_BAD).msgKey("文件不存在:" + zipFilePath);
throw new TimiException(TimiCode.ARG_BAD, "文件不存在:" + zipFilePath);
}
if (TimiJava.isEmpty(params.get("to"))) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:to");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:to");
}
// 异步任务
FileUnZipAsyncTask task = new FileUnZipAsyncTask(zipFile, params.get("to"));
@@ -341,14 +341,14 @@ public class FileController implements TimiJava, OS.FileSystem {
// TODO 具名入参
String tarFilePath = params.get("tarFile");
if (TimiJava.isEmpty(tarFilePath)) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:tarFile");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:tarFile");
}
File tarFile = new File(tarFilePath);
if (!tarFile.exists()) {
throw new TimiException(TimiCode.ARG_BAD).msgKey("文件不存在:" + tarFilePath);
throw new TimiException(TimiCode.ARG_BAD, "文件不存在:" + tarFilePath);
}
if (TimiJava.isEmpty(params.get("to"))) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:to");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:to");
}
FileUnTarAsyncTask task = new FileUnTarAsyncTask(tarFile, params.get("to"));
asyncTaskService.addAsyncTask(task);
@@ -116,7 +116,7 @@ public abstract class AbstractAsyncTask extends AsyncTask {
/** 开始 */
void start() {
if (status != AsyncTask.Status.IDLE && status != AsyncTask.Status.PAUSE) {
throw new TimiException(TimiCode.RESULT_BAD).msgKey("can not start this task");
throw new TimiException(TimiCode.RESULT_BAD, "can not start this task");
}
synchronized (pauseLocker) {
pauseLocker.notifyAll();
@@ -127,7 +127,7 @@ public abstract class AbstractAsyncTask extends AsyncTask {
/** 暂停 */
void pause() {
if (!canPause || (status != AsyncTask.Status.WAITING && status != AsyncTask.Status.RUNNING)) {
throw new TimiException(TimiCode.RESULT_BAD).msgKey("can not pause this task");
throw new TimiException(TimiCode.RESULT_BAD, "can not pause this task");
}
status = Status.PAUSE;
onPause();
@@ -139,7 +139,7 @@ public abstract class AbstractAsyncTask extends AsyncTask {
return;
}
if (!canInterrupt || (status != AsyncTask.Status.WAITING && status != AsyncTask.Status.RUNNING && status != AsyncTask.Status.PAUSE)) {
throw new TimiException(TimiCode.RESULT_BAD).msgKey("can not interrupt this task");
throw new TimiException(TimiCode.RESULT_BAD, "can not interrupt this task");
}
if (status == AsyncTask.Status.PAUSE) {
status = AsyncTask.Status.INTERRUPT;
@@ -109,7 +109,7 @@ public class AsyncTaskServiceImplement implements AsyncTaskService {
task.setMessage(task.logBuffer.toString());
return task;
}
throw new TimiException(TimiCode.RESULT_NULL).msgKey("TODO not found task");
throw new TimiException(TimiCode.RESULT_NULL, "TODO not found task");
}
@Override
@@ -114,7 +114,7 @@ public class FileServiceImplement implements TimiJava, FileService {
if (canAccess(path)) {
return;
}
throw new TimiException(TimiCode.PERMISSION_ERROR).msgKey("TODO invalid permission");
throw new TimiException(TimiCode.PERMISSION_ERROR, "TODO invalid permission");
}
@Override
@@ -139,7 +139,7 @@ public class FileServiceImplement implements TimiJava, FileService {
}
return result;
} else {
throw new TimiException(TimiCode.RESULT_NULL).msgKey("文件或路径不存在");
throw new TimiException(TimiCode.RESULT_NULL, "文件或路径不存在");
}
}
@@ -176,7 +176,7 @@ public class FileServiceImplement implements TimiJava, FileService {
}
return result;
} else {
throw new TimiException(TimiCode.RESULT_NULL).msgKey("文件或路径不存在");
throw new TimiException(TimiCode.RESULT_NULL, "文件或路径不存在");
}
}
@@ -186,7 +186,7 @@ public class FileServiceImplement implements TimiJava, FileService {
try {
return IO.dir(uri);
} catch (NoPermissionException e) {
throw new TimiException(TimiCode.PERMISSION_ERROR).msgKey("权限错误");
throw new TimiException(TimiCode.PERMISSION_ERROR, "权限错误");
}
}
@@ -205,7 +205,7 @@ public class FileServiceImplement implements TimiJava, FileService {
try {
return IO.getInputStream(getPath(path));
} catch (FileNotFoundException e) {
throw new TimiException(TimiCode.RESULT_NULL).msgKey("找不到文件");
throw new TimiException(TimiCode.RESULT_NULL, "找不到文件");
}
}
@@ -213,25 +213,25 @@ public class FileServiceImplement implements TimiJava, FileService {
public void upload(TransferFile file) {
String path = getPath(Decoder.url(file.getPath()));
if (file.getName() == null) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少参数:name");
throw new TimiException(TimiCode.ARG_MISS, "缺少参数:name");
}
String fileName = Decoder.url(file.getName());
if (!OS.isValidFileName(path)) {
throw new TimiException(TimiCode.ARG_BAD).msgKey("路径名称不合法:" + path);
throw new TimiException(TimiCode.ARG_BAD, "路径名称不合法:" + path);
}
if (!OS.isValidFileName(fileName)) {
throw new TimiException(TimiCode.ARG_BAD).msgKey("文件名称不合法:" + fileName);
throw new TimiException(TimiCode.ARG_BAD, "文件名称不合法:" + fileName);
}
if (file.getLength() == file.getFile().getSize()) {
try {
toFile(new File(path + fileName), file.getFile().getInputStream());
} catch (IOException e) {
log.error("get request input stream error", e);
throw new TimiException(TimiCode.ARG_BAD).msgKey("获取文件输入流失败");
throw new TimiException(TimiCode.ARG_BAD, "获取文件输入流失败");
}
} else {
log.error("request submit request size: {}, receive request size: {}", file.getLength(), file.getFile().getSize());
throw new TimiException(TimiCode.ERROR).msgKey("不完整上传文件,已忽略");
throw new TimiException(TimiCode.ERROR, "不完整上传文件,已忽略");
}
}
@@ -63,7 +63,7 @@ public class FileMoveAsyncTask extends AbstractAsyncTask {
File toFile = new File(IO.fitPath(to) + item.getValue());
IO.dir(toFile.getParent());
if (!item.getKey().renameTo(toFile)) {
throw new TimiException(TimiCode.ERROR).msgKey("移动失败:" + item.getKey().getAbsolutePath() + " -> " + toFile.getAbsolutePath());
throw new TimiException(TimiCode.ERROR, "移动失败:" + item.getKey().getAbsolutePath() + " -> " + toFile.getAbsolutePath());
}
}
@@ -67,10 +67,10 @@ public class DockerEngineClient {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.error("docker engine request interrupted: {}", requestPath, e);
throw new TimiException(TimiCode.ERROR).msgKey("TODO docker engine request interrupted");
throw new TimiException(TimiCode.ERROR, "TODO docker engine request interrupted");
} catch (IOException e) {
log.error("docker engine request error: {}", requestPath, e);
throw new TimiException(TimiCode.ERROR).msgKey("TODO docker engine request error");
throw new TimiException(TimiCode.ERROR, "TODO docker engine request error");
}
}
@@ -53,7 +53,7 @@ public class SystemAPIInterceptor implements HandlerInterceptor {
// TimiSpring.setRequestAttr(HIGH_AUTHORITY, keyMap.get(key));
// return true;
// }
// throw new TimiException(TimiCode.PERMISSION_ERROR).msgKey("TODO invalid key");
// throw new TimiException(TimiCode.PERMISSION_ERROR, "TODO invalid key");
return true;
}
@@ -43,14 +43,14 @@ public class UpsStatusClient {
public JsonNode getStatusJson() {
if (statusUrl == null || statusUrl.isBlank()) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("缺少配置:ups.status-url");
throw new TimiException(TimiCode.ARG_MISS, "缺少配置:ups.status-url");
}
try {
String response = CommonRequest.post(statusUrl).bodyEntity(ArgMap.of("portName", "USBusbdev3").toEntity()).asString();
return jackson.readTree(response);
} catch (IOException e) {
log.error("request ups status error: {}", statusUrl, e);
throw new TimiException(TimiCode.ERROR).msgKey("UPS 状态请求失败");
throw new TimiException(TimiCode.ERROR, "UPS 状态请求失败");
}
}
@@ -53,7 +53,7 @@ public class PermissionCheckerImplement implements PermissionChecker {
public void checkAll(ModuleCode moduleCode, String... permissionCodeList) {
if (!hasAll(moduleCode, permissionCodeList)) {
String codeList = buildPermissionKeys(moduleCode, permissionCodeList).toString();
throw new TimiException(TimiCode.PERMISSION_ERROR).msgKey("权限不足:%s".formatted(codeList));
throw new TimiException(TimiCode.PERMISSION_ERROR, "权限不足:%s".formatted(codeList));
}
}
@@ -61,7 +61,7 @@ public class PermissionCheckerImplement implements PermissionChecker {
public void checkAny(ModuleCode moduleCode, String... permissionCodeList) {
if (!hasAny(moduleCode, permissionCodeList)) {
String codeList = buildPermissionKeys(moduleCode, permissionCodeList).toString();
throw new TimiException(TimiCode.PERMISSION_ERROR).msgKey("权限不足:%s".formatted(codeList));
throw new TimiException(TimiCode.PERMISSION_ERROR, "权限不足:%s".formatted(codeList));
}
}
@@ -8,8 +8,8 @@ import com.imyeyu.api.modules.user.mapper.PermissionMapper;
import com.imyeyu.api.modules.user.mapper.RolePermissionMapper;
import com.imyeyu.api.modules.user.service.PermissionService;
import com.imyeyu.api.modules.user.vo.permission.BatchCreateReq;
import com.imyeyu.api.util.RedisMultilingual;
import com.imyeyu.java.TimiJava;
import com.imyeyu.lang.message.MessageResolver;
import com.imyeyu.spring.TimiSpring;
import com.imyeyu.spring.mapper.BaseMapper;
import com.imyeyu.spring.service.AbstractEntityService;
@@ -35,7 +35,7 @@ public class PermissionServiceImplement extends AbstractEntityService<Permission
private final MultilingualMapper multilingualMapper;
private final MultilingualService multilingualService;
private final RedisMultilingual multilingual;
private final MessageResolver messageResolver;
@Override
protected BaseMapper<Permission, String> mapper() {
@@ -61,7 +61,7 @@ public class PermissionServiceImplement extends AbstractEntityService<Permission
permission.setId(UUID.randomUUID().toString());
permission.setModuleCode(req.getModuleCode());
permission.setCode(req.getPrefixCode() + "_" + type.name());
permission.setName(req.getPrefixName() + multilingual.map(TimiSpring.getLanguage()).text(type.name().toLowerCase()));
permission.setName(req.getPrefixName() + messageResolver.resolve(type.name().toLowerCase(), null, TimiSpring.getLanguage()));
permission.setCreatedAt(Time.now());
permissionList.add(permission);
}
@@ -47,14 +47,14 @@ public class RoleCheckerImplement implements RoleChecker {
@Override
public void checkAll(ModuleCode moduleCode, String... roleCodeList) {
if (!hasAll(moduleCode, roleCodeList)) {
throw new TimiException(TimiCode.PERMISSION_ERROR).msgKey("require role: %s".formatted(buildRoleKeys(moduleCode, roleCodeList)));
throw new TimiException(TimiCode.PERMISSION_ERROR, "require role: %s".formatted(buildRoleKeys(moduleCode, roleCodeList)));
}
}
@Override
public void checkAny(ModuleCode moduleCode, String... roleCodeList) {
if (!hasAny(moduleCode, roleCodeList)) {
throw new TimiException(TimiCode.PERMISSION_ERROR).msgKey("require role: %s".formatted(buildRoleKeys(moduleCode, roleCodeList)));
throw new TimiException(TimiCode.PERMISSION_ERROR, "require role: %s".formatted(buildRoleKeys(moduleCode, roleCodeList)));
}
}
@@ -159,7 +159,7 @@ public class RoleServiceImplement extends AbstractEntityService<Role, String> im
TimiException.required(req, "not found req");
TimiException.required(req.getUserId(), "not found req.userId");
if (req.getModuleCode() == null) {
throw new TimiException(TimiCode.ARG_MISS).msgKey("moduleCode");
throw new TimiException(TimiCode.ARG_MISS, "moduleCode");
}
List<UserRole> bindingList = userRoleService.listByUserId(req.getUserId());
List<String> bindingRoleIdList = bindingList.stream().map(UserRole::getRoleId).toList();
@@ -200,10 +200,10 @@ public class CaptchaManager {
String cacheKey = CACHE_KEY.formatted(uniqueId);
String cacheValue = redisCaptcha.get(cacheKey);
if (TimiJava.isEmpty(cacheValue)) {
throw new TimiException(TimiCode.ARG_EXPIRED).msgKey("captcha.expire");
throw new TimiException(TimiCode.ARG_EXPIRED, "captcha.expire");
}
if (!value.trim().equalsIgnoreCase(cacheValue)) {
throw new TimiException(TimiCode.RESULT_BAD).msgKey("captcha.error");
throw new TimiException(TimiCode.RESULT_BAD, "captcha.error");
}
// 清除缓存
redisCaptcha.destroy(cacheKey);
@@ -1,9 +1,6 @@
package com.imyeyu.api.util;
import com.imyeyu.api.modules.common.service.SettingService;
import com.imyeyu.lang.mapper.AbstractLanguageMapper;
import com.imyeyu.spring.TimiSpring;
import com.imyeyu.spring.util.GlobalReturnHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.jgit.api.ArchiveCommand;
@@ -42,20 +39,11 @@ public class InitApplication implements ApplicationRunner {
private String devLang;
private final SettingService settingService;
private final RedisMultilingual redisMultilingual;
private final GlobalReturnHandler globalReturnHandler;
private void initGitCommand() {
ArchiveCommand.registerFormat("tar.gz", new TarFormat());
}
private void initMultilingual() {
globalReturnHandler.setMultilingualHeader(mapping -> {
AbstractLanguageMapper map = redisMultilingual.map(TimiSpring.getLanguage());
return map.textArgs(mapping.getMsgKey(), mapping.getMsgArgs());
});
}
@Override
public void run(ApplicationArguments args) throws Exception {
Method[] methods = getClass().getDeclaredMethods();
@@ -1,43 +0,0 @@
package com.imyeyu.api.util;
import com.imyeyu.api.TimiServerAPI;
import com.imyeyu.api.modules.common.service.MultilingualService;
import com.imyeyu.java.bean.Language;
import com.imyeyu.lang.mapper.AbstractLanguageMapper;
import com.imyeyu.utils.StringInterpolator;
import org.jcodec.api.NotSupportedException;
import java.util.Map;
/**
* @author 夜雨
* @version 2024-04-03 11:01
*/
public class RedisLanguage extends AbstractLanguageMapper {
private static final StringInterpolator INTERPOLATOR = new StringInterpolator(StringInterpolator.SIMPLE_OBJ);
public RedisLanguage(Language.Enum language) {
super(language);
}
@Override
public void add(String id, String value) {
throw new NotSupportedException("not supported to add value, MultilingualService will auto cache when not found value");
}
@Override
public boolean has(String id) {
return text(id).equals(id);
}
@Override
public String text(String id) {
return TimiServerAPI.applicationContext.getBean(MultilingualService.class).get(id).getValue(language);
}
@Override
public String textArgs(String id, Map<String, Object> args) {
return INTERPOLATOR.inject(text(id), args);
}
}
@@ -0,0 +1,44 @@
package com.imyeyu.api.util;
import com.imyeyu.api.modules.common.entity.Multilingual;
import com.imyeyu.api.modules.common.service.MultilingualService;
import com.imyeyu.java.TimiJava;
import com.imyeyu.java.bean.Language;
import com.imyeyu.lang.message.MessageResolver;
import com.imyeyu.utils.StringInterpolator;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* Redis 消息解析器
*
* @author 夜雨
* @since 2026-08-01 00:00
*/
@Component
@RequiredArgsConstructor
public class RedisMessageResolver implements MessageResolver {
private static final StringInterpolator INTERPOLATOR = new StringInterpolator(StringInterpolator.SIMPLE_OBJ);
private final MultilingualService multilingualService;
@Override
public String resolve(String messageCode, Map<String, Object> messageArgs, Language.Enum language) {
if (TimiJava.isEmpty(messageCode)) {
return "";
}
Language.Enum actualLanguage = language == null ? Language.Enum.zh_CN : language;
Multilingual multilingual = multilingualService.get(messageCode);
if (multilingual == null) {
return INTERPOLATOR.inject(messageCode, messageArgs);
}
String template = multilingual.getValue(actualLanguage);
if (TimiJava.isEmpty(template)) {
return INTERPOLATOR.inject(messageCode, messageArgs);
}
return INTERPOLATOR.inject(template, messageArgs);
}
}
@@ -1,24 +0,0 @@
package com.imyeyu.api.util;
import com.imyeyu.java.bean.Language;
import com.imyeyu.lang.multi.Multilingual;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
/**
* @author 夜雨
* @version 2024-04-03 11:15
*/
@Component
@RequiredArgsConstructor
public class RedisMultilingual extends Multilingual {
@PostConstruct
private void postConstruct() {
Language.Enum[] languages = Language.Enum.values();
for (Language.Enum language : languages) {
add(language, new RedisLanguage(language));
}
}
}
@@ -0,0 +1,5 @@
ALTER TABLE `gao_customer`
ADD COLUMN `active_name` VARCHAR(64) GENERATED ALWAYS AS (
CASE WHEN `deleted_at` IS NULL THEN NULLIF(TRIM(`name`), '') ELSE NULL END
) STORED COMMENT '未删除客户姓名' INVISIBLE,
ADD UNIQUE KEY `uk_gao_customer_active_name` (`active_name`);