Przeglądaj źródła

修改价格日历

夏文涛 2 lat temu
rodzic
commit
a16a905075

+ 19 - 1
mhotel/src/com/happy/Until/TimeExchange.java

@@ -412,6 +412,24 @@ public class TimeExchange {
     }
 
     /**
+     * 获取指定月份有多少天
+     *
+     * @param month
+     * @return
+     */
+    public static int getMonthDays(String date, int month) {
+        int year = Integer.valueOf(date.substring(0, 4));
+        int[] arr = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+        int day = arr[month - 1];//天数对应=数组-1
+        if (month == 2 && year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
+            day = 29;
+        }
+
+        return day;
+
+    }
+
+    /**
      * Date转为String
      * @param time 时间
      * @param FormatStr 自定义时间格式
@@ -541,7 +559,7 @@ public class TimeExchange {
 
         int lastDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);
         c.set(Calendar.DAY_OF_MONTH, lastDay);
-        String endDate = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()) + " 23:59:59";
+        String endDate = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
 
         return new String[]{startDate, endDate};
     }

+ 6 - 2
mhotel/src/com/happy/action/AppHomePageAction.java

@@ -242,13 +242,17 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
             dateStrs.add(date);
         }
         List<House> houseList = hotel.getHouseList();
-        for (House houseData : houseList) {
+        for (House houseData:houseList) {
+            Double todayPrice = 0.0;
             for (String dateStr:dateStrs){
                 Optional<HousePriceOneDataVo> oneData = oneDatas.stream().filter(e -> e.getHouseId().equals(houseData.getId()) && e.getSetDate().equals(dateStr)).sorted(Comparator.comparing(HousePriceOneDataVo::getCreateDate,Comparator.reverseOrder())).findFirst();
                 if(oneData != null && oneData.isPresent()){
-                    houseData.setPrice(houseData.getPrice() + oneData.get().getPrice());
+                    todayPrice = todayPrice + oneData.get().getPrice();
+                }else{
+                    todayPrice = todayPrice + houseData.getPrice();
                 }
             }
+            houseData.setPrice(todayPrice);
             if(dateStrs.size() > 0){
                 houseData.setPrice(houseData.getPrice() == 0.0 ? 0.0 : (houseData.getPrice() / dateStrs.size()));
             }

+ 9 - 28
mhotel/src/com/happy/action/HousePriceAction.java

@@ -171,44 +171,25 @@ public class HousePriceAction extends BaseController implements ModelDriven<Hous
             return null;
         }
         if (startTime == null) {
-            resultJson.put("message", "入住时间不能为空");
+            resultJson.put("message", "月份时间不能为空");
             resultJson.put("code", 500);
             ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return null;
         }
 
+        int days = TimeExchange.getMonthDays(startTime, Integer.valueOf(startTime.substring(5, 7)));
+        String[] months = TimeExchange.getCurrentMonthTimeFrame(startTime);
+        String startDate = months[0];
+        String endDate = months[1];
         List<HousePriceResultVo> result = new ArrayList<>();
         List<String> dateStrs = new ArrayList<>();
-        String DateNow = TimeExchange.DateToString(new Date(), "yyyy-MM-dd");
-        //离店时间为空的话 则拿入店时间的前三天和后七天数据
-        boolean IsDurStart = TimeExchange.CompareDate(DateNow, startTime, "yyyy-MM-dd");
-        if (IsDurStart) {
-            for (int i = 1; i <= 3; i++) {
-                String date = TimeExchange.TimeDesD(startTime, -i);
-                if (date.equals(DateNow)) {
-                    dateStrs.add(date);
-                    break;
-                }
-                dateStrs.add(date);
-            }
-        }
-
-        dateStrs.add(startTime);
-
-        int dateNum = 7;
-        if (endTime != null) {
-            //后七天
-            dateNum = TimeExchange.daysBetween(startTime, endTime);
-        }
-
-        for (int i = 1; i <= dateNum; i++) {
+        for (int i = 0; i < days; i++) {
             String date = TimeExchange.TimeDesD(startTime, i);
             dateStrs.add(date);
         }
-
         Collections.sort(dateStrs);
 
-        List<HousePriceDataVo> hprd = housePriceService.queryHousePriceDatas(merchantId, dateStrs.get(0), dateStrs.get(dateStrs.size() - 1));
+        List<HousePriceDataVo> hprd = housePriceService.queryHousePriceDatas(merchantId, startDate, endDate);
         List<HousePriceOneDataVo> oneDatas = new ArrayList<>();
         //将数据处理成单天的
         for (HousePriceDataVo hp : hprd) {
@@ -262,9 +243,9 @@ public class HousePriceAction extends BaseController implements ModelDriven<Hous
             List<HousePriceOneDataVo> priceDatas = oneDatas.stream().filter(e -> e.getSetDate().equals(str)).sorted(Comparator.comparing(HousePriceOneDataVo::getPrice)).collect(Collectors.toList());
 
             if (priceDatas.size() > 0) {
-                data.setTopinfo("¥" + priceDatas.get(0).getPrice());
+                data.setTopinfo("¥" + priceDatas.get(0).getPrice() + "起");
             } else {
-                data.setTopinfo("¥" + minPrice);
+                data.setTopinfo("¥" + minPrice + "起");
             }
             result.add(data);
         }