package com.ruoyi.web.app;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.bst.locationLog.domain.LocationLogQuery;
import com.ruoyi.bst.locationLog.domain.LocationLogVO;
import com.ruoyi.bst.locationLog.service.LocationLogService;
import com.ruoyi.bst.order.service.OrderValidator;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

import io.swagger.annotations.ApiOperation;


@RestController
@RequestMapping("/app/locationLog")
public class AppLocationLogController extends BaseController {

    @Autowired
    private LocationLogService locationLogService;

    @Autowired
    private OrderValidator orderValidator;

    private boolean canView(Long orderId) {
        return orderValidator.isUser(orderId, getUserId());
    }

    @ApiOperation("根据订单ID查询定位日志")
    @GetMapping("/allByOrder")
    public AjaxResult getAllByOrder(Long orderId) {
        if (orderId == null) {
            return error("订单ID不允许为空");
        }
        if (!canView(orderId)) {
            return error("您无权查看ID为" + orderId + "的订单轨迹");
        }

        LocationLogQuery query = new LocationLogQuery();
        query.setOrderId(orderId);
        List<LocationLogVO> list = locationLogService.selectLocationLogList(query);
        return success(list);
    }
    
    
}
