
package com.tmerclub.cloud.multishop.feign;

import com.tmerclub.cloud.api.multishop.vo.ShopDetailVO;
import com.tmerclub.cloud.common.order.constant.ShopType;
import com.tmerclub.cloud.common.order.feign.OrderShopDetailFeignClient;
import com.tmerclub.cloud.common.order.vo.ShopInfoInOrderVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.multishop.service.ShopDetailService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Objects;

/**
 * @author tmerclub
 * @date 2020/11/23
 */
@DubboService
public class OrderShopDetailFeignController implements OrderShopDetailFeignClient {
    @Autowired
    private ShopDetailService shopDetailService;

    @Override
    public ServerResponseEntity<ShopInfoInOrderVO> getShopInfoInOrderByShopId(Long shopId) {
        ShopDetailVO shopDetail = shopDetailService.getByShopId(shopId);
        ShopInfoInOrderVO shopInfoInOrderVO = new ShopInfoInOrderVO();
        if (Objects.isNull(shopDetail)) {
            shopInfoInOrderVO.setShopName("");
            // 普通店
            shopInfoInOrderVO.setType(ShopType.STOP.value());
            return ServerResponseEntity.success(shopInfoInOrderVO);
        }
        shopInfoInOrderVO.setShopName(shopDetail.getShopName());
        shopInfoInOrderVO.setType(shopDetail.getType());
        return ServerResponseEntity.success(shopInfoInOrderVO);
    }
}
