| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.common.util;
|
1 |
package com.spice.profitmandi.common.util;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.io.FileOutputStream;
|
| 3 |
import java.io.IOException;
|
4 |
import java.io.IOException;
|
| 4 |
import java.io.InputStream;
|
5 |
import java.io.InputStream;
|
| - |
|
6 |
import java.io.OutputStream;
|
| 5 |
import java.time.LocalDateTime;
|
7 |
import java.time.LocalDateTime;
|
| 6 |
import java.time.ZoneId;
|
8 |
import java.time.ZoneId;
|
| 7 |
import java.util.ArrayList;
|
9 |
import java.util.ArrayList;
|
| 8 |
import java.util.Date;
|
10 |
import java.util.Date;
|
| 9 |
import java.util.List;
|
11 |
import java.util.List;
|
| 10 |
|
12 |
|
| 11 |
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
13 |
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
| 12 |
import org.apache.poi.sl.usermodel.Sheet;
|
14 |
import org.apache.poi.ss.usermodel.Cell;
|
| - |
|
15 |
import org.apache.poi.ss.usermodel.CellStyle;
|
| 13 |
import org.apache.poi.ss.usermodel.CellType;
|
16 |
import org.apache.poi.ss.usermodel.CellType;
|
| - |
|
17 |
import org.apache.poi.ss.usermodel.CreationHelper;
|
| - |
|
18 |
import org.apache.poi.ss.usermodel.Font;
|
| - |
|
19 |
import org.apache.poi.ss.usermodel.Row;
|
| 14 |
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
|
20 |
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
|
| - |
|
21 |
import org.apache.poi.ss.util.CellRangeAddress;
|
| - |
|
22 |
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
| - |
|
23 |
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
| - |
|
24 |
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
| 15 |
import org.apache.poi.xssf.usermodel.XSSFRow;
|
25 |
import org.apache.poi.xssf.usermodel.XSSFRow;
|
| 16 |
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
26 |
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
| 17 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
27 |
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
| 18 |
import org.slf4j.Logger;
|
28 |
import org.slf4j.Logger;
|
| 19 |
import org.slf4j.LoggerFactory;
|
29 |
import org.slf4j.LoggerFactory;
|
| 20 |
|
30 |
|
| 21 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
31 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
32 |
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
|
| - |
|
33 |
import com.spice.profitmandi.common.model.InventoryItemAgingValue;
|
| 22 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
34 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23 |
import com.spice.profitmandi.common.model.TagListingModel;
|
35 |
import com.spice.profitmandi.common.model.TagListingModel;
|
| 24 |
|
36 |
|
| 25 |
public class ExcelUtils {
|
37 |
public class ExcelUtils {
|
| 26 |
private static final String TAG_ID = "Tag Id";
|
38 |
private static final String TAG_ID = "Tag Id";
|
| Line 37... |
Line 49... |
| 37 |
private static final String TAG_LISTING = "Tag Listing";
|
49 |
private static final String TAG_LISTING = "Tag Listing";
|
| 38 |
|
50 |
|
| 39 |
private static final Logger LOGGER = LoggerFactory.getLogger(ExcelUtils.class);
|
51 |
private static final Logger LOGGER = LoggerFactory.getLogger(ExcelUtils.class);
|
| 40 |
|
52 |
|
| 41 |
public static void main(String[] args) throws Throwable{
|
53 |
public static void main(String[] args) throws Throwable{
|
| 42 |
parse(null);
|
54 |
//List<Integer> intervals = Arrays.asList(5, 10, 15, 20, 25);
|
| - |
|
55 |
//writeInventoryItemAgingModels(inventoryItemAgingModels, intervals);
|
| 43 |
}
|
56 |
}
|
| 44 |
public static List<TagListingModel> parse(InputStream inputStream) throws Throwable {
|
57 |
public static List<TagListingModel> parse(InputStream inputStream) throws Throwable {
|
| 45 |
|
58 |
|
| 46 |
List<TagListingModel> tagListings = new ArrayList<>();
|
59 |
List<TagListingModel> tagListings = new ArrayList<>();
|
| 47 |
XSSFWorkbook myWorkBook = null;
|
60 |
XSSFWorkbook myWorkBook = null;
|
| Line 120... |
Line 133... |
| 120 |
}
|
133 |
}
|
| 121 |
}
|
134 |
}
|
| 122 |
}
|
135 |
}
|
| 123 |
return tagListings;
|
136 |
return tagListings;
|
| 124 |
}
|
137 |
}
|
| - |
|
138 |
|
| - |
|
139 |
public static OutputStream writeInventoryItemAgingModels(List<InventoryItemAgingModel> inventoryItemAgingModels, List<Integer> intervals){
|
| - |
|
140 |
SXSSFWorkbook workbook = new SXSSFWorkbook();
|
| - |
|
141 |
|
| - |
|
142 |
//CreationHelper createHelper = workbook.getCreationHelper();
|
| - |
|
143 |
|
| - |
|
144 |
SXSSFSheet sheet = workbook.createSheet("InventoryItemAging");
|
| - |
|
145 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
|
| - |
|
146 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
|
| - |
|
147 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
|
| - |
|
148 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
|
| - |
|
149 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 4, 4));
|
| - |
|
150 |
sheet.addMergedRegion(new CellRangeAddress(0, 1, 5, 5));
|
| - |
|
151 |
sheet.trackAllColumnsForAutoSizing();
|
| - |
|
152 |
|
| - |
|
153 |
|
| - |
|
154 |
Row rowHeader = sheet.createRow(0);
|
| - |
|
155 |
Cell cellItemIdHeader = rowHeader.createCell(0);
|
| - |
|
156 |
cellItemIdHeader.setCellValue("Item Id");
|
| - |
|
157 |
Cell cellBrandHeader = rowHeader.createCell(1);
|
| - |
|
158 |
cellBrandHeader.setCellValue("Brand");
|
| - |
|
159 |
Cell cellModelNameHeader = rowHeader.createCell(2);
|
| - |
|
160 |
cellModelNameHeader.setCellValue("Model Name");
|
| - |
|
161 |
Cell cellModelNumberHeader = rowHeader.createCell(3);
|
| - |
|
162 |
cellModelNumberHeader.setCellValue("Model Number");
|
| - |
|
163 |
Cell cellColorHeader = rowHeader.createCell(4);
|
| - |
|
164 |
cellColorHeader.setCellValue("Color");
|
| - |
|
165 |
Cell cellTypeHeader = rowHeader.createCell(5);
|
| - |
|
166 |
cellTypeHeader.setCellValue("Item Type");
|
| - |
|
167 |
Row rowPriceQuantity = sheet.createRow(1);
|
| - |
|
168 |
for(int index = 0, colIndex = 6; index < intervals.size() + 1; index++, colIndex = colIndex + 2){
|
| - |
|
169 |
Cell cellHeader = rowHeader.createCell(colIndex);
|
| - |
|
170 |
if(index == 0){
|
| - |
|
171 |
cellHeader.setCellValue("Less Than "+intervals.get(index)+" Days");
|
| - |
|
172 |
}else if(index < intervals.size()){
|
| - |
|
173 |
cellHeader.setCellValue(intervals.get(index - 1) + " - " + intervals.get(index) + " Days");
|
| - |
|
174 |
}else{
|
| - |
|
175 |
cellHeader.setCellValue("More Than "+intervals.get(index - 1)+" Days");
|
| - |
|
176 |
}
|
| - |
|
177 |
sheet.addMergedRegion(new CellRangeAddress(0, 0, colIndex, colIndex + 1));
|
| - |
|
178 |
rowHeader.createCell(colIndex + 1);
|
| - |
|
179 |
Cell cellPrice = rowPriceQuantity.createCell(colIndex);
|
| - |
|
180 |
cellPrice.setCellValue("Price");
|
| - |
|
181 |
Cell cellQuantity = rowPriceQuantity.createCell(colIndex + 1);
|
| - |
|
182 |
cellQuantity.setCellValue("Quantity");
|
| - |
|
183 |
}
|
| - |
|
184 |
Font font = workbook.createFont();
|
| - |
|
185 |
CellStyle cellStyle = workbook.createCellStyle();
|
| - |
|
186 |
font.setBold(true);
|
| - |
|
187 |
//font.setFontHeight((short)16);
|
| - |
|
188 |
cellStyle.setFont(font);
|
| - |
|
189 |
for(int i = 0; i < 18; i++){
|
| - |
|
190 |
rowHeader.getCell(i).setCellStyle(cellStyle);
|
| - |
|
191 |
if(rowPriceQuantity.getCell(i) != null){
|
| - |
|
192 |
rowPriceQuantity.getCell(i).setCellStyle(cellStyle);
|
| - |
|
193 |
}
|
| - |
|
194 |
}
|
| - |
|
195 |
|
| - |
|
196 |
for(int index = 0; index < inventoryItemAgingModels.size(); index++){
|
| - |
|
197 |
InventoryItemAgingModel inventoryItemAgingModel = inventoryItemAgingModels.get(index);
|
| - |
|
198 |
Row rowValues = sheet.createRow(index + 2);
|
| - |
|
199 |
Cell cellItemId = rowValues.createCell(0);
|
| - |
|
200 |
cellItemId.setCellValue(inventoryItemAgingModel.getItemId());
|
| - |
|
201 |
Cell cellBrand = rowValues.createCell(1);
|
| - |
|
202 |
cellBrand.setCellValue(inventoryItemAgingModel.getBrand());
|
| - |
|
203 |
Cell cellModelName = rowValues.createCell(2);
|
| - |
|
204 |
cellModelName.setCellValue(inventoryItemAgingModel.getModelName());
|
| - |
|
205 |
Cell cellModelNumber = rowValues.createCell(3);
|
| - |
|
206 |
cellModelNumber.setCellValue(inventoryItemAgingModel.getModelNumber());
|
| - |
|
207 |
Cell cellColor = rowValues.createCell(4);
|
| - |
|
208 |
cellColor.setCellValue(inventoryItemAgingModel.getColor());
|
| - |
|
209 |
Cell cellType = rowValues.createCell(5);
|
| - |
|
210 |
cellType.setCellValue(inventoryItemAgingModel.getItemType().toString());
|
| - |
|
211 |
List<InventoryItemAgingValue> inventoryItemAgingValues = inventoryItemAgingModel.getValues();
|
| - |
|
212 |
//LOGGER.info("inventoryItemAgingValues {}", inventoryItemAgingValues);
|
| - |
|
213 |
for(int i = 0, colIndex = 6; i < inventoryItemAgingValues.size(); i++, colIndex = colIndex + 2){
|
| - |
|
214 |
Cell cellPrice = rowValues.createCell(colIndex);
|
| - |
|
215 |
InventoryItemAgingValue inventoryItemAgingValue = inventoryItemAgingValues.get(i);
|
| - |
|
216 |
//LOGGER.info("inventoryItemAgingValue {}", inventoryItemAgingValue);
|
| - |
|
217 |
Cell cellQuantity = rowValues.createCell(colIndex + 1);
|
| - |
|
218 |
if(inventoryItemAgingValue != null){
|
| - |
|
219 |
cellPrice.setCellValue(inventoryItemAgingValue.getPrice());
|
| - |
|
220 |
cellQuantity.setCellValue(inventoryItemAgingValue.getQuantity());
|
| - |
|
221 |
}else{
|
| - |
|
222 |
cellPrice.setCellValue("NA");
|
| - |
|
223 |
cellQuantity.setCellValue("NA");
|
| - |
|
224 |
}
|
| - |
|
225 |
}
|
| - |
|
226 |
}
|
| - |
|
227 |
|
| - |
|
228 |
for(int index = 0; index < 18; index++){
|
| - |
|
229 |
sheet.autoSizeColumn(index);
|
| - |
|
230 |
}
|
| - |
|
231 |
|
| - |
|
232 |
try{
|
| - |
|
233 |
FileOutputStream fileOutputStream = new FileOutputStream("/home/ashikali/Documents/testInventoryItemAging.xlsx");
|
| - |
|
234 |
workbook.write(fileOutputStream);
|
| - |
|
235 |
workbook.close();
|
| - |
|
236 |
}catch(IOException ioException){
|
| - |
|
237 |
LOGGER.info("Unable to generate excel file", ioException);
|
| - |
|
238 |
}
|
| - |
|
239 |
return null;
|
| - |
|
240 |
}
|
| - |
|
241 |
|
| 125 |
}
|
242 |
}
|