提交 | 用户 | age
|
a6a76f
|
1 |
package com.yc.action.upload; |
F |
2 |
|
0a4f16
|
3 |
import com.alibaba.fastjson.JSON; |
a6a76f
|
4 |
import com.google.gson.JsonObject; |
F |
5 |
import com.yc.action.BaseAction; |
|
6 |
import com.yc.action.grid.GridUtils; |
2b4227
|
7 |
import com.yc.action.grid.PicEntity; |
3decaa
|
8 |
import com.yc.batchUpload.utils.CallBackMsg; |
a6a76f
|
9 |
import com.yc.entity.AttachmentConfig; |
F |
10 |
import com.yc.entity.DataSourceEntity; |
|
11 |
import com.yc.entity.FileUpload; |
|
12 |
import com.yc.entity.UpFile; |
e44ea2
|
13 |
import com.yc.entity.attachment.AttachmentDocInfoEntity; |
F |
14 |
import com.yc.entity.attachment.AttachmentEntity; |
|
15 |
import com.yc.entity.attachment.AttachmentPermissionEntity; |
|
16 |
import com.yc.entity.attachment.AttachmentWhereEntity; |
a6a76f
|
17 |
import com.yc.exception.ApplicationException; |
F |
18 |
import com.yc.exception.CallBackMessage; |
|
19 |
import com.yc.factory.FactoryBean; |
|
20 |
import com.yc.listener.SessionListener; |
|
21 |
import com.yc.multiData.MultiDataSource; |
|
22 |
import com.yc.multiData.SpObserver; |
|
23 |
import com.yc.sdk.password.action.ChangePassword; |
|
24 |
import com.yc.sdk.shopping.entity.ImageEntity; |
|
25 |
import com.yc.sdk.shopping.entity.ImageUrlParametersEntity; |
|
26 |
import com.yc.sdk.shopping.filter.ImageFilter; |
|
27 |
import com.yc.sdk.shopping.util.SettingKey; |
|
28 |
import com.yc.sdk.shopping.util.WordToPic; |
|
29 |
import com.yc.sdk.weixincp.util.UploadFiles; |
|
30 |
import com.yc.service.BaseService; |
|
31 |
import com.yc.service.impl.DBHelper; |
|
32 |
import com.yc.service.impl.EnImageMD5; |
|
33 |
import com.yc.service.upload.AttachmentIfc; |
0c06a4
|
34 |
import com.yc.service.upload.AttachmentOaIfc; |
a6a76f
|
35 |
import com.yc.service.upload.AttachmentPermissionIfc; |
F |
36 |
import com.yc.utils.EncodeUtil; |
|
37 |
import com.yc.utils.ImageUtils; |
|
38 |
import com.yc.utils.JsonUtil; |
|
39 |
import com.yc.utils.SessionKey; |
|
40 |
import lombok.Data; |
|
41 |
import net.sf.json.JSONArray; |
|
42 |
import net.sf.json.JSONObject; |
|
43 |
import org.apache.catalina.connector.ClientAbortException; |
|
44 |
import org.apache.commons.lang.StringUtils; |
|
45 |
import org.springframework.beans.factory.annotation.Autowired; |
|
46 |
import org.springframework.dao.DataAccessException; |
|
47 |
import org.springframework.jdbc.LobRetrievalFailureException; |
|
48 |
import org.springframework.jdbc.core.support.AbstractLobStreamingResultSetExtractor; |
|
49 |
import org.springframework.jdbc.support.lob.DefaultLobHandler; |
|
50 |
import org.springframework.stereotype.Controller; |
|
51 |
import org.springframework.util.FileCopyUtils; |
|
52 |
import org.springframework.web.bind.annotation.CrossOrigin; |
|
53 |
import org.springframework.web.bind.annotation.RequestMapping; |
3decaa
|
54 |
import org.springframework.web.bind.annotation.ResponseBody; |
a6a76f
|
55 |
import org.springframework.web.multipart.MultipartFile; |
F |
56 |
import org.springframework.web.multipart.MultipartHttpServletRequest; |
|
57 |
import org.springframework.web.multipart.MultipartResolver; |
|
58 |
import org.springframework.web.multipart.commons.CommonsMultipartResolver; |
|
59 |
|
|
60 |
import javax.servlet.http.HttpServletRequest; |
|
61 |
import javax.servlet.http.HttpServletResponse; |
|
62 |
import javax.servlet.http.HttpSession; |
|
63 |
import java.io.*; |
|
64 |
import java.net.URLEncoder; |
|
65 |
import java.sql.ResultSet; |
|
66 |
import java.sql.SQLException; |
|
67 |
import java.text.SimpleDateFormat; |
|
68 |
import java.util.*; |
|
69 |
|
|
70 |
@Controller |
|
71 |
public class AttachmentAction extends BaseAction { |
|
72 |
@Autowired |
|
73 |
private DefaultLobHandler defaultLobHandler; |
|
74 |
|
|
75 |
@Autowired |
|
76 |
private AttachmentIfc attachmentIfc; |
0c06a4
|
77 |
|
X |
78 |
@Autowired |
|
79 |
AttachmentOaIfc attachmentOaIfc; |
a6a76f
|
80 |
|
F |
81 |
public static String domain = AttachmentConfig.get("attachment.server"); |
|
82 |
|
|
83 |
/** |
|
84 |
* 文件显示 |
|
85 |
* |
|
86 |
* @param request |
|
87 |
* @param response |
|
88 |
* @throws IOException |
|
89 |
*/ |
|
90 |
@RequestMapping("/attachment/getAttachmentList.do") //上传的类型的方法 yang 2018-03-30 |
|
91 |
@SuppressWarnings("all") |
|
92 |
public void getAttachmentList(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
93 |
AttachmentDocInfoEntity uploadPerEntity = new AttachmentDocInfoEntity(); |
|
94 |
// PrintWriter out = response.getWriter(); |
|
95 |
HttpSession session = request.getSession(); |
|
96 |
String dbid = (String) session.getAttribute(SessionKey.DATA_BASE_ID); |
|
97 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); |
|
98 |
try { |
|
99 |
SpObserver.setDBtoInstance("_" + dbid); //切换数据源 |
|
100 |
String pant = request.getParameter("pant"); |
|
101 |
Map<String, Object> pMap = (Map) JSONObject.fromObject(pant); |
|
102 |
String usercode = session.getAttribute(SessionKey.USERCODE) + ""; |
|
103 |
String fieldid = DBHelper.getValue(pMap, "fieldid"); |
|
104 |
String docstatus = DBHelper.getValue(pMap, "docstatus"); |
|
105 |
String controlType = DBHelper.getValue(pMap, "controltype"); |
|
106 |
String readerUserCodes = DBHelper.getValue(pMap, "readerusercodes"); |
|
107 |
|
|
108 |
uploadPerEntity.setUsercode(usercode); |
|
109 |
uploadPerEntity.setFormid(DBHelper.getValueInt(pMap, "formid")); |
|
110 |
uploadPerEntity.setDoccode(DBHelper.getValue(pMap, "doccode")); |
|
111 |
uploadPerEntity.setType(DBHelper.getValue(pMap, "type")); |
|
112 |
uploadPerEntity.setFieldid(fieldid); |
|
113 |
uploadPerEntity.setRowid(DBHelper.getValue(pMap, "rowid")); |
|
114 |
uploadPerEntity.setDocstatus(docstatus); |
|
115 |
uploadPerEntity.setHeadFlag(DBHelper.getValueInt(pMap, "headflag")); |
|
116 |
uploadPerEntity.setEditStatus(DBHelper.getValue(pMap, "editStatus")); |
|
117 |
|
|
118 |
List<AttachmentPermissionEntity> uploadPermissionList = new ArrayList<AttachmentPermissionEntity>(); |
|
119 |
|
|
120 |
String vfiluploads = null; |
|
121 |
if (pMap != null) |
|
122 |
vfiluploads = DBHelper.getValue(pMap, "unid"); //uuid |
|
123 |
else { |
|
124 |
vfiluploads = uploadPerEntity.getRowid(); //grid, uuid |
|
125 |
AttachmentDocInfoEntity myUploadPerEntity = attachmentIfc.getAttachmentGfieldInfo(uploadPerEntity.getFormid(), uploadPerEntity.getFieldid()); |
|
126 |
uploadPerEntity.setEditStatus(myUploadPerEntity.getEditStatus()); |
|
127 |
uploadPerEntity.setHeadFlag(myUploadPerEntity.getHeadFlag()); |
|
128 |
} |
|
129 |
|
|
130 |
List<AttachmentEntity> picInfos = null; |
|
131 |
if (vfiluploads != null && !"".equalsIgnoreCase(vfiluploads) && !";".equalsIgnoreCase(vfiluploads) && |
|
132 |
!vfiluploads.toLowerCase().startsWith("http://") && !vfiluploads.toLowerCase().startsWith("https://")) { |
|
133 |
picInfos = attachmentIfc.getAttachmentEntityList(vfiluploads.split(";")[0], controlType != null && controlType.equals("9") ? "1" : "3"); //(formid, fieldid, vfiluploads, doccode,19,true); |
|
134 |
} |
|
135 |
|
|
136 |
AttachmentPermissionIfc attachmentPermissionIfc = (AttachmentPermissionIfc) FactoryBean.getBean("AttachmentPermissionImpl"); |
|
137 |
// docstatus=docMap.get("docstatus")==null?"0":docMap.get("docstatus")+""; |
|
138 |
if (domain == null) { |
|
139 |
domain = ""; |
|
140 |
} |
|
141 |
//上传附件的类型循环判断 |
|
142 |
if (picInfos != null && picInfos.size() > 0) { |
|
143 |
for (AttachmentEntity pic : picInfos) { |
|
144 |
String fileType = "other"; |
|
145 |
//"+(type!=null&& "9".equals(type)?"1":"3")+" |
|
146 |
String staticUrl = ""; |
|
147 |
String src = "/getImage.do?type=" + (controlType != null && controlType.equals("9") ? "1" : "3") + "&uuid=" + pic.getUnid() + ";" + pic.getSeq() + "&dbid=" + dbid; |
|
148 |
if ("jpg".equalsIgnoreCase((String) pic.getFileType()) || |
|
149 |
"jpeg".equalsIgnoreCase((String) pic.getFileType()) || |
|
150 |
"png".equalsIgnoreCase((String) pic.getFileType()) || |
|
151 |
"gif".equalsIgnoreCase((String) pic.getFileType()) || |
|
152 |
"pic".equalsIgnoreCase((String) pic.getFileType()) || |
a1d352
|
153 |
"ico".equalsIgnoreCase((String) pic.getFileType()) || |
a6a76f
|
154 |
"bmp".equalsIgnoreCase((String) pic.getFileType()) || |
F |
155 |
"tif".equalsIgnoreCase((String) pic.getFileType())) { |
|
156 |
fileType = "image"; |
|
157 |
src = "/getImage.do?type=" + (controlType != null && controlType.equals("9") ? "1" : "3") + "&uuid=" + pic.getUnid() + ";" + pic.getSeq() + "&dbid=" + dbid; |
|
158 |
} else if ("mp4".equalsIgnoreCase((String) pic.getFileType()) || |
|
159 |
"avi".equalsIgnoreCase((String) pic.getFileType()) || |
|
160 |
"rm".equalsIgnoreCase((String) pic.getFileType()) || |
|
161 |
"asf".equalsIgnoreCase((String) pic.getFileType()) || |
|
162 |
"divx".equalsIgnoreCase((String) pic.getFileType()) || |
|
163 |
"rmvb".equalsIgnoreCase((String) pic.getFileType())) { |
|
164 |
fileType = "video"; |
02ed67
|
165 |
src = "/smallpic/specialpic/avi.png"; |
X |
166 |
staticUrl = "/smallpic/specialpic/avi.png"; |
a6a76f
|
167 |
} else if ("mp3".equalsIgnoreCase((String) pic.getFileType()) || |
F |
168 |
"aif".equalsIgnoreCase((String) pic.getFileType()) || |
|
169 |
"wav".equalsIgnoreCase((String) pic.getFileType()) || |
|
170 |
"au".equalsIgnoreCase((String) pic.getFileType()) || |
|
171 |
"ram".equalsIgnoreCase((String) pic.getFileType())) { |
|
172 |
fileType = "audio"; |
02ed67
|
173 |
src = "/smallpic/specialpic/avi.png"; |
X |
174 |
staticUrl = "/smallpic/specialpic/avi.png"; |
a6a76f
|
175 |
} else if ("html".equalsIgnoreCase((String) pic.getFileType()) || |
F |
176 |
"htm".equalsIgnoreCase((String) pic.getFileType())) { |
|
177 |
fileType = "html"; |
|
178 |
src = "/smallpic/specialpic/html.png"; |
|
179 |
staticUrl = "/smallpic/specialpic/html.png"; |
|
180 |
} else if ("txt".equalsIgnoreCase((String) pic.getFileType()) || |
|
181 |
"hlp".equalsIgnoreCase((String) pic.getFileType()) || |
|
182 |
"wps".equalsIgnoreCase((String) pic.getFileType())) { |
|
183 |
fileType = "text"; |
|
184 |
src = "/smallpic/specialpic/txt.png"; |
|
185 |
staticUrl = "/smallpic/specialpic/txt.png"; |
|
186 |
} else if ("pdf".equalsIgnoreCase((String) pic.getFileType())) { |
11fbc9
|
187 |
fileType = "pdf"; |
a6a76f
|
188 |
src = "/smallpic/specialpic/pdf.png"; |
F |
189 |
staticUrl = "/smallpic/specialpic/pdf.png"; |
|
190 |
} else if ("docx".equalsIgnoreCase((String) pic.getFileType()) || |
|
191 |
"docm".equalsIgnoreCase((String) pic.getFileType()) || |
|
192 |
"dotx".equalsIgnoreCase((String) pic.getFileType()) || |
|
193 |
"dotm".equalsIgnoreCase((String) pic.getFileType()) || |
|
194 |
"doc".equalsIgnoreCase((String) pic.getFileType())) { |
525d00
|
195 |
fileType = "office"; |
a6a76f
|
196 |
src = "/smallpic/specialpic/doc.png"; |
F |
197 |
staticUrl = "/smallpic/specialpic/doc.png"; |
|
198 |
} else if ("pptx".equalsIgnoreCase((String) pic.getFileType()) || |
|
199 |
"pptm".equalsIgnoreCase((String) pic.getFileType()) || |
|
200 |
"ppsx".equalsIgnoreCase((String) pic.getFileType()) || |
|
201 |
"potx".equalsIgnoreCase((String) pic.getFileType()) || |
|
202 |
"potm".equalsIgnoreCase((String) pic.getFileType()) || |
|
203 |
"ppam".equalsIgnoreCase((String) pic.getFileType()) || |
|
204 |
"ppt".equalsIgnoreCase((String) pic.getFileType())) { |
525d00
|
205 |
fileType = "office"; |
a6a76f
|
206 |
src = "/smallpic/specialpic/ppt.png"; |
F |
207 |
staticUrl = "/smallpic/specialpic/ppt.png"; |
|
208 |
} else if ("xlsx".equalsIgnoreCase((String) pic.getFileType()) || |
|
209 |
"xltx".equalsIgnoreCase((String) pic.getFileType()) || |
|
210 |
"xltm".equalsIgnoreCase((String) pic.getFileType()) || |
|
211 |
"xlsm".equalsIgnoreCase((String) pic.getFileType()) || |
|
212 |
"xlsb".equalsIgnoreCase((String) pic.getFileType()) || |
|
213 |
"xlam".equalsIgnoreCase((String) pic.getFileType()) || |
|
214 |
"xls".equalsIgnoreCase((String) pic.getFileType())) { |
525d00
|
215 |
fileType = "office"; |
a6a76f
|
216 |
staticUrl = "/smallpic/specialpic/excel.png"; |
F |
217 |
} else if ("zip".equalsIgnoreCase((String) pic.getFileType())) { |
|
218 |
fileType = "zip"; |
|
219 |
src = "/smallpic/specialpic/zip.png"; |
|
220 |
staticUrl = "/smallpic/specialpic/zip.png"; |
|
221 |
} else if ("rar".equalsIgnoreCase((String) pic.getFileType())) { |
|
222 |
fileType = "rar"; |
|
223 |
src = "/smallpic/specialpic/rar.png"; |
|
224 |
staticUrl = "/smallpic/specialpic/rar.png"; |
525d00
|
225 |
} else if ("key".equalsIgnoreCase((String) pic.getFileType())) { |
X |
226 |
fileType = "key"; |
|
227 |
src = "/smallpic/specialpic/key.png"; |
|
228 |
staticUrl = "/smallpic/specialpic/key.png"; |
|
229 |
}else if ("mov".equalsIgnoreCase((String) pic.getFileType())) { |
|
230 |
fileType = "video"; |
|
231 |
src = "/smallpic/specialpic/mov.png"; |
|
232 |
staticUrl = "/smallpic/specialpic/mov.png"; |
|
233 |
}else if ("numbers".equalsIgnoreCase((String) pic.getFileType())) { |
|
234 |
fileType = "numbers"; |
|
235 |
src = "/smallpic/specialpic/numbers.png"; |
|
236 |
staticUrl = "/smallpic/specialpic/numbers.png"; |
|
237 |
}else if ("pages".equalsIgnoreCase((String) pic.getFileType())) { |
|
238 |
fileType = "pages"; |
|
239 |
src = "/smallpic/specialpic/pages.png"; |
|
240 |
staticUrl = "/smallpic/specialpic/pages.png"; |
|
241 |
}else if ("png".equalsIgnoreCase((String) pic.getFileType())) { |
|
242 |
fileType = "image"; |
|
243 |
src = "/smallpic/specialpic/png.png"; |
|
244 |
staticUrl = "/smallpic/specialpic/png.png"; |
|
245 |
}else { |
a6a76f
|
246 |
src = "/smallpic/specialpic/unknown.png"; |
F |
247 |
staticUrl = "/smallpic/specialpic/unknown.png"; |
|
248 |
} |
|
249 |
AttachmentPermissionEntity uploadPermissionEntity = new AttachmentPermissionEntity(); |
|
250 |
uploadPermissionEntity.setOriginalFileName(pic.getOriginalFileName()); |
|
251 |
uploadPermissionEntity.setPhysicalFile(pic.getPhysicalFile()); |
|
252 |
uploadPermissionEntity.setStaticUrl(staticUrl); |
|
253 |
String fileSizeStr = pic.getFileSize() + "B"; |
|
254 |
if (pic.getFileSize() != null && pic.getFileSize().longValue() != 0L) { |
|
255 |
Long fileSize = pic.getFileSize(); |
|
256 |
if (fileSize != null) { |
|
257 |
if (fileSize.longValue() < 1024L) { |
|
258 |
fileSizeStr = fileSize.longValue() + "B"; |
|
259 |
} else if (fileSize.longValue() >= 1024L && fileSize.longValue() < 1024L * 1024L) { |
|
260 |
fileSizeStr = (fileSize.longValue() / 1024L) + "KB"; |
|
261 |
} else if (fileSize.longValue() >= 1024L * 1024L && fileSize.longValue() < 1024L * 1024L * 1024L) { |
|
262 |
fileSizeStr = (fileSize.longValue() / (1024L * 1024L)) + "MB"; |
|
263 |
} else if (fileSize.longValue() >= 1024L * 1024L * 1024L && fileSize.longValue() < 1024L * 1024L * 1024L * 1024L) { |
|
264 |
fileSizeStr = (fileSize.longValue() / (1024L * 1024L * 1024L)) + "GB"; |
|
265 |
} else { |
|
266 |
Long fileSizeByMB = (fileSize.longValue() / (1024L * 1024L)); //分开2次计算,因为 1024*1024*1024*1024=?? 会导致内存溢出 2019-12-07 |
|
267 |
fileSizeStr = (fileSizeByMB.longValue() / (1024L * 1024L)) + "TB"; |
|
268 |
} |
|
269 |
} |
|
270 |
} |
|
271 |
uploadPermissionEntity.setFileSizeStr(fileSizeStr); |
|
272 |
uploadPermissionEntity.setFileSize(pic.getFileSize()); |
|
273 |
uploadPermissionEntity.setOrgFileType(pic.getFileType()); |
|
274 |
uploadPermissionEntity.setUnid(pic.getUnid()); |
|
275 |
uploadPermissionEntity.setSeq(pic.getSeq()); |
|
276 |
uploadPermissionEntity.setSrc(src); |
|
277 |
uploadPermissionEntity.setAuthorName(pic.getAuthorName()); |
|
278 |
uploadPermissionEntity.setUploadTime(pic.getUploadTime()); |
|
279 |
uploadPermissionEntity.setUploadTimeStr(pic.getUploadTime() != null ? sdf.format(pic.getUploadTime()) : ""); |
|
280 |
uploadPermissionEntity.setFileType(fileType); |
|
281 |
uploadPermissionEntity.setAuthorCode(pic.getAuthorCode()); |
|
282 |
uploadPermissionEntity.setDocStatus((docstatus == null || "".equalsIgnoreCase(docstatus)) ? 0 : Integer.valueOf(docstatus)); |
|
283 |
uploadPermissionEntity.setEditStatus(uploadPerEntity.getEditStatus()); |
|
284 |
uploadPermissionEntity.setFormid(uploadPerEntity.getFormid()); |
|
285 |
uploadPermissionEntity.setHeadFlag(uploadPerEntity.getHeadFlag()); |
|
286 |
uploadPermissionEntity.setFieldid(uploadPerEntity.getFieldid()); |
|
287 |
uploadPermissionEntity.setUserCode(uploadPerEntity.getUsercode()); |
|
288 |
uploadPermissionEntity.setUserName(session.getAttribute(SessionKey.USER_NAME) + ""); |
|
289 |
uploadPermissionEntity = attachmentPermissionIfc.getAttachmentPermissionEntity(uploadPermissionEntity, usercode, readerUserCodes, (controlType != null && "9".equals(controlType) ? "1" : "3")); |
|
290 |
uploadPermissionEntity.setDomain(domain); |
|
291 |
uploadPermissionEntity.setDbid(dbid); |
|
292 |
uploadPermissionList.add(uploadPermissionEntity); |
|
293 |
} |
|
294 |
} else {//新单时,没有附件的情况下,需要把domain,dbid,usercode,username也传回去 |
|
295 |
AttachmentPermissionEntity uploadPermissionEntity = new AttachmentPermissionEntity(); |
|
296 |
uploadPermissionEntity.setUserCode(uploadPerEntity.getUsercode()); |
|
297 |
uploadPermissionEntity.setUserName(session.getAttribute(SessionKey.USER_NAME) + ""); |
|
298 |
uploadPermissionEntity.setDomain(domain); |
|
299 |
uploadPermissionEntity.setDbid(dbid); |
|
300 |
uploadPermissionEntity.setFormid(uploadPerEntity.getFormid());//新增 |
|
301 |
uploadPermissionEntity.setHeadFlag(uploadPerEntity.getHeadFlag()); |
|
302 |
uploadPermissionEntity.setFieldid(uploadPerEntity.getFieldid()); |
|
303 |
uploadPermissionEntity.setIsNewAttachment(1);//前端通过这个值判断是不是全新附件 |
|
304 |
if (vfiluploads.toLowerCase().startsWith("http://") || vfiluploads.toLowerCase().startsWith("https://")) {//以这个开头的表示有所有的权限 |
|
305 |
uploadPermissionEntity.setHasView(true); |
|
306 |
uploadPermissionEntity.setHasUpdate(true); |
|
307 |
uploadPermissionEntity.setHasDelete(true); |
|
308 |
uploadPermissionEntity.setHasDownload(true); |
|
309 |
uploadPermissionEntity.setAllowDownload(true); |
|
310 |
uploadPermissionEntity.setAllowUpdate(true); |
|
311 |
uploadPermissionEntity.setAllowDelete(true); |
|
312 |
uploadPermissionEntity.setAllowView(true); |
|
313 |
uploadPermissionEntity.setSrc(vfiluploads); |
|
314 |
} else { |
|
315 |
//增加空白单时取默认权限参数 |
|
316 |
uploadPermissionEntity = attachmentPermissionIfc.getAttachmentPermissionEntity(uploadPermissionEntity, usercode, readerUserCodes, (controlType != null && "9".equals(controlType) ? "1" : "3")); |
|
317 |
|
|
318 |
} |
|
319 |
uploadPermissionList.add(uploadPermissionEntity); |
|
320 |
} |
|
321 |
JSONArray json = JSONArray.fromObject(uploadPermissionList); |
|
322 |
this.printJson(response, json.toString()); |
|
323 |
} catch (DataAccessException e) { |
|
324 |
e.printStackTrace(); |
bc34a9
|
325 |
this.printJson(response, (e.getCause() != null ? e.getCause().getMessage() : e.getMessage())); |
a6a76f
|
326 |
} catch (Exception e) { |
F |
327 |
e.printStackTrace(); |
bc34a9
|
328 |
this.printJson(response, (e.getCause() != null ? e.getCause().getMessage() : e.getMessage())); |
a6a76f
|
329 |
} finally { |
F |
330 |
SpObserver.setDBtoInstance(); //增加数据源 , Added by Johns Wang, 2016-07-28 |
|
331 |
} |
|
332 |
} |
|
333 |
|
|
334 |
/** |
|
335 |
* 文本编辑图片显示 指定type类型为3 |
|
336 |
* |
|
337 |
* @param uuid |
|
338 |
* @param request |
|
339 |
* @param response |
|
340 |
* @throws IOException |
|
341 |
*/ |
|
342 |
@RequestMapping("/getImageedit.do") |
|
343 |
@SuppressWarnings("all") |
|
344 |
public void getImageedit(String uuid, HttpServletRequest request, final HttpServletResponse response) |
|
345 |
throws IOException { |
|
346 |
getImage(uuid, 3, request, response); |
|
347 |
} |
|
348 |
|
|
349 |
/** |
|
350 |
* 把图片用流输出到页面显示 type: 9类型 0---单附件的小图 1---单附件的大图 19类型 2---多附件的小图 3---多附件的大图 |
|
351 |
**/ |
|
352 |
@RequestMapping("/attachment/downLoadAttachment.do") |
|
353 |
@CrossOrigin |
|
354 |
@SuppressWarnings("all") |
0c06a4
|
355 |
public void downLoadAttachment(String filePath,String type,final HttpServletRequest request, final HttpServletResponse response) { |
a6a76f
|
356 |
File file = null; |
F |
357 |
String fileName = null; |
|
358 |
|
|
359 |
if (filePath == null || "".equals(filePath)) { |
|
360 |
file = WordToPic.TextToPic("附件路径不能为空", 500, 500, 10); |
|
361 |
downLoadFile(file, response, fileName); |
|
362 |
return; |
|
363 |
} |
|
364 |
; |
|
365 |
ImageFilter imageFilter = (ImageFilter) FactoryBean.getBean("imageFilter"); |
|
366 |
try { |
|
367 |
String rootPath = request.getServletContext().getRealPath("/"); |
|
368 |
if (filePath.indexOf("_") > 0) {//表示非图片附件 |
|
369 |
FileBean fileBean = joinFilePath(filePath); |
|
370 |
file = new File(rootPath + fileBean.getPath()); |
|
371 |
if (file == null || !file.exists()) {//不存在表示需要生成 |
|
372 |
ImageUrlParametersEntity imageUrlParametersEntity = new ImageUrlParametersEntity(); |
|
373 |
imageUrlParametersEntity.setUnids(fileBean.unid); |
|
374 |
imageUrlParametersEntity.setAttachmentPath("attachment"); |
|
375 |
imageUrlParametersEntity.setDbId(fileBean.dbid); |
|
376 |
imageUrlParametersEntity.setFormidPath(fileBean.formid); |
|
377 |
imageUrlParametersEntity.setFileType(fileBean.fileExt); |
|
378 |
imageUrlParametersEntity.setFileName(fileBean.unid + "." + fileBean.fileExt); |
|
379 |
|
|
380 |
ImageEntity imageEntity = imageFilter.getImageEntity(request, filePath, "", "", imageUrlParametersEntity); |
|
381 |
if (imageEntity != null) { |
|
382 |
file = imageEntity.getFile(); |
|
383 |
fileName = imageEntity.getOriginalFileName(); |
|
384 |
} |
|
385 |
} |
|
386 |
} else { |
|
387 |
file = new File(rootPath + filePath); |
|
388 |
} |
|
389 |
if (file != null && file.exists()) { |
|
390 |
if (fileName == null) {//通过unid,seq查询附件的原文件名称和类型 |
|
391 |
if (filePath.indexOf("_") > 0) { |
|
392 |
FileBean fileBean = joinFilePath(filePath); |
|
393 |
filePath = fileBean.getPath(); |
|
394 |
} |
|
395 |
ImageUrlParametersEntity imageUrlParametersEntity = imageFilter.getImageUrlParameters(filePath); |
|
396 |
String unids[] = imageUrlParametersEntity.getUnids().split(SettingKey.NAVSPLIT); |
|
397 |
|
|
398 |
try { |
|
399 |
SpObserver.setDBtoInstance("_" + imageUrlParametersEntity.getDbId()); //切换数据源 |
0c06a4
|
400 |
//这里是pc端处理下载更新次数 xin 2022-12-1 15:27:27 |
X |
401 |
// if(StringUtils.isNotBlank(type) && "pc".equals(type)){ |
|
402 |
// AttachmentOAParam parm = new AttachmentOAParam(); |
|
403 |
// parm.setSeq(Integer.parseInt(unids[1])); |
|
404 |
// parm.setUnid(unids[0]); |
|
405 |
// parm.setType("down"); |
|
406 |
// parm.setUserCode((String) request.getSession().getAttribute(SessionKey.HRCODE)); |
|
407 |
// String memo = attachmentOaIfc.getAttachmentAllow(parm); |
|
408 |
// String[] info = memo.split(";"); |
|
409 |
// if (info.length == 10) { |
|
410 |
// if (Integer.parseInt(info[1]) == -1) {//表示已经没有下载次数 |
|
411 |
// response.getWriter().write("<script >alert(\"" + info[0] + "\")</script >"); |
|
412 |
// return; |
|
413 |
// } |
|
414 |
// } |
|
415 |
// } |
a6a76f
|
416 |
AttachmentEntity attachmentEntity = attachmentIfc.getAttachmentEntity(unids[0], unids[1]); |
F |
417 |
fileName = attachmentEntity.getOriginalFileName(); |
|
418 |
} catch (Exception ex) { |
|
419 |
ex.printStackTrace(); |
|
420 |
} finally { |
|
421 |
SpObserver.setDBtoInstance(); |
|
422 |
} |
359af0
|
423 |
//执行下载更新次数 xin 2022-11-29 15:00:25 |
X |
424 |
|
a6a76f
|
425 |
} |
e3707f
|
426 |
String filenamedisplay = URLEncoder.encode(fileName, "UTF-8");//这个编码不能去掉 不然有些附件下载不了 zip存在中文名称的就下载不了 xin 2023-3-3 14:02:01 |
X |
427 |
if ("FF".equals(getBrowser(request))) { |
|
428 |
//针对火狐浏览器处理方式不一样了 |
|
429 |
filenamedisplay = new String(fileName.getBytes("UTF-8"), "iso-8859-1"); |
|
430 |
} |
a6a76f
|
431 |
downLoadFile(file, response, filenamedisplay); |
F |
432 |
} else { |
|
433 |
file = WordToPic.TextToPic("附件不存在", 500, 500, 10); |
|
434 |
downLoadFile(file, response, fileName); |
|
435 |
} |
|
436 |
} catch (Exception e2) { |
|
437 |
try { |
|
438 |
e2.printStackTrace(); |
|
439 |
if (response != null && response.getWriter() != null) { |
|
440 |
response.getWriter().write((e2.getCause() != null ? e2.getCause().getMessage() : e2.getMessage())); |
|
441 |
} |
|
442 |
} catch (IOException e) { |
|
443 |
e.printStackTrace(); |
|
444 |
} |
|
445 |
} |
|
446 |
} |
|
447 |
|
|
448 |
private FileBean joinFilePath(String filePath) { |
|
449 |
String[] fileInfo = filePath.split("_"); |
|
450 |
FileBean fileBean = new FileBean(); |
|
451 |
fileBean.setDbid(fileInfo[1]); |
|
452 |
fileBean.setFormid(fileInfo[2]); |
|
453 |
fileBean.setUnid(fileInfo[0]); |
|
454 |
fileBean.setFileExt(fileInfo[3]); |
|
455 |
return fileBean; |
|
456 |
} |
|
457 |
|
|
458 |
@Data |
|
459 |
class FileBean { |
|
460 |
String dbid; |
|
461 |
String unid; |
|
462 |
String formid; |
|
463 |
String fileExt; |
|
464 |
String path; |
|
465 |
|
|
466 |
public String getPath() { |
|
467 |
return "/uploads/attachment/" + dbid + "/" + formid + "/" + unid + "." + fileExt; |
|
468 |
} |
|
469 |
} |
|
470 |
|
|
471 |
private String getBrowser(HttpServletRequest request) { |
|
472 |
String UserAgent = request.getHeader("USER-AGENT").toLowerCase(); |
|
473 |
if (UserAgent != null) { |
|
474 |
if (UserAgent.indexOf("msie") >= 0) return "IE"; |
|
475 |
if (UserAgent.indexOf("firefox") >= 0) return "FF"; |
|
476 |
if (UserAgent.indexOf("safari") >= 0) return "SF"; |
|
477 |
} |
|
478 |
return null; |
|
479 |
} |
|
480 |
|
|
481 |
private void downLoadFile(File file, HttpServletResponse response, String fileName) { |
|
482 |
//如果输出的是中文名的文件,在此处就要用URLEncoder.encode方法进行处理 |
|
483 |
// 读取出来输出成流 |
|
484 |
try { |
|
485 |
if (fileName == null) fileName = file.getName(); |
|
486 |
response.setContentType("application/x-msdownload"); |
|
487 |
response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
|
488 |
FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream()); |
|
489 |
} catch (IOException e2) { |
|
490 |
e2.printStackTrace(); |
|
491 |
try { |
|
492 |
response.getWriter().write((e2.getCause() != null ? e2.getCause().getMessage() : e2.getMessage())); |
|
493 |
} catch (IOException ex) { |
|
494 |
ex.printStackTrace(); |
|
495 |
} |
|
496 |
} |
|
497 |
} |
|
498 |
|
|
499 |
/** |
|
500 |
* 把图片用流输出到页面显示 type: 9类型 0---单附件的小图 1---单附件的大图 19类型 2---多附件的小图 3---多附件的大图 |
|
501 |
**/ |
|
502 |
@RequestMapping("/getImage.do") |
|
503 |
@SuppressWarnings("all") |
|
504 |
public void getImage(String uuid, int type, final HttpServletRequest request, final HttpServletResponse response) |
|
505 |
throws IOException { |
|
506 |
//增加数据源 , Added by Johns Wang, 2016-07-28 |
|
507 |
HttpSession session = request.getSession(); |
|
508 |
String dbId = (String) request.getParameter("dbid"); //webscoket 显示图片 |
|
509 |
if (dbId == null || "".equals(dbId)) { |
|
510 |
try { |
|
511 |
DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request); |
|
512 |
dbId = dataSourceEntity.getDbId() + ""; |
|
513 |
} catch (Exception e) { |
|
514 |
e.printStackTrace(); |
|
515 |
File file = null; |
|
516 |
try { |
|
517 |
file = WordToPic.TextToPic((e.getCause() != null ? e.getCause().getMessage() : e.getMessage()), 500, 500, 10); |
|
518 |
if (file != null && file.exists()) { |
|
519 |
response.setContentType("application/x-msdownload"); |
|
520 |
//如果输出的是中文名的文件,在此处就要用URLEncoder.encode方法进行处理 |
|
521 |
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8")); |
|
522 |
// 读取出来输出成流 |
|
523 |
//is = defaultLobHandler.getBlobAsBinaryStream(rs, 1); //从数据库取值,下载 |
|
524 |
FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream()); |
|
525 |
} else { |
|
526 |
response.getWriter().write((e.getCause() != null ? e.getCause().getMessage() : e.getMessage())); |
|
527 |
} |
|
528 |
} catch (Exception e2) { |
|
529 |
response.getWriter().write((e2.getCause() != null ? e2.getCause().getMessage() : e2.getMessage())); |
|
530 |
} finally { |
|
531 |
|
|
532 |
if (file != null && file.exists() && file.isFile()) { |
|
533 |
log.info("del>>userCode:" + request.getSession().getAttribute(SessionKey.USERCODE) + "|dbid:" + dbId + "|" + file.getAbsolutePath()); |
|
534 |
file.delete(); |
|
535 |
} |
|
536 |
} |
|
537 |
|
|
538 |
return; |
|
539 |
} finally { |
|
540 |
SpObserver.setDBtoInstance(); |
|
541 |
} |
|
542 |
} |
|
543 |
|
|
544 |
|
|
545 |
if (dbId == null || "".equals(dbId)) { |
|
546 |
System.out.println(this.getClass() + " getImage() 没有找到数据源,可能会话已过期,需要重新登录 uuid=" + uuid); |
|
547 |
File file = null; |
|
548 |
try { |
|
549 |
file = WordToPic.TextToPic("可能会话已过期,请重新登录", 500, 500, 10); |
|
550 |
if (file != null && file.exists()) { |
|
551 |
response.setContentType("application/x-msdownload"); |
|
552 |
//如果输出的是中文名的文件,在此处就要用URLEncoder.encode方法进行处理 |
|
553 |
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8")); |
|
554 |
// 读取出来输出成流 |
|
555 |
//is = defaultLobHandler.getBlobAsBinaryStream(rs, 1); //从数据库取值,下载 |
|
556 |
FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream()); |
|
557 |
} |
|
558 |
} finally { |
|
559 |
if (file != null && file.exists() && file.isFile()) { |
|
560 |
file.delete(); |
|
561 |
} |
|
562 |
} |
|
563 |
|
|
564 |
return; |
|
565 |
} |
|
566 |
|
|
567 |
EnImageMD5 de = new EnImageMD5(); |
|
568 |
String uuidmd5 = uuid; |
|
569 |
if (uuidmd5.indexOf(";") < 0) { |
|
570 |
uuidmd5 = de.convertMD5(uuid); |
|
571 |
} |
|
572 |
|
|
573 |
int seq = 0; |
|
574 |
String whereStr = ""; |
|
575 |
try { |
|
576 |
SpObserver.setDBtoInstance("_" + dbId); //切换数据源 //增加数据源 , Added by Johns Wang, 2016-07-28 |
|
577 |
|
|
578 |
if (uuidmd5.indexOf(";") != -1) { //附件上传图片处理 |
|
579 |
String[] uuidseq = uuidmd5.split(";"); |
|
580 |
uuid = uuidseq[0]; |
|
581 |
seq = Integer.parseInt(uuidseq[1]); |
|
582 |
whereStr = " and seq=" + seq; |
|
583 |
} |
|
584 |
if (uuid.indexOf(";") != -1) { |
|
585 |
String[] uuidseq = uuid.split(";"); |
|
586 |
uuid = uuidseq[0]; |
|
587 |
whereStr = " and seq=" + uuidseq[1]; |
|
588 |
} |
|
589 |
|
|
590 |
if (uuid == null || "".equalsIgnoreCase(uuid)) |
|
591 |
return; |
|
592 |
|
|
593 |
String sql = " set nocount on \n" |
|
594 |
+ " declare @unid varchar(50) = ? \n"; |
|
595 |
|
|
596 |
if (type == 0) { |
|
597 |
sql += " SELECT top 1 SmallPicture,FileType,OriginalFileName FROM _sys_Attachment9 WHERE unid= @unid " + whereStr + " \n"; |
|
598 |
} else if (type == 1) { |
|
599 |
sql += " SELECT top 1 OriginalPicture,FileType,OriginalFileName FROM _sys_Attachment9 WHERE unid= @unid " + whereStr + "\n"; |
|
600 |
} else if (type == 2) { |
|
601 |
sql += " SELECT top 1 SmallPicture,FileType,OriginalFileName FROM _sys_Attachment WHERE unid= @unid " + whereStr + "\n"; |
|
602 |
} else if (type == 3) { |
|
603 |
sql += " SELECT top 1 OriginalPicture,FileType,OriginalFileName FROM _sys_Attachment WHERE unid= @unid " + whereStr + "\n"; |
|
604 |
} |
|
605 |
BaseService baseServer = (BaseService) FactoryBean.getBean("BaseService"); |
|
606 |
|
|
607 |
// PrintWriter out = response.getWriter(); |
|
608 |
final String myUnid = uuid; |
|
609 |
baseServer.getJdbcTemplate().query(sql, new Object[]{uuid}, |
|
610 |
new AbstractLobStreamingResultSetExtractor() { // ② 匿名内部类 |
|
611 |
// ③ 处理未找到数据行的情况 |
|
612 |
protected void handleNoRowFound() throws LobRetrievalFailureException { |
|
613 |
System.out.println("查找不到附件(uuid: " + myUnid + " , dbid: " + SpObserver.getCurrentInstance() + " )!"); |
|
614 |
} |
|
615 |
|
|
616 |
// ④ 以流的方式处理 LOB 字段 |
|
617 |
public void streamData(ResultSet rs) throws SQLException, IOException { |
|
618 |
InputStream is = null; |
|
619 |
String fileName = rs.getString("OriginalFileName"); |
|
620 |
String fileType = rs.getString("FileType"); |
|
621 |
try { |
|
622 |
/*if ("jpg".equalsIgnoreCase(rs.getString(2)) |
|
623 |
||"jpeg".equalsIgnoreCase(fileType) |
|
624 |
|| "png".equalsIgnoreCase(fileType) |
|
625 |
|| "gif".equalsIgnoreCase(fileType) |
|
626 |
|| "bmp".equalsIgnoreCase(fileType)) { |
|
627 |
|
|
628 |
String type = "image/"; |
|
629 |
response.setContentType(type + fileType); |
|
630 |
} else { // 附件,不是图片 |
|
631 |
response.setContentType("application/octet-stream"); |
|
632 |
} |
|
633 |
*/ |
|
634 |
|
|
635 |
if ("mp4".equalsIgnoreCase(fileType) |
|
636 |
|| "avi".equalsIgnoreCase(fileType) |
|
637 |
|| "asf".equalsIgnoreCase(fileType) |
|
638 |
|| "wmv".equalsIgnoreCase(fileType) |
|
639 |
|| "wma".equalsIgnoreCase(fileType) |
|
640 |
|| "mpeg".equalsIgnoreCase(fileType) |
|
641 |
|| "mpg".equalsIgnoreCase(fileType) |
|
642 |
|| "dat".equalsIgnoreCase(fileType) |
|
643 |
|| "swf".equalsIgnoreCase(fileType) |
|
644 |
|| "mts".equalsIgnoreCase(fileType) |
|
645 |
|| "aam".equalsIgnoreCase(fileType) |
|
646 |
|| "ra".equalsIgnoreCase(fileType) |
|
647 |
|| "ra".equalsIgnoreCase(fileType) |
|
648 |
|| "rm".equalsIgnoreCase(fileType) |
|
649 |
|| "rmvb".equalsIgnoreCase(fileType) |
|
650 |
|| "mov".equalsIgnoreCase(fileType) |
|
651 |
|| "qt".equalsIgnoreCase(fileType)) { |
|
652 |
//response.setContentType("video/mp4"); |
|
653 |
response.setContentType("application/octet-stream"); //流:边播边下载 |
|
654 |
} else { |
|
655 |
response.setContentType("application/x-msdownload"); |
|
656 |
} |
|
657 |
//response.setContentType("application/x-msdownload"); |
|
658 |
//如果输出的是中文名的文件,在此处就要用URLEncoder.encode方法进行处理 |
|
659 |
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); |
|
660 |
// 读取出来输出成流 |
|
661 |
is = defaultLobHandler.getBlobAsBinaryStream(rs, 1); //从数据库取值,下载 |
|
662 |
OutputStream output = response.getOutputStream(); |
|
663 |
try { |
|
664 |
FileCopyUtils.copy(is, output); |
|
665 |
} catch (ClientAbortException | IllegalStateException e) { |
|
666 |
System.out.println(getClass() + " unid:" + myUnid + ", Error:" + e.getMessage()); |
|
667 |
} finally { |
|
668 |
//output.flush(); |
|
669 |
//output.close(); |
|
670 |
} |
|
671 |
|
|
672 |
} catch (Exception e) { |
|
673 |
e.printStackTrace(); |
|
674 |
|
|
675 |
File file = null; |
|
676 |
|
|
677 |
try { |
|
678 |
file = WordToPic.TextToPic((e.getCause() != null ? e.getCause().getMessage() : e.getMessage()), 500, 500, 10); |
|
679 |
if (file != null && file.exists()) { |
|
680 |
response.setContentType("application/x-msdownload"); |
|
681 |
//如果输出的是中文名的文件,在此处就要用URLEncoder.encode方法进行处理 |
|
682 |
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8")); |
|
683 |
// 读取出来输出成流 |
|
684 |
//is = defaultLobHandler.getBlobAsBinaryStream(rs, 1); //从数据库取值,下载 |
|
685 |
FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream()); |
|
686 |
|
|
687 |
} else { |
|
688 |
response.getWriter().write((e.getCause() != null ? e.getCause().getMessage() : e.getMessage())); |
|
689 |
} |
|
690 |
} catch (Exception e2) { |
|
691 |
response.getWriter().write((e2.getCause() != null ? e2.getCause().getMessage() : e2.getMessage())); |
|
692 |
} finally { |
|
693 |
|
|
694 |
if (file != null && file.exists() && file.isFile()) { |
|
695 |
file.delete(); |
|
696 |
} |
|
697 |
} |
|
698 |
|
|
699 |
response.flushBuffer(); |
|
700 |
} finally { |
|
701 |
is.close(); |
|
702 |
|
|
703 |
} |
|
704 |
} |
|
705 |
}); |
|
706 |
} catch (DataAccessException e) { |
|
707 |
System.out.println(this.getClass() + " getImage() " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()) + "【数据源:" + SpObserver.getCurrentInstance() + "】,uuid=" + uuid + whereStr); |
|
708 |
e.printStackTrace(); |
|
709 |
File file = null; |
|
710 |
try { |
|
711 |
file = WordToPic.TextToPic((e.getCause() != null ? e.getCause().getMessage() : e.getMessage()), 500, 500, 10); |
|
712 |
if (file != null && file.exists()) { |
|
713 |
response.setContentType("application/x-msdownload"); |
|
714 |
//如果输出的是中文名的文件,在此处就要用URLEncoder.encode方法进行处理 |
|
715 |
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8")); |
|
716 |
// 读取出来输出成流 |
|
717 |
//is = defaultLobHandler.getBlobAsBinaryStream(rs, 1); //从数据库取值,下载 |
|
718 |
FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream()); |
|
719 |
} else { |
|
720 |
response.getWriter().write((e.getCause() != null ? e.getCause().getMessage() : e.getMessage())); |
|
721 |
} |
|
722 |
} catch (Exception e2) { |
|
723 |
response.getWriter().write((e2.getCause() != null ? e2.getCause().getMessage() : e2.getMessage())); |
|
724 |
} finally { |
|
725 |
|
|
726 |
if (file != null && file.exists() && file.isFile()) { |
|
727 |
file.delete(); |
|
728 |
} |
|
729 |
} |
|
730 |
|
|
731 |
return; |
|
732 |
} catch (Exception e) { |
|
733 |
System.out.println(this.getClass() + " getImage() " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()) + "【数据源:" + SpObserver.getCurrentInstance() + "】,uuid=" + uuid + whereStr); |
|
734 |
e.printStackTrace(); |
|
735 |
File file = null; |
|
736 |
try { |
|
737 |
file = WordToPic.TextToPic((e.getCause() != null ? e.getCause().getMessage() : e.getMessage()), 500, 500, 10); |
|
738 |
if (file != null && file.exists()) { |
|
739 |
response.setContentType("application/x-msdownload"); |
|
740 |
//如果输出的是中文名的文件,在此处就要用URLEncoder.encode方法进行处理 |
|
741 |
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8")); |
|
742 |
// 读取出来输出成流 |
|
743 |
//is = defaultLobHandler.getBlobAsBinaryStream(rs, 1); //从数据库取值,下载 |
|
744 |
FileCopyUtils.copy(new FileInputStream(file), response.getOutputStream()); |
|
745 |
} else { |
|
746 |
response.getWriter().write((e.getCause() != null ? e.getCause().getMessage() : e.getMessage())); |
|
747 |
} |
|
748 |
} catch (Exception e2) { |
|
749 |
response.getWriter().write((e2.getCause() != null ? e2.getCause().getMessage() : e2.getMessage())); |
|
750 |
} finally { |
|
751 |
|
|
752 |
if (file != null && file.exists() && file.isFile()) { |
|
753 |
file.delete(); |
|
754 |
} |
|
755 |
} |
|
756 |
|
|
757 |
return; |
|
758 |
} finally { |
|
759 |
SpObserver.setDBtoInstance(); //增加数据源 , Added by Johns Wang, 2016-07-28 |
|
760 |
response.flushBuffer(); |
|
761 |
} |
|
762 |
} |
|
763 |
|
|
764 |
/** |
|
765 |
* 保存富文本框编辑控件图片上传 |
|
766 |
* |
|
767 |
* @param request |
|
768 |
* @param response |
|
769 |
* @throws IOException |
|
770 |
*/ |
|
771 |
@RequestMapping("/ckeditor_up.do") |
3decaa
|
772 |
@ResponseBody |
X |
773 |
public CallBackMsg ckeditor_up(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
774 |
CallBackMsg msg = new CallBackMsg(); |
a6a76f
|
775 |
try { |
3decaa
|
776 |
MultipartHttpServletRequest multipartRequest = null; |
a6a76f
|
777 |
try { |
3decaa
|
778 |
multipartRequest = (MultipartHttpServletRequest) request; |
X |
779 |
} catch (ClassCastException e) { |
|
780 |
MultipartResolver resolver = new CommonsMultipartResolver(request.getSession().getServletContext()); |
a6a76f
|
781 |
multipartRequest = resolver.resolveMultipart(request); |
3decaa
|
782 |
} |
X |
783 |
MultipartFile file = multipartRequest.getFile("img"); |
a6a76f
|
784 |
// 保存 |
F |
785 |
if (file.getSize() > 0) { |
3decaa
|
786 |
HttpSession session = request.getSession(); |
X |
787 |
AttachmentEntity attachmentEntity = new AttachmentEntity(); |
|
788 |
Integer formid=Integer.parseInt(multipartRequest.getParameter("formid")); |
a6a76f
|
789 |
attachmentEntity.setOriginalFileName(file.getOriginalFilename()); |
3decaa
|
790 |
attachmentEntity.setDoccode(multipartRequest.getParameter("doccode")); |
X |
791 |
attachmentEntity.setFormId(formid); |
|
792 |
attachmentEntity.setFieldId(multipartRequest.getParameter("fieldid")); |
|
793 |
attachmentEntity.setUnid(UUID.randomUUID().toString().toUpperCase()); |
|
794 |
attachmentEntity.setFileType(file.getContentType()); |
|
795 |
attachmentEntity.setFileSize(file.getSize()); |
|
796 |
attachmentEntity.setAuthorCode(session.getAttribute(SessionKey.USERCODE) + ""); |
|
797 |
attachmentEntity.setAuthorName(session.getAttribute(SessionKey.USERNAME) + ""); |
|
798 |
attachmentEntity.setUploadTime(new Date()); |
|
799 |
attachmentEntity.setLastUpdateTime(new Date()); |
|
800 |
attachmentEntity.setRowId(""); |
|
801 |
String dbid = (String) session.getAttribute(SessionKey.DATA_BASE_ID); |
|
802 |
SpObserver.setDBtoInstance("_" + dbid); //切换数据源 |
a6a76f
|
803 |
//上传图片 |
F |
804 |
AttachmentWhereEntity attachmentWhereEntity = attachmentIfc.saveAttachment(attachmentEntity, file, "3"); |
3decaa
|
805 |
if(attachmentWhereEntity.getSeq()!=null && !"".equals(attachmentWhereEntity.getSeq())){ |
X |
806 |
String value=AttachmentConfig.get("attachment.server")+"/uploads/attachment/"+dbid+"/"+formid+"/"+attachmentWhereEntity.getUnid()+"."+attachmentWhereEntity.getFileType(); |
|
807 |
msg.setOk(value); |
|
808 |
// msg.setOk("/getImageedit.do?uuid=" + attachmentWhereEntity.getUnid() + ";" + attachmentWhereEntity.getSeq() + "&filetype=" + attachmentWhereEntity.getFileType() + "&type=2"); |
|
809 |
}else{ |
|
810 |
msg.setFail("糟糕!图片的seq获取不到值"); |
|
811 |
} |
a6a76f
|
812 |
} |
F |
813 |
} catch (Exception e) { |
|
814 |
e.printStackTrace(); |
3decaa
|
815 |
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); |
a6a76f
|
816 |
} finally { |
F |
817 |
SpObserver.setDBtoInstance(); |
|
818 |
} |
3decaa
|
819 |
return msg; |
a6a76f
|
820 |
} |
F |
821 |
|
|
822 |
public PostBeanInfo prossParameter(HttpServletRequest request) { |
|
823 |
PostBeanInfo postBeanInfo = new PostBeanInfo(); |
|
824 |
String usercode = request.getParameter("usercode"); |
|
825 |
String username = request.getParameter("username"); |
|
826 |
String dbid = request.getParameter("dbid"); |
|
827 |
String curUsercode = request.getParameter("curUsercode"); |
|
828 |
String curUsername = request.getParameter("curUsername"); |
|
829 |
String rowid = request.getParameter("rowid"); |
4442a8
|
830 |
String detailRowid=request.getParameter("detailrowid"); |
a6a76f
|
831 |
String docCode = request.getParameter("doccode"); |
F |
832 |
String formid = request.getParameter("formid"); |
|
833 |
String fieldid = request.getParameter("fieldid"); |
|
834 |
Integer ishd = org.apache.commons.lang3.StringUtils.isBlank(request.getParameter("ishd")) ? null : Integer.valueOf(request.getParameter("ishd")); |
|
835 |
Integer is1 = org.apache.commons.lang3.StringUtils.isBlank(request.getParameter("is1")) ? null : Integer.valueOf(request.getParameter("is1")); |
|
836 |
Integer is8 = org.apache.commons.lang3.StringUtils.isBlank(request.getParameter("is8")) ? null : Integer.valueOf(request.getParameter("is8")); |
|
837 |
Integer is16 = org.apache.commons.lang3.StringUtils.isBlank(request.getParameter("is16")) ? null : Integer.valueOf(request.getParameter("is16")); |
|
838 |
int type = 0; |
|
839 |
try { |
|
840 |
|
|
841 |
type = request.getParameter("type") == null ? 0 : Integer.parseInt(request.getParameter("type")); |
|
842 |
|
|
843 |
} catch (Exception e) { |
|
844 |
throw new ApplicationException("type参数转换出错:" + this.getErrorMsg(e)); |
|
845 |
} |
|
846 |
if (dbid == null) { |
|
847 |
throw new ApplicationException("dbid不能为空"); |
|
848 |
} |
|
849 |
if (dbid.length() < 32) { |
|
850 |
throw new ApplicationException("dbid未有加密传输"); |
|
851 |
} |
|
852 |
try { |
|
853 |
dbid = ChangePassword.getDecryptPassword(EncodeUtil.replaceUrlChar(dbid)); |
|
854 |
} catch (Exception ex) { |
|
855 |
throw new ApplicationException("dbid解密:" + this.getErrorMsg(ex)); |
|
856 |
} |
|
857 |
if (usercode == null || usercode.length() < 32) { |
|
858 |
throw new ApplicationException("usercode不能为空"); |
|
859 |
} |
|
860 |
try { |
|
861 |
usercode = ChangePassword.getDecryptPassword(EncodeUtil.replaceUrlChar(usercode)); |
|
862 |
} catch (Exception ex) { |
|
863 |
throw new ApplicationException("usercode解密:" + this.getErrorMsg(ex)); |
|
864 |
} |
|
865 |
try { |
|
866 |
if (username != null && !"".equals(username)) { |
|
867 |
username = ChangePassword.getDecryptPassword(EncodeUtil.replaceUrlChar(username)); |
|
868 |
} |
|
869 |
} catch (Exception ex) { |
|
870 |
throw new ApplicationException("username解密:" + this.getErrorMsg(ex)); |
|
871 |
} |
|
872 |
|
|
873 |
try { |
|
874 |
if (curUsercode != null && !"".equals(curUsercode)) { |
|
875 |
curUsercode = ChangePassword.getDecryptPassword(EncodeUtil.replaceUrlChar(curUsercode)); |
|
876 |
} |
|
877 |
} catch (Exception ex) { |
|
878 |
throw new ApplicationException("curUsercode解密:" + this.getErrorMsg(ex)); |
|
879 |
} |
|
880 |
|
|
881 |
try { |
|
882 |
if (curUsername != null && !"".equals(curUsername)) { |
|
883 |
curUsername = ChangePassword.getDecryptPassword(EncodeUtil.replaceUrlChar(curUsername)); |
|
884 |
} |
|
885 |
} catch (Exception ex) { |
|
886 |
throw new ApplicationException("curUsername解密:" + this.getErrorMsg(ex)); |
|
887 |
} |
|
888 |
postBeanInfo.setDbid(dbid); |
|
889 |
postBeanInfo.setCurUsercode(curUsercode); |
|
890 |
postBeanInfo.setCurUsername(curUsername); |
|
891 |
postBeanInfo.setUsercode(usercode); |
|
892 |
postBeanInfo.setUsername(username); |
|
893 |
postBeanInfo.setType(type); |
|
894 |
postBeanInfo.setIshd(ishd); |
|
895 |
postBeanInfo.setRowid(rowid); |
13a943
|
896 |
postBeanInfo.setDetailrowid(detailRowid); |
a6a76f
|
897 |
postBeanInfo.setDoccode(docCode); |
F |
898 |
postBeanInfo.setFormid(StringUtils.isNotBlank(formid)?Integer.valueOf(formid):0); |
|
899 |
postBeanInfo.setFieldid(fieldid); |
|
900 |
postBeanInfo.setIs8(is8); |
|
901 |
postBeanInfo.setIs1(is1); |
|
902 |
postBeanInfo.setIs16(is16); |
|
903 |
return postBeanInfo; |
|
904 |
} |
|
905 |
|
|
906 |
/** |
|
907 |
* 删除文件 |
|
908 |
* |
|
909 |
* @param request |
|
910 |
* @param response |
|
911 |
*/ |
|
912 |
|
|
913 |
@RequestMapping("/attachment/deleteAttachment.do") |
|
914 |
@CrossOrigin |
|
915 |
public void deleteAttachment(HttpServletRequest request, HttpServletResponse response) { |
|
916 |
String str_formid = request.getParameter("formid"); |
|
917 |
String unid = request.getParameter("unid"); |
|
918 |
String seq = request.getParameter("seq"); |
|
919 |
String type = request.getParameter("type"); |
|
920 |
String fieldid = request.getParameter("fieldid"); |
|
921 |
String docstatus = request.getParameter("docstatus"); |
|
922 |
String isHd = request.getParameter("ishd"); //是否主表 |
|
923 |
HttpSession session = request.getSession(); |
|
924 |
String usercode = request.getParameter("usercode"); |
|
925 |
String dbid = request.getParameter("dbid"); |
|
926 |
if (dbid == null) { |
|
927 |
dbid = (String) session.getAttribute(SessionKey.DATA_BASE_ID); |
|
928 |
} |
|
929 |
String readerUserCodes = request.getParameter("readerusercodes"); |
|
930 |
|
|
931 |
int formid = -1; |
|
932 |
try { |
|
933 |
formid = Integer.parseInt(str_formid); |
|
934 |
} catch (Exception e) { |
|
935 |
return; |
|
936 |
} |
|
937 |
// @SuppressWarnings("unchecked") |
|
938 |
// Map<String, Map<String, Object>> perssion = (Map<String, Map<String, Object>>) session.getAttribute(SessionKey.PERSSION); |
|
939 |
// if (!perssion.containsKey(formid+"")) {// 判断是否有该功能号的权限 |
|
940 |
// Map<String,String> m=new HashMap<String,String>(); |
|
941 |
// m.put("error", "没权限,请联系上传者!"); |
|
942 |
// printJson(response, GridUtils.toJson(m)); |
|
943 |
// return; |
|
944 |
// } |
|
945 |
|
|
946 |
try { |
|
947 |
SpObserver.setDBtoInstance("_" + dbid); //切换数据源 |
|
948 |
|
|
949 |
Map<String, Object> fieldInfo = null; |
|
950 |
if ("2".contentEquals(isHd)) {//判断为3类型执行 |
|
951 |
fieldInfo = attachmentIfc.getUploadFieldInfo3(formid, fieldid); |
|
952 |
isHd = "1";//还原成取主表的表名 |
|
953 |
} else { |
|
954 |
fieldInfo = attachmentIfc.getUploadFieldInfo(formid, fieldid, "1".equals(isHd) ? true : false); |
|
955 |
} |
|
956 |
if (fieldInfo == null) { |
|
957 |
print(response, "配置有误," + formid + "功能号不存在该上传图片控件!"); |
|
958 |
return; |
|
959 |
} |
|
960 |
String tableName = attachmentIfc.getPanelTableName(formid, "1".equals(isHd) ? true : false); |
|
961 |
if (StringUtils.isBlank(tableName)) { |
|
962 |
print(response, "表名为空!"); |
|
963 |
return; |
|
964 |
} |
|
965 |
AttachmentPermissionIfc attachmentPermissionIfc = (AttachmentPermissionIfc) FactoryBean.getBean("AttachmentPermissionImpl"); |
|
966 |
AttachmentEntity attachmentEntity = attachmentIfc.getAttachmentEntity(unid, Integer.valueOf(seq), type); |
|
967 |
if (attachmentEntity != null) { |
|
968 |
AttachmentPermissionEntity uploadPermissionEntity = new AttachmentPermissionEntity(); |
|
969 |
uploadPermissionEntity.setUnid(unid); |
|
970 |
uploadPermissionEntity.setSeq(Integer.valueOf(seq)); |
|
971 |
uploadPermissionEntity.setDocStatus((docstatus == null || "".equalsIgnoreCase(docstatus)) ? 0 : Integer.valueOf(docstatus)); |
|
972 |
uploadPermissionEntity.setAuthorCode(attachmentEntity.getAuthorCode()); |
|
973 |
uploadPermissionEntity = attachmentPermissionIfc.getAttachmentPermissionEntity(uploadPermissionEntity, usercode, readerUserCodes, type); |
|
974 |
if (!uploadPermissionEntity.isAllowDelete()) { |
|
975 |
Map<String, String> m = new HashMap<String, String>(); |
|
976 |
m.put("error", "没权限,请联系上传者!"); |
|
977 |
printJson(response, GridUtils.toJson(m)); |
|
978 |
return; |
|
979 |
} |
|
980 |
//拼接附件的URL,磁盘上删除附件 |
|
981 |
|
|
982 |
String path = session.getServletContext().getRealPath("/") + "/uploads/attachment/" + dbid + "/" + formid + "/" + unid + SettingKey.NAVSPLIT + seq + "." + attachmentEntity.getFileType();//原图 |
|
983 |
File file = new File(path); |
|
984 |
if (file != null && file.exists() && file.isFile()) { |
|
985 |
file.delete(); |
|
986 |
} |
|
987 |
if (attachmentEntity.getFileType() != null && (attachmentEntity.getFileType().matches("jpg|png|gif|bmp"))) {//小图且是图片 |
|
988 |
path = session.getServletContext().getRealPath("/") + "/uploads/attachment/" + dbid + "/" + formid + "/" + unid + SettingKey.NAVSPLIT + seq + "_80x80." + attachmentEntity.getFileType(); |
|
989 |
file = new File(path); |
|
990 |
if (file != null && file.exists() && file.isFile()) { |
|
991 |
file.delete(); |
|
992 |
} |
|
993 |
} |
|
994 |
} |
|
995 |
|
|
996 |
String acType = "删除"; |
|
997 |
String curUsercode = request.getParameter("curUsercode"); |
|
998 |
if (curUsercode == null) { |
|
999 |
curUsercode = session.getAttribute(SessionKey.USERCODE) + ""; |
|
1000 |
} |
|
1001 |
String curUsername = request.getParameter("curUsername"); |
|
1002 |
if (curUsername == null) { |
|
1003 |
curUsername = session.getAttribute(SessionKey.USERNAME) + ""; |
|
1004 |
} |
|
1005 |
String ip = request.getParameter("ip"); |
|
1006 |
if (ip == null) { |
|
1007 |
ip = getIp(request); |
|
1008 |
} |
2b4227
|
1009 |
PicEntity picEntity=new PicEntity(); |
F |
1010 |
picEntity.setUuid(unid); |
|
1011 |
picEntity.setSeq(Integer.parseInt(seq)); |
|
1012 |
picEntity.setType(2); |
|
1013 |
picEntity.setUserCode(curUsercode); |
|
1014 |
picEntity.setUserName(curUsername); |
|
1015 |
picEntity.setIp(ip); |
|
1016 |
picEntity.setField(fieldid); |
|
1017 |
picEntity.setFormId(str_formid); |
|
1018 |
boolean success = attachmentIfc.deleteAttachment(picEntity); |
a6a76f
|
1019 |
if (success) { |
F |
1020 |
printJson(response, "{\"status\":\"success\"}"); |
|
1021 |
} else { |
|
1022 |
printJson(response, "{\"status\":\"failed\"}"); |
|
1023 |
} |
|
1024 |
// print(response,"<script type='text/javascript'>alert('删除成功');window.returnValue='success';window.close();</script>"); |
|
1025 |
} catch (Exception e) { |
|
1026 |
e.printStackTrace(); |
|
1027 |
// print(response, "删除图片出现异常!"); |
|
1028 |
Map<String, String> m = new HashMap<String, String>(); |
|
1029 |
m.put("error", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); //删除图片报错的错误输出 |
|
1030 |
printJson(response, GridUtils.toJson(m)); |
|
1031 |
} finally { |
|
1032 |
SpObserver.setDBtoInstance(); |
|
1033 |
} |
|
1034 |
} |
|
1035 |
|
|
1036 |
@RequestMapping("/attachment/deleteAttachmentV2.do") |
|
1037 |
@CrossOrigin |
|
1038 |
public void deleteAttachmentV2(HttpServletRequest request, HttpServletResponse response) { |
|
1039 |
try { |
|
1040 |
String str_formid = request.getParameter("formid"); |
|
1041 |
String unid = request.getParameter("unid"); |
|
1042 |
String seq = request.getParameter("seq"); |
|
1043 |
String type = request.getParameter("type"); |
|
1044 |
String fieldid = request.getParameter("fieldid"); |
|
1045 |
String docstatus = request.getParameter("docstatus"); |
|
1046 |
String isHd = request.getParameter("ishd"); //是否主表 |
|
1047 |
HttpSession session = request.getSession(); |
|
1048 |
PostBeanInfo postBeanInfo = this.prossParameter(request); |
|
1049 |
String readerUserCodes = request.getParameter("readerusercodes"); |
|
1050 |
|
|
1051 |
int formid = -1; |
|
1052 |
try { |
|
1053 |
formid = Integer.parseInt(str_formid); |
|
1054 |
} catch (Exception e) { |
|
1055 |
return; |
|
1056 |
} |
|
1057 |
SpObserver.setDBtoInstance("_" + postBeanInfo.getDbid()); //切换数据源 |
|
1058 |
|
|
1059 |
Map<String, Object> fieldInfo = null; |
|
1060 |
if ("2".contentEquals(isHd)) {//判断为3类型执行 |
|
1061 |
fieldInfo = attachmentIfc.getUploadFieldInfo3(formid, fieldid); |
|
1062 |
isHd = "1";//还原成取主表的表名 |
|
1063 |
} else { |
|
1064 |
fieldInfo = attachmentIfc.getUploadFieldInfo(formid, fieldid, "1".equals(isHd) ? true : false); |
|
1065 |
} |
|
1066 |
if (fieldInfo == null) { |
|
1067 |
print(response, "配置有误," + formid + "功能号不存在该上传图片控件!"); |
|
1068 |
return; |
|
1069 |
} |
|
1070 |
String tableName = attachmentIfc.getPanelTableName(formid, "1".equals(isHd) ? true : false); |
|
1071 |
if (StringUtils.isBlank(tableName)) { |
|
1072 |
print(response, "表名为空!"); |
|
1073 |
return; |
|
1074 |
} |
|
1075 |
AttachmentPermissionIfc attachmentPermissionIfc = (AttachmentPermissionIfc) FactoryBean.getBean("AttachmentPermissionImpl"); |
|
1076 |
AttachmentEntity attachmentEntity = attachmentIfc.getAttachmentEntity(unid, Integer.valueOf(seq), type); |
|
1077 |
if (attachmentEntity != null) { |
|
1078 |
AttachmentPermissionEntity uploadPermissionEntity = new AttachmentPermissionEntity(); |
|
1079 |
uploadPermissionEntity.setUnid(unid); |
|
1080 |
uploadPermissionEntity.setSeq(Integer.valueOf(seq)); |
|
1081 |
uploadPermissionEntity.setDocStatus((docstatus == null || "".equalsIgnoreCase(docstatus)) ? 0 : Integer.valueOf(docstatus)); |
|
1082 |
uploadPermissionEntity.setAuthorCode(attachmentEntity.getAuthorCode()); |
|
1083 |
uploadPermissionEntity = attachmentPermissionIfc.getAttachmentPermissionEntity(uploadPermissionEntity, postBeanInfo.getUsercode(), readerUserCodes, type); |
|
1084 |
if (!uploadPermissionEntity.isAllowDelete()) { |
|
1085 |
Map<String, String> m = new HashMap<String, String>(); |
e44ea2
|
1086 |
m.put("error", "没删除权限,请联系上传者!"); |
a6a76f
|
1087 |
printJson(response, GridUtils.toJson(m)); |
F |
1088 |
return; |
|
1089 |
} |
|
1090 |
//拼接附件的URL,磁盘上删除附件 |
|
1091 |
|
|
1092 |
String path = session.getServletContext().getRealPath("/") + "/uploads/attachment/" + postBeanInfo.getDbid() + "/" + formid + "/" + unid + SettingKey.NAVSPLIT + seq + "." + attachmentEntity.getFileType();//原图 |
|
1093 |
File file = new File(path); |
|
1094 |
if (file != null && file.exists() && file.isFile()) { |
|
1095 |
file.delete(); |
|
1096 |
} |
|
1097 |
if (attachmentEntity.getFileType() != null && (attachmentEntity.getFileType().matches("jpg|png|gif|bmp"))) {//小图且是图片 |
|
1098 |
path = session.getServletContext().getRealPath("/") + "/uploads/attachment/" + postBeanInfo.getDbid() + "/" + formid + "/" + unid + SettingKey.NAVSPLIT + seq + "_80x80." + attachmentEntity.getFileType(); |
|
1099 |
file = new File(path); |
|
1100 |
if (file != null && file.exists() && file.isFile()) { |
|
1101 |
file.delete(); |
|
1102 |
} |
|
1103 |
} |
|
1104 |
} |
|
1105 |
|
|
1106 |
String acType = "删除"; |
|
1107 |
|
|
1108 |
String ip = request.getParameter("ip"); |
|
1109 |
if (ip == null) { |
|
1110 |
ip = getIp(request); |
|
1111 |
} |
|
1112 |
//同时更新对应表字段值,避免删除没保存就退出页面,造成数据不一致 by danaus 2020/4/3 15:33 |
97a11f
|
1113 |
String sql = " declare @tempStr varchar(500)\n" + |
a6a76f
|
1114 |
"select @tempStr=" + fieldid + " from " + tableName + " where '" + unid + "' in (select list from getinstr( " + fieldid + "))\n" + |
97a11f
|
1115 |
" if isnull(@tempStr,'')<>''\n" + |
F |
1116 |
" begin \n" + |
|
1117 |
" set @tempStr=REPLACE(@tempStr,';" + seq + "','')\n" + |
|
1118 |
" if charindex(';',@tempStr)=0 \n" +//表示已经是最后一个,需要清空 |
|
1119 |
" update a set " + fieldid + "=null from " + tableName + " a where '" + unid + "' in (select list from getinstr( " + fieldid + "))\n" + |
|
1120 |
" else\n" + |
|
1121 |
" update a set a." + fieldid + "=@tempStr from " + tableName + " a where '" + unid + "' in (select list from getinstr( " + fieldid + ")) \n" + |
|
1122 |
" set @mydelPicrowcount_Attachment = @@rowcount \n" + |
|
1123 |
" end \n"; |
2b4227
|
1124 |
PicEntity picEntity=new PicEntity(); |
F |
1125 |
picEntity.setUuid(unid); |
|
1126 |
picEntity.setSeq(Integer.parseInt(seq)); |
|
1127 |
picEntity.setType(Integer.parseInt(type)); |
|
1128 |
picEntity.setUserCode(postBeanInfo.getCurUsercode()); |
|
1129 |
picEntity.setUserName(postBeanInfo.getCurUsername()); |
|
1130 |
picEntity.setIp(ip); |
|
1131 |
picEntity.setAction(acType); |
|
1132 |
picEntity.setSql(sql); |
|
1133 |
picEntity.setField(fieldid); |
|
1134 |
picEntity.setFormId(str_formid); |
|
1135 |
boolean success = attachmentIfc.deleteAttachment(picEntity); |
a6a76f
|
1136 |
|
F |
1137 |
if (success) { |
|
1138 |
printJson(response, "{\"status\":\"success\"}"); |
|
1139 |
} else { |
|
1140 |
printJson(response, "{\"status\":\"failed\"}"); |
|
1141 |
} |
|
1142 |
} catch (Exception e) { |
|
1143 |
e.printStackTrace(); |
|
1144 |
Map<String, String> m = new HashMap<String, String>(); |
|
1145 |
m.put("error", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); //删除图片报错的错误输出 |
|
1146 |
printJson(response, GridUtils.toJson(m)); |
|
1147 |
} finally { |
|
1148 |
SpObserver.setDBtoInstance(); |
|
1149 |
} |
|
1150 |
} |
|
1151 |
|
|
1152 |
/** |
|
1153 |
* 供后台删除格线行时,有图片时调用,只删除磁盘文件 |
|
1154 |
* |
|
1155 |
* @param request |
|
1156 |
* @param response |
|
1157 |
*/ |
|
1158 |
@RequestMapping("/attachment/deleteAttachmentByGrid.do") |
|
1159 |
@CrossOrigin |
|
1160 |
public void deleteAttachmentByGrid(HttpServletRequest request, HttpServletResponse response) { |
|
1161 |
try { |
|
1162 |
String str_formid = request.getParameter("formid"); |
|
1163 |
String unid = request.getParameter("unid"); |
|
1164 |
String seq = request.getParameter("seq"); |
|
1165 |
HttpSession session = request.getSession(); |
|
1166 |
String dbid = request.getParameter("dbid"); |
|
1167 |
if (dbid == null) { |
|
1168 |
throw new ApplicationException("dbid不能为空"); |
|
1169 |
} |
|
1170 |
if (dbid.length() < 32) { |
|
1171 |
throw new ApplicationException("dbid未有加密传输"); |
|
1172 |
} |
|
1173 |
try { |
|
1174 |
dbid = ChangePassword.getDecryptPassword(EncodeUtil.replaceUrlChar(dbid)); |
|
1175 |
} catch (Exception ex) { |
|
1176 |
throw new ApplicationException("dbid解密:" + this.getErrorMsg(ex)); |
|
1177 |
} |
|
1178 |
int formid = -1; |
|
1179 |
try { |
|
1180 |
formid = Integer.parseInt(str_formid); |
|
1181 |
} catch (Exception e) { |
|
1182 |
return; |
|
1183 |
} |
|
1184 |
SpObserver.setDBtoInstance("_" + dbid); //切换数据源 |
|
1185 |
AttachmentEntity attachmentEntity = attachmentIfc.getAttachmentEntity(unid, seq); |
|
1186 |
if (attachmentEntity != null) { |
|
1187 |
//拼接附件的URL,磁盘上删除附件 |
|
1188 |
String path = session.getServletContext().getRealPath("/") + "/uploads/attachment/" + dbid + "/" + formid + "/" + unid + SettingKey.NAVSPLIT + seq + "." + attachmentEntity.getFileType();//原图 |
|
1189 |
File file = new File(path); |
|
1190 |
if (file != null && file.exists() && file.isFile()) { |
|
1191 |
file.delete(); |
|
1192 |
} |
|
1193 |
if (attachmentEntity.getFileType() != null && (attachmentEntity.getFileType().matches("jpg|png|gif|bmp"))) {//小图且是图片 |
|
1194 |
path = session.getServletContext().getRealPath("/") + "/uploads/attachment/" + dbid + "/" + formid + "/" + unid + SettingKey.NAVSPLIT + seq + "_80x80." + attachmentEntity.getFileType(); |
|
1195 |
file = new File(path); |
|
1196 |
if (file != null && file.exists() && file.isFile()) { |
|
1197 |
file.delete(); |
|
1198 |
} |
|
1199 |
} |
|
1200 |
} |
|
1201 |
} catch (Exception e) { |
|
1202 |
e.printStackTrace(); |
|
1203 |
Map<String, String> m = new HashMap<String, String>(); |
|
1204 |
m.put("error", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); //删除图片报错的错误输出 |
|
1205 |
printJson(response, GridUtils.toJson(m)); |
|
1206 |
} finally { |
|
1207 |
SpObserver.setDBtoInstance(); |
|
1208 |
} |
|
1209 |
} |
|
1210 |
|
|
1211 |
/** |
|
1212 |
* 删除未保存的文件 |
|
1213 |
* |
|
1214 |
* @param request |
|
1215 |
* @param response |
|
1216 |
*/ |
|
1217 |
|
|
1218 |
@RequestMapping("/attachment/deleteOwnerAttachment.do") |
|
1219 |
@CrossOrigin |
|
1220 |
public void deleteOwnerAttachment(HttpServletRequest request, HttpServletResponse response) { |
e44ea2
|
1221 |
String formid = request.getParameter("formid"); |
F |
1222 |
String fieldid = request.getParameter("fieldid"); |
|
1223 |
String isHd = request.getParameter("ishd"); //是否主表 |
a6a76f
|
1224 |
String unid = request.getParameter("unid"); |
F |
1225 |
String seq = request.getParameter("seq"); |
|
1226 |
String type = (String) request.getParameter("type"); |
|
1227 |
HttpSession session = request.getSession(); |
|
1228 |
String dbid = request.getParameter("dbid"); |
|
1229 |
if (dbid == null) { |
|
1230 |
dbid = (String) session.getAttribute(SessionKey.DATA_BASE_ID); |
|
1231 |
} |
|
1232 |
try { |
|
1233 |
SpObserver.setDBtoInstance("_" + dbid); //切换数据源 |
2b4227
|
1234 |
//String acType = "删除"; |
a6a76f
|
1235 |
String userCode = request.getParameter("usercode"); |
F |
1236 |
if (userCode == null) { |
|
1237 |
userCode = session.getAttribute(SessionKey.USERCODE) + ""; |
|
1238 |
} |
|
1239 |
String userName = request.getParameter("username"); |
|
1240 |
if (userName == null) { |
|
1241 |
userName = session.getAttribute(SessionKey.USERNAME) + ""; |
|
1242 |
} |
|
1243 |
String ip = request.getParameter("ip"); |
|
1244 |
if (ip == null) { |
|
1245 |
ip = getIp(request); |
|
1246 |
} |
e44ea2
|
1247 |
PicEntity picEntity = new PicEntity(); |
1efd43
|
1248 |
if (org.apache.commons.lang3.StringUtils.isNotBlank(isHd)) {//兼容旧用法 |
F |
1249 |
Map<String, Object> fieldInfo = null; |
|
1250 |
if ("2".contentEquals(isHd)) {//判断为3类型执行 |
|
1251 |
fieldInfo = attachmentIfc.getUploadFieldInfo3(Integer.parseInt(formid), fieldid); |
|
1252 |
isHd = "1";//还原成取主表的表名 |
|
1253 |
} else { |
|
1254 |
fieldInfo = attachmentIfc.getUploadFieldInfo(Integer.parseInt(formid), fieldid, "1".equals(isHd) ? true : false); |
|
1255 |
} |
|
1256 |
if (fieldInfo == null) { |
|
1257 |
print(response, "配置有误," + formid + "功能号不存在该上传图片控件!"); |
|
1258 |
return; |
|
1259 |
} |
|
1260 |
String tableName = attachmentIfc.getPanelTableName(Integer.parseInt(formid), "1".equals(isHd) ? true : false); |
|
1261 |
if (StringUtils.isBlank(tableName)) { |
|
1262 |
print(response, "表名为空!"); |
|
1263 |
return; |
|
1264 |
} |
|
1265 |
|
|
1266 |
//同时更新对应表字段值,避免删除没保存就退出页面,造成数据不一致 by danaus 2020/4/3 15:33 |
|
1267 |
String sql = "set nocount on \n declare @tempStr varchar(500)\n" + |
|
1268 |
"select @tempStr=" + fieldid + " from " + tableName + " where '" + unid + "' in (select list from getinstr( " + fieldid + "))\n" + |
|
1269 |
"set @tempStr=REPLACE(@tempStr,';" + seq + "','')\n" + |
|
1270 |
"if charindex(';',@tempStr)=0 \n" +//表示已经是最后一个,需要清空 |
|
1271 |
"update a set " + fieldid + "=null from " + tableName + " a where '" + unid + "' in (select list from getinstr( " + fieldid + "))\n" + |
|
1272 |
"else\n" + |
|
1273 |
"update a set a." + fieldid + "=@tempStr from " + tableName + " a where '" + unid + "' in (select list from getinstr( " + fieldid + "))"; |
|
1274 |
picEntity.setSql(sql); |
|
1275 |
} |
2b4227
|
1276 |
picEntity.setUuid(unid); |
F |
1277 |
picEntity.setSeq(Integer.parseInt(seq)); |
|
1278 |
picEntity.setType(Integer.parseInt(type)); |
|
1279 |
picEntity.setUserCode(userCode); |
|
1280 |
picEntity.setUserName(userName); |
|
1281 |
picEntity.setIp(ip); |
|
1282 |
boolean success = attachmentIfc.deleteAttachment(picEntity); |
a6a76f
|
1283 |
if (success) { |
0a4f16
|
1284 |
printJson(response, "{\"status\":\"success\",\"key\":\"" + (unid + ";" + seq) + "\"}"); |
a6a76f
|
1285 |
} else { |
F |
1286 |
printJson(response, "{\"status\":\"failed\"}"); |
|
1287 |
} |
|
1288 |
} catch (Exception e) { |
|
1289 |
e.printStackTrace(); |
|
1290 |
Map<String, String> m = new HashMap<String, String>(); |
|
1291 |
m.put("error", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); //删除图片报错的错误输出 |
|
1292 |
printJson(response, GridUtils.toJson(m)); |
|
1293 |
} finally { |
|
1294 |
SpObserver.setDBtoInstance(); |
|
1295 |
} |
|
1296 |
} |
|
1297 |
|
|
1298 |
/** |
|
1299 |
* 处理上传附件,成功返回unid,seq |
|
1300 |
* |
|
1301 |
* @param request |
|
1302 |
* @param response |
|
1303 |
* @return |
|
1304 |
* @throws IOException |
|
1305 |
*/ |
|
1306 |
public Object doPostAttachment(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
1307 |
request.setCharacterEncoding("utf-8"); |
|
1308 |
HttpSession session = request.getSession(true); |
|
1309 |
JsonObject json = new JsonObject(); |
|
1310 |
String userCode = request.getParameter("usercode"); |
|
1311 |
if (userCode == null) { |
|
1312 |
userCode = (String) session.getAttribute(SessionKey.HRCODE); |
|
1313 |
if (userCode == null) { |
|
1314 |
String sid = (String) request.getParameter("sid"); |
|
1315 |
if (null == sid) { |
|
1316 |
json.addProperty("status", "failed"); |
|
1317 |
json.addProperty("error", "sid不能为空"); |
|
1318 |
return json; |
|
1319 |
} |
|
1320 |
session = SessionListener.getSession(request, sid); |
|
1321 |
} |
|
1322 |
} |
|
1323 |
String type = request.getParameter("type"); |
|
1324 |
if (type == null) { |
|
1325 |
type = request.getAttribute("type") + ""; |
|
1326 |
} |
|
1327 |
if (null == userCode) { |
|
1328 |
json.addProperty("status", "failed"); |
|
1329 |
json.addProperty("error", "userCode不能为空"); |
|
1330 |
return json; |
|
1331 |
} |
|
1332 |
String userName = request.getParameter("username"); |
|
1333 |
if (userName == null) { |
|
1334 |
userName = (String) session.getAttribute(SessionKey.USERNAME); |
|
1335 |
} |
|
1336 |
String str_formid = request.getParameter("formid"); |
|
1337 |
if (str_formid == null) { |
|
1338 |
str_formid = request.getAttribute("formid") + ""; |
|
1339 |
} |
|
1340 |
String doccode = request.getParameter("doccode"); |
|
1341 |
String fieldid = (String) request.getParameter("fieldid"); |
035491
|
1342 |
if(fieldid==null) fieldid="";//避免app上传头像时报错 |
a6a76f
|
1343 |
String rowid = (String) request.getParameter("rowid"); |
F |
1344 |
String uuid = (String) request.getParameter("uuid"); |
|
1345 |
|
|
1346 |
response.setCharacterEncoding("utf-8"); |
|
1347 |
//处理app或pc上面还有旧文件可能有传随机数的情况,在这里处理下 |
|
1348 |
if (rowid != null && rowid != "" && rowid.startsWith("0.")) rowid = null; |
|
1349 |
|
|
1350 |
doccode = doccode == null ? "" : doccode; |
|
1351 |
String dbid = request.getParameter("dbid"); |
|
1352 |
if (dbid == null) { |
|
1353 |
dbid = (String) session.getAttribute(SessionKey.DATA_BASE_ID); |
|
1354 |
} |
f7ec4b
|
1355 |
String fileExt=""; |
a6a76f
|
1356 |
try { |
F |
1357 |
SpObserver.setDBtoInstance("_" + dbid); //切换数据源 |
|
1358 |
|
|
1359 |
FileUpload fileUpload = new FileUpload(ImageUtils.tempPath, request); |
|
1360 |
fileUpload.setSizeMax(999999999L);//默认最大10MB |
|
1361 |
|
|
1362 |
//上传文件 |
|
1363 |
String[] unidseq = null; |
|
1364 |
String seqString = ""; |
|
1365 |
if (uuid != null && !uuid.equals(";") && uuid.indexOf(";") != -1) { |
|
1366 |
unidseq = uuid.split(";"); |
|
1367 |
uuid = unidseq[0]; |
|
1368 |
} |
|
1369 |
int index = 0; |
|
1370 |
java.util.List<UpFile> upFiles = fileUpload.Upload(); |
|
1371 |
byte[] orgBinaryimages = null;//源文件 |
|
1372 |
byte[] smallBinaryimages = null;//缩略图 |
|
1373 |
|
f7ec4b
|
1374 |
|
a6a76f
|
1375 |
//图片缩小处理 |
F |
1376 |
for (UpFile upFile : upFiles) { |
|
1377 |
Integer seq = null; |
|
1378 |
String fileName = upFile.getNewFile().getAbsolutePath(); |
|
1379 |
if (ImageUtils.isPicture(upFile.getOldFileName())) { |
|
1380 |
ImageUtils.scaleByConfig(fileName, fileName, request); |
|
1381 |
} |
|
1382 |
|
|
1383 |
//源文件二进制 |
|
1384 |
InputStream photoStream = new FileInputStream(fileName); |
|
1385 |
orgBinaryimages = input2byte(photoStream); |
|
1386 |
|
|
1387 |
//处理缩略图 |
|
1388 |
String smallImagePath = ImageUtils.buildSmallPicReName(upFile.getNewFile().getAbsolutePath(), |
|
1389 |
180, 180); |
|
1390 |
//非图片的需要补全路径 |
|
1391 |
if (!ImageUtils.isPicture(upFile.getOldFileName())) { |
|
1392 |
smallImagePath = request.getServletContext().getRealPath("/") + smallImagePath; |
|
1393 |
} |
|
1394 |
//缩略图二进制 |
|
1395 |
InputStream photoStream1 = new FileInputStream(smallImagePath); |
|
1396 |
smallBinaryimages = input2byte(photoStream1); |
|
1397 |
if (uuid == null || uuid.equals("") || uuid.equals(";") || uuid.equals("null")) { |
|
1398 |
uuid = UUID.randomUUID().toString().toUpperCase(); //生成uuid |
|
1399 |
} |
|
1400 |
|
f7ec4b
|
1401 |
fileExt = upFile.getSuffix(); |
J |
1402 |
if (fileExt!=null&&!"".equals(fileExt)) { |
|
1403 |
fileExt = fileExt.toLowerCase(); |
|
1404 |
} |
a6a76f
|
1405 |
AttachmentEntity attachmentEntity = new AttachmentEntity(); |
F |
1406 |
attachmentEntity.setUnid(uuid); |
|
1407 |
attachmentEntity.setSeq(seq); |
|
1408 |
attachmentEntity.setFormId(Integer.valueOf(str_formid)); |
|
1409 |
attachmentEntity.setDoccode(doccode); |
|
1410 |
attachmentEntity.setFieldId(fieldid); |
|
1411 |
attachmentEntity.setRowId(rowid); |
|
1412 |
attachmentEntity.setPhysicalFile(null); |
|
1413 |
attachmentEntity.setPhysicalPath(null); |
|
1414 |
attachmentEntity.setOriginalFileName(upFile.getOldFileName()); |
|
1415 |
attachmentEntity.setFileSize(upFile.getFileSize()); |
f7ec4b
|
1416 |
attachmentEntity.setFileType(fileExt); |
a6a76f
|
1417 |
attachmentEntity.setAuthorCode(userCode); |
F |
1418 |
attachmentEntity.setAuthorName(userName); |
|
1419 |
UploadFiles uploadFiles = new UploadFiles(); |
|
1420 |
uploadFiles.setOrgBinaryimages(orgBinaryimages); |
|
1421 |
uploadFiles.setSmallBinaryimages(smallBinaryimages); |
|
1422 |
AttachmentWhereEntity attachmentWhereEntity = attachmentIfc.saveAttachment(uploadFiles, attachmentEntity, type); |
|
1423 |
index++; |
|
1424 |
if (index == upFiles.size()) |
|
1425 |
seqString += attachmentWhereEntity.getSeq(); |
|
1426 |
else { |
|
1427 |
seqString += attachmentWhereEntity.getSeq() + ";"; |
|
1428 |
} |
|
1429 |
|
|
1430 |
//处理水印 |
|
1431 |
if (ImageUtils.isPicture(upFile.getOldFileName())) { |
|
1432 |
ImageUtils.waterMark(fileName, request); |
|
1433 |
} |
|
1434 |
|
|
1435 |
//删除磁盘文件 |
|
1436 |
File pic = new File(fileName); |
|
1437 |
if (pic != null && pic.exists() && pic.isFile()) { |
|
1438 |
if (pic.getPath().indexOf("specialpic") != -1) { |
|
1439 |
} else { //specialpic文件里面的不能删除 |
|
1440 |
pic.delete(); |
|
1441 |
} |
|
1442 |
} |
|
1443 |
//删除缩略图 |
|
1444 |
File smpic = new File(smallImagePath); |
|
1445 |
if (smpic != null && smpic.exists() && smpic.isFile()) { |
|
1446 |
if (smpic.getPath().indexOf("specialpic") != -1) { |
|
1447 |
} else { //specialpic文件里面的不能删除 |
|
1448 |
smpic.delete(); |
|
1449 |
} |
|
1450 |
} |
|
1451 |
|
|
1452 |
} |
|
1453 |
seqString = uuid + ";" + seqString; |
|
1454 |
if (unidseq != null && unidseq.length > 1) {//修改 |
|
1455 |
for (int i = 1; i < unidseq.length; i++) { |
|
1456 |
seqString += ";" + unidseq[i]; |
|
1457 |
} |
|
1458 |
} |
|
1459 |
Map<String, String> m = new HashMap<String, String>(); |
|
1460 |
m.put("status", "success"); |
|
1461 |
m.put("uuid", seqString); |
|
1462 |
m.put("type", type); |
f7ec4b
|
1463 |
m.put("fileType", fileExt); |
a6a76f
|
1464 |
m.put("path", "|/getImage.do?type=0&uuid=" + seqString + "&r=" + Math.random() + JsonUtil.IMGRANG); |
F |
1465 |
return m; |
|
1466 |
|
|
1467 |
} catch (Exception e) { |
|
1468 |
e.printStackTrace(); |
|
1469 |
json.addProperty("status", "failed"); |
|
1470 |
json.addProperty("error", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); //上传图片报错的错误输出 |
|
1471 |
return json; |
|
1472 |
} finally { |
|
1473 |
SpObserver.setDBtoInstance(); |
|
1474 |
} |
|
1475 |
} |
|
1476 |
|
|
1477 |
public Object doPostAttachmentV2(PostBeanInfo info, HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
1478 |
JsonObject json = new JsonObject(); |
|
1479 |
PostBeanInfo postBeanInfo = info; |
|
1480 |
if (postBeanInfo == null) { |
|
1481 |
postBeanInfo = prossParameter(request); |
|
1482 |
} |
|
1483 |
String type = request.getParameter("type"); |
|
1484 |
if (type == null) { |
|
1485 |
type = request.getAttribute("type") == null ? null : request.getAttribute("type") + ""; |
|
1486 |
} |
|
1487 |
if (type == null) { |
|
1488 |
type = postBeanInfo.getType() + ""; |
|
1489 |
} |
|
1490 |
|
|
1491 |
String str_formid = request.getParameter("formid"); |
|
1492 |
if (str_formid == null) { |
|
1493 |
str_formid = postBeanInfo.getFormid() + ""; |
|
1494 |
} |
|
1495 |
String doccode = request.getParameter("doccode"); |
035491
|
1496 |
String fieldid =request.getParameter("fieldid"); |
F |
1497 |
if(fieldid==null) fieldid="";//避免app上传头像时报错 |
a6a76f
|
1498 |
String rowid = request.getParameter("rowid"); |
F |
1499 |
String uuid = request.getParameter("uuid"); |
9bd2e8
|
1500 |
String matCode=request.getParameter("matCode");//个别数据没有doccode值需要到这个属性 xin 2023-2-10 17:29:11 |
X |
1501 |
boolean isMatCode=false; |
|
1502 |
//没有doccode值的情况,用matCode值替换 |
|
1503 |
if(StringUtils.isBlank(doccode) && StringUtils.isNotBlank(matCode)){ |
56df6c
|
1504 |
matCode= EncodeUtil.base64Decode(matCode);//解码前端加密过的内容 |
9bd2e8
|
1505 |
isMatCode=true; |
X |
1506 |
//把matCode值给doccode; |
|
1507 |
doccode=matCode; |
|
1508 |
postBeanInfo.setDoccode(matCode); |
|
1509 |
} |
a6a76f
|
1510 |
|
F |
1511 |
response.setCharacterEncoding("utf-8"); |
|
1512 |
//处理app或pc上面还有旧文件可能有传随机数的情况,在这里处理下 |
|
1513 |
if (rowid != null && !"".equals(rowid) && rowid.startsWith("0.")) rowid = null; |
|
1514 |
|
|
1515 |
doccode = doccode == null ? "" : doccode; |
|
1516 |
|
|
1517 |
try { |
|
1518 |
SpObserver.setDBtoInstance("_" + postBeanInfo.getDbid()); //切换数据源 |
|
1519 |
|
|
1520 |
FileUpload fileUpload = new FileUpload(ImageUtils.tempPath, request); |
|
1521 |
fileUpload.setSizeMax(999999999L);//默认最大10MB |
|
1522 |
|
|
1523 |
//上传文件 |
|
1524 |
String[] unidseq = null; |
|
1525 |
String seqString = ""; |
796236
|
1526 |
uuid = (fieldid.equals(uuid) ? "" : uuid); |
a6a76f
|
1527 |
if (uuid != null && !uuid.equals(";") && uuid.indexOf(";") != -1) { |
F |
1528 |
unidseq = uuid.split(";"); |
|
1529 |
uuid = unidseq[0]; |
|
1530 |
} |
|
1531 |
int index = 0; |
|
1532 |
java.util.List<UpFile> upFiles = fileUpload.Upload(); |
|
1533 |
byte[] orgBinaryimages = null;//源文件 |
|
1534 |
byte[] smallBinaryimages = null;//缩略图 |
|
1535 |
String fileExt = ""; |
0a4f16
|
1536 |
Map<String, String> seqMap = new HashMap<>(); |
F |
1537 |
Map<String, String> fileExtMap = new HashMap<>(); |
a6a76f
|
1538 |
//图片缩小处理 |
F |
1539 |
for (UpFile upFile : upFiles) { |
|
1540 |
Integer seq = null; |
|
1541 |
String fileName = upFile.getNewFile().getAbsolutePath(); |
|
1542 |
if (ImageUtils.isPicture(upFile.getOldFileName())) { |
|
1543 |
ImageUtils.scaleByConfig(fileName, fileName, request); |
|
1544 |
} |
|
1545 |
|
|
1546 |
//源文件二进制 |
|
1547 |
InputStream photoStream = new FileInputStream(fileName); |
|
1548 |
orgBinaryimages = input2byte(photoStream); |
|
1549 |
|
|
1550 |
//处理缩略图 |
|
1551 |
String smallImagePath = ImageUtils.buildSmallPicReName(upFile.getNewFile().getAbsolutePath(), |
|
1552 |
180, 180); |
|
1553 |
//非图片的需要补全路径 |
|
1554 |
if (!ImageUtils.isPicture(upFile.getOldFileName())) { |
|
1555 |
smallImagePath = request.getServletContext().getRealPath("/") + smallImagePath; |
|
1556 |
} |
|
1557 |
//缩略图二进制 |
|
1558 |
InputStream photoStream1 = new FileInputStream(smallImagePath); |
|
1559 |
smallBinaryimages = input2byte(photoStream1); |
|
1560 |
if (uuid == null || uuid.equals("") || uuid.equals(";") || uuid.equals("null")) { |
|
1561 |
uuid = UUID.randomUUID().toString().toUpperCase(); //生成uuid |
|
1562 |
} |
|
1563 |
fileExt = upFile.getSuffix(); |
b29ddc
|
1564 |
if (fileExt!=null&&!"".equals(fileExt)) { |
J |
1565 |
fileExt = fileExt.toLowerCase(); |
|
1566 |
} |
a6a76f
|
1567 |
AttachmentEntity attachmentEntity = new AttachmentEntity(); |
F |
1568 |
attachmentEntity.setUnid(uuid); |
|
1569 |
attachmentEntity.setSeq(seq); |
|
1570 |
attachmentEntity.setFormId(Integer.valueOf(str_formid)); |
|
1571 |
attachmentEntity.setDoccode(doccode); |
|
1572 |
attachmentEntity.setFieldId(fieldid); |
|
1573 |
attachmentEntity.setRowId(rowid); |
|
1574 |
attachmentEntity.setPhysicalFile(null); |
|
1575 |
attachmentEntity.setPhysicalPath(null); |
|
1576 |
attachmentEntity.setOriginalFileName(upFile.getOldFileName()); |
|
1577 |
attachmentEntity.setFileSize(upFile.getFileSize()); |
b29ddc
|
1578 |
attachmentEntity.setFileType(fileExt); |
a6a76f
|
1579 |
attachmentEntity.setAuthorCode(postBeanInfo.getUsercode()); |
F |
1580 |
attachmentEntity.setAuthorName(postBeanInfo.getUsername()); |
|
1581 |
UploadFiles uploadFiles = new UploadFiles(); |
|
1582 |
uploadFiles.setOrgBinaryimages(orgBinaryimages); |
|
1583 |
uploadFiles.setSmallBinaryimages(smallBinaryimages); |
|
1584 |
AttachmentWhereEntity attachmentWhereEntity = attachmentIfc.saveAttachment(uploadFiles, attachmentEntity, type); |
|
1585 |
index++; |
|
1586 |
if (index == upFiles.size()) |
|
1587 |
seqString += attachmentWhereEntity.getSeq(); |
|
1588 |
else { |
|
1589 |
seqString += attachmentWhereEntity.getSeq() + ";"; |
|
1590 |
} |
0a4f16
|
1591 |
seqMap.put(upFile.getOldFileName(), attachmentWhereEntity.getSeq() + ""); |
F |
1592 |
fileExtMap.put(uuid + ";" + attachmentWhereEntity.getSeq(), fileExt); |
a6a76f
|
1593 |
//处理水印 |
F |
1594 |
if (ImageUtils.isPicture(upFile.getOldFileName())) { |
|
1595 |
ImageUtils.waterMark(fileName, request); |
|
1596 |
} |
|
1597 |
|
|
1598 |
//删除磁盘文件 |
|
1599 |
File pic = new File(fileName); |
|
1600 |
if (pic != null && pic.exists() && pic.isFile()) { |
|
1601 |
if (pic.getPath().indexOf("specialpic") != -1) { |
|
1602 |
} else { //specialpic文件里面的不能删除 |
|
1603 |
pic.delete(); |
|
1604 |
} |
|
1605 |
} |
|
1606 |
//删除缩略图 |
|
1607 |
File smpic = new File(smallImagePath); |
|
1608 |
if (smpic != null && smpic.exists() && smpic.isFile()) { |
|
1609 |
if (smpic.getPath().indexOf("specialpic") != -1) { |
|
1610 |
} else { //specialpic文件里面的不能删除 |
|
1611 |
smpic.delete(); |
|
1612 |
} |
|
1613 |
} |
|
1614 |
|
|
1615 |
} |
|
1616 |
seqString = uuid + ";" + seqString; |
|
1617 |
if (unidseq != null && unidseq.length > 1) {//修改 |
|
1618 |
for (int i = 1; i < unidseq.length; i++) { |
|
1619 |
seqString += ";" + unidseq[i]; |
|
1620 |
} |
|
1621 |
} |
|
1622 |
//上传成功后更新表字段 |
|
1623 |
if (postBeanInfo.getIshd() != null && 2 == postBeanInfo.getIshd()) { |
|
1624 |
//格表传参=2表示为附件是主表的内容,需要转成=0 |
|
1625 |
postBeanInfo.setIshd(1); |
|
1626 |
} |
|
1627 |
if (org.apache.commons.lang3.StringUtils.isNotBlank(postBeanInfo.getDoccode()) && postBeanInfo.getIshd() != null) { |
|
1628 |
//有单号且有传新参数ishd指定表才执行更新,为了向后兼容,ishd=1表示主表,0表示从表 |
|
1629 |
final BaseService baseService = (BaseService) FactoryBean.getBean("BaseService"); |
|
1630 |
String tableName = attachmentIfc.getPanelTableName(postBeanInfo.getFormid(), postBeanInfo.getIshd() == 1 ? true : false); |
|
1631 |
if (postBeanInfo.getIshd() == 1) { |
|
1632 |
//更新主表 |
|
1633 |
if (postBeanInfo.getIs8() != null && postBeanInfo.getIs8() == 1) { |
|
1634 |
//8类型的第三表,需要rowid,对应表中的detailrowid |
4442a8
|
1635 |
if (StringUtils.isBlank(postBeanInfo.getRowid())) { |
a6a76f
|
1636 |
throw new ApplicationException(postBeanInfo.getFormid() + "更新单号【" + postBeanInfo.getDoccode() + "】附件信息,rowid不能为空"); |
F |
1637 |
} |
|
1638 |
baseService.getSimpleJdbcTemplate().update(" update a set a." + postBeanInfo.getFieldid() + "=? from " + tableName + " a where a.doccode=? and a.detailrowid=?", seqString, postBeanInfo.getDoccode(),postBeanInfo.getRowid()); |
|
1639 |
} else if (postBeanInfo.getIs1() != null && postBeanInfo.getIs1() == 1) { |
|
1640 |
//496,498多表的子功能号为格线,需要rowid |
4442a8
|
1641 |
if (StringUtils.isBlank(postBeanInfo.getRowid())) { |
13a943
|
1642 |
if(StringUtils.isBlank(postBeanInfo.getDetailrowid())){ |
4442a8
|
1643 |
throw new ApplicationException(postBeanInfo.getFormid() + "更新单号【" + postBeanInfo.getDoccode() + "】附件信息,rowid不能为空"); |
X |
1644 |
} |
a6a76f
|
1645 |
} |
4442a8
|
1646 |
//这个496窗体个别单据特殊需要到detailrowid。比如:维护系统帮助问答 xin 2023-1-5 16:35:47 |
X |
1647 |
String myRowid=postBeanInfo.getRowid(); |
|
1648 |
String rowidSql="a.rowid=?"; |
13a943
|
1649 |
if(StringUtils.isNotBlank(postBeanInfo.getDetailrowid())){ |
X |
1650 |
myRowid=postBeanInfo.getDetailrowid(); |
4442a8
|
1651 |
rowidSql="a.detailrowid=?"; |
X |
1652 |
} |
|
1653 |
baseService.getSimpleJdbcTemplate().update(" update a set a." + postBeanInfo.getFieldid() + "=? from " + tableName + " a where a.doccode=? and "+rowidSql, seqString, postBeanInfo.getDoccode(),myRowid); |
a6a76f
|
1654 |
} else if(postBeanInfo.getIs16() != null && postBeanInfo.getIs16() == 1) { |
F |
1655 |
//面板主表 |
|
1656 |
baseService.getSimpleJdbcTemplate().update(" update a set a." + postBeanInfo.getFieldid() + "=? from " + tableName + " a where a.doccode=?", seqString, postBeanInfo.getDoccode()); |
9bd2e8
|
1657 |
}else if(isMatCode){ |
X |
1658 |
//是特殊单据,在前端没有doccode值,用matCode代替的情况 xin 2023-2-10 17:32:49 |
|
1659 |
baseService.getSimpleJdbcTemplate().update(" update a set a." + postBeanInfo.getFieldid() + "=? from " + tableName + " a where a.matCode=?", seqString, postBeanInfo.getDoccode()); |
a6a76f
|
1660 |
} |
F |
1661 |
//其他情况不更新 |
|
1662 |
} else { |
|
1663 |
//从表更新需要有rowid, 针对5类型,8类型从表 |
035491
|
1664 |
if (StringUtils.isNotBlank(postBeanInfo.getRowid())) { |
F |
1665 |
baseService.getSimpleJdbcTemplate().update(" update a set a." + postBeanInfo.getFieldid() + "=? from " + tableName + " a where a.doccode=? and a.rowid=?", seqString, postBeanInfo.getDoccode(), postBeanInfo.getRowid()); |
a6a76f
|
1666 |
} |
F |
1667 |
} |
|
1668 |
} |
|
1669 |
Map<String, String> m = new HashMap<String, String>(); |
|
1670 |
m.put("status", "success"); |
|
1671 |
m.put("uuid", seqString); |
|
1672 |
m.put("type", type); |
0a4f16
|
1673 |
m.put("seqMap", JSON.toJSONString(seqMap)); |
F |
1674 |
m.put("fileExtMap", JSON.toJSONString(fileExtMap)); |
|
1675 |
m.put("fileType", fileExt);//这里只返回最后一个附件的文件类型,在多附件时会有问题 |
a6a76f
|
1676 |
m.put("path", "|/getImage.do?type=0&uuid=" + seqString + "&r=" + Math.random() + JsonUtil.IMGRANG); |
F |
1677 |
return m; |
|
1678 |
|
|
1679 |
} catch (Exception e) { |
|
1680 |
e.printStackTrace(); |
|
1681 |
json.addProperty("status", "failed"); |
|
1682 |
json.addProperty("error", e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); //上传图片报错的错误输出 |
|
1683 |
return json; |
|
1684 |
} finally { |
|
1685 |
SpObserver.setDBtoInstance(); |
|
1686 |
} |
|
1687 |
} |
|
1688 |
|
|
1689 |
/** |
|
1690 |
* 上传文件 |
|
1691 |
* |
|
1692 |
* @param request |
|
1693 |
* @param response |
|
1694 |
* @throws IOException |
|
1695 |
*/ |
|
1696 |
@RequestMapping("/attachment/uploadAttachment.do") |
|
1697 |
@CrossOrigin |
|
1698 |
public void saveAttachment(String token, HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
1699 |
CallBackMessage callBackMessage = new CallBackMessage(); |
|
1700 |
try { |
|
1701 |
Object result = doPostAttachment(request, response); |
|
1702 |
if (result instanceof Map) { |
|
1703 |
printJson(response, GridUtils.toJson(result)); |
|
1704 |
} else if (result instanceof JsonObject) { |
|
1705 |
printJson(response, result.toString()); |
|
1706 |
} |
|
1707 |
} catch (Exception ex) { |
|
1708 |
printJson(response, callBackMessage.print()); |
|
1709 |
} |
|
1710 |
} |
|
1711 |
|
|
1712 |
@RequestMapping("/attachment/uploadAttachmentV2.do") |
|
1713 |
@CrossOrigin |
|
1714 |
public void saveAttachmentV2(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
1715 |
CallBackMessage callBackMessage = new CallBackMessage(); |
|
1716 |
try { |
|
1717 |
|
|
1718 |
Object result = doPostAttachmentV2(null, request, response); |
|
1719 |
|
|
1720 |
if (result instanceof Map) { |
|
1721 |
printJson(response, GridUtils.toJson(result)); |
|
1722 |
} else if (result instanceof JsonObject) { |
|
1723 |
printJson(response, result.toString()); |
|
1724 |
} |
|
1725 |
} catch (Exception ex) { |
|
1726 |
callBackMessage.sendErrorMessage(ex.getMessage()); |
|
1727 |
printJson(response, callBackMessage.print()); |
|
1728 |
} |
|
1729 |
} |
|
1730 |
|
|
1731 |
private String getAttExt(String type) { |
|
1732 |
String path = "smallpic" + File.separator + "specialpic" + File.separator; |
|
1733 |
if ("doc".equalsIgnoreCase(type) || "docx".equalsIgnoreCase(type)) { |
|
1734 |
path += type + ".png"; |
|
1735 |
} else if ("xls".equalsIgnoreCase(type) || "xlsx".equalsIgnoreCase(type)) { |
|
1736 |
path += "excel.png"; |
|
1737 |
} else if ("ppt".equalsIgnoreCase(type) || "pptx".equalsIgnoreCase(type)) { |
|
1738 |
path += type + ".png"; |
|
1739 |
} else if ("pdf".equalsIgnoreCase(type)) { |
|
1740 |
path += type + ".png"; |
|
1741 |
} else if ("rar".equalsIgnoreCase(type)) { |
|
1742 |
path += type + ".png"; |
|
1743 |
} else if ("html".equalsIgnoreCase(type)) { |
|
1744 |
path += type + ".png"; |
|
1745 |
} else if ("txt".equalsIgnoreCase(type)) { |
|
1746 |
path += type + ".png"; |
|
1747 |
} else if ("zip".equalsIgnoreCase(type)) { |
|
1748 |
path += type + ".png"; |
|
1749 |
} else if ("jrxml".equalsIgnoreCase(type)) { |
|
1750 |
path += "iReport.png"; |
|
1751 |
} else { |
|
1752 |
path += "unknown.png"; |
|
1753 |
} |
|
1754 |
return path; |
|
1755 |
} |
|
1756 |
|
|
1757 |
public static String getIp(HttpServletRequest request) { |
|
1758 |
String ip = request.getHeader("X-Forwarded-For"); |
|
1759 |
if (StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) { |
|
1760 |
//多次反向代理后会有多个ip值,第一个ip才是真实ip |
|
1761 |
int index = ip.indexOf(","); |
|
1762 |
if (index != -1) { |
|
1763 |
return ip.substring(0, index); |
|
1764 |
} else { |
|
1765 |
return ip; |
|
1766 |
} |
|
1767 |
} |
|
1768 |
ip = request.getHeader("X-Real-IP"); |
|
1769 |
if (StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) { |
|
1770 |
return ip; |
|
1771 |
} |
|
1772 |
return request.getRemoteAddr(); |
|
1773 |
} |
|
1774 |
} |