/** * 多线程查询 根据条件查询所有表的数据量,返回HashMap<表名,数据量> * * @return */ private Map<String, Integer> getTablesCount(Parameters<AlcoholWarning> parameters, List<String> tables) { List<Future<Map<String, Integer>>> futureList = new ArrayList<Future<Map<String, Integer>>>(); ThreadPoolExecutor threadPool = new ThreadPoolExecutor(5,5,0,TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>(1024),new ThreadPoolExecutor.DiscardOldestPolicy()); Map<String, Integer> result = new HashMap<String, Integer>();
// 查询所有表的总数,分表数量存入map for (String tb : tables) { // 设置参数 final Parameters<AlcoholWarning> param = new Parameters<AlcoholWarning>(); BeanUtils.copyProperties(parameters, param); AlcoholWarning temp = new AlcoholWarning(); BeanUtils.copyProperties(parameters.getModel(), temp); temp.setTableName(ALCOHOLTABLE + tb); temp.setIsHis(false); param.setModel(temp); // 查询 Future<Map<String, Integer>> future = threadPool.submit(new Callable<Map<String, Integer>>() { @Override public Map<String, Integer> call() throws Exception { Map<String, Integer> map = new HashMap<String, Integer>(); try { Integer count = 0; // if (param.getModel().getIsHis()) { count = alcoholWarningMapper.getHisCountTable(param); // count = alcoholWarningMapper.getCountTable(param); // } else { // count = alarmMapper.getCountTable(param); // } count = alcoholWarningMapper.getCountTable(param); map.put(ALCOHOLTABLE + tb, count); } catch (Exception ex) { // 解决表和视图不存在的问题 log.info("多线程查询所有表的总数据量异常:{}------",ex); } return map; } }); // 封装入查询结果 futureList.add(future); } for (Future<Map<String, Integer>> future : futureList) { try { result.putAll(future.get()); } catch (Exception e) { log.info("多线程查询所有表的总数据量异常:{}------",e); } } threadPool.shutdown(); return result; }
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<!-- 报警明细查询 当月表 --> <select id="getListOfAlarmBean" parameterType="com.tiamaes.cloud.adas.core.bean.Parameters" resultMap="alcoholWarningMap"> select tr.*,tp.paths as jpg_paths,tv.paths as video_paths from ( select * from ( SELECT ts.*,ROWNUM RN FROM( SELECT d.REC_NO, d.MACH_NO, d.COUNTRY_NO, d.CITY_ID, d.ORGAN_NO, d.FILA_NO, d.GROUP_NO, d.PARKING_ID, d.PARKING_NAME, d.WARN_SIGN, d.WARN_NO, d.DRIVER_NO, d.DRIVER_NAME, d.LNG, d.LAT, d.WARN_CODE, d.WARN_CONTENT, d.WARN_FLAG, d.WARN_LEVEL, d.OCCUR_TIME, d.MEDIA_ID, d.ALCOHOL_VAL, case when d.ALCOHOL_VAL < 20 then '正常' else to_char(d.ALCOHOL_VAL) end alcoholValStr, d.ALCOHOL_RESULT, d.DIASTOLIC_PRESSURE_VAL, d.SYSTOLIC_PRESSURE_VAL, d.BLOOD_PRESSURE_RESULT, d.BLOOD_OXYGEN_VAL, d.BLOOD_OXYGEN_RESULT, d.TEMPERATURE_VAL, d.TEMPERATURE_RESULT, d.HEART_RATE_VAL, d.HEART_RATE_RESULT, d.MACH_TYPE, d.PHONE_NUM, d.FILA_NAME, d.GROUP_NAME, d.ORGAN_NAME, d.IS_TRANS, d.IS_CLEAR, d.INS_TIME FROM ${model.tableName} d <if test=" null != model.isShow or null != model.isCount or null != model.isShowBar"> right join tm_warn_level_para tp on tp.warn_code = d.warn_code and tp.warn_type = 1 and enable = 1 and tp.level_is_show = 1 and d.warn_level = tp.warn_level </if> <where> <if test=" null != model.isShow or null != model.isCount or null != model.isShowBar"> and d.WARN_FLAG < 2 </if> <if test="model.filaNo != null"> AND d.fila_no = #{model.filaNo} </if> <if test="model.machNo != null and model.machNo != ''"> and d.mach_no = #{model.machNo} </if> <if test="model.groupNo != null"> AND d.group_no = #{model.groupNo} </if> <if test="model.mediaId != null and model.mediaId != ''"> AND d.media_id like '%'||#{model.mediaId}||'%' </if> <if test="model.warnNo != null "> AND d.warn_no = #{model.warnNo} </if> <if test="model.warnLevel != null"> AND d.WARN_LEVEL=#{model.warnLevel} </if> <!-- 驾驶员工号或者姓名 --> <if test="model.driverNoOrName != null and model.driverNoOrName !='' "> AND ( d.DRIVER_NO like CONCAT(CONCAT('%',#{model.driverNoOrName}),'%') or d.DRIVER_NAME like CONCAT(CONCAT('%',#{model.driverNoOrName}),'%') ) </if> <if test="model.startTime != null "> AND d.occur_time >= #{model.startTime} </if> <if test="model.endTime != null "> AND d.occur_time <= #{model.endTime} </if> <if test=" !isAdmin "> AND d.PARKING_ID in (select dataid from tm_user_data_authority where userid = #{user.username,jdbcType=VARCHAR} and dtype='parking') </if> <!-- 驾驶员工号--> <if test="model.driverNo != null and model.driverNo !='' "> AND ( d.DRIVER_NO like CONCAT(CONCAT('%',#{model.driverNo}),'%') ) </if> <!-- 驾驶员姓名 --> <if test="model.driverName != null and model.driverName !='' "> AND ( d.DRIVER_NAME like CONCAT(CONCAT('%',#{model.driverName}),'%') ) </if> <if test="model.parkingId != null"> and d.PARKING_ID = #{model.parkingId} </if> <if test="model.parkingName != null and model.parkingName !=''"> AND d.PARKING_NAME like '%'||#{model.parkingName}||'%' </if> <if test="model.alcoholResult != null"> and d.ALCOHOL_RESULT = #{model.alcoholResult} </if> <if test="model.temperatureResult != null"> and d.TEMPERATURE_RESULT = #{model.temperatureResult} </if> <if test="model.diastolicPressureVal != null"> and d.DIASTOLIC_PRESSURE_VAL = #{model.diastolicPressureVal} </if> <if test="model.systolicPressureVal != null"> and d.SYSTOLIC_PRESSURE_VAL = #{model.systolicPressureVal} </if> <if test="model.bloodOxygenResult != null"> and d.BLOOD_OXYGEN_RESULT = #{model.bloodOxygenResult} </if> <if test="model.bloodPressureResult != null"> and d.BLOOD_PRESSURE_RESULT = #{model.bloodPressureResult} </if> <if test="model.heartRateResult != null"> and d.HEART_RATE_RESULT = #{model.heartRateResult} </if> </where> ORDER BY d.occur_time desc ) ts <if test="pageSize != null "> where ROWNUM <= #{pageSize} </if> ) <if test="startNum != null "> WHERE RN >= #{startNum} </if> ) tr left JOIN ( select * from ${DBNAME}.${model.mediaJpgTableName} where MEDIA_TYPE='4' ) tp ON tp.media_No = tr.MEDIA_ID left join ( select * from ${DBNAME}.${model.mediaJpgTableName} where MEDIA_TYPE='2' ) tv on tv.media_no = tr.MEDIA_ID order by tr.occur_time desc </select>
