package cn.cslg.pas.service; import cn.cslg.pas.common.core.base.Constants; import cn.cslg.pas.common.core.exception.CustomException; import cn.cslg.pas.common.model.PersonnelVO; import cn.cslg.pas.common.model.dto.TaskWebSocketDTO; import cn.cslg.pas.common.model.dto.UploadFileDTO; import cn.cslg.pas.common.model.vo.*; import cn.cslg.pas.common.utils.SecurityUtils.SecurityUtils; import cn.cslg.pas.domain.*; import cn.cslg.pas.common.utils.*; import cn.cslg.pas.common.model.params.*; import cn.cslg.pas.common.utils.ExcelUtils; import cn.cslg.pas.common.utils.WebSocketServer; import cn.cslg.pas.mapper.ProjectMapper; import cn.dev33.satoken.stp.StpUtil; import cn.cslg.pas.common.utils.PatentUtils; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.IterUtil; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ZipUtil; import cn.hutool.extra.spring.SpringUtil; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelWriter; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.RequiredArgsConstructor; import org.apache.poi.ss.usermodel.PictureData; import org.springframework.beans.BeanUtils; import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.stream.Collectors; /** *

* 专题库表 服务实现类 *

* * @author 王岩 * @since 2022-01-24 */ @Service @RequiredArgsConstructor(onConstructor_ = {@Lazy}) public class ProjectService extends ServiceImpl { private final ClientService clientService; private final ProjectUserService projectUserService; private final PatentService patentService; private final PatentApplicantService patentApplicantService; private final PatentAgencyService patentAgencyService; private final PatentAgentService patentAgentService; private final PatentAgentLinkService patentAgentLinkService; private final PatentLicensorService patentLicensorService; private final PatentPledgeService patentPledgeService; private final PatentAffairService patentAffairService; private final PatentApplicantLinkService patentApplicantLinkService; private final PatentApplicantMergeLinkService patentApplicantMergeLinkService; private final PatentInventorService patentInventorService; private final PatentInventorLinkService patentInventorLinkService; private final PatentSimpleFamilyService patentSimpleFamilyService; private final PatentSimpleFamilyLinkService patentSimpleFamilyLinkService; private final PatentClassNumberService patentClassNumberService; private final PatentClassNumberLinkService patentClassNumberLinkService; private final ProjectPatentLinkService projectPatentLinkService; private final TaskService taskService; private final PatentImageService patentImageService; private final ProjectFieldPatentLinkService projectFieldPatentLinkService; private final ProjectFolderService projectFolderService; private final ProjectFolderPatentLinkService projectFolderPatentLinkService; private final ProjectFieldService projectFieldService; private final ProjectFieldOptionService projectFieldOptionService; private final ProjectFieldTreeService projectFieldTreeService; private final ProjectFieldTextService projectFieldTextService; private final ProjectFileService projectFileService; private final SystemDictService systemDictService; private final PatentInstructionService patentInstructionService; private final PatentInstructionTextService patentInstructionTextService; private final PatentRightService patentRightService; private final FileUtils fileUtils; private final PatentLabelService patentLabelService; private final CacheUtils cacheUtils; private final ProjectExportService projectExportService; private final ProjectService projectService; private final PatentInventorMergeService patentInventorMergeService; private final UserService userService; private final ApiUtils apiUtils; public Project getProjectByName(String name) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Project::getName, name); queryWrapper.last("limit 1"); return this.getOne(queryWrapper); } public IPage getPageList(ProjectVO params) { Map m =new HashMap<>(); m.put("token",params.getToken()); m.put("loginId",4); m.put("functionId",8); PersonnelVO user = cacheUtils.getLoginUserPersonnel(3); List projectIds = new ArrayList() {{ add(-1); }}; if (params.getMyself()) { projectIds.addAll(projectUserService.getProIdByUserId(3)); } if (user.getUsername().equals(Constants.ADMIN_USERNAME)) { projectIds.addAll(projectService.list().stream().map(Project::getId).collect(Collectors.toList())); } params.setProIds(projectIds); params.setCreateBy(3); SecurityUtils.startDataScope(m); IPage pageList = baseMapper.getPageList(new Page<>(params.getCurrent(), params.getSize()), params); List dataList = pageList.getRecords(); Map map = new HashMap<>(); map.put("departmentId", dataList.stream().map(Project::getDepartmentId).collect(Collectors.toList())); // try { // JSONArray jsonObject = apiUtils.invokeApi(new JSONObject(map), "/permission/api/system/getDepartmentById", "post", "data"); // for (int i = 0; i < dataList.size(); i++) { // dataList.get(i).setDepartmentName((String) jsonObject.get(i)); // } // } catch (IOException e) { // e.printStackTrace(); // } // this.setDataList(dataList); // pageList.setRecords(dataList); return pageList; } public List getProjectByIds(List ids) { if (ids == null || ids.size() == 0) { return new ArrayList<>(); } LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.in(Project::getId, ids); return this.list(queryWrapper); } public List getProjectByCreateId(Integer createBy) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Project::getCreateBy, createBy); return this.list(queryWrapper); } public Project getProjectById(Integer id) { Project project = this.getById(id); Client client = clientService.getById(project.getClientId()); if (client != null) { project.setClientName(client.getName()); } return project; } private void setDataList(List dataList) { List systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.ENTERPRISE_APPLICATION_SCENARIO, Constants.INVESTIGATION_TYPE)); dataList.forEach(item -> { if (StringUtils.isNotEmpty(item.getScenario())) { item.setScenarioList(StringUtils.changeStringToInteger(item.getScenario(), ",")); item.setScenarioName(systemDictList.stream().filter(systemDict -> systemDict.getType().equals(Constants.ENTERPRISE_APPLICATION_SCENARIO) && item.getScenarioList().contains(Integer.parseInt(systemDict.getValue()))).map(SystemDict::getLabel).collect(Collectors.toList())); item.setScenario(null); } if (StringUtils.isNotEmpty(item.getType())) { item.setTypeList(StringUtils.changeStringToInteger(item.getType(), ",")); item.setTypeName(systemDictList.stream().filter(systemDict -> systemDict.getType().equals(Constants.INVESTIGATION_TYPE) && item.getTypeList().contains(Integer.parseInt(systemDict.getValue()))).map(SystemDict::getLabel).collect(Collectors.toList())); item.setType(null); } }); } public List getAllProjectByMySelf() { User user = cacheUtils.getLoginUser(3); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); List proIds = new ArrayList<>(); if (!user.getUsername().equals(Constants.ADMIN_USERNAME)) { proIds.addAll(projectUserService.getProIdByUserId(user.getId())); proIds.addAll(this.getProjectByCreateId(3).stream().map(Project::getId).collect(Collectors.toList())); if (proIds.size() != 0) { queryWrapper.in(Project::getId, proIds); } else { queryWrapper.eq(Project::getId, -1); } } List projectList = this.list(queryWrapper); this.setDataList(projectList); return projectList; } public Map getProjectStatusTotal() { Map map = new HashMap<>(); List projectList = this.getAllProjectByMySelf(); List systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.ENTERPRISE_APPLICATION_SCENARIO)); for (SystemDict systemDict : systemDictList) { Map result = new HashMap<>(); List tempList = projectList.stream().filter(item -> item.getScenarioList().contains(Integer.parseInt(systemDict.getValue()))).collect(Collectors.toList()); result.put("completed", tempList.stream().filter(item -> item.getStatus().equals("1")).count()); result.put("unfinished", tempList.stream().filter(item -> item.getStatus().equals("0")).count()); map.put(systemDict.getLabel(), result); } return map; } public Map getProjectTypeTotal(String scenario) { Map map = new HashMap<>(); List projectList = this.getAllProjectByMySelf(); projectList = projectList.stream().filter(item -> item.getScenarioName().contains(scenario)).collect(Collectors.toList()); List systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.INVESTIGATION_TYPE)); for (SystemDict systemDict : systemDictList) { Map result = new HashMap<>(); map.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getTypeList().contains(Integer.parseInt(systemDict.getValue()))).count()); } return map; } public Map getScenarioAndTypeTotal() { List projectList = this.getAllProjectByMySelf(); List systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.ENTERPRISE_APPLICATION_SCENARIO, Constants.INVESTIGATION_TYPE)); List clientList = clientService.getClientByObjectIds(this.getClientIds(projectList.stream().map(Project::getClientId).collect(Collectors.toList()))); Map type = new HashMap<>(); Map scenario = new HashMap<>(); Map result = new HashMap<>(); Map client = new HashMap<>(); Map create = new HashMap<>(); systemDictList.forEach(systemDict -> { switch (systemDict.getType()) { case Constants.ENTERPRISE_APPLICATION_SCENARIO: scenario.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getScenarioList().contains(Integer.parseInt(systemDict.getValue()))).count()); break; case Constants.INVESTIGATION_TYPE: type.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getTypeList().contains(Integer.parseInt(systemDict.getValue()))).count()); break; } }); clientList.forEach(item -> client.put(item.getName(), projectList.stream().filter(project -> project.getClientId().equals(item.getId())).count())); Date date = DateUtil.date(); for (int i = 0; i < 6; i++) { Date finalDate = date; create.put(DateUtil.format(date, "yyyy-MM"), projectList.stream().filter(item -> (item.getCreateTime() * 1000L) >= DateUtil.beginOfMonth(finalDate).getTime() && (item.getCreateTime() * 1000L) <= DateUtil.endOfMonth(finalDate).getTime()).count()); date = DateUtil.offset(date, DateField.MONTH, -1); } result.put("scenario", scenario); result.put("type", type); result.put("client", client); result.put("create", create); return result; } private List getClientIds(List clientIds) { Map map = clientIds.stream().collect(Collectors.groupingBy(p -> p, Collectors.counting())); return map.entrySet().stream() .sorted((Map.Entry o1, Map.Entry o2) -> o2.getValue().intValue() - o1.getValue().intValue()) .map(Map.Entry::getKey).collect(Collectors.toList()) .subList(0, Math.min(map.size(), 10)); } public String getImportProjectName(String name) { String tempName = name + "(1)"; Project project1 = this.getProjectByName(name); if (project1 == null) { return name; } Project project2 = this.getProjectByName(tempName); if (project2 != null) { tempName = this.getImportProjectName(tempName); } return tempName; } public Integer importProject(Integer projectId, String json, Integer userId) { if ((projectId == null || projectId.equals(0)) && StringUtils.isEmpty(json)) { return 0; } if (StringUtils.isEmpty(json)) { return projectId; } Project temp = this.getById(projectId); Project data = JsonUtils.jsonToPojo(json, Project.class); Client client = clientService.getClientByName(data.getClientName()); if (client == null) { client = new Client(); client.setName(data.getClientName()); client.setStatus(1); client.setCreateBy(userId); client.setCreateTime(DateUtils.getDateTime()); client.insert(); } if (temp == null) { temp = new Project(); } String projectName = temp.getName(); BeanUtils.copyProperties(data, temp); if (projectName == null || !projectName.equals(data.getName())) { temp.setName(this.getImportProjectName(temp.getName())); } temp.setClientId(client.getId()); if (projectId == null || projectId.equals(0)) { temp.setCreateBy(userId); temp.setCreateTime(DateUtils.getDateTime()); temp.setId(null); } else { temp.setId(projectId); } temp.insertOrUpdate(); return temp.getId(); } @Transactional public String add(Project project) { Project temp = this.getProjectByName(project.getName()); if (temp != null) { return Response.error("专题库名称已存在"); } if (project.getClientId() == -1) { project.setClientId(this.getNewClientId(project.getClientName())); } project.setScenario(StringUtils.join(project.getScenarioList(), ",")); project.setType(StringUtils.join(project.getTypeList(), ",")); project.setCreateBy(StpUtil.getLoginIdAsInt()); project.setCreateTime(DateUtils.getDateTime()); project.insert(); this.addProjectUser(project.getId()); return Response.success(project.getId()); } @Transactional public String edit(Project project) { Project temp = this.getProjectByName(project.getName()); if (temp != null && !temp.getId().equals(project.getId())) { return Response.error("专题库名称已存在"); } if (project.getClientId() == -1) { project.setClientId(this.getNewClientId(project.getClientName())); } project.setScenario(StringUtils.join(project.getScenarioList(), ",")); project.setType(StringUtils.join(project.getTypeList(), ",")); project.updateById(); return Response.success(); } @Transactional public String delete(Integer id) { this.removeById(id); this.deleteProjectUser(id, StpUtil.getLoginIdAsInt()); projectPatentLinkService.deleteByProjectId(id); projectFolderService.deleteByProjectId(id); projectFieldService.deleteByProjectId(id); projectUserService.deleteByProjectId(id); projectFileService.deleteByProjectId(id); patentApplicantMergeLinkService.deleteByProjectId(id); return Response.success(); } private Integer getNewClientId(String name) { Client client = clientService.getOne(Wrappers.lambdaQuery().eq(Client::getName, name).last("limit 1")); if (client == null) { client = new Client(); client.setName(name); client.setStatus(1); client.setCreateBy(StpUtil.getLoginIdAsInt()); client.setCreateTime(DateUtils.getDateTime()); client.insert(); } return client.getId(); } private void addProjectUser(Integer projectId) { ProjectUser user = new ProjectUser(); user.setUserId(StpUtil.getLoginIdAsInt()); user.setProjectId(projectId); user.setCreateTime(DateUtils.getDateTime()); user.insert(); } private void deleteProjectUser(Integer projectId, Integer userId) { projectUserService.remove(Wrappers.lambdaQuery().eq(ProjectUser::getUserId, userId).eq(ProjectUser::getProjectId, projectId)); } @Transactional(rollbackFor = Exception.class) public String importExcel(MultipartFile file) { try { ExcelReader reader = ExcelUtil.getReader(file.getInputStream()); List> readAll = reader.readAll(); List systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.INVESTIGATION_TYPE, Constants.ENTERPRISE_APPLICATION_SCENARIO)); for (int i = 0; i < readAll.size(); i++) { Map row = readAll.get(i); Project project = new Project(); project.setSort(1); project.setName(row.get("专题库名称").toString()); project.setClientId(this.getNewClientId(row.get("委托方").toString())); project.setRemark(row.get("备注").toString()); project.setCreateBy(StpUtil.getLoginIdAsInt()); project.setCreateTime(DateUtils.getDateTime()); List typeName = StringUtils.changeStringToString(row.get("调查类型").toString(), ";"); List typeList = systemDictList.stream().filter(item -> item.getType().equals(Constants.INVESTIGATION_TYPE) && typeName.contains(item.getLabel())).map(SystemDict::getValue).map(Integer::parseInt).collect(Collectors.toList()); project.setType(StringUtils.join(typeList, ",")); List scenarioName = StringUtils.changeStringToString(row.get("企业应用场景").toString(), ";"); List scenarioList = systemDictList.stream().filter(item -> item.getType().equals(Constants.ENTERPRISE_APPLICATION_SCENARIO) && scenarioName.contains(item.getLabel())).map(SystemDict::getValue).map(Integer::parseInt).collect(Collectors.toList()); project.setScenario(StringUtils.join(scenarioList, ",")); project.setTechnicalTheme(row.get("技术主题").toString()); project.setContractNo(row.get("合同号").toString()); project.setInnerFile(row.get("内部案卷").toString()); Object caseDate = row.get("委案日"); if (StringUtils.isNotNull(caseDate)) { project.setCaseDate(caseDate.toString()); } project.setStatus(row.get("处理状态").toString().equals("处理中") ? "0" : "1"); Object update = row.get("是否更新"); if (StringUtils.isNotNull(update)) { project.setUpdate(update.toString().equals("是") ? 1 : 0); project.setUpdateTime(row.get("更新周期").toString()); } else { project.setUpdate(0); project.setUpdateTime("一天"); } project.insert(); List userName = StringUtils.changeStringToString(row.get("管理员").toString(), ";"); List userList = userService.getUserByNames(userName); List projectUserList = new ArrayList<>(); userList.forEach(item -> { ProjectUser projectUser = new ProjectUser(); projectUser.setProjectId(project.getId()); projectUser.setUserId(item.getId()); projectUser.setCreateTime(DateUtils.getDateTime()); projectUser.setType(2); projectUserList.add(projectUser); }); projectUserService.saveOrUpdateBatch(projectUserList); } return Response.success(true); } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return Response.error(); } } @Transactional public String share(Integer id, List userIds) { ProjectUser user = new ProjectUser(); user.setType(3); user.setRemark("用户分享"); user.setProjectId(id); user.setUserIds(userIds); return projectUserService.add(user); } public TaskParams getImportPatentTaskParams(MultipartFile file, Integer projectId) { UploadFileDTO fileDTO = fileUtils.uploadFile(file); String path = fileUtils.getPath(fileDTO.getPath()); List> rowList = new ArrayList<>(); List> mapList = new ArrayList<>(); ExcelUtil.readBySax(path, -1, (sheetIndex, rowIndex, row) -> rowList.add(row)); for (int i = 1; i < rowList.size(); i++) { mapList.add(IterUtil.toMap(rowList.get(0), rowList.get(i))); } Integer taskId = taskService.add(fileDTO, projectId, rowList.size() - 1, 1, 0, file.getOriginalFilename()); TaskParams taskParams = new TaskParams(); taskParams.setTaskId(taskId); taskParams.setPath(path); taskParams.setTaskType(1); taskParams.setRowList(mapList); taskParams.setUserId(String.valueOf(StpUtil.getLoginIdAsInt())); taskParams.setOldName(file.getOriginalFilename()); return taskParams; } @Async("singleThreadAsyncTaskExecutor") @Transactional(rollbackFor = Exception.class) public void importPatent(TaskParams params, ProjectImportPatentVO projectImportPatentVO) { Integer total = params.getRowList().size(); try { if (projectImportPatentVO != null) { List systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.PATENT_TYPE, Constants.PATENT_SIMPLE_STATUS)); Map pictureDataMap = ExcelUtils.getDataFromExcel(params.getPath()); for (int i = 0; i < params.getRowList().size(); i++) { Map row = params.getRowList().get(i); Object patentNo = row.get("公开(公告)号"); if (StringUtils.isNotNull(patentNo)) { PatentCustomFieldParams patentCustomFieldParams = new PatentCustomFieldParams(); //用专利号查找专利的相关信息 并装配到 Patent 中 Patent patent = patentService.getByPatentNo(patentNo.toString()); //法律状态/事件|INPADOC法律状态|法律状态更新时间|简单法律状态 PatentAffairParams patentAffairParams = new PatentAffairParams(); //当前申请(专利权)人 List patentApplicantCurrentName = new ArrayList<>(); //原始申请(专利权)人 List patentApplicantOriginalName = new ArrayList<>(); //[标]当前申请(专利权)人 List patentApplicantStandardCurrentName = new ArrayList<>(); //[标]原始申请(专利权)人 List patentApplicantStandardOriginalName = new ArrayList<>(); //发明人|第一发明人 PatentInventorParams patentInventorParams = new PatentInventorParams(); //简单同族|PatSnap同族|INPADOC同族 PatentSimpleFamilyParams patentSimpleFamilyParams = new PatentSimpleFamilyParams(); //IPC分类号|UPC分类号|LOC分类号|CPC分类号|IPC主分类号|UPC主分类号 PatentClassNumberParams patentClassNumberParams = new PatentClassNumberParams(); //许可人|被许可人|许可类型 PatentLicensorParams patentLicensorParams = new PatentLicensorParams(); //质押人|质权人 PatentPledgeParams patentPledgeParams = new PatentPledgeParams(); //代理人 PatentAgentParams patentAgentParams = new PatentAgentParams(); //当前申请(专利权)人地址|当前申请(专利权)人国家|当前第一申请(专利权)人地址|原始申请(专利权)人地址|原始申请(专利权)人国家 PatentApplicantAddressParams patentApplicantAddressParams = new PatentApplicantAddressParams(); //发明人地址|第一发明人地址 PatentInventorAddressParams patentInventorAddressParams = new PatentInventorAddressParams(); //说明书|说明书(译) PatentInstructionTextParams patentInstructionTextParams = new PatentInstructionTextParams(); //权利要求|独立权利要求|权利要求(译) PatentRightParams patentRightParams = new PatentRightParams(); //标签 PatentLabelParams patentLabelParams = new PatentLabelParams(); if (patent == null) { patent = new Patent(); patent.setPatentNo(patentNo.toString()); patent.setPublicNo(patentNo.toString()); patent.insert(); } patentAffairParams.setPatentId(patent.getId()); patentInventorParams.setPatentId(patent.getId()); patentSimpleFamilyParams.setPatentId(patent.getId()); patentSimpleFamilyParams.setPatentNo(patent.getPatentNo()); patentClassNumberParams.setPatentId(patent.getId()); patentCustomFieldParams.setPatentId(patent.getId()); patentCustomFieldParams.setProjectId(projectImportPatentVO.getProjectId()); patentCustomFieldParams.setUserId(Integer.parseInt(params.getUserId())); patentLicensorParams.setPatentId(patent.getId()); patentPledgeParams.setPatentId(patent.getId()); patentAgentParams.setPatentId(patent.getId()); patentApplicantAddressParams.setPatentId(patent.getId()); patentInventorAddressParams.setPatentId(patent.getId()); patentInstructionTextParams.setPatentId(patent.getId()); patentRightParams.setPatentId(patent.getId()); patentRightParams.setPatentNo(patent.getPatentNo()); patentLabelParams.setPatentId(patent.getId()); patentLabelParams.setProjectId(projectImportPatentVO.getProjectId()); for (Object object : row.keySet()) { String key = object.toString(); if (key.equals("摘要附图")) { PictureData pictureData = pictureDataMap.get(String.valueOf(i + 1)); if (pictureData != null) { //1.先把Excel里的图片存到文件夹里 路径大致是 ../target/file/时间/文件.png 2.生成完文件并存完后 将文件的路径和名称存到表里 OS_PATENT_IMAGE 然后最终得到摘要图片的存储路径 String abstractPath = patentImageService.updatePatentImage(patent.getId(), pictureData); //将路径进行装配 patent.setAbstractPath(abstractPath); } } Object value = row.get(key); if (StringUtils.isNotNull(value) && !value.equals("") && !value.equals("-") && !value.equals("\\")) { switch (key) { case "标题": List titles = StringUtils.changeStringToString(value.toString(), " \\| "); if (titles.size() == 2) { patent.setName(titles.get(0)); patent.setNameOut(titles.get(1)); } else { patent.setName(value.toString()); } break; case "摘要": List abstracts = StringUtils.changeStringToString(value.toString(), " \\| "); if (abstracts.size() == 2) { patent.setAbstractStr(abstracts.get(0)); patent.setAbstractOut(abstracts.get(1)); } else { patent.setAbstractStr(value.toString()); } break; case "公开(公告)日": patent.setPublicDate(DateUtils.getDateTime(value.toString())); break; case "当前申请(专利权)人": patentApplicantCurrentName.addAll(PatentUtils.formatValue(value.toString())); break; case "当前申请(专利权)人地址": //patentApplicantAddressParams.setCurrentAddress(value.toString()); break; case "当前申请(专利权)人国家": //patentApplicantAddressParams.setCurrentCountry(value.toString()); break; case "[标]当前申请(专利权)人": patentApplicantStandardCurrentName.addAll(PatentUtils.formatValue(value.toString())); break; case "法律状态/事件": //patentAffairParams.setStatusList(PatentUtils.formatValue(value.toString())); break; case "INPADOC法律状态": patentAffairParams.setContent(value.toString()); break; case "法律状态更新时间": patentAffairParams.setDateTime(DateUtils.getDateTime(value.toString())); break; case "简单法律状态": Integer simpleStatus = Integer.parseInt(systemDictList.stream().filter(systemDict -> systemDict.getType().equals(Constants.PATENT_SIMPLE_STATUS) && systemDict.getLabel().equals(value.toString())).findFirst().orElse(new SystemDict()).getValue()); patent.setSimpleStatus(simpleStatus); patentAffairParams.setSimpleStatus(simpleStatus); break; case "申请号": patent.setApplicationNo(value.toString()); break; case "文献代码": patent.setCode(value.toString()); break; case "受理局": patent.setBureau(value.toString()); break; case "申请日": patent.setApplicationDate(DateUtils.getDateTime(value.toString())); break; case "摘要(译)": patent.setAbstractOut(value.toString()); break; case "标题(译)": patent.setNameOut(value.toString()); break; case "专利类型": Integer type = Integer.parseInt(systemDictList.stream().filter(systemDict -> systemDict.getType().equals(Constants.PATENT_TYPE) && systemDict.getLabel().equals(value.toString())).findFirst().orElse(new SystemDict()).getValue()); patent.setType(type); break; case "说明书": patentInstructionTextParams.setManual(value.toString()); break; case "说明书(译)": patentInstructionTextParams.setManualOut(value.toString()); break; case "文献页数": patent.setDocPage(Integer.parseInt(value.toString())); break; case "首次公开日": patent.setFirstPublicDate(DateUtils.getDateTime(value.toString())); break; case "当前第一申请(专利权)人": break; case "当前申请(专利权)人数量": patent.setApplicantNum(Integer.parseInt(value.toString())); break; case "当前第一申请(专利权)人地址": patentApplicantAddressParams.setFirstCurrentAddress(value.toString()); break; case "发明人地址": patentInventorAddressParams.setAddress(PatentUtils.formatValue(value.toString())); break; case "第一发明人地址": patentInventorAddressParams.setFirstAddress(value.toString()); break; case "原始申请(专利权)人": patentApplicantOriginalName.addAll(PatentUtils.formatValue(value.toString())); break; case "原始申请(专利权)人地址": //patentApplicantAddressParams.setOriginalAddress(value.toString()); break; case "原始申请(专利权)人国家": //patentApplicantAddressParams.setOriginalCountry(value.toString()); break; case "[标]原始申请(专利权)人": patentApplicantStandardOriginalName.addAll(PatentUtils.formatValue(value.toString())); break; case "发明人": patentInventorParams.setNameList(PatentUtils.formatValue(value.toString())); break; case "第一发明人": patentInventorParams.setFirstName(value.toString()); break; case "发明人数量": patent.setInventorNum(Integer.parseInt(value.toString())); break; case "权利要求": patentRightParams.setContent(value.toString()); break; case "独立权利要求": patentRightParams.setSelfContent(value.toString()); break; case "权利要求(译)": patentRightParams.setContentOut(value.toString()); break; case "权利要求数量": // if ("该数据不支持导出".equals(value.toString())) { // patent.setSelfRightContentNum(0); // } else { // // } patent.setSelfRightContentNum(Integer.parseInt(value.toString())); break; case "IPC分类号": patentClassNumberParams.setIpcList(PatentUtils.formatValue(value.toString())); break; case "UPC分类号": patentClassNumberParams.setUpcList(PatentUtils.formatValue(value.toString())); break; case "LOC分类号": patentClassNumberParams.setLocList(PatentUtils.formatValue(value.toString())); break; case "CPC分类号": patentClassNumberParams.setCpcList(PatentUtils.formatValue(value.toString())); break; case "IPC主分类号": patentClassNumberParams.setMainIpc(value.toString()); break; case "UPC主分类号": patentClassNumberParams.setMainUpc(value.toString()); break; case "简单同族": patentSimpleFamilyParams.setSimpleFamily(PatentUtils.formatValue(value.toString())); break; case "简单同族成员数量": patent.setSimpleFamilyNum(Integer.parseInt(value.toString())); break; case "PatSnap同族": patentSimpleFamilyParams.setPatSnapFamily(PatentUtils.formatValue(value.toString())); break; case "PatSnap同族成员数量": patent.setPatSnapFamilyNum(Integer.parseInt(value.toString())); break; case "INPADOC同族": patentSimpleFamilyParams.setInpadocFamily(PatentUtils.formatValue(value.toString())); break; case "INPADOC同族成员数量": patent.setInpadocFamilyNum(Integer.parseInt(value.toString())); break; case "优先权号": patent.setPriorityNo(value.toString()); break; case "授权日": patent.setPublicAccreditDate(DateUtils.getDateTime(value.toString())); break; case "优先权国家": patent.setPriorityCountry(value.toString()); break; case "优先权日": patent.setPriorityDate(DateUtils.getDateTime(value.toString())); break; case "非专利引用文献": patent.setNotPatentQuote(value.toString()); break; case "非专利引用文献数量": patent.setNotPatentQuoteNum(Integer.parseInt(value.toString())); break; case "被引用专利": patent.setQuoted(value.toString()); break; case "被引用专利数量": patent.setQuotedNum(Integer.parseInt(value.toString())); break; case "引用专利": patent.setQuote(value.toString()); break; case "引用专利数量": patent.setQuoteNum(Integer.parseInt(value.toString())); break; case "3年内被引用次数": patent.setQuotedNum3(Integer.parseInt(value.toString())); break; case "5年内被引用次数": patent.setQuotedNum5(Integer.parseInt(value.toString())); break; case "许可人": patentLicensorParams.setLicensor(PatentUtils.getPatentLicensor(value.toString())); break; case "被许可人": patentLicensorParams.setLicensee(PatentUtils.getPatentLicensor(value.toString())); break; case "许可类型": patentLicensorParams.setType(PatentUtils.getPatentLicensor(value.toString())); break; case "质押人": patentPledgeParams.setPledgor(PatentUtils.getPatentLicensor(value.toString())); break; case "质权人": patentPledgeParams.setPledgee(PatentUtils.getPatentLicensor(value.toString())); break; case "EP指定国状态": patent.setEpStatus(value.toString()); break; case "WO国家阶段": patent.setWo(value.toString()); break; case "代理机构": patent.setAgencyId(patentAgencyService.getAgencyStringIdByName(value.toString())); break; case "代理人": patentAgentParams.setAgent(PatentUtils.formatValue(value.toString())); break; case "审查员": patent.setExaminer(value.toString()); break; case "助理审查员": patent.setAidExaminer(value.toString()); break; case "标签": patentLabelParams.setLabel(PatentUtils.formatValue2(value.toString())); break; default: List fields = StringUtils.changeStringToString(key, ":"); if (fields.size() == 2) { patentCustomFieldParams.put(key, PatentUtils.formatValue2(value.toString())); } break; } } else { List fields = StringUtils.changeStringToString(key, ":"); if (fields.size() == 2) { patentCustomFieldParams.put(key, null); } } } patent.updateById(); //专利权利要求表 //patentRightService.updatePatentRight(patentRightParams); //专利说明书(文本) //patentInstructionTextService.updatePatentInstructionText(patentInstructionTextParams); //代理人 (代理人关联专利) //patentAgentService.updatePatentAgent(patentAgentParams); //专利信息质押质权人 //patentPledgeService.updatePatentPledge(patentPledgeParams); //专利信息许可人 //patentLicensorService.updatePatentLicensor(patentLicensorParams); //专利信息事务信息 //patentAffairService.updatePatientAffair(patentAffairParams); //权利人 patentApplicantLinkService.updatePatentApplicantLink(patentApplicantCurrentName, patentApplicantStandardCurrentName, 1, patent.getId()); //申请人 patentApplicantLinkService.updatePatentApplicantLink(patentApplicantOriginalName, patentApplicantStandardOriginalName, 2, patent.getId()); //申请人地址 patentApplicantService.updatePatentApplicantAddress(patentApplicantAddressParams); //发明人 patentInventorService.updatePatentInventor(patentInventorParams); //发明人地址 patentInventorService.updatePatentInventorAddress(patentInventorAddressParams); //专利信息简单同族关联 //patentSimpleFamilyService.updatePatentSimpleFamily(patentSimpleFamilyParams); //专利分类号关联 //patentClassNumberLinkService.updatePatentClassNumberLink(patentClassNumberParams); //专题库关联专利信息 //projectPatentLinkService.updateProjectPatent(projectImportPatentVO.getProjectId(), patent.getId()); //标引内容关联专利信息 //projectFieldPatentLinkService.updateProjectFieldPatentLink(projectImportPatentVO, patent.getId()); //文件夹管理 //projectFolderPatentLinkService.updateProjectFolderLink(projectImportPatentVO, patent.getId()); //自定义字段 //patentService.updatePatentCustomField(patentCustomFieldParams); //标签 //patentLabelService.updatePatentLabel(patentLabelParams); // WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO() // .setTaskId(params.getTaskId()) // .setProjectId(projectImportPatentVO.getProjectId()) // .setComplete(false) // .setIndex(i) // .setTaskType(Constants.TASK_IMPORT_PATENT) // .setPercentage(total == 0 ? 0 : Math.round((total.equals(i) ? (i * 1D) : (i + 1D)) / total * 100D)) // .setFileName("") // .setOldName(params.getOldName()) // .setUrl("") // .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), params.getUserId()); } } // SpringUtil.getBean(ProjectService.class).setImportPatentTaskStatus(2, params.getTaskId()); // WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO() // .setTaskId(params.getTaskId()) // .setProjectId(projectImportPatentVO.getProjectId()) // .setComplete(true) // .setIndex(total) // .setTaskType(Constants.TASK_IMPORT_PATENT) // .setPercentage(100L) // .setFileName("") // .setOldName(params.getOldName()) // .setUrl("") // .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), params.getUserId()); } } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); SpringUtil.getBean(ProjectService.class).setImportPatentTaskStatus(3, params.getTaskId()); WebSocketServer.sendInfo(Response.error(ResponseEnum.PATENT_IMPORT_TASK_ERROR), params.getUserId()); } } @Transactional(propagation = Propagation.NOT_SUPPORTED) public void setImportPatentTaskStatus(Integer status, Integer taskId) { taskService.updateStatus(taskId, status, DateUtils.getDateTime()); } public void saveDataToJsonFile(String tempPath, String fileName, String data) throws IOException { String path = tempPath + FileUtils.FILE_SEPARATOR + fileName; FileOutputStream fileOutputStream = new FileOutputStream(path); fileOutputStream.write(data.getBytes(StandardCharsets.UTF_8)); fileOutputStream.close(); } public void copyFileToTempDirectory(String src, String tempPath, String directoryName, String fileName) { String dest = tempPath + FileUtils.FILE_SEPARATOR + directoryName + FileUtils.FILE_SEPARATOR + fileName; File file = FileUtil.file(fileUtils.getSystemPath(src)); if (FileUtil.exist(file)) { FileUtil.copy(file, new File(dest), true); } } @Async public void export(ProjectExportVO params, Integer exportId, Integer userId) { try { String json = cacheUtils.getSelectPatentIds(params.getKey()); List patentIds = StringUtils.changeStringToInteger(json, ","); List patentList = patentService.getPatentListByIds(patentIds); String directoryName = IdUtil.simpleUUID(); String fileName = directoryName + ".zip"; String tempPath = fileUtils.getTempPath(directoryName); String url = fileUtils.getDirectory(fileName); String savePath = fileUtils.getSystemPath(url); File directory = new File(tempPath); if (!directory.exists()) { directory.mkdir(); } WebSocketServer.sendInfo(Response.websocket(true, ResponseEnum.PROJECT_EXPORT_TASK_SUCCESS), String.valueOf(userId)); if (params.getProjectInfo()) { Project project = this.getProjectById(params.getProjectId()); this.saveDataToJsonFile(tempPath, Constants.PROJECT_INFO_FILE_NAME, JsonUtils.objectToJson(project)); } if (params.getProjectReport() != null && params.getProjectReport().size() != 0) { List projectFileList = projectFileService.getProjectFileByIds(params.getProjectReport()); this.saveDataToJsonFile(tempPath, Constants.PROJECT_REPORT_FILE_NAME, JsonUtils.objectToJson(projectFileList)); projectFileList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PROJECT_REPORT_DIRECTORY_NAME, item.getFileName())); } if (params.getProjectFile() != null && params.getProjectFile().size() != 0) { List projectFileList = projectFileService.getProjectFileByIds(params.getProjectFile()); this.saveDataToJsonFile(tempPath, Constants.PROJECT_FILE_FILE_NAME, JsonUtils.objectToJson(projectFileList)); projectFileList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PROJECT_FILE_DIRECTORY_NAME, item.getFileName())); } if (params.getPatentImage()) { List patentImageList = patentImageService.getPatentImageByPatentIds(patentIds); this.saveDataToJsonFile(tempPath, Constants.PATENT_IMAGE_FILE_NAME, JsonUtils.objectToJson(patentImageList)); patentImageList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PATENT_IMAGE_DIRECTORY_NAME, item.getFileName())); } if (params.getPatentInstruction()) { List patentNo = patentList.stream().map(Patent::getPatentNo).collect(Collectors.toList()); List patentInstructionList = patentInstructionService.getPatentInstructionByPatentNo(patentNo); this.saveDataToJsonFile(tempPath, Constants.PATENT_INSTRUCTION_FILE_NAME, JsonUtils.objectToJson(patentInstructionList)); patentInstructionList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PATENT_INSTRUCTION_DIRECTORY_NAME, item.getFileName())); } if (params.getPatentBase()) { List patentApplicantLinkList = patentApplicantLinkService.getApplicantAttributesListByPatentIds(patentIds); List patentApplicantMergeLinkList = patentApplicantMergeLinkService.getPatentApplicantMergeLinkListByProjectId(params.getProjectId()); List patentApplicantIds = new ArrayList<>(); patentApplicantLinkList.forEach(item -> patentApplicantIds.add(item.getApplicantId())); patentApplicantMergeLinkList.forEach(item -> patentApplicantIds.add(item.getMergeId())); List patentApplicantList = patentApplicantService.getPatentApplicantByIds(patentApplicantIds); List patentAffairList = patentAffairService.getPatentAffairListByPatentIds(patentIds); List patentAgencyList = patentAgencyService.getPatentAgencyByIds(patentList.stream().filter(item -> StringUtils.isNotEmpty(item.getAgencyId())).map(item -> Integer.parseInt(item.getAgencyId())).collect(Collectors.toList())); List patentAgentLinkList = patentAgentLinkService.getPatentAgentLinkByPatentIds(patentIds); List patentAgentList = patentAgentService.getPatentAgentByIds(patentAgentLinkList.stream().map(PatentAgentLink::getAgentId).collect(Collectors.toList())); List patentInstructionTextList = patentInstructionTextService.getPatentInstructionTextByPatentIds(patentIds); List patentInventorLinkList = patentInventorLinkService.getPatentInventorLinkByPatentIds(patentIds); List patentInventorMergeList = patentInventorMergeService.getPatentInventorMergeByProjectId(params.getProjectId()); List patentInventorIds = new ArrayList<>(); patentInventorLinkList.forEach(item -> patentInventorIds.add(item.getInventorId())); patentInventorMergeList.forEach(item -> patentInventorIds.add(item.getMergeId())); List patentInventorList = patentInventorService.getPatentInventorByIds(patentInventorIds); List patentLicensorList = patentLicensorService.getPatentLicensorByPatentIds(patentIds); List patentPledgeList = patentPledgeService.getPatentPledgeByPatentIds(patentIds); List patentRightList = patentRightService.getPatentRightByPatentIds(patentIds); List patentFamilyIds = new ArrayList<>(); patentList.forEach(item -> { patentFamilyIds.add(item.getSimpleFamily()); patentFamilyIds.add(item.getInpadocFamily()); patentFamilyIds.add(item.getPatSnapFamily()); }); List patentSimpleFamilyLinkList = patentSimpleFamilyLinkService.getPatentSimpleFamilyLinkByFamilyIds(patentFamilyIds); List patentSimpleFamilyList = patentSimpleFamilyService.getPatentSimpleFamilyByIds(patentFamilyIds); List patentClassNumberLinkList = patentClassNumberLinkService.getPatentClassNumberLinkByPatentIds(patentIds); this.saveDataToJsonFile(tempPath, Constants.PATENT_FILE_NAME, JsonUtils.objectToJson(patentList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_AFFAIR_FILE_NAME, JsonUtils.objectToJson(patentAffairList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENCY_FILE_NAME, JsonUtils.objectToJson(patentAgencyList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENT_LINK_FILE_NAME, JsonUtils.objectToJson(patentAgentLinkList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENT_FILE_NAME, JsonUtils.objectToJson(patentAgentList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_INSTRUCTION_TEXT_FILE_NAME, JsonUtils.objectToJson(patentInstructionTextList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_LINK_FILE_NAME, JsonUtils.objectToJson(patentInventorLinkList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_FILE_NAME, JsonUtils.objectToJson(patentInventorList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_MERGE_FILE_NAME, JsonUtils.objectToJson(patentInventorMergeList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_LICENSOR_FILE_NAME, JsonUtils.objectToJson(patentLicensorList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_PLEDGE_FILE_NAME, JsonUtils.objectToJson(patentPledgeList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_RIGHT_FILE_NAME, JsonUtils.objectToJson(patentRightList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_FAMILY_LINK_FILE_NAME, JsonUtils.objectToJson(patentSimpleFamilyLinkList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_FAMILY_FILE_NAME, JsonUtils.objectToJson(patentSimpleFamilyList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_CLASS_NUMBER_FILE_NAME, JsonUtils.objectToJson(patentClassNumberLinkList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_FILE_NAME, JsonUtils.objectToJson(patentApplicantList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_LINK_FILE_NAME, JsonUtils.objectToJson(patentApplicantLinkList)); this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_MERGE_LINK_FILE_NAME, JsonUtils.objectToJson(patentApplicantMergeLinkList)); } if (params.getPatentField() != null && params.getPatentField().size() != 0) { if (params.getPatentField().contains(0)) { List patentLabelList = patentLabelService.getPatentLabelByPatentIdsAndProjectId(patentIds, params.getProjectId()); this.saveDataToJsonFile(tempPath, Constants.PATENT_LABEL_FILE_NAME, JsonUtils.objectToJson(patentLabelList)); } List projectFieldList = projectFieldService.getFieldListByIds(params.getPatentField()); List projectFieldIds = projectFieldList.stream().map(ProjectField::getId).collect(Collectors.toList()); List projectFieldOptionList = projectFieldOptionService.getFieldOptionList(projectFieldIds); List projectFieldTreeList = projectFieldTreeService.getProjectFieldTreeOptionByFieldIds(projectFieldIds); List projectFieldTextList = projectFieldTextService.getProjectFieldTextByFieldIds(projectFieldIds); List projectFieldPatentLinkList = new ArrayList<>(); for (Integer fieldId : params.getPatentField()) { projectFieldPatentLinkList.addAll(projectFieldPatentLinkService.getProjectPatentLinkByPatentIdsAndFieldId(patentIds, fieldId)); } this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_FILE_NAME, JsonUtils.objectToJson(projectFieldList)); this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_OPTION_FILE_NAME, JsonUtils.objectToJson(projectFieldOptionList)); this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_TREE_FILE_NAME, JsonUtils.objectToJson(projectFieldTreeList)); this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_TEXT_FILE_NAME, JsonUtils.objectToJson(projectFieldTextList)); this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_PATENT_LINK_FILE_NAME, JsonUtils.objectToJson(projectFieldPatentLinkList)); } List patents = patentService.getPatentIdAndPatentNoByIds(patentIds); this.saveDataToJsonFile(tempPath, Constants.PATENT_ID_PATENT_NO_FILE_NAME, JsonUtils.objectToJson(patents)); File file = ZipUtil.zip(tempPath, savePath); FileUtil.del(tempPath); ProjectExport projectExport = projectExportService.getById(exportId); projectExport.setUrl(url); projectExport.setFileName(fileName); projectExport.setStatus(1); projectExport.setFileSize(FileUtil.size(file)); projectExport.updateById(); WebSocketServer.sendInfo(Response.websocket(true, ResponseEnum.PROJECT_EXPORT_TASK_SUCCESS), String.valueOf(userId)); } catch (Exception e) { e.printStackTrace(); WebSocketServer.sendInfo(Response.websocket(false, ResponseEnum.PROJECT_EXPORT_TASK_ERROR), String.valueOf(userId)); } } @Async("singleThreadAsyncTaskExecutor") @Transactional(rollbackFor = Exception.class) public void importData(String url, ProjectImportVO params, Integer userId, Integer importId) { String tempPath = null; ProjectImportStatusService projectImportStatusService = SpringUtil.getBean(ProjectImportStatusService.class); try { String tempDirectoryName = IdUtil.simpleUUID(); tempPath = fileUtils.getTempPath(tempDirectoryName); String tempSavePath = fileUtils.getSystemPath(url); File tempDirectory = new File(tempPath); if (!tempDirectory.exists()) { tempDirectory.mkdir(); } projectImportStatusService.add(importId, userId, 2); ZipUtil.unzip(tempSavePath, tempPath); String projectJson = this.parseTempFileData(tempPath, Constants.PROJECT_INFO_FILE_NAME); Integer projectId = params.getProjectId(); if (StringUtils.isNotEmpty(projectJson)) { projectImportStatusService.add(importId, userId, 3); projectId = this.importProject(params.getProjectId(), projectJson, userId); } if (projectId.equals(0)) { projectImportStatusService.add(importId, userId, 100); throw new CustomException("数据包未包含专题库信息"); } String projectReportJson = this.parseTempFileData(tempPath, Constants.PROJECT_REPORT_FILE_NAME); String projectFileJson = this.parseTempFileData(tempPath, Constants.PROJECT_FILE_FILE_NAME); if (StringUtils.isNotEmpty(projectReportJson) || StringUtils.isNotEmpty(projectFileJson)) { projectImportStatusService.add(importId, userId, 4); projectFileService.importProjectFile(projectId, userId, tempPath, projectFileJson, projectReportJson); } String patentIdPatentNoJson = this.parseTempFileData(tempPath, Constants.PATENT_ID_PATENT_NO_FILE_NAME); String patentJson = this.parseTempFileData(tempPath, Constants.PATENT_FILE_NAME); String patentAffairJson = this.parseTempFileData(tempPath, Constants.PATENT_AFFAIR_FILE_NAME); String patentAgencyJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENCY_FILE_NAME); String patentAgentJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENT_FILE_NAME); String patentAgentLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENT_LINK_FILE_NAME); String patentInventorJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_FILE_NAME); String patentInventorMergeJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_MERGE_FILE_NAME); String patentInventorLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_LINK_FILE_NAME); String patentApplicantJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_FILE_NAME); String patentApplicantLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_LINK_FILE_NAME); String patentApplicantMergeLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_MERGE_LINK_FILE_NAME); String patentFamilyJson = this.parseTempFileData(tempPath, Constants.PATENT_FAMILY_FILE_NAME); String patentFamilyLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_FAMILY_LINK_FILE_NAME); String patentClassNumberJson = this.parseTempFileData(tempPath, Constants.PATENT_CLASS_NUMBER_FILE_NAME); String patentInstructionTextJson = this.parseTempFileData(tempPath, Constants.PATENT_INSTRUCTION_TEXT_FILE_NAME); String patentRightJson = this.parseTempFileData(tempPath, Constants.PATENT_RIGHT_FILE_NAME); String patentLicensorJson = this.parseTempFileData(tempPath, Constants.PATENT_LICENSOR_FILE_NAME); String patentPledgeJson = this.parseTempFileData(tempPath, Constants.PATENT_PLEDGE_FILE_NAME); if (StringUtils.isNotEmpty(patentJson)) { projectImportStatusService.add(importId, userId, 8); patentService.importPatent(projectId, patentJson, patentAffairJson, patentAgencyJson, patentFamilyJson, patentFamilyLinkJson, patentInventorJson, patentInventorLinkJson, patentAgentJson, patentAgentLinkJson, patentApplicantJson, patentApplicantLinkJson, patentApplicantMergeLinkJson, patentClassNumberJson, patentInstructionTextJson, patentRightJson, patentLicensorJson, patentPledgeJson, patentInventorMergeJson); } projectImportStatusService.add(importId, userId, 9); projectPatentLinkService.importProjectPatentLink(projectId, patentIdPatentNoJson); String projectFieldJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_FILE_NAME); if (StringUtils.isNotEmpty(projectFieldJson)) { String projectFieldTextJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_TEXT_FILE_NAME); String projectFieldOptionJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_OPTION_FILE_NAME); String projectFieldTreeJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_TREE_FILE_NAME); String projectFieldPatentLink = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_PATENT_LINK_FILE_NAME); projectImportStatusService.add(importId, userId, 5); projectFieldService.importProjectField(projectId, userId, patentIdPatentNoJson, projectFieldJson, projectFieldTextJson, projectFieldOptionJson, projectFieldTreeJson, projectFieldPatentLink); } String patentImageJson = this.parseTempFileData(tempPath, Constants.PATENT_IMAGE_FILE_NAME); if (StringUtils.isNotEmpty(patentImageJson)) { projectImportStatusService.add(importId, userId, 6); patentImageService.importPatentImage(tempPath, patentIdPatentNoJson, patentImageJson); } String patentInstructionJson = this.parseTempFileData(tempPath, Constants.PATENT_INSTRUCTION_FILE_NAME); if (StringUtils.isNotEmpty(patentInstructionJson)) { projectImportStatusService.add(importId, userId, 7); patentInstructionService.importPatentInstruction(userId, tempPath, patentIdPatentNoJson, patentInstructionJson); } } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); projectImportStatusService.add(importId, userId, 101); } finally { FileUtil.del(tempPath); projectImportStatusService.add(importId, userId, 200); cacheUtils.deleteUserImport(userId); } } private String parseTempFileData(String path, String fileName) throws IOException { String src = path + FileUtil.FILE_SEPARATOR + fileName; if (!FileUtil.exist(src)) { return null; } File file = new File(src); FileReader fileReader = new FileReader(file); Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); int ch = 0; StringBuffer sb = new StringBuffer(); while ((ch = reader.read()) != -1) { sb.append((char) ch); } fileReader.close(); reader.close(); return sb.toString(); } //主页面 导出列表功能 public void exportProject(HttpServletResponse response) { try { ProjectVO params = new ProjectVO(); params.setSize(99999999999L); params.setCurrent(1L); params.setMyself(true); ProjectVO.Sort sort = new ProjectVO.Sort(); sort.setProp("create_time"); sort.setOrder("desc"); params.setSort(sort); IPage pageList = this.getPageList(params); List projectList = pageList.getRecords(); List> row = new ArrayList<>(); row.add(CollUtil.newArrayList("#", "名称", "委托方", "调查类型", "应用场景", "技术主题", "合同号", "委案日", "创建人")); for (int i = 0; i < projectList.size(); i++) { Project project = projectList.get(i); row.add(CollUtil.newArrayList(String.valueOf(i + 1), project.getName(), project.getClientName(), StringUtils.join(project.getTypeName(), ","), StringUtils.join(project.getScenarioName(), ","), project.getTechnicalTheme(), project.getContractNo(), project.getCaseDate(), project.getCreateName())); } List> rows = CollUtil.newArrayList(row); ExcelWriter writer = ExcelUtil.getWriter(true); OutputStream out = response.getOutputStream(); writer.write(rows, true); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); response.setHeader("Content-Disposition", "attachment;filename=" + IdUtil.simpleUUID() + ".xlsx"); writer.flush(out, true); writer.close(); IoUtil.close(out); } catch (Exception e) { e.printStackTrace(); } } }