package com.prolog.upcloud.base.wh.operate.service.impl.eis;

import com.alibaba.fastjson.JSONObject;
import com.prolog.entity.vo.CompleteTaskVO;
import com.prolog.entity.vo.OrderBindingGridFeedbackVO;
import com.prolog.entity.vo.OutboundTaskCallbackVO;
import com.prolog.inte.WmsHandler;
import com.prolog.upcloud.base.wh.operate.WhOperateApplication;
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.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {WhOperateApplication.class})
public class WmsOperateHandlerTest {

    @Resource
    private WmsHandler wmsHandler;

    @Test
    public void outboundTaskCallback() {
        String json = wrapOutboundTaskCallback();

        OutboundTaskCallbackVO vo = JSONObject.parseObject(json, OutboundTaskCallbackVO.class);
        wmsHandler.outboundTaskCallback(Collections.singletonList(vo));
    }

    @Test
    public void completeTask() {
        String json = wrapCompleteTask();

        List<CompleteTaskVO> list = JSONObject.parseArray(json, CompleteTaskVO.class);
        wmsHandler.completeTask(list);
    }

    private String wrapCompleteTask() {
        String msg = "[{\"billNo\":\"971166100173754368\",\"businessType\":\"INV_RTM\",\"containerNo\":\"800497\",\"employeeId\":\"0711\",\"isLack\":\"1\",\"itemId\":\"ssssslhyp001\",\"lackQty\":0.0,\"lotId\":\"971164421772677120\",\"msgId\":\"c466a069-d0b7-4baa-b484-10da7e789b7f\",\"ownerId\":\"748963439141064888\",\"packId\":\"ssssslhyp001\",\"taskId\":\"971166100173754368\",\"taskLineId\":\"971166100333137920\",\"warehouseId\":\"901884530611326976\",\"wmsLocationCode\":\"MJZ\",\"workType\":\"30\"}]";
        return msg;
    }


    private String wrapOutboundTaskCallback() {
        String json = "{\n" +
                "    \"containerNo\": \"100011\",\n" +
                "    \"msgId\": \"7e808ec5-86ff-4edc-8352-e281f7cc5732\",\n" +
                "    \"subList\":\n" +
                "    [\n" +
                "        {\n" +
                "            \"billNo\": \"904347633483649024\",\n" +
                "            \"businessType\": \"INV_CONSERVE\",\n" +
                "            \"eisTaskId\": \"C26570D01CD6480FAB881EAA04D25A05\",\n" +
                "            \"enterpriseId\": \"891063172566487040\",\n" +
                "            \"itemId\": \"2155036\",\n" +
                "            \"lotId\": \"904352619110207488\",\n" +
                "            \"ownerId\": \"748963439141064888\",\n" +
                "            \"packId\": \"UOM00053\",\n" +
                "            \"qty\": 1.0,\n" +
                "            \"targetArea\": \"\",\n" +
                "            \"targetLocation\": \"\",\n" +
                "            \"taskId\": \"904360184343351296\",\n" +
                "            \"taskLineId\": \"911995736084844544\",\n" +
                "            \"warehouseId\": \"891420072483098624\",\n" +
                "            \"wmsLocationCode\": \"MJZ\",\n" +
                "            \"workType\": \"50\"\n" +
                "        }\n" +
                "    ]\n" +
                "}";
        return json;
    }

    @Test
    public void orderBindingGridFeedbackTest() {
        String msg = orderBindingGridFeedbackTestParams();
        OrderBindingGridFeedbackVO vo = JSONObject.parseObject(msg, OrderBindingGridFeedbackVO.class);
        wmsHandler.orderBindingGridFeedback(vo);
    }

    private static String orderBindingGridFeedbackTestParams() {
        String msg = "{\n" +
                "  \"msgId\": \"bc106fe3c1284bf3a21e3b6c18e67713\",\n" +
                "  \"warehouseId\": \"891420072483098624\",\n" +
                "  \"taskId\": \"911677624777625600\",\n" +
                "  \"billNo\": \"903997432958689280\",\n" +
                "  \"enterpriseId\": \"891063172566487040\",\n" +
                "  \"gridNo\": [\n" +
                "    \"200001\"\n" +
                "  ]\n" +
                "}";
        return msg;
    }
}