📄 dutyexchangedaoimpl.java
字号:
package dao.exchange.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import vo.DutyExchangeVo;
import dao.common.DBConnectionManager;
import dao.common.sql.DutyExchangeSql;
import dao.exchange.DutyExchangeDao;
public class DutyExchangeDaoImpl implements DutyExchangeDao {
private DBConnectionManager manager = DBConnectionManager.getInstance();
public DutyExchangeVo getCurrentExchangeInfo() {
DutyExchangeVo value = null;
Connection con = null;
ResultSet set1 = null;
ResultSet set2 = null;
ResultSet set3 = null;
Statement stmt1 = null;
PreparedStatement pstmt1 = null;
PreparedStatement pstmt2 = null;
try {
con = manager.getConnection("oracle");
stmt1 = con.createStatement();
// 得到上一次当班的记录
set1 = stmt1.executeQuery(DutyExchangeSql.GET_LATEST_RECORD);
set1.next();
String latestPresentTime = String.valueOf(set1.getString("PRESENT_TIME")
.subSequence(0, 19));
String latestLastTime = String.valueOf(set1.getString("LAST_TIME").substring(0, 19));
double latestRecordBalance = set1.getDouble("CURRENT_BALANCE");
// 得到该操作员值班期间会员的消费总额
pstmt1 = con.prepareStatement(DutyExchangeSql.GET_VIP_STAGE_CONSUME);
pstmt1.setString(1, latestLastTime);
pstmt1.setString(2, latestPresentTime);
set2 = pstmt1.executeQuery();
set2.next();
double satgeVipIncome = set2.getDouble("sum(needed_amount)");
// 得到该操作员值班期间非会员(普通客户)的消费总额
pstmt2 = con.prepareStatement(DutyExchangeSql.GET_NONVIP_STAGE_CONSUME);
pstmt2.setString(1, latestLastTime);
pstmt2.setString(2, latestPresentTime);
set3 = pstmt2.executeQuery();
set3.next();
double stageNonVipIncome = set3.getDouble("sum(needed_amount)");
value = new DutyExchangeVo(latestRecordBalance, stageNonVipIncome, satgeVipIncome,
satgeVipIncome + stageNonVipIncome, 0.0, 0.0, latestRecordBalance + satgeVipIncome
+ stageNonVipIncome, "", latestPresentTime, "交班员工", "接班员工");
} catch (SQLException e) {
e.printStackTrace();
} finally {
manager.freeConnection("oracle", con);
}
return value;
}
public boolean insertExchangeInfo(DutyExchangeVo value) {
boolean flag = false;
Connection con = null;
PreparedStatement pstmt = null;
try {
con = manager.getConnection("oracle");
pstmt = con.prepareStatement(DutyExchangeSql.ADD_DUTY_EXCHANGE_RECORD);
pstmt.setDouble(1, value.getLastBalance());
pstmt.setDouble(2, value.getIncomeCash());
pstmt.setDouble(3, value.getIncomeCard());
pstmt.setDouble(4, value.getTurnoverUp());
pstmt.setDouble(5, value.getTurnoverDown());
pstmt.setDouble(6, value.getCurrentBalance());
pstmt.setString(7, value.getLastExcangeTime());
pstmt.setString(8, value.getPresentTime());
pstmt.setString(9, value.getOperatorOff());
pstmt.setString(10, value.getOperatorOn());
int count = pstmt.executeUpdate();
if (count != 0) {
flag = true;
}
} catch (SQLException e) {
System.out.println("添加交班记录失败:" + e.getMessage());
} finally {
manager.freeConnection("oracle", con);
}
return flag;
}
public Vector<DutyExchangeVo> getExchangeHistory(String startTime, String endTime) {
Vector<DutyExchangeVo> vector = null;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet set = null;
try {
con = manager.getConnection("oracle");
pstmt = con.prepareStatement(DutyExchangeSql.GET_DUTY_EXCHANGE_HISTORY);
pstmt.setString(1, startTime);
pstmt.setString(2, endTime);
set = pstmt.executeQuery();
vector = new Vector<DutyExchangeVo>();
while (set.next()) {
double lastBalance = set.getDouble("LAST_BALANCE");
double incomeCash = set.getDouble("INCOME_CASH");
double incomeCard = set.getDouble("INCOME_CARD");
double tatalIncome = incomeCash + incomeCard;
double turnoverUp = set.getDouble("TURNOVER_UP");
double turnoverDown = set.getDouble("TURNOVER_DOWN");
double currentBalance = set.getDouble("CURRENT_BALANCE");
String lastExcangeTime = set.getString("LAST_TIME");
String presentTime = set.getString("PRESENT_TIME");
String operatorOff = set.getString("OPERATOR_OFF");
String operatorOn = set.getString("OPERATOR_ON");
vector.add(new DutyExchangeVo(lastBalance, incomeCash, incomeCard, tatalIncome,
turnoverUp, turnoverDown, currentBalance, lastExcangeTime, presentTime,
operatorOff, operatorOn));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
manager.freeConnection("oracle", con);
}
return vector;
}
/**
* 获得当前的操作员
*/
public String getCurrentOperator() {
String curOperator = null;
Connection con = manager.getConnection("oracle");
Statement stmt = null;
ResultSet set = null;
try {
stmt = con.createStatement();
set = stmt.executeQuery(DutyExchangeSql.GET_CURRENT_OPERATOR);
set.next();
curOperator = set.getString("OPERATOR_ON");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
manager.freeConnection("oracle", con);
}
return curOperator;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -