package com.securitycontrol.system.controller;

import com.securitycontrol.common.core.domain.Result;
import com.securitycontrol.common.core.web.controller.BaseController;
import com.securitycontrol.common.log.annotation.Log;
import com.securitycontrol.common.log.enums.OperationType;
import com.securitycontrol.entity.system.dto.DictDto;
import com.securitycontrol.entity.system.vo.DictVo;
import com.securitycontrol.system.service.DictService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 字典管理层
 *
 * @author HeiZi
 */
@RestController
@RequestMapping("/sys/dict/")
public class DictController extends BaseController {

    @Resource
    private DictService service;


    /**
     * @param dto
     * @return
     */
    @GetMapping("getDictList")
    @Log(title = "系统管理", menu = "系统管理->字典管理", grade = OperationType.QUERY_SYS, details = "查询字典", type = "系统日志")
    public Result<List<DictVo>> getDictList(@Valid DictDto dto) {
        return service.getDictList(dto);
    }


    /**
     * 新增組織機構
     *
     * @param dto
     * @return
     */
    @PostMapping("addDict")
    @Log(title = "系统管理", menu = "系统管理->字典管理", grade = OperationType.ADD_SYS, details = "新增字典", type = "系统日志")
    public Result<String> addDict(@RequestBody @Valid DictVo dto) {
        return service.addDict(dto);
    }


    /**
     * 修改组织机构
     *
     * @param dto
     * @return
     */
    @PostMapping("updateDict")
    @Log(title = "系统管理", menu = "系统管理->字典管理", grade = OperationType.UPDATE_SYS, details = "修改字典", type = "系统日志")
    public Result<String> updateDict(@RequestBody @Valid DictVo dto) {
        return service.updateDict(dto);
    }


    /**
     * 新增組織機構
     *
     * @param dto
     * @return
     */
    @PostMapping("delDict")
    @Log(title = "系统管理", menu = "系统管理->字典管理", grade = OperationType.DELETE_SYS, details = "删除字典", type = "系统日志")
    public Result<String> delDict(@RequestBody DictDto dto) {
        return service.delDict(dto);
    }


    /**
     * 新增組織機構
     *
     * @param id
     * @return
     */
    @PostMapping("getDetails/{id}")
    public Result<DictVo> getDetails(@PathVariable("id") String id) {
        return service.getDetails(id);
    }


}
