/**
* 批量更新
*
* @return
*/
@ResponseBody
@RequestMapping("/updateNumber")
public void updateNumber() {
String seqId = UUID.randomUUID().toString();
//设置所需参数
//subts,变更时间,ts
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss");
String ts=sdf.format(new Date());
String subts=sdf2.format(new Date());
XzDataBindVo bindVo=new XzDataBindVo();
bindVo.setTs(ts);
bindVo.setSubts(subts);
// bindVo.setSubId("C1129X028X0278563933-00-0-XZGF-GXI");
bindVo.setSmsmtchannel("4");
//读取数据
//String filename = "/src/main/resources/data.txt";
String path =this.getClass().getClassLoader().getResource("./data.txt").getPath();
Map<Integer, String> fileMaps = readTxtFile(path);
int num = fileMaps.size();// 行数
for (int i = 0; i < num; i++) {
String subId = fileMaps.get(i);
bindVo.setSubId(subId);
//调用修改接口
try {
xzBindService.updateBind(loggerSingleWork, bindVo, seqId);
} catch (Exception e) {
System.out.println("catch a exception");
}
}
}
public static Map<Integer,String> readTxtFile(String filePath) {
//存放内容的map对象
Map<Integer,String> filemaps = new HashMap<Integer,String>();
try {
String encoding = "GBK";
File file = new File(filePath);
int count = 0;//定义顺序变量
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) {//按行读取
if(!"".equals(lineTxt)){
String reds = lineTxt.split("\\+")[0];//对行的内容进行分析处理后再放入map里。
filemaps.put(count, reds);//放入map
count ++;
}
}
read.close();//关闭InputStreamReader
bufferedReader.close();//关闭BufferedReader
} else {
System.out.println("not find");
}
} catch (Exception e) {
System.out.println("wrong");
e.printStackTrace();
}
return filemaps;
}
}