Showing
3 changed files
with
92 additions
and
11 deletions
@@ -116,22 +116,33 @@ public class ShowCtrl { | @@ -116,22 +116,33 @@ public class ShowCtrl { | ||
116 | @GetMapping("/updateSampleInfo") | 116 | @GetMapping("/updateSampleInfo") |
117 | public String updateSampleInfo(boolean flag, int currentIndex, String sampleDir){ | 117 | public String updateSampleInfo(boolean flag, int currentIndex, String sampleDir){ |
118 | File file = new File(sampleDir + "/update.info"); | 118 | File file = new File(sampleDir + "/update.info"); |
119 | - if(!file.exists()){ | ||
120 | - try { | ||
121 | - FileUtils.forceMkdirParent(file); | ||
122 | - } catch (IOException e) { | ||
123 | - e.printStackTrace(); | ||
124 | - return "创建update.info文件失败!"; | ||
125 | - } | 119 | + if(!showSer.checkFile(file)){ |
120 | + return "创建文件失败!"; | ||
126 | } | 121 | } |
122 | + | ||
127 | if( !showSer.modifyFile(file, currentIndex, flag)){ | 123 | if( !showSer.modifyFile(file, currentIndex, flag)){ |
128 | return "更新失败!"; | 124 | return "更新失败!"; |
129 | } | 125 | } |
130 | return ""; | 126 | return ""; |
131 | } | 127 | } |
132 | 128 | ||
129 | + | ||
130 | + @GetMapping("/updateSamplesByBatch") | ||
131 | + public String updateSamplesByBatch(boolean flag, String indexListStr, String sampleDir){ | ||
132 | + File file = new File(sampleDir + "/update.info"); | ||
133 | + if(!showSer.checkFile(file)){ | ||
134 | + return "创建文件失败!"; | ||
135 | + } | ||
136 | + if( !showSer.modifyFile(file, indexListStr, flag)){ | ||
137 | + return "更新失败!"; | ||
138 | + } | ||
139 | + return ""; | ||
140 | + } | ||
141 | + | ||
133 | @RequestMapping("/loadSingleImage") | 142 | @RequestMapping("/loadSingleImage") |
134 | public ModelAndView loadSingleImage(){ | 143 | public ModelAndView loadSingleImage(){ |
135 | return new ModelAndView("loadSingleImage"); | 144 | return new ModelAndView("loadSingleImage"); |
136 | } | 145 | } |
146 | + | ||
147 | + | ||
137 | } | 148 | } |
@@ -276,7 +276,8 @@ public class ShowSer { | @@ -276,7 +276,8 @@ public class ShowSer { | ||
276 | * @param flag --true ,当前行号写入文件 false --当前行 移出文件 | 276 | * @param flag --true ,当前行号写入文件 false --当前行 移出文件 |
277 | */ | 277 | */ |
278 | 278 | ||
279 | - public boolean modifyFile(File file, int content, boolean flag) { | 279 | + |
280 | + public synchronized boolean modifyFile(File file, int content, boolean flag) { | ||
280 | if(flag){ | 281 | if(flag){ |
281 | try {//追加写入文件 | 282 | try {//追加写入文件 |
282 | FileUtils.writeLines(file,"utf-8",Arrays.asList(content), true); | 283 | FileUtils.writeLines(file,"utf-8",Arrays.asList(content), true); |
@@ -284,7 +285,8 @@ public class ShowSer { | @@ -284,7 +285,8 @@ public class ShowSer { | ||
284 | e.printStackTrace(); | 285 | e.printStackTrace(); |
285 | return false; | 286 | return false; |
286 | } | 287 | } |
287 | - }/*else {//从文件中移出 | 288 | + }; |
289 | + /*else {//从文件中移出 | ||
288 | LineIterator lineIterator = null; | 290 | LineIterator lineIterator = null; |
289 | try { | 291 | try { |
290 | lineIterator = FileUtils.lineIterator(file); | 292 | lineIterator = FileUtils.lineIterator(file); |
@@ -303,4 +305,37 @@ public class ShowSer { | @@ -303,4 +305,37 @@ public class ShowSer { | ||
303 | }*/ | 305 | }*/ |
304 | return true; | 306 | return true; |
305 | } | 307 | } |
308 | + | ||
309 | + | ||
310 | + | ||
311 | + public synchronized boolean modifyFile(File file, String contentListStr, boolean flag) { | ||
312 | + if(flag){ | ||
313 | + try {//追加写入文件 | ||
314 | + String[] strings = StringUtils.split(contentListStr, ","); | ||
315 | + FileUtils.writeLines(file,"utf-8",Arrays.asList(strings), true); | ||
316 | + } catch (IOException e) { | ||
317 | + e.printStackTrace(); | ||
318 | + return false; | ||
319 | + } | ||
320 | + }; | ||
321 | + | ||
322 | + return true; | ||
323 | + } | ||
324 | + | ||
325 | + | ||
326 | + public boolean checkFile(File file){ | ||
327 | + if(!file.exists()){ | ||
328 | + try { | ||
329 | + FileUtils.forceMkdirParent(file); | ||
330 | + } catch (IOException e) { | ||
331 | + e.printStackTrace(); | ||
332 | + return false; | ||
333 | + } | ||
334 | + } | ||
335 | + return true; | ||
336 | + } | ||
337 | + | ||
338 | + | ||
339 | + | ||
340 | + | ||
306 | } | 341 | } |
@@ -1046,12 +1046,15 @@ | @@ -1046,12 +1046,15 @@ | ||
1046 | return "<img src='"+mData.npic+"'>"; | 1046 | return "<img src='"+mData.npic+"'>"; |
1047 | } | 1047 | } |
1048 | }, | 1048 | }, |
1049 | - {sTitle: "标识", mData: function(mData){ | 1049 | + {sTitle: "<button onclick='chooseAll()' class='btn btn-xs mini green'>标识当前页</button>", mData: function(mData){ |
1050 | if(mData.flag){//已经做了标识的 | 1050 | if(mData.flag){//已经做了标识的 |
1051 | return "√"; | 1051 | return "√"; |
1052 | }else { | 1052 | }else { |
1053 | - return "<button class='btn btn-xs mini red' onclick='changeFlag(true,"+mData.currentIndex+")' >标识</button>"; | 1053 | + var result = "<input type='hidden' name = 'currentIndex' value ="+mData.currentIndex+" >"; |
1054 | + result +="<button class='btn btn-xs mini red' onclick='changeFlag(true,"+mData.currentIndex+")' >标识</button>"; | ||
1055 | + return result; | ||
1054 | } | 1056 | } |
1057 | + | ||
1055 | } | 1058 | } |
1056 | } | 1059 | } |
1057 | ], | 1060 | ], |
@@ -1111,6 +1114,38 @@ | @@ -1111,6 +1114,38 @@ | ||
1111 | 1114 | ||
1112 | } | 1115 | } |
1113 | 1116 | ||
1117 | + //选择当前页 | ||
1118 | + function chooseAll() { | ||
1119 | + | ||
1120 | + var indexList = new Array(); | ||
1121 | + $("#sampleTable tbody").find("input[name='currentIndex']").each(function (index, item) { | ||
1122 | + console.log("选中的index:" + $(this).val()); | ||
1123 | + var value = $(this).val(); | ||
1124 | + indexList.push(value); | ||
1125 | + }); | ||
1126 | + var indexListStr = indexList.join(","); | ||
1127 | + | ||
1128 | + //发送ajax请求 | ||
1129 | + $.ajax({ | ||
1130 | + url: encodeURI("/show/updateSamplesByBatch?flag=true" + "&indexListStr=" + indexListStr + "&sampleDir=" + sampleDir), | ||
1131 | + type: "get", | ||
1132 | + success: function (data) { | ||
1133 | + if (data != "") { | ||
1134 | + alert(data); | ||
1135 | + } else { | ||
1136 | + sampleTable.fnDraw(); | ||
1137 | + | ||
1138 | + } | ||
1139 | + | ||
1140 | + | ||
1141 | + }, | ||
1142 | + error: function (data) { | ||
1143 | + alert("更新失败"); | ||
1144 | + } | ||
1145 | + }); | ||
1146 | + | ||
1147 | + | ||
1148 | + } | ||
1114 | 1149 | ||
1115 | 1150 | ||
1116 | 1151 |
-
Please register or login to post a comment