/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.crunii.com</a>
 */
package com.crunii.micro.domain.service.impl;

import com.crunii.micro.common.constants.CommonConstants;
import com.crunii.micro.common.constants.RedisKeys;
import com.crunii.micro.common.utils.JsonUtil;
import com.crunii.micro.domain.dto.Worker;
import com.crunii.micro.domain.service.CurrWorkerService;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RMapCache;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author 田平 create 2018年11月1日上午10:04:12
 */
@Slf4j
public class CurrWorkerServiceImpl implements CurrWorkerService {

	@Autowired
	private RedissonClient redisson;

	@Override
	public Worker getCurrWorker(String token) {
		RMapCache<String, String> tokenMap = null;
		Worker worker = null;
		if (token.startsWith(CommonConstants.SCOPE_WEB)) {
			tokenMap = redisson.getMapCache(RedisKeys.TOKEN_WEB_KEY);
		} else if (token.startsWith(CommonConstants.SCOPE_PHONE)) {
			tokenMap = redisson.getMapCache(RedisKeys.TOKEN_PHONE_KEY);
		}
		if (tokenMap != null) {
			String workJson = tokenMap.get(token);
			worker = JsonUtil.jsonToObject(workJson, Worker.class);
		}
		return worker;
	}

}
