package com.fs.qw.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.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.sop.domain.QwSopTemp;
import com.fs.sop.params.QwSopShareTempParam;
import com.fs.sop.service.IQwSopTempService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * sop模板Controller
 *
 * @author fs
 * @date 2024-09-26
 */
@RestController
@RequestMapping("/qw/sopTemp")
public class QwSopTempController extends BaseController
{
    @Autowired
    private IQwSopTempService qwSopTempService;
    /**
     * 查询sop模板列表
     */
    @GetMapping("/list")
    public TableDataInfo list(QwSopTemp qwSopTemp)
    {
        startPage();
        List<QwSopTemp> list = qwSopTempService.selectQwSopTempList(qwSopTemp);
        return getDataTable(list);
    }

    /**
     * 导出sop模板列表
     */
    @PreAuthorize("@ss.hasPermi('qw:sopTemp:export')")
    @Log(title = "sop模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwSopTemp qwSopTemp)
    {
        List<QwSopTemp> list = qwSopTempService.selectQwSopTempList(qwSopTemp);
        ExcelUtil<QwSopTemp> util = new ExcelUtil<QwSopTemp>(QwSopTemp.class);
        return util.exportExcel(list, "sop模板数据");
    }

    /**
     * 获取sop模板详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(qwSopTempService.selectQwSopTempById(id));
    }

    /**
     * 新增sop模板
     */
    @PreAuthorize("@ss.hasPermi('qw:sopTemp:add')")
    @Log(title = "sop模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwSopTemp qwSopTemp)
    {
        return toAjax(qwSopTempService.insertQwSopTemp(qwSopTemp));
    }

    /**
     * 修改sop模板
     */
    @PreAuthorize("@ss.hasPermi('qw:sopTemp:edit')")
    @Log(title = "sop模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwSopTemp qwSopTemp)
    {

        SimpleDateFormat slf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        qwSopTemp.setUpdateTime(slf.format(new Date()));
        return toAjax(qwSopTempService.updateQwSopTemp(qwSopTemp));
    }

    /**
     * 删除sop模板
     */
    @PreAuthorize("@ss.hasPermi('qw:sopTemp:remove')")
    @Log(title = "sop模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        ;
//        qwSopTempService.deleteQwSopTempByIds(ids);
        return toAjax(qwSopTempService.updateQwSopTempByIds(ids));
    }
}
