RoleController.java 1.9 KB
Newer Older
刘弈臻's avatar
刘弈臻 committed
1 2 3 4 5 6 7 8 9
package com.govmade.modules.system.controller;

import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
刘弈臻's avatar
刘弈臻 committed
10
import org.springframework.web.bind.annotation.RequestBody;
刘弈臻's avatar
刘弈臻 committed
11 12 13 14 15 16
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.govmade.common.utils.PageUtils;
import com.govmade.common.utils.R;
刘弈臻's avatar
刘弈臻 committed
17
import com.govmade.common.validator.Assert;
刘弈臻's avatar
刘弈臻 committed
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
import com.govmade.modules.basic.controller.AbstractController;
import com.govmade.modules.system.entity.RoleEntity;
import com.govmade.modules.system.service.RoleService;

/**
 * 系统管理 - 角色设置
 * 
 * @author 刘弈臻
 * @date 2018年8月7日
 */

@RestController
@RequestMapping("/system/role")
public class RoleController extends AbstractController{

	@Autowired
	private RoleService roleService;
	
	/**
	 * 角色列表
	 */
	@GetMapping("/list")
	public R list(@RequestParam Map<String, Object> params) {
		
		PageUtils page = roleService.queryPage(params);
		return R.ok().put("page", page);
	}
	
	/**
刘弈臻's avatar
刘弈臻 committed
47
	 * 保存或更新角色
刘弈臻's avatar
刘弈臻 committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61
	 */
	@PostMapping("/save")
	public R save(RoleEntity role) {

		if (null == role.getId()) {
			if (this.roleService.checkRole(role.getName()) > 0) {
				return R.error(role.getName() + " 已存在!");
			}
			
		}
		roleService.save(role);
		return R.ok();
	}
	
刘弈臻's avatar
刘弈臻 committed
62 63 64 65 66 67

/**
	 * 批量删除角色
	 * 
	 * @param ids
	 * @return
刘弈臻's avatar
刘弈臻 committed
68 69
	 */
	@DeleteMapping("/delete")
刘弈臻's avatar
刘弈臻 committed
70 71
	public R deleteRole(@RequestBody Set<Long> ids) {
		Assert.isNull(ids, "删除项不能为空");
刘弈臻's avatar
刘弈臻 committed
72

刘弈臻's avatar
刘弈臻 committed
73 74 75
		roleService.deleteBatch(ids);
		return R.ok();
	}
刘弈臻's avatar
刘弈臻 committed
76 77 78
	
	
}