package com.hzs.system.config.provider;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hzs.common.core.domain.R;
import com.hzs.common.domain.system.config.BdAgreementRenewalWhite;
import com.hzs.system.config.service.IBdAgreementRenewalWhiteService;
import com.hzs.system.config.IAgreementRenewalWhiteServiceApi;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Description: 自动续约服务处理
 * @Author: jiang chao
 * @Time: 2024/6/17 15:06
 * @Classname: AgreementRenewalWhiteServiceProvider
 * @PackageName: com.hzs.system.config.provider
 */
@Slf4j
@DubboService
public class AgreementRenewalWhiteServiceProvider implements IAgreementRenewalWhiteServiceApi {

    @Autowired
    private IBdAgreementRenewalWhiteService iBdAgreementRenewalWhiteService;

    @Override
    public R<?> saveBatch(List<BdAgreementRenewalWhite> whiteList) {
        try {
            iBdAgreementRenewalWhiteService.saveBatch(whiteList);
            return R.ok();
        } catch (Exception e) {
            log.error("批量保存续约白名单异常", e);
            return R.fail(e.getMessage());
        }
    }

    @Override
    public R<BdAgreementRenewalWhite> getInfo(Long pkMember, Integer type) {
        try {
            return R.ok(iBdAgreementRenewalWhiteService.getOne(Wrappers.<BdAgreementRenewalWhite>lambdaQuery()
                    .eq(BdAgreementRenewalWhite::getPkMember, pkMember)
                    .eq(BdAgreementRenewalWhite::getType, type)
            ));
        } catch (Exception e) {
            log.error("查询会员续约配置异常", e);
            return R.fail(e.getMessage());
        }
    }

}
