Subversion Repositories SmartDukaan

Rev

Rev 33917 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
33917 ranu 1
package com.spice.profitmandi.dao.model;
2
 
3
import javax.persistence.*;
4
import java.util.Objects;
5
 
6
@Entity
7
@NamedNativeQueries({
8
        @NamedNativeQuery(name = "RbmTarget.getWarehouseWiseMonthlyTarget",
9
                query = "SELECT a.auth_id," +
10
                        "       a.first_name," +
11
                        "       a.warehouse_id," +
12
                        "       SUM(a.target)  AS monthly_target" +
13
                        " FROM (" +
14
                        "         SELECT au.id AS auth_id," +
33939 ranu 15
                        "                CONCAT(au.first_name, ' ', au.last_name) AS first_name," +
33917 ranu 16
                        "                fs.id AS fofo_id," +
17
                        "                fs.target," +
18
                        "                fs.warehouse_id" +
19
                        "         FROM auth.auth_user au" +
20
                        "                  JOIN cs.position p ON p.auth_user_id = au.id" +
21
                        "                  JOIN cs.partner_position pp ON pp.position_id = p.id" +
22
                        "                  JOIN fofo.fofo_store fs ON fs.id = pp.partner_id" +
23
                        "         WHERE pp.partner_id != 0" +
24
                        "           AND p.category_id = 18" +
25
                        "           AND p.escalation_type = 'L1'" +
26
                        "         UNION ALL" +
27
                        "         SELECT au.id AS auth_id," +
33939 ranu 28
                        "                CONCAT(au.first_name, ' ', au.last_name) AS first_name," +
33917 ranu 29
                        "                fs.id AS fofo_id," +
30
                        "                fs.target," +
31
                        "                fs.warehouse_id" +
32
                        "         FROM auth.auth_user au" +
33
                        "                  JOIN cs.position p ON p.auth_user_id = au.id" +
34
                        "                  JOIN cs.partner_position pp ON pp.position_id = p.id" +
35
                        "                  JOIN cs.region r ON pp.region_id = r.id" +
36
                        "                  JOIN cs.partner_region pr ON pr.region_id = pp.region_id" +
37
                        "                  JOIN fofo.fofo_store fs ON fs.id = pr.fofo_id" +
38
                        "         WHERE pp.partner_id = 0" +
39
                        "           AND p.category_id = 18" +
40
                        "           AND p.escalation_type = 'L1') a" +
41
                        " WHERE a.target != 0" +
42
                        " GROUP BY a.auth_id, a.warehouse_id",
43
                resultSetMapping = "WarehouseWiseMonthlyTarget"),
44
 
45
})
46
 
47
@SqlResultSetMappings({
48
 
49
        @SqlResultSetMapping(name = "WarehouseWiseMonthlyTarget",
50
                classes = {@ConstructorResult(targetClass = WarehouseRbmTargetModel.class,
51
                        columns = {
52
                                @ColumnResult(name = "auth_id", type = Integer.class),
53
                                @ColumnResult(name = "first_name ", type = String.class),
54
                                @ColumnResult(name = "warehouse_id ", type = Integer.class),
55
                                @ColumnResult(name = "monthly_target ", type = Float.class)
56
                        }
57
                )}
58
        )
59
 
60
})
61
 
62
public class WarehouseRbmTargetModel {
63
    int authId;
64
    String rbmName;
65
    int warehouseId;
66
    float monthlyTarget;
67
    // Synthetic primary key to satisfy JPA's requirement
68
    @Id
69
    @GeneratedValue(strategy = GenerationType.IDENTITY)
70
    private Long id; // This will not be used in the query but satisfies JPA.
71
 
72
    public WarehouseRbmTargetModel(int authId, String rbmName, int warehouseId, float monthlyTarget) {
73
        this.authId = authId;
74
        this.rbmName = rbmName;
75
        this.warehouseId = warehouseId;
76
        this.monthlyTarget = monthlyTarget;
77
    }
78
 
79
    public int getAuthId() {
80
        return authId;
81
    }
82
 
83
    public void setAuthId(int authId) {
84
        this.authId = authId;
85
    }
86
 
87
    public String getRbmName() {
88
        return rbmName;
89
    }
90
 
91
    public void setRbmName(String rbmName) {
92
        this.rbmName = rbmName;
93
    }
94
 
95
    public int getWarehouseId() {
96
        return warehouseId;
97
    }
98
 
99
    public void setWarehouseId(int warehouseId) {
100
        this.warehouseId = warehouseId;
101
    }
102
 
103
    public float getMonthlyTarget() {
104
        return monthlyTarget;
105
    }
106
 
107
    public void setMonthlyTarget(float monthlyTarget) {
108
        this.monthlyTarget = monthlyTarget;
109
    }
110
 
111
    @Override
112
    public boolean equals(Object o) {
113
        if (this == o) return true;
114
        if (o == null || getClass() != o.getClass()) return false;
115
        WarehouseRbmTargetModel that = (WarehouseRbmTargetModel) o;
116
        return authId == that.authId && warehouseId == that.warehouseId && Float.compare(monthlyTarget, that.monthlyTarget) == 0 && Objects.equals(rbmName, that.rbmName);
117
    }
118
 
119
    @Override
120
    public int hashCode() {
121
        return Objects.hash(authId, rbmName, warehouseId, monthlyTarget);
122
    }
123
 
124
    @Override
125
    public String toString() {
126
        return "WarehouseRbmTargetModel{" +
127
                "authId=" + authId +
128
                ", rbmName='" + rbmName + '\'' +
129
                ", warehouseId=" + warehouseId +
130
                ", monthlyTarget=" + monthlyTarget +
131
                '}';
132
    }
133
}