|
|
@@ -1,6 +1,7 @@
|
|
|
package org.jeecg.modules.business.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.lang.Snowflake;
|
|
|
import cn.hutool.core.util.BooleanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
@@ -15,6 +16,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.checkerframework.checker.units.qual.C;
|
|
|
import org.jeecg.common.exception.JeecgBootException;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
@@ -1152,6 +1154,9 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
|
|
|
return livingOrder.getId();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 首次超时收费时间
|
|
|
+ */
|
|
|
public Calendar getRemindTime(BusRoomsLivingOrder livingOrder, CesAllDayPriceRule cesAllDayPriceRule, Integer BookingType){
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
if (ObjectUtil.equals(BookingType, 1)) {
|
|
|
@@ -1590,6 +1595,10 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
|
|
|
if (ObjectUtil.isEmpty(roomBookingOrder)){
|
|
|
return;
|
|
|
}
|
|
|
+ List<CesRooms> cesRooms = roomsService.list(Wrappers.<CesRooms>lambdaQuery().eq(CesRooms::getLivingOrderId, e.getId()));
|
|
|
+ if (CollUtil.isNotEmpty(cesRooms)){
|
|
|
+ System.out.println(cesRooms.get(0).getName());
|
|
|
+ }
|
|
|
// 全天房
|
|
|
if (ObjectUtil.equals(1,roomBookingOrder.getBookingType())){
|
|
|
// 如果房间超时是按分钟加收费用
|
|
|
@@ -1617,6 +1626,7 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
|
|
|
public void addByMinute(BusRoomsLivingOrder livingOrder, CesAllDayPriceRule cesAllDayPriceRule){
|
|
|
Date date = new Date();
|
|
|
Calendar nextCalendar = Calendar.getInstance();
|
|
|
+ Calendar nowCalendar = Calendar.getInstance();
|
|
|
nextCalendar.setTime(date);
|
|
|
BusBookingRooms bookingroom = bookingRoomsService.getById(livingOrder.getBookingRoomId());
|
|
|
if (ObjectUtil.isEmpty(bookingroom)){
|
|
|
@@ -1628,37 +1638,65 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
|
|
|
// 需要支付完整费用时间的最后时间
|
|
|
Date endTime = getFullFeeTime(date, cesAllDayPriceRule);
|
|
|
// 当前时间加上超时收费时间
|
|
|
- nextCalendar.add(Calendar.MINUTE, Integer.parseInt(cesAllDayPriceRule.getDayTime()));
|
|
|
+// nextCalendar.add(Calendar.MINUTE, cesAllDayPriceRule.getMinute());
|
|
|
+ // 获取今日第一次超时时间
|
|
|
+ nextCalendar = getRemindTime(livingOrder, cesAllDayPriceRule, 1);
|
|
|
+ nextCalendar.set(Calendar.YEAR, nowCalendar.get(Calendar.YEAR));
|
|
|
+ nextCalendar.set(Calendar.MONTH, nowCalendar.get(Calendar.MONTH));
|
|
|
+ nextCalendar.set(Calendar.DATE, nowCalendar.get(Calendar.DATE));
|
|
|
+ // 今日超时分钟
|
|
|
+ Integer overMinutes = Math.round((nowCalendar.getTimeInMillis() - nextCalendar.getTimeInMillis()) / (1000 * 60 ));
|
|
|
+ if (overMinutes < 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //已经超时的 不足时间
|
|
|
+ Integer minutesDiff = overMinutes % cesAllDayPriceRule.getMinute();
|
|
|
+ // 超出 超时时间 的数量
|
|
|
+ Integer minutesDiffNum = (int) Math.floor(overMinutes / cesAllDayPriceRule.getMinute());
|
|
|
+
|
|
|
+ Integer moreThenMinuteDiffNum = (int) Math.floor(minutesDiff / cesAllDayPriceRule.getMoreThenMinute());
|
|
|
+ // 加上下一次不足时间 >= 超出时间,用超出时间
|
|
|
+ if (minutesDiff + cesAllDayPriceRule.getMoreThenMinute() > cesAllDayPriceRule.getMinute()){
|
|
|
+ Integer newOverTime = cesAllDayPriceRule.getMinute() * (minutesDiffNum + 1);
|
|
|
+ nextCalendar.add(Calendar.MINUTE, newOverTime);
|
|
|
+ }else {
|
|
|
+ nextCalendar.add(Calendar.MINUTE, cesAllDayPriceRule.getMoreThenMinute());
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("{}今日超时分钟{},超时时间数量{},不足时间数量{}",livingOrder.getId(),overMinutes,minutesDiffNum,moreThenMinuteDiffNum);
|
|
|
+
|
|
|
// 当前时间加上超时收费时间 < 按全天收费时间的标准
|
|
|
if (nextCalendar.getTime().compareTo(endTime) < 0){
|
|
|
// 不满足的情况下,添加超时收费,设置下一次收费时间戳
|
|
|
+ BigDecimal money = cesAllDayPriceRule.getPrice().multiply(BigDecimal.valueOf(minutesDiffNum))
|
|
|
+ .add(cesAllDayPriceRule.getMoreThenPrice().multiply(BigDecimal.valueOf(moreThenMinuteDiffNum)));
|
|
|
fee.setDayTime(date);
|
|
|
- fee.setMoney(fee.getMoney().add(cesAllDayPriceRule.getPrice()));
|
|
|
+ fee.setMoney(money);
|
|
|
redisTemplate.opsForZSet().remove("overTimerOrder",livingOrder.getId());
|
|
|
|
|
|
// 如果下一次增加收费时间大于 全天收费时间 设置
|
|
|
}else {
|
|
|
// 如果满足全天收费要求,预离时间增加1天
|
|
|
CesRoomLayout layout = layoutService.getById(bookingroom.getRoomLayoutId());
|
|
|
+
|
|
|
BusLivingLayoutDayPrice dayPrice = addDayPrice(livingOrder, bookingroom, layout.getMarketPrice());
|
|
|
fee.setMoney(dayPrice.getPrice());
|
|
|
fee.setDayTime(date);
|
|
|
- nextCalendar.setTime(livingOrder.getDueOutTime());
|
|
|
- nextCalendar.add(Calendar.DAY_OF_YEAR,1);
|
|
|
- livingOrder.setDueOutTime(nextCalendar.getTime());
|
|
|
- roomsLivingOrderService.updateById(livingOrder);
|
|
|
- // 下一次收费时间戳
|
|
|
- nextCalendar.add(Calendar.MINUTE, Integer.parseInt(cesAllDayPriceRule.getDayTime()));
|
|
|
- // 添加每日房费
|
|
|
+ // 获取每天超时时间,如果超过预离时间,修改预离时间
|
|
|
+ nextCalendar = getNextCalendar(livingOrder, nowCalendar,cesAllDayPriceRule);
|
|
|
+
|
|
|
}
|
|
|
// 移除处理过的时间订单,添加订单下一次超时的时间戳
|
|
|
redisTemplate.opsForZSet().remove("overTimerOrder",livingOrder.getId());
|
|
|
redisTemplate.opsForZSet().add("overTimerOrder",livingOrder.getId(),nextCalendar.getTimeInMillis());
|
|
|
+ // 添加超时房费
|
|
|
feeService.saveOrUpdate(fee);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public void addByDay(BusRoomsLivingOrder livingOrder, CesAllDayPriceRule cesAllDayPriceRule){
|
|
|
Date date = new Date();
|
|
|
+ Calendar nowCalendar = Calendar.getInstance();
|
|
|
Calendar nextCalendar = Calendar.getInstance();
|
|
|
BusBookingRooms bookingroom = bookingRoomsService.getById(livingOrder.getBookingRoomId());
|
|
|
if (ObjectUtil.isEmpty(bookingroom)) {
|
|
|
@@ -1678,12 +1716,8 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
|
|
|
// 添加每日房费
|
|
|
BusLivingLayoutDayPrice dayPrice = addDayPrice(livingOrder, bookingroom, layout.getMarketPrice());
|
|
|
fee.setMoney(dayPrice.getPrice());
|
|
|
- nextCalendar.setTime(livingOrder.getDueOutTime());
|
|
|
- nextCalendar.add(Calendar.DAY_OF_YEAR,1);
|
|
|
- livingOrder.setDueOutTime(nextCalendar.getTime());
|
|
|
- roomsLivingOrderService.updateById(livingOrder);
|
|
|
- // 下一次收费时间戳
|
|
|
- nextCalendar.add(Calendar.MINUTE, Integer.parseInt(cesAllDayPriceRule.getDayTime()));
|
|
|
+ // 获取每天超时时间,如果超过预离时间,修改预离时间
|
|
|
+ nextCalendar = getNextCalendar(livingOrder, nowCalendar,cesAllDayPriceRule);
|
|
|
}
|
|
|
// 移除处理过的时间订单,添加订单下一次超时的时间戳
|
|
|
redisTemplate.opsForZSet().remove("overTimerOrder",livingOrder.getId());
|
|
|
@@ -1693,6 +1727,7 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
|
|
|
|
|
|
public void notAdd(BusRoomsLivingOrder livingOrder, CesAllDayPriceRule cesAllDayPriceRule){
|
|
|
Date date = new Date();
|
|
|
+ Calendar nowCalendar = Calendar.getInstance();
|
|
|
Calendar nextCalendar = Calendar.getInstance();
|
|
|
BusBookingRooms bookingroom = bookingRoomsService.getById(livingOrder.getBookingRoomId());
|
|
|
if (ObjectUtil.isEmpty(bookingroom)) {
|
|
|
@@ -1708,12 +1743,8 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
|
|
|
// 添加每日房费
|
|
|
BusLivingLayoutDayPrice dayPrice = addDayPrice(livingOrder, bookingroom, layout.getMarketPrice());
|
|
|
fee.setMoney(dayPrice.getPrice());
|
|
|
- nextCalendar.setTime(livingOrder.getDueOutTime());
|
|
|
- nextCalendar.add(Calendar.DAY_OF_YEAR,1);
|
|
|
- livingOrder.setDueOutTime(nextCalendar.getTime());
|
|
|
- roomsLivingOrderService.updateById(livingOrder);
|
|
|
- // 下一次收费时间戳
|
|
|
- nextCalendar.add(Calendar.MINUTE, Integer.parseInt(cesAllDayPriceRule.getDayTime()));
|
|
|
+ // 获取每天超时时间,如果超过预离时间,修改预离时间
|
|
|
+ nextCalendar = getNextCalendar(livingOrder, nowCalendar,cesAllDayPriceRule);
|
|
|
}
|
|
|
// 移除处理过的时间订单,添加订单下一次超时的时间戳
|
|
|
redisTemplate.opsForZSet().remove("overTimerOrder",livingOrder.getId());
|
|
|
@@ -1769,6 +1800,23 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
|
|
|
return fee;
|
|
|
}
|
|
|
|
|
|
+ private Calendar getNextCalendar(BusRoomsLivingOrder livingOrder, Calendar nowCalendar,CesAllDayPriceRule cesAllDayPriceRule) {
|
|
|
+ Calendar nextCalendar = Calendar.getInstance();
|
|
|
+ nextCalendar.setTime(livingOrder.getDueOutTime());
|
|
|
+ nextCalendar.set(Calendar.YEAR, nowCalendar.get(Calendar.YEAR));
|
|
|
+ nextCalendar.set(Calendar.MONTH, nowCalendar.get(Calendar.MONTH));
|
|
|
+ nextCalendar.set(Calendar.DAY_OF_MONTH, nowCalendar.get(Calendar.YEAR));
|
|
|
+ nextCalendar.add(Calendar.DAY_OF_YEAR,1);
|
|
|
+ // 修改预离时间
|
|
|
+ if(nextCalendar.getTime().compareTo(livingOrder.getDueOutTime()) > 0){
|
|
|
+ livingOrder.setDueOutTime(nextCalendar.getTime());
|
|
|
+ roomsLivingOrderService.updateById(livingOrder);
|
|
|
+ }
|
|
|
+ // 下一次收费时间戳
|
|
|
+ nextCalendar.add(Calendar.MINUTE, Integer.parseInt(cesAllDayPriceRule.getDayTime()));
|
|
|
+ return nextCalendar;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 完整费用时间
|
|
|
* @return
|