From 8c2f79b721a05fbf73c50a78b267ea3868c632d2 Mon Sep 17 00:00:00 2001
From: eight <641137800@qq.com>
Date: 星期四, 15 八月 2024 14:00:40 +0800
Subject: [PATCH] update

---
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedQueueBO.java                                |   18 ++++
 jh-server/src/main/resources/application-local.yaml                                                                              |    2 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/AppointmentController.java      |   62 ++++----------
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/vo/AppointmentConfirmReqVO.java |    2 
 jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/QueueStatusEnum.java                                   |   52 +++++++++++++
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java                          |   51 ++++++++++++
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/room/RoomMapper.java                               |    4 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/queueMapper.java                             |    4 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/dataobject/room/RoomStatisticsDO.java                    |    1 
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java                              |    5 +
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/room/RoomService.java                                |    1 
 11 files changed, 154 insertions(+), 48 deletions(-)

diff --git a/jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/QueueStatusEnum.java b/jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/QueueStatusEnum.java
new file mode 100644
index 0000000..50b5800
--- /dev/null
+++ b/jh-module-ecg/jh-module-ecg-api/src/main/java/cn/lihu/jh/module/ecg/enums/QueueStatusEnum.java
@@ -0,0 +1,52 @@
+package cn.lihu.jh.module.ecg.enums;
+
+import cn.hutool.core.util.ObjUtil;
+import cn.lihu.jh.framework.common.core.IntArrayValuable;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Arrays;
+
+/**
+ * 閫氱敤鐘舵�佹灇涓�
+ *
+ * @author 鑺嬮亾婧愮爜
+ */
+@Getter
+@AllArgsConstructor
+public enum QueueStatusEnum implements IntArrayValuable {
+
+    //10:鎺掗槦涓� 20:鍊欒瘖鍑嗗 30:灏辫瘖涓� 40:灏辫瘖瀹屾垚 50:杩囧彿 60:杩囨湡
+    WAITING((byte)10, "鎺掗槦涓�"),
+    READY((byte)20, "鍊欒瘖鍑嗗"),
+    ONSTAGE((byte)30, "灏辫瘖涓�"),
+    FINISH((byte)40, "灏辫瘖瀹屾垚"),
+    PASSED((byte)50, "杩囧彿");
+
+    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(QueueStatusEnum::getStatus).toArray();
+
+    /**
+     * 鐘舵�佸��
+     */
+    private final Byte status;
+    /**
+     * 鐘舵�佸悕
+     */
+    private final String name;
+
+    @Override
+    public int[] array() {
+        return ARRAYS;
+    }
+
+/*
+    public static boolean isEnable(Integer status) {
+        return ObjUtil.equal(ENABLE.status, status);
+    }
+
+    public static boolean isDisable(Integer status) {
+        return ObjUtil.equal(DISABLE.status, status);
+    }
+*/
+
+}
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/AppointmentController.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/AppointmentController.java
index 6b0f76d..574bae5 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/AppointmentController.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/AppointmentController.java
@@ -128,14 +128,8 @@
                         BeanUtils.toBean(list, AppointmentRespVO.class));
     }
 
-    @PostMapping("/confirm")
-    @Operation(summary = "棰勭害纭")
-    @PreAuthorize("@ss.hasPermission('ecg:appointment:confirm')")
-    public CommonResult<String> appointmentConfirm(@RequestBody AppointmentConfirmReqVO confirmReqVO) {
-        //TODO 澶勭悊鎺掗槦閫昏緫
-        //AppointmentDO appointment = appointmentService.getAppointment(id);
-        //return success(BeanUtils.toBean(appointment, AppointmentRespVO.class));
-
+    // TODO 瀵规帴鏁版嵁骞冲彴
+    private void getRemoteAppointment(AppointmentConfirmReqVO confirmReqVO) {
         RestApiReqBodyVo reqBodyVo = new RestApiReqBodyVo();
         reqBodyVo.setSfzh(confirmReqVO.getPatId());
         reqBodyVo.setMzzyh("A34343");
@@ -172,7 +166,7 @@
         LocalDateTime bookEndTime = bookStartTime.plusMinutes(30);
         queueSaveReqVO.setBookTimeslot(
                 (bookStartTime.getHour()*100 + bookStartTime.getMinute())*10000
-                + bookEndTime.getHour()*100 + bookEndTime.getMinute() );
+                        + bookEndTime.getHour()*100 + bookEndTime.getMinute() );
 
         //queueSaveReqVO.setBookCheckType( Byte.valueOf(appointmentExternal.getPlanDefItemList().getPlanDefItem().getPlanDefItemcode()) );
         queueSaveReqVO.setBookCheckType( (byte)10 );
@@ -186,42 +180,24 @@
         queueSaveReqVO.setBedNum("-");
 
         queueService.createqueue(queueSaveReqVO);
+    }
 
+    @PostMapping("/confirm")
+    @Operation(summary = "棰勭害纭")
+    @PreAuthorize("@ss.hasPermission('ecg:appointment:confirm')")
+    public CommonResult<String> appointmentConfirm(@RequestBody AppointmentConfirmReqVO confirmReqVO) {
+        //TODO 鍏堜粠棰勭害琛ㄥ彇鏁版嵁锛屽悗缁鎺ユ暟鎹钩鍙版煡棰勭害鏁版嵁
+        AppointmentDO appointment = appointmentService.getAppointment(confirmReqVO.getId());
 
-        // 鑾峰彇鍊欒瘖鍑嗗鐨勯厤缃汉鏁�  锛� 钀ヤ笟鐨勮瘖瀹�
-
-/*
-        List<DeptDO> list = deptService.getDeptList(
-                new DeptListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()));
-        return success(BeanUtils.toBean(list, DeptSimpleRespVO.class));
-*/
-
-        List<DeptRespDTO> deptRespDTOList = deptApi.getSimpleDeptList();
-        Optional<DeptRespDTO> ecgDept = deptRespDTOList.stream()
-                .filter(a -> a.getName().equals("ECG"))
-                .findAny();
-
-        if (ecgDept.isPresent()){
-            System.out.println(ecgDept.get().getName());
-
-            List<DeptRespDTO> list2 = deptRespDTOList.stream()
-                    .filter(a -> Objects.equals(a.getParentId(), ecgDept.get().getId()))
-                    .toList();
-            list2.forEach(System.out::println);
-            list2.size();
-        }
-
-        // 鑾峰彇闂ㄨ瘖瀹� 璇婄枟搴婄殑缁熻
-        List<RoomStatisticsDO> roomStatisticsList = roomService.roomStatistics();
-        roomStatisticsList.size();
-
-        // 鑾峰彇 姣忎釜钀ヤ笟鐨勮瘖瀹� 鍊欒瘖鍑嗗鐨勫綋鍓嶄汉鏁�  灏辫瘖涓殑褰撳墠浜烘暟
-        // queueService.get
-        List statusList = new ArrayList<Byte>();
-        statusList.add((byte)20);
-        statusList.add((byte)30);
-        List<QueueStatisticDO> queueStatisticDOList = queueService.queueStatistics(statusList);
-        queueStatisticDOList.size();
+        QueueSaveReqVO queueSaveReqVO = new QueueSaveReqVO();
+        queueSaveReqVO.setPatId( appointment.getPatId());
+        queueSaveReqVO.setPatName( appointment.getPatName() );
+        queueSaveReqVO.setPatGender( appointment.getPatGender());
+        queueSaveReqVO.setBookTimeslot( appointment.getBookTimeslot() );
+        queueSaveReqVO.setBookCheckType( appointment.getBookCheckType() );
+        queueSaveReqVO.setPassed((byte)0);
+        queueSaveReqVO.setExpired((byte)0);
+        queueService.queue(queueSaveReqVO);
 
         return success("hello");
     }
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/vo/AppointmentConfirmReqVO.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/vo/AppointmentConfirmReqVO.java
index b68c083..551d6d4 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/vo/AppointmentConfirmReqVO.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/controller/admin/appointment/vo/AppointmentConfirmReqVO.java
@@ -11,6 +11,8 @@
 @Data
 public class AppointmentConfirmReqVO {
 
+    private Integer id;
+
     @Schema(description = "鎮h�呯紪鍙�", requiredMode = Schema.RequiredMode.REQUIRED, example = "29034")
     //@NotEmpty(message = "鎮h�呯紪鍙蜂笉鑳戒负绌�")
     private String patId;
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/dataobject/room/RoomStatisticsDO.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/dataobject/room/RoomStatisticsDO.java
index c60558f..cb7e2dc 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/dataobject/room/RoomStatisticsDO.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/dataobject/room/RoomStatisticsDO.java
@@ -5,5 +5,6 @@
 @Data
 public class RoomStatisticsDO {
     Long roomId;
+    String roomName;
     Integer bedNum;
 }
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/queueMapper.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/queueMapper.java
index 1cd7419..faacf8c 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/queueMapper.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queue/queueMapper.java
@@ -45,6 +45,8 @@
             " </foreach> )" +
             " group by status; "
             +"</script>")
-
     List<QueueStatisticDO> queueStatistic(@Param("statusList")List<Byte> statusList);
+
+    @Select("SELECT max(seq_num) FROM lihu.queue")
+    int getMaxSeqNum();
 }
\ No newline at end of file
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/room/RoomMapper.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/room/RoomMapper.java
index 6d6543a..7298f70 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/room/RoomMapper.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/room/RoomMapper.java
@@ -28,10 +28,10 @@
                 .orderByDesc(RoomDO::getId));
     }
 
-    @Select({ "SELECT room_id, count(1) as bed_num FROM lihu.clinic_room group by room_id;" })
+    @Select({ "SELECT room_id, room_name, count(1) as bed_num FROM lihu.clinic_room group by room_id;" })
     List<RoomStatisticsDO> roomStatistic();
 
-    @Select({ "SELECT room_id, room_name FROM lihu.clinic_room where onstage=true group by room_id;" })
+    @Select({ "SELECT id, room_id, room_name, bed_no, onstage FROM lihu.clinic_room where onstage=true;" })
     List<RoomDO> simpleRoomList();
 
 }
\ No newline at end of file
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedQueueBO.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedQueueBO.java
new file mode 100644
index 0000000..86ae942
--- /dev/null
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/BedQueueBO.java
@@ -0,0 +1,18 @@
+package cn.lihu.jh.module.ecg.service.queue;
+
+import lombok.Data;
+import org.jetbrains.annotations.NotNull;
+
+@Data
+public class BedQueueBO implements Comparable<BedQueueBO> {
+    String bedNo;
+    Long roomId;
+    String roomName;
+    Integer queueNum;
+    Integer maxQueueNum;
+
+    @Override
+    public int compareTo(@NotNull BedQueueBO o) {
+        return Integer.compare(o.queueNum, this.queueNum);
+    }
+}
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java
index 101ded9..4e90d54 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueService.java
@@ -56,4 +56,9 @@
 
     List<QueueStatisticDO> queueStatistics(List<Byte> statusList);
 
+    /**
+     * 鎮h�呮帓闃�
+     * @param queueSaveReqVO
+     */
+    void queue(QueueSaveReqVO queueSaveReqVO);
 }
\ No newline at end of file
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java
index 936379e..5b558c7 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queue/queueServiceImpl.java
@@ -1,6 +1,12 @@
 package cn.lihu.jh.module.ecg.service.queue;
 
 import cn.lihu.jh.module.ecg.dal.dataobject.queue.QueueStatisticDO;
+import cn.lihu.jh.module.ecg.dal.dataobject.room.RoomDO;
+import cn.lihu.jh.module.ecg.dal.dataobject.room.RoomStatisticsDO;
+import cn.lihu.jh.module.ecg.dal.mysql.room.RoomMapper;
+import cn.lihu.jh.module.ecg.enums.QueueStatusEnum;
+import lombok.Data;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
@@ -11,9 +17,12 @@
 
 import cn.lihu.jh.module.ecg.dal.mysql.queue.queueMapper;
 
+import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.PriorityQueue;
 
 import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*;
@@ -27,8 +36,17 @@
 @Validated
 public class QueueServiceImpl implements QueueService {
 
+    final static Integer MAX_QUEUE_NUM = 2;
+
+    Integer  curSeqNum = 0;
+
+    PriorityQueue<BedQueueBO> priorityQueue = new PriorityQueue<>();
+
     @Resource
     private queueMapper queueMapper;
+
+    @Resource
+    private RoomMapper roomMapper;
 
     @Override
     public Integer createqueue(QueueSaveReqVO createReqVO) {
@@ -77,4 +95,35 @@
         return queueMapper.queueStatistic(statusList);
     }
 
-}
\ No newline at end of file
+    @Override
+    public void queue(QueueSaveReqVO queueSaveReqVO) {
+        BedQueueBO bedQueueBO = priorityQueue.peek();
+        if (bedQueueBO.queueNum == bedQueueBO.maxQueueNum) {
+            queueSaveReqVO.setStatus(QueueStatusEnum.WAITING.getStatus()); //鎺掗槦涓�
+        } else if (bedQueueBO.queueNum < bedQueueBO.maxQueueNum) {
+            queueSaveReqVO.setStatus(QueueStatusEnum.READY.getStatus()); //鍊欒瘖鍑嗗涓�
+            queueSaveReqVO.setRoomNum(bedQueueBO.getRoomName());
+            queueSaveReqVO.setBedNum(bedQueueBO.getBedNo());
+            queueSaveReqVO.setSeqNum(curSeqNum++);
+            QueueDO queue = BeanUtils.toBean(queueSaveReqVO, QueueDO.class);
+            queueMapper.insert(queue);  // queue.getId();
+
+            bedQueueBO.queueNum++;
+        }
+    }
+
+    @PostConstruct
+    private void initQueue() {
+        List<RoomDO> roomDOList = roomMapper.simpleRoomList();
+        List<BedQueueBO> bedQueueBOList = roomDOList.stream().map(item -> BeanUtils.toBean(item, BedQueueBO.class)).toList();
+
+        bedQueueBOList.forEach(item -> {
+            item.maxQueueNum = MAX_QUEUE_NUM;
+            item.queueNum = 0;
+            priorityQueue.add(item);
+        });
+
+        curSeqNum = queueMapper.getMaxSeqNum();
+    }
+}
+
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/room/RoomService.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/room/RoomService.java
index 24e2a19..bba206e 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/room/RoomService.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/room/RoomService.java
@@ -58,4 +58,5 @@
     List<RoomStatisticsDO> roomStatistics();
 
     List<RoomDO> simpleRoomList();
+
 }
\ No newline at end of file
diff --git a/jh-server/src/main/resources/application-local.yaml b/jh-server/src/main/resources/application-local.yaml
index ac5815c..acac1e8 100644
--- a/jh-server/src/main/resources/application-local.yaml
+++ b/jh-server/src/main/resources/application-local.yaml
@@ -76,7 +76,7 @@
   redis:
     host: 116.62.18.175   #r-bp1zyjl0g07e1ry08rpd.redis.rds.aliyuncs.com # 鍦板潃
     port: 6020            #绔彛 6379
-    database: 2 # 鏁版嵁搴撶储寮�
+    database: 15 # 鏁版嵁搴撶储寮�
     password: Smartor    #Root@yinyu # 瀵嗙爜锛屽缓璁敓浜х幆澧冨紑鍚�
 
 --- #################### 瀹氭椂浠诲姟鐩稿叧閰嶇疆 ####################

--
Gitblit v1.9.3