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