流程 的 模板下载 和 excel 282 行 姓名支持拼音查询的bug修复
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
package com.adc.da.slrs.processModel.entity;
|
||||||
|
|
||||||
|
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class exportExcel {
|
||||||
|
|
||||||
|
@Excel(name = "企标类别" ,orderNum = "0" , width = 20.0 )
|
||||||
|
private String bussSort;
|
||||||
|
|
||||||
|
@Excel(name = "企标名称",orderNum = "1", width = 20.0)
|
||||||
|
private String esName;
|
||||||
|
|
||||||
|
@Excel(name = "制修订类型",orderNum = "2", width = 20.0)
|
||||||
|
private String reviseStatus;
|
||||||
|
|
||||||
|
@Excel(name = "起草责任单位" , orderNum = "3", width = 20.0)
|
||||||
|
private String unitName;
|
||||||
|
|
||||||
|
@Excel(name = "起草人" , orderNum = "4", width = 20.0)
|
||||||
|
private String drafterName;
|
||||||
|
|
||||||
|
@Excel(name = "评审责任人" , orderNum = "5", width = 20.0)
|
||||||
|
private String resPersonName;
|
||||||
|
|
||||||
|
@Excel(name = "工作组组长" , orderNum = "6", width = 20.0)
|
||||||
|
private String wgLeaderName;
|
||||||
|
|
||||||
|
@Excel(name = "计划初稿完成日期" , orderNum = "7", width = 20.0)
|
||||||
|
private String draftTime;
|
||||||
|
|
||||||
|
@Excel(name = "计划标准发布时间", orderNum = "8", width = 18.0)
|
||||||
|
private String releaseTime;
|
||||||
|
|
||||||
|
@Excel(name = "立项完成时间" ,orderNum = "9", width = 18.0)
|
||||||
|
private String endTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.adc.da.slrs.processModel;
|
||||||
|
|
||||||
|
import com.adc.da.excel.poi.excel.entity.ExportParams;
|
||||||
|
import com.adc.da.excel.poi.excel.entity.enums.ExcelType;
|
||||||
|
import com.adc.da.slrs.msgDynamicInfo.common.ReadExcel;
|
||||||
|
import com.adc.da.slrs.processModel.entity.exportExcel;
|
||||||
|
import com.adc.da.slrs.processModel.utils.ExcelExportUtilByWk;
|
||||||
|
import com.adc.da.sys.service.IDicTypeEOService;
|
||||||
|
import com.adc.da.util.exception.AdcDaBaseException;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
import org.apache.poi.util.IOUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Api(description = "|SapMeeting|")
|
||||||
|
@RequestMapping("/api/exportWkExcel")
|
||||||
|
public class exportWkExcel {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IDicTypeEOService dicTypeEOService;
|
||||||
|
|
||||||
|
@ApiOperation(value = "|SysCorpEO|导出excel")
|
||||||
|
@GetMapping(value = "/exportqbzxdjh")
|
||||||
|
public void exportMsgDynamicInfoExcel( HttpServletResponse response, HttpServletRequest request) {
|
||||||
|
OutputStream os = null;
|
||||||
|
HSSFWorkbook workbook = null;
|
||||||
|
try {
|
||||||
|
String exportName="企标制修订计划模板";
|
||||||
|
response.setHeader("Content-Disposition",
|
||||||
|
"attachment; filename=" + ReadExcel.encodeFileName(exportName+".xlsx", request));
|
||||||
|
response.setContentType("application/force-download");
|
||||||
|
ExportParams exportParams = new ExportParams();
|
||||||
|
exportParams.setType(ExcelType.XSSF);
|
||||||
|
exportParams.setSheetName(exportName);
|
||||||
|
|
||||||
|
Map<String, Object> dicTypeEO = dicTypeEOService.getDicTypeListCode();
|
||||||
|
workbook = ExcelExportUtilByWk.getHSSFWorkbook(exportParams, exportExcel.class,workbook,"1",dicTypeEO);
|
||||||
|
os = response.getOutputStream();
|
||||||
|
workbook.write(os);
|
||||||
|
os.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new AdcDaBaseException("下载文件失败,请重试");
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(os);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
package com.adc.da.slrs.processModel.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 判断是否为日期格式
|
||||||
|
* @Author: yangxuenan
|
||||||
|
* date: 2020/12/31 11:25
|
||||||
|
*/
|
||||||
|
public class DateUtil {
|
||||||
|
|
||||||
|
private static List<String> dateFormatStr = new ArrayList<>();
|
||||||
|
private static List<String> dateRegExStr = new ArrayList<>();
|
||||||
|
|
||||||
|
static{
|
||||||
|
dateFormatStr.add("yyyy-MM-dd");
|
||||||
|
dateFormatStr.add("yyyy-M-d");
|
||||||
|
dateFormatStr.add("yyyy-MM-d");
|
||||||
|
dateFormatStr.add("yyyy-M-dd");
|
||||||
|
dateFormatStr.add("yyyy/M/d");
|
||||||
|
dateFormatStr.add("yyyy/MM/d");
|
||||||
|
dateFormatStr.add("yyyy/M/dd");
|
||||||
|
dateFormatStr.add("yyyy/MM/dd");
|
||||||
|
dateRegExStr.add("^\\d{4}-\\d{2}-\\d{2}$");
|
||||||
|
dateRegExStr.add("^\\d{4}-\\d{1}-\\d{1}$");
|
||||||
|
dateRegExStr.add("^\\d{4}-\\d{2}-\\d{1}$");
|
||||||
|
dateRegExStr.add("^\\d{4}-\\d{1}-\\d{2}$");
|
||||||
|
dateRegExStr.add("^\\d{4}(\\/)\\d{1}(\\/)\\d{1}$");
|
||||||
|
dateRegExStr.add("^\\d{4}(\\/)\\d{2}(\\/)\\d{1}$");
|
||||||
|
dateRegExStr.add("^\\d{4}(\\/)\\d{1}(\\/)\\d{2}$");
|
||||||
|
dateRegExStr.add("^\\d{4}(\\/)\\d{2}(\\/)\\d{2}$");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @Description: 判断多个日期是否都符合日期格式
|
||||||
|
* @Author: yangxuenan
|
||||||
|
* @Date: 2020/12/31 11:31
|
||||||
|
* @Param: [str]
|
||||||
|
* @Return: boolean
|
||||||
|
*/
|
||||||
|
public static boolean isValidDate(String str) throws Exception{
|
||||||
|
//时间多了空格也可进行导入,所以当存在 “2021-01-01 2021-01-02” 的情况时,通过使用去除空格的方式进行验重
|
||||||
|
str = str.trim().replace(" ","");
|
||||||
|
String regEx="^[0-9/,-]+$";
|
||||||
|
Pattern p = Pattern.compile(regEx);
|
||||||
|
Matcher m = p.matcher(str);
|
||||||
|
if (!m.matches()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] strArr = str.split(",");
|
||||||
|
for (String dateStr : strArr) {
|
||||||
|
boolean checkResult = true;
|
||||||
|
for(int checkIndex=0;checkIndex<dateRegExStr.size();checkIndex++){
|
||||||
|
String regExStr = dateRegExStr.get(checkIndex);
|
||||||
|
String dateFormateStr = dateFormatStr.get(checkIndex);
|
||||||
|
Pattern patternCheck = Pattern.compile(regExStr);
|
||||||
|
Matcher matcherResult = patternCheck.matcher(dateStr);
|
||||||
|
if(matcherResult.matches()){
|
||||||
|
try{
|
||||||
|
SimpleDateFormat checkFormat = new SimpleDateFormat(dateFormateStr);
|
||||||
|
checkFormat.setLenient(false);
|
||||||
|
checkFormat.parse(dateStr);
|
||||||
|
checkResult = true;
|
||||||
|
}catch (Exception e){
|
||||||
|
checkResult=false;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
checkResult =false;
|
||||||
|
}
|
||||||
|
if(checkResult){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!checkResult){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将符合校验规则的时间字符串转换为标准的时间字符串
|
||||||
|
* @param str
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String formateConvertDate(String str){
|
||||||
|
str = str.trim().replace(" ","");
|
||||||
|
String[] strArr = str.split(",");
|
||||||
|
String resultDateStr = str;
|
||||||
|
List<String> resultDateList = new ArrayList<>();
|
||||||
|
SimpleDateFormat defaultDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
for (String dateStr : strArr) {
|
||||||
|
for(int checkIndex=0;checkIndex<dateFormatStr.size();checkIndex++){
|
||||||
|
String dateFormateStr = dateFormatStr.get(checkIndex);
|
||||||
|
try {
|
||||||
|
SimpleDateFormat checkFormat = new SimpleDateFormat(dateFormateStr);
|
||||||
|
checkFormat.setLenient(false);
|
||||||
|
Date newDate = checkFormat.parse(dateStr);
|
||||||
|
String result = defaultDateFormat.format(newDate);
|
||||||
|
resultDateList.add(result);
|
||||||
|
break;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!resultDateList.isEmpty()){
|
||||||
|
resultDateStr = StringUtils.join(resultDateList, ",");
|
||||||
|
}
|
||||||
|
return resultDateStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将符合时间格式的字符串(单时间) 转换为Date类型
|
||||||
|
* @param str
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Date formateStrConvertToDate(String str){
|
||||||
|
Date result = null;
|
||||||
|
str = str.trim().replace(" ","");
|
||||||
|
for(int checkIndex=0;checkIndex<dateFormatStr.size();checkIndex++){
|
||||||
|
String dateFormateStr = dateFormatStr.get(checkIndex);
|
||||||
|
try {
|
||||||
|
SimpleDateFormat checkFormat = new SimpleDateFormat(dateFormateStr);
|
||||||
|
checkFormat.setLenient(false);
|
||||||
|
result = checkFormat.parse(str);
|
||||||
|
break;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* utc 时间格式转换正常格式 2018-08-07T03:41:59Z
|
||||||
|
* @param utcTime 时间
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String formatStrUTCToDateStr(String utcTime) {
|
||||||
|
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.SIMPLIFIED_CHINESE);
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
TimeZone utcZone = TimeZone.getTimeZone("UTC");
|
||||||
|
sf.setTimeZone(utcZone);
|
||||||
|
Date date = null;
|
||||||
|
String dateTime = "";
|
||||||
|
try {
|
||||||
|
date = sf.parse(utcTime);
|
||||||
|
dateTime = sdf.format(date);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return dateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+171
@@ -0,0 +1,171 @@
|
|||||||
|
package com.adc.da.slrs.processModel.utils;
|
||||||
|
|
||||||
|
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||||
|
import com.adc.da.excel.poi.excel.entity.ExportParams;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.poi.hssf.usermodel.*;
|
||||||
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||||
|
import org.apache.poi.ss.usermodel.Name;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ExcelExportUtilByWk {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private ExcelExportUtilByWk() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HSSFWorkbook getHSSFWorkbook(ExportParams sheetName, Class<?> tClass , HSSFWorkbook wb,String flag, Map<String, Object> dicTypeEO){
|
||||||
|
|
||||||
|
// 第一步,创建一个HSSFWorkbook,对应一个Excel文件
|
||||||
|
if(wb == null){
|
||||||
|
wb = new HSSFWorkbook();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 第二步,在workbook中添加一个sheet,对应Excel文件中的sheet
|
||||||
|
HSSFSheet sheet = wb.createSheet(sheetName.getSheetName());
|
||||||
|
|
||||||
|
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
|
||||||
|
HSSFRow row = sheet.createRow(0);
|
||||||
|
|
||||||
|
// 第四步,创建单元格,并设置值表头 设置表头居中
|
||||||
|
HSSFCellStyle style = wb.createCellStyle();
|
||||||
|
style.setAlignment(HorizontalAlignment.CENTER);
|
||||||
|
|
||||||
|
//声明列对象
|
||||||
|
HSSFCell cell = null;
|
||||||
|
Map<Integer,Excel> map=new HashMap<>();
|
||||||
|
Field[] fields=tClass.getDeclaredFields();
|
||||||
|
for (Field field:fields) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
Excel excel=field.getAnnotation(Excel.class);
|
||||||
|
map.put(Integer.valueOf(excel.orderNum()),excel);
|
||||||
|
}
|
||||||
|
//创建标题
|
||||||
|
HSSFDataFormat df= wb.createDataFormat();
|
||||||
|
for (Integer i:map.keySet()) {
|
||||||
|
sheet.setColumnWidth(i, (int) (map.get(i).width()*256));
|
||||||
|
cell = row.createCell(i);
|
||||||
|
cell.setCellValue(map.get(i).name());
|
||||||
|
if (i>6){
|
||||||
|
HSSFCellStyle style1 = wb.createCellStyle();
|
||||||
|
style1.setAlignment(HorizontalAlignment.CENTER); // 创建一个居中格式
|
||||||
|
style1.setDataFormat(df.getFormat("yyyy-MM-dd"));
|
||||||
|
sheet.setDefaultColumnStyle(i,style1);
|
||||||
|
}
|
||||||
|
cell.setCellStyle(style);
|
||||||
|
|
||||||
|
}
|
||||||
|
if ("1".equals(flag)){
|
||||||
|
//冻结首行
|
||||||
|
sheet.createFreezePane( 0, 1, 0, 1 );
|
||||||
|
wb=putValue(sheet,wb,dicTypeEO);
|
||||||
|
}
|
||||||
|
|
||||||
|
return wb;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static HSSFWorkbook putValue(HSSFSheet sheet, HSSFWorkbook wb, Map<String, Object> dicTypeEO) {
|
||||||
|
JSONArray array=JSONArray.parseArray(JSON.toJSONString(dicTypeEO.get("BUSSSTANDCLASS")));
|
||||||
|
String[] bussSort=new String[array.size()];
|
||||||
|
int i=0;
|
||||||
|
for (Object o: array) {
|
||||||
|
JSONObject object=JSONObject.parseObject(o.toString());
|
||||||
|
if (!"".equals(object.getString("label"))){
|
||||||
|
bussSort[i]=object.getString("value");
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bussSort=replaceNull(bussSort);
|
||||||
|
selectList(sheet,wb,0,0,bussSort);
|
||||||
|
String [] reviseStatus=new String [2];
|
||||||
|
reviseStatus[0]="制定";
|
||||||
|
reviseStatus[1]="修订";
|
||||||
|
selectList(sheet,wb,2,2,reviseStatus);
|
||||||
|
|
||||||
|
System.out.println(bussSort.toString());
|
||||||
|
return wb;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* firstRow 開始行號 根据此项目,默认为2(下标0开始)
|
||||||
|
* lastRow 根据此项目,默认为最大65535
|
||||||
|
* firstCol 区域中第一个单元格的列号 (下标0开始)
|
||||||
|
* lastCol 区域中最后一个单元格的列号
|
||||||
|
* strings 下拉内容
|
||||||
|
* */
|
||||||
|
public static void selectList(HSSFSheet sheet,HSSFWorkbook wbCreat,int firstCol,int lastCol,String[] strings ){
|
||||||
|
HSSFSheet hidden=null;
|
||||||
|
if (null!=wbCreat.getSheet("hidden")){
|
||||||
|
hidden=wbCreat.getSheet("hidden");
|
||||||
|
}else {
|
||||||
|
hidden = wbCreat.createSheet("hidden");
|
||||||
|
}
|
||||||
|
HSSFCell cell = null;
|
||||||
|
for (int i = 0, length = strings.length; i < length; i++)
|
||||||
|
{
|
||||||
|
String name = strings[i];
|
||||||
|
if (firstCol==0) {
|
||||||
|
HSSFRow row = hidden.createRow(i);
|
||||||
|
cell = row.createCell(firstCol);
|
||||||
|
cell.setCellValue(name);
|
||||||
|
}else {
|
||||||
|
HSSFRow row = hidden.getRow(i);
|
||||||
|
cell = row.createCell(firstCol);
|
||||||
|
cell.setCellValue(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Name namedCell = wbCreat.createName();
|
||||||
|
String names="";
|
||||||
|
if (0==firstCol) {
|
||||||
|
names="hidden";
|
||||||
|
namedCell.setNameName("hidden");
|
||||||
|
namedCell.setRefersToFormula("hidden!$A$1:$A$" + strings.length);
|
||||||
|
}else if (2==firstCol){
|
||||||
|
names="hidden2";
|
||||||
|
namedCell.setNameName("hidden2");
|
||||||
|
namedCell.setRefersToFormula("hidden!$C$1:$C$" + strings.length);
|
||||||
|
}
|
||||||
|
//加载数据,将名称为hidden的
|
||||||
|
DVConstraint constraint = DVConstraint.createFormulaListConstraint(names);
|
||||||
|
|
||||||
|
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
|
||||||
|
CellRangeAddressList addressList = new CellRangeAddressList(1, 65535, firstCol,
|
||||||
|
lastCol);
|
||||||
|
HSSFDataValidation validation = new HSSFDataValidation(addressList, constraint);
|
||||||
|
|
||||||
|
//将第二个sheet设置为隐藏
|
||||||
|
wbCreat.setSheetHidden(1, true);
|
||||||
|
|
||||||
|
if (null != validation)
|
||||||
|
{
|
||||||
|
sheet.addValidationData(validation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 去除错误数据
|
||||||
|
private static String[] replaceNull(String[] str){
|
||||||
|
//用StringBuffer来存放数组中的非空元素,用“;”分隔
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
for(int i=0; i<str.length; i++) {
|
||||||
|
if("".equals(str[i]) || "null".equals(str[i]) || null == str[i] ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sb.append(str[i]);
|
||||||
|
if(i != str.length - 1) {
|
||||||
|
sb.append(";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//用String的split方法分割,得到数组
|
||||||
|
str = sb.toString().split(";");
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -397,6 +397,7 @@ public class TsUserServiceImpl extends ServiceImpl<TsUserDao, TsUser> implements
|
|||||||
flag=false;
|
flag=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ids.removeIf(s -> null==s);
|
||||||
Page<TsUser> tsUserPage = new Page<>();
|
Page<TsUser> tsUserPage = new Page<>();
|
||||||
tsUserPage.setCurrent(tsUser.getCurrent());
|
tsUserPage.setCurrent(tsUser.getCurrent());
|
||||||
tsUserPage.setSize(tsUser.getSize());
|
tsUserPage.setSize(tsUser.getSize());
|
||||||
|
|||||||
Reference in New Issue
Block a user