统计
This commit is contained in:
@@ -125,16 +125,20 @@
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--mybatis-plus工具-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- word工具 -->
|
||||
<dependency>
|
||||
<groupId>com.deepoove</groupId>
|
||||
<artifactId>poi-tl</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -8,16 +8,18 @@ import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
|
||||
/**
|
||||
* 时间工具类
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
{
|
||||
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
public static String YYYY = "yyyy";
|
||||
|
||||
public static String YYYY_MM = "yyyy-MM";
|
||||
@@ -29,63 +31,52 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
private static String[] parsePatterns = {
|
||||
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
||||
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
||||
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
||||
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
|
||||
|
||||
/**
|
||||
* 获取当前Date型日期
|
||||
*
|
||||
*
|
||||
* @return Date() 当前日期
|
||||
*/
|
||||
public static Date getNowDate()
|
||||
{
|
||||
public static Date getNowDate() {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前日期, 默认格式为yyyy-MM-dd
|
||||
*
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String getDate()
|
||||
{
|
||||
public static String getDate() {
|
||||
return dateTimeNow(YYYY_MM_DD);
|
||||
}
|
||||
|
||||
public static final String getTime()
|
||||
{
|
||||
public static final String getTime() {
|
||||
return dateTimeNow(YYYY_MM_DD_HH_MM_SS);
|
||||
}
|
||||
|
||||
public static final String dateTimeNow()
|
||||
{
|
||||
public static final String dateTimeNow() {
|
||||
return dateTimeNow(YYYYMMDDHHMMSS);
|
||||
}
|
||||
|
||||
public static final String dateTimeNow(final String format)
|
||||
{
|
||||
public static final String dateTimeNow(final String format) {
|
||||
return parseDateToStr(format, new Date());
|
||||
}
|
||||
|
||||
public static final String dateTime(final Date date)
|
||||
{
|
||||
public static final String dateTime(final Date date) {
|
||||
return parseDateToStr(YYYY_MM_DD, date);
|
||||
}
|
||||
|
||||
public static final String parseDateToStr(final String format, final Date date)
|
||||
{
|
||||
public static final String parseDateToStr(final String format, final Date date) {
|
||||
return new SimpleDateFormat(format).format(date);
|
||||
}
|
||||
|
||||
public static final Date dateTime(final String format, final String ts)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static final Date dateTime(final String format, final String ts) {
|
||||
try {
|
||||
return new SimpleDateFormat(format).parse(ts);
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -93,8 +84,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
/**
|
||||
* 日期路径 即年/月/日 如2018/08/08
|
||||
*/
|
||||
public static final String datePath()
|
||||
{
|
||||
public static final String datePath() {
|
||||
Date now = new Date();
|
||||
return DateFormatUtils.format(now, "yyyy/MM/dd");
|
||||
}
|
||||
@@ -102,8 +92,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
/**
|
||||
* 日期路径 即年/月/日 如20180808
|
||||
*/
|
||||
public static final String dateTime()
|
||||
{
|
||||
public static final String dateTime() {
|
||||
Date now = new Date();
|
||||
return DateFormatUtils.format(now, "yyyyMMdd");
|
||||
}
|
||||
@@ -111,18 +100,13 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
/**
|
||||
* 日期型字符串转化为日期 格式
|
||||
*/
|
||||
public static Date parseDate(Object str)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
public static Date parseDate(Object str) {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
try {
|
||||
return parseDate(str.toString(), parsePatterns);
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
} catch (ParseException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -130,8 +114,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
/**
|
||||
* 获取服务器启动时间
|
||||
*/
|
||||
public static Date getServerStartDate()
|
||||
{
|
||||
public static Date getServerStartDate() {
|
||||
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
|
||||
return new Date(time);
|
||||
}
|
||||
@@ -139,20 +122,18 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
/**
|
||||
* 计算相差天数
|
||||
*/
|
||||
public static int differentDaysByMillisecond(Date date1, Date date2)
|
||||
{
|
||||
public static int differentDaysByMillisecond(Date date1, Date date2) {
|
||||
return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算时间差
|
||||
*
|
||||
* @param endDate 最后时间
|
||||
* @param endDate 最后时间
|
||||
* @param startTime 开始时间
|
||||
* @return 时间差(天/小时/分钟)
|
||||
*/
|
||||
public static String timeDistance(Date endDate, Date startTime)
|
||||
{
|
||||
public static String timeDistance(Date endDate, Date startTime) {
|
||||
long nd = 1000 * 24 * 60 * 60;
|
||||
long nh = 1000 * 60 * 60;
|
||||
long nm = 1000 * 60;
|
||||
@@ -173,8 +154,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
/**
|
||||
* 增加 LocalDateTime ==> Date
|
||||
*/
|
||||
public static Date toDate(LocalDateTime temporalAccessor)
|
||||
{
|
||||
public static Date toDate(LocalDateTime temporalAccessor) {
|
||||
ZonedDateTime zdt = temporalAccessor.atZone(ZoneId.systemDefault());
|
||||
return Date.from(zdt.toInstant());
|
||||
}
|
||||
@@ -182,10 +162,28 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
/**
|
||||
* 增加 LocalDate ==> Date
|
||||
*/
|
||||
public static Date toDate(LocalDate temporalAccessor)
|
||||
{
|
||||
public static Date toDate(LocalDate temporalAccessor) {
|
||||
LocalDateTime localDateTime = LocalDateTime.of(temporalAccessor, LocalTime.of(0, 0, 0));
|
||||
ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
|
||||
return Date.from(zdt.toInstant());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某个月所有的日期序列
|
||||
*
|
||||
* @param year
|
||||
* @param month
|
||||
* @return
|
||||
*/
|
||||
public static List<LocalDate> generateDatesInMonth(int year, int month) {
|
||||
List<LocalDate> dates = new ArrayList<>();
|
||||
LocalDate firstDayOfMonth = LocalDate.of(year, month, 1);
|
||||
LocalDate lastDayOfMonth = firstDayOfMonth.plusMonths(1).minusDays(1);
|
||||
|
||||
for (LocalDate date = firstDayOfMonth; !date.isAfter(lastDayOfMonth); date = date.plusDays(1)) {
|
||||
dates.add(date);
|
||||
}
|
||||
|
||||
return dates;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package com.ruoyi.common.utils.bean;
|
||||
|
||||
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -107,4 +113,17 @@ public class BeanUtils extends org.springframework.beans.BeanUtils
|
||||
{
|
||||
return m1.substring(BEAN_METHOD_PROP_INDEX).equals(m2.substring(BEAN_METHOD_PROP_INDEX));
|
||||
}
|
||||
|
||||
public static String[] getNullPropertyNames (Object source) {
|
||||
final BeanWrapper src = new BeanWrapperImpl(source);
|
||||
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
|
||||
|
||||
Set<String> emptyNames = new HashSet<String>();
|
||||
for(java.beans.PropertyDescriptor pd : pds) {
|
||||
Object srcValue = src.getPropertyValue(pd.getName());
|
||||
if (srcValue == null) emptyNames.add(pd.getName());
|
||||
}
|
||||
String[] result = new String[emptyNames.size()];
|
||||
return emptyNames.toArray(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class FileUploadUtils
|
||||
/**
|
||||
* 默认大小 50M
|
||||
*/
|
||||
public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024;
|
||||
public static final long DEFAULT_MAX_SIZE = 256 * 1024 * 1024;
|
||||
|
||||
/**
|
||||
* 默认的文件名最大长度 100
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.ruoyi.common.utils.poi;
|
||||
|
||||
import com.deepoove.poi.XWPFTemplate;
|
||||
import com.deepoove.poi.config.Configure;
|
||||
import com.deepoove.poi.config.ConfigureBuilder;
|
||||
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
||||
import com.deepoove.poi.util.PoitlIOUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class PoiTlWordUtils {
|
||||
|
||||
/**
|
||||
* 根据文件模版生成文件保存至本地
|
||||
*
|
||||
* @param map 数据集合
|
||||
* @param nameList 循环添加的数据
|
||||
* @param path 模版路径 我放到了 项目的 resources/file 下面了
|
||||
* @param filePath 生成文件保存到本地的路径及文件名称
|
||||
*/
|
||||
public static void poiTlWord(Map<String, Object> map, List<String> nameList, String path, String filePath) {
|
||||
XWPFTemplate template;
|
||||
try {
|
||||
//处理文件
|
||||
template = common(path, map, nameList);
|
||||
//写出文件且关闭流
|
||||
template.writeAndClose(Files.newOutputStream(Paths.get(filePath)));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据word模版生成word文档并通过流的方式下载 get请求
|
||||
*
|
||||
* @param map 数据集合
|
||||
* @param nameList 循环表格名称
|
||||
* @param path 模版文件路径
|
||||
* @param fileName 生成的文件名称
|
||||
* @param response response
|
||||
*/
|
||||
public static void poiTlWord(Map<String, Object> map, List<String> nameList, String path, String fileName, HttpServletResponse response) {
|
||||
OutputStream out = null;
|
||||
BufferedOutputStream bos = null;
|
||||
XWPFTemplate template;
|
||||
String filePoiName;
|
||||
try {
|
||||
//处理文件
|
||||
template = common(path, map, nameList);
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
filePoiName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
|
||||
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + filePoiName + ".docx");
|
||||
out = response.getOutputStream();
|
||||
bos = new BufferedOutputStream(out);
|
||||
template.write(bos);
|
||||
bos.flush();
|
||||
out.flush();
|
||||
PoitlIOUtils.closeQuietlyMulti(template, bos, out);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (bos != null) {
|
||||
bos.close();
|
||||
}
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据word模版生成文件 返回InputStream
|
||||
*
|
||||
* @param map 数据
|
||||
* @param nameList 循环数据名称集合
|
||||
* @param path 模版文件位置
|
||||
* @return InputStream
|
||||
*/
|
||||
public static InputStream poiTlWord(Map<String, Object> map, List<String> nameList, String path) {
|
||||
ByteArrayOutputStream bos = null;
|
||||
XWPFTemplate template = null;
|
||||
try {
|
||||
//处理文件
|
||||
template = common(path, map, nameList);
|
||||
bos = new ByteArrayOutputStream();
|
||||
template.write(bos);
|
||||
return new ByteArrayInputStream(bos.toByteArray());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (bos != null) {
|
||||
bos.close();
|
||||
}
|
||||
if (template != null) {
|
||||
template.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 公共处理模版数据
|
||||
*
|
||||
* @param path 模版文件位置
|
||||
* @param map 数据
|
||||
* @param nameList 数据名字集合
|
||||
* @return 文档
|
||||
*/
|
||||
private static XWPFTemplate common(String path, Map<String, Object> map, List<String> nameList) {
|
||||
//获取模版文件的文件流
|
||||
ClassPathResource classPathResource = new ClassPathResource(path);
|
||||
XWPFTemplate template;
|
||||
InputStream ins = null;
|
||||
try {
|
||||
ins = classPathResource.getInputStream();
|
||||
if (CollectionUtils.isNotEmpty(nameList)) {
|
||||
//如果有循环添加的数据表格的话 则绑定
|
||||
LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
||||
ConfigureBuilder builder = Configure.builder();
|
||||
nameList.forEach(l -> builder.bind(l, policy));
|
||||
Configure config = builder.build();
|
||||
template = XWPFTemplate.compile(ins, config).render(map);
|
||||
} else {
|
||||
template = XWPFTemplate.compile(ins).render(map);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (ins != null) {
|
||||
ins.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
}
|
||||
BIN
ruoyi-common/src/main/resources/template/taskCheckExport.doc
Normal file
BIN
ruoyi-common/src/main/resources/template/taskCheckExport.doc
Normal file
Binary file not shown.
Reference in New Issue
Block a user