package com.fs.project.controller;

import com.fs.common.annotation.Log;
import com.fs.common.config.LoginContextManager;
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.project.domain.ProjectTaskType;
import com.fs.project.service.IProjectTaskTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目任务类型Controller
 * 
 * @author fs
 * @date 2025-12-30
 */
@RestController
@RequestMapping("/project/type")
public class ProjectTaskTypeController extends BaseController
{
    @Autowired
    private IProjectTaskTypeService projectTaskTypeService;

    /**
     * 查询项目任务类型列表
     */
    @PreAuthorize("@ss.hasPermi('project:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectTaskType projectTaskType)
    {
        startPage();
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        projectTaskType.setCompanyId(currentCompanyId);
        List<ProjectTaskType> list = projectTaskTypeService.selectProjectTaskTypeList(projectTaskType);
        return getDataTable(list);
    }

    /**
     * 导出项目任务类型列表
     */
    @PreAuthorize("@ss.hasPermi('project:type:export')")
    @Log(title = "项目任务类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProjectTaskType projectTaskType)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        projectTaskType.setCompanyId(currentCompanyId);
        List<ProjectTaskType> list = projectTaskTypeService.selectProjectTaskTypeList(projectTaskType);
        ExcelUtil<ProjectTaskType> util = new ExcelUtil<ProjectTaskType>(ProjectTaskType.class);
        return util.exportExcel(list, "项目任务类型数据");
    }

    /**
     * 获取项目任务类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(projectTaskTypeService.selectProjectTaskTypeById(id));
    }

    /**
     * 新增项目任务类型
     */
    @PreAuthorize("@ss.hasPermi('project:type:add')")
    @Log(title = "项目任务类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectTaskType projectTaskType)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        projectTaskType.setCompanyId(currentCompanyId);
        return toAjax(projectTaskTypeService.insertProjectTaskType(projectTaskType));
    }

    /**
     * 修改项目任务类型
     */
    @PreAuthorize("@ss.hasPermi('project:type:edit')")
    @Log(title = "项目任务类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectTaskType projectTaskType)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        projectTaskType.setCompanyId(currentCompanyId);
        return toAjax(projectTaskTypeService.updateProjectTaskType(projectTaskType));
    }

    /**
     * 删除项目任务类型
     */
    @PreAuthorize("@ss.hasPermi('project:type:remove')")
    @Log(title = "项目任务类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectTaskTypeService.deleteProjectTaskTypeByIds(ids));
    }




    @GetMapping("/selectProjectOptionsByDept")
    public AjaxResult optionsByDept(@RequestParam Long deptId,
                                    @RequestParam(required = false) String projectName) {
        return AjaxResult.success(projectTaskTypeService.selectProjectOptionsByDept(deptId, projectName));
    }



}
