⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cardbean.java

📁 国内很牛的软件公司花费两年半开发的用EJB3开发的代码,采用STRUTS和EJB3,目前系统进行第二版.所以拿出来共享
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		{
			CardEntity ce = list.get(i);
			ce.setAgent(newAgentCode);
			cardDao.updateCard(ce);
		}
		
	}	
	
	/**
	 * @author chengjy
	 * @param  staArea,
	 * @param  agentCode
	 * @param  cardType
	 * @param  beginDate
	 * @param  endDate
	 * @exception BusinessException
	 * @since 1.1
	 * 2007-09-06
	 * 
	 * */
	public Integer staCostCardNum(Integer staArea,
			                        String agentCode,
			                        Integer cardType,
			                        Date beginDate,
			                        Date endDate) throws BusinessException{
		
		RunTimeLogger.info(getClass(), "统计代理商充值卡总额数量");
		CardDAO cardDao = new CardDAO(getManager());
		Integer total = cardDao.queryStaCostCardNum(staArea, agentCode, cardType, beginDate, endDate);
		return total;
	}
	
	/**
	 * @author chengjy
	 * @param  staArea,
	 * @param  agentCode
	 * @param  cardType
	 * @param  beginDate
	 * @param  endDate
	 * @param  beginIndex
	 * @param  maxNumber
	 * @exception BusinessException
	 * @since 1.1
	 * 2007-09-06
	 * 
	 * */
	public List<CostCardStatiDetail> staCostCard(Integer staArea,
			                        String agentCode,
			                        Integer cardType,
			                        Date beginDate,
			                        Date endDate,
			                        int beginIndex, 
									int maxNumber) throws BusinessException
	{
		RunTimeLogger.info(getClass(), "查询统计代理商充值卡总额列表");
		CardDAO cardDao = new CardDAO(getManager());
		List<Object[]> list = cardDao.queryStaCostCard(staArea, agentCode, cardType, beginDate, endDate, beginIndex, maxNumber); //获取统计信息列表
		Hashtable<String,String> agenttable = cardDao.getAgentname();                //获得代理商编码和简称的hash表

		ArrayList<CostCardStatiDetail> ccsd = new ArrayList<CostCardStatiDetail>();  //返回值

		
		//构建返回信息
		if(list!=null && list.size()>0){
			for(int i=0;i<list.size();i++){
				Object[] obj = list.get(i);
			CostCardStatiDetail statiDetail = new CostCardStatiDetail();
			if(obj[0]!= null){
				String code = obj[0].toString();
				statiDetail.setAgentCode(code);
				
				String name = agenttable.get(code);
				if(name != null){
					statiDetail.setAgentName(name);
				}
			}
			
			if(obj[1]!=null){
				Integer cardtype1 = ((BigDecimal) obj[1]).intValue();
				statiDetail.setCardType(cardtype1.intValue());
			}	
			
			
			if(obj[2]!=null){
				BigDecimal mount = (BigDecimal) obj[2];
				statiDetail.setAmount(mount);
			}
			
			if(obj[3]!=null){
				String staDate = obj[3].toString();
				String years = staDate.substring(0,4);
				
                String lastdateofyears = years + "-12-31";
            	Date lastdate = DateUtil.parse(lastdateofyears, "yyyy-MM-dd");
            	Calendar call = Calendar.getInstance();
            	call.setFirstDayOfWeek(Calendar.MONDAY);
            	call.setTime(lastdate);
            	int maxweek = call.get(Calendar.WEEK_OF_YEAR);	
				if(staArea ==1){
				 Long year1 = Long.parseLong(years);
				 
				 String weeks = staDate.substring(5,7);
				 if(weeks.startsWith("0")){
					 weeks = weeks.substring(1,2);
				 }
				 
				 getBeginDayofWeek(2007,52);
                 Long week1 = Long.parseLong(weeks);
                 Date begindt = getBeginDayofWeek(year1.intValue(),week1.intValue());
                 Date enddt = null;
                 
                  //对最后一周和第一周的处理
//                 if(week1.intValue()==1){
//                	 Date enddts = getBeginDayofWeek(year1.intValue(),2);
//                	 enddt = DateUtil.getDate(enddts, Calendar.DAY_OF_MONTH, -1);
//                 }else if(week1.intValue() == maxweek){
//                	 enddt = lastdate;
//                 }else{
                      enddt = DateUtil.getDate(begindt, Calendar.DAY_OF_MONTH, 6);
//                 }
                 
                 //将日期与区间进行比较,控制时间区间取值

                 if(begindt.before(beginDate)){
                	 begindt = beginDate;
                  }
                 if(enddt.after(endDate)){
                	 enddt =  endDate;
                 }
                 
                 String area = DateUtil.format(begindt, "yyyy-MM-dd") + "--" + DateUtil.format(enddt, "yyyy-MM-dd");
                 statiDetail.setStatiArea(area);
				}else{
					statiDetail.setStatiArea(staDate);
				}
				
			}
			ccsd.add(statiDetail);
		}
			
	}		
					
		return ccsd;
   }
	
	private Date getBeginDayofWeek(int year,int week){ //根据年份和这年的第几周取这周的开始日期

		String yeardate = String.valueOf(year) + "-01-01";
		Date dt = DateUtil.parse(yeardate, "yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.setFirstDayOfWeek(Calendar.MONDAY);
		cal.setTime(dt);
		cal.set(Calendar.WEEK_OF_YEAR, week);
		Date beginDate = cal.getTime();
		return beginDate;
	}

	private List<CardEntity> queryHisCard() throws CardException {
		
		CardDAO cardDao = new CardDAO(getManager());
		List<CardEntity> list = cardDao.queryAllHisCard();
		return list;
	}

public boolean encryHisCard() throws CardException {
		
	   /**2007-11-05:首先判断是否已经更新过*/
	   CardDAO cardDao = new CardDAO(getManager());	    
	   ParamEntity entity= cardDao.queryParam();	   
	   String paramvalue = entity.getParamvalue();		
	   if(paramvalue.equals("1")){//历史充值卡已经更新过

			return false;
		}		
		/**2007-10-24:对取出的数据加密*/
		List<CardEntity> list1 = queryHisCard();
//		list1 =list1.subList(0,4);
		int batchCount = 100;
		int fromIndex = -batchCount;
		int toIndex = fromIndex + batchCount;
		
		try {
			while (toIndex < list1.size()) {
				fromIndex += batchCount;
				toIndex = fromIndex + batchCount;
				if (toIndex >= list1.size()){
					toIndex = list1.size();
				}
				List<CardEntity> list2 = new ArrayList<CardEntity>();
				list2.addAll(list1.subList(fromIndex, toIndex));
				/**2007-10-24:每100条充值卡处理加密*/
				encryCard(list2);				
			}
		} catch (Exception e) {
			//toIndex = fromIndex;
			RunTimeLogger.error(this, "充值卡加密失败。", e);
			throw new CardException(this, "充值卡加密失败。");
		}
		
		entity.setParamvalue("1");
		new CardDAO(getManager()).updateParamValue(entity);
		return true;
	}
	
	private void encryCard(List<CardEntity> list) throws CardException{
		if(list!=null && list.size()>0){
			List<CardEntity> list3 = new ArrayList<CardEntity>();
			CardDAO cardDao = new CardDAO(getManager());
			for(int i=0;i<list.size(); i++){
				CardEntity cardentity = list.get(i);
				String password = cardentity.getPassword();
				StringBuffer sEcryptBuf = new StringBuffer("");
				int nn = SecurityTool.encrypt(password, sEcryptBuf);
				if(nn<0){
					throw new CardException(this, "充值卡充值加密失败。");
				}
				password = sEcryptBuf.toString();//加密后密文

				cardentity.setPassword(password);	
				list3.add(cardentity);
				/***2007-10-24:更新数据库*/				
			}
			cardDao.updateBatchCard(list3);
		}				
	}
	
	public boolean ifupdate(){
		/**2007-11-06:已经升级过积分*/
		CardDAO cardDao = new CardDAO(getManager());	    
		ParamEntity entity= cardDao.queryParam2();	   
		String paramvalue = entity.getParamvalue();		
		if(paramvalue.equals("1")){//已经升级过积分

			return true;
		}
		return false;
	}
	
	public boolean updateScore(Long sysID){
		
		Connection conn = null;
	 	PreparedStatement pstmt = null;
	 	boolean issuccess = false;
	 	try{
		conn = this.getConnection(sysID);
		pstmt=conn.prepareStatement("update tb_booth b set b.score = b.score + ?1 where accountid = ?2");

		
	   	List resultlist = this.getAllAcountScore(6l);
	   	int size = resultlist.size();

	   	for(int m = 0 ; m < size ; m ++){
	   		AcountScoreInfo asi = (AcountScoreInfo)resultlist.get(m);
	   		pstmt.setString(1,asi.getScore().toString()); 
	    	pstmt.setString(2,asi.getAccountid()); 
	    	pstmt.addBatch();
	    	pstmt.clearParameters();
	    	
	    	if(m%100==0){
	    		 pstmt.executeBatch(); 
	    		 issuccess = true;
	    	}
	    	if(m%100!=0&&size==m+1){
	    		pstmt.executeBatch();
	    		issuccess = true;
	    	}
	   	}
		
	   	/**2007-11-06:已经升级过积分*/
		CardDAO cardDao = new CardDAO(getManager());	    
		ParamEntity entity= cardDao.queryParam2();	   
	   	entity.setParamvalue("1");
	   	cardDao.updateParamValue(entity);
	   	
	 	}catch(Exception e){
	 		e.printStackTrace();
	   		issuccess = false;
	   	}finally{
			close(conn, pstmt);
		}	

	   
	 	return issuccess;
	}
	
	
	public List getAllAcountScore(long ruleid){
		BoothDAO bdao = new BoothDAO();
		bdao.setManager(getManager());
		BoothScoreAdjustDAO bsadao = new BoothScoreAdjustDAO();
		bsadao.setManager(getManager());
		AccountLogDAO2 aldao2 = new AccountLogDAO2(getManager());
		aldao2.setManager(getManager());
		BoothScoreRuleDAO bsrdao = new BoothScoreRuleDAO();
		bsrdao.setManager(getManager());
		
		BoothScoreRuleEntity bsre = null;
		bsre = bsrdao.getBoothScoreRuleById(ruleid);
		
		List resultlist = new ArrayList();
		
		List list = new ArrayList();
		list = aldao2.getAllAcountId();
		int acountsize = list.size();
		RunTimeLogger.info(this, "升级商铺积分开始 共有帐户 :" +acountsize+" 个");
		try
		{
		for(int j = 0 ; j < acountsize ; j ++){
			String accountid = list.get(j).toString();
			Accountlog2Entity ae = null ;
			RunTimeLogger.info(this, "开始升级商铺帐户id accountid :" +accountid);
			if(accountid!=null){
				ae = aldao2.queryByAccountID(accountid,BussinessType.debuct);
			}
			Long cost = null ;
			if(ae!=null){
				if(ae.getAccouttotal()!=null){
					cost = ae.getAccouttotal().longValue();
					RunTimeLogger.info(this, "升级商铺帐户cost  :" +cost);
				}
				Long rulecost = bsre.getCost();
				Long rulescore = bsre.getScore();
				Long score = (cost / rulecost) * rulescore ;
				RunTimeLogger.info(this, "升级商铺帐户rulecost  :" +rulecost);
				RunTimeLogger.info(this, "升级商铺帐户rulescore  :" +rulescore);
				RunTimeLogger.info(this, "升级商铺帐户score  :" +score);
				
				AcountScoreInfo asi = new AcountScoreInfo();
				asi.setAccountid(accountid);
				asi.setScore(score);
				
				resultlist.add(asi);
			}
		}
		}
		catch(Exception e)
		{
			RunTimeLogger.error(this, "商铺积分升级异常");
			e.printStackTrace();
		}
		RunTimeLogger.info(this, "完成返回 resultlist size  :" +resultlist.size());
		return resultlist;
	}
	
	public boolean calculateBootHistoryScore(long ruleid){
		
		BoothDAO bdao = new BoothDAO();
		bdao.setManager(getManager());
		BoothScoreAdjustDAO bsadao = new BoothScoreAdjustDAO();
		bsadao.setManager(getManager());
		AccountLogDAO2 aldao2 = new AccountLogDAO2(getManager());
		aldao2.setManager(getManager());
		BoothScoreRuleDAO bsrdao = new BoothScoreRuleDAO();
		bsrdao.setManager(getManager());
		
		BoothScoreRuleEntity bsre = null;
		bsre = bsrdao.getBoothScoreRuleById(ruleid);
		
		List<BoothEntity> boothlist = null;
		boothlist = bdao.getAllBooth();
		int size = boothlist.size();
				
		
		List list = new ArrayList();
		list = aldao2.getAllAcountId();
		int acountsize = list.size();
		RunTimeLogger.info(this, "升级商铺积分开始 共有帐户 :" +acountsize+" 个");
		try
		{
		for(int j = 0 ; j < acountsize ; j ++){
			String accountid = list.get(j).toString();
			Accountlog2Entity ae = null ;
			RunTimeLogger.info(this, "开始升级商铺帐户id accountid :" +accountid);
			if(accountid!=null){
				ae = aldao2.queryByAccountID(accountid,BussinessType.debuct);
			}
			Long cost = null ;
			if(ae!=null){
				if(ae.getAccouttotal()!=null){
					cost = ae.getAccouttotal().longValue();
					RunTimeLogger.info(this, "升级商铺帐户cost  :" +cost);
				}
				Long rulecost = bsre.getCost();
				Long rulescore = bsre.getScore();
				Long score = (cost / rulecost) * rulescore ;
				RunTimeLogger.info(this, "升级商铺帐户rulecost  :" +rulecost);
				RunTimeLogger.info(this, "升级商铺帐户rulescore  :" +rulescore);
				RunTimeLogger.info(this, "升级商铺帐户score  :" +score);
				
				bdao.modifyBoothScore(score, accountid);
				
			}
		}
		}
		catch(Exception e)
		{
			RunTimeLogger.error(this, "商铺积分升级异常");
			e.printStackTrace();
			return false;
		}
		
		return true;
		
		/*
		try
		{
		RunTimeLogger.info(this, "升级商铺积分开始 共有待升级商铺 :" +size+" 个");
		for(int i = 0 ; i < size ; i ++){
			BoothEntity be = boothlist.get(i);
			String accountid = be.getAccountid();		
			RunTimeLogger.info(this, "开始升级商铺帐户id accountid :" +accountid);
			Accountlog2Entity ae = null ;
			if(accountid!=null){
				ae = aldao2.queryByAccountID(accountid,BussinessType.debuct);
			}
			Long cost = null ;
			if(ae!=null){
				if(ae.getAccouttotal()!=null){
					cost = ae.getAccouttotal().longValue();
					RunTimeLogger.info(this, "升级商铺帐户cost  :" +cost);
				}
				Long rulecost = bsre.getCost();
				Long rulescore = bsre.getScore();
				Long score = (cost / rulecost) * rulescore ;
				RunTimeLogger.info(this, "升级商铺帐户rulecost  :" +rulecost);
				RunTimeLogger.info(this, "升级商铺帐户rulescore  :" +rulescore);
				RunTimeLogger.info(this, "升级商铺帐户score  :" +score);
				Long newscore = be.getScore() + score;
				RunTimeLogger.info(this, "升级商铺帐户newscore  :" +newscore);
				be.setScore(newscore);
				bdao.modifyBoothScore(be);
			}
			RunTimeLogger.info(this, "结束升级商铺帐户id accountid :" +accountid);
		}
		}
		catch(Exception e)
		{
			RunTimeLogger.error(this, "商铺积分升级异常");
			e.printStackTrace();
			return false;
		}
		
		*/
		
		
	}
	
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -