package jnpf.attendance.controller;

import jnpf.attendance.service.AttendancePermissionDictService;
import jnpf.base.ActionResult;
import jnpf.entity.PermissionDict;
import jnpf.exception.HandleException;
import jnpf.model.attendance.dto.SavePermissionDto;
import jnpf.model.attendance.vo.PermissionDictVo;
import jnpf.util.ParamUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 权限字典管理
 */
@RestController
@RequestMapping("/dict")
public class AttendancePermissionDictController {

    @Resource
    private AttendancePermissionDictService attendancePermissionDictService;

    /**
     * 保存权限字典信息
     * @param savePermissionDto
     * @return ActionResult<Void>
     * @throws Exception
     */
    @PostMapping
    public ActionResult<Void> save(@RequestBody SavePermissionDto savePermissionDto) throws Exception {
        ParamUtil.checkParam(savePermissionDto);
        attendancePermissionDictService.save(savePermissionDto);
        return ActionResult.success();
    }

    /**
     * 权限字典查询列表
     * @param moduleType
     * @return ActionResult<List<PermissionDictVo>>
     */
    @GetMapping
    public ActionResult<List<PermissionDictVo>> query(Integer moduleType) {
        List<PermissionDictVo> result = attendancePermissionDictService.queryPermissionDictList(moduleType);
        return ActionResult.success(result);
    }

    /**
     * 根据id删除权限字典
     * @param id 权限字典id
     * @return ActionResult<Void>
     */
    @DeleteMapping("/{id}")
    public ActionResult<Void> delete(@PathVariable String id) {
        attendancePermissionDictService.delete(id);
        return ActionResult.success();
    }

    /**
     * 权限详情
     * @param id
     * @return ActionResult<PermissionDict>
     */
    @GetMapping("/{id}")
    public ActionResult<PermissionDict> detail(@PathVariable String id) {
        PermissionDict permissionDict = attendancePermissionDictService.detail(id);
        return ActionResult.success(permissionDict);
    }
}
