本地上传添加时间

This commit is contained in:
chenshaohua
2026-07-08 12:40:59 +08:00
parent 3db8786e89
commit 96a4b1503d
2 changed files with 73 additions and 9 deletions

View File

@@ -3,10 +3,7 @@ package com.ruoyi.cms.domain.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.cms.domain.JobContact;
import com.ruoyi.cms.util.excel.ContactParseConverter;
import com.ruoyi.cms.util.excel.EducationConverter;
import com.ruoyi.cms.util.excel.SalaryParseConverter;
import com.ruoyi.cms.util.excel.VacancyLongConverter;
import com.ruoyi.cms.util.excel.*;
import com.ruoyi.common.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -68,6 +65,11 @@ public class JobLocalExcelVo
@ApiModelProperty("岗位收集人")
private String gwsjr;
@ExcelProperty(value = "需求月份", index = 12,converter = PostingDateConverter.class)
@JsonFormat(pattern = "yyyy-MM-dd")
@ApiModelProperty("发布时间")
private String postingDate;
@ExcelProperty(value = "联系人")
@ApiModelProperty("联系人")
private String contactPerson;
@@ -110,11 +112,6 @@ public class JobLocalExcelVo
@ApiModelProperty("工作地点区县字典代码")
private Integer jobLocationAreaCode;
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "发布时间", width = 30, dateFormat = "yyyy-MM-dd")
@ApiModelProperty("发布时间")
private String postingDate;
@ApiModelProperty("数据来源")
private String dataSource;

View File

@@ -0,0 +1,67 @@
package com.ruoyi.cms.util.excel;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PostingDateConverter implements Converter<Date> {
private static final Pattern MONTH_PATTERN = Pattern.compile("^(\\d{1,2})月$");
@Override
public Class<Date> supportJavaTypeKey() {
return Date.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public Date convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
String value = cellData.getStringValue();
if (isBlank(value)) {
return null;
}
String trimStr = value.trim();
Matcher matcher = MONTH_PATTERN.matcher(trimStr);
if (!matcher.matches()) {
return null;
}
int month = Integer.parseInt(matcher.group(1));
if (month < 1 || month > 12) {
return null;
}
int currentYear = LocalDate.now().getYear();
LocalDate localDate = LocalDate.of(currentYear, month, 1);
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}
@Override
public WriteCellData<?> convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
if (value == null) {
return new WriteCellData<>("");
}
LocalDate localDate = value.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
return new WriteCellData<>(localDate.getMonthValue() + "");
}
public static boolean isBlank(String str) {
if (str == null) {
return true;
}
for (int i = 0; i < str.length(); i++) {
if (!Character.isWhitespace(str.charAt(i))) {
return false;
}
}
return true;
}
}