Procházet zdrojové kódy

考情监考-大屏报表时间趋势修改动态调整

wangliang před 2 roky
rodič
revize
8d0f9752ff

+ 14 - 2
themis-business/src/main/java/com/qmth/themis/business/dao/TOeExamRecordMapper.java

@@ -389,7 +389,17 @@ public interface TOeExamRecordMapper extends BaseMapper<TOeExamRecord> {
      */
     public List<ExaminationMonitorMapBean> getMap(@Param("orgId") Long orgId);
 
-    public List<TimeScaleDataResult> getWarnTrend(@Param("orgId") Long orgId, @Param("timeData") List<String> timeData, @Param("currentDate") String currentDate, @Param("interval") Integer interval);
+    /**
+     * 获取预警数据
+     *
+     * @param orgId
+     * @param timeData
+     * @param currentDate
+     * @param interval
+     * @param scaleSize
+     * @return
+     */
+    public List<TimeScaleDataResult> getWarnTrend(@Param("orgId") Long orgId, @Param("timeData") List<String> timeData, @Param("currentDate") String currentDate, @Param("interval") Integer interval, @Param("scaleSize") Integer scaleSize);
 
     public void updateHasAnswerFile(@Param("recordId") Long recordId, @Param("hasAnswerFile") Integer hasAnswerFile);
 
@@ -488,9 +498,11 @@ public interface TOeExamRecordMapper extends BaseMapper<TOeExamRecord> {
      * 获取时间尺度数据
      *
      * @param orgId
+     * @param timeData
      * @param currentDate
+     * @param interval
      * @param scaleSize
      * @return
      */
-    public List<TimeOnlineDataResult> getTimeOnlineData(@Param("orgId") Long orgId, @Param("currentDate") String currentDate, @Param("scaleSize") Integer scaleSize);
+    public List<TimeOnlineDataResult> getTimeOnlineData(@Param("orgId") Long orgId, @Param("timeData") List<String> timeData, @Param("currentDate") String currentDate, @Param("interval") Integer interval, @Param("scaleSize") Integer scaleSize);
 }

+ 15 - 33
themis-business/src/main/java/com/qmth/themis/business/service/impl/TIeReportServiceImpl.java

@@ -399,40 +399,22 @@ public class TIeReportServiceImpl implements TIeReportService {
         String currentDate = DateUtil.format(new Date(), Constants.DEFAULT_DATE_PATTERN);
         Map<String, String> map = this.getTimeScale(timeSize, currentDate);
 
-        List<TimeScaleDataResult> timeScaleDataResultList = tOeExamRecordMapper.getWarnTrend(tbUser.getOrgId(), new ArrayList<>(map.values()), currentDate, interval);
-        List<TimeOnlineDataResult> timeOnlineDataResultList = tOeExamRecordMapper.getTimeOnlineData(tbUser.getOrgId(), currentDate, scaleSize);
-        Map<String, TimeOnlineDataResult> onlineMap = null;
-        if (!CollectionUtils.isEmpty(timeOnlineDataResultList)) {
-            onlineMap = new LinkedHashMap<>();
-            for (TimeOnlineDataResult t : timeOnlineDataResultList) {
-                if (!onlineMap.containsKey(t.getHour())) {
-                    onlineMap.put(t.getHour(), t);
-                } else {
-                    TimeOnlineDataResult temp = onlineMap.get(t.getHour());
-                    temp.setOnlineCount(temp.getOnlineCount() + t.getOnlineCount());
-                    temp.setOfflineCount(temp.getOfflineCount() + t.getOfflineCount());
-                }
-            }
-        }
-        int beforeOnlineCount = 0;
-        TimeScaleDataResult beforeT = null;
-        if (!CollectionUtils.isEmpty(timeScaleDataResultList) && !CollectionUtils.isEmpty(onlineMap)) {
-            for (int i = 0; i < timeScaleDataResultList.size(); i++) {
-                TimeScaleDataResult t = timeScaleDataResultList.get(i);
-                if (onlineMap.containsKey(t.getHour())) {
-                    if (i > 0) {
-                        beforeT = timeScaleDataResultList.get(i - 1);
-                        beforeOnlineCount = beforeT.getOnlineCount();
-                    }
-                    int onlineCount = onlineMap.get(t.getHour()).getOnlineCount() + beforeOnlineCount - onlineMap.get(t.getHour()).getOfflineCount();
-                    onlineCount = onlineCount < 0 ? 0 : onlineCount;
-                    t.setOnlineCount(onlineCount);
-                } else {
-                    if (i > 0) {
-                        beforeT = timeScaleDataResultList.get(i - 1);
-                        t.setOnlineCount(beforeT.getOnlineCount() < 0 ? 0 : beforeT.getOnlineCount());
-                    }
+        List<String> timeData = new ArrayList<>(map.values());
+        List<TimeScaleDataResult> timeScaleDataResultList = tOeExamRecordMapper.getWarnTrend(tbUser.getOrgId(), timeData, currentDate, interval, scaleSize);
+        List<TimeOnlineDataResult> timeOnlineDataResultList = tOeExamRecordMapper.getTimeOnlineData(tbUser.getOrgId(), timeData, currentDate, interval, scaleSize);
+        if (!CollectionUtils.isEmpty(timeOnlineDataResultList) && !CollectionUtils.isEmpty(timeScaleDataResultList)
+                && timeOnlineDataResultList.size() == timeScaleDataResultList.size()) {
+            int beforeOnlineCount = 0;
+            TimeScaleDataResult beforeScale = null;
+            for (int i = 0; i < timeOnlineDataResultList.size(); i++) {
+                TimeOnlineDataResult t = timeOnlineDataResultList.get(i);
+                if (i > 0) {
+                    beforeScale = timeScaleDataResultList.get(i - 1);
+                    beforeOnlineCount = beforeScale.getOnlineCount();
                 }
+                int onlineCount = t.getOnlineCount() + beforeOnlineCount - t.getOfflineCount();
+                onlineCount = onlineCount < 0 ? 0 : onlineCount;
+                timeScaleDataResultList.get(i).setOnlineCount(onlineCount);
             }
         }
         return timeScaleDataResultList;

+ 83 - 65
themis-business/src/main/resources/mapper/TOeExamRecordMapper.xml

@@ -1152,11 +1152,11 @@
         <foreach collection="timeData" item="item" index="index">
             <choose>
                 <when test="index == 0">
-                    <include refid="getWarnTrendCommon" />
+                    <include refid="getWarnTrendCommon"/>
                 </when>
                 <otherwise>
                     union all
-                    <include refid="getWarnTrendCommon" />
+                    <include refid="getWarnTrendCommon"/>
                 </otherwise>
             </choose>
         </foreach>
@@ -1573,94 +1573,112 @@
     </select>
 
     <sql id="getWarnTrendCommon">
-        <!--select
-            t.hour,
-            count(distinct t.examRecordId) as onlineCount,
-            0 as warnCount
+        select
+        t.hour,
+        count(t.examRecordId) as warnCount
         from
-            (
-                select
-                    DATE_FORMAT(#{item}, '%H:%i') as hour,
-                    teesol.exam_record_id as examRecordId,
-                    DATE_FORMAT(FROM_UNIXTIME(teesol.create_time / 1000), '%Y-%m-%d %H:%i:00') as createTime
-                from
-                    t_e_exam_student_online_log teesol
-                    join t_oe_exam_record toer on toer.id = teesol.exam_record_id
-                    join t_e_exam tee on toer.exam_id = tee.id
-                    WHERE 1 = 1
-                    <if test="orgId != null and orgId != ''">
-                        and tee.org_id = #{orgId}
-                    </if>
-                  and (teesol.create_time <![CDATA[ >= ]]> unix_timestamp(date_sub(#{currentDate}, interval 30 minute)) * 1000
-                  and teesol.create_time <![CDATA[ <= ]]> unix_timestamp(#{currentDate}) * 1000)) t
+        (
+        select
+        DATE_FORMAT(#{item}, '%H:%i') as hour,
+        tiiwi.exam_record_id as examRecordId,
+        DATE_FORMAT(FROM_UNIXTIME(tiiwi.create_time / 1000), '%Y-%m-%d %H:%i:00') as createTime
+        from
+        t_oe_exam_record toer
+        join t_ie_invigilate_warn_info tiiwi on
+        tiiwi.exam_record_id = toer.id
+        join t_e_exam tee on toer.exam_id = tee.id
+        WHERE 1 = 1
+        <if test="orgId != null and orgId != ''">
+            and tee.org_id = #{orgId}
+        </if>
+        and (tiiwi.create_time <![CDATA[ >= ]]> unix_timestamp(date_sub(#{currentDate}, interval #{scaleSize} minute)) *
+        1000
+        and tiiwi.create_time <![CDATA[ <= ]]> unix_timestamp(#{currentDate}) * 1000)) t
         where
-            (t.createTime <![CDATA[ >= ]]> #{item} and t.createTime <![CDATA[ < ]]> date_add(#{item}, interval #{interval} minute))
-        union all
-          -->
-            select
-                t.hour,
-                <!--0 as onlineCount,-->
-                count(t.examRecordId) as warnCount
-                from
-                (
-                select
-                DATE_FORMAT(#{item}, '%H:%i') as hour,
-                tiiwi.exam_record_id as examRecordId,
-                DATE_FORMAT(FROM_UNIXTIME(tiiwi.create_time / 1000), '%Y-%m-%d %H:%i:00') as createTime
-                from
-                t_oe_exam_record toer
-                join t_ie_invigilate_warn_info tiiwi on
-                    tiiwi.exam_record_id = toer.id
-                join t_e_exam tee on toer.exam_id = tee.id
-                WHERE 1 = 1
-                <if test="orgId != null and orgId != ''">
-                    and tee.org_id = #{orgId}
-                </if>
-                and (tiiwi.create_time <![CDATA[ >= ]]> unix_timestamp(date_sub(#{currentDate}, interval 30 minute)) * 1000
-                and tiiwi.create_time <![CDATA[ <= ]]> unix_timestamp(#{currentDate}) * 1000)) t
-                where
-                (t.createTime <![CDATA[ >= ]]> #{item} and t.createTime <![CDATA[ < ]]> date_add(#{item}, interval #{interval} minute))
+        (t.createTime <![CDATA[ >= ]]> #{item} and t.createTime <![CDATA[ < ]]> date_add(#{item}, interval #{interval}
+        minute))
     </sql>
 
     <select id="getTimeOnlineData" resultType="com.qmth.themis.business.bean.result.TimeOnlineDataResult">
         select
-            t.hour,
-            sum(t.onlineCount) as onlineCount,
-            sum(t.offlineCount) as offlineCount
+        t.hour,
+        sum(t.onlineCount) as onlineCount,
+        sum(t.offlineCount) as offlineCount
         from
         (
+        <foreach collection="timeData" item="item" index="index">
+            <choose>
+                <when test="index == 0">
+                    <include refid="getTimeOnlineDataCommon"/>
+                </when>
+                <otherwise>
+                    union all
+                    <include refid="getTimeOnlineDataCommon"/>
+                </otherwise>
+            </choose>
+        </foreach>
+        ) t
+        group by
+        t.hour
+        order by
+        t.hour
+    </select>
+
+    <sql id="getTimeOnlineDataCommon">
         select
-        DATE_FORMAT(FROM_UNIXTIME(teesol.create_time / 1000), '%H:%i') as hour,
-        count(distinct teesol.exam_record_id) as onlineCount,
+        t.hour,
+        count(distinct t.examRecordId) as onlineCount,
         0 as offlineCount
         from
+        (
+        select
+        DATE_FORMAT(#{item}, '%H:%i') as hour,
+        teesol.exam_record_id as examRecordId,
+        DATE_FORMAT(FROM_UNIXTIME(teesol.create_time / 1000), '%Y-%m-%d %H:%i:00') as createTime
+        from
         t_e_exam_student_online_log teesol
-        join t_oe_exam_record toer on toer.id = teesol.exam_record_id
-        join t_e_exam tee on toer.exam_id = tee.id
+        join t_oe_exam_record toer on
+        toer.id = teesol.exam_record_id
+        join t_e_exam tee on
+        toer.exam_id = tee.id
         where 1 = 1
         <if test="orgId != null and orgId != ''">
             and tee.org_id = #{orgId}
         </if>
-        and (teesol.create_time <![CDATA[ >= ]]> unix_timestamp(date_sub(#{currentDate}, interval #{scaleSize} minute)) * 1000
+        and (teesol.create_time <![CDATA[ >= ]]> unix_timestamp(date_sub(#{currentDate}, interval #{scaleSize} minute))
+        * 1000
         and teesol.create_time <![CDATA[ <= ]]> unix_timestamp(#{currentDate}) * 1000)
-        and teesol.`type` = 'ON_LINE' group by teesol.create_time
+        and teesol.`type` = 'ON_LINE') t
+        where
+        (t.createTime <![CDATA[ >= ]]> #{item} and t.createTime <![CDATA[ < ]]> date_add(#{item}, interval #{interval}
+        minute))
         union all
         select
-        DATE_FORMAT(FROM_UNIXTIME(teesol.create_time / 1000), '%H:%i') as hour,
+        t.hour,
         0 as onlineCount,
-        count(distinct teesol.exam_record_id) as offlineCount
+        count(distinct t.examRecordId) as offlineCount
+        from
+        (
+        select
+        DATE_FORMAT(#{item}, '%H:%i') as hour,
+        teesol.exam_record_id as examRecordId,
+        DATE_FORMAT(FROM_UNIXTIME(teesol.create_time / 1000), '%Y-%m-%d %H:%i:00') as createTime
         from
         t_e_exam_student_online_log teesol
-        join t_oe_exam_record toer on toer.id = teesol.exam_record_id
-        join t_e_exam tee on toer.exam_id = tee.id
+        join t_oe_exam_record toer on
+        toer.id = teesol.exam_record_id
+        join t_e_exam tee on
+        toer.exam_id = tee.id
         where 1 = 1
         <if test="orgId != null and orgId != ''">
             and tee.org_id = #{orgId}
         </if>
-        and (teesol.create_time <![CDATA[ >= ]]> unix_timestamp(date_sub(#{currentDate}, interval #{scaleSize} minute)) * 1000
+        and (teesol.create_time <![CDATA[ >= ]]> unix_timestamp(date_sub(#{currentDate}, interval #{scaleSize} minute))
+        * 1000
         and teesol.create_time <![CDATA[ <= ]]> unix_timestamp(#{currentDate}) * 1000)
-        and teesol.`type` = 'OFF_LINE' group by teesol.create_time) t
-        group by t.hour
-        order by t.hour
-    </select>
+        and teesol.`type` = 'OFF_LINE') t
+        where
+        (t.createTime <![CDATA[ >= ]]> #{item} and t.createTime <![CDATA[ < ]]> date_add(#{item}, interval #{interval}
+        minute))
+    </sql>
 </mapper>