package com.jr.market.tool;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import org.apache.activemq.console.Main;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils; import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedisPool; import ch.qos.logback.core.util.FileUtil; import com.xiaomi.jr.market.constants.RpInvConstants;
import com.xiaomi.jr.market.domain.RpReciveInput;
import com.xiaomi.jr.market.gift.dto.FpSettleDetail;
import com.xiaomi.jr.market.util.CacheKey;
import com.xiaomi.jr.market.util.DateUtil;
import com.xiaomi.jr.market.util.JsonExceptionUtil;
import com.xiaomi.jr.market.util.QueuesCfg;
import com.xiaomi.operation.platform.hogwarts.util.StringUtil;
import com.xiaomi.operation.platform.tsg.base.core.utils.JsonUtil;
import com.xiaomi.operation.platform.tsg.base.core.utils.ResponseVo; public class RedisCacheTool { /**
* @param args
* @throws IOException
*
*
* xxxxxx 19000
* xxxxxx 19102
*/
public static boolean connect = false ;
public static RedisClientImpl cl = null ; public static void connect(String[] infos) {
if(!connect) {
String host = infos[1] ;
String port = infos[2] ;
int ports = -1;
try{
ports = Integer.parseInt(infos[2]);
} catch (Exception e) {
e.printStackTrace() ;
return ;
} JedisPoolConfig config = new JedisPoolConfig();
JedisShardInfo info = new JedisShardInfo(host,ports) ;
List<JedisShardInfo> jedisInfo = new ArrayList<JedisShardInfo>() ;
jedisInfo.add(info) ; ShardedJedisPool pool = new ShardedJedisPool(config,jedisInfo) ;
cl = new RedisClientImpl() ;
cl.setJedisPool(pool) ;
System.out.println("连接成功 [" + host +":" +ports+"]" ) ;
connect = true ;
}
} public static String[] initInvValue(int size) {
String[] values = new String[size] ;
for(int i =0 ; i<size ; i++)
values[i] = "1" ;
return values;
} public static void main1(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String str = null ;
String[] infos= null; while (StringUtil.isNotEmpty(str = reader.readLine())) {
str = str.replaceAll("\\s+", " ").trim();
infos = str.split(" "); if (infos.length == 3 && "connect".equalsIgnoreCase(infos[0])) {
connect(infos);
continue ;
}
//MARKET#RPQUECFG#FZ_R1
if (infos.length == 1 && "en".equalsIgnoreCase(infos[0])) {
QueuesCfg cfg = cl.getCache("MARKET#RPQUECFG#FZ_R1", QueuesCfg.class);
cfg.setUsed(true) ;
cl.set("MARKET#RPQUECFG#FZ_R1", cfg) ;
continue ;
} if (infos.length == 1 && "addinv".equalsIgnoreCase(infos[0])) {
for(int i= 0; i< 900 ;i ++) {
String[] rpValues = initInvValue(1500 );
cl.lPush("MARKET#UQUE#FZ_R1", rpValues);
}
continue ;
} if (infos.length == 1 && "hget".equalsIgnoreCase(infos[0])) { Map<String, String> maps = cl.getMap("MARKET#TYPE");
for (String s : maps.keySet()) {
System.out.println(maps.get(s));
}
}
if (infos.length == 1 && "hset".equalsIgnoreCase(infos[0])) {
/*
* if(infos.length == 4 && "hset".equalsIgnoreCase(infos[0])){
* //cl.setMap(infos[1], infos[2], infos[3]) ;
* cl.setMap("MARKET#TYPE", "1", "新人专享") ;
* cl.setMap("MARKET#TYPE", "2", "老带新") ;
* cl.setMap("MARKET#TYPE", "3", "现金奖励") ;
* cl.setMap("MARKET#TYPE", "4", "充值返现") ; }
*/
cl.setMap("MARKET#TYPE", "7", "国庆双倍收益");
continue;
} if (infos.length == 1 && "detail".equalsIgnoreCase(infos[0])) {
BufferedReader b1 = new BufferedReader(new FileReader("c:\\hb.txt"));
String c1 = null;
while (StringUtil.isNotEmpty(c1 = b1.readLine())) {
String[] params = c1.replaceAll("\\s+", " ").trim() .split(" ");
modyfyDetail(params[0].trim(), params[1].trim());
}
} if (/* infos.length == 3 && */"print".equalsIgnoreCase(infos[0])) {
BufferedReader b = new BufferedReader(new FileReader(
"c:\\hb.txt"));
String c = null;
String value = null;
while (StringUtil.isNotEmpty(c = b.readLine())) {
String rcdCntKey = CacheKey.RP_RECORD.getKey(new String[] {
"NFL", c.trim() });
int cnt = (int) cl.incre(rcdCntKey, 1);
}
} }
} /**
* "http://xxxxxx/gift/rechargetrigger" 充值
* http://xxxxxx/gift/rpsettledetail 修改流水
* 修改 流水
* @param object
* @param url
* @param method
*/
public static void rspCall(Object object, String url, String method ) {
String params = JsonExceptionUtil.toJsonString(object);
String returnStr = null;
Object obj = null;
ResponseVo responseVo = null;
Object dto = null;
try {
returnStr = RestUtilTool.sendData(url, method, params, 2000, "add", "add");
responseVo = JsonExceptionUtil.toBean(returnStr, ResponseVo.class);
if (responseVo.isSuccess()) {
obj = responseVo.getData();
System.out.println(obj.toString()) ;
}
} catch (Exception e) {
e.printStackTrace() ;
}
if (!responseVo.isSuccess()) {
System.out.println(responseVo.toString()) ;
}
} public static void modyfyDetail(String id,String accountNo ) {
FpSettleDetail detail = new FpSettleDetail() ;
detail.setId(Integer.valueOf(id)) ;
detail.setAccountNo(accountNo);
detail.setActiveCode("FZ");
detail.setOverTime(DateUtil.parseDateTime("2015-11-15 00:00:00")) ;
try {
rspCall(detail, "http://xxxxxx/gift/rpsettledetail", "POST") ;
} catch (Exception e) {
System.out.println("id ==" + id) ;
} } public static void test(String memberId ,BigDecimal amount) {
try {
RpReciveInput input = new RpReciveInput();
input.setAccountNo(memberId) ;
input.setMoney(amount) ;
input.setDetailId("-1") ;
String params = JsonUtil.toString(input);
//Base64Util
// queryForFinInfo(input);
} catch (Exception e) {
e.printStackTrace() ;
}
} public static String[] readTxtFile(String filePath){
StringBuilder sb = new StringBuilder();
try {
String encoding="UTF-8";
File file=new File(filePath);
if(file.isFile() && file.exists()){ //判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file),encoding);//考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while((lineTxt = bufferedReader.readLine()) != null){
//System.out.println(lineTxt);
sb.append(lineTxt).append(";");
}
read.close();
}else{
System.out.println("找不到指定的文件");
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}
return sb.toString().split(";");
} public static void mainXX(String[] args) throws IOException {
String filePath = "C:\\Users\\fanghui\\Desktop\\DATA.txt";
String[] s= readTxtFile(filePath);
String sql = "";
StringBuilder sb = new StringBuilder();
int count = 0;
for(String str : s){
String[] subStr = str.trim().split("\t");
String add_time = subStr[0];
String member_id = subStr[1];
String partner_id = subStr[2];
String order_id = subStr[3];
String trade_type = subStr[4];
double trade_money = new BigDecimal(subStr[5]).doubleValue();
String status = subStr[6];
sql = "insert into `t_settle_recharge` ( `add_time`, `member_id`, `partner_id`, `order_id`, `trade_type`, `trade_money`, `status`) " +
"values('"+add_time+"','"+member_id+"','"+partner_id+"','"+order_id+"','"+trade_type+"',"+trade_money+",'"+status+"');";
//System.out.println(sql);
sb.append(sql).append("\r\n");
/*count++;
if(count>200)
return;*/
}
FileUtils.write(new File("C:\\Users\\fanghui\\Desktop\\bigsql.sql"), sb.toString());
} public static void main(String[] args) throws IOException {
setNetValueCache();
}
public static void setNetValueCache(){
String filePath = "C:\\Users\\fanghui\\Desktop\\c1.txt";
String[] s= readTxtFile(filePath);
String sql = "";
StringBuilder sb = new StringBuilder();
for(String str : s){
String[] subStr = str.trim().split(",");
String member_id = subStr[0];
String inputMoney = subStr[1];
String totalAward = subStr[2]; //根据该发总奖金反推此用户的总净值
BigDecimal totalMoney = new BigDecimal(totalAward).divide(new BigDecimal(9)).multiply(new BigDecimal(5000));
String nvKey = CacheKey.RP_NET_WORTH.getKey(new String[]{"JZN",member_id}) ; //ex: MARKET#NETWORTH##JZN#6700336
//cl.setMap(nvKey, "field_netValueMoney", totalMoney.toString());//净值
//cl.setMap(nvKey, "field_ownAwardMoney", totalAward);//总共已领取金额
System.out.println(member_id+", jinzhi: "+totalMoney.toString()+" ,总共已领取金额 : "+totalAward); /*String netValueMoney = (String) cl.getMapValue(nvKey, "field_netValueMoney");//从缓存中取用户已有净值
String ownAwardMoney = (String) cl.getMapValue(nvKey, "field_ownAwardMoney");//从缓存中取用户已领取金额
if(netValueMoney==null){ //缓存中无净值时,可认为是用户首次访问系统[如果缓存系统挂了,应该执行后门程序去查库更新缓存值]
cl.setMap(nvKey, "field_netValueMoney", "0");//净值
netValueMoney = "0";
} if(ownAwardMoney == null ){
cl.setMap(nvKey, "field_ownAwardMoney", "0");//总共已领取金额
ownAwardMoney = "0";
}
*/
} }
}

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. 数据处理项目Beta阶段软件架构建议

    class:Dataserver string serverIP string serverPassword string sqlAccount string sqlPassword bool Dat ...

  2. Dwarves (有向图判环)

    Dwarves 时间限制: 1 Sec  内存限制: 64 MB提交: 14  解决: 4[提交][状态][讨论版] 题目描述 Once upon a time, there arose a huge ...

  3. mysql优化参数thread_cache_size

    thread_cache_size功能在mysql数据库配置文件中是非常重要的一项功能了,如果对thread_cache_size优化做得好我们可以让服务器跑得非常快,设置不好就会发现很小访问量就非常 ...

  4. 状态压缩dp 入门

    1.有一张n*m (n<=m)的棋盘,在上面放n个中国象棋里的车,使得任意两个车不能相互攻击,总共有多少种不同的方案. 2.有一张n*m (n<=m)的棋盘,其中有些格子里面不能放,在上面 ...

  5. 《苹果开发之Cocoa编程》挑战1 创建委托 练习

    <苹果开发之Cocoa编程>第4版 P87 新建一个单窗口应用程序,设置某对象为窗口的委托,当用户调整窗口尺寸时,确保窗口高度为宽度的2倍. 需要实现的委托方法为:-(NSSize)win ...

  6. 安装了iis之后,打开默认网站http://localhost/要求输入用户名和密码解决办法

        开始-运行gpedit.msc回车.     计算机配置--管理模板-windows 组件-Internet Exporer-Internet控制面板-安全页-Internet区域:双击登陆选 ...

  7. java的nio之:浅析I/O模型

    也许很多朋友在学习NIO的时候都会感觉有点吃力,对里面的很多概念都感觉不是那么明朗.在 进入Java NIO编程之前,我们今天先来讨论一些比较基础的知识:I/O模型.下面本文先从同步和异步的概念 说起 ...

  8. Python 基础语法(四)

    Python 基础语法(四) --------------------------------------------接 Python 基础语法(三)------------------------- ...

  9. phpstorm编辑器智能提示框架代码

    按照上面的步骤就可以智能提示代码了!

  10. HTTP头详解

    HTTP 头部解释 1. Accept:告诉WEB服务器自己接受什么介质类型,*/* 表示任何类型,type/* 表示该类型下的所有子类型,type/sub-type. 2. Accept-Chars ...