|
|
|
@ -5,16 +5,19 @@ import com.shxy.xymanager_common.entity.TerminalPhotoExample;
|
|
|
|
|
import com.shxy.xymanager_common.model.PhotoPrepareModel;
|
|
|
|
|
import com.shxy.xymanager_common.util.DateUtil;
|
|
|
|
|
import com.shxy.xymanager_dao.dao.TerminalPhotoDao;
|
|
|
|
|
import io.sigpipe.jbsdiff.Patch;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
@ -41,7 +44,6 @@ public class AsyncService {
|
|
|
|
|
private void saveOnePreparePhoto(PhotoPrepareModel item) {
|
|
|
|
|
TerminalPhoto record = item.getRecord();
|
|
|
|
|
String cmdid = item.getCmdid();
|
|
|
|
|
MultipartFile file = item.getFile();
|
|
|
|
|
String hexC = item.getHexC();
|
|
|
|
|
Integer termId = item.getTermId();
|
|
|
|
|
Long photoId = item.getPhotoId();
|
|
|
|
@ -60,8 +62,8 @@ public class AsyncService {
|
|
|
|
|
String filePath = folder + "/" + filename;
|
|
|
|
|
|
|
|
|
|
File dest = new File(C_PATH + filePath);
|
|
|
|
|
try {
|
|
|
|
|
file.transferTo(dest);
|
|
|
|
|
try (FileOutputStream fos = new FileOutputStream(dest)) {
|
|
|
|
|
fos.write(item.getData());
|
|
|
|
|
log.info("成功上传一张图片" + filePath);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("保存上传的图片失败, cmdid=" + cmdid + ", fileName=" + fileName);
|
|
|
|
@ -103,4 +105,46 @@ public class AsyncService {
|
|
|
|
|
terminalPhotoDao.updateByPrimaryKey(record);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Async
|
|
|
|
|
public void savePreparePatchs(List<PhotoPrepareModel> list) {
|
|
|
|
|
for (PhotoPrepareModel item : list) {
|
|
|
|
|
this.patchOnePhoto(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void patchOnePhoto(PhotoPrepareModel item) {
|
|
|
|
|
Integer termId = item.getTermId();
|
|
|
|
|
Integer oid = item.getOid();
|
|
|
|
|
TerminalPhotoExample example = new TerminalPhotoExample();
|
|
|
|
|
TerminalPhotoExample.Criteria criteria = example.createCriteria();
|
|
|
|
|
criteria.andTermIdEqualTo(termId);
|
|
|
|
|
criteria.andOrginalIdEqualTo(oid);
|
|
|
|
|
List<TerminalPhoto> list = terminalPhotoDao.selectByExample(example);
|
|
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
log.error("没有找到base图片,termId=" + termId + ", oid=" + oid);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String filePath = list.get(0).getPath();
|
|
|
|
|
byte[] oldIn;
|
|
|
|
|
try {
|
|
|
|
|
oldIn = Files.readAllBytes(Paths.get(C_PATH + filePath));
|
|
|
|
|
String suffix = StringUtils.getFilenameExtension(filePath);
|
|
|
|
|
item.setSuffix(suffix);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("读取base图片失败" + filePath);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
|
|
try {
|
|
|
|
|
Patch.patch(oldIn, item.getData(), baos);
|
|
|
|
|
byte[] data = baos.toByteArray();
|
|
|
|
|
item.setData(data);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("patch合并图片失败.", e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.saveOnePreparePhoto(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|