package org.ta.pddserver;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.ta.pddserver.model.enums.OrderProblemType;
import org.ta.pddserver.model.pddjy.request.*;
import org.ta.pddserver.model.pddjy.response.PddServiceConsoDerelictionResponse;
import org.ta.pddserver.utils.PddHttpTool;
import org.ta.pddserver.utils.PddSignTool;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

@Slf4j
public class CommonTest {

    private static final String PROVIDER_CODE = "HAIJI_KR";
    private static final String WAREHOUSE_CODE = "HJJY001";

    private static final String CLIENT_ID = "8f5f3f9c92e847b2894fc9c0afce3d61";
    private static final String CLIENT_SECRET = "281d79ad5117d20a51efb9e7b0d5f7ee336399b0";

    private String firstLogisticsOrderCode = "PC25110416466837504037527";

    private static String getNowString() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }

    @Test
    public void Test1() {
        PddServiceConsoDerelictionRequest derelictionRequest = new PddServiceConsoDerelictionRequest();
        derelictionRequest.setProviderCode(PROVIDER_CODE);
        derelictionRequest.setExecuteTime("2025-10-23 14:53:22");
        derelictionRequest.setTimeZone("UTC+8");
        derelictionRequest.setMailNo("2343534632");
        derelictionRequest.setExpressCode("快递公司编码");
        derelictionRequest.setDereRecogCode("D00NJL01");
        log.info("derelictionRequest:{}", JSON.toJSONString(derelictionRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(derelictionRequest));
        requestModel.setRequest_id("111");
        requestModel.setType("pdd.service.conso.dereliction");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    @Test
    public void Test2() {
        PddServiceConsoFirstBizActionNotifyRequest notifyRequest = new PddServiceConsoFirstBizActionNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setExecuteTime("2025-10-23 14:53:22");
        notifyRequest.setTimeZone("UTC+8");
        notifyRequest.setLogisticsOrderCode("xx198985333");
        notifyRequest.setBizAction("warehouse_sign");
        notifyRequest.setBizActionDesc("仓库签收");
        notifyRequest.setMailNo("234546666");
        notifyRequest.setExpressCode("快递公司编码");
        PddServiceConsoFirstBizActionNotifyRequest.Result notifyResult = new PddServiceConsoFirstBizActionNotifyRequest.Result();
        notifyResult.setCode(22);
        notifyResult.setDesc("运输品类限制");
        notifyRequest.setResult(notifyResult);
        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("111");
        requestModel.setType("pdd.service.conso.first.biz.action.notify");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }


    /**
     * 确认收货
     */
    @Test
    public void receive() {
        String mailNo = "773846466954492";
        String expressCode = "STO";
        String action = "warehouse_sign";
        PddServiceConsoFirstBizActionNotifyRequest notifyRequest = new PddServiceConsoFirstBizActionNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");
        notifyRequest.setLogisticsOrderCode(firstLogisticsOrderCode);
        notifyRequest.setBizAction(action);
        PddServiceConsoFirstBizActionNotifyRequest.Result notifyResult = new PddServiceConsoFirstBizActionNotifyRequest.Result();
        notifyRequest.setMailNo(mailNo);
        notifyRequest.setExpressCode(expressCode);
        if (action == "warehouse_sign") {
            notifyRequest.setBizActionDesc("仓库签收");
            notifyResult.setCode(0);
        } else if (action == "warehouse_reject_sign") {
            notifyRequest.setBizActionDesc("仓库拒签");
            notifyResult.setCode(22);
            notifyResult.setDesc("运输品类限制");
            notifyResult.setRemark("运输品类限制");
            notifyRequest.setResult(notifyResult);
        } else if (action == "destroy") {
            notifyRequest.setBizActionDesc("包裹销毁");
            notifyResult.setCode(0);
        }
        notifyRequest.setResult(notifyResult);


        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.first.biz.action.notify");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    /**
     * 拒收
     */
    @Test
    public void reject() {
        String mailNo = "773074032778146";
        String expressCode = "STO";
        String action = "warehouse_reject_sign";
        PddServiceConsoFirstBizActionNotifyRequest notifyRequest = new PddServiceConsoFirstBizActionNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");
        notifyRequest.setLogisticsOrderCode(firstLogisticsOrderCode);
        notifyRequest.setBizAction(action);
        PddServiceConsoFirstBizActionNotifyRequest.Result notifyResult = new PddServiceConsoFirstBizActionNotifyRequest.Result();
        notifyRequest.setMailNo(mailNo);
        notifyRequest.setExpressCode(expressCode);
        if (action == "warehouse_sign") {
            notifyRequest.setBizActionDesc("仓库签收");
            notifyResult.setCode(0);
        } else if (action == "warehouse_reject_sign") {
            notifyRequest.setBizActionDesc("仓库拒签");
            notifyResult.setCode(20);
            notifyResult.setDesc("超大");
            notifyResult.setRemark("超大");
            notifyRequest.setResult(notifyResult);
            PddServiceConsoFirstBizActionNotifyRequest.PackageInfo packageInfo = new PddServiceConsoFirstBizActionNotifyRequest.PackageInfo();
            notifyRequest.setPackageInfo(packageInfo);
            packageInfo.setWidth(100L);
            packageInfo.setHeight(100L);
            packageInfo.setLength(100L);
            packageInfo.setWeight(30000L);
            packageInfo.setActualWeight(30000L);
        } else if (action == "destroy") {
            notifyRequest.setBizActionDesc("包裹销毁");
            notifyResult.setCode(0);
        }
        notifyRequest.setResult(notifyResult);


        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.first.biz.action.notify");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    /**
     * 入库
     */
    @Test
    public void inBound() {

        String mailNo = "773846466954492";
        String expressCode = "STO";
        PddServiceConsoInboundRequest notifyRequest = new PddServiceConsoInboundRequest();


//        PddServiceConsoFirstBizActionNotifyRequest notifyRequest = new PddServiceConsoFirstBizActionNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setLogisticsOrderCode(firstLogisticsOrderCode);
        notifyRequest.setExecuteTime(getNowString());
//        notifyRequest.setExecuteTime("2025-05-04 00:00:00");
        notifyRequest.setTimeZone("UTC+8");

        notifyRequest.setStatus("FULL_INBOUND");
//        notifyRequest.setStatus("PART_INBOUND");
        notifyRequest.setPackageQuantity(1L);

        notifyRequest.setPackageInfo(new PddServiceConsoInboundRequest.PackageInfo());
        notifyRequest.getPackageInfo().setMailNo(mailNo);
        notifyRequest.getPackageInfo().setExpressCode(expressCode);
        notifyRequest.getPackageInfo().setLength(30L);
        notifyRequest.getPackageInfo().setWidth(30L);
        notifyRequest.getPackageInfo().setHeight(30L);
        notifyRequest.getPackageInfo().setWeight(600L);
        notifyRequest.getPackageInfo().setActualWeight(600L);
        notifyRequest.getPackageInfo().setGoodsType("NORMAL");

        notifyRequest.setResult(new PddServiceConsoInboundRequest.Result());
        notifyRequest.getResult().setCode(0);

        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.inbound");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    /**
     * 开始拣货
     */
    @Test
    public void beginPick() {
        String LogisticsOrderCode = "PP25110414221207143137527";
        String action = "begin_pick";
        PddServiceConsoCoBizActionNotifyRequest notifyRequest = new PddServiceConsoCoBizActionNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setOrderCode(LogisticsOrderCode);
        notifyRequest.setBizAction(action);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");


        PddServiceConsoCoBizActionNotifyRequest.Result notifyResult = new PddServiceConsoCoBizActionNotifyRequest.Result();
//        notifyRequest.setMailNo(mailNo);
//        notifyRequest.setExpressCode(expressCode);
        if (action == "begin_pick") {
            notifyRequest.setBizActionDesc("开始拣货");
            notifyResult.setCode(0);
        } else if (action == "finish_pick") {
            notifyRequest.setBizActionDesc("拣货完成");
            notifyResult.setCode(0);
        } else if (action == "finish_unpack") {
            notifyRequest.setBizActionDesc("拆包完成");
            notifyRequest.setUnpackRemark("");
            notifyResult.setCode(0);
        }
        notifyRequest.setResult(notifyResult);


        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.co.biz.action.notify");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    /**
     * 完成拣货
     */
    @Test
    public void finishPick() {
        String LogisticsOrderCode = "PP25110414221207143137527";
        String action = "finish_pick";
        PddServiceConsoCoBizActionNotifyRequest notifyRequest = new PddServiceConsoCoBizActionNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setOrderCode(LogisticsOrderCode);
        notifyRequest.setBizAction(action);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");


        PddServiceConsoCoBizActionNotifyRequest.Result notifyResult = new PddServiceConsoCoBizActionNotifyRequest.Result();

        notifyRequest.setBizActionDesc("拣货完成");
        notifyResult.setCode(0);

        notifyRequest.setResult(notifyResult);

        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.co.biz.action.notify");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }


    /**
     * 拣货完成后出库
     */
    @Test
    public void outBound() {

        String mailNo = "BK-25110414221207143137527";
        String expressCode = "KR_JD";
        String orderCode = "PP25110414221207143137527";
//        String segmentCode = "RETURNSELLER";
        String segmentCode = "SENDTORECEVER";

        PddServiceConsoOutboundRequest notifyRequest = new PddServiceConsoOutboundRequest();

        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setOrderCode(orderCode);
        notifyRequest.setSegmentCode(segmentCode);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");
//        notifyRequest.setIsSplitOut("N");

        notifyRequest.setIsSplitOut("Y");


        notifyRequest.setPackageInfos(new ArrayList<>());
        PddServiceConsoOutboundRequest.PackageInfo packageInfo0 = new PddServiceConsoOutboundRequest.PackageInfo();
        notifyRequest.getPackageInfos().add(packageInfo0);
        packageInfo0.setOutboundMailNo(mailNo + "1");
        packageInfo0.setExpressCode(expressCode);
        packageInfo0.setPackageType("2");
        packageInfo0.setLength(30L);
        packageInfo0.setWidth(30L);
        packageInfo0.setHeight(30L);
        packageInfo0.setWeight(1000L);
//        packageInfo0.setInboundMailDetails(new ArrayList<>());
//        PddServiceConsoOutboundRequest.InboundMailDetail inboundMailDetail0 = new PddServiceConsoOutboundRequest.InboundMailDetail();
//        packageInfo0.getInboundMailDetails().add(inboundMailDetail0);
//        inboundMailDetail0.setMailNo("773608936457954");
//        inboundMailDetail0.setExpressCode("STO");
//        PddServiceConsoOutboundRequest.InboundMailDetail inboundMailDetail1 = new PddServiceConsoOutboundRequest.InboundMailDetail();
//        packageInfo0.getInboundMailDetails().add(inboundMailDetail1);
//        inboundMailDetail1.setMailNo("773010635902734");
//        inboundMailDetail1.setExpressCode("STO");

        /*
        PddServiceConsoOutboundRequest.PackageInfo packageInfo = new PddServiceConsoOutboundRequest.PackageInfo();
        notifyRequest.getPackageInfos().add(packageInfo);
        packageInfo.setOutboundMailNo(mailNo + "2");
        packageInfo.setExpressCode(expressCode);
        packageInfo.setPackageType("2");
        packageInfo.setLength(30L);
        packageInfo.setWidth(30L);
        packageInfo.setHeight(30L);
        packageInfo.setWeight(1500L);
        packageInfo.setInboundMailDetails(new ArrayList<>());
        PddServiceConsoOutboundRequest.InboundMailDetail inboundMailDetail2 = new PddServiceConsoOutboundRequest.InboundMailDetail();
        packageInfo.getInboundMailDetails().add(inboundMailDetail2);
        inboundMailDetail2.setMailNo("TT773010635902734");
        inboundMailDetail2.setExpressCode("STO");
         */

        notifyRequest.setSenderDetail(new PddServiceConsoOutboundRequest.SenderDetail());
        notifyRequest.getSenderDetail().setName("海际集货仓");
        notifyRequest.getSenderDetail().setTelePhone("18660975251");
        notifyRequest.getSenderDetail().setCountry("CN");
        notifyRequest.getSenderDetail().setProvince("山东省");
        notifyRequest.getSenderDetail().setCity("临沂市");
        notifyRequest.getSenderDetail().setDistrict("兰山区");
        notifyRequest.getSenderDetail().setDetailAddress("山东省临沂市兰山区横九路与纵十路交汇兰山财金智慧云仓五期二层二号仓");

        notifyRequest.setReceiverDetail(new PddServiceConsoOutboundRequest.ReceiverDetail());
        notifyRequest.getReceiverDetail().setName("김명상");
        notifyRequest.getReceiverDetail().setTelePhone("01012345678");
        notifyRequest.getReceiverDetail().setCountry("KR");
        notifyRequest.getReceiverDetail().setProvince("서울특별시");
        notifyRequest.getReceiverDetail().setCity("강북구");
        notifyRequest.getReceiverDetail().setDistrict("강북구");
        notifyRequest.getReceiverDetail().setDetailAddress("护照1号");

        notifyRequest.setResult(new PddServiceConsoOutboundRequest.Result());
        notifyRequest.getResult().setCode(0);
//        notifyRequest.getResult().setDesc("");
//        notifyRequest.getResult().setRemark("");


        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.outbound");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    /**
     * 收到拆包通知后 完成拆包 （不一定收到出库通知）
     */
    @Test
    public void finishUnpack() {
        String LogisticsOrderCode = "PP25110415653142528037527";
        String action = "finish_unpack";
        PddServiceConsoCoBizActionNotifyRequest notifyRequest = new PddServiceConsoCoBizActionNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setOrderCode(LogisticsOrderCode);
        notifyRequest.setBizAction(action);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");


        PddServiceConsoCoBizActionNotifyRequest.Result notifyResult = new PddServiceConsoCoBizActionNotifyRequest.Result();

        notifyRequest.setBizActionDesc("拆包完成");
        notifyRequest.setUnpackRemark("");
        notifyResult.setCode(0);
        notifyRequest.setPackageInfos(new ArrayList<>());
        PddServiceConsoCoBizActionNotifyRequest.PackageInfo packageInfo0 = new PddServiceConsoCoBizActionNotifyRequest.PackageInfo();
        notifyRequest.getPackageInfos().add(packageInfo0);
        packageInfo0.setWeight(600L);
        packageInfo0.setWidth(30L);
        packageInfo0.setHeight(30L);
        packageInfo0.setLength(30L);
        packageInfo0.setActualWeight(600L);
        packageInfo0.setConsoType("SEA");
        packageInfo0.setGoodsType("NORMAL");

        notifyRequest.setResult(notifyResult);


        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.co.biz.action.notify");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    /**
     * 无主件识别
     */
    @Test
    public void dereliction() {
        String mailNo = "TT773010635902734";
        String expressCode = "STO";
        String dereRecogCode = "51103HHF52832";
        PddServiceConsoDerelictionRequest notifyRequest = new PddServiceConsoDerelictionRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");
        notifyRequest.setMailNo(mailNo);
        notifyRequest.setExpressCode(expressCode);
        notifyRequest.setDereRecogCode(dereRecogCode);

        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.dereliction");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
        PddServiceConsoDerelictionResponse response = JSON.parseObject(resp, PddServiceConsoDerelictionResponse.class);
        String logisticsOrderCode = response.getLogisticsOrderCode();
        log.info("logisticsOrderCode = {}", logisticsOrderCode);
    }

    /**
     * 问题件上传
     */
    @Test
    public void problemNotify() {
        String mailNo = "773838955577767";
        String expressCode = "STO";
        PddServiceConsoProblemOrderNotifyRequest notifyRequest = new PddServiceConsoProblemOrderNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");
        notifyRequest.setMailInfos(new ArrayList<>());
        PddServiceConsoProblemOrderNotifyRequest.MailInfo mailInfo = new PddServiceConsoProblemOrderNotifyRequest.MailInfo();
        notifyRequest.getMailInfos().add(mailInfo);
        mailInfo.setMailNo(mailNo);
        mailInfo.setOrderCode(firstLogisticsOrderCode);
        mailInfo.setExpressCode(expressCode);
        mailInfo.setReasonCode(OrderProblemType.JinYun.getValue());

        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.problem.order.notify");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);

    }


    @Test
    public void testFee() {

    }

    /**
     * 退运
     */
    @Test
    public void outBoundToSeller() {

        String mailNo = "77383895557776";
        String expressCode = "STO";
        String orderCode = "PT25110416466837504337527";
        String segmentCode = "RETURNSELLER";
//        String segmentCode = "SENDTORECEVER";

        PddServiceConsoOutboundRequest notifyRequest = new PddServiceConsoOutboundRequest();

        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setOrderCode(orderCode);
        notifyRequest.setSegmentCode(segmentCode);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");
        notifyRequest.setIsSplitOut("N");
//        notifyRequest.setIsSplitOut("Y");


        notifyRequest.setPackageInfos(new ArrayList<>());
        PddServiceConsoOutboundRequest.PackageInfo packageInfo0 = new PddServiceConsoOutboundRequest.PackageInfo();
        notifyRequest.getPackageInfos().add(packageInfo0);
        packageInfo0.setOutboundMailNo(mailNo + "1");
        packageInfo0.setExpressCode(expressCode);
        packageInfo0.setPackageType("2");
        packageInfo0.setLength(30L);
        packageInfo0.setWidth(30L);
        packageInfo0.setHeight(30L);
        packageInfo0.setWeight(1000L);

//        packageInfo0.setInboundMailDetails(new ArrayList<>());
//        PddServiceConsoOutboundRequest.InboundMailDetail inboundMailDetail0 = new PddServiceConsoOutboundRequest.InboundMailDetail();
//        packageInfo0.getInboundMailDetails().add(inboundMailDetail0);
//        inboundMailDetail0.setMailNo("773608936457954");
//        inboundMailDetail0.setExpressCode("STO");
//        PddServiceConsoOutboundRequest.InboundMailDetail inboundMailDetail1 = new PddServiceConsoOutboundRequest.InboundMailDetail();
//        packageInfo0.getInboundMailDetails().add(inboundMailDetail1);
//        inboundMailDetail1.setMailNo("773010635902734");
//        inboundMailDetail1.setExpressCode("STO");

        notifyRequest.setSenderDetail(new PddServiceConsoOutboundRequest.SenderDetail());
        notifyRequest.getSenderDetail().setName("海际集货仓");
        notifyRequest.getSenderDetail().setTelePhone("18660975251");
        notifyRequest.getSenderDetail().setCountry("CN");
        notifyRequest.getSenderDetail().setProvince("山东省");
        notifyRequest.getSenderDetail().setCity("临沂市");
        notifyRequest.getSenderDetail().setDistrict("兰山区");
        notifyRequest.getSenderDetail().setDetailAddress("山东省临沂市兰山区横九路与纵十路交汇兰山财金智慧云仓五期二层二号仓");

        notifyRequest.setReceiverDetail(new PddServiceConsoOutboundRequest.ReceiverDetail());
        notifyRequest.getReceiverDetail().setName("玛蒂尔");
        notifyRequest.getReceiverDetail().setTelePhone("15691757118");
        notifyRequest.getReceiverDetail().setCountry("中国");
        notifyRequest.getReceiverDetail().setProvince("上海市");
        notifyRequest.getReceiverDetail().setCity("上海市");
        notifyRequest.getReceiverDetail().setDistrict("长宁区");
        notifyRequest.getReceiverDetail().setDetailAddress("娄山关路金虹桥国际中心南楼2号");

        notifyRequest.setResult(new PddServiceConsoOutboundRequest.Result());
        notifyRequest.getResult().setCode(0);
//        notifyRequest.getResult().setDesc("");
//        notifyRequest.getResult().setRemark("");


        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.outbound");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    /**
     * 销毁
     */
    @Test
    public void destroy() {
        String mailNo = "773230214487313";
        String expressCode = "STO";
        String action = "destroy";
        PddServiceConsoFirstBizActionNotifyRequest notifyRequest = new PddServiceConsoFirstBizActionNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");
        notifyRequest.setLogisticsOrderCode(firstLogisticsOrderCode);
        notifyRequest.setBizAction(action);
        PddServiceConsoFirstBizActionNotifyRequest.Result notifyResult = new PddServiceConsoFirstBizActionNotifyRequest.Result();
        notifyRequest.setMailNo(mailNo);
        notifyRequest.setExpressCode(expressCode);
        if (action == "warehouse_sign") {
            notifyRequest.setBizActionDesc("仓库签收");
            notifyResult.setCode(0);
        } else if (action == "warehouse_reject_sign") {
            notifyRequest.setBizActionDesc("仓库拒签");
            notifyResult.setCode(22);
            notifyResult.setDesc("运输品类限制");
            notifyResult.setRemark("运输品类限制");
            notifyRequest.setResult(notifyResult);
        } else if (action == "destroy") {
            notifyRequest.setBizActionDesc("包裹销毁");
            notifyResult.setCode(0);
        }
        notifyRequest.setResult(notifyResult);


        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.first.biz.action.notify");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    /**
     * 入库异常
     */
    @Test
    public void inBoundError() {

        String mailNo = "773289250144406";
        String expressCode = "STO";
        PddServiceConsoInboundRequest notifyRequest = new PddServiceConsoInboundRequest();


//        PddServiceConsoFirstBizActionNotifyRequest notifyRequest = new PddServiceConsoFirstBizActionNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setLogisticsOrderCode(firstLogisticsOrderCode);
        notifyRequest.setExecuteTime(getNowString());
//        notifyRequest.setExecuteTime("2025-05-04 00:00:00");
        notifyRequest.setTimeZone("UTC+8");

        notifyRequest.setStatus("FULL_INBOUND");
//        notifyRequest.setStatus("PART_INBOUND");
        notifyRequest.setPackageQuantity(1L);

        notifyRequest.setPackageInfo(new PddServiceConsoInboundRequest.PackageInfo());
        notifyRequest.getPackageInfo().setMailNo(mailNo);
        notifyRequest.getPackageInfo().setExpressCode(expressCode);
        notifyRequest.getPackageInfo().setLength(30L);
        notifyRequest.getPackageInfo().setWidth(30L);
        notifyRequest.getPackageInfo().setHeight(30L);
        notifyRequest.getPackageInfo().setWeight(600L);
        notifyRequest.getPackageInfo().setActualWeight(600L);
        notifyRequest.getPackageInfo().setGoodsType("NORMAL");

        notifyRequest.setResult(new PddServiceConsoInboundRequest.Result());
        notifyRequest.getResult().setCode(103);
        notifyRequest.getResult().setDesc("禁限运");
        notifyRequest.getResult().setRemark("禁限运");

        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.inbound");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    /**
     * 开始拣货异常
     */
    @Test
    public void beginPickError() {
        String LogisticsOrderCode = "PP25110414221207143137527";
        String action = "begin_pick";
        PddServiceConsoCoBizActionNotifyRequest notifyRequest = new PddServiceConsoCoBizActionNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setOrderCode(LogisticsOrderCode);
        notifyRequest.setBizAction(action);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");


        PddServiceConsoCoBizActionNotifyRequest.Result notifyResult = new PddServiceConsoCoBizActionNotifyRequest.Result();
//        notifyRequest.setMailNo(mailNo);
//        notifyRequest.setExpressCode(expressCode);
        notifyRequest.setBizActionDesc("开始拣货");
        notifyResult.setCode(102);
        notifyResult.setDesc("破损");
        notifyResult.setRemark("破损");

        notifyRequest.setResult(notifyResult);


        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.co.biz.action.notify");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    /**
     * 完成拣货异常
     */
    @Test
    public void finishPickError() {
        String LogisticsOrderCode = "PP25110414221207143137527";
        String action = "finish_pick";
        PddServiceConsoCoBizActionNotifyRequest notifyRequest = new PddServiceConsoCoBizActionNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setOrderCode(LogisticsOrderCode);
        notifyRequest.setBizAction(action);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");


        PddServiceConsoCoBizActionNotifyRequest.Result notifyResult = new PddServiceConsoCoBizActionNotifyRequest.Result();
        notifyRequest.setBizActionDesc("拣货完成");
        notifyResult.setCode(102);
        notifyResult.setRemark("破损");
        notifyResult.setDesc("破损");

        notifyRequest.setResult(notifyResult);


        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.co.biz.action.notify");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    /**
     * 拣货完成后出库异常
     */
    @Test
    public void outBoundError() {

        String mailNo = "BK-25110414221207143137527";
        String expressCode = "KR_JD";
        String orderCode = "PP25110414221207143137527";
//        String segmentCode = "RETURNSELLER";
        String segmentCode = "SENDTORECEVER";

        PddServiceConsoOutboundRequest notifyRequest = new PddServiceConsoOutboundRequest();

        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setOrderCode(orderCode);
        notifyRequest.setSegmentCode(segmentCode);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");
//        notifyRequest.setIsSplitOut("N");

        notifyRequest.setIsSplitOut("Y");


        notifyRequest.setPackageInfos(new ArrayList<>());
        PddServiceConsoOutboundRequest.PackageInfo packageInfo0 = new PddServiceConsoOutboundRequest.PackageInfo();
        notifyRequest.getPackageInfos().add(packageInfo0);
        packageInfo0.setOutboundMailNo(mailNo + "1");
        packageInfo0.setExpressCode(expressCode);
        packageInfo0.setPackageType("2");
        packageInfo0.setLength(30L);
        packageInfo0.setWidth(30L);
        packageInfo0.setHeight(30L);
        packageInfo0.setWeight(1000L);

        notifyRequest.setSenderDetail(new PddServiceConsoOutboundRequest.SenderDetail());
        notifyRequest.getSenderDetail().setName("海际集货仓");
        notifyRequest.getSenderDetail().setTelePhone("18660975251");
        notifyRequest.getSenderDetail().setCountry("CN");
        notifyRequest.getSenderDetail().setProvince("山东省");
        notifyRequest.getSenderDetail().setCity("临沂市");
        notifyRequest.getSenderDetail().setDistrict("兰山区");
        notifyRequest.getSenderDetail().setDetailAddress("山东省临沂市兰山区横九路与纵十路交汇兰山财金智慧云仓五期二层二号仓");

        notifyRequest.setReceiverDetail(new PddServiceConsoOutboundRequest.ReceiverDetail());
        notifyRequest.getReceiverDetail().setName("김명상");
        notifyRequest.getReceiverDetail().setTelePhone("01012345678");
        notifyRequest.getReceiverDetail().setCountry("KR");
        notifyRequest.getReceiverDetail().setProvince("서울특별시");
        notifyRequest.getReceiverDetail().setCity("강북구");
        notifyRequest.getReceiverDetail().setDistrict("강북구");
        notifyRequest.getReceiverDetail().setDetailAddress("护照1号");

        notifyRequest.setResult(new PddServiceConsoOutboundRequest.Result());
        notifyRequest.getResult().setCode(102);
        notifyRequest.getResult().setDesc("破损");
        notifyRequest.getResult().setRemark("破损");


        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.outbound");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }

    /**
     * 完成拆包异常
     */
    @Test
    public void finishUnpackError() {
        String LogisticsOrderCode = "PP25110415653142528037527";
        String action = "finish_unpack";
        PddServiceConsoCoBizActionNotifyRequest notifyRequest = new PddServiceConsoCoBizActionNotifyRequest();
        notifyRequest.setProviderCode(PROVIDER_CODE);
        notifyRequest.setOrderCode(LogisticsOrderCode);
        notifyRequest.setBizAction(action);
        notifyRequest.setExecuteTime(getNowString());
        notifyRequest.setTimeZone("UTC+8");


        PddServiceConsoCoBizActionNotifyRequest.Result notifyResult = new PddServiceConsoCoBizActionNotifyRequest.Result();

        notifyRequest.setBizActionDesc("拆包完成");
        notifyRequest.setUnpackRemark("");
        notifyResult.setCode(102);
        notifyResult.setDesc("破损");
        notifyResult.setRemark("破损");
        notifyRequest.setPackageInfos(new ArrayList<>());
        PddServiceConsoCoBizActionNotifyRequest.PackageInfo packageInfo0 = new PddServiceConsoCoBizActionNotifyRequest.PackageInfo();
        notifyRequest.getPackageInfos().add(packageInfo0);
        packageInfo0.setWeight(600L);
        packageInfo0.setWidth(30L);
        packageInfo0.setHeight(30L);
        packageInfo0.setLength(30L);
        packageInfo0.setActualWeight(600L);
        packageInfo0.setConsoType("SEA");
        packageInfo0.setGoodsType("NORMAL");

        notifyRequest.setResult(notifyResult);


        log.info("derelictionRequest:{}", JSON.toJSONString(notifyRequest));
        JYBaseRequestModel requestModel = new JYBaseRequestModel();
        requestModel.setRequest(JSON.toJSONString(notifyRequest));
        requestModel.setRequest_id("" + new Date().getTime());
        requestModel.setType("pdd.service.conso.co.biz.action.notify");
        requestModel.setTarget_client_id(CLIENT_ID);
        requestModel.setClient_id(CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);

    }
}
