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.TDevCofferdam;
import com.ruoyi.project.patrol.dev.service.ITDevCofferdamService;
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/cofferdam")
public class TDevCofferdamController extends BaseController
{
    @Autowired
    private ITDevCofferdamService tDevCofferdamService;

    /**
     * 查询蒸汽裂解装置各区域围堰列表
     */
    @PreAuthorize("@ss.hasPermi('dev:cofferdam:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDevCofferdam tDevCofferdam)
    {
        startPage();
        List<TDevCofferdam> list = tDevCofferdamService.selectTDevCofferdamList(tDevCofferdam);
        return getDataTable(list);
    }

    /**
     * 导出蒸汽裂解装置各区域围堰列表
     */
    
    @Log(title = "蒸汽裂解装置各区域围堰", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(TDevCofferdam tDevCofferdam)
    {
        List<TDevCofferdam> list = tDevCofferdamService.selectTDevCofferdamList(tDevCofferdam);
        ExcelUtil<TDevCofferdam> util = new ExcelUtil<TDevCofferdam>(TDevCofferdam.class);
        return util.exportExcel(list,  "蒸汽裂解装置各区域围堰数据");
    }

    @Log(title = "蒸汽裂解装置各区域围堰二维码导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportQRCode")
    public void exportQRCode(HttpServletResponse response, TDevCofferdam tDevCofferdam) {
        List<TDevCofferdam> list = tDevCofferdamService.selectTDevCofferdamList(tDevCofferdam);
        List<QRCodeEntity> qrCodeEntities = new ArrayList<>();
        for (TDevCofferdam 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:cofferdam:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tDevCofferdamService.selectTDevCofferdamById(id));
    }

    /**
     * 新增蒸汽裂解装置各区域围堰
     */
    @PreAuthorize("@ss.hasPermi('dev:cofferdam:add')")
    @Log(title = "蒸汽裂解装置各区域围堰", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDevCofferdam tDevCofferdam)
    {
        return toAjax(tDevCofferdamService.insertTDevCofferdam(tDevCofferdam));
    }

    /**
     * 修改蒸汽裂解装置各区域围堰
     */
    @PreAuthorize("@ss.hasPermi('dev:cofferdam:edit')")
    @Log(title = "蒸汽裂解装置各区域围堰", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDevCofferdam tDevCofferdam)
    {
        return toAjax(tDevCofferdamService.updateTDevCofferdam(tDevCofferdam));
    }

    /**
     * 删除蒸汽裂解装置各区域围堰
     */
    @PreAuthorize("@ss.hasPermi('dev:cofferdam:remove')")
    @Log(title = "蒸汽裂解装置各区域围堰", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tDevCofferdamService.deleteTDevCofferdamByIds(ids));
    }
}
