
package com.crm.manager.service.impl;

import com.crm.manager.dao.repository.SysKycConfigRepository;
import com.crm.manager.service.SysKycConfigService;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.pojo.table.SysKycConfigTable;
import com.crm.rely.backend.exception.ServiceException;
import com.crm.rely.backend.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysKycConfigServiceImpl implements SysKycConfigService {

    @Autowired
    private SysKycConfigRepository sysKycConfigRepository;

    @Autowired
    private RedisService redisService;

    @Override
    public SysKycConfigTable getByCode(String code) throws ServiceException {
        SysKycConfigTable sysKycConfigTable = redisService.getEntity(code, SysKycConfigTable.class);

        if (sysKycConfigTable == null) {
            sysKycConfigTable = sysKycConfigRepository.getByCode(code);
            if (sysKycConfigTable == null) {
                throw ServiceException.exception(Constants.INFO_NOT_FOUND);
            } else {
                redisService.save(sysKycConfigTable.getCode(), sysKycConfigTable);
            }

        }
        return sysKycConfigTable;
    }

    @Override
    public SysKycConfigTable getByCodeAndCountryAndEnable(String code, String country,Integer enable) throws ServiceException {
        SysKycConfigTable sysKycConfigTable = sysKycConfigRepository.getByCodeAndCountryAndEnable(code,country,enable);
        return sysKycConfigTable;
    }

}
