admin
2021-07-30 19533a17aa55fafc70d0a385928e785cb50e1ebc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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;
    }
 
}