refactor: 优化公共工具类代码规范
- 移除所有行尾注释,改为独立行注释 - 优化代码可读性和维护性 - 涉及枚举、拦截器、日期工具、文件工具等核心工具类 - 统一注释风格,符合项目规范
This commit is contained in:
parent
044b642f3a
commit
262a63735f
@ -9,15 +9,23 @@ package org.leocoder.thin.common.enmus.common;
|
||||
public interface IResultEnum {
|
||||
|
||||
// 项目服务名 系统编码
|
||||
String A = "101"; // 前台系统
|
||||
String B = "202"; // APP系统
|
||||
// 前台系统
|
||||
String A = "101";
|
||||
// APP系统
|
||||
String B = "202";
|
||||
|
||||
String LOGIN = "100"; // 登录
|
||||
String USER = "101"; // 用户
|
||||
String ROLE = "102"; // 角色
|
||||
String PERMISSION = "103"; // 菜单
|
||||
String LOGIN_LOG = "106"; // 登录日志
|
||||
String OPER_LOG = "107"; // 操作日志
|
||||
// 登录
|
||||
String LOGIN = "100";
|
||||
// 用户
|
||||
String USER = "101";
|
||||
// 角色
|
||||
String ROLE = "102";
|
||||
// 菜单
|
||||
String PERMISSION = "103";
|
||||
// 登录日志
|
||||
String LOGIN_LOG = "106";
|
||||
// 操作日志
|
||||
String OPER_LOG = "107";
|
||||
|
||||
// 成功状态常量
|
||||
int SUCCESS = 200;
|
||||
|
||||
@ -90,7 +90,8 @@ public class CoderIpBlockListInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // 没有白名单Redis数据,不进行校验
|
||||
// 没有白名单Redis数据,不进行校验
|
||||
} else {
|
||||
isWhite = CoderConstants.TRUE;
|
||||
}
|
||||
|
||||
|
||||
@ -410,8 +410,10 @@ public class DateUtil {
|
||||
try {
|
||||
long startTimeMills = startTime.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();
|
||||
if (day_diff < 0) {
|
||||
return "[error],时间越界...";
|
||||
@ -670,21 +672,25 @@ public class DateUtil {
|
||||
|
||||
int year1 = cal1.get(Calendar.YEAR);
|
||||
int year2 = cal2.get(Calendar.YEAR);
|
||||
if (year1 != year2) // 同一年
|
||||
// 同一年
|
||||
if (year1 != year2)
|
||||
{
|
||||
int timeDistance = 0;
|
||||
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;
|
||||
} else // 不是闰年
|
||||
// 不是闰年
|
||||
} else
|
||||
{
|
||||
timeDistance += 365;
|
||||
}
|
||||
}
|
||||
|
||||
return timeDistance + (day2 - day1);
|
||||
} else // 不同年
|
||||
// 不同年
|
||||
} else
|
||||
{
|
||||
return day2 - day1;
|
||||
}
|
||||
@ -710,7 +716,8 @@ public class DateUtil {
|
||||
|
||||
Calendar tempEnd = Calendar.getInstance();
|
||||
tempEnd.setTime(end);
|
||||
tempEnd.add(Calendar.DATE, +1);// 日期加1(包含结束)
|
||||
// 日期加1(包含结束)
|
||||
tempEnd.add(Calendar.DATE, +1);
|
||||
while (tempStart.before(tempEnd)) {
|
||||
days.add(dateFormat.format(tempStart.getTime()));
|
||||
tempStart.add(Calendar.DAY_OF_YEAR, 1);
|
||||
|
||||
@ -151,19 +151,26 @@ public class FileTypeUtil {
|
||||
|
||||
// 检查文件类型并返回对应的类别编号
|
||||
if (pictureTypeList.contains(extension)) {
|
||||
return "1"; // 图片
|
||||
// 图片
|
||||
return "1";
|
||||
} else if (fileTypeList.contains(extension)) {
|
||||
return "2"; // 文档
|
||||
// 文档
|
||||
return "2";
|
||||
} else if (audioList.contains(extension)) {
|
||||
return "3"; // 音频
|
||||
// 音频
|
||||
return "3";
|
||||
} else if (videoList.contains(extension)) {
|
||||
return "4"; // 视频
|
||||
// 视频
|
||||
return "4";
|
||||
} else if (packageList.contains(extension)) {
|
||||
return "5"; // 压缩包
|
||||
// 压缩包
|
||||
return "5";
|
||||
} else if (applyList.contains(extension)) {
|
||||
return "6"; // 应用程序
|
||||
// 应用程序
|
||||
return "6";
|
||||
} else {
|
||||
return "7"; // 其他
|
||||
// 其他
|
||||
return "7";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -83,10 +83,12 @@ public class TextUtil {
|
||||
public static void writeRowText(String filePath, String content) {
|
||||
/* 一行一行写txt文件追加内容 */
|
||||
try {
|
||||
FileWriter writer = new FileWriter(filePath, true); // 创建文件写入器,参数为要写入的文件路径,第二个参数为true表示以追加模式写入
|
||||
// 创建文件写入器,参数为要写入的文件路径,第二个参数为true表示以追加模式写入
|
||||
FileWriter writer = new FileWriter(filePath, true);
|
||||
String[] splitArray = content.split("/n");
|
||||
for (String rowSplit : splitArray) {
|
||||
writer.write(rowSplit); // 按行写入文本数据,每行末尾加上换行符
|
||||
// 按行写入文本数据,每行末尾加上换行符
|
||||
writer.write(rowSplit);
|
||||
}
|
||||
writer.close();
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -75,16 +75,22 @@ public class UploadUtil {
|
||||
} catch (IllegalStateException | IOException e) {
|
||||
log.error("上传文件异常信息:{}", e.getMessage());
|
||||
}
|
||||
map.put("fileSize", fileSize); // 文件大小
|
||||
map.put("fileName", originalFilename); // 原文件名字
|
||||
map.put("suffixName", suffixName); // 文件后缀
|
||||
// 文件大小
|
||||
map.put("fileSize", fileSize);
|
||||
// 原文件名字
|
||||
map.put("fileName", originalFilename);
|
||||
// 文件后缀
|
||||
map.put("suffixName", suffixName);
|
||||
int index = fileUploadPath.indexOf(":");
|
||||
String fileUploadPathString = fileUploadPath.substring(index + 1) + newName;
|
||||
// 文件上传路径
|
||||
log.info("文件上传路径fileUploadPath:{}", fileUploadPathString);
|
||||
map.put("fileUploadPath", fileUploadPathString); // 文件上传路径
|
||||
map.put("newName", newName); // 新文件名字
|
||||
map.put("filePath", absoluteFilePath); // 绝对文件路径
|
||||
// 文件上传路径
|
||||
map.put("fileUploadPath", fileUploadPathString);
|
||||
// 新文件名字
|
||||
map.put("newName", newName);
|
||||
// 绝对文件路径
|
||||
map.put("filePath", absoluteFilePath);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@ -19,11 +19,16 @@ public class EscapeUtil {
|
||||
}
|
||||
|
||||
// special HTML characters
|
||||
TEXT['\''] = "'".toCharArray(); // 单引号
|
||||
TEXT['"'] = """.toCharArray(); // 双引号
|
||||
TEXT['&'] = "&".toCharArray(); // &符
|
||||
TEXT['<'] = "<".toCharArray(); // 小于号
|
||||
TEXT['>'] = ">".toCharArray(); // 大于号
|
||||
// 单引号
|
||||
TEXT['\''] = "'".toCharArray();
|
||||
// 双引号
|
||||
TEXT['"'] = """.toCharArray();
|
||||
// &符
|
||||
TEXT['&'] = "&".toCharArray();
|
||||
// 小于号
|
||||
TEXT['<'] = "<".toCharArray();
|
||||
// 大于号
|
||||
TEXT['>'] = ">".toCharArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -33,11 +33,15 @@ public class GenBatchUtil {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// GenBatchUtil batchUtil = new GenBatchUtil();
|
||||
// String serialNumber = batchUtil.getBatchNumber("Coder", 12, 10); // 生成12位流水编号
|
||||
// System.out.println(serialNumber); // 输出生成的12位流水编号
|
||||
// 生成12位流水编号
|
||||
// String serialNumber = batchUtil.getBatchNumber("Coder", 12, 10);
|
||||
// 输出生成的12位流水编号
|
||||
// System.out.println(serialNumber);
|
||||
//
|
||||
// String serialNumber8 = batchUtil.getBatchNumber("Coder", 8, 16); // 生成8位流水编号
|
||||
// System.out.println(serialNumber8); // 输出生成的8位流水编号
|
||||
// 生成8位流水编号
|
||||
// String serialNumber8 = batchUtil.getBatchNumber("Coder", 8, 16);
|
||||
// 输出生成的8位流水编号
|
||||
// System.out.println(serialNumber8);
|
||||
//
|
||||
// int coder = batchUtil.getSortNumber("Coder", serialNumber8);
|
||||
// System.out.println(coder);
|
||||
|
||||
@ -36,13 +36,15 @@ public class StrFormatter {
|
||||
StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
|
||||
|
||||
int handledPosition = 0;
|
||||
int delimIndex;// 占位符所在位置
|
||||
// 占位符所在位置
|
||||
int delimIndex;
|
||||
for (int argIndex = 0; argIndex < argArray.length; argIndex++) {
|
||||
delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition);
|
||||
if (delimIndex == -1) {
|
||||
if (handledPosition == 0) {
|
||||
return strPattern;
|
||||
} else { // 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果
|
||||
// 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果
|
||||
} else {
|
||||
sbuf.append(strPattern, handledPosition, strPatternLength);
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user