|
@@ -0,0 +1,147 @@
|
|
|
|
+package cn.cslg.pas.service.common;
|
|
|
|
+
|
|
|
|
+import cn.cslg.pas.common.core.base.RedisConf;
|
|
|
|
+import cn.cslg.pas.common.model.pythonModel.GetPatentSimilarScoreDTO;
|
|
|
|
+import cn.cslg.pas.common.model.pythonModel.GetPatentSimilarScoreVO;
|
|
|
|
+import cn.cslg.pas.common.model.pythonModel.PatentScoreDTO;
|
|
|
|
+import cn.cslg.pas.common.model.pythonModel.PatentScoreVO;
|
|
|
|
+import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
|
+import cn.cslg.pas.common.utils.MD5Util;
|
|
|
|
+import cn.cslg.pas.common.utils.RedisUtil;
|
|
|
|
+import cn.cslg.pas.common.utils.StringUtils;
|
|
|
|
+import cn.cslg.pas.common.vo.StarPatentVO;
|
|
|
|
+import cn.cslg.pas.domain.business.TechnicalCase;
|
|
|
|
+import cn.cslg.pas.exception.ExceptionEnum;
|
|
|
|
+import cn.cslg.pas.exception.XiaoShiException;
|
|
|
|
+import cn.cslg.pas.service.business.TechnicalCaseService;
|
|
|
|
+import cn.cslg.pas.service.importPatent.WebVOTransformService;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
+import okhttp3.MediaType;
|
|
|
|
+import okhttp3.OkHttpClient;
|
|
|
|
+import okhttp3.Request;
|
|
|
|
+import okhttp3.RequestBody;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class PythonApiService {
|
|
|
|
+ @Value("${PythonUrl}")
|
|
|
|
+ private String PythonUrl;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
+ @Autowired
|
|
|
|
+ private PatentStarApiService patentStarApiService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private WebVOTransformService webVOTransformService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TechnicalCaseService technicalCaseService;
|
|
|
|
+
|
|
|
|
+ public GetPatentSimilarScoreVO getPatentSimilarScore(GetPatentSimilarScoreDTO getPatentSimilarScoreDTO) {
|
|
|
|
+ GetPatentSimilarScoreVO getPatentSimilarScoreVo = new GetPatentSimilarScoreVO();
|
|
|
|
+ try {
|
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
|
+ String param = new Gson().toJson(getPatentSimilarScoreDTO);
|
|
|
|
+ RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), param);
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
+ .url(PythonUrl + "/getPatentSimilarScore")
|
|
|
|
+ .post(requestBody)
|
|
|
|
+ .build();
|
|
|
|
+ String reStr = Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
|
+ getPatentSimilarScoreVo = JSONObject.parseObject(reStr, GetPatentSimilarScoreVO.class);
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "获取专利相似度失败");
|
|
|
|
+ }
|
|
|
|
+ return getPatentSimilarScoreVo;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public GetPatentSimilarScoreVO getPatentSimilarMess(GetPatentSimilarScoreDTO getPatentSimilarScoreDTO) {
|
|
|
|
+ GetPatentSimilarScoreVO getPatentSimilarScoreVO = new GetPatentSimilarScoreVO();
|
|
|
|
+ Integer projectId = getPatentSimilarScoreDTO.getProjectId();
|
|
|
|
+ TechnicalCase technicalCase = technicalCaseService.getByProjectId(projectId);
|
|
|
|
+ String text = technicalCase.getInventionPoint();
|
|
|
|
+ if (text == null || text.trim().equals("")) {
|
|
|
|
+ return getPatentSimilarScoreVO;
|
|
|
|
+ }
|
|
|
|
+ List<PatentScoreVO> donePatentScoreVo = new ArrayList<>();
|
|
|
|
+ List<PatentScoreDTO> waitTOGetDTOs = new ArrayList<>();
|
|
|
|
+ String code = MD5Util.toMD5(text);
|
|
|
|
+ List<PatentScoreDTO> patentScoreDTOList = getPatentSimilarScoreDTO.getPatentScoreDTOList();
|
|
|
|
+ patentScoreDTOList.forEach(item -> {
|
|
|
|
+
|
|
|
|
+ String json = redisUtil.get(RedisConf.GET_PATENT_SIMILAR_SCORE + ":" + item.getPatentNo()+":"+code);
|
|
|
|
+
|
|
|
|
+ if (!StringUtils.isEmpty(json)) {
|
|
|
|
+ PatentScoreVO patentScoreVO = JSONObject.parseObject(json, PatentScoreVO.class);
|
|
|
|
+ donePatentScoreVo.add(patentScoreVO);
|
|
|
|
+ } else {
|
|
|
|
+ waitTOGetDTOs.add(item);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ List<PatentScoreVO> patentScoreVOS = this.getPatentScore(waitTOGetDTOs, text);
|
|
|
|
+ donePatentScoreVo.addAll(patentScoreVOS);
|
|
|
|
+
|
|
|
|
+ getPatentSimilarScoreVO.setText(text);
|
|
|
|
+ getPatentSimilarScoreVO.setPatentScoreDTOList(donePatentScoreVo);
|
|
|
|
+ return getPatentSimilarScoreVO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public List<PatentScoreVO> getPatentScore(List<PatentScoreDTO> waitTOGetDTOs, String text) {
|
|
|
|
+ String code = MD5Util.toMD5(text);
|
|
|
|
+ List<PatentScoreVO> patentScoreVOS = new ArrayList<>();
|
|
|
|
+ if (waitTOGetDTOs.size() > 0) {
|
|
|
|
+ this.formatPatentScoreVO(waitTOGetDTOs);
|
|
|
|
+ GetPatentSimilarScoreDTO getSearchScoreDTO = new GetPatentSimilarScoreDTO();
|
|
|
|
+ getSearchScoreDTO.setText(text);
|
|
|
|
+ getSearchScoreDTO.setPatentScoreDTOList(waitTOGetDTOs);
|
|
|
|
+ GetPatentSimilarScoreVO getPatentSimilarScoreVO = this.getPatentSimilarScore(getSearchScoreDTO);
|
|
|
|
+ patentScoreVOS = getPatentSimilarScoreVO.getPatentScoreDTOList();
|
|
|
|
+ patentScoreVOS.forEach(item -> {
|
|
|
|
+ String jsons = JSONObject.toJSONString(item);
|
|
|
|
+ redisUtil.setEx(RedisConf.GET_PATENT_SIMILAR_SCORE + ":" + item.getPatentNo()+":"+code, jsons, 1l, TimeUnit.DAYS);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return patentScoreVOS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<PatentScoreDTO> formatPatentScoreVO(List<PatentScoreDTO> waitTOGetDTOs) {
|
|
|
|
+ waitTOGetDTOs.forEach(item -> {
|
|
|
|
+ String rowAppNo = item.getRowApplicationNo();
|
|
|
|
+ String patentNo = item.getPatentNo();
|
|
|
|
+ String publicNo =item.getPublicNo();
|
|
|
|
+ if (patentNo.startsWith("CN")) {
|
|
|
|
+ String patentZhuLuStr = patentStarApiService.getCnBibApi(rowAppNo);
|
|
|
|
+ if (patentZhuLuStr != null && !patentZhuLuStr.trim().equals("") && !patentZhuLuStr.equals("{}") && !patentZhuLuStr.contains("请求不合法")) {
|
|
|
|
+ List<StarPatentVO> chinaPatentZhuLus = JSON.parseArray(patentZhuLuStr, StarPatentVO.class);
|
|
|
|
+ StarPatentVO chinaPatentZhuLu = chinaPatentZhuLus.get(0);
|
|
|
|
+ item.setAbstractStr(chinaPatentZhuLu.getAB());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ String patentZhuLuStr = patentStarApiService.getENBibApi(publicNo);
|
|
|
|
+ if (patentZhuLuStr != null && !patentZhuLuStr.trim().equals("") && !patentZhuLuStr.equals("{}") && !patentZhuLuStr.contains("请求不合法")) {
|
|
|
|
+ List<StarPatentVO> worldPatentZhuLus = JSON.parseArray(patentZhuLuStr, StarPatentVO.class);
|
|
|
|
+ StarPatentVO worldPatentZhuLu = worldPatentZhuLus.get(0);
|
|
|
|
+ item.setAbstractStr(worldPatentZhuLu.getAB());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return waitTOGetDTOs;
|
|
|
|
+ }
|
|
|
|
+}
|