Rev 29753 | Rev 30290 | 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.io.ByteArrayInputStream;import java.io.InputStream;import java.time.LocalDate;import java.time.LocalDateTime;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.HashSet;import java.util.List;import java.util.Map;import java.util.stream.Collectors;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.transaction.Transactional;import org.apache.commons.csv.CSVRecord;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.core.io.InputStreamResource;import org.springframework.http.HttpHeaders;import org.springframework.http.HttpStatus;import org.springframework.http.ResponseEntity;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;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 org.springframework.web.bind.annotation.RequestPart;import org.springframework.web.multipart.MultipartFile;import com.google.gson.Gson;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.model.Legend;import com.spice.profitmandi.common.model.OptionModel;import com.spice.profitmandi.common.model.PieLables;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.common.util.FileUtil;import com.spice.profitmandi.dao.entity.auth.AuthUser;import com.spice.profitmandi.dao.entity.fofo.FofoStore;import com.spice.profitmandi.dao.entity.user.Lead;import com.spice.profitmandi.dao.entity.user.LeadActivity;import com.spice.profitmandi.dao.enumuration.dtr.LeadSource;import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;import com.spice.profitmandi.dao.model.ChartLeadModel;import com.spice.profitmandi.dao.model.CreateLeacdActivityRequest;import com.spice.profitmandi.dao.model.CreateRefferalRequest;import com.spice.profitmandi.dao.model.DataLeadModel;import com.spice.profitmandi.dao.model.LeadStatusData;import com.spice.profitmandi.dao.repository.auth.AuthRepository;import com.spice.profitmandi.dao.repository.cs.PositionRepository;import com.spice.profitmandi.dao.repository.dtr.LeadActivityRepository;import com.spice.profitmandi.dao.repository.dtr.LeadRepository;import com.spice.profitmandi.dao.repository.inventory.StateRepository;import com.spice.profitmandi.service.AuthService;import com.spice.profitmandi.web.model.LoginDetails;import com.spice.profitmandi.web.util.CookiesProcessor;import com.spice.profitmandi.web.util.MVCResponseSender;@Controller@Transactional(rollbackOn = Throwable.class)public class LeadController {private static final Logger LOGGER = LogManager.getLogger(LeadController.class);@Autowiredprivate LeadRepository leadRepository;@Autowiredprivate LeadActivityRepository leadActivityRepository;@Autowiredprivate StateRepository stateRepository;@Autowiredprivate AuthService authService;@Autowiredprivate AuthRepository authRepository;@Autowiredprivate Gson gson;@Autowiredprivate CookiesProcessor cookiesProcessor;@AutowiredPositionRepository positionRepository;@Autowiredprivate MVCResponseSender mvcResponseSender;List<LeadStatus> status = Arrays.asList(LeadStatus.notInterested, LeadStatus.finalized);@RequestMapping(value = "/getOpenLead", method = RequestMethod.GET)public String getOpenLead(HttpServletRequest request,@RequestParam(name = "leadStatus", required = false, defaultValue = "All") List<LeadStatus> leadStatus,@RequestParam(name = "color", required = false, defaultValue = "All") List<String> color,@RequestParam(name = "leadDate", required = false, defaultValue = "") LocalDate leadDate, Model model)throws Exception {LocalDateTime localDateTime = null;if (leadDate != null) {localDateTime = leadDate.atStartOfDay();}LOGGER.info("localDateTime" + localDateTime);LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);String emailId = loginDetails.getEmailId();AuthUser authUser = authRepository.selectByEmailOrMobile(emailId);boolean authPositon = positionRepository.hasCategory(authUser.getId(),ProfitMandiConstants.TICKET_CATEGORY_SALES);if (leadStatus.contains(LeadStatus.All)) {leadStatus.add(LeadStatus.pending);leadStatus.add(LeadStatus.notInterested);leadStatus.add(LeadStatus.finalized);}if (color.contains("All")) {color.add("yellow");color.add("green");}List<Lead> leads = new ArrayList<>();model.addAttribute("colors", color);Map<Integer, List<LeadActivity>> leadActivityMap = new HashMap<>();List<Integer> authUserIds = null;LOGGER.info("color111" + color);List<Lead> leadFollowUp = new ArrayList<>();if (authPositon) {authUserIds = authService.getAllReportees(authUser.getId());authUserIds.add(authUser.getId());LOGGER.info("authIds" + authUserIds);LOGGER.info("leadStatus" + leadStatus);if (localDateTime == null) {if (!leadStatus.contains(LeadStatus.followUp)) {leads = leadRepository.selectAllByColorStatusAndUpdatedTimestampAndAuthIds(leadStatus, authUserIds,color, LocalDateTime.now().minusMonths(1));}if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);leads.addAll(leadFollowUp);}} else {if (!leadStatus.contains(LeadStatus.followUp)) {leads = leadRepository.selectAllByColorStatusAndUpdatedTimestampAndAuthIds(leadStatus, authUserIds,color, localDateTime);}if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);leads.addAll(leadFollowUp);}}} else {if (localDateTime == null) {if (!leadStatus.contains(LeadStatus.followUp)) {leads = leadRepository.selectAllByColorStatusAndUpdatedTimestamp(leadStatus, color,LocalDateTime.now().minusMonths(1));}if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);leads.addAll(leadFollowUp);}LOGGER.info("leadlocalDateTime1" + leads);} else {if (!leadStatus.contains(LeadStatus.followUp)) {leads = leadRepository.selectAllByColorStatusAndUpdatedTimestamp(leadStatus, color, localDateTime);}if (leadStatus.contains(LeadStatus.followUp) || leadStatus.contains(LeadStatus.All)) {leadFollowUp = leadRepository.selectAllByStatus(LeadStatus.followUp);leads.addAll(leadFollowUp);}LOGGER.info("leadlocalDateTime2" + leads);}}if (authPositon && authUserIds.size() > 0) {List<String> leadCreators = new ArrayList<>();leadCreators.add("daily-sync");leadCreators.addAll(authRepository.selectAllAuthUserByIds(authUserIds).stream().map(x -> x.getFullName()).collect(Collectors.toList()));model.addAttribute("leadCreators", leadCreators);}List<Lead> weekLast = new ArrayList<>();List<Lead> weekThird = new ArrayList<>();List<Lead> weekSecond = new ArrayList<>();List<Lead> weekFirst = new ArrayList<>();LocalDateTime curDate = LocalDate.now().atStartOfDay();List<LeadWeakWiseModel> lwDays = new ArrayList<>();for (int i = 7; i >= 1; i--) {LocalDateTime startOfDay = curDate.minusDays(i);LeadWeakWiseModel lm = new LeadWeakWiseModel();lm.setMonth(startOfDay.toLocalDate());lwDays.add(lm);}if (!leads.isEmpty()) {weekLast.addAll(leads.stream().filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(28))&& x.getCreatedTimestamp().isBefore(curDate.minusDays(21))).collect(Collectors.toList()));weekThird.addAll(leads.stream().filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(21))&& x.getCreatedTimestamp().isBefore(curDate.minusDays(14))).collect(Collectors.toList()));weekSecond.addAll(leads.stream().filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(14))&& x.getCreatedTimestamp().isBefore(curDate.minusDays(7))).collect(Collectors.toList()));weekFirst.addAll(leads.stream().filter(x -> x.getCreatedTimestamp().isAfter(curDate.minusDays(7))).collect(Collectors.toList()));}LOGGER.info("weekLast" + weekLast);LOGGER.info("weekThird" + weekThird);LOGGER.info("weekSecond" + weekSecond);Map<String, Long> leadLasts = weekLast.stream().collect(Collectors.groupingBy(x -> x.getCreatedBy(), Collectors.counting()));Map<String, Long> leadThirds = weekThird.stream().collect(Collectors.groupingBy(x -> x.getCreatedBy(), Collectors.counting()));Map<String, Long> leadSeconds = weekSecond.stream().collect(Collectors.groupingBy(x -> x.getCreatedBy(),Collectors.mapping(Lead::getCreatedBy, Collectors.counting())));Map<String, Map<LocalDate, Long>> leadFirsts = weekFirst.stream().collect(Collectors.groupingBy(x -> x.getCreatedBy(),Collectors.groupingBy(x -> x.getCreatedTimestamp().toLocalDate(), Collectors.counting())));LOGGER.info("leadFirsts" + leadFirsts);List<Integer> authIds = new ArrayList<>();if (!leads.isEmpty()) {authIds.addAll(leads.stream().map(x -> x.getAssignTo()).collect(Collectors.toList()));leadActivityMap = leadActivityRepository.selectAllByleadIds(leads.stream().map(x -> x.getId()).collect(Collectors.toList())).stream().collect(Collectors.groupingBy(LeadActivity::getLeadId, Collectors.toList()));Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));model.addAttribute("leadActivityMap", leadActivityMap);model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);}ChartLeadModel cm = this.getLeadChart(leads);model.addAttribute("chartLead", gson.toJson(cm));LOGGER.info("ChartLeadModel" + gson.toJson(cm));LOGGER.info("lwDays" + lwDays);LOGGER.info("leads" + leads);List<String> stateNames = stateRepository.selectAll().stream().map(x -> x.getName()).collect(Collectors.toList());List<AuthUser> authUsers = authRepository.selectAllActiveUser();LocalDate lastDate = curDate.minusDays(1).toLocalDate();List<LocalDate> weekDates = new ArrayList<>();weekDates.add(curDate.minusDays(28).toLocalDate());weekDates.add(curDate.minusDays(22).toLocalDate());weekDates.add(curDate.minusDays(21).toLocalDate());weekDates.add(curDate.minusDays(15).toLocalDate());weekDates.add(curDate.minusDays(14).toLocalDate());weekDates.add(curDate.minusDays(8).toLocalDate());weekDates.add(curDate.minusDays(7).toLocalDate());LOGGER.info("lastDate" + lastDate);model.addAttribute("weekDates", weekDates);model.addAttribute("leadDate", leadDate);model.addAttribute("lastDate", lastDate);model.addAttribute("stateNames", stateNames);model.addAttribute("authUsers", authUsers);model.addAttribute("lead", leads);model.addAttribute("leadStatus", LeadStatus.values());model.addAttribute("leadLasts", leadLasts);model.addAttribute("leadThirds", leadThirds);model.addAttribute("leadSeconds", leadSeconds);model.addAttribute("leadFirsts", leadFirsts);model.addAttribute("lwDays", lwDays);model.addAttribute("selectedLeadStatus", leadStatus.get(0));return "lead";}public ChartLeadModel getLeadChart(List<Lead> leads) throws ProfitMandiBusinessException {Map<LeadStatus, Long> leadStatusMap = leads.stream().collect(Collectors.groupingBy(x -> x.getStatus(), Collectors.mapping(Lead::getStatus, Collectors.counting())));Map<String, Long> hotLeadsMap = leads.stream().collect(Collectors.groupingBy(x -> x.getColor(), Collectors.mapping(Lead::getColor, Collectors.counting())));LOGGER.info("hotLeadsMap" + hotLeadsMap);ChartLeadModel cm = new ChartLeadModel();HashSet<LeadStatus> labels = new HashSet<LeadStatus>();labels.addAll(leadStatusMap.keySet());HashSet<String> hotLeads = new HashSet<String>();hotLeads.addAll(leadStatusMap.keySet().stream().map(x -> x.toString()).collect(Collectors.toSet()));hotLeads.add("HotLead");HashSet<String> hotLeadKeys = new HashSet<String>();hotLeadKeys.add("HotLead");List<String> hotLeadGreen = new ArrayList<>(hotLeadKeys);LOGGER.info("hotLeads" + hotLeads);List<LeadStatus> labelList = new ArrayList<>(labels);List<String> backgroundColor = new ArrayList<>();LOGGER.info("hotLeadKeys" + hotLeadKeys);List<Long> values = new ArrayList<>();for (String hotLead : hotLeads) {if (hotLead.equals("pending")) {backgroundColor.add("pink");values.add(leadStatusMap.get(LeadStatus.pending));}if (hotLead.equals("notInterested")) {backgroundColor.add("red");values.add(leadStatusMap.get(LeadStatus.notInterested));}if (hotLead.equals("followUp")) {backgroundColor.add("#9ACD32");values.add(leadStatusMap.get(LeadStatus.followUp));}if (hotLead.equals("finalized")) {backgroundColor.add("blue");values.add(leadStatusMap.get(LeadStatus.finalized));}if (hotLead.equals("HotLead")) {backgroundColor.add("green");values.add(hotLeadsMap.get("Green"));}}LOGGER.info("labelList" + labelList);LOGGER.info("backgroundColor" + backgroundColor);LOGGER.info("labelsChartLead" + labels);LeadStatusData data = new LeadStatusData();data.setData(values);data.setBackgroundColor(backgroundColor);data.setLabel("DataSet 1");PieLables label = new PieLables();label.setFontColor("black");label.setFontSize(15);Legend legend = new Legend();legend.setLabels(label);legend.setPosition("left");List<LeadStatusData> dataList = new ArrayList<>();dataList.add(data);DataLeadModel datasets = new DataLeadModel();datasets.setDatasets(dataList);datasets.setLabels(hotLeads);OptionModel om = new OptionModel();om.setLegend(legend);cm.setType("pie");cm.setData(datasets);cm.setOptions(om);return cm;}@RequestMapping(value = "/getClosedLead", method = RequestMethod.GET)public String getClosedLead(HttpServletRequest request,@RequestParam(name = "offset", defaultValue = "0") int offset,@RequestParam(name = "limit", defaultValue = "10") int limit,@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)throws Exception {List<AuthUser> authUsers = authRepository.selectAllActiveUser();List<Lead> leads = null;long size = 0;leads = leadRepository.selectAllByStatus(status, offset, limit);size = leadRepository.selectCountByStatus(status);if (!leads.isEmpty()) {List<Integer> authIds = new ArrayList<>();for (Lead lead : leads) {authIds.add(lead.getAssignTo());}Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));model.addAttribute("leads", leads);model.addAttribute("start", offset + 1);model.addAttribute("size", size);model.addAttribute("searchTerm", searchTerm);model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);model.addAttribute("url", "/getPaginatedClosedLeads");if (leads.size() < limit) {model.addAttribute("end", offset + leads.size());} else {model.addAttribute("end", offset + limit);}} else {model.addAttribute("lead", leads);model.addAttribute("size", size);}model.addAttribute("authUsers", authUsers);return "lead-close";}@RequestMapping(value = "/getPaginatedClosedLeads", method = RequestMethod.GET)public String getPaginatedClosedLeads(HttpServletRequest request,@RequestParam(name = "offset", defaultValue = "0") int offset,@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)throws ProfitMandiBusinessException {List<Lead> leads = null;leads = leadRepository.selectAllByStatus(status, offset, limit);if (!leads.isEmpty()) {List<Integer> authIds = new ArrayList<>();for (Lead lead : leads) {authIds.add(lead.getAssignTo());}Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);model.addAttribute("leads", leads);model.addAttribute("url", "/getPaginatedClosedLeads");} else {model.addAttribute("leads", leads);}return "lead-close-paginated";}@RequestMapping(value = "/searchLeads")public String getClosedLeads(HttpServletRequest request,@RequestParam(name = "offset", defaultValue = "0") int offset,@RequestParam(name = "limit", defaultValue = "10") int limit,@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)throws ProfitMandiBusinessException {List<AuthUser> authUsers = authRepository.selectAllActiveUser();List<Lead> leads = null;long size = 0;if (!(searchTerm.equals(""))) {leads = leadRepository.selectBySearchTerm(status, searchTerm, offset, limit);if (!(leads.size() == 0)) {size = leadRepository.selectCountByStatus(status);List<Integer> authIds = new ArrayList<>();for (Lead lead : leads) {authIds.add(lead.getAssignTo());}Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);model.addAttribute("leads", leads);model.addAttribute("start", offset + 1);model.addAttribute("size", size);model.addAttribute("searchTerm", searchTerm);if (leads.size() < limit) {model.addAttribute("end", offset + leads.size());} else {model.addAttribute("end", offset + limit);}} else {throw new ProfitMandiBusinessException("lead", searchTerm, "leads Not Found");}} else {leads = leadRepository.selectAllByStatus(status, offset, limit);size = leadRepository.selectCountByStatus(status);if (!leads.isEmpty()) {List<Integer> authIds = new ArrayList<>();for (Lead lead : leads) {authIds.add(lead.getAssignTo());}Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));model.addAttribute("leads", leads);model.addAttribute("start", offset + 1);model.addAttribute("size", size);model.addAttribute("searchTerm", searchTerm);model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);if (leads.size() < limit) {model.addAttribute("end", offset + leads.size());} else {model.addAttribute("end", offset + limit);}}}model.addAttribute("authUsers", authUsers);return "lead-close";}@RequestMapping(value = "/searchLeadPaginated")public String searchLeadPaginated(HttpServletRequest request,@RequestParam(name = "offset", defaultValue = "0") int offset,@RequestParam(name = "limit", defaultValue = "10") int limit,@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)throws ProfitMandiBusinessException {LOGGER.info("In search Item....");List<Lead> leads = null;if (!searchTerm.equals("")) {leads = leadRepository.selectBySearchTerm(status, searchTerm, offset, limit);if (!(leads.size() == 0)) {List<Integer> authIds = new ArrayList<>();for (Lead lead : leads) {authIds.add(lead.getAssignTo());}Map<Integer, AuthUser> authIdAndAuthUserMap = authRepository.selectAllAuthUserByIds(authIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);model.addAttribute("leads", leads);}}return "lead-close-paginated";}@RequestMapping(value = "/getLeadActivity", method = RequestMethod.GET)public String getLeadActivity(HttpServletRequest request, @RequestParam int leadId, Model model) throws Exception {List<LeadActivity> leadActivity = leadActivityRepository.selectBYLeadId(leadId);model.addAttribute("leadActivity", leadActivity);return "lead_activity_modal";}@RequestMapping(value = "/createLead", method = RequestMethod.POST)public String CreateLead(HttpServletRequest request, @RequestBody CreateRefferalRequest createRefferalRequest,Model model) throws Exception {LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);LOGGER.info("createRefferalRequest" + createRefferalRequest.getSchelduleTimestamp());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());lead.setAssignTo(createRefferalRequest.getAssignTo());lead.setSource(createRefferalRequest.getSource());lead.setColor("yellow");// changeAuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());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() == LeadStatus.followUp) {leadActivity.setSchelduleTimestamp(createRefferalRequest.getSchelduleTimestamp());} else {leadActivity.setSchelduleTimestamp(null);}leadActivity.setCreatedTimestamp(LocalDateTime.now());leadActivityRepository.persist(leadActivity);model.addAttribute("response", mvcResponseSender.createResponseString(true));return "response";}@RequestMapping(value = "/editLead", method = RequestMethod.POST)public String EditLead(HttpServletRequest request,@RequestBody CreateLeacdActivityRequest createLeadActivityRequest, Model model) throws Exception {LeadActivity leadActivity = new LeadActivity();leadActivity.setLeadId(createLeadActivityRequest.getId());leadActivity.setRemark(createLeadActivityRequest.getRemark());LOGGER.info("createRefferalRequest" + createLeadActivityRequest);if (createLeadActivityRequest.getStatus() == LeadStatus.followUp) {leadActivity.setSchelduleTimestamp(createLeadActivityRequest.getScheldule());} else {leadActivity.setSchelduleTimestamp(null);}leadActivity.setCreatedTimestamp(LocalDateTime.now());leadActivityRepository.persist(leadActivity);Lead lead = leadRepository.selectById(createLeadActivityRequest.getId());lead.setAssignTo(createLeadActivityRequest.getAssignTo());lead.setStatus(createLeadActivityRequest.getStatus());lead.setNotinterestedReason(createLeadActivityRequest.getReason());lead.setUpdatedTimestamp(LocalDateTime.now());lead = leadRepository.selectById(createLeadActivityRequest.getId());int authId = 0;if (lead != null) {authId = lead.getAssignTo();Map<Integer, LeadActivity> leadActivityMap = new HashMap<>();List<LeadActivity> leadActivitys = leadActivityRepository.selectBYLeadId(lead.getId());if (!leadActivitys.isEmpty()) {leadActivityMap.put(lead.getId(), leadActivitys.get(0));}Map<Integer, AuthUser> authIdAndAuthUserMap = new HashMap<>();AuthUser AuthUser = authRepository.selectById(authId);authIdAndAuthUserMap.put(AuthUser.getId(), AuthUser);model.addAttribute("leadActivityMap", leadActivityMap);model.addAttribute("authIdAndAuthUserMap", authIdAndAuthUserMap);}model.addAttribute("request", lead);return "edit-lead";}@RequestMapping(value = "/downloadIvoryLead", method = RequestMethod.GET)public ResponseEntity<?> downloadDelayDayTemplate(HttpServletRequest request) throws Exception {List<String> stateNames = stateRepository.selectAll().stream().map(x -> x.getName()).collect(Collectors.toList());List<List<?>> rows = new ArrayList<>();List<LeadSource> lss = LeadSource.enumValues;for (LeadSource ls : lss) {rows.add(Arrays.asList("-", "-", "-", "-", "-", "-", "-", ls));}for (String stateName : stateNames) {rows.add(Arrays.asList("-", "-", "-", "-", stateName, "-", "-", "-"));}org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("First Name","Last Name", "Address", "City", "State", "Mobile", "Assign To(email)", "Source"), rows);final HttpHeaders headers = new HttpHeaders();headers.set("Content-Type", "text/csv");headers.set("Content-disposition", "inline; filename=leads.format.csv");headers.setContentLength(baos.toByteArray().length);final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);}@RequestMapping(value = "/csvFileAndSetLead", method = RequestMethod.POST)public String readCsvFileAndSetLead(HttpServletRequest request, Model model, HttpServletResponse response,@RequestPart MultipartFile file) throws Throwable {LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);String email = loginDetails.getEmailId();AuthUser createdBy = authRepository.selectByEmailOrMobile(email);LOGGER.info("file" + file.toString());String fileName = file.getName();String fileNames = file.getOriginalFilename();LOGGER.info("fileName" + fileName);LOGGER.info("fileNames" + fileNames);List<CSVRecord> records = FileUtil.readFile(file);for (CSVRecord record : records) {Lead lead = new Lead();lead.setFirstName(record.get(0));lead.setLastName(record.get(1));lead.setAddress(record.get(2));lead.setCity(record.get(3));lead.setState(record.get(4));lead.setLeadMobile(record.get(5));LOGGER.info("record" + record.get(6));AuthUser assignTo = authRepository.selectByEmailOrMobile(record.get(6));if (assignTo == null) {throw new ProfitMandiBusinessException("Assign To ", record.get(6), "email id not exist");}lead.setAssignTo(assignTo.getId());lead.setSource(record.get(7));lead.setCreatedTimestamp(LocalDateTime.now());lead.setUpdatedTimestamp(LocalDateTime.now());lead.setStatus(LeadStatus.pending);lead.setColor("yellow");// changelead.setCreatedBy(createdBy.getFullName());lead.setAuthId(createdBy.getId());leadRepository.persist(lead);LeadActivity leadActivity = new LeadActivity();leadActivity.setLeadId(lead.getId());leadActivity.setRemark("New Lead");leadActivity.setSchelduleTimestamp(null);leadActivity.setCreatedTimestamp(LocalDateTime.now());leadActivityRepository.persist(leadActivity);model.addAttribute("response", mvcResponseSender.createResponseString(true));}model.addAttribute("responseSTG", mvcResponseSender.createResponseString(true));return "response";}}