Subversion Repositories SmartDukaan

Rev

Rev 2058 | Rev 2345 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2058 Rev 2340
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
-
 
3
import in.shop2020.model.v1.order.LineItem;
-
 
4
import in.shop2020.model.v1.order.Order;
3
import in.shop2020.model.v1.order.TransactionServiceException;
5
import in.shop2020.model.v1.order.TransactionServiceException;
4
import in.shop2020.model.v1.user.Affiliate;
6
import in.shop2020.model.v1.user.Affiliate;
5
import in.shop2020.model.v1.user.MasterAffiliate;
7
import in.shop2020.model.v1.user.MasterAffiliate;
6
import in.shop2020.model.v1.user.TrackLog;
8
import in.shop2020.model.v1.user.TrackLog;
7
import in.shop2020.model.v1.user.UserContextService.Client;
9
import in.shop2020.model.v1.user.UserContextService.Client;
-
 
10
import in.shop2020.payments.Payment;
-
 
11
import in.shop2020.thrift.clients.PaymentServiceClient;
-
 
12
import in.shop2020.thrift.clients.TransactionServiceClient;
8
import in.shop2020.thrift.clients.UserContextServiceClient;
13
import in.shop2020.thrift.clients.UserContextServiceClient;
9
 
14
 
10
import java.io.ByteArrayOutputStream;
15
import java.io.ByteArrayOutputStream;
11
import java.io.IOException;
16
import java.io.IOException;
12
import java.text.ParseException;
17
import java.text.ParseException;
Line 64... Line 69...
64
	
69
	
65
	public String create()	{
70
	public String create()	{
66
	    try   {
71
	    try   {
67
	        long mAfId = Long.parseLong(request.getParameter("masterAffiliate"));
72
	        long mAfId = Long.parseLong(request.getParameter("masterAffiliate"));
68
            UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
73
            UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
-
 
74
            PaymentServiceClient paymentServiceClient = new PaymentServiceClient();
-
 
75
            TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
-
 
76
            
69
            Client userClient = userContextServiceClient.getClient();
77
            Client userClient = userContextServiceClient.getClient();
-
 
78
            in.shop2020.payments.PaymentService.Client paymentClient = paymentServiceClient.getClient();
-
 
79
            in.shop2020.model.v1.order.TransactionService.Client transactionClient = transactionServiceClient.getClient();
-
 
80
            
70
 
81
            
71
            List<Map<String, String>> contentRows = new LinkedList<Map<String,String>>(); 
82
            List<Map<String, String>> contentRows = new LinkedList<Map<String,String>>(); 
72
            MasterAffiliate mAffiliate = userClient.getMasterAffiliateById(mAfId);
83
            MasterAffiliate mAffiliate = userClient.getMasterAffiliateById(mAfId);
73
            for (Affiliate aff : userClient.getAffiliatesByMasterAffiliate(mAfId)) {
84
            for (Affiliate aff : userClient.getAffiliatesByMasterAffiliate(mAfId)) {
74
                for (TrackLog tracklog : userClient.getTrackLogsByAffiliate(aff.getId())) {
85
                for (TrackLog tracklog : userClient.getTrackLogsByAffiliate(aff.getId())) {
75
                    Map<String, String> contentRow = new HashMap<String, String>();
86
                    Map<String, String> contentRow = new HashMap<String, String>();
Line 77... Line 88...
77
                    contentRow.put("affiliate", aff.getName());
88
                    contentRow.put("affiliate", aff.getName());
78
                    contentRow.put("affiliateUrl", aff.getUrl());
89
                    contentRow.put("affiliateUrl", aff.getUrl());
79
                    contentRow.put("date",String.valueOf(tracklog.getAddedOn()));
90
                    contentRow.put("date",String.valueOf(tracklog.getAddedOn()));
80
                    contentRow.put("event", tracklog.getEvent());
91
                    contentRow.put("event", tracklog.getEvent());
81
                    contentRow.put("url", tracklog.getUrl());
92
                    contentRow.put("url", tracklog.getUrl());
-
 
93
                    if (tracklog.getEvent() == "payment success") {
-
 
94
                        try {
-
 
95
                            long paymentId = Long.parseLong(tracklog.getData()
-
 
96
                                    .substring(0,
-
 
97
                                            tracklog.getData().indexOf('(')));
-
 
98
                            Payment payment = paymentClient
-
 
99
                                    .getPayment(paymentId);
-
 
100
                            List<Order> orders = transactionServiceClient
-
 
101
                                    .getClient().getOrdersForTransaction(
-
 
102
                                            payment.getMerchantTxnId(),
-
 
103
                                            payment.getUserId());
-
 
104
                            contentRow.put("amount",
-
 
105
                                    Double.toString(payment.getAmount()));
-
 
106
                            for (Order order : orders) {
-
 
107
                                List<LineItem> items = order.getLineitems();
-
 
108
                                String itemString = "";
-
 
109
                                for (LineItem item : items) {
-
 
110
                                    itemString += item.getBrand() + " "
-
 
111
                                            + item.getModel_name() + " "
-
 
112
                                            + item.getModel_number() + "("
-
 
113
                                            + item.getQuantity() + ", "
-
 
114
                                            + item.getTotal_price() + "), ";
-
 
115
                                }
-
 
116
                                contentRow.put("items", itemString);
-
 
117
                            }
-
 
118
                        } catch (Exception e) {
-
 
119
                            e.printStackTrace();
-
 
120
                        }
-
 
121
                    }
82
                    contentRow.put("data", tracklog.getData());
122
                    contentRow.put("data", tracklog.getData());
83
                    contentRows.add(contentRow);
123
                    contentRows.add(contentRow);
84
                }
124
                }
85
            }
125
            }
86
             
126
             
Line 164... Line 204...
164
	    affHeaderRow.createCell(1).setCellValue("Affiliate Url");
204
	    affHeaderRow.createCell(1).setCellValue("Affiliate Url");
165
	    affHeaderRow.createCell(2).setCellValue("Date");
205
	    affHeaderRow.createCell(2).setCellValue("Date");
166
	    affHeaderRow.createCell(3).setCellValue("Event");
206
	    affHeaderRow.createCell(3).setCellValue("Event");
167
	    affHeaderRow.createCell(4).setCellValue("Url");
207
	    affHeaderRow.createCell(4).setCellValue("Url");
168
	    affHeaderRow.createCell(5).setCellValue("Data");
208
	    affHeaderRow.createCell(5).setCellValue("Data");
-
 
209
	    affHeaderRow.createCell(6).setCellValue("Items");
-
 
210
	    affHeaderRow.createCell(7).setCellValue("Amount");
169
	    for (int i=0; i<6 ;i++) {
211
	    for (int i=0; i<8 ;i++) {
170
	        affHeaderRow.getCell(i).setCellStyle(style);
212
	        affHeaderRow.getCell(i).setCellStyle(style);
171
	    }
213
	    }
172
	    
214
	    
173
		for( Map<String, String> contentRow : contentRows) {
215
		for( Map<String, String> contentRow : contentRows) {
174
			affSerialNo++;
216
			affSerialNo++;
Line 179... Line 221...
179
			commContentRow.createCell(2).setCellValue(new Date(Long.parseLong(contentRow.get("date"))));
221
			commContentRow.createCell(2).setCellValue(new Date(Long.parseLong(contentRow.get("date"))));
180
			commContentRow.getCell(2).setCellStyle(dateCellStyle);
222
			commContentRow.getCell(2).setCellStyle(dateCellStyle);
181
            commContentRow.createCell(3).setCellValue(contentRow.get("event"));
223
            commContentRow.createCell(3).setCellValue(contentRow.get("event"));
182
			commContentRow.createCell(4).setCellValue(contentRow.get("url"));
224
			commContentRow.createCell(4).setCellValue(contentRow.get("url"));
183
			commContentRow.createCell(5).setCellValue(contentRow.get("data"));
225
			commContentRow.createCell(5).setCellValue(contentRow.get("data"));
-
 
226
			if (contentRow.containsKey("items")) {
-
 
227
			    commContentRow.createCell(6).setCellValue(contentRow.get("items"));
-
 
228
			}
-
 
229
			if (contentRow.containsKey("amount")) {
-
 
230
	            commContentRow.createCell(7).setCellValue(contentRow.get("amount"));
-
 
231
			}
184
		}
232
		}
185
        for (int i = 0; i<6; i++) {
233
        for (int i = 0; i<8; i++) {
186
            affSheet.autoSizeColumn(i);
234
            affSheet.autoSizeColumn(i);
187
        }
235
        }
188
	}
236
	}
189
 
237
 
190
	public String getErrorMsg() {
238
	public String getErrorMsg() {
Line 192... Line 240...
192
	}
240
	}
193
	
241
	
194
	public List<MasterAffiliate> getMasterAffiliates() {
242
	public List<MasterAffiliate> getMasterAffiliates() {
195
        return masterAffiliates;
243
        return masterAffiliates;
196
    }
244
    }
197
}
-
 
198
245
}
-
 
246