package com.clx.performance;

import cn.hutool.json.JSONUtil;
import com.clx.order.feign.OrderFeign;
import com.clx.order.vo.feign.OrderOwnTruckVo;
import com.clx.performance.component.GoodsOrderTruckRecordComponent;
import com.clx.performance.component.OrderGoodsStatusLazyComponent;
import com.clx.performance.constant.RabbitKeyConstants;
import com.clx.performance.dao.OrderGoodsDao;
import com.clx.performance.feign.TransportFeignService;
import com.clx.performance.model.OrderChild;
import com.clx.performance.model.OrderGoods;
import com.clx.performance.param.feign.transport.ThirdOrderChildBrokerParam;
import com.clx.performance.param.mq.OrderCancelMqParam;
import com.clx.performance.service.OrderCancelService;
import com.clx.performance.vo.feign.transport.ThirdOrderChildBrokerResultVO;
import com.clx.user.feign.TruckFeign;
import com.msl.common.result.Result;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

@SpringBootTest
@RunWith(SpringRunner.class)
public class JobTest {

    @Autowired
    private OrderFeign orderFeign;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private OrderGoodsStatusLazyComponent orderGoodsStatusLazyComponent;

    @Autowired
    private OrderGoodsDao orderGoodsDao;

    @Autowired
    private GoodsOrderTruckRecordComponent recordComponent;

    @Autowired
    private OrderCancelService orderCancelService;

    @Autowired
    private TransportFeignService transportFeignService;

    @Test
    public void test1() {

//        OrderCancelMqParam mqParam = new OrderCancelMqParam();
//        mqParam.setType("2");
//        mqParam.setOrderNo("123");
//        Message message = MessageBuilder.withBody(JSONUtil.parse(mqParam).toString().getBytes()).build();
//        rabbitTemplate.send(
//                RabbitKeyConstants.ORDER_CANCEL_EXCHANGE, RabbitKeyConstants.ORDER_CANCEL_ROUTE_KEY, message
//        );

        //orderCancelService.ownerCancelOrderPre("PT2023102700473");
        //orderCancelService.ownerCancelOrder("PT2023102600466");
        OrderChild orderChild = new OrderChild();
        OrderGoods orderGoods = new OrderGoods();
        ThirdOrderChildBrokerParam param = new ThirdOrderChildBrokerParam();
        param.setOrderNo(orderChild.getOrderNo());
        param.setChildNo(orderChild.getChildNo());
        param.setTruckNo(orderChild.getTruckNo());
        param.setFreightPrice(Integer.valueOf(orderChild.getFreightPrice().toString()));
        param.setFreight(Integer.valueOf(orderChild.getFreight().toString()));
        param.setSendAddress(orderGoods.getSendAddressShorter());
        //缺省市区
        param.setSendName(orderGoods.getUserName());


        Result<ThirdOrderChildBrokerResultVO> thirdOrderChildBrokerResultVOResult = transportFeignService.orderChildSync(param);
        System.out.println(thirdOrderChildBrokerResultVOResult);
    }
}
