Subversion Repositories SmartDukaan

Rev

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

Rev 4361 Rev 4411
Line 6... Line 6...
6
import in.shop2020.model.v1.order.LineItem;
6
import in.shop2020.model.v1.order.LineItem;
7
import in.shop2020.model.v1.order.OrderStatus;
7
import in.shop2020.model.v1.order.OrderStatus;
8
import in.shop2020.model.v1.order.TransactionService.Client;
8
import in.shop2020.model.v1.order.TransactionService.Client;
9
import in.shop2020.thrift.clients.TransactionClient;
9
import in.shop2020.thrift.clients.TransactionClient;
10
 
10
 
-
 
11
import java.io.ByteArrayOutputStream;
-
 
12
import java.io.File;
-
 
13
import java.io.FileNotFoundException;
-
 
14
import java.io.FileOutputStream;
-
 
15
import java.io.IOException;
11
import java.util.ArrayList;
16
import java.util.ArrayList;
-
 
17
import java.util.Calendar;
12
import java.util.Date;
18
import java.util.Date;
-
 
19
import java.util.GregorianCalendar;
-
 
20
import java.util.HashMap;
13
import java.util.List;
21
import java.util.List;
-
 
22
import java.util.Map;
-
 
23
 
-
 
24
import org.slf4j.Logger;
-
 
25
import org.slf4j.LoggerFactory;
14
 
26
 
15
/**
27
/**
16
 * This class is a facade to the Transaction service and should be used to
28
 * This class is a facade to the Transaction service and should be used to
17
 * access all order specific data which requires some kind of transformation.
29
 * access all order specific data which requires some kind of transformation.
18
 * 
30
 * 
19
 * @author Chandranshu
31
 * @author Chandranshu
20
 * 
32
 * 
21
 */
33
 */
22
public class TransactionUtils {
34
public class TransactionUtils {
-
 
35
	private static String courierDetailsPath = "/CourierDetailReports";
-
 
36
	private static Logger logger = LoggerFactory.getLogger(TransactionUtils.class);
-
 
37
	
23
	/**
38
	/**
24
	 * The human user is concerned only with a consolidated view of actionable
39
	 * The human user is concerned only with a consolidated view of actionable
25
	 * orders. Orders with different statuses in the database can be part of the
40
	 * orders. Orders with different statuses in the database can be part of the
26
	 * same consolidated view. This method uses a mapping of <i>type</i> to
41
	 * same consolidated view. This method uses a mapping of <i>type</i> to
27
	 * <i>status</i> to get all such orders and return them as order beans.
42
	 * <i>status</i> to get all such orders and return them as order beans.
Line 102... Line 117...
102
	public static boolean markOrdersAsManifested(long warehouseId, String providerId, boolean cod){
117
	public static boolean markOrdersAsManifested(long warehouseId, String providerId, boolean cod){
103
		try {
118
		try {
104
			long provider_id = Long.parseLong(providerId);
119
			long provider_id = Long.parseLong(providerId);
105
			TransactionClient client = new TransactionClient();
120
			TransactionClient client = new TransactionClient();
106
			Client c = client.getClient();
121
			Client c = client.getClient();
-
 
122
			if(generateCourierDetailsFile(warehouseId, provider_id, cod)){
107
			return c.markOrdersAsManifested(warehouseId, provider_id, cod);
123
				return c.markOrdersAsShippedFromWarehouse(warehouseId, provider_id, cod);	
-
 
124
			}else{
-
 
125
				return false;
-
 
126
			}
-
 
127
			
108
		}catch(Exception e){
128
		}catch(Exception e){
109
			e.printStackTrace();
129
			e.printStackTrace();
110
			return false;
130
			return false;
111
		}
131
		}
112
	}
132
	}
113
 
133
 
-
 
134
	private static boolean generateCourierDetailsFile(long warehouseId, long providerId, boolean isCod){
-
 
135
		Calendar date = new GregorianCalendar();
-
 
136
		int year = date.get(Calendar.YEAR);
-
 
137
		int month = date.get(Calendar.MONTH) +1;
-
 
138
		int day = date.get(Calendar.DAY_OF_MONTH);
-
 
139
		
-
 
140
		String fileNameSuffix = "-" + warehouseId + "-"+ providerId + "-" + year + "-" + month + "-" + day;
-
 
141
		String mergedFileNameSuffix = "-" + 0 + "-"+ providerId + "-" + year + "-" + month + "-" + day;
-
 
142
		if(isCod){
-
 
143
		    fileNameSuffix = "cod" + fileNameSuffix ;
-
 
144
			mergedFileNameSuffix = "cod" + mergedFileNameSuffix;
-
 
145
		}
-
 
146
		else{
-
 
147
		    fileNameSuffix = "prepaid" + fileNameSuffix;
-
 
148
			mergedFileNameSuffix = "prepaid" + mergedFileNameSuffix;
-
 
149
		}
-
 
150
		
-
 
151
		try {
-
 
152
			String fileName = courierDetailsPath + "/courier-details-" + fileNameSuffix + ".xls";
-
 
153
			FileOutputStream f = new FileOutputStream(fileName);
-
 
154
			File file = new File(fileName);
-
 
155
			if(file.exists()){
-
 
156
				return false;
-
 
157
			}
-
 
158
			CourierDetailsGenerator courierDetailsGenerator = new CourierDetailsGenerator();
-
 
159
			ByteArrayOutputStream baosXLS = courierDetailsGenerator.generateCourierDetails(warehouseId, providerId, isCod);
-
 
160
			baosXLS.writeTo(f);
-
 
161
			f.close();
-
 
162
		} catch (FileNotFoundException e) {
-
 
163
			logger.error("Unable to create the courier details file", e);
-
 
164
		} catch (IOException e) {
-
 
165
			logger.error("Unable to create the courier details file", e);
-
 
166
		}
-
 
167
	
-
 
168
		// FIXME This is not a useful way. We need to fix it asap. This is done just to give ease to courier company.
-
 
169
		CourierDetailsReportMerger merger = new CourierDetailsReportMerger();
-
 
170
		try {
-
 
171
			FileOutputStream f = new FileOutputStream(courierDetailsPath + "/courier-details-" + mergedFileNameSuffix + ".xls");
-
 
172
			Map<Long, String> warehouseIdFileNames = new HashMap<Long, String>();
-
 
173
		
-
 
174
			String p1;
-
 
175
			if(isCod){
-
 
176
				p1 = "cod";
-
 
177
			}
-
 
178
			else{
-
 
179
				p1 = "prepaid";
-
 
180
			}
-
 
181
			String fName;
-
 
182
			fName = courierDetailsPath + "/courier-details-" + p1 + "-" + 1 + "-"+ providerId + "-" + year + "-" + month + "-" + day + ".xls";
-
 
183
			warehouseIdFileNames.put(1L, fName);
-
 
184
			fName = courierDetailsPath + "/courier-details-" + p1 + "-" + 2 + "-"+ providerId + "-" + year + "-" + month + "-" + day + ".xls";
-
 
185
			warehouseIdFileNames.put(2L, fName);
-
 
186
			fName = courierDetailsPath + "/courier-details-" + p1 + "-" + 5 + "-"+ providerId + "-" + year + "-" + month + "-" + day + ".xls";
-
 
187
			warehouseIdFileNames.put(5L, fName);
-
 
188
			ByteArrayOutputStream binXLS = merger.mergeCourierDetailsReports(warehouseIdFileNames, 1, true);
-
 
189
			binXLS.writeTo(f);
-
 
190
			f.close();
-
 
191
		} catch (FileNotFoundException e) {
-
 
192
			logger.error("Error while creating the Courier Details report", e);
-
 
193
		} catch (IOException e) {
-
 
194
			logger.error("IO error while writing the Courier Details report", e);
-
 
195
		}
-
 
196
		return true;
-
 
197
	}
-
 
198
	
114
	/**
199
	/**
115
	 * 
200
	 * 
116
	 * @param t_order
201
	 * @param t_order
117
	 *            A thrift order object with line items.
202
	 *            A thrift order object with line items.
118
	 * @return an Order bean which can be used for rendering on the client side.
203
	 * @return an Order bean which can be used for rendering on the client side.