Subversion Repositories SmartDukaan

Rev

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