Przeglądaj źródła

修改文档提出的问题

许智捷 2 lat temu
rodzic
commit
c57a0930e5
40 zmienionych plików z 1167 dodań i 379 usunięć
  1. 56 4
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/BusBookingRoomsController.java
  2. 1 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/BusOrderFeeController.java
  3. 45 9
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/BusRoomBookingOrdersController.java
  4. 2 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/dto/BookingOrderSaveDto.java
  5. 3 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/BusBookingRooms.java
  6. 9 9
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/BusMemberMessage.java
  7. 14 3
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/BusRoomsLivingOrder.java
  8. 7 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/BusBookingRoomsMapper.java
  9. 17 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/BusRoomBookingOrdersMapper.java
  10. 21 1
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/BusRoomBookingOrdersMapper.xml
  11. 3 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/IBusBookingRoomsService.java
  12. 5 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/IBusMarketAgreementUnitService.java
  13. 13 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/IBusMemberCardService.java
  14. 1 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/IBusRoomBookingOrdersService.java
  15. 10 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/BusBookingRoomsServiceImpl.java
  16. 49 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/BusMarketMarketAgreementUnitServiceImpl.java
  17. 41 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/BusMemberCardServiceImpl.java
  18. 33 63
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/BusOrderFeeServiceImpl.java
  19. 426 78
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/BusRoomBookingOrdersServiceImpl.java
  20. 3 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/vo/RiLiFangTaiVo.java
  21. 4 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/vo/RoomLivingQueryVo.java
  22. 0 1
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/kc/entity/KcDepositoryInGoods.java
  23. 89 9
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/order/controller/CesOrderLeaseGoodsController.java
  24. 13 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/order/entity/CesOrderLeaseGoods.java
  25. 11 103
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/controller/PosOrderGoodsController.java
  26. 84 19
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/controller/PosOrderGoodsPaymentController.java
  27. 2 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/dto/OrderPaymentDto.java
  28. 4 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/entity/PosOrderGoods.java
  29. 2 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/service/IPosOrderGoodsService.java
  30. 150 17
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/service/impl/PosOrderGoodsServiceImpl.java
  31. 1 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/LivingRoomOrderFeeJob.java
  32. 1 1
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/DTO/CesGoodsSearchDto.java
  33. 2 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/DTO/CesRoomSearchDto.java
  34. 3 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/Vo/BookingRealtimeVo.java
  35. 5 2
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/controller/CesRoomsController.java
  36. 2 2
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/entity/CesAllDayPriceRule.java
  37. 2 2
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/mapper/CesRoomsMapper.java
  38. 26 54
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/mapper/xml/CesRoomsMapper.xml
  39. 2 1
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/service/CesGoodsServiceImpl.java
  40. 5 1
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/service/CesRoomsServiceImpl.java

+ 56 - 4
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/BusBookingRoomsController.java

@@ -1,18 +1,24 @@
 package org.jeecg.modules.business.controller;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
 import java.util.stream.Collectors;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.business.entity.BusBookingRooms;
+import org.jeecg.modules.business.entity.BusRoomBookingOrders;
 import org.jeecg.modules.business.service.IBusBookingRoomsService;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -20,6 +26,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
 
+import org.jeecg.modules.business.service.IBusRoomBookingOrdersService;
+import org.jeecg.modules.rooms.entity.CesRooms;
+import org.jeecg.modules.rooms.mapper.CesRoomsMapper;
+import org.jeecg.modules.rooms.service.CesRoomsServiceImpl;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
 import org.jeecgframework.poi.excel.entity.ExportParams;
@@ -50,7 +60,12 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
 public class BusBookingRoomsController extends JeecgController<BusBookingRooms, IBusBookingRoomsService> {
 	@Autowired
 	private IBusBookingRoomsService busBookingRoomsService;
-
+	@Resource
+	private CesRoomsMapper roomsMapper;
+	 @Resource
+	 private IBusRoomBookingOrdersService roomBookingOrdersService;
+	 @Resource
+	 private CesRoomsServiceImpl roomsService;
 	/**
 	 * 分页列表查询
 	 *
@@ -102,6 +117,43 @@ public class BusBookingRoomsController extends JeecgController<BusBookingRooms,
 		busBookingRoomsService.updateById(busBookingRooms);
 		return Result.OK("编辑成功!");
 	}
+
+	 /**
+	  *  批量排房
+	  * @param ids
+	  * @return
+	  */
+	 @AutoLog(value = "预定订单关联房间-批量排房")
+	 @ApiOperation(value="预定订单关联房间-批量排房", notes="预定订单关联房间-批量排房")
+	 @RequestMapping(value = "/editBatch", method = {RequestMethod.POST})
+	 public Result<String> editBatch(@RequestBody List<String> ids,String hotelId) {
+		 if (CollUtil.isEmpty(ids)){
+			 return Result.error("参数异常");
+		 }
+		 LambdaQueryWrapper<BusBookingRooms> wrapper = new LambdaQueryWrapper<>();
+		 wrapper.eq(BusBookingRooms::getRoomStatus, 1);
+		 wrapper.in(BusBookingRooms::getId, ids);
+		 List<BusBookingRooms> bookingRooms = busBookingRoomsService.list(wrapper);
+		 if (ids.size() != bookingRooms.size()){
+			 return Result.error("未找到预约单");
+		 }
+		 BusRoomBookingOrders bookingOrder = roomBookingOrdersService.getById(bookingRooms.get(0).getBookingOrdersId());
+		 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+		 List<CesRooms> cesRooms = roomsMapper.canUseRooms(hotelId, formatter.format(bookingOrder.getArrivalTime()), formatter.format(bookingOrder.getDueOutTime()));
+		 ArrayList<CesRooms> useRoomList = new ArrayList<>();
+		 bookingRooms.forEach(e -> {
+			 cesRooms.forEach(room ->{
+				 if (room.getLayoutId().equals(e.getRoomLayoutId()) && !useRoomList.contains(room)){
+					 e.setRoomId(room.getId());
+					 useRoomList.add(room);
+				 }
+			 });
+		 });
+		 busBookingRoomsService.updateBatchById(bookingRooms);
+		 roomsService.getReserveRoom();
+		 return Result.OK("编辑成功!");
+	 }
+
 	 /**
 	  *  设置为主房
 	  *

+ 1 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/BusOrderFeeController.java

@@ -164,6 +164,7 @@ public class BusOrderFeeController extends JeecgController<BusOrderFee, IBusOrde
 	 public Result<List<BusOrderFee>> refundList(@RequestBody List<String> livingOrderIds) {
 		 LambdaQueryWrapper<BusOrderFee> qw = new LambdaQueryWrapper<>();
 		 qw.eq(BusOrderFee::getFeeType, FeeType.COLLECTION.getKey());
+		 qw.eq(BusOrderFee::getPreferentialStatus, 1);
 		 qw.in(CollUtil.isNotEmpty(livingOrderIds), BusOrderFee::getLivingOrderId, livingOrderIds);
 		 List<BusOrderFee> orderFees = busOrderFeeService.list(qw);
 		 return Result.OK(orderFees);

+ 45 - 9
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/BusRoomBookingOrdersController.java

@@ -28,6 +28,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
 
+import org.jeecg.modules.business.service.IBusRoomsLivingOrderService;
 import org.jeecg.modules.business.service.impl.BusBookingRoomsServiceImpl;
 import org.jeecg.modules.business.service.impl.BusOrderFeeServiceImpl;
 import org.jeecg.modules.business.vo.*;
@@ -65,7 +66,8 @@ public class BusRoomBookingOrdersController extends JeecgController<BusRoomBooki
 	@Resource
 	private IBusRoomBookingOrdersService busRoomBookingOrdersService;
 
-	private IBusBookingRoomsService busBookingRoomsService;
+	@Resource
+	private IBusRoomsLivingOrderService roomsLivingOrderService;
 	/**
 	 * 分页列表查询
 	 *
@@ -84,7 +86,7 @@ public class BusRoomBookingOrdersController extends JeecgController<BusRoomBooki
 								   HttpServletRequest req) {
 		QueryWrapper<BusRoomBookingOrders> queryWrapper = QueryGenerator.initQueryWrapper(busRoomBookingOrders, req.getParameterMap());
 		Page<BusRoomBookingOrders> page = new Page<BusRoomBookingOrders>(pageNo, pageSize);
-		IPage<BusRoomBookingOrders> pageList = busRoomBookingOrdersService.page(page, queryWrapper);
+		IPage<BusRoomBookingOrders> pageList = service.page(page, queryWrapper);
 		return Result.OK(pageList);
 	}
 
@@ -102,7 +104,7 @@ public class BusRoomBookingOrdersController extends JeecgController<BusRoomBooki
 		Boolean isTeam = busRoomBookingOrders.getOrderInfo().getBookingOrdersType().equals(2);
 		busRoomBookingOrders.getOrderInfo().setBookingOrdersType(1);
 		busRoomBookingOrders.getOrderInfo().setBookingStatus(1);
-		return Result.OK("预定成功",busRoomBookingOrdersService.bookingOrderSave(busRoomBookingOrders,isTeam,false,hotelId));
+		return Result.OK("预定成功",service.bookingOrderSave(busRoomBookingOrders,isTeam,false,hotelId));
 	}
 	 /**
 	  *   添加批次订单
@@ -115,7 +117,7 @@ public class BusRoomBookingOrdersController extends JeecgController<BusRoomBooki
 	 //@RequiresPermissions("business:bus_room_booking_orders:add")
 	 @PostMapping(value = "/add-batch")
 	 public Result<String> addBatchOrder(@RequestBody BatchOrderSavaDto batchOrderSavaDto) {
-		 return Result.OK("预定成功",busRoomBookingOrdersService.batchOrderSave(batchOrderSavaDto));
+		 return Result.OK("预定成功",service.batchOrderSave(batchOrderSavaDto));
 	 }
 	/**
 	 *  编辑
@@ -128,7 +130,7 @@ public class BusRoomBookingOrdersController extends JeecgController<BusRoomBooki
 	//@RequiresPermissions("business:bus_room_booking_orders:edit")
 	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
 	public Result<Boolean> edit(@RequestBody BookingOrderEditVo busRoomBookingOrders) {
-		return Result.OK("编辑预定成功",busRoomBookingOrdersService.editBooking(busRoomBookingOrders));
+		return Result.OK("编辑预定成功",service.editBooking(busRoomBookingOrders));
 	}
 
 	 /**
@@ -157,7 +159,7 @@ public class BusRoomBookingOrdersController extends JeecgController<BusRoomBooki
 	//@RequiresPermissions("business:bus_room_booking_orders:delete")
 	@DeleteMapping(value = "/delete")
 	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
-		busRoomBookingOrdersService.removeOrder(id);
+		service.removeOrder(id);
 		return Result.OK("删除成功!");
 	}
 
@@ -172,7 +174,7 @@ public class BusRoomBookingOrdersController extends JeecgController<BusRoomBooki
 	 //@RequiresPermissions("business:bus_room_booking_orders:delete")
 	 @PostMapping(value = "/set-booking-status")
 	 public Result<String> delete(@RequestBody BusRoomBookingOrders order) {
-		 busRoomBookingOrdersService.setOrderStatus(order);
+		 service.setOrderStatus(order);
 		 return Result.OK("设置成功!");
 	 }
 
@@ -187,7 +189,7 @@ public class BusRoomBookingOrdersController extends JeecgController<BusRoomBooki
 	//@RequiresPermissions("business:bus_room_booking_orders:deleteBatch")
 	@DeleteMapping(value = "/deleteBatch")
 	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
-		this.busRoomBookingOrdersService.removeByIds(Arrays.asList(ids.split(",")));
+		service.removeByIds(Arrays.asList(ids.split(",")));
 		return Result.OK("批量删除成功!");
 	}
 
@@ -201,7 +203,7 @@ public class BusRoomBookingOrdersController extends JeecgController<BusRoomBooki
 	@ApiOperation(value="酒店预定订单-通过id查询", notes="酒店预定订单-通过id查询")
 	@GetMapping(value = "/queryById")
 	public Result<BusRoomBookingOrders> queryById(@RequestParam(name="id",required=true) String id) {
-		BusRoomBookingOrders busRoomBookingOrders = busRoomBookingOrdersService.getById(id);
+		BusRoomBookingOrders busRoomBookingOrders = service.getById(id);
 		if(busRoomBookingOrders==null) {
 			return Result.error("未找到对应数据");
 		}
@@ -395,6 +397,19 @@ public class BusRoomBookingOrdersController extends JeecgController<BusRoomBooki
 	 }
 
 	 /**
+	  * 获取可联房入住订单列表
+	  * @param status
+	  * @return
+	  */
+	 @ApiOperation(value="酒店预定订单-获取入住订单", notes="酒店预定订单-获取入住订单")
+	 @RequestMapping(value = "/union-living-orders",method = RequestMethod.GET)
+	 public Result<IPage<RoomLivingQueryVo>> unionLivingOrders(Page<RoomLivingQueryVo> page, String keyw, Integer status,String hotelId){
+		 return Result.OK(service.getUnionLivingPageData(keyw,page,hotelId));
+	 }
+
+
+
+	 /**
 	  * 新增收费项目
 	  * @param orders
 	  * @param livingOrderId
@@ -437,6 +452,16 @@ public class BusRoomBookingOrdersController extends JeecgController<BusRoomBooki
 	 }
 
 	 /**
+	  * 合并联房
+	  * @return
+	  */
+	 @ApiOperation(value="酒店预定订单-合并联房", notes="酒店预定订单-合并联房")
+	 @RequestMapping(value = "/merge-order2",method = RequestMethod.POST)
+	 public Result<Boolean> mergeOrder2(String hotelId, String livingRoomId,@RequestBody List<String> livingOrderIds ){
+		 return  Result.OK(service.mergeOrder(hotelId,livingRoomId,livingOrderIds));
+	 }
+
+	 /**
 	  * 远期房态
 	  * @return
 	  */
@@ -573,4 +598,15 @@ public class BusRoomBookingOrdersController extends JeecgController<BusRoomBooki
 		 Boolean onlyPaySelf = service.payPortionFee(feeIds);
 		 return  Result.OK(onlyPaySelf);
 	 }
+
+
+
+	 @ApiOperation(value = "修改房间状态", notes = "修改房间状态")
+	 @GetMapping(value = "/changeState")
+	 public Result<String> changeState(BusRoomsLivingOrder roomsLivingOrder){
+		 boolean update = roomsLivingOrderService.updateById(roomsLivingOrder);
+		 System.out.println(roomsLivingOrder);
+		 return update ? Result.OK("修改房态成功") : Result.error("修改房态失败");
+	 }
+
  }

+ 2 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/dto/BookingOrderSaveDto.java

@@ -29,6 +29,8 @@ public class BookingOrderSaveDto  {
     private String contactName;
     // 联系人电话
     private String phone;
+    // 联系人证件号
+    private String certNo;
     // 确认入住
     private Boolean confirm;
     private String hotelId;

+ 3 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/BusBookingRooms.java

@@ -66,4 +66,7 @@ public class BusBookingRooms implements Serializable {
     @TableField(exist = false)
     private String layoutId;
 
+    @TableField(exist = false)
+    private String roomsName;
+
 }

+ 9 - 9
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/BusMemberMessage.java

@@ -55,15 +55,15 @@ public class BusMemberMessage implements Serializable {
     @ApiModelProperty(value = "留言人")
     private String userName;
 	/**自动提醒时间*/
-	@Excel(name = "自动提醒时间", width = 15, format = "yyyy-MM-dd")
-	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
-    @DateTimeFormat(pattern="yyyy-MM-dd")
+	@Excel(name = "自动提醒时间", width = 15, format = "yyyy-MM-dd HH:mm:ss")
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
     @ApiModelProperty(value = "自动提醒时间")
     private Date remindDate;
 	/**有效时间*/
-	@Excel(name = "有效时间", width = 15, format = "yyyy-MM-dd")
-	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
-    @DateTimeFormat(pattern="yyyy-MM-dd")
+	@Excel(name = "有效时间", width = 15, format = "yyyy-MM-dd HH:mm:ss")
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
     @ApiModelProperty(value = "有效时间")
     private Date validDate;
 	/**是否传达*/
@@ -75,9 +75,9 @@ public class BusMemberMessage implements Serializable {
     @ApiModelProperty(value = "留言内容")
     private String contentBody;
 	/**创建时间*/
-	@Excel(name = "创建时间", width = 15, format = "yyyy-MM-dd")
-	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
-    @DateTimeFormat(pattern="yyyy-MM-dd")
+	@Excel(name = "创建时间", width = 15, format = "yyyy-MM-dd HH:mm")
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH-mm")
     @ApiModelProperty(value = "创建时间")
     private Date createDate;
 

+ 14 - 3
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/BusRoomsLivingOrder.java

@@ -204,9 +204,6 @@ public class BusRoomsLivingOrder implements Serializable {
     @ApiModelProperty(value = "批次id")
     private String batchId;
 
-    @TableField(exist = false)
-    private Boolean isTeam;
-
     @Excel(name = "结账类型", width = 15)
     @ApiModelProperty(value = "结账类型")
     private Integer settleType;
@@ -221,6 +218,17 @@ public class BusRoomsLivingOrder implements Serializable {
     @ApiModelProperty(value = "第三方用戶ID")
     private String thirdLoginUserId;
 
+    /**是否主房*/
+    @ApiModelProperty(value = "免打扰")
+    private Boolean ddisturb;
+    /**是否主房*/
+
+    @ApiModelProperty(value = "免查询")
+    private Boolean dquery;
+
+    @ApiModelProperty(value = "保密房")
+    private Boolean secrecy;
+
     @TableField(exist = false)
     private BigDecimal xiaoFei;
 
@@ -238,6 +246,9 @@ public class BusRoomsLivingOrder implements Serializable {
     private Boolean isRel;
 
     @TableField(exist = false)
+    private Boolean isTeam;
+
+    @TableField(exist = false)
     private String relTag;
 
 }

+ 7 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/BusBookingRoomsMapper.java

@@ -31,4 +31,11 @@ public interface BusBookingRoomsMapper extends BaseMapper<BusBookingRooms> {
 
     @Update("update bus_booking_rooms set is_main = 0 where booking_orders_id = #{orderId}")
     Boolean setNotMain(String orderId);
+
+    @Select("<script>select bbr.*, cr.name as rooms_name from bus_booking_rooms bbr " +
+            "left join ces_rooms cr on bbr.room_id = cr.id " +
+            "where bbr.booking_orders_id in" +
+            "<foreach item='id' collection='booingIds' open='(' separator=',' close=')'> " +
+            "#{ id } </foreach> </script>")
+    List<BusBookingRooms> bookingRoomsDetail(List<String> booingIds);
 }

+ 17 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/BusRoomBookingOrdersMapper.java

@@ -36,6 +36,9 @@ public interface BusRoomBookingOrdersMapper extends BaseMapper<BusRoomBookingOrd
 
     IPage<RoomLivingQueryVo> getPage(IPage<RoomLivingQueryVo> page,@Param("status") Integer status,@Param("keyw") String keyw,@Param("hotelId") String hotelId);
 
+
+    IPage<RoomLivingQueryVo> getUnionPage(IPage<RoomLivingQueryVo> page, @Param("keyw") String keyw,@Param("hotelId") String hotelId ,@Param("isMain") Boolean isMain,@Param("bookingIds") List<String> bookingIds);
+
     List<ForwardFangTaiQueryVo> forwardFangTaiQuery(String hotelId,
                                                     String start,
                                                     String end);
@@ -77,4 +80,18 @@ public interface BusRoomBookingOrdersMapper extends BaseMapper<BusRoomBookingOrd
             "inner join ces_rooms cr on cr.id = bbr.room_id " +
             "where bbr.id = #{bookingRoomId}) ")
     List<BusRoomBookingOrders> findBookingOrderByRoom(String bookingRoomId, String arrivalTimeStr);
+
+    @Select("<script>SELECT brbo.id,cr.name from bus_booking_rooms bbr \n" +
+            "left join ces_rooms cr on cr.id = bbr.room_id \n" +
+            "left Join bus_room_booking_orders brbo  on bbr.booking_orders_id = brbo.id\n" +
+            "where \n" +
+            "brbo.booking_status = 1 and bbr.room_status != 4\n" +
+            "AND (( brbo.arrival_time &lt;= #{startOf} AND brbo.due_out_time &gt;= #{startOf} ) \n" +
+            "OR ( brbo.arrival_time &lt;= #{endOf} AND brbo.due_out_time &gt;= #{endOf} )) \n" +
+            "and cr.id in " +
+            "<foreach collection='roomIds' item='id' open='(' separator=',' close=')'> " +
+            "#{id} " +
+            "</foreach> " +
+            "</script>")
+    List<BusRoomBookingOrders> findBookingOrder(List<String> roomIds, Date startOf, Date endOf);
 }

+ 21 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/BusRoomBookingOrdersMapper.xml

@@ -84,6 +84,26 @@
 
     </select>
 
+    <select id="getUnionPage" resultType="org.jeecg.modules.business.vo.RoomLivingQueryVo">
+        select r.room_id, rm.name, tb.living_order_id, o.living_order_no, o.booking_order_id ,r.is_main ,
+               CONCAT(ifnull(rm.`prefix`, ''), rm.`name`) AS room_name, tb.customer_id, tb.customer_name,bt.rel_type,bt.sort_index ,r.room_status
+        from bus_rooms_living_order o
+                 INNER JOIN bus_booking_rooms r ON o.booking_room_id = r.id
+                 INNER JOIN ces_rooms rm ON r.room_id = rm.id
+                 INNER JOIN bus_living_customer tb ON tb.living_order_id = o.id
+                 LEFT JOIN bus_team bt ON bt.booking_order_id = o.booking_order_id and bt.is_delete = 0
+        WHERE o.hotel_id = #{hotelId}  and o.settle_type = -1 and r.is_main = #{isMain}
+        <if test="keyw != null and keyw != ''">
+            and (o.living_order_no like  CONCAT('%', #{keyw}, '%') or rm.`name` like  CONCAT('%', #{keyw}, '%') or tb.customer_name like CONCAT('%', #{keyw}, '%'))
+        </if>
+        <if test="bookingIds != null and bookingIds.size >0">
+            and o.booking_order_id in
+            <foreach collection="bookingIds" item="id" open="(" close=")" separator=",">
+                #{id}
+            </foreach>
+        </if>
+    </select>
+
     <select id="forwardFangTaiQuery" resultType="org.jeecg.modules.business.vo.ForwardFangTaiQueryVo">
 
 
@@ -288,7 +308,7 @@ lo.booking_order_id
         inner join bus_booking_rooms br
         on o.id = br.booking_orders_id
         and br.id
-        <if test="status == 1">
+        <if test="status == 1 or  status == 3">
             not
         </if>
          in (

+ 3 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/IBusBookingRoomsService.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.business.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.apache.ibatis.annotations.Select;
 import org.jeecg.modules.business.entity.BusBookingRooms;
 import com.baomidou.mybatisplus.extension.service.IService;
@@ -17,4 +18,6 @@ public interface IBusBookingRoomsService extends IService<BusBookingRooms> {
 
     List<ExtendBusBookingRoomsVo> bookingRooms(String bookingId, Integer type);
     Boolean setMain(String bookingRoomsId, String livingOrderId);
+
+    List<BusBookingRooms> bookingRoomsDetail(List<String> booingIds);
 }

+ 5 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/IBusMarketAgreementUnitService.java

@@ -2,8 +2,11 @@ package org.jeecg.modules.business.service;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.modules.business.entity.BusAgreementOrderFee;
 import org.jeecg.modules.business.entity.BusMarketAgreementUnit;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -18,4 +21,6 @@ public interface IBusMarketAgreementUnitService extends IService<BusMarketAgreem
      */
     public String getMaxAccount();
 
+    public BusAgreementOrderFee agreementPayFee(BusMarketAgreementUnit marketAgreementUnit, BigDecimal money, String feeId, String hotelId);
+
 }

+ 13 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/IBusMemberCardService.java

@@ -3,10 +3,13 @@ package org.jeecg.modules.business.service;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.business.dto.UserGroupDto;
 import org.jeecg.modules.business.dto.UserLabelDto;
+import org.jeecg.modules.business.entity.BusMemberBalanceLog;
 import org.jeecg.modules.business.entity.BusMemberCard;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.modules.business.vo.MemberCardStatVo;
 
+import java.math.BigDecimal;
+
 /**
  * @Description: bus_member_card
  * @Author: jeecg-boot
@@ -33,4 +36,14 @@ public interface IBusMemberCardService extends IService<BusMemberCard> {
      * @return
      */
     public MemberCardStatVo stat(String hotelId);
+
+    /**
+     * 会员卡支付
+     * @param busMemberCard
+     * @param money
+     * @param feeId
+     * @param hotelId
+     * @return
+     */
+    public BusMemberBalanceLog cardPayFee(BusMemberCard busMemberCard, BigDecimal money, String feeId, String hotelId);
 }

+ 1 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/IBusRoomBookingOrdersService.java

@@ -63,6 +63,7 @@ public interface IBusRoomBookingOrdersService extends IService<BusRoomBookingOrd
     Boolean cancelLeaveNotSettle(String bookingOrderId, String livingOrderId);
 
     IPage<RoomLivingQueryVo> getLivingPageData(Integer status,String keyw, Page<RoomLivingQueryVo> page,String hotelId);
+    IPage<RoomLivingQueryVo> getUnionLivingPageData(String keyw, Page<RoomLivingQueryVo> page,String hotelId);
     IPage<KeLiItemVo> getLivingOrderKL(Integer status,String keyw,String hotelId,String thirdUserId, Page<KeLiItemVo> page);
     IPage<KeLiItemVo> getBookingOrderKL(Integer status,String keyw,String hotelId,String thirdUserId, Page<KeLiItemVo> page);
     Boolean setLivingOrderFee(List<BusOrderFee> fees,String livingOrderId,String hotelId);

+ 10 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/BusBookingRoomsServiceImpl.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.business.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.modules.business.entity.BusBookingRooms;
@@ -14,6 +15,7 @@ import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -54,4 +56,12 @@ public class BusBookingRoomsServiceImpl extends ServiceImpl<BusBookingRoomsMappe
         updateById(roomR);
         return true;
     }
+
+    @Override
+    public List<BusBookingRooms> bookingRoomsDetail(List<String> booingIds) {
+        if (CollUtil.isEmpty(booingIds)){
+            return new ArrayList<>();
+        }
+        return baseMapper.bookingRoomsDetail(booingIds);
+    }
 }

+ 49 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/BusMarketMarketAgreementUnitServiceImpl.java

@@ -1,6 +1,12 @@
 package org.jeecg.modules.business.service.impl;
 
+import cn.hutool.core.date.DateTime;
+import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.TokenUtils;
+import org.jeecg.modules.business.entity.BusAgreementOrderFee;
 import org.jeecg.modules.business.entity.BusMarketAgreementUnit;
+import org.jeecg.modules.business.enums.AgreementOrderStatusEnum;
 import org.jeecg.modules.business.mapper.BusMarketAgreementUnitMapper;
 import org.jeecg.modules.business.service.IBusMarketAgreementUnitService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -8,6 +14,8 @@ import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.util.List;
 
 /**
@@ -29,4 +37,45 @@ public class BusMarketMarketAgreementUnitServiceImpl extends ServiceImpl<BusMark
         return  maxAccount;
     }
 
+    @Override
+    public BusAgreementOrderFee agreementPayFee(BusMarketAgreementUnit marketAgreementUnit, BigDecimal money, String feeId, String hotelId){
+        // 计算余额与账单金额差价,如果差价小于0,将余额置0,将差价加到已用额度。差价大于等于0,直接扣余额
+        BigDecimal differMoney = marketAgreementUnit.getBalance().subtract(money);
+        if (differMoney.compareTo(new BigDecimal(0)) < 0){
+            marketAgreementUnit.setBalance(new BigDecimal(0));
+            marketAgreementUnit.setAmountUsed(marketAgreementUnit.getAmountUsed().subtract(differMoney));
+        } else {
+            marketAgreementUnit.setBalance(differMoney);
+        }
+        // 已用额度大于记账额度,抛出异常
+        if (marketAgreementUnit.getBookkeeping() != null
+                && (marketAgreementUnit.getAmountUsed().compareTo(marketAgreementUnit.getBookkeeping()) > 0)){
+            throw new JeecgBootException(marketAgreementUnit.getCustomerName() + "超过记账额度");
+        }
+        return addAgreementOrderFee(feeId, money, marketAgreementUnit.getId(), true);
+    }
+
+    public BusAgreementOrderFee addAgreementOrderFee(String feeId, BigDecimal money, String agreeUnitId, Boolean isCollect){
+        LoginUser user = TokenUtils.getAuthUser();
+        BusAgreementOrderFee agreementOrderFee = new BusAgreementOrderFee();
+        agreementOrderFee.setAgreementUnitId(agreeUnitId);
+        agreementOrderFee.setCreateUserId(user.getId());
+        agreementOrderFee.setOrderFeeId(feeId);
+        //生成订单号
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+        agreementOrderFee.setOrderNo("R"+sdf.format(System.currentTimeMillis()));
+        agreementOrderFee.setStatus(AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
+        // 商品消费
+        agreementOrderFee.setType(3);
+        if (isCollect){
+            agreementOrderFee.setPayPrice(money);
+            agreementOrderFee.setProjectName("收款");
+        } else {
+            agreementOrderFee.setProjectName("退款");
+            agreementOrderFee.setPayPrice(money.multiply(new BigDecimal(-1)));
+        }
+        agreementOrderFee.setCreatedTime(new DateTime());
+        return agreementOrderFee;
+    }
+
 }

+ 41 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/BusMemberCardServiceImpl.java

@@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import org.apache.commons.lang3.ObjectUtils;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.TokenUtils;
 import org.jeecg.modules.business.dto.UserGroupDto;
 import org.jeecg.modules.business.dto.UserLabelDto;
 import org.jeecg.modules.business.entity.*;
@@ -16,6 +19,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * @Description: bus_member_card
@@ -82,4 +87,40 @@ public class BusMemberCardServiceImpl extends ServiceImpl<BusMemberCardMapper, B
     public MemberCardStatVo stat(String hotelId) {
         return busMemberCardMapper.stat(hotelId);
     }
+
+    /**
+     *
+     * @param busMemberCard
+     * @param money
+     * @param feeId
+     * @param hotelId
+     * @return
+     */
+    public BusMemberBalanceLog cardPayFee(BusMemberCard busMemberCard, BigDecimal money, String feeId, String hotelId){
+        LoginUser user = TokenUtils.getAuthUser();
+        BigDecimal balance = busMemberCard.getBalance().subtract(money);
+        if (balance.longValue() < 0){
+            throw new JeecgBootException("会员卡余额不足");
+        }
+        busMemberCard.setBalance(balance);
+
+        BusMemberBalanceLog balanceLog = new BusMemberBalanceLog();
+        balanceLog.setOrderFeeId(feeId);
+        balanceLog.setBalance(balance);
+        balanceLog.setType(2);// 扣费
+        balanceLog.setMemberId(busMemberCard.getId());
+        balanceLog.setStatus(1);// TODO:不知道干什么用的 貌似是个啥支付状态
+        balanceLog.setGiveMoney(new BigDecimal(0));
+        balanceLog.setRemarks("收费扣款");
+        balanceLog.setHotelId(hotelId);
+        if(user!=null) {
+            balanceLog.setTenantId(user.getRelTenantIds());
+        }
+        balanceLog.setPaymentMethod("");
+        balanceLog.setPayMoney(new BigDecimal(0));
+        balanceLog.setCode(BusMemberBalanceLogServiceImpl.randomNumber("KF"));
+        balanceLog.setCreateTime(new Date());
+        return balanceLog;
+    }
+
 }

+ 33 - 63
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/BusOrderFeeServiceImpl.java

@@ -47,7 +47,7 @@ public class BusOrderFeeServiceImpl extends ServiceImpl<BusOrderFeeMapper, BusOr
     @Resource
     IBusOrderFeeGoodsService orderFeeGoodsService;
     @Resource
-    IBusMarketAgreementUnitService marketAgreementUnitService;
+    BusMarketMarketAgreementUnitServiceImpl marketAgreementUnitService;
     @Resource
     IBusAgreementOrderFeeService agreementOrderFeeService;
     @Resource
@@ -133,7 +133,7 @@ public class BusOrderFeeServiceImpl extends ServiceImpl<BusOrderFeeMapper, BusOr
                         } else {
                             agreement.setAmountUsed(differMoney);
                         }
-                        BusAgreementOrderFee agreementOrderFee = addAgreementOrderFee(fee, agreement.getId(), false);
+                        BusAgreementOrderFee agreementOrderFee = marketAgreementUnitService.addAgreementOrderFee(fee.getId(), fee.getMoney(), agreement.getId(), false);
                         agreementOrderFeeList.add(agreementOrderFee);
                     });
                 });
@@ -149,17 +149,17 @@ public class BusOrderFeeServiceImpl extends ServiceImpl<BusOrderFeeMapper, BusOr
         return saveBatch(busOrderFeeList);
     }
 
+
     @Override
     public Boolean collectionBatch(List<BusOrderFee> busOrderFeeList, String hotelId) {
-        LoginUser user = TokenUtils.getAuthUser();
         List<BusRoomPayType> payTypeList = payTypeService.list();
         payTypeList.stream().filter(e -> "会员卡".equals(e.getName())).findFirst().ifPresent(type -> {
             //找出会员支付的账单,将会员支付的账单中的会员id去重
             List<BusOrderFee> MemberPayFee = busOrderFeeList.stream().filter(fee -> type.getId().equals(fee.getPayType())).collect(Collectors.toList());
             List<String> cardIds = MemberPayFee.stream().map(BusOrderFee::getVipCardId).filter(StrUtil::isNotEmpty).distinct().collect(Collectors.toList());
-            List<BusMemberCard> busMemberCards;
+//            List<BusMemberCard> busMemberCards;
             if (CollUtil.isNotEmpty(cardIds)) {
-                busMemberCards = memberCardService.listByIds(cardIds);
+                List<BusMemberCard> busMemberCards = memberCardService.listByIds(cardIds);
                 if(CollUtil.isEmpty(busMemberCards) || cardIds.size() != busMemberCards.size()) {
                     throw new JeecgBootException("会员卡匹配异常");
                 }
@@ -171,29 +171,9 @@ public class BusOrderFeeServiceImpl extends ServiceImpl<BusOrderFeeMapper, BusOr
                         throw new JeecgBootException("支付方式为会员但没有会员id");
                     }
                     BusMemberCard busMemberCard = busMemberCards.stream().filter(card -> card.getId().equals(fee.getVipCardId())).findFirst().get();
-                    BigDecimal balance = busMemberCard.getBalance().subtract(fee.getMoney());
-                    if (balance.longValue() < 0){
-                        throw new JeecgBootException("会员卡余额不足");
-                    }
-                    busMemberCard.setBalance(balance);
-
-                    BusMemberBalanceLog balanceLog = new BusMemberBalanceLog();
-                    balanceLog.setOrderFeeId(fee.getId());
-                    balanceLog.setBalance(balance);
+                    // 会员卡扣款, 产生会员消费记录
+                    BusMemberBalanceLog balanceLog = memberCardService.cardPayFee(busMemberCard, fee.getMoney(), fee.getId(), hotelId);
                     balanceLog.setWithhold(fee.getMoney());
-                    balanceLog.setType(2);// 扣费
-                    balanceLog.setMemberId(busMemberCard.getId());
-                    balanceLog.setStatus(1);// TODO:不知道干什么用的 貌似是个啥支付状态
-                    balanceLog.setGiveMoney(new BigDecimal(0));
-                    balanceLog.setRemarks("收费扣款");
-                    balanceLog.setHotelId(hotelId);
-                    if(user!=null) {
-                        balanceLog.setTenantId(user.getRelTenantIds());
-                    }
-                    balanceLog.setPaymentMethod("");
-                    balanceLog.setPayMoney(new BigDecimal(0));
-                    balanceLog.setCode(BusMemberBalanceLogServiceImpl.randomNumber("KF"));
-                    balanceLog.setCreateTime(new Date());
                     busMemberBalanceLogs.add(balanceLog);
                 });
                 memberCardService.updateBatchById(busMemberCards);
@@ -217,20 +197,9 @@ public class BusOrderFeeServiceImpl extends ServiceImpl<BusOrderFeeMapper, BusOr
                     // 找出账单匹配的合同单位
                     BusMarketAgreementUnit marketAgreementUnit = marketAgreementUnitList.stream().filter(agreement ->
                             agreement.getId().equals(fee.getAgreementUnitId())).findFirst().get();
-                    // 计算余额与账单金额差价,如果差价小于0,将余额置0,将差价加到已用额度。差价大于等于0,直接扣余额
-                    BigDecimal differMoney = marketAgreementUnit.getBalance().subtract(fee.getMoney());
-                    if (differMoney.compareTo(new BigDecimal(0)) < 0){
-                        marketAgreementUnit.setBalance(new BigDecimal(0));
-                        marketAgreementUnit.setAmountUsed(marketAgreementUnit.getAmountUsed().subtract(differMoney));
-                    } else {
-                        marketAgreementUnit.setBalance(differMoney);
-                    }
-                    // 已用额度大于记账额度,抛出异常
-                    if (marketAgreementUnit.getBookkeeping() != null
-                            && (marketAgreementUnit.getAmountUsed().compareTo(marketAgreementUnit.getBookkeeping()) > 0)){
-                        throw new JeecgBootException(marketAgreementUnit.getCustomerName() + "超过记账额度");
-                    }
-                    agreementOrderFeeList.add(addAgreementOrderFee(fee, marketAgreementUnit.getId(), true));
+                    // 单位合同扣款或挂账, 产生消费记录
+                    BusAgreementOrderFee agreementOrderFee = marketAgreementUnitService.agreementPayFee(marketAgreementUnit, fee.getMoney(), fee.getId(), hotelId);
+                    agreementOrderFeeList.add(agreementOrderFee);
                 });
                 marketAgreementUnitService.updateBatchById(marketAgreementUnitList);
                 agreementOrderFeeService.saveBatch(agreementOrderFeeList);
@@ -240,28 +209,29 @@ public class BusOrderFeeServiceImpl extends ServiceImpl<BusOrderFeeMapper, BusOr
         return saveBatch(busOrderFeeList);
     }
 
-    public BusAgreementOrderFee addAgreementOrderFee(BusOrderFee fee, String agreeUnitId, Boolean isCollect){
-        LoginUser user = TokenUtils.getAuthUser();
-        BusAgreementOrderFee agreementOrderFee = new BusAgreementOrderFee();
-        agreementOrderFee.setAgreementUnitId(agreeUnitId);
-        agreementOrderFee.setCreateUserId(user.getId());
-        agreementOrderFee.setOrderFeeId(fee.getId());
-        //生成订单号
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
-        agreementOrderFee.setOrderNo("R"+sdf.format(System.currentTimeMillis()));
-        agreementOrderFee.setStatus(AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
-        // 商品消费
-        agreementOrderFee.setType(3);
-        if (isCollect){
-            agreementOrderFee.setPayPrice(fee.getMoney());
-            agreementOrderFee.setProjectName("房费收款");
-        } else {
-            agreementOrderFee.setProjectName("房费退款");
-            agreementOrderFee.setPayPrice(fee.getMoney().multiply(new BigDecimal(-1)));
-        }
-        agreementOrderFee.setCreatedTime(new DateTime());
-        return agreementOrderFee;
-    }
+
+//    public BusAgreementOrderFee addAgreementOrderFee(String feeId, BigDecimal money, String agreeUnitId, Boolean isCollect){
+//        LoginUser user = TokenUtils.getAuthUser();
+//        BusAgreementOrderFee agreementOrderFee = new BusAgreementOrderFee();
+//        agreementOrderFee.setAgreementUnitId(agreeUnitId);
+//        agreementOrderFee.setCreateUserId(user.getId());
+//        agreementOrderFee.setOrderFeeId(feeId);
+//        //生成订单号
+//        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+//        agreementOrderFee.setOrderNo("R"+sdf.format(System.currentTimeMillis()));
+//        agreementOrderFee.setStatus(AgreementOrderStatusEnum.NOT_SETTLEMENT.getKey());
+//        // 商品消费
+//        agreementOrderFee.setType(3);
+//        if (isCollect){
+//            agreementOrderFee.setPayPrice(money);
+//            agreementOrderFee.setProjectName("收款");
+//        } else {
+//            agreementOrderFee.setProjectName("退款");
+//            agreementOrderFee.setPayPrice(money.multiply(new BigDecimal(-1)));
+//        }
+//        agreementOrderFee.setCreatedTime(new DateTime());
+//        return agreementOrderFee;
+//    }
 
     @Override
     public IPage<RoomOrderFeeVo> strikeBalancePage(Page<RoomOrderFeeVo> page, String roomName, Integer preferentialStatus,String bookingOrderId, DateTime startTime, DateTime endTime) {

+ 426 - 78
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/service/impl/BusRoomBookingOrdersServiceImpl.java

@@ -1,20 +1,20 @@
 package org.jeecg.modules.business.service.impl;
 
-import cn.hutool.core.bean.BeanUtil;
 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;
 import cn.hutool.core.util.StrUtil;
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.SneakyThrows;
-import net.sf.saxon.expr.instruct.ForEach;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.DateUtils;
@@ -26,7 +26,6 @@ import org.jeecg.modules.business.mapper.BusRoomBookingOrdersMapper;
 import org.jeecg.modules.business.service.*;
 import org.jeecg.modules.business.util.MxTools;
 import org.jeecg.modules.business.vo.*;
-import org.jeecg.modules.finance.vo.OrderFeeVo;
 import org.jeecg.modules.fw.entity.FwRoomClean;
 import org.jeecg.modules.fw.entity.FwRoomExamine;
 import org.jeecg.modules.fw.entity.FwRoomLock;
@@ -37,15 +36,15 @@ import org.jeecg.modules.fw.service.IFwRoomLockService;
 import org.jeecg.modules.fw.service.IFwRoomRepairService;
 import org.jeecg.modules.fw.vo.FwRoomLockVo;
 import org.jeecg.modules.fw.vo.FwRoomRepairVo;
-import org.jeecg.modules.pos.service.IPosJialiaoConfigDetailService;
-import org.jeecg.modules.pos.service.IPosMealSectionService;
 import org.jeecg.modules.rooms.Enum.RoomStatusEnum;
+import org.jeecg.modules.rooms.Enum.TimeOutRuleEnum;
 import org.jeecg.modules.rooms.Vo.BookingRealtimeVo;
 import org.jeecg.modules.rooms.Vo.FloorBuildingRoomVo;
 import org.jeecg.modules.rooms.Vo.LivingRealtimeVo;
 import org.jeecg.modules.rooms.entity.*;
 import org.jeecg.modules.rooms.service.*;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -53,12 +52,9 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.time.Duration;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
@@ -69,6 +65,7 @@ import java.util.stream.Collectors;
  * @Date:   2023-03-25
  * @Version: V1.0
  */
+@Slf4j
 @Service
 public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingOrdersMapper, BusRoomBookingOrders> implements IBusRoomBookingOrdersService {
 
@@ -125,7 +122,6 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
 
     @Resource
     private CesAllDayPriceRuleServiceImpl allDayPriceRuleService;
-
     @Resource
     private CesGoodsServiceImpl cesGoodsServiceImpl;
 
@@ -159,6 +155,9 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
     @Resource
     private IBusCancelService cancelService;
 
+    @Autowired
+    private RedisTemplate<String, Object> redisTemplate;
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String bookingOrderSave(BookingOrderSaveDto item, Boolean isTeam,Boolean isLiving,String hotelId) {
@@ -229,6 +228,7 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
                     newCustomer.setName(item.getContactName());
                     newCustomer.setPhone(item.getPhone());
                     newCustomer.setCertType(1); // 身份证
+                    newCustomer.setCertNo(item.getCertNo()); // 身份证
                     customerService.save(newCustomer);
                     item.getOrderInfo().setContactId(newCustomer.getId());
                 } else {
@@ -253,7 +253,6 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
                     throw new JeecgBootException("入住天数不能小于0");
 
             }
-
             if(item.getRoomIds() == null || item.getRoomIds().size() == 0)
                 throw new JeecgBootException("请选择预定房间");
             if(hotelId == null || hotelId.isEmpty()) throw  new JeecgBootException("参数错误,酒店id");
@@ -316,32 +315,35 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
 
             // 处理预定每天的房型价格 End
 
-            //<editor-fold msg="团队标志">
-            if(isTeam && isLiving) {
-                BusTeam team = new BusTeam();
-                List<BusTeam> existTeams = teamService.list(Wrappers.<BusTeam>query().eq("is_delete", 0).eq("hotel_id", hotelId)
-                        .eq("rel_type",1)); // 1团队房,2联房
-                Integer sortIndex = 1;
-                List<Integer> indexs = existTeams.stream().map(s->s.getSortIndex()).collect(Collectors.toList());
-                while(true){
-                    Integer finalSortIndex = sortIndex;
-                    if(indexs.stream().filter(s->s.equals(finalSortIndex)).count() == 0) {
-                        break;
+            // 预约时不添加联房和团队标识,入住时才添加
+            if (isLiving) {
+                if(isTeam) {
+                    BusTeam team = new BusTeam();
+                    List<BusTeam> existTeams = teamService.list(Wrappers.<BusTeam>query().eq("is_delete", 0).eq("hotel_id", hotelId)
+                            .eq("rel_type",1)); // 1团队房,2联房
+                    Integer sortIndex = 1;
+                    List<Integer> indexs = existTeams.stream().map(s->s.getSortIndex()).collect(Collectors.toList());
+                    while(true){
+                        Integer finalSortIndex = sortIndex;
+                        if(indexs.stream().filter(s->s.equals(finalSortIndex)).count() == 0) {
+                            break;
+                        }
+                        sortIndex++;
+                    }
+                    team.setBookingOrderId(bookingId);
+                    team.setIsDelete(0);
+                    team.setHotelId(hotelId);
+                    team.setSortIndex(sortIndex);
+                    team.setRelType(1);
+
+                    teamService.save(team);
+                } else {
+                    // 散客同时居住
+                    if(item.getRoomIds().size() > 1) {
+                        addBusTeams(hotelId, bookingId);
                     }
-                    sortIndex++;
                 }
-                team.setBookingOrderId(bookingId);
-                team.setIsDelete(0);
-                team.setHotelId(hotelId);
-                team.setSortIndex(sortIndex);
-                team.setRelType(1);
 
-                teamService.save(team);
-            } else {
-//                if(isLiving && item.getRoomIds().size() > 1) {
-//                if(item.getRoomIds().size() > 1) {
-//                    addBusTeams(hotelId, bookingId);
-//                }
             }
             //</editor-fold>
             roomsService.getReserveRoom();
@@ -417,6 +419,7 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
                 dayPriceService.saveBatch(c.getLayoutDayPrices().stream().filter(x->lList.contains(x.getRoomLayoutId())).collect(Collectors.toList()));
                 //批次中处理每天房型价格 End
             });
+            // 改变房间状态
             roomsService.getReserveRoom();
             return item.getOrderInfo().getBookingOrdersNo();
         } else { // not exist type
@@ -464,19 +467,25 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
         BookingOrderEditVo result = new BookingOrderEditVo();
         if(orderInfo.getBookingOrdersType().equals(BookingOrdersType.NORMAL.getKey())) {
             List<ExtendBusBookingRoomsVo> bookingRooms = bookingRoomsService.bookingRooms(orderId,BookingOrdersType.NORMAL.getKey());
+
             List<BusBookingLayoutDayPrice> layoutDayPrices = dayPriceService.list(Wrappers.<BusBookingLayoutDayPrice>query()
             .eq("booking_order_id",orderId));
             bookingRooms.forEach(s->{
                 List<BusBookingLayoutDayPrice> findLayoutPrice = layoutDayPrices.stream().filter(a->a.getRoomLayoutId().equals(s.getRoomLayoutId())).collect(Collectors.toList());
                 s.setLayoutDayPrices(findLayoutPrice);
             });
-            result.setLayoutDayPrices(layoutDayPrices);
-            // 设置不是住脏或者住净的 预约中的房间
-            result.setRoomIds(bookingRooms.stream().filter(r->!(r.getRoomStatus().equals(RoomStatusEnum.LIVE_DIRTY.getKey()) || r.getRoomStatus().equals(RoomStatusEnum.LIVE_CLEAR.getKey()))).collect(Collectors.toList()));
+            if (ObjectUtil.isNotEmpty(orderInfo.getBookingStatus()) && orderInfo.getBookingStatus() == 2){
+                result.setLayoutDayPrices(new ArrayList<>());
+                // 设置不是住脏或者住净的 预约中的房间
+                result.setRoomIds(new ArrayList<>());
+            } else {
+                result.setLayoutDayPrices(layoutDayPrices);
+                // 设置不是住脏或者住净的 预约中的房间
+                result.setRoomIds(bookingRooms.stream().filter(r->!(r.getRoomStatus().equals(RoomStatusEnum.LIVE_DIRTY.getKey()) || r.getRoomStatus().equals(RoomStatusEnum.LIVE_CLEAR.getKey()))).collect(Collectors.toList()));
+            }
             //<editor-fold msg="入住相关信息查询">
             List<ExtendBusBookingRoomsVo> livingRooms = bookingRooms.stream().filter(r->(r.getRoomStatus().equals(RoomStatusEnum.LIVE_DIRTY.getKey()) || r.getRoomStatus().equals(RoomStatusEnum.LIVE_CLEAR.getKey()))).collect(Collectors.toList());
             List<String> livingBookingRoomIds = livingRooms.stream().map(r->r.getId()).collect(Collectors.toList());
-
             List<BusRoomsLivingOrder> livingOrders =
                     livingBookingRoomIds.size() > 0?
                     roomsLivingOrderService.list(Wrappers.<BusRoomsLivingOrder>query()
@@ -622,7 +631,12 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
             updateById(item.getOrderInfo());
             String bookingId = item.getOrderInfo().getId();
             // todo 判定是否有安排冲突的房间
-
+            List<String> roomIds = item.getRoomIds().stream().map(BusBookingRooms::getRoomId).collect(Collectors.toList());
+            List<BusRoomBookingOrders> clashOrder = baseMapper.findBookingOrder(roomIds, item.getOrderInfo().getArrivalTime(), item.getOrderInfo().getDueOutTime());
+            long clashCount = clashOrder.stream().filter(e -> !StrUtil.equals(e.getId(), order.getId())).count();
+            if (clashCount > 0){
+                throw new JeecgBootException("房间预约有冲突");
+            }
 
             //这里不能直接删除  先查询预订单有没有入住记录,如果房间有入住,那么入住过的记录则不能删除
             List<BusRoomsLivingOrder> bookingLivings = roomsLivingOrderService.list(Wrappers.<BusRoomsLivingOrder>query()
@@ -786,10 +800,16 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
     public Boolean setOrderStatus(BusRoomBookingOrders entity) {
         if(entity.getId() == null || entity.getBookingStatus() == null) throw new JeecgBootException("参数错误");
         if(BookingStatusTypeEnum.val(entity.getBookingStatus()) == null) throw new JeecgBootException("状态错误");
-        BusRoomBookingOrders updateModel = new BusRoomBookingOrders();
-        updateModel.setId(entity.getId());
-        updateModel.setBookingStatus(entity.getBookingStatus());
-        updateById(updateModel);
+        LambdaUpdateWrapper<BusRoomBookingOrders> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.set(BusRoomBookingOrders::getBookingStatus, entity.getBookingStatus());
+        updateWrapper.eq(BusRoomBookingOrders::getId, entity.getId());
+        update(updateWrapper);
+        if (BookingStatusTypeEnum.CANCEL.getKey().equals(entity.getBookingStatus())){
+            List<BusBookingRooms> bookingRoomsList = bookingRoomsService.list(Wrappers.<BusBookingRooms>lambdaQuery().eq(BusBookingRooms::getBookingOrdersId, entity.getId()));
+            List<String> roomIds = bookingRoomsList.stream().map(BusBookingRooms::getRoomId).collect(Collectors.toList());
+            roomsService.update(Wrappers.<CesRooms>update().setSql("room_status = last_room_status")
+                    .eq("room_status",RoomStatusEnum.RESERVE.getKey()).in("id",roomIds));
+        }
         return true;
     }
 
@@ -1019,7 +1039,13 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
         livingOrder.setHotelId(hotelId);
 
         livingOrder.setArrivalTime(new Date());// todo 这个地方的入住开始时间应该怎么算
-        if(customers.size() > 0) livingOrder.setContactId(customers.get(0).getCustomerId());
+        if(customers != null && !customers.isEmpty()) {
+            if (StrUtil.isEmpty(customers.get(0).getCustomerId())){
+                long id = new Snowflake().nextId();
+                customers.get(0).setCustomerId(StrUtil.toString(id));
+            }
+            livingOrder.setContactId(customers.get(0).getCustomerId());
+        } else throw new JeecgBootException("请添加入住人信息");
         roomsLivingOrderService.save(livingOrder);
 
         // 添加查房记录 start
@@ -1042,7 +1068,7 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
         //</editor-fold>
 
         //<editor-fold desc="同住人相关">
-        if(customers != null && customers.size() > 0) {
+
             BusRoomsLivingOrder finalLivingOrder = livingOrder;
             customers.forEach(s->{
                 // 【添加客人信息 Start】
@@ -1056,8 +1082,10 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
                         newCustomer.setCreateUser("");
                         newCustomer.setTenantId(user.getRelTenantIds());
                         newCustomer.setName(s.getCustomerName());
+                        newCustomer.setGender(s.getGender());
                         newCustomer.setPhone(s.getPhone());
                         newCustomer.setCertType(1); // 身份证
+                        newCustomer.setCertNo(s.getCertNo()); // 身份证
                         customerService.save(newCustomer);
                         s.setCustomerId(newCustomer.getId());
                     } else {
@@ -1068,9 +1096,11 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
                 livingCustomerService.save(s);
                 // 【添加客人信息 end】
             });
-        } else throw new JeecgBootException("请添加入住人信息");
+
         //</editor-fold>
 
+         //</editor-fold>
+
         //<editor-fold desc="todo:账单相关">
         if(bookingLiving != null && bookingLiving) {
             BigDecimal money = new BigDecimal(0);
@@ -1099,6 +1129,17 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
             dayOrderFee.setHotelId(hotelId);
             feeService.save(dayOrderFee);
         }
+
+        CesAllDayPriceRule cesAllDayPriceRule =  allDayPriceRuleService.getOne(Wrappers.<CesAllDayPriceRule>lambdaQuery().eq(CesAllDayPriceRule::getHotelId,hotelId).eq(CesAllDayPriceRule::getInvalid,false));
+        if(ObjectUtils.isEmpty(cesAllDayPriceRule)) {
+            throw new JeecgBootException("未找到超时收费规则");
+        }
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(livingOrder.getDueOutTime());
+        calendar.add(Calendar.MINUTE, Integer.parseInt(cesAllDayPriceRule.getDayTime()));
+        redisTemplate.opsForZSet().add("overTimerOrder", livingOrder.getId(), calendar.getTimeInMillis());
+        roomsService.getReserveRoom();
         //</editor-fold>
         return livingOrder.getId();
     }
@@ -1107,7 +1148,11 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
     @Transactional(rollbackFor = Exception.class)
     public String customerLiving(BookingOrderSaveDto livingData, Boolean isTeam, String hotelId) {
         List<String> roomIds = livingData.getRoomIds().stream().map(BookingLayoutRoomsDto::getRoomId).collect(Collectors.toList());
-
+        List<CesRooms> rooms = roomsService.listByIds(roomIds);
+        Optional<CesRooms> optional = rooms.stream().filter(e -> StrUtil.isNotEmpty(e.getLivingOrderId())).findFirst();
+        if (optional.isPresent()){
+            throw new JeecgBootException("房间已被入住");
+        }
         // 是预约单先将预约单与房间关联删掉。因为原来这个接口是自己入住的接口,后来预定也要调这个接口,只能先将预定时添加的BusRoomBookingOrders关联表删掉,重新进行关联
         if(StrUtil.isNotEmpty(livingData.getOrderInfo().getId())){
             BusRoomBookingOrders bookingOrders = getById(livingData.getOrderInfo().getId());
@@ -1121,7 +1166,7 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
             BookingOrderEditVo bookingOrderVo =  getBookingInfoById(null,bookingOrderNo);
             // 散客取roomIds
             if(bookingOrderVo.getOrderInfo().getBookingOrdersType().equals(BookingOrdersType.NORMAL.getKey())) {
-                //
+                // 返回map中key为房间id, value为居住单id 。该方法添加房间,费用等入住信息,
                 Map<String,String> roomOrderMap = bookingRoomToLiving(livingData, bookingOrderVo.getRoomIds(), bookingOrderVo,hotelId);
                 livingData.getLivingRoomDayPrices().forEach(g->{
                     String livingOrderId = roomOrderMap.get(g.getRoomId());
@@ -1133,6 +1178,7 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
                 livingLayoutDayPriceService.saveBatch(livingData.getLivingRoomDayPrices());
             } else if(bookingOrderVo.getOrderInfo().getBookingOrdersType().equals(BookingOrdersType.TEAM.getKey())) {
                 bookingOrderVo.getBatchRooms().forEach(b->{
+                    /*保存入住单,保存入住费用*/
                     bookingRoomToLiving(livingData, b.getRoomIds(), bookingOrderVo,hotelId);
                 });
             } else throw new JeecgBootException("订单类型错误");
@@ -1162,26 +1208,49 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
         .in("living_order_id",livingOrderIds)):new ArrayList<>();
         List<BusLivingLayoutDayPrice> livingLayoutDayPrices =livingOrderIds.size()>0? livingLayoutDayPriceService.list(Wrappers.<BusLivingLayoutDayPrice>query()
         .in("living_order_id",livingOrderIds)):new ArrayList<>();
+
+
+        List<BusTeam> teamOrders_all = teamService.list(Wrappers.<BusTeam>lambdaQuery().eq(BusTeam::getIsDelete, 0));
+        List<String> booingIds = teamOrders_all.stream().map(BusTeam::getBookingOrderId).collect(Collectors.toList());
+//        List<BusBookingRooms> bookingRoomsList = bookingRoomsService.bookingRoomsDetail(Wrappers.<BusBookingRooms>lambdaQuery().in(BusBookingRooms::getBookingOrdersId, booingIds));
+        List<BusBookingRooms> bookingRoomsList = bookingRoomsService.bookingRoomsDetail(booingIds);
+
         rooms.forEach(s-> {
             FloorBuildingRoomVo vo = new FloorBuildingRoomVo();
             vo.setRoomId(s.getId());
             vo.setBookingData(new BookingRealtimeVo());
             vo.setLivingData(new LivingRealtimeVo());
+            // 通过房间id找出对应的预约单号, 实际上目前数据库房间表的预约订单id全部未空
             Optional<TodayBookingQueryDto> optionalTodayBookingQueryDto =  roomBookingOrders.stream().filter(t->t.getRoomId().equals(s.getId())).findFirst();
             if(optionalTodayBookingQueryDto.isPresent()) {
                 s.setBookingOrderId(optionalTodayBookingQueryDto.get().getBookingOrderId());
+                // 找出当前房间的预约单
                 Optional<BusRoomBookingOrders> opBookingOrder = bookingOrders.stream().filter(a->a.getId().equals(s.getBookingOrderId())).findFirst();
                 if(opBookingOrder.isPresent()) {
+                    //设置团队联房标签
+                    Optional<BusTeam> opTeam = teamOrders_all.stream().filter(r->r.getBookingOrderId().equals(opBookingOrder.get().getId())).findFirst();
+                    if(opTeam.isPresent()) {
+                        BusTeam t = opTeam.get();
+                        if(t.getRelType().equals(1)) {
+                            opBookingOrder.get().setIsTeam(true);
+                            opBookingOrder.get().setTeamTag("团"+t.getSortIndex());
+                        } else {
+                            opBookingOrder.get().setIsRel(true);
+                            opBookingOrder.get().setRelTag("联"+t.getSortIndex());
+                        }
+                        // 关联房间
+                        List<BusBookingRooms> releBookingRooms = bookingRoomsList.stream().filter(e ->
+                                opBookingOrder.get().getId().equals(e.getBookingOrdersId())).collect(Collectors.toList());
+                        vo.getBookingData().setReleBookingRooms(releBookingRooms);
+                    }
+
                     vo.getBookingData().setBookingOrder(opBookingOrder.get());
                     Optional<BusCustomer> opBookingCustomer = bookingCustomers.stream().filter(a->a.getId().equals(opBookingOrder.get().getContactId())).findFirst();
-                    if(opBookingCustomer.isPresent()){
-                        vo.getBookingData().setBookingCustomer(opBookingCustomer.get());
-                    }
+                    opBookingCustomer.ifPresent(customer -> vo.getBookingData().setBookingCustomer(customer));
                     vo.getBookingData().setLayoutDayPrices(bookingLayoutDayPrices.stream().filter(a->a.getBookingOrderId().equals(opBookingOrder.get().getId())).collect(Collectors.toList()));
                 }
             }
-
-
+            // 找出当前房间的居住单
              Optional<BusRoomsLivingOrder> opLivingOrder=livingOrders.stream().filter(a->a.getId().equals(s.getLivingOrderId())).findFirst();
              if(opLivingOrder.isPresent()) {
                  BusRoomsLivingOrder livingOrder = opLivingOrder.get();
@@ -1190,14 +1259,25 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
                  livingOrder.setShouKuan(feeMap.get("sk"));
                  // 获取入住天数
                  livingOrder.setLiveDayCount(getLivingDayCount(livingOrder));
-
+                 // 设置居住单的团队联房标签
+                 Optional<BusTeam> opTeam = teamOrders_all.stream().filter(r->r.getBookingOrderId().equals(livingOrder.getBookingOrderId())).findFirst();
+                 if(opTeam.isPresent()) {
+                     BusTeam t = opTeam.get();
+                     if(t.getRelType().equals(1)) {
+                         livingOrder.setIsTeam(true);
+                         livingOrder.setTeamTag("团"+opTeam.get().getSortIndex());
+                     } else {
+                         livingOrder.setIsRel(true);
+                         livingOrder.setRelTag("联"+opTeam.get().getSortIndex());
+                     }
+                     List<BusBookingRooms> releBookingRooms = bookingRoomsList.stream().filter(e ->
+                             livingOrder.getBookingOrderId().equals(e.getBookingOrdersId())).collect(Collectors.toList());
+                     vo.getBookingData().setReleBookingRooms(releBookingRooms);
+                 }
+                 // 赋值
                  vo.getLivingData().setLivingOrder(livingOrder);
-
-
                  Optional<BusLivingCustomer> opLivingCustomer = livingCustomers.stream().filter(a->a.getLivingOrderId().equals(opLivingOrder.get().getId())).findFirst();
-                 if(opLivingCustomer.isPresent()) {
-                     vo.getLivingData().setLivingCustomers(opLivingCustomer.get());
-                 }
+                 opLivingCustomer.ifPresent(busLivingCustomer -> vo.getLivingData().setLivingCustomers(busLivingCustomer));
                  vo.getLivingData().setPrice(
                          livingLayoutDayPrices.stream().filter(a->a.getLivingOrderId().equals(opLivingOrder.get().getId())).collect(Collectors.toList())
                  );
@@ -1368,6 +1448,220 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
         return null;
     }
 
+
+    public Boolean syncRoomOrder(String hotelId) {
+        // 查询出当前时间内需要处理的超时订单
+        Set<Object> set = redisTemplate.opsForZSet().rangeByScore("overTimerOrder", 0, Calendar.getInstance().getTimeInMillis());
+        CesAllDayPriceRule cesAllDayPriceRule =  allDayPriceRuleService.getOne(Wrappers.<CesAllDayPriceRule>lambdaQuery().eq(CesAllDayPriceRule::getHotelId,hotelId).eq(CesAllDayPriceRule::getInvalid,false));
+        if(CollUtil.isEmpty(set)){
+            return true;
+        }
+        if(ObjectUtils.isEmpty(cesAllDayPriceRule)) {
+            throw new JeecgBootException("未找到超时收费规则");
+        }
+        // 如果房间超时是按分钟加收费用
+        if (TimeOutRuleEnum.ADD_BY_MINUTE.getKey().equals(cesAllDayPriceRule.getTimeOutRule())){
+            addByMinute(set, cesAllDayPriceRule);
+        }else if (TimeOutRuleEnum.ADD_BY_DAY.getKey().equals(cesAllDayPriceRule.getTimeOutRule())){
+            addByDay(set, cesAllDayPriceRule);
+        }else if (TimeOutRuleEnum.NOT_ADD.getKey().equals(cesAllDayPriceRule.getTimeOutRule())) {
+            notAdd(set, cesAllDayPriceRule);
+        }
+        return null;
+    }
+
+    /**
+     * 超时收费规则是按分钟
+     */
+    public void addByMinute(Set<Object> set, CesAllDayPriceRule cesAllDayPriceRule){
+        Date date = new Date();
+        Calendar nextCalendar = Calendar.getInstance();
+        set.forEach(e -> {
+            nextCalendar.setTime(date);
+            BusRoomsLivingOrder livingOrder = roomsLivingOrderService.getById(e.toString());
+            if(ObjectUtil.isNotEmpty(livingOrder)){
+                BusBookingRooms bookingroom = bookingRoomsService.getById(livingOrder.getBookingRoomId());
+                if (ObjectUtil.isEmpty(bookingroom)){
+                    throw new JeecgBootException("未找到订单对应的房间");
+                }
+                // 查询当天房间超时消费
+                BusOrderFee fee = getOverTimeFee(livingOrder, bookingroom);
+                // 需要支付完整费用时间的最后时间
+                Date endTime = getFullFeeTime(date, cesAllDayPriceRule);
+                // 当前时间加上超时收费时间
+                nextCalendar.add(Calendar.MINUTE, Integer.parseInt(cesAllDayPriceRule.getDayTime()));
+                // 当前时间加上超时收费时间 < 按全天收费时间的标准
+                if (nextCalendar.getTime().compareTo(endTime) < 0){
+                    // 不满足的情况下,添加超时收费,设置下一次收费时间戳
+                    fee.setDayTime(date);
+                    fee.setMoney(fee.getMoney().add(cesAllDayPriceRule.getPrice()));
+                    redisTemplate.opsForZSet().remove("overTimerOrder",livingOrder.getId());
+
+                    // 如果下一次增加收费时间大于 全天收费时间 设置
+                }else {
+                    // 如果满足全天收费要求,预离时间增加1天
+                    CesRoomLayout layout = layoutService.getById(bookingroom.getRoomLayoutId());
+                    fee.setMoney(layout.getMarketPrice());
+                    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()));
+                    // 添加每日房费
+                    BusLivingLayoutDayPrice nPrice = new BusLivingLayoutDayPrice();
+                    nPrice.setBookingRoomId(livingOrder.getBookingRoomId());
+                    try {
+                        nPrice.setDayTime(DateUtils.parseDate(DateUtils.formatDate(new Date()),"yyyy-MM-dd"));
+                    } catch (ParseException ex) {
+                        throw new RuntimeException(ex);
+                    }
+                    nPrice.setRoomId(bookingroom.getRoomId());
+                    nPrice.setRoomLayoutId(bookingroom.getRoomLayoutId());
+                    nPrice.setPrice(layout.getMarketPrice());
+                    nPrice.setLivingOrderId(livingOrder.getId());
+                    nPrice.setLivingType(livingOrder.getLivingType());
+                    livingLayoutDayPriceService.save(nPrice);
+                }
+                // 移除处理过的时间订单,添加订单下一次超时的时间戳
+                redisTemplate.opsForZSet().remove("overTimerOrder",livingOrder.getId());
+                redisTemplate.opsForZSet().add("overTimerOrder",livingOrder.getId(),nextCalendar.getTimeInMillis());
+                feeService.saveOrUpdate(fee);
+            }
+        });
+    }
+
+    public void addByDay(Set<Object> set, CesAllDayPriceRule cesAllDayPriceRule){
+        Date date = new Date();
+        Calendar nextCalendar = Calendar.getInstance();
+        set.forEach(e -> {
+            BusRoomsLivingOrder livingOrder = roomsLivingOrderService.getById(e.toString());
+            if(ObjectUtil.isNotEmpty(livingOrder)) {
+                BusBookingRooms bookingroom = bookingRoomsService.getById(livingOrder.getBookingRoomId());
+                if (ObjectUtil.isEmpty(bookingroom)) {
+                    log.info("未找到订单{}对应的房间", livingOrder.getId());
+                    return;
+                }
+                CesRoomLayout layout = layoutService.getById(bookingroom.getRoomLayoutId());
+                // 查询当天房间超时消费
+                BusOrderFee fee = getOverTimeFee(livingOrder, bookingroom);
+                // 需要支付完整费用时间的最后时间
+                Date endTime = getFullFeeTime(date, cesAllDayPriceRule);
+                if (nextCalendar.getTime().compareTo(endTime) < 0){
+                    fee.setMoney(layout.getMarketPrice().divide(new BigDecimal(2)));
+                    nextCalendar.setTime(endTime);
+                } else {
+                    fee.setMoney(layout.getMarketPrice());
+                    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()));
+                    // 添加每日房费
+                    BusLivingLayoutDayPrice nPrice = new BusLivingLayoutDayPrice();
+                    nPrice.setBookingRoomId(livingOrder.getBookingRoomId());
+                    try {
+                        nPrice.setDayTime(DateUtils.parseDate(DateUtils.formatDate(new Date()),"yyyy-MM-dd"));
+                    } catch (ParseException ex) {
+                        throw new RuntimeException(ex);
+                    }
+                    nPrice.setRoomId(bookingroom.getRoomId());
+                    nPrice.setRoomLayoutId(bookingroom.getRoomLayoutId());
+                    nPrice.setPrice(layout.getMarketPrice());
+                    nPrice.setLivingOrderId(livingOrder.getId());
+                    nPrice.setLivingType(livingOrder.getLivingType());
+                    livingLayoutDayPriceService.save(nPrice);
+                }
+                // 移除处理过的时间订单,添加订单下一次超时的时间戳
+                redisTemplate.opsForZSet().remove("overTimerOrder",livingOrder.getId());
+                redisTemplate.opsForZSet().add("overTimerOrder",livingOrder.getId(),nextCalendar.getTimeInMillis());
+                feeService.saveOrUpdate(fee);
+            }
+        });
+    }
+
+    public void notAdd(Set<Object> set, CesAllDayPriceRule cesAllDayPriceRule){
+        Date date = new Date();
+        Calendar nextCalendar = Calendar.getInstance();
+        set.forEach(e -> {
+            BusRoomsLivingOrder livingOrder = roomsLivingOrderService.getById(e.toString());
+            if(ObjectUtil.isNotEmpty(livingOrder)) {
+                BusBookingRooms bookingroom = bookingRoomsService.getById(livingOrder.getBookingRoomId());
+                if (ObjectUtil.isEmpty(bookingroom)) {
+                    throw new JeecgBootException("未找到订单对应的房间");
+                }
+                CesRoomLayout layout = layoutService.getById(bookingroom.getRoomLayoutId());
+                // 查询当天房间超时消费
+                BusOrderFee fee = getOverTimeFee(livingOrder, bookingroom);
+                // 需要支付完整费用时间的最后时间
+                Date endTime = getFullFeeTime(date, cesAllDayPriceRule);
+                if (nextCalendar.getTime().compareTo(endTime) >= 0){
+                    fee.setMoney(layout.getMarketPrice());
+                    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()));
+                    // 添加每日房费
+                    BusLivingLayoutDayPrice nPrice = new BusLivingLayoutDayPrice();
+                    nPrice.setBookingRoomId(livingOrder.getBookingRoomId());
+                    try {
+                        nPrice.setDayTime(DateUtils.parseDate(DateUtils.formatDate(new Date()),"yyyy-MM-dd"));
+                    } catch (ParseException ex) {
+                        throw new RuntimeException(ex);
+                    }
+                    nPrice.setRoomId(bookingroom.getRoomId());
+                    nPrice.setRoomLayoutId(bookingroom.getRoomLayoutId());
+                    nPrice.setPrice(layout.getMarketPrice());
+                    nPrice.setLivingOrderId(livingOrder.getId());
+                    nPrice.setLivingType(livingOrder.getLivingType());
+                    livingLayoutDayPriceService.save(nPrice);
+                }
+                // 移除处理过的时间订单,添加订单下一次超时的时间戳
+                redisTemplate.opsForZSet().remove("overTimerOrder",livingOrder.getId());
+                redisTemplate.opsForZSet().add("overTimerOrder",livingOrder.getId(),nextCalendar.getTimeInMillis());
+                feeService.saveOrUpdate(fee);
+            }
+        });
+    }
+
+    public BusOrderFee getOverTimeFee(BusRoomsLivingOrder livingOrder, BusBookingRooms bookingroom){
+        BusOrderFee fee = feeService.getOne(Wrappers.<BusOrderFee>lambdaQuery()
+                .eq(BusOrderFee::getLivingOrderId, livingOrder.getId()).eq(BusOrderFee::getPreferentialStatus, "1")
+                .eq(BusOrderFee::getSubjectType, FeeSubjectType.MEI_RI_FANG_FEI.getKey()).gt(BusOrderFee::getCreateTime, livingOrder.getDueOutTime()));
+        if (ObjectUtil.isEmpty(fee)){
+            fee = new BusOrderFee();
+            fee.setMoney(new BigDecimal(0));
+            fee.setCreateTime(new Date());
+            fee.setSubjectType(FeeSubjectType.MEI_RI_FANG_FEI.getKey());
+            fee.setLivingOrderId(livingOrder.getId());
+            fee.setHotelId(livingOrder.getHotelId());
+            fee.setFeeType(FeeType.CONSUME.getKey());
+            fee.setRoomId(bookingroom.getRoomId());
+            fee.setRemark("超时房费");
+        }
+        return fee;
+    }
+
+    /**
+     * 完整费用时间
+     * @return
+     */
+    public Date getFullFeeTime(Date date, CesAllDayPriceRule cesAllDayPriceRule){
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd ");
+        String endDateStr = dateFormat.format(date);
+        Date endTime = null;
+        try {
+            endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(endDateStr + cesAllDayPriceRule.getEndTime());
+        } catch (ParseException ex) {
+            throw new JeecgBootException("结束时间格式异常");
+        }
+        return endTime;
+    }
+
+
     @Override
     public BigDecimal getOrderFeeTotal(String livingOrderId, String bookingOrderId) {
 
@@ -1484,14 +1778,18 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
                         s.setRoomStatus(RoomStatusEnum.EMPTY_DIRTY.getKey());
                         s.setLastRoomStatus(RoomStatusEnum.EMPTY_DIRTY.getKey());
                         s.setLivingOrderId("");
+                        s.setBookingOrderId("");
                     });
                     roomsService.updateBatchById(baseRooms);
                 }
-                BusTeam team = teamService.getOne(Wrappers.<BusTeam>query().eq("booking_order_id",bookingOrderId));
-                if(team != null) {
-                    team.setIsDelete(1);
-                    teamService.updateById(team);
+                List<BusTeam> teams = teamService.list(Wrappers.<BusTeam>query().eq("booking_order_id",bookingOrderId));
+                if(CollUtil.isNotEmpty(teams)) {
+                    teams.get(0).setIsDelete(1);
+                    teamService.updateById(teams.get(0));
                 }
+                livingOrders.forEach(e -> {
+                    redisTemplate.opsForZSet().remove("overTimerOrder",e.getId());
+                });
                 return true;
                 // todo 对账
             } else throw new JeecgBootException("未找到任何入住订单");
@@ -1508,22 +1806,41 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
         if(livingOrder == null) throw new JeecgBootException("未找到任何入住订单");
         BusBookingRooms mainRoom = bookingRoomsService.getOne(Wrappers.<BusBookingRooms>query()
                 .eq("id",livingOrder.getBookingRoomId()));
+        if(mainRoom == null) throw new JeecgBootException("没有找到房间");
         List<BusRoomsLivingOrder> releLivingingOrders = roomsLivingOrderService.list(Wrappers.<BusRoomsLivingOrder>lambdaQuery()
                 .eq(BusRoomsLivingOrder::getBookingOrderId, livingOrder.getBookingOrderId()));
         if (CollUtil.isEmpty(releLivingingOrders)){
             throw new JeecgBootException("未找到预定订单");
         }
+        releLivingingOrders = releLivingingOrders.stream().filter(e ->
+                ObjectUtil.equal(SettleTypeEnum.SETTLE_LEAVE.getKey(),e.getSettleType())).collect(Collectors.toList());
+
         if(mainRoom.getIsMain().equals(true) && releLivingingOrders.size() > 1) throw new JeecgBootException("查询到其他关联房间,主房不能单独结账退房");
-        if(mainRoom == null) throw new JeecgBootException("没有找到主房");
 
         BusRoomsLivingOrder mainRoomOrder = livingOrder;
         // fixbug 当结账后设置离店时间 2023-05-09
         livingOrder.setDueOutTime(new Date());
         livingOrder.setSettleType(SettleTypeEnum.SETTLE_LEAVE.getKey());
         roomsLivingOrderService.updateById(livingOrder);
+        // 当前居住单中未结算的费用
         List<BusOrderFee> feeItems = getLivingOrderFees(livingOrderId).stream().filter(
                 s->s.getPreferentialStatus().equals(1)// 找到未结账的
         ).collect(Collectors.toList());
+
+        final BigDecimal[] shoukuan = {new BigDecimal(0)};
+        final BigDecimal[] xiaofei = {new BigDecimal(0)};
+        feeItems.forEach(c->{
+            if(c.getFeeType().equals(1)) { // 收款
+                shoukuan[0] = shoukuan[0].add(c.getMoney());
+            } else if(c.getFeeType().equals(2)) { // 消费
+                xiaofei[0] = xiaofei[0].add(c.getMoney());
+            }
+        });
+        BigDecimal m = shoukuan[0].subtract(xiaofei[0]);
+        BigDecimal nowMoney = settleFees.stream().map(BusOrderFee::getMoney).reduce(BigDecimal.ZERO,BigDecimal::add);
+        if (new BigDecimal(0).equals(m.add(nowMoney))){
+            throw new JeecgBootException("账单未平账");
+        }
 //        // 消费账单
 //        List<BusOrderFee> xiaoFeiFees = feeItems.stream().filter(s->s.getFeeType().equals(1)).collect(Collectors.toList());
 //        // 收款
@@ -1537,9 +1854,11 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
                 s.setRoomStatus(RoomStatusEnum.EMPTY_DIRTY.getKey());
                 s.setLastRoomStatus(RoomStatusEnum.EMPTY_DIRTY.getKey());
                 s.setLivingOrderId("");
+                s.setBookingOrderId("");
             });
             roomsService.updateBatchById(baseRooms);
         }
+        redisTemplate.opsForZSet().remove("overTimerOrder",livingOrder.getId());
         return true;
     }
 
@@ -1585,6 +1904,9 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
         save(newBookingOrder);
         livingOrder.setBookingOrderId(newBookingOrder.getId());
         roomsLivingOrderService.updateById(livingOrder);
+        LambdaUpdateWrapper<CesRooms> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.set(CesRooms::getBookingOrderId, "").eq(CesRooms::getId, bookingRoom.getRoomId());
+        roomsService.update(updateWrapper);
         bookingRoom.setBookingOrdersId(newBookingOrder.getId());
         bookingRoom.setIsMain(true);
         bookingRoomsService.updateById(bookingRoom);
@@ -1653,13 +1975,32 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
 
     @Override
     public IPage<RoomLivingQueryVo> getLivingPageData(Integer status,String keyw, Page<RoomLivingQueryVo> page,String hotelId) {
-        IPage<RoomLivingQueryVo> RoomLivings = baseMapper.getPage(page, status, keyw, hotelId);
-        RoomLivings.getRecords().stream().forEach(e ->{
+        IPage<RoomLivingQueryVo> roomLivings = baseMapper.getPage(page, status, keyw, hotelId);
+
+        roomLivings.getRecords().stream().forEach(e ->{
                 if (ObjectUtil.isNotEmpty(e.getRelType())){
                     e.setGroupTag(TeamEnum.val(e.getRelType()).getTitle() + e.getSortIndex());
                 }
         });
-        return RoomLivings;
+        return roomLivings;
+    }
+
+    @Override
+    public IPage<RoomLivingQueryVo> getUnionLivingPageData(String keyw, Page<RoomLivingQueryVo> page,String hotelId) {
+        IPage<RoomLivingQueryVo> roomLivings = baseMapper.getUnionPage(page, keyw, hotelId, true, null);
+        List<String> bookingIds = roomLivings.getRecords().stream().map(RoomLivingQueryVo::getBookingOrderId).collect(Collectors.toList());
+        Page<RoomLivingQueryVo> childPage = new Page<>();
+        childPage.setPages(1);
+        childPage.setSize(9999);
+        List<RoomLivingQueryVo> livingQueryVos = baseMapper.getUnionPage(childPage, keyw, hotelId, false, bookingIds).getRecords();
+        Map<String, List<RoomLivingQueryVo>> map = livingQueryVos.stream().collect(Collectors.groupingBy(RoomLivingQueryVo::getBookingOrderId));
+        roomLivings.getRecords().forEach(e ->{
+            if (ObjectUtil.isNotEmpty(e.getRelType())){
+                e.setChildren(map.get(e.getBookingOrderId()));
+                e.setGroupTag(TeamEnum.val(e.getRelType()).getTitle() + e.getSortIndex());
+            }
+        });
+        return roomLivings;
     }
     @Override
     public IPage<KeLiItemVo> getLivingOrderKL(Integer status,String keyw,String hotelId,String thirdUserId, Page<KeLiItemVo> page) {
@@ -1759,7 +2100,10 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
         livingOrderId.forEach(s->{
             this.mergeSingle(mainLivingOrder,s);
         });
-        addBusTeams(hotelId, mainLivingOrder.getBookingOrderId());
+        List<BusTeam> teams = teamService.list(Wrappers.<BusTeam>lambdaQuery().eq(BusTeam::getBookingOrderId, mainLivingOrder.getBookingOrderId()).eq(BusTeam::getIsDelete, "0"));
+        if (teams.isEmpty()){
+            addBusTeams(hotelId, mainLivingOrder.getBookingOrderId());
+        }
         return true;
     }
 
@@ -2285,12 +2629,6 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
             //将修改后关联标识后的房间存好
             bookingRoomsService.updateBatchById(bookingRoomsList);
             needMergeLivingOrders.addAll(relationOtherLivingOrders);
-
-//            BusBookingRooms mainBkRoom = bookingRoomsService.getOne(Wrappers.<BusBookingRooms>query().eq("booking_orders_id",bookingRooms.getBookingOrdersId()));
-//            if(mainBkRoom != null) {
-//                mainBkRoom.setIsMain(true);
-//                bookingRoomsService.updateById(mainBkRoom); // 设置预约的主房
-//            }
         } else {
             needMergeLivingOrders.add(mergeLivingOrder);
         }
@@ -2540,7 +2878,7 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
             BookingLayoutRoomsDto bkRoomItem = livingData.getRoomIds().stream().filter(s->s.getRoomId().equals(bkRoom.getRoomId())).findFirst().get();
             List<BusLivingCustomer> customers = bkRoomItem.getLivingCustomers();
             if(customers == null || customers.size() == 0) throw new JeecgBootException("请添加客户信息");
-            // 保存入住单
+            // 保存入住单,修改房间状态
             String livingOrderId = bookingToLive(bkRoom.getId(), customers,hotelId,null, bkRoomItem.getRoomOrderInfo());
             // 费用关联到主房
             if(livingData.getOrderFees()!=null && livingData.getOrderFees().size() > 0 ) {
@@ -2609,7 +2947,8 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
             roomFee.setRoomId(bkRoom.getRoomId());
             roomFee.setLivingOrderId(livingOrderId);
             roomFee.setFeeType(1); // 消费
-            List<BusLivingLayoutDayPrice> roomDayPrice = livingData.getLivingRoomDayPrices().stream().filter(i->i.getRoomId().equals(bkRoom.getRoomId())).collect(Collectors.toList());
+            List<BusLivingLayoutDayPrice> roomDayPrice = livingData.getLivingRoomDayPrices().stream()
+                    .filter(i->i.getRoomId().equals(bkRoom.getRoomId())).collect(Collectors.toList());
             BigDecimal dayRoomFee =  currentDayFee(roomDayPrice,null);
             if(dayRoomFee == null) throw new JeecgBootException("未找到当日房价");
             roomFee.setMoney(dayRoomFee); // 取当日房费的优惠价  其他时间要查询房价方案、每日房价,房型门市价按照规则去取
@@ -2901,6 +3240,15 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
             s.setRoomId(changeRoom.getId());
             s.setLivingType(1);
             s.setLivingOrderId(livingOrderId);
+            if(DateUtils.formatDate(new Date()).equals(DateUtils.formatDate(s.getDayTime()))){
+                // 修改当日房价 产生的当日房费账单也要改
+                BusOrderFee fee = feeService.getOne(Wrappers.<BusOrderFee>query()
+                        .eq("DATE_FORMAT(day_time,'%Y-%m-%d')",DateUtils.formatDate(new Date())).eq("living_order_id",s.getLivingOrderId()));
+                if(fee != null) {
+                    fee.setMoney(s.getPrice());
+                    feeService.updateById(fee);
+                }
+            }
         });
         livingLayoutDayPriceService.saveBatch(prices);
         return true;

+ 3 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/vo/RiLiFangTaiVo.java

@@ -24,6 +24,9 @@ public class RiLiFangTaiVo {
     private BigDecimal yushou;
     private BigDecimal yajin;
     private BigDecimal yuE;
+    /**
+     * 0:未入住,1:已入住
+     */
     private Integer isLiving;
     private Integer settleType;
     private String customerName;

+ 4 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/vo/RoomLivingQueryVo.java

@@ -3,11 +3,14 @@ package org.jeecg.modules.business.vo;
 import lombok.Data;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 @Data
 public class RoomLivingQueryVo {
     private String livingOrderId;
     private String livingOrderNo;
+    private String bookingOrderId;
+    private Boolean isMain;
     private String roomName;
     private String customerId;
     private String customerName;
@@ -19,4 +22,5 @@ public class RoomLivingQueryVo {
     private Integer relType;
     private Integer sortIndex;
     private String groupTag;
+    private List<RoomLivingQueryVo> children;
 }

+ 0 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/kc/entity/KcDepositoryInGoods.java

@@ -60,7 +60,6 @@ public class KcDepositoryInGoods implements Serializable {
     @ApiModelProperty(value = "库存详情id")
     private String stockDetailId;
 
-
 	@TableField(exist = false)
 	private Decimal price;
 

+ 89 - 9
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/order/controller/CesOrderLeaseGoodsController.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.order.controller;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 import java.io.IOException;
@@ -9,10 +10,14 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import io.swagger.annotations.Info;
 import org.apache.commons.lang3.ObjectUtils;
 import org.jeecg.common.api.vo.Result;
@@ -30,13 +35,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
 
 import org.jeecg.modules.business.dto.PostDataDto;
-import org.jeecg.modules.business.entity.BusDictItem;
-import org.jeecg.modules.business.entity.BusHotel;
-import org.jeecg.modules.business.entity.BusMarketCouponsCashUsed;
-import org.jeecg.modules.business.entity.BusMemberBalanceLog;
+import org.jeecg.modules.business.entity.*;
 import org.jeecg.modules.business.enums.CouponsStatusEnum;
+import org.jeecg.modules.business.enums.FeeType;
 import org.jeecg.modules.business.service.IBusDictItemService;
 import org.jeecg.modules.business.service.IBusHotelService;
+import org.jeecg.modules.business.service.IBusOrderFeeService;
 import org.jeecg.modules.order.entity.CesOrderLeaseGoods;
 import org.jeecg.modules.order.service.ICesOrderLeaseGoodsService;
 import org.jeecg.modules.rooms.entity.CesRooms;
@@ -48,6 +52,7 @@ import org.jeecgframework.poi.excel.entity.ImportParams;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.jeecg.common.system.base.controller.JeecgController;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
@@ -75,6 +80,8 @@ public class CesOrderLeaseGoodsController extends JeecgController<CesOrderLeaseG
 	 private CesRoomsServiceImpl cesRoomsService;
 	 @Resource
 	 private IBusDictItemService busDictItemService;
+	 @Resource
+	 private IBusOrderFeeService busOrderFeeService;
 	/**
 	 * 分页列表查询
 	 *
@@ -125,6 +132,16 @@ public class CesOrderLeaseGoodsController extends JeecgController<CesOrderLeaseG
 			if (busDictItem != null) {
 				item.setGoodName(busDictItem.getItemText());
 			}
+			if (item.getOrderFeeId() != null){
+				BusOrderFee orderFee = busOrderFeeService.getById(item.getOrderFeeId());
+				if (orderFee != null && ObjectUtil.equals(orderFee.getPreferentialStatus(),1)){
+					List<BusOrderFee> returnOrderFees = busOrderFeeService.list(Wrappers.<BusOrderFee>lambdaQuery()
+							.eq(BusOrderFee::getReturnFeeId, orderFee.getId()).eq(BusOrderFee::getPreferentialStatus, 1));
+					BigDecimal returnMoney = returnOrderFees.stream().map(BusOrderFee::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
+					item.setDeposit(orderFee.getMoney().add(returnMoney));
+					item.setPayType(orderFee.getPayType());
+				}
+			}
 		});
 		return Result.OK(pageList);
 	}
@@ -157,11 +174,16 @@ public class CesOrderLeaseGoodsController extends JeecgController<CesOrderLeaseG
 	 @AutoLog(value = "归还")
 	 @ApiOperation(value="归还", notes="归还")
 	 @RequestMapping(value = "/revert", method = {RequestMethod.PUT,RequestMethod.POST})
-	 public Result<String> revert(@RequestBody PostDataDto dto) {
-		 LambdaUpdateWrapper<CesOrderLeaseGoods> updateWrapper = new UpdateWrapper().lambda();
-		 updateWrapper.set(CesOrderLeaseGoods::getRevertDate, new Date());
-		 updateWrapper.eq(CesOrderLeaseGoods::getId, dto.getId());
-		 cesOrderLeaseGoodsService.update(updateWrapper);
+	 public Result<String> revert(@RequestBody PostDataDto dto, boolean returnDeposit) {
+		 CesOrderLeaseGoods orderLeaseGood = cesOrderLeaseGoodsService.getById(dto.getId());
+		 orderLeaseGood.setRevertDate(new Date());
+		 boolean isSuccess = cesOrderLeaseGoodsService.updateById(orderLeaseGood);
+		 if (isSuccess && returnDeposit && StrUtil.isNotEmpty(orderLeaseGood.getOrderFeeId())){
+			 LambdaUpdateWrapper<BusOrderFee> wrapper = new LambdaUpdateWrapper<>();
+			 wrapper.eq(BusOrderFee::getId,orderLeaseGood.getOrderFeeId());
+			 wrapper.set(BusOrderFee::getPreferentialStatus,2);
+			 busOrderFeeService.update(wrapper);
+		 }
 		 return Result.OK("编辑成功!");
 	 }
 
@@ -184,12 +206,70 @@ public class CesOrderLeaseGoodsController extends JeecgController<CesOrderLeaseG
 				throw new JeecgBootException("当前登录人租户信息错误");
 			}
 		}
+		if (cesOrderLeaseGoods.getDeposit().compareTo(new BigDecimal(0)) > 0){
+			String orderFeeId = addOrderFee(cesOrderLeaseGoods);
+			if (orderFeeId == null){
+				return Result.error("押金收取失败!");
+			}
+			cesOrderLeaseGoods.setOrderFeeId(orderFeeId);
+		}
 		cesOrderLeaseGoods.setOrderNo(DateUtils.getCurrentTimestamp() + "");
 		cesOrderLeaseGoods.setCreateDate(new Date());
 		cesOrderLeaseGoodsService.save(cesOrderLeaseGoods);
 		return Result.OK("添加成功!");
 	}
 
+	public String addOrderFee(CesOrderLeaseGoods cesOrderLeaseGoods){
+		ArrayList<BusOrderFee> orderFees = new ArrayList<>();
+		BusOrderFee busOrderFee = new BusOrderFee();
+		busOrderFee.setLivingOrderId(cesOrderLeaseGoods.getLivingOrderId());
+		busOrderFee.setRoomId(cesOrderLeaseGoods.getRoomId());
+		busOrderFee.setMoney(cesOrderLeaseGoods.getDeposit());
+		busOrderFee.setFeeType(FeeType.COLLECTION.getKey());
+		busOrderFee.setSubjectType(1);
+		busOrderFee.setPayType(cesOrderLeaseGoods.getPayType());
+		busOrderFee.setVipCardId(cesOrderLeaseGoods.getVipCardId());
+		busOrderFee.setAgreementUnitId(cesOrderLeaseGoods.getAgreementUnitId());
+		busOrderFee.setDayTime(new Date());
+		orderFees.add(busOrderFee);
+		busOrderFeeService.collectionBatch(orderFees, cesOrderLeaseGoods.getHotelId());
+		return busOrderFee.getId();
+	}
+
+	 /**
+	  *   添加
+	  * @param cesOrderLeaseGoodlist
+	  * @return
+	  */
+	 @AutoLog(value = "ces_order_lease_goods-批量添加")
+	 @ApiOperation(value="ces_order_lease_goods-批量添加", notes="ces_order_lease_goods-批量添加")
+	 //@RequiresPermissions("order:ces_order_lease_goods:add")
+	 @Transactional(rollbackFor = Exception.class)
+	 @PostMapping(value = "/addBatch")
+	 public Result<String> addBatch(@RequestBody List<CesOrderLeaseGoods> cesOrderLeaseGoodlist) {
+		 if (CollUtil.isEmpty(cesOrderLeaseGoodlist)) {
+			 return Result.error("没有要借的物品");
+		 }
+		 LoginUser user = TokenUtils.getAuthUser();
+		 if (user.getRelTenantIds() == null || user.getRelTenantIds().equals("")) {
+			 throw new JeecgBootException("当前登录人租户信息错误");
+		 }
+		 cesOrderLeaseGoodlist.forEach(e ->{
+			 e.setTenantId(user.getRelTenantIds());
+			 if (e.getDeposit().compareTo(new BigDecimal(0)) > 0){
+				 String orderFeeId = addOrderFee(e);
+				 if (orderFeeId == null){
+					 throw new JeecgBootException("押金收取失败");
+				 }
+				 e.setOrderFeeId(orderFeeId);
+			 }
+			 e.setOrderNo(DateUtils.getCurrentTimestamp() + "");
+			 e.setCreateDate(new Date());
+		 });
+		 cesOrderLeaseGoodsService.saveBatch(cesOrderLeaseGoodlist);
+		 return Result.OK("添加成功!");
+	 }
+
 	/**
 	 *  编辑
 	 *

+ 13 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/order/entity/CesOrderLeaseGoods.java

@@ -62,6 +62,10 @@ public class CesOrderLeaseGoods implements Serializable {
 	@Excel(name = "押金", width = 15)
     @ApiModelProperty(value = "押金")
     private BigDecimal deposit;
+	/**押金*/
+	@Excel(name = "押金关联费用", width = 15)
+	@ApiModelProperty(value = "押金关联费用")
+	private String orderFeeId;
 	/**备注*/
 	@Excel(name = "备注", width = 15)
     @ApiModelProperty(value = "备注")
@@ -92,4 +96,13 @@ public class CesOrderLeaseGoods implements Serializable {
 
 	@TableField(exist = false)
 	private String goodName;
+
+	@TableField(exist = false)
+	private String payType;
+
+	@TableField(exist = false)
+	private String vipCardId;
+
+	@TableField(exist = false)
+	private String agreementUnitId;
 }

+ 11 - 103
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/controller/PosOrderGoodsController.java

@@ -11,7 +11,9 @@ import java.net.URLDecoder;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.BooleanUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -65,18 +67,12 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
 public class PosOrderGoodsController extends JeecgController<PosOrderGoods, IPosOrderGoodsService> {
 	@Autowired
 	private IPosOrderGoodsService posOrderGoodsService;
-@Autowired
-private IPosOrderGoodsDetailService posOrderGoodsDetailService;
-@Autowired
-private CesGoodsServiceImpl cesGoodsService;
-@Autowired
-private IPosTypeService posTypeService;
-@Autowired
-private IPosOrderGoodsPaymentService posOrderGoodsPaymentService;
-@Autowired
-private IPosTableService posTableService;
-@Autowired
-private  IBusRoomBookingOrdersService busRoomBookingOrdersService;
+	@Autowired
+	private IPosOrderGoodsDetailService posOrderGoodsDetailService;
+	@Autowired
+	private IPosTypeService posTypeService;
+	@Autowired
+	private IPosOrderGoodsPaymentService posOrderGoodsPaymentService;
 	/**
 	 * 分页列表查询
 	 *
@@ -129,100 +125,12 @@ private  IBusRoomBookingOrdersService busRoomBookingOrdersService;
 	 @ApiOperation(value="pos_order_goods-添加", notes="pos_order_goods-添加")
 	 //@RequiresPermissions("pos:pos_order_goods:add")
 	 @PostMapping(value = "/add")
-	 public Result<PosOrderGoods> add(@RequestBody PosOrderGoods posOrderGoods,String hotelId) {
+	 public Result<PosOrderGoods> add(@RequestBody PosOrderGoods posOrderGoods) {
 		 if (ObjectUtils.isEmpty(posOrderGoods.getPosOrderGoodsDetailList())) {
 			 return Result.error("请先选择商品");
 		 }
-
-		 if (ObjectUtils.isEmpty(posOrderGoods.getId())) {
-			 if (ObjectUtils.isEmpty(posOrderGoods.getPosTableId())) {
-				 LocalDateTime localDateTime = LocalDateTime.now().withNano(0).withSecond(0).withMinute(0).withHour(0);
-				 LocalDateTime[] arr = new LocalDateTime[]{localDateTime, localDateTime.withHour(23).withMinute(59)};
-				 LambdaQueryWrapper<PosOrderGoods> lambdaQueryWrapper = new LambdaQueryWrapper<>();
-				 lambdaQueryWrapper.eq(PosOrderGoods::getHotelId, posOrderGoods.getHotelId());
-				 lambdaQueryWrapper.ge(PosOrderGoods::getCreateTime, arr[0]);
-				 lambdaQueryWrapper.le(PosOrderGoods::getCreateTime, arr[1]);
-				 lambdaQueryWrapper.isNull(PosOrderGoods::getPosTableId);
-				 Page<PosOrderGoods> page = new Page<PosOrderGoods>(1, 1);
-				 lambdaQueryWrapper.orderByDesc(PosOrderGoods::getCreateTime);
-				 IPage<PosOrderGoods> pageList = posOrderGoodsService.page(page, lambdaQueryWrapper);
-				 if (ObjectUtils.isNotEmpty(pageList.getRecords())) {
-					 String no = pageList.getRecords().get(0).getTableNo();
-					 try {
-						 Integer newNo = Integer.parseInt(no) + 1;
-						 posOrderGoods.setTableNo(String.format("%03d", newNo));
-					 } catch (NumberFormatException ex) {
-						 posOrderGoods.setTableNo("001");
-					 }
-				 } else {
-					 posOrderGoods.setTableNo("001");
-				 }
-			 }
-			 posOrderGoods.setCode(randomNumber("P"));
-		 } else {
-			 List<PosOrderGoodsDetail> list = posOrderGoods.getPosOrderGoodsDetailList();
-			 String toRoomFeeOrderId = posOrderGoods.getToRoomFeeOrderId();
-			 String tableId=posOrderGoods.getPosTableId();
-			 String tableNo=posOrderGoods.getTableNo();
-			 posOrderGoods = posOrderGoodsService.getById(posOrderGoods.getId());
-			 posOrderGoods.setPosOrderGoodsDetailList(list);
-			 posOrderGoods.setToRoomFeeOrderId(toRoomFeeOrderId);
-			 posOrderGoods.setPosTableId(tableId);
-			 posOrderGoods.setTableNo(tableNo);
-		 }
-		 posOrderGoods.setTenantId(TokenUtils.currentTenantId());
-		 BigDecimal amount = BigDecimal.ZERO;
-		 for (PosOrderGoodsDetail posOrderGoodsDetail : posOrderGoods.getPosOrderGoodsDetailList()) {
-			 amount = amount.add(posOrderGoodsDetail.getMoney().multiply(BigDecimal.valueOf(posOrderGoodsDetail.getNum())));
-			 posOrderGoodsDetail.setTenantId(posOrderGoods.getTenantId());
-			 posOrderGoodsDetail.setHotelId(posOrderGoods.getHotelId());
-			 posOrderGoodsDetail.setOrderId(posOrderGoods.getCode());
-			 posOrderGoodsDetail.setCouponMoney(posOrderGoodsDetail.getMoney());
-			 posOrderGoodsDetail.setPayMoney(posOrderGoodsDetail.getMoney());
-			 posOrderGoodsDetail.setOrderId(posOrderGoods.getCode());
-		 }
-		 posOrderGoods.setMoney(amount);
-		 posOrderGoods.setConsumeMoney(amount);
-		 posOrderGoods.setCreateTime(new Date());
-
-		 if (ObjectUtils.isNotEmpty(posOrderGoods.getToRoomFeeOrderId())) {
-			 posOrderGoods.setStatus(1);
-			 posOrderGoods.setSettleTime(new Date());
-			 posOrderGoods.setPayInfo("挂房账");
-
-			 List<BusOrderFee> fees = new ArrayList<>();
-			 BusOrderFee busOrderFee = new BusOrderFee();
-			 busOrderFee.setMoney(posOrderGoods.getMoney());
-			 busOrderFee.setSubjectType(FeeSubjectType.DIAN_PIN.getKey());
-			 fees.add(busOrderFee);
-			 busRoomBookingOrdersService.setLivingOrderFee(fees, posOrderGoods.getToRoomFeeOrderId(),hotelId);
-		 }
-		 Boolean res = posOrderGoodsService.saveOrUpdate(posOrderGoods);
-		 if (res) {
-			 LambdaQueryWrapper<PosOrderGoodsDetail> lambdaQueryWrapper = new LambdaQueryWrapper<>();
-			 lambdaQueryWrapper.eq(PosOrderGoodsDetail::getOrderId, posOrderGoods.getCode());
-			 posOrderGoodsDetailService.remove(lambdaQueryWrapper);
-			 res = posOrderGoodsDetailService.saveBatch(posOrderGoods.getPosOrderGoodsDetailList());
-			 if (res) {
-				 //商品减库存
-				 for (PosOrderGoodsDetail posOrderGoodsDetail : posOrderGoods.getPosOrderGoodsDetailList()) {
-					 CesGoods cesGoods = cesGoodsService.getById(posOrderGoodsDetail.getGoodsId());
-					 if (ObjectUtils.isNotEmpty(cesGoods)) {
-						 Integer c = cesGoods.getInventory() - posOrderGoodsDetail.getNum();
-						 if (c < 0) {
-							 c = 0;
-						 }
-						 cesGoods.setInventory(c);
-						 cesGoodsService.updateById(cesGoods);
-					 }
-				 }
-			 }
-			 LambdaUpdateWrapper<PosTable> lambdaUpdateWrapper=new LambdaUpdateWrapper<>();
-			 lambdaUpdateWrapper.eq(PosTable::getId,posOrderGoods.getPosTableId());
-			 lambdaUpdateWrapper.set(PosTable::getState,2);
-			 posTableService.update(lambdaUpdateWrapper);
-		 }
-		 return Result.OK("添加成功", posOrderGoods);
+		 PosOrderGoods orderGoods = service.addOrder(posOrderGoods);
+		 return Result.OK("添加成功", orderGoods);
 	 }
 
 	 /**

+ 84 - 19
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/controller/PosOrderGoodsPaymentController.java

@@ -1,30 +1,32 @@
 package org.jeecg.modules.pos.controller;
 
 import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import org.apache.commons.lang3.ObjectUtils;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.query.QueryGenerator;
-import org.jeecg.common.util.TokenUtils;
-import org.jeecg.common.util.oConvertUtils;
-import org.jeecg.modules.business.entity.BusRoomPayType;
-import org.jeecg.modules.business.service.IBusRoomPayTypeService;
+import org.jeecg.modules.business.entity.*;
+import org.jeecg.modules.business.service.*;
 import org.jeecg.modules.pos.dto.OrderPaymentDto;
 import org.jeecg.modules.pos.entity.PosOrderGoods;
+import org.jeecg.modules.pos.entity.PosOrderGoodsDetail;
 import org.jeecg.modules.pos.entity.PosOrderGoodsPayment;
 import org.jeecg.modules.pos.entity.PosTable;
+import org.jeecg.modules.pos.service.IPosOrderGoodsDetailService;
 import org.jeecg.modules.pos.service.IPosOrderGoodsPaymentService;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -34,22 +36,15 @@ import lombok.extern.slf4j.Slf4j;
 
 import org.jeecg.modules.pos.service.IPosOrderGoodsService;
 import org.jeecg.modules.pos.service.IPosTableService;
-import org.jeecgframework.poi.excel.ExcelImportUtil;
-import org.jeecgframework.poi.excel.def.NormalExcelConstants;
-import org.jeecgframework.poi.excel.entity.ExportParams;
-import org.jeecgframework.poi.excel.entity.ImportParams;
-import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.jeecg.common.system.base.controller.JeecgController;
+import org.jeecg.modules.rooms.entity.CesGoods;
+import org.jeecg.modules.rooms.service.CesGoodsServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
-import com.alibaba.fastjson.JSON;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.jeecg.common.aspect.annotation.AutoLog;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
 
  /**
  * @Description: pos_order_goods_payment
@@ -70,6 +65,20 @@ public class PosOrderGoodsPaymentController extends JeecgController<PosOrderGood
 	 private IBusRoomPayTypeService busRoomPayTypeService;
 	 @Autowired
 	 private IPosTableService posTableService;
+	 @Resource
+	 private IPosOrderGoodsDetailService posOrderGoodsDetailService;
+	 @Resource
+	 private CesGoodsServiceImpl goodsService;
+	 @Resource
+	 private IBusRoomPayTypeService payTypeService;
+	 @Resource
+	 IBusMemberCardService memberCardService;
+	 @Resource
+	 IBusMemberBalanceLogService memberBalanceLogService;
+	 @Resource
+	 IBusMarketAgreementUnitService marketAgreementUnitService;
+	 @Resource
+	 IBusAgreementOrderFeeService agreementOrderFeeService;
 	/**
 	 * 分页列表查询
 	 *
@@ -102,7 +111,7 @@ public class PosOrderGoodsPaymentController extends JeecgController<PosOrderGood
 	@ApiOperation(value="pos_order_goods_payment-添加", notes="pos_order_goods_payment-添加")
 	//@RequiresPermissions("pos:pos_order_goods_payment:add")
 	@PostMapping(value = "/add")
-	public Result<String> add(@RequestBody OrderPaymentDto dto) {
+	public Result<String> add(@RequestBody OrderPaymentDto dto,String hotel) {
 		if (ObjectUtils.isEmpty(dto.getPaymentList())) {
 			return Result.error("请先选择支付方式");
 		}
@@ -124,19 +133,75 @@ public class PosOrderGoodsPaymentController extends JeecgController<PosOrderGood
 			}
 		}
 		posOrderGoodsPaymentService.saveBatch(dto.getPaymentList());
+		// 有会员卡支付的费用时
+		List<BusRoomPayType> payTypeList = payTypeService.list();
+		payTypeList.stream().filter(e -> "会员卡".equals(e.getName())).findFirst().ifPresent(type -> {
+			//找出会员支付的账单
+			List<PosOrderGoodsPayment> goodsPaymentList = dto.getPaymentList().stream().filter(payment -> type.getId().equals(payment.getPaymentMethod())).collect(Collectors.toList());
+			if (CollUtil.isNotEmpty(goodsPaymentList) && StrUtil.isNotEmpty(dto.getCardId())) {
+				BusMemberCard card = memberCardService.getById(dto.getCardId());
+				if (card == null) {
+					throw new JeecgBootException("未找到会员卡");
+				}
+				ArrayList<BusMemberBalanceLog> memberBalanceLogList = new ArrayList<>();
+				goodsPaymentList.forEach(payment -> {
+					BusMemberBalanceLog memberBalanceLog = memberCardService.cardPayFee(card, payment.getPayMoney(), payment.getId(), hotel);
+					memberBalanceLogList.add(memberBalanceLog);
+				});
+				memberCardService.updateById(card);
+				memberBalanceLogService.saveBatch(memberBalanceLogList);
+			}
+		});
+		// 有单位挂账的费用时
+		payTypeList.stream().filter(e -> "单位挂账".equals(e.getName())).findFirst().ifPresent(type -> {
+			//找出会员支付的账单
+			List<PosOrderGoodsPayment> goodsPaymentList = dto.getPaymentList().stream().filter(payment -> type.getId().equals(payment.getPaymentMethod())).collect(Collectors.toList());
+			if (CollUtil.isNotEmpty(goodsPaymentList) && StrUtil.isNotEmpty(dto.getAgreementId())) {
+				BusMarketAgreementUnit agreementUnit = marketAgreementUnitService.getById(dto.getAgreementId());
+				if (agreementUnit == null) {
+					throw new JeecgBootException("未找到合同单位");
+				}
+				ArrayList<BusAgreementOrderFee> memberBalanceLogList = new ArrayList<>();
+				goodsPaymentList.forEach(payment -> {
+					BusAgreementOrderFee agreementOrderFee = marketAgreementUnitService.agreementPayFee(agreementUnit, payment.getPayMoney(), payment.getId(), hotel);
+					memberBalanceLogList.add(agreementOrderFee);
+				});
+				marketAgreementUnitService.updateById(agreementUnit);
+				agreementOrderFeeService.saveBatch(memberBalanceLogList);
+			}
+		});
 		posOrderGoods.setSettleTime(new Date());
 		posOrderGoods.setStatus(1);
 		posOrderGoods.setPayMoney(sum);
 		posOrderGoods.setCouponMoney(posOrderGoods.getConsumeMoney().subtract(sum));
 		posOrderGoods.setPayInfo(payInfo);
 		posOrderGoodsService.updateById(posOrderGoods);
-
+		// 桌台下单情况下,修改桌台状态
 		if (ObjectUtils.isNotEmpty(posOrderGoods.getPosTableId())) {
 			LambdaUpdateWrapper<PosTable> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
 			lambdaUpdateWrapper.eq(PosTable::getId, posOrderGoods.getPosTableId());
 			lambdaUpdateWrapper.set(PosTable::getState, 4);
 			posTableService.update(lambdaUpdateWrapper);
+		} else {
+			// 如果是大厅结账, 支付后减库存
+			List<PosOrderGoodsDetail> orderGoodsDetailList = posOrderGoodsDetailService.list(Wrappers.<PosOrderGoodsDetail>lambdaQuery()
+					.eq(PosOrderGoodsDetail::getOrderId,posOrderGoods.getCode()));
+			List<String> goodIds = orderGoodsDetailList.stream().map(PosOrderGoodsDetail::getGoodsId).collect(Collectors.toList());
+			List<CesGoods> goodsList = goodsService.listByIds(goodIds);
+			orderGoodsDetailList.forEach(detail -> {
+				Optional<CesGoods> goodsOptional = goodsList.stream().filter(good -> good.getId().equals(detail.getGoodsId())).findFirst();
+				goodsOptional.ifPresent(e -> {
+					int differ = e.getInventory() - detail.getNum();
+					if (differ < 0){
+						throw new JeecgBootException(e.getName() + "库存不足");
+					}
+					e.setInventory(differ);
+					// TODO: 2023/9/14 减少仓库库存操作
+				});
+			});
+			goodsService.updateBatchById(goodsList);
 		}
+
 		return Result.OK("添加成功!");
 	}
 

+ 2 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/dto/OrderPaymentDto.java

@@ -15,4 +15,6 @@ public class OrderPaymentDto {
     private List<PosOrderGoodsPayment> paymentList;
     private String orderCode;
     private BigDecimal couponPrice;
+    private String cardId;
+    private String agreementId;
 }

+ 4 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/entity/PosOrderGoods.java

@@ -116,4 +116,8 @@ public class PosOrderGoods implements Serializable {
 
     @TableField(exist = false)
     private String posTypeName;
+
+    /** 是挂单 */
+    @TableField(exist = false)
+    private Boolean isPending;
 }

+ 2 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/service/IPosOrderGoodsService.java

@@ -16,4 +16,6 @@ public interface IPosOrderGoodsService extends IService<PosOrderGoods> {
     PosOrderGoods getOrderByTableId(String tableId);
 
     Boolean addRoomFee(PosOrderGoods posOrderGoods,String hotelId);
+
+    PosOrderGoods addOrder(PosOrderGoods posOrderGoods);
 }

+ 150 - 17
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/service/impl/PosOrderGoodsServiceImpl.java

@@ -1,12 +1,20 @@
 package org.jeecg.modules.pos.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.lang.Snowflake;
+import cn.hutool.core.util.BooleanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.apache.commons.lang3.ObjectUtils;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.common.util.TokenUtils;
 import org.jeecg.modules.business.entity.BusBookingRooms;
 import org.jeecg.modules.business.entity.BusOrderFee;
 import org.jeecg.modules.business.entity.BusOrderFeeGoods;
@@ -18,17 +26,18 @@ import org.jeecg.modules.pos.entity.PosOrderGoods;
 import org.jeecg.modules.pos.entity.PosOrderGoodsDetail;
 import org.jeecg.modules.pos.entity.PosTable;
 import org.jeecg.modules.pos.mapper.PosOrderGoodsMapper;
-import org.jeecg.modules.pos.service.IPosOrderGoodsDetailService;
-import org.jeecg.modules.pos.service.IPosOrderGoodsService;
-import org.jeecg.modules.pos.service.IPosTableService;
+import org.jeecg.modules.pos.service.*;
+import org.jeecg.modules.rooms.entity.CesGoods;
+import org.jeecg.modules.rooms.service.CesGoodsServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.List;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.*;
 
 /**
  * @Description: pos_order_goods
@@ -52,6 +61,12 @@ public class PosOrderGoodsServiceImpl extends ServiceImpl<PosOrderGoodsMapper, P
     @Resource
     private IBusOrderFeeGoodsService orderFeeGoodsService;
 
+    @Resource
+    private CesGoodsServiceImpl cesGoodsService;
+
+    @Resource
+    private  IBusRoomBookingOrdersService busRoomBookingOrdersService;
+
     @Override
     public PosOrderGoods getOrderByTableId(String tableId) {
         LambdaQueryWrapper<PosOrderGoods> queryWrapper = new LambdaQueryWrapper<PosOrderGoods>()
@@ -78,17 +93,24 @@ public class PosOrderGoodsServiceImpl extends ServiceImpl<PosOrderGoodsMapper, P
         if (ObjectUtil.isEmpty(bookingRoom)){
             throw new JeecgBootException("未找到订单关联的房间");
         }
-        if (posOrderGoods.getId().isEmpty()){
-            throw new JeecgBootException("未找到订单");
+        if (StrUtil.isEmpty(posOrderGoods.getId()) && CollUtil.isEmpty(posOrderGoods.getPosOrderGoodsDetailList())){
+            throw new JeecgBootException("未找到商品订单");
         }
-        PosOrderGoods orderGoods = getById(posOrderGoods.getId());
-        if (ObjectUtil.isEmpty(orderGoods) || orderGoods.getCode().isEmpty()){
-            throw new JeecgBootException("未找到订单");
+        PosOrderGoods orderGoods;
+        if (CollUtil.isNotEmpty(posOrderGoods.getPosOrderGoodsDetailList())) {
+            // 如果存在未加入订单的商品,先加入订单
+            orderGoods = addOrder(posOrderGoods);
+        } else {
+            orderGoods = getById(posOrderGoods.getId());
+            orderGoods.setToRoomFeeOrderId(posOrderGoods.getToRoomFeeOrderId());
         }
-        orderGoods.setToRoomFeeOrderId(posOrderGoods.getToRoomFeeOrderId());
-        PosTable posTable = posTableService.getById(orderGoods.getPosTableId());
-        if (ObjectUtil.isEmpty(posTable)) {
-            throw new JeecgBootException("未找到桌号");
+        if (StrUtil.isNotEmpty(orderGoods.getPosTableId())) {
+            PosTable posTable = posTableService.getById(orderGoods.getPosTableId());
+            if (ObjectUtil.isEmpty(posTable)) {
+                throw new JeecgBootException("未找到桌号");
+            }
+            posTable.setState(4);
+            posTableService.updateById(posTable);
         }
         List<PosOrderGoodsDetail> goodsDetailList = posOrderGoodsDetailService.list(Wrappers.<PosOrderGoodsDetail>lambdaQuery()
                 .eq(PosOrderGoodsDetail::getOrderId, orderGoods.getCode()));
@@ -100,7 +122,9 @@ public class PosOrderGoodsServiceImpl extends ServiceImpl<PosOrderGoodsMapper, P
             busOrderFee.setId(StrUtil.toString(id));
             busOrderFee.setFeeType(FeeType.CONSUME.getKey());
             busOrderFee.setSubjectType(FeeSubjectType.DIAN_PIN.getKey());
-            busOrderFee.setMoney(e.getPayMoney());
+            busOrderFee.setMoney(e.getPayMoney().multiply(BigDecimal.valueOf(e.getNum())));
+            busOrderFee.setOriginalMoney(e.getPayMoney().multiply(BigDecimal.valueOf(e.getNum())));
+            busOrderFee.setDayTime(new Date());
             busOrderFee.setHotelId(hotelId);
             busOrderFee.setRoomId(bookingRoom.getRoomId());
             busOrderFee.setLivingOrderId(orderGoods.getToRoomFeeOrderId());
@@ -118,8 +142,117 @@ public class PosOrderGoodsServiceImpl extends ServiceImpl<PosOrderGoodsMapper, P
         orderFeeGoodsService.saveBatch(feeGoodsList);
         orderGoods.setStatus(1);
         updateById(orderGoods);
-        posTable.setState(4);
-        posTableService.updateById(posTable);
         return true;
     }
+
+    @Override
+    public PosOrderGoods addOrder(PosOrderGoods posOrderGoods) {
+        // 直接点击结账时id为空
+        if (ObjectUtils.isEmpty(posOrderGoods.getId())) {
+            // 点击结账,且不是桌台
+            if (ObjectUtils.isEmpty(posOrderGoods.getPosTableId())) {
+                // 找出今日最后的一个账单
+                LocalDateTime localDateTime = LocalDateTime.now().withNano(0).withSecond(0).withMinute(0).withHour(0);
+                LocalDateTime[] arr = new LocalDateTime[]{localDateTime, localDateTime.withHour(23).withMinute(59)};
+                LambdaQueryWrapper<PosOrderGoods> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+                lambdaQueryWrapper.eq(PosOrderGoods::getHotelId, posOrderGoods.getHotelId());
+                lambdaQueryWrapper.ge(PosOrderGoods::getCreateTime, arr[0]);
+                lambdaQueryWrapper.le(PosOrderGoods::getCreateTime, arr[1]);
+                lambdaQueryWrapper.and(o -> o.isNull(PosOrderGoods::getPosTableId).or().eq(PosOrderGoods::getPosTableId,""));
+                Page<PosOrderGoods> page = new Page<>(1, 1);
+                lambdaQueryWrapper.orderByDesc(PosOrderGoods::getCreateTime);
+                IPage<PosOrderGoods> pageList = page(page, lambdaQueryWrapper);
+                // 设置取餐号
+                if (ObjectUtils.isNotEmpty(pageList.getRecords())) {
+                    String no = pageList.getRecords().get(0).getTableNo();
+                    try {
+                        Integer newNo = Integer.parseInt(no) + 1;
+                        posOrderGoods.setTableNo(String.format("%03d", newNo));
+                    } catch (NumberFormatException ex) {
+                        posOrderGoods.setTableNo("001");
+                    }
+                } else {
+                    posOrderGoods.setTableNo("001");
+                }
+            }
+            posOrderGoods.setCode(randomNumber("P"));
+        } else {
+            // 存在订单(桌台点单,取单支付)
+            List<PosOrderGoodsDetail> list = posOrderGoods.getPosOrderGoodsDetailList();
+            String toRoomFeeOrderId = posOrderGoods.getToRoomFeeOrderId();
+            String tableId=posOrderGoods.getPosTableId();
+            String tableNo=posOrderGoods.getTableNo();
+            Boolean isPending = posOrderGoods.getIsPending();
+            // 找出订单,将订单重新赋值
+            posOrderGoods = getById(posOrderGoods.getId());
+            posOrderGoods.setPosOrderGoodsDetailList(list);
+            posOrderGoods.setToRoomFeeOrderId(toRoomFeeOrderId);
+            posOrderGoods.setPosTableId(tableId);
+            posOrderGoods.setTableNo(tableNo);
+            posOrderGoods.setIsPending(isPending);
+        }
+        posOrderGoods.setTenantId(TokenUtils.currentTenantId());
+        BigDecimal amount = BigDecimal.ZERO;
+        if (ObjectUtil.isNotEmpty(posOrderGoods.getMoney())){
+            amount = posOrderGoods.getMoney();
+        }
+        for (PosOrderGoodsDetail posOrderGoodsDetail : posOrderGoods.getPosOrderGoodsDetailList()) {
+            amount = amount.add(posOrderGoodsDetail.getMoney().multiply(BigDecimal.valueOf(posOrderGoodsDetail.getNum())));
+            posOrderGoodsDetail.setTenantId(posOrderGoods.getTenantId());
+            posOrderGoodsDetail.setHotelId(posOrderGoods.getHotelId());
+            posOrderGoodsDetail.setOrderId(posOrderGoods.getCode());
+            posOrderGoodsDetail.setCouponMoney(posOrderGoodsDetail.getMoney());
+            posOrderGoodsDetail.setPayMoney(posOrderGoodsDetail.getMoney());
+            posOrderGoodsDetail.setOrderId(posOrderGoods.getCode());
+        }
+        posOrderGoods.setMoney(amount);
+        posOrderGoods.setConsumeMoney(amount);
+        posOrderGoods.setCreateTime(new Date());
+
+        if (ObjectUtils.isNotEmpty(posOrderGoods.getToRoomFeeOrderId())) {
+            posOrderGoods.setStatus(1);
+            posOrderGoods.setSettleTime(new Date());
+            posOrderGoods.setPayInfo("挂房账");
+
+        }
+        Boolean res = saveOrUpdate(posOrderGoods);
+        if (res) {
+            res = posOrderGoodsDetailService.saveBatch(posOrderGoods.getPosOrderGoodsDetailList());
+            if (res && (ObjectUtils.isNotEmpty(posOrderGoods.getPosTableId()) || BooleanUtil.isTrue(posOrderGoods.getIsPending())
+                    || StrUtil.isNotEmpty(posOrderGoods.getToRoomFeeOrderId()))) {
+                //桌台下单或者挂单时商品减库存   如果是大厅点击结账,支付后减库存
+                for (PosOrderGoodsDetail posOrderGoodsDetail : posOrderGoods.getPosOrderGoodsDetailList()) {
+                    CesGoods cesGoods = cesGoodsService.getById(posOrderGoodsDetail.getGoodsId());
+                    if (ObjectUtils.isNotEmpty(cesGoods)) {
+                        Integer c = cesGoods.getInventory() - posOrderGoodsDetail.getNum();
+                        if (c < 0) {
+                            c = 0;
+                        }
+                        cesGoods.setInventory(c);
+                        cesGoodsService.updateById(cesGoods);
+                    }
+                }
+            }
+            LambdaUpdateWrapper<PosTable> lambdaUpdateWrapper=new LambdaUpdateWrapper<>();
+            lambdaUpdateWrapper.eq(PosTable::getId,posOrderGoods.getPosTableId());
+            lambdaUpdateWrapper.set(PosTable::getState,2);
+            posTableService.update(lambdaUpdateWrapper);
+        }
+        return posOrderGoods;
+    }
+
+
+    /**
+     * 生成16位数字+prefix
+     * @param prefix
+     * @return
+     */
+    private String randomNumber(String prefix) {
+        int first = new Random(10).nextInt(8) + 1;
+        int hashCode = UUID.randomUUID().toString().hashCode();
+        if (hashCode < 0) {
+            hashCode = -hashCode;
+        }
+        return prefix + first + String.format("%015d", hashCode);
+    }
 }

+ 1 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/job/LivingRoomOrderFeeJob.java

@@ -26,6 +26,7 @@ public class LivingRoomOrderFeeJob implements Job {
 
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        log.info("改房间费用订单");
         bookingOrdersService.syncDayRoomOrder(parameter);
     }
 }

+ 1 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/DTO/CesGoodsSearchDto.java

@@ -6,7 +6,7 @@ import org.jeecg.common.api.dto.BasePage;
 @Data
 public class CesGoodsSearchDto  extends BasePage {
     private String search;
-
+    private String name;
     private String hotelId;
     private String typeId;
 }

+ 2 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/DTO/CesRoomSearchDto.java

@@ -11,4 +11,6 @@ public class CesRoomSearchDto  extends BasePage {
 
     private String floorId;
 
+    private String roomName;
+
 }

+ 3 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/Vo/BookingRealtimeVo.java

@@ -2,8 +2,10 @@ package org.jeecg.modules.rooms.Vo;
 
 import lombok.Data;
 import org.jeecg.modules.business.entity.BusBookingLayoutDayPrice;
+import org.jeecg.modules.business.entity.BusBookingRooms;
 import org.jeecg.modules.business.entity.BusCustomer;
 import org.jeecg.modules.business.entity.BusRoomBookingOrders;
+import org.jeecg.modules.rooms.entity.CesRooms;
 
 import java.util.List;
 
@@ -12,4 +14,5 @@ public class BookingRealtimeVo {
     private BusRoomBookingOrders bookingOrder;
     private BusCustomer bookingCustomer;
     private List<BusBookingLayoutDayPrice> layoutDayPrices;
+    private List<BusBookingRooms> releBookingRooms;
 }

+ 5 - 2
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/controller/CesRoomsController.java

@@ -5,7 +5,9 @@ import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.EnumUtil;
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -17,6 +19,7 @@ import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.formula.functions.T;
 import org.jeecg.common.Enum.ResultCode;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
@@ -443,8 +446,8 @@ public class CesRoomsController {
      * @param roomIds
      * @return
      */
-    @AutoLog(value = "房间智障")
-    @ApiOperation(value="房间智障", notes="房间智障")
+    @AutoLog(value = "房间置脏")
+    @ApiOperation(value="房间置脏", notes="房间置脏")
     @PostMapping(value = "/dirtyRoom")
     public Result<String> dirtyRoom(@RequestParam(name="roomIds",required=true) String roomIds) {
         List<String> list = Arrays.asList(roomIds.split(","));

+ 2 - 2
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/entity/CesAllDayPriceRule.java

@@ -44,8 +44,8 @@ public class CesAllDayPriceRule extends Model<CesAllDayPriceRule> {
 
     /**
      * 1按分钟加收
-2 按半天房费加收
-3 不收房费
+        2 按半天房费加收
+        3 不收房费
      */
     private Integer timeOutRule;
 

+ 2 - 2
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/mapper/CesRoomsMapper.java

@@ -24,7 +24,7 @@ import java.util.List;
  */
 public interface CesRoomsMapper extends BaseMapper<CesRooms> {
 
-    List<CesRooms> canUseRooms(String hotelId, Date startOf, Date endOf);
+    List<CesRooms> canUseRooms(String hotelId, String startOf, String endOf);
     List<AlreadyUseLayoutNumberVo> alreadyUseLayoutNumber(String hotelId, Date startOf, Date endOf);
 
     /**
@@ -70,6 +70,6 @@ public interface CesRoomsMapper extends BaseMapper<CesRooms> {
     @Select("SELECT cr.* from bus_room_booking_orders brbo\n" +
             "inner join bus_booking_rooms bbr on brbo.id = bbr.booking_orders_id\n" +
             "inner join ces_rooms cr on bbr.room_id = cr.id\n" +
-            "where brbo.arrival_time > #{nowDateStr} and brbo.arrival_time < #{tomorrowStr}")
+            "where brbo.booking_status = 1 and brbo.arrival_time > #{nowDateStr} and brbo.arrival_time < #{tomorrowStr}")
     List<CesRooms> getReserveRoom(@Param("nowDateStr") String nowDateStr, @Param("tomorrowStr") String tomorrowStr);
 }

+ 26 - 54
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/mapper/xml/CesRoomsMapper.xml

@@ -2,63 +2,35 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.modules.rooms.mapper.CesRoomsMapper">
     <select id="canUseRooms" resultType="org.jeecg.modules.rooms.entity.CesRooms">
-        SELECT
-            *
-        FROM
-            ces_rooms
-        WHERE
-            hotel_id = #{hotelId}
-          AND invalid = 0
-          AND state = 1
-          AND id NOT IN (
-            SELECT DISTINCT
-                br.room_id
-            FROM
-                bus_booking_rooms br
-                    INNER JOIN bus_room_booking_orders o ON br.booking_orders_id = o.id
-            WHERE
-                br.booking_type = 1
-              AND br.room_id IS NOT NULL
+        SELECT * FROM ces_rooms
+        WHERE hotel_id = #{hotelId} AND invalid = 0 AND id NOT IN (
+            SELECT DISTINCT br.room_id FROM bus_booking_rooms br
+            INNER JOIN bus_room_booking_orders o ON br.booking_orders_id = o.id
+            WHERE br.booking_type = 1 AND br.room_id IS NOT NULL
 --               And br.room_status = 1 Or br.room_status = 1
-              AND (o.booking_status = 2 or o.booking_status = 4)
-              and TIMESTAMPDIFF(minute, ADDDATE(now(),INTERVAL 8 HOUR),o.arrival_time) > -2 -- 订单超过当前时间2分钟以后 则不算入已预定中 时间 > -2 算是正常预约,超过的一律算做超时订单
-              AND (
-                ( o.arrival_time &lt;= #{startOf} AND o.due_out_time &gt;= #{startOf} ) -- 预抵时间在别的客人预定时间范围内
-		OR ( o.arrival_time &lt;= #{endOf} AND o.due_out_time &gt;= #{endOf} ) -- 或者预离时间在别的客户预定范围内
-
-	)
-        UNION ALL
-        SELECT DISTINCT
-            br.room_id
-        FROM
-            bus_booking_rooms br
-        inner join bus_rooms_living_order lo on lo.booking_room_id = br.id
-        WHERE
-            br.booking_type = 1
-        AND br.room_id IS NOT NULL
-        AND (lo.settle_type = -1)
-        and (
-            ( lo.arrival_time &lt;= #{startOf} AND lo.due_out_time >= #{startOf} ) -- 预抵时间在别的客人预定时间范围内
-        OR ( lo.arrival_time &lt;= #{endOf} AND lo.due_out_time >= #{endOf} ) -- 或者预离时间在别的客户预定范围内
-        )
+            AND o.booking_status = 1
+            and TIMESTAMPDIFF(minute, ADDDATE(now(),INTERVAL 8 HOUR),o.arrival_time) > -2 -- 订单超过当前时间2分钟以后 则不算入已预定中 时间 > -2 算是正常预约,超过的一律算做超时订单
+            AND (( o.arrival_time &lt;= #{startOf} AND o.due_out_time &gt;= #{startOf} ) -- 预抵时间在别的客人预定时间范围内
+            OR ( o.arrival_time &lt;= #{endOf} AND o.due_out_time &gt;= #{endOf} )) -- 或者预离时间在别的客户预定范围内
 
-	UNION ALL
-        SELECT
-            br.room_id
-        FROM
-            bus_booking_rooms br
-                INNER JOIN bus_room_booking_orders o ON br.booking_orders_id = o.id
-                INNER JOIN bus_booking_batch_info bi ON br.booking_batch_id = bi.id
-                AND (
-            ( bi.arrival_time &lt;= #{startOf} AND bi.due_out_time &gt;= #{startOf} ) -- 预抵时间在别的客人预定时间范围内
-		OR ( bi.arrival_time &lt;= #{endOf} AND bi.due_out_time &gt;= #{endOf} ) -- 或者预离时间在别的客户预定范围内
+            UNION ALL
+            SELECT DISTINCT br.room_id FROM bus_booking_rooms br
+            inner join bus_rooms_living_order lo on lo.booking_room_id = br.id
+            WHERE br.booking_type = 1 AND br.room_id IS NOT NULL AND (lo.settle_type = -1)
+            and (( lo.arrival_time &lt;= #{startOf} AND lo.due_out_time >= #{startOf} ) -- 预抵时间在别的客人预定时间范围内
+            OR ( lo.arrival_time &lt;= #{endOf} AND lo.due_out_time >= #{endOf} )) -- 或者预离时间在别的客户预定范围内
 
-	)
-	WHERE
-		br.booking_type = 2
-		AND br.room_id IS NOT NULL
-	    AND (o.booking_status = 1 or o.booking_status = 3)
-        and TIMESTAMPDIFF(minute, ADDDATE(now(),INTERVAL 8 HOUR),bi.arrival_time) > -2 -- 计算批次号中如果有超时的批次,则批次关联房间均失效
+            UNION ALL
+            SELECT br.room_id FROM bus_booking_rooms br
+            INNER JOIN bus_room_booking_orders o ON br.booking_orders_id = o.id
+            INNER JOIN bus_booking_batch_info bi ON br.booking_batch_id = bi.id
+            AND (( bi.arrival_time &lt;= #{startOf} AND bi.due_out_time &gt;= #{startOf} ) -- 预抵时间在别的客人预定时间范围内
+            OR ( bi.arrival_time &lt;= #{endOf} AND bi.due_out_time &gt;= #{endOf} )) -- 或者预离时间在别的客户预定范围内
+            WHERE
+                br.booking_type = 2
+                AND br.room_id IS NOT NULL
+                AND (o.booking_status = 1 or o.booking_status = 3)
+                and TIMESTAMPDIFF(minute, ADDDATE(now(),INTERVAL 8 HOUR),bi.arrival_time) > -2 -- 计算批次号中如果有超时的批次,则批次关联房间均失效
 	)
     </select>
     <select id="alreadyUseLayoutNumber" resultType="org.jeecg.modules.rooms.Vo.AlreadyUseLayoutNumberVo">

+ 2 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/service/CesGoodsServiceImpl.java

@@ -3,6 +3,7 @@ package org.jeecg.modules.rooms.service;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.bean.copier.CopyOptions;
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -78,8 +79,8 @@ private KcGoodsServiceImpl kcGoodsService;
         if (!StringUtils.isBlank(dto.getSearch())) {
             String search = CommonUtils.escapeChar(dto.getSearch());
             queryWrapper.like(CesGoods.BAR_CODE, search);
-            queryWrapper.like(CesGoods.NAME, search);
         }
+        queryWrapper.like(StrUtil.isNotEmpty(dto.getName()), CesGoods.NAME, dto.getName());
         queryWrapper.eq(CesGoods.HOTEL_ID, dto.getHotelId());
         queryWrapper.eq(CesGoods.INVALID, false);
         queryWrapper.orderByDesc(CesGoods.CREATAT);

+ 5 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/service/CesRoomsServiceImpl.java

@@ -81,6 +81,7 @@ public class CesRoomsServiceImpl extends ServiceImpl<CesRoomsMapper, CesRooms> i
                 .eq(!StringUtils.isBlank(dto.getBuildId()),CesRooms.BUILD_ID, dto.getBuildId())
                 .eq(!StringUtils.isBlank(dto.getFloorId()),CesRooms.FLOOR_ID, dto.getFloorId())
                 .eq(!StringUtils.isBlank(dto.getHotelId()),CesRooms.HOTEL_ID, dto.getHotelId())
+                .like(!StringUtils.isBlank(dto.getRoomName()),CesRooms.NAME, dto.getRoomName())
                 .eq(CesRooms.INVALID, false).orderByDesc(CesRooms.SORT, CesRooms.CREATEAT);
         IPage<CesRooms> dataPage = roomsMapper.selectPage(new Page<>(dto.getPageNo().intValue(), dto.getPageSize().intValue()), queryWrapper);
         List<CesRooms> records = dataPage.getRecords();
@@ -302,7 +303,9 @@ public class CesRoomsServiceImpl extends ServiceImpl<CesRoomsMapper, CesRooms> i
             wrappers.eq("id", param.getLayoutId());
         }
         List<CesRoomLayout> layouts = layoutService.list(wrappers);
-        List<CesRooms> allRooms = baseMapper.canUseRooms(param.getHotelId(), param.getStartOf(), param.getEndOf());
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+
+        List<CesRooms> allRooms = baseMapper.canUseRooms(param.getHotelId(), formatter.format(param.getStartOf()), formatter.format(param.getEndOf()));
         List<AlreadyUseLayoutNumberVo> useLayoutNumbers = baseMapper.alreadyUseLayoutNumber(param.getHotelId(), param.getStartOf(), param.getEndOf());
         List<CesRoomBuildingFloor> allBuildingFloors = buildingFloorService.list(Wrappers.<CesRoomBuildingFloor>query().eq("hotelId", param.getHotelId()).eq("invalid", false));
         List<CanUseResultVo> results = new ArrayList<>();
@@ -441,6 +444,7 @@ public class CesRoomsServiceImpl extends ServiceImpl<CesRoomsMapper, CesRooms> i
 
     }
 
+    // 如果是空间,且为今天预约,将房间状态改为预约态
     public Boolean getReserveRoom() {
 
         // 将Calendar设置为当前日期