添加工具类方法
This commit is contained in:
parent
cfd0dfc06e
commit
205bdda0c6
|
|
@ -828,4 +828,51 @@ public class DateUtils extends PropertyEditorSupport {
|
|||
return days;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取开始时间和结束时间之间的全部小时信息
|
||||
* @param beginDay
|
||||
* @param endDay
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getAllDayTime(String beginDay, String endDay){
|
||||
List<String> dayTimes = new ArrayList<>();
|
||||
try {
|
||||
//开始日期
|
||||
Calendar begin = Calendar.getInstance();
|
||||
begin.setTime(DateUtils.parseDate(beginDay, "yyyy-MM-dd"));
|
||||
//将开始日期的24个小时放入集合中
|
||||
for (int i=0; i< 24; i++) {
|
||||
String dayTime = beginDay;
|
||||
if (i < 10) {
|
||||
dayTime+=" 0"+i;
|
||||
} else {
|
||||
dayTime+=" "+i;
|
||||
}
|
||||
dayTime+=":00:00";
|
||||
dayTimes.add(dayTime);
|
||||
}
|
||||
//结束日期
|
||||
Calendar end = Calendar.getInstance();
|
||||
end.setTime(DateUtils.parseDate(endDay, "yyyy-MM-dd"));
|
||||
//判断 如果结束日期的时间在开始日期的时间之后
|
||||
while(end.getTime().after(begin.getTime())){
|
||||
//开始日期需要+1天
|
||||
begin.add(Calendar.DAY_OF_MONTH, 1);
|
||||
for (int i=0; i< 24; i++) {
|
||||
String dayTime = DateUtils.formatDate(begin.getTime(),"yyyy-MM-dd");
|
||||
if (i < 10) {
|
||||
dayTime+=" 0"+i;
|
||||
} else {
|
||||
dayTime+=" "+i;
|
||||
}
|
||||
dayTime+=":00:00";
|
||||
dayTimes.add(dayTime);
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return dayTimes;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
package org.jeecg.common.util;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
|
|
@ -13,18 +11,12 @@ import org.apache.poi.ss.usermodel.Workbook;
|
|||
import org.jeecgframework.poi.excel.ExcelExportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
|
@ -104,6 +96,29 @@ public class ExportUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static <T> void exportXls(HttpServletResponse response, List<Map<String, Object>> dataList, String fileName){
|
||||
Workbook workbook = null;
|
||||
OutputStream outputStream = null;
|
||||
try {
|
||||
// 设置文件名、Excel类型(xls|xlsx)
|
||||
outputStream = ExportUtil.xls(response,fileName);
|
||||
workbook = ExcelExportUtil.
|
||||
exportExcel(dataList, ExcelType.HSSF);
|
||||
workbook.write(outputStream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
if (ObjectUtil.isNotNull(outputStream))
|
||||
outputStream.close();
|
||||
if (ObjectUtil.isNotNull(workbook))
|
||||
workbook.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void exportXls(HttpServletResponse response, Class<T> target, List<T> data){
|
||||
exportXls(response, target, data, "file.xls");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,9 @@ public class NumberFormatUtil {
|
|||
|
||||
//总数字个数是6位的数
|
||||
public static String numberSixLen(String number) {
|
||||
if (StringUtils.isBlank(number)) {
|
||||
return number;
|
||||
}
|
||||
String value = "";
|
||||
if (number.equalsIgnoreCase("nan")) {
|
||||
value = number;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user