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.pddjy.request.JYBaseRequestModel;
import org.ta.pddserver.model.pddjy.request.PddServiceConsoDerelictionRequest;
import org.ta.pddserver.model.pddjy.request.PddServiceConsoFirstBizActionNotifyRequest;
import org.ta.pddserver.utils.PddHttpTool;
import org.ta.pddserver.utils.PddSignTool;

import java.util.Date;

@Slf4j
public class CommonTest {

    private static final String PROVIDER_CODE = "HAIJI_KR";
    private static final String WAREHOUSE_CODE = "HJJY001";
    @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("8f5f3f9c92e847b2894fc9c0afce3d61");
        requestModel.setClient_id("8f5f3f9c92e847b2894fc9c0afce3d61");
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, "281d79ad5117d20a51efb9e7b0d5f7ee336399b0"));
        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("HAIJI_KR");
        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("8f5f3f9c92e847b2894fc9c0afce3d61");
        requestModel.setClient_id("8f5f3f9c92e847b2894fc9c0afce3d61");
        long time = new Date().getTime() / 1000;
        requestModel.setTimestamp(time);
        requestModel.setSign(PddSignTool.generateSign(requestModel, "281d79ad5117d20a51efb9e7b0d5f7ee336399b0"));
        log.info("requestModel:{}", JSON.toJSONString(requestModel));
//        String resp = PddHttpTool.postRequest(requestModel);
        String resp = PddHttpTool.sendJsonPost(requestModel);
        log.info("resp = {}", resp);
    }
}
