From 4a24728338b869117a58c21dbd5544d1f1e782fd Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 10 九月 2024 17:41:53 +0800 Subject: [PATCH] 1 --- se-modules/se-system/src/main/java/com/se/system/controller/SysProfileController.java | 8 ++- se-modules/se-system/src/main/java/com/se/system/controller/SysConfigController.java | 76 ++++++++++++++++++++++++++------------ 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/se-modules/se-system/src/main/java/com/se/system/controller/SysConfigController.java b/se-modules/se-system/src/main/java/com/se/system/controller/SysConfigController.java index 8f816b5..c13c9c3 100644 --- a/se-modules/se-system/src/main/java/com/se/system/controller/SysConfigController.java +++ b/se-modules/se-system/src/main/java/com/se/system/controller/SysConfigController.java @@ -3,8 +3,11 @@ import java.util.List; import javax.servlet.http.HttpServletResponse; +import com.se.common.core.utils.AesUtils; +import com.se.common.core.utils.StringUtils; import com.se.system.domain.SysConfig; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -31,8 +34,13 @@ */ @RestController @RequestMapping("/config") -public class SysConfigController extends BaseController -{ +@SuppressWarnings("ALL") +public class SysConfigController extends BaseController { + @Value("${enableEncrypt}") + boolean enableEncrypt; + + private final static String PWD_KEY = "sys.user.initPassword"; + @Autowired private ISysConfigService configService; @@ -41,19 +49,33 @@ */ @RequiresPermissions("system:config:list") @GetMapping("/list") - public TableDataInfo list(SysConfig config) - { + public TableDataInfo list(SysConfig config) throws Exception { startPage(); List<SysConfig> list = configService.selectConfigList(config); + /*if (enableEncrypt && null != list) { + for (SysConfig cfg : list) { + if (null != cfg && PWD_KEY.equals(cfg.getConfigKey()) && !StringUtils.isEmpty(cfg.getConfigValue())) { + cfg.setConfigValue(AesUtils.encrypt(cfg.getConfigValue())); + } + } + }*/ + return getDataTable(list); } @Log(title = "鍙傛暟绠$悊", businessType = BusinessType.EXPORT) @RequiresPermissions("system:config:export") @PostMapping("/export") - public void export(HttpServletResponse response, SysConfig config) - { + public void export(HttpServletResponse response, SysConfig config) { List<SysConfig> list = configService.selectConfigList(config); + /*if (enableEncrypt && null != list) { + for (SysConfig cfg : list) { + if (null != cfg && PWD_KEY.equals(cfg.getConfigKey()) && !StringUtils.isEmpty(cfg.getConfigValue())) { + cfg.setConfigValue(AesUtils.encrypt(cfg.getConfigValue())); + } + } + }*/ + ExcelUtil<SysConfig> util = new ExcelUtil<SysConfig>(SysConfig.class); util.exportExcel(response, list, "鍙傛暟鏁版嵁"); } @@ -62,18 +84,26 @@ * 鏍规嵁鍙傛暟缂栧彿鑾峰彇璇︾粏淇℃伅 */ @GetMapping(value = "/{configId}") - public AjaxResult getInfo(@PathVariable Long configId) - { - return success(configService.selectConfigById(configId)); + public AjaxResult getInfo(@PathVariable Long configId) throws Exception { + SysConfig config = configService.selectConfigById(configId); + /*if ((enableEncrypt && null != config && PWD_KEY.equals(config.getConfigKey()) && !StringUtils.isEmpty(config.getConfigValue())) { + config.setConfigValue(AesUtils.encrypt(config.getConfigValue())); + }*/ + + return success(config); } /** * 鏍规嵁鍙傛暟閿悕鏌ヨ鍙傛暟鍊� */ @GetMapping(value = "/configKey/{configKey}") - public AjaxResult getConfigKey(@PathVariable String configKey) - { - return success(configService.selectConfigByKey(configKey)); + public AjaxResult getConfigKey(@PathVariable String configKey) throws Exception { + String val = configService.selectConfigByKey(configKey); + /*if (enableEncrypt && PWD_KEY.equals(configKey) && !StringUtils.isEmpty(val)) { + val = AesUtils.encrypt(val); + }*/ + + return success(val); } /** @@ -82,10 +112,8 @@ @RequiresPermissions("system:config:add") @Log(title = "鍙傛暟绠$悊", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@Validated @RequestBody SysConfig config) - { - if (!configService.checkConfigKeyUnique(config)) - { + public AjaxResult add(@Validated @RequestBody SysConfig config) { + if (!configService.checkConfigKeyUnique(config)) { return error("鏂板鍙傛暟'" + config.getConfigName() + "'澶辫触锛屽弬鏁伴敭鍚嶅凡瀛樺湪"); } config.setCreateBy(SecurityUtils.getUsername()); @@ -98,13 +126,15 @@ @RequiresPermissions("system:config:edit") @Log(title = "鍙傛暟绠$悊", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@Validated @RequestBody SysConfig config) - { - if (!configService.checkConfigKeyUnique(config)) - { + public AjaxResult edit(@Validated @RequestBody SysConfig config) throws Exception { + if (!configService.checkConfigKeyUnique(config)) { return error("淇敼鍙傛暟'" + config.getConfigName() + "'澶辫触锛屽弬鏁伴敭鍚嶅凡瀛樺湪"); } config.setUpdateBy(SecurityUtils.getUsername()); + /*if ((enableEncrypt && PWD_KEY.equals(config.getConfigKey()) && !StringUtils.isEmpty(config.getConfigValue())){ + config.setConfigValue(AesUtils.decrypt(config.getConfigValue())); + }*/ + return toAjax(configService.updateConfig(config)); } @@ -114,8 +144,7 @@ @RequiresPermissions("system:config:remove") @Log(title = "鍙傛暟绠$悊", businessType = BusinessType.DELETE) @DeleteMapping("/{configIds}") - public AjaxResult remove(@PathVariable Long[] configIds) - { + public AjaxResult remove(@PathVariable Long[] configIds) { configService.deleteConfigByIds(configIds); return success(); } @@ -126,8 +155,7 @@ @RequiresPermissions("system:config:remove") @Log(title = "鍙傛暟绠$悊", businessType = BusinessType.CLEAN) @DeleteMapping("/refreshCache") - public AjaxResult refreshCache() - { + public AjaxResult refreshCache() { configService.resetConfigCache(); return success(); } diff --git a/se-modules/se-system/src/main/java/com/se/system/controller/SysProfileController.java b/se-modules/se-system/src/main/java/com/se/system/controller/SysProfileController.java index 6201f36..8f60843 100644 --- a/se-modules/se-system/src/main/java/com/se/system/controller/SysProfileController.java +++ b/se-modules/se-system/src/main/java/com/se/system/controller/SysProfileController.java @@ -98,11 +98,13 @@ @Log(title = "涓汉淇℃伅", businessType = BusinessType.UPDATE) @PutMapping("/updatePwd") public AjaxResult updatePwd(String oldPassword, String newPassword) throws Exception { + if (enableEncrypt) { + oldPassword = AesUtils.decrypt(oldPassword); + newPassword = AesUtils.decrypt(newPassword); + } + String username = SecurityUtils.getUsername(); SysUser user = userService.selectUserByUserName(username); - if (enableEncrypt && !StringUtils.isEmpty(user.getPassword())) { - user.setPassword(AesUtils.decrypt(user.getPassword())); - } String password = user.getPassword(); if (!SecurityUtils.matchesPassword(oldPassword, password)) { return error("淇敼瀵嗙爜澶辫触锛屾棫瀵嗙爜閿欒"); -- Gitblit v1.9.3