1. 程式人生 > >2018.07.11 新增郵件號段管理及查詢後臺管理模組

2018.07.11 新增郵件號段管理及查詢後臺管理模組

新增郵件號段管理及查詢後臺管理模組
wawe
[email protected]

MySQL
-- 後臺選單
select * from TB_GLOBAL_MENUS t ;
新增SID:10033	10034

-- 角色選單包
select * FROM tb_global_role_r_menus t;
新增SID:1550	1551


新增:jar包:

新增指令碼:/shipping-platform/src/configAli/MAXsequences.lua
新增jsp頁面:shipping-platform\web\pages\mailNumQuery\mailSegmentQuery.jsp  ---jsp名及包名
新增Java程式碼:shipping-platform\src\com\teamsun\oms\internat\action\MailSegmentQueryAction--Java類名


package com.teamsun.oms.internat.action;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.roc.japp.core.mybatis.dialect.Page;
import com.teamsun.common.help.AppServiceHelper;
import com.teamsun.common.util.CopyUtils;
import com.teamsun.common.web.SuperBaseAction;

import net.sf.json.JSONObject;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * 郵件號段查詢
 * @author XING
 *
 */
@UrlBinding("/mail/segmentquery.action")
public class MailSegmentQueryAction extends SuperBaseAction {

private static final Log _log = LogFactory.getLog(PrintMngAction.class);
private static final Log logeer = LogFactory.getLog(MailSegmentQueryAction.class);
private static JedisPool jedisPool;

	@DefaultHandler
	 public Resolution index(){
		return new ForwardResolution("/pages/mailNumQuery/mailSegmentQuery.jsp");
	}
	

	
	//-----------
	public static JedisPool getJredis(){
		if(jedisPool==null){
			JedisPoolConfig poolConfig = new JedisPoolConfig();
			poolConfig.setMaxIdle(10);
			poolConfig.setMaxTotal(2000);
			poolConfig.setMaxWaitMillis(9000);
			poolConfig.setTestOnBorrow(false);
		    //jedisPool=new JedisPool(poolConfig,"r-2ze5d836dbca4f64.redis.rds.aliyuncs.com",6379,9000,"ShipRedis654321",2);
		    jedisPool=new JedisPool(poolConfig,"47.95.49.40",6379,9000,"ShipRedis654321",2);
		}
		return jedisPool;
	}
	
    public Resolution findByPage() {
    	
    	
    		String[] sequ=new String[16];
    		sequ[0]="GETMAIL:SQ_LY_API_MAILNUM";
    		sequ[1]="GETMAIL:SQ_LM_API_MAILNUM";
    		sequ[2]="GETMAIL:SQ_LZ_API_MAILNUM";
    		sequ[3]="GETMAIL:SQ_A_API_MAILNUM";
    		sequ[4]="GETMAIL:SQ_CX_API_MAILNUM";
    		sequ[5]="GETMAIL:SQ_LH_API_MAILNUM";
    		sequ[6]="GETMAIL:SQ_EZ_ES_MAILNUM";
    		sequ[7]="GETMAIL:SQ_AS_API_MAILNUM";
    		sequ[8]="GETMAIL:SQ_LF_API_MAILNUM";
    		sequ[9]="GETMAIL:SQ_EZ_KR_MAILNUM";
    		sequ[10]="GETMAIL:SQ_EV_API_MAILNUM";
    		sequ[11]="GETMAIL:SQ_RX_API_MAILNUM";
    		sequ[12]="GETMAIL:SQ_API_MAILNUM";
    		sequ[13]="GETMAIL:SQ_EA_API_MAILNUM";
    		sequ[14]="GETMAIL:SQ_LS_API_MAILNUM";
    		sequ[15]="GETMAIL:SQ_CY_API_MAILNUM";
    		Jedis jedis = getJredis().getResource();
    		InputStream in = MailSegmentQueryAction.class.getClassLoader().getResourceAsStream("MAXsequences.lua");
    		BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    		StringBuilder sb = new StringBuilder();
    		String line = null;
    		String mailnum = null;
    		final List<Map<String, String>> list=new ArrayList<Map<String,String>>();
    		try {
    			while ((line = reader.readLine()) != null) {
    				sb.append(line + "\n");
    			}
    			String hash = jedis.scriptLoad(sb.toString());
    			//判斷查詢的郵件段號欄位是否為空
    			if(sequ.length>0){
    				for (int i = 0; i < sequ.length; i++) {//迴圈拿取郵件號並放在map中,最後放在一個大的list中
    					Map<String, String> map=new HashMap<String, String>();
    					mailnum = String.valueOf(jedis.evalsha(hash, 1, sequ[i]));
    					List<String> result = Arrays.asList(mailnum.split(":"));
    					
    					String current = result.get(1).toString();
    					if (current.length()<8) {
							if(current.length()==7){
								current="0"+current;
							}
							if(current.length()==6){
								current="00"+current;
							}
							if(current.length()==5){
								current="000"+current;
							}
							if(current.length()==4){
								current="0000"+current;
							}
							if(current.length()==3){
								current="00000"+current;
							}
							if(current.length()==2){
								current="000000"+current;
							}
							if(current.length()==1){
								current="0000000"+current;
							}
						}
    					
    					String min = result.get(3).toString();
    					if (min.length()<8) {
							if(min.length()==7){
								min="0"+min;
							}
							if(min.length()==6){
								min="00"+min;
							}
							if(min.length()==5){
								min="000"+min;
							}
							if(min.length()==4){
								min="0000"+min;
							}
							if(min.length()==3){
								min="00000"+min;
							}
							if(min.length()==2){
								min="000000"+min;
							}
							if(min.length()==1){
								min="0000000"+min;
							}
						}
    					map.put("numtype", result.get(0).toString());
    					map.put("currentnum", current);
    					map.put("maxnum", result.get(2).toString());
    					map.put("minnum", min);
    					list.add(map);
    				}
    				
    			}
    			
    			
    			
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			try {
    				if (jedis != null) {
    					jedis.close();
    				}
    				in.close();
    			} catch (IOException e) {
    				e.printStackTrace();
    				logeer.error(e);
    			}
    		}
    	
    	
    	
        return findByPage(new DoPage(){
            
            @Override
            public JSONObject doInitPage(JSONObject jsonData, Page page) {
                Map<String, Object> params = CopyUtils.copyMap(getQm());
                _log.debug("##########params=" + params);
               /* 
                List pageList = AppServiceHelper.getSuperService().selectByPage("com.teamsun.oms.entity.Role.find", params, page);
               */
                jsonData.put(ROWS, list);
                return jsonData;
            }
            
        });
    }
	
	
	
}