package com.fs.store.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.store.domain.FsTestTemp;
import com.fs.store.service.IFsTestTempService;
import com.fs.store.vo.OptionsVO;
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 2023-09-04
 */
@RestController
@RequestMapping("/his/testTemp")
public class FsTestTempController extends BaseController
{
    @Autowired
    private IFsTestTempService fsTestTempService;

    /**
     * 查询测一测模板列表
     */
    @PreAuthorize("@ss.hasPermi('his:testTemp:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsTestTemp fsTestTemp)
    {
        startPage();
        List<FsTestTemp> list = fsTestTempService.selectFsTestTempList(fsTestTemp);
        return getDataTable(list);
    }

    /**
     * 导出测一测模板列表
     */
    @PreAuthorize("@ss.hasPermi('his:testTemp:export')")
    @Log(title = "测一测模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsTestTemp fsTestTemp)
    {
        List<FsTestTemp> list = fsTestTempService.selectFsTestTempList(fsTestTemp);
        ExcelUtil<FsTestTemp> util = new ExcelUtil<FsTestTemp>(FsTestTemp.class);
        return util.exportExcel(list, "测一测模板数据");
    }

    /**
     * 获取测一测模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:testTemp:query')")
    @GetMapping(value = "/{tempId}")
    public AjaxResult getInfo(@PathVariable("tempId") Long tempId)
    {
        return AjaxResult.success(fsTestTempService.selectFsTestTempByTempId(tempId));
    }

    /**
     * 新增测一测模板
     */
    @PreAuthorize("@ss.hasPermi('his:testTemp:add')")
    @Log(title = "测一测模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsTestTemp fsTestTemp)
    {

        fsTestTemp.setTempCode("C"+System.currentTimeMillis());
        return toAjax(fsTestTempService.insertFsTestTemp(fsTestTemp));
    }

    /**
     * 修改测一测模板
     */
    @PreAuthorize("@ss.hasPermi('his:testTemp:edit')")
    @Log(title = "测一测模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsTestTemp fsTestTemp)
    {
        return toAjax(fsTestTempService.updateFsTestTemp(fsTestTemp));
    }

    /**
     * 删除测一测模板
     */
    @PreAuthorize("@ss.hasPermi('his:testTemp:remove')")
    @Log(title = "测一测模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tempIds}")
    public AjaxResult remove(@PathVariable Long[] tempIds)
    {
        return toAjax(fsTestTempService.deleteFsTestTempByTempIds(tempIds));
    }


    @GetMapping("/allList")
    public TableDataInfo getTestTemp()
    {
        List<OptionsVO> list = fsTestTempService.selectAllTestTempList();
        return getDataTable(list);
    }

    @GetMapping(value = "/getTempType/{tempId}")
    public AjaxResult getTempType(@PathVariable("tempId") Long tempId)
    {
        return AjaxResult.success(fsTestTempService.selectFsTempTypeByTempId(tempId));
    }

}
