Subversion Repositories SmartDukaan

Rev

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

Rev 37630 Rev 37729
Line 158... Line 158...
158
        int assignTo = resolveAiLeadAssignee();
158
        int assignTo = resolveAiLeadAssignee();
159
        lead.setAssignTo(assignTo);
159
        lead.setAssignTo(assignTo);
160
        lead.setAuthId(lead.getAssignTo());
160
        lead.setAuthId(lead.getAssignTo());
161
        lead.setCreatedTimestamp(LocalDateTime.now());
161
        lead.setCreatedTimestamp(LocalDateTime.now());
162
        lead.setUpdatedTimestamp(LocalDateTime.now());
162
        lead.setUpdatedTimestamp(LocalDateTime.now());
163
        leadRepository.persist(lead);
163
        leadCreationService.createUnattended(lead);
164
 
164
 
165
        LOGGER.info("AI lead intake: created lead id={} for mobile {}, assigned to authId={}", lead.getId(), mobile, assignTo);
165
        LOGGER.info("AI lead intake: created lead id={} for mobile {}, assigned to authId={}", lead.getId(), mobile, assignTo);
166
        return aiLeadResponse(HttpStatus.OK, "200", "OK", "SUCCESS", lead.getId());
166
        return aiLeadResponse(HttpStatus.OK, "200", "OK", "SUCCESS", lead.getId());
167
    }
167
    }
168
 
168
 
Line 213... Line 213...
213
 
213
 
214
    @Autowired
214
    @Autowired
215
    private LeadRepository leadRepository;
215
    private LeadRepository leadRepository;
216
 
216
 
217
    @Autowired
217
    @Autowired
-
 
218
    private com.spice.profitmandi.dao.service.lead.LeadCreationService leadCreationService;
-
 
219
 
-
 
220
    @Autowired
218
    private LeadActivityRepository leadActivityRepository;
221
    private LeadActivityRepository leadActivityRepository;
219
 
222
 
220
    @Autowired
223
    @Autowired
221
    private com.spice.profitmandi.dao.repository.dtr.LeadVisitRequestRepository leadVisitRequestRepository;
224
    private com.spice.profitmandi.dao.repository.dtr.LeadVisitRequestRepository leadVisitRequestRepository;
222
 
225
 
Line 1033... Line 1036...
1033
    }
1036
    }
1034
 
1037
 
1035
    @RequestMapping(value = "/createLead", method = RequestMethod.POST)
1038
    @RequestMapping(value = "/createLead", method = RequestMethod.POST)
1036
    public String CreateLead(HttpServletRequest request, @RequestBody CreateRefferalRequest createRefferalRequest, Model model) throws Exception {
1039
    public String CreateLead(HttpServletRequest request, @RequestBody CreateRefferalRequest createRefferalRequest, Model model) throws Exception {
1037
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1040
        LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
1041
        // Duplicate rule lives in LeadCreationService now. The old check here was status-only:
-
 
1042
        // it blocked on ANY non-notInterested lead however old, and ignored whether the assignee
-
 
1043
        // was still an employee -- so an open lead owned by a departed account blocked the number
-
 
1044
        // permanently. See LeadCreationService for the rule and the evidence.
1038
        Lead leadDetails = leadRepository.selectByMobileNumber(createRefferalRequest.getMobile());
1045
        com.spice.profitmandi.dao.service.lead.LeadDuplicateDecision duplicate = leadCreationService.evaluate(createRefferalRequest.getMobile());
1039
        LOGGER.info("Lead Details {}", leadDetails);
1046
        if (duplicate.isBlocked()) {
1040
 
-
 
1041
        if (leadDetails != null && leadDetails.getStatus() != LeadStatus.notInterested) {
1047
            Lead leadDetails = duplicate.getExisting();
1042
            AuthUser authUser1 = authRepository.selectById(leadDetails.getAssignTo());
1048
            AuthUser authUser1 = authRepository.selectById(leadDetails.getAssignTo());
1043
            model.addAttribute("response1", "Lead already exists, created by " + leadDetails.getCreatedBy() +
1049
            model.addAttribute("response1", "Lead already exists, created by " + leadDetails.getCreatedBy() +
1044
                    " on " + FormattingUtils.format(leadDetails.getCreatedTimestamp()) +
1050
                    " on " + FormattingUtils.format(leadDetails.getCreatedTimestamp()) +
1045
                    ", assigned to " + authUser1.getFullName());
1051
                    ", assigned to " + (authUser1 == null ? "unassigned" : authUser1.getFullName()) +
-
 
1052
                    ". An L2 or above can take it over.");
1046
            return "response";
1053
            return "response";
1047
 
-
 
1048
 
-
 
1049
        }
1054
        }
1050
 
1055
 
1051
        LOGGER.info("createRefferalRequest" + createRefferalRequest.getSchelduleTimestamp());
1056
        LOGGER.info("createRefferalRequest" + createRefferalRequest.getSchelduleTimestamp());
1052
        Lead lead = new Lead();
1057
        Lead lead = new Lead();
1053
        lead.setFirstName(createRefferalRequest.getFirstName());
1058
        lead.setFirstName(createRefferalRequest.getFirstName());
Line 1070... Line 1075...
1070
        AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
1075
        AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
1071
        String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
1076
        String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
1072
        lead.setCreatedBy(authUserName);
1077
        lead.setCreatedBy(authUserName);
1073
        lead.setAuthId(authUser.getId());
1078
        lead.setAuthId(authUser.getId());
1074
        LOGGER.info("lead --- {}", lead);
1079
        LOGGER.info("lead --- {}", lead);
-
 
1080
        // Goes through the service so a stale open lead on this number is retired first.
1075
        leadRepository.persist(lead);
1081
        leadCreationService.create(lead, authUser.getId(), false);
1076
        LeadActivity leadActivity = new LeadActivity();
1082
        LeadActivity leadActivity = new LeadActivity();
1077
        leadActivity.setLeadId(lead.getId());
1083
        leadActivity.setLeadId(lead.getId());
1078
        leadActivity.setRemark(createRefferalRequest.getRemark());
1084
        leadActivity.setRemark(createRefferalRequest.getRemark());
1079
        leadActivity.setAuthId(authUser.getId());
1085
        leadActivity.setAuthId(authUser.getId());
1080
 
1086
 
Line 1509... Line 1515...
1509
            lead.setColor("yellow");
1515
            lead.setColor("yellow");
1510
            // change
1516
            // change
1511
            lead.setCreatedBy(createdBy.getFullName());
1517
            lead.setCreatedBy(createdBy.getFullName());
1512
            lead.setAuthId(createdBy.getId());
1518
            lead.setAuthId(createdBy.getId());
1513
 
1519
 
1514
            leadRepository.persist(lead);
1520
            // CSV: skip only the colliding row, import the rest.
-
 
1521
            if (leadCreationService.createUnattended(lead).isBlocked()) { continue; }
1515
 
1522
 
1516
            LeadActivity leadActivity = new LeadActivity();
1523
            LeadActivity leadActivity = new LeadActivity();
1517
            leadActivity.setLeadId(lead.getId());
1524
            leadActivity.setLeadId(lead.getId());
1518
            leadActivity.setRemark("New Lead");
1525
            leadActivity.setRemark("New Lead");
1519
            leadActivity.setSchelduleTimestamp(null);
1526
            leadActivity.setSchelduleTimestamp(null);