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.TDevWaterCannon;
import com.ruoyi.project.patrol.dev.service.ITDevWaterCannonService;
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-10-30
 */
@RestController
@RequestMapping("/dev/cannon")
public class TDevWaterCannonController extends BaseController
{
    @Autowired
    private ITDevWaterCannonService tDevWaterCannonService;

    /**
     * 查询消防水炮检查记录列表
     */
    @PreAuthorize("@ss.hasPermi('dev:cannon:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDevWaterCannon tDevWaterCannon)
    {
        startPage();
        List<TDevWaterCannon> list = tDevWaterCannonService.selectTDevWaterCannonList(tDevWaterCannon);
        return getDataTable(list);
    }

    /**
     * 导出消防水炮检查记录列表
     */
    
    @Log(title = "消防水炮检查记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(TDevWaterCannon tDevWaterCannon)
    {
        List<TDevWaterCannon> list = tDevWaterCannonService.selectTDevWaterCannonList(tDevWaterCannon);
        ExcelUtil<TDevWaterCannon> util = new ExcelUtil<TDevWaterCannon>(TDevWaterCannon.class);
        return util.exportExcel(list,  "消防水炮检查记录数据");
    }

    @Log(title = "洗眼器", businessType = BusinessType.EXPORT)
    @PostMapping("/exportQRCode")
    public void exportQRCode(HttpServletResponse response, TDevWaterCannon tDevWaterCannon){
        List<TDevWaterCannon> list = tDevWaterCannonService.selectTDevWaterCannonList(tDevWaterCannon);
        List<QRCodeEntity> qrCodeEntities = new ArrayList<>();
        for (TDevWaterCannon 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:cannon:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tDevWaterCannonService.selectTDevWaterCannonById(id));
    }

    /**
     * 新增消防水炮检查记录
     */
    @PreAuthorize("@ss.hasPermi('dev:cannon:add')")
    @Log(title = "消防水炮检查记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDevWaterCannon tDevWaterCannon)
    {
        return toAjax(tDevWaterCannonService.insertTDevWaterCannon(tDevWaterCannon));
    }

    /**
     * 修改消防水炮检查记录
     */
    @PreAuthorize("@ss.hasPermi('dev:cannon:edit')")
    @Log(title = "消防水炮检查记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDevWaterCannon tDevWaterCannon)
    {
        return toAjax(tDevWaterCannonService.updateTDevWaterCannon(tDevWaterCannon));
    }

    /**
     * 删除消防水炮检查记录
     */
    @PreAuthorize("@ss.hasPermi('dev:cannon:remove')")
    @Log(title = "消防水炮检查记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tDevWaterCannonService.deleteTDevWaterCannonByIds(ids));
    }
}
