⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mailorderresend.java

📁 电信的网厅的整站代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
package com.doone.fj1w.fjmgr.order.mailorder;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Set;
import java.util.Date;
import java.util.Vector;
import java.util.Map;

import com.doone.data.DacClient;
import com.doone.data.DataRow;
import com.doone.data.DataTable;
import com.doone.fj1w.fj1w.selfquery.adsl.Remoteadsl;
import com.doone.fj1w.fj1w.selfquery.onesixeight.Remoteonese;
import com.doone.fj1w.fj1w.selfquery.comdeal.Getforwinfo;
import com.doone.fj1w.fj1w.selfquery.querylongdis.Remotequerylongdis;
import com.doone.fj1w.fj1w.selfquery.mailorder.Remotemailorder;
import com.doone.fj1w.fj1w.selfquery.mailorder.SendmailorderThr;
import com.doone.fj1w.fj1w.selfquery.mailorder.TL_MailLog;
import com.doone.fj1w.common.ServiceFactory;
import com.doone.fj1w.common.WSClientThird;
import com.doone.iossp.EMessage;
import com.doone.iossp.FormBody;
import com.doone.util.FileLogger;
import org.apache.soap.rpc.Parameter;
import  com.doone.fj1w.fj1w.selfquery.mailorder.*;
public class MailOrderReSend {

	
	protected static DacClient _dac = null;
	static {
		try {
			_dac = new DacClient();
		} catch (Exception rux) {
			FileLogger.getLogger().warn("连接数据库异常!");
		}
	}	
	private static String getOrderSort(String name){
		try {
			Hashtable servistate = new Hashtable();
			servistate.put("帐单","1");
			servistate.put("长途清单","2");
			servistate.put("上网清单","3");
			servistate.put("信息费清单","4");
			if(servistate.get(name)!=null){
				return servistate.get(name).toString();
			}else{
				return "";
			}
		} catch (NumberFormatException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return "";
	}
	private static String sqlfaultcountadd = "update tf_mailorder set faultcount=faultcount+1  where MAILORDERID=? and state='E'";	
	public static String getSendmailorder(String month,String userid,String account,String phonenum,String ordersort,String email){
        int succnum = 0;
        int totalnum = 0;
        String S_MAILLOG= "";
	  	try{
	  		//1、读取数据库
	  		if(month==null || month.equals("") || month.length()!=6)
	  			return "err-month";
	  		S_MAILLOG= 
				   "select b.MAILORDERID,b.ordersort,b.faultcount ,a.productid, a.phonenum, a.citycode, c.email,c.ACCOUNTID"+ 
				   "  from tf_andcustrela a, tf_mailorder b, tf_custinfoweb c"+ 
				   "  where not exists (select 1 from tl_maillog_"+month+" d where d.state='E' and d.mailorderid=b.mailorderid)"+ 
		           "  and a.andcustrelaid = b.andcustrelaid and a.userid = c.userid" +
				   "  and c.userid='"+userid+"' and a.phonenum ='"+phonenum+"' and b.startmonth <= "+month+" and b.endmonth >= "+month+" and b.ordersort='"+ordersort+"' "+
				   "  and a.state = 'E' and b.state = 'E' and c.state = 'E'"+ 
				   "  and c.email='"+email+"'";
//System.out.println("getSendmailorder-S_MAILLOG:"+S_MAILLOG);
	  		_dac.beginTransaction(10000);
	  		DataTable ret = _dac.executeQuery(S_MAILLOG);
	        _dac.endTransaction(true);	

			//2、发送邮件
	  		WSClientThird wt = new WSClientThird();
	  		Remotequerylongdis _clongdis = new Remotequerylongdis();
	        Remoteadsl _cadsl = new Remoteadsl();      
	        Remoteonese _conese = new Remoteonese(); 
	        
	  		String body = "";

	        if(ret!=null && ret.getRows().getCount()>0){
	        	totalnum = ret.getRows().getCount();
		        if(ret.getRows().getCount()<1){
		        	return "0";
		        }
		        for(int t=0;t<ret.getRows().getCount();t++){
			  		DataTable dtbill = null; 
			  		FormBody fbresult = null; 	
			  		
		        	DataRow dr =  ret.getRow(t);
		        	//param:String toAddr,String subject, String body, String mime
		        	String toAddr = dr.getString("email");
		        	String accountid = dr.getString("ACCOUNTID");
		        	String subject = "帐单寄送";
		        	
		        	//1:帐单 2:长途清单 3:adsl清单
		        	String mailorderid = dr.getString("MAILORDERID");
		        	String ordertype = dr.getString("ordersort");
		        	String faultcount = dr.getString("faultcount");
		        	String prodno = dr.getString("phonenum");
		        	String citycode = dr.getString("citycode");	  	        	
		        	String productid = dr.getString("productid");
		        	//转换lan帐号为产品号
		        	String _prodnbr = "";
		        	Hashtable _paramHT = new Hashtable();
		        	if(ordertype!=null && ordertype.equals("1")){
		        		//调用帐单接口
		        		Vector params = new Vector();
						if(prodno.indexOf("@")<0){
							_prodnbr = prodno;
						}else{
							String methodname = "ServiceCall_APP";
							params.clear();
							params.addElement(new Parameter("CITYCODE", String.class, citycode, null));
							params.addElement(new Parameter("pServiceName", String.class, "Webso_getBILLbyNbr", null));
							_paramHT.put("I_NBR",prodno);
							params.addElement(new Parameter("I_NBR", Hashtable.class, _paramHT, null));
							String getPhone = wt.QueryThird(methodname, params);
												
							if(getPhone!=null){
								FormBody _formbody = new FormBody(); 
								_formbody.fromXML(getPhone);
			        	    	
								if(_formbody!=null){
									String _sussGetPhone = _formbody.getString("O_result");
									int i_suss = Integer.parseInt(_sussGetPhone);
									if(i_suss==0){
										  _prodnbr = _formbody.getString("O_acc_nbr");
									}
								}
							}				
						}
						
						if(_prodnbr==null || _prodnbr.equals(""))continue;		        		
		        	    String methodname = "Inter_BILL";
		        	    params = new Vector();
		        	    params.clear();
		        	    String sparabill = citycode.substring(1,4)+" "+_prodnbr+" "+month;
		        	    params.addElement(new Parameter("citycode", String.class, citycode, null));
		        	    if((citycode!=null && citycode.equals("0595"))){
		        	    	params.addElement(new Parameter("trade", String.class, "W0001", null));
		        	    }else{
		        	    	params.addElement(new Parameter("trade", String.class, "S0001", null));
		        	    }
		        	    params.addElement(new Parameter("param", String.class, sparabill, null));
		        	    params.addElement(new Parameter("type", String.class, "5", null));
		        	    String sbillres = wt.QueryThird(methodname, params);
		        	    if(sbillres!=null){
		        	    	EMessage _ebill = new EMessage(sbillres);
		        	    	dtbill = _ebill.getDataTableBody();
		        	    }

		        		if(dtbill==null){	        			
		        			//对异常的处理,当出现错误信息时,往记录表中更新记录
		        			if(Integer.parseInt(faultcount)<9){	      			
		        				Remotemailorder.updsendstate(sqlfaultcountadd,mailorderid);
		        			}
		        			continue;
		        		}else{ 
	        				body = getFZAccoBillPartInfo(citycode,prodno,month,dtbill);
		        			if(body!=null && body.equals("0")){
		        				body="";
		        			}
		   		        }
		        	}
		        	
		        	if(ordertype!=null && ordertype.equals("2")&& productid!=null && !productid.equals("3")){
		        		//调用长途清单接口
		        		String sticket = _clongdis.getticketmore(month,citycode,prodno,"","");//后面两个参数原来是指定起始结束时间的,实际没有用到
		        		//FileLogger.getLogger().info("调用长途清单接口sticket返回结果:" + sticket);
		        		if(sticket!=null && !sticket.equals("notable") && !sticket.equals("execerr")){
		        			EMessage _eticket = new EMessage(sticket);
		        			dtbill = _eticket.getDataTableBody();
		        		}
		        		//FileLogger.getLogger().info("调用长途清单接口dtbilllongdis返回结果:" + dtbill);
		        		if(dtbill==null){	        			
		        			//对异常的处理,当出现错误信息时,往记录表中更新记录
		        			if(Integer.parseInt(faultcount)<9){	        				
		        				Remotemailorder.updsendstate(sqlfaultcountadd,mailorderid);
		        			}
		        			continue;
		        		}else{
		        			//画出长途清单
		        			String ipnum = _clongdis.gettb_ticketIPnum(month,citycode,prodno,"","");
		        			String moneysum  = _clongdis.gettb_ticketsum(month,citycode,prodno,"","");
		        			if(ipnum==null || ipnum.equals(""))
		        				ipnum = "0";		        			
		        			if(moneysum==null || moneysum.equals(""))
		        				moneysum = "0";
	        				body = getTablelongdisInfo(citycode,month,prodno,dtbill,ipnum,moneysum); 
		        			if(body!=null && body.equals("0")){
		        				body="";
		        			}		        			
		        		}
		        	}	
		        	
		        	if(ordertype!=null && ordertype.equals("3")){
		        		//调用adsl清单接口
		        		String sticketadsl = _cadsl.getticketadslmore(month,citycode,prodno,"","");
		        		//FileLogger.getLogger().info("调用adsl清单接口返回结果:" + sticketadsl);
		        		if(sticketadsl!=null && !sticketadsl.equals("notable") && !sticketadsl.equals("execerr")){
		        			EMessage _eticketadsl = new EMessage(sticketadsl);
		        			dtbill = _eticketadsl.getDataTableBody();
		        		}
		        		//FileLogger.getLogger().info("调用adsl清单接口dtbilladsl返回结果:" + dtbill);
		        		if(dtbill==null){	        			
		        			//对异常的处理,当出现错误信息时,往记录表中更新记录
		        			if(Integer.parseInt(faultcount)<9){	        				
			        			Remotemailorder.updsendstate(sqlfaultcountadd,mailorderid);
		        			}
		        			continue;
		        		}else{	        			
		        			//画出帐单表格
		        			body = getTableadslInfo(citycode,month,prodno,dtbill); 
		        			if(body!=null && body.equals("0")){
		        				//continue;
		        				body="";
		        			}		        			
		        		}
		        	}		   
		        	
		        	if(ordertype!=null && ordertype.equals("4")){
		        		//调用信息费清单接口
		        		String sticket = _conese.getonesemore(month,citycode,prodno,"","");//后面两个参数原来是指定起始结束时间的,实际没有用到
		        		//FileLogger.getLogger().info("调用信息费清单接口返回结果:" + sticket);
		        		if(sticket!=null && !sticket.equals("notable") && !sticket.equals("execerr")){
		        			EMessage _eticket = new EMessage(sticket);
		        			dtbill = _eticket.getDataTableBody();
		        		}
		        		//FileLogger.getLogger().info("调用信息费清单接口dtbillonese返回结果:" + dtbill);
		        		if(dtbill==null){	        			
		        			//对异常的处理,当出现错误信息时,往记录表中更新记录
		        			if(Integer.parseInt(faultcount)<9){	        				
		        				Remotemailorder.updsendstate(sqlfaultcountadd,mailorderid);
		        			}
		        			continue;
		        		}else{
		        			String recordnum = _conese.getoneseRecono(month,citycode,prodno,"","");
		        			String moneysum  = _conese.getonesesum(month,citycode,prodno,"","");
		        			if(recordnum==null || recordnum.equals(""))
		        				recordnum = "0";		        			
		        			if(moneysum==null || moneysum.equals(""))
		        				moneysum = "0";
	        				body = getTableoneseInfo(citycode,month,prodno,dtbill,recordnum,moneysum); 
		        			if(body!=null && body.equals("0")){
		        				body="";
		        			}		        			
		        		}
		        	}		  		        	
		        	
		        	//将正常的记录插入到表tl_maillog_200601
		        	TL_MailLog tl_maillog = TL_MailLog.getInstance(month);
		        	//序列号
		            long _lseq = _dac.getSequence("SEQ_MAILLOGID");	        	
		    		tl_maillog.setValue("MAILLOGID",new Long(_lseq));
		    		tl_maillog.setValue("USERID",accountid);
		    		tl_maillog.setValue("CREATETIME",new Date());
		    		tl_maillog.setValue("STATE","E");
		    		tl_maillog.setValue("DESCRIBE",body);
		    		tl_maillog.setValue("FAULTCOUNT","0");
		    		tl_maillog.setValue("MAILORDERID",mailorderid);
		    		tl_maillog.setValue("MAILTYPE","1");
		    		tl_maillog.setValue("EMAIL",toAddr);
		    		tl_maillog.save();   	
		        }
	        }
	        
	  	}catch(Exception ex){
	  		FileLogger.getLogger().warn("插入表maillog发生异常:"+S_MAILLOG, ex);
	  	}
	  	return "0/"+String.valueOf(succnum)+"/"+String.valueOf(totalnum);
	} 	

	
	/**
	 * 
	 */
	public static void runmaillogthread(String month,String userid,String account,String phonenum,String mailcomm,String email){
		String  S_MAILLOG = "";
	  	try {
			// 1、读取数据库
			if (month == null || month.equals("") || month.length() != 6)
				return;
	  		String ordersort = getOrderSort(mailcomm);
	  		if(ordersort==null || ordersort.equals(""))
	  			return ;	  		
			getSendmailorder(month,userid,account,phonenum,ordersort,email);

			S_MAILLOG= 
				   "select b.MAILORDERID,b.ordersort,b.faultcount ,a.productid, a.phonenum, a.citycode, c.email,c.ACCOUNTID,d.maillogid"+ 
				   "  from tf_andcustrela a, tf_mailorder b, tf_custinfoweb c ,tl_maillog_"+month+" d "+ 
				   "  where "+ 
		           "  a.andcustrelaid = b.andcustrelaid and a.userid = c.userid and c.accountid=d.userid" +
		           "  and d.mailorderid=b.mailorderid "+
				   "  and c.userid='"+userid+"' and a.phonenum = '"+phonenum+"' and b.startmonth <= "+month+" and b.endmonth >= "+month+" and b.ordersort='"+ordersort+"' "+
				   "  and a.state = 'E' and b.state = 'E' and c.state = 'E' and d.state='E' "+ 
				   "  and c.email='"+email+"'";	
//System.out.println("runmaillogthread-S_MAILLOG:"+S_MAILLOG);	  		
			_dac.beginTransaction(10000);
			DataTable ret = _dac.executeQuery(S_MAILLOG);
			_dac.endTransaction(true);

			if (ret != null) {
				if (ret.getRows().getCount() < 1) {
					return;
				}
				String toAddr = "";
				String subject = "帐单寄送";
				String body = "";
				String mime = "";
				String mailorderid = "";
				String faultcount = "";
				String accountid = "";
				String tablename = "tl_maillog_" + month;
				String maillogid = "";
				
				int ThrCount = 30;
				int ThrIdx = 0;
				boolean canSend = false;
				SendmailorderThr[] clientmailorderThr = new SendmailorderThr[ThrCount];
				for (int t = 0; t < ret.getRows().getCount(); t++) {
					maillogid = ret.getRow(t).getString("maillogid");
					String sqlfaultcountreset = "update "+tablename+" set faultcount=0  where maillogid=? and state='E'";
					Remotemailorder.updsendstate(sqlfaultcountreset,maillogid); 
					while (!canSend) {
						for (int i = 0; i < ThrCount; i++) {
							if (clientmailorderThr[i] == null || !clientmailorderThr[i].isAlive()) {
								canSend = true;
								ThrIdx = i;
								break;
							}
						}
					}
					canSend = false;
					clientmailorderThr[ThrIdx] = new SendmailorderThr(toAddr,
							subject, body, mime, mailorderid, faultcount,
							accountid, tablename, maillogid);
					clientmailorderThr[ThrIdx].start();
				}
			}
		} catch (Exception ex) {
			FileLogger.getLogger().info("runmaillogthread发生异常:"+S_MAILLOG, ex);
		} 
	}   
	
	/**
	 * 
	 */
	public static boolean checkmailsend(String month,String userid,String account,String phonenum,String mailcomm,String email){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -