|
|
@@ -1,13 +1,18 @@
|
|
|
package com.xunmei.core.edu.service.impl;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.poi.excel.ExcelUtil;
|
|
|
+import cn.hutool.poi.excel.ExcelWriter;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xunmei.common.core.constant.Constants;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.domain.R;
|
|
|
+import com.xunmei.common.core.utils.DateHelper;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
import com.xunmei.common.core.domain.edu.domain.SysLearningMaterials;
|
|
|
@@ -20,13 +25,15 @@ import com.xunmei.system.api.domain.SysOrg;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
/**
|
|
|
* 学习资料Service业务层处理
|
|
|
*
|
|
|
@@ -53,6 +60,9 @@ public class SysLearningMaterialsServiceImpl extends ServiceImpl<SysLearningMate
|
|
|
sysLearningMaterials.setUserId(SecurityUtils.getUserId());
|
|
|
//获取数据
|
|
|
page = sysLearningMaterialsMapper.selectPageData(page, sysLearningMaterials);
|
|
|
+ for (SysLearningMaterialsPageVo record : page.getRecords()) {
|
|
|
+ extractStringFromUrl(record);
|
|
|
+ }
|
|
|
//抓换为TableDataInfo适配前端
|
|
|
TableDataInfo tableDataInfo = new TableDataInfo();
|
|
|
tableDataInfo.setMsg("操作成功");
|
|
|
@@ -68,13 +78,22 @@ public class SysLearningMaterialsServiceImpl extends ServiceImpl<SysLearningMate
|
|
|
if (sysOrg == null || ObjectUtil.isEmpty(sysOrg.getPath())) {
|
|
|
throw new RuntimeException("机构不存在或机构信息缺失!");
|
|
|
}
|
|
|
- String[] split = "4352539158904832-4352539158904833-".split("-");
|
|
|
+ String[] split = sysOrg.getPath().split("-");
|
|
|
List<Long> list = new ArrayList<>();
|
|
|
Stream.of(split).forEach(s -> list.add(Long.valueOf(s)));
|
|
|
list.remove(sysLearningMaterials.getOrgId());
|
|
|
sysLearningMaterials.setOrgIdList(list);
|
|
|
}
|
|
|
|
|
|
+ public void extractStringFromUrl(SysLearningMaterialsPageVo record) {
|
|
|
+ if (ObjectUtil.isEmpty(record.getFile()) || !record.getFile().contains(Constants.HTTP)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 获取最后一个斜杠的索引
|
|
|
+ int lastSlashIndex = record.getFile().lastIndexOf("/");
|
|
|
+ // 获取最后一个斜杠后面的字符串
|
|
|
+ record.setFile(record.getFile().substring(lastSlashIndex + 1));
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 查询学习资料
|
|
|
@@ -166,4 +185,51 @@ public class SysLearningMaterialsServiceImpl extends ServiceImpl<SysLearningMate
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void export(SysLearningMaterialsPageDto sysLearningMaterials, HttpServletResponse response) throws
|
|
|
+ IOException {
|
|
|
+
|
|
|
+ SysOrg sysOrg = null;
|
|
|
+ try {
|
|
|
+ R<SysOrg> sysOrgR = remoteOrgService.selectSysOrgById(sysLearningMaterials.getOrgId(), SecurityConstants.INNER);
|
|
|
+ sysOrg = sysOrgR.getData();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("获取机构信息失败,请确认服务可用!");
|
|
|
+ }
|
|
|
+
|
|
|
+ sysLearningMaterials.setPageSize((long) Integer.MAX_VALUE);
|
|
|
+ final TableDataInfo tableDataInfo = this.selectPage(sysLearningMaterials);
|
|
|
+ if (ObjectUtil.isEmpty(tableDataInfo.getRows())) {
|
|
|
+ throw new RuntimeException("导出数据为空!");
|
|
|
+ }
|
|
|
+ List<SysLearningMaterialsPageVo> list = (List<SysLearningMaterialsPageVo>) tableDataInfo.getRows();
|
|
|
+
|
|
|
+ //在内存操作,写到浏览器
|
|
|
+ ExcelWriter writer = ExcelUtil.getWriter(true);
|
|
|
+ writer.addHeaderAlias("title", "资料标题");
|
|
|
+ writer.addHeaderAlias("knowledgeName", "资料类型");
|
|
|
+ writer.addHeaderAlias("orgName", "所属机构");
|
|
|
+ writer.addHeaderAlias("isOpen", "是否公开");
|
|
|
+ writer.addHeaderAlias("createBy", "上传人");
|
|
|
+ writer.addHeaderAlias("createTime", "上传时间");
|
|
|
+
|
|
|
+ //只保留别名的数据
|
|
|
+ writer.setOnlyAlias(true);
|
|
|
+ // 默认配置
|
|
|
+ writer.write(list, true);
|
|
|
+ // 设置content—type
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset:utf-8");
|
|
|
+ // 设置标题
|
|
|
+ String fileName = URLEncoder.encode("【" + sysOrg.getName() + "】-履职记录" + DateHelper.getDateString(new Date()), "UTF-8");
|
|
|
+ //Content-disposition是MIME协议的扩展,MIME协议指示MIME用户代理如何显示附加的文件。
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream();
|
|
|
+ //将Writer刷新到OutPut
|
|
|
+ writer.flush(outputStream, true);
|
|
|
+ outputStream.close();
|
|
|
+ writer.close();
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|