package com.sckw.transport.controller.enterpriseApp;

import com.alibaba.fastjson.JSONObject;
import com.sckw.core.web.response.HttpResult;
import com.sckw.transport.model.param.AcceptCarriageOrderQuery;
import com.sckw.transport.service.KwtAcceptCarriageOrderService;
import com.sckw.transport.service.KwtWaybillOrderService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lfdc
 * @description 企业app承运controller
 * @date 2023-08-21 16:08:41
 */
@Slf4j
@RestController
@RequestMapping("/appKwtAcceptCarriageOrder")
public class AppAcceptCarriageController {

    @Autowired
    private KwtAcceptCarriageOrderService carriageOrderService;

    @Autowired
    private KwtWaybillOrderService waybillOrderService;

    @RequestMapping(name = "企业app订单管理数据承运订单统计", path = "/statisticsCarriage", method = RequestMethod.POST)
    public HttpResult statisticsCarriage(@Valid @RequestBody AcceptCarriageOrderQuery query) {
        log.info("企业app订单管理数据承运订单统计 query :{}", JSONObject.toJSONString(query));
        try {
            return HttpResult.ok(carriageOrderService.statisticsCarriage(query));
        } catch (Exception e) {
            log.error("企业app订单管理数据承运订单统计失败  query:{}, error:{}", JSONObject.toJSONString(query), e.getMessage(), e);
            return HttpResult.error(e.getMessage());
        }
    }

    @RequestMapping(name = "企业app承运订单详情统计", path = "/statisticsCarriageByOrderId", method = RequestMethod.GET)
    public HttpResult statisticsCarriageByOrderId(@NotBlank(message = "订单id不能为空") @RequestParam("orderId") String orderId) {
        log.info("企业app承运订单详情统计 query :{}", orderId);
        try {
            return HttpResult.ok(waybillOrderService.statisticsByOrderId(orderId,"2"));
        } catch (Exception e) {
            log.error("企业app承运订单详情统计失败  query:{}, error:{}", orderId, e.getMessage(), e);
            return HttpResult.error(e.getMessage());
        }
    }


    @RequestMapping(name = "企业app承运订单订单进度", path = "/getOrderTrackByOrderId", method = RequestMethod.GET)
    public HttpResult getOrderTrackByOrderId(@NotBlank(message = "订单id不能为空") @RequestParam("orderId") String orderId) {
        log.info("企业app承运订单订单进度 query :{}", orderId);
        try {
            return carriageOrderService.getOrderTrackByOrderId(orderId,"2");
        } catch (Exception e) {
            log.error("企业app承运订单订单进度失败  query:{}, error:{}", orderId, e.getMessage(), e);
            return HttpResult.error(e.getMessage());
        }
    }

}
