package com.huatek.frame.base.dictionnaire.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.frame.base.dto.DictionnaireDTO;
import com.huatek.frame.base.dto.DictionnaireDetailDTO;
import com.huatek.frame.base.entity.Dictionnaire;
import com.huatek.frame.base.entity.DictionnaireDetail;
import com.huatek.frame.base.service.DictionnaireDetailService;
import com.huatek.frame.base.service.DictionnaireService;
import com.huatek.frame.base.vo.DictionnaireDetailVO;
import com.huatek.frame.base.vo.DictionnaireVO;
import com.huatek.torch.frame.log.KerLog;
import com.huatek.torch.frame.permission.KerPermission;
import com.huatek.torch.frame.validate.KerValid;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 字典管理
 * 
 * @author porter_zhang
 *
 */
@Api(tags={"字典管理接口"})
@RestController
@RequestMapping("/api/dictionnaire")
public class DictionnaireController {

	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(DictionnaireController.class);

	@Reference(check = false)
	private DictionnaireService dictionnaireService;

	@Reference(check = false)
	private DictionnaireDetailService dictionnaireDetailService;

	/**
	 * 字典列表
	 * 
	 * @return
	 */
	@ApiOperation(value = "字典列表",httpMethod="POST", notes= "字典列表", produces = "application/json;charset=utf-8",response=DictionnaireVO.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "DICTIONARY.MODELNAME", methodName = "DICTIONARY.METHODNAME.DICTIONARYLIST")
	@PostMapping(value = "/queryList", produces = { "application/json;charset=utf-8" })
	public  @KerPermission("10012") Map<String, Object> queryPageList(@RequestBody DictionnaireDTO dto) {
		Map<String, Object> map = dictionnaireService.findDictionnairePage(dto);
		return map;
	}

	/**
	 * 新增字典
	 * 
	 * @return
	 */
	@ApiOperation(value = "新增字典",httpMethod="POST", notes= "新增字典", produces = "application/json;charset=utf-8",response=Map.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "DICTIONARY.MODELNAME", methodName = "DICTIONARY.METHODNAME.DICTIONARYADD")
	@PostMapping(value = "/addDictionnaire", produces = { "application/json;charset=utf-8" })
	public  @KerPermission("10014") @KerValid Map<String, Object> addDictionnaire(@RequestBody Dictionnaire dictionnaire) {
		Map<String, Object> map = dictionnaireService.addDictionnaire(dictionnaire);
		return map;
	}

	/**
	 * 字典详情
	 * 
	 * @return
	 */
	@ApiOperation(value = "字典详情",httpMethod="POST", notes= "字典详情", produces = "application/json;charset=utf-8",response=DictionnaireVO.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "DICTIONARY.MODELNAME", methodName = "DICTIONARY.METHODNAME.DICTIONARYFIND")
	@GetMapping(value = "/findDictionnaire/{id}", produces = { "application/json;charset=utf-8" })
	public  @KerPermission("10013") Map<String, Object> findDictionnaire(@PathVariable("id")String id) {
		Map<String, Object> map = dictionnaireService.findDictionnaire(id);
		return map;
	}

	/**
	 * 修改字典
	 * 
	 * @return
	 */
	@ApiOperation(value = "修改字典",httpMethod="POST", notes= "修改字典", produces = "application/json;charset=utf-8",response=Map.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "DICTIONARY.MODELNAME", methodName = "DICTIONARY.METHODNAME.DICTIONARYMODIFY")
	@PostMapping(value = "/modifyDictionnaire", produces = { "application/json;charset=utf-8" })
	public  @KerPermission("10015") Map<String, Object> modifyDictionnaire(@RequestBody Dictionnaire dictionnaire) {
		Map<String, Object> map = dictionnaireService.updateDictionnaire(dictionnaire);
		return map;
	}

	/**
	 * 删除字典
	 * 
	 * @return
	 */
	@ApiOperation(value = "删除字典",httpMethod="POST", notes= "删除字典", produces = "application/json;charset=utf-8",response=Map.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "DICTIONARY.MODELNAME", methodName = "DICTIONARY.METHODNAME.DICTIONARYSTATUSMODIFY")
	@PostMapping(value = "/deleteDictionnaire", produces = { "application/json;charset=utf-8" })
	public  @KerPermission("10016") Map<String, Object> deleteDictionnaire(@RequestBody String[] ids) {
		Map<String, Object> map = dictionnaireService.deleteDictionnaire(ids);
		return map;
	}

	/**
	 * 根据字典id获取字典明细列表
	 * 
	 * @return
	 */
	@ApiOperation(value = "根据字典id获取字典明细列表",httpMethod="POST", notes= "根据字典id获取字典明细列表", produces = "application/json;charset=utf-8",response=DictionnaireDetailVO.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "DICTIONARY.MODELNAME", methodName = "DICTIONARY.METHODNAME.DICTIONARYDETAILLIST")
	@PostMapping(value = "/queryListById/{pid}", produces = { "application/json;charset=utf-8" })
	public  @KerPermission("10017") Map<String, Object> queryPageListById(@RequestBody DictionnaireDetailDTO dto,@PathVariable("pid")String pid) {
		dto.setPid(pid);
		Map<String, Object> map = dictionnaireDetailService.findDictionnaireDetailPage(dto);
		return map;
	}

	/**
	 * 新增字典明细
	 * 
	 * @return
	 */
	@ApiOperation(value = "新增字典明细",httpMethod="POST", notes= "新增字典明细", produces = "application/json;charset=utf-8",response=Map.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "DICTIONARY.MODELNAME", methodName = "DICTIONARY.METHODNAME.DICTIONARYDETAILADD")
	@PostMapping(value = "/addDetail", produces = { "application/json;charset=utf-8" })
	public  @KerPermission("10017") @KerValid Map<String, Object> addById(@RequestBody DictionnaireDetail detail) {
		Map<String, Object> map = dictionnaireDetailService.addDictionnaireDetail(detail);
		return map;
	}

	/**
	 * 删除字典明细
	 * 
	 * @return
	 */
	@ApiOperation(value = "删除字典明细",httpMethod="POST", notes= "删除字典明细", produces = "application/json;charset=utf-8",response=Map.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "DICTIONARY.MODELNAME", methodName = "DICTIONARY.METHODNAME.DICTIONARYDETAILSTATUS")
	@PostMapping(value = "/deleteDetail", produces = { "application/json;charset=utf-8" })
	public  @KerPermission("10017") Map<String, Object> modifyDdetailStatus(@RequestBody String[] ids) {
		Map<String, Object> map = dictionnaireDetailService.deleteDictionnaireDetail(ids);
		return map;
	}

	/**
	 * 字典明细详情
	 * 
	 * @return
	 */
	@ApiOperation(value = "字典明细详情",httpMethod="POST", notes= "字典明细详情", produces = "application/json;charset=utf-8",response=DictionnaireDetailVO.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "DICTIONARY.MODELNAME", methodName = "DICTIONARY.METHODNAME.DICTIONARYDETAIL")
	@GetMapping(value = "/findDetail/{id}", produces = { "application/json;charset=utf-8" })
	public  @KerPermission("10017") Map<String, Object> findDdetail(@PathVariable("id")String id) {
		Map<String, Object> map = dictionnaireDetailService.findDictionnaireDetail(id);
		return map;
	}

	/**
	 * 修改字典明细
	 * 
	 * @return
	 */
	@ApiOperation(value = "修改字典明细",httpMethod="POST", notes= "修改字典明细", produces = "application/json;charset=utf-8",response=Map.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "DICTIONARY.MODELNAME", methodName = "DICTIONARY.METHODNAME.DICTIONARYDETAILMODIFY")
	@PostMapping(value = "/modifyDetail", produces = { "application/json;charset=utf-8" })
	public  @KerPermission("10017") Map<String, Object> modifyDdetail(@RequestBody DictionnaireDetail dictionnaireDetail) {
		Map<String, Object> map = dictionnaireDetailService.updateDictionnaireDetail(dictionnaireDetail);
		return map;
	}

	@ApiOperation(value = "根据字典键查询字典信息",httpMethod="POST", notes= "根据字典键查询字典信息", produces = "application/json;charset=utf-8",response=Map.class)
	@PostMapping(value = "/findByCode", produces = { "application/json;charset=utf-8" })
	public Map<String, Object> findByCode(@RequestParam("code") String code) {
		return dictionnaireDetailService.findByCode(code);
	}
}
