@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); 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); 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); x++; } catch (Exception e) { return "error"; } String jmptp=""; try { jmptp=getSignature(ukeyPassword,ukeyid,yuan3); } catch (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, ""); //获取文件路径 String zhaiyaoFilePath = FilePath.getTmnClpKeyFilePath(timefile, zhaiyaofile); int isSucZy=FileUtil.fileAppend(zhaiyaoFilePath,remark256); 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, ""); 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"; }
java 查询到指定条数写入文件
猜你喜欢
转载自blog.csdn.net/shy415502155/article/details/70915982
今日推荐
周排行