预约段 接口

This commit is contained in:
2025-11-27 18:12:00 +08:00
parent b5239368f5
commit a2fe3d5421
16 changed files with 949 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.BkContactList;
import java.util.List;
/**
* 通讯录联系人列表 映射层。
*
* @author ww
* @since 2025-11-27
*/
public interface BkContactListMapper extends BaseMapper<BkContactList> {
/**
* 获取店铺的通讯录联系人列表
* @param shopId 店铺ID
* @return 通讯录联系人列表
*/
List<BkContactList> getUserList(Long shopId);
}

View File

@@ -0,0 +1,21 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.BkOrder;
import java.time.LocalDate;
import java.util.List;
/**
* 预约单 映射层。
*
* @author ww
* @since 2025-11-27
*/
public interface BkOrderMapper extends BaseMapper<BkOrder> {
/**
* 查询预约单列表
*/
List<BkOrder> bookings(Long shopId, String search, LocalDate start, LocalDate end, String status);
}

View File

@@ -0,0 +1,37 @@
package com.czg.service.account.mapper;
import com.czg.account.vo.BkTableVO;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.BkOrderTable;
import java.time.LocalDate;
import java.util.List;
/**
* 预约单台桌关联 映射层。
*
* @author ww
* @since 2025-11-27
*/
public interface BkOrderTableMapper extends BaseMapper<BkOrderTable> {
/**
* 批量插入预约单台桌关联
*
* @param shopId 店铺id
* @param bookOrderId 预约单id
* @param bkOrderTables 台桌信息
*/
void customInsertBatch(Long shopId, Long bookOrderId, List<BkOrderTable> bkOrderTables);
/**
* 查询预约单台桌关联
*
* @param shopId 店铺id
* @param areaId 台桌区域id
* @param day 预约日期
* @param seatTimeType 预约时间类型
* @return 预约单台桌关联列表
*/
List<BkTableVO> table(Long shopId, Long areaId, LocalDate day, String seatTimeType);
}

View File

@@ -0,0 +1,39 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.BkContactList;
import com.czg.account.service.BkContactListService;
import com.czg.service.account.mapper.BkContactListMapper;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 通讯录联系人列表 服务层实现。
*
* @author ww
* @since 2025-11-27
*/
@Service
public class BkContactListServiceImpl extends ServiceImpl<BkContactListMapper, BkContactList> implements BkContactListService{
@Override
public List<BkContactList> getUserList(Long shopId, Set<String> phones) {
remove(QueryWrapper.create().eq(BkContactList::getShopId, shopId));
saveBatch(phones.stream()
.filter(StrUtil::isNotEmpty)
.map(phone -> {
BkContactList bkContact = new BkContactList();
bkContact.setShopId(shopId);
bkContact.setPhone(phone.trim());
return bkContact;
})
.collect(Collectors.toList()));
return mapper.getUserList(shopId);
}
}

View File

@@ -0,0 +1,98 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import com.czg.account.dto.BkOrderDTO;
import com.czg.account.entity.BkOrderTable;
import com.czg.account.vo.BkTableVO;
import com.czg.exception.CzgException;
import com.czg.service.account.mapper.BkOrderTableMapper;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.BkOrder;
import com.czg.account.service.BkOrderService;
import com.czg.service.account.mapper.BkOrderMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
/**
* 预约单 服务层实现。
*
* @author ww
* @since 2025-11-27
*/
@Service
public class BkOrderServiceImpl extends ServiceImpl<BkOrderMapper, BkOrder> implements BkOrderService {
@Resource
private BkOrderTableMapper tableMapper;
/**
* 预约端-预约单:列表
*/
@Override
public List<BkOrder> bookings(Long shopId, String search, LocalDate start, LocalDate end, String status) {
return mapper.bookings(shopId, search, start, end, status);
}
@Override
public void booking(Long shopId, BkOrderDTO bkOrder) {
BkOrder bkOrderEntity = BeanUtil.copyProperties(bkOrder, BkOrder.class);
bkOrderEntity.setShopId(shopId);
if (bkOrder.getId() != null) {
bkOrderEntity.setUpBookingTime(LocalDateTime.now());
tableMapper.deleteByQuery(QueryWrapper.create().eq(BkOrderTable::getBookOrderId, bkOrderEntity.getId()));
tableMapper.customInsertBatch(shopId, bkOrderEntity.getId(), bkOrder.getBookingTables());
} else {
bkOrderEntity.setBookingOrderNo("BK" + IdUtil.getSnowflakeNextId());
}
bkOrderEntity.setStatus("待到店");
bkOrderEntity.setStandardPricePerson(BigDecimal.ZERO);
if (bkOrderEntity.getStandardPrice() != null && bkOrderEntity.getStandardPrice().compareTo(BigDecimal.ZERO) > 0) {
if (bkOrderEntity.getStandardPriceStr().contains("")) {
BigDecimal seatNumBd = new BigDecimal(bkOrderEntity.getSeatNum());
BigDecimal bookingTableNumBd = new BigDecimal(bkOrderEntity.getBookingTableNum());
BigDecimal seatPerTable = seatNumBd.divide(bookingTableNumBd, 2, RoundingMode.HALF_UP);
BigDecimal divide = bkOrderEntity.getStandardPrice().divide(seatPerTable, 2, RoundingMode.HALF_UP);
bkOrderEntity.setStandardPricePerson(divide);
} else {
bkOrderEntity.setStandardPricePerson(bkOrderEntity.getStandardPrice());
}
}
saveOrUpdate(bkOrderEntity);
if (bkOrder.getId() == null) {
tableMapper.customInsertBatch(shopId, bkOrderEntity.getId(), bkOrder.getBookingTables());
}
}
@Override
public void upStatus(Long shopId, String status, Long bkOrderId, String cancelReason) {
BkOrder upBkOrder = new BkOrder();
if ("已取消".equals(status)) {
upBkOrder.setStatus(status);
upBkOrder.setCancelReason(cancelReason);
upBkOrder.setCancelTime(LocalDateTime.now());
} else if ("已到店".equals(status)) {
upBkOrder.setStatus(status);
upBkOrder.setArrivalTime(LocalDateTime.now());
}
boolean update = update(upBkOrder, QueryWrapper.create().eq(BkOrder::getId, bkOrderId).eq(BkOrder::getShopId, shopId));
if (!update) {
throw new CzgException("修改失败");
}
}
@Override
public List<BkTableVO> table(Long shopId, Long areaId, LocalDate day, String seatTimeType) {
return tableMapper.table(shopId, areaId, day, seatTimeType);
}
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.BkContactListMapper">
<select id="getUserList" resultType="com.czg.account.entity.BkContactList">
SELECT
`order`.call_phone AS phone,
count( 1 ) AS orderNum,
sum( CASE `order`.`status` WHEN '已取消' THEN 1 ELSE 0 END ) AS cannelNum,
MAX(`order`.create_time) AS lastBookingTime
FROM
`bk_order` `order`
INNER JOIN bk_contact_list contact ON `order`.call_phone = contact.phone AND contact.shop_id = #{shopId}
WHERE
`order`.shop_id = #{shopId}
GROUP BY `order`.call_phone
</select>
</mapper>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.BkOrderMapper">
<select id="bookings" resultType="com.czg.account.entity.BkOrder">
SELECT
o.*, IFNULL(GROUP_CONCAT(DISTINCT t.name SEPARATOR '、'), '') AS tableInFos
FROM bk_order o
LEFT JOIN bk_order_table t ON t.book_order_id = o.id
WHERE o.shop_id = #{shopId}
<if test="search != null and search != ''">
AND (o.call_username LIKE CONCAT('%', #{search}, '%')
OR o.call_phone LIKE CONCAT('%', #{search}, '%')
OR o.booking_username LIKE CONCAT('%', #{search}, '%')
OR o.booking_phone LIKE CONCAT('%', #{search}, '%'))
</if>
<if test="start != null and end != null">
AND o.booking_time >= CONCAT(#{start}, ' 00:00:00')
AND o.booking_time &lt;= CONCAT(#{end}, ' 23:59:59')
</if>
<if test="status != null and status != ''">
<if test="status == '已超时'">
AND o.status = '待到店'
AND o.booking_time &lt; DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')
</if>
<if test="status != '已超时'">
AND o.status = #{status}
</if>
</if>
group by o.id
</select>
</mapper>

View File

@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.BkOrderTableMapper">
<insert id="customInsertBatch">
insert into bk_order_table (shop_id, book_order_id, table_area_id ,table_area_name,table_id,table_name)
values
<foreach collection="bkOrderTables" item="item" separator=",">
(#{shopId}, #{bookOrderId}, #{item.tableAreaId}, #{item.tableAreaName}, #{item.tableId}, #{item.tableName})
</foreach>
</insert>
<select id="table" resultMap="BkTableVOResultMap">
SELECT
`table`.area_id,
`area`.`name` as area_name,
`table`.id as table_id,
`table`.`name` as table_name,
`order`.call_phone,
`order`.call_username,
`order`.booking_phone,
`order`.booking_username,
`order`.booking_time
FROM
`tb_shop_table` `table`
LEFT JOIN tb_shop_table_area `area` on `table`.area_id = `area`.id
LEFT JOIN bk_order `order` ON `table`.shop_id = `order`.shop_id
AND DATE(`order`.booking_time) = #{day}
<if test="seatTimeType != null and seatTimeType != ''">
AND `order`.seat_time_type = #{seatTimeType}
</if>
LEFT JOIN bk_order_table oTable on oTable.book_order_id = `order`.id
and `table`.id = oTable.table_id
WHERE
`table`.shop_id = #{shopId}
AND `table`.`status` != 'unbound'
<if test="areaId != null">
AND `table`.area_id = #{areaId}
</if>
ORDER BY `table`.area_id, `table`.id
</select>
<resultMap id="BkTableVOResultMap" type="com.czg.account.vo.BkTableVO">
<result property="areaId" column="area_id"/>
<result property="areaName" column="area_name"/>
<collection property="tables" ofType="com.czg.account.vo.BkTableVO$tableVO">
<result property="tableName" column="table_name"/>
<collection property="bkOrders" ofType="com.czg.account.vo.BkTableVO$BkOrder">
<result property="callPhone" column="call_phone"/>
<result property="callUsername" column="call_username"/>
<result property="bookingPhone" column="booking_phone"/>
<result property="bookingUsername" column="booking_username"/>
</collection>
</collection>
</resultMap>
</mapper>