package com.fs.survey;

import java.util.List;

import com.fs.common.config.LoginContextManager;
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.survey.domain.SurveyTaskPeriod;
import com.fs.survey.service.ISurveyTaskPeriodService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 问卷任务期次Controller
 * 
 * @author fs
 * @date 2026-02-06
 */
@RestController
@RequestMapping("/survey/period")
public class SurveyTaskPeriodController extends BaseController
{
    @Autowired
    private ISurveyTaskPeriodService surveyTaskPeriodService;

    /**
     * 查询问卷任务期次列表
     */
    @PreAuthorize("@ss.hasPermi('survey:period:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurveyTaskPeriod surveyTaskPeriod)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        surveyTaskPeriod.setCompanyId(currentCompanyId);
        startPage();
        List<SurveyTaskPeriod> list = surveyTaskPeriodService.selectSurveyTaskPeriodList(surveyTaskPeriod);
        return getDataTable(list);
    }

    /**
     * 导出问卷任务期次列表
     */
    @PreAuthorize("@ss.hasPermi('survey:period:export')")
    @Log(title = "问卷任务期次", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SurveyTaskPeriod surveyTaskPeriod)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        surveyTaskPeriod.setCompanyId(currentCompanyId);
        List<SurveyTaskPeriod> list = surveyTaskPeriodService.selectSurveyTaskPeriodList(surveyTaskPeriod);
        ExcelUtil<SurveyTaskPeriod> util = new ExcelUtil<SurveyTaskPeriod>(SurveyTaskPeriod.class);
        return util.exportExcel(list, "问卷任务期次数据");
    }

    /**
     * 获取问卷任务期次详细信息
     */
    @PreAuthorize("@ss.hasPermi('survey:period:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(surveyTaskPeriodService.selectSurveyTaskPeriodById(id));
    }

    /**
     * 新增问卷任务期次
     */
    @PreAuthorize("@ss.hasPermi('survey:period:add')")
    @Log(title = "问卷任务期次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurveyTaskPeriod surveyTaskPeriod)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        surveyTaskPeriod.setCompanyId(currentCompanyId);
        return toAjax(surveyTaskPeriodService.insertSurveyTaskPeriod(surveyTaskPeriod));
    }

    /**
     * 修改问卷任务期次
     */
    @PreAuthorize("@ss.hasPermi('survey:period:edit')")
    @Log(title = "问卷任务期次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurveyTaskPeriod surveyTaskPeriod)
    {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();
        surveyTaskPeriod.setCompanyId(currentCompanyId);
        return toAjax(surveyTaskPeriodService.updateSurveyTaskPeriod(surveyTaskPeriod));
    }

    /**
     * 删除问卷任务期次
     */
    @PreAuthorize("@ss.hasPermi('survey:period:remove')")
    @Log(title = "问卷任务期次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surveyTaskPeriodService.deleteSurveyTaskPeriodByIds(ids));
    }
}
