📄 cardbean.java
字号:
package com.ufmobile.business.account.bo.bean;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import javax.ejb.Stateless;
import javax.sql.DataSource;
import com.ufmobile.business.account.bo.Card;
import com.ufmobile.business.account.bo.CostCardStatiDetail;
import com.ufmobile.business.account.bo.Account.BussinessType;
import com.ufmobile.business.account.dao.AccountLogDAO2;
import com.ufmobile.business.account.dao.CardDAO;
import com.ufmobile.business.account.entity.Accountlog2Entity;
import com.ufmobile.business.account.entity.CardEntity;
import com.ufmobile.business.exception.CardException;
import com.ufmobile.common.BaseBean;
import com.ufmobile.common.login.entity.UserInfo;
import com.ufmobile.common.security.bo.SecurityTool;
import com.ufmobile.mstreet.booth.boothscore.dao.BoothScoreAdjustDAO;
import com.ufmobile.mstreet.booth.boothscore.dao.BoothScoreRuleDAO;
import com.ufmobile.mstreet.boothmanage.boothset.dao.BoothDAO;
import com.ufmobile.mstreet.entity.BoothEntity;
import com.ufmobile.mstreet.entity.BoothScoreRuleEntity;
import com.ufmobile.mstreet.entity.ParamEntity;
import com.ufmobile.mstreet.util.CommonUtil;
import com.ufmobile.mstreet.util.DateUtil;
import com.ufmobile.platform.Exception.BusinessException;
import com.ufmobile.platform.log.RunTimeLogger;
/**
* <p>
* 充值卡管理
* <p>
* 创建日期:Dec 14, 2006
*
* @author Janet Feng
* @since v3.0
*/
public @Stateless
class CardBean extends BaseBean implements Card {
public static final String v2DsName = "V2DataSource";
public void addCard(CardEntity card) throws CardException {
RunTimeLogger.info(getClass(), "新增充值卡");
CardDAO cardDao = new CardDAO(getManager());
cardDao.addCard(card);
}
public void updateCard(CardEntity card) throws CardException {
RunTimeLogger.info(getClass(), "更新充值卡");
CardDAO cardDao = new CardDAO(getManager());
cardDao.updateCard(card);
// 更新v2
Object o = getContext().lookup("java:/"+v2DsName);
if (o != null) {
DataSource ds = (DataSource) o;
String[] sCardCode = new String[1];
sCardCode[0] = card.getCode();
cardDao.changeV2CardState(ds, card.getFreeze(), sCardCode);
}
}
public void deleteCard(Long cardId) throws CardException {
RunTimeLogger.info(getClass(), "删除充值卡");
CardDAO cardDao = new CardDAO(getManager());
cardDao.deleteCard(cardId);
}
public CardEntity getCardEntity(Long cardId) throws CardException {
RunTimeLogger.info(getClass(), "获得充值卡信息");
CardDAO cardDao = new CardDAO(getManager());
return cardDao.getCardEntity(cardId);
}
public void importCard(List<CardEntity> cards) throws CardException {
if (cards == null)
throw new CardException("Cards can't be null");
new CardDAO(getManager()).importCard(cards);
}
public String checkImportedCard(int formIndex,UserInfo user,List<String[]> source) throws CardException{
List<String> codeList = getListcodes(source);
List<CardEntity> importcarList=new ArrayList<CardEntity>();
int successNumber = 0;
StringBuffer lineErrorMsg = new StringBuffer("");
for(int i=0;i<source.size();i++){
String[] s = source.get(i);
String errmsg = getErrorMsg(formIndex,i+2,s ,codeList);
if(CommonUtil.isNull(errmsg)){
String code = s[0].trim(); // 卡号
String password = s[1].trim(); // 密码
/**2007-10-23:充值卡导入密码加密*/
StringBuffer sEncryptBuf = new StringBuffer("");
int nn = SecurityTool.encrypt(password, sEncryptBuf);
if(nn<0){
throw new CardException(this, "充值卡导入密码加密失败。");
}
password = sEncryptBuf.toString();
String type = s[2].trim(); // 类型(0-流量 1-服务)
String amount = s[3].trim(); // 金额
String agentCode = s[4].trim(); // 代理商编号
String sSalesDate = s[5].trim(); // 销售日期
Date saleDate = null;
try{
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
saleDate = new Date(df.parse(sSalesDate).getTime());
}catch(ParseException e){
}
String state = s[6].trim(); // 状态(0-正常 1-冻结)
CardEntity card = new CardEntity();
card.setCode(code);
card.setPassword(password);
card.setCardtype(new Integer(type));
card.setMoneny(new BigDecimal(amount));
card.setAgent(agentCode);
card.setSaledate(saleDate);
if ("0".equals(state))
card.setFreeze(false);
else
card.setFreeze(true);
// 默认设置
card.setDr(new Integer(0));
card.setIslast(Boolean.TRUE);
card.setIsover(Boolean.FALSE);
if (user != null){
card.setCardoperator(user.getUsrid() + "");
}
card.setOpdate(new Date(System.currentTimeMillis()));
importcarList.add(card);
successNumber++;
}else{
lineErrorMsg.append(errmsg);
}
}
/**数据库倒入操作*/
if(importcarList!=null && importcarList.size()>0){
importCard(importcarList);
}
return lineErrorMsg.toString();
}
public List<String> getListcodes(List<String[]> source) throws CardException{
String codes = "";
if(source!=null && source.size()>0){
for(int i=0;i<source.size();i++){
String[] s = source.get(i);
String code = s[0].trim();
if(i!=0)
codes = codes +",";
codes = codes +"'" + code +"'";
}
}
List<String> codeList = QueryAllCardCode(codes);
return codeList;
}
public String getErrorMsg(int formIndex,int i,String[] s ,List<String> cardcodeList) throws CardException{
StringBuffer lineError = new StringBuffer("");
if (s==null||s.length!=7){
int linenumber = i+formIndex;
lineError.append("第" + linenumber + "行有错误:数据格式不正确");
return lineError.toString();
}
String code = s[0].trim(); // 卡号
String password = s[1].trim(); // 密码
String type = s[2].trim(); // 类型(0-流量 1-服务)
String amount = s[3].trim(); // 金额
String sSalesDate = s[5].trim(); // 销售日期
Date saleDate = null;
String state = s[6].trim(); // 状态(0-正常 1-冻结)
if (CommonUtil.isNull(code)) {
lineError.append("卡号不为空!");
}else{
if (cardcodeList.contains(code)) {
lineError.append("充值卡号已存在,");
}
}
if (CommonUtil.isNull(password)) {
lineError.append("密码不为空!");
}
if (CommonUtil.isNull(type)) {
lineError.append("卡类型不能为空!");
}else{
if(!"0".equals(type) && !"1".equals(type)) {
lineError.append("卡类型只能为0或1,");
}
}
try {
double amountNum = Double.parseDouble(amount);
if (amountNum < 0 || amountNum > 1000000) {
lineError.append("金额不能小于0,大于1,000,000");
}
} catch (Exception e) {
lineError.append("请输入正确的金额,");
}
if (CommonUtil.isNull(sSalesDate)) {
lineError.append("销售日期不能为空,");
} else {
try {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
saleDate = new Date(df.parse(sSalesDate).getTime());
} catch (ParseException e) {
lineError.append("销售日期格式不正确,");
}
}
if (CommonUtil.isNull(state)) {
lineError.append("卡状态不能为空,");
} else {
if (!"0".equals(state) && !"1".equals(state)) {
lineError.append("卡状态只能为0或1,");
}
}
StringBuffer resultMsg = new StringBuffer("");
if(!lineError.toString().equals("") ){
int linenumber = i+formIndex;
resultMsg.append( "第" + linenumber+ "行有错误:" + lineError.toString());
}else{
cardcodeList.add(code);
}
return resultMsg.toString();
}
public int getAllCardsTotal() throws CardException {
RunTimeLogger.info(getClass(), "获得所有充值卡记录数");
CardDAO cardDao = new CardDAO(getManager());
return cardDao.queryCardsTotal(null, null, -1, -1, -1,null,null,null,null,null,null,UserInfo.Operator);
}
public List<CardEntity> getAllCardsByPage(int beginIndex, int maxNumber) throws CardException {
RunTimeLogger.info(getClass(), "获得所有充值卡信息");
CardDAO cardDao = new CardDAO(getManager());
return cardDao.queryCards(beginIndex, maxNumber, null, null, -1, -1, -1,null,null,null,null,null,null,UserInfo.Operator);
}
public List<CardEntity> findCardByAgentCode(int beginIndex, int maxNumber, String agentCode, int dr,int queryType) throws CardException {
RunTimeLogger.info(getClass(), "分页按代理商编号和状态查询充值卡");
CardDAO cardDao = new CardDAO(getManager());
return cardDao.queryCards(beginIndex, maxNumber, agentCode, null, -1, dr, -1,null,null,null,null,null,null,queryType);
}
public int findCardByAgentCodeTotal(String agentCode, int dr,int queryType) throws CardException {
RunTimeLogger.info(getClass(), "按代理商编号和状态查询充值卡总数");
CardDAO cardDao = new CardDAO(getManager());
return cardDao.queryCardsTotal(agentCode, null, -1, dr, -1,null,null,null,null,null,null,queryType);
}
public void changeCardState(Boolean bFreeze, long... cardId) throws CardException {
RunTimeLogger.info(getClass(), "更改充值卡状态");
CardDAO cardDao = new CardDAO(getManager());
cardDao.changeCardState(bFreeze, cardId);
// 更新v2
Object o = getContext().lookup("java:/"+v2DsName);
if (o != null) {
DataSource ds = (DataSource) o;
String[] sCardCode = new String[cardId.length];
for (int i = 0; i < cardId.length; i++) {
CardEntity card = this.getCardEntity(cardId[i]);
sCardCode[i] = card.getCode();
}
cardDao.changeV2CardState(ds, bFreeze, sCardCode);
}
}
public List<CardEntity> queryCardsByPage(int beginIndex,
int maxNumber,
String agentCode,
String cardCode,
int isFreeze,
int dr,
int cardType,
String accountName,
String streetName,
Date fillBeginDate,
Date fillEndDate,
Date saleBeginDate,
Date saleEndDate,
int queryType) throws CardException {
RunTimeLogger.info(getClass(), "查询充值卡");
CardDAO cardDao = new CardDAO(getManager());
initDate(fillBeginDate,fillEndDate);
initDate(saleBeginDate,saleEndDate);
return cardDao.queryCards(beginIndex, maxNumber, agentCode, cardCode, isFreeze, dr, cardType, accountName,streetName,fillBeginDate,fillEndDate,saleBeginDate,saleEndDate,queryType);
}
public List<String[]>prepareCardData(int beginIndex,
int maxNumber,
String agentCode,
String cardCode,
int isFreeze,
int dr,
int cardType,
String accountName,
String streetName,
Date fillBeginDate,
Date fillEndDate,
Date saleBeginDate,
Date saleEndDate,
UserInfo userinfo) throws CardException
{
List<String[]> list = new ArrayList<String[]>();
if(userinfo.getType().intValue() ==1 ){//总部
list.add(0,CardEntity.getCardTitle());
}else if(userinfo.getType().intValue() == 2){//代理商
list.add(0,CardEntity.getCardTitle1());
}
initDate(fillBeginDate,fillEndDate);
initDate(saleBeginDate,saleEndDate);
List<CardEntity> ce = this.queryCardsByPage(beginIndex,
maxNumber,
agentCode,
cardCode,
isFreeze,
dr,
cardType,
accountName,
streetName,
fillBeginDate,
fillEndDate,
saleBeginDate,
saleEndDate,
userinfo.getType().intValue());
if(ce != null && ce.size() > 0)
{
for(int i = 0;i < ce.size();i++)
{
if(userinfo.getType().intValue() ==1 ){//总部
list.add(i + 1,ce.get(i).convertCard());
}else if(userinfo.getType().intValue() == 2){//代理商
list.add(i + 1,ce.get(i).convertCard1());
}
}
}
return list;
}
public int queryCardsTotal(String agentCode,
String cardCode,
int isFreeze,
int dr,
int cardType,
String accountName,
String streetName,
Date fillBeginDate,
Date fillEndDate,
Date saleBeginDate,
Date saleEndDate,
int queryType) throws CardException {
RunTimeLogger.info(getClass(), "查询充值卡总数");
CardDAO cardDao = new CardDAO(getManager());
initDate(fillBeginDate,fillEndDate);
initDate(saleBeginDate,saleEndDate);
return cardDao.queryCardsTotal(agentCode, cardCode, isFreeze, dr, cardType, accountName, streetName,fillBeginDate,fillEndDate,saleBeginDate,saleEndDate,queryType);
}
public CardEntity findCardByCode(String cardCode) throws CardException {
RunTimeLogger.info(getClass(), "根据卡号查询充值卡");
CardDAO cardDao = new CardDAO(getManager());
return cardDao.findCardByCardCode(cardCode);
}
public void fillMoney(CardEntity card, String userName) throws CardException {
CardDAO cardDao = new CardDAO(getManager());
cardDao.fillMoney(card, userName);
Object o = getContext().lookup("java:/"+v2DsName);
if (o != null) {
DataSource ds = (DataSource) o;
cardDao.deleteV2Card(ds, card.getCode());
}
}
public List<String> QueryAllCardCode(String codes) throws CardException {
CardDAO cardDao = new CardDAO(getManager());
return cardDao.QueryAllCardCode(codes);
}
private void initDate(Date beginDate,Date endDate)
{
Calendar cal = Calendar.getInstance();
if(beginDate != null && endDate != null)
{
DateUtil.compareDate(beginDate,endDate);
}
if(beginDate != null)
{
cal.setTime(beginDate);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE,0);
cal.set(Calendar.SECOND,0);
cal.set(Calendar.MILLISECOND,0);
beginDate = cal.getTime();
}
if(endDate != null)
{
cal.setTime(endDate);
cal.add(Calendar.DATE, 1);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE,59);
cal.set(Calendar.SECOND,59);
cal.set(Calendar.MILLISECOND,999);
endDate = cal.getTime();
}
}
public void modifyCardAgent(String oldAgentCode, String newAgentCode) throws BusinessException
{
if(oldAgentCode == null || newAgentCode == null)
throw new BusinessException(this,"代理商编号不能为空");
CardDAO cardDao = new CardDAO(getManager());
List<CardEntity> list = cardDao.findCardByAgent(oldAgentCode);
if(list == null)
return;
for(int i=0;i < list.size();i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -