package com.gic.haoban.manage.web.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gic.api.base.commons.Page;
import com.gic.haoban.base.api.common.BasePageInfo;
import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.manage.api.dto.DictDTO;
import com.gic.haoban.manage.api.service.DictApiService;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode;

@RestController
public class DictController extends WebBaseController{
	private static Logger logger  = LoggerFactory.getLogger(DictController.class);

	@Autowired
	private DictApiService dictApiService;
	//获取字典列表
	@RequestMapping("get-dict-list")
	public HaobanResponse getDictList(BasePageInfo pageInfo) {
		Page<DictDTO> page = dictApiService.pageList(pageInfo);
		return resultResponse(HaoBanErrCode.ERR_1,page);
	}
	//保存字典
	@RequestMapping("save-dict")
	public HaobanResponse saveDict(DictDTO dto) {
		int i = dictApiService.saveDict(dto);
		if(i == 8){
			return resultResponse(HaoBanErrCode.ERR_10006);
		}
		if(i == 9){
			return resultResponse(HaoBanErrCode.ERR_10007);
		}
		return resultResponse(HaoBanErrCode.ERR_1);
	}
	//查看字典详情
	@RequestMapping("find-dict-detail")
	public HaobanResponse findDictDetail(String  dictId) {
		DictDTO dictDTO = dictApiService.findOneDict(dictId);
		return resultResponse(HaoBanErrCode.ERR_1,dictDTO);
	}
	//删除字典
	@RequestMapping("del-dict")
	public HaobanResponse deleteDict(String  dictId) {
		dictApiService.deleteOne(dictId);
		return resultResponse(HaoBanErrCode.ERR_1);
	}
}
