package com.hzs.sale.postage.provider;

import com.hzs.common.core.domain.R;
import com.hzs.common.core.exception.ServiceException;
import com.hzs.sale.postage.IPostageServiceApi;
import com.hzs.sale.postage.dto.PostageProductDTO;
import com.hzs.sale.postage.service.IPostageBusinessService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Description: 邮费服务API
 * @Author: jiang chao
 * @Time: 2023/4/25 14:41
 * @Classname: IPostageServiceProvider
 * @PackageName: com.hzs.sale.postage.provider
 */
@Slf4j
@DubboService
public class IPostageServiceProvider implements IPostageServiceApi {

    @Autowired
    private IPostageBusinessService iPostageBusinessService;

    @Override
    public R<BigDecimal> queryPostage(Integer pkId, List<PostageProductDTO> productList, Integer province, Integer recCity) {
        try {
            return R.ok(iPostageBusinessService.queryPostage(pkId, productList, province, recCity));
        } catch (ServiceException se) {
            log.error("查询邮费模板数据异常， 模板ID： {}", pkId, se);
            return R.fail(se.getMessage());
        } catch (Exception e) {
            log.error("查询邮费模板异常， 模板ID： {}", pkId, e);
        }
        return R.fail();
    }

}
