package com.sooka.sponest.monitor.meiqiguan.gps.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.sooka.sponest.monitor.meiqiguan.gps.domain.GasTankHistoricalTrajectory;
import com.sooka.sponest.monitor.meiqiguan.gps.service.IGasTankHistoricalTrajectoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 历史轨迹Controller
 *
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/gps/trajectory")
public class GasTankHistoricalTrajectoryController extends BaseController {
    @Autowired
    private IGasTankHistoricalTrajectoryService gasTankHistoricalTrajectoryService;

    /**
     * 查询历史轨迹列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GasTankHistoricalTrajectory gasTankHistoricalTrajectory) {
        startPage();
        List<GasTankHistoricalTrajectory> list = gasTankHistoricalTrajectoryService.selectGasTankHistoricalTrajectoryList(gasTankHistoricalTrajectory);
        return getDataTable(list);
    }

    /**
     * 导出历史轨迹列表
     */
    @Log(title = "历史轨迹", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GasTankHistoricalTrajectory gasTankHistoricalTrajectory) {
        List<GasTankHistoricalTrajectory> list = gasTankHistoricalTrajectoryService.selectGasTankHistoricalTrajectoryList(gasTankHistoricalTrajectory);
        ExcelUtil<GasTankHistoricalTrajectory> util = new ExcelUtil<GasTankHistoricalTrajectory>(GasTankHistoricalTrajectory.class);
        util.exportExcel(response, list, "历史轨迹数据");
    }

    /**
     * 获取历史轨迹详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(gasTankHistoricalTrajectoryService.selectGasTankHistoricalTrajectoryById(id));
    }

    /**
     * 新增历史轨迹
     */
    @Log(title = "历史轨迹", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GasTankHistoricalTrajectory gasTankHistoricalTrajectory) {
        return toAjax(gasTankHistoricalTrajectoryService.insertGasTankHistoricalTrajectory(gasTankHistoricalTrajectory));
    }

    /**
     * 修改历史轨迹
     */
    @Log(title = "历史轨迹", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GasTankHistoricalTrajectory gasTankHistoricalTrajectory) {
        return toAjax(gasTankHistoricalTrajectoryService.updateGasTankHistoricalTrajectory(gasTankHistoricalTrajectory));
    }

    /**
     * 删除历史轨迹
     */
    @Log(title = "历史轨迹", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(gasTankHistoricalTrajectoryService.deleteGasTankHistoricalTrajectoryByIds(ids));
    }

    /**
     * 根据设备id获取历史轨迹和行程列表
     */
    @GetMapping(value = "/selectGasTankHistoricalTrajectoryListByDeviceid")
    public AjaxResult selectGasTankHistoricalTrajectoryListByDeviceid(GasTankHistoricalTrajectory gasTankHistoricalTrajectory) {
        return AjaxResult.success(gasTankHistoricalTrajectoryService.selectGasTankHistoricalTrajectoryListByDeviceid(gasTankHistoricalTrajectory));
    }

}
