77 门诊挂号-》预约签到
This commit is contained in:
@@ -9,6 +9,8 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 号源池明细Entity
|
||||
*
|
||||
@@ -29,7 +31,7 @@ public class ScheduleSlot extends HisBaseEntity {
|
||||
/** 序号 */
|
||||
private Integer seqNo;
|
||||
|
||||
/** 序号状态: 0-可用,1-已预约,2-已取消,3-已过期等 */
|
||||
/** 序号状态: 0-可用,1-已预约,2-已取消/已停诊,3-已锁定,4-已签到,5-已退号 */
|
||||
private Integer status;
|
||||
|
||||
/** 预约订单ID */
|
||||
@@ -37,4 +39,7 @@ public class ScheduleSlot extends HisBaseEntity {
|
||||
|
||||
/** 预计叫号时间 */
|
||||
private LocalTime expectTime;
|
||||
|
||||
/** 签到时间 */
|
||||
private Date checkInTime;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,13 @@ public class TicketSlotDTO {
|
||||
private Long patientId;
|
||||
private String phone;
|
||||
private Integer orderStatus;
|
||||
private Long orderId;
|
||||
private String orderNo;
|
||||
private String patientGender;
|
||||
private Integer genderEnum;
|
||||
private String idCard;
|
||||
private String encounterId;
|
||||
private String appointmentTime;
|
||||
|
||||
// 底层逻辑判断专属字段
|
||||
private Integer slotStatus;
|
||||
|
||||
@@ -37,4 +37,21 @@ public interface SchedulePoolMapper extends BaseMapper<SchedulePool> {
|
||||
AND p.delete_flag = '0'
|
||||
""")
|
||||
int refreshPoolStats(@Param("poolId") Long poolId);
|
||||
|
||||
/**
|
||||
* 签到时更新号源池统计:锁定数-1,已预约数+1
|
||||
*
|
||||
* @param poolId 号源池ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Update("""
|
||||
UPDATE adm_schedule_pool
|
||||
SET locked_num = locked_num - 1,
|
||||
booked_num = booked_num + 1,
|
||||
update_time = NOW()
|
||||
WHERE id = #{poolId}
|
||||
AND locked_num > 0
|
||||
AND delete_flag = '0'
|
||||
""")
|
||||
int updatePoolStatsOnCheckIn(@Param("poolId") Integer poolId);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.openhis.appointmentmanage.domain.ScheduleSlot;
|
||||
import com.openhis.appointmentmanage.domain.TicketSlotDTO;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.openhis.appointmentmanage.dto.TicketQueryDTO;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -30,6 +31,16 @@ public interface ScheduleSlotMapper extends BaseMapper<ScheduleSlot> {
|
||||
*/
|
||||
int updateSlotStatus(@Param("slotId") Long slotId, @Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* 更新槽位状态并记录签到时间
|
||||
*
|
||||
* @param slotId 槽位ID
|
||||
* @param status 状态
|
||||
* @param checkInTime 签到时间
|
||||
* @return 结果
|
||||
*/
|
||||
int updateSlotStatusAndCheckInTime(@Param("slotId") Long slotId, @Param("status") Integer status, @Param("checkInTime") Date checkInTime);
|
||||
|
||||
/**
|
||||
* 根据槽位ID查询所属号源池ID。
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,7 @@ import lombok.experimental.Accessors;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class Order extends HisBaseEntity {
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@TableId(type = IdType.AUTO)
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
|
||||
@@ -32,4 +32,14 @@ public interface OrderMapper extends BaseMapper<Order> {
|
||||
int updateOrderStatusById(Long id, Integer status);
|
||||
|
||||
int updateOrderCancelInfoById(Long id, Date cancelTime, String cancelReason);
|
||||
|
||||
/**
|
||||
* 更新订单支付状态
|
||||
*
|
||||
* @param orderId 订单ID
|
||||
* @param payStatus 支付状态:0-未支付,1-已支付
|
||||
* @param payTime 支付时间
|
||||
* @return 结果
|
||||
*/
|
||||
int updatePayStatus(@Param("orderId") Long orderId, @Param("payStatus") Integer payStatus, @Param("payTime") Date payTime);
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
}
|
||||
|
||||
Order order = new Order();
|
||||
order.setId(null); // 显式置空,确保触发数据库自增,避免 MP 预分配雪花 ID 的干扰
|
||||
String orderNo = assignSeqUtil.getSeq(AssignSeqEnum.ORDER_NUM.getPrefix(), 18);
|
||||
order.setOrderNo(orderNo);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.openhis.appointmentmanage.domain.AppointmentConfig;
|
||||
import com.openhis.appointmentmanage.service.IAppointmentConfigService;
|
||||
import com.openhis.appointmentmanage.domain.TicketSlotDTO;
|
||||
import com.openhis.appointmentmanage.domain.ScheduleSlot;
|
||||
import com.openhis.appointmentmanage.mapper.SchedulePoolMapper;
|
||||
import com.openhis.appointmentmanage.mapper.ScheduleSlotMapper;
|
||||
import com.openhis.clinical.domain.Order;
|
||||
@@ -52,6 +53,9 @@ public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> impleme
|
||||
@Resource
|
||||
private SchedulePoolMapper schedulePoolMapper;
|
||||
|
||||
@Resource
|
||||
private com.openhis.clinical.mapper.OrderMapper orderMapper;
|
||||
|
||||
@Resource
|
||||
private IAppointmentConfigService appointmentConfigService;
|
||||
|
||||
@@ -277,7 +281,7 @@ public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> impleme
|
||||
}
|
||||
|
||||
/**
|
||||
* 取号
|
||||
* 取号(签到)
|
||||
*
|
||||
* @param slotId 槽位ID
|
||||
* @return 结果
|
||||
@@ -290,7 +294,24 @@ public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> impleme
|
||||
throw new RuntimeException("当前号源没有可取号的预约订单");
|
||||
}
|
||||
Order latestOrder = orders.get(0);
|
||||
return orderService.updateOrderStatusById(latestOrder.getId(), AppointmentOrderStatus.CHECKED_IN);
|
||||
|
||||
// 1. 更新订单状态为已取号,并更新支付状态和支付时间
|
||||
orderService.updateOrderStatusById(latestOrder.getId(), AppointmentOrderStatus.CHECKED_IN);
|
||||
// 更新支付状态为已支付,记录支付时间
|
||||
orderMapper.updatePayStatus(latestOrder.getId(), 1, new Date());
|
||||
|
||||
// 2. 查询号源槽位信息
|
||||
ScheduleSlot slot = scheduleSlotMapper.selectById(slotId);
|
||||
|
||||
// 3. 更新号源槽位状态为已签到,记录签到时间
|
||||
scheduleSlotMapper.updateSlotStatusAndCheckInTime(slotId, SlotStatus.CHECKED_IN, new Date());
|
||||
|
||||
// 4. 更新号源池统计:锁定数-1,已预约数+1
|
||||
if (slot != null && slot.getPoolId() != null) {
|
||||
schedulePoolMapper.updatePoolStatsOnCheckIn(slot.getPoolId());
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,7 +333,7 @@ public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> impleme
|
||||
orderService.cancelAppointmentOrder(order.getId(), "医生停诊");
|
||||
}
|
||||
|
||||
int updated = scheduleSlotMapper.updateSlotStatus(slotId, SlotStatus.STOPPED);
|
||||
int updated = scheduleSlotMapper.updateSlotStatus(slotId, SlotStatus.CANCELLED);
|
||||
if (updated > 0) {
|
||||
refreshPoolStatsBySlotId(slotId);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,41 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.openhis.appointmentmanage.mapper.ScheduleSlotMapper">
|
||||
|
||||
<!-- 统一状态值(兼容数字/英文字符串存储),输出 Integer,避免 resultType 映射 NumberFormatException -->
|
||||
<sql id="slotStatusNormExpr">
|
||||
CASE
|
||||
WHEN LOWER(CONCAT('', s.status)) IN ('0', 'unbooked', 'available') THEN 0
|
||||
WHEN LOWER(CONCAT('', s.status)) IN ('1', 'booked') THEN 1
|
||||
WHEN LOWER(CONCAT('', s.status)) IN ('2', 'cancelled', 'canceled', 'stopped') THEN 2
|
||||
WHEN LOWER(CONCAT('', s.status)) IN ('3', 'locked') THEN 3
|
||||
WHEN LOWER(CONCAT('', s.status)) IN ('4', 'checked', 'checked_in', 'checkin') THEN 4
|
||||
WHEN LOWER(CONCAT('', s.status)) IN ('5', 'returned') THEN 5
|
||||
ELSE NULL
|
||||
END
|
||||
</sql>
|
||||
|
||||
<sql id="orderStatusNormExpr">
|
||||
CASE
|
||||
WHEN LOWER(CONCAT('', o.status)) IN ('1', 'booked') THEN 1
|
||||
WHEN LOWER(CONCAT('', o.status)) IN ('2', 'checked', 'checked_in', 'checkin') THEN 2
|
||||
WHEN LOWER(CONCAT('', o.status)) IN ('3', 'cancelled', 'canceled') THEN 3
|
||||
WHEN LOWER(CONCAT('', o.status)) IN ('4', 'returned') THEN 4
|
||||
ELSE NULL
|
||||
END
|
||||
</sql>
|
||||
|
||||
<sql id="poolStatusNormExpr">
|
||||
CASE
|
||||
WHEN LOWER(CONCAT('', p.status)) IN ('0', 'unbooked', 'available') THEN 0
|
||||
WHEN LOWER(CONCAT('', p.status)) IN ('1', 'booked') THEN 1
|
||||
WHEN LOWER(CONCAT('', p.status)) IN ('2', 'cancelled', 'canceled', 'stopped') THEN 2
|
||||
WHEN LOWER(CONCAT('', p.status)) IN ('3', 'locked') THEN 3
|
||||
WHEN LOWER(CONCAT('', p.status)) IN ('4', 'checked', 'checked_in', 'checkin') THEN 4
|
||||
WHEN LOWER(CONCAT('', p.status)) IN ('5', 'returned') THEN 5
|
||||
ELSE NULL
|
||||
END
|
||||
</sql>
|
||||
|
||||
<!-- 注意这里的 resultType 指向了您刚建好的 DTO 实体类 -->
|
||||
<select id="selectAllTicketSlots" resultType="com.openhis.appointmentmanage.domain.TicketSlotDTO">
|
||||
SELECT
|
||||
@@ -16,12 +51,12 @@
|
||||
o.patient_name AS patientName,
|
||||
o.medical_card AS medicalCard,
|
||||
o.phone AS phone,
|
||||
o.status AS orderStatus,
|
||||
s.status AS slotStatus,
|
||||
<include refid="orderStatusNormExpr" /> AS orderStatus,
|
||||
<include refid="slotStatusNormExpr" /> AS slotStatus,
|
||||
s.expect_time AS expectTime,
|
||||
p.schedule_date AS scheduleDate,
|
||||
d.reg_type AS regType,
|
||||
p.status AS poolStatus,
|
||||
<include refid="poolStatusNormExpr" /> AS poolStatus,
|
||||
p.stop_reason AS stopReason,
|
||||
d.is_stopped AS isStopped
|
||||
FROM
|
||||
@@ -39,7 +74,7 @@
|
||||
FROM
|
||||
order_main
|
||||
WHERE
|
||||
status IN (1, 2)
|
||||
LOWER(CONCAT('', status)) IN ('1', '2', '4', 'booked', 'checked', 'checked_in', 'checkin', 'returned')
|
||||
ORDER BY
|
||||
slot_id,
|
||||
create_time DESC
|
||||
@@ -66,12 +101,18 @@
|
||||
o.patient_name AS patientName,
|
||||
o.medical_card AS medicalCard,
|
||||
o.phone AS phone,
|
||||
o.status AS orderStatus,
|
||||
s.status AS slotStatus,
|
||||
o.id AS orderId,
|
||||
o.order_no AS orderNo,
|
||||
COALESCE(CAST(o.gender AS VARCHAR), CAST(pinfo.gender_enum AS VARCHAR)) AS patientGender,
|
||||
pinfo.gender_enum AS genderEnum,
|
||||
pinfo.id_card AS idCard,
|
||||
o.appointment_time AS appointmentTime,
|
||||
<include refid="orderStatusNormExpr" /> AS orderStatus,
|
||||
<include refid="slotStatusNormExpr" /> AS slotStatus,
|
||||
s.expect_time AS expectTime,
|
||||
p.schedule_date AS scheduleDate,
|
||||
d.reg_type AS regType,
|
||||
p.status AS poolStatus,
|
||||
<include refid="poolStatusNormExpr" /> AS poolStatus,
|
||||
p.stop_reason AS stopReason,
|
||||
d.is_stopped AS isStopped
|
||||
FROM
|
||||
@@ -87,15 +128,20 @@
|
||||
patient_name,
|
||||
medical_card,
|
||||
phone,
|
||||
id,
|
||||
order_no,
|
||||
gender,
|
||||
appointment_time,
|
||||
status
|
||||
FROM
|
||||
order_main
|
||||
WHERE
|
||||
status IN (1, 2)
|
||||
LOWER(CONCAT('', status)) IN ('1', '2', '4', 'booked', 'checked', 'checked_in', 'checkin', 'returned')
|
||||
ORDER BY
|
||||
slot_id,
|
||||
create_time DESC
|
||||
) o ON o.slot_id = s.id
|
||||
LEFT JOIN adm_patient pinfo ON o.patient_id = pinfo.id
|
||||
WHERE
|
||||
s.id = #{id}
|
||||
</select>
|
||||
@@ -115,7 +161,7 @@
|
||||
UPDATE adm_schedule_slot
|
||||
SET
|
||||
status = #{status},
|
||||
<if test="status == 0">
|
||||
<if test="status != null and '0'.equals(status.toString())">
|
||||
order_id = NULL,
|
||||
</if>
|
||||
update_time = now()
|
||||
@@ -124,11 +170,25 @@
|
||||
AND delete_flag = '0'
|
||||
</update>
|
||||
|
||||
<update id="updateSlotStatusAndCheckInTime">
|
||||
UPDATE adm_schedule_slot
|
||||
SET
|
||||
status = #{status},
|
||||
check_in_time = #{checkInTime},
|
||||
update_time = NOW()
|
||||
WHERE
|
||||
id = #{slotId}
|
||||
AND delete_flag = '0'
|
||||
</update>
|
||||
|
||||
<select id="selectPoolIdBySlotId" resultType="java.lang.Long">
|
||||
SELECT pool_id
|
||||
FROM adm_schedule_slot
|
||||
WHERE id = #{slotId}
|
||||
AND delete_flag = '0'
|
||||
SELECT
|
||||
pool_id
|
||||
FROM
|
||||
adm_schedule_slot
|
||||
WHERE
|
||||
id = #{slotId}
|
||||
AND delete_flag = '0'
|
||||
</select>
|
||||
|
||||
<update id="bindOrderToSlot">
|
||||
@@ -155,12 +215,18 @@
|
||||
o.patient_name AS patientName,
|
||||
o.medical_card AS medicalCard,
|
||||
o.phone AS phone,
|
||||
o.status AS orderStatus,
|
||||
s.status AS slotStatus,
|
||||
o.id AS orderId,
|
||||
o.order_no AS orderNo,
|
||||
COALESCE(CAST(o.gender AS VARCHAR), CAST(pinfo.gender_enum AS VARCHAR)) AS patientGender,
|
||||
pinfo.gender_enum AS genderEnum,
|
||||
pinfo.id_card AS idCard,
|
||||
o.appointment_time AS appointmentTime,
|
||||
<include refid="orderStatusNormExpr" /> AS orderStatus,
|
||||
<include refid="slotStatusNormExpr" /> AS slotStatus,
|
||||
s.expect_time AS expectTime,
|
||||
p.schedule_date AS scheduleDate,
|
||||
d.reg_type AS regType,
|
||||
p.status AS poolStatus,
|
||||
<include refid="poolStatusNormExpr" /> AS poolStatus,
|
||||
p.stop_reason AS stopReason,
|
||||
d.is_stopped AS isStopped
|
||||
FROM
|
||||
@@ -176,15 +242,20 @@
|
||||
patient_name,
|
||||
medical_card,
|
||||
phone,
|
||||
id,
|
||||
order_no,
|
||||
gender,
|
||||
appointment_time,
|
||||
status
|
||||
FROM
|
||||
order_main
|
||||
WHERE
|
||||
status IN (1, 2)
|
||||
LOWER(CONCAT('', status)) IN ('1', '2', '4', 'booked', 'checked', 'checked_in', 'checkin', 'returned')
|
||||
ORDER BY
|
||||
slot_id,
|
||||
create_time DESC
|
||||
) o ON o.slot_id = s.id
|
||||
LEFT JOIN adm_patient pinfo ON o.patient_id = pinfo.id
|
||||
<where>
|
||||
p.delete_flag = '0'
|
||||
AND s.delete_flag = '0' <!-- 1. 按日期查 -->
|
||||
@@ -225,35 +296,49 @@
|
||||
<!-- 5. 核心:解答您疑问的 4 种业务状态的复合查询! -->
|
||||
<if test="query.status != null and query.status != '' and query.status != 'all'">
|
||||
<choose>
|
||||
<when test="query.status == 'unbooked'">
|
||||
AND s.status = 0
|
||||
<when test="'unbooked'.equals(query.status) or '未预约'.equals(query.status)">
|
||||
AND <include refid="slotStatusNormExpr" /> = 0
|
||||
AND (
|
||||
d.is_stopped IS NULL
|
||||
OR d.is_stopped = FALSE
|
||||
)
|
||||
</when>
|
||||
<when test="query.status == 'booked'">
|
||||
AND s.status = 1
|
||||
AND o.status = 1
|
||||
<when test="'booked'.equals(query.status) or '已预约'.equals(query.status)">
|
||||
AND <include refid="slotStatusNormExpr" /> = 1
|
||||
AND <include refid="orderStatusNormExpr" /> = 1
|
||||
AND (
|
||||
d.is_stopped IS NULL
|
||||
OR d.is_stopped = FALSE
|
||||
)
|
||||
</when>
|
||||
<when test="query.status == 'checked'">
|
||||
AND s.status = 1
|
||||
AND o.status = 2
|
||||
<when test="'checked'.equals(query.status) or '已取号'.equals(query.status)">
|
||||
AND (
|
||||
<include refid="slotStatusNormExpr" /> = 4
|
||||
OR (
|
||||
<include refid="slotStatusNormExpr" /> = 1
|
||||
AND <include refid="orderStatusNormExpr" /> = 2
|
||||
)
|
||||
)
|
||||
AND (
|
||||
d.is_stopped IS NULL
|
||||
OR d.is_stopped = FALSE
|
||||
)
|
||||
</when>
|
||||
<when test="query.status == 'cancelled'">
|
||||
<when test="'cancelled'.equals(query.status) or '已停诊'.equals(query.status) or '已取消'.equals(query.status)">
|
||||
AND (
|
||||
s.status = 2
|
||||
<include refid="slotStatusNormExpr" /> = 2
|
||||
OR d.is_stopped = TRUE
|
||||
)
|
||||
</when>
|
||||
<when test="'returned'.equals(query.status) or '已退号'.equals(query.status)">
|
||||
AND (
|
||||
<include refid="slotStatusNormExpr" /> = 5
|
||||
OR <include refid="orderStatusNormExpr" /> = 4
|
||||
)
|
||||
</when>
|
||||
<otherwise>
|
||||
AND 1 = 2
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
</where>
|
||||
@@ -266,9 +351,22 @@
|
||||
SELECT
|
||||
p.doctor_id AS doctorId,
|
||||
p.doctor_name AS doctorName,
|
||||
COALESCE(SUM(GREATEST(COALESCE(p.total_quota, 0) - COALESCE(p.booked_num, 0) - COALESCE(p.locked_num, 0), 0)), 0) AS available,
|
||||
COALESCE(
|
||||
SUM(
|
||||
GREATEST(
|
||||
COALESCE(p.total_quota, 0) - COALESCE(p.booked_num, 0) - COALESCE(p.locked_num, 0),
|
||||
0
|
||||
)
|
||||
),
|
||||
0
|
||||
) AS available,
|
||||
CASE
|
||||
WHEN MAX(CASE WHEN d.reg_type = 1 THEN 1 ELSE 0 END) = 1 THEN 'expert'
|
||||
WHEN MAX(
|
||||
CASE
|
||||
WHEN d.reg_type = 1 THEN 1
|
||||
ELSE 0
|
||||
END
|
||||
) = 1 THEN 'expert'
|
||||
ELSE 'general'
|
||||
END AS ticketType
|
||||
FROM
|
||||
@@ -290,7 +388,10 @@
|
||||
AND d.reg_type = 1
|
||||
</when>
|
||||
<when test="query.type == 'general'">
|
||||
AND (d.reg_type != 1 OR d.reg_type IS NULL)
|
||||
AND (
|
||||
d.reg_type != 1
|
||||
OR d.reg_type IS NULL
|
||||
)
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
|
||||
@@ -127,7 +127,7 @@
|
||||
select * from order_main where slot_id = #{slotId} and status = 1
|
||||
</select>
|
||||
|
||||
<insert id="insertOrder" parameterType="com.openhis.clinical.domain.Order">
|
||||
<insert id="insertOrder" parameterType="com.openhis.clinical.domain.Order" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into order_main
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="orderNo != null and orderNo != ''">order_no,</if>
|
||||
@@ -225,6 +225,12 @@
|
||||
update order_main set status = 3, cancel_time = #{cancelTime}, cancel_reason = #{cancelReason} where id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="updatePayStatus">
|
||||
update order_main
|
||||
set pay_status = #{payStatus}, pay_time = #{payTime}, update_time = NOW()
|
||||
where id = #{orderId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteOrderById">
|
||||
delete from order_main where id = #{id}
|
||||
</delete>
|
||||
|
||||
Reference in New Issue
Block a user