package com.example.xiaoshiweixinback.controller; import com.alibaba.fastjson2.JSONObject; import com.example.xiaoshiweixinback.business.common.Constants; import com.example.xiaoshiweixinback.business.common.Response; import com.example.xiaoshiweixinback.business.common.base.Records; import com.example.xiaoshiweixinback.business.exception.BusinessException; import com.example.xiaoshiweixinback.business.utils.FileUtils; import com.example.xiaoshiweixinback.checkLogin.checkLogin; import com.example.xiaoshiweixinback.entity.dataRecord.DataRangeRecord; import com.example.xiaoshiweixinback.entity.dto.GetPatentByRecordDTO; import com.example.xiaoshiweixinback.entity.dto.PatentNoDTO; import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPictureNoDTO; import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPatentVectorDTO; import com.example.xiaoshiweixinback.entity.dto.patent.*; import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPictureNoVo; import com.example.xiaoshiweixinback.service.MonitorRecordService; import com.example.xiaoshiweixinback.service.PatentService; import com.example.xiaoshiweixinback.service.exportPatent.PatentExportService; import com.example.xiaoshiweixinback.service.importPatent.EsDenseVectorService; import com.example.xiaoshiweixinback.service.importPatent.EsPatentService; import com.example.xiaoshiweixinback.service.importPatent.GetPatentFromExcelService; import com.example.xiaoshiweixinback.service.importPatent.ImportFromWebToEsService; import com.example.xiaoshiweixinback.useFunctionRecordAop.useFunctionRecord; import io.swagger.v3.oas.annotations.Operation; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.InputStreamResource; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.List; @RequestMapping(Constants.XIAOSHI_WEIXINBACK + "/patent") @RestController public class PatentController { @Autowired private ImportFromWebToEsService importFromWebToEsService; @Autowired private EsDenseVectorService esDenseVectorService; @Autowired private GetPatentFromExcelService getPatentFromExcelService; @Autowired private EsPatentService esPatentService; @Autowired private PatentExportService patentExportService; @Autowired private PatentService patentService; @Autowired private MonitorRecordService monitorRecordService; //--------------------------- 导入 -------------------------- @Operation(summary = "导入专利") @PostMapping(value = "/importPatent") public Response queryPatent(@RequestBody ImportTaskAMVO importTaskAMVO) { try { importFromWebToEsService.ImportTask(importTaskAMVO); } catch (Exception e) { e.printStackTrace(); } return Response.success(""); } @Operation(summary = "excel导入") @GetMapping(value = "/importPatentE") public Response importPatentE(String path) { try { getPatentFromExcelService.run(path); } catch (Exception e) { e.printStackTrace(); } return Response.success(""); } //--------------------------- 关于图片的专利检索 -------------------------- @Operation(summary = "根据关键词获取列表(图片用于排序)--zero") @PostMapping(value = "/getPatentVectors") @useFunctionRecord public Response getPatentVectors(@RequestParam(value = "vectorDTO", required = false) String vectorDTO, @RequestParam(value = "multipartFile", required = false) MultipartFile multipartFile) throws Exception { Records records = null; try { File file = FileUtils.multipartFileToFile(multipartFile); EsPatentVectorDTO esPatentVectorDTO = new EsPatentVectorDTO(); if (StringUtils.isNotEmpty(vectorDTO)) { esPatentVectorDTO = JSONObject.parseObject(vectorDTO, EsPatentVectorDTO.class); } records = esDenseVectorService.getPatentVectors(esPatentVectorDTO, file); } catch (Exception e) { if(e instanceof BusinessException) { BusinessException b =(BusinessException) e; return Response.error(b.getErrorCode(), e.getMessage());} return Response.error(e.getMessage()); } return Response.success(records); } @Operation(summary = "根据专利号获取相关图片--zero") @PostMapping(value = "/getPictureByNo") public Response getPictureByNo(@RequestBody EsPictureNoDTO pictureNoDTO) throws Exception { List pictureByNo = esDenseVectorService.getPictureByNo3(pictureNoDTO); return Response.success(pictureByNo); } //--------------------------- 收藏专利相关 -------------------------- @checkLogin @Operation(summary = "收藏专利--zero") @PostMapping(value = "/collectPatent") public Response collectPatent(@RequestBody CollectPatentDTO patentDTO) { boolean b = false; try { b = esPatentService.collectPatent(patentDTO); } catch (IOException e) { return Response.error(e.getMessage()); } return Response.success(b); } @Operation(summary = "查询收藏专利--zero") @PostMapping(value = "/selectCollectPatent") public Response selectCollectPatent(@RequestBody SelectCollectPatentDTO patentDTO) throws Exception { Records records = esPatentService.selectCollectPatent(patentDTO); return Response.success(records); } @Operation(summary = "删除收藏专利--zero") @PostMapping(value = "/delCollectPatent") public Response delCollectPatent(@RequestBody DelCollectPatentDTO patentDTO) throws IOException { boolean b = false; try { b = esPatentService.delCollectPatent(patentDTO); } catch (IOException e) { return Response.error(e.getMessage()); } return Response.success(b); } //--------------------------- 查询专利 -------------------------- @Operation(summary = "查询专利(用于导出专利数据)--zero") @PostMapping(value = "/selectPatent") public Response selectPatent(@RequestParam(value = "searchQuery", required = false) String searchQuery, @RequestParam(value = "multipartFile", required = false) MultipartFile multipartFile) throws Exception { File file = FileUtils.multipartFileToFile(multipartFile); SelectPatentDTO patentDTO = new SelectPatentDTO(); if (StringUtils.isNotEmpty(searchQuery)) { patentDTO = JSONObject.parseObject(searchQuery, SelectPatentDTO.class); } List columnDTOS = esPatentService.selectPatent(patentDTO, file); return Response.success(columnDTOS); } @Operation(summary = "根据专利号查询专利详情") @PostMapping(value = "/selectPatentInfoByPatentNo") public Response selectPatentInfoByPatentNo(@RequestBody PatentNoDTO patentNoDTO) throws IOException { String patentNo = patentNoDTO.getPatentNo(); PatentColumnDTO columnDTO = esPatentService.selectPatentInfoByPatentNo(patentNo); return Response.success(columnDTO); } //--------------------------导出专利------------------------------- @PostMapping(value = "/exportPatent") @Operation(summary = "导出专利数据") public Response exportPatent(@RequestBody ExportPatentDTO exportPatentDTO) throws IOException { String fileGuid = patentExportService.exportPatent(exportPatentDTO.getPatentNos()); Records records = new Records(); records.setData(fileGuid); return Response.success(records); } @GetMapping(value = "/getDataRangeRecord") @Operation(summary = "获取专利数据库数据信息") public Response getDataRangeRecord() throws IOException { List dataRangeRecords = patentService.getDataRangeRecord(); Records records = new Records(); records.setData(dataRangeRecords); return Response.success(records); } @PostMapping(value = "/getPatentByRecord") @Operation(summary = "查询监控记录的专利信息") public Response getPatentByRecord(@RequestBody GetPatentByRecordDTO getPatentByRecordDTO) throws IOException { Records records = monitorRecordService.getPatentByRecord(getPatentByRecordDTO); return Response.success(records); } }