ProjectService.java 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  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)) {
  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. //专题库表删除数据
  504. log.info("专题库表删除数据");
  505. this.removeById(id);
  506. this.deleteProjectUser(id, loginUtils.getId());
  507. projectPatentLinkService.deleteByProjectId(id);
  508. projectFolderService.deleteByProjectId(id);
  509. projectFieldService.deleteByProjectId(id);
  510. projectUserService.deleteByProjectId(id);
  511. projectFileService.deleteByProjectId(id);
  512. patentApplicantMergeLinkService.deleteByProjectId(id);
  513. //陈宇 ↓ 删除专题库产品架构标引表(asso_structure_patent)数据
  514. assoStructurePatentMapper.deleteByProjectId(id);
  515. //陈宇 ↓ 删除任务表(os_task)和任务条件关联表(asso_osTask_qrtzTask)数据
  516. List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getProjectId, id));
  517. //陈宇 ↓ 删除任务表(os_task)数据
  518. taskService.removeByIds(tasks.stream().map(Task::getId).collect(Collectors.toList()));
  519. //陈宇 ↓ 若是网站导入任务则还要删除任务条件关联表(asso_osTask_qrtzTask)数据
  520. List<Integer> taskConditionIds = tasks.stream().filter(item -> item.getTaskConditionId() != null).map(Task::getTaskConditionId).collect(Collectors.toList());
  521. if (taskConditionIds.size() > 0) {
  522. taskConditionService.removeByIds(taskConditionIds);
  523. }
  524. return Response.success();
  525. }
  526. private Integer getNewClientId(String name) throws IOException {
  527. String res = requestService.getClientByName(name);
  528. ClientDTO client = JSONObject.parseObject(res, ClientDTO.class);
  529. Integer clientId = 0;
  530. if (client == null) {
  531. client.setName(name);
  532. String res2 = requestService.addClient(client);
  533. JSONObject jsonObject = JSONObject.parseObject(res2);
  534. clientId = Integer.parseInt(jsonObject.get("data").toString());
  535. } else {
  536. clientId = client.getId();
  537. }
  538. return clientId;
  539. }
  540. private void addProjectUser(Integer projectId) {
  541. ProjectUser user = new ProjectUser();
  542. user.setUserId(loginUtils.getId());
  543. user.setProjectId(projectId);
  544. user.setCreateTime(DateUtils.getDateTime());
  545. user.setType(2);
  546. user.insert();
  547. }
  548. private void deleteProjectUser(Integer projectId, Integer userId) {
  549. projectUserService.remove(Wrappers.<ProjectUser>lambdaQuery().eq(ProjectUser::getUserId, userId).eq(ProjectUser::getProjectId, projectId));
  550. }
  551. @Transactional(rollbackFor = Exception.class)
  552. public String importExcel(MultipartFile file) {
  553. try {
  554. PersonnelVO user = cacheUtils.getLoginUserPersonnel(loginUtils.getId());
  555. ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
  556. List<Map<String, Object>> readAll = reader.readAll();
  557. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.INVESTIGATION_TYPE, Constants.ENTERPRISE_APPLICATION_SCENARIO));
  558. for (Map<String, Object> row : readAll) {
  559. Project project = new Project();
  560. project.setSort(1);
  561. project.setName(row.get("专题库名称").toString());
  562. project.setClientId(this.getNewClientId(row.get("委托方").toString()));
  563. project.setRemark(row.get("备注").toString());
  564. project.setCreateBy(loginUtils.getId());
  565. project.setCreateTime(DateUtils.getDateTime());
  566. List<String> typeName = StringUtils.changeStringToString(row.get("调查类型").toString(), ";");
  567. 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());
  568. project.setType(StringUtils.join(typeList, ","));
  569. List<String> scenarioName = StringUtils.changeStringToString(row.get("企业应用场景").toString(), ";");
  570. 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());
  571. project.setScenario(StringUtils.join(scenarioList, ","));
  572. project.setTechnicalTheme(row.get("技术主题").toString());
  573. project.setContractNo(row.get("合同号").toString());
  574. project.setInnerFile(row.get("内部案卷").toString());
  575. Object caseDate = row.get("委案日");
  576. if (StringUtils.isNotNull(caseDate)) {
  577. project.setCaseDate(caseDate.toString());
  578. }
  579. project.setStatus(row.get("处理状态").toString().equals("处理中") ? "0" : "1");
  580. Object update = row.get("是否更新");
  581. if (StringUtils.isNotNull(update)) {
  582. project.setUpdate(update.toString().equals("是") ? 1 : 0);
  583. project.setUpdateTime(row.get("更新周期").toString());
  584. } else {
  585. project.setUpdate(0);
  586. project.setUpdateTime("一天");
  587. }
  588. project.insert();
  589. List<String> userName = StringUtils.changeStringToString(row.get("管理员").toString(), ";");
  590. List<User> userList = userService.getUserByNames(userName);
  591. List<ProjectUser> projectUserList = new ArrayList<>();
  592. userList.forEach(item -> {
  593. ProjectUser projectUser = new ProjectUser();
  594. projectUser.setProjectId(project.getId());
  595. projectUser.setUserId(item.getId());
  596. projectUser.setCreateTime(DateUtils.getDateTime());
  597. projectUser.setType(2);
  598. projectUserList.add(projectUser);
  599. });
  600. projectUserService.saveOrUpdateBatch(projectUserList);
  601. }
  602. return Response.success(true);
  603. } catch (Exception e) {
  604. e.printStackTrace();
  605. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  606. return Response.error();
  607. }
  608. }
  609. @Transactional
  610. public String share(Integer id, List<Integer> userIds, List<ProjectUser.User> users) {
  611. ProjectUser user = new ProjectUser();
  612. user.setType(3);
  613. user.setRemark("用户分享");
  614. user.setProjectId(id);
  615. user.setUserIds(userIds);
  616. user.setUsers(users);
  617. return projectUserService.add(user);
  618. }
  619. public TaskParams getImportPatentTaskParams(MultipartFile file, Integer projectId) {
  620. //将包含多件专利的Excel文件上传至本地,并返回文件对象fileDTO
  621. UploadFileDTO fileDTO = fileUtils.uploadFile(file);
  622. //获得文件路径
  623. String path = fileUtils.getPath(fileDTO.getPath());
  624. //创建集合rowList,准备装载Excel中所有行数据(元素个数=总行数,元素=行数据,第一个元素=表头行数据)
  625. List<List<Object>> rowList = new ArrayList<>();
  626. //集合mapList,准备装载Excel中的全部专利的数据(每一个元素的key:表头(如"公开号") value:表头对应的专利内容(如"CN204445352U"))
  627. List<Map<Object, Object>> mapList = new ArrayList<>();
  628. //使用excel工具类解析读取文件(通过Sax方式按行读取),将内容装载到集合rowList(元素数量=总行数,元素=行数据,第一个元素=表头行数据)
  629. ExcelUtil.readBySax(path, -1, (sheetIndex, rowIndex, row) -> rowList.add(row));
  630. //遍历rowList集合,将集合第一个元素(表头行内容)作为keys,其余元素(专利行内容)作为values,将键列表keys和值列表values转换为Map集合
  631. for (int i = 1; i < rowList.size(); i++) {
  632. mapList.add(IterUtil.toMap(rowList.get(0), rowList.get(i)));
  633. }
  634. //新增任务(专利导入导出任务表)
  635. Integer taskId = taskService.add(fileDTO, projectId, null, rowList.size() - 1, 1, 0, file.getOriginalFilename());
  636. TaskParams taskParams = new TaskParams();
  637. taskParams.setTaskId(taskId);
  638. taskParams.setPath(path);
  639. taskParams.setTaskType(1);
  640. taskParams.setRowList(mapList);
  641. taskParams.setUserId(String.valueOf(loginUtils.getId()));
  642. taskParams.setOldName(file.getOriginalFilename());
  643. return taskParams;
  644. }
  645. //获得
  646. public TaskParams getImportPatentTaskParamsBro(MultipartFile file, Integer productId) {
  647. //上传文档
  648. UploadFileDTO fileDTO = fileUtils.uploadFile(file);
  649. //获得文档保存的路径
  650. String path = fileUtils.getPath(fileDTO.getPath());
  651. List<List<Object>> rowList = new ArrayList<>();
  652. //解析excel文件并保存进map里
  653. List<Map<Object, Object>> mapList = new ArrayList<>();
  654. ExcelUtil.readBySax(path, -1, (sheetIndex, rowIndex, row) -> rowList.add(row));
  655. for (int i = 1; i < rowList.size(); i++) {
  656. mapList.add(IterUtil.toMap(rowList.get(0), rowList.get(i)));
  657. }
  658. Integer taskId = taskService.add(fileDTO, null, productId, rowList.size() - 1, 1, 0, file.getOriginalFilename());
  659. TaskParams taskParams = new TaskParams();
  660. taskParams.setPath(path);
  661. taskParams.setTaskId(taskId);
  662. taskParams.setTaskType(1);
  663. taskParams.setRowList(mapList);
  664. taskParams.setUserId(String.valueOf(loginUtils.getId()));
  665. taskParams.setOldName(file.getOriginalFilename());
  666. taskParams.setProductId(productId);
  667. return taskParams;
  668. }
  669. @Transactional(propagation = Propagation.NOT_SUPPORTED)
  670. public void setImportPatentTaskStatus(Integer status, Integer taskId) {
  671. taskService.updateStatus(taskId, status, DateUtils.getDateTime());
  672. }
  673. public void saveDataToJsonFile(String tempPath, String fileName, String data) throws IOException {
  674. String path = tempPath + FileUtils.FILE_SEPARATOR + fileName;
  675. FileOutputStream fileOutputStream = new FileOutputStream(path);
  676. fileOutputStream.write(data.getBytes(StandardCharsets.UTF_8));
  677. fileOutputStream.close();
  678. }
  679. public void copyFileToTempDirectory(String src, String tempPath, String directoryName, String fileName) {
  680. String dest = tempPath + FileUtils.FILE_SEPARATOR + directoryName + FileUtils.FILE_SEPARATOR + fileName;
  681. File file = FileUtil.file(fileUtils.getSystemPath(src));
  682. if (FileUtil.exist(file)) {
  683. FileUtil.copy(file, new File(dest), true);
  684. }
  685. }
  686. @Async
  687. public void export(ProjectExportVO params, Integer exportId, Integer userId) {
  688. try {
  689. String json = cacheUtils.getSelectPatentIds(params.getKey());
  690. List<Integer> patentIds = StringUtils.changeStringToInteger(json, ",");
  691. List<Patent> patentList = patentService.getPatentListByIds(patentIds);
  692. String directoryName = IdUtil.simpleUUID();
  693. String fileName = directoryName + ".zip";
  694. String tempPath = fileUtils.getTempPath(directoryName);
  695. String url = fileUtils.getDirectory(fileName);
  696. String savePath = fileUtils.getSystemPath(url);
  697. File directory = new File(tempPath);
  698. if (!directory.exists()) {
  699. boolean success = directory.mkdir();
  700. if (!success) {
  701. throw new Exception("数据导出时创建文件夹失败");
  702. }
  703. }
  704. WebSocketServer.sendInfo(Response.websocket(true, ResponseEnum.PROJECT_EXPORT_TASK_SUCCESS), String.valueOf(userId));
  705. if (params.getProjectInfo()) {
  706. Project project = this.getProjectById(params.getProjectId());
  707. this.saveDataToJsonFile(tempPath, Constants.PROJECT_INFO_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(project)));
  708. }
  709. if (params.getProjectReport() != null && params.getProjectReport().size() != 0) {
  710. List<ProjectFile> projectFileList = projectFileService.getProjectFileByIds(params.getProjectReport());
  711. this.saveDataToJsonFile(tempPath, Constants.PROJECT_REPORT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFileList)));
  712. projectFileList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PROJECT_REPORT_DIRECTORY_NAME, item.getFileName()));
  713. }
  714. if (params.getProjectFile() != null && params.getProjectFile().size() != 0) {
  715. List<ProjectFile> projectFileList = projectFileService.getProjectFileByIds(params.getProjectFile());
  716. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FILE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFileList)));
  717. projectFileList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PROJECT_FILE_DIRECTORY_NAME, item.getFileName()));
  718. }
  719. if (params.getPatentImage()) {
  720. List<PatentImage> patentImageList = patentImageService.getPatentImageByPatentIds(patentIds);
  721. this.saveDataToJsonFile(tempPath, Constants.PATENT_IMAGE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentImageList)));
  722. patentImageList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PATENT_IMAGE_DIRECTORY_NAME, item.getFileName()));
  723. }
  724. if (params.getPatentInstruction()) {
  725. List<String> patentNo = patentList.stream().map(Patent::getPatentNo).collect(Collectors.toList());
  726. List<PatentInstruction> patentInstructionList = patentInstructionService.getPatentInstructionByPatentNo(patentNo);
  727. this.saveDataToJsonFile(tempPath, Constants.PATENT_INSTRUCTION_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInstructionList)));
  728. patentInstructionList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PATENT_INSTRUCTION_DIRECTORY_NAME, item.getFileName()));
  729. }
  730. if (params.getPatentBase()) {
  731. List<PatentApplicantLink> patentApplicantLinkList = patentApplicantLinkService.getApplicantAttributesListByPatentIds(patentIds);
  732. List<PatentApplicantMergeLink> patentApplicantMergeLinkList = patentApplicantMergeLinkService.getPatentApplicantMergeLinkListByProjectId(params.getProjectId());
  733. List<Integer> patentApplicantIds = new ArrayList<>();
  734. patentApplicantLinkList.forEach(item -> patentApplicantIds.add(item.getApplicantId()));
  735. patentApplicantMergeLinkList.forEach(item -> patentApplicantIds.add(item.getMergeId()));
  736. List<PatentApplicant> patentApplicantList = patentApplicantService.getPatentApplicantByIds(patentApplicantIds);
  737. List<PatentAffair> patentAffairList = patentAffairService.getPatentAffairListByPatentIds(patentIds);
  738. List<PatentAgency> patentAgencyList = patentAgencyService.getPatentAgencyByIds(patentList.stream().filter(item -> StringUtils.isNotEmpty(item.getAgencyId())).map(item -> Integer.parseInt(item.getAgencyId())).collect(Collectors.toList()));
  739. List<PatentAgentLink> patentAgentLinkList = patentAgentLinkService.getPatentAgentLinkByPatentIds(patentIds);
  740. List<PatentAgent> patentAgentList = patentAgentService.getPatentAgentByIds(patentAgentLinkList.stream().map(PatentAgentLink::getAgentId).collect(Collectors.toList()));
  741. List<PatentInstructionText> patentInstructionTextList = patentInstructionTextService.getPatentInstructionTextByPatentIds(patentIds);
  742. List<PatentInventorLink> patentInventorLinkList = patentInventorLinkService.getPatentInventorLinkByPatentIds(patentIds);
  743. List<PatentInventorMerge> patentInventorMergeList = patentInventorMergeService.getPatentInventorMergeByProjectId(params.getProjectId());
  744. List<Integer> patentInventorIds = new ArrayList<>();
  745. patentInventorLinkList.forEach(item -> patentInventorIds.add(item.getInventorId()));
  746. patentInventorMergeList.forEach(item -> patentInventorIds.add(item.getMergeId()));
  747. List<PatentInventor> patentInventorList = patentInventorService.getPatentInventorByIds(patentInventorIds);
  748. List<PatentLicensor> patentLicensorList = patentLicensorService.getPatentLicensorByPatentIds(patentIds);
  749. List<PatentPledge> patentPledgeList = patentPledgeService.getPatentPledgeByPatentIds(patentIds);
  750. List<PatentRight> patentRightList = patentRightService.getPatentRightByPatentIds(patentIds);
  751. List<Integer> patentFamilyIds = new ArrayList<>();
  752. patentList.forEach(item -> {
  753. patentFamilyIds.add(item.getSimpleFamily());
  754. patentFamilyIds.add(item.getInpadocFamily());
  755. patentFamilyIds.add(item.getPatSnapFamily());
  756. });
  757. List<PatentSimpleFamilyLink> patentSimpleFamilyLinkList = patentSimpleFamilyLinkService.getPatentSimpleFamilyLinkByFamilyIds(patentFamilyIds);
  758. List<PatentSimpleFamily> patentSimpleFamilyList = patentSimpleFamilyService.getPatentSimpleFamilyByIds(patentFamilyIds);
  759. List<PatentClassNumberLink> patentClassNumberLinkList = patentClassNumberLinkService.getPatentClassNumberLinkByPatentIds(patentIds);
  760. this.saveDataToJsonFile(tempPath, Constants.PATENT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentList)));
  761. this.saveDataToJsonFile(tempPath, Constants.PATENT_AFFAIR_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAffairList)));
  762. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENCY_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAgencyList)));
  763. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENT_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAgentLinkList)));
  764. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAgentList)));
  765. this.saveDataToJsonFile(tempPath, Constants.PATENT_INSTRUCTION_TEXT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInstructionTextList)));
  766. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInventorLinkList)));
  767. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInventorList)));
  768. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_MERGE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInventorMergeList)));
  769. this.saveDataToJsonFile(tempPath, Constants.PATENT_LICENSOR_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentLicensorList)));
  770. this.saveDataToJsonFile(tempPath, Constants.PATENT_PLEDGE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentPledgeList)));
  771. this.saveDataToJsonFile(tempPath, Constants.PATENT_RIGHT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentRightList)));
  772. this.saveDataToJsonFile(tempPath, Constants.PATENT_FAMILY_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentSimpleFamilyLinkList)));
  773. this.saveDataToJsonFile(tempPath, Constants.PATENT_FAMILY_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentSimpleFamilyList)));
  774. this.saveDataToJsonFile(tempPath, Constants.PATENT_CLASS_NUMBER_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentClassNumberLinkList)));
  775. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentApplicantList)));
  776. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentApplicantLinkList)));
  777. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_MERGE_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentApplicantMergeLinkList)));
  778. }
  779. if (params.getPatentField() != null && params.getPatentField().size() != 0) {
  780. if (params.getPatentField().contains(0)) {
  781. List<PatentLabel> patentLabelList = patentLabelService.getPatentLabelByPatentIdsAndProjectId(patentIds, params.getProjectId());
  782. this.saveDataToJsonFile(tempPath, Constants.PATENT_LABEL_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentLabelList)));
  783. }
  784. List<ProjectField> projectFieldList = projectFieldService.getFieldListByIds(params.getPatentField());
  785. List<Integer> projectFieldIds = projectFieldList.stream().map(ProjectField::getId).collect(Collectors.toList());
  786. List<ProjectFieldOption> projectFieldOptionList = projectFieldOptionService.getFieldOptionList(projectFieldIds);
  787. List<ProjectFieldTree> projectFieldTreeList = projectFieldTreeService.getProjectFieldTreeOptionByFieldIds(projectFieldIds);
  788. List<ProjectFieldText> projectFieldTextList = projectFieldTextService.getProjectFieldTextByFieldIds(projectFieldIds);
  789. List<ProjectFieldPatentLink> projectFieldPatentLinkList = new ArrayList<>();
  790. for (Integer fieldId : params.getPatentField()) {
  791. projectFieldPatentLinkList.addAll(projectFieldPatentLinkService.getProjectPatentLinkByPatentIdsAndFieldId(patentIds, fieldId));
  792. }
  793. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldList)));
  794. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_OPTION_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldOptionList)));
  795. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_TREE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldTreeList)));
  796. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_TEXT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldTextList)));
  797. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_PATENT_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldPatentLinkList)));
  798. }
  799. List<Patent> patents = patentService.getPatentIdAndPatentNoByIds(patentIds);
  800. this.saveDataToJsonFile(tempPath, Constants.PATENT_ID_PATENT_NO_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patents)));
  801. File file = ZipUtil.zip(tempPath, savePath);
  802. FileUtil.del(tempPath);
  803. ProjectExport projectExport = projectExportService.getById(exportId);
  804. projectExport.setUrl(url);
  805. projectExport.setFileName(fileName);
  806. projectExport.setStatus(1);
  807. projectExport.setFileSize(FileUtil.size(file));
  808. projectExport.updateById();
  809. WebSocketServer.sendInfo(Response.websocket(true, ResponseEnum.PROJECT_EXPORT_TASK_SUCCESS), String.valueOf(userId));
  810. } catch (Exception e) {
  811. e.printStackTrace();
  812. WebSocketServer.sendInfo(Response.websocket(false, ResponseEnum.PROJECT_EXPORT_TASK_ERROR), String.valueOf(userId));
  813. }
  814. }
  815. @Async("singleThreadAsyncTaskExecutor")
  816. @Transactional(rollbackFor = Exception.class)
  817. public void importData(String url, ProjectImportVO params, Integer userId, Integer importId) {
  818. String tempPath = null;
  819. ProjectImportStatusService projectImportStatusService = SpringUtil.getBean(ProjectImportStatusService.class);
  820. try {
  821. String tempDirectoryName = IdUtil.simpleUUID();
  822. tempPath = fileUtils.getTempPath(tempDirectoryName);
  823. String tempSavePath = fileUtils.getSystemPath(url);
  824. File tempDirectory = new File(tempPath);
  825. if (!tempDirectory.exists()) {
  826. boolean success = tempDirectory.mkdir();
  827. if (!success) {
  828. throw new Exception("数据导入时创建文件夹失败");
  829. }
  830. }
  831. projectImportStatusService.add(importId, userId, 2);
  832. ZipUtil.unzip(tempSavePath, tempPath);
  833. String projectJson = this.parseTempFileData(tempPath, Constants.PROJECT_INFO_FILE_NAME);
  834. Integer projectId = params.getProjectId();
  835. if (StringUtils.isNotEmpty(projectJson)) {
  836. projectImportStatusService.add(importId, userId, 3);
  837. projectId = this.importProject(params.getProjectId(), projectJson, userId);
  838. }
  839. if (projectId.equals(0)) {
  840. projectImportStatusService.add(importId, userId, 100);
  841. throw new CustomException("数据包未包含专题库信息");
  842. }
  843. String projectReportJson = this.parseTempFileData(tempPath, Constants.PROJECT_REPORT_FILE_NAME);
  844. String projectFileJson = this.parseTempFileData(tempPath, Constants.PROJECT_FILE_FILE_NAME);
  845. if (StringUtils.isNotEmpty(projectReportJson) || StringUtils.isNotEmpty(projectFileJson)) {
  846. projectImportStatusService.add(importId, userId, 4);
  847. projectFileService.importProjectFile(projectId, userId, tempPath, projectFileJson, projectReportJson);
  848. }
  849. String patentIdPatentNoJson = this.parseTempFileData(tempPath, Constants.PATENT_ID_PATENT_NO_FILE_NAME);
  850. String patentJson = this.parseTempFileData(tempPath, Constants.PATENT_FILE_NAME);
  851. String patentAffairJson = this.parseTempFileData(tempPath, Constants.PATENT_AFFAIR_FILE_NAME);
  852. String patentAgencyJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENCY_FILE_NAME);
  853. String patentAgentJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENT_FILE_NAME);
  854. String patentAgentLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENT_LINK_FILE_NAME);
  855. String patentInventorJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_FILE_NAME);
  856. String patentInventorMergeJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_MERGE_FILE_NAME);
  857. String patentInventorLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_LINK_FILE_NAME);
  858. String patentApplicantJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_FILE_NAME);
  859. String patentApplicantLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_LINK_FILE_NAME);
  860. String patentApplicantMergeLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_MERGE_LINK_FILE_NAME);
  861. String patentFamilyJson = this.parseTempFileData(tempPath, Constants.PATENT_FAMILY_FILE_NAME);
  862. String patentFamilyLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_FAMILY_LINK_FILE_NAME);
  863. String patentClassNumberJson = this.parseTempFileData(tempPath, Constants.PATENT_CLASS_NUMBER_FILE_NAME);
  864. String patentInstructionTextJson = this.parseTempFileData(tempPath, Constants.PATENT_INSTRUCTION_TEXT_FILE_NAME);
  865. String patentRightJson = this.parseTempFileData(tempPath, Constants.PATENT_RIGHT_FILE_NAME);
  866. String patentLicensorJson = this.parseTempFileData(tempPath, Constants.PATENT_LICENSOR_FILE_NAME);
  867. String patentPledgeJson = this.parseTempFileData(tempPath, Constants.PATENT_PLEDGE_FILE_NAME);
  868. if (StringUtils.isNotEmpty(patentJson)) {
  869. projectImportStatusService.add(importId, userId, 8);
  870. patentService.importPatent(projectId, patentJson, patentAffairJson, patentAgencyJson, patentFamilyJson, patentFamilyLinkJson, patentInventorJson, patentInventorLinkJson, patentAgentJson, patentAgentLinkJson, patentApplicantJson, patentApplicantLinkJson, patentApplicantMergeLinkJson, patentClassNumberJson, patentInstructionTextJson, patentRightJson, patentLicensorJson, patentPledgeJson, patentInventorMergeJson);
  871. }
  872. projectImportStatusService.add(importId, userId, 9);
  873. projectPatentLinkService.importProjectPatentLink(projectId, patentIdPatentNoJson);
  874. String projectFieldJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_FILE_NAME);
  875. if (StringUtils.isNotEmpty(projectFieldJson)) {
  876. String projectFieldTextJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_TEXT_FILE_NAME);
  877. String projectFieldOptionJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_OPTION_FILE_NAME);
  878. String projectFieldTreeJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_TREE_FILE_NAME);
  879. String projectFieldPatentLink = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_PATENT_LINK_FILE_NAME);
  880. projectImportStatusService.add(importId, userId, 5);
  881. projectFieldService.importProjectField(projectId, userId, patentIdPatentNoJson, projectFieldJson, projectFieldTextJson, projectFieldOptionJson, projectFieldTreeJson, projectFieldPatentLink);
  882. }
  883. String patentImageJson = this.parseTempFileData(tempPath, Constants.PATENT_IMAGE_FILE_NAME);
  884. if (StringUtils.isNotEmpty(patentImageJson)) {
  885. projectImportStatusService.add(importId, userId, 6);
  886. patentImageService.importPatentImage(tempPath, patentIdPatentNoJson, patentImageJson);
  887. }
  888. String patentInstructionJson = this.parseTempFileData(tempPath, Constants.PATENT_INSTRUCTION_FILE_NAME);
  889. if (StringUtils.isNotEmpty(patentInstructionJson)) {
  890. projectImportStatusService.add(importId, userId, 7);
  891. patentInstructionService.importPatentInstruction(userId, tempPath, patentIdPatentNoJson, patentInstructionJson);
  892. }
  893. } catch (Exception e) {
  894. e.printStackTrace();
  895. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  896. projectImportStatusService.add(importId, userId, 101);
  897. } finally {
  898. FileUtil.del(tempPath);
  899. projectImportStatusService.add(importId, userId, 200);
  900. cacheUtils.deleteUserImport(userId);
  901. }
  902. }
  903. private String parseTempFileData(String path, String fileName) throws IOException {
  904. String src = path + FileUtil.FILE_SEPARATOR + fileName;
  905. if (!FileUtil.exist(src)) {
  906. return null;
  907. }
  908. File file = new File(src);
  909. FileReader fileReader = new FileReader(file);
  910. Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
  911. int ch;
  912. StringBuffer sb = new StringBuffer();
  913. while ((ch = reader.read()) != -1) {
  914. sb.append((char) ch);
  915. }
  916. fileReader.close();
  917. reader.close();
  918. return sb.toString();
  919. }
  920. //主页面 导出列表功能
  921. public void exportProject(HttpServletResponse response) {
  922. try {
  923. ProjectVO params = new ProjectVO();
  924. params.setSize(99999999999L);
  925. params.setCurrent(1L);
  926. params.setMyself(false);
  927. ProjectVO.Sort sort = new ProjectVO.Sort();
  928. sort.setProp("create_time");
  929. sort.setOrder("desc");
  930. params.setSort(sort);
  931. IPage<Project> pageList = this.getPageList(params);
  932. List<Project> projectList = pageList.getRecords();
  933. List<List<String>> row = new ArrayList<>();
  934. row.add(CollUtil.newArrayList("#", "名称", "委托方", "调查类型", "应用场景", "技术主题", "合同号", "委案日", "创建人"));
  935. for (int i = 0; i < projectList.size(); i++) {
  936. Project project = projectList.get(i);
  937. 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()));
  938. }
  939. List<List<String>> rows = CollUtil.newArrayList(row);
  940. ExcelWriter writer = ExcelUtil.getWriter(true);
  941. OutputStream out = response.getOutputStream();
  942. writer.write(rows, true);
  943. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  944. response.setHeader("Content-Disposition", "attachment;filename=" + IdUtil.simpleUUID() + ".xlsx");
  945. writer.flush(out, true);
  946. writer.close();
  947. IoUtil.close(out);
  948. } catch (Exception e) {
  949. e.printStackTrace();
  950. }
  951. }
  952. /**
  953. * @param projectCopyDTO
  954. * @return
  955. * @throws IOException
  956. * @deprecated 复制专题库
  957. */
  958. @Transactional
  959. public Integer copy(ProjectCopyDTO projectCopyDTO) throws IOException {
  960. Integer oldId = projectCopyDTO.getId();
  961. //复制专题库基本信息
  962. Project project = this.getById(oldId);
  963. project.setTenantId(projectCopyDTO.getTenantId());
  964. project.setId(null);
  965. project.insert();
  966. //复制专题库专利
  967. LambdaQueryWrapper<ProjectPatentLink> patentLinkWrapper = new LambdaQueryWrapper<>();
  968. patentLinkWrapper.eq(ProjectPatentLink::getProjectId, oldId);
  969. List<ProjectPatentLink> projectPatentLinkList = projectPatentLinkService.list(patentLinkWrapper);
  970. projectPatentLinkList.forEach(
  971. item -> {
  972. item.setProjectId(project.getId());
  973. item.setId(null);
  974. }
  975. );
  976. projectPatentLinkService.saveBatch(projectPatentLinkList);
  977. //复制专题库标引信息
  978. copyService.CopyPatentLabels(oldId, project.getId());
  979. //复制专题库文件夹
  980. copyService.CopyProjectFolder(oldId, project.getId());
  981. return project.getId();
  982. }
  983. }