| 24417 |
govind |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
| 24572 |
amit.gupta |
4 |
import java.util.ArrayList;
|
| 24417 |
govind |
5 |
import java.util.HashSet;
|
|
|
6 |
import java.util.List;
|
|
|
7 |
import java.util.Map;
|
|
|
8 |
import java.util.Optional;
|
| 24572 |
amit.gupta |
9 |
import java.util.Set;
|
| 24500 |
govind |
10 |
import java.util.stream.Collectors;
|
| 24417 |
govind |
11 |
|
|
|
12 |
import javax.servlet.http.HttpServletRequest;
|
|
|
13 |
|
|
|
14 |
import org.apache.logging.log4j.LogManager;
|
|
|
15 |
import org.apache.logging.log4j.Logger;
|
|
|
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
17 |
import org.springframework.stereotype.Controller;
|
|
|
18 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
19 |
import org.springframework.ui.Model;
|
| 24471 |
govind |
20 |
import org.springframework.web.bind.annotation.DeleteMapping;
|
| 24417 |
govind |
21 |
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
22 |
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
23 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
24 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
25 |
|
|
|
26 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
27 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
|
|
28 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
|
|
29 |
import com.spice.profitmandi.dao.entity.cs.Activity;
|
|
|
30 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
|
|
31 |
import com.spice.profitmandi.dao.entity.cs.Region;
|
|
|
32 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
| 24500 |
govind |
33 |
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
|
| 24417 |
govind |
34 |
import com.spice.profitmandi.dao.entity.cs.TicketCategory;
|
|
|
35 |
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
|
|
|
36 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
|
|
37 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
|
|
38 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
39 |
import com.spice.profitmandi.dao.repository.cs.ActivityRepository;
|
|
|
40 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 24557 |
govind |
41 |
import com.spice.profitmandi.dao.repository.cs.PartnerRegionRepository;
|
| 24417 |
govind |
42 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
|
|
43 |
import com.spice.profitmandi.dao.repository.cs.RegionRepository;
|
| 24500 |
govind |
44 |
import com.spice.profitmandi.dao.repository.cs.TicketAssignedRepository;
|
| 24417 |
govind |
45 |
import com.spice.profitmandi.dao.repository.cs.TicketCategoryRepository;
|
|
|
46 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
|
|
47 |
import com.spice.profitmandi.dao.repository.cs.TicketSubCategoryRepository;
|
|
|
48 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
|
|
49 |
import com.spice.profitmandi.service.slab.TargetSlabService;
|
|
|
50 |
import com.spice.profitmandi.service.user.RetailerService;
|
|
|
51 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
52 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
53 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
54 |
|
|
|
55 |
@Controller
|
|
|
56 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
57 |
public class CsController {
|
|
|
58 |
|
|
|
59 |
private static final Logger LOGGER = LogManager.getLogger(CsController.class);
|
|
|
60 |
|
|
|
61 |
@Autowired
|
|
|
62 |
private CsService csService;
|
|
|
63 |
|
|
|
64 |
@Autowired
|
|
|
65 |
private CookiesProcessor cookiesProcessor;
|
|
|
66 |
|
|
|
67 |
@Autowired
|
|
|
68 |
private TicketCategoryRepository ticketCategoryRepository;
|
|
|
69 |
|
|
|
70 |
@Autowired
|
|
|
71 |
private TicketSubCategoryRepository ticketSubCategoryRepository;
|
|
|
72 |
|
|
|
73 |
@Autowired
|
|
|
74 |
private RegionRepository regionRepository;
|
|
|
75 |
|
|
|
76 |
@Autowired
|
|
|
77 |
private TargetSlabService targetSlabService;
|
|
|
78 |
|
|
|
79 |
@Autowired
|
|
|
80 |
private RetailerService retailerService;
|
|
|
81 |
|
|
|
82 |
@Autowired
|
|
|
83 |
private MVCResponseSender mvcResponseSender;
|
|
|
84 |
|
|
|
85 |
@Autowired
|
|
|
86 |
private AuthRepository authRepository;
|
|
|
87 |
|
|
|
88 |
@Autowired
|
|
|
89 |
private PositionRepository positionRepository;
|
|
|
90 |
|
|
|
91 |
@Autowired
|
|
|
92 |
private TicketRepository ticketRepository;
|
|
|
93 |
|
|
|
94 |
@Autowired
|
|
|
95 |
private RoleManager roleManager;
|
|
|
96 |
|
|
|
97 |
@Autowired
|
|
|
98 |
private ActivityRepository activityRepository;
|
|
|
99 |
|
| 24500 |
govind |
100 |
@Autowired
|
|
|
101 |
private TicketAssignedRepository ticketAssignedRepository;
|
| 24569 |
govind |
102 |
|
|
|
103 |
@Autowired
|
| 24557 |
govind |
104 |
private PartnerRegionRepository partnerRegionRepository;
|
| 24500 |
govind |
105 |
|
| 24417 |
govind |
106 |
@GetMapping(value = "/cs/createCategory")
|
|
|
107 |
public String getCreateCategory(HttpServletRequest request, Model model) {
|
|
|
108 |
List<TicketCategory> ticketCategories = ticketCategoryRepository.selectAll();
|
|
|
109 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
110 |
return "create-ticket-category";
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
@PostMapping(value = "/cs/createCategory")
|
|
|
114 |
public String createCategory(HttpServletRequest request, @RequestParam(name = "name") String name,
|
|
|
115 |
@RequestParam(name = "description") String description, Model model) throws ProfitMandiBusinessException {
|
|
|
116 |
|
|
|
117 |
TicketCategory ticketCategory = ticketCategoryRepository.selectByName(name);
|
|
|
118 |
if (ticketCategory != null) {
|
|
|
119 |
throw new ProfitMandiBusinessException("name", name, "already exists!");
|
|
|
120 |
}
|
|
|
121 |
ticketCategory = new TicketCategory();
|
|
|
122 |
ticketCategory.setName(name);
|
|
|
123 |
ticketCategory.setDescription(description);
|
|
|
124 |
ticketCategoryRepository.persist(ticketCategory);
|
|
|
125 |
return "create-ticket-category";
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
@GetMapping(value = "/cs/createSubCategory")
|
|
|
129 |
public String getCreateSubCategory(HttpServletRequest request, Model model) {
|
|
|
130 |
List<TicketCategory> ticketCategories = ticketCategoryRepository.selectAll();
|
|
|
131 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
132 |
return "create-ticket-sub-category";
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
@GetMapping(value = "/cs/getSubCategoryByCategoryId")
|
|
|
136 |
public String getSubCategoryByCategoryId(HttpServletRequest request,
|
|
|
137 |
@RequestParam(name = "ticketCategoryId", defaultValue = "") int ticketCategoryId, Model model) {
|
|
|
138 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll(ticketCategoryId);
|
|
|
139 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(ticketCategoryId);
|
|
|
140 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
|
|
141 |
model.addAttribute("ticketCategory", ticketCategory);
|
|
|
142 |
return "ticket-sub-category";
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
@PostMapping(value = "/cs/createSubCategory")
|
|
|
146 |
public String createSubCategory(HttpServletRequest request,
|
|
|
147 |
@RequestParam(name = "categoryId", defaultValue = "0") int categoryId,
|
|
|
148 |
@RequestParam(name = "name") String name, @RequestParam(name = "description") String description,
|
|
|
149 |
Model model) throws ProfitMandiBusinessException {
|
|
|
150 |
|
|
|
151 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectTicketSubCategory(categoryId, name);
|
|
|
152 |
if (ticketSubCategory != null) {
|
|
|
153 |
throw new ProfitMandiBusinessException("name & categoryId", name + " " + categoryId, "already exists!");
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
ticketSubCategory = new TicketSubCategory();
|
|
|
157 |
ticketSubCategory.setcategoryId(categoryId);
|
|
|
158 |
ticketSubCategory.setName(name);
|
|
|
159 |
ticketSubCategory.setDescription(description);
|
|
|
160 |
ticketSubCategoryRepository.persist(ticketSubCategory);
|
|
|
161 |
return "create-ticket-sub-category";
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
@GetMapping(value = "/cs/createRegion")
|
|
|
165 |
public String createRegion(HttpServletRequest request, Model model) {
|
|
|
166 |
List<Region> regions = regionRepository.selectAll();
|
|
|
167 |
model.addAttribute("regions", regions);
|
|
|
168 |
return "create-region";
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
@PostMapping(value = "/cs/createRegion")
|
|
|
172 |
public String createRegion(HttpServletRequest request, @RequestParam(name = "name") String name,
|
|
|
173 |
@RequestParam(name = "description") String description, Model model) throws Exception {
|
|
|
174 |
Region region = regionRepository.selectByName(name);
|
|
|
175 |
if (region != null) {
|
|
|
176 |
throw new ProfitMandiBusinessException("name", name, "already exists!");
|
|
|
177 |
}
|
|
|
178 |
region = new Region();
|
|
|
179 |
region.setName(name);
|
|
|
180 |
region.setDescription(description);
|
|
|
181 |
regionRepository.persist(region);
|
|
|
182 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
183 |
return "response";
|
|
|
184 |
}
|
|
|
185 |
|
| 24557 |
govind |
186 |
@GetMapping(value = "/cs/getPartners")
|
| 24569 |
govind |
187 |
public String getPartners(HttpServletRequest request,
|
|
|
188 |
@RequestParam(name = "regionId", defaultValue = "0") int regionId, Model model) {
|
| 24557 |
govind |
189 |
List<Integer> fofoIds = targetSlabService.getfofoIdsFromfofoStore();
|
| 24569 |
govind |
190 |
List<Integer> addedfofoIds = partnerRegionRepository.selectByRegionId(regionId).stream().map(x -> x.getFofoId())
|
|
|
191 |
.collect(Collectors.toList());
|
| 24557 |
govind |
192 |
Map<Integer, CustomRetailer> fofoRetailers = retailerService.getFofoRetailers(fofoIds);
|
|
|
193 |
model.addAttribute("fofoRetailers", fofoRetailers);
|
|
|
194 |
model.addAttribute("addedfofoIds", addedfofoIds);
|
|
|
195 |
return "added-region-partners";
|
|
|
196 |
}
|
| 24569 |
govind |
197 |
|
| 24417 |
govind |
198 |
@GetMapping(value = "/cs/createPartnerRegion")
|
|
|
199 |
public String createPartnerRegion(HttpServletRequest request, Model model) {
|
|
|
200 |
List<Region> regions = regionRepository.selectAll();
|
|
|
201 |
model.addAttribute("regions", regions);
|
|
|
202 |
return "create-partner-region";
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
@PostMapping(value = "/cs/createPartnerRegion")
|
|
|
206 |
public String createPartnerRegion(HttpServletRequest request, @RequestParam(name = "regionId") int regionId,
|
|
|
207 |
@RequestBody List<Integer> selectedFofoIds, Model model) throws Exception {
|
| 24557 |
govind |
208 |
partnerRegionRepository.delete(regionId);
|
|
|
209 |
LOGGER.info("successfully removed");
|
|
|
210 |
LOGGER.info(selectedFofoIds.size());
|
| 24417 |
govind |
211 |
csService.addPartnerToRegion(regionId, selectedFofoIds);
|
|
|
212 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
213 |
return "response";
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
@GetMapping(value = "/cs/createPosition")
|
| 24500 |
govind |
217 |
public String createPosition(HttpServletRequest request,
|
|
|
218 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 24471 |
govind |
219 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) {
|
| 24417 |
govind |
220 |
List<AuthUser> authUsers = authRepository.selectAll();
|
|
|
221 |
List<TicketCategory> ticketCategories = ticketCategoryRepository.selectAll();
|
|
|
222 |
List<Region> regions = regionRepository.selectAll();
|
|
|
223 |
model.addAttribute("escalationTypes", EscalationType.values());
|
|
|
224 |
model.addAttribute("authUsers", authUsers);
|
|
|
225 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
226 |
model.addAttribute("regions", regions);
|
| 24500 |
govind |
227 |
|
|
|
228 |
List<Position> positions = positionRepository.selectAll(offset, limit);
|
|
|
229 |
LOGGER.info(positions);
|
|
|
230 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = csService
|
|
|
231 |
.getAuthUserIdAndAuthUserMapUsingPositions(positions);
|
|
|
232 |
Map<Integer, TicketCategory> categoryIdAndCategoryMap = csService
|
|
|
233 |
.getCategoryIdAndCategoryUsingPositions(positions);
|
|
|
234 |
Map<Integer, Region> regionIdAndRegionMap = csService.getRegionIdAndRegionMap(positions);
|
|
|
235 |
long size = positionRepository.selectAllCount();
|
|
|
236 |
|
| 24471 |
govind |
237 |
if (size < limit) {
|
|
|
238 |
model.addAttribute("end", offset + size);
|
|
|
239 |
} else {
|
|
|
240 |
model.addAttribute("end", offset + limit);
|
|
|
241 |
}
|
|
|
242 |
model.addAttribute("start", offset + 1);
|
|
|
243 |
model.addAttribute("size", size);
|
|
|
244 |
model.addAttribute("positions", positions);
|
|
|
245 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
246 |
model.addAttribute("categoryIdAndCategoryMap", categoryIdAndCategoryMap);
|
|
|
247 |
model.addAttribute("regionIdAndRegionMap", regionIdAndRegionMap);
|
| 24417 |
govind |
248 |
return "create-position";
|
|
|
249 |
}
|
| 24500 |
govind |
250 |
|
| 24471 |
govind |
251 |
@GetMapping(value = "/cs/position-paginated")
|
| 24500 |
govind |
252 |
public String positionPaginated(HttpServletRequest request,
|
|
|
253 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 24471 |
govind |
254 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) {
|
| 24500 |
govind |
255 |
|
|
|
256 |
List<Position> positions = positionRepository.selectAll(offset, limit);
|
|
|
257 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = csService
|
|
|
258 |
.getAuthUserIdAndAuthUserMapUsingPositions(positions);
|
|
|
259 |
Map<Integer, TicketCategory> categoryIdAndCategoryMap = csService
|
|
|
260 |
.getCategoryIdAndCategoryUsingPositions(positions);
|
|
|
261 |
Map<Integer, Region> regionIdAndRegionMap = csService.getRegionIdAndRegionMap(positions);
|
| 24471 |
govind |
262 |
model.addAttribute("positions", positions);
|
|
|
263 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
264 |
model.addAttribute("categoryIdAndCategoryMap", categoryIdAndCategoryMap);
|
|
|
265 |
model.addAttribute("regionIdAndRegionMap", regionIdAndRegionMap);
|
|
|
266 |
return "position-paginated";
|
|
|
267 |
}
|
| 24417 |
govind |
268 |
|
|
|
269 |
@PostMapping(value = "/cs/createPosition")
|
|
|
270 |
public String createPosition(HttpServletRequest request, @RequestParam(name = "authUserId") int authUserId,
|
|
|
271 |
@RequestParam(name = "categoryId") int categoryId,
|
|
|
272 |
@RequestParam(name = "escalationType") EscalationType escalationType,
|
|
|
273 |
@RequestParam(name = "regionId") int regionId, Model model) throws Exception {
|
|
|
274 |
|
|
|
275 |
Position position = positionRepository.selectPosition(authUserId, categoryId, regionId, escalationType);
|
|
|
276 |
if (position == null) {
|
|
|
277 |
position = new Position();
|
|
|
278 |
position.setAuthUserId(authUserId);
|
|
|
279 |
position.setCategoryId(categoryId);
|
|
|
280 |
position.setEscalationType(escalationType);
|
|
|
281 |
position.setRegionId(regionId);
|
|
|
282 |
position.setCreateTimestamp(LocalDateTime.now());
|
|
|
283 |
positionRepository.persist(position);
|
|
|
284 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
285 |
} else {
|
|
|
286 |
throw new ProfitMandiBusinessException("Position", authUserId, "already exists!");
|
|
|
287 |
}
|
|
|
288 |
return "response";
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
@GetMapping(value = "/cs/createTicket")
|
|
|
292 |
public String createTicket(HttpServletRequest request, Model model) {
|
| 24500 |
govind |
293 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
| 24417 |
govind |
294 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
295 |
return "create-ticket";
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
@GetMapping(value = "/cs/getSubCategoriesByCategoryId")
|
|
|
299 |
public String getSubCategoriesByCategoryId(HttpServletRequest request,
|
|
|
300 |
@RequestParam(name = "categoryId", defaultValue = "0") int categoryId, Model model) {
|
|
|
301 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll(categoryId);
|
|
|
302 |
LOGGER.info(ticketSubCategories);
|
|
|
303 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
|
|
304 |
return "ticket-sub-categories";
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
@PostMapping(value = "/cs/createTicket")
|
|
|
308 |
public String createTicket(HttpServletRequest request, @RequestParam(name = "categoryId") int categoryId,
|
|
|
309 |
@RequestParam(name = "subCategoryId") int subCategoryId, @RequestParam(name = "message") String message,
|
|
|
310 |
Model model) throws Exception {
|
|
|
311 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
312 |
csService.createTicket(loginDetails.getFofoId(), categoryId, subCategoryId, message);
|
|
|
313 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
314 |
return "response";
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
@GetMapping(value = "/cs/myticket")
|
|
|
318 |
public String getMyTicket(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
319 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
320 |
throws ProfitMandiBusinessException {
|
|
|
321 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
322 |
List<Ticket> tickets = null;
|
| 24500 |
govind |
323 |
List<TicketAssigned> ticketAssigneds = null;
|
|
|
324 |
List<Integer> ticketIds = null;
|
| 24417 |
govind |
325 |
long size = 0;
|
| 24500 |
govind |
326 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = null;
|
|
|
327 |
// LOGGER.info(roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))));
|
| 24417 |
govind |
328 |
if (roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))) {
|
|
|
329 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 24500 |
govind |
330 |
ticketAssigneds = ticketAssignedRepository.selectByAssigneeId(authUser.getId(), offset, limit);
|
|
|
331 |
ticketIds = ticketAssigneds.stream().map(x -> x.getTicketId()).collect(Collectors.toList());
|
| 24543 |
tejbeer |
332 |
tickets = ticketRepository.selectAllByTicketIds(ticketIds);
|
| 24500 |
govind |
333 |
size = ticketAssignedRepository.selectCountByAssigneeId(authUser.getId());
|
| 24569 |
govind |
334 |
LOGGER.info(size +"size");
|
| 24500 |
govind |
335 |
authUserIdAndAuthUserMap = csService.getAuthUserIdAndAuthUserMap(ticketAssigneds);
|
| 24569 |
govind |
336 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
337 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
|
|
338 |
|
| 24417 |
govind |
339 |
} else {
|
|
|
340 |
tickets = ticketRepository.selectAllByCreator(loginDetails.getFofoId(), Optional.empty(), offset, limit);
|
| 24500 |
govind |
341 |
authUserIdAndAuthUserMap = csService.getTicketIdAndAuthUserMapUsingTickets(tickets);
|
|
|
342 |
size = ticketRepository.selectAllCountByCreator(loginDetails.getFofoId(), Optional.empty());
|
|
|
343 |
|
| 24417 |
govind |
344 |
}
|
|
|
345 |
if (size < limit) {
|
|
|
346 |
model.addAttribute("end", offset + size);
|
|
|
347 |
} else {
|
|
|
348 |
model.addAttribute("end", offset + limit);
|
|
|
349 |
}
|
|
|
350 |
model.addAttribute("start", offset + 1);
|
|
|
351 |
model.addAttribute("size", size);
|
| 24500 |
govind |
352 |
model.addAttribute("roleType", roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds())));
|
| 24417 |
govind |
353 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService
|
|
|
354 |
.getSubCategoryIdAndSubCategoryMap(tickets);
|
|
|
355 |
model.addAttribute("tickets", tickets);
|
|
|
356 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
357 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
|
|
358 |
return "ticket";
|
|
|
359 |
}
|
| 24500 |
govind |
360 |
|
| 24417 |
govind |
361 |
@GetMapping(value = "/cs/myticketPaginated")
|
| 24500 |
govind |
362 |
public String getMyTicketPaginated(HttpServletRequest request,
|
|
|
363 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 24417 |
govind |
364 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
365 |
throws ProfitMandiBusinessException {
|
|
|
366 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
367 |
List<Ticket> tickets = null;
|
| 24500 |
govind |
368 |
List<TicketAssigned> ticketAssigneds = null;
|
|
|
369 |
List<Integer> ticketIds = null;
|
|
|
370 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = null;
|
|
|
371 |
// LOGGER.info(roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))));
|
| 24417 |
govind |
372 |
if (roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))) {
|
|
|
373 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 24500 |
govind |
374 |
ticketAssigneds = ticketAssignedRepository.selectByAssigneeId(authUser.getId(), offset, limit);
|
| 24569 |
govind |
375 |
ticketIds = ticketAssigneds.stream().map(x -> x.getTicketId()).collect(Collectors.toList());
|
|
|
376 |
tickets = ticketRepository.selectAllByTicketIds(ticketIds);
|
|
|
377 |
authUserIdAndAuthUserMap = csService.getAuthUserIdAndAuthUserMap(ticketAssigneds);
|
|
|
378 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
379 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
| 24417 |
govind |
380 |
} else {
|
|
|
381 |
tickets = ticketRepository.selectAllByCreator(loginDetails.getFofoId(), Optional.empty(), offset, limit);
|
| 24500 |
govind |
382 |
authUserIdAndAuthUserMap = csService.getTicketIdAndAuthUserMapUsingTickets(tickets);
|
| 24417 |
govind |
383 |
}
|
| 24500 |
govind |
384 |
model.addAttribute("roleType", roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds())));
|
| 24417 |
govind |
385 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService
|
|
|
386 |
.getSubCategoryIdAndSubCategoryMap(tickets);
|
|
|
387 |
model.addAttribute("tickets", tickets);
|
|
|
388 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
389 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
|
|
390 |
return "ticket-paginated";
|
|
|
391 |
}
|
|
|
392 |
|
|
|
393 |
@GetMapping(value = "/cs/getActivities")
|
|
|
394 |
public String getActivity(HttpServletRequest request,
|
|
|
395 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) throws Exception {
|
|
|
396 |
List<Activity> activities = activityRepository.selectAll(ticketId);
|
| 24572 |
amit.gupta |
397 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
398 |
if(roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
399 |
Set<Integer> authUserIds = activities.stream().map(x->x.getCreatedBy()).collect(Collectors.toSet());
|
|
|
400 |
List<AuthUser> users = authRepository.selectAllAuthUserByIds(new ArrayList<>(authUserIds));
|
|
|
401 |
Map<Integer, String> authUserNameMap = users.stream().collect(Collectors.toMap(AuthUser::getId, x->x.getFirstName() + " "+ x.getLastName()));
|
|
|
402 |
activities.stream().forEach(x->x.setName(authUserNameMap.get(x.getCreatedBy())));
|
|
|
403 |
}
|
| 24417 |
govind |
404 |
if (activities == null) {
|
|
|
405 |
throw new ProfitMandiBusinessException("Activity", ticketId, "No Activity Found");
|
|
|
406 |
}
|
|
|
407 |
model.addAttribute("response", mvcResponseSender.createResponseString(activities));
|
|
|
408 |
return "response";
|
|
|
409 |
|
|
|
410 |
}
|
|
|
411 |
|
|
|
412 |
@PostMapping(value = "/cs/createActivity")
|
|
|
413 |
public String createActivity(HttpServletRequest request,
|
|
|
414 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId,
|
| 24500 |
govind |
415 |
@RequestParam(name = "assigneeId", defaultValue = "0") int assigneeId,
|
| 24417 |
govind |
416 |
@RequestParam(name = "message", defaultValue = "") String message, Model model) throws Exception {
|
|
|
417 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24500 |
govind |
418 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
419 |
if (ticket.getCloseTimestamp() == null) {
|
|
|
420 |
if (!roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))) {
|
|
|
421 |
Activity activity = new Activity();
|
|
|
422 |
activity.setMessage(message);
|
|
|
423 |
activity.setCreatedBy(0);
|
|
|
424 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
425 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
|
|
426 |
csService.addActivity(ticketId, activity);
|
|
|
427 |
AuthUser authUser = authRepository.selectById(assigneeId);
|
|
|
428 |
model.addAttribute("response", mvcResponseSender.createResponseString(authUser));
|
|
|
429 |
} else {
|
|
|
430 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
431 |
Activity activity = new Activity();
|
|
|
432 |
activity.setMessage(message);
|
|
|
433 |
activity.setCreatedBy(authUser.getId());
|
|
|
434 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
435 |
activity.setType(ActivityType.COMMUNICATION_OUT);
|
|
|
436 |
csService.addActivity(ticketId, activity);
|
|
|
437 |
model.addAttribute("response", mvcResponseSender.createResponseString(authUser));
|
|
|
438 |
}
|
| 24417 |
govind |
439 |
} else {
|
|
|
440 |
throw new ProfitMandiBusinessException("Ticket", ticket.getId(), "Already closed ticket");
|
|
|
441 |
}
|
|
|
442 |
return "response";
|
|
|
443 |
}
|
| 24500 |
govind |
444 |
|
|
|
445 |
@PostMapping(value = "/cs/closeTicket")
|
| 24417 |
govind |
446 |
public String closeTicket(HttpServletRequest request,
|
| 24439 |
govind |
447 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId,
|
| 24500 |
govind |
448 |
@RequestParam(name = "happyCode") String happyCode, Model model) throws Exception {
|
|
|
449 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
450 |
if (ticket.getHappyCode().equals(happyCode)) {
|
|
|
451 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
|
|
452 |
ticketRepository.persist(ticket);
|
|
|
453 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
454 |
} else {
|
|
|
455 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Happy Code can't match");
|
| 24439 |
govind |
456 |
}
|
| 24417 |
govind |
457 |
return "response";
|
|
|
458 |
}
|
| 24500 |
govind |
459 |
|
|
|
460 |
@GetMapping(value = "/cs/managerTicket")
|
|
|
461 |
public String getL2L3AndL4Tickets(HttpServletRequest request,
|
|
|
462 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
463 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
464 |
throws ProfitMandiBusinessException {
|
| 24439 |
govind |
465 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
466 |
long size = 0;
|
| 24500 |
govind |
467 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
468 |
List<Ticket> tickets = null;
|
| 24569 |
govind |
469 |
Map<Integer, List<AuthUser>> authUserListMap = null;
|
| 24500 |
govind |
470 |
if (loginDetails.getEmailId().equals("amandeep.singh@smartdukaan.com")) {
|
|
|
471 |
tickets = ticketRepository.selectAll(offset, limit, Optional.empty());
|
| 24570 |
govind |
472 |
authUserListMap = csService.getAuthUserList(tickets,authUser);
|
| 24500 |
govind |
473 |
size = ticketRepository.selectAllCount();
|
|
|
474 |
} else {
|
| 24570 |
govind |
475 |
tickets=ticketRepository.selectAllByEscalatedUserType(authUser.getId(), offset, limit);
|
|
|
476 |
authUserListMap = csService.getAuthUserList(tickets,authUser);
|
|
|
477 |
size=ticketRepository.selectAllCountByEscalatedUserType(authUser.getId());
|
|
|
478 |
if(tickets.size()>0)
|
|
|
479 |
{
|
|
|
480 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
481 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
| 24439 |
govind |
482 |
}
|
|
|
483 |
}
|
|
|
484 |
if (size < limit) {
|
|
|
485 |
model.addAttribute("end", offset + size);
|
|
|
486 |
} else {
|
|
|
487 |
model.addAttribute("end", offset + limit);
|
|
|
488 |
}
|
|
|
489 |
model.addAttribute("start", offset + 1);
|
|
|
490 |
model.addAttribute("size", size);
|
|
|
491 |
model.addAttribute("tickets", tickets);
|
| 24500 |
govind |
492 |
|
| 24439 |
govind |
493 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService
|
|
|
494 |
.getSubCategoryIdAndSubCategoryMap(tickets);
|
|
|
495 |
model.addAttribute("tickets", tickets);
|
| 24500 |
govind |
496 |
model.addAttribute("authUserListMap", authUserListMap);
|
| 24439 |
govind |
497 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
|
|
498 |
return "managerTicket";
|
|
|
499 |
}
|
| 24500 |
govind |
500 |
|
|
|
501 |
@GetMapping(value = "/cs/managerTicket-paginated")
|
|
|
502 |
public String getL2L3AndL4TicketsPaginated(HttpServletRequest request,
|
|
|
503 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
504 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
505 |
throws ProfitMandiBusinessException {
|
| 24467 |
govind |
506 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24500 |
govind |
507 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 24557 |
govind |
508 |
Map<Integer, List<AuthUser>> authUserListMap = null;
|
| 24500 |
govind |
509 |
List<Ticket> tickets = null;
|
|
|
510 |
if (loginDetails.getEmailId().equals("amandeep.singh@smartdukaan.com")) {
|
|
|
511 |
tickets = ticketRepository.selectAll(offset, limit, Optional.empty());
|
| 24570 |
govind |
512 |
authUserListMap = csService.getAuthUserList(tickets,authUser);
|
| 24500 |
govind |
513 |
} else {
|
| 24570 |
govind |
514 |
|
|
|
515 |
tickets=ticketRepository.selectAllByEscalatedUserType(authUser.getId(), offset, limit);
|
|
|
516 |
authUserListMap = csService.getAuthUserList(tickets,authUser);
|
| 24569 |
govind |
517 |
if(tickets.size()>0)
|
|
|
518 |
{
|
| 24500 |
govind |
519 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
| 24467 |
govind |
520 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
| 24569 |
govind |
521 |
}
|
| 24467 |
govind |
522 |
}
|
|
|
523 |
model.addAttribute("tickets", tickets);
|
|
|
524 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService
|
|
|
525 |
.getSubCategoryIdAndSubCategoryMap(tickets);
|
|
|
526 |
model.addAttribute("tickets", tickets);
|
| 24500 |
govind |
527 |
model.addAttribute("authUserListMap", authUserListMap);
|
| 24467 |
govind |
528 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
|
|
529 |
return "managerTicket-paginated";
|
|
|
530 |
}
|
| 24500 |
govind |
531 |
|
|
|
532 |
@GetMapping(value = "/cs/edit-ticket")
|
|
|
533 |
public String getEditTicket(HttpServletRequest request,
|
|
|
534 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) {
|
|
|
535 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
536 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
|
|
537 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
538 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository
|
|
|
539 |
.selectAll(ticketSubCategory.getcategoryId());
|
| 24569 |
govind |
540 |
List<AuthUser> authUsers = authRepository.selectAll();
|
| 24467 |
govind |
541 |
model.addAttribute("ticket", ticket);
|
|
|
542 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
543 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
| 24575 |
govind |
544 |
model.addAttribute("ticketSubCategory", ticketSubCategory);
|
| 24500 |
govind |
545 |
model.addAttribute("authUsers", authUsers);
|
| 24467 |
govind |
546 |
return "edit-ticket-modal";
|
|
|
547 |
}
|
| 24500 |
govind |
548 |
|
|
|
549 |
@PostMapping(value = "/cs/edit-ticket")
|
|
|
550 |
public String editTicket(HttpServletRequest request,
|
|
|
551 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId,
|
|
|
552 |
@RequestParam(name = "subCategoryId", defaultValue = "0") int subCategoryId,
|
|
|
553 |
@RequestParam(name = "categoryId", defaultValue = "0") int categoryId,
|
|
|
554 |
@RequestParam(name = "authUserId", defaultValue = "0") int authUserId, Model model) throws Exception {
|
| 24467 |
govind |
555 |
LOGGER.info(ticketId);
|
| 24500 |
govind |
556 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
| 24569 |
govind |
557 |
ticketAssignedRepository.deleteByTicketId(ticketId);
|
|
|
558 |
if (ticket.getSubCategoryId() == subCategoryId) {
|
|
|
559 |
LOGGER.info(ticket);
|
|
|
560 |
TicketAssigned ticketAssigned = new TicketAssigned();
|
| 24500 |
govind |
561 |
ticketAssigned.setTicketId(ticketId);
|
|
|
562 |
ticketAssigned.setAssineeId(authUserId);
|
|
|
563 |
ticketAssignedRepository.persist(ticketAssigned);
|
| 24569 |
govind |
564 |
ticket.setL1AuthUser(authUserId);
|
|
|
565 |
ticket.setSubCategoryId(subCategoryId);
|
|
|
566 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
567 |
ticket.setL2EscalationTimestamp(ticket.getUpdateTimestamp().plusDays(2));
|
|
|
568 |
ticket.setL3EscalationTimestamp(ticket.getL2EscalationTimestamp().plusDays(2));
|
|
|
569 |
ticket.setLastEscalationTimestamp(ticket.getL3EscalationTimestamp().plusDays(2));
|
|
|
570 |
ticketRepository.persist(ticket);
|
|
|
571 |
csService.sendAssignedTicketMail(authRepository.selectById(authUserId), ticket);
|
| 24500 |
govind |
572 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 24569 |
govind |
573 |
} else {
|
|
|
574 |
csService.updateTicket(categoryId, subCategoryId, ticket);
|
|
|
575 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 24500 |
govind |
576 |
}
|
| 24467 |
govind |
577 |
return "response";
|
|
|
578 |
}
|
| 24500 |
govind |
579 |
|
|
|
580 |
@DeleteMapping(value = "/cs/removePosition")
|
|
|
581 |
public String removePosition(HttpServletRequest request,
|
|
|
582 |
@RequestParam(name = "positionId", defaultValue = "0") int positionId, Model model) throws Exception {
|
| 24471 |
govind |
583 |
positionRepository.delete(positionId);
|
|
|
584 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
585 |
return "response";
|
|
|
586 |
}
|
| 24417 |
govind |
587 |
}
|