|
|
@@ -3,26 +3,33 @@ package platform.common.util.holiday;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
public class HolidayExcelParser {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(HolidayExcelParser.class);
|
|
|
|
|
|
- public static String parse(List<ArrayList<String>> readExcel) {
|
|
|
+ public static Map<String, String> parse(List<ArrayList<String>> readExcel) {
|
|
|
+ Map<String, String> mapRet = new HashMap<>();
|
|
|
+
|
|
|
String ret = "{";
|
|
|
// 逐行变换
|
|
|
// {"0101":2,"0102":2,"0103":2,
|
|
|
for (int i = 0; i < readExcel.size(); i++) {
|
|
|
+ Map<String, String> mapRowParseRet = parse1Row(readExcel.get(i));
|
|
|
+ if ("false".equals(mapRowParseRet.get("valid"))){
|
|
|
+ mapRet.put("valid","false");
|
|
|
+ mapRet.put("errMsg", "err: 第" + (i + 1 ) + "行有错误:" + mapRowParseRet.get("errMsg"));
|
|
|
+ return mapRet;
|
|
|
+ }
|
|
|
|
|
|
- String str1Row = parse1Row(readExcel.get(i));
|
|
|
-
|
|
|
- if ("".equals(str1Row))
|
|
|
+ if ("".equals(mapRowParseRet.get("data")))
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- ret += str1Row;
|
|
|
+ ret += mapRowParseRet.get("data");
|
|
|
|
|
|
ret += ",";
|
|
|
}
|
|
|
@@ -30,21 +37,60 @@ public class HolidayExcelParser {
|
|
|
ret = ret.substring(0,ret.length()-1);
|
|
|
|
|
|
ret += "}";
|
|
|
- return ret;
|
|
|
+
|
|
|
+ mapRet.put("valid","true");
|
|
|
+ mapRet.put("data",ret);
|
|
|
+ return mapRet;
|
|
|
}
|
|
|
|
|
|
- private static String parse1Row(ArrayList<String> strings) {
|
|
|
- String ret = "";
|
|
|
- if (null == strings.get(1) || "".equals(strings.get(1)))
|
|
|
+ private static Map<String, String> parse1Row(ArrayList<String> strListRow) {
|
|
|
+ Map<String, String> mapRet = new HashMap<>();
|
|
|
+ String retData = "";
|
|
|
+ if (null == strListRow.get(1) || "".equals(strListRow.get(1)))
|
|
|
{
|
|
|
- return ret;
|
|
|
+ mapRet.put("valid","true");
|
|
|
+ mapRet.put("data",retData);
|
|
|
+ return mapRet;
|
|
|
}
|
|
|
|
|
|
- ret += "\"" + parse1RowDayInfo(strings.get(1)) + "\"";
|
|
|
- ret += ":" + parse1RowHolidayType(strings.get(2));
|
|
|
+ Map<String, String> mapCheck = checkRowData(strListRow);
|
|
|
|
|
|
+ if ("false".equals(mapCheck.get("valid")))
|
|
|
+ {
|
|
|
+ mapRet.put("valid","false");
|
|
|
+ mapRet.put("errMsg",mapCheck.get("errMsg"));
|
|
|
+ return mapRet;
|
|
|
+ }
|
|
|
|
|
|
- return ret;
|
|
|
+ retData += "\"" + parse1RowDayInfo(strListRow.get(1)) + "\"";
|
|
|
+ retData += ":" + parse1RowHolidayType(strListRow.get(2));
|
|
|
+
|
|
|
+ mapRet.put("valid","true");
|
|
|
+ mapRet.put("data",retData);
|
|
|
+ return mapRet;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String, String> checkRowData(ArrayList<String> strListRow) {
|
|
|
+ Map<String, String> mapRet = new HashMap<>();
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ try {
|
|
|
+ Date dtTemp = simpleDateFormat.parse(strListRow.get(1));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ mapRet.put("valid","false");
|
|
|
+ mapRet.put("errMsg","日期格式错误!");
|
|
|
+ return mapRet;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!"1".equals(strListRow.get(2)) && !"2".equals(strListRow.get(2)))
|
|
|
+ {
|
|
|
+ mapRet.put("valid","false");
|
|
|
+ mapRet.put("errMsg","假日类型错误!只能是”1“或”2“");
|
|
|
+ return mapRet;
|
|
|
+ }
|
|
|
+
|
|
|
+ mapRet.put("valid","true");
|
|
|
+ return mapRet;
|
|
|
}
|
|
|
|
|
|
private static String parse1RowHolidayType(String s) {
|
|
|
@@ -52,7 +98,6 @@ public class HolidayExcelParser {
|
|
|
}
|
|
|
|
|
|
private static String parse1RowDayInfo(String s) {
|
|
|
-
|
|
|
return s.substring(5,7) + s.substring(8,10);
|
|
|
}
|
|
|
}
|