📄 accountbean.java
字号:
package com.ufmobile.business.account.bo.bean;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import com.ufmobile.business.account.bo.Account;
import com.ufmobile.business.account.bo.Card;
import com.ufmobile.business.account.bo.Account.AccountType;
import com.ufmobile.business.account.dao.AccountAdjustDAO;
import com.ufmobile.business.account.dao.AccountDAO;
import com.ufmobile.business.account.dao.AccountLogDAO;
import com.ufmobile.business.account.dao.AccountLogDAO2;
import com.ufmobile.business.account.dao.AccountMoneyDAO;
import com.ufmobile.business.account.dao.CardDAO;
import com.ufmobile.business.account.dao.PriceDAO;
import com.ufmobile.business.account.entity.AccmoneyEntity;
import com.ufmobile.business.account.entity.AccountAdjustEntity;
import com.ufmobile.business.account.entity.AccountEntity;
import com.ufmobile.business.account.entity.CardEntity;
import com.ufmobile.business.account.entity.BusiPriceEntity;
import com.ufmobile.business.exception.AccountException;
import com.ufmobile.business.exception.CardException;
import com.ufmobile.common.BaseBean;
import com.ufmobile.common.login.entity.UserInfo;
import com.ufmobile.common.param.PublicParam;
import com.ufmobile.common.param.PublicParamDAO;
import com.ufmobile.common.security.bo.SecurityTool;
import com.ufmobile.mstreet.boothmanage.boothset.bo.Booth;
import com.ufmobile.mstreet.entity.BoothEntity;
import com.ufmobile.mstreet.entity.OperatorEntity;
import com.ufmobile.mstreet.util.CommonUtil;
import com.ufmobile.platform.Exception.BusinessException;
import com.ufmobile.platform.alert.AlertAccount;
import com.ufmobile.platform.ejb.EJBBoClient;
import com.ufmobile.platform.log.RunTimeLogger;
/*
* @auur 毛士福
* @date 2006/12/7
* @function 账户管理
*/
public @Stateless
class AccountBean extends BaseBean implements Account {
private AccountDAO accountDao;
private AccountMoneyDAO moneyDao;
private AccountLogDAO logDao;
private AccountLogDAO2 log2Dao;
private static long[] alertkey = new long[] { 0, 0 };
private AlertAccount alterAcount;
private PublicParamDAO paramDao;
private AccountAdjustDAO accaDao;
@PostConstruct
/**
* 商街重构
* comment by sijian 2007-08-08
* reasion:modify getBean(int,String)
* public void init()
*/
public void init()
{
accountDao = new AccountDAO(getManager(this.getClass()));
moneyDao = new AccountMoneyDAO(getManager(this.getClass()));
logDao = new AccountLogDAO(getManager(this.getClass()));
log2Dao = new AccountLogDAO2(getManager(this.getClass()));
accaDao = new AccountAdjustDAO(this.getManager(this.getClass()));
paramDao = new PublicParamDAO();
paramDao.setManager(this.getManager());
}
public AccountEntity add(AccountEntity account) throws AccountException {
RunTimeLogger.info(getClass(), "新增账户");
AccountEntity ret = accountDao.add(account);
moneyDao.add(ret.getId());
return ret;
}
/**
* 作者:msf <br>
* 日期:Dec 15, 2006
*
* @see com.ufmobile.business.account.bo.Account#back(java.lang.String,
* com.ufmobile.business.account.bo.Account.AccountType,
* java.math.BigDecimal, java.lang.Long, java.lang.String)
*/
public void back(String accountid, AccountType Type, BigDecimal money, String usrname, String reson) throws AccountException {
RunTimeLogger.info(getClass(), "返款");
if (money == null || money.doubleValue() <= 0.0) {
throw new AccountException("金额不能小于零");
}
AccmoneyEntity moneyEntity = moneyDao.back(accountid, Type, money);
// 记日志
if (Type == AccountType.Flow) {
logDao.recordLog(moneyEntity, money, BussinessType.back, usrname, reson);
} else if (Type == AccountType.Service) {
log2Dao.recordLog(moneyEntity, money, BussinessType.back, usrname, reson);
}
}
private void initAlertKey() {
int localid = Integer.parseInt(paramDao.getParamValue(PublicParam.LOCAL_ID));
// 多商街修改 msf
// alterAcount = (AlertAccount) getBean("AlertAccountBean"); //comment by sijian 2007-08-08
alterAcount = (AlertAccount) EJBBoClient.getClient(localid, "AlertAccountBean");
for (int i = 0; i < alertkey.length; i++) {
try {
alertkey[i] = alterAcount.queryAccountAlertValue(i);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 作者:msf <br>
* 日期:Dec 15, 2006
*
* @see com.ufmobile.business.account.bo.Account#deduct(java.lang.String,
* com.ufmobile.business.account.bo.Account.AccountType,
* java.math.BigDecimal, java.lang.Long, java.lang.String)
*/
public void deduct(String accountid, AccountType Type, BigDecimal money, String usrname, String reson) throws AccountException {
this.initAlertKey();
if (money == null || money.doubleValue() <= 0.0) {
RunTimeLogger.info(getClass(), "金额小于等于零");
return;
}
RunTimeLogger.info(getClass(), "扣费");
// 扣费
AccmoneyEntity moneyEntity = moneyDao.deduct(accountid, Type, money);
// 记日志
if (Type == AccountType.Flow) {
logDao.recordLog(moneyEntity, money, BussinessType.debuct, usrname, reson);
} else if (Type == AccountType.Service) {
log2Dao.recordLog(moneyEntity, money, BussinessType.debuct, usrname, reson);
}
RunTimeLogger.info(this, "流量:" + alertkey[0] + "服务:" + alertkey[1] + "余额:" + moneyEntity.getBalance().longValue() + "类型:" + Type);
if (Type == AccountType.Flow && alertkey[0] > moneyEntity.getBalance().longValue()) {
// 流量预警方法
RunTimeLogger.info(this, "流量预警:帐户id=" + accountid + "余额为=" + moneyEntity.getBalance());
int localId = Integer.parseInt(paramDao.getParamValue(PublicParam.LOCAL_ID));
alterAcount.eventOfFluxBalanceChanged(localId,accountid, moneyEntity.getBalance().doubleValue(), logDao.getLastFillDate(accountid));
RunTimeLogger.info(this, "end 流量预警:帐户id22=" + accountid + "余额为=" + moneyEntity.getBalance());
}
/** 取消服务预警,fixed by Janet 2007-12-19
else if (Type == AccountType.Service && alertkey[1] > moneyEntity.getBalance().longValue()) {
// 服务预警方法
RunTimeLogger.info(this, "服务预警:帐户id=" + accountid + "余额为=" + moneyEntity.getBalance());
alterAcount.eventOfServiceBalanceChanged(accountid, moneyEntity.getBalance().doubleValue(), log2Dao.getLastFillDate(accountid));
}
*/
}
/**
* 作者:chengjy <br>
* 日期:Nov 9, 2007
* 重载deduct
* 增加业务操作类型项
*
*
* @see com.ufmobile.business.account.bo.Account#deduct(java.lang.String,
* com.ufmobile.business.account.bo.Account.AccountType,
* java.math.BigDecimal, java.lang.Long, java.lang.String)
*/
public void deduct(String accountid, AccountType Type, BigDecimal money, String usrname, String reson,BussinessType bt) throws AccountException {
this.initAlertKey();
if (money == null || money.doubleValue() <= 0.0) {
RunTimeLogger.info(getClass(), "金额小于等于零");
return;
}
RunTimeLogger.info(getClass(), "扣费");
// 扣费
AccmoneyEntity moneyEntity = moneyDao.deduct(accountid, Type, money);
// 记日志
if (Type == AccountType.Flow) {
logDao.recordLog(moneyEntity, money, bt, usrname, reson);
} else if (Type == AccountType.Service) {
log2Dao.recordLog(moneyEntity, money, bt, usrname, reson);
}
RunTimeLogger.info(this, "流量:" + alertkey[0] + "服务:" + alertkey[1] + "余额:" + moneyEntity.getBalance().longValue() + "类型:" + Type);
if (Type == AccountType.Flow && alertkey[0] > moneyEntity.getBalance().longValue()) {
// 流量预警方法
RunTimeLogger.info(this, "流量预警:帐户id=" + accountid + "余额为=" + moneyEntity.getBalance());
int localId = Integer.parseInt(paramDao.getParamValue(PublicParam.LOCAL_ID));
alterAcount.eventOfFluxBalanceChanged(localId,accountid, moneyEntity.getBalance().doubleValue(), logDao.getLastFillDate(accountid));
RunTimeLogger.info(this, "end 流量预警:帐户id22=" + accountid + "余额为=" + moneyEntity.getBalance());
}
/** 取消服务预警,fixed by Janet 2007-12-19
else if (Type == AccountType.Service && alertkey[1] > moneyEntity.getBalance().longValue()) {
// 服务预警方法
RunTimeLogger.info(this, "服务预警:帐户id=" + accountid + "余额为=" + moneyEntity.getBalance());
alterAcount.eventOfServiceBalanceChanged(accountid, moneyEntity.getBalance().doubleValue(), log2Dao.getLastFillDate(accountid));
}
*/
}
/**
* 作者:msf <br>
* 日期:Dec 21, 2006
*
* @see com.ufmobile.business.account.bo.Account#deduct(java.lang.String,
* com.ufmobile.business.account.bo.Account.AccountType,
* java.lang.Integer, java.lang.String, java.lang.String,
* java.lang.String)
*/
public void deduct(String accountid, AccountType Type, BigDecimal quantity, String category, String usrname, String reson) throws AccountException {
RunTimeLogger.info(getClass(), "计算扣费1");
BusiPriceEntity p = new PriceDAO(getManager(getClass())).getPriceByType(category).get(0);
BigDecimal money = p.getPrice().multiply(quantity);
// 扣费
if (money.doubleValue() > 0.0)
deduct(accountid, Type, money, usrname, reson);
}
/**
* 作者:msf <br>
* 日期:Dec 18, 2006
*
* @see com.ufmobile.business.account.bo.Account#delete(java.lang.String,
* java.lang.Long)
*/
public void delete(String accountid) throws AccountException {
RunTimeLogger.info(getClass(), "删除账户");
// 校验
List l1 = logDao.queryByAccountID(accountid);
List l2 = log2Dao.queryByAccountID(accountid);
if ((l1 != null && l1.size() > 0 && l1.get(0) != null) || (l2 != null && l2.size() > 0 && l2.get(0) != null)) {
throw new AccountException("有后续操作,不能删除");
}
accountDao.delete(accountid);
moneyDao.deleteByaccountid(accountid);
}
public void deploy(String fromAccountid, AccountType fromType, String toAccountid, AccountType toType, BigDecimal money, String usrname) throws AccountException {
RunTimeLogger.info(getClass(), "账户调拨");
}
/**
* 作者:msf <br>
* 日期:Dec 15, 2006
*
* @see com.ufmobile.business.account.bo.Account#fillMoney(java.lang.String,
* com.ufmobile.business.account.bo.Account.AccountType,
* java.lang.Long, java.lang.Long, java.lang.String)
*/
public void fillMoney(String accountid, AccountType Type, String usrname, String sCardcode, String password) throws BusinessException {
RunTimeLogger.info(getClass(), "充值");
Card card =(Card) EJBBoClient.getRemoteClient(0, "CardBean");
// 验证卡和密码
CardEntity cardentity = card.findCardByCode(sCardcode);
if (cardentity == null)
throw new CardException("找不到该卡号的充值卡");
/**2007-10-24:充值卡充值解密 by daixh*/
String password1 = cardentity.getPassword();
StringBuffer sDecryptBuf = new StringBuffer("");
int nn = SecurityTool.decrypt(password1, sDecryptBuf);
if(nn<0){
throw new CardException(this, "充值卡充值解密失败。");
}
/**解成明文密码*/
String depassword = sDecryptBuf.toString();
if (depassword == null || !depassword.equals(password)) {
throw new CardException("输入的密码错误");
}
if (cardentity.getCardtype() == null || cardentity.getCardtype().intValue() != Type.ordinal()) {
throw new CardException("账户类型不匹配");
}
if (cardentity.getFreeze().booleanValue()) {
throw new CardException("该充值卡已被冻结");
}
if (cardentity.getIsover().booleanValue()) {
// 提示与v2同步的卡
if ("V2".equals(cardentity.getCardoperator()))
throw new CardException("该充值卡已被V2充完");
else
throw new CardException("该充值卡已充完");
}
// 验证代理商
AccountEntity account = accountDao.querybyAccountID(accountid);
if (account == null)
throw new AccountException("找不到该Id号的账户");
if (!account.getAccountstart().booleanValue())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -