
package com.tmerclub.cloud.multishop.feign;

import com.tmerclub.cloud.api.multishop.feign.ShopSubstituteSalesFeignClient;
import com.tmerclub.cloud.common.constant.Constant;
import com.tmerclub.cloud.common.product.constant.SalesType;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.vo.ShopSubstituteSalesVO;
import com.tmerclub.cloud.multishop.mapper.ShopSubstituteSalesMapper;
import com.tmerclub.cloud.multishop.model.ShopSubstituteSales;
import com.tmerclub.cloud.multishop.service.ShopSubstituteSalesService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author xxw
 * @date 2022/6/24 15:38
 */
@DubboService
public class ShopSubstituteSalesFeignController implements ShopSubstituteSalesFeignClient {
    @Autowired
    private ShopSubstituteSalesMapper shopSubstituteSalesMapper;

    @Autowired
    private ShopSubstituteSalesService shopSubstituteSalesService;

    @Override
    public ServerResponseEntity<ShopSubstituteSalesVO> getByShopSubstituteSalesId(Long shopId) {
        ShopSubstituteSalesVO byShopSubstituteSalesId = shopSubstituteSalesService.getByShopSubstituteSalesId(shopId);
        return ServerResponseEntity.success(byShopSubstituteSalesId);
    }

    @Override
    public ServerResponseEntity<List<ShopSubstituteSalesVO>> shopSubstituteSalesList(List<Long> shopIdList) {
        List<ShopSubstituteSalesVO> shopSubstituteSalesList = new ArrayList<>(Constant.INITIAL_CAPACITY);
        if (Objects.isNull(shopIdList) || shopIdList.size() == 0) {
            return ServerResponseEntity.success(shopSubstituteSalesList);
        }
        shopSubstituteSalesList = shopSubstituteSalesMapper.listByShopIds(shopIdList);
        return ServerResponseEntity.success(shopSubstituteSalesList);
    }

    @Override
    public void saveDefault(Long shopId) {
        // 保存店铺代销设置默认值
        ShopSubstituteSales shopSubstituteSales = new ShopSubstituteSales();
        shopSubstituteSales.setShopId(shopId);
        shopSubstituteSales.setSalesType(SalesType.MANUAL_OPERATION_PRICE.value());
        shopSubstituteSales.setOrderShape(0);
        shopSubstituteSalesService.save(shopSubstituteSales);
    }
}
