| 3389 |
varun.gupt |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
| 6466 |
amit.gupta |
3 |
import in.shop2020.model.v1.user.Coupon;
|
|
|
4 |
import in.shop2020.model.v1.user.PromotionService.Client;
|
| 3389 |
varun.gupt |
5 |
import in.shop2020.model.v1.user.UserContextService;
|
|
|
6 |
import in.shop2020.support.utils.ReportsUtils;
|
|
|
7 |
import in.shop2020.thrift.clients.PromotionClient;
|
|
|
8 |
import in.shop2020.thrift.clients.UserClient;
|
|
|
9 |
|
| 6466 |
amit.gupta |
10 |
import java.util.ArrayList;
|
|
|
11 |
import java.util.List;
|
|
|
12 |
|
| 3389 |
varun.gupt |
13 |
import javax.servlet.http.HttpServletRequest;
|
|
|
14 |
import javax.servlet.http.HttpSession;
|
|
|
15 |
|
|
|
16 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
17 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 3936 |
chandransh |
18 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
19 |
import org.apache.struts2.convention.annotation.Results;
|
| 3389 |
varun.gupt |
20 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
| 5148 |
varun.gupt |
21 |
import org.json.JSONException;
|
| 3389 |
varun.gupt |
22 |
import org.json.JSONObject;
|
|
|
23 |
import org.slf4j.Logger;
|
|
|
24 |
import org.slf4j.LoggerFactory;
|
|
|
25 |
|
|
|
26 |
@InterceptorRefs({
|
|
|
27 |
@InterceptorRef("defaultStack"),
|
|
|
28 |
@InterceptorRef("login")
|
|
|
29 |
})
|
| 3936 |
chandransh |
30 |
@Results({
|
|
|
31 |
@Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
32 |
})
|
| 3389 |
varun.gupt |
33 |
public class PromotionsController implements ServletRequestAware {
|
|
|
34 |
|
|
|
35 |
private static Logger log = LoggerFactory.getLogger(PromotionsController.class);
|
|
|
36 |
|
|
|
37 |
private HttpServletRequest request;
|
|
|
38 |
private HttpSession session;
|
|
|
39 |
private Client promotionClient;
|
|
|
40 |
private UserContextService.Client userClient;
|
|
|
41 |
|
|
|
42 |
private List<CouponInfo> coupons;
|
| 6360 |
amit.gupta |
43 |
private List<VoucherInfo> vouchers;
|
| 3389 |
varun.gupt |
44 |
|
|
|
45 |
@Override
|
|
|
46 |
public void setServletRequest(HttpServletRequest req) {
|
|
|
47 |
this.request = req;
|
|
|
48 |
this.session = req.getSession();
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
public String index() {
|
| 5149 |
varun.gupt |
52 |
if (!ReportsUtils.canAccessReport((Long) session.getAttribute(ReportsUtils.ROLE), request.getServletPath())) {
|
|
|
53 |
return "authfail";
|
|
|
54 |
}
|
| 3389 |
varun.gupt |
55 |
try {
|
|
|
56 |
PromotionClient promotionServiceClient = new PromotionClient();
|
|
|
57 |
promotionClient = promotionServiceClient.getClient();
|
|
|
58 |
|
|
|
59 |
UserClient userServiceClient = new UserClient();
|
|
|
60 |
userClient = userServiceClient.getClient();
|
|
|
61 |
|
|
|
62 |
coupons = new ArrayList<CouponInfo>();
|
|
|
63 |
CouponInfo couponInfo;
|
|
|
64 |
|
| 6360 |
amit.gupta |
65 |
long voucherIssued = 0;
|
|
|
66 |
long voucherRedeemed = 0;
|
|
|
67 |
long voucherInCart = 0;
|
|
|
68 |
double voucherAmountRedeemed = 0d;
|
|
|
69 |
|
| 3389 |
varun.gupt |
70 |
for (Coupon coupon: promotionClient.getActiveCoupons()) {
|
| 6360 |
amit.gupta |
71 |
if(!promotionClient.isGiftVoucher(coupon.getCouponCode())) {
|
|
|
72 |
try {
|
|
|
73 |
couponInfo = new CouponInfo(coupon.getCouponCode());
|
|
|
74 |
couponInfo.setPaymentsCount(promotionClient.getSuccessfulPaymentCountForCoupon(coupon.getCouponCode()));
|
|
|
75 |
couponInfo.setCartsCount(userClient.getCartsWithCouponCount(coupon.getCouponCode()));
|
| 5148 |
varun.gupt |
76 |
|
| 6360 |
amit.gupta |
77 |
String args = coupon.getArguments();
|
|
|
78 |
String description;
|
| 5148 |
varun.gupt |
79 |
|
| 6360 |
amit.gupta |
80 |
if(args == null) {
|
|
|
81 |
description = promotionClient.getRuleDocString(coupon.getPromotion().getRuleExecutionSrc());
|
|
|
82 |
couponInfo.setDescription("<pre>" + description + "</pre>");
|
|
|
83 |
|
|
|
84 |
} else {
|
|
|
85 |
JSONObject argsJSON = new JSONObject(args);
|
|
|
86 |
|
|
|
87 |
description = "Rs." + argsJSON.getString("discount");
|
|
|
88 |
description += " off on " + argsJSON.getString("handset_display_name");
|
|
|
89 |
description += " (Max " + argsJSON.getString("usage_limit") + " uses)";
|
|
|
90 |
|
|
|
91 |
couponInfo.setDescription("<i>" + description + "</i>");
|
|
|
92 |
}
|
|
|
93 |
coupons.add(couponInfo);
|
| 5148 |
varun.gupt |
94 |
|
| 6360 |
amit.gupta |
95 |
} catch (JSONException e) {
|
|
|
96 |
log.error("" + e);
|
| 5148 |
varun.gupt |
97 |
}
|
| 6466 |
amit.gupta |
98 |
} else if (coupon.getPromotion().getId() == 26){
|
| 6360 |
amit.gupta |
99 |
try {
|
|
|
100 |
voucherIssued++;
|
| 6466 |
amit.gupta |
101 |
long redeemedCount = promotionClient.getSuccessfulPaymentCountForCoupon(coupon.getCouponCode());
|
|
|
102 |
voucherRedeemed += redeemedCount;
|
| 6360 |
amit.gupta |
103 |
voucherInCart += userClient.getCartsWithCouponCount(coupon.getCouponCode());
|
|
|
104 |
JSONObject argsJSON = new JSONObject(coupon.getArguments());
|
| 6466 |
amit.gupta |
105 |
if(redeemedCount > 0){
|
| 6360 |
amit.gupta |
106 |
voucherAmountRedeemed += argsJSON.getDouble("discount");
|
|
|
107 |
}
|
|
|
108 |
} catch (Exception e) {
|
|
|
109 |
log.error("" + e);
|
|
|
110 |
}
|
| 3389 |
varun.gupt |
111 |
}
|
| 6360 |
amit.gupta |
112 |
VoucherInfo v = new VoucherInfo("Recharge Gift Voucher");
|
|
|
113 |
v.setTotalAmountRedeemed(voucherAmountRedeemed);
|
|
|
114 |
v.setTotalVoucherIssued(voucherIssued);
|
|
|
115 |
v.setTotalVouchersRedeemed(voucherRedeemed);
|
|
|
116 |
v.setTotalVouchersInCart(voucherInCart);
|
|
|
117 |
vouchers = new ArrayList<VoucherInfo>();
|
|
|
118 |
vouchers.add(v);
|
| 3389 |
varun.gupt |
119 |
}
|
|
|
120 |
} catch (Exception e) {
|
| 5148 |
varun.gupt |
121 |
log.error("" + e);
|
| 3389 |
varun.gupt |
122 |
}
|
|
|
123 |
return "index";
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
public List<CouponInfo> getActiveCoupons() {
|
|
|
127 |
return coupons;
|
|
|
128 |
}
|
| 6360 |
amit.gupta |
129 |
|
|
|
130 |
public List<VoucherInfo> getActiveGiftVouchers() {
|
|
|
131 |
return vouchers;
|
|
|
132 |
}
|
| 3389 |
varun.gupt |
133 |
|
|
|
134 |
public static class CouponInfo {
|
|
|
135 |
private String code;
|
|
|
136 |
private long paymentsCount;
|
|
|
137 |
private long cartsCount;
|
|
|
138 |
private String description;
|
|
|
139 |
|
|
|
140 |
public CouponInfo(String code) {
|
|
|
141 |
this.code = code;
|
|
|
142 |
paymentsCount = -1;
|
|
|
143 |
cartsCount = -1;
|
|
|
144 |
description = null;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
public void setPaymentsCount(long paymentsCount) {
|
|
|
148 |
this.paymentsCount = paymentsCount;
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
public void setCartsCount(long cartsCount) {
|
|
|
152 |
this.cartsCount = cartsCount;
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
public void setDescription(String desc) {
|
|
|
156 |
description = desc;
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
public String getCode() {
|
|
|
160 |
return this.code;
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
public long getPaymentsCount() {
|
|
|
164 |
return this.paymentsCount;
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
public long getCartsCount() {
|
|
|
168 |
return this.cartsCount;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
public String getDescription() {
|
|
|
172 |
return description;
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
public String toString() {
|
|
|
176 |
return code + " " + paymentsCount + " " + cartsCount + " " + description;
|
|
|
177 |
}
|
|
|
178 |
}
|
| 6360 |
amit.gupta |
179 |
|
|
|
180 |
public static class VoucherInfo {
|
|
|
181 |
private String promotionName;
|
|
|
182 |
private long totalVoucherIssued;
|
|
|
183 |
private long totalVouchersInCart;
|
|
|
184 |
private long totalVouchersRedeemed;
|
|
|
185 |
private double totalAmountRedeemed;
|
|
|
186 |
|
|
|
187 |
public VoucherInfo(String promotionName){
|
|
|
188 |
this.promotionName = promotionName;
|
|
|
189 |
this.totalVoucherIssued = 0;
|
|
|
190 |
this.totalAmountRedeemed = 0d;
|
|
|
191 |
this.totalVouchersInCart = 0;
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
public String getPromotionName() {
|
|
|
195 |
return promotionName;
|
|
|
196 |
}
|
|
|
197 |
public void setPromotionName(String promotionName) {
|
|
|
198 |
this.promotionName = promotionName;
|
|
|
199 |
}
|
|
|
200 |
public long getTotalVoucherIssued() {
|
|
|
201 |
return totalVoucherIssued;
|
|
|
202 |
}
|
|
|
203 |
public void setTotalVoucherIssued(long totalVoucherIssued) {
|
|
|
204 |
this.totalVoucherIssued = totalVoucherIssued;
|
|
|
205 |
}
|
|
|
206 |
public long getTotalVouchersInCart() {
|
|
|
207 |
return totalVouchersInCart;
|
|
|
208 |
}
|
|
|
209 |
public void setTotalVouchersInCart(long totalVouchersInCart) {
|
|
|
210 |
this.totalVouchersInCart = totalVouchersInCart;
|
|
|
211 |
}
|
|
|
212 |
public long getTotalVouchersRedeemed() {
|
|
|
213 |
return totalVouchersRedeemed;
|
|
|
214 |
}
|
|
|
215 |
public void setTotalVouchersRedeemed(long totalVouchersRedeemed) {
|
|
|
216 |
this.totalVouchersRedeemed = totalVouchersRedeemed;
|
|
|
217 |
}
|
|
|
218 |
public double getTotalAmountRedeemed() {
|
|
|
219 |
return totalAmountRedeemed;
|
|
|
220 |
}
|
|
|
221 |
public void setTotalAmountRedeemed(double totalAmountRedeemed) {
|
|
|
222 |
this.totalAmountRedeemed = totalAmountRedeemed;
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
}
|
| 3389 |
varun.gupt |
227 |
}
|