package com.jy.system.controller;

import com.jy.framework.model.annotation.JyLog;
import com.jy.framework.model.base.BaseSelectDto;
import com.jy.framework.model.enums.BusinessType;
import com.jy.framework.model.validation.AddGroup;
import com.jy.framework.model.validation.DeleteGroup;
import com.jy.framework.model.validation.DetailGroup;
import com.jy.framework.model.validation.EditGroup;
import com.jy.system.model.dto.SysDeptDto;
import com.jy.system.model.dto.SysDeptSelectDto;
import com.jy.system.model.vo.SysDeptVo;
import com.jy.system.service.SysDeptService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 部门 前端控制器
 * </p>
 *
 * @author
 * @since 2024-06-20
 */
@RestController
@RequestMapping("/sysDept")
public class SysDeptController {

    @Resource
    private SysDeptService sysDeptService;

    /**
     * 部门列表
     */
    @GetMapping("/getList")
    public List<SysDeptVo> getList(SysDeptSelectDto dto) {
        return sysDeptService.getList(dto);
    }

    /**
     * 部门分页
     */
    @GetMapping("/getTree")
    public List<SysDeptVo> getTree(SysDeptSelectDto dto) {
        return sysDeptService.getTree(dto);
    }

    /**
     * 部门明细
     */
    @GetMapping("/getDetail")
    public SysDeptVo getDetail(@Validated(DetailGroup.class) BaseSelectDto dto) {
        return sysDeptService.getDetail(dto.getId());
    }

    /**
     * 部门新增
     */
    @JyLog(title = "新增部门", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public void add(@Validated(AddGroup.class) @RequestBody SysDeptDto dto) {
        sysDeptService.add(dto);
    }

    /**
     * 部门编辑
     */
    @JyLog(title = "编辑部门", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public void edit(@Validated(EditGroup.class) @RequestBody SysDeptDto dto) {
        sysDeptService.edit(dto);
    }

    /**
     * 部门删除
     */
    @JyLog(title = "删除部门", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public void delete(@Validated(DeleteGroup.class) @RequestBody BaseSelectDto dto) {
        sysDeptService.delete(dto.getId());
    }

}
