| 25899 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 32978 |
amit.gupta |
3 |
import com.mongodb.DBObject;
|
| 31677 |
amit.gupta |
4 |
import com.spice.profitmandi.common.enumuration.ActivationType;
|
| 31249 |
tejbeer |
5 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 25899 |
tejbeer |
6 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 25952 |
tejbeer |
7 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 27117 |
tejbeer |
8 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 31249 |
tejbeer |
9 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 30433 |
tejbeer |
10 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 25899 |
tejbeer |
11 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
12 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 30077 |
tejbeer |
13 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionPlan;
|
| 30416 |
tejbeer |
14 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
|
| 30077 |
tejbeer |
15 |
import com.spice.profitmandi.dao.entity.auth.PartnerSecondaryPlan;
|
| 36267 |
ranu |
16 |
import com.spice.profitmandi.dao.entity.cs.Activity;
|
| 32978 |
amit.gupta |
17 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 36267 |
ranu |
18 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
| 25899 |
tejbeer |
19 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 25952 |
tejbeer |
20 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 34322 |
ranu |
21 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
| 32978 |
amit.gupta |
22 |
import com.spice.profitmandi.dao.entity.user.*;
|
| 30416 |
tejbeer |
23 |
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
|
| 32978 |
amit.gupta |
24 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
|
|
25 |
import com.spice.profitmandi.dao.enumuration.dtr.*;
|
|
|
26 |
import com.spice.profitmandi.dao.model.*;
|
|
|
27 |
import com.spice.profitmandi.dao.repository.auth.*;
|
|
|
28 |
import com.spice.profitmandi.dao.repository.cs.*;
|
|
|
29 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 30087 |
tejbeer |
30 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 35075 |
aman |
31 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 36286 |
ranu |
32 |
import com.spice.profitmandi.dao.repository.fofo.RatingReminderRepository;
|
| 34301 |
ranu |
33 |
import com.spice.profitmandi.dao.repository.fofo.RbmRatingRepository;
|
| 34322 |
ranu |
34 |
import com.spice.profitmandi.dao.repository.fofo.SalesRatingRepository;
|
| 35632 |
ranu |
35 |
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
|
| 30077 |
tejbeer |
36 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 32978 |
amit.gupta |
37 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 31249 |
tejbeer |
38 |
import com.spice.profitmandi.service.AuthService;
|
|
|
39 |
import com.spice.profitmandi.service.NotificationService;
|
| 30348 |
tejbeer |
40 |
import com.spice.profitmandi.service.PartnerCollectionService;
|
| 35725 |
ranu |
41 |
import com.spice.profitmandi.service.integrations.kommuno.RecordingService;
|
| 25952 |
tejbeer |
42 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 28935 |
tejbeer |
43 |
import com.spice.profitmandi.service.user.StoreTimelineTatService;
|
| 25952 |
tejbeer |
44 |
import com.spice.profitmandi.web.req.CreateFranchiseeRequest;
|
| 34322 |
ranu |
45 |
import com.spice.profitmandi.web.req.RbmSalesRatingRequest;
|
| 25952 |
tejbeer |
46 |
import com.spice.profitmandi.web.res.Partner;
|
| 25899 |
tejbeer |
47 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
48 |
import io.swagger.annotations.ApiImplicitParams;
|
| 32978 |
amit.gupta |
49 |
import org.apache.commons.csv.CSVRecord;
|
|
|
50 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
|
51 |
import org.apache.logging.log4j.LogManager;
|
|
|
52 |
import org.apache.logging.log4j.Logger;
|
|
|
53 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
54 |
import org.springframework.format.annotation.DateTimeFormat;
|
|
|
55 |
import org.springframework.http.HttpHeaders;
|
|
|
56 |
import org.springframework.http.HttpStatus;
|
|
|
57 |
import org.springframework.http.MediaType;
|
|
|
58 |
import org.springframework.http.ResponseEntity;
|
|
|
59 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
60 |
import org.springframework.stereotype.Controller;
|
|
|
61 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
62 |
import org.springframework.ui.Model;
|
|
|
63 |
import org.springframework.web.bind.annotation.*;
|
|
|
64 |
import org.springframework.web.multipart.MultipartFile;
|
| 25899 |
tejbeer |
65 |
|
| 32978 |
amit.gupta |
66 |
import javax.servlet.http.HttpServletRequest;
|
|
|
67 |
import java.io.IOException;
|
| 36114 |
ranu |
68 |
import java.time.DayOfWeek;
|
| 32978 |
amit.gupta |
69 |
import java.time.LocalDate;
|
|
|
70 |
import java.time.LocalDateTime;
|
| 34301 |
ranu |
71 |
import java.time.YearMonth;
|
| 32978 |
amit.gupta |
72 |
import java.time.format.DateTimeFormatter;
|
| 36114 |
ranu |
73 |
import java.time.temporal.TemporalAdjusters;
|
| 32978 |
amit.gupta |
74 |
import java.util.*;
|
| 35415 |
amit |
75 |
import java.util.HashSet;
|
| 32978 |
amit.gupta |
76 |
import java.util.Map.Entry;
|
|
|
77 |
import java.util.stream.Collectors;
|
|
|
78 |
|
| 25899 |
tejbeer |
79 |
@Controller
|
|
|
80 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
81 |
public class LeadController {
|
| 31677 |
amit.gupta |
82 |
private static final Logger LOGGER = LogManager.getLogger(LeadController.class);
|
|
|
83 |
@Autowired
|
|
|
84 |
private ResponseSender<?> responseSender;
|
| 25899 |
tejbeer |
85 |
|
| 31677 |
amit.gupta |
86 |
@Autowired
|
|
|
87 |
private AuthRepository authRepository;
|
| 25899 |
tejbeer |
88 |
|
| 31677 |
amit.gupta |
89 |
@Autowired
|
|
|
90 |
private LeadRepository leadRepository;
|
| 25899 |
tejbeer |
91 |
|
| 31677 |
amit.gupta |
92 |
@Autowired
|
| 32923 |
ranu |
93 |
DocumentRepository documentRepository;
|
|
|
94 |
|
|
|
95 |
@Autowired
|
|
|
96 |
PositionRepository positionRepository;
|
|
|
97 |
|
|
|
98 |
@Autowired
|
|
|
99 |
private ActivityAttachmentRepository activityAttachmentRepository;
|
|
|
100 |
|
|
|
101 |
@Autowired
|
| 31677 |
amit.gupta |
102 |
private CsService csService;
|
| 25952 |
tejbeer |
103 |
|
| 31677 |
amit.gupta |
104 |
@Autowired
|
|
|
105 |
private UserRepository userRepository;
|
| 25952 |
tejbeer |
106 |
|
| 31677 |
amit.gupta |
107 |
@Autowired
|
| 32923 |
ranu |
108 |
private AddressRepository addressRepository;
|
|
|
109 |
|
|
|
110 |
@Autowired
|
|
|
111 |
|
|
|
112 |
private UserRoleRepository userRoleRepository;
|
|
|
113 |
|
|
|
114 |
@Autowired
|
| 31677 |
amit.gupta |
115 |
private UserAccountRepository userAccountRepository;
|
| 25952 |
tejbeer |
116 |
|
| 31677 |
amit.gupta |
117 |
@Autowired
|
|
|
118 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 25952 |
tejbeer |
119 |
|
| 31677 |
amit.gupta |
120 |
@Autowired
|
|
|
121 |
private RetailerService retailerService;
|
| 25952 |
tejbeer |
122 |
|
| 31677 |
amit.gupta |
123 |
@Autowired
|
|
|
124 |
private LeadActivityRepository leadActivityRepository;
|
| 25899 |
tejbeer |
125 |
|
| 31677 |
amit.gupta |
126 |
@Autowired
|
|
|
127 |
private FranchiseeVisitRepository franchiseeVisitRepository;
|
| 25952 |
tejbeer |
128 |
|
| 31677 |
amit.gupta |
129 |
@Autowired
|
|
|
130 |
private FranchiseeActivityRepository franchiseeActivityRepository;
|
| 25952 |
tejbeer |
131 |
|
| 31677 |
amit.gupta |
132 |
@Autowired
|
|
|
133 |
private PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
| 28935 |
tejbeer |
134 |
|
| 31677 |
amit.gupta |
135 |
@Autowired
|
|
|
136 |
private FofoStoreRepository fofoStoreRepository;
|
| 28935 |
tejbeer |
137 |
|
| 31677 |
amit.gupta |
138 |
@Autowired
|
|
|
139 |
private StoreTimelineTatService storeTimelineTatService;
|
| 28935 |
tejbeer |
140 |
|
| 31677 |
amit.gupta |
141 |
@Autowired
|
|
|
142 |
private PartnerCollectionService partnerCollectionService;
|
| 30348 |
tejbeer |
143 |
|
| 31677 |
amit.gupta |
144 |
@Autowired
|
|
|
145 |
private TicketRepository ticketRepository;
|
| 30416 |
tejbeer |
146 |
|
| 31677 |
amit.gupta |
147 |
@Autowired
|
| 36267 |
ranu |
148 |
private ActivityRepository activityRepository;
|
|
|
149 |
|
|
|
150 |
@Autowired
|
| 31677 |
amit.gupta |
151 |
private TicketCategoryRepository ticketCategoryRepository;
|
| 30416 |
tejbeer |
152 |
|
| 31677 |
amit.gupta |
153 |
@Autowired
|
|
|
154 |
private TicketSubCategoryRepository ticketSubCategoryRepository;
|
| 30416 |
tejbeer |
155 |
|
| 31677 |
amit.gupta |
156 |
@Autowired
|
|
|
157 |
private PartnerCollectionRemarkRepository partnerCollectionRemarkRepository;
|
| 30416 |
tejbeer |
158 |
|
| 31677 |
amit.gupta |
159 |
@Autowired
|
|
|
160 |
private Mongo mongoClient;
|
| 30487 |
tejbeer |
161 |
|
| 31677 |
amit.gupta |
162 |
@Autowired
|
|
|
163 |
private OrderRepository orderRepository;
|
| 30487 |
tejbeer |
164 |
|
| 31677 |
amit.gupta |
165 |
@Autowired
|
|
|
166 |
private PartnerCollectionPlanRepository partnerCollectionPlanRepository;
|
| 30487 |
tejbeer |
167 |
|
| 31677 |
amit.gupta |
168 |
@Autowired
|
|
|
169 |
private PartnerSecondaryPlanRepository partnerSecondaryPlanRepository;
|
| 30487 |
tejbeer |
170 |
|
| 31677 |
amit.gupta |
171 |
@Autowired
|
|
|
172 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 30487 |
tejbeer |
173 |
|
| 31677 |
amit.gupta |
174 |
@Autowired
|
|
|
175 |
private VisitRequestRepository visitRequestRepository;
|
| 31249 |
tejbeer |
176 |
|
| 31677 |
amit.gupta |
177 |
@Autowired
|
|
|
178 |
private AuthService authService;
|
| 31249 |
tejbeer |
179 |
|
| 31677 |
amit.gupta |
180 |
@Autowired
|
|
|
181 |
private NotificationService notificationService;
|
| 31249 |
tejbeer |
182 |
|
| 32923 |
ranu |
183 |
@Autowired
|
| 36400 |
amit |
184 |
JavaMailSender gmailRelaySender;
|
| 32923 |
ranu |
185 |
|
|
|
186 |
@Autowired
|
|
|
187 |
private TicketAssignedRepository ticketAssignedRepository;
|
|
|
188 |
|
| 34124 |
tejus.loha |
189 |
@Autowired
|
|
|
190 |
LeadDetailRepository leadDetailRepository;
|
|
|
191 |
|
| 35075 |
aman |
192 |
@Autowired
|
|
|
193 |
PurchaseRepository purchaseRepository;
|
|
|
194 |
|
| 35632 |
ranu |
195 |
@Autowired
|
|
|
196 |
private LoanRepository loanRepository;
|
|
|
197 |
|
| 35725 |
ranu |
198 |
@Autowired
|
|
|
199 |
private RecordingService recordingService;
|
|
|
200 |
|
| 31677 |
amit.gupta |
201 |
@RequestMapping(value = "/lead", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
202 |
@ApiImplicitParams({
|
|
|
203 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 34118 |
tejus.loha |
204 |
|
|
|
205 |
public ResponseEntity<?> LeadUser(@RequestBody CreateRefferalRequest createRefferalRequest) throws Exception {
|
| 35079 |
vikas |
206 |
LOGGER.info("CreateReferralRequest - " + createRefferalRequest);
|
| 34394 |
tejus.loha |
207 |
if (createRefferalRequest.getOutletName() == null || createRefferalRequest.getPotential() == 0) {
|
| 35079 |
vikas |
208 |
throw new Exception("Outlet should not be empty and potential should be greater > 0");
|
| 34386 |
ranu |
209 |
}
|
| 35288 |
amit |
210 |
Lead lead;
|
|
|
211 |
AuthUser authUser = authRepository.selectByGmailId(createRefferalRequest.getReffereeEmail());
|
|
|
212 |
if (createRefferalRequest.getId() > 0) {
|
|
|
213 |
lead = leadRepository.selectById(createRefferalRequest.getId());
|
|
|
214 |
lead.setAssignTo(authUser.getId());
|
| 31677 |
amit.gupta |
215 |
} else {
|
| 35288 |
amit |
216 |
lead = new Lead();
|
|
|
217 |
lead.setFirstName(createRefferalRequest.getFirstName());
|
|
|
218 |
lead.setLastName(createRefferalRequest.getLastName());
|
|
|
219 |
lead.setLeadMobile(createRefferalRequest.getMobile());
|
|
|
220 |
lead.setState(createRefferalRequest.getState());
|
|
|
221 |
lead.setCity(createRefferalRequest.getCity());
|
|
|
222 |
lead.setAddress(createRefferalRequest.getAddress());
|
|
|
223 |
lead.setCreatedTimestamp(LocalDateTime.now());
|
|
|
224 |
lead.setOutLetName(createRefferalRequest.getOutletName());
|
|
|
225 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
226 |
lead.setStatus(createRefferalRequest.getStatus());
|
|
|
227 |
lead.setSource(createRefferalRequest.getSource());
|
|
|
228 |
lead.setNotinterestedReason(createRefferalRequest.getReason());
|
|
|
229 |
lead.setPotential(createRefferalRequest.getPotential());
|
|
|
230 |
if (createRefferalRequest.getColorCheck() == true) {
|
|
|
231 |
lead.setColor("Green");
|
|
|
232 |
} else {
|
|
|
233 |
lead.setColor("Yellow");
|
|
|
234 |
}
|
|
|
235 |
String authUserName = authUser.getFullName();
|
|
|
236 |
lead.setAuthId(authUser.getId());
|
|
|
237 |
lead.setAssignTo(authUser.getId());
|
| 35079 |
vikas |
238 |
lead.setCreatedBy(authUserName);
|
|
|
239 |
leadRepository.persist(lead);
|
| 35288 |
amit |
240 |
|
| 35079 |
vikas |
241 |
}
|
| 34118 |
tejus.loha |
242 |
|
| 31677 |
amit.gupta |
243 |
LeadActivity leadActivity = new LeadActivity();
|
|
|
244 |
leadActivity.setLeadId(lead.getId());
|
| 35288 |
amit |
245 |
leadActivity.setRemark((createRefferalRequest.getId() > 0 ? "Self Assigned." : "") + createRefferalRequest.getRemark());
|
| 31677 |
amit.gupta |
246 |
leadActivity.setAuthId(authUser.getId());
|
| 31249 |
tejbeer |
247 |
|
| 31677 |
amit.gupta |
248 |
if (createRefferalRequest.getStatus().equals(LeadStatus.followUp)) {
|
|
|
249 |
leadActivity.setSchelduleTimestamp(createRefferalRequest.getSchelduleTimestamp());
|
|
|
250 |
leadActivity.setCommunicationType(createRefferalRequest.getCommunicationType());
|
| 31249 |
tejbeer |
251 |
|
| 31677 |
amit.gupta |
252 |
if (leadActivity.getCommunicationType().equals(CommunicationType.VISIT)) {
|
| 31249 |
tejbeer |
253 |
|
| 31677 |
amit.gupta |
254 |
visitRequestRepository.createVisitRequest(lead.getId(), "lead", lead.getAssignTo(),
|
|
|
255 |
createRefferalRequest.getSchelduleTimestamp());
|
|
|
256 |
}
|
|
|
257 |
//
|
|
|
258 |
leadActivity.setClosureTimestamp(createRefferalRequest.getClosureTimestamp());
|
|
|
259 |
lead.setClosureTimestamp(createRefferalRequest.getClosureTimestamp());
|
|
|
260 |
} else {
|
|
|
261 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
262 |
leadActivity.setClosureTimestamp(null);
|
|
|
263 |
lead.setClosureTimestamp(null);
|
|
|
264 |
}
|
|
|
265 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
266 |
leadActivityRepository.persist(leadActivity);
|
| 25899 |
tejbeer |
267 |
|
| 31677 |
amit.gupta |
268 |
return responseSender.ok(true);
|
|
|
269 |
}
|
| 25899 |
tejbeer |
270 |
|
| 31677 |
amit.gupta |
271 |
@RequestMapping(value = "/lead-description", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
272 |
@ApiImplicitParams({
|
|
|
273 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 35288 |
amit |
274 |
public ResponseEntity<?> leadDescription(HttpServletRequest request, @RequestParam(name = "gmailId") String
|
|
|
275 |
gmailId,
|
| 31677 |
amit.gupta |
276 |
@RequestParam(name = "status") LeadStatus status) throws ProfitMandiBusinessException {
|
|
|
277 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
|
|
278 |
List<Lead> leads = null;
|
|
|
279 |
LOGGER.info("emails" + status);
|
| 31249 |
tejbeer |
280 |
|
| 35469 |
vikas |
281 |
List<VisitRequest> visitRequests = visitRequestRepository.selectByAuthIdAndDate(authUser.getId(),
|
|
|
282 |
LocalDate.now());
|
|
|
283 |
Map<Integer, List<VisitRequest>> visitRequestMap = null;
|
|
|
284 |
if (!visitRequests.isEmpty()) {
|
|
|
285 |
visitRequestMap = visitRequests.stream().collect(Collectors.groupingBy(x -> x.getVisitId()));
|
|
|
286 |
}
|
| 31677 |
amit.gupta |
287 |
if (status.equals(LeadStatus.followUp)) {
|
| 35469 |
vikas |
288 |
|
| 31677 |
amit.gupta |
289 |
leads = leadRepository.selectLeadsScheduledBetweenDate(Arrays.asList(authUser.getId()), null, null);
|
| 31249 |
tejbeer |
290 |
|
| 35469 |
vikas |
291 |
if (visitRequestMap != null) {
|
| 31677 |
amit.gupta |
292 |
for (Lead lead : leads) {
|
|
|
293 |
List<VisitRequest> visitRequest = visitRequestMap.get(lead.getId());
|
| 35469 |
vikas |
294 |
|
| 31677 |
amit.gupta |
295 |
if (visitRequest != null) {
|
|
|
296 |
if (visitRequest.size() > 1) {
|
| 35469 |
vikas |
297 |
|
|
|
298 |
Comparator<VisitRequest> visitComparato = Comparator
|
|
|
299 |
.comparing(VisitRequest::getCreatedTimestamp);
|
|
|
300 |
|
|
|
301 |
VisitRequest youngestVisit = visitRequest.stream().max(visitComparato).get();
|
| 31677 |
amit.gupta |
302 |
lead.setVisitStatus(youngestVisit.getStatus());
|
| 35469 |
vikas |
303 |
|
| 31677 |
amit.gupta |
304 |
} else {
|
|
|
305 |
lead.setVisitStatus(visitRequest.get(0).getStatus());
|
| 35469 |
vikas |
306 |
|
| 31677 |
amit.gupta |
307 |
}
|
|
|
308 |
}
|
| 35469 |
vikas |
309 |
|
| 31677 |
amit.gupta |
310 |
}
|
|
|
311 |
}
|
| 31249 |
tejbeer |
312 |
|
| 31677 |
amit.gupta |
313 |
leads = leads.stream()
|
| 35079 |
vikas |
314 |
.sorted(Comparator.comparing(Lead::getScheduledTimestamp, Comparator.nullsFirst(Comparator.reverseOrder())))
|
|
|
315 |
.collect(Collectors.toList());
|
| 35469 |
vikas |
316 |
/*
|
|
|
317 |
* Collections.sort(leads, (o1, o2) -> { if (o1.getScheduledTimestamp() != null
|
|
|
318 |
* && o2.getScheduledTimestamp() != null) { return
|
|
|
319 |
* o1.getScheduledTimestamp().isBefore(o2.getScheduledTimestamp()) ? -1 : 1; }
|
|
|
320 |
* else if (o1.getScheduledTimestamp() != null) { return 1; } else { return -1;
|
|
|
321 |
* } });
|
|
|
322 |
*/
|
|
|
323 |
|
| 31677 |
amit.gupta |
324 |
} else {
|
|
|
325 |
leads = leadRepository.selectByAssignAuthIdAndStatus(authUser.getId(), status);
|
| 35469 |
vikas |
326 |
|
| 31677 |
amit.gupta |
327 |
}
|
| 25979 |
tejbeer |
328 |
|
| 31677 |
amit.gupta |
329 |
return responseSender.ok(leads);
|
| 35469 |
vikas |
330 |
|
| 31677 |
amit.gupta |
331 |
}
|
| 25899 |
tejbeer |
332 |
|
| 31677 |
amit.gupta |
333 |
@RequestMapping(value = "/getlead", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35288 |
amit |
334 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
335 |
public ResponseEntity<?> getLead(HttpServletRequest request, @RequestParam(name = "id") int id) throws
|
|
|
336 |
ProfitMandiBusinessException {
|
| 25899 |
tejbeer |
337 |
|
| 31677 |
amit.gupta |
338 |
List<LeadActivity> leadActivities = leadActivityRepository.selectBYLeadId(id);
|
|
|
339 |
Lead lead = leadRepository.selectById(id);
|
|
|
340 |
lead.setLeadActivities(leadActivities);
|
|
|
341 |
return responseSender.ok(lead);
|
| 25899 |
tejbeer |
342 |
|
| 31677 |
amit.gupta |
343 |
}
|
| 25899 |
tejbeer |
344 |
|
| 35079 |
vikas |
345 |
@RequestMapping(value = "/check-existing-lead", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35288 |
amit |
346 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
347 |
public ResponseEntity<?> getLeadByMobile(HttpServletRequest request, @RequestParam(name = "mobile") String
|
|
|
348 |
mobile) throws ProfitMandiBusinessException {
|
| 35079 |
vikas |
349 |
int userId = (int) request.getAttribute("userId");
|
|
|
350 |
LOGGER.info("userId: " + userId);
|
|
|
351 |
Lead lead = leadRepository.selectByMobileNumber(mobile);
|
|
|
352 |
return responseSender.ok(lead);
|
|
|
353 |
|
|
|
354 |
}
|
|
|
355 |
|
| 31677 |
amit.gupta |
356 |
@RequestMapping(value = "/leadUpdate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35288 |
amit |
357 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 31677 |
amit.gupta |
358 |
public ResponseEntity<?> leadUpdate(HttpServletRequest request, @RequestParam(name = "id") int id,
|
| 35288 |
amit |
359 |
@RequestParam(name = "status") LeadStatus status, @RequestParam(name = "colorCheck") Boolean colorCheck,
|
|
|
360 |
@RequestParam(name = "remark") String remark, @RequestParam(name = "reason") String reason,
|
|
|
361 |
@RequestParam(name = "schelduleTimestamp") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime schelduleTimestamp,
|
|
|
362 |
@RequestParam(name = "closureTimestamp") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime closureTimestamp,
|
|
|
363 |
@RequestParam(name = "communicationType") CommunicationType communicationType) throws
|
|
|
364 |
ProfitMandiBusinessException {
|
| 25899 |
tejbeer |
365 |
|
| 31677 |
amit.gupta |
366 |
Lead lead = leadRepository.selectById(id);
|
| 25899 |
tejbeer |
367 |
|
| 31677 |
amit.gupta |
368 |
LeadActivity leadActivity = new LeadActivity();
|
|
|
369 |
lead.setStatus(status);
|
|
|
370 |
lead.setNotinterestedReason(reason);
|
|
|
371 |
leadActivity.setRemark(remark);
|
|
|
372 |
leadActivity.setLeadId(id);
|
| 34394 |
tejus.loha |
373 |
leadActivity.setOutletName(lead.getOutLetName());
|
|
|
374 |
leadActivity.setPotential(lead.getPotential());
|
| 31677 |
amit.gupta |
375 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
376 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
377 |
leadActivity.setClosureTimestamp(null);
|
|
|
378 |
leadActivity.setAuthId(lead.getAssignTo());
|
|
|
379 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
380 |
if (colorCheck == true) {
|
|
|
381 |
lead.setColor("Green");
|
|
|
382 |
} else {
|
|
|
383 |
lead.setColor("Yellow");
|
|
|
384 |
}
|
|
|
385 |
if (status == LeadStatus.followUp) {
|
| 25899 |
tejbeer |
386 |
|
| 31677 |
amit.gupta |
387 |
if (schelduleTimestamp != null) {
|
| 31249 |
tejbeer |
388 |
|
| 31677 |
amit.gupta |
389 |
leadActivity.setCommunicationType(communicationType);
|
| 31249 |
tejbeer |
390 |
|
| 31677 |
amit.gupta |
391 |
if (leadActivity.getCommunicationType().equals(CommunicationType.VISIT)) {
|
| 31249 |
tejbeer |
392 |
|
| 35079 |
vikas |
393 |
visitRequestRepository.createVisitRequest(lead.getId(), "lead", lead.getAssignTo(), schelduleTimestamp);
|
| 31677 |
amit.gupta |
394 |
}
|
| 31249 |
tejbeer |
395 |
|
| 31677 |
amit.gupta |
396 |
}
|
|
|
397 |
leadActivity.setSchelduleTimestamp(schelduleTimestamp);
|
|
|
398 |
leadActivity.setClosureTimestamp(closureTimestamp);
|
|
|
399 |
lead.setClosureTimestamp(closureTimestamp);
|
| 26250 |
tejbeer |
400 |
|
| 31677 |
amit.gupta |
401 |
} else {
|
| 26250 |
tejbeer |
402 |
|
| 31677 |
amit.gupta |
403 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
404 |
leadActivity.setClosureTimestamp(null);
|
|
|
405 |
lead.setClosureTimestamp(null);
|
| 26244 |
tejbeer |
406 |
|
| 31677 |
amit.gupta |
407 |
}
|
|
|
408 |
leadActivityRepository.persist(leadActivity);
|
|
|
409 |
return responseSender.ok(true);
|
| 25899 |
tejbeer |
410 |
|
| 31677 |
amit.gupta |
411 |
}
|
| 25952 |
tejbeer |
412 |
|
| 31677 |
amit.gupta |
413 |
@RequestMapping(value = ProfitMandiConstants.URL_NEW_LEAD, method = RequestMethod.POST)
|
| 35288 |
amit |
414 |
public ResponseEntity<?> newLead(HttpServletRequest request, @RequestBody CreateRefferalRequest
|
|
|
415 |
createRefferalRequest) throws ProfitMandiBusinessException {
|
| 31677 |
amit.gupta |
416 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
417 |
Lead lead = new Lead();
|
|
|
418 |
lead.setAddress(createRefferalRequest.getCity());
|
|
|
419 |
Long.parseLong(createRefferalRequest.getMobile());
|
|
|
420 |
if (createRefferalRequest.getMobile().length() != 10) {
|
| 35079 |
vikas |
421 |
throw new ProfitMandiBusinessException("Mobile Number", createRefferalRequest.getMobile(), "Number should be of 10 digits");
|
| 31677 |
amit.gupta |
422 |
}
|
|
|
423 |
lead.setLeadMobile(createRefferalRequest.getMobile());
|
|
|
424 |
lead.setCity(createRefferalRequest.getCity());
|
|
|
425 |
lead.setState(createRefferalRequest.getState());
|
|
|
426 |
lead.setLastName(createRefferalRequest.getLastName());
|
|
|
427 |
if (lead.getState().equals("Uttar Pradesh")) {
|
|
|
428 |
lead.setAssignTo(53);
|
|
|
429 |
} else if (lead.getState().equals("Haryana")) {
|
|
|
430 |
lead.setAssignTo(53);
|
|
|
431 |
} else if (lead.getState().equals("Delhi")) {
|
|
|
432 |
lead.setAssignTo(53);
|
|
|
433 |
} else {
|
|
|
434 |
// Assign to sm
|
|
|
435 |
lead.setAssignTo(53);
|
|
|
436 |
// Assign to neha
|
|
|
437 |
// lead.setAssignTo(1);
|
|
|
438 |
}
|
|
|
439 |
lead.setAuthId(lead.getAssignTo());
|
|
|
440 |
lead.setCreatedBy("daily-sync");
|
|
|
441 |
lead.setSource("SD-WEB");
|
|
|
442 |
lead.setFirstName(createRefferalRequest.getFirstName());
|
|
|
443 |
lead.setStatus(LeadStatus.followUp);
|
|
|
444 |
lead.setColor("yellow");
|
|
|
445 |
lead.setCreatedTimestamp(LocalDateTime.now());
|
|
|
446 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
447 |
leadRepository.persist(lead);
|
| 27117 |
tejbeer |
448 |
|
| 31677 |
amit.gupta |
449 |
return responseSender.ok(true);
|
| 27117 |
tejbeer |
450 |
|
| 31677 |
amit.gupta |
451 |
}
|
| 27117 |
tejbeer |
452 |
|
| 31677 |
amit.gupta |
453 |
@RequestMapping(value = "/getPartnersList", method = RequestMethod.GET)
|
| 35079 |
vikas |
454 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 31677 |
amit.gupta |
455 |
public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId)
|
|
|
456 |
throws ProfitMandiBusinessException {
|
| 25952 |
tejbeer |
457 |
|
| 31677 |
amit.gupta |
458 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
| 35630 |
aman |
459 |
if (authUser == null) {
|
|
|
460 |
LOGGER.warn("No auth user found for gmailId: {}", gmailId);
|
|
|
461 |
return responseSender.badRequest("No user found for the provided email");
|
|
|
462 |
}
|
| 25952 |
tejbeer |
463 |
|
| 31677 |
amit.gupta |
464 |
Map<String, Set<String>> storeGuyMap = csService.getAuthUserPartnerEmailMapping();
|
| 25952 |
tejbeer |
465 |
|
| 31677 |
amit.gupta |
466 |
Set<String> emails = storeGuyMap.get(authUser.getEmailId());
|
| 35630 |
aman |
467 |
LOGGER.info("emails: {}", emails);
|
|
|
468 |
if (emails == null || emails.isEmpty()) {
|
|
|
469 |
LOGGER.info("No partner emails found for user: {}", gmailId);
|
|
|
470 |
return responseSender.ok(new ArrayList<>());
|
|
|
471 |
}
|
| 31677 |
amit.gupta |
472 |
List<User> users = userRepository.selectAllByEmailIds(new ArrayList<>(emails));
|
|
|
473 |
List<Partner> partners = new ArrayList<>();
|
|
|
474 |
for (User user : users) {
|
| 35630 |
aman |
475 |
try {
|
|
|
476 |
UserAccount uc = userAccountRepository.selectSaholicByUserId(user.getId());
|
|
|
477 |
if (uc == null) {
|
|
|
478 |
LOGGER.warn("No user account found for userId: {}", user.getId());
|
|
|
479 |
continue;
|
|
|
480 |
}
|
|
|
481 |
com.spice.profitmandi.dao.entity.user.User userInfo = userUserRepository.selectById(uc.getAccountKey());
|
|
|
482 |
if (userInfo == null) {
|
|
|
483 |
LOGGER.warn("No user info found for accountKey: {}", uc.getAccountKey());
|
|
|
484 |
continue;
|
|
|
485 |
}
|
|
|
486 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(userInfo.getId());
|
|
|
487 |
if (customRetailer == null) {
|
|
|
488 |
LOGGER.warn("No custom retailer found for userInfoId: {}", userInfo.getId());
|
|
|
489 |
continue;
|
|
|
490 |
}
|
| 25952 |
tejbeer |
491 |
|
| 35630 |
aman |
492 |
Partner partner = new Partner();
|
|
|
493 |
partner.setBusinessName(customRetailer.getBusinessName());
|
|
|
494 |
partner.setPartnerId(customRetailer.getPartnerId());
|
|
|
495 |
partner.setCartId(customRetailer.getCartId());
|
|
|
496 |
partner.setEmail(customRetailer.getEmail());
|
|
|
497 |
partner.setGstNumber(customRetailer.getGstNumber());
|
|
|
498 |
partner.setDisplayName(customRetailer.getDisplayName());
|
|
|
499 |
partner.setCity(customRetailer.getAddress() != null ? customRetailer.getAddress().getCity() : null);
|
|
|
500 |
partner.setUserId(user.getId());
|
|
|
501 |
partners.add(partner);
|
|
|
502 |
} catch (Exception e) {
|
|
|
503 |
LOGGER.error("Error processing partner for userId: {}", user.getId(), e);
|
|
|
504 |
}
|
| 31677 |
amit.gupta |
505 |
}
|
| 35630 |
aman |
506 |
LOGGER.info("partners: {}", partners);
|
| 31677 |
amit.gupta |
507 |
return responseSender.ok(partners);
|
|
|
508 |
}
|
| 25952 |
tejbeer |
509 |
|
| 31677 |
amit.gupta |
510 |
@RequestMapping(value = "/franchise-first-visit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35079 |
vikas |
511 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 35288 |
amit |
512 |
public ResponseEntity<?> FranchiseFirstVisit(HttpServletRequest request, @RequestBody CreateFranchiseeRequest
|
|
|
513 |
createFranchiseeRequest) throws Exception {
|
| 25952 |
tejbeer |
514 |
|
| 31677 |
amit.gupta |
515 |
FranchiseeVisit franchiseeVisit = new FranchiseeVisit();
|
|
|
516 |
franchiseeVisit.setFofoId(createFranchiseeRequest.getFofoId());
|
|
|
517 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(createFranchiseeRequest.getFofoId());
|
| 25952 |
tejbeer |
518 |
|
| 31677 |
amit.gupta |
519 |
franchiseeVisit.setPartnerName(customRetailer.getBusinessName());
|
|
|
520 |
franchiseeVisit.setAgenda(createFranchiseeRequest.getAgenda());
|
|
|
521 |
franchiseeVisit.setCreatedTimestamp(LocalDateTime.now());
|
|
|
522 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
523 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.OPEN);
|
|
|
524 |
franchiseeVisit.setScheduleTimestamp(createFranchiseeRequest.getFirstSchelduleTimestamp());
|
|
|
525 |
// change
|
|
|
526 |
AuthUser authUser = authRepository.selectByGmailId(createFranchiseeRequest.getCreatedBy());
|
| 25952 |
tejbeer |
527 |
|
| 31677 |
amit.gupta |
528 |
String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
529 |
franchiseeVisit.setCreatedBy(authUserName);
|
|
|
530 |
franchiseeVisit.setAuthId(authUser.getId());
|
| 25952 |
tejbeer |
531 |
|
| 31677 |
amit.gupta |
532 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| 25952 |
tejbeer |
533 |
|
| 31677 |
amit.gupta |
534 |
FranchiseeActivity franchiseeActivity = new FranchiseeActivity();
|
|
|
535 |
franchiseeActivity.setAction(FranchiseeActivityStatus.FOLLOWUP);
|
|
|
536 |
franchiseeActivity.setFranchiseeVisitd(franchiseeVisit.getId());
|
|
|
537 |
franchiseeActivity.setResolution(createFranchiseeRequest.getResolution());
|
|
|
538 |
franchiseeActivity.setSchelduleTimestamp(createFranchiseeRequest.getFirstSchelduleTimestamp());
|
| 31249 |
tejbeer |
539 |
|
| 31677 |
amit.gupta |
540 |
franchiseeActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
541 |
franchiseeActivityRepository.persist(franchiseeActivity);
|
| 31249 |
tejbeer |
542 |
|
| 31677 |
amit.gupta |
543 |
franchiseeVisit.setFranchiseActivityId(franchiseeActivity.getId());
|
| 31249 |
tejbeer |
544 |
|
| 35079 |
vikas |
545 |
visitRequestRepository.createVisitRequest(franchiseeVisit.getId(), "franchiseeVisit", authUser.getId(), createFranchiseeRequest.getFirstSchelduleTimestamp());
|
| 31249 |
tejbeer |
546 |
|
| 31677 |
amit.gupta |
547 |
return responseSender.ok(true);
|
|
|
548 |
}
|
| 25952 |
tejbeer |
549 |
|
| 31677 |
amit.gupta |
550 |
@RequestMapping(value = "/franchise-visit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35079 |
vikas |
551 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 31677 |
amit.gupta |
552 |
public ResponseEntity<?> FranchiseVisit(HttpServletRequest request,
|
|
|
553 |
@RequestBody CreateFranchiseeRequest createFranchiseeRequest) throws Exception {
|
| 25952 |
tejbeer |
554 |
|
| 34394 |
tejus.loha |
555 |
int rbmL1 = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, createFranchiseeRequest.getFofoId());
|
| 34276 |
ranu |
556 |
|
| 31677 |
amit.gupta |
557 |
FranchiseeVisit franchiseeVisit = franchiseeVisitRepository.selectById(createFranchiseeRequest.getId());
|
|
|
558 |
franchiseeVisit.setFofoId(createFranchiseeRequest.getFofoId());
|
|
|
559 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(createFranchiseeRequest.getFofoId());
|
| 34394 |
tejus.loha |
560 |
LOGGER.info("rbmL1 {}", rbmL1);
|
| 31677 |
amit.gupta |
561 |
franchiseeVisit.setPartnerName(customRetailer.getBusinessName());
|
|
|
562 |
franchiseeVisit.setAgenda(createFranchiseeRequest.getAgenda());
|
|
|
563 |
franchiseeVisit.setPartnerRemark(createFranchiseeRequest.getPartnerRemark());
|
|
|
564 |
franchiseeVisit.setOutsideVisibity(createFranchiseeRequest.getOutsideVisibity());
|
|
|
565 |
franchiseeVisit.setInstoreVisibility(createFranchiseeRequest.getInstoreVisibility());
|
|
|
566 |
franchiseeVisit.setOutsideStock(createFranchiseeRequest.getOutsideStock());
|
|
|
567 |
franchiseeVisit.setSystemKnowledge(createFranchiseeRequest.getSystemKnowledge());
|
|
|
568 |
franchiseeVisit.setWorkingDevice(createFranchiseeRequest.getWorkingDevice());
|
|
|
569 |
franchiseeVisit.setWorkingPrinter(createFranchiseeRequest.getWorkingPrinter());
|
|
|
570 |
franchiseeVisit.setCarryBags(createFranchiseeRequest.getCarryBags());
|
|
|
571 |
franchiseeVisit.setSmartdukaanTshirt(createFranchiseeRequest.getSmartdukaanTshirt());
|
|
|
572 |
franchiseeVisit.setLatestDummies(createFranchiseeRequest.getLatestDummies());
|
|
|
573 |
franchiseeVisit.setInvestment(createFranchiseeRequest.getInvestment());
|
|
|
574 |
franchiseeVisit.setMtd(createFranchiseeRequest.getMtd());
|
|
|
575 |
franchiseeVisit.setHygiene(createFranchiseeRequest.getHygiene());
|
|
|
576 |
franchiseeVisit.setCreatedTimestamp(LocalDateTime.now());
|
|
|
577 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
578 |
franchiseeVisit.setInformedAboutOnline(createFranchiseeRequest.getOnline());
|
|
|
579 |
franchiseeVisit.setPendingBilling(createFranchiseeRequest.getPendingBilling());
|
| 34276 |
ranu |
580 |
franchiseeVisit.setRbmId(rbmL1);
|
|
|
581 |
franchiseeVisit.setRbmRating(createFranchiseeRequest.getRbmRating());
|
| 31677 |
amit.gupta |
582 |
if (createFranchiseeRequest.getAction().equals(FranchiseeActivityStatus.FOLLOWUP)) {
|
|
|
583 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.OPEN);
|
|
|
584 |
} else {
|
|
|
585 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.CLOSE);
|
|
|
586 |
}
|
| 25952 |
tejbeer |
587 |
|
| 31677 |
amit.gupta |
588 |
// AuthUser authUser =
|
|
|
589 |
// authRepository.selectByGmailId(createFranchiseeRequest.getCreatedBy());
|
|
|
590 |
// change
|
|
|
591 |
AuthUser authUser = authRepository.selectByGmailId(createFranchiseeRequest.getCreatedBy());
|
| 25952 |
tejbeer |
592 |
|
| 31677 |
amit.gupta |
593 |
String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
594 |
franchiseeVisit.setCreatedBy(authUserName);
|
|
|
595 |
franchiseeVisit.setAuthId(authUser.getId());
|
| 25952 |
tejbeer |
596 |
|
| 31677 |
amit.gupta |
597 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| 25952 |
tejbeer |
598 |
|
| 31677 |
amit.gupta |
599 |
FranchiseeActivity franchiseeActivity = new FranchiseeActivity();
|
|
|
600 |
franchiseeActivity.setAction(createFranchiseeRequest.getAction());
|
|
|
601 |
franchiseeActivity.setFranchiseeVisitd(franchiseeVisit.getId());
|
|
|
602 |
franchiseeActivity.setResolution(createFranchiseeRequest.getResolution());
|
|
|
603 |
if (createFranchiseeRequest.getAction().equals(FranchiseeActivityStatus.FOLLOWUP)) {
|
|
|
604 |
franchiseeActivity.setSchelduleTimestamp(createFranchiseeRequest.getSchelduleTimestamp());
|
| 31249 |
tejbeer |
605 |
|
| 31677 |
amit.gupta |
606 |
visitRequestRepository.createVisitRequest(franchiseeVisit.getId(), "franchiseeVisit",
|
|
|
607 |
franchiseeVisit.getAuthId(), createFranchiseeRequest.getSchelduleTimestamp());
|
|
|
608 |
} else {
|
|
|
609 |
franchiseeActivity.setSchelduleTimestamp(null);
|
|
|
610 |
}
|
|
|
611 |
franchiseeActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
612 |
franchiseeActivityRepository.persist(franchiseeActivity);
|
| 25952 |
tejbeer |
613 |
|
| 31677 |
amit.gupta |
614 |
franchiseeVisit.setFranchiseActivityId(franchiseeActivity.getId());
|
| 34276 |
ranu |
615 |
|
| 34394 |
tejus.loha |
616 |
if (!createFranchiseeRequest.getOutsideVisibityReason().isEmpty()) {
|
| 34288 |
ranu |
617 |
csService.createTicket(createFranchiseeRequest.getFofoId(), ProfitMandiConstants.TICKET_CATEGORY_DESIGN, ProfitMandiConstants.TICKET_CATEGORY_DESIGNING_BRANDING_EXTERNAL_VISIBILITY, createFranchiseeRequest.getOutsideVisibityReason(), authUser.getId());
|
| 34276 |
ranu |
618 |
}
|
|
|
619 |
|
| 34394 |
tejus.loha |
620 |
if (!createFranchiseeRequest.getInstoreVisibilityReason().isEmpty()) {
|
| 34288 |
ranu |
621 |
csService.createTicket(createFranchiseeRequest.getFofoId(), ProfitMandiConstants.TICKET_CATEGORY_DESIGN, ProfitMandiConstants.TICKET_CATEGORY_DESIGNING_BRANDING_INTERNAL_VISIBILITY, createFranchiseeRequest.getInstoreVisibilityReason(), authUser.getId());
|
| 34276 |
ranu |
622 |
}
|
|
|
623 |
|
| 34394 |
tejus.loha |
624 |
if (!createFranchiseeRequest.getOutsideStockReason().isEmpty()) {
|
| 34288 |
ranu |
625 |
csService.createTicket(createFranchiseeRequest.getFofoId(), ProfitMandiConstants.TICKET_CATEGORY_SALES, ProfitMandiConstants.TICKET_CATEGORY_SALES_OUTSIDE_STOCK, createFranchiseeRequest.getOutsideStockReason(), authUser.getId());
|
| 34276 |
ranu |
626 |
}
|
|
|
627 |
|
| 34394 |
tejus.loha |
628 |
if (!createFranchiseeRequest.getSystemKnowledgeReason().isEmpty()) {
|
| 34288 |
ranu |
629 |
csService.createTicket(createFranchiseeRequest.getFofoId(), ProfitMandiConstants.TICKET_CATEGORY_TRAINING, ProfitMandiConstants.TICKET_CATEGORY_TRAINING_NEED, createFranchiseeRequest.getSystemKnowledgeReason(), authUser.getId());
|
| 34276 |
ranu |
630 |
}
|
|
|
631 |
|
| 34394 |
tejus.loha |
632 |
if (!createFranchiseeRequest.getLatestDummiesReason().isEmpty()) {
|
| 34288 |
ranu |
633 |
csService.createTicket(createFranchiseeRequest.getFofoId(), ProfitMandiConstants.TICKET_CATEGORY_MARKETING, ProfitMandiConstants.TICKET_CATEGORY_MARKETING_DUMMIES, createFranchiseeRequest.getLatestDummiesReason(), authUser.getId());
|
| 34276 |
ranu |
634 |
}
|
|
|
635 |
|
| 34394 |
tejus.loha |
636 |
if (!createFranchiseeRequest.getInvestmentReason().isEmpty()) {
|
| 34288 |
ranu |
637 |
csService.createTicket(createFranchiseeRequest.getFofoId(), ProfitMandiConstants.TICKET_CATEGORY_SALES, ProfitMandiConstants.TICKET_CATEGORY_SALES_LOW_INVESTMENT, createFranchiseeRequest.getInvestmentReason(), authUser.getId());
|
| 34276 |
ranu |
638 |
}
|
|
|
639 |
|
| 34394 |
tejus.loha |
640 |
if (!createFranchiseeRequest.getHygieneReason().isEmpty()) {
|
| 34288 |
ranu |
641 |
csService.createTicket(createFranchiseeRequest.getFofoId(), ProfitMandiConstants.TICKET_CATEGORY_SALES, ProfitMandiConstants.TICKET_CATEGORY_SALES_LOW_DATA_ACCURACY, createFranchiseeRequest.getHygieneReason(), authUser.getId());
|
|
|
642 |
}
|
| 34276 |
ranu |
643 |
|
| 31677 |
amit.gupta |
644 |
return responseSender.ok(true);
|
| 34276 |
ranu |
645 |
|
| 31677 |
amit.gupta |
646 |
}
|
| 25952 |
tejbeer |
647 |
|
| 31677 |
amit.gupta |
648 |
@RequestMapping(value = "/getFranchiseVisit", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35079 |
vikas |
649 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 31677 |
amit.gupta |
650 |
public ResponseEntity<?> getFranchiseVisit(HttpServletRequest request,
|
| 35288 |
amit |
651 |
@RequestParam(name = "gmailId") String gmailId, @RequestParam(name = "status") FranchiseeVisitStatus
|
|
|
652 |
status,
|
| 31677 |
amit.gupta |
653 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
654 |
@RequestParam(name = "limit", defaultValue = "10") int limit) throws ProfitMandiBusinessException {
|
|
|
655 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
| 35079 |
vikas |
656 |
List<VisitRequest> visitRequests = visitRequestRepository.selectByAuthIdAndDate(authUser.getId(), LocalDate.now());
|
| 31677 |
amit.gupta |
657 |
Map<Integer, List<VisitRequest>> visitRequestMap = null;
|
|
|
658 |
if (!visitRequests.isEmpty()) {
|
|
|
659 |
visitRequestMap = visitRequests.stream().collect(Collectors.groupingBy(x -> x.getVisitId()));
|
|
|
660 |
}
|
| 35079 |
vikas |
661 |
List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository.selectByAuthIdAndStatus(authUser.getId(), status, offset, limit);
|
| 25952 |
tejbeer |
662 |
|
| 35415 |
amit |
663 |
// Batch fetch all FranchiseeActivity in one query instead of N+1
|
|
|
664 |
List<Integer> activityIds = franchiseeVisits.stream()
|
|
|
665 |
.filter(fv -> fv.getFranchiseActivityId() != 0)
|
|
|
666 |
.map(FranchiseeVisit::getFranchiseActivityId)
|
|
|
667 |
.collect(Collectors.toList());
|
|
|
668 |
Map<Integer, FranchiseeActivity> activityMap = new HashMap<>();
|
|
|
669 |
if (!activityIds.isEmpty()) {
|
|
|
670 |
activityMap = franchiseeActivityRepository.selectByIds(activityIds).stream()
|
|
|
671 |
.collect(Collectors.toMap(FranchiseeActivity::getId, x -> x));
|
|
|
672 |
}
|
|
|
673 |
|
| 31677 |
amit.gupta |
674 |
for (FranchiseeVisit fv : franchiseeVisits) {
|
|
|
675 |
if (visitRequestMap != null) {
|
| 31249 |
tejbeer |
676 |
|
| 31677 |
amit.gupta |
677 |
List<VisitRequest> visitRequest = visitRequestMap.get(fv.getId());
|
|
|
678 |
if (visitRequest != null) {
|
|
|
679 |
if (visitRequest.size() > 1) {
|
| 31249 |
tejbeer |
680 |
|
| 35079 |
vikas |
681 |
Comparator<VisitRequest> visitComparato = Comparator.comparing(VisitRequest::getCreatedTimestamp);
|
| 31249 |
tejbeer |
682 |
|
| 31677 |
amit.gupta |
683 |
VisitRequest youngestVisit = visitRequest.stream().max(visitComparato).get();
|
|
|
684 |
fv.setVisitStatus(youngestVisit.getStatus());
|
| 31249 |
tejbeer |
685 |
|
| 31677 |
amit.gupta |
686 |
} else {
|
|
|
687 |
fv.setVisitStatus(visitRequest.get(0).getStatus());
|
| 31249 |
tejbeer |
688 |
|
| 31677 |
amit.gupta |
689 |
}
|
|
|
690 |
}
|
|
|
691 |
}
|
|
|
692 |
if (fv.getFranchiseActivityId() != 0) {
|
| 35415 |
amit |
693 |
FranchiseeActivity fA = activityMap.get(fv.getFranchiseActivityId());
|
| 31677 |
amit.gupta |
694 |
fv.setFranchiseeActivity(fA);
|
|
|
695 |
}
|
| 31249 |
tejbeer |
696 |
|
| 31677 |
amit.gupta |
697 |
}
|
| 25952 |
tejbeer |
698 |
|
| 31677 |
amit.gupta |
699 |
return responseSender.ok(franchiseeVisits);
|
| 25952 |
tejbeer |
700 |
|
| 31677 |
amit.gupta |
701 |
}
|
| 25952 |
tejbeer |
702 |
|
| 31677 |
amit.gupta |
703 |
@RequestMapping(value = "/getFranchiseActivity", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35079 |
vikas |
704 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 35288 |
amit |
705 |
public ResponseEntity<?> getFranchiseActivity(HttpServletRequest request, @RequestParam(name = "id") int id) throws
|
|
|
706 |
ProfitMandiBusinessException {
|
| 25952 |
tejbeer |
707 |
|
| 31677 |
amit.gupta |
708 |
List<FranchiseeActivity> franchiseeActivities = franchiseeActivityRepository.selectByFranchiseeVisitId(id);
|
|
|
709 |
return responseSender.ok(franchiseeActivities);
|
| 25952 |
tejbeer |
710 |
|
| 31677 |
amit.gupta |
711 |
}
|
| 25952 |
tejbeer |
712 |
|
| 31677 |
amit.gupta |
713 |
@RequestMapping(value = "/getFranchiseeInfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35079 |
vikas |
714 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 35288 |
amit |
715 |
public ResponseEntity<?> getFranchiseeInfo(HttpServletRequest request, @RequestParam(name = "id") int id) throws
|
|
|
716 |
ProfitMandiBusinessException {
|
| 31677 |
amit.gupta |
717 |
FranchiseeVisit franchiseeVisit = franchiseeVisitRepository.selectById(id);
|
| 25952 |
tejbeer |
718 |
|
| 31677 |
amit.gupta |
719 |
List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
|
| 30487 |
tejbeer |
720 |
|
| 31677 |
amit.gupta |
721 |
List<String> brands = mobileBrands.stream().filter(x -> (boolean) x.get("active"))
|
|
|
722 |
.map(x -> (String) x.get("name")).collect(Collectors.toList());
|
| 30487 |
tejbeer |
723 |
|
| 31677 |
amit.gupta |
724 |
franchiseeVisit.setBrands(brands);
|
| 30487 |
tejbeer |
725 |
|
| 31677 |
amit.gupta |
726 |
return responseSender.ok(franchiseeVisit);
|
| 25952 |
tejbeer |
727 |
|
| 31677 |
amit.gupta |
728 |
}
|
| 25952 |
tejbeer |
729 |
|
| 31677 |
amit.gupta |
730 |
@RequestMapping(value = "/franchise-visit-update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35079 |
vikas |
731 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 35288 |
amit |
732 |
public ResponseEntity<?> franchiseVisitUpdate(HttpServletRequest request, @RequestParam(name = "id") int id,
|
|
|
733 |
@RequestParam(name = "action") FranchiseeActivityStatus action,
|
|
|
734 |
@RequestParam(name = "resolution") String resolution,
|
|
|
735 |
@RequestParam(name = "schelduleTimestamp") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime schelduleTimestamp)
|
| 31677 |
amit.gupta |
736 |
throws ProfitMandiBusinessException {
|
|
|
737 |
FranchiseeVisit franchiseeVisit = franchiseeVisitRepository.selectById(id);
|
| 25952 |
tejbeer |
738 |
|
| 31677 |
amit.gupta |
739 |
FranchiseeActivity franchiseeActivity = new FranchiseeActivity();
|
| 25952 |
tejbeer |
740 |
|
| 31677 |
amit.gupta |
741 |
if (action == FranchiseeActivityStatus.FOLLOWUP) {
|
| 30487 |
tejbeer |
742 |
|
| 31677 |
amit.gupta |
743 |
if (schelduleTimestamp != null) {
|
| 31249 |
tejbeer |
744 |
|
| 31677 |
amit.gupta |
745 |
visitRequestRepository.createVisitRequest(franchiseeVisit.getId(), "franchiseeVisit",
|
|
|
746 |
franchiseeVisit.getAuthId(), schelduleTimestamp);
|
|
|
747 |
}
|
| 31249 |
tejbeer |
748 |
|
| 31677 |
amit.gupta |
749 |
franchiseeActivity.setSchelduleTimestamp(schelduleTimestamp);
|
|
|
750 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.OPEN);
|
|
|
751 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
752 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| 25952 |
tejbeer |
753 |
|
| 31677 |
amit.gupta |
754 |
} else {
|
| 30487 |
tejbeer |
755 |
|
| 31677 |
amit.gupta |
756 |
franchiseeActivity.setSchelduleTimestamp(null);
|
|
|
757 |
franchiseeVisit.setFranchiseActivityId(franchiseeActivity.getId());
|
|
|
758 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.CLOSE);
|
|
|
759 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
760 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| 25952 |
tejbeer |
761 |
|
| 31677 |
amit.gupta |
762 |
}
|
| 25952 |
tejbeer |
763 |
|
| 31677 |
amit.gupta |
764 |
franchiseeActivity.setResolution(resolution);
|
|
|
765 |
franchiseeActivity.setFranchiseeVisitd(franchiseeVisit.getId());
|
|
|
766 |
franchiseeActivity.setAction(action);
|
| 30487 |
tejbeer |
767 |
|
| 31677 |
amit.gupta |
768 |
franchiseeActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
769 |
franchiseeActivityRepository.persist(franchiseeActivity);
|
| 30487 |
tejbeer |
770 |
|
| 31677 |
amit.gupta |
771 |
franchiseeVisit.setFranchiseActivityId(franchiseeActivity.getId());
|
|
|
772 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.OPEN);
|
|
|
773 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
774 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| 30487 |
tejbeer |
775 |
|
| 31677 |
amit.gupta |
776 |
return responseSender.ok(true);
|
| 25952 |
tejbeer |
777 |
|
| 31677 |
amit.gupta |
778 |
}
|
| 28935 |
tejbeer |
779 |
|
| 31677 |
amit.gupta |
780 |
@RequestMapping(value = "/onBoardingTimelineStatus", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35079 |
vikas |
781 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 31677 |
amit.gupta |
782 |
public ResponseEntity<?> onBoardingTimelineStatus(HttpServletRequest request, Model model)
|
|
|
783 |
throws ProfitMandiBusinessException {
|
| 35075 |
aman |
784 |
//This userId is of dtr.users
|
| 31677 |
amit.gupta |
785 |
int userId = (int) request.getAttribute("userId");
|
| 35075 |
aman |
786 |
|
|
|
787 |
//UserCart contains userId/retailerId in context of user.user as
|
|
|
788 |
//uc contains retailerId and cartId of the retailerId that belongs to user schema
|
| 31677 |
amit.gupta |
789 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
790 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(uc.getUserId());
|
|
|
791 |
PartnerOnBoardingPanel partnerOnBoardingPanel = partnerOnBoardingPanelRepository.selectByCode(fs.getCode());
|
|
|
792 |
Map<StoreTimeline, OnBoardingTimelineModel> timelineStatus = null;
|
|
|
793 |
LOGGER.info("partnerOnBoardingPanel" + partnerOnBoardingPanel);
|
|
|
794 |
if (partnerOnBoardingPanel != null) {
|
| 28935 |
tejbeer |
795 |
|
| 31677 |
amit.gupta |
796 |
timelineStatus = storeTimelineTatService.getTimeline(partnerOnBoardingPanel.getId());
|
|
|
797 |
}
|
|
|
798 |
List<OnBoardingTimelineModel> onBoardingModel = new ArrayList<>();
|
|
|
799 |
if (timelineStatus != null) {
|
|
|
800 |
onBoardingModel = timelineStatus.values().stream().skip(2).map(x -> x).collect(Collectors.toList());
|
|
|
801 |
}
|
|
|
802 |
return responseSender.ok(onBoardingModel);
|
| 28935 |
tejbeer |
803 |
|
| 31677 |
amit.gupta |
804 |
}
|
| 35288 |
amit |
805 |
|
| 35075 |
aman |
806 |
@RequestMapping(value = "/purchaseExist", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
807 |
@ApiImplicitParams({
|
|
|
808 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 35415 |
amit |
809 |
public ResponseEntity<?> purchaseExist(HttpServletRequest request) throws ProfitMandiBusinessException {
|
| 35075 |
aman |
810 |
int userId = (int) request.getAttribute("userId");
|
|
|
811 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| 35415 |
amit |
812 |
return responseSender.ok(purchaseRepository.hasPurchaseForFofoId(uc.getUserId()));
|
| 35075 |
aman |
813 |
}
|
| 35288 |
amit |
814 |
|
| 31677 |
amit.gupta |
815 |
@RequestMapping(value = "/onBoardingTimelineVisibility", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35079 |
vikas |
816 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 31677 |
amit.gupta |
817 |
public ResponseEntity<?> onBoardingTimelineVisibility(HttpServletRequest request, Model model)
|
|
|
818 |
throws ProfitMandiBusinessException {
|
|
|
819 |
int userId = (int) request.getAttribute("userId");
|
|
|
820 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| 28982 |
tejbeer |
821 |
|
| 31677 |
amit.gupta |
822 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(uc.getUserId());
|
|
|
823 |
PartnerOnBoardingPanel partnerOnBoardingPanel = partnerOnBoardingPanelRepository.selectByCode(fs.getCode());
|
|
|
824 |
boolean status = true;
|
|
|
825 |
if (partnerOnBoardingPanel != null) {
|
| 28982 |
tejbeer |
826 |
|
| 31677 |
amit.gupta |
827 |
status = storeTimelineTatService.getTimelineCompleted(partnerOnBoardingPanel.getId());
|
|
|
828 |
}
|
| 28982 |
tejbeer |
829 |
|
| 31677 |
amit.gupta |
830 |
LOGGER.info("status" + status);
|
| 28983 |
tejbeer |
831 |
|
| 31677 |
amit.gupta |
832 |
return responseSender.ok(status);
|
| 28982 |
tejbeer |
833 |
|
| 31677 |
amit.gupta |
834 |
}
|
| 30077 |
tejbeer |
835 |
|
| 31677 |
amit.gupta |
836 |
@RequestMapping(value = "/getPartnerTarget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35079 |
vikas |
837 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 35288 |
amit |
838 |
public ResponseEntity<?> getPartnerTarget(HttpServletRequest request, @RequestParam String
|
|
|
839 |
gmailId, @RequestParam String dayValue, @RequestParam ActivationType activationType) throws
|
|
|
840 |
ProfitMandiBusinessException {
|
| 30077 |
tejbeer |
841 |
|
| 35632 |
ranu |
842 |
long startTime = System.currentTimeMillis();
|
|
|
843 |
long lapTime = startTime;
|
|
|
844 |
|
| 31677 |
amit.gupta |
845 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
| 35632 |
ranu |
846 |
|
| 35649 |
ranu |
847 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
|
|
848 |
Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
|
| 31677 |
amit.gupta |
849 |
List<String> brands = Arrays.asList("Vivo", "Samsung", "Oppo", "Itel", "Almost New", "Others");
|
| 30078 |
tejbeer |
850 |
|
| 35649 |
ranu |
851 |
|
| 31677 |
amit.gupta |
852 |
float totalPartnerTargetSecondary = 0;
|
|
|
853 |
float totalPartnerTargetCollection = 0;
|
|
|
854 |
float totalPartnerAchievementSecondary = 0;
|
|
|
855 |
float totalPartnerAchievementCollection = 0;
|
|
|
856 |
TargetModel tm = new TargetModel();
|
|
|
857 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
|
| 35632 |
ranu |
858 |
Map<Integer, Long> partnerTicketCount = new HashMap<>(); // Will be populated after we have fofoIdList
|
| 30416 |
tejbeer |
859 |
|
| 31677 |
amit.gupta |
860 |
List<PartnerTargetAchievementModel> ptams = new ArrayList<>();
|
| 30077 |
tejbeer |
861 |
|
| 31677 |
amit.gupta |
862 |
if (fofoIds != null && fofoIds.size() > 0) {
|
| 32737 |
amit.gupta |
863 |
LOGGER.info("fofoIds {}", fofoIds);
|
| 31727 |
amit.gupta |
864 |
List<Integer> fofoIdList = fofoStoreRepository.selectByRetailerIds(new ArrayList<>(fofoIds)).stream()
|
| 31677 |
amit.gupta |
865 |
.filter(x -> (!x.isInternal() && (activationType == null || x.getActivationType().equals(activationType))))
|
|
|
866 |
.map(x -> x.getId()).collect(Collectors.toList());
|
| 35632 |
ranu |
867 |
LOGGER.info("PERF: selectByRetailerIds took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
868 |
lapTime = System.currentTimeMillis();
|
|
|
869 |
LOGGER.info("fofoIdList size: {}", fofoIdList.size());
|
|
|
870 |
|
|
|
871 |
// Optimized: fetch ticket counts only for specific fofoIds instead of all retailers
|
|
|
872 |
if (!fofoIdList.isEmpty()) {
|
|
|
873 |
partnerTicketCount = ticketRepository.selectOpenTicketsCountByFofoIds(fofoIdList);
|
|
|
874 |
}
|
|
|
875 |
LOGGER.info("PERF: selectOpenTicketsCountByFofoIds took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
876 |
lapTime = System.currentTimeMillis();
|
| 31677 |
amit.gupta |
877 |
LocalDateTime startDate = LocalDate.now().atStartOfDay();
|
| 30077 |
tejbeer |
878 |
|
| 31677 |
amit.gupta |
879 |
if (dayValue.equals("previous")) {
|
|
|
880 |
startDate = LocalDate.now().minusDays(1).atStartOfDay();
|
| 30138 |
tejbeer |
881 |
|
| 31677 |
amit.gupta |
882 |
}
|
| 30087 |
tejbeer |
883 |
|
| 31686 |
amit.gupta |
884 |
if (fofoIdList.size() > 0) {
|
| 30453 |
tejbeer |
885 |
|
| 35632 |
ranu |
886 |
// Fetch fofoIds with overdue loans (pending amount > 0 and created > 15 days ago)
|
|
|
887 |
// Optimized: returns only fofoIds, not full Loan objects
|
|
|
888 |
LocalDateTime fifteenDaysAgo = LocalDate.now().minusDays(15).atStartOfDay();
|
|
|
889 |
Set<Integer> fofoIdsWithOverdueLoans = loanRepository.selectFofoIdsWithOverdueLoans(fofoIdList, fifteenDaysAgo);
|
|
|
890 |
LOGGER.info("PERF: selectFofoIdsWithOverdueLoans took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
891 |
lapTime = System.currentTimeMillis();
|
|
|
892 |
|
|
|
893 |
// Fetch fofoIds with MTD billing above threshold (20000)
|
|
|
894 |
// Optimized: direct query on orders table instead of complex RBM query
|
|
|
895 |
LocalDateTime mtdStartDate = LocalDate.now().withDayOfMonth(1).atStartOfDay();
|
|
|
896 |
LocalDateTime mtdEndDate = LocalDate.now().plusDays(1).atStartOfDay();
|
| 35650 |
ranu |
897 |
long billingThreshold = 1000L; // Same as RbmWeeklyBillingModel.BILLING_THRESHOLD
|
| 35632 |
ranu |
898 |
Set<Integer> allMtdBilledFofoIds = orderRepository.selectFofoIdsWithMtdBillingAboveThreshold(
|
|
|
899 |
fofoIdList, mtdStartDate, mtdEndDate, billingThreshold);
|
|
|
900 |
LOGGER.info("PERF: selectFofoIdsWithMtdBillingAboveThreshold took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
901 |
lapTime = System.currentTimeMillis();
|
|
|
902 |
|
| 35079 |
vikas |
903 |
List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository.selectAll(fofoIdList, startDate.toLocalDate().minusDays(1));
|
| 35632 |
ranu |
904 |
LOGGER.info("PERF: partnerDailyInvestmentRepository.selectAll took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
905 |
lapTime = System.currentTimeMillis();
|
| 30087 |
tejbeer |
906 |
|
| 31686 |
amit.gupta |
907 |
if (!partnerDailyInvestments.isEmpty()) {
|
| 35079 |
vikas |
908 |
partnerDailyInvestmentMap = partnerDailyInvestments.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 31686 |
amit.gupta |
909 |
}
|
| 30077 |
tejbeer |
910 |
|
| 35632 |
ranu |
911 |
// Optimized: fetch only specific fofoIds instead of all retailers
|
|
|
912 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(fofoIdList);
|
|
|
913 |
LOGGER.info("PERF: getFofoRetailers took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
914 |
lapTime = System.currentTimeMillis();
|
| 30426 |
tejbeer |
915 |
|
| 31686 |
amit.gupta |
916 |
List<Integer> remarkIds = partnerCollectionRemarkRepository.selectMaxRemarkId(fofoIdList);
|
| 35632 |
ranu |
917 |
LOGGER.info("PERF: selectMaxRemarkId took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
918 |
lapTime = System.currentTimeMillis();
|
| 30453 |
tejbeer |
919 |
|
| 31686 |
amit.gupta |
920 |
long todayCollectionCount = 0;
|
|
|
921 |
if (!remarkIds.isEmpty()) {
|
|
|
922 |
todayCollectionCount = partnerCollectionRemarkRepository
|
|
|
923 |
.selectByAuthIdAndIds(authUser.getId(), remarkIds).stream()
|
|
|
924 |
.filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now()))
|
|
|
925 |
.collect(Collectors.counting());
|
| 30453 |
tejbeer |
926 |
|
| 31686 |
amit.gupta |
927 |
}
|
| 35632 |
ranu |
928 |
LOGGER.info("PERF: selectByAuthIdAndIds took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
929 |
lapTime = System.currentTimeMillis();
|
| 30330 |
tejbeer |
930 |
|
| 35079 |
vikas |
931 |
Map<Integer, PartnerCollectionPlanModel> collectionMap = partnerCollectionService.getCollectionMap(fofoIdList, startDate);
|
| 35632 |
ranu |
932 |
LOGGER.info("PERF: getCollectionMap took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
933 |
lapTime = System.currentTimeMillis();
|
| 30077 |
tejbeer |
934 |
|
| 32978 |
amit.gupta |
935 |
Map<Integer, List<PartnerSecondaryPlanModel>> partnerSecondaryPlans = orderRepository
|
| 31686 |
amit.gupta |
936 |
.selectPartnerSecondaryGroupByBrand(fofoIdList, startDate.toLocalDate()).stream()
|
|
|
937 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 35632 |
ranu |
938 |
LOGGER.info("PERF: selectPartnerSecondaryGroupByBrand took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
939 |
lapTime = System.currentTimeMillis();
|
| 30077 |
tejbeer |
940 |
|
| 35415 |
amit |
941 |
// Pre-fetch all AuthUsers that might be needed (instead of N+1 queries)
|
|
|
942 |
Set<Integer> allAuthIds = new HashSet<>();
|
|
|
943 |
collectionMap.values().stream()
|
|
|
944 |
.map(PartnerCollectionPlanModel::getAuthId)
|
|
|
945 |
.filter(id -> id != null && id != authUser.getId())
|
|
|
946 |
.forEach(allAuthIds::add);
|
|
|
947 |
partnerSecondaryPlans.values().stream()
|
|
|
948 |
.flatMap(List::stream)
|
|
|
949 |
.map(PartnerSecondaryPlanModel::getAuthId)
|
|
|
950 |
.filter(id -> id != null && id != authUser.getId())
|
|
|
951 |
.forEach(allAuthIds::add);
|
|
|
952 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|
|
|
953 |
if (!allAuthIds.isEmpty()) {
|
|
|
954 |
authUserMap = authRepository.selectByIds(new ArrayList<>(allAuthIds)).stream()
|
|
|
955 |
.collect(Collectors.toMap(AuthUser::getId, x -> x));
|
|
|
956 |
}
|
|
|
957 |
|
| 35968 |
ranu |
958 |
// Fetch BM/ASM/RBM for all partners
|
|
|
959 |
Map<Integer, Map<String, Integer>> bmAsmRbmMap = csService.getBmAsmRbmAuthUserIdsByFofoIds(new HashSet<>(fofoIdList));
|
|
|
960 |
LOGGER.info("PERF: getBmAsmRbmAuthUserIdsByFofoIds took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
961 |
lapTime = System.currentTimeMillis();
|
|
|
962 |
|
|
|
963 |
// Collect all BM/ASM/RBM auth IDs to batch fetch AuthUser names
|
|
|
964 |
Set<Integer> bmAsmRbmAuthIds = bmAsmRbmMap.values().stream()
|
|
|
965 |
.flatMap(m -> m.values().stream())
|
|
|
966 |
.filter(id -> id != null && id > 0)
|
|
|
967 |
.collect(Collectors.toSet());
|
|
|
968 |
|
|
|
969 |
Map<Integer, AuthUser> bmAsmRbmAuthUserMap = new HashMap<>();
|
|
|
970 |
if (!bmAsmRbmAuthIds.isEmpty()) {
|
|
|
971 |
bmAsmRbmAuthUserMap = authRepository.selectByIds(new ArrayList<>(bmAsmRbmAuthIds)).stream()
|
|
|
972 |
.collect(Collectors.toMap(AuthUser::getId, x -> x, (a, b) -> a));
|
|
|
973 |
}
|
|
|
974 |
LOGGER.info("PERF: fetch BM/ASM/RBM AuthUsers took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
975 |
lapTime = System.currentTimeMillis();
|
|
|
976 |
|
| 32978 |
amit.gupta |
977 |
LOGGER.info("partnerSecondayPlans {}", partnerSecondaryPlans);
|
| 35968 |
ranu |
978 |
final Map<Integer, AuthUser> finalBmAsmRbmAuthUserMap = bmAsmRbmAuthUserMap;
|
| 31686 |
amit.gupta |
979 |
for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailers.entrySet()) {
|
|
|
980 |
int fofoId = customRetailerEntry.getKey();
|
|
|
981 |
CustomRetailer customRetailer = customRetailerEntry.getValue();
|
|
|
982 |
float totalSecondaryPlan = 0;
|
|
|
983 |
float totalSecondaryAchivement = 0;
|
| 30077 |
tejbeer |
984 |
|
| 31686 |
amit.gupta |
985 |
PartnerTargetAchievementModel ptam = new PartnerTargetAchievementModel();
|
|
|
986 |
ptam.setFofoId(fofoId);
|
|
|
987 |
ptam.setBusinessName(customRetailer.getBusinessName());
|
|
|
988 |
ptam.setMobile(customRetailer.getMobileNumber());
|
| 36211 |
ranu |
989 |
ptam.setActivationType(customRetailer.getActivationType());
|
| 30087 |
tejbeer |
990 |
|
| 35968 |
ranu |
991 |
// Set ASM/RBM/BM names
|
|
|
992 |
Map<String, Integer> roleMap = bmAsmRbmMap.get(fofoId);
|
|
|
993 |
if (roleMap != null) {
|
|
|
994 |
Integer asmId = roleMap.get("ASM");
|
|
|
995 |
if (asmId != null && asmId > 0 && finalBmAsmRbmAuthUserMap.get(asmId) != null) {
|
|
|
996 |
ptam.setAsmName(finalBmAsmRbmAuthUserMap.get(asmId).getFullName());
|
|
|
997 |
}
|
|
|
998 |
Integer rbmId = roleMap.get("RBM");
|
|
|
999 |
if (rbmId != null && rbmId > 0 && finalBmAsmRbmAuthUserMap.get(rbmId) != null) {
|
|
|
1000 |
ptam.setRbmName(finalBmAsmRbmAuthUserMap.get(rbmId).getFullName());
|
|
|
1001 |
}
|
|
|
1002 |
Integer bmId = roleMap.get("BM");
|
|
|
1003 |
if (bmId != null && bmId > 0 && finalBmAsmRbmAuthUserMap.get(bmId) != null) {
|
|
|
1004 |
ptam.setBmName(finalBmAsmRbmAuthUserMap.get(bmId).getFullName());
|
|
|
1005 |
}
|
|
|
1006 |
}
|
|
|
1007 |
|
| 31686 |
amit.gupta |
1008 |
if (partnerDailyInvestmentMap.get(fofoId) != null) {
|
|
|
1009 |
ptam.setWalletAmount(partnerDailyInvestmentMap.get(fofoId).getWalletAmount());
|
|
|
1010 |
ptam.setShortInvestment(partnerDailyInvestmentMap.get(fofoId).getShortInvestment());
|
|
|
1011 |
}
|
| 30808 |
tejbeer |
1012 |
|
| 32978 |
amit.gupta |
1013 |
if (collectionMap.get(fofoId) != null) {
|
|
|
1014 |
PartnerCollectionPlanModel collectionPlan = collectionMap.get(fofoId);
|
| 30330 |
tejbeer |
1015 |
|
| 31686 |
amit.gupta |
1016 |
ptam.setRemark(collectionPlan.getRemark());
|
|
|
1017 |
ptam.setMessage(collectionPlan.getMessage());
|
|
|
1018 |
ptam.setRemarkTimestamp(collectionPlan.getRemarkTimestamp());
|
| 35632 |
ranu |
1019 |
ptam.setRecordingUrl(collectionPlan.getRecordingUrl());
|
| 35835 |
ranu |
1020 |
ptam.setScheduledCallTime(collectionPlan.getScheduledCallTime());
|
| 31686 |
amit.gupta |
1021 |
ptam.setRank(collectionPlan.getRank());
|
| 36267 |
ranu |
1022 |
|
|
|
1023 |
// If remark is SALES_ESCALATION, fetch open escalation ticket activities
|
|
|
1024 |
if (CollectionRemark.SALES_ESCALATION.equals(collectionPlan.getRemark())
|
|
|
1025 |
|| CollectionRemark.PARTIAL_RESOLVE.equals(collectionPlan.getRemark())
|
|
|
1026 |
|| CollectionRemark.NOT_RESOLVED.equals(collectionPlan.getRemark())) {
|
|
|
1027 |
List<Ticket> openTickets = ticketRepository.selectAllOpenTicketByRetailer(fofoId);
|
|
|
1028 |
for (Ticket ticket : openTickets) {
|
|
|
1029 |
if (ticket.getSubCategoryId() == ProfitMandiConstants.SALES_ESCALATION) {
|
|
|
1030 |
List<Activity> activities = activityRepository.selectAll(ticket.getId());
|
|
|
1031 |
ptam.setTicketActivities(activities);
|
|
|
1032 |
break;
|
|
|
1033 |
}
|
|
|
1034 |
}
|
|
|
1035 |
}
|
|
|
1036 |
|
| 31686 |
amit.gupta |
1037 |
Integer authId = collectionPlan.getAuthId();
|
| 30330 |
tejbeer |
1038 |
|
| 31686 |
amit.gupta |
1039 |
Map<Integer, String> rankColorMap = ProfitMandiConstants.Rank_Color_Map;
|
| 30416 |
tejbeer |
1040 |
|
| 31686 |
amit.gupta |
1041 |
ptam.setCollectionColor(rankColorMap.get(collectionPlan.getRank()));
|
| 30077 |
tejbeer |
1042 |
|
| 31686 |
amit.gupta |
1043 |
LOGGER.info("authId" + authId);
|
| 30137 |
tejbeer |
1044 |
|
| 31686 |
amit.gupta |
1045 |
if (collectionPlan.getTargetPlan() != null && collectionPlan.getCommittedDate() != null) {
|
|
|
1046 |
float targetCollection = 0;
|
| 30330 |
tejbeer |
1047 |
|
| 31686 |
amit.gupta |
1048 |
if (collectionPlan.getRank() == 2 && collectionPlan.getAchievementPlan() != null) {
|
|
|
1049 |
targetCollection = collectionPlan.getTargetPlan() - collectionPlan.getAchievementPlan();
|
|
|
1050 |
} else {
|
|
|
1051 |
targetCollection = collectionPlan.getTargetPlan();
|
| 31677 |
amit.gupta |
1052 |
}
|
| 30451 |
tejbeer |
1053 |
|
| 31677 |
amit.gupta |
1054 |
if (authId != null && authId == authUser.getId()) {
|
| 31686 |
amit.gupta |
1055 |
if (!collectionPlan.getCommittedDate().isAfter(startDate)) {
|
|
|
1056 |
totalPartnerTargetCollection += targetCollection;
|
|
|
1057 |
}
|
| 31677 |
amit.gupta |
1058 |
}
|
| 31686 |
amit.gupta |
1059 |
ptam.setCollectionTarget(targetCollection);
|
|
|
1060 |
if (collectionPlan.getRank() == 2 && collectionPlan.getAchievementPlan() != null
|
|
|
1061 |
&& collectionPlan.getWalletTimestamp() != null
|
|
|
1062 |
&& collectionPlan.getWalletTimestamp().toLocalDate().equals(startDate.toLocalDate())) {
|
|
|
1063 |
if (authId != null && authId == authUser.getId()) {
|
|
|
1064 |
totalPartnerAchievementCollection += collectionPlan.getAchievementPlan();
|
|
|
1065 |
}
|
|
|
1066 |
ptam.setCollectionAchievement(collectionPlan.getAchievementPlan());
|
|
|
1067 |
} else if (collectionPlan.getCommittedDate().toLocalDate().isEqual(startDate.toLocalDate())
|
|
|
1068 |
&& collectionPlan.getAchievementPlan() != null) {
|
|
|
1069 |
if (authId != null && authId == authUser.getId()) {
|
|
|
1070 |
totalPartnerAchievementCollection += collectionPlan.getAchievementPlan();
|
|
|
1071 |
}
|
|
|
1072 |
ptam.setCollectionAchievement(collectionPlan.getAchievementPlan());
|
|
|
1073 |
|
| 31677 |
amit.gupta |
1074 |
}
|
| 31686 |
amit.gupta |
1075 |
}
|
| 30822 |
tejbeer |
1076 |
|
| 31686 |
amit.gupta |
1077 |
if (authId != null && authId != authUser.getId()) {
|
| 35415 |
amit |
1078 |
ptam.setAuthUser(authUserMap.get(authId));
|
| 31686 |
amit.gupta |
1079 |
|
| 31677 |
amit.gupta |
1080 |
}
|
| 30087 |
tejbeer |
1081 |
|
| 31686 |
amit.gupta |
1082 |
if (collectionPlan.getCommittedDate() != null) {
|
| 30087 |
tejbeer |
1083 |
|
| 31686 |
amit.gupta |
1084 |
ptam.setCollectionCommitmentDate(collectionPlan.getCommittedDate().toLocalDate());
|
|
|
1085 |
}
|
| 30087 |
tejbeer |
1086 |
|
| 31677 |
amit.gupta |
1087 |
}
|
| 30821 |
tejbeer |
1088 |
|
| 31686 |
amit.gupta |
1089 |
// Secondary
|
| 30077 |
tejbeer |
1090 |
|
| 31686 |
amit.gupta |
1091 |
PartnerSecondaryPlanModel otherPartnerSecondaryPlanModel = null;
|
|
|
1092 |
Map<String, PartnerSecondaryPlanModel> secondaryModelMap = new HashMap<>();
|
| 32978 |
amit.gupta |
1093 |
if (partnerSecondaryPlans.get(fofoId) != null) {
|
| 31686 |
amit.gupta |
1094 |
long otherBrandSecondary = 0;
|
| 32978 |
amit.gupta |
1095 |
for (PartnerSecondaryPlanModel pspm : partnerSecondaryPlans.get(fofoId)) {
|
| 31686 |
amit.gupta |
1096 |
Integer authId = pspm.getAuthId();
|
|
|
1097 |
if (!brands.contains(pspm.getBrand())) {
|
|
|
1098 |
if (pspm.getAchievementPlan() != null) {
|
|
|
1099 |
otherBrandSecondary += pspm.getAchievementPlan();
|
|
|
1100 |
}
|
|
|
1101 |
} else {
|
|
|
1102 |
otherPartnerSecondaryPlanModel = pspm;
|
|
|
1103 |
}
|
|
|
1104 |
if (pspm.getTargetPlan() != null) {
|
|
|
1105 |
totalSecondaryPlan += pspm.getTargetPlan();
|
|
|
1106 |
}
|
| 30330 |
tejbeer |
1107 |
|
| 31677 |
amit.gupta |
1108 |
if (pspm.getAchievementPlan() != null) {
|
| 31686 |
amit.gupta |
1109 |
totalSecondaryAchivement += pspm.getAchievementPlan();
|
| 31677 |
amit.gupta |
1110 |
}
|
| 30087 |
tejbeer |
1111 |
|
| 31686 |
amit.gupta |
1112 |
if (pspm.getCommittedDate() != null) {
|
| 30137 |
tejbeer |
1113 |
|
| 31686 |
amit.gupta |
1114 |
ptam.setSecondaryCommitmentDate(pspm.getCommittedDate().toLocalDate());
|
|
|
1115 |
}
|
|
|
1116 |
if (authId != null && authId == authUser.getId()) {
|
| 30137 |
tejbeer |
1117 |
|
| 31686 |
amit.gupta |
1118 |
if (pspm.getTargetPlan() != null && pspm.getCommittedDate() != null) {
|
| 30087 |
tejbeer |
1119 |
|
| 31686 |
amit.gupta |
1120 |
if (pspm.getCommittedDate().isEqual(startDate)) {
|
|
|
1121 |
totalPartnerTargetSecondary += pspm.getTargetPlan();
|
|
|
1122 |
}
|
|
|
1123 |
}
|
| 30087 |
tejbeer |
1124 |
|
| 31686 |
amit.gupta |
1125 |
if (pspm.getAchievementPlan() != null) {
|
|
|
1126 |
totalPartnerAchievementSecondary += pspm.getAchievementPlan();
|
| 31677 |
amit.gupta |
1127 |
}
|
| 31686 |
amit.gupta |
1128 |
|
| 31677 |
amit.gupta |
1129 |
}
|
| 31686 |
amit.gupta |
1130 |
}
|
|
|
1131 |
if (otherPartnerSecondaryPlanModel != null) {
|
|
|
1132 |
otherPartnerSecondaryPlanModel.setAchievementPlan(otherBrandSecondary);
|
|
|
1133 |
}
|
| 32978 |
amit.gupta |
1134 |
secondaryModelMap = partnerSecondaryPlans.get(fofoId).stream()
|
| 31686 |
amit.gupta |
1135 |
.filter(x -> brands.contains(x.getBrand()))
|
|
|
1136 |
.collect(Collectors.toMap(x -> x.getBrand(), x -> x));
|
| 30087 |
tejbeer |
1137 |
|
| 31686 |
amit.gupta |
1138 |
if (secondaryModelMap.containsKey("Others")) {
|
|
|
1139 |
PartnerSecondaryPlanModel psp = secondaryModelMap.get("Others");
|
|
|
1140 |
psp.setAchievementPlan(otherBrandSecondary);
|
|
|
1141 |
} else {
|
| 35079 |
vikas |
1142 |
secondaryModelMap.put("Others", new PartnerSecondaryPlanModel(fofoId, "Others", (long) 0, otherBrandSecondary, authUser.getId(), null));
|
| 31686 |
amit.gupta |
1143 |
}
|
|
|
1144 |
for (String brand : brands) {
|
|
|
1145 |
if (!secondaryModelMap.containsKey(brand)) {
|
| 35079 |
vikas |
1146 |
secondaryModelMap.put(brand, new PartnerSecondaryPlanModel(fofoId, brand, (long) 0, (long) 0, authUser.getId(), null));
|
| 31677 |
amit.gupta |
1147 |
}
|
| 31686 |
amit.gupta |
1148 |
}
|
| 30087 |
tejbeer |
1149 |
|
| 31686 |
amit.gupta |
1150 |
for (Entry<String, PartnerSecondaryPlanModel> secondaryModelEntry : secondaryModelMap.entrySet()) {
|
|
|
1151 |
Integer authId = secondaryModelEntry.getValue().getAuthId();
|
|
|
1152 |
if (authId != null && authId != authUser.getId()) {
|
| 35415 |
amit |
1153 |
secondaryModelEntry.getValue().setAuthUser(authUserMap.get(authId));
|
| 31686 |
amit.gupta |
1154 |
ptam.setSecondaryColor("red");
|
|
|
1155 |
}
|
|
|
1156 |
|
| 31677 |
amit.gupta |
1157 |
}
|
| 30077 |
tejbeer |
1158 |
|
| 31686 |
amit.gupta |
1159 |
ptam.setPartnerSecondaryModel(secondaryModelMap);
|
|
|
1160 |
ptam.setTotalSecondaryPlan(totalSecondaryPlan);
|
|
|
1161 |
ptam.setTotalSecondaryAchievement(totalSecondaryAchivement);
|
|
|
1162 |
// Secondary
|
|
|
1163 |
|
| 31677 |
amit.gupta |
1164 |
} else {
|
| 31686 |
amit.gupta |
1165 |
for (String brand : brands) {
|
|
|
1166 |
PartnerSecondaryPlanModel pspm = new PartnerSecondaryPlanModel();
|
|
|
1167 |
pspm.setAchievementPlan((long) 0);
|
|
|
1168 |
pspm.setTargetPlan((long) 0);
|
|
|
1169 |
pspm.setBrand(brand);
|
|
|
1170 |
pspm.setFofoId(fofoId);
|
|
|
1171 |
secondaryModelMap.put(brand, pspm);
|
| 31677 |
amit.gupta |
1172 |
}
|
| 31686 |
amit.gupta |
1173 |
ptam.setPartnerSecondaryModel(secondaryModelMap);
|
| 31677 |
amit.gupta |
1174 |
}
|
| 30077 |
tejbeer |
1175 |
|
| 31686 |
amit.gupta |
1176 |
if (!partnerTicketCount.isEmpty()) {
|
|
|
1177 |
if (partnerTicketCount.get(fofoId) != null) {
|
|
|
1178 |
ptam.setTicketCount(partnerTicketCount.get(fofoId));
|
|
|
1179 |
} else {
|
|
|
1180 |
ptam.setTicketCount(0);
|
|
|
1181 |
|
| 31677 |
amit.gupta |
1182 |
}
|
|
|
1183 |
}
|
| 30087 |
tejbeer |
1184 |
|
| 35632 |
ranu |
1185 |
// Category Assignment Logic (Priority: PLAN_TODAY > CARRY_FORWARD > ZERO_BILLED > UNTOUCHED > NORMAL)
|
|
|
1186 |
// Check if partner has credit due (loans > 15 days with pending amount) - just a flag, doesn't affect sorting
|
|
|
1187 |
boolean hasCreditDue = fofoIdsWithOverdueLoans.contains(fofoId);
|
|
|
1188 |
ptam.setHasOverdue(hasCreditDue);
|
|
|
1189 |
|
|
|
1190 |
// Default rank to 5 (Normal) if no collection plan exists
|
|
|
1191 |
int rank = ptam.getRank() > 0 ? ptam.getRank() : 5;
|
|
|
1192 |
boolean hasZeroBilling = !allMtdBilledFofoIds.contains(fofoId);
|
|
|
1193 |
|
|
|
1194 |
// Assign category based on rank (overdue is just a flag, doesn't affect category)
|
|
|
1195 |
if (rank == 1) {
|
|
|
1196 |
ptam.setCategory("PLAN_TODAY");
|
|
|
1197 |
ptam.setCategoryPriority(1);
|
|
|
1198 |
} else if (rank == 2) {
|
|
|
1199 |
ptam.setCategory("CARRY_FORWARD");
|
|
|
1200 |
ptam.setCategoryPriority(2);
|
|
|
1201 |
} else if (hasZeroBilling && rank < 5) {
|
|
|
1202 |
// Zero billed only if NOT in normal category (rank 5+)
|
|
|
1203 |
// If rank is 1,2,3,4 and has zero billing, include in ZERO_BILLED
|
|
|
1204 |
ptam.setCategory("ZERO_BILLED");
|
|
|
1205 |
ptam.setCategoryPriority(3);
|
|
|
1206 |
} else if (rank == 3) {
|
|
|
1207 |
ptam.setCategory("UNTOUCHED");
|
|
|
1208 |
ptam.setCategoryPriority(4);
|
|
|
1209 |
} else {
|
|
|
1210 |
// rank 4 (future plan) and rank 5+ (normal) go to NORMAL
|
|
|
1211 |
// Also, zero billing with rank 5+ goes to NORMAL (not ZERO_BILLED)
|
|
|
1212 |
ptam.setCategory("NORMAL");
|
|
|
1213 |
ptam.setCategoryPriority(5);
|
|
|
1214 |
}
|
|
|
1215 |
|
| 31686 |
amit.gupta |
1216 |
ptams.add(ptam);
|
| 30077 |
tejbeer |
1217 |
|
| 31677 |
amit.gupta |
1218 |
}
|
| 32923 |
ranu |
1219 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId()).stream().collect(Collectors.toList());
|
| 30077 |
tejbeer |
1220 |
|
| 32923 |
ranu |
1221 |
LOGGER.info("positions {}", positions);
|
|
|
1222 |
|
| 35079 |
vikas |
1223 |
boolean isRBMAndL1 = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId() && EscalationType.L1.equals(position.getEscalationType()));
|
| 36211 |
ranu |
1224 |
boolean isRBMAndL2 = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId() && EscalationType.L2.equals(position.getEscalationType()));
|
|
|
1225 |
boolean isRBMAndL3 = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId() && EscalationType.L3.equals(position.getEscalationType()));
|
| 35079 |
vikas |
1226 |
boolean isRBMAndNotL1 = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId() && !EscalationType.L1.equals(position.getEscalationType()));
|
| 32923 |
ranu |
1227 |
|
| 36211 |
ranu |
1228 |
LOGGER.info("isRBMAndL1{}, isRBMAndL2{}, isRBMAndL3{}", isRBMAndL1, isRBMAndL2, isRBMAndL3);
|
| 32923 |
ranu |
1229 |
|
| 35079 |
vikas |
1230 |
boolean isSales = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_SALES == position.getCategoryId());
|
| 32923 |
ranu |
1231 |
|
| 31686 |
amit.gupta |
1232 |
tm.setTotalPartnerTargetCollection(totalPartnerTargetCollection);
|
|
|
1233 |
tm.setTotalPartnerTargetSecondary(totalPartnerTargetSecondary);
|
|
|
1234 |
tm.setTotalPartnerSecondary(totalPartnerAchievementSecondary);
|
|
|
1235 |
tm.setTotalPartnerCollection(totalPartnerAchievementCollection);
|
|
|
1236 |
tm.setTodayCollectionCount((int) todayCollectionCount);
|
| 32923 |
ranu |
1237 |
List<PartnerTargetAchievementModel> filteredPtams;
|
| 30416 |
tejbeer |
1238 |
|
| 32923 |
ranu |
1239 |
if (isRBMAndL1) {
|
| 34428 |
ranu |
1240 |
filteredPtams = ptams;
|
|
|
1241 |
// as of now all party is showing to rbm
|
|
|
1242 |
/*filteredPtams = ptams.stream()
|
| 32978 |
amit.gupta |
1243 |
.filter(ptam -> !(CollectionRemark.RBM_L2_ESCALATION.equals(ptam.getRemark()) || CollectionRemark.SALES_ESCALATION.equals(ptam.getRemark())))
|
| 34428 |
ranu |
1244 |
.collect(Collectors.toList());*/
|
| 32923 |
ranu |
1245 |
} else if (isRBMAndNotL1) {
|
| 34429 |
ranu |
1246 |
filteredPtams = ptams;
|
|
|
1247 |
/*filteredPtams = ptams.stream()
|
| 32923 |
ranu |
1248 |
.filter(ptam -> !(CollectionRemark.SALES_ESCALATION.equals(ptam.getRemark())))
|
| 34429 |
ranu |
1249 |
.collect(Collectors.toList());*/
|
| 33041 |
ranu |
1250 |
} else if (isSales) {
|
|
|
1251 |
filteredPtams = ptams.stream()
|
| 36211 |
ranu |
1252 |
.filter(ptam -> !(CollectionRemark.RBM_L2_ESCALATION.equals(ptam.getRemark()) || CollectionRemark.RBM_L3_ESCALATION.equals(ptam.getRemark())))
|
| 33041 |
ranu |
1253 |
.collect(Collectors.toList());
|
| 32923 |
ranu |
1254 |
} else {
|
|
|
1255 |
filteredPtams = ptams;
|
|
|
1256 |
}
|
| 34428 |
ranu |
1257 |
tm.setRBMAndL1(isRBMAndL1);
|
| 36211 |
ranu |
1258 |
tm.setRBMAndL2(isRBMAndL2);
|
|
|
1259 |
tm.setRBMAndL3(isRBMAndL3);
|
| 34428 |
ranu |
1260 |
tm.setRBMAndNotL1(isRBMAndNotL1);
|
|
|
1261 |
tm.setSales(isSales);
|
| 35632 |
ranu |
1262 |
|
|
|
1263 |
// Calculate category counts
|
|
|
1264 |
Map<String, Long> categoryCounts = filteredPtams.stream()
|
|
|
1265 |
.collect(Collectors.groupingBy(
|
|
|
1266 |
p -> p.getCategory() != null ? p.getCategory() : "NORMAL",
|
|
|
1267 |
Collectors.counting()));
|
|
|
1268 |
// Count parties with overdue flag (independent of category)
|
|
|
1269 |
tm.setOverdueCount((int) filteredPtams.stream().filter(PartnerTargetAchievementModel::isHasOverdue).count());
|
|
|
1270 |
tm.setPlanTodayCount(categoryCounts.getOrDefault("PLAN_TODAY", 0L).intValue());
|
|
|
1271 |
tm.setCarryForwardCount(categoryCounts.getOrDefault("CARRY_FORWARD", 0L).intValue());
|
|
|
1272 |
tm.setZeroBilledCount(categoryCounts.getOrDefault("ZERO_BILLED", 0L).intValue());
|
|
|
1273 |
tm.setUntouchedCount(categoryCounts.getOrDefault("UNTOUCHED", 0L).intValue());
|
|
|
1274 |
tm.setNormalCount(categoryCounts.getOrDefault("NORMAL", 0L).intValue());
|
|
|
1275 |
|
|
|
1276 |
// Sort by: 1) Partners with today's remark go to bottom of entire list
|
| 35835 |
ranu |
1277 |
// EXCEPT: NO_ANSWER/SCHEDULE_CALL with scheduledCallTime reached → comes back up
|
| 35853 |
ranu |
1278 |
// EXCEPT: NO_ANSWER without scheduledCallTime older than 4 hours → comes back up
|
| 35632 |
ranu |
1279 |
// 2) Category Priority (PLAN_TODAY=1, CARRY_FORWARD=2, ZERO_BILLED=3, UNTOUCHED=4, NORMAL=5)
|
|
|
1280 |
// 3) Then by rank
|
| 35835 |
ranu |
1281 |
LocalDateTime now = LocalDateTime.now();
|
| 35853 |
ranu |
1282 |
LocalDateTime fourHoursAgo = now.minusHours(4);
|
| 34796 |
ranu |
1283 |
tm.setTargetAchievement(filteredPtams.stream()
|
|
|
1284 |
.sorted(Comparator
|
| 35632 |
ranu |
1285 |
.comparing((PartnerTargetAchievementModel p) -> {
|
|
|
1286 |
if (p.getRemarkTimestamp() == null) {
|
|
|
1287 |
return false; // No remark → comes first
|
|
|
1288 |
}
|
|
|
1289 |
LocalDate remarkDate = p.getRemarkTimestamp().toLocalDate();
|
|
|
1290 |
if (!remarkDate.equals(LocalDate.now())) {
|
|
|
1291 |
return false; // Not today's remark → comes first
|
|
|
1292 |
}
|
| 35835 |
ranu |
1293 |
// Check if SCHEDULE_CALL or NO_ANSWER with scheduledCallTime
|
|
|
1294 |
if (CollectionRemark.SCHEDULE_CALL.equals(p.getRemark()) || CollectionRemark.NO_ANSWER.equals(p.getRemark())) {
|
|
|
1295 |
if (p.getScheduledCallTime() != null) {
|
|
|
1296 |
// Has scheduled time - come up only when scheduled time is reached
|
|
|
1297 |
if (!p.getScheduledCallTime().isAfter(now)) {
|
|
|
1298 |
return false; // Scheduled time reached → comes back up
|
|
|
1299 |
}
|
|
|
1300 |
return true; // Scheduled time not reached → stays at bottom
|
|
|
1301 |
}
|
| 35853 |
ranu |
1302 |
// NO_ANSWER without scheduledCallTime - use 4 hour logic
|
| 35835 |
ranu |
1303 |
if (CollectionRemark.NO_ANSWER.equals(p.getRemark())
|
| 35853 |
ranu |
1304 |
&& p.getRemarkTimestamp().isBefore(fourHoursAgo)) {
|
|
|
1305 |
return false; // NO_ANSWER older than 4 hours → comes back up
|
| 35835 |
ranu |
1306 |
}
|
| 35632 |
ranu |
1307 |
}
|
|
|
1308 |
return true; // Other today's remarks → goes to bottom
|
|
|
1309 |
}) // false → comes first, true → goes to bottom
|
|
|
1310 |
.thenComparing(PartnerTargetAchievementModel::getCategoryPriority)
|
| 34796 |
ranu |
1311 |
.thenComparing(PartnerTargetAchievementModel::getRank)
|
|
|
1312 |
)
|
| 31686 |
amit.gupta |
1313 |
.collect(Collectors.toList()));
|
| 30416 |
tejbeer |
1314 |
|
| 34796 |
ranu |
1315 |
|
| 31677 |
amit.gupta |
1316 |
}
|
| 30077 |
tejbeer |
1317 |
|
| 31677 |
amit.gupta |
1318 |
}
|
| 35632 |
ranu |
1319 |
LOGGER.info("PERF: Total getPartnerTarget took {} ms", System.currentTimeMillis() - startTime);
|
| 31677 |
amit.gupta |
1320 |
return responseSender.ok(tm);
|
| 30077 |
tejbeer |
1321 |
|
| 31677 |
amit.gupta |
1322 |
}
|
| 32737 |
amit.gupta |
1323 |
|
| 35920 |
ranu |
1324 |
@RequestMapping(value = "/getInactivePartnerTarget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1325 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
1326 |
public ResponseEntity<?> getInactivePartnerTarget(HttpServletRequest request, @RequestParam String
|
|
|
1327 |
gmailId, @RequestParam String dayValue, @RequestParam ActivationType activationType) throws
|
|
|
1328 |
ProfitMandiBusinessException {
|
|
|
1329 |
|
|
|
1330 |
long startTime = System.currentTimeMillis();
|
|
|
1331 |
long lapTime = startTime;
|
|
|
1332 |
|
|
|
1333 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
|
|
1334 |
|
|
|
1335 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserInactivePartnerIdMapping();
|
|
|
1336 |
Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
|
|
|
1337 |
List<String> brands = Arrays.asList("Vivo", "Samsung", "Oppo", "Itel", "Almost New", "Others");
|
|
|
1338 |
|
|
|
1339 |
float totalPartnerTargetSecondary = 0;
|
|
|
1340 |
float totalPartnerTargetCollection = 0;
|
|
|
1341 |
float totalPartnerAchievementSecondary = 0;
|
|
|
1342 |
float totalPartnerAchievementCollection = 0;
|
|
|
1343 |
TargetModel tm = new TargetModel();
|
|
|
1344 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
|
|
|
1345 |
Map<Integer, Long> partnerTicketCount = new HashMap<>();
|
|
|
1346 |
|
|
|
1347 |
List<PartnerTargetAchievementModel> ptams = new ArrayList<>();
|
|
|
1348 |
|
|
|
1349 |
if (fofoIds != null && fofoIds.size() > 0) {
|
|
|
1350 |
LOGGER.info("fofoIds {}", fofoIds);
|
|
|
1351 |
// Get inactive stores for the given retailer IDs
|
|
|
1352 |
List<Integer> fofoIdList = fofoStoreRepository.selectByRetailerIds(new ArrayList<>(fofoIds)).stream()
|
|
|
1353 |
.filter(x -> (!x.isInternal()))
|
|
|
1354 |
.map(x -> x.getId()).collect(Collectors.toList());
|
|
|
1355 |
LOGGER.info("PERF: selectInActiveStore took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
1356 |
lapTime = System.currentTimeMillis();
|
|
|
1357 |
LOGGER.info("inactive fofoIdList size: {}", fofoIdList.size());
|
|
|
1358 |
|
|
|
1359 |
if (!fofoIdList.isEmpty()) {
|
|
|
1360 |
partnerTicketCount = ticketRepository.selectOpenTicketsCountByFofoIds(fofoIdList);
|
|
|
1361 |
}
|
|
|
1362 |
LOGGER.info("PERF: selectOpenTicketsCountByFofoIds took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
1363 |
lapTime = System.currentTimeMillis();
|
|
|
1364 |
LocalDateTime startDate = LocalDate.now().atStartOfDay();
|
|
|
1365 |
|
|
|
1366 |
if (dayValue.equals("previous")) {
|
|
|
1367 |
startDate = LocalDate.now().minusDays(1).atStartOfDay();
|
|
|
1368 |
}
|
|
|
1369 |
|
|
|
1370 |
if (fofoIdList.size() > 0) {
|
|
|
1371 |
|
|
|
1372 |
LocalDateTime fifteenDaysAgo = LocalDate.now().minusDays(15).atStartOfDay();
|
|
|
1373 |
Set<Integer> fofoIdsWithOverdueLoans = loanRepository.selectFofoIdsWithOverdueLoans(fofoIdList, fifteenDaysAgo);
|
|
|
1374 |
LOGGER.info("PERF: selectFofoIdsWithOverdueLoans took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
1375 |
lapTime = System.currentTimeMillis();
|
|
|
1376 |
|
|
|
1377 |
LocalDateTime mtdStartDate = LocalDate.now().withDayOfMonth(1).atStartOfDay();
|
|
|
1378 |
LocalDateTime mtdEndDate = LocalDate.now().plusDays(1).atStartOfDay();
|
|
|
1379 |
long billingThreshold = 1000L;
|
|
|
1380 |
Set<Integer> allMtdBilledFofoIds = orderRepository.selectFofoIdsWithMtdBillingAboveThreshold(
|
|
|
1381 |
fofoIdList, mtdStartDate, mtdEndDate, billingThreshold);
|
|
|
1382 |
LOGGER.info("PERF: selectFofoIdsWithMtdBillingAboveThreshold took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
1383 |
lapTime = System.currentTimeMillis();
|
|
|
1384 |
|
|
|
1385 |
List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository.selectAll(fofoIdList, startDate.toLocalDate().minusDays(1));
|
|
|
1386 |
LOGGER.info("PERF: partnerDailyInvestmentRepository.selectAll took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
1387 |
lapTime = System.currentTimeMillis();
|
|
|
1388 |
|
|
|
1389 |
if (!partnerDailyInvestments.isEmpty()) {
|
|
|
1390 |
partnerDailyInvestmentMap = partnerDailyInvestments.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
1391 |
}
|
|
|
1392 |
|
|
|
1393 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(fofoIdList);
|
|
|
1394 |
LOGGER.info("PERF: getFofoRetailers took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
1395 |
lapTime = System.currentTimeMillis();
|
|
|
1396 |
|
|
|
1397 |
List<Integer> remarkIds = partnerCollectionRemarkRepository.selectMaxRemarkId(fofoIdList);
|
|
|
1398 |
LOGGER.info("PERF: selectMaxRemarkId took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
1399 |
lapTime = System.currentTimeMillis();
|
|
|
1400 |
|
|
|
1401 |
long todayCollectionCount = 0;
|
|
|
1402 |
if (!remarkIds.isEmpty()) {
|
|
|
1403 |
todayCollectionCount = partnerCollectionRemarkRepository
|
|
|
1404 |
.selectByAuthIdAndIds(authUser.getId(), remarkIds).stream()
|
|
|
1405 |
.filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now()))
|
|
|
1406 |
.collect(Collectors.counting());
|
|
|
1407 |
}
|
|
|
1408 |
LOGGER.info("PERF: selectByAuthIdAndIds took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
1409 |
lapTime = System.currentTimeMillis();
|
|
|
1410 |
|
|
|
1411 |
Map<Integer, PartnerCollectionPlanModel> collectionMap = partnerCollectionService.getCollectionMap(fofoIdList, startDate);
|
|
|
1412 |
LOGGER.info("PERF: getCollectionMap took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
1413 |
lapTime = System.currentTimeMillis();
|
|
|
1414 |
|
|
|
1415 |
Map<Integer, List<PartnerSecondaryPlanModel>> partnerSecondaryPlans = orderRepository
|
|
|
1416 |
.selectPartnerSecondaryGroupByBrand(fofoIdList, startDate.toLocalDate()).stream()
|
|
|
1417 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
|
|
1418 |
LOGGER.info("PERF: selectPartnerSecondaryGroupByBrand took {} ms", System.currentTimeMillis() - lapTime);
|
|
|
1419 |
lapTime = System.currentTimeMillis();
|
|
|
1420 |
|
|
|
1421 |
Set<Integer> allAuthIds = new HashSet<>();
|
|
|
1422 |
collectionMap.values().stream()
|
|
|
1423 |
.map(PartnerCollectionPlanModel::getAuthId)
|
|
|
1424 |
.filter(id -> id != null && id != authUser.getId())
|
|
|
1425 |
.forEach(allAuthIds::add);
|
|
|
1426 |
partnerSecondaryPlans.values().stream()
|
|
|
1427 |
.flatMap(List::stream)
|
|
|
1428 |
.map(PartnerSecondaryPlanModel::getAuthId)
|
|
|
1429 |
.filter(id -> id != null && id != authUser.getId())
|
|
|
1430 |
.forEach(allAuthIds::add);
|
|
|
1431 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|
|
|
1432 |
if (!allAuthIds.isEmpty()) {
|
|
|
1433 |
authUserMap = authRepository.selectByIds(new ArrayList<>(allAuthIds)).stream()
|
|
|
1434 |
.collect(Collectors.toMap(AuthUser::getId, x -> x));
|
|
|
1435 |
}
|
|
|
1436 |
|
|
|
1437 |
LOGGER.info("partnerSecondayPlans {}", partnerSecondaryPlans);
|
|
|
1438 |
for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailers.entrySet()) {
|
|
|
1439 |
int fofoId = customRetailerEntry.getKey();
|
|
|
1440 |
CustomRetailer customRetailer = customRetailerEntry.getValue();
|
|
|
1441 |
float totalSecondaryPlan = 0;
|
|
|
1442 |
float totalSecondaryAchivement = 0;
|
|
|
1443 |
|
|
|
1444 |
PartnerTargetAchievementModel ptam = new PartnerTargetAchievementModel();
|
|
|
1445 |
ptam.setFofoId(fofoId);
|
|
|
1446 |
ptam.setBusinessName(customRetailer.getBusinessName());
|
|
|
1447 |
ptam.setMobile(customRetailer.getMobileNumber());
|
| 36211 |
ranu |
1448 |
ptam.setActivationType(customRetailer.getActivationType());
|
| 35920 |
ranu |
1449 |
|
|
|
1450 |
if (partnerDailyInvestmentMap.get(fofoId) != null) {
|
|
|
1451 |
ptam.setWalletAmount(partnerDailyInvestmentMap.get(fofoId).getWalletAmount());
|
|
|
1452 |
ptam.setShortInvestment(partnerDailyInvestmentMap.get(fofoId).getShortInvestment());
|
|
|
1453 |
}
|
|
|
1454 |
|
|
|
1455 |
if (collectionMap.get(fofoId) != null) {
|
|
|
1456 |
PartnerCollectionPlanModel collectionPlan = collectionMap.get(fofoId);
|
|
|
1457 |
|
|
|
1458 |
ptam.setRemark(collectionPlan.getRemark());
|
|
|
1459 |
ptam.setMessage(collectionPlan.getMessage());
|
|
|
1460 |
ptam.setRemarkTimestamp(collectionPlan.getRemarkTimestamp());
|
|
|
1461 |
ptam.setRecordingUrl(collectionPlan.getRecordingUrl());
|
|
|
1462 |
ptam.setScheduledCallTime(collectionPlan.getScheduledCallTime());
|
|
|
1463 |
ptam.setRank(collectionPlan.getRank());
|
|
|
1464 |
Integer authId = collectionPlan.getAuthId();
|
|
|
1465 |
|
|
|
1466 |
Map<Integer, String> rankColorMap = ProfitMandiConstants.Rank_Color_Map;
|
|
|
1467 |
ptam.setCollectionColor(rankColorMap.get(collectionPlan.getRank()));
|
|
|
1468 |
|
|
|
1469 |
LOGGER.info("authId" + authId);
|
|
|
1470 |
|
|
|
1471 |
if (collectionPlan.getTargetPlan() != null && collectionPlan.getCommittedDate() != null) {
|
|
|
1472 |
float targetCollection = 0;
|
|
|
1473 |
|
|
|
1474 |
if (collectionPlan.getRank() == 2 && collectionPlan.getAchievementPlan() != null) {
|
|
|
1475 |
targetCollection = collectionPlan.getTargetPlan() - collectionPlan.getAchievementPlan();
|
|
|
1476 |
} else {
|
|
|
1477 |
targetCollection = collectionPlan.getTargetPlan();
|
|
|
1478 |
}
|
|
|
1479 |
|
|
|
1480 |
if (authId != null && authId == authUser.getId()) {
|
|
|
1481 |
if (!collectionPlan.getCommittedDate().isAfter(startDate)) {
|
|
|
1482 |
totalPartnerTargetCollection += targetCollection;
|
|
|
1483 |
}
|
|
|
1484 |
}
|
|
|
1485 |
ptam.setCollectionTarget(targetCollection);
|
|
|
1486 |
if (collectionPlan.getRank() == 2 && collectionPlan.getAchievementPlan() != null
|
|
|
1487 |
&& collectionPlan.getWalletTimestamp() != null
|
|
|
1488 |
&& collectionPlan.getWalletTimestamp().toLocalDate().equals(startDate.toLocalDate())) {
|
|
|
1489 |
if (authId != null && authId == authUser.getId()) {
|
|
|
1490 |
totalPartnerAchievementCollection += collectionPlan.getAchievementPlan();
|
|
|
1491 |
}
|
|
|
1492 |
ptam.setCollectionAchievement(collectionPlan.getAchievementPlan());
|
|
|
1493 |
} else if (collectionPlan.getCommittedDate().toLocalDate().isEqual(startDate.toLocalDate())
|
|
|
1494 |
&& collectionPlan.getAchievementPlan() != null) {
|
|
|
1495 |
if (authId != null && authId == authUser.getId()) {
|
|
|
1496 |
totalPartnerAchievementCollection += collectionPlan.getAchievementPlan();
|
|
|
1497 |
}
|
|
|
1498 |
ptam.setCollectionAchievement(collectionPlan.getAchievementPlan());
|
|
|
1499 |
}
|
|
|
1500 |
}
|
|
|
1501 |
|
|
|
1502 |
if (authId != null && authId != authUser.getId()) {
|
|
|
1503 |
ptam.setAuthUser(authUserMap.get(authId));
|
|
|
1504 |
}
|
|
|
1505 |
|
|
|
1506 |
if (collectionPlan.getCommittedDate() != null) {
|
|
|
1507 |
ptam.setCollectionCommitmentDate(collectionPlan.getCommittedDate().toLocalDate());
|
|
|
1508 |
}
|
|
|
1509 |
}
|
|
|
1510 |
|
|
|
1511 |
PartnerSecondaryPlanModel otherPartnerSecondaryPlanModel = null;
|
|
|
1512 |
Map<String, PartnerSecondaryPlanModel> secondaryModelMap = new HashMap<>();
|
|
|
1513 |
if (partnerSecondaryPlans.get(fofoId) != null) {
|
|
|
1514 |
long otherBrandSecondary = 0;
|
|
|
1515 |
for (PartnerSecondaryPlanModel pspm : partnerSecondaryPlans.get(fofoId)) {
|
|
|
1516 |
Integer authId = pspm.getAuthId();
|
|
|
1517 |
if (!brands.contains(pspm.getBrand())) {
|
|
|
1518 |
if (pspm.getAchievementPlan() != null) {
|
|
|
1519 |
otherBrandSecondary += pspm.getAchievementPlan();
|
|
|
1520 |
}
|
|
|
1521 |
} else {
|
|
|
1522 |
otherPartnerSecondaryPlanModel = pspm;
|
|
|
1523 |
}
|
|
|
1524 |
if (pspm.getTargetPlan() != null) {
|
|
|
1525 |
totalSecondaryPlan += pspm.getTargetPlan();
|
|
|
1526 |
}
|
|
|
1527 |
|
|
|
1528 |
if (pspm.getAchievementPlan() != null) {
|
|
|
1529 |
totalSecondaryAchivement += pspm.getAchievementPlan();
|
|
|
1530 |
}
|
|
|
1531 |
|
|
|
1532 |
if (pspm.getCommittedDate() != null) {
|
|
|
1533 |
ptam.setSecondaryCommitmentDate(pspm.getCommittedDate().toLocalDate());
|
|
|
1534 |
}
|
|
|
1535 |
if (authId != null && authId == authUser.getId()) {
|
|
|
1536 |
if (pspm.getTargetPlan() != null && pspm.getCommittedDate() != null) {
|
|
|
1537 |
if (pspm.getCommittedDate().isEqual(startDate)) {
|
|
|
1538 |
totalPartnerTargetSecondary += pspm.getTargetPlan();
|
|
|
1539 |
}
|
|
|
1540 |
}
|
|
|
1541 |
|
|
|
1542 |
if (pspm.getAchievementPlan() != null) {
|
|
|
1543 |
totalPartnerAchievementSecondary += pspm.getAchievementPlan();
|
|
|
1544 |
}
|
|
|
1545 |
}
|
|
|
1546 |
}
|
|
|
1547 |
if (otherPartnerSecondaryPlanModel != null) {
|
|
|
1548 |
otherPartnerSecondaryPlanModel.setAchievementPlan(otherBrandSecondary);
|
|
|
1549 |
}
|
|
|
1550 |
secondaryModelMap = partnerSecondaryPlans.get(fofoId).stream()
|
|
|
1551 |
.filter(x -> brands.contains(x.getBrand()))
|
|
|
1552 |
.collect(Collectors.toMap(x -> x.getBrand(), x -> x));
|
|
|
1553 |
|
|
|
1554 |
if (secondaryModelMap.containsKey("Others")) {
|
|
|
1555 |
PartnerSecondaryPlanModel psp = secondaryModelMap.get("Others");
|
|
|
1556 |
psp.setAchievementPlan(otherBrandSecondary);
|
|
|
1557 |
} else {
|
|
|
1558 |
secondaryModelMap.put("Others", new PartnerSecondaryPlanModel(fofoId, "Others", (long) 0, otherBrandSecondary, authUser.getId(), null));
|
|
|
1559 |
}
|
|
|
1560 |
for (String brand : brands) {
|
|
|
1561 |
if (!secondaryModelMap.containsKey(brand)) {
|
|
|
1562 |
secondaryModelMap.put(brand, new PartnerSecondaryPlanModel(fofoId, brand, (long) 0, (long) 0, authUser.getId(), null));
|
|
|
1563 |
}
|
|
|
1564 |
}
|
|
|
1565 |
|
|
|
1566 |
for (Entry<String, PartnerSecondaryPlanModel> secondaryModelEntry : secondaryModelMap.entrySet()) {
|
|
|
1567 |
Integer authId = secondaryModelEntry.getValue().getAuthId();
|
|
|
1568 |
if (authId != null && authId != authUser.getId()) {
|
|
|
1569 |
secondaryModelEntry.getValue().setAuthUser(authUserMap.get(authId));
|
|
|
1570 |
ptam.setSecondaryColor("red");
|
|
|
1571 |
}
|
|
|
1572 |
}
|
|
|
1573 |
|
|
|
1574 |
ptam.setPartnerSecondaryModel(secondaryModelMap);
|
|
|
1575 |
ptam.setTotalSecondaryPlan(totalSecondaryPlan);
|
|
|
1576 |
ptam.setTotalSecondaryAchievement(totalSecondaryAchivement);
|
|
|
1577 |
|
|
|
1578 |
} else {
|
|
|
1579 |
for (String brand : brands) {
|
|
|
1580 |
PartnerSecondaryPlanModel pspm = new PartnerSecondaryPlanModel();
|
|
|
1581 |
pspm.setAchievementPlan((long) 0);
|
|
|
1582 |
pspm.setTargetPlan((long) 0);
|
|
|
1583 |
pspm.setBrand(brand);
|
|
|
1584 |
pspm.setFofoId(fofoId);
|
|
|
1585 |
secondaryModelMap.put(brand, pspm);
|
|
|
1586 |
}
|
|
|
1587 |
ptam.setPartnerSecondaryModel(secondaryModelMap);
|
|
|
1588 |
}
|
|
|
1589 |
|
|
|
1590 |
if (!partnerTicketCount.isEmpty()) {
|
|
|
1591 |
if (partnerTicketCount.get(fofoId) != null) {
|
|
|
1592 |
ptam.setTicketCount(partnerTicketCount.get(fofoId));
|
|
|
1593 |
} else {
|
|
|
1594 |
ptam.setTicketCount(0);
|
|
|
1595 |
}
|
|
|
1596 |
}
|
|
|
1597 |
|
|
|
1598 |
boolean hasCreditDue = fofoIdsWithOverdueLoans.contains(fofoId);
|
|
|
1599 |
ptam.setHasOverdue(hasCreditDue);
|
|
|
1600 |
|
|
|
1601 |
int rank = ptam.getRank() > 0 ? ptam.getRank() : 5;
|
|
|
1602 |
boolean hasZeroBilling = !allMtdBilledFofoIds.contains(fofoId);
|
|
|
1603 |
|
|
|
1604 |
if (rank == 1) {
|
|
|
1605 |
ptam.setCategory("PLAN_TODAY");
|
|
|
1606 |
ptam.setCategoryPriority(1);
|
|
|
1607 |
} else if (rank == 2) {
|
|
|
1608 |
ptam.setCategory("CARRY_FORWARD");
|
|
|
1609 |
ptam.setCategoryPriority(2);
|
|
|
1610 |
} else if (hasZeroBilling && rank < 5) {
|
|
|
1611 |
ptam.setCategory("ZERO_BILLED");
|
|
|
1612 |
ptam.setCategoryPriority(3);
|
|
|
1613 |
} else if (rank == 3) {
|
|
|
1614 |
ptam.setCategory("UNTOUCHED");
|
|
|
1615 |
ptam.setCategoryPriority(4);
|
|
|
1616 |
} else {
|
|
|
1617 |
ptam.setCategory("NORMAL");
|
|
|
1618 |
ptam.setCategoryPriority(5);
|
|
|
1619 |
}
|
|
|
1620 |
|
|
|
1621 |
ptams.add(ptam);
|
|
|
1622 |
}
|
|
|
1623 |
|
|
|
1624 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId()).stream().collect(Collectors.toList());
|
|
|
1625 |
LOGGER.info("positions {}", positions);
|
|
|
1626 |
|
|
|
1627 |
boolean isRBMAndL1 = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId() && EscalationType.L1.equals(position.getEscalationType()));
|
| 36211 |
ranu |
1628 |
boolean isRBMAndL2 = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId() && EscalationType.L2.equals(position.getEscalationType()));
|
|
|
1629 |
boolean isRBMAndL3 = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId() && EscalationType.L3.equals(position.getEscalationType()));
|
| 35920 |
ranu |
1630 |
boolean isRBMAndNotL1 = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId() && !EscalationType.L1.equals(position.getEscalationType()));
|
| 36211 |
ranu |
1631 |
LOGGER.info("isRBMAndL1{}, isRBMAndL2{}, isRBMAndL3{}", isRBMAndL1, isRBMAndL2, isRBMAndL3);
|
| 35920 |
ranu |
1632 |
|
|
|
1633 |
boolean isSales = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_SALES == position.getCategoryId());
|
|
|
1634 |
|
|
|
1635 |
tm.setTotalPartnerTargetCollection(totalPartnerTargetCollection);
|
|
|
1636 |
tm.setTotalPartnerTargetSecondary(totalPartnerTargetSecondary);
|
|
|
1637 |
tm.setTotalPartnerSecondary(totalPartnerAchievementSecondary);
|
|
|
1638 |
tm.setTotalPartnerCollection(totalPartnerAchievementCollection);
|
|
|
1639 |
tm.setTodayCollectionCount((int) todayCollectionCount);
|
|
|
1640 |
List<PartnerTargetAchievementModel> filteredPtams;
|
|
|
1641 |
|
|
|
1642 |
if (isRBMAndL1) {
|
|
|
1643 |
filteredPtams = ptams;
|
|
|
1644 |
} else if (isRBMAndNotL1) {
|
|
|
1645 |
filteredPtams = ptams;
|
|
|
1646 |
} else if (isSales) {
|
|
|
1647 |
filteredPtams = ptams.stream()
|
| 36211 |
ranu |
1648 |
.filter(ptam -> !(CollectionRemark.RBM_L2_ESCALATION.equals(ptam.getRemark()) || CollectionRemark.RBM_L3_ESCALATION.equals(ptam.getRemark())))
|
| 35920 |
ranu |
1649 |
.collect(Collectors.toList());
|
|
|
1650 |
} else {
|
|
|
1651 |
filteredPtams = ptams;
|
|
|
1652 |
}
|
|
|
1653 |
tm.setRBMAndL1(isRBMAndL1);
|
| 36211 |
ranu |
1654 |
tm.setRBMAndL2(isRBMAndL2);
|
|
|
1655 |
tm.setRBMAndL3(isRBMAndL3);
|
| 35920 |
ranu |
1656 |
tm.setRBMAndNotL1(isRBMAndNotL1);
|
|
|
1657 |
tm.setSales(isSales);
|
|
|
1658 |
|
|
|
1659 |
Map<String, Long> categoryCounts = filteredPtams.stream()
|
|
|
1660 |
.collect(Collectors.groupingBy(
|
|
|
1661 |
p -> p.getCategory() != null ? p.getCategory() : "NORMAL",
|
|
|
1662 |
Collectors.counting()));
|
|
|
1663 |
tm.setOverdueCount((int) filteredPtams.stream().filter(PartnerTargetAchievementModel::isHasOverdue).count());
|
|
|
1664 |
tm.setPlanTodayCount(categoryCounts.getOrDefault("PLAN_TODAY", 0L).intValue());
|
|
|
1665 |
tm.setCarryForwardCount(categoryCounts.getOrDefault("CARRY_FORWARD", 0L).intValue());
|
|
|
1666 |
tm.setZeroBilledCount(categoryCounts.getOrDefault("ZERO_BILLED", 0L).intValue());
|
|
|
1667 |
tm.setUntouchedCount(categoryCounts.getOrDefault("UNTOUCHED", 0L).intValue());
|
|
|
1668 |
tm.setNormalCount(categoryCounts.getOrDefault("NORMAL", 0L).intValue());
|
|
|
1669 |
|
|
|
1670 |
LocalDateTime now = LocalDateTime.now();
|
|
|
1671 |
LocalDateTime fourHoursAgo = now.minusHours(4);
|
|
|
1672 |
tm.setTargetAchievement(filteredPtams.stream()
|
|
|
1673 |
.sorted(Comparator
|
|
|
1674 |
.comparing((PartnerTargetAchievementModel p) -> {
|
|
|
1675 |
if (p.getRemarkTimestamp() == null) {
|
|
|
1676 |
return false;
|
|
|
1677 |
}
|
|
|
1678 |
LocalDate remarkDate = p.getRemarkTimestamp().toLocalDate();
|
|
|
1679 |
if (!remarkDate.equals(LocalDate.now())) {
|
|
|
1680 |
return false;
|
|
|
1681 |
}
|
|
|
1682 |
if (CollectionRemark.SCHEDULE_CALL.equals(p.getRemark()) || CollectionRemark.NO_ANSWER.equals(p.getRemark())) {
|
|
|
1683 |
if (p.getScheduledCallTime() != null) {
|
|
|
1684 |
if (!p.getScheduledCallTime().isAfter(now)) {
|
|
|
1685 |
return false;
|
|
|
1686 |
}
|
|
|
1687 |
return true;
|
|
|
1688 |
}
|
|
|
1689 |
if (CollectionRemark.NO_ANSWER.equals(p.getRemark())
|
|
|
1690 |
&& p.getRemarkTimestamp().isBefore(fourHoursAgo)) {
|
|
|
1691 |
return false;
|
|
|
1692 |
}
|
|
|
1693 |
}
|
|
|
1694 |
return true;
|
|
|
1695 |
})
|
|
|
1696 |
.thenComparing(PartnerTargetAchievementModel::getCategoryPriority)
|
|
|
1697 |
.thenComparing(PartnerTargetAchievementModel::getRank)
|
|
|
1698 |
)
|
|
|
1699 |
.collect(Collectors.toList()));
|
|
|
1700 |
}
|
|
|
1701 |
}
|
|
|
1702 |
LOGGER.info("PERF: Total getInactivePartnerTarget took {} ms", System.currentTimeMillis() - startTime);
|
|
|
1703 |
return responseSender.ok(tm);
|
|
|
1704 |
|
|
|
1705 |
}
|
|
|
1706 |
|
| 32737 |
amit.gupta |
1707 |
//TODO:Amit
|
| 31677 |
amit.gupta |
1708 |
@RequestMapping(value = "/target", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35079 |
vikas |
1709 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 31677 |
amit.gupta |
1710 |
public ResponseEntity<?> createPartnerTarget(HttpServletRequest request,
|
|
|
1711 |
@RequestBody PartnerTargetAchievementModel ptam) throws ProfitMandiBusinessException {
|
| 30077 |
tejbeer |
1712 |
|
| 31677 |
amit.gupta |
1713 |
LOGGER.info("ptam" + ptam);
|
| 30089 |
tejbeer |
1714 |
|
| 31677 |
amit.gupta |
1715 |
AuthUser authUser = authRepository.selectByGmailId(ptam.getCreatedBy());
|
| 30077 |
tejbeer |
1716 |
|
| 31677 |
amit.gupta |
1717 |
if (ptam.getCollectionCommitmentDate().isAfter(LocalDate.now())
|
|
|
1718 |
|| ptam.getCollectionCommitmentDate().isEqual(LocalDate.now())) {
|
|
|
1719 |
PartnerCollectionPlan partnerCollectionPlan = partnerCollectionPlanRepository
|
|
|
1720 |
.selectByLocalDate(LocalDate.now(), ptam.getFofoId(), true);
|
|
|
1721 |
LOGGER.info("pcp" + partnerCollectionPlan);
|
| 30077 |
tejbeer |
1722 |
|
| 31677 |
amit.gupta |
1723 |
if (partnerCollectionPlan == null) {
|
|
|
1724 |
if (ptam.getCollectionTarget() > 0) {
|
| 30087 |
tejbeer |
1725 |
|
| 31677 |
amit.gupta |
1726 |
partnerCollectionPlan = new PartnerCollectionPlan();
|
|
|
1727 |
partnerCollectionPlan.setCreateTimestamp(LocalDateTime.now());
|
|
|
1728 |
partnerCollectionPlan.setAuthId(authUser.getId());
|
|
|
1729 |
partnerCollectionPlan.setFofoId(ptam.getFofoId());
|
|
|
1730 |
partnerCollectionPlan.setActive(true);
|
|
|
1731 |
partnerCollectionPlan.setCollectionPlan(ptam.getCollectionTarget());
|
|
|
1732 |
partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1733 |
partnerCollectionPlan.setCommitedTimestamp(ptam.getCollectionCommitmentDate().atStartOfDay());
|
|
|
1734 |
partnerCollectionPlanRepository.persist(partnerCollectionPlan);
|
| 30416 |
tejbeer |
1735 |
|
| 31677 |
amit.gupta |
1736 |
}
|
| 30087 |
tejbeer |
1737 |
|
| 31677 |
amit.gupta |
1738 |
} else {
|
| 30087 |
tejbeer |
1739 |
|
| 31677 |
amit.gupta |
1740 |
if (partnerCollectionPlan.getCollectionPlan() != ptam.getCollectionTarget()) {
|
|
|
1741 |
float totalCollectionPlan = partnerCollectionPlan.getCollectionPlan() + 10000;
|
|
|
1742 |
if (authUser.getId() == partnerCollectionPlan.getAuthId()) {
|
| 30087 |
tejbeer |
1743 |
|
| 31677 |
amit.gupta |
1744 |
if (authUser.getEmailId().equals("tarun.verma@smartdukaan.com")
|
|
|
1745 |
|| authUser.getEmailId().equals("rakesh.sonawane@smartdukaan.com")
|
|
|
1746 |
|| ptam.getCollectionTarget() >= totalCollectionPlan) {
|
|
|
1747 |
partnerCollectionPlan.setCollectionPlan(ptam.getCollectionTarget());
|
|
|
1748 |
partnerCollectionPlan.setActive(true);
|
|
|
1749 |
partnerCollectionPlan
|
|
|
1750 |
.setCommitedTimestamp(ptam.getCollectionCommitmentDate().atStartOfDay());
|
|
|
1751 |
partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1752 |
} else {
|
|
|
1753 |
throw new ProfitMandiBusinessException("collection target", "",
|
|
|
1754 |
"collection target should be more than " + totalCollectionPlan);
|
|
|
1755 |
}
|
| 30087 |
tejbeer |
1756 |
|
| 31677 |
amit.gupta |
1757 |
} else {
|
| 30137 |
tejbeer |
1758 |
|
| 31677 |
amit.gupta |
1759 |
if (authUser.getEmailId().equals("tarun.verma@smartdukaan.com")
|
|
|
1760 |
|| authUser.getEmailId().equals("rakesh.sonawane@smartdukaan.com")
|
|
|
1761 |
|| ptam.getCollectionTarget() >= totalCollectionPlan) {
|
| 30137 |
tejbeer |
1762 |
|
| 31677 |
amit.gupta |
1763 |
partnerCollectionPlan.setActive(false);
|
|
|
1764 |
partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1765 |
partnerCollectionPlan = new PartnerCollectionPlan();
|
|
|
1766 |
partnerCollectionPlan.setCreateTimestamp(LocalDateTime.now());
|
|
|
1767 |
partnerCollectionPlan.setAuthId(authUser.getId());
|
|
|
1768 |
partnerCollectionPlan.setFofoId(ptam.getFofoId());
|
|
|
1769 |
partnerCollectionPlan.setActive(true);
|
|
|
1770 |
partnerCollectionPlan
|
|
|
1771 |
.setCommitedTimestamp(ptam.getSecondaryCommitmentDate().atStartOfDay());
|
|
|
1772 |
partnerCollectionPlan.setCollectionPlan(ptam.getCollectionTarget());
|
|
|
1773 |
partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1774 |
partnerCollectionPlanRepository.persist(partnerCollectionPlan);
|
|
|
1775 |
} else {
|
|
|
1776 |
throw new ProfitMandiBusinessException("collection target", "",
|
|
|
1777 |
"collection target should be more than " + totalCollectionPlan);
|
|
|
1778 |
}
|
|
|
1779 |
}
|
|
|
1780 |
}
|
| 30137 |
tejbeer |
1781 |
|
| 31677 |
amit.gupta |
1782 |
if ((LocalDate.now().atStartOfDay().equals(ptam.getCollectionCommitmentDate().atStartOfDay())
|
|
|
1783 |
|| ptam.getCollectionCommitmentDate().atStartOfDay().isAfter(LocalDate.now().atStartOfDay()))
|
|
|
1784 |
&& partnerCollectionPlan.getCollectionPlan() == ptam.getCollectionTarget()) {
|
|
|
1785 |
partnerCollectionPlan.setCommitedTimestamp(ptam.getCollectionCommitmentDate().atStartOfDay());
|
|
|
1786 |
partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1787 |
}
|
| 30416 |
tejbeer |
1788 |
|
| 31677 |
amit.gupta |
1789 |
}
|
| 30433 |
tejbeer |
1790 |
|
| 35725 |
ranu |
1791 |
long callLogId = recordingService.getLatestAgentCallLog(ptam.getFofoId(),authUser.getId());
|
|
|
1792 |
|
| 31677 |
amit.gupta |
1793 |
PartnerCollectionRemark pcr = new PartnerCollectionRemark();
|
|
|
1794 |
pcr.setFofoId(ptam.getFofoId());
|
|
|
1795 |
pcr.setAuthId(authUser.getId());
|
|
|
1796 |
pcr.setMessage("Collection plan for" + ptam.getCollectionCommitmentDate());
|
|
|
1797 |
pcr.setRemark(CollectionRemark.COLLECTION_PLAN);
|
| 35725 |
ranu |
1798 |
pcr.setAgentCallLogId(callLogId);
|
| 31677 |
amit.gupta |
1799 |
pcr.setCreateTimestamp(LocalDateTime.now());
|
|
|
1800 |
partnerCollectionRemarkRepository.persist(pcr);
|
|
|
1801 |
} else {
|
|
|
1802 |
throw new ProfitMandiBusinessException("Date", "",
|
|
|
1803 |
"you can't select the back date " + ptam.getCollectionCommitmentDate());
|
|
|
1804 |
}
|
| 30077 |
tejbeer |
1805 |
|
| 31677 |
amit.gupta |
1806 |
for (Entry<String, PartnerSecondaryPlanModel> pspm : ptam.getPartnerSecondaryModel().entrySet()) {
|
| 30087 |
tejbeer |
1807 |
|
| 31677 |
amit.gupta |
1808 |
if (ptam.getCollectionCommitmentDate().isAfter(LocalDate.now())
|
|
|
1809 |
|| ptam.getCollectionCommitmentDate().isEqual(LocalDate.now())) {
|
|
|
1810 |
PartnerSecondaryPlanModel plan = pspm.getValue();
|
|
|
1811 |
PartnerSecondaryPlan psp = partnerSecondaryPlanRepository.selectByLocalDateBrand(plan.getBrand(),
|
|
|
1812 |
LocalDate.now(), ptam.getFofoId(), true);
|
|
|
1813 |
LOGGER.info("psp" + psp);
|
| 30087 |
tejbeer |
1814 |
|
| 31677 |
amit.gupta |
1815 |
if (psp == null) {
|
|
|
1816 |
if (plan.getTargetPlan() != null && plan.getTargetPlan() > 0) {
|
| 30087 |
tejbeer |
1817 |
|
| 31677 |
amit.gupta |
1818 |
psp = new PartnerSecondaryPlan();
|
|
|
1819 |
psp.setAuthId(authUser.getId());
|
|
|
1820 |
psp.setBrand(pspm.getKey());
|
|
|
1821 |
psp.setFofoId(pspm.getValue().getFofoId());
|
|
|
1822 |
psp.setSecondaryPlan(pspm.getValue().getTargetPlan());
|
|
|
1823 |
psp.setCreateTimestamp(LocalDateTime.now());
|
|
|
1824 |
psp.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1825 |
psp.setCommitedTimestamp(ptam.getSecondaryCommitmentDate().atStartOfDay());
|
|
|
1826 |
psp.setActive(true);
|
|
|
1827 |
partnerSecondaryPlanRepository.persist(psp);
|
|
|
1828 |
}
|
| 30087 |
tejbeer |
1829 |
|
| 31677 |
amit.gupta |
1830 |
} else {
|
|
|
1831 |
if (plan.getTargetPlan() != psp.getSecondaryPlan()) {
|
|
|
1832 |
float totalSecondaryPlan = psp.getSecondaryPlan() + 10000;
|
|
|
1833 |
if (authUser.getId() == plan.getAuthId()) {
|
|
|
1834 |
if (authUser.getEmailId().equals("tarun.verma@smartdukaan.com")
|
|
|
1835 |
|| authUser.getEmailId().equals("rakesh.sonawane@smartdukaan.com")
|
|
|
1836 |
|| plan.getTargetPlan() >= totalSecondaryPlan) {
|
|
|
1837 |
psp.setSecondaryPlan(pspm.getValue().getTargetPlan());
|
|
|
1838 |
psp.setCommitedTimestamp(ptam.getSecondaryCommitmentDate().atStartOfDay());
|
|
|
1839 |
psp.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1840 |
psp.setActive(true);
|
|
|
1841 |
} else {
|
|
|
1842 |
throw new ProfitMandiBusinessException("secondary target", "",
|
|
|
1843 |
"secondary target should be more than " + totalSecondaryPlan);
|
|
|
1844 |
}
|
| 30087 |
tejbeer |
1845 |
|
| 31677 |
amit.gupta |
1846 |
} else {
|
| 30087 |
tejbeer |
1847 |
|
| 31677 |
amit.gupta |
1848 |
if (authUser.getEmailId().equals("tarun.verma@smartdukaan.com")
|
|
|
1849 |
|| authUser.getEmailId().equals("rakesh.sonawane@smartdukaan.com")
|
|
|
1850 |
|| plan.getTargetPlan() >= totalSecondaryPlan) {
|
| 30087 |
tejbeer |
1851 |
|
| 31677 |
amit.gupta |
1852 |
psp.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1853 |
psp.setActive(false);
|
|
|
1854 |
psp = new PartnerSecondaryPlan();
|
|
|
1855 |
psp.setAuthId(authUser.getId());
|
|
|
1856 |
psp.setBrand(pspm.getKey());
|
|
|
1857 |
psp.setFofoId(pspm.getValue().getFofoId());
|
|
|
1858 |
psp.setSecondaryPlan(pspm.getValue().getTargetPlan());
|
|
|
1859 |
psp.setCommitedTimestamp(ptam.getSecondaryCommitmentDate().atStartOfDay());
|
|
|
1860 |
psp.setCreateTimestamp(LocalDateTime.now());
|
|
|
1861 |
psp.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1862 |
psp.setActive(true);
|
|
|
1863 |
partnerSecondaryPlanRepository.persist(psp);
|
|
|
1864 |
} else {
|
|
|
1865 |
throw new ProfitMandiBusinessException("secondary target", "",
|
|
|
1866 |
"secondary target should be more than " + totalSecondaryPlan);
|
|
|
1867 |
}
|
|
|
1868 |
}
|
|
|
1869 |
}
|
| 30137 |
tejbeer |
1870 |
|
| 31677 |
amit.gupta |
1871 |
if ((LocalDate.now().atStartOfDay().equals(ptam.getSecondaryCommitmentDate().atStartOfDay())
|
|
|
1872 |
|| ptam.getSecondaryCommitmentDate().atStartOfDay().isAfter(LocalDate.now().atStartOfDay()))
|
|
|
1873 |
&& plan.getTargetPlan() == psp.getSecondaryPlan()) {
|
|
|
1874 |
psp.setCommitedTimestamp(ptam.getSecondaryCommitmentDate().atStartOfDay());
|
|
|
1875 |
psp.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1876 |
}
|
| 30137 |
tejbeer |
1877 |
|
| 31677 |
amit.gupta |
1878 |
}
|
|
|
1879 |
} else {
|
|
|
1880 |
throw new ProfitMandiBusinessException("Date", "",
|
|
|
1881 |
"you can't select the back date " + ptam.getSecondaryCommitmentDate());
|
|
|
1882 |
}
|
| 30137 |
tejbeer |
1883 |
|
| 31677 |
amit.gupta |
1884 |
}
|
| 30077 |
tejbeer |
1885 |
|
| 31677 |
amit.gupta |
1886 |
return responseSender.ok(true);
|
| 30137 |
tejbeer |
1887 |
|
| 31677 |
amit.gupta |
1888 |
}
|
| 30077 |
tejbeer |
1889 |
|
| 31677 |
amit.gupta |
1890 |
@RequestMapping(value = "/uploadFranchiseeVisit", method = RequestMethod.POST)
|
| 35288 |
amit |
1891 |
public ResponseEntity<?> readCsvFileAndSetLead(HttpServletRequest request, @RequestPart MultipartFile
|
|
|
1892 |
multipartFile) throws Throwable {
|
| 30433 |
tejbeer |
1893 |
|
| 31677 |
amit.gupta |
1894 |
int id = (int) request.getAttribute("userId");
|
| 30433 |
tejbeer |
1895 |
|
| 31677 |
amit.gupta |
1896 |
LOGGER.info("id" + id);
|
| 30433 |
tejbeer |
1897 |
|
| 31677 |
amit.gupta |
1898 |
User user = userRepository.selectById(id);
|
| 30433 |
tejbeer |
1899 |
|
| 31677 |
amit.gupta |
1900 |
AuthUser authUser = authRepository.selectByEmailOrMobile(user.getEmailId());
|
| 30433 |
tejbeer |
1901 |
|
| 31677 |
amit.gupta |
1902 |
String fileName = multipartFile.getName();
|
|
|
1903 |
String fileNames = multipartFile.getOriginalFilename();
|
| 30433 |
tejbeer |
1904 |
|
| 31677 |
amit.gupta |
1905 |
LOGGER.info("fileName" + fileName);
|
|
|
1906 |
LOGGER.info("fileNames" + fileNames);
|
| 30433 |
tejbeer |
1907 |
|
| 31677 |
amit.gupta |
1908 |
List<CSVRecord> records = FileUtil.readFile(multipartFile);
|
| 30433 |
tejbeer |
1909 |
|
| 31677 |
amit.gupta |
1910 |
for (CSVRecord record : records) {
|
|
|
1911 |
FranchiseeVisit franchiseeVisit = new FranchiseeVisit();
|
|
|
1912 |
franchiseeVisit.setFofoId(Integer.parseInt(record.get(0)));
|
|
|
1913 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(Integer.parseInt(record.get(0)));
|
| 30433 |
tejbeer |
1914 |
|
| 31677 |
amit.gupta |
1915 |
franchiseeVisit.setPartnerName(customRetailer.getBusinessName());
|
|
|
1916 |
franchiseeVisit.setAgenda(record.get(1));
|
|
|
1917 |
franchiseeVisit.setCreatedTimestamp(LocalDateTime.now());
|
|
|
1918 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1919 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.OPEN);
|
| 30433 |
tejbeer |
1920 |
|
| 31677 |
amit.gupta |
1921 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
|
|
|
1922 |
LOGGER.info(record.get(1));
|
|
|
1923 |
LocalDate dateTime = LocalDate.parse(record.get(2), formatter);
|
| 30433 |
tejbeer |
1924 |
|
| 31677 |
amit.gupta |
1925 |
franchiseeVisit.setScheduleTimestamp(dateTime.atStartOfDay());
|
|
|
1926 |
// change
|
| 30433 |
tejbeer |
1927 |
|
| 31677 |
amit.gupta |
1928 |
String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
1929 |
franchiseeVisit.setCreatedBy(authUserName);
|
|
|
1930 |
franchiseeVisit.setAuthId(authUser.getId());
|
| 30433 |
tejbeer |
1931 |
|
| 31677 |
amit.gupta |
1932 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| 30433 |
tejbeer |
1933 |
|
| 31677 |
amit.gupta |
1934 |
return responseSender.ok(true);
|
|
|
1935 |
}
|
| 30433 |
tejbeer |
1936 |
|
| 31677 |
amit.gupta |
1937 |
return responseSender.ok(true);
|
| 30433 |
tejbeer |
1938 |
|
| 31677 |
amit.gupta |
1939 |
}
|
| 30487 |
tejbeer |
1940 |
|
| 31677 |
amit.gupta |
1941 |
@RequestMapping(value = "/downloadFranchiseeVisitTemplate", method = RequestMethod.GET)
|
|
|
1942 |
public ResponseEntity<?> downloadFranchiseeVisitTemplate(HttpServletRequest request) throws Exception {
|
| 30487 |
tejbeer |
1943 |
|
| 31677 |
amit.gupta |
1944 |
// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| 30487 |
tejbeer |
1945 |
|
| 31677 |
amit.gupta |
1946 |
List<List<?>> rows = new ArrayList<>();
|
| 30487 |
tejbeer |
1947 |
|
| 32923 |
ranu |
1948 |
ByteArrayOutputStream byteArrayOutputStream = FileUtil
|
| 31677 |
amit.gupta |
1949 |
.getCSVByteStream(Arrays.asList("Partner Id", "Agenda", "Schedule Timestamp"), rows);
|
| 30487 |
tejbeer |
1950 |
|
| 31677 |
amit.gupta |
1951 |
try {
|
|
|
1952 |
byteArrayOutputStream.close();
|
|
|
1953 |
} catch (IOException e) {
|
|
|
1954 |
// TODO Auto-generated catch block
|
|
|
1955 |
e.printStackTrace();
|
|
|
1956 |
}
|
| 30487 |
tejbeer |
1957 |
|
| 31677 |
amit.gupta |
1958 |
String filename = "template.csv";
|
|
|
1959 |
HttpHeaders headers = new HttpHeaders();
|
|
|
1960 |
headers.add("Content-Type", "application/csv");
|
|
|
1961 |
headers.setContentDispositionFormData(filename, filename);
|
| 30487 |
tejbeer |
1962 |
|
| 31677 |
amit.gupta |
1963 |
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
|
| 30487 |
tejbeer |
1964 |
|
| 31677 |
amit.gupta |
1965 |
ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(byteArrayOutputStream.toByteArray(), headers,
|
|
|
1966 |
HttpStatus.OK);
|
|
|
1967 |
return response;
|
| 30544 |
tejbeer |
1968 |
|
| 31677 |
amit.gupta |
1969 |
}
|
| 30542 |
tejbeer |
1970 |
|
| 31677 |
amit.gupta |
1971 |
@RequestMapping(value = "/markVisitAttendance", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1972 |
public ResponseEntity<?> markVisitAttendance(HttpServletRequest request, @RequestParam(name = "id") int id)
|
|
|
1973 |
throws ProfitMandiBusinessException {
|
|
|
1974 |
FranchiseeVisit franchiseeVisit = franchiseeVisitRepository.selectById(id);
|
| 30542 |
tejbeer |
1975 |
|
| 31677 |
amit.gupta |
1976 |
franchiseeVisit.setVisitTimestamp(LocalDateTime.now());
|
| 30542 |
tejbeer |
1977 |
|
| 31677 |
amit.gupta |
1978 |
return responseSender.ok(true);
|
| 30542 |
tejbeer |
1979 |
|
| 31677 |
amit.gupta |
1980 |
}
|
| 31249 |
tejbeer |
1981 |
|
| 31677 |
amit.gupta |
1982 |
@RequestMapping(value = "/getVisitRequests", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1983 |
public ResponseEntity<?> getVisitRequests(HttpServletRequest request,
|
|
|
1984 |
@RequestParam(name = "gmailId") String gmailId, Model model) throws Exception {
|
| 31249 |
tejbeer |
1985 |
|
| 31677 |
amit.gupta |
1986 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
| 31249 |
tejbeer |
1987 |
|
| 31677 |
amit.gupta |
1988 |
List<Integer> authUserIds = authService.getAllReportees(authUser.getId());
|
|
|
1989 |
List<VisitSummaryModel> visitSummary = new ArrayList<>();
|
| 31249 |
tejbeer |
1990 |
|
| 31677 |
amit.gupta |
1991 |
if (!authUserIds.isEmpty()) {
|
| 35397 |
amit |
1992 |
List<AuthUser> authUsers = authRepository.selectByIds(authUserIds);
|
| 31249 |
tejbeer |
1993 |
|
| 31677 |
amit.gupta |
1994 |
List<VisitRequest> allVisitRequests = visitRequestRepository.selectByAuthIdsAndDate(authUserIds,
|
|
|
1995 |
LocalDate.now().minusDays(7), Arrays.asList(VisitStatus.approved, VisitStatus.pending));
|
|
|
1996 |
LOGGER.info("allVisitRequests {}", allVisitRequests);
|
| 31249 |
tejbeer |
1997 |
|
| 31677 |
amit.gupta |
1998 |
if (!allVisitRequests.isEmpty()) {
|
| 31249 |
tejbeer |
1999 |
|
| 31677 |
amit.gupta |
2000 |
List<Integer> leadIds = allVisitRequests.stream().filter(x -> x.getVisitType().equals("lead"))
|
|
|
2001 |
.map(x -> x.getVisitId()).collect(Collectors.toList());
|
|
|
2002 |
List<Lead> leads = new ArrayList<>();
|
|
|
2003 |
if (!leadIds.isEmpty()) {
|
|
|
2004 |
leads = leadRepository.selectAllByIds(leadIds);
|
| 31249 |
tejbeer |
2005 |
|
| 35415 |
amit |
2006 |
// Batch fetch all LeadActivities instead of N+1
|
|
|
2007 |
List<LeadActivity> allLeadActivities = leadActivityRepository.selectAllByleadIds(leadIds);
|
|
|
2008 |
Map<Integer, List<LeadActivity>> leadActivityMap = allLeadActivities.stream()
|
|
|
2009 |
.collect(Collectors.groupingBy(LeadActivity::getLeadId));
|
|
|
2010 |
|
| 31677 |
amit.gupta |
2011 |
for (Lead lead : leads) {
|
| 35415 |
amit |
2012 |
List<LeadActivity> leadActivities = leadActivityMap.get(lead.getId());
|
|
|
2013 |
if (leadActivities != null && !leadActivities.isEmpty()) {
|
|
|
2014 |
lead.setScheduledTimestamp(leadActivities.get(0).getSchelduleTimestamp());
|
|
|
2015 |
lead.setLeadActivity(leadActivities.get(0));
|
|
|
2016 |
}
|
| 31677 |
amit.gupta |
2017 |
}
|
|
|
2018 |
}
|
|
|
2019 |
List<Integer> franchiseeIds = allVisitRequests.stream()
|
|
|
2020 |
.filter(x -> x.getVisitType().equals("franchiseeVisit")).map(x -> x.getVisitId())
|
|
|
2021 |
.collect(Collectors.toList());
|
|
|
2022 |
List<FranchiseeVisit> franchiseeVisits = new ArrayList<>();
|
|
|
2023 |
if (!franchiseeIds.isEmpty()) {
|
|
|
2024 |
franchiseeVisits = franchiseeVisitRepository.selectAllByIds(franchiseeIds);
|
|
|
2025 |
LOGGER.info("franchiseeVisits {}", franchiseeVisits);
|
| 31249 |
tejbeer |
2026 |
|
| 35415 |
amit |
2027 |
// Batch fetch all FranchiseeActivities instead of N+1
|
|
|
2028 |
List<FranchiseeActivity> allFranchiseeActivities = franchiseeActivityRepository
|
|
|
2029 |
.selectByFranchiseeVisitIds(franchiseeIds);
|
|
|
2030 |
Map<Integer, List<FranchiseeActivity>> franchiseeActivityMap = allFranchiseeActivities.stream()
|
|
|
2031 |
.collect(Collectors.groupingBy(FranchiseeActivity::getFranchiseeVisitd));
|
|
|
2032 |
|
| 31677 |
amit.gupta |
2033 |
for (FranchiseeVisit franchiseeVisit : franchiseeVisits) {
|
| 35415 |
amit |
2034 |
List<FranchiseeActivity> franchiseeActivities = franchiseeActivityMap.get(franchiseeVisit.getId());
|
| 31677 |
amit.gupta |
2035 |
LOGGER.info("franchiseeActivities {}", franchiseeActivities);
|
| 31249 |
tejbeer |
2036 |
|
| 35415 |
amit |
2037 |
if (franchiseeActivities != null && !franchiseeActivities.isEmpty()) {
|
|
|
2038 |
franchiseeVisit.setScheduleTimestamp(franchiseeActivities.get(0).getSchelduleTimestamp());
|
|
|
2039 |
franchiseeVisit.setFranchiseeActivity(franchiseeActivities.get(0));
|
|
|
2040 |
}
|
| 31677 |
amit.gupta |
2041 |
}
|
| 31249 |
tejbeer |
2042 |
|
| 31677 |
amit.gupta |
2043 |
}
|
| 31249 |
tejbeer |
2044 |
|
| 35415 |
amit |
2045 |
// Pre-fetch all retailers using cached method (instead of N+1 getFofoRetailer calls)
|
|
|
2046 |
Map<Integer, CustomRetailer> allRetailersMap = retailerService.getAllFofoRetailers();
|
|
|
2047 |
|
| 31677 |
amit.gupta |
2048 |
Map<LocalDate, List<VisitRequest>> dateWiseVisitRequest = allVisitRequests.stream()
|
|
|
2049 |
.collect(Collectors.groupingBy(x -> x.getScheduleTimestamp().toLocalDate()));
|
| 31249 |
tejbeer |
2050 |
|
| 31677 |
amit.gupta |
2051 |
for (Entry<LocalDate, List<VisitRequest>> visitEntry : dateWiseVisitRequest.entrySet()) {
|
| 31249 |
tejbeer |
2052 |
|
| 31677 |
amit.gupta |
2053 |
LocalDate date = visitEntry.getKey();
|
|
|
2054 |
List<VisitRequest> visitRequests = visitEntry.getValue();
|
| 31249 |
tejbeer |
2055 |
|
| 31677 |
amit.gupta |
2056 |
VisitSummaryModel visitSummaryModel = new VisitSummaryModel();
|
| 31249 |
tejbeer |
2057 |
|
| 31677 |
amit.gupta |
2058 |
visitSummaryModel.setDate(date);
|
|
|
2059 |
List<Integer> dateWiseLeadEntry = visitRequests.stream()
|
|
|
2060 |
.filter(x -> x.getVisitType().equals("lead")).map(x -> x.getVisitId())
|
|
|
2061 |
.collect(Collectors.toList());
|
| 31249 |
tejbeer |
2062 |
|
| 31677 |
amit.gupta |
2063 |
List<Integer> dateWiseFranchiseeIds = visitRequests.stream()
|
|
|
2064 |
.filter(x -> x.getVisitType().equals("franchiseeVisit")).map(x -> x.getVisitId())
|
|
|
2065 |
.collect(Collectors.toList());
|
| 31249 |
tejbeer |
2066 |
|
| 31677 |
amit.gupta |
2067 |
Map<Integer, List<Lead>> filteredLeadsMap = null;
|
|
|
2068 |
if (!leads.isEmpty()) {
|
|
|
2069 |
filteredLeadsMap = leads.stream().filter(x -> dateWiseLeadEntry.contains(x.getId()))
|
|
|
2070 |
.collect(Collectors.groupingBy(x -> x.getAssignTo()));
|
| 31249 |
tejbeer |
2071 |
|
| 31677 |
amit.gupta |
2072 |
}
|
| 31249 |
tejbeer |
2073 |
|
| 31677 |
amit.gupta |
2074 |
Map<Integer, List<FranchiseeVisit>> filteredFranchiseeVisitsMap = null;
|
| 31249 |
tejbeer |
2075 |
|
| 31677 |
amit.gupta |
2076 |
if (!franchiseeVisits.isEmpty()) {
|
|
|
2077 |
filteredFranchiseeVisitsMap = franchiseeVisits.stream()
|
|
|
2078 |
.filter(x -> dateWiseFranchiseeIds.contains(x.getId()))
|
|
|
2079 |
.collect(Collectors.groupingBy(x -> x.getAuthId()));
|
| 31249 |
tejbeer |
2080 |
|
| 31677 |
amit.gupta |
2081 |
}
|
| 31249 |
tejbeer |
2082 |
|
| 31677 |
amit.gupta |
2083 |
List<UserVisitModel> userVisits = new ArrayList<>();
|
| 31249 |
tejbeer |
2084 |
|
| 31677 |
amit.gupta |
2085 |
for (AuthUser auth : authUsers) {
|
|
|
2086 |
UserVisitModel userVisitModel = new UserVisitModel();
|
|
|
2087 |
List<VisitDescriptionModel> visitDescriptions = new ArrayList<>();
|
| 31249 |
tejbeer |
2088 |
|
| 31677 |
amit.gupta |
2089 |
List<Lead> authLeads = new ArrayList<>();
|
|
|
2090 |
if (filteredLeadsMap != null) {
|
|
|
2091 |
authLeads = filteredLeadsMap.get(auth.getId());
|
| 31249 |
tejbeer |
2092 |
|
| 31677 |
amit.gupta |
2093 |
}
|
| 31249 |
tejbeer |
2094 |
|
| 31677 |
amit.gupta |
2095 |
if (authLeads != null && !authLeads.isEmpty()) {
|
|
|
2096 |
userVisitModel.setAuthUser(auth.getFullName());
|
| 31249 |
tejbeer |
2097 |
|
| 31677 |
amit.gupta |
2098 |
for (Lead lead : authLeads) {
|
| 31249 |
tejbeer |
2099 |
|
| 31677 |
amit.gupta |
2100 |
VisitRequest visitRequest = visitRequests.stream().filter(
|
|
|
2101 |
x -> x.getVisitId() == lead.getId() && x.getCreatedBy() == lead.getAssignTo())
|
|
|
2102 |
.findAny().orElse(null);
|
|
|
2103 |
VisitDescriptionModel visitDescriptionModel = new VisitDescriptionModel();
|
|
|
2104 |
visitDescriptionModel.setVisitId(visitRequest.getId());
|
|
|
2105 |
visitDescriptionModel.setVisitName(lead.getFirstName());
|
|
|
2106 |
visitDescriptionModel.setCity(lead.getCity());
|
|
|
2107 |
visitDescriptionModel.setState(lead.getState());
|
|
|
2108 |
visitDescriptionModel.setScheduleTime(lead.getScheduledTimestamp());
|
|
|
2109 |
visitDescriptionModel.setStatus(visitRequest.getStatus());
|
|
|
2110 |
visitDescriptionModel.setRemarks(lead.getLeadActivity().getRemark());
|
|
|
2111 |
visitDescriptionModel.setVisitType(visitRequest.getVisitType());
|
|
|
2112 |
visitDescriptions.add(visitDescriptionModel);
|
| 31249 |
tejbeer |
2113 |
|
| 31677 |
amit.gupta |
2114 |
}
|
|
|
2115 |
}
|
| 31249 |
tejbeer |
2116 |
|
| 31677 |
amit.gupta |
2117 |
List<FranchiseeVisit> authfranchiseeVisit = new ArrayList<>();
|
|
|
2118 |
if (filteredFranchiseeVisitsMap != null) {
|
|
|
2119 |
authfranchiseeVisit = filteredFranchiseeVisitsMap.get(auth.getId());
|
| 31249 |
tejbeer |
2120 |
|
| 31677 |
amit.gupta |
2121 |
}
|
| 31249 |
tejbeer |
2122 |
|
| 31677 |
amit.gupta |
2123 |
if (authfranchiseeVisit != null && !authfranchiseeVisit.isEmpty()) {
|
|
|
2124 |
userVisitModel.setAuthUser(auth.getFullName());
|
| 31249 |
tejbeer |
2125 |
|
| 31677 |
amit.gupta |
2126 |
for (FranchiseeVisit franchiseeVisit : authfranchiseeVisit) {
|
| 31249 |
tejbeer |
2127 |
|
| 31677 |
amit.gupta |
2128 |
VisitRequest visitRequest = visitRequests.stream()
|
|
|
2129 |
.filter(x -> x.getVisitId() == franchiseeVisit.getId()
|
|
|
2130 |
&& x.getCreatedBy() == franchiseeVisit.getAuthId())
|
|
|
2131 |
.findAny().orElse(null);
|
| 31249 |
tejbeer |
2132 |
|
| 35415 |
amit |
2133 |
CustomRetailer customRetailer = allRetailersMap.get(franchiseeVisit.getFofoId());
|
| 31677 |
amit.gupta |
2134 |
VisitDescriptionModel visitDescriptionModel = new VisitDescriptionModel();
|
|
|
2135 |
visitDescriptionModel.setVisitId(visitRequest.getId());
|
|
|
2136 |
visitDescriptionModel.setVisitName(franchiseeVisit.getPartnerName());
|
| 35415 |
amit |
2137 |
if (customRetailer != null && customRetailer.getAddress() != null) {
|
|
|
2138 |
visitDescriptionModel.setCity(customRetailer.getAddress().getCity());
|
|
|
2139 |
visitDescriptionModel.setState(customRetailer.getAddress().getState());
|
|
|
2140 |
}
|
| 31677 |
amit.gupta |
2141 |
visitDescriptionModel.setScheduleTime(
|
|
|
2142 |
franchiseeVisit.getFranchiseeActivity().getSchelduleTimestamp());
|
|
|
2143 |
visitDescriptionModel.setStatus(visitRequest.getStatus());
|
|
|
2144 |
visitDescriptionModel.setRemarks(franchiseeVisit.getAgenda());
|
|
|
2145 |
visitDescriptionModel.setVisitType(visitRequest.getVisitType());
|
| 31249 |
tejbeer |
2146 |
|
| 31677 |
amit.gupta |
2147 |
visitDescriptions.add(visitDescriptionModel);
|
| 31249 |
tejbeer |
2148 |
|
| 31677 |
amit.gupta |
2149 |
}
|
|
|
2150 |
}
|
| 31249 |
tejbeer |
2151 |
|
| 31677 |
amit.gupta |
2152 |
userVisitModel.setVisitDescriptions(visitDescriptions);
|
|
|
2153 |
LOGGER.info("userVisit {}", userVisitModel);
|
| 31249 |
tejbeer |
2154 |
|
| 31677 |
amit.gupta |
2155 |
if (userVisitModel.getAuthUser() != null) {
|
|
|
2156 |
userVisits.add(userVisitModel);
|
|
|
2157 |
}
|
| 31249 |
tejbeer |
2158 |
|
| 31677 |
amit.gupta |
2159 |
}
|
| 31249 |
tejbeer |
2160 |
|
| 31677 |
amit.gupta |
2161 |
visitSummaryModel.setUserVisits(userVisits);
|
| 31249 |
tejbeer |
2162 |
|
| 31677 |
amit.gupta |
2163 |
visitSummary.add(visitSummaryModel);
|
| 31249 |
tejbeer |
2164 |
|
| 31677 |
amit.gupta |
2165 |
}
|
| 31249 |
tejbeer |
2166 |
|
| 31677 |
amit.gupta |
2167 |
}
|
| 31249 |
tejbeer |
2168 |
|
| 31677 |
amit.gupta |
2169 |
}
|
|
|
2170 |
return responseSender.ok(visitSummary);
|
| 31249 |
tejbeer |
2171 |
|
| 31677 |
amit.gupta |
2172 |
}
|
| 31249 |
tejbeer |
2173 |
|
| 31677 |
amit.gupta |
2174 |
@RequestMapping(value = "/visitRequest", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35288 |
amit |
2175 |
public ResponseEntity<?> visitRequest(HttpServletRequest request, @RequestParam(name = "gmailId") String
|
|
|
2176 |
gmailId,
|
| 31677 |
amit.gupta |
2177 |
@RequestParam(name = "visitId") int visitId, @RequestParam(name = "status") VisitStatus status, Model model)
|
|
|
2178 |
throws Exception {
|
|
|
2179 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
| 31249 |
tejbeer |
2180 |
|
| 31677 |
amit.gupta |
2181 |
VisitRequest visitRequest = visitRequestRepository.selectById(visitId);
|
|
|
2182 |
visitRequest.setActionedBy(authUser.getId());
|
|
|
2183 |
visitRequest.setStatus(status);
|
|
|
2184 |
visitRequest.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
2185 |
if (status.equals(VisitStatus.approved)) {
|
|
|
2186 |
visitRequest.setApprovedTimestamp(LocalDateTime.now());
|
|
|
2187 |
}
|
| 31249 |
tejbeer |
2188 |
|
| 31677 |
amit.gupta |
2189 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
2190 |
sendNotificationModel.setCampaignName("Visit Request");
|
|
|
2191 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
2192 |
sendNotificationModel.setTitle("Visit Request");
|
|
|
2193 |
String message = "Visit Request has been " + status + " for scheduled time on "
|
|
|
2194 |
+ visitRequest.getScheduleTimestamp().toLocalDate();
|
| 31249 |
tejbeer |
2195 |
|
| 31677 |
amit.gupta |
2196 |
sendNotificationModel.setMessage(message);
|
|
|
2197 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
2198 |
User user = userRepository.selectByEmailId(gmailId);
|
|
|
2199 |
sendNotificationModel.setUserIds(new ArrayList<>(user.getId()));
|
| 31249 |
tejbeer |
2200 |
|
| 31677 |
amit.gupta |
2201 |
notificationService.sendNotificationToAll(sendNotificationModel);
|
| 31249 |
tejbeer |
2202 |
|
| 31677 |
amit.gupta |
2203 |
return responseSender.ok(true);
|
| 31249 |
tejbeer |
2204 |
|
| 31677 |
amit.gupta |
2205 |
}
|
| 31249 |
tejbeer |
2206 |
|
| 34301 |
ranu |
2207 |
@Autowired
|
|
|
2208 |
RbmRatingRepository rbmRatingRepository;
|
|
|
2209 |
|
| 34322 |
ranu |
2210 |
@Autowired
|
|
|
2211 |
SalesRatingRepository salesRatingRepository;
|
|
|
2212 |
|
| 34301 |
ranu |
2213 |
@RequestMapping(value = "/rbmRating", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 35288 |
amit |
2214 |
public ResponseEntity<?> rbmRating(HttpServletRequest request, @RequestBody RbmSalesRatingRequest
|
|
|
2215 |
rbmSalesRatingRequest, Model model) throws Exception {
|
| 34301 |
ranu |
2216 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
2217 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
2218 |
int fofoId = uc.getUserId();
|
| 34322 |
ranu |
2219 |
|
| 34301 |
ranu |
2220 |
int rbmL1 = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
|
| 34322 |
ranu |
2221 |
int salesL1Id = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1, fofoId);
|
| 34301 |
ranu |
2222 |
|
| 36114 |
ranu |
2223 |
// Calculate current week boundaries (Monday to Sunday)
|
|
|
2224 |
LocalDate today = LocalDate.now();
|
|
|
2225 |
LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
|
2226 |
LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
|
|
2227 |
LocalDateTime startOfWeekDateTime = startOfWeek.atStartOfDay();
|
|
|
2228 |
LocalDateTime endOfWeekDateTime = endOfWeek.atTime(23, 59, 59);
|
| 34301 |
ranu |
2229 |
|
| 36114 |
ranu |
2230 |
// Check if RBM rating already exists for this week
|
|
|
2231 |
List<RbmRating> existingRbmRatings = rbmRatingRepository.findByFofoIdAndRbmIdForCurrentMonth(fofoId, rbmL1, startOfWeekDateTime, endOfWeekDateTime);
|
| 34322 |
ranu |
2232 |
if (!existingRbmRatings.isEmpty()) {
|
| 36114 |
ranu |
2233 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Rating for this week already exists.");
|
| 34301 |
ranu |
2234 |
}
|
|
|
2235 |
|
| 36114 |
ranu |
2236 |
// Check if Sales Person rating already exists for this week
|
|
|
2237 |
List<SalesRating> existingSalesRatings = salesRatingRepository.findByFofoIdAndSalesL1IdForCurrentMonth(fofoId, salesL1Id, startOfWeekDateTime, endOfWeekDateTime);
|
| 34322 |
ranu |
2238 |
if (!existingSalesRatings.isEmpty()) {
|
| 36114 |
ranu |
2239 |
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Rating for this week already exists.");
|
| 34322 |
ranu |
2240 |
}
|
| 34301 |
ranu |
2241 |
|
| 34322 |
ranu |
2242 |
// Save RBM rating
|
| 34301 |
ranu |
2243 |
RbmRating rbmRating = new RbmRating();
|
| 34322 |
ranu |
2244 |
rbmRating.setComment(rbmSalesRatingRequest.getRbmComment());
|
|
|
2245 |
rbmRating.setRating(rbmSalesRatingRequest.getRbmRating());
|
| 34301 |
ranu |
2246 |
rbmRating.setFofoId(fofoId);
|
|
|
2247 |
rbmRating.setRbmId(rbmL1);
|
|
|
2248 |
rbmRating.setCreateTimeStamp(LocalDateTime.now());
|
|
|
2249 |
rbmRatingRepository.persist(rbmRating);
|
|
|
2250 |
|
| 34322 |
ranu |
2251 |
// Save Sales Person rating
|
|
|
2252 |
SalesRating salesRating = new SalesRating();
|
|
|
2253 |
salesRating.setComment(rbmSalesRatingRequest.getSalesComment());
|
|
|
2254 |
salesRating.setRating(rbmSalesRatingRequest.getSalesRating());
|
|
|
2255 |
salesRating.setFofoId(fofoId);
|
|
|
2256 |
salesRating.setSalesL1Id(salesL1Id);
|
|
|
2257 |
salesRating.setCreateTimeStamp(LocalDateTime.now());
|
|
|
2258 |
salesRatingRepository.persist(salesRating);
|
|
|
2259 |
|
|
|
2260 |
return responseSender.ok("Rating submitted successfully.");
|
| 34301 |
ranu |
2261 |
}
|
|
|
2262 |
|
| 36286 |
ranu |
2263 |
@RequestMapping(value = "/rbmRating/weekly-status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
2264 |
public ResponseEntity<?> rbmRatingWeeklyStatus(HttpServletRequest request) throws Exception {
|
|
|
2265 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
2266 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
2267 |
int fofoId = uc.getUserId();
|
| 34301 |
ranu |
2268 |
|
| 36286 |
ranu |
2269 |
int rbmL1 = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_RBM, EscalationType.L1, fofoId);
|
|
|
2270 |
int salesL1Id = csService.getAuthUserId(ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1, fofoId);
|
|
|
2271 |
|
|
|
2272 |
// Calculate current week boundaries (Monday to Sunday)
|
|
|
2273 |
LocalDate today = LocalDate.now();
|
|
|
2274 |
LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
|
2275 |
LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
|
|
2276 |
LocalDateTime startOfWeekDateTime = startOfWeek.atStartOfDay();
|
|
|
2277 |
LocalDateTime endOfWeekDateTime = endOfWeek.atTime(23, 59, 59);
|
|
|
2278 |
|
| 36336 |
ranu |
2279 |
List<RbmRating> existingRbmRatings = rbmRatingRepository.findByFofoIdForCurrentWeek(fofoId, startOfWeekDateTime, endOfWeekDateTime);
|
|
|
2280 |
List<SalesRating> existingSalesRatings = salesRatingRepository.findByFofoIdForCurrentWeek(fofoId, startOfWeekDateTime, endOfWeekDateTime);
|
| 36286 |
ranu |
2281 |
|
|
|
2282 |
boolean pending = existingRbmRatings.isEmpty() || existingSalesRatings.isEmpty();
|
|
|
2283 |
|
|
|
2284 |
Map<String, Object> response = new HashMap<>();
|
|
|
2285 |
response.put("pending", pending);
|
|
|
2286 |
response.put("weekStart", startOfWeek.toString());
|
|
|
2287 |
response.put("weekEnd", endOfWeek.toString());
|
|
|
2288 |
|
|
|
2289 |
if (rbmL1 > 0) {
|
|
|
2290 |
AuthUser rbmUser = authRepository.selectById(rbmL1);
|
|
|
2291 |
if (rbmUser != null) {
|
|
|
2292 |
response.put("rbmName", rbmUser.getFullName());
|
|
|
2293 |
}
|
|
|
2294 |
}
|
|
|
2295 |
if (salesL1Id > 0) {
|
|
|
2296 |
AuthUser salesUser = authRepository.selectById(salesL1Id);
|
|
|
2297 |
if (salesUser != null) {
|
|
|
2298 |
response.put("salesPersonName", salesUser.getFullName());
|
|
|
2299 |
}
|
|
|
2300 |
}
|
|
|
2301 |
|
|
|
2302 |
return responseSender.ok(response);
|
|
|
2303 |
}
|
|
|
2304 |
|
|
|
2305 |
@Autowired
|
|
|
2306 |
private RatingReminderRepository ratingReminderRepository;
|
|
|
2307 |
|
|
|
2308 |
@RequestMapping(value = "/rbmRating/reminder", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
2309 |
public ResponseEntity<?> rbmRatingReminder(HttpServletRequest request) throws Exception {
|
|
|
2310 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
2311 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
2312 |
int fofoId = uc.getUserId();
|
|
|
2313 |
|
|
|
2314 |
LocalDate today = LocalDate.now();
|
|
|
2315 |
LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
|
2316 |
LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
|
|
2317 |
|
|
|
2318 |
RatingReminder reminder = ratingReminderRepository.findByFofoIdAndWeek(fofoId, startOfWeek);
|
|
|
2319 |
|
|
|
2320 |
int attemptsRemaining;
|
|
|
2321 |
if (reminder == null) {
|
|
|
2322 |
// First hit this week: create entry initialised to MAX, no decrement
|
|
|
2323 |
reminder = new RatingReminder();
|
|
|
2324 |
reminder.setFofoId(fofoId);
|
|
|
2325 |
reminder.setWeekStart(startOfWeek);
|
|
|
2326 |
reminder.setWeekEnd(endOfWeek);
|
|
|
2327 |
reminder.setAttemptsRemaining(RatingReminder.MAX_ATTEMPTS_PER_WEEK);
|
|
|
2328 |
reminder.setCreateTimestamp(LocalDateTime.now());
|
|
|
2329 |
ratingReminderRepository.persist(reminder);
|
|
|
2330 |
attemptsRemaining = RatingReminder.MAX_ATTEMPTS_PER_WEEK;
|
|
|
2331 |
} else {
|
|
|
2332 |
// Subsequent hit: atomically decrement (floor 0) and re-read
|
|
|
2333 |
ratingReminderRepository.decrementRemaining(reminder.getId());
|
|
|
2334 |
reminder = ratingReminderRepository.findByFofoIdAndWeek(fofoId, startOfWeek);
|
|
|
2335 |
attemptsRemaining = reminder.getAttemptsRemaining();
|
|
|
2336 |
}
|
|
|
2337 |
|
|
|
2338 |
Map<String, Object> response = new HashMap<>();
|
|
|
2339 |
response.put("partnerId", fofoId);
|
|
|
2340 |
response.put("attemptsRemaining", attemptsRemaining);
|
|
|
2341 |
|
|
|
2342 |
return responseSender.ok(response);
|
|
|
2343 |
}
|
|
|
2344 |
|
|
|
2345 |
|
| 30077 |
tejbeer |
2346 |
}
|