|
|
|
@ -55,7 +55,6 @@ import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
|
|
|
|
|
import com.teamcenter.rac.kernel.ListOfValuesInfo;
|
|
|
|
|
import com.teamcenter.rac.kernel.TCComponent;
|
|
|
|
@ -86,7 +85,8 @@ public class RWFPDialog extends JFrame implements ActionListener {
|
|
|
|
|
private LinkedHashMap<Integer, String> lovPositionMap = new LinkedHashMap<Integer, String>();
|
|
|
|
|
private LinkedHashMap<String, Integer> positionFieldMap = new LinkedHashMap<String, Integer>();
|
|
|
|
|
private LinkedHashMap<Integer, Integer> widtheMap = new LinkedHashMap<Integer, Integer>();
|
|
|
|
|
//public static final int[] HEADERWIDTH = new int[] { 50, 100, 200, 200, 100, 100, 80, 80, 100, 150, 150, 150, 150,150, 150, 150, 150, 150, 150 };
|
|
|
|
|
// public static final int[] HEADERWIDTH = new int[] { 50, 100, 200, 200, 100,
|
|
|
|
|
// 100, 80, 80, 100, 150, 150, 150, 150,150, 150, 150, 150, 150, 150 };
|
|
|
|
|
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
private DefaultTableModel dtm1;
|
|
|
|
|
private JButton yyButton = new JButton("应用");
|
|
|
|
@ -97,19 +97,29 @@ public class RWFPDialog extends JFrame implements ActionListener {
|
|
|
|
|
private static ArrayList<String> dateConnList = new ArrayList<String>();
|
|
|
|
|
private String type;
|
|
|
|
|
private String id;
|
|
|
|
|
private String objectString;
|
|
|
|
|
private boolean readOnly;
|
|
|
|
|
private ArrayList<Integer> canWriteColume = new ArrayList<Integer>();
|
|
|
|
|
|
|
|
|
|
public RWFPDialog(TCSession session,String type,String id) {
|
|
|
|
|
public RWFPDialog(TCSession session, String type, String id, String objectString, boolean readOnly) {
|
|
|
|
|
// TODO Auto-generated constructor stub
|
|
|
|
|
this.session = session;
|
|
|
|
|
this.type = type;
|
|
|
|
|
this.id = id;
|
|
|
|
|
this.objectString = objectString;
|
|
|
|
|
this.readOnly = readOnly;
|
|
|
|
|
initUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initUI() {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
this.setTitle("任务分配表");
|
|
|
|
|
|
|
|
|
|
if(readOnly) {
|
|
|
|
|
yyButton.setEnabled(false);
|
|
|
|
|
tzsjButton.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.setTitle(objectString+"变更任务分配表");
|
|
|
|
|
this.setLayout(new BorderLayout());
|
|
|
|
|
|
|
|
|
|
String[] cfdj = session.getPreferenceService().getStringValues("Connor_ChangeTaskForm_TriggerLevelMapping");
|
|
|
|
@ -119,9 +129,18 @@ public class RWFPDialog extends JFrame implements ActionListener {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < cfdj.length; i++) {
|
|
|
|
|
|
|
|
|
|
String[] split = cfdj[i].split("=");
|
|
|
|
|
cfdjPref.put(split[0],split[1]);
|
|
|
|
|
cfdJComboBox.addItem(split[0]);
|
|
|
|
|
if(split[0].equals(type)) {
|
|
|
|
|
String[] split2 = split[1].split(";");
|
|
|
|
|
for (int j = 0; j < split2.length; j++) {
|
|
|
|
|
String[] split3 = split2[j].split("\\|");
|
|
|
|
|
cfdjPref.put(split3[0],split3[1]);
|
|
|
|
|
cfdJComboBox.addItem(split3[0]);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取首选项匹配的类型
|
|
|
|
@ -172,6 +191,11 @@ public class RWFPDialog extends JFrame implements ActionListener {
|
|
|
|
|
System.out.println("fieldsMap====="+fieldsMap);
|
|
|
|
|
System.out.println("positionMap====="+lovPositionMap);
|
|
|
|
|
System.out.println("widtheMap====="+widtheMap);
|
|
|
|
|
if(fieldsMap.size() == 0) {
|
|
|
|
|
|
|
|
|
|
MessageBox.post("该类型未匹配到首选项!", "提示 ", MessageBox.INFORMATION);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Collection<String> valuesCollection = fieldsMap.values();
|
|
|
|
|
|
|
|
|
|
// 将集合转换为数组
|
|
|
|
@ -258,7 +282,6 @@ public class RWFPDialog extends JFrame implements ActionListener {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void createActionEvent() {
|
|
|
|
|
this.yyButton.addActionListener(this);
|
|
|
|
|
this.gbButton.addActionListener(this);
|
|
|
|
@ -272,7 +295,7 @@ public class RWFPDialog extends JFrame implements ActionListener {
|
|
|
|
|
topPanel.setLayout(new PropertyLayout());
|
|
|
|
|
|
|
|
|
|
topPanel.add("1.1.left.center", new JLabel("触发等级 "));
|
|
|
|
|
topPanel.add("1.2.left.center",cfdJComboBox);
|
|
|
|
|
topPanel.add("1.2.left.center", cfdJComboBox);
|
|
|
|
|
topPanel.add("1.3.left.center", new JLabel(" 触发时间 "));
|
|
|
|
|
|
|
|
|
|
cfsjButton = new DateButton(null, "yyyy-MM-dd", false, false, false);
|
|
|
|
@ -286,16 +309,16 @@ public class RWFPDialog extends JFrame implements ActionListener {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询部分
|
|
|
|
|
private JPanel getBottomPanel() {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
JPanel bottomPanel = new JPanel();
|
|
|
|
|
bottomPanel.setLayout(new PropertyLayout());
|
|
|
|
|
bottomPanel.add("1.1.left.center", new JLabel(" "));
|
|
|
|
|
bottomPanel.add("1.2.left.center", yyButton);
|
|
|
|
|
bottomPanel.add("1.3.left.center", new JLabel(" "));
|
|
|
|
|
bottomPanel.add("1.4.left.center", gbButton);
|
|
|
|
|
return bottomPanel;
|
|
|
|
|
}
|
|
|
|
|
private JPanel getBottomPanel() {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
JPanel bottomPanel = new JPanel();
|
|
|
|
|
bottomPanel.setLayout(new PropertyLayout());
|
|
|
|
|
bottomPanel.add("1.1.left.center", new JLabel(" "));
|
|
|
|
|
bottomPanel.add("1.2.left.center", yyButton);
|
|
|
|
|
bottomPanel.add("1.3.left.center", new JLabel(" "));
|
|
|
|
|
bottomPanel.add("1.4.left.center", gbButton);
|
|
|
|
|
return bottomPanel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JScrollPane getTablePanel() {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
@ -310,12 +333,12 @@ public class RWFPDialog extends JFrame implements ActionListener {
|
|
|
|
|
for (Entry<Integer, String> map : lovPositionMap.entrySet()) {
|
|
|
|
|
JComboBox<String> jComboBox = new JComboBox<String>();
|
|
|
|
|
String value = map.getValue();
|
|
|
|
|
if(value.contains(",")) {
|
|
|
|
|
if (value.contains(",")) {
|
|
|
|
|
String[] split = value.split(",");
|
|
|
|
|
for (int i = 0; i < split.length; i++) {
|
|
|
|
|
jComboBox.addItem(split[i]);
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
jComboBox.addItem(value);
|
|
|
|
|
}
|
|
|
|
|
table.getColumnModel().getColumn(map.getKey()).setCellEditor(new DefaultCellEditor(jComboBox));
|
|
|
|
@ -365,10 +388,10 @@ public class RWFPDialog extends JFrame implements ActionListener {
|
|
|
|
|
dtm1 = new DefaultTableModel(values, titleNames) {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isCellEditable(int row, int column) {
|
|
|
|
|
if(canWriteColume.size() > 0) {
|
|
|
|
|
if (canWriteColume.size() > 0) {
|
|
|
|
|
for (int i = 0; i < canWriteColume.size(); i++) {
|
|
|
|
|
if(canWriteColume.get(i) == column) {
|
|
|
|
|
System.out.println("row=========="+row);
|
|
|
|
|
if (canWriteColume.get(i) == column) {
|
|
|
|
|
System.out.println("row==========" + row);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -389,32 +412,31 @@ public class RWFPDialog extends JFrame implements ActionListener {
|
|
|
|
|
|
|
|
|
|
if (source.equals(this.gbButton)) {
|
|
|
|
|
dispose();
|
|
|
|
|
}
|
|
|
|
|
else if(source.equals(this.yyButton)){
|
|
|
|
|
//保存数据
|
|
|
|
|
} else if (source.equals(this.yyButton)) {
|
|
|
|
|
// 保存数据
|
|
|
|
|
Connection conn = getConn();
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
for(int i = 0; i < table.getRowCount(); i++){
|
|
|
|
|
for (int i = 0; i < table.getRowCount(); i++) {
|
|
|
|
|
StringBuilder updateSql = new StringBuilder();
|
|
|
|
|
updateSql.append("update LY_CHANGETASSKFORM_DETAILS set ");
|
|
|
|
|
for (Entry<String, Integer> map : positionFieldMap.entrySet()) {
|
|
|
|
|
updateSql.append(map.getKey());
|
|
|
|
|
String valueAt = (String)table.getValueAt(i,map.getValue());
|
|
|
|
|
if(valueAt == null || valueAt.isEmpty()) {
|
|
|
|
|
String valueAt = (String) table.getValueAt(i, map.getValue());
|
|
|
|
|
if (valueAt == null || valueAt.isEmpty()) {
|
|
|
|
|
updateSql.append("=");
|
|
|
|
|
updateSql.append("null,");
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
updateSql.append("='");
|
|
|
|
|
updateSql.append(table.getValueAt(i,map.getValue()));
|
|
|
|
|
updateSql.append(table.getValueAt(i, map.getValue()));
|
|
|
|
|
updateSql.append("',");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//去掉最后一个,
|
|
|
|
|
// 去掉最后一个,
|
|
|
|
|
updateSql.deleteCharAt(updateSql.length() - 1);
|
|
|
|
|
updateSql.append(" where ID='"+id+"' and XH='"+table.getValueAt(i,0)+"'");
|
|
|
|
|
updateSql.append(" where ID='" + id + "' and XH='" + table.getValueAt(i, 0) + "'");
|
|
|
|
|
try {
|
|
|
|
|
stmt = conn.prepareStatement(updateSql.toString());
|
|
|
|
|
System.out.println("updateSql========="+updateSql.toString());
|
|
|
|
|
System.out.println("updateSql=========" + updateSql.toString());
|
|
|
|
|
stmt.execute();
|
|
|
|
|
} catch (SQLException e1) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
@ -423,149 +445,147 @@ public class RWFPDialog extends JFrame implements ActionListener {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if(stmt != null) {
|
|
|
|
|
if (stmt != null) {
|
|
|
|
|
stmt.close();
|
|
|
|
|
}
|
|
|
|
|
if(conn != null) {
|
|
|
|
|
if (conn != null) {
|
|
|
|
|
conn.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e1) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e1.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}else if(source.equals(this.tzsjButton)){
|
|
|
|
|
} else if (source.equals(this.tzsjButton)) {
|
|
|
|
|
gsPrefTopLine = new ArrayList<String>();
|
|
|
|
|
String selectedItem = (String)cfdJComboBox.getSelectedItem();
|
|
|
|
|
if(selectedItem == null || selectedItem.isEmpty()) {
|
|
|
|
|
String selectedItem = (String) cfdJComboBox.getSelectedItem();
|
|
|
|
|
if (selectedItem == null || selectedItem.isEmpty()) {
|
|
|
|
|
MessageBox.post("请选择触发等级!", "提示", 2);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Date date = cfsjButton.getDate();
|
|
|
|
|
|
|
|
|
|
if(date == null) {
|
|
|
|
|
if (date == null) {
|
|
|
|
|
MessageBox.post("请选择触发时间!", "提示", 2);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String cfsjDate = dateFormat.format(date);
|
|
|
|
|
String pref = cfdjPref.get(selectedItem);
|
|
|
|
|
if(pref == null || pref.isEmpty()) {
|
|
|
|
|
if (pref == null || pref.isEmpty()) {
|
|
|
|
|
MessageBox.post("未配置触发等级相关的首选项!", "提示", 2);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String[] calculateTime = session.getPreferenceService().getStringValues(pref);
|
|
|
|
|
if (calculateTime == null || calculateTime.length <= 0) {
|
|
|
|
|
MessageBox.post("请配置首选项“"+pref+"”", "提示 ", MessageBox.INFORMATION);
|
|
|
|
|
MessageBox.post("请配置首选项“" + pref + "”", "提示 ", MessageBox.INFORMATION);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < calculateTime.length; i++) {
|
|
|
|
|
String[] split = calculateTime[i].split("\\|");
|
|
|
|
|
if(i == 0) {
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < split.length; j++) {
|
|
|
|
|
gsPrefTopLine.add(split[j]);
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
gsPrefMap.put(split[0],calculateTime[i]);
|
|
|
|
|
} else {
|
|
|
|
|
gsPrefMap.put(split[0], calculateTime[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println(positionFieldMap+"==================positionFieldMap");
|
|
|
|
|
System.out.println("gsPrefTopLine----------------"+gsPrefTopLine.size());
|
|
|
|
|
System.out.println(positionFieldMap + "==================positionFieldMap");
|
|
|
|
|
System.out.println("gsPrefTopLine----------------" + gsPrefTopLine.size());
|
|
|
|
|
Integer xh = positionFieldMap.get(gsPrefTopLine.get(0));
|
|
|
|
|
//表里table 开始计算
|
|
|
|
|
for(int i = 0; i < table.getRowCount(); i++){
|
|
|
|
|
String xhStr = table.getValueAt(i, xh).toString();
|
|
|
|
|
String gsStr = gsPrefMap.get(xhStr);
|
|
|
|
|
if(gsStr != null && !gsStr.isEmpty() ) {
|
|
|
|
|
String[] split = gsStr.split("\\|");
|
|
|
|
|
for (int j = 1; j < gsPrefTopLine.size(); j++) {
|
|
|
|
|
//如果有值
|
|
|
|
|
System.out.println("gsPrefTopLine.get(j)========"+gsPrefTopLine.get(j));
|
|
|
|
|
Integer colume = positionFieldMap.get(gsPrefTopLine.get(j));
|
|
|
|
|
if(colume != null) {
|
|
|
|
|
System.out.println(positionFieldMap.get(gsPrefTopLine.get(j))+"=================positionFieldMap.get(gsPrefTopLine.get(j))");
|
|
|
|
|
//处理公式
|
|
|
|
|
String gs = split[j];
|
|
|
|
|
System.out.println("gs========"+gs);
|
|
|
|
|
if(gs.equals("N")) {
|
|
|
|
|
table.setValueAt(cfsjDate,i, colume);
|
|
|
|
|
}else {
|
|
|
|
|
String[] split2 = gs.split("N");
|
|
|
|
|
String time = calculateDate(cfsjDate, Integer.parseInt(split2[1]));
|
|
|
|
|
System.out.println("time============"+time);
|
|
|
|
|
table.setValueAt(time,i, colume);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 表里table 开始计算
|
|
|
|
|
for (int i = 0; i < table.getRowCount(); i++) {
|
|
|
|
|
String xhStr = table.getValueAt(i, xh).toString();
|
|
|
|
|
String gsStr = gsPrefMap.get(xhStr);
|
|
|
|
|
if (gsStr != null && !gsStr.isEmpty()) {
|
|
|
|
|
String[] split = gsStr.split("\\|");
|
|
|
|
|
for (int j = 1; j < gsPrefTopLine.size(); j++) {
|
|
|
|
|
// 如果有值
|
|
|
|
|
System.out.println("gsPrefTopLine.get(j)========" + gsPrefTopLine.get(j));
|
|
|
|
|
Integer colume = positionFieldMap.get(gsPrefTopLine.get(j));
|
|
|
|
|
if (colume != null) {
|
|
|
|
|
System.out.println(positionFieldMap.get(gsPrefTopLine.get(j))
|
|
|
|
|
+ "=================positionFieldMap.get(gsPrefTopLine.get(j))");
|
|
|
|
|
// 处理公式
|
|
|
|
|
String gs = split[j];
|
|
|
|
|
System.out.println("gs========" + gs);
|
|
|
|
|
if (gs.equals("N")) {
|
|
|
|
|
table.setValueAt(cfsjDate, i, colume);
|
|
|
|
|
} else {
|
|
|
|
|
String[] split2 = gs.split("N");
|
|
|
|
|
String time = calculateDate(cfsjDate, Integer.parseInt(split2[1]));
|
|
|
|
|
System.out.println("time============" + time);
|
|
|
|
|
table.setValueAt(time, i, colume);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//调用应用按钮
|
|
|
|
|
yyButton.doClick();
|
|
|
|
|
MessageBox.post("调整时间完成!", "提示", 2);
|
|
|
|
|
}
|
|
|
|
|
// 调用应用按钮
|
|
|
|
|
yyButton.doClick();
|
|
|
|
|
MessageBox.post("调整时间完成!", "提示", 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取数据库连接
|
|
|
|
|
public static Connection getConn() {
|
|
|
|
|
Connection conn = null;
|
|
|
|
|
try {
|
|
|
|
|
conn = DbPool.getConnection(dateConnList.get(0), dateConnList.get(1));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return conn;
|
|
|
|
|
public static Connection getConn() {
|
|
|
|
|
Connection conn = null;
|
|
|
|
|
try {
|
|
|
|
|
conn = DbPool.getConnection(dateConnList.get(0), dateConnList.get(1));
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return conn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String calculateDate(String dateString, int daysToAdd) {
|
|
|
|
|
// 定义日期格式
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
|
|
|
|
|
public static String calculateDate(String dateString, int daysToAdd) {
|
|
|
|
|
// 定义日期格式
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
|
|
|
|
|
// 解析输入的日期字符串
|
|
|
|
|
LocalDate date;
|
|
|
|
|
try {
|
|
|
|
|
date = LocalDate.parse(dateString, formatter);
|
|
|
|
|
} catch (DateTimeParseException e) {
|
|
|
|
|
throw new IllegalArgumentException("Invalid date format. Please use yyyy-MM-dd.", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 增加或减少天数
|
|
|
|
|
LocalDate resultDate = date.plusDays(daysToAdd);
|
|
|
|
|
|
|
|
|
|
// 格式化结果日期为字符串
|
|
|
|
|
return resultDate.format(formatter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String validateAndFormatDate(String input) {
|
|
|
|
|
// 定义输入和输出的日期格式
|
|
|
|
|
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S");
|
|
|
|
|
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 尝试解析输入的日期时间字符串
|
|
|
|
|
LocalDateTime dateTime = LocalDateTime.parse(input, inputFormatter);
|
|
|
|
|
|
|
|
|
|
// 转换为只包含日期的LocalDate对象
|
|
|
|
|
LocalDate date = dateTime.toLocalDate();
|
|
|
|
|
|
|
|
|
|
// 格式化结果日期为字符串
|
|
|
|
|
return date.format(outputFormatter);
|
|
|
|
|
} catch (DateTimeParseException e) {
|
|
|
|
|
// 如果解析失败,说明输入不符合指定格式,返回原始字符串
|
|
|
|
|
return input;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 解析输入的日期字符串
|
|
|
|
|
LocalDate date;
|
|
|
|
|
try {
|
|
|
|
|
date = LocalDate.parse(dateString, formatter);
|
|
|
|
|
} catch (DateTimeParseException e) {
|
|
|
|
|
throw new IllegalArgumentException("Invalid date format. Please use yyyy-MM-dd.", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 增加或减少天数
|
|
|
|
|
LocalDate resultDate = date.plusDays(daysToAdd);
|
|
|
|
|
|
|
|
|
|
// 格式化结果日期为字符串
|
|
|
|
|
return resultDate.format(formatter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String validateAndFormatDate(String input) {
|
|
|
|
|
// 定义输入和输出的日期格式
|
|
|
|
|
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S");
|
|
|
|
|
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 尝试解析输入的日期时间字符串
|
|
|
|
|
LocalDateTime dateTime = LocalDateTime.parse(input, inputFormatter);
|
|
|
|
|
|
|
|
|
|
// 转换为只包含日期的LocalDate对象
|
|
|
|
|
LocalDate date = dateTime.toLocalDate();
|
|
|
|
|
|
|
|
|
|
// 格式化结果日期为字符串
|
|
|
|
|
return date.format(outputFormatter);
|
|
|
|
|
} catch (DateTimeParseException e) {
|
|
|
|
|
// 如果解析失败,说明输入不符合指定格式,返回原始字符串
|
|
|
|
|
return input;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|