|
|
|
@ -427,13 +427,21 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void upload(MultipartFile file, String cmdid) throws Exception {
|
|
|
|
|
public void uploadPhotos(MultipartFile[] files, String cmdid) throws Exception {
|
|
|
|
|
Terminals term = terminalExtService.getByCmdid(cmdid);
|
|
|
|
|
if (term == null) {
|
|
|
|
|
throw new ApiException(cmdid + "该装置不存在");
|
|
|
|
|
}
|
|
|
|
|
for (MultipartFile file : files) {
|
|
|
|
|
this.uploadOnePhoto(file, cmdid, term.getId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void uploadOnePhoto(MultipartFile file, String cmdid, Integer termId) throws Exception {
|
|
|
|
|
|
|
|
|
|
String suffix;
|
|
|
|
|
String hexC = "";
|
|
|
|
|
Long photoId;
|
|
|
|
|
Long time;
|
|
|
|
|
TerminalPhoto record = new TerminalPhoto();
|
|
|
|
|
try {
|
|
|
|
@ -441,7 +449,7 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
|
|
|
|
|
suffix = org.springframework.util.StringUtils.getFilenameExtension(fileName);
|
|
|
|
|
String prefix = fileName.replace("." + suffix, "");
|
|
|
|
|
String[] str = prefix.split("_");
|
|
|
|
|
Long photoId = Long.parseLong(str[1], 16);
|
|
|
|
|
photoId = Long.parseLong(str[1], 16);
|
|
|
|
|
Integer channel = Integer.parseInt(str[2], 16);
|
|
|
|
|
hexC = str[3];
|
|
|
|
|
Integer preset = Integer.parseInt(hexC, 16);
|
|
|
|
@ -467,7 +475,7 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
|
|
|
|
|
file.transferTo(dest);
|
|
|
|
|
log.info("成功上传一张图片" + filePath);
|
|
|
|
|
|
|
|
|
|
record.setTermId(term.getId());
|
|
|
|
|
record.setTermId(termId);
|
|
|
|
|
record.setMediaType(0);
|
|
|
|
|
record.setPath(filePath);
|
|
|
|
|
record.setRecvTime(BigInteger.valueOf(now.getTime() / 1000));
|
|
|
|
@ -488,7 +496,17 @@ public class TerminalPhotoServiceImpl implements TerminalPhotoService {
|
|
|
|
|
long fileSize = Files.size(Paths.get(C_PATH + filePath));
|
|
|
|
|
record.setFileSize((int) fileSize);
|
|
|
|
|
|
|
|
|
|
terminalPhotoDao.insert(record);
|
|
|
|
|
TerminalPhotoExample example = new TerminalPhotoExample();
|
|
|
|
|
TerminalPhotoExample.Criteria criteria = example.createCriteria();
|
|
|
|
|
criteria.andTermIdEqualTo(termId);
|
|
|
|
|
criteria.andOrginalIdEqualTo(photoId.intValue());
|
|
|
|
|
List<TerminalPhoto> list = terminalPhotoDao.selectByExample(example);
|
|
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
terminalPhotoDao.insert(record);
|
|
|
|
|
} else {
|
|
|
|
|
record.setId(list.get(0).getId());
|
|
|
|
|
terminalPhotoDao.updateByPrimaryKey(record);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|