Rev 24388 | Rev 24439 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.dao.repository.cs;import java.time.LocalDateTime;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.model.CustomRetailer;import com.spice.profitmandi.dao.entity.auth.AuthUser;import com.spice.profitmandi.dao.entity.cs.Activity;import com.spice.profitmandi.dao.entity.cs.PartnerRegion;import com.spice.profitmandi.dao.entity.cs.Position;import com.spice.profitmandi.dao.entity.cs.Ticket;import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;import com.spice.profitmandi.dao.entity.fofo.ActivityType;import com.spice.profitmandi.dao.enumuration.cs.EscalationType;import com.spice.profitmandi.dao.repository.auth.AuthRepository;import com.spice.profitmandi.service.user.RetailerService;@Componentpublic class CsServiceImpl implements CsService {@AutowiredTicketRepository ticketRepository;@AutowiredTicketCategoryRepository ticketCategoryRepository;@AutowiredTicketSubCategoryRepository ticketSubCategoryRepository;@AutowiredActivityRepository activityRepository;@AutowiredPartnerRegionRepository partnerRepository;@Autowiredprivate PositionRepository positionRepository;@Autowiredprivate AuthRepository authRepository;@Autowiredprivate RetailerService retailerService;@Overridepublic void createTicket(int fofoId, int categoryId, int subcategoryId, String message) {ActivityType type = ActivityType.OPENED;EscalationType escalationType = EscalationType.L1;Ticket ticket = new Ticket();ticket.setSubCategoryId(subcategoryId);ticket.setFofoId(fofoId);ticket.setCreateTimestamp(LocalDateTime.now());ticket.setUpdateTimestamp(LocalDateTime.now());try {ticket.setAssigneeId(this.getAssigneeId(categoryId, escalationType));} catch (Exception e) {e.printStackTrace();}ticketRepository.persist(ticket);Activity activity = this.createActivity(type, message, 0);this.addActivity(ticket.getId(), activity);}private Activity createActivity(ActivityType activityType, String message, int createdBy) {Activity activity = new Activity();activity.setMessage(message);activity.setCreatedBy(createdBy);activity.setType(activityType);activity.setCreateTimestamp(LocalDateTime.now());return activity;}private int getAssigneeId(int categoryId, EscalationType escalationType) throws ProfitMandiBusinessException {Position position = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId, escalationType);return position.getAuthUserId();/** if(ActivityType.escalationTypes.contains(escalationType)) {* //escalationMatrix } else { throw new* ProfitMandiBusinessException("SubCategory", subcategoryId,* "Could not find Assignee for "); }*/}@Overridepublic void addActivity(int ticketId, Activity activity) {activity.setTicketId(ticketId);activityRepository.persist(activity);}@Overridepublic void addPartnerToRegion(int regionId, List<Integer> fofoIds) {for (Integer fofoId : fofoIds) {PartnerRegion partnerRegion = partnerRepository.selectByRegionIdAndFofoId(regionId, fofoId);if (partnerRegion == null) {partnerRegion = new PartnerRegion();partnerRegion.setFofoId(fofoId);partnerRegion.setRegionId(regionId);partnerRepository.persist(partnerRegion);} else {continue;}}}@Overridepublic Map<Integer, AuthUser> getAuthUserIdAndAuthUserMap(List<Ticket> tickets) {Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();for (Ticket ticket : tickets) {AuthUser authUser = authRepository.selectById(ticket.getAssigneeId());authUserIdAndAuthUserMap.put(ticket.getAssigneeId(), authUser);}return authUserIdAndAuthUserMap;}@Overridepublic Map<Integer, TicketSubCategory> getSubCategoryIdAndSubCategoryMap(List<Ticket> tickets) {Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = new HashMap<>();for (Ticket ticket : tickets) {TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());subCategoryIdAndSubCategoryMap.put(ticket.getSubCategoryId(), ticketSubCategory);}return subCategoryIdAndSubCategoryMap;}@Overridepublic Map<Integer, CustomRetailer> getPartnerByFofoIds(List<Ticket> tickets) {List<Integer> fofoIds = new ArrayList<>();for (Ticket ticket : tickets) {fofoIds.add(ticket.getFofoId());}Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService.getFofoRetailers(fofoIds);return fofoIdsAndCustomRetailer;}}