Prechádzať zdrojové kódy

add
记录最后一次密码修改时间

lifang 1 deň pred
rodič
commit
e112cf5fb0

+ 63 - 13
nb-service/web-service/src/main/java/com/nb/web/service/bus/listener/DeviceInfoListener.java

@@ -5,6 +5,7 @@ import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.nb.web.api.entity.BusDeviceAlarmEntity;
@@ -400,15 +401,36 @@ public class DeviceInfoListener implements IIotMsgHandler {
                 // 1. 判断当前输注的病号是否存在其他正在进行的输注
                 // 2. 判断该设备上一次输注绑定的病号是否没有任何输注
                 long runningInfusionCount = infusionHistoryService.getRunningInfusionCount(device.getPatientId());
-                patientService.update(new UpdateWrapper<BusPatientEntity>()
-                        .lambda()
-                        .eq(BusPatientEntity::getId,device.getPatientId())
-                        // 已撤泵且修改参数的输注不再作为主泵进行判定
-                        .set(device.isNewInfusion(),BusPatientEntity::getInfusionId,device.getInfusionId())
-                        .set(device.isNewInfusion(),BusPatientEntity::getOriginCode,device.getPatientCode())
-                        .set(device.isNewInfusion(),BusPatientEntity::getCode,device.getFormatPatientCode())
-                        .set(runningInfusionCount>0,BusPatientEntity::getAlarm,PatientAlarmEnum.DEVICE_REPEAT)
-                        .set(runningInfusionCount==0,BusPatientEntity::getAlarm,PatientAlarmEnum.NONE));
+                
+                // 优化:只在数据实际变化时才更新数据库
+                boolean needsUpdate = false;
+                LambdaUpdateWrapper<BusPatientEntity> updateWrapper = new LambdaUpdateWrapper<BusPatientEntity>()
+                        .eq(BusPatientEntity::getId, device.getPatientId());
+                
+                if (device.isNewInfusion() ) {
+                    updateWrapper.set(BusPatientEntity::getInfusionId, device.getInfusionId());
+                    needsUpdate = true;
+                }
+                if (device.isNewInfusion()) {
+                    updateWrapper.set(BusPatientEntity::getOriginCode, device.getPatientCode());
+                    needsUpdate = true;
+                }
+                if (device.isNewInfusion()) {
+                    updateWrapper.set(BusPatientEntity::getCode, device.getFormatPatientCode());
+                    needsUpdate = true;
+                }
+                if (runningInfusionCount > 0 ) {
+                    updateWrapper.set(BusPatientEntity::getAlarm, PatientAlarmEnum.DEVICE_REPEAT);
+                    needsUpdate = true;
+                }
+                if (runningInfusionCount == 0) {
+                    updateWrapper.set(BusPatientEntity::getAlarm, PatientAlarmEnum.NONE);
+                    needsUpdate = true;
+                }
+                
+                if (needsUpdate) {
+                    patientService.update(updateWrapper);
+                }
                 
                 // 处理新输注情况
                 if(device.isNewInfusion()){
@@ -444,9 +466,12 @@ public class DeviceInfoListener implements IIotMsgHandler {
                 });
             }else if(!clinicFinished){
                 // 临床未结束,切换当前输注信息为主输注
-                patientService.update(new UpdateWrapper<BusPatientEntity>().lambda()
-                        .eq(BusPatientEntity::getId,device.getPatientId())
-                        .set(BusPatientEntity::getInfusionId,device.getInfusionId()));
+                BusPatientEntity existingPatient = patientService.getById(device.getPatientId());
+                if (!ObjectUtil.equal(existingPatient.getInfusionId(), device.getInfusionId())) {
+                    patientService.update(new UpdateWrapper<BusPatientEntity>().lambda()
+                            .eq(BusPatientEntity::getId, device.getPatientId())
+                            .set(BusPatientEntity::getInfusionId, device.getInfusionId()));
+                }
                 device.setMaster(true);
                 suppliers.add(()->{
                     currentPatientOperator.setBindDeviceId(deviceId);
@@ -646,6 +671,15 @@ public class DeviceInfoListener implements IIotMsgHandler {
         
         // 判断临床是否已结束,若临床已结束,则采用当前输注作为主输注开启临床
         BusPatientEntity patient = patientService.getById(device.getPatientId());
+        // 保存原始数据用于比较
+        BusPatientEntity originalPatient = new BusPatientEntity();
+
+        originalPatient.setInfusionId(patient.getInfusionId());
+        originalPatient.setClinicId(patient.getClinicId());
+        originalPatient.setTenantId(patient.getTenantId());
+        originalPatient.setAlarm(patient.getAlarm());
+        originalPatient.setId(patient.getId());
+
         if(clinicFinished){
             clinicService.resetClinic(device.getClinicId());
             patient.setInfusionId(device.getInfusionId());
@@ -659,9 +693,25 @@ public class DeviceInfoListener implements IIotMsgHandler {
         } else if (StrUtil.isEmpty(patient.getInfusionId())) {
             patient.setInfusionId(device.getInfusionId());
         }
-        patientService.updateById(patient);
+        
+        // 优化:只在数据真正发生变化时才更新数据库
+        if (isPatientDataChanged(originalPatient, patient)) {
+            patientService.updateById(patient);
+        }
     }
 
+    /**
+     * 比较患者数据是否发生变化
+     * @param originalPatient 原始患者数据
+     * @param updatedPatient 更新后的患者数据
+     * @return 如果数据发生变化返回true,否则返回false
+     */
+    private boolean isPatientDataChanged(BusPatientEntity originalPatient, BusPatientEntity updatedPatient) {
+        return !ObjectUtil.equal(originalPatient.getInfusionId(), updatedPatient.getInfusionId()) ||
+               !ObjectUtil.equal(originalPatient.getCode(), updatedPatient.getCode()) ||
+               !ObjectUtil.equal(originalPatient.getOriginCode(), updatedPatient.getOriginCode()) ||
+               !ObjectUtil.equal(originalPatient.getAlarm(), updatedPatient.getAlarm());
+    }
 
     /**
      * 格式化患者编码