ProjectService.java 55 KB

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