Authored by mlge

增加标志 操作

... ... @@ -17,5 +17,8 @@ public class SampleViewObj {
private String qPic;
private String pPic;
private String nPic;
private int currentIndex;//当前图片所在的行index
private boolean flag;//标识
}
... ...
package com.example.demo;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
... ... @@ -13,7 +15,6 @@ import java.util.ArrayList;
@RestController
@RequestMapping(path = "/show")
public class ShowCtrl {
public static final int pageSize = 10;
@Autowired
ShowSer showSer;
... ... @@ -33,16 +34,23 @@ public class ShowCtrl {
return mv;
}
//跳转至样本展示页面
@GetMapping(path = "/toSampleShow")
public ModelAndView toSampleShow() {
return new ModelAndView("showSamples");
}
/**
* 获取样本table 分页数据
* @param req
* @param sampleDir
* @return
*/
@RequestMapping ("/getSamplesByPage")
@ResponseBody
public PageListResp<SampleViewObj> getSamplesByPage(PageTableReq req,String sampleDir ) {
if(! showSer.samplesMap.contains(sampleDir)){
showSer.loadSampleInfo(sampleDir);//重新加载
showSer.loadSampleInfo(sampleDir);//统计样本个数
}
Integer count = showSer.samplesMap.get(sampleDir);
if(count == null || count == 0){//加载文件失败
... ... @@ -99,4 +107,26 @@ public class ShowCtrl {
return null;
}
/**
* 更新update文件
* @param flag
* @param currentIndex
* @return
*/
@GetMapping("/updateSampleInfo")
public String updateSampleInfo(boolean flag, int currentIndex, String sampleDir){
File file = new File(sampleDir + "/update.info");
if(!file.exists()){
try {
FileUtils.forceMkdirParent(file);
} catch (IOException e) {
e.printStackTrace();
return "创建update.info文件失败!";
}
}
if( !showSer.modifyFile(file, currentIndex, flag)){
return "更新失败!";
}
return "";
}
}
... ...
... ... @@ -35,7 +35,11 @@ public class ShowSer {
public ConcurrentHashMap<String, List<Integer>> sknDirsListMap = new ConcurrentHashMap<String, List<Integer>>();
public ConcurrentHashMap<String, Integer> samplesMap = new ConcurrentHashMap<String, Integer>();
public ConcurrentHashMap<String, Integer> samplesMap = new ConcurrentHashMap<>();
/*public Set<String> updateSet =Collections.synchronizedSet(new HashSet<>());*/
public PhotoViewObj fetchCurentPhotos(String currentDir, int skip) {
... ... @@ -196,11 +200,20 @@ public class ShowSer {
List<String> pList = readFileByIndex(pInfo,startIndex,endIndex);
List<String> nList = readFileByIndex(nInfo,startIndex,endIndex);
String readUrl = "/show/readAli?file=";
String updateFilePath = sampleDir+"/update.info";
Set<Integer> updateSet = getUpdateFileInfo(updateFilePath);
for(int i = 0 ; i< qList.size(); i++){
int itemIndex = startIndex + i;//所在的行 以0为起始
boolean flag = false;
if(updateSet.contains(itemIndex)){
flag = true;
}
SampleViewObj sampleViewObj = new SampleViewObj(
readUrl+ URLEncoder.encode(qList.get(i)),
readUrl+ URLEncoder.encode(pList.get(i)),
readUrl+ URLEncoder.encode(nList.get(i)));
readUrl+ URLEncoder.encode(nList.get(i)),
itemIndex,
flag);
pageList.add(sampleViewObj);
}
} catch (IOException e) {
... ... @@ -211,6 +224,28 @@ public class ShowSer {
LineIterator.closeQuietly(nInfo);
}
return pageList;
}
//读取updateFile文件
private Set<Integer> getUpdateFileInfo(String updateFilePath) {
Set<Integer> set = new HashSet<>();
LineIterator lineIterator = null;
try {
lineIterator = FileUtils.lineIterator(new File(updateFilePath));
while (lineIterator.hasNext()){
String s = lineIterator.next();
if(StringUtils.isEmpty(s))continue;
int value = Integer.valueOf(s);
set.add(value);
}
} catch (IOException e) {
e.printStackTrace();
}finally {
LineIterator.closeQuietly(lineIterator);
}
return set;
}
//读取文件
... ... @@ -252,10 +287,39 @@ public class ShowSer {
return count;
}
/* public static void main(String[] args) {
ShowSer s = new ShowSer();
s.fetchSamplesByPage("E:\\0419", 94, 2);
}*/
/**
* 更新 update.info 文件
*
* @param file
* @param content
* @param flag --true ,当前行号写入文件 false --当前行 移出文件
*/
public boolean modifyFile(File file, int content, boolean flag) {
if(flag){
try {//追加写入文件
FileUtils.writeLines(file,"utf-8",Arrays.asList(content), true);
} catch (IOException e) {
e.printStackTrace();
return false;
}
}/*else {//从文件中移出
LineIterator lineIterator = null;
try {
lineIterator = FileUtils.lineIterator(file);
while (lineIterator.hasNext()) {
int s = Integer.valueOf(lineIterator.next());
if (s == content) {
lineIterator.remove();
break;
}
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
}*/
return true;
}
}
... ...
... ... @@ -1064,10 +1064,12 @@
</div>
<div class="row-fluid" >
<div class="span12" >
<table id = "sampleTable" class="table table-striped table-bordered table-hover">
<table id = "sampleTable" class="table table-striped table-bordered table-hover" >
</table>
</div>
</div>
... ... @@ -1114,13 +1116,14 @@
});
var sampleDir = "";
var sampleTable;
function sampleLoad(){
sampleDir = $("#sampleDir").val();
initSampleTable();
}
function initSampleTable () {
$("#sampleTable").dataTable({
sampleTable = $("#sampleTable").dataTable({
iDisplayLength: 10,
bProcessing: true,
bServerSide: true,
... ... @@ -1138,7 +1141,8 @@
aoColumnDefs: [
{ sWidth: "30%", aTargets: [0] ,},
{ sWidth: "30%", aTargets: [1] },
{ sWidth: "35%", aTargets: [2] }
{ sWidth: "30%", aTargets: [2] },
{ sWidth: "10%", aTargets: [3] }
],
aoColumns: [
{sTitle: "原文件", mData: function(mData){
... ... @@ -1150,17 +1154,51 @@
{sTitle: "负样本", mData: function(mData){
return "<img src='"+mData.npic+"'>";
}
},
{sTitle: "标识", mData: function(mData){
if(mData.flag){//已经做了标识的
return "&radic;";
}else {
return "<button class='btn btn-xs mini red' onclick='changeFlag(true,"+mData.currentIndex+")' >标识</button>";
}
}
}
]
/*fnServerParams: function (aoData) {
aoData = $.merge(aoData, that.getQueryParams());
/* fnServerParams: function (aoData) {
console.log();
aoData.iDisplayStart
// aoData = $.merge(aoData, that.getQueryParams());
},*/
});
}
<!-- END JAVASCRIPTS -->
function changeFlag(flag, currentIndex) {
//发送请求--修改update文件
$.ajax({
url: encodeURI("/show/updateSampleInfo?flag="+flag+"&currentIndex="+currentIndex+"&sampleDir="+sampleDir),
type: "get",
success: function (data) {
if( data != ""){
alert(data);
}else{
sampleTable.fnDraw();
}
},
error:function (data) {
alert("更新失败");
}
});
}
</script>
... ...