OrganizationsController.java 6.9 KB
Newer Older
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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.
 */
 

MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
18 19 20 21 22
package org.maxkey.web.contorller;

import java.util.HashMap;
import java.util.List;

MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
23
import org.apache.mybatis.jpa.persistence.JpaPageResults;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
24
import org.maxkey.constants.ConstantsOperateMessage;
M
MaxKey 已提交
25 26
import org.maxkey.entity.ExcelImport;
import org.maxkey.entity.Organizations;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
27
import org.maxkey.persistence.service.OrganizationsService;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
28 29 30 31
import org.maxkey.web.WebContext;
import org.maxkey.web.component.TreeNode;
import org.maxkey.web.component.TreeNodeList;
import org.maxkey.web.message.Message;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
32
import org.maxkey.web.message.MessageScope;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
33
import org.maxkey.web.message.MessageType;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
34
import org.maxkey.web.message.OperateType;
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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({"/orgs"})
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
49
public class OrganizationsController {
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
50 51 52 53 54 55 56 57 58 59 60
  static final Logger _logger = LoggerFactory.getLogger(OrganizationsController.class);

  
  @Autowired
  OrganizationsService organizationsService;

  
  @ResponseBody
  @RequestMapping({"/tree"})
  public List<HashMap<String, Object>> organizationsTree(@RequestParam(value = "id", required = false) String id) {
    _logger.debug("organizationsTree id :" + id);
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
61
    Organizations queryOrg = new Organizations();
M
MaxKey 已提交
62
    List<Organizations> organizationsList = this.organizationsService.queryOrgs(queryOrg);
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
63 64
    TreeNodeList treeNodeList = new TreeNodeList();
    
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
65 66 67
    for (Organizations org : organizationsList) {
      TreeNode treeNode = new TreeNode(org.getId(), org.getName());
      if (org.getHasChild() != null && org.getHasChild().startsWith("Y")) {
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
68 69 70
        treeNode.setHasChild();
      }
      
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
71
      treeNode.setAttr("data", org);
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
72
      treeNode.setPId(org.getParentId());
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
73
      if (org.getId().equals("1")) {
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86
        treeNode.setAttr("open", Boolean.valueOf(true));
      } else {
        treeNode.setAttr("open", Boolean.valueOf(false));
      } 
      treeNodeList.addTreeNode(treeNode.getAttr());
    } 

    
    return treeNodeList.getTreeNodeList();
  }


  
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
87 88 89 90
	@RequestMapping({ "/list" })
	public ModelAndView orgsTreeList() {
		return new ModelAndView("orgs/orgsList");
	}
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
91

MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
92 93 94 95
	@RequestMapping(value = { "/pageresults" })
	@ResponseBody
	public JpaPageResults<Organizations> pageResults(@ModelAttribute("orgs") Organizations orgs) {
		return organizationsService.queryPageResults(orgs);
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
96

MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
97
	}
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
98 99 100 101 102 103 104 105 106 107 108

  
  @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;
  }


MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
109 110 111 112 113 114 115
	@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;
	}
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
116 117 118 119 120 121



  
  @ResponseBody
  @RequestMapping({"/add"})
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
122 123 124 125
  public Message insert(@ModelAttribute("org") Organizations org) {
    _logger.debug("-Add  :" + org);
    if (null == org.getId() || org.getId().equals("")) {
    	org.generateId();
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
126 127
    }
    
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
128
    if (this.organizationsService.insert(org)) {
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
      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"})
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
144 145 146
  public Message query(@ModelAttribute("org") Organizations org) {
    _logger.debug("-query  :" + org);
    if (this.organizationsService.load(org) != null) {
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
147 148 149 150 151 152 153 154 155
      return new Message(WebContext.getI18nValue("message.action.insert.success"), MessageType.success);
    }
    
    return new Message(WebContext.getI18nValue("message.action.insert.error"), MessageType.error);
  }




MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
156 157 158 159 160 161 162 163
	@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;
	}
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
164 165 166 167 168


  
  @ResponseBody
  @RequestMapping({"/update"})
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
169 170 171
  public Message update(@ModelAttribute("org") Organizations org) {
    _logger.debug("-update  organization :" + org);
    if (this.organizationsService.update(org)) {
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 185
      return new Message(WebContext.getI18nValue("message.action.update.success"), MessageType.success);
    }
    
    return new Message(WebContext.getI18nValue("message.action.update.error"), MessageType.error);
  }







  @ResponseBody
  @RequestMapping({"/delete"})
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
186 187
  public Message delete(@ModelAttribute("org") Organizations org) {
    _logger.debug("-delete  organization :" + org);
188
    if (this.organizationsService.batchDelete(org.getId())) {
MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
189 190 191 192 193 194 195 196 197 198 199
      return new Message(WebContext.getI18nValue("message.action.delete.success"), MessageType.success);
    }
    
    return new Message(WebContext.getI18nValue("message.action.delete.success"), MessageType.error);
  }



  
  @RequestMapping({"/orgUsersList"})
  public ModelAndView orgUsersList() { return new ModelAndView("orgs/orgUsersList"); }
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
200 201


MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
202 203 204 205 206 207 208 209 210 211 212 213
  @RequestMapping(value = "/import")
  public ModelAndView importing(@ModelAttribute("excelImportFile")ExcelImport excelImportFile)  {
      ModelAndView modelAndView=new ModelAndView("/orgs/orgsImport");
      
      if (excelImportFile.getExcelFile() != null && !excelImportFile.getExcelFile().isEmpty() && organizationsService.importing(excelImportFile.getExcelFile())) {
           new Message(WebContext.getI18nValue(ConstantsOperateMessage.INSERT_SUCCESS), null, MessageType.success, OperateType.add, MessageScope.DB);
      }else {
           new Message(WebContext.getI18nValue(ConstantsOperateMessage.INSERT_ERROR), MessageType.error);
      }
      
      return modelAndView;
  }
MaxKey单点登录官方's avatar
mgt fix  
MaxKey单点登录官方 已提交
214 215 216 217




MaxKey单点登录官方's avatar
MaxKey单点登录官方 已提交
218
}