加密资源
Showing
2 changed files
with
719 additions
and
7 deletions
| 1 | package com.lego.web.controller.core; | 1 | package com.lego.web.controller.core; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.bean.BeanUtil; | ||
| 4 | import cn.hutool.core.io.IoUtil; | ||
| 5 | import cn.hutool.core.util.ObjectUtil; | ||
| 3 | import com.lego.common.annotation.RepeatSubmit; | 6 | import com.lego.common.annotation.RepeatSubmit; |
| 4 | import com.lego.common.core.controller.BaseController; | 7 | import com.lego.common.core.controller.BaseController; |
| 5 | import com.lego.common.core.domain.R; | 8 | import com.lego.common.core.domain.R; |
| 6 | import com.lego.common.core.page.TableDataInfo; | 9 | import com.lego.common.core.page.TableDataInfo; |
| 10 | import com.lego.common.core.service.ConfigService; | ||
| 11 | import com.lego.common.exception.ServiceException; | ||
| 12 | import com.lego.common.utils.EncryptUtils; | ||
| 13 | import com.lego.common.utils.StringUtils; | ||
| 14 | import com.lego.common.utils.spring.SpringUtils; | ||
| 15 | import com.lego.core.domin.Course; | ||
| 7 | import com.lego.core.domin.bo.BuildingBlockBo; | 16 | import com.lego.core.domin.bo.BuildingBlockBo; |
| 8 | import com.lego.core.domin.bo.BuildingBlockQueryBo; | 17 | import com.lego.core.domin.bo.BuildingBlockQueryBo; |
| 9 | import com.lego.core.domin.bo.CourseBo; | 18 | import com.lego.core.domin.bo.CourseBo; |
| 10 | import com.lego.core.domin.bo.CourseQueryBo; | 19 | import com.lego.core.domin.bo.CourseQueryBo; |
| 11 | import com.lego.core.domin.vo.BuildingBlockVo; | 20 | import com.lego.core.domin.vo.BuildingBlockVo; |
| 12 | import com.lego.core.domin.vo.CourseVo; | 21 | import com.lego.core.domin.vo.CourseVo; |
| 22 | import com.lego.core.mapper.CourseMapper; | ||
| 13 | import com.lego.core.service.IBuildingBlockService; | 23 | import com.lego.core.service.IBuildingBlockService; |
| 14 | import com.lego.core.service.ICourseService; | 24 | import com.lego.core.service.ICourseService; |
| 25 | import com.lego.oss.core.OssClient; | ||
| 26 | import com.lego.oss.entity.UploadResult; | ||
| 27 | import com.lego.oss.factory.OssFactory; | ||
| 28 | import com.lego.system.domain.vo.SysOssVo; | ||
| 29 | import com.lego.system.service.ISysOssService; | ||
| 30 | import com.lego.system.service.impl.SysOssServiceImpl; | ||
| 15 | import lombok.RequiredArgsConstructor; | 31 | import lombok.RequiredArgsConstructor; |
| 16 | import org.springframework.web.bind.annotation.*; | 32 | import org.springframework.web.bind.annotation.*; |
| 17 | 33 | ||
| 18 | import javax.servlet.http.HttpServletRequest; | 34 | import javax.servlet.http.HttpServletRequest; |
| 19 | import javax.validation.Valid; | 35 | import javax.validation.Valid; |
| 36 | import java.io.ByteArrayOutputStream; | ||
| 37 | import java.io.IOException; | ||
| 38 | import java.io.InputStream; | ||
| 39 | import java.io.OutputStream; | ||
| 20 | import java.rmi.ServerException; | 40 | import java.rmi.ServerException; |
| 21 | import java.util.List; | 41 | import java.util.List; |
| 42 | import java.util.Objects; | ||
| 22 | 43 | ||
| 23 | /** | 44 | /** |
| 24 | * 课程 信息操作处理 | 45 | * 课程 信息操作处理 |
| ... | @@ -31,6 +52,8 @@ import java.util.List; | ... | @@ -31,6 +52,8 @@ import java.util.List; |
| 31 | @RequestMapping("/core/course") | 52 | @RequestMapping("/core/course") |
| 32 | public class CourseController extends BaseController { | 53 | public class CourseController extends BaseController { |
| 33 | private final ICourseService service; | 54 | private final ICourseService service; |
| 55 | private final SysOssServiceImpl sysOssService; | ||
| 56 | private final CourseMapper baseMapper; | ||
| 34 | 57 | ||
| 35 | /** | 58 | /** |
| 36 | * 查询列表数据(带分页) | 59 | * 查询列表数据(带分页) |
| ... | @@ -66,6 +89,694 @@ public class CourseController extends BaseController { | ... | @@ -66,6 +89,694 @@ public class CourseController extends BaseController { |
| 66 | return R.ok(service.getById(id)); | 89 | return R.ok(service.getById(id)); |
| 67 | } | 90 | } |
| 68 | 91 | ||
| 92 | @GetMapping("/encrypt") | ||
| 93 | public R<String> encrypt() { | ||
| 94 | List<CourseVo> list = baseMapper.selectVoList(null); | ||
| 95 | OssClient storage = OssFactory.instance(); | ||
| 96 | for (CourseVo courseVo : list) { | ||
| 97 | String ossIds = courseVo.getTwoDimensionalType(); | ||
| 98 | StringBuffer newOssIds = new StringBuffer(""); | ||
| 99 | if(StringUtils.isNotBlank(ossIds)){ | ||
| 100 | String[] arr = ossIds.split(","); | ||
| 101 | for(String ossId : arr) { | ||
| 102 | SysOssVo sysOss = sysOssService.getById(Long.valueOf(ossId)); | ||
| 103 | if (ObjectUtil.isNull(sysOss)) { | ||
| 104 | } else { | ||
| 105 | String originalfileName = sysOss.getOriginalName(); | ||
| 106 | String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length()); | ||
| 107 | UploadResult uploadResult = null; | ||
| 108 | if (".pdf".equals(suffix)) { | ||
| 109 | byte[] fileBytes = null; | ||
| 110 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 111 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 112 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 113 | int bytesRead; | ||
| 114 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 115 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 116 | } | ||
| 117 | byteArrayOutputStream.flush(); | ||
| 118 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 119 | } catch (IOException e) { | ||
| 120 | System.out.println(e.getMessage()); | ||
| 121 | } | ||
| 122 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 123 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "application/pdf"); | ||
| 124 | } else if (".mp4".equals(suffix)) { | ||
| 125 | byte[] fileBytes = null; | ||
| 126 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 127 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 128 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 129 | int bytesRead; | ||
| 130 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 131 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 132 | } | ||
| 133 | byteArrayOutputStream.flush(); | ||
| 134 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 135 | } catch (IOException e) { | ||
| 136 | System.out.println(e.getMessage()); | ||
| 137 | } | ||
| 138 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 139 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "video/mpeg4"); | ||
| 140 | } else if (".json".equals(suffix)) { | ||
| 141 | byte[] fileBytes = null; | ||
| 142 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 143 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 144 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 145 | int bytesRead; | ||
| 146 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 147 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 148 | } | ||
| 149 | byteArrayOutputStream.flush(); | ||
| 150 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 151 | } catch (IOException e) { | ||
| 152 | System.out.println(e.getMessage()); | ||
| 153 | } | ||
| 154 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 155 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 156 | } else if (".ldr".equals(suffix)) { | ||
| 157 | byte[] fileBytes = null; | ||
| 158 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 159 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 160 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 161 | int bytesRead; | ||
| 162 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 163 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 164 | } | ||
| 165 | byteArrayOutputStream.flush(); | ||
| 166 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 167 | } catch (IOException e) { | ||
| 168 | System.out.println(e.getMessage()); | ||
| 169 | } | ||
| 170 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 171 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 172 | } | ||
| 173 | if (Objects.nonNull(uploadResult)) { | ||
| 174 | // 保存文件信息 | ||
| 175 | SysOssVo vo = sysOssService.buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult); | ||
| 176 | newOssIds.append(vo.getOssId()).append( ","); | ||
| 177 | } | ||
| 178 | } | ||
| 179 | } | ||
| 180 | if(newOssIds.toString().lastIndexOf(",") != -1){ | ||
| 181 | newOssIds.deleteCharAt(newOssIds.length()-1); | ||
| 182 | } | ||
| 183 | if(StringUtils.isNotBlank(newOssIds.toString())) { | ||
| 184 | courseVo.setTwoDimensionalType(newOssIds.toString()); | ||
| 185 | CourseBo courseBo = BeanUtil.toBean(courseVo, CourseBo.class); | ||
| 186 | try { | ||
| 187 | service.updateCourse(courseBo); | ||
| 188 | } catch (Exception e) { | ||
| 189 | System.out.println(e.getMessage()); | ||
| 190 | } | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | ossIds = courseVo.getTwoDimensionalUrl(); | ||
| 195 | newOssIds = new StringBuffer(""); | ||
| 196 | if(StringUtils.isNotBlank(ossIds)){ | ||
| 197 | String[] arr = ossIds.split(","); | ||
| 198 | for(String ossId : arr) { | ||
| 199 | SysOssVo sysOss = sysOssService.getById(Long.valueOf(ossId)); | ||
| 200 | if (ObjectUtil.isNull(sysOss)) { | ||
| 201 | } else { | ||
| 202 | String originalfileName = sysOss.getOriginalName(); | ||
| 203 | String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length()); | ||
| 204 | UploadResult uploadResult = null; | ||
| 205 | if (".pdf".equals(suffix)) { | ||
| 206 | byte[] fileBytes = null; | ||
| 207 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 208 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 209 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 210 | int bytesRead; | ||
| 211 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 212 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 213 | } | ||
| 214 | byteArrayOutputStream.flush(); | ||
| 215 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 216 | } catch (IOException e) { | ||
| 217 | System.out.println(e.getMessage()); | ||
| 218 | } | ||
| 219 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 220 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "application/pdf"); | ||
| 221 | } else if (".mp4".equals(suffix)) { | ||
| 222 | byte[] fileBytes = null; | ||
| 223 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 224 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 225 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 226 | int bytesRead; | ||
| 227 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 228 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 229 | } | ||
| 230 | byteArrayOutputStream.flush(); | ||
| 231 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 232 | } catch (IOException e) { | ||
| 233 | System.out.println(e.getMessage()); | ||
| 234 | } | ||
| 235 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 236 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "video/mpeg4"); | ||
| 237 | } else if (".json".equals(suffix)) { | ||
| 238 | byte[] fileBytes = null; | ||
| 239 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 240 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 241 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 242 | int bytesRead; | ||
| 243 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 244 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 245 | } | ||
| 246 | byteArrayOutputStream.flush(); | ||
| 247 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 248 | } catch (IOException e) { | ||
| 249 | System.out.println(e.getMessage()); | ||
| 250 | } | ||
| 251 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 252 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 253 | } else if (".ldr".equals(suffix)) { | ||
| 254 | byte[] fileBytes = null; | ||
| 255 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 256 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 257 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 258 | int bytesRead; | ||
| 259 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 260 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 261 | } | ||
| 262 | byteArrayOutputStream.flush(); | ||
| 263 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 264 | } catch (IOException e) { | ||
| 265 | System.out.println(e.getMessage()); | ||
| 266 | } | ||
| 267 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 268 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 269 | } | ||
| 270 | if (Objects.nonNull(uploadResult)) { | ||
| 271 | // 保存文件信息 | ||
| 272 | SysOssVo vo = sysOssService.buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult); | ||
| 273 | newOssIds.append(vo.getOssId()).append( ","); | ||
| 274 | } | ||
| 275 | } | ||
| 276 | } | ||
| 277 | if(newOssIds.toString().lastIndexOf(",") != -1){ | ||
| 278 | newOssIds.deleteCharAt(newOssIds.length()-1); | ||
| 279 | } | ||
| 280 | if(StringUtils.isNotBlank(newOssIds.toString())) { | ||
| 281 | courseVo.setTwoDimensionalUrl(newOssIds.toString()); | ||
| 282 | CourseBo courseBo = BeanUtil.toBean(courseVo, CourseBo.class); | ||
| 283 | try { | ||
| 284 | service.updateCourse(courseBo); | ||
| 285 | } catch (Exception e) { | ||
| 286 | System.out.println(e.getMessage()); | ||
| 287 | } | ||
| 288 | } | ||
| 289 | } | ||
| 290 | |||
| 291 | ossIds = courseVo.getThreeDimensionalType(); | ||
| 292 | newOssIds = new StringBuffer(""); | ||
| 293 | if(StringUtils.isNotBlank(ossIds)){ | ||
| 294 | String[] arr = ossIds.split(","); | ||
| 295 | for(String ossId : arr) { | ||
| 296 | SysOssVo sysOss = sysOssService.getById(Long.valueOf(ossId)); | ||
| 297 | if (ObjectUtil.isNull(sysOss)) { | ||
| 298 | } else { | ||
| 299 | String originalfileName = sysOss.getOriginalName(); | ||
| 300 | String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length()); | ||
| 301 | UploadResult uploadResult = null; | ||
| 302 | if (".pdf".equals(suffix)) { | ||
| 303 | byte[] fileBytes = null; | ||
| 304 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 305 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 306 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 307 | int bytesRead; | ||
| 308 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 309 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 310 | } | ||
| 311 | byteArrayOutputStream.flush(); | ||
| 312 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 313 | } catch (IOException e) { | ||
| 314 | System.out.println(e.getMessage()); | ||
| 315 | } | ||
| 316 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 317 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "application/pdf"); | ||
| 318 | } else if (".mp4".equals(suffix)) { | ||
| 319 | byte[] fileBytes = null; | ||
| 320 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 321 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 322 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 323 | int bytesRead; | ||
| 324 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 325 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 326 | } | ||
| 327 | byteArrayOutputStream.flush(); | ||
| 328 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 329 | } catch (IOException e) { | ||
| 330 | System.out.println(e.getMessage()); | ||
| 331 | } | ||
| 332 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 333 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "video/mpeg4"); | ||
| 334 | } else if (".json".equals(suffix)) { | ||
| 335 | byte[] fileBytes = null; | ||
| 336 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 337 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 338 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 339 | int bytesRead; | ||
| 340 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 341 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 342 | } | ||
| 343 | byteArrayOutputStream.flush(); | ||
| 344 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 345 | } catch (IOException e) { | ||
| 346 | System.out.println(e.getMessage()); | ||
| 347 | } | ||
| 348 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 349 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 350 | } else if (".ldr".equals(suffix)) { | ||
| 351 | byte[] fileBytes = null; | ||
| 352 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 353 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 354 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 355 | int bytesRead; | ||
| 356 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 357 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 358 | } | ||
| 359 | byteArrayOutputStream.flush(); | ||
| 360 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 361 | } catch (IOException e) { | ||
| 362 | System.out.println(e.getMessage()); | ||
| 363 | } | ||
| 364 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 365 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 366 | } | ||
| 367 | if (Objects.nonNull(uploadResult)) { | ||
| 368 | // 保存文件信息 | ||
| 369 | SysOssVo vo = sysOssService.buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult); | ||
| 370 | newOssIds.append(vo.getOssId()).append( ","); | ||
| 371 | } | ||
| 372 | } | ||
| 373 | } | ||
| 374 | if(newOssIds.toString().lastIndexOf(",") != -1){ | ||
| 375 | newOssIds.deleteCharAt(newOssIds.length()-1); | ||
| 376 | } | ||
| 377 | if(StringUtils.isNotBlank(newOssIds.toString())) { | ||
| 378 | courseVo.setThreeDimensionalType(newOssIds.toString()); | ||
| 379 | CourseBo courseBo = BeanUtil.toBean(courseVo, CourseBo.class); | ||
| 380 | try { | ||
| 381 | service.updateCourse(courseBo); | ||
| 382 | } catch (Exception e) { | ||
| 383 | System.out.println(e.getMessage()); | ||
| 384 | } | ||
| 385 | } | ||
| 386 | } | ||
| 387 | |||
| 388 | ossIds = courseVo.getThreeDimensionalUrl(); | ||
| 389 | newOssIds = new StringBuffer(""); | ||
| 390 | if(StringUtils.isNotBlank(ossIds)){ | ||
| 391 | String[] arr = ossIds.split(","); | ||
| 392 | for(String ossId : arr) { | ||
| 393 | SysOssVo sysOss = sysOssService.getById(Long.valueOf(ossId)); | ||
| 394 | if (ObjectUtil.isNull(sysOss)) { | ||
| 395 | } else { | ||
| 396 | String originalfileName = sysOss.getOriginalName(); | ||
| 397 | String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length()); | ||
| 398 | UploadResult uploadResult = null; | ||
| 399 | if (".pdf".equals(suffix)) { | ||
| 400 | byte[] fileBytes = null; | ||
| 401 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 402 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 403 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 404 | int bytesRead; | ||
| 405 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 406 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 407 | } | ||
| 408 | byteArrayOutputStream.flush(); | ||
| 409 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 410 | } catch (IOException e) { | ||
| 411 | System.out.println(e.getMessage()); | ||
| 412 | } | ||
| 413 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 414 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "application/pdf"); | ||
| 415 | } else if (".mp4".equals(suffix)) { | ||
| 416 | byte[] fileBytes = null; | ||
| 417 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 418 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 419 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 420 | int bytesRead; | ||
| 421 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 422 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 423 | } | ||
| 424 | byteArrayOutputStream.flush(); | ||
| 425 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 426 | } catch (IOException e) { | ||
| 427 | System.out.println(e.getMessage()); | ||
| 428 | } | ||
| 429 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 430 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "video/mpeg4"); | ||
| 431 | } else if (".json".equals(suffix)) { | ||
| 432 | byte[] fileBytes = null; | ||
| 433 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 434 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 435 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 436 | int bytesRead; | ||
| 437 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 438 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 439 | } | ||
| 440 | byteArrayOutputStream.flush(); | ||
| 441 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 442 | } catch (IOException e) { | ||
| 443 | System.out.println(e.getMessage()); | ||
| 444 | } | ||
| 445 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 446 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 447 | } else if (".ldr".equals(suffix)) { | ||
| 448 | byte[] fileBytes = null; | ||
| 449 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 450 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 451 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 452 | int bytesRead; | ||
| 453 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 454 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 455 | } | ||
| 456 | byteArrayOutputStream.flush(); | ||
| 457 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 458 | } catch (IOException e) { | ||
| 459 | System.out.println(e.getMessage()); | ||
| 460 | } | ||
| 461 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 462 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 463 | } | ||
| 464 | if (Objects.nonNull(uploadResult)) { | ||
| 465 | // 保存文件信息 | ||
| 466 | SysOssVo vo = sysOssService.buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult); | ||
| 467 | newOssIds.append(vo.getOssId()).append( ","); | ||
| 468 | } | ||
| 469 | } | ||
| 470 | } | ||
| 471 | if(newOssIds.toString().lastIndexOf(",") != -1){ | ||
| 472 | newOssIds.deleteCharAt(newOssIds.length()-1); | ||
| 473 | } | ||
| 474 | if(StringUtils.isNotBlank(newOssIds.toString())) { | ||
| 475 | courseVo.setThreeDimensionalUrl(newOssIds.toString()); | ||
| 476 | CourseBo courseBo = BeanUtil.toBean(courseVo, CourseBo.class); | ||
| 477 | try { | ||
| 478 | service.updateCourse(courseBo); | ||
| 479 | } catch (Exception e) { | ||
| 480 | System.out.println(e.getMessage()); | ||
| 481 | } | ||
| 482 | } | ||
| 483 | } | ||
| 484 | |||
| 485 | ossIds = courseVo.getCaseOssId(); | ||
| 486 | newOssIds = new StringBuffer(""); | ||
| 487 | if(StringUtils.isNotBlank(ossIds)){ | ||
| 488 | String[] arr = ossIds.split(","); | ||
| 489 | for(String ossId : arr) { | ||
| 490 | SysOssVo sysOss = sysOssService.getById(Long.valueOf(ossId)); | ||
| 491 | if (ObjectUtil.isNull(sysOss)) { | ||
| 492 | } else { | ||
| 493 | String originalfileName = sysOss.getOriginalName(); | ||
| 494 | String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length()); | ||
| 495 | UploadResult uploadResult = null; | ||
| 496 | if (".pdf".equals(suffix)) { | ||
| 497 | byte[] fileBytes = null; | ||
| 498 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 499 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 500 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 501 | int bytesRead; | ||
| 502 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 503 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 504 | } | ||
| 505 | byteArrayOutputStream.flush(); | ||
| 506 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 507 | } catch (IOException e) { | ||
| 508 | System.out.println(e.getMessage()); | ||
| 509 | } | ||
| 510 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 511 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "application/pdf"); | ||
| 512 | } else if (".mp4".equals(suffix)) { | ||
| 513 | byte[] fileBytes = null; | ||
| 514 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 515 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 516 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 517 | int bytesRead; | ||
| 518 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 519 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 520 | } | ||
| 521 | byteArrayOutputStream.flush(); | ||
| 522 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 523 | } catch (IOException e) { | ||
| 524 | System.out.println(e.getMessage()); | ||
| 525 | } | ||
| 526 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 527 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "video/mpeg4"); | ||
| 528 | } else if (".json".equals(suffix)) { | ||
| 529 | byte[] fileBytes = null; | ||
| 530 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 531 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 532 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 533 | int bytesRead; | ||
| 534 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 535 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 536 | } | ||
| 537 | byteArrayOutputStream.flush(); | ||
| 538 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 539 | } catch (IOException e) { | ||
| 540 | System.out.println(e.getMessage()); | ||
| 541 | } | ||
| 542 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 543 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 544 | } else if (".ldr".equals(suffix)) { | ||
| 545 | byte[] fileBytes = null; | ||
| 546 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 547 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 548 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 549 | int bytesRead; | ||
| 550 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 551 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 552 | } | ||
| 553 | byteArrayOutputStream.flush(); | ||
| 554 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 555 | } catch (IOException e) { | ||
| 556 | System.out.println(e.getMessage()); | ||
| 557 | } | ||
| 558 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 559 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 560 | } | ||
| 561 | if (Objects.nonNull(uploadResult)) { | ||
| 562 | // 保存文件信息 | ||
| 563 | SysOssVo vo = sysOssService.buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult); | ||
| 564 | newOssIds.append(vo.getOssId()).append( ","); | ||
| 565 | } | ||
| 566 | } | ||
| 567 | } | ||
| 568 | if(newOssIds.toString().lastIndexOf(",") != -1){ | ||
| 569 | newOssIds.deleteCharAt(newOssIds.length()-1); | ||
| 570 | } | ||
| 571 | if(StringUtils.isNotBlank(newOssIds.toString())) { | ||
| 572 | courseVo.setCaseOssId(newOssIds.toString()); | ||
| 573 | CourseBo courseBo = BeanUtil.toBean(courseVo, CourseBo.class); | ||
| 574 | try { | ||
| 575 | service.updateCourse(courseBo); | ||
| 576 | } catch (Exception e) { | ||
| 577 | System.out.println(e.getMessage()); | ||
| 578 | } | ||
| 579 | } | ||
| 580 | } | ||
| 581 | |||
| 582 | ossIds = courseVo.getTeachingOssId(); | ||
| 583 | newOssIds = new StringBuffer(""); | ||
| 584 | if(StringUtils.isNotBlank(ossIds)){ | ||
| 585 | String[] arr = ossIds.split(","); | ||
| 586 | for(String ossId : arr) { | ||
| 587 | SysOssVo sysOss = sysOssService.getById(Long.valueOf(ossId)); | ||
| 588 | if (ObjectUtil.isNull(sysOss)) { | ||
| 589 | } else { | ||
| 590 | String originalfileName = sysOss.getOriginalName(); | ||
| 591 | String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length()); | ||
| 592 | UploadResult uploadResult = null; | ||
| 593 | if (".pdf".equals(suffix)) { | ||
| 594 | byte[] fileBytes = null; | ||
| 595 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 596 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 597 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 598 | int bytesRead; | ||
| 599 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 600 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 601 | } | ||
| 602 | byteArrayOutputStream.flush(); | ||
| 603 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 604 | } catch (IOException e) { | ||
| 605 | System.out.println(e.getMessage()); | ||
| 606 | } | ||
| 607 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 608 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "application/pdf"); | ||
| 609 | } else if (".mp4".equals(suffix)) { | ||
| 610 | byte[] fileBytes = null; | ||
| 611 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 612 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 613 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 614 | int bytesRead; | ||
| 615 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 616 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 617 | } | ||
| 618 | byteArrayOutputStream.flush(); | ||
| 619 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 620 | } catch (IOException e) { | ||
| 621 | System.out.println(e.getMessage()); | ||
| 622 | } | ||
| 623 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 624 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "video/mpeg4"); | ||
| 625 | } else if (".json".equals(suffix)) { | ||
| 626 | byte[] fileBytes = null; | ||
| 627 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 628 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 629 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 630 | int bytesRead; | ||
| 631 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 632 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 633 | } | ||
| 634 | byteArrayOutputStream.flush(); | ||
| 635 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 636 | } catch (IOException e) { | ||
| 637 | System.out.println(e.getMessage()); | ||
| 638 | } | ||
| 639 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 640 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 641 | } else if (".ldr".equals(suffix)) { | ||
| 642 | byte[] fileBytes = null; | ||
| 643 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 644 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 645 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 646 | int bytesRead; | ||
| 647 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 648 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 649 | } | ||
| 650 | byteArrayOutputStream.flush(); | ||
| 651 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 652 | } catch (IOException e) { | ||
| 653 | System.out.println(e.getMessage()); | ||
| 654 | } | ||
| 655 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 656 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 657 | } | ||
| 658 | if (Objects.nonNull(uploadResult)) { | ||
| 659 | // 保存文件信息 | ||
| 660 | SysOssVo vo = sysOssService.buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult); | ||
| 661 | newOssIds.append(vo.getOssId()).append( ","); | ||
| 662 | } | ||
| 663 | } | ||
| 664 | } | ||
| 665 | if(newOssIds.toString().lastIndexOf(",") != -1){ | ||
| 666 | newOssIds.deleteCharAt(newOssIds.length()-1); | ||
| 667 | } | ||
| 668 | if(StringUtils.isNotBlank(newOssIds.toString())) { | ||
| 669 | courseVo.setTeachingOssId(newOssIds.toString()); | ||
| 670 | CourseBo courseBo = BeanUtil.toBean(courseVo, CourseBo.class); | ||
| 671 | try { | ||
| 672 | service.updateCourse(courseBo); | ||
| 673 | } catch (Exception e) { | ||
| 674 | System.out.println(e.getMessage()); | ||
| 675 | } | ||
| 676 | } | ||
| 677 | } | ||
| 678 | |||
| 679 | ossIds = courseVo.getPptOssId(); | ||
| 680 | newOssIds = new StringBuffer(""); | ||
| 681 | if(StringUtils.isNotBlank(ossIds)){ | ||
| 682 | String[] arr = ossIds.split(","); | ||
| 683 | for(String ossId : arr) { | ||
| 684 | SysOssVo sysOss = sysOssService.getById(Long.valueOf(ossId)); | ||
| 685 | if (ObjectUtil.isNull(sysOss)) { | ||
| 686 | } else { | ||
| 687 | String originalfileName = sysOss.getOriginalName(); | ||
| 688 | String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length()); | ||
| 689 | UploadResult uploadResult = null; | ||
| 690 | if (".pdf".equals(suffix)) { | ||
| 691 | byte[] fileBytes = null; | ||
| 692 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 693 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 694 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 695 | int bytesRead; | ||
| 696 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 697 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 698 | } | ||
| 699 | byteArrayOutputStream.flush(); | ||
| 700 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 701 | } catch (IOException e) { | ||
| 702 | System.out.println(e.getMessage()); | ||
| 703 | } | ||
| 704 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 705 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "application/pdf"); | ||
| 706 | } else if (".mp4".equals(suffix)) { | ||
| 707 | byte[] fileBytes = null; | ||
| 708 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 709 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 710 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 711 | int bytesRead; | ||
| 712 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 713 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 714 | } | ||
| 715 | byteArrayOutputStream.flush(); | ||
| 716 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 717 | } catch (IOException e) { | ||
| 718 | System.out.println(e.getMessage()); | ||
| 719 | } | ||
| 720 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 721 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "video/mpeg4"); | ||
| 722 | } else if (".json".equals(suffix)) { | ||
| 723 | byte[] fileBytes = null; | ||
| 724 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 725 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 726 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 727 | int bytesRead; | ||
| 728 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 729 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 730 | } | ||
| 731 | byteArrayOutputStream.flush(); | ||
| 732 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 733 | } catch (IOException e) { | ||
| 734 | System.out.println(e.getMessage()); | ||
| 735 | } | ||
| 736 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 737 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 738 | } else if (".ldr".equals(suffix)) { | ||
| 739 | byte[] fileBytes = null; | ||
| 740 | try (InputStream inputStream = storage.getObjectContent(sysOss.getUrl())) { | ||
| 741 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); | ||
| 742 | byte[] buffer = new byte[8192]; // 或者根据实际情况选择合适的缓冲区大小 | ||
| 743 | int bytesRead; | ||
| 744 | while ((bytesRead = inputStream.read(buffer)) != -1) { | ||
| 745 | byteArrayOutputStream.write(buffer, 0, bytesRead); | ||
| 746 | } | ||
| 747 | byteArrayOutputStream.flush(); | ||
| 748 | fileBytes = byteArrayOutputStream.toByteArray(); | ||
| 749 | } catch (IOException e) { | ||
| 750 | System.out.println(e.getMessage()); | ||
| 751 | } | ||
| 752 | byte[] encryptBytes = EncryptUtils.encryptByAes(fileBytes); | ||
| 753 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, "text/plain"); | ||
| 754 | } | ||
| 755 | if (Objects.nonNull(uploadResult)) { | ||
| 756 | // 保存文件信息 | ||
| 757 | SysOssVo vo = sysOssService.buildResultEntity(originalfileName, suffix, storage.getConfigKey(), uploadResult); | ||
| 758 | newOssIds.append(vo.getOssId()).append( ","); | ||
| 759 | } | ||
| 760 | } | ||
| 761 | } | ||
| 762 | if(newOssIds.toString().lastIndexOf(",") != -1){ | ||
| 763 | newOssIds.deleteCharAt(newOssIds.length()-1); | ||
| 764 | } | ||
| 765 | if(StringUtils.isNotBlank(newOssIds.toString())) { | ||
| 766 | courseVo.setPptOssId(newOssIds.toString()); | ||
| 767 | CourseBo courseBo = BeanUtil.toBean(courseVo, CourseBo.class); | ||
| 768 | try { | ||
| 769 | service.updateCourse(courseBo); | ||
| 770 | } catch (Exception e) { | ||
| 771 | System.out.println(e.getMessage()); | ||
| 772 | } | ||
| 773 | } | ||
| 774 | } | ||
| 775 | |||
| 776 | } | ||
| 777 | return R.ok("game is over"); | ||
| 778 | } | ||
| 779 | |||
| 69 | /** | 780 | /** |
| 70 | * 新增 | 781 | * 新增 |
| 71 | * | 782 | * | ... | ... |
| ... | @@ -210,13 +210,14 @@ public class SysOssServiceImpl implements ISysOssService, OssService { | ... | @@ -210,13 +210,14 @@ public class SysOssServiceImpl implements ISysOssService, OssService { |
| 210 | OssClient storage = OssFactory.instance(); | 210 | OssClient storage = OssFactory.instance(); |
| 211 | UploadResult uploadResult; | 211 | UploadResult uploadResult; |
| 212 | try { | 212 | try { |
| 213 | if(".pdf".equals(suffix) || ".mp4".equals(suffix) || ".json".equals(suffix) || ".ldr".equals(suffix)) { | 213 | // if(".pdf".equals(suffix) || ".mp4".equals(suffix) || ".json".equals(suffix) || ".ldr".equals(suffix)) { |
| 214 | byte[] encryptBytes = EncryptUtils.encryptByAes(file.getBytes()); | 214 | // byte[] encryptBytes = EncryptUtils.encryptByAes(file.getBytes()); |
| 215 | uploadResult = storage.uploadSuffix(encryptBytes, suffix, file.getContentType()); | 215 | // uploadResult = storage.uploadSuffix(encryptBytes, suffix, file.getContentType()); |
| 216 | } | 216 | // } |
| 217 | else{ | 217 | // else{ |
| 218 | // uploadResult = storage.upload(file.getBytes(), originalfileName, file.getContentType()); | ||
| 219 | // } | ||
| 218 | uploadResult = storage.upload(file.getBytes(), originalfileName, file.getContentType()); | 220 | uploadResult = storage.upload(file.getBytes(), originalfileName, file.getContentType()); |
| 219 | } | ||
| 220 | } catch (IOException e) { | 221 | } catch (IOException e) { |
| 221 | throw new ServiceException(e.getMessage()); | 222 | throw new ServiceException(e.getMessage()); |
| 222 | } | 223 | } |
| ... | @@ -258,7 +259,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService { | ... | @@ -258,7 +259,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService { |
| 258 | return vo; | 259 | return vo; |
| 259 | } | 260 | } |
| 260 | 261 | ||
| 261 | private SysOssVo buildResultEntity(String originalfileName, String suffix, String configKey, UploadResult uploadResult) { | 262 | public SysOssVo buildResultEntity(String originalfileName, String suffix, String configKey, UploadResult uploadResult) { |
| 262 | SysOss oss = new SysOss(); | 263 | SysOss oss = new SysOss(); |
| 263 | oss.setUrl(uploadResult.getUrl()); | 264 | oss.setUrl(uploadResult.getUrl()); |
| 264 | oss.setFileSuffix(suffix); | 265 | oss.setFileSuffix(suffix); | ... | ... |
-
Please register or sign in to post a comment