From 6b771d61c6cefa729300f6aa3784401c8fc14c30 Mon Sep 17 00:00:00 2001 From: gaoguangchao <443960933@qq.com> Date: Sat, 27 Jul 2024 12:08:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9Asheet=20Excel=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=A8=E6=80=81=E5=AD=97=E5=85=B8=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/DictUtils.java | 21 +++-- .../utils/poi/ExcelMultipleSheetsUtil.java | 6 +- .../com/ruoyi/common/utils/poi/ExcelUtil.java | 42 ++++----- ruoyi-ui/src/utils/dateUtils.js | 42 +++++++++ .../views/deviceManage/deviceOnline/index.vue | 93 +++++++++++-------- .../com/zc/business/domain/OnlineSum.java | 4 +- 6 files changed, 132 insertions(+), 76 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java index 16404392..19556db4 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java @@ -1,5 +1,6 @@ package com.ruoyi.common.utils; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import com.ruoyi.common.constant.Constants; @@ -9,7 +10,7 @@ import com.ruoyi.common.utils.spring.SpringUtils; /** * 字典工具类 - * + * * */ public class DictUtils @@ -21,7 +22,7 @@ public class DictUtils /** * 设置字典缓存 - * + * * @param key 参数键 * @param dictDatas 字典数据列表 */ @@ -32,7 +33,7 @@ public class DictUtils /** * 获取字典缓存 - * + * * @param key 参数键 * @return dictDatas 字典数据列表 */ @@ -43,12 +44,12 @@ public class DictUtils { return StringUtils.cast(cacheObj); } - return null; + return new ArrayList<>(); } /** * 根据字典类型和字典值获取字典标签 - * + * * @param dictType 字典类型 * @param dictValue 字典值 * @return 字典标签 @@ -60,7 +61,7 @@ public class DictUtils /** * 根据字典类型和字典标签获取字典值 - * + * * @param dictType 字典类型 * @param dictLabel 字典标签 * @return 字典值 @@ -72,7 +73,7 @@ public class DictUtils /** * 根据字典类型和字典值获取字典标签 - * + * * @param dictType 字典类型 * @param dictValue 字典值 * @param separator 分隔符 @@ -112,7 +113,7 @@ public class DictUtils /** * 根据字典类型和字典标签获取字典值 - * + * * @param dictType 字典类型 * @param dictLabel 字典标签 * @param separator 分隔符 @@ -152,7 +153,7 @@ public class DictUtils /** * 删除指定字典缓存 - * + * * @param key 字典键 */ public static void removeDictCache(String key) @@ -171,7 +172,7 @@ public class DictUtils /** * 设置cache key - * + * * @param configKey 参数键 * @return 缓存键key */ diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelMultipleSheetsUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelMultipleSheetsUtil.java index 5fdc9e51..43c0f19e 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelMultipleSheetsUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelMultipleSheetsUtil.java @@ -8,6 +8,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.utils.DictUtils; +import com.ruoyi.common.utils.StringUtils; import org.apache.poi.ss.usermodel.*; import org.apache.poi.util.IOUtils; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -242,10 +243,10 @@ public class ExcelMultipleSheetsUtil { * @param value 值 */ private void handleAnnotationAndSetValue(Cell cell, Field field, Object value) { - if (field.isAnnotationPresent(Excel.class) && field.getAnnotation(Excel.class).dictType().length() > 0) { + if (StringUtils.isNotNull(value)&&field.isAnnotationPresent(Excel.class) && field.getAnnotation(Excel.class).dictType().length() > 0) { value = DictUtils.getDictLabel(field.getAnnotation(Excel.class).dictType(), String.valueOf(value)); } - if (field.isAnnotationPresent(Excel.class) && StrUtil.isNotEmpty(field.getAnnotation(Excel.class).dateFormat())) { + if (StringUtils.isNotNull(value)&&field.isAnnotationPresent(Excel.class) && StrUtil.isNotEmpty(field.getAnnotation(Excel.class).dateFormat())) { value = DateUtil.format(Convert.convert(Date.class, value), field.getAnnotation(Excel.class).dateFormat()); } cell.setCellValue(ObjectUtil.isEmpty(value) ? null : value.toString()); @@ -333,5 +334,4 @@ public class ExcelMultipleSheetsUtil { return styles; } - } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java index a0582424..c6642e7e 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java @@ -623,41 +623,41 @@ public class ExcelUtil // 写入各条记录,每条记录对应excel表中的一行 Map styles = new HashMap(); CellStyle style = wb.createCellStyle(); - style.setAlignment(HorizontalAlignment.CENTER); - style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setAlignment(HorizontalAlignment.CENTER);//单元格水平对齐方式 + style.setVerticalAlignment(VerticalAlignment.CENTER);//单元格垂直对齐方式 Font titleFont = wb.createFont(); - titleFont.setFontName("Arial"); - titleFont.setFontHeightInPoints((short) 16); - titleFont.setBold(true); - style.setFont(titleFont); + titleFont.setFontName("Arial");//字体 + titleFont.setFontHeightInPoints((short) 16);//字号 + titleFont.setBold(true);//加粗 + style.setFont(titleFont);//设置字体 styles.put("title", style); style = wb.createCellStyle(); - style.setAlignment(HorizontalAlignment.CENTER); - style.setVerticalAlignment(VerticalAlignment.CENTER); - style.setBorderRight(BorderStyle.THIN); - style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); - style.setBorderLeft(BorderStyle.THIN); - style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); - style.setBorderTop(BorderStyle.THIN); - style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); - style.setBorderBottom(BorderStyle.THIN); - style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setAlignment(HorizontalAlignment.CENTER);//单元格水平对齐方式 + style.setVerticalAlignment(VerticalAlignment.CENTER);//单元格垂直对齐方式 + style.setBorderRight(BorderStyle.THIN);//右边框细线 + style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());//右边框颜色 + style.setBorderLeft(BorderStyle.THIN);//左边框细线 + style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());//左边框颜色 + style.setBorderTop(BorderStyle.THIN);//上边框细线 + style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());//上边框颜色 + style.setBorderBottom(BorderStyle.THIN); //下边框细线 + style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());//下边框颜色 Font dataFont = wb.createFont(); - dataFont.setFontName("Arial"); - dataFont.setFontHeightInPoints((short) 10); - style.setFont(dataFont); + dataFont.setFontName("Arial");//字体 + dataFont.setFontHeightInPoints((short) 10);//字号 + style.setFont(dataFont);//设置字体 styles.put("data", style); style = wb.createCellStyle(); style.cloneStyleFrom(styles.get("data")); style.setAlignment(HorizontalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER); - style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setFillForegroundColor(IndexedColors.BLUE_GREY.getIndex());//填充前景色为25%灰色 style.setFillPattern(FillPatternType.SOLID_FOREGROUND); Font headerFont = wb.createFont(); headerFont.setFontName("Arial"); - headerFont.setFontHeightInPoints((short) 10); + headerFont.setFontHeightInPoints((short) 12); headerFont.setBold(true); headerFont.setColor(IndexedColors.WHITE.getIndex()); style.setFont(headerFont); diff --git a/ruoyi-ui/src/utils/dateUtils.js b/ruoyi-ui/src/utils/dateUtils.js index 15b23085..52b416cf 100644 --- a/ruoyi-ui/src/utils/dateUtils.js +++ b/ruoyi-ui/src/utils/dateUtils.js @@ -165,3 +165,45 @@ export function countDays(date1, date2) { return 0 } } + +/** + * 日期加一天或减一天 + * @param dateStr 日期字符串,格式为yyyy-MM-dd + * @param numDays 增加或减少的天数,负数减,正数加 + * @returns {string} + */ +export function addOrSubtractDays(date, numDays) { + if(typeof date === 'string'){ + const parts = date.split('-'); + const year = parseInt(parts[0], 10); + const month = parseInt(parts[1], 10) - 1; // 月份需要减1,因为Date对象月份是从0开始的 + const day = parseInt(parts[2], 10); + const date1 = new Date(year, month, day); + date1.setDate(date1.getDate() + numDays); + const yearFormatted = date1.getFullYear(); + const monthFormatted = (date1.getMonth() + 1).toString().padStart(2, '0'); // 月份加1,并格式化为两位数 + const dayFormatted = date1.getDate().toString().padStart(2, '0'); // 格式化为两位数 + return `${yearFormatted}-${monthFormatted}-${dayFormatted}`; + }else if(date instanceof Date){ + date.setDate(date.getDate() + numDays); + const yearFormatted = date.getFullYear(); + const monthFormatted = (date.getMonth() + 1).toString().padStart(2, '0'); // 月份加1,并格式化为两位数 + const dayFormatted = date.getDate().toString().padStart(2, '0'); // 格式化为两位数 + return `${yearFormatted}-${monthFormatted}-${dayFormatted}`; + }else { + console.error('参数格式无效!') + return '' + } +} + +/** + * + * @param rangeNubmer 范围天数,负数表示向前,正数表示向后 + * @returns {{start: string, end: String}} + */ +export function getDaysRange(rangeNubmer){ + if(!(rangeNubmer instanceof Number)) rangeNubmer=Number(rangeNubmer) + const startDate= new Date(); + startDate.setDate(startDate.getDate()+rangeNubmer); + return {start:formatDate(startDate),end:formatDate(new Date())} +} diff --git a/ruoyi-ui/src/views/deviceManage/deviceOnline/index.vue b/ruoyi-ui/src/views/deviceManage/deviceOnline/index.vue index aa840c25..4c4ee0aa 100644 --- a/ruoyi-ui/src/views/deviceManage/deviceOnline/index.vue +++ b/ruoyi-ui/src/views/deviceManage/deviceOnline/index.vue @@ -5,9 +5,22 @@ - 导出 + + + + 导出 + - + @@ -159,6 +172,7 @@ diff --git a/zc-business/src/main/java/com/zc/business/domain/OnlineSum.java b/zc-business/src/main/java/com/zc/business/domain/OnlineSum.java index 2d98fa62..7db6fac3 100644 --- a/zc-business/src/main/java/com/zc/business/domain/OnlineSum.java +++ b/zc-business/src/main/java/com/zc/business/domain/OnlineSum.java @@ -21,9 +21,9 @@ public class OnlineSum implements java.io.Serializable { private String stakeMark;//设备桩号 private String direction;//方向 private String deviceType;//设备类型 - @Excel(name = "设备状态", readConverterExp = "0=异常,1=正常") + @Excel(name = "设备状态", dictType = "dc_device_state") private String deviceStatus;//当前设备状态? - @Excel(name = "使用状态", readConverterExp = "0=未使用,1=使用中") + @Excel(name = "使用状态", dictType = "dc_device_use") private String useState; private int totalCount;//当天总次数 @Excel(name = "在线率(%)")