ProjectService.java 52 KB

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