optimize pay fee detail to month
| | |
| | | public static final String DATE_FORMATE_STRING_M = "yyyyMM"; |
| | | public static final String DATE_FORMATE_STRING_N = "HHmmss"; |
| | | public static final String DATE_FORMATE_STRING_O = "yyyyMMddHHmm"; |
| | | public static final String DATE_FORMATE_STRING_Q = "yyyy-MM"; |
| | | |
| | | |
| | | |
| | | static { |
| | |
| | | formats.put("yyyyMM", new SimpleDateFormat("yyyyMM")); |
| | | formats.put("HHmmss", new SimpleDateFormat("HHmmss")); |
| | | formats.put("yyyyMMddHHmm", new SimpleDateFormat("yyyyMMddHHmm")); |
| | | formats.put("yyyy-MM", new SimpleDateFormat("yyyy-MM")); |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | * @return:list |
| | | */ |
| | | public static List<String> getMonthBetweenDate(String startTime, String endTime) { |
| | | SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMATE_STRING_M); |
| | | SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMATE_STRING_Q); |
| | | // 声明保存日期集合 |
| | | List<String> list = new ArrayList<>(); |
| | | try { |
| | |
| | | import junit.framework.TestSuite; |
| | | |
| | | import java.util.Calendar; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Unit test for simple App. |
| | |
| | | */ |
| | | public void testApp() |
| | | { |
| | | Calendar today = Calendar.getInstance(); |
| | | today.setTime(DateUtil.getDateFromStringB("2022-12-26")); |
| | | int week = today.get(Calendar.WEEK_OF_MONTH); |
| | | int curDay = today.get(Calendar.DAY_OF_WEEK); |
| | | String startTime = "2023-03-02 04:00:00"; |
| | | String endTime = "2024-01-01 00:00:00"; |
| | | |
| | | //一周第一天是否为星期天 |
| | | boolean isFirstSunday = (today.getFirstDayOfWeek() == Calendar.SUNDAY); |
| | | //获取周几 |
| | | //若一周第一天为星期天,则-1 |
| | | if (isFirstSunday) { |
| | | curDay = curDay - 1; |
| | | if (curDay == 0) { |
| | | curDay = 7; |
| | | } |
| | | |
| | | List<String> months = DateUtil.getMonthBetweenDate(startTime,endTime); |
| | | |
| | | for(String month : months) { |
| | | System.out.println(month); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | |
| | | Map<String, MonthFeeDetailDto> monthFeeDetailDtos = new HashMap<>(); |
| | | |
| | | for (FeeDetailDto feeDetailDto : feeDetailDtos) { |
| | | Date endTime = feeDetailDto.getEndTime(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(endTime); |
| | | calendar.add(Calendar.DAY_OF_MONTH,-1); |
| | | if(feeDetailDto.getStartTime().getTime()< calendar.getTime().getTime()){ |
| | | endTime = calendar.getTime(); |
| | | } |
| | | //计算两个日期包含的月份 |
| | | List<String> months = DateUtil.getMonthBetweenDate(feeDetailDto.getStartTime(), feeDetailDto.getEndTime()); |
| | | List<String> months = DateUtil.getMonthBetweenDate(feeDetailDto.getStartTime(), endTime); |
| | | |
| | | if (months == null || months.size() < 1) { |
| | | putReceivedAmountToMonthFeeDetailDtos(monthFeeDetailDtos, |
| | | DateUtil.getFormatTimeString(feeDetailDto.getStartTime(), DateUtil.DATE_FORMATE_STRING_M), |
| | | DateUtil.getFormatTimeString(feeDetailDto.getStartTime(), DateUtil.DATE_FORMATE_STRING_Q), |
| | | Double.parseDouble(feeDetailDto.getReceivedAmount()), |
| | | feeDetailDto); |
| | | continue; |