Index: ssts-recyclingrecord/src/main/java/com/forgon/disinfectsystem/recyclingrecord/action/RecyclingRecordAction.java =================================================================== diff -u -r32894 -r32897 --- ssts-recyclingrecord/src/main/java/com/forgon/disinfectsystem/recyclingrecord/action/RecyclingRecordAction.java (.../RecyclingRecordAction.java) (revision 32894) +++ ssts-recyclingrecord/src/main/java/com/forgon/disinfectsystem/recyclingrecord/action/RecyclingRecordAction.java (.../RecyclingRecordAction.java) (revision 32897) @@ -3822,11 +3822,26 @@ JSONArray arr = JSONArray.fromObject(configStr); SimpleDateFormat yearToDay = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = Calendar.getInstance(); //创建Calendar 的实例 - calendar.add(Calendar.DAY_OF_MONTH,-1); - String startDateStr = yearToDay.format(new Date(calendar.getTimeInMillis())) + " " + arr.get(0).toString(); - String endDateStr = yearToDay.format(new Date()) + " " + arr.get(1).toString(); + String startDateStr = null; + String endDateStr = null; SimpleDateFormat yearToMinutes = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - long newDateTime = new Date().getTime(); + Date newDate = new Date(); + calendar.setTime(newDate); + if(isWeekend(newDate)){ + calendar.add(Calendar.DAY_OF_MONTH,-1); + newDate = calendar.getTime(); + if(isWeekend(calendar.getTime())){ + calendar.add(Calendar.DAY_OF_MONTH,-1); + newDate = calendar.getTime(); + } + startDateStr = yearToDay.format(newDate) + " " + arr.get(0).toString(); + newDate = yearToMinutes.parse(startDateStr); + } + reduceToNotWeek(calendar); + startDateStr = yearToDay.format(new Date(calendar.getTimeInMillis())) + " " + arr.get(0).toString(); + endDateStr = yearToDay.format(newDate) + " " + arr.get(1).toString(); + + long newDateTime = newDate.getTime(); Double outTime = Double.valueOf(outTimeInt); Date endDate = yearToMinutes.parse(endDateStr); Date startDate = yearToMinutes.parse(startDateStr); @@ -3841,7 +3856,7 @@ if(b.compareTo(0.00) <= 0){ outTime = restTime*60*60*1000; }else{ - calendar.add(Calendar.DAY_OF_MONTH,-1); + reduceToNotWeek(calendar); startDateStr = yearToDay.format(new Date(calendar.getTimeInMillis())) + " " + arr.get(0).toString(); startDate = yearToMinutes.parse(startDateStr); newDateTime = startDate.getTime(); @@ -3858,6 +3873,33 @@ } return returnDate; } + /** + * 日期减一天,减到不是周末为止 + * @param calendar + * @return + */ + private Calendar reduceToNotWeek(Calendar calendar){ + calendar.add(Calendar.DAY_OF_MONTH,-1); + if(isWeekend(calendar.getTime())){ + calendar.add(Calendar.DAY_OF_MONTH,-1); + if(isWeekend(calendar.getTime())){ + calendar.add(Calendar.DAY_OF_MONTH,-1); + } + } + return calendar; + } + /** + * 判断日期是不是周末 + * @param date + * @return + */ + private boolean isWeekend(Date date) { + boolean isWeekend = false; + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + isWeekend = cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY; + return isWeekend; + } public void updateTousseItemTimeoutProcessType(){ JSONObject result = JSONUtil.buildJsonObject(false); Long id = StrutsParamUtils.getPraramLongValue("id", null);