package com.prolog.cs.biz.outbound.service.impl;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import com.prolog.cs.basic.warehouse.model.vo.WhWorkstationQueryVO;
import com.prolog.cs.biz.outbound.Application;
import com.prolog.cs.biz.outbound.dao.WaveBillMapper;
import com.prolog.cs.biz.outbound.model.entity.WaveBillDO;
import com.prolog.cs.biz.outbound.resource.ItemClient;
import com.prolog.cs.biz.outbound.resource.WarehouseResource;
import com.prolog.framework.authority.util.HystrixVarUtil;
import com.prolog.framework.bz.common.search.SearchApi;
import com.prolog.framework.bz.common.search.TestModel;
import com.prolog.framework.core.restriction.Criteria;
import com.prolog.framework.utils.MapUtils;
import org.assertj.core.util.Arrays;
import org.junit.Before;
import org.junit.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.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import java.util.List;


/**
 * 基础测试类
 *
 * @author stylefeng
 * @Date 2017/5/21 16:10
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@WebAppConfiguration
//@Transactional //打开的话测试之后数据可自动回滚
public class BaseJunit {

    @Autowired
    WebApplicationContext webApplicationContext;
    @Autowired
    PickTaskAppServiceImpl PickTaskAppServiceImpl;

    protected MockMvc mockMvc;

    @Autowired
    private WarehouseResource warehouseResource;

    @Autowired
    private WaveBillMapper billMapper;

    @Before
    public void setupMockMvc(){
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
    }

    @Before
    public void initDatabase(){
    }
    
    @Test
    public void outerCheckUnCheck() throws Exception {

        Criteria cr = Criteria.forClass(WaveBillDO.class);
        cr.restrictionBuilder().eq("srcId", "SJ1060000174").eq("isMerged", 1);
        cr.buildRestriction();
        System.out.println(billMapper.findCountByCriteria(cr)==0L);
//        HystrixRequestContext context = HystrixRequestContext.initializeContext();
//        HystrixVarUtil.setUserKey("kzywms-admin");
////        JSON.toJSONString(PickTaskAppServiceImpl.outerCheckUnCheck("599581810778836992","ZHY1000000030",
////                "599581702716788736",1,1));
//        WhWorkstationQueryVO WhWorkstationQueryVO=new WhWorkstationQueryVO();
//        WhWorkstationQueryVO.setCode("FH2-01");
//        WhWorkstationQueryVO.setWarehouseId("599581702716788736");
//        System.out.println(JSON.toJSONString(warehouseResource.queryList(WhWorkstationQueryVO)));
    }

    public static void main(String[] args) {
        List list= Arrays.asList(new Integer[]{1,2,3,4});
        list.forEach(x -> {
            if((Integer) x==2){
                return;
            }
            System.out.println(x);
        });
    }
}
