|
@@ -481,10 +481,11 @@ public class SceneService extends ServiceImpl<SceneMapper, SceneEntity> {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public List<Map<String,Object>> selectYearAlarmTimes(@Param("scene") SceneEntity sceneEntity, @Param("startDate") String startDate, @Param("endDate") String endDate,@Param("sort") int sort){
|
|
|
+ public List<Map<String,Object>> selectYearAlarmTimes(@Param("scene") SceneEntity sceneEntity, @Param("startDate") String startDate, @Param("endDate") String endDate,@Param("sort") int sort) throws ParseException {
|
|
|
+ int months = differentMonths(startDate,endDate);
|
|
|
List<Map<String,Object>> list = sceneMapper.selectYearAlarmTimes(sceneEntity,startDate,endDate,sort);
|
|
|
List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();
|
|
|
- for(int i=0; i<12; i++) {
|
|
|
+ for(int i=0; i<months; i++) {
|
|
|
String strDate = startDate.substring(0, 4) + String.format("-%02d", i + 1);
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
data.put("数量", 0);
|
|
@@ -521,6 +522,39 @@ public class SceneService extends ServiceImpl<SceneMapper, SceneEntity> {
|
|
|
return days;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算2个日期之间相差的 以年、月、日为单位,各自计算结果是多少
|
|
|
+ * 比如:2011-02-02 到 2017-03-02
|
|
|
+ * 以年为单位相差为:6年
|
|
|
+ * 以月为单位相差为:73个月
|
|
|
+ * 以日为单位相差为:2220天
|
|
|
+ * @param startDate
|
|
|
+ * @param endDate
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public int differentMonths(String startDate,String endDate) throws ParseException {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Date fromDate = sdf.parse(startDate);
|
|
|
+ Date toDate = sdf.parse(endDate);
|
|
|
+ Calendar from = Calendar.getInstance();
|
|
|
+ from.setTime(fromDate);
|
|
|
+ Calendar to = Calendar.getInstance();
|
|
|
+ to.setTime(toDate);
|
|
|
+ //只要年月
|
|
|
+ int fromYear = from.get(Calendar.YEAR);
|
|
|
+ int fromMonth = from.get(Calendar.MONTH);
|
|
|
+
|
|
|
+ int toYear = to.get(Calendar.YEAR);
|
|
|
+ int toMonth = to.get(Calendar.MONTH);
|
|
|
+ // int year = toYear - fromYear;
|
|
|
+ int month = toYear * 12 + toMonth - (fromYear * 12 + fromMonth);
|
|
|
+ // int day = (int) ((to.getTimeInMillis() - from.getTimeInMillis()) / (24 * 3600 * 1000));
|
|
|
+ return month;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
*日期加一天
|
|
|
*/
|