|
@@ -8,10 +8,14 @@ import java.io.ByteArrayOutputStream;
|
|
|
import java.io.InputStream;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
+import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.Period;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* zian Y
|
|
@@ -23,7 +27,7 @@ public class SettlementUtil {
|
|
|
public static String getFileNameNoEx(String filename) {
|
|
|
if ((filename != null) && (filename.length() > 0)) {
|
|
|
int dot = filename.lastIndexOf('.');
|
|
|
- if ((dot >-1) && (dot < (filename.length()))) {
|
|
|
+ if ((dot > -1) && (dot < (filename.length()))) {
|
|
|
return filename.substring(0, dot);
|
|
|
}
|
|
|
}
|
|
@@ -33,12 +37,13 @@ public class SettlementUtil {
|
|
|
/**
|
|
|
* 格式:123456-1
|
|
|
* 截取 账户 id
|
|
|
+ *
|
|
|
* @param str
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String subAccountName(String str){
|
|
|
- if (!Check.isNull(str)){
|
|
|
- if (str.contains("-")){
|
|
|
+ public static String subAccountName(String str) {
|
|
|
+ if (!Check.isNull(str)) {
|
|
|
+ if (str.contains("-")) {
|
|
|
return str.substring(0, str.indexOf("-"));
|
|
|
}
|
|
|
}
|
|
@@ -50,11 +55,11 @@ public class SettlementUtil {
|
|
|
/**
|
|
|
* @Description: 忽略null值/只拷贝非null属性
|
|
|
*/
|
|
|
- public static String[] getNullPropertyNames (Object source) {
|
|
|
+ public static String[] getNullPropertyNames(Object source) {
|
|
|
final BeanWrapper src = new BeanWrapperImpl(source);
|
|
|
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
|
|
|
Set<String> emptyNames = new HashSet<String>();
|
|
|
- for(java.beans.PropertyDescriptor pd : pds) {
|
|
|
+ for (java.beans.PropertyDescriptor pd : pds) {
|
|
|
Object srcValue = src.getPropertyValue(pd.getName());
|
|
|
if (srcValue == null) emptyNames.add(pd.getName());
|
|
|
}
|
|
@@ -63,9 +68,9 @@ public class SettlementUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 获取网络图片转成字节流
|
|
|
+ *
|
|
|
* @param strUrl 完整图片地址
|
|
|
* @return 图片资源数组
|
|
|
*/
|
|
@@ -89,13 +94,14 @@ public class SettlementUtil {
|
|
|
|
|
|
/**
|
|
|
* 从输入流中获取字节流数据
|
|
|
+ *
|
|
|
* @param inStream 输入流
|
|
|
- * @return 图片流
|
|
|
+ * @return 图片流
|
|
|
*/
|
|
|
private static byte[] readInputStream(InputStream inStream) throws Exception {
|
|
|
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
|
|
// 设置每次读取缓存区大小
|
|
|
- byte[] buffer = new byte[1024*10];
|
|
|
+ byte[] buffer = new byte[1024 * 10];
|
|
|
int len = 0;
|
|
|
while ((len = inStream.read(buffer)) != -1) {
|
|
|
outStream.write(buffer, 0, len);
|
|
@@ -106,10 +112,11 @@ public class SettlementUtil {
|
|
|
|
|
|
/**
|
|
|
* 获取日期的年月
|
|
|
+ *
|
|
|
* @param strDate
|
|
|
* @return
|
|
|
*/
|
|
|
- public static int getYearMonth(String strDate)throws Exception{
|
|
|
+ public static int getYearMonth(String strDate) throws Exception {
|
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Date date = simpleDateFormat.parse(strDate);
|
|
@@ -117,23 +124,23 @@ public class SettlementUtil {
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
cal.setTime(date);//设置时间
|
|
|
int year = cal.get(Calendar.YEAR);//获取年份
|
|
|
- int month=cal.get(Calendar.MONTH);//获取月份
|
|
|
- return year*100+month;//返回年份乘以100加上月份的值,因为月份最多2位数,所以年份乘以100可以获取一个唯一的年月数值
|
|
|
+ int month = cal.get(Calendar.MONTH);//获取月份
|
|
|
+ return year * 100 + month;//返回年份乘以100加上月份的值,因为月份最多2位数,所以年份乘以100可以获取一个唯一的年月数值
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 判断当前时间是否在[startTime, endTime]区间
|
|
|
* 年-月 2021-08
|
|
|
- * @param nowStrTime 当前时间
|
|
|
+ *
|
|
|
+ * @param nowStrTime 当前时间
|
|
|
* @param startStrTime 开始时间
|
|
|
- * @param endStrTime 结束时间
|
|
|
+ * @param endStrTime 结束时间
|
|
|
* @return
|
|
|
* @author zian Y
|
|
|
*/
|
|
|
public static boolean isEffectiveDate(String nowStrTime, String startStrTime, String endStrTime) throws Exception {
|
|
|
- // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
|
|
|
Date nowTime = simpleDateFormat.parse(nowStrTime);
|
|
|
Date startTime = simpleDateFormat.parse(startStrTime);
|
|
@@ -157,18 +164,13 @@ public class SettlementUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
public static long DateCompare(String s1, String s2) {
|
|
|
try {
|
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Date d1 = simpleDateFormat.parse(s1);
|
|
|
Date d2 = simpleDateFormat.parse(s2);
|
|
|
- // LocalDateTime d1 = LocalDateTime.parse(s1, DateTimeFormatter.ISO_LOCAL_DATE);
|
|
|
+ // LocalDateTime d1 = LocalDateTime.parse(s1, DateTimeFormatter.ISO_LOCAL_DATE);
|
|
|
//LocalDateTime d2 = LocalDateTime.parse(s2, DateTimeFormatter.ISO_LOCAL_DATE);
|
|
|
//排序规则
|
|
|
return ((d1.getTime()) - (d2.getTime()));
|
|
@@ -178,30 +180,30 @@ public class SettlementUtil {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- public static List<String> sortlistTest(List<String> list){
|
|
|
+ public static List<String> sortlistTest(List<String> list) {
|
|
|
//去重
|
|
|
List<String> newlist = new ArrayList<String>();
|
|
|
- for(int i=0; i<list.size(); i++){
|
|
|
- if(!newlist.contains(list.get(i))){
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ if (!newlist.contains(list.get(i))) {
|
|
|
newlist.add(list.get(i));
|
|
|
}
|
|
|
}
|
|
|
String tmp;
|
|
|
- for(int i=1; i<newlist.size(); i++){
|
|
|
+ for (int i = 1; i < newlist.size(); i++) {
|
|
|
tmp = newlist.get(i);
|
|
|
- int j=i-1;
|
|
|
- for(; j>=0&&(DateCompare(tmp, newlist.get(j))<0); j--){
|
|
|
- newlist.set(j+1, newlist.get(j));
|
|
|
+ int j = i - 1;
|
|
|
+ for (; j >= 0 && (DateCompare(tmp, newlist.get(j)) < 0); j--) {
|
|
|
+ newlist.set(j + 1, newlist.get(j));
|
|
|
}
|
|
|
- newlist.set(j+1, tmp);
|
|
|
+ newlist.set(j + 1, tmp);
|
|
|
}
|
|
|
return newlist;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 获取 两个日期之间的所有 日期
|
|
|
+ *
|
|
|
* @param startDate
|
|
|
* @param endDate
|
|
|
* @return
|
|
@@ -209,7 +211,7 @@ public class SettlementUtil {
|
|
|
public static List<String> getAllDatesOfTwoTimes(String startDate, String endDate) {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
List<String> dateList = new ArrayList<String>();
|
|
|
- try{
|
|
|
+ try {
|
|
|
Date dateOne = sdf.parse(startDate);
|
|
|
Date dateTwo = sdf.parse(endDate);
|
|
|
|
|
@@ -217,17 +219,131 @@ public class SettlementUtil {
|
|
|
calendar.setTime(dateOne);
|
|
|
|
|
|
dateList.add(startDate);
|
|
|
- while(calendar.getTime().before(dateTwo)){ //倒序时间,顺序after改before其他相应的改动。
|
|
|
+ while (calendar.getTime().before(dateTwo)) { //倒序时间,顺序after改before其他相应的改动。
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
dateList.add(sdf.format(calendar.getTime()));
|
|
|
}
|
|
|
- } catch(Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return dateList;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public static List<Map<String, String>> getTime( List<String> list) {
|
|
|
+ //初始化list,且该list中的日期是升序的。
|
|
|
+ //List<String> list = Arrays.asList("2020-11-19","2020-11-20","2020-11-21","2021-07-20");
|
|
|
+ /* List<String> list = Arrays.asList("2021-07-02", "2021-07-03", "2021-07-04", "2021-07-06",
|
|
|
+ "2021-07-07", "2021-07-08", "2021-07-09", "2021-07-11", "2021-07-12",
|
|
|
+ "2021-07-13", "2021-07-14", "2021-07-16", "2021-07-17", "2021-07-18",
|
|
|
+ "2021-07-19", "2021-07-20", "2021-07-21", "2021-07-22", "2021-07-23",
|
|
|
+ "2021-07-24", "2021-07-25", "2021-07-26", "2021-07-27", "2021-07-28",
|
|
|
+ "2021-07-29", "2021-07-30");
|
|
|
+ */
|
|
|
+ List<Map<String, String>> arrayList = new ArrayList<>();
|
|
|
+ int num = 0;
|
|
|
+ for (int i = 0; i < list.size(); i = num) {
|
|
|
+ String start = list.get(i);
|
|
|
+ String end = "";
|
|
|
+ if (i == list.size() - 1) {
|
|
|
+ end = start;
|
|
|
+ }
|
|
|
+ int n = 0;
|
|
|
+ for (int j = i + 1; j < list.size(); j++) {
|
|
|
+ //判断当前日期的后一天与list中该元素的下一个元素是否相等
|
|
|
+ if (getSpecifiedDayAfter(list.get(j - 1)).equals(list.get(j))) {
|
|
|
+ end = list.get(j);
|
|
|
+ n++;
|
|
|
+ num++;
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ //list中该元素不是连续的
|
|
|
+ if (n == 0) {
|
|
|
+ end = list.get(j - 1);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ num = num + 1;
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("startDate", start);
|
|
|
+ map.put("endDate", end);
|
|
|
+ arrayList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ // System.out.println(arrayList);
|
|
|
+ return arrayList;
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前日期的后一天
|
|
|
+ * @param specifiedDay
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String getSpecifiedDayAfter(String specifiedDay) {
|
|
|
+ Calendar c = Calendar.getInstance();
|
|
|
+ Date date = null;
|
|
|
+ try {
|
|
|
+ date = new SimpleDateFormat("yyyy-MM-dd").parse(specifiedDay);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ c.setTime(date);
|
|
|
+ int day = c.get(Calendar.DATE);
|
|
|
+ c.set(Calendar.DATE, day + 1);
|
|
|
+ String dayAfter = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
|
|
|
+ return dayAfter;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ List list = new ArrayList();
|
|
|
+
|
|
|
+
|
|
|
+ Map map1 = new HashMap();
|
|
|
+ map1.put("startTime","2021-07-01");
|
|
|
+ map1.put("endTime","2021-07-05");
|
|
|
+
|
|
|
+ Map map2 = new HashMap();
|
|
|
+ map2.put("startTime","2021-07-10");
|
|
|
+ map2.put("endTime","2021-07-15");
|
|
|
+
|
|
|
+
|
|
|
+ list.add("2021-07-01");
|
|
|
+ list.add("2021-07-02");
|
|
|
+ //list.add("2021-07-03");
|
|
|
+ list.add("2021-07-04");
|
|
|
+ list.add("2021-07-05");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 获取两个日期之间 所有的 时间 年-月-日
|
|
|
+ List<String> betweenDaysList = SettlementUtil.getAllDatesOfTwoTimes("2021-07-01","2021-07-10");
|
|
|
+
|
|
|
+ List<Object> times = SettlementUtil.sortlistTest(list);
|
|
|
+
|
|
|
+ //差集
|
|
|
+ List<String> reduceList = betweenDaysList.stream().filter(item -> !times.contains(item)).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ System.out.println(betweenDaysList);
|
|
|
+ System.out.println(times);
|
|
|
+ System.out.println(reduceList);
|
|
|
+
|
|
|
+ List<Map<String, String>> stringList = SettlementUtil.getTime(reduceList);
|
|
|
+
|
|
|
+ System.out.println(stringList);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|