|
|
|
@ -1,15 +1,29 @@ |
|
|
|
package com.bnyer.file.service.impl; |
|
|
|
|
|
|
|
import com.bnyer.file.dto.FileDto; |
|
|
|
import com.bnyer.file.dto.FileUploadDto; |
|
|
|
import com.bnyer.file.service.IFileService; |
|
|
|
import com.bnyer.file.service.IQiniuService; |
|
|
|
import com.bnyer.file.service.ITikTokImage; |
|
|
|
import com.bnyer.file.utils.ImgUtil; |
|
|
|
import com.bnyer.file.vo.ChekFileVo; |
|
|
|
import com.bnyer.file.vo.TiktokImgVo; |
|
|
|
import com.bnyer.img.api.RemoteImgService; |
|
|
|
import com.bnyer.img.api.dto.TiktokImgMiniDto; |
|
|
|
import com.bnyer.system.api.RemoteFileService; |
|
|
|
import org.apache.http.entity.ContentType; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.mock.web.MockMultipartFile; |
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author: Yeman |
|
|
|
@ -22,6 +36,8 @@ public class FileServiceImpl implements IFileService { |
|
|
|
private IQiniuService qiniuService; |
|
|
|
@Autowired |
|
|
|
private ITikTokImage tikTokImage; |
|
|
|
@Autowired |
|
|
|
private RemoteImgService remoteImgService; |
|
|
|
@Override |
|
|
|
public ArrayList<ChekFileVo> checkImg(ArrayList<MultipartFile> multipartFiles) { |
|
|
|
ArrayList<ChekFileVo> chekFileVos = new ArrayList<>(); |
|
|
|
@ -29,21 +45,22 @@ public class FileServiceImpl implements IFileService { |
|
|
|
ArrayList<MultipartFile> multipartFileList = qiniuService.checkImageFormat(multipartFiles); |
|
|
|
for (MultipartFile multipartFile : multipartFileList) { |
|
|
|
ChekFileVo chekFileVo = new ChekFileVo(); |
|
|
|
chekFileVo.setFile(multipartFile); |
|
|
|
String filename = multipartFile.getResource().getFilename(); |
|
|
|
chekFileVo.setFileName(filename); |
|
|
|
String imageString = ImgUtil.getImageString(multipartFile); |
|
|
|
String checkMsg = qiniuService.checkImageContent("data:application/octet-stream;base64," +imageString); |
|
|
|
if (checkMsg.equals("pass")){ |
|
|
|
//抖音图片检测二次检测
|
|
|
|
if (tikTokImage.checkImageContent(multipartFile)) { |
|
|
|
// if (tikTokImage.checkImageContent(multipartFile)) {
|
|
|
|
//可以通过
|
|
|
|
chekFileVo.setStatus("1"); |
|
|
|
chekFileVos.add(chekFileVo); |
|
|
|
}else { |
|
|
|
//不可以通过
|
|
|
|
chekFileVo.setStatus("2"); |
|
|
|
chekFileVos.add(chekFileVo); |
|
|
|
} |
|
|
|
// }else {
|
|
|
|
// //不可以通过
|
|
|
|
// chekFileVo.setStatus("2");
|
|
|
|
// chekFileVos.add(chekFileVo);
|
|
|
|
// }
|
|
|
|
continue; |
|
|
|
} |
|
|
|
if (checkMsg.equals("review")){ |
|
|
|
@ -60,4 +77,29 @@ public class FileServiceImpl implements IFileService { |
|
|
|
} |
|
|
|
return chekFileVos; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Async("mySimpleAsync") |
|
|
|
public void checkUploadSave(FileUploadDto fileUploadDto) throws IOException { |
|
|
|
ArrayList<MultipartFile> multipartFiles = new ArrayList<>(); |
|
|
|
for (FileDto fileDto : fileUploadDto.getFiles()) { |
|
|
|
InputStream inputStream = new ByteArrayInputStream(fileDto.getBytes()); |
|
|
|
MultipartFile files = new MockMultipartFile(fileDto.getName(), fileDto.getOriginalFilename(), ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream); |
|
|
|
//System.out.println(files.getSize());
|
|
|
|
multipartFiles.add(files); |
|
|
|
} |
|
|
|
|
|
|
|
//检测图片
|
|
|
|
for (ChekFileVo chekFileVo : checkImg(multipartFiles)) { |
|
|
|
//图片上传
|
|
|
|
String imgUrl = qiniuService.userUpload(chekFileVo.getFile()); |
|
|
|
TiktokImgMiniDto tiktokImg = new TiktokImgMiniDto(); |
|
|
|
tiktokImg.setImgUrl(imgUrl); |
|
|
|
tiktokImg.setStatus(chekFileVo.getStatus()); |
|
|
|
tiktokImg.setTypeId(fileUploadDto.getTypeId()); |
|
|
|
tiktokImg.setCreatorId(fileUploadDto.getCreatorId()); |
|
|
|
remoteImgService.insertTiktokImg(tiktokImg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|