ProjectService.java 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. package cn.cslg.pas.service;
  2. import cn.cslg.pas.common.core.base.Constants;
  3. import cn.cslg.pas.common.core.exception.CustomException;
  4. import cn.cslg.pas.common.model.PersonnelVO;
  5. import cn.cslg.pas.common.model.dto.UploadFileDTO;
  6. import cn.cslg.pas.common.model.vo.ProjectExportVO;
  7. import cn.cslg.pas.common.model.vo.ProjectImportVO;
  8. import cn.cslg.pas.common.model.vo.ProjectVO;
  9. import cn.cslg.pas.common.model.vo.TaskParams;
  10. import cn.cslg.pas.common.utils.*;
  11. import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
  12. import cn.cslg.pas.common.utils.SecurityUtils.SecurityUtils;
  13. import cn.cslg.pas.common.utils.auth.checkAuth;
  14. import cn.cslg.pas.domain.*;
  15. import cn.cslg.pas.mapper.ProjectMapper;
  16. import cn.hutool.core.collection.CollUtil;
  17. import cn.hutool.core.collection.IterUtil;
  18. import cn.hutool.core.date.DateField;
  19. import cn.hutool.core.date.DateUtil;
  20. import cn.hutool.core.io.FileUtil;
  21. import cn.hutool.core.io.IoUtil;
  22. import cn.hutool.core.util.IdUtil;
  23. import cn.hutool.core.util.ZipUtil;
  24. import cn.hutool.extra.spring.SpringUtil;
  25. import cn.hutool.poi.excel.ExcelReader;
  26. import cn.hutool.poi.excel.ExcelUtil;
  27. import cn.hutool.poi.excel.ExcelWriter;
  28. import com.alibaba.fastjson.JSON;
  29. import com.alibaba.fastjson.JSONArray;
  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 org.springframework.beans.BeanUtils;
  37. import org.springframework.context.annotation.Lazy;
  38. import org.springframework.scheduling.annotation.Async;
  39. import org.springframework.stereotype.Service;
  40. import org.springframework.transaction.annotation.Propagation;
  41. import org.springframework.transaction.annotation.Transactional;
  42. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  43. import org.springframework.web.multipart.MultipartFile;
  44. import javax.servlet.http.HttpServletResponse;
  45. import java.io.*;
  46. import java.nio.charset.StandardCharsets;
  47. import java.util.*;
  48. import java.util.stream.Collectors;
  49. /**
  50. * <p>
  51. * 专题库表 服务实现类
  52. * </p>
  53. *
  54. * @author 王岩
  55. * @since 2022-01-24
  56. */
  57. @Service
  58. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  59. public class ProjectService extends ServiceImpl<ProjectMapper, Project> {
  60. private final ClientService clientService;
  61. private final ProjectUserService projectUserService;
  62. private final PatentService patentService;
  63. private final PatentApplicantService patentApplicantService;
  64. private final PatentAgencyService patentAgencyService;
  65. private final PatentAgentService patentAgentService;
  66. private final PatentAgentLinkService patentAgentLinkService;
  67. private final PatentLicensorService patentLicensorService;
  68. private final PatentPledgeService patentPledgeService;
  69. private final PatentAffairService patentAffairService;
  70. private final PatentApplicantLinkService patentApplicantLinkService;
  71. private final PatentApplicantMergeLinkService patentApplicantMergeLinkService;
  72. private final PatentInventorService patentInventorService;
  73. private final PatentInventorLinkService patentInventorLinkService;
  74. private final PatentSimpleFamilyService patentSimpleFamilyService;
  75. private final PatentSimpleFamilyLinkService patentSimpleFamilyLinkService;
  76. private final PatentClassNumberLinkService patentClassNumberLinkService;
  77. private final ProjectPatentLinkService projectPatentLinkService;
  78. private final TaskService taskService;
  79. private final PatentImageService patentImageService;
  80. private final ProjectFieldPatentLinkService projectFieldPatentLinkService;
  81. private final ProjectFolderService projectFolderService;
  82. private final ProjectFieldService projectFieldService;
  83. private final ProjectFieldOptionService projectFieldOptionService;
  84. private final ProjectFieldTreeService projectFieldTreeService;
  85. private final ProjectFieldTextService projectFieldTextService;
  86. private final ProjectFileService projectFileService;
  87. private final SystemDictService systemDictService;
  88. private final PatentInstructionService patentInstructionService;
  89. private final PatentInstructionTextService patentInstructionTextService;
  90. private final PatentRightService patentRightService;
  91. private final FileUtils fileUtils;
  92. private final PatentLabelService patentLabelService;
  93. private final CacheUtils cacheUtils;
  94. private final ProjectExportService projectExportService;
  95. private final PatentInventorMergeService patentInventorMergeService;
  96. private final UserService userService;
  97. private final LoginUtils loginUtils;
  98. private final SecurityUtils securityUtils;
  99. private final RequestService requestService;
  100. public Project getProjectByName(String name) {
  101. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  102. queryWrapper.eq(Project::getName, name);
  103. queryWrapper.last("limit 1");
  104. return this.getOne(queryWrapper);
  105. }
  106. public IPage<Project> getPageList(ProjectVO params) throws IOException {
  107. List<Integer> projectIds = new ArrayList<Integer>() {{
  108. add(-1);
  109. }};
  110. if (params.getMyself()) {
  111. projectIds.addAll(projectUserService.getProIdByUserId(loginUtils.getId()));
  112. }
  113. params.setProIds(projectIds);
  114. params.setCreateBy(loginUtils.getId());
  115. //TODO 代码控制不同类型的角色查询权限
  116. PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  117. if (personnelVO.getRoleType() == null || personnelVO.getRoleType() != 1) {
  118. params.setPersonnelId(loginUtils.getId());
  119. if (personnelVO.getRoleType() != null && personnelVO.getRoleType() == 2) {
  120. params.setTenantId(personnelVO.getTenantId());
  121. }
  122. }
  123. IPage<Project> pageList = baseMapper.getPageList(new Page<>(params.getCurrent(), params.getSize()), params);
  124. List<Project> dataList = pageList.getRecords();
  125. try {
  126. //获取所属部门对应信息
  127. String jsonObject = requestService.getDepartmentFromPCS(dataList);
  128. JSONArray jsonArray1 = JSON.parseArray(jsonObject);
  129. List<ProjectVO.Department> departmentList = jsonArray1.toJavaList(ProjectVO.Department.class);
  130. for (Project project : dataList) {
  131. for (ProjectVO.Department department : departmentList) {
  132. if (project.getDepartmentId() != null) {
  133. if (project.getDepartmentId().equals(department.getId())) {
  134. project.setDepartmentName(department.getDepartmentName());
  135. }
  136. }
  137. }
  138. }
  139. //获取专题库负责人对应信息
  140. String jsonObject1 = requestService.getPersonnelFromPCS(dataList);
  141. JSONArray jsonArray = JSON.parseArray(jsonObject1);
  142. List<ProjectVO.Personnel> personnelList = jsonArray.toJavaList(ProjectVO.Personnel.class);
  143. for (Project project : dataList) {
  144. for (ProjectVO.Personnel personnel : personnelList) {
  145. if (project.getPersonnelId() != null) {
  146. if (project.getPersonnelId().equals(personnel.getId())) {
  147. project.setPersonnelName(personnel.getPersonnelName());
  148. }
  149. }
  150. }
  151. }
  152. } catch (IOException e) {
  153. e.printStackTrace();
  154. }
  155. this.setDataList(dataList);
  156. pageList.setRecords(dataList);
  157. return pageList;
  158. }
  159. public List<Project> getProjectByIds(List<Integer> ids) {
  160. if (ids == null || ids.size() == 0) {
  161. return new ArrayList<>();
  162. }
  163. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  164. queryWrapper.in(Project::getId, ids);
  165. List<Project> dataList = this.list(queryWrapper);
  166. try {
  167. //获取所属部门对应信息
  168. String jsonObject = requestService.getDepartmentFromPCS(dataList);
  169. JSONArray jsonArray1 = JSON.parseArray(jsonObject);
  170. List<ProjectVO.Department> departmentList = jsonArray1.toJavaList(ProjectVO.Department.class);
  171. for (Project project : dataList) {
  172. for (ProjectVO.Department department : departmentList) {
  173. if (project.getDepartmentId() != null) {
  174. if (project.getDepartmentId().equals(department.getId())) {
  175. project.setDepartmentName(department.getDepartmentName());
  176. }
  177. }
  178. }
  179. }
  180. //获取专题库负责人对应信息
  181. String jsonObject1 = requestService.getPersonnelFromPCS(dataList);
  182. JSONArray jsonArray = JSON.parseArray(jsonObject1);
  183. List<ProjectVO.Personnel> personnelList = jsonArray.toJavaList(ProjectVO.Personnel.class);
  184. for (Project project : dataList) {
  185. for (ProjectVO.Personnel personnel : personnelList) {
  186. if (project.getPersonnelId() != null) {
  187. if (project.getPersonnelId().equals(personnel.getId())) {
  188. project.setPersonnelName(personnel.getPersonnelName());
  189. }
  190. }
  191. }
  192. }
  193. } catch (IOException e) {
  194. e.printStackTrace();
  195. }
  196. this.setDataList(dataList);
  197. return dataList;
  198. }
  199. public List<Project> getProjectByCreateId(Integer createBy) {
  200. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  201. queryWrapper.eq(Project::getCreateBy, createBy);
  202. return this.list(queryWrapper);
  203. }
  204. public Project getProjectById(Integer id) {
  205. Project project = this.getById(id);
  206. Client client = clientService.getById(project.getClientId());
  207. if (client != null) {
  208. project.setClientName(client.getName());
  209. }
  210. return project;
  211. }
  212. private void setDataList(List<Project> dataList) {
  213. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.ENTERPRISE_APPLICATION_SCENARIO, Constants.INVESTIGATION_TYPE));
  214. dataList.forEach(item -> {
  215. if (StringUtils.isNotEmpty(item.getScenario())) {
  216. item.setScenarioList(StringUtils.changeStringToInteger(item.getScenario(), ","));
  217. 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()));
  218. item.setScenario(null);
  219. }
  220. if (StringUtils.isNotEmpty(item.getType())) {
  221. item.setTypeList(StringUtils.changeStringToInteger(item.getType(), ","));
  222. 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()));
  223. item.setType(null);
  224. }
  225. });
  226. }
  227. public List<Project> getAllProjectByMySelf() {
  228. ProjectVO params=new ProjectVO();
  229. PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
  230. if (personnelVO.getRoleType() == null || personnelVO.getRoleType() != 1) {
  231. params.setPersonnelId(loginUtils.getId());
  232. if (personnelVO.getRoleType() != null && personnelVO.getRoleType() == 2) {
  233. params.setTenantId(personnelVO.getTenantId());
  234. }
  235. }
  236. List<Project> projectList = baseMapper.getListForCount(params);
  237. this.setDataList(projectList);
  238. return projectList;
  239. }
  240. public Map<Object, Object> getProjectStatusTotal() {
  241. Map<Object, Object> map = new HashMap<>();
  242. List<Project> projectList = this.getAllProjectByMySelf();
  243. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.ENTERPRISE_APPLICATION_SCENARIO));
  244. for (SystemDict systemDict : systemDictList) {
  245. Map<String, Object> result = new HashMap<>();
  246. List<Project> tempList = projectList.stream().filter(item -> item.getScenarioList().contains(Integer.parseInt(systemDict.getValue()))).collect(Collectors.toList());
  247. result.put("completed", tempList.stream().filter(item -> item.getStatus().equals("1")).count());
  248. result.put("unfinished", tempList.stream().filter(item -> item.getStatus().equals("0")).count());
  249. map.put(systemDict.getLabel(), result);
  250. }
  251. return map;
  252. }
  253. public Map<String, Object> getProjectTypeTotal(String scenario) {
  254. Map<String, Object> map = new HashMap<>();
  255. List<Project> projectList = this.getAllProjectByMySelf();
  256. projectList = projectList.stream().filter(item -> item.getScenarioName().contains(scenario)).collect(Collectors.toList());
  257. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.INVESTIGATION_TYPE));
  258. for (SystemDict systemDict : systemDictList) {
  259. map.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getTypeList().contains(Integer.parseInt(systemDict.getValue()))).count());
  260. }
  261. return map;
  262. }
  263. public Map<Object, Object> getScenarioAndTypeTotal() {
  264. List<Project> projectList = this.getAllProjectByMySelf();
  265. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.ENTERPRISE_APPLICATION_SCENARIO, Constants.INVESTIGATION_TYPE));
  266. List<Client> clientList = clientService.getClientByObjectIds(this.getClientIds(projectList.stream().map(Project::getClientId).collect(Collectors.toList())));
  267. Map<Object, Object> type = new HashMap<>();
  268. Map<Object, Object> scenario = new HashMap<>();
  269. Map<Object, Object> result = new HashMap<>();
  270. Map<Object, Object> client = new HashMap<>();
  271. Map<Object, Object> create = new HashMap<>();
  272. systemDictList.forEach(systemDict -> {
  273. switch (systemDict.getType()) {
  274. case Constants.ENTERPRISE_APPLICATION_SCENARIO:
  275. scenario.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getScenarioList().contains(Integer.parseInt(systemDict.getValue()))).count());
  276. break;
  277. case Constants.INVESTIGATION_TYPE:
  278. type.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getTypeList().contains(Integer.parseInt(systemDict.getValue()))).count());
  279. break;
  280. }
  281. });
  282. clientList.forEach(item -> client.put(item.getName(), projectList.stream().filter(project -> project.getClientId().equals(item.getId())).count()));
  283. Date date = DateUtil.date();
  284. for (int i = 0; i < 6; i++) {
  285. Date finalDate = date;
  286. 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());
  287. date = DateUtil.offset(date, DateField.MONTH, -1);
  288. }
  289. result.put("scenario", scenario);
  290. result.put("type", type);
  291. result.put("client", client);
  292. result.put("create", create);
  293. return result;
  294. }
  295. private List<Object> getClientIds(List<Integer> clientIds) {
  296. Map<Object, Long> map = clientIds.stream().collect(Collectors.groupingBy(p -> p, Collectors.counting()));
  297. return map.entrySet().stream()
  298. .sorted((Map.Entry<Object, Long> o1, Map.Entry<Object, Long> o2) -> o2.getValue().intValue() - o1.getValue().intValue())
  299. .map(Map.Entry::getKey).collect(Collectors.toList())
  300. .subList(0, Math.min(map.size(), 10));
  301. }
  302. public String getImportProjectName(String name) {
  303. String tempName = name + "(1)";
  304. Project project1 = this.getProjectByName(name);
  305. if (project1 == null) {
  306. return name;
  307. }
  308. Project project2 = this.getProjectByName(tempName);
  309. if (project2 != null) {
  310. tempName = this.getImportProjectName(tempName);
  311. }
  312. return tempName;
  313. }
  314. public Integer importProject(Integer projectId, String json, Integer userId) {
  315. if ((projectId == null || projectId.equals(0)) && StringUtils.isEmpty(json)) {
  316. return 0;
  317. }
  318. if (StringUtils.isEmpty(json)) {
  319. return projectId;
  320. }
  321. Project temp = this.getById(projectId);
  322. Project data = JsonUtils.jsonToPojo(json, Project.class);
  323. Client client = clientService.getClientByName(Objects.requireNonNull(data).getClientName());
  324. if (client == null) {
  325. client = new Client();
  326. client.setName(data.getClientName());
  327. client.setStatus(1);
  328. client.setCreateBy(userId);
  329. client.setCreateTime(DateUtils.getDateTime());
  330. client.insert();
  331. }
  332. if (temp == null) {
  333. temp = new Project();
  334. }
  335. String projectName = temp.getName();
  336. BeanUtils.copyProperties(data, temp);
  337. if (projectName == null || !projectName.equals(data.getName())) {
  338. temp.setName(this.getImportProjectName(temp.getName()));
  339. }
  340. temp.setClientId(client.getId());
  341. if (projectId == null || projectId.equals(0)) {
  342. temp.setCreateBy(userId);
  343. temp.setCreateTime(DateUtils.getDateTime());
  344. temp.setId(null);
  345. } else {
  346. temp.setId(projectId);
  347. }
  348. temp.insertOrUpdate();
  349. return temp.getId();
  350. }
  351. @Transactional
  352. public String add(Project project) {
  353. PersonnelVO user = cacheUtils.getLoginUserPersonnel(loginUtils.getId());
  354. Project temp = this.getProjectByName(project.getName());
  355. if (temp != null) {
  356. return Response.error("专题库名称已存在");
  357. }
  358. if (project.getClientId() == -1) {
  359. project.setClientId(this.getNewClientId(project.getClientName(), user.getTenantId()));
  360. }
  361. project.setScenario(StringUtils.join(project.getScenarioList(), ","));
  362. project.setType(StringUtils.join(project.getTypeList(), ","));
  363. project.setCreateBy(loginUtils.getId());
  364. project.setCreateTime(DateUtils.getDateTime());
  365. project.setTenantId(user.getTenantId());
  366. project.insert();
  367. this.addProjectUser(project.getId());
  368. return Response.success(project.getId());
  369. }
  370. @Transactional
  371. public String edit(Project project) {
  372. Project temp = this.getProjectByName(project.getName());
  373. Project project1 = this.getProjectById(project.getId());
  374. if (temp != null && !temp.getId().equals(project.getId())) {
  375. return Response.error("专题库名称已存在");
  376. }
  377. if (project.getClientId() == -1) {
  378. project.setClientId(this.getNewClientId(project.getClientName(), project1.getTenantId()));
  379. }
  380. project.setScenario(StringUtils.join(project.getScenarioList(), ","));
  381. project.setType(StringUtils.join(project.getTypeList(), ","));
  382. project.updateById();
  383. return Response.success();
  384. }
  385. @Transactional
  386. public String delete(Integer id) {
  387. this.removeById(id);
  388. this.deleteProjectUser(id, loginUtils.getId());
  389. projectPatentLinkService.deleteByProjectId(id);
  390. projectFolderService.deleteByProjectId(id);
  391. projectFieldService.deleteByProjectId(id);
  392. projectUserService.deleteByProjectId(id);
  393. projectFileService.deleteByProjectId(id);
  394. patentApplicantMergeLinkService.deleteByProjectId(id);
  395. return Response.success();
  396. }
  397. private Integer getNewClientId(String name, Integer tenantId) {
  398. Client client = clientService.getOne(Wrappers.<Client>lambdaQuery().eq(Client::getName, name).last("limit 1"));
  399. if (client == null) {
  400. client = new Client();
  401. client.setName(name);
  402. client.setStatus(1);
  403. client.setCreateBy(loginUtils.getId());
  404. client.setCreateTime(DateUtils.getDateTime());
  405. client.setTenantId(tenantId);
  406. client.insert();
  407. }
  408. return client.getId();
  409. }
  410. private void addProjectUser(Integer projectId) {
  411. ProjectUser user = new ProjectUser();
  412. user.setUserId(loginUtils.getId());
  413. user.setProjectId(projectId);
  414. user.setCreateTime(DateUtils.getDateTime());
  415. user.setType(2);
  416. user.insert();
  417. }
  418. private void deleteProjectUser(Integer projectId, Integer userId) {
  419. projectUserService.remove(Wrappers.<ProjectUser>lambdaQuery().eq(ProjectUser::getUserId, userId).eq(ProjectUser::getProjectId, projectId));
  420. }
  421. @Transactional(rollbackFor = Exception.class)
  422. public String importExcel(MultipartFile file) {
  423. try {
  424. PersonnelVO user = cacheUtils.getLoginUserPersonnel(loginUtils.getId());
  425. ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
  426. List<Map<String, Object>> readAll = reader.readAll();
  427. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.INVESTIGATION_TYPE, Constants.ENTERPRISE_APPLICATION_SCENARIO));
  428. for (Map<String, Object> row : readAll) {
  429. Project project = new Project();
  430. project.setSort(1);
  431. project.setName(row.get("专题库名称").toString());
  432. project.setClientId(this.getNewClientId(row.get("委托方").toString(), user.getTenantId()));
  433. project.setRemark(row.get("备注").toString());
  434. project.setCreateBy(loginUtils.getId());
  435. project.setCreateTime(DateUtils.getDateTime());
  436. List<String> typeName = StringUtils.changeStringToString(row.get("调查类型").toString(), ";");
  437. 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());
  438. project.setType(StringUtils.join(typeList, ","));
  439. List<String> scenarioName = StringUtils.changeStringToString(row.get("企业应用场景").toString(), ";");
  440. 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());
  441. project.setScenario(StringUtils.join(scenarioList, ","));
  442. project.setTechnicalTheme(row.get("技术主题").toString());
  443. project.setContractNo(row.get("合同号").toString());
  444. project.setInnerFile(row.get("内部案卷").toString());
  445. Object caseDate = row.get("委案日");
  446. if (StringUtils.isNotNull(caseDate)) {
  447. project.setCaseDate(caseDate.toString());
  448. }
  449. project.setStatus(row.get("处理状态").toString().equals("处理中") ? "0" : "1");
  450. Object update = row.get("是否更新");
  451. if (StringUtils.isNotNull(update)) {
  452. project.setUpdate(update.toString().equals("是") ? 1 : 0);
  453. project.setUpdateTime(row.get("更新周期").toString());
  454. } else {
  455. project.setUpdate(0);
  456. project.setUpdateTime("一天");
  457. }
  458. project.insert();
  459. List<String> userName = StringUtils.changeStringToString(row.get("管理员").toString(), ";");
  460. List<User> userList = userService.getUserByNames(userName);
  461. List<ProjectUser> projectUserList = new ArrayList<>();
  462. userList.forEach(item -> {
  463. ProjectUser projectUser = new ProjectUser();
  464. projectUser.setProjectId(project.getId());
  465. projectUser.setUserId(item.getId());
  466. projectUser.setCreateTime(DateUtils.getDateTime());
  467. projectUser.setType(2);
  468. projectUserList.add(projectUser);
  469. });
  470. projectUserService.saveOrUpdateBatch(projectUserList);
  471. }
  472. return Response.success(true);
  473. } catch (Exception e) {
  474. e.printStackTrace();
  475. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  476. return Response.error();
  477. }
  478. }
  479. @Transactional
  480. public String share(Integer id, List<Integer> userIds, List<ProjectUser.User> users) {
  481. ProjectUser user = new ProjectUser();
  482. user.setType(3);
  483. user.setRemark("用户分享");
  484. user.setProjectId(id);
  485. user.setUserIds(userIds);
  486. user.setUsers(users);
  487. return projectUserService.add(user);
  488. }
  489. public TaskParams getImportPatentTaskParams(MultipartFile file, Integer projectId) {
  490. UploadFileDTO fileDTO = fileUtils.uploadFile(file);
  491. String path = fileUtils.getPath(fileDTO.getPath());
  492. List<List<Object>> rowList = new ArrayList<>();
  493. List<Map<Object, Object>> mapList = new ArrayList<>();
  494. ExcelUtil.readBySax(path, -1, (sheetIndex, rowIndex, row) -> rowList.add(row));
  495. for (int i = 1; i < rowList.size(); i++) {
  496. mapList.add(IterUtil.toMap(rowList.get(0), rowList.get(i)));
  497. }
  498. Integer taskId = taskService.add(fileDTO, projectId, rowList.size() - 1, 1, 0, file.getOriginalFilename());
  499. TaskParams taskParams = new TaskParams();
  500. taskParams.setTaskId(taskId);
  501. taskParams.setPath(path);
  502. taskParams.setTaskType(1);
  503. taskParams.setRowList(mapList);
  504. taskParams.setUserId(String.valueOf(loginUtils.getId()));
  505. taskParams.setOldName(file.getOriginalFilename());
  506. return taskParams;
  507. }
  508. //获得
  509. public TaskParams getImportPatentTaskParamsBro(MultipartFile file) {
  510. //上传文档
  511. UploadFileDTO fileDTO = fileUtils.uploadFile(file);
  512. //获得文档保存的路径
  513. String path = fileUtils.getPath(fileDTO.getPath());
  514. List<List<Object>> rowList = new ArrayList<>();
  515. //解析excel文件并保存进map里
  516. List<Map<Object, Object>> mapList = new ArrayList<>();
  517. ExcelUtil.readBySax(path, -1, (sheetIndex, rowIndex, row) -> rowList.add(row));
  518. for (int i = 1; i < rowList.size(); i++) {
  519. mapList.add(IterUtil.toMap(rowList.get(0), rowList.get(i)));
  520. }
  521. TaskParams taskParams = new TaskParams();
  522. taskParams.setPath(path);
  523. taskParams.setTaskType(1);
  524. taskParams.setRowList(mapList);
  525. taskParams.setUserId(String.valueOf(loginUtils.getId()));
  526. taskParams.setOldName(file.getOriginalFilename());
  527. return taskParams;
  528. }
  529. @Transactional(propagation = Propagation.NOT_SUPPORTED)
  530. public void setImportPatentTaskStatus(Integer status, Integer taskId) {
  531. taskService.updateStatus(taskId, status, DateUtils.getDateTime());
  532. }
  533. public void saveDataToJsonFile(String tempPath, String fileName, String data) throws IOException {
  534. String path = tempPath + FileUtils.FILE_SEPARATOR + fileName;
  535. FileOutputStream fileOutputStream = new FileOutputStream(path);
  536. fileOutputStream.write(data.getBytes(StandardCharsets.UTF_8));
  537. fileOutputStream.close();
  538. }
  539. public void copyFileToTempDirectory(String src, String tempPath, String directoryName, String fileName) {
  540. String dest = tempPath + FileUtils.FILE_SEPARATOR + directoryName + FileUtils.FILE_SEPARATOR + fileName;
  541. File file = FileUtil.file(fileUtils.getSystemPath(src));
  542. if (FileUtil.exist(file)) {
  543. FileUtil.copy(file, new File(dest), true);
  544. }
  545. }
  546. @Async
  547. public void export(ProjectExportVO params, Integer exportId, Integer userId) {
  548. try {
  549. String json = cacheUtils.getSelectPatentIds(params.getKey());
  550. List<Integer> patentIds = StringUtils.changeStringToInteger(json, ",");
  551. List<Patent> patentList = patentService.getPatentListByIds(patentIds);
  552. String directoryName = IdUtil.simpleUUID();
  553. String fileName = directoryName + ".zip";
  554. String tempPath = fileUtils.getTempPath(directoryName);
  555. String url = fileUtils.getDirectory(fileName);
  556. String savePath = fileUtils.getSystemPath(url);
  557. File directory = new File(tempPath);
  558. if (!directory.exists()) {
  559. boolean success = directory.mkdir();
  560. if (!success) {
  561. throw new Exception("数据导出时创建文件夹失败");
  562. }
  563. }
  564. WebSocketServer.sendInfo(Response.websocket(true, ResponseEnum.PROJECT_EXPORT_TASK_SUCCESS), String.valueOf(userId));
  565. if (params.getProjectInfo()) {
  566. Project project = this.getProjectById(params.getProjectId());
  567. this.saveDataToJsonFile(tempPath, Constants.PROJECT_INFO_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(project)));
  568. }
  569. if (params.getProjectReport() != null && params.getProjectReport().size() != 0) {
  570. List<ProjectFile> projectFileList = projectFileService.getProjectFileByIds(params.getProjectReport());
  571. this.saveDataToJsonFile(tempPath, Constants.PROJECT_REPORT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFileList)));
  572. projectFileList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PROJECT_REPORT_DIRECTORY_NAME, item.getFileName()));
  573. }
  574. if (params.getProjectFile() != null && params.getProjectFile().size() != 0) {
  575. List<ProjectFile> projectFileList = projectFileService.getProjectFileByIds(params.getProjectFile());
  576. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FILE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFileList)));
  577. projectFileList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PROJECT_FILE_DIRECTORY_NAME, item.getFileName()));
  578. }
  579. if (params.getPatentImage()) {
  580. List<PatentImage> patentImageList = patentImageService.getPatentImageByPatentIds(patentIds);
  581. this.saveDataToJsonFile(tempPath, Constants.PATENT_IMAGE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentImageList)));
  582. patentImageList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PATENT_IMAGE_DIRECTORY_NAME, item.getFileName()));
  583. }
  584. if (params.getPatentInstruction()) {
  585. List<String> patentNo = patentList.stream().map(Patent::getPatentNo).collect(Collectors.toList());
  586. List<PatentInstruction> patentInstructionList = patentInstructionService.getPatentInstructionByPatentNo(patentNo);
  587. this.saveDataToJsonFile(tempPath, Constants.PATENT_INSTRUCTION_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInstructionList)));
  588. patentInstructionList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PATENT_INSTRUCTION_DIRECTORY_NAME, item.getFileName()));
  589. }
  590. if (params.getPatentBase()) {
  591. List<PatentApplicantLink> patentApplicantLinkList = patentApplicantLinkService.getApplicantAttributesListByPatentIds(patentIds);
  592. List<PatentApplicantMergeLink> patentApplicantMergeLinkList = patentApplicantMergeLinkService.getPatentApplicantMergeLinkListByProjectId(params.getProjectId());
  593. List<Integer> patentApplicantIds = new ArrayList<>();
  594. patentApplicantLinkList.forEach(item -> patentApplicantIds.add(item.getApplicantId()));
  595. patentApplicantMergeLinkList.forEach(item -> patentApplicantIds.add(item.getMergeId()));
  596. List<PatentApplicant> patentApplicantList = patentApplicantService.getPatentApplicantByIds(patentApplicantIds);
  597. List<PatentAffair> patentAffairList = patentAffairService.getPatentAffairListByPatentIds(patentIds);
  598. List<PatentAgency> patentAgencyList = patentAgencyService.getPatentAgencyByIds(patentList.stream().filter(item -> StringUtils.isNotEmpty(item.getAgencyId())).map(item -> Integer.parseInt(item.getAgencyId())).collect(Collectors.toList()));
  599. List<PatentAgentLink> patentAgentLinkList = patentAgentLinkService.getPatentAgentLinkByPatentIds(patentIds);
  600. List<PatentAgent> patentAgentList = patentAgentService.getPatentAgentByIds(patentAgentLinkList.stream().map(PatentAgentLink::getAgentId).collect(Collectors.toList()));
  601. List<PatentInstructionText> patentInstructionTextList = patentInstructionTextService.getPatentInstructionTextByPatentIds(patentIds);
  602. List<PatentInventorLink> patentInventorLinkList = patentInventorLinkService.getPatentInventorLinkByPatentIds(patentIds);
  603. List<PatentInventorMerge> patentInventorMergeList = patentInventorMergeService.getPatentInventorMergeByProjectId(params.getProjectId());
  604. List<Integer> patentInventorIds = new ArrayList<>();
  605. patentInventorLinkList.forEach(item -> patentInventorIds.add(item.getInventorId()));
  606. patentInventorMergeList.forEach(item -> patentInventorIds.add(item.getMergeId()));
  607. List<PatentInventor> patentInventorList = patentInventorService.getPatentInventorByIds(patentInventorIds);
  608. List<PatentLicensor> patentLicensorList = patentLicensorService.getPatentLicensorByPatentIds(patentIds);
  609. List<PatentPledge> patentPledgeList = patentPledgeService.getPatentPledgeByPatentIds(patentIds);
  610. List<PatentRight> patentRightList = patentRightService.getPatentRightByPatentIds(patentIds);
  611. List<Integer> patentFamilyIds = new ArrayList<>();
  612. patentList.forEach(item -> {
  613. patentFamilyIds.add(item.getSimpleFamily());
  614. patentFamilyIds.add(item.getInpadocFamily());
  615. patentFamilyIds.add(item.getPatSnapFamily());
  616. });
  617. List<PatentSimpleFamilyLink> patentSimpleFamilyLinkList = patentSimpleFamilyLinkService.getPatentSimpleFamilyLinkByFamilyIds(patentFamilyIds);
  618. List<PatentSimpleFamily> patentSimpleFamilyList = patentSimpleFamilyService.getPatentSimpleFamilyByIds(patentFamilyIds);
  619. List<PatentClassNumberLink> patentClassNumberLinkList = patentClassNumberLinkService.getPatentClassNumberLinkByPatentIds(patentIds);
  620. this.saveDataToJsonFile(tempPath, Constants.PATENT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentList)));
  621. this.saveDataToJsonFile(tempPath, Constants.PATENT_AFFAIR_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAffairList)));
  622. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENCY_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAgencyList)));
  623. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENT_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAgentLinkList)));
  624. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAgentList)));
  625. this.saveDataToJsonFile(tempPath, Constants.PATENT_INSTRUCTION_TEXT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInstructionTextList)));
  626. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInventorLinkList)));
  627. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInventorList)));
  628. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_MERGE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInventorMergeList)));
  629. this.saveDataToJsonFile(tempPath, Constants.PATENT_LICENSOR_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentLicensorList)));
  630. this.saveDataToJsonFile(tempPath, Constants.PATENT_PLEDGE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentPledgeList)));
  631. this.saveDataToJsonFile(tempPath, Constants.PATENT_RIGHT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentRightList)));
  632. this.saveDataToJsonFile(tempPath, Constants.PATENT_FAMILY_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentSimpleFamilyLinkList)));
  633. this.saveDataToJsonFile(tempPath, Constants.PATENT_FAMILY_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentSimpleFamilyList)));
  634. this.saveDataToJsonFile(tempPath, Constants.PATENT_CLASS_NUMBER_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentClassNumberLinkList)));
  635. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentApplicantList)));
  636. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentApplicantLinkList)));
  637. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_MERGE_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentApplicantMergeLinkList)));
  638. }
  639. if (params.getPatentField() != null && params.getPatentField().size() != 0) {
  640. if (params.getPatentField().contains(0)) {
  641. List<PatentLabel> patentLabelList = patentLabelService.getPatentLabelByPatentIdsAndProjectId(patentIds, params.getProjectId());
  642. this.saveDataToJsonFile(tempPath, Constants.PATENT_LABEL_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentLabelList)));
  643. }
  644. List<ProjectField> projectFieldList = projectFieldService.getFieldListByIds(params.getPatentField());
  645. List<Integer> projectFieldIds = projectFieldList.stream().map(ProjectField::getId).collect(Collectors.toList());
  646. List<ProjectFieldOption> projectFieldOptionList = projectFieldOptionService.getFieldOptionList(projectFieldIds);
  647. List<ProjectFieldTree> projectFieldTreeList = projectFieldTreeService.getProjectFieldTreeOptionByFieldIds(projectFieldIds);
  648. List<ProjectFieldText> projectFieldTextList = projectFieldTextService.getProjectFieldTextByFieldIds(projectFieldIds);
  649. List<ProjectFieldPatentLink> projectFieldPatentLinkList = new ArrayList<>();
  650. for (Integer fieldId : params.getPatentField()) {
  651. projectFieldPatentLinkList.addAll(projectFieldPatentLinkService.getProjectPatentLinkByPatentIdsAndFieldId(patentIds, fieldId));
  652. }
  653. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldList)));
  654. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_OPTION_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldOptionList)));
  655. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_TREE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldTreeList)));
  656. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_TEXT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldTextList)));
  657. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_PATENT_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldPatentLinkList)));
  658. }
  659. List<Patent> patents = patentService.getPatentIdAndPatentNoByIds(patentIds);
  660. this.saveDataToJsonFile(tempPath, Constants.PATENT_ID_PATENT_NO_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patents)));
  661. File file = ZipUtil.zip(tempPath, savePath);
  662. FileUtil.del(tempPath);
  663. ProjectExport projectExport = projectExportService.getById(exportId);
  664. projectExport.setUrl(url);
  665. projectExport.setFileName(fileName);
  666. projectExport.setStatus(1);
  667. projectExport.setFileSize(FileUtil.size(file));
  668. projectExport.updateById();
  669. WebSocketServer.sendInfo(Response.websocket(true, ResponseEnum.PROJECT_EXPORT_TASK_SUCCESS), String.valueOf(userId));
  670. } catch (Exception e) {
  671. e.printStackTrace();
  672. WebSocketServer.sendInfo(Response.websocket(false, ResponseEnum.PROJECT_EXPORT_TASK_ERROR), String.valueOf(userId));
  673. }
  674. }
  675. @Async("singleThreadAsyncTaskExecutor")
  676. @Transactional(rollbackFor = Exception.class)
  677. public void importData(String url, ProjectImportVO params, Integer userId, Integer importId) {
  678. String tempPath = null;
  679. ProjectImportStatusService projectImportStatusService = SpringUtil.getBean(ProjectImportStatusService.class);
  680. try {
  681. String tempDirectoryName = IdUtil.simpleUUID();
  682. tempPath = fileUtils.getTempPath(tempDirectoryName);
  683. String tempSavePath = fileUtils.getSystemPath(url);
  684. File tempDirectory = new File(tempPath);
  685. if (!tempDirectory.exists()) {
  686. boolean success = tempDirectory.mkdir();
  687. if (!success) {
  688. throw new Exception("数据导入时创建文件夹失败");
  689. }
  690. }
  691. projectImportStatusService.add(importId, userId, 2);
  692. ZipUtil.unzip(tempSavePath, tempPath);
  693. String projectJson = this.parseTempFileData(tempPath, Constants.PROJECT_INFO_FILE_NAME);
  694. Integer projectId = params.getProjectId();
  695. if (StringUtils.isNotEmpty(projectJson)) {
  696. projectImportStatusService.add(importId, userId, 3);
  697. projectId = this.importProject(params.getProjectId(), projectJson, userId);
  698. }
  699. if (projectId.equals(0)) {
  700. projectImportStatusService.add(importId, userId, 100);
  701. throw new CustomException("数据包未包含专题库信息");
  702. }
  703. String projectReportJson = this.parseTempFileData(tempPath, Constants.PROJECT_REPORT_FILE_NAME);
  704. String projectFileJson = this.parseTempFileData(tempPath, Constants.PROJECT_FILE_FILE_NAME);
  705. if (StringUtils.isNotEmpty(projectReportJson) || StringUtils.isNotEmpty(projectFileJson)) {
  706. projectImportStatusService.add(importId, userId, 4);
  707. projectFileService.importProjectFile(projectId, userId, tempPath, projectFileJson, projectReportJson);
  708. }
  709. String patentIdPatentNoJson = this.parseTempFileData(tempPath, Constants.PATENT_ID_PATENT_NO_FILE_NAME);
  710. String patentJson = this.parseTempFileData(tempPath, Constants.PATENT_FILE_NAME);
  711. String patentAffairJson = this.parseTempFileData(tempPath, Constants.PATENT_AFFAIR_FILE_NAME);
  712. String patentAgencyJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENCY_FILE_NAME);
  713. String patentAgentJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENT_FILE_NAME);
  714. String patentAgentLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENT_LINK_FILE_NAME);
  715. String patentInventorJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_FILE_NAME);
  716. String patentInventorMergeJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_MERGE_FILE_NAME);
  717. String patentInventorLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_LINK_FILE_NAME);
  718. String patentApplicantJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_FILE_NAME);
  719. String patentApplicantLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_LINK_FILE_NAME);
  720. String patentApplicantMergeLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_MERGE_LINK_FILE_NAME);
  721. String patentFamilyJson = this.parseTempFileData(tempPath, Constants.PATENT_FAMILY_FILE_NAME);
  722. String patentFamilyLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_FAMILY_LINK_FILE_NAME);
  723. String patentClassNumberJson = this.parseTempFileData(tempPath, Constants.PATENT_CLASS_NUMBER_FILE_NAME);
  724. String patentInstructionTextJson = this.parseTempFileData(tempPath, Constants.PATENT_INSTRUCTION_TEXT_FILE_NAME);
  725. String patentRightJson = this.parseTempFileData(tempPath, Constants.PATENT_RIGHT_FILE_NAME);
  726. String patentLicensorJson = this.parseTempFileData(tempPath, Constants.PATENT_LICENSOR_FILE_NAME);
  727. String patentPledgeJson = this.parseTempFileData(tempPath, Constants.PATENT_PLEDGE_FILE_NAME);
  728. if (StringUtils.isNotEmpty(patentJson)) {
  729. projectImportStatusService.add(importId, userId, 8);
  730. patentService.importPatent(projectId, patentJson, patentAffairJson, patentAgencyJson, patentFamilyJson, patentFamilyLinkJson, patentInventorJson, patentInventorLinkJson, patentAgentJson, patentAgentLinkJson, patentApplicantJson, patentApplicantLinkJson, patentApplicantMergeLinkJson, patentClassNumberJson, patentInstructionTextJson, patentRightJson, patentLicensorJson, patentPledgeJson, patentInventorMergeJson);
  731. }
  732. projectImportStatusService.add(importId, userId, 9);
  733. projectPatentLinkService.importProjectPatentLink(projectId, patentIdPatentNoJson);
  734. String projectFieldJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_FILE_NAME);
  735. if (StringUtils.isNotEmpty(projectFieldJson)) {
  736. String projectFieldTextJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_TEXT_FILE_NAME);
  737. String projectFieldOptionJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_OPTION_FILE_NAME);
  738. String projectFieldTreeJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_TREE_FILE_NAME);
  739. String projectFieldPatentLink = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_PATENT_LINK_FILE_NAME);
  740. projectImportStatusService.add(importId, userId, 5);
  741. projectFieldService.importProjectField(projectId, userId, patentIdPatentNoJson, projectFieldJson, projectFieldTextJson, projectFieldOptionJson, projectFieldTreeJson, projectFieldPatentLink);
  742. }
  743. String patentImageJson = this.parseTempFileData(tempPath, Constants.PATENT_IMAGE_FILE_NAME);
  744. if (StringUtils.isNotEmpty(patentImageJson)) {
  745. projectImportStatusService.add(importId, userId, 6);
  746. patentImageService.importPatentImage(tempPath, patentIdPatentNoJson, patentImageJson);
  747. }
  748. String patentInstructionJson = this.parseTempFileData(tempPath, Constants.PATENT_INSTRUCTION_FILE_NAME);
  749. if (StringUtils.isNotEmpty(patentInstructionJson)) {
  750. projectImportStatusService.add(importId, userId, 7);
  751. patentInstructionService.importPatentInstruction(userId, tempPath, patentIdPatentNoJson, patentInstructionJson);
  752. }
  753. } catch (Exception e) {
  754. e.printStackTrace();
  755. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  756. projectImportStatusService.add(importId, userId, 101);
  757. } finally {
  758. FileUtil.del(tempPath);
  759. projectImportStatusService.add(importId, userId, 200);
  760. cacheUtils.deleteUserImport(userId);
  761. }
  762. }
  763. private String parseTempFileData(String path, String fileName) throws IOException {
  764. String src = path + FileUtil.FILE_SEPARATOR + fileName;
  765. if (!FileUtil.exist(src)) {
  766. return null;
  767. }
  768. File file = new File(src);
  769. FileReader fileReader = new FileReader(file);
  770. Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
  771. int ch;
  772. StringBuffer sb = new StringBuffer();
  773. while ((ch = reader.read()) != -1) {
  774. sb.append((char) ch);
  775. }
  776. fileReader.close();
  777. reader.close();
  778. return sb.toString();
  779. }
  780. //主页面 导出列表功能
  781. public void exportProject(HttpServletResponse response) {
  782. try {
  783. ProjectVO params = new ProjectVO();
  784. params.setSize(99999999999L);
  785. params.setCurrent(1L);
  786. params.setMyself(false);
  787. ProjectVO.Sort sort = new ProjectVO.Sort();
  788. sort.setProp("create_time");
  789. sort.setOrder("desc");
  790. params.setSort(sort);
  791. IPage<Project> pageList = this.getPageList(params);
  792. List<Project> projectList = pageList.getRecords();
  793. List<List<String>> row = new ArrayList<>();
  794. row.add(CollUtil.newArrayList("#", "名称", "委托方", "调查类型", "应用场景", "技术主题", "合同号", "委案日", "创建人"));
  795. for (int i = 0; i < projectList.size(); i++) {
  796. Project project = projectList.get(i);
  797. 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()));
  798. }
  799. List<List<String>> rows = CollUtil.newArrayList(row);
  800. ExcelWriter writer = ExcelUtil.getWriter(true);
  801. OutputStream out = response.getOutputStream();
  802. writer.write(rows, true);
  803. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  804. response.setHeader("Content-Disposition", "attachment;filename=" + IdUtil.simpleUUID() + ".xlsx");
  805. writer.flush(out, true);
  806. writer.close();
  807. IoUtil.close(out);
  808. } catch (Exception e) {
  809. e.printStackTrace();
  810. }
  811. }
  812. }