|
@@ -2389,7 +2389,7 @@ public class UserSubscribeServiceImpl extends ServiceImpl<UserSubscribeMapper, U
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void updateStudentImage(UpdateStudentImageBo bo) {
|
|
|
+ public String updateStudentImage(UpdateStudentImageBo bo) {
|
|
|
//校验图片是否存在
|
|
|
List<UserStudyRecordPhoto> recordPhotos = iUserStudyRecordPhotoService.getListByPhoto(bo.getImageUrl());
|
|
|
if (CollectionUtils.isEmpty(recordPhotos)){
|
|
@@ -2405,33 +2405,21 @@ public class UserSubscribeServiceImpl extends ServiceImpl<UserSubscribeMapper, U
|
|
|
throw new CustomException("照片和学员不匹配,请检查!");
|
|
|
}
|
|
|
try {
|
|
|
- InputStream in = ossService.getStreamByObject(bo.getImageUrl());
|
|
|
- BufferedImage img = ImageIO.read(in);
|
|
|
- BufferedImage bufferedImage = ImageUtils.rotateImage(img, bo.getDegree());
|
|
|
- OssRequest oss = new OssRequest();
|
|
|
- oss.setImageStatus(0);
|
|
|
- oss.setGradeId(0L);
|
|
|
- oss.setUserId(0L);
|
|
|
-
|
|
|
- //创建一个ByteArrayOutputStream
|
|
|
- ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
- //把BufferedImage写入ByteArrayOutputStream
|
|
|
- ImageIO.write(bufferedImage, "jpg", os);
|
|
|
- //ByteArrayOutputStream转成InputStream
|
|
|
- InputStream input = new ByteArrayInputStream(os.toByteArray());
|
|
|
- //InputStream转成MultipartFile
|
|
|
- MultipartFile multipartFile =new MockMultipartFile(DateUtils.getNowTime().toString(), DateUtils.getNowTime()+".jpg", "text/plain", input);
|
|
|
-
|
|
|
-// //将newImage写入字节数组输出流
|
|
|
-// ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
-// ImageIO.write( bufferedImage, "jpg", baos);
|
|
|
-// //转换为MultipartFile
|
|
|
-// MultipartFile multipartFile = new MockMultipartFile(DateUtils.getNowTime().toString(), baos.toByteArray());
|
|
|
+ String upload = String.format("%s?x-oss-process=image/rotate,%s",bo.getImageUrl(),bo.getDegree());
|
|
|
|
|
|
- oss.setFile(multipartFile);
|
|
|
- String upload = ossService.upload(oss);
|
|
|
List<Long> ids = recordPhotos.stream().map(UserStudyRecordPhoto::getId).collect(Collectors.toList());
|
|
|
iUserStudyRecordPhotoService.updateBatchByIdNotTenant(ids,upload);
|
|
|
+
|
|
|
+ InputStream newUpload = ossService.getStreamByObject(upload);
|
|
|
+ ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
|
|
|
+ byte[] buff = new byte[100];
|
|
|
+ int rc = 0;
|
|
|
+ while ((rc = newUpload.read(buff, 0, 100)) > 0) {
|
|
|
+ swapStream.write(buff, 0, rc);
|
|
|
+ }
|
|
|
+ byte[] image = swapStream.toByteArray();
|
|
|
+ newUpload.close();
|
|
|
+ return Base64.getEncoder().encodeToString(image);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
throw new CustomException("修改图片错误!");
|