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.TDevPostFire;
import com.ruoyi.project.patrol.dev.service.ITDevPostFireService;
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 ruoyi
 * @date 2023-10-30
 */
@RestController
@RequestMapping("/dev/postFire")
public class TDevPostFireController extends BaseController
{
    @Autowired
    private ITDevPostFireService tDevPostFireService;

    /**
     * 查询地上消火栓检查记录列表
     */
    @PreAuthorize("@ss.hasPermi('dev:postFire:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDevPostFire tDevPostFire)
    {
        startPage();
        List<TDevPostFire> list = tDevPostFireService.selectTDevPostFireList(tDevPostFire);
        return getDataTable(list);
    }

    /**
     * 导出地上消火栓检查记录列表
     */
    
    @Log(title = "地上消火栓检查记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(TDevPostFire tDevPostFire)
    {
        List<TDevPostFire> list = tDevPostFireService.selectTDevPostFireList(tDevPostFire);
        ExcelUtil<TDevPostFire> util = new ExcelUtil<TDevPostFire>(TDevPostFire.class);
        return util.exportExcel(list,  "地上消火栓检查记录数据");
    }

    @Log(title = "地上消火栓二维码导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportQRCode")
    public void exportQRCode(HttpServletResponse response, TDevPostFire tDevPostFire) {
        List<TDevPostFire> list = tDevPostFireService.selectTDevPostFireList(tDevPostFire);
        List<QRCodeEntity> qrCodeEntities = new ArrayList<>();
        for (TDevPostFire item : list) {
            qrCodeEntities.add(new QRCodeEntity(item.getId(), item.getDevNo(),item.getPatrolType(), item.getPosition()));
        }
        QRCodeUtil<QRCodeEntity> util = new QRCodeUtil<>(QRCodeEntity.class);
        util.exportQRCode(response, qrCodeEntities);
    }

    /**
     * 获取地上消火栓检查记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('dev:postFire:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tDevPostFireService.selectTDevPostFireById(id));
    }

    /**
     * 新增地上消火栓检查记录
     */
    @PreAuthorize("@ss.hasPermi('dev:postFire:add')")
    @Log(title = "地上消火栓检查记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDevPostFire tDevPostFire)
    {
        return toAjax(tDevPostFireService.insertTDevPostFire(tDevPostFire));
    }

    /**
     * 修改地上消火栓检查记录
     */
    @PreAuthorize("@ss.hasPermi('dev:postFire:edit')")
    @Log(title = "地上消火栓检查记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDevPostFire tDevPostFire)
    {
        return toAjax(tDevPostFireService.updateTDevPostFire(tDevPostFire));
    }

    /**
     * 删除地上消火栓检查记录
     */
    @PreAuthorize("@ss.hasPermi('dev:postFire:remove')")
    @Log(title = "地上消火栓检查记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tDevPostFireService.deleteTDevPostFireByIds(ids));
    }
}
