public Connection getConnection() {
try {
Class.forName(oracleDriver);
conn = DriverManager.getConnection(connStr,"scott","scott");
} catch(Exception e) {
e.printStackTrace();
return null;
}
return conn;
}
}
计费算法类
/**
* name:CallDetails.java
* coder:wangpeng
* date time:Mar 20, 2009 2:31:22 PM
*/
package com.hexin.wp;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import com.hexin.wp.bean.FeeMehodBean;
import com.hexin.wp.bean.MethodDetailsBean;
import com.hexin.wp.utils.ConvertDate;
public class CallMoney {
Statement stmt = null;
ResultSet rs = null;
int time_temp = 0; // 定义临时通话时长,往后累加
int first_order = 0; // 首次进行计费开始的阶段号
int callTypeNo = 0; // 定义该次通话记录的通话类型。
ArrayList<Integer> v_time_long = new ArrayList<Integer>();
ArrayList<Date> v_startTime = new ArrayList<Date>();
ArrayList<FeeMehodBean> mArray = new ArrayList<FeeMehodBean>();
/**
* 通过号码头遍历计费方法
* 获取匹配方法的集合
* @param phoneHead
* @return
*/
public ArrayList<FeeMehodBean> getMethodLi(String phoneHead) {
ArrayList<FeeMehodBean> methodsLi = new ArrayList<FeeMehodBean>();
ArrayList<FeeMehodBean> array = new ArrayList<FeeMehodBean>();
FeeMethod fm = new FeeMethod();
// 将计费方法从数据库读出。
array = fm.feeMehod();
for (int i = 0; i < array.size(); i++) {
if (phoneHead.equals(fm.methodList.get(i).getPhoneHead())) {
methodsLi.add(fm.methodList.get(i)); // 缩小循环遍历的方法范围
}
}
if(methodsLi.size() == 0) {
methodsLi.add(fm.methodList.get(0));
}
return methodsLi;
}
/**
* 计费细则方法
* @param phoneHead号码头
* @param startTime开始时间
* @param time_long通话时长
* @param fOrder开始阶段号
* @param sTime开始阶段已用时间
* @return callDee通话费用
*/
public double callFee(String phoneHead, Date startTime, int time_long, int order, int sTime) {
double callFee = 0.0; //初始化通话费用
FeeMethod fm = new FeeMethod();
v_time_long.add(time_long); //保存原始通话时长
v_startTime.add(startTime); //保存原始的通话开始时间
ArrayList<MethodDetailsBean> dArray = new ArrayList<MethodDetailsBean>();
Date countTime = startTime; // 定义临时结束时间点,往后累加
if (mArray.size() == 0) {
mArray = this.getMethodLi(phoneHead);
}
// 遍历号码头已经匹配好的几个方法,是否是节假日优惠里
for (int i = 0; i < mArray.size(); i++) {
int time_length = 0;
//找到匹配的计费方法号
if ((countTime.after(mArray.get(i).getStartValidDate()) || countTime.equals(mArray.get(i).getStartValidDate()))
&& (countTime.before(mArray.get(i).getEndValidDate()))) {
callTypeNo = mArray.get(i).getCallTypeNO();
dArray = fm.methodDetails(mArray.get(i).getFeeMethodNO());
//计费细则中阶段时长累加
www.751com.cn
time_length += dArray.get(order).getUnit();
first_order = order;
time_temp += dArray.get(order).getUnit();
//累加的时长等于或超过了原始通话时长,退出
if (time_temp >= v_time_long.get(0)) {
ArrayList<FeeMehodBean> tempList = new ArrayList<FeeMehodBean>();
/*
* 结束前,判断该次通话记录是否需要多项收费
*/
for(int j=0; j<mArray.size(); j++) {
if(callTypeNo != mArray.get(j).getCallTypeNO()) {
tempList.add(mArray.get(j));
}
}if(tempList.size()==0){
return callFee;
}else{
time_temp = 0;//临时计费时长清零
mArray = tempList;//另外项目收费的计费方法赋值给成员变量,递归
return callFee + this.callFee(phoneHead, v_startTime.get(0), time_long, 0, 0);countTime = ConvertDate.dateAdd(countTime, dArray.get(order).getUnit());
//用户通话跨优惠段,需要递归,另寻相应的计费方法
if (countTime.after(mArray.get(i).getEndValidDate()) || countTime.equals(mArray.get(i).getEndValidDate())) {
if (time_length < dArray.get(order).getTimeLength() || dArray.get(order).getTimeLength() == -1) {
<< 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] 下一页