package com.ruoyi.project.patrol.dev.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.poi.QRCodeEntity;
import com.ruoyi.common.utils.poi.QRCodeUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.patrol.dev.domain.TDevSteamCurtain;
import com.ruoyi.project.patrol.dev.service.ITDevSteamCurtainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 蒸汽幕Controller
 *
 * @author admin
 * @date 2023-11-06
 */
@RestController
@RequestMapping("/dev/curtain")
public class TDevSteamCurtainController extends BaseController {
    @Autowired
    private ITDevSteamCurtainService tDevSteamCurtainService;

    /**
     * 查询蒸汽幕列表
     */
    @PreAuthorize("@ss.hasPermi('dev:curtain:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDevSteamCurtain tDevSteamCurtain) {
        startPage();
        List<TDevSteamCurtain> list = tDevSteamCurtainService.selectTDevSteamCurtainList(tDevSteamCurtain);
        return getDataTable(list);
    }

    /**
     * 导出蒸汽幕列表
     */
    
    @Log(title = "蒸汽幕", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(TDevSteamCurtain tDevSteamCurtain) {
        List<TDevSteamCurtain> list = tDevSteamCurtainService.selectTDevSteamCurtainList(tDevSteamCurtain);
        ExcelUtil<TDevSteamCurtain> util = new ExcelUtil<TDevSteamCurtain>(TDevSteamCurtain.class);
        return util.exportExcel(list,  "蒸汽幕数据");
    }

    @Log(title = "蒸汽幕二维码导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportQRCode")
    public void exportQRCode(HttpServletResponse response, TDevSteamCurtain tDevSteamCurtain) {
        List<TDevSteamCurtain> list = tDevSteamCurtainService.selectTDevSteamCurtainList(tDevSteamCurtain);
        List<QRCodeEntity> qrCodeEntities = new ArrayList<>();
        for (TDevSteamCurtain item : list) {
            qrCodeEntities.add(new QRCodeEntity(item.getId(), item.getDevNo(), item.getPatrolType(), ""));
        }
        QRCodeUtil<QRCodeEntity> util = new QRCodeUtil<>(QRCodeEntity.class);
        util.exportQRCode(response, qrCodeEntities);
    }

    /**
     * 获取蒸汽幕详细信息
     */
    @PreAuthorize("@ss.hasPermi('dev:curtain:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(tDevSteamCurtainService.selectTDevSteamCurtainById(id));
    }

    /**
     * 新增蒸汽幕
     */
    @PreAuthorize("@ss.hasPermi('dev:curtain:add')")
    @Log(title = "蒸汽幕", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDevSteamCurtain tDevSteamCurtain) {
        return toAjax(tDevSteamCurtainService.insertTDevSteamCurtain(tDevSteamCurtain));
    }

    /**
     * 修改蒸汽幕
     */
    @PreAuthorize("@ss.hasPermi('dev:curtain:edit')")
    @Log(title = "蒸汽幕", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDevSteamCurtain tDevSteamCurtain) {
        return toAjax(tDevSteamCurtainService.updateTDevSteamCurtain(tDevSteamCurtain));
    }

    /**
     * 删除蒸汽幕
     */
    @PreAuthorize("@ss.hasPermi('dev:curtain:remove')")
    @Log(title = "蒸汽幕", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tDevSteamCurtainService.deleteTDevSteamCurtainByIds(ids));
    }
}
