From 32c1de479c0adbea49480bdf5f9e8ce2b9af7006 Mon Sep 17 00:00:00 2001 From: du <1725534722@qq.com> Date: Thu, 10 Oct 2024 10:38:31 +0800 Subject: [PATCH 1/6] =?UTF-8?q?Origin=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/utils/file/FileUtils.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java index 0d63c12..98506cc 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java @@ -76,17 +76,37 @@ public class FileUtils { * @throws IOException IO异常 */ public static String writeBytes(byte[] data, String uploadDir) throws IOException { - FileOutputStream fos = null; - String pathName = ""; - try { - String extension = getFileExtendName(data); - pathName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension; - File file = FileUploadUtils.getAbsoluteFile(uploadDir, pathName); - fos = new FileOutputStream(file); +// FileOutputStream fos = null; +// String pathName = ""; +// try { +// String extension = getFileExtendName(data); +// pathName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension; +// File file = FileUploadUtils.getAbsoluteFile(uploadDir, pathName); +// fos = new FileOutputStream(file); +// fos.write(data); +// } finally { +// IOUtils.close(fos); +// } +// return FileUploadUtils.getPathFileName(uploadDir, pathName); + if (data == null || data.length == 0) { + throw new IllegalArgumentException("数据不能为空"); + } + + String extension = getFileExtendName(data); + String pathName = DateUtils.datePath() + "/" + IdUtils.fastUUID() + "." + extension; + File file = FileUploadUtils.getAbsoluteFile(uploadDir, pathName); + + // 确保父目录存在 + file.getParentFile().mkdirs(); + + // 使用 try-with-resources 自动管理 FileOutputStream 的生命周期 + try (FileOutputStream fos = new FileOutputStream(file)) { fos.write(data); - } finally { - IOUtils.close(fos); + } catch (IOException e) { + // 可以选择记录日志或抛出自定义异常 + throw new IOException("文件写入失败: " + e.getMessage(), e); } + return FileUploadUtils.getPathFileName(uploadDir, pathName); } From 031d6ae375f331e0abc95c178a9a2347e8f64ad3 Mon Sep 17 00:00:00 2001 From: wu Date: Thu, 10 Oct 2024 10:42:31 +0800 Subject: [PATCH 2/6] bugfix --- .../com/ruoyi/common/filter/XssFilter.java | 5 ++- .../ruoyi/framework/config/FilterConfig.java | 13 +++++++ .../web/service/SysLoginService.java | 36 ++++++++++++------- .../framework/web/service/TokenService.java | 15 +++----- .../service/GenTableColumnServiceImpl.java | 5 +-- .../service/GenTableServiceImpl.java | 6 ++-- .../service/impl/SysJobLogServiceImpl.java | 4 +-- .../service/impl/SysJobServiceImpl.java | 6 ++-- 8 files changed, 54 insertions(+), 36 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java b/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java index 851c16a..8e168ba 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java @@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -31,9 +32,7 @@ public class XssFilter implements Filter { String tempExcludes = filterConfig.getInitParameter("excludes"); if (StringUtils.isNotEmpty(tempExcludes)) { String[] url = tempExcludes.split(","); - for (int i = 0; url != null && i < url.length; i++) { - excludes.add(url[i]); - } + excludes.addAll(Arrays.asList(url)); } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java index a67ede6..6eb0076 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java @@ -8,6 +8,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import javax.servlet.DispatcherType; import java.util.HashMap; @@ -30,6 +32,7 @@ public class FilterConfig { @Bean @ConditionalOnProperty(value = "xss.enabled", havingValue = "true") public FilterRegistrationBean xssFilterRegistration() { + FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setDispatcherTypes(DispatcherType.REQUEST); registration.setFilter(new XssFilter()); @@ -39,6 +42,16 @@ public class FilterConfig { Map initParameters = new HashMap(); initParameters.put("excludes", excludes); registration.setInitParameters(initParameters); + + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + config.addAllowedOrigin("http://39.101.188.84:9999"); + config.addAllowedHeader("*"); + config.addAllowedMethod("*"); + source.registerCorsConfiguration("/**", config); // CORS 配置对所有接口都有效 + registration.setOrder(0); + return registration; } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index 802e992..ade3954 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -1,5 +1,6 @@ package com.ruoyi.framework.web.service; +import cn.hutool.core.collection.CollectionUtil; import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.UserConstants; @@ -11,7 +12,11 @@ import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.user.CaptchaException; import com.ruoyi.common.exception.user.CaptchaExpireException; import com.ruoyi.common.exception.user.UserPasswordNotMatchException; -import com.ruoyi.common.utils.*; +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.MessageUtils; +import com.ruoyi.common.utils.RsaUtils; +import com.ruoyi.common.utils.ServletUtils; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.ip.IpUtils; import com.ruoyi.framework.manager.AsyncManager; import com.ruoyi.framework.manager.factory.AsyncFactory; @@ -72,18 +77,23 @@ public class SysLoginService { * @return 结果 */ public Map login(String username, String password, String code, String uuid, String userType) { - String strP = ""; + String strP; try { - strP = RsaUtils.decryptByPrivateKey(password); + strP = RsaUtils.decryptByPrivateKey(password); } catch (Exception e) { throw new RuntimeException(e); } // 验证码校验 // validateCaptcha(username, code, uuid); // 登录前置校验 - loginPreCheck(username,strP); + loginPreCheck(username, strP); + Map map = redisCache.getCacheObject(username + password); + if (CollectionUtil.isNotEmpty(map)) { + map.remove("@type"); + return map; + } // 用户验证 - Authentication authentication = null; + Authentication authentication; try { UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, strP); AuthenticationContextHolder.setContext(authenticationToken); @@ -100,14 +110,14 @@ public class SysLoginService { } finally { AuthenticationContextHolder.clearContext(); } - AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); +// AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); LoginUser loginUser = (LoginUser) authentication.getPrincipal(); // recordLoginInfo(loginUser.getUserId()); if (StringUtils.isNull(loginUser) || StringUtils.isNull(loginUser.getUserId())) { - addRecord(username, Constants.LOGIN_FAIL, "登录用户不存在"); +// addRecord(username, Constants.LOGIN_FAIL, "登录用户不存在"); throw new ServiceException("登录用户:" + username + " 不存在"); } - + loginUser.getUser().setPassword(password); SysUser user = loginUser.getUser(); // 判断用户类型 if (!"admin".equals(username)) { @@ -117,11 +127,11 @@ public class SysLoginService { } if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) { - addRecord(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除"); +// addRecord(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除"); throw new ServiceException("对不起,您的账号:" + username + " 已被删除"); } if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { - addRecord(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); +// addRecord(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); throw new ServiceException("对不起,您的账号:" + username + " 已停用"); } // sysPasswordService.validate(user); @@ -164,19 +174,19 @@ public class SysLoginService { public void loginPreCheck(String username, String password) { // 用户名或密码为空 错误 if (StringUtils.isAnyBlank(username, password)) { - this.addRecord(username, Constants.LOGIN_FAIL, "用户/密码必须填写"); +// this.addRecord(username, Constants.LOGIN_FAIL, "用户/密码必须填写"); throw new ServiceException("用户/密码必须填写"); } // 密码如果不在指定范围内 错误 if (password.length() < UserConstants.PASSWORD_MIN_LENGTH || password.length() > UserConstants.PASSWORD_MAX_LENGTH) { - this.addRecord(username, Constants.LOGIN_FAIL, "用户密码不在指定范围"); +// this.addRecord(username, Constants.LOGIN_FAIL, "用户密码不在指定范围"); throw new ServiceException("用户密码不在指定范围"); } // 用户名不在指定范围内 错误 if (username.length() < UserConstants.USERNAME_MIN_LENGTH || username.length() > UserConstants.USERNAME_MAX_LENGTH) { - this.addRecord(username, Constants.LOGIN_FAIL, "用户名不在指定范围"); +// this.addRecord(username, Constants.LOGIN_FAIL, "用户名不在指定范围"); throw new ServiceException("用户名不在指定范围"); } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java index ba487bb..559fcf9 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java @@ -8,7 +8,6 @@ import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.ip.AddressUtils; import com.ruoyi.common.utils.ip.IpUtils; -import com.ruoyi.common.utils.uuid.IdUtils; import eu.bitwalker.useragentutils.UserAgent; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; @@ -96,7 +95,8 @@ public class TokenService { * @return 令牌 */ public Map createToken(LoginUser loginUser) { - String token = IdUtils.fastUUID(); +// String token = IdUtils.fastUUID(); + String token = String.valueOf(loginUser.getUser().getUserName()); loginUser.setToken(token); setUserAgent(loginUser); refreshToken(loginUser); @@ -109,6 +109,7 @@ public class TokenService { Map rspMap = new HashMap<>(); rspMap.put("access_token", token1); rspMap.put("expires_in", expireTime); + redisCache.setCacheObject(token + loginUser.getPassword(), rspMap, 5, TimeUnit.SECONDS); return rspMap; } @@ -160,10 +161,7 @@ public class TokenService { * @return 令牌 */ private String createToken(Map claims) { - String token = Jwts.builder() - .setClaims(claims) - .signWith(SignatureAlgorithm.HS512, secret).compact(); - return token; + return Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact(); } /** @@ -173,10 +171,7 @@ public class TokenService { * @return 数据声明 */ private Claims parseToken(String token) { - return Jwts.parser() - .setSigningKey(secret) - .parseClaimsJws(token) - .getBody(); + return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody(); } /** diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java index fed997c..018cf7b 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java @@ -3,9 +3,9 @@ package com.ruoyi.generator.service; import com.ruoyi.common.core.text.Convert; import com.ruoyi.generator.domain.GenTableColumn; import com.ruoyi.generator.mapper.GenTableColumnMapper; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.Resource; import java.util.List; /** @@ -15,7 +15,8 @@ import java.util.List; */ @Service public class GenTableColumnServiceImpl implements IGenTableColumnService { - @Autowired + + @Resource private GenTableColumnMapper genTableColumnMapper; /** diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java index bd2750c..2c7b5c2 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java @@ -21,10 +21,10 @@ import org.apache.velocity.VelocityContext; import org.apache.velocity.app.Velocity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -46,10 +46,10 @@ import java.util.zip.ZipOutputStream; public class GenTableServiceImpl implements IGenTableService { private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); - @Autowired + @Resource private GenTableMapper genTableMapper; - @Autowired + @Resource private GenTableColumnMapper genTableColumnMapper; /** diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobLogServiceImpl.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobLogServiceImpl.java index e867fcf..af2bb6a 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobLogServiceImpl.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobLogServiceImpl.java @@ -3,9 +3,9 @@ package com.ruoyi.quartz.service.impl; import com.ruoyi.quartz.domain.SysJobLog; import com.ruoyi.quartz.mapper.SysJobLogMapper; import com.ruoyi.quartz.service.ISysJobLogService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.annotation.Resource; import java.util.List; /** @@ -15,7 +15,7 @@ import java.util.List; */ @Service public class SysJobLogServiceImpl implements ISysJobLogService { - @Autowired + @Resource private SysJobLogMapper jobLogMapper; /** diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java index 6ab7002..0dd6ace 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java @@ -11,11 +11,11 @@ import org.quartz.JobDataMap; import org.quartz.JobKey; import org.quartz.Scheduler; import org.quartz.SchedulerException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.PostConstruct; +import javax.annotation.Resource; import java.util.List; /** @@ -25,10 +25,10 @@ import java.util.List; */ @Service public class SysJobServiceImpl implements ISysJobService { - @Autowired + @Resource private Scheduler scheduler; - @Autowired + @Resource private SysJobMapper jobMapper; /** From a3e17ceb042f505f99187cbbb210b9c9eeb1a1b3 Mon Sep 17 00:00:00 2001 From: du <1725534722@qq.com> Date: Fri, 11 Oct 2024 14:31:50 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E8=84=B1=E6=95=8Fbug=E4=B8=AD=E9=80=94?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-admin/pom.xml | 6 - .../impl/BmsTemplateInfoServiceImpl.java | 32 +- .../single/util/HMAC256Config.java | 2 +- .../jjh/declaration/util/AESEncryptor.java | 6 +- .../java/com/ruoyi/common/utils/RsaUtils.java | 134 +--- .../ruoyi/common/utils/file/FileUtils.java | 46 +- .../ruoyi/common/utils/file/ImageUtils.java | 59 +- .../ruoyi/common/utils/http/HttpUtils.java | 65 -- .../com/ruoyi/common/utils/poi/ExcelUtil.java | 38 +- .../common/utils/poi/ProjectExcelUtil.java | 38 +- .../common/utils/poi/ProjectValueUtil.java | 38 +- ruoyi-generator/pom.xml | 40 - .../com/ruoyi/generator/config/GenConfig.java | 72 -- .../generator/controller/GenController.java | 236 ------ .../com/ruoyi/generator/domain/GenTable.java | 376 --------- .../generator/domain/GenTableColumn.java | 348 -------- .../mapper/GenTableColumnMapper.java | 60 -- .../generator/mapper/GenTableMapper.java | 91 --- .../service/GenTableColumnServiceImpl.java | 65 -- .../service/GenTableServiceImpl.java | 464 ----------- .../service/IGenTableColumnService.java | 44 -- .../generator/service/IGenTableService.java | 130 --- .../com/ruoyi/generator/util/GenUtils.java | 221 ------ .../generator/util/VelocityInitializer.java | 30 - .../ruoyi/generator/util/VelocityUtils.java | 354 --------- .../src/main/resources/generator.yml | 10 - .../mapper/generator/GenTableColumnMapper.xml | 131 --- .../mapper/generator/GenTableMapper.xml | 221 ------ .../main/resources/vm/java/controller.java.vm | 108 --- .../src/main/resources/vm/java/domain.java.vm | 101 --- .../src/main/resources/vm/java/mapper.java.vm | 91 --- .../main/resources/vm/java/service.java.vm | 61 -- .../resources/vm/java/serviceImpl.java.vm | 161 ---- .../main/resources/vm/java/sub-domain.java.vm | 77 -- .../src/main/resources/vm/js/api.js.vm | 44 -- .../src/main/resources/vm/sql/sql.vm | 22 - .../main/resources/vm/vue/index-tree.vue.vm | 571 -------------- .../src/main/resources/vm/vue/index.vue.vm | 744 ------------------ .../resources/vm/vue/v3/index-tree.vue.vm | 542 ------------- .../src/main/resources/vm/vue/v3/index.vue.vm | 729 ----------------- .../src/main/resources/vm/xml/mapper.xml.vm | 166 ---- 41 files changed, 220 insertions(+), 6554 deletions(-) delete mode 100644 ruoyi-generator/pom.xml delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityInitializer.java delete mode 100644 ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java delete mode 100644 ruoyi-generator/src/main/resources/generator.yml delete mode 100644 ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml delete mode 100644 ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml delete mode 100644 ruoyi-generator/src/main/resources/vm/java/controller.java.vm delete mode 100644 ruoyi-generator/src/main/resources/vm/java/domain.java.vm delete mode 100644 ruoyi-generator/src/main/resources/vm/java/mapper.java.vm delete mode 100644 ruoyi-generator/src/main/resources/vm/java/service.java.vm delete mode 100644 ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm delete mode 100644 ruoyi-generator/src/main/resources/vm/java/sub-domain.java.vm delete mode 100644 ruoyi-generator/src/main/resources/vm/js/api.js.vm delete mode 100644 ruoyi-generator/src/main/resources/vm/sql/sql.vm delete mode 100644 ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm delete mode 100644 ruoyi-generator/src/main/resources/vm/vue/index.vue.vm delete mode 100644 ruoyi-generator/src/main/resources/vm/vue/v3/index-tree.vue.vm delete mode 100644 ruoyi-generator/src/main/resources/vm/vue/v3/index.vue.vm delete mode 100644 ruoyi-generator/src/main/resources/vm/xml/mapper.xml.vm diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index 7ffbb20..ab5d499 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -32,12 +32,6 @@ knife4j-openapi2-spring-boot-starter 4.4.0 - - - org.springframework.boot - spring-boot-devtools - true - mysql diff --git a/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/service/impl/BmsTemplateInfoServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/service/impl/BmsTemplateInfoServiceImpl.java index b53a76e..c02bd68 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/service/impl/BmsTemplateInfoServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/jjh/declaration/service/impl/BmsTemplateInfoServiceImpl.java @@ -66,20 +66,40 @@ public class BmsTemplateInfoServiceImpl extends ServiceImpl 0) { +// os.write(b, 0, length); +// } +// } catch (IOException e) { +// throw e; +// } finally { +// IOUtils.close(os); +// IOUtils.close(fis); +// } + File file = new File(filePath); + if (!file.exists()) { + throw new FileNotFoundException(filePath); + } + + // 使用 try-with-resources 确保流被正确关闭 + try (FileInputStream fis = new FileInputStream(file)) { + byte[] buffer = new byte[1024]; int length; - while ((length = fis.read(b)) > 0) { - os.write(b, 0, length); + while ((length = fis.read(buffer)) > 0) { + os.write(buffer, 0, length); } } catch (IOException e) { - throw e; + throw e; // 可以选择记录日志或处理其他逻辑 } finally { - IOUtils.close(os); - IOUtils.close(fis); + // 这里假设 os 是由调用者提供并且需要在外部关闭 + // 如果 os 也应该由此方法管理,建议将其放入 try-with-resources 中 + // IOUtils.close(os); // 如果你希望在这里关闭 os,请确认它的管理责任 } } @@ -88,6 +107,7 @@ public class FileUtils { // IOUtils.close(fos); // } // return FileUploadUtils.getPathFileName(uploadDir, pathName); + if (data == null || data.length == 0) { throw new IllegalArgumentException("数据不能为空"); } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/ImageUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/ImageUtils.java index 59ed39a..eac46c9 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/ImageUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/ImageUtils.java @@ -52,28 +52,51 @@ public class ImageUtils { * @return 字节数据 */ public static byte[] readFile(String url) { - InputStream in = null; - try { - if (url.startsWith("http")) { - // 网络地址 - URL urlObj = new URL(url); - URLConnection urlConnection = urlObj.openConnection(); - urlConnection.setConnectTimeout(30 * 1000); - urlConnection.setReadTimeout(60 * 1000); - urlConnection.setDoInput(true); - in = urlConnection.getInputStream(); - } else { - // 本机地址 - String localPath = RuoYiConfig.getProfile(); - String downloadPath = localPath + StringUtils.substringAfter(url, Constants.RESOURCE_PREFIX); - in = new FileInputStream(downloadPath); - } +// InputStream in = null; +// try { +// if (url.startsWith("http")) { +// // 网络地址 +// URL urlObj = new URL(url); +// URLConnection urlConnection = urlObj.openConnection(); +// urlConnection.setConnectTimeout(30 * 1000); +// urlConnection.setReadTimeout(60 * 1000); +// urlConnection.setDoInput(true); +// in = urlConnection.getInputStream(); +// } else { +// // 本机地址 +// String localPath = RuoYiConfig.getProfile(); +// String downloadPath = localPath + StringUtils.substringAfter(url, Constants.RESOURCE_PREFIX); +// in = new FileInputStream(downloadPath); +// } +// return IOUtils.toByteArray(in); +// } catch (Exception e) { +// log.error("获取文件路径异常 {}", e); +// return null; +// } finally { +// IOUtils.closeQuietly(in); +// } + try (InputStream in = openInputStream(url)) { return IOUtils.toByteArray(in); } catch (Exception e) { log.error("获取文件路径异常 {}", e); return null; - } finally { - IOUtils.closeQuietly(in); + } + } + + private static InputStream openInputStream(String url) throws Exception { + if (url.startsWith("http")) { + // 网络地址 + URL urlObj = new URL(url); + URLConnection urlConnection = urlObj.openConnection(); + urlConnection.setConnectTimeout(30 * 1000); + urlConnection.setReadTimeout(60 * 1000); + urlConnection.setDoInput(true); + return urlConnection.getInputStream(); + } else { + // 本机地址 + String localPath = RuoYiConfig.getProfile(); + String downloadPath = localPath + StringUtils.substringAfter(url, Constants.RESOURCE_PREFIX); + return new FileInputStream(downloadPath); } } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java index 6af068a..3398b23 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java @@ -151,69 +151,4 @@ public class HttpUtils { } return result.toString(); } - - public static String sendSSLPost(String url, String param) { - StringBuilder result = new StringBuilder(); - String urlNameString = url + "?" + param; - try { - log.info("sendSSLPost - {}", urlNameString); - SSLContext sc = SSLContext.getInstance("SSL"); - sc.init(null, new TrustManager[]{new TrustAnyTrustManager()}, new java.security.SecureRandom()); - URL console = new URL(urlNameString); - HttpsURLConnection conn = (HttpsURLConnection) console.openConnection(); - conn.setRequestProperty("accept", "*/*"); - conn.setRequestProperty("connection", "Keep-Alive"); - conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"); - conn.setRequestProperty("Accept-Charset", "utf-8"); - conn.setRequestProperty("contentType", "utf-8"); - conn.setDoOutput(true); - conn.setDoInput(true); - - conn.setSSLSocketFactory(sc.getSocketFactory()); - conn.setHostnameVerifier(new TrustAnyHostnameVerifier()); - conn.connect(); - InputStream is = conn.getInputStream(); - BufferedReader br = new BufferedReader(new InputStreamReader(is)); - String ret = ""; - while ((ret = br.readLine()) != null) { - if (ret != null && !"".equals(ret.trim())) { - result.append(new String(ret.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8)); - } - } - log.info("recv - {}", result); - conn.disconnect(); - br.close(); - } catch (ConnectException e) { - log.error("调用HttpUtils.sendSSLPost ConnectException, url=" + url + ",param=" + param, e); - } catch (SocketTimeoutException e) { - log.error("调用HttpUtils.sendSSLPost SocketTimeoutException, url=" + url + ",param=" + param, e); - } catch (IOException e) { - log.error("调用HttpUtils.sendSSLPost IOException, url=" + url + ",param=" + param, e); - } catch (Exception e) { - log.error("调用HttpsUtil.sendSSLPost Exception, url=" + url + ",param=" + param, e); - } - return result.toString(); - } - - private static class TrustAnyTrustManager implements X509TrustManager { - @Override - public void checkClientTrusted(X509Certificate[] chain, String authType) { - } - - @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) { - } - - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[]{}; - } - } - - private static class TrustAnyHostnameVerifier implements HostnameVerifier { - @Override - public boolean verify(String hostname, SSLSession session) { - return true; - } - } } \ No newline at end of file diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java index 98e34f8..70f031a 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java @@ -680,19 +680,39 @@ public class ExcelUtil { * @return 结果 */ public AjaxResult exportExcel() { - OutputStream out = null; - try { - writeSheet(); - String filename = encodingFilename(sheetName); - out = new FileOutputStream(getAbsoluteFile(filename)); - wb.write(out); +// OutputStream out = null; +// try { +// writeSheet(); +// String filename = encodingFilename(sheetName); +// out = new FileOutputStream(getAbsoluteFile(filename)); +// wb.write(out); +// return AjaxResult.success(filename); +// } catch (Exception e) { +// log.error("导出Excel异常{}", e.getMessage()); +// throw new UtilException("导出Excel失败,请联系网站管理员!"); +// } finally { +// IOUtils.closeQuietly(wb); +// IOUtils.closeQuietly(out); +// } + String filename = encodingFilename(sheetName); + + // 使用 try-with-resources 自动管理 FileOutputStream + try (OutputStream out = new FileOutputStream(getAbsoluteFile(filename))) { + writeSheet(); // 确保在写入之前准备好工作表 + wb.write(out); // 写入数据到输出流 return AjaxResult.success(filename); } catch (Exception e) { - log.error("导出Excel异常{}", e.getMessage()); + log.error("导出Excel异常: {}", e.getMessage(), e); throw new UtilException("导出Excel失败,请联系网站管理员!"); } finally { - IOUtils.closeQuietly(wb); - IOUtils.closeQuietly(out); + // 确保 Workbook 被关闭 + if (wb != null) { + try { + wb.close(); + } catch (IOException e) { + log.error("关闭Workbook时发生异常: {}", e.getMessage(), e); + } + } } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ProjectExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ProjectExcelUtil.java index 101e9a4..5d61678 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ProjectExcelUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ProjectExcelUtil.java @@ -716,19 +716,39 @@ public class ProjectExcelUtil { * @return 结果 */ public AjaxResult exportExcel() { - OutputStream out = null; - try { - writeSheet(); - String filename = encodingFilename(sheetName); - out = new FileOutputStream(getAbsoluteFile(filename)); - wb.write(out); +// OutputStream out = null; +// try { +// writeSheet(); +// String filename = encodingFilename(sheetName); +// out = new FileOutputStream(getAbsoluteFile(filename)); +// wb.write(out); +// return AjaxResult.success(filename); +// } catch (Exception e) { +// log.error("导出Excel异常{}", e.getMessage()); +// throw new UtilException("导出Excel失败,请联系网站管理员!"); +// } finally { +// IOUtils.closeQuietly(wb); +// IOUtils.closeQuietly(out); +// } + String filename = encodingFilename(sheetName); + + // 使用 try-with-resources 自动管理 FileOutputStream + try (OutputStream out = new FileOutputStream(getAbsoluteFile(filename))) { + writeSheet(); // 确保在写入之前准备好工作表 + wb.write(out); // 写入数据到输出流 return AjaxResult.success(filename); } catch (Exception e) { - log.error("导出Excel异常{}", e.getMessage()); + log.error("导出Excel异常: {}", e.getMessage(), e); throw new UtilException("导出Excel失败,请联系网站管理员!"); } finally { - IOUtils.closeQuietly(wb); - IOUtils.closeQuietly(out); + // 确保 Workbook 被关闭 + if (wb != null) { + try { + wb.close(); + } catch (IOException e) { + log.error("关闭Workbook时发生异常: {}", e.getMessage(), e); + } + } } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ProjectValueUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ProjectValueUtil.java index 14e3260..0fb37a6 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ProjectValueUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ProjectValueUtil.java @@ -715,19 +715,39 @@ public class ProjectValueUtil { * @return 结果 */ public AjaxResult exportExcel() { - OutputStream out = null; - try { - writeSheet(); - String filename = encodingFilename(sheetName); - out = new FileOutputStream(getAbsoluteFile(filename)); - wb.write(out); +// OutputStream out = null; +// try { +// writeSheet(); +// String filename = encodingFilename(sheetName); +// out = new FileOutputStream(getAbsoluteFile(filename)); +// wb.write(out); +// return AjaxResult.success(filename); +// } catch (Exception e) { +// log.error("导出Excel异常{}", e.getMessage()); +// throw new UtilException("导出Excel失败,请联系网站管理员!"); +// } finally { +// IOUtils.closeQuietly(wb); +// IOUtils.closeQuietly(out); +// } + String filename = encodingFilename(sheetName); + + // 使用 try-with-resources 自动管理 FileOutputStream + try (OutputStream out = new FileOutputStream(getAbsoluteFile(filename))) { + writeSheet(); // 确保在写入之前准备好工作表 + wb.write(out); // 写入数据到输出流 return AjaxResult.success(filename); } catch (Exception e) { - log.error("导出Excel异常{}", e.getMessage()); + log.error("导出Excel异常: {}", e.getMessage(), e); throw new UtilException("导出Excel失败,请联系网站管理员!"); } finally { - IOUtils.closeQuietly(wb); - IOUtils.closeQuietly(out); + // 确保 Workbook 被关闭 + if (wb != null) { + try { + wb.close(); + } catch (IOException e) { + log.error("关闭Workbook时发生异常: {}", e.getMessage(), e); + } + } } } diff --git a/ruoyi-generator/pom.xml b/ruoyi-generator/pom.xml deleted file mode 100644 index a4da824..0000000 --- a/ruoyi-generator/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - ruoyi - com.ruoyi - 3.8.7 - - 4.0.0 - - ruoyi-generator - - - generator代码生成 - - - - - - - org.apache.velocity - velocity-engine-core - - - - - com.ruoyi - ruoyi-common - - - - - com.alibaba - druid-spring-boot-starter - - - - - \ No newline at end of file diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java deleted file mode 100644 index 7baa6cd..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/config/GenConfig.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.ruoyi.generator.config; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.PropertySource; -import org.springframework.stereotype.Component; - -/** - * 读取代码生成相关配置 - * - * @author ruoyi - */ -@Component -@ConfigurationProperties(prefix = "gen") -@PropertySource(value = {"classpath:generator.yml"}) -public class GenConfig { - /** - * 作者 - */ - public static String author; - - /** - * 生成包路径 - */ - public static String packageName; - - /** - * 自动去除表前缀,默认是false - */ - public static boolean autoRemovePre; - - /** - * 表前缀(类名不会包含表前缀) - */ - public static String tablePrefix; - - public static String getAuthor() { - return author; - } - - @Value("${author}") - public void setAuthor(String author) { - GenConfig.author = author; - } - - public static String getPackageName() { - return packageName; - } - - @Value("${packageName}") - public void setPackageName(String packageName) { - GenConfig.packageName = packageName; - } - - public static boolean getAutoRemovePre() { - return autoRemovePre; - } - - @Value("${autoRemovePre}") - public void setAutoRemovePre(boolean autoRemovePre) { - GenConfig.autoRemovePre = autoRemovePre; - } - - public static String getTablePrefix() { - return tablePrefix; - } - - @Value("${tablePrefix}") - public void setTablePrefix(String tablePrefix) { - GenConfig.tablePrefix = tablePrefix; - } -} diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java deleted file mode 100644 index fa532d4..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java +++ /dev/null @@ -1,236 +0,0 @@ -package com.ruoyi.generator.controller; - -import com.alibaba.druid.DbType; -import com.alibaba.druid.sql.SQLUtils; -import com.alibaba.druid.sql.ast.SQLStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement; -import com.ruoyi.common.annotation.Log; -import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.core.page.TableDataInfo; -import com.ruoyi.common.core.text.Convert; -import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.sql.SqlUtil; -import com.ruoyi.generator.domain.GenTable; -import com.ruoyi.generator.domain.GenTableColumn; -import com.ruoyi.generator.service.IGenTableColumnService; -import com.ruoyi.generator.service.IGenTableService; -import org.apache.commons.io.IOUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * 代码生成 操作处理 - * - * @author ruoyi - */ -@RestController -@RequestMapping("/tool/gen") -public class GenController extends BaseController { - @Autowired - private IGenTableService genTableService; - - @Autowired - private IGenTableColumnService genTableColumnService; - - /** - * 查询代码生成列表 - */ - @PreAuthorize("@ss.hasPermi('tool:gen:list')") - @GetMapping("/list") - public TableDataInfo genList(GenTable genTable) { - startPage(); - List list = genTableService.selectGenTableList(genTable); - return getDataTable(list); - } - - /** - * 修改代码生成业务 - */ - @PreAuthorize("@ss.hasPermi('tool:gen:query')") - @GetMapping(value = "/{tableId}") - public AjaxResult getInfo(@PathVariable Long tableId) { - GenTable table = genTableService.selectGenTableById(tableId); - List tables = genTableService.selectGenTableAll(); - List list = genTableColumnService.selectGenTableColumnListByTableId(tableId); - Map map = new HashMap(); - map.put("info", table); - map.put("rows", list); - map.put("tables", tables); - return success(map); - } - - /** - * 查询数据库列表 - */ - @PreAuthorize("@ss.hasPermi('tool:gen:list')") - @GetMapping("/db/list") - public TableDataInfo dataList(GenTable genTable) { - startPage(); - List list = genTableService.selectDbTableList(genTable); - return getDataTable(list); - } - - /** - * 查询数据表字段列表 - */ - @PreAuthorize("@ss.hasPermi('tool:gen:list')") - @GetMapping(value = "/column/{tableId}") - public TableDataInfo columnList(Long tableId) { - TableDataInfo dataInfo = new TableDataInfo(); - List list = genTableColumnService.selectGenTableColumnListByTableId(tableId); - dataInfo.setRows(list); - dataInfo.setTotal(list.size()); - return dataInfo; - } - - /** - * 导入表结构(保存) - */ - @PreAuthorize("@ss.hasPermi('tool:gen:import')") - @Log(title = "代码生成", businessType = BusinessType.IMPORT) - @PostMapping("/importTable") - public AjaxResult importTableSave(String tables) { - String[] tableNames = Convert.toStrArray(tables); - // 查询表信息 - List tableList = genTableService.selectDbTableListByNames(tableNames); - genTableService.importGenTable(tableList, SecurityUtils.getUsername()); - return success(); - } - - /** - * 创建表结构(保存) - */ - @PreAuthorize("@ss.hasRole('admin')") - @Log(title = "创建表", businessType = BusinessType.OTHER) - @PostMapping("/createTable") - public AjaxResult createTableSave(String sql) { - try { - SqlUtil.filterKeyword(sql); - List sqlStatements = SQLUtils.parseStatements(sql, DbType.mysql); - List tableNames = new ArrayList<>(); - for (SQLStatement sqlStatement : sqlStatements) { - if (sqlStatement instanceof MySqlCreateTableStatement) { - MySqlCreateTableStatement createTableStatement = (MySqlCreateTableStatement) sqlStatement; - if (genTableService.createTable(createTableStatement.toString())) { - String tableName = createTableStatement.getTableName().replaceAll("`", ""); - tableNames.add(tableName); - } - } - } - List tableList = genTableService.selectDbTableListByNames(tableNames.toArray(new String[tableNames.size()])); - String operName = SecurityUtils.getUsername(); - genTableService.importGenTable(tableList, operName); - return AjaxResult.success(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - return AjaxResult.error("创建表结构异常"); - } - } - - /** - * 修改保存代码生成业务 - */ - @PreAuthorize("@ss.hasPermi('tool:gen:edit')") - @Log(title = "代码生成", businessType = BusinessType.UPDATE) - @PostMapping("/edit") - public AjaxResult editSave(@Validated @RequestBody GenTable genTable) { - genTableService.validateEdit(genTable); - genTableService.updateGenTable(genTable); - return success(); - } - - /** - * 删除代码生成 - */ - @PreAuthorize("@ss.hasPermi('tool:gen:remove')") - @Log(title = "代码生成", businessType = BusinessType.DELETE) - @PostMapping("/{tableIds}") - public AjaxResult remove(@PathVariable Long[] tableIds) { - genTableService.deleteGenTableByIds(tableIds); - return success(); - } - - /** - * 预览代码 - */ - @PreAuthorize("@ss.hasPermi('tool:gen:preview')") - @GetMapping("/preview/{tableId}") - public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException { - Map dataMap = genTableService.previewCode(tableId); - return success(dataMap); - } - - /** - * 生成代码(下载方式) - */ - @PreAuthorize("@ss.hasPermi('tool:gen:code')") - @Log(title = "代码生成", businessType = BusinessType.GENCODE) - @GetMapping("/download/{tableName}") - public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException { - byte[] data = genTableService.downloadCode(tableName); - genCode(response, data); - } - - /** - * 生成代码(自定义路径) - */ - @PreAuthorize("@ss.hasPermi('tool:gen:code')") - @Log(title = "代码生成", businessType = BusinessType.GENCODE) - @GetMapping("/genCode/{tableName}") - public AjaxResult genCode(@PathVariable("tableName") String tableName) { - genTableService.generatorCode(tableName); - return success(); - } - - /** - * 同步数据库 - */ - @PreAuthorize("@ss.hasPermi('tool:gen:edit')") - @Log(title = "代码生成", businessType = BusinessType.UPDATE) - @GetMapping("/synchDb/{tableName}") - public AjaxResult synchDb(@PathVariable("tableName") String tableName) { - genTableService.synchDb(tableName); - return success(); - } - - /** - * 批量生成代码 - */ - @PreAuthorize("@ss.hasPermi('tool:gen:code')") - @Log(title = "代码生成", businessType = BusinessType.GENCODE) - @GetMapping("/batchGenCode") - public void batchGenCode(HttpServletResponse response, String tables) throws IOException { - String[] tableNames = Convert.toStrArray(tables); - byte[] data = genTableService.downloadCode(tableNames); - genCode(response, data); - } - - /** - * 生成zip文件 - */ - private void genCode(HttpServletResponse response, byte[] data) throws IOException { - response.reset(); - response.addHeader("Access-Control-Allow-Origin", "*"); - response.addHeader("Access-Control-Expose-Headers", "Content-Disposition"); - response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); - response.addHeader("Content-Length", "" + data.length); - response.setContentType("application/octet-stream; charset=UTF-8"); - IOUtils.write(data, response.getOutputStream()); - } -} \ No newline at end of file diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java deleted file mode 100644 index 101f0cc..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java +++ /dev/null @@ -1,376 +0,0 @@ -package com.ruoyi.generator.domain; - -import com.ruoyi.common.constant.GenConstants; -import com.ruoyi.common.core.domain.BaseEntity; -import com.ruoyi.common.utils.StringUtils; -import org.apache.commons.lang3.ArrayUtils; - -import javax.validation.Valid; -import javax.validation.constraints.NotBlank; -import java.util.List; - -/** - * 业务表 gen_table - * - * @author ruoyi - */ -public class GenTable extends BaseEntity { - private static final long serialVersionUID = 1L; - - /** - * 编号 - */ - private Long tableId; - - /** - * 表名称 - */ - @NotBlank(message = "表名称不能为空") - private String tableName; - - /** - * 表描述 - */ - @NotBlank(message = "表描述不能为空") - private String tableComment; - - /** - * 关联父表的表名 - */ - private String subTableName; - - /** - * 本表关联父表的外键名 - */ - private String subTableFkName; - - /** - * 实体类名称(首字母大写) - */ - @NotBlank(message = "实体类名称不能为空") - private String className; - - /** - * 使用的模板(crud单表操作 tree树表操作 sub主子表操作) - */ - private String tplCategory; - - /** - * 前端类型(element-ui模版 element-plus模版) - */ - private String tplWebType; - - /** - * 生成包路径 - */ - @NotBlank(message = "生成包路径不能为空") - private String packageName; - - /** - * 生成模块名 - */ - @NotBlank(message = "生成模块名不能为空") - private String moduleName; - - /** - * 生成业务名 - */ - @NotBlank(message = "生成业务名不能为空") - private String businessName; - - /** - * 生成功能名 - */ - @NotBlank(message = "生成功能名不能为空") - private String functionName; - - /** - * 生成作者 - */ - @NotBlank(message = "作者不能为空") - private String functionAuthor; - - /** - * 生成代码方式(0zip压缩包 1自定义路径) - */ - private String genType; - - /** - * 生成路径(不填默认项目路径) - */ - private String genPath; - - /** - * 主键信息 - */ - private GenTableColumn pkColumn; - - /** - * 子表信息 - */ - private GenTable subTable; - - /** - * 表列信息 - */ - @Valid - private List columns; - - /** - * 其它生成选项 - */ - private String options; - - /** - * 树编码字段 - */ - private String treeCode; - - /** - * 树父编码字段 - */ - private String treeParentCode; - - /** - * 树名称字段 - */ - private String treeName; - - /** - * 上级菜单ID字段 - */ - private String parentMenuId; - - /** - * 上级菜单名称字段 - */ - private String parentMenuName; - - public static boolean isSub(String tplCategory) { - return tplCategory != null && StringUtils.equals(GenConstants.TPL_SUB, tplCategory); - } - - public static boolean isTree(String tplCategory) { - return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory); - } - - public static boolean isCrud(String tplCategory) { - return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory); - } - - public static boolean isSuperColumn(String tplCategory, String javaField) { - if (isTree(tplCategory)) { - return StringUtils.equalsAnyIgnoreCase(javaField, - ArrayUtils.addAll(GenConstants.TREE_ENTITY, GenConstants.BASE_ENTITY)); - } - return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); - } - - public Long getTableId() { - return tableId; - } - - public void setTableId(Long tableId) { - this.tableId = tableId; - } - - public String getTableName() { - return tableName; - } - - public void setTableName(String tableName) { - this.tableName = tableName; - } - - public String getTableComment() { - return tableComment; - } - - public void setTableComment(String tableComment) { - this.tableComment = tableComment; - } - - public String getSubTableName() { - return subTableName; - } - - public void setSubTableName(String subTableName) { - this.subTableName = subTableName; - } - - public String getSubTableFkName() { - return subTableFkName; - } - - public void setSubTableFkName(String subTableFkName) { - this.subTableFkName = subTableFkName; - } - - public String getClassName() { - return className; - } - - public void setClassName(String className) { - this.className = className; - } - - public String getTplCategory() { - return tplCategory; - } - - public void setTplCategory(String tplCategory) { - this.tplCategory = tplCategory; - } - - public String getTplWebType() { - return tplWebType; - } - - public void setTplWebType(String tplWebType) { - this.tplWebType = tplWebType; - } - - public String getPackageName() { - return packageName; - } - - public void setPackageName(String packageName) { - this.packageName = packageName; - } - - public String getModuleName() { - return moduleName; - } - - public void setModuleName(String moduleName) { - this.moduleName = moduleName; - } - - public String getBusinessName() { - return businessName; - } - - public void setBusinessName(String businessName) { - this.businessName = businessName; - } - - public String getFunctionName() { - return functionName; - } - - public void setFunctionName(String functionName) { - this.functionName = functionName; - } - - public String getFunctionAuthor() { - return functionAuthor; - } - - public void setFunctionAuthor(String functionAuthor) { - this.functionAuthor = functionAuthor; - } - - public String getGenType() { - return genType; - } - - public void setGenType(String genType) { - this.genType = genType; - } - - public String getGenPath() { - return genPath; - } - - public void setGenPath(String genPath) { - this.genPath = genPath; - } - - public GenTableColumn getPkColumn() { - return pkColumn; - } - - public void setPkColumn(GenTableColumn pkColumn) { - this.pkColumn = pkColumn; - } - - public GenTable getSubTable() { - return subTable; - } - - public void setSubTable(GenTable subTable) { - this.subTable = subTable; - } - - public List getColumns() { - return columns; - } - - public void setColumns(List columns) { - this.columns = columns; - } - - public String getOptions() { - return options; - } - - public void setOptions(String options) { - this.options = options; - } - - public String getTreeCode() { - return treeCode; - } - - public void setTreeCode(String treeCode) { - this.treeCode = treeCode; - } - - public String getTreeParentCode() { - return treeParentCode; - } - - public void setTreeParentCode(String treeParentCode) { - this.treeParentCode = treeParentCode; - } - - public String getTreeName() { - return treeName; - } - - public void setTreeName(String treeName) { - this.treeName = treeName; - } - - public String getParentMenuId() { - return parentMenuId; - } - - public void setParentMenuId(String parentMenuId) { - this.parentMenuId = parentMenuId; - } - - public String getParentMenuName() { - return parentMenuName; - } - - public void setParentMenuName(String parentMenuName) { - this.parentMenuName = parentMenuName; - } - - public boolean isSub() { - return isSub(this.tplCategory); - } - - public boolean isTree() { - return isTree(this.tplCategory); - } - - public boolean isCrud() { - return isCrud(this.tplCategory); - } - - public boolean isSuperColumn(String javaField) { - return isSuperColumn(this.tplCategory, javaField); - } -} \ No newline at end of file diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java deleted file mode 100644 index ed0c90b..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java +++ /dev/null @@ -1,348 +0,0 @@ -package com.ruoyi.generator.domain; - -import com.ruoyi.common.core.domain.BaseEntity; -import com.ruoyi.common.utils.StringUtils; - -import javax.validation.constraints.NotBlank; - -/** - * 代码生成业务字段表 gen_table_column - * - * @author ruoyi - */ -public class GenTableColumn extends BaseEntity { - private static final long serialVersionUID = 1L; - - /** - * 编号 - */ - private Long columnId; - - /** - * 归属表编号 - */ - private Long tableId; - - /** - * 列名称 - */ - private String columnName; - - /** - * 列描述 - */ - private String columnComment; - - /** - * 列类型 - */ - private String columnType; - - /** - * JAVA类型 - */ - private String javaType; - - /** - * JAVA字段名 - */ - @NotBlank(message = "Java属性不能为空") - private String javaField; - - /** - * 是否主键(1是) - */ - private String isPk; - - /** - * 是否自增(1是) - */ - private String isIncrement; - - /** - * 是否必填(1是) - */ - private String isRequired; - - /** - * 是否为插入字段(1是) - */ - private String isInsert; - - /** - * 是否编辑字段(1是) - */ - private String isEdit; - - /** - * 是否列表字段(1是) - */ - private String isList; - - /** - * 是否查询字段(1是) - */ - private String isQuery; - - /** - * 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) - */ - private String queryType; - - /** - * 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传控件、upload文件上传控件、editor富文本控件) - */ - private String htmlType; - - /** - * 字典类型 - */ - private String dictType; - - /** - * 排序 - */ - private Integer sort; - - public static boolean isSuperColumn(String javaField) { - return StringUtils.equalsAnyIgnoreCase(javaField, - // BaseEntity - "createBy", "createTime", "updateBy", "updateTime", "remark", - // TreeEntity - "parentName", "parentId", "orderNum", "ancestors"); - } - - public static boolean isUsableColumn(String javaField) { - // isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单 - return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark"); - } - - public Long getColumnId() { - return columnId; - } - - public void setColumnId(Long columnId) { - this.columnId = columnId; - } - - public Long getTableId() { - return tableId; - } - - public void setTableId(Long tableId) { - this.tableId = tableId; - } - - public String getColumnName() { - return columnName; - } - - public void setColumnName(String columnName) { - this.columnName = columnName; - } - - public String getColumnComment() { - return columnComment; - } - - public void setColumnComment(String columnComment) { - this.columnComment = columnComment; - } - - public String getColumnType() { - return columnType; - } - - public void setColumnType(String columnType) { - this.columnType = columnType; - } - - public String getJavaType() { - return javaType; - } - - public void setJavaType(String javaType) { - this.javaType = javaType; - } - - public String getJavaField() { - return javaField; - } - - public void setJavaField(String javaField) { - this.javaField = javaField; - } - - public String getCapJavaField() { - return StringUtils.capitalize(javaField); - } - - public String getIsPk() { - return isPk; - } - - public void setIsPk(String isPk) { - this.isPk = isPk; - } - - public boolean isPk() { - return isPk(this.isPk); - } - - public boolean isPk(String isPk) { - return isPk != null && StringUtils.equals("1", isPk); - } - - public String getIsIncrement() { - return isIncrement; - } - - public void setIsIncrement(String isIncrement) { - this.isIncrement = isIncrement; - } - - public boolean isIncrement() { - return isIncrement(this.isIncrement); - } - - public boolean isIncrement(String isIncrement) { - return isIncrement != null && StringUtils.equals("1", isIncrement); - } - - public String getIsRequired() { - return isRequired; - } - - public void setIsRequired(String isRequired) { - this.isRequired = isRequired; - } - - public boolean isRequired() { - return isRequired(this.isRequired); - } - - public boolean isRequired(String isRequired) { - return isRequired != null && StringUtils.equals("1", isRequired); - } - - public String getIsInsert() { - return isInsert; - } - - public void setIsInsert(String isInsert) { - this.isInsert = isInsert; - } - - public boolean isInsert() { - return isInsert(this.isInsert); - } - - public boolean isInsert(String isInsert) { - return isInsert != null && StringUtils.equals("1", isInsert); - } - - public String getIsEdit() { - return isEdit; - } - - public void setIsEdit(String isEdit) { - this.isEdit = isEdit; - } - - public boolean isEdit() { - return isInsert(this.isEdit); - } - - public boolean isEdit(String isEdit) { - return isEdit != null && StringUtils.equals("1", isEdit); - } - - public String getIsList() { - return isList; - } - - public void setIsList(String isList) { - this.isList = isList; - } - - public boolean isList() { - return isList(this.isList); - } - - public boolean isList(String isList) { - return isList != null && StringUtils.equals("1", isList); - } - - public String getIsQuery() { - return isQuery; - } - - public void setIsQuery(String isQuery) { - this.isQuery = isQuery; - } - - public boolean isQuery() { - return isQuery(this.isQuery); - } - - public boolean isQuery(String isQuery) { - return isQuery != null && StringUtils.equals("1", isQuery); - } - - public String getQueryType() { - return queryType; - } - - public void setQueryType(String queryType) { - this.queryType = queryType; - } - - public String getHtmlType() { - return htmlType; - } - - public void setHtmlType(String htmlType) { - this.htmlType = htmlType; - } - - public String getDictType() { - return dictType; - } - - public void setDictType(String dictType) { - this.dictType = dictType; - } - - public Integer getSort() { - return sort; - } - - public void setSort(Integer sort) { - this.sort = sort; - } - - public boolean isSuperColumn() { - return isSuperColumn(this.javaField); - } - - public boolean isUsableColumn() { - return isUsableColumn(javaField); - } - - public String readConverterExp() { - String remarks = StringUtils.substringBetween(this.columnComment, "(", ")"); - StringBuffer sb = new StringBuffer(); - if (StringUtils.isNotEmpty(remarks)) { - for (String value : remarks.split(" ")) { - if (StringUtils.isNotEmpty(value)) { - Object startStr = value.subSequence(0, 1); - String endStr = value.substring(1); - sb.append("").append(startStr).append("=").append(endStr).append(","); - } - } - return sb.deleteCharAt(sb.length() - 1).toString(); - } else { - return this.columnComment; - } - } -} diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java deleted file mode 100644 index 2b9470f..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.ruoyi.generator.mapper; - -import com.ruoyi.generator.domain.GenTableColumn; - -import java.util.List; - -/** - * 业务字段 数据层 - * - * @author ruoyi - */ -public interface GenTableColumnMapper { - /** - * 根据表名称查询列信息 - * - * @param tableName 表名称 - * @return 列信息 - */ - public List selectDbTableColumnsByName(String tableName); - - /** - * 查询业务字段列表 - * - * @param tableId 业务字段编号 - * @return 业务字段集合 - */ - public List selectGenTableColumnListByTableId(Long tableId); - - /** - * 新增业务字段 - * - * @param genTableColumn 业务字段信息 - * @return 结果 - */ - public int insertGenTableColumn(GenTableColumn genTableColumn); - - /** - * 修改业务字段 - * - * @param genTableColumn 业务字段信息 - * @return 结果 - */ - public int updateGenTableColumn(GenTableColumn genTableColumn); - - /** - * 删除业务字段 - * - * @param genTableColumns 列数据 - * @return 结果 - */ - public int deleteGenTableColumns(List genTableColumns); - - /** - * 批量删除业务字段 - * - * @param ids 需要删除的数据ID - * @return 结果 - */ - public int deleteGenTableColumnByIds(Long[] ids); -} diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java deleted file mode 100644 index 1eed653..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.ruoyi.generator.mapper; - -import com.ruoyi.generator.domain.GenTable; - -import java.util.List; - -/** - * 业务 数据层 - * - * @author ruoyi - */ -public interface GenTableMapper { - /** - * 查询业务列表 - * - * @param genTable 业务信息 - * @return 业务集合 - */ - public List selectGenTableList(GenTable genTable); - - /** - * 查询据库列表 - * - * @param genTable 业务信息 - * @return 数据库表集合 - */ - public List selectDbTableList(GenTable genTable); - - /** - * 查询据库列表 - * - * @param tableNames 表名称组 - * @return 数据库表集合 - */ - public List selectDbTableListByNames(String[] tableNames); - - /** - * 查询所有表信息 - * - * @return 表信息集合 - */ - public List selectGenTableAll(); - - /** - * 查询表ID业务信息 - * - * @param id 业务ID - * @return 业务信息 - */ - public GenTable selectGenTableById(Long id); - - /** - * 查询表名称业务信息 - * - * @param tableName 表名称 - * @return 业务信息 - */ - public GenTable selectGenTableByName(String tableName); - - /** - * 新增业务 - * - * @param genTable 业务信息 - * @return 结果 - */ - public int insertGenTable(GenTable genTable); - - /** - * 修改业务 - * - * @param genTable 业务信息 - * @return 结果 - */ - public int updateGenTable(GenTable genTable); - - /** - * 批量删除业务 - * - * @param ids 需要删除的数据ID - * @return 结果 - */ - public int deleteGenTableByIds(Long[] ids); - - /** - * 创建表 - * - * @param sql 表结构 - * @return 结果 - */ - public int createTable(String sql); -} diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java deleted file mode 100644 index 018cf7b..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.ruoyi.generator.service; - -import com.ruoyi.common.core.text.Convert; -import com.ruoyi.generator.domain.GenTableColumn; -import com.ruoyi.generator.mapper.GenTableColumnMapper; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.util.List; - -/** - * 业务字段 服务层实现 - * - * @author ruoyi - */ -@Service -public class GenTableColumnServiceImpl implements IGenTableColumnService { - - @Resource - private GenTableColumnMapper genTableColumnMapper; - - /** - * 查询业务字段列表 - * - * @param tableId 业务字段编号 - * @return 业务字段集合 - */ - @Override - public List selectGenTableColumnListByTableId(Long tableId) { - return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); - } - - /** - * 新增业务字段 - * - * @param genTableColumn 业务字段信息 - * @return 结果 - */ - @Override - public int insertGenTableColumn(GenTableColumn genTableColumn) { - return genTableColumnMapper.insertGenTableColumn(genTableColumn); - } - - /** - * 修改业务字段 - * - * @param genTableColumn 业务字段信息 - * @return 结果 - */ - @Override - public int updateGenTableColumn(GenTableColumn genTableColumn) { - return genTableColumnMapper.updateGenTableColumn(genTableColumn); - } - - /** - * 删除业务字段对象 - * - * @param ids 需要删除的数据ID - * @return 结果 - */ - @Override - public int deleteGenTableColumnByIds(String ids) { - return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); - } -} diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java deleted file mode 100644 index 2c7b5c2..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java +++ /dev/null @@ -1,464 +0,0 @@ -package com.ruoyi.generator.service; - -import com.alibaba.fastjson2.JSON; -import com.alibaba.fastjson2.JSONObject; -import com.ruoyi.common.constant.Constants; -import com.ruoyi.common.constant.GenConstants; -import com.ruoyi.common.core.text.CharsetKit; -import com.ruoyi.common.exception.ServiceException; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.generator.domain.GenTable; -import com.ruoyi.generator.domain.GenTableColumn; -import com.ruoyi.generator.mapper.GenTableColumnMapper; -import com.ruoyi.generator.mapper.GenTableMapper; -import com.ruoyi.generator.util.GenUtils; -import com.ruoyi.generator.util.VelocityInitializer; -import com.ruoyi.generator.util.VelocityUtils; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.velocity.Template; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.app.Velocity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import javax.annotation.Resource; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.StringWriter; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -/** - * 业务 服务层实现 - * - * @author ruoyi - */ -@Service -public class GenTableServiceImpl implements IGenTableService { - private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); - - @Resource - private GenTableMapper genTableMapper; - - @Resource - private GenTableColumnMapper genTableColumnMapper; - - /** - * 获取代码生成地址 - * - * @param table 业务表信息 - * @param template 模板文件路径 - * @return 生成地址 - */ - public static String getGenPath(GenTable table, String template) { - String genPath = table.getGenPath(); - if (StringUtils.equals(genPath, "/")) { - return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); - } - return genPath + File.separator + VelocityUtils.getFileName(template, table); - } - - /** - * 查询业务信息 - * - * @param id 业务ID - * @return 业务信息 - */ - @Override - public GenTable selectGenTableById(Long id) { - GenTable genTable = genTableMapper.selectGenTableById(id); - setTableFromOptions(genTable); - return genTable; - } - - /** - * 查询业务列表 - * - * @param genTable 业务信息 - * @return 业务集合 - */ - @Override - public List selectGenTableList(GenTable genTable) { - return genTableMapper.selectGenTableList(genTable); - } - - /** - * 查询据库列表 - * - * @param genTable 业务信息 - * @return 数据库表集合 - */ - @Override - public List selectDbTableList(GenTable genTable) { - return genTableMapper.selectDbTableList(genTable); - } - - /** - * 查询据库列表 - * - * @param tableNames 表名称组 - * @return 数据库表集合 - */ - @Override - public List selectDbTableListByNames(String[] tableNames) { - return genTableMapper.selectDbTableListByNames(tableNames); - } - - /** - * 查询所有表信息 - * - * @return 表信息集合 - */ - @Override - public List selectGenTableAll() { - return genTableMapper.selectGenTableAll(); - } - - /** - * 修改业务 - * - * @param genTable 业务信息 - * @return 结果 - */ - @Override - @Transactional - public void updateGenTable(GenTable genTable) { - String options = JSON.toJSONString(genTable.getParams()); - genTable.setOptions(options); - int row = genTableMapper.updateGenTable(genTable); - if (row > 0) { - for (GenTableColumn cenTableColumn : genTable.getColumns()) { - genTableColumnMapper.updateGenTableColumn(cenTableColumn); - } - } - } - - /** - * 删除业务对象 - * - * @param tableIds 需要删除的数据ID - * @return 结果 - */ - @Override - @Transactional - public void deleteGenTableByIds(Long[] tableIds) { - genTableMapper.deleteGenTableByIds(tableIds); - genTableColumnMapper.deleteGenTableColumnByIds(tableIds); - } - - /** - * 创建表 - * - * @param sql 创建表语句 - * @return 结果 - */ - @Override - public boolean createTable(String sql) { - return genTableMapper.createTable(sql) == 0; - } - - /** - * 导入表结构 - * - * @param tableList 导入表列表 - */ - @Override - @Transactional - public void importGenTable(List tableList, String operName) { - try { - for (GenTable table : tableList) { - String tableName = table.getTableName(); - GenUtils.initTable(table, operName); - int row = genTableMapper.insertGenTable(table); - if (row > 0) { - // 保存列信息 - List genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); - for (GenTableColumn column : genTableColumns) { - GenUtils.initColumnField(column, table); - genTableColumnMapper.insertGenTableColumn(column); - } - } - } - } catch (Exception e) { - throw new ServiceException("导入失败:" + e.getMessage()); - } - } - - /** - * 预览代码 - * - * @param tableId 表编号 - * @return 预览数据列表 - */ - @Override - public Map previewCode(Long tableId) { - Map dataMap = new LinkedHashMap<>(); - // 查询表信息 - GenTable table = genTableMapper.selectGenTableById(tableId); - // 设置主子表信息 - setSubTable(table); - // 设置主键列信息 - setPkColumn(table); - VelocityInitializer.initVelocity(); - - VelocityContext context = VelocityUtils.prepareContext(table); - - // 获取模板列表 - List templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType()); - for (String template : templates) { - // 渲染模板 - StringWriter sw = new StringWriter(); - Template tpl = Velocity.getTemplate(template, Constants.UTF8); - tpl.merge(context, sw); - dataMap.put(template, sw.toString()); - } - return dataMap; - } - - /** - * 生成代码(下载方式) - * - * @param tableName 表名称 - * @return 数据 - */ - @Override - public byte[] downloadCode(String tableName) { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - ZipOutputStream zip = new ZipOutputStream(outputStream); - generatorCode(tableName, zip); - IOUtils.closeQuietly(zip); - return outputStream.toByteArray(); - } - - /** - * 生成代码(自定义路径) - * - * @param tableName 表名称 - */ - @Override - public void generatorCode(String tableName) { - // 查询表信息 - GenTable table = genTableMapper.selectGenTableByName(tableName); - // 设置主子表信息 - setSubTable(table); - // 设置主键列信息 - setPkColumn(table); - - VelocityInitializer.initVelocity(); - - VelocityContext context = VelocityUtils.prepareContext(table); - - // 获取模板列表 - List templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType()); - for (String template : templates) { - if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) { - // 渲染模板 - StringWriter sw = new StringWriter(); - Template tpl = Velocity.getTemplate(template, Constants.UTF8); - tpl.merge(context, sw); - try { - String path = getGenPath(table, template); - FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8); - } catch (IOException e) { - throw new ServiceException("渲染模板失败,表名:" + table.getTableName()); - } - } - } - } - - /** - * 同步数据库 - * - * @param tableName 表名称 - */ - @Override - @Transactional - public void synchDb(String tableName) { - GenTable table = genTableMapper.selectGenTableByName(tableName); - List tableColumns = table.getColumns(); - Map tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity())); - - List dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); - if (StringUtils.isEmpty(dbTableColumns)) { - throw new ServiceException("同步数据失败,原表结构不存在"); - } - List dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); - - dbTableColumns.forEach(column -> { - GenUtils.initColumnField(column, table); - if (tableColumnMap.containsKey(column.getColumnName())) { - GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName()); - column.setColumnId(prevColumn.getColumnId()); - if (column.isList()) { - // 如果是列表,继续保留查询方式/字典类型选项 - column.setDictType(prevColumn.getDictType()); - column.setQueryType(prevColumn.getQueryType()); - } - if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk() - && (column.isInsert() || column.isEdit()) - && ((column.isUsableColumn()) || (!column.isSuperColumn()))) { - // 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项 - column.setIsRequired(prevColumn.getIsRequired()); - column.setHtmlType(prevColumn.getHtmlType()); - } - genTableColumnMapper.updateGenTableColumn(column); - } else { - genTableColumnMapper.insertGenTableColumn(column); - } - }); - - List delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); - if (StringUtils.isNotEmpty(delColumns)) { - genTableColumnMapper.deleteGenTableColumns(delColumns); - } - } - - /** - * 批量生成代码(下载方式) - * - * @param tableNames 表数组 - * @return 数据 - */ - @Override - public byte[] downloadCode(String[] tableNames) { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - ZipOutputStream zip = new ZipOutputStream(outputStream); - for (String tableName : tableNames) { - generatorCode(tableName, zip); - } - IOUtils.closeQuietly(zip); - return outputStream.toByteArray(); - } - - /** - * 查询表信息并生成代码 - */ - private void generatorCode(String tableName, ZipOutputStream zip) { - // 查询表信息 - GenTable table = genTableMapper.selectGenTableByName(tableName); - // 设置主子表信息 - setSubTable(table); - // 设置主键列信息 - setPkColumn(table); - - VelocityInitializer.initVelocity(); - - VelocityContext context = VelocityUtils.prepareContext(table); - - // 获取模板列表 - List templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType()); - for (String template : templates) { - // 渲染模板 - StringWriter sw = new StringWriter(); - Template tpl = Velocity.getTemplate(template, Constants.UTF8); - tpl.merge(context, sw); - try { - // 添加到zip - zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); - IOUtils.write(sw.toString(), zip, Constants.UTF8); - IOUtils.closeQuietly(sw); - zip.flush(); - zip.closeEntry(); - } catch (IOException e) { - log.error("渲染模板失败,表名:" + table.getTableName(), e); - } - } - } - - /** - * 修改保存参数校验 - * - * @param genTable 业务信息 - */ - @Override - public void validateEdit(GenTable genTable) { - if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { - String options = JSON.toJSONString(genTable.getParams()); - JSONObject paramsObj = JSON.parseObject(options); - if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) { - throw new ServiceException("树编码字段不能为空"); - } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) { - throw new ServiceException("树父编码字段不能为空"); - } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) { - throw new ServiceException("树名称字段不能为空"); - } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) { - if (StringUtils.isEmpty(genTable.getSubTableName())) { - throw new ServiceException("关联子表的表名不能为空"); - } else if (StringUtils.isEmpty(genTable.getSubTableFkName())) { - throw new ServiceException("子表关联的外键名不能为空"); - } - } - } - } - - /** - * 设置主键列信息 - * - * @param table 业务表信息 - */ - public void setPkColumn(GenTable table) { - for (GenTableColumn column : table.getColumns()) { - if (column.isPk()) { - table.setPkColumn(column); - break; - } - } - if (StringUtils.isNull(table.getPkColumn())) { - table.setPkColumn(table.getColumns().get(0)); - } - if (GenConstants.TPL_SUB.equals(table.getTplCategory())) { - for (GenTableColumn column : table.getSubTable().getColumns()) { - if (column.isPk()) { - table.getSubTable().setPkColumn(column); - break; - } - } - if (StringUtils.isNull(table.getSubTable().getPkColumn())) { - table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0)); - } - } - } - - /** - * 设置主子表信息 - * - * @param table 业务表信息 - */ - public void setSubTable(GenTable table) { - String subTableName = table.getSubTableName(); - if (StringUtils.isNotEmpty(subTableName)) { - table.setSubTable(genTableMapper.selectGenTableByName(subTableName)); - } - } - - /** - * 设置代码生成其他选项值 - * - * @param genTable 设置后的生成对象 - */ - public void setTableFromOptions(GenTable genTable) { - JSONObject paramsObj = JSON.parseObject(genTable.getOptions()); - if (StringUtils.isNotNull(paramsObj)) { - String treeCode = paramsObj.getString(GenConstants.TREE_CODE); - String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); - String treeName = paramsObj.getString(GenConstants.TREE_NAME); - String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID); - String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME); - - genTable.setTreeCode(treeCode); - genTable.setTreeParentCode(treeParentCode); - genTable.setTreeName(treeName); - genTable.setParentMenuId(parentMenuId); - genTable.setParentMenuName(parentMenuName); - } - } -} \ No newline at end of file diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java deleted file mode 100644 index f957b33..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableColumnService.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.ruoyi.generator.service; - -import com.ruoyi.generator.domain.GenTableColumn; - -import java.util.List; - -/** - * 业务字段 服务层 - * - * @author ruoyi - */ -public interface IGenTableColumnService { - /** - * 查询业务字段列表 - * - * @param tableId 业务字段编号 - * @return 业务字段集合 - */ - public List selectGenTableColumnListByTableId(Long tableId); - - /** - * 新增业务字段 - * - * @param genTableColumn 业务字段信息 - * @return 结果 - */ - public int insertGenTableColumn(GenTableColumn genTableColumn); - - /** - * 修改业务字段 - * - * @param genTableColumn 业务字段信息 - * @return 结果 - */ - public int updateGenTableColumn(GenTableColumn genTableColumn); - - /** - * 删除业务字段信息 - * - * @param ids 需要删除的数据ID - * @return 结果 - */ - public int deleteGenTableColumnByIds(String ids); -} diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java deleted file mode 100644 index a8a23f7..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.ruoyi.generator.service; - -import com.ruoyi.generator.domain.GenTable; - -import java.util.List; -import java.util.Map; - -/** - * 业务 服务层 - * - * @author ruoyi - */ -public interface IGenTableService { - /** - * 查询业务列表 - * - * @param genTable 业务信息 - * @return 业务集合 - */ - public List selectGenTableList(GenTable genTable); - - /** - * 查询据库列表 - * - * @param genTable 业务信息 - * @return 数据库表集合 - */ - public List selectDbTableList(GenTable genTable); - - /** - * 查询据库列表 - * - * @param tableNames 表名称组 - * @return 数据库表集合 - */ - public List selectDbTableListByNames(String[] tableNames); - - /** - * 查询所有表信息 - * - * @return 表信息集合 - */ - public List selectGenTableAll(); - - /** - * 查询业务信息 - * - * @param id 业务ID - * @return 业务信息 - */ - public GenTable selectGenTableById(Long id); - - /** - * 修改业务 - * - * @param genTable 业务信息 - * @return 结果 - */ - public void updateGenTable(GenTable genTable); - - /** - * 删除业务信息 - * - * @param tableIds 需要删除的表数据ID - * @return 结果 - */ - public void deleteGenTableByIds(Long[] tableIds); - - /** - * 创建表 - * - * @param sql 创建表语句 - * @return 结果 - */ - public boolean createTable(String sql); - - /** - * 导入表结构 - * - * @param tableList 导入表列表 - * @param operName 操作人员 - */ - public void importGenTable(List tableList, String operName); - - /** - * 预览代码 - * - * @param tableId 表编号 - * @return 预览数据列表 - */ - public Map previewCode(Long tableId); - - /** - * 生成代码(下载方式) - * - * @param tableName 表名称 - * @return 数据 - */ - public byte[] downloadCode(String tableName); - - /** - * 生成代码(自定义路径) - * - * @param tableName 表名称 - * @return 数据 - */ - public void generatorCode(String tableName); - - /** - * 同步数据库 - * - * @param tableName 表名称 - */ - public void synchDb(String tableName); - - /** - * 批量生成代码(下载方式) - * - * @param tableNames 表数组 - * @return 数据 - */ - public byte[] downloadCode(String[] tableNames); - - /** - * 修改保存参数校验 - * - * @param genTable 业务信息 - */ - public void validateEdit(GenTable genTable); -} diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java deleted file mode 100644 index 048243d..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/GenUtils.java +++ /dev/null @@ -1,221 +0,0 @@ -package com.ruoyi.generator.util; - -import com.ruoyi.common.constant.GenConstants; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.generator.config.GenConfig; -import com.ruoyi.generator.domain.GenTable; -import com.ruoyi.generator.domain.GenTableColumn; -import org.apache.commons.lang3.RegExUtils; - -import java.util.Arrays; - -/** - * 代码生成器 工具类 - * - * @author ruoyi - */ -public class GenUtils { - /** - * 初始化表信息 - */ - public static void initTable(GenTable genTable, String operName) { - genTable.setClassName(convertClassName(genTable.getTableName())); - genTable.setPackageName(GenConfig.getPackageName()); - genTable.setModuleName(getModuleName(GenConfig.getPackageName())); - genTable.setBusinessName(getBusinessName(genTable.getTableName())); - genTable.setFunctionName(replaceText(genTable.getTableComment())); - genTable.setFunctionAuthor(GenConfig.getAuthor()); - genTable.setCreateBy(operName); - } - - /** - * 初始化列属性字段 - */ - public static void initColumnField(GenTableColumn column, GenTable table) { - String dataType = getDbType(column.getColumnType()); - String columnName = column.getColumnName(); - column.setTableId(table.getTableId()); - column.setCreateBy(table.getCreateBy()); - // 设置java字段名 - column.setJavaField(StringUtils.toCamelCase(columnName)); - // 设置默认类型 - column.setJavaType(GenConstants.TYPE_STRING); - column.setQueryType(GenConstants.QUERY_EQ); - - if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) { - // 字符串长度超过500设置为文本域 - Integer columnLength = getColumnLength(column.getColumnType()); - String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; - column.setHtmlType(htmlType); - } else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) { - column.setJavaType(GenConstants.TYPE_DATE); - column.setHtmlType(GenConstants.HTML_DATETIME); - } else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) { - column.setHtmlType(GenConstants.HTML_INPUT); - - // 如果是浮点型 统一用BigDecimal - String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); - if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) { - column.setJavaType(GenConstants.TYPE_BIGDECIMAL); - } - // 如果是整形 - else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) { - column.setJavaType(GenConstants.TYPE_INTEGER); - } - // 长整形 - else { - column.setJavaType(GenConstants.TYPE_LONG); - } - } - - // 插入字段(默认所有字段都需要插入) - column.setIsInsert(GenConstants.REQUIRE); - - // 编辑字段 - if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) { - column.setIsEdit(GenConstants.REQUIRE); - } - // 列表字段 - if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) { - column.setIsList(GenConstants.REQUIRE); - } - // 查询字段 - if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) { - column.setIsQuery(GenConstants.REQUIRE); - } - - // 查询字段类型 - if (StringUtils.endsWithIgnoreCase(columnName, "name")) { - column.setQueryType(GenConstants.QUERY_LIKE); - } - // 状态字段设置单选框 - if (StringUtils.endsWithIgnoreCase(columnName, "status")) { - column.setHtmlType(GenConstants.HTML_RADIO); - } - // 类型&性别字段设置下拉框 - else if (StringUtils.endsWithIgnoreCase(columnName, "type") - || StringUtils.endsWithIgnoreCase(columnName, "sex")) { - column.setHtmlType(GenConstants.HTML_SELECT); - } - // 图片字段设置图片上传控件 - else if (StringUtils.endsWithIgnoreCase(columnName, "image")) { - column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD); - } - // 文件字段设置文件上传控件 - else if (StringUtils.endsWithIgnoreCase(columnName, "file")) { - column.setHtmlType(GenConstants.HTML_FILE_UPLOAD); - } - // 内容字段设置富文本控件 - else if (StringUtils.endsWithIgnoreCase(columnName, "content")) { - column.setHtmlType(GenConstants.HTML_EDITOR); - } - } - - /** - * 校验数组是否包含指定值 - * - * @param arr 数组 - * @param targetValue 值 - * @return 是否包含 - */ - public static boolean arraysContains(String[] arr, String targetValue) { - return Arrays.asList(arr).contains(targetValue); - } - - /** - * 获取模块名 - * - * @param packageName 包名 - * @return 模块名 - */ - public static String getModuleName(String packageName) { - int lastIndex = packageName.lastIndexOf("."); - int nameLength = packageName.length(); - return StringUtils.substring(packageName, lastIndex + 1, nameLength); - } - - /** - * 获取业务名 - * - * @param tableName 表名 - * @return 业务名 - */ - public static String getBusinessName(String tableName) { - int lastIndex = tableName.lastIndexOf("_"); - int nameLength = tableName.length(); - return StringUtils.substring(tableName, lastIndex + 1, nameLength); - } - - /** - * 表名转换成Java类名 - * - * @param tableName 表名称 - * @return 类名 - */ - public static String convertClassName(String tableName) { - boolean autoRemovePre = GenConfig.getAutoRemovePre(); - String tablePrefix = GenConfig.getTablePrefix(); - if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) { - String[] searchList = StringUtils.split(tablePrefix, ","); - tableName = replaceFirst(tableName, searchList); - } - return StringUtils.convertToCamelCase(tableName); - } - - /** - * 批量替换前缀 - * - * @param replacementm 替换值 - * @param searchList 替换列表 - * @return - */ - public static String replaceFirst(String replacementm, String[] searchList) { - String text = replacementm; - for (String searchString : searchList) { - if (replacementm.startsWith(searchString)) { - text = replacementm.replaceFirst(searchString, ""); - break; - } - } - return text; - } - - /** - * 关键字替换 - * - * @param text 需要被替换的名字 - * @return 替换后的名字 - */ - public static String replaceText(String text) { - return RegExUtils.replaceAll(text, "(?:表|若依)", ""); - } - - /** - * 获取数据库类型字段 - * - * @param columnType 列类型 - * @return 截取后的列类型 - */ - public static String getDbType(String columnType) { - if (StringUtils.indexOf(columnType, "(") > 0) { - return StringUtils.substringBefore(columnType, "("); - } else { - return columnType; - } - } - - /** - * 获取字段长度 - * - * @param columnType 列类型 - * @return 截取后的列类型 - */ - public static Integer getColumnLength(String columnType) { - if (StringUtils.indexOf(columnType, "(") > 0) { - String length = StringUtils.substringBetween(columnType, "(", ")"); - return Integer.valueOf(length); - } else { - return 0; - } - } -} diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityInitializer.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityInitializer.java deleted file mode 100644 index 93d8b46..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityInitializer.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.ruoyi.generator.util; - -import com.ruoyi.common.constant.Constants; -import org.apache.velocity.app.Velocity; - -import java.util.Properties; - -/** - * VelocityEngine工厂 - * - * @author ruoyi - */ -public class VelocityInitializer { - /** - * 初始化vm方法 - */ - public static void initVelocity() { - Properties p = new Properties(); - try { - // 加载classpath目录下的vm文件 - p.setProperty("resource.loader.file.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); - // 定义字符集 - p.setProperty(Velocity.INPUT_ENCODING, Constants.UTF8); - // 初始化Velocity引擎,指定配置Properties - Velocity.init(p); - } catch (Exception e) { - throw new RuntimeException(e); - } - } -} diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java deleted file mode 100644 index bb379cc..0000000 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java +++ /dev/null @@ -1,354 +0,0 @@ -package com.ruoyi.generator.util; - -import com.alibaba.fastjson2.JSON; -import com.alibaba.fastjson2.JSONObject; -import com.ruoyi.common.constant.GenConstants; -import com.ruoyi.common.utils.DateUtils; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.generator.domain.GenTable; -import com.ruoyi.generator.domain.GenTableColumn; -import org.apache.velocity.VelocityContext; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * 模板处理工具类 - * - * @author ruoyi - */ -public class VelocityUtils { - /** - * 项目空间路径 - */ - private static final String PROJECT_PATH = "main/java"; - - /** - * mybatis空间路径 - */ - private static final String MYBATIS_PATH = "main/resources/mapper"; - - /** - * 默认上级菜单,系统工具 - */ - private static final String DEFAULT_PARENT_MENU_ID = "3"; - - /** - * 设置模板变量信息 - * - * @return 模板列表 - */ - public static VelocityContext prepareContext(GenTable genTable) { - String moduleName = genTable.getModuleName(); - String businessName = genTable.getBusinessName(); - String packageName = genTable.getPackageName(); - String tplCategory = genTable.getTplCategory(); - String functionName = genTable.getFunctionName(); - - VelocityContext velocityContext = new VelocityContext(); - velocityContext.put("tplCategory", genTable.getTplCategory()); - velocityContext.put("tableName", genTable.getTableName()); - velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】"); - velocityContext.put("ClassName", genTable.getClassName()); - velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); - velocityContext.put("moduleName", genTable.getModuleName()); - velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); - velocityContext.put("businessName", genTable.getBusinessName()); - velocityContext.put("basePackage", getPackagePrefix(packageName)); - velocityContext.put("packageName", packageName); - velocityContext.put("author", genTable.getFunctionAuthor()); - velocityContext.put("datetime", DateUtils.getDate()); - velocityContext.put("pkColumn", genTable.getPkColumn()); - velocityContext.put("importList", getImportList(genTable)); - velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); - velocityContext.put("columns", genTable.getColumns()); - velocityContext.put("table", genTable); - velocityContext.put("dicts", getDicts(genTable)); - setMenuVelocityContext(velocityContext, genTable); - if (GenConstants.TPL_TREE.equals(tplCategory)) { - setTreeVelocityContext(velocityContext, genTable); - } - if (GenConstants.TPL_SUB.equals(tplCategory)) { - setSubVelocityContext(velocityContext, genTable); - } - return velocityContext; - } - - public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) { - String options = genTable.getOptions(); - JSONObject paramsObj = JSON.parseObject(options); - String parentMenuId = getParentMenuId(paramsObj); - context.put("parentMenuId", parentMenuId); - } - - public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) { - String options = genTable.getOptions(); - JSONObject paramsObj = JSON.parseObject(options); - String treeCode = getTreecode(paramsObj); - String treeParentCode = getTreeParentCode(paramsObj); - String treeName = getTreeName(paramsObj); - - context.put("treeCode", treeCode); - context.put("treeParentCode", treeParentCode); - context.put("treeName", treeName); - context.put("expandColumn", getExpandColumn(genTable)); - if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { - context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE)); - } - if (paramsObj.containsKey(GenConstants.TREE_NAME)) { - context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME)); - } - } - - public static void setSubVelocityContext(VelocityContext context, GenTable genTable) { - GenTable subTable = genTable.getSubTable(); - String subTableName = genTable.getSubTableName(); - String subTableFkName = genTable.getSubTableFkName(); - String subClassName = genTable.getSubTable().getClassName(); - String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName); - - context.put("subTable", subTable); - context.put("subTableName", subTableName); - context.put("subTableFkName", subTableFkName); - context.put("subTableFkClassName", subTableFkClassName); - context.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName)); - context.put("subClassName", subClassName); - context.put("subclassName", StringUtils.uncapitalize(subClassName)); - context.put("subImportList", getImportList(genTable.getSubTable())); - } - - /** - * 获取模板信息 - * - * @param tplCategory 生成的模板 - * @param tplWebType 前端类型 - * @return 模板列表 - */ - public static List getTemplateList(String tplCategory, String tplWebType) { - String useWebType = "vm/vue"; - if ("element-plus".equals(tplWebType)) { - useWebType = "vm/vue/v3"; - } - List templates = new ArrayList(); - templates.add("vm/java/domain.java.vm"); - templates.add("vm/java/mapper.java.vm"); - templates.add("vm/java/service.java.vm"); - templates.add("vm/java/serviceImpl.java.vm"); - templates.add("vm/java/controller.java.vm"); - templates.add("vm/xml/mapper.xml.vm"); - templates.add("vm/sql/sql.vm"); - templates.add("vm/js/api.js.vm"); - if (GenConstants.TPL_CRUD.equals(tplCategory)) { - templates.add(useWebType + "/index.vue.vm"); - } else if (GenConstants.TPL_TREE.equals(tplCategory)) { - templates.add(useWebType + "/index-tree.vue.vm"); - } else if (GenConstants.TPL_SUB.equals(tplCategory)) { - templates.add(useWebType + "/index.vue.vm"); - templates.add("vm/java/sub-domain.java.vm"); - } - return templates; - } - - /** - * 获取文件名 - */ - public static String getFileName(String template, GenTable genTable) { - // 文件名称 - String fileName = ""; - // 包路径 - String packageName = genTable.getPackageName(); - // 模块名 - String moduleName = genTable.getModuleName(); - // 大写类名 - String className = genTable.getClassName(); - // 业务名称 - String businessName = genTable.getBusinessName(); - - String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); - String mybatisPath = MYBATIS_PATH + "/" + moduleName; - String vuePath = "vue"; - - if (template.contains("domain.java.vm")) { - fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); - } - if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) { - fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); - } else if (template.contains("mapper.java.vm")) { - fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); - } else if (template.contains("service.java.vm")) { - fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); - } else if (template.contains("serviceImpl.java.vm")) { - fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); - } else if (template.contains("controller.java.vm")) { - fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); - } else if (template.contains("mapper.xml.vm")) { - fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); - } else if (template.contains("sql.vm")) { - fileName = businessName + "Menu.sql"; - } else if (template.contains("api.js.vm")) { - fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); - } else if (template.contains("index.vue.vm")) { - fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); - } else if (template.contains("index-tree.vue.vm")) { - fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); - } - return fileName; - } - - /** - * 获取包前缀 - * - * @param packageName 包名称 - * @return 包前缀名称 - */ - public static String getPackagePrefix(String packageName) { - int lastIndex = packageName.lastIndexOf("."); - return StringUtils.substring(packageName, 0, lastIndex); - } - - /** - * 根据列类型获取导入包 - * - * @param genTable 业务表对象 - * @return 返回需要导入的包列表 - */ - public static HashSet getImportList(GenTable genTable) { - List columns = genTable.getColumns(); - GenTable subGenTable = genTable.getSubTable(); - HashSet importList = new HashSet(); - if (StringUtils.isNotNull(subGenTable)) { - importList.add("java.util.List"); - } - for (GenTableColumn column : columns) { - if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) { - importList.add("java.util.Date"); - importList.add("com.fasterxml.jackson.annotation.JsonFormat"); - } else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) { - importList.add("java.math.BigDecimal"); - } - } - return importList; - } - - /** - * 根据列类型获取字典组 - * - * @param genTable 业务表对象 - * @return 返回字典组 - */ - public static String getDicts(GenTable genTable) { - List columns = genTable.getColumns(); - Set dicts = new HashSet(); - addDicts(dicts, columns); - if (StringUtils.isNotNull(genTable.getSubTable())) { - List subColumns = genTable.getSubTable().getColumns(); - addDicts(dicts, subColumns); - } - return StringUtils.join(dicts, ", "); - } - - /** - * 添加字典列表 - * - * @param dicts 字典列表 - * @param columns 列集合 - */ - public static void addDicts(Set dicts, List columns) { - for (GenTableColumn column : columns) { - if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny( - column.getHtmlType(), - new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) { - dicts.add("'" + column.getDictType() + "'"); - } - } - } - - /** - * 获取权限前缀 - * - * @param moduleName 模块名称 - * @param businessName 业务名称 - * @return 返回权限前缀 - */ - public static String getPermissionPrefix(String moduleName, String businessName) { - return StringUtils.format("{}:{}", moduleName, businessName); - } - - /** - * 获取上级菜单ID字段 - * - * @param paramsObj 生成其他选项 - * @return 上级菜单ID字段 - */ - public static String getParentMenuId(JSONObject paramsObj) { - if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID) - && StringUtils.isNotEmpty(paramsObj.getString(GenConstants.PARENT_MENU_ID))) { - return paramsObj.getString(GenConstants.PARENT_MENU_ID); - } - return DEFAULT_PARENT_MENU_ID; - } - - /** - * 获取树编码 - * - * @param paramsObj 生成其他选项 - * @return 树编码 - */ - public static String getTreecode(JSONObject paramsObj) { - if (paramsObj.containsKey(GenConstants.TREE_CODE)) { - return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE)); - } - return StringUtils.EMPTY; - } - - /** - * 获取树父编码 - * - * @param paramsObj 生成其他选项 - * @return 树父编码 - */ - public static String getTreeParentCode(JSONObject paramsObj) { - if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { - return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); - } - return StringUtils.EMPTY; - } - - /** - * 获取树名称 - * - * @param paramsObj 生成其他选项 - * @return 树名称 - */ - public static String getTreeName(JSONObject paramsObj) { - if (paramsObj.containsKey(GenConstants.TREE_NAME)) { - return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); - } - return StringUtils.EMPTY; - } - - /** - * 获取需要在哪一列上面显示展开按钮 - * - * @param genTable 业务表对象 - * @return 展开按钮列序号 - */ - public static int getExpandColumn(GenTable genTable) { - String options = genTable.getOptions(); - JSONObject paramsObj = JSON.parseObject(options); - String treeName = paramsObj.getString(GenConstants.TREE_NAME); - int num = 0; - for (GenTableColumn column : genTable.getColumns()) { - if (column.isList()) { - num++; - String columnName = column.getColumnName(); - if (columnName.equals(treeName)) { - break; - } - } - } - return num; - } -} diff --git a/ruoyi-generator/src/main/resources/generator.yml b/ruoyi-generator/src/main/resources/generator.yml deleted file mode 100644 index 7eae68e..0000000 --- a/ruoyi-generator/src/main/resources/generator.yml +++ /dev/null @@ -1,10 +0,0 @@ -# 代码生成 -gen: - # 作者 - author: ruoyi - # 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool - packageName: com.ruoyi.system - # 自动去除表前缀,默认是false - autoRemovePre: false - # 表前缀(生成类名不会包含表前缀,多个用逗号分隔) - tablePrefix: sys_ \ No newline at end of file diff --git a/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml b/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml deleted file mode 100644 index 0daba12..0000000 --- a/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, - is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, - create_by, create_time, update_by, update_time from gen_table_column - - - - - - - - insert into gen_table_column ( - table_id, - column_name, - column_comment, - column_type, - java_type, - java_field, - is_pk, - is_increment, - is_required, - is_insert, - is_edit, - is_list, - is_query, - query_type, - html_type, - dict_type, - sort, - create_by, - create_time - )values( - #{tableId}, - #{columnName}, - #{columnComment}, - #{columnType}, - #{javaType}, - #{javaField}, - #{isPk}, - #{isIncrement}, - #{isRequired}, - #{isInsert}, - #{isEdit}, - #{isList}, - #{isQuery}, - #{queryType}, - #{htmlType}, - #{dictType}, - #{sort}, - #{createBy}, - sysdate() - ) - - - - update gen_table_column - - column_comment = #{columnComment}, - java_type = #{javaType}, - java_field = #{javaField}, - is_insert = #{isInsert}, - is_edit = #{isEdit}, - is_list = #{isList}, - is_query = #{isQuery}, - is_required = #{isRequired}, - query_type = #{queryType}, - html_type = #{htmlType}, - dict_type = #{dictType}, - sort = #{sort}, - update_by = #{updateBy}, - update_time = sysdate() - - where column_id = #{columnId} - - - - delete from gen_table_column where table_id in - - #{tableId} - - - - - delete from gen_table_column where column_id in - - #{item.columnId} - - - - \ No newline at end of file diff --git a/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml b/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml deleted file mode 100644 index 6d515a8..0000000 --- a/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml +++ /dev/null @@ -1,221 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, - tpl_web_type, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, - options, create_by, create_time, update_by, update_time, remark from gen_table - - - - - - - - - - - - - - - - - - insert into gen_table ( - table_name, - table_comment, - class_name, - tpl_category, - tpl_web_type, - package_name, - module_name, - business_name, - function_name, - function_author, - gen_type, - gen_path, - remark, - create_by, - create_time - )values( - #{tableName}, - #{tableComment}, - #{className}, - #{tplCategory}, - #{tplWebType}, - #{packageName}, - #{moduleName}, - #{businessName}, - #{functionName}, - #{functionAuthor}, - #{genType}, - #{genPath}, - #{remark}, - #{createBy}, - sysdate() - ) - - - - ${sql} - - - - update gen_table - - table_name = #{tableName}, - table_comment = #{tableComment}, - sub_table_name = #{subTableName}, - sub_table_fk_name = #{subTableFkName}, - class_name = #{className}, - function_author = #{functionAuthor}, - gen_type = #{genType}, - gen_path = #{genPath}, - tpl_category = #{tplCategory}, - tpl_web_type = #{tplWebType}, - package_name = #{packageName}, - module_name = #{moduleName}, - business_name = #{businessName}, - function_name = #{functionName}, - options = #{options}, - update_by = #{updateBy}, - remark = #{remark}, - update_time = sysdate() - - where table_id = #{tableId} - - - - delete from gen_table where table_id in - - #{tableId} - - - - \ No newline at end of file diff --git a/ruoyi-generator/src/main/resources/vm/java/controller.java.vm b/ruoyi-generator/src/main/resources/vm/java/controller.java.vm deleted file mode 100644 index feacc74..0000000 --- a/ruoyi-generator/src/main/resources/vm/java/controller.java.vm +++ /dev/null @@ -1,108 +0,0 @@ -package ${packageName}.controller; - -import java.util.List; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import com.ruoyi.common.annotation.Log; -import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.enums.BusinessType; -import ${packageName}.domain.${ClassName}; -import ${packageName}.service.I${ClassName}Service; -import com.ruoyi.common.utils.poi.ExcelUtil; -#if($table.crud || $table.sub) -import com.ruoyi.common.core.page.TableDataInfo; -#elseif($table.tree) -#end - -/** - * ${functionName}Controller - * - * @author ${author} - * @date ${datetime} - */ -@RestController -@RequestMapping("/${moduleName}/${businessName}") -public class ${ClassName}Controller extends BaseController { - @Autowired - private I${ClassName}Service ${className}Service; - -/** - * 查询${functionName}列表 - */ -@PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')") -@GetMapping("/list") - #if($table.crud || $table.sub) - public TableDataInfo list(${ClassName} ${className}) { - startPage(); - List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); - return getDataTable(list); - } - #elseif($table.tree) - public AjaxResult list(${ClassName} ${className}) { - List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); - return success(list); - } - #end - - /** - * 导出${functionName}列表 - */ - @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')") - @Log(title = "${functionName}", businessType = BusinessType.EXPORT) - @PostMapping("/export") - public void export(HttpServletResponse response, ${ClassName} ${className}) { - List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); - ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}. class); - util.exportExcel(response, list, "${functionName}数据"); - } - - /** - * 获取${functionName}详细信息 - */ - @PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')") - @GetMapping(value = "/{${pkColumn.javaField}}") - public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) { - return success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField})); - } - - /** - * 新增${functionName} - */ - @PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')") - @Log(title = "${functionName}", businessType = BusinessType.INSERT) - @PostMapping - public AjaxResult add(@RequestBody ${ClassName} ${className}) { - return toAjax(${className}Service.insert${ClassName}(${className})); - } - - /** - * 修改${functionName} - */ - @PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')") - @Log(title = "${functionName}", businessType = BusinessType.UPDATE) - @PostMapping("/edit") - public AjaxResult edit(@RequestBody ${ClassName} ${className}) { - return toAjax(${className}Service.update${ClassName}(${className})); - } - - /** - * 删除${functionName} - */ - @PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')") - @Log(title = "${functionName}", businessType = BusinessType.DELETE) - @PostMapping("/{${pkColumn.javaField}s}") - public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) { - return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s)); - } -} diff --git a/ruoyi-generator/src/main/resources/vm/java/domain.java.vm b/ruoyi-generator/src/main/resources/vm/java/domain.java.vm deleted file mode 100644 index 34c18cf..0000000 --- a/ruoyi-generator/src/main/resources/vm/java/domain.java.vm +++ /dev/null @@ -1,101 +0,0 @@ -package ${packageName}.domain; - -#foreach ($import in $importList) -import ${import}; -#end -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import com.ruoyi.common.annotation.Excel; -#if($table.crud || $table.sub) -import com.ruoyi.common.core.domain.BaseEntity; -#elseif($table.tree) -import com.ruoyi.common.core.domain.TreeEntity; -#end - -/** - * ${functionName}对象 ${tableName} - * - * @author ${author} - * @date ${datetime} - */ -#if($table.crud || $table.sub) - #set($Entity="BaseEntity") -#elseif($table.tree) - #set($Entity="TreeEntity") -#end -public class ${ClassName} extends ${Entity} - { -private static final long serialVersionUID = 1L; - - #foreach ($column in $columns) - #if(!$table.isSuperColumn($column.javaField)) - /** $column.columnComment */ - #if($column.list) - #set($parentheseIndex=$column.columnComment.indexOf("(")) - #if($parentheseIndex != -1) - #set($comment=$column.columnComment.substring(0, $parentheseIndex)) - #else - #set($comment=$column.columnComment) - #end - #if($parentheseIndex != -1) - @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") - #elseif($column.javaType == 'Date') - @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") - #else - @Excel(name = "${comment}") - #end - #end - private $column.javaType $column.javaField; - - #end - #end - #if($table.sub) - /** $table.subTable.functionName信息 */ - private List<${subClassName}> ${subclassName}List; - - #end - #foreach ($column in $columns) - #if(!$table.isSuperColumn($column.javaField)) - #if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) - #set($AttrName=$column.javaField) - #else - #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) - #end - public void set${AttrName}($column.javaType $column.javaField) { - this.$column.javaField = $column.javaField; - } - - public $column.javaType get${AttrName}() { - return $column.javaField; - } - #end - #end - - #if($table.sub) - public List<${subClassName}> get${subClassName}List() { - return ${subclassName}List; - } - - public void set${subClassName}List(List<${subClassName}> ${subclassName}List) { - this.${subclassName}List = ${subclassName}List; - } - - #end -@Override -public String toString() { - return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) - #foreach ($column in $columns) - #if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) - #set($AttrName=$column.javaField) - #else - #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) - #end - .append("${column.javaField}", get${AttrName}()) - #end - #if($table.sub) - .append("${subclassName}List", get${subClassName}List()) - #end - .toString(); -} -} diff --git a/ruoyi-generator/src/main/resources/vm/java/mapper.java.vm b/ruoyi-generator/src/main/resources/vm/java/mapper.java.vm deleted file mode 100644 index aeb46cd..0000000 --- a/ruoyi-generator/src/main/resources/vm/java/mapper.java.vm +++ /dev/null @@ -1,91 +0,0 @@ -package ${packageName}.mapper; - -import java.util.List; - -import ${packageName}.domain.${ClassName}; -#if($table.sub) -import ${packageName}.domain .${subClassName}; -#end - -/** - * ${functionName}Mapper接口 - * - * @author ${author} - * @date ${datetime} - */ -public interface ${ClassName}Mapper { - /** - * 查询${functionName} - * - * @param ${pkColumn.javaField} ${functionName}主键 - * @return ${functionName} - */ - public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}); - - /** - * 查询${functionName}列表 - * - * @param ${className} ${functionName} - * @return ${functionName}集合 - */ - public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); - - /** - * 新增${functionName} - * - * @param ${className} ${functionName} - * @return 结果 - */ - public int insert${ClassName}(${ClassName} ${className}); - - /** - * 修改${functionName} - * - * @param ${className} ${functionName} - * @return 结果 - */ - public int update${ClassName}(${ClassName} ${className}); - - /** - * 删除${functionName} - * - * @param ${pkColumn.javaField} ${functionName}主键 - * @return 结果 - */ - public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}); - - /** - * 批量删除${functionName} - * - * @param ${pkColumn.javaField}s 需要删除的数据主键集合 - * @return 结果 - */ - public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s); - #if($table.sub) - - /** - * 批量删除${subTable.functionName} - * - * @param ${pkColumn.javaField}s 需要删除的数据主键集合 - * @return 结果 - */ - public int delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaType}[] ${pkColumn.javaField}s); - - /** - * 批量新增${subTable.functionName} - * - * @param ${subclassName}List ${subTable.functionName}列表 - * @return 结果 - */ - public int batch${subClassName}(List<${subClassName}> ${subclassName}List); - - - /** - * 通过${functionName}主键删除${subTable.functionName}信息 - * - * @param ${pkColumn.javaField} ${functionName}ID - * @return 结果 - */ - public int delete${subClassName}By${subTableFkClassName}(${pkColumn.javaType} ${pkColumn.javaField}); - #end -} diff --git a/ruoyi-generator/src/main/resources/vm/java/service.java.vm b/ruoyi-generator/src/main/resources/vm/java/service.java.vm deleted file mode 100644 index 4649dd5..0000000 --- a/ruoyi-generator/src/main/resources/vm/java/service.java.vm +++ /dev/null @@ -1,61 +0,0 @@ -package ${packageName}.service; - -import java.util.List; - -import ${packageName}.domain .${ClassName}; - -/** - * ${functionName}Service接口 - * - * @author ${author} - * @date ${datetime} - */ -public interface I${ClassName}Service { - /** - * 查询${functionName} - * - * @param ${pkColumn.javaField} ${functionName}主键 - * @return ${functionName} - */ - public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}); - - /** - * 查询${functionName}列表 - * - * @param ${className} ${functionName} - * @return ${functionName}集合 - */ - public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); - - /** - * 新增${functionName} - * - * @param ${className} ${functionName} - * @return 结果 - */ - public int insert${ClassName}(${ClassName} ${className}); - - /** - * 修改${functionName} - * - * @param ${className} ${functionName} - * @return 结果 - */ - public int update${ClassName}(${ClassName} ${className}); - - /** - * 批量删除${functionName} - * - * @param ${pkColumn.javaField}s 需要删除的${functionName}主键集合 - * @return 结果 - */ - public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s); - - /** - * 删除${functionName}信息 - * - * @param ${pkColumn.javaField} ${functionName}主键 - * @return 结果 - */ - public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}); -} diff --git a/ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm b/ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm deleted file mode 100644 index 6b25cbe..0000000 --- a/ruoyi-generator/src/main/resources/vm/java/serviceImpl.java.vm +++ /dev/null @@ -1,161 +0,0 @@ -package ${packageName}.service.impl; - -import java.util.List; - #foreach ($column in $columns) - #if($column.javaField == 'createTime' || $column.javaField == 'updateTime') - import com.ruoyi.common.utils.DateUtils; - #break - #end - #end -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - #if($table.sub) - import java.util.ArrayList; - - import com.ruoyi.common.utils.StringUtils; - import org.springframework.transaction.annotation.Transactional; - import ${packageName}.domain.${subClassName}; - #end -import ${packageName}.mapper.${ClassName}Mapper; -import ${packageName}.domain.${ClassName}; -import ${packageName}.service.I${ClassName}Service; - -/** - * ${functionName}Service业务层处理 - * - * @author ${author} - * @date ${datetime} - */ -@Service -public class ${ClassName}ServiceImpl implements I${ClassName}Service { - @Autowired - private ${ClassName}Mapper ${className}Mapper; - - /** - * 查询${functionName} - * - * @param ${pkColumn.javaField} ${functionName}主键 - * @return ${functionName} - */ - @Override - public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}) { - return ${className}Mapper.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}); - } - - /** - * 查询${functionName}列表 - * - * @param ${className} ${functionName} - * @return ${functionName} - */ - @Override - public List<${ClassName}> select${ClassName}List(${ClassName} ${className}) { - return ${className}Mapper.select${ClassName}List(${className}); - } - - /** - * 新增${functionName} - * - * @param ${className} ${functionName} - * @return 结果 - */ - #if($table.sub) - @Transactional - #end - @Override - public int insert${ClassName}(${ClassName} ${className}) { - #foreach ($column in $columns) - #if($column.javaField == 'createTime') - ${className}.setCreateTime(DateUtils.getNowDate()); - #end - #end - #if($table.sub) - int rows = ${className}Mapper.insert${ClassName}(${className}); - insert${subClassName}(${className}); - return rows; - #else - return ${className}Mapper.insert${ClassName}(${className}); - #end - } - - /** - * 修改${functionName} - * - * @param ${className} ${functionName} - * @return 结果 - */ - #if($table.sub) - @Transactional - #end - @Override - public int update${ClassName}(${ClassName} ${className}) { - #foreach ($column in $columns) - #if($column.javaField == 'updateTime') - ${className}.setUpdateTime(DateUtils.getNowDate()); - #end - #end - #if($table.sub) - ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}()) - ; - insert${subClassName}(${className}); - #end - return ${className}Mapper.update${ClassName}(${className}); - } - - /** - * 批量删除${functionName} - * - * @param ${pkColumn.javaField}s 需要删除的${functionName}主键 - * @return 结果 - */ - #if($table.sub) - @Transactional - #end - @Override - public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s) { - #if($table.sub) - ${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s); - #end - return ${className}Mapper.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s); - } - - /** - * 删除${functionName}信息 - * - * @param ${pkColumn.javaField} ${functionName}主键 - * @return 结果 - */ - #if($table.sub) - @Transactional - #end - @Override - public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}) { - #if($table.sub) - ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField}); - #end - return ${className}Mapper.delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}); - } - #if($table.sub) - - /** - * 新增${subTable.functionName}信息 - * - * @param ${className} ${functionName}对象 - */ - public void insert${subClassName}(${ClassName} ${className}) { - List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List(); - ${pkColumn.javaType} ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}(); - if (StringUtils.isNotNull(${subclassName}List)) { - List<${subClassName}> list = new ArrayList<${subClassName}>(); - for (${subClassName} ${subclassName} :${subclassName}List) - { - ${subclassName}.set${subTableFkClassName}(${pkColumn.javaField}); - list.add(${subclassName}); - } - if (list.size() > 0) { - ${className}Mapper.batch${subClassName}(list); - } - } - } - #end -} diff --git a/ruoyi-generator/src/main/resources/vm/java/sub-domain.java.vm b/ruoyi-generator/src/main/resources/vm/java/sub-domain.java.vm deleted file mode 100644 index ed5c774..0000000 --- a/ruoyi-generator/src/main/resources/vm/java/sub-domain.java.vm +++ /dev/null @@ -1,77 +0,0 @@ -package ${packageName}.domain; - - #foreach ($import in $subImportList) - import ${import}; - #end -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import com.ruoyi.common.annotation.Excel; -import com.ruoyi.common.core.domain.BaseEntity; - -/** - * ${subTable.functionName}对象 ${subTableName} - * - * @author ${author} - * @date ${datetime} - */ -public class ${subClassName} extends - -BaseEntity { - private static final long serialVersionUID = 1L; - - #foreach ($column in $subTable.columns) - #if(!$table.isSuperColumn($column.javaField)) - /** $column.columnComment */ - #if($column.list) - #set($parentheseIndex=$column.columnComment.indexOf("(")) - #if($parentheseIndex != -1) - #set($comment=$column.columnComment.substring(0, $parentheseIndex)) - #else - #set($comment=$column.columnComment) - #end - #if($parentheseIndex != -1) - @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") - #elseif($column.javaType == 'Date') - @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") - #else - @Excel(name = "${comment}") - #end - #end - private $column.javaType $column.javaField; - - #end - #end - #foreach ($column in $subTable.columns) - #if(!$table.isSuperColumn($column.javaField)) - #if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) - #set($AttrName=$column.javaField) - #else - #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) - #end - public void set${AttrName}($column.javaType $column.javaField) - { - this.$column.javaField = $column.javaField; - } - - public $column.javaType get${AttrName}() - { - return $column.javaField; - } - #end - #end - - @Override - public String toString () { - return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) - #foreach ($column in $subTable.columns) - #if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) - #set($AttrName=$column.javaField) - #else - #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) - #end - .append("${column.javaField}", get${AttrName}()) - #end - .toString(); - } -} diff --git a/ruoyi-generator/src/main/resources/vm/js/api.js.vm b/ruoyi-generator/src/main/resources/vm/js/api.js.vm deleted file mode 100644 index 346c95e..0000000 --- a/ruoyi-generator/src/main/resources/vm/js/api.js.vm +++ /dev/null @@ -1,44 +0,0 @@ -import request from '@/utils/request' - -// 查询${functionName}列表 -export function list${BusinessName}(query) { - return request({ - url: '/${moduleName}/${businessName}/list', - method: 'get', - params: query - }) -} - -// 查询${functionName}详细 -export function get${BusinessName}(${pkColumn.javaField}) { - return request({ - url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField}, - method: 'get' - }) -} - -// 新增${functionName} -export function add${BusinessName}(data) { - return request({ - url: '/${moduleName}/${businessName}', - method: 'post', - data: data - }) -} - -// 修改${functionName} -export function update${BusinessName}(data) { - return request({ - url: '/${moduleName}/${businessName}', - method: 'put', - data: data - }) -} - -// 删除${functionName} -export function del${BusinessName}(${pkColumn.javaField}) { - return request({ - url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField}, - method: 'delete' - }) -} diff --git a/ruoyi-generator/src/main/resources/vm/sql/sql.vm b/ruoyi-generator/src/main/resources/vm/sql/sql.vm deleted file mode 100644 index 0575583..0000000 --- a/ruoyi-generator/src/main/resources/vm/sql/sql.vm +++ /dev/null @@ -1,22 +0,0 @@ --- 菜单 SQL -insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) -values('${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', sysdate(), '', null, '${functionName}菜单'); - --- 按钮父菜单ID -SELECT @parentId := LAST_INSERT_ID(); - --- 按钮 SQL -insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) -values('${functionName}查询', @parentId, '1', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query', '#', 'admin', sysdate(), '', null, ''); - -insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) -values('${functionName}新增', @parentId, '2', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add', '#', 'admin', sysdate(), '', null, ''); - -insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) -values('${functionName}修改', @parentId, '3', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit', '#', 'admin', sysdate(), '', null, ''); - -insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) -values('${functionName}删除', @parentId, '4', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove', '#', 'admin', sysdate(), '', null, ''); - -insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark) -values('${functionName}导出', @parentId, '5', '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export', '#', 'admin', sysdate(), '', null, ''); \ No newline at end of file diff --git a/ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm b/ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm deleted file mode 100644 index 6baa7f8..0000000 --- a/ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm +++ /dev/null @@ -1,571 +0,0 @@ - - - diff --git a/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm b/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm deleted file mode 100644 index 8f40940..0000000 --- a/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm +++ /dev/null @@ -1,744 +0,0 @@ - - - diff --git a/ruoyi-generator/src/main/resources/vm/vue/v3/index-tree.vue.vm b/ruoyi-generator/src/main/resources/vm/vue/v3/index-tree.vue.vm deleted file mode 100644 index b25bb9b..0000000 --- a/ruoyi-generator/src/main/resources/vm/vue/v3/index-tree.vue.vm +++ /dev/null @@ -1,542 +0,0 @@ - - - diff --git a/ruoyi-generator/src/main/resources/vm/vue/v3/index.vue.vm b/ruoyi-generator/src/main/resources/vm/vue/v3/index.vue.vm deleted file mode 100644 index 79faf8e..0000000 --- a/ruoyi-generator/src/main/resources/vm/vue/v3/index.vue.vm +++ /dev/null @@ -1,729 +0,0 @@ - - - diff --git a/ruoyi-generator/src/main/resources/vm/xml/mapper.xml.vm b/ruoyi-generator/src/main/resources/vm/xml/mapper.xml.vm deleted file mode 100644 index e1ccd6b..0000000 --- a/ruoyi-generator/src/main/resources/vm/xml/mapper.xml.vm +++ /dev/null @@ -1,166 +0,0 @@ - - - - - - #foreach ($column in $columns) - - #end - - #if($table.sub) - - - - - - - #foreach ($column in $subTable.columns) - - #end - - #end - - - select#foreach($column in $columns) $column.columnName#if($foreach.count != $columns.size()),#end#end - from ${tableName} - - - - - - - - insert into ${tableName} - - #foreach($column in $columns) - #if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) - $column.columnName, - - #end - #end - - - #foreach($column in $columns) - #if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) - #{$column.javaField}, - - #end - #end - - - - - update ${tableName} - - #foreach($column in $columns) - #if($column.columnName != $pkColumn.columnName) - $column.columnName = - #{$column.javaField}, - - #end - #end - - where ${pkColumn.columnName} = #{${pkColumn.javaField}} - - - - delete from ${tableName} where ${pkColumn.columnName} = #{${pkColumn.javaField}} - - - - delete from ${tableName} where ${pkColumn.columnName} in - - #{${pkColumn.javaField}} - - - #if($table.sub) - - - delete from ${subTableName} where ${subTableFkName} in - - #{${subTableFkclassName}} - - - - - delete from ${subTableName} where ${subTableFkName} = #{${subTableFkclassName}} - - - - insert into ${subTableName} - (#foreach($column in $subTable.columns) $column.columnName#if($foreach.count != $subTable.columns.size()) - ,#end#end) values - - (#foreach($column in $subTable.columns) #{item.$column.javaField - }#if($foreach.count != $subTable.columns.size()),#end#end) - - - #end - \ No newline at end of file From a38d58d91d30a785226646585cc9294b32bf114d Mon Sep 17 00:00:00 2001 From: du <1725534722@qq.com> Date: Sat, 12 Oct 2024 09:17:33 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=9B=B4=E6=94=B9RSA=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/common/utils/RsaUtils.java | 75 ++++++------------- .../web/service/SysLoginService.java | 2 +- 2 files changed, 24 insertions(+), 53 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/RsaUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/RsaUtils.java index f4f66e3..2541b2a 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/RsaUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/RsaUtils.java @@ -1,12 +1,9 @@ package com.ruoyi.common.utils; -import org.apache.commons.codec.binary.Base64; import javax.crypto.Cipher; -import java.security.*; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; +import java.security.KeyFactory; +import java.security.PrivateKey; import java.security.spec.PKCS8EncodedKeySpec; -import java.security.spec.X509EncodedKeySpec; /** * RSA加密解密 @@ -16,59 +13,33 @@ import java.security.spec.X509EncodedKeySpec; public class RsaUtils { // Rsa 私钥 - public static String privateKey = " -----BEGIN RSA PRIVATE KEY-----\n" + - "MIIEpQIBAAKCAQEAnEeZMSY6UdmJRJzqbPb5h6iXW1PziRWHlwq7vfZ7Bslb3kKR\n" + - "Va3TeGqiZsCCf7y5CuGS61multLKi/ABbS11LRTpUv+UAYm+edmM4TK/KdPbSExz\n" + - "D8z8CZd6x0wek+uKSkDOZWlwlrH0cXSfTyY3uget7jEbU/0WJCbucKXrFiB34fl4\n" + - "7RTgCBfcWHbCnIuEqV8h4mewvZDsluD55x4cv6vdlLS4NQ9CHkFWJjeViirjZscj\n" + - "b4X8m31PTmRMQAzsKjmS0cm87Gtjv+VfQHBLaV962FVEZBF+D/809bunUxfAi0kX\n" + - "D3K6OSYw0fvJo1sESOVntxjhKDng1ZXwoaIBcQIDAQABAoIBAQCJRQaVOkvNqzM8\n" + - "Vkw/a+wgMYDJEoN+rK+NhzsDD6Zefq24G2aHCIkQYzHE6WF3C/DJUvv2x65oAj0x\n" + - "D55hJKWg9JZBdgauFyx84Q8ym514AwPAjI4gmd/kGO8acY0GRsUQlb31K9leNG9O\n" + - "3K42Go6mU6p95xpm+o3hMWUNA1/r7TdlIq7BB7pV4z+GYaVnAhPJP6JUddt8L8eO\n" + - "Y0LCtLvE24FcXbkrHTMdBca+dfNeYT03Vvd1JYRxHr+VHFVh8Ov6adAQ/vejJ8Iu\n" + - "+xcbgKjeQSAVBCjTu15q8mmW4ZVip0DRKjJ35EbWu8HMTqSTWEe+iZqHzvf/I2cz\n" + - "3vBLCqoBAoGBAM9ErbanIyL3yfPwMfrQhxAqDLuJQaNraZvvG4VJKlJDtux2dT3Z\n" + - "rIh+Qe0QEivuePbEb9fKPTVtdK/vJSOcmlgsJvFPqsfEvTF2CS01Me2YOjvQtheY\n" + - "FZd9KR51kOA+9oQhnJIzUmIOJ9ERY/BS4xmWfj+Rb83WYzTQY9z1d2HRAoGBAMEF\n" + - "9Gm37U2X3TX7A83dSJYVz7stWQ1aEqDJqfC8rOondti0Mkx2kKHJjEHSVBl0rpPT\n" + - "lVxbhiaHO9QMlD5qOGfDnIxRiAA5MQn0PO3u6E27ZiMxx5di8ipLF1oRvT5FHwcy\n" + - "RXL39lDMib2lBxzRT9InZZ4owgU3oTc6ZW1kz+2hAoGBALSvvnA4jBzzvo51mlx4\n" + - "ZQXmYmsqYJpCDTLu4yLygX5toY3KRrLAi/QBfR9Ynz7FCZa18HpBx9JHtS2aYNoG\n" + - "r1amRtyfAtZb4EK6D43ljbz+s+VpMRSodEo3xhzTiJS0ztqpIoEhVHQ+ut87NdBP\n" + - "scKguzZXZwweFSX5dNUu9//BAoGBAIsTM0uIzl598VEXj2Ig8k/RX19KCUPphkp7\n" + - "gwqFp0D/Nk5lZ2hYdVVc1sYGObotrCuu44ssFrhj7+OVPKrL9eAtvPoNNKSUkJTP\n" + - "eacl4BNB1xG8qEaXcEyw1h57cZMQUo7o1clEiCEnfoc6BKnq1kxhPoJ6c3E2593X\n" + - "IYV0gayBAoGARE9gbxgCP8YW1AvOB1nEkyWNR40qEKhAniQP+pg3h7o5K/7aUcew\n" + - "UnJsYdOm3JPA8zkGbXWupIaqzVwKYVNEVqt0lJ+L5jbIrPXtarHoBEnH1MB0spZ5\n" + - "ZwtgQpYOR2MbVRDKzKf+YbhcKMjt6U5JqiAf/JYSPCkR0BCK8cQ8+TI=\n" + - "-----END RSA PRIVATE KEY-----"; + private static final String PRIVATE_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXxtLWRhOIyEhLkxlTbndtzS6RrGsDWV8LOIAEXFCsLZzT20ytAaO4fpXXHah80EwaE4P25Y3+qQBDL8fA5780pSoLDo3Si/qC5KuowNb8F1ncGXSuYzX/3mNMLXF98UW96PvFY198hto8j5snhYtf01WI2L0eZPQFE3Mnh3ZHzos88Jr5vEto+OyHZHa0GRsuRSi33vr1olo8+LA8JkcyS5B6eMdKalYvSiSV6owfwQZfuPoDkD/ghRc8w0owzOSJJGmwgnrkYmYMBudHdldF8LwzNUEEkHrOvk3QXg33Fl8X4lL9jHvbq0K76sDoYMLJPG1D/Ccqk93AU/mdRYJZAgMBAAECggEAG+w3M7aWt25pZoX8fc3v6OJ7s88trOMPSkgtvR+is9p8ZLmOxLFthm67cGUDb1r+9Tkr6QtYcUZ0RugObt3z3mKYdopJ6zdXcidRsW0w4BYHsSd5wO99qsImMIiXvZzawNKRJ0Jd+dHxanzdBYtbFdkSfmepe2MFRb3LTLVuPE1oCTKbzwqPSGWERpkejZJz+Cthc/xp7PWNFtfmEASEuAmYV0tdWC0H6NJqTtg2Stotp4hlk/jTKLoYQW/m3pmnkw1QbVRh1B9mtxTVtGV6HzhiQbuc5HWaUvBm4ysiXjFEtCTpBeDjwvnD1wkDXR1SyVdYiAfDYM2zCCs5OvWPFQKBgQD3MONf6Jn7x6Xo2uwsKwca4HFkfIHpK5TdiFB9p2eCZ4V8JZNPv02fPRldFb56nYVmdNVoo8/z4WG9t6uNoTLDMqTI0wVkrJCufQCI/50XnKITEmLfXOKXkwhekRLi1oho0nEsbaQllFFrlfx4NkcgoW6XL1TW8eRx8JD7EORI9wKBgQCdL3mZ5gumLLhB/RTK5G786jJtztNxQ4jpFtClv25uPJgqsRgSVoLnnTCmLm/yGsHNna/CHbA4mYOYzXiM10WUK1tEqPwYm0nalQAxtXJjNgERKjWWaopZW/f4pCBPV8RG4dk/+13zjPCYTeS4i7J89psHljqoeQoLe4xazLKLLwKBgHgV+f/34gadIQ6UfDOg25zE+JFWo04BbBqLRH8munRxkjmTj5MoXq9DYXUFQToUGGCD1cE2A6p5DaC6/86YRy7pBYDCc1ZLNyZtd7sWYty7rUkSn5Hfb/0u4tv+ImysyCwUQALTaPEQstVPUg2cYMWLZ0xvJAogDVkFA4nU1PJVAoGAEBQ7LDMMHgOVFar95YNYlyad4f22Q2/VIYLj9RCQC1bHehaDj9ypp2e9AkLd0LZL/OyUfhbrX97UR109Z6rdwzpsK6ndn+bCt0lmq68T9HIhyc+3i5t6a4ms5BJl+7fOrDGON61O/wr70ZimPPqNV5siYLRNa8516JbK1L77xKECgYEAyaTui+7B27219nwgoin9AuM0H7B+rzz0GkXmYXzWhxgKB+eBuJbZsrUTOBVkk66j3Ss4cJvQJ9utcFBnS6msEAUCYU6OuInIb/PMv8I7DC7SrrTZpyD9LXKIB4aYtqPrntZSo+75EAHgXNpRYqUwkpZbCuYSIXebno4JOxB1RK8=" + + "CfhCau4K5xqFfYnCDxwN6EfWtl118/RC/H1G6YUH9VZ02hTsIKtcdoz/w3knVDuL/i1uCtKtJDdyejF8osix2IVVA2HNoUPEG+3VH0IJjOoFTZTP76LcuQvgig6pjAtB5+GFPVkkrdxWZc3rn+psCdzYBueVhDRDFatKxfvAQMk90SMNVOLApB8u4aWUdxGju3vOKO5ShBUVutyczTzAOW39hHdzXX5CvGPXNYNv7S55AVAI5ZVdn11dyxgPr6u7n7AuHtc2pvUddHTRM/UczNN5lkpdMvISQy4iHwCw9wGVax3kvRxMzhYiBricSKJWbl4LiAMRV3P15LWkaBwSkw=="; + /** - * 私钥解密 - * - * @param text 待解密的文本 - * @return 解密后的文本 + * 利用私钥进行解密 */ - public static String decryptByPrivateKey(String text) throws Exception - { - return decryptByPrivateKey(privateKey, text); + public static String decryptByPrivateKey(String decodeString) throws Exception { + // 将传入的Base64编码字符串解码为字节数组 + byte[] encryptedBytes = java.util.Base64.getDecoder().decode(decodeString); + // 使用私钥解密 + PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(org.apache.commons.codec.binary.Base64.decodeBase64(PRIVATE_KEY)); + KeyFactory keyFactory = KeyFactory.getInstance("RSA"); + PrivateKey privateKey = keyFactory.generatePrivate(pkcs8EncodedKeySpec); + byte[] decryptedBytes = decrypt(encryptedBytes, privateKey); + // 返回解密后的字符串 + return new String(decryptedBytes); } /** - * 私钥解密 - * - * @param privateKeyString 私钥 - * @param text 待解密的文本 - * @return 解密后的文本 + * 解密操作 */ - public static String decryptByPrivateKey(String privateKeyString, String text) throws Exception - { - PKCS8EncodedKeySpec pkcs8EncodedKeySpec5 = new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKeyString)); - KeyFactory keyFactory = KeyFactory.getInstance("RSA"); - PrivateKey privateKey = keyFactory.generatePrivate(pkcs8EncodedKeySpec5); - Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithMD5AndMGF1Padding"); + private static byte[] decrypt(byte[] data, PrivateKey privateKey) throws Exception { + // 获取RSA算法的Cipher实例 + Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding"); + // 用私钥初始化Cipher实例,设置为解密模式 cipher.init(Cipher.DECRYPT_MODE, privateKey); - byte[] result = cipher.doFinal(Base64.decodeBase64(text)); - return new String(result); + // 执行解密操作,返回解密后的字节数组 + return cipher.doFinal(data); } } \ No newline at end of file diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index ade3954..d4fea5a 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -87,7 +87,7 @@ public class SysLoginService { // validateCaptcha(username, code, uuid); // 登录前置校验 loginPreCheck(username, strP); - Map map = redisCache.getCacheObject(username + password); + Map map = redisCache.getCacheObject(username + strP); if (CollectionUtil.isNotEmpty(map)) { map.remove("@type"); return map; From 15546d7b4c59cd1142ff5be6f87d6db7cd2fdddf Mon Sep 17 00:00:00 2001 From: du <1725534722@qq.com> Date: Sat, 12 Oct 2024 09:19:24 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 12 ++++++------ ruoyi-admin/pom.xml | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 51c9a09..78dbee7 100644 --- a/pom.xml +++ b/pom.xml @@ -161,11 +161,11 @@ - - com.ruoyi - ruoyi-generator - ${ruoyi.version} - + + + + + @@ -203,7 +203,7 @@ ruoyi-framework ruoyi-system ruoyi-quartz - ruoyi-generator + ruoyi-common ruoyi-flowable diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index ab5d499..cfdeab1 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -57,10 +57,10 @@ - - com.ruoyi - ruoyi-generator - + + + + org.projectlombok lombok From cc55f3ecef2cd2b52379b325ebe692e451f30724 Mon Sep 17 00:00:00 2001 From: du <1725534722@qq.com> Date: Sat, 12 Oct 2024 10:31:48 +0800 Subject: [PATCH 6/6] bugfix --- .../src/main/resources/mapper/jjh/ent/JProjectMapper.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-admin/src/main/resources/mapper/jjh/ent/JProjectMapper.xml b/ruoyi-admin/src/main/resources/mapper/jjh/ent/JProjectMapper.xml index 8948a03..24efc4d 100644 --- a/ruoyi-admin/src/main/resources/mapper/jjh/ent/JProjectMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/jjh/ent/JProjectMapper.xml @@ -29,7 +29,7 @@ and project_year = #{req.projectYear} - order by create_time desc ,project_year desc + order by project_year desc