5fab9eb97b5ff4a0b2e1de06bc963fc310f8273c.svn-base
8.45 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package com.thinkgem.jeesite.modules.reg.web.bus;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusQlr;
import com.thinkgem.jeesite.modules.reg.entity.bus.RegBusSlsq;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusQlrService;
import com.thinkgem.jeesite.modules.reg.service.bus.RegBusSlsqService;
import sun.misc.BASE64Decoder;
@Controller
@RequestMapping(value = "${adminPath}/reg/bus/uploadExamPic")
public class uploadExamPicController extends BaseController{
@Autowired
private RegBusSlsqService regBusSlsqService;
@Autowired
private RegBusQlrService regBusQlrService;
@RequestMapping(value = "scanss")
public String scanss(RegBusSlsq regBusSlsq,HttpServletRequest request, HttpServletResponse response, Model model) {
String picywh = request.getParameter("ywh");
List<String> listpic = new ArrayList<String>();
if(StringUtils.isNotBlank(picywh)){
String Path = Global.getPictures()+ picywh + "/";
File file = new File(Path);
if(file.exists()){
File[] files = file.listFiles();
if(files.length > 0){
for (File file2 : files) {
String absoltpath = (file2.getAbsolutePath()).replaceAll("\\\\", "/");
listpic.add(picywh+"/"+file2.getName());
logger.info(file2.getName());
}
}
}
}
Double data = Math.random();
model.addAttribute("math", data);
model.addAttribute("taskkey",request.getParameter("picid"));
model.addAttribute("ywh", picywh);
model.addAttribute("listpic",listpic);
return "modules/reg/bus/dialog/scanss";
}
@RequestMapping(value = "scan")
public String scan(RegBusSlsq regBusSlsq, HttpServletRequest request, HttpServletResponse response, Model model) {
String ywh = request.getParameter("ywh");
model.addAttribute("ywh", ywh);
return "modules/reg/bus/dialog/scan";
}
@RequestMapping(value = "uploadPic")
public void uploadPic(HttpServletRequest request,Model model,HttpServletResponse response) throws IOException{
String ywh = request.getParameter("ywh");
String sxh = request.getParameter("sxh");
String dirpic = Global.getPictures()+ywh;
//String savePath = "F:/images/";
File filedir = new File(dirpic);
String savePath = "";
if(filedir.isDirectory()){
savePath = dirpic + "/";
}else{
filedir.mkdir();
savePath = dirpic +"/";
}
File tmp_path = new File(savePath);
tmp_path.mkdirs();
System.out.println("照片数据保存路径:" + savePath);
int num = 100;
//权利人人像比对是传递顺序号
if(StringUtils.isNotBlank(sxh)) {
num = Integer.parseInt(sxh);
}
String picname= Integer.toString(num);
picname = ywh + "-"+picname+".jpg";
File file_txt = new File(savePath+picname);
if(StringUtils.isBlank(sxh)) {
do{//业务拍照
num = num+1;
picname= Integer.toString(num);
picname = ywh + "-"+ picname+".jpg";
file_txt = new File(savePath+picname);
}while(file_txt.exists());
}else {//人像比对拍照
picname= Integer.toString(num);
picname = ywh + "-"+ picname+".jpg";
file_txt = new File(savePath+picname);
}
model.addAttribute("pic",picname);
String image = request.getParameter("image");//240
String type = request.getParameter("val");//240
if(null!=image && !"".equals(image)){//防止没有拍照直接保存产生的空指针的错误
String width = request.getParameter("w");//320
String height = request.getParameter("h");//240
int w = Integer.parseInt(width);
int h = Integer.parseInt(height);
OutputStream out = null;
if (null!=type &&"pixel".equals(type)) {//Trident
try {
BufferedImage bf = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
String[] rows = image.split("\\|");
for (int i = 0; i < rows.length; i++) {
String[] col = rows[i].split(";");
for (int j = 0; j < col.length; j++) {
int data = Integer.parseInt(col[j], 10);
bf.setRGB(j, i, data);
}
}
File picPath = new File(savePath);
if (!picPath.exists()) {
picPath.mkdirs();
}
ImageIO.write(bf, "jpg", file_txt);
} catch (Exception e) {
e.printStackTrace();
}
} else {//WebKit
try {
byte[] bytes = null;
String imageStr = null;
//Base64解码并生成图片
//替换头
imageStr = image.replace("data:image/png;base64,", "").trim();
/*if (null != image) {
image = image.substring(image.indexOf(",") + 1);
}*/
// Base64解码
bytes = new BASE64Decoder().decodeBuffer(imageStr);
for (int i = 0; i < bytes.length; ++i) {
if (bytes[i] < 0) {// 调整异常数据
bytes[i] += 256;
}
}
if (!file_txt.exists()) {
file_txt.createNewFile();
}else{
file_txt.delete();
file_txt.createNewFile();
}
// 生成jpeg图片
out = new FileOutputStream(file_txt.getAbsoluteFile());
out.write(bytes);
} catch (Exception e) {
e.printStackTrace();
}finally{
if(null!=out){
out.flush();
out.close();
}
}
}
}else{
System.out.println("图像为空");
}
//人像比对附件保存后直接更新权利人字段
if(StringUtils.isNotBlank(sxh)) {
String tpbm = image.replace("data:image/png;base64,", "").trim();
RegBusQlr regBusQlr = regBusQlrService.findByPic(ywh,sxh);
regBusQlr.setTpbm(tpbm);
regBusQlr.setPic(ywh+"/"+picname);
regBusQlrService.save(regBusQlr);
}
}
@RequestMapping(value = "delpho")
public String delpho(HttpServletRequest request,Model model,HttpServletResponse response) throws IOException{
String picpath = Global.getPictures();
String realpath = picpath + request.getParameter("picname");
File file =new File(realpath);
if(file.exists()){
file.delete();
}
String sxh = request.getParameter("sxh");
String ywh = request.getParameter("ywh");
if(StringUtils.isBlank(sxh)) {
return "redirect:"+Global.getAdminPath()+"/reg/bus/uploadExamPic/scanss?ywh="+ request.getParameter("ywh")+"&picid="+request.getParameter("picid");
}else {
RegBusQlr regBusQlr = regBusQlrService.findByPic(ywh,sxh);
regBusQlr.setTpbm(null);
regBusQlr.setPic(null);
regBusQlrService.save(regBusQlr);
return "redirect:"+Global.getAdminPath()+"/reg/bus/regBusQlr/rxbdForm?ywh="+ request.getParameter("ywh");
}
}
@RequestMapping(value = "delphodir")
public String delphodir(HttpServletRequest request,Model model,HttpServletResponse response) throws IOException{
//删除照片
String picpath = Global.getPictures();
String dirpath = picpath + request.getParameter("ywh");
System.out.println(dirpath);
File filedir = new File(dirpath);
if(filedir.isDirectory()){
File[] filelist = filedir.listFiles();
for(int i = 0;i<filelist.length;i++){
filelist[i].delete();
}
filedir.delete();
}
return "redirect:"+ adminPath + "/act/task/todo/";
}
//-----------------------------------------人像比对---------------------------------------------------
@RequestMapping(value = "rxbdscan")
public String rxbdscan(RegBusSlsq regBusSlsq, HttpServletRequest request, HttpServletResponse response, Model model) {
String ywh = request.getParameter("ywh");
String sxh = request.getParameter("sxh");
model.addAttribute("sxh", sxh);
model.addAttribute("ywh", ywh);
return "modules/reg/bus/dialog/rxbdscan";
}
}