DepartController.java 2.16 KB
Newer Older
刘弈臻's avatar
刘弈臻 committed
1 2 3 4 5
package com.govmade.modules.system.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
Fred's avatar
Fred committed
6
import org.springframework.web.bind.annotation.DeleteMapping;
刘弈臻's avatar
刘弈臻 committed
7 8
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
Fred's avatar
Fred committed
9
import org.springframework.web.bind.annotation.RequestBody;
刘弈臻's avatar
刘弈臻 committed
10 11 12 13 14 15
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
16
import com.govmade.common.validator.Assert;
刘弈臻's avatar
刘弈臻 committed
17 18 19
import com.govmade.modules.basic.controller.AbstractController;
import com.govmade.modules.system.entity.DepartEntity;
import com.govmade.modules.system.service.DepartService;
刘弈臻's avatar
刘弈臻 committed
20
import com.govmade.modules.system.service.UserService;
刘弈臻's avatar
刘弈臻 committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34

/**
 * 系统管理 - 部门设置
 * 
 * @author 刘弈臻
 * @date 2018年8月8日
 */
@RestController
@RequestMapping("/system/depart")
public class DepartController extends AbstractController{
  
	@Autowired
	private DepartService departService;
	
刘弈臻's avatar
刘弈臻 committed
35 36 37
	@Autowired
	private UserService userService;
	
刘弈臻's avatar
刘弈臻 committed
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
	/**
	 * 部门列表
	 */
	@GetMapping("/list")
	public R list(@RequestParam Map<String, Object> params) {
		
		PageUtils page = departService.queryPage(params);
		return R.ok().put("page", page);
	}
	
	/**
	 * 保存或更新部门
	 */
	@PostMapping("/save")
	public R save(DepartEntity depart) {

		if (null == depart.getId()) {
			if (this.departService.checkDepart(depart.getName()) > 0) {
				return R.error(depart.getName() + " 已存在!");
			}
			
		}
		departService.save(depart);
		return R.ok();
	}
	

刘弈臻's avatar
刘弈臻 committed
65
	/**
Fred's avatar
Fred committed
66
	 * 删除部门
刘弈臻's avatar
刘弈臻 committed
67 68 69
	 * 
	 * @param ids
	 * @return
刘弈臻's avatar
刘弈臻 committed
70
	 */
71

刘弈臻's avatar
刘弈臻 committed
72
	@DeleteMapping("/delete")
刘弈臻's avatar
刘弈臻 committed
73 74
	public R deleteDepart(@RequestBody DepartEntity depart) {
		Assert.isNull(depart.getId(), "删除项不能为空");
75
        if(this.userService.userCount(depart.getId())>0) {
刘弈臻's avatar
刘弈臻 committed
76 77
           return R.error("选中部门下有用户!!");
        }
78
		departService.deleteDepart(depart);
刘弈臻's avatar
刘弈臻 committed
79 80
		return R.ok();
	}
刘弈臻's avatar
刘弈臻 committed
81 82
	
}