package com.poyee;

import com.tzy.PoyiApplication;
import com.tzy.common.utils.DateUtils;
import com.tzy.pojo.card.CardGroupGoods;
import com.tzy.pojo.card.CardGroupOrderInfo;
import com.tzy.sportcard.api.mapper.MineApiMapper;
import com.tzy.sportcard.api.service.AsyncAppService;
import com.tzy.sportcard.group.mapper.TzyMerchantInfoMapper;
import com.tzy.sportcard.group.service.ICardGroupOrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.teasoft.bee.osql.Op;
import org.teasoft.bee.osql.PreparedSql;
import org.teasoft.bee.osql.SuidRich;
import org.teasoft.honey.osql.core.ConditionImpl;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@SpringBootTest(classes = PoyiApplication.class)
@RunWith(SpringRunner.class)
class AppOrderTest {

	@Resource
	private TzyMerchantInfoMapper tzyMerchantInfoMapper;
	@Autowired
	private ICardGroupOrderInfoService orderInfoService;
	@Autowired
	private PreparedSql preparedSql;
	@Resource
	private MineApiMapper mineApiMapper;
	@Autowired
	private SuidRich suidRich;
	@Autowired
	private AsyncAppService asyncAppService;
	@Test
	public void merchantOrderNotice() {
		com.tzy.sportcard.group.domain.CardGroupOrderInfo orderInfo = new com.tzy.sportcard.group.domain.CardGroupOrderInfo();
		orderInfo.setId(23542L);
		orderInfo.setMerchantId(13L);
		orderInfo.setAppUserNickName("yu");
		asyncAppService.sendMerchantNotice(orderInfo);
	}
	@Test
	public void testQueryIn() {
		ConditionImpl condition = new ConditionImpl();
		List<Integer> ids = new ArrayList<>();
		ids.add(346920);
		ids.add(346921);
		condition.op("id", Op.in,ids);
		CardGroupGoods goods = new CardGroupGoods();
		//goods.setLockStatus(1);
		//int update = suidRich.update(goods,condition);
		//System.out.println(update);
		List<CardGroupGoods> select = suidRich.select(goods, condition);
		System.out.println(select);
	}

	@Test
	public void testPickUpOrder() {
		CardGroupOrderInfo condition = new CardGroupOrderInfo();
		condition.setUserId(179L);
		//组团下所有中卡订单全部改为自提
		//自提确认收货 即代表订单完成
		condition.setGroupInfoId(547L);
		condition.setStatus(103L);
		CardGroupOrderInfo updateInfo = new CardGroupOrderInfo();
		updateInfo.setStatus(301L);
		updateInfo.setPickUpType("1");
		updateInfo.setShipTime(DateUtils.getTimestampNow());
		suidRich.update(condition,updateInfo);
	}


	@Test
	public void tesCheckOrder() {
		String[] orderIds = "20095,20941".split(",");
		orderInfoService.checkIsWaitShipping(orderIds);

	}

	@Test
	public void testreturnId() {
		com.tzy.sportcard.group.domain.CardGroupOrderInfo order = new com.tzy.sportcard.group.domain.CardGroupOrderInfo();
		order.setGroupInfoId(455L);
		order.setActualPayment(BigDecimal.TEN);
		long id = orderInfoService.insertCardGroupOrderInfo(order);
		System.out.println(id);
	}

	//public static void main(String[] args) {
	//	List<CardGroupOrderInfo> orders=new ArrayList<>();
	//	CardGroupOrderInfo order1 = new CardGroupOrderInfo();
	//	order1.setUserId(1L);
	//	CardGroupOrderInfo order2 = new CardGroupOrderInfo();
	//	order2.setUserId(2L);
	//	CardGroupOrderInfo order3 = new CardGroupOrderInfo();
	//	order3.setUserId(2L);
	//	orders.add(order1);
	//	orders.add(order2);
	//	orders.add(order3);
	//	Map<Long, CardGroupOrderInfo> distinctUserOrders = orders.stream().collect(Collectors.toMap(CardGroupOrderInfo::getUserId, u -> u,(key1, key2) -> key1));
	//	System.out.println(distinctUserOrders.size());
	//}



}
