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

import com.alibaba.fastjson.JSONObject;
import com.prolog.entity.vo.ApplyForDocumentPrintingVO;
import com.prolog.entity.vo.CompleteTaskVO;
import com.prolog.entity.vo.OutboundCheckResultCallbackVO;
import com.prolog.entity.vo.OutboundTaskCallbackVO;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest
public class EisOutboundTest {
    @Resource
    private PickTaskServiceImpl pickTaskService;

    @Test
    public void outboundTaskCallback() throws Exception {
        String json = "{\n" +
                "    \"containerNo\": \"100011\",\n" +
                "    \"msgId\": \"7e808ec5-86ff-4edc-8352-e281f7cc5732\",\n" +
                "    \"subList\":\n" +
                "    [\n" +
                "        {\n" +
                "            \"billNo\": \"904347633483649024\",\n" +
                "            \"businessType\": \"DO_SO\",\n" +
                "            \"eisTaskId\": \"C26570D01CD6480FAB881EAA04D25A05\",\n" +
                "            \"enterpriseId\": \"891063172566487040\",\n" +
                "            \"itemId\": \"2155036\",\n" +
                "            \"lotId\": \"904352619110207488\",\n" +
                "            \"ownerId\": \"748963439141064888\",\n" +
                "            \"packId\": \"UOM00053\",\n" +
                "            \"qty\": 14.0,\n" +
                "            \"targetArea\": \"\",\n" +
                "            \"targetLocation\": \"\",\n" +
                "            \"taskId\": \"904360184343351296\",\n" +
                "            \"taskLineId\": \"904360184355360768\",\n" +
                "            \"warehouseId\": \"891420072483098624\",\n" +
                "            \"wmsLocationCode\": \"MJZ\",\n" +
                "            \"workType\": \"20\"\n" +
                "        }\n" +
                "    ]\n" +
                "}";

        OutboundTaskCallbackVO vo = JSONObject.parseObject(json, OutboundTaskCallbackVO.class);
        pickTaskService.outboundTaskCallback(vo);
    }

    @Test
    public void completeTask() {
        String msg = getStringCompleteTask();
        CompleteTaskVO vo = JSONObject.parseObject(msg, CompleteTaskVO.class);
        Map<String, Object> map = pickTaskService.completeTask(Collections.singletonList(vo));
        Assert.assertEquals("0", map.get("flg"));
    }

    private String getStringCompleteTask() {
        return "[{\"billNo\":\"CKD202402281550\",\"businessType\":\"DO_SO\",\"containerNo\":\"20000165\",\"employeeId\":\"0711\",\"inventoryQty\":3,\"isLack\":0,\"itemId\":\"ssssslhyp002\",\"lackQty\":\"2.00\",\"lotId\":\"960877541223174144\",\"msgId\":\"9949a237-4461-4f07-b614-887582a4ac29\",\"ownerId\":\"748963439141064888\",\"packId\":\"ssssslhyp002\",\"taskId\":\"960881826900660224\",\"taskLineId\":\"960881826921058306\",\"warehouseId\":\"901884530611326976\",\"wmsLocationCode\":\"AGVL\",\"workType\":\"20\"}]";
    }

    @Test
    public void outboundCheckResultCallback() {
        String msg = packOutboundCheckResultCallback();
        OutboundCheckResultCallbackVO vo = JSONObject.parseObject(msg, OutboundCheckResultCallbackVO.class);
        pickTaskService.outboundCheckResultCallback(vo);
    }

    private  String packOutboundCheckResultCallback() {
        String msg = "{\"warehouseId\":\"901884530611326976\",\"enterpriseId\":\"900356013474058240\",\"taskId\":\"960216329611825152\",\"billNo\":\"CKD202402281350\",\"printUrl\":\"http://172.17.200.67:33314/barcodelabel.grf\",\"employeeId\":\"0711\",\"subList\":[{\"taskLineId\":\"960216329619640320\",\"ownerId\":\"748963439141064888\",\"itemId\":\"ssssslhyp001\",\"lotId\":\"960189099204022272\",\"packId\":\"ssssslhyp001\",\"qty\":2,\"drugSupervisionCode\":[]},{\"taskLineId\":\"960216329644806146\",\"ownerId\":\"748963439141064888\",\"itemId\":\"ssssslhyp002\",\"lotId\":\"960189099204022274\",\"packId\":\"ssssslhyp002\",\"qty\":3,\"drugSupervisionCode\":[]},{\"taskLineId\":\"960216329644806148\",\"ownerId\":\"748963439141064888\",\"itemId\":\"ssssslhyp007\",\"lotId\":\"960189099208216576\",\"packId\":\"ssssslhyp007\",\"qty\":1,\"drugSupervisionCode\":[]}]}";
        return msg;
    }

    @Test
    public void applyForDocumentPrinting() {
        String msg = "{\"warehouseId\":\"901884530611326976\",\"enterpriseId\":\"KingYan\",\"taskId\":\"KingYan\",\"billNo\":\"CKD20240129003\",\"gridNo\":\"1\"}";
        ApplyForDocumentPrintingVO vo = JSONObject.parseObject(msg, ApplyForDocumentPrintingVO.class);
        pickTaskService.applyForDocumentPrinting(vo);
    }
}
