| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Map<String, Object> add(MultipartFile[] files, Supervision supervision) { |
| | | public Map<String, Object> add(List<MultipartFile> files, Supervision supervision) { |
| | | //获取jar包所在目录 |
| | | ApplicationHome applicationHome = new ApplicationHome(getClass()); |
| | | //在jar包所在目录下生成一个upload文件夹用来存储上传的图片 |
| | |
| | | } |
| | | |
| | | List<String> images = new ArrayList<>(); |
| | | for (MultipartFile file : files) { |
| | | //判断上传文件格式 |
| | | String fileType = file.getContentType(); |
| | | if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) { |
| | | //获取文件名 |
| | | String fileName = file.getOriginalFilename(); |
| | | //获取文件后缀名 |
| | | String suffixName = fileName.substring(fileName.lastIndexOf(".")); |
| | | //重新生成文件名 |
| | | fileName = UUID.randomUUID() + suffixName; |
| | | //图片上传 |
| | | if (FileUtils.upload(file, path, fileName)) { |
| | | images.add(fileName); |
| | | |
| | | if (files.size() > 0) { |
| | | for (MultipartFile file : files) { |
| | | //判断上传文件格式 |
| | | String fileType = file.getContentType(); |
| | | if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) { |
| | | //获取文件名 |
| | | String fileName = file.getOriginalFilename(); |
| | | //获取文件后缀名 |
| | | String suffixName = fileName.substring(fileName.lastIndexOf(".")); |
| | | //重新生成文件名 |
| | | fileName = UUID.randomUUID() + suffixName; |
| | | //图片上传 |
| | | if (FileUtils.upload(file, path, fileName)) { |
| | | images.add(fileName); |
| | | } |
| | | } else { |
| | | result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode()); |
| | | result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg()); |
| | | return result; |
| | | } |
| | | } else { |
| | | result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode()); |
| | | result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg()); |
| | | return result; |
| | | } |
| | | } |
| | | |
| | |
| | | .collect(Collectors.joining(",")); |
| | | supervision.setImages(image); |
| | | } |
| | | |
| | | |
| | | supervisionMapper.insert(supervision); |
| | | return result; |
| | | } |
| | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Map<String, Object> updateSupervision(MultipartFile[] files, Supervision supervision) { |
| | | |
| | | public Map<String, Object> updateSupervision(List<MultipartFile> files, Supervision supervision) { |
| | | //获取jar包所在目录 |
| | | ApplicationHome applicationHome = new ApplicationHome(getClass()); |
| | | //在jar包所在目录下生成一个upload文件夹用来存储上传的图片 |
| | |
| | | |
| | | List<String> images = new ArrayList<>(); |
| | | |
| | | |
| | | for (MultipartFile file : files) { |
| | | //判断上传文件格式 |
| | | String fileType = file.getContentType(); |
| | | if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) { |
| | | //获取文件名 |
| | | String fileName = file.getOriginalFilename(); |
| | | //获取文件后缀名 |
| | | String suffixName = fileName.substring(fileName.lastIndexOf(".")); |
| | | //重新生成文件名 |
| | | fileName = UUID.randomUUID() + suffixName; |
| | | //图片上传 |
| | | if (FileUtils.upload(file, path, fileName)) { |
| | | images.add(fileName); |
| | | //如果上传了图片,就覆盖之前图片,删除服务器中图片 |
| | | if (files.size() > 0) { |
| | | //删除服务器中的原来督办单中图片 |
| | | String[] oldImages = supervisionMapper.selectById(supervision.getId()).getImages().split(","); |
| | | for (String image : oldImages) { |
| | | String realPath = path + File.separator + image; |
| | | File file = new File(realPath); |
| | | if (file.exists() && file.isFile()) { |
| | | file.delete(); |
| | | } |
| | | } else { |
| | | result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode()); |
| | | result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg()); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | for (MultipartFile file : files) { |
| | | //判断上传文件格式 |
| | | String fileType = file.getContentType(); |
| | | if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) { |
| | | //获取文件名 |
| | | String fileName = file.getOriginalFilename(); |
| | | //获取文件后缀名 |
| | | String suffixName = fileName.substring(fileName.lastIndexOf(".")); |
| | | //重新生成文件名 |
| | | fileName = UUID.randomUUID() + suffixName; |
| | | //图片上传 |
| | | if (FileUtils.upload(file, path, fileName)) { |
| | | images.add(fileName); |
| | | } |
| | | } else { |
| | | result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode()); |
| | | result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg()); |
| | | return result; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | if (!ObjectUtils.isEmpty(images)) { |
| | | |
| | | String image = images.stream() |
| | | .map(String::valueOf) |
| | | .collect(Collectors.joining(",")); |