package com.evt.mgr.handler;

import com.data.util.CountUtil;
import com.evt.mgr.IHandler;
import com.evt.mgr.Utils;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.ITObject;
import com.taurus.core.plugin.redis.Redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

public class HandlerGroupRound implements IHandler{

	@Override
	public int process(int uid,  ITObject param) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int processGroup(int groupId, ITObject param) throws Exception {
		int pid = param.getInt("pid");
		int valid = param.getInt("valid");
		ITArray playerList = param.getTArray("player_list");
		int valid_count = param.getInt("valid_count");
		int valid_diamo = 0;
		int all_count = 0;
		if (param.containsKey("valid_diamo"))
		{
			valid_diamo = param.getInt("valid_diamo");
		}

		if (param.containsKey("all_count"))
		{
			all_count = param.getInt("all_count");
		}
		
		String rp_key = String.format("g%s:round:p%s",groupId,pid);
		String round_key = String.format("g%s:round",groupId);
		
		Jedis jedis9 = Redis.use("group1_db9").getJedis();
		try {
			Pipeline pipeline9 = jedis9.pipelined();
			
			CountUtil.countLog(rp_key, 1, pipeline9,false,true);
			CountUtil.countLog(round_key, 1, pipeline9,true);
			
			if(valid == 1) {
				
				String valid_key = String.format("g%s:valid_room",groupId);
				String p_valid_key = String.format("g%s:valid_room:p%s",groupId,pid);
				CountUtil.countLogByDay(p_valid_key, 1, pipeline9,true);
				CountUtil.countLog(valid_key, 1, pipeline9);
			}else {
				
				String no_valid_key = String.format("g%s:no_valid_room",groupId);
				String p_no_valid_key = String.format("g%s:no_valid_room:p%s",groupId,pid);
				CountUtil.countLogByDay(p_no_valid_key, 1, pipeline9,true);
				CountUtil.countLog(no_valid_key, 1, pipeline9);
			}
			Utils.countValidAndTotal(pipeline9, playerList, groupId, pid, valid_count, valid_diamo, all_count);
			
			pipeline9.sync();
			
		}finally {
			jedis9.close();
		}
		return 0;
	}

}
