ProjectService.java 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. package cn.cslg.pas.service;
  2. import cn.cslg.pas.common.core.base.Constants;
  3. import cn.cslg.pas.common.core.exception.CustomException;
  4. import cn.cslg.pas.common.model.PersonnelVO;
  5. import cn.cslg.pas.common.model.dto.TaskWebSocketDTO;
  6. import cn.cslg.pas.common.model.dto.UploadFileDTO;
  7. import cn.cslg.pas.common.model.vo.*;
  8. import cn.cslg.pas.common.utils.SecurityUtils.SecurityUtils;
  9. import cn.cslg.pas.domain.*;
  10. import cn.cslg.pas.common.utils.*;
  11. import cn.cslg.pas.common.model.params.*;
  12. import cn.cslg.pas.common.utils.ExcelUtils;
  13. import cn.cslg.pas.common.utils.WebSocketServer;
  14. import cn.cslg.pas.mapper.ProjectMapper;
  15. import cn.dev33.satoken.stp.StpUtil;
  16. import cn.cslg.pas.common.utils.PatentUtils;
  17. import cn.hutool.core.collection.CollUtil;
  18. import cn.hutool.core.collection.IterUtil;
  19. import cn.hutool.core.date.DateField;
  20. import cn.hutool.core.date.DateUtil;
  21. import cn.hutool.core.io.FileUtil;
  22. import cn.hutool.core.io.IoUtil;
  23. import cn.hutool.core.util.IdUtil;
  24. import cn.hutool.core.util.ZipUtil;
  25. import cn.hutool.extra.spring.SpringUtil;
  26. import cn.hutool.poi.excel.ExcelReader;
  27. import cn.hutool.poi.excel.ExcelUtil;
  28. import cn.hutool.poi.excel.ExcelWriter;
  29. import com.alibaba.fastjson2.JSONArray;
  30. import com.alibaba.fastjson2.JSONObject;
  31. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  32. import com.baomidou.mybatisplus.core.metadata.IPage;
  33. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  34. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  35. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  36. import lombok.RequiredArgsConstructor;
  37. import org.apache.poi.ss.usermodel.PictureData;
  38. import org.springframework.beans.BeanUtils;
  39. import org.springframework.context.annotation.Lazy;
  40. import org.springframework.scheduling.annotation.Async;
  41. import org.springframework.stereotype.Service;
  42. import org.springframework.transaction.annotation.Propagation;
  43. import org.springframework.transaction.annotation.Transactional;
  44. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  45. import org.springframework.web.multipart.MultipartFile;
  46. import javax.servlet.http.HttpServletResponse;
  47. import java.io.*;
  48. import java.nio.charset.StandardCharsets;
  49. import java.util.*;
  50. import java.util.stream.Collectors;
  51. /**
  52. * <p>
  53. * 专题库表 服务实现类
  54. * </p>
  55. *
  56. * @author 王岩
  57. * @since 2022-01-24
  58. */
  59. @Service
  60. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  61. public class ProjectService extends ServiceImpl<ProjectMapper, Project> {
  62. private final ClientService clientService;
  63. private final ProjectUserService projectUserService;
  64. private final PatentService patentService;
  65. private final PatentApplicantService patentApplicantService;
  66. private final PatentAgencyService patentAgencyService;
  67. private final PatentAgentService patentAgentService;
  68. private final PatentAgentLinkService patentAgentLinkService;
  69. private final PatentLicensorService patentLicensorService;
  70. private final PatentPledgeService patentPledgeService;
  71. private final PatentAffairService patentAffairService;
  72. private final PatentApplicantLinkService patentApplicantLinkService;
  73. private final PatentApplicantMergeLinkService patentApplicantMergeLinkService;
  74. private final PatentInventorService patentInventorService;
  75. private final PatentInventorLinkService patentInventorLinkService;
  76. private final PatentSimpleFamilyService patentSimpleFamilyService;
  77. private final PatentSimpleFamilyLinkService patentSimpleFamilyLinkService;
  78. private final PatentClassNumberService patentClassNumberService;
  79. private final PatentClassNumberLinkService patentClassNumberLinkService;
  80. private final ProjectPatentLinkService projectPatentLinkService;
  81. private final TaskService taskService;
  82. private final PatentImageService patentImageService;
  83. private final ProjectFieldPatentLinkService projectFieldPatentLinkService;
  84. private final ProjectFolderService projectFolderService;
  85. private final ProjectFolderPatentLinkService projectFolderPatentLinkService;
  86. private final ProjectFieldService projectFieldService;
  87. private final ProjectFieldOptionService projectFieldOptionService;
  88. private final ProjectFieldTreeService projectFieldTreeService;
  89. private final ProjectFieldTextService projectFieldTextService;
  90. private final ProjectFileService projectFileService;
  91. private final SystemDictService systemDictService;
  92. private final PatentInstructionService patentInstructionService;
  93. private final PatentInstructionTextService patentInstructionTextService;
  94. private final PatentRightService patentRightService;
  95. private final FileUtils fileUtils;
  96. private final PatentLabelService patentLabelService;
  97. private final CacheUtils cacheUtils;
  98. private final ProjectExportService projectExportService;
  99. private final ProjectService projectService;
  100. private final PatentInventorMergeService patentInventorMergeService;
  101. private final UserService userService;
  102. private final ApiUtils apiUtils;
  103. public Project getProjectByName(String name) {
  104. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  105. queryWrapper.eq(Project::getName, name);
  106. queryWrapper.last("limit 1");
  107. return this.getOne(queryWrapper);
  108. }
  109. public IPage<Project> getPageList(ProjectVO params) {
  110. Map<String,Object> m =new HashMap<>();
  111. m.put("token",params.getToken());
  112. m.put("loginId",4);
  113. m.put("functionId",8);
  114. PersonnelVO user = cacheUtils.getLoginUserPersonnel(3);
  115. List<Integer> projectIds = new ArrayList<Integer>() {{
  116. add(-1);
  117. }};
  118. if (params.getMyself()) {
  119. projectIds.addAll(projectUserService.getProIdByUserId(3));
  120. }
  121. if (user.getUsername().equals(Constants.ADMIN_USERNAME)) {
  122. projectIds.addAll(projectService.list().stream().map(Project::getId).collect(Collectors.toList()));
  123. }
  124. params.setProIds(projectIds);
  125. params.setCreateBy(3);
  126. SecurityUtils.startDataScope(m);
  127. IPage<Project> pageList = baseMapper.getPageList(new Page<>(params.getCurrent(), params.getSize()), params);
  128. List<Project> dataList = pageList.getRecords();
  129. Map<String, Object> map = new HashMap<>();
  130. map.put("departmentId", dataList.stream().map(Project::getDepartmentId).collect(Collectors.toList()));
  131. // try {
  132. // JSONArray jsonObject = apiUtils.invokeApi(new JSONObject(map), "/permission/api/system/getDepartmentById", "post", "data");
  133. // for (int i = 0; i < dataList.size(); i++) {
  134. // dataList.get(i).setDepartmentName((String) jsonObject.get(i));
  135. // }
  136. // } catch (IOException e) {
  137. // e.printStackTrace();
  138. // }
  139. // this.setDataList(dataList);
  140. // pageList.setRecords(dataList);
  141. return pageList;
  142. }
  143. public List<Project> getProjectByIds(List<Integer> ids) {
  144. if (ids == null || ids.size() == 0) {
  145. return new ArrayList<>();
  146. }
  147. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  148. queryWrapper.in(Project::getId, ids);
  149. return this.list(queryWrapper);
  150. }
  151. public List<Project> getProjectByCreateId(Integer createBy) {
  152. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  153. queryWrapper.eq(Project::getCreateBy, createBy);
  154. return this.list(queryWrapper);
  155. }
  156. public Project getProjectById(Integer id) {
  157. Project project = this.getById(id);
  158. Client client = clientService.getById(project.getClientId());
  159. if (client != null) {
  160. project.setClientName(client.getName());
  161. }
  162. return project;
  163. }
  164. private void setDataList(List<Project> dataList) {
  165. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.ENTERPRISE_APPLICATION_SCENARIO, Constants.INVESTIGATION_TYPE));
  166. dataList.forEach(item -> {
  167. if (StringUtils.isNotEmpty(item.getScenario())) {
  168. item.setScenarioList(StringUtils.changeStringToInteger(item.getScenario(), ","));
  169. 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()));
  170. item.setScenario(null);
  171. }
  172. if (StringUtils.isNotEmpty(item.getType())) {
  173. item.setTypeList(StringUtils.changeStringToInteger(item.getType(), ","));
  174. 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()));
  175. item.setType(null);
  176. }
  177. });
  178. }
  179. public List<Project> getAllProjectByMySelf() {
  180. User user = cacheUtils.getLoginUser(3);
  181. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  182. List<Integer> proIds = new ArrayList<>();
  183. if (!user.getUsername().equals(Constants.ADMIN_USERNAME)) {
  184. proIds.addAll(projectUserService.getProIdByUserId(user.getId()));
  185. proIds.addAll(this.getProjectByCreateId(3).stream().map(Project::getId).collect(Collectors.toList()));
  186. if (proIds.size() != 0) {
  187. queryWrapper.in(Project::getId, proIds);
  188. } else {
  189. queryWrapper.eq(Project::getId, -1);
  190. }
  191. }
  192. List<Project> projectList = this.list(queryWrapper);
  193. this.setDataList(projectList);
  194. return projectList;
  195. }
  196. public Map<Object, Object> getProjectStatusTotal() {
  197. Map<Object, Object> map = new HashMap<>();
  198. List<Project> projectList = this.getAllProjectByMySelf();
  199. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.ENTERPRISE_APPLICATION_SCENARIO));
  200. for (SystemDict systemDict : systemDictList) {
  201. Map<String, Object> result = new HashMap<>();
  202. List<Project> tempList = projectList.stream().filter(item -> item.getScenarioList().contains(Integer.parseInt(systemDict.getValue()))).collect(Collectors.toList());
  203. result.put("completed", tempList.stream().filter(item -> item.getStatus().equals("1")).count());
  204. result.put("unfinished", tempList.stream().filter(item -> item.getStatus().equals("0")).count());
  205. map.put(systemDict.getLabel(), result);
  206. }
  207. return map;
  208. }
  209. public Map<String, Object> getProjectTypeTotal(String scenario) {
  210. Map<String, Object> map = new HashMap<>();
  211. List<Project> projectList = this.getAllProjectByMySelf();
  212. projectList = projectList.stream().filter(item -> item.getScenarioName().contains(scenario)).collect(Collectors.toList());
  213. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.INVESTIGATION_TYPE));
  214. for (SystemDict systemDict : systemDictList) {
  215. Map<String, Object> result = new HashMap<>();
  216. map.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getTypeList().contains(Integer.parseInt(systemDict.getValue()))).count());
  217. }
  218. return map;
  219. }
  220. public Map<Object, Object> getScenarioAndTypeTotal() {
  221. List<Project> projectList = this.getAllProjectByMySelf();
  222. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.ENTERPRISE_APPLICATION_SCENARIO, Constants.INVESTIGATION_TYPE));
  223. List<Client> clientList = clientService.getClientByObjectIds(this.getClientIds(projectList.stream().map(Project::getClientId).collect(Collectors.toList())));
  224. Map<Object, Object> type = new HashMap<>();
  225. Map<Object, Object> scenario = new HashMap<>();
  226. Map<Object, Object> result = new HashMap<>();
  227. Map<Object, Object> client = new HashMap<>();
  228. Map<Object, Object> create = new HashMap<>();
  229. systemDictList.forEach(systemDict -> {
  230. switch (systemDict.getType()) {
  231. case Constants.ENTERPRISE_APPLICATION_SCENARIO:
  232. scenario.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getScenarioList().contains(Integer.parseInt(systemDict.getValue()))).count());
  233. break;
  234. case Constants.INVESTIGATION_TYPE:
  235. type.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getTypeList().contains(Integer.parseInt(systemDict.getValue()))).count());
  236. break;
  237. }
  238. });
  239. clientList.forEach(item -> client.put(item.getName(), projectList.stream().filter(project -> project.getClientId().equals(item.getId())).count()));
  240. Date date = DateUtil.date();
  241. for (int i = 0; i < 6; i++) {
  242. Date finalDate = date;
  243. 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());
  244. date = DateUtil.offset(date, DateField.MONTH, -1);
  245. }
  246. result.put("scenario", scenario);
  247. result.put("type", type);
  248. result.put("client", client);
  249. result.put("create", create);
  250. return result;
  251. }
  252. private List<Object> getClientIds(List<Integer> clientIds) {
  253. Map<Object, Long> map = clientIds.stream().collect(Collectors.groupingBy(p -> p, Collectors.counting()));
  254. return map.entrySet().stream()
  255. .sorted((Map.Entry<Object, Long> o1, Map.Entry<Object, Long> o2) -> o2.getValue().intValue() - o1.getValue().intValue())
  256. .map(Map.Entry::getKey).collect(Collectors.toList())
  257. .subList(0, Math.min(map.size(), 10));
  258. }
  259. public String getImportProjectName(String name) {
  260. String tempName = name + "(1)";
  261. Project project1 = this.getProjectByName(name);
  262. if (project1 == null) {
  263. return name;
  264. }
  265. Project project2 = this.getProjectByName(tempName);
  266. if (project2 != null) {
  267. tempName = this.getImportProjectName(tempName);
  268. }
  269. return tempName;
  270. }
  271. public Integer importProject(Integer projectId, String json, Integer userId) {
  272. if ((projectId == null || projectId.equals(0)) && StringUtils.isEmpty(json)) {
  273. return 0;
  274. }
  275. if (StringUtils.isEmpty(json)) {
  276. return projectId;
  277. }
  278. Project temp = this.getById(projectId);
  279. Project data = JsonUtils.jsonToPojo(json, Project.class);
  280. Client client = clientService.getClientByName(data.getClientName());
  281. if (client == null) {
  282. client = new Client();
  283. client.setName(data.getClientName());
  284. client.setStatus(1);
  285. client.setCreateBy(userId);
  286. client.setCreateTime(DateUtils.getDateTime());
  287. client.insert();
  288. }
  289. if (temp == null) {
  290. temp = new Project();
  291. }
  292. String projectName = temp.getName();
  293. BeanUtils.copyProperties(data, temp);
  294. if (projectName == null || !projectName.equals(data.getName())) {
  295. temp.setName(this.getImportProjectName(temp.getName()));
  296. }
  297. temp.setClientId(client.getId());
  298. if (projectId == null || projectId.equals(0)) {
  299. temp.setCreateBy(userId);
  300. temp.setCreateTime(DateUtils.getDateTime());
  301. temp.setId(null);
  302. } else {
  303. temp.setId(projectId);
  304. }
  305. temp.insertOrUpdate();
  306. return temp.getId();
  307. }
  308. @Transactional
  309. public String add(Project project) {
  310. Project temp = this.getProjectByName(project.getName());
  311. if (temp != null) {
  312. return Response.error("专题库名称已存在");
  313. }
  314. if (project.getClientId() == -1) {
  315. project.setClientId(this.getNewClientId(project.getClientName()));
  316. }
  317. project.setScenario(StringUtils.join(project.getScenarioList(), ","));
  318. project.setType(StringUtils.join(project.getTypeList(), ","));
  319. project.setCreateBy(StpUtil.getLoginIdAsInt());
  320. project.setCreateTime(DateUtils.getDateTime());
  321. project.insert();
  322. this.addProjectUser(project.getId());
  323. return Response.success(project.getId());
  324. }
  325. @Transactional
  326. public String edit(Project project) {
  327. Project temp = this.getProjectByName(project.getName());
  328. if (temp != null && !temp.getId().equals(project.getId())) {
  329. return Response.error("专题库名称已存在");
  330. }
  331. if (project.getClientId() == -1) {
  332. project.setClientId(this.getNewClientId(project.getClientName()));
  333. }
  334. project.setScenario(StringUtils.join(project.getScenarioList(), ","));
  335. project.setType(StringUtils.join(project.getTypeList(), ","));
  336. project.updateById();
  337. return Response.success();
  338. }
  339. @Transactional
  340. public String delete(Integer id) {
  341. this.removeById(id);
  342. this.deleteProjectUser(id, StpUtil.getLoginIdAsInt());
  343. projectPatentLinkService.deleteByProjectId(id);
  344. projectFolderService.deleteByProjectId(id);
  345. projectFieldService.deleteByProjectId(id);
  346. projectUserService.deleteByProjectId(id);
  347. projectFileService.deleteByProjectId(id);
  348. patentApplicantMergeLinkService.deleteByProjectId(id);
  349. return Response.success();
  350. }
  351. private Integer getNewClientId(String name) {
  352. Client client = clientService.getOne(Wrappers.<Client>lambdaQuery().eq(Client::getName, name).last("limit 1"));
  353. if (client == null) {
  354. client = new Client();
  355. client.setName(name);
  356. client.setStatus(1);
  357. client.setCreateBy(StpUtil.getLoginIdAsInt());
  358. client.setCreateTime(DateUtils.getDateTime());
  359. client.insert();
  360. }
  361. return client.getId();
  362. }
  363. private void addProjectUser(Integer projectId) {
  364. ProjectUser user = new ProjectUser();
  365. user.setUserId(StpUtil.getLoginIdAsInt());
  366. user.setProjectId(projectId);
  367. user.setCreateTime(DateUtils.getDateTime());
  368. user.insert();
  369. }
  370. private void deleteProjectUser(Integer projectId, Integer userId) {
  371. projectUserService.remove(Wrappers.<ProjectUser>lambdaQuery().eq(ProjectUser::getUserId, userId).eq(ProjectUser::getProjectId, projectId));
  372. }
  373. @Transactional(rollbackFor = Exception.class)
  374. public String importExcel(MultipartFile file) {
  375. try {
  376. ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
  377. List<Map<String, Object>> readAll = reader.readAll();
  378. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.INVESTIGATION_TYPE, Constants.ENTERPRISE_APPLICATION_SCENARIO));
  379. for (int i = 0; i < readAll.size(); i++) {
  380. Map<String, Object> row = readAll.get(i);
  381. Project project = new Project();
  382. project.setSort(1);
  383. project.setName(row.get("专题库名称").toString());
  384. project.setClientId(this.getNewClientId(row.get("委托方").toString()));
  385. project.setRemark(row.get("备注").toString());
  386. project.setCreateBy(StpUtil.getLoginIdAsInt());
  387. project.setCreateTime(DateUtils.getDateTime());
  388. List<String> typeName = StringUtils.changeStringToString(row.get("调查类型").toString(), ";");
  389. 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());
  390. project.setType(StringUtils.join(typeList, ","));
  391. List<String> scenarioName = StringUtils.changeStringToString(row.get("企业应用场景").toString(), ";");
  392. 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());
  393. project.setScenario(StringUtils.join(scenarioList, ","));
  394. project.setTechnicalTheme(row.get("技术主题").toString());
  395. project.setContractNo(row.get("合同号").toString());
  396. project.setInnerFile(row.get("内部案卷").toString());
  397. Object caseDate = row.get("委案日");
  398. if (StringUtils.isNotNull(caseDate)) {
  399. project.setCaseDate(caseDate.toString());
  400. }
  401. project.setStatus(row.get("处理状态").toString().equals("处理中") ? "0" : "1");
  402. Object update = row.get("是否更新");
  403. if (StringUtils.isNotNull(update)) {
  404. project.setUpdate(update.toString().equals("是") ? 1 : 0);
  405. project.setUpdateTime(row.get("更新周期").toString());
  406. } else {
  407. project.setUpdate(0);
  408. project.setUpdateTime("一天");
  409. }
  410. project.insert();
  411. List<String> userName = StringUtils.changeStringToString(row.get("管理员").toString(), ";");
  412. List<User> userList = userService.getUserByNames(userName);
  413. List<ProjectUser> projectUserList = new ArrayList<>();
  414. userList.forEach(item -> {
  415. ProjectUser projectUser = new ProjectUser();
  416. projectUser.setProjectId(project.getId());
  417. projectUser.setUserId(item.getId());
  418. projectUser.setCreateTime(DateUtils.getDateTime());
  419. projectUser.setType(2);
  420. projectUserList.add(projectUser);
  421. });
  422. projectUserService.saveOrUpdateBatch(projectUserList);
  423. }
  424. return Response.success(true);
  425. } catch (Exception e) {
  426. e.printStackTrace();
  427. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  428. return Response.error();
  429. }
  430. }
  431. @Transactional
  432. public String share(Integer id, List<Integer> userIds) {
  433. ProjectUser user = new ProjectUser();
  434. user.setType(3);
  435. user.setRemark("用户分享");
  436. user.setProjectId(id);
  437. user.setUserIds(userIds);
  438. return projectUserService.add(user);
  439. }
  440. public TaskParams getImportPatentTaskParams(MultipartFile file, Integer projectId) {
  441. UploadFileDTO fileDTO = fileUtils.uploadFile(file);
  442. String path = fileUtils.getPath(fileDTO.getPath());
  443. List<List<Object>> rowList = new ArrayList<>();
  444. List<Map<Object, Object>> mapList = new ArrayList<>();
  445. ExcelUtil.readBySax(path, -1, (sheetIndex, rowIndex, row) -> rowList.add(row));
  446. for (int i = 1; i < rowList.size(); i++) {
  447. mapList.add(IterUtil.toMap(rowList.get(0), rowList.get(i)));
  448. }
  449. Integer taskId = taskService.add(fileDTO, projectId, rowList.size() - 1, 1, 0, file.getOriginalFilename());
  450. TaskParams taskParams = new TaskParams();
  451. taskParams.setTaskId(taskId);
  452. taskParams.setPath(path);
  453. taskParams.setTaskType(1);
  454. taskParams.setRowList(mapList);
  455. taskParams.setUserId(String.valueOf(StpUtil.getLoginIdAsInt()));
  456. taskParams.setOldName(file.getOriginalFilename());
  457. return taskParams;
  458. }
  459. @Async("singleThreadAsyncTaskExecutor")
  460. @Transactional(rollbackFor = Exception.class)
  461. public void importPatent(TaskParams params, ProjectImportPatentVO projectImportPatentVO) {
  462. Integer total = params.getRowList().size();
  463. try {
  464. if (projectImportPatentVO != null) {
  465. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.PATENT_TYPE, Constants.PATENT_SIMPLE_STATUS));
  466. Map<String, PictureData> pictureDataMap = ExcelUtils.getDataFromExcel(params.getPath());
  467. for (int i = 0; i < params.getRowList().size(); i++) {
  468. Map<Object, Object> row = params.getRowList().get(i);
  469. Object patentNo = row.get("公开(公告)号");
  470. if (StringUtils.isNotNull(patentNo)) {
  471. PatentCustomFieldParams patentCustomFieldParams = new PatentCustomFieldParams();
  472. //用专利号查找专利的相关信息 并装配到 Patent 中
  473. Patent patent = patentService.getByPatentNo(patentNo.toString());
  474. //法律状态/事件|INPADOC法律状态|法律状态更新时间|简单法律状态
  475. PatentAffairParams patentAffairParams = new PatentAffairParams();
  476. //当前申请(专利权)人
  477. List<String> patentApplicantCurrentName = new ArrayList<>();
  478. //原始申请(专利权)人
  479. List<String> patentApplicantOriginalName = new ArrayList<>();
  480. //[标]当前申请(专利权)人
  481. List<String> patentApplicantStandardCurrentName = new ArrayList<>();
  482. //[标]原始申请(专利权)人
  483. List<String> patentApplicantStandardOriginalName = new ArrayList<>();
  484. //发明人|第一发明人
  485. PatentInventorParams patentInventorParams = new PatentInventorParams();
  486. //简单同族|PatSnap同族|INPADOC同族
  487. PatentSimpleFamilyParams patentSimpleFamilyParams = new PatentSimpleFamilyParams();
  488. //IPC分类号|UPC分类号|LOC分类号|CPC分类号|IPC主分类号|UPC主分类号
  489. PatentClassNumberParams patentClassNumberParams = new PatentClassNumberParams();
  490. //许可人|被许可人|许可类型
  491. PatentLicensorParams patentLicensorParams = new PatentLicensorParams();
  492. //质押人|质权人
  493. PatentPledgeParams patentPledgeParams = new PatentPledgeParams();
  494. //代理人
  495. PatentAgentParams patentAgentParams = new PatentAgentParams();
  496. //当前申请(专利权)人地址|当前申请(专利权)人国家|当前第一申请(专利权)人地址|原始申请(专利权)人地址|原始申请(专利权)人国家
  497. PatentApplicantAddressParams patentApplicantAddressParams = new PatentApplicantAddressParams();
  498. //发明人地址|第一发明人地址
  499. PatentInventorAddressParams patentInventorAddressParams = new PatentInventorAddressParams();
  500. //说明书|说明书(译)
  501. PatentInstructionTextParams patentInstructionTextParams = new PatentInstructionTextParams();
  502. //权利要求|独立权利要求|权利要求(译)
  503. PatentRightParams patentRightParams = new PatentRightParams();
  504. //标签
  505. PatentLabelParams patentLabelParams = new PatentLabelParams();
  506. if (patent == null) {
  507. patent = new Patent();
  508. patent.setPatentNo(patentNo.toString());
  509. patent.setPublicNo(patentNo.toString());
  510. patent.insert();
  511. }
  512. patentAffairParams.setPatentId(patent.getId());
  513. patentInventorParams.setPatentId(patent.getId());
  514. patentSimpleFamilyParams.setPatentId(patent.getId());
  515. patentSimpleFamilyParams.setPatentNo(patent.getPatentNo());
  516. patentClassNumberParams.setPatentId(patent.getId());
  517. patentCustomFieldParams.setPatentId(patent.getId());
  518. patentCustomFieldParams.setProjectId(projectImportPatentVO.getProjectId());
  519. patentCustomFieldParams.setUserId(Integer.parseInt(params.getUserId()));
  520. patentLicensorParams.setPatentId(patent.getId());
  521. patentPledgeParams.setPatentId(patent.getId());
  522. patentAgentParams.setPatentId(patent.getId());
  523. patentApplicantAddressParams.setPatentId(patent.getId());
  524. patentInventorAddressParams.setPatentId(patent.getId());
  525. patentInstructionTextParams.setPatentId(patent.getId());
  526. patentRightParams.setPatentId(patent.getId());
  527. patentRightParams.setPatentNo(patent.getPatentNo());
  528. patentLabelParams.setPatentId(patent.getId());
  529. patentLabelParams.setProjectId(projectImportPatentVO.getProjectId());
  530. for (Object object : row.keySet()) {
  531. String key = object.toString();
  532. if (key.equals("摘要附图")) {
  533. PictureData pictureData = pictureDataMap.get(String.valueOf(i + 1));
  534. if (pictureData != null) {
  535. //1.先把Excel里的图片存到文件夹里 路径大致是 ../target/file/时间/文件.png 2.生成完文件并存完后 将文件的路径和名称存到表里 OS_PATENT_IMAGE 然后最终得到摘要图片的存储路径
  536. String abstractPath = patentImageService.updatePatentImage(patent.getId(), pictureData);
  537. //将路径进行装配
  538. patent.setAbstractPath(abstractPath);
  539. }
  540. }
  541. Object value = row.get(key);
  542. if (StringUtils.isNotNull(value) && !value.equals("") && !value.equals("-") && !value.equals("\\")) {
  543. switch (key) {
  544. case "标题":
  545. List<String> titles = StringUtils.changeStringToString(value.toString(), " \\| ");
  546. if (titles.size() == 2) {
  547. patent.setName(titles.get(0));
  548. patent.setNameOut(titles.get(1));
  549. } else {
  550. patent.setName(value.toString());
  551. }
  552. break;
  553. case "摘要":
  554. List<String> abstracts = StringUtils.changeStringToString(value.toString(), " \\| ");
  555. if (abstracts.size() == 2) {
  556. patent.setAbstractStr(abstracts.get(0));
  557. patent.setAbstractOut(abstracts.get(1));
  558. } else {
  559. patent.setAbstractStr(value.toString());
  560. }
  561. break;
  562. case "公开(公告)日":
  563. patent.setPublicDate(DateUtils.getDateTime(value.toString()));
  564. break;
  565. case "当前申请(专利权)人":
  566. patentApplicantCurrentName.addAll(PatentUtils.formatValue(value.toString()));
  567. break;
  568. case "当前申请(专利权)人地址":
  569. //patentApplicantAddressParams.setCurrentAddress(value.toString());
  570. break;
  571. case "当前申请(专利权)人国家":
  572. //patentApplicantAddressParams.setCurrentCountry(value.toString());
  573. break;
  574. case "[标]当前申请(专利权)人":
  575. patentApplicantStandardCurrentName.addAll(PatentUtils.formatValue(value.toString()));
  576. break;
  577. case "法律状态/事件":
  578. //patentAffairParams.setStatusList(PatentUtils.formatValue(value.toString()));
  579. break;
  580. case "INPADOC法律状态":
  581. patentAffairParams.setContent(value.toString());
  582. break;
  583. case "法律状态更新时间":
  584. patentAffairParams.setDateTime(DateUtils.getDateTime(value.toString()));
  585. break;
  586. case "简单法律状态":
  587. 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());
  588. patent.setSimpleStatus(simpleStatus);
  589. patentAffairParams.setSimpleStatus(simpleStatus);
  590. break;
  591. case "申请号":
  592. patent.setApplicationNo(value.toString());
  593. break;
  594. case "文献代码":
  595. patent.setCode(value.toString());
  596. break;
  597. case "受理局":
  598. patent.setBureau(value.toString());
  599. break;
  600. case "申请日":
  601. patent.setApplicationDate(DateUtils.getDateTime(value.toString()));
  602. break;
  603. case "摘要(译)":
  604. patent.setAbstractOut(value.toString());
  605. break;
  606. case "标题(译)":
  607. patent.setNameOut(value.toString());
  608. break;
  609. case "专利类型":
  610. Integer type = Integer.parseInt(systemDictList.stream().filter(systemDict -> systemDict.getType().equals(Constants.PATENT_TYPE) && systemDict.getLabel().equals(value.toString())).findFirst().orElse(new SystemDict()).getValue());
  611. patent.setType(type);
  612. break;
  613. case "说明书":
  614. patentInstructionTextParams.setManual(value.toString());
  615. break;
  616. case "说明书(译)":
  617. patentInstructionTextParams.setManualOut(value.toString());
  618. break;
  619. case "文献页数":
  620. patent.setDocPage(Integer.parseInt(value.toString()));
  621. break;
  622. case "首次公开日":
  623. patent.setFirstPublicDate(DateUtils.getDateTime(value.toString()));
  624. break;
  625. case "当前第一申请(专利权)人":
  626. break;
  627. case "当前申请(专利权)人数量":
  628. patent.setApplicantNum(Integer.parseInt(value.toString()));
  629. break;
  630. case "当前第一申请(专利权)人地址":
  631. patentApplicantAddressParams.setFirstCurrentAddress(value.toString());
  632. break;
  633. case "发明人地址":
  634. patentInventorAddressParams.setAddress(PatentUtils.formatValue(value.toString()));
  635. break;
  636. case "第一发明人地址":
  637. patentInventorAddressParams.setFirstAddress(value.toString());
  638. break;
  639. case "原始申请(专利权)人":
  640. patentApplicantOriginalName.addAll(PatentUtils.formatValue(value.toString()));
  641. break;
  642. case "原始申请(专利权)人地址":
  643. //patentApplicantAddressParams.setOriginalAddress(value.toString());
  644. break;
  645. case "原始申请(专利权)人国家":
  646. //patentApplicantAddressParams.setOriginalCountry(value.toString());
  647. break;
  648. case "[标]原始申请(专利权)人":
  649. patentApplicantStandardOriginalName.addAll(PatentUtils.formatValue(value.toString()));
  650. break;
  651. case "发明人":
  652. patentInventorParams.setNameList(PatentUtils.formatValue(value.toString()));
  653. break;
  654. case "第一发明人":
  655. patentInventorParams.setFirstName(value.toString());
  656. break;
  657. case "发明人数量":
  658. patent.setInventorNum(Integer.parseInt(value.toString()));
  659. break;
  660. case "权利要求":
  661. patentRightParams.setContent(value.toString());
  662. break;
  663. case "独立权利要求":
  664. patentRightParams.setSelfContent(value.toString());
  665. break;
  666. case "权利要求(译)":
  667. patentRightParams.setContentOut(value.toString());
  668. break;
  669. case "权利要求数量":
  670. // if ("该数据不支持导出".equals(value.toString())) {
  671. // patent.setSelfRightContentNum(0);
  672. // } else {
  673. //
  674. // }
  675. patent.setSelfRightContentNum(Integer.parseInt(value.toString()));
  676. break;
  677. case "IPC分类号":
  678. patentClassNumberParams.setIpcList(PatentUtils.formatValue(value.toString()));
  679. break;
  680. case "UPC分类号":
  681. patentClassNumberParams.setUpcList(PatentUtils.formatValue(value.toString()));
  682. break;
  683. case "LOC分类号":
  684. patentClassNumberParams.setLocList(PatentUtils.formatValue(value.toString()));
  685. break;
  686. case "CPC分类号":
  687. patentClassNumberParams.setCpcList(PatentUtils.formatValue(value.toString()));
  688. break;
  689. case "IPC主分类号":
  690. patentClassNumberParams.setMainIpc(value.toString());
  691. break;
  692. case "UPC主分类号":
  693. patentClassNumberParams.setMainUpc(value.toString());
  694. break;
  695. case "简单同族":
  696. patentSimpleFamilyParams.setSimpleFamily(PatentUtils.formatValue(value.toString()));
  697. break;
  698. case "简单同族成员数量":
  699. patent.setSimpleFamilyNum(Integer.parseInt(value.toString()));
  700. break;
  701. case "PatSnap同族":
  702. patentSimpleFamilyParams.setPatSnapFamily(PatentUtils.formatValue(value.toString()));
  703. break;
  704. case "PatSnap同族成员数量":
  705. patent.setPatSnapFamilyNum(Integer.parseInt(value.toString()));
  706. break;
  707. case "INPADOC同族":
  708. patentSimpleFamilyParams.setInpadocFamily(PatentUtils.formatValue(value.toString()));
  709. break;
  710. case "INPADOC同族成员数量":
  711. patent.setInpadocFamilyNum(Integer.parseInt(value.toString()));
  712. break;
  713. case "优先权号":
  714. patent.setPriorityNo(value.toString());
  715. break;
  716. case "授权日":
  717. patent.setPublicAccreditDate(DateUtils.getDateTime(value.toString()));
  718. break;
  719. case "优先权国家":
  720. patent.setPriorityCountry(value.toString());
  721. break;
  722. case "优先权日":
  723. patent.setPriorityDate(DateUtils.getDateTime(value.toString()));
  724. break;
  725. case "非专利引用文献":
  726. patent.setNotPatentQuote(value.toString());
  727. break;
  728. case "非专利引用文献数量":
  729. patent.setNotPatentQuoteNum(Integer.parseInt(value.toString()));
  730. break;
  731. case "被引用专利":
  732. patent.setQuoted(value.toString());
  733. break;
  734. case "被引用专利数量":
  735. patent.setQuotedNum(Integer.parseInt(value.toString()));
  736. break;
  737. case "引用专利":
  738. patent.setQuote(value.toString());
  739. break;
  740. case "引用专利数量":
  741. patent.setQuoteNum(Integer.parseInt(value.toString()));
  742. break;
  743. case "3年内被引用次数":
  744. patent.setQuotedNum3(Integer.parseInt(value.toString()));
  745. break;
  746. case "5年内被引用次数":
  747. patent.setQuotedNum5(Integer.parseInt(value.toString()));
  748. break;
  749. case "许可人":
  750. patentLicensorParams.setLicensor(PatentUtils.getPatentLicensor(value.toString()));
  751. break;
  752. case "被许可人":
  753. patentLicensorParams.setLicensee(PatentUtils.getPatentLicensor(value.toString()));
  754. break;
  755. case "许可类型":
  756. patentLicensorParams.setType(PatentUtils.getPatentLicensor(value.toString()));
  757. break;
  758. case "质押人":
  759. patentPledgeParams.setPledgor(PatentUtils.getPatentLicensor(value.toString()));
  760. break;
  761. case "质权人":
  762. patentPledgeParams.setPledgee(PatentUtils.getPatentLicensor(value.toString()));
  763. break;
  764. case "EP指定国状态":
  765. patent.setEpStatus(value.toString());
  766. break;
  767. case "WO国家阶段":
  768. patent.setWo(value.toString());
  769. break;
  770. case "代理机构":
  771. patent.setAgencyId(patentAgencyService.getAgencyStringIdByName(value.toString()));
  772. break;
  773. case "代理人":
  774. patentAgentParams.setAgent(PatentUtils.formatValue(value.toString()));
  775. break;
  776. case "审查员":
  777. patent.setExaminer(value.toString());
  778. break;
  779. case "助理审查员":
  780. patent.setAidExaminer(value.toString());
  781. break;
  782. case "标签":
  783. patentLabelParams.setLabel(PatentUtils.formatValue2(value.toString()));
  784. break;
  785. default:
  786. List<String> fields = StringUtils.changeStringToString(key, ":");
  787. if (fields.size() == 2) {
  788. patentCustomFieldParams.put(key, PatentUtils.formatValue2(value.toString()));
  789. }
  790. break;
  791. }
  792. } else {
  793. List<String> fields = StringUtils.changeStringToString(key, ":");
  794. if (fields.size() == 2) {
  795. patentCustomFieldParams.put(key, null);
  796. }
  797. }
  798. }
  799. patent.updateById();
  800. //专利权利要求表
  801. //patentRightService.updatePatentRight(patentRightParams);
  802. //专利说明书(文本)
  803. //patentInstructionTextService.updatePatentInstructionText(patentInstructionTextParams);
  804. //代理人 (代理人关联专利)
  805. //patentAgentService.updatePatentAgent(patentAgentParams);
  806. //专利信息质押质权人
  807. //patentPledgeService.updatePatentPledge(patentPledgeParams);
  808. //专利信息许可人
  809. //patentLicensorService.updatePatentLicensor(patentLicensorParams);
  810. //专利信息事务信息
  811. //patentAffairService.updatePatientAffair(patentAffairParams);
  812. //权利人
  813. patentApplicantLinkService.updatePatentApplicantLink(patentApplicantCurrentName, patentApplicantStandardCurrentName, 1, patent.getId());
  814. //申请人
  815. patentApplicantLinkService.updatePatentApplicantLink(patentApplicantOriginalName, patentApplicantStandardOriginalName, 2, patent.getId());
  816. //申请人地址
  817. patentApplicantService.updatePatentApplicantAddress(patentApplicantAddressParams);
  818. //发明人
  819. patentInventorService.updatePatentInventor(patentInventorParams);
  820. //发明人地址
  821. patentInventorService.updatePatentInventorAddress(patentInventorAddressParams);
  822. //专利信息简单同族关联
  823. //patentSimpleFamilyService.updatePatentSimpleFamily(patentSimpleFamilyParams);
  824. //专利分类号关联
  825. //patentClassNumberLinkService.updatePatentClassNumberLink(patentClassNumberParams);
  826. //专题库关联专利信息
  827. //projectPatentLinkService.updateProjectPatent(projectImportPatentVO.getProjectId(), patent.getId());
  828. //标引内容关联专利信息
  829. //projectFieldPatentLinkService.updateProjectFieldPatentLink(projectImportPatentVO, patent.getId());
  830. //文件夹管理
  831. //projectFolderPatentLinkService.updateProjectFolderLink(projectImportPatentVO, patent.getId());
  832. //自定义字段
  833. //patentService.updatePatentCustomField(patentCustomFieldParams);
  834. //标签
  835. //patentLabelService.updatePatentLabel(patentLabelParams);
  836. // WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
  837. // .setTaskId(params.getTaskId())
  838. // .setProjectId(projectImportPatentVO.getProjectId())
  839. // .setComplete(false)
  840. // .setIndex(i)
  841. // .setTaskType(Constants.TASK_IMPORT_PATENT)
  842. // .setPercentage(total == 0 ? 0 : Math.round((total.equals(i) ? (i * 1D) : (i + 1D)) / total * 100D))
  843. // .setFileName("")
  844. // .setOldName(params.getOldName())
  845. // .setUrl("")
  846. // .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), params.getUserId());
  847. }
  848. }
  849. // SpringUtil.getBean(ProjectService.class).setImportPatentTaskStatus(2, params.getTaskId());
  850. // WebSocketServer.sendInfo(Response.websocket(new TaskWebSocketDTO()
  851. // .setTaskId(params.getTaskId())
  852. // .setProjectId(projectImportPatentVO.getProjectId())
  853. // .setComplete(true)
  854. // .setIndex(total)
  855. // .setTaskType(Constants.TASK_IMPORT_PATENT)
  856. // .setPercentage(100L)
  857. // .setFileName("")
  858. // .setOldName(params.getOldName())
  859. // .setUrl("")
  860. // .setTotal(total), ResponseEnum.PATENT_IMPORT_TASK_SUCCESS), params.getUserId());
  861. }
  862. } catch (Exception e) {
  863. e.printStackTrace();
  864. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  865. SpringUtil.getBean(ProjectService.class).setImportPatentTaskStatus(3, params.getTaskId());
  866. WebSocketServer.sendInfo(Response.error(ResponseEnum.PATENT_IMPORT_TASK_ERROR), params.getUserId());
  867. }
  868. }
  869. @Transactional(propagation = Propagation.NOT_SUPPORTED)
  870. public void setImportPatentTaskStatus(Integer status, Integer taskId) {
  871. taskService.updateStatus(taskId, status, DateUtils.getDateTime());
  872. }
  873. public void saveDataToJsonFile(String tempPath, String fileName, String data) throws IOException {
  874. String path = tempPath + FileUtils.FILE_SEPARATOR + fileName;
  875. FileOutputStream fileOutputStream = new FileOutputStream(path);
  876. fileOutputStream.write(data.getBytes(StandardCharsets.UTF_8));
  877. fileOutputStream.close();
  878. }
  879. public void copyFileToTempDirectory(String src, String tempPath, String directoryName, String fileName) {
  880. String dest = tempPath + FileUtils.FILE_SEPARATOR + directoryName + FileUtils.FILE_SEPARATOR + fileName;
  881. File file = FileUtil.file(fileUtils.getSystemPath(src));
  882. if (FileUtil.exist(file)) {
  883. FileUtil.copy(file, new File(dest), true);
  884. }
  885. }
  886. @Async
  887. public void export(ProjectExportVO params, Integer exportId, Integer userId) {
  888. try {
  889. String json = cacheUtils.getSelectPatentIds(params.getKey());
  890. List<Integer> patentIds = StringUtils.changeStringToInteger(json, ",");
  891. List<Patent> patentList = patentService.getPatentListByIds(patentIds);
  892. String directoryName = IdUtil.simpleUUID();
  893. String fileName = directoryName + ".zip";
  894. String tempPath = fileUtils.getTempPath(directoryName);
  895. String url = fileUtils.getDirectory(fileName);
  896. String savePath = fileUtils.getSystemPath(url);
  897. File directory = new File(tempPath);
  898. if (!directory.exists()) {
  899. directory.mkdir();
  900. }
  901. WebSocketServer.sendInfo(Response.websocket(true, ResponseEnum.PROJECT_EXPORT_TASK_SUCCESS), String.valueOf(userId));
  902. if (params.getProjectInfo()) {
  903. Project project = this.getProjectById(params.getProjectId());
  904. this.saveDataToJsonFile(tempPath, Constants.PROJECT_INFO_FILE_NAME, JsonUtils.objectToJson(project));
  905. }
  906. if (params.getProjectReport() != null && params.getProjectReport().size() != 0) {
  907. List<ProjectFile> projectFileList = projectFileService.getProjectFileByIds(params.getProjectReport());
  908. this.saveDataToJsonFile(tempPath, Constants.PROJECT_REPORT_FILE_NAME, JsonUtils.objectToJson(projectFileList));
  909. projectFileList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PROJECT_REPORT_DIRECTORY_NAME, item.getFileName()));
  910. }
  911. if (params.getProjectFile() != null && params.getProjectFile().size() != 0) {
  912. List<ProjectFile> projectFileList = projectFileService.getProjectFileByIds(params.getProjectFile());
  913. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FILE_FILE_NAME, JsonUtils.objectToJson(projectFileList));
  914. projectFileList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PROJECT_FILE_DIRECTORY_NAME, item.getFileName()));
  915. }
  916. if (params.getPatentImage()) {
  917. List<PatentImage> patentImageList = patentImageService.getPatentImageByPatentIds(patentIds);
  918. this.saveDataToJsonFile(tempPath, Constants.PATENT_IMAGE_FILE_NAME, JsonUtils.objectToJson(patentImageList));
  919. patentImageList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PATENT_IMAGE_DIRECTORY_NAME, item.getFileName()));
  920. }
  921. if (params.getPatentInstruction()) {
  922. List<String> patentNo = patentList.stream().map(Patent::getPatentNo).collect(Collectors.toList());
  923. List<PatentInstruction> patentInstructionList = patentInstructionService.getPatentInstructionByPatentNo(patentNo);
  924. this.saveDataToJsonFile(tempPath, Constants.PATENT_INSTRUCTION_FILE_NAME, JsonUtils.objectToJson(patentInstructionList));
  925. patentInstructionList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PATENT_INSTRUCTION_DIRECTORY_NAME, item.getFileName()));
  926. }
  927. if (params.getPatentBase()) {
  928. List<PatentApplicantLink> patentApplicantLinkList = patentApplicantLinkService.getApplicantAttributesListByPatentIds(patentIds);
  929. List<PatentApplicantMergeLink> patentApplicantMergeLinkList = patentApplicantMergeLinkService.getPatentApplicantMergeLinkListByProjectId(params.getProjectId());
  930. List<Integer> patentApplicantIds = new ArrayList<>();
  931. patentApplicantLinkList.forEach(item -> patentApplicantIds.add(item.getApplicantId()));
  932. patentApplicantMergeLinkList.forEach(item -> patentApplicantIds.add(item.getMergeId()));
  933. List<PatentApplicant> patentApplicantList = patentApplicantService.getPatentApplicantByIds(patentApplicantIds);
  934. List<PatentAffair> patentAffairList = patentAffairService.getPatentAffairListByPatentIds(patentIds);
  935. List<PatentAgency> patentAgencyList = patentAgencyService.getPatentAgencyByIds(patentList.stream().filter(item -> StringUtils.isNotEmpty(item.getAgencyId())).map(item -> Integer.parseInt(item.getAgencyId())).collect(Collectors.toList()));
  936. List<PatentAgentLink> patentAgentLinkList = patentAgentLinkService.getPatentAgentLinkByPatentIds(patentIds);
  937. List<PatentAgent> patentAgentList = patentAgentService.getPatentAgentByIds(patentAgentLinkList.stream().map(PatentAgentLink::getAgentId).collect(Collectors.toList()));
  938. List<PatentInstructionText> patentInstructionTextList = patentInstructionTextService.getPatentInstructionTextByPatentIds(patentIds);
  939. List<PatentInventorLink> patentInventorLinkList = patentInventorLinkService.getPatentInventorLinkByPatentIds(patentIds);
  940. List<PatentInventorMerge> patentInventorMergeList = patentInventorMergeService.getPatentInventorMergeByProjectId(params.getProjectId());
  941. List<Integer> patentInventorIds = new ArrayList<>();
  942. patentInventorLinkList.forEach(item -> patentInventorIds.add(item.getInventorId()));
  943. patentInventorMergeList.forEach(item -> patentInventorIds.add(item.getMergeId()));
  944. List<PatentInventor> patentInventorList = patentInventorService.getPatentInventorByIds(patentInventorIds);
  945. List<PatentLicensor> patentLicensorList = patentLicensorService.getPatentLicensorByPatentIds(patentIds);
  946. List<PatentPledge> patentPledgeList = patentPledgeService.getPatentPledgeByPatentIds(patentIds);
  947. List<PatentRight> patentRightList = patentRightService.getPatentRightByPatentIds(patentIds);
  948. List<Integer> patentFamilyIds = new ArrayList<>();
  949. patentList.forEach(item -> {
  950. patentFamilyIds.add(item.getSimpleFamily());
  951. patentFamilyIds.add(item.getInpadocFamily());
  952. patentFamilyIds.add(item.getPatSnapFamily());
  953. });
  954. List<PatentSimpleFamilyLink> patentSimpleFamilyLinkList = patentSimpleFamilyLinkService.getPatentSimpleFamilyLinkByFamilyIds(patentFamilyIds);
  955. List<PatentSimpleFamily> patentSimpleFamilyList = patentSimpleFamilyService.getPatentSimpleFamilyByIds(patentFamilyIds);
  956. List<PatentClassNumberLink> patentClassNumberLinkList = patentClassNumberLinkService.getPatentClassNumberLinkByPatentIds(patentIds);
  957. this.saveDataToJsonFile(tempPath, Constants.PATENT_FILE_NAME, JsonUtils.objectToJson(patentList));
  958. this.saveDataToJsonFile(tempPath, Constants.PATENT_AFFAIR_FILE_NAME, JsonUtils.objectToJson(patentAffairList));
  959. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENCY_FILE_NAME, JsonUtils.objectToJson(patentAgencyList));
  960. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENT_LINK_FILE_NAME, JsonUtils.objectToJson(patentAgentLinkList));
  961. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENT_FILE_NAME, JsonUtils.objectToJson(patentAgentList));
  962. this.saveDataToJsonFile(tempPath, Constants.PATENT_INSTRUCTION_TEXT_FILE_NAME, JsonUtils.objectToJson(patentInstructionTextList));
  963. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_LINK_FILE_NAME, JsonUtils.objectToJson(patentInventorLinkList));
  964. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_FILE_NAME, JsonUtils.objectToJson(patentInventorList));
  965. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_MERGE_FILE_NAME, JsonUtils.objectToJson(patentInventorMergeList));
  966. this.saveDataToJsonFile(tempPath, Constants.PATENT_LICENSOR_FILE_NAME, JsonUtils.objectToJson(patentLicensorList));
  967. this.saveDataToJsonFile(tempPath, Constants.PATENT_PLEDGE_FILE_NAME, JsonUtils.objectToJson(patentPledgeList));
  968. this.saveDataToJsonFile(tempPath, Constants.PATENT_RIGHT_FILE_NAME, JsonUtils.objectToJson(patentRightList));
  969. this.saveDataToJsonFile(tempPath, Constants.PATENT_FAMILY_LINK_FILE_NAME, JsonUtils.objectToJson(patentSimpleFamilyLinkList));
  970. this.saveDataToJsonFile(tempPath, Constants.PATENT_FAMILY_FILE_NAME, JsonUtils.objectToJson(patentSimpleFamilyList));
  971. this.saveDataToJsonFile(tempPath, Constants.PATENT_CLASS_NUMBER_FILE_NAME, JsonUtils.objectToJson(patentClassNumberLinkList));
  972. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_FILE_NAME, JsonUtils.objectToJson(patentApplicantList));
  973. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_LINK_FILE_NAME, JsonUtils.objectToJson(patentApplicantLinkList));
  974. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_MERGE_LINK_FILE_NAME, JsonUtils.objectToJson(patentApplicantMergeLinkList));
  975. }
  976. if (params.getPatentField() != null && params.getPatentField().size() != 0) {
  977. if (params.getPatentField().contains(0)) {
  978. List<PatentLabel> patentLabelList = patentLabelService.getPatentLabelByPatentIdsAndProjectId(patentIds, params.getProjectId());
  979. this.saveDataToJsonFile(tempPath, Constants.PATENT_LABEL_FILE_NAME, JsonUtils.objectToJson(patentLabelList));
  980. }
  981. List<ProjectField> projectFieldList = projectFieldService.getFieldListByIds(params.getPatentField());
  982. List<Integer> projectFieldIds = projectFieldList.stream().map(ProjectField::getId).collect(Collectors.toList());
  983. List<ProjectFieldOption> projectFieldOptionList = projectFieldOptionService.getFieldOptionList(projectFieldIds);
  984. List<ProjectFieldTree> projectFieldTreeList = projectFieldTreeService.getProjectFieldTreeOptionByFieldIds(projectFieldIds);
  985. List<ProjectFieldText> projectFieldTextList = projectFieldTextService.getProjectFieldTextByFieldIds(projectFieldIds);
  986. List<ProjectFieldPatentLink> projectFieldPatentLinkList = new ArrayList<>();
  987. for (Integer fieldId : params.getPatentField()) {
  988. projectFieldPatentLinkList.addAll(projectFieldPatentLinkService.getProjectPatentLinkByPatentIdsAndFieldId(patentIds, fieldId));
  989. }
  990. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_FILE_NAME, JsonUtils.objectToJson(projectFieldList));
  991. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_OPTION_FILE_NAME, JsonUtils.objectToJson(projectFieldOptionList));
  992. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_TREE_FILE_NAME, JsonUtils.objectToJson(projectFieldTreeList));
  993. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_TEXT_FILE_NAME, JsonUtils.objectToJson(projectFieldTextList));
  994. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_PATENT_LINK_FILE_NAME, JsonUtils.objectToJson(projectFieldPatentLinkList));
  995. }
  996. List<Patent> patents = patentService.getPatentIdAndPatentNoByIds(patentIds);
  997. this.saveDataToJsonFile(tempPath, Constants.PATENT_ID_PATENT_NO_FILE_NAME, JsonUtils.objectToJson(patents));
  998. File file = ZipUtil.zip(tempPath, savePath);
  999. FileUtil.del(tempPath);
  1000. ProjectExport projectExport = projectExportService.getById(exportId);
  1001. projectExport.setUrl(url);
  1002. projectExport.setFileName(fileName);
  1003. projectExport.setStatus(1);
  1004. projectExport.setFileSize(FileUtil.size(file));
  1005. projectExport.updateById();
  1006. WebSocketServer.sendInfo(Response.websocket(true, ResponseEnum.PROJECT_EXPORT_TASK_SUCCESS), String.valueOf(userId));
  1007. } catch (Exception e) {
  1008. e.printStackTrace();
  1009. WebSocketServer.sendInfo(Response.websocket(false, ResponseEnum.PROJECT_EXPORT_TASK_ERROR), String.valueOf(userId));
  1010. }
  1011. }
  1012. @Async("singleThreadAsyncTaskExecutor")
  1013. @Transactional(rollbackFor = Exception.class)
  1014. public void importData(String url, ProjectImportVO params, Integer userId, Integer importId) {
  1015. String tempPath = null;
  1016. ProjectImportStatusService projectImportStatusService = SpringUtil.getBean(ProjectImportStatusService.class);
  1017. try {
  1018. String tempDirectoryName = IdUtil.simpleUUID();
  1019. tempPath = fileUtils.getTempPath(tempDirectoryName);
  1020. String tempSavePath = fileUtils.getSystemPath(url);
  1021. File tempDirectory = new File(tempPath);
  1022. if (!tempDirectory.exists()) {
  1023. tempDirectory.mkdir();
  1024. }
  1025. projectImportStatusService.add(importId, userId, 2);
  1026. ZipUtil.unzip(tempSavePath, tempPath);
  1027. String projectJson = this.parseTempFileData(tempPath, Constants.PROJECT_INFO_FILE_NAME);
  1028. Integer projectId = params.getProjectId();
  1029. if (StringUtils.isNotEmpty(projectJson)) {
  1030. projectImportStatusService.add(importId, userId, 3);
  1031. projectId = this.importProject(params.getProjectId(), projectJson, userId);
  1032. }
  1033. if (projectId.equals(0)) {
  1034. projectImportStatusService.add(importId, userId, 100);
  1035. throw new CustomException("数据包未包含专题库信息");
  1036. }
  1037. String projectReportJson = this.parseTempFileData(tempPath, Constants.PROJECT_REPORT_FILE_NAME);
  1038. String projectFileJson = this.parseTempFileData(tempPath, Constants.PROJECT_FILE_FILE_NAME);
  1039. if (StringUtils.isNotEmpty(projectReportJson) || StringUtils.isNotEmpty(projectFileJson)) {
  1040. projectImportStatusService.add(importId, userId, 4);
  1041. projectFileService.importProjectFile(projectId, userId, tempPath, projectFileJson, projectReportJson);
  1042. }
  1043. String patentIdPatentNoJson = this.parseTempFileData(tempPath, Constants.PATENT_ID_PATENT_NO_FILE_NAME);
  1044. String patentJson = this.parseTempFileData(tempPath, Constants.PATENT_FILE_NAME);
  1045. String patentAffairJson = this.parseTempFileData(tempPath, Constants.PATENT_AFFAIR_FILE_NAME);
  1046. String patentAgencyJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENCY_FILE_NAME);
  1047. String patentAgentJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENT_FILE_NAME);
  1048. String patentAgentLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENT_LINK_FILE_NAME);
  1049. String patentInventorJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_FILE_NAME);
  1050. String patentInventorMergeJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_MERGE_FILE_NAME);
  1051. String patentInventorLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_LINK_FILE_NAME);
  1052. String patentApplicantJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_FILE_NAME);
  1053. String patentApplicantLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_LINK_FILE_NAME);
  1054. String patentApplicantMergeLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_MERGE_LINK_FILE_NAME);
  1055. String patentFamilyJson = this.parseTempFileData(tempPath, Constants.PATENT_FAMILY_FILE_NAME);
  1056. String patentFamilyLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_FAMILY_LINK_FILE_NAME);
  1057. String patentClassNumberJson = this.parseTempFileData(tempPath, Constants.PATENT_CLASS_NUMBER_FILE_NAME);
  1058. String patentInstructionTextJson = this.parseTempFileData(tempPath, Constants.PATENT_INSTRUCTION_TEXT_FILE_NAME);
  1059. String patentRightJson = this.parseTempFileData(tempPath, Constants.PATENT_RIGHT_FILE_NAME);
  1060. String patentLicensorJson = this.parseTempFileData(tempPath, Constants.PATENT_LICENSOR_FILE_NAME);
  1061. String patentPledgeJson = this.parseTempFileData(tempPath, Constants.PATENT_PLEDGE_FILE_NAME);
  1062. if (StringUtils.isNotEmpty(patentJson)) {
  1063. projectImportStatusService.add(importId, userId, 8);
  1064. patentService.importPatent(projectId, patentJson, patentAffairJson, patentAgencyJson, patentFamilyJson, patentFamilyLinkJson, patentInventorJson, patentInventorLinkJson, patentAgentJson, patentAgentLinkJson, patentApplicantJson, patentApplicantLinkJson, patentApplicantMergeLinkJson, patentClassNumberJson, patentInstructionTextJson, patentRightJson, patentLicensorJson, patentPledgeJson, patentInventorMergeJson);
  1065. }
  1066. projectImportStatusService.add(importId, userId, 9);
  1067. projectPatentLinkService.importProjectPatentLink(projectId, patentIdPatentNoJson);
  1068. String projectFieldJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_FILE_NAME);
  1069. if (StringUtils.isNotEmpty(projectFieldJson)) {
  1070. String projectFieldTextJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_TEXT_FILE_NAME);
  1071. String projectFieldOptionJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_OPTION_FILE_NAME);
  1072. String projectFieldTreeJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_TREE_FILE_NAME);
  1073. String projectFieldPatentLink = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_PATENT_LINK_FILE_NAME);
  1074. projectImportStatusService.add(importId, userId, 5);
  1075. projectFieldService.importProjectField(projectId, userId, patentIdPatentNoJson, projectFieldJson, projectFieldTextJson, projectFieldOptionJson, projectFieldTreeJson, projectFieldPatentLink);
  1076. }
  1077. String patentImageJson = this.parseTempFileData(tempPath, Constants.PATENT_IMAGE_FILE_NAME);
  1078. if (StringUtils.isNotEmpty(patentImageJson)) {
  1079. projectImportStatusService.add(importId, userId, 6);
  1080. patentImageService.importPatentImage(tempPath, patentIdPatentNoJson, patentImageJson);
  1081. }
  1082. String patentInstructionJson = this.parseTempFileData(tempPath, Constants.PATENT_INSTRUCTION_FILE_NAME);
  1083. if (StringUtils.isNotEmpty(patentInstructionJson)) {
  1084. projectImportStatusService.add(importId, userId, 7);
  1085. patentInstructionService.importPatentInstruction(userId, tempPath, patentIdPatentNoJson, patentInstructionJson);
  1086. }
  1087. } catch (Exception e) {
  1088. e.printStackTrace();
  1089. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1090. projectImportStatusService.add(importId, userId, 101);
  1091. } finally {
  1092. FileUtil.del(tempPath);
  1093. projectImportStatusService.add(importId, userId, 200);
  1094. cacheUtils.deleteUserImport(userId);
  1095. }
  1096. }
  1097. private String parseTempFileData(String path, String fileName) throws IOException {
  1098. String src = path + FileUtil.FILE_SEPARATOR + fileName;
  1099. if (!FileUtil.exist(src)) {
  1100. return null;
  1101. }
  1102. File file = new File(src);
  1103. FileReader fileReader = new FileReader(file);
  1104. Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
  1105. int ch = 0;
  1106. StringBuffer sb = new StringBuffer();
  1107. while ((ch = reader.read()) != -1) {
  1108. sb.append((char) ch);
  1109. }
  1110. fileReader.close();
  1111. reader.close();
  1112. return sb.toString();
  1113. }
  1114. //主页面 导出列表功能
  1115. public void exportProject(HttpServletResponse response) {
  1116. try {
  1117. ProjectVO params = new ProjectVO();
  1118. params.setSize(99999999999L);
  1119. params.setCurrent(1L);
  1120. params.setMyself(true);
  1121. ProjectVO.Sort sort = new ProjectVO.Sort();
  1122. sort.setProp("create_time");
  1123. sort.setOrder("desc");
  1124. params.setSort(sort);
  1125. IPage<Project> pageList = this.getPageList(params);
  1126. List<Project> projectList = pageList.getRecords();
  1127. List<List<String>> row = new ArrayList<>();
  1128. row.add(CollUtil.newArrayList("#", "名称", "委托方", "调查类型", "应用场景", "技术主题", "合同号", "委案日", "创建人"));
  1129. for (int i = 0; i < projectList.size(); i++) {
  1130. Project project = projectList.get(i);
  1131. 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()));
  1132. }
  1133. List<List<String>> rows = CollUtil.newArrayList(row);
  1134. ExcelWriter writer = ExcelUtil.getWriter(true);
  1135. OutputStream out = response.getOutputStream();
  1136. writer.write(rows, true);
  1137. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  1138. response.setHeader("Content-Disposition", "attachment;filename=" + IdUtil.simpleUUID() + ".xlsx");
  1139. writer.flush(out, true);
  1140. writer.close();
  1141. IoUtil.close(out);
  1142. } catch (Exception e) {
  1143. e.printStackTrace();
  1144. }
  1145. }
  1146. }