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

📄 setfeetofree.java

📁 这是我工作项目中的一个java类
💻 JAVA
字号:
/**
 * Created on 2005-5-12
 *
 *@author  杨洪波
 */
package com.qxweb.setFee;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class SetFeeToFree {
	
	private String telNum = "";
	
	/**mag的第一个之值为0,程序错误,没有正常执行结束;
	 * 1,正常用户,正常执行,正常结束;
	 * 2,正常用户,已经设置为免费;
	 * 3,用户已退订短信;
	 * 5,没有订制信息的用户;7,消号用户
	 */
	private String[] msg = new String[4];
	
	
	
 	public String[] setToFree(String telNum,String workNum){
 		
		//用户状态,0无效用户,1有效用户
 		String userType = "";
 		
 		//用户收费状态,0免费,1收费
		String feeType = "";
		
        //用户收费状态,0免费,1收费
		String usersource = "";
		
		/**对于已经是免费的用户,需要获取以下资料:
		 * workNum员工工号;operatedate设置为免费的操作日期;
		 * sendedmonth 给用户免费的日期。
		 */
		String operator  = "";
		String operatedate = "";
		String sendedmonth = "";
		
		msg[0] = "5";
		//访问数据库  
 		Connection conn=null;
		try{
			Context ctx = new InitialContext();
			ctx = new InitialContext();
			DataSource ds =(DataSource)ctx.lookup("java:comp"+
					"/env/jdbc/oratq");
			conn = ds.getConnection();
			Statement St = conn.createStatement();
				       
			ResultSet rst=null;	
			
			String strSQL="SELECT usertype,feetype,usersource "+
			              " FROM td_user "+
			              " WHERE msisdn = '"+telNum+"'";			
			rst=St.executeQuery(strSQL);
			while(rst.next()){
				userType = rst.getString(1);
				feeType = rst.getString(2);
				usersource = rst.getString(3);			          
			}
			rst.close();
						
			//没有该用户的记录
			if(userType == null){
				userType = "";			
			}
			if(feeType == null) feeType = "";
			
			//正常用户、收费用户,设置为免费用户
			if(userType.equals("1")&&feeType.equals("1")){
				strSQL = "UPDATE td_user SET "+
				         " feetype = '0',pri = '99',sendedmonth = '205002'"+
						 " WHERE msisdn = '"+telNum+"'";
				St.execute(strSQL);					
				msg[0] = "1";
				
				
				strSQL = "INSERT INTO td_operator_log "+
				         " VALUES('"+workNum+"','"+telNum+
						 " ','sysdate','free')";
			} 
						
			//正常用户、已设置为免费,查询免费日期、操作员工工号、操作日期
			else if(userType.equals("1")&&feeType.equals("0")){
				strSQL = "SELECT a.operatorid,a.operatedate,b.sendedmonth "+
				         " FROM td_operator_log a,td_user b "+
						 " WHERE b.msisdn = '"+telNum+"' AND a.msg = 'free'"+
						 " AND a.msisdn = b.msisdn"+
						 " order by a.operatedate asc";
	            rst = St.executeQuery(strSQL);
	            while(rst.next()){
	            	operator = rst.getString(1);
	            	operatedate = rst.getString(2);
	            	sendedmonth = rst.getString(3);	              
	            }	            
	            rst.close();
				
				if(operator == null) operator = "";
				if(operatedate == null) operatedate = "";
				if(sendedmonth == null) sendedmonth = "";
				
				msg[0] = "2";				
				msg[1] = operator;
				msg[2] = operatedate;
				msg[3] = sendedmonth;
			}
			
			else if(userType.equals("0")){
				//销号
				if(usersource.equals("5")){					
					msg[0] = "7";
				}
				
				//退订
				else {					
					msg[0] = "3";
				}
			}
			
			conn.close();
		}
		
		catch(Exception e){
			//conn.close();
			System.out.println(e);			
			msg[0] = "0";
			msg[1] = e.toString();
		}			
		
		return msg;		
	}


}

⌨️ 快捷键说明

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