ProjectService.java 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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. return this.list(queryWrapper);
  166. }
  167. public List<Project> getProjectByCreateId(Integer createBy) {
  168. LambdaQueryWrapper<Project> queryWrapper = new LambdaQueryWrapper<>();
  169. queryWrapper.eq(Project::getCreateBy, createBy);
  170. return this.list(queryWrapper);
  171. }
  172. public Project getProjectById(Integer id) {
  173. Project project = this.getById(id);
  174. Client client = clientService.getById(project.getClientId());
  175. if (client != null) {
  176. project.setClientName(client.getName());
  177. }
  178. return project;
  179. }
  180. private void setDataList(List<Project> dataList) {
  181. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.ENTERPRISE_APPLICATION_SCENARIO, Constants.INVESTIGATION_TYPE));
  182. dataList.forEach(item -> {
  183. if (StringUtils.isNotEmpty(item.getScenario())) {
  184. item.setScenarioList(StringUtils.changeStringToInteger(item.getScenario(), ","));
  185. 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()));
  186. item.setScenario(null);
  187. }
  188. if (StringUtils.isNotEmpty(item.getType())) {
  189. item.setTypeList(StringUtils.changeStringToInteger(item.getType(), ","));
  190. 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()));
  191. item.setType(null);
  192. }
  193. });
  194. }
  195. public List<Project> getAllProjectByMySelf() {
  196. //使用专题库查询的权限查询,因为要使用专题库的权限,因此查询语句格式需要和专题库查询的格式统一,所以手写了查询语句
  197. securityUtils.startDataScope("/workspace/project/check");
  198. List<Project> projectList = baseMapper.getListForCount();
  199. this.setDataList(projectList);
  200. return projectList;
  201. }
  202. public Map<Object, Object> getProjectStatusTotal() {
  203. Map<Object, Object> map = new HashMap<>();
  204. List<Project> projectList = this.getAllProjectByMySelf();
  205. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.ENTERPRISE_APPLICATION_SCENARIO));
  206. for (SystemDict systemDict : systemDictList) {
  207. Map<String, Object> result = new HashMap<>();
  208. List<Project> tempList = projectList.stream().filter(item -> item.getScenarioList().contains(Integer.parseInt(systemDict.getValue()))).collect(Collectors.toList());
  209. result.put("completed", tempList.stream().filter(item -> item.getStatus().equals("1")).count());
  210. result.put("unfinished", tempList.stream().filter(item -> item.getStatus().equals("0")).count());
  211. map.put(systemDict.getLabel(), result);
  212. }
  213. return map;
  214. }
  215. public Map<String, Object> getProjectTypeTotal(String scenario) {
  216. Map<String, Object> map = new HashMap<>();
  217. List<Project> projectList = this.getAllProjectByMySelf();
  218. projectList = projectList.stream().filter(item -> item.getScenarioName().contains(scenario)).collect(Collectors.toList());
  219. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Collections.singletonList(Constants.INVESTIGATION_TYPE));
  220. for (SystemDict systemDict : systemDictList) {
  221. map.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getTypeList().contains(Integer.parseInt(systemDict.getValue()))).count());
  222. }
  223. return map;
  224. }
  225. public Map<Object, Object> getScenarioAndTypeTotal() {
  226. List<Project> projectList = this.getAllProjectByMySelf();
  227. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.ENTERPRISE_APPLICATION_SCENARIO, Constants.INVESTIGATION_TYPE));
  228. List<Client> clientList = clientService.getClientByObjectIds(this.getClientIds(projectList.stream().map(Project::getClientId).collect(Collectors.toList())));
  229. Map<Object, Object> type = new HashMap<>();
  230. Map<Object, Object> scenario = new HashMap<>();
  231. Map<Object, Object> result = new HashMap<>();
  232. Map<Object, Object> client = new HashMap<>();
  233. Map<Object, Object> create = new HashMap<>();
  234. systemDictList.forEach(systemDict -> {
  235. switch (systemDict.getType()) {
  236. case Constants.ENTERPRISE_APPLICATION_SCENARIO:
  237. scenario.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getScenarioList().contains(Integer.parseInt(systemDict.getValue()))).count());
  238. break;
  239. case Constants.INVESTIGATION_TYPE:
  240. type.put(systemDict.getLabel(), projectList.stream().filter(item -> item.getTypeList().contains(Integer.parseInt(systemDict.getValue()))).count());
  241. break;
  242. }
  243. });
  244. clientList.forEach(item -> client.put(item.getName(), projectList.stream().filter(project -> project.getClientId().equals(item.getId())).count()));
  245. Date date = DateUtil.date();
  246. for (int i = 0; i < 6; i++) {
  247. Date finalDate = date;
  248. 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());
  249. date = DateUtil.offset(date, DateField.MONTH, -1);
  250. }
  251. result.put("scenario", scenario);
  252. result.put("type", type);
  253. result.put("client", client);
  254. result.put("create", create);
  255. return result;
  256. }
  257. private List<Object> getClientIds(List<Integer> clientIds) {
  258. Map<Object, Long> map = clientIds.stream().collect(Collectors.groupingBy(p -> p, Collectors.counting()));
  259. return map.entrySet().stream()
  260. .sorted((Map.Entry<Object, Long> o1, Map.Entry<Object, Long> o2) -> o2.getValue().intValue() - o1.getValue().intValue())
  261. .map(Map.Entry::getKey).collect(Collectors.toList())
  262. .subList(0, Math.min(map.size(), 10));
  263. }
  264. public String getImportProjectName(String name) {
  265. String tempName = name + "(1)";
  266. Project project1 = this.getProjectByName(name);
  267. if (project1 == null) {
  268. return name;
  269. }
  270. Project project2 = this.getProjectByName(tempName);
  271. if (project2 != null) {
  272. tempName = this.getImportProjectName(tempName);
  273. }
  274. return tempName;
  275. }
  276. public Integer importProject(Integer projectId, String json, Integer userId) {
  277. if ((projectId == null || projectId.equals(0)) && StringUtils.isEmpty(json)) {
  278. return 0;
  279. }
  280. if (StringUtils.isEmpty(json)) {
  281. return projectId;
  282. }
  283. Project temp = this.getById(projectId);
  284. Project data = JsonUtils.jsonToPojo(json, Project.class);
  285. Client client = clientService.getClientByName(Objects.requireNonNull(data).getClientName());
  286. if (client == null) {
  287. client = new Client();
  288. client.setName(data.getClientName());
  289. client.setStatus(1);
  290. client.setCreateBy(userId);
  291. client.setCreateTime(DateUtils.getDateTime());
  292. client.insert();
  293. }
  294. if (temp == null) {
  295. temp = new Project();
  296. }
  297. String projectName = temp.getName();
  298. BeanUtils.copyProperties(data, temp);
  299. if (projectName == null || !projectName.equals(data.getName())) {
  300. temp.setName(this.getImportProjectName(temp.getName()));
  301. }
  302. temp.setClientId(client.getId());
  303. if (projectId == null || projectId.equals(0)) {
  304. temp.setCreateBy(userId);
  305. temp.setCreateTime(DateUtils.getDateTime());
  306. temp.setId(null);
  307. } else {
  308. temp.setId(projectId);
  309. }
  310. temp.insertOrUpdate();
  311. return temp.getId();
  312. }
  313. @Transactional
  314. public String add(Project project) {
  315. PersonnelVO user = cacheUtils.getLoginUserPersonnel(loginUtils.getId());
  316. Project temp = this.getProjectByName(project.getName());
  317. if (temp != null) {
  318. return Response.error("专题库名称已存在");
  319. }
  320. if (project.getClientId() == -1) {
  321. project.setClientId(this.getNewClientId(project.getClientName(), user.getTenantId()));
  322. }
  323. project.setScenario(StringUtils.join(project.getScenarioList(), ","));
  324. project.setType(StringUtils.join(project.getTypeList(), ","));
  325. project.setCreateBy(loginUtils.getId());
  326. project.setCreateTime(DateUtils.getDateTime());
  327. project.setTenantId(user.getTenantId());
  328. project.insert();
  329. this.addProjectUser(project.getId());
  330. return Response.success(project.getId());
  331. }
  332. @Transactional
  333. public String edit(Project project) {
  334. Project temp = this.getProjectByName(project.getName());
  335. Project project1 = this.getProjectById(project.getId());
  336. if (temp != null && !temp.getId().equals(project.getId())) {
  337. return Response.error("专题库名称已存在");
  338. }
  339. if (project.getClientId() == -1) {
  340. project.setClientId(this.getNewClientId(project.getClientName(), project1.getTenantId()));
  341. }
  342. project.setScenario(StringUtils.join(project.getScenarioList(), ","));
  343. project.setType(StringUtils.join(project.getTypeList(), ","));
  344. project.updateById();
  345. return Response.success();
  346. }
  347. @Transactional
  348. public String delete(Integer id) {
  349. this.removeById(id);
  350. this.deleteProjectUser(id, loginUtils.getId());
  351. projectPatentLinkService.deleteByProjectId(id);
  352. projectFolderService.deleteByProjectId(id);
  353. projectFieldService.deleteByProjectId(id);
  354. projectUserService.deleteByProjectId(id);
  355. projectFileService.deleteByProjectId(id);
  356. patentApplicantMergeLinkService.deleteByProjectId(id);
  357. return Response.success();
  358. }
  359. private Integer getNewClientId(String name, Integer tenantId) {
  360. Client client = clientService.getOne(Wrappers.<Client>lambdaQuery().eq(Client::getName, name).last("limit 1"));
  361. if (client == null) {
  362. client = new Client();
  363. client.setName(name);
  364. client.setStatus(1);
  365. client.setCreateBy(loginUtils.getId());
  366. client.setCreateTime(DateUtils.getDateTime());
  367. client.setTenantId(tenantId);
  368. client.insert();
  369. }
  370. return client.getId();
  371. }
  372. private void addProjectUser(Integer projectId) {
  373. ProjectUser user = new ProjectUser();
  374. user.setUserId(loginUtils.getId());
  375. user.setProjectId(projectId);
  376. user.setCreateTime(DateUtils.getDateTime());
  377. user.setType(2);
  378. user.insert();
  379. }
  380. private void deleteProjectUser(Integer projectId, Integer userId) {
  381. projectUserService.remove(Wrappers.<ProjectUser>lambdaQuery().eq(ProjectUser::getUserId, userId).eq(ProjectUser::getProjectId, projectId));
  382. }
  383. @Transactional(rollbackFor = Exception.class)
  384. public String importExcel(MultipartFile file) {
  385. try {
  386. PersonnelVO user = cacheUtils.getLoginUserPersonnel(loginUtils.getId());
  387. ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
  388. List<Map<String, Object>> readAll = reader.readAll();
  389. List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(Arrays.asList(Constants.INVESTIGATION_TYPE, Constants.ENTERPRISE_APPLICATION_SCENARIO));
  390. for (Map<String, Object> row : readAll) {
  391. Project project = new Project();
  392. project.setSort(1);
  393. project.setName(row.get("专题库名称").toString());
  394. project.setClientId(this.getNewClientId(row.get("委托方").toString(), user.getTenantId()));
  395. project.setRemark(row.get("备注").toString());
  396. project.setCreateBy(loginUtils.getId());
  397. project.setCreateTime(DateUtils.getDateTime());
  398. List<String> typeName = StringUtils.changeStringToString(row.get("调查类型").toString(), ";");
  399. 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());
  400. project.setType(StringUtils.join(typeList, ","));
  401. List<String> scenarioName = StringUtils.changeStringToString(row.get("企业应用场景").toString(), ";");
  402. 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());
  403. project.setScenario(StringUtils.join(scenarioList, ","));
  404. project.setTechnicalTheme(row.get("技术主题").toString());
  405. project.setContractNo(row.get("合同号").toString());
  406. project.setInnerFile(row.get("内部案卷").toString());
  407. Object caseDate = row.get("委案日");
  408. if (StringUtils.isNotNull(caseDate)) {
  409. project.setCaseDate(caseDate.toString());
  410. }
  411. project.setStatus(row.get("处理状态").toString().equals("处理中") ? "0" : "1");
  412. Object update = row.get("是否更新");
  413. if (StringUtils.isNotNull(update)) {
  414. project.setUpdate(update.toString().equals("是") ? 1 : 0);
  415. project.setUpdateTime(row.get("更新周期").toString());
  416. } else {
  417. project.setUpdate(0);
  418. project.setUpdateTime("一天");
  419. }
  420. project.insert();
  421. List<String> userName = StringUtils.changeStringToString(row.get("管理员").toString(), ";");
  422. List<User> userList = userService.getUserByNames(userName);
  423. List<ProjectUser> projectUserList = new ArrayList<>();
  424. userList.forEach(item -> {
  425. ProjectUser projectUser = new ProjectUser();
  426. projectUser.setProjectId(project.getId());
  427. projectUser.setUserId(item.getId());
  428. projectUser.setCreateTime(DateUtils.getDateTime());
  429. projectUser.setType(2);
  430. projectUserList.add(projectUser);
  431. });
  432. projectUserService.saveOrUpdateBatch(projectUserList);
  433. }
  434. return Response.success(true);
  435. } catch (Exception e) {
  436. e.printStackTrace();
  437. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  438. return Response.error();
  439. }
  440. }
  441. @Transactional
  442. public String share(Integer id, List<Integer> userIds, List<ProjectUser.User> users) {
  443. ProjectUser user = new ProjectUser();
  444. user.setType(3);
  445. user.setRemark("用户分享");
  446. user.setProjectId(id);
  447. user.setUserIds(userIds);
  448. user.setUsers(users);
  449. return projectUserService.add(user);
  450. }
  451. public TaskParams getImportPatentTaskParams(MultipartFile file, Integer projectId) {
  452. UploadFileDTO fileDTO = fileUtils.uploadFile(file);
  453. String path = fileUtils.getPath(fileDTO.getPath());
  454. List<List<Object>> rowList = new ArrayList<>();
  455. List<Map<Object, Object>> mapList = new ArrayList<>();
  456. ExcelUtil.readBySax(path, -1, (sheetIndex, rowIndex, row) -> rowList.add(row));
  457. for (int i = 1; i < rowList.size(); i++) {
  458. mapList.add(IterUtil.toMap(rowList.get(0), rowList.get(i)));
  459. }
  460. Integer taskId = taskService.add(fileDTO, projectId, rowList.size() - 1, 1, 0, file.getOriginalFilename());
  461. TaskParams taskParams = new TaskParams();
  462. taskParams.setTaskId(taskId);
  463. taskParams.setPath(path);
  464. taskParams.setTaskType(1);
  465. taskParams.setRowList(mapList);
  466. taskParams.setUserId(String.valueOf(loginUtils.getId()));
  467. taskParams.setOldName(file.getOriginalFilename());
  468. return taskParams;
  469. }
  470. @Transactional(propagation = Propagation.NOT_SUPPORTED)
  471. public void setImportPatentTaskStatus(Integer status, Integer taskId) {
  472. taskService.updateStatus(taskId, status, DateUtils.getDateTime());
  473. }
  474. public void saveDataToJsonFile(String tempPath, String fileName, String data) throws IOException {
  475. String path = tempPath + FileUtils.FILE_SEPARATOR + fileName;
  476. FileOutputStream fileOutputStream = new FileOutputStream(path);
  477. fileOutputStream.write(data.getBytes(StandardCharsets.UTF_8));
  478. fileOutputStream.close();
  479. }
  480. public void copyFileToTempDirectory(String src, String tempPath, String directoryName, String fileName) {
  481. String dest = tempPath + FileUtils.FILE_SEPARATOR + directoryName + FileUtils.FILE_SEPARATOR + fileName;
  482. File file = FileUtil.file(fileUtils.getSystemPath(src));
  483. if (FileUtil.exist(file)) {
  484. FileUtil.copy(file, new File(dest), true);
  485. }
  486. }
  487. @Async
  488. public void export(ProjectExportVO params, Integer exportId, Integer userId) {
  489. try {
  490. String json = cacheUtils.getSelectPatentIds(params.getKey());
  491. List<Integer> patentIds = StringUtils.changeStringToInteger(json, ",");
  492. List<Patent> patentList = patentService.getPatentListByIds(patentIds);
  493. String directoryName = IdUtil.simpleUUID();
  494. String fileName = directoryName + ".zip";
  495. String tempPath = fileUtils.getTempPath(directoryName);
  496. String url = fileUtils.getDirectory(fileName);
  497. String savePath = fileUtils.getSystemPath(url);
  498. File directory = new File(tempPath);
  499. if (!directory.exists()) {
  500. boolean success = directory.mkdir();
  501. if (!success) {
  502. throw new Exception("数据导出时创建文件夹失败");
  503. }
  504. }
  505. WebSocketServer.sendInfo(Response.websocket(true, ResponseEnum.PROJECT_EXPORT_TASK_SUCCESS), String.valueOf(userId));
  506. if (params.getProjectInfo()) {
  507. Project project = this.getProjectById(params.getProjectId());
  508. this.saveDataToJsonFile(tempPath, Constants.PROJECT_INFO_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(project)));
  509. }
  510. if (params.getProjectReport() != null && params.getProjectReport().size() != 0) {
  511. List<ProjectFile> projectFileList = projectFileService.getProjectFileByIds(params.getProjectReport());
  512. this.saveDataToJsonFile(tempPath, Constants.PROJECT_REPORT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFileList)));
  513. projectFileList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PROJECT_REPORT_DIRECTORY_NAME, item.getFileName()));
  514. }
  515. if (params.getProjectFile() != null && params.getProjectFile().size() != 0) {
  516. List<ProjectFile> projectFileList = projectFileService.getProjectFileByIds(params.getProjectFile());
  517. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FILE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFileList)));
  518. projectFileList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PROJECT_FILE_DIRECTORY_NAME, item.getFileName()));
  519. }
  520. if (params.getPatentImage()) {
  521. List<PatentImage> patentImageList = patentImageService.getPatentImageByPatentIds(patentIds);
  522. this.saveDataToJsonFile(tempPath, Constants.PATENT_IMAGE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentImageList)));
  523. patentImageList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PATENT_IMAGE_DIRECTORY_NAME, item.getFileName()));
  524. }
  525. if (params.getPatentInstruction()) {
  526. List<String> patentNo = patentList.stream().map(Patent::getPatentNo).collect(Collectors.toList());
  527. List<PatentInstruction> patentInstructionList = patentInstructionService.getPatentInstructionByPatentNo(patentNo);
  528. this.saveDataToJsonFile(tempPath, Constants.PATENT_INSTRUCTION_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInstructionList)));
  529. patentInstructionList.forEach(item -> this.copyFileToTempDirectory(item.getUrl(), tempPath, Constants.PATENT_INSTRUCTION_DIRECTORY_NAME, item.getFileName()));
  530. }
  531. if (params.getPatentBase()) {
  532. List<PatentApplicantLink> patentApplicantLinkList = patentApplicantLinkService.getApplicantAttributesListByPatentIds(patentIds);
  533. List<PatentApplicantMergeLink> patentApplicantMergeLinkList = patentApplicantMergeLinkService.getPatentApplicantMergeLinkListByProjectId(params.getProjectId());
  534. List<Integer> patentApplicantIds = new ArrayList<>();
  535. patentApplicantLinkList.forEach(item -> patentApplicantIds.add(item.getApplicantId()));
  536. patentApplicantMergeLinkList.forEach(item -> patentApplicantIds.add(item.getMergeId()));
  537. List<PatentApplicant> patentApplicantList = patentApplicantService.getPatentApplicantByIds(patentApplicantIds);
  538. List<PatentAffair> patentAffairList = patentAffairService.getPatentAffairListByPatentIds(patentIds);
  539. List<PatentAgency> patentAgencyList = patentAgencyService.getPatentAgencyByIds(patentList.stream().filter(item -> StringUtils.isNotEmpty(item.getAgencyId())).map(item -> Integer.parseInt(item.getAgencyId())).collect(Collectors.toList()));
  540. List<PatentAgentLink> patentAgentLinkList = patentAgentLinkService.getPatentAgentLinkByPatentIds(patentIds);
  541. List<PatentAgent> patentAgentList = patentAgentService.getPatentAgentByIds(patentAgentLinkList.stream().map(PatentAgentLink::getAgentId).collect(Collectors.toList()));
  542. List<PatentInstructionText> patentInstructionTextList = patentInstructionTextService.getPatentInstructionTextByPatentIds(patentIds);
  543. List<PatentInventorLink> patentInventorLinkList = patentInventorLinkService.getPatentInventorLinkByPatentIds(patentIds);
  544. List<PatentInventorMerge> patentInventorMergeList = patentInventorMergeService.getPatentInventorMergeByProjectId(params.getProjectId());
  545. List<Integer> patentInventorIds = new ArrayList<>();
  546. patentInventorLinkList.forEach(item -> patentInventorIds.add(item.getInventorId()));
  547. patentInventorMergeList.forEach(item -> patentInventorIds.add(item.getMergeId()));
  548. List<PatentInventor> patentInventorList = patentInventorService.getPatentInventorByIds(patentInventorIds);
  549. List<PatentLicensor> patentLicensorList = patentLicensorService.getPatentLicensorByPatentIds(patentIds);
  550. List<PatentPledge> patentPledgeList = patentPledgeService.getPatentPledgeByPatentIds(patentIds);
  551. List<PatentRight> patentRightList = patentRightService.getPatentRightByPatentIds(patentIds);
  552. List<Integer> patentFamilyIds = new ArrayList<>();
  553. patentList.forEach(item -> {
  554. patentFamilyIds.add(item.getSimpleFamily());
  555. patentFamilyIds.add(item.getInpadocFamily());
  556. patentFamilyIds.add(item.getPatSnapFamily());
  557. });
  558. List<PatentSimpleFamilyLink> patentSimpleFamilyLinkList = patentSimpleFamilyLinkService.getPatentSimpleFamilyLinkByFamilyIds(patentFamilyIds);
  559. List<PatentSimpleFamily> patentSimpleFamilyList = patentSimpleFamilyService.getPatentSimpleFamilyByIds(patentFamilyIds);
  560. List<PatentClassNumberLink> patentClassNumberLinkList = patentClassNumberLinkService.getPatentClassNumberLinkByPatentIds(patentIds);
  561. this.saveDataToJsonFile(tempPath, Constants.PATENT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentList)));
  562. this.saveDataToJsonFile(tempPath, Constants.PATENT_AFFAIR_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAffairList)));
  563. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENCY_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAgencyList)));
  564. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENT_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAgentLinkList)));
  565. this.saveDataToJsonFile(tempPath, Constants.PATENT_AGENT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentAgentList)));
  566. this.saveDataToJsonFile(tempPath, Constants.PATENT_INSTRUCTION_TEXT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInstructionTextList)));
  567. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInventorLinkList)));
  568. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInventorList)));
  569. this.saveDataToJsonFile(tempPath, Constants.PATENT_INVENTOR_MERGE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentInventorMergeList)));
  570. this.saveDataToJsonFile(tempPath, Constants.PATENT_LICENSOR_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentLicensorList)));
  571. this.saveDataToJsonFile(tempPath, Constants.PATENT_PLEDGE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentPledgeList)));
  572. this.saveDataToJsonFile(tempPath, Constants.PATENT_RIGHT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentRightList)));
  573. this.saveDataToJsonFile(tempPath, Constants.PATENT_FAMILY_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentSimpleFamilyLinkList)));
  574. this.saveDataToJsonFile(tempPath, Constants.PATENT_FAMILY_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentSimpleFamilyList)));
  575. this.saveDataToJsonFile(tempPath, Constants.PATENT_CLASS_NUMBER_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentClassNumberLinkList)));
  576. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentApplicantList)));
  577. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentApplicantLinkList)));
  578. this.saveDataToJsonFile(tempPath, Constants.PATENT_APPLICANT_MERGE_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentApplicantMergeLinkList)));
  579. }
  580. if (params.getPatentField() != null && params.getPatentField().size() != 0) {
  581. if (params.getPatentField().contains(0)) {
  582. List<PatentLabel> patentLabelList = patentLabelService.getPatentLabelByPatentIdsAndProjectId(patentIds, params.getProjectId());
  583. this.saveDataToJsonFile(tempPath, Constants.PATENT_LABEL_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patentLabelList)));
  584. }
  585. List<ProjectField> projectFieldList = projectFieldService.getFieldListByIds(params.getPatentField());
  586. List<Integer> projectFieldIds = projectFieldList.stream().map(ProjectField::getId).collect(Collectors.toList());
  587. List<ProjectFieldOption> projectFieldOptionList = projectFieldOptionService.getFieldOptionList(projectFieldIds);
  588. List<ProjectFieldTree> projectFieldTreeList = projectFieldTreeService.getProjectFieldTreeOptionByFieldIds(projectFieldIds);
  589. List<ProjectFieldText> projectFieldTextList = projectFieldTextService.getProjectFieldTextByFieldIds(projectFieldIds);
  590. List<ProjectFieldPatentLink> projectFieldPatentLinkList = new ArrayList<>();
  591. for (Integer fieldId : params.getPatentField()) {
  592. projectFieldPatentLinkList.addAll(projectFieldPatentLinkService.getProjectPatentLinkByPatentIdsAndFieldId(patentIds, fieldId));
  593. }
  594. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldList)));
  595. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_OPTION_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldOptionList)));
  596. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_TREE_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldTreeList)));
  597. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_TEXT_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldTextList)));
  598. this.saveDataToJsonFile(tempPath, Constants.PROJECT_FIELD_PATENT_LINK_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(projectFieldPatentLinkList)));
  599. }
  600. List<Patent> patents = patentService.getPatentIdAndPatentNoByIds(patentIds);
  601. this.saveDataToJsonFile(tempPath, Constants.PATENT_ID_PATENT_NO_FILE_NAME, Objects.requireNonNull(JsonUtils.objectToJson(patents)));
  602. File file = ZipUtil.zip(tempPath, savePath);
  603. FileUtil.del(tempPath);
  604. ProjectExport projectExport = projectExportService.getById(exportId);
  605. projectExport.setUrl(url);
  606. projectExport.setFileName(fileName);
  607. projectExport.setStatus(1);
  608. projectExport.setFileSize(FileUtil.size(file));
  609. projectExport.updateById();
  610. WebSocketServer.sendInfo(Response.websocket(true, ResponseEnum.PROJECT_EXPORT_TASK_SUCCESS), String.valueOf(userId));
  611. } catch (Exception e) {
  612. e.printStackTrace();
  613. WebSocketServer.sendInfo(Response.websocket(false, ResponseEnum.PROJECT_EXPORT_TASK_ERROR), String.valueOf(userId));
  614. }
  615. }
  616. @Async("singleThreadAsyncTaskExecutor")
  617. @Transactional(rollbackFor = Exception.class)
  618. public void importData(String url, ProjectImportVO params, Integer userId, Integer importId) {
  619. String tempPath = null;
  620. ProjectImportStatusService projectImportStatusService = SpringUtil.getBean(ProjectImportStatusService.class);
  621. try {
  622. String tempDirectoryName = IdUtil.simpleUUID();
  623. tempPath = fileUtils.getTempPath(tempDirectoryName);
  624. String tempSavePath = fileUtils.getSystemPath(url);
  625. File tempDirectory = new File(tempPath);
  626. if (!tempDirectory.exists()) {
  627. boolean success = tempDirectory.mkdir();
  628. if (!success) {
  629. throw new Exception("数据导入时创建文件夹失败");
  630. }
  631. }
  632. projectImportStatusService.add(importId, userId, 2);
  633. ZipUtil.unzip(tempSavePath, tempPath);
  634. String projectJson = this.parseTempFileData(tempPath, Constants.PROJECT_INFO_FILE_NAME);
  635. Integer projectId = params.getProjectId();
  636. if (StringUtils.isNotEmpty(projectJson)) {
  637. projectImportStatusService.add(importId, userId, 3);
  638. projectId = this.importProject(params.getProjectId(), projectJson, userId);
  639. }
  640. if (projectId.equals(0)) {
  641. projectImportStatusService.add(importId, userId, 100);
  642. throw new CustomException("数据包未包含专题库信息");
  643. }
  644. String projectReportJson = this.parseTempFileData(tempPath, Constants.PROJECT_REPORT_FILE_NAME);
  645. String projectFileJson = this.parseTempFileData(tempPath, Constants.PROJECT_FILE_FILE_NAME);
  646. if (StringUtils.isNotEmpty(projectReportJson) || StringUtils.isNotEmpty(projectFileJson)) {
  647. projectImportStatusService.add(importId, userId, 4);
  648. projectFileService.importProjectFile(projectId, userId, tempPath, projectFileJson, projectReportJson);
  649. }
  650. String patentIdPatentNoJson = this.parseTempFileData(tempPath, Constants.PATENT_ID_PATENT_NO_FILE_NAME);
  651. String patentJson = this.parseTempFileData(tempPath, Constants.PATENT_FILE_NAME);
  652. String patentAffairJson = this.parseTempFileData(tempPath, Constants.PATENT_AFFAIR_FILE_NAME);
  653. String patentAgencyJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENCY_FILE_NAME);
  654. String patentAgentJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENT_FILE_NAME);
  655. String patentAgentLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_AGENT_LINK_FILE_NAME);
  656. String patentInventorJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_FILE_NAME);
  657. String patentInventorMergeJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_MERGE_FILE_NAME);
  658. String patentInventorLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_INVENTOR_LINK_FILE_NAME);
  659. String patentApplicantJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_FILE_NAME);
  660. String patentApplicantLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_LINK_FILE_NAME);
  661. String patentApplicantMergeLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_APPLICANT_MERGE_LINK_FILE_NAME);
  662. String patentFamilyJson = this.parseTempFileData(tempPath, Constants.PATENT_FAMILY_FILE_NAME);
  663. String patentFamilyLinkJson = this.parseTempFileData(tempPath, Constants.PATENT_FAMILY_LINK_FILE_NAME);
  664. String patentClassNumberJson = this.parseTempFileData(tempPath, Constants.PATENT_CLASS_NUMBER_FILE_NAME);
  665. String patentInstructionTextJson = this.parseTempFileData(tempPath, Constants.PATENT_INSTRUCTION_TEXT_FILE_NAME);
  666. String patentRightJson = this.parseTempFileData(tempPath, Constants.PATENT_RIGHT_FILE_NAME);
  667. String patentLicensorJson = this.parseTempFileData(tempPath, Constants.PATENT_LICENSOR_FILE_NAME);
  668. String patentPledgeJson = this.parseTempFileData(tempPath, Constants.PATENT_PLEDGE_FILE_NAME);
  669. if (StringUtils.isNotEmpty(patentJson)) {
  670. projectImportStatusService.add(importId, userId, 8);
  671. patentService.importPatent(projectId, patentJson, patentAffairJson, patentAgencyJson, patentFamilyJson, patentFamilyLinkJson, patentInventorJson, patentInventorLinkJson, patentAgentJson, patentAgentLinkJson, patentApplicantJson, patentApplicantLinkJson, patentApplicantMergeLinkJson, patentClassNumberJson, patentInstructionTextJson, patentRightJson, patentLicensorJson, patentPledgeJson, patentInventorMergeJson);
  672. }
  673. projectImportStatusService.add(importId, userId, 9);
  674. projectPatentLinkService.importProjectPatentLink(projectId, patentIdPatentNoJson);
  675. String projectFieldJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_FILE_NAME);
  676. if (StringUtils.isNotEmpty(projectFieldJson)) {
  677. String projectFieldTextJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_TEXT_FILE_NAME);
  678. String projectFieldOptionJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_OPTION_FILE_NAME);
  679. String projectFieldTreeJson = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_TREE_FILE_NAME);
  680. String projectFieldPatentLink = this.parseTempFileData(tempPath, Constants.PROJECT_FIELD_PATENT_LINK_FILE_NAME);
  681. projectImportStatusService.add(importId, userId, 5);
  682. projectFieldService.importProjectField(projectId, userId, patentIdPatentNoJson, projectFieldJson, projectFieldTextJson, projectFieldOptionJson, projectFieldTreeJson, projectFieldPatentLink);
  683. }
  684. String patentImageJson = this.parseTempFileData(tempPath, Constants.PATENT_IMAGE_FILE_NAME);
  685. if (StringUtils.isNotEmpty(patentImageJson)) {
  686. projectImportStatusService.add(importId, userId, 6);
  687. patentImageService.importPatentImage(tempPath, patentIdPatentNoJson, patentImageJson);
  688. }
  689. String patentInstructionJson = this.parseTempFileData(tempPath, Constants.PATENT_INSTRUCTION_FILE_NAME);
  690. if (StringUtils.isNotEmpty(patentInstructionJson)) {
  691. projectImportStatusService.add(importId, userId, 7);
  692. patentInstructionService.importPatentInstruction(userId, tempPath, patentIdPatentNoJson, patentInstructionJson);
  693. }
  694. } catch (Exception e) {
  695. e.printStackTrace();
  696. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  697. projectImportStatusService.add(importId, userId, 101);
  698. } finally {
  699. FileUtil.del(tempPath);
  700. projectImportStatusService.add(importId, userId, 200);
  701. cacheUtils.deleteUserImport(userId);
  702. }
  703. }
  704. private String parseTempFileData(String path, String fileName) throws IOException {
  705. String src = path + FileUtil.FILE_SEPARATOR + fileName;
  706. if (!FileUtil.exist(src)) {
  707. return null;
  708. }
  709. File file = new File(src);
  710. FileReader fileReader = new FileReader(file);
  711. Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
  712. int ch;
  713. StringBuffer sb = new StringBuffer();
  714. while ((ch = reader.read()) != -1) {
  715. sb.append((char) ch);
  716. }
  717. fileReader.close();
  718. reader.close();
  719. return sb.toString();
  720. }
  721. //主页面 导出列表功能
  722. public void exportProject(HttpServletResponse response) {
  723. try {
  724. ProjectVO params = new ProjectVO();
  725. params.setSize(99999999999L);
  726. params.setCurrent(1L);
  727. params.setMyself(false);
  728. ProjectVO.Sort sort = new ProjectVO.Sort();
  729. sort.setProp("create_time");
  730. sort.setOrder("desc");
  731. params.setSort(sort);
  732. IPage<Project> pageList = this.getPageList(params);
  733. List<Project> projectList = pageList.getRecords();
  734. List<List<String>> row = new ArrayList<>();
  735. row.add(CollUtil.newArrayList("#", "名称", "委托方", "调查类型", "应用场景", "技术主题", "合同号", "委案日", "创建人"));
  736. for (int i = 0; i < projectList.size(); i++) {
  737. Project project = projectList.get(i);
  738. 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()));
  739. }
  740. List<List<String>> rows = CollUtil.newArrayList(row);
  741. ExcelWriter writer = ExcelUtil.getWriter(true);
  742. OutputStream out = response.getOutputStream();
  743. writer.write(rows, true);
  744. response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
  745. response.setHeader("Content-Disposition", "attachment;filename=" + IdUtil.simpleUUID() + ".xlsx");
  746. writer.flush(out, true);
  747. writer.close();
  748. IoUtil.close(out);
  749. } catch (Exception e) {
  750. e.printStackTrace();
  751. }
  752. }
  753. }