package com.ruoyi.record.controller;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.RuoYiConfig;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.record.domain.RecordBusbarTemp;
import com.ruoyi.record.service.IRecordBusbarTempService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 母排测温信息Controller
 *
 * @author zangch
 * @date 2024-11-07
 */
@RestController
@RequestMapping("/record/recordBusbarTemp")
public class RecordBusbarTempController extends BaseController
{
    @Autowired
    private IRecordBusbarTempService recordBusbarTempService;

    /**
     * 查询母排测温信息列表
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarTemp:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordBusbarTemp recordBusbarTemp)
    {
        startPage();
        List<RecordBusbarTemp> list = recordBusbarTempService.selectRecordBusbarTempList(recordBusbarTemp);
        return getDataTable(list);
    }

    /**
     * 导出母排测温信息列表
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarTemp:export')")
    @Log(title = "母排测温信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordBusbarTemp recordBusbarTemp)
    {
        List<RecordBusbarTemp> list = recordBusbarTempService.selectRecordBusbarTempList(recordBusbarTemp);
        ExcelUtil<RecordBusbarTemp> util = new ExcelUtil<RecordBusbarTemp>(RecordBusbarTemp.class);
        util.exportExcel(response, list, "母排测温信息数据");
    }

    /**
     * 获取母排测温信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarTemp:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId)
    {
        return success(recordBusbarTempService.selectRecordBusbarTempByObjId(objId));
    }

    /**
     * 新增母排测温信息
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarTemp:add')")
    @Log(title = "母排测温信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordBusbarTemp recordBusbarTemp)
    {
        return toAjax(recordBusbarTempService.insertRecordBusbarTemp(recordBusbarTemp));
    }

    /**
     * 修改母排测温信息
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarTemp:edit')")
    @Log(title = "母排测温信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordBusbarTemp recordBusbarTemp)
    {
        return toAjax(recordBusbarTempService.updateRecordBusbarTemp(recordBusbarTemp));
    }

    /**
     * 删除母排测温信息
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarTemp:remove')")
    @Log(title = "母排测温信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objIds}")
    public AjaxResult remove(@PathVariable Long[] objIds)
    {
        return toAjax(recordBusbarTempService.deleteRecordBusbarTempByObjIds(objIds));
    }


    /**
     * 获取可见光照片。
     * @param filePath 需要获取的可见光照片的文件路径。
     * @return 如果文件存在，返回包含文件资源的ResponseEntity对象；如果文件不存在，返回null。
     */
    @GetMapping("/getVisiblePhoto/{filePath}")
    public ResponseEntity<FileSystemResource> getVisiblePhoto(@PathVariable String filePath) {
        return recordBusbarTempService.getVisiblePhoto(filePath);
    }

    /**
     * 获取热成像照片。
     * @param filePath 需要获取的热成像照片的文件路径。
     * @return 如果文件存在，返回包含文件资源的响应实体；如果文件不存在，返回null（注释掉的代码是返回404状态）。
     */
    @GetMapping("/getThermalPhoto/{filePath}")
    public ResponseEntity<FileSystemResource> getThermalPhoto (@PathVariable String filePath) {
        return recordBusbarTempService.getThermalPhoto(filePath);
    }

    /**
     * 获取母排测温曲线。
     * @param recordBusbarTemp 需要查询的母线温度记录。
     * @return 返回一个AjaxResult对象，其中包含查询到的母线温度记录列表。
     */
    @GetMapping("/busbarTempCurve")
    public AjaxResult busbarTempCurve (RecordBusbarTemp recordBusbarTemp){
        List<RecordBusbarTemp> recordBusbarTempList = recordBusbarTempService
                .selectRecordBusbarTempList(recordBusbarTemp);
        return success(recordBusbarTempList);
    }


    /**
     * 获取母排测温记录列表。
     * @param recordBusbarTemp 母线温度记录对象，用于封装查询条件。
     * @return 返回一个AjaxResult对象，其中包含查询到的母线温度记录列表。
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarTemp:list')")
    @PostMapping("/recordBusbarTempList")
    public AjaxResult recordBusbarTempList(RecordBusbarTemp recordBusbarTemp)
    {
        List<RecordBusbarTemp> list = recordBusbarTempService.selectRecordBusbarTempList(recordBusbarTemp);
        return success(list);
    }

    /**
     * 获取母排测温记录列表。
     * @param recordBusbarTemp 母线温度记录对象，用于封装查询条件。
     * @return 返回一个AjaxResult对象，其中包含查询到的母线温度记录列表。
     */
    @PostMapping("/boardTempList")
    public AjaxResult boardTempList(RecordBusbarTemp recordBusbarTemp)
    {
        List<RecordBusbarTemp> list = recordBusbarTempService.boardTempList(recordBusbarTemp);
        return success(list);
    }



}
