jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/Utils.java
@@ -5,6 +5,7 @@ import java.time.LocalTime; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -65,5 +66,33 @@ public static String formatRoomBed(Long roomId, String bedNo) { return String.format("%09d%s", roomId, bedNo); } public static List<LocalTime> parseTimeSlotList(String strTimeSlotList, Integer timeslotLength) { List<LocalTime> localTimeList = new ArrayList<>(); // 7:30,8:30,9:30,10:30,11:30,12:30,13:30,14:30,15:30 String[] arrTimeSlotItemStr = strTimeSlotList.split(",|,"); Arrays.stream(arrTimeSlotItemStr).forEach( strTimeSlot -> { String regex = "(\\d+)[::](\\d+)"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(strTimeSlot); if (!matcher.find()) return; // 获取整个匹配的字符串 String fullMatch = matcher.group(); // 获取第一个捕获组(小时) String strHour = matcher.group(1); // 获取第二个捕获组(分钟) String strMinute = matcher.group(2); LocalTime localTimeSlot = LocalTime.of(Integer.valueOf(strHour), Integer.valueOf(strMinute)); localTimeList.add( localTimeSlot ); } ); return localTimeList; } } jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/dal/mysql/queuesequence/QueueSequenceMapper.java
@@ -8,6 +8,7 @@ import cn.lihu.jh.module.ecg.dal.dataobject.queuesequence.QueueSequenceDO; import org.apache.ibatis.annotations.Mapper; import cn.lihu.jh.module.ecg.controller.admin.queuesequence.vo.*; import org.apache.ibatis.annotations.Update; /** * 当天序号 Mapper @@ -29,4 +30,7 @@ .orderByDesc(QueueSequenceDO::getId)); } @Update("truncate table lihu.queue_sequence") void clearQueueSequenceTable(); } jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/config/EcgConfigServiceImpl.java
@@ -2,7 +2,9 @@ import cn.lihu.jh.module.ecg.Utils; import cn.lihu.jh.module.ecg.config.DynamicSchedulingConfig; import cn.lihu.jh.module.ecg.dal.mysql.queuesequence.QueueSequenceMapper; import cn.lihu.jh.module.ecg.service.queue.QueueService; import cn.lihu.jh.module.ecg.service.queuesequence.QueueSequenceService; import cn.lihu.jh.module.ecg.service.room.RoomService; import cn.lihu.jh.module.infra.api.config.ConfigApi; import lombok.extern.slf4j.Slf4j; @@ -35,6 +37,9 @@ @Resource private QueueService queueService; @Resource private QueueSequenceService queueSequenceService; ScheduledTask startBizTask = null; ScheduledTask closeBizTask = null; @@ -72,6 +77,7 @@ resetRoomTask = taskRegistrar.scheduleCronTask(new CronTask(() -> { System.out.println("Room Reset Task executed at: " + System.currentTimeMillis()); roomService.resetRoom(false); queueSequenceService.resetQueueSequence(); }, roomResetCronExpression)); taskRegistrar.afterPropertiesSet(); jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queuesequence/QueueSequenceService.java
@@ -53,4 +53,5 @@ */ PageResult<QueueSequenceDO> getQueueSequencePage(QueueSequencePageReqVO pageReqVO); void resetQueueSequence(); } jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queuesequence/QueueSequenceServiceImpl.java
@@ -1,9 +1,14 @@ package cn.lihu.jh.module.ecg.service.queuesequence; import cn.lihu.jh.module.ecg.Utils; import cn.lihu.jh.module.ecg.dal.dataobject.checktype.CheckTypeDO; import cn.lihu.jh.module.ecg.dal.mysql.checktype.CheckTypeMapper; import cn.lihu.jh.module.infra.api.config.ConfigApi; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; import java.time.LocalTime; import java.util.*; import cn.lihu.jh.module.ecg.controller.admin.queuesequence.vo.*; import cn.lihu.jh.module.ecg.dal.dataobject.queuesequence.QueueSequenceDO; @@ -16,6 +21,7 @@ import javax.annotation.Resource; import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.lihu.jh.module.ecg.Constants.*; import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*; /** @@ -28,7 +34,13 @@ public class QueueSequenceServiceImpl implements QueueSequenceService { @Resource private ConfigApi configApi; @Resource private QueueSequenceMapper queueSequenceMapper; @Resource private CheckTypeMapper checkTypeMapper; @Override public Integer createQueueSequence(QueueSequenceSaveReqVO createReqVO) { @@ -72,4 +84,31 @@ return queueSequenceMapper.selectPage(pageReqVO); } } @Override public void resetQueueSequence() { queueSequenceMapper.clearQueueSequenceTable(); // 读取时段配置 String strBookTimeslotLength = configApi.getConfigValueByKey(BOOK_TIMESLOT_LENGTH); String strBookTimeslotList = configApi.getConfigValueByKey(BOOK_TIMESLOT_LIST); // 读取所有的检查类型 List<CheckTypeDO> checkTypeDOList = checkTypeMapper.simpleCheckTypeList(); checkTypeDOList.forEach( checkTypeDO -> { List<LocalTime> timeslotList = Utils.parseTimeSlotList(strBookTimeslotList, Integer.valueOf(strBookTimeslotLength)); for (int i=0; i < timeslotList.size(); i++) { LocalTime timeslot = timeslotList.get(i); QueueSequenceDO queueSequenceDO = new QueueSequenceDO(); queueSequenceDO.setCheckType( checkTypeDO.getValue() ); queueSequenceDO.setTimeSlot( timeslot.getHour()*100 + timeslot.getMinute() ); queueSequenceDO.setQueueNo( i * checkTypeDO.getTimeslotBookNum() + checkTypeDO.getTimeslotReservedNum()); queueSequenceDO.setQueueVipNo( i * checkTypeDO.getTimeslotBookNum()); queueSequenceDO.setQueueFull( i * checkTypeDO.getTimeslotBookNum() + checkTypeDO.getTimeslotBookNum()); queueSequenceDO.setQueueVipFull( i * checkTypeDO.getTimeslotBookNum() + checkTypeDO.getTimeslotReservedNum()); queueSequenceMapper.insert( queueSequenceDO ); }; }); } }