package com.fs.app.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.company.domain.CompanyDept;
import com.fs.company.service.ICompanyDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/company/companyDept")
public class CompanyDeptController extends BaseController
{
    @Autowired
    private ICompanyDeptService companyDeptService;

    /**
     * 查询部门列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CompanyDept companyDept)
    {
        startPage();
        List<CompanyDept> list = companyDeptService.selectCompanyDeptList(companyDept);
        return getDataTable(list);
    }

    /**
     * 导出部门列表
     */
    @GetMapping("/export")
    public AjaxResult export(CompanyDept companyDept)
    {
        List<CompanyDept> list = companyDeptService.selectCompanyDeptList(companyDept);
        ExcelUtil<CompanyDept> util = new ExcelUtil<CompanyDept>(CompanyDept.class);
        return util.exportExcel(list, "companyDept");
    }

    /**
     * 获取部门详细信息
     */
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(companyDeptService.selectCompanyDeptById(deptId));
    }

    /**
     * 新增部门
     */
    @PostMapping
    public AjaxResult add(@RequestBody CompanyDept companyDept)
    {
        return toAjax(companyDeptService.insertCompanyDept(companyDept));
    }

    /**
     * 修改部门
     */
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyDept companyDept)
    {
        return toAjax(companyDeptService.updateCompanyDept(companyDept));
    }

    /**
     * 删除部门
     */
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(companyDeptService.deleteCompanyDeptByIds(deptIds));
    }

    /**
     * 获取部门下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(CompanyDept dept)
    {
        dept.setStatus("0");
        List<CompanyDept> depts = companyDeptService.selectCompanyDeptList(dept);
        return AjaxResult.success(companyDeptService.buildDeptTreeSelect(depts));
    }
}
