Kaynağa Gözat

申请请假

chenc 3 yıl önce
ebeveyn
işleme
0ee1871095

+ 64 - 0
jeecg-boot/jeecg-boot-base-common/src/main/java/org/jeecg/common/system/controller/CommonController.java

@@ -286,6 +286,70 @@ public class CommonController {
 //
 //	}
 
+	/**
+	 * 获取文件
+	 * 请求地址:http://localhost:8080/common/downloadFile/{file/20190119/e1fe9925bc315c60addea1b98eb1cb1349547719_1547866868179.jpg}
+	 *
+	 * @param request
+	 * @param response
+	 */
+	@GetMapping(value = "/downloadFile/**")
+	public void downloadFile(HttpServletRequest request, HttpServletResponse response) {
+		// ISO-8859-1 ==> UTF-8 进行编码转换
+		String filePath = extractPathFromPattern(request);
+		// 其余处理略
+		InputStream inputStream = null;
+		OutputStream outputStream = null;
+		try {
+			filePath = filePath.replace("..", "");
+			if (filePath.endsWith(",")) {
+				filePath = filePath.substring(0, filePath.length() - 1);
+			}
+			String localPath = uploadpath;
+			String fileurl = localPath + File.separator + filePath;
+			String fileName = fileurl.substring(fileurl.lastIndexOf("/")+1);
+			//浏览器设置,处理下载文件时文件名乱码
+			String userAgent = request.getHeader("User-Agent");
+			if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
+				//IE浏览器处理
+				fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
+			} else {
+				// 非IE浏览器的处理:
+				fileName = new String(fileName.getBytes("UTF-8"), "ISO-8859-1");
+			}
+			response.setContentType("application/octet-stream");
+			response.setHeader("content-type", "application/octet-stream");
+			response.setHeader("Content-Disposition", "attachment;fileName=" + fileName );// 设置文件名
+			inputStream = new BufferedInputStream(new FileInputStream(fileurl));
+			outputStream = response.getOutputStream();
+			byte[] buf = new byte[1024];
+			int len;
+			while ((len = inputStream.read(buf)) > 0) {
+				outputStream.write(buf, 0, len);
+			}
+			response.flushBuffer();
+		} catch (IOException e) {
+			log.info("预览图片失败" + e.getMessage());
+			// e.printStackTrace();
+		} finally {
+			if (inputStream != null) {
+				try {
+					inputStream.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+			if (outputStream != null) {
+				try {
+					outputStream.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+
+	}
+
 	/**
 	 * @功能:pdf预览Iframe
 	 * @param modelAndView

+ 2 - 4
jeecg-boot/jeecg-boot-module-activiti/src/main/java/org/jeecg/modules/activiti/service/Impl/ActBusinessServiceImpl.java

@@ -99,6 +99,8 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
             //子表修改逻辑
             if(StringUtils.isNotBlank(tableNameB)) {
                 JSONArray jsonArray = JSONArray.parseArray(childstr);
+                //删除子表
+                this.baseMapper.deletetBusiData(String.format("DELETE FROM %s WHERE %s = %s", tableNameB, tableName + "_id",  "'" + tableId + "'"));
                 for(int i = 0; i < jsonArray.size(); i++) {
                     //子表id
                     String tableBId = IdUtil.simpleUUID();
@@ -119,10 +121,6 @@ public class ActBusinessServiceImpl extends ServiceImpl<ActBusinessMapper, ActBu
                     //排序
                     filedIdB.append(",sort");
                     filedIdVB.append(",'" + i + "'");
-                    //删除子表
-                    this.baseMapper.deletetBusiData(String.format("DELETE FROM %s WHERE %s = %s", tableNameB, tableName + "_id",  "'" + tableId + "'"));
-
-
                     this.baseMapper.insertBusiData(String.format("INSERT INTO %s (%s) VALUES (%s)", tableNameB, filedIdB.toString(), filedIdVB.toString()));
                 }
             }