Commit bc3242a52a9bb57dd52c2bc6a1bcb3368b5643ef
1 parent
33a7d3a896
Exists in
master
and in
6 other branches
智能建档
Showing 4 changed files with 109 additions and 14 deletions
- platform-common/src/main/java/com/lyms/platform/common/utils/FileUtil.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/PregnantBuildController.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/request/ImgRequest.java
platform-common/src/main/java/com/lyms/platform/common/utils/FileUtil.java
View file @
bc3242a
1 | 1 | package com.lyms.platform.common.utils; |
2 | 2 | |
3 | 3 | import org.apache.commons.io.FileUtils; |
4 | +import sun.misc.BASE64Decoder; | |
4 | 5 | |
5 | 6 | import java.io.File; |
7 | +import java.io.FileOutputStream; | |
6 | 8 | import java.io.IOException; |
9 | +import java.io.OutputStream; | |
7 | 10 | import java.util.ArrayList; |
8 | 11 | import java.util.List; |
9 | 12 | import java.util.Map; |
... | ... | @@ -42,6 +45,44 @@ |
42 | 45 | return true; |
43 | 46 | } |
44 | 47 | return false; |
48 | + } | |
49 | + | |
50 | + | |
51 | + //base64字符串转化成图片 | |
52 | + public static boolean generateImage(String imgStr,String imgFilePath) | |
53 | + { //对字节数组字符串进行Base64解码并生成图片 | |
54 | + if (imgStr == null) //图像数据为空 | |
55 | + return false; | |
56 | + BASE64Decoder decoder = new BASE64Decoder(); | |
57 | + OutputStream out = null; | |
58 | + try | |
59 | + { | |
60 | + //Base64解码 | |
61 | + byte[] b = decoder.decodeBuffer(imgStr); | |
62 | + for(int i=0;i<b.length;++i) | |
63 | + { | |
64 | + if(b[i]<0) | |
65 | + {//调整异常数据 | |
66 | + b[i]+=256; | |
67 | + } | |
68 | + } | |
69 | + out = new FileOutputStream(imgFilePath); | |
70 | + out.write(b); | |
71 | + return true; | |
72 | + } | |
73 | + catch (Exception e) | |
74 | + { | |
75 | + return false; | |
76 | + } | |
77 | + finally { | |
78 | + try { | |
79 | + out.flush(); | |
80 | + out.close(); | |
81 | + } catch (IOException e) { | |
82 | + e.printStackTrace(); | |
83 | + } | |
84 | + | |
85 | + } | |
45 | 86 | } |
46 | 87 | |
47 | 88 | public static String getFileSuffix(String fileName) |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/PregnantBuildController.java
View file @
bc3242a
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | import com.lyms.platform.operate.web.facade.BookbuildingFacade; |
17 | 17 | import com.lyms.platform.operate.web.request.AntenatalExaminationQueryRequest; |
18 | 18 | import com.lyms.platform.operate.web.request.BookbuildingQueryRequest; |
19 | +import com.lyms.platform.operate.web.request.ImgRequest; | |
19 | 20 | import com.lyms.platform.operate.web.request.YunBookbuildingAddRequest; |
20 | 21 | import com.lyms.platform.permission.service.CouponService; |
21 | 22 | import org.apache.commons.httpclient.HttpClient; |
22 | 23 | |
23 | 24 | |
24 | 25 | |
25 | 26 | |
26 | 27 | |
... | ... | @@ -533,34 +534,35 @@ |
533 | 534 | doctorNo); |
534 | 535 | } |
535 | 536 | |
537 | + /** | |
538 | + * 保存图片 | |
539 | + * @param request | |
540 | + * @param imgRequest | |
541 | + * @return | |
542 | + */ | |
543 | + @RequestMapping(value="/saveImg",method=RequestMethod.POST) | |
544 | + @ResponseBody | |
545 | + public BaseResponse saveImg(HttpServletRequest request, | |
546 | + @RequestBody ImgRequest imgRequest) { | |
536 | 547 | |
548 | + return bookbuildingFacade.saveImg(imgRequest); | |
549 | + | |
550 | + } | |
551 | + | |
537 | 552 | /** |
538 | 553 | * 图片上次 |
539 | 554 | * @param request |
540 | 555 | * @param file |
541 | 556 | * @return |
542 | - * @throws Exception | |
543 | 557 | */ |
544 | 558 | @RequestMapping(value="/uploadImg",method=RequestMethod.POST) |
545 | 559 | @ResponseBody |
546 | -// @TokenRequired | |
547 | 560 | public BaseResponse upload(HttpServletRequest request, |
548 | - @RequestParam("file") MultipartFile file) throws Exception { | |
561 | + @RequestParam("file") MultipartFile file) { | |
549 | 562 | |
550 | 563 | return bookbuildingFacade.uploadImg(file); |
551 | 564 | |
552 | 565 | } |
553 | - | |
554 | -// @RequestMapping(value="/deleteImg",method=RequestMethod.GET) | |
555 | -// @ResponseBody | |
556 | -//// @TokenRequired | |
557 | -// public BaseResponse deleteImg(HttpServletRequest request, | |
558 | -// @RequestParam("filePath") String filePath) throws Exception { | |
559 | -// | |
560 | -// return bookbuildingFacade.deleteImg(filePath); | |
561 | -// | |
562 | -// } | |
563 | - | |
564 | 566 | |
565 | 567 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java
View file @
bc3242a
... | ... | @@ -18,6 +18,7 @@ |
18 | 18 | import com.lyms.platform.common.utils.*; |
19 | 19 | import com.lyms.platform.operate.web.request.BookBuildManagerQueryRequest; |
20 | 20 | import com.lyms.platform.operate.web.request.BookbuildingQueryRequest; |
21 | +import com.lyms.platform.operate.web.request.ImgRequest; | |
21 | 22 | import com.lyms.platform.operate.web.request.YunBookbuildingAddRequest; |
22 | 23 | import com.lyms.platform.operate.web.result.*; |
23 | 24 | import com.lyms.platform.operate.web.service.ITrackDownService; |
... | ... | @@ -2094,6 +2095,40 @@ |
2094 | 2095 | { |
2095 | 2096 | filepath.delete(); |
2096 | 2097 | } |
2098 | + } | |
2099 | + } | |
2100 | + | |
2101 | + public BaseResponse saveImg(ImgRequest imgRequest) { | |
2102 | + | |
2103 | + //如果文件不为空,写入上传路径 | |
2104 | + BaseObjectResponse objectResponse = new BaseObjectResponse(); | |
2105 | + if(!StringUtils.isNotEmpty(imgRequest.getImg())) { | |
2106 | + objectResponse.setErrorcode(ErrorCodeConstants.NO_DATA); | |
2107 | + objectResponse.setErrormsg("没有上传数据"); | |
2108 | + return objectResponse; | |
2109 | + } | |
2110 | + try { | |
2111 | + | |
2112 | + String imgPath = DateUtil.getYmd(new Date()); | |
2113 | + String filename = StringUtils.uuid()+".jpg"; | |
2114 | + | |
2115 | + String fileAllPath = BASE_IMG_PATH+File.separator+imgPath+File.separator+filename; | |
2116 | + System.out.println("fileAllPath=" + fileAllPath); | |
2117 | + File filepath = new File(fileAllPath); | |
2118 | + //判断路径是否存在,如果不存在就创建一个 | |
2119 | + if (!filepath.getParentFile().exists()) { | |
2120 | + filepath.getParentFile().mkdirs(); | |
2121 | + } | |
2122 | + FileUtil.generateImage(imgRequest.getImg(),fileAllPath); | |
2123 | + objectResponse.setData(imgPath + "/" + filename); | |
2124 | + objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS); | |
2125 | + objectResponse.setErrormsg("成功"); | |
2126 | + return objectResponse; | |
2127 | + } catch (Exception e) { | |
2128 | + ExceptionUtils.catchException(e,"上传图片发生异常"); | |
2129 | + objectResponse.setErrorcode(ErrorCodeConstants.SYSTEM_ERROR); | |
2130 | + objectResponse.setErrormsg(ErrorCodeConstants.SYSTEM_ERROR_DESCRIPTION); | |
2131 | + return objectResponse; | |
2097 | 2132 | } |
2098 | 2133 | } |
2099 | 2134 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/request/ImgRequest.java
View file @
bc3242a
1 | +package com.lyms.platform.operate.web.request; | |
2 | + | |
3 | +/** | |
4 | + * Created by Administrator on 2018-05-23. | |
5 | + */ | |
6 | +public class ImgRequest { | |
7 | + | |
8 | + private String img; | |
9 | + | |
10 | + public String getImg() { | |
11 | + return img; | |
12 | + } | |
13 | + | |
14 | + public void setImg(String img) { | |
15 | + this.img = img; | |
16 | + } | |
17 | +} |