package com.lantone.qc.dbanaly.facade.comsis;

import com.lantone.qc.dbanaly.util.RedisUtil;
import com.lantone.qc.dbanaly.vo.CrfCacheRemoveVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @Description:
 * @author: rengb
 * @time: 2020/6/17 16:57
 */
@Component
public class RedisFacade {
    @Autowired
    private RedisUtil redisUtil;

    public boolean crfCacheRemove(CrfCacheRemoveVO crfCacheRemoveVO) {
        if (crfCacheRemoveVO.getHospitalId() == null) {
            return true;
        }
        String prex = "crf_cache:" + crfCacheRemoveVO.getHospitalId() + ":";
        Set<String> behospitalCodes = crfCacheRemoveVO.getBehospitalCodes();
        if (behospitalCodes == null || behospitalCodes.size() == 0) {
            behospitalCodes = redisUtil.keys(prex + "*");
        } else {
            for (String behospitalCode : behospitalCodes) {
                behospitalCode = prex + behospitalCode;
            }
        }
        behospitalCodes.forEach(behospitalCode -> {
            redisUtil.del(behospitalCode);
        });
        return true;
    }

}