| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.common.util;
|
1 |
package com.spice.profitmandi.common.util;
|
| 2 |
|
2 |
|
| 3 |
import java.io.IOException;
|
3 |
import java.io.IOException;
|
| 4 |
import java.io.InputStream;
|
4 |
import java.io.InputStream;
|
| 5 |
import java.io.OutputStream;
|
5 |
import java.io.OutputStream;
|
| - |
|
6 |
import java.time.LocalDate;
|
| 6 |
import java.time.LocalDateTime;
|
7 |
import java.time.LocalDateTime;
|
| - |
|
8 |
import java.time.LocalTime;
|
| 7 |
import java.time.ZoneId;
|
9 |
import java.time.ZoneId;
|
| 8 |
import java.util.ArrayList;
|
10 |
import java.util.ArrayList;
|
| - |
|
11 |
import java.util.Arrays;
|
| 9 |
import java.util.Date;
|
12 |
import java.util.Date;
|
| 10 |
import java.util.LinkedHashMap;
|
13 |
import java.util.LinkedHashMap;
|
| 11 |
import java.util.List;
|
14 |
import java.util.List;
|
| 12 |
import java.util.Map;
|
15 |
import java.util.Map;
|
| 13 |
import java.util.Set;
|
16 |
import java.util.Set;
|
| Line 37... |
Line 40... |
| 37 |
import com.spice.profitmandi.common.model.PartnerTargetModel;
|
40 |
import com.spice.profitmandi.common.model.PartnerTargetModel;
|
| 38 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
41 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 39 |
import com.spice.profitmandi.common.model.SchemeModel;
|
42 |
import com.spice.profitmandi.common.model.SchemeModel;
|
| 40 |
import com.spice.profitmandi.common.model.TagListingModel;
|
43 |
import com.spice.profitmandi.common.model.TagListingModel;
|
| 41 |
|
44 |
|
| - |
|
45 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| - |
|
46 |
|
| 42 |
public class ExcelUtils {
|
47 |
public class ExcelUtils {
|
| 43 |
private static final String TAG_ID = "Tag Id";
|
48 |
private static final String TAG_ID = "Tag Id";
|
| 44 |
private static final String TAG_LABEL = "Tag Label";
|
49 |
private static final String TAG_LABEL = "Tag Label";
|
| 45 |
private static final String ITEM_ID = "Item Id";
|
50 |
private static final String ITEM_ID = "Item Id";
|
| 46 |
private static final String BRAND = "Brand";
|
51 |
private static final String BRAND = "Brand";
|
| Line 55... |
Line 60... |
| 55 |
private static final String FOFO_ID = "fofoId";
|
60 |
private static final String FOFO_ID = "fofoId";
|
| 56 |
private static final String STORE_NAME = "storeName";
|
61 |
private static final String STORE_NAME = "storeName";
|
| 57 |
private static final String EMAIL = "email";
|
62 |
private static final String EMAIL = "email";
|
| 58 |
private static final String TARGET_VALUE = "targetValue";
|
63 |
private static final String TARGET_VALUE = "targetValue";
|
| 59 |
|
64 |
|
| - |
|
65 |
private static final List<WalletReferenceType> BULK_WALLET_REFERENCES = Arrays.asList(
|
| - |
|
66 |
|
| - |
|
67 |
WalletReferenceType.BRAND_FEE, WalletReferenceType.FESTIVE_OFFER, WalletReferenceType.GOODWILL_GESTURE,
|
| - |
|
68 |
WalletReferenceType.EOL, WalletReferenceType.ACTIVATION_SCHEME, WalletReferenceType.BRAND_PAYOUT,
|
| - |
|
69 |
WalletReferenceType.SALES_MARKETING_SUPPORT, WalletReferenceType.INVESTMENT_PAYOUT,
|
| - |
|
70 |
WalletReferenceType.CATEGORY_SPL_PAYOUT, WalletReferenceType.REFERRAL_INCENTIVES
|
| - |
|
71 |
|
| - |
|
72 |
);
|
| - |
|
73 |
|
| 60 |
private static final Logger LOGGER = LogManager.getLogger(ExcelUtils.class);
|
74 |
private static final Logger LOGGER = LogManager.getLogger(ExcelUtils.class);
|
| 61 |
|
75 |
|
| 62 |
public static void main(String[] args) throws Throwable {
|
76 |
public static void main(String[] args) throws Throwable {
|
| 63 |
// List<Integer> intervals = Arrays.asList(5, 10, 15, 20, 25);
|
77 |
// List<Integer> intervals = Arrays.asList(5, 10, 15, 20, 25);
|
| 64 |
// writeInventoryItemAgingModels(inventoryItemAgingModels, intervals);
|
78 |
// writeInventoryItemAgingModels(inventoryItemAgingModels, intervals);
|
| Line 174... |
Line 188... |
| 174 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
|
188 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
|
| 175 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
|
189 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
|
| 176 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
|
190 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
|
| 177 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
|
191 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
|
| 178 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
|
192 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
|
| 179 |
|
193 |
|
| 180 |
int rowIndex = 0;
|
194 |
int rowIndex = 0;
|
| 181 |
Row rowHeader = sheet.createRow(rowIndex++);
|
195 |
Row rowHeader = sheet.createRow(rowIndex++);
|
| 182 |
Row rowPriceQuantity = sheet.createRow(rowIndex++);
|
196 |
Row rowPriceQuantity = sheet.createRow(rowIndex++);
|
| 183 |
int i=0;
|
197 |
int i = 0;
|
| 184 |
if(showPartner) {
|
198 |
if (showPartner) {
|
| 185 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 6, 6));
|
199 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 6, 6));
|
| 186 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 7, 7));
|
200 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 7, 7));
|
| 187 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 8, 8));
|
201 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 8, 8));
|
| 188 |
}
|
202 |
}
|
| 189 |
sheet.trackAllColumnsForAutoSizing();
|
203 |
sheet.trackAllColumnsForAutoSizing();
|
| 190 |
if(showPartner) {
|
204 |
if (showPartner) {
|
| 191 |
Cell cellFofoIdHeader = rowHeader.createCell(i++);
|
205 |
Cell cellFofoIdHeader = rowHeader.createCell(i++);
|
| 192 |
cellFofoIdHeader.setCellValue("Partner Id");
|
206 |
cellFofoIdHeader.setCellValue("Partner Id");
|
| 193 |
Cell cellStoreCodeHeader = rowHeader.createCell(i++);
|
207 |
Cell cellStoreCodeHeader = rowHeader.createCell(i++);
|
| 194 |
cellStoreCodeHeader.setCellValue("Store Code");
|
208 |
cellStoreCodeHeader.setCellValue("Store Code");
|
| 195 |
Cell cellStoreNameHeader = rowHeader.createCell(i++);
|
209 |
Cell cellStoreNameHeader = rowHeader.createCell(i++);
|
| Line 214... |
Line 228... |
| 214 |
} else if (index < intervals.size()) {
|
228 |
} else if (index < intervals.size()) {
|
| 215 |
cellHeader.setCellValue(intervals.get(index - 1) + " - " + intervals.get(index) + " Days");
|
229 |
cellHeader.setCellValue(intervals.get(index - 1) + " - " + intervals.get(index) + " Days");
|
| 216 |
} else {
|
230 |
} else {
|
| 217 |
cellHeader.setCellValue("More Than " + intervals.get(index - 1) + " Days");
|
231 |
cellHeader.setCellValue("More Than " + intervals.get(index - 1) + " Days");
|
| 218 |
}
|
232 |
}
|
| 219 |
sheet.addMergedRegion(new CellRangeAddress(0, 0, i-1, i));
|
233 |
sheet.addMergedRegion(new CellRangeAddress(0, 0, i - 1, i));
|
| 220 |
rowHeader.createCell(i++);
|
234 |
rowHeader.createCell(i++);
|
| 221 |
Cell cellPrice = rowPriceQuantity.createCell(i-2);
|
235 |
Cell cellPrice = rowPriceQuantity.createCell(i - 2);
|
| 222 |
cellPrice.setCellValue("Price");
|
236 |
cellPrice.setCellValue("Price");
|
| 223 |
Cell cellQuantity = rowPriceQuantity.createCell(i-1);
|
237 |
Cell cellQuantity = rowPriceQuantity.createCell(i - 1);
|
| 224 |
cellQuantity.setCellValue("Quantity");
|
238 |
cellQuantity.setCellValue("Quantity");
|
| 225 |
}
|
239 |
}
|
| 226 |
|
240 |
|
| 227 |
Font font = workbook.createFont();
|
241 |
Font font = workbook.createFont();
|
| 228 |
font.setBold(true);
|
242 |
font.setBold(true);
|
| 229 |
CellStyle cellStyle = workbook.createCellStyle();
|
243 |
CellStyle cellStyle = workbook.createCellStyle();
|
| 230 |
cellStyle.setFont(font);
|
244 |
cellStyle.setFont(font);
|
| 231 |
for (int j = 0; j < nonValueColumns + ((intervals.size()+1)) * 2; j++) {
|
245 |
for (int j = 0; j < nonValueColumns + ((intervals.size() + 1)) * 2; j++) {
|
| 232 |
rowHeader.getCell(j).setCellStyle(cellStyle);
|
246 |
rowHeader.getCell(j).setCellStyle(cellStyle);
|
| 233 |
if (rowPriceQuantity.getCell(j) != null) {
|
247 |
if (rowPriceQuantity.getCell(j) != null) {
|
| 234 |
rowPriceQuantity.getCell(j).setCellStyle(cellStyle);
|
248 |
rowPriceQuantity.getCell(j).setCellStyle(cellStyle);
|
| 235 |
}
|
249 |
}
|
| 236 |
}
|
250 |
}
|
| 237 |
for (InventoryItemAgingModel inventoryItemAgingModel : inventoryItemAgingModels) {
|
251 |
for (InventoryItemAgingModel inventoryItemAgingModel : inventoryItemAgingModels) {
|
| 238 |
i=0;
|
252 |
i = 0;
|
| 239 |
Row rowValues = sheet.createRow(rowIndex++);
|
253 |
Row rowValues = sheet.createRow(rowIndex++);
|
| 240 |
if(showPartner) {
|
254 |
if (showPartner) {
|
| 241 |
rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getFofoId());
|
255 |
rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getFofoId());
|
| 242 |
rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getStoreCode());
|
256 |
rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getStoreCode());
|
| 243 |
rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getStoreName());
|
257 |
rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getStoreName());
|
| 244 |
}
|
258 |
}
|
| 245 |
rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getItemId());
|
259 |
rowValues.createCell(i++).setCellValue(inventoryItemAgingModel.getItemId());
|
| Line 259... |
Line 273... |
| 259 |
rowValues.createCell(i++).setCellValue("-");
|
273 |
rowValues.createCell(i++).setCellValue("-");
|
| 260 |
}
|
274 |
}
|
| 261 |
}
|
275 |
}
|
| 262 |
}
|
276 |
}
|
| 263 |
|
277 |
|
| 264 |
for (int index = 0; index < nonValueColumns + ((intervals.size()+1) * 2); index++) {
|
278 |
for (int index = 0; index < nonValueColumns + ((intervals.size() + 1) * 2); index++) {
|
| 265 |
sheet.autoSizeColumn(index);
|
279 |
sheet.autoSizeColumn(index);
|
| 266 |
}
|
280 |
}
|
| 267 |
|
281 |
|
| 268 |
try {
|
282 |
try {
|
| 269 |
workbook.write(outputStream);
|
283 |
workbook.write(outputStream);
|
| Line 907... |
Line 921... |
| 907 |
} catch (IOException ioException) {
|
921 |
} catch (IOException ioException) {
|
| 908 |
LOGGER.error("Unable to generate excel file", ioException);
|
922 |
LOGGER.error("Unable to generate excel file", ioException);
|
| 909 |
}
|
923 |
}
|
| 910 |
}
|
924 |
}
|
| 911 |
|
925 |
|
| - |
|
926 |
public static List<WalletHistoryModel> parseWalletBulkCredit(InputStream inputStream) throws Exception {
|
| - |
|
927 |
List<WalletHistoryModel> walletHistoryModels = new ArrayList<>();
|
| - |
|
928 |
try (XSSFWorkbook myWorkBook = new XSSFWorkbook(inputStream)) {
|
| - |
|
929 |
|
| - |
|
930 |
myWorkBook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
|
| - |
|
931 |
// Return first sheet from the XLSX workbook
|
| - |
|
932 |
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
|
| - |
|
933 |
LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
|
| - |
|
934 |
|
| - |
|
935 |
for (int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++) {
|
| - |
|
936 |
XSSFRow row = mySheet.getRow(rowNumber);
|
| - |
|
937 |
LOGGER.info("row {}", row);
|
| - |
|
938 |
WalletHistoryModel walletHistoryModel = new WalletHistoryModel();
|
| - |
|
939 |
if (row.getCell(1) != null && row.getCell(1).getCellTypeEnum() == CellType.NUMERIC) {
|
| - |
|
940 |
walletHistoryModel.setFofoId((int) row.getCell(1).getNumericCellValue());
|
| - |
|
941 |
} else {
|
| - |
|
942 |
throw new ProfitMandiBusinessException("Invalid Fofo Id", "row number " + rowNumber,
|
| - |
|
943 |
"row number " + rowNumber);
|
| - |
|
944 |
}
|
| - |
|
945 |
if (row.getCell(2) != null && row.getCell(2).getCellTypeEnum() == CellType.STRING) {
|
| - |
|
946 |
WalletReferenceType referenceType = WalletReferenceType
|
| - |
|
947 |
.valueOf(row.getCell(2).getStringCellValue());
|
| - |
|
948 |
if (!BULK_WALLET_REFERENCES.contains(referenceType)) {
|
| - |
|
949 |
throw new ProfitMandiBusinessException("Invalid Reference type", "row number " + rowNumber,
|
| - |
|
950 |
"row number " + rowNumber);
|
| - |
|
951 |
}
|
| - |
|
952 |
walletHistoryModel
|
| - |
|
953 |
.setWalletReferenceType(WalletReferenceType.valueOf(row.getCell(2).getStringCellValue()));
|
| - |
|
954 |
} else {
|
| - |
|
955 |
throw new ProfitMandiBusinessException("Invalid ReferenceType", "row number " + rowNumber,
|
| - |
|
956 |
"row number " + rowNumber);
|
| - |
|
957 |
}
|
| - |
|
958 |
if (row.getCell(3) != null && row.getCell(3).getCellTypeEnum() == CellType.NUMERIC) {
|
| - |
|
959 |
Date businessDate = row.getCell(3).getDateCellValue();
|
| - |
|
960 |
LocalDateTime businessDateTime = LocalDateTime.of(
|
| - |
|
961 |
LocalDate.of(businessDate.getYear(), businessDate.getMonth(), businessDate.getDate()),
|
| - |
|
962 |
LocalTime.MIDNIGHT);
|
| - |
|
963 |
walletHistoryModel.setBusinessDate(businessDateTime);
|
| - |
|
964 |
;
|
| - |
|
965 |
} else {
|
| - |
|
966 |
throw new ProfitMandiBusinessException("Invalid Business Date", "row number " + rowNumber,
|
| - |
|
967 |
"row number " + rowNumber);
|
| - |
|
968 |
}
|
| - |
|
969 |
if (row.getCell(4) != null && row.getCell(4).getCellTypeEnum() == CellType.NUMERIC) {
|
| - |
|
970 |
Date businessDate = row.getCell(4).getDateCellValue();
|
| - |
|
971 |
LocalDateTime businessDateTime = LocalDateTime.of(
|
| - |
|
972 |
LocalDate.of(businessDate.getYear(), businessDate.getMonth(), businessDate.getDate()),
|
| - |
|
973 |
LocalTime.MIDNIGHT);
|
| - |
|
974 |
walletHistoryModel.setBusinessDate(businessDateTime);
|
| - |
|
975 |
;
|
| - |
|
976 |
} else {
|
| - |
|
977 |
throw new ProfitMandiBusinessException("Invalid Business Date", "row number " + rowNumber,
|
| - |
|
978 |
"row number " + rowNumber);
|
| - |
|
979 |
}
|
| - |
|
980 |
if (row.getCell(5) != null && row.getCell(5).getCellTypeEnum() == CellType.NUMERIC) {
|
| - |
|
981 |
double amount = row.getCell(5).getNumericCellValue();
|
| - |
|
982 |
if (amount < 0) {
|
| - |
|
983 |
throw new ProfitMandiBusinessException("Invalid Amount, only positive values",
|
| - |
|
984 |
"row number " + rowNumber, "row number " + rowNumber);
|
| - |
|
985 |
}
|
| - |
|
986 |
walletHistoryModel.setAmount(amount);
|
| - |
|
987 |
} else {
|
| - |
|
988 |
throw new ProfitMandiBusinessException("Invalid Amount", "row number " + rowNumber,
|
| - |
|
989 |
"row number " + rowNumber);
|
| - |
|
990 |
}
|
| - |
|
991 |
if (row.getCell(6) != null && row.getCell(6).getCellTypeEnum() == CellType.STRING) {
|
| - |
|
992 |
String transactionType = row.getCell(6).getStringCellValue().toLowerCase();
|
| - |
|
993 |
if (transactionType.equals("dr")) {
|
| - |
|
994 |
walletHistoryModel.setAmount(-walletHistoryModel.getAmount());
|
| - |
|
995 |
} else if (!transactionType.equals("cr")) {
|
| - |
|
996 |
throw new ProfitMandiBusinessException("Invalid Transaction Type", "row number " + rowNumber,
|
| - |
|
997 |
"row number " + rowNumber);
|
| - |
|
998 |
}
|
| - |
|
999 |
} else {
|
| - |
|
1000 |
throw new ProfitMandiBusinessException("Invalid Transaction Type", "row number " + rowNumber,
|
| - |
|
1001 |
"row number " + rowNumber);
|
| - |
|
1002 |
}
|
| - |
|
1003 |
if (row.getCell(7) != null && row.getCell(7).getCellTypeEnum() == CellType.STRING) {
|
| - |
|
1004 |
String description = row.getCell(7).getStringCellValue().toLowerCase();
|
| - |
|
1005 |
walletHistoryModel.setDescription(description);
|
| - |
|
1006 |
} else {
|
| - |
|
1007 |
throw new ProfitMandiBusinessException("Invalid Transaction Type", "row number " + rowNumber,
|
| - |
|
1008 |
"row number " + rowNumber);
|
| - |
|
1009 |
}
|
| - |
|
1010 |
walletHistoryModels.add(walletHistoryModel);
|
| - |
|
1011 |
}
|
| - |
|
1012 |
return walletHistoryModels;
|
| - |
|
1013 |
}
|
| - |
|
1014 |
}
|
| - |
|
1015 |
|
| 912 |
}
|
1016 |
}
|