|
@@ -47,6 +47,7 @@ import java.util.regex.Pattern;
|
|
|
@RequestMapping("/v1/hardware")
|
|
|
public class HardwareController {
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
|
private OrderInfoMapper orderInfoMapper;
|
|
|
@Autowired
|
|
@@ -76,7 +77,7 @@ public class HardwareController {
|
|
|
Date currentDateTime = sdf.parse(currentTime);
|
|
|
Date lastRequestDateTime = sdf.parse(lastRequestTime);
|
|
|
long timeElapsed = currentDateTime.getTime() - lastRequestDateTime.getTime();
|
|
|
- return timeElapsed >= 5000; // 5秒等于5000毫秒
|
|
|
+ return timeElapsed >= 10000; // 10秒等于10000毫秒
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return true; // 如果出现异常,默认返回true以执行程序
|
|
@@ -147,6 +148,7 @@ public class HardwareController {
|
|
|
}
|
|
|
|
|
|
OrderInfo orderInfo = orderInfoMapper.selectById(orderId);
|
|
|
+
|
|
|
log.info("此时的订单信息为{}", orderInfo);
|
|
|
|
|
|
//这里先判断是什么订单
|
|
@@ -209,7 +211,7 @@ public class HardwareController {
|
|
|
log.info("使用次卡二维码出门的时间为:{}", currentTime);
|
|
|
orderInfo.setOrderState(String.valueOf(OrderStatusEnum.USED));
|
|
|
orderInfoMapper.updateById(orderInfo);
|
|
|
-
|
|
|
+// return ResultUtil.success(ResultCode.TICKET_ORDER_FINISH);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -260,20 +262,20 @@ public class HardwareController {
|
|
|
//获取订单信息
|
|
|
OrderInfo orderInfo = orderInfoMapper.selectById(orderId);
|
|
|
|
|
|
- // 处理时间格式
|
|
|
- SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- // 获取当前日期和时间
|
|
|
- Date currentDate = new Date();
|
|
|
- String format = sdf1.format(currentDate);
|
|
|
+// // 处理时间格式
|
|
|
+// SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+// // 获取当前日期和时间
|
|
|
+// Date currentDate = new Date();
|
|
|
+// String format = sdf1.format(currentDate);
|
|
|
|
|
|
Date date = sdf.parse(time);
|
|
|
log.info("此刻的传入的时间为:{}", date);
|
|
|
|
|
|
- // 设置不同时间段的价格
|
|
|
- Date startTime1 = sdf.parse(format + " 09:30:00");
|
|
|
- Date endTime1 = sdf.parse(format + " 18:00:00");
|
|
|
- Date startTime2 = sdf.parse(format + " 18:30:00");
|
|
|
- log.info("此时格式化的三个时间段为:{},{},{}", startTime1, endTime1, startTime2);
|
|
|
+// // 设置不同时间段的价格
|
|
|
+// Date startTime1 = sdf.parse(format + " 09:30:00");
|
|
|
+// Date endTime1 = sdf.parse(format + " 18:00:00");
|
|
|
+// Date startTime2 = sdf.parse(format + " 18:30:00");
|
|
|
+// log.info("此时格式化的三个时间段为:{},{},{}", startTime1, endTime1, startTime2);
|
|
|
|
|
|
//先处理订场订单的情况
|
|
|
if (orderInfo.getStartTime() == null) {
|
|
@@ -284,29 +286,29 @@ public class HardwareController {
|
|
|
log.info("此时第一次调用接口设置的计时订单的进场时间为:{}", date);
|
|
|
orderInfoMapper.updateById(orderInfo);
|
|
|
|
|
|
- if (date.after(startTime1) && date.before(endTime1)) {
|
|
|
-
|
|
|
- // 当前时间在 09:30 - 18:00 之间,价格为 8 元/小时
|
|
|
- double initialPrice = 8.0;
|
|
|
- orderInfo.setOrderPrice(initialPrice);
|
|
|
- orderInfo.setOrderState(String.valueOf(OrderStatusEnum.WAITING_TO_PAY));
|
|
|
- log.info("09:30 - 18:00这个时间段的订单信息为:{}", orderInfo);
|
|
|
- orderInfoService.updateById(orderInfo);
|
|
|
-
|
|
|
- } else if (date.after(startTime2)) {
|
|
|
-
|
|
|
- // 当前时间在 18:30 之后,价格为 10 元/小时
|
|
|
- double initialPrice = 10.0;
|
|
|
- orderInfo.setOrderPrice(initialPrice);
|
|
|
- orderInfo.setOrderState(String.valueOf(OrderStatusEnum.WAITING_TO_PAY));
|
|
|
- log.info("18 :30 之后的这个时间段的订单信息为:{}", orderInfo);
|
|
|
- orderInfoService.updateById(orderInfo);
|
|
|
-
|
|
|
- }
|
|
|
+// if (date.after(startTime1) && date.before(endTime1)) {
|
|
|
+//
|
|
|
+// // 当前时间在 09:30 - 18:00 之间,价格为 8 元/小时
|
|
|
+// double initialPrice = 8.0;
|
|
|
+// orderInfo.setOrderPrice(initialPrice);
|
|
|
+// orderInfo.setOrderState(String.valueOf(OrderStatusEnum.WAITING_TO_PAY));
|
|
|
+// log.info("09:30 - 18:00这个时间段的订单信息为:{}", orderInfo);
|
|
|
+// orderInfoService.updateById(orderInfo);
|
|
|
+//
|
|
|
+// } else if (date.after(startTime2)) {
|
|
|
+//
|
|
|
+// // 当前时间在 18:30 之后,价格为 10 元/小时
|
|
|
+// double initialPrice = 10.0;
|
|
|
+// orderInfo.setOrderPrice(initialPrice);
|
|
|
+// orderInfo.setOrderState(String.valueOf(OrderStatusEnum.WAITING_TO_PAY));
|
|
|
+// log.info("18 :30 之后的这个时间段的订单信息为:{}", orderInfo);
|
|
|
+// orderInfoService.updateById(orderInfo);
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- if (orderInfo.getEndTime() == null) {
|
|
|
+ if (orderInfo.getEndTime() == null && orderInfo.getStartTime() != null) {
|
|
|
|
|
|
// 第二次调用接口,设置endTime,并计算费用
|
|
|
orderInfo.setEndTime(date);
|
|
@@ -333,15 +335,15 @@ public class HardwareController {
|
|
|
orderInfo.setOverPrice(totalPrice);
|
|
|
log.info("计时订单超时金额为:{}", totalPrice);
|
|
|
orderInfo.setOrderState(String.valueOf(OrderStatusEnum.WAITING_SUPPLEMENTS));
|
|
|
-
|
|
|
+ orderInfo.setOverTime((int) extraMinutes);
|
|
|
orderInfoService.updateById(orderInfo);
|
|
|
+ return ResultUtil.success(ResultCode.TIME_ORDER_OVER_FINISH);
|
|
|
}
|
|
|
-
|
|
|
//如果没有超时 该计时订单完成
|
|
|
orderInfo.setOrderState(String.valueOf(OrderStatusEnum.USED));
|
|
|
log.info("使用完成的计时订单信息为:{}", orderInfo);
|
|
|
orderInfoService.updateById(orderInfo);
|
|
|
-
|
|
|
+ return ResultUtil.success(ResultCode.TIME_ORDER_FINISH);
|
|
|
}
|
|
|
}
|
|
|
return ResultUtil.error(ResultCode.TIMER_HARD_ERROR);
|
|
@@ -367,6 +369,7 @@ public class HardwareController {
|
|
|
log.info("此刻的时间为:{}", currentTime);
|
|
|
|
|
|
|
|
|
+ //todo:第2个问题,订场还没有到点的,然后拿着二维码去扫是进不去的,但是只要有这个操作后台就会显示已使用,然后二维码就找不到了。
|
|
|
//处理可能会出现提前扫码的情况
|
|
|
// 1-->保证在订场开始时间的前30分钟扫码才有效
|
|
|
// 获取原始时间
|
|
@@ -377,16 +380,19 @@ public class HardwareController {
|
|
|
// 减去30分钟
|
|
|
calendar.add(Calendar.MINUTE, -30);
|
|
|
Date newTime = calendar.getTime();
|
|
|
+ Date parse = sdf.parse(newTime.toString());
|
|
|
log.info("该订单开始时间减去30分钟之后的时间为:{}", newTime);
|
|
|
|
|
|
// 判断时间
|
|
|
- if (currentTime.after(newTime)) {
|
|
|
+ if (currentTime.before(parse)) {
|
|
|
return ResultUtil.success(ResultCode.TIME_BU_DAO);
|
|
|
}
|
|
|
|
|
|
//先处理订场订单的情况
|
|
|
if (orderTypeEnum.RENTAL.toString().equals(orderInfo.getOrderType())) {
|
|
|
|
|
|
+ //如果来回进出场地 或者说用户分享给朋友进行使用的情况
|
|
|
+ // 进入时间就是第一次扫码的时间 但是出门时间要设置为在订单前后的时间
|
|
|
if (orderInfo.getStartTime() == null && orderInfo.getOrderState().equals(OrderStatusEnum.WAITING_TO_USE)) {
|
|
|
|
|
|
// 第一次调用接口,设置startTime
|
|
@@ -408,9 +414,16 @@ public class HardwareController {
|
|
|
if (currentTime.before(orderInfo.getOrderEd())) {
|
|
|
|
|
|
// 在ordered时间之前,返回状态码200
|
|
|
- orderInfo.setOrderState(String.valueOf(OrderStatusEnum.USED));
|
|
|
+ orderInfo.setOrderState(String.valueOf(OrderStatusEnum.IN_USE));
|
|
|
orderInfoMapper.updateById(orderInfo);
|
|
|
|
|
|
+ if (currentTime.after(orderInfo.getOrderEd())) {
|
|
|
+
|
|
|
+ orderInfo.setOrderState(String.valueOf(OrderStatusEnum.USED));
|
|
|
+ orderInfoMapper.updateById(orderInfo);
|
|
|
+ return ResultUtil.success(ResultCode.RENTAL_ORDER_FINISH);
|
|
|
+
|
|
|
+ }
|
|
|
} else {
|
|
|
|
|
|
// 超过ordered时间,计算超过的分钟数
|
|
@@ -427,6 +440,7 @@ public class HardwareController {
|
|
|
log.info("租场超时金额为:{}", v1);
|
|
|
orderInfo.setOverPrice(v1);
|
|
|
orderInfoService.updateById(orderInfo);
|
|
|
+ return ResultUtil.success(ResultCode.RENTAL_ORDER_OVER_FINISH);
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -488,24 +502,56 @@ public class HardwareController {
|
|
|
*/
|
|
|
@Operation(summary = "计时卡")
|
|
|
@PostMapping("/timeCard/{accessToken}")
|
|
|
- public ResultMessage timeCard(@PathVariable("accessToken") String accessToken) {
|
|
|
+ public ResultMessage timeCard(@PathVariable("accessToken") String accessToken) throws ParseException {
|
|
|
//解析校验token获得用户id
|
|
|
AuthUser authUser = UserContext.getAuthUser(accessToken);
|
|
|
assert authUser != null;
|
|
|
String userId = authUser.getId();
|
|
|
+
|
|
|
+ if (userId.isEmpty()) {
|
|
|
+ return ResultUtil.error(ResultCode.USER_NEED_LOGIN);
|
|
|
+ }
|
|
|
log.info("此时的用户id为:{}", userId);
|
|
|
//根据userId查询user信息
|
|
|
User user = userMapper.selectById(userId);
|
|
|
// 处理nickName为null的情况
|
|
|
- String nickName = (user.getNickName() != null) ? user.getNickName() : "";
|
|
|
- // 获取当前日期
|
|
|
- LocalDate currentDate = LocalDate.now();
|
|
|
- // 格式化日期为字符串
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
- String formattedDate = currentDate.format(formatter);
|
|
|
- /**
|
|
|
- * 这里存储计时订单信息
|
|
|
- */
|
|
|
+ //生成一个随机数字
|
|
|
+ String numbersUser = RandomUtil.randomNumbers(4);
|
|
|
+ String nickName = (user.getNickName() != null) ? user.getNickName() : "用户+" + numbersUser;
|
|
|
+
|
|
|
+ // 获取当前时间
|
|
|
+ Date now = new Date();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ // 格式化当前时间为字符串
|
|
|
+ String date = sdf.format(now);
|
|
|
+ long time = sdf.parse(date).getTime();
|
|
|
+ log.info("此刻使用计时码的时间为其对应的时间戳为:{},{}", date, time);
|
|
|
+
|
|
|
+ // 处理时间格式
|
|
|
+ SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ // 获取当前日期和时间
|
|
|
+ Date currentDate = new Date();
|
|
|
+ String format = sdf1.format(currentDate);
|
|
|
+
|
|
|
+ // 设置不同时间段的价格
|
|
|
+ long startTime1 = sdf.parse(format + " 09:30:00").getTime();
|
|
|
+ long endTime1 = sdf.parse(format + " 18:00:00").getTime();
|
|
|
+ long startTime2 = sdf.parse(format + " 18:30:00").getTime();
|
|
|
+ log.info("此时格式化的三个时间段的时间戳为:{},{},{}", startTime1, endTime1, startTime2);
|
|
|
+
|
|
|
+
|
|
|
+ //根据不同的时间判断进场价格
|
|
|
+ double initPrice = 0.0;
|
|
|
+
|
|
|
+ if (time >= startTime1 && time <= endTime1) {
|
|
|
+ initPrice = 8.0;
|
|
|
+ } else if (time >= startTime2) {
|
|
|
+ initPrice = 10.0;
|
|
|
+ }
|
|
|
+ log.info("此时的初始价格为:{}", initPrice);
|
|
|
+
|
|
|
+ //根据不同的时间判断进场价格
|
|
|
OrderInfo orderInfo = new OrderInfo();
|
|
|
String orderId = RandomUtil.randomNumbers(9);
|
|
|
orderInfo.setId(orderId);
|
|
@@ -513,24 +559,16 @@ public class HardwareController {
|
|
|
orderInfo.setCreateTime(new Date());
|
|
|
orderInfo.setStoreId(9376L);
|
|
|
orderInfo.setOrderType(String.valueOf(orderTypeEnum.TIMER));
|
|
|
- orderInfoService.save(orderInfo);
|
|
|
-
|
|
|
- //生成一个随机数字
|
|
|
- String numbers = RandomUtil.randomNumbers(5);
|
|
|
-
|
|
|
- String data = "pxo_" + formattedDate + "_" + numbers + "_" + orderInfo.getId() + "_00";
|
|
|
-
|
|
|
- Boolean flag = QrCodeRegistrationUtil.registerTimerQrCode(data);
|
|
|
+ orderInfo.setOrderState(String.valueOf(OrderStatusEnum.WAITING_TO_PAY));
|
|
|
+ orderInfo.setOrderPrice(initPrice);
|
|
|
+ boolean save = orderInfoService.save(orderInfo);
|
|
|
|
|
|
- if (flag) {
|
|
|
- orderInfo.setQrCode(data);
|
|
|
- orderInfoService.updateById(orderInfo);
|
|
|
- //判断响应结果
|
|
|
+ if (save) {
|
|
|
TimeCodeVo timeCodeVo = new TimeCodeVo();
|
|
|
- timeCodeVo.setCode(data);
|
|
|
+ timeCodeVo.setOrderInfo(orderInfo);
|
|
|
timeCodeVo.setNickName(nickName);
|
|
|
return ResultUtil.data(timeCodeVo);
|
|
|
}
|
|
|
- return ResultUtil.error(ResultCode.TIME_CODE_ERROR);
|
|
|
+ return ResultUtil.error(ResultCode.PRICE);
|
|
|
}
|
|
|
}
|