refactor: 优化公共工具类代码规范

- 移除所有行尾注释,改为独立行注释
- 优化代码可读性和维护性
- 涉及枚举、拦截器、日期工具、文件工具等核心工具类
- 统一注释风格,符合项目规范
This commit is contained in:
Leo 2025-07-07 14:45:44 +08:00
parent 044b642f3a
commit 262a63735f
9 changed files with 84 additions and 42 deletions

View File

@ -9,15 +9,23 @@ package org.leocoder.thin.common.enmus.common;
public interface IResultEnum { public interface IResultEnum {
// 项目服务名 系统编码 // 项目服务名 系统编码
String A = "101"; // 前台系统 // 前台系统
String B = "202"; // APP系统 String A = "101";
// APP系统
String B = "202";
String LOGIN = "100"; // 登录 // 登录
String USER = "101"; // 用户 String LOGIN = "100";
String ROLE = "102"; // 角色 // 用户
String PERMISSION = "103"; // 菜单 String USER = "101";
String LOGIN_LOG = "106"; // 登录日志 // 角色
String OPER_LOG = "107"; // 操作日志 String ROLE = "102";
// 菜单
String PERMISSION = "103";
// 登录日志
String LOGIN_LOG = "106";
// 操作日志
String OPER_LOG = "107";
// 成功状态常量 // 成功状态常量
int SUCCESS = 200; int SUCCESS = 200;

View File

@ -90,7 +90,8 @@ public class CoderIpBlockListInterceptor implements HandlerInterceptor {
} }
} }
} }
} else { // 没有白名单Redis数据不进行校验 // 没有白名单Redis数据不进行校验
} else {
isWhite = CoderConstants.TRUE; isWhite = CoderConstants.TRUE;
} }

View File

@ -410,8 +410,10 @@ public class DateUtil {
try { try {
long startTimeMills = startTime.getTime(); long startTimeMills = startTime.getTime();
long endTimeMills = new Date().getTime(); long endTimeMills = new Date().getTime();
long diff = (endTimeMills - startTimeMills) / 1000;// //
long day_diff = (long) Math.floor(diff / 86400);// long diff = (endTimeMills - startTimeMills) / 1000;
//
long day_diff = (long) Math.floor(diff / 86400);
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
if (day_diff < 0) { if (day_diff < 0) {
return "[error],时间越界..."; return "[error],时间越界...";
@ -670,21 +672,25 @@ public class DateUtil {
int year1 = cal1.get(Calendar.YEAR); int year1 = cal1.get(Calendar.YEAR);
int year2 = cal2.get(Calendar.YEAR); int year2 = cal2.get(Calendar.YEAR);
if (year1 != year2) // 同一年 // 同一年
if (year1 != year2)
{ {
int timeDistance = 0; int timeDistance = 0;
for (int i = year1; i < year2; i++) { for (int i = year1; i < year2; i++) {
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) // 闰年 // 闰年
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0)
{ {
timeDistance += 366; timeDistance += 366;
} else // 不是闰年 // 不是闰年
} else
{ {
timeDistance += 365; timeDistance += 365;
} }
} }
return timeDistance + (day2 - day1); return timeDistance + (day2 - day1);
} else // 不同年 // 不同年
} else
{ {
return day2 - day1; return day2 - day1;
} }
@ -710,7 +716,8 @@ public class DateUtil {
Calendar tempEnd = Calendar.getInstance(); Calendar tempEnd = Calendar.getInstance();
tempEnd.setTime(end); tempEnd.setTime(end);
tempEnd.add(Calendar.DATE, +1);// 日期加1(包含结束) // 日期加1(包含结束)
tempEnd.add(Calendar.DATE, +1);
while (tempStart.before(tempEnd)) { while (tempStart.before(tempEnd)) {
days.add(dateFormat.format(tempStart.getTime())); days.add(dateFormat.format(tempStart.getTime()));
tempStart.add(Calendar.DAY_OF_YEAR, 1); tempStart.add(Calendar.DAY_OF_YEAR, 1);

View File

@ -151,19 +151,26 @@ public class FileTypeUtil {
// 检查文件类型并返回对应的类别编号 // 检查文件类型并返回对应的类别编号
if (pictureTypeList.contains(extension)) { if (pictureTypeList.contains(extension)) {
return "1"; // 图片 // 图片
return "1";
} else if (fileTypeList.contains(extension)) { } else if (fileTypeList.contains(extension)) {
return "2"; // 文档 // 文档
return "2";
} else if (audioList.contains(extension)) { } else if (audioList.contains(extension)) {
return "3"; // 音频 // 音频
return "3";
} else if (videoList.contains(extension)) { } else if (videoList.contains(extension)) {
return "4"; // 视频 // 视频
return "4";
} else if (packageList.contains(extension)) { } else if (packageList.contains(extension)) {
return "5"; // 压缩包 // 压缩包
return "5";
} else if (applyList.contains(extension)) { } else if (applyList.contains(extension)) {
return "6"; // 应用程序 // 应用程序
return "6";
} else { } else {
return "7"; // 其他 // 其他
return "7";
} }
} }

View File

@ -83,10 +83,12 @@ public class TextUtil {
public static void writeRowText(String filePath, String content) { public static void writeRowText(String filePath, String content) {
/* 一行一行写txt文件追加内容 */ /* 一行一行写txt文件追加内容 */
try { try {
FileWriter writer = new FileWriter(filePath, true); // 创建文件写入器参数为要写入的文件路径第二个参数为true表示以追加模式写入 // 创建文件写入器参数为要写入的文件路径第二个参数为true表示以追加模式写入
FileWriter writer = new FileWriter(filePath, true);
String[] splitArray = content.split("/n"); String[] splitArray = content.split("/n");
for (String rowSplit : splitArray) { for (String rowSplit : splitArray) {
writer.write(rowSplit); // 按行写入文本数据每行末尾加上换行符 // 按行写入文本数据每行末尾加上换行符
writer.write(rowSplit);
} }
writer.close(); writer.close();
} catch (Exception e) { } catch (Exception e) {

View File

@ -75,16 +75,22 @@ public class UploadUtil {
} catch (IllegalStateException | IOException e) { } catch (IllegalStateException | IOException e) {
log.error("上传文件异常信息:{}", e.getMessage()); log.error("上传文件异常信息:{}", e.getMessage());
} }
map.put("fileSize", fileSize); // 文件大小 // 文件大小
map.put("fileName", originalFilename); // 原文件名字 map.put("fileSize", fileSize);
map.put("suffixName", suffixName); // 文件后缀 // 原文件名字
map.put("fileName", originalFilename);
// 文件后缀
map.put("suffixName", suffixName);
int index = fileUploadPath.indexOf(":"); int index = fileUploadPath.indexOf(":");
String fileUploadPathString = fileUploadPath.substring(index + 1) + newName; String fileUploadPathString = fileUploadPath.substring(index + 1) + newName;
// 文件上传路径 // 文件上传路径
log.info("文件上传路径fileUploadPath{}", fileUploadPathString); log.info("文件上传路径fileUploadPath{}", fileUploadPathString);
map.put("fileUploadPath", fileUploadPathString); // 文件上传路径 // 文件上传路径
map.put("newName", newName); // 新文件名字 map.put("fileUploadPath", fileUploadPathString);
map.put("filePath", absoluteFilePath); // 绝对文件路径 // 新文件名字
map.put("newName", newName);
// 绝对文件路径
map.put("filePath", absoluteFilePath);
return map; return map;
} }

View File

@ -19,11 +19,16 @@ public class EscapeUtil {
} }
// special HTML characters // special HTML characters
TEXT['\''] = "&#039;".toCharArray(); // 单引号 // 单引号
TEXT['"'] = "&#34;".toCharArray(); // 双引号 TEXT['\''] = "&#039;".toCharArray();
TEXT['&'] = "&#38;".toCharArray(); // & // 双引号
TEXT['<'] = "&#60;".toCharArray(); // 小于号 TEXT['"'] = "&#34;".toCharArray();
TEXT['>'] = "&#62;".toCharArray(); // 大于号 // &
TEXT['&'] = "&#38;".toCharArray();
// 小于号
TEXT['<'] = "&#60;".toCharArray();
// 大于号
TEXT['>'] = "&#62;".toCharArray();
} }
/** /**

View File

@ -33,11 +33,15 @@ public class GenBatchUtil {
public static void main(String[] args) { public static void main(String[] args) {
// GenBatchUtil batchUtil = new GenBatchUtil(); // GenBatchUtil batchUtil = new GenBatchUtil();
// String serialNumber = batchUtil.getBatchNumber("Coder", 12, 10); // 生成12位流水编号 // 生成12位流水编号
// System.out.println(serialNumber); // 输出生成的12位流水编号 // String serialNumber = batchUtil.getBatchNumber("Coder", 12, 10);
// 输出生成的12位流水编号
// System.out.println(serialNumber);
// //
// String serialNumber8 = batchUtil.getBatchNumber("Coder", 8, 16); // 生成8位流水编号 // 生成8位流水编号
// System.out.println(serialNumber8); // 输出生成的8位流水编号 // String serialNumber8 = batchUtil.getBatchNumber("Coder", 8, 16);
// 输出生成的8位流水编号
// System.out.println(serialNumber8);
// //
// int coder = batchUtil.getSortNumber("Coder", serialNumber8); // int coder = batchUtil.getSortNumber("Coder", serialNumber8);
// System.out.println(coder); // System.out.println(coder);

View File

@ -36,13 +36,15 @@ public class StrFormatter {
StringBuilder sbuf = new StringBuilder(strPatternLength + 50); StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
int handledPosition = 0; int handledPosition = 0;
int delimIndex;// 占位符所在位置 // 占位符所在位置
int delimIndex;
for (int argIndex = 0; argIndex < argArray.length; argIndex++) { for (int argIndex = 0; argIndex < argArray.length; argIndex++) {
delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition); delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition);
if (delimIndex == -1) { if (delimIndex == -1) {
if (handledPosition == 0) { if (handledPosition == 0) {
return strPattern; return strPattern;
} else { // 字符串模板剩余部分不再包含占位符加入剩余部分后返回结果 // 字符串模板剩余部分不再包含占位符加入剩余部分后返回结果
} else {
sbuf.append(strPattern, handledPosition, strPatternLength); sbuf.append(strPattern, handledPosition, strPatternLength);
return sbuf.toString(); return sbuf.toString();
} }