|
|
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
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.BatchOrderSavaDto;
|
|
|
import org.jeecg.modules.business.dto.BookingBatchRoomsDto;
|
|
|
import org.jeecg.modules.business.dto.BookingOrderSaveDto;
|
|
|
import org.jeecg.modules.business.entity.*;
|
|
|
@@ -558,6 +559,141 @@ public class BusRoomBookingOrdersServiceImpl extends ServiceImpl<BusRoomBookingO
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String batchOrderSave(BatchOrderSavaDto item) {
|
|
|
+ LoginUser user = TokenUtils.getAuthUser();
|
|
|
+ if(item == null || item.getOrderInfo() == null || item.getOrderInfo().getBookingOrdersId() == null) throw
|
|
|
+ new JeecgBootException("参数错误");
|
|
|
+ BusRoomBookingOrders orignOrder = getById(item.getOrderInfo().getBookingOrdersId());
|
|
|
+ if(orignOrder == null) throw
|
|
|
+ new JeecgBootException("关联订单信息不存在");
|
|
|
+ item.getOrderInfo().setCreateTime(new Date());
|
|
|
+ item.getOrderInfo().setCreateUser(user.getId());
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
|
|
+ item.getOrderInfo().setBatchNo("YDPC"+sdf.format(System.currentTimeMillis()));
|
|
|
+// if(item.getOrderInfo().getBookingType() == null)
|
|
|
+
|
|
|
+ if(item.getOrderInfo().getCustomerSource() == null || item.getOrderInfo().getCustomerSource().isEmpty())
|
|
|
+ throw new JeecgBootException("客人来源不能为空");
|
|
|
+ if(item.getOrderInfo().getCustomerType() == null)
|
|
|
+ throw new JeecgBootException("客人类型不能为空");
|
|
|
+ if(CustomerTypeEnum.val(item.getOrderInfo().getCustomerType()) == null)
|
|
|
+ throw new JeecgBootException("客人类型不正确");
|
|
|
+ if(item.getOrderInfo().getCustomerType().equals(CustomerTypeEnum.VIP.getKey())
|
|
|
+ && (item.getOrderInfo().getVipCustomerId() == null || item.getOrderInfo().getVipCustomerId().isEmpty()))
|
|
|
+ throw new JeecgBootException("客人类型为会员时,请选择会员");
|
|
|
+ if(item.getOrderInfo().getCustomerType().equals(CustomerTypeEnum.PROTOCOL.getKey())
|
|
|
+ && (item.getOrderInfo().getContactId() == null || item.getOrderInfo().getContactId().isEmpty()
|
|
|
+ || item.getOrderInfo().getContractTeamProtocolId() == null || item.getOrderInfo().getContractTeamProtocolId().isEmpty()
|
|
|
+ )
|
|
|
+ )
|
|
|
+ throw new JeecgBootException("客人类型为协议单位时,请选择协议单位和相关协议");
|
|
|
+ if(item.getOrderInfo().getCustomerType().equals(CustomerTypeEnum.PROXY.getKey())
|
|
|
+ && (item.getOrderInfo().getAgencyName() == null || item.getOrderInfo().getAgencyName().isEmpty())
|
|
|
+ )
|
|
|
+ throw new JeecgBootException("客人类型为中介时,请填写中介信息");
|
|
|
+ // 钟点房判断,计费项目判定
|
|
|
+ if(item.getOrderInfo().getBookingType().equals(CheckInTypeEnum.HOUR_TIME.getKey())) {
|
|
|
+ if(item.getOrderInfo().getHourRoomId() == null || item.getOrderInfo().getHourRoomId().isEmpty())
|
|
|
+ throw new JeecgBootException("钟点房计费项目不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 【添加客人信息 Start】
|
|
|
+ if(item.getContactName() != null && !item.getContactName().isEmpty() && item.getPhone() != null && !item.getPhone().isEmpty()){
|
|
|
+ BusCustomer customer = customerService.getOne(Wrappers.<BusCustomer>query().eq("name",item.getContactName())
|
|
|
+ .eq("phone",item.getPhone()));
|
|
|
+ if(customer == null) {
|
|
|
+ // save customer
|
|
|
+ BusCustomer newCustomer = new BusCustomer();
|
|
|
+ newCustomer.setCreateTime(new Date());
|
|
|
+ newCustomer.setCreateUser(user.getId());
|
|
|
+ newCustomer.setHotelId(user.getRelTenantIds());
|
|
|
+ newCustomer.setTenantId(user.getRelTenantIds());
|
|
|
+ newCustomer.setName(item.getContactName());
|
|
|
+ newCustomer.setPhone(item.getPhone());
|
|
|
+ newCustomer.setCertType(1); // 身份证
|
|
|
+ customerService.save(newCustomer);
|
|
|
+ item.getOrderInfo().setContactId(newCustomer.getId());
|
|
|
+ } else {
|
|
|
+ item.getOrderInfo().setContactId(customer.getId());
|
|
|
+ }
|
|
|
+ } else throw new JeecgBootException("客人信息不能为空");
|
|
|
+
|
|
|
+ // 【添加客人信息 end】
|
|
|
+
|
|
|
+
|
|
|
+ BookingBatchRoomsDto c = new BookingBatchRoomsDto();
|
|
|
+
|
|
|
+ if(c.getArrivalTime() == null || c.getDueOutTime() == null)
|
|
|
+ throw new JeecgBootException("预抵时间和预离时间不能为空");
|
|
|
+ if(c.getArrivalTime().getTime() < new Date().getTime())
|
|
|
+ throw new JeecgBootException("预抵时间不能小于当前时间");
|
|
|
+ if(c.getArrivalTime().getTime() >= c.getDueOutTime().getTime())
|
|
|
+ throw new JeecgBootException("预抵时间不能大于或者等于预离时间");
|
|
|
+ // 非钟点房判定
|
|
|
+ if(!item.getOrderInfo().getBookingType().equals(CheckInTypeEnum.HOUR_TIME.getKey())) {
|
|
|
+ if(c.getDayCount() == null || c.getDayCount() <= 0)
|
|
|
+ throw new JeecgBootException("入住天数不能小于0");
|
|
|
+ }
|
|
|
+ if(c.getRoomIds() == null || c.getRoomIds().size() == 0)
|
|
|
+ throw new JeecgBootException("请选择批次房间");
|
|
|
+ SimpleDateFormat sdfPc = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
|
|
+ c.setBatchNo("YDPC"+sdfPc.format(System.currentTimeMillis()));
|
|
|
+ c.setBookingOrdersId(item.getOrderInfo().getId());
|
|
|
+// setBatchOrderInfo(item.getOrderInfo(),c);
|
|
|
+// BusBookingBatch batchItem = copyBatchToBase(c);
|
|
|
+ BusBookingBatch batchItem = copyBatchToBase(c);
|
|
|
+ bookingBatchService.save(batchItem);
|
|
|
+ List<BusBookingRooms> batchBookingRooms = new ArrayList<>();
|
|
|
+ long mainCount = c.getRoomIds().stream().filter(t->t.getIsMain()!=null&&t.getIsMain()).count();
|
|
|
+ c.getRoomIds().forEach(s-> {
|
|
|
+ BusBookingRooms bookingRoomItem = new BusBookingRooms();
|
|
|
+ bookingRoomItem.setRoomId(s.getRoomId());
|
|
|
+ bookingRoomItem.setRoomLayoutId(s.getLayoutId());
|
|
|
+ if(s.getRoomId() != null && !s.getRoomId().isEmpty()){
|
|
|
+ bookingRoomItem.setRoomStatus(2);
|
|
|
+ } else {
|
|
|
+ bookingRoomItem.setRoomStatus(1);
|
|
|
+ }
|
|
|
+ if(mainCount != 1) {
|
|
|
+ bookingRoomItem.setIsMain(false);
|
|
|
+ } else {
|
|
|
+ bookingRoomItem.setIsMain(s.getIsMain());
|
|
|
+ }
|
|
|
+ bookingRoomItem.setBookingType(2);
|
|
|
+ bookingRoomItem.setBookingBatchId(batchItem.getId());
|
|
|
+ bookingRoomItem.setBookingOrdersId(item.getOrderInfo().getId());
|
|
|
+ batchBookingRooms.add(bookingRoomItem);
|
|
|
+ });
|
|
|
+ if(mainCount != 1) {
|
|
|
+ batchBookingRooms.get(0).setIsMain(true);
|
|
|
+ }
|
|
|
+ bookingRoomsService.saveBatch(batchBookingRooms);
|
|
|
+ // 以上处理批次关联的房间
|
|
|
+
|
|
|
+ //批次中处理每天房型价格 Start
|
|
|
+ if(c.getLayoutDayPrices() == null || c.getLayoutDayPrices().size() == 0)
|
|
|
+ throw new JeecgBootException("参数错误,批次中对应房型当天价格必传");
|
|
|
+ if(c.getLayoutDayPrices().stream().anyMatch(o->o.getPrice()==null || o.getDayTime() == null || o.getRoomLayoutId() == null))
|
|
|
+ throw new JeecgBootException("参数错误,批次中请传入价格、日期、房型");
|
|
|
+ c.getLayoutDayPrices().forEach(g->{
|
|
|
+ long roomCount = c.getRoomIds().stream().filter(e->e.getLayoutId().equals(g.getRoomLayoutId())).count();
|
|
|
+ if(roomCount > 0 ) {
|
|
|
+ g.setBookingOrderId(item.getOrderInfo().getId());
|
|
|
+ g.setBookingType(BookingOrdersType.TEAM.getKey());
|
|
|
+ g.setBatchId(batchItem.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<String> lList = c.getRoomIds().stream().map(a->a.getLayoutId()).collect(Collectors.toList());
|
|
|
+ dayPriceService.saveBatch(c.getLayoutDayPrices().stream().filter(x->lList.contains(x.getRoomLayoutId())).collect(Collectors.toList()));
|
|
|
+ //批次中处理每天房型价格 End
|
|
|
+
|
|
|
+ return batchItem.getBatchNo();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private BusBookingBatch copyBatchToBase(BookingBatchRoomsDto data) {
|
|
|
BusBookingBatch batch = new BookingBatchRoomsDto();
|