📄 rankdao.java
字号:
package cn.zqnet8.rank.dao;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import cn.zqnet8.rank.entity.RankInfo;
import cn.zqnet8.rank.util.CommonUtil;
public class RankDao implements java.io.Serializable{
/*
* 获取当前日期的字符串形式的年月
*/
public String getCurMonth(boolean isFormat){
Date date=new Date();
String strDate="";
int intYear=date.getYear()+1900;
System.out.println(intYear);
int month=date.getMonth();//不加1得到的是上一个月的月份
String strMonth="";
if(month<10){
strMonth="0"+month;
}else{
strMonth=""+month;
}
if(month==0){
strMonth="11";
}
if(month==1){
strMonth="12";
}
strDate=intYear+strMonth;
if(isFormat){
strDate=intYear+"年"+strMonth+"月";
}
return strDate;
}
/*
* 获取当前月份的排行榜信息
*/
public List getCurrentMonthRankInfo(){
RankDao rd=new RankDao();
String strDate=rd.getCurMonth(false);
System.out.println("strDate:"+strDate);
return rd.getRankInfoByMonth(strDate);
}
/*
* 根据传入的年份和月份获取该月的会员排行榜信息
*/
public List getRankInfoByMonth(String strDate){
String hql="from RankInfo where rankMonth.monthDate ='"+strDate+" '";
System.out.println("hql:+++++++++++++++"+hql);
// List list=CommonUtil.getAllByHQL(hql);
Session session=CommonUtil.getSession();
Query query=session.createQuery(hql);
return query.list();
}
/*
* 获取每月消费排行第一的顾客信息。
*
*/
public List getFirstCustInfo(){
String hql="from RankInfo ri where rankLevel.levelId=1 order by ri.rankMonth.monthId desc";
return CommonUtil.getAllByHQL(hql);
}
/*
* 根据排行编号保存该排行信息
*/
public boolean updateRankInfo(int rankID){
CommonUtil.closeSession();
boolean res=false;
RankDao rd=new RankDao();
RankInfo ri=rd.getRankInfoByID(rankID);
System.out.println("执行更新了2222222222222");
ri.setReceiveDate(new Date());
ri.setIsReceived(1);
res=rd.updateRankInfo(ri);
return res;
}
/*
* 根据排行编号获取该排行信息
*/
public RankInfo getRankInfoByID(int rankID){
Session session=CommonUtil.getSession();
RankInfo ri=(RankInfo)session.get(RankInfo.class, rankID);
// CommonUtil.closeSession();
return ri;
}
/*
* 将排行信息保存到数据库。
*/
public boolean updateRankInfo(RankInfo ri){
boolean bool=false;
System.out.println("执行更新了——");
Session session=CommonUtil.getSession();
Transaction tx=session.beginTransaction();
session.update(ri);
tx.commit();
bool=true;
CommonUtil.closeSession();
return bool;
}
/*
* 使该月所有未领取的会员的状态变为“逾期未领”
*/
public boolean changeToTimeOver(String strDate){
boolean bool=false;
String hql="from RankInfo where isReceived=0 and rankMonth.monthDate='"+strDate+"'";
if(Integer.parseInt(strDate)<0){
return false;
}
Session session=CommonUtil.getSession();
Transaction tx=session.beginTransaction();
Query query=session.createQuery(hql);
List list=query.list();
Iterator ita=list.iterator();
while(ita.hasNext()){
RankInfo ri=(RankInfo)ita.next();
ri.setIsReceived(2);
session.update(ri);
}
tx.commit();
bool=true;
CommonUtil.closeSession();
return bool;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -