ProjectService.java 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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.*;
  6. import cn.cslg.pas.common.model.vo.*;
  7. import cn.cslg.pas.common.utils.*;
  8. import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
  9. import cn.cslg.pas.domain.*;
  10. import cn.cslg.pas.exception.XiaoShiException;
  11. import cn.cslg.pas.mapper.ProductMapper;
  12. import cn.cslg.pas.mapper.ProjectMapper;
  13. import cn.cslg.pas.mapper.asso.AssoStructurePatentMapper;
  14. import cn.cslg.pas.service.asso.TaskConditionService;
  15. import cn.hutool.core.collection.CollUtil;
  16. import cn.hutool.core.collection.IterUtil;
  17. import cn.hutool.core.date.DateField;
  18. import cn.hutool.core.date.DateUtil;
  19. import cn.hutool.core.io.FileUtil;
  20. import cn.hutool.core.io.IoUtil;
  21. import cn.hutool.core.util.IdUtil;
  22. import cn.hutool.core.util.ZipUtil;
  23. import cn.hutool.extra.spring.SpringUtil;
  24. import cn.hutool.poi.excel.ExcelReader;
  25. import cn.hutool.poi.excel.ExcelUtil;
  26. import cn.hutool.poi.excel.ExcelWriter;
  27. import com.alibaba.fastjson.JSON;
  28. import com.alibaba.fastjson.JSONArray;
  29. import com.alibaba.fastjson.JSONObject;
  30. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  31. import com.baomidou.mybatisplus.core.metadata.IPage;
  32. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  33. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  34. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  35. import lombok.RequiredArgsConstructor;
  36. import lombok.extern.slf4j.Slf4j;
  37. import org.springframework.beans.BeanUtils;
  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. @Slf4j
  59. @Service
  60. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  61. public class ProjectService extends ServiceImpl<ProjectMapper, Project> {
  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 PatentClassNumberLinkService patentClassNumberLinkService;
  78. private final ProjectPatentLinkService projectPatentLinkService;
  79. private final TaskService taskService;
  80. private final TaskConditionService taskConditionService;
  81. private final PatentImageService patentImageService;
  82. private final ProjectFieldPatentLinkService projectFieldPatentLinkService;
  83. private final ProjectFolderService projectFolderService;
  84. private final ProjectFieldService projectFieldService;
  85. private final ProjectFieldOptionService projectFieldOptionService;
  86. private final ProjectFieldTreeService projectFieldTreeService;
  87. private final ProjectFieldTextService projectFieldTextService;
  88. private final ProjectFileService projectFileService;
  89. private final SystemDictService systemDictService;
  90. private final PatentInstructionService patentInstructionService;
  91. private final PatentInstructionTextService patentInstructionTextService;
  92. private final PatentRightService patentRightService;
  93. private final FileUtils fileUtils;
  94. private final PatentLabelService patentLabelService;
  95. private final CacheUtils cacheUtils;
  96. private final ProjectExportService projectExportService;
  97. private final PatentInventorMergeService patentInventorMergeService;
  98. private final UserService userService;
  99. private final LoginUtils loginUtils;
  100. private final RequestService requestService;
  101. private final AssoStructurePatentMapper assoStructurePatentMapper;
  102. private final ProductMapper productMapper;
  103. private final ProjectMapper projectMapper;
  104. private final IEventService eventService;
  105. private final IAssoEventProjectService assoEventProjectService;
  106. private final CopyService copyService;
  107. public Project getProjectByName(String name) {
  108. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  109. PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  110. queryWrapper.eq(Project::getName, name);
  111. queryWrapper.eq(Project::getTenantId, personnelVO.getTenantId());
  112. queryWrapper.last("limit 1");
  113. return this.getOne(queryWrapper);
  114. }
  115. public Project getProjectByName(String name, Integer loginId) {
  116. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  117. PersonnelVO personnelVO = cacheUtils.getLoginUser(loginId);
  118. queryWrapper.eq(Project::getName, name);
  119. queryWrapper.eq(Project::getTenantId, personnelVO.getTenantId());
  120. queryWrapper.last("limit 1");
  121. return this.getOne(queryWrapper);
  122. }
  123. public IPage<Project> getPageList(ProjectVO params) throws IOException {
  124. List<Integer> projectIds = new ArrayList<Integer>() {{
  125. add(-1);
  126. }};
  127. //TODO 代码控制不同类型的角色查询权限
  128. PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  129. if (personnelVO.getRoleType() == null || personnelVO.getRoleType() != 1) {
  130. params.setPersonnelId(loginUtils.getId());
  131. if (personnelVO.getRoleType() != null && personnelVO.getRoleType() == 2) {
  132. params.setTenantId(personnelVO.getTenantId());
  133. }
  134. }
  135. //分页查询专题库列表
  136. IPage<Project> pageList = baseMapper.getPageList(new Page<>(params.getCurrent(), params.getSize()), params);
  137. List<Project> dataList = pageList.getRecords();
  138. this.setDataList(dataList);
  139. pageList.setRecords(dataList);
  140. return pageList;
  141. }
  142. public List<Project> getProjectByIds(List<Integer> ids) throws IOException {
  143. if (ids == null || ids.size() == 0) {
  144. return new ArrayList<>();
  145. }
  146. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  147. queryWrapper.in(Project::getId, ids);
  148. //根据ids查询专题库列表
  149. List<Project> dataList = this.list(queryWrapper);
  150. //↓根据专题库id查询专题库时,查询到的就是一条,就将当前专题库的产品名字赋值(他妈的两个控制层方法调当前业务层,坑爹)
  151. if (dataList.size() == 1) {
  152. for (Project project : dataList) {
  153. Integer productId = project.getProductId();
  154. if (productId != null) {
  155. ProductVO queryResult = productMapper.getStandardById(productId);
  156. String productName = queryResult.getProductName();
  157. project.setProductName(productName);
  158. }
  159. }
  160. }
  161. try {
  162. //获取所属部门对应信息
  163. String jsonObject = requestService.getDepartmentFromPCS(dataList);
  164. JSONArray jsonArray1 = JSON.parseArray(jsonObject);
  165. List<ProjectVO.Department> departmentList = jsonArray1.toJavaList(ProjectVO.Department.class);
  166. for (Project project : dataList) {
  167. for (ProjectVO.Department department : departmentList) {
  168. if (project.getDepartmentId() != null) {
  169. if (project.getDepartmentId().equals(department.getId())) {
  170. project.setDepartmentName(department.getDepartmentName());
  171. }
  172. }
  173. }
  174. }
  175. List<Integer> personnelIds = dataList.stream().map(Project::getPersonnelId).collect(Collectors.toList());
  176. //获取专题库负责人对应信息
  177. String jsonObject1 = requestService.getPersonnelFromPCS(personnelIds);
  178. JSONArray jsonArray = JSON.parseArray(jsonObject1);
  179. List<ProjectVO.Personnel> personnelList = jsonArray.toJavaList(ProjectVO.Personnel.class);
  180. for (Project project : dataList) {
  181. for (ProjectVO.Personnel personnel : personnelList) {
  182. if (project.getPersonnelId() != null) {
  183. if (project.getPersonnelId().equals(personnel.getId())) {
  184. project.setPersonnelName(personnel.getPersonnelName());
  185. }
  186. }
  187. }
  188. }
  189. } catch (IOException e) {
  190. e.printStackTrace();
  191. }
  192. this.setDataList(dataList);
  193. return dataList;
  194. }
  195. public List<Project> getProjectByCreateId(Integer createBy) {
  196. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  197. queryWrapper.eq(Project::getCreateBy, createBy);
  198. return this.list(queryWrapper);
  199. }
  200. public Project getProjectById(Integer id) {
  201. Project project = this.getById(id);
  202. try {
  203. String res = requestService.getClientByIds(Arrays.asList(project.getClientId()));
  204. JSONArray jsonArray2 = JSON.parseArray(res);
  205. List<ClientDTO> clientList = jsonArray2.toJavaList(ClientDTO.class);
  206. if (clientList != null && clientList.size() != 0) {
  207. project.setClientName(clientList.get(0).getName());
  208. }
  209. } catch (Exception e) {
  210. }
  211. return project;
  212. }
  213. private void setDataList(List<Project> dataList) throws IOException {
  214. //获得委托方的id集合
  215. List<Integer> clientIds = dataList.stream().map(Project::getClientId).collect(Collectors.toList());
  216. //获得负责人的id集合
  217. List<Integer> personIds = dataList.stream().map(Project::getPersonnelId).collect(Collectors.toList());
  218. //获得创建人的id集合
  219. List<Integer> createIds = dataList.stream().map(Project::getCreateBy).collect(Collectors.toList());
  220. personIds.addAll(createIds);
  221. //获取所属部门对应信息
  222. String jsonObject = requestService.getDepartmentFromPCS(dataList);
  223. JSONArray jsonArray1 = JSON.parseArray(jsonObject);
  224. List<ProjectVO.Department> departmentList = jsonArray1.toJavaList(ProjectVO.Department.class);
  225. //获取专题库负责人对应信息
  226. String jsonObject1 = requestService.getPersonnelFromPCS(personIds);
  227. JSONArray jsonArray = JSON.parseArray(jsonObject1);
  228. List<ProjectVO.Personnel> personnelList = jsonArray.toJavaList(ProjectVO.Personnel.class);
  229. //获取专题库委托方对应信息
  230. List<ClientDTO> clientList = new ArrayList<>();
  231. if (clientIds.size() > 0) {
  232. String jsonObject2 = requestService.getClientByIds(clientIds);
  233. JSONArray jsonArray2 = JSON.parseArray(jsonObject2);
  234. clientList = jsonArray2.toJavaList(ClientDTO.class);
  235. }
  236. for (Project project : dataList) {
  237. //装载负责人名
  238. for (ProjectVO.Personnel personnel : personnelList) {
  239. if (project.getPersonnelId() != null) {
  240. if (project.getPersonnelId().equals(personnel.getId())) {
  241. project.setPersonnelName(personnel.getPersonnelName());
  242. }
  243. }
  244. //装载创建人名
  245. if (project.getCreateBy() != null) {
  246. if (project.getCreateBy().equals(personnel.getId())) {
  247. project.setCreateName(personnel.getPersonnelName());
  248. }
  249. }
  250. }
  251. //装载委托方名
  252. for (ClientDTO clientDTO : clientList) {
  253. if (project.getClientId() != null) {
  254. if (project.getClientId().equals(clientDTO.getId())) {
  255. project.setClientName(clientDTO.getName());
  256. }
  257. }
  258. }
  259. Integer productId = project.getProductId();
  260. //装载产品id
  261. if (productId != null) {
  262. ProductVO queryResult = productMapper.getStandardById(productId);
  263. String productName = queryResult.getProductName();
  264. project.setProductName(productName);
  265. }
  266. //装载部门
  267. for (ProjectVO.Department department : departmentList) {
  268. if (project.getDepartmentId() != null) {
  269. if (project.getDepartmentId().equals(department.getId())) {
  270. project.setDepartmentName(department.getDepartmentName());
  271. }
  272. }
  273. }
  274. }
  275. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.ENTERPRISE_APPLICATION_SCENARIO, Constants.INVESTIGATION_TYPE));
  276. dataList.forEach(item -> {
  277. if (StringUtils.isNotEmpty(item.getScenario())) {
  278. item.setScenarioList(StringUtils.changeStringToInteger(item.getScenario(), ","));
  279. 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()));
  280. item.setScenario(null);
  281. }
  282. if (StringUtils.isNotEmpty(item.getType())) {
  283. item.setTypeList(StringUtils.changeStringToInteger(item.getType(), ","));
  284. 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()));
  285. item.setType(null);
  286. } else {
  287. item.setTypeList(new ArrayList<Integer>());
  288. }
  289. });
  290. }
  291. public List<Project> getAllProjectByMySelf() throws IOException {
  292. ProjectVO params = new ProjectVO();
  293. PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  294. if (personnelVO.getRoleType() == null || personnelVO.getRoleType() != 1) {
  295. params.setPersonnelId(loginUtils.getId());
  296. if (personnelVO.getRoleType() != null && personnelVO.getRoleType() == 2) {
  297. params.setTenantId(personnelVO.getTenantId());
  298. }
  299. }
  300. List<Project> projectList = baseMapper.getListForCount(params);
  301. this.setDataList(projectList);
  302. return projectList;
  303. }
  304. public Map<Object, Object> getProjectStatusTotal() throws IOException {
  305. Map<Object, Object> map = new HashMap<>();
  306. List<Project> projectList = this.getAllProjectByMySelf();
  307. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.ENTERPRISE_APPLICATION_SCENARIO));
  308. for (SystemDict systemDict : systemDictList) {
  309. Map<String, Object> result = new HashMap<>();
  310. List<Project> tempList = projectList.stream().filter(item -> item.getScenarioList() != null && item.getScenarioList().contains(Integer.parseInt(systemDict.getValue()))).collect(Collectors.toList());
  311. result.put("completed", tempList.stream().filter(item -> item.getStatus().equals("1")).count());
  312. result.put("unfinished", tempList.stream().filter(item -> item.getStatus().equals("0")).count());
  313. map.put(systemDict.getLabel(), result);
  314. }
  315. return map;
  316. }
  317. public Map<String, Object> getProjectTypeTotal(String scenario) throws IOException {
  318. Map<String, Object> map = new HashMap<>();
  319. List<Project> projectList = this.getAllProjectByMySelf();
  320. projectList = projectList.stream().filter(item -> item.getScenarioName() != null && item.getScenarioName().contains(scenario)).collect(Collectors.toList());
  321. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.INVESTIGATION_TYPE));
  322. for (SystemDict systemDict : systemDictList) {
  323. map.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getTypeList().contains(Integer.parseInt(systemDict.getValue()))).count());
  324. }
  325. return map;
  326. }
  327. public Map<Object, Object> getScenarioAndTypeTotal() throws IOException {
  328. List<Project> projectList = this.getAllProjectByMySelf();
  329. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.ENTERPRISE_APPLICATION_SCENARIO, Constants.INVESTIGATION_TYPE));
  330. List<Integer> clientIds = projectList.stream().map(Project::getClientId).collect(Collectors.toList());
  331. List<ClientDTO> clientList = new ArrayList<>();
  332. if (clientIds.size() > 0) {
  333. String res = requestService.getClientByIds(clientIds);
  334. JSONArray jsonArray2 = JSON.parseArray(res);
  335. clientList = jsonArray2.toJavaList(ClientDTO.class);
  336. }
  337. Map<Object, Object> type = new HashMap<>();
  338. Map<Object, Object> scenario = new HashMap<>();
  339. Map<Object, Object> result = new HashMap<>();
  340. Map<Object, Object> client = new HashMap<>();
  341. Map<Object, Object> create = new HashMap<>();
  342. systemDictList.forEach(systemDict -> {
  343. switch (systemDict.getType()) {
  344. case Constants.ENTERPRISE_APPLICATION_SCENARIO:
  345. scenario.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getScenarioList() != null && item.getScenarioList().contains(Integer.parseInt(systemDict.getValue()))).count());
  346. break;
  347. case Constants.INVESTIGATION_TYPE:
  348. type.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getTypeList().contains(Integer.parseInt(systemDict.getValue()))).count());
  349. break;
  350. }
  351. });
  352. clientList.forEach(item -> client.put(item.getName(), projectList.stream().filter(project -> item.getId().equals(project.getClientId())).count()));
  353. Date date = DateUtil.date();
  354. for (int i = 0; i < 6; i++) {
  355. Date finalDate = date;
  356. 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());
  357. date = DateUtil.offset(date, DateField.MONTH, -1);
  358. }
  359. result.put("scenario", scenario);
  360. result.put("type", type);
  361. result.put("client", client);
  362. result.put("create", create);
  363. return result;
  364. }
  365. private List<Object> getClientIds(List<Integer> clientIds) {
  366. Map<Object, Long> map = clientIds.stream().collect(Collectors.groupingBy(p -> p, Collectors.counting()));
  367. return map.entrySet().stream()
  368. .sorted((Map.Entry<Object, Long> o1, Map.Entry<Object, Long> o2) -> o2.getValue().intValue() - o1.getValue().intValue())
  369. .map(Map.Entry::getKey).collect(Collectors.toList())
  370. .subList(0, Math.min(map.size(), 10));
  371. }
  372. public String getImportProjectName(String name) {
  373. String tempName = name + "(1)";
  374. Project project1 = this.getProjectByName(name);
  375. if (project1 == null) {
  376. return name;
  377. }
  378. Project project2 = this.getProjectByName(tempName);
  379. if (project2 != null) {
  380. tempName = this.getImportProjectName(tempName);
  381. }
  382. return tempName;
  383. }
  384. public String getImportProjectName(String name, Integer userId) {
  385. String tempName = name + "(1)";
  386. Project project1 = this.getProjectByName(name, userId);
  387. if (project1 == null) {
  388. return name;
  389. }
  390. Project project2 = this.getProjectByName(tempName, userId);
  391. if (project2 != null) {
  392. tempName = this.getImportProjectName(tempName, userId);
  393. }
  394. return tempName;
  395. }
  396. public Integer importProject(Integer projectId, String json, Integer userId) throws IOException {
  397. if ((projectId == null || projectId.equals(0)) && StringUtils.isEmpty(json)) {
  398. return 0;
  399. }
  400. if (StringUtils.isEmpty(json)) {
  401. return projectId;
  402. }
  403. Project temp = this.getById(projectId);
  404. Project data = JsonUtils.jsonToPojo(json, Project.class);
  405. if (data.getClientId() != null) {
  406. temp.setClientId(data.getClientId());
  407. }
  408. if (temp == null) {
  409. temp = new Project();
  410. }
  411. String projectName = temp.getName();
  412. BeanUtils.copyProperties(data, temp);
  413. if (projectName == null || !projectName.equals(data.getName())) {
  414. temp.setName(this.getImportProjectName(temp.getName(), userId));
  415. }
  416. if (projectId == null || projectId.equals(0)) {
  417. temp.setCreateBy(userId);
  418. temp.setCreateTime(DateUtils.getDateTime());
  419. temp.setId(null);
  420. } else {
  421. temp.setId(projectId);
  422. }
  423. temp.insertOrUpdate();
  424. return temp.getId();
  425. }
  426. @Transactional
  427. public Integer add(Project project) throws IOException {
  428. PersonnelVO user = cacheUtils.getLoginUserPersonnel(loginUtils.getId());
  429. //检查专题库名称是否被占用
  430. Project temp = this.getProjectByName(project.getName());
  431. if (temp != null) {
  432. ThrowException.throwXiaoShiException("专题库名称已存在");
  433. }
  434. if ((project.getClientId() == null || project.getClientId() == -1) && project.getClientName() != null && project.getClientName() != "") {
  435. ClientDTO clientDTO = new ClientDTO();
  436. clientDTO.setName(project.getClientName());
  437. clientDTO.setTenantId(user.getTenantId());
  438. String res = requestService.addClient(clientDTO);
  439. JSONObject jsonObject = JSONObject.parseObject(res);
  440. Integer clientId = Integer.parseInt(jsonObject.get("data").toString());
  441. project.setClientId(clientId);
  442. }
  443. project.setScenario(StringUtils.join(project.getScenarioList(), ","));
  444. project.setType(StringUtils.join(project.getTypeList(), ","));
  445. project.setCreateBy(loginUtils.getId());
  446. project.setCreateTime(DateUtils.getDateTime());
  447. project.setTenantId(user.getTenantId());
  448. //专题库表新增数据
  449. log.info("专题库表新增数据");
  450. project.insert();
  451. this.addProjectUser(project.getId());
  452. //新增事件
  453. List<EventAddNewDTO> eventAddNewDTOs = project.getEventAddNewDTOs();
  454. if (eventAddNewDTOs != null && eventAddNewDTOs.size() > 0) {
  455. ProjectEventAddNewDTO projectEventAddNewDTO = new ProjectEventAddNewDTO()
  456. .setEventAddNewDTOs(eventAddNewDTOs)
  457. .setProjectId(project.getId());
  458. eventService.addNewEvent(projectEventAddNewDTO);
  459. }
  460. log.info("新增专题库完成");
  461. return project.getId();
  462. }
  463. @Transactional
  464. public String edit(Project project) throws IOException {
  465. //检查当前专题库的修改是否要修改产品
  466. Integer projectId = project.getId();
  467. Integer newProductId = project.getProductId();
  468. ProjectStandardVO queryResult = projectMapper.getStandardById(projectId);
  469. Integer oldProductId = queryResult.getProductId();
  470. //若当前产品id和原产品id不一致,则表示当前的修改要修改产品
  471. if ((newProductId != null && !newProductId.equals(oldProductId)) || (newProductId == null && oldProductId != null)) {
  472. //检查当前专题库产品架构是否已标引,若已标引则不允许修改产品
  473. int count = assoStructurePatentMapper.countByProjectId(projectId);
  474. if (count > 0) {
  475. String message = "修改专题库失败,该专题库产品或架构已被标引,无法更换产品或架构";
  476. log.info("{}", message);
  477. throw new XiaoShiException(message);
  478. }
  479. }
  480. Project temp = this.getProjectByName(project.getName());
  481. //检查尝试修改的新专题库名称是否被占用
  482. if (temp != null && !temp.getId().equals(project.getId())) {
  483. return Response.error("专题库名称已存在");
  484. }
  485. if (project.getClientId() == null || project.getClientId() == -1) {
  486. ClientDTO clientDTO = new ClientDTO();
  487. clientDTO.setName(project.getClientName());
  488. clientDTO.setTenantId(project.getTenantId());
  489. String res = requestService.addClient(clientDTO);
  490. JSONObject jsonObject = JSONObject.parseObject(res);
  491. Integer clientId = Integer.parseInt(jsonObject.get("data").toString());
  492. project.setClientId(clientId);
  493. }
  494. project.setScenario(StringUtils.join(project.getScenarioList(), ","));
  495. project.setType(StringUtils.join(project.getTypeList(), ","));
  496. //专题库表修改数据
  497. log.info("专题库表修改数据");
  498. project.updateById();
  499. return Response.success();
  500. }
  501. @Transactional
  502. public String delete(Integer id) {
  503. this.deleteProjectUser(id, loginUtils.getId());
  504. projectPatentLinkService.deleteByProjectId(id);
  505. projectFolderService.deleteByProjectId(id);
  506. projectFieldService.deleteByProjectId(id);
  507. projectUserService.deleteByProjectId(id);
  508. projectFileService.deleteByProjectId(id);
  509. patentApplicantMergeLinkService.deleteByProjectId(id);
  510. //陈宇 ↓ 删除专题库产品架构标引表(asso_structure_patent)数据
  511. assoStructurePatentMapper.deleteByProjectId(id);
  512. //陈宇 ↓ 删除任务表(os_task)和任务条件关联表(asso_osTask_qrtzTask)数据
  513. List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getProjectId, id));
  514. //陈宇 ↓ 删除任务表(os_task)数据
  515. taskService.removeByIds(tasks.stream().map(Task::getId).collect(Collectors.toList()));
  516. //陈宇 ↓ 若是网站导入任务则还要删除任务条件关联表(asso_osTask_qrtzTask)数据
  517. List<Integer> taskConditionIds = tasks.stream().filter(item -> item.getTaskConditionId() != null).map(Task::getTaskConditionId).collect(Collectors.toList());
  518. if (taskConditionIds.size() > 0) {
  519. taskConditionService.removeByIds(taskConditionIds);
  520. }
  521. this.removeById(id);
  522. return Response.success();
  523. }
  524. private Integer getNewClientId(String name) throws IOException {
  525. String res = requestService.getClientByName(name);
  526. ClientDTO client = JSONObject.parseObject(res, ClientDTO.class);
  527. Integer clientId = 0;
  528. if (client == null) {
  529. client.setName(name);
  530. String res2 = requestService.addClient(client);
  531. JSONObject jsonObject = JSONObject.parseObject(res2);
  532. clientId = Integer.parseInt(jsonObject.get("data").toString());
  533. } else {
  534. clientId = client.getId();
  535. }
  536. return clientId;
  537. }
  538. private void addProjectUser(Integer projectId) {
  539. ProjectUser user = new ProjectUser();
  540. user.setUserId(loginUtils.getId());
  541. user.setProjectId(projectId);
  542. user.setCreateTime(DateUtils.getDateTime());
  543. user.setType(2);
  544. user.insert();
  545. }
  546. private void deleteProjectUser(Integer projectId, Integer userId) {
  547. projectUserService.remove(Wrappers.<ProjectUser>lambdaQuery().eq(ProjectUser::getUserId, userId).eq(ProjectUser::getProjectId, projectId));
  548. }
  549. @Transactional(rollbackFor = Exception.class)
  550. public String importExcel(MultipartFile file) {
  551. try {
  552. PersonnelVO user = cacheUtils.getLoginUserPersonnel(loginUtils.getId());
  553. ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
  554. List<Map<String, Object>> readAll = reader.readAll();
  555. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.INVESTIGATION_TYPE, Constants.ENTERPRISE_APPLICATION_SCENARIO));
  556. for (Map<String, Object> row : readAll) {
  557. Project project = new Project();
  558. project.setSort(1);
  559. project.setName(row.get("专题库名称").toString());
  560. project.setClientId(this.getNewClientId(row.get("委托方").toString()));
  561. project.setRemark(row.get("备注").toString());
  562. project.setCreateBy(loginUtils.getId());
  563. project.setCreateTime(DateUtils.getDateTime());
  564. List<String> typeName = StringUtils.changeStringToString(row.get("调查类型").toString(), ";");
  565. 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());
  566. project.setType(StringUtils.join(typeList, ","));
  567. List<String> scenarioName = StringUtils.changeStringToString(row.get("企业应用场景").toString(), ";");
  568. 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());
  569. project.setScenario(StringUtils.join(scenarioList, ","));
  570. project.setTechnicalTheme(row.get("技术主题").toString());
  571. project.setContractNo(row.get("合同号").toString());
  572. project.setInnerFile(row.get("内部案卷").toString());
  573. Object caseDate = row.get("委案日");
  574. if (StringUtils.isNotNull(caseDate)) {
  575. project.setCaseDate(caseDate.toString());
  576. }
  577. project.setStatus(row.get("处理状态").toString().equals("处理中") ? "0" : "1");
  578. Object update = row.get("是否更新");
  579. if (StringUtils.isNotNull(update)) {
  580. project.setUpdate(update.toString().equals("是") ? 1 : 0);
  581. project.setUpdateTime(row.get("更新周期").toString());
  582. } else {
  583. project.setUpdate(0);
  584. project.setUpdateTime("一天");
  585. }
  586. project.insert();
  587. List<String> userName = StringUtils.changeStringToString(row.get("管理员").toString(), ";");
  588. List<User> userList = userService.getUserByNames(userName);
  589. List<ProjectUser> projectUserList = new ArrayList<>();
  590. userList.forEach(item -> {
  591. ProjectUser projectUser = new ProjectUser();
  592. projectUser.setProjectId(project.getId());
  593. projectUser.setUserId(item.getId());
  594. projectUser.setCreateTime(DateUtils.getDateTime());
  595. projectUser.setType(2);
  596. projectUserList.add(projectUser);
  597. });
  598. projectUserService.saveOrUpdateBatch(projectUserList);
  599. }
  600. return Response.success(true);
  601. } catch (Exception e) {
  602. e.printStackTrace();
  603. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  604. return Response.error();
  605. }
  606. }
  607. @Transactional
  608. public String share(Integer id, List<Integer> userIds, List<ProjectUser.User> users) {
  609. ProjectUser user = new ProjectUser();
  610. user.setType(3);
  611. user.setRemark("用户分享");
  612. user.setProjectId(id);
  613. user.setUserIds(userIds);
  614. user.setUsers(users);
  615. return projectUserService.add(user);
  616. }
  617. public TaskParams getImportPatentTaskParams(MultipartFile file, Integer projectId) {
  618. //将包含多件专利的Excel文件上传至本地,并返回文件对象fileDTO
  619. UploadFileDTO fileDTO = fileUtils.uploadFile(file);
  620. //获得文件路径
  621. String path = fileUtils.getPath(fileDTO.getPath());
  622. //创建集合rowList,准备装载Excel中所有行数据(元素个数=总行数,元素=行数据,第一个元素=表头行数据)
  623. List<List<Object>> rowList = new ArrayList<>();
  624. //集合mapList,准备装载Excel中的全部专利的数据(每一个元素的key:表头(如"公开号") value:表头对应的专利内容(如"CN204445352U"))
  625. List<Map<Object, Object>> mapList = new ArrayList<>();
  626. //使用excel工具类解析读取文件(通过Sax方式按行读取),将内容装载到集合rowList(元素数量=总行数,元素=行数据,第一个元素=表头行数据)
  627. ExcelUtil.readBySax(path, -1, (sheetIndex, rowIndex, row) -> rowList.add(row));
  628. //遍历rowList集合,将集合第一个元素(表头行内容)作为keys,其余元素(专利行内容)作为values,将键列表keys和值列表values转换为Map集合
  629. for (int i = 1; i < rowList.size(); i++) {
  630. mapList.add(IterUtil.toMap(rowList.get(0), rowList.get(i)));
  631. }
  632. //新增任务(专利导入导出任务表)
  633. Integer taskId = taskService.add(fileDTO, projectId, null, rowList.size() - 1, 1, 0, file.getOriginalFilename());
  634. TaskParams taskParams = new TaskParams();
  635. taskParams.setTaskId(taskId);
  636. taskParams.setPath(path);
  637. taskParams.setTaskType(1);
  638. taskParams.setRowList(mapList);
  639. taskParams.setUserId(String.valueOf(loginUtils.getId()));
  640. taskParams.setOldName(file.getOriginalFilename());
  641. return taskParams;
  642. }
  643. //获得
  644. public TaskParams getImportPatentTaskParamsBro(MultipartFile file, Integer productId) {
  645. //上传文档
  646. UploadFileDTO fileDTO = fileUtils.uploadFile(file);
  647. //获得文档保存的路径
  648. String path = fileUtils.getPath(fileDTO.getPath());
  649. List<List<Object>> rowList = new ArrayList<>();
  650. //解析excel文件并保存进map里
  651. List<Map<Object, Object>> mapList = new ArrayList<>();
  652. ExcelUtil.readBySax(path, -1, (sheetIndex, rowIndex, row) -> rowList.add(row));
  653. for (int i = 1; i < rowList.size(); i++) {
  654. mapList.add(IterUtil.toMap(rowList.get(0), rowList.get(i)));
  655. }
  656. Integer taskId = taskService.add(fileDTO, null, productId, rowList.size() - 1, 1, 0, file.getOriginalFilename());
  657. TaskParams taskParams = new TaskParams();
  658. taskParams.setPath(path);
  659. taskParams.setTaskId(taskId);
  660. taskParams.setTaskType(1);
  661. taskParams.setRowList(mapList);
  662. taskParams.setUserId(String.valueOf(loginUtils.getId()));
  663. taskParams.setOldName(file.getOriginalFilename());
  664. taskParams.setProductId(productId);
  665. return taskParams;
  666. }
  667. @Transactional(propagation = Propagation.NOT_SUPPORTED)
  668. public void setImportPatentTaskStatus(Integer status, Integer taskId) {
  669. taskService.updateStatus(taskId, status, DateUtils.getDateTime());
  670. }
  671. public void saveDataToJsonFile(String tempPath, String fileName, String data) throws IOException {
  672. String path = tempPath + FileUtils.FILE_SEPARATOR + fileName;
  673. FileOutputStream fileOutputStream = new FileOutputStream(path);
  674. fileOutputStream.write(data.getBytes(StandardCharsets.UTF_8));
  675. fileOutputStream.close();
  676. }
  677. public void copyFileToTempDirectory(String src, String tempPath, String directoryName, String fileName) {
  678. String dest = tempPath + FileUtils.FILE_SEPARATOR + directoryName + FileUtils.FILE_SEPARATOR + fileName;
  679. File file = FileUtil.file(fileUtils.getSystemPath(src));
  680. if (FileUtil.exist(file)) {
  681. FileUtil.copy(file, new File(dest), true);
  682. }
  683. }
  684. @Async
  685. public void export(ProjectExportVO params, Integer exportId, Integer userId) {
  686. try {
  687. String json = cacheUtils.getSelectPatentIds(params.getKey());
  688. List<Integer> patentIds = StringUtils.changeStringToInteger(json, ",");
  689. List<Patent> patentList = patentService.getPatentListByIds(patentIds);
  690. String directoryName = IdUtil.simpleUUID();
  691. String fileName = directoryName + ".zip";
  692. String tempPath = fileUtils.getTempPath(directoryName);
  693. String url = fileUtils.getDirectory(fileName);
  694. String savePath = fileUtils.getSystemPath(url);
  695. File directory = new File(tempPath);
  696. if (!directory.exists()) {
  697. boolean success = directory.mkdir();
  698. if (!success) {
  699. throw new Exception("数据导出时创建文件夹失败");
  700. }
  701. }
  702. WebSocketServer.sendInfo(Response.websocket(true, ResponseEnum.PROJECT_EXPORT_TASK_SUCCESS), String.valueOf(userId));
  703. if (params.getProjectInfo()) {
  704. Project project = this.getProjectById(params.getProjectId());
  705. this.saveDataToJsonFile(tempPath, Constants.PROJECT_INFO_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(project)));
  706. }
  707. if (params.getProjectReport() != null && params.getProjectReport().size() != 0) {
  708. List<ProjectFile> projectFileList = projectFileService.getProjectFileByIds(params.getProjectReport());
  709. this.saveDataToJsonFile(tempPath, Constants.PROJECT_REPORT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFileList)));
  710. projectFileList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PROJECT_REPORT_DIRECTORY_NAME, item.getFileName()));
  711. }
  712. if (params.getProjectFile() != null && params.getProjectFile().size() != 0) {
  713. List<ProjectFile> projectFileList = projectFileService.getProjectFileByIds(params.getProjectFile());
  714. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FILE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFileList)));
  715. projectFileList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PROJECT_FILE_DIRECTORY_NAME, item.getFileName()));
  716. }
  717. if (params.getPatentImage()) {
  718. List<PatentImage> patentImageList = patentImageService.getPatentImageByPatentIds(patentIds);
  719. this.saveDataToJsonFile(tempPath, Constants.PATENT_IMAGE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentImageList)));
  720. patentImageList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PATENT_IMAGE_DIRECTORY_NAME, item.getFileName()));
  721. }
  722. if (params.getPatentInstruction()) {
  723. List<String> patentNo = patentList.stream().map(Patent::getPatentNo).collect(Collectors.toList());
  724. List<PatentInstruction> patentInstructionList = patentInstructionService.getPatentInstructionByPatentNo(patentNo);
  725. this.saveDataToJsonFile(tempPath, Constants.PATENT_INSTRUCTION_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInstructionList)));
  726. patentInstructionList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PATENT_INSTRUCTION_DIRECTORY_NAME, item.getFileName()));
  727. }
  728. if (params.getPatentBase()) {
  729. List<PatentApplicantLink> patentApplicantLinkList = patentApplicantLinkService.getApplicantAttributesListByPatentIds(patentIds);
  730. List<PatentApplicantMergeLink> patentApplicantMergeLinkList = patentApplicantMergeLinkService.getPatentApplicantMergeLinkListByProjectId(params.getProjectId());
  731. List<Integer> patentApplicantIds = new ArrayList<>();
  732. patentApplicantLinkList.forEach(item -> patentApplicantIds.add(item.getApplicantId()));
  733. patentApplicantMergeLinkList.forEach(item -> patentApplicantIds.add(item.getMergeId()));
  734. List<PatentApplicant> patentApplicantList = patentApplicantService.getPatentApplicantByIds(patentApplicantIds);
  735. List<PatentAffair> patentAffairList = patentAffairService.getPatentAffairListByPatentIds(patentIds);
  736. List<PatentAgency> patentAgencyList = patentAgencyService.getPatentAgencyByIds(patentList.stream().filter(item -> StringUtils.isNotEmpty(item.getAgencyId())).map(item -> Integer.parseInt(item.getAgencyId())).collect(Collectors.toList()));
  737. List<PatentAgentLink> patentAgentLinkList = patentAgentLinkService.getPatentAgentLinkByPatentIds(patentIds);
  738. List<PatentAgent> patentAgentList = patentAgentService.getPatentAgentByIds(patentAgentLinkList.stream().map(PatentAgentLink::getAgentId).collect(Collectors.toList()));
  739. List<PatentInstructionText> patentInstructionTextList = patentInstructionTextService.getPatentInstructionTextByPatentIds(patentIds);
  740. List<PatentInventorLink> patentInventorLinkList = patentInventorLinkService.getPatentInventorLinkByPatentIds(patentIds);
  741. List<PatentInventorMerge> patentInventorMergeList = patentInventorMergeService.getPatentInventorMergeByProjectId(params.getProjectId());
  742. List<Integer> patentInventorIds = new ArrayList<>();
  743. patentInventorLinkList.forEach(item -> patentInventorIds.add(item.getInventorId()));
  744. patentInventorMergeList.forEach(item -> patentInventorIds.add(item.getMergeId()));
  745. List<PatentInventor> patentInventorList = patentInventorService.getPatentInventorByIds(patentInventorIds);
  746. List<PatentLicensor> patentLicensorList = patentLicensorService.getPatentLicensorByPatentIds(patentIds);
  747. List<PatentPledge> patentPledgeList = patentPledgeService.getPatentPledgeByPatentIds(patentIds);
  748. List<PatentRight> patentRightList = patentRightService.getPatentRightByPatentIds(patentIds);
  749. List<Integer> patentFamilyIds = new ArrayList<>();
  750. patentList.forEach(item -> {
  751. patentFamilyIds.add(item.getSimpleFamily());
  752. patentFamilyIds.add(item.getInpadocFamily());
  753. patentFamilyIds.add(item.getPatSnapFamily());
  754. });
  755. List<PatentSimpleFamilyLink> patentSimpleFamilyLinkList = patentSimpleFamilyLinkService.getPatentSimpleFamilyLinkByFamilyIds(patentFamilyIds);
  756. List<PatentSimpleFamily> patentSimpleFamilyList = patentSimpleFamilyService.getPatentSimpleFamilyByIds(patentFamilyIds);
  757. List<PatentClassNumberLink> patentClassNumberLinkList = patentClassNumberLinkService.getPatentClassNumberLinkByPatentIds(patentIds);
  758. this.saveDataToJsonFile(tempPath, Constants.PATENT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentList)));
  759. this.saveDataToJsonFile(tempPath, Constants.PATENT_AFFAIR_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAffairList)));
  760. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENCY_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAgencyList)));
  761. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENT_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAgentLinkList)));
  762. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAgentList)));
  763. this.saveDataToJsonFile(tempPath, Constants.PATENT_INSTRUCTION_TEXT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInstructionTextList)));
  764. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInventorLinkList)));
  765. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInventorList)));
  766. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_MERGE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInventorMergeList)));
  767. this.saveDataToJsonFile(tempPath, Constants.PATENT_LICENSOR_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentLicensorList)));
  768. this.saveDataToJsonFile(tempPath, Constants.PATENT_PLEDGE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentPledgeList)));
  769. this.saveDataToJsonFile(tempPath, Constants.PATENT_RIGHT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentRightList)));
  770. this.saveDataToJsonFile(tempPath, Constants.PATENT_FAMILY_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentSimpleFamilyLinkList)));
  771. this.saveDataToJsonFile(tempPath, Constants.PATENT_FAMILY_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentSimpleFamilyList)));
  772. this.saveDataToJsonFile(tempPath, Constants.PATENT_CLASS_NUMBER_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentClassNumberLinkList)));
  773. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentApplicantList)));
  774. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentApplicantLinkList)));
  775. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_MERGE_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentApplicantMergeLinkList)));
  776. }
  777. if (params.getPatentField() != null && params.getPatentField().size() != 0) {
  778. if (params.getPatentField().contains(0)) {
  779. List<PatentLabel> patentLabelList = patentLabelService.getPatentLabelByPatentIdsAndProjectId(patentIds, params.getProjectId());
  780. this.saveDataToJsonFile(tempPath, Constants.PATENT_LABEL_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentLabelList)));
  781. }
  782. List<ProjectField> projectFieldList = projectFieldService.getFieldListByIds(params.getPatentField());
  783. List<Integer> projectFieldIds = projectFieldList.stream().map(ProjectField::getId).collect(Collectors.toList());
  784. List<ProjectFieldOption> projectFieldOptionList = projectFieldOptionService.getFieldOptionList(projectFieldIds);
  785. List<ProjectFieldTree> projectFieldTreeList = projectFieldTreeService.getProjectFieldTreeOptionByFieldIds(projectFieldIds);
  786. List<ProjectFieldText> projectFieldTextList = projectFieldTextService.getProjectFieldTextByFieldIds(projectFieldIds);
  787. List<ProjectFieldPatentLink> projectFieldPatentLinkList = new ArrayList<>();
  788. for (Integer fieldId : params.getPatentField()) {
  789. projectFieldPatentLinkList.addAll(projectFieldPatentLinkService.getProjectPatentLinkByPatentIdsAndFieldId(patentIds, fieldId));
  790. }
  791. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldList)));
  792. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_OPTION_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldOptionList)));
  793. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_TREE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldTreeList)));
  794. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_TEXT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldTextList)));
  795. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_PATENT_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldPatentLinkList)));
  796. }
  797. List<Patent> patents = patentService.getPatentIdAndPatentNoByIds(patentIds);
  798. this.saveDataToJsonFile(tempPath, Constants.PATENT_ID_PATENT_NO_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patents)));
  799. File file = ZipUtil.zip(tempPath, savePath);
  800. FileUtil.del(tempPath);
  801. ProjectExport projectExport = projectExportService.getById(exportId);
  802. projectExport.setUrl(url);
  803. projectExport.setFileName(fileName);
  804. projectExport.setStatus(1);
  805. projectExport.setFileSize(FileUtil.size(file));
  806. projectExport.updateById();
  807. WebSocketServer.sendInfo(Response.websocket(true, ResponseEnum.PROJECT_EXPORT_TASK_SUCCESS), String.valueOf(userId));
  808. } catch (Exception e) {
  809. e.printStackTrace();
  810. WebSocketServer.sendInfo(Response.websocket(false, ResponseEnum.PROJECT_EXPORT_TASK_ERROR), String.valueOf(userId));
  811. }
  812. }
  813. @Async("singleThreadAsyncTaskExecutor")
  814. @Transactional(rollbackFor = Exception.class)
  815. public void importData(String url, ProjectImportVO params, Integer userId, Integer importId) {
  816. String tempPath = null;
  817. ProjectImportStatusService projectImportStatusService = SpringUtil.getBean(ProjectImportStatusService.class);
  818. try {
  819. String tempDirectoryName = IdUtil.simpleUUID();
  820. tempPath = fileUtils.getTempPath(tempDirectoryName);
  821. String tempSavePath = fileUtils.getSystemPath(url);
  822. File tempDirectory = new File(tempPath);
  823. if (!tempDirectory.exists()) {
  824. boolean success = tempDirectory.mkdir();
  825. if (!success) {
  826. throw new Exception("数据导入时创建文件夹失败");
  827. }
  828. }
  829. projectImportStatusService.add(importId, userId, 2);
  830. ZipUtil.unzip(tempSavePath, tempPath);
  831. String projectJson = this.parseTempFileData(tempPath, Constants.PROJECT_INFO_FILE_NAME);
  832. Integer projectId = params.getProjectId();
  833. if (StringUtils.isNotEmpty(projectJson)) {
  834. projectImportStatusService.add(importId, userId, 3);
  835. projectId = this.importProject(params.getProjectId(), projectJson, userId);
  836. }
  837. if (projectId.equals(0)) {
  838. projectImportStatusService.add(importId, userId, 100);
  839. throw new CustomException("数据包未包含专题库信息");
  840. }
  841. String projectReportJson = this.parseTempFileData(tempPath, Constants.PROJECT_REPORT_FILE_NAME);
  842. String projectFileJson = this.parseTempFileData(tempPath, Constants.PROJECT_FILE_FILE_NAME);
  843. if (StringUtils.isNotEmpty(projectReportJson) || StringUtils.isNotEmpty(projectFileJson)) {
  844. projectImportStatusService.add(importId, userId, 4);
  845. projectFileService.importProjectFile(projectId, userId, tempPath, projectFileJson, projectReportJson);
  846. }
  847. String patentIdPatentNoJson = this.parseTempFileData(tempPath, Constants.PATENT_ID_PATENT_NO_FILE_NAME);
  848. String patentJson = this.parseTempFileData(tempPath, Constants.PATENT_FILE_NAME);
  849. String patentAffairJson = this.parseTempFileData(tempPath, Constants.PATENT_AFFAIR_FILE_NAME);
  850. String patentAgencyJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENCY_FILE_NAME);
  851. String patentAgentJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENT_FILE_NAME);
  852. String patentAgentLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENT_LINK_FILE_NAME);
  853. String patentInventorJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_FILE_NAME);
  854. String patentInventorMergeJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_MERGE_FILE_NAME);
  855. String patentInventorLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_LINK_FILE_NAME);
  856. String patentApplicantJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_FILE_NAME);
  857. String patentApplicantLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_LINK_FILE_NAME);
  858. String patentApplicantMergeLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_MERGE_LINK_FILE_NAME);
  859. String patentFamilyJson = this.parseTempFileData(tempPath, Constants.PATENT_FAMILY_FILE_NAME);
  860. String patentFamilyLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_FAMILY_LINK_FILE_NAME);
  861. String patentClassNumberJson = this.parseTempFileData(tempPath, Constants.PATENT_CLASS_NUMBER_FILE_NAME);
  862. String patentInstructionTextJson = this.parseTempFileData(tempPath, Constants.PATENT_INSTRUCTION_TEXT_FILE_NAME);
  863. String patentRightJson = this.parseTempFileData(tempPath, Constants.PATENT_RIGHT_FILE_NAME);
  864. String patentLicensorJson = this.parseTempFileData(tempPath, Constants.PATENT_LICENSOR_FILE_NAME);
  865. String patentPledgeJson = this.parseTempFileData(tempPath, Constants.PATENT_PLEDGE_FILE_NAME);
  866. if (StringUtils.isNotEmpty(patentJson)) {
  867. projectImportStatusService.add(importId, userId, 8);
  868. patentService.importPatent(projectId, patentJson, patentAffairJson, patentAgencyJson, patentFamilyJson, patentFamilyLinkJson, patentInventorJson, patentInventorLinkJson, patentAgentJson, patentAgentLinkJson, patentApplicantJson, patentApplicantLinkJson, patentApplicantMergeLinkJson, patentClassNumberJson, patentInstructionTextJson, patentRightJson, patentLicensorJson, patentPledgeJson, patentInventorMergeJson);
  869. }
  870. projectImportStatusService.add(importId, userId, 9);
  871. projectPatentLinkService.importProjectPatentLink(projectId, patentIdPatentNoJson);
  872. String projectFieldJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_FILE_NAME);
  873. if (StringUtils.isNotEmpty(projectFieldJson)) {
  874. String projectFieldTextJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_TEXT_FILE_NAME);
  875. String projectFieldOptionJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_OPTION_FILE_NAME);
  876. String projectFieldTreeJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_TREE_FILE_NAME);
  877. String projectFieldPatentLink = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_PATENT_LINK_FILE_NAME);
  878. projectImportStatusService.add(importId, userId, 5);
  879. projectFieldService.importProjectField(projectId, userId, patentIdPatentNoJson, projectFieldJson, projectFieldTextJson, projectFieldOptionJson, projectFieldTreeJson, projectFieldPatentLink);
  880. }
  881. String patentImageJson = this.parseTempFileData(tempPath, Constants.PATENT_IMAGE_FILE_NAME);
  882. if (StringUtils.isNotEmpty(patentImageJson)) {
  883. projectImportStatusService.add(importId, userId, 6);
  884. patentImageService.importPatentImage(tempPath, patentIdPatentNoJson, patentImageJson);
  885. }
  886. String patentInstructionJson = this.parseTempFileData(tempPath, Constants.PATENT_INSTRUCTION_FILE_NAME);
  887. if (StringUtils.isNotEmpty(patentInstructionJson)) {
  888. projectImportStatusService.add(importId, userId, 7);
  889. patentInstructionService.importPatentInstruction(userId, tempPath, patentIdPatentNoJson, patentInstructionJson);
  890. }
  891. } catch (Exception e) {
  892. e.printStackTrace();
  893. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  894. projectImportStatusService.add(importId, userId, 101);
  895. } finally {
  896. FileUtil.del(tempPath);
  897. projectImportStatusService.add(importId, userId, 200);
  898. cacheUtils.deleteUserImport(userId);
  899. }
  900. }
  901. private String parseTempFileData(String path, String fileName) throws IOException {
  902. String src = path + FileUtil.FILE_SEPARATOR + fileName;
  903. if (!FileUtil.exist(src)) {
  904. return null;
  905. }
  906. File file = new File(src);
  907. FileReader fileReader = new FileReader(file);
  908. Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
  909. int ch;
  910. StringBuffer sb = new StringBuffer();
  911. while ((ch = reader.read()) != -1) {
  912. sb.append((char) ch);
  913. }
  914. fileReader.close();
  915. reader.close();
  916. return sb.toString();
  917. }
  918. //主页面 导出列表功能
  919. public void exportProject(HttpServletResponse response) {
  920. try {
  921. ProjectVO params = new ProjectVO();
  922. params.setSize(99999999999L);
  923. params.setCurrent(1L);
  924. params.setMyself(false);
  925. ProjectVO.Sort sort = new ProjectVO.Sort();
  926. sort.setProp("create_time");
  927. sort.setOrder("desc");
  928. params.setSort(sort);
  929. IPage<Project> pageList = this.getPageList(params);
  930. List<Project> projectList = pageList.getRecords();
  931. List<List<String>> row = new ArrayList<>();
  932. row.add(CollUtil.newArrayList("#", "名称", "委托方", "调查类型", "应用场景", "技术主题", "合同号", "委案日", "创建人"));
  933. for (int i = 0; i < projectList.size(); i++) {
  934. Project project = projectList.get(i);
  935. 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()));
  936. }
  937. List<List<String>> rows = CollUtil.newArrayList(row);
  938. ExcelWriter writer = ExcelUtil.getWriter(true);
  939. OutputStream out = response.getOutputStream();
  940. writer.write(rows, true);
  941. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  942. response.setHeader("Content-Disposition", "attachment;filename=" + IdUtil.simpleUUID() + ".xlsx");
  943. writer.flush(out, true);
  944. writer.close();
  945. IoUtil.close(out);
  946. } catch (Exception e) {
  947. e.printStackTrace();
  948. }
  949. }
  950. /**
  951. * @param projectCopyDTO
  952. * @return
  953. * @throws IOException
  954. * @deprecated 复制专题库
  955. */
  956. @Transactional
  957. public Integer copy(ProjectCopyDTO projectCopyDTO) throws IOException {
  958. Integer oldId = projectCopyDTO.getId();
  959. //复制专题库基本信息
  960. Project project = this.getById(oldId);
  961. project.setTenantId(projectCopyDTO.getTenantId());
  962. project.setId(null);
  963. project.insert();
  964. //复制专题库专利
  965. LambdaQueryWrapper<ProjectPatentLink> patentLinkWrapper = new LambdaQueryWrapper<>();
  966. patentLinkWrapper.eq(ProjectPatentLink::getProjectId, oldId);
  967. List<ProjectPatentLink> projectPatentLinkList = projectPatentLinkService.list(patentLinkWrapper);
  968. projectPatentLinkList.forEach(
  969. item -> {
  970. item.setProjectId(project.getId());
  971. item.setId(null);
  972. }
  973. );
  974. projectPatentLinkService.saveBatch(projectPatentLinkList);
  975. //复制专题库标引信息
  976. copyService.CopyPatentLabels(oldId, project.getId());
  977. //复制专题库文件夹
  978. copyService.CopyProjectFolder(oldId, project.getId());
  979. return project.getId();
  980. }
  981. }