📄 fundaccountjb.java
字号:
package com.funddeal.model.bean.fund_account;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import com.funddeal.base.PublicFunction;
import com.funddeal.base.SessionCommit;
import com.funddeal.base.interfaces.OperLogInterface;
import com.funddeal.model.bean.financial_account.FinancialAccountJB;
import com.funddeal.model.bean.operare_log.OperareLogJB;
import com.funddeal.model.dao.fund_account.FundAccountDAO;
import com.funddeal.model.pojo.custom_entity.BringNumParamEntity;
import com.funddeal.model.pojo.custom_entity.OperLogParamEntity;
import com.funddeal.model.pojo.custom_entity.SearchParamEntity;
import com.funddeal.model.pojo.financial_account.FinancialAccount;
import com.funddeal.model.pojo.fund.Fund;
import com.funddeal.model.pojo.fund_account.FundAccount;
/**
* 基金交易模块
* @author Administrator
*
*/
public class FundAccountJB {
public static String errorMsg="";
/**
* 购买基金
* @param fa: 基金帐号实体
* @param pwd: 资金帐号密码
* @param olpe: 日志参数实体
* @return True|False(是否成功)
*/
public boolean addFundAccountJB(FundAccount fa,String pwd,OperLogParamEntity olpe){
errorMsg="";
String id="";
// 验证资金帐号相关信息
String financialAccNo = fa.getFinancialAccNo();
if(financialAccNo.equals("")){
errorMsg="程序错误:未得到资金帐号的值";
return false;
}
FinancialAccountJB faJB=new FinancialAccountJB();
Collection col= faJB.SearchFinaAccount("financialAccount",financialAccNo);
if(col==null){
errorMsg=FinancialAccountJB.errorMsg;
return false;
}
ArrayList al=(ArrayList)col;
if(al.size()<=0){
String errMsg=FinancialAccountJB.errorMsg;
if(errMsg.equals(""))
errorMsg="资金帐号不存在";
else
errorMsg=errMsg;
return false;
}
FinancialAccount faPojo=(FinancialAccount)al.get(0);
if(!faPojo.getPassword().equals(pwd)){
errorMsg="该客户的资金帐号密码不正确";
return false;
}
if(!faPojo.getStatus().equals("正常")){
errorMsg="该客户的资金状态为冻结状态";
return false;
}
float financingAmount= faPojo.getFinancingAmount();
float price=fa.getPrice();
long quantity=fa.getQuantity();
float sxf=(float)((float)price*quantity*0.01);
if((financingAmount-sxf)<=price*quantity){
errorMsg="客户资金余额不足!";
return false;
}
// 验证基金产品信息
String fundNo = fa.getFundNo();
if(fundNo.equals("")){
errorMsg="程序错误:未得到基金产品编号";
return false;
}
PublicFunction pf=new PublicFunction();
Query query= pf.search("from Fund as fund where fund.fundNo='"+ fundNo +"'");
Fund fund=null;
try {
if(query.list().size()<=0){
errorMsg="程序错误: 基金产品编号在传值过程中出现异常";
return false;
}
fund=(Fund)query.list().get(0);
} catch (HibernateException e1) {
errorMsg=e1.getMessage();
e1.printStackTrace();
return false;
}
if(!fund.getStatus().equals("上市")){
errorMsg="该基金产品尚未上市或已取消上市了";
return false;
}
// 更新客户资金金额数
faPojo.setFinancingAmount(financingAmount-price*quantity-sxf);
SessionCommit sc;
try {
sc=new SessionCommit();
sc.getSessionUpdate(faPojo);
} catch (HibernateException e2) {
e2.printStackTrace();
errorMsg="修改资金金额时出现异常:"+ e2.getMessage();
return false;
}
//查找客户购买的基金是否在之前购买过
String hql="from FundAccount as fa where fa.fundNo='"+ fundNo +"' and fa.financialAccNo='"+ financialAccNo +"'";
Query queryFundAccount = pf.search(hql);
int cut=0;
try {
cut= queryFundAccount.list().size();
if(cut>0){
FundAccount fundA=(FundAccount)queryFundAccount.list().get(0);
fundA.setQuantity(fundA.getQuantity()+ fa.getQuantity());
fundA.setPrice(fa.getPrice());
sc=new SessionCommit();
if(sc.getSessionUpdate(fundA)){
/*
* 添加相应的日志
*/
//////////////////////////////////////////////////////////////////
olpe.setOperResultId(fundA.getFundAccNo()); //
olpe.setOperTableName("FUND_ACCOUNT"); //
olpe.setOperType("购买基金"); //
OperLogInterface pif=new OperareLogJB(); //
pif.addOperareLog(olpe); //
//////////////////////////////////////////////////////////////////
return true;
}else{
errorMsg=SessionCommit.errorMsg;
return false;
}
}
} catch (HibernateException e1) {
e1.printStackTrace();
}
BringNumParamEntity bnpe=new BringNumParamEntity();
bnpe.setPojoName("FundAccount");
bnpe.setPropertyId("fundAccNo");
bnpe.setTableName("FUND_ACCOUNT");
String fundAccountNo=pf.bringNumber(bnpe);
fa.setFundAccNo(fundAccountNo);
FundAccountDAO faDao=new FundAccountDAO();
try {
id=faDao.addFundAccount(fa);
} catch (HibernateException e) {
e.printStackTrace();
errorMsg="添加购买基金记录时出现异常:" + e.getMessage();
return false;
}
if(id.length()==32){
/*
* 添加相应的日志
*/
//////////////////////////////////////////////////////////////
olpe.setOperResultId(fundAccountNo); //
olpe.setOperTableName("FUND_ACCOUNT"); //
olpe.setOperType("购买基金"); //
OperLogInterface pif=new OperareLogJB(); //
pif.addOperareLog(olpe); //
//////////////////////////////////////////////////////////////
return true;
}else{
return false;
}
}
/**
* 赎回基金
* @param fa: 基金帐号实体
* @param pwd: 资金帐号密码
* @param olpe: 日志参数实体
* @return True|False(是否成功)
*/
public boolean redeemFundAccount(FundAccount fa,String pwd,OperLogParamEntity olpe){
errorMsg="";
//检查参数值
String fundAccNo= fa.getFundAccNo();
long quantity=fa.getQuantity();
if(fundAccNo.equals("") || quantity<=0 || pwd.equals("")){
errorMsg="参数不能为空";
return false;
}
//检查基金交易编号是否存在,存在则取出基金交易编号所对应的实体
SearchParamEntity spe=new SearchParamEntity();//查找参数实体
spe.setPojoName("FundAccount");
spe.setPropertyName("fundAccNo");
spe.setValue(fundAccNo);
PublicFunction pf=new PublicFunction();
Query query= pf.search(spe);
try {
int cut= query.list().size();
if(cut<=0){
errorMsg="该基金交易编号不存在!";
return false;
}
fa=(FundAccount)query.list().get(0);
} catch (HibernateException e) {
e.printStackTrace();
errorMsg=e.getMessage();
return false;
}
//判断赎回基金数量是否有效
if(quantity>fa.getQuantity()){
errorMsg="要赎回的基金数量大于购买的基金数量";
return false;
}
//检查客户资金帐号信息
String financialAccNo=fa.getFinancialAccNo();
spe.setPojoName("FinancialAccount");
spe.setPropertyName("accountNo");
spe.setValue(financialAccNo);
Query queryFa=pf.search(spe);
FinancialAccount financialA;
try {
int cut=queryFa.list().size();
if(cut<=0){
errorMsg="程序出现异常:该客户的资金帐号不存在!可能是数据库中的数据已被破坏";
return false;
}
financialA=(FinancialAccount)queryFa.list().get(0);
} catch (HibernateException e) {
e.printStackTrace();
errorMsg=e.getMessage();
return false;
}
//验证资金帐号密码是否正确
if(!financialA.getPassword().equals(pwd)){
errorMsg="资金帐号密码不正确";
return false;
}
//检查资金帐号是否正常
String status=financialA.getStatus();
if(!status.equals("正常")){
errorMsg="该客户的资金帐号已被冻结,不能为其赎回基金";
return false;
}
//取得所购基金的信息
String fundNo = fa.getFundNo();
spe.setPojoName("Fund");
spe.setPropertyName("fundNo");
spe.setValue(fundNo);
Query queryFund=pf.search(spe);
Fund fund;
try {
int cut=queryFund.list().size();
if(cut<=0){
errorMsg="程序出现异常:该客户所购买的基金不存在!可能是数据库中的数据已被破坏";
return false;
}
fund=(Fund)queryFund.list().get(0);
} catch (HibernateException e) {
e.printStackTrace();
errorMsg=e.getMessage();
return false;
}
//取得基金上市价格
float price=fund.getPrice();
//将基金上市价格转换为当前的价格
price=(float) (price+(Math.random()*20-10));
//取得剩余基金数量
long surplusQuantity=fa.getQuantity()-quantity;
//更新基金帐号中的基金数量
fa.setQuantity(surplusQuantity);
try {
SessionCommit sc=new SessionCommit();
if(surplusQuantity==0){
if(!sc.getSessionDelete(fa)){
errorMsg=SessionCommit.errorMsg;
return false;
}
}else{
if(!sc.getSessionUpdate(fa)){
errorMsg=SessionCommit.errorMsg;
return false;
}
}
} catch (HibernateException e) {
e.printStackTrace();
errorMsg=e.getMessage();
return false;
}
//手续费:
float poundage=(float) (quantity*price*0.01);
//赎回基金后的当前资金帐户金额
float currentlyAmount=financialA.getFinancingAmount()+ quantity*price -poundage;
//将当前资金金额设到实体对象之中
financialA.setFinancingAmount(currentlyAmount);
//更新赎回基金后的资金帐户金额
try {
SessionCommit sc=new SessionCommit();
if(!sc.getSessionUpdate(financialA)){
errorMsg=SessionCommit.errorMsg;
return false;
}
} catch (HibernateException e) {
e.printStackTrace();
errorMsg=e.getMessage();
return false;
}
/*
* 添加相应的日志
*/
//////////////////////////////////////////////////////////
olpe.setOperResultId(fa.getFundAccNo()); //
olpe.setOperTableName("FUND_ACCOUNT"); //
olpe.setOperType("赎回基金"); //
OperLogInterface pif=new OperareLogJB(); //
pif.addOperareLog(olpe); //
//////////////////////////////////////////////////////////
return true;
}
/**
*
* @param str
* @return
* @throws HibernateException
*/
public Iterator selectFundAccount(String str) throws HibernateException{
FundAccountDAO faDAO=new FundAccountDAO();
String st="select fa.fundAccNo,fa.financialAccNo," +
"fa.quantity,fa.price," +
"fund.createdDate,fund.status,fund.fundName,fund.price," +
"fcat.status,fcat.createdDate,fcat.financingAmount" +
" from FundAccount fa,Fund fund," +
"FinancialAccount fcat where fa.fundAccNo='"+ str +
"' and fa.financialAccNo=fcat.accountNo and" +
" fa.fundNo=fund.fundNo";
Iterator iter=faDAO.selectFundAccount(st);
return iter;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -