Преглед изворни кода

20240902 修改标注库查询,查询专题库专利

lwhhszx пре 1 година
родитељ
комит
d7c2e9838d

+ 14 - 0
src/main/java/cn/cslg/pas/service/business/AssoProjectPersonService.java

@@ -173,10 +173,24 @@ public class AssoProjectPersonService extends ServiceImpl<AssoProjectPersonMappe
     public List<Integer> getRootProjectIds() {
 
         PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
+
+        Integer roleType = personnelVO.getRoleType();
+        Integer tenantId =personnelVO.getTenantId();
+        if(roleType!=null&&roleType.equals(1))
+        {
+       return  null;
+        }
+
         String createId = personnelVO.getId();
         List<Integer> ids = new ArrayList<>();
         LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.select(Project::getId);
+        if(roleType!=null&&roleType.equals(2)){
+            queryWrapper.eq(Project::getTenantId, tenantId);
+        }
+        else {
+            queryWrapper.eq(Project::getCreateId, createId);
+        }
         queryWrapper.eq(Project::getCreateId, createId)
                 .or().eq(Project::getHeadId, createId);
         List<Project> projects =projectService.list(queryWrapper);

+ 348 - 193
src/main/java/cn/cslg/pas/service/business/PatentExportService.java

@@ -5,31 +5,47 @@ import cn.cslg.pas.common.dto.PatentColumnDTO;
 import cn.cslg.pas.common.dto.PatentExport.PatentExportVO;
 import cn.cslg.pas.common.dto.es.EsQueryPatentFieldsDTO;
 import cn.cslg.pas.common.dto.es.InnerFields;
+import cn.cslg.pas.common.model.cronModel.Records;
+import cn.cslg.pas.common.model.request.QueryRequest;
 import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.vo.ConfigVOS.PatentConfigVO;
 import cn.cslg.pas.common.vo.FieldValueVO;
+import cn.cslg.pas.common.vo.ImportTaskAMVO;
+import cn.cslg.pas.common.vo.PatentPageMessageVO;
 import cn.cslg.pas.common.vo.WebSocketMessageVO;
 import cn.cslg.pas.common.vo.business.PatentNoVO;
 import cn.cslg.pas.common.vo.es.EsCustomFieldBatchVO;
+import cn.cslg.pas.common.vo.es.EsPatentCommonVO;
 import cn.cslg.pas.common.vo.es.EsPatentFieldsVO;
 import cn.cslg.pas.common.vo.es.InnerPatentFieldsVO;
 import cn.cslg.pas.domain.business.ImportTask;
+import cn.cslg.pas.domain.es.Patent;
+import cn.cslg.pas.exception.ExceptionEnum;
 import cn.cslg.pas.exception.XiaoShiException;
 import cn.cslg.pas.factorys.PatentExportFactory.GetValueImp;
 import cn.cslg.pas.factorys.PatentExportFactory.PatentExportFactory;
 import cn.cslg.pas.service.business.es.EsCustomFieldService;
 import cn.cslg.pas.service.business.es.EsPatentService;
+import cn.cslg.pas.service.business.es.EsService;
 import cn.cslg.pas.service.common.MessageService;
+import co.elastic.clients.elasticsearch.ElasticsearchClient;
+import co.elastic.clients.elasticsearch._types.aggregations.Aggregate;
+import co.elastic.clients.elasticsearch.core.SearchRequest;
+import co.elastic.clients.elasticsearch.core.SearchResponse;
+import co.elastic.clients.elasticsearch.core.search.Hit;
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.hssf.usermodel.*;
 import org.apache.poi.hssf.util.HSSFColor;
 import org.apache.poi.ss.usermodel.FillPatternType;
 import org.apache.poi.ss.usermodel.HorizontalAlignment;
 import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
@@ -39,6 +55,7 @@ import java.util.stream.Collectors;
 
 /**
  * Excel导出专利
+ *
  * @Author xiexiang
  * @Date 2024/1/3
  */
@@ -66,200 +83,14 @@ public class PatentExportService {
 
     @Autowired
     private EsCustomFieldService esCustomFieldService;
+    @Autowired
+    private EsService esService;
 
-//    /**
-//     * 导出专利
-//     *
-//     * @param exportTask
-//     * @return
-//     * @throws IOException
-//     */
-//    @Async
-//    public void exportPatent(ExportTaskDTO exportTask) throws IOException {
-//        EsCustomFieldBatchVO EsVO = exportTask.getEsVO();
-//        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
-//            //字段是否被选择
-//            String esSelected = JsonUtils.objectToJson(EsVO.getSelected());
-//            //专利字段的集合
-//            List<PatentExportVO> selected = Optional.ofNullable(JsonUtils.jsonToList(esSelected, PatentExportVO.class))
-//                    .orElse(new ArrayList<>());
-//
-//            if (selected.isEmpty()) {
-//                throw new IllegalArgumentException("没有选择要导出的字段数据");
-//            }
-//
-//            //key的集合(标头:例如patentNo)
-//            //过滤出被选择的字段
-//            List<PatentExportVO> patentExportVOS = selected.stream()
-//                    .filter(PatentExportVO::getSelected)
-//                    .collect(Collectors.toList());
-//            List<String> types = Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
-//            List<InnerFields> innerFieldsList = new ArrayList<>();
-//            for (PatentExportVO patentExportVO : patentExportVOS) {
-//                if (types.contains(patentExportVO.getType())) {
-//                    InnerFields innerFields = new InnerFields();
-//                    innerFields.setFieldId(patentExportVO.getValue());
-//                    innerFields.setFieldType(Integer.parseInt(patentExportVO.getType()));
-//                    innerFieldsList.add(innerFields);
-//                }
-//            }
-//            //name的集合
-//            List<String> headers = selected.stream().filter(PatentExportVO::getSelected).map(PatentExportVO::getName).distinct().collect(Collectors.toList());
-//            //新建工作簿
-//            HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
-//            //新建sheet页
-//            HSSFSheet sheet = hssfWorkbook.createSheet();
-//            sheet.setDefaultColumnWidth(30);
-//            //新建标头行
-//            HSSFRow headerRow = sheet.createRow(0);
-//            headerRow.setHeight((short) 500);
-//            //新建标头行格式
-//            HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();
-//            //新建普通行格式
-//            HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();
-//            //遍历设置标头
-//            for (int i = 0; i < headers.size(); i++) {
-//                HSSFCell cell = headerRow.createCell(i);
-//                ExcelUtils.setExcelCellStyle(headerCellStyle);
-//                headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
-//                headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
-//                headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
-//                headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
-//                headerCellStyle.setWrapText(true);
-//                cell.setCellStyle(headerCellStyle);
-//                cell.setCellValue(headers.get(i));
-//            }
-//            //根据projectId查询专利信息
-//            List<String> patentNos = pdfExportFirstPageService.getPatentNo(EsVO);
-//            if (patentNos.isEmpty()) {
-//                throw new XiaoShiException("未获取到专利信息");
-//            }
-//            Integer total = patentNos.size();
-//            Integer defaultNum = 0;
-//            for (int i = 0; i < patentNos.size(); i++) {
-//                String patentNo = patentNos.get(i);
-//                Map<String, Object> map = new LinkedHashMap<>();
-//                PatentNoVO patentNoVO = new PatentNoVO();
-//                patentNoVO.setPatentNo(patentNo);
-//                patentNoVO.setProjectId(exportTask.getProjectId());
-//                PatentColumnDTO patent = patentService.selectPatentDetail(patentNoVO);
-//                if (patent == null) {
-//                    defaultNum++;
-//                    continue;
-//                }
-//
-//                EsQueryPatentFieldsDTO esQueryPatentFieldsDTO = new EsQueryPatentFieldsDTO();
-//                esQueryPatentFieldsDTO.setProjectId(exportTask.getProjectId());
-//                esQueryPatentFieldsDTO.setTaskId(EsVO.getTaskId());
-//                esQueryPatentFieldsDTO.setPatentNos(patentNos);
-//                esQueryPatentFieldsDTO.setInnerFields(innerFieldsList);
-//                List<EsPatentFieldsVO> list = esCustomFieldService.getPatentFields(esQueryPatentFieldsDTO);
-//
-//
-//                for (int j = 0; j < patentExportVOS.size(); j++) {
-//                    String column = patentExportVOS.get(j).getValue();
-//                    String name = patentExportVOS.get(j).getName();
-//                    String type = patentExportVOS.get(j).getType();
-//
-//                    if (types.contains(type)) {
-//                        EsPatentFieldsVO esPatentFieldsVO = list.stream()
-//                                .filter(item -> item.getPatentNo().equals(patentNo))
-//                                .findFirst()
-//                                .orElse(null);
-//                        if (esPatentFieldsVO != null) {
-//                            List<InnerPatentFieldsVO> innerClassFields = esPatentFieldsVO.getInnerClassFields();
-//                            if (!innerClassFields.isEmpty()) {
-//                                InnerPatentFieldsVO innerPatentFieldsVO = innerClassFields.stream()
-//                                        .filter(item -> item.getField().equals(column) && item.getFieldType().equals(Integer.parseInt(type)))
-//                                        .findFirst()
-//                                        .orElse(null);
-//                                if (innerPatentFieldsVO != null) {
-//                                    List<FieldValueVO> fieldValueVOS = innerPatentFieldsVO.getFieldValueVOS();
-//                                    if (!fieldValueVOS.isEmpty()) {
-//                                        StringBuffer sb = new StringBuffer();
-//                                        for (FieldValueVO fieldValueVO : fieldValueVOS) {
-//                                            String valueStr = fieldValueVO.getValue();
-//                                            sb.append(valueStr);
-//                                        }
-//                                        map.put(name, sb.toString());
-//                                    }
-//                                }
-//                            }
-//                        }
-//                    } else {
-//                        // 使用反射获取属性值
-//                        Object value = GenerateObjectUtil.getPropertyValue(patent, column);
-//                        if (value != null) {
-//                            String json = CommonService.readJsonFile("patent.json");
-//                            List<PatentConfigVO> patentConfigVOS = JSON.parseArray(json, PatentConfigVO.class);
-//                            PatentConfigVO patentConfigVO = patentConfigVOS.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(null);
-//                            String exportClass = patentConfigVO.getExportClass();
-//                            GetValueImp getValueImp = patentExportFactory.getClass(exportClass);
-//                            if (getValueImp != null) {
-//                                String reValue = getValueImp.getValue(value);
-//                                map.put(name, reValue);
-//                            }
-//                        }
-//                    }
-//                }
-//                //新建一普通行
-//                HSSFRow row = sheet.createRow(i + 1);
-//                row.setHeight((short) 800);
-//                for (String key : map.keySet()) {
-//                    int index = headers.indexOf(key);
-//                    if (index != -1) {
-//                        HSSFCell cell = row.createCell(index);
-//                        ExcelUtils.setExcelCellStyle(commonCellStyle);
-//                        commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
-//                        commonCellStyle.setWrapText(true);
-//                        cell.setCellStyle(commonCellStyle);
-//                        if (StringUtils.isNotNull(map.get(key))) {
-//                            cell.setCellValue(String.valueOf(map.get(key)));
-//                        }
-//                    }
-//                }
-//                WebSocketMessageVO webSocketMessageVO = new WebSocketMessageVO();
-//                webSocketMessageVO.setProjectId(EsVO.getProjectId());
-//                webSocketMessageVO.setCreateId(exportTask.getCreateId());
-//                webSocketMessageVO.setCode(602);
-//                webSocketMessageVO.setAllNum(total);
-//                webSocketMessageVO.setCurrentNum(i+1);
-//                webSocketMessageVO.setTaskId(exportTask.getTaskId());
-//                webSocketMessageVO.setState(1);
-//                messageService.sendPatentExportMessage(webSocketMessageVO);
-//            }
-//            hssfWorkbook.write(out);
-//            WebSocketMessageVO webSocketMessageVO = new WebSocketMessageVO();
-//            webSocketMessageVO.setProjectId(EsVO.getProjectId());
-//            webSocketMessageVO.setCreateId(exportTask.getCreateId());
-//            webSocketMessageVO.setCode(603);
-//            webSocketMessageVO.setAllNum(total);
-//            webSocketMessageVO.setCurrentNum(total);
-//            webSocketMessageVO.setTaskId(exportTask.getTaskId());
-//            webSocketMessageVO.setState(2);
-//            messageService.sendPatentExportMessage(webSocketMessageVO);
-//            String fileGuid = "";
-//            if (out.toByteArray() != null && out.toByteArray().length != 0) {
-//                fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray(), 1);
-//            }
-//            exportTask.setFileGuid(fileGuid);
-//            exportTask.setAllNum(total);
-//            exportTask.setDefaultNum(defaultNum);
-//            exportTask.setDoneNum(total - defaultNum);
-//            exportTask.setState(2);
-//            Integer taskId = importTaskService.updateExportTask(exportTask);
-//            if (taskId == null) {
-//                throw new XiaoShiException("导出记录失败");
-//            }
-//
-//        } catch (FileNotFoundException e) {
-//            throw new FileNotFoundException();
-//        } catch (Exception e) {
-//
-//        }
-//    }
-
+    @Autowired
+    private ElasticsearchClient client;
 
+    @Autowired
+    private EsPatentService esPatentService;
     /**
      * 导出专利
      *
@@ -270,6 +101,7 @@ public class PatentExportService {
     @Async
     public void exportPatent(ExportTaskDTO exportTask) throws IOException {
         EsCustomFieldBatchVO EsVO = exportTask.getEsVO();
+
         try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
             //字段是否被选择
             String esSelected = JsonUtils.objectToJson(EsVO.getSelected());
@@ -417,7 +249,7 @@ public class PatentExportService {
                 webSocketMessageVO.setCreateId(exportTask.getCreateId());
                 webSocketMessageVO.setCode(602);
                 webSocketMessageVO.setAllNum(total);
-                webSocketMessageVO.setCurrentNum(i+1);
+                webSocketMessageVO.setCurrentNum(i + 1);
                 webSocketMessageVO.setTaskId(exportTask.getTaskId());
                 webSocketMessageVO.setState(1);
                 messageService.sendPatentExportMessage(webSocketMessageVO);
@@ -455,4 +287,327 @@ public class PatentExportService {
     }
 
 
+    public HSSFWorkbook getExportHssWorkbook(List<String> headers) {
+
+        //新建工作簿
+        HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
+        //新建sheet页
+        HSSFSheet sheet = hssfWorkbook.createSheet();
+        sheet.setDefaultColumnWidth(30);
+        //新建标头行
+        HSSFRow headerRow = sheet.createRow(0);
+        headerRow.setHeight((short) 500);
+        //新建标头行格式
+        HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();
+        //新建普通行格式
+        HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();
+        //遍历设置标头
+        for (int i = 0; i < headers.size(); i++) {
+            HSSFCell cell = headerRow.createCell(i);
+            ExcelUtils.setExcelCellStyle(headerCellStyle);
+            headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
+            headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+            headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
+            headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+            headerCellStyle.setWrapText(true);
+            cell.setCellStyle(headerCellStyle);
+            cell.setCellValue(headers.get(i));
+        }
+        return hssfWorkbook;
+    }
+
+
+    public Integer updateTaskStateToDoing(Integer taskId) {
+        ImportTask importTask = importTaskService.getById(taskId);
+        if (importTask == null) {
+            throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "导入任务不存在");
+        } else {
+            importTask.setState(1);
+            importTask.updateById();
+        }
+        return importTask.getId();
+    }
+
+    public Records queryPatents(EsPatentCommonVO esPatentCommonVO) throws Exception {
+        List<Patent> patentList = new ArrayList<>();
+        Records records = new Records();
+        SearchRequest.Builder builder = esService.getCommonPatent(esPatentCommonVO);
+        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+        List<Hit<Patent>> hits = response.hits().hits();
+        Long total = 0L;
+        if (org.apache.commons.lang3.StringUtils.isNotEmpty(esPatentCommonVO.getEsField())) {
+            Aggregate aggregate = response.aggregations().get("count");
+            total = aggregate.cardinality().value();
+        } else {
+            total = response.hits().total().value();
+        }
+        records.setTotal(total);
+        for (Hit<Patent> hit : hits) {
+            patentList.add(hit.source());
+        }
+        records.setData(patentList);
+        return records;
+    }
+
+
+    public void exportPatent2(ExportTaskDTO exportTask, ImportTaskAMVO importTaskAMVO) throws Exception {
+
+        EsCustomFieldBatchVO esVO = exportTask.getEsVO();
+        List<PatentExportVO> selectedFields = esVO.getSelected();
+        Integer taskId = exportTask.getTaskId();
+        Integer projectId = exportTask.getProjectId();
+        String createId = exportTask.getCreateId();
+        if (taskId == null) {
+            throw new XiaoShiException(ExceptionEnum.BUSINESS_CHECK, "任务id不可为空");
+        }
+        if (CollectionUtils.isEmpty(selectedFields)) {
+            throw new IllegalArgumentException("没有选择要导出的字段数据");
+        }
+
+        this.updateTaskStateToDoing(taskId);
+
+        List<String> headers = selectedFields.stream().filter(PatentExportVO::getSelected).map(PatentExportVO::getName).distinct().collect(Collectors.toList());
+
+        List<String> notInNos = esVO.getIsDelete();
+        List<String> inNos = esVO.getIsAdd();
+
+        List<String> types = Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
+        List<InnerFields> innerFieldsList = new ArrayList<>();
+        for (PatentExportVO patentExportVO : selectedFields) {
+            if (types.contains(patentExportVO.getType())) {
+                InnerFields innerFields = new InnerFields();
+                innerFields.setFieldId(patentExportVO.getValue());
+                innerFields.setFieldType(Integer.parseInt(patentExportVO.getType()));
+                innerFieldsList.add(innerFields);
+            }
+        }
+        HSSFWorkbook hssfWorkbook = this.getExportHssWorkbook(headers);
+        HSSFSheet hssfSheet = hssfWorkbook.createSheet();
+        QueryRequest queryRequest = new QueryRequest();
+        BeanUtils.copyProperties(esVO, queryRequest);
+
+        EsQueryPatentFieldsDTO esQueryPatentFieldsDTO = new EsQueryPatentFieldsDTO();
+        esQueryPatentFieldsDTO.setProjectId(exportTask.getProjectId());
+        esQueryPatentFieldsDTO.setTaskId(esVO.getTaskId());
+        esQueryPatentFieldsDTO.setInnerFields(innerFieldsList);
+
+        HSSFCellStyle commonCellStyle = this.getComCellStyle(hssfWorkbook);
+        Long startNum = null;
+        Long endNum = null;
+        if (esVO.getStartNumber() != null) {
+            startNum = Long.getLong(esVO.getStartNumber().toString());
+        }
+        if (esVO.getEndNumber() != null) {
+            endNum = Long.getLong(esVO.getEndNumber().toString());
+        }
+
+        if (startNum == null) {
+            startNum = 1l;
+        }
+        Long toNum = 10L;
+        if (endNum != null && endNum < toNum) {
+            toNum = endNum;
+        }
+        Integer index = 1;
+        String json = CommonService.readJsonFile("patent.json");
+        List<PatentConfigVO> patentConfigVOS = JSON.parseArray(json, PatentConfigVO.class);
+
+        EsPatentCommonVO esPatentCommonVO = esService.tranPatentRequestToComVO(queryRequest);
+        esPatentCommonVO.setStartNum(startNum);
+        esPatentCommonVO.setEndNum(endNum);
+        Records firstRecords = this.queryPatents(esPatentCommonVO);
+
+        Long total = 0l;
+        if (startNum != null && endNum != null) {
+            total = (endNum - startNum) + 1;
+            if (notInNos != null) {
+                total = total - notInNos.size();
+            }
+            if (inNos != null) {
+                total += inNos.size();
+            }
+        } else if (inNos != null) {
+            total = 0L + inNos.size();
+        } else {
+            firstRecords.getTotal();
+        }
+        List<Patent> firstPatentList = (List<Patent>) firstRecords.getData();
+        List<String> firstPatentNos = firstPatentList.stream().map(Patent::getPatentNo).collect(Collectors.toList());
+        ;
+        //查询自定义字段
+        esQueryPatentFieldsDTO.setPatentNos(firstPatentNos);
+        List<EsPatentFieldsVO> firstEsPatentFieldsVOS = esCustomFieldService.getPatentFields(esQueryPatentFieldsDTO);
+        for (int i = 0; i < firstPatentList.size(); i++) {
+            Patent patent = firstPatentList.get(i);
+            if (notInNos != null && notInNos.contains(patent.getPatentNo())) {
+                continue;
+            }
+            this.loadPatentCell(patent, selectedFields, patentConfigVOS, firstEsPatentFieldsVOS, hssfSheet, commonCellStyle, index);
+
+            index++;
+            this.sendWebSocketMessage(projectId, taskId, createId, total.intValue(), index, false);
+        }
+
+
+        if (endNum == null) {
+            endNum = total;
+        }
+        while (toNum < endNum) {
+            startNum = toNum + 1;
+
+            toNum = toNum + 10L;
+            if (toNum > endNum) {
+                toNum = endNum;
+            }
+
+            esPatentCommonVO.setStartNum(startNum);
+            esPatentCommonVO.setEndNum(endNum);
+            Records records = this.queryPatents(esPatentCommonVO);
+
+            List<Patent> patentList = (List<Patent>) records.getData();
+            List<String> patentNos = patentList.stream().map(Patent::getPatentNo).collect(Collectors.toList());
+            ;
+            //查询自定义字段
+            esQueryPatentFieldsDTO.setPatentNos(patentNos);
+            List<EsPatentFieldsVO> esPatentFieldsVOS = esCustomFieldService.getPatentFields(esQueryPatentFieldsDTO);
+            for (int i = 0; i < patentList.size(); i++) {
+                Patent patent = patentList.get(i);
+                if (notInNos != null && notInNos.contains(patent.getPatentNo())) {
+                    continue;
+                }
+                this.loadPatentCell(patent, selectedFields, patentConfigVOS, esPatentFieldsVOS, hssfSheet, commonCellStyle, index);
+
+                index++;
+                this.sendWebSocketMessage(projectId, taskId, createId, total.intValue(), index, false);
+
+            }
+
+        }
+
+        esQueryPatentFieldsDTO.setPatentNos(inNos);
+        List<EsPatentFieldsVO> esPatentFieldsVOS = esCustomFieldService.getPatentFields(esQueryPatentFieldsDTO);
+        List<Patent> patentList =  esPatentService.getPatentsByNo(inNos,true,null,null);
+        for (int i=0;i<patentList.size();i++){
+
+            Patent patent = patentList.get(i);
+            if (notInNos != null && notInNos.contains(patent.getPatentNo())) {
+                continue;
+            }
+            this.loadPatentCell(patent, selectedFields, patentConfigVOS, esPatentFieldsVOS, hssfSheet, commonCellStyle, index);
+
+            index++;
+            this.sendWebSocketMessage(projectId, taskId, createId, total.intValue(), index, false);
+
+        }
+
+
+        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+
+            hssfWorkbook.write(out);
+
+            String fileGuid = "";
+            if (out.toByteArray() != null && out.toByteArray().length != 0) {
+                fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray(), 1);
+            }
+            exportTask.setFileGuid(fileGuid);
+            Integer reTaskId = importTaskService.updateExportTask(exportTask);
+            if (reTaskId == null) {
+                throw new XiaoShiException("导出记录失败");
+            }
+
+        } catch (FileNotFoundException e) {
+            throw new FileNotFoundException();
+        } catch (Exception e) {
+
+        }
+    }
+
+    public void sendWebSocketMessage(Integer projectId, Integer taskId, String createId, Integer total, Integer index, Boolean ifDone) {
+        WebSocketMessageVO webSocketMessageVO = new WebSocketMessageVO();
+        webSocketMessageVO.setProjectId(projectId);
+        webSocketMessageVO.setCreateId(createId);
+        if (ifDone) {
+            webSocketMessageVO.setCode(603);
+        } else {
+            webSocketMessageVO.setCode(602);
+        }
+        webSocketMessageVO.setAllNum(total);
+        webSocketMessageVO.setCurrentNum(index);
+        webSocketMessageVO.setTaskId(taskId);
+        if (ifDone) {
+            webSocketMessageVO.setState(2);
+        } else {
+            webSocketMessageVO.setState(1);
+        }
+        messageService.sendPatentExportMessage(webSocketMessageVO);
+    }
+
+    public HSSFCellStyle getComCellStyle(HSSFWorkbook hssfWorkbook) {
+        HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();
+        ExcelUtils.setExcelCellStyle(commonCellStyle);
+        commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+        commonCellStyle.setWrapText(true);
+        return commonCellStyle;
+    }
+
+    public void loadPatentCell(Patent patent, List<PatentExportVO> patentExportVOS, List<PatentConfigVO> patentConfigVOS, List<EsPatentFieldsVO> esPatentFieldsVOs, HSSFSheet sheet, HSSFCellStyle commonCellStyle, Integer index) {
+
+        HSSFRow row = sheet.createRow(index + 1);
+        row.setHeight((short) 800);
+        for (int j = 0; j < patentExportVOS.size(); j++) {
+            String column = patentExportVOS.get(j).getValue();
+            String name = patentExportVOS.get(j).getName();
+            String type = patentExportVOS.get(j).getType();
+
+            List<String> types = Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
+
+            if (types.contains(type)) {
+                EsPatentFieldsVO esPatentFieldsVO = esPatentFieldsVOs.stream()
+                        .filter(item -> item.getPatentNo().equals(patent.getPatentNo()))
+                        .findFirst()
+                        .orElse(null);
+                if (esPatentFieldsVO != null) {
+                    List<InnerPatentFieldsVO> innerClassFields = esPatentFieldsVO.getInnerClassFields();
+                    if (!innerClassFields.isEmpty()) {
+                        InnerPatentFieldsVO innerPatentFieldsVO = innerClassFields.stream()
+                                .filter(item -> item.getField().equals(column) && item.getFieldType().equals(Integer.parseInt(type)))
+                                .findFirst()
+                                .orElse(null);
+                        if (innerPatentFieldsVO != null) {
+                            List<FieldValueVO> fieldValueVOS = innerPatentFieldsVO.getFieldValueVOS();
+                            if (!fieldValueVOS.isEmpty()) {
+                                StringBuffer sb = new StringBuffer();
+                                for (FieldValueVO fieldValueVO : fieldValueVOS) {
+                                    String valueStr = fieldValueVO.getValue();
+                                    sb.append(valueStr);
+                                }
+                                HSSFCell cell = row.createCell(index);
+                                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                                commonCellStyle.setWrapText(true);
+                                cell.setCellStyle(commonCellStyle);
+                                cell.setCellValue(sb.toString());
+
+
+                            }
+                        }
+                    }
+                }
+            } else {
+                // 使用反射获取属性值
+                Object value = GenerateObjectUtil.getPropertyValue(patent, column);
+                if (value != null) {
+                    PatentConfigVO patentConfigVO = patentConfigVOS.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(null);
+                    String exportClass = patentConfigVO.getExportClass();
+                    GetValueImp getValueImp = patentExportFactory.getClass(exportClass);
+                    if (getValueImp != null) {
+                        String reValue = getValueImp.getValue(value);
+                        HSSFCell cell = row.createCell(index);
+                        cell.setCellStyle(commonCellStyle);
+                        cell.setCellValue(reValue);
+                    }
+                }
+            }
+        }
+    }
 }

+ 25 - 26
src/main/java/cn/cslg/pas/service/business/es/EsScratchWordsService.java

@@ -63,6 +63,7 @@ public class EsScratchWordsService {
     private FormatQueryService formatQueryService;
     @Autowired
     private AssoProjectPersonService assoProjectPersonService;
+
     //添加划词标注
     public String addScratchWords(ScratchWords scratchWords) {
         String patentNo = scratchWords.getPatentNo();
@@ -134,7 +135,7 @@ public class EsScratchWordsService {
     }
 
     public Query getSearchQuerys(StringRequest stringRequest) {
-      PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
+        PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
         String createId = personnelVO.getId();
         Integer tenantId = personnelVO.getTenantId();
         String searchCondition = stringRequest.getSearchQuery();
@@ -159,27 +160,26 @@ public class EsScratchWordsService {
             //数据库id
             Query q7 = null;
             List<Integer> projectIds = assoProjectPersonService.getRootProjectIds();
-             if(projectIds.size()==0){
-                 projectIds.add(-1);
-             }
-            if (projectId != null) {
-           if(!projectIds.contains(-1)||!projectIds.contains(projectId))
-           {
-               throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR,"无权限查看该专题库标注");
-           }
-               q7 = QueryBuilders.term(t -> t.field("public_project_id").value(projectId));
-            }
-            else {
-                List<FieldValue> fieldValues = new ArrayList<>();
-
-                projectIds.forEach(item -> {
-                    fieldValues.add(FieldValue.of(item));
-                });
-                q7 = QueryBuilders.terms(t -> t.field("public_project_id").terms(new TermsQueryField.Builder().value(fieldValues).build()));
+            if (projectIds != null) {
+                if (projectIds.size() == 0) {
+                    projectIds.add(-1);
+                }
+                if (projectId != null) {
+                    if (!projectIds.contains(-1) || !projectIds.contains(projectId)) {
+                        throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "无权限查看该专题库标注");
+                    }
+                    q7 = QueryBuilders.term(t -> t.field("public_project_id").value(projectId));
+                } else {
+                    List<FieldValue> fieldValues = new ArrayList<>();
+
+                    projectIds.forEach(item -> {
+                        fieldValues.add(FieldValue.of(item));
+                    });
+                    q7 = QueryBuilders.terms(t -> t.field("public_project_id").terms(new TermsQueryField.Builder().value(fieldValues).build()));
 
+                }
             }
 
-
             //公开并且全部范围
             Query bool1 = QueryBuilders.bool(i -> i.must(q1, q5, q4));
 
@@ -187,7 +187,7 @@ public class EsScratchWordsService {
             List<Query> bool2Querys = new ArrayList<>();
             bool2Querys.add(q1);
             bool2Querys.add(q6);
-            if (projectId != null) {
+            if (q7 != null) {
                 bool2Querys.add(q7);
             }
             bool2Querys.add(q4);
@@ -199,7 +199,7 @@ public class EsScratchWordsService {
             List<Query> bool3Querys = new ArrayList<>();
             bool3Querys.add(q2);
             bool3Querys.add(q6);
-            if (projectId != null) {
+            if (q7 != null) {
                 bool3Querys.add(q7);
             }
             bool3Querys.add(q3);
@@ -281,12 +281,12 @@ public class EsScratchWordsService {
         Aggregation aggregation = null;
         if (esGroupFiled.equals("mark_time")) {
             aggregation = new Aggregation.Builder().dateHistogram(new DateHistogramAggregation.Builder().field(esGroupFiled)
-                            .calendarInterval(CalendarInterval.Day).format("yyyy-MM-dd").build())
+                    .calendarInterval(CalendarInterval.Day).format("yyyy-MM-dd").build())
                     .aggregations(new HashMap() {{
                         put("pageAgg", hits);
                     }}).build();
         } else {
-           aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
+            aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
                     .field(esGroupFiled).build()).aggregations(new HashMap() {{
                 put("pageAgg", hits);
             }}).build();
@@ -326,8 +326,7 @@ public class EsScratchWordsService {
                     map.put("count", count);
                     maps.add(map);
                 }
-            }
-            else {
+            } else {
                 List<StringTermsBucket> list = agg.sterms().buckets().array();
                 for (StringTermsBucket bucket : list) {
                     String key = bucket.key().stringValue();
@@ -367,7 +366,7 @@ public class EsScratchWordsService {
             treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
             //格式化检索式
             //3. 从es中检索数据
-            q = formatQueryService.EsQueryToQuery((operateNode) tree, "marking",null);
+            q = formatQueryService.EsQueryToQuery((operateNode) tree, "marking", null);
 
         }
         return q;

+ 1 - 1
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -1493,7 +1493,7 @@ public class EsService {
         String productFrom = queryRequest.getFrom();
         if(projectId!=null) {
             List<Integer> ids = assoProjectPersonService.getRootProjectIds();
-            if (ids.size() == 0||!ids.contains(projectId)) {
+            if (ids!=null&&(ids.size() == 0||!ids.contains(projectId))) {
                 throw new XiaoShiException(ExceptionEnum.PERMISSION_ERROR,"无法查询此专题库专利");
             }
         }

+ 6 - 7
src/main/java/cn/cslg/pas/service/importPatent/SchedulingTaskService.java

@@ -1,6 +1,7 @@
 package cn.cslg.pas.service.importPatent;
 
 import cn.cslg.pas.common.core.base.Constants;
+import cn.cslg.pas.common.dto.ExportTaskDTO;
 import cn.cslg.pas.common.dto.es.EsCustomFieldDTO;
 import cn.cslg.pas.common.vo.ImportTaskAMVO;
 import cn.cslg.pas.common.vo.ProgressVO;
@@ -8,10 +9,7 @@ import cn.cslg.pas.domain.business.ImportTask;
 import cn.cslg.pas.domain.business.ImportTaskCondition;
 import cn.cslg.pas.domain.business.PatentProject;
 import cn.cslg.pas.domain.business.ReportProject;
-import cn.cslg.pas.service.business.ImportTaskConditionService;
-import cn.cslg.pas.service.business.ImportTaskService;
-import cn.cslg.pas.service.business.PatentProjectService;
-import cn.cslg.pas.service.business.ReportProjectService;
+import cn.cslg.pas.service.business.*;
 import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.springframework.beans.BeanUtils;
@@ -47,6 +45,8 @@ public class SchedulingTaskService {
     @Autowired
     private PatentProjectService patentProjectService;
 
+    @Autowired
+    private PatentExportService patentExportService;
     public void startTask() {
         Integer freeCount = Constants.MAX_IMPORT_TASK_COUNT - threadPoolTaskExecutor.getActiveCount();
         if (importTaskAMVOS == null) {
@@ -183,7 +183,6 @@ public class SchedulingTaskService {
 
     }
 
-    public void startPdfTask() {
-
-    }
+   public void StartExportTask(ExportTaskDTO exportTask){
+   }
 }

+ 0 - 7
src/test/java/cn/cslg/pas/service/EsServiceTests.java

@@ -112,13 +112,6 @@ public class EsServiceTests {
 
     @Test
     public void addNet() throws Exception {
-        Patent patent =new Patent();
-        patent.setPatentNo("CN201680059185.0");
-        patent.setPublicNo("CN108135256A");
-        patent.setAppNo("CN201680059185.0");
-        patent.setGrantNo("CN108135256B");
-        esLegalEventService.addEsLegalEvent(patent,"202410929065");
-
     }
 
 }