diff --git a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalPhotoController.java b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalPhotoController.java index 9f0af3a..265a234 100644 --- a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalPhotoController.java +++ b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/TerminalPhotoController.java @@ -295,10 +295,10 @@ public class TerminalPhotoController extends BaseController { @PostMapping("uploadPhoto") @ApiOperation("上传图片") @Log(title = "上传图片", type = "上传") - public ResponseReult uploadPhoto(@RequestParam("file") MultipartFile file, + public ResponseReult uploadPhoto(@RequestParam("files") MultipartFile[] files, @RequestParam("cmdid") String cmdid) throws Exception { - if (file != null && file.getInputStream() != null) { - terminalPhotoService.upload(file, cmdid); + if (files != null && files.length > 0) { + terminalPhotoService.uploadPhotos(files, cmdid); return ResponseReult.success("OK"); } else { return ResponseReult.error("缺少上传文件"); diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TerminalPhotoServiceImpl.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TerminalPhotoServiceImpl.java index a7c008d..cbbcbbb 100644 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TerminalPhotoServiceImpl.java +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/TerminalPhotoServiceImpl.java @@ -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 list = terminalPhotoDao.selectByExample(example); + if (CollectionUtils.isEmpty(list)) { + terminalPhotoDao.insert(record); + } else { + record.setId(list.get(0).getId()); + terminalPhotoDao.updateByPrimaryKey(record); + } } /** diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/service/TerminalPhotoService.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/service/TerminalPhotoService.java index a6dcede..2b6f40c 100644 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/service/TerminalPhotoService.java +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/service/TerminalPhotoService.java @@ -117,7 +117,7 @@ public interface TerminalPhotoService { ServiceBody takeAlarm(TerminalPhotoTestVo vo); - void upload(MultipartFile file, String cmdid) throws Exception; + void uploadPhotos(MultipartFile[] files, String cmdid) throws Exception; }