diff --git a/build.gradle b/build.gradle index a6267d83..29e961ad 100644 --- a/build.gradle +++ b/build.gradle @@ -78,12 +78,12 @@ allprojects { compileJava.options.encoding = 'UTF-8' eclipse { - /* 第一次时请注释这段eclipse设置,可能报错,设置工程字符集 + /* 第一次时请注释这段eclipse设置,可能报错,设置工程字符集*/ jdt { File f = file('.settings/org.eclipse.core.resources.prefs') f.write('eclipse.preferences.version=1\n') f.append('encoding/=UTF-8') //use UTF-8 - }*/ + } } diff --git a/maxkey-common/src/test/java/org/maxkey/Copyright.java b/maxkey-common/src/test/java/org/maxkey/Copyright.java deleted file mode 100644 index 315678bf..00000000 --- a/maxkey-common/src/test/java/org/maxkey/Copyright.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top ] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.maxkey; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; - -/** - * 给java文件批量添加License信息. - * @author MaxKey Copyright Adder - * - */ -public class Copyright { - // 存放java文件的文件夹,必须是文件夹 - private static String srcFolder = "D:\\MaxKey\\workspace\\workspace-maxkey\\MaxKey"; - //已添加标识 - private static String copyRightText = "http://www.apache.org/licenses/LICENSE-2.0"; - //扫描目录 - private String folder; - //版权信息 - private String copyRight; - //待添加所以文件统计 - private long fileCount = 0; - //添加的问题就统计 - private long copyRightFileCount = 0; - private static String lineSeperator = System.getProperty("line.separator"); - private static String encode = "UTF-8"; - - /** - * Copyright. - * @param folder java文件夹. - * @param copyRight 版权内容. - */ - public Copyright(String folder, String copyRight) { - this.folder = folder; - this.copyRight = copyRight; - } - - /** - * main . - * @param args String - * @throws IOException IOException - */ - public static void main(String[] args) throws IOException { - // 从文件读取版权内容 - // 在D盘创建一个copyright.txt文件,把版权内容放进去即可 - String copyright = readCopyrightFromFile( - Copyright.class.getResource("copyright.txt").getFile()); - new Copyright(srcFolder, copyright).process(); - - - } - - /** - * process. - * @throws IOException not - */ - public void process() throws IOException { - this.addCopyright(new File(folder)); - System.out.println("fileCount " + fileCount); - System.out.println("copyRightFileCount " + copyRightFileCount); - } - - private void addCopyright(File folder) throws IOException { - File[] files = folder.listFiles(); - - if (files == null || files.length == 0) { - return; - } - - for (File f : files) { - if (f.isFile()) { - doAddCopyright(f); - } else { - addCopyright(f); - } - } - } - - private void doAddCopyright(File file) throws IOException { - String fileName = file.getName(); - boolean isJavaFile = fileName.toLowerCase().endsWith(".java"); - this.fileCount++; - if (isJavaFile && !isAddCopyrightFile(file.getAbsolutePath())) { - copyRightFileCount++; - System.out.println(file.getAbsolutePath()); - try { - this.doWrite(file); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - private void doWrite(File file) throws IOException { - StringBuilder javaFileContent = new StringBuilder(); - String line = null; - // 先添加copyright到文件头 - javaFileContent.append(copyRight).append(lineSeperator); - // 追加剩余内容 - BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(file), encode)); - while ((line = br.readLine()) != null) { - javaFileContent.append(line).append(lineSeperator); - } - - OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), encode); - writer.write(javaFileContent.toString()); - writer.close(); - br.close(); - } - - private static String readCopyrightFromFile(String copyFilePath) throws IOException { - StringBuilder copyright = new StringBuilder(); - - String line = null; - - BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(copyFilePath), encode)); - - while ((line = br.readLine()) != null) { - copyright.append(line).append(lineSeperator); - } - br.close(); - - return copyright.toString(); - } - - private static boolean isAddCopyrightFile(String filePath) throws IOException { - boolean isAddCopyright = false; - String line = null; - - BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(filePath), encode)); - - while ((line = br.readLine()) != null) { - if (line.indexOf(copyRightText) > -1) { - isAddCopyright = true; - break; - } - } - br.close(); - - return isAddCopyright; - } - -} \ No newline at end of file diff --git a/maxkey-common/src/test/java/org/maxkey/Copyright4RZ.java b/maxkey-common/src/test/java/org/maxkey/Copyright4RZ.java deleted file mode 100644 index 3bd6378c..00000000 --- a/maxkey-common/src/test/java/org/maxkey/Copyright4RZ.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright [2020] [MaxKey of copyright http://www.maxkey.top ] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.maxkey; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; - -/** - * 给java文件批量添加License信息. - * @author MaxKey Copyright Adder - * - */ -public class Copyright4RZ { - // 存放java文件的文件夹,必须是文件夹 - private static String srcFolder = "D:\\MaxKey\\Workspaces\\maxkey\\MaxKey\\maxkey-webs\\maxkey-web-mgt"; - - //已添加标识 - private static String copyRightText = "http://www.apache.org/licenses/LICENSE-2.0"; - //扫描目录 - private String folder; - //待添加所以文件统计 - private long fileCount = 0; - //添加的问题就统计 - private long copyRightFileCount = 0; - private static String lineSeperator = System.getProperty("line.separator"); - private static String encode = "UTF-8"; - private static OutputStreamWriter writer; - - static { - try { - writer = new OutputStreamWriter(new FileOutputStream("D:/MaxKey/code.txt"), encode); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - /** - * Copyright. - * @param folder java文件夹. - * @param copyRight 版权内容. - */ - public Copyright4RZ(String folder, String copyRight) { - this.folder = folder; - } - - /** - * main . - * @param args String - * @throws IOException IOException - */ - public static void main(String[] args) throws IOException { - // 从文件读取版权内容 - // 在D盘创建一个copyright.txt文件,把版权内容放进去即可 - String copyright = readCopyrightFromFile( - Copyright4RZ.class.getResource("copyright.txt").getFile()); - new Copyright4RZ(srcFolder, copyright).process(); - - writer.close(); - } - - /** - * process. - * @throws IOException not - */ - public void process() throws IOException { - this.addCopyright(new File(folder)); - System.out.println("fileCount " + fileCount); - System.out.println("copyRightFileCount " + copyRightFileCount); - } - - private void addCopyright(File folder) throws IOException { - File[] files = folder.listFiles(); - - if (files == null || files.length == 0) { - return; - } - - for (File f : files) { - if (f.isFile()) { - doAddCopyright(f); - } else { - addCopyright(f); - } - } - } - - private void doAddCopyright(File file) throws IOException { - String fileName = file.getName(); - boolean isJavaFile = fileName.toLowerCase().endsWith(".java"); - //boolean isJavaFile = fileName.toLowerCase().endsWith(".ftl"); - this.fileCount++; - if (isJavaFile) { - copyRightFileCount++; - System.out.println(file.getAbsolutePath()); - try { - this.doWrite(file); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - private void doWrite(File file) throws IOException { - StringBuilder javaFileContent = new StringBuilder(); - String line = null; - boolean isAddCopyrightFile = isAddCopyrightFile(file.getAbsolutePath()); - // 先添加copyright到文件头 - //javaFileContent.append(copyRight).append(lineSeperator); - // 追加剩余内容 - BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(file), encode)); - - int i=0; - while ((line = br.readLine()) != null) { - if(isAddCopyrightFile && i< 16) { - i++; - continue; - } - if(line.equals("") - ||line.replaceAll(" ", "").equals("") - ||line.replaceAll("\t", "").equals("") - ) { - - }else { - javaFileContent.append(line).append(lineSeperator); - } - } - - //OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), encode); - writer.write(javaFileContent.toString()); - - br.close(); - } - - private static String readCopyrightFromFile(String copyFilePath) throws IOException { - StringBuilder copyright = new StringBuilder(); - - String line = null; - - BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(copyFilePath), encode)); - - while ((line = br.readLine()) != null) { - copyright.append(line).append(lineSeperator); - } - br.close(); - - return copyright.toString(); - } - - private static boolean isAddCopyrightFile(String filePath) throws IOException { - boolean isAddCopyright = false; - String line = null; - - BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(filePath), encode)); - - while ((line = br.readLine()) != null) { - if (line.indexOf(copyRightText) > -1) { - isAddCopyright = true; - break; - } - } - br.close(); - - return isAddCopyright; - } - -} \ No newline at end of file diff --git a/maxkey-common/src/test/java/org/maxkey/copyright.txt b/maxkey-common/src/test/java/org/maxkey/copyright.txt deleted file mode 100644 index 70db8b51..00000000 --- a/maxkey-common/src/test/java/org/maxkey/copyright.txt +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright [2022] [MaxKey of copyright http://www.maxkey.top] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - \ No newline at end of file diff --git a/maxkey-core/src/main/java/org/maxkey/entity/AccountsStrategy.java b/maxkey-core/src/main/java/org/maxkey/entity/AccountsStrategy.java index 9303f375..88bc0c84 100644 --- a/maxkey-core/src/main/java/org/maxkey/entity/AccountsStrategy.java +++ b/maxkey-core/src/main/java/org/maxkey/entity/AccountsStrategy.java @@ -18,6 +18,8 @@ package org.maxkey.entity; import java.io.Serializable; +import java.util.Base64; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -43,6 +45,7 @@ public class AccountsStrategy extends JpaBaseEntity implements Serializable { @Column private String appId; private byte[] appIcon; + private String appIconBase64; @Column private String appName; @Column @@ -185,6 +188,14 @@ public class AccountsStrategy extends JpaBaseEntity implements Serializable { return appIcon; } + public String getAppIconBase64() { + return appIconBase64; + } + + public void setAppIconBase64(String appIconBase64) { + this.appIconBase64 = appIconBase64; + } + public void setAppIcon(byte[] appIcon) { this.appIcon = appIcon; } @@ -221,6 +232,15 @@ public class AccountsStrategy extends JpaBaseEntity implements Serializable { this.instName = instName; } + + public void transIconBase64() { + if(this.appIcon !=null) { + this.appIconBase64 = "data:image/png;base64," + + Base64.getEncoder().encodeToString(appIcon); + } + } + + @Override public String toString() { StringBuilder builder = new StringBuilder(); diff --git a/maxkey-core/src/main/java/org/maxkey/entity/Synchronizers.java b/maxkey-core/src/main/java/org/maxkey/entity/Synchronizers.java index 66911aae..6a7efdf3 100644 --- a/maxkey-core/src/main/java/org/maxkey/entity/Synchronizers.java +++ b/maxkey-core/src/main/java/org/maxkey/entity/Synchronizers.java @@ -84,7 +84,7 @@ public class Synchronizers extends JpaBaseEntity implements Serializable { String modifiedDate; @Column String status; - + @Column String service; @Column diff --git a/maxkey-core/src/main/java/org/maxkey/web/component/TreeNodeList.java b/maxkey-core/src/main/java/org/maxkey/web/component/TreeAttributes.java similarity index 55% rename from maxkey-core/src/main/java/org/maxkey/web/component/TreeNodeList.java rename to maxkey-core/src/main/java/org/maxkey/web/component/TreeAttributes.java index 0bf186a8..f4c394be 100644 --- a/maxkey-core/src/main/java/org/maxkey/web/component/TreeNodeList.java +++ b/maxkey-core/src/main/java/org/maxkey/web/component/TreeAttributes.java @@ -13,46 +13,56 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.maxkey.web.component; import java.util.ArrayList; -import java.util.HashMap; /** - * 数控件节点列表 - * 列表的元素为HashMap + * 数控件节点列表 列表的元素为TreeNode * * @author Crystal.Sea * */ -public class TreeNodeList { - - ArrayList> treeNodeList=new ArrayList>(); +public class TreeAttributes { - /** - * 获取列表 - * @return treeNodeList - */ - public ArrayList> getTreeNodeList() { - return treeNodeList; + TreeNode rootNode; + + int nodeCount; + + ArrayList nodes = new ArrayList(); + + public ArrayList getNodes() { + return nodes; } - /** - * 设置节点列表 - * @param treeNodeList - */ - public void setTreeNodeList(ArrayList> treeNodeList) { - this.treeNodeList = treeNodeList; + public void setNodes(ArrayList nodes) { + this.nodes = nodes; + } + + public TreeNode getRootNode() { + return rootNode; + } + + public void setRootNode(TreeNode rootNode) { + this.rootNode = rootNode; + } + + public int getNodeCount() { + return nodeCount; + } + + public void setNodeCount(int nodeCount) { + this.nodeCount = nodeCount; } /** * 新增节点到列表 + * * @param treeNode */ - public void addTreeNode(HashMap treeNode) { - this.treeNodeList .add(treeNode); + public void addNode(TreeNode treeNode) { + this.nodes.add(treeNode); } - + } diff --git a/maxkey-core/src/main/java/org/maxkey/web/component/TreeNode.java b/maxkey-core/src/main/java/org/maxkey/web/component/TreeNode.java index 98c7917d..24224056 100644 --- a/maxkey-core/src/main/java/org/maxkey/web/component/TreeNode.java +++ b/maxkey-core/src/main/java/org/maxkey/web/component/TreeNode.java @@ -17,8 +17,6 @@ package org.maxkey.web.component; -import java.util.HashMap; - /** * 数控件的节点 使用HashMap attr存储节点数据. * @@ -26,71 +24,119 @@ import java.util.HashMap; * */ public class TreeNode { + String key; + String code; + String title; + + String codePath; + String namePath; + + String parentKey; + String parentCode; + String parentTitle; + + + boolean expanded; + boolean isLeaf; + // TreeNode - HashMap attr = new HashMap(); + Object attrs; public TreeNode() { super(); } - public TreeNode(String id, String name) { - attr.put("id", id); - attr.put("name", name); + public TreeNode(String key, String title) { + this.key = key; + this.title = title; } - public TreeNode(String id, String name, boolean hasChild) { - attr.put("id", id); - attr.put("name", name); - attr.put("isParent", hasChild); - } + public String getKey() { + return key; + } - public TreeNode(String id, String name, String pId) { - attr.put("id", id); - attr.put("name", name); - attr.put("pId", pId); - } + public void setKey(String key) { + this.key = key; + } - public TreeNode(String id, String name, String pId, String url) { - attr.put("id", id); - attr.put("name", name); - attr.put("pId", pId); - attr.put("url", url); - } + public String getCode() { + return code; + } - public TreeNode(String id, String name, String pId, String url, String target) { - attr.put("id", id); - attr.put("name", name); - attr.put("pId", pId); - attr.put("url", url); - attr.put("target", target); - } + public void setCode(String code) { + this.code = code; + } - public void setChecked() { - attr.put("checked", true); - } + public String getTitle() { + return title; + } - public void setHasChild() { - attr.put("isParent", true); - } + public void setTitle(String title) { + this.title = title; + } - public void setPId(String pId) { - attr.put("pId", pId); - } + public String getCodePath() { + return codePath; + } - public void setIcon(String icon) { - attr.put("icon", icon); - } + public void setCodePath(String codePath) { + this.codePath = codePath; + } - public HashMap getAttr() { - return attr; - } + public String getNamePath() { + return namePath; + } - public void setAttr(String attrName, Object value) { - this.attr.put(attrName, value); - } + public void setNamePath(String namePath) { + this.namePath = namePath; + } - public void setAttr(HashMap attr) { - this.attr = attr; - } + public String getParentKey() { + return parentKey; + } + + public void setParentKey(String parentKey) { + this.parentKey = parentKey; + } + + public String getParentCode() { + return parentCode; + } + + public void setParentCode(String parentCode) { + this.parentCode = parentCode; + } + + public String getParentTitle() { + return parentTitle; + } + + public void setParentTitle(String parentTitle) { + this.parentTitle = parentTitle; + } + + public boolean isExpanded() { + return expanded; + } + + public void setExpanded(boolean expanded) { + this.expanded = expanded; + } + + public boolean getIsLeaf() { + return isLeaf; + } + + public void setLeaf(boolean isLeaf) { + this.isLeaf = isLeaf; + } + + public Object getAttrs() { + return attrs; + } + + public void setAttrs(Object attrs) { + this.attrs = attrs; + } } diff --git a/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/AccountsMapper.xml b/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/AccountsMapper.xml index ce671521..ff27434c 100644 --- a/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/AccountsMapper.xml +++ b/maxkey-persistence/src/main/resources/org/maxkey/persistence/mapper/xml/mysql/AccountsMapper.xml @@ -12,6 +12,9 @@ and username = #{username} + + and appName = #{appName} + and relatedusername = #{relatedUsername} diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/MaxKeyMgtMvcConfig.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/MaxKeyMgtMvcConfig.java index 07a46afa..85ca4a84 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/MaxKeyMgtMvcConfig.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/MaxKeyMgtMvcConfig.java @@ -117,15 +117,9 @@ public class MaxKeyMgtMvcConfig implements WebMvcConfigurer { registry.addInterceptor(permissionAdapter) .addPathPatterns("/dashboard/**") .addPathPatterns("/orgs/**") - .addPathPatterns("/userinfo/**") + .addPathPatterns("/users/**") .addPathPatterns("/apps/**") - .addPathPatterns("/app/accounts/**") - .addPathPatterns("/groups/**") - .addPathPatterns("/groupMember/**") - .addPathPatterns("/groupPrivileges/**") - .addPathPatterns("/roles/**") - .addPathPatterns("/rolemembers/**") - .addPathPatterns("/resources/**") + .addPathPatterns("/accounts/**") .addPathPatterns("/access/**") .addPathPatterns("/access/**/**") @@ -139,11 +133,8 @@ public class MaxKeyMgtMvcConfig implements WebMvcConfigurer { .addPathPatterns("/historys/**") .addPathPatterns("/historys/**/**") - .addPathPatterns("/socialsprovider/**") - .addPathPatterns("/accountsstrategy/**") .addPathPatterns("/institutions/**") .addPathPatterns("/localization/**") - .addPathPatterns("/synchronizers/**") ; diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/access/contorller/GroupMemberController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/access/contorller/GroupMemberController.java index ce2f78e1..9c3596d2 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/access/contorller/GroupMemberController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/access/contorller/GroupMemberController.java @@ -18,24 +18,24 @@ package org.maxkey.web.access.contorller; import org.apache.mybatis.jpa.persistence.JpaPageResults; -import org.maxkey.constants.ConstsOperateMessage; +import org.maxkey.authn.annotation.CurrentUser; import org.maxkey.entity.GroupMember; -import org.maxkey.entity.Groups; +import org.maxkey.entity.Message; +import org.maxkey.entity.UserInfo; import org.maxkey.persistence.service.GroupMemberService; import org.maxkey.persistence.service.GroupsService; import org.maxkey.web.WebContext; -import org.maxkey.web.message.Message; -import org.maxkey.web.message.MessageType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; @Controller @@ -51,72 +51,46 @@ public class GroupMemberController { @Qualifier("groupsService") GroupsService groupsService; - - - @RequestMapping(value={"/list"}) - public ModelAndView groupsList(){ - return new ModelAndView("groupuser/groupUsersList"); - } - - - @RequestMapping(value = { "/grid" }) + @RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE}) @ResponseBody - public JpaPageResults grid(@ModelAttribute("groupMember") GroupMember groupMember) { - if(groupMember.getGroupId()==null||groupMember.getGroupId().equals("")){ - return null; - } - groupMember.setInstId(WebContext.getUserInfo().getInstId()); - return groupMemberService.queryPageResults(groupMember); + public ResponseEntity fetch( + @ModelAttribute GroupMember groupMember, + @CurrentUser UserInfo currentUser) { + _logger.debug("fetch "+groupMember); + groupMember.setInstId(currentUser.getInstId()); + return new Message>( + groupMemberService.queryPageResults(groupMember)).buildResponse(); } - - @RequestMapping(value = { "/forwardAdd" }) - public ModelAndView forwardAdd() { - return new ModelAndView("groups/groupAdd"); - } - - @RequestMapping(value = { "/forwardUpdate/{id}" }) - public ModelAndView forwardUpdate(@PathVariable("id") String id) { - ModelAndView modelAndView=new ModelAndView("groups/groupUpdate"); - GroupMember groupMember=groupMemberService.get(id); - modelAndView.addObject("model",groupMember); - return modelAndView; - } - - - @RequestMapping(value = { "/queryMemberInGroup" }) + + @RequestMapping(value = { "/memberInGroup" }) @ResponseBody - public JpaPageResults queryMemberInGroup(@ModelAttribute("groupMember") GroupMember groupMember) { + public ResponseEntity memberInGroup(@ModelAttribute GroupMember groupMember,@CurrentUser UserInfo currentUser) { _logger.debug("groupMember : "+groupMember); - groupMember.setInstId(WebContext.getUserInfo().getInstId()); + groupMember.setInstId(currentUser.getInstId()); if(groupMember.getGroupId()==null||groupMember.getGroupId().equals("")||groupMember.getGroupId().equals("ROLE_ALL_USER")){ - return groupMemberService.queryPageResults("allMemberInGroup",groupMember); + return new Message>( + groupMemberService.queryPageResults("allMemberInGroup",groupMember)).buildResponse(); }else{ - return groupMemberService.queryPageResults("memberInGroup",groupMember); + return new Message>( + groupMemberService.queryPageResults("memberInGroup",groupMember)).buildResponse(); } } + - - @RequestMapping(value={"/addGroupAppsList/{groupId}"}) - public ModelAndView addGroupAppsList(@PathVariable("groupId") String groupId){ - ModelAndView modelAndView=new ModelAndView("groupuser/addGroupUsersList"); - Groups group=groupsService.get(groupId); - modelAndView.addObject("group", group); - return modelAndView; - } - - @RequestMapping(value = { "/queryMemberNotInGroup" }) + @RequestMapping(value = { "/memberNotInGroup" }) @ResponseBody - public JpaPageResults queryMemberNotInGroupGrid(@ModelAttribute("groupMember") GroupMember groupMember) { - groupMember.setInstId(WebContext.getUserInfo().getInstId()); - return groupMemberService.queryPageResults("memberNotInGroup",groupMember); + public ResponseEntity memberNotInGroup(@ModelAttribute GroupMember groupMember,@CurrentUser UserInfo currentUser) { + groupMember.setInstId(currentUser.getInstId()); + return new Message>( + groupMemberService.queryPageResults("memberNotInGroup",groupMember)).buildResponse(); } - @RequestMapping(value = {"/insert"}) + @RequestMapping(value = {"/add"}) @ResponseBody - public Message insertGroupUser(@ModelAttribute("groupMember") GroupMember groupMember) { + public ResponseEntity addGroupMember(@ModelAttribute("groupMember") GroupMember groupMember,@CurrentUser UserInfo currentUser) { if (groupMember == null || groupMember.getGroupId() == null) { - return new Message("传入参数为空",MessageType.error); + return new Message(Message.FAIL).buildResponse(); } String groupId = groupMember.getGroupId(); @@ -136,31 +110,25 @@ public class GroupMemberController { arrMemberIds[i], arrMemberNames[i], "USER", - WebContext.getUserInfo().getInstId()); + currentUser.getInstId()); newGroupMember.setId(WebContext.genId()); result = groupMemberService.insert(newGroupMember); } - if(!result) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error); + if(result) { + return new Message(Message.SUCCESS).buildResponse(); } - } - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.info); + return new Message(Message.FAIL).buildResponse(); } - @RequestMapping(value = {"/delete"}) @ResponseBody - public Message deleteGroupMember(@ModelAttribute("groupMember") GroupMember groupMember) { - _logger.debug("groupMember : "+groupMember); - - if (groupMember == null || groupMember.getId() == null) { - return new Message("传入参数为空",MessageType.error); + @RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity delete(@RequestParam("ids") String ids,@CurrentUser UserInfo currentUser) { + _logger.debug("-delete ids : {}" , ids); + if (groupMemberService.deleteBatch(ids)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); } - - if(groupMemberService.deleteBatch(groupMember.getId())) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.info); - } - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error); - } } diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/access/contorller/GroupPrivilegesController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/access/contorller/GroupPrivilegesController.java index 8af0d45a..3bd94612 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/access/contorller/GroupPrivilegesController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/access/contorller/GroupPrivilegesController.java @@ -14,28 +14,26 @@ * limitations under the License. */ - package org.maxkey.web.access.contorller; import org.apache.mybatis.jpa.persistence.JpaPageResults; -import org.maxkey.constants.ConstsOperateMessage; +import org.maxkey.authn.annotation.CurrentUser; import org.maxkey.entity.GroupPrivileges; +import org.maxkey.entity.Message; +import org.maxkey.entity.UserInfo; import org.maxkey.entity.apps.Apps; import org.maxkey.persistence.service.GroupPrivilegesService; import org.maxkey.web.WebContext; -import org.maxkey.web.message.Message; -import org.maxkey.web.message.MessageType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; - @Controller @RequestMapping(value={"/access/privileges"}) @@ -43,100 +41,78 @@ public class GroupPrivilegesController { final static Logger _logger = LoggerFactory.getLogger(GroupPrivilegesController.class); @Autowired - @Qualifier("groupPrivilegesService") GroupPrivilegesService groupPrivilegesService; - - @RequestMapping(value={"/list"}) - public ModelAndView groupsList(){ - return new ModelAndView("groupapp/groupAppsList"); - } - - @RequestMapping(value = { "/queryAppsInGroup" }) + @RequestMapping(value = { "/appsInGroup" }) @ResponseBody - public JpaPageResults queryAppsInGroup(@ModelAttribute("groupApp") GroupPrivileges groupApp) { - + public ResponseEntity appsInGroup( + @ModelAttribute GroupPrivileges groupPrivilege, + @CurrentUser UserInfo currentUser) { JpaPageResults groupPrivileges; - groupApp.setInstId(WebContext.getUserInfo().getInstId()); - groupPrivileges= groupPrivilegesService.queryPageResults("appsInGroup",groupApp); + groupPrivilege.setInstId(currentUser.getInstId()); + groupPrivileges= groupPrivilegesService.queryPageResults("appsInGroup",groupPrivilege); if(groupPrivileges!=null&&groupPrivileges.getRows()!=null){ for (Apps app : groupPrivileges.getRows()){ app.transIconBase64(); } } - return groupPrivileges; - + return new Message>(Message.FAIL,groupPrivileges).buildResponse(); } - @RequestMapping(value={"/addGroupAppsList/{groupId}"}) - public ModelAndView appsNotInGroupList(@PathVariable("groupId") String groupId){ - ModelAndView modelAndView=new ModelAndView("groupapp/addGroupAppsList"); - modelAndView.addObject("groupId", groupId); - return modelAndView; - } - - - @RequestMapping(value = { "/queryAppsNotInGroup" }) + @RequestMapping(value = { "/appsNotInGroup" }) @ResponseBody - public JpaPageResults queryAppsNotInGroup(@ModelAttribute("groupApp") GroupPrivileges groupApp) { + public ResponseEntity appsNotInGroup( + @ModelAttribute GroupPrivileges groupPrivilege, + @CurrentUser UserInfo currentUser) { JpaPageResults groupPrivileges; - groupApp.setInstId(WebContext.getUserInfo().getInstId()); - groupPrivileges= groupPrivilegesService.queryPageResults("appsNotInGroup",groupApp); + groupPrivilege.setInstId(currentUser.getInstId()); + groupPrivileges= groupPrivilegesService.queryPageResults("appsNotInGroup",groupPrivilege); if(groupPrivileges!=null&&groupPrivileges.getRows()!=null){ for (Apps app : groupPrivileges.getRows()){ app.transIconBase64(); } } - return groupPrivileges; - + return new Message>(Message.FAIL,groupPrivileges).buildResponse(); } - - @RequestMapping(value = {"/insert"}) + @RequestMapping(value = {"/add"}) @ResponseBody - public Message insertGroupApp(@ModelAttribute("groupApp") GroupPrivileges groupApp) { - if (groupApp == null || groupApp.getGroupId() == null) { - return new Message("传入参数为空",MessageType.error); + public ResponseEntity insertGroupApp( + @ModelAttribute GroupPrivileges groupPrivileges, + @CurrentUser UserInfo currentUser) { + if (groupPrivileges == null || groupPrivileges.getGroupId() == null) { + return new Message(Message.FAIL).buildResponse(); } - String groupId = groupApp.getGroupId(); - + String groupId = groupPrivileges.getGroupId(); boolean result = true; - String appIds = groupApp.getAppId(); + String appIds = groupPrivileges.getAppId(); if (appIds != null) { String[] arrAppIds = appIds.split(","); - for (int i = 0; i < arrAppIds.length; i++) { - GroupPrivileges newGroupApp = - new GroupPrivileges(groupId, arrAppIds[i],WebContext.getUserInfo().getInstId()); - newGroupApp.setId(WebContext.genId()); - result = groupPrivilegesService.insert(newGroupApp); + GroupPrivileges newGroupPrivilege = + new GroupPrivileges(groupId, arrAppIds[i],currentUser.getInstId()); + newGroupPrivilege.setId(WebContext.genId()); + result = groupPrivilegesService.insert(newGroupPrivilege); } - if(!result) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error); + if(result) { + return new Message(Message.SUCCESS).buildResponse(); } - } - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.info); + return new Message(Message.FAIL).buildResponse(); } - @RequestMapping(value = {"/delete"}) @ResponseBody - public Message deleteGroupApp(@ModelAttribute("groupApp") GroupPrivileges groupApp) { - if (groupApp == null || groupApp.getId() == null) { - return new Message("传入参数为空",MessageType.error); + @RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity delete(@RequestParam("ids") String ids,@CurrentUser UserInfo currentUser) { + _logger.debug("-delete ids : {}" , ids); + if (groupPrivilegesService.deleteBatch(ids)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); } - - if(groupPrivilegesService.deleteBatch(groupApp.getId())) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.info); - } - - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error); } - - - } diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/apps/contorller/ApplicationsController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/apps/contorller/ApplicationsController.java index 986a5ffc..20384607 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/apps/contorller/ApplicationsController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/apps/contorller/ApplicationsController.java @@ -19,24 +19,24 @@ package org.maxkey.web.apps.contorller; import org.apache.mybatis.jpa.persistence.JpaPageResults; -import org.maxkey.constants.ConstsOperateMessage; +import org.maxkey.authn.annotation.CurrentUser; import org.maxkey.crypto.ReciprocalUtils; import org.maxkey.entity.ExtraAttr; import org.maxkey.entity.ExtraAttrs; +import org.maxkey.entity.Message; +import org.maxkey.entity.UserInfo; import org.maxkey.entity.apps.Apps; -import org.maxkey.web.WebContext; -import org.maxkey.web.message.Message; -import org.maxkey.web.message.MessageType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; - import com.nimbusds.jose.JOSEException; import com.nimbusds.jose.JWEAlgorithm; import com.nimbusds.jose.JWSAlgorithm; @@ -53,68 +53,82 @@ import com.nimbusds.jose.jwk.gen.RSAKeyGenerator; public class ApplicationsController extends BaseAppContorller { final static Logger _logger = LoggerFactory.getLogger(ApplicationsController.class); - @RequestMapping(value={"/list"}) - public ModelAndView applicationsList(){ - return new ModelAndView("apps/appsList"); - } - - @RequestMapping(value={"/select"}) - public ModelAndView select(@RequestParam(name="accountMgmt",required=false) String accountMgmt){ - ModelAndView modelAndView=new ModelAndView("apps/selectAppsList"); - if(accountMgmt != null) { - modelAndView.addObject("accountMgmt", accountMgmt); - }else { - modelAndView.addObject("accountMgmt", 3); - } - return modelAndView; - } - - - @RequestMapping(value = { "/grid" }) + @RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE}) @ResponseBody - public JpaPageResults queryDataGrid(@ModelAttribute("applications") Apps applications) { - applications.setInstId(WebContext.getUserInfo().getInstId()); - JpaPageResults apps=appsService.queryPageResults(applications); - if(apps!=null&&apps.getRows()!=null){ - for (Apps app : apps.getRows()){ - app.transIconBase64(); - } + public ResponseEntity fetch(@ModelAttribute Apps apps,@CurrentUser UserInfo currentUser) { + apps.setInstId(currentUser.getInstId()); + JpaPageResults appsList =appsService.queryPageResults(apps); + for (Apps app : appsList.getRows()){ + app.transIconBase64(); } - return apps; + _logger.debug("List "+appsList); + return new Message>(appsList).buildResponse(); } - - @RequestMapping(value = { "/forwardAdd" }) - public ModelAndView forwardAdd() { - return new ModelAndView("apps/appAdd"); - } - - + @ResponseBody - @RequestMapping(value={"/add"}) - public Message insert(@ModelAttribute("application") Apps application) { - _logger.debug("-Add :" + application); - - transform(application); - application.setInstId(WebContext.getUserInfo().getInstId()); - if (appsService.insert(application)) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.success); - + @RequestMapping(value={"/query"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity query(@ModelAttribute Apps apps,@CurrentUser UserInfo currentUser) { + _logger.debug("-query :" + apps); + if (appsService.load(apps)!=null) { + return new Message(Message.SUCCESS).buildResponse(); } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.error); + return new Message(Message.SUCCESS).buildResponse(); } - } + @RequestMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity get(@PathVariable("id") String id) { + Apps apps = appsService.get(id); + return new Message(apps).buildResponse(); + } + + @ResponseBody + @RequestMapping(value={"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity insert(@RequestBody Apps apps,@CurrentUser UserInfo currentUser) { + _logger.debug("-Add :" + apps); + transform(apps); + apps.setInstId(currentUser.getInstId()); + if (appsService.insert(apps)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } + } + + @ResponseBody + @RequestMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity update(@RequestBody Apps apps,@CurrentUser UserInfo currentUser) { + _logger.debug("-update :" + apps); + transform(apps); + apps.setInstId(currentUser.getInstId()); + if (appsService.update(apps)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } + } + + @ResponseBody + @RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity delete(@RequestParam("ids") String ids,@CurrentUser UserInfo currentUser) { + _logger.debug("-delete ids : {} " , ids); + if (appsService.deleteBatch(ids)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } + } + + @RequestMapping(value = { "/forwardAppsExtendAttr/{id}" }) - public ModelAndView forwardExtendAttr(@PathVariable("id") String id) { - ModelAndView modelAndView=new ModelAndView("apps/appsExtendAttr"); - modelAndView.addObject("model",appsService.get(id)); - return modelAndView; + public ResponseEntity forwardExtendAttr(@PathVariable("id") String id) { + Apps apps = appsService.get(id); + return new Message(apps).buildResponse(); } @ResponseBody @RequestMapping(value = { "/updateExtendAttr" }) - public Message updateExtendAttr(@ModelAttribute("application") Apps application,@ModelAttribute("extraAttrs") ExtraAttr extraAttr) { + public ResponseEntity updateExtendAttr(@ModelAttribute("application") Apps application,@ModelAttribute("extraAttrs") ExtraAttr extraAttr) { if(extraAttr.getAttr()!=null){ String []attributes=extraAttr.getAttr().split(","); String []attributeType=extraAttr.getType().split(","); @@ -127,67 +141,16 @@ public class ApplicationsController extends BaseAppContorller { } if (appsService.updateExtendAttr(application)) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.success); - + return new Message(Message.SUCCESS).buildResponse(); } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error); + return new Message(Message.FAIL).buildResponse(); } } - /** - * query - * @param application - * @return - */ - @ResponseBody - @RequestMapping(value={"/query"}) - public Message query(@ModelAttribute("application") Apps application) { - _logger.debug("-query :" + application); - if (appsService.load(application)!=null) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.success); - - } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error); - } - - } - - /** - * modify - * @param application - * @return - */ - @ResponseBody - @RequestMapping(value={"/update"}) - public Message update(@ModelAttribute("application") Apps application) { - _logger.debug("-update application :" + application); - application.setInstId(WebContext.getUserInfo().getInstId()); - if (appsService.update(application)) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_SUCCESS),MessageType.success); - - } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_ERROR),MessageType.error); - } - - } - - - @ResponseBody - @RequestMapping(value={"/delete"}) - public Message delete(@ModelAttribute("application") Apps application) { - _logger.debug("-delete application :" + application); - if (appsService.deleteBatch(application.getId())) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_SUCCESS),MessageType.success); - - } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_SUCCESS),MessageType.error); - } - - } @ResponseBody @RequestMapping(value = { "/generate/secret/{type}" }) - public String generateSecret(@PathVariable("type") String type,@RequestParam(name="id",required=false) String id) throws JOSEException { + public ResponseEntity generateSecret(@PathVariable("type") String type,@RequestParam(name="id",required=false) String id) throws JOSEException { String secret=""; type=type.toLowerCase(); if(type.equals("des")){ @@ -242,7 +205,7 @@ public class ApplicationsController extends BaseAppContorller { secret=ReciprocalUtils.generateKey(""); } - return secret; + return new Message(Message.SUCCESS,(Object)secret).buildResponse(); } diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/config/contorller/AccountsStrategyController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/config/contorller/AccountsStrategyController.java index e243b696..cf8dd897 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/config/contorller/AccountsStrategyController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/config/contorller/AccountsStrategyController.java @@ -18,144 +18,99 @@ package org.maxkey.web.config.contorller; import org.apache.mybatis.jpa.persistence.JpaPageResults; -import org.maxkey.constants.ConstsOperateMessage; +import org.maxkey.authn.annotation.CurrentUser; import org.maxkey.entity.AccountsStrategy; -import org.maxkey.entity.Roles; +import org.maxkey.entity.Message; +import org.maxkey.entity.UserInfo; import org.maxkey.persistence.service.AccountsService; import org.maxkey.persistence.service.AccountsStrategyService; -import org.maxkey.web.WebContext; -import org.maxkey.web.message.Message; -import org.maxkey.web.message.MessageType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; - @Controller -@RequestMapping(value={"/accountsstrategy"}) +@RequestMapping(value={"/config/accountsstrategy"}) public class AccountsStrategyController { final static Logger _logger = LoggerFactory.getLogger(AccountsStrategyController.class); @Autowired - @Qualifier("accountsStrategyService") AccountsStrategyService accountsStrategyService; @Autowired AccountsService accountsService; - - - @RequestMapping(value={"/list"}) - public ModelAndView rolesList(){ - return new ModelAndView("accountsstrategy/accountsStrategyList"); - } - - @RequestMapping(value={"/select"}) - public ModelAndView selectAccountsStrategyList(){ - return new ModelAndView("accountsstrategy/selectAccountsStrategy"); - } - - @RequestMapping(value = { "/grid" }) + @RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE}) @ResponseBody - public JpaPageResults queryDataGrid(@ModelAttribute("accountsStrategy") AccountsStrategy accountsStrategy) { - _logger.debug(""+accountsStrategy); - accountsStrategy.setInstId(WebContext.getUserInfo().getInstId()); + public ResponseEntity fetch(@ModelAttribute AccountsStrategy accountsStrategy,@CurrentUser UserInfo currentUser) { + accountsStrategy.setInstId(currentUser.getInstId()); JpaPageResults accountsStrategyList =accountsStrategyService.queryPageResults(accountsStrategy); for (AccountsStrategy strategy : accountsStrategyList.getRows()){ - WebContext.setAttribute(strategy.getId(), strategy.getAppIcon()); + strategy.transIconBase64(); } - return accountsStrategyList; + _logger.debug("Accounts Strategy "+accountsStrategyList); + return new Message>( + accountsStrategyList).buildResponse(); } - - @RequestMapping(value = { "/forwardAdd" }) - public ModelAndView forwardAdd() { - return new ModelAndView("accountsstrategy/accountsStrategyAdd"); - } - - @RequestMapping(value = { "/forwardUpdate/{id}" }) - public ModelAndView forwardUpdate(@PathVariable("id") String id) { - ModelAndView modelAndView=new ModelAndView("accountsstrategy/accountsStrategyUpdate"); - AccountsStrategy accountsStrategy=accountsStrategyService.get(id); - modelAndView.addObject("model",accountsStrategy); - return modelAndView; - } - @ResponseBody - @RequestMapping(value={"/add"}) - public Message insert(@ModelAttribute("accountsStrategy") AccountsStrategy accountsStrategy) { - _logger.debug("-Add :" + accountsStrategy); - accountsStrategy.setInstId(WebContext.getUserInfo().getInstId()); - if (accountsStrategyService.insert(accountsStrategy)) { - accountsService.refreshByStrategy(accountsStrategy); - //rolesService.refreshDynamicRoles(role); - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.success); - - } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.error); - } - - } - - /** - * 查询 - * @param role - * @return - */ - @ResponseBody - @RequestMapping(value={"/query"}) - public Message query(@ModelAttribute("accountsStrategy") AccountsStrategy accountsStrategy) { + @RequestMapping(value={"/query"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity query(@ModelAttribute AccountsStrategy accountsStrategy,@CurrentUser UserInfo currentUser) { _logger.debug("-query :" + accountsStrategy); - accountsStrategy.setInstId(WebContext.getUserInfo().getInstId()); if (accountsStrategyService.load(accountsStrategy)!=null) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.success); - + return new Message(Message.SUCCESS).buildResponse(); } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error); + return new Message(Message.SUCCESS).buildResponse(); } - } - /** - * 修改 - * @param role - * @return - */ + @RequestMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity get(@PathVariable("id") String id) { + AccountsStrategy accountsStrategy = accountsStrategyService.get(id); + return new Message(accountsStrategy).buildResponse(); + } + @ResponseBody - @RequestMapping(value={"/update"}) - public Message update(@ModelAttribute("accountsStrategy") AccountsStrategy accountsStrategy) { - _logger.debug("-update AccountsStrategy :" + accountsStrategy); - accountsStrategy.setInstId(WebContext.getUserInfo().getInstId()); + @RequestMapping(value={"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity insert(@RequestBody AccountsStrategy accountsStrategy,@CurrentUser UserInfo currentUser) { + _logger.debug("-Add :" + accountsStrategy); + + if (accountsStrategyService.insert(accountsStrategy)) { + accountsService.refreshByStrategy(accountsStrategy); + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } + } + + @ResponseBody + @RequestMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity update(@RequestBody AccountsStrategy accountsStrategy,@CurrentUser UserInfo currentUser) { + _logger.debug("-update :" + accountsStrategy); if (accountsStrategyService.update(accountsStrategy)) { - // rolesService.refreshDynamicRoles(role); - accountsService.refreshByStrategy(accountsStrategy); - return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_SUCCESS),MessageType.success); - + accountsService.refreshByStrategy(accountsStrategy); + return new Message(Message.SUCCESS).buildResponse(); } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_ERROR),MessageType.error); + return new Message(Message.FAIL).buildResponse(); } - } - @ResponseBody - @RequestMapping(value={"/delete"}) - public Message delete(@ModelAttribute("role") Roles role) { - _logger.debug("-delete role :" + role); - - if (accountsStrategyService.deleteById(role.getId())) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_SUCCESS),MessageType.success); - + @RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity delete(@RequestParam("ids") String ids,@CurrentUser UserInfo currentUser) { + _logger.debug("-delete ids : {} " , ids); + if (accountsStrategyService.deleteBatch(ids)) { + return new Message(Message.SUCCESS).buildResponse(); } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_SUCCESS),MessageType.error); + return new Message(Message.FAIL).buildResponse(); } - } } diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/config/contorller/NoticesController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/config/contorller/NoticesController.java index 7b967bc5..080b26d2 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/config/contorller/NoticesController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/config/contorller/NoticesController.java @@ -18,23 +18,23 @@ package org.maxkey.web.config.contorller; import org.apache.mybatis.jpa.persistence.JpaPageResults; -import org.maxkey.constants.ConstsOperateMessage; +import org.maxkey.authn.annotation.CurrentUser; +import org.maxkey.entity.Message; import org.maxkey.entity.Notices; +import org.maxkey.entity.UserInfo; import org.maxkey.persistence.service.NoticesService; -import org.maxkey.web.WebContext; -import org.maxkey.web.message.Message; -import org.maxkey.web.message.MessageType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; - @Controller @RequestMapping(value={"/notices"}) @@ -42,101 +42,66 @@ public class NoticesController { final static Logger _logger = LoggerFactory.getLogger(NoticesController.class); @Autowired - @Qualifier("noticesService") NoticesService noticesService; - - @RequestMapping(value={"/list"}) - public ModelAndView noticesList(){ - return new ModelAndView("notices/noticesList"); - } - - @RequestMapping(value = { "/grid" }) + @RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE}) @ResponseBody - public JpaPageResults queryDataGrid(@ModelAttribute("notices") Notices notice) { + public ResponseEntity fetch(@ModelAttribute Notices notice,@CurrentUser UserInfo currentUser) { _logger.debug(""+notice); - notice.setInstId(WebContext.getUserInfo().getInstId()); - return noticesService.queryPageResults(notice); + notice.setInstId(currentUser.getInstId()); + return new Message>( + noticesService.queryPageResults(notice)).buildResponse(); } - - @RequestMapping(value = { "/forwardAdd" }) - public ModelAndView forwardAdd() { - return new ModelAndView("notices/noticeAdd"); - } - - @RequestMapping(value = { "/forwardUpdate/{id}" }) - public ModelAndView forwardUpdate(@PathVariable("id") String id) { - ModelAndView modelAndView=new ModelAndView("notices/noticeUpdate"); - Notices notice=noticesService.get(id); - modelAndView.addObject("model",notice); - return modelAndView; - } - @ResponseBody - @RequestMapping(value={"/add"}) - public Message insert(@ModelAttribute("notice")Notices notice) { - _logger.debug("-Add :" + notice); - notice.setInstId(WebContext.getUserInfo().getInstId()); - if (noticesService.insert(notice)) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.success); - - } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.error); - } - - } - - /** - * 查询 - * @param role - * @return - */ - @ResponseBody - @RequestMapping(value={"/query"}) - public Message query(@ModelAttribute("notice")Notices notice) { + @RequestMapping(value={"/query"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity query(@ModelAttribute Notices notice,@CurrentUser UserInfo currentUser) { _logger.debug("-query :" + notice); - notice.setInstId(WebContext.getUserInfo().getInstId()); if (noticesService.load(notice)!=null) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.success); - + return new Message(Message.SUCCESS).buildResponse(); } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error); + return new Message(Message.SUCCESS).buildResponse(); } - } - /** - * 修改 - * @param role - * @return - */ + @RequestMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity get(@PathVariable("id") String id) { + Notices notice=noticesService.get(id); + return new Message(notice).buildResponse(); + } + @ResponseBody - @RequestMapping(value={"/update"}) - public Message update(@ModelAttribute("notice")Notices notice) { - _logger.debug("-update notice :" + notice); - notice.setInstId(WebContext.getUserInfo().getInstId()); + @RequestMapping(value={"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity insert(@RequestBody Notices notice,@CurrentUser UserInfo currentUser) { + _logger.debug("-Add :" + notice); + + if (noticesService.insert(notice)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } + } + + @ResponseBody + @RequestMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity update(@RequestBody Notices notice,@CurrentUser UserInfo currentUser) { + _logger.debug("-update :" + notice); if (noticesService.update(notice)) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_SUCCESS),MessageType.success); - + return new Message(Message.SUCCESS).buildResponse(); } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_ERROR),MessageType.error); + return new Message(Message.FAIL).buildResponse(); } - } - @ResponseBody - @RequestMapping(value={"/delete"}) - public Message delete(@ModelAttribute("notice")Notices notice) { - _logger.debug("-delete notice :" + notice); - - if (noticesService.deleteBatch(notice.getId())) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_SUCCESS),MessageType.success); - + @RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity delete(@RequestParam("ids") String ids,@CurrentUser UserInfo currentUser) { + _logger.debug("-delete ids : {} " , ids); + if (noticesService.deleteBatch(ids)) { + return new Message(Message.SUCCESS).buildResponse(); } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_SUCCESS),MessageType.error); + return new Message(Message.FAIL).buildResponse(); } - } + } diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/config/contorller/SynchronizersController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/config/contorller/SynchronizersController.java index 2fb4f560..ad49ebf5 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/config/contorller/SynchronizersController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/config/contorller/SynchronizersController.java @@ -79,8 +79,8 @@ public class SynchronizersController { } @ResponseBody - @RequestMapping(value={"/sync"}) - public ResponseEntity sync(@RequestParam("id") String id) { + @RequestMapping(value={"/synchr"}) + public ResponseEntity synchr(@RequestParam("id") String id) { _logger.debug("-sync ids :" + id); List ids = StringUtils.string2List(id, ","); diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/AccountsController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/AccountsController.java index 64c32b5b..9aaff0b9 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/AccountsController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/AccountsController.java @@ -18,28 +18,28 @@ package org.maxkey.web.contorller; import org.apache.mybatis.jpa.persistence.JpaPageResults; -import org.maxkey.constants.ConstsOperateMessage; +import org.maxkey.authn.annotation.CurrentUser; import org.maxkey.crypto.password.PasswordReciprocal; import org.maxkey.entity.Accounts; import org.maxkey.entity.AccountsStrategy; +import org.maxkey.entity.Message; import org.maxkey.entity.UserInfo; import org.maxkey.persistence.service.AccountsService; import org.maxkey.persistence.service.AccountsStrategyService; import org.maxkey.persistence.service.AppsService; import org.maxkey.persistence.service.UserInfoService; -import org.maxkey.web.WebContext; -import org.maxkey.web.message.Message; -import org.maxkey.web.message.MessageType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; @Controller @@ -48,114 +48,89 @@ public class AccountsController { final static Logger _logger = LoggerFactory.getLogger(AccountsController.class); @Autowired - @Qualifier("accountsService") AccountsService accountsService; @Autowired - @Qualifier("accountsStrategyService") AccountsStrategyService accountsStrategyService; @Autowired - @Qualifier("appsService") - protected AppsService appsService; + AppsService appsService; @Autowired - @Qualifier("userInfoService") - private UserInfoService userInfoService; + UserInfoService userInfoService; - @RequestMapping(value={"/list"}) - public ModelAndView appAccountsList(){ - ModelAndView modelAndView=new ModelAndView("/accounts/accountsList"); - return modelAndView; + @RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE}) + @ResponseBody + public ResponseEntity fetch(@ModelAttribute Accounts accounts,@CurrentUser UserInfo currentUser) { + _logger.debug(""+accounts); + accounts.setInstId(currentUser.getInstId()); + return new Message>( + accountsService.queryPageResults(accounts)).buildResponse(); } - @RequestMapping(value={"/grid"}) @ResponseBody - public JpaPageResults grid(@ModelAttribute("appAccounts") Accounts appAccounts){ - appAccounts.setInstId(WebContext.getUserInfo().getInstId()); - return accountsService.queryPageResults(appAccounts); - - } - - @RequestMapping(value = { "/forwardSelect/{appId}" }) - public ModelAndView forwardSelect(@PathVariable("appId") String appId) { - ModelAndView modelAndView=new ModelAndView("/accounts/accountsAddSelect"); - modelAndView.addObject("appId",appId); - return modelAndView; - } - - @RequestMapping(value = { "/forwardAdd" }) - public ModelAndView forwardAdd(@ModelAttribute("appAccounts") Accounts appAccounts) { - ModelAndView modelAndView=new ModelAndView("/accounts/accountsAdd"); - //Applications app= appsService.get(appAccounts.getAppId()); - //appAccounts.setAppName(app.getName()); - modelAndView.addObject("model",appAccounts); - return modelAndView; - } - - /** - * - * @param group - * @return - */ - @ResponseBody - @RequestMapping(value={"/add"}) - public Message add(@ModelAttribute("appAccounts") Accounts appAccounts ) { - _logger.debug("-update :" + appAccounts); - appAccounts.setInstId(WebContext.getUserInfo().getInstId()); - appAccounts.setRelatedPassword(PasswordReciprocal.getInstance().encode(appAccounts.getRelatedPassword())); - accountsService.insert(appAccounts); - return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_SUCCESS),MessageType.success); - - } - - - @RequestMapping(value = { "/forwardUpdate/{id}" }) - public ModelAndView forwardUpdate(@PathVariable("id") String id) { - ModelAndView modelAndView=new ModelAndView("/accounts/accountsUpdate"); - Accounts appAccounts =accountsService.get(id); - - appAccounts.setRelatedPassword(PasswordReciprocal.getInstance().decoder(appAccounts.getRelatedPassword())); - modelAndView.addObject("model",appAccounts); - return modelAndView; + @RequestMapping(value={"/query"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity query(@ModelAttribute Accounts account,@CurrentUser UserInfo currentUser) { + _logger.debug("-query :" + account); + account.setInstId(currentUser.getInstId()); + if (accountsService.load(account)!=null) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.SUCCESS).buildResponse(); + } } - - /** - * - * @param group - * @return - */ - @ResponseBody - @RequestMapping(value={"/update"}) - public Message update(@ModelAttribute("appAccounts") Accounts appAccounts ) { - _logger.debug("-update :" + appAccounts); - appAccounts.setInstId(WebContext.getUserInfo().getInstId()); - appAccounts.setRelatedPassword(PasswordReciprocal.getInstance().encode(appAccounts.getRelatedPassword())); - accountsService.update(appAccounts); - return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_SUCCESS),MessageType.success); - + @RequestMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity get(@PathVariable("id") String id) { + Accounts account=accountsService.get(id); + return new Message(account).buildResponse(); } - @ResponseBody - @RequestMapping(value={"/delete"}) - public Message delete(@ModelAttribute("appAccounts") Accounts appAccounts ) { - - _logger.debug("-delete AppAccounts :" + appAccounts); - - accountsService.deleteBatch(appAccounts.getId()); - - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_SUCCESS),MessageType.success); + @RequestMapping(value={"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity insert(@RequestBody Accounts account,@CurrentUser UserInfo currentUser) { + _logger.debug("-Add :" + account); + account.setInstId(currentUser.getInstId()); + account.setRelatedPassword(PasswordReciprocal.getInstance().encode(account.getRelatedPassword())); + if (accountsService.insert(account)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } + } + + @ResponseBody + @RequestMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity update(@RequestBody Accounts account,@CurrentUser UserInfo currentUser) { + _logger.debug("-update :" + account); + account.setInstId(currentUser.getInstId()); + account.setRelatedPassword(PasswordReciprocal.getInstance().encode(account.getRelatedPassword())); + if (accountsService.update(account)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } + } + + @ResponseBody + @RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity delete(@RequestParam("ids") String ids,@CurrentUser UserInfo currentUser) { + _logger.debug("-delete ids : {} " , ids); + if (accountsService.deleteBatch(ids)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } } @ResponseBody @RequestMapping(value = "/generate") - public String generate(@ModelAttribute("appAccounts") Accounts appAccounts) { - AccountsStrategy accountsStrategy = accountsStrategyService.get(appAccounts.getStrategyId()); - UserInfo userInfo = userInfoService.get(appAccounts.getUserId()); + public String generate(@ModelAttribute Accounts account) { + AccountsStrategy accountsStrategy = accountsStrategyService.get(account.getStrategyId()); + UserInfo userInfo = userInfoService.get(account.getUserId()); return accountsService.generateAccount(userInfo,accountsStrategy); } + } diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/OrganizationsController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/OrganizationsController.java index 61049020..3a184659 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/OrganizationsController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/OrganizationsController.java @@ -20,7 +20,6 @@ package org.maxkey.web.contorller; import java.io.IOException; import java.util.ArrayList; import java.util.Comparator; -import java.util.HashMap; import java.util.List; import java.util.TreeSet; import java.util.stream.Collectors; @@ -29,30 +28,29 @@ import org.apache.mybatis.jpa.persistence.JpaPageResults; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; -import org.maxkey.constants.ConstsOperateMessage; +import org.maxkey.authn.annotation.CurrentUser; import org.maxkey.entity.ExcelImport; +import org.maxkey.entity.Message; import org.maxkey.entity.Organizations; +import org.maxkey.entity.UserInfo; import org.maxkey.persistence.service.OrganizationsService; import org.maxkey.util.ExcelUtils; import org.maxkey.web.WebContext; +import org.maxkey.web.component.TreeAttributes; import org.maxkey.web.component.TreeNode; -import org.maxkey.web.component.TreeNodeList; -import org.maxkey.web.message.Message; -import org.maxkey.web.message.MessageScope; -import org.maxkey.web.message.MessageType; -import org.maxkey.web.message.OperateType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.ModelAttribute; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; - import com.google.common.collect.Lists; @@ -61,132 +59,109 @@ import com.google.common.collect.Lists; public class OrganizationsController { static final Logger _logger = LoggerFactory.getLogger(OrganizationsController.class); - @Autowired - OrganizationsService organizationsService; + @Autowired + OrganizationsService organizationsService; - @ResponseBody - @RequestMapping({"/tree"}) - public List> organizationsTree(@RequestParam(value = "id", required = false) String id) { - _logger.debug("organizationsTree id :" + id); - Organizations queryOrg = new Organizations(); - queryOrg.setInstId(WebContext.getUserInfo().getInstId()); - List organizationsList = this.organizationsService.queryOrgs(queryOrg); - TreeNodeList treeNodeList = new TreeNodeList(); - - for (Organizations org : organizationsList) { - TreeNode treeNode = new TreeNode(org.getId(), org.getName()); - if (org.getHasChild() != null && org.getHasChild().startsWith("Y")) { - treeNode.setHasChild(); - } - - treeNode.setAttr("data", org); - treeNode.setPId(org.getParentId()); - if (org.getId().equals("1")) { - treeNode.setAttr("open", Boolean.valueOf(true)); - } else { - treeNode.setAttr("open", Boolean.valueOf(false)); - } - treeNodeList.addTreeNode(treeNode.getAttr()); - } - - - return treeNodeList.getTreeNodeList(); - } - - @RequestMapping({ "/list" }) - public ModelAndView orgsTreeList() { - return new ModelAndView("orgs/orgsList"); - } - - @RequestMapping(value = { "/pageresults" }) + @RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE}) @ResponseBody - public JpaPageResults pageResults(@ModelAttribute("orgs") Organizations orgs) { - orgs.setInstId(WebContext.getUserInfo().getInstId()); - return organizationsService.queryPageResults(orgs); - + public ResponseEntity fetch(@ModelAttribute Organizations org,@CurrentUser UserInfo currentUser) { + _logger.debug("fetch {}" , org); + org.setInstId(currentUser.getInstId()); + return new Message>( + organizationsService.queryPageResults(org)).buildResponse(); } - @RequestMapping({"/orgsSelect/{deptId}/{department}"}) - public ModelAndView orgsSelect(@PathVariable("deptId") String deptId, @PathVariable("department") String department) { - ModelAndView modelAndView = new ModelAndView("orgs/orgsSelect"); - modelAndView.addObject("deptId", deptId); - modelAndView.addObject("department", department); - return modelAndView; - } - - @RequestMapping(value = { "/forwardAdd" }) - public ModelAndView forwardAdd(@ModelAttribute("org") Organizations org) { - ModelAndView modelAndView=new ModelAndView("/orgs/orgsAdd"); - org =organizationsService.get(org.getId()); - modelAndView.addObject("model",org); - return modelAndView; - } - - @ResponseBody - @RequestMapping({"/add"}) - public Message insert(@ModelAttribute("org") Organizations org) { - _logger.debug("-Add :" + org); - if (null == org.getId() || org.getId().equals("")) { - org.generateId(); - } - - org.setInstId(WebContext.getUserInfo().getInstId()); - if (this.organizationsService.insert(org)) { - return new Message(WebContext.getI18nValue("message.action.insert.success"), MessageType.success); - } - - return new Message(WebContext.getI18nValue("message.action.insert.success"), MessageType.error); - } - @ResponseBody - @RequestMapping({"/query"}) - public Message query(@ModelAttribute("org") Organizations org) { - _logger.debug("-query :" + org); - org.setInstId(WebContext.getUserInfo().getInstId()); - if (this.organizationsService.load(org) != null) { - return new Message(WebContext.getI18nValue("message.action.insert.success"), MessageType.success); + @RequestMapping(value={"/query"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity query(@ModelAttribute Organizations org,@CurrentUser UserInfo currentUser) { + _logger.debug("-query {}" , org); + org.setInstId(currentUser.getInstId()); + List orgList = organizationsService.query(org); + if (orgList != null) { + return new Message>(Message.SUCCESS,orgList).buildResponse(); + } else { + return new Message>(Message.FAIL).buildResponse(); } - - return new Message(WebContext.getI18nValue("message.action.insert.error"), MessageType.error); } - - @RequestMapping(value = { "/forwardUpdate/{id}" }) - public ModelAndView forwardUpdate(@PathVariable("id") String id) { - ModelAndView modelAndView=new ModelAndView("/orgs/orgsUpdate"); - Organizations org =organizationsService.get(id); - - modelAndView.addObject("model",org); - return modelAndView; + + @RequestMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity get(@PathVariable("id") String id) { + Organizations org=organizationsService.get(id); + return new Message(org).buildResponse(); } - + @ResponseBody - @RequestMapping({"/update"}) - public Message update(@ModelAttribute("org") Organizations org) { - _logger.debug("-update organization :" + org); - org.setInstId(WebContext.getUserInfo().getInstId()); - if (this.organizationsService.update(org)) { - return new Message(WebContext.getI18nValue("message.action.update.success"), MessageType.success); - } - - return new Message(WebContext.getI18nValue("message.action.update.error"), MessageType.error); + @RequestMapping(value={"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity insert(@RequestBody Organizations org,@CurrentUser UserInfo currentUser) { + _logger.debug("-Add :" + org); + org.setInstId(currentUser.getInstId()); + if (organizationsService.insert(org)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } } - + @ResponseBody - @RequestMapping({"/delete"}) - public Message delete(@ModelAttribute("org") Organizations org) { - _logger.debug("-delete organization :" + org); - if (this.organizationsService.deleteBatch(org.getId())) { - return new Message(WebContext.getI18nValue("message.action.delete.success"), MessageType.success); - } - - return new Message(WebContext.getI18nValue("message.action.delete.success"), MessageType.error); + @RequestMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity update(@RequestBody Organizations org,@CurrentUser UserInfo currentUser) { + _logger.debug("-update :" + org); + org.setInstId(currentUser.getInstId()); + if (organizationsService.update(org)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } + } + + @ResponseBody + @RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity delete(@RequestParam("ids") String ids,@CurrentUser UserInfo currentUser) { + _logger.debug("-delete ids : {} " , ids); + if (organizationsService.deleteBatch(ids)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } + } + + + @ResponseBody + @RequestMapping(value={"/tree"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity tree(@ModelAttribute Organizations organization,@CurrentUser UserInfo currentUser) { + _logger.debug("-query {}" , organization); + organization.setInstId(currentUser.getInstId()); + List orgList = organizationsService.query(organization); + if (orgList != null) { + TreeAttributes treeAttributes = new TreeAttributes(); + int nodeCount = 0; + for (Organizations org : orgList) { + TreeNode treeNode = new TreeNode(org.getId(),org.getName()); + treeNode.setCode(org.getCode()); + treeNode.setCodePath(org.getCodePath()); + treeNode.setNamePath(org.getNamePath()); + treeNode.setParentKey(org.getParentId()); + treeNode.setParentTitle(org.getParentName()); + treeNode.setParentCode(org.getParentCode()); + treeNode.setAttrs(org); + treeNode.setLeaf(true); + treeAttributes.addNode(treeNode); + nodeCount ++; + if(org.getId().equalsIgnoreCase(currentUser.getInstId())) { + treeNode.setExpanded(true); + treeNode.setLeaf(false); + treeAttributes.setRootNode(treeNode); + } + } + treeAttributes.setNodeCount(nodeCount); + return new Message(Message.SUCCESS,treeAttributes).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } } - - @RequestMapping({"/orgUsersList"}) - public ModelAndView orgUsersList() { return new ModelAndView("orgs/orgUsersList"); } @RequestMapping(value = "/import") - public ModelAndView importing(@ModelAttribute("excelImportFile")ExcelImport excelImportFile) { + public ResponseEntity importingOrganizations(@ModelAttribute("excelImportFile")ExcelImport excelImportFile) { if (excelImportFile.isExcelNotEmpty() ) { try { List orgsList = Lists.newArrayList(); @@ -209,9 +184,9 @@ public class OrganizationsController { if(!CollectionUtils.isEmpty(orgsList)){ orgsList = orgsList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getId()))), ArrayList::new)); if(organizationsService.insertBatch(orgsList)) { - new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS), null, MessageType.success, OperateType.add, MessageScope.DB); + return new Message(Message.SUCCESS).buildResponse(); }else { - new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR), MessageType.error); + return new Message(Message.FAIL).buildResponse(); } } } catch (IOException e) { @@ -219,11 +194,10 @@ public class OrganizationsController { }finally { excelImportFile.closeWorkbook(); } - }else { - new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR), MessageType.error); } - return new ModelAndView("/orgs/orgsImport"); + return new Message(Message.FAIL).buildResponse(); + } public Organizations buildOrganizationsFromSheetRow(Row row) { diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/UserInfoController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/UserInfoController.java index 02dabf10..5aaa9374 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/UserInfoController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/contorller/UserInfoController.java @@ -29,16 +29,14 @@ import java.util.Map; import java.util.TreeSet; import java.util.stream.Collectors; -import javax.validation.Valid; - import org.apache.mybatis.jpa.persistence.JpaPageResults; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; -import org.maxkey.constants.ConstsOperateMessage; +import org.maxkey.authn.annotation.CurrentUser; import org.maxkey.constants.ConstsPasswordSetType; -import org.maxkey.crypto.password.PasswordReciprocal; import org.maxkey.entity.ExcelImport; +import org.maxkey.entity.Message; import org.maxkey.entity.UserInfo; import org.maxkey.persistence.service.UserInfoService; import org.maxkey.util.DateUtils; @@ -46,27 +44,22 @@ import org.maxkey.util.ExcelUtils; import org.maxkey.util.JsonUtils; import org.maxkey.util.StringUtils; import org.maxkey.web.WebContext; -import org.maxkey.web.message.Message; -import org.maxkey.web.message.MessageScope; -import org.maxkey.web.message.MessageType; -import org.maxkey.web.message.OperateType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.propertyeditors.CustomDateEditor; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.util.CollectionUtils; -import org.springframework.validation.BindingResult; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.ModelAttribute; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; - import com.google.common.collect.Lists; /** @@ -74,104 +67,85 @@ import com.google.common.collect.Lists; * */ @Controller -@RequestMapping(value = { "/userinfo" }) +@RequestMapping(value = { "/users" }) public class UserInfoController { final static Logger _logger = LoggerFactory.getLogger(UserInfoController.class); @Autowired - @Qualifier("userInfoService") private UserInfoService userInfoService; - /** - * 查询用户列表 - * @param user - * @return - */ - @RequestMapping(value={"/grid"}) + @RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE}) @ResponseBody - public JpaPageResults forwardUsersList(@ModelAttribute("userInfo") UserInfo userInfo){ - userInfo.setInstId(WebContext.getUserInfo().getInstId()); - return userInfoService.queryPageResults(userInfo); - + public ResponseEntity fetch(@ModelAttribute UserInfo userInfo,@CurrentUser UserInfo currentUser) { + _logger.debug(""+userInfo); + userInfo.setInstId(currentUser.getInstId()); + return new Message>( + userInfoService.queryPageResults(userInfo)).buildResponse(); } - - @RequestMapping(value={"/forwardAdd"}) - public ModelAndView forwardSelectUserType(){ - ModelAndView modelAndView=new ModelAndView("/userinfo/userAdd"); - //List userTypeList=userTypeService.query(null); - //modelAndView.addObject("userTypeList", userTypeList); - return modelAndView; - } - - @RequestMapping(value={"/list"}) - public ModelAndView usersList(){ - return new ModelAndView("/userinfo/usersList"); - } - - @RequestMapping(value={"/select"}) - public ModelAndView usersSelect(){ - ModelAndView modelAndView= new ModelAndView("/userinfo/userinfoSelect"); - return modelAndView; - } - - /** - * 新增 - * @param userInfo - * @param result - * @return - */ - @RequestMapping(value="/add") - public ModelAndView addUsers(@Valid @ModelAttribute("userInfo")UserInfo userInfo,BindingResult result) { - _logger.debug(userInfo.toString()); - if(result.hasErrors()){ - // new Message(WebContext.getValidErrorText(),result); + + @ResponseBody + @RequestMapping(value={"/query"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity query(@ModelAttribute UserInfo userInfo,@CurrentUser UserInfo currentUser) { + _logger.debug("-query :" + userInfo); + if (userInfoService.load(userInfo)!=null) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.SUCCESS).buildResponse(); } - - userInfo.setId(WebContext.genId()); - userInfo.setInstId(WebContext.getUserInfo().getInstId()); - //userInfo.setNameZHShortSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), true)); - //userInfo.setNameZHSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), false)); - if( userInfoService.insert(userInfo)) { - new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),userInfo,MessageType.success,OperateType.add,MessageScope.DB); - } - - new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error); - return WebContext.forward("forwardUpdate/"+userInfo.getId()); } - @RequestMapping(value={"/forwardUpdate/{id}"}) - public ModelAndView forwardUpdateUsers(@PathVariable("id")String id){ - ModelAndView modelAndView=new ModelAndView("/userinfo/userUpdate"); + @RequestMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity get(@PathVariable("id") String id) { UserInfo userInfo=userInfoService.get(id); if(userInfo.getPicture()!=null){ userInfo.transPictureBase64(); } - - modelAndView.addObject("model", userInfo); - return modelAndView; - } - - /** - * 查询用户,根据id - * @param id - * @return - */ - @ResponseBody - @RequestMapping(value="/getUsers/{id}") - public UserInfo getUserInfo(@PathVariable("id")String id) { - _logger.debug(id); - UserInfo userInfo = userInfoService.get(id); - if(userInfo!=null&&userInfo.getDecipherable()!=null){ - try{ - userInfo.setPassword(PasswordReciprocal.getInstance().decoder(userInfo.getDecipherable())); - }catch (Exception e) { - } - userInfo.setDecipherable(userInfo.getPassword()); - } - return userInfo; + return new Message(userInfo).buildResponse(); } + @ResponseBody + @RequestMapping(value={"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity insert(@RequestBody UserInfo userInfo,@CurrentUser UserInfo currentUser) { + _logger.debug("-Add :" + userInfo); + userInfo.setId(WebContext.genId()); + userInfo.setInstId(currentUser.getInstId()); + if (userInfoService.insert(userInfo)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } + } + + @ResponseBody + @RequestMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity update(@RequestBody UserInfo userInfo,@CurrentUser UserInfo currentUser) { + _logger.debug("-update :" + userInfo); + _logger.info(userInfo.getExtraAttributeName()); + _logger.info(userInfo.getExtraAttributeValue()); + //userInfo.setNameZHShortSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), true)); + //userInfo.setNameZHSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), false)); + convertExtraAttribute(userInfo) ; + _logger.info(userInfo.getExtraAttribute()); + userInfo.setInstId(currentUser.getInstId()); + if (userInfoService.update(userInfo)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } + } + + @ResponseBody + @RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity delete(@RequestParam("ids") String ids,@CurrentUser UserInfo currentUser) { + _logger.debug("-delete ids : {} " , ids); + if (userInfoService.deleteBatch(ids)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); + } + } + @ResponseBody @RequestMapping(value = "/randomPassword") @@ -179,69 +153,6 @@ public class UserInfoController { return userInfoService.randomPassword(); } - /** - * 修改用户 - * @param userInfo - * @param result - * @return - */ - - @RequestMapping(value="/update") - public ModelAndView updateUsers(@Valid @ModelAttribute("userInfo")UserInfo userInfo,BindingResult result) { - _logger.debug(userInfo.toString()); - if(result.hasErrors()){ - // new Message(WebContext.getValidErrorText(),result); - } - _logger.info(userInfo.getExtraAttributeName()); - _logger.info(userInfo.getExtraAttributeValue()); - //userInfo.setNameZHShortSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), true)); - //userInfo.setNameZHSpell(StringUtils.hanYu2Pinyin(userInfo.getDisplayName(), false)); - convertExtraAttribute(userInfo) ; - _logger.info(userInfo.getExtraAttribute()); - userInfo.setInstId(WebContext.getUserInfo().getInstId()); - if(userInfoService.update(userInfo)) { - new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_SUCCESS),userInfo,MessageType.success,OperateType.add,MessageScope.DB); - - } - new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_ERROR),MessageType.error); - return WebContext.forward("forwardUpdate/"+userInfo.getId()); - } - - - /** - * 批量删除用户 - * @param id - * @return - */ - @ResponseBody - @RequestMapping(value="/batchDelete") - public Message batchDeleteUsers(@RequestParam("id")String id) { - _logger.debug(id); - if(userInfoService.deleteBatch(StringUtils.string2List(id, ","))) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_SUCCESS),MessageType.success); - - } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_ERROR),MessageType.error); - } - } - - /** - * 根据用户id删除用户 - * - * @param id - * @return - */ - @ResponseBody - @RequestMapping(value="/delete") - public Message deleteUsersById(@RequestParam("id") String id) { - _logger.debug(id); - if(userInfoService.deleteBatch(id)) { - //provisioningPrepare.prepare(userInfo, OPERATEACTION.DELETE_ACTION); - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_SUCCESS),MessageType.success); - } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_ERROR),MessageType.error); - } - } protected void convertExtraAttribute(UserInfo userInfo) { if(userInfo.getExtraAttributeValue()!=null){ @@ -256,39 +167,22 @@ public class UserInfoController { } } - @RequestMapping(value={"/forwardChangePassword/{id}"}) - public ModelAndView forwardChangePassword(@PathVariable("id")String id){ - ModelAndView modelAndView=new ModelAndView("/userinfo/changePassword"); - UserInfo userInfo=userInfoService.get(id); - - modelAndView.addObject("model", userInfo); - return modelAndView; - } - - @RequestMapping(value={"/forwardChangeUserinfoStatus/{id}"}) - public ModelAndView forwardChangeUserinfoStatus(@PathVariable("id")String id){ - ModelAndView modelAndView=new ModelAndView("/userinfo/changeUserinfoStatus"); - UserInfo userInfo=userInfoService.get(id); - - modelAndView.addObject("model", userInfo); - return modelAndView; - } @ResponseBody @RequestMapping(value="/changePassword") - public Message changePassword( @ModelAttribute("userInfo")UserInfo userInfo) { + public ResponseEntity changePassword( @ModelAttribute("userInfo")UserInfo userInfo) { _logger.debug(userInfo.getId()); userInfo.setPasswordSetType(ConstsPasswordSetType.PASSWORD_NORMAL); if(userInfoService.changePassword(userInfo,true)) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_SUCCESS),MessageType.success); + return new Message(Message.SUCCESS).buildResponse(); } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_ERROR),MessageType.error); + return new Message(Message.FAIL).buildResponse(); } } @RequestMapping(value = "/import") - public ModelAndView importing(@ModelAttribute("excelImportFile")ExcelImport excelImportFile) { + public ResponseEntity importingUsers(@ModelAttribute("excelImportFile")ExcelImport excelImportFile) { if (excelImportFile.isExcelNotEmpty() ) { try { List userInfoList = Lists.newArrayList(); @@ -314,9 +208,7 @@ public class UserInfoController { if(!CollectionUtils.isEmpty(userInfoList)){ userInfoList = userInfoList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getUsername()))), ArrayList::new)); if( userInfoService.insertBatch(userInfoList)) { - new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS), null, MessageType.success, OperateType.add, MessageScope.DB); - }else { - new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR), MessageType.error); + return new Message(Message.SUCCESS).buildResponse(); } } } catch (IOException e) { @@ -324,11 +216,9 @@ public class UserInfoController { }finally { excelImportFile.closeWorkbook(); } - }else { - new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR), MessageType.error); } + return new Message(Message.FAIL).buildResponse(); - return new ModelAndView("/userinfo/usersImport"); } @InitBinder diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/ResourcesController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/ResourcesController.java index 302737cb..964399df 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/ResourcesController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/ResourcesController.java @@ -17,167 +17,138 @@ package org.maxkey.web.permissions.contorller; -import java.util.HashMap; import java.util.List; import org.apache.mybatis.jpa.persistence.JpaPageResults; -import org.maxkey.constants.ConstsOperateMessage; +import org.maxkey.authn.annotation.CurrentUser; +import org.maxkey.entity.Message; import org.maxkey.entity.Resources; +import org.maxkey.entity.UserInfo; import org.maxkey.persistence.service.ResourcesService; -import org.maxkey.web.WebContext; +import org.maxkey.web.component.TreeAttributes; import org.maxkey.web.component.TreeNode; -import org.maxkey.web.component.TreeNodeList; -import org.maxkey.web.message.Message; -import org.maxkey.web.message.MessageType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; @Controller -@RequestMapping(value={"/resources"}) +@RequestMapping(value={"/permissions/resources"}) public class ResourcesController { final static Logger _logger = LoggerFactory.getLogger(ResourcesController.class); @Autowired - @Qualifier("resourcesService") ResourcesService resourcesService; - - - @RequestMapping(value={"/list"}) - public ModelAndView resourcesList(){ - return new ModelAndView("resources/resourcesList"); - } - - @RequestMapping(value={"/selectResourcesList"}) - public ModelAndView selectResourcesList(){ - return new ModelAndView("resources/selectResourcesList"); - } - - - @RequestMapping(value = { "/grid" }) + @RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE}) @ResponseBody - public JpaPageResults queryDataGrid(@ModelAttribute("resources") Resources resources) { - _logger.debug(""+resources); - resources.setInstId(WebContext.getUserInfo().getInstId()); - return resourcesService.queryPageResults(resources); + public ResponseEntity fetch(@ModelAttribute Resources resource,@CurrentUser UserInfo currentUser) { + _logger.debug("fetch {}" , resource); + resource.setInstId(currentUser.getInstId()); + return new Message>( + resourcesService.queryPageResults(resource)).buildResponse(); } - - @RequestMapping(value = { "/forwardAdd" }) - public ModelAndView forwardAdd() { - return new ModelAndView("resources/resourceAdd"); + @ResponseBody + @RequestMapping(value={"/query"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity query(@ModelAttribute Resources resource,@CurrentUser UserInfo currentUser) { + _logger.debug("-query {}" , resource); + resource.setInstId(currentUser.getInstId()); + List resourceList = resourcesService.query(resource); + if (resourceList != null) { + return new Message>(Message.SUCCESS,resourceList).buildResponse(); + } else { + return new Message>(Message.FAIL).buildResponse(); + } } - @RequestMapping(value = { "/forwardUpdate/{id}" }) - public ModelAndView forwardUpdate(@PathVariable("id") String id) { - ModelAndView modelAndView=new ModelAndView("resources/resourceUpdate"); + @RequestMapping(value = { "/get/{id}" }, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity get(@PathVariable("id") String id) { Resources resource=resourcesService.get(id); - modelAndView.addObject("model",resource); - return modelAndView; + return new Message(resource).buildResponse(); } @ResponseBody - @RequestMapping(value={"/add"}) - public Message insert(@ModelAttribute("resource") Resources resource) { + @RequestMapping(value={"/add"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity insert(@RequestBody Resources resource,@CurrentUser UserInfo currentUser) { _logger.debug("-Add :" + resource); - resource.setInstId(WebContext.getUserInfo().getInstId()); + resource.setInstId(currentUser.getInstId()); if (resourcesService.insert(resource)) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.success); - + return new Message(Message.SUCCESS).buildResponse(); } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.error); + return new Message(Message.FAIL).buildResponse(); } - } - /** - * 查询 - * @param resource - * @return - */ @ResponseBody - @RequestMapping(value={"/query"}) - public Message query(@ModelAttribute("resource") Resources resource) { - _logger.debug("-query :" + resource); - resource.setInstId(WebContext.getUserInfo().getInstId()); - if (resourcesService.load(resource)!=null) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.success); - - } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error); - } - - } - - /** - * 修改 - * @param resource - * @return - */ - @ResponseBody - @RequestMapping(value={"/update"}) - public Message update(@ModelAttribute("resource") Resources resource) { - _logger.debug("-update resource :" + resource); - resource.setInstId(WebContext.getUserInfo().getInstId()); + @RequestMapping(value={"/update"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity update(@RequestBody Resources resource,@CurrentUser UserInfo currentUser) { + _logger.debug("-update :" + resource); + resource.setInstId(currentUser.getInstId()); if (resourcesService.update(resource)) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_SUCCESS),MessageType.success); - + return new Message(Message.SUCCESS).buildResponse(); } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.UPDATE_ERROR),MessageType.error); + return new Message(Message.FAIL).buildResponse(); } - } - @ResponseBody - @RequestMapping(value={"/delete"}) - public Message delete(@ModelAttribute("resource") Resources resource) { - _logger.debug("-delete resource :" + resource); - - if (resourcesService.deleteBatch(resource.getId())) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_SUCCESS),MessageType.success); - + @RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity delete(@RequestParam("ids") String ids,@CurrentUser UserInfo currentUser) { + _logger.debug("-delete ids : {} " , ids); + if (resourcesService.deleteBatch(ids)) { + return new Message(Message.SUCCESS).buildResponse(); } else { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.DELETE_SUCCESS),MessageType.error); + return new Message(Message.FAIL).buildResponse(); + } + } + + + @ResponseBody + @RequestMapping(value={"/tree"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity tree(@ModelAttribute Resources resource,@CurrentUser UserInfo currentUser) { + _logger.debug("-query {}" , resource); + resource.setInstId(currentUser.getInstId()); + List resourceList = resourcesService.query(resource); + if (resourceList != null) { + TreeAttributes treeAttributes = new TreeAttributes(); + int nodeCount = 0; + for (Resources r : resourceList) { + TreeNode treeNode = new TreeNode(r.getId(),r.getName()); + treeNode.setParentKey(r.getParentId()); + treeNode.setParentTitle(r.getParentName()); + treeNode.setAttrs(r); + treeNode.setLeaf(true); + treeAttributes.addNode(treeNode); + nodeCount ++; + if(r.getId().equalsIgnoreCase(currentUser.getInstId())) { + treeNode.setExpanded(true); + treeNode.setLeaf(false); + treeAttributes.setRootNode(treeNode); + } + } + + TreeNode rootNode = new TreeNode(resource.getAppId(),resource.getAppName()); + rootNode.setParentKey(resource.getAppId()); + rootNode.setExpanded(true); + rootNode.setLeaf(false); + treeAttributes.setRootNode(rootNode); + + treeAttributes.setNodeCount(nodeCount); + return new Message(Message.SUCCESS,treeAttributes).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); } - } - @ResponseBody - @RequestMapping({"/tree"}) - public List> resourcesTree( - @RequestParam(value = "appId", required = false) String appId, - @RequestParam(value = "appName", required = false) String appName - ) { - _logger.debug("resourcesTree appId :" + appId + " ,appName " + appName); - Resources queryRes = new Resources(); - queryRes.setAppId(appId); - queryRes.setInstId(WebContext.getUserInfo().getInstId()); - List resourcesList = this.resourcesService.queryResourcesTree(queryRes); - TreeNodeList treeNodeList = new TreeNodeList(); - - TreeNode rootNode = new TreeNode(appId, appName); - rootNode.setAttr("open", Boolean.valueOf(true)); - treeNodeList.addTreeNode(rootNode.getAttr()); - - for (Resources res : resourcesList) { - TreeNode treeNode = new TreeNode(res.getId(), res.getName()); - treeNode.setAttr("data", res); - treeNode.setPId(res.getParentId()); - treeNodeList.addTreeNode(treeNode.getAttr()); - } - - return treeNodeList.getTreeNodeList(); - } } diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/RoleMemberController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/RoleMemberController.java index ed01142a..061b265e 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/RoleMemberController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/RoleMemberController.java @@ -18,96 +18,79 @@ package org.maxkey.web.permissions.contorller; import org.apache.mybatis.jpa.persistence.JpaPageResults; -import org.maxkey.constants.ConstsOperateMessage; +import org.maxkey.authn.annotation.CurrentUser; +import org.maxkey.entity.Message; import org.maxkey.entity.RoleMember; -import org.maxkey.entity.Roles; +import org.maxkey.entity.UserInfo; import org.maxkey.persistence.service.RoleMemberService; import org.maxkey.persistence.service.RolesService; import org.maxkey.web.WebContext; -import org.maxkey.web.message.Message; -import org.maxkey.web.message.MessageType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; @Controller -@RequestMapping(value={"/rolemembers"}) +@RequestMapping(value={"/permissions/rolemembers"}) public class RoleMemberController { final static Logger _logger = LoggerFactory.getLogger(RoleMemberController.class); @Autowired - @Qualifier("roleMemberService") RoleMemberService roleMemberService; @Autowired - @Qualifier("rolesService") RolesService rolesService; - - - @RequestMapping(value={"/list"}) - public ModelAndView groupsList(){ - return new ModelAndView("roleusers/roleUsersList"); - } - - - @RequestMapping(value = { "/grid" }) + @RequestMapping(value = { "/fetch" }, produces = {MediaType.APPLICATION_JSON_VALUE}) @ResponseBody - public JpaPageResults grid(@ModelAttribute("roleMember") RoleMember roleMember) { + public ResponseEntity fetch( + @ModelAttribute("roleMember") RoleMember roleMember, + @CurrentUser UserInfo currentUser) { if(roleMember.getRoleId()==null||roleMember.getRoleId().equals("")){ return null; } - roleMember.setInstId(WebContext.getUserInfo().getInstId()); - return roleMemberService.queryPageResults(roleMember); + roleMember.setInstId(currentUser.getInstId()); + return new Message>( + roleMemberService.queryPageResults(roleMember)).buildResponse(); } - - @RequestMapping(value = { "/queryMemberInRole" }) + @RequestMapping(value = { "/memberInRole" }) @ResponseBody - public JpaPageResults queryMemberInRole(@ModelAttribute("roleMember") RoleMember roleMember) { + public ResponseEntity memberInRole(@ModelAttribute RoleMember roleMember) { _logger.debug("roleMember : "+roleMember); roleMember.setInstId(WebContext.getUserInfo().getInstId()); if(roleMember.getRoleId()==null||roleMember.getRoleId().equals("")||roleMember.getRoleId().equals("ALL_USER_ROLE")){ - return roleMemberService.queryPageResults("allMemberInRole",roleMember); + return new Message>( + roleMemberService.queryPageResults("allMemberInRole",roleMember)).buildResponse(); }else{ - return roleMemberService.queryPageResults("memberInRole",roleMember); + return new Message>( + roleMemberService.queryPageResults("memberInRole",roleMember)).buildResponse(); } } - - - @RequestMapping(value={"/addRoleAppsList/{roleId}"}) - public ModelAndView addGroupAppsList(@PathVariable("roleId") String roleId){ - ModelAndView modelAndView=new ModelAndView("roleusers/addRoleUsersList"); - Roles role=rolesService.get(roleId); - modelAndView.addObject("role", role); - return modelAndView; - } - - @RequestMapping(value = { "/queryMemberNotInRole" }) + + @RequestMapping(value = { "/memberNotInRole" }) @ResponseBody - public JpaPageResults queryMemberNotInGroupGrid(@ModelAttribute("roleMember") RoleMember roleMember) { + public ResponseEntity memberNotInRole(@ModelAttribute RoleMember roleMember) { roleMember.setInstId(WebContext.getUserInfo().getInstId()); - return roleMemberService.queryPageResults("memberNotInRole",roleMember); + return new Message>( + roleMemberService.queryPageResults("memberNotInGroup",roleMember)).buildResponse(); } - - @RequestMapping(value = {"/insert"}) + @RequestMapping(value = {"/add"}) @ResponseBody - public Message insertRoleUsers(@ModelAttribute("roleMember") RoleMember roleMember) { + public ResponseEntity add(@ModelAttribute RoleMember roleMember) { if (roleMember == null || roleMember.getRoleId() == null) { - return new Message("传入参数为空",MessageType.error); + return new Message(Message.FAIL).buildResponse(); } String groupId = roleMember.getRoleId(); - boolean result = true; String memberIds = roleMember.getMemberId(); String memberNames = roleMember.getMemberName(); @@ -127,26 +110,21 @@ public class RoleMemberController { newRoleMember.setId(WebContext.genId()); result = roleMemberService.insert(newRoleMember); } - if(!result) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error); + if(result) { + return new Message(Message.SUCCESS).buildResponse(); } - } - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.info); + return new Message(Message.FAIL).buildResponse(); } - @RequestMapping(value = {"/delete"}) @ResponseBody - public Message deleteGroupMember(@ModelAttribute("roleMember") RoleMember roleMember) { - _logger.debug("roleMember : "+roleMember); - - if (roleMember == null || roleMember.getId() == null) { - return new Message("传入参数为空",MessageType.error); + @RequestMapping(value={"/delete"}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public ResponseEntity delete(@RequestParam("ids") String ids,@CurrentUser UserInfo currentUser) { + _logger.debug("-delete ids : {}" , ids); + if (roleMemberService.deleteBatch(ids)) { + return new Message(Message.SUCCESS).buildResponse(); + } else { + return new Message(Message.FAIL).buildResponse(); } - - if(roleMemberService.deleteBatch(roleMember.getId())) { - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_SUCCESS),MessageType.info); - } - return new Message(WebContext.getI18nValue(ConstsOperateMessage.INSERT_ERROR),MessageType.error); } } diff --git a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/PermissionsController.java b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/RolePrivilegesController.java similarity index 96% rename from maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/PermissionsController.java rename to maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/RolePrivilegesController.java index c98a43c5..c4171944 100644 --- a/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/PermissionsController.java +++ b/maxkey-webs/maxkey-web-mgt/src/main/java/org/maxkey/web/permissions/contorller/RolePrivilegesController.java @@ -40,9 +40,9 @@ import org.springframework.web.servlet.ModelAndView; @Controller -@RequestMapping(value={"/permissions"}) -public class PermissionsController { - final static Logger _logger = LoggerFactory.getLogger(PermissionsController.class); +@RequestMapping(value={"/permissions/privileges"}) +public class RolePrivilegesController { + final static Logger _logger = LoggerFactory.getLogger(RolePrivilegesController.class); @Autowired @Qualifier("rolesService")