Subversion Repositories SmartDukaan

Rev

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

Rev 32940 Rev 32978
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.io.IOException;
-
 
4
import java.time.LocalDate;
-
 
5
import java.time.LocalDateTime;
-
 
6
import java.time.format.DateTimeFormatter;
-
 
7
import java.util.*;
-
 
8
import java.util.Map.Entry;
-
 
9
import java.util.stream.Collectors;
-
 
10
 
-
 
11
import javax.servlet.http.HttpServletRequest;
-
 
12
 
-
 
13
import com.spice.profitmandi.common.enumuration.ActivationType;
-
 
14
import com.spice.profitmandi.common.util.Utils;
-
 
15
import com.spice.profitmandi.common.web.client.RestClient;
-
 
16
import com.spice.profitmandi.dao.entity.cs.*;
-
 
17
import com.spice.profitmandi.dao.entity.dtr.Document;
-
 
18
import com.spice.profitmandi.dao.entity.fofo.*;
-
 
19
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
-
 
20
import com.spice.profitmandi.dao.model.*;
-
 
21
import com.spice.profitmandi.dao.repository.cs.*;
-
 
22
import com.spice.profitmandi.dao.repository.dtr.*;
-
 
23
import com.spice.profitmandi.dao.repository.user.AddressRepository;
-
 
24
import org.apache.commons.csv.CSVRecord;
-
 
25
import org.apache.commons.io.output.ByteArrayOutputStream;
-
 
26
import org.apache.logging.log4j.LogManager;
-
 
27
import org.apache.logging.log4j.Logger;
-
 
28
import org.springframework.beans.factory.annotation.Autowired;
-
 
29
import org.springframework.format.annotation.DateTimeFormat;
-
 
30
import org.springframework.http.HttpHeaders;
-
 
31
import org.springframework.http.HttpStatus;
-
 
32
import org.springframework.http.MediaType;
-
 
33
import org.springframework.http.ResponseEntity;
-
 
34
import org.springframework.mail.javamail.JavaMailSender;
-
 
35
import org.springframework.stereotype.Controller;
-
 
36
import org.springframework.transaction.annotation.Transactional;
-
 
37
import org.springframework.ui.Model;
-
 
38
import org.springframework.web.bind.annotation.*;
-
 
39
import org.springframework.web.multipart.MultipartFile;
-
 
40
 
-
 
41
import com.mongodb.DBObject;
3
import com.mongodb.DBObject;
-
 
4
import com.spice.profitmandi.common.enumuration.ActivationType;
42
import com.spice.profitmandi.common.enumuration.MessageType;
5
import com.spice.profitmandi.common.enumuration.MessageType;
43
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
6
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
44
import com.spice.profitmandi.common.model.CustomRetailer;
7
import com.spice.profitmandi.common.model.CustomRetailer;
45
import com.spice.profitmandi.common.model.ProfitMandiConstants;
8
import com.spice.profitmandi.common.model.ProfitMandiConstants;
46
import com.spice.profitmandi.common.model.SendNotificationModel;
9
import com.spice.profitmandi.common.model.SendNotificationModel;
Line 48... Line 11...
48
import com.spice.profitmandi.common.web.util.ResponseSender;
11
import com.spice.profitmandi.common.web.util.ResponseSender;
49
import com.spice.profitmandi.dao.entity.auth.AuthUser;
12
import com.spice.profitmandi.dao.entity.auth.AuthUser;
50
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionPlan;
13
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionPlan;
51
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
14
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
52
import com.spice.profitmandi.dao.entity.auth.PartnerSecondaryPlan;
15
import com.spice.profitmandi.dao.entity.auth.PartnerSecondaryPlan;
-
 
16
import com.spice.profitmandi.dao.entity.cs.Position;
53
import com.spice.profitmandi.dao.entity.dtr.User;
17
import com.spice.profitmandi.dao.entity.dtr.User;
54
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
18
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
55
import com.spice.profitmandi.dao.entity.user.FranchiseeActivity;
19
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
56
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
20
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
57
import com.spice.profitmandi.dao.entity.user.Lead;
-
 
58
import com.spice.profitmandi.dao.entity.user.LeadActivity;
21
import com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel;
59
import com.spice.profitmandi.dao.entity.user.VisitRequest;
22
import com.spice.profitmandi.dao.entity.user.*;
60
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
23
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
61
import com.spice.profitmandi.dao.enumuration.dtr.CommunicationType;
24
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
62
import com.spice.profitmandi.dao.enumuration.dtr.FranchiseeActivityStatus;
-
 
63
import com.spice.profitmandi.dao.enumuration.dtr.FranchiseeVisitStatus;
-
 
64
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
25
import com.spice.profitmandi.dao.enumuration.dtr.*;
65
import com.spice.profitmandi.dao.enumuration.dtr.StoreTimeline;
26
import com.spice.profitmandi.dao.model.*;
66
import com.spice.profitmandi.dao.enumuration.dtr.VisitStatus;
27
import com.spice.profitmandi.dao.repository.auth.*;
67
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
28
import com.spice.profitmandi.dao.repository.cs.*;
68
import com.spice.profitmandi.dao.repository.auth.AuthUserPartnerMappingRepository;
-
 
69
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionPlanRepository;
-
 
70
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
-
 
71
import com.spice.profitmandi.dao.repository.auth.PartnerSecondaryPlanRepository;
29
import com.spice.profitmandi.dao.repository.dtr.*;
72
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
30
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
73
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
31
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
-
 
32
import com.spice.profitmandi.dao.repository.user.AddressRepository;
74
import com.spice.profitmandi.service.AuthService;
33
import com.spice.profitmandi.service.AuthService;
75
import com.spice.profitmandi.service.NotificationService;
34
import com.spice.profitmandi.service.NotificationService;
76
import com.spice.profitmandi.service.PartnerCollectionService;
35
import com.spice.profitmandi.service.PartnerCollectionService;
77
import com.spice.profitmandi.service.user.RetailerService;
36
import com.spice.profitmandi.service.user.RetailerService;
78
import com.spice.profitmandi.service.user.StoreTimelineTatService;
37
import com.spice.profitmandi.service.user.StoreTimelineTatService;
79
import com.spice.profitmandi.web.req.CreateFranchiseeRequest;
38
import com.spice.profitmandi.web.req.CreateFranchiseeRequest;
80
import com.spice.profitmandi.web.res.Partner;
39
import com.spice.profitmandi.web.res.Partner;
81
 
-
 
82
import io.swagger.annotations.ApiImplicitParam;
40
import io.swagger.annotations.ApiImplicitParam;
83
import io.swagger.annotations.ApiImplicitParams;
41
import io.swagger.annotations.ApiImplicitParams;
-
 
42
import org.apache.commons.csv.CSVRecord;
-
 
43
import org.apache.commons.io.output.ByteArrayOutputStream;
-
 
44
import org.apache.logging.log4j.LogManager;
-
 
45
import org.apache.logging.log4j.Logger;
-
 
46
import org.springframework.beans.factory.annotation.Autowired;
-
 
47
import org.springframework.format.annotation.DateTimeFormat;
-
 
48
import org.springframework.http.HttpHeaders;
-
 
49
import org.springframework.http.HttpStatus;
-
 
50
import org.springframework.http.MediaType;
-
 
51
import org.springframework.http.ResponseEntity;
-
 
52
import org.springframework.mail.javamail.JavaMailSender;
-
 
53
import org.springframework.stereotype.Controller;
-
 
54
import org.springframework.transaction.annotation.Transactional;
-
 
55
import org.springframework.ui.Model;
-
 
56
import org.springframework.web.bind.annotation.*;
-
 
57
import org.springframework.web.multipart.MultipartFile;
-
 
58
 
-
 
59
import javax.servlet.http.HttpServletRequest;
-
 
60
import java.io.IOException;
-
 
61
import java.time.LocalDate;
-
 
62
import java.time.LocalDateTime;
-
 
63
import java.time.format.DateTimeFormatter;
-
 
64
import java.util.*;
-
 
65
import java.util.Map.Entry;
-
 
66
import java.util.stream.Collectors;
84
 
67
 
85
@Controller
68
@Controller
86
@Transactional(rollbackFor = Throwable.class)
69
@Transactional(rollbackFor = Throwable.class)
87
public class LeadController {
70
public class LeadController {
88
    private static final Logger LOGGER = LogManager.getLogger(LeadController.class);
71
    private static final Logger LOGGER = LogManager.getLogger(LeadController.class);
Line 94... Line 77...
94
 
77
 
95
    @Autowired
78
    @Autowired
96
    private LeadRepository leadRepository;
79
    private LeadRepository leadRepository;
97
 
80
 
98
    @Autowired
81
    @Autowired
99
    private ActivityRepository activityRepository;
-
 
100
 
-
 
101
    @Autowired
-
 
102
    private TicketActivityMediaRepository activityMeidaRepository;
-
 
103
 
-
 
104
    @Autowired
-
 
105
    DocumentRepository documentRepository;
82
    DocumentRepository documentRepository;
106
 
83
 
107
    @Autowired
84
    @Autowired
108
    PositionRepository positionRepository;
85
    PositionRepository positionRepository;
109
 
86
 
Line 807... Line 784...
807
                            .filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now()))
784
                            .filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now()))
808
                            .collect(Collectors.counting());
785
                            .collect(Collectors.counting());
809
 
786
 
810
                }
787
                }
811
 
788
 
812
                Map<Integer, PartnerCollectionPlanModel> CollectionMap = partnerCollectionService
789
                Map<Integer, PartnerCollectionPlanModel> collectionMap = partnerCollectionService
813
                        .getCollectionMap(fofoIdList, startDate);
790
                        .getCollectionMap(fofoIdList, startDate);
814
 
791
 
815
                Map<Integer, List<PartnerSecondaryPlanModel>> partnerSecondayPlans = orderRepository
792
                Map<Integer, List<PartnerSecondaryPlanModel>> partnerSecondaryPlans = orderRepository
816
                        .selectPartnerSecondaryGroupByBrand(fofoIdList, startDate.toLocalDate()).stream()
793
                        .selectPartnerSecondaryGroupByBrand(fofoIdList, startDate.toLocalDate()).stream()
817
                        .collect(Collectors.groupingBy(x -> x.getFofoId()));
794
                        .collect(Collectors.groupingBy(x -> x.getFofoId()));
818
 
795
 
819
                LOGGER.info("partnerSecondayPlans {}", partnerSecondayPlans);
796
                LOGGER.info("partnerSecondayPlans {}", partnerSecondaryPlans);
820
                for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailers.entrySet()) {
797
                for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailers.entrySet()) {
821
                    int fofoId = customRetailerEntry.getKey();
798
                    int fofoId = customRetailerEntry.getKey();
822
                    CustomRetailer customRetailer = customRetailerEntry.getValue();
799
                    CustomRetailer customRetailer = customRetailerEntry.getValue();
823
                    float totalSecondaryPlan = 0;
800
                    float totalSecondaryPlan = 0;
824
                    float totalSecondaryAchivement = 0;
801
                    float totalSecondaryAchivement = 0;
Line 831... Line 808...
831
                    if (partnerDailyInvestmentMap.get(fofoId) != null) {
808
                    if (partnerDailyInvestmentMap.get(fofoId) != null) {
832
                        ptam.setWalletAmount(partnerDailyInvestmentMap.get(fofoId).getWalletAmount());
809
                        ptam.setWalletAmount(partnerDailyInvestmentMap.get(fofoId).getWalletAmount());
833
                        ptam.setShortInvestment(partnerDailyInvestmentMap.get(fofoId).getShortInvestment());
810
                        ptam.setShortInvestment(partnerDailyInvestmentMap.get(fofoId).getShortInvestment());
834
                    }
811
                    }
835
 
812
 
836
                    if (CollectionMap.get(fofoId) != null) {
813
                    if (collectionMap.get(fofoId) != null) {
837
                        PartnerCollectionPlanModel collectionPlan = CollectionMap.get(fofoId);
814
                        PartnerCollectionPlanModel collectionPlan = collectionMap.get(fofoId);
838
 
815
 
839
                        ptam.setRemark(collectionPlan.getRemark());
816
                        ptam.setRemark(collectionPlan.getRemark());
840
                        ptam.setMessage(collectionPlan.getMessage());
817
                        ptam.setMessage(collectionPlan.getMessage());
841
                        ptam.setRemarkTimestamp(collectionPlan.getRemarkTimestamp());
818
                        ptam.setRemarkTimestamp(collectionPlan.getRemarkTimestamp());
842
                        ptam.setRank(collectionPlan.getRank());
819
                        ptam.setRank(collectionPlan.getRank());
Line 899... Line 876...
899
 
876
 
900
                    // Secondary
877
                    // Secondary
901
 
878
 
902
                    PartnerSecondaryPlanModel otherPartnerSecondaryPlanModel = null;
879
                    PartnerSecondaryPlanModel otherPartnerSecondaryPlanModel = null;
903
                    Map<String, PartnerSecondaryPlanModel> secondaryModelMap = new HashMap<>();
880
                    Map<String, PartnerSecondaryPlanModel> secondaryModelMap = new HashMap<>();
904
                    if (partnerSecondayPlans.get(fofoId) != null) {
881
                    if (partnerSecondaryPlans.get(fofoId) != null) {
905
                        long otherBrandSecondary = 0;
882
                        long otherBrandSecondary = 0;
906
                        for (PartnerSecondaryPlanModel pspm : partnerSecondayPlans.get(fofoId)) {
883
                        for (PartnerSecondaryPlanModel pspm : partnerSecondaryPlans.get(fofoId)) {
907
                            Integer authId = pspm.getAuthId();
884
                            Integer authId = pspm.getAuthId();
908
                            if (!brands.contains(pspm.getBrand())) {
885
                            if (!brands.contains(pspm.getBrand())) {
909
                                if (pspm.getAchievementPlan() != null) {
886
                                if (pspm.getAchievementPlan() != null) {
910
                                    otherBrandSecondary += pspm.getAchievementPlan();
887
                                    otherBrandSecondary += pspm.getAchievementPlan();
911
                                }
888
                                }
Line 940... Line 917...
940
                            }
917
                            }
941
                        }
918
                        }
942
                        if (otherPartnerSecondaryPlanModel != null) {
919
                        if (otherPartnerSecondaryPlanModel != null) {
943
                            otherPartnerSecondaryPlanModel.setAchievementPlan(otherBrandSecondary);
920
                            otherPartnerSecondaryPlanModel.setAchievementPlan(otherBrandSecondary);
944
                        }
921
                        }
945
                        secondaryModelMap = partnerSecondayPlans.get(fofoId).stream()
922
                        secondaryModelMap = partnerSecondaryPlans.get(fofoId).stream()
946
                                .filter(x -> brands.contains(x.getBrand()))
923
                                .filter(x -> brands.contains(x.getBrand()))
947
                                .collect(Collectors.toMap(x -> x.getBrand(), x -> x));
924
                                .collect(Collectors.toMap(x -> x.getBrand(), x -> x));
948
 
925
 
949
                        if (secondaryModelMap.containsKey("Others")) {
926
                        if (secondaryModelMap.containsKey("Others")) {
950
                            PartnerSecondaryPlanModel psp = secondaryModelMap.get("Others");
927
                            PartnerSecondaryPlanModel psp = secondaryModelMap.get("Others");
Line 1024... Line 1001...
1024
                tm.setTodayCollectionCount((int) todayCollectionCount);
1001
                tm.setTodayCollectionCount((int) todayCollectionCount);
1025
                List<PartnerTargetAchievementModel> filteredPtams;
1002
                List<PartnerTargetAchievementModel> filteredPtams;
1026
 
1003
 
1027
                if (isRBMAndL1) {
1004
                if (isRBMAndL1) {
1028
                    filteredPtams = ptams.stream()
1005
                    filteredPtams = ptams.stream()
1029
                            .filter(ptam -> !(CollectionRemark.RBM_ESCALATION.equals(ptam.getRemark()) || CollectionRemark.SALES_ESCALATION.equals(ptam.getRemark())))
1006
                            .filter(ptam -> !(CollectionRemark.RBM_L2_ESCALATION.equals(ptam.getRemark()) || CollectionRemark.SALES_ESCALATION.equals(ptam.getRemark())))
1030
                            .collect(Collectors.toList());
1007
                            .collect(Collectors.toList());
1031
                } else if (isRBMAndNotL1) {
1008
                } else if (isRBMAndNotL1) {
1032
                    filteredPtams = ptams.stream()
1009
                    filteredPtams = ptams.stream()
1033
                            .filter(ptam -> !(CollectionRemark.SALES_ESCALATION.equals(ptam.getRemark())))
1010
                            .filter(ptam -> !(CollectionRemark.SALES_ESCALATION.equals(ptam.getRemark())))
1034
                            .collect(Collectors.toList());
1011
                            .collect(Collectors.toList());