123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- 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;
- }
- }
|