12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205 |
- 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.UploadFileDTO;
- import cn.cslg.pas.common.model.params.*;
- import cn.cslg.pas.common.model.vo.*;
- import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
- import cn.cslg.pas.common.utils.*;
- import cn.cslg.pas.common.utils.SecurityUtils.SecurityUtils;
- import cn.cslg.pas.domain.*;
- import cn.cslg.pas.mapper.ProjectMapper;
- import cn.dev33.satoken.stp.StpUtil;
- 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.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.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.beans.factory.annotation.Autowired;
- 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;
- /**
- * <p>
- * 专题库表 服务实现类
- * </p>
- *
- * @author 王岩
- * @since 2022-01-24
- */
- @Service
- @RequiredArgsConstructor(onConstructor_ = {@Lazy})
- public class ProjectService extends ServiceImpl<ProjectMapper, Project> {
- 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;
- private final LoginUtils loginUtils;
- public Project getProjectByName(String name) {
- LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(Project::getName, name);
- queryWrapper.last("limit 1");
- return this.getOne(queryWrapper);
- }
- public IPage<Project> getPageList(ProjectVO params) {
- Map<String, Object> m = new HashMap<>();
- m.put("token", LoginUtils.getToken());
- m.put("loginId", loginUtils.getId());
- m.put("functionId", 8);
- PersonnelVO user = cacheUtils.getLoginUserPersonnel(loginUtils.getId());
- List<Integer> projectIds = new ArrayList<Integer>() {{
- add(-1);
- }};
- if (params.getMyself()) {
- projectIds.addAll(projectUserService.getProIdByUserId(loginUtils.getId()));
- }
- if (user.getUsername().equals(Constants.ADMIN_USERNAME)) {
- projectIds.addAll(projectService.list().stream().map(Project::getId).collect(Collectors.toList()));
- }
- params.setProIds(projectIds);
- params.setCreateBy(loginUtils.getId());
- SecurityUtils.startDataScope(m);
- IPage<Project> pageList = baseMapper.getPageList(new Page<>(params.getCurrent(), params.getSize()), params);
- List<Project> dataList = pageList.getRecords();
- // try {
- // Map<String, Object> map = new HashMap<>();
- // map.put("departmentId", dataList.stream().map(Project::getDepartmentId).collect(Collectors.toList()));
- // String jsonObject = apiUtils.invokeApi(new JSONObject(map), "/permission/api/system/getDepartmentById", "post", "data");
- // JSONArray jsonArray1 = JSON.parseArray(jsonObject);
- // List<ProjectVO.Department> departmentList = jsonArray1.toJavaList(ProjectVO.Department.class);
- // for (Project project : dataList) {
- // for (ProjectVO.Department department : departmentList) {
- // if (project.getDepartmentId().equals(department.getId())) {
- // project.setDepartmentName(department.getDepartmentName());
- // }
- // }
- // }
- //
- // Map<String, Object> map1 = new HashMap<>();
- // map1.put("personnelId", dataList.stream().map(Project::getPersonnelId).collect(Collectors.toList()));
- // String jsonObject1 = apiUtils.invokeApi(new JSONObject(map1), "/permission/api/system/getPersonnelById", "post", "data");
- // JSONArray jsonArray = JSON.parseArray(jsonObject1);
- // List<ProjectVO.Personnel> personnelList = jsonArray.toJavaList(ProjectVO.Personnel.class);
- // for (Project project : dataList) {
- // for (ProjectVO.Personnel personnel : personnelList) {
- // if (project.getPersonnelId().equals(personnel.getId())) {
- // project.setPersonnelName(personnel.getPersonnelName());
- // }
- // }
- // }
- // } catch (IOException e) {
- // e.printStackTrace();
- // }
- this.setDataList(dataList);
- pageList.setRecords(dataList);
- return pageList;
- }
- public List<Project> getProjectByIds(List<Integer> ids) {
- if (ids == null || ids.size() == 0) {
- return new ArrayList<>();
- }
- LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.in(Project::getId, ids);
- return this.list(queryWrapper);
- }
- public List<Project> getProjectByCreateId(Integer createBy) {
- LambdaQueryWrapper<Project> 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<Project> dataList) {
- List<SystemDict> 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<Project> getAllProjectByMySelf() {
- PersonnelVO user = cacheUtils.getLoginUserPersonnel(loginUtils.getId());
- LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
- List<Integer> proIds = new ArrayList<>();
- if (!user.getUsername().equals(Constants.ADMIN_USERNAME)) {
- proIds.addAll(projectUserService.getProIdByUserId(user.getId()));
- proIds.addAll(this.getProjectByCreateId(loginUtils.getId()).stream().map(Project::getId).collect(Collectors.toList()));
- if (proIds.size() != 0) {
- queryWrapper.in(Project::getId, proIds);
- } else {
- queryWrapper.eq(Project::getId, -1);
- }
- }
- List<Project> projectList = this.list(queryWrapper);
- this.setDataList(projectList);
- return projectList;
- }
- public Map<Object, Object> getProjectStatusTotal() {
- Map<Object, Object> map = new HashMap<>();
- List<Project> projectList = this.getAllProjectByMySelf();
- List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.ENTERPRISE_APPLICATION_SCENARIO));
- for (SystemDict systemDict : systemDictList) {
- Map<String, Object> result = new HashMap<>();
- List<Project> 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<String, Object> getProjectTypeTotal(String scenario) {
- Map<String, Object> map = new HashMap<>();
- List<Project> projectList = this.getAllProjectByMySelf();
- projectList = projectList.stream().filter(item -> item.getScenarioName().contains(scenario)).collect(Collectors.toList());
- List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.INVESTIGATION_TYPE));
- for (SystemDict systemDict : systemDictList) {
- Map<String, Object> result = new HashMap<>();
- map.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getTypeList().contains(Integer.parseInt(systemDict.getValue()))).count());
- }
- return map;
- }
- public Map<Object, Object> getScenarioAndTypeTotal() {
- List<Project> projectList = this.getAllProjectByMySelf();
- List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.ENTERPRISE_APPLICATION_SCENARIO, Constants.INVESTIGATION_TYPE));
- List<Client> clientList = clientService.getClientByObjectIds(this.getClientIds(projectList.stream().map(Project::getClientId).collect(Collectors.toList())));
- Map<Object, Object> type = new HashMap<>();
- Map<Object, Object> scenario = new HashMap<>();
- Map<Object, Object> result = new HashMap<>();
- Map<Object, Object> client = new HashMap<>();
- Map<Object, Object> 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<Object> getClientIds(List<Integer> clientIds) {
- Map<Object, Long> map = clientIds.stream().collect(Collectors.groupingBy(p -> p, Collectors.counting()));
- return map.entrySet().stream()
- .sorted((Map.Entry<Object, Long> o1, Map.Entry<Object, Long> 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(loginUtils.getId());
- 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, loginUtils.getId());
- 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.<Client>lambdaQuery().eq(Client::getName, name).last("limit 1"));
- if (client == null) {
- client = new Client();
- client.setName(name);
- client.setStatus(1);
- client.setCreateBy(loginUtils.getId());
- client.setCreateTime(DateUtils.getDateTime());
- client.insert();
- }
- return client.getId();
- }
- private void addProjectUser(Integer projectId) {
- ProjectUser user = new ProjectUser();
- user.setUserId(loginUtils.getId());
- user.setProjectId(projectId);
- user.setCreateTime(DateUtils.getDateTime());
- user.insert();
- }
- private void deleteProjectUser(Integer projectId, Integer userId) {
- projectUserService.remove(Wrappers.<ProjectUser>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<Map<String, Object>> readAll = reader.readAll();
- List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.INVESTIGATION_TYPE, Constants.ENTERPRISE_APPLICATION_SCENARIO));
- for (int i = 0; i < readAll.size(); i++) {
- Map<String, Object> 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(loginUtils.getId());
- project.setCreateTime(DateUtils.getDateTime());
- List<String> typeName = StringUtils.changeStringToString(row.get("调查类型").toString(), ";");
- List<Integer> 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<String> scenarioName = StringUtils.changeStringToString(row.get("企业应用场景").toString(), ";");
- List<Integer> 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<String> userName = StringUtils.changeStringToString(row.get("管理员").toString(), ";");
- List<User> userList = userService.getUserByNames(userName);
- List<ProjectUser> 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<Integer> 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<List<Object>> rowList = new ArrayList<>();
- List<Map<Object, Object>> 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(loginUtils.getId()));
- 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<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.PATENT_TYPE, Constants.PATENT_SIMPLE_STATUS));
- Map<String, PictureData> pictureDataMap = ExcelUtils.getDataFromExcel(params.getPath());
- for (int i = 0; i < params.getRowList().size(); i++) {
- Map<Object, Object> 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<String> patentApplicantCurrentName = new ArrayList<>();
- //原始申请(专利权)人
- List<String> patentApplicantOriginalName = new ArrayList<>();
- //[标]当前申请(专利权)人
- List<String> patentApplicantStandardCurrentName = new ArrayList<>();
- //[标]原始申请(专利权)人
- List<String> 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<String> 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<String> 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<String> fields = StringUtils.changeStringToString(key, ":");
- if (fields.size() == 2) {
- patentCustomFieldParams.put(key, PatentUtils.formatValue2(value.toString()));
- }
- break;
- }
- } else {
- List<String> 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<Integer> patentIds = StringUtils.changeStringToInteger(json, ",");
- List<Patent> 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<ProjectFile> 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<ProjectFile> 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<PatentImage> 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<String> patentNo = patentList.stream().map(Patent::getPatentNo).collect(Collectors.toList());
- List<PatentInstruction> 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<PatentApplicantLink> patentApplicantLinkList = patentApplicantLinkService.getApplicantAttributesListByPatentIds(patentIds);
- List<PatentApplicantMergeLink> patentApplicantMergeLinkList = patentApplicantMergeLinkService.getPatentApplicantMergeLinkListByProjectId(params.getProjectId());
- List<Integer> patentApplicantIds = new ArrayList<>();
- patentApplicantLinkList.forEach(item -> patentApplicantIds.add(item.getApplicantId()));
- patentApplicantMergeLinkList.forEach(item -> patentApplicantIds.add(item.getMergeId()));
- List<PatentApplicant> patentApplicantList = patentApplicantService.getPatentApplicantByIds(patentApplicantIds);
- List<PatentAffair> patentAffairList = patentAffairService.getPatentAffairListByPatentIds(patentIds);
- List<PatentAgency> patentAgencyList = patentAgencyService.getPatentAgencyByIds(patentList.stream().filter(item -> StringUtils.isNotEmpty(item.getAgencyId())).map(item -> Integer.parseInt(item.getAgencyId())).collect(Collectors.toList()));
- List<PatentAgentLink> patentAgentLinkList = patentAgentLinkService.getPatentAgentLinkByPatentIds(patentIds);
- List<PatentAgent> patentAgentList = patentAgentService.getPatentAgentByIds(patentAgentLinkList.stream().map(PatentAgentLink::getAgentId).collect(Collectors.toList()));
- List<PatentInstructionText> patentInstructionTextList = patentInstructionTextService.getPatentInstructionTextByPatentIds(patentIds);
- List<PatentInventorLink> patentInventorLinkList = patentInventorLinkService.getPatentInventorLinkByPatentIds(patentIds);
- List<PatentInventorMerge> patentInventorMergeList = patentInventorMergeService.getPatentInventorMergeByProjectId(params.getProjectId());
- List<Integer> patentInventorIds = new ArrayList<>();
- patentInventorLinkList.forEach(item -> patentInventorIds.add(item.getInventorId()));
- patentInventorMergeList.forEach(item -> patentInventorIds.add(item.getMergeId()));
- List<PatentInventor> patentInventorList = patentInventorService.getPatentInventorByIds(patentInventorIds);
- List<PatentLicensor> patentLicensorList = patentLicensorService.getPatentLicensorByPatentIds(patentIds);
- List<PatentPledge> patentPledgeList = patentPledgeService.getPatentPledgeByPatentIds(patentIds);
- List<PatentRight> patentRightList = patentRightService.getPatentRightByPatentIds(patentIds);
- List<Integer> patentFamilyIds = new ArrayList<>();
- patentList.forEach(item -> {
- patentFamilyIds.add(item.getSimpleFamily());
- patentFamilyIds.add(item.getInpadocFamily());
- patentFamilyIds.add(item.getPatSnapFamily());
- });
- List<PatentSimpleFamilyLink> patentSimpleFamilyLinkList = patentSimpleFamilyLinkService.getPatentSimpleFamilyLinkByFamilyIds(patentFamilyIds);
- List<PatentSimpleFamily> patentSimpleFamilyList = patentSimpleFamilyService.getPatentSimpleFamilyByIds(patentFamilyIds);
- List<PatentClassNumberLink> 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<PatentLabel> patentLabelList = patentLabelService.getPatentLabelByPatentIdsAndProjectId(patentIds, params.getProjectId());
- this.saveDataToJsonFile(tempPath, Constants.PATENT_LABEL_FILE_NAME, JsonUtils.objectToJson(patentLabelList));
- }
- List<ProjectField> projectFieldList = projectFieldService.getFieldListByIds(params.getPatentField());
- List<Integer> projectFieldIds = projectFieldList.stream().map(ProjectField::getId).collect(Collectors.toList());
- List<ProjectFieldOption> projectFieldOptionList = projectFieldOptionService.getFieldOptionList(projectFieldIds);
- List<ProjectFieldTree> projectFieldTreeList = projectFieldTreeService.getProjectFieldTreeOptionByFieldIds(projectFieldIds);
- List<ProjectFieldText> projectFieldTextList = projectFieldTextService.getProjectFieldTextByFieldIds(projectFieldIds);
- List<ProjectFieldPatentLink> 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<Patent> 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(false);
- ProjectVO.Sort sort = new ProjectVO.Sort();
- sort.setProp("create_time");
- sort.setOrder("desc");
- params.setSort(sort);
- IPage<Project> pageList = this.getPageList(params);
- List<Project> projectList = pageList.getRecords();
- List<List<String>> 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<List<String>> 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();
- }
- }
- }
|