package com.koobietech.eas.controller;

import com.github.pagehelper.PageHelper;
import com.koobietech.eas.common.result.JsonPageResult;
import com.koobietech.eas.common.result.JsonResult;
import com.koobietech.eas.common.result.PageDataResult;
import com.koobietech.eas.mbg.model.EasSysDepartment;
import com.koobietech.eas.service.EasSysDepartmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@Tag(name = "部门模块")
@RequestMapping("/department")
public class EasSysDepartmentController {

    @Resource
    EasSysDepartmentService easSysDepartmentService;


    @PostMapping("/query")
    @Operation(summary = "查询部门", description = "根据参数查询部门表信息")
    public JsonPageResult query(@RequestBody EasSysDepartment department,
                                @RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        PageDataResult ret = easSysDepartmentService.query(department);
        return JsonPageResult.data(ret);
    }

    @PostMapping("/add")
    @Operation(summary = "添加部门", description = "添加部门信息")
    public JsonResult add(@RequestBody EasSysDepartment department) {
        Boolean ret = easSysDepartmentService.add(department);
        if (ret) {
            return JsonResult.data(ret);
        }
        return JsonResult.fail();
    }


    @DeleteMapping("/delete")
    @Operation(summary = "删除部门", description = "删除部门表数据根据ID")
    public JsonResult delete(@RequestParam Long id) {
        Boolean ret = easSysDepartmentService.delete(id);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }


    @PutMapping("/update")
    @Operation(summary = "更新部门", description = "更新部门信息")
    public JsonResult update(@RequestBody EasSysDepartment department) {
        Boolean ret = easSysDepartmentService.update(department);
        if (ret) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }


}
