package com.cpxt.web.controller.biz;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cpxt.biz.domain.BizCar;
import com.cpxt.biz.domain.BizDriverState;
import com.cpxt.biz.service.BizDriverStateService;
import com.cpxt.common.annotation.Log;
import com.cpxt.common.core.domain.AjaxResult;
import com.cpxt.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/biz/driver/state")
public class BizDriverStateController {

    @Autowired
    private BizDriverStateService bizDriverStateService;

    /**
     * 查询司机定位信息
     */
    @GetMapping("/list")
    public AjaxResult list() {
        return AjaxResult.success(bizDriverStateService.selectDriverLocation());
    }

    /**
     * 查询司机轨迹信息
     */
    @GetMapping("/track")
    public AjaxResult list(@RequestParam(required = false) String startTime,
                           @RequestParam(required = false) String endTime,
                           @RequestParam Long driverId) {
        String tableName = "track_driver_" + driverId;
        return AjaxResult.success(bizDriverStateService.selectDriverTrack(startTime, endTime, tableName));
    }

    /**
     * 新增司机轨迹
     */
    @PostMapping("/add")
    @Transactional
    public AjaxResult add(@RequestBody BizDriverState bizDriverState) {
        // 同步新增到司机对应的轨迹表中
        bizDriverStateService.insertDriveDriveState(bizDriverState);
        bizDriverState.setId(null);
        return AjaxResult.success(bizDriverStateService.save(bizDriverState));
    }
}
