| Line 3... |
Line 3... |
| 3 |
import java.io.ByteArrayInputStream;
|
3 |
import java.io.ByteArrayInputStream;
|
| 4 |
import java.io.ByteArrayOutputStream;
|
4 |
import java.io.ByteArrayOutputStream;
|
| 5 |
import java.io.InputStream;
|
5 |
import java.io.InputStream;
|
| 6 |
import java.time.LocalDateTime;
|
6 |
import java.time.LocalDateTime;
|
| 7 |
import java.util.ArrayList;
|
7 |
import java.util.ArrayList;
|
| - |
|
8 |
import java.util.Arrays;
|
| 8 |
import java.util.HashMap;
|
9 |
import java.util.HashMap;
|
| 9 |
import java.util.HashSet;
|
- |
|
| 10 |
import java.util.LinkedHashMap;
|
10 |
import java.util.LinkedHashMap;
|
| 11 |
import java.util.List;
|
11 |
import java.util.List;
|
| 12 |
import java.util.Map;
|
12 |
import java.util.Map;
|
| 13 |
import java.util.stream.Collectors;
|
13 |
import java.util.stream.Collectors;
|
| 14 |
|
14 |
|
| 15 |
import javax.servlet.http.HttpServletRequest;
|
15 |
import javax.servlet.http.HttpServletRequest;
|
| 16 |
import javax.transaction.Transactional;
|
16 |
import javax.transaction.Transactional;
|
| 17 |
|
17 |
|
| 18 |
import org.apache.logging.log4j.LogManager;
|
18 |
import org.apache.logging.log4j.LogManager;
|
| 19 |
import org.apache.logging.log4j.Logger;
|
19 |
import org.apache.logging.log4j.Logger;
|
| - |
|
20 |
import org.json.JSONArray;
|
| 20 |
import org.springframework.beans.factory.annotation.Autowired;
|
21 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21 |
import org.springframework.beans.factory.annotation.Qualifier;
|
22 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 22 |
import org.springframework.core.io.InputStreamResource;
|
23 |
import org.springframework.core.io.InputStreamResource;
|
| 23 |
import org.springframework.http.HttpHeaders;
|
24 |
import org.springframework.http.HttpHeaders;
|
| 24 |
import org.springframework.http.HttpStatus;
|
25 |
import org.springframework.http.HttpStatus;
|
| 25 |
import org.springframework.http.ResponseEntity;
|
26 |
import org.springframework.http.ResponseEntity;
|
| 26 |
import org.springframework.stereotype.Controller;
|
27 |
import org.springframework.stereotype.Controller;
|
| 27 |
import org.springframework.ui.Model;
|
28 |
import org.springframework.ui.Model;
|
| 28 |
import org.springframework.web.bind.annotation.PathVariable;
|
29 |
import org.springframework.web.bind.annotation.PathVariable;
|
| - |
|
30 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 29 |
import org.springframework.web.bind.annotation.RequestMapping;
|
31 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 30 |
import org.springframework.web.bind.annotation.RequestMethod;
|
32 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 31 |
|
33 |
|
| 32 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
34 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
35 |
import com.spice.profitmandi.common.model.ItemDescriptionModel;
|
| - |
|
36 |
import com.spice.profitmandi.common.model.PriceDropModel;
|
| 33 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
37 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 34 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
38 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| - |
|
39 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| - |
|
40 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| - |
|
41 |
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
|
| 35 |
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
|
42 |
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
|
| 36 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
43 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 37 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
44 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
| 38 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
45 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| - |
|
46 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| - |
|
47 |
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
|
| 39 |
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
|
48 |
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
|
| 40 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
49 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
| 41 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
50 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 42 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
51 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 43 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
52 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| - |
|
53 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 44 |
import com.spice.profitmandi.service.wallet.WalletService;
|
54 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 45 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
55 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 46 |
|
56 |
|
| 47 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
57 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 48 |
|
58 |
|
| Line 54... |
Line 64... |
| 54 |
|
64 |
|
| 55 |
@Autowired
|
65 |
@Autowired
|
| 56 |
private PriceDropRepository priceDropRepository;
|
66 |
private PriceDropRepository priceDropRepository;
|
| 57 |
|
67 |
|
| 58 |
@Autowired
|
68 |
@Autowired
|
| 59 |
private InventoryService inventoryService;
|
- |
|
| 60 |
|
- |
|
| 61 |
@Autowired
|
- |
|
| 62 |
private PriceDropIMEIRepository priceDropIMEIRepository;
|
69 |
private PriceDropIMEIRepository priceDropIMEIRepository;
|
| - |
|
70 |
|
| - |
|
71 |
@Autowired
|
| - |
|
72 |
private VendorItemPricingRepository vendorItemPricingRepository;
|
| 63 |
|
73 |
|
| 64 |
@Autowired
|
74 |
@Autowired
|
| 65 |
private PriceDropService priceDropService;
|
75 |
private PriceDropService priceDropService;
|
| 66 |
|
76 |
|
| 67 |
@Autowired
|
77 |
@Autowired
|
| - |
|
78 |
@Qualifier("fofoInventoryService")
|
| - |
|
79 |
private InventoryService inventoryService;
|
| - |
|
80 |
|
| - |
|
81 |
@Autowired
|
| 68 |
private MVCResponseSender mvcResponseSender;
|
82 |
private MVCResponseSender mvcResponseSender;
|
| 69 |
|
83 |
|
| 70 |
@Autowired
|
84 |
@Autowired
|
| 71 |
private WalletService walletService;
|
85 |
private WalletService walletService;
|
| 72 |
|
86 |
|
| 73 |
@Autowired
|
87 |
@Autowired
|
| 74 |
private LineItemImeisRepository lineItemImeisRepository;
|
88 |
private LineItemImeisRepository lineItemImeisRepository;
|
| - |
|
89 |
|
| - |
|
90 |
@Autowired
|
| - |
|
91 |
private TagListingRepository tagListingRepository;
|
| - |
|
92 |
|
| - |
|
93 |
@Autowired
|
| - |
|
94 |
private TransactionService transactionService;
|
| 75 |
|
95 |
|
| 76 |
@Autowired
|
96 |
@Autowired
|
| 77 |
@Qualifier("catalogItemRepository")
|
97 |
@Qualifier("catalogItemRepository")
|
| 78 |
private ItemRepository itemRepository;
|
98 |
private ItemRepository itemRepository;
|
| 79 |
|
99 |
|
| 80 |
private List<Integer> getItemIds() {
|
- |
|
| 81 |
List<Integer> itemIds = new ArrayList<>();
|
- |
|
| 82 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
- |
|
| 83 |
for (PriceDrop priceDrop : priceDrops) {
|
- |
|
| 84 |
itemIds.add(priceDrop.getItemId());
|
- |
|
| 85 |
}
|
- |
|
| 86 |
return itemIds;
|
- |
|
| 87 |
}
|
- |
|
| 88 |
|
- |
|
| 89 |
@RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
|
100 |
@RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
|
| 90 |
public String getItemDescription(HttpServletRequest request, Model model) {
|
101 |
public String getItemDescription(HttpServletRequest request, Model model) throws Throwable{
|
| 91 |
|
102 |
|
| - |
|
103 |
List<TagListing> tagListings = tagListingRepository.selectAll(false);
|
| - |
|
104 |
Map<Integer, TagListing> tagListingMap = new HashMap<>();
|
| 92 |
List<Integer> itemIds = this.getItemIds();
|
105 |
List<ItemDescriptionModel> customItems = new ArrayList<>();
|
| - |
|
106 |
for(TagListing tagListing : tagListings) {
|
| - |
|
107 |
tagListing.setItemDescription(itemRepository.selectById(tagListing.getItemId()).getItemDescription());
|
| - |
|
108 |
tagListingMap.put(tagListing.getItemId(), tagListing);
|
| 93 |
Map<Integer, String> itemIdDescriptions = inventoryService
|
109 |
ItemDescriptionModel itemDescriptionModel = new ItemDescriptionModel();
|
| 94 |
.getItemIdDescriptionMap(new HashSet<Integer>(itemIds));
|
110 |
itemDescriptionModel.setItemId(tagListing.getItemId());
|
| - |
|
111 |
itemDescriptionModel.setItemDescription(tagListing.getItemDescription() + "(" + tagListing.getItemId() +")");
|
| - |
|
112 |
customItems.add(itemDescriptionModel);
|
| - |
|
113 |
}
|
| - |
|
114 |
|
| 95 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
115 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 96 |
model.addAttribute("itemIdDescriptions", itemIdDescriptions);
|
116 |
model.addAttribute("tagListingMap", tagListingMap);
|
| - |
|
117 |
model.addAttribute("customItems", new JSONArray(customItems).toString());
|
| 97 |
model.addAttribute("priceDrops", priceDrops);
|
118 |
model.addAttribute("priceDrops", priceDrops);
|
| 98 |
return "price-drop";
|
119 |
return "price-drop";
|
| 99 |
|
120 |
|
| 100 |
}
|
121 |
}
|
| 101 |
|
122 |
|
| Line 172... |
Line 193... |
| 172 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
193 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
| 173 |
return "false";
|
194 |
return "false";
|
| 174 |
}
|
195 |
}
|
| 175 |
}
|
196 |
}
|
| 176 |
|
197 |
|
| - |
|
198 |
@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
|
| - |
|
199 |
public String addPriceDrop(HttpServletRequest request, Model model, @RequestBody PriceDropModel priceDropModel) throws Exception {
|
| - |
|
200 |
boolean response = false;
|
| - |
|
201 |
if(this.validatePriceDrop(priceDropModel)) {
|
| - |
|
202 |
TagListing tagListing = tagListingRepository.selectByItemId(priceDropModel.getItemId());
|
| - |
|
203 |
float newDp = tagListing.getSellingPrice() - priceDropModel.getPd();
|
| - |
|
204 |
if(newDp > 0) {
|
| - |
|
205 |
List<Item> allItems = null;
|
| - |
|
206 |
Item currentItem = itemRepository.selectById(priceDropModel.getItemId());
|
| - |
|
207 |
if(priceDropModel.isAllColors()) {
|
| - |
|
208 |
allItems = itemRepository.selectAllByCatalogItemId(currentItem.getCatalogItemId());
|
| - |
|
209 |
|
| - |
|
210 |
} else {
|
| - |
|
211 |
allItems=Arrays.asList(currentItem);
|
| - |
|
212 |
}
|
| - |
|
213 |
for(Item item : allItems) {
|
| - |
|
214 |
TagListing itemTagListing = tagListingRepository.selectByItemId(item.getId());
|
| - |
|
215 |
if(itemTagListing == null) continue;
|
| - |
|
216 |
itemTagListing.setSellingPrice(newDp);
|
| - |
|
217 |
itemTagListing.setMop(priceDropModel.getMop());
|
| - |
|
218 |
tagListingRepository.persist(tagListing);
|
| - |
|
219 |
List<VendorItemPricing> vipList = vendorItemPricingRepository.selectAll(item.getId());
|
| - |
|
220 |
for(VendorItemPricing vip : vipList) {
|
| - |
|
221 |
vip.setDp(newDp);
|
| - |
|
222 |
vip.setMop(priceDropModel.getMop());
|
| - |
|
223 |
vip.setNlc(priceDropModel.getNlc());
|
| - |
|
224 |
vip.setTp(priceDropModel.getTp());
|
| - |
|
225 |
vendorItemPricingRepository.persist(vip);
|
| - |
|
226 |
}
|
| - |
|
227 |
PriceDrop priceDrop = new PriceDrop();
|
| - |
|
228 |
priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
|
| - |
|
229 |
priceDrop.setAmount(priceDropModel.getPd());
|
| - |
|
230 |
priceDrop.setCreatedOn(LocalDateTime.now());
|
| - |
|
231 |
priceDrop.setItemId(item.getId());
|
| - |
|
232 |
priceDropRepository.persist(priceDrop);
|
| - |
|
233 |
transactionService.updatePriceDrop(item.getId(), newDp);
|
| - |
|
234 |
}
|
| - |
|
235 |
response = true;
|
| - |
|
236 |
} else {
|
| - |
|
237 |
throw new ProfitMandiBusinessException("Price Drop", priceDropModel.getPd(), "Price Drop Cannot be more than Current DP");
|
| - |
|
238 |
}
|
| - |
|
239 |
}
|
| - |
|
240 |
model.addAttribute("response", mvcResponseSender.createResponseString(response));
|
| - |
|
241 |
return "response";
|
| - |
|
242 |
}
|
| 177 |
@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
|
243 |
@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
|
| 178 |
public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
|
244 |
public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
|
| 179 |
Model model) throws ProfitMandiBusinessException {
|
245 |
Model model) throws ProfitMandiBusinessException {
|
| 180 |
|
246 |
|
| 181 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
|
247 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
|
| Line 194... |
Line 260... |
| 194 |
priceDrop.setProcessTimestamp(LocalDateTime.now());
|
260 |
priceDrop.setProcessTimestamp(LocalDateTime.now());
|
| 195 |
throw new ProfitMandiBusinessException("IMEI", 1, "IMEI not Found For PriceDrop");
|
261 |
throw new ProfitMandiBusinessException("IMEI", 1, "IMEI not Found For PriceDrop");
|
| 196 |
}
|
262 |
}
|
| 197 |
}
|
263 |
}
|
| 198 |
|
264 |
|
| - |
|
265 |
private boolean validatePriceDrop(PriceDropModel priceDropModel) throws ProfitMandiBusinessException {
|
| - |
|
266 |
if(priceDropModel.getMop() > 0 && priceDropModel.getMop() > 0 && priceDropModel.getNlc() > 0 && priceDropModel.getTp() > 0 && priceDropModel.getNlc() > 0) {
|
| - |
|
267 |
return true;
|
| - |
|
268 |
}
|
| - |
|
269 |
return false;
|
| - |
|
270 |
}
|
| 199 |
private Map<String, String> getpriceDropIMEIAndItemDescription(PriceDrop priceDrop)
|
271 |
private Map<String, String> getpriceDropIMEIAndItemDescription(PriceDrop priceDrop)
|
| 200 |
throws ProfitMandiBusinessException {
|
272 |
throws ProfitMandiBusinessException {
|
| 201 |
Map<String, String> priceDropIMEIAndItemId = new LinkedHashMap<>();
|
273 |
Map<String, String> priceDropIMEIAndItemId = new LinkedHashMap<>();
|
| 202 |
List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository.selectByPriceDropId(priceDrop.getId());
|
274 |
List<InventoryItem> inventoryInStock = inventoryService.getInventoryInStock(priceDrop.getItemId(), priceDrop.getAffectedOn());
|
| 203 |
Item item = itemRepository.selectById(priceDrop.getItemId());
|
- |
|
| 204 |
for (PriceDropIMEI priceDropIMEI : priceDropIMEIs) {
|
- |
|
| 205 |
priceDropIMEIAndItemId.put(priceDropIMEI.getImei(), item.getItemDescription());
|
- |
|
| 206 |
}
|
- |
|
| 207 |
return priceDropIMEIAndItemId;
|
275 |
return priceDropIMEIAndItemId;
|
| 208 |
}
|
276 |
}
|
| 209 |
|
277 |
|
| 210 |
}
|
278 |
}
|