1. 程式人生 > >如何在專案中使用redis來實現一些需要的功能例項?

如何在專案中使用redis來實現一些需要的功能例項?

使用Redis來實現申請布控和一些跟資料庫中的資料對比

一、需要使用Jedis的工具類去寫一些通用的工具類方法

package com.ia.lhc.redis;
import org.apache.commons.lang3.StringUtils; 
import org.apache.commons.lang3.tuple.*;
//import org.apache.log4j.Logger;  
import redis.clients.jedis.Jedis;  
import redis.clients.jedis.JedisPool;  
import redis.clients.jedis.JedisPoolConfig;
import
redis.clients.jedis.Transaction; import java.util.List; import java.util.Map; /** * Redis 工具類 */ public class JedisUtil { // protected static Logger logger = Logger.getLogger(JedisUtil.class); //Redis伺服器IP private static String ADDR_ARRAY = "localhost"; //Redis的埠號 private
static int PORT = 6379; //訪問密碼 // private static String AUTH = ""; //可用連線例項的最大數目,預設值為8; //如果賦值為-1,則表示不限制;如果pool已經分配了maxActive個jedis例項,則此時pool的狀態為exhausted(耗盡)。 private static int MAX_ACTIVE = 20; //控制一個pool最多有多少個狀態為idle(空閒的)的jedis例項,預設值也是8。 private static int MAX_IDLE = 20
; //最小空閒連線數, 預設0 private static int MIN_IDLE=5; //等待可用連線的最大時間,單位毫秒,預設值為-1,表示永不超時。如果超過等待時間,則直接丟擲JedisConnectionException; private static int MAX_WAIT = -1; //超時時間 private static int TIMEOUT = 10000; //連線耗盡時是否阻塞, false報異常,ture阻塞直到超時, 預設true private static boolean BLOCK_WHEN_EXHAUSTED = false; //設定的逐出策略類名, 預設DefaultEvictionPolicy(當連線超過最大空閒時間,或連線數超過最大空閒連線數) private static String EVICTION_POLICY_CLASSNAME="org.apache.commons.pool2.impl.DefaultEvictionPolicy"; //是否啟用pool的jmx管理功能, 預設true private static boolean JMX_ENABLED=true; private static String JMX_NAME_PREFIX="pool"; //是否啟用後進先出, 預設true private static boolean LIFO=true; //逐出連線的最小空閒時間 預設1800000毫秒(30分鐘) private static long MIN_EVICTABLE_IDLE_TIME_MILLIS=1800000L; //物件空閒多久後逐出, 當空閒時間>該值 且 空閒連線>最大空閒數 時直接逐出,不再根據MinEvictableIdleTimeMillis判斷 (預設逐出策略) private static long SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS=1800000L; //每次逐出檢查時 逐出的最大數目 如果為負數就是 : 1/abs(n), 預設3 private static int NUM_TESTS_PER_EVICYION_RUN=5; //在borrow一個jedis例項時,是否提前進行validate操作;如果為true,則得到的jedis例項均是可用的; private static boolean TEST_ON_BORROW = false; //在空閒時檢查有效性, 預設false private static boolean TEST_WHILEIDLE=false; //逐出掃描的時間間隔(毫秒) 如果為負數,則不執行逐出執行緒, 預設-1 private static long TIME_BERWEEN_EVICTION_RUNS_MILLIS=-1; //連線池管理 private static JedisPool jedisPool = null; /** * redis過期時間,以秒為單位 */ public final static int EXRP_HOUR = 60 * 60; //一小時 public final static int EXRP_DAY = 60 * 60 * 24; //一天 public final static int EXRP_MONTH = 60 * 60 * 24 * 30; //一個月 /** * 初始化Redis連線池 */ static { try { JedisPoolConfig config = new JedisPoolConfig(); config.setBlockWhenExhausted(BLOCK_WHEN_EXHAUSTED); config.setEvictionPolicyClassName(EVICTION_POLICY_CLASSNAME); config.setJmxEnabled(JMX_ENABLED); config.setJmxNamePrefix(JMX_NAME_PREFIX); config.setLifo(LIFO); config.setMinEvictableIdleTimeMillis(MIN_EVICTABLE_IDLE_TIME_MILLIS); config.setMinIdle(MIN_IDLE); config.setNumTestsPerEvictionRun(NUM_TESTS_PER_EVICYION_RUN); config.setSoftMinEvictableIdleTimeMillis(SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS); config.setTestOnBorrow(TEST_ON_BORROW); config.setTestWhileIdle(TEST_WHILEIDLE); config.setTimeBetweenEvictionRunsMillis(TIME_BERWEEN_EVICTION_RUNS_MILLIS); config.setMaxTotal(MAX_ACTIVE); config.setMaxIdle(MAX_IDLE); config.setMaxWaitMillis(MAX_WAIT); jedisPool = new JedisPool(config, ADDR_ARRAY, PORT, TIMEOUT); System.out.println("connect to redis ok "); } catch (Exception e) { // logger.error("First create JedisPool error : " + e); System.out.println("Initialize JedisPool error : " + e); e.printStackTrace(); } } /** * 銷燬連線池 * @return void */ public static void end() { if(null != jedisPool){ jedisPool.destroy(); System.out.println("連線池關閉"); } } /** * 同步獲取Jedis例項 * @return Jedis */ public static Jedis getJedis() { Jedis jedis = null; try { if (jedisPool != null) { jedis = jedisPool.getResource(); } } catch (Exception e) { // logger.error("Get jedis error : "+e); System.out.println("getJedis error : "+e); e.printStackTrace(); } return jedis; } /** * 釋放jedis資源 * * @param jedis */ public static void returnResource(final Jedis jedis) { if (jedis != null && jedisPool != null) { jedis.close(); // System.out.println("返回jedis資源!"); } } /** * 設定 List * * @param key * @param value */ public static void setListItem(String key, String value) { Jedis resource = null; try { value = StringUtils.isEmpty(value) ? "" : value; resource = getJedis(); resource.lpush(key, value); } catch (Exception e) { // logger.error("Set key error : " + e); System.out.println("setListItem error : " + e); e.printStackTrace(); } finally{ if ( resource != null ) { returnResource(resource); } } } /** * 刪除 List中的元素 * * @param key * @param value */ public static void RemListItem(String key, String value) { Jedis resource = null; try { value = StringUtils.isEmpty(value) ? "" : value; resource = getJedis(); resource.lrem(key, 1, value); } catch (Exception e) { // logger.error("Set key error : " + e); System.out.println("RemListItem error : " + e); e.printStackTrace(); } finally{ if ( resource != null ) { returnResource(resource); } } } /** * 獲取List值 * * @param key * @return value */ public static List<String> getListItems(String key) { Jedis resource = null; List<String> value = null; try { resource = getJedis(); //如果列表存在,則取出所有 if (resource.exists(key)) { long len = resource.llen(key); value = resource.lrange(key, 0, len-1); } } catch (Exception e) { // logger.error("Get string error : " + e); System.out.println("getListItems error : " + e); e.printStackTrace(); } finally { if ( resource != null ) { returnResource(resource); } } return value; } /** * 設定 單條Hash表值 * * @param key * @param value */ public static void setHashItem(String key, Pair<String, String> value) { Jedis resource = null; try { //String pair_val = value.getValue(); //value.setValue(StringUtils.isEmpty(pair_val) ? "" : pair_val); resource = getJedis(); resource.hset(key, value.getKey(), value.getValue()); } catch (Exception e) { // logger.error("Set key error : " + e); System.out.println("setHashItem error : " + e); e.printStackTrace(); } finally{ if ( resource != null ) { returnResource(resource); } } } /** * 檢查Key是否存在 * @param key * @return value */ public static Boolean ExsitKey(String key) { Jedis resource = null; Boolean value = false; try { resource = getJedis(); if (resource.exists(key) ) { value = true; } } catch (Exception e) { // logger.error("Get string error : " + e); System.out.println("ExsitKey error : " + e); e.printStackTrace(); } finally { if ( resource != null ) { returnResource(resource); } } return value; } /** * 設定Key的有效期 * * @param key 要設定的key * @param timestamp 設定的有效期限(unix時間戳) */ public static void setKeyExpireTime(String key, long timestamp) { Jedis resource = null; try { resource = getJedis(); resource.expireAt(key, timestamp); } catch (Exception e) { // logger.error("Set key error : " + e); System.out.println("setKeyExpireTime error : " + e); e.printStackTrace(); } finally{ if ( resource != null ) { returnResource(resource); } } } /** * 刪除Key * * @param key 要刪除的key */ public static void removeKey(String key) { Jedis resource = null; try { resource = getJedis(); resource.del(key); } catch (Exception e) { // logger.error("Set key error : " + e); System.out.println("removeKey error : " + e); e.printStackTrace(); } finally{ if ( resource != null ) { returnResource(resource); } } } /** * 檢查Hash表中對應的field是否存在 * * @param key * @return value */ public static Boolean ExsitHashItem(String key, String field_name) { Jedis resource = null; Boolean value = false; try { resource = getJedis(); if (resource.hexists(key, field_name)) { value = true; } } catch (Exception e) { // logger.error("Get string error : " + e); System.out.println("ExsitHashItem error : " + e); e.printStackTrace(); } finally { if ( resource != null ) { returnResource(resource); } } return value; } /** * 獲取指定field的值 * * @param key * @return value */ public static String getHashItem(String key, String field_name) { Jedis resource = null; String value = null; try { resource = getJedis(); value = resource.hget(key, field_name); } catch (Exception e) { // logger.error("Get string error : " + e); System.out.println("getHashItem error : " + e); e.printStackTrace(); } finally { if ( resource != null ) { returnResource(resource); } } return value; } /** * 設定 多條Hash表值 * * @param key * @param value */ public static void setHashItems(String key, Map<String, String> value) { Jedis resource = null; try { resource = getJedis(); resource.hmset(key, value); } catch (Exception e) { // logger.error("Set key error : " + e); System.out.println("setHashItems error : " + e); e.printStackTrace(); } finally{ if ( resource != null ) { returnResource(resource); } } } /** * 獲取所有field的值 * * @param key * @return value */ public static Map<String, String> getHashItems(String key) { Jedis resource = null; Map<String, String> value = null; try { resource = getJedis(); value = resource.hgetAll(key); } catch (Exception e) { // logger.error("Get string error : " + e); System.out.println("getHashItems error : " + e); e.printStackTrace(); } finally { if ( resource != null ) { returnResource(resource); } } return value; } /** * 設定布控資訊的事務; * * @param key * @param value */ public static void setEvents(String Listkey, String HashKey, Map<String,String> HashValue, long timestamp) { Jedis resource = null; try { resource = getJedis(); Transaction transaction = resource.multi(); transaction.hmset(HashKey, HashValue); transaction.expireAt(HashKey, timestamp); transaction.lpush(Listkey, HashKey); transaction.exec(); } catch (Exception e) { // logger.error("Set key error : " + e); System.out.println("setEvents error : " + e); e.printStackTrace(); } finally{ if ( resource != null ) { returnResource(resource); } } } /** * 刪除布控資訊的事務; * * @param key * @param value */ public static void removeEvents(String Listkey, String HashKey) { Jedis resource = null; try { resource = getJedis(); Transaction transaction = resource.multi(); transaction.del(HashKey); transaction.lrem(Listkey, 1, HashKey); transaction.exec(); } catch (Exception e) { // logger.error("Set key error : " + e); System.out.println("removeEvents error : " + e); e.printStackTrace(); } finally{ if ( resource != null ) { returnResource(resource); } } } }

二、然後是新建一個Redis包在哪個專案的功能模組中使用的時候就直接用spring給注入,然後呼叫方法就行了,一般都是在controller中去呼叫這些封裝好的Redis功能介面

package com.ia.lhc.redis;
import java.util.Date;
import java.text.SimpleDateFormat;
import org.apache.commons.lang3.tuple.*;
import java.util.Map;
import java.util.HashMap;
import java.util.List;

public class VehicleInfoCompare {

    //首次入城判定時間區間(30天) 
    private final static int FirstEntryTimeSection = 30; 

    //車輛過車記錄Hash表名稱
    private final static String vehiclePassRecords = "vehiclePassRecords";

    //車輛過車記錄Hash表名稱
    private final static String vehicleFirstEntryRecords = "vehicleFirstEntryRecords";

    //維穩布控列表名稱
    private final static String StabilityItems = "StabilityItems";

    //精準車牌布控列表名稱
    private final static String ExactPlateItems = "ExactPlateItems";

    //模糊車牌布控列表名稱
    private final static String BlurPlateItems = "BlurPlateItems";

    //車型布控列表名稱
    private final static String VehicleTypeItems = "VehicleTypeItems";

    //車輛類別布控列表名稱
    private final static String VehicleKindItems = "VehicleKindItems";

     /** 
     * 得到兩個日期時間相差的天數
     * @param   lastUpdateDate  之前的日期時間(YYYY-MM-DD)
     * @param   currentDate     之後的日期時間(YYYY-MM-DD)
     * @return  long    兩個日期時間相差的天數
     */
    private static long daysOfTwoDates(String lastUpdateDate, String currentDate) {


         long days = 0;

         try {

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            //跨年不會出現問題
            //如果時間為:2016-03-18 11:59:59 和 2016-03-19 00:00:01的話差值為 0

            Date fDate=sdf.parse(lastUpdateDate);

            Date oDate=sdf.parse(currentDate);

            days=(oDate.getTime()-fDate.getTime())/(1000*3600*24);

         } catch (Exception e){

             System.out.println("daysOfTwoDates error : " + e);

             e.printStackTrace();
         }

         return days;
    }

    /**
     * 日期格式字串轉換成時間戳
     * @param dateStr 字串日期
     * @param format   如:yyyy-MM-dd HH:mm:ss
     * @return long Unix時間戳
     */
    private static long Date2TimeStamp(String dateStr) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return sdf.parse(dateStr).getTime() / 1000;
        } catch (Exception e) {

            System.out.println("Date2TimeStamp error : " + e);

            e.printStackTrace();
        }
        return 0;
    }

    /** 
     * 判斷時間是否在時間段內 
     *  
     * @param date 
     *            當前時間 yyyy-MM-dd HH:mm:ss 
     * @param strDateBegin 
     *            開始時間 00:00:00 
     * @param strDateEnd 
     *            結束時間 00:05:00 
     * @return 
     */  
    private static boolean isInTimeSection(String strDate, String strDateBegin,   String strDateEnd) 
    {  
        // 擷取當前時間時分秒  
        int strDateH = Integer.parseInt(strDate.substring(11, 13));  
        int strDateM = Integer.parseInt(strDate.substring(14, 16));  
        int strDateS = Integer.parseInt(strDate.substring(17, 19));  
        // 擷取開始時間時分秒  
        int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2));  
        int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5));  
        int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8));  
        // 擷取結束時間時分秒  
        int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2));  
        int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5));  
        int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8));  
        if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) {  
            // 當前時間小時數在開始時間和結束時間小時數之間  
            if (strDateH > strDateBeginH && strDateH < strDateEndH) {  
                return true;  
                // 當前時間小時數等於開始時間小時數,分鐘數在開始和結束之間  
            } else if (strDateH == strDateBeginH && strDateM >= strDateBeginM  
                    && strDateM <= strDateEndM) {  
                return true;  
                // 當前時間小時數等於開始時間小時數,分鐘數等於開始時間分鐘數,秒數在開始和結束之間  
            } else if (strDateH == strDateBeginH && strDateM == strDateBeginM  
                    && strDateS >= strDateBeginS && strDateS <= strDateEndS) {  
                return true;  
            }  
            // 當前時間小時數大等於開始時間小時數,等於結束時間小時數,分鐘數小等於結束時間分鐘數  
            else if (strDateH >= strDateBeginH && strDateH == strDateEndH  
                    && strDateM <= strDateEndM) {  
                return true;  
                // 當前時間小時數大等於開始時間小時數,等於結束時間小時數,分鐘數等於結束時間分鐘數,秒數小等於結束時間秒數  
            } else if (strDateH >= strDateBeginH && strDateH == strDateEndH  
                    && strDateM == strDateEndM && strDateS <= strDateEndS) {  
                return true;  
            } else {  
                return false;  
            }  
        } else {  
            return false;  
        }  
    }
     /** 
     *判斷是否為首次入城車輛
     * @param   key 歷史過車記錄Hash表
     * @param   vehicleID   本次過車記錄中的車輛ID
     * @param   captureTime 本次過車記錄中的過車時間
     * @return  Boolean true(判斷為首次入城車輛) false(判斷為非首次入城車輛)
     */
    private static boolean IsFirstEntryCity(String key, String vehicleID, String captureTime)
    {
        boolean ret = false;

        try {
            //當前傳入車牌是否在歷史過車記錄中,如果存在,則取出該車輛上一次過車時間。
            if ( JedisUtil.ExsitHashItem(key, vehicleID) )
            {
                String lastUpdateTime = JedisUtil.getHashItem(key, vehicleID);

                //判斷本次過車時間與上一次過車時間相比相差是否超過一定時間(暫定30天),如果超過,則判定為首次入城
                if (  daysOfTwoDates(lastUpdateTime, captureTime) >= FirstEntryTimeSection )
                {
                    ret = true;
                }
            }
            //如果在過車歷史記錄中不存在,則也判定為首次入城。
            else
            {
                ret = true;
            }

        } catch ( Exception e) {

            System.out.println("IsFirstEntryCity error : " + e);

            e.printStackTrace();

        } finally {

            Pair<String, String> value = new ImmutablePair<String, String>(vehicleID, captureTime);

            JedisUtil.setHashItem(key, value);
        }
        return ret;
    }

     /** 
     * 更新首次入城車輛記錄
     * @param   key 首次入城記錄Hash表
     * @param   vehicleID   本次過車記錄中的車輛ID
     * @param   captureTime 本次過車記錄中的過車時間
     * @return  void
     */
    private static void UpdateFirstEntryCityRecord(String vehicleID, String captureTime)
    {

        try {
            if (IsFirstEntryCity(vehiclePassRecords, vehicleID, captureTime))
            {
                Pair<String, String> value =  new ImmutablePair<String, String>(vehicleID, captureTime);

                JedisUtil.setHashItem(vehicleFirstEntryRecords, value);
            }
        } catch ( Exception e ) {

            System.out.println("UpdateFirstEntryCityRecord error : " + e);

            e.printStackTrace();
        }
    }

     /** 
     * 比對碰撞分析(精準號牌布控、模糊號牌布控)
     * @param   vehicleID   本次過車記錄中的車輛ID(格式為:車牌顏色-車牌號碼)
     * @param   captureTime 本次過車記錄中的過車時間
     * @param   bayonetID   本次過車記錄中的過車卡口ID
     * @return  Map<String, String> key:布控編號  value:布控方式
     */
    public static Map<String, String> GetAlarmInfoByLicenseNumber(String vehicleID, String captureTime, String bayonetID)
    {
        long startTime=System.currentTimeMillis();
        Map<String, String> retval = new HashMap<String, String>();

        List<String>    listExactPlateItems = null;     //精確號牌布控列表
        List<String>    listBlurPlateItems = null;      //模糊號牌布控列表

        try {
            //1. 判斷比較精準號牌布控資訊
            listExactPlateItems = JedisUtil.getListItems(ExactPlateItems);

            if ( listExactPlateItems != null )
            {
                //遍歷所有的精準號牌布控資訊
                for ( String item : listExactPlateItems )
                {               
                    //如果列表中的精準號牌資訊有效,則進行比較判斷
                    if ( JedisUtil.ExsitKey(item) )
                    {
                        Map<String, String> ExactPlateItem = JedisUtil.getHashItems(item);

                        //取得精準號牌布控資訊中的布控卡口列表資訊,然後比較當前卡口是否在該列表中
                        String bayonetIDList = ExactPlateItem.get("bayonetID");
                        if ( bayonetIDList != null && bayonetIDList.indexOf(bayonetID) >= 0)
                        {
                            //取得布控資訊中的布控起始日期,然後判斷本次過車時間是否是在布控起始日期之後
                            String BeginDate = ExactPlateItem.get("startdate");                     
                            if ( BeginDate != null && daysOfTwoDates(BeginDate, captureTime.substring(0, 10)) >= 0 )
                            {
                                 String BeginTime = ExactPlateItem.get("starttime");
                                 String EndTime = ExactPlateItem.get("endtime");

                                 //如取得布控資訊中的布控起始和終止時間,判斷過車時間是不是在該時間區間內,若是,則繼續判斷車牌號碼資訊
                                 if ( BeginTime != null && EndTime != null && isInTimeSection(captureTime, BeginTime, EndTime))
                                 {
                                     String vlpList = ExactPlateItem.get("platenumbers");

                                     //取得布控資訊中的車牌號碼列表,判斷過車資訊中的車牌號碼是否在其中,若在,則儲存報警資訊。
                                     if ( vlpList != null && vlpList.indexOf(vehicleID) >= 0 )
                                     {
                                         //將此條過車警報資訊對應的布控資訊儲存到返回結果之中。
                                         retval.put(item, "0");
                                     }
                                 }
                            }

                        }   
                    }
                    //如果列表中的精準號牌資訊無效,則從列表中刪除之
                    else
                    {
                        JedisUtil.RemListItem(ExactPlateItems, item);

                    }           
                }
            }

            //2. 判斷比較模糊號牌布控資訊
            listBlurPlateItems = JedisUtil.getListItems(BlurPlateItems);

            if (listBlurPlateItems != null)
            {
                for ( String item : listBlurPlateItems )
                {   
                    if ( JedisUtil.ExsitKey(item) )
                    {
                        Map<String, String> BlurPlateItem = JedisUtil.getHashItems(item);

                        //取得精準號牌布控資訊中的布控卡口列表資訊,然後比較當前卡口是否在該列表中
                        String bayonetIDList = BlurPlateItem.get("bayonetID");
                        if ( bayonetIDList != null && bayonetIDList.indexOf(bayonetID) >= 0)
                        {
                            //取得布控資訊中的布控起始日期,然後判斷本次過車時間是否是在布控起始日期之後
                            String BeginDate = BlurPlateItem.get("startdate");                      
                            if ( BeginDate != null && daysOfTwoDates(BeginDate, captureTime.substring(0, 10)) >= 0 )
                            {
                                 String BeginTime = BlurPlateItem.get("starttime");
                                 String EndTime = BlurPlateItem.get("endtime");

                                 //如取得布控資訊中的布控起始和終止時間,判斷過車時間是不是在該時間區間內,若是,則繼續判斷車牌號碼資訊
                                 if ( BeginTime != null && EndTime != null && isInTimeSection(captureTime, BeginTime, EndTime))
                                 {
                                     String vlpList = BlurPlateItem.get("platenumbers");

                                     if ( vlpList == null )
                                     {
                                         continue;
                                     }

                                     String vlpinfo[] = vlpList.split("\\|");

                                     //遍歷所有模糊號牌
                                     for ( String str : vlpinfo )
                                     {
                                         //生成正則表示式
                                         str = str.replaceAll("\\*", "\\.\\*");

                                         //匹配本次過車記錄中的車牌號碼,若匹配,則將報警資訊儲存,然後結束本條布控資訊的比對。
                                         if ( vehicleID.matches(str) )
                                         {
                                            //將此條過車警報資訊對應的布控資訊儲存到返回結果之中。
                                             retval.put(item, "1");

                                             break;
                                         }

                                     }
                                 }
                            }
                        }
                    }   
                }
            }
        } catch ( Exception e ){

            System.out.println("GetAlarmInfoByLicenseNumber error : " + e);

            e.printStackTrace();
        }

        long endTime=System.currentTimeMillis();

        System.out.println("GetAlarmInfoByLicenseNumber執行時間:"+(endTime-startTime)+"ms");

        return retval;
    }
     /** 
     * 比對碰撞分析(維穩布控、車型布控、車輛類別布控)
     * @param   vehicleID   本次過車記錄中的車輛ID(格式為:車牌顏色-車牌號碼)
     * @param   captureTime 本次過車記錄中的過車時間
     * @param   bayonetID   本次過車記錄中的過車卡口ID
     * @param   vBrand      本次過車記錄中的車輛品牌
     * @param   vSubBrand   本次過車記錄中的車輛子品牌
     * @param   vMode       本次過車記錄中的車輛年款
     * @param   vType       本次過車記錄中的車輛 類別
     * @return  Map<String, String> key:TrapID(布控編號)  value:布控方式
     */
    public static Map<String, String> GetAlarmInfoByOthers(String vehicleID, String captureTime, String bayonetID, int vBrand, int vSubBrand, int vModel, int vType, int hideFace)
    {
        long startTime=System.currentTimeMillis();
        Map<String, String> retval = new HashMap<String, String>();

        List<String>    listStabilityItems = null;      //維穩布控列表
        List<String>    listVehicleTypeItems = null;    //車輛型別布控列表
        List<String>    listVehicleKindItems = null;    //車輛類別布控列表

        try {
            //1. 根據卡口資料更新首次入城資訊
            UpdateFirstEntryCityRecord(vehicleID, captureTime);

            //2. 判斷比較維穩布控資訊
            listStabilityItems = JedisUtil.getListItems(StabilityItems);

            if (listStabilityItems != null)
            {
                for ( String item : listStabilityItems )
                {   
                    if ( JedisUtil.ExsitKey(item) )
                    {
                        Map<String, String> StabilityItem = JedisUtil.getHashItems(item);

                        //取得精準號牌布控資訊中的布控卡口列表資訊,然後比較當前卡口是否在該列表中
                        String bayonetIDList = StabilityItem.get("bayonetID");
                        if ( bayonetIDList != null && bayonetIDList.indexOf(bayonetID) >= 0)
                        {
                            //取得布控資訊中的布控起始日期,然後判斷本次過車時間是否是在布控起始日期之後
                            String BeginDate = StabilityItem.get("startdate");                      
                            if ( BeginDate != null && daysOfTwoDates(BeginDate, captureTime.substring(0, 10)) >= 0 )
                            {
                                 String BeginTime = StabilityItem.get("starttime");
                                 String EndTime = StabilityItem.get("endtime");

                                 //如取得布控資訊中的布控起始和終止時間,判斷過車時間是不是在該時間區間內,若是,則繼續判斷車牌號碼資訊
                                 if ( BeginTime != null && EndTime != null && isInTimeSection(captureTime, BeginTime, EndTime))
                                 {
                                     String vlpstate = StabilityItem.get("platestate");

                                     String vlpinfo = StabilityItem.get("platenumber");

                                     //布控資訊存在錯誤時,則跳過此條布控資訊
                                     if ( vlpstate == null || vlpinfo == null )
                                     {
                                         continue;
                                     }

                                     int pstate = Integer.parseInt(vlpstate);
                                    //布控資訊中為精確號牌時,比較車牌是否一致,不一致繼續處理下一條布控資訊
                                     if ( 0 == pstate && !vehicleID.equals(vlpinfo) )
                                     {
                                         continue;
                                     }

                                    //布控資訊中為模糊號牌時,比較車牌是否匹配,不匹配繼續處理下一條布控資訊
                                     if ( 1 == pstate )
                                     {
                                         String vlpregx = vlpinfo.replaceAll("\\*", "\\.\\*");

                                         if ( !vehicleID.matches(vlpregx) )
                                         {
                                             continue;
                                         }
                                     }

                                     String ebstr = StabilityItem.get("exceptionbehavior");
                                    //布控資訊存在錯誤時,則跳過此條布控資訊
                                     if ( ebstr == null )
                                     {
                                         continue;
                                     }

                                     int ebint = Integer.parseInt(ebstr);

                                     //布控資訊中遮擋面部被設定
                                     if ( ebint % 2 == 1 )
                                     {
                                        //本次過車記錄中未遮擋面部的場合,則繼續匹配下一條布控資訊
                                        if ( hideFace != 1)
                                        {
                                            continue;
                                        }
                                     }

                                     //布控資訊中首次入城被設定
                                     if ( ebint/2 == 1 )
                                     {
                                         //取得最新判定為首次入城的時間
                                         String fectime = JedisUtil.getHashItem(vehicleFirstEntryRecords, vehicleID);

                                         //如果沒有判定過首次入城,或者被判定為首次入城的時間早於布控開始日期,則中止,然後繼續匹配下一條布控資訊
                                         if ( (null == fectime) || (daysOfTwoDates(BeginDate, fectime.substring(0, 10)) < 0) )
                                         {
                                             continue;
                                         }
                                     }

                                     String vbstr = StabilityItem.get("vBrand");
                                     String vsbstr = StabilityItem.get("vSubBrand");
                                     String vmstr = StabilityItem.get("vModel");

                                    //布控資訊存在錯誤時,則跳過此條布控資訊
                                     if ( vbstr == null || vsbstr == null || vmstr == null )
                                     {
                                         continue;
                                     }

                                     int vbint = Integer.parseInt(vbstr);                                                                            
                                     int vsbint = Integer.parseInt(vsbstr);                              
                                     int vmint = Integer.parseInt(vmstr);