| | |
| | | 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; |
| | | |
| | | private String getHql(DaoQuery daoQuery) { |
| | | 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=" + daoQuery.state; |
| | | hql += " and r.state=?"; |
| | | params.add(daoQuery.state); |
| | | } |
| | | |
| | | if (daoQuery.uid != null) { |
| | | hql += " and r.uid=" + daoQuery.uid; |
| | | hql += " and r.uid=?"; |
| | | params.add(daoQuery.uid); |
| | | } |
| | | |
| | | if (daoQuery.orderType != null) { |
| | | hql += " and r.orderType='" + daoQuery.orderType+"'"; |
| | | 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"; |
| | | return hql; |
| | | Serializable[] ps = new Serializable[params.size()]; |
| | | params.toArray(ps); |
| | | |
| | | return new DaoQueryResult(hql, ps); |
| | | } |
| | | |
| | | |
| | | public List<OrderRecord> list(DaoQuery daoQuery) { |
| | | return super.list(getHql(daoQuery), daoQuery.start, daoQuery.count, null); |
| | | DaoQueryResult queryResult = getHql(daoQuery); |
| | | return super.list(queryResult.hql, daoQuery.start, daoQuery.count, queryResult.params); |
| | | } |
| | | |
| | | |
| | | public long count(DaoQuery daoQuery) { |
| | | return super.getCount(getHql(daoQuery), null); |
| | | DaoQueryResult queryResult = getHql(daoQuery); |
| | | return super.getCount(queryResult.hql, queryResult.params); |
| | | } |
| | | |
| | | public static class DaoQuery { |
| | |
| | | public String uid; |
| | | public int start; |
| | | public int count; |
| | | public Date minCreateTime; |
| | | public Date maxCreateTime; |
| | | } |
| | | |
| | | } |