java jredis

来源:互联网 发布:灰色预测软件2007 编辑:程序博客网 时间:2024/06/02 02:29
package com.cache;


import java.util.LinkedList;
import java.util.List;
import java.util.Map;



@SuppressWarnings("unchecked")
public interface CommonCache {

//缓存操作失败记录
public static final List<String> CACHE_ERROR_QUEUE = new LinkedList<String>();


/**
 * 添加缓存map
 */

public boolean addCache(String cacheKey, Map<String, String> cacheMap, CacheMapType cacheMapType);

/**
 * 删除缓存map
 */
public boolean deleteCache(String cacheKey, CacheMapType cacheMapType);

/**
* 更新缓存map
*/
public boolean updateCache(String cacheKey, Map<String, String> cacheMap, CacheMapType cacheMapType);

/**
* 获得缓存
*/
public Map<String, String> get(String cacheKey, CacheMapType cacheMapType);

/**
* 判断缓存是否存在
*/
public boolean isExists(String cacheKey, CacheMapType cacheMapType);

/**
* 判断该cacheKey是否存在缓存错误记录�?
*/
public boolean isExistsCacheError(String cacheKey, CacheMapType cacheMapType);

/**
* 缓存List
*/
public void addCacheList(String cacheKey, List cacheList, CacheMapType cacheMapType);
/**
 * 
 * @Description TODO(获取List)
 */
public List getList(String cacheKey, CacheMapType cacheMapType);
 
/**
 * 
 * @Description TODO(更新缓存List)
 * @param cacheKey
 * @param cacheList
 * @param cacheMapType
 * @return
 * @return boolean
 * @throws
 */
public void updateCacheList(String cacheKey, List cacheList, CacheMapType cacheMapType);
 
/**
 * 
 * @Description TODO(取缓存Object)
 * @param cacheKey
 * @param cacheMapType
 * @return
 * @return Object
 * @throws
 */
public Object getCachObject(String cacheKey, CacheMapType cacheMapType);
 
/**
 * 
 * @Description TODO(缓存Object)
 * @param cacheKey
 * @param object
 * @param cacheMapType
 * @return void
 * @throws
 */
public void addCacheObject(String cacheKey, Object object, CacheMapType cacheMapType);

}


package com.cache;


import java.util.List;
import java.util.Map;


import org.apache.log4j.Logger;


import redis.clients.jedis.Jedis;


@SuppressWarnings("unchecked")
public class CommonCacheImpl implements CommonCache {

protected static Logger log = Logger.getLogger(CommonCacheImpl.class);

protected Jedis jedis = null;

public Jedis getJedis(){
   jedis = new Jedis(SystemGlobals.getContextProperty("cache_ip"));
   return jedis;
}

public void close(){
   if(jedis != null){
       jedis.disconnect();
       jedis = null;
   }
}
// private Jedis jedis = new Jedis("localhost");

/**
* 添加缓存�?��存的map
* @return 缓存成功 true 缓存失败 false
*/
@Override
public boolean addCache(String cacheKey, Map<String, String> cacheMap, CacheMapType cacheMapType) {
if(cacheKey.isEmpty() || cacheMap.isEmpty()){
return false;              //键或者�?不能为空
}
String cacheKeyRule = this.cacheKeyRule(cacheKey, cacheMapType);  //处理要保存的�?
if(this.getJedis().exists(cacheKeyRule)){
return false;             //如果缓存存在也不进行缓存
}
boolean result = this.getJedis().hmset(cacheKeyRule, cacheMap).toLowerCase().equals("ok") ? true : false;
this.close();
return result;
}

    @Override
    public void addCacheList(String cacheKey, List cacheList, CacheMapType cacheMapType) {
        if(cacheKey.isEmpty() || cacheList.isEmpty()){
            return ;              //键或者�?不能为空
        }
        String cacheKeyRule = this.cacheKeyRule(cacheKey, cacheMapType);  //处理要保存的�?
        if(this.getJedis().exists(cacheKeyRule)){
            return ;             //如果缓存存在也不进行缓存
        }
        for (Object object : cacheList) {//把List存入到缓�?
//            if(null != object){
//                cacheBytes = Serializer.serialize(object);
//                jedis.set(cacheKey.getBytes(), cacheBytes);
//            }
            getJedis().lpush(cacheKeyRule, PMSUtil.isNull(object));
        }
        this.close();
    }
    
    public void addCacheObject(String cacheKey, Object object, CacheMapType cacheMapType) {
        if(cacheKey.isEmpty() || object == null)
        {
            return ;
        }
        String cacheKeyRule = this.cacheKeyRule(cacheKey, cacheMapType);  //处理要保存的�?
        if(this.getJedis().exists(cacheKeyRule)){
        deleteCache(cacheKey, CacheMapType.FPZL_DM_map0FPZL_DM); //如果缓存存在也不进行缓存
        }
        byte [] cacheBytes = new byte[]{};
        cacheBytes = Serializer.serialize(object);
        log.info("==========添加===============>>>:" + cacheKeyRule.getBytes());
        getJedis().set(cacheKeyRule.getBytes(), cacheBytes);
        this.close();
    }
    
    public Object getCachObject(String cacheKey, CacheMapType cacheMapType){
        if(cacheKey.isEmpty()){
            return null;
        }
        Object cacheObject  = null;
        String cacheKeyRule = this.cacheKeyRule(cacheKey, cacheMapType);
        byte[] bytes = new byte[]{};
        log.info("==========获取===============>>>:" + cacheKeyRule.getBytes());
        bytes = getJedis().get(cacheKeyRule.getBytes());
        log.info("================>>>key:" + bytes);
        if(bytes != null && bytes.length > 0)
        {
            cacheObject = Serializer.unserialize(bytes);
        }
        this.close();
        return cacheObject;
    }
    /**
     * 获得缓存
     * @return 缓存信息cacheList
     */
    @Override
    public List getList(String cacheKey, CacheMapType cacheMapType) {
        if(cacheKey.isEmpty()){
            return null;
        }
        List cacheList = null;
        String cacheKeyRule = this.cacheKeyRule(cacheKey, cacheMapType);
        log.info("=======>>>取key:" + cacheKeyRule);
        cacheList = getJedis().lrange(cacheKeyRule, 0, -1);
        this.close();
        return cacheList.size() > 0 ? cacheList : null;
    }
    
    public void updateCacheList(String cacheKey, List cacheList, CacheMapType cacheMapType){
        if(cacheKey.isEmpty() || cacheList.isEmpty()){
                return ;              //键或者�?不能为空
        }
        for (Object object : cacheList) {//把List存入到缓�?
            getJedis().lpush(cacheKey, PMSUtil.isNull(object));
        }
        this.close();
     }

/**
* 删除缓存
* @return 删除陈功true 删除失败false
*/
@Override
public boolean deleteCache(String cacheKey, CacheMapType cacheMapType){
if(cacheKey.isEmpty()){
return false;
}
String cacheKeyRule = this.cacheKeyRule(cacheKey, cacheMapType);
boolean result = this.getJedis().del(cacheKeyRule) == 0 ? false : true;
this.close();
return result;
}


/**
* 获得缓存
* @return 缓存信息cacheMap
*/
@Override
public Map<String, String> get(String cacheKey, CacheMapType cacheMapType) {
if(cacheKey.isEmpty()){
return null;
}
Map<String, String> cacheMap = null;
String cacheKeyRule = this.cacheKeyRule(cacheKey, cacheMapType);
cacheMap = this.getJedis().hgetAll(cacheKeyRule);
this.close();
return cacheMap.size() > 0 ? cacheMap : null;
}

/**
* 更新缓存map
* @param cacheMap
* @return 更新成功true 更新失败false
*/
@Override
public boolean updateCache(String cacheKey, Map<String, String> cacheMap, CacheMapType cacheMapType){
if(cacheKey.isEmpty() || cacheMap.isEmpty()){
return false;              //键或者�?不能为空
}
String cacheKeyRule = this.cacheKeyRule(cacheKey, cacheMapType);
boolean result = this.getJedis().hmset(cacheKeyRule, this.turnChanage(cacheMap)).toLowerCase().equals("ok") ? true : false;
this.close();
return result;
}

/**
* 判断缓存是否存在
* @return 存在true 不存在false
*/
@Override
public boolean isExists(String cacheKey, CacheMapType cacheMapType){
if(cacheKey.isEmpty()){
return false;
}
String cacheKeyRule = this.cacheKeyRule(cacheKey, cacheMapType);
boolean result = this.getJedis().exists(cacheKeyRule);
this.close();
return result ;
}

/**
* 定义cacheKey的规�?
*/
protected String cacheKeyRule(String cacheKey,CacheMapType cacheMapType){
String cacheType = cacheMapType.name();
String[] fields = cacheType.split("0");
return fields[0] + "_" + cacheKey + "_" + fields[1];
}

/*
* 转换cacheMap的类�?
*/
protected Map turnChanage(Map cacheMap){
if(cacheMap != null && cacheMap.size() > 0){
for(Object o : cacheMap.keySet()){
if(cacheMap.get(o) != null ){
cacheMap.put(o, cacheMap.get(o).toString());
}
}
}
return cacheMap;
}


/**
* 判断该cacheKey是否存在缓存错误记录�?
* @param cahcheKey
* @param cacheMapType
* @return
*/
@Override
public boolean isExistsCacheError(String cacheKey, CacheMapType cacheMapType) {
boolean result = false;
String cacheKeyRule = this.cacheKeyRule(cacheKey, cacheMapType);
if(CACHE_ERROR_QUEUE.contains(cacheKeyRule)){
result = true;
}
return result;
}

}



package com.cache;


import java.util.List;
import java.util.Map;


@SuppressWarnings("unchecked")
public class CommonCacheImplWrap extends CommonCacheImpl {


/**
* 添加缓存�?��存的map
* @return 缓存成功 true 缓存失败 false
*/
@Override
public boolean addCache(String cacheKey, Map<String, String> cacheMap, CacheMapType cacheMapType){
boolean result = false;
try{
result = super.addCache(cacheKey,cacheMap, cacheMapType);
}catch(Exception e){
log.info("添加缓存异常" + e);
}
return result;
}

/**
* 缓存List
*/
@Override
public void addCacheList(String cacheKey, List cacheList, CacheMapType cacheMapType){
        try{
            log.info("添加内容:" + cacheList);
             super.addCacheList(cacheKey,cacheList, cacheMapType);
        }catch(Exception e){
            log.info("添加缓存异常" + e);
        }
    }

/**

* @Description TODO(存Object)
* @param cacheKey
* @param cacheList
* @param cacheMapType
* @return void
* @throws
*/
@Override
public void addCacheObject(String cacheKey, Object object, CacheMapType cacheMapType){
        try{
             super.addCacheObject(cacheKey,object, cacheMapType);
        }catch(Exception e){
            log.info("添加缓存异常" + e);
        }
    }

  /**
   * 获取缓存Object
   */
  @Override
public Object getCachObject(String cacheKey, CacheMapType cacheMapType){
      Object result = null;
      try{
          result = super.getCachObject(cacheKey,cacheMapType);
          log.debug("获取缓存:" + result);
      }catch(Exception e){
          log.info("缓存获取异常" + e);
      }
      return result;
  }
    /**
     * 更新List
     */
   @Override
public void updateCacheList(String cacheKey, List cacheList, CacheMapType cacheMapType){
        try{
            super.updateCacheList(cacheKey, cacheList, cacheMapType);
            this.removeError(cacheKey,cacheMapType);
        }catch(Exception e){
            this.addError(cacheKey, e, cacheMapType);
        }
    }
   
   /**
    * 获取缓存List
    */
   @Override
public List getList(String cacheKey, CacheMapType cacheMapType){
       List result = null;
       try{
           result = super.getList(cacheKey,cacheMapType);
           log.debug("获取缓存:" + result);
       }catch(Exception e){
           log.info("缓存获取异常" + e);
       }
       return result;
   }
/**
* 删除缓存
*/
@Override
public boolean deleteCache(String cacheKey, CacheMapType cacheMapType){
boolean result = false;
try{
result = super.deleteCache(cacheKey, cacheMapType);
}catch(Exception e){
this.addError(cacheKey, e, cacheMapType);
}
return result;
}

/**
* 更新缓存map
* @return 更新成功true 更新失败false
*/
@Override
public boolean updateCache(String cacheKey, Map<String, String> cacheMap, CacheMapType cacheMapType){
boolean result = false;
try{
result = super.updateCache(cacheKey, cacheMap, cacheMapType);
this.removeError(cacheKey,cacheMapType);
}catch(Exception e){
this.addError(cacheKey, e, cacheMapType);
}
return result;
}

/**
* 获得缓存
* @return 缓存信息cacheMap
*/
@Override
public Map<String, String> get(String cacheKey, CacheMapType cacheMapType){
Map<String, String> result = null;
try{
result = super.get(cacheKey,cacheMapType);
log.debug("获取缓存:" + result);
}catch(Exception e){
log.info("缓存获取异常" + e);
}
return result;
}

/**
* 判断缓存是否存在
* @return 存在true 不存在false
*/
@Override
public boolean isExists(String cacheKey, CacheMapType cacheMapType){
return super.isExists(cacheKey, cacheMapType);
}

/**
* 保存缓存失败记录
* @param e
* @param cacheKey
*/
protected void addError(String cacheKey,Exception e, CacheMapType cacheMapType){
log.info("缓存操作异常,本次操作存入异常记录中" + e);
String cacheKeyRule = super.cacheKeyRule(cacheKey, cacheMapType);  //处理异常的键
if(!CACHE_ERROR_QUEUE.contains(cacheKeyRule)){
CACHE_ERROR_QUEUE.add(cacheKeyRule);
}
}

/**
* 移除缓存失败记录
* @param e
* @param cacheKey
*/
protected void removeError(String cacheKey, CacheMapType cacheMapType){
String cacheKeyRule = super.cacheKeyRule(cacheKey, cacheMapType);  //处理异常的键
CACHE_ERROR_QUEUE.remove(cacheKeyRule);
}
}



package com.cache;


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * 
* @ClassName Serializer
* @Description TODO(序列化器)
* @company 中润四方
* @author guochuanjing
* @date Aug 1, 2012 5:34:31 PM
 */
public final class Serializer
{
    private static final Logger logger = LoggerFactory.getLogger(Serializer.class);


    /**
     * 序列化�?
     * @param object �?��序列化的对象�?
     * @return 字节数组�?
     */
    public static final byte[] serialize(Object object)
    {
        ObjectOutputStream oos = null;
        ByteArrayOutputStream baos = null;
        try
        {
            baos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(baos);
            oos.writeObject(object);
            return baos.toByteArray();
        }
        catch(Exception ex)
        {
            logger.error("序列化对象失败", ex);
        }
        finally
        {
            if(oos != null)
            {
                try {
                    oos.close();
                }catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(baos != null)
            {
                try {
                    baos.close();
                }catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }


    /**
     * 反序列化�?
     * @param bytes 字节数组�?
     * @return 反序列化后的对象�?
     */
    public static final Object unserialize(byte[] bytes)
    {
        ByteArrayInputStream bais = null;
        ObjectInputStream ois = null;
        try
        {
            bais = new ByteArrayInputStream(bytes);
            ois = new ObjectInputStream(bais);
            return ois.readObject();
        }
        catch(Exception ex)
        {
            logger.error("反序列化对象失败", ex);
        }
        finally
        {
            if(ois != null)
            {
                try {
                    ois.close();
                }catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(bais != null)
            {
                try {
                    bais.close();
                }catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
}



package com.cache;




public enum CacheMapType {
/**
* 数字0前对应的是cacheMap信息数字0后对应的是缓存键的字�?
*/
user_info_map0user_id,    
taxpayer_info_map0tax_register_no,    
taxpayer_info_map0tax_taxpayer_id,     
invoice_config_info_map0invoice_code,   
exception_taxpayers_map0exception_taxpayers_tax_register_no, 
trueInvoice_config_info_map0true_invoice_code, 
trueInvoice_config_info_map0true_trade_code, 
trueInvoice_config_info_map0true_invoice_type_code,
invoice_datavalidate_map0invoice_validate_info, 
FPZL_DM_map0FPZL_DM,
lose_invoice_map0tax_register_no,  
IsInitLoseInvoice0tax_register_no,
IsInitExceptionTaxpayers0IsInitExceptionTaxpayers,
entrustisqueryByToday0tax_register_no,
entrustDocumentsList0tax_register_no, 
useredCarNameList0useredCarNameList,
pdf_info0fm
}



package com.zrsf.dzfp.cache.util;


import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


import net.sf.json.JSONObject;


import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;


@SuppressWarnings("unchecked")
public class PMSUtil {
public static final String MACHINE_ID = "CHNBS-NETINVOICE";
public static final String AES_KEY = "0123456789ABCDEF";
/**
* �� s ���� BASE64 ���� 
*/ 
public static String getBASE64(String s) {
if (PMSUtil.isEmpty(s))
return null;
return (new BASE64Encoder()).encode(s.getBytes());
}


/**
* �� BASE64 ������ַ� s ���н���
*/
public static String getFromBASE64(String s) {
if (PMSUtil.isEmpty(s))
return null;
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b);
} catch (Exception e) {
return null;
}

/**
* ȡ��Ȩ��(ʱ���ȡ��8λ)
* @return
*/
public static String getAuthorizationCode(){
String cont=System.currentTimeMillis()+"";
return cont.substring(5,13);
}
/**
* ��������
* @param seq ��ݿ�seq
* @param length ���鳤��
* @return
*/
public static String getInstrumentNumber(String seq,int length){
if(!isEmpty(isNull(seq))){
if(seq.length()<length){
StringBuffer sub=new StringBuffer();
for(int i=0;i<length-seq.length();i++){
sub.append("0");
}
sub.append(seq);
return sub.toString();
}
}
return seq;
}
/**
* ������������֤�Ƿ������ַ�

* @param s
*            ����֤
* @param zz
*            �������
* @return
*/
public static boolean isNum(String s, String zz) {
Pattern pattern = Pattern.compile(zz);
Matcher isNum = pattern.matcher(s);
return isNum.matches();
}


/**
* �ж��ַ��Ƿ��ڔ��M�У��Hᘌ����ַ��M

* @param str
* @param arr
* @return
*/
public static boolean inArray(String str, ArrayList arr) {
for (int i = 0; i < arr.size(); i++) {
if (str.equals(arr.get(i))) {
return true;
}
}
return false;
}


/**
* �ж��ַ��Ƿ��ڔ��M�У��Hᘌ����ַ��M������ִ�Сд

* @param str
* @param arr
* @return
*/
public static boolean inArrayNCase(String str, ArrayList arr) {
for (int i = 0; i < arr.size(); i++) {
if (str.equalsIgnoreCase((String) arr.get(i))) {
return true;
}
}
return false;
}


/**
* ���M�D�Q���ַ�ͨ�^�ָ����M���B�ӣ��Hᘌ����ַ��M

* @param glue
* @param arr
* @return
*/
public static String implode(String glue, ArrayList arr) {
String implodeStr = "";
for (int i = 0; i < arr.size(); i++) {
if (i == 0) {
implodeStr += (String) arr.get(i);
} else {
implodeStr += glue + (String) arr.get(i);
}
}
return implodeStr;
}


/**
* �@ȡMAP�������I�����ַ��M

* @param mp
* @return
*/
public static ArrayList<String> mapKeys(Map mp) {
ArrayList<String> arr = new ArrayList<String>();
Iterator it = mp.keySet().iterator();
while (it.hasNext()) {
// System.out.println("====================="+it.next());
arr.add((String) it.next());
}
return arr;
}

/**
* �@ȡMAP�������I�����ַ��M

* @param mp
* @return
*/
public static String mapKey(Map map) {
StringBuffer sb=new StringBuffer();
if(null!=map){
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry e = (Map.Entry) it.next();
sb.append(e.getKey()).append("=").append(e.getValue()).append("&");
}
return sb.toString();
}
else{
return "";
}
}


/**
* �ж���MAP���Ƿ���ڴ˼�

* @param key
*            ����
* @param mp
*            MAP����
* @return
*/
public static boolean inMap(String key, Map mp) {
ArrayList li = PMSUtil.mapKeys(mp);
boolean flag = false;
for (int i = 0; i < li.size(); i++) {
String tmp = (String) li.get(i);
if (key.equals(tmp)) {
flag = true;
break;
}
}
return flag;


}


/**
* �@ȡJSONObject�������I�����ַ��M

* @param mp
* @return
*/
public static ArrayList jsonObjectKeys(JSONObject object) {
ArrayList arr = new ArrayList();
Iterator it = object.keys();
while (it.hasNext()) {
arr.add(it.next());
}
return arr;
}


/**
* �ж���JSONObject ���Ƿ���ڴ˼�

* @param key
*            ����
* @param mp
*            MAP����
* @return
*/


public static boolean inJSON(String key, JSONObject object) {
ArrayList li = PMSUtil.jsonObjectKeys(object);
boolean flag = false;
for (int i = 0; i < li.size(); i++) {
String tmp = (String) li.get(i);
if (key.equals(tmp)) {
flag = true;
break;
}
}
return flag;


}


/**
* �������ַ�

* @param length
*            �ַ���
* @return
*/
public static String randomStr(int length) {
String str = "";
String source = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
String[] s = source.split(",");
for (int i = 0; i < length; i++) {
int rand = (int) (Math.random() * 35);
str += s[rand];
}
return str;
}


/**
* ���ؿ��ַ�

* @param str
* @return

*/
public static String isNull(Object str) {
if (isEmpty(String.valueOf(str))) {
return "";
} else {
return String.valueOf(str);
}
}


/**
* �ж��ַ��Ƿ�Ϊ��

* @param str
* @return �� true �ǿ� false
*/
public static boolean isEmpty(String str) {
if (str != null && !"".equals(str) && !"null".equals(str)) {
return false;
} else {
return true;
}
}


/**
* ȥ���ַ�ͷ�ͽ�β�Ŀո�

* @param str
* @return
*/
public static String trim(String str) {
if (str.charAt(0) == ' ') {
str = str.substring(1, str.length());
}
if (str.charAt(str.length() - 1) == ' ') {
str = str.substring(0, str.length() - 1);
}
if (str.charAt(0) == ' ' || str.charAt(str.length() - 1) == ' ') {
str = PMSUtil.trim(str);
}


return str;
}


/**
* �ж��Ƿ����ַ�����
*/
public static boolean isStringArr(Object obj) {
if (obj instanceof String[]) {
return true;
} else {
return false;
}
}


// /**
// * �ָ��ַ�
// * @param str
// * @param split
// * @return
// */
// public static String[] split(String str,String split){
//
//
// }
//
// public static Strring[] _split()


public static String addSlashes(String str) {
str = str.replaceAll("'", "''"); // SQL-92��׼
// str = str.replaceAll("\"", "\\\\\"");
return str;
}


public static String stripSlashes(String str) {
str = str.replaceAll("''", "'");// SQL-92��׼
// str = str.replaceAll("\\\\\"", "\"");
return str;
}




/**
* ���������ȡ�ַ�ǰ����

* @param info
*            �����ַ�
* @param jsf
*            �����
* @return
*/
public static String getRequestInfo(String info, String jsf) {
int i = isNull(info).indexOf(jsf);
if (i > 0) {
return isNull(info).substring(0, i);
} else {
return info;
}
}


public static boolean verifyIDCard(String idCard) {
boolean ok = false;
if (idCard.length() == 18) {
char idCards[] = idCard.toCharArray();
int iS = 0;
int iW[] = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
char szVerCode[] = new char[] { '1', '0', 'X', '9', '8', '7', '6',
'5', '4', '3', '2' };
for (int i = 0; i < 17; i++) {
iS += (idCards[i] - '0') * iW[i];
}
int iY = iS % 11;
ok = szVerCode[iY] == idCards[17];
} else if (idCard.length() == 15) {
ok = true;
}
return ok;
}


/**

* @Description TODO(2���ַ��С�Ƿ�����)
* @param str1
* @param str2
* @return
* @return boolean
* @throws
*/
public static boolean comparingString(String str1, String str2){
   Long str1Long = Long.valueOf(str1);
   Long str2Long = Long.valueOf(str2);
  System.out.println((str2Long - str1Long));
  if((str2Long - str1Long) == 1){
      return true;
  }
   return false;
}
/**
* ���ֱ���2ΪС��
* @Description TODO(��һ�仰�������ļ�)
* @param source
* @param n
* @return
* @return double
* @throws
*/
    public static double toTwoPointDouble(String source){
        double result=0;
        if(source==null || "".equals(source)){
            source="0";
        }
        source=source.replaceAll(",","");
        BigDecimal big = new BigDecimal(source);
        big = big.setScale(2,BigDecimal.ROUND_HALF_UP);
        result=big.doubleValue();
        return result;
     }
    
    /**
     * 
     * @Description TODO(doubleת����2ΪСʱ��double)
     * @param source
     * @return
     * @return double
     * @throws
     */
    public static double toNPointDouble(double source){
        BigDecimal big = new BigDecimal(source);
        big = big.setScale(2,BigDecimal.ROUND_HALF_UP);
        source=big.doubleValue();
        return source;
    }
    
    /**
     * 
     * @Description TODO(��doubleת�����ַ�)
     * @param source
     * @return
     * @return String
     * @throws
     */
    public static String toTwoPointString(double source){
        NumberFormat rmbFormat = NumberFormat.getInstance();
        rmbFormat.setMinimumFractionDigits(2);
        rmbFormat.setMaximumFractionDigits(2);
        return (rmbFormat.format(source)).replaceAll(",","");
     }
    /**
     * 
     * @Description TODO(��������ȡ��)
     * @param s
     * @return
     * @return String
     * @throws
     */
    public static String toIntOfString(String s){
        BigDecimal b = new BigDecimal(s).setScale(0, BigDecimal.ROUND_HALF_UP);
        return b.toString();
    }
    
/**

* @Description TODO(��ȡ·����Ϣ)
* @param taxRegisterNo
* @return
* @return String
* @throws
*/
public static String getRoute(String taxRegisterNo){
//    String route = null;
//   if(null != taxRegisterNo){
//       route = taxRegisterNo.substring(0, 2);
//   }
   return "44";
}
public static void main(String[] args) {
// Map<String, Long> m = new TreeMap<String, Long>();
// for (long i = 10000L; i < 99999L; i++) {
// String code = String.valueOf(i);
// String key = String.valueOf(code.hashCode() % 20);
// if (key.length() >= 2)
// key = key.substring(0, 2);
// else {
// while (key.length() < 2) {
// key = new StringBuffer("0").append(key).toString();
// }
// }
// if (m.containsKey(key)) {
// long value = m.get(key);
// m.put(key, value + 1);
// } else {
// m.put(key, 1L);
// }
// System.out.println(key);
// }
// System.out.println(m.toString());
//    System.out.println(comparingString("2222222221","2222222222"));
System.out.println(getInstrumentNumber("41",6));
}
}


0 0
原创粉丝点击