tangzy
2021-08-27 ffdb63951da8b66bb6a5a06369dc3fe75a6df133
src/main/java/org/springblade/modules/resource/endpoint/OssEndpoint.java
@@ -180,8 +180,8 @@
   /**
    *
    * app 文件上传
    *
    * @param file 图片对象
    */
   @PostMapping("put-file-app")
@@ -224,8 +224,8 @@
   /**
    *
    * 文件上传,自定义上传
    *
    * @param file 图片对象
    */
   @PostMapping("put-files")
@@ -273,8 +273,8 @@
   /**
    *
    * 文件上传,自定义上传
    *
    * @param file 图片对象
    */
   @PostMapping("put-files-talk")
@@ -347,7 +347,8 @@
   public R<BladeFile> putFileAttach(@RequestParam MultipartFile file,String deptid,String type,Long noticeId,String cardid) {
      String fileName = file.getOriginalFilename();
      BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream());
      Long attachId = buildAttach(fileName, file.getSize(), bladeFile,deptid,type,noticeId,cardid);
      InputStream inputStream = file.getInputStream();
      Long attachId = buildAttach(fileName, file.getSize(), bladeFile, deptid, type, noticeId, cardid, inputStream);
      bladeFile.setAttachId(attachId);
      return R.data(bladeFile);
   }
@@ -363,7 +364,7 @@
   @PostMapping("/put-file-attach-by-name")
   public R<BladeFile> putFileAttach(@RequestParam String fileName, @RequestParam MultipartFile file,String deptid,String type,Long noticeId,String cardid) {
      BladeFile bladeFile = ossBuilder.template().putFile(fileName, file.getInputStream());
      Long attachId = buildAttach(fileName, file.getSize(), bladeFile,deptid,type,noticeId,cardid);
      Long attachId = buildAttach(fileName, file.getSize(), bladeFile, deptid, type, noticeId, cardid, file.getInputStream());
      bladeFile.setAttachId(attachId);
      return R.data(bladeFile);
   }
@@ -376,7 +377,7 @@
    * @param bladeFile 对象存储文件
    * @return attachId
    */
   private Long buildAttach(String fileName, Long fileSize, BladeFile bladeFile,String deptid,String type,Long noticeId,String cardid) throws Exception {
   private Long buildAttach(String fileName, Long fileSize, BladeFile bladeFile, String deptid, String type, Long noticeId, String cardid, InputStream in) throws Exception {
      //BladeUser user = AuthUtil.getUser();
      String fileExtension = FileUtil.getFileExtension(fileName);
      Attach attach = new Attach();
@@ -393,15 +394,23 @@
         attach.setNoticeId(noticeId);
      }
      attachService.save(attach);
      String[] split = bladeFile.getName().split("/");
      String ip = "http://192.168.0.108/zhba/picture/";
      String imgurl = ip + split[2];
      FtpUtil.uploadFile(ftpHost_dev, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", split[2], in);
      //数据同步
      String s1 =
         "insert into blade_attach(id,tenant_id,link,domain,name,original_name,extension,attach_size,create_user,create_dept," +
            "create_time,update_user,update_time,status,is_deleted,deptid,type,notice_id,cardid) " +
            "create_time,update_user,update_time,status,is_deleted,type,cardid";
      if (noticeId != null) {
         s1 += ",notice_id";
      } else {
         s1 += ") " +
            "values(" + "'" + attach.getId() + "'" + "," +
            "'" + attach.getTenantId() + "'" + "," +
            "'" + attach.getLink() + "'" + "," +
            "'" + attach.getDomain() + "'" + "," +
            "'" + attach.getName() + "'" + "," +
            "'" + imgurl + "'" + "," +
            "'" + ip + "'" + "," +
            "'" + split[2] + "'" + "," +
            "'" + attach.getOriginalName() + "'" + "," +
            "'" + attach.getExtension() + "'" + "," +
            "'" + attach.getAttachSize() + "'" + "," +
@@ -413,8 +422,14 @@
            "'" + attach.getStatus() + "'" + "," +
            "'" + attach.getIsDeleted() + "'" + "," +
            "'" + attach.getType() + "'" + "," +
            "'" + attach.getNoticeId() + "'" + "," +
            "'" +attach.getCardid() + "'" + ")";
            "'" + cardid + "'";
      }
      if (noticeId != null) {
         s1 += "'" + noticeId + "'" + ")";
      }
      else {
         s1+=")";
      }
      FtpUtil.sqlFileUpload(s1);
      return attach.getId();
   }