package com.yeshi.buwan.dao.vip;
|
|
import com.yeshi.buwan.dao.base.BaseDao;
|
import com.yeshi.buwan.domain.vip.OrderType;
|
import com.yeshi.buwan.domain.vip.OrderRecord;
|
import org.springframework.stereotype.Repository;
|
|
import java.io.Serializable;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
@Repository
|
public class OrderRecordDao extends BaseDao<OrderRecord> {
|
|
class DaoQueryResult {
|
public String hql;
|
public Serializable[] params;
|
|
public DaoQueryResult(String hql, Serializable[] params) {
|
this.hql = hql;
|
this.params = params;
|
}
|
}
|
|
|
private DaoQueryResult getHql(DaoQuery daoQuery) {
|
|
String hql = "from OrderRecord r where 1=1";
|
List<Serializable> params = new ArrayList<>();
|
|
if (daoQuery.state != null) {
|
hql += " and r.state=?";
|
params.add(daoQuery.state);
|
}
|
|
if (daoQuery.uid != null) {
|
hql += " and r.uid=?";
|
params.add(daoQuery.uid);
|
}
|
|
if (daoQuery.orderType != null) {
|
hql += " and r.orderType=?";
|
params.add(daoQuery.orderType);
|
}
|
|
if (daoQuery.minCreateTime != null) {
|
hql += " and r.createTime>=? ";
|
params.add(daoQuery.minCreateTime);
|
}
|
|
|
if (daoQuery.maxCreateTime != null) {
|
hql += " and r.createTime < ?";
|
params.add(daoQuery.maxCreateTime);
|
}
|
|
|
hql += " order by r.createTime desc";
|
Serializable[] ps = new Serializable[params.size()];
|
params.toArray(ps);
|
|
return new DaoQueryResult(hql, ps);
|
}
|
|
|
public List<OrderRecord> list(DaoQuery daoQuery) {
|
DaoQueryResult queryResult = getHql(daoQuery);
|
return super.list(queryResult.hql, daoQuery.start, daoQuery.count, queryResult.params);
|
}
|
|
|
public long count(DaoQuery daoQuery) {
|
DaoQueryResult queryResult = getHql(daoQuery);
|
return super.getCount(queryResult.hql, queryResult.params);
|
}
|
|
public static class DaoQuery {
|
public Integer state;
|
public OrderType orderType;
|
public String uid;
|
public int start;
|
public int count;
|
public Date minCreateTime;
|
public Date maxCreateTime;
|
}
|
|
}
|