DictController.java 2.1 KB
Newer Older
Fred's avatar
Fred committed
1 2 3 4
package com.govmade.modules.system.controller;

import java.util.List;
import java.util.Map;
刘弈臻's avatar
刘弈臻 committed
5
import java.util.Set;
Fred's avatar
Fred committed
6 7

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

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

/**
 * 系统管理 - 字典设置
 * 
 * @author Fred
 * @email fangtaosh@qq.com
 * @date 2018年8月7日
 */
@RestController
@RequestMapping("/system/dict")
public class DictController extends AbstractController {

	@Autowired
	private DictService dictService;


	/**
	 * 用户列表
	 */
	@GetMapping("/list")
	public R list(Map<String, Object> params) {
		
		List<DictEntity> dictList = dictService.queryChilds("city_level");
		
		return R.ok().put("childs", dictList);
	}
刘弈臻's avatar
刘弈臻 committed
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
	
	/**
	 * 所有字典数据树结构
	 */
	@GetMapping("/listTree")
	public R listTree(@RequestParam Map<String, Object> params) {
		PageTreeUtils page = dictService.queryPage(params);
		return R.ok().put("page", page);
	}
	
	
	/**
	 * 保存或更新字典
	 */
	@PostMapping("/save")
	public R save(DictEntity dict) {

		if (null == dict.getId()) {
			if (this.dictService.checkDict(dict.getName()) > 0) {
				return R.error(dict.getName() + " 已存在!");
			}
		}
		dictService.save(dict);
		return R.ok();
	}
/**
	 * 批量删除字典
	 * 
	 * @param ids
	 * @return
	 */
	@DeleteMapping("/delete")
	public R deleteDict(@RequestBody Set<Long> ids) {
		Assert.isNull(ids, "删除项不能为空");

		dictService.deleteBatch(ids);
		return R.ok();
	}
Fred's avatar
Fred committed
86 87

}