package org.ta.pddserver.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.ta.pddserver.entity.*;
import org.ta.pddserver.model.ConsignmentOrder;
import org.ta.pddserver.model.pddjy.request.JYBaseRequestModel;
import org.ta.pddserver.model.pddjy.request.*;
import org.ta.pddserver.model.pddlg.common.TraceObject;
import org.ta.pddserver.model.pddlg.request.LGBaseModel;
import org.ta.pddserver.model.pddlg.request.PddLogisticsCoTrackQueryRequest;
import org.ta.pddserver.model.pddlg.request.PddLogisticsCoTrackSubRequest;
import org.ta.pddserver.service.impl.*;
import org.ta.pddserver.utils.JsonResponse;
import org.ta.pddserver.utils.PddSignTool;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
public class PddOpenController {

    @Resource
    private OrderCreateImpl orderCreateImpl;
    @Resource
    private OutboundNoticeImpl outboundNoticeImpl;
    @Resource
    private OrderUpdateImpl orderUpdateImpl;
    @Resource
    private ReverseNotifyImpl reverseNotifyImpl;
    @Resource
    private FeeQueryImpl feeQueryImpl;
    @Resource
    private OrderQueryImpl orderQueryImpl;
    @Resource
    private PackOrderQueryImpl packOrderQueryImpl;
    @Resource
    private ReturnOrderQueryImpl returnOrderQueryImpl;
    @Resource
    private PackageQueryImpl packageQueryImpl;
    @Resource
    private PackageNoticeImpl packageNoticeImpl;
    @Resource
    private UnpackNoticeImpl unpackNoticeImpl;
    @Resource
    private UserIdentifyImpl userIdentifyImpl;
    @Resource
    TraceObjectImpl traceObjectImpl;

    @Resource
    private OrderImpl orderImpl;
    @Resource
    private OrderBuyerDetailImpl orderBuyerDetailImpl;
    @Resource
    private OrderItemImpl orderItemImpl;
    @Autowired
    private OrderMailDetailImpl orderMailDetailImpl;
    @Autowired
    private OrderPaymentDetailImpl orderPaymentDetailImpl;

    @PostMapping("/pdd-open")
    public JSONObject pddOpenAPI(HttpServletRequest request,
                                 @RequestBody JYBaseRequestModel requestParam) {
        String pdd_sign = request.getHeader("pdd_sign");
        if (StringUtils.isEmpty(pdd_sign)) {
            log.error("pdd_sign is empty");
        }
        log.info("pdd_sign:{}", pdd_sign);
//        log.info("PDD orderCreate, type={}", requestParam.getType());
//        log.info("target_client_id = {}, client_id = {}, request_id={}, sign={}, timestamp = {}, type={}",
//                requestParam.getTarget_client_id(), requestParam.getClient_id(), requestParam.getRequest_id(), requestParam.getSign(), requestParam.getTimestamp(), requestParam.getType()
//        );
        String body = getStringFromRequest(request);
        log.info("requestString = {}", body);

        if (PddSignTool.verifySignFromBody(body, "281d79ad5117d20a51efb9e7b0d5f7ee336399b0", pdd_sign)) {
            log.info("验签成功");
        }
        switch (requestParam.getType()) {
            case "pdd.service.conso.order.create": {
                PddServiceConsoOrderCreateRequest createParam = JSON.parseObject(body, PddServiceConsoOrderCreateRequest.class);
                OrderCreate(createParam);
                log.info("pdd service conso.order.create 集运单创建接口");
                // todo 不需特殊回复，但是code区分状态码
            }
            break;
            case "pdd.service.conso.outbound.notice": {
                PddServiceConsoOutboundNoticeRequest noticeParam = JSON.parseObject(body, PddServiceConsoOutboundNoticeRequest.class);
                OutboundNotice(noticeParam);
                log.info("pdd.service.conso.outbound.notice 出库通知");
                // todo 不需特殊回复，但是code区分状态码
            }
            break;
            case "pdd.service.conso.order.update": {
                PddServiceConsoOrderUpdateRequest updateRequest = JSON.parseObject(body, PddServiceConsoOrderUpdateRequest.class);
                OrderUpdate(updateRequest);
                log.info("pdd.service.conso.order.update 集运单更新");
                // todo 不需特殊回复，但是code区分状态码
            }
            break;
            case "pdd.service.conso.reverse.notify": {
                PddServiceConsoReverseNotifyRequest notifyRequest = JSON.parseObject(body, PddServiceConsoReverseNotifyRequest.class);
                ReverseNotify(notifyRequest);
                log.info("pdd.service.conso.reverse.notify 逆向通知");
                // todo 不需特殊回复，但是code区分状态码
            }
            break;
            case "pdd.service.conso.fee.query": {
                PddServiceConsoFeeQueryRequest queryRequest = JSON.parseObject(body, PddServiceConsoFeeQueryRequest.class);
                FeeQuery(queryRequest);
                log.info("pdd.service.conso.fee.query 集运费用查询");
                // todo 回复 PddServiceConsoFeeQueryResponse

            }
            break;
            case "pdd.service.conso.order.query": {
                PddServiceConsoOrderQueryRequest queryRequest = JSON.parseObject(body, PddServiceConsoOrderQueryRequest.class);
                OrderQuery(queryRequest);
                log.info("pdd.service.conso.order.query 集运单查询");
                // todo 回复 PddServiceConsoOrderQueryResponse

            }
            break;
            case "pdd.service.conso.pack.order.query": {
                PddServiceConsoPackOrderQueryRequest queryRequest = JSON.parseObject(body, PddServiceConsoPackOrderQueryRequest.class);
                PackOrderQuery(queryRequest);
                log.info("pdd.service.conso.pack.order.query 集运合包单状态查询接口");
                // todo 回复 PddServiceConsoPackOrderQueryQueryResponse
            }
            break;
            case "pdd.service.conso.return.order.query": {
                PddServiceConsoReturnOrderQueryRequest queryRequest = JSON.parseObject(body, PddServiceConsoReturnOrderQueryRequest.class);
                ReturnOrderQuery(queryRequest);
                log.info("pdd.service.conso.return.order.query");
                // todo 回复 PddServiceConsoReturnOrderQueryResponse
            }
            break;
            case "pdd.service.conso.package.query": {
                PddServiceConsoPackageQueryRequest queryRequest = JSON.parseObject(body, PddServiceConsoPackageQueryRequest.class);
                PackageQuery(queryRequest);
                log.info("pdd.service.conso.package.query");
                // todo 回复 PddServiceConsoPackageQueryResponse
            }
            break;
            case "pdd.service.conso.package.notice": {
                PddServiceConsoPackageNoticeRequest noticeRequest = JSON.parseObject(body, PddServiceConsoPackageNoticeRequest.class);
                PackageNotice(noticeRequest);
                log.info("pdd.service.conso.package.notice");
                // todo 不需特殊回复，但是code区分状态码
            }
            break;
            case "pdd.service.conso.unpack.notice": {
                PddServiceConsoUnpackNoticeRequest noticeRequest = JSON.parseObject(body, PddServiceConsoUnpackNoticeRequest.class);
                UnpackNotice(noticeRequest);
                log.info("pdd.service.conso.unpack.notice");
                // todo 不许特殊回复
            }
            break;
            case "pdd.service.conso.user.identify": {
                PddServiceConsoUserIdentifyRequest identifyRequest = JSON.parseObject(body, PddServiceConsoUserIdentifyRequest.class);
                UserIdentify(identifyRequest);
                log.info("pdd.service.conso.user.identify");
                // todo 不需特殊回复，但是code区分状态码
            }
            break;
            default: {
//                return JsonResponse.generateCommonFailedResponse(999, "UNKNOWN API");
            }
        }
        log.info("request_body = {}", JSON.toJSON(requestParam));
        return JsonResponse.generateOpenCommonSuccessResponse();
    }

    /**
     * 获取请求消息体文本
     *
     * @param request 请求
     * @return 消息体文本
     */
    private static String getStringFromRequest(HttpServletRequest request) {
        StringBuffer buffer = new StringBuffer();
        String line = null;
        try {
            BufferedReader reader = request.getReader();
            while ((line = reader.readLine()) != null) {
                buffer.append(line);
            }
        } catch (IOException e) {
            log.error(e.getMessage());
        }
        return buffer.toString();
    }

    @PostMapping("/pdd-lg")
    public JSONObject pddLogisticAPI(HttpServletRequest request,
                                     @RequestBody LGBaseModel requestParam) {
        log.info("PDD pddLogisticAPI, type={}", requestParam.getType());
        log.info("target_client_id = {}, client_id = {}, sign={}, timestamp = {}, type={}",
                requestParam.getTarget_client_id(), requestParam.getClient_id(), requestParam.getSign(), requestParam.getTimestamp(), requestParam.getType()
        );

        if (PddSignTool.verifyLGSign(requestParam, "281d79ad5117d20a51efb9e7b0d5f7ee336399b0")) {
            log.info("验签成功");
        }
        String body = getStringFromRequest(request);
        switch (requestParam.getType()) {
            case "pdd.logistics.co.track.sub": {
                log.info("pdd.logistics.co.track.sub 拼多多向物流公司订阅指定运单号的物流轨迹详情");
                PddLogisticsCoTrackSubRequest subRequest = JSON.parseObject(body, PddLogisticsCoTrackSubRequest.class);
                subRequest.parseData();
                log.info("快递公司运单号：{}", subRequest.getDataObject().getTrackingOrderNo());
                // todo 不需特殊回复，但是code区分状态码
            }
            break;
            case "pdd.logistics.co.track.query": {
                log.info("pdd.logistics.co.track.query 拼多多向物流公司查询指定运单号当前的完整物流轨迹信息。");
                PddLogisticsCoTrackQueryRequest subRequest = JSON.parseObject(body, PddLogisticsCoTrackQueryRequest.class);
                subRequest.parseData();
                log.info("快递公司运单号：{}", subRequest.getDataObject().getTrackingNumber());


                List<TraceObjectEntity> TraceObjectlist = traceObjectImpl.selectByTrackingNumber(subRequest.getDataObject().getTrackingNumber());
                List<TraceObject> list = new ArrayList<TraceObject>();

                for (TraceObjectEntity traceObjectEntity : TraceObjectlist) {
                    list.add(TraceObject.createFromTraceEntity(traceObjectEntity));
                }

                return JsonResponse.generateLGCommonSuccessResponse(requestParam.getShip_id(), list);
            }
            default: {
                log.info("request_body = {}", JSON.toJSON(requestParam));
                return JsonResponse.generateLGCommonFailedResponse(requestParam.getShip_id(), "999", "UNKNOWN API");
            }
        }

        return JsonResponse.generateLGCommonSuccessResponse(requestParam.getShip_id(), null);
    }

    public void OrderCreate(PddServiceConsoOrderCreateRequest createParam) {
        OrderCreateEntity orderCreateEntity = new OrderCreateEntity();
        orderCreateEntity.setProviderCode(createParam.getProviderCode());
        orderCreateEntity.setConsoWarehouseCode(createParam.getConsoWarehouseCode());
        orderCreateEntity.setLogisticsOrderCode(createParam.getLogisticsOrderCode());
        orderCreateEntity.setBizType(createParam.getBizType());
        orderCreateEntity.setConsoType(createParam.getConsoType());
        orderCreateEntity.setBuyerCode(createParam.getBuyerCode());
        orderCreateEntity.setDereRecogCode(createParam.getDereRecogCode());
        orderCreateEntity.setPackageQuantity(createParam.getPackageQuantity());
        orderCreateEntity.setMailDetails(JSONObject.toJSONString(createParam.getMailDetails()));
        orderCreateEntity.setItems(JSONObject.toJSONString(createParam.getItems()));
        orderCreateEntity.setBuyerDetail(JSONObject.toJSONString(createParam.getBuyerDetail()));
        orderCreateEntity.setPaymentDetail(JSONObject.toJSONString(createParam.getPaymentDetail()));
        orderCreateEntity.setTags(JSONObject.toJSONString(createParam.getTags()));
        orderCreateImpl.save(orderCreateEntity);

        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setUid(orderCreateEntity.getUid());
        orderEntity.setCreated(orderCreateEntity.getCreated());
        orderEntity.setUpdated(orderCreateEntity.getUpdated());
        orderEntity.setStatus(orderCreateEntity.getStatus());
        orderEntity.setState(orderCreateEntity.getState());
        orderEntity.setProviderCode(orderCreateEntity.getProviderCode());
        orderEntity.setConsoWarehouseCode(orderCreateEntity.getConsoWarehouseCode());
        orderEntity.setLogisticsOrderCode(orderCreateEntity.getLogisticsOrderCode());
        orderEntity.setBizType(orderCreateEntity.getBizType());
        orderEntity.setConsoType(orderCreateEntity.getConsoType());
        orderEntity.setBuyerCode(orderCreateEntity.getBuyerCode());
        orderEntity.setDereRecogCode(orderCreateEntity.getDereRecogCode());
        orderEntity.setPackageQuantity(orderCreateEntity.getPackageQuantity());
        orderImpl.save(orderEntity);

        OrderBuyerDetailEntity orderBuyerDetailEntity = new OrderBuyerDetailEntity();
        orderBuyerDetailEntity.setLogisticsOrderCode(orderCreateEntity.getLogisticsOrderCode());
        orderBuyerDetailEntity.setName(createParam.getBuyerDetail().getName());
        orderBuyerDetailEntity.setTelePhone(createParam.getBuyerDetail().getTelePhone());
        orderBuyerDetailEntity.setCountry(createParam.getBuyerDetail().getCountry());
        orderBuyerDetailEntity.setProvince(createParam.getBuyerDetail().getProvince());
        orderBuyerDetailEntity.setCity(createParam.getBuyerDetail().getCity());
        orderBuyerDetailEntity.setDistrict(createParam.getBuyerDetail().getDistrict());
        orderBuyerDetailEntity.setDetailAddress(createParam.getBuyerDetail().getDetailAddress());
        orderBuyerDetailEntity.setPostCode(createParam.getBuyerDetail().getPostCode());
        orderBuyerDetailImpl.save(orderBuyerDetailEntity);

        for (PddServiceConsoOrderCreateRequest.Item item: createParam.getItems()) {
            OrderItemEntity orderItemEntity = new OrderItemEntity();
            orderItemEntity.setLogisticsOrderCode(orderCreateEntity.getLogisticsOrderCode());
            orderItemEntity.setItemId(item.getItemId());
            orderItemEntity.setItemName(item.getItemName());
            orderItemEntity.setCategoryId(item.getCategoryId());
            orderItemEntity.setCategoryName(item.getCategoryName());
            orderItemEntity.setTotalActualPayment(item.getTotalActualPayment());
            orderItemEntity.setCurrencyUnit(item.getCurrencyUnit());
            orderItemEntity.setCurrency(item.getCurrency());
            orderItemEntity.setItemQuantity(item.getItemQuantity());
            orderItemEntity.setItemPicUrl(item.getItemPicUrl());
            orderItemEntity.setItemSkuProperty(item.getItemSkuProperty());
            orderItemEntity.setChargedStatus(item.getChargedStatus());
            orderItemEntity.setGoodsType(item.getGoodsType());
            orderItemEntity.setMagneticStatus(item.getMagneticStatus());
            orderItemImpl.save(orderItemEntity);
        }

        for (PddServiceConsoOrderCreateRequest.MailDetail mailDetail: createParam.getMailDetails()) {
            OrderMailDetailEntity orderMailDetail = new OrderMailDetailEntity();
            orderMailDetail.setExpressCode(mailDetail.getExpressCode());
            orderMailDetail.setMailNo(mailDetail.getMailNo());
            orderMailDetailImpl.save(orderMailDetail);
        }

        OrderPaymentDetailEntity orderPaymentDetailEntity = new OrderPaymentDetailEntity();
        orderPaymentDetailEntity.setTradeOrderSn(createParam.getPaymentDetail().getTradeOrderSn());
        orderPaymentDetailEntity.setTradeOrderValue(createParam.getPaymentDetail().getTradeOrderValue());
        orderPaymentDetailEntity.setTradeOrderActualAmount(createParam.getPaymentDetail().getTradeOrderActualAmount());
        orderPaymentDetailEntity.setCurrencyUnit(createParam.getPaymentDetail().getCurrencyUnit());
        orderPaymentDetailEntity.setCurrency(createParam.getPaymentDetail().getCurrency());
        orderPaymentDetailImpl.save(orderPaymentDetailEntity);

    }

    public void OutboundNotice(PddServiceConsoOutboundNoticeRequest noticeParam) {
        OutboundNoticeEntity outboundNoticeEntity = new OutboundNoticeEntity();
        outboundNoticeEntity.setProviderCode(noticeParam.getProviderCode());
        outboundNoticeEntity.setConsoWarehouseCode(noticeParam.getConsoWarehouseCode());
        outboundNoticeEntity.setOrderCode(noticeParam.getOrderCode());
        outboundNoticeEntity.setBuyerCode(noticeParam.getBuyerCode());
        outboundNoticeEntity.setLogisticsOrderCodes(JSONObject.toJSONString(noticeParam.getLogisticsOrderCodes()));
        outboundNoticeEntity.setOrderSns(JSONObject.toJSONString(noticeParam.getOrderSns()));
        outboundNoticeEntity.setOrderDetails(JSONObject.toJSONString(noticeParam.getOrderDetails()));
        outboundNoticeEntity.setTradeOrderActualAmountTotal(noticeParam.getTradeOrderActualAmountTotal());
        outboundNoticeEntity.setItemQuantityTotal(noticeParam.getItemQuantityTotal());
        outboundNoticeEntity.setSegmentCode(noticeParam.getSegmentCode());
        outboundNoticeEntity.setConsoType(noticeParam.getConsoType());
        outboundNoticeEntity.setDeliveryType(noticeParam.getDeliveryType());
        outboundNoticeEntity.setStationCode(noticeParam.getStationCode());
        outboundNoticeEntity.setMailDetails(JSONObject.toJSONString(noticeParam.getMailDetails()));
        outboundNoticeEntity.setReceiverDetail(JSONObject.toJSONString(noticeParam.getReceiverDetail()));
        outboundNoticeEntity.setFreightFeeDetail(JSONObject.toJSONString(noticeParam.getFreightFeeDetail()));

        outboundNoticeImpl.save(outboundNoticeEntity);
    }

    public void OrderUpdate(PddServiceConsoOrderUpdateRequest updateRequest) {
        OrderUpdateEntity orderUpdateEntity = new OrderUpdateEntity();
        orderUpdateEntity.setProviderCode(updateRequest.getProviderCode());
        orderUpdateEntity.setConsoWarehouseCode(updateRequest.getConsoWarehouseCode());
        orderUpdateEntity.setLogisticsOrderCode(updateRequest.getLogisticsOrderCode());
        orderUpdateEntity.setPackageQuantity(updateRequest.getPackageQuantity());
        orderUpdateEntity.setMailDetails(JSONObject.toJSONString(updateRequest.getMailDetails()));
        orderUpdateEntity.setTags(JSONObject.toJSONString(updateRequest.getTags()));
        orderUpdateImpl.save(orderUpdateEntity);

        //根据集运单号更新包裹数量
        orderImpl.savePackageQuantity(orderUpdateEntity.getLogisticsOrderCode(), orderUpdateEntity.getPackageQuantity());

        //最新详情列表
        List<PddServiceConsoOrderUpdateRequest.MailDetail> listNew = updateRequest.getMailDetails();

        //根据集运单号获取运单详情列表
        List<OrderMailDetailEntity> list = orderMailDetailImpl.getListByCode(orderUpdateEntity.getLogisticsOrderCode());
        for(OrderMailDetailEntity orderMailDetailEntity : list){
            for(PddServiceConsoOrderUpdateRequest.MailDetail  mailDetail : listNew){
                if(orderMailDetailEntity.getMailNo().equals(mailDetail.getMailNo())){
                    //相同，删除
                    list.remove(orderMailDetailEntity);
                    listNew.remove(mailDetail);
                    break;
                }
            }
        }

        //判断是否有剩余
        for(PddServiceConsoOrderUpdateRequest.MailDetail  mailDetail : listNew){
            OrderMailDetailEntity orderMailDetailEntity = new OrderMailDetailEntity();
            orderMailDetailEntity.setExpressCode(mailDetail.getExpressCode());
            orderMailDetailEntity.setMailNo(mailDetail.getMailNo());
            orderMailDetailImpl.save(orderMailDetailEntity);
        }

        for(OrderMailDetailEntity orderMailDetailEntity : list){
            orderMailDetailImpl.removeById(orderMailDetailEntity.getUid());
        }

    }


    public void ReverseNotify(PddServiceConsoReverseNotifyRequest notifyRequest) {
        ReverseNotifyEntity reverseNotifyEntity = new ReverseNotifyEntity();
        reverseNotifyEntity.setProviderCode(notifyRequest.getProviderCode());
        reverseNotifyEntity.setConsoWarehouseCode(notifyRequest.getConsoWarehouseCode());
        reverseNotifyEntity.setOrderCode(notifyRequest.getOrderCode());
        reverseNotifyEntity.setOrderType(notifyRequest.getOrderType());
        reverseNotifyEntity.setStatus(notifyRequest.getStatus());

        reverseNotifyImpl.save(reverseNotifyEntity);
    }

    public void FeeQuery(PddServiceConsoFeeQueryRequest queryRequest) {
        FeeQueryEntity feeQueryEntity = new FeeQueryEntity();
        feeQueryEntity.setProviderCode(queryRequest.getProviderCode());
        feeQueryEntity.setConsoWarehouseCode(queryRequest.getConsoWarehouseCode());
        feeQueryEntity.setLogisticsPackOrderCode(queryRequest.getLogisticsPackOrderCode());
        feeQueryEntity.setLogisticsOrderCodes(JSONObject.toJSONString(queryRequest.getLogisticsOrderCodes()));
        feeQueryEntity.setBizType(queryRequest.getBizType());
        feeQueryEntity.setFreightPackageType(queryRequest.getFreightPackageType());
        feeQueryEntity.setGoodsType(queryRequest.getGoodsType());
        feeQueryEntity.setSegmentCode(queryRequest.getSegmentCode());
        feeQueryEntity.setDeliveryType(queryRequest.getDeliveryType());
        feeQueryEntity.setConsoType(queryRequest.getConsoType());
        feeQueryEntity.setMailDetails(JSONObject.toJSONString(queryRequest.getMailDetails()));
        feeQueryEntity.setReceiverDetail(JSONObject.toJSONString(queryRequest.getReceiverDetail()));
        feeQueryImpl.save(feeQueryEntity);
    }

    public void OrderQuery(PddServiceConsoOrderQueryRequest queryRequest) {
        OrderQueryEntity orderQueryEntity = new OrderQueryEntity();
        orderQueryEntity.setProviderCode(queryRequest.getProviderCode());
        orderQueryEntity.setLogisticsOrderCode(queryRequest.getLogisticsOrderCode());

        orderQueryImpl.save(orderQueryEntity);
    }

    public void PackOrderQuery(PddServiceConsoPackOrderQueryRequest queryRequest) {
        PackOrderQueryEntity packOrderQueryEntity = new PackOrderQueryEntity();
        packOrderQueryEntity.setProviderCode(queryRequest.getProviderCode());
        packOrderQueryEntity.setOrderCode(queryRequest.getOrderCode());

        packOrderQueryImpl.save(packOrderQueryEntity);
    }

    public void ReturnOrderQuery(PddServiceConsoReturnOrderQueryRequest queryRequest) {
        ReturnOrderQueryEntity returnOrderQueryEntity = new ReturnOrderQueryEntity();
        returnOrderQueryEntity.setProviderCode(queryRequest.getProviderCode());
        returnOrderQueryEntity.setOrderCode(queryRequest.getOrderCode());

        returnOrderQueryImpl.save(returnOrderQueryEntity);
    }

    public void PackageQuery(PddServiceConsoPackageQueryRequest queryRequest) {
        PackageQueryEntity packageQueryEntity = new PackageQueryEntity();
        packageQueryEntity.setOrderCode(queryRequest.getOrderCode());
        packageQueryEntity.setOrderCodeType(queryRequest.getOrderCodeType());
        packageQueryEntity.setProviderCode(queryRequest.getProviderCode());
        packageQueryEntity.setMailDetails(JSONObject.toJSONString(queryRequest.getMailDetails()));

        packageQueryImpl.save(packageQueryEntity);
    }

    public void PackageNotice(PddServiceConsoPackageNoticeRequest noticeRequest) {
        PackageNoticeEntity packageNoticeEntity = new PackageNoticeEntity();
        packageNoticeEntity.setOrderCode(noticeRequest.getOrderCode());
        packageNoticeEntity.setOrderCodeType(noticeRequest.getOrderCodeType());
        packageNoticeEntity.setProviderCode(noticeRequest.getProviderCode());
        packageNoticeEntity.setMailDetails(JSONObject.toJSONString(noticeRequest.getMailDetails()));

        packageNoticeImpl.save(packageNoticeEntity);
    }

    public void UnpackNotice(PddServiceConsoUnpackNoticeRequest noticeRequest) {
        UnpackNoticeEntity unpackNoticeEntity = new UnpackNoticeEntity();
        unpackNoticeEntity.setOrderCode(noticeRequest.getOrderCode());
        unpackNoticeEntity.setBuyerCode(noticeRequest.getBuyerCode());
        unpackNoticeEntity.setConsoType(noticeRequest.getConsoType());
        unpackNoticeEntity.setConsoWarehouseCode(noticeRequest.getConsoWarehouseCode());
        unpackNoticeEntity.setDeliveryType(noticeRequest.getDeliveryType());
        unpackNoticeEntity.setProviderCode(noticeRequest.getProviderCode());
        unpackNoticeEntity.setMailDetails(JSONObject.toJSONString(noticeRequest.getMailDetails()));
        unpackNoticeEntity.setReceiverDetail(JSONObject.toJSONString(noticeRequest.getReceiverDetail()));

        unpackNoticeImpl.save(unpackNoticeEntity);
    }

    public void UserIdentify(PddServiceConsoUserIdentifyRequest identifyRequest) {
        UserIdentifyEntity userIdentifyEntity = new UserIdentifyEntity();
        userIdentifyEntity.setMobileNo(identifyRequest.getMobileNo());
        userIdentifyEntity.setIdType(identifyRequest.getIdType());
        userIdentifyEntity.setIdNumber(identifyRequest.getIdNumber());
        userIdentifyEntity.setName(identifyRequest.getName());

        userIdentifyImpl.save(userIdentifyEntity);
    }
}
