Subversion Repositories SmartDukaan

Rev

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

Rev 27599 Rev 27628
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.io.File;
3
import java.io.File;
4
import java.io.FileInputStream;
4
import java.io.FileInputStream;
5
import java.io.FileNotFoundException;
5
import java.io.FileNotFoundException;
-
 
6
import java.io.FileOutputStream;
-
 
7
import java.io.ObjectInputStream;
-
 
8
import java.io.ObjectOutputStream;
6
import java.time.LocalDate;
9
import java.time.LocalDate;
7
import java.time.LocalDateTime;
10
import java.time.LocalDateTime;
8
import java.time.LocalTime;
11
import java.time.LocalTime;
9
import java.time.YearMonth;
12
import java.time.YearMonth;
10
import java.time.ZoneOffset;
13
import java.time.ZoneOffset;
Line 37... Line 40...
37
import org.springframework.ui.Model;
40
import org.springframework.ui.Model;
38
import org.springframework.web.bind.annotation.RequestMapping;
41
import org.springframework.web.bind.annotation.RequestMapping;
39
import org.springframework.web.bind.annotation.RequestMethod;
42
import org.springframework.web.bind.annotation.RequestMethod;
40
import org.springframework.web.bind.annotation.RequestParam;
43
import org.springframework.web.bind.annotation.RequestParam;
41
 
44
 
42
import com.fasterxml.jackson.databind.ObjectMapper;
-
 
43
import com.google.gson.Gson;
45
import com.google.gson.Gson;
44
import com.mongodb.DBObject;
46
import com.mongodb.DBObject;
45
import com.spice.profitmandi.common.enumuration.ContentType;
47
import com.spice.profitmandi.common.enumuration.ContentType;
46
import com.spice.profitmandi.common.enumuration.MessageType;
48
import com.spice.profitmandi.common.enumuration.MessageType;
47
import com.spice.profitmandi.common.enumuration.ReporticoProject;
49
import com.spice.profitmandi.common.enumuration.ReporticoProject;
Line 70... Line 72...
70
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
72
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
71
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
73
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
72
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
74
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
73
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
75
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
74
import com.spice.profitmandi.dao.entity.inventory.ReporticoCacheTable;
76
import com.spice.profitmandi.dao.entity.inventory.ReporticoCacheTable;
75
import com.spice.profitmandi.dao.entity.transaction.LineItem;
-
 
76
import com.spice.profitmandi.dao.entity.transaction.Order;
77
import com.spice.profitmandi.dao.entity.transaction.Order;
77
import com.spice.profitmandi.dao.entity.user.Lead;
78
import com.spice.profitmandi.dao.entity.user.Lead;
78
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
79
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
79
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
80
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
80
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
81
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
-
 
82
import com.spice.profitmandi.dao.model.BrandWisePartnerSaleModel;
81
import com.spice.profitmandi.dao.model.CreateOfferRequest;
83
import com.spice.profitmandi.dao.model.CreateOfferRequest;
82
import com.spice.profitmandi.dao.model.ItemTypeParams;
84
import com.spice.profitmandi.dao.model.ItemTypeParams;
83
import com.spice.profitmandi.dao.model.ItemWiseTertiaryModel;
85
import com.spice.profitmandi.dao.model.ItemWiseTertiaryModel;
84
import com.spice.profitmandi.dao.model.MonthSaleModel;
86
import com.spice.profitmandi.dao.model.MonthSaleModel;
85
import com.spice.profitmandi.dao.model.PartnerDetailModel;
87
import com.spice.profitmandi.dao.model.PartnerDetailModel;
86
import com.spice.profitmandi.dao.model.PartnerPendingIndentItemModel;
88
import com.spice.profitmandi.dao.model.PartnerPendingIndentItemModel;
87
import com.spice.profitmandi.dao.model.SimpleCampaign;
89
import com.spice.profitmandi.dao.model.SimpleCampaign;
88
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
90
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
89
import com.spice.profitmandi.dao.model.WarehouseBrandWiseItemSaleModel;
91
import com.spice.profitmandi.dao.model.WarehouseBrandWiseItemSaleModel;
90
import com.spice.profitmandi.dao.model.BrandWisePartnerSaleModel;
-
 
91
import com.spice.profitmandi.dao.model.WarehouseWiseBrandStockModel;
-
 
92
import com.spice.profitmandi.dao.model.WarehouseWiseBrandSaleModel;
92
import com.spice.profitmandi.dao.model.WarehouseWiseBrandSaleModel;
-
 
93
import com.spice.profitmandi.dao.model.WarehouseWiseBrandStockModel;
93
import com.spice.profitmandi.dao.model.WarehouseWiseStockModel;
94
import com.spice.profitmandi.dao.model.WarehouseWiseStockModel;
94
import com.spice.profitmandi.dao.model.WarehouseWiseitemStockModel;
95
import com.spice.profitmandi.dao.model.WarehouseWiseitemStockModel;
95
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
96
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
96
import com.spice.profitmandi.dao.repository.auth.MenuCategoryRepository;
97
import com.spice.profitmandi.dao.repository.auth.MenuCategoryRepository;
97
import com.spice.profitmandi.dao.repository.auth.MenuRepository;
98
import com.spice.profitmandi.dao.repository.auth.MenuRepository;
Line 304... Line 305...
304
			model.addAttribute("fofoStore", customRetailer);
305
			model.addAttribute("fofoStore", customRetailer);
305
			model.addAttribute("partnerType", partnerType);
306
			model.addAttribute("partnerType", partnerType);
306
			model.addAttribute("hasGift", hasGift(fofoId));
307
			model.addAttribute("hasGift", hasGift(fofoId));
307
			model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
308
			model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
308
 
309
 
309
			model.addAttribute("brandStockPrices", this.getBrandStockPrices(fofoId));
310
			// model.addAttribute("brandStockPrices", this.getBrandStockPrices(fofoId));
310
			model.addAttribute("salesMap", this.getSales(fofoId));
311
			model.addAttribute("salesMap", this.getSales(fofoId));
311
			model.addAttribute("activatedImeis", inventoryItemRepository.selectCountByActivatedNotSold(fofoId));
312
			model.addAttribute("activatedImeis", inventoryItemRepository.selectCountByActivatedNotSold(fofoId));
312
			// this.setInvestments
313
			// this.setInvestments
313
			//
314
			//
314
			model.addAttribute("investments", this.getInvestments(fofoId));
315
			model.addAttribute("investments", this.getInvestments(fofoId));
Line 787... Line 788...
787
		List<Menu> menus = null;
788
		List<Menu> menus = null;
788
		try {
789
		try {
789
			AuthUser authUser = authRepository.selectByEmailOrMobile(email);
790
			AuthUser authUser = authRepository.selectByEmailOrMobile(email);
790
			List<Position> positions = positionRepository.selectAll(authUser.getId());
791
			List<Position> positions = positionRepository.selectAll(authUser.getId());
791
			Map<Integer, PartnerDetailModel> warehousePartnerDetailMap = null;
792
			Map<Integer, PartnerDetailModel> warehousePartnerDetailMap = null;
792
			ReporticoCacheTable rct = null;
793
			ReporticoCacheTable rctSaholic = null;
-
 
794
			ReporticoCacheTable rctPartneStat = null;
-
 
795
 
793
			Map<Integer, WarehouseWiseStockModel> warehouseStockMap = new HashMap<>();
796
			Map<Integer, WarehouseWiseStockModel> warehouseStockMap = new HashMap<>();
794
			Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
797
			Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
795
			LinkedHashMap<Integer, String> wm = new LinkedHashMap<Integer, String>();
798
			LinkedHashMap<Integer, String> wm = new LinkedHashMap<Integer, String>();
796
 
799
 
797
			List<BrandWisePartnerSaleModel> partnersBrandSale = null;
800
			List<BrandWisePartnerSaleModel> partnersBrandSale = null;
Line 835... Line 838...
835
						warehouseStockMap.put(0, ws);
838
						warehouseStockMap.put(0, ws);
836
 
839
 
837
					}
840
					}
838
 
841
 
839
					warehousePartnerDetailMap = this.getWarehousePartnerDetail();
842
					warehousePartnerDetailMap = this.getWarehousePartnerDetail();
-
 
843
					LOGGER.info("warehousePartnerDetailMap" + warehousePartnerDetailMap);
840
					rct = reporticoCacheTableRepository.selectByTableName("SaholicInventoryCIS");
844
					rctSaholic = reporticoCacheTableRepository.selectByTableName("SaholicInventoryCIS");
-
 
845
					rctPartneStat = reporticoCacheTableRepository.selectByTableName("partnerStat");
841
					partnersBrandSale = fofoStoreRepository.selectGroupByBrandWarehousePartnerSale();
846
					partnersBrandSale = fofoStoreRepository.selectGroupByBrandWarehousePartnerSale();
842
					accessoriesBrandSales = fofoStoreRepository.selectGroupByBrandAccesoriesWarehousePartnerSale();
847
					accessoriesBrandSales = fofoStoreRepository.selectGroupByBrandAccesoriesWarehousePartnerSale();
843
				}
848
				}
844
			}
849
			}
845
 
850
 
Line 882... Line 887...
882
					model.addAttribute("warehouses", getWarehouses(positionRetailers));
887
					model.addAttribute("warehouses", getWarehouses(positionRetailers));
883
				}
888
				}
884
				model.addAttribute("authId", authUser.getId());
889
				model.addAttribute("authId", authUser.getId());
885
 
890
 
886
			}
891
			}
-
 
892
			model.addAttribute("rctPartneStat", rctPartneStat);
-
 
893
 
887
			model.addAttribute("reporticoDate", rct);
894
			model.addAttribute("reporticoDate", rctSaholic);
888
			model.addAttribute("warehousePartnerDetailMap", warehousePartnerDetailMap);
895
			model.addAttribute("warehousePartnerDetailMap", warehousePartnerDetailMap);
889
			model.addAttribute("warehouseMap", wm);
896
			model.addAttribute("warehouseMap", wm);
890
			model.addAttribute("warehouseStockMap", warehouseStockMap);
897
			model.addAttribute("warehouseStockMap", warehouseStockMap);
891
			model.addAttribute("brandSales", partnersBrandSale);
898
			model.addAttribute("brandSales", partnersBrandSale);
892
 
899
 
Line 1011... Line 1018...
1011
	@RequestMapping(value = "/getWarehousePartners", method = RequestMethod.GET)
1018
	@RequestMapping(value = "/getWarehousePartners", method = RequestMethod.GET)
1012
	public String warehousePartnersDetail(HttpServletRequest request, Model model, @RequestParam int warehouseId)
1019
	public String warehousePartnersDetail(HttpServletRequest request, Model model, @RequestParam int warehouseId)
1013
			throws Exception {
1020
			throws Exception {
1014
 
1021
 
1015
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
1022
		Map<Integer, CustomRetailer> fofoIdAndPartnerMap = retailerService.getFofoRetailers(false);
1016
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = partnerStatsService.getAllPartnerStats();
1023
		Map<Integer, PartnerDetailModel> fofoIdAndallValues = this.getPartnersStatDataFromFile();
1017
		if (warehouseId != 0) {
1024
		if (warehouseId != 0) {
1018
 
1025
 
1019
			List<Integer> fofoIds = fofoStoreRepository.selectActivePartnerByWarehouse(warehouseId).stream()
1026
			List<Integer> fofoIds = fofoStoreRepository.selectActivePartnerByWarehouse(warehouseId).stream()
1020
					.map(x -> x.getId()).collect(Collectors.toList());
1027
					.map(x -> x.getId()).collect(Collectors.toList());
1021
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
1028
			fofoIdAndallValues = fofoIdAndallValues.entrySet().stream().filter(x -> fofoIds.contains(x.getKey()))
Line 1048... Line 1055...
1048
		inventoryService.getItemAvailabilityAndIndent();
1055
		inventoryService.getItemAvailabilityAndIndent();
1049
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
1056
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
1050
		return "response";
1057
		return "response";
1051
	}
1058
	}
1052
 
1059
 
-
 
1060
	public Map<Integer, PartnerDetailModel> getWarehousePartnerDetail() throws Exception {
-
 
1061
 
-
 
1062
		Map<Integer, PartnerDetailModel> warehouseIdAndallValues = new LinkedHashMap<>();
-
 
1063
		Map<Integer, List<FofoStore>> warehousePartnerMap = fofoStoreRepository.getWarehousePartnerMap();
-
 
1064
		Map<Integer, PartnerDetailModel> partnerStats = this.getPartnersStatDataFromFile();
-
 
1065
		if (partnerStats != null) {
-
 
1066
			for (Entry<Integer, List<FofoStore>> warehouse : warehousePartnerMap.entrySet()) {
-
 
1067
				List<Integer> fofoIds = warehouse.getValue().stream().map(x -> x.getId()).collect(Collectors.toList());
-
 
1068
				List<PartnerDetailModel> partnerDetails = fofoIds.stream().map(x -> partnerStats.get(x))
-
 
1069
						.collect(Collectors.toList());
-
 
1070
				LOGGER.info("partnerDetails" + partnerDetails);
-
 
1071
 
-
 
1072
				PartnerDetailModel partnerDetailModel = partnerStatsService.getAggregateStats(partnerDetails);
-
 
1073
 
-
 
1074
				warehouseIdAndallValues.put(warehouse.getKey(), partnerDetailModel);
-
 
1075
			}
-
 
1076
			LOGGER.info("warehouseIdAndallValues" + warehouseIdAndallValues);
-
 
1077
			PartnerDetailModel partnerDetailModel = partnerStatsService
-
 
1078
					.getAggregateStats(new ArrayList<>(partnerStats.values()));
-
 
1079
			warehouseIdAndallValues.put(0, partnerDetailModel);
-
 
1080
		}
-
 
1081
		return warehouseIdAndallValues;
-
 
1082
	}
-
 
1083
 
-
 
1084
	@RequestMapping(value = "/getPartnersStatData", method = RequestMethod.GET)
-
 
1085
	public String getPartnersStatData(HttpServletRequest request, Model model) throws Exception {
-
 
1086
		Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
-
 
1087
		ObjectOutputStream oos = null;
-
 
1088
		FileOutputStream fout = null;
-
 
1089
		try {
-
 
1090
			fout = new FileOutputStream("/tmp/partnerStat.tmp", false);
-
 
1091
			oos = new ObjectOutputStream(fout);
-
 
1092
			oos.writeObject(partnerStats);
-
 
1093
 
-
 
1094
		} catch (Exception ex) {
-
 
1095
			ex.printStackTrace();
-
 
1096
		} finally {
-
 
1097
			if (oos != null) {
-
 
1098
				oos.close();
-
 
1099
			}
-
 
1100
		}
-
 
1101
		ReporticoCacheTable rct = reporticoCacheTableRepository.selectByTableName("partnerStat");
-
 
1102
		if (rct == null) {
-
 
1103
			rct = new ReporticoCacheTable();
-
 
1104
			rct.setTableName("partnerStat");
-
 
1105
 
-
 
1106
		}
-
 
1107
		rct.setLastCreatedTimestamp(LocalDateTime.now());
-
 
1108
		reporticoCacheTableRepository.persist(rct);
-
 
1109
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
1110
		return "response";
-
 
1111
	}
-
 
1112
 
-
 
1113
	public Map<Integer, PartnerDetailModel> getPartnersStatDataFromFile() throws Exception {
-
 
1114
		ObjectInputStream objectinputstream = null;
-
 
1115
		Map<Integer, PartnerDetailModel> partnerStat = null;
-
 
1116
		try {
-
 
1117
			FileInputStream streamIn = new FileInputStream("/tmp/partnerStat.tmp");
-
 
1118
			objectinputstream = new ObjectInputStream(streamIn);
-
 
1119
			partnerStat = (Map<Integer, PartnerDetailModel>) objectinputstream.readObject();
-
 
1120
 
-
 
1121
			LOGGER.info("partnerStat" + partnerStat);
-
 
1122
			objectinputstream.close();
-
 
1123
 
-
 
1124
		} catch (Exception e) {
-
 
1125
			LOGGER.info("exceptionddd" + e);
-
 
1126
 
-
 
1127
			e.printStackTrace();
-
 
1128
 
-
 
1129
		} finally {
-
 
1130
			if (objectinputstream != null) {
-
 
1131
				objectinputstream.close();
-
 
1132
				LOGGER.info("clofddd" + partnerStat);
-
 
1133
 
-
 
1134
			}
-
 
1135
		}
-
 
1136
		return partnerStat;
-
 
1137
 
-
 
1138
	}
-
 
1139
 
1053
	@RequestMapping(value = "/getWarehouseWiseBrandAndCategory", method = RequestMethod.GET)
1140
	@RequestMapping(value = "/getWarehouseWiseBrandAndCategory", method = RequestMethod.GET)
1054
	public String getWarehouseWiseBrandAndCategory(HttpServletRequest request, Model model,
1141
	public String getWarehouseWiseBrandAndCategory(HttpServletRequest request, Model model,
1055
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
1142
			@RequestParam List<Integer> warehouseId, @RequestParam List<String> brands, @RequestParam String category)
1056
			throws Exception {
1143
			throws Exception {
1057
 
1144
 
Line 1390... Line 1477...
1390
		authIdAndallValues.put(-1, partnerStatsService.getAggregateStats(unmappedPartnerDetails));
1477
		authIdAndallValues.put(-1, partnerStatsService.getAggregateStats(unmappedPartnerDetails));
1391
		authIdAndallValues.put(0, partnerDetailModel);
1478
		authIdAndallValues.put(0, partnerDetailModel);
1392
		return authIdAndallValues;
1479
		return authIdAndallValues;
1393
	}
1480
	}
1394
 
1481
 
1395
	public Map<Integer, PartnerDetailModel> getWarehousePartnerDetail() throws Exception {
-
 
1396
 
-
 
1397
		Map<Integer, PartnerDetailModel> warehouseIdAndallValues = new LinkedHashMap<>();
-
 
1398
		Map<Integer, List<FofoStore>> warehousePartnerMap = fofoStoreRepository.getWarehousePartnerMap();
-
 
1399
		Map<Integer, PartnerDetailModel> partnerStats = partnerStatsService.getAllPartnerStats();
-
 
1400
 
-
 
1401
		for (Entry<Integer, List<FofoStore>> warehouse : warehousePartnerMap.entrySet()) {
-
 
1402
			List<Integer> fofoIds = warehouse.getValue().stream().map(x -> x.getId()).collect(Collectors.toList());
-
 
1403
			List<PartnerDetailModel> partnerDetails = fofoIds.stream().map(x -> partnerStats.get(x))
-
 
1404
					.collect(Collectors.toList());
-
 
1405
			LOGGER.info("partnerDetails" + partnerDetails);
-
 
1406
 
-
 
1407
			PartnerDetailModel partnerDetailModel = partnerStatsService.getAggregateStats(partnerDetails);
-
 
1408
 
-
 
1409
			warehouseIdAndallValues.put(warehouse.getKey(), partnerDetailModel);
-
 
1410
		}
-
 
1411
		LOGGER.info("warehouseIdAndallValues" + warehouseIdAndallValues);
-
 
1412
		PartnerDetailModel partnerDetailModel = partnerStatsService
-
 
1413
				.getAggregateStats(new ArrayList<>(partnerStats.values()));
-
 
1414
		warehouseIdAndallValues.put(0, partnerDetailModel);
-
 
1415
 
-
 
1416
		return warehouseIdAndallValues;
-
 
1417
	}
-
 
1418
 
-
 
1419
	@RequestMapping(value = "/getItemWiseTertiary", method = RequestMethod.GET)
1482
	@RequestMapping(value = "/getItemWiseTertiary", method = RequestMethod.GET)
1420
	public String getItemWiseTertiary(HttpServletRequest request,
1483
	public String getItemWiseTertiary(HttpServletRequest request,
1421
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
1484
			@RequestParam(name = ProfitMandiConstants.FOFO_ID) int fofoId, Model model)
1422
			throws ProfitMandiBusinessException {
1485
			throws ProfitMandiBusinessException {
1423
		List<ItemWiseTertiaryModel> itemWiseTertiary = fofoOrderRepository.SelectItemWiseTertiary(fofoId);
1486
		List<ItemWiseTertiaryModel> itemWiseTertiary = fofoOrderRepository.SelectItemWiseTertiary(fofoId);