ProjectService.java 76 KB

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