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