ShowCtrl.java
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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;
/**
* Created by jack on 2018/4/18.
*/
@RestController
@RequestMapping(path = "/show")
public class ShowCtrl {
@Autowired
ShowSer showSer;
@RequestMapping("/index")
public ModelAndView index() {
return new ModelAndView("index");
}
@GetMapping(path = "/load")
public ModelAndView loadPhotoDir(@RequestParam String curDir) {
ModelAndView mv = new ModelAndView("showImage");
showSer.loadDir(curDir);
mv.addObject("curDir",curDir);
mv.addObject("photoViewObj", showSer.fetchCurentPhotos(curDir, 0));
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.containsKey(sampleDir)){
showSer.loadSampleInfo(sampleDir);//统计样本个数
}
Integer count = showSer.samplesMap.get(sampleDir);
if(count == null || count == 0){//加载文件失败
return PageListResp.newBuilder().iTotalDisplayRecords(0).iTotalRecords(0).aaData(new ArrayList()).build();
}
PageListResp.Builder pageListResp = PageListResp.newBuilder().iTotalDisplayRecords(count.intValue()).iTotalRecords(count.intValue());
pageListResp.aaData(showSer.fetchSamplesByPage(sampleDir, req.getIDisplayStart(), req.getIDisplayLength()));
return pageListResp.build();
}
@GetMapping(path = "/next")
public ModelAndView nextPhoto(@RequestParam String curDir) {
ModelAndView mv = new ModelAndView("showImage");
mv.addObject("curDir",curDir);
mv.addObject("photoViewObj", showSer.fetchCurentPhotos(curDir, 1));
return mv;
}
@GetMapping(path = "/prev")
public ModelAndView prevPhoto(@RequestParam String curDir) {
ModelAndView mv = new ModelAndView("showImage");
mv.addObject("curDir",curDir);
mv.addObject("photoViewObj", showSer.fetchPrevPhotos(curDir));
return mv;
}
@GetMapping(path = "/jump")
public ModelAndView jumpSknPhoto(@RequestParam("curDir") String curDir, @RequestParam String skn) {
ModelAndView mv = new ModelAndView("showImage");
mv.addObject("curDir",curDir);
mv.addObject("photoViewObj", showSer.fetchSknPhotos(curDir, skn));
return mv;
}
@GetMapping(path = "/read")
public Object readPhotoBytes(@RequestParam("curDir") String curDir, @RequestParam("skn") String skn, @RequestParam("order") String order) {
try {
return showSer.readPhotoBytes(curDir, skn, order);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@GetMapping(path = "/readAli")
public Object readPhotoBytes(@RequestParam("file") String filePath) {
try {
return showSer.readPhotoBytes(filePath);
} catch (IOException e) {
e.printStackTrace();
}
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 "";
}
@RequestMapping("/loadSingleImage")
public ModelAndView loadSingleImage(){
return new ModelAndView("loadSingleImage");
}
}