package com.ruoyi.cms.controller.cms;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cms.domain.BussinessDictData;
import com.ruoyi.common.core.domain.entity.Industry;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.core.domain.entity.JobTitle;
import com.ruoyi.cms.service.IJobTitleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 岗位Controller
 * 
 * @author Lishundong
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/cms/job/titile")
@Api(tags = "后台：职位接口")
public class JobTitleController extends BaseController
{
    @Autowired
    private IJobTitleService jobTitleService;

    /**
     * 查询岗位列表
     */
    @ApiOperation("查询岗位列表")
    @PreAuthorize("@ss.hasPermi('cms:title:list')")
    @GetMapping("/list")
    public TableDataInfo list(JobTitle jobTitle)
    {
        startPage();
        List<JobTitle> list = jobTitleService.selectJobTitleList(jobTitle);
        return getDataTable(list);
    }

    /**
     * 导出岗位列表
     */
    @ApiOperation("导出岗位列表")
    @PreAuthorize("@ss.hasPermi('cms:title:export')")
    @Log(title = "岗位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JobTitle jobTitle)
    {
        List<JobTitle> list = jobTitleService.selectJobTitleList(jobTitle);
        ExcelUtil<JobTitle> util = new ExcelUtil<JobTitle>(JobTitle.class);
        util.exportExcel(response, list, "岗位数据");
    }

    /**
     * 获取岗位详细信息
     */
    @ApiOperation("获取岗位详细信息")
    @PreAuthorize("@ss.hasPermi('cms:title:query')")
    @GetMapping(value = "/{jobId}")
    public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
    {
        return success(jobTitleService.selectJobTitleByJobId(jobId));
    }

    /**
     * 新增岗位
     */
    @ApiOperation("新增岗位")
    @PreAuthorize("@ss.hasPermi('cms:title:add')")
    @Log(title = "岗位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JobTitle jobTitle)
    {
        return toAjax(jobTitleService.insertJobTitle(jobTitle));
    }

    /**
     * 修改岗位
     */
    @ApiOperation("修改岗位")
    @PreAuthorize("@ss.hasPermi('cms:title:edit')")
    @Log(title = "岗位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JobTitle jobTitle)
    {
        return toAjax(jobTitleService.updateJobTitle(jobTitle));
    }

    /**
     * 删除岗位
     */
    @ApiOperation("删除岗位")
    @PreAuthorize("@ss.hasPermi('cms:title:remove')")
    @Log(title = "岗位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jobId}")
    public AjaxResult remove(@PathVariable Long jobId)
    {
        if (jobTitleService.hasChildByJobId(jobId))
        {
            return warn("存在子岗位,不允许删除");
        }
        Long[] jobIds = {jobId};
        return toAjax(jobTitleService.deleteJobTitleByJobIds(jobIds));
    }
    @ApiOperation("行业树结构")
    @GetMapping("/treeselect")
    public AjaxResult treeselect(JobTitle jobTitle)
    {
        List<JobTitle> jobTitleList = jobTitleService.selectJobTitleList(jobTitle);
        return success(jobTitleService.buildJobTitleTreeSelect(jobTitleList));
    }

    @GetMapping("/import")
    public AjaxResult importJobTitle()
    {
        jobTitleService.importJobTitle();
        return success();
    }

    @GetMapping("/levelOne")
    public AjaxResult levelOne()
    {
        List<JobTitle> result = jobTitleService.levelOne();
        return success(result);
    }
}
