更新StringUtils
This commit is contained in:
parent
aabb4267b9
commit
b3d54bc25f
|
@ -77,9 +77,9 @@ public class BizController {
|
||||||
|
|
||||||
|
|
||||||
Map<String, String> resultMap = new HashMap<>();
|
Map<String, String> resultMap = new HashMap<>();
|
||||||
resultMap.put("latestShippingDate", "0".equals(latestShippingDate) ? latestShippingDate : StringUtils.formatDateString(latestShippingDate, "yyyyMMdd", "yyyy-MM-dd"));
|
resultMap.put("latestShippingDate", "0".equals(latestShippingDate) ? latestShippingDate : StringUtils.formatDateString(latestShippingDate, "yyyy-MM-dd"));
|
||||||
resultMap.put("latestOrderDate", "0".equals(latestOrderDate) ? latestOrderDate : StringUtils.formatDateString(latestOrderDate, "yyyyMMdd", "yyyy-MM-dd"));
|
resultMap.put("latestOrderDate", "0".equals(latestOrderDate) ? latestOrderDate : StringUtils.formatDateString(latestOrderDate, "yyyy-MM-dd"));
|
||||||
resultMap.put("latestQuotationDate", "0".equals(latestQuotationDate) ? latestQuotationDate : StringUtils.formatDateString(latestQuotationDate, "yyyy-MM-dd HH:mm:ss.SS", "yyyy-MM-dd"));
|
resultMap.put("latestQuotationDate", "0".equals(latestQuotationDate) ? latestQuotationDate : StringUtils.formatDateString(latestQuotationDate, "yyyy-MM-dd"));
|
||||||
resultMap.put("salespersonCount", salespersonCount );
|
resultMap.put("salespersonCount", salespersonCount );
|
||||||
|
|
||||||
log.info("Received request with parameter: {}", "开始写日志文件");
|
log.info("Received request with parameter: {}", "开始写日志文件");
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package com.JIAL.utils;
|
package com.JIAL.utils;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,20 +32,34 @@ public class StringUtils {
|
||||||
/**
|
/**
|
||||||
* @title formatDateString
|
* @title formatDateString
|
||||||
* @description 格式化传入的日期字符串
|
* @description 格式化传入的日期字符串
|
||||||
* @author JIAL
|
* @author JN
|
||||||
* @param: inputString 传入字符串
|
* @param: dateTimeString 日期字符串 支持yyyy-MM-dd HH:mm:ss,SSS(小数点位数不固定),支持yyyyMMdd
|
||||||
* @param: inputFormat 指定传入的格式 yyyyMMdd
|
* @param: pattern 你想要输出的格式
|
||||||
* @param: outputFormat 指定输出的格式 yyyy-MM-dd
|
* @updateTime 2024/1/15 9:52
|
||||||
* @updateTime 2024/1/9 14:39
|
|
||||||
* @return: java.lang.String
|
* @return: java.lang.String
|
||||||
*/
|
*/
|
||||||
public static String formatDateString(String inputString, String inputFormat, String outputFormat) {
|
public static String formatDateString(String dateTimeString, String pattern) {
|
||||||
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(inputFormat);
|
try {
|
||||||
LocalDate date = LocalDate.parse(inputString, inputFormatter);
|
// 将时间字符串解析为 Date 对象
|
||||||
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormat);
|
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||||
return date.format(outputFormatter);
|
Date parsedDate = inputFormat.parse(dateTimeString);
|
||||||
}
|
|
||||||
|
|
||||||
|
// 格式化 Date 对象为指定格式的字符串
|
||||||
|
SimpleDateFormat outputFormat = new SimpleDateFormat(pattern);
|
||||||
|
return outputFormat.format(parsedDate);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
// 解析失败时,尝试解析为纯日期格式
|
||||||
|
try {
|
||||||
|
SimpleDateFormat dateOnlyFormat = new SimpleDateFormat("yyyyMMdd");
|
||||||
|
Date parsedDate = dateOnlyFormat.parse(dateTimeString);
|
||||||
|
return new SimpleDateFormat(pattern).format(parsedDate);
|
||||||
|
} catch (ParseException ex) {
|
||||||
|
// 无法解析时的异常处理
|
||||||
|
ex.printStackTrace();
|
||||||
|
return "解析失败";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@
|
||||||
})
|
})
|
||||||
queryInsuredCountByName(params).then(res => {
|
queryInsuredCountByName(params).then(res => {
|
||||||
if (String(res.code) === '1') {
|
if (String(res.code) === '1') {
|
||||||
this.detail.insuredCount = res.data.insuredCount !== '0' ? res.data.insuredCount : '无数据';
|
this.detail.insuredCount = res.data.insuredCount !== '' ? res.data.insuredCount : '无数据';
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
this.$message.error('请求出错了:' + err)
|
this.$message.error('请求出错了:' + err)
|
||||||
|
|
Loading…
Reference in New Issue