| 9761 |
amar.kumar |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.model.v1.catalog.CatalogService;
|
|
|
4 |
import in.shop2020.model.v1.catalog.EbayItem;
|
|
|
5 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
6 |
import in.shop2020.model.v1.inventory.HoldInventoryDetail;
|
|
|
7 |
import in.shop2020.model.v1.inventory.InventoryService;
|
|
|
8 |
import in.shop2020.model.v1.inventory.InventoryType;
|
|
|
9 |
import in.shop2020.model.v1.inventory.ItemInventory;
|
|
|
10 |
import in.shop2020.model.v1.inventory.Warehouse;
|
|
|
11 |
import in.shop2020.model.v1.order.OrderSource;
|
|
|
12 |
import in.shop2020.support.utils.ReportsUtils;
|
|
|
13 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
14 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
15 |
|
|
|
16 |
import java.io.File;
|
|
|
17 |
import java.io.FileInputStream;
|
|
|
18 |
import java.io.IOException;
|
|
|
19 |
import java.text.SimpleDateFormat;
|
|
|
20 |
import java.util.Date;
|
|
|
21 |
import java.util.HashMap;
|
|
|
22 |
import java.util.List;
|
|
|
23 |
import java.util.Map;
|
|
|
24 |
|
|
|
25 |
import javax.servlet.http.HttpServletRequest;
|
|
|
26 |
import javax.servlet.http.HttpSession;
|
|
|
27 |
|
|
|
28 |
import org.apache.commons.io.FileUtils;
|
|
|
29 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
30 |
import org.apache.poi.ss.usermodel.Cell;
|
|
|
31 |
import org.apache.poi.ss.usermodel.Row;
|
|
|
32 |
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
33 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
34 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
35 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
36 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
37 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
38 |
import org.apache.thrift.transport.TTransportException;
|
|
|
39 |
import org.slf4j.Logger;
|
|
|
40 |
import org.slf4j.LoggerFactory;
|
|
|
41 |
|
|
|
42 |
import com.opensymphony.xwork2.ActionSupport;
|
|
|
43 |
|
|
|
44 |
@SuppressWarnings("serial")
|
|
|
45 |
@InterceptorRefs({
|
|
|
46 |
@InterceptorRef("defaultStack"),
|
|
|
47 |
@InterceptorRef("login")
|
|
|
48 |
})
|
|
|
49 |
@Results({
|
|
|
50 |
@Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
51 |
})
|
|
|
52 |
public class HoldInventoryController extends ActionSupport implements ServletRequestAware {
|
|
|
53 |
|
|
|
54 |
public class ItemStockDetail {
|
|
|
55 |
private long itemId;
|
|
|
56 |
private long available;
|
|
|
57 |
private long reserved;
|
|
|
58 |
private long held;
|
|
|
59 |
|
|
|
60 |
public ItemStockDetail(long itemId, long available, long reserved,
|
|
|
61 |
long held) {
|
|
|
62 |
this.itemId = itemId;
|
|
|
63 |
this.available = available;
|
|
|
64 |
this.reserved = reserved;
|
|
|
65 |
this.held = held;
|
|
|
66 |
}
|
|
|
67 |
public long getItemId() {
|
|
|
68 |
return itemId;
|
|
|
69 |
}
|
|
|
70 |
public void setItemId(long itemId) {
|
|
|
71 |
this.itemId = itemId;
|
|
|
72 |
}
|
|
|
73 |
public long getAvailable() {
|
|
|
74 |
return available;
|
|
|
75 |
}
|
|
|
76 |
public void setAvailable(long available) {
|
|
|
77 |
this.available = available;
|
|
|
78 |
}
|
|
|
79 |
public long getReserved() {
|
|
|
80 |
return reserved;
|
|
|
81 |
}
|
|
|
82 |
public void setReserved(long reserved) {
|
|
|
83 |
this.reserved = reserved;
|
|
|
84 |
}
|
|
|
85 |
public long getHeld() {
|
|
|
86 |
return held;
|
|
|
87 |
}
|
|
|
88 |
public void setHeld(long held) {
|
|
|
89 |
this.held = held;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
private static Logger logger = LoggerFactory.getLogger(HoldInventoryController.class);
|
|
|
95 |
|
|
|
96 |
private static Map<Long, Warehouse> warehouseMap;
|
|
|
97 |
private static List<Warehouse> warehouses;
|
|
|
98 |
private List<HoldInventoryDetail> holdInventoryDetails;
|
|
|
99 |
private Map<Long, Item> itemMap;
|
|
|
100 |
private Map<Long, ItemStockDetail> itemAvailabilityMap;
|
|
|
101 |
|
|
|
102 |
private long source;
|
|
|
103 |
private long itemId;
|
|
|
104 |
private long warehouseId;
|
|
|
105 |
private long heldQuantity;
|
|
|
106 |
|
|
|
107 |
private HttpServletRequest request;
|
|
|
108 |
private HttpSession session;
|
|
|
109 |
|
|
|
110 |
private String errorMsg = "";
|
|
|
111 |
|
|
|
112 |
static {
|
|
|
113 |
try {
|
|
|
114 |
InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
|
|
115 |
warehouseMap = new HashMap<Long, Warehouse>(100);
|
|
|
116 |
warehouses = inventoryClient.getWarehouses(null, InventoryType.GOOD, 0, 0, 0);
|
|
|
117 |
for (Warehouse warehouse : warehouses) {
|
|
|
118 |
warehouseMap.put(warehouse.getId(), warehouse);
|
|
|
119 |
}
|
|
|
120 |
} catch (Exception e) {
|
|
|
121 |
try {
|
|
|
122 |
InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
|
|
123 |
warehouses = inventoryClient.getWarehouses(null, InventoryType.GOOD, 0, 0, 0);
|
|
|
124 |
for (Warehouse warehouse : warehouses) {
|
|
|
125 |
warehouseMap.put(warehouse.getId(), warehouse);
|
|
|
126 |
}
|
|
|
127 |
} catch (Exception e1) {
|
|
|
128 |
e1.printStackTrace();
|
|
|
129 |
//TODO log statement
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
public String index() {
|
|
|
136 |
if(!ReportsUtils.canAccessReport((Long)session.getAttribute(ReportsUtils.ROLE), "/hold-inventory"))
|
|
|
137 |
return "authfail";
|
|
|
138 |
|
|
|
139 |
try {
|
|
|
140 |
itemMap = new HashMap<Long, Item>(50);
|
|
|
141 |
itemAvailabilityMap = new HashMap<Long, ItemStockDetail>();
|
|
|
142 |
InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
|
|
143 |
holdInventoryDetails = inventoryClient.getHoldInventoryDetails(0,0,0);
|
|
|
144 |
Map<Long, ItemInventory> itemInventoryMap = inventoryClient.getInventorySnapshot(0);
|
|
|
145 |
CatalogService.Client catalogClient = new CatalogClient().getClient();
|
|
|
146 |
for (HoldInventoryDetail holdInventoryDetail : holdInventoryDetails) {
|
|
|
147 |
if(itemMap.containsKey(holdInventoryDetail.getItem_id())) {
|
|
|
148 |
continue;
|
|
|
149 |
}
|
|
|
150 |
long availability = 0;
|
|
|
151 |
long reserved = 0;
|
|
|
152 |
long held = 0;
|
|
|
153 |
Item item = catalogClient.getItem(holdInventoryDetail.getItem_id());
|
|
|
154 |
Map<Long, Long> itemAvailability = itemInventoryMap.get(holdInventoryDetail.getItem_id()).getAvailability();
|
|
|
155 |
Map<Long, Long> itemReserved = itemInventoryMap.get(holdInventoryDetail.getItem_id()).getReserved();
|
|
|
156 |
Map<Long, Long> itemHeld = itemInventoryMap.get(holdInventoryDetail.getItem_id()).getHeld();
|
|
|
157 |
|
|
|
158 |
for (Long availabilityKey : itemAvailability.keySet()) {
|
|
|
159 |
if (availabilityKey!=16) {
|
|
|
160 |
availability += itemAvailability.get(availabilityKey);
|
|
|
161 |
}
|
|
|
162 |
}
|
|
|
163 |
for (Long reservedKey : itemReserved.keySet()) {
|
|
|
164 |
if (reservedKey!=16) {
|
|
|
165 |
reserved += itemReserved.get(reservedKey);
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
for (Long heldKey : itemHeld.keySet()) {
|
|
|
169 |
if (heldKey!=16) {
|
|
|
170 |
held += itemHeld.get(heldKey);
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
ItemStockDetail itemStockDetail = new ItemStockDetail(holdInventoryDetail.getItem_id(), availability, reserved, held);
|
|
|
174 |
itemAvailabilityMap.put(holdInventoryDetail.getItem_id(), itemStockDetail);
|
|
|
175 |
itemMap.put(holdInventoryDetail.getItem_id(), item);
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
} catch (Exception e) {
|
|
|
179 |
// TODO Auto-generated catch block
|
|
|
180 |
e.printStackTrace();
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
return "index";
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
public String create() throws Exception{
|
|
|
187 |
InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
|
|
188 |
inventoryClient.addUpdateHoldInventory(itemId, warehouseId, heldQuantity, source);
|
|
|
189 |
return index();
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
@Override
|
|
|
193 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
194 |
this.request = request;
|
|
|
195 |
this.session = request.getSession();
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
public String getErrorMsg() {
|
|
|
199 |
return errorMsg;
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
public void setErrorMsg(String errorMsg) {
|
|
|
203 |
this.errorMsg = errorMsg;
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
public static Map<Long, Warehouse> getWarehouseMap() {
|
|
|
207 |
return warehouseMap;
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
public static List<Warehouse> getWarehouses() {
|
|
|
211 |
return warehouses;
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
public List<HoldInventoryDetail> getHoldInventoryDetails() {
|
|
|
215 |
return holdInventoryDetails;
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
public long getSource() {
|
|
|
219 |
return source;
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
public void setSource(long source) {
|
|
|
223 |
this.source = source;
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
public long getItemId() {
|
|
|
227 |
return itemId;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
public void setItemId(long itemId) {
|
|
|
231 |
this.itemId = itemId;
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
public long getWarehouseId() {
|
|
|
235 |
return warehouseId;
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
public void setWarehouseId(long warehouseId) {
|
|
|
239 |
this.warehouseId = warehouseId;
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
public long getHeldQuantity() {
|
|
|
243 |
return heldQuantity;
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
public void setHeldQuantity(long heldQuantity) {
|
|
|
247 |
this.heldQuantity = heldQuantity;
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
public Map<Long, Item> getItemMap() {
|
|
|
251 |
return itemMap;
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
public void setItemMap(Map<Long, Item> itemMap) {
|
|
|
255 |
this.itemMap = itemMap;
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
public Map<Long, ItemStockDetail> getItemAvailabilityMap() {
|
|
|
259 |
return itemAvailabilityMap;
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
public void setItemAvailabilityMap(
|
|
|
263 |
Map<Long, ItemStockDetail> itemAvailabilityMap) {
|
|
|
264 |
this.itemAvailabilityMap = itemAvailabilityMap;
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
public String getSource(long source) {
|
|
|
268 |
return OrderSource.findByValue(new Long(source).intValue()).toString();
|
|
|
269 |
}
|
|
|
270 |
}
|