Subversion Repositories SmartDukaan

Rev

Rev 28846 | Rev 28871 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 28846 Rev 28865
Line 1... Line 1...
1
package com.smartdukaan.cron.migrations;
1
package com.smartdukaan.cron.migrations;
2
 
2
 
3
import java.io.File;
3
import java.io.File;
-
 
4
import java.io.FileInputStream;
4
import java.io.IOException;
5
import java.io.IOException;
-
 
6
import java.io.InputStream;
5
import java.time.LocalDate;
7
import java.time.LocalDate;
6
import java.time.LocalDateTime;
8
import java.time.LocalDateTime;
7
import java.time.LocalTime;
9
import java.time.LocalTime;
8
import java.time.Month;
10
import java.time.Month;
9
import java.time.temporal.ChronoUnit;
11
import java.time.temporal.ChronoUnit;
Line 17... Line 19...
17
import java.util.List;
19
import java.util.List;
18
import java.util.Map;
20
import java.util.Map;
19
import java.util.Set;
21
import java.util.Set;
20
import java.util.concurrent.TimeUnit;
22
import java.util.concurrent.TimeUnit;
21
import java.util.stream.Collectors;
23
import java.util.stream.Collectors;
-
 
24
import java.util.stream.IntStream;
22
 
25
 
23
import org.apache.commons.io.output.ByteArrayOutputStream;
26
import org.apache.commons.io.output.ByteArrayOutputStream;
24
import org.apache.commons.lang.StringUtils;
27
import org.apache.commons.lang.StringUtils;
25
import org.apache.logging.log4j.LogManager;
28
import org.apache.logging.log4j.LogManager;
26
import org.apache.logging.log4j.Logger;
29
import org.apache.logging.log4j.Logger;
-
 
30
import org.apache.poi.ss.usermodel.CellType;
-
 
31
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
-
 
32
import org.apache.poi.xssf.usermodel.XSSFRow;
-
 
33
import org.apache.poi.xssf.usermodel.XSSFSheet;
-
 
34
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
27
import org.json.JSONArray;
35
import org.json.JSONArray;
28
import org.json.JSONObject;
36
import org.json.JSONObject;
29
import org.openqa.selenium.Dimension;
37
import org.openqa.selenium.Dimension;
30
import org.openqa.selenium.OutputType;
38
import org.openqa.selenium.OutputType;
31
import org.openqa.selenium.TakesScreenshot;
39
import org.openqa.selenium.TakesScreenshot;
Line 42... Line 50...
42
import com.smartdukaan.cron.scheduled.SamsungIMEIActivationService;
50
import com.smartdukaan.cron.scheduled.SamsungIMEIActivationService;
43
import com.smartdukaan.cron.scheduled.ScheduledTasks;
51
import com.smartdukaan.cron.scheduled.ScheduledTasks;
44
import com.spice.profitmandi.common.enumuration.ItemType;
52
import com.spice.profitmandi.common.enumuration.ItemType;
45
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
53
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
46
import com.spice.profitmandi.common.model.CustomRetailer;
54
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
55
import com.spice.profitmandi.common.model.PartnerTargetModel;
47
import com.spice.profitmandi.common.model.ProfitMandiConstants;
56
import com.spice.profitmandi.common.model.ProfitMandiConstants;
48
import com.spice.profitmandi.common.util.FileUtil;
57
import com.spice.profitmandi.common.util.FileUtil;
49
import com.spice.profitmandi.common.util.FormattingUtils;
58
import com.spice.profitmandi.common.util.FormattingUtils;
50
import com.spice.profitmandi.common.util.Utils;
59
import com.spice.profitmandi.common.util.Utils;
51
import com.spice.profitmandi.dao.entity.catalog.Item;
60
import com.spice.profitmandi.dao.entity.catalog.Item;
52
import com.spice.profitmandi.dao.entity.catalog.Offer;
61
import com.spice.profitmandi.dao.entity.catalog.Offer;
53
import com.spice.profitmandi.dao.entity.catalog.Scheme;
62
import com.spice.profitmandi.dao.entity.catalog.Scheme;
54
import com.spice.profitmandi.dao.entity.catalog.TagListing;
63
import com.spice.profitmandi.dao.entity.catalog.TagListing;
-
 
64
import com.spice.profitmandi.dao.entity.catalog.TargetSlab;
55
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
65
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
56
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
66
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
57
import com.spice.profitmandi.dao.entity.fofo.DebitNote;
67
import com.spice.profitmandi.dao.entity.fofo.DebitNote;
58
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
68
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
59
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
69
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
Line 1209... Line 1219...
1209
		List<WarehouseInventoryItem> lavaInventoryItems = warehouseInventoryItemRepository.getSerialNumbers("Lava",
1219
		List<WarehouseInventoryItem> lavaInventoryItems = warehouseInventoryItemRepository.getSerialNumbers("Lava",
1210
				LocalDate.of(2020, Month.SEPTEMBER, 1).atStartOfDay(), LocalDateTime.now());
1220
				LocalDate.of(2020, Month.SEPTEMBER, 1).atStartOfDay(), LocalDateTime.now());
1211
		LOGGER.info("Lava Inventory Size is {}", lavaInventoryItems.size());
1221
		LOGGER.info("Lava Inventory Size is {}", lavaInventoryItems.size());
1212
	}
1222
	}
1213
 
1223
 
1214
	public void createOffers(int offerId) throws Exception {
1224
	public void createOffers(String fileName) throws Exception {
1215
		Map<List<Integer>, List<Integer>> targetMap = new HashMap<>();
1225
		Map<CreateOfferRequest, List<PartnerTargetModel>> offerPartnerTargetMap = this.parseFromExcel(fileName);
1216
		targetMap.put(Arrays.asList(175138805, 175138733, 175138821, 175138886, 175138853, 175138799),
1226
		for(Map.Entry<CreateOfferRequest, List<PartnerTargetModel>> partnerTargetEntry: offerPartnerTargetMap.entrySet()) {
1217
				Arrays.asList(300000, 330000, 375000));
1227
			CreateOfferRequest createOfferRequest = partnerTargetEntry.getKey();
1218
		targetMap.put(Arrays.asList(175138895, 175138877, 175138854, 175138857, 175138870, 175138862, 175138873),
1228
			Map<List<Integer>, List<Integer>> targetPartnerMap = partnerTargetEntry.getValue().stream().collect(Collectors.groupingBy(PartnerTargetModel::getTargets, Collectors.mapping(PartnerTargetModel::getFofoId, Collectors.toList())));
1219
				Arrays.asList(350000, 400000, 450000));
1229
					for (Map.Entry<List<Integer>, List<Integer>> targetPartnersEntry : targetPartnerMap.entrySet()) {
1220
		targetMap.put(Arrays.asList(175138878), Arrays.asList(380000, 418000, 475000));
1230
						List<Integer> fofoIds = createOfferRequest.getPartnerCriteria().getFofoIds();
1221
		targetMap.put(Arrays.asList(175138922, 175138833, 175138893, 175138939, 175138832, 175138949, 175138882,
1231
						List<Integer> filterFofoIds = targetPartnersEntry.getKey().stream().filter(x->!fofoIds.contains(x)).collect(Collectors.toList());
1222
				175138876, 175138834, 175138930, 175138911, 175138522, 175138871, 175138934, 175138900, 4149607,
1232
						List<Integer> targets = targetPartnersEntry.getKey();
-
 
1233
						
1223
				175138835, 175138941, 175138917, 175138855, 175138825, 175138896, 175138866, 175138174, 175138887,
1234
						createOfferRequest.getPartnerCriteria().setFofoIds(filterFofoIds);
1224
				175138816, 175138892, 175135376, 175138918, 175138845, 175138946, 175138920, 175138903, 175138813,
1235
						int counter = 0;
1225
				175138901, 175138899, 175136389, 175138913, 175138919, 175138923, 175138926, 175138950, 175138953,
1236
						for (com.spice.profitmandi.dao.model.TargetSlab targetSlab : createOfferRequest.getTargetSlabs()) {
1226
				175138954, 175138955), Arrays.asList(400000, 500000, 600000));
1237
							targetSlab.setOnwardsAmount(targets.get(counter));
-
 
1238
							counter++;
-
 
1239
						}
1227
		targetMap.put(Arrays.asList(175138839), Arrays.asList(412000, 453200, 515000));
1240
						offerService.addOfferService(createOfferRequest);
-
 
1241
					}
-
 
1242
		}
-
 
1243
	}
-
 
1244
 
1228
		targetMap.put(Arrays.asList(175138716), Arrays.asList(450000, 495000, 562500));
1245
	private Map<CreateOfferRequest, List<PartnerTargetModel>> parseFromExcel(String fileName) throws ProfitMandiBusinessException {
-
 
1246
 
1229
		targetMap.put(Arrays.asList(175138812), Arrays.asList(465000, 511500, 581250));
1247
		Map<CreateOfferRequest, List<PartnerTargetModel>> offerPartnerTargetMap =  new HashMap<>();
-
 
1248
		XSSFWorkbook myWorkBook = null;
-
 
1249
		try {
1230
		targetMap.put(Arrays.asList(175138859, 175138906, 175138874, 175138940, 175138916, 175136207, 175138851,
1250
			FileInputStream fileInputStream = new FileInputStream(fileName);
1231
				175138844, 175138929), Arrays.asList(500000, 600000, 700000));
1251
			myWorkBook = new XSSFWorkbook(fileInputStream);
1232
		targetMap.put(Arrays.asList(175138804, 175138910), Arrays.asList(550000, 600000, 650000));
1252
			myWorkBook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
1233
		targetMap.put(Arrays.asList(175127215, 175138879), Arrays.asList(555000, 610500, 693750));
1253
			for(int i=0; i< myWorkBook.getNumberOfSheets();i++) {
1234
		targetMap.put(
1254
				
1235
				Arrays.asList(175138869, 175138902, 175138909, 175138914, 175138824, 157112773, 175138897, 175138801),
-
 
1236
				Arrays.asList(600000, 730000, 840000));
1255
				XSSFSheet mySheet = myWorkBook.getSheetAt(i);
1237
		targetMap.put(Arrays.asList(172157716), Arrays.asList(616000, 677600, 770000));
1256
				int offerId = Integer.parseInt(mySheet.getSheetName());
1238
		targetMap.put(Arrays.asList(175138674, 175138840), Arrays.asList(650000, 715000, 812500));
1257
				CreateOfferRequest existingOffer = offerService.getOffer(offerId);
1239
		targetMap.put(Arrays.asList(175138936, 175138952, 175138907, 156232687, 175138856, 175138836, 175138942),
1258
				List<PartnerTargetModel> partnerTargetModels = new ArrayList<>();
1240
				Arrays.asList(700000, 800000, 900000));
1259
				offerPartnerTargetMap.put(existingOffer, partnerTargetModels);
-
 
1260
 
1241
		targetMap.put(Arrays.asList(175138868), Arrays.asList(775000, 852500, 968750));
1261
				LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
1242
		targetMap.put(Arrays.asList(175138820), Arrays.asList(780000, 850000, 1050000));
1262
				for (int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++) {
1243
		targetMap.put(Arrays.asList(175138864, 175138863, 175138867, 175138823, 175135227),
1263
					XSSFRow row = mySheet.getRow(rowNumber);
1244
				Arrays.asList(800000, 900000, 1000000));
1264
					LOGGER.info("row {}", row);
1245
		targetMap.put(Arrays.asList(175138408), Arrays.asList(850000, 900000, 950000));
1265
					PartnerTargetModel partnerTargetModel = new PartnerTargetModel();
-
 
1266
 
1246
		targetMap.put(Arrays.asList(175135923, 175138888), Arrays.asList(900000, 990000, 1125000));
1267
					if (row.getCell(0) != null && row.getCell(0).getCellTypeEnum() == CellType.NUMERIC) {
1247
		targetMap.put(Arrays.asList(175138908), Arrays.asList(1000000, 1200000, 1350000));
1268
						partnerTargetModel.setFofoId((int) row.getCell(0).getNumericCellValue());
-
 
1269
					} else {
1248
		targetMap.put(Arrays.asList(175138843), Arrays.asList(1100000, 1200000, 1350000));
1270
						ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
1249
		targetMap.put(Arrays.asList(175138827), Arrays.asList(1150000, 1265000, 1437500));
1271
								"FOFO ID", row.getCell(0).toString(), "TGLSTNG_VE_1010");
1250
		targetMap.put(Arrays.asList(175138883, 175135707), Arrays.asList(1200000, 1300000, 1400000));
1272
						LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
-
 
1273
						throw profitMandiBusinessException;
-
 
1274
					}
-
 
1275
					List<Integer> targets = new ArrayList<>();
1251
		targetMap.put(Arrays.asList(175138814, 175138829), Arrays.asList(1300000, 1500000, 1650000));
1276
					for (int cellNumber = 1; cellNumber <= existingOffer.getTargetSlabs().size(); cellNumber++) {
-
 
1277
						if (row.getCell(cellNumber) != null
1252
		targetMap.put(Arrays.asList(175138842, 175138875), Arrays.asList(1500000, 1650000, 1800000));
1278
								&& row.getCell(cellNumber).getCellTypeEnum() == CellType.NUMERIC) {
1253
		targetMap.put(Arrays.asList(175138541), Arrays.asList(1600000, 1700000, 1850000));
1279
							targets.add((int) row.getCell(cellNumber).getNumericCellValue());
-
 
1280
						} else {
1254
		targetMap.put(Arrays.asList(175138372), Arrays.asList(1890000, 2079000, 2362500));
1281
							ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(
1255
		targetMap.put(Arrays.asList(175138885), Arrays.asList(2100000, 2400000, 2600000));
1282
									"Target Column issue at " + rowNumber + ", " + cellNumber, row.getCell(cellNumber),
1256
 
-
 
-
 
1283
									"Invalid target");
1257
		CreateOfferRequest createOfferRequest = offerService.getOffer(offerId);
1284
							LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
-
 
1285
							throw profitMandiBusinessException;
-
 
1286
						}
-
 
1287
					}
1258
		for (Map.Entry<List<Integer>, List<Integer>> targetEntry : targetMap.entrySet()) {
1288
					partnerTargetModel.setTargets(targets);
1259
			List<Integer> targets = targetEntry.getValue();
1289
					partnerTargetModels.add(partnerTargetModel);
-
 
1290
				}
1260
 
1291
			}
-
 
1292
			myWorkBook.close();
1261
			createOfferRequest.getPartnerCriteria().setFofoIds(targetEntry.getKey());
1293
		} catch ( ProfitMandiBusinessException pbse) {
1262
			int counter = 0;
1294
			throw pbse;
-
 
1295
		} catch (IOException ioException) {
-
 
1296
			ioException.printStackTrace();
1263
			for (com.spice.profitmandi.dao.model.TargetSlab targetSlab : createOfferRequest.getTargetSlabs()) {
1297
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EXCEL_FILE, ioException.getMessage(),
-
 
1298
					"EXL_VE_1000");
-
 
1299
		} finally {
1264
				targetSlab.setOnwardsAmount(targets.get(counter));
1300
			if (myWorkBook != null) {
1265
				counter++;
1301
				try {
-
 
1302
					myWorkBook.close();
-
 
1303
				} catch (IOException e) {
-
 
1304
					// TODO Auto-generated catch block
-
 
1305
					e.printStackTrace();
-
 
1306
				}
1266
			}
1307
			}
1267
			offerService.addOfferService(createOfferRequest);
-
 
1268
		}
1308
		}
-
 
1309
		LOGGER.info("offerPartnerTargetMap {}", offerPartnerTargetMap);
-
 
1310
		return offerPartnerTargetMap;
1269
	}
1311
	}
1270
 
1312
 
1271
	@Autowired
1313
	@Autowired
1272
	private WarehouseScanRepository warehouseScanRepository;
1314
	private WarehouseScanRepository warehouseScanRepository;
1273
 
1315