From d4dfe3a484f82c8f4f51961d18df8b31a2438e49 Mon Sep 17 00:00:00 2001 From: Wang Chen Chen <932560435@qq.com> Date: Thu, 23 Nov 2023 14:29:39 +0800 Subject: [PATCH] =?UTF-8?q?1.=E7=A7=BB=E9=99=A4JsonUtils=E4=B8=AD=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E6=A0=BC=E5=BC=8F=E5=8C=96=20=202.=E6=B7=BB=E5=8A=A0E?= =?UTF-8?q?xcel=E5=B7=A5=E5=85=B7=E7=B1=BB=20=203.=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=BA=93=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 8 +- server/common/pom.xml | 6 + .../xaaef/molly/common/util/ExcelUtils.java | 228 ++++++++++++++++++ .../xaaef/molly/common/util/JsonUtils.java | 20 +- .../service/impl/CmsProjectServiceImpl.java | 4 +- .../molly/monitor/entity/ServerInfo.java | 21 +- server/molly-service/aa.xlsx | Bin 0 -> 5120 bytes .../java/com/xaaef/molly/NoSpringTests.java | 23 +- server/molly-sys/pom.xml | 2 +- .../service/impl/SysConfigServiceImpl.java | 8 +- .../service/impl/SysTenantServiceImpl.java | 15 +- .../service/impl/JwtTokenServiceImpl.java | 3 +- .../service/impl/UserLoginServiceImpl.java | 4 +- .../molly/web/CustomSpringWebConfig.java | 30 ++- server/pom.xml | 35 +-- 15 files changed, 328 insertions(+), 79 deletions(-) create mode 100644 server/common/src/main/java/com/xaaef/molly/common/util/ExcelUtils.java create mode 100644 server/molly-service/aa.xlsx diff --git a/.gitignore b/.gitignore index 0ee876a..a0b4a0b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,13 @@ HELP.md target/ +server/molly-service/src/main/resources/application-dev.yml +/server/molly-service/src/main/resources/application-dev.yml +./server/molly-service/src/main/resources/application-dev.yml +server/molly-service/src/main/resources/application-*.yml +/server/molly-service/src/main/resources/application-*.yml +./server/molly-service/src/main/resources/application-*.yml + ### STS ### .apt_generated .classpath @@ -28,4 +35,3 @@ build/ ### VS Code ### .vscode/ -server/molly-service/src/main/resources/application-dev.yml diff --git a/server/common/pom.xml b/server/common/pom.xml index e978ace..21e3efb 100644 --- a/server/common/pom.xml +++ b/server/common/pom.xml @@ -26,6 +26,12 @@ spring-boot-starter-json + + org.apache.poi + poi + ${apache-poi.version} + + jakarta.validation jakarta.validation-api diff --git a/server/common/src/main/java/com/xaaef/molly/common/util/ExcelUtils.java b/server/common/src/main/java/com/xaaef/molly/common/util/ExcelUtils.java new file mode 100644 index 0000000..31f7af9 --- /dev/null +++ b/server/common/src/main/java/com/xaaef/molly/common/util/ExcelUtils.java @@ -0,0 +1,228 @@ +package com.xaaef.molly.common.util; + +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.util.StrUtil; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.hssf.usermodel.HSSFCellStyle; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.*; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZonedDateTime; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; +import java.util.stream.Collectors; + + +/** + *

+ * Excel 工具类 + *

+ * + * @author WangChenChen + * @version 1.2 + * @date 2023/11/23 14:50 + */ + +@Slf4j +public class ExcelUtils { + + + /** + * 设备导出的 Excel + * + * @author WangChenChen + * @date 2023/9/21 14:51 + */ + public static ResponseEntity deviceExport(String fileName, List dataList) { + //创建一个Excel文件 + return getWorkbook(fileName, (workbook) -> { + if (!dataList.isEmpty()) { + // 获取设备的总数量 + int total = dataList.size(); + int pageSize = 10000; + if (total > pageSize) { + int pages = (total / pageSize) + 1; + var startIndex = new AtomicInteger(0); + for (int i = 0; i < pages; i++) { + int fromIndex = startIndex.get(); + var toIndex = (fromIndex + pageSize); + startIndex.set(toIndex); + if (toIndex >= total) { + toIndex = total; + } + var rangeData = dataList.subList(fromIndex, toIndex); + var pageNum = i + 1; + pageExport(workbook, String.format("第 %d 页", pageNum), rangeData); + } + } else { + pageExport(workbook, String.format("第 %d 页", 1), dataList); + } + } + }); + } + + + /** + * 分页导出 + * + * @author WangChenChen + * @version 2.0 + * @date 2023/11/23 12:32 + */ + private static void pageExport(HSSFWorkbook workbook, String sheetName, List rangeData) { + // 反射获取对象属性,和描述名称 + var fieldNames = Arrays.stream(ReflectUtil.getFields(rangeData.getFirst().getClass())) + .map(field -> { + var ann = field.getAnnotation(Schema.class); + return ann == null ? StrUtil.EMPTY : ann.description(); + }) + .collect(Collectors.toCollection(LinkedList::new)); + //创建工作表,指定工作表名称 + var sheet1 = workbook.createSheet(sheetName); + sheet1.setDefaultColumnWidth(20); + var titleRow = sheet1.createRow(0); + // 设置标题 + setTitle(titleRow, createTitleStyle(workbook), fieldNames); + + var cellNum = fieldNames.size(); + for (int ind = 0; ind < rangeData.size(); ind++) { + var a1 = rangeData.get(ind); + var row1 = sheet1.createRow((ind + 1)); + var fieldsValue = ReflectUtil.getFieldsValue(a1); + for (int v = 0; v < cellNum; v++) { + var cell0 = row1.createCell(v); + cell0.setCellType(CellType.STRING); + var obj = fieldsValue[v]; + if (obj == null) { + cell0.setCellValue(StrUtil.EMPTY); + break; + } + if (obj instanceof Long o1) { + cell0.setCellValue(o1); + } else if (obj instanceof Integer o1) { + cell0.setCellValue(o1); + } else if (obj instanceof Short o1) { + cell0.setCellValue(o1); + } else if (obj instanceof Float o1) { + cell0.setCellValue(o1); + } else if (obj instanceof Double o1) { + cell0.setCellValue(o1); + } else if (obj instanceof String o1) { + cell0.setCellValue(o1); + } else if (obj instanceof Byte o1) { + cell0.setCellValue(o1); + } else if (obj instanceof Boolean o1) { + cell0.setCellValue(o1); + } else if (obj instanceof Date o1) { + cell0.setCellValue(DateUtil.formatDateTime(o1)); + } else if (obj instanceof LocalDate o1) { + cell0.setCellValue(o1.format(DatePattern.NORM_DATE_FORMATTER)); + } else if (obj instanceof LocalTime o1) { + cell0.setCellValue(o1.format(DatePattern.NORM_TIME_FORMATTER)); + } else if (obj instanceof LocalDateTime o1) { + cell0.setCellValue(o1.format(DatePattern.NORM_DATETIME_FORMATTER)); + } else if (obj instanceof ZonedDateTime o1) { + cell0.setCellValue(o1.format(DatePattern.NORM_DATETIME_FORMATTER)); + } else if (obj instanceof Iterable || obj instanceof Map || obj instanceof Enum || obj.getClass().isArray()) { + cell0.setCellValue(JsonUtils.toFormatJson(obj)); + } else { + cell0.setCellValue(obj.toString()); + } + } + } + } + + + /** + * 获取一个 Workbook + * + * @date 2023/11/23 11:20 + */ + public static ResponseEntity getWorkbook(String fileName, Consumer workbookConsumer) { + //在内存中创建一个Excel文件 + var workbook = new HSSFWorkbook(); + // 创建一个 消费者 + workbookConsumer.accept(workbook); + var os = new ByteArrayOutputStream(); + try { + workbook.write(os); + workbook.close(); + } catch (IOException e) { + log.error(e.getMessage()); + try { + os.write(e.getMessage().getBytes(StandardCharsets.UTF_8)); + } catch (IOException ex) { + log.error(e.getMessage()); + } + } + if (fileName.endsWith(".xlsx")) { + fileName = fileName.replaceFirst(".xlsx", ""); + } + return ResponseEntity.ok() + .contentType(MediaType.APPLICATION_OCTET_STREAM) + .header("Content-Disposition", String.format("attachment;filename=%s.xlsx", fileNameEncode(fileName))) + .body(new ByteArrayResource(os.toByteArray())); + } + + + /** + * 文件名编码 + * + * @date 2023/11/23 11:20 + */ + private static String fileNameEncode(String fileName) { + return URLEncoder.encode(fileName, StandardCharsets.UTF_8).replaceAll("\\+", "%20"); + } + + + /** + * 创建标题样式 + * + * @date 2023/11/23 11:20 + */ + private static HSSFCellStyle createTitleStyle(HSSFWorkbook workbook) { + // 标题,颜色 + var titleStyle = workbook.createCellStyle(); + titleStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中 + titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中 + titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + titleStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); + var font1 = workbook.createFont(); + font1.setBold(true); //加粗 + font1.setColor(Font.COLOR_NORMAL); //字体颜色 + titleStyle.setFont(font1); + return titleStyle; + } + + + /** + * 设置 标题 + * + * @date 2023/11/23 11:20 + */ + private static void setTitle(HSSFRow titleRow, HSSFCellStyle titleStyle, List titleName) { + for (int index = 0; index < titleName.size(); index++) { + var cell = titleRow.createCell(index); + cell.setCellStyle(titleStyle); + cell.setCellValue(titleName.get(index)); + cell.setCellType(CellType.STRING); + } + } + + +} diff --git a/server/common/src/main/java/com/xaaef/molly/common/util/JsonUtils.java b/server/common/src/main/java/com/xaaef/molly/common/util/JsonUtils.java index 7fddcfd..ae83132 100644 --- a/server/common/src/main/java/com/xaaef/molly/common/util/JsonUtils.java +++ b/server/common/src/main/java/com/xaaef/molly/common/util/JsonUtils.java @@ -1,5 +1,6 @@ package com.xaaef.molly.common.util; +import cn.hutool.core.date.DatePattern; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.util.DefaultIndenter; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; @@ -18,7 +19,6 @@ import org.apache.commons.lang3.StringUtils; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; -import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -38,23 +38,17 @@ import java.util.Map; @Slf4j public class JsonUtils { - public static final String DEFAULT_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; - - public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd"; - - public static final String DEFAULT_TIME_PATTERN = "HH:mm:ss"; - private static final ObjectMapper MAPPER; static { MAPPER = new ObjectMapper(); JavaTimeModule javaTimeModule = new JavaTimeModule(); - javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN))); - javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN))); - javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN))); - javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN))); - javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN))); - javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN))); + javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DatePattern.NORM_DATETIME_FORMATTER)); + javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DatePattern.NORM_DATETIME_FORMATTER)); + javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DatePattern.NORM_DATE_FORMATTER)); + javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DatePattern.NORM_DATE_FORMATTER)); + javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DatePattern.NORM_TIME_FORMATTER)); + javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DatePattern.NORM_TIME_FORMATTER)); MAPPER.registerModule(javaTimeModule); /* diff --git a/server/molly-cms/src/main/java/com/xaaef/molly/corems/service/impl/CmsProjectServiceImpl.java b/server/molly-cms/src/main/java/com/xaaef/molly/corems/service/impl/CmsProjectServiceImpl.java index 38dec67..9320eb6 100644 --- a/server/molly-cms/src/main/java/com/xaaef/molly/corems/service/impl/CmsProjectServiceImpl.java +++ b/server/molly-cms/src/main/java/com/xaaef/molly/corems/service/impl/CmsProjectServiceImpl.java @@ -147,8 +147,8 @@ public class CmsProjectServiceImpl extends BaseServiceImpldNF!Szi(&E_lkW6^lix*hhE0{D*d6R3`Cz zNql)oPNJQXX&&WYF0B%F>~bsOV-185bcGGZ;7NF&k_kDg^O#s;RBct0xGVlSkJ?t( zOGg6#*K7V?65idbAhsTs9tQEw*MlM;%Gb-yy92zle8+hwYn^`-a$c2vsv;}l4s139gbQ`E0)B)NC@d}+ z9)mY7{-P0_VqI9iOP1Cra?@qi)vvQ`Md~me3q`V$PxazU;gQ7R*Twy2EPsuGUGdW2hbZLdX1|l72+) z*RU_X_8zYUN?7(xojCIR4N;uu^h-WEyf(PQ)k*G1cBVT!`*J-)-L~J;;cdgQ;1XF0 zv`>$Y=btGz@$q8gj#-nt`YJHM0;UTux?gQmiDV21B_(|#IXX!Bc18i)t$fc=z$WiZ zVm`U<;T$}qabIzBbKT{mQhsSj%CE5BEos3yl{+#sukgi5mAT7gN)894SMDxzXh&P0 z!BBNu8n>WNmB_C}Y{yFZ%BP&Cuky=Qv9_EiS<8MkIZa=Ytc-l4>>a~@EXxmZ< z7svGBcnc_J_5V@WNx$k#KUVqjho|vWI{1C!XzOjprDII7T#HT9fhXdusW6Lw>ZXNyO@NeUnXX{LNF6+w)$>YUP&0KbIWO9s7o{Jrj z?DmPJk$cB!zM)cNhefN!9F7Tv%!K;!*67UoWodS4_T1xve5YU_XS`D$lfCk=jG`X3 zqjqtX)b3JE7MiE5ZU9e{>IURlc}2!i2bhD_*PwhqlgiFzi+JWDGL180uJI$~;mS~|0H11nqJ!a5w%^_hnO*F3zEumHO_P)j+J*|JDxt34ayWlK=n! literal 0 HcmV?d00001 diff --git a/server/molly-service/src/test/java/com/xaaef/molly/NoSpringTests.java b/server/molly-service/src/test/java/com/xaaef/molly/NoSpringTests.java index e0d02ac..f09ea76 100644 --- a/server/molly-service/src/test/java/com/xaaef/molly/NoSpringTests.java +++ b/server/molly-service/src/test/java/com/xaaef/molly/NoSpringTests.java @@ -8,11 +8,16 @@ import cn.hutool.core.util.IdUtil; import com.mysql.cj.jdbc.MysqlDataSource; import com.xaaef.molly.auth.jwt.JwtSecurityUtils; import com.xaaef.molly.common.consts.JwtConst; +import com.xaaef.molly.common.util.ExcelUtils; import com.xaaef.molly.common.util.JsonUtils; +import com.xaaef.molly.perms.entity.PmsRole; import liquibase.integration.spring.MultiTenantSpringLiquibase; import org.junit.jupiter.api.Test; import org.springframework.core.io.FileSystemResourceLoader; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; @@ -20,7 +25,6 @@ import java.time.LocalTime; import java.util.List; import java.util.Map; import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.stream.Stream; import static com.xaaef.molly.common.util.IpUtils.getLocalIPS; @@ -116,7 +120,7 @@ public class NoSpringTests { .flatMap(Stream::of) .filter(s -> !JwtConst.LOGIN_URL.equals(s)) .distinct() - .collect(Collectors.toList()); + .toList(); String formatJson = JsonUtils.toFormatJson(Map.of( "data", whiteList, "time", LocalTime.now() @@ -125,4 +129,19 @@ public class NoSpringTests { } + @Test + public void test12() throws IOException { + var treeNodes = List.of( + new PmsRole(1001L, "角色1", 1L, "角色1问问去"), + new PmsRole(1002L, "角色2", 2L, "角色2QBGRBR"), + new PmsRole(1003L, "角色3", 3L, "角色3GRNRY"), + new PmsRole(1004L, "角色4", 4L, "角色4fwef"), + new PmsRole(1005L, "角色5", 5L, "角色5这个人") + ); + var entity = ExcelUtils.deviceExport("aa.xlsx", treeNodes); + var file = Files.createFile(Path.of("aa.xlsx")).toFile(); + FileUtil.writeFromStream(entity.getBody().getInputStream(), file, true); + } + + } diff --git a/server/molly-sys/pom.xml b/server/molly-sys/pom.xml index 98fb5a0..e7b0161 100644 --- a/server/molly-sys/pom.xml +++ b/server/molly-sys/pom.xml @@ -63,7 +63,7 @@ com.qiniu qiniu-java-sdk - ${qiniu.version} + ${qiniu-storage.version} diff --git a/server/molly-sys/src/main/java/com/xaaef/molly/system/service/impl/SysConfigServiceImpl.java b/server/molly-sys/src/main/java/com/xaaef/molly/system/service/impl/SysConfigServiceImpl.java index 8327173..b7e0090 100644 --- a/server/molly-sys/src/main/java/com/xaaef/molly/system/service/impl/SysConfigServiceImpl.java +++ b/server/molly-sys/src/main/java/com/xaaef/molly/system/service/impl/SysConfigServiceImpl.java @@ -1,5 +1,6 @@ package com.xaaef.molly.system.service.impl; +import cn.hutool.core.date.DatePattern; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.xaaef.molly.auth.jwt.JwtSecurityUtils; @@ -24,7 +25,6 @@ import java.io.Serializable; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; -import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -173,21 +173,21 @@ public class SysConfigServiceImpl extends BaseServiceImpl simplePageKeywords(SearchPO params) { var wrapper = super.getKeywordsQueryWrapper( - params, - List.of(SysTenant::getTenantId, SysTenant::getName, SysTenant::getLinkman) - ); - wrapper.lambda().select( - List.of(SysTenant::getTenantId, SysTenant::getLogo, SysTenant::getName, SysTenant::getLinkman) - ); + params, + List.of(SysTenant::getTenantId, SysTenant::getName, SysTenant::getLinkman) + ) + .lambda() + .select(List.of(SysTenant::getTenantId, SysTenant::getLogo, SysTenant::getName, SysTenant::getLinkman)) + .eq(SysTenant::getStatus, StatusEnum.NORMAL.getCode()) + .orderByAsc(SysTenant::getCreateTime); // 如果当前登录的用户,关联的有租户, var tenantIds = sysUserService.listHaveTenantIds(getUserId()); if (!tenantIds.isEmpty()) { - wrapper.lambda().in(SysTenant::getTenantId, tenantIds); + wrapper.in(SysTenant::getTenantId, tenantIds); } Page pageRequest = Page.of(params.getPageIndex(), params.getPageSize()); return super.page(pageRequest, wrapper); diff --git a/server/plugins/auth-jwt/src/main/java/com/xaaef/molly/auth/service/impl/JwtTokenServiceImpl.java b/server/plugins/auth-jwt/src/main/java/com/xaaef/molly/auth/service/impl/JwtTokenServiceImpl.java index 6780f25..a82dc5c 100644 --- a/server/plugins/auth-jwt/src/main/java/com/xaaef/molly/auth/service/impl/JwtTokenServiceImpl.java +++ b/server/plugins/auth-jwt/src/main/java/com/xaaef/molly/auth/service/impl/JwtTokenServiceImpl.java @@ -29,7 +29,6 @@ import java.util.stream.Collectors; import static com.xaaef.molly.auth.enums.OAuth2Error.TOKEN_FORMAT_ERROR; import static com.xaaef.molly.common.consts.LoginConst.*; -import static com.xaaef.molly.common.util.JsonUtils.DEFAULT_DATE_TIME_PATTERN; /** @@ -111,7 +110,7 @@ public class JwtTokenServiceImpl implements JwtTokenService { removeLoginUser(onlineUserKey); // 获取当前时间 - var milli = LocalDateTimeUtil.format(LocalDateTime.now(), DEFAULT_DATE_TIME_PATTERN); + var milli = LocalDateTimeUtil.formatNormal(LocalDateTime.now()); // 将 被强制挤下线的用户,以及时间,保存到 redis中,提示给前端用户! strRedisTemplate.opsForValue().set( diff --git a/server/plugins/auth-jwt/src/main/java/com/xaaef/molly/auth/service/impl/UserLoginServiceImpl.java b/server/plugins/auth-jwt/src/main/java/com/xaaef/molly/auth/service/impl/UserLoginServiceImpl.java index 75b45b1..292ca29 100644 --- a/server/plugins/auth-jwt/src/main/java/com/xaaef/molly/auth/service/impl/UserLoginServiceImpl.java +++ b/server/plugins/auth-jwt/src/main/java/com/xaaef/molly/auth/service/impl/UserLoginServiceImpl.java @@ -37,8 +37,6 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; -import static com.xaaef.molly.common.util.JsonUtils.DEFAULT_DATE_TIME_PATTERN; - /** *

@@ -98,7 +96,7 @@ public class UserLoginServiceImpl implements UserLoginService { } // 判断租户是否过期 if (LocalDateTime.now().isAfter(currentTenant.getExpired())) { - var format = LocalDateTimeUtil.format(currentTenant.getExpired(), DEFAULT_DATE_TIME_PATTERN); + var format = LocalDateTimeUtil.formatNormal(currentTenant.getExpired()); throw new JwtAuthException(StrUtil.format("租户 {} 已经在 {} 过期了!", currentTenant.getName(), format)); } // 把表单提交的 username password 封装到 UsernamePasswordAuthenticationToken中 diff --git a/server/plugins/web-config/src/main/java/com/xaaef/molly/web/CustomSpringWebConfig.java b/server/plugins/web-config/src/main/java/com/xaaef/molly/web/CustomSpringWebConfig.java index 04b5607..e19eafc 100644 --- a/server/plugins/web-config/src/main/java/com/xaaef/molly/web/CustomSpringWebConfig.java +++ b/server/plugins/web-config/src/main/java/com/xaaef/molly/web/CustomSpringWebConfig.java @@ -1,5 +1,6 @@ package com.xaaef.molly.web; +import cn.hutool.core.date.DatePattern; import cn.hutool.core.net.Ipv4Util; import com.fasterxml.jackson.databind.ObjectMapper; import com.xaaef.molly.common.consts.JwtConst; @@ -28,7 +29,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; -import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; import java.util.Set; @@ -82,9 +82,9 @@ public class CustomSpringWebConfig implements WebMvcConfigurer { .distinct() .collect(Collectors.toList()); - var multiTenantProperties = tenantService.getByMultiTenantProperties(); + var mtp = tenantService.getByMultiTenantProperties(); // 启用 租户ID 拦截器 - if (multiTenantProperties.getEnable()) { + if (mtp.getEnable()) { registry.addInterceptor(tenantIdInterceptor) .addPathPatterns("/**") .excludePathPatterns(whiteList); @@ -92,7 +92,7 @@ public class CustomSpringWebConfig implements WebMvcConfigurer { } // 启用 项目ID 拦截器 - if (multiTenantProperties.getEnableProject()) { + if (mtp.getEnableProject()) { registry.addInterceptor(projectIdInterceptor) .addPathPatterns("/**") .excludePathPatterns(whiteList); @@ -146,12 +146,11 @@ public class CustomSpringWebConfig implements WebMvcConfigurer { @Bean public Formatter dateFormatter() { return new Formatter<>() { - @Override public Date parse(String text, Locale locale) { Date date = null; try { - date = DateUtils.parseDate(text, locale, JsonUtils.DEFAULT_DATE_TIME_PATTERN); + date = DateUtils.parseDate(text, locale, DatePattern.NORM_DATETIME_PATTERN); } catch (Exception e) { log.error(e.getMessage()); } @@ -160,7 +159,7 @@ public class CustomSpringWebConfig implements WebMvcConfigurer { @Override public String print(Date date, Locale locale) { - return DateFormatUtils.format(date, JsonUtils.DEFAULT_DATE_TIME_PATTERN, TimeZone.getDefault(), locale); + return DateFormatUtils.format(date, DatePattern.NORM_DATETIME_PATTERN, TimeZone.getDefault(), locale); } }; } @@ -170,12 +169,12 @@ public class CustomSpringWebConfig implements WebMvcConfigurer { return new Formatter<>() { @Override public LocalDate parse(String text, Locale locale) { - return LocalDate.parse(text, DateTimeFormatter.ofPattern(JsonUtils.DEFAULT_DATE_PATTERN, locale)); + return LocalDate.parse(text, DatePattern.NORM_DATE_FORMATTER.withLocale(locale)); } @Override public String print(LocalDate object, Locale locale) { - return DateTimeFormatter.ofPattern(JsonUtils.DEFAULT_DATE_PATTERN, locale).format(object); + return DatePattern.NORM_DATE_FORMATTER.withLocale(locale).format(object); } }; } @@ -185,12 +184,12 @@ public class CustomSpringWebConfig implements WebMvcConfigurer { return new Formatter<>() { @Override public LocalTime parse(String text, Locale locale) { - return LocalTime.parse(text, DateTimeFormatter.ofPattern(JsonUtils.DEFAULT_TIME_PATTERN, locale)); + return LocalTime.parse(text, DatePattern.NORM_TIME_FORMATTER.withLocale(locale)); } @Override public String print(LocalTime object, Locale locale) { - return DateTimeFormatter.ofPattern(JsonUtils.DEFAULT_TIME_PATTERN, locale).format(object); + return DatePattern.NORM_TIME_FORMATTER.withLocale(locale).format(object); } }; } @@ -198,15 +197,14 @@ public class CustomSpringWebConfig implements WebMvcConfigurer { @Bean public Formatter localDateTimeFormatter() { return new Formatter<>() { - @Override - public String print(LocalDateTime localDateTime, Locale locale) { - return DateTimeFormatter.ofPattern(JsonUtils.DEFAULT_DATE_TIME_PATTERN, locale).format(localDateTime); + public LocalDateTime parse(String text, Locale locale) { + return LocalDateTime.parse(text, DatePattern.NORM_DATETIME_FORMATTER.withLocale(locale)); } @Override - public LocalDateTime parse(String text, Locale locale) { - return LocalDateTime.parse(text, DateTimeFormatter.ofPattern(JsonUtils.DEFAULT_DATE_TIME_PATTERN, locale)); + public String print(LocalDateTime localDateTime, Locale locale) { + return DatePattern.NORM_DATETIME_FORMATTER.withLocale(locale).format(localDateTime); } }; } diff --git a/server/pom.xml b/server/pom.xml index 3805b7c..437edbe 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -36,16 +36,23 @@ 3.11.0 UTF-8 UTF-8 - - + 2.0.0 - 7.14.0 + + 7.14.0 + + 3.17.2 + 6.4.6 - - 5.8.22 + + 5.2.4 + + 5.8.23 + 4.3.0 + 3.5.4.1 - + 3.1.5 @@ -73,14 +80,14 @@ spring-boot-starter-actuator - + org.springframework.boot