18339543638 il y a 1 an
Parent
commit
e829002d70

+ 38 - 1
nb-service/web-service/src/main/java/com/nb/web/service/bus/service/LocalBusClinicService.java

@@ -1,10 +1,13 @@
 package com.nb.web.service.bus.service;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.extra.spring.SpringUtil;
 import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.nb.web.api.entity.BusEvaluationEntity;
 import com.nb.web.api.enums.ClinicManageEnum;
 import com.nb.web.api.event.ClinicFinishedEvent;
 import com.nb.web.api.event.ClinicRestartEvent;
@@ -14,6 +17,8 @@ import com.nb.web.api.entity.BusClinicEntity;
 import com.nb.web.api.entity.BusInfusionHistoryEntity;
 import com.nb.web.service.bus.entity.BusPatientEntity;
 import com.nb.web.service.bus.mapper.BusClinicMapper;
+import com.nb.web.service.bus.mapper.BusEvaluationMapper;
+import com.nb.web.service.bus.mapper.BusInfusionHistoryMapper;
 import com.nb.web.service.bus.registry.patient.PatientOperator;
 import com.nb.web.service.bus.registry.patient.PatientRegistry;
 import com.nb.web.service.bus.service.dto.ClinicQuery;
@@ -30,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author lifang
@@ -48,6 +54,12 @@ public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClini
     @Lazy
     private LocalBusInfusionHistoryService infusionHistoryService;
 
+    @Autowired
+    private BusEvaluationMapper evaluationMapper;
+
+    @Autowired
+    private BusInfusionHistoryMapper infusionHistoryMapper;
+
     @Autowired
     @Lazy
     private LocalBusPatientService patientService;
@@ -246,7 +258,32 @@ public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClini
     }
 
     public IPage<ClinicResult> pageQuery(ClinicQuery query){
-        return this.baseMapper.pageQuery(query.getPage(),query);
+        IPage<ClinicResult> result = this.baseMapper.pageQuery(query.getPage(), query);
+        List<ClinicResult> records = result.getRecords();
+        if(CollectionUtil.isNotEmpty(records)){
+            Set<String> clinicIds = records.stream()
+                    .map(ClinicResult::getClinicId)
+                    .collect(Collectors.toSet());
+            List<BusInfusionHistoryEntity> infusionHistories = infusionHistoryMapper.selectList(new LambdaQueryWrapper<BusInfusionHistoryEntity>()
+                    .in(BusInfusionHistoryEntity::getClinicId, clinicIds));
+            List<BusEvaluationEntity> evals = evaluationMapper.selectList(new LambdaQueryWrapper<BusEvaluationEntity>()
+                    .in(BusEvaluationEntity::getClinicId, clinicIds));
+
+            Map<String, Integer> infusionMap = infusionHistories.stream()
+                    .collect(Collectors.groupingBy(BusInfusionHistoryEntity::getClinicId, Collectors.collectingAndThen(Collectors.toList(), CollectionUtil::size)));
+
+            Map<String, Integer> evalMap = evals.stream()
+                    .collect(Collectors.groupingBy(BusEvaluationEntity::getClinicId, Collectors.collectingAndThen(Collectors.toList(), CollectionUtil::size)));
+
+            for (ClinicResult record : records) {
+                Integer infusionCount = infusionMap.getOrDefault(record.getClinicId(),0);
+                Integer evalCount = evalMap.getOrDefault(record.getClinicId(),0);
+                record.setInfusionCount(infusionCount);
+                record.setEvalCount(evalCount);
+            }
+
+        }
+        return result;
     }
 
     /**

+ 42 - 53
nb-service/web-service/src/main/resources/mapper/bus/BusClinicMapper.xml

@@ -102,61 +102,50 @@
     </select>
 
     <select id="pageQuery" resultMap="queryResult" parameterType="com.nb.web.service.bus.service.dto.ClinicQuery">
-        select
-        tmp.*,
-        i.infusion_count as infusion_count,
-        eval.eval_count as eval_count
-        from (select p.id as patient_id,
-                c.id as clinic_id,
-                if(c.monitor_type=1,p.code,c.patient_code) as patient_code,
-                c.patient_name as patient_name,
-                c.ward as ward,
-                c.bed_no as bed_no,
-                c.`surgery_name` as surgery_name,
-                c.surgery_doctor as surgery_doctor,
-                c.ana_doctor as ana_doctor,
-                c.monitor_type as monitor_type,
-                c.finished as finished,
-                c.start_time as clinic_start_time,
-                c.monitor_start_time as monitor_start_time,
-                c.end_time as monitor_end_time
-                 from
-                (select * from bus_clinic
-                <where>
-                    <if test="query.monitorType!=null">
-                        and monitor_type=#{query.monitorType}
-                    </if>
-                    <if test="query.finished!=null">
-                        and finished=#{query.finished}
-                    </if>
-                    <if test="query.surgeryName!=null">
-                        and surgery_name like concat('%',#{query.surgeryName},'%')
-                    </if>
-                    <if test="query.patientName!=null">
-                        and patient_name like concat('%',#{query.patientName},'%')
-                    </if>
-                    <if test="query.ward != null and query.ward.size > 0">
-                        and ward in
-                        <foreach item="w" index="index" collection="query.ward" open="(" separator="," close=")">
-                            #{w, jdbcType=VARCHAR}
-                        </foreach>
-                    </if>
-                    <if test="query.bedNo!=null">
-                        and bed_no like concat('%',#{query.bedNo},'%')
-                    </if>
-                    <if test="query.timeRange != null and query.timeRange.size >0">
-                        and monitor_start_time &gt; #{query.timeRange[0]} and  monitor_start_time &lt; #{query.timeRange[1]}
-                    </if>
-                </where>
-                ) as c
-                left join (select * from bus_patient)
-                as p on c.patient_id = p.id
-        ) as tmp
-        left join  (select clinic_id,count(1) as infusion_count from bus_infusion_history GROUP BY clinic_id) as i on i.clinic_id=tmp.clinic_id
-        left join (select clinic_id,count(1) as eval_count from bus_evaluation  GROUP BY clinic_id) as eval on eval.clinic_id=tmp.clinic_id
+       select p.id as patient_id,
+        c.id as clinic_id,
+        if(c.monitor_type=1,p.code,c.patient_code) as patient_code,
+        c.patient_name as patient_name,
+        c.ward as ward,
+        c.bed_no as bed_no,
+        c.`surgery_name` as surgery_name,
+        c.surgery_doctor as surgery_doctor,
+        c.ana_doctor as ana_doctor,
+        c.monitor_type as monitor_type,
+        c.finished as finished,
+        c.start_time as clinic_start_time,
+        c.monitor_start_time as monitor_start_time,
+        c.end_time as monitor_end_time
+        from bus_clinic as c
+        left join bus_patient
+        as p on c.patient_id = p.id
         <where>
+            <if test="query.monitorType!=null">
+                and c.monitor_type=#{query.monitorType}
+            </if>
+            <if test="query.finished!=null">
+                and c.finished=#{query.finished}
+            </if>
+            <if test="query.surgeryName!=null">
+                and c.surgery_name like concat('%',#{query.surgeryName},'%')
+            </if>
+            <if test="query.patientName!=null">
+                and c.patient_name like concat('%',#{query.patientName},'%')
+            </if>
+            <if test="query.ward != null and query.ward.size > 0">
+                and c.ward in
+                <foreach item="w" index="index" collection="query.ward" open="(" separator="," close=")">
+                    #{w, jdbcType=VARCHAR}
+                </foreach>
+            </if>
+            <if test="query.bedNo!=null">
+                and c.bed_no like concat('%',#{query.bedNo},'%')
+            </if>
+            <if test="query.timeRange != null and query.timeRange.size >0">
+                and c.monitor_start_time &gt; #{query.timeRange[0]} and  c.monitor_start_time &lt; #{query.timeRange[1]}
+            </if>
             <if test="query.patientCode!=null">
-                patient_code like concat('%',#{query.patientCode},'%')
+                and c.patient_code like concat('%',#{query.patientCode},'%')
             </if>
         </where>
         <if test="(query.orderByDesc!=null and query.orderByDesc.size > 0 ) or (query.orderByAsc!=null and query.orderByAsc.size > 0)">