loseUserDataTransfer.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using NPOI.HSSF.UserModel;
  7. using System.IO;
  8. using StackExchange.Redis;
  9. //using System.Threading;
  10. //using System.Data;
  11. using CSharpUtil;
  12. //using Newtonsoft.Json;
  13. //using Newtonsoft.Json.Linq;
  14. //using System.Diagnostics;
  15. namespace DataTransfer.tongji
  16. {
  17. class loseUserDataTransfer
  18. {
  19. public static void excelText(string memKey,int retain,int zoneid,float day)
  20. {
  21. //获取redis种的数据
  22. var mem = Redis.Ins.GetDatabase(0);
  23. HashEntry[] ctxList = mem.HashGetAll(memKey);
  24. int length = ctxList.Length;
  25. if (length <= 0)
  26. {
  27. return;
  28. }
  29. Dictionary<string, string> levelDic = new Dictionary<string, string>();
  30. Dictionary<string, string> taskDic = new Dictionary<string, string>();
  31. Dictionary<string, string> gateDic = new Dictionary<string, string>();
  32. foreach (var item in ctxList)
  33. {
  34. string[] sList = item.ToString().Split(':');
  35. string type = sList[0];
  36. string num = sList[1];
  37. string[] ctx = type.Split('-');
  38. string name = ctx[0];
  39. //string id = ctx[1];
  40. if (name == "level")
  41. {
  42. levelDic[type] = num;
  43. }
  44. else if (name == "task")
  45. {
  46. taskDic[type] = num;
  47. }
  48. else if (name == "gateId")
  49. {
  50. gateDic[type] = num;
  51. }
  52. }
  53. Dictionary<string,string> dic = levelDic.Union(taskDic).ToDictionary(k=>k.Key,v=>v.Value);
  54. Dictionary<string, string> newdic = dic.Union(gateDic).ToDictionary(k => k.Key, v => v.Value);
  55. HSSFWorkbook workbook = new HSSFWorkbook();
  56. //创建工作表
  57. var sheet = workbook.CreateSheet("信息表");
  58. var row = sheet.CreateRow(0);
  59. //创建单元格
  60. var cellid = row.CreateCell(0);
  61. cellid.SetCellValue("指标类型");
  62. var cellname = row.CreateCell(1);
  63. cellname.SetCellValue("指标id");
  64. var cellpwd = row.CreateCell(2);
  65. cellpwd.SetCellValue("指标累计值");
  66. int x = 1;
  67. foreach (KeyValuePair<string,string>kv in newdic)
  68. {
  69. string[] sList = kv.Key.Split('-');
  70. string name = sList[0];
  71. string id = sList[1];
  72. int num = int.Parse(kv.Value);
  73. var rowi = sheet.CreateRow(x);
  74. var cname = rowi.CreateCell(0);
  75. cname.SetCellValue(name);
  76. var cid = rowi.CreateCell(1);
  77. cid.SetCellValue(id);
  78. var cnum = rowi.CreateCell(2);
  79. cnum.SetCellValue(num);
  80. x += 1;
  81. }
  82. string txtName = "流失玩家指标累计信息表_" +"zone"+zoneid+"_"+retain+"lose_" + day;
  83. FileStream file = new FileStream(@"F:\excel\"+txtName+".xls", FileMode.CreateNew, FileAccess.Write);
  84. workbook.Write(file);
  85. file.Dispose();
  86. }
  87. }
  88. public class User
  89. {
  90. /// <summary>
  91. /// 索引
  92. /// </summary>
  93. public int Id { get; set; }
  94. public string Name { get; set; }
  95. public string pwd { get; set; }
  96. public string type { get; set; }
  97. }
  98. public class Model
  99. {
  100. /// <summary>
  101. /// 索引
  102. /// </summary>
  103. public int Id { get; set; }
  104. public string Name { get; set; }
  105. public int pwd { get; set; }
  106. public string type { get; set; }
  107. }
  108. }