package com.fs.company.controller;

import java.util.List;

import com.fs.common.utils.ServletUtils;
import com.fs.core.security.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.company.domain.CompanyDept;
import com.fs.company.service.ICompanyDeptService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;


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

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

    /**
     * 导出部门列表
     */
    @PreAuthorize("@ss.hasPermi('company:companyDept:export')")
    @Log(title = "部门", businessType = BusinessType.EXPORT)
    @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");
    }

    /**
     * 获取部门详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:companyDept:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(companyDeptService.selectCompanyDeptById(deptId));
    }

    /**
     * 新增部门
     */
    @PreAuthorize("@ss.hasPermi('company:companyDept:add')")
    @Log(title = "部门", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyDept companyDept)
    {
        return toAjax(companyDeptService.insertCompanyDept(companyDept));
    }

    /**
     * 修改部门
     */
    @PreAuthorize("@ss.hasPermi('company:companyDept:edit')")
    @Log(title = "部门", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyDept companyDept)
    {
        return toAjax(companyDeptService.updateCompanyDept(companyDept));
    }

    /**
     * 删除部门
     */
    @PreAuthorize("@ss.hasPermi('company:companyDept:remove')")
    @Log(title = "部门", businessType = BusinessType.DELETE)
	@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));
    }
}
