ChannelAppWarnTest.java 9 KB
Newer Older
zhangxiaoyan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
package com.cy.report.test;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.cy.report.pojo.AppInfo;
import com.cy.report.pojo.ChannelInfo;
import com.cy.report.pojo.ChannelUser;
import com.cy.report.pojo.WarnInfo;
import com.cy.report.pojo.WarnedInfo;
import com.cy.report.service.ServiceFactory;
import com.cy.report.utils.ChannelUserPassGenerator;
import com.cy.report.utils.Constant;
import com.cy.report.utils.PhoenixUtil;

public class ChannelAppWarnTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		List<WarnInfo> list = getWarninfoListSize();
		for (WarnInfo warn : list) {
			//System.out.println(warn.getReporttoscan());
		}
//		//System.out.println(getWarnedListDataBase());

	}
	
	private static List<WarnInfo> getWarninfoListSize() {
		return ServiceFactory.getWarnManageService().getAllWarnList();
	}
	
	private static int getWarnedNoScan() {
		return ServiceFactory.getWarnManageService().getWarnListCountNoScan("1001");
	}
	
//	public static String getWarnedListDataBase() {
//		List<WarnedInfo> warnedlist = ServiceFactory.getWarnManageService().getPageWarnedListByApp("1001");
//		return String.valueOf(warnedlist.size());
//	}
	
	
	private static String getWarnList() {
		WarnInfo warn = new WarnInfo();
		warn.setName("name");
		warn.setAppkey("1001");
		warn.setTime("每日8时");
		warn.setReporttoscan("活跃用户");
		warn.setKpi("增量");
		warn.setOperator("大于");
		warn.setValue("8");
		warn.setEmails("tst@163.com");
		warn.setPhones("18810405411");
		warn.setContacts(warn.getEmails()+" "+warn.getPhones());
		warn.setNumberstr("1,2,3,0");
		warn.setStatus("1");
		warn.setIsexist("1");
		warn.setChannelorevent("");
		StringBuffer sb = new StringBuffer();
		sb.append(warn.getTime()).append(warn.getReporttoscan())
		.append(Constant.WARNCOMPARE).append(warn.getKpi())
		.append(warn.getOperator()).append(warn.getValue());
		warn.setDescription(sb.toString());
		List<WarnInfo> warnList = new ArrayList<WarnInfo>();
		warnList.add(warn);
		String jsonStr = JSONArray.fromObject(warnList).toString();
		return jsonStr;
	}
	
	private static String getWarnedList() {
		WarnedInfo warned = new WarnedInfo();
		warned.setWarnname("name");
		
		warned.setValue("10");
		WarnInfo warn = new WarnInfo();
		warn.setName("name");
		warn.setAppkey("1001");
		warn.setTime("每日8时");
		warn.setReporttoscan("活跃用户");
		warn.setKpi("增量");
		warn.setOperator("大于");
		warn.setValue("8");
		warn.setNumberstr("1,2,3,0");
		warn.setEmails("tst@163.com");
		warn.setPhones("18810405411");
		warn.setStatus("1");
		warn.setIsexist("1");
		warn.setChannelorevent("");
		warned.setContacts(warn.getEmails()+" "+warn.getPhones());
		StringBuffer sb = new StringBuffer();
		sb.append(warn.getTime()).append(warn.getReporttoscan())
		.append(Constant.WARNCOMPARE).append(warn.getKpi())
		.append(Constant.IS).append(warned.getValue())
		.append(",").append(warn.getOperator())
		.append(warn.getValue());
		warned.setDescription(sb.toString());
		Date date = new Date();
		warned.setDatetime(date.toString());
		List<WarnedInfo> warnedList = new ArrayList<WarnedInfo>();
		warnedList.add(warned);
		String jsonStr = JSONArray.fromObject(warnedList).toString();
		return jsonStr;
		
	}
	
	private static String insertChannel() {
		String appid = "1001";
		String dev_id = "1";
		String tracetype = "1";
		String os = "0";
		String name = "66872e66ea1949fcb752d2f251c25915";
		String downloadurl = ".........";
		String appkey = appid;
		String channelkey = "66872e66ea1949fcb752d2f251c25915";
		//channel中已创建用户的状态默认为"0"
		String userstatus = "0";
		
//		if (tracetype.equals("0")) {
//			name = request.getParameter("name");
//			downloadurl = request.getParameter("downloadurl");
//		} else {
//			channelkey = ChannelKeyGenerator.getUUID();
//			name = channelkey;
//		}
		int id = ServiceFactory.getChannelManageService().insertChannel(name, tracetype, os, channelkey, downloadurl, appkey, dev_id, userstatus, 0,0);
		String jsonStr = "{\"channelid\":"+id+"}";
		return jsonStr;
	}
	
	private static String updateChannelNameById() {
		int id = 1;
		String name = "channeltestalter";
		id = ServiceFactory.getChannelManageService().updateChannelNameById(name, id);
		String jsonStr = "{\"channelid\":"+id+"}";
		return jsonStr;
	}
	
	private static String getChannelUserInfo() {
		int id = 1;
		ChannelInfo c = ServiceFactory.getChannelManageService().getChannelInfoById(id);
		String channelname = c.getName();
		String tracetype = c.getTracetype();
		String channelkey = c.getChannelkey();
		int cid = ServiceFactory.getChannelManageService().getChannelUserMaxId() + 1;
		String username = ChannelUserPassGenerator.getLoginName(cid);
		String password = ChannelUserPassGenerator.getPassword();
		String jsonStr = "{\"id\":\"" + id + "\",\"channelname\":\"" + channelname
		+ "\",\"channelkey\":\"" + channelkey + "\",\"tracetype\":\"" + tracetype
		+ "\",\"username\":\"" + username + "\",\"password\":\"" + password + "\"}";
		return jsonStr;
	}
	
	private static String insertChannelUser() {
		String appkey = "1001";
		String dev_id = "1";
		String json = "{\"id\":\"1\",\"channelname\":\"channeltestalter\",\"channelkey\":\"\",\"tracetype\":\"0\",\"username\":\"CY000003\",\"password\":\"981756\"}";
		JSONObject obj = JSONObject.fromObject(json);
		ChannelUser cuser = new ChannelUser();
		cuser.setAppkey(appkey);
		cuser.setChannelid(obj.getString("id"));
		cuser.setChannelkey(obj.getString("channelkey"));
		cuser.setChannelname(obj.getString("channelname"));
		cuser.setDev_id(dev_id);
		cuser.setPassword(obj.getString("password"));
		cuser.setTracetype(obj.getString("tracetype"));
		cuser.setUsername(obj.getString("username"));
		int id = ServiceFactory.getChannelManageService().insertChannelUser(cuser);
		//修改channel中已创建用户的状态为"1"
		ServiceFactory.getChannelManageService().updateChannelUserStatusById("1", obj.getInt("id"));
		String jsonStr = "{\"channeluserid\":"+id+"}";
		return jsonStr;
	}

	private static String updateAppDownloadUrl() {
		String appid = "1001";
		String appDownloadUrl = "http://test1";
		AppInfo app = new AppInfo();
		app.setAppkey(appid);
		app.setDownloadurl(appDownloadUrl);
		int id = ServiceFactory.getAppInfoService().updateAppUrlByKey(app);
		String jsonStr = "{\"result\":"+id+"}";
		return jsonStr;
	}
	
	private static String getMyApps() {
			int userid = 1;
			List<AppInfo> appList = ServiceFactory.getAppInfoService().getAppList(String.valueOf(userid));
		StringBuffer sb = new StringBuffer();
		for (AppInfo app : appList) {
			sb.append("'").append(app.getAppkey()).append("',");
		}
		String condition = sb.toString();
		if (condition.contains(",")) {
			condition = condition.substring(0, condition.length()-1);
		}
		String sql1 = "select appid, sum(val) as reged from NEWACCOUNT_BASE where appid in ("+condition+") group by appid";
		String sql2 = "select appid, sum(val) as dau from DAU_BASE where appid in ("+condition+") group by appid";
		String sql3 = "select appid, sum(totaltimes) as times from gametime_base where appid in ("+condition+") group by appid";
		String sql4 = "select appid, sum(amount) as amount from payment_base where appid in ("+condition+") group by appid";
		//System.out.println(sql1);
		//System.out.println(sql2);
		//System.out.println(sql3);
		//System.out.println(sql4);
		Map<String, Integer> regedmap = new HashMap<String, Integer>();
		Map<String, Integer> daumap = new HashMap<String, Integer>();
		Map<String, Integer> timesmap = new HashMap<String, Integer>();
		Map<String, Integer> amountmap = new HashMap<String, Integer>();
		try {
			ResultSet rs1 = PhoenixUtil.executeQuery(sql1);
			while (rs1.next()) {
				regedmap.put(rs1.getString("appid"), rs1.getInt("reged"));
			}
			ResultSet rs2 = PhoenixUtil.executeQuery(sql2);
			while (rs2.next()) {
				daumap.put(rs2.getString("appid"), rs2.getInt("dau"));
			}
			ResultSet rs3 = PhoenixUtil.executeQuery(sql3);
			while (rs3.next()) {
				timesmap.put(rs3.getString("appid"), rs3.getInt("times"));
			}
			ResultSet rs4 = PhoenixUtil.executeQuery(sql4);
			while (rs4.next()) {
				amountmap.put(rs4.getString("appid"), rs4.getInt("amount"));
			}
			// appList.add(app);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		for (AppInfo app : appList) {
			if (regedmap.containsKey(app.getAppkey())) {
				app.setDeviceactive(regedmap.get(app.getAppkey()));
			} else {
				app.setDeviceactive(0);
			}
			if (daumap.containsKey(app.getAppkey())) {
				app.setUser(daumap.get(app.getAppkey()));
			} else {
				app.setUser(0);
			}
			if (timesmap.containsKey(app.getAppkey())) {
//				app.setTimes(timesmap.get(app.getAppkey()));
			} else {
//				app.setTimes(0);
			}
			if (amountmap.containsKey(app.getAppkey())) {
				app.setIncome(amountmap.get(app.getAppkey()));
			} else {
				app.setIncome(0);
			}
		}
		String jsonStr = JSONArray.fromObject(appList).toString();
		return jsonStr;
	}
}