|
|
@ -22,10 +22,10 @@ import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
|
import com.epmet.constant.IssueConstant; |
|
|
|
import com.epmet.dto.form.VoteRedisFormDTO; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
@ -51,16 +51,43 @@ public class IssueVoteDetailRedis { |
|
|
|
} |
|
|
|
|
|
|
|
public VoteRedisFormDTO get(String issueId){ |
|
|
|
VoteRedisFormDTO voteRedis = new VoteRedisFormDTO(); |
|
|
|
String key = IssueConstant.REDIS_KEY + issueId; |
|
|
|
Map<String, Object> stringObjectMap = redisUtils.hGetAll(key); |
|
|
|
if (stringObjectMap.size()== NumConstant.ZERO || stringObjectMap == null){ |
|
|
|
return new VoteRedisFormDTO(); |
|
|
|
} |
|
|
|
voteRedis.setShouldVoteCount(Integer.valueOf(stringObjectMap.get("shouldVoteCount").toString())); |
|
|
|
voteRedis.setSupportAmount(Integer.valueOf(stringObjectMap.get("supportAmount").toString())); |
|
|
|
voteRedis.setOppositionAmount(Integer.valueOf(stringObjectMap.get("oppositionAmount").toString())); |
|
|
|
return voteRedis; |
|
|
|
VoteRedisFormDTO voteRedisFormDTO = mapToEntity(stringObjectMap, VoteRedisFormDTO.class); |
|
|
|
return voteRedisFormDTO; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description map 转 Entity |
|
|
|
* @param map |
|
|
|
* @param entity |
|
|
|
* @author zxc |
|
|
|
*/ |
|
|
|
public <T> T mapToEntity(Map<String, Object> map, Class<T> entity) { |
|
|
|
T t = null; |
|
|
|
try { |
|
|
|
t = entity.newInstance(); |
|
|
|
for(Field field : entity.getDeclaredFields()) { |
|
|
|
if (map.containsKey(field.getName())) { |
|
|
|
boolean flag = field.isAccessible(); |
|
|
|
field.setAccessible(true); |
|
|
|
Object object = map.get(field.getName()); |
|
|
|
if (object!= null && field.getType().isAssignableFrom(object.getClass())) { |
|
|
|
field.set(t, object); |
|
|
|
} |
|
|
|
field.setAccessible(flag); |
|
|
|
} |
|
|
|
} |
|
|
|
return t; |
|
|
|
} catch (InstantiationException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} catch (IllegalAccessException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return t; |
|
|
|
} |
|
|
|
|
|
|
|
} |