Browse Source

保存附件

licailing 5 years ago
parent
commit
e3c43da2d7

+ 3 - 1
src/main/java/com/izouma/uwip/domain/Attachment.java

@@ -20,12 +20,14 @@ public class Attachment extends BaseEntity {
     private Long patentId;
     private Long patentId;
 
 
     /*
     /*
-    上传的海外账单等
+    附件名称--> 商标查询报告书
      */
      */
     private String attachmentName;
     private String attachmentName;
 
 
     private String fileName;
     private String fileName;
 
 
+    private String url;
+
     private String remark;
     private String remark;
 
 
     private String size;
     private String size;

+ 1 - 0
src/main/java/com/izouma/uwip/domain/Fee.java

@@ -28,6 +28,7 @@ public class Fee extends BaseEntity {
     @ApiModelProperty(value = "费用名称")
     @ApiModelProperty(value = "费用名称")
     private String feeName;
     private String feeName;
 
 
+    @ApiModelProperty(value = "是否支付")
     private PayStatus status;
     private PayStatus status;
 
 
     /*
     /*

+ 4 - 0
src/main/java/com/izouma/uwip/domain/LogoPatent.java

@@ -1,6 +1,7 @@
 package com.izouma.uwip.domain;
 package com.izouma.uwip.domain;
 
 
 import com.izouma.uwip.converter.HandleListConverter;
 import com.izouma.uwip.converter.HandleListConverter;
+import com.izouma.uwip.dto.AttachmentDTO;
 import com.izouma.uwip.enums.LogoApplyStatus;
 import com.izouma.uwip.enums.LogoApplyStatus;
 import com.izouma.uwip.enums.LogoWorkflow;
 import com.izouma.uwip.enums.LogoWorkflow;
 import com.izouma.uwip.enums.PayRatio;
 import com.izouma.uwip.enums.PayRatio;
@@ -93,4 +94,7 @@ public class LogoPatent extends BaseEntity {
 
 
     private int sort;
     private int sort;
 
 
+    @Transient
+    public List<AttachmentDTO> attachments;
+
 }
 }

+ 27 - 0
src/main/java/com/izouma/uwip/dto/AttachmentDTO.java

@@ -0,0 +1,27 @@
+package com.izouma.uwip.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@AllArgsConstructor
+@Data
+@Builder
+@NoArgsConstructor
+@ApiModel(value = "附件")
+public class AttachmentDTO {
+    /*
+    附件名称--> 商标查询报告书
+     */
+    private String attachmentName;
+
+    private String fileName;
+
+    private String url;
+
+    private String remark;
+
+}

+ 6 - 0
src/main/java/com/izouma/uwip/repo/AttachmentRepo.java

@@ -7,10 +7,16 @@ import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.jpa.repository.Query;
 
 
 import javax.transaction.Transactional;
 import javax.transaction.Transactional;
+import java.util.List;
 
 
 public interface AttachmentRepo extends JpaRepository<Attachment, Long>, JpaSpecificationExecutor<Attachment> {
 public interface AttachmentRepo extends JpaRepository<Attachment, Long>, JpaSpecificationExecutor<Attachment> {
     @Query("update Attachment t set t.del = true where t.id = ?1")
     @Query("update Attachment t set t.del = true where t.id = ?1")
     @Modifying
     @Modifying
     @Transactional
     @Transactional
     void softDelete(Long id);
     void softDelete(Long id);
+
+    @Query(nativeQuery = true, value = "select ifnull(max(attachment.version + 1),1) " +
+            "from  attachment " +
+            "where del = true and attachment_name like '%'+ ?1 + '%'")
+    int findVersion(String attachmentName);
 }
 }

+ 1 - 1
src/main/java/com/izouma/uwip/repo/LogoPatentRepo.java

@@ -14,6 +14,6 @@ public interface LogoPatentRepo extends JpaRepository<LogoPatent, Long>, JpaSpec
     @Transactional
     @Transactional
     void softDelete(Long id);
     void softDelete(Long id);
 
 
-    @Query("select max(t.sort)+1 from  LogoPatent t where t.del = true")
+    @Query(nativeQuery = true, value = "select ifnull(max(sort + 1),1) from  logo_patent where del = true")
     int findMax();
     int findMax();
 }
 }

+ 23 - 1
src/main/java/com/izouma/uwip/service/AttachmentService.java

@@ -1,6 +1,7 @@
 package com.izouma.uwip.service;
 package com.izouma.uwip.service;
 
 
 import com.izouma.uwip.domain.Attachment;
 import com.izouma.uwip.domain.Attachment;
+import com.izouma.uwip.dto.AttachmentDTO;
 import com.izouma.uwip.dto.PageQuery;
 import com.izouma.uwip.dto.PageQuery;
 import com.izouma.uwip.repo.AttachmentRepo;
 import com.izouma.uwip.repo.AttachmentRepo;
 import com.izouma.uwip.utils.JpaUtils;
 import com.izouma.uwip.utils.JpaUtils;
@@ -12,6 +13,7 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLConnection;
+import java.util.List;
 
 
 @Service
 @Service
 @AllArgsConstructor
 @AllArgsConstructor
@@ -36,6 +38,26 @@ public class AttachmentService {
         } catch (IOException e) {
         } catch (IOException e) {
             e.printStackTrace();
             e.printStackTrace();
         }
         }
-        return size/1024;
+        return size / 1024;
+    }
+
+    /*
+    附件存储
+     */
+    public void batchSave(List<AttachmentDTO> dtoList, Long userId, Long patentId) {
+        dtoList.forEach(dto -> {
+            Attachment build = Attachment.builder()
+                    .userId(userId)
+                    .patentId(patentId)
+                    .attachmentName(dto.getAttachmentName())
+                    .fileName(dto.getFileName())
+                    .url(dto.getUrl())
+                    .remark(dto.getRemark())
+                    .size(getSize(dto.getUrl()) + "KB")
+                    .version(attachmentRepo.findVersion(dto.getAttachmentName()))
+                    .build();
+            attachmentRepo.save(build);
+        });
+
     }
     }
 }
 }

+ 17 - 1
src/main/java/com/izouma/uwip/web/LogoPatentController.java

@@ -2,13 +2,16 @@ package com.izouma.uwip.web;
 
 
 import com.izouma.uwip.domain.LogoPatent;
 import com.izouma.uwip.domain.LogoPatent;
 import com.izouma.uwip.domain.Partner;
 import com.izouma.uwip.domain.Partner;
+import com.izouma.uwip.service.AttachmentService;
 import com.izouma.uwip.service.LogoPatentService;
 import com.izouma.uwip.service.LogoPatentService;
 import com.izouma.uwip.dto.PageQuery;
 import com.izouma.uwip.dto.PageQuery;
 import com.izouma.uwip.exception.BusinessException;
 import com.izouma.uwip.exception.BusinessException;
 import com.izouma.uwip.repo.LogoPatentRepo;
 import com.izouma.uwip.repo.LogoPatentRepo;
 import com.izouma.uwip.utils.ObjUtils;
 import com.izouma.uwip.utils.ObjUtils;
+import com.izouma.uwip.utils.SecurityUtils;
 import com.izouma.uwip.utils.excel.ExcelUtils;
 import com.izouma.uwip.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
 import lombok.AllArgsConstructor;
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Page;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
@@ -23,12 +26,19 @@ import java.util.List;
 public class LogoPatentController extends BaseController {
 public class LogoPatentController extends BaseController {
     private LogoPatentService logoPatentService;
     private LogoPatentService logoPatentService;
     private LogoPatentRepo    logoPatentRepo;
     private LogoPatentRepo    logoPatentRepo;
+    private AttachmentService attachmentService;
 
 
     //@PreAuthorize("hasRole('ADMIN')")
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")
     @PostMapping("/save")
     public LogoPatent save(@RequestBody LogoPatent record) {
     public LogoPatent save(@RequestBody LogoPatent record) {
+
         if (record.getId() != null) {
         if (record.getId() != null) {
             LogoPatent orig = logoPatentRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
             LogoPatent orig = logoPatentRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
+            // 保存附件
+            if (CollectionUtils.isNotEmpty(record.getAttachments())) {
+                attachmentService.batchSave(record.getAttachments(), SecurityUtils.getAuthenticatedUser()
+                        .getId(), record.getId());
+            }
             ObjUtils.merge(orig, record);
             ObjUtils.merge(orig, record);
             return logoPatentRepo.save(orig);
             return logoPatentRepo.save(orig);
         }
         }
@@ -36,7 +46,13 @@ public class LogoPatentController extends BaseController {
             record.setSort(logoPatentRepo.findMax());
             record.setSort(logoPatentRepo.findMax());
         }
         }
         record.setUwNo(logoPatentService.getUwNo(record));
         record.setUwNo(logoPatentService.getUwNo(record));
-        return logoPatentRepo.save(record);
+        record = logoPatentRepo.save(record);
+        // 保存附件
+        if (CollectionUtils.isNotEmpty(record.getAttachments())) {
+            attachmentService.batchSave(record.getAttachments(), SecurityUtils.getAuthenticatedUser()
+                    .getId(), record.getId());
+        }
+        return record;
     }
     }