按一定条数写入拼接文件
来源:互联网 发布:好玩的战争游戏知乎 编辑:程序博客网 时间:2024/06/06 10:41
@RequestMapping(value = "/scfile")
@ResponseBody
public String ScPkeyFile(String sj) throws Exception {
int sjlen =sj.length();
String syear="";
String smonth="";
String sday="";
if(sjlen==8){
syear=sj.substring(0, 4);
smonth=sj.substring(4, 6);
sday=sj.substring(6, 8);
}
List<SystemInfo> systemInfoslist =is.getSystemInfoList(tJdbcTemplate);
SystemInfo systemInfo=systemInfoslist.get(0);
Integer Province_id= systemInfo.getProvince_id();
String provinceidString=String.valueOf(Province_id);
logger.info("省份id为:"+Province_id);
if("1".equals(sj)){
String allfile ="allKeyAndRemark";
String allPublicKeyFilePath = FilePath.getTmnClpKeyFilePath(allfile, publickeyfile);
String allZhaiyaoFilePath = FilePath.getTmnClpKeyFilePath(allfile, zhaiyaofile);
int a=FileUtil.deleteFile(allPublicKeyFilePath);
int b=FileUtil.deleteFile(allZhaiyaoFilePath);
int tms =itck.getAllTnmClpKeyCount(termJdbcTemplate);
logger.info("=============================tms:"+tms);
String countkey="";
String bwcountkey="";
if(tms!=0){
countkey=String.valueOf(tms);
int len=countkey.length();
if(len<6){
int n0=6-len;
bwcountkey=String.format("%1$0"+(6-countkey.length())+"d",0)+countkey;
logger.info("bwcountkey:"+bwcountkey);
}
}else{
return "There is no data for the current time";
}
StringBuilder strBuf = new StringBuilder();
String bwcountkeyjfh =bwcountkey+";";
strBuf.append(bwcountkeyjfh);
int numcs=0;
int x=0;
int y=0;
String timefile ="allKeyAndRemark";
String result ="";
String publicKeyFilePath = FilePath.getTmnClpKeyFilePath(timefile, publickeyfile);
List<TmnClpKey> tckList =itck.getTmnClpkeyList(termJdbcTemplate);
for (int i = 0; i < tckList.size(); i++) {
String terminalidString=String.valueOf(tckList.get(i).getTerminal_id());
String bwterminalID="";
int terminalLen=terminalidString.length();
if(terminalLen<12){
int t0=12-terminalLen;
bwterminalID=String.format("%1$0"+(12-terminalidString.length())+"d",0)+terminalidString;
logger.info("bwterminalID bu ling:"+bwterminalID+"....terminalID:"+terminalidString);
}
String tmnclpkey =tckList.get(i).getPublic_key();
String yuan3 =provinceidString+bwterminalID+tmnclpkey;
logger.info("ukeyPassword:"+ukeyPassword);
try {
ukeyid=getKey(ukeyPassword);//获取uKeyId
x++;
logger.info("ukeyid:"+ukeyid+"XXXXXXXXX:"+x);
} catch (Exception e) {
logger.info("getKeyId is exception:"+e);
return "error";
}
String jmptp="";
try {
jmptp=getSignature(ukeyPassword,ukeyid,yuan3);
logger.info("yuanptp:"+jmptp);
} catch (Exception e) {
logger.info("getSignature is exception:"+e);
return "error";
}
y++;
String TerminalPublicKey =y+"y++"+provinceidString+","+bwterminalID+","+tmnclpkey+","+jmptp+";";
strBuf.append(TerminalPublicKey);
if ((i + 1) % 1000 == 0) {//1000条记录写一次文件
//全部截取
result =strBuf.substring(0, strBuf.length());
int isSucKey=FileUtil.fileAppend(publicKeyFilePath,result);
try {
if(isSucKey==0){
logger.info(" isSucKey success > 1");
}else{
logger.info(" isSucKey error");
}
} catch (Exception e) {
logger.info("fileAppend isSucKey or isSucZy exc:"+e);
}
strBuf = new StringBuilder();
}
}
result =strBuf.substring(0, strBuf.length()-1);
int isSucKey=FileUtil.fileAppend(publicKeyFilePath,result);
if(isSucKey==0){
logger.info(" isSucKey success");
}
//获取生成文件
File f =FileUtil.getFile(publicKeyFilePath);
//读取文件内容
String allString=FileUtil.getFileContent(f);
String remark256=StringEncrytp.Encrypt(allString, "");
logger.info("remark256:"+remark256+"chang du wei :"+remark256.length());
//获取文件路径
String zhaiyaoFilePath = FilePath.getTmnClpKeyFilePath(timefile, zhaiyaofile);
int isSucZy=FileUtil.fileAppend(zhaiyaoFilePath,remark256);
logger.info("isSucZy:"+isSucZy);
System.out.println("isSucZy:"+isSucZy);
try {
if(isSucZy==0){
logger.info(" isSucZy success");
}else{
logger.info(" isSucZy error");
}
} catch (Exception e) {
logger.info("fileAppend isSucZy exc:"+e);
}
}else if(sjlen==8){
logger.info("input parameters length :8");
String resString=jiaoyan(sj);
if(resString=="success"){
String date =syear+"-"+smonth+"-"+sday;
logger.info("Query time is :"+date);
List<TmnClpKey> tckList=itck.getTmnClpkeyListByDate(tJdbcTemplate, date);
int tms =itck.getOneDayTnmClpKeyCount(tJdbcTemplate, date);
logger.info("tckList is:"+tckList);
logger.info("tms is:"+tms);
String countkey="";
String bwcountkey="";
if(tms!=0){
countkey=String.valueOf(tms);
int len=countkey.length();
if(len<6){
int n0=6-len;
bwcountkey=String.format("%1$0"+(6-countkey.length())+"d",0)+countkey;//补零
logger.info("bwcountkey:"+bwcountkey);
}
}else{
return "There is no data for the current time";
}
StringBuilder strBuf = new StringBuilder();
String bwcountkeyjfh =bwcountkey+";";
strBuf.append(bwcountkeyjfh);
if(tckList!=null){
for(TmnClpKey tcKey:tckList){
String terminalidString=String.valueOf(tcKey.getTerminal_id());
String bwterminalID="";
int terminalLen=terminalidString.length();
if(terminalLen<12){
int t0=12-terminalLen;
bwterminalID=String.format("%1$0"+(12-terminalidString.length())+"d",0)+terminalidString;
logger.info("bwterminalID bu ling:"+bwterminalID);
}
String tmnclpkey =tcKey.getPublic_key();
String yuan3 =provinceidString+bwterminalID+tmnclpkey;
logger.info("ukeyPassword:"+ukeyPassword);
try {
ukeyid=getKey(ukeyPassword);
logger.info("ukeyid:"+ukeyid);
} catch (Exception e) {
logger.info("getKeyId is exception:"+e);
return "error";
}
String jmptp="";
try {
jmptp=getSignature(ukeyPassword,ukeyid,yuan3);
logger.info("yuanptp:"+jmptp);
} catch (Exception e) {
logger.info("getSignature is exception:"+e);
return "error";
}
String TerminalPublicKey =provinceidString+","+bwterminalID+","+tmnclpkey+","+jmptp+";";
strBuf.append(TerminalPublicKey);
}
}
String result =strBuf.substring(0, strBuf.length()-1);
String remark256=StringEncrytp.Encrypt(result, "");
logger.info("remark256:"+remark256+"chang du wei :"+remark256.length());
FileOutputStream out = null;
FileOutputStream out256 = null;
String timefile =syear+smonth+sday;
String publicKeyFilePath = FilePath.getTmnClpKeyFilePath(timefile, publickeyfile);
String zhaiyaoFilePath = FilePath.getTmnClpKeyFilePath(timefile, zhaiyaofile);
FileOutputStream outpublickey = null;
FileOutputStream outzhaiyao = null;
outpublickey = new FileOutputStream(FileUtil.makeNewFile(publicKeyFilePath));
outzhaiyao = new FileOutputStream(FileUtil.makeNewFile(zhaiyaoFilePath));
outpublickey.write(result.getBytes());
outpublickey.close();
outzhaiyao.write(remark256.getBytes());
outzhaiyao.close();
}else{
logger.info("Input time format error !");
return "Input time format error";
}
}else{
logger.info("Input time format error !");
return "Input time format error";
}
return "success";
}
@ResponseBody
public String ScPkeyFile(String sj) throws Exception {
int sjlen =sj.length();
String syear="";
String smonth="";
String sday="";
if(sjlen==8){
syear=sj.substring(0, 4);
smonth=sj.substring(4, 6);
sday=sj.substring(6, 8);
}
List<SystemInfo> systemInfoslist =is.getSystemInfoList(tJdbcTemplate);
SystemInfo systemInfo=systemInfoslist.get(0);
Integer Province_id= systemInfo.getProvince_id();
String provinceidString=String.valueOf(Province_id);
logger.info("省份id为:"+Province_id);
if("1".equals(sj)){
String allfile ="allKeyAndRemark";
String allPublicKeyFilePath = FilePath.getTmnClpKeyFilePath(allfile, publickeyfile);
String allZhaiyaoFilePath = FilePath.getTmnClpKeyFilePath(allfile, zhaiyaofile);
int a=FileUtil.deleteFile(allPublicKeyFilePath);
int b=FileUtil.deleteFile(allZhaiyaoFilePath);
int tms =itck.getAllTnmClpKeyCount(termJdbcTemplate);
logger.info("=============================tms:"+tms);
String countkey="";
String bwcountkey="";
if(tms!=0){
countkey=String.valueOf(tms);
int len=countkey.length();
if(len<6){
int n0=6-len;
bwcountkey=String.format("%1$0"+(6-countkey.length())+"d",0)+countkey;
logger.info("bwcountkey:"+bwcountkey);
}
}else{
return "There is no data for the current time";
}
StringBuilder strBuf = new StringBuilder();
String bwcountkeyjfh =bwcountkey+";";
strBuf.append(bwcountkeyjfh);
int numcs=0;
int x=0;
int y=0;
String timefile ="allKeyAndRemark";
String result ="";
String publicKeyFilePath = FilePath.getTmnClpKeyFilePath(timefile, publickeyfile);
List<TmnClpKey> tckList =itck.getTmnClpkeyList(termJdbcTemplate);
for (int i = 0; i < tckList.size(); i++) {
String terminalidString=String.valueOf(tckList.get(i).getTerminal_id());
String bwterminalID="";
int terminalLen=terminalidString.length();
if(terminalLen<12){
int t0=12-terminalLen;
bwterminalID=String.format("%1$0"+(12-terminalidString.length())+"d",0)+terminalidString;
logger.info("bwterminalID bu ling:"+bwterminalID+"....terminalID:"+terminalidString);
}
String tmnclpkey =tckList.get(i).getPublic_key();
String yuan3 =provinceidString+bwterminalID+tmnclpkey;
logger.info("ukeyPassword:"+ukeyPassword);
try {
ukeyid=getKey(ukeyPassword);//获取uKeyId
x++;
logger.info("ukeyid:"+ukeyid+"XXXXXXXXX:"+x);
} catch (Exception e) {
logger.info("getKeyId is exception:"+e);
return "error";
}
String jmptp="";
try {
jmptp=getSignature(ukeyPassword,ukeyid,yuan3);
logger.info("yuanptp:"+jmptp);
} catch (Exception e) {
logger.info("getSignature is exception:"+e);
return "error";
}
y++;
String TerminalPublicKey =y+"y++"+provinceidString+","+bwterminalID+","+tmnclpkey+","+jmptp+";";
strBuf.append(TerminalPublicKey);
if ((i + 1) % 1000 == 0) {//1000条记录写一次文件
//全部截取
result =strBuf.substring(0, strBuf.length());
int isSucKey=FileUtil.fileAppend(publicKeyFilePath,result);
try {
if(isSucKey==0){
logger.info(" isSucKey success > 1");
}else{
logger.info(" isSucKey error");
}
} catch (Exception e) {
logger.info("fileAppend isSucKey or isSucZy exc:"+e);
}
strBuf = new StringBuilder();
}
}
result =strBuf.substring(0, strBuf.length()-1);
int isSucKey=FileUtil.fileAppend(publicKeyFilePath,result);
if(isSucKey==0){
logger.info(" isSucKey success");
}
//获取生成文件
File f =FileUtil.getFile(publicKeyFilePath);
//读取文件内容
String allString=FileUtil.getFileContent(f);
String remark256=StringEncrytp.Encrypt(allString, "");
logger.info("remark256:"+remark256+"chang du wei :"+remark256.length());
//获取文件路径
String zhaiyaoFilePath = FilePath.getTmnClpKeyFilePath(timefile, zhaiyaofile);
int isSucZy=FileUtil.fileAppend(zhaiyaoFilePath,remark256);
logger.info("isSucZy:"+isSucZy);
System.out.println("isSucZy:"+isSucZy);
try {
if(isSucZy==0){
logger.info(" isSucZy success");
}else{
logger.info(" isSucZy error");
}
} catch (Exception e) {
logger.info("fileAppend isSucZy exc:"+e);
}
}else if(sjlen==8){
logger.info("input parameters length :8");
String resString=jiaoyan(sj);
if(resString=="success"){
String date =syear+"-"+smonth+"-"+sday;
logger.info("Query time is :"+date);
List<TmnClpKey> tckList=itck.getTmnClpkeyListByDate(tJdbcTemplate, date);
int tms =itck.getOneDayTnmClpKeyCount(tJdbcTemplate, date);
logger.info("tckList is:"+tckList);
logger.info("tms is:"+tms);
String countkey="";
String bwcountkey="";
if(tms!=0){
countkey=String.valueOf(tms);
int len=countkey.length();
if(len<6){
int n0=6-len;
bwcountkey=String.format("%1$0"+(6-countkey.length())+"d",0)+countkey;//补零
logger.info("bwcountkey:"+bwcountkey);
}
}else{
return "There is no data for the current time";
}
StringBuilder strBuf = new StringBuilder();
String bwcountkeyjfh =bwcountkey+";";
strBuf.append(bwcountkeyjfh);
if(tckList!=null){
for(TmnClpKey tcKey:tckList){
String terminalidString=String.valueOf(tcKey.getTerminal_id());
String bwterminalID="";
int terminalLen=terminalidString.length();
if(terminalLen<12){
int t0=12-terminalLen;
bwterminalID=String.format("%1$0"+(12-terminalidString.length())+"d",0)+terminalidString;
logger.info("bwterminalID bu ling:"+bwterminalID);
}
String tmnclpkey =tcKey.getPublic_key();
String yuan3 =provinceidString+bwterminalID+tmnclpkey;
logger.info("ukeyPassword:"+ukeyPassword);
try {
ukeyid=getKey(ukeyPassword);
logger.info("ukeyid:"+ukeyid);
} catch (Exception e) {
logger.info("getKeyId is exception:"+e);
return "error";
}
String jmptp="";
try {
jmptp=getSignature(ukeyPassword,ukeyid,yuan3);
logger.info("yuanptp:"+jmptp);
} catch (Exception e) {
logger.info("getSignature is exception:"+e);
return "error";
}
String TerminalPublicKey =provinceidString+","+bwterminalID+","+tmnclpkey+","+jmptp+";";
strBuf.append(TerminalPublicKey);
}
}
String result =strBuf.substring(0, strBuf.length()-1);
String remark256=StringEncrytp.Encrypt(result, "");
logger.info("remark256:"+remark256+"chang du wei :"+remark256.length());
FileOutputStream out = null;
FileOutputStream out256 = null;
String timefile =syear+smonth+sday;
String publicKeyFilePath = FilePath.getTmnClpKeyFilePath(timefile, publickeyfile);
String zhaiyaoFilePath = FilePath.getTmnClpKeyFilePath(timefile, zhaiyaofile);
FileOutputStream outpublickey = null;
FileOutputStream outzhaiyao = null;
outpublickey = new FileOutputStream(FileUtil.makeNewFile(publicKeyFilePath));
outzhaiyao = new FileOutputStream(FileUtil.makeNewFile(zhaiyaoFilePath));
outpublickey.write(result.getBytes());
outpublickey.close();
outzhaiyao.write(remark256.getBytes());
outzhaiyao.close();
}else{
logger.info("Input time format error !");
return "Input time format error";
}
}else{
logger.info("Input time format error !");
return "Input time format error";
}
return "success";
}
0 0
- 按一定条数写入拼接文件
- 限制一定时间内发送短信条数
- sql查询指定列超过一定条数的记录
- BlockingQueue定时或达到一定条数读取队列
- scala读取HDFS文件,每次读取一定的字节数
- scala读取HDFS文件,每次读取一定的字节数
- ecshop 如何首页调用显示一定条数的用户评论
- 3秒钟完成50万条并发日志 文件写入
- 3秒钟完成50万条并发日志 文件写入
- Python3 随机生成一组不重复数并按行写入文件
- 沙盒路径、拼接路径、将字符串,二进制Data、照片写入到文件中或读取
- C#对二进制数据进行拼接平移补位,并用BinaryWriter写入文件中
- 删除指定日期前的日志文件,对大于一定内存的日志文件重命名且新建日志继续写入
- 拼接平方数
- 拼接平方数
- 自己编写的一个程序:读取XML格式的日志文件,并以一定的数据写入数据库中
- 怎样把数当做字符串写入另外的txt文件?
- C语言回文数判断,结果写入文件中
- ui-grid 行编辑功能
- java/bitmap
- 最近学了点PHP,现学现用顺手做了个APP
- linux shell 保留字
- Kali Linux 2017中Scapy运行bug解决
- 按一定条数写入拼接文件
- 初来乍到
- 搭建coreseek(sphinx+mmseg3)详细安装配置+php之sphinx扩展安装+php调用示例
- 异或运算的应用与nimm博弈
- 自定义服务1
- VMware Workstation Centos7 搭建开发环境
- activemq集群搭建与多线程消息发送接收案例
- 搭建LAMP服务器环境流程
- RabbitMq之Routing,Topics