package com.hzs.system.config.provider;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.EYesNo;
import com.hzs.common.domain.system.config.BdAreaFreePostage;
import com.hzs.system.config.IAreaFreePostageServiceApi;
import com.hzs.system.config.service.IBdAreaFreePostageService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 专区免邮服务
 */
@DubboService
public class AreaFreePostageProvider implements IAreaFreePostageServiceApi {

    @Autowired
    private IBdAreaFreePostageService iBdAreaFreePostageService;

    @Override
    public R<BdAreaFreePostage> queryAreaFreePostage(Integer specialArea, Integer pkCountry) {
        BdAreaFreePostage areaFreePostage = null;

        LambdaQueryWrapper<BdAreaFreePostage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BdAreaFreePostage::getPkCountry, pkCountry);
        queryWrapper.eq(BdAreaFreePostage::getSpecialArea, specialArea);
        queryWrapper.eq(BdAreaFreePostage::getEnableState, EYesNo.YES.getIntValue());
        queryWrapper.orderByDesc(BdAreaFreePostage::getCreationTime);
        List<BdAreaFreePostage> list = iBdAreaFreePostageService.list(queryWrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            areaFreePostage = list.get(0);
        }
        return R.ok(areaFreePostage);
    }

}
