package com.fs.third.controller;

import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.his.domain.FsStoreOrder;
import com.fs.his.service.IFsStoreOrderService;
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;

import java.util.Map;

import static com.fs.his.utils.PhoneUtil.decryptPhone;

@RestController
@RequestMapping("/third/weizou")
public class WeizouController extends BaseController {
    @Autowired
    private IFsStoreOrderService fsStoreOrderService;
    /**
     * 微走发货同步接口
     */
    @PostMapping("/sendGoodsThirdParty")
    public AjaxResult sendGoodsThirdParty(@RequestBody Map map) {
        String thirdPartySecret = (String) map.get("thirdPartySecret");
        String s = decryptPhone(thirdPartySecret);
        if (!s.equals("weizou_send_goods_call_back")) {
            return error("认证失败，请核验参数");
        }
        FsStoreOrder fsStoreOrder = new FsStoreOrder();
        if (map.get("orderCode") == null) {
            return error("参数异常请核验参数");
        }
        fsStoreOrder.setOrderId(Long.valueOf((String) map.get("orderCode")));
        fsStoreOrder.setOperator("微走发货同步");
// 校验物流单号
        if (map.get("deliverySn") == null) {
            return error("参数异常请核验参数：deliverySn不能为空");
        }
        fsStoreOrder.setDeliverySn((String) map.get("deliverySn"));
// 校验物流代码
        if (map.get("deliveryCode") == null) {
            return error("参数异常请核验参数：deliveryCode不能为空");
        }
        fsStoreOrder.setDeliveryCode((String) map.get("deliveryCode"));
// 校验物流名称
        if (map.get("deliveryName") == null) {
            return error("参数异常请核验参数：deliveryName不能为空");
        }
        fsStoreOrder.setDeliveryName((String) map.get("deliveryName"));

        return toAjax(fsStoreOrderService.sendGoodsWeizou(fsStoreOrder, "微走发货同步"));
    }
}
