| 7283 |
kshitij.so |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
| 7365 |
kshitij.so |
3 |
import java.util.HashMap;
|
| 7283 |
kshitij.so |
4 |
import java.util.List;
|
|
|
5 |
import java.util.Map;
|
|
|
6 |
|
|
|
7 |
import javax.servlet.ServletRequest;
|
|
|
8 |
import javax.servlet.http.HttpServletRequest;
|
|
|
9 |
|
|
|
10 |
import in.shop2020.model.v1.catalog.Amazonlisted;
|
|
|
11 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
|
|
12 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
13 |
import in.shop2020.model.v1.inventory.AmazonInventorySnapshot;
|
|
|
14 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
15 |
import in.shop2020.model.v1.inventory.InventoryServiceException;
|
|
|
16 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
17 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 7365 |
kshitij.so |
18 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
19 |
import in.shop2020.logistics.DeliveryType;
|
|
|
20 |
import in.shop2020.logistics.LogisticsInfo;
|
|
|
21 |
import in.shop2020.logistics.LogisticsServiceException;
|
|
|
22 |
import in.shop2020.logistics.PickUpType;
|
| 7283 |
kshitij.so |
23 |
|
| 7365 |
kshitij.so |
24 |
import org.apache.commons.lang.xwork.StringUtils;
|
| 7283 |
kshitij.so |
25 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
26 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
27 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
28 |
import org.apache.thrift.TException;
|
|
|
29 |
import org.apache.thrift.transport.TTransportException;
|
|
|
30 |
import org.slf4j.Logger;
|
|
|
31 |
import org.slf4j.LoggerFactory;
|
|
|
32 |
|
|
|
33 |
import com.opensymphony.xwork2.ValidationAwareSupport;
|
|
|
34 |
|
|
|
35 |
@SuppressWarnings("serial")
|
|
|
36 |
@Results({
|
|
|
37 |
@Result(name = "redirect", location = "${url}", type = "redirect") })
|
|
|
38 |
public class AmazonListController extends ValidationAwareSupport implements ServletRequestAware {
|
|
|
39 |
|
|
|
40 |
private static Logger logger = LoggerFactory.getLogger(AmazonListController.class);
|
|
|
41 |
|
|
|
42 |
private ServletRequest request;
|
|
|
43 |
private String url;
|
|
|
44 |
private String id;
|
|
|
45 |
private String itemId;
|
|
|
46 |
private String isFba;
|
|
|
47 |
private String isNonFba;
|
|
|
48 |
private String isInventoryOverride;
|
|
|
49 |
private String fbaPrice;
|
|
|
50 |
private String sellingPrice;
|
|
|
51 |
private String saholicPrice;
|
| 7365 |
kshitij.so |
52 |
private String isTime;
|
|
|
53 |
private String handlingTime;
|
|
|
54 |
private String customHandlingTime;
|
| 7461 |
kshitij.so |
55 |
private String holdInventory;
|
|
|
56 |
private String defaultInventory;
|
| 7283 |
kshitij.so |
57 |
|
|
|
58 |
public String index() {
|
|
|
59 |
return "index";
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
public List<Amazonlisted> fetchItems() throws TException {
|
| 7408 |
kshitij.so |
64 |
Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| 7283 |
kshitij.so |
65 |
return CatalogClient.getAllAmazonListedItems();
|
|
|
66 |
}
|
|
|
67 |
|
| 7408 |
kshitij.so |
68 |
public Amazonlisted fetchItemDetail() throws NumberFormatException, TException {
|
|
|
69 |
Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| 7283 |
kshitij.so |
70 |
return CatalogClient.getAmazonItemDetails(Long.valueOf(id));
|
|
|
71 |
}
|
|
|
72 |
|
| 7408 |
kshitij.so |
73 |
public Item getSaholicItem(String id) throws NumberFormatException, CatalogServiceException, TException {
|
|
|
74 |
Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| 7283 |
kshitij.so |
75 |
return CatalogClient.getItem(Long.valueOf(id));
|
|
|
76 |
}
|
| 7365 |
kshitij.so |
77 |
|
|
|
78 |
|
|
|
79 |
|
| 7283 |
kshitij.so |
80 |
public String update() throws NumberFormatException, TException{
|
| 7408 |
kshitij.so |
81 |
Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| 7283 |
kshitij.so |
82 |
if ( Double.valueOf(fbaPrice) > Double.valueOf(saholicPrice) || Double.valueOf(sellingPrice) > Double.valueOf(saholicPrice) ) {
|
| 7365 |
kshitij.so |
83 |
addActionError("Failed To Do Changes");
|
| 7283 |
kshitij.so |
84 |
}
|
|
|
85 |
else {
|
| 7365 |
kshitij.so |
86 |
boolean flag=false;
|
|
|
87 |
long delay = Long.valueOf(handlingTime);
|
|
|
88 |
if ( Boolean.valueOf(isTime)) {
|
|
|
89 |
flag = true;
|
|
|
90 |
delay = Long.valueOf(customHandlingTime);
|
|
|
91 |
}
|
| 7461 |
kshitij.so |
92 |
changeItemInventory();
|
| 7365 |
kshitij.so |
93 |
CatalogClient.updateAmazonItemDetails(Long.valueOf(itemId),Double.valueOf(fbaPrice),Double.valueOf(sellingPrice),Boolean.valueOf(isFba),Boolean.valueOf(isNonFba),Boolean.valueOf(isInventoryOverride),delay,flag);
|
| 7283 |
kshitij.so |
94 |
}
|
|
|
95 |
setUrl("/amazon-list/");
|
|
|
96 |
return "redirect";
|
|
|
97 |
|
|
|
98 |
}
|
|
|
99 |
|
| 7461 |
kshitij.so |
100 |
private void changeItemInventory() throws NumberFormatException, TException {
|
|
|
101 |
Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
|
|
102 |
if (StringUtils.isEmpty(holdInventory)) {
|
|
|
103 |
holdInventory = "0";
|
|
|
104 |
}
|
|
|
105 |
if (StringUtils.isEmpty(defaultInventory)) {
|
|
|
106 |
defaultInventory = "0";
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
CatalogClient.updateItemInventory(Long.valueOf(itemId),Long.valueOf(holdInventory),Long.valueOf(defaultInventory));
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
|
| 7283 |
kshitij.so |
113 |
public Map<Long, Long> getAvailableItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
|
|
|
114 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
|
|
115 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
|
|
116 |
in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
|
|
|
117 |
return thriftItemInventory.getAvailability();
|
|
|
118 |
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
public Map<Long, Long> getReservedItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
|
|
|
122 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
|
|
123 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
|
|
124 |
in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
|
|
|
125 |
return thriftItemInventory.getReserved();
|
|
|
126 |
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
public String getWarehouseName(String warehouseId) throws NumberFormatException, TException {
|
|
|
130 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
|
|
131 |
return inventoryServiceClient.getClient().getWarehouseName(Long.valueOf(warehouseId));
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
public AmazonInventorySnapshot getInventoryForAmazonItem(String itemId) throws NumberFormatException, TException {
|
|
|
135 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
| 7365 |
kshitij.so |
136 |
try {
|
|
|
137 |
return inventoryServiceClient.getClient().getAmazonInventoryForItem(Long.valueOf(itemId));
|
|
|
138 |
}
|
|
|
139 |
catch (Exception e){
|
|
|
140 |
return null;
|
|
|
141 |
}
|
| 7283 |
kshitij.so |
142 |
}
|
|
|
143 |
|
| 7365 |
kshitij.so |
144 |
public Long getTimetoShip(String itemId) throws LogisticsServiceException, TException{
|
|
|
145 |
LogisticsClient logisticsClient = new LogisticsClient();
|
|
|
146 |
return logisticsClient.getClient().getLogisticsInfo("110001", Long.valueOf(itemId), DeliveryType.COD, PickUpType.COURIER).getShippingTime();
|
|
|
147 |
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
public Map<Long, String> getAliveItemMap() throws TException{
|
| 7408 |
kshitij.so |
151 |
Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
| 7365 |
kshitij.so |
152 |
List<Item> itemList = CatalogClient.getAllAliveItems();
|
|
|
153 |
Map<Long, String> itemMap = new HashMap<Long, String>();
|
|
|
154 |
for (Item o : itemList) {
|
|
|
155 |
itemMap.put((Long) o.getId(), (String) o.getBrand()+" "+o.getModelName()+" "+o.getModelNumber()+" "+o.getColor());
|
|
|
156 |
}
|
|
|
157 |
return itemMap;
|
|
|
158 |
}
|
|
|
159 |
|
| 7283 |
kshitij.so |
160 |
public String edit() {
|
|
|
161 |
return "edit";
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
public String show() {
|
|
|
165 |
return "show";
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
public String editNew() {
|
|
|
169 |
return "editNew";
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
public void setId(String id) {
|
|
|
175 |
this.id = id;
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
public void setUrl(String url) {
|
|
|
179 |
this.url = url;
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
public String getUrl() {
|
|
|
183 |
return url;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
public String getId() {
|
|
|
187 |
return id;
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
public void setItemId(String itemId) {
|
|
|
191 |
this.itemId = itemId;
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
public String getItemId() {
|
|
|
195 |
return itemId;
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
public void setIsFba(String isFba) {
|
|
|
199 |
this.isFba = isFba;
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
public String getIsFba() {
|
|
|
203 |
return isFba;
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
public void setIsNonFba(String isNonFba) {
|
|
|
207 |
this.isNonFba = isNonFba;
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
public String getIsNonFba() {
|
|
|
211 |
return isNonFba;
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
public void setIsInventoryOverride(String isInventoryOverride) {
|
|
|
215 |
this.isInventoryOverride = isInventoryOverride;
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
public String getIsInventoryOverride() {
|
|
|
219 |
return isInventoryOverride;
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
public void setSellingPrice(String sellingPrice) {
|
|
|
223 |
this.sellingPrice = sellingPrice;
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
public String getSellingPrice() {
|
|
|
227 |
return sellingPrice;
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
public void setFbaPrice(String fbaPrice) {
|
|
|
231 |
this.fbaPrice = fbaPrice;
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
public String getFbaPrice() {
|
|
|
235 |
return fbaPrice;
|
|
|
236 |
}
|
| 7365 |
kshitij.so |
237 |
|
| 7283 |
kshitij.so |
238 |
public void setSaholicPrice(String saholicPrice) {
|
|
|
239 |
this.saholicPrice = saholicPrice;
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
public String getSaholicPrice() {
|
|
|
243 |
return saholicPrice;
|
|
|
244 |
}
|
|
|
245 |
|
| 7365 |
kshitij.so |
246 |
public void setIsTime(String isTime){
|
|
|
247 |
this.isTime = isTime;
|
|
|
248 |
}
|
|
|
249 |
|
| 7461 |
kshitij.so |
250 |
public String getIsTime(){
|
| 7365 |
kshitij.so |
251 |
return isTime;
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
public void setHandlingTime(String handlingTime){
|
|
|
255 |
this.handlingTime = handlingTime;
|
|
|
256 |
}
|
|
|
257 |
|
| 7461 |
kshitij.so |
258 |
public String getHandlingTime(){
|
| 7365 |
kshitij.so |
259 |
return handlingTime;
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
public void setCustomHandlingTime(String customHandlingTime){
|
|
|
263 |
this.customHandlingTime = customHandlingTime;
|
|
|
264 |
}
|
|
|
265 |
|
| 7461 |
kshitij.so |
266 |
public String getCustomHandlingTime(){
|
| 7365 |
kshitij.so |
267 |
return customHandlingTime;
|
|
|
268 |
}
|
| 7461 |
kshitij.so |
269 |
|
|
|
270 |
public void setHoldInventory(String holdInventory){
|
|
|
271 |
this.holdInventory = holdInventory;
|
|
|
272 |
}
|
| 7365 |
kshitij.so |
273 |
|
| 7461 |
kshitij.so |
274 |
public String getHoldInventory(){
|
|
|
275 |
return holdInventory;
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
public void setDefaultInventory(String defaultInventory){
|
|
|
279 |
this.defaultInventory = defaultInventory;
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
public String getDefaultInventory(){
|
|
|
283 |
return defaultInventory;
|
|
|
284 |
}
|
|
|
285 |
|
| 7283 |
kshitij.so |
286 |
@Override
|
|
|
287 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
288 |
this.request = request;
|
|
|
289 |
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
public static void main(String[] args) throws NumberFormatException, InventoryServiceException, TException {
|
|
|
293 |
AmazonListController call = new AmazonListController();
|
| 7365 |
kshitij.so |
294 |
System.out.println(call.getInventoryForAmazonItem("5"));
|
| 7283 |
kshitij.so |
295 |
}
|
|
|
296 |
}
|