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

import com.alibaba.fastjson.JSON;
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import com.prolog.cs.biz.inbound.Application;
import com.prolog.cs.biz.inbound.model.SupervisionCode;
import com.prolog.cs.biz.inbound.service.impl.SupervisionCodeServiceImpl;
import com.prolog.cs.biz.inbound.service.rcv.RcvHeadersService;
import com.prolog.framework.authority.util.HystrixVarUtil;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.Resource;
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;


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

    @Autowired
    WebApplicationContext webApplicationContext;

    protected MockMvc mockMvc;

    @Autowired
    private RcvHeadersService rcvHeadersService;
    
    @Autowired
    private SupervisionCodeServiceImpl SupervisionCodeServiceImpl;

    @Value("${prolog.wms.instockCallId}")
    private String instockCallId;

    @Value("${prolog.wms.instockTransforId}")
    private String instockTransforId;

    @Value("classpath:rcvDTO.json")
    private Resource rcvDTO;

    @Before
    public void setupMockMvc(){
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
        HystrixRequestContext context = HystrixRequestContext.initializeContext();
        HystrixVarUtil.setUserKey("cube_admin");
    }

    //空入入库
    @Test
    public void findCargoChangeList(){
        try {
            //扫描监管码节点：0=整件拣货、零货拣货 1=整件外复核、零货拣货 2=整件拣货、零货内复核 3=整件外复核、零货内复核
            //扫码阶段：0=入库质检 10=PC整件拣货 11=PC零货拣货 12=PC功能库房拣货 2=PC内复核 3=PC外复核 4=补录
            // 50=PDA整件拣货 51=PDA零货拣货 52=PDA功能库房拣货 6=PDA内复核 7=PDA外复核
            //SupervisionCodeServiceImpl.findCargoChangeList("CNS1000000034");
//            String s="[{\"barcode\":\"696470661553336320\",\"barcodeId\":\"696470661555687424\",\"billType\":\"1\",\"checkStatus\":\"1\",\"consignorId\":\"E23A4BUUPPW\",\"consignorName\":\"曲靖市康桥医药有限责任公司\",\"doLcl\":0,\"doPcs\":0,\"isSupervise\":0,\"lcl\":1,\"orderNo\":\"ZHY13000024\",\"pcs\":0,\"printStatus\":\"\\u0000\",\"salespersonName\":\"端木俊\",\"shipperId\":\"E23A4BUUPPW-C24KMYZNFBN\",\"shipperName\":\"云南昱楚凡商贸有限公司第一分公司\",\"totLcl\":2,\"totPcs\":0,\"type\":\"0\",\"warehouseId\":\"599581702716788736\"},{\"barcode\":\"696470661419118592\",\"barcodeId\":\"696470661421469696\",\"billType\":\"1\",\"checkStatus\":\"1\",\"consignorId\":\"E23A4BUUPPW\",\"consignorName\":\"曲靖市康桥医药有限责任公司\",\"doLcl\":0,\"doPcs\":0,\"isSupervise\":0,\"lcl\":1,\"orderNo\":\"ZHY13000024\",\"pcs\":0,\"printStatus\":\"\\u0000\",\"salespersonName\":\"端木俊\",\"shipperId\":\"E23A4BUUPPW-C24KMYZNFBN\",\"shipperName\":\"云南昱楚凡商贸有限公司第一分公司\",\"totLcl\":2,\"totPcs\":0,\"type\":\"0\",\"warehouseId\":\"599581702716788736\"}]";
//            s="[{\"billType\":\"1\",\"consignorId\":\"ZDA\",\"isSupervise\":0,\"noSuperviseReason\":\"dto.getIsSupervise()!=null\",\"shipperId\":\"DWI00000275\",\"warehouseId\":\"646346467442823168\"},{\"billType\":\"1\",\"consignorId\":\"ZDA\",\"itemId\":\"SPH00000218\",\"noSuperviseReason\":\"itemList==null\",\"shipperId\":\"DWI00000275\",\"warehouseId\":\"646346467442823168\"}]";
//            s="[{\"billType\":\"1\",\"consignorId\":\"ZDA\",\"isSupervise\":0,\"noSuperviseReason\":\"dto.getIsSupervise()!=null\",\"shipperId\":\"DWI00000266\",\"warehouseId\":\"646346467442823168\"},{\"billType\":\"1\",\"consignorId\":\"ZDA\",\"itemId\":\"SPH00000274\",\"noSuperviseReason\":\"ownerMap==null\",\"shipperId\":\"DWI00000266\",\"warehouseId\":\"646346467442823168\"},{\"billType\":\"1\",\"consignorId\":\"ZDA\",\"itemId\":\"SPH00000283\",\"noSuperviseReason\":\"ownerMap==null\",\"shipperId\":\"DWI00000266\",\"warehouseId\":\"646346467442823168\"}]";
//            //s="[{\"billType\":\"1\",\"consignorId\":\"ZDA\",\"itemId\":\"SPH00000274\",\"noSuperviseReason\":\"ownerMap==null\",\"shipperId\":\"DWI00000266\",\"warehouseId\":\"646346467442823168\"},{\"billType\":\"1\",\"consignorId\":\"ZDA\",\"itemId\":\"SPH00000283\",\"noSuperviseReason\":\"ownerMap==null\",\"shipperId\":\"DWI00000266\",\"warehouseId\":\"646346467442823168\"}]";
//            List<IsSuperviseDTO> list=JSON.parseArray(s,IsSuperviseDTO.class);
//            System.out.println(JSON.toJSONString(SupervisionCodeServiceImpl.isSupervise(list,7)));
            System.out.println("instockCallId:"+instockCallId);
            System.out.println("instockTransforId:"+instockTransforId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //空入入库
    @Test
    public void isSupervised(){
        try {
            String s="[{\"refBillId\":\"699363680541872128\",\"refBillLineId\":\"701499766890172416\",\"warehouseId\":\"599581702716788736\",\"billType\":\"1\",\"itemId\":\"0021264341\",\"consignorId\":\"E23A4BUUPPW\",\"shipperId\":\"C2PB2H4Z77S\",\"minSu\":\"1\",\"middleSu\":\"1\",\"maxSu\":\"80\",\"isSupervise\":1,\"itemCode\":\"YHXYYY0357\",\"itemName\":\"葡萄糖注射液\",\"itemSpecs\":\"20ml:10g*5支\",\"conversionRate\":60,\"uom\":\"盒\",\"manufacturerLotNum\":\"B2111040\",\"batchNum\":null,\"warehouseAreaCode\":null,\"locatorCode\":\"1ZJ07-03\",\"manufacturer\":\"湖北科伦药业有限公司\",\"qty\":2100,\"uomQty\":35,\"oddPieceQty\":0,\"lclNo\":null,\"shipperName\":null,\"expiredDate\":\"2023-10-25 00:00:00\",\"productionDate\":\"2021-11-04 00:00:00\",\"outerAskDate\":\"2022-03-18 15:55:54\",\"srcCode\":\"_cusId8402.89433161726\",\"pickUomQty\":35,\"pickOddPieceQty\":0,\"pickQty\":2100,\"pickerName\":\"昆中药WMS管理员\",\"barcode\":\"699363680541872128\",\"barcodeDId\":\"701499766890172416\",\"consignorName\":\"曲靖市康桥医药有限责任公司\",\"consignorCode\":null,\"itemHealthIsDouble\":0,\"itemHealthApprovalNbr\":\"国药准字H42021188\",\"isCaseOrPiece\":1,\"itemHealthSuperviseflag\":1,\"isBacteria\":0,\"isDelegate\":0,\"isHosted\":0,\"itemHealthCategoryCode\":\"001\",\"manufacturerName\":\"湖北科伦药业有限公司\",\"itemHealthListedLicensor\":\"湖北科伦药业有限公司\",\"itemHealthProduceLicense\":null,\"itemHealthRegisterNbr\":\"2020R001679\",\"itemHealthRecordNbr\":null,\"volume\":35937,\"weight\":0,\"_row_count\":1}]";
            System.out.println("-------"+JSON.toJSONString(SupervisionCodeServiceImpl.
                    isSupervised(JSON.parseArray(s, SupervisionCode.class))));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
