package cn.superdesk.uniorder.common.excel.validate;

import cn.hutool.core.util.StrUtil;
import cn.superdesk.uniorder.common.mq.redis.service.RedisService;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2021/8/27 下午2:28
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/8/27 下午2:28
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@AllArgsConstructor
@Slf4j
@Builder(toBuilder = true)
public class RelationCheckFromCacheRedisUtils {

//	public RelationCheckFromCacheRedisUtils() {
//		cacheService = SpringContextHolder.getBean(CacheService.class);
//	}

	/**
	 * 字段值
	 */
	private String       fieldValue;
	/**
	 * 前缀
	 */
	private String       cachePrefix;
	/**
	 * cacheKey
	 */
	private String       cacheKey;
	/**
	 *
	 */
	private String       message;
	/**
	 *
	 */
	private RedisService redisService;

	/**
	 * 逻辑是这样的 如果有问题 返回 true
	 *
	 * @return {@code false} if {@code value} does not pass the constraint
	 */
	public boolean isEntry() {

//		log.info("hashTable@{}@field@{}@cacheService@{}", cachePrefix + ":" + cacheKey, fieldValue, cacheService);

//		redisService.setDatabase(2);
//		redisService.getRedisInfo(RedisInfoEnum.clients.getKey());

//		cachePrefix + ":" + cacheKey
//		"relation:sys_enterprise_ext_invoice:company_name"
//		String cacheStr = (String) cacheService.hashGetByKey(cachePrefix + ":" + cacheKey, URLUtil.encode(fieldValue.trim()));
		String cacheStr = (String) redisService.hashGetByKey(cachePrefix + ":" + cacheKey, fieldValue.trim());
//		String cacheStr = (String) cacheService.hashGetByKey(cachePrefix + ":" + cacheKey, "中航物业管理有限公司济南分公司");

		log.info("CCCC {} -> {}", fieldValue, cacheStr);

		if (StrUtil.isEmpty(cacheStr)) {
			return false;
		}
		return true;
	}

}
