AreaController.java 1.93 KB
Newer Older
1 2
package com.govmade.modules.system.controller;

刘弈臻's avatar
刘弈臻 committed
3
import java.util.Map;
4 5 6 7 8 9
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;
11
import org.springframework.web.bind.annotation.RequestMapping;
Fred's avatar
Fred committed
12
import org.springframework.web.bind.annotation.RequestParam;
13 14
import org.springframework.web.bind.annotation.RestController;

15
import com.govmade.common.utils.PageTreeUtils;
16
import com.govmade.common.utils.R;
刘弈臻's avatar
刘弈臻 committed
17
import com.govmade.common.validator.Assert;
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
import com.govmade.modules.basic.controller.AbstractController;
import com.govmade.modules.system.entity.AreaEntity;
import com.govmade.modules.system.service.AreaService;

/**
 * 系统管理 - 行政区划设置
 * 
 * @author 刘弈臻
 * @date 2018年8月9日
 */

@RestController
@RequestMapping("/system/area")
public class AreaController extends AbstractController{
     
	@Autowired
	private AreaService areaService;
	
	/**
	 * 所有区划数据树结构
	 */
刘弈臻's avatar
刘弈臻 committed
39 40
	@GetMapping("/listTree")
	public R listTree(@RequestParam Map<String, Object> params) {
41
		PageTreeUtils page = areaService.queryPage(params);
刘弈臻's avatar
刘弈臻 committed
42
		return R.ok().put("page", page);
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
	}
	
	/**
	 * 保存或更新区划
	 */
	@PostMapping("/save")
	public R save(AreaEntity area) {

		if (null == area.getId()) {
			if (this.areaService.checkArea(area.getName()) > 0) {
				return R.error(area.getName() + " 已存在!");
			}
			
		}
		areaService.save(area);
		return R.ok();
	}
	
刘弈臻's avatar
刘弈臻 committed
61 62 63 64 65 66
	/**
	 * 批量删除区划
	 * 
	 * @param ids
	 * @return
	 */
67
	@DeleteMapping("/delete")
刘弈臻's avatar
刘弈臻 committed
68 69
	public R deleteArea(@RequestBody Set<Long> ids) {
		Assert.isNull(ids, "删除项不能为空");
70

刘弈臻's avatar
刘弈臻 committed
71 72 73
		areaService.deleteBatch(ids);
		return R.ok();
	}
74 75
	
}