ProjectService.java 48 KB

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