|
|
@@ -1145,39 +1145,96 @@ public class OrderServiceImpl extends ServiceImpl<AppOrderMapper, AppOrder> impl
|
|
|
AppSite appSite = appSiteMapper.selectById(appCoursesMapper.selectById(appOrderProInfo.getProductId()).getAddressSiteId());
|
|
|
if (null != appSite &&
|
|
|
appSite.getType() == 0) {
|
|
|
- AppOrderProInfo proInfo1 = appOrderProInfoMapper.selectOne(Wrappers.<AppOrderProInfo>lambdaQuery()
|
|
|
+ // 查询该用户所有待使用的课程订单,合并时间范围
|
|
|
+ List<AppOrderProInfo> allCourseOrders = appOrderProInfoMapper.selectList(Wrappers.<AppOrderProInfo>lambdaQuery()
|
|
|
.eq(AppOrderProInfo::getFamilyUserId, appOrderProInfo.getFamilyUserId())
|
|
|
.eq(AppOrderProInfo::getOrderStatus, 1)
|
|
|
.eq(AppOrderProInfo::getType, 5)
|
|
|
- .orderByDesc(AppOrderProInfo::getExpireTime)
|
|
|
- .last("limit 1"));
|
|
|
- AppOrderProInfo proInfo2 = appOrderProInfoMapper.selectOne(Wrappers.<AppOrderProInfo>lambdaQuery()
|
|
|
- .eq(AppOrderProInfo::getFamilyUserId, appOrderProInfo.getFamilyUserId())
|
|
|
- .eq(AppOrderProInfo::getOrderStatus, 1)
|
|
|
- .eq(AppOrderProInfo::getType, 5)
|
|
|
- .orderByAsc(AppOrderProInfo::getExpireTime)
|
|
|
- .last("limit 1"));
|
|
|
+ .isNotNull(AppOrderProInfo::getFrameTimeStr));
|
|
|
+
|
|
|
FamilyMembers familyMembers = familyMembersMapper.selectById(appOrderProInfo.getFamilyUserId());
|
|
|
- for (AppDevice appDevice : appDeviceMapper.selectList(Wrappers.<AppDevice>lambdaQuery().eq(AppDevice::getSiteId, appSite.getId()))) {
|
|
|
- if (null != appDevice && proInfo1 != null && proInfo2 != null) {
|
|
|
- JsonObject addUserJson = JsonParser.parseString(addUser(new DateTime(proInfo2.getExpireTime()),
|
|
|
- appDevice.getDeviceSerial(),
|
|
|
- appOrderProInfo.getUserName(),
|
|
|
- familyMembers.getId(), new DateTime(proInfo1.getExpireTime()), appOrderProInfo.getFrameTimeStr())).getAsJsonObject();
|
|
|
- JsonObject addFaceJson = JsonParser.parseString(addFace(appDevice.getDeviceSerial(), familyMembers.getId(),
|
|
|
- familyMembers.getRealNameImg())).getAsJsonObject();
|
|
|
- if (addUserJson.get("code").getAsInt() != 0 && addFaceJson.get("code").getAsInt() != 0) {
|
|
|
- throw new JeecgBootException("设备录入用户信息失败!请联系管理员");
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(allCourseOrders)) {
|
|
|
+ // 解析所有订单的frameTimeStr,找出最早和最晚的日期
|
|
|
+ LocalDate earliestStartDate = null;
|
|
|
+ LocalDate latestEndDate = null;
|
|
|
+
|
|
|
+ for (AppOrderProInfo courseOrder : allCourseOrders) {
|
|
|
+ String frameTimeStr = courseOrder.getFrameTimeStr();
|
|
|
+ if (frameTimeStr != null && !frameTimeStr.isEmpty()) {
|
|
|
+ try {
|
|
|
+ // 解析 "yyyy-MM-dd-MM-dd" 格式
|
|
|
+ String[] parts = frameTimeStr.split("-");
|
|
|
+ if (parts.length == 5) {
|
|
|
+ String startDateStr = parts[0] + "-" + parts[1] + "-" + parts[2];
|
|
|
+ String endDateStr = parts[0] + "-" + parts[3] + "-" + parts[4];
|
|
|
+
|
|
|
+ LocalDate startDate = LocalDate.parse(startDateStr);
|
|
|
+ LocalDate endDate = LocalDate.parse(endDateStr);
|
|
|
+
|
|
|
+ // 找出最早的开始日期
|
|
|
+ if (earliestStartDate == null || startDate.isBefore(earliestStartDate)) {
|
|
|
+ earliestStartDate = startDate;
|
|
|
+ }
|
|
|
+ // 找出最晚的结束日期
|
|
|
+ if (latestEndDate == null || endDate.isAfter(latestEndDate)) {
|
|
|
+ latestEndDate = endDate;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 解析失败,跳过该订单
|
|
|
+ log.error("解析课程订单frameTimeStr失败: {}", frameTimeStr, e);
|
|
|
+ }
|
|
|
}
|
|
|
- }else if (null != appDevice) {
|
|
|
- JsonObject addUserJson = JsonParser.parseString(addUser(new Date(),
|
|
|
- appDevice.getDeviceSerial(),
|
|
|
- appOrderProInfo.getUserName(),
|
|
|
- familyMembers.getId(), new DateTime(appOrderProInfo.getExpireTime()), appOrderProInfo.getFrameTimeStr())).getAsJsonObject();
|
|
|
- JsonObject addFaceJson = JsonParser.parseString(addFace(appDevice.getDeviceSerial(), familyMembers.getId(),
|
|
|
- familyMembers.getRealNameImg())).getAsJsonObject();
|
|
|
- if (addUserJson.get("code").getAsInt() != 0 && addFaceJson.get("code").getAsInt() != 0) {
|
|
|
- throw new JeecgBootException("设备录入用户信息失败!请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果找到了有效的日期范围,合并为一个frameTimeStr
|
|
|
+ if (earliestStartDate != null && latestEndDate != null) {
|
|
|
+ // 构造合并后的frameTimeStr: "yyyy-MM-dd-MM-dd"
|
|
|
+ String mergedFrameTimeStr = earliestStartDate.getYear() + "-" +
|
|
|
+ String.format("%02d", earliestStartDate.getMonthValue()) + "-" +
|
|
|
+ String.format("%02d", earliestStartDate.getDayOfMonth()) + "-" +
|
|
|
+ String.format("%02d", latestEndDate.getMonthValue()) + "-" +
|
|
|
+ String.format("%02d", latestEndDate.getDayOfMonth());
|
|
|
+
|
|
|
+ // 使用合并后的时间范围更新门禁权限
|
|
|
+ for (AppDevice appDevice : appDeviceMapper.selectList(Wrappers.<AppDevice>lambdaQuery().eq(AppDevice::getSiteId, appSite.getId()))) {
|
|
|
+ if (null != appDevice) {
|
|
|
+ JsonObject addUserJson = JsonParser.parseString(addUser(
|
|
|
+ new Date(), // inputDate可以传任意值,会被frameTimeStr覆盖
|
|
|
+ appDevice.getDeviceSerial(),
|
|
|
+ appOrderProInfo.getUserName(),
|
|
|
+ familyMembers.getId(),
|
|
|
+ null, // endDate会被frameTimeStr覆盖
|
|
|
+ mergedFrameTimeStr)).getAsJsonObject();
|
|
|
+ JsonObject addFaceJson = JsonParser.parseString(addFace(
|
|
|
+ appDevice.getDeviceSerial(),
|
|
|
+ familyMembers.getId(),
|
|
|
+ familyMembers.getRealNameImg())).getAsJsonObject();
|
|
|
+ if (addUserJson.get("code").getAsInt() != 0 && addFaceJson.get("code").getAsInt() != 0) {
|
|
|
+ throw new JeecgBootException("设备录入用户信息失败!请联系管理员");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (null != appOrderProInfo.getFrameTimeStr()) {
|
|
|
+ // 如果只有当前订单,直接使用当前订单的frameTimeStr
|
|
|
+ for (AppDevice appDevice : appDeviceMapper.selectList(Wrappers.<AppDevice>lambdaQuery().eq(AppDevice::getSiteId, appSite.getId()))) {
|
|
|
+ if (null != appDevice) {
|
|
|
+ JsonObject addUserJson = JsonParser.parseString(addUser(
|
|
|
+ new Date(),
|
|
|
+ appDevice.getDeviceSerial(),
|
|
|
+ appOrderProInfo.getUserName(),
|
|
|
+ familyMembers.getId(),
|
|
|
+ null,
|
|
|
+ appOrderProInfo.getFrameTimeStr())).getAsJsonObject();
|
|
|
+ JsonObject addFaceJson = JsonParser.parseString(addFace(
|
|
|
+ appDevice.getDeviceSerial(),
|
|
|
+ familyMembers.getId(),
|
|
|
+ familyMembers.getRealNameImg())).getAsJsonObject();
|
|
|
+ if (addUserJson.get("code").getAsInt() != 0 && addFaceJson.get("code").getAsInt() != 0) {
|
|
|
+ throw new JeecgBootException("设备录入用户信息失败!请联系管理员");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|