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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import com.prolog.cs.biz.outbound.Application;
import com.prolog.cs.biz.outbound.model.vo.check.OutCheckSupervisionCodeVO;
import com.prolog.cs.biz.outbound.service.PickTaskAppService;
import com.prolog.entity.vo.ApplyForPackageWeighVO;
import com.prolog.entity.vo.OutboundCheckResultCallbackVO;
import com.prolog.framework.authority.util.HystrixVarUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.Assert;
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 java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/** 
* PickTaskAppServiceImpl Tester. 
* 
* @author <Authors name> 
* @since <pre>3�� 21, 2022</pre> 
* @version 1.0 
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@WebAppConfiguration
@Slf4j
public class PickTaskAppServiceImplTest {

    @Autowired
    PickTaskAppServiceImpl PickTaskAppServiceImpl;

    @Autowired
    private PickTaskAppService pickTaskAppService;

@Before
public void before() throws Exception { 
} 

@After
public void after() throws Exception { 
} 

/** 
* 
* Method: outerCheckUnAsk(String barcode, String bldgId, String warehouseId, Integer pageNum, Integer pageSize) 
* 
*/ 
@Test
public void testOuterCheckUnAsk() throws Exception { 
//TODO: Test goes here... 
} 

/** 
* 
* Method: outerCheckUnCheck(String bldgId, String srcCode, String warehouseId, Integer pageNum, Integer pageSize) 
* 
*/ 
@Test
public void testOuterCheckUnCheck() throws Exception { 
//TODO: Test goes here... 
} 

/** 
* 
* Method: outerCheckConfirm(String barcode, Integer pcs, String superviseCode, String warehouseId) 
* 
*/ 
@Test
public void testOuterCheckConfirm() throws Exception { 
//TODO: Test goes here... 
} 

/** 
* 
* Method: getPickTaskCount(String bldgId, String warehouseId, Integer pickTaskType, String operatorCode) 
* 
*/ 
@Test
public void testGetPickTaskCount() throws Exception { 
//TODO: Test goes here... 
} 

/** 
* 
* Method: createByOperatorCode(String bldgId, String warehouseId, Integer pickTaskType) 
* 
*/ 
@Test
public void testCreateByOperatorCode() throws Exception { 
//TODO: Test goes here... 
} 

/** 
* 
* Method: bindContainer(String pickOrderId, String containerCode, String warehouseId) 
* 
*/ 
@Test
public void testBindContainer() throws Exception { 
//TODO: Test goes here... 
} 

/** 
* 
* Method: getPickTaskDList(String bldgId, String warehouseId, String pickOrderId, Integer pageNum, Integer pageSize) 
* 
*/ 
@Test
public void testGetPickTaskDList() throws Exception {
//warehouseId=599581702716788736&bldgId=599581810778836992&pickOrderId=701125104381333504&pageSize=0&pageNum=0
    HystrixRequestContext context = HystrixRequestContext.initializeContext();
    HystrixVarUtil.setUserKey("kzywms-admin");
    System.out.println(JSON.toJSONString(PickTaskAppServiceImpl.getPickTaskDList("599581810778836992",
            "599581702716788736","701125104381333504", 0, 0)));

//TODO: Test goes here... 
} 

/** 
* 
* Method: getTaskHListByPickOrder(String bldgId, String warehouseId, String pickOrderId, Integer pageNum, Integer pageSize) 
* 
*/ 
@Test
public void testGetTaskHListByPickOrder() throws Exception { 
//TODO: Test goes here... 
} 

/** 
* 
* Method: getContainerList(String warehouseId, String pickOrderId, String itemId, String locatorCode, String manufacturerLotNum) 
* 
*/ 
@Test
public void testGetContainerList() throws Exception { 
//TODO: Test goes here... 
} 

/** 
* 
* Method: pickTaskConfirm(List<ContainerListDTO> list) 
* 
*/ 
@Test
public void testPickTaskConfirm() throws Exception { 
//TODO: Test goes here... 
} 

/** 
* 
* Method: pickTaskHConfirm(String pickOrderId, String pickTaskDId, String pickTaskId, BigDecimal pickQty, String redReason) 
* 
*/ 
@Test
public void testPickTaskHConfirm() throws Exception { 
//TODO: Test goes here... 
} 

/** 
* 
* Method: containerOffShelf(String containerNo) 
* 
*/ 
@Test
public void testContainerOffShelf() throws Exception { 
//TODO: Test goes here... 
} 


/** 
* 
* Method: isSupervise(List<? extends IsSuperviseDTO> list, Integer stage) 
* 
*/ 
@Test
public void testIsSupervise() throws Exception { 
//TODO: Test goes here... 
/* 
try { 
   Method method = PickTaskAppServiceImpl.getClass().getMethod("isSupervise", List<?.class, Integer.class); 
   method.setAccessible(true); 
   method.invoke(<Object>, <Parameters>); 
} catch(NoSuchMethodException e) { 
} catch(IllegalAccessException e) { 
} catch(InvocationTargetException e) { 
} 
*/ 
}

    @Test
    public void applyForPackageWeigh() {
        ApplyForPackageWeighVO vo = new ApplyForPackageWeighVO();
        vo.setWeight("90");
        vo.setMailNo("2023092800001");
//        vo.setMailNo("20230928000011231");

        Map<String, Object> map = pickTaskAppService.applyForPackageWeigh(vo);
        Assert.assertEquals(map.get("target"),2);
//        Assert.assertEquals(map.get("target"),1);
    }

    @Test
    public void scanSupervisionCode() {

        String msg = scanSupervisionCodeParams();

        OutboundCheckResultCallbackVO vo = JSONObject.parseObject(msg, new TypeReference<OutboundCheckResultCallbackVO>() {
        });

        OutCheckSupervisionCodeVO codeVO = new OutCheckSupervisionCodeVO();
        codeVO.setBillId("CLH202311071703");
        codeVO.setBillType("1");
        List<String> collect = vo.getSubList().stream().flatMap(t -> t.getDrugSupervisionCode().stream()).collect(Collectors.toList());
        codeVO.setSupervisionCodes(collect);

        pickTaskAppService.scanSupervisionCode(codeVO);
    }

    private static String scanSupervisionCodeParams() {
        String msg = "{\n" +
                "  \"warehouseId\": \"901884530611326976\",\n" +
                "  \"enterpriseId\": \"900356013474058240\",\n" +
                "  \"taskId\": \"919314291248254976\",\n" +
                "  \"billNo\": \"CLH202311071703\",\n" +
                "  \"printUrl\": \"http://172.17.200.67:33314/barcodelabel.grf\",\n" +
                "  \"taskLineId\": \"919314291247681536\",\n" +
                "  \"employeeId\": \"0711\",\n" +
                "  \"subList\": [\n" +
                "    {\n" +
                "      \"ownerId\": \"748963439141064888\",\n" +
                "      \"itemId\": \"ssssslhyp008\",\n" +
                "      \"lotId\": \"919217024117379072\",\n" +
                "      \"packId\": \"ssssslhyp008\",\n" +
                "      \"qty\": 2,\n" +
                "      \"drugSupervisionCode\": [\n" +
                "        \"89202311071231230001\",\n" +
                "        \"89202311071231230002\"\n" +
                "      ]\n" +
                "    }\n" +
                "  ]\n" +
                "}";
        return msg;
    }

    @Test
    public void getInvoice() {
        List<String> result = PickTaskAppServiceImpl.getInvoice("ZJqn00001");
        System.out.println(result.toString());
    }
}
