Subversion Repositories SmartDukaan

Rev

Rev 34114 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
34103 ranu 1
package com.spice.profitmandi.dao.model;
2
 
3
import javax.persistence.*;
4
import java.util.Objects;
5
 
6
 
7
@Entity
8
@NamedNativeQueries({
9
        @NamedNativeQuery(name = "RBM.RbmBilledFofoId",
10
                query = "SELECT" +
11
                        "    a.auth_id," +
12
                        "    a.rbm_Name," +
13
                        "    a.fofo_id," +
14
                        "    a.fofo_code," +
15
                        "    (CASE WHEN MAX(o.billing_timestamp) IS NOT NULL THEN 'Billed' ELSE 'Not billed' END) AS status" +
16
                        " FROM (" +
17
                        "         SELECT" +
18
                        "             au.id AS auth_id," +
19
                        "             CONCAT(au.first_name, ' ', au.last_name) AS Rbm_Name," +
20
                        "             fs.id AS fofo_id," +
21
                        "             fs.code as fofo_code" +
22
                        "         FROM auth.auth_user au" +
23
                        "                  JOIN cs.position p ON p.auth_user_id = au.id" +
24
                        "                  JOIN cs.partner_position pp ON pp.position_id = p.id" +
25
                        "                  JOIN fofo.fofo_store fs ON fs.id = pp.partner_id" +
26
                        "         WHERE pp.partner_id != 0" +
27
                        "           AND p.category_id = 18" +
28
                        "           AND p.escalation_type = 'L1'" +
29
                        "           AND fs.active = 1" +
30
                        "           AND fs.internal = false" +
31
                        "         UNION ALL" +
32
                        "         SELECT" +
33
                        "             au.id AS auth_id," +
34
                        "             CONCAT(au.first_name, ' ', au.last_name) AS Rbm_Name," +
35
                        "             fs.id AS fofo_id," +
36
                        "             fs.code as fofo_code" +
37
                        "         FROM auth.auth_user au" +
38
                        "                  JOIN cs.position p ON p.auth_user_id = au.id" +
39
                        "                  JOIN cs.partner_position pp ON pp.position_id = p.id" +
40
                        "                  JOIN cs.region r ON pp.region_id = r.id" +
41
                        "                  JOIN cs.partner_region pr ON pr.region_id = pp.region_id" +
42
                        "                  JOIN fofo.fofo_store fs ON fs.id = pr.fofo_id" +
43
                        "         WHERE pp.partner_id = 0" +
44
                        "           AND p.category_id = 18" +
45
                        "           AND fs.active = 1" +
46
                        "           AND fs.internal = false" +
47
                        "           AND p.escalation_type = 'L1'" +
48
                        "     ) a" +
49
                        "    LEFT JOIN transaction.order o ON o.customer_id = a.fofo_id" +
50
                        "    AND o.billing_timestamp >= :startDate" +
51
                        "    AND o.billing_timestamp < :endDate" +
52
                        " GROUP BY a.auth_id, a.Rbm_Name, a.fofo_id",
53
                resultSetMapping = "BilledFofoId"),
54
 
55
})
56
 
57
@SqlResultSetMappings({
58
 
59
        @SqlResultSetMapping(name = "BilledFofoId",
60
                classes = {@ConstructorResult(targetClass = RbmBilledFofoIdsModel.class,
61
                        columns = {
62
                                @ColumnResult(name = "auth_id", type = Integer.class),
63
                                @ColumnResult(name = "rbm_name", type = String.class),
64
                                @ColumnResult(name = "fofo_id", type = Integer.class),
65
                                @ColumnResult(name = "fofo_code", type = String.class),
66
                                @ColumnResult(name = "status ", type = String.class),
67
                        }
68
                )}
69
        )
70
 
71
})
72
 
73
public class RbmBilledFofoIdsModel {
74
    int authId;
75
    String rbmName;
76
    int fofoId;
77
    String partnerCode;
78
    String status;
79
 
80
    // Synthetic primary key to satisfy JPA's requirement
81
    @Id
82
    @GeneratedValue(strategy = GenerationType.IDENTITY)
83
    private Long id; // This will not be used in the query but satisfies JPA.
84
 
85
    public RbmBilledFofoIdsModel(int authId, String rbmName, int fofoId, String partnerCode, String status) {
86
        this.authId = authId;
87
        this.rbmName = rbmName;
88
        this.fofoId = fofoId;
89
        this.partnerCode = partnerCode;
90
        this.status = status;
91
    }
92
 
93
    public int getAuthId() {
94
        return authId;
95
    }
96
 
97
    public void setAuthId(int authId) {
98
        this.authId = authId;
99
    }
100
 
101
    public String getRbmName() {
102
        return rbmName;
103
    }
104
 
105
    public void setRbmName(String rbmName) {
106
        this.rbmName = rbmName;
107
    }
108
 
109
    public int getFofoId() {
110
        return fofoId;
111
    }
112
 
113
    public void setFofoId(int fofoId) {
114
        this.fofoId = fofoId;
115
    }
116
 
117
    public String getpartnerCode() {
118
        return partnerCode;
119
    }
120
 
121
    public void setpartnerCode(String partnerCode) {
122
        this.partnerCode = partnerCode;
123
    }
124
 
125
    public String getStatus() {
126
        return status;
127
    }
128
 
129
    public void setStatus(String status) {
130
        this.status = status;
131
    }
132
 
133
    @Override
134
    public String toString() {
135
        return "RbmBilledFofoIdsModel{" +
136
                "authId=" + authId +
137
                ", rbmName='" + rbmName + '\'' +
138
                ", fofoId=" + fofoId +
139
                ", partnerCode='" + partnerCode + '\'' +
140
                ", status='" + status + '\'' +
141
                '}';
142
    }
143
 
144
    @Override
145
    public boolean equals(Object o) {
146
 
147
        if (this == o) return true;
148
        if (o == null || getClass() != o.getClass()) return false;
149
        RbmBilledFofoIdsModel that = (RbmBilledFofoIdsModel) o;
150
        return authId == that.authId && fofoId == that.fofoId && Objects.equals(rbmName, that.rbmName) && Objects.equals(partnerCode, that.partnerCode) && Objects.equals(status, that.status);
151
    }
152
 
153
    @Override
154
    public int hashCode() {
155
        return Objects.hash(authId, rbmName, fofoId, partnerCode, status);
156
    }
157
}
158
 
159