UserController.java 2.52 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
package com.lyms.cm.controller.sys;

import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.lyms.cm.entity.sys.User;
import com.lyms.cm.service.sys.UserService;
import com.lyms.constants.OperationName;
import com.lyms.shiro.HashUtils;
import com.lyms.util.StrUtils;
import com.lyms.web.bean.AjaxResult;
import com.lyms.web.controller.BaseController;

@Controller
@RequestMapping("/user")
public class UserController extends BaseController{
@Autowired
private UserService userService;
@RequiresPermissions("user:view")
@RequestMapping("/list")
public String list() {
return "/user/user_list";
}
/**
* 概要.
* <br>
* @param id
* @param model
* @return
* @return String
* @author 自己的中文名
* @date 2016年7月7日 下午4:35:09
*/
@RequestMapping(value = "/{id}/toEdit")
public String toEdit(@PathVariable String id, Model model) {
model.addAttribute("user", userService.selectById(id));
return "/user/user_edit";
}

@RequestMapping(value = "/create")
@ResponseBody
public AjaxResult create(User user, AjaxResult ajaxResult) {
user.setId(StrUtils.uuid());
user.setPassword(HashUtils.md5(user.getPassword()));
boolean rs = userService.insert(user);
return handleAjaxResult(ajaxResult, rs, OperationName.CREATE);
}

@RequestMapping(value = "/update")
@ResponseBody
public AjaxResult update(User user, AjaxResult ajaxResult) {
if (!StringUtils.isEmpty(user.getPassword())) {
user.setPassword(HashUtils.md5(user.getPassword()));
}
boolean ret = userService.updateById(user);
return handleAjaxResult(ajaxResult, ret, OperationName.UPDATE);
}

@RequestMapping(value = "/{id}/delete")
@ResponseBody
public AjaxResult delete(@PathVariable String id, AjaxResult ajaxResult) {
if ("1".equals(id))
return new AjaxResult(false, "不能删除超级管理员");
boolean rs = userService.deleteById(id);
return handleAjaxResult(ajaxResult, rs, OperationName.DELETE);
}

@RequestMapping("/getUserList")
@ResponseBody
public Map<String, Object> getUserList(){
Page<User> page = getPage();
return toGridData(userService.selectPage(page, null));
}
}