拆分-日期校验修改

This commit is contained in:
liyawei
2022-04-18 16:28:13 +08:00
parent 86e59b9200
commit 0b9afb807d
2 changed files with 74 additions and 17 deletions
@@ -1,15 +1,13 @@
package com.jero.common.util;
import org.springframework.util.StringUtils;
import java.beans.PropertyEditorSupport;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.springframework.util.StringUtils;
import java.util.*;
/**
* 类描述:时间操作定义类
@@ -647,7 +645,7 @@ public class DateUtils extends PropertyEditorSupport {
return calendar.get(Calendar.YEAR);
}
/***
* @Description: 判断多个日期是否都符合日期格式
* @Description: 判断多个日期是否都符合日期格式 yyyy/m/d、yyyy-MM-dd、yyyy年MM月dd日
* @Author: yangxuenan
* @Date: 2020/12/31 11:31
* @Param: [str]
@@ -655,19 +653,52 @@ public class DateUtils extends PropertyEditorSupport {
*/
public static boolean isValidDate(String str){
if(org.apache.commons.lang3.StringUtils.isNotBlank(str)){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String dateRegex = "^\\d{4}年\\d{1,2}月\\d{1,2}日";
str = str.replace("",",");
String[] strArr = str.split(",");
for (String dateStr : strArr) {
String replace = dateStr.replace("/", "-");
try {
simpleDateFormat.setLenient(false);
simpleDateFormat.parse(replace);
} catch (Exception e){
return false;
if(dateStr.matches(dateRegex)){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
try {
simpleDateFormat.setLenient(false);
simpleDateFormat.parse(dateStr);
} catch (Exception e){
return false;
}
} else {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String replace = dateStr.replace("/", "-");
try {
simpleDateFormat.setLenient(false);
simpleDateFormat.parse(replace);
} catch (Exception e){
return false;
}
}
}
}
return true;
}
//yyyy年MM月dd日,yyyy/MM/dd 转 yyyy-MM-dd
public static String coverDate(String str) throws ParseException {
List<String> newStrList = new ArrayList<>();
String dateRegex = "^\\d{4}年\\d{1,2}月\\d{1,2}日";
str = str.replace("",",");
String[] strArr = str.split(",");
for (String dateStr : strArr) {
String newStr = null;
if (dateStr.matches(dateRegex)) {
Date date = new SimpleDateFormat("yyyy年MM月dd日").parse(dateStr);
newStr = new SimpleDateFormat("yyyy-MM-dd").format(date);
} else if (dateStr.contains("/")) {
Date date = new SimpleDateFormat("yyyy/MM/dd").parse(dateStr);
newStr = new SimpleDateFormat("yyyy-MM-dd").format(date);
} else if (dateStr.contains("-")){
newStr = dateStr;
}
newStrList.add(newStr);
}
return org.apache.commons.lang3.StringUtils.join(newStrList, ",");
}
}
@@ -539,11 +539,13 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
if(fieldPersonList.contains(entry.getKey()) && StringUtils.isNotBlank((String)entry.getValue())) {
List<SysUser> sysUserList = sysUserService.listByIds(Arrays.asList(entry.getValue().toString().split(",")));
StringBuilder stringBuilder = new StringBuilder();
for(SysUser user : sysUserList){
stringBuilder.append(user.getRealname()).append("(").append(user.getUsername()).append("),");
if (CollectionUtil.isNotEmpty(sysUserList)) {
for (SysUser user : sysUserList) {
stringBuilder.append(user.getRealname()).append("(").append(user.getUsername()).append("),");
}
String value = stringBuilder.substring(0, stringBuilder.lastIndexOf(","));
entry.setValue(value);
}
String value = stringBuilder.substring(0, stringBuilder.lastIndexOf(","));
entry.setValue(value);
}
// 标准选择
if(fieldStanList.contains(entry.getKey()) && StringUtils.isNotBlank((String)entry.getValue())) {
@@ -797,6 +799,9 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
@Override
public Map<String, Object> getInfoById(String id) {
if (StringUtils.isBlank(id)) {
return null;
}
Map<String, Object> itemsMap = dao.selectByPrimaryKey(id);
// 查询条款表单字段
List<OnlCgformField> formFieldList = onlCgformFieldService.getFieldList(ModuleEnum.FILE_SPLIT_ITEMS.getValue());
@@ -2035,6 +2040,8 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
errorMsg += fieldName + " Incorrect format correct format is:yyyy/m/d、yyyy-MM-dd、yyyy年MM月dd日;";
}
countError++;
} else {
value = DateUtils.coverDate((String) value);
}
} else if (FieldTypeEnum.DATE_MORE.getValue().equals(fieldShowType)) {
@@ -2056,6 +2063,19 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
errorMsg += fieldName + " Incorrect format correct format is:yyyy/m/d、yyyy-MM-dd、yyyy年MM月dd日;";
}
countError++;
} else {
value = DateUtils.coverDate((String) value);
}
//判断是否是两个日期点
String str = value.replace("",",");
String[] strArr = str.split(",");
if (strArr.length != 2) {
if(CutEnum.CN.getValue().equals(cut)){
errorMsg += fieldName + "必须填写两个日期;";
}else{
errorMsg += fieldName + " must fill in the two dates;";
}
countError++;
}
} else if (FieldTypeEnum.FILE.getValue().equals(fieldShowType)) {
@@ -2184,6 +2204,12 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
SysUser user = sysUserService.getUserByName(uName);
if (ObjectUtils.isNotEmpty(user)) {
userIdList.add(user.getId());
} else {
if(CutEnum.CN.getValue().equals(cut)) {
errorMsg += fieldName + "中人员" + userNames[u] + "不存在;";
} else {
errorMsg += fieldName + " " + userNames[u] + "Not exist;";
}
}
}
}