| 23819 |
govind |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 23968 |
amit.gupta |
3 |
import java.text.MessageFormat;
|
| 23819 |
govind |
4 |
import java.time.LocalDateTime;
|
|
|
5 |
import java.util.ArrayList;
|
| 23884 |
amit.gupta |
6 |
import java.util.Arrays;
|
| 23819 |
govind |
7 |
import java.util.HashMap;
|
|
|
8 |
import java.util.List;
|
|
|
9 |
import java.util.Map;
|
|
|
10 |
import java.util.stream.Collectors;
|
|
|
11 |
|
|
|
12 |
import javax.servlet.http.HttpServletRequest;
|
|
|
13 |
import javax.transaction.Transactional;
|
|
|
14 |
|
| 23951 |
amit.gupta |
15 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
|
16 |
import org.apache.commons.lang.StringUtils;
|
| 23945 |
amit.gupta |
17 |
import org.apache.http.HttpResponse;
|
| 23819 |
govind |
18 |
import org.apache.logging.log4j.LogManager;
|
|
|
19 |
import org.apache.logging.log4j.Logger;
|
| 23884 |
amit.gupta |
20 |
import org.json.JSONArray;
|
| 23819 |
govind |
21 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
22 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 23951 |
amit.gupta |
23 |
import org.springframework.core.io.ByteArrayResource;
|
|
|
24 |
import org.springframework.http.HttpHeaders;
|
| 23819 |
govind |
25 |
import org.springframework.http.HttpStatus;
|
|
|
26 |
import org.springframework.http.ResponseEntity;
|
|
|
27 |
import org.springframework.stereotype.Controller;
|
|
|
28 |
import org.springframework.ui.Model;
|
|
|
29 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 23884 |
amit.gupta |
30 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 23819 |
govind |
31 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
32 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 23951 |
amit.gupta |
33 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 23819 |
govind |
34 |
|
| 23951 |
amit.gupta |
35 |
import com.fasterxml.jackson.databind.JavaType;
|
| 23945 |
amit.gupta |
36 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
37 |
import com.fasterxml.jackson.databind.ObjectReader;
|
|
|
38 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 23819 |
govind |
39 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23945 |
amit.gupta |
40 |
import com.spice.profitmandi.common.model.ClosingStockOnDate;
|
|
|
41 |
import com.spice.profitmandi.common.model.GrnPendingDataModel;
|
| 23951 |
amit.gupta |
42 |
import com.spice.profitmandi.common.model.ImeiDropSummaryModel;
|
| 23884 |
amit.gupta |
43 |
import com.spice.profitmandi.common.model.ItemDescriptionModel;
|
| 23945 |
amit.gupta |
44 |
import com.spice.profitmandi.common.model.PartnerImeiNotSold;
|
| 23884 |
amit.gupta |
45 |
import com.spice.profitmandi.common.model.PriceDropModel;
|
| 23968 |
amit.gupta |
46 |
import com.spice.profitmandi.common.model.PriceDropProcessModel;
|
| 23945 |
amit.gupta |
47 |
import com.spice.profitmandi.common.model.ReporticoResponseModel;
|
|
|
48 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 23951 |
amit.gupta |
49 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 23945 |
amit.gupta |
50 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 23819 |
govind |
51 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 23884 |
amit.gupta |
52 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 23968 |
amit.gupta |
53 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 23884 |
amit.gupta |
54 |
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
|
| 23819 |
govind |
55 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
|
|
56 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 23884 |
amit.gupta |
57 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 23968 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 23884 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
|
| 23819 |
govind |
60 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
|
|
61 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 23968 |
amit.gupta |
62 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 23884 |
amit.gupta |
63 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 23819 |
govind |
64 |
import com.spice.profitmandi.service.wallet.WalletService;
|
|
|
65 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
66 |
|
| 23968 |
amit.gupta |
67 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
|
|
68 |
|
| 23819 |
govind |
69 |
@Controller
|
|
|
70 |
@Transactional
|
|
|
71 |
public class PriceDropController {
|
|
|
72 |
|
|
|
73 |
private static final Logger LOGGER = LogManager.getLogger(PriceDropController.class);
|
|
|
74 |
|
|
|
75 |
@Autowired
|
|
|
76 |
private PriceDropRepository priceDropRepository;
|
|
|
77 |
|
| 23951 |
amit.gupta |
78 |
@Autowired
|
|
|
79 |
private ObjectMapper objectMapper;
|
| 23945 |
amit.gupta |
80 |
|
| 23819 |
govind |
81 |
@Autowired
|
| 23884 |
amit.gupta |
82 |
private VendorItemPricingRepository vendorItemPricingRepository;
|
| 23819 |
govind |
83 |
|
|
|
84 |
@Autowired
|
| 23884 |
amit.gupta |
85 |
@Qualifier("fofoInventoryService")
|
|
|
86 |
private InventoryService inventoryService;
|
| 23945 |
amit.gupta |
87 |
|
| 23884 |
amit.gupta |
88 |
@Autowired
|
| 23968 |
amit.gupta |
89 |
private InventoryItemRepository inventoryItemRepository;
|
|
|
90 |
|
|
|
91 |
@Autowired
|
| 23819 |
govind |
92 |
private MVCResponseSender mvcResponseSender;
|
|
|
93 |
|
|
|
94 |
@Autowired
|
|
|
95 |
private WalletService walletService;
|
|
|
96 |
|
|
|
97 |
@Autowired
|
| 23884 |
amit.gupta |
98 |
private TagListingRepository tagListingRepository;
|
| 23945 |
amit.gupta |
99 |
|
| 23884 |
amit.gupta |
100 |
@Autowired
|
|
|
101 |
private TransactionService transactionService;
|
| 23819 |
govind |
102 |
|
|
|
103 |
@Autowired
|
|
|
104 |
@Qualifier("catalogItemRepository")
|
|
|
105 |
private ItemRepository itemRepository;
|
|
|
106 |
|
| 23945 |
amit.gupta |
107 |
@Autowired
|
| 23968 |
amit.gupta |
108 |
private SchemeService schemeService;
|
|
|
109 |
|
|
|
110 |
@Autowired
|
| 23945 |
amit.gupta |
111 |
ReporticoService reporticoService;
|
|
|
112 |
|
| 23819 |
govind |
113 |
@RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
|
| 23945 |
amit.gupta |
114 |
public String getItemDescription(HttpServletRequest request, Model model) throws Throwable {
|
| 23819 |
govind |
115 |
|
| 23884 |
amit.gupta |
116 |
List<TagListing> tagListings = tagListingRepository.selectAll(false);
|
|
|
117 |
Map<Integer, TagListing> tagListingMap = new HashMap<>();
|
|
|
118 |
List<ItemDescriptionModel> customItems = new ArrayList<>();
|
| 23968 |
amit.gupta |
119 |
Map<Integer, String> catalogDescription = new HashMap<>();
|
| 23945 |
amit.gupta |
120 |
for (TagListing tagListing : tagListings) {
|
| 23968 |
amit.gupta |
121 |
Item item = itemRepository.selectById(tagListing.getItemId());
|
|
|
122 |
tagListing.setItemDescription(item.getItemDescription());
|
| 23884 |
amit.gupta |
123 |
tagListingMap.put(tagListing.getItemId(), tagListing);
|
|
|
124 |
ItemDescriptionModel itemDescriptionModel = new ItemDescriptionModel();
|
|
|
125 |
itemDescriptionModel.setItemId(tagListing.getItemId());
|
| 23945 |
amit.gupta |
126 |
itemDescriptionModel
|
|
|
127 |
.setItemDescription(tagListing.getItemDescription() + "(" + tagListing.getItemId() + ")");
|
|
|
128 |
customItems.add(itemDescriptionModel);
|
| 23968 |
amit.gupta |
129 |
catalogDescription.put(item.getCatalogItemId(), item.getItemDescriptionNoColor());
|
| 23884 |
amit.gupta |
130 |
}
|
| 23945 |
amit.gupta |
131 |
|
| 23819 |
govind |
132 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 23884 |
amit.gupta |
133 |
model.addAttribute("tagListingMap", tagListingMap);
|
|
|
134 |
model.addAttribute("customItems", new JSONArray(customItems).toString());
|
| 23819 |
govind |
135 |
model.addAttribute("priceDrops", priceDrops);
|
| 23968 |
amit.gupta |
136 |
model.addAttribute("catalogDescription", catalogDescription);
|
| 23819 |
govind |
137 |
return "price-drop";
|
|
|
138 |
|
|
|
139 |
}
|
|
|
140 |
|
| 23945 |
amit.gupta |
141 |
/*
|
|
|
142 |
* @RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method =
|
|
|
143 |
* RequestMethod.GET) public ResponseEntity<?>
|
|
|
144 |
* downloadPriceDropIMEI(HttpServletRequest request, @PathVariable int
|
|
|
145 |
* priceDropId, Model model) throws ProfitMandiBusinessException {
|
|
|
146 |
*
|
|
|
147 |
* PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
|
|
|
148 |
* List<PriceDropIMEI> priceDropIMEIs =
|
|
|
149 |
* priceDropIMEIRepository.selectByPriceDropId(priceDrop.getId()); List<String>
|
|
|
150 |
* imeis = priceDropIMEIs.stream().map(x ->
|
|
|
151 |
* x.getImei()).collect(Collectors.toList()); List<LineItemImei> lineItemImeis =
|
|
|
152 |
* lineItemImeisRepository.selectByIMEI(imeis); Map<String, String>
|
|
|
153 |
* priceDropIMEIfofoId = priceDropService.getIMEIandRetailerName(lineItemImeis,
|
|
|
154 |
* priceDrop); if (priceDropIMEIfofoId.size() > 0) { ByteArrayOutputStream
|
|
|
155 |
* byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
156 |
* ExcelUtils.writePriceDrop(priceDropIMEIfofoId, priceDrop.getItemId(),
|
|
|
157 |
* byteArrayOutputStream); final HttpHeaders headers = new HttpHeaders(); //
|
|
|
158 |
* private static final String CONTENT_TYPE_XLSX = //
|
|
|
159 |
* "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
|
160 |
* headers.set("Content-Type",
|
|
|
161 |
* "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); //
|
|
|
162 |
* headers.set("Content-Type", "application/vnd.ms-excel");
|
|
|
163 |
* headers.set("Content-disposition", "inline; filename=priceDrop" +
|
|
|
164 |
* priceDrop.getId() + ".xlsx");
|
|
|
165 |
* headers.setContentLength(byteArrayOutputStream.toByteArray().length); final
|
|
|
166 |
* InputStream inputStream = new
|
|
|
167 |
* ByteArrayInputStream(byteArrayOutputStream.toByteArray()); final
|
|
|
168 |
* InputStreamResource inputStreamResource = new
|
|
|
169 |
* InputStreamResource(inputStream); return new
|
|
|
170 |
* ResponseEntity<InputStreamResource>(inputStreamResource, headers,
|
|
|
171 |
* HttpStatus.OK); } else { throw new
|
|
|
172 |
* ProfitMandiBusinessException("priceDropId", priceDropId,
|
|
|
173 |
* "No IMEI is Eligible For PriceDrop"); }
|
|
|
174 |
*
|
|
|
175 |
* }
|
|
|
176 |
*/
|
| 23819 |
govind |
177 |
|
| 23951 |
amit.gupta |
178 |
@RequestMapping(value = "/price-drop/imes/download")
|
|
|
179 |
public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
|
|
|
180 |
@RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
|
|
|
181 |
Item item = itemRepository.selectById(itemId);
|
| 23968 |
amit.gupta |
182 |
ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId());
|
| 23951 |
amit.gupta |
183 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
184 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
185 |
headers.set("Content-disposition", "inline; filename=imei-" + item.getItemDescriptionNoColor() + ".csv");
|
|
|
186 |
byte[] byteArray = baos.toByteArray();
|
|
|
187 |
headers.setContentLength(byteArray.length);
|
|
|
188 |
return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
|
|
|
189 |
}
|
|
|
190 |
|
| 23968 |
amit.gupta |
191 |
@RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
|
|
|
192 |
public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcess,
|
|
|
193 |
Model model) throws Exception {
|
|
|
194 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcess.getPriceDropId());
|
|
|
195 |
boolean response = false;
|
|
|
196 |
if (priceDrop.getProcessTimestamp() == null) {
|
|
|
197 |
priceDrop.setPartnerPayout(priceDropProcess.getPartnerPayout());
|
|
|
198 |
priceDrop.setPriceDropIn(priceDropProcess.getPriceDropIn());
|
|
|
199 |
priceDrop.setProcessTimestamp(LocalDateTime.now());
|
|
|
200 |
priceDropRepository.persist(priceDrop);
|
|
|
201 |
List<ImeiDropSummaryModel> partnerPendingImeis = getPartnerPendingImeis(priceDrop.getAffectedOn(),
|
|
|
202 |
priceDrop.getCatalogItemId());
|
|
|
203 |
if (partnerPendingImeis.size() > 0) {
|
|
|
204 |
Map<Integer, List<ImeiDropSummaryModel>> partnerImeiMap = new HashMap<>();
|
|
|
205 |
for (ImeiDropSummaryModel pendingImei : partnerPendingImeis) {
|
|
|
206 |
if (!partnerImeiMap.containsKey(pendingImei.getRetailerId())) {
|
|
|
207 |
partnerImeiMap.put(pendingImei.getRetailerId(), new ArrayList<>());
|
|
|
208 |
}
|
|
|
209 |
partnerImeiMap.get(pendingImei.getRetailerId()).add(pendingImei);
|
|
|
210 |
}
|
| 23819 |
govind |
211 |
|
| 23968 |
amit.gupta |
212 |
for (Map.Entry<Integer, List<ImeiDropSummaryModel>> pendingPartnerImei : partnerImeiMap.entrySet()) {
|
|
|
213 |
List<ImeiDropSummaryModel> retailerImeiList = pendingPartnerImei.getValue();
|
|
|
214 |
int fofoId = pendingPartnerImei.getKey();
|
|
|
215 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByFofoIdSerialNumbers(fofoId,
|
|
|
216 |
retailerImeiList.stream().map(x -> x.getSerialNumber()).collect(Collectors.toSet()), true);
|
|
|
217 |
String reversalReason = MessageFormat.format(
|
|
|
218 |
"Scheme amount reversal due to Price Drop of Rs.{0} on {1}. Affected on {3}, Total {2} item(s)",
|
|
|
219 |
priceDrop.getAmount(), priceDrop.getDescription(), pendingPartnerImei.getValue().size(),
|
|
|
220 |
FormattingUtils.formatDate(priceDrop.getAffectedOn()));
|
|
|
221 |
String aReason = MessageFormat.format(
|
|
|
222 |
"Per unit payout of Rs.{4} Price Drop of Rs.{0} on {1} affected on {3}. Total {2} item(s)",
|
|
|
223 |
priceDrop.getAmount(), priceDrop.getDescription(), pendingPartnerImei.getValue().size(),
|
|
|
224 |
FormattingUtils.formatDate(priceDrop.getAffectedOn()), priceDropProcess.getPartnerPayout());
|
|
|
225 |
schemeService.reverseSchemes(inventoryItems, priceDropProcess.getPriceDropId(), reversalReason);
|
|
|
226 |
inventoryService.updatePriceDrop(inventoryItems, priceDrop.getAmount());
|
|
|
227 |
walletService.addAmountToWallet(fofoId, priceDrop.getId(), WalletReferenceType.PRICE_DROP,
|
|
|
228 |
aReason, priceDropProcess.getPartnerPayout()*pendingPartnerImei.getValue().size());
|
| 23819 |
govind |
229 |
}
|
|
|
230 |
|
|
|
231 |
}
|
| 23968 |
amit.gupta |
232 |
response = true;
|
| 23819 |
govind |
233 |
}
|
| 23968 |
amit.gupta |
234 |
model.addAttribute("response", mvcResponseSender.createResponseString(response));
|
|
|
235 |
return "response";
|
| 23819 |
govind |
236 |
}
|
|
|
237 |
|
| 23884 |
amit.gupta |
238 |
@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
|
| 23945 |
amit.gupta |
239 |
public String addPriceDrop(HttpServletRequest request, Model model, @RequestBody PriceDropModel priceDropModel)
|
|
|
240 |
throws Exception {
|
| 23884 |
amit.gupta |
241 |
boolean response = false;
|
| 23968 |
amit.gupta |
242 |
priceDropModel.setAllColors(true);
|
| 23945 |
amit.gupta |
243 |
if (this.validatePriceDrop(priceDropModel)) {
|
| 23884 |
amit.gupta |
244 |
TagListing tagListing = tagListingRepository.selectByItemId(priceDropModel.getItemId());
|
|
|
245 |
float newDp = tagListing.getSellingPrice() - priceDropModel.getPd();
|
| 23945 |
amit.gupta |
246 |
if (newDp > 0) {
|
| 23884 |
amit.gupta |
247 |
List<Item> allItems = null;
|
|
|
248 |
Item currentItem = itemRepository.selectById(priceDropModel.getItemId());
|
| 23945 |
amit.gupta |
249 |
if (priceDropModel.isAllColors()) {
|
| 23884 |
amit.gupta |
250 |
allItems = itemRepository.selectAllByCatalogItemId(currentItem.getCatalogItemId());
|
| 23945 |
amit.gupta |
251 |
|
| 23884 |
amit.gupta |
252 |
} else {
|
| 23945 |
amit.gupta |
253 |
allItems = Arrays.asList(currentItem);
|
| 23884 |
amit.gupta |
254 |
}
|
| 23945 |
amit.gupta |
255 |
for (Item item : allItems) {
|
| 23884 |
amit.gupta |
256 |
TagListing itemTagListing = tagListingRepository.selectByItemId(item.getId());
|
| 23945 |
amit.gupta |
257 |
if (itemTagListing == null)
|
|
|
258 |
continue;
|
| 23884 |
amit.gupta |
259 |
itemTagListing.setSellingPrice(newDp);
|
|
|
260 |
itemTagListing.setMop(priceDropModel.getMop());
|
|
|
261 |
tagListingRepository.persist(tagListing);
|
|
|
262 |
List<VendorItemPricing> vipList = vendorItemPricingRepository.selectAll(item.getId());
|
| 23945 |
amit.gupta |
263 |
for (VendorItemPricing vip : vipList) {
|
| 23884 |
amit.gupta |
264 |
vip.setDp(newDp);
|
|
|
265 |
vip.setMop(priceDropModel.getMop());
|
|
|
266 |
vip.setNlc(priceDropModel.getNlc());
|
|
|
267 |
vip.setTp(priceDropModel.getTp());
|
|
|
268 |
vendorItemPricingRepository.persist(vip);
|
|
|
269 |
}
|
|
|
270 |
transactionService.updatePriceDrop(item.getId(), newDp);
|
|
|
271 |
}
|
| 23951 |
amit.gupta |
272 |
PriceDrop priceDrop = new PriceDrop();
|
|
|
273 |
priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
|
| 23968 |
amit.gupta |
274 |
priceDrop.setOldDp(newDp + priceDropModel.getPd());
|
| 23951 |
amit.gupta |
275 |
priceDrop.setAmount(priceDropModel.getPd());
|
| 23968 |
amit.gupta |
276 |
priceDrop.setNewDp(newDp);
|
|
|
277 |
priceDrop.setNlc(priceDropModel.getNlc());
|
|
|
278 |
priceDrop.setTp(priceDropModel.getTp());
|
| 23951 |
amit.gupta |
279 |
priceDrop.setCreatedOn(LocalDateTime.now());
|
|
|
280 |
priceDrop.setCatalogItemId(currentItem.getCatalogItemId());
|
|
|
281 |
priceDropRepository.persist(priceDrop);
|
| 23884 |
amit.gupta |
282 |
response = true;
|
|
|
283 |
} else {
|
| 23945 |
amit.gupta |
284 |
throw new ProfitMandiBusinessException("Price Drop", priceDropModel.getPd(),
|
|
|
285 |
"Price Drop Cannot be more than Current DP");
|
| 23884 |
amit.gupta |
286 |
}
|
|
|
287 |
}
|
|
|
288 |
model.addAttribute("response", mvcResponseSender.createResponseString(response));
|
|
|
289 |
return "response";
|
|
|
290 |
}
|
| 23945 |
amit.gupta |
291 |
|
| 23819 |
govind |
292 |
@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
|
|
|
293 |
public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
|
| 23945 |
amit.gupta |
294 |
Model model) throws ProfitMandiBusinessException, Exception {
|
| 23819 |
govind |
295 |
|
|
|
296 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
|
| 23968 |
amit.gupta |
297 |
Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
|
|
|
298 |
ByteArrayOutputStream baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId());
|
|
|
299 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
300 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
301 |
headers.set("Content-disposition", "inline; filename=pricedrop-" + item.getItemDescriptionNoColor() + "-"
|
|
|
302 |
+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
|
|
|
303 |
byte[] byteArray = baos.toByteArray();
|
|
|
304 |
headers.setContentLength(byteArray.length);
|
|
|
305 |
return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
|
| 23951 |
amit.gupta |
306 |
|
|
|
307 |
}
|
|
|
308 |
|
| 23968 |
amit.gupta |
309 |
private List<ImeiDropSummaryModel> getPartnerPendingImeis(LocalDateTime affectedOn, Integer catalogItemId)
|
| 23951 |
amit.gupta |
310 |
throws Exception {
|
| 23945 |
amit.gupta |
311 |
Map<String, String> params = new HashMap<>();
|
| 23951 |
amit.gupta |
312 |
params.put("MANUAL_criteria1_FROMDATE", FormattingUtils.formatReporitcoDate(affectedOn));
|
|
|
313 |
List<Item> items = itemRepository.selectAllByCatalogItemId(catalogItemId);
|
|
|
314 |
List<String> itemIds = items.stream().map(x -> String.valueOf(x.getId())).collect(Collectors.toList());
|
|
|
315 |
params.put("MANUAL_itemId", StringUtils.join(itemIds, ","));
|
| 23945 |
amit.gupta |
316 |
Map<String, String> params1 = new HashMap<>();
|
| 23951 |
amit.gupta |
317 |
params1.put("MANUAL_criteriaDate_FROMDATE", FormattingUtils.formatReporitcoDate(affectedOn));
|
|
|
318 |
params1.put("MANUAL_criteriaItemId", StringUtils.join(itemIds, ","));
|
| 23945 |
amit.gupta |
319 |
|
|
|
320 |
Map<String, String> params2 = new HashMap<>();
|
| 23951 |
amit.gupta |
321 |
params2.put("MANUAL_Criteria2_FROMDATE", FormattingUtils.formatReporitcoDate(affectedOn));
|
|
|
322 |
params2.put("MANUAL_Criteria1", StringUtils.join(itemIds, ","));
|
|
|
323 |
List<? extends ImeiDropSummaryModel> grnPendingList = getReports(GrnPendingDataModel.class,
|
|
|
324 |
ReporticoProject.FOCO, "imeispendinggrn.xml", params);
|
|
|
325 |
List<? extends ImeiDropSummaryModel> partnerImeiNotSoldList = getReports(PartnerImeiNotSold.class,
|
|
|
326 |
ReporticoProject.FOCO, "PartnerIMEINotSold.xml", params1);
|
|
|
327 |
List<? extends ImeiDropSummaryModel> itemStockOnDateList = getReports(ClosingStockOnDate.class,
|
|
|
328 |
ReporticoProject.WAREHOUSENEW, "itemstockondate.xml", params2);
|
|
|
329 |
List<ImeiDropSummaryModel> mergedImeis = new ArrayList<>();
|
|
|
330 |
mergedImeis.addAll(grnPendingList);
|
|
|
331 |
mergedImeis.addAll(partnerImeiNotSoldList);
|
| 23968 |
amit.gupta |
332 |
|
|
|
333 |
return mergedImeis;
|
|
|
334 |
}
|
|
|
335 |
|
|
|
336 |
private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId)
|
|
|
337 |
throws Exception {
|
|
|
338 |
|
|
|
339 |
List<Item> items = itemRepository.selectAllByCatalogItemId(catalogItemId);
|
|
|
340 |
List<String> itemIds = items.stream().map(x -> String.valueOf(x.getId())).collect(Collectors.toList());
|
|
|
341 |
|
|
|
342 |
Map<String, String> params = new HashMap<>();
|
|
|
343 |
params.put("MANUAL_criteria1_FROMDATE", FormattingUtils.formatReporitcoDate(affectedOn));
|
|
|
344 |
params.put("MANUAL_itemId", StringUtils.join(itemIds, ","));
|
|
|
345 |
|
|
|
346 |
Map<String, String> params1 = new HashMap<>();
|
|
|
347 |
params1.put("MANUAL_criteriaDate_FROMDATE", FormattingUtils.formatReporitcoDate(affectedOn));
|
|
|
348 |
params1.put("MANUAL_criteriaItemId", StringUtils.join(itemIds, ","));
|
|
|
349 |
|
|
|
350 |
List<? extends ImeiDropSummaryModel> grnPendingList = getReports(GrnPendingDataModel.class,
|
|
|
351 |
ReporticoProject.FOCO, "imeispendinggrn.xml", params);
|
|
|
352 |
List<? extends ImeiDropSummaryModel> partnerImeiNotSoldList = getReports(PartnerImeiNotSold.class,
|
|
|
353 |
ReporticoProject.FOCO, "PartnerIMEINotSold.xml", params1);
|
|
|
354 |
|
|
|
355 |
List<ImeiDropSummaryModel> mergedImeis = new ArrayList<>();
|
|
|
356 |
mergedImeis.addAll(grnPendingList);
|
|
|
357 |
mergedImeis.addAll(partnerImeiNotSoldList);
|
|
|
358 |
|
| 23951 |
amit.gupta |
359 |
List<List<Object>> rows = new ArrayList<>();
|
|
|
360 |
for (ImeiDropSummaryModel imeiDropSummaryModel : mergedImeis) {
|
|
|
361 |
List<Object> row = new ArrayList<>();
|
|
|
362 |
row.add(imeiDropSummaryModel.getSerialNumber());
|
|
|
363 |
row.add(imeiDropSummaryModel.getStoreName());
|
|
|
364 |
row.add(imeiDropSummaryModel.getPartnerCode());
|
|
|
365 |
row.add(imeiDropSummaryModel.getItemId());
|
|
|
366 |
row.add(imeiDropSummaryModel.getBrand());
|
|
|
367 |
row.add(imeiDropSummaryModel.getModelName());
|
|
|
368 |
row.add(imeiDropSummaryModel.getModelNumber());
|
|
|
369 |
row.add(imeiDropSummaryModel.getColor());
|
|
|
370 |
row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getLastScanned()));
|
|
|
371 |
rows.add(row);
|
|
|
372 |
}
|
|
|
373 |
|
|
|
374 |
return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
|
|
|
375 |
"Model Name", "Model Number", "Color", "Last Scanned"), rows);
|
| 23819 |
govind |
376 |
}
|
|
|
377 |
|
| 23945 |
amit.gupta |
378 |
private <T> List<T> getReports(Class<T> className, ReporticoProject project, String reportName,
|
|
|
379 |
Map<String, String> params) throws Exception {
|
|
|
380 |
HttpResponse reportResponse = reporticoService.getJsonFile(project, reportName, params);
|
| 23951 |
amit.gupta |
381 |
JavaType type = objectMapper.getTypeFactory().constructParametricType(ReporticoResponseModel.class, className);
|
|
|
382 |
ObjectReader or = objectMapper.readerFor(type);
|
| 23945 |
amit.gupta |
383 |
ReporticoResponseModel<T> responseObj = or.readValue(reportResponse.getEntity().getContent());
|
|
|
384 |
return responseObj.getData();
|
|
|
385 |
}
|
|
|
386 |
|
| 23884 |
amit.gupta |
387 |
private boolean validatePriceDrop(PriceDropModel priceDropModel) throws ProfitMandiBusinessException {
|
| 23945 |
amit.gupta |
388 |
if (priceDropModel.getMop() > 0 && priceDropModel.getMop() > 0 && priceDropModel.getNlc() > 0
|
|
|
389 |
&& priceDropModel.getTp() > 0 && priceDropModel.getNlc() > 0) {
|
| 23884 |
amit.gupta |
390 |
return true;
|
|
|
391 |
}
|
|
|
392 |
return false;
|
|
|
393 |
}
|
| 23945 |
amit.gupta |
394 |
|
| 23819 |
govind |
395 |
}
|