package com.hzs.system.config.provider;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.constant.SystemFieldConstants;
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;

/**
 * @Description: 专区免邮服务
 * @Author: jiang chao
 * @Time: 2023/12/1 11:22
 * @Classname: AreaFreePostageProvider
 * @PackageName: com.hzs.system.config.provider
 */
@DubboService
public class AreaFreePostageProvider implements IAreaFreePostageServiceApi {

    @Autowired
    private IBdAreaFreePostageService iBdAreaFreePostageService;

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

        QueryWrapper<BdAreaFreePostage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(SystemFieldConstants.PK_COUNTRY, pkCountry);
        queryWrapper.eq("SPECIAL_AREA", specialArea);
        queryWrapper.eq("ENABLE_STATE", EYesNo.YES.getIntValue());
        queryWrapper.orderByDesc(SystemFieldConstants.CREATION_TIME);
        List<BdAreaFreePostage> list = iBdAreaFreePostageService.list(queryWrapper);
        if (CollectionUtil.isNotEmpty(list)) {
            areaFreePostage = list.get(0);
        }
        return R.ok(areaFreePostage);
    }

}
