123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- package cn.cslg.pas.service.importPatent;
- import cn.cslg.pas.common.core.base.FamilyType;
- import cn.cslg.pas.common.dto.UploadPatentWebDTO;
- import cn.cslg.pas.common.dto.business.EsPatentFamilyDTO;
- import cn.cslg.pas.common.dto.es.EsCustomFieldDTO;
- import cn.cslg.pas.common.model.cronModel.SystemFile;
- import cn.cslg.pas.common.model.importTaskModel.PatentAffair;
- import cn.cslg.pas.common.model.importTaskModel.PatentInventor;
- import cn.cslg.pas.common.utils.ReadExcelUtils;
- import cn.cslg.pas.common.utils.esDataForm.PatentClassifySplitter;
- import cn.cslg.pas.common.vo.ImportTaskAMVO;
- import cn.cslg.pas.common.vo.PatentData;
- import cn.cslg.pas.common.vo.UploadParamsVO;
- import cn.cslg.pas.common.vo.UploadSettingVO;
- import cn.cslg.pas.domain.es.*;
- import cn.cslg.pas.service.business.CustomFieldService;
- import cn.cslg.pas.service.business.es.EsService;
- import cn.cslg.pas.service.common.ExcuteDataToVOService;
- import cn.cslg.pas.service.common.ExcuteUploadSettingService;
- import cn.cslg.pas.service.common.FileManagerService;
- import com.alibaba.fastjson.JSONArray;
- import org.apache.commons.compress.utils.IOUtils;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.springframework.beans.factory.annotation.Configurable;
- import org.springframework.context.ApplicationContext;
- import java.io.*;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- @Configurable
- public class GetPatentFromExcelThread extends Thread {
- private ImportTaskAMVO importTaskAMVO;
- private ApplicationContext applicationContext;
- private SavePatentToEsThread savePatentToEsThread;
- private GetPatentPictureFromExcelThread getPatentPictureFromExcelThread;
- @Override
- public void run() {
- try {
- FileManagerService fileManagerService = applicationContext.getBean(FileManagerService.class);
- String res = fileManagerService.getSystemFileFromFMS(Arrays.asList(importTaskAMVO.getFileGuid()));
- List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
- SystemFile systemFile = systemFiles.get(0);
- String suffix = systemFile.getFileName().substring(systemFile.getFileName().lastIndexOf("."));
- //调用文件系统取出文件接口,获得文件流
- byte[] bytes = fileManagerService.downloadSystemFileFromFMS(importTaskAMVO.getFileGuid());
- //创建临时文件tempFile,并将文件读取到tempFile
- File tempFile = File.createTempFile(systemFile.getFileName() + "temp", suffix);
- try (
- InputStream inputStream = new ByteArrayInputStream(bytes);
- FileOutputStream outputStream = new FileOutputStream(tempFile)
- ) {
- IOUtils.copy(inputStream, outputStream); // 将输入流复制到临时文件
- }
- Integer total = importTaskAMVO.getAllNum();
- Integer lastIndex = importTaskAMVO.getDoneNum();
- Integer sourceId = importTaskAMVO.getSourceId();
- //解析数据源类,通过数据来源id(如1:智慧芽)解析数据源配置文件,获得数据源配置文件对象jsonData
- ExcuteDataToVOService excuteDataToVOService = applicationContext.getBean(ExcuteDataToVOService.class);
- ExcuteUploadSettingService excuteUploadSettingService = applicationContext.getBean(ExcuteUploadSettingService.class);
- List<UploadSettingVO.Column> jsonData = excuteUploadSettingService.ExcuteUploadSetting(sourceId.toString());
- //解析Excel文件获得工作簿
- Sheet sheet = ReadExcelUtils.readExcel(tempFile);
- Integer x = 0;
- //遍历专利总数量,在循环中将专利一个一个存入消费者专利队列
- for (int i = lastIndex; i < total; i++) {
- if (!importTaskAMVO.getState().equals(1)) {
- System.out.println(importTaskAMVO.getId());
- break;
- }
- PatentData patentData = ReadExcelUtils.readExcelOneRow(tempFile, sheet, i + 1);
- //调用装载数据类(根据数据源配置文件对象和专利源数据生成专利数据)
- UploadParamsVO uploadParamsVO = excuteDataToVOService.fileToPatentVO(patentData, jsonData);
- this.loadPatent(uploadParamsVO);
- UploadPatentWebDTO uploadPatentWebDTO = new UploadPatentWebDTO();
- uploadPatentWebDTO.setHaveSaveCounter(0);
- uploadPatentWebDTO.setTotalCounter(importTaskAMVO.getThreadCounter());
- uploadPatentWebDTO.setPictureData(uploadParamsVO.getPictureData());
- uploadPatentWebDTO.setPatent(uploadParamsVO.getPatent());
- if (uploadParamsVO.getCustomerFieldList() != null && uploadParamsVO.getCustomerFieldList().size() != 0) {
- CustomFieldService customFieldService = applicationContext.getBean(CustomFieldService.class);
- List<EsCustomFieldDTO> esCustomFieldDTOList = customFieldService.getFieldDTOByStrings(uploadParamsVO.getCustomerFieldList(), importTaskAMVO.getProjectId());
- uploadPatentWebDTO.setEsCustomFieldDTOList(esCustomFieldDTOList);
- }
- //专利丢入消费者队列,并唤醒消费者线程
- savePatentToEsThread.awakeTask(uploadPatentWebDTO);
- x++;
- getPatentPictureFromExcelThread.awakeTask(uploadPatentWebDTO);
- }
- //专利取完通知消费者线程
- savePatentToEsThread.setIfProductAll(true);
- System.out.println("从excel获取专利:" + x);
- getPatentPictureFromExcelThread.setIfProductAll(true);
- //删除临时文件tempFile
- new File(tempFile.getPath()).delete();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public GetPatentFromExcelThread(TaskThread taskThread, SavePatentToEsThread savePatentToEsThread, GetPatentPictureFromExcelThread getPatentPictureFromExcelThread) {
- this.importTaskAMVO = taskThread.getImportTaskAMVO();
- this.savePatentToEsThread = savePatentToEsThread;
- this.applicationContext = taskThread.getApplicationContext();
- this.getPatentPictureFromExcelThread = getPatentPictureFromExcelThread;
- }
- public void loadPatent(UploadParamsVO uploadParamsVO) {
- Patent patent = uploadParamsVO.getPatent();
- String patentNo = patent.getPatentNo();
- String appNo = patent.getAppNo();
- String publicNo = patent.getPublicNo();
- String grantNo = patent.getGrantNo();
- String usedNo = null;
- if (appNo != null) {
- usedNo = appNo;
- } else if (publicNo != null) {
- usedNo = publicNo;
- } else if (grantNo != null) {
- usedNo = grantNo;
- }
- String contry = usedNo.substring(0, 2);
- if (contry.equals("CN")) {
- patentNo = appNo;
- } else {
- if (publicNo != null) {
- patentNo = publicNo;
- } else if (grantNo != null) {
- patentNo = grantNo;
- }
- }
- patent.setPatentNo(patentNo);
- //装载国家
- patent.setAppCountry(contry);
- //装载标题
- if (uploadParamsVO.getTitle() != null) {
- List<Text> texts = new ArrayList<>();
- if (uploadParamsVO.getTitle().getName() != null) {
- Text text = new Text();
- text.setTextContent(uploadParamsVO.getTitle().getName());
- text.setIfOrigin(true);
- text.setLanguage(contry);
- texts.add(text);
- }
- if (uploadParamsVO.getTitle().getNameOut() != null) {
- Text text = new Text();
- text.setTextContent(uploadParamsVO.getTitle().getNameOut());
- text.setIfOrigin(false);
- text.setLanguage("CN");
- texts.add(text);
- }
- if (texts.size() != 0) {
- patent.setTitle(texts);
- }
- }
- //装载摘要
- if (uploadParamsVO.getAbstractStr() != null) {
- List<Text> texts = new ArrayList<>();
- if (uploadParamsVO.getAbstractStr().getName() != null) {
- Text text = new Text();
- text.setTextContent(uploadParamsVO.getAbstractStr().getName());
- text.setIfOrigin(true);
- text.setLanguage(contry);
- texts.add(text);
- }
- if (uploadParamsVO.getAbstractStr().getNameOut() != null) {
- Text text = new Text();
- text.setTextContent(uploadParamsVO.getAbstractStr().getNameOut());
- text.setIfOrigin(false);
- text.setLanguage("CN");
- texts.add(text);
- }
- if (texts.size() != 0) {
- patent.setAbstractStr(texts);
- }
- }
- //装载权利要求
- if (uploadParamsVO.getPatentRight() != null) {
- List<Text> texts = new ArrayList<>();
- if (uploadParamsVO.getPatentRight().getName() != null) {
- Text text = new Text();
- text.setTextContent(uploadParamsVO.getPatentRight().getName());
- text.setIfOrigin(true);
- text.setLanguage(contry);
- texts.add(text);
- }
- if (uploadParamsVO.getPatentRight().getNameOut() != null) {
- Text text = new Text();
- text.setTextContent(uploadParamsVO.getPatentRight().getNameOut());
- text.setIfOrigin(false);
- text.setLanguage("CN");
- texts.add(text);
- }
- if (texts.size() != 0) {
- patent.setClaim(texts);
- }
- }
- //简单同族
- if (uploadParamsVO.getSimpleFamily() != null) {
- EsService esService = applicationContext.getBean(EsService.class);
- try {
- EsPatentFamilyDTO esPatentFamilyDTO = esService.addEsPatentFamily(patent, uploadParamsVO.getSimpleFamily(), FamilyType.SIMPLE);
- if (esPatentFamilyDTO != null) {
- patent.setSimpleFamilyId(esPatentFamilyDTO.getPatentFamilyId());
- patent.setSimpleFamilyNum(esPatentFamilyDTO.getFamilyNum());
- }
- } catch (Exception e) {
- }
- }
- //inpadapc同族
- if (uploadParamsVO.getInpadocFamily() != null) {
- EsService esService = applicationContext.getBean(EsService.class);
- try {
- EsPatentFamilyDTO esPatentFamilyDTO = esService.addEsPatentFamily(patent, uploadParamsVO.getSimpleFamily(), FamilyType.INPADOC);
- if (esPatentFamilyDTO != null) {
- patent.setInpadocFamilyId(esPatentFamilyDTO.getPatentFamilyId());
- patent.setInpadocFamilyNum(esPatentFamilyDTO.getFamilyNum());
- }
- } catch (Exception e) {
- }
- }
- //patsnap同族
- if (uploadParamsVO.getPatSnapFamily() != null) {
- EsService esService = applicationContext.getBean(EsService.class);
- try {
- EsPatentFamilyDTO esPatentFamilyDTO = esService.addEsPatentFamily(patent, uploadParamsVO.getSimpleFamily(), FamilyType.PATSNAP);
- if (esPatentFamilyDTO != null) {
- patent.setPatsnapFamilyId(esPatentFamilyDTO.getPatentFamilyId());
- patent.setPatsnapFamilyNum(esPatentFamilyDTO.getFamilyNum());
- }
- } catch (Exception e) {
- }
- }
- List<String> applicantNames = uploadParamsVO.getPatentApplicantOriginalName();
- //申请人
- if (applicantNames != null && applicantNames.size() != 0) {
- List<PatentPerson> patentPeople = new ArrayList<>();
- for (int i = 0; i < applicantNames.size(); i++) {
- PatentPerson patentPerson = new PatentPerson();
- patentPerson.setOrder(i + 1);
- patentPerson.setType("1");
- patentPerson.setName(applicantNames.get(i));
- patentPeople.add(patentPerson);
- }
- patent.setApplicant(patentPeople);
- }
- //权利人
- List<String> rightNames = uploadParamsVO.getPatentApplicantCurrentName();
- if (rightNames != null && rightNames.size() != 0) {
- List<PatentPerson> patentPeople = new ArrayList<>();
- for (int i = 0; i < rightNames.size(); i++) {
- PatentPerson patentPerson = new PatentPerson();
- patentPerson.setOrder(i + 1);
- patentPerson.setType("1");
- patentPerson.setName(rightNames.get(i));
- patentPeople.add(patentPerson);
- }
- patent.setRightHolder(patentPeople);
- }
- //发明人
- List<PatentInventor> patentInventorList = uploadParamsVO.getPatentInventorList();
- if (patentInventorList != null && patentInventorList.size() > 0) {
- List<PatentPerson> patentPeople = new ArrayList<>();
- for (int i = 0; i < patentInventorList.size(); i++) {
- PatentPerson patentPerson = new PatentPerson();
- patentPerson.setOrder(i + 1);
- patentPerson.setType("1");
- patentPerson.setName(patentInventorList.get(i).getName());
- patentPeople.add(patentPerson);
- }
- patent.setInventor(patentPeople);
- }
- List<String> ipcList = uploadParamsVO.getIpcList();
- String mainIpc = uploadParamsVO.getMainIpc();
- //装载IPC分类号
- if (ipcList == null && mainIpc != null) {
- ipcList = new ArrayList<>();
- ipcList.add(uploadParamsVO.getMainIpc());
- }
- if (ipcList != null && ipcList.size() > 0) {
- List<PatentClassify> patentClassifies = new ArrayList<>();
- for (int i = 0; i < ipcList.size(); i++) {
- PatentClassify patentClassify = PatentClassifySplitter.split(ipcList.get(i));
- if (patentClassify != null) {
- patentClassifies.add(patentClassify);
- if (i == 0) {
- patent.setMipc(patentClassify);
- }
- }
- }
- patent.setIpc(patentClassifies);
- }
- //装载CPC分类号
- List<String> cpcList = uploadParamsVO.getCpcList();
- if (cpcList != null && cpcList.size() > 0) {
- List<PatentClassify> patentClassifies = new ArrayList<>();
- for (int i = 0; i < cpcList.size(); i++) {
- PatentClassify patentClassify = PatentClassifySplitter.split(cpcList.get(i));
- patentClassifies.add(patentClassify);
- }
- patent.setCpc(patentClassifies);
- }
- //装载说明书
- if (uploadParamsVO.getPatentInstructionText() != null) {
- List<Text> texts = new ArrayList<>();
- if (uploadParamsVO.getPatentInstructionText().getManual() != null) {
- Text text = new Text();
- text.setTextContent(uploadParamsVO.getPatentInstructionText().getManual());
- text.setIfOrigin(true);
- text.setLanguage(contry);
- texts.add(text);
- }
- if (uploadParamsVO.getPatentInstructionText().getManualOut() != null) {
- Text text = new Text();
- text.setTextContent(uploadParamsVO.getPatentInstructionText().getManualOut());
- text.setIfOrigin(false);
- text.setLanguage("CN");
- texts.add(text);
- }
- if (texts.size() != 0) {
- patent.setPublicFullText(texts);
- }
- }
- //装载优先权
- if (uploadParamsVO.getPriorityNo() != null && uploadParamsVO.getPriorityNo().size() > 0) {
- List<String> prDates = uploadParamsVO.getPriorityDate();
- List<Priorities> priorities = new ArrayList<>();
- for (int i = 0; i < uploadParamsVO.getPriorityNo().size(); i++) {
- String prNo = uploadParamsVO.getPriorityNo().get(i);
- Priorities prioritie = new Priorities();
- prioritie.setPriorityNo(prNo);
- String pCountry = prNo.substring(0, 2);
- prioritie.setPriorityCountry(pCountry);
- if (prDates != null && prDates.size() > i) {
- prioritie.setPriorityDate(prDates.get(i));
- }
- priorities.add(prioritie);
- }
- patent.setPriorities(priorities);
- }
- this.loadLegalStatus(patent);
- this.loadPatentType(patent);
- this.loadLegalStatusBySta(uploadParamsVO);
- }
- /**
- * 装载法律状态
- */
- private void loadLegalStatus(Patent patent) {
- if (patent != null && patent.getSimpleStatus() != null) {
- String status = patent.getSimpleStatus().trim();
- if (status != null) {
- switch (status) {
- case "有效":
- patent.setSimpleStatus("3");
- break;
- case "审中":
- patent.setSimpleStatus("1");
- case "失效":
- patent.setSimpleStatus("2");
- }
- }
- }
- }
- private void loadLegalStatusBySta(UploadParamsVO uploadParamsVO) {
- Patent patent =uploadParamsVO.getPatent();
- if (uploadParamsVO != null && uploadParamsVO.getPatentAffair() != null && uploadParamsVO.getPatentAffair().getStatus()!=null&&patent.getSimpleStatus()==null) {
- String status = uploadParamsVO.getPatentAffair().getStatus().split("\\|")[0];
- if (status != null) {
- switch (status) {
- case "公开":
- case "授权":
- patent.setSimpleStatus("3");
- break;
- case "实质审查":
- patent.setSimpleStatus("1");
- break;
- default:
- patent.setSimpleStatus("3");
- }
- }
- }
- }
- private void loadPatentType(Patent patent) {
- String type = patent.getPatentType();
- if (type != null) {
- type = type.trim();
- switch (type) {
- case "授权发明":
- case "发明申请":
- type = "1";
- break;
- case "实用新型":
- type = "2";
- break;
- case "外观设计":
- type = "3";
- break;
- default:
- type = null;
- break;
- }
- patent.setPatentType(type);
- }
- }
- }
|