package com.aucma.report.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

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.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.enums.BusinessType;
import com.aucma.report.domain.BoxTemperatureHistory;
import com.aucma.report.service.IBoxTemperatureHistoryService;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.common.core.page.TableDataInfo;

/**
 * 测温记录报表Controller
 *
 * @author Yinq
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/report/temperatureHistory" )
public class BoxTemperatureHistoryController extends BaseController {
    @Autowired
    private IBoxTemperatureHistoryService boxTemperatureHistoryService;

    /**
     * 查询测温记录报表列表
     */
//    @PreAuthorize("@ss.hasPermi('report:temperatureHistory:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(BoxTemperatureHistory boxTemperatureHistory) {
        startPage();
        List<BoxTemperatureHistory> list = boxTemperatureHistoryService.selectBoxTemperatureHistoryList(boxTemperatureHistory);
        return getDataTable(list);
    }

    /**
     * 导出测温记录报表列表
     */
//    @PreAuthorize("@ss.hasPermi('report:temperatureHistory:export')" )
    @Log(title = "测温记录报表" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, BoxTemperatureHistory boxTemperatureHistory) {
        List<BoxTemperatureHistory> list = boxTemperatureHistoryService.selectBoxTemperatureHistoryList(boxTemperatureHistory);
        ExcelUtil<BoxTemperatureHistory> util = new ExcelUtil<BoxTemperatureHistory>(BoxTemperatureHistory. class);
        util.exportExcel(response, list, "测温记录报表数据" );
    }

    /**
     * 获取测温记录报表详细信息
     */
//    @PreAuthorize("@ss.hasPermi('report:temperatureHistory:query')" )
    @GetMapping(value = "/{objId}" )
    public AjaxResult getInfo(@PathVariable("objId" ) Long objId) {
        return success(boxTemperatureHistoryService.selectBoxTemperatureHistoryByObjId(objId));
    }

    /**
     * 新增测温记录报表
     */
    @PreAuthorize("@ss.hasPermi('report:temperatureHistory:add')" )
    @Log(title = "测温记录报表" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BoxTemperatureHistory boxTemperatureHistory) {
        return toAjax(boxTemperatureHistoryService.insertBoxTemperatureHistory(boxTemperatureHistory));
    }

    /**
     * 修改测温记录报表
     */
    @PreAuthorize("@ss.hasPermi('report:temperatureHistory:edit')" )
    @Log(title = "测温记录报表" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BoxTemperatureHistory boxTemperatureHistory) {
        return toAjax(boxTemperatureHistoryService.updateBoxTemperatureHistory(boxTemperatureHistory));
    }

    /**
     * 删除测温记录报表
     */
    @PreAuthorize("@ss.hasPermi('report:temperatureHistory:remove')" )
    @Log(title = "测温记录报表" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}" )
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(boxTemperatureHistoryService.deleteBoxTemperatureHistoryByObjIds(objIds));
    }

    /**
     * 查看测试折线图
     * */

    @PostMapping("/testTemp")
    public AjaxResult getTestTemp(@RequestBody BoxTemperatureHistory boxTemperatureHistory){
        return success(boxTemperatureHistoryService.getTestTemp(boxTemperatureHistory));
    }
}
