Rev 25906 | Rev 25952 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import java.time.LocalDateTime;import java.util.List;import javax.servlet.http.HttpServletRequest;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.format.annotation.DateTimeFormat;import org.springframework.http.MediaType;import org.springframework.http.ResponseEntity;import org.springframework.stereotype.Controller;import org.springframework.transaction.annotation.Transactional;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.common.web.util.ResponseSender;import com.spice.profitmandi.dao.entity.auth.AuthUser;import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;import com.spice.profitmandi.dao.entity.dtr.User;import com.spice.profitmandi.dao.entity.user.Lead;import com.spice.profitmandi.dao.entity.user.LeadActivity;import com.spice.profitmandi.dao.entity.user.Promoter;import com.spice.profitmandi.dao.entity.user.Refferal;import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;import com.spice.profitmandi.dao.repository.auth.AuthRepository;import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;import com.spice.profitmandi.dao.repository.dtr.LeadRepository;import com.spice.profitmandi.dao.repository.dtr.RefferalRepository;import com.spice.profitmandi.dao.repository.dtr.UserRepository;import com.spice.profitmandi.dao.repository.user.PromoterRepository;import com.spice.profitmandi.web.req.CreateRefferalRequest;import io.swagger.annotations.ApiImplicitParam;import io.swagger.annotations.ApiImplicitParams;@Controller@Transactional(rollbackFor = Throwable.class)public class LeadController {private static final Logger LOGGER = LogManager.getLogger(LeadController.class);@Autowiredprivate ResponseSender<?> responseSender;@Autowiredprivate AuthRepository authRepository;@Autowiredprivate LeadRepository leadRepository;@Autowiredprivate LeadActivityRepository leadActivityRepository;@RequestMapping(value = "/lead", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })public ResponseEntity<?> LeadUser(HttpServletRequest request,@RequestBody CreateRefferalRequest createRefferalRequest) throws Exception {Lead lead = new Lead();lead.setFirstName(createRefferalRequest.getFirstName());lead.setLastName(createRefferalRequest.getLastName());lead.setLeadMobile(createRefferalRequest.getMobile());lead.setState(createRefferalRequest.getState());lead.setCity(createRefferalRequest.getCity());lead.setAddress(createRefferalRequest.getAddress());lead.setCreatedTimestamp(LocalDateTime.now());lead.setUpdatedTimestamp(LocalDateTime.now());lead.setStatus(createRefferalRequest.getStatus());AuthUser authUser = authRepository.selectByGmailId(createRefferalRequest.getReffereeEmail());String authUserName = authUser.getFirstName() + " " + authUser.getLastName();lead.setCreatedBy(authUserName);lead.setAuthId(authUser.getId());leadRepository.persist(lead);LeadActivity leadActivity = new LeadActivity();leadActivity.setLeadId(lead.getId());leadActivity.setRemark(createRefferalRequest.getRemark());if (createRefferalRequest.getStatus().equals(LeadStatus.followUp)) {leadActivity.setSchelduleTimestamp(createRefferalRequest.getSchelduleTimestamp());} else {leadActivity.setSchelduleTimestamp(null);}leadActivity.setCreatedTimestamp(LocalDateTime.now());leadActivityRepository.persist(leadActivity);return responseSender.ok(true);}@RequestMapping(value = "/lead-description", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })public ResponseEntity<?> leadDescription(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId,@RequestParam(name = "status") LeadStatus status,@RequestParam(name = "offset", defaultValue = "0") int offset,@RequestParam(name = "limit", defaultValue = "10") int limit) throws ProfitMandiBusinessException {AuthUser authUser = authRepository.selectByGmailId(gmailId);List<Lead> leads = leadRepository.selectByAuthIdAndStatus(authUser.getId(), status, offset, limit);return responseSender.ok(leads);}@RequestMapping(value = "/getlead", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })public ResponseEntity<?> getLead(HttpServletRequest request, @RequestParam(name = "id") int id)throws ProfitMandiBusinessException {List<LeadActivity> leadActivities = leadActivityRepository.selectBYLeadId(id);return responseSender.ok(leadActivities);}@RequestMapping(value = "/leadUpdate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })public ResponseEntity<?> leadUpdate(HttpServletRequest request, @RequestParam(name = "id") int id,@RequestParam(name = "status") LeadStatus status, @RequestParam(name = "remark") String remark,@RequestParam(name = "schelduleTimestamp") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime schelduleTimestamp)throws ProfitMandiBusinessException {Lead lead = leadRepository.selectById(id);LeadActivity leadActivity = new LeadActivity();if (status == LeadStatus.followUp) {lead.setStatus(status);leadActivity.setSchelduleTimestamp(schelduleTimestamp);leadActivity.setRemark(remark);leadActivity.setLeadId(id);leadActivity.setCreatedTimestamp(LocalDateTime.now());lead.setUpdatedTimestamp(LocalDateTime.now());leadActivityRepository.persist(leadActivity);} else {lead.setStatus(status);leadActivity.setRemark(remark);leadActivity.setLeadId(id);leadActivity.setCreatedTimestamp(LocalDateTime.now());leadActivity.setSchelduleTimestamp(null);lead.setUpdatedTimestamp(LocalDateTime.now());leadActivityRepository.persist(leadActivity);}return responseSender.ok(true);}}