| Line 1... |
Line 1... |
| 1 |
package in.shop2020.support.controllers;
|
1 |
package in.shop2020.support.controllers;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.model.v1.catalog.InventoryService.Client;
|
3 |
import in.shop2020.model.v1.catalog.InventoryService.Client;
|
| - |
|
4 |
import in.shop2020.model.v1.catalog.InventoryServiceException;
|
| 4 |
import in.shop2020.model.v1.catalog.Item;
|
5 |
import in.shop2020.model.v1.catalog.Item;
|
| 5 |
import in.shop2020.model.v1.catalog.ItemType;
|
6 |
import in.shop2020.model.v1.catalog.ItemType;
|
| 6 |
import in.shop2020.model.v1.catalog.VendorItemMapping;
|
7 |
import in.shop2020.model.v1.catalog.VendorItemMapping;
|
| 7 |
import in.shop2020.model.v1.catalog.Warehouse;
|
8 |
import in.shop2020.model.v1.catalog.Warehouse;
|
| 8 |
import in.shop2020.support.models.BillingUpdate;
|
9 |
import in.shop2020.support.models.BillingUpdate;
|
| Line 18... |
Line 19... |
| 18 |
import java.util.ArrayList;
|
19 |
import java.util.ArrayList;
|
| 19 |
import java.util.HashMap;
|
20 |
import java.util.HashMap;
|
| 20 |
import java.util.List;
|
21 |
import java.util.List;
|
| 21 |
import java.util.Map;
|
22 |
import java.util.Map;
|
| 22 |
|
23 |
|
| - |
|
24 |
import javax.mail.MessagingException;
|
| - |
|
25 |
|
| 23 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
26 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
| 24 |
import org.apache.struts2.rest.HttpHeaders;
|
27 |
import org.apache.struts2.rest.HttpHeaders;
|
| - |
|
28 |
import org.apache.thrift.TException;
|
| 25 |
import org.slf4j.Logger;
|
29 |
import org.slf4j.Logger;
|
| 26 |
import org.slf4j.LoggerFactory;
|
30 |
import org.slf4j.LoggerFactory;
|
| 27 |
|
31 |
|
| 28 |
import com.opensymphony.xwork2.ModelDriven;
|
32 |
import com.opensymphony.xwork2.ModelDriven;
|
| 29 |
|
33 |
|
| Line 143... |
Line 147... |
| 143 |
}
|
147 |
}
|
| 144 |
}
|
148 |
}
|
| 145 |
|
149 |
|
| 146 |
List<PLBDetails> plbDetails = inventoryUpdate.getPlbDetails();
|
150 |
List<PLBDetails> plbDetails = inventoryUpdate.getPlbDetails();
|
| 147 |
if (plbDetails != null) {
|
151 |
if (plbDetails != null) {
|
| - |
|
152 |
Map<String, PLBDetails> currentInventory = new HashMap<String, PLBDetails>();
|
| 148 |
for (PLBDetails plbDetail : plbDetails) {
|
153 |
for (PLBDetails plbDetail : plbDetails) {
|
| 149 |
try {
|
154 |
try {
|
| - |
|
155 |
if (fullPlbSync) {
|
| - |
|
156 |
currentInventory.put(plbDetail.getItemKey(), plbDetail);
|
| - |
|
157 |
}
|
| - |
|
158 |
else {
|
| 150 |
snapshotClient.resetAvailability(
|
159 |
snapshotClient.resetAvailability(
|
| 151 |
plbDetail.getItemKey(), 1,
|
160 |
plbDetail.getItemKey(), 1,
|
| 152 |
plbDetail.getQuantity().longValue(), warehouseId);
|
161 |
plbDetail.getQuantity().longValue(), warehouseId);
|
| 153 |
snapshotClient.markMissedInventoryUpdatesAsProcessed(
|
162 |
snapshotClient.markMissedInventoryUpdatesAsProcessed(
|
| 154 |
plbDetail.getItemKey(), warehouseId);
|
163 |
plbDetail.getItemKey(), warehouseId);
|
| - |
|
164 |
}
|
| 155 |
} catch (Exception e) {
|
165 |
} catch (Exception e) {
|
| 156 |
logger.error("Could not reset availability of: " + plbDetail.getItemKey(), e);
|
166 |
logger.error("Could not reset availability of: " + plbDetail.getItemKey(), e);
|
| 157 |
GmailUtils g = new GmailUtils();
|
167 |
GmailUtils g = new GmailUtils();
|
| 158 |
g.sendSSLMessage(new String[]{ "mandeep.dhir@shop2020.in" }, "Error resetting availability for " + plbDetail.getItemKey() + " in warehouseId: " + warehouseId + " to " + plbDetail.getQuantity(), "", "cnc.center@shop2020.in", "5hop2o2o", new ArrayList<File>());
|
168 |
g.sendSSLMessage(new String[]{ "mandeep.dhir@shop2020.in" }, "Error resetting availability for " + plbDetail.getItemKey() + " in warehouseId: " + warehouseId + " to " + plbDetail.getQuantity(), "", "cnc.center@shop2020.in", "5hop2o2o", new ArrayList<File>());
|
| 159 |
}
|
169 |
}
|
| 160 |
}
|
170 |
}
|
| - |
|
171 |
|
| - |
|
172 |
semdMailForPLBMismatches(snapshotClient, warehouseId,
|
| - |
|
173 |
currentInventory);
|
| 161 |
}
|
174 |
}
|
| 162 |
} catch (Exception e) {
|
175 |
} catch (Exception e) {
|
| 163 |
logger.error("Unable to update inventory", e);
|
176 |
logger.error("Unable to update inventory", e);
|
| 164 |
}
|
177 |
}
|
| 165 |
|
178 |
|
| 166 |
return new DefaultHttpHeaders("psuccess");
|
179 |
return new DefaultHttpHeaders("psuccess");
|
| 167 |
|
180 |
|
| 168 |
}
|
181 |
}
|
| 169 |
|
182 |
|
| - |
|
183 |
private void semdMailForPLBMismatches(Client snapshotClient,
|
| - |
|
184 |
Long warehouseId, Map<String, PLBDetails> currentInventory)
|
| - |
|
185 |
throws InventoryServiceException, TException, MessagingException {
|
| - |
|
186 |
if (fullPlbSync) {
|
| - |
|
187 |
Map<Item, PLBDetails> mismatches = new HashMap<Item, PLBDetails>();
|
| - |
|
188 |
List<Item> items = snapshotClient.getAllItems(true);
|
| - |
|
189 |
for (Item item : items) {
|
| - |
|
190 |
if (ItemType.NON_SERIALIZED.equals(item.getType())) {
|
| - |
|
191 |
continue;
|
| - |
|
192 |
}
|
| - |
|
193 |
|
| - |
|
194 |
List<VendorItemMapping> mappings = snapshotClient.getVendorItemMappings(item.getId());
|
| - |
|
195 |
if (mappings != null) {
|
| - |
|
196 |
for (VendorItemMapping mapping : mappings) {
|
| - |
|
197 |
if (mapping.getVendorId() == 1) {
|
| - |
|
198 |
if (!item.getItemInventory().getAvailability().get(warehouseId).equals(currentInventory.get(mapping.getItemKey()).getQuantity().longValue())) {
|
| - |
|
199 |
mismatches.put(item, currentInventory.get(mapping.getItemKey()));
|
| - |
|
200 |
}
|
| - |
|
201 |
}
|
| - |
|
202 |
}
|
| - |
|
203 |
}
|
| - |
|
204 |
}
|
| - |
|
205 |
|
| - |
|
206 |
String subject = mismatches.size() + " mismatches with PLB sync for warehouse id: " + warehouseId;
|
| - |
|
207 |
StringBuilder body = new StringBuilder("");
|
| - |
|
208 |
for (Item item : mismatches.keySet()) {
|
| - |
|
209 |
body.append(item.getId() + " " + mismatches.get(item).getItemKey() + " " + item.getItemInventory().getAvailability().get(warehouseId) + " " + mismatches.get(item).getQuantity().longValue() + "\n");
|
| - |
|
210 |
}
|
| - |
|
211 |
GmailUtils g = new GmailUtils();
|
| - |
|
212 |
g.sendSSLMessage(new String[]{ "mandeep.dhir@shop2020.in" }, subject, body.toString(), "cnc.center@shop2020.in", "5hop2o2o", new ArrayList<File>());
|
| - |
|
213 |
}
|
| - |
|
214 |
}
|
| - |
|
215 |
|
| 170 |
public int getErrorCode() {
|
216 |
public int getErrorCode() {
|
| 171 |
return errorCode;
|
217 |
return errorCode;
|
| 172 |
}
|
218 |
}
|
| 173 |
|
219 |
|
| 174 |
public String getErrorMessage() {
|
220 |
public String getErrorMessage() {
|