From 88128bec0823aef14a253d7e95e5ce94ef10b4c8 Mon Sep 17 00:00:00 2001 From: "Crystal.Sea" Date: Thu, 27 Aug 2020 07:59:03 +0800 Subject: [PATCH] GRIDLIST --- .../persistence/service/UserInfoService.java | 21 +++++++++++++++++++ .../web/contorller/AppListController.java | 12 +---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/maxkey-persistence/src/main/java/org/maxkey/persistence/service/UserInfoService.java b/maxkey-persistence/src/main/java/org/maxkey/persistence/service/UserInfoService.java index 5651aac3b..75fa3b737 100644 --- a/maxkey-persistence/src/main/java/org/maxkey/persistence/service/UserInfoService.java +++ b/maxkey-persistence/src/main/java/org/maxkey/persistence/service/UserInfoService.java @@ -35,6 +35,7 @@ import org.maxkey.web.WebContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; @@ -47,6 +48,7 @@ import org.springframework.stereotype.Service; public class UserInfoService extends JpaBaseService { final static Logger _logger = LoggerFactory.getLogger(UserInfoService.class); + final static String UPDATE_GRIDLIST_SQL = "UPDATE MXK_USERINFO SET GRIDLIST = ? WHERE ID = ?"; @Autowired private PasswordEncoder passwordEncoder; @@ -56,6 +58,9 @@ public class UserInfoService extends JpaBaseService { @Autowired KafkaProvisioningService kafkaProvisioningService; + @Autowired + protected JdbcTemplate jdbcTemplate; + public UserInfoService() { super(UserInfoMapper.class); } @@ -107,6 +112,22 @@ public class UserInfoService extends JpaBaseService { return false; } + public boolean updateGridList(String gridList) { + try { + if (gridList != null && !gridList.equals("")) { + int intGridList = Integer.parseInt(gridList); + jdbcTemplate.update(UPDATE_GRIDLIST_SQL, intGridList, + WebContext.getUserInfo().getId()); + WebContext.getUserInfo().setGridList(intGridList); + } + }catch(Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + + public boolean updateProtectedApps(UserInfo userinfo) { try { if(WebContext.getUserInfo() != null) { diff --git a/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/AppListController.java b/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/AppListController.java index b3bda6bbb..278f797f2 100644 --- a/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/AppListController.java +++ b/maxkey-web-maxkey/src/main/java/org/maxkey/web/contorller/AppListController.java @@ -34,7 +34,6 @@ import org.maxkey.web.message.MessageType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -55,9 +54,6 @@ public class AppListController { @Autowired private UserInfoService userInfoService; - @Autowired - protected JdbcTemplate jdbcTemplate; - @Autowired AccountsService appUsersService; @@ -73,13 +69,7 @@ public class AppListController { public ModelAndView appList( @RequestParam(value = "gridList", required = false) String gridList) { ModelAndView modelAndView = new ModelAndView("main/appList"); - - if (gridList != null && !gridList.equals("")) { - int intGridList = Integer.parseInt(gridList); - jdbcTemplate.update("UPDATE MXK_USERINFO SET GRIDLIST = ? WHERE ID = ?", intGridList, - WebContext.getUserInfo().getId()); - WebContext.getUserInfo().setGridList(intGridList); - } + userInfoService.updateGridList(gridList); modelAndView.addObject("appList", queryAccessableApps()); return modelAndView; } -- GitLab