文档库--导出excel(不带文件)
This commit is contained in:
+2
-19
@@ -377,25 +377,8 @@ public class BussDocumentLibraryEOController extends JeroController<BussDocument
|
|||||||
@GetMapping(value = "/exportExcel")
|
@GetMapping(value = "/exportExcel")
|
||||||
public void exportExcel(@RequestParam Map<String,Object> map,
|
public void exportExcel(@RequestParam Map<String,Object> map,
|
||||||
HttpServletResponse response,
|
HttpServletResponse response,
|
||||||
HttpServletRequest request) throws Exception {
|
HttpServletRequest request){
|
||||||
OutputStream os = null;
|
bussDocumentLibraryEOService.exportExcel(map,response,request);
|
||||||
Workbook workbook = null;
|
|
||||||
try {
|
|
||||||
String fileName = "11111";
|
|
||||||
response.setHeader("Content-Disposition",
|
|
||||||
"attachment; filename=" + fileName);
|
|
||||||
response.setContentType("application/force-download");
|
|
||||||
// 导出所有数据
|
|
||||||
List<Map<String,Object>> datas = new ArrayList<>();
|
|
||||||
workbook = bussDocumentLibraryEOService.exportDatas(datas);
|
|
||||||
os = response.getOutputStream();
|
|
||||||
workbook.write(os);
|
|
||||||
os.flush();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new JeroBootException("下载文件失败,请重试");
|
|
||||||
} finally {
|
|
||||||
IOUtils.closeQuietly(os);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "带文件导出")
|
@ApiOperation(value = "带文件导出")
|
||||||
|
|||||||
+17
-1
@@ -2,10 +2,12 @@ package com.jero.modules.document.mapper;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.jero.modules.document.entity.BussDocumentLibraryEO;
|
import com.jero.modules.document.entity.BussDocumentLibraryEO;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 文档库信息表
|
* @Description: 文档库信息表
|
||||||
* @Author: jero-boot
|
* @Author: jero-boot
|
||||||
@@ -19,6 +21,7 @@ public interface BussDocumentLibraryEOMapper extends BaseMapper<BussDocumentLibr
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询
|
* 分页查询
|
||||||
|
*
|
||||||
* @param page
|
* @param page
|
||||||
* @param field
|
* @param field
|
||||||
* @param condition
|
* @param condition
|
||||||
@@ -28,8 +31,21 @@ public interface BussDocumentLibraryEOMapper extends BaseMapper<BussDocumentLibr
|
|||||||
@Param("field") String field,
|
@Param("field") String field,
|
||||||
@Param("condition") String condition);
|
@Param("condition") String condition);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表查询
|
||||||
|
*
|
||||||
|
* @param
|
||||||
|
* @param field
|
||||||
|
* @param condition
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<Map<String, Object>> getInfoList(@Param("field") String field,
|
||||||
|
@Param("condition") String condition);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代替标准分页
|
* 代替标准分页
|
||||||
|
*
|
||||||
* @param page
|
* @param page
|
||||||
* @param field
|
* @param field
|
||||||
* @param condition
|
* @param condition
|
||||||
|
|||||||
+6
-1
@@ -32,7 +32,6 @@
|
|||||||
<result column="exposure_draft" property="exposureDraft" />
|
<result column="exposure_draft" property="exposureDraft" />
|
||||||
<result column="datum" property="datum" />
|
<result column="datum" property="datum" />
|
||||||
<result column="warn_flag" property="warnFlag" />
|
<result column="warn_flag" property="warnFlag" />
|
||||||
<result column="read_flag" property="readFlag" />
|
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<insert id="insertInfo">
|
<insert id="insertInfo">
|
||||||
@@ -40,10 +39,16 @@
|
|||||||
values (${insertValue})
|
values (${insertValue})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
<!--分页-->
|
||||||
<select id="getInfoPage" resultType="java.util.LinkedHashMap">
|
<select id="getInfoPage" resultType="java.util.LinkedHashMap">
|
||||||
select ${field} from buss_document_library
|
select ${field} from buss_document_library
|
||||||
${condition}
|
${condition}
|
||||||
</select>
|
</select>
|
||||||
|
<!--列表-->
|
||||||
|
<select id="getInfoList" resultType="java.util.LinkedHashMap">
|
||||||
|
select ${field} from buss_document_library
|
||||||
|
${condition}
|
||||||
|
</select>
|
||||||
<!--代替标准分页-->
|
<!--代替标准分页-->
|
||||||
<select id="replacePageInfo" resultType="java.util.LinkedHashMap">
|
<select id="replacePageInfo" resultType="java.util.LinkedHashMap">
|
||||||
select ${field} from buss_document_library
|
select ${field} from buss_document_library
|
||||||
|
|||||||
+10
-1
@@ -134,7 +134,16 @@ public interface IBussDocumentLibraryEOService extends IService<BussDocumentLibr
|
|||||||
*/
|
*/
|
||||||
void cancelSubscribe(String id);
|
void cancelSubscribe(String id);
|
||||||
|
|
||||||
Workbook exportDatas(List<Map<String,Object>> datas);
|
|
||||||
|
/**
|
||||||
|
* 导出excel
|
||||||
|
* @param map
|
||||||
|
* @param response
|
||||||
|
* @param request
|
||||||
|
*/
|
||||||
|
void exportExcel(Map<String,Object> map,
|
||||||
|
HttpServletResponse response,
|
||||||
|
HttpServletRequest request);
|
||||||
|
|
||||||
void exportZip(Map<String,Object> map,
|
void exportZip(Map<String,Object> map,
|
||||||
HttpServletResponse response,
|
HttpServletResponse response,
|
||||||
|
|||||||
+244
-91
@@ -1,6 +1,5 @@
|
|||||||
package com.jero.modules.document.service.impl;
|
package com.jero.modules.document.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.ZipUtil;
|
|
||||||
import com.aliyuncs.utils.IOUtils;
|
import com.aliyuncs.utils.IOUtils;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
@@ -33,16 +32,19 @@ import org.apache.commons.lang3.ObjectUtils;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
|
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -50,8 +52,6 @@ import org.springframework.stereotype.Service;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
@@ -67,8 +67,6 @@ import java.util.Map;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cn.hutool.core.io.FileUtil.copyFile;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 文档库信息表
|
* @Description: 文档库信息表
|
||||||
* @Author: jero-boot
|
* @Author: jero-boot
|
||||||
@@ -574,6 +572,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新log
|
* 更新log
|
||||||
|
*
|
||||||
* @param map
|
* @param map
|
||||||
*/
|
*/
|
||||||
private void updateLog(Map<String, Object> map,
|
private void updateLog(Map<String, Object> map,
|
||||||
@@ -710,6 +709,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理修改代替标准,发送通知
|
* 处理修改代替标准,发送通知
|
||||||
|
*
|
||||||
* @param map
|
* @param map
|
||||||
*/
|
*/
|
||||||
private void sendMessage(Map<String, Object> map, List<Map<String, Object>> dataList) {
|
private void sendMessage(Map<String, Object> map, List<Map<String, Object>> dataList) {
|
||||||
@@ -745,6 +745,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 代替标准分页
|
* 代替标准分页
|
||||||
|
*
|
||||||
* @param parameter
|
* @param parameter
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -806,7 +807,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
List<String> fieldListTemp = fieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
|
List<String> fieldListTemp = fieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
|
||||||
List<String> fieldListNew = new ArrayList<>();
|
List<String> fieldListNew = new ArrayList<>();
|
||||||
fieldListNew.add("id");
|
fieldListNew.add("id");
|
||||||
//转时间格式 case when region is null then "" else region end region
|
//转时间格式
|
||||||
for (String field : fieldListTemp) {
|
for (String field : fieldListTemp) {
|
||||||
String fieldTemp = null;
|
String fieldTemp = null;
|
||||||
if ("issue_time".equals(field) || "implement_time".equals(field)) {
|
if ("issue_time".equals(field) || "implement_time".equals(field)) {
|
||||||
@@ -818,6 +819,38 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
fieldListNew.add(fieldTemp);
|
fieldListNew.add(fieldTemp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//封装查询条件
|
||||||
|
String condition = getConditionStr(parameter);
|
||||||
|
int pageNo = Integer.parseInt(parameter.get("pageNo").toString());
|
||||||
|
int pageSize = Integer.parseInt(parameter.get("pageSize").toString());
|
||||||
|
IPage page = new Page(pageNo, pageSize);
|
||||||
|
|
||||||
|
IPage infoPage = bussDocumentLibraryEOMapper.getInfoPage(page, " " + StringUtils.join(fieldListNew, ","), condition);
|
||||||
|
|
||||||
|
//数据字典
|
||||||
|
List<SysDictItem> sysDictItems = sysDictItemServiceImpl.selectItemsAll();
|
||||||
|
//下拉选处理数据字典
|
||||||
|
List<Map> records = infoPage.getRecords();
|
||||||
|
List<String> idList = new ArrayList<>();
|
||||||
|
for (Map record : records) {
|
||||||
|
Map<String, Object> record1 = (Map) record;
|
||||||
|
idList.add((String) record1.get("id"));
|
||||||
|
for (Map.Entry<String, Object> entry : record1.entrySet()) {
|
||||||
|
List<OnlCgformField> collect = fieldList.stream()
|
||||||
|
.filter(e -> entry.getKey().equals(e.getDictField()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
//下拉选处理数据字典
|
||||||
|
dictItem(sysDictItems, entry, collect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//收藏和订阅
|
||||||
|
collectAndSubscribe(records, idList);
|
||||||
|
return infoPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String getConditionStr(Map<String, Object> parameter) {
|
||||||
//查询条件
|
//查询条件
|
||||||
StringBuilder conditionSb = new StringBuilder("where 1 = 1");
|
StringBuilder conditionSb = new StringBuilder("where 1 = 1");
|
||||||
|
|
||||||
@@ -834,7 +867,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
if (key.equals(fieldName)) {
|
if (key.equals(fieldName)) {
|
||||||
//字段类型(判断是输入框还是下拉,等等)
|
//字段类型(判断是输入框还是下拉,等等)
|
||||||
String fieldType = (String) map.get("field_show_type");//字段类型
|
String fieldType = (String) map.get("field_show_type");//字段类型
|
||||||
if (FieldTypeEnum.TEXT.getValue().equals(fieldType)) {
|
if (FieldTypeEnum.TEXT_STRING.getValue().equals(fieldType)) {
|
||||||
//输入框
|
//输入框
|
||||||
conditionSb.append(" and " + key + " like concat(concat('%','" + value + "'),'%')");
|
conditionSb.append(" and " + key + " like concat(concat('%','" + value + "'),'%')");
|
||||||
} else if (FieldTypeEnum.PULL_SINGLE.getValue().equals(fieldType)
|
} else if (FieldTypeEnum.PULL_SINGLE.getValue().equals(fieldType)
|
||||||
@@ -871,36 +904,14 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
} else {
|
} else {
|
||||||
conditionSb.append(" order by create_time desc");
|
conditionSb.append(" order by create_time desc");
|
||||||
}
|
}
|
||||||
int pageNo = Integer.parseInt(parameter.get("pageNo").toString());
|
String condition = conditionSb.toString();
|
||||||
int pageSize = Integer.parseInt(parameter.get("pageSize").toString());
|
return condition;
|
||||||
IPage page = new Page(pageNo, pageSize);
|
|
||||||
|
|
||||||
IPage infoPage = bussDocumentLibraryEOMapper.getInfoPage(page, " " + StringUtils.join(fieldListNew, ","), conditionSb.toString());
|
|
||||||
|
|
||||||
//数据字典
|
|
||||||
List<SysDictItem> sysDictItems = sysDictItemServiceImpl.selectItemsAll();
|
|
||||||
//下拉选处理数据字典
|
|
||||||
List<Map> records = infoPage.getRecords();
|
|
||||||
List<String> idList = new ArrayList<>();
|
|
||||||
for (Map record : records) {
|
|
||||||
Map<String, Object> record1 = (Map) record;
|
|
||||||
idList.add((String) record1.get("id"));
|
|
||||||
for (Map.Entry<String, Object> entry : record1.entrySet()) {
|
|
||||||
List<OnlCgformField> collect = fieldList.stream()
|
|
||||||
.filter(e -> entry.getKey().equals(e.getDictField()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
//下拉选处理数据字典
|
|
||||||
dictItem(sysDictItems, entry, collect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//收藏和订阅
|
|
||||||
collectAndSubscribe(records, idList);
|
|
||||||
return infoPage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 收藏和订阅
|
* 收藏和订阅
|
||||||
|
*
|
||||||
* @param records
|
* @param records
|
||||||
* @param idList
|
* @param idList
|
||||||
*/
|
*/
|
||||||
@@ -970,7 +981,6 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCollect(String id) {
|
public void addCollect(String id) {
|
||||||
//收藏表中添加数据
|
//收藏表中添加数据
|
||||||
@@ -1013,9 +1023,9 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断两个集合元素是否完全一致
|
* 判断两个集合元素是否完全一致
|
||||||
|
*
|
||||||
* @param list
|
* @param list
|
||||||
* @param list1
|
* @param list1
|
||||||
* @return
|
* @return
|
||||||
@@ -1047,17 +1057,158 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出excel
|
* 导出excel
|
||||||
* @param datas
|
*
|
||||||
|
* @param map
|
||||||
|
* @param response
|
||||||
|
* @param request
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Workbook exportDatas(List<Map<String, Object>> datas) {
|
public void exportExcel(Map<String, Object> map, HttpServletResponse response, HttpServletRequest request) {
|
||||||
|
OutputStream os = null;
|
||||||
Workbook workbook = new XSSFWorkbook();
|
Workbook workbook = new XSSFWorkbook();
|
||||||
return workbook;
|
try {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String fileName = "文件库 " + sdf.format(new Date()) + ".xlsx";
|
||||||
|
response.setHeader("Content-Disposition",
|
||||||
|
"attachment; filename=" + fileName);
|
||||||
|
response.setContentType("application/force-download");
|
||||||
|
//需要查询的字段
|
||||||
|
List<OnlCgformField> fieldList = onlCgformFieldService.getFieldList("1");
|
||||||
|
//表头
|
||||||
|
List<String> headerFieldList = new ArrayList<>();
|
||||||
|
List<OnlCgformField> fieldListTemp = new ArrayList<>();
|
||||||
|
if (fieldList.size() != 0) {
|
||||||
|
//过滤掉系统默认的字段
|
||||||
|
fieldListTemp = fieldList.stream().filter(e -> !"id".equals(e.getDbFieldName())
|
||||||
|
&& !"create_by".equals(e.getDbFieldName())
|
||||||
|
&& !"create_time".equals(e.getDbFieldName())
|
||||||
|
&& !"update_by".equals(e.getDbFieldName())
|
||||||
|
&& !"update_time".equals(e.getDbFieldName())
|
||||||
|
&& !"sys_org_code".equals(e.getDbFieldName())
|
||||||
|
&& !"warn_flag".equals(e.getDbFieldName())).collect(Collectors.toList());
|
||||||
|
//只导出数据时,过滤掉文件类型
|
||||||
|
fieldListTemp = fieldListTemp.stream().filter(e -> !FieldTypeEnum.FILE.getValue().equals(e.getFieldShowType())).collect(Collectors.toList());
|
||||||
|
headerFieldList = fieldListTemp.stream().map(OnlCgformField::getDbFieldTxt).collect(Collectors.toList());
|
||||||
|
|
||||||
|
}
|
||||||
|
//查询字段
|
||||||
|
List<String> conditionFieldList = fieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
|
||||||
|
//查询条件
|
||||||
|
String condition = getConditionStr(map);
|
||||||
|
//导出数据(全部导出的数据)
|
||||||
|
List<Map<String, Object>> datas = bussDocumentLibraryEOMapper.getInfoList(" " + StringUtils.join(conditionFieldList, ","), condition);
|
||||||
|
//部分导出
|
||||||
|
String partId = (String) map.get("id");
|
||||||
|
if (StringUtils.isNotBlank(partId)) {
|
||||||
|
//部门导出的数据
|
||||||
|
datas = datas.stream().filter(entry -> partId.contains((String) entry.get("id"))).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
//创建工作表对象
|
||||||
|
Sheet sheet = workbook.createSheet();
|
||||||
|
// 创建头部
|
||||||
|
String header = StringUtils.join(headerFieldList, ",");
|
||||||
|
createHeader(workbook, sheet, header);
|
||||||
|
// 创建数据
|
||||||
|
createDatas(workbook, sheet, datas, header, fieldListTemp);
|
||||||
|
|
||||||
|
os = response.getOutputStream();
|
||||||
|
workbook.write(os);
|
||||||
|
os.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new JeroBootException("下载文件失败,请重试");
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createDatas(Workbook workbook, Sheet sheet, List<Map<String, Object>> datas, String header, List<OnlCgformField> fieldList) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
CellStyle cellStyle = workbook.createCellStyle();//初始化单元格格式对象
|
||||||
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
|
//数据字典
|
||||||
|
List<SysDictItem> sysDictItems = sysDictItemServiceImpl.selectItemsAll();
|
||||||
|
//过滤出下拉单选和下拉多选的字段
|
||||||
|
List<OnlCgformField> onlCgformFieldList = fieldList.stream()
|
||||||
|
.filter(e -> FieldTypeEnum.PULL_SINGLE.getValue().equals(e.getFieldShowType())
|
||||||
|
|| FieldTypeEnum.PULL_MORE.getValue().equals(e.getFieldShowType())).collect(Collectors.toList());
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (Map<String, Object> data : datas) {
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
||||||
|
List<OnlCgformField> collect = fieldList.stream()
|
||||||
|
.filter(e -> entry.getKey().equals(e.getDictField()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
//下拉选处理数据字典
|
||||||
|
dictItem(sysDictItems, entry, collect);
|
||||||
|
}
|
||||||
|
Row row = sheet.createRow(i + 1);
|
||||||
|
i++;
|
||||||
|
int sheetNum = 0;
|
||||||
|
String value = "";
|
||||||
|
for (OnlCgformField onlCgformField : fieldList) {
|
||||||
|
//时间类型
|
||||||
|
if (FieldTypeEnum.DATE_SINGLE.getValue().equals(onlCgformField.getFieldShowType())) {
|
||||||
|
if (ObjectUtils.isNotEmpty(data.get(onlCgformField.getDbFieldName()))) {
|
||||||
|
value = sdf.format(data.get(onlCgformField.getDbFieldName()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
value = (String) data.get(onlCgformField.getDbFieldName());
|
||||||
|
}
|
||||||
|
row.createCell(sheetNum).setCellValue(value);
|
||||||
|
sheetNum++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int a = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建表头
|
||||||
|
*
|
||||||
|
* @param workbook
|
||||||
|
* @param sheet
|
||||||
|
* @param header
|
||||||
|
*/
|
||||||
|
public static void createHeader(Workbook workbook, Sheet sheet, String header) {
|
||||||
|
CellStyle cellStyle = workbook.createCellStyle();//初始化单元格格式对象
|
||||||
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
|
Row rowHeader = sheet.createRow(0);//开始创建标题行
|
||||||
|
if (StringUtils.isNotBlank(header)) {
|
||||||
|
String[] headerArr = header.split(",");
|
||||||
|
for (int i = 0; i < headerArr.length; i++) {
|
||||||
|
rowHeader.createCell(i).setCellValue(headerArr[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取导出的数据
|
||||||
|
*
|
||||||
|
* @param map
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<Map<String, Object>> getExportDatas(Map<String, Object> map) {
|
||||||
|
//需要查询的字段
|
||||||
|
List<OnlCgformField> fieldList = onlCgformFieldService.getFieldList("1");
|
||||||
|
if (fieldList.size() != 0) {
|
||||||
|
//过滤列表字段(is_show_list-->列表是否显示0否 1是)
|
||||||
|
fieldList = fieldList.stream().filter(e -> YesOrNoEnum.YES.getValue().equals(String.valueOf(e.getIsShowList()))).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
List<String> fieldListTemp = fieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
|
||||||
|
List<String> fieldListNew = new ArrayList<>();
|
||||||
|
fieldListNew.add("id");
|
||||||
|
fieldListNew.addAll(fieldListTemp);
|
||||||
|
//查询条件
|
||||||
|
String condition = getConditionStr(map);
|
||||||
|
List<Map<String, Object>> infoList = bussDocumentLibraryEOMapper.getInfoList(" " + StringUtils.join(fieldListNew, ","), condition);
|
||||||
|
return infoList;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 带文件导出
|
* 带文件导出
|
||||||
|
*
|
||||||
* @param datas
|
* @param datas
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -1065,65 +1216,66 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
public void exportZip(Map<String, Object> map,
|
public void exportZip(Map<String, Object> map,
|
||||||
HttpServletResponse response,
|
HttpServletResponse response,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
try {
|
// try {
|
||||||
String fileName = "带文件导出.zip";
|
// String fileName = "带文件导出.zip";
|
||||||
response.setHeader("Content-Disposition",
|
// response.setHeader("Content-Disposition",
|
||||||
"attachment; filename=" + fileName);
|
// "attachment; filename=" + fileName);
|
||||||
response.setContentType("application/force-download");
|
// response.setContentType("application/force-download");
|
||||||
// 导出所有数据
|
// // 导出所有数据
|
||||||
List<Map<String,Object> > datas = new ArrayList<>();
|
// List<Map<String,Object> > datas = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// List<String> pdfFileIdList = new ArrayList<>();
|
||||||
|
// //从查询的数据中,过滤出文件(根据字段类型)
|
||||||
|
//
|
||||||
|
// //文件信息
|
||||||
|
// List<OSSFile> oSSFileList = iOSSFileService.getFileInfosByConnectId(StringUtils.join(pdfFileIdList,","));
|
||||||
|
//
|
||||||
|
// //创建临时文件夹
|
||||||
|
// String uuid = "";
|
||||||
|
// String fileNowPath = "path" + "带文件导出";
|
||||||
|
// File nowFile = new File(fileNowPath);
|
||||||
|
// if (nowFile.exists()){
|
||||||
|
// nowFile.delete();
|
||||||
|
// }
|
||||||
|
// nowFile.mkdirs();
|
||||||
|
|
||||||
List<String> pdfFileIdList = new ArrayList<>();
|
// try(Workbook workbook = exportDatas(datas);
|
||||||
//从查询的数据中,过滤出文件(根据字段类型)
|
// OutputStream excelOS = new FileOutputStream(fileNowPath + File.separator + "军品数据.xls");
|
||||||
|
// OutputStream os = response.getOutputStream();
|
||||||
//文件信息
|
// ) {
|
||||||
List<OSSFile> oSSFileList = iOSSFileService.getFileInfosByConnectId(StringUtils.join(pdfFileIdList,","));
|
// for (OSSFile oSSFile : oSSFileList) {
|
||||||
|
// //文件路径
|
||||||
//创建临时文件夹
|
// String path = oSSFile.getUrl();
|
||||||
String uuid = "";
|
// copyFile(path,fileNowPath+File.separator);
|
||||||
String fileNowPath = "path" + "带文件导出";
|
// }
|
||||||
File nowFile = new File(fileNowPath);
|
//
|
||||||
if (nowFile.exists()){
|
// workbook.write(excelOS);
|
||||||
nowFile.delete();
|
// excelOS.flush();
|
||||||
}
|
//
|
||||||
nowFile.mkdirs();
|
// ZipUtil.zip(fileNowPath,fileNowPath+".zip");
|
||||||
|
// FileInputStream fis = new FileInputStream(fileNowPath+".zip");
|
||||||
try(Workbook workbook = exportDatas(datas);
|
// int len = 0;
|
||||||
OutputStream excelOS = new FileOutputStream(fileNowPath + File.separator + "军品数据.xls");
|
// while ((len = fis.read()) != -1) {
|
||||||
OutputStream os = response.getOutputStream();
|
// os.write(len);
|
||||||
) {
|
// }
|
||||||
for (OSSFile oSSFile : oSSFileList) {
|
// os.flush();
|
||||||
//文件路径
|
// fis.close();
|
||||||
String path = oSSFile.getUrl();
|
// } catch (IOException e) {
|
||||||
copyFile(path,fileNowPath+File.separator);
|
// throw new JeroBootException("下载文件失败,请重试");
|
||||||
}
|
// }finally {
|
||||||
|
//// File file = new File(uploadFilePath + "/tempZip/" + uuid);
|
||||||
workbook.write(excelOS);
|
//// FileUnZip.deleteDir(file);
|
||||||
excelOS.flush();
|
//
|
||||||
|
// }
|
||||||
ZipUtil.zip(fileNowPath,fileNowPath+".zip");
|
// } catch (Exception e) {
|
||||||
FileInputStream fis = new FileInputStream(fileNowPath+".zip");
|
// throw new JeroBootException("下载文件失败,请重试");
|
||||||
int len = 0;
|
// }
|
||||||
while ((len = fis.read()) != -1) {
|
|
||||||
os.write(len);
|
|
||||||
}
|
|
||||||
os.flush();
|
|
||||||
fis.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new JeroBootException("下载文件失败,请重试");
|
|
||||||
}finally {
|
|
||||||
// File file = new File(uploadFilePath + "/tempZip/" + uuid);
|
|
||||||
// FileUnZip.deleteDir(file);
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new JeroBootException("下载文件失败,请重试");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模板下载
|
* 模板下载
|
||||||
|
*
|
||||||
* @param response
|
* @param response
|
||||||
* @param request
|
* @param request
|
||||||
*/
|
*/
|
||||||
@@ -1190,6 +1342,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取模板下载的表头
|
* 获取模板下载的表头
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private List<String> getWorkbookTitle(String cut) {
|
private List<String> getWorkbookTitle(String cut) {
|
||||||
|
|||||||
Reference in New Issue
Block a user