ProjectService.java 54 KB

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