Subversion Repositories SmartDukaan

Rev

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

Rev 24052 Rev 24107
Line 31... Line 31...
31
 
31
 
32
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
32
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
33
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
33
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
34
import com.spice.profitmandi.common.model.InventoryItemAgingValue;
34
import com.spice.profitmandi.common.model.InventoryItemAgingValue;
35
import com.spice.profitmandi.common.model.ItemCompleteLedgerModel;
35
import com.spice.profitmandi.common.model.ItemCompleteLedgerModel;
-
 
36
import com.spice.profitmandi.common.model.PartnerTargetModel;
36
import com.spice.profitmandi.common.model.ProfitMandiConstants;
37
import com.spice.profitmandi.common.model.ProfitMandiConstants;
37
import com.spice.profitmandi.common.model.SchemeModel;
38
import com.spice.profitmandi.common.model.SchemeModel;
38
import com.spice.profitmandi.common.model.TagListingModel;
39
import com.spice.profitmandi.common.model.TagListingModel;
39
 
40
 
40
public class ExcelUtils {
41
public class ExcelUtils {
Line 48... Line 49...
48
	private static final String SELLING_PRICE = "Selling Price";
49
	private static final String SELLING_PRICE = "Selling Price";
49
	private static final String MOP = "MOP";
50
	private static final String MOP = "MOP";
50
	private static final String SUPPORT_PRICE = "Support Price";
51
	private static final String SUPPORT_PRICE = "Support Price";
51
	private static final String START_DATE = "Start Date";
52
	private static final String START_DATE = "Start Date";
52
	private static final String TAG_LISTING = "Tag Listing";
53
	private static final String TAG_LISTING = "Tag Listing";
-
 
54
	private static final String FOFO_ID = "fofoId";
-
 
55
	private static final String STORE_NAME = "storeName";
-
 
56
	private static final String EMAIL = "email";
-
 
57
	private static final String TARGET_VALUE="targetValue";
53
	
58
	
54
	private static final Logger LOGGER = LogManager.getLogger(ExcelUtils.class);
59
	private static final Logger LOGGER = LogManager.getLogger(ExcelUtils.class);
55
	
60
	
56
	public static void main(String[] args) throws Throwable{
61
	public static void main(String[] args) throws Throwable{
57
		//List<Integer> intervals = Arrays.asList(5, 10, 15, 20, 25);
62
		//List<Integer> intervals = Arrays.asList(5, 10, 15, 20, 25);
Line 667... Line 672...
667
	    	workbook.close();
672
	    	workbook.close();
668
	    }catch(IOException ioException){
673
	    }catch(IOException ioException){
669
	    	LOGGER.error("Unable to generate excel file", ioException);
674
	    	LOGGER.error("Unable to generate excel file", ioException);
670
	    }
675
	    }
671
	}
676
	}
-
 
677
public static List<PartnerTargetModel> parseFromExcel(InputStream inputStream) throws Exception {
-
 
678
		
-
 
679
		List<PartnerTargetModel> partnerTargetModels = new ArrayList<>();
-
 
680
		XSSFWorkbook myWorkBook = null;
-
 
681
		try{
-
 
682
			//FileInputStream fileInputStream = new FileInputStream("/home/ashikali/tag_listing1.xlsx");
-
 
683
			myWorkBook = new XSSFWorkbook (inputStream);
-
 
684
			
-
 
685
			myWorkBook.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
-
 
686
			// Return first sheet from the XLSX workbook 
-
 
687
			XSSFSheet mySheet = myWorkBook.getSheetAt(0);
-
 
688
			LOGGER.info("rowCellNum {}", mySheet.getLastRowNum());
-
 
689
			
-
 
690
			for(int rowNumber = 1; rowNumber <= mySheet.getLastRowNum(); rowNumber++){
-
 
691
				XSSFRow row = mySheet.getRow(rowNumber);
-
 
692
				LOGGER.info("row {}", row);
-
 
693
				PartnerTargetModel partnerTargetModel = new PartnerTargetModel();
-
 
694
				if(row.getCell(0) != null && row.getCell(0).getCellTypeEnum() == CellType.NUMERIC){
-
 
695
					partnerTargetModel.setFofoId((int) row.getCell(0).getNumericCellValue());
-
 
696
				}else{
-
 
697
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(FOFO_ID, row.getCell(0).toString(), "TGLSTNG_VE_1010");
-
 
698
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
-
 
699
					throw profitMandiBusinessException;
-
 
700
				}
-
 
701
				
-
 
702
				if(row.getCell(1) != null && row.getCell(1).getCellTypeEnum() == CellType.STRING){
-
 
703
					partnerTargetModel.setStoreName(row.getCell(1).getStringCellValue());
-
 
704
				}else{
-
 
705
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(STORE_NAME, row.getCell(2).toString(), "TGLSTNG_VE_1010");
-
 
706
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
-
 
707
					throw profitMandiBusinessException;
-
 
708
				}
-
 
709
 
-
 
710
				if(row.getCell(2) != null && row.getCell(2).getCellTypeEnum() == CellType.STRING){
-
 
711
					partnerTargetModel.setEmail(row.getCell(2).getStringCellValue());
-
 
712
				}else{
-
 
713
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(EMAIL, row.getCell(7), "TGLSTNG_VE_1010");
-
 
714
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
-
 
715
					throw profitMandiBusinessException;
-
 
716
				}
-
 
717
				if(row.getCell(3) != null && row.getCell(3).getCellTypeEnum() == CellType.NUMERIC){
-
 
718
					partnerTargetModel.setTargetValue((int) row.getCell(3).getNumericCellValue());
-
 
719
				}else{
-
 
720
					ProfitMandiBusinessException profitMandiBusinessException = new ProfitMandiBusinessException(TARGET_VALUE, row.getCell(8), "TGLSTNG_VE_1010");
-
 
721
					LOGGER.error("Excel file parse error : ", profitMandiBusinessException);
-
 
722
					throw profitMandiBusinessException;
-
 
723
				}
-
 
724
				
-
 
725
				partnerTargetModels.add(partnerTargetModel);
-
 
726
			}
-
 
727
			myWorkBook.close();
-
 
728
		} catch(IOException ioException){
-
 
729
			ioException.printStackTrace();
-
 
730
			throw new ProfitMandiBusinessException(ProfitMandiConstants.EXCEL_FILE, ioException.getMessage(), "EXL_VE_1000");
-
 
731
		} finally {
-
 
732
			if(myWorkBook != null){
-
 
733
				try {
-
 
734
					myWorkBook.close();
-
 
735
				} catch (IOException e) {
-
 
736
					// TODO Auto-generated catch block
-
 
737
					e.printStackTrace();
-
 
738
				}
-
 
739
			}
-
 
740
		}
-
 
741
		return partnerTargetModels;
672
	
742
	}
673
}
743
}