package com.aiotagro.cattletrade.business.controller;


import com.aiotagro.cattletrade.business.dto.DeliveryQueryDto;
import com.aiotagro.cattletrade.business.dto.DeliverListDto;
import com.aiotagro.cattletrade.business.service.IDeliveryService;
import com.aiotagro.cattletrade.business.service.IWarningLogService;
import com.aiotagro.cattletrade.business.vo.DeliveryLogVo;
import com.aiotagro.common.core.web.domain.AjaxResult;
import com.aiotagro.common.core.web.domain.PageResultResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 预警记录表
 *
 * @author admin
 * @since 2024-12-26
 */
@RestController
@RequestMapping("/warningLog")
public class WarningLogController {

    @Autowired
    private IWarningLogService warningLogService;
    @Autowired
    private IDeliveryService deliveryService;

    /**
     * 供远程调用-保存预警日志
     */
    @GetMapping("/savaWarn")
    public AjaxResult savaWarn(@RequestParam String deviceId) {
        return warningLogService.savaWarn(deviceId);
    }

    /**
     * 运单预警-预警统计
     */
    @RequestMapping("/warningCount")
    public AjaxResult warningCount() {
        return warningLogService.warningCount();
    }

    /**
     * 运单预警-分页查询
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/queryList")
    public PageResultResponse<DeliveryLogVo> queryList(@RequestBody @Validated DeliveryQueryDto dto) {
        return warningLogService.queryList(dto);
    }

    /**
     * 预警记录详情
     */
    @RequestMapping("/warningDetail")
    public AjaxResult warningDetail(@RequestParam Integer id) {
        return warningLogService.warningDetail(id);
    }


    /**
     * 后台系统，预警记录
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/pageQuery")
    public PageResultResponse<DeliveryLogVo> pageQuery(@RequestBody DeliverListDto dto) {
        return deliveryService.pageQueryList(dto);
    }

    /**
     * 获取设备温度历史数据（用于温度预警详情）
     * 
     * @param deviceId 设备ID
     * @param startTime 开始时间（可选）
     * @param endTime 结束时间（可选）
     * @return 温度历史记录
     */
    @GetMapping("/getDeviceTemperatureHistory")
    public AjaxResult getDeviceTemperatureHistory(
            @RequestParam String deviceId,
            @RequestParam(required = false) String startTime,
            @RequestParam(required = false) String endTime) {
        return warningLogService.getDeviceTemperatureHistory(deviceId, startTime, endTime);
    }

    /**
     * 获取预警位置的设备轨迹数据（用于停留预警、位置偏离预警详情）
     * 
     * @param deliveryId 运单ID
     * @param warningTime 预警时间
     * @return 设备轨迹记录
     */
    @GetMapping("/getDeviceTrackAroundWarning")
    public AjaxResult getDeviceTrackAroundWarning(
            @RequestParam Integer deliveryId,
            @RequestParam String warningTime) {
        return warningLogService.getDeviceTrackAroundWarning(deliveryId, warningTime);
    }

}
