xiongzhu há 2 anos atrás
pai
commit
f7ab986808

+ 164 - 0
src/main/java/com/izouma/zhirongip/dto/PatentDemandExcelDto.java

@@ -0,0 +1,164 @@
+package com.izouma.zhirongip.dto;
+
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.izouma.zhirongip.annotations.Searchable;
+import com.izouma.zhirongip.domain.demand.PatentDemand;
+import com.izouma.zhirongip.enums.ApplyStatus;
+import com.izouma.zhirongip.enums.CaseType;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.persistence.Column;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@ExcelIgnoreUnannotated
+public class PatentDemandExcelDto {
+
+    @ExcelProperty(value = "专利名称")
+    private String name;
+
+    @ExcelProperty(value = "包含关键字")
+    private String keyword;
+
+    @ExcelProperty(value = "专利类型")
+    private String patentType;
+
+    private Long patentTypeId;
+
+    @ExcelProperty("行业分类")
+    private String industryName;
+
+    @ExcelProperty(value = "专利状态")
+    private String patentStatus;
+
+    private Long patentStatusId;
+
+    @ExcelProperty(value = "行业分类")
+    private Long industryClass;
+
+    @Searchable
+    @ExcelIgnore
+    @Column(columnDefinition = "TEXT")
+    @ExcelProperty(value = "需求描述")
+    private String description;
+
+
+    @ExcelProperty(value = "转移转化方式")
+    private String mode;
+
+    private Long modeId;
+
+    @ExcelProperty(value = "预算")
+    private String expectedPrice;
+
+    @ExcelProperty(value = "面议")
+    private String negotiateDirectly;
+
+    @ExcelProperty(value = "联系人")
+    private String contact;
+
+    @ExcelProperty(value = "手机号")
+    private String phone;
+
+    @ExcelProperty(value = "邮箱")
+    private String email;
+
+    @ExcelProperty(value = "所在地区")
+    private String address;
+
+    private CaseType caseType = CaseType.GENERAL;
+
+    private ApplyStatus status = ApplyStatus.PASS;
+
+
+    public static PatentDemandExcelDto from(PatentDemand patent) {
+        PatentDemandExcelDto dto = new PatentDemandExcelDto();
+        try {
+            BeanUtils.copyProperties(dto, patent);
+        } catch (Exception e) {
+        }
+        if (patent.getPatentTypeId() != null) {
+            if (7239L == patent.getPatentTypeId()) {
+                dto.setPatentType("发明专利");
+            } else if (7240L == patent.getPatentTypeId()) {
+                dto.setPatentType("实用新型专利");
+            } else if (7241L == patent.getPatentTypeId()) {
+                dto.setPatentType("外观设计专利");
+            }
+        }
+
+        if (patent.getExpectedPrice() != null) {
+            dto.setExpectedPrice(patent.getExpectedPrice().toString());
+        }
+        if (patent.getNegotiateDirectly() != null) {
+            dto.setNegotiateDirectly(patent.getNegotiateDirectly() ? "是" : "否");
+        }
+
+        return dto;
+    }
+
+    public PatentDemand toPatentDemand() {
+        PatentDemand patent = new PatentDemand();
+        try {
+            BeanUtils.copyProperties(patent, this);
+        } catch (Exception e) {
+        }
+        if (StringUtils.isNotBlank(this.patentType)) {
+            if (this.patentType.contains("发明")) {
+                patent.setPatentTypeId(7239L);
+                patent.setPatentType("发明专利");
+            } else if (this.patentType.contains("实用")) {
+                patent.setPatentTypeId(7240L);
+                patent.setPatentType("实用新型专利");
+            } else if (this.patentType.contains("外观")) {
+                patent.setPatentTypeId(7241L);
+                patent.setPatentType("外观设计专利");
+            }
+        }
+        if (StringUtils.isNotBlank(this.patentStatus)) {
+            if (this.patentStatus.contains("申请中")) {
+                patent.setPatentStatusId(7243L);
+                patent.setPatentStatus("申请中");
+            } else if (this.patentStatus.contains("已授权")) {
+                patent.setPatentStatusId(7244L);
+                patent.setPatentStatus("已授权已期满");
+            }
+        }
+        if (StringUtils.isNotBlank(this.expectedPrice)) {
+            patent.setExpectedPrice(new BigDecimal(this.expectedPrice));
+        }
+        if (StringUtils.isNotBlank(this.negotiateDirectly)) {
+            if ("是".equals(this.negotiateDirectly.trim())) {
+                patent.setNegotiateDirectly(true);
+            } else if ("否".equals(this.negotiateDirectly.trim())) {
+                patent.setNegotiateDirectly(false);
+            }
+        }
+
+        return patent;
+    }
+
+
+    private static List<String> splitStr(String s) {
+        if (StringUtils.isBlank(s)) {
+            return new ArrayList<>();
+        }
+        return Arrays.asList(StringUtils.split(s.replaceAll(" ", "")
+                                                .replace(";", ",")
+                                                .replace(";", ",")
+                                                .replace(",", ","), ","));
+    }
+}

+ 286 - 0
src/main/java/com/izouma/zhirongip/dto/PatentExcelDto.java

@@ -0,0 +1,286 @@
+package com.izouma.zhirongip.dto;
+
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.izouma.zhirongip.annotations.Searchable;
+import com.izouma.zhirongip.domain.supply.Patent;
+import com.izouma.zhirongip.enums.ApplyStatus;
+import com.izouma.zhirongip.enums.CaseType;
+import com.izouma.zhirongip.enums.CommissionType;
+import com.izouma.zhirongip.utils.DateTimeUtils;
+import com.izouma.zhirongip.utils.ObjUtils;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.persistence.Column;
+import java.lang.reflect.InvocationTargetException;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Pattern;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@ExcelIgnoreUnannotated
+public class PatentExcelDto {
+
+    @ExcelProperty(value = "专利名称")
+    private String name;
+
+    @ExcelProperty(value = "申请号")
+    private String code;
+
+    @ExcelProperty(value = "专利类型")
+    private String patentType;
+
+    @ExcelProperty(value = "申请时间")
+    private String applyTime;
+
+    private Long industryClass;
+
+    @ExcelProperty(value = "行业分类")
+    private String industryName;
+
+    @ExcelProperty(value = "IPC分类号")
+    private String ipc;
+
+    @ExcelProperty(value = "法律状态")
+    private String lawStatus;
+
+    @ExcelProperty(value = "申请人")
+    private String applicant;
+
+    @ExcelProperty(value = "专利权人")
+    private String owner;
+
+    @ExcelProperty(value = "发明人")
+    private String inventor;
+
+    @ExcelProperty(value = "摘要")
+    private String digest;
+
+    @ExcelProperty(value = "交易方式")
+    private String tradingMethod;
+
+    @ExcelProperty(value = "期望价(万元)")
+    private String expectedPrice;
+
+    @ExcelProperty(value = "面议")
+    private String negotiateDirectly;
+
+    @ExcelProperty(value = "底价(万元)")
+    private String basePrice;
+
+    @ExcelProperty(value = "佣金/百分比")
+    private String commissionType;
+
+    @ExcelProperty(value = "佣金(万元)")
+    private String commission;
+
+    @ExcelProperty(value = "联系人")
+    private String contact;
+
+    @ExcelProperty(value = "电话")
+    private String phone;
+
+    @ExcelProperty(value = "邮箱")
+    private String email;
+
+    @ExcelProperty(value = "所在地区")
+    private String address;
+
+    private CaseType caseType = CaseType.GENERAL;
+
+    private ApplyStatus status = ApplyStatus.PASS;
+
+    public static PatentExcelDto from(Patent patent) {
+        PatentExcelDto dto = new PatentExcelDto();
+        try {
+            BeanUtils.copyProperties(dto, patent);
+        } catch (Exception e) {
+        }
+        if (patent.getPatentTypeId() != null) {
+            if (7239L == patent.getPatentTypeId()) {
+                dto.setPatentType("发明专利");
+            } else if (7240L == patent.getPatentTypeId()) {
+                dto.setPatentType("实用新型专利");
+            } else if (7241L == patent.getPatentTypeId()) {
+                dto.setPatentType("外观设计专利");
+            }
+        }
+        if (patent.getApplyTime() != null) {
+            dto.setApplyTime(DateTimeUtils.format(patent.getApplyTime(), "yyyyMMdd"));
+        }
+        if (patent.getLawStatusId() != null) {
+
+            if (7243L == patent.getLawStatusId()) {
+                dto.setLawStatus("申请中");
+            } else if (7244L == patent.getLawStatusId()) {
+                dto.setLawStatus("已授权已期满");
+            }
+        }
+        if (patent.getApplicant() != null) {
+            dto.setApplicant(StringUtils.join(patent.getApplicant()));
+        }
+        if (patent.getOwner() != null) {
+            dto.setOwner(StringUtils.join(patent.getOwner()));
+        }
+        if (patent.getInventor() != null) {
+            dto.setInventor(StringUtils.join(patent.getInventor()));
+        }
+        if (patent.getTradingMethodId() != null) {
+            if (7232L == patent.getTradingMethodId()) {
+                dto.setTradingMethod("转让");
+            } else if (7233L == patent.getTradingMethodId()) {
+                dto.setTradingMethod("许可");
+            } else if (7234L == patent.getTradingMethodId()) {
+                dto.setTradingMethod("独占许可");
+            } else if (7235L == patent.getTradingMethodId()) {
+                dto.setTradingMethod("排他许可");
+            } else if (7236L == patent.getTradingMethodId()) {
+                dto.setTradingMethod("入股");
+            } else if (7237L == patent.getTradingMethodId()) {
+                dto.setTradingMethod("其他");
+            }
+        }
+        if (patent.getExpectedPrice() != null) {
+            dto.setExpectedPrice(patent.getExpectedPrice().toString());
+        }
+        if (patent.getNegotiateDirectly() != null) {
+            dto.setNegotiateDirectly(patent.getNegotiateDirectly() ? "是" : "否");
+        }
+        if (patent.getBasePrice() != null) {
+            dto.setBasePrice(patent.getBasePrice().toString());
+        }
+        if (patent.getCommissionType() != null) {
+            dto.setCommissionType(patent.getCommissionType().getDesc());
+        }
+        if (patent.getCommission() != null) {
+            dto.setCommission(patent.getCommission().toString());
+        }
+
+        return dto;
+    }
+
+    public Patent toPatent() {
+        Patent patent = new Patent();
+        try {
+//            BeanUtils.copyProperties(patent, this);
+            org.springframework.beans.BeanUtils.copyProperties(this, patent);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        if (StringUtils.isNotBlank(this.patentType)) {
+            if (this.patentType.contains("发明")) {
+                patent.setPatentTypeId(7239L);
+                patent.setPatentType("发明专利");
+            } else if (this.patentType.contains("实用")) {
+                patent.setPatentTypeId(7240L);
+                patent.setPatentType("实用新型专利");
+            } else if (this.patentType.contains("外观")) {
+                patent.setPatentTypeId(7241L);
+                patent.setPatentType("外观设计专利");
+            }
+        }
+        if (StringUtils.isNotBlank(this.applyTime)) {
+            try {
+                if (Pattern.matches("\\d{4}-\\d{2}-\\d{2}", this.applyTime)) {
+                    patent.setApplyTime(LocalDate.parse(this.applyTime, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+                } else if (Pattern.matches("\\d{4}/\\d{2}/\\d{2}", this.applyTime)) {
+                    patent.setApplyTime(LocalDate.parse(this.applyTime, DateTimeFormatter.ofPattern("yyyy/MM/dd")));
+                } else if (Pattern.matches("\\d{4}\\.\\d{2}\\.\\d{2}", this.applyTime)) {
+                    patent.setApplyTime(LocalDate.parse(this.applyTime, DateTimeFormatter.ofPattern("yyyy.MM.dd")));
+                } else if (Pattern.matches("\\d{4}\\d{2}\\d{2}", this.applyTime)) {
+                    patent.setApplyTime(LocalDate.parse(this.applyTime, DateTimeFormatter.ofPattern("yyyyMMdd")));
+                }
+            } catch (Exception e) {
+            }
+        }
+        if (StringUtils.isNotBlank(this.lawStatus)) {
+            if (this.lawStatus.contains("申请中")) {
+                patent.setLawStatusId(7243L);
+                patent.setLawStatus("申请中");
+            } else if (this.lawStatus.contains("已授权")) {
+                patent.setLawStatusId(7244L);
+                patent.setLawStatus("已授权已期满");
+            }
+        }
+        if (StringUtils.isNotBlank(this.applicant)) {
+            patent.setApplicant(splitStr(this.applicant));
+        }
+        if (StringUtils.isNotBlank(this.owner)) {
+            patent.setOwner(splitStr(this.owner));
+        }
+        if (StringUtils.isNotBlank(this.inventor)) {
+            patent.setInventor(splitStr(this.inventor));
+        }
+        if (StringUtils.isNotBlank(this.tradingMethod)) {
+            if (this.tradingMethod.contains("转让")) {
+                patent.setTradingMethodId(7232L);
+                patent.setTradingMethod("转让");
+            } else if (this.tradingMethod.contains("普通")) {
+                patent.setTradingMethodId(7233L);
+                patent.setTradingMethod("普通许可");
+            } else if (this.tradingMethod.contains("独占")) {
+                patent.setTradingMethodId(7234L);
+                patent.setTradingMethod("独占许可");
+            } else if (this.tradingMethod.contains("排他")) {
+                patent.setTradingMethodId(7235L);
+                patent.setTradingMethod("排他许可");
+            } else if (this.tradingMethod.contains("入股")) {
+                patent.setTradingMethodId(7236L);
+                patent.setTradingMethod("入股");
+            } else if (this.tradingMethod.contains("其他")) {
+                patent.setTradingMethodId(7237L);
+                patent.setTradingMethod("其他");
+            }
+        }
+        if (StringUtils.isNotBlank(this.expectedPrice)) {
+            patent.setExpectedPrice(new BigDecimal(this.expectedPrice));
+        }
+        if (StringUtils.isNotBlank(this.negotiateDirectly)) {
+            if ("是".equals(this.negotiateDirectly.trim())) {
+                patent.setNegotiateDirectly(true);
+            } else if ("否".equals(this.negotiateDirectly.trim())) {
+                patent.setNegotiateDirectly(false);
+            }
+        }
+        if (StringUtils.isNotBlank(this.basePrice)) {
+            patent.setBasePrice(new BigDecimal(this.basePrice));
+        }
+        if (StringUtils.isNotBlank(this.commissionType)) {
+            if (this.commissionType.contains("固定")) {
+                patent.setCommissionType(CommissionType.COMMISSION);
+            } else if (this.commissionType.contains("百分比")) {
+                patent.setCommissionType(CommissionType.PERCENTAGE);
+            }
+        }
+        if (StringUtils.isNotBlank(this.commission)) {
+            patent.setCommission(new BigDecimal(this.commission));
+        }
+
+        return patent;
+    }
+
+
+    private static List<String> splitStr(String s) {
+        if (StringUtils.isBlank(s)) {
+            return new ArrayList<>();
+        }
+        return Arrays.asList(StringUtils.split(s.replaceAll(" ", "")
+                                                .replace(";", ",")
+                                                .replace(";", ",")
+                                                .replace(",", ","), ","));
+    }
+}

+ 21 - 4
src/main/java/com/izouma/zhirongip/service/demand/PatentDemandService.java

@@ -1,11 +1,14 @@
 package com.izouma.zhirongip.service.demand;
 
 import cn.hutool.core.collection.CollUtil;
+import com.alibaba.excel.EasyExcel;
 import com.izouma.zhirongip.domain.Information;
 import com.izouma.zhirongip.domain.Setting;
 import com.izouma.zhirongip.domain.demand.PatentDemand;
 import com.izouma.zhirongip.domain.supply.Patent;
 import com.izouma.zhirongip.dto.PageQuery;
+import com.izouma.zhirongip.dto.PatentDemandExcelDto;
+import com.izouma.zhirongip.dto.PatentExcelDto;
 import com.izouma.zhirongip.dto.excel.PatentExcel;
 import com.izouma.zhirongip.enums.ApplyStatus;
 import com.izouma.zhirongip.enums.OwnerType;
@@ -13,6 +16,7 @@ import com.izouma.zhirongip.exception.BusinessException;
 import com.izouma.zhirongip.repo.InformationRepo;
 import com.izouma.zhirongip.repo.SettingRepo;
 import com.izouma.zhirongip.repo.demand.PatentDemandRepo;
+import com.izouma.zhirongip.service.SettingService;
 import com.izouma.zhirongip.utils.JpaUtils;
 import com.izouma.zhirongip.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
@@ -38,10 +42,11 @@ public class PatentDemandService {
     private final PatentDemandRepo patentDemandRepo;
     private final SettingRepo      settingRepo;
     private final InformationRepo  informationRepo;
+    private final SettingService   settingService;
 
     public Page<PatentDemand> all(PageQuery pageQuery) {
         Map<Long, String> settingMap = settingRepo.findAllByFlagIn(CollUtil.list(false, 1, 13, 24, 25, 26)).stream()
-                .collect(Collectors.toMap(Setting::getId, Setting::getName));
+                                                  .collect(Collectors.toMap(Setting::getId, Setting::getName));
         return patentDemandRepo
                 .findAll(JpaUtils.toSpecification(pageQuery, PatentDemand.class), JpaUtils.toPageRequest(pageQuery))
                 .map(cd -> {
@@ -63,9 +68,9 @@ public class PatentDemandService {
         PatentDemand record = patentDemandRepo.findById(id).orElseThrow(new BusinessException("无记录"));
 
         Information information = Information.builder()
-                .receiveUserId(record.getUserId())
-                .isRead(false)
-                .build();
+                                             .receiveUserId(record.getUserId())
+                                             .isRead(false)
+                                             .build();
 
         if (pass) {
             record.setStatus(ApplyStatus.PASS);
@@ -82,5 +87,17 @@ public class PatentDemandService {
         informationRepo.save(information);
     }
 
+    @Transactional(rollbackOn = Exception.class)
+    public void upload1(InputStream is) throws IOException {
+        List<PatentDemandExcelDto> dtos = EasyExcel.read(is).head(PatentDemandExcelDto.class).sheet().doReadSync();
+        List<PatentDemand> patents = dtos.stream().map(PatentDemandExcelDto::toPatentDemand)
+                                         .collect(Collectors.toList());
+        List<Setting> settings = settingService.getTree(settingRepo.findAllByFlag(1));
+        patents.forEach(d -> {
+            d.setIndustryClass(settings.stream().filter(s -> s.getName().equals(d.getIndustryName())).findFirst()
+                                       .map(Setting::getId).orElse(null));
+        });
+        patentDemandRepo.saveAll(patents);
+    }
 
 }

+ 43 - 29
src/main/java/com/izouma/zhirongip/service/supply/PatentService.java

@@ -1,11 +1,12 @@
 package com.izouma.zhirongip.service.supply;
 
 import cn.hutool.core.collection.CollUtil;
+import com.alibaba.excel.EasyExcel;
 import com.izouma.zhirongip.domain.Information;
 import com.izouma.zhirongip.domain.Setting;
-import com.izouma.zhirongip.domain.demand.PatentDemand;
 import com.izouma.zhirongip.domain.supply.Patent;
 import com.izouma.zhirongip.dto.PageQuery;
+import com.izouma.zhirongip.dto.PatentExcelDto;
 import com.izouma.zhirongip.dto.excel.PatentExcel;
 import com.izouma.zhirongip.enums.ApplyStatus;
 import com.izouma.zhirongip.enums.CaseType;
@@ -14,6 +15,7 @@ import com.izouma.zhirongip.exception.BusinessException;
 import com.izouma.zhirongip.repo.InformationRepo;
 import com.izouma.zhirongip.repo.SettingRepo;
 import com.izouma.zhirongip.repo.supply.PatentRepo;
+import com.izouma.zhirongip.service.SettingService;
 import com.izouma.zhirongip.utils.JpaUtils;
 import com.izouma.zhirongip.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
@@ -30,7 +32,6 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Random;
 import java.util.stream.Collectors;
 
 @Service
@@ -40,47 +41,48 @@ public class PatentService {
     private final PatentRepo      patentRepo;
     private final SettingRepo     settingRepo;
     private final InformationRepo informationRepo;
+    private final SettingService  settingService;
 
     public Page<Patent> all(PageQuery pageQuery) {
         Map<Long, String> settingMap = settingRepo.findAllByFlagIn(CollUtil.list(false, 1, 13, 24, 25, 26)).stream()
-                .collect(Collectors.toMap(Setting::getId, Setting::getName));
+                                                  .collect(Collectors.toMap(Setting::getId, Setting::getName));
         return patentRepo.findAll(JpaUtils.toSpecification(pageQuery, Patent.class), JpaUtils.toPageRequest(pageQuery))
-                .map(cd -> {
-                    cd.setIndustryName(settingMap.get(cd.getIndustryClass()));
-                    if (cd.getPatentTypeId() != null) {
-                        cd.setPatentType(settingMap.get(cd.getPatentTypeId()));
-                    }
-                    if (cd.getLawStatusId() != null) {
-                        cd.setLawStatus(settingMap.get(cd.getLawStatusId()));
-                    }
-                    if (cd.getTradingMethodId() != null) {
-                        cd.setTradingMethod(settingMap.get(cd.getTradingMethodId()));
-                    }
-                    cd.setView((long) (Math.random() * 10 + 10));
-                    return cd;
-                });
+                         .map(cd -> {
+//                             cd.setIndustryName(settingMap.get(cd.getIndustryClass()));
+//                             if (cd.getPatentTypeId() != null) {
+//                                 cd.setPatentType(settingMap.get(cd.getPatentTypeId()));
+//                             }
+//                             if (cd.getLawStatusId() != null) {
+//                                 cd.setLawStatus(settingMap.get(cd.getLawStatusId()));
+//                             }
+//                             if (cd.getTradingMethodId() != null) {
+//                                 cd.setTradingMethod(settingMap.get(cd.getTradingMethodId()));
+//                             }
+//                             cd.setView((long) (Math.random() * 10 + 10));
+                             return cd;
+                         });
     }
 
     public Patent get(Long id) {
         Patent patent = patentRepo.findById(id).orElseThrow(new BusinessException("无记录"));
         patent.setIndustryName(settingRepo.findById(patent.getIndustryClass())
-                .orElseThrow(new BusinessException("无记录"))
-                .getName());
+                                          .orElseThrow(new BusinessException("无记录"))
+                                          .getName());
 
         if (patent.getPatentTypeId() != null) {
             patent.setPatentType(settingRepo.findById(patent.getPatentTypeId())
-                    .orElseThrow(new BusinessException("无记录"))
-                    .getName());
+                                            .orElseThrow(new BusinessException("无记录"))
+                                            .getName());
         }
         if (patent.getLawStatusId() != null) {
             patent.setLawStatus(settingRepo.findById(patent.getLawStatusId())
-                    .orElseThrow(new BusinessException("无记录"))
-                    .getName());
+                                           .orElseThrow(new BusinessException("无记录"))
+                                           .getName());
         }
         if (patent.getTradingMethodId() != null) {
             patent.setTradingMethod(settingRepo.findById(patent.getTradingMethodId())
-                    .orElseThrow(new BusinessException("无记录"))
-                    .getName());
+                                               .orElseThrow(new BusinessException("无记录"))
+                                               .getName());
         }
         return patent;
     }
@@ -89,9 +91,9 @@ public class PatentService {
         Patent record = patentRepo.findById(id).orElseThrow(new BusinessException("无记录"));
 
         Information information = Information.builder()
-                .receiveUserId(record.getUserId())
-                .isRead(false)
-                .build();
+                                             .receiveUserId(record.getUserId())
+                                             .isRead(false)
+                                             .build();
 
         if (pass) {
             record.setStatus(ApplyStatus.PASS);
@@ -125,7 +127,7 @@ public class PatentService {
         List<Patent> patents = new ArrayList<>();
         int index = 0;
         Map<String, Long> settingMap = settingRepo.findAllByFlagIn(CollUtil.list(false, 1, 13, 24, 25, 26)).stream()
-                .collect(Collectors.toMap(Setting::getName, Setting::getId));
+                                                  .collect(Collectors.toMap(Setting::getName, Setting::getId));
         Map<String, OwnerType> typeMap = new HashMap<>();
         typeMap.put("企事业单位", OwnerType.ENTERPRISES_AND_INSTITUTIONS);
         typeMap.put("高校院所", OwnerType.UNIVERSITIES_AND_INSTITUTES);
@@ -164,4 +166,16 @@ public class PatentService {
         }
         patentRepo.saveAll(patents);
     }
+
+    @Transactional(rollbackOn = Exception.class)
+    public void upload1(InputStream is) throws IOException {
+        List<PatentExcelDto> dtos = EasyExcel.read(is).head(PatentExcelDto.class).sheet().doReadSync();
+        List<Patent> patents = dtos.stream().map(PatentExcelDto::toPatent).collect(Collectors.toList());
+        List<Setting> settings = settingService.getTree(settingRepo.findAllByFlag(1));
+        patents.forEach(d -> {
+            d.setIndustryClass(settings.stream().filter(s -> s.getName().equals(d.getIndustryName())).findFirst()
+                                       .map(Setting::getId).orElse(null));
+        });
+        patentRepo.saveAll(patents);
+    }
 }

+ 38 - 8
src/main/java/com/izouma/zhirongip/web/demand/PatentDemandController.java

@@ -1,6 +1,10 @@
 package com.izouma.zhirongip.web.demand;
 
+import com.izouma.zhirongip.domain.Setting;
+import com.izouma.zhirongip.dto.PatentDemandExcelDto;
+import com.izouma.zhirongip.dto.PatentExcelDto;
 import com.izouma.zhirongip.repo.SettingRepo;
+import com.izouma.zhirongip.service.SettingService;
 import com.izouma.zhirongip.utils.SecurityUtils;
 import com.izouma.zhirongip.web.BaseController;
 import com.izouma.zhirongip.domain.demand.PatentDemand;
@@ -13,21 +17,27 @@ import com.izouma.zhirongip.utils.excel.ExcelUtils;
 
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.data.domain.Page;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @RestController
 @RequestMapping("/patentDemand")
 @AllArgsConstructor
+@Slf4j
 public class PatentDemandController extends BaseController {
     private final PatentDemandService patentDemandService;
     private final PatentDemandRepo    patentDemandRepo;
     private final SettingRepo         settingRepo;
+    private final SettingService      settingService;
 
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")
@@ -52,18 +62,18 @@ public class PatentDemandController extends BaseController {
     public PatentDemand get(@PathVariable Long id) {
         PatentDemand record = patentDemandRepo.findById(id).orElseThrow(new BusinessException("无记录"));
         settingRepo.findById(record.getIndustryClass())
-                .ifPresent(setting -> record.setIndustryName(setting.getName()));
-        if(record.getModeId()!=null){
+                   .ifPresent(setting -> record.setIndustryName(setting.getName()));
+        if (record.getModeId() != null) {
             settingRepo.findById(record.getModeId())
-                    .ifPresent(setting -> record.setMode(setting.getName()));
+                       .ifPresent(setting -> record.setMode(setting.getName()));
         }
-        if(record.getPatentStatusId()!=null){
+        if (record.getPatentStatusId() != null) {
             settingRepo.findById(record.getPatentStatusId())
-                    .ifPresent(setting -> record.setPatentStatus(setting.getName()));
+                       .ifPresent(setting -> record.setPatentStatus(setting.getName()));
         }
-        if(record.getPatentTypeId()!=null){
+        if (record.getPatentTypeId() != null) {
             settingRepo.findById(record.getPatentTypeId())
-                    .ifPresent(setting -> record.setPatentType(setting.getName()));
+                       .ifPresent(setting -> record.setPatentType(setting.getName()));
         }
         return record;
     }
@@ -76,7 +86,15 @@ public class PatentDemandController extends BaseController {
     @GetMapping("/excel")
     @ResponseBody
     public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
-        List<PatentDemand> data = all(pageQuery).getContent();
+        List<PatentDemandExcelDto> data = all(pageQuery)
+                .getContent().stream()
+                .map(PatentDemandExcelDto::from)
+                .collect(Collectors.toList());
+        List<Setting> settings = settingService.getTree(settingRepo.findAllByFlag(1));
+        data.forEach(d -> {
+            d.setIndustryName(settings.stream().filter(s -> s.getId().equals(d.getIndustryClass())).findFirst()
+                                      .map(Setting::getName).orElse(null));
+        });
         ExcelUtils.export(response, data);
     }
 
@@ -86,5 +104,17 @@ public class PatentDemandController extends BaseController {
     public void audit(@RequestParam Long id, @RequestParam boolean pass, String remark) {
         patentDemandService.audit(id, pass, remark);
     }
+
+    @PostMapping("/upload")
+    public void uploadFile(@RequestParam("file") MultipartFile file) {
+        InputStream is;
+        try {
+            is = file.getInputStream();
+            patentDemandService.upload1(is);
+        } catch (IOException e) {
+            log.error("上传失败", e);
+            throw new BusinessException("上传失败", e.getMessage());
+        }
+    }
 }
 

+ 19 - 4
src/main/java/com/izouma/zhirongip/web/supply/PatentController.java

@@ -1,5 +1,9 @@
 package com.izouma.zhirongip.web.supply;
 
+import com.izouma.zhirongip.domain.Setting;
+import com.izouma.zhirongip.dto.PatentExcelDto;
+import com.izouma.zhirongip.repo.SettingRepo;
+import com.izouma.zhirongip.service.SettingService;
 import com.izouma.zhirongip.utils.SecurityUtils;
 import com.izouma.zhirongip.web.BaseController;
 import com.izouma.zhirongip.domain.supply.Patent;
@@ -22,14 +26,17 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @RestController
 @RequestMapping("/patent")
 @AllArgsConstructor
 @Slf4j
 public class PatentController extends BaseController {
-    private final PatentService patentService;
-    private final PatentRepo    patentRepo;
+    private final PatentService  patentService;
+    private final PatentRepo     patentRepo;
+    private final SettingService settingService;
+    private final SettingRepo    settingRepo;
 
     //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")
@@ -63,7 +70,15 @@ public class PatentController extends BaseController {
     @GetMapping("/excel")
     @ResponseBody
     public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
-        List<Patent> data = all(pageQuery).getContent();
+        List<PatentExcelDto> data = all(pageQuery)
+                .getContent().stream()
+                .map(PatentExcelDto::from)
+                .collect(Collectors.toList());
+        List<Setting> settings = settingService.getTree(settingRepo.findAllByFlag(1));
+        data.forEach(d -> {
+            d.setIndustryName(settings.stream().filter(s -> s.getId().equals(d.getIndustryClass())).findFirst()
+                                      .map(Setting::getName).orElse(null));
+        });
         ExcelUtils.export(response, data);
     }
 
@@ -79,7 +94,7 @@ public class PatentController extends BaseController {
         InputStream is;
         try {
             is = file.getInputStream();
-            patentService.upload(is);
+            patentService.upload1(is);
         } catch (IOException e) {
             log.error("上传失败", e);
             throw new BusinessException("上传失败", e.getMessage());

+ 10 - 2
src/main/vue/src/components/ExcelUpload.vue

@@ -8,8 +8,11 @@
         :on-success="onSuccess"
         class="uploader"
         :on-error="onfail"
+        :disabled="loading"
     >
-        <el-button icon="el-icon-upload2" slot="trigger" size="small" class="filter-item">导入</el-button>
+        <el-button icon="el-icon-upload2" slot="trigger" size="small" class="filter-item" :loading="loading"
+            >导入</el-button
+        >
     </el-upload>
 </template>
 
@@ -26,7 +29,8 @@ export default {
     },
     data() {
         return {
-            uploadUrl: ''
+            uploadUrl: '',
+            loading: false
         };
     },
     computed: {
@@ -45,16 +49,20 @@ export default {
             console.log(e);
             this.$message.error('失败');
             this.changeSelect();
+            this.loading = false;
         },
         onSuccess() {
             this.$message.success('上传成功');
             this.changeSelect();
+            this.loading = false;
         },
         beforeUpload() {
             return this.$confirm('确认要导入文件数据吗?', '提示', {
                 confirmButtonText: '确定',
                 cancelButtonText: '取消',
                 type: 'warning'
+            }).then(() => {
+                this.loading = true;
             });
         },
         changeSelect() {

+ 4 - 3
src/main/vue/src/views/demand/GeneralPatentDemandList.vue

@@ -10,7 +10,7 @@
             >
                 新增
             </el-button>
-            <!-- <el-button
+            <el-button
                 @click="download"
                 icon="el-icon-upload2"
                 :loading="downloading"
@@ -18,7 +18,8 @@
                 class="filter-item"
             >
                 导出
-            </el-button> -->
+            </el-button>
+            <excel-upload uri="/patentDemand/upload" />
         </page-title>
         <div class="filters-container">
             <el-input
@@ -158,7 +159,7 @@ import pageableTable from '@/mixins/pageableTable';
 import tradingMethod from '@/mixins/tradingMethod';
 import SettingSelect from '../../components/select/SettingSelect.vue';
 import CreatedPicker from '../../components/select/CreatedPicker.vue';
-
+import ExcelUpload from '../../components/ExcelUpload.vue';
 export default {
     components: { SettingSelect, CreatedPicker },
     name: 'GeneralPatentDemandList',

+ 3 - 3
src/main/vue/src/views/demand/PatentDemandList.vue

@@ -10,7 +10,7 @@
             >
                 新增
             </el-button>
-            <!-- <el-button
+            <el-button
                 @click="download"
                 icon="el-icon-upload2"
                 :loading="downloading"
@@ -18,7 +18,7 @@
                 class="filter-item"
             >
                 导出
-            </el-button> -->
+            </el-button>
         </page-title>
         <div class="filters-container">
             <el-input
@@ -130,7 +130,7 @@ import pageableTable from '@/mixins/pageableTable';
 import tradingMethod from '@/mixins/tradingMethod';
 import SettingSelect from '../../components/select/SettingSelect.vue';
 import CreatedPicker from '../../components/select/CreatedPicker.vue';
-
+import ExcelUpload from '../../components/ExcelUpload.vue';
 export default {
     components: { SettingSelect, CreatedPicker },
     name: 'PatentDemandList',

+ 1 - 2
src/main/vue/src/views/resource/PolicyLawEdit.vue

@@ -91,9 +91,8 @@
     </div>
 </template>
 <script>
-import FileUpload from '../../components/FileUpload.vue';
 export default {
-    components: { FileUpload },
+    components: {},
     name: 'PolicyLawEdit',
     created() {
         if (this.$route.query.id) {

+ 5 - 3
src/main/vue/src/views/supply/GeneralPatentList.vue

@@ -10,7 +10,7 @@
             >
                 新增
             </el-button>
-            <!-- <el-button
+            <el-button
                 @click="download"
                 icon="el-icon-upload2"
                 :loading="downloading"
@@ -18,7 +18,8 @@
                 class="filter-item"
             >
                 导出
-            </el-button> -->
+            </el-button>
+            <excel-upload uri="/patent/upload" />
         </page-title>
         <div class="filters-container">
             <setting-select name="所属领域" :flag="1" v-model="industry" @input="getData"></setting-select>
@@ -184,9 +185,10 @@ import pageableTable from '@/mixins/pageableTable';
 import tradingMethod from '@/mixins/tradingMethod';
 import SettingSelect from '../../components/select/SettingSelect.vue';
 import CreatedPicker from '../../components/select/CreatedPicker.vue';
+import ExcelUpload from '../../components/ExcelUpload.vue';
 
 export default {
-    components: { SettingSelect, CreatedPicker },
+    components: { SettingSelect, CreatedPicker, ExcelUpload },
     name: 'GeneralPatentList',
     mixins: [pageableTable, tradingMethod],
     data() {