package com.fjhx.controller.thirdpartypush;

import com.alibaba.fastjson.JSONObject;
import com.fjhx.service.logistics.LogisticsInfoService;
import com.fjhx.uitl.kd100.KD100Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 第三方推送 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-12-09
 */
@RestController
@RequestMapping("/third/party/push")
public class ThirdPartyPushController {

    @Autowired
    private LogisticsInfoService logisticsInfoService;

    /**
     * kd100回调
     *
     * @param data 物流信息
     * @return
     */
    @PostMapping("/kd100")
    public JSONObject kd100(@RequestBody String data) {
        JSONObject returnResult = new JSONObject();
        returnResult.put("result", true);
        returnResult.put("returnCode", "200");
        returnResult.put("message", "成功");

        JSONObject result = KD100Util.parsePushData(data);

        //更新物流信息
        logisticsInfoService.updateStatusByCode(result.getString("nu"), result.getInteger("state"));

        return returnResult;
    }
}

