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.TDevHoseBox;
import com.ruoyi.project.patrol.dev.service.ITDevHoseBoxService;
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-31
 */
@RestController
@RequestMapping("/dev/hoseBox")
public class TDevHoseBoxController extends BaseController
{
    @Autowired
    private ITDevHoseBoxService tDevHoseBoxService;

    /**
     * 查询消防水带箱检查记录列表
     */
    @PreAuthorize("@ss.hasPermi('dev:hoseBox:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDevHoseBox tDevHoseBox)
    {
        startPage();
        List<TDevHoseBox> list = tDevHoseBoxService.selectTDevHoseBoxList(tDevHoseBox);
        return getDataTable(list);
    }

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

    @Log(title = "消防水带箱二维码导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportQRCode")
    public void exportQRCode(HttpServletResponse response, TDevHoseBox tDevHoseBox) {
        List<TDevHoseBox> list = tDevHoseBoxService.selectTDevHoseBoxList(tDevHoseBox);
        List<QRCodeEntity> qrCodeEntities = new ArrayList<>();
        for (TDevHoseBox 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:hoseBox:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tDevHoseBoxService.selectTDevHoseBoxById(id));
    }

    /**
     * 新增消防水带箱检查记录
     */
    @PreAuthorize("@ss.hasPermi('dev:hoseBox:add')")
    @Log(title = "消防水带箱检查记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDevHoseBox tDevHoseBox)
    {
        return toAjax(tDevHoseBoxService.insertTDevHoseBox(tDevHoseBox));
    }

    /**
     * 修改消防水带箱检查记录
     */
    @PreAuthorize("@ss.hasPermi('dev:hoseBox:edit')")
    @Log(title = "消防水带箱检查记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDevHoseBox tDevHoseBox)
    {
        return toAjax(tDevHoseBoxService.updateTDevHoseBox(tDevHoseBox));
    }

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