package com.zjsgfa.project.zjsgfa.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zjsgfa.framework.aspectj.lang.annotation.Log;
import com.zjsgfa.framework.aspectj.lang.enums.BusinessType;
import com.zjsgfa.project.zjsgfa.domain.Czsms;
import com.zjsgfa.project.zjsgfa.service.ICzsmsService;
import com.zjsgfa.framework.web.controller.BaseController;
import com.zjsgfa.framework.web.domain.AjaxResult;
import com.zjsgfa.common.utils.poi.ExcelUtil;
import com.zjsgfa.framework.web.page.TableDataInfo;

/**
 * 操作说明书Controller
 * 
 * @author ruoyi
 * @date 2026-03-25
 */
@RestController
@RequestMapping("/system/czsms")
public class CzsmsController extends BaseController
{
    @Autowired
    private ICzsmsService czsmsService;

    /**
     * 查询操作说明书列表
     */
    //@PreAuthorize("@ss.hasPermi('system:czsms:list')")
    @GetMapping("/list")
    public TableDataInfo list(Czsms czsms)
    {
//        startPage();
        List<Czsms> list = czsmsService.selectCzsmsList(czsms);
        return getDataTable(list);
    }

    /**
     * 导出操作说明书列表
     */
    //@PreAuthorize("@ss.hasPermi('system:czsms:export')")
    @Log(title = "操作说明书", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Czsms czsms)
    {
        List<Czsms> list = czsmsService.selectCzsmsList(czsms);
        ExcelUtil<Czsms> util = new ExcelUtil<Czsms>(Czsms.class);
        util.exportExcel(response, list, "操作说明书数据");
    }

    /**
     * 获取操作说明书详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:czsms:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(czsmsService.selectCzsmsById(id));
    }

    /**
     * 新增操作说明书
     */
    //@PreAuthorize("@ss.hasPermi('system:czsms:add')")
    @Log(title = "操作说明书", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Czsms czsms)
    {
        return toAjax(czsmsService.insertCzsms(czsms));
    }

    /**
     * 修改操作说明书
     */
    //@PreAuthorize("@ss.hasPermi('system:czsms:edit')")
    @Log(title = "操作说明书", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Czsms czsms)
    {
        return toAjax(czsmsService.updateCzsms(czsms));
    }

    /**
     * 删除操作说明书
     */
    //@PreAuthorize("@ss.hasPermi('system:czsms:remove')")
    @Log(title = "操作说明书", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(czsmsService.deleteCzsmsByIds(ids));
    }



    @GetMapping(value ="/getFilePath")
    public Map<String, Object> getFilePath(HttpServletResponse response)
    {
        List<Czsms> czsms = czsmsService.selectCzsmsList(new Czsms());
        String filePath = "";
        if(czsms.size()>0){
            filePath = czsms.get(0).getFilePath();
        }
        Map<String, Object> map = new HashMap<>();
        map.put("filePath", filePath);
        return map;
    }

}
