项目初始导入
This commit is contained in:
167
src/main/java/com/nis/web/controller/BaseController.java
Normal file
167
src/main/java/com/nis/web/controller/BaseController.java
Normal file
@@ -0,0 +1,167 @@
|
||||
package com.nis.web.controller;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.WebDataBinder;
|
||||
import org.springframework.web.bind.annotation.InitBinder;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
import com.nis.util.DateUtils;
|
||||
import com.nis.util.JsonMapper;
|
||||
import com.nis.web.service.ArchiveServcie;
|
||||
import com.nis.web.service.AreaService;
|
||||
import com.nis.web.service.DictService;
|
||||
import com.nis.web.service.LogService;
|
||||
import com.nis.web.service.MenuService;
|
||||
import com.nis.web.service.OfficeService;
|
||||
import com.nis.web.service.RoleService;
|
||||
import com.nis.web.service.SystemService;
|
||||
import com.nis.web.service.UserService;
|
||||
|
||||
public class BaseController {
|
||||
|
||||
@Autowired
|
||||
protected UserService userService;
|
||||
|
||||
@Autowired
|
||||
protected SystemService systemService;
|
||||
|
||||
@Autowired
|
||||
protected OfficeService officeService;
|
||||
|
||||
@Autowired
|
||||
protected AreaService areaService;
|
||||
|
||||
@Autowired
|
||||
protected RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
protected MenuService menuService;
|
||||
|
||||
@Autowired
|
||||
protected LogService logService;
|
||||
|
||||
@Autowired
|
||||
protected ArchiveServcie archiveServcie;
|
||||
|
||||
@Autowired
|
||||
protected DictService dictService;
|
||||
|
||||
|
||||
protected final Logger logger = Logger.getLogger(this.getClass());
|
||||
|
||||
|
||||
/**
|
||||
* 管理基础路径
|
||||
*/
|
||||
@Value("${adminPath}")
|
||||
protected String adminPath;
|
||||
|
||||
/**
|
||||
* 前端基础路径
|
||||
*/
|
||||
@Value("${frontPath}")
|
||||
protected String frontPath;
|
||||
|
||||
/**
|
||||
* 前端URL后缀
|
||||
*/
|
||||
@Value("${urlSuffix}")
|
||||
protected String urlSuffix;
|
||||
|
||||
|
||||
/**
|
||||
* 客户端返回JSON字符串
|
||||
* @param response
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
protected String renderString(HttpServletResponse response, Object object) {
|
||||
return renderString(response, JsonMapper.toJsonString(object), "application/json");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 客户端返回字符串
|
||||
* @param response
|
||||
* @param string
|
||||
* @return
|
||||
*/
|
||||
protected String renderString(HttpServletResponse response, String string, String type) {
|
||||
try {
|
||||
response.reset();
|
||||
response.setContentType(type);
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.getWriter().print(string);
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加Model消息
|
||||
* @param message
|
||||
*/
|
||||
protected void addMessage(Model model, String... messages) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String message : messages){
|
||||
sb.append(message).append(messages.length>1?"<br/>":"");
|
||||
}
|
||||
model.addAttribute("message", sb.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加Flash消息
|
||||
* @param message
|
||||
*/
|
||||
protected void addMessage(RedirectAttributes redirectAttributes, String... messages) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String message : messages){
|
||||
sb.append(message).append(messages.length>1?"<br/>":"");
|
||||
}
|
||||
redirectAttributes.addFlashAttribute("message", sb.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化数据绑定
|
||||
* 1. 将所有传递进来的String进行HTML编码,防止XSS攻击
|
||||
* 2. 将字段中Date类型转换为String类型
|
||||
*/
|
||||
@InitBinder
|
||||
protected void initBinder(WebDataBinder binder) {
|
||||
// String类型转换,将所有传递进来的String进行HTML编码,防止XSS攻击
|
||||
binder.registerCustomEditor(String.class, new PropertyEditorSupport() {
|
||||
@Override
|
||||
public void setAsText(String text) {
|
||||
setValue(text == null ? null : StringEscapeUtils.escapeHtml4(text.trim()));
|
||||
}
|
||||
@Override
|
||||
public String getAsText() {
|
||||
Object value = getValue();
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
});
|
||||
// Date 类型转换
|
||||
binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
|
||||
@Override
|
||||
public void setAsText(String text) {
|
||||
setValue(DateUtils.parseDate(text));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
72
src/main/java/com/nis/web/controller/CKFinderConfig.java
Normal file
72
src/main/java/com/nis/web/controller/CKFinderConfig.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* Copyright © 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
|
||||
*/
|
||||
package com.nis.web.controller;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
||||
import com.ckfinder.connector.configuration.Configuration;
|
||||
import com.ckfinder.connector.data.AccessControlLevel;
|
||||
import com.ckfinder.connector.utils.AccessControlUtil;
|
||||
import com.nis.util.Configurations;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.FileUtils;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.web.security.Servlets;
|
||||
import com.nis.web.security.SystemAuthorizingRealm.Principal;
|
||||
import com.nis.web.security.UserUtils;
|
||||
|
||||
/**
|
||||
* CKFinder配置
|
||||
* @author ThinkGem
|
||||
* @version 2014-06-25
|
||||
*/
|
||||
public class CKFinderConfig extends Configuration {
|
||||
|
||||
public CKFinderConfig(ServletConfig servletConfig) {
|
||||
super(servletConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Configuration createConfigurationInstance() {
|
||||
Principal principal = (Principal) UserUtils.getPrincipal();
|
||||
if (principal == null){
|
||||
return new CKFinderConfig(this.servletConf);
|
||||
}
|
||||
boolean isView = true;//UserUtils.getSubject().isPermitted("cms:ckfinder:view");
|
||||
boolean isUpload = true;//UserUtils.getSubject().isPermitted("cms:ckfinder:upload");
|
||||
boolean isEdit = true;//UserUtils.getSubject().isPermitted("cms:ckfinder:edit");
|
||||
AccessControlLevel alc = this.getAccessConrolLevels().get(0);
|
||||
alc.setFolderView(isView);
|
||||
alc.setFolderCreate(isEdit);
|
||||
alc.setFolderRename(isEdit);
|
||||
alc.setFolderDelete(isEdit);
|
||||
alc.setFileView(isView);
|
||||
alc.setFileUpload(isUpload);
|
||||
alc.setFileRename(isEdit);
|
||||
alc.setFileDelete(isEdit);
|
||||
// for (AccessControlLevel a : this.getAccessConrolLevels()){
|
||||
// System.out.println(a.getRole()+", "+a.getResourceType()+", "+a.getFolder()
|
||||
// +", "+a.isFolderView()+", "+a.isFolderCreate()+", "+a.isFolderRename()+", "+a.isFolderDelete()
|
||||
// +", "+a.isFileView()+", "+a.isFileUpload()+", "+a.isFileRename()+", "+a.isFileDelete());
|
||||
// }
|
||||
AccessControlUtil.getInstance(this).loadACLConfig();
|
||||
try {
|
||||
// Principal principal = (Principal)SecurityUtils.getSubject().getPrincipal();
|
||||
// this.baseURL = ServletContextFactory.getServletContext().getContextPath()+"/userfiles/"+principal+"/";
|
||||
this.baseURL = FileUtils.path(Servlets.getRequest().getContextPath() + "/" + Configurations.getStringProperty("userfiles.basedir","") + Constants.USERFILES_BASE_URL + principal + "/");
|
||||
this.baseDir = FileUtils.path(StringUtils.getUserfilesBaseDir() + Constants.USERFILES_BASE_URL + principal + "/");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return new CKFinderConfig(this.servletConf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkAuthentication(final HttpServletRequest request) {
|
||||
return UserUtils.getPrincipal()!=null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright © 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
|
||||
*/
|
||||
package com.nis.web.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ckfinder.connector.ConnectorServlet;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.FileUtils;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.web.security.SystemAuthorizingRealm.Principal;
|
||||
import com.nis.web.security.UserUtils;
|
||||
|
||||
|
||||
/**
|
||||
* CKFinderConnectorServlet
|
||||
* @author ThinkGem
|
||||
* @version 2014-06-25
|
||||
*/
|
||||
public class CKFinderConnectorServlet extends ConnectorServlet {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException, IOException {
|
||||
prepareGetResponse(request, response, false);
|
||||
response.setContentType("text/html;charset=UTF-8");
|
||||
super.doGet(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request,
|
||||
HttpServletResponse response) throws ServletException, IOException {
|
||||
prepareGetResponse(request, response, true);
|
||||
response.setContentType("text/html;charset=UTF-8");
|
||||
super.doPost(request, response);
|
||||
}
|
||||
|
||||
private void prepareGetResponse(final HttpServletRequest request,
|
||||
final HttpServletResponse response, final boolean post) throws ServletException {
|
||||
Principal principal = (Principal) UserUtils.getPrincipal();
|
||||
if (principal == null){
|
||||
return;
|
||||
}
|
||||
String command = request.getParameter("command");
|
||||
String type = request.getParameter("type");
|
||||
// 初始化时,如果startupPath文件夹不存在,则自动创建startupPath文件夹
|
||||
if ("Init".equals(command)){
|
||||
String startupPath = request.getParameter("startupPath");// 当前文件夹可指定为模块名
|
||||
if (startupPath!=null){
|
||||
String[] ss = startupPath.split(":");
|
||||
if (ss.length==2){
|
||||
String realPath = StringUtils.getUserfilesBaseDir() + Constants.USERFILES_BASE_URL
|
||||
+ principal + "/" + ss[0] + ss[1];
|
||||
FileUtils.createDirectory(FileUtils.path(realPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
// 快捷上传,自动创建当前文件夹,并上传到该路径
|
||||
else if ("QuickUpload".equals(command) && type!=null){
|
||||
String currentFolder = request.getParameter("currentFolder");// 当前文件夹可指定为模块名
|
||||
String realPath = StringUtils.getUserfilesBaseDir() + Constants.USERFILES_BASE_URL
|
||||
+ principal + "/" + type + (currentFolder != null ? currentFolder : "");
|
||||
FileUtils.createDirectory(FileUtils.path(realPath));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.nis.web.controller;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.google.code.kaptcha.Constants;
|
||||
import com.google.code.kaptcha.Producer;
|
||||
|
||||
@Controller
|
||||
public class CaptchaProducerController {
|
||||
@Autowired
|
||||
private Producer captchaProducer;
|
||||
|
||||
|
||||
@RequestMapping("captcha-image")
|
||||
public ModelAndView handleRequest(HttpServletRequest request,HttpServletResponse response) throws IOException{
|
||||
|
||||
// Set to expire far in the past.
|
||||
response.setDateHeader("Expires", 0);
|
||||
// Set standard HTTP/1.1 no-cache headers.
|
||||
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
|
||||
// Set IE extended HTTP/1.1 no-cache headers (use addHeader).
|
||||
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
|
||||
// Set standard HTTP/1.0 no-cache header.
|
||||
response.setHeader("Pragma", "no-cache");
|
||||
|
||||
// return a jpeg
|
||||
response.setContentType("image/jpeg");
|
||||
|
||||
// create the text for the image
|
||||
String capText = captchaProducer.createText();
|
||||
|
||||
// store the text in the session
|
||||
request.getSession().setAttribute(Constants.KAPTCHA_SESSION_KEY, capText.toUpperCase());
|
||||
|
||||
// create the image with the text
|
||||
BufferedImage bi = captchaProducer.createImage(capText);
|
||||
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
|
||||
// write the data out
|
||||
ImageIO.write(bi, "jpg", out);
|
||||
try
|
||||
{
|
||||
out.flush();
|
||||
}
|
||||
finally
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
210
src/main/java/com/nis/web/controller/LoginController.java
Normal file
210
src/main/java/com/nis/web/controller/LoginController.java
Normal file
@@ -0,0 +1,210 @@
|
||||
package com.nis.web.controller;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.UnauthorizedException;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
|
||||
import org.apache.shiro.web.util.WebUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import com.nis.util.Configurations;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.CookieUtil;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.web.security.IdGen;
|
||||
import com.nis.web.security.SystemAuthorizingRealm.Principal;
|
||||
import com.nis.web.security.UserUtils;
|
||||
import com.nis.web.service.SystemService;
|
||||
|
||||
@Controller
|
||||
public class LoginController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private SystemService systemService;
|
||||
|
||||
|
||||
/**
|
||||
* 默认进入系统动作,即跳转登录操作
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="login",method=RequestMethod.GET)
|
||||
public String login(HttpServletRequest request, HttpServletResponse response, Model model){
|
||||
Principal principal = UserUtils.getPrincipal();
|
||||
|
||||
logger.debug("login, active session size: {}"+systemService.getActiveSessions(false).size());
|
||||
|
||||
if (Constants.TRUE.equals(Configurations.getStringProperty("notAllowRefreshIndex", "false"))) {
|
||||
try {
|
||||
CookieUtil.addCookie(response, "LOGINED", "false");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 如果已经登录,则跳转到管理首页
|
||||
if(principal != null && !principal.isMobileLogin()){
|
||||
return "redirect:" + adminPath + "/index";
|
||||
}
|
||||
|
||||
return "login";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 登录失败时调用的方法,真正登录方法在shiro filter时实现。
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="login",method=RequestMethod.POST)
|
||||
public String loginFail(HttpServletRequest request, HttpServletResponse response, Model model){
|
||||
|
||||
Principal principal = UserUtils.getPrincipal();
|
||||
// 如果已经登录,则跳转到管理首页
|
||||
if(principal != null){
|
||||
return "redirect:" + adminPath + "/index";
|
||||
}
|
||||
|
||||
String username = WebUtils.getCleanParam(request, FormAuthenticationFilter.DEFAULT_USERNAME_PARAM);
|
||||
boolean rememberMe = WebUtils.isTrue(request, FormAuthenticationFilter.DEFAULT_REMEMBER_ME_PARAM);
|
||||
boolean mobile = WebUtils.isTrue(request, Constants.DEFAULT_MOBILE_PARAM);
|
||||
String exception = (String)request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
|
||||
String message = (String)request.getAttribute(Constants.DEFAULT_MESSAGE_PARAM);
|
||||
|
||||
if (StringUtils.isBlank(message) || StringUtils.equals(message, "null")){
|
||||
message = "用户或密码错误, 请重试!";
|
||||
}
|
||||
|
||||
model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, username);
|
||||
model.addAttribute(FormAuthenticationFilter.DEFAULT_REMEMBER_ME_PARAM, rememberMe);
|
||||
model.addAttribute(Constants.DEFAULT_MOBILE_PARAM, mobile);
|
||||
model.addAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME, exception);
|
||||
model.addAttribute(Constants.DEFAULT_MESSAGE_PARAM, message);
|
||||
|
||||
if (logger.isDebugEnabled()){
|
||||
logger.debug("login fail, active session size: "+systemService.getActiveSessions(false).size()+", message: "+message+", exception: "+exception);
|
||||
}
|
||||
|
||||
// 非授权异常,登录失败,验证码加1。
|
||||
if (!UnauthorizedException.class.getName().equals(exception)){
|
||||
model.addAttribute("isValidateCodeLogin", UserUtils.isValidateCodeLogin(username, true, false));
|
||||
}
|
||||
|
||||
// 验证失败清空验证码
|
||||
request.getSession().setAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY, IdGen.uuid());
|
||||
|
||||
// 如果是手机登录,则返回JSON字符串
|
||||
if (mobile){
|
||||
return renderString(response, model);
|
||||
}
|
||||
|
||||
return "login";
|
||||
}
|
||||
|
||||
@RequiresPermissions("user")
|
||||
@RequestMapping("/nis/index")
|
||||
public String index(HttpServletRequest request, HttpServletResponse response,ModelMap model){
|
||||
Principal principal = UserUtils.getPrincipal();
|
||||
// 登录成功后,验证码计算器清零
|
||||
UserUtils.isValidateCodeLogin(principal.getLoginName(), false, true);
|
||||
|
||||
if (logger.isDebugEnabled()){
|
||||
logger.debug("show index, active session size: {}"+ systemService.getActiveSessions(false).size());
|
||||
}
|
||||
|
||||
// 如果已登录,再次访问主页,则退出原账号。
|
||||
if (Constants.TRUE.equals(Configurations.getStringProperty("notAllowRefreshIndex","false"))){
|
||||
|
||||
String logined;
|
||||
try {
|
||||
logined = CookieUtil.getValue(request, "LOGINED");
|
||||
if (StringUtils.isBlank(logined) || "false".equals(logined)){
|
||||
CookieUtil.addCookie(response, "LOGINED", "true");
|
||||
}else if (StringUtils.equals(logined, "true")){
|
||||
UserUtils.getSubject().logout();
|
||||
return "redirect:" + "/login";
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 如果是手机登录,则返回JSON字符串
|
||||
if (principal.isMobileLogin()){
|
||||
if (request.getParameter("login") != null){
|
||||
return renderString(response, principal);
|
||||
}
|
||||
if (request.getParameter("index") != null){
|
||||
return "home";
|
||||
}
|
||||
return "redirect:" + "/login";
|
||||
}
|
||||
|
||||
model.addAttribute("adminPath", adminPath);
|
||||
return "/home";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取主题方案
|
||||
*/
|
||||
@RequestMapping(value = "/theme/{theme}")
|
||||
public String getThemeInCookie(@PathVariable String theme, HttpServletRequest request, HttpServletResponse response){
|
||||
try {
|
||||
|
||||
if (StringUtils.isNotBlank(theme)){
|
||||
CookieUtil.addCookie(response, "theme", theme);
|
||||
}else{
|
||||
theme = CookieUtil.getValue(request, "theme");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "redirect:"+request.getParameter("url");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改权限组
|
||||
*/
|
||||
@RequestMapping(value = "/permission/{roleId}")
|
||||
public String switchPermissionGroup(@PathVariable String roleId, HttpServletRequest request, HttpServletResponse response){
|
||||
try {
|
||||
|
||||
if (StringUtils.isNotBlank(roleId)){
|
||||
System.out.println("*****************");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "redirect:"+request.getParameter("url");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value="/validateCode")
|
||||
public void validateCode(HttpServletRequest request, HttpServletResponse response,String captcha) {
|
||||
renderString(response, UserUtils.validateCodeIsValid(captcha));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
20
src/main/java/com/nis/web/controller/SystemController.java
Normal file
20
src/main/java/com/nis/web/controller/SystemController.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.nis.web.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@RequestMapping("${adminPath}/sys/")
|
||||
public class SystemController extends BaseController{
|
||||
|
||||
@RequestMapping("index")
|
||||
public String index(HttpServletRequest request, HttpServletResponse response,ModelMap model){
|
||||
return "/sys/sysIndex";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
41
src/main/java/com/nis/web/controller/TagController.java
Normal file
41
src/main/java/com/nis/web/controller/TagController.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.nis.web.controller;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping("${adminPath}/tag")
|
||||
public class TagController extends BaseController {
|
||||
|
||||
/**
|
||||
* 树结构选择标签(treeselect.tag)
|
||||
*/
|
||||
@RequiresPermissions("user")
|
||||
@RequestMapping(value = "treeselect")
|
||||
public String treeselect(HttpServletRequest request, Model model) {
|
||||
model.addAttribute("url", request.getParameter("url")); // 树结构数据URL
|
||||
model.addAttribute("extId", request.getParameter("extId")); // 排除的编号ID
|
||||
model.addAttribute("checked", request.getParameter("checked")); // 是否可复选
|
||||
model.addAttribute("selectIds", request.getParameter("selectIds")); // 指定默认选中的ID
|
||||
model.addAttribute("isAll", request.getParameter("isAll")); // 是否读取全部数据,不进行权限过滤
|
||||
model.addAttribute("module", request.getParameter("module")); // 过滤栏目模型(仅针对CMS的Category树)
|
||||
return "/sys/tagTreeselect";
|
||||
}
|
||||
|
||||
/**
|
||||
* 图标选择标签(iconselect.tag)
|
||||
*/
|
||||
@RequiresPermissions("user")
|
||||
@RequestMapping(value = "iconselect")
|
||||
public String iconselect(HttpServletRequest request, Model model) {
|
||||
model.addAttribute("value", request.getParameter("value"));
|
||||
return "/sys/tagIconselect";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
115
src/main/java/com/nis/web/controller/sys/AreaController.java
Normal file
115
src/main/java/com/nis/web/controller/sys/AreaController.java
Normal file
@@ -0,0 +1,115 @@
|
||||
package com.nis.web.controller.sys;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
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.mvc.support.RedirectAttributes;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.nis.domain.SysArea;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.web.controller.BaseController;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("${adminPath}/sys/area")
|
||||
public class AreaController extends BaseController {
|
||||
|
||||
|
||||
@ModelAttribute
|
||||
public SysArea get(@RequestParam(required=false) Long id) {
|
||||
if (!StringUtil.isEmpty(id)){
|
||||
return areaService.get(id);
|
||||
}else{
|
||||
return new SysArea();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("sys:area:view")
|
||||
@RequestMapping("index")
|
||||
public String index(SysArea area, Model model) {
|
||||
|
||||
return "/sys/areaIndex";
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("sys:area:view")
|
||||
@RequestMapping(value = {"list"})
|
||||
public String list(SysArea sysArea, Model model) {
|
||||
model.addAttribute("list", areaService.findAllAreaList(sysArea));
|
||||
return "/sys/areaList";
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("sys:area:view")
|
||||
@RequestMapping(value = "form")
|
||||
public String form(SysArea area, Model model) {
|
||||
|
||||
if (!StringUtil.isEmpty(area.getParent().getId())) {
|
||||
area.setParent(areaService.get(area.getParent().getId()));
|
||||
}
|
||||
model.addAttribute("area", area);
|
||||
return "/sys/areaForm";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@RequiresPermissions("sys:area:edit")
|
||||
@RequestMapping(value = "saveOrUpdate")
|
||||
public String saveOrUpdate(SysArea sysArea, Model model, RedirectAttributes redirectAttributes) {
|
||||
areaService.saveOrUpdate(sysArea);
|
||||
addMessage(redirectAttributes, "保存区域'" + sysArea.getName() + "'成功");
|
||||
String id = sysArea.getParentId().equals(0l) ? "" : String.valueOf(sysArea.getParentId());
|
||||
|
||||
return "redirect:" + adminPath + "/sys/area/list?id="+id+"&parentIds="+sysArea.getParent().getParentIds();
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("sys:area:edit")
|
||||
@RequestMapping(value = "delete")
|
||||
public String delete(SysArea area, RedirectAttributes redirectAttributes) {
|
||||
areaService.delete(area);
|
||||
|
||||
addMessage(redirectAttributes, "删除区域成功");
|
||||
|
||||
return "redirect:" + adminPath + "/sys/area/list?id="+area.getParentId()+"&parentIds="+area.getParent().getParentIds();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequiresPermissions("user")
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "treeData")
|
||||
public List<Map<String, Object>> treeData(@RequestParam(required=false) String extId, HttpServletResponse response) {
|
||||
List<Map<String, Object>> mapList = Lists.newArrayList();
|
||||
List<SysArea> list = areaService.findAll();
|
||||
for (int i=0; i<list.size(); i++){
|
||||
SysArea e = list.get(i);
|
||||
if (StringUtils.isBlank(extId) || (extId!=null && !extId.equals(e.getId()) && e.getParentIds().indexOf(","+extId+",")==-1)){
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
map.put("id", e.getId());
|
||||
map.put("pId", e.getParentId());
|
||||
map.put("pIds", e.getParentIds());
|
||||
map.put("name", e.getName());
|
||||
mapList.add(map);
|
||||
}
|
||||
}
|
||||
return mapList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
101
src/main/java/com/nis/web/controller/sys/DictController.java
Normal file
101
src/main/java/com/nis/web/controller/sys/DictController.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package com.nis.web.controller.sys;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
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.mvc.support.RedirectAttributes;
|
||||
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.SysDataDictionaryName;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.web.controller.BaseController;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "${adminPath}/sys/dict")
|
||||
public class DictController extends BaseController {
|
||||
|
||||
|
||||
@ModelAttribute
|
||||
public SysDataDictionaryName get(@RequestParam(required=false) Integer id) {
|
||||
if (!StringUtil.isEmpty(id)){
|
||||
return dictService.getDictByIdWithRelation(id);
|
||||
}else{
|
||||
return new SysDataDictionaryName();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@RequiresPermissions("sys:dict:view")
|
||||
@RequestMapping(value = {"list", ""})
|
||||
public String list(SysDataDictionaryName sysDictName,HttpServletRequest request, HttpServletResponse response, Model model) {
|
||||
|
||||
Page<SysDataDictionaryName> page = dictService.findDictList(new Page<SysDataDictionaryName>(request, response), sysDictName);
|
||||
model.addAttribute("page", page);
|
||||
|
||||
return "/sys/dictList";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 进入字典添加或修改页面
|
||||
* @param sysDictName
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value={"form"})
|
||||
public String form(SysDataDictionaryName sysDictName, Model model) {
|
||||
|
||||
return "/sys/dictForm";
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("sys:dict:edit")
|
||||
@RequestMapping(value = "saveOrUpdate")
|
||||
public String saveOrUpdate(SysDataDictionaryName sysDictName,Model model, RedirectAttributes redirectAttributes) {
|
||||
|
||||
try {
|
||||
dictService.saveOrUpdate(sysDictName);
|
||||
addMessage(redirectAttributes, "保存字典成功");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
addMessage(redirectAttributes, "保存字典失败!");
|
||||
}
|
||||
|
||||
return "redirect:" + adminPath + "/sys/dict/list";
|
||||
}
|
||||
|
||||
@RequiresPermissions("sys:dict:edit")
|
||||
@RequestMapping(value = "delete")
|
||||
public String delete(Integer id,Model model, RedirectAttributes redirectAttributes) {
|
||||
|
||||
try {
|
||||
dictService.deleteDict(id);
|
||||
addMessage(redirectAttributes, "删除字典成功");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
addMessage(redirectAttributes, "删除字典失败!");
|
||||
}
|
||||
|
||||
|
||||
return "redirect:" + adminPath + "/sys/dict/list";
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "loadDataDict")
|
||||
public SysDataDictionaryName loadDataDict(@RequestParam(required=false) Integer id,HttpServletRequest request, HttpServletResponse response, Model model){
|
||||
|
||||
return dictService.getDictByIdWithRelation(id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.nis.web.controller.sys;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.nis.domain.SrcIp;
|
||||
import com.nis.web.controller.BaseController;
|
||||
@Controller
|
||||
@RequestMapping("${adminPath}/sys/ipLocation")
|
||||
public class IpLocationController extends BaseController{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 进入首页IP定位
|
||||
* @param office
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("index")
|
||||
public String index(Model model) {
|
||||
|
||||
return "/sys/ipLocation";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检索获取当前位置信息
|
||||
* @param srcIp
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("search")
|
||||
public String search(SrcIp srcIp, Model model) {
|
||||
systemService.ipLookUp(srcIp.getSearchIp()).get(0);
|
||||
|
||||
return "/sys/iplocationResult";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
143
src/main/java/com/nis/web/controller/sys/MenuController.java
Normal file
143
src/main/java/com/nis/web/controller/sys/MenuController.java
Normal file
@@ -0,0 +1,143 @@
|
||||
package com.nis.web.controller.sys;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
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.mvc.support.RedirectAttributes;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.nis.domain.SysMenu;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.web.controller.BaseController;
|
||||
import com.nis.web.security.UserUtils;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("${adminPath}/sys/menu")
|
||||
public class MenuController extends BaseController {
|
||||
|
||||
@ModelAttribute("sysMenu")
|
||||
public SysMenu get(@RequestParam(required=false) Long id) {
|
||||
if (!StringUtil.isEmpty(id)){
|
||||
return menuService.getMenu(id);
|
||||
}else{
|
||||
return new SysMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresPermissions("sys:menu:view")
|
||||
@RequestMapping(value = {"list", ""})
|
||||
public String list(Model model) {
|
||||
List<SysMenu> list = Lists.newArrayList();
|
||||
List<SysMenu> sourcelist = menuService.findAllMenu();
|
||||
SysMenu.sortList(list, sourcelist, SysMenu.getRootId(), true);
|
||||
model.addAttribute("list", list);
|
||||
return "/sys/menuList";
|
||||
}
|
||||
|
||||
@RequiresPermissions("sys:menu:view")
|
||||
@RequestMapping(value = "form")
|
||||
public String form(SysMenu menu, Model model) {
|
||||
if (menu.getParent() == null || menu.getParent().getId() == null) {
|
||||
menu.setParent(new SysMenu(SysMenu.getRootId()));
|
||||
}
|
||||
menu.setParent(menuService.getMenu(menu.getParent().getId()));
|
||||
// 获取排序号,最末节点排序号+30
|
||||
if (StringUtil.isEmpty(menu.getId())) {
|
||||
List<SysMenu> list = Lists.newArrayList();
|
||||
List<SysMenu> sourcelist = menuService.findAllMenu();
|
||||
SysMenu.sortList(list, sourcelist, menu.getParentId(), false);
|
||||
if (list.size() > 0){
|
||||
menu.setSort(list.get(list.size()-1).getSort() + 30);
|
||||
}
|
||||
}
|
||||
model.addAttribute("menu", menu);
|
||||
return "/sys/menuForm";
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("sys:menu:edit")
|
||||
@RequestMapping(value = "saveOrUpdate")
|
||||
public String saveOrUpdate(SysMenu menu, Model model, RedirectAttributes redirectAttributes) {
|
||||
if(!UserUtils.getUser().isAdmin()){
|
||||
addMessage(redirectAttributes, "越权操作,只有超级管理员才能添加或修改数据!");
|
||||
return "redirect:" + adminPath + "/sys/role/?repage";
|
||||
}
|
||||
|
||||
menuService.saveOrUpdateMenu(menu);
|
||||
addMessage(redirectAttributes, "保存菜单'" + menu.getName() + "'成功");
|
||||
return "redirect:" + adminPath + "/sys/menu/";
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("sys:menu:edit")
|
||||
@RequestMapping(value = "delete")
|
||||
public String delete(SysMenu menu, RedirectAttributes redirectAttributes) {
|
||||
|
||||
// if (Menu.isRoot(id)){
|
||||
// addMessage(redirectAttributes, "删除菜单失败, 不允许删除顶级菜单或编号为空");
|
||||
// }else{
|
||||
menuService.deleteMenu(menu);
|
||||
addMessage(redirectAttributes, "删除菜单成功");
|
||||
// }
|
||||
return "redirect:" + adminPath + "/sys/menu/";
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改菜单排序
|
||||
*/
|
||||
@RequiresPermissions("sys:menu:edit")
|
||||
@RequestMapping(value = "updateSort")
|
||||
public String updateSort(Long[] ids, Integer[] sorts, RedirectAttributes redirectAttributes) {
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
SysMenu menu = new SysMenu(ids[i]);
|
||||
menu.setSort(sorts[i]);
|
||||
menuService.updateMenuSort(menu);
|
||||
}
|
||||
addMessage(redirectAttributes, "保存菜单排序成功!");
|
||||
return "redirect:" + adminPath + "/sys/menu/";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* isShowHide是否显示隐藏菜单
|
||||
* @param extId
|
||||
* @param isShowHidden
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("user")
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "treeData")
|
||||
public List<Map<String, Object>> treeData(@RequestParam(required=false) String extId,@RequestParam(required=false) String isShowHide, HttpServletResponse response) {
|
||||
List<Map<String, Object>> mapList = Lists.newArrayList();
|
||||
List<SysMenu> list = menuService.findAllMenu();
|
||||
for (int i=0; i<list.size(); i++){
|
||||
SysMenu menu = list.get(i);
|
||||
if (StringUtils.isBlank(extId) || (extId !=null && !extId.equals(menu.getId()) && menu.getParentIds().indexOf(","+extId+",") == -1)) {
|
||||
if(isShowHide != null && isShowHide.equals("0") && menu.getIsShow().equals(0)){
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
map.put("id", menu.getId());
|
||||
map.put("pId", menu.getParentId());
|
||||
map.put("name",menu.getName());
|
||||
mapList.add(map);
|
||||
}
|
||||
}
|
||||
return mapList;
|
||||
}
|
||||
|
||||
}
|
||||
163
src/main/java/com/nis/web/controller/sys/OfficeController.java
Normal file
163
src/main/java/com/nis/web/controller/sys/OfficeController.java
Normal file
@@ -0,0 +1,163 @@
|
||||
package com.nis.web.controller.sys;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
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.mvc.support.RedirectAttributes;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.nis.domain.SysOffice;
|
||||
import com.nis.domain.SysUser;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.web.controller.BaseController;
|
||||
import com.nis.web.security.UserUtils;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("${adminPath}/sys/office")
|
||||
public class OfficeController extends BaseController {
|
||||
|
||||
@ModelAttribute
|
||||
public SysOffice get(@RequestParam(required=false) Long id) {
|
||||
if (!StringUtil.isEmpty(id)){
|
||||
return officeService.get(id);
|
||||
}else{
|
||||
return new SysOffice();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 进入机构首页
|
||||
* @param office
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:office:view")
|
||||
@RequestMapping("")
|
||||
public String index(SysOffice office,Model model) {
|
||||
|
||||
return "/sys/officeIndex";
|
||||
}
|
||||
|
||||
@RequiresPermissions("sys:office:view")
|
||||
@RequestMapping("list")
|
||||
public String list(SysOffice sysOffice, Model model) {
|
||||
|
||||
model.addAttribute("list", officeService.findAllOfficeList(sysOffice));
|
||||
return "/sys/officeList";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@RequiresPermissions("sys:office:view")
|
||||
@RequestMapping(value = "form")
|
||||
public String form(SysOffice office, Model model) {
|
||||
SysUser user = UserUtils.getUser();
|
||||
if (office.getParent() == null || office.getParent().getId() == null){
|
||||
office.setParent(user.getOffice());
|
||||
} else {
|
||||
office.setParent(officeService.get(office.getParent().getId()));
|
||||
}
|
||||
|
||||
if (office.getArea() == null) {
|
||||
office.setArea(user.getOffice().getArea());
|
||||
}
|
||||
// 自动获取排序号
|
||||
if (StringUtil.isEmpty(office.getId()) && office.getParent() != null) {
|
||||
int size = 0;
|
||||
List<SysOffice> list = officeService.findAll();
|
||||
for (int i=0; i<list.size(); i++){
|
||||
SysOffice e = list.get(i);
|
||||
if (e.getParent() != null && e.getParent().getId() !=null
|
||||
&& e.getParent().getId().equals(office.getParent().getId())){
|
||||
size++;
|
||||
}
|
||||
}
|
||||
office.setCode(office.getParent().getCode() + StringUtils.leftPad(String.valueOf(size > 0 ? size+1 : 1), 3, "0"));
|
||||
}
|
||||
model.addAttribute("office", office);
|
||||
return "/sys/officeForm";
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("sys:office:edit")
|
||||
@RequestMapping(value = "saveOrUpdate")
|
||||
public String saveOrUpdate(SysOffice office, Model model, RedirectAttributes redirectAttributes) {
|
||||
|
||||
officeService.saveOrUpdate(office);
|
||||
addMessage(redirectAttributes, "保存机构'" + office.getName() + "'成功");
|
||||
String id = office.getParentId().equals(0l) ? "" : String.valueOf(office.getParentId());
|
||||
|
||||
return "redirect:" + adminPath + "/sys/office/list?id="+id+"&parentIds="+office.getParentIds();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequiresPermissions("sys:office:edit")
|
||||
@RequestMapping(value = "delete")
|
||||
public String delete(SysOffice office, RedirectAttributes redirectAttributes) {
|
||||
// if (Office.isRoot(id)){
|
||||
// addMessage(redirectAttributes, "删除机构失败, 不允许删除顶级机构或编号空");
|
||||
// }else{
|
||||
officeService.delete(office);
|
||||
addMessage(redirectAttributes, "删除机构成功");
|
||||
// }
|
||||
String id = office.getParentId().equals(0l) ? "" : String.valueOf(office.getParentId());
|
||||
|
||||
return "redirect:" + adminPath + "/sys/office/list?id="+id+"&parentIds="+office.getParentIds();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取机构JSON数据。
|
||||
* @param extId 排除的ID
|
||||
* @param type 类型(1:公司;2 :单位;3:部门;4:信访办;5:其它;6:携带用户)
|
||||
* @param grade 显示级别
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("user")
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "treeData")
|
||||
public List<Map<String, Object>> treeData(@RequestParam(required=false) String extId, @RequestParam(required=false) String type,
|
||||
@RequestParam(required=false) Long grade, @RequestParam(required=false) Boolean isAll, HttpServletResponse response) {
|
||||
List<Map<String, Object>> mapList = Lists.newArrayList();
|
||||
List<SysOffice> list = officeService.findList(isAll);
|
||||
for (int i=0; i<list.size(); i++){
|
||||
SysOffice e = list.get(i);
|
||||
if ((StringUtils.isBlank(extId) || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf(","+extId+",") == -1))
|
||||
&& (type == null || (type != null && e.getType() <= Integer.valueOf(type)))
|
||||
&& (grade == null || (grade != null && e.getGrade() <= grade.intValue()))){
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
map.put("id", e.getId());
|
||||
map.put("pId", e.getParentId());
|
||||
map.put("pIds", e.getParentIds());
|
||||
map.put("name", e.getName());
|
||||
if (type != null && "6".equals(type)){
|
||||
map.put("isParent", true);
|
||||
}
|
||||
mapList.add(map);
|
||||
}
|
||||
}
|
||||
return mapList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
212
src/main/java/com/nis/web/controller/sys/RoleController.java
Normal file
212
src/main/java/com/nis/web/controller/sys/RoleController.java
Normal file
@@ -0,0 +1,212 @@
|
||||
package com.nis.web.controller.sys;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
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.mvc.support.RedirectAttributes;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.nis.domain.SysRole;
|
||||
import com.nis.domain.SysUser;
|
||||
import com.nis.util.Collections3;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.web.controller.BaseController;
|
||||
import com.nis.web.security.UserUtils;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "${adminPath}/sys/role")
|
||||
public class RoleController extends BaseController {
|
||||
|
||||
@ModelAttribute("sysRole")
|
||||
public SysRole get(@RequestParam(required=false) Long id) {
|
||||
if (!StringUtil.isEmpty(id)){
|
||||
return roleService.getRole(id);
|
||||
}else{
|
||||
return new SysRole();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("sys:role:view")
|
||||
@RequestMapping(value = {"list", ""})
|
||||
public String list(SysRole role, Model model) {
|
||||
List<SysRole> list = roleService.findAllRole();
|
||||
model.addAttribute("list", list);
|
||||
return "/sys/roleList";
|
||||
}
|
||||
|
||||
@RequiresPermissions("sys:role:view")
|
||||
@RequestMapping(value = "form")
|
||||
public String form(SysRole role, Model model) {
|
||||
|
||||
model.addAttribute("role", role);
|
||||
model.addAttribute("menuList", menuService.findAllMenu());
|
||||
return "/sys/roleForm";
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色分配页面
|
||||
* @param role
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:role:edit")
|
||||
@RequestMapping(value = "assign")
|
||||
public String assign(SysRole role, Model model) {
|
||||
List<SysUser> userList = userService.findUserByRoleId(role.getId());
|
||||
model.addAttribute("userList", userList);
|
||||
return "/sys/roleAssign";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 角色分配 -- 打开角色分配对话框
|
||||
* @param role
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:role:view")
|
||||
@RequestMapping(value = "usertorole")
|
||||
public String selectUserToRole(SysRole role, Model model) {
|
||||
List<SysUser> userList = userService.findUserByRoleId(role.getId());
|
||||
model.addAttribute("role", role);
|
||||
model.addAttribute("userList", userList);
|
||||
model.addAttribute("selectIds", Collections3.extractToString(userList, "id", ","));
|
||||
model.addAttribute("officeList", officeService.findAll());
|
||||
return "/sys/selectUserToRole";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 角色分配 -- 根据部门编号获取用户列表
|
||||
* @param officeId
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:role:view")
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "users")
|
||||
public List<Map<String, Object>> users(Long officeId, HttpServletResponse response) {
|
||||
List<Map<String, Object>> mapList = Lists.newArrayList();
|
||||
List<SysUser> userList = userService.findUserByOfficeId(officeId);
|
||||
for (SysUser e : userList) {
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
map.put("id", e.getId());
|
||||
map.put("pId", 0);
|
||||
map.put("name", e.getName());
|
||||
mapList.add(map);
|
||||
}
|
||||
return mapList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色分配
|
||||
* @param role
|
||||
* @param idsArr
|
||||
* @param redirectAttributes
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:role:edit")
|
||||
@RequestMapping(value = "assignrole")
|
||||
public String assignRole(SysRole role, String[] idsArr, RedirectAttributes redirectAttributes) {
|
||||
|
||||
StringBuilder msg = new StringBuilder();
|
||||
int newNum = 0;
|
||||
for (int i = 0; i < idsArr.length; i++) {
|
||||
|
||||
SysUser user = systemService.assignUserToRole(role, userService.getUser(idsArr[i]));
|
||||
|
||||
if (null != user) {
|
||||
msg.append("<br/>新增用户【" + user.getName() + "】到角色【" + role.getName() + "】!");
|
||||
newNum++;
|
||||
}
|
||||
}
|
||||
addMessage(redirectAttributes, "已成功分配 "+newNum+" 个用户"+msg);
|
||||
return "redirect:" + adminPath + "/sys/role/assign?id="+role.getId();
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("sys:role:edit")
|
||||
@RequestMapping(value = "saveOrUpdate")
|
||||
public String saveOrUpdate(SysRole role, Model model, RedirectAttributes redirectAttributes) {
|
||||
|
||||
if (!"true".equals(checkName(role.getOldName(), role.getName()))){
|
||||
addMessage(model, "保存角色'" + role.getName() + "'失败, 角色名已存在");
|
||||
return form(role, model);
|
||||
}
|
||||
roleService.saveOrUpdate(role);
|
||||
addMessage(redirectAttributes, "保存角色'" + role.getName() + "'成功");
|
||||
return "redirect:" + adminPath + "/sys/role/?repage";
|
||||
}
|
||||
|
||||
@RequiresPermissions("sys:role:edit")
|
||||
@RequestMapping(value = "delete")
|
||||
public String delete(SysRole role, RedirectAttributes redirectAttributes) {
|
||||
roleService.deleteRole(role);
|
||||
addMessage(redirectAttributes, "删除角色成功");
|
||||
return "redirect:" + adminPath + "/sys/role/?repage";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 验证角色名是否有效
|
||||
* @param oldName
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("user")
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "checkName")
|
||||
public String checkName(String oldName, String name) {
|
||||
if (name!=null && name.equals(oldName)) {
|
||||
return "true";
|
||||
} else if (name!=null && roleService.getRoleByName(name) == null) {
|
||||
return "true";
|
||||
}
|
||||
return "false";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 角色分配 -- 从角色中移除用户
|
||||
* @param userId
|
||||
* @param roleId
|
||||
* @param redirectAttributes
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:role:edit")
|
||||
@RequestMapping(value = "outrole")
|
||||
public String outrole(Long userId, Long roleId, RedirectAttributes redirectAttributes) {
|
||||
SysRole role = roleService.getRole(roleId);
|
||||
SysUser user = userService.getUser(userId.toString());
|
||||
if (UserUtils.getUser().getId().equals(userId)) {
|
||||
addMessage(redirectAttributes, "无法从角色【" + role.getName() + "】中移除用户【" + user.getName() + "】自己!");
|
||||
}else {
|
||||
if (user.getUserRoleList().size() <= 1){
|
||||
addMessage(redirectAttributes, "用户【" + user.getName() + "】从角色【" + role.getName() + "】中移除失败!这已经是该用户的唯一角色,不能移除。");
|
||||
}else{
|
||||
Boolean flag = systemService.outUserInRole(role, user);
|
||||
if (!flag) {
|
||||
addMessage(redirectAttributes, "用户【" + user.getName() + "】从角色【" + role.getName() + "】中移除失败!");
|
||||
}else {
|
||||
addMessage(redirectAttributes, "用户【" + user.getName() + "】从角色【" + role.getName() + "】中移除成功!");
|
||||
}
|
||||
}
|
||||
}
|
||||
return "redirect:" + adminPath + "/sys/role/assign?id="+role.getId();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.nis.web.controller.sys;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.SysLog;
|
||||
import com.nis.web.controller.BaseController;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("${adminPath}/sys/log")
|
||||
public class SysLogController extends BaseController {
|
||||
|
||||
@RequiresPermissions("sys:log:view")
|
||||
@RequestMapping(value = {"list", ""})
|
||||
public String list(SysLog sysLog, HttpServletRequest request, HttpServletResponse response, Model model) {
|
||||
Page<SysLog> page = logService.findPage(new Page<SysLog>(request, response), sysLog);
|
||||
model.addAttribute("page", page);
|
||||
return "/sys/logList";
|
||||
}
|
||||
|
||||
}
|
||||
289
src/main/java/com/nis/web/controller/sys/UserController.java
Normal file
289
src/main/java/com/nis/web/controller/sys/UserController.java
Normal file
@@ -0,0 +1,289 @@
|
||||
package com.nis.web.controller.sys;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.SysRole;
|
||||
import com.nis.domain.SysUser;
|
||||
import com.nis.util.DateUtils;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.util.excel.ExportExcel;
|
||||
import com.nis.web.controller.BaseController;
|
||||
import com.nis.web.security.UserUtils;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("${adminPath}/sys/user")
|
||||
public class UserController extends BaseController{
|
||||
|
||||
@ModelAttribute
|
||||
public SysUser get(@RequestParam(required=false) Long id) {
|
||||
if (!StringUtil.isEmpty(id)){
|
||||
return userService.getUserByIdWithRelation(id);
|
||||
}else{
|
||||
return new SysUser();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("sys:user:view")
|
||||
@RequestMapping(value = {"index"})
|
||||
public String index(SysUser user, Model model) {
|
||||
return "/sys/userIndex";
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入用户添加或修改页面
|
||||
* @param user
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value={"form"})
|
||||
public String form(SysUser user, Model model) {
|
||||
|
||||
if (user.getCompany()==null || user.getCompany().getId()==null){
|
||||
user.setCompany(UserUtils.getUser().getCompany());
|
||||
}
|
||||
|
||||
|
||||
if (user.getEntity() == null || user.getEntity().getId() == null) {
|
||||
user.setEntity(UserUtils.getUser().getEntity());
|
||||
} else {
|
||||
user.setEntity(user.getEntity());
|
||||
}
|
||||
|
||||
if (user.getOffice() == null || user.getOffice().getId() == null) {
|
||||
user.setOffice(UserUtils.getUser().getOffice());
|
||||
} else {
|
||||
user.setOffice(user.getOffice());
|
||||
}
|
||||
|
||||
model.addAttribute("user", user);
|
||||
model.addAttribute("allRoles", roleService.findAllRole());
|
||||
|
||||
return "/sys/userForm";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequiresPermissions("sys:user:edit")
|
||||
@RequestMapping(value = "saveOrUpdate")
|
||||
public String saveOrUpdate(SysUser user, HttpServletRequest request, Model model, RedirectAttributes redirectAttributes) {
|
||||
|
||||
|
||||
// 如果新密码为空,则不更换密码
|
||||
if (StringUtils.isNotBlank(user.getNewPassword())) {
|
||||
user.setPassword(StringUtils.entryptPassword(user.getNewPassword()));
|
||||
}
|
||||
/*if (!beanValidator(model, user)){
|
||||
return form(user, model);
|
||||
}*/
|
||||
if (!"true".equals(checkLoginName(user.getOldLoginId(), user.getLoginId()))){
|
||||
addMessage(model, "保存用户'" + user.getLoginId() + "'失败,登录名已存在");
|
||||
return form(user, model);
|
||||
}
|
||||
// 角色数据有效性验证,过滤不在授权内的角色
|
||||
List<SysRole> roleList = Lists.newArrayList();
|
||||
List<Long> roleIdList = user.getRoleIdList();
|
||||
for (SysRole r : roleService.findAllRole()) {
|
||||
if (roleIdList.contains(r.getId())){
|
||||
roleList.add(r);
|
||||
}
|
||||
}
|
||||
user.setUserRoleList(roleList);
|
||||
// 保存用户信息
|
||||
userService.saveOrUpdate(user);
|
||||
// 清除当前用户缓存
|
||||
if (user.getLoginId().equals(UserUtils.getUser().getLoginId())){
|
||||
UserUtils.clearCache();
|
||||
}
|
||||
addMessage(redirectAttributes, "保存用户'" + user.getLoginId() + "'成功");
|
||||
return "redirect:" + adminPath + "/sys/user/list?repage";
|
||||
}
|
||||
|
||||
|
||||
@RequiresPermissions("sys:user:edit")
|
||||
@RequestMapping(value = "delete")
|
||||
public String delete(SysUser user, RedirectAttributes redirectAttributes) {
|
||||
|
||||
if (UserUtils.getUser().getId().equals(user.getId())){
|
||||
addMessage(redirectAttributes, "删除用户失败, 不允许删除当前用户");
|
||||
}else if (user.isAdmin()){
|
||||
addMessage(redirectAttributes, "删除用户失败, 不允许删除超级管理员用户");
|
||||
}else{
|
||||
userService.deleteUser(user);
|
||||
addMessage(redirectAttributes, "删除用户成功");
|
||||
}
|
||||
return "redirect:" + adminPath + "/sys/user/list?repage";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证登录名是否有效
|
||||
* @param oldLoginName
|
||||
* @param loginName
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequiresPermissions("sys:user:edit")
|
||||
@RequestMapping(value = "checkLoginName")
|
||||
public String checkLoginName(String oldLoginId, String loginId) {
|
||||
if (loginId !=null && loginId.equals(oldLoginId)) {
|
||||
return "true";
|
||||
} else if (loginId !=null && systemService.getUserByLoginName(loginId) == null) {
|
||||
return "true";
|
||||
}
|
||||
return "false";
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@RequiresPermissions("sys:user:edit")
|
||||
@RequestMapping(value = "checkOffice")
|
||||
public String checkOffice(Long officeId, Long companyId) {
|
||||
|
||||
boolean isValid = !StringUtil.isEmpty(officeId) && !StringUtil.isEmpty(companyId);
|
||||
|
||||
if (isValid) {
|
||||
isValid = systemService.officeIsValid(officeId, companyId);
|
||||
}
|
||||
|
||||
return String.valueOf(isValid);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@RequiresPermissions("sys:user:view")
|
||||
@RequestMapping(value = {"list"})
|
||||
public String list(SysUser user, HttpServletRequest request, HttpServletResponse response, Model model) {
|
||||
Page<SysUser> page = userService.findUser(new Page<SysUser>(request, response), user);
|
||||
model.addAttribute("page", page);
|
||||
return "/sys/userList";
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出用户数据
|
||||
* @param user
|
||||
* @param request
|
||||
* @param response
|
||||
* @param redirectAttributes
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("sys:user:view")
|
||||
@RequestMapping(value = "export", method=RequestMethod.POST)
|
||||
public String exportFile(SysUser user, HttpServletRequest request, HttpServletResponse response,
|
||||
RedirectAttributes redirectAttributes) {
|
||||
try {
|
||||
String fileName = "用户数据-"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
|
||||
Page<SysUser> page = userService.findUser(new Page<SysUser>(request, response, -1), user);
|
||||
new ExportExcel("用户数据", SysUser.class).setDataList(page.getList()).write(response, fileName).dispose();
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
addMessage(redirectAttributes, "导出用户失败!失败信息:"+e.getMessage());
|
||||
}
|
||||
return "redirect:" + adminPath + "/sys/user/list?repage";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequiresPermissions("user")
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "treeData")
|
||||
public List<Map<String, Object>> treeData(@RequestParam(required=false) Long officeId, HttpServletResponse response) {
|
||||
List<Map<String, Object>> mapList = Lists.newArrayList();
|
||||
List<SysUser> list = userService.findUserByOfficeId(officeId);
|
||||
for (int i=0; i<list.size() ; i++){
|
||||
SysUser e = list.get(i);
|
||||
Map<String, Object> map = Maps.newHashMap();
|
||||
map.put("id", "u_"+e.getId());
|
||||
map.put("pId", officeId);
|
||||
map.put("name", StringUtils.replace(e.getName(), " ", ""));
|
||||
mapList.add(map);
|
||||
}
|
||||
return mapList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户信息显示及保存
|
||||
* @param user
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("user")
|
||||
@RequestMapping(value = "info")
|
||||
public String info(SysUser user, HttpServletResponse response, Model model) {
|
||||
SysUser currentUser = UserUtils.getUser();
|
||||
if (StringUtils.isNotBlank(user.getName())){
|
||||
currentUser.setEmail(user.getEmail());
|
||||
currentUser.setPhoto(user.getPhoto());
|
||||
userService.updateUserInfo(currentUser);
|
||||
model.addAttribute("message", "保存用户信息成功");
|
||||
}
|
||||
model.addAttribute("user", currentUser);
|
||||
return "/sys/userInfo";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回用户信息
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("user")
|
||||
@ResponseBody
|
||||
@RequestMapping(value = "infoData")
|
||||
public SysUser infoData() {
|
||||
return UserUtils.getUser();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改个人用户密码
|
||||
* @param oldPassword
|
||||
* @param newPassword
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("user")
|
||||
@RequestMapping(value = "modifyPwd")
|
||||
public String modifyPwd(String oldPassword, String newPassword, Model model) {
|
||||
SysUser user = UserUtils.getUser();
|
||||
if (StringUtils.isNotBlank(oldPassword) && StringUtils.isNotBlank(newPassword)){
|
||||
|
||||
if (StringUtils.validatePassword(oldPassword, user.getPassword())){
|
||||
userService.updatePasswordById(user.getId(), user.getLoginId(), newPassword);
|
||||
model.addAttribute("message", "修改密码成功");
|
||||
}else{
|
||||
model.addAttribute("message", "修改密码失败,旧密码错误");
|
||||
}
|
||||
}
|
||||
model.addAttribute("user", user);
|
||||
return "/sys/userModifyPwd";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user