|
@@ -0,0 +1,84 @@
|
|
|
+package com.example.xiaoshiweixinback.service.importPatent;
|
|
|
+
|
|
|
+import com.example.xiaoshiweixinback.business.utils.FileUtils;
|
|
|
+import com.example.xiaoshiweixinback.business.utils.FormatUtil;
|
|
|
+import com.example.xiaoshiweixinback.domain.es.Patent;
|
|
|
+import com.example.xiaoshiweixinback.domain.es.PatentClassify;
|
|
|
+import com.example.xiaoshiweixinback.domain.es.PatentVector;
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.patent.UploadPatentWebDTO;
|
|
|
+import com.example.xiaoshiweixinback.service.common.FileManagerService;
|
|
|
+import com.example.xiaoshiweixinback.service.common.GetVectorService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class GetFiguresService {
|
|
|
+ @Autowired
|
|
|
+ private PatentStarApiService patentStarApiService;
|
|
|
+ @Autowired
|
|
|
+ private FileManagerService fileManagerService;
|
|
|
+ @Autowired
|
|
|
+ private GetVectorService getVectorService;
|
|
|
+ @Autowired
|
|
|
+ private EsService esService;
|
|
|
+
|
|
|
+ public void getFigures(UploadPatentWebDTO uploadPatentWebDTO) {
|
|
|
+ Patent patent = uploadPatentWebDTO.getPatent();
|
|
|
+ try {
|
|
|
+ List<String> urls = patentStarApiService.getExternalFigure(patent.getAppNo().replace(".", ""));
|
|
|
+ if (!urls.get(0).equals("{}")) {
|
|
|
+ for (int i = 0; i < urls.size(); i++) {
|
|
|
+ String url = urls.get(i);
|
|
|
+ this.tem(url, uploadPatentWebDTO, i + 1);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void tem(String pictureUrl, UploadPatentWebDTO uploadPatentWebDTO, Integer i) throws Exception {
|
|
|
+ Patent patent = uploadPatentWebDTO.getPatent();
|
|
|
+ if (pictureUrl != null && !pictureUrl.contains("408")) {
|
|
|
+ File file = FileUtils.getPictureFileByUrl(pictureUrl);
|
|
|
+ String guid = FormatUtil.getPictureFormat(uploadPatentWebDTO.getStarPatentVO().getApplicationNo())+i;
|
|
|
+ fileManagerService.uploadFileWithGuid(file, guid);
|
|
|
+ PatentVector patentVectorOrg = esService.getVectorByIndex(patent.getAppNo(),i);
|
|
|
+ if(patentVectorOrg!=null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ PatentVector patentVector = new PatentVector();
|
|
|
+ patentVector.setAppNo(patent.getAppNo());
|
|
|
+ patentVector.setTitle(patent.getTitle());
|
|
|
+ patentVector.setRightHolder(patent.getRightHolder());
|
|
|
+ patentVector.setAppDate(patent.getAppDate());
|
|
|
+ patentVector.setAbstractStr(patent.getAbstractStr());
|
|
|
+ patentVector.setAppCountry(patent.getAppCountry());
|
|
|
+ PatentClassify patentClassify = new PatentClassify();
|
|
|
+ patentClassify.setLevel1(uploadPatentWebDTO.getStarPatentVO().getMainIpc());
|
|
|
+ patentVector.setLoc(Arrays.asList(patentClassify));
|
|
|
+ patentVector.setImageIndex(i);
|
|
|
+ patentVector.setGuid(guid);
|
|
|
+ List<String> stringList = getVectorService.getVectorByFile(file);
|
|
|
+ List<Float> floats = new ArrayList<>();
|
|
|
+ stringList.forEach(item -> {
|
|
|
+ Float a = Float.parseFloat(item);
|
|
|
+ floats.add(a);
|
|
|
+
|
|
|
+ });
|
|
|
+ org.apache.commons.io.FileUtils.deleteQuietly(file);
|
|
|
+ patentVector.setMyVector(floats);
|
|
|
+ esService.addPatentVector(patentVector);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|