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";
}
*/
} }
}
05-07 15:56