From 2bc90e242eceb83d9aa80d48ea9f991c0f9b99c6 Mon Sep 17 00:00:00 2001 From: eight <641137800@qq.com> Date: 星期四, 12 十二月 2024 19:47:57 +0800 Subject: [PATCH] 工位选择界面 诊室按照room id排序 --- jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queuesequence/QueueSequenceServiceImpl.java | 127 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 126 insertions(+), 1 deletions(-) diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queuesequence/QueueSequenceServiceImpl.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queuesequence/QueueSequenceServiceImpl.java index 0c6fffb..d48bf41 100644 --- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queuesequence/QueueSequenceServiceImpl.java +++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queuesequence/QueueSequenceServiceImpl.java @@ -1,9 +1,16 @@ 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 cn.lihu.jh.module.system.api.dict.DictDataApi; +import cn.lihu.jh.module.system.api.dict.dto.DictDataRespDTO; 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 +23,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 +36,25 @@ public class QueueSequenceServiceImpl implements QueueSequenceService { @Resource + private ConfigApi configApi; + + @Resource + private DictDataApi dictDataApi; + + @Resource private QueueSequenceMapper queueSequenceMapper; + + @Resource + private CheckTypeMapper checkTypeMapper; + + @Override + public void initQueueSequenceTable() { + queueSequenceMapper.clearQueueSequenceTableNotCurrent(); + Integer rowCount = queueSequenceMapper.getQueueSequenceTableRowCount(); + if (null == rowCount || 0 == rowCount) { + resetQueueSequence(); + } + } @Override public Integer createQueueSequence(QueueSequenceSaveReqVO createReqVO) { @@ -68,8 +94,107 @@ } @Override + public List<QueueSequenceDO> selectGivenCheckTypeTimeslot(Integer checkType) { + return queueSequenceMapper.selectTimeslotByCheckType( checkType ); + } + + @Override public PageResult<QueueSequenceDO> getQueueSequencePage(QueueSequencePageReqVO pageReqVO) { return queueSequenceMapper.selectPage(pageReqVO); } -} \ No newline at end of file + @Override + public void resetQueueSequence() { + queueSequenceMapper.clearQueueSequenceTable(); + + // 璇诲彇鏃舵閰嶇疆 + String strBookTimeslotLength = configApi.getConfigValueByKey(BOOK_TIMESLOT_LENGTH); + + // 鏂规1锛氶厤缃腑鍙� 7:30,8:30,9:30,10:30,11:30,12:30,13:30,14:30,15:30 + //String strBookTimeslotList = configApi.getConfigValueByKey(BOOK_TIMESLOT_LIST); + //List<LocalTime> timeslotList = Utils.parseTimeSlotList(strBookTimeslotList, Integer.valueOf(strBookTimeslotLength)); + + List<DictDataRespDTO> dictBookTimeslotList = dictDataApi.getDictDataList(ECG_BOOK_TIMESLOT); + + // 璇诲彇鎵�鏈夌殑妫�鏌ョ被鍨� + List<CheckTypeDO> checkTypeDOList = checkTypeMapper.simpleCheckTypeList(); + checkTypeDOList.forEach( checkTypeDO -> { + + for (int i=0; i < dictBookTimeslotList.size(); i++) { + QueueSequenceDO queueSequenceDO = new QueueSequenceDO(); + queueSequenceDO.setCheckType( checkTypeDO.getValue() ); + queueSequenceDO.setTimeSlot( Integer.valueOf(dictBookTimeslotList.get(i).getValue()) ); + 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 ); + }; + }); + } + + @Override + @Transactional + public Integer distributeSeqNo(Integer checkType, Integer timeslot) { + Integer curSeqNo = queueSequenceMapper.selectQueueNoForUpdate(checkType, timeslot); + if (null == curSeqNo) { + // 浠庝笅涓�涓椂娈� 鑾峰彇搴忓彿銆傚師鍥犵郴缁熺敤30鍒嗛挓鐨勯棿闅斿垝鍒嗛绾︽椂闂存锛孒IS鐨勯绾︽椂闂存鍙兘鏄�30鍒嗛挓鎴�60鍒嗛挓 + Integer nextTimeslot = getNextTimeSlot(timeslot, checkType); + if (null == nextTimeslot) { + throw exception(QUEUE_SEQUENCE_TIMESLOT_FULL); + } + + curSeqNo = queueSequenceMapper.selectQueueNoForUpdate(checkType, nextTimeslot); + if (null == curSeqNo) { + throw exception(QUEUE_SEQUENCE_TIMESLOT_FULL); + } + + Integer updateRowNum = queueSequenceMapper.updateGivenCheckTypeTimeslotSeqNo(checkType, nextTimeslot, curSeqNo); + if (null == updateRowNum || updateRowNum == 0) { + throw exception(QUEUE_SEQUENCE_TIMESLOT_EXCEPTION); + } + + } else { + Integer updateRowNum = queueSequenceMapper.updateGivenCheckTypeTimeslotSeqNo(checkType, timeslot, curSeqNo); + if (null == updateRowNum || updateRowNum == 0) { + throw exception(QUEUE_SEQUENCE_TIMESLOT_EXCEPTION); + } + } + + return curSeqNo + 1; + } + + @Override + @Transactional + public Integer distributeVipSeqNo(Integer checkType, Integer timeslot) { + Integer curVipSeqNo = queueSequenceMapper.selectQueueVipNoForUpdate(checkType, timeslot); + if (null == curVipSeqNo) { + throw exception(QUEUE_SEQUENCE_TIMESLOT_FULL); + } + + Integer updateRowNum = queueSequenceMapper.updateGivenCheckTypeTimeslotVipSeqNo(checkType, timeslot, curVipSeqNo); + if (null == updateRowNum || updateRowNum == 0) { + throw exception(QUEUE_SEQUENCE_TIMESLOT_EXCEPTION); + } + + return curVipSeqNo + 1; + } + + private Integer getNextTimeSlot(Integer timeslot, Integer checkType) { + List<DictDataRespDTO> dictBookTimeslotList = dictDataApi.getDictDataList(ECG_BOOK_TIMESLOT); + Optional<Integer> index = dictBookTimeslotList.stream() + .filter(e -> e.getValue().equals(String.valueOf(timeslot))) + .findFirst() + .map(dictBookTimeslotList::indexOf); + if (!index.isPresent()) + return null; + + if (dictBookTimeslotList.size() <= (index.get() + 1)) + return null; + + DictDataRespDTO dictDataRespDTO = dictBookTimeslotList.get(index.get() + 1); + return Integer.valueOf(dictDataRespDTO.getValue()); + } + +} + -- Gitblit v1.9.3