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.project.domain.ProjectSettings;
import com.fs.project.service.IProjectSettingsService;
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 2026-01-12
 */
@RestController
@RequestMapping("/project/settings")
public class ProjectSettingsController extends BaseController
{
    @Autowired
    private IProjectSettingsService projectSettingsService;

    /**
     * 查询项目设置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ProjectSettings projectSettings)
    {
        startPage();
        List<ProjectSettings> list = projectSettingsService.selectProjectSettingsList(projectSettings);
        return getDataTable(list);
    }

    /**
     * 导出项目设置列表
     */
    @GetMapping("/export")
    public AjaxResult export(ProjectSettings projectSettings)
    {
        List<ProjectSettings> list = projectSettingsService.selectProjectSettingsList(projectSettings);
        ExcelUtil<ProjectSettings> util = new ExcelUtil<ProjectSettings>(ProjectSettings.class);
        return util.exportExcel(list, "项目设置数据");
    }

    /**
     * 获取项目设置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(projectSettingsService.selectProjectSettingsById(id));
    }

    /**
     * 新增项目设置
     */
    @PostMapping
    public AjaxResult add(@RequestBody ProjectSettings projectSettings)
    {
        return toAjax(projectSettingsService.insertProjectSettings(projectSettings));
    }

    /**
     * 修改项目设置
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectSettings projectSettings)
    {
        return toAjax(projectSettingsService.updateProjectSettings(projectSettings));
    }

    /**
     * 删除项目设置
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectSettingsService.deleteProjectSettingsByIds(ids));
    }

    /**
     * 查询指定公司下的项目设置列表
     */
    @GetMapping("/company/{companyId}")
    public AjaxResult listByCompanyId(@PathVariable String companyId)
    {
        return AjaxResult.success(projectSettingsService.selectProjectSettingsByCompanyId(companyId));
    }
}
