|
|
@@ -4,6 +4,7 @@ import cn.tr.module.phototherapy.common.dto.*;
|
|
|
import cn.tr.module.phototherapy.common.enums.PhaseDayEnum;
|
|
|
import cn.tr.module.phototherapy.common.enums.TherapyPlanNameEnum;
|
|
|
import cn.tr.module.phototherapy.common.enums.TherapyPlanStatusEnum;
|
|
|
+import cn.tr.module.phototherapy.common.repository.BusClinicRepository;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import cn.tr.module.phototherapy.common.po.BusClinicPO;
|
|
|
@@ -32,6 +33,11 @@ import cn.tr.core.exception.TRExcCode;
|
|
|
@Service
|
|
|
public class BusTherapyPlanServiceImpl extends ServiceImpl<BusTherapyPlanRepository, BusTherapyPlanPO> implements IBusTherapyPlanService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BusClinicRepository busClinicRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BusTherapyPlanRepository therapyPlanRepository;
|
|
|
|
|
|
/**
|
|
|
* 根据条件查询设计方案
|
|
|
@@ -230,4 +236,45 @@ public class BusTherapyPlanServiceImpl extends ServiceImpl<BusTherapyPlanReposit
|
|
|
.isNull(BusTherapyPlanPO::getPhaseEndTime))
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean updateTherapyPlanStatus(String patientUniqueId) {
|
|
|
+
|
|
|
+ String therapyPlanId = busClinicRepository.selectTherapyPlanIdByPatientId(patientUniqueId);
|
|
|
+ if (therapyPlanId == null){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "患者无关联治疗方案");
|
|
|
+ }
|
|
|
+ // 2. 根据therapy_plan_id查询方案详情
|
|
|
+ BusTherapyPlanPO plan = therapyPlanRepository.selectStatusByPlanId(therapyPlanId);
|
|
|
+ if (plan == null){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "患者治疗方案不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 判断当前状态,进行更改
|
|
|
+ int targetStatus;
|
|
|
+ TherapyPlanStatusEnum currentStatus = TherapyPlanStatusEnum.getByValue(plan.getPlanStatus());
|
|
|
+ if (currentStatus == null) {
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "操作失败:方案状态异常");
|
|
|
+ }
|
|
|
+ if (TherapyPlanStatusEnum.TERMINATED.equals(currentStatus)) {
|
|
|
+ // 终止状态 → 切换为启用中
|
|
|
+ targetStatus = TherapyPlanStatusEnum.ENABLED.getValue();
|
|
|
+ } else if (TherapyPlanStatusEnum.ENABLED.equals(currentStatus) || TherapyPlanStatusEnum.WAITING.equals(currentStatus)) {
|
|
|
+ // 启用中/等待启用 → 切换为终止
|
|
|
+ targetStatus = TherapyPlanStatusEnum.TERMINATED.getValue();
|
|
|
+ } else {
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "操作失败:当前状态无需更改");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 更新方案状态
|
|
|
+ plan.setPlanStatus(targetStatus);
|
|
|
+ int updateCount = therapyPlanRepository.updateById(plan);
|
|
|
+ if (updateCount == 0) {
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "操作失败:更新方案状态失败");
|
|
|
+
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|