| 25899 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 30487 |
tejbeer |
3 |
import java.io.IOException;
|
| 30416 |
tejbeer |
4 |
import java.time.LocalDate;
|
|
|
5 |
import java.time.LocalDateTime;
|
| 30433 |
tejbeer |
6 |
import java.time.format.DateTimeFormatter;
|
| 30416 |
tejbeer |
7 |
import java.util.ArrayList;
|
|
|
8 |
import java.util.Arrays;
|
|
|
9 |
import java.util.Comparator;
|
|
|
10 |
import java.util.HashMap;
|
|
|
11 |
import java.util.List;
|
|
|
12 |
import java.util.Map;
|
|
|
13 |
import java.util.Map.Entry;
|
|
|
14 |
import java.util.Set;
|
|
|
15 |
import java.util.stream.Collectors;
|
|
|
16 |
|
|
|
17 |
import javax.servlet.http.HttpServletRequest;
|
|
|
18 |
|
| 31677 |
amit.gupta |
19 |
import com.spice.profitmandi.common.enumuration.ActivationType;
|
| 32701 |
amit.gupta |
20 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 32737 |
amit.gupta |
21 |
import com.spice.profitmandi.dao.entity.fofo.RetailerContact;
|
| 32701 |
amit.gupta |
22 |
import com.spice.profitmandi.service.FofoUser;
|
| 32737 |
amit.gupta |
23 |
import com.spice.profitmandi.service.smartping.SmartPingAgentModel;
|
|
|
24 |
import com.spice.profitmandi.service.smartping.SmartPingService;
|
| 30433 |
tejbeer |
25 |
import org.apache.commons.csv.CSVRecord;
|
| 30416 |
tejbeer |
26 |
import org.apache.logging.log4j.LogManager;
|
|
|
27 |
import org.apache.logging.log4j.Logger;
|
|
|
28 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
29 |
import org.springframework.format.annotation.DateTimeFormat;
|
| 30487 |
tejbeer |
30 |
import org.springframework.http.HttpHeaders;
|
|
|
31 |
import org.springframework.http.HttpStatus;
|
| 30416 |
tejbeer |
32 |
import org.springframework.http.MediaType;
|
|
|
33 |
import org.springframework.http.ResponseEntity;
|
|
|
34 |
import org.springframework.stereotype.Controller;
|
|
|
35 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
36 |
import org.springframework.ui.Model;
|
| 32701 |
amit.gupta |
37 |
import org.springframework.web.bind.annotation.*;
|
| 30433 |
tejbeer |
38 |
import org.springframework.web.multipart.MultipartFile;
|
| 30416 |
tejbeer |
39 |
|
| 30487 |
tejbeer |
40 |
import com.mongodb.DBObject;
|
| 31249 |
tejbeer |
41 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 25899 |
tejbeer |
42 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 25952 |
tejbeer |
43 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 27117 |
tejbeer |
44 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 31249 |
tejbeer |
45 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 30433 |
tejbeer |
46 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 31249 |
tejbeer |
47 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 25899 |
tejbeer |
48 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
49 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 30077 |
tejbeer |
50 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionPlan;
|
| 30416 |
tejbeer |
51 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
|
| 30077 |
tejbeer |
52 |
import com.spice.profitmandi.dao.entity.auth.PartnerSecondaryPlan;
|
| 30416 |
tejbeer |
53 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
|
|
54 |
import com.spice.profitmandi.dao.entity.cs.TicketCategory;
|
|
|
55 |
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
|
| 25899 |
tejbeer |
56 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 25952 |
tejbeer |
57 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 28935 |
tejbeer |
58 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 30087 |
tejbeer |
59 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 28935 |
tejbeer |
60 |
import com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel;
|
| 25952 |
tejbeer |
61 |
import com.spice.profitmandi.dao.entity.user.FranchiseeActivity;
|
|
|
62 |
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
|
| 25899 |
tejbeer |
63 |
import com.spice.profitmandi.dao.entity.user.Lead;
|
|
|
64 |
import com.spice.profitmandi.dao.entity.user.LeadActivity;
|
| 31249 |
tejbeer |
65 |
import com.spice.profitmandi.dao.entity.user.VisitRequest;
|
| 30416 |
tejbeer |
66 |
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
|
| 31249 |
tejbeer |
67 |
import com.spice.profitmandi.dao.enumuration.dtr.CommunicationType;
|
| 25952 |
tejbeer |
68 |
import com.spice.profitmandi.dao.enumuration.dtr.FranchiseeActivityStatus;
|
|
|
69 |
import com.spice.profitmandi.dao.enumuration.dtr.FranchiseeVisitStatus;
|
| 25899 |
tejbeer |
70 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
|
| 28935 |
tejbeer |
71 |
import com.spice.profitmandi.dao.enumuration.dtr.StoreTimeline;
|
| 31249 |
tejbeer |
72 |
import com.spice.profitmandi.dao.enumuration.dtr.VisitStatus;
|
| 30416 |
tejbeer |
73 |
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
|
|
|
74 |
import com.spice.profitmandi.dao.model.OnBoardingTimelineModel;
|
|
|
75 |
import com.spice.profitmandi.dao.model.PartnerCollectionPlanModel;
|
|
|
76 |
import com.spice.profitmandi.dao.model.PartnerCollectionRemarkModel;
|
|
|
77 |
import com.spice.profitmandi.dao.model.PartnerSecondaryPlanModel;
|
|
|
78 |
import com.spice.profitmandi.dao.model.PartnerTargetAchievementModel;
|
|
|
79 |
import com.spice.profitmandi.dao.model.TargetModel;
|
|
|
80 |
import com.spice.profitmandi.dao.model.TicketViewModel;
|
|
|
81 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 31249 |
tejbeer |
82 |
import com.spice.profitmandi.dao.model.UserVisitModel;
|
|
|
83 |
import com.spice.profitmandi.dao.model.VisitDescriptionModel;
|
|
|
84 |
import com.spice.profitmandi.dao.model.VisitSummaryModel;
|
| 25899 |
tejbeer |
85 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 30104 |
tejbeer |
86 |
import com.spice.profitmandi.dao.repository.auth.AuthUserPartnerMappingRepository;
|
| 30077 |
tejbeer |
87 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionPlanRepository;
|
| 30416 |
tejbeer |
88 |
import com.spice.profitmandi.dao.repository.auth.PartnerCollectionRemarkRepository;
|
| 30077 |
tejbeer |
89 |
import com.spice.profitmandi.dao.repository.auth.PartnerSecondaryPlanRepository;
|
| 25952 |
tejbeer |
90 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 30416 |
tejbeer |
91 |
import com.spice.profitmandi.dao.repository.cs.TicketCategoryRepository;
|
|
|
92 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
|
|
93 |
import com.spice.profitmandi.dao.repository.cs.TicketSubCategoryRepository;
|
|
|
94 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
95 |
import com.spice.profitmandi.dao.repository.dtr.FranchiseeActivityRepository;
|
|
|
96 |
import com.spice.profitmandi.dao.repository.dtr.FranchiseeVisitRepository;
|
|
|
97 |
import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;
|
|
|
98 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
| 30487 |
tejbeer |
99 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 30416 |
tejbeer |
100 |
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
|
|
|
101 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
102 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 31249 |
tejbeer |
103 |
import com.spice.profitmandi.dao.repository.dtr.VisitRequestRepository;
|
| 30087 |
tejbeer |
104 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 30077 |
tejbeer |
105 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 31249 |
tejbeer |
106 |
import com.spice.profitmandi.service.AuthService;
|
|
|
107 |
import com.spice.profitmandi.service.NotificationService;
|
| 30348 |
tejbeer |
108 |
import com.spice.profitmandi.service.PartnerCollectionService;
|
| 25952 |
tejbeer |
109 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 28935 |
tejbeer |
110 |
import com.spice.profitmandi.service.user.StoreTimelineTatService;
|
| 25952 |
tejbeer |
111 |
import com.spice.profitmandi.web.req.CreateFranchiseeRequest;
|
|
|
112 |
import com.spice.profitmandi.web.res.Partner;
|
| 30416 |
tejbeer |
113 |
|
| 25899 |
tejbeer |
114 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
115 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
116 |
|
|
|
117 |
@Controller
|
|
|
118 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
119 |
public class LeadController {
|
| 31677 |
amit.gupta |
120 |
private static final Logger LOGGER = LogManager.getLogger(LeadController.class);
|
|
|
121 |
@Autowired
|
|
|
122 |
private ResponseSender<?> responseSender;
|
| 25899 |
tejbeer |
123 |
|
| 31677 |
amit.gupta |
124 |
@Autowired
|
|
|
125 |
private AuthRepository authRepository;
|
| 25899 |
tejbeer |
126 |
|
| 31677 |
amit.gupta |
127 |
@Autowired
|
|
|
128 |
private LeadRepository leadRepository;
|
| 25899 |
tejbeer |
129 |
|
| 31677 |
amit.gupta |
130 |
@Autowired
|
|
|
131 |
private CsService csService;
|
| 25952 |
tejbeer |
132 |
|
| 31677 |
amit.gupta |
133 |
@Autowired
|
|
|
134 |
private UserRepository userRepository;
|
| 25952 |
tejbeer |
135 |
|
| 31677 |
amit.gupta |
136 |
@Autowired
|
|
|
137 |
private UserAccountRepository userAccountRepository;
|
| 25952 |
tejbeer |
138 |
|
| 31677 |
amit.gupta |
139 |
@Autowired
|
|
|
140 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 25952 |
tejbeer |
141 |
|
| 31677 |
amit.gupta |
142 |
@Autowired
|
|
|
143 |
private RetailerService retailerService;
|
| 25952 |
tejbeer |
144 |
|
| 31677 |
amit.gupta |
145 |
@Autowired
|
|
|
146 |
private LeadActivityRepository leadActivityRepository;
|
| 25899 |
tejbeer |
147 |
|
| 31677 |
amit.gupta |
148 |
@Autowired
|
|
|
149 |
private FranchiseeVisitRepository franchiseeVisitRepository;
|
| 25952 |
tejbeer |
150 |
|
| 31677 |
amit.gupta |
151 |
@Autowired
|
|
|
152 |
private FranchiseeActivityRepository franchiseeActivityRepository;
|
| 25952 |
tejbeer |
153 |
|
| 31677 |
amit.gupta |
154 |
@Autowired
|
|
|
155 |
private PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
| 28935 |
tejbeer |
156 |
|
| 31677 |
amit.gupta |
157 |
@Autowired
|
|
|
158 |
private FofoStoreRepository fofoStoreRepository;
|
| 28935 |
tejbeer |
159 |
|
| 31677 |
amit.gupta |
160 |
@Autowired
|
|
|
161 |
private StoreTimelineTatService storeTimelineTatService;
|
| 28935 |
tejbeer |
162 |
|
| 31677 |
amit.gupta |
163 |
@Autowired
|
|
|
164 |
private PartnerCollectionService partnerCollectionService;
|
| 30348 |
tejbeer |
165 |
|
| 31677 |
amit.gupta |
166 |
@Autowired
|
|
|
167 |
private TicketRepository ticketRepository;
|
| 30416 |
tejbeer |
168 |
|
| 31677 |
amit.gupta |
169 |
@Autowired
|
|
|
170 |
private TicketCategoryRepository ticketCategoryRepository;
|
| 30416 |
tejbeer |
171 |
|
| 31677 |
amit.gupta |
172 |
@Autowired
|
|
|
173 |
private TicketSubCategoryRepository ticketSubCategoryRepository;
|
| 30416 |
tejbeer |
174 |
|
| 31677 |
amit.gupta |
175 |
@Autowired
|
|
|
176 |
private PartnerCollectionRemarkRepository partnerCollectionRemarkRepository;
|
| 30416 |
tejbeer |
177 |
|
| 31677 |
amit.gupta |
178 |
@Autowired
|
|
|
179 |
private Mongo mongoClient;
|
| 30487 |
tejbeer |
180 |
|
| 31677 |
amit.gupta |
181 |
@Autowired
|
|
|
182 |
private OrderRepository orderRepository;
|
| 30487 |
tejbeer |
183 |
|
| 31677 |
amit.gupta |
184 |
@Autowired
|
|
|
185 |
private PartnerCollectionPlanRepository partnerCollectionPlanRepository;
|
| 30487 |
tejbeer |
186 |
|
| 31677 |
amit.gupta |
187 |
@Autowired
|
|
|
188 |
private PartnerSecondaryPlanRepository partnerSecondaryPlanRepository;
|
| 30487 |
tejbeer |
189 |
|
| 31677 |
amit.gupta |
190 |
@Autowired
|
|
|
191 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 30487 |
tejbeer |
192 |
|
| 31677 |
amit.gupta |
193 |
@Autowired
|
|
|
194 |
private AuthUserPartnerMappingRepository authUserPartnerMappingRepository;
|
| 30487 |
tejbeer |
195 |
|
| 31677 |
amit.gupta |
196 |
@Autowired
|
|
|
197 |
private VisitRequestRepository visitRequestRepository;
|
| 31249 |
tejbeer |
198 |
|
| 31677 |
amit.gupta |
199 |
@Autowired
|
|
|
200 |
private AuthService authService;
|
| 31249 |
tejbeer |
201 |
|
| 31677 |
amit.gupta |
202 |
@Autowired
|
|
|
203 |
private NotificationService notificationService;
|
| 31249 |
tejbeer |
204 |
|
| 31677 |
amit.gupta |
205 |
@RequestMapping(value = "/lead", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
206 |
@ApiImplicitParams({
|
|
|
207 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
208 |
public ResponseEntity<?> LeadUser(HttpServletRequest request,
|
|
|
209 |
@RequestBody CreateRefferalRequest createRefferalRequest) throws Exception {
|
|
|
210 |
Lead lead = new Lead();
|
|
|
211 |
lead.setFirstName(createRefferalRequest.getFirstName());
|
|
|
212 |
lead.setLastName(createRefferalRequest.getLastName());
|
|
|
213 |
lead.setLeadMobile(createRefferalRequest.getMobile());
|
|
|
214 |
lead.setState(createRefferalRequest.getState());
|
|
|
215 |
lead.setCity(createRefferalRequest.getCity());
|
|
|
216 |
lead.setAddress(createRefferalRequest.getAddress());
|
|
|
217 |
lead.setCreatedTimestamp(LocalDateTime.now());
|
|
|
218 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
219 |
lead.setStatus(createRefferalRequest.getStatus());
|
|
|
220 |
lead.setSource(createRefferalRequest.getSource());
|
|
|
221 |
lead.setNotinterestedReason(createRefferalRequest.getReason());
|
|
|
222 |
if (createRefferalRequest.getColorCheck() == true) {
|
|
|
223 |
lead.setColor("Green");
|
|
|
224 |
} else {
|
|
|
225 |
lead.setColor("Yellow");
|
|
|
226 |
}
|
|
|
227 |
AuthUser authUser = authRepository.selectByGmailId(createRefferalRequest.getReffereeEmail());
|
|
|
228 |
String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
229 |
lead.setCreatedBy(authUserName);
|
|
|
230 |
lead.setAuthId(authUser.getId());
|
|
|
231 |
lead.setAssignTo(authUser.getId());
|
| 25899 |
tejbeer |
232 |
|
| 31677 |
amit.gupta |
233 |
leadRepository.persist(lead);
|
|
|
234 |
LeadActivity leadActivity = new LeadActivity();
|
|
|
235 |
leadActivity.setLeadId(lead.getId());
|
|
|
236 |
leadActivity.setRemark(createRefferalRequest.getRemark());
|
| 25899 |
tejbeer |
237 |
|
| 31677 |
amit.gupta |
238 |
leadActivity.setAuthId(authUser.getId());
|
| 31249 |
tejbeer |
239 |
|
| 31677 |
amit.gupta |
240 |
if (createRefferalRequest.getStatus().equals(LeadStatus.followUp)) {
|
|
|
241 |
leadActivity.setSchelduleTimestamp(createRefferalRequest.getSchelduleTimestamp());
|
|
|
242 |
leadActivity.setCommunicationType(createRefferalRequest.getCommunicationType());
|
| 31249 |
tejbeer |
243 |
|
| 31677 |
amit.gupta |
244 |
if (leadActivity.getCommunicationType().equals(CommunicationType.VISIT)) {
|
| 31249 |
tejbeer |
245 |
|
| 31677 |
amit.gupta |
246 |
visitRequestRepository.createVisitRequest(lead.getId(), "lead", lead.getAssignTo(),
|
|
|
247 |
createRefferalRequest.getSchelduleTimestamp());
|
|
|
248 |
}
|
|
|
249 |
//
|
|
|
250 |
leadActivity.setClosureTimestamp(createRefferalRequest.getClosureTimestamp());
|
|
|
251 |
lead.setClosureTimestamp(createRefferalRequest.getClosureTimestamp());
|
|
|
252 |
} else {
|
|
|
253 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
254 |
leadActivity.setClosureTimestamp(null);
|
|
|
255 |
lead.setClosureTimestamp(null);
|
|
|
256 |
}
|
|
|
257 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
258 |
leadActivityRepository.persist(leadActivity);
|
| 25899 |
tejbeer |
259 |
|
| 31677 |
amit.gupta |
260 |
return responseSender.ok(true);
|
|
|
261 |
}
|
| 25899 |
tejbeer |
262 |
|
| 31677 |
amit.gupta |
263 |
@RequestMapping(value = "/lead-description", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
264 |
@ApiImplicitParams({
|
|
|
265 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
266 |
public ResponseEntity<?> leadDescription(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId,
|
|
|
267 |
@RequestParam(name = "status") LeadStatus status) throws ProfitMandiBusinessException {
|
|
|
268 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
|
|
269 |
List<Lead> leads = null;
|
|
|
270 |
LOGGER.info("emails" + status);
|
| 31249 |
tejbeer |
271 |
|
| 31677 |
amit.gupta |
272 |
List<VisitRequest> visitRequests = visitRequestRepository.selectByAuthIdAndDate(authUser.getId(),
|
|
|
273 |
LocalDate.now());
|
|
|
274 |
Map<Integer, List<VisitRequest>> visitRequestMap = null;
|
|
|
275 |
if (!visitRequests.isEmpty()) {
|
|
|
276 |
visitRequestMap = visitRequests.stream().collect(Collectors.groupingBy(x -> x.getVisitId()));
|
|
|
277 |
}
|
|
|
278 |
if (status.equals(LeadStatus.followUp)) {
|
| 30306 |
tejbeer |
279 |
|
| 31677 |
amit.gupta |
280 |
leads = leadRepository.selectLeadsScheduledBetweenDate(Arrays.asList(authUser.getId()), null, null);
|
| 31249 |
tejbeer |
281 |
|
| 31677 |
amit.gupta |
282 |
if (visitRequestMap != null) {
|
|
|
283 |
for (Lead lead : leads) {
|
|
|
284 |
List<VisitRequest> visitRequest = visitRequestMap.get(lead.getId());
|
| 31249 |
tejbeer |
285 |
|
| 31677 |
amit.gupta |
286 |
if (visitRequest != null) {
|
|
|
287 |
if (visitRequest.size() > 1) {
|
| 31249 |
tejbeer |
288 |
|
| 31677 |
amit.gupta |
289 |
Comparator<VisitRequest> visitComparato = Comparator
|
|
|
290 |
.comparing(VisitRequest::getCreatedTimestamp);
|
| 31249 |
tejbeer |
291 |
|
| 31677 |
amit.gupta |
292 |
VisitRequest youngestVisit = visitRequest.stream().max(visitComparato).get();
|
|
|
293 |
lead.setVisitStatus(youngestVisit.getStatus());
|
| 31249 |
tejbeer |
294 |
|
| 31677 |
amit.gupta |
295 |
} else {
|
|
|
296 |
lead.setVisitStatus(visitRequest.get(0).getStatus());
|
| 31249 |
tejbeer |
297 |
|
| 31677 |
amit.gupta |
298 |
}
|
|
|
299 |
}
|
| 31249 |
tejbeer |
300 |
|
| 31677 |
amit.gupta |
301 |
}
|
|
|
302 |
}
|
| 31249 |
tejbeer |
303 |
|
| 31677 |
amit.gupta |
304 |
leads = leads.stream()
|
|
|
305 |
.sorted(Comparator.comparing(Lead::getScheduledTimestamp,
|
|
|
306 |
Comparator.nullsFirst(Comparator.reverseOrder())))
|
|
|
307 |
.collect(Collectors
|
|
|
308 |
.toList());/*
|
|
|
309 |
* Collections.sort(leads, (o1, o2) -> { if (o1.getScheduledTimestamp() != null
|
|
|
310 |
* && o2.getScheduledTimestamp() != null) { return
|
|
|
311 |
* o1.getScheduledTimestamp().isBefore(o2.getScheduledTimestamp()) ? -1 : 1; }
|
|
|
312 |
* else if (o1.getScheduledTimestamp() != null) { return 1; } else { return -1;
|
|
|
313 |
* } });
|
|
|
314 |
*/
|
| 30306 |
tejbeer |
315 |
|
| 31677 |
amit.gupta |
316 |
} else {
|
|
|
317 |
leads = leadRepository.selectByAssignAuthIdAndStatus(authUser.getId(), status);
|
| 30294 |
tejbeer |
318 |
|
| 31677 |
amit.gupta |
319 |
}
|
| 25979 |
tejbeer |
320 |
|
| 31677 |
amit.gupta |
321 |
return responseSender.ok(leads);
|
| 25899 |
tejbeer |
322 |
|
| 31677 |
amit.gupta |
323 |
}
|
| 25899 |
tejbeer |
324 |
|
| 31677 |
amit.gupta |
325 |
@RequestMapping(value = "/getlead", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
326 |
@ApiImplicitParams({
|
|
|
327 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
328 |
public ResponseEntity<?> getLead(HttpServletRequest request, @RequestParam(name = "id") int id)
|
|
|
329 |
throws ProfitMandiBusinessException {
|
| 25899 |
tejbeer |
330 |
|
| 31677 |
amit.gupta |
331 |
List<LeadActivity> leadActivities = leadActivityRepository.selectBYLeadId(id);
|
|
|
332 |
Lead lead = leadRepository.selectById(id);
|
|
|
333 |
lead.setLeadActivities(leadActivities);
|
|
|
334 |
return responseSender.ok(lead);
|
| 25899 |
tejbeer |
335 |
|
| 31677 |
amit.gupta |
336 |
}
|
| 25899 |
tejbeer |
337 |
|
| 31677 |
amit.gupta |
338 |
@RequestMapping(value = "/leadUpdate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
339 |
@ApiImplicitParams({
|
|
|
340 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
341 |
public ResponseEntity<?> leadUpdate(HttpServletRequest request, @RequestParam(name = "id") int id,
|
|
|
342 |
@RequestParam(name = "status") LeadStatus status, @RequestParam(name = "colorCheck") Boolean colorCheck,
|
|
|
343 |
@RequestParam(name = "remark") String remark, @RequestParam(name = "reason") String reason,
|
|
|
344 |
@RequestParam(name = "schelduleTimestamp") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime schelduleTimestamp,
|
|
|
345 |
@RequestParam(name = "closureTimestamp") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime closureTimestamp,
|
|
|
346 |
@RequestParam(name = "communicationType") CommunicationType communicationType)
|
|
|
347 |
throws ProfitMandiBusinessException {
|
| 25899 |
tejbeer |
348 |
|
| 31677 |
amit.gupta |
349 |
Lead lead = leadRepository.selectById(id);
|
| 25899 |
tejbeer |
350 |
|
| 31677 |
amit.gupta |
351 |
LeadActivity leadActivity = new LeadActivity();
|
|
|
352 |
lead.setStatus(status);
|
|
|
353 |
lead.setNotinterestedReason(reason);
|
|
|
354 |
leadActivity.setRemark(remark);
|
|
|
355 |
leadActivity.setLeadId(id);
|
|
|
356 |
leadActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
357 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
358 |
leadActivity.setClosureTimestamp(null);
|
|
|
359 |
leadActivity.setAuthId(lead.getAssignTo());
|
|
|
360 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
361 |
if (colorCheck == true) {
|
|
|
362 |
lead.setColor("Green");
|
|
|
363 |
} else {
|
|
|
364 |
lead.setColor("Yellow");
|
|
|
365 |
}
|
|
|
366 |
if (status == LeadStatus.followUp) {
|
| 25899 |
tejbeer |
367 |
|
| 31677 |
amit.gupta |
368 |
if (schelduleTimestamp != null) {
|
| 31249 |
tejbeer |
369 |
|
| 31677 |
amit.gupta |
370 |
leadActivity.setCommunicationType(communicationType);
|
| 31249 |
tejbeer |
371 |
|
| 31677 |
amit.gupta |
372 |
if (leadActivity.getCommunicationType().equals(CommunicationType.VISIT)) {
|
| 31249 |
tejbeer |
373 |
|
| 31677 |
amit.gupta |
374 |
visitRequestRepository.createVisitRequest(lead.getId(), "lead", lead.getAssignTo(),
|
|
|
375 |
schelduleTimestamp);
|
|
|
376 |
}
|
| 31249 |
tejbeer |
377 |
|
| 31677 |
amit.gupta |
378 |
}
|
|
|
379 |
leadActivity.setSchelduleTimestamp(schelduleTimestamp);
|
|
|
380 |
leadActivity.setClosureTimestamp(closureTimestamp);
|
|
|
381 |
lead.setClosureTimestamp(closureTimestamp);
|
| 26250 |
tejbeer |
382 |
|
| 31677 |
amit.gupta |
383 |
} else {
|
| 26250 |
tejbeer |
384 |
|
| 31677 |
amit.gupta |
385 |
leadActivity.setSchelduleTimestamp(null);
|
|
|
386 |
leadActivity.setClosureTimestamp(null);
|
|
|
387 |
lead.setClosureTimestamp(null);
|
| 26244 |
tejbeer |
388 |
|
| 31677 |
amit.gupta |
389 |
}
|
|
|
390 |
leadActivityRepository.persist(leadActivity);
|
|
|
391 |
return responseSender.ok(true);
|
| 25899 |
tejbeer |
392 |
|
| 31677 |
amit.gupta |
393 |
}
|
| 25952 |
tejbeer |
394 |
|
| 31677 |
amit.gupta |
395 |
@RequestMapping(value = ProfitMandiConstants.URL_NEW_LEAD, method = RequestMethod.POST)
|
|
|
396 |
public ResponseEntity<?> newLead(HttpServletRequest request,
|
|
|
397 |
@RequestBody CreateRefferalRequest createRefferalRequest) throws ProfitMandiBusinessException {
|
|
|
398 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
399 |
Lead lead = new Lead();
|
|
|
400 |
lead.setAddress(createRefferalRequest.getCity());
|
|
|
401 |
Long.parseLong(createRefferalRequest.getMobile());
|
|
|
402 |
if (createRefferalRequest.getMobile().length() != 10) {
|
|
|
403 |
throw new ProfitMandiBusinessException("Mobile Number", createRefferalRequest.getMobile(),
|
|
|
404 |
"Number should be of 10 digits");
|
|
|
405 |
}
|
|
|
406 |
lead.setLeadMobile(createRefferalRequest.getMobile());
|
|
|
407 |
lead.setCity(createRefferalRequest.getCity());
|
|
|
408 |
lead.setState(createRefferalRequest.getState());
|
|
|
409 |
lead.setLastName(createRefferalRequest.getLastName());
|
|
|
410 |
if (lead.getState().equals("Uttar Pradesh")) {
|
|
|
411 |
lead.setAssignTo(53);
|
|
|
412 |
} else if (lead.getState().equals("Haryana")) {
|
|
|
413 |
lead.setAssignTo(53);
|
|
|
414 |
} else if (lead.getState().equals("Delhi")) {
|
|
|
415 |
lead.setAssignTo(53);
|
|
|
416 |
} else {
|
|
|
417 |
// Assign to sm
|
|
|
418 |
lead.setAssignTo(53);
|
|
|
419 |
// Assign to neha
|
|
|
420 |
// lead.setAssignTo(1);
|
|
|
421 |
}
|
|
|
422 |
lead.setAuthId(lead.getAssignTo());
|
|
|
423 |
lead.setCreatedBy("daily-sync");
|
|
|
424 |
lead.setSource("SD-WEB");
|
|
|
425 |
lead.setFirstName(createRefferalRequest.getFirstName());
|
|
|
426 |
lead.setStatus(LeadStatus.followUp);
|
|
|
427 |
lead.setColor("yellow");
|
|
|
428 |
lead.setCreatedTimestamp(LocalDateTime.now());
|
|
|
429 |
lead.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
430 |
leadRepository.persist(lead);
|
| 27117 |
tejbeer |
431 |
|
| 31677 |
amit.gupta |
432 |
return responseSender.ok(true);
|
| 27117 |
tejbeer |
433 |
|
| 31677 |
amit.gupta |
434 |
}
|
| 27117 |
tejbeer |
435 |
|
| 31677 |
amit.gupta |
436 |
@RequestMapping(value = "/getPartnersList", method = RequestMethod.GET)
|
|
|
437 |
@ApiImplicitParams({
|
|
|
438 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
439 |
public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId)
|
|
|
440 |
throws ProfitMandiBusinessException {
|
| 25952 |
tejbeer |
441 |
|
| 31677 |
amit.gupta |
442 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
| 25952 |
tejbeer |
443 |
|
| 31677 |
amit.gupta |
444 |
Map<String, Set<String>> storeGuyMap = csService.getAuthUserPartnerEmailMapping();
|
| 25952 |
tejbeer |
445 |
|
| 31677 |
amit.gupta |
446 |
Set<String> emails = storeGuyMap.get(authUser.getEmailId());
|
|
|
447 |
LOGGER.info("emails" + emails);
|
|
|
448 |
List<User> users = userRepository.selectAllByEmailIds(new ArrayList<>(emails));
|
|
|
449 |
List<Partner> partners = new ArrayList<>();
|
|
|
450 |
for (User user : users) {
|
| 25952 |
tejbeer |
451 |
|
| 31677 |
amit.gupta |
452 |
UserAccount uc = userAccountRepository.selectSaholicByUserId(user.getId());
|
|
|
453 |
com.spice.profitmandi.dao.entity.user.User userInfo = userUserRepository.selectById(uc.getAccountKey());
|
|
|
454 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(userInfo.getId());
|
| 25952 |
tejbeer |
455 |
|
| 31677 |
amit.gupta |
456 |
Partner partner = new Partner();
|
|
|
457 |
partner.setBusinessName(customRetailer.getBusinessName());
|
|
|
458 |
partner.setPartnerId(customRetailer.getPartnerId());
|
|
|
459 |
partner.setCartId(customRetailer.getCartId());
|
|
|
460 |
partner.setEmail(customRetailer.getEmail());
|
|
|
461 |
partner.setGstNumber(customRetailer.getGstNumber());
|
|
|
462 |
partner.setDisplayName(customRetailer.getDisplayName());
|
|
|
463 |
partner.setCity(customRetailer.getAddress().getCity());
|
|
|
464 |
partner.setUserId(user.getId());
|
|
|
465 |
partners.add(partner);
|
|
|
466 |
}
|
|
|
467 |
LOGGER.info("partners" + partners);
|
|
|
468 |
return responseSender.ok(partners);
|
|
|
469 |
}
|
| 25952 |
tejbeer |
470 |
|
| 31677 |
amit.gupta |
471 |
@RequestMapping(value = "/franchise-first-visit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
472 |
@ApiImplicitParams({
|
|
|
473 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
474 |
public ResponseEntity<?> FranchiseFirstVisit(HttpServletRequest request,
|
|
|
475 |
@RequestBody CreateFranchiseeRequest createFranchiseeRequest) throws Exception {
|
| 25952 |
tejbeer |
476 |
|
| 31677 |
amit.gupta |
477 |
FranchiseeVisit franchiseeVisit = new FranchiseeVisit();
|
|
|
478 |
franchiseeVisit.setFofoId(createFranchiseeRequest.getFofoId());
|
|
|
479 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(createFranchiseeRequest.getFofoId());
|
| 25952 |
tejbeer |
480 |
|
| 31677 |
amit.gupta |
481 |
franchiseeVisit.setPartnerName(customRetailer.getBusinessName());
|
|
|
482 |
franchiseeVisit.setAgenda(createFranchiseeRequest.getAgenda());
|
|
|
483 |
franchiseeVisit.setCreatedTimestamp(LocalDateTime.now());
|
|
|
484 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
485 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.OPEN);
|
|
|
486 |
franchiseeVisit.setScheduleTimestamp(createFranchiseeRequest.getFirstSchelduleTimestamp());
|
|
|
487 |
// change
|
|
|
488 |
AuthUser authUser = authRepository.selectByGmailId(createFranchiseeRequest.getCreatedBy());
|
| 25952 |
tejbeer |
489 |
|
| 31677 |
amit.gupta |
490 |
String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
491 |
franchiseeVisit.setCreatedBy(authUserName);
|
|
|
492 |
franchiseeVisit.setAuthId(authUser.getId());
|
| 25952 |
tejbeer |
493 |
|
| 31677 |
amit.gupta |
494 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| 25952 |
tejbeer |
495 |
|
| 31677 |
amit.gupta |
496 |
FranchiseeActivity franchiseeActivity = new FranchiseeActivity();
|
|
|
497 |
franchiseeActivity.setAction(FranchiseeActivityStatus.FOLLOWUP);
|
|
|
498 |
franchiseeActivity.setFranchiseeVisitd(franchiseeVisit.getId());
|
|
|
499 |
franchiseeActivity.setResolution(createFranchiseeRequest.getResolution());
|
|
|
500 |
franchiseeActivity.setSchelduleTimestamp(createFranchiseeRequest.getFirstSchelduleTimestamp());
|
| 31249 |
tejbeer |
501 |
|
| 31677 |
amit.gupta |
502 |
franchiseeActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
503 |
franchiseeActivityRepository.persist(franchiseeActivity);
|
| 31249 |
tejbeer |
504 |
|
| 31677 |
amit.gupta |
505 |
franchiseeVisit.setFranchiseActivityId(franchiseeActivity.getId());
|
| 31249 |
tejbeer |
506 |
|
| 31677 |
amit.gupta |
507 |
visitRequestRepository.createVisitRequest(franchiseeVisit.getId(), "franchiseeVisit", authUser.getId(),
|
|
|
508 |
createFranchiseeRequest.getFirstSchelduleTimestamp());
|
| 31249 |
tejbeer |
509 |
|
| 31677 |
amit.gupta |
510 |
return responseSender.ok(true);
|
|
|
511 |
}
|
| 25952 |
tejbeer |
512 |
|
| 31677 |
amit.gupta |
513 |
@RequestMapping(value = "/franchise-visit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
514 |
@ApiImplicitParams({
|
|
|
515 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
516 |
public ResponseEntity<?> FranchiseVisit(HttpServletRequest request,
|
|
|
517 |
@RequestBody CreateFranchiseeRequest createFranchiseeRequest) throws Exception {
|
| 25952 |
tejbeer |
518 |
|
| 31677 |
amit.gupta |
519 |
FranchiseeVisit franchiseeVisit = franchiseeVisitRepository.selectById(createFranchiseeRequest.getId());
|
|
|
520 |
franchiseeVisit.setFofoId(createFranchiseeRequest.getFofoId());
|
|
|
521 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(createFranchiseeRequest.getFofoId());
|
| 25952 |
tejbeer |
522 |
|
| 31677 |
amit.gupta |
523 |
franchiseeVisit.setPartnerName(customRetailer.getBusinessName());
|
|
|
524 |
franchiseeVisit.setAgenda(createFranchiseeRequest.getAgenda());
|
|
|
525 |
franchiseeVisit.setPartnerRemark(createFranchiseeRequest.getPartnerRemark());
|
|
|
526 |
franchiseeVisit.setOutsideVisibity(createFranchiseeRequest.getOutsideVisibity());
|
|
|
527 |
franchiseeVisit.setInstoreVisibility(createFranchiseeRequest.getInstoreVisibility());
|
|
|
528 |
franchiseeVisit.setOutsideStock(createFranchiseeRequest.getOutsideStock());
|
|
|
529 |
franchiseeVisit.setSystemKnowledge(createFranchiseeRequest.getSystemKnowledge());
|
|
|
530 |
franchiseeVisit.setWorkingDevice(createFranchiseeRequest.getWorkingDevice());
|
|
|
531 |
franchiseeVisit.setWorkingPrinter(createFranchiseeRequest.getWorkingPrinter());
|
|
|
532 |
franchiseeVisit.setCarryBags(createFranchiseeRequest.getCarryBags());
|
|
|
533 |
franchiseeVisit.setSmartdukaanTshirt(createFranchiseeRequest.getSmartdukaanTshirt());
|
|
|
534 |
franchiseeVisit.setLatestDummies(createFranchiseeRequest.getLatestDummies());
|
|
|
535 |
franchiseeVisit.setInvestment(createFranchiseeRequest.getInvestment());
|
|
|
536 |
franchiseeVisit.setMtd(createFranchiseeRequest.getMtd());
|
|
|
537 |
franchiseeVisit.setHygiene(createFranchiseeRequest.getHygiene());
|
|
|
538 |
franchiseeVisit.setCreatedTimestamp(LocalDateTime.now());
|
|
|
539 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
540 |
franchiseeVisit.setInformedAboutOnline(createFranchiseeRequest.getOnline());
|
|
|
541 |
franchiseeVisit.setPendingBilling(createFranchiseeRequest.getPendingBilling());
|
|
|
542 |
if (createFranchiseeRequest.getAction().equals(FranchiseeActivityStatus.FOLLOWUP)) {
|
|
|
543 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.OPEN);
|
|
|
544 |
} else {
|
|
|
545 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.CLOSE);
|
|
|
546 |
}
|
| 25952 |
tejbeer |
547 |
|
| 31677 |
amit.gupta |
548 |
// AuthUser authUser =
|
|
|
549 |
// authRepository.selectByGmailId(createFranchiseeRequest.getCreatedBy());
|
|
|
550 |
// change
|
|
|
551 |
AuthUser authUser = authRepository.selectByGmailId(createFranchiseeRequest.getCreatedBy());
|
| 25952 |
tejbeer |
552 |
|
| 31677 |
amit.gupta |
553 |
String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
554 |
franchiseeVisit.setCreatedBy(authUserName);
|
|
|
555 |
franchiseeVisit.setAuthId(authUser.getId());
|
| 25952 |
tejbeer |
556 |
|
| 31677 |
amit.gupta |
557 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| 25952 |
tejbeer |
558 |
|
| 31677 |
amit.gupta |
559 |
FranchiseeActivity franchiseeActivity = new FranchiseeActivity();
|
|
|
560 |
franchiseeActivity.setAction(createFranchiseeRequest.getAction());
|
|
|
561 |
franchiseeActivity.setFranchiseeVisitd(franchiseeVisit.getId());
|
|
|
562 |
franchiseeActivity.setResolution(createFranchiseeRequest.getResolution());
|
|
|
563 |
if (createFranchiseeRequest.getAction().equals(FranchiseeActivityStatus.FOLLOWUP)) {
|
|
|
564 |
franchiseeActivity.setSchelduleTimestamp(createFranchiseeRequest.getSchelduleTimestamp());
|
| 31249 |
tejbeer |
565 |
|
| 31677 |
amit.gupta |
566 |
visitRequestRepository.createVisitRequest(franchiseeVisit.getId(), "franchiseeVisit",
|
|
|
567 |
franchiseeVisit.getAuthId(), createFranchiseeRequest.getSchelduleTimestamp());
|
|
|
568 |
} else {
|
|
|
569 |
franchiseeActivity.setSchelduleTimestamp(null);
|
|
|
570 |
}
|
|
|
571 |
franchiseeActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
572 |
franchiseeActivityRepository.persist(franchiseeActivity);
|
| 25952 |
tejbeer |
573 |
|
| 31677 |
amit.gupta |
574 |
franchiseeVisit.setFranchiseActivityId(franchiseeActivity.getId());
|
|
|
575 |
return responseSender.ok(true);
|
|
|
576 |
}
|
| 25952 |
tejbeer |
577 |
|
| 31677 |
amit.gupta |
578 |
@RequestMapping(value = "/getFranchiseVisit", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
579 |
@ApiImplicitParams({
|
|
|
580 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
581 |
public ResponseEntity<?> getFranchiseVisit(HttpServletRequest request,
|
|
|
582 |
@RequestParam(name = "gmailId") String gmailId, @RequestParam(name = "status") FranchiseeVisitStatus status,
|
|
|
583 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
584 |
@RequestParam(name = "limit", defaultValue = "10") int limit) throws ProfitMandiBusinessException {
|
|
|
585 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
|
|
586 |
List<VisitRequest> visitRequests = visitRequestRepository.selectByAuthIdAndDate(authUser.getId(),
|
|
|
587 |
LocalDate.now());
|
|
|
588 |
Map<Integer, List<VisitRequest>> visitRequestMap = null;
|
|
|
589 |
if (!visitRequests.isEmpty()) {
|
|
|
590 |
visitRequestMap = visitRequests.stream().collect(Collectors.groupingBy(x -> x.getVisitId()));
|
|
|
591 |
}
|
|
|
592 |
List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository.selectByAuthIdAndStatus(authUser.getId(),
|
|
|
593 |
status, offset, limit);
|
| 25952 |
tejbeer |
594 |
|
| 31677 |
amit.gupta |
595 |
for (FranchiseeVisit fv : franchiseeVisits) {
|
|
|
596 |
if (visitRequestMap != null) {
|
| 31249 |
tejbeer |
597 |
|
| 31677 |
amit.gupta |
598 |
List<VisitRequest> visitRequest = visitRequestMap.get(fv.getId());
|
|
|
599 |
if (visitRequest != null) {
|
|
|
600 |
if (visitRequest.size() > 1) {
|
| 31249 |
tejbeer |
601 |
|
| 31677 |
amit.gupta |
602 |
Comparator<VisitRequest> visitComparato = Comparator
|
|
|
603 |
.comparing(VisitRequest::getCreatedTimestamp);
|
| 31249 |
tejbeer |
604 |
|
| 31677 |
amit.gupta |
605 |
VisitRequest youngestVisit = visitRequest.stream().max(visitComparato).get();
|
|
|
606 |
fv.setVisitStatus(youngestVisit.getStatus());
|
| 31249 |
tejbeer |
607 |
|
| 31677 |
amit.gupta |
608 |
} else {
|
|
|
609 |
fv.setVisitStatus(visitRequest.get(0).getStatus());
|
| 31249 |
tejbeer |
610 |
|
| 31677 |
amit.gupta |
611 |
}
|
|
|
612 |
}
|
|
|
613 |
}
|
|
|
614 |
if (fv.getFranchiseActivityId() != 0) {
|
|
|
615 |
FranchiseeActivity fA = franchiseeActivityRepository.selectById(fv.getFranchiseActivityId());
|
|
|
616 |
fv.setFranchiseeActivity(fA);
|
|
|
617 |
}
|
| 31249 |
tejbeer |
618 |
|
| 31677 |
amit.gupta |
619 |
}
|
| 25952 |
tejbeer |
620 |
|
| 31677 |
amit.gupta |
621 |
return responseSender.ok(franchiseeVisits);
|
| 25952 |
tejbeer |
622 |
|
| 31677 |
amit.gupta |
623 |
}
|
| 25952 |
tejbeer |
624 |
|
| 31677 |
amit.gupta |
625 |
@RequestMapping(value = "/getFranchiseActivity", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
626 |
@ApiImplicitParams({
|
|
|
627 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
628 |
public ResponseEntity<?> getFranchiseActivity(HttpServletRequest request, @RequestParam(name = "id") int id)
|
|
|
629 |
throws ProfitMandiBusinessException {
|
| 25952 |
tejbeer |
630 |
|
| 31677 |
amit.gupta |
631 |
List<FranchiseeActivity> franchiseeActivities = franchiseeActivityRepository.selectByFranchiseeVisitId(id);
|
|
|
632 |
return responseSender.ok(franchiseeActivities);
|
| 25952 |
tejbeer |
633 |
|
| 31677 |
amit.gupta |
634 |
}
|
| 25952 |
tejbeer |
635 |
|
| 31677 |
amit.gupta |
636 |
@RequestMapping(value = "/getFranchiseeInfo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
637 |
@ApiImplicitParams({
|
|
|
638 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
639 |
public ResponseEntity<?> getFranchiseeInfo(HttpServletRequest request, @RequestParam(name = "id") int id)
|
|
|
640 |
throws ProfitMandiBusinessException {
|
|
|
641 |
FranchiseeVisit franchiseeVisit = franchiseeVisitRepository.selectById(id);
|
| 25952 |
tejbeer |
642 |
|
| 31677 |
amit.gupta |
643 |
List<DBObject> mobileBrands = mongoClient.getAllBrandsToDisplay(3);
|
| 30487 |
tejbeer |
644 |
|
| 31677 |
amit.gupta |
645 |
List<String> brands = mobileBrands.stream().filter(x -> (boolean) x.get("active"))
|
|
|
646 |
.map(x -> (String) x.get("name")).collect(Collectors.toList());
|
| 30487 |
tejbeer |
647 |
|
| 31677 |
amit.gupta |
648 |
franchiseeVisit.setBrands(brands);
|
| 30487 |
tejbeer |
649 |
|
| 31677 |
amit.gupta |
650 |
return responseSender.ok(franchiseeVisit);
|
| 25952 |
tejbeer |
651 |
|
| 31677 |
amit.gupta |
652 |
}
|
| 25952 |
tejbeer |
653 |
|
| 31677 |
amit.gupta |
654 |
@RequestMapping(value = "/franchise-visit-update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
655 |
@ApiImplicitParams({
|
|
|
656 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
657 |
public ResponseEntity<?> franchiseVisitUpdate(HttpServletRequest request, @RequestParam(name = "id") int id,
|
|
|
658 |
@RequestParam(name = "action") FranchiseeActivityStatus action,
|
|
|
659 |
@RequestParam(name = "resolution") String resolution,
|
|
|
660 |
@RequestParam(name = "schelduleTimestamp") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime schelduleTimestamp)
|
|
|
661 |
throws ProfitMandiBusinessException {
|
|
|
662 |
FranchiseeVisit franchiseeVisit = franchiseeVisitRepository.selectById(id);
|
| 25952 |
tejbeer |
663 |
|
| 31677 |
amit.gupta |
664 |
FranchiseeActivity franchiseeActivity = new FranchiseeActivity();
|
| 25952 |
tejbeer |
665 |
|
| 31677 |
amit.gupta |
666 |
if (action == FranchiseeActivityStatus.FOLLOWUP) {
|
| 30487 |
tejbeer |
667 |
|
| 31677 |
amit.gupta |
668 |
if (schelduleTimestamp != null) {
|
| 31249 |
tejbeer |
669 |
|
| 31677 |
amit.gupta |
670 |
visitRequestRepository.createVisitRequest(franchiseeVisit.getId(), "franchiseeVisit",
|
|
|
671 |
franchiseeVisit.getAuthId(), schelduleTimestamp);
|
|
|
672 |
}
|
| 31249 |
tejbeer |
673 |
|
| 31677 |
amit.gupta |
674 |
franchiseeActivity.setSchelduleTimestamp(schelduleTimestamp);
|
|
|
675 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.OPEN);
|
|
|
676 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
677 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| 25952 |
tejbeer |
678 |
|
| 31677 |
amit.gupta |
679 |
} else {
|
| 30487 |
tejbeer |
680 |
|
| 31677 |
amit.gupta |
681 |
franchiseeActivity.setSchelduleTimestamp(null);
|
|
|
682 |
franchiseeVisit.setFranchiseActivityId(franchiseeActivity.getId());
|
|
|
683 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.CLOSE);
|
|
|
684 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
685 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| 25952 |
tejbeer |
686 |
|
| 31677 |
amit.gupta |
687 |
}
|
| 25952 |
tejbeer |
688 |
|
| 31677 |
amit.gupta |
689 |
franchiseeActivity.setResolution(resolution);
|
|
|
690 |
franchiseeActivity.setFranchiseeVisitd(franchiseeVisit.getId());
|
|
|
691 |
franchiseeActivity.setAction(action);
|
| 30487 |
tejbeer |
692 |
|
| 31677 |
amit.gupta |
693 |
franchiseeActivity.setCreatedTimestamp(LocalDateTime.now());
|
|
|
694 |
franchiseeActivityRepository.persist(franchiseeActivity);
|
| 30487 |
tejbeer |
695 |
|
| 31677 |
amit.gupta |
696 |
franchiseeVisit.setFranchiseActivityId(franchiseeActivity.getId());
|
|
|
697 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.OPEN);
|
|
|
698 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
699 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| 30487 |
tejbeer |
700 |
|
| 31677 |
amit.gupta |
701 |
return responseSender.ok(true);
|
| 25952 |
tejbeer |
702 |
|
| 31677 |
amit.gupta |
703 |
}
|
| 28935 |
tejbeer |
704 |
|
| 31677 |
amit.gupta |
705 |
@RequestMapping(value = "/onBoardingTimelineStatus", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
706 |
@ApiImplicitParams({
|
|
|
707 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
708 |
public ResponseEntity<?> onBoardingTimelineStatus(HttpServletRequest request, Model model)
|
|
|
709 |
throws ProfitMandiBusinessException {
|
|
|
710 |
int userId = (int) request.getAttribute("userId");
|
|
|
711 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
712 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(uc.getUserId());
|
|
|
713 |
PartnerOnBoardingPanel partnerOnBoardingPanel = partnerOnBoardingPanelRepository.selectByCode(fs.getCode());
|
|
|
714 |
Map<StoreTimeline, OnBoardingTimelineModel> timelineStatus = null;
|
|
|
715 |
LOGGER.info("partnerOnBoardingPanel" + partnerOnBoardingPanel);
|
|
|
716 |
if (partnerOnBoardingPanel != null) {
|
| 28935 |
tejbeer |
717 |
|
| 31677 |
amit.gupta |
718 |
timelineStatus = storeTimelineTatService.getTimeline(partnerOnBoardingPanel.getId());
|
|
|
719 |
}
|
|
|
720 |
List<OnBoardingTimelineModel> onBoardingModel = new ArrayList<>();
|
|
|
721 |
if (timelineStatus != null) {
|
|
|
722 |
onBoardingModel = timelineStatus.values().stream().skip(2).map(x -> x).collect(Collectors.toList());
|
|
|
723 |
}
|
|
|
724 |
return responseSender.ok(onBoardingModel);
|
| 28935 |
tejbeer |
725 |
|
| 31677 |
amit.gupta |
726 |
}
|
| 28982 |
tejbeer |
727 |
|
| 31677 |
amit.gupta |
728 |
@RequestMapping(value = "/onBoardingTimelineVisibility", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
729 |
@ApiImplicitParams({
|
|
|
730 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
731 |
public ResponseEntity<?> onBoardingTimelineVisibility(HttpServletRequest request, Model model)
|
|
|
732 |
throws ProfitMandiBusinessException {
|
|
|
733 |
int userId = (int) request.getAttribute("userId");
|
|
|
734 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| 28982 |
tejbeer |
735 |
|
| 31677 |
amit.gupta |
736 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(uc.getUserId());
|
|
|
737 |
PartnerOnBoardingPanel partnerOnBoardingPanel = partnerOnBoardingPanelRepository.selectByCode(fs.getCode());
|
|
|
738 |
boolean status = true;
|
|
|
739 |
if (partnerOnBoardingPanel != null) {
|
| 28982 |
tejbeer |
740 |
|
| 31677 |
amit.gupta |
741 |
status = storeTimelineTatService.getTimelineCompleted(partnerOnBoardingPanel.getId());
|
|
|
742 |
}
|
| 28982 |
tejbeer |
743 |
|
| 31677 |
amit.gupta |
744 |
LOGGER.info("status" + status);
|
| 28983 |
tejbeer |
745 |
|
| 31677 |
amit.gupta |
746 |
return responseSender.ok(status);
|
| 28982 |
tejbeer |
747 |
|
| 31677 |
amit.gupta |
748 |
}
|
| 30077 |
tejbeer |
749 |
|
| 31677 |
amit.gupta |
750 |
@RequestMapping(value = "/getPartnerTarget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
751 |
@ApiImplicitParams({
|
|
|
752 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
753 |
public ResponseEntity<?> getPartnerTarget(HttpServletRequest request,
|
|
|
754 |
@RequestParam String gmailId, @RequestParam String dayValue, @RequestParam ActivationType activationType)
|
|
|
755 |
throws ProfitMandiBusinessException {
|
| 30077 |
tejbeer |
756 |
|
| 31677 |
amit.gupta |
757 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
|
|
758 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
|
|
759 |
Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
|
|
|
760 |
List<String> brands = Arrays.asList("Vivo", "Samsung", "Oppo", "Itel", "Almost New", "Others");
|
| 30078 |
tejbeer |
761 |
|
| 31677 |
amit.gupta |
762 |
float totalPartnerTargetSecondary = 0;
|
|
|
763 |
float totalPartnerTargetCollection = 0;
|
|
|
764 |
float totalPartnerAchievementSecondary = 0;
|
|
|
765 |
float totalPartnerAchievementCollection = 0;
|
|
|
766 |
TargetModel tm = new TargetModel();
|
|
|
767 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
|
|
|
768 |
Map<Integer, Long> partnerTicketCount = ticketRepository.selectAllOpenTicketsGroupByRetailer();
|
| 30416 |
tejbeer |
769 |
|
| 31677 |
amit.gupta |
770 |
LOGGER.info("partnerTicketCount {}", partnerTicketCount);
|
| 30416 |
tejbeer |
771 |
|
| 31677 |
amit.gupta |
772 |
List<PartnerTargetAchievementModel> ptams = new ArrayList<>();
|
| 30077 |
tejbeer |
773 |
|
| 31677 |
amit.gupta |
774 |
if (fofoIds != null && fofoIds.size() > 0) {
|
| 32737 |
amit.gupta |
775 |
LOGGER.info("fofoIds {}", fofoIds);
|
| 31727 |
amit.gupta |
776 |
List<Integer> fofoIdList = fofoStoreRepository.selectByRetailerIds(new ArrayList<>(fofoIds)).stream()
|
| 31677 |
amit.gupta |
777 |
.filter(x -> (!x.isInternal() && (activationType == null || x.getActivationType().equals(activationType))))
|
|
|
778 |
.map(x -> x.getId()).collect(Collectors.toList());
|
| 32737 |
amit.gupta |
779 |
LOGGER.info("fofoIdList {}", fofoIdList);
|
| 31677 |
amit.gupta |
780 |
LocalDateTime startDate = LocalDate.now().atStartOfDay();
|
| 30077 |
tejbeer |
781 |
|
| 31677 |
amit.gupta |
782 |
if (dayValue.equals("previous")) {
|
|
|
783 |
startDate = LocalDate.now().minusDays(1).atStartOfDay();
|
| 30138 |
tejbeer |
784 |
|
| 31677 |
amit.gupta |
785 |
}
|
| 30087 |
tejbeer |
786 |
|
| 31686 |
amit.gupta |
787 |
if (fofoIdList.size() > 0) {
|
| 30453 |
tejbeer |
788 |
|
| 31686 |
amit.gupta |
789 |
List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
|
|
|
790 |
.selectAll(fofoIdList, startDate.toLocalDate().minusDays(1));
|
| 30087 |
tejbeer |
791 |
|
| 31686 |
amit.gupta |
792 |
if (!partnerDailyInvestments.isEmpty()) {
|
|
|
793 |
partnerDailyInvestmentMap = partnerDailyInvestments.stream()
|
|
|
794 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
795 |
}
|
| 30077 |
tejbeer |
796 |
|
| 31686 |
amit.gupta |
797 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 30426 |
tejbeer |
798 |
|
| 31686 |
amit.gupta |
799 |
Map<Integer, CustomRetailer> customRetailers = fofoIdList.stream().map(x -> customRetailerMap.get(x))
|
|
|
800 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
801 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 30330 |
tejbeer |
802 |
|
| 31686 |
amit.gupta |
803 |
List<Integer> remarkIds = partnerCollectionRemarkRepository.selectMaxRemarkId(fofoIdList);
|
| 30453 |
tejbeer |
804 |
|
| 31686 |
amit.gupta |
805 |
LOGGER.info("remarkIds {}", remarkIds);
|
| 30453 |
tejbeer |
806 |
|
| 31686 |
amit.gupta |
807 |
long todayCollectionCount = 0;
|
|
|
808 |
if (!remarkIds.isEmpty()) {
|
|
|
809 |
todayCollectionCount = partnerCollectionRemarkRepository
|
|
|
810 |
.selectByAuthIdAndIds(authUser.getId(), remarkIds).stream()
|
|
|
811 |
.filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now()))
|
|
|
812 |
.collect(Collectors.counting());
|
| 30453 |
tejbeer |
813 |
|
| 31686 |
amit.gupta |
814 |
}
|
| 30330 |
tejbeer |
815 |
|
| 31686 |
amit.gupta |
816 |
Map<Integer, PartnerCollectionPlanModel> CollectionMap = partnerCollectionService
|
|
|
817 |
.getCollectionMap(fofoIdList, startDate);
|
| 30077 |
tejbeer |
818 |
|
| 31686 |
amit.gupta |
819 |
Map<Integer, List<PartnerSecondaryPlanModel>> partnerSecondayPlans = orderRepository
|
|
|
820 |
.selectPartnerSecondaryGroupByBrand(fofoIdList, startDate.toLocalDate()).stream()
|
|
|
821 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 30077 |
tejbeer |
822 |
|
| 31686 |
amit.gupta |
823 |
LOGGER.info("partnerSecondayPlans {}", partnerSecondayPlans);
|
|
|
824 |
for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailers.entrySet()) {
|
|
|
825 |
int fofoId = customRetailerEntry.getKey();
|
|
|
826 |
CustomRetailer customRetailer = customRetailerEntry.getValue();
|
|
|
827 |
float totalSecondaryPlan = 0;
|
|
|
828 |
float totalSecondaryAchivement = 0;
|
| 30077 |
tejbeer |
829 |
|
| 31686 |
amit.gupta |
830 |
PartnerTargetAchievementModel ptam = new PartnerTargetAchievementModel();
|
|
|
831 |
ptam.setFofoId(fofoId);
|
|
|
832 |
ptam.setBusinessName(customRetailer.getBusinessName());
|
|
|
833 |
ptam.setMobile(customRetailer.getMobileNumber());
|
| 30087 |
tejbeer |
834 |
|
| 31686 |
amit.gupta |
835 |
if (partnerDailyInvestmentMap.get(fofoId) != null) {
|
|
|
836 |
ptam.setWalletAmount(partnerDailyInvestmentMap.get(fofoId).getWalletAmount());
|
|
|
837 |
ptam.setShortInvestment(partnerDailyInvestmentMap.get(fofoId).getShortInvestment());
|
|
|
838 |
}
|
| 30808 |
tejbeer |
839 |
|
| 31686 |
amit.gupta |
840 |
if (CollectionMap.get(fofoId) != null) {
|
|
|
841 |
PartnerCollectionPlanModel collectionPlan = CollectionMap.get(fofoId);
|
| 30330 |
tejbeer |
842 |
|
| 31686 |
amit.gupta |
843 |
ptam.setRemark(collectionPlan.getRemark());
|
|
|
844 |
ptam.setMessage(collectionPlan.getMessage());
|
|
|
845 |
ptam.setRemarkTimestamp(collectionPlan.getRemarkTimestamp());
|
|
|
846 |
ptam.setRank(collectionPlan.getRank());
|
|
|
847 |
Integer authId = collectionPlan.getAuthId();
|
| 30330 |
tejbeer |
848 |
|
| 31686 |
amit.gupta |
849 |
Map<Integer, String> rankColorMap = ProfitMandiConstants.Rank_Color_Map;
|
| 30416 |
tejbeer |
850 |
|
| 31686 |
amit.gupta |
851 |
ptam.setCollectionColor(rankColorMap.get(collectionPlan.getRank()));
|
| 30077 |
tejbeer |
852 |
|
| 31686 |
amit.gupta |
853 |
LOGGER.info("authId" + authId);
|
| 30137 |
tejbeer |
854 |
|
| 31686 |
amit.gupta |
855 |
if (collectionPlan.getTargetPlan() != null && collectionPlan.getCommittedDate() != null) {
|
|
|
856 |
float targetCollection = 0;
|
| 30330 |
tejbeer |
857 |
|
| 31686 |
amit.gupta |
858 |
if (collectionPlan.getRank() == 2 && collectionPlan.getAchievementPlan() != null) {
|
|
|
859 |
targetCollection = collectionPlan.getTargetPlan() - collectionPlan.getAchievementPlan();
|
|
|
860 |
} else {
|
|
|
861 |
targetCollection = collectionPlan.getTargetPlan();
|
| 31677 |
amit.gupta |
862 |
}
|
| 30451 |
tejbeer |
863 |
|
| 31677 |
amit.gupta |
864 |
if (authId != null && authId == authUser.getId()) {
|
| 30822 |
tejbeer |
865 |
|
| 31686 |
amit.gupta |
866 |
if (!collectionPlan.getCommittedDate().isAfter(startDate)) {
|
|
|
867 |
totalPartnerTargetCollection += targetCollection;
|
|
|
868 |
}
|
| 31677 |
amit.gupta |
869 |
}
|
| 30822 |
tejbeer |
870 |
|
| 31686 |
amit.gupta |
871 |
ptam.setCollectionTarget(targetCollection);
|
|
|
872 |
|
|
|
873 |
if (collectionPlan.getRank() == 2 && collectionPlan.getAchievementPlan() != null
|
|
|
874 |
&& collectionPlan.getWalletTimestamp() != null
|
|
|
875 |
&& collectionPlan.getWalletTimestamp().toLocalDate().equals(startDate.toLocalDate())) {
|
|
|
876 |
if (authId != null && authId == authUser.getId()) {
|
|
|
877 |
|
|
|
878 |
totalPartnerAchievementCollection += collectionPlan.getAchievementPlan();
|
|
|
879 |
}
|
|
|
880 |
ptam.setCollectionAchievement(collectionPlan.getAchievementPlan());
|
|
|
881 |
} else if (collectionPlan.getCommittedDate().toLocalDate().isEqual(startDate.toLocalDate())
|
|
|
882 |
&& collectionPlan.getAchievementPlan() != null) {
|
|
|
883 |
if (authId != null && authId == authUser.getId()) {
|
|
|
884 |
|
|
|
885 |
totalPartnerAchievementCollection += collectionPlan.getAchievementPlan();
|
|
|
886 |
}
|
|
|
887 |
ptam.setCollectionAchievement(collectionPlan.getAchievementPlan());
|
|
|
888 |
|
| 31677 |
amit.gupta |
889 |
}
|
| 31686 |
amit.gupta |
890 |
}
|
| 30822 |
tejbeer |
891 |
|
| 31686 |
amit.gupta |
892 |
if (authId != null && authId != authUser.getId()) {
|
|
|
893 |
ptam.setAuthUser(authRepository.selectById(authId));
|
|
|
894 |
|
| 31677 |
amit.gupta |
895 |
}
|
| 30087 |
tejbeer |
896 |
|
| 31686 |
amit.gupta |
897 |
if (collectionPlan.getCommittedDate() != null) {
|
| 30087 |
tejbeer |
898 |
|
| 31686 |
amit.gupta |
899 |
ptam.setCollectionCommitmentDate(collectionPlan.getCommittedDate().toLocalDate());
|
|
|
900 |
}
|
| 30087 |
tejbeer |
901 |
|
| 31677 |
amit.gupta |
902 |
}
|
| 30821 |
tejbeer |
903 |
|
| 31686 |
amit.gupta |
904 |
// Secondary
|
| 30077 |
tejbeer |
905 |
|
| 31686 |
amit.gupta |
906 |
PartnerSecondaryPlanModel otherPartnerSecondaryPlanModel = null;
|
|
|
907 |
Map<String, PartnerSecondaryPlanModel> secondaryModelMap = new HashMap<>();
|
|
|
908 |
if (partnerSecondayPlans.get(fofoId) != null) {
|
|
|
909 |
long otherBrandSecondary = 0;
|
|
|
910 |
for (PartnerSecondaryPlanModel pspm : partnerSecondayPlans.get(fofoId)) {
|
|
|
911 |
Integer authId = pspm.getAuthId();
|
|
|
912 |
if (!brands.contains(pspm.getBrand())) {
|
|
|
913 |
if (pspm.getAchievementPlan() != null) {
|
|
|
914 |
otherBrandSecondary += pspm.getAchievementPlan();
|
|
|
915 |
}
|
|
|
916 |
} else {
|
|
|
917 |
otherPartnerSecondaryPlanModel = pspm;
|
|
|
918 |
}
|
|
|
919 |
if (pspm.getTargetPlan() != null) {
|
|
|
920 |
totalSecondaryPlan += pspm.getTargetPlan();
|
|
|
921 |
}
|
| 30330 |
tejbeer |
922 |
|
| 31677 |
amit.gupta |
923 |
if (pspm.getAchievementPlan() != null) {
|
| 31686 |
amit.gupta |
924 |
totalSecondaryAchivement += pspm.getAchievementPlan();
|
| 31677 |
amit.gupta |
925 |
}
|
| 30087 |
tejbeer |
926 |
|
| 31686 |
amit.gupta |
927 |
if (pspm.getCommittedDate() != null) {
|
| 30137 |
tejbeer |
928 |
|
| 31686 |
amit.gupta |
929 |
ptam.setSecondaryCommitmentDate(pspm.getCommittedDate().toLocalDate());
|
|
|
930 |
}
|
|
|
931 |
if (authId != null && authId == authUser.getId()) {
|
| 30137 |
tejbeer |
932 |
|
| 31686 |
amit.gupta |
933 |
if (pspm.getTargetPlan() != null && pspm.getCommittedDate() != null) {
|
| 30087 |
tejbeer |
934 |
|
| 31686 |
amit.gupta |
935 |
if (pspm.getCommittedDate().isEqual(startDate)) {
|
|
|
936 |
totalPartnerTargetSecondary += pspm.getTargetPlan();
|
|
|
937 |
}
|
|
|
938 |
}
|
| 30087 |
tejbeer |
939 |
|
| 31686 |
amit.gupta |
940 |
if (pspm.getAchievementPlan() != null) {
|
|
|
941 |
totalPartnerAchievementSecondary += pspm.getAchievementPlan();
|
| 31677 |
amit.gupta |
942 |
}
|
| 31686 |
amit.gupta |
943 |
|
| 31677 |
amit.gupta |
944 |
}
|
| 31686 |
amit.gupta |
945 |
}
|
|
|
946 |
if (otherPartnerSecondaryPlanModel != null) {
|
|
|
947 |
otherPartnerSecondaryPlanModel.setAchievementPlan(otherBrandSecondary);
|
|
|
948 |
}
|
|
|
949 |
secondaryModelMap = partnerSecondayPlans.get(fofoId).stream()
|
|
|
950 |
.filter(x -> brands.contains(x.getBrand()))
|
|
|
951 |
.collect(Collectors.toMap(x -> x.getBrand(), x -> x));
|
| 30087 |
tejbeer |
952 |
|
| 31686 |
amit.gupta |
953 |
if (secondaryModelMap.containsKey("Others")) {
|
|
|
954 |
PartnerSecondaryPlanModel psp = secondaryModelMap.get("Others");
|
|
|
955 |
psp.setAchievementPlan(otherBrandSecondary);
|
|
|
956 |
} else {
|
|
|
957 |
secondaryModelMap.put("Others", new PartnerSecondaryPlanModel(fofoId, "Others", (long) 0,
|
|
|
958 |
otherBrandSecondary, authUser.getId(), null));
|
|
|
959 |
}
|
|
|
960 |
for (String brand : brands) {
|
|
|
961 |
if (!secondaryModelMap.containsKey(brand)) {
|
|
|
962 |
secondaryModelMap.put(brand, new PartnerSecondaryPlanModel(fofoId, brand, (long) 0,
|
|
|
963 |
(long) 0, authUser.getId(), null));
|
| 31677 |
amit.gupta |
964 |
}
|
| 31686 |
amit.gupta |
965 |
}
|
| 30087 |
tejbeer |
966 |
|
| 31686 |
amit.gupta |
967 |
for (Entry<String, PartnerSecondaryPlanModel> secondaryModelEntry : secondaryModelMap.entrySet()) {
|
|
|
968 |
Integer authId = secondaryModelEntry.getValue().getAuthId();
|
|
|
969 |
if (authId != null && authId != authUser.getId()) {
|
|
|
970 |
secondaryModelEntry.getValue().setAuthUser(authRepository.selectById(authId));
|
|
|
971 |
ptam.setSecondaryColor("red");
|
|
|
972 |
}
|
|
|
973 |
|
| 31677 |
amit.gupta |
974 |
}
|
| 30077 |
tejbeer |
975 |
|
| 31686 |
amit.gupta |
976 |
ptam.setPartnerSecondaryModel(secondaryModelMap);
|
|
|
977 |
ptam.setTotalSecondaryPlan(totalSecondaryPlan);
|
|
|
978 |
ptam.setTotalSecondaryAchievement(totalSecondaryAchivement);
|
|
|
979 |
// Secondary
|
|
|
980 |
|
| 31677 |
amit.gupta |
981 |
} else {
|
| 31686 |
amit.gupta |
982 |
for (String brand : brands) {
|
|
|
983 |
PartnerSecondaryPlanModel pspm = new PartnerSecondaryPlanModel();
|
|
|
984 |
pspm.setAchievementPlan((long) 0);
|
|
|
985 |
pspm.setTargetPlan((long) 0);
|
|
|
986 |
pspm.setBrand(brand);
|
|
|
987 |
pspm.setFofoId(fofoId);
|
|
|
988 |
secondaryModelMap.put(brand, pspm);
|
| 31677 |
amit.gupta |
989 |
}
|
| 31686 |
amit.gupta |
990 |
ptam.setPartnerSecondaryModel(secondaryModelMap);
|
| 31677 |
amit.gupta |
991 |
}
|
| 30077 |
tejbeer |
992 |
|
| 31686 |
amit.gupta |
993 |
if (!partnerTicketCount.isEmpty()) {
|
|
|
994 |
if (partnerTicketCount.get(fofoId) != null) {
|
|
|
995 |
ptam.setTicketCount(partnerTicketCount.get(fofoId));
|
|
|
996 |
} else {
|
|
|
997 |
ptam.setTicketCount(0);
|
|
|
998 |
|
| 31677 |
amit.gupta |
999 |
}
|
|
|
1000 |
}
|
| 30087 |
tejbeer |
1001 |
|
| 31686 |
amit.gupta |
1002 |
ptams.add(ptam);
|
| 30077 |
tejbeer |
1003 |
|
| 31677 |
amit.gupta |
1004 |
}
|
| 30077 |
tejbeer |
1005 |
|
| 31686 |
amit.gupta |
1006 |
tm.setTotalPartnerTargetCollection(totalPartnerTargetCollection);
|
|
|
1007 |
tm.setTotalPartnerTargetSecondary(totalPartnerTargetSecondary);
|
|
|
1008 |
tm.setTotalPartnerSecondary(totalPartnerAchievementSecondary);
|
|
|
1009 |
tm.setTotalPartnerCollection(totalPartnerAchievementCollection);
|
|
|
1010 |
tm.setTodayCollectionCount((int) todayCollectionCount);
|
| 30416 |
tejbeer |
1011 |
|
| 31686 |
amit.gupta |
1012 |
tm.setTargetAchievement(ptams.stream().sorted(Comparator.comparing(PartnerTargetAchievementModel::getRank))
|
|
|
1013 |
.collect(Collectors.toList()));
|
| 30416 |
tejbeer |
1014 |
|
| 31677 |
amit.gupta |
1015 |
}
|
| 30077 |
tejbeer |
1016 |
|
| 31677 |
amit.gupta |
1017 |
}
|
|
|
1018 |
return responseSender.ok(tm);
|
| 30077 |
tejbeer |
1019 |
|
| 31677 |
amit.gupta |
1020 |
}
|
| 32737 |
amit.gupta |
1021 |
|
|
|
1022 |
//TODO:Amit
|
| 31677 |
amit.gupta |
1023 |
@RequestMapping(value = "/target", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1024 |
@ApiImplicitParams({
|
|
|
1025 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
1026 |
public ResponseEntity<?> createPartnerTarget(HttpServletRequest request,
|
|
|
1027 |
@RequestBody PartnerTargetAchievementModel ptam) throws ProfitMandiBusinessException {
|
| 30077 |
tejbeer |
1028 |
|
| 31677 |
amit.gupta |
1029 |
LOGGER.info("ptam" + ptam);
|
| 30089 |
tejbeer |
1030 |
|
| 31677 |
amit.gupta |
1031 |
AuthUser authUser = authRepository.selectByGmailId(ptam.getCreatedBy());
|
| 30077 |
tejbeer |
1032 |
|
| 31677 |
amit.gupta |
1033 |
if (ptam.getCollectionCommitmentDate().isAfter(LocalDate.now())
|
|
|
1034 |
|| ptam.getCollectionCommitmentDate().isEqual(LocalDate.now())) {
|
|
|
1035 |
PartnerCollectionPlan partnerCollectionPlan = partnerCollectionPlanRepository
|
|
|
1036 |
.selectByLocalDate(LocalDate.now(), ptam.getFofoId(), true);
|
|
|
1037 |
LOGGER.info("pcp" + partnerCollectionPlan);
|
| 30077 |
tejbeer |
1038 |
|
| 31677 |
amit.gupta |
1039 |
if (partnerCollectionPlan == null) {
|
|
|
1040 |
if (ptam.getCollectionTarget() > 0) {
|
| 30087 |
tejbeer |
1041 |
|
| 31677 |
amit.gupta |
1042 |
partnerCollectionPlan = new PartnerCollectionPlan();
|
|
|
1043 |
partnerCollectionPlan.setCreateTimestamp(LocalDateTime.now());
|
|
|
1044 |
partnerCollectionPlan.setAuthId(authUser.getId());
|
|
|
1045 |
partnerCollectionPlan.setFofoId(ptam.getFofoId());
|
|
|
1046 |
partnerCollectionPlan.setActive(true);
|
|
|
1047 |
partnerCollectionPlan.setCollectionPlan(ptam.getCollectionTarget());
|
|
|
1048 |
partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1049 |
partnerCollectionPlan.setCommitedTimestamp(ptam.getCollectionCommitmentDate().atStartOfDay());
|
|
|
1050 |
partnerCollectionPlanRepository.persist(partnerCollectionPlan);
|
| 30416 |
tejbeer |
1051 |
|
| 31677 |
amit.gupta |
1052 |
}
|
| 30087 |
tejbeer |
1053 |
|
| 31677 |
amit.gupta |
1054 |
} else {
|
| 30087 |
tejbeer |
1055 |
|
| 31677 |
amit.gupta |
1056 |
if (partnerCollectionPlan.getCollectionPlan() != ptam.getCollectionTarget()) {
|
|
|
1057 |
float totalCollectionPlan = partnerCollectionPlan.getCollectionPlan() + 10000;
|
|
|
1058 |
if (authUser.getId() == partnerCollectionPlan.getAuthId()) {
|
| 30087 |
tejbeer |
1059 |
|
| 31677 |
amit.gupta |
1060 |
if (authUser.getEmailId().equals("tarun.verma@smartdukaan.com")
|
|
|
1061 |
|| authUser.getEmailId().equals("rakesh.sonawane@smartdukaan.com")
|
|
|
1062 |
|| ptam.getCollectionTarget() >= totalCollectionPlan) {
|
|
|
1063 |
partnerCollectionPlan.setCollectionPlan(ptam.getCollectionTarget());
|
|
|
1064 |
partnerCollectionPlan.setActive(true);
|
|
|
1065 |
partnerCollectionPlan
|
|
|
1066 |
.setCommitedTimestamp(ptam.getCollectionCommitmentDate().atStartOfDay());
|
|
|
1067 |
partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1068 |
} else {
|
|
|
1069 |
throw new ProfitMandiBusinessException("collection target", "",
|
|
|
1070 |
"collection target should be more than " + totalCollectionPlan);
|
|
|
1071 |
}
|
| 30087 |
tejbeer |
1072 |
|
| 31677 |
amit.gupta |
1073 |
} else {
|
| 30137 |
tejbeer |
1074 |
|
| 31677 |
amit.gupta |
1075 |
if (authUser.getEmailId().equals("tarun.verma@smartdukaan.com")
|
|
|
1076 |
|| authUser.getEmailId().equals("rakesh.sonawane@smartdukaan.com")
|
|
|
1077 |
|| ptam.getCollectionTarget() >= totalCollectionPlan) {
|
| 30137 |
tejbeer |
1078 |
|
| 31677 |
amit.gupta |
1079 |
partnerCollectionPlan.setActive(false);
|
|
|
1080 |
partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1081 |
partnerCollectionPlan = new PartnerCollectionPlan();
|
|
|
1082 |
partnerCollectionPlan.setCreateTimestamp(LocalDateTime.now());
|
|
|
1083 |
partnerCollectionPlan.setAuthId(authUser.getId());
|
|
|
1084 |
partnerCollectionPlan.setFofoId(ptam.getFofoId());
|
|
|
1085 |
partnerCollectionPlan.setActive(true);
|
|
|
1086 |
partnerCollectionPlan
|
|
|
1087 |
.setCommitedTimestamp(ptam.getSecondaryCommitmentDate().atStartOfDay());
|
|
|
1088 |
partnerCollectionPlan.setCollectionPlan(ptam.getCollectionTarget());
|
|
|
1089 |
partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1090 |
partnerCollectionPlanRepository.persist(partnerCollectionPlan);
|
|
|
1091 |
} else {
|
|
|
1092 |
throw new ProfitMandiBusinessException("collection target", "",
|
|
|
1093 |
"collection target should be more than " + totalCollectionPlan);
|
|
|
1094 |
}
|
|
|
1095 |
}
|
|
|
1096 |
}
|
| 30137 |
tejbeer |
1097 |
|
| 31677 |
amit.gupta |
1098 |
if ((LocalDate.now().atStartOfDay().equals(ptam.getCollectionCommitmentDate().atStartOfDay())
|
|
|
1099 |
|| ptam.getCollectionCommitmentDate().atStartOfDay().isAfter(LocalDate.now().atStartOfDay()))
|
|
|
1100 |
&& partnerCollectionPlan.getCollectionPlan() == ptam.getCollectionTarget()) {
|
|
|
1101 |
partnerCollectionPlan.setCommitedTimestamp(ptam.getCollectionCommitmentDate().atStartOfDay());
|
|
|
1102 |
partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1103 |
}
|
| 30416 |
tejbeer |
1104 |
|
| 31677 |
amit.gupta |
1105 |
}
|
| 30433 |
tejbeer |
1106 |
|
| 31677 |
amit.gupta |
1107 |
PartnerCollectionRemark pcr = new PartnerCollectionRemark();
|
|
|
1108 |
pcr.setFofoId(ptam.getFofoId());
|
|
|
1109 |
pcr.setAuthId(authUser.getId());
|
|
|
1110 |
pcr.setMessage("Collection plan for" + ptam.getCollectionCommitmentDate());
|
|
|
1111 |
pcr.setRemark(CollectionRemark.COLLECTION_PLAN);
|
|
|
1112 |
pcr.setCreateTimestamp(LocalDateTime.now());
|
|
|
1113 |
partnerCollectionRemarkRepository.persist(pcr);
|
|
|
1114 |
} else {
|
|
|
1115 |
throw new ProfitMandiBusinessException("Date", "",
|
|
|
1116 |
"you can't select the back date " + ptam.getCollectionCommitmentDate());
|
|
|
1117 |
}
|
| 30077 |
tejbeer |
1118 |
|
| 31677 |
amit.gupta |
1119 |
for (Entry<String, PartnerSecondaryPlanModel> pspm : ptam.getPartnerSecondaryModel().entrySet()) {
|
| 30087 |
tejbeer |
1120 |
|
| 31677 |
amit.gupta |
1121 |
if (ptam.getCollectionCommitmentDate().isAfter(LocalDate.now())
|
|
|
1122 |
|| ptam.getCollectionCommitmentDate().isEqual(LocalDate.now())) {
|
|
|
1123 |
PartnerSecondaryPlanModel plan = pspm.getValue();
|
|
|
1124 |
PartnerSecondaryPlan psp = partnerSecondaryPlanRepository.selectByLocalDateBrand(plan.getBrand(),
|
|
|
1125 |
LocalDate.now(), ptam.getFofoId(), true);
|
|
|
1126 |
LOGGER.info("psp" + psp);
|
| 30087 |
tejbeer |
1127 |
|
| 31677 |
amit.gupta |
1128 |
if (psp == null) {
|
|
|
1129 |
if (plan.getTargetPlan() != null && plan.getTargetPlan() > 0) {
|
| 30087 |
tejbeer |
1130 |
|
| 31677 |
amit.gupta |
1131 |
psp = new PartnerSecondaryPlan();
|
|
|
1132 |
psp.setAuthId(authUser.getId());
|
|
|
1133 |
psp.setBrand(pspm.getKey());
|
|
|
1134 |
psp.setFofoId(pspm.getValue().getFofoId());
|
|
|
1135 |
psp.setSecondaryPlan(pspm.getValue().getTargetPlan());
|
|
|
1136 |
psp.setCreateTimestamp(LocalDateTime.now());
|
|
|
1137 |
psp.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1138 |
psp.setCommitedTimestamp(ptam.getSecondaryCommitmentDate().atStartOfDay());
|
|
|
1139 |
psp.setActive(true);
|
|
|
1140 |
partnerSecondaryPlanRepository.persist(psp);
|
|
|
1141 |
}
|
| 30087 |
tejbeer |
1142 |
|
| 31677 |
amit.gupta |
1143 |
} else {
|
|
|
1144 |
if (plan.getTargetPlan() != psp.getSecondaryPlan()) {
|
|
|
1145 |
float totalSecondaryPlan = psp.getSecondaryPlan() + 10000;
|
|
|
1146 |
if (authUser.getId() == plan.getAuthId()) {
|
|
|
1147 |
if (authUser.getEmailId().equals("tarun.verma@smartdukaan.com")
|
|
|
1148 |
|| authUser.getEmailId().equals("rakesh.sonawane@smartdukaan.com")
|
|
|
1149 |
|| plan.getTargetPlan() >= totalSecondaryPlan) {
|
|
|
1150 |
psp.setSecondaryPlan(pspm.getValue().getTargetPlan());
|
|
|
1151 |
psp.setCommitedTimestamp(ptam.getSecondaryCommitmentDate().atStartOfDay());
|
|
|
1152 |
psp.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1153 |
psp.setActive(true);
|
|
|
1154 |
} else {
|
|
|
1155 |
throw new ProfitMandiBusinessException("secondary target", "",
|
|
|
1156 |
"secondary target should be more than " + totalSecondaryPlan);
|
|
|
1157 |
}
|
| 30087 |
tejbeer |
1158 |
|
| 31677 |
amit.gupta |
1159 |
} else {
|
| 30087 |
tejbeer |
1160 |
|
| 31677 |
amit.gupta |
1161 |
if (authUser.getEmailId().equals("tarun.verma@smartdukaan.com")
|
|
|
1162 |
|| authUser.getEmailId().equals("rakesh.sonawane@smartdukaan.com")
|
|
|
1163 |
|| plan.getTargetPlan() >= totalSecondaryPlan) {
|
| 30087 |
tejbeer |
1164 |
|
| 31677 |
amit.gupta |
1165 |
psp.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1166 |
psp.setActive(false);
|
|
|
1167 |
psp = new PartnerSecondaryPlan();
|
|
|
1168 |
psp.setAuthId(authUser.getId());
|
|
|
1169 |
psp.setBrand(pspm.getKey());
|
|
|
1170 |
psp.setFofoId(pspm.getValue().getFofoId());
|
|
|
1171 |
psp.setSecondaryPlan(pspm.getValue().getTargetPlan());
|
|
|
1172 |
psp.setCommitedTimestamp(ptam.getSecondaryCommitmentDate().atStartOfDay());
|
|
|
1173 |
psp.setCreateTimestamp(LocalDateTime.now());
|
|
|
1174 |
psp.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1175 |
psp.setActive(true);
|
|
|
1176 |
partnerSecondaryPlanRepository.persist(psp);
|
|
|
1177 |
} else {
|
|
|
1178 |
throw new ProfitMandiBusinessException("secondary target", "",
|
|
|
1179 |
"secondary target should be more than " + totalSecondaryPlan);
|
|
|
1180 |
}
|
|
|
1181 |
}
|
|
|
1182 |
}
|
| 30137 |
tejbeer |
1183 |
|
| 31677 |
amit.gupta |
1184 |
if ((LocalDate.now().atStartOfDay().equals(ptam.getSecondaryCommitmentDate().atStartOfDay())
|
|
|
1185 |
|| ptam.getSecondaryCommitmentDate().atStartOfDay().isAfter(LocalDate.now().atStartOfDay()))
|
|
|
1186 |
&& plan.getTargetPlan() == psp.getSecondaryPlan()) {
|
|
|
1187 |
psp.setCommitedTimestamp(ptam.getSecondaryCommitmentDate().atStartOfDay());
|
|
|
1188 |
psp.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1189 |
}
|
| 30137 |
tejbeer |
1190 |
|
| 31677 |
amit.gupta |
1191 |
}
|
|
|
1192 |
} else {
|
|
|
1193 |
throw new ProfitMandiBusinessException("Date", "",
|
|
|
1194 |
"you can't select the back date " + ptam.getSecondaryCommitmentDate());
|
|
|
1195 |
}
|
| 30137 |
tejbeer |
1196 |
|
| 31677 |
amit.gupta |
1197 |
}
|
| 30077 |
tejbeer |
1198 |
|
| 31677 |
amit.gupta |
1199 |
return responseSender.ok(true);
|
| 30137 |
tejbeer |
1200 |
|
| 31677 |
amit.gupta |
1201 |
}
|
| 30077 |
tejbeer |
1202 |
|
| 31677 |
amit.gupta |
1203 |
@RequestMapping(value = "/viewTickets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1204 |
@ApiImplicitParams({
|
| 30416 |
tejbeer |
1205 |
|
| 31677 |
amit.gupta |
1206 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
1207 |
public ResponseEntity<?> viewTickets(HttpServletRequest request, @RequestParam int fofoId)
|
|
|
1208 |
throws ProfitMandiBusinessException {
|
|
|
1209 |
List<Ticket> tickets = ticketRepository.selectAllOpenTicketByRetailer(fofoId);
|
| 30416 |
tejbeer |
1210 |
|
| 31677 |
amit.gupta |
1211 |
List<TicketViewModel> viewList = new ArrayList<>();
|
|
|
1212 |
for (Ticket ticket : tickets) {
|
| 30416 |
tejbeer |
1213 |
|
| 31677 |
amit.gupta |
1214 |
TicketViewModel ticketViewModel = new TicketViewModel();
|
|
|
1215 |
ticketViewModel.setId(ticket.getId());
|
|
|
1216 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
1217 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(ticketSubCategory.getCategoryId());
|
| 30416 |
tejbeer |
1218 |
|
| 31677 |
amit.gupta |
1219 |
ticketViewModel.setCategoryName(ticketCategory.getName());
|
|
|
1220 |
ticketViewModel.setSubCategoryName(ticketSubCategory.getName());
|
|
|
1221 |
ticketViewModel.setCreatedTimestamp(ticket.getCreateTimestamp());
|
| 30416 |
tejbeer |
1222 |
|
| 31677 |
amit.gupta |
1223 |
viewList.add(ticketViewModel);
|
|
|
1224 |
}
|
|
|
1225 |
return responseSender.ok(viewList);
|
| 30416 |
tejbeer |
1226 |
|
| 31677 |
amit.gupta |
1227 |
}
|
| 30416 |
tejbeer |
1228 |
|
| 31677 |
amit.gupta |
1229 |
@RequestMapping(value = "/viewRecentTickets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1230 |
@ApiImplicitParams({
|
| 30416 |
tejbeer |
1231 |
|
| 31677 |
amit.gupta |
1232 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
1233 |
public ResponseEntity<?> viewRecentTickets(HttpServletRequest request, @RequestParam int fofoId)
|
|
|
1234 |
throws ProfitMandiBusinessException {
|
|
|
1235 |
List<TicketViewModel> viewList = ticketRepository.selectRecentClosedTicket(fofoId,
|
|
|
1236 |
LocalDateTime.now().minusDays(20));
|
| 30416 |
tejbeer |
1237 |
|
| 31677 |
amit.gupta |
1238 |
return responseSender.ok(viewList);
|
| 30416 |
tejbeer |
1239 |
|
| 31677 |
amit.gupta |
1240 |
}
|
| 30416 |
tejbeer |
1241 |
|
| 31677 |
amit.gupta |
1242 |
@RequestMapping(value = "/createTicket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1243 |
@ApiImplicitParams({
|
| 30416 |
tejbeer |
1244 |
|
| 31677 |
amit.gupta |
1245 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
1246 |
public ResponseEntity<?> createTicket(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
1247 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
| 30460 |
tejbeer |
1248 |
|
| 31677 |
amit.gupta |
1249 |
return responseSender.ok(ticketCategories);
|
|
|
1250 |
}
|
| 30416 |
tejbeer |
1251 |
|
| 31677 |
amit.gupta |
1252 |
@RequestMapping(value = "/getSubCategoriesByCategoryId", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1253 |
@ApiImplicitParams({
|
|
|
1254 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 30416 |
tejbeer |
1255 |
|
| 31677 |
amit.gupta |
1256 |
public ResponseEntity<?> getSubCategoriesByCategoryId(HttpServletRequest request,
|
|
|
1257 |
@RequestParam(name = "categoryId", defaultValue = "0") int categoryId, Model model) {
|
|
|
1258 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll(categoryId);
|
|
|
1259 |
LOGGER.info(ticketSubCategories);
|
|
|
1260 |
return responseSender.ok(ticketSubCategories);
|
|
|
1261 |
}
|
| 30416 |
tejbeer |
1262 |
|
| 31677 |
amit.gupta |
1263 |
@RequestMapping(value = "/createTicket", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1264 |
@ApiImplicitParams({
|
| 30416 |
tejbeer |
1265 |
|
| 31677 |
amit.gupta |
1266 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
1267 |
public ResponseEntity<?> createTicket(HttpServletRequest request, @RequestParam(name = "categoryId") int categoryId,
|
|
|
1268 |
@RequestParam(name = "subCategoryId") int subCategoryId, @RequestParam(name = "message") String message,
|
|
|
1269 |
@RequestParam(name = "fofoId") int fofoId) throws Exception {
|
| 30460 |
tejbeer |
1270 |
|
| 31677 |
amit.gupta |
1271 |
int id = (int) request.getAttribute("userId");
|
| 30460 |
tejbeer |
1272 |
|
| 31677 |
amit.gupta |
1273 |
LOGGER.info("id" + id);
|
| 30460 |
tejbeer |
1274 |
|
| 31677 |
amit.gupta |
1275 |
User user = userRepository.selectById(id);
|
| 30460 |
tejbeer |
1276 |
|
| 31677 |
amit.gupta |
1277 |
AuthUser authUser = authRepository.selectByEmailOrMobile(user.getEmailId());
|
| 30460 |
tejbeer |
1278 |
|
| 31677 |
amit.gupta |
1279 |
List<Ticket> tickets = ticketRepository.selectAllResolvedMarkedTicketByCreator(fofoId);
|
|
|
1280 |
if (tickets.size() > 3 || tickets.size() == 3) {
|
|
|
1281 |
return responseSender.ok(false);
|
|
|
1282 |
} else {
|
|
|
1283 |
csService.createTicket(fofoId, categoryId, subCategoryId, message);
|
| 30416 |
tejbeer |
1284 |
|
| 31677 |
amit.gupta |
1285 |
PartnerCollectionRemark pcr = new PartnerCollectionRemark();
|
|
|
1286 |
pcr.setFofoId(fofoId);
|
|
|
1287 |
pcr.setAuthId(authUser.getId());
|
|
|
1288 |
pcr.setMessage("Ticket Created");
|
|
|
1289 |
pcr.setRemark(CollectionRemark.TICKET_CREATED);
|
|
|
1290 |
pcr.setCreateTimestamp(LocalDateTime.now());
|
|
|
1291 |
partnerCollectionRemarkRepository.persist(pcr);
|
| 30460 |
tejbeer |
1292 |
|
| 31677 |
amit.gupta |
1293 |
}
|
|
|
1294 |
return responseSender.ok(true);
|
|
|
1295 |
}
|
| 30416 |
tejbeer |
1296 |
|
| 31677 |
amit.gupta |
1297 |
@RequestMapping(value = "/getCollectionRemark", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1298 |
@ApiImplicitParams({
|
| 30416 |
tejbeer |
1299 |
|
| 31677 |
amit.gupta |
1300 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
1301 |
public ResponseEntity<?> getCollectionRemark(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
1302 |
List<CollectionRemark> remarks = Arrays.asList(CollectionRemark.values()).stream()
|
|
|
1303 |
.filter(x -> !x.equals(CollectionRemark.COLLECTION_PLAN)).collect(Collectors.toList());
|
|
|
1304 |
return responseSender.ok(remarks);
|
|
|
1305 |
}
|
| 30416 |
tejbeer |
1306 |
|
| 32701 |
amit.gupta |
1307 |
@Autowired
|
|
|
1308 |
RestClient restClient;
|
|
|
1309 |
|
| 32737 |
amit.gupta |
1310 |
@Autowired
|
|
|
1311 |
SmartPingService smartPingService;
|
|
|
1312 |
|
|
|
1313 |
@RequestMapping(value = "/retailer/contacts/{fofoId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1314 |
public ResponseEntity<?> getContacts(HttpServletRequest request, @PathVariable int fofoId) throws Exception {
|
|
|
1315 |
return responseSender.ok(retailerService.getContactsByFofoId(fofoId, true));
|
|
|
1316 |
}
|
|
|
1317 |
|
|
|
1318 |
@RequestMapping(value = "/click2call/{toMobile}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1319 |
public ResponseEntity<?> makeCallOnAgentBehalf(HttpServletRequest request, @PathVariable String toMobile) throws Exception {
|
| 32701 |
amit.gupta |
1320 |
int id = (int) request.getAttribute("userId");
|
|
|
1321 |
User user = userRepository.selectById(id);
|
|
|
1322 |
AuthUser authUser = authRepository.selectByEmailOrMobile(user.getEmailId());
|
|
|
1323 |
String fromMobile = authUser.getMobileNumber();
|
|
|
1324 |
|
| 32737 |
amit.gupta |
1325 |
SmartPingAgentModel smartPingAgentModel = smartPingService.getAllAgents().get(toMobile);
|
| 32701 |
amit.gupta |
1326 |
|
| 32737 |
amit.gupta |
1327 |
String urlTemplate = "https://ccs1.smartpingcc.io/v2/clickToCall/para?&user_id=71287091&token=InCfClzwFUtLUW610faI&from=%d&fromType=Agent&fromCLI=&to=%s&toCLI=%s";
|
| 32703 |
amit.gupta |
1328 |
|
| 32737 |
amit.gupta |
1329 |
String url = String.format(urlTemplate, smartPingAgentModel.getAgentId(), smartPingAgentModel.getAllowDid().get(0), toMobile, smartPingAgentModel.getAllowDid().get(0));
|
| 32703 |
amit.gupta |
1330 |
|
| 32701 |
amit.gupta |
1331 |
restClient.get(url, null, null);
|
|
|
1332 |
|
|
|
1333 |
return responseSender.ok(true);
|
|
|
1334 |
}
|
|
|
1335 |
|
| 31677 |
amit.gupta |
1336 |
@RequestMapping(value = "/createPartnerColectionRemark", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1337 |
@ApiImplicitParams({
|
| 30416 |
tejbeer |
1338 |
|
| 31677 |
amit.gupta |
1339 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 32587 |
ranu |
1340 |
public ResponseEntity<?> createPartnerCollectionRemark(HttpServletRequest request,
|
| 32737 |
amit.gupta |
1341 |
@RequestBody PartnerCollectionRemarkModel partnerCollectionRemarkModel)
|
| 31677 |
amit.gupta |
1342 |
throws ProfitMandiBusinessException {
|
|
|
1343 |
AuthUser authUser = authRepository.selectByGmailId(partnerCollectionRemarkModel.getGmailId());
|
| 30416 |
tejbeer |
1344 |
|
| 31677 |
amit.gupta |
1345 |
PartnerCollectionRemark pcr = new PartnerCollectionRemark();
|
|
|
1346 |
pcr.setFofoId(partnerCollectionRemarkModel.getFofoId());
|
|
|
1347 |
pcr.setAuthId(authUser.getId());
|
|
|
1348 |
pcr.setMessage(partnerCollectionRemarkModel.getMessage());
|
|
|
1349 |
pcr.setRemark(partnerCollectionRemarkModel.getRemark());
|
|
|
1350 |
pcr.setCreateTimestamp(LocalDateTime.now());
|
|
|
1351 |
partnerCollectionRemarkRepository.persist(pcr);
|
|
|
1352 |
return responseSender.ok(true);
|
| 30416 |
tejbeer |
1353 |
|
| 31677 |
amit.gupta |
1354 |
}
|
| 30433 |
tejbeer |
1355 |
|
| 31677 |
amit.gupta |
1356 |
@RequestMapping(value = "/uploadFranchiseeVisit", method = RequestMethod.POST)
|
|
|
1357 |
public ResponseEntity<?> readCsvFileAndSetLead(HttpServletRequest request, @RequestPart MultipartFile multipartFile)
|
|
|
1358 |
throws Throwable {
|
| 30433 |
tejbeer |
1359 |
|
| 31677 |
amit.gupta |
1360 |
int id = (int) request.getAttribute("userId");
|
| 30433 |
tejbeer |
1361 |
|
| 31677 |
amit.gupta |
1362 |
LOGGER.info("id" + id);
|
| 30433 |
tejbeer |
1363 |
|
| 31677 |
amit.gupta |
1364 |
User user = userRepository.selectById(id);
|
| 30433 |
tejbeer |
1365 |
|
| 31677 |
amit.gupta |
1366 |
AuthUser authUser = authRepository.selectByEmailOrMobile(user.getEmailId());
|
| 30433 |
tejbeer |
1367 |
|
| 31677 |
amit.gupta |
1368 |
String fileName = multipartFile.getName();
|
|
|
1369 |
String fileNames = multipartFile.getOriginalFilename();
|
| 30433 |
tejbeer |
1370 |
|
| 31677 |
amit.gupta |
1371 |
LOGGER.info("fileName" + fileName);
|
|
|
1372 |
LOGGER.info("fileNames" + fileNames);
|
| 30433 |
tejbeer |
1373 |
|
| 31677 |
amit.gupta |
1374 |
List<CSVRecord> records = FileUtil.readFile(multipartFile);
|
| 30433 |
tejbeer |
1375 |
|
| 31677 |
amit.gupta |
1376 |
for (CSVRecord record : records) {
|
|
|
1377 |
FranchiseeVisit franchiseeVisit = new FranchiseeVisit();
|
|
|
1378 |
franchiseeVisit.setFofoId(Integer.parseInt(record.get(0)));
|
|
|
1379 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(Integer.parseInt(record.get(0)));
|
| 30433 |
tejbeer |
1380 |
|
| 31677 |
amit.gupta |
1381 |
franchiseeVisit.setPartnerName(customRetailer.getBusinessName());
|
|
|
1382 |
franchiseeVisit.setAgenda(record.get(1));
|
|
|
1383 |
franchiseeVisit.setCreatedTimestamp(LocalDateTime.now());
|
|
|
1384 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1385 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.OPEN);
|
| 30433 |
tejbeer |
1386 |
|
| 31677 |
amit.gupta |
1387 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
|
|
|
1388 |
LOGGER.info(record.get(1));
|
|
|
1389 |
LocalDate dateTime = LocalDate.parse(record.get(2), formatter);
|
| 30433 |
tejbeer |
1390 |
|
| 31677 |
amit.gupta |
1391 |
franchiseeVisit.setScheduleTimestamp(dateTime.atStartOfDay());
|
|
|
1392 |
// change
|
| 30433 |
tejbeer |
1393 |
|
| 31677 |
amit.gupta |
1394 |
String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
1395 |
franchiseeVisit.setCreatedBy(authUserName);
|
|
|
1396 |
franchiseeVisit.setAuthId(authUser.getId());
|
| 30433 |
tejbeer |
1397 |
|
| 31677 |
amit.gupta |
1398 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| 30433 |
tejbeer |
1399 |
|
| 31677 |
amit.gupta |
1400 |
return responseSender.ok(true);
|
|
|
1401 |
}
|
| 30433 |
tejbeer |
1402 |
|
| 31677 |
amit.gupta |
1403 |
return responseSender.ok(true);
|
| 30433 |
tejbeer |
1404 |
|
| 31677 |
amit.gupta |
1405 |
}
|
| 30487 |
tejbeer |
1406 |
|
| 31677 |
amit.gupta |
1407 |
@RequestMapping(value = "/downloadFranchiseeVisitTemplate", method = RequestMethod.GET)
|
|
|
1408 |
public ResponseEntity<?> downloadFranchiseeVisitTemplate(HttpServletRequest request) throws Exception {
|
| 30487 |
tejbeer |
1409 |
|
| 31677 |
amit.gupta |
1410 |
// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| 30487 |
tejbeer |
1411 |
|
| 31677 |
amit.gupta |
1412 |
List<List<?>> rows = new ArrayList<>();
|
| 30487 |
tejbeer |
1413 |
|
| 31677 |
amit.gupta |
1414 |
org.apache.commons.io.output.ByteArrayOutputStream byteArrayOutputStream = FileUtil
|
|
|
1415 |
.getCSVByteStream(Arrays.asList("Partner Id", "Agenda", "Schedule Timestamp"), rows);
|
| 30487 |
tejbeer |
1416 |
|
| 31677 |
amit.gupta |
1417 |
try {
|
|
|
1418 |
byteArrayOutputStream.close();
|
|
|
1419 |
} catch (IOException e) {
|
|
|
1420 |
// TODO Auto-generated catch block
|
|
|
1421 |
e.printStackTrace();
|
|
|
1422 |
}
|
| 30487 |
tejbeer |
1423 |
|
| 31677 |
amit.gupta |
1424 |
String filename = "template.csv";
|
|
|
1425 |
HttpHeaders headers = new HttpHeaders();
|
|
|
1426 |
headers.add("Content-Type", "application/csv");
|
|
|
1427 |
headers.setContentDispositionFormData(filename, filename);
|
| 30487 |
tejbeer |
1428 |
|
| 31677 |
amit.gupta |
1429 |
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
|
| 30487 |
tejbeer |
1430 |
|
| 31677 |
amit.gupta |
1431 |
ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(byteArrayOutputStream.toByteArray(), headers,
|
|
|
1432 |
HttpStatus.OK);
|
|
|
1433 |
return response;
|
| 30544 |
tejbeer |
1434 |
|
| 31677 |
amit.gupta |
1435 |
}
|
| 30542 |
tejbeer |
1436 |
|
| 31677 |
amit.gupta |
1437 |
@RequestMapping(value = "/markVisitAttendance", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1438 |
public ResponseEntity<?> markVisitAttendance(HttpServletRequest request, @RequestParam(name = "id") int id)
|
|
|
1439 |
throws ProfitMandiBusinessException {
|
|
|
1440 |
FranchiseeVisit franchiseeVisit = franchiseeVisitRepository.selectById(id);
|
| 30542 |
tejbeer |
1441 |
|
| 31677 |
amit.gupta |
1442 |
franchiseeVisit.setVisitTimestamp(LocalDateTime.now());
|
| 30542 |
tejbeer |
1443 |
|
| 31677 |
amit.gupta |
1444 |
return responseSender.ok(true);
|
| 30542 |
tejbeer |
1445 |
|
| 31677 |
amit.gupta |
1446 |
}
|
| 31249 |
tejbeer |
1447 |
|
| 31677 |
amit.gupta |
1448 |
@RequestMapping(value = "/getVisitRequests", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1449 |
public ResponseEntity<?> getVisitRequests(HttpServletRequest request,
|
|
|
1450 |
@RequestParam(name = "gmailId") String gmailId, Model model) throws Exception {
|
| 31249 |
tejbeer |
1451 |
|
| 31677 |
amit.gupta |
1452 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
| 31249 |
tejbeer |
1453 |
|
| 31677 |
amit.gupta |
1454 |
List<Integer> authUserIds = authService.getAllReportees(authUser.getId());
|
|
|
1455 |
List<VisitSummaryModel> visitSummary = new ArrayList<>();
|
| 31249 |
tejbeer |
1456 |
|
| 31677 |
amit.gupta |
1457 |
if (!authUserIds.isEmpty()) {
|
|
|
1458 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(authUserIds);
|
| 31249 |
tejbeer |
1459 |
|
| 31677 |
amit.gupta |
1460 |
List<VisitRequest> allVisitRequests = visitRequestRepository.selectByAuthIdsAndDate(authUserIds,
|
|
|
1461 |
LocalDate.now().minusDays(7), Arrays.asList(VisitStatus.approved, VisitStatus.pending));
|
|
|
1462 |
LOGGER.info("allVisitRequests {}", allVisitRequests);
|
| 31249 |
tejbeer |
1463 |
|
| 31677 |
amit.gupta |
1464 |
if (!allVisitRequests.isEmpty()) {
|
| 31249 |
tejbeer |
1465 |
|
| 31677 |
amit.gupta |
1466 |
List<Integer> leadIds = allVisitRequests.stream().filter(x -> x.getVisitType().equals("lead"))
|
|
|
1467 |
.map(x -> x.getVisitId()).collect(Collectors.toList());
|
|
|
1468 |
List<Lead> leads = new ArrayList<>();
|
|
|
1469 |
if (!leadIds.isEmpty()) {
|
|
|
1470 |
leads = leadRepository.selectAllByIds(leadIds);
|
| 31249 |
tejbeer |
1471 |
|
| 31677 |
amit.gupta |
1472 |
for (Lead lead : leads) {
|
|
|
1473 |
List<LeadActivity> leadActivities = leadActivityRepository.selectBYLeadId(lead.getId());
|
|
|
1474 |
lead.setScheduledTimestamp(leadActivities.get(0).getSchelduleTimestamp());
|
|
|
1475 |
lead.setLeadActivity(leadActivities.get(0));
|
|
|
1476 |
}
|
|
|
1477 |
}
|
|
|
1478 |
List<Integer> franchiseeIds = allVisitRequests.stream()
|
|
|
1479 |
.filter(x -> x.getVisitType().equals("franchiseeVisit")).map(x -> x.getVisitId())
|
|
|
1480 |
.collect(Collectors.toList());
|
|
|
1481 |
List<FranchiseeVisit> franchiseeVisits = new ArrayList<>();
|
|
|
1482 |
if (!franchiseeIds.isEmpty()) {
|
|
|
1483 |
franchiseeVisits = franchiseeVisitRepository.selectAllByIds(franchiseeIds);
|
|
|
1484 |
LOGGER.info("franchiseeVisits {}", franchiseeVisits);
|
| 31249 |
tejbeer |
1485 |
|
| 31677 |
amit.gupta |
1486 |
for (FranchiseeVisit franchiseeVisit : franchiseeVisits) {
|
|
|
1487 |
List<FranchiseeActivity> franchiseeActivities = franchiseeActivityRepository
|
|
|
1488 |
.selectByFranchiseeVisitId(franchiseeVisit.getId());
|
|
|
1489 |
LOGGER.info("franchiseeActivities {}", franchiseeActivities);
|
| 31249 |
tejbeer |
1490 |
|
| 31677 |
amit.gupta |
1491 |
franchiseeVisit.setScheduleTimestamp(franchiseeActivities.get(0).getSchelduleTimestamp());
|
|
|
1492 |
franchiseeVisit.setFranchiseeActivity(franchiseeActivities.get(0));
|
|
|
1493 |
}
|
| 31249 |
tejbeer |
1494 |
|
| 31677 |
amit.gupta |
1495 |
}
|
| 31249 |
tejbeer |
1496 |
|
| 31677 |
amit.gupta |
1497 |
Map<LocalDate, List<VisitRequest>> dateWiseVisitRequest = allVisitRequests.stream()
|
|
|
1498 |
.collect(Collectors.groupingBy(x -> x.getScheduleTimestamp().toLocalDate()));
|
| 31249 |
tejbeer |
1499 |
|
| 31677 |
amit.gupta |
1500 |
for (Entry<LocalDate, List<VisitRequest>> visitEntry : dateWiseVisitRequest.entrySet()) {
|
| 31249 |
tejbeer |
1501 |
|
| 31677 |
amit.gupta |
1502 |
LocalDate date = visitEntry.getKey();
|
|
|
1503 |
List<VisitRequest> visitRequests = visitEntry.getValue();
|
| 31249 |
tejbeer |
1504 |
|
| 31677 |
amit.gupta |
1505 |
VisitSummaryModel visitSummaryModel = new VisitSummaryModel();
|
| 31249 |
tejbeer |
1506 |
|
| 31677 |
amit.gupta |
1507 |
visitSummaryModel.setDate(date);
|
|
|
1508 |
List<Integer> dateWiseLeadEntry = visitRequests.stream()
|
|
|
1509 |
.filter(x -> x.getVisitType().equals("lead")).map(x -> x.getVisitId())
|
|
|
1510 |
.collect(Collectors.toList());
|
| 31249 |
tejbeer |
1511 |
|
| 31677 |
amit.gupta |
1512 |
List<Integer> dateWiseFranchiseeIds = visitRequests.stream()
|
|
|
1513 |
.filter(x -> x.getVisitType().equals("franchiseeVisit")).map(x -> x.getVisitId())
|
|
|
1514 |
.collect(Collectors.toList());
|
| 31249 |
tejbeer |
1515 |
|
| 31677 |
amit.gupta |
1516 |
Map<Integer, List<Lead>> filteredLeadsMap = null;
|
|
|
1517 |
if (!leads.isEmpty()) {
|
|
|
1518 |
filteredLeadsMap = leads.stream().filter(x -> dateWiseLeadEntry.contains(x.getId()))
|
|
|
1519 |
.collect(Collectors.groupingBy(x -> x.getAssignTo()));
|
| 31249 |
tejbeer |
1520 |
|
| 31677 |
amit.gupta |
1521 |
}
|
| 31249 |
tejbeer |
1522 |
|
| 31677 |
amit.gupta |
1523 |
Map<Integer, List<FranchiseeVisit>> filteredFranchiseeVisitsMap = null;
|
| 31249 |
tejbeer |
1524 |
|
| 31677 |
amit.gupta |
1525 |
if (!franchiseeVisits.isEmpty()) {
|
|
|
1526 |
filteredFranchiseeVisitsMap = franchiseeVisits.stream()
|
|
|
1527 |
.filter(x -> dateWiseFranchiseeIds.contains(x.getId()))
|
|
|
1528 |
.collect(Collectors.groupingBy(x -> x.getAuthId()));
|
| 31249 |
tejbeer |
1529 |
|
| 31677 |
amit.gupta |
1530 |
}
|
| 31249 |
tejbeer |
1531 |
|
| 31677 |
amit.gupta |
1532 |
List<UserVisitModel> userVisits = new ArrayList<>();
|
| 31249 |
tejbeer |
1533 |
|
| 31677 |
amit.gupta |
1534 |
for (AuthUser auth : authUsers) {
|
|
|
1535 |
UserVisitModel userVisitModel = new UserVisitModel();
|
|
|
1536 |
List<VisitDescriptionModel> visitDescriptions = new ArrayList<>();
|
| 31249 |
tejbeer |
1537 |
|
| 31677 |
amit.gupta |
1538 |
List<Lead> authLeads = new ArrayList<>();
|
|
|
1539 |
if (filteredLeadsMap != null) {
|
|
|
1540 |
authLeads = filteredLeadsMap.get(auth.getId());
|
| 31249 |
tejbeer |
1541 |
|
| 31677 |
amit.gupta |
1542 |
}
|
| 31249 |
tejbeer |
1543 |
|
| 31677 |
amit.gupta |
1544 |
if (authLeads != null && !authLeads.isEmpty()) {
|
|
|
1545 |
userVisitModel.setAuthUser(auth.getFullName());
|
| 31249 |
tejbeer |
1546 |
|
| 31677 |
amit.gupta |
1547 |
for (Lead lead : authLeads) {
|
| 31249 |
tejbeer |
1548 |
|
| 31677 |
amit.gupta |
1549 |
VisitRequest visitRequest = visitRequests.stream().filter(
|
|
|
1550 |
x -> x.getVisitId() == lead.getId() && x.getCreatedBy() == lead.getAssignTo())
|
|
|
1551 |
.findAny().orElse(null);
|
|
|
1552 |
VisitDescriptionModel visitDescriptionModel = new VisitDescriptionModel();
|
|
|
1553 |
visitDescriptionModel.setVisitId(visitRequest.getId());
|
|
|
1554 |
visitDescriptionModel.setVisitName(lead.getFirstName());
|
|
|
1555 |
visitDescriptionModel.setCity(lead.getCity());
|
|
|
1556 |
visitDescriptionModel.setState(lead.getState());
|
|
|
1557 |
visitDescriptionModel.setScheduleTime(lead.getScheduledTimestamp());
|
|
|
1558 |
visitDescriptionModel.setStatus(visitRequest.getStatus());
|
|
|
1559 |
visitDescriptionModel.setRemarks(lead.getLeadActivity().getRemark());
|
|
|
1560 |
visitDescriptionModel.setVisitType(visitRequest.getVisitType());
|
|
|
1561 |
visitDescriptions.add(visitDescriptionModel);
|
| 31249 |
tejbeer |
1562 |
|
| 31677 |
amit.gupta |
1563 |
}
|
|
|
1564 |
}
|
| 31249 |
tejbeer |
1565 |
|
| 31677 |
amit.gupta |
1566 |
List<FranchiseeVisit> authfranchiseeVisit = new ArrayList<>();
|
|
|
1567 |
if (filteredFranchiseeVisitsMap != null) {
|
|
|
1568 |
authfranchiseeVisit = filteredFranchiseeVisitsMap.get(auth.getId());
|
| 31249 |
tejbeer |
1569 |
|
| 31677 |
amit.gupta |
1570 |
}
|
| 31249 |
tejbeer |
1571 |
|
| 31677 |
amit.gupta |
1572 |
if (authfranchiseeVisit != null && !authfranchiseeVisit.isEmpty()) {
|
|
|
1573 |
userVisitModel.setAuthUser(auth.getFullName());
|
| 31249 |
tejbeer |
1574 |
|
| 31677 |
amit.gupta |
1575 |
for (FranchiseeVisit franchiseeVisit : authfranchiseeVisit) {
|
| 31249 |
tejbeer |
1576 |
|
| 31677 |
amit.gupta |
1577 |
VisitRequest visitRequest = visitRequests.stream()
|
|
|
1578 |
.filter(x -> x.getVisitId() == franchiseeVisit.getId()
|
|
|
1579 |
&& x.getCreatedBy() == franchiseeVisit.getAuthId())
|
|
|
1580 |
.findAny().orElse(null);
|
| 31249 |
tejbeer |
1581 |
|
| 31677 |
amit.gupta |
1582 |
CustomRetailer customRetailer = retailerService
|
|
|
1583 |
.getFofoRetailer(franchiseeVisit.getFofoId());
|
|
|
1584 |
VisitDescriptionModel visitDescriptionModel = new VisitDescriptionModel();
|
|
|
1585 |
visitDescriptionModel.setVisitId(visitRequest.getId());
|
|
|
1586 |
visitDescriptionModel.setVisitName(franchiseeVisit.getPartnerName());
|
|
|
1587 |
visitDescriptionModel.setCity(customRetailer.getAddress().getCity());
|
|
|
1588 |
visitDescriptionModel.setState(customRetailer.getAddress().getState());
|
|
|
1589 |
visitDescriptionModel.setScheduleTime(
|
|
|
1590 |
franchiseeVisit.getFranchiseeActivity().getSchelduleTimestamp());
|
|
|
1591 |
visitDescriptionModel.setStatus(visitRequest.getStatus());
|
|
|
1592 |
visitDescriptionModel.setRemarks(franchiseeVisit.getAgenda());
|
|
|
1593 |
visitDescriptionModel.setVisitType(visitRequest.getVisitType());
|
| 31249 |
tejbeer |
1594 |
|
| 31677 |
amit.gupta |
1595 |
visitDescriptions.add(visitDescriptionModel);
|
| 31249 |
tejbeer |
1596 |
|
| 31677 |
amit.gupta |
1597 |
}
|
|
|
1598 |
}
|
| 31249 |
tejbeer |
1599 |
|
| 31677 |
amit.gupta |
1600 |
userVisitModel.setVisitDescriptions(visitDescriptions);
|
|
|
1601 |
LOGGER.info("userVisit {}", userVisitModel);
|
| 31249 |
tejbeer |
1602 |
|
| 31677 |
amit.gupta |
1603 |
if (userVisitModel.getAuthUser() != null) {
|
|
|
1604 |
userVisits.add(userVisitModel);
|
|
|
1605 |
}
|
| 31249 |
tejbeer |
1606 |
|
| 31677 |
amit.gupta |
1607 |
}
|
| 31249 |
tejbeer |
1608 |
|
| 31677 |
amit.gupta |
1609 |
visitSummaryModel.setUserVisits(userVisits);
|
| 31249 |
tejbeer |
1610 |
|
| 31677 |
amit.gupta |
1611 |
visitSummary.add(visitSummaryModel);
|
| 31249 |
tejbeer |
1612 |
|
| 31677 |
amit.gupta |
1613 |
}
|
| 31249 |
tejbeer |
1614 |
|
| 31677 |
amit.gupta |
1615 |
}
|
| 31249 |
tejbeer |
1616 |
|
| 31677 |
amit.gupta |
1617 |
}
|
|
|
1618 |
return responseSender.ok(visitSummary);
|
| 31249 |
tejbeer |
1619 |
|
| 31677 |
amit.gupta |
1620 |
}
|
| 31249 |
tejbeer |
1621 |
|
| 31677 |
amit.gupta |
1622 |
@RequestMapping(value = "/visitRequest", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1623 |
public ResponseEntity<?> visitRequest(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId,
|
|
|
1624 |
@RequestParam(name = "visitId") int visitId, @RequestParam(name = "status") VisitStatus status, Model model)
|
|
|
1625 |
throws Exception {
|
|
|
1626 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
| 31249 |
tejbeer |
1627 |
|
| 31677 |
amit.gupta |
1628 |
VisitRequest visitRequest = visitRequestRepository.selectById(visitId);
|
|
|
1629 |
visitRequest.setActionedBy(authUser.getId());
|
|
|
1630 |
visitRequest.setStatus(status);
|
|
|
1631 |
visitRequest.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1632 |
if (status.equals(VisitStatus.approved)) {
|
|
|
1633 |
visitRequest.setApprovedTimestamp(LocalDateTime.now());
|
|
|
1634 |
}
|
| 31249 |
tejbeer |
1635 |
|
| 31677 |
amit.gupta |
1636 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
1637 |
sendNotificationModel.setCampaignName("Visit Request");
|
|
|
1638 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
1639 |
sendNotificationModel.setTitle("Visit Request");
|
|
|
1640 |
String message = "Visit Request has been " + status + " for scheduled time on "
|
|
|
1641 |
+ visitRequest.getScheduleTimestamp().toLocalDate();
|
| 31249 |
tejbeer |
1642 |
|
| 31677 |
amit.gupta |
1643 |
sendNotificationModel.setMessage(message);
|
|
|
1644 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
1645 |
User user = userRepository.selectByEmailId(gmailId);
|
|
|
1646 |
sendNotificationModel.setUserIds(new ArrayList<>(user.getId()));
|
| 31249 |
tejbeer |
1647 |
|
| 31677 |
amit.gupta |
1648 |
notificationService.sendNotificationToAll(sendNotificationModel);
|
| 31249 |
tejbeer |
1649 |
|
| 31677 |
amit.gupta |
1650 |
return responseSender.ok(true);
|
| 31249 |
tejbeer |
1651 |
|
| 31677 |
amit.gupta |
1652 |
}
|
| 31249 |
tejbeer |
1653 |
|
| 30077 |
tejbeer |
1654 |
}
|