ProjectService.java 48 KB

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