| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.dao.repository.cs;
|
1 |
package com.spice.profitmandi.dao.repository.cs;
|
| 2 |
|
- |
|
| 3 |
import java.time.LocalDateTime;
|
2 |
import java.time.LocalDateTime;
|
| 4 |
import java.util.ArrayList;
|
3 |
import java.util.ArrayList;
|
| 5 |
import java.util.HashMap;
|
4 |
import java.util.HashMap;
|
| - |
|
5 |
import java.util.HashSet;
|
| 6 |
import java.util.List;
|
6 |
import java.util.List;
|
| 7 |
import java.util.Map;
|
7 |
import java.util.Map;
|
| 8 |
|
- |
|
| - |
|
8 |
import org.apache.commons.lang.RandomStringUtils;
|
| - |
|
9 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
10 |
import org.apache.logging.log4j.Logger;
|
| 9 |
import org.springframework.beans.factory.annotation.Autowired;
|
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
12 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 10 |
import org.springframework.stereotype.Component;
|
13 |
import org.springframework.stereotype.Component;
|
| 11 |
|
- |
|
| 12 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
14 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 13 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
15 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| - |
|
16 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
17 |
import com.spice.profitmandi.common.util.Utils;
|
| 14 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
18 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 15 |
import com.spice.profitmandi.dao.entity.cs.Activity;
|
19 |
import com.spice.profitmandi.dao.entity.cs.Activity;
|
| 16 |
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
|
20 |
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
|
| 17 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
21 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 18 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
22 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
| - |
|
23 |
import com.spice.profitmandi.dao.entity.cs.TicketCategory;
|
| 19 |
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
|
24 |
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
|
| 20 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
25 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
| 21 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
26 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 22 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
27 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 23 |
import com.spice.profitmandi.service.user.RetailerService;
|
28 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 24 |
|
29 |
|
| 25 |
@Component
|
30 |
@Component
|
| 26 |
public class CsServiceImpl implements CsService {
|
31 |
public class CsServiceImpl implements CsService {
|
| 27 |
|
32 |
|
| - |
|
33 |
private static final Logger LOGGER = LogManager.getLogger(CsServiceImpl.class);
|
| - |
|
34 |
|
| - |
|
35 |
private static final String ASSIGNED_TICKET = "Dear %s,You have assigned a ticket by %s. Regards\nSmartdukaan";
|
| - |
|
36 |
private static final String ASSINMENT_SUBJECT = "Assignment Ticket";
|
| - |
|
37 |
|
| 28 |
@Autowired
|
38 |
@Autowired
|
| 29 |
TicketRepository ticketRepository;
|
39 |
TicketRepository ticketRepository;
|
| 30 |
|
40 |
|
| 31 |
@Autowired
|
41 |
@Autowired
|
| - |
|
42 |
JavaMailSender mailSender;
|
| - |
|
43 |
|
| - |
|
44 |
@Autowired
|
| 32 |
TicketCategoryRepository ticketCategoryRepository;
|
45 |
TicketCategoryRepository ticketCategoryRepository;
|
| 33 |
|
46 |
|
| 34 |
@Autowired
|
47 |
@Autowired
|
| 35 |
TicketSubCategoryRepository ticketSubCategoryRepository;
|
48 |
TicketSubCategoryRepository ticketSubCategoryRepository;
|
| 36 |
|
49 |
|
| 37 |
@Autowired
|
50 |
@Autowired
|
| 38 |
ActivityRepository activityRepository;
|
51 |
ActivityRepository activityRepository;
|
| 39 |
|
52 |
|
| 40 |
@Autowired
|
53 |
@Autowired
|
| 41 |
PartnerRegionRepository partnerRepository;
|
54 |
PartnerRegionRepository partnerRegionRepository;
|
| 42 |
|
55 |
|
| 43 |
@Autowired
|
56 |
@Autowired
|
| 44 |
private PositionRepository positionRepository;
|
57 |
private PositionRepository positionRepository;
|
| 45 |
|
58 |
|
| 46 |
@Autowired
|
59 |
@Autowired
|
| Line 48... |
Line 61... |
| 48 |
|
61 |
|
| 49 |
@Autowired
|
62 |
@Autowired
|
| 50 |
private RetailerService retailerService;
|
63 |
private RetailerService retailerService;
|
| 51 |
|
64 |
|
| 52 |
@Override
|
65 |
@Override
|
| 53 |
public void createTicket(int fofoId, int categoryId, int subcategoryId, String message) {
|
66 |
public void createTicket(int fofoId, int categoryId, int subcategoryId, String message)
|
| - |
|
67 |
throws ProfitMandiBusinessException {
|
| 54 |
|
68 |
|
| 55 |
ActivityType type = ActivityType.OPENED;
|
69 |
ActivityType type = ActivityType.OPENED;
|
| 56 |
EscalationType escalationType = EscalationType.L1;
|
70 |
EscalationType escalationTypeL1 = EscalationType.L1;
|
| - |
|
71 |
EscalationType escalationTypeL2 = EscalationType.L2;
|
| - |
|
72 |
EscalationType escalationTypeL3 = EscalationType.L3;
|
| 57 |
Ticket ticket = new Ticket();
|
73 |
Ticket ticket = new Ticket();
|
| 58 |
ticket.setSubCategoryId(subcategoryId);
|
74 |
ticket.setSubCategoryId(subcategoryId);
|
| 59 |
ticket.setFofoId(fofoId);
|
75 |
ticket.setFofoId(fofoId);
|
| 60 |
ticket.setCreateTimestamp(LocalDateTime.now());
|
76 |
ticket.setCreateTimestamp(LocalDateTime.now());
|
| 61 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
77 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
| - |
|
78 |
ticket.setHappyCode(getRandomString());
|
| - |
|
79 |
int l3Auth = this.getAuthUserId(categoryId, escalationTypeL3, fofoId);
|
| - |
|
80 |
int l1Auth = this.getAuthUserId(categoryId, escalationTypeL1, fofoId);
|
| - |
|
81 |
int l2Auth = this.getAuthUserId(categoryId, escalationTypeL2, fofoId);
|
| - |
|
82 |
LOGGER.info(l1Auth + "-" + l2Auth + "-" + l3Auth);
|
| - |
|
83 |
if (l1Auth == 0) {
|
| - |
|
84 |
if (l2Auth == 0) {
|
| - |
|
85 |
this.setAssignment(ticket);
|
| - |
|
86 |
} else {
|
| - |
|
87 |
ticket.setAssigneeId(l2Auth);
|
| - |
|
88 |
}
|
| - |
|
89 |
} else {
|
| - |
|
90 |
ticket.setAssigneeId(l1Auth);
|
| - |
|
91 |
ticket.setL1AuthUser(l1Auth);
|
| - |
|
92 |
ticket.setL2AuthUser(l2Auth);
|
| - |
|
93 |
}
|
| - |
|
94 |
ticket.setL3AuthUser(l3Auth);
|
| - |
|
95 |
ticketRepository.persist(ticket);
|
| - |
|
96 |
AuthUser authUser = authRepository.selectById(ticket.getAssigneeId());
|
| 62 |
try {
|
97 |
try {
|
| - |
|
98 |
Utils.sendMailWithAttachments(mailSender, authUser.getEmailId(), null, ASSINMENT_SUBJECT,
|
| - |
|
99 |
String.format(ASSIGNED_TICKET, authUser.getFirstName(),
|
| 63 |
ticket.setAssigneeId(this.getAssigneeId(categoryId, escalationType));
|
100 |
retailerService.getFofoRetailer(fofoId).getBusinessName()),
|
| - |
|
101 |
null);
|
| 64 |
} catch (Exception e) {
|
102 |
} catch (Exception e) {
|
| - |
|
103 |
throw new ProfitMandiBusinessException("Ticket Assingment", authUser.getEmailId(),
|
| 65 |
e.printStackTrace();
|
104 |
"Could not send ticket assignment mail");
|
| 66 |
}
|
105 |
}
|
| 67 |
ticketRepository.persist(ticket);
|
- |
|
| 68 |
Activity activity = this.createActivity(type, message, 0);
|
106 |
Activity activity = this.createActivity(type, message, 0);
|
| 69 |
this.addActivity(ticket.getId(), activity);
|
107 |
this.addActivity(ticket.getId(), activity);
|
| 70 |
}
|
108 |
}
|
| 71 |
|
109 |
|
| 72 |
private Activity createActivity(ActivityType activityType, String message, int createdBy) {
|
110 |
private Activity createActivity(ActivityType activityType, String message, int createdBy) {
|
| Line 76... |
Line 114... |
| 76 |
activity.setType(activityType);
|
114 |
activity.setType(activityType);
|
| 77 |
activity.setCreateTimestamp(LocalDateTime.now());
|
115 |
activity.setCreateTimestamp(LocalDateTime.now());
|
| 78 |
return activity;
|
116 |
return activity;
|
| 79 |
}
|
117 |
}
|
| 80 |
|
118 |
|
| 81 |
private int getAssigneeId(int categoryId, EscalationType escalationType) throws ProfitMandiBusinessException {
|
119 |
private int getAuthUserId(int categoryId, EscalationType escalationType, int fofoId) {
|
| 82 |
|
120 |
|
| - |
|
121 |
List<Position> positions = null;
|
| - |
|
122 |
if (escalationType == EscalationType.L3) {
|
| - |
|
123 |
positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(0, escalationType, 0);
|
| - |
|
124 |
} else {
|
| - |
|
125 |
List<PartnerRegion> regions = partnerRegionRepository.selectByfofoId(fofoId);
|
| - |
|
126 |
LOGGER.info("regions=" + regions);
|
| - |
|
127 |
for (PartnerRegion region : regions) {
|
| 83 |
Position position = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId, escalationType);
|
128 |
positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId, escalationType,
|
| - |
|
129 |
region.getRegionId());
|
| - |
|
130 |
LOGGER.info("positions:-" + positions);
|
| - |
|
131 |
if (positions != null) {
|
| - |
|
132 |
break;
|
| - |
|
133 |
}
|
| - |
|
134 |
|
| - |
|
135 |
}
|
| - |
|
136 |
if (positions.size() == 0) {
|
| - |
|
137 |
return 0;
|
| - |
|
138 |
}
|
| - |
|
139 |
}
|
| 84 |
return position.getAuthUserId();
|
140 |
return positions.get(0).getAuthUserId();
|
| 85 |
/*
|
141 |
/*
|
| 86 |
* if(ActivityType.escalationTypes.contains(escalationType)) {
|
142 |
* if(ActivityType.escalationTypes.contains(escalationType)) {
|
| 87 |
* //escalationMatrix } else { throw new
|
143 |
* //escalationMatrix } else { throw new
|
| 88 |
* ProfitMandiBusinessException("SubCategory", subcategoryId,
|
144 |
* ProfitMandiBusinessException("SubCategory", subcategoryId,
|
| 89 |
* "Could not find Assignee for "); }
|
145 |
* "Could not find Assignee for "); }
|
| 90 |
*/
|
146 |
*/
|
| - |
|
147 |
|
| 91 |
}
|
148 |
}
|
| 92 |
|
149 |
|
| 93 |
@Override
|
150 |
@Override
|
| 94 |
public void addActivity(int ticketId, Activity activity) {
|
151 |
public void addActivity(int ticketId, Activity activity) {
|
| 95 |
activity.setTicketId(ticketId);
|
152 |
activity.setTicketId(ticketId);
|
| 96 |
activityRepository.persist(activity);
|
153 |
activityRepository.persist(activity);
|
| 97 |
}
|
154 |
}
|
| 98 |
|
155 |
|
| - |
|
156 |
private String getRandomString() {
|
| - |
|
157 |
int length = 4;
|
| - |
|
158 |
boolean useLetters = false;
|
| - |
|
159 |
boolean useNumbers = true;
|
| - |
|
160 |
String generatedString = RandomStringUtils.random(length, useLetters, useNumbers);
|
| - |
|
161 |
return generatedString;
|
| - |
|
162 |
}
|
| - |
|
163 |
|
| 99 |
@Override
|
164 |
@Override
|
| 100 |
public void addPartnerToRegion(int regionId, List<Integer> fofoIds) {
|
165 |
public void addPartnerToRegion(int regionId, List<Integer> fofoIds) {
|
| 101 |
|
166 |
|
| 102 |
for (Integer fofoId : fofoIds) {
|
167 |
for (Integer fofoId : fofoIds) {
|
| 103 |
PartnerRegion partnerRegion = partnerRepository.selectByRegionIdAndFofoId(regionId, fofoId);
|
168 |
PartnerRegion partnerRegion = partnerRegionRepository.selectByRegionIdAndFofoId(regionId, fofoId);
|
| 104 |
if (partnerRegion == null) {
|
169 |
if (partnerRegion == null) {
|
| 105 |
partnerRegion = new PartnerRegion();
|
170 |
partnerRegion = new PartnerRegion();
|
| 106 |
partnerRegion.setFofoId(fofoId);
|
171 |
partnerRegion.setFofoId(fofoId);
|
| 107 |
partnerRegion.setRegionId(regionId);
|
172 |
partnerRegion.setRegionId(regionId);
|
| 108 |
partnerRepository.persist(partnerRegion);
|
173 |
partnerRegionRepository.persist(partnerRegion);
|
| 109 |
} else {
|
174 |
} else {
|
| 110 |
continue;
|
175 |
continue;
|
| 111 |
}
|
176 |
}
|
| 112 |
}
|
177 |
}
|
| 113 |
}
|
178 |
}
|
| Line 137... |
Line 202... |
| 137 |
List<Integer> fofoIds = new ArrayList<>();
|
202 |
List<Integer> fofoIds = new ArrayList<>();
|
| 138 |
for (Ticket ticket : tickets) {
|
203 |
for (Ticket ticket : tickets) {
|
| 139 |
fofoIds.add(ticket.getFofoId());
|
204 |
fofoIds.add(ticket.getFofoId());
|
| 140 |
}
|
205 |
}
|
| 141 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService.getFofoRetailers(fofoIds);
|
206 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService.getFofoRetailers(fofoIds);
|
| 142 |
|
- |
|
| 143 |
return fofoIdsAndCustomRetailer;
|
207 |
return fofoIdsAndCustomRetailer;
|
| 144 |
}
|
208 |
}
|
| 145 |
|
209 |
|
| - |
|
210 |
@Override
|
| - |
|
211 |
public List<TicketCategory> getAllTicketCategotyFromSubCategory() {
|
| - |
|
212 |
|
| - |
|
213 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll();
|
| - |
|
214 |
HashSet<Integer> categoryIds = new HashSet<>();
|
| - |
|
215 |
for (TicketSubCategory ticketSubcategory : ticketSubCategories) {
|
| - |
|
216 |
categoryIds.add(ticketSubcategory.getcategoryId());
|
| - |
|
217 |
}
|
| - |
|
218 |
List<TicketCategory> ticketcategories = ticketCategoryRepository.selectAll(new ArrayList<>(categoryIds));
|
| - |
|
219 |
return ticketcategories;
|
| - |
|
220 |
}
|
| - |
|
221 |
|
| - |
|
222 |
private Ticket setAssignment(Ticket ticket) {
|
| - |
|
223 |
TicketCategory ticketCategory = ticketCategoryRepository.selectByName(ProfitMandiConstants.CRM);
|
| - |
|
224 |
List<Position> positions = positionRepository.selectPositionByCategoryId(ticketCategory.getId());
|
| - |
|
225 |
for (Position position : positions) {
|
| - |
|
226 |
if (position.getEscalationType().equals(EscalationType.L1)) {
|
| - |
|
227 |
ticket.setAssigneeId(position.getAuthUserId());
|
| - |
|
228 |
ticket.setL1AuthUser(position.getAuthUserId());
|
| - |
|
229 |
} else {
|
| - |
|
230 |
ticket.setL2AuthUser(position.getAuthUserId());
|
| - |
|
231 |
}
|
| - |
|
232 |
}
|
| - |
|
233 |
return ticket;
|
| - |
|
234 |
}
|
| - |
|
235 |
|
| 146 |
}
|
236 |
}
|