KuaidiCallBackService.java 2.88 KB
package com.huaheng.api.WAYBILLNO.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.pc.config.KDCertification.service.KDCertificationService;
import com.huaheng.pc.shipment.kuaidiHeader.domain.KuaidiHeader;
import com.huaheng.pc.shipment.kuaidiHeader.service.KuaidiHeaderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class KuaidiCallBackService {

    private final static Logger logger = LoggerFactory.getLogger(KuaidiCallBackService.class);
    @Resource
    private KDCertificationService kdCertificationService;
    @Autowired
    private KuaidiHeaderService kuaidiHeaderService;

    public void kuaidiCallback(JSONObject body, String warehouseCode) {
        String json = JSON.toJSONString(body);
        logger.info("获取快递单号:{}", json);
        System.out.println(body);
        String type = body.getString("type");
        if (StringUtils.isNotEmpty(type)) {
            if (type.equals("SEND")) {
                JSONObject data = body.getJSONObject("data");
                String number = data.getString("orderNum");
                System.out.println(number);
            }
            if (type.equals("UPDATE")) {
                JSONObject data = body.getJSONObject("data");
                String number = data.getString("orderNum");
                System.out.println(number);
            }
            if (type.equals("FILLEXPNUM")) {
                JSONObject data = body.getJSONArray("data").getJSONObject(0);
                String number = data.getString("orderNum");
                System.out.println(number);
                String dingdan = data.getString("kuaidinum");
                LambdaQueryWrapper<KuaidiHeader> queryWrapper = Wrappers.lambdaQueryNoWarehouse();
                queryWrapper.eq(KuaidiHeader::getKuaidiNum, number);
                queryWrapper.last("limit 1");
                KuaidiHeader kuaidiHeader = kuaidiHeaderService.getOne(queryWrapper);
                if (kuaidiHeader != null) {
                    if (StringUtils.isNotEmpty(kuaidiHeader.getTrackCode())) {
                        kuaidiHeader.setTrackCode(dingdan + "," + kuaidiHeader.getTrackCode());
                    } else {
                        kuaidiHeader.setTrackCode(dingdan);
                    }
                    kuaidiHeader.setDeleted(true);
                    kuaidiHeader.setLastUpdated(new Date());
                    kuaidiHeaderService.updateById(kuaidiHeader);
                }
                System.out.println(dingdan);
            }

        } else {
        }
    }
}