package org.ta.pddserver;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.ta.pddserver.config.PddAPIConfig;
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 String firstLogisticsOrderCode = "PC25111006871947680723271";

    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(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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 = "SF3270717746148";
        String expressCode = "SF";
        String action = "warehouse_sign";
        PddServiceConsoFirstBizActionNotifyRequest notifyRequest = new PddServiceConsoFirstBizActionNotifyRequest();
        notifyRequest.setProviderCode(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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 = "SF3270717746148";
        String expressCode = "SF";
        PddServiceConsoInboundRequest notifyRequest = new PddServiceConsoInboundRequest();


//        PddServiceConsoFirstBizActionNotifyRequest notifyRequest = new PddServiceConsoFirstBizActionNotifyRequest();
        notifyRequest.setProviderCode(PddAPIConfig.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(1000L);
        notifyRequest.getPackageInfo().setActualWeight(1000L);
        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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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 = "PP25110920956210797423271";
        String action = "finish_pick";
        PddServiceConsoCoBizActionNotifyRequest notifyRequest = new PddServiceConsoCoBizActionNotifyRequest();
        notifyRequest.setProviderCode(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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 = "KRJDV329857683219";
        String expressCode = "KRJDV";
        String orderCode = "PP25111014321660730023271";
//        String segmentCode = "RETURNSELLER";
        String segmentCode = "SENDTORECEVER";

        PddServiceConsoOutboundRequest notifyRequest = new PddServiceConsoOutboundRequest();

        notifyRequest.setProviderCode(PddAPIConfig.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(60L);
        packageInfo0.setWidth(30L);
        packageInfo0.setHeight(30L);
        packageInfo0.setWeight(2000L);
        packageInfo0.setInboundMailDetails(new ArrayList<>());
        PddServiceConsoOutboundRequest.InboundMailDetail inboundMailDetail0 = new PddServiceConsoOutboundRequest.InboundMailDetail();
        packageInfo0.getInboundMailDetails().add(inboundMailDetail0);
        inboundMailDetail0.setMailNo("SF3279615820942");
        inboundMailDetail0.setExpressCode("SF");
        PddServiceConsoOutboundRequest.InboundMailDetail inboundMailDetail1 = new PddServiceConsoOutboundRequest.InboundMailDetail();
        packageInfo0.getInboundMailDetails().add(inboundMailDetail1);
        inboundMailDetail1.setMailNo("SF3298576832192");
        inboundMailDetail1.setExpressCode("SF");


        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(1000L);
        packageInfo.setInboundMailDetails(new ArrayList<>());
        PddServiceConsoOutboundRequest.InboundMailDetail inboundMailDetail2 = new PddServiceConsoOutboundRequest.InboundMailDetail();
        packageInfo.getInboundMailDetails().add(inboundMailDetail2);
        inboundMailDetail2.setMailNo("SF3298576832194");
        inboundMailDetail2.setExpressCode("SF");


        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("符合");

        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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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 = "PP25111014321660729723271";
        String action = "finish_unpack";
        PddServiceConsoCoBizActionNotifyRequest notifyRequest = new PddServiceConsoCoBizActionNotifyRequest();
        notifyRequest.setProviderCode(PddAPIConfig.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 packageInfo1 = new PddServiceConsoCoBizActionNotifyRequest.PackageInfo();
        notifyRequest.getPackageInfos().add(packageInfo1);
        packageInfo1.setWeight(2000L);
        packageInfo1.setWidth(30L);
        packageInfo1.setHeight(30L);
        packageInfo1.setLength(30L);
        packageInfo1.setActualWeight(2000L);
        packageInfo1.setConsoType("SEA");
        packageInfo1.setGoodsType("SPECIAL");

//        PddServiceConsoCoBizActionNotifyRequest.PackageInfo packageInfo0 = new PddServiceConsoCoBizActionNotifyRequest.PackageInfo();
//        notifyRequest.getPackageInfos().add(packageInfo0);
//        packageInfo0.setWeight(1000L);
//        packageInfo0.setWidth(30L);
//        packageInfo0.setHeight(30L);
//        packageInfo0.setLength(30L);
//        packageInfo0.setActualWeight(1000L);
//        packageInfo0.setConsoType("SEA");
//        packageInfo0.setGoodsType("SPECIAL");

        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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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 = "SF3298576832194";
        String expressCode = "SF";
        String dereRecogCode = "51110ANK19872";
        PddServiceConsoDerelictionRequest notifyRequest = new PddServiceConsoDerelictionRequest();
        notifyRequest.setProviderCode(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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 = "SF3298516646348";
        String expressCode = "SF";
        PddServiceConsoProblemOrderNotifyRequest notifyRequest = new PddServiceConsoProblemOrderNotifyRequest();
        notifyRequest.setProviderCode(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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 = "SF3298513357701";
        String expressCode = "SF";
        String action = "destroy";
        PddServiceConsoFirstBizActionNotifyRequest notifyRequest = new PddServiceConsoFirstBizActionNotifyRequest();
        notifyRequest.setProviderCode(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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 = "KRJDV3298515094483";
        String expressCode = "KRJDV";
        String orderCode = "PP25111017757634566623271";
//        String segmentCode = "RETURNSELLER";
        String segmentCode = "SENDTORECEVER";

        PddServiceConsoOutboundRequest notifyRequest = new PddServiceConsoOutboundRequest();

        notifyRequest.setProviderCode(PddAPIConfig.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);
        packageInfo0.setExpressCode(expressCode);
        packageInfo0.setPackageType("2");
        packageInfo0.setLength(30L);
        packageInfo0.setWidth(30L);
        packageInfo0.setHeight(30L);
        packageInfo0.setWeight(800L);

        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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.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(PddAPIConfig.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(PddAPIConfig.CLIENT_ID);
        requestModel.setClient_id(PddAPIConfig.CLIENT_ID);
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, PddAPIConfig.CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);

    }
}
