Subversion Repositories SmartDukaan

Rev

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