mmstranssearchtotalserviceimpl.java

来自「移动彩信管理平台」· Java 代码 · 共 616 行 · 第 1/2 页

JAVA
616
字号
			System.out.println(sql_firstNum);
			List firstNumList = jdbcTemplate.queryForList(sql_firstNum);
			List secondNumList = jdbcTemplate.queryForList(sql_secondNum);
			List thirdNumList = jdbcTemplate.queryForList(sql_thirdNum);
			int firstNum = 0;
			int secondNum = 0;
			int thirdNum = 0;
			if (firstNumList != null && firstNumList.size() > 0) {
				firstNum = Integer.parseInt(getStringFromListMap(firstNumList,
						0, "transmit_amount", "0"));
			}
			if (secondNumList != null && secondNumList.size() > 0) {
				secondNum = Integer.parseInt(getStringFromListMap(
						secondNumList, 0, "transmit_amount", "0"));
			}
			if (thirdNumList != null && thirdNumList.size() > 0) {
				thirdNum = Integer.parseInt(getStringFromListMap(thirdNumList,
						0, "transmit_amount", "0"));
			}

			// 组装页面显示用的数据列表
			int first = firstNum_p + firstNum;// 第一层转发量
			int second = secondNum_p + secondNum;// 第二层转发量
			int third = thirdNum_p + thirdNum;// 第三层转发量
			int total = first + second + third;// 总转发量

			// 栏目名称
			List lanmuList = daoSupport
					.find(
							"select t.sortName from TbMmsType t where t.sortId=?",
							objs);
			String lanmu = "";
			if (lanmuList.get(0) != null)
				lanmu = lanmuList.get(0).toString();
			// 页面栏目行数据封装
			HashMap<String, String> dataMap = new HashMap<String, String>();
			dataMap.put("lanmu", lanmu);
			dataMap.put("deadLine", deadLine);
			dataMap.put("total", new Integer(total).toString());
			dataMap.put("first", new Integer(first).toString());
			dataMap.put("second", new Integer(second).toString());
			dataMap.put("third", new Integer(third).toString());
			data.add(dataMap);
			// 页面总计行数据封装
			HashMap<String, String> totalMap = new HashMap<String, String>();
			totalMap.put("lanmu", "总计");
			totalMap.put("deadLine", "");
			totalMap.put("total", new Integer(total).toString());
			totalMap.put("first", new Integer(first).toString());
			totalMap.put("second", new Integer(second).toString());
			totalMap.put("third", new Integer(third).toString());
			data.add(totalMap);
		}
		return data;
	}

	// 获取cp相对应的栏目列表
	public List getTypeList(String userid, String user_group) {
		List<MmsSelectBean> typeList = new ArrayList<MmsSelectBean>();
		List list;
		// 登陆用户为局方
		if ("4".equals(user_group)) {
			// 取栏目对应的id,名称列表
			list = this.daoSupport
					.find("select t.sortId,t.sortName from TbMmsType t where t.sortDeep = '3' order by t.sortOrder");

		} else {
			// 登陆用户为cp
			Object[] objs = { userid };
			// 取这个cp对应的栏目id
			List typeIdList = this.daoSupportCp
					.find(
							"select p.typeIndex from TbMmsCpProvider p where p.UserId = ?",
							objs);
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < typeIdList.size(); i++) {
				sb.append(typeIdList.get(i).toString());
				if (i != typeIdList.size() - 1)
					sb.append(",");
			}
			// 取栏目对应的名称
			list = this.daoSupport
					.find("select t.sortId,t.sortName from TbMmsType t where t.sortIndex in ("
							+ sb.toString() + ")");

		}
		if ("4".equals(user_group)) {
			MmsSelectBean selectBean = new MmsSelectBean("all", "所有栏目");
			typeList.add(selectBean);
		}
		if (list != null) {
			for (int i = 0; i < list.size(); i++) {
				Object[] objs = (Object[]) list.get(i);
				String code = objs[0] != null ? objs[0].toString() : "";
				String name = objs[1] != null ? objs[1].toString() : "";
				MmsSelectBean selectBean = new MmsSelectBean(code, name);
				typeList.add(selectBean);
			}
		}
		return typeList;
	}

	// 生成报表
	private void createWorkbook(List list, OutputStream out) {
		WritableWorkbook wwb = null;
		try {
			wwb = Workbook.createWorkbook(out);
			WritableSheet ws = wwb.createSheet("转发量统计", 0);

			// 总计计数器
			int totalnum = 0;
			int firstnum = 0;
			int secondnum = 0;
			int thirdnum = 0;

			// 字段名
			Label lb_1 = new Label(0, 0, "栏目");
			ws.addCell(lb_1);
			Label lb_2 = new Label(1, 0, "截至日期");
			ws.addCell(lb_2);
			Label lb_3 = new Label(2, 0, "总转发量");
			ws.addCell(lb_3);
			Label lb_4 = new Label(3, 0, "首层转发量");
			ws.addCell(lb_4);
			Label lb_5 = new Label(4, 0, "二层转发量");
			ws.addCell(lb_5);
			Label lb_6 = new Label(5, 0, "三层转发量");
			ws.addCell(lb_6);

			// 明细数据
			for (int i = 0; i < list.size(); i++) {
				Map objs = (Map) list.get(i);
				if (objs == null)
					continue;
				// 栏目
				String lanmu = (String) objs.get("lanmu");
				Label lb_lanmu = new Label(0, i + 1, lanmu);
				ws.addCell(lb_lanmu);
				// 截止日期
				if (i!=list.size()) {
					String deadLine = (String) objs.get("deadLine");
					Label lb_deadLine = new Label(1, i + 1, deadLine);
					ws.addCell(lb_deadLine);
				}
				// 每个栏目总转发量
				String total = (String) objs.get("total");
				totalnum += Integer.parseInt(total);
				Label lb_total = new Label(2, i + 1, total);
				ws.addCell(lb_total);
				// 每个栏目总转发量
				String first = (String) objs.get("first");
				firstnum += Integer.parseInt(first);
				Label lb_first = new Label(3, i + 1, first);
				ws.addCell(lb_first);
				// 每个栏目第二层转发量
				String second = (String) objs.get("second");
				secondnum += Integer.parseInt(second);
				Label lb_second = new Label(4, i + 1, second);
				ws.addCell(lb_second);
				// 每个栏目第三层转发量
				String third = (String) objs.get("third");
				thirdnum += Integer.parseInt(third);
				Label lb_third = new Label(5, i + 1, third);
				ws.addCell(lb_third);
			}
			// 保存
			wwb.write();

		} catch (Exception e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		} finally {
			if (wwb != null) {
				try {
					// 关闭
					wwb.close();
				} catch (WriteException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				} catch (IOException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				}
			}
		}
	}

	public void setDaoSupportCp(DaoSupport daoSupportCp) {
		this.daoSupportCp = daoSupportCp;
	}

	/**
	 * 获取List<Object[]>结果集中指定行指定列的String型数据
	 * 
	 * @param list
	 * @param row
	 *            0表示第一行
	 * @param col
	 *            0表示第一列
	 * @return
	 */
	private String getStringFromListObjects(List list, int row, int col,
			String defaultValue) {
		String obj = null;
		if (list.size() > 0) {
			Object[] objs = (Object[]) list.get(row);
			if (objs[col] == null)
				obj = defaultValue;
			else
				obj = objs[col].toString();
		}
		return obj;
	}

	/**
	 * 获取List<Map>结果集中指定行指定列的String型数据
	 * 
	 * @param list
	 * @param row
	 *            0表示第一行
	 * @param col
	 * @return
	 */
	private String getStringFromListMap(List list, int row, String col,
			String defaultValue) {
		String obj = null;
		if (list.size() > 0) {
			Map objs = (Map) list.get(row);
			if (objs.get(col) == null) {
				obj = defaultValue;
			} else {
				obj = objs.get(col).toString();
			}
		}
		return obj;
	}

	class TransTotalRow {
		private String lanmu;

		private String date;

		private Integer firstnum;

		private Integer secondnum;

		private Integer thirdnum;

		public String getDate() {
			return date;
		}

		public void setDate(String time) {
			String deadLine = "";
			try {
				String[] date = time.split("-");
				deadLine = date[0] + "年" + date[1] + "月" + date[2] + "日";
			} catch (Exception e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
			this.date = deadLine;
		}

		public Integer getFirstnum() {
			return firstnum;
		}

		public void setFirstnum(int firstnum) {
			this.firstnum = firstnum;
		}

		public String getLanmu() {
			return lanmu;
		}

		public void setLanmu(String lanmu) {
			this.lanmu = lanmu;
		}

		public Integer getSecondnum() {
			return secondnum;
		}

		public void setSecondnum(int secondnum) {
			this.secondnum = secondnum;
		}

		public Integer getThirdnum() {
			return thirdnum;
		}

		public void setThirdnum(int thridnum) {
			this.thirdnum = thridnum;
		}

		public Integer getTotalnum() {
			if (firstnum == null)
				firstnum = 0;
			if (secondnum == null)
				secondnum = 0;
			if (thirdnum == null)
				thirdnum = 0;
			return firstnum + secondnum + thirdnum;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?