package com.ruoyi.business.state.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.business.state.domain.StateModel;
import com.ruoyi.business.state.service.IStateModelService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 调查问卷模板Controller
 * 
 * @author Duke_yzl
 * @date 2023-06-26
 */
@RestController
@RequestMapping("/business/stateModel")
public class StateModelController extends BaseController
{
    @Autowired
    private IStateModelService stateModelService;

    /**
     * 查询调查问卷模板列表
     */
    @SaCheckPermission("business:stateModel:list")
    @GetMapping("/list")
    public TableDataInfo list(StateModel stateModel)
    {
        startPage();
        List<StateModel> list = stateModelService.selectStateModelList(stateModel);

        return getDataTable(list);
    }

    /**
     * 导出调查问卷模板列表
     */
    @SaCheckPermission("business:stateModel:export")
    @Log(title = "调查问卷模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StateModel stateModel)
    {
        List<StateModel> list = stateModelService.selectStateModelList(stateModel);
        ExcelUtil<StateModel> util = new ExcelUtil<StateModel>(StateModel.class);
        util.exportExcel(response, list, "调查问卷模板数据");
    }

    /**
     * 获取调查问卷模板详细信息
     */
    @SaCheckPermission("business:stateModel:query")
    @GetMapping(value = "/{modelId}")
    public AjaxResult getInfo(@PathVariable("modelId") Long modelId)
    {
        return success(stateModelService.selectStateModelByModelId(modelId));
    }

    /**
     * 新增调查问卷模板
     */
    @SaCheckPermission("business:stateModel:add")
    @Log(title = "调查问卷模板", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody StateModel stateModel)
    {
        return toAjax(stateModelService.insertStateModel(stateModel));
    }

    /**
     * 修改调查问卷模板
     */
    @SaCheckPermission("business:stateModel:edit")
    @Log(title = "调查问卷模板", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@RequestBody StateModel stateModel)
    {
        return toAjax(stateModelService.updateStateModel(stateModel));
    }

    /**
     * 删除调查问卷模板
     */
    @SaCheckPermission("business:stateModel:remove")
    @Log(title = "调查问卷模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{modelIds}")
    public AjaxResult remove(@PathVariable Long[] modelIds)
    {
        return toAjax(stateModelService.deleteStateModelByModelIds(modelIds));
    }
}
