Commit 36d994d2c4fe6762af4401b4ae7ba2ed27bee7a7
1 parent
6e7775b4
update
Showing
1 changed file
with
46 additions
and
41 deletions
src/main/java/com/huaheng/pc/file/picture/controller/FilePictureController.java
... | ... | @@ -9,6 +9,7 @@ import com.huaheng.common.utils.DateUtils; |
9 | 9 | import com.huaheng.common.utils.file.FileUploadUtils; |
10 | 10 | import com.huaheng.common.utils.security.ShiroUtils; |
11 | 11 | import com.huaheng.framework.config.HuaHengConfig; |
12 | +import com.huaheng.framework.config.ServerIpConfig; | |
12 | 13 | import com.huaheng.framework.web.page.PageDomain; |
13 | 14 | import com.huaheng.framework.web.page.TableDataInfo; |
14 | 15 | import com.huaheng.framework.web.page.TableSupport; |
... | ... | @@ -32,6 +33,7 @@ import javax.annotation.Resource; |
32 | 33 | import javax.servlet.http.HttpServletRequest; |
33 | 34 | import javax.servlet.http.HttpServletResponse; |
34 | 35 | import java.io.File; |
36 | +import java.util.Arrays; | |
35 | 37 | import java.util.Date; |
36 | 38 | import java.util.List; |
37 | 39 | |
... | ... | @@ -112,36 +114,41 @@ public class FilePictureController extends BaseController { |
112 | 114 | @Log(title = "保存图片", action = BusinessType.INSERT) |
113 | 115 | @PostMapping("/add") |
114 | 116 | @ResponseBody |
115 | - public AjaxResult addSave(FilePicture filePicture, @RequestParam("picture") MultipartFile picture) { | |
116 | - try { | |
117 | - long size = picture.getSize(); | |
117 | + public AjaxResult addSave(FilePicture filePicture,HttpServletRequest request) { | |
118 | 118 | |
119 | - if (size > 1024 * 1024 * 2) { | |
120 | - return AjaxResult.error("文件不能超过2M"); | |
121 | - } | |
122 | - | |
123 | - String httpBase = ""; | |
124 | - try { | |
125 | - httpBase = addressService.selectAddress(url_prefix_key, ShiroUtils.getWarehouseCode(), ""); | |
126 | - } catch (Exception e) { | |
127 | - return AjaxResult.error("上传文件出错,没有配置address表参数" + url_prefix_key + "对应的url"); | |
128 | - } | |
129 | - String basePath = FileUploadUtils.getFileServerUploadPath(); | |
130 | - String subPath = "images/" + DateUtils.getDate() + "/"; | |
131 | - String savePath = basePath + subPath; | |
132 | - String fileName = FileUploadUtils.upload(savePath, picture, FileUploadUtils.IMAGE_JPG_EXTENSION); | |
133 | - String url = httpBase + subPath + fileName; | |
134 | - filePicture.setUrl(url); | |
135 | - filePicture.setCreated(new Date()); | |
136 | - filePicture.setIp(ShiroUtils.getIp()); | |
137 | - filePicture.setSize(size); | |
138 | - filePicture.setName(filePicture.getName()); | |
139 | - filePicture.setCreatedBy(ShiroUtils.getLoginName()); | |
140 | - filePictureService.save(filePicture); | |
141 | - return AjaxResult.success(filePicture); | |
142 | - } catch (Exception e) { | |
143 | - return error("图片上传失败:" + e.getMessage()); | |
119 | + AjaxResult<FilePicture> ajaxResult = uploadFile(request, "picture"); | |
120 | + if(ajaxResult.hasErr()){ | |
121 | + return ajaxResult; | |
144 | 122 | } |
123 | + ajaxResult.getData(); | |
124 | +// try { | |
125 | +// long size = picture.getSize(); | |
126 | +// | |
127 | +// if (size > 1024 * 1024 * 2) { | |
128 | +// return AjaxResult.error("文件不能超过2M"); | |
129 | +// } | |
130 | +// | |
131 | +// String httpBase = ""; | |
132 | +// try { | |
133 | +// httpBase = "http://" + ShiroUtils.getIp() + ":" + ServerIpConfig.getPort() + "/wms/files"; | |
134 | +// } catch (Exception e) { | |
135 | +// return AjaxResult.error("上传文件出错,没有配置address表参数" + url_prefix_key + "对应的url"); | |
136 | +// } | |
137 | +// String fileName = FileUploadUtils.upload(HuaHengConfig.getFileserverpath(), picture, 1); | |
138 | +//// String fileName = FileUploadUtils.upload(savePath, picture, FileUploadUtils.IMAGE_JPG_EXTENSION); | |
139 | +// String url = httpBase + fileName; | |
140 | +// filePicture.setUrl(url); | |
141 | +// filePicture.setCreated(new Date()); | |
142 | +// filePicture.setIp(ShiroUtils.getIp()); | |
143 | +// filePicture.setSize(size); | |
144 | +// filePicture.setName(filePicture.getName()); | |
145 | +// filePicture.setCreatedBy(ShiroUtils.getLoginName()); | |
146 | +// filePictureService.save(filePicture); | |
147 | +// return AjaxResult.success(filePicture); | |
148 | +// } catch (Exception e) { | |
149 | +// return error("图片上传失败:" + e.getMessage()); | |
150 | +// } | |
151 | + return error("图片上传失败:"); | |
145 | 152 | } |
146 | 153 | |
147 | 154 | /** |
... | ... | @@ -176,9 +183,13 @@ public class FilePictureController extends BaseController { |
176 | 183 | if (StringUtils.isEmpty(ids)) { |
177 | 184 | return AjaxResult.error("id不能为空"); |
178 | 185 | } |
179 | - FilePicture filePicture = filePictureService.getById(ids); | |
180 | - filePicture.setDeleted(1); | |
181 | - filePictureService.updateById(filePicture); | |
186 | + List<String> idList = Arrays.asList(ids); | |
187 | + for (String id : idList) { | |
188 | + FilePicture filePicture = filePictureService.getById(id); | |
189 | + filePicture.setDeleted(1); | |
190 | + filePictureService.updateById(filePicture); | |
191 | + } | |
192 | + | |
182 | 193 | // return toAjax(filePictureService.removeByIds(Arrays.asList(Convert.toIntArray(ids)))); |
183 | 194 | return AjaxResult.success(); |
184 | 195 | } |
... | ... | @@ -206,18 +217,12 @@ public class FilePictureController extends BaseController { |
206 | 217 | for (MultipartFile picture : fileList) { |
207 | 218 | String fileName = ""; //当前上传文件全名称 |
208 | 219 | try { |
209 | - String httpBase = ""; | |
210 | - try { | |
211 | - httpBase = addressService.selectAddress(QuantityConstant.FILE_PICTURE_URL, ShiroUtils.getWarehouseCode(), ""); | |
212 | - } catch (Exception e) { | |
213 | - return AjaxResult.error("上传文件出错,没有配置address表参数" + url_prefix_key + "对应的url"); | |
214 | - } | |
220 | + String httpBase = "http://" + ShiroUtils.getIp() + ":" + ServerIpConfig.getPort()+"/wms/files/"; | |
215 | 221 | String basePath = FileUploadUtils.getFileServerUploadPath(); |
216 | - String subPath = "images/" + DateUtils.getDate() + "/"; | |
217 | - String savePath = basePath + subPath; | |
218 | - fileName = FileUploadUtils.upload(savePath, picture, FileUploadUtils.IMAGE_JPG_EXTENSION); | |
219 | - String url = httpBase + subPath + fileName; | |
222 | + fileName = FileUploadUtils.upload(basePath, picture, FileUploadUtils.IMAGE_JPG_EXTENSION); | |
223 | + String url = httpBase + fileName; | |
220 | 224 | FilePicture filePicture = new FilePicture(); |
225 | + filePicture.setReferType(picture.getContentType()); | |
221 | 226 | filePicture.setUrl(url); |
222 | 227 | filePicture.setCreated(new Date()); |
223 | 228 | filePicture.setIp(ShiroUtils.getIp()); |
... | ... |