eight
2024-11-12 60e288dfb165eafe7d03d5e22780d61029a4a825
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/queuesequence/QueueSequenceServiceImpl.java
@@ -4,6 +4,8 @@
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;
@@ -37,10 +39,22 @@
    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) {
@@ -90,17 +104,21 @@
        // 读取时段配置
        String strBookTimeslotLength = configApi.getConfigValueByKey(BOOK_TIMESLOT_LENGTH);
        String strBookTimeslotList = configApi.getConfigValueByKey(BOOK_TIMESLOT_LIST);
        // 方案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 -> {
            List<LocalTime> timeslotList = Utils.parseTimeSlotList(strBookTimeslotList, Integer.valueOf(strBookTimeslotLength));
            for (int i=0; i < timeslotList.size(); i++) {
                LocalTime timeslot = timeslotList.get(i);
            for (int i=0; i < dictBookTimeslotList.size(); i++) {
                QueueSequenceDO queueSequenceDO = new QueueSequenceDO();
                queueSequenceDO.setCheckType( checkTypeDO.getValue() );
                queueSequenceDO.setTimeSlot( timeslot.getHour()*100 + timeslot.getMinute() );
                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());
@@ -110,5 +128,37 @@
        });
    }
    @Override
    @Transactional
    public Integer distributeSeqNo(Integer checkType, Integer timeslot) {
        Integer curSeqNo = queueSequenceMapper.selectQueueNoForUpdate(checkType, timeslot);
        if (null == curSeqNo) {
            throw exception(QUEUE_SEQUENCE_TIMESLOT_FULL);
        }
        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;
    }
}