Subversion Repositories SmartDukaan

Rev

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

Rev 28071 Rev 28272
Line 3... Line 3...
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.time.LocalDate;
6
import java.time.LocalDate;
7
import java.time.LocalDateTime;
7
import java.time.LocalDateTime;
-
 
8
import java.util.AbstractMap;
8
import java.util.ArrayList;
9
import java.util.ArrayList;
9
import java.util.Arrays;
10
import java.util.Arrays;
10
import java.util.HashMap;
11
import java.util.HashMap;
11
import java.util.List;
12
import java.util.List;
12
import java.util.Map;
13
import java.util.Map;
-
 
14
import java.util.Map.Entry;
13
import java.util.Set;
15
import java.util.Set;
14
import java.util.stream.Collectors;
16
import java.util.stream.Collectors;
15
 
17
 
16
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletRequest;
17
import javax.transaction.Transactional;
19
import javax.transaction.Transactional;
Line 45... Line 47...
45
import com.spice.profitmandi.common.util.Utils;
47
import com.spice.profitmandi.common.util.Utils;
46
import com.spice.profitmandi.common.web.util.ResponseSender;
48
import com.spice.profitmandi.common.web.util.ResponseSender;
47
import com.spice.profitmandi.dao.entity.auth.AuthUser;
49
import com.spice.profitmandi.dao.entity.auth.AuthUser;
48
import com.spice.profitmandi.dao.entity.cs.PartnerPosition;
50
import com.spice.profitmandi.dao.entity.cs.PartnerPosition;
49
import com.spice.profitmandi.dao.entity.cs.Position;
51
import com.spice.profitmandi.dao.entity.cs.Position;
-
 
52
import com.spice.profitmandi.dao.entity.dtr.BrandLimit;
50
import com.spice.profitmandi.dao.entity.dtr.Document;
53
import com.spice.profitmandi.dao.entity.dtr.Document;
51
import com.spice.profitmandi.dao.entity.dtr.Retailer;
54
import com.spice.profitmandi.dao.entity.dtr.Retailer;
52
import com.spice.profitmandi.dao.entity.dtr.RetailerBlockBrands;
55
import com.spice.profitmandi.dao.entity.dtr.RetailerBlockBrands;
-
 
56
import com.spice.profitmandi.dao.entity.dtr.RetailerBrandsLimit;
53
import com.spice.profitmandi.dao.entity.dtr.Shop;
57
import com.spice.profitmandi.dao.entity.dtr.Shop;
54
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
58
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
55
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
59
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
56
import com.spice.profitmandi.dao.entity.fofo.PartnerTypeChange;
60
import com.spice.profitmandi.dao.entity.fofo.PartnerTypeChange;
57
import com.spice.profitmandi.dao.entity.user.Location;
61
import com.spice.profitmandi.dao.entity.user.Location;
58
import com.spice.profitmandi.dao.entity.user.Promoter;
62
import com.spice.profitmandi.dao.entity.user.Promoter;
59
import com.spice.profitmandi.dao.entity.user.User;
63
import com.spice.profitmandi.dao.entity.user.User;
-
 
64
import com.spice.profitmandi.dao.entity.warehouse.WarehouseInventoryItem;
60
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
65
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
61
import com.spice.profitmandi.dao.repository.cs.CsService;
66
import com.spice.profitmandi.dao.repository.cs.CsService;
-
 
67
import com.spice.profitmandi.dao.repository.cs.RetailerBrandsLimitService;
-
 
68
import com.spice.profitmandi.dao.repository.dtr.BrandLimitRepository;
62
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
69
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
63
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
70
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
64
import com.spice.profitmandi.dao.repository.dtr.Mongo;
71
import com.spice.profitmandi.dao.repository.dtr.Mongo;
65
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
72
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
-
 
73
import com.spice.profitmandi.dao.repository.dtr.RetailerBrandsLimitRepository;
66
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
74
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
67
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
75
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
68
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeRepository;
76
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeRepository;
69
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
77
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
70
import com.spice.profitmandi.dao.repository.user.LocationRepository;
78
import com.spice.profitmandi.dao.repository.user.LocationRepository;
Line 88... Line 96...
88
 
96
 
89
	@Autowired
97
	@Autowired
90
	private RetailerRepository retailerRepository;
98
	private RetailerRepository retailerRepository;
91
 
99
 
92
	@Autowired
100
	@Autowired
-
 
101
	private BrandLimitRepository brandLimitRepository;
-
 
102
 
-
 
103
	@Autowired
-
 
104
	private RetailerBrandsLimitService retailerBrandsLimitService;
-
 
105
 
-
 
106
	@Autowired
-
 
107
	private RetailerBrandsLimitRepository retailerBrandsLimitRepository;
-
 
108
 
-
 
109
	@Autowired
93
	private ShopRepository shopRepository;
110
	private ShopRepository shopRepository;
94
 
111
 
95
	@Autowired
112
	@Autowired
96
	private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
113
	private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
97
 
114
 
Line 666... Line 683...
666
		List<RetailerBlockBrands> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByBrands(brand);
683
		List<RetailerBlockBrands> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByBrands(brand);
667
 
684
 
668
		List<Integer> blockBrandPartners = retailerBlockBrands.stream().map(x -> x.getFofoId())
685
		List<Integer> blockBrandPartners = retailerBlockBrands.stream().map(x -> x.getFofoId())
669
				.collect(Collectors.toList());
686
				.collect(Collectors.toList());
670
		Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
687
		Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
-
 
688
 
671
		LOGGER.info("retailerBlockBrands" + retailerBlockBrands);
689
		LOGGER.info("retailerBlockBrands" + retailerBlockBrands);
672
		model.addAttribute("blockBrandPartners", blockBrandPartners);
690
		model.addAttribute("blockBrandPartners", blockBrandPartners);
673
		model.addAttribute("retailerBlockBrands", retailerBlockBrands);
691
		model.addAttribute("retailerBlockBrands", retailerBlockBrands);
674
		model.addAttribute("customRetailers", customRetailers);
692
		model.addAttribute("customRetailers", customRetailers);
675
 
693
 
Line 697... Line 715...
697
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
715
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
698
 
716
 
699
		return "response";
717
		return "response";
700
	}
718
	}
701
 
719
 
-
 
720
	@RequestMapping(value = "/getBrandslimit", method = RequestMethod.GET)
-
 
721
	public String getBrandslimit(HttpServletRequest request, Model model) throws Exception {
-
 
722
 
-
 
723
		int fofoId = Utils.SYSTEM_PARTNER_ID;
-
 
724
		Set<String> brands = null;
-
 
725
 
-
 
726
		brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
-
 
727
				.collect(Collectors.toSet());
-
 
728
 
-
 
729
		model.addAttribute("brands", brands);
-
 
730
 
-
 
731
		return "brands-limit";
-
 
732
 
-
 
733
	}
-
 
734
 
-
 
735
	@RequestMapping(value = "/setUpdateLimit", method = RequestMethod.POST)
-
 
736
	public String getUpdateLimit(HttpServletRequest request,
-
 
737
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand,
-
 
738
			@RequestParam(name = "fofoId", required = true, defaultValue = "0") int fofoId,
-
 
739
			@RequestParam(name = "limit", required = true, defaultValue = "0") float limit, Model model)
-
 
740
			throws Exception {
-
 
741
 
-
 
742
		CustomRetailer cr = retailerService.getFofoRetailer(fofoId);
-
 
743
		
-
 
744
		
-
 
745
		Map.Entry<Integer, CustomRetailer> customRetailers =  new AbstractMap.SimpleEntry(cr.getPartnerId(), cr);
-
 
746
		
-
 
747
		//Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
-
 
748
		LOGGER.info("customRetailers"+customRetailers);
-
 
749
		RetailerBrandsLimit retailerBrands = retailerBrandsLimitRepository.selectLimitByBrandAndFofoId(fofoId, brand);
-
 
750
		
-
 
751
		if (retailerBrands == null) {
-
 
752
			retailerBrands = new RetailerBrandsLimit();
-
 
753
			retailerBrands.setBrandLimit(limit);
-
 
754
			retailerBrands.setIsUpdate(1);
-
 
755
			retailerBrands.setCreatedTimestamp(LocalDateTime.now());
-
 
756
			retailerBrands.setPartnerId(fofoId);
-
 
757
			retailerBrands.setBrandName(brand);
-
 
758
			retailerBrands.setUpdatedTimestamp(LocalDateTime.now());
-
 
759
			retailerBrandsLimitRepository.persist(retailerBrands);
-
 
760
 
-
 
761
		}
-
 
762
 
-
 
763
		else {
-
 
764
			retailerBrands.setBrandLimit(limit);
-
 
765
			retailerBrands.setIsUpdate(1);
-
 
766
			retailerBrands.setUpdatedTimestamp(LocalDateTime.now());
-
 
767
			retailerBrandsLimitRepository.persist(retailerBrands);
-
 
768
 
-
 
769
		}
-
 
770
		retailerBrands = retailerBrandsLimitRepository.selectLimitByBrandAndFofoId(fofoId, brand);
-
 
771
 
-
 
772
		Map<Integer, RetailerBrandsLimit> retailerBrandsLimitMap = new HashMap<>();
-
 
773
 
-
 
774
		retailerBrandsLimitMap.put(retailerBrands.getPartnerId(), retailerBrands);
-
 
775
 
-
 
776
		BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brand);
-
 
777
 
-
 
778
		model.addAttribute("retailerBrandsLimitMap", retailerBrandsLimitMap);
-
 
779
		model.addAttribute("brandLimit", brandLimit);
-
 
780
		model.addAttribute("customRetailers", customRetailers);
-
 
781
		
-
 
782
		model.addAttribute("brands", brand);
-
 
783
		return "brands-limit-row-mapping";
-
 
784
 
-
 
785
	}
-
 
786
 
-
 
787
	@RequestMapping(value = "/getRetailerBrandslimitMapping", method = RequestMethod.GET)
-
 
788
	public String getRetailerBrandslimit(HttpServletRequest request,
-
 
789
			@RequestParam(name = "brand", required = true, defaultValue = "0") String brand, Model model)
-
 
790
			throws Exception {
-
 
791
 
-
 
792
		Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
-
 
793
 
-
 
794
		model.addAttribute("customRetailers", customRetailers);
-
 
795
		model.addAttribute("brand", brand);
-
 
796
 
-
 
797
		BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brand);
-
 
798
 
-
 
799
		model.addAttribute("brandLimit", brandLimit);
-
 
800
 
-
 
801
		return "brands-limit-mapping";
-
 
802
 
-
 
803
	}
-
 
804
 
-
 
805
	@RequestMapping(value = "/setBrandWiseLimit", method = RequestMethod.POST)
-
 
806
	public String brandwiseLimit(HttpServletRequest request,
-
 
807
			@RequestParam(name = "brands", required = true, defaultValue = "") String brands,
-
 
808
			@RequestParam(name = "limit", required = true, defaultValue = "") float limit, Model model)
-
 
809
			throws Exception {
-
 
810
 
-
 
811
		LOGGER.info("limit" + limit);
-
 
812
 
-
 
813
		BrandLimit brandLimit = brandLimitRepository.setLimitByBrands(brands);
-
 
814
 
-
 
815
		List<RetailerBrandsLimit> retailerBrandsLimit = retailerBrandsLimitRepository.setAllLimitByBrands(brands);
-
 
816
 
-
 
817
		Map<Integer, RetailerBrandsLimit> retailerBrandsLimitMap = retailerBrandsLimit.stream()
-
 
818
				.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
-
 
819
 
-
 
820
		Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
-
 
821
 
-
 
822
		if (brandLimit == null) {
-
 
823
 
-
 
824
			brandLimit = new BrandLimit();
-
 
825
			brandLimit.setBrandLimit(limit);
-
 
826
			brandLimit.setBrandName(brands);
-
 
827
			brandLimit.setCreatedTimestamp(LocalDateTime.now());
-
 
828
			brandLimit.setUpdatedTimestamp(LocalDateTime.now());
-
 
829
			brandLimitRepository.persist(brandLimit);
-
 
830
 
-
 
831
		}
-
 
832
 
-
 
833
		else {
-
 
834
			brandLimit.setBrandLimit(limit);
-
 
835
 
-
 
836
			brandLimit.setUpdatedTimestamp(LocalDateTime.now());
-
 
837
			brandLimitRepository.persist(brandLimit);
-
 
838
 
-
 
839
		}
-
 
840
		brandLimit = brandLimitRepository.setLimitByBrands(brands);
-
 
841
 
-
 
842
		LOGGER.info("brandLimit" + brandLimit);
-
 
843
		model.addAttribute("brandLimit", brandLimit);
-
 
844
		model.addAttribute("customRetailers", customRetailers);
-
 
845
		model.addAttribute("retailerBrandsLimitMap", retailerBrandsLimitMap);
-
 
846
		return "brands-limit-mapping";
-
 
847
 
-
 
848
	}
-
 
849
 
702
}
850
}
703
851