liusheng
2 天以前 a4c8c09a33ae26a460c7422f59b4d2f93d0f6dc5
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java
@@ -11,13 +11,17 @@
import cn.lihu.jh.module.ecg.dal.dataobject.patient.PatDetails;
import cn.lihu.jh.module.ecg.dal.dataobject.queue.QueueDO;
import cn.lihu.jh.module.ecg.dal.mysql.appointment.AppointmentMapper;
import cn.lihu.jh.module.ecg.enums.AppointmentTypeEnum;
import cn.lihu.jh.module.ecg.enums.HisCheckCodeEnum;
import cn.lihu.jh.module.ecg.feign.RemoteDataService;
import cn.lihu.jh.module.ecg.service.config.EcgConfigService;
import cn.lihu.jh.module.ecg.service.devrent.ApplicationTemplate;
import cn.lihu.jh.module.ecg.service.queue.QueueService;
import cn.lihu.jh.module.ecg.service.queuesequence.QueueSequenceService;
import cn.lihu.jh.module.ecg.webservice.WebServiceClient;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -61,6 +65,9 @@
    @Resource
    private AppointmentMapper appointmentMapper;
    @Autowired
    private WebServiceClient webServiceClient;
    @Override
    public Long createAppointment(AppointmentSaveReqVO createReqVO) {
        // 插入
@@ -83,6 +90,56 @@
        // 更新
        AppointmentDO updateObj = BeanUtils.toBean(updateReqVO, AppointmentDO.class);
        appointmentMapper.updateById(updateObj);
    }
    @Override
    public void updateAppointmentStatus(AppointmentSaveReqVO updateReqVO) {
        // 校验存在
        validateAppointmentExists(updateReqVO.getId());
        // 获取完整的预约信息
        AppointmentDO appointment = appointmentMapper.selectById(updateReqVO.getId());
        if (appointment == null) {
            throw exception(APPOINTMENT_NOT_EXISTS);
        }
        // 更新状态
        appointment.setStatus(updateReqVO.getStatus());
        // 调用HIS系统更新状态
        String action = "S0405";
        ApplicationTemplate app = new ApplicationTemplate();
        String statusName = AppointmentTypeEnum.getByType(appointment.getStatus());
        String message = app.getXML(
            appointment.getApplyNo(),
            appointment.getStatus(),
            statusName,
            null,
            appointment.getPatDeptCode(),
            appointment.getPatDeptDesc(),
            appointment.getPatWardCode(),
            appointment.getPatWardDesc(),
            appointment.getPatBedNo(),
            appointment.getEpisodeId(),
            String.valueOf(appointment.getBookSrc()),
            appointment.getPatId(),
            appointment.getPatName()
        );
        try {
            String response = webServiceClient.callJHFWTYRK(action, "", message);
            if (response.contains("更新成功")) {
                // 更新本地数据库
                appointmentMapper.updateById(appointment);
            } else {
                throw exception(APPOINTMENT_UPDATE_FAIL);
            }
        } catch (Exception e) {
            log.error("[updateAppointmentStatus][更新预约状态失败 appointment({})]", appointment, e);
            throw exception(APPOINTMENT_UPDATE_FAIL);
        }
    }
    @Override
@@ -371,7 +428,6 @@
            // 将AppointmentDO转换为AppointmentSaveReqVO并保存
            AppointmentSaveReqVO saveReqVO = BeanUtils.toBean(appointment, AppointmentSaveReqVO.class);
            saveReqVO.setStatus("1");
            return createAppointment(saveReqVO);
        } catch (Exception e) {
            log.error("[handleAppointmentCreate][处理预约创建失败 dataMap({})]", dataMap, e);
@@ -559,22 +615,27 @@
        // 解析预约时间
        LocalDateTime bookTime = LocalDateTime.parse(bookTimeStr, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        LocalDate bookDate = bookTime.toLocalDate();
        Integer bookTimeslot = null;
        // 获取时间段
        String timeRange = (String) ((Map<String, Object>) actAppointment.get("ZDY")).get("time");
        String[] time1 = timeRange.split(" ");
        String[] times = time1[1].split("-");
        String startTime = times[0].trim();
        String endTime = times[1].trim();
        // 转换时间段格式为hhmmhhmm
        int bookTimeslot = Integer.parseInt(startTime.replace(":", "")) * 10000 + Integer.parseInt(endTime.replace(":", ""));
        try {
//            String timeRange = (String) ((Map<String, Object>) actAppointment.get("ZDY")).get("time");这行如果是更新操作的时候,有可能报空指针(但不影响,可以不用管)
            String timeRange = (String) ((Map<String, Object>) actAppointment.get("ZDY")).get("time");
            String[] time1 = timeRange.split(" ");
            String[] times = time1[1].split("-");
            String startTime = times[0].trim();
            String endTime = times[1].trim();
            // 转换时间段格式为hhmmhhmm
            bookTimeslot = Integer.parseInt(startTime.replace(":", "")) * 10000 + Integer.parseInt(endTime.replace(":", ""));
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 更新预约信息
        appointment.setBookDate(bookDate);
        appointment.setBookTimeslot(bookTimeslot);
        appointment.setBookTime(bookTime);
        appointment.setBookSrc(Integer.parseInt(bookSrc));
        appointment.setStatus((String) ((Map<String, Object>) actAppointment.get("ZDY")).get("statusCode"));
        // 保存更新
        appointmentMapper.updateById(appointment);