package com.bohuikeji.delivery.backstage.controller.api.order;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bohuikeji.delivery.backstage.entity.TCourier;
import com.bohuikeji.delivery.backstage.entity.TOrder;
import com.bohuikeji.delivery.backstage.entity.TOrderCircu;
import com.bohuikeji.delivery.backstage.service.ITOrderCircuService;
import com.bohuikeji.delivery.backstage.service.ITOrderService;
import com.bohuikeji.delivery.backstage.service.third.ThirdUtils;
import com.bohuikeji.frame.module.admin.base.ApiController;
import com.bohuikeji.frame.module.admin.entity.back.APIEntity;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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 java.util.Collections;
import java.util.List;

/**
 * 订单流转信息
 * @author 10552
 */
@Slf4j
@Api(tags = {"订单流转记录相关接口"})
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/order/circe")
public class TorderCirceApi extends ApiController {
    final ITOrderCircuService circuService;
    final ITOrderService orderService;

    /**
     * 根据订单id查询订单详情
     * @return
     */
    @ApiOperation("根据订单id查询订单流转记录列表")
    @GetMapping("/get/by/order")
    @ApiImplicitParams({
            @ApiImplicitParam(name="orderId",value="订单id",dataType="Integer", paramType = "query")})
    public APIEntity<List<TOrderCircu>> getByOrder(Integer orderId){
        TOrder order=orderService.getById(orderId);
        if (order.getThird()){
            List<TOrderCircu> list= ThirdUtils.orderRecords(order.getThirdName(),order.getOrderNum(),order.getThirdNum());
            if (list!=null&&list.size()>0){
                Collections.reverse(list);
                return APIEntity.success(list);
            }
        }
        return APIEntity.success(circuService.list(new QueryWrapper<TOrderCircu>().eq("order_id",orderId).orderByDesc("order_circu_id")));
    }
}
