Преглед изворни кода

Merge branch 'feature/空调加时最短申请时间改为半小时'

xiachuang пре 9 месеци
родитељ
комит
13afe504ba

+ 21 - 21
src/main/java/com/palmnest/application/core/util/DateUtils.java

@@ -1,7 +1,6 @@
 package com.palmnest.application.core.util;
 
 
-import cn.superdesk.libs.common.json.JsonUtils;
 import com.palmnest.application.dto.DateTypeDto;
 import net.sf.json.JSONObject;
 
@@ -71,7 +70,7 @@ public class DateUtils {
 		}
 		return DateUtils.getTime(parrten);
 	}
-	
+
 	/**
 	 *  java 获取 获取某年某月 所有日期(yyyy-mm-dd格式字符串)
 	 * @param year
@@ -96,7 +95,7 @@ public class DateUtils {
 	    }
 	    return fullDayList;
 	}
-	
+
 	/**
      * 获取一天中间隔五分钟的所有时间点
      *
@@ -130,7 +129,7 @@ public class DateUtils {
 
         return list;
     }
-    
+
     public static List<String> getTimeMin(int min){
     	ArrayList<String> list = new ArrayList<String>();//创建集合存储所有时间点
     	List<String> tList=getTimeLagMinute(min);
@@ -138,7 +137,7 @@ public class DateUtils {
     		Date date=DateHelper.parseToDate(beginTime,DateHelper.TIME_HOUR_MINUTE);
     		Date day=addMinute(date, min, DateHelper.TIME_HOUR_MINUTE);
     		String endTime=DateHelper.formatDate(day, DateHelper.TIME_HOUR_MINUTE);
-    		
+
     		if("23:30".equals(beginTime)){
     			endTime="24:00";
     		}
@@ -149,11 +148,12 @@ public class DateUtils {
     	return list;
     }
 
-	public static void main(String[] args) {
-
-		List<WeekDate> list=getWeek();
-		System.out.println(JsonUtils.toJson(list));
-	}
+    public static BigDecimal calculateUsageDuration(Date startTime, Date endTime) {
+        long durationInMillis = endTime.getTime() - startTime.getTime();
+        double durationInHours = durationInMillis / (60.0 * 60 * 1000);
+        // Round up to the nearest half hour
+        return BigDecimal.valueOf(Math.ceil(durationInHours * 2) / 2);
+    }
 
 	/**
 	 * 时间格式转换
@@ -1039,31 +1039,31 @@ public class DateUtils {
 //		System.out.println(getDate("yyyy-MM-dd"));
 //		System.out.println(getPreWeekDate2(new Date()));
 //		System.out.println(getBeforeNowDays(0));*/
-//		
+//
 //		/*System.out.println(getDateByString("2015-10-28 10:20:16"));
 //		System.out.println(getDateByString("2015-10-28 10:18:41"));
 //		System.out.println(compareStringTimesToMinute(getDateByString("2015-10-28 10:18:41"),getDateByString("2015-10-28 10:20:16")));
 //		*/
 //		//System.out.println(DateUtils.formatDate(DateUtils.StrToDate("2017-05","yyyy-MM"),"yyyy-MM"));
 //		//System.out.println(calculateTime("2015-10-28 10:10:06", "2015-10-28 10:20:16.0"));
-//		
+//
 //		//System.out.println(compareStringTimesToHour(getDateByString("2015-10-28 08:30:00"),getDateByString("2015-10-28 10:30:00"),"yyyy-MM-dd HH:mm"));
-//		
+//
 ////		String str11="2018-10-22 16:30:00";
 ////		Date useStartTime=DateUtils.getDateByString(str11, DateUtils.YYYY_MM_DD_MM_HH_SS);
 ////		String str22="2018-10-22 20:30:00";
 ////		Date useEndTime=DateUtils.getDateByString(str22, DateUtils.YYYY_MM_DD_MM_HH_SS);
-////		
-////		
+////
+////
 ////		int min=1800;
 ////		int max=2300;
-////		
+////
 ////		String currentDateStr=DateUtils.formatDate(useStartTime, "yyyy-MM-dd HH:mm");
 ////		useStartTime=DateUtils.getDateByString(currentDateStr, "yyyy-MM-dd HH:mm");
-//		
+//
 //		//getIncludeTime(useStartTime, useEndTime, min, max);
-//		
-//		
+//
+//
 //	}
 
 	public static Map<String, Date> getIncludeTime(Date useStartTime, Date useEndTime, Date ruleStartTime,
@@ -1620,7 +1620,7 @@ public class DateUtils {
 		return days;
 	}
 
-//    public static void main(String[] args) {  
+//    public static void main(String[] args) {
 ////    	String date="2019-4";
 ////		try {
 ////			List<DateTypeDto> mapList = getHoliday(date);
@@ -1645,5 +1645,5 @@ public class DateUtils {
 //            w=7;
 //        }
 //        System.out.println(w);
-//    }  
+//    }
 }

+ 54 - 83
src/main/java/com/palmnest/service/estateserve/airconditioner/impl/ConditionerAddTimeServiceImpl.java

@@ -38,7 +38,6 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.servlet.http.HttpServletRequest;
 import java.io.File;
 import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
 import java.math.BigDecimal;
 import java.math.MathContext;
 import java.math.RoundingMode;
@@ -339,17 +338,14 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
 
             // 1-实际面积 2-半层起定 3-不可预定 4-一层起订
 
-            Integer haveFloorNum = 0;// 一层的数量
-            Integer halfHaveFloorNum = 0;// 半层的数量
+            int haveFloorNum = 0;// 一层的数量
+            int halfHaveFloorNum = 0;// 半层的数量
             applyArea = "";
-            String current_floorId = "";
+            StringBuilder current_floorId = new StringBuilder();
             if (priceType == 1) { // 平米每小时
-                Iterator it = floorSumAreaMap.keySet().iterator();
-                while (it.hasNext()) {
-
-                    Integer floorId = (Integer) it.next();
+                for (Integer floorId : floorSumAreaMap.keySet()) {
 
-                    current_floorId = current_floorId + floorId.toString() + ";";
+                    current_floorId.append(floorId.toString()).append(";");
 
                     boolean isHalfHaveFloor = false;// 是否有半层起
                     boolean isHaveFloor = false;// 是否有一层起
@@ -361,7 +357,7 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
                     }
 
 
-                    BigDecimal sumArea = (BigDecimal) floorSumAreaMap.get(floorId);// 当层申请合计面积
+                    BigDecimal sumArea = floorSumAreaMap.get(floorId);// 当层申请合计面积
                     BigDecimal floorSumArea = roomInfoManager.getSumArueByFloorId(floorId);// 整层合计面积
                     if (null == floorSumArea) {
                         floorSumArea = BigDecimal.ZERO;
@@ -384,12 +380,9 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
                 applyArea = calcapplyArea.toString() + "m²";
             } else if (priceType == 2) { // 层(半层)每小时
 
-                Iterator it = floorSumAreaMap.keySet().iterator();
-                while (it.hasNext()) {
-
-                    Integer floorId = (Integer) it.next();
+                for (Integer floorId : floorSumAreaMap.keySet()) {
 
-                    current_floorId = current_floorId + floorId.toString() + ";";
+                    current_floorId.append(floorId.toString()).append(";");
 
                     boolean isHalfHaveFloor = false;// 是否有半层起
                     boolean isHaveFloor = false;// 是否有一层起
@@ -428,16 +421,16 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
                 }
                 // applyArea =  calcapplyArea.toString();
                 if (haveFloorNum > 0) {
-                    applyArea = "层*" + haveFloorNum.toString();
+                    applyArea = "层*" + haveFloorNum;
                 }
                 if (StringUtils.isNotEmpty(applyArea) && halfHaveFloorNum > 0) {
-                    applyArea = applyArea + "," + "半层*" + halfHaveFloorNum.toString();
+                    applyArea = applyArea + "," + "半层*" + halfHaveFloorNum;
                 } else if (halfHaveFloorNum > 0) {
-                    applyArea = "半层*" + halfHaveFloorNum.toString();
+                    applyArea = "半层*" + halfHaveFloorNum;
                 }
             }
 
-            airConditionerAddTime.setFloorId(current_floorId.replaceAll("[;]$", ""));
+            airConditionerAddTime.setFloorId(current_floorId.toString().replaceAll("[;]$", ""));
             airConditionerAddTime.setApplyArea(applyArea);
             airConditionerAddTime.setUseStartTime(minDate);
             airConditionerAddTime.setUseEndTime(maxDate);
@@ -447,12 +440,13 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
             floorPriceHour = airRule.getFloorPriceHour();// 每层多少钱/每小时
             halfFloorPriceHour = airRule.getHalfFloorPriceHour();// 每半层多少钱/每小时
 
+            // deprecated
             // 空调加时最低申请1小时,半小时按1小时收取费用
-            BigDecimal UseLengthTime = DateUtils.compareStringTimesToHour(airConditionerAddTime.getUseStartTime(), airConditionerAddTime.getUseEndTime());
-            // if (UseLengthTime.compareTo(new BigDecimal("1")) == -1) {
-            //	return AppResultUtil.createErrorDto(AppConstants.ERROR_CODE, "最低申请1小时,请重新选择时间");
-            //}
-            UseLengthTime = UseLengthTime.setScale(0, BigDecimal.ROUND_UP);// 向上取整
+            // BigDecimal UseLengthTime = DateUtils.compareStringTimesToHour(airConditionerAddTime.getUseStartTime(), airConditionerAddTime.getUseEndTime());
+            // UseLengthTime = UseLengthTime.setScale(0, BigDecimal.ROUND_UP);// 向上取整
+
+            // 20231201 空调加时最低申请半小时,不满半小时按半小时收取费用
+            BigDecimal UseLengthTime = DateUtils.calculateUsageDuration(airConditionerAddTime.getUseStartTime(), airConditionerAddTime.getUseEndTime());
 
             airConditionerAddTime.setUseLengthTime(UseLengthTime);// 使用时长
 
@@ -462,73 +456,58 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
             boolean isCalcHouse = true;// 是否按面积来计算
 
 
-            BigDecimal calcFee = BigDecimal.ZERO.setScale(2);// 费用
+            BigDecimal calcFee = BigDecimal.ZERO.setScale(2, RoundingMode.UNNECESSARY);// 费用
             String freeDetail = "";// 费用明细
             // 小时*1层*每层300元/小时
             // 1小时*半层*每半层200元/小时
-            if (false) {// 按户计算
-
-                // priceDisplay="每户350元/每小时";
-                priceDisplay = "每户" + df4.format(priceHu.setScale(2)) + "元/每小时";
-
-                // 费用明细:2小时*2户*每户350元/每小时=1400.00元
-                calcFee = UseLengthTime.multiply(new BigDecimal(houseNo)).multiply(priceHu).setScale(2, 4);
-                freeDetail = UseLengthTime.toPlainString() + "小时*" + houseNo + "户*" + priceDisplay;
-                airConditionerAddTime.setUseAreaOrTime(2);// 使用 1面积 2 时间
-
-
-            } else {// 用面积计算
-
+            // 用面积计算
+            if (priceType == 1) {
 
-                if (priceType == 1) {
+                String calc_applyArea = applyArea.replace("m²", "");
 
-                    String calc_applyArea = applyArea.replace("m²", "");
+                // priceDisplay="每平米0.15元/小时";
+                priceDisplay = "每平米" + df4.format(priceHour.setScale(2)) + "元/小时";
 
-                    // priceDisplay="每平米0.15元/小时";
-                    priceDisplay = "每平米" + df4.format(priceHour.setScale(2)) + "元/小时";
 
+                // 费用明细:2小时*2平米*每平米0.15元/小时=1400.00元
+                calcFee = UseLengthTime.multiply(new BigDecimal(calc_applyArea)).multiply(priceHour).setScale(2, 4);
+                freeDetail = UseLengthTime.toPlainString() + "小时*" + calc_applyArea + "平米*" + priceDisplay;
+                airConditionerAddTime.setUseAreaOrTime(1);// 使用 1面积 2 时间
+            } else if (priceType == 2) {
 
-                    // 费用明细:2小时*2平米*每平米0.15元/小时=1400.00元
-                    calcFee = UseLengthTime.multiply(new BigDecimal(calc_applyArea)).multiply(priceHour).setScale(2, 4);
-                    freeDetail = UseLengthTime.toPlainString() + "小时*" + calc_applyArea + "平米*" + priceDisplay;
-                    airConditionerAddTime.setUseAreaOrTime(1);// 使用 1面积 2 时间
-                } else if (priceType == 2) {
+                // 每层300元/小时、每半层200元/小时
+                priceDisplay = "每层" + df4.format(floorPriceHour.setScale(2)) + "元/小时、" + "每半层" + df4.format(halfFloorPriceHour.setScale(2)) + "元/小时";
 
-                    // 每层300元/小时、每半层200元/小时
-                    priceDisplay = "每层" + df4.format(floorPriceHour.setScale(2)) + "元/小时、" + "每半层" + df4.format(halfFloorPriceHour.setScale(2)) + "元/小时";
+                // 1小时*1层*每层300元/小时-1小时*半层*每半层200元/小时
+                // haveFloorNum 多少一层
+                if (haveFloorNum > 0) {
+                    calcFee = UseLengthTime.multiply(BigDecimal.valueOf(haveFloorNum)).multiply(floorPriceHour).setScale(2, 4);
+                    // 1小时*1层*每层300元/小时
+                    freeDetail = UseLengthTime.toPlainString() + "小时*" + haveFloorNum + "层*每层" + floorPriceHour + "元/小时";
+                }
+                if (halfHaveFloorNum > 0) {
+                    calcFee = calcFee.add(UseLengthTime.multiply(BigDecimal.valueOf(halfHaveFloorNum)).multiply(halfFloorPriceHour).setScale(2, 4));
 
-                    // 1小时*1层*每层300元/小时-1小时*半层*每半层200元/小时
-                    // haveFloorNum 多少一层
-                    if (haveFloorNum > 0) {
-                        calcFee = UseLengthTime.multiply(BigDecimal.valueOf(haveFloorNum)).multiply(floorPriceHour).setScale(2, 4);
-                        // 1小时*1层*每层300元/小时
-                        freeDetail = UseLengthTime.toPlainString() + "小时*" + haveFloorNum + "层*每层" + floorPriceHour + "元/小时";
-                    }
-                    if (halfHaveFloorNum > 0) {
-                        calcFee = calcFee.add(UseLengthTime.multiply(BigDecimal.valueOf(halfHaveFloorNum)).multiply(halfFloorPriceHour).setScale(2, 4));
-
-                        if (StringUtils.isNotBlank(freeDetail)) {
-                            // 1小时*半层*每半层200元/小时
-                            freeDetail = freeDetail + "," + UseLengthTime.toPlainString() + "小时*" + "半层*" + halfHaveFloorNum + "*每半层" + halfFloorPriceHour + "元/小时";
-                        } else {
-                            freeDetail = UseLengthTime.toPlainString() + "小时*" + "半层*" + halfHaveFloorNum + "*每半层" + halfFloorPriceHour + "元/小时";
-                        }
+                    if (StringUtils.isNotBlank(freeDetail)) {
+                        // 1小时*半层*每半层200元/小时
+                        freeDetail = freeDetail + "," + UseLengthTime.toPlainString() + "小时*" + "半层*" + halfHaveFloorNum + "*每半层" + halfFloorPriceHour + "元/小时";
+                    } else {
+                        freeDetail = UseLengthTime.toPlainString() + "小时*" + "半层*" + halfHaveFloorNum + "*每半层" + halfFloorPriceHour + "元/小时";
                     }
-
                 }
 
-
             }
 
+
             airConditionerAddTime.setPriceDisplay(priceDisplay);// 单价:每户350元/每小时
             // 工作日2018-09-18 07:00~21:00
             // 工作日根据时间获取
             String dataTypeStr = "工作日";
-            if (dataType == GoodsCodeConstants.DATATYPE_WORKINGDAY) {// 工作日
+            if (Objects.equals(dataType, GoodsCodeConstants.DATATYPE_WORKINGDAY)) {// 工作日
                 dataTypeStr = "工作日";
-            } else if (dataType == GoodsCodeConstants.DATATYPE_RESTDAY) {// 休息日
+            } else if (Objects.equals(dataType, GoodsCodeConstants.DATATYPE_RESTDAY)) {// 休息日
                 dataTypeStr = "休息日";
-            } else if (dataType == GoodsCodeConstants.DATATYPE_VACATIONS) {// 节假日
+            } else if (Objects.equals(dataType, GoodsCodeConstants.DATATYPE_VACATIONS)) {// 节假日
                 dataTypeStr = "节假日";
             }
 
@@ -555,7 +534,7 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
 
             String types = "5,6";// 空调加时
             List<Map<String, Object>> list = enterprisePermissionDao.getGoodsConfig(airConditionerAddTime.getOrganizationId().longValue(), types, "");
-            if (list != null && list.size() > 0) {
+            if (list != null && !list.isEmpty()) {
                 if (null != virPermId && virPermId.equals((Integer) list.get(0).get("roleId"))) {
 
                     if (list.size() >= 2) {
@@ -658,14 +637,8 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
 
             return AppResultUtil.createSuccesDto(convert(bill));
 
-        } catch (IllegalAccessException e) {
-            e.printStackTrace();
-            return AppResultUtil.createErrorDto(AppConstants.ERROR_CODE, "空调加时申请失败:" + LogExceptionStackUtil.LogExceptionStack(e));
-        } catch (InvocationTargetException e) {
-            e.printStackTrace();
-            return AppResultUtil.createErrorDto(AppConstants.ERROR_CODE, "空调加时申请失败:" + LogExceptionStackUtil.LogExceptionStack(e));
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error("空调加时申请失败:{}", LogExceptionStackUtil.LogExceptionStack(e));
             return AppResultUtil.createErrorDto(AppConstants.ERROR_CODE, "空调加时申请失败:" + LogExceptionStackUtil.LogExceptionStack(e));
         }
 
@@ -2607,13 +2580,11 @@ public class ConditionerAddTimeServiceImpl implements ConditionerAddTimeService
                 }
             }
 
-
             /*
-             *	使用时长
-             *	空调加时最低申请1小时,半小时按1小时收取费用
+             * 使用时长
+             * 空调加时最低申请半小时,不到半小时按半小时收取费用
              */
-            BigDecimal useLengthTime = DateUtils.compareStringTimesToHour(minDate, maxDate);
-            useLengthTime = useLengthTime.setScale(0, RoundingMode.UP);// 向上取整
+            BigDecimal useLengthTime = DateUtils.calculateUsageDuration(airConditionerAddTime.getUseStartTime(), airConditionerAddTime.getUseEndTime());
 
             airConditionerAddTime.setUseLengthTime(useLengthTime);