LIVE_YE 1 vuosi sitten
vanhempi
commit
3f640c7d86

+ 6 - 3
ruoyi-admin/src/main/java/com/ruoyi/web/controller/webOffice/ConsoleController.java

@@ -3,6 +3,7 @@ package com.ruoyi.web.controller.webOffice;
 
 import cn.ljserver.tool.weboffice.v3.exception.FileNotExist;
 import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.framework.web.domain.server.Sys;
 import com.ruoyi.system.service.ISysConfigService;
 import com.ruoyi.system.service.webService.IWebofficeFjService;
 import com.ruoyi.system.service.webService.QnFileService;
@@ -10,6 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+
 @RestController
 @RequestMapping("/console")
 public class ConsoleController {
@@ -26,13 +29,13 @@ public class ConsoleController {
     }
 
     @PutMapping(value = "/upload/{file_id}")
-    public String upload(@PathVariable("file_id") String fileId, @RequestBody byte[] content) {
+    public String upload(@PathVariable("file_id") String fileId, @RequestBody byte[] content, HttpServletRequest request) {
         // ATTENTION a dirty version is written into storage
-
+        System.out.println(fileId+"ooooooooooooooooooooooooooo");
         if (redisCache.getCacheObject(fileId)==null) throw new FileNotExist();
         // 从缓存中获取当前需要上传文件的文件类型
         String suffix = redisCache.getCacheObject(fileId);
-        return webofficeFjService.upload(fileId,content, suffix);
+        return webofficeFjService.upload(fileId,content, suffix,request);
     }
 
 }

+ 30 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java

@@ -258,4 +258,34 @@ public class FileUploadUtils {
         }
         return extension;
     }
+
+    public static String uploadLoanApplicationNumberOldName(String baseDir, MultipartFile file, String loanApplicationNumber, String originalFilename) throws IOException {
+        try {
+            return uploadLoanApplicationNumberOldName(baseDir, file, loanApplicationNumber, originalFilename, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
+        } catch (Exception e) {
+            throw new IOException(e.getMessage(), e);
+        }
+    }
+
+    private static String uploadLoanApplicationNumberOldName(String baseDir, MultipartFile file, String loanApplicationNumber, String originalFilename, String[] allowedExtension)
+            throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
+            InvalidExtensionException {
+        int fileNamelength = Objects.requireNonNull(originalFilename).length();
+        if (fileNamelength > FileUploadUtils.DEFAULT_FILE_NAME_LENGTH) {
+            throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
+        }
+
+        assertAllowed(file, allowedExtension);
+
+        String fileName = extractFilenameLoanApplicationNumberOldName(file, loanApplicationNumber, originalFilename);
+
+        String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath();
+        file.transferTo(Paths.get(absPath));
+        return getPathFileName(baseDir, fileName);
+    }
+
+    private static String extractFilenameLoanApplicationNumberOldName(MultipartFile file, String loanApplicationNumber, String originalFilename) {
+        return StringUtils.format("{}/{}.{}", loanApplicationNumber,
+                FilenameUtils.getBaseName(originalFilename), getExtension(file));
+    }
 }

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -112,7 +112,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 // 过滤请求
                 .authorizeRequests()
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
-                .antMatchers("/login", "/register", "/captchaImage","/pageoffice/**","/sendSms/sendLoginSms").permitAll()
+                .antMatchers("/login", "/register", "/captchaImage","/pageoffice/**","/sendSms/sendLoginSms","/console/**").permitAll()
                 // 静态资源,可匿名访问
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()

+ 4 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java

@@ -63,6 +63,10 @@ public class TokenService
     {
         // 获取请求携带的令牌
         String token = getToken(request);
+        String url = request.getRequestURL().toString();
+        if(url.contains("/v3/3rd/") || url.contains("/console/upload")){
+            token = request.getHeader("X-Weboffice-Token");
+        }
         if (StringUtils.isNotEmpty(token))
         {
             try

+ 20 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/loan/LoanApplication.java

@@ -268,6 +268,11 @@ public class LoanApplication extends BaseEntity
     private String bUserName;
 
     private String type;
+
+    private String fileType;
+
+    private String bigType;
+
     /**
      * 全体股东信息附件
      */
@@ -296,6 +301,21 @@ public class LoanApplication extends BaseEntity
      */
     private Map<String,List<LoanApplicationFj>> otherFj;
 
+    public String getFileType() {
+        return fileType;
+    }
+
+    public void setFileType(String fileType) {
+        this.fileType = fileType;
+    }
+
+    public String getBigType() {
+        return bigType;
+    }
+
+    public void setBigType(String bigType) {
+        this.bigType = bigType;
+    }
 
     public String getType() {
         return type;

+ 29 - 9
ruoyi-system/src/main/java/com/ruoyi/system/domain/webOffice/WebofficeFj.java

@@ -24,23 +24,18 @@ public class WebofficeFj {
     private Long webofficeId;
 
     /** 附件id */
-    @Excel(name = "附件id")
-    private Long fjId;
+    private String fjId;
 
     /** 版本号 */
-    @Excel(name = "版本号")
     private int version;
 
     /** 文件大小 */
-    @Excel(name = "文件大小")
     private Long size;
 
     /** 附件名称 */
-    @Excel(name = "附件名称")
     private String name;
 
     /** 附件地址 */
-    @Excel(name = "附件地址")
     private String url;
 
     /** 创建者 */
@@ -57,6 +52,13 @@ public class WebofficeFj {
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime updateTime;
 
+    /** 创建者id */
+    private String creatorId;
+
+    /** 文档最后修改者 Id */
+    private String modifierId;
+
+
     /** 备注 */
     private String remark;
 
@@ -68,11 +70,11 @@ public class WebofficeFj {
         this.webofficeId = webofficeId;
     }
 
-    public Long getFjId() {
+    public String getFjId() {
         return fjId;
     }
 
-    public void setFjId(Long fjId) {
+    public void setFjId(String fjId) {
         this.fjId = fjId;
     }
 
@@ -148,6 +150,22 @@ public class WebofficeFj {
         this.remark = remark;
     }
 
+    public String getCreatorId() {
+        return creatorId;
+    }
+
+    public void setCreatorId(String creatorId) {
+        this.creatorId = creatorId;
+    }
+
+    public String getModifierId() {
+        return modifierId;
+    }
+
+    public void setModifierId(String modifierId) {
+        this.modifierId = modifierId;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -170,12 +188,14 @@ public class WebofficeFj {
      */
     public FileInfo toFileInfo() {
         return FileInfo.builder()
-                .id(String.valueOf(this.fjId))
+                .id(this.fjId)
                 .name(this.name)
                 .version(this.version)
                 .size(this.size)
                 .createTime(this.createTime)
                 .modifyTime(this.updateTime)
+                .creatorId(this.creatorId)
+                .modifierId(this.creatorId)
                 .build();
     }
 }

+ 9 - 5
ruoyi-system/src/main/java/com/ruoyi/system/service/loan/impl/LoanApplicationServiceImpl.java

@@ -710,14 +710,14 @@ public class LoanApplicationServiceImpl implements ILoanApplicationService {
     public AjaxResult exportMb(LoanApplication loanApplication) {
         Map<String, Object> map = new HashMap<>();
         String type = loanApplication.getType();
+        String fileType = loanApplication.getFileType();
+        String bigType = loanApplication.getBigType();
         if (loanApplication.getLoanApplicationId() != null && loanApplication.getLoanApplicationId() != 0L) {
             loanApplication = loanApplicationMapper.selectLoanApplicationByLoanApplicationId(loanApplication.getLoanApplicationId());
             loanApplication.setType(type);
             //判断附件存不存在
             LoanApplicationFj loanApplicationFj = new LoanApplicationFj();
             loanApplicationFj.setLoanApplicationId(loanApplication.getLoanApplicationId());
-            //返回附件表对应type
-            String fileType = contrastType(type);
             loanApplicationFj.setType(fileType);
             List<LoanApplicationFj> loanApplicationFjs = loanApplicationFjMapper.selectLoanApplicationFjList(loanApplicationFj);
             if (loanApplicationFjs != null && loanApplicationFjs.size() > 0) {
@@ -732,7 +732,7 @@ public class LoanApplicationServiceImpl implements ILoanApplicationService {
         }
         String loanApplicationNumber = loanApplication.getLoanApplicationNumber();
         Map<String, Object> params = new HashMap<>();
-        String path = "/profile/mb/temporarily";
+        String path = "/profile/mb/temporarily/"+ loanApplicationNumber;
         //查询公司信息
         SysUserEnterprise sysUserEnterprise = sysUserEnterpriseMapper.selectSysUserEnterpriseByEnterpriseId(loanApplication.getEnterpriseId());
         params.put("loanApplication", loanApplication);
@@ -926,11 +926,15 @@ public class LoanApplicationServiceImpl implements ILoanApplicationService {
         }
 
         LoanApplicationFj applicationFj = new LoanApplicationFj();
-        applicationFj.setType(type);
+        applicationFj.setLoanApplicationId(loanApplication.getLoanApplicationId());
+        applicationFj.setType(fileType);
+        applicationFj.setBigType(bigType);
         applicationFj.setLoanApplicationNumber(loanApplication.getLoanApplicationNumber());
-        applicationFj.setName(fileName);
+        applicationFj.setName(fileNameHz);
+        applicationFj.setUrl(path);
         String fileId = IdUtils.fastSimpleUUID();
         redisCache.setCacheObject(fileId + "info", applicationFj, 2, TimeUnit.HOURS);
+        LoanApplicationFj application = redisCache.getCacheObject(fileId + "info");
 
         map.put("fileId", fileId);
         map.put("path", path);

+ 65 - 16
ruoyi-system/src/main/java/com/ruoyi/system/service/webOfficeImpl/MultiPhaseFileStorageServiceImpl.java

@@ -1,24 +1,27 @@
 package com.ruoyi.system.service.webOfficeImpl;
 
 
-import cn.ljserver.tool.weboffice.v3.exception.FileUploadNotComplete;
 import cn.ljserver.tool.weboffice.v3.exception.InvalidArgument;
 import cn.ljserver.tool.weboffice.v3.model.DigestType;
 import cn.ljserver.tool.weboffice.v3.model.FileInfo;
 import cn.ljserver.tool.weboffice.v3.model.FileUploadMultiPhase;
 import cn.ljserver.tool.weboffice.v3.service.MultiPhaseFileStorageService;
 import cn.ljserver.tool.weboffice.v3.util.FileUtils;
+import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.system.domain.loan.LoanApplicationFj;
 import com.ruoyi.system.domain.webOffice.WebofficeFj;
+import com.ruoyi.system.mapper.LoanApplicationFjMapper;
+import com.ruoyi.system.mapper.WebofficeFjMapper;
 import com.ruoyi.system.service.webService.WebofficeFjServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -35,6 +38,12 @@ public class MultiPhaseFileStorageServiceImpl implements MultiPhaseFileStorageSe
     @Autowired
     private WebofficeFjServiceImpl webofficeFjServiceImpl;
 
+    @Autowired
+    private WebofficeFjMapper webofficeFjMapper;
+
+    @Autowired
+    private LoanApplicationFjMapper loanApplicationFjMapper;
+
     /**
      * 准备上传阶段
      *
@@ -71,11 +80,15 @@ public class MultiPhaseFileStorageServiceImpl implements MultiPhaseFileStorageSe
         // 这里简单的放内存
         String suffix = FileUtils.suffix(request.getName());
         redisCache.setCacheObject(request.getFileId(), suffix, 2, TimeUnit.HOURS);
+        SysUser user = SecurityUtils.getLoginUser().getUser();
+        Map<String, String> map = new HashMap<>();
+        map.put("X-WPS-USERID", String.valueOf(user.getUserId()));
 
         // 返回地址
         return FileUploadMultiPhase.FileUploadAddress.Response.builder()
                 // 方法必须是PUT接口
                 .method(FileUploadMultiPhase.FileUploadAddress.Response.Method.PUT)
+                .extraHeaders(map)
                 // 获取自定义上传接口方法
                 // 这里的url是自定义的,需要开发者自己实现,也就是自己的回调地址
                 .url(String.format("%s/prod-api/console/upload/" + request.getFileId(), "https://rzdb.qs163.cn", request.getFileId()))
@@ -91,31 +104,65 @@ public class MultiPhaseFileStorageServiceImpl implements MultiPhaseFileStorageSe
     @Override
     public FileInfo uploadComplete(FileUploadMultiPhase.FileUploadComplete.Request request) {
         if (request == null) throw new InvalidArgument();
-
         // emm
         Optional.of(request)
                 .map(FileUploadMultiPhase.FileUploadComplete.Request::getResponse)
                 .filter(r -> r.getStatus() == HttpStatus.OK.value())
                 .ifPresent(r -> {
                 });
-
-        // 获取当前用户,实际不是这么玩的,点进去看看
-        //SysUser user = SecurityUtils.getLoginUser().getUser();
+        // 获取当前用户
+        SysUser user = SecurityUtils.getLoginUser().getUser();
         // 回调中body返回的是url
         // --------------------------------
-        // 这里不应该直接URL,而是不带domain的uri方便后续迁移等等
-        // 为了方便,就这么弄了
+        // 这里不应该直接URL,
         // --------------------------------
-        String url = request.getResponse().getBody();
-
+        LoanApplicationFj cacheObject = redisCache.getCacheObject(request.getFileId() + "info");
+        String fileName = redisCache.getCacheObject(request.getFileId() + "fileName");
+        System.out.println(fileName + "yyyyyyyyyyyyyyyyyyyyyyyyyyy");
         // 获取文件 并 返回文件信息
-        WebofficeFj webofficeFj = webofficeFjServiceImpl.fetchFile(request.getFileId());
+        WebofficeFj weboffice = webofficeFjServiceImpl.fetchFile(request.getFileId());
         int version = 1;
         LocalDateTime createTime = LocalDateTime.now();
-        if (webofficeFj != null) {
-            version = webofficeFj.getVersion();
-            createTime = webofficeFj.getCreateTime();
+        if (weboffice != null) {
+            version = weboffice.getVersion() + 1;
+            createTime = weboffice.getCreateTime();
+        }
+        WebofficeFj webofficeFj = new WebofficeFj();
+        webofficeFj.setFjId(request.getFileId());
+        webofficeFj.setVersion(version);
+        webofficeFj.setUrl(fileName);
+        webofficeFj.setCreateTime(createTime);
+        webofficeFj.setUpdateTime(LocalDateTime.now());
+        webofficeFj.setSize(Long.valueOf(request.getRequest().getSize()));
+        webofficeFj.setName(com.ruoyi.common.utils.file.FileUtils.getName(fileName));
+        webofficeFj.setCreateBy(user.getNickName());
+        webofficeFj.setCreatorId(String.valueOf(user.getUserId()));
+        webofficeFj.setModifierId(String.valueOf(user.getUserId()));
+        webofficeFjMapper.insertWebofficeFj(webofficeFj);
+        System.out.println(webofficeFj + "hhhhhhhhhhhhhhhhhhhhhhhhhhh");
+        //数据库查询
+        LoanApplicationFj applicationFj = new LoanApplicationFj();
+        applicationFj.setLoanApplicationNumber(cacheObject.getLoanApplicationNumber());
+        applicationFj.setBigType(cacheObject.getBigType());
+        applicationFj.setType(cacheObject.getType());
+        List<LoanApplicationFj> loanApplicationFjs = loanApplicationFjMapper.selectLoanApplicationFjList(applicationFj);
+        if (loanApplicationFjs == null || loanApplicationFjs.size() <= 0) {
+            //将文件存入loan_application_fj表
+            LoanApplicationFj loanApplicationFj = new LoanApplicationFj();
+            loanApplicationFj.setLoanApplicationId(cacheObject.getLoanApplicationId());
+            loanApplicationFj.setLoanApplicationNumber(cacheObject.getLoanApplicationNumber());
+            loanApplicationFj.setOldName(cacheObject.getName());
+            loanApplicationFj.setName(com.ruoyi.common.utils.file.FileUtils.getName(fileName));
+            loanApplicationFj.setUrl(fileName);
+            loanApplicationFj.setBigType(cacheObject.getBigType());
+            loanApplicationFj.setType(cacheObject.getType());
+            loanApplicationFj.setCreateBy(user.getNickName());
+            loanApplicationFj.setCreateTime(DateUtils.getNowDate());
+            loanApplicationFjMapper.insertLoanApplicationFj(loanApplicationFj);
+            System.out.println(loanApplicationFj.toString() + "888888888888888888888888888888");
         }
+
+
         return FileInfo.builder()
                 .id(request.getFileId())
                 .name(request.getRequest().getName())
@@ -123,6 +170,8 @@ public class MultiPhaseFileStorageServiceImpl implements MultiPhaseFileStorageSe
                 .size(request.getRequest().getSize())
                 .createTime(createTime)
                 .modifyTime(LocalDateTime.now())
+                .modifierId(String.valueOf(user.getUserId()))
+                .creatorId(String.valueOf(user.getUserId()))
                 .build();
     }
 }

+ 12 - 9
ruoyi-system/src/main/java/com/ruoyi/system/service/webOfficeImpl/PreviewServiceImpl.java

@@ -7,7 +7,9 @@ import cn.ljserver.tool.weboffice.v3.model.FileInfo;
 import cn.ljserver.tool.weboffice.v3.model.UserPermission;
 import cn.ljserver.tool.weboffice.v3.service.PreviewService;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.system.domain.loan.LoanApplicationFj;
 import com.ruoyi.system.service.webService.WebofficeFjServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -27,6 +29,9 @@ public class PreviewServiceImpl implements PreviewService {
     @Autowired
     private WebofficeFjServiceImpl webofficeFjServiceImpl;
 
+    @Autowired
+    private RedisCache redisCache;
+
     /**
      * 获取文件信息
      *
@@ -38,7 +43,8 @@ public class PreviewServiceImpl implements PreviewService {
         // 解释说明下,这里在实际的设计中,需要将 文件信息 表 和历史文件版本表分开放
         // 这里是通过文件id,获取到当前文件最新一个版本的文件信息,并返回
         // 这里为了方便,所以设计成了一张表
-        return webofficeFjServiceImpl.fetchFile(fileId).toFileInfo();
+        FileInfo fileInfo = webofficeFjServiceImpl.fetchFile(fileId).toFileInfo();
+        return fileInfo;
     }
 
     /**
@@ -52,14 +58,11 @@ public class PreviewServiceImpl implements PreviewService {
         // 解释说明下,这里在实际的设计中,需要将 文件信息 表 和历史文件版本表分开放
         // 然后这里就会获取最后一个版本的文件并返回
         // 这里为了方便,所以设计成了一张表
-        return Optional.ofNullable(fileId)
-                .map(webofficeFjServiceImpl::selectWebofficeFjList)
-                .map(Collection::stream)
-                .flatMap(s -> s.max(Comparator.comparingInt(f -> f.getVersion())))
-                .map(f -> DownloadInfo.builder()
-                        .url(f.getUrl())
-                        .build())
-                .orElseThrow(FileNotExist::new);
+        LoanApplicationFj cacheObject = redisCache.getCacheObject(fileId + "info");
+        String url = "https://rzdb.qs163.cn/prod-api/"+cacheObject.getUrl();
+        DownloadInfo downloadInfo = new DownloadInfo();
+        downloadInfo.setUrl(url);
+        return downloadInfo;
     }
 
     /**

+ 2 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/webOfficeImpl/SinglePhaseFileStorageServiceImpl.java

@@ -59,13 +59,14 @@ public class SinglePhaseFileStorageServiceImpl implements SinglePhaseFileStorage
         //String url = serverConfig.getUrl() + fileName;
         //将文件存入在线编辑预存表
         WebofficeFj webofficeFj = webofficeFjServiceImpl.fetchFile(request.getFileId());
-        webofficeFj.setWebofficeId(0l);
         webofficeFj.setVersion(webofficeFj.getVersion() + 1);
         webofficeFj.setCreateTime(LocalDateTime.now());
         webofficeFj.setUpdateTime(LocalDateTime.now());
         webofficeFj.setSize(Long.valueOf(request.getSize()));
         webofficeFj.setName(request.getName());
         webofficeFj.setCreateBy(user.getNickName());
+        webofficeFj.setCreatorId(String.valueOf(user.getUserId()));
+        webofficeFj.setModifierId(String.valueOf(user.getUserId()));
         webofficeFjServiceImpl.insertWebofficeFj(webofficeFj);
         // 返回文件信息
         return webofficeFj.toFileInfo();

+ 43 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/webOfficeImpl/UserServiceImpl.java

@@ -0,0 +1,43 @@
+package com.ruoyi.system.service.webOfficeImpl;
+
+import cn.ljserver.tool.weboffice.v3.model.UserInfo;
+import cn.ljserver.tool.weboffice.v3.service.UserService;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.utils.SecurityUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 用户信息接口实现
+ * <br>
+ * <a href="https://solution.wps.cn/docs/callback/user.html">-详见官方文档-</a>
+ */
+@Service
+public class UserServiceImpl implements UserService {
+
+    /**
+     * 获取用户信息
+     *
+     * @param userIds 用户ID列表
+     * @return 用户信息列表
+     */
+    @Override
+    public List<UserInfo> fetchUsers(List<String> userIds) {
+        // 看着这里写这么多,感觉有点复杂
+        // 其实就是获取到 userIds,然后到数据库中拿出对应的user list
+        // 然后构造成userInfo list 返回即可
+       /* for (String userId : userIds) {
+            System.out.println(userId + "qqqqqqqqqqqqq");
+        }*/
+
+        List<UserInfo> userInfoList = new ArrayList<>();
+        SysUser user = SecurityUtils.getLoginUser().getUser();
+        UserInfo userInfo = new UserInfo();
+        userInfo.setId(String.valueOf(user.getUserId()));
+        userInfo.setName(user.getNickName());
+        userInfoList.add(userInfo);
+        return userInfoList;
+    }
+}

+ 2 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/webService/IWebofficeFjService.java

@@ -3,6 +3,7 @@ package com.ruoyi.system.service.webService;
 import com.ruoyi.system.domain.webOffice.WebofficeFj;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.List;
 
 /**
@@ -63,5 +64,5 @@ public interface IWebofficeFjService
 
     String upload(MultipartFile file);
 
-    String upload(String fileId, byte[] content, String suffix);
+    String upload(String fileId, byte[] content, String suffix, HttpServletRequest request);
 }

+ 97 - 28
ruoyi-system/src/main/java/com/ruoyi/system/service/webService/WebofficeFjServiceImpl.java

@@ -1,7 +1,9 @@
 package com.ruoyi.system.service.webService;
 
 import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 import cn.ljserver.tool.weboffice.v3.exception.FileNotExist;
 import com.ruoyi.common.config.RuoYiConfig;
@@ -9,9 +11,13 @@ import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
+import com.ruoyi.common.utils.file.FileUtils;
 import com.ruoyi.system.domain.loan.LoanApplicationFj;
 import com.ruoyi.system.domain.webOffice.WebofficeFj;
+import com.ruoyi.system.mapper.LoanApplicationFjMapper;
+import com.ruoyi.system.mapper.SysUserMapper;
 import com.ruoyi.system.mapper.WebofficeFjMapper;
 import lombok.SneakyThrows;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,14 +25,16 @@ import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * webOffice附件记录Service业务层处理
- * 
+ *
  * @author boman
  * @date 2024-05-20
  */
 @Service
-public class WebofficeFjServiceImpl implements IWebofficeFjService 
+public class WebofficeFjServiceImpl implements IWebofficeFjService
 {
     @Autowired
     private WebofficeFjMapper webofficeFjMapper;
@@ -34,9 +42,15 @@ public class WebofficeFjServiceImpl implements IWebofficeFjService
     @Autowired
     private RedisCache redisCache;
 
+    @Autowired
+    private SysUserMapper userMapper;
+
+    @Autowired
+    private LoanApplicationFjMapper loanApplicationFjMapper;
+
     /**
      * 查询webOffice附件记录
-     * 
+     *
      * @param webofficeId webOffice附件记录主键
      * @return webOffice附件记录
      */
@@ -48,7 +62,7 @@ public class WebofficeFjServiceImpl implements IWebofficeFjService
 
     /**
      * 查询webOffice附件记录列表
-     * 
+     *
      * @param webofficeFj webOffice附件记录
      * @return webOffice附件记录
      */
@@ -60,7 +74,7 @@ public class WebofficeFjServiceImpl implements IWebofficeFjService
 
     /**
      * 新增webOffice附件记录
-     * 
+     *
      * @param webofficeFj webOffice附件记录
      * @return 结果
      */
@@ -73,7 +87,7 @@ public class WebofficeFjServiceImpl implements IWebofficeFjService
 
     /**
      * 修改webOffice附件记录
-     * 
+     *
      * @param webofficeFj webOffice附件记录
      * @return 结果
      */
@@ -86,7 +100,7 @@ public class WebofficeFjServiceImpl implements IWebofficeFjService
 
     /**
      * 批量删除webOffice附件记录
-     * 
+     *
      * @param webofficeIds 需要删除的webOffice附件记录主键
      * @return 结果
      */
@@ -98,7 +112,7 @@ public class WebofficeFjServiceImpl implements IWebofficeFjService
 
     /**
      * 删除webOffice附件记录信息
-     * 
+     *
      * @param webofficeId webOffice附件记录主键
      * @return 结果
      */
@@ -115,42 +129,89 @@ public class WebofficeFjServiceImpl implements IWebofficeFjService
 
     @SneakyThrows
     @Override
-    public String upload(String fileId, byte[] content, String suffix) {
-
-        SysUser user = SecurityUtils.getLoginUser().getUser();
+    public String upload(String fileId, byte[] content, String suffix, HttpServletRequest request) {
+        //SysUser user = SecurityUtils.getLoginUser().getUser();
         //从redis取文件信息
         LoanApplicationFj cacheObject = redisCache.getCacheObject(fileId + "info");
         if (cacheObject == null) {
             throw new FileNotExist();
         }
-
+        String userId  = request.getHeader("X-WPS-USERID");
+        if(StringUtils.isEmpty(userId)){
+            return "参数错误";
+        }
+        SysUser user = userMapper.selectUserById(Long.valueOf(userId));
         MultipartFile file = new MockMultipartFile(cacheObject.getName(), cacheObject.getName(), suffix, content);
         // 上传文件路径
         String filePath = RuoYiConfig.getUploadPath();
-        // 上传并返回新文件名称
-        String fileName = FileUploadUtils.uploadLoanApplicationNumber(filePath, file, cacheObject.getLoanApplicationNumber(), file.getOriginalFilename());
+        String fileName = redisCache.getCacheObject(fileId + "fileName");
+        if(StringUtils.isEmpty(fileName)){
+            //已经存在文件,文件名不变
+            if(cacheObject.getFjId()!=null && cacheObject.getFjId()!=0L){
+                fileName = FileUploadUtils.uploadLoanApplicationNumberOldName(filePath, file, cacheObject.getLoanApplicationNumber(), file.getOriginalFilename());
+            }else{
+                // 上传并返回新文件名称
+                fileName = FileUploadUtils.uploadLoanApplicationNumber(filePath, file, cacheObject.getLoanApplicationNumber(), file.getOriginalFilename());
+            }
+        }else{
+            String name = FileUtils.getName(fileName);
+            fileName = FileUploadUtils.uploadLoanApplicationNumberOldName(filePath, file, cacheObject.getLoanApplicationNumber(), name);
+        }
+        redisCache.setCacheObject(fileId + "fileName",fileName,1, TimeUnit.HOURS);
         //String url = serverConfig.getUrl() + fileName;
         //将文件存入在线编辑预存表
-        WebofficeFj webofficeFj = fetchFile(fileId);
-        webofficeFj.setWebofficeId(0l);
+        /*WebofficeFj webofficeFj = new WebofficeFj();
+        webofficeFj.setFjId(fileId);
         webofficeFj.setVersion(webofficeFj.getVersion() + 1);
+        webofficeFj.setUrl(fileName);
         webofficeFj.setCreateTime(LocalDateTime.now());
         webofficeFj.setUpdateTime(LocalDateTime.now());
-        webofficeFj.setSize(Long.valueOf(file.getSize()));
+        webofficeFj.setSize(file.getSize());
         webofficeFj.setName(file.getName());
         webofficeFj.setCreateBy(user.getNickName());
+        webofficeFj.setCreatorId(String.valueOf(user.getUserId()));
+        webofficeFj.setModifierId(String.valueOf(user.getUserId()));
         webofficeFjMapper.insertWebofficeFj(webofficeFj);
+        System.out.println(webofficeFj.toString()+"6666666666666666666666666");
+        if(cacheObject.getFjId()==null || cacheObject.getFjId()==0L){
+            if(cacheObject.getLoanApplicationId()!=null && cacheObject.getLoanApplicationId()!=0L){
+                //将文件存入loan_application_fj表
+                LoanApplicationFj loanApplicationFj = new LoanApplicationFj();
+                loanApplicationFj.setLoanApplicationId(cacheObject.getLoanApplicationId());
+                loanApplicationFj.setLoanApplicationNumber(cacheObject.getLoanApplicationNumber());
+                loanApplicationFj.setOldName(cacheObject.getName());
+                loanApplicationFj.setName(cacheObject.getName());
+                loanApplicationFj.setUrl(fileName);
+                loanApplicationFj.setBigType(cacheObject.getBigType());
+                loanApplicationFj.setType(cacheObject.getType());
+                loanApplicationFj.setCreateBy(user.getNickName());
+                loanApplicationFj.setCreateTime(DateUtils.getNowDate());
+                loanApplicationFjMapper.insertLoanApplicationFj(loanApplicationFj);
+                System.out.println(loanApplicationFj.toString()+"888888888888888888888888888888");
+            }
+        }*/
+
         return fileName;
     }
 
     public List<WebofficeFj> selectWebofficeFjList(String fileId)
     {
-        if(!DateUtils.isNumeric(fileId)){
-            fileId = "0";
-        }
+        List<WebofficeFj> webofficeFjList = new ArrayList<>();
         WebofficeFj webofficeFj = new WebofficeFj();
-        webofficeFj.setFjId(Long.valueOf(fileId));
-        return webofficeFjMapper.selectWebofficeFjList(webofficeFj);
+        SysUser user = SecurityUtils.getLoginUser().getUser();
+        webofficeFj.setFjId(fileId);
+        LoanApplicationFj cacheObject = redisCache.getCacheObject(fileId + "info");
+        webofficeFj.setName(cacheObject.getName());
+        webofficeFj.setSize(102400L);
+        webofficeFj.setUpdateTime(LocalDateTime.now());
+        webofficeFj.setUpdateTime(LocalDateTime.now());
+        webofficeFj.setCreatorId(String.valueOf(user.getUserId()));
+        webofficeFj.setModifierId(String.valueOf(user.getUserId()));
+        webofficeFjList.add(webofficeFj);
+        WebofficeFj weboffice = new WebofficeFj();
+        weboffice.setFjId(fileId);
+        webofficeFjList = webofficeFjMapper.selectWebofficeFjList(weboffice);
+        return webofficeFjList;
     }
 
     /***
@@ -164,7 +225,7 @@ public class WebofficeFjServiceImpl implements IWebofficeFjService
             fileId = "0";
         }
         WebofficeFj webofficeFj = new WebofficeFj();
-        webofficeFj.setFjId(Long.valueOf(fileId));
+        webofficeFj.setFjId(fileId);
         webofficeFj.setVersion(version);
         List<WebofficeFj> webofficeFjs = webofficeFjMapper.selectWebofficeFjList(webofficeFj);
         if(webofficeFjs!=null && webofficeFjs.size()>0){
@@ -182,16 +243,24 @@ public class WebofficeFjServiceImpl implements IWebofficeFjService
      */
     public WebofficeFj fetchFile(String fileId)
     {
-        if(!DateUtils.isNumeric(fileId)){
-            fileId = "0";
-        }
+        SysUser user = SecurityUtils.getLoginUser().getUser();
         WebofficeFj webofficeFj = new WebofficeFj();
-        webofficeFj.setFjId(Long.valueOf(fileId));
+        webofficeFj.setFjId(fileId);
         List<WebofficeFj> webofficeFjs = webofficeFjMapper.selectWebofficeFjList(webofficeFj);
         if(webofficeFjs!=null && webofficeFjs.size()>0){
             return webofficeFjs.get(0);
         }else {
-            return new WebofficeFj();
+            //从redis取文件信息
+            LoanApplicationFj cacheObject = redisCache.getCacheObject(fileId + "info");
+            webofficeFj.setName(cacheObject.getName());
+            webofficeFj.setSize(102400L);
+            webofficeFj.setVersion(1);
+            webofficeFj.setCreateTime(LocalDateTime.now());
+            webofficeFj.setUpdateTime(LocalDateTime.now());
+            webofficeFj.setCreatorId(String.valueOf(user.getUserId()));
+            webofficeFj.setModifierId(String.valueOf(user.getUserId()));
+            return webofficeFj;
         }
+
     }
 }

+ 9 - 1
ruoyi-system/src/main/resources/mapper/system/WebofficeFjMapper.xml

@@ -15,11 +15,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="createTime"    column="create_time"    />
         <result property="updateBy"    column="update_by"    />
         <result property="updateTime"    column="update_time"    />
+        <result property="creatorId"    column="modifier_id"    />
+        <result property="modifierId"    column="creator_id"    />
         <result property="remark"    column="remark"    />
     </resultMap>
 
     <sql id="selectWebofficeFjVo">
-        select webOffice_id, fj_id, version, size, name, url, create_by, create_time, update_by, update_time, remark from webOffice_fj
+        select webOffice_id, fj_id, version, size, name, url, create_by, create_time, update_by, update_time,modifier_id,creator_id, remark from webOffice_fj
     </sql>
 
     <select id="selectWebofficeFjList" parameterType="WebofficeFj" resultMap="WebofficeFjResult">
@@ -51,6 +53,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createTime != null">create_time,</if>
             <if test="updateBy != null">update_by,</if>
             <if test="updateTime != null">update_time,</if>
+            <if test="creatorId != null">creator_id,</if>
+            <if test="modifierId != null">modifier_id,</if>
             <if test="remark != null">remark,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
@@ -63,6 +67,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createTime != null">#{createTime},</if>
             <if test="updateBy != null">#{updateBy},</if>
             <if test="updateTime != null">#{updateTime},</if>
+            <if test="creatorId != null">#{creatorId},</if>
+            <if test="modifierId != null">#{modifierId},</if>
             <if test="remark != null">#{remark},</if>
          </trim>
     </insert>
@@ -79,6 +85,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="updateBy != null">update_by = #{updateBy},</if>
             <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="creatorId != null">creator_id = #{creatorId},</if>
+            <if test="modifierId != null">modifier_id = #{modifierId},</if>
             <if test="remark != null">remark = #{remark},</if>
         </trim>
         where webOffice_id = #{webofficeId}