1. package com.jr.market.tool;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileReader;
  7. import java.io.IOException;
  8. import java.io.InputStreamReader;
  9. import java.math.BigDecimal;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import java.util.Map;
  13.  
  14. import org.apache.activemq.console.Main;
  15. import org.apache.commons.io.FileUtils;
  16. import org.apache.commons.io.FilenameUtils;
  17.  
  18. import redis.clients.jedis.JedisPoolConfig;
  19. import redis.clients.jedis.JedisShardInfo;
  20. import redis.clients.jedis.ShardedJedisPool;
  21.  
  22. import ch.qos.logback.core.util.FileUtil;
  23.  
  24. import com.xiaomi.jr.market.constants.RpInvConstants;
  25. import com.xiaomi.jr.market.domain.RpReciveInput;
  26. import com.xiaomi.jr.market.gift.dto.FpSettleDetail;
  27. import com.xiaomi.jr.market.util.CacheKey;
  28. import com.xiaomi.jr.market.util.DateUtil;
  29. import com.xiaomi.jr.market.util.JsonExceptionUtil;
  30. import com.xiaomi.jr.market.util.QueuesCfg;
  31. import com.xiaomi.operation.platform.hogwarts.util.StringUtil;
  32. import com.xiaomi.operation.platform.tsg.base.core.utils.JsonUtil;
  33. import com.xiaomi.operation.platform.tsg.base.core.utils.ResponseVo;
  34.  
  35. public class RedisCacheTool {
  36.  
  37. /**
  38. * @param args
  39. * @throws IOException
  40. *
  41. *
  42. * xxxxxx 19000
  43. * xxxxxx 19102
  44. */
  45. public static boolean connect = false ;
  46. public static RedisClientImpl cl = null ;
  47.  
  48. public static void connect(String[] infos) {
  49. if(!connect) {
  50. String host = infos[1] ;
  51. String port = infos[2] ;
  52. int ports = -1;
  53. try{
  54. ports = Integer.parseInt(infos[2]);
  55. } catch (Exception e) {
  56. e.printStackTrace() ;
  57. return ;
  58. }
  59.  
  60. JedisPoolConfig config = new JedisPoolConfig();
  61. JedisShardInfo info = new JedisShardInfo(host,ports) ;
  62. List<JedisShardInfo> jedisInfo = new ArrayList<JedisShardInfo>() ;
  63. jedisInfo.add(info) ;
  64.  
  65. ShardedJedisPool pool = new ShardedJedisPool(config,jedisInfo) ;
  66. cl = new RedisClientImpl() ;
  67. cl.setJedisPool(pool) ;
  68. System.out.println("连接成功 [" + host +":" +ports+"]" ) ;
  69. connect = true ;
  70. }
  71. }
  72.  
  73. public static String[] initInvValue(int size) {
  74. String[] values = new String[size] ;
  75. for(int i =0 ; i<size ; i++)
  76. values[i] = "1" ;
  77. return values;
  78. }
  79.  
  80. public static void main1(String[] args) throws IOException {
  81. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  82. String str = null ;
  83. String[] infos= null;
  84.  
  85. while (StringUtil.isNotEmpty(str = reader.readLine())) {
  86. str = str.replaceAll("\\s+", " ").trim();
  87. infos = str.split(" ");
  88.  
  89. if (infos.length == 3 && "connect".equalsIgnoreCase(infos[0])) {
  90. connect(infos);
  91. continue ;
  92. }
  93. //MARKET#RPQUECFG#FZ_R1
  94. if (infos.length == 1 && "en".equalsIgnoreCase(infos[0])) {
  95. QueuesCfg cfg = cl.getCache("MARKET#RPQUECFG#FZ_R1", QueuesCfg.class);
  96. cfg.setUsed(true) ;
  97. cl.set("MARKET#RPQUECFG#FZ_R1", cfg) ;
  98. continue ;
  99. }
  100.  
  101. if (infos.length == 1 && "addinv".equalsIgnoreCase(infos[0])) {
  102. for(int i= 0; i< 900 ;i ++) {
  103. String[] rpValues = initInvValue(1500 );
  104. cl.lPush("MARKET#UQUE#FZ_R1", rpValues);
  105. }
  106. continue ;
  107. }
  108.  
  109. if (infos.length == 1 && "hget".equalsIgnoreCase(infos[0])) {
  110.  
  111. Map<String, String> maps = cl.getMap("MARKET#TYPE");
  112. for (String s : maps.keySet()) {
  113. System.out.println(maps.get(s));
  114. }
  115. }
  116. if (infos.length == 1 && "hset".equalsIgnoreCase(infos[0])) {
  117. /*
  118. * if(infos.length == 4 && "hset".equalsIgnoreCase(infos[0])){
  119. * //cl.setMap(infos[1], infos[2], infos[3]) ;
  120. * cl.setMap("MARKET#TYPE", "1", "新人专享") ;
  121. * cl.setMap("MARKET#TYPE", "2", "老带新") ;
  122. * cl.setMap("MARKET#TYPE", "3", "现金奖励") ;
  123. * cl.setMap("MARKET#TYPE", "4", "充值返现") ; }
  124. */
  125. cl.setMap("MARKET#TYPE", "7", "国庆双倍收益");
  126. continue;
  127. }
  128.  
  129. if (infos.length == 1 && "detail".equalsIgnoreCase(infos[0])) {
  130. BufferedReader b1 = new BufferedReader(new FileReader("c:\\hb.txt"));
  131. String c1 = null;
  132. while (StringUtil.isNotEmpty(c1 = b1.readLine())) {
  133. String[] params = c1.replaceAll("\\s+", " ").trim() .split(" ");
  134. modyfyDetail(params[0].trim(), params[1].trim());
  135. }
  136. }
  137.  
  138. if (/* infos.length == 3 && */"print".equalsIgnoreCase(infos[0])) {
  139. BufferedReader b = new BufferedReader(new FileReader(
  140. "c:\\hb.txt"));
  141. String c = null;
  142. String value = null;
  143. while (StringUtil.isNotEmpty(c = b.readLine())) {
  144. String rcdCntKey = CacheKey.RP_RECORD.getKey(new String[] {
  145. "NFL", c.trim() });
  146. int cnt = (int) cl.incre(rcdCntKey, 1);
  147. }
  148. }
  149.  
  150. }
  151. }
  152.  
  153. /**
  154. * "http://xxxxxx/gift/rechargetrigger" 充值
  155. * http://xxxxxx/gift/rpsettledetail 修改流水
  156. * 修改 流水
  157. * @param object
  158. * @param url
  159. * @param method
  160. */
  161. public static void rspCall(Object object, String url, String method ) {
  162. String params = JsonExceptionUtil.toJsonString(object);
  163. String returnStr = null;
  164. Object obj = null;
  165. ResponseVo responseVo = null;
  166. Object dto = null;
  167. try {
  168. returnStr = RestUtilTool.sendData(url, method, params, 2000, "add", "add");
  169. responseVo = JsonExceptionUtil.toBean(returnStr, ResponseVo.class);
  170. if (responseVo.isSuccess()) {
  171. obj = responseVo.getData();
  172. System.out.println(obj.toString()) ;
  173. }
  174. } catch (Exception e) {
  175. e.printStackTrace() ;
  176. }
  177. if (!responseVo.isSuccess()) {
  178. System.out.println(responseVo.toString()) ;
  179. }
  180. }
  181.  
  182. public static void modyfyDetail(String id,String accountNo ) {
  183. FpSettleDetail detail = new FpSettleDetail() ;
  184. detail.setId(Integer.valueOf(id)) ;
  185. detail.setAccountNo(accountNo);
  186. detail.setActiveCode("FZ");
  187. detail.setOverTime(DateUtil.parseDateTime("2015-11-15 00:00:00")) ;
  188. try {
  189. rspCall(detail, "http://xxxxxx/gift/rpsettledetail", "POST") ;
  190. } catch (Exception e) {
  191. System.out.println("id ==" + id) ;
  192. }
  193.  
  194. }
  195.  
  196. public static void test(String memberId ,BigDecimal amount) {
  197. try {
  198. RpReciveInput input = new RpReciveInput();
  199. input.setAccountNo(memberId) ;
  200. input.setMoney(amount) ;
  201. input.setDetailId("-1") ;
  202. String params = JsonUtil.toString(input);
  203. //Base64Util
  204. // queryForFinInfo(input);
  205. } catch (Exception e) {
  206. e.printStackTrace() ;
  207. }
  208. }
  209.  
  210. public static String[] readTxtFile(String filePath){
  211. StringBuilder sb = new StringBuilder();
  212. try {
  213. String encoding="UTF-8";
  214. File file=new File(filePath);
  215. if(file.isFile() && file.exists()){ //判断文件是否存在
  216. InputStreamReader read = new InputStreamReader(
  217. new FileInputStream(file),encoding);//考虑到编码格式
  218. BufferedReader bufferedReader = new BufferedReader(read);
  219. String lineTxt = null;
  220. while((lineTxt = bufferedReader.readLine()) != null){
  221. //System.out.println(lineTxt);
  222. sb.append(lineTxt).append(";");
  223. }
  224. read.close();
  225. }else{
  226. System.out.println("找不到指定的文件");
  227. }
  228. } catch (Exception e) {
  229. System.out.println("读取文件内容出错");
  230. e.printStackTrace();
  231. }
  232. return sb.toString().split(";");
  233. }
  234.  
  235. public static void mainXX(String[] args) throws IOException {
  236. String filePath = "C:\\Users\\fanghui\\Desktop\\DATA.txt";
  237. String[] s= readTxtFile(filePath);
  238. String sql = "";
  239. StringBuilder sb = new StringBuilder();
  240. int count = 0;
  241. for(String str : s){
  242. String[] subStr = str.trim().split("\t");
  243. String add_time = subStr[0];
  244. String member_id = subStr[1];
  245. String partner_id = subStr[2];
  246. String order_id = subStr[3];
  247. String trade_type = subStr[4];
  248. double trade_money = new BigDecimal(subStr[5]).doubleValue();
  249. String status = subStr[6];
  250. sql = "insert into `t_settle_recharge` ( `add_time`, `member_id`, `partner_id`, `order_id`, `trade_type`, `trade_money`, `status`) " +
  251. "values('"+add_time+"','"+member_id+"','"+partner_id+"','"+order_id+"','"+trade_type+"',"+trade_money+",'"+status+"');";
  252. //System.out.println(sql);
  253. sb.append(sql).append("\r\n");
  254. /*count++;
  255. if(count>200)
  256. return;*/
  257. }
  258. FileUtils.write(new File("C:\\Users\\fanghui\\Desktop\\bigsql.sql"), sb.toString());
  259. }
  260.  
  261. public static void main(String[] args) throws IOException {
  262. setNetValueCache();
  263. }
  264. public static void setNetValueCache(){
  265. String filePath = "C:\\Users\\fanghui\\Desktop\\c1.txt";
  266. String[] s= readTxtFile(filePath);
  267. String sql = "";
  268. StringBuilder sb = new StringBuilder();
  269. for(String str : s){
  270. String[] subStr = str.trim().split(",");
  271. String member_id = subStr[0];
  272. String inputMoney = subStr[1];
  273. String totalAward = subStr[2];
  274.  
  275. //根据该发总奖金反推此用户的总净值
  276. BigDecimal totalMoney = new BigDecimal(totalAward).divide(new BigDecimal(9)).multiply(new BigDecimal(5000));
  277. String nvKey = CacheKey.RP_NET_WORTH.getKey(new String[]{"JZN",member_id}) ; //ex: MARKET#NETWORTH##JZN#6700336
  278. //cl.setMap(nvKey, "field_netValueMoney", totalMoney.toString());//净值
  279. //cl.setMap(nvKey, "field_ownAwardMoney", totalAward);//总共已领取金额
  280. System.out.println(member_id+", jinzhi: "+totalMoney.toString()+" ,总共已领取金额 : "+totalAward);
  281.  
  282. /*String netValueMoney = (String) cl.getMapValue(nvKey, "field_netValueMoney");//从缓存中取用户已有净值
  283. String ownAwardMoney = (String) cl.getMapValue(nvKey, "field_ownAwardMoney");//从缓存中取用户已领取金额
  284. if(netValueMoney==null){ //缓存中无净值时,可认为是用户首次访问系统[如果缓存系统挂了,应该执行后门程序去查库更新缓存值]
  285. cl.setMap(nvKey, "field_netValueMoney", "0");//净值
  286. netValueMoney = "0";
  287. }
  288.  
  289. if(ownAwardMoney == null ){
  290. cl.setMap(nvKey, "field_ownAwardMoney", "0");//总共已领取金额
  291. ownAwardMoney = "0";
  292. }
  293. */
  294. }
  295.  
  296. }
  297. }

RedisCacheTool参考其中的文件读写功能的更多相关文章

  1. JS封装插件:实现文件读写功能

    scripting.FileSystemObject是一个可以实现文件读写的COM组件,由于COM组件可以被跨语言调用,因此可以选择像vbs或者JS这种脚本语言调用,下面我就使用该COM组件封装了一个 ...

  2. [js高手之路]node js系列课程-创建简易web服务器与文件读写

    web服务器至少有以下几个特点: 1.24小时不停止的工作,也就是说这个进程要常驻在内存中 2.24小时在某一端口监听,如: http://localhost:8080, www服务器默认端口80 3 ...

  3. java byte【】数组与文件读写(增加新功能)

    今天在测试直接写的文章: java byte[]数组与文件读写 时,想调用FileHelper类对字节数组以追加的方式写文件,结果无论怎样竟然数据录入不全,重新看了下文件的追加模式,提供了两种方式: ...

  4. [转]Android - 文件读写操作 总结

     转自:http://blog.csdn.net/ztp800201/article/details/7322110 Android - 文件读写操作 总结 分类: Android2012-03-05 ...

  5. Python之文件读写

    本节内容: I/O操作概述 文件读写实现原理与操作步骤 文件打开模式 Python文件操作步骤示例 Python文件读取相关方法 文件读写与字符编码 一.I/O操作概述 I/O在计算机中是指Input ...

  6. 通过文件读写方式实现Matlab和Modelsim的联合仿真

    虽然Modelsim的功能非常强大,仿真的波形可以以多种形式进行显示,但是当涉及到数字信号处理的算法的仿真验证的时候,则显得有点不足.而进行数字信号处理是Matlab的强项,不但有大量的关于数字信号处 ...

  7. python之文件读写详解

    打开文件 函数open() 参数说明: file:文件路径 mode: 文件的读写方式,默认'r',只读方式: buffering:设置缓冲策略,0用于二进制文件,1为行缓冲,用于文本模式:默认二进制 ...

  8. C#使用FileSystemWatcher控件实现的文件监控功能示例

    本文实例讲述了C#使用FileSystemWatcher控件实现的文件监控功能.分享给大家供大家参考,具体如下: FileSystemWatcher 可以使用FileSystemWatcher组件监视 ...

  9. python的文件读写笔记

    读写文件是最常见的IO操作.Python内置了读写文件的函数,用法和C是兼容的. 读写文件前,我们先必须了解一下,在磁盘上读写文件的功能都是由操作系统提供的,现代操作系统不允许普通的程序直接操作磁盘, ...

随机推荐

  1. 【转】Android使用Log4j例子

    Step 1 Download Log4J library from http://logging.apache.org/log4j/1.2/download.html Step 2 Configur ...

  2. 笨小猴 2008年NOIP全国联赛提高组

    题目描述 Description 笨小猴的词汇量很小,所以每次做英语选择题的时候都很头疼.但是他找到了一种方法,经试验证明,用这种方法去选择选项的时候选对的几率非常大! 这种方法的具体描述如下:假设m ...

  3. POJ3352 Road Construction(边双连通分量)

                                                                                                         ...

  4. bzoj 1061 志愿者招募(最小费用最大流)

    [Noi2008]志愿者招募 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 3792  Solved: 2314[Submit][Status][Di ...

  5. phpwind数据同步本地之后板块排版乱

    排版紊乱的问题一般是css文件的问题 解决思路 1.打开chrome调用F12,查看是不是css文件没有获取. 2.如果没有获取到的话检查css文件的路径. 在本例中phpwind数据同步到本地之后, ...

  6. 升级win10的理由

    微软也没给我钱,我免费给它打了次广告. 我还是非常喜欢linux的,无奈公司深度依赖windows. 废话不多说,直接进入主题: [开机速度] 这里先说句题外话,不那么缺钱的兄弟,一定要去换一块SSD ...

  7. linux下crontab定时执行本地脚本和定时访问指定url

    https://my.oschina.net/u/2487410/blog/683308 使用linux curl命令讲解:http://www.linuxdiyf.com/linux/2800.ht ...

  8. dom4j测试

    book.xml <?xml version="1.0" encoding="UTF-8"?><books><book>&l ...

  9. dump java

    http://www.gamlor.info/wordpress/2011/09/visualvm/ https://visualvm.java.net/zh_CN/gettingstarted.ht ...

  10. Java 实现学生信息管理系统

    编写一个简单的学生管理信息系统. 在oracle中设计一张学生表,以学号作为关键字. 其他学生信息有:姓名.手机号. 在进入系统时,显示如下菜单: ************************** ...