| 24417 |
govind |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
4 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 24620 |
govind |
5 |
import com.spice.profitmandi.common.util.Utils;
|
| 24417 |
govind |
6 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 27690 |
amit.gupta |
7 |
import com.spice.profitmandi.dao.entity.cs.*;
|
| 27270 |
tejbeer |
8 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
| 24417 |
govind |
9 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
|
|
10 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 24699 |
govind |
11 |
import com.spice.profitmandi.dao.enumuration.cs.TicketStatus;
|
| 25570 |
tejbeer |
12 |
import com.spice.profitmandi.dao.model.CreatePositionModel;
|
| 24417 |
govind |
13 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 27690 |
amit.gupta |
14 |
import com.spice.profitmandi.dao.repository.cs.*;
|
| 27270 |
tejbeer |
15 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| 25570 |
tejbeer |
16 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24417 |
govind |
17 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
|
|
18 |
import com.spice.profitmandi.service.user.RetailerService;
|
|
|
19 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
20 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
21 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 27690 |
amit.gupta |
22 |
import org.apache.logging.log4j.LogManager;
|
|
|
23 |
import org.apache.logging.log4j.Logger;
|
|
|
24 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
25 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
26 |
import org.springframework.stereotype.Controller;
|
|
|
27 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
28 |
import org.springframework.ui.Model;
|
|
|
29 |
import org.springframework.web.bind.annotation.*;
|
| 24417 |
govind |
30 |
|
| 27690 |
amit.gupta |
31 |
import javax.servlet.http.HttpServletRequest;
|
|
|
32 |
import javax.swing.*;
|
|
|
33 |
import java.time.LocalDateTime;
|
|
|
34 |
import java.util.*;
|
|
|
35 |
import java.util.stream.Collectors;
|
|
|
36 |
|
| 24417 |
govind |
37 |
@Controller
|
|
|
38 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
39 |
public class CsController {
|
|
|
40 |
|
|
|
41 |
private static final Logger LOGGER = LogManager.getLogger(CsController.class);
|
| 24620 |
govind |
42 |
private static final String ACTIVITY_SUBJECT = "Message related ticketId#%s";
|
| 24699 |
govind |
43 |
private static final String PARTNER_RESOLVED_TICKET_MAIL = "Dear Partner , we have resolved your ticket # %s , request to kindly accept the same. In case you still have any concerns regarding the same pls click on %s so that we can help you.Regards\nSmartdukaan";
|
|
|
44 |
private static final String PARTNER_REOPEN = "Dear Partner , Your ticket # %s has been re-opened as per your confirmation & we are committed to resolve it on priority.Regards\nSmartdukaan";
|
| 27205 |
amit.gupta |
45 |
private static final String INTERNAL_REOPEN_MAIL = "Team, Pls note that the Ticket Id %s has been re-opened by %s , pls respond on priority";
|
|
|
46 |
private static final String INTERNAL_REOPEN_ACTIVITY_MESSAGE = "Hi,My ticket is not resolved yet,so I have reopened it";
|
| 24699 |
govind |
47 |
|
| 24417 |
govind |
48 |
@Autowired
|
| 24620 |
govind |
49 |
JavaMailSender mailSender;
|
|
|
50 |
|
|
|
51 |
@Autowired
|
| 24417 |
govind |
52 |
private CsService csService;
|
|
|
53 |
|
|
|
54 |
@Autowired
|
|
|
55 |
private CookiesProcessor cookiesProcessor;
|
|
|
56 |
|
|
|
57 |
@Autowired
|
|
|
58 |
private TicketCategoryRepository ticketCategoryRepository;
|
|
|
59 |
|
|
|
60 |
@Autowired
|
|
|
61 |
private TicketSubCategoryRepository ticketSubCategoryRepository;
|
|
|
62 |
|
|
|
63 |
@Autowired
|
|
|
64 |
private RegionRepository regionRepository;
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
@Autowired
|
|
|
68 |
private RetailerService retailerService;
|
|
|
69 |
|
|
|
70 |
@Autowired
|
|
|
71 |
private MVCResponseSender mvcResponseSender;
|
|
|
72 |
|
|
|
73 |
@Autowired
|
|
|
74 |
private AuthRepository authRepository;
|
|
|
75 |
|
|
|
76 |
@Autowired
|
|
|
77 |
private PositionRepository positionRepository;
|
|
|
78 |
|
|
|
79 |
@Autowired
|
|
|
80 |
private TicketRepository ticketRepository;
|
|
|
81 |
|
|
|
82 |
@Autowired
|
|
|
83 |
private RoleManager roleManager;
|
|
|
84 |
|
|
|
85 |
@Autowired
|
|
|
86 |
private ActivityRepository activityRepository;
|
|
|
87 |
|
| 24500 |
govind |
88 |
@Autowired
|
| 27270 |
tejbeer |
89 |
private ActivityAttachmentRepository activityAttachmentRepository;
|
|
|
90 |
|
|
|
91 |
@Autowired
|
| 24500 |
govind |
92 |
private TicketAssignedRepository ticketAssignedRepository;
|
| 24569 |
govind |
93 |
|
|
|
94 |
@Autowired
|
| 24557 |
govind |
95 |
private PartnerRegionRepository partnerRegionRepository;
|
| 24500 |
govind |
96 |
|
| 25570 |
tejbeer |
97 |
@Autowired
|
|
|
98 |
PartnersPositionRepository partnersPositionRepository;
|
|
|
99 |
|
|
|
100 |
@Autowired
|
|
|
101 |
FofoStoreRepository fofoStoreRepository;
|
|
|
102 |
|
| 27270 |
tejbeer |
103 |
@Autowired
|
|
|
104 |
DocumentRepository documentRepository;
|
|
|
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();
|
| 27124 |
amit.gupta |
157 |
ticketSubCategory.setCategoryId(categoryId);
|
| 24417 |
govind |
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) {
|
| 27690 |
amit.gupta |
189 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x->x.getId()).collect(Collectors.toList());
|
| 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 |
|
| 25570 |
tejbeer |
198 |
@GetMapping(value = "/cs/getPartnersByRegion")
|
|
|
199 |
public String getPartnersByRegion(HttpServletRequest request,
|
|
|
200 |
@RequestParam(name = "regionId", defaultValue = "0") int regionId, Model model) {
|
|
|
201 |
List<Integer> fofoIds = null;
|
|
|
202 |
fofoIds = partnerRegionRepository.selectByRegionId(regionId).stream().map(x -> x.getFofoId())
|
|
|
203 |
.collect(Collectors.toList());
|
|
|
204 |
|
|
|
205 |
if (fofoIds.contains(0)) {
|
|
|
206 |
fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).collect(Collectors.toList())
|
|
|
207 |
.stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
208 |
|
|
|
209 |
}
|
|
|
210 |
Map<Integer, CustomRetailer> fofoRetailers = retailerService.getFofoRetailers(fofoIds);
|
|
|
211 |
|
|
|
212 |
model.addAttribute("fofoRetailers", fofoRetailers);
|
|
|
213 |
return "added-subregion-partners";
|
|
|
214 |
}
|
|
|
215 |
|
| 24417 |
govind |
216 |
@GetMapping(value = "/cs/createPartnerRegion")
|
|
|
217 |
public String createPartnerRegion(HttpServletRequest request, Model model) {
|
|
|
218 |
List<Region> regions = regionRepository.selectAll();
|
|
|
219 |
model.addAttribute("regions", regions);
|
|
|
220 |
return "create-partner-region";
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
@PostMapping(value = "/cs/createPartnerRegion")
|
|
|
224 |
public String createPartnerRegion(HttpServletRequest request, @RequestParam(name = "regionId") int regionId,
|
|
|
225 |
@RequestBody List<Integer> selectedFofoIds, Model model) throws Exception {
|
| 24557 |
govind |
226 |
partnerRegionRepository.delete(regionId);
|
|
|
227 |
LOGGER.info("successfully removed");
|
|
|
228 |
LOGGER.info(selectedFofoIds.size());
|
| 24417 |
govind |
229 |
csService.addPartnerToRegion(regionId, selectedFofoIds);
|
|
|
230 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
231 |
return "response";
|
|
|
232 |
}
|
|
|
233 |
|
| 27410 |
tejbeer |
234 |
@GetMapping(value = "/cs/getPosition")
|
|
|
235 |
public String getPosition(HttpServletRequest request, @RequestParam int positionId, Model model) {
|
|
|
236 |
|
|
|
237 |
Position position = positionRepository.selectById(positionId);
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
List<CustomRetailer> positionIdCustomRetailer = csService.getPositionCustomRetailerMap(Arrays.asList(position))
|
|
|
241 |
.get(position.getId());
|
|
|
242 |
|
|
|
243 |
Map<Integer, CustomRetailer> regionRetailerMap = csService.getRegionPartners(Arrays.asList(position))
|
|
|
244 |
.get(position.getRegionId()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
model.addAttribute("position", position);
|
|
|
248 |
model.addAttribute("regionRetailerMap", regionRetailerMap);
|
|
|
249 |
model.addAttribute("positionIdCustomRetailer", positionIdCustomRetailer);
|
|
|
250 |
|
|
|
251 |
|
|
|
252 |
return "position-partner";
|
|
|
253 |
}
|
|
|
254 |
|
| 24417 |
govind |
255 |
@GetMapping(value = "/cs/createPosition")
|
| 24500 |
govind |
256 |
public String createPosition(HttpServletRequest request,
|
|
|
257 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 24471 |
govind |
258 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) {
|
| 25570 |
tejbeer |
259 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 24417 |
govind |
260 |
List<TicketCategory> ticketCategories = ticketCategoryRepository.selectAll();
|
|
|
261 |
List<Region> regions = regionRepository.selectAll();
|
|
|
262 |
model.addAttribute("escalationTypes", EscalationType.values());
|
|
|
263 |
model.addAttribute("authUsers", authUsers);
|
|
|
264 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
265 |
model.addAttribute("regions", regions);
|
| 24500 |
govind |
266 |
|
|
|
267 |
List<Position> positions = positionRepository.selectAll(offset, limit);
|
|
|
268 |
LOGGER.info(positions);
|
|
|
269 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = csService
|
|
|
270 |
.getAuthUserIdAndAuthUserMapUsingPositions(positions);
|
|
|
271 |
Map<Integer, TicketCategory> categoryIdAndCategoryMap = csService
|
|
|
272 |
.getCategoryIdAndCategoryUsingPositions(positions);
|
|
|
273 |
Map<Integer, Region> regionIdAndRegionMap = csService.getRegionIdAndRegionMap(positions);
|
| 25570 |
tejbeer |
274 |
|
| 27410 |
tejbeer |
275 |
// Map<Integer, List<CustomRetailer>> positionIdAndpartnerRegionMap = csService
|
|
|
276 |
// .getpositionIdAndpartnerRegionMap(positions);
|
| 25570 |
tejbeer |
277 |
|
| 27410 |
tejbeer |
278 |
// Map<Integer, List<CustomRetailer>> addedpositionIdAndCustomRetailerMap = csService
|
|
|
279 |
// .getPositionCustomRetailerMap(positions);
|
|
|
280 |
// LOGGER.info("fofoIdAndCustomRetailerMap" + addedpositionIdAndCustomRetailerMap);
|
| 24500 |
govind |
281 |
long size = positionRepository.selectAllCount();
|
|
|
282 |
|
| 24471 |
govind |
283 |
if (size < limit) {
|
|
|
284 |
model.addAttribute("end", offset + size);
|
|
|
285 |
} else {
|
|
|
286 |
model.addAttribute("end", offset + limit);
|
|
|
287 |
}
|
| 25570 |
tejbeer |
288 |
|
| 24471 |
govind |
289 |
model.addAttribute("start", offset + 1);
|
|
|
290 |
model.addAttribute("size", size);
|
|
|
291 |
model.addAttribute("positions", positions);
|
|
|
292 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
293 |
model.addAttribute("categoryIdAndCategoryMap", categoryIdAndCategoryMap);
|
|
|
294 |
model.addAttribute("regionIdAndRegionMap", regionIdAndRegionMap);
|
| 27410 |
tejbeer |
295 |
// model.addAttribute("positionIdAndCustomRetailerMap",
|
|
|
296 |
// addedpositionIdAndCustomRetailerMap);
|
|
|
297 |
// model.addAttribute("positionIdAndpartnerRegionMap",
|
|
|
298 |
// positionIdAndpartnerRegionMap);
|
| 25570 |
tejbeer |
299 |
|
| 24417 |
govind |
300 |
return "create-position";
|
|
|
301 |
}
|
| 24500 |
govind |
302 |
|
| 24471 |
govind |
303 |
@GetMapping(value = "/cs/position-paginated")
|
| 24500 |
govind |
304 |
public String positionPaginated(HttpServletRequest request,
|
|
|
305 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 24471 |
govind |
306 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) {
|
| 24500 |
govind |
307 |
|
|
|
308 |
List<Position> positions = positionRepository.selectAll(offset, limit);
|
|
|
309 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = csService
|
|
|
310 |
.getAuthUserIdAndAuthUserMapUsingPositions(positions);
|
|
|
311 |
Map<Integer, TicketCategory> categoryIdAndCategoryMap = csService
|
|
|
312 |
.getCategoryIdAndCategoryUsingPositions(positions);
|
|
|
313 |
Map<Integer, Region> regionIdAndRegionMap = csService.getRegionIdAndRegionMap(positions);
|
| 27410 |
tejbeer |
314 |
/*
|
|
|
315 |
* Map<Integer, List<CustomRetailer>> positionIdAndpartnerRegionMap = csService
|
|
|
316 |
* .getpositionIdAndpartnerRegionMap(positions);
|
|
|
317 |
*
|
|
|
318 |
* Map<Integer, List<CustomRetailer>> addedpositionIdAndCustomRetailerMap =
|
|
|
319 |
* csService .getPositionCustomRetailerMap(positions);
|
|
|
320 |
*/
|
| 25570 |
tejbeer |
321 |
|
| 24471 |
govind |
322 |
model.addAttribute("positions", positions);
|
|
|
323 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
324 |
model.addAttribute("categoryIdAndCategoryMap", categoryIdAndCategoryMap);
|
|
|
325 |
model.addAttribute("regionIdAndRegionMap", regionIdAndRegionMap);
|
| 27410 |
tejbeer |
326 |
// model.addAttribute("positionIdAndCustomRetailerMap",
|
|
|
327 |
// addedpositionIdAndCustomRetailerMap);
|
|
|
328 |
// model.addAttribute("positionIdAndpartnerRegionMap",
|
|
|
329 |
// positionIdAndpartnerRegionMap);
|
| 25570 |
tejbeer |
330 |
|
| 24471 |
govind |
331 |
return "position-paginated";
|
|
|
332 |
}
|
| 24417 |
govind |
333 |
|
|
|
334 |
@PostMapping(value = "/cs/createPosition")
|
| 25570 |
tejbeer |
335 |
public String createPosition(HttpServletRequest request, @RequestBody CreatePositionModel createPositionModel,
|
|
|
336 |
Model model) throws Exception {
|
| 24417 |
govind |
337 |
|
| 25570 |
tejbeer |
338 |
Position position = positionRepository.selectPosition(createPositionModel.getAuthUserId(),
|
|
|
339 |
createPositionModel.getCategoryId(), createPositionModel.getRegionId(),
|
|
|
340 |
createPositionModel.getEscalationType());
|
| 24417 |
govind |
341 |
if (position == null) {
|
|
|
342 |
position = new Position();
|
| 25570 |
tejbeer |
343 |
position.setAuthUserId(createPositionModel.getAuthUserId());
|
|
|
344 |
position.setCategoryId(createPositionModel.getCategoryId());
|
|
|
345 |
position.setEscalationType(createPositionModel.getEscalationType());
|
|
|
346 |
position.setRegionId(createPositionModel.getRegionId());
|
| 24417 |
govind |
347 |
position.setCreateTimestamp(LocalDateTime.now());
|
|
|
348 |
positionRepository.persist(position);
|
| 25570 |
tejbeer |
349 |
|
|
|
350 |
for (int fofoId : createPositionModel.getFofoIds()) {
|
|
|
351 |
|
|
|
352 |
PartnerPosition partnerPosition = new PartnerPosition();
|
|
|
353 |
partnerPosition.setFofoId(fofoId);
|
|
|
354 |
partnerPosition.setRegionId(createPositionModel.getRegionId());
|
|
|
355 |
partnerPosition.setPositionId(position.getId());
|
|
|
356 |
partnersPositionRepository.persist(partnerPosition);
|
|
|
357 |
LOGGER.info("partnerPosition" + partnerPosition);
|
|
|
358 |
}
|
|
|
359 |
|
| 24417 |
govind |
360 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
361 |
} else {
|
| 25570 |
tejbeer |
362 |
throw new ProfitMandiBusinessException("Position", createPositionModel.getAuthUserId(), "already exists!");
|
| 24417 |
govind |
363 |
}
|
|
|
364 |
return "response";
|
|
|
365 |
}
|
|
|
366 |
|
| 25570 |
tejbeer |
367 |
@PostMapping(value = "/cs/updatePartnerPosition")
|
|
|
368 |
public String updatePartnerPosition(HttpServletRequest request, @RequestParam(name = "regionId") int regionId,
|
|
|
369 |
@RequestBody List<Integer> selectedFofoIds, @RequestParam(name = "positionId") int positionId, Model model)
|
|
|
370 |
throws Exception {
|
|
|
371 |
|
|
|
372 |
partnersPositionRepository.delete(positionId);
|
|
|
373 |
for (int fofoId : selectedFofoIds) {
|
|
|
374 |
PartnerPosition partnerPosition = new PartnerPosition();
|
|
|
375 |
partnerPosition.setFofoId(fofoId);
|
|
|
376 |
partnerPosition.setRegionId(regionId);
|
|
|
377 |
partnerPosition.setPositionId(positionId);
|
|
|
378 |
partnersPositionRepository.persist(partnerPosition);
|
|
|
379 |
}
|
|
|
380 |
|
|
|
381 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
382 |
|
|
|
383 |
return "response";
|
|
|
384 |
}
|
|
|
385 |
|
| 24417 |
govind |
386 |
@GetMapping(value = "/cs/createTicket")
|
| 24824 |
govind |
387 |
public String createTicket(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
388 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24500 |
govind |
389 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
| 24824 |
govind |
390 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 24417 |
govind |
391 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
392 |
return "create-ticket";
|
|
|
393 |
}
|
|
|
394 |
|
|
|
395 |
@GetMapping(value = "/cs/getSubCategoriesByCategoryId")
|
|
|
396 |
public String getSubCategoriesByCategoryId(HttpServletRequest request,
|
|
|
397 |
@RequestParam(name = "categoryId", defaultValue = "0") int categoryId, Model model) {
|
|
|
398 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll(categoryId);
|
|
|
399 |
LOGGER.info(ticketSubCategories);
|
|
|
400 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
|
|
401 |
return "ticket-sub-categories";
|
|
|
402 |
}
|
|
|
403 |
|
|
|
404 |
@PostMapping(value = "/cs/createTicket")
|
|
|
405 |
public String createTicket(HttpServletRequest request, @RequestParam(name = "categoryId") int categoryId,
|
|
|
406 |
@RequestParam(name = "subCategoryId") int subCategoryId, @RequestParam(name = "message") String message,
|
|
|
407 |
Model model) throws Exception {
|
|
|
408 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24837 |
govind |
409 |
List<Ticket> tickets = ticketRepository.selectAllResolvedMarkedTicketByCreator(loginDetails.getFofoId());
|
| 24620 |
govind |
410 |
if (tickets.size() > 3 || tickets.size() == 3) {
|
|
|
411 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
412 |
} else {
|
|
|
413 |
csService.createTicket(loginDetails.getFofoId(), categoryId, subCategoryId, message);
|
|
|
414 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
415 |
}
|
| 24417 |
govind |
416 |
return "response";
|
|
|
417 |
}
|
|
|
418 |
|
|
|
419 |
@GetMapping(value = "/cs/myticket")
|
| 24699 |
govind |
420 |
public String getTicket(HttpServletRequest request,
|
|
|
421 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
422 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
| 24787 |
govind |
423 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
424 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
| 24699 |
govind |
425 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 24417 |
govind |
426 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
427 |
throws ProfitMandiBusinessException {
|
|
|
428 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
429 |
List<Ticket> tickets = null;
|
| 24500 |
govind |
430 |
List<TicketAssigned> ticketAssigneds = null;
|
| 24417 |
govind |
431 |
long size = 0;
|
| 24500 |
govind |
432 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = null;
|
| 24417 |
govind |
433 |
if (roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))) {
|
|
|
434 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 24787 |
govind |
435 |
if (ticketSearchType == null) {
|
| 24791 |
govind |
436 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
437 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(), Optional.empty(), sortOrder, null,
|
|
|
438 |
searchTerm, offset, limit);
|
|
|
439 |
size = ticketRepository.selectAllCountByAssignee(authUser.getId(), Optional.empty(), null,
|
|
|
440 |
searchTerm);
|
|
|
441 |
} else {
|
| 24787 |
govind |
442 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(),
|
| 27124 |
amit.gupta |
443 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), sortOrder, null, searchTerm, offset,
|
| 24787 |
govind |
444 |
limit);
|
|
|
445 |
size = ticketRepository.selectAllCountByAssignee(authUser.getId(),
|
| 27124 |
amit.gupta |
446 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), null, searchTerm);
|
| 24791 |
govind |
447 |
}
|
|
|
448 |
|
| 24787 |
govind |
449 |
} else {
|
| 24791 |
govind |
450 |
|
|
|
451 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
452 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(), Optional.empty(), sortOrder,
|
|
|
453 |
ticketSearchType, searchTerm, offset, limit);
|
|
|
454 |
size = ticketRepository.selectAllCountByAssignee(authUser.getId(), Optional.empty(),
|
|
|
455 |
ticketSearchType, searchTerm);
|
|
|
456 |
} else {
|
| 24787 |
govind |
457 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(),
|
| 27124 |
amit.gupta |
458 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), sortOrder, ticketSearchType,
|
| 24787 |
govind |
459 |
searchTerm, offset, limit);
|
|
|
460 |
size = ticketRepository.selectAllCountByAssignee(authUser.getId(),
|
| 27124 |
amit.gupta |
461 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), ticketSearchType, searchTerm);
|
| 24791 |
govind |
462 |
}
|
| 24787 |
govind |
463 |
}
|
| 24824 |
govind |
464 |
// LOGGER.info(size + "size");
|
| 24791 |
govind |
465 |
if (tickets.size() > 0) {
|
|
|
466 |
ticketAssigneds = ticketAssignedRepository
|
|
|
467 |
.selectByTicketIds(tickets.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
|
|
468 |
authUserIdAndAuthUserMap = csService.getAuthUserIdAndAuthUserMap(ticketAssigneds);
|
|
|
469 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
470 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
| 24787 |
govind |
471 |
}
|
| 24620 |
govind |
472 |
|
| 24417 |
govind |
473 |
} else {
|
| 24699 |
govind |
474 |
tickets = ticketRepository.selectAllByCreator(loginDetails.getFofoId(),
|
| 24751 |
govind |
475 |
Optional.of(TicketStatus.OPENED.equals(ticketStatus)), sortOrder, offset, limit);
|
| 24699 |
govind |
476 |
size = ticketRepository.selectAllCountByCreator(loginDetails.getFofoId(),
|
| 24751 |
govind |
477 |
Optional.of(TicketStatus.OPENED.equals(ticketStatus)));
|
| 24699 |
govind |
478 |
}
|
|
|
479 |
authUserIdAndAuthUserMap = csService.getTicketIdAndAuthUserMapUsingTickets(tickets);
|
| 24500 |
govind |
480 |
|
| 24417 |
govind |
481 |
if (size < limit) {
|
|
|
482 |
model.addAttribute("end", offset + size);
|
|
|
483 |
} else {
|
|
|
484 |
model.addAttribute("end", offset + limit);
|
|
|
485 |
}
|
|
|
486 |
model.addAttribute("start", offset + 1);
|
|
|
487 |
model.addAttribute("size", size);
|
| 24500 |
govind |
488 |
model.addAttribute("roleType", roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds())));
|
| 24417 |
govind |
489 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService
|
|
|
490 |
.getSubCategoryIdAndSubCategoryMap(tickets);
|
|
|
491 |
model.addAttribute("tickets", tickets);
|
| 24620 |
govind |
492 |
model.addAttribute("resolved", ActivityType.RESOLVED);
|
|
|
493 |
model.addAttribute("resolved-accepted", ActivityType.RESOLVED_ACCEPTED);
|
|
|
494 |
model.addAttribute("resolved-rejected", ActivityType.RESOLVED_REJECTED);
|
| 24417 |
govind |
495 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
496 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
| 24699 |
govind |
497 |
model.addAttribute("ticketStatusValues", TicketStatus.values());
|
|
|
498 |
model.addAttribute("orderByValues", SortOrder.values());
|
|
|
499 |
model.addAttribute("selectedticketStatus", ticketStatus);
|
|
|
500 |
model.addAttribute("selectedorderby", sortOrder);
|
| 24787 |
govind |
501 |
model.addAttribute("ticketSearchTypes", TicketSearchType.values());
|
|
|
502 |
model.addAttribute("ticketSearchType", ticketSearchType);
|
|
|
503 |
model.addAttribute("searchTerm", searchTerm);
|
| 24417 |
govind |
504 |
return "ticket";
|
|
|
505 |
}
|
| 24500 |
govind |
506 |
|
| 24417 |
govind |
507 |
@GetMapping(value = "/cs/myticketPaginated")
|
| 24500 |
govind |
508 |
public String getMyTicketPaginated(HttpServletRequest request,
|
| 24699 |
govind |
509 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
510 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
| 24787 |
govind |
511 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
512 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
| 24500 |
govind |
513 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 24417 |
govind |
514 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
515 |
throws ProfitMandiBusinessException {
|
|
|
516 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
517 |
List<Ticket> tickets = null;
|
| 24500 |
govind |
518 |
List<TicketAssigned> ticketAssigneds = null;
|
| 24824 |
govind |
519 |
|
| 24500 |
govind |
520 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = null;
|
| 24824 |
govind |
521 |
|
| 24417 |
govind |
522 |
if (roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))) {
|
|
|
523 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 24791 |
govind |
524 |
if (ticketSearchType == null) {
|
|
|
525 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
526 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(), Optional.empty(), sortOrder, null,
|
|
|
527 |
searchTerm, offset, limit);
|
|
|
528 |
} else {
|
|
|
529 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(),
|
| 27195 |
amit.gupta |
530 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), sortOrder, null, searchTerm, offset,
|
| 24791 |
govind |
531 |
limit);
|
|
|
532 |
}
|
| 24787 |
govind |
533 |
|
|
|
534 |
} else {
|
| 24791 |
govind |
535 |
|
|
|
536 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
537 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(), Optional.empty(), sortOrder,
|
|
|
538 |
ticketSearchType, searchTerm, offset, limit);
|
|
|
539 |
} else {
|
|
|
540 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(),
|
| 27195 |
amit.gupta |
541 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), sortOrder, ticketSearchType,
|
| 24791 |
govind |
542 |
searchTerm, offset, limit);
|
|
|
543 |
}
|
| 24787 |
govind |
544 |
}
|
| 24747 |
govind |
545 |
ticketAssigneds = ticketAssignedRepository
|
|
|
546 |
.selectByTicketIds(tickets.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 24620 |
govind |
547 |
authUserIdAndAuthUserMap = csService.getAuthUserIdAndAuthUserMap(ticketAssigneds);
|
|
|
548 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
549 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
| 24417 |
govind |
550 |
} else {
|
| 24747 |
govind |
551 |
tickets = ticketRepository.selectAllByCreator(loginDetails.getFofoId(),
|
| 24751 |
govind |
552 |
Optional.of(TicketStatus.OPENED.equals(ticketStatus)), sortOrder, offset, limit);
|
| 24500 |
govind |
553 |
authUserIdAndAuthUserMap = csService.getTicketIdAndAuthUserMapUsingTickets(tickets);
|
| 24417 |
govind |
554 |
}
|
| 24500 |
govind |
555 |
model.addAttribute("roleType", roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds())));
|
| 24417 |
govind |
556 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService
|
|
|
557 |
.getSubCategoryIdAndSubCategoryMap(tickets);
|
|
|
558 |
model.addAttribute("tickets", tickets);
|
|
|
559 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
560 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
| 24699 |
govind |
561 |
model.addAttribute("resolved", ActivityType.RESOLVED);
|
|
|
562 |
model.addAttribute("resolved-accepted", ActivityType.RESOLVED_ACCEPTED);
|
|
|
563 |
model.addAttribute("resolved-rejected", ActivityType.RESOLVED_REJECTED);
|
| 24417 |
govind |
564 |
return "ticket-paginated";
|
|
|
565 |
}
|
|
|
566 |
|
|
|
567 |
@GetMapping(value = "/cs/getActivities")
|
|
|
568 |
public String getActivity(HttpServletRequest request,
|
|
|
569 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) throws Exception {
|
| 24824 |
govind |
570 |
List<Activity> allactivities = activityRepository.selectAll(ticketId);
|
| 27270 |
tejbeer |
571 |
List<List<ActivityAttachment>> activityAttachments = allactivities.stream().map(x -> x.getActivityAttachment())
|
|
|
572 |
.collect(Collectors.toList());
|
|
|
573 |
for (List<ActivityAttachment> aA : activityAttachments) {
|
|
|
574 |
// List<ActivityAttachment> documentId = aA.stream().map(x ->
|
|
|
575 |
// x).collect(Collectors.toList());
|
|
|
576 |
for (ActivityAttachment attachment : aA) {
|
|
|
577 |
Document document = documentRepository.selectById(attachment.getDocumentId());
|
|
|
578 |
attachment.setDocumentName(document.getDisplayName());
|
|
|
579 |
activityAttachmentRepository.persist(attachment);
|
|
|
580 |
}
|
|
|
581 |
}
|
| 24824 |
govind |
582 |
List<Activity> activities = null;
|
| 24572 |
amit.gupta |
583 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24620 |
govind |
584 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 24824 |
govind |
585 |
Set<Integer> authUserIds = allactivities.stream().map(x -> x.getCreatedBy()).collect(Collectors.toSet());
|
| 24572 |
amit.gupta |
586 |
List<AuthUser> users = authRepository.selectAllAuthUserByIds(new ArrayList<>(authUserIds));
|
| 24620 |
govind |
587 |
Map<Integer, String> authUserNameMap = users.stream()
|
|
|
588 |
.collect(Collectors.toMap(AuthUser::getId, x -> x.getFirstName() + " " + x.getLastName()));
|
| 24824 |
govind |
589 |
allactivities.stream().forEach(x -> x.setName(authUserNameMap.get(x.getCreatedBy())));
|
|
|
590 |
activities = allactivities;
|
|
|
591 |
} else {
|
| 27139 |
amit.gupta |
592 |
activities = allactivities.stream().filter(x -> ActivityType.PARTNER_ACTIVITIES.contains(x.getType()))
|
| 24824 |
govind |
593 |
.collect(Collectors.toList());
|
| 24572 |
amit.gupta |
594 |
}
|
| 24417 |
govind |
595 |
if (activities == null) {
|
|
|
596 |
throw new ProfitMandiBusinessException("Activity", ticketId, "No Activity Found");
|
|
|
597 |
}
|
|
|
598 |
model.addAttribute("response", mvcResponseSender.createResponseString(activities));
|
|
|
599 |
return "response";
|
|
|
600 |
|
|
|
601 |
}
|
|
|
602 |
|
|
|
603 |
@PostMapping(value = "/cs/createActivity")
|
|
|
604 |
public String createActivity(HttpServletRequest request,
|
|
|
605 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId,
|
| 24500 |
govind |
606 |
@RequestParam(name = "assigneeId", defaultValue = "0") int assigneeId,
|
| 24824 |
govind |
607 |
@RequestParam(name = "internal", defaultValue = "true") boolean internal,
|
| 27270 |
tejbeer |
608 |
@RequestParam(name = "message", defaultValue = "") String message, @RequestBody List<Integer> documentIds,
|
|
|
609 |
|
|
|
610 |
Model model) throws Exception {
|
|
|
611 |
|
|
|
612 |
LOGGER.info("documentIds" + documentIds);
|
| 24417 |
govind |
613 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24500 |
govind |
614 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
| 27150 |
amit.gupta |
615 |
List<TicketAssigned> ticketAssignedList = ticketAssignedRepository.selectByTicketIds(Arrays.asList(ticketId));
|
| 27270 |
tejbeer |
616 |
List<Integer> authUserIds = ticketAssignedList.stream().map(x -> x.getAssineeId()).collect(Collectors.toList());
|
|
|
617 |
authUserIds.add(ticketAssignedList.get(ticketAssignedList.size() - 1).getManagerId());
|
|
|
618 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectAllAuthUserByIds(authUserIds).stream()
|
|
|
619 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 24500 |
govind |
620 |
if (ticket.getCloseTimestamp() == null) {
|
| 27124 |
amit.gupta |
621 |
Activity activity = new Activity();
|
|
|
622 |
activity.setCreatedBy(0);
|
|
|
623 |
activity.setCreateTimestamp(LocalDateTime.now());
|
| 27150 |
amit.gupta |
624 |
String subject = null;
|
| 27270 |
tejbeer |
625 |
String mailMessage = null;
|
| 27159 |
amit.gupta |
626 |
activity.setMessage(message);
|
| 24500 |
govind |
627 |
if (!roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))) {
|
| 27150 |
amit.gupta |
628 |
CustomRetailer customRetailer = retailerService.getFofoRetailers(true).get(loginDetails.getFofoId());
|
| 24500 |
govind |
629 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
| 27270 |
tejbeer |
630 |
subject = String.format("Ticket Update #%s by franchisee %s", ticket.getId(),
|
|
|
631 |
customRetailer.getBusinessName() + "(" + customRetailer.getCode() + ")");
|
| 27197 |
amit.gupta |
632 |
mailMessage = String.format("Franchisee message - %s", message);
|
| 24500 |
govind |
633 |
} else {
|
| 27156 |
amit.gupta |
634 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 27164 |
amit.gupta |
635 |
activity.setCreatedBy(authUser.getId());
|
| 27162 |
amit.gupta |
636 |
authUsersMap.remove(authUser.getId());
|
| 27150 |
amit.gupta |
637 |
subject = String.format("Ticket Update #%s by %s", ticket.getId(), authUser.getName());
|
| 27197 |
amit.gupta |
638 |
mailMessage = String.format("%s's message - %s", authUser.getFirstName(), message);
|
| 24824 |
govind |
639 |
if (internal) {
|
|
|
640 |
activity.setType(ActivityType.COMMUNICATION_INTERNAL);
|
| 27124 |
amit.gupta |
641 |
// String subject = String.format(ACTIVITY_SUBJECT, ticket.getId());
|
| 24824 |
govind |
642 |
} else {
|
| 27186 |
amit.gupta |
643 |
String updatedBy = "SD Team";
|
| 27192 |
amit.gupta |
644 |
CustomRetailer customRetailer = retailerService.getFofoRetailers(true).get(ticket.getFofoId());
|
| 27186 |
amit.gupta |
645 |
subject = String.format("Ticket Update #%s by %s", ticket.getId(), updatedBy);
|
| 27197 |
amit.gupta |
646 |
String partnerMessage = String.format("%s's message - %s", updatedBy, message);
|
|
|
647 |
this.activityRelatedMail(customRetailer.getEmail(), null, "subject", partnerMessage);
|
| 24824 |
govind |
648 |
activity.setType(ActivityType.COMMUNICATION_OUT);
|
|
|
649 |
}
|
| 24500 |
govind |
650 |
}
|
| 27124 |
amit.gupta |
651 |
activityRepository.persist(activity);
|
| 27270 |
tejbeer |
652 |
|
|
|
653 |
for (Integer documentId : documentIds) {
|
|
|
654 |
ActivityAttachment activityAttachment = new ActivityAttachment();
|
|
|
655 |
activityAttachment.setActivityId(activity.getId());
|
|
|
656 |
activityAttachment.setDocumentId(documentId);
|
|
|
657 |
activityAttachmentRepository.persist(activityAttachment);
|
|
|
658 |
}
|
|
|
659 |
|
| 27124 |
amit.gupta |
660 |
csService.addActivity(ticket, activity);
|
| 27150 |
amit.gupta |
661 |
AuthUser authUser = authUsersMap.remove(authUserIds.get(0));
|
| 27270 |
tejbeer |
662 |
if (authUser == null) {
|
| 27163 |
amit.gupta |
663 |
authUser = authUsersMap.remove(authUserIds.get(1));
|
|
|
664 |
}
|
| 27150 |
amit.gupta |
665 |
model.addAttribute("response", mvcResponseSender.createResponseString(authUser));
|
| 27410 |
tejbeer |
666 |
String[] cc = authUsersMap.entrySet().stream().map(x -> x.getValue().getEmailId()).toArray(String[]::new);
|
| 27197 |
amit.gupta |
667 |
this.activityRelatedMail(authUser.getEmailId(), cc, subject, mailMessage);
|
| 24417 |
govind |
668 |
} else {
|
|
|
669 |
throw new ProfitMandiBusinessException("Ticket", ticket.getId(), "Already closed ticket");
|
|
|
670 |
}
|
|
|
671 |
return "response";
|
|
|
672 |
}
|
| 24500 |
govind |
673 |
|
| 24620 |
govind |
674 |
private void activityRelatedMail(String to, String[] cc, String subject, String message)
|
|
|
675 |
throws ProfitMandiBusinessException {
|
|
|
676 |
try {
|
|
|
677 |
Utils.sendMailWithAttachments(mailSender, to, cc, subject, message, null);
|
|
|
678 |
} catch (Exception e) {
|
|
|
679 |
throw new ProfitMandiBusinessException("Ticket Activity", to, "Could not send ticket activity mail");
|
|
|
680 |
}
|
|
|
681 |
}
|
|
|
682 |
|
| 24500 |
govind |
683 |
@PostMapping(value = "/cs/closeTicket")
|
| 24417 |
govind |
684 |
public String closeTicket(HttpServletRequest request,
|
| 24439 |
govind |
685 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId,
|
| 24500 |
govind |
686 |
@RequestParam(name = "happyCode") String happyCode, Model model) throws Exception {
|
|
|
687 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
688 |
if (ticket.getHappyCode().equals(happyCode)) {
|
|
|
689 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
|
|
690 |
ticketRepository.persist(ticket);
|
|
|
691 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
692 |
} else {
|
|
|
693 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Happy Code can't match");
|
| 24439 |
govind |
694 |
}
|
| 24417 |
govind |
695 |
return "response";
|
|
|
696 |
}
|
| 24500 |
govind |
697 |
|
|
|
698 |
@GetMapping(value = "/cs/managerTicket")
|
| 27124 |
amit.gupta |
699 |
public String getManagerTickets(HttpServletRequest request,
|
| 24699 |
govind |
700 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
701 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
| 24747 |
govind |
702 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
703 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
| 24500 |
govind |
704 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
705 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
706 |
throws ProfitMandiBusinessException {
|
| 24439 |
govind |
707 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
708 |
long size = 0;
|
| 24500 |
govind |
709 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
710 |
List<Ticket> tickets = null;
|
| 24569 |
govind |
711 |
Map<Integer, List<AuthUser>> authUserListMap = null;
|
| 27318 |
amit.gupta |
712 |
if (ticketSearchType == null) {
|
|
|
713 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
714 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder, Optional.empty(), null,
|
|
|
715 |
searchTerm, offset, limit);
|
|
|
716 |
size = ticketRepository.selectAllCountByManagerTicket(authUser.getId(), Optional.empty(), null, 0);
|
|
|
717 |
} else {
|
|
|
718 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder,
|
|
|
719 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), null, searchTerm, offset, limit);
|
|
|
720 |
size = ticketRepository.selectAllCountByManagerTicket(authUser.getId(),
|
|
|
721 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), null, 0);
|
|
|
722 |
}
|
| 24500 |
govind |
723 |
} else {
|
| 27318 |
amit.gupta |
724 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
725 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder, Optional.empty(),
|
|
|
726 |
ticketSearchType, searchTerm, offset, limit);
|
|
|
727 |
size = ticketRepository.selectAllCountByManagerTicket(authUser.getId(), Optional.empty(),
|
|
|
728 |
ticketSearchType, searchTerm);
|
| 24747 |
govind |
729 |
} else {
|
| 27318 |
amit.gupta |
730 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder,
|
|
|
731 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), ticketSearchType, searchTerm, offset,
|
|
|
732 |
limit);
|
|
|
733 |
size = ticketRepository.selectAllCountByManagerTicket(authUser.getId(),
|
|
|
734 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), ticketSearchType, searchTerm);
|
| 24747 |
govind |
735 |
}
|
|
|
736 |
|
| 24439 |
govind |
737 |
}
|
| 27318 |
amit.gupta |
738 |
authUserListMap = csService.getAssignedAuthList(tickets);
|
|
|
739 |
|
|
|
740 |
if (tickets.size() > 0) {
|
|
|
741 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
742 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
|
|
743 |
}
|
| 24439 |
govind |
744 |
if (size < limit) {
|
|
|
745 |
model.addAttribute("end", offset + size);
|
|
|
746 |
} else {
|
|
|
747 |
model.addAttribute("end", offset + limit);
|
|
|
748 |
}
|
|
|
749 |
model.addAttribute("start", offset + 1);
|
|
|
750 |
model.addAttribute("size", size);
|
|
|
751 |
model.addAttribute("tickets", tickets);
|
| 24500 |
govind |
752 |
|
| 24439 |
govind |
753 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService
|
|
|
754 |
.getSubCategoryIdAndSubCategoryMap(tickets);
|
| 24699 |
govind |
755 |
model.addAttribute("ticketStatusValues", TicketStatus.values());
|
|
|
756 |
model.addAttribute("orderByValues", SortOrder.values());
|
|
|
757 |
model.addAttribute("selectedticketStatus", ticketStatus);
|
|
|
758 |
model.addAttribute("selectedorderby", sortOrder);
|
| 24439 |
govind |
759 |
model.addAttribute("tickets", tickets);
|
| 24747 |
govind |
760 |
model.addAttribute("ticketSearchTypes", TicketSearchType.values());
|
| 24750 |
govind |
761 |
model.addAttribute("ticketSearchType", ticketSearchType);
|
| 24747 |
govind |
762 |
model.addAttribute("searchTerm", searchTerm);
|
| 24500 |
govind |
763 |
model.addAttribute("authUserListMap", authUserListMap);
|
| 24439 |
govind |
764 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
|
|
765 |
return "managerTicket";
|
|
|
766 |
}
|
| 24500 |
govind |
767 |
|
|
|
768 |
@GetMapping(value = "/cs/managerTicket-paginated")
|
| 27205 |
amit.gupta |
769 |
public String getManagerTicketsPaginated(HttpServletRequest request,
|
| 24699 |
govind |
770 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
771 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
| 24747 |
govind |
772 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
773 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
| 24500 |
govind |
774 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
775 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
776 |
throws ProfitMandiBusinessException {
|
| 24467 |
govind |
777 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24500 |
govind |
778 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 24557 |
govind |
779 |
Map<Integer, List<AuthUser>> authUserListMap = null;
|
| 24500 |
govind |
780 |
List<Ticket> tickets = null;
|
| 27318 |
amit.gupta |
781 |
if (ticketSearchType == null) {
|
|
|
782 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
783 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder, Optional.empty(), null,
|
|
|
784 |
searchTerm, offset, limit);
|
| 24787 |
govind |
785 |
|
| 24747 |
govind |
786 |
} else {
|
| 27318 |
amit.gupta |
787 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder,
|
|
|
788 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), null, searchTerm, offset, limit);
|
| 24787 |
govind |
789 |
|
| 27318 |
amit.gupta |
790 |
}
|
|
|
791 |
} else {
|
|
|
792 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
793 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder, Optional.empty(),
|
|
|
794 |
ticketSearchType, searchTerm, offset, limit);
|
| 24787 |
govind |
795 |
|
| 27318 |
amit.gupta |
796 |
} else {
|
|
|
797 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder,
|
|
|
798 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), ticketSearchType, searchTerm, offset,
|
|
|
799 |
limit);
|
| 24747 |
govind |
800 |
}
|
| 27318 |
amit.gupta |
801 |
|
| 24467 |
govind |
802 |
}
|
| 27318 |
amit.gupta |
803 |
authUserListMap = csService.getAssignedAuthList(tickets);
|
|
|
804 |
if (tickets.size() > 0) {
|
|
|
805 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
806 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
|
|
807 |
}
|
| 24467 |
govind |
808 |
model.addAttribute("tickets", tickets);
|
|
|
809 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService
|
|
|
810 |
.getSubCategoryIdAndSubCategoryMap(tickets);
|
|
|
811 |
model.addAttribute("tickets", tickets);
|
| 24500 |
govind |
812 |
model.addAttribute("authUserListMap", authUserListMap);
|
| 24467 |
govind |
813 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
|
|
814 |
return "managerTicket-paginated";
|
|
|
815 |
}
|
| 24500 |
govind |
816 |
|
|
|
817 |
@GetMapping(value = "/cs/edit-ticket")
|
|
|
818 |
public String getEditTicket(HttpServletRequest request,
|
|
|
819 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) {
|
|
|
820 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
821 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
|
|
822 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
823 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository
|
| 27124 |
amit.gupta |
824 |
.selectAll(ticketSubCategory.getCategoryId());
|
|
|
825 |
List<AuthUser> authUsers = new ArrayList<>();
|
| 24467 |
govind |
826 |
model.addAttribute("ticket", ticket);
|
|
|
827 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
828 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
| 24575 |
govind |
829 |
model.addAttribute("ticketSubCategory", ticketSubCategory);
|
| 24500 |
govind |
830 |
model.addAttribute("authUsers", authUsers);
|
| 24467 |
govind |
831 |
return "edit-ticket-modal";
|
|
|
832 |
}
|
| 24500 |
govind |
833 |
|
|
|
834 |
@PostMapping(value = "/cs/edit-ticket")
|
|
|
835 |
public String editTicket(HttpServletRequest request,
|
|
|
836 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId,
|
|
|
837 |
@RequestParam(name = "subCategoryId", defaultValue = "0") int subCategoryId,
|
|
|
838 |
@RequestParam(name = "categoryId", defaultValue = "0") int categoryId,
|
|
|
839 |
@RequestParam(name = "authUserId", defaultValue = "0") int authUserId, Model model) throws Exception {
|
| 27152 |
amit.gupta |
840 |
LOGGER.info("Ticket Id {}, CategoryId {}, SubCategory Id {}", ticketId, categoryId, subCategoryId);
|
| 24500 |
govind |
841 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
| 27124 |
amit.gupta |
842 |
csService.updateTicket(categoryId, subCategoryId, ticket);
|
|
|
843 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 24467 |
govind |
844 |
return "response";
|
| 27124 |
amit.gupta |
845 |
|
| 24467 |
govind |
846 |
}
|
| 24500 |
govind |
847 |
|
|
|
848 |
@DeleteMapping(value = "/cs/removePosition")
|
|
|
849 |
public String removePosition(HttpServletRequest request,
|
|
|
850 |
@RequestParam(name = "positionId", defaultValue = "0") int positionId, Model model) throws Exception {
|
| 24471 |
govind |
851 |
positionRepository.delete(positionId);
|
|
|
852 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
853 |
return "response";
|
|
|
854 |
}
|
| 24620 |
govind |
855 |
|
|
|
856 |
@PostMapping(value = "/cs/create-last-activity")
|
|
|
857 |
public String createlastActivity(HttpServletRequest request, @RequestParam(name = "ticketId") int ticketId,
|
|
|
858 |
@RequestParam(name = "lastactivity") ActivityType lastActivity, Model model) throws Exception {
|
|
|
859 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
860 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
861 |
Activity activity = new Activity();
|
|
|
862 |
String subject = String.format(ACTIVITY_SUBJECT, ticket.getId());
|
|
|
863 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
864 |
ticket.setLastActivity(lastActivity);
|
|
|
865 |
String to = retailerService.getFofoRetailer(ticket.getFofoId()).getEmail();
|
| 24699 |
govind |
866 |
String message = String.format(PARTNER_RESOLVED_TICKET_MAIL, ticketId, "REOPEN");
|
| 24620 |
govind |
867 |
activity.setMessage(message);
|
|
|
868 |
activity.setCreatedBy(authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getId());
|
|
|
869 |
activity.setTicketId(ticketId);
|
|
|
870 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
871 |
activity.setType(ActivityType.COMMUNICATION_OUT);
|
| 24621 |
govind |
872 |
this.activityRelatedMail(to, null, subject, message);
|
| 24620 |
govind |
873 |
} else {
|
|
|
874 |
if (ActivityType.RESOLVED_ACCEPTED == lastActivity) {
|
|
|
875 |
ticket.setLastActivity(lastActivity);
|
|
|
876 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
| 27139 |
amit.gupta |
877 |
activity.setMessage(ActivityType.RESOLVED_ACCEPTED.toString());
|
| 24620 |
govind |
878 |
activity.setCreatedBy(0);
|
|
|
879 |
activity.setTicketId(ticketId);
|
|
|
880 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
|
|
881 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
882 |
} else {
|
| 24699 |
govind |
883 |
String message = String.format(INTERNAL_REOPEN_MAIL, ticketId,
|
|
|
884 |
retailerService.getFofoRetailer(loginDetails.getFofoId()).getBusinessName());
|
| 24620 |
govind |
885 |
String to = authRepository.selectById(ticket.getL1AuthUser()).getEmailId();
|
| 27270 |
tejbeer |
886 |
String[] ccTo = authRepository
|
|
|
887 |
.selectAllAuthUserByIds(Arrays.asList(ticket.getL2AuthUser(), ticket.getL3AuthUser(),
|
|
|
888 |
ticket.getL4AuthUser(), ticket.getL5AuthUser()))
|
|
|
889 |
.stream().map(x -> x.getEmailId()).toArray(String[]::new);
|
| 24620 |
govind |
890 |
ticket.setLastActivity(lastActivity);
|
| 24638 |
govind |
891 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
892 |
ticketAssignedRepository.deleteByTicketId(ticketId);
|
| 24699 |
govind |
893 |
TicketAssigned ticketAssigned = new TicketAssigned();
|
| 24638 |
govind |
894 |
ticketAssigned.setAssineeId(ticket.getL1AuthUser());
|
|
|
895 |
ticketAssigned.setTicketId(ticketId);
|
|
|
896 |
ticketAssignedRepository.persist(ticketAssigned);
|
| 24620 |
govind |
897 |
activity.setMessage(INTERNAL_REOPEN_ACTIVITY_MESSAGE);
|
|
|
898 |
activity.setCreatedBy(0);
|
|
|
899 |
activity.setTicketId(ticketId);
|
|
|
900 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
|
|
901 |
activity.setCreateTimestamp(LocalDateTime.now());
|
| 27139 |
amit.gupta |
902 |
this.activityRelatedMail(to, ccTo, subject, message);
|
| 24699 |
govind |
903 |
this.activityRelatedMail(retailerService.getFofoRetailer(loginDetails.getFofoId()).getEmail(), null,
|
|
|
904 |
subject, String.format(PARTNER_REOPEN, ticketId));
|
| 24620 |
govind |
905 |
}
|
|
|
906 |
|
|
|
907 |
}
|
|
|
908 |
activityRepository.persist(activity);
|
|
|
909 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
910 |
return "response";
|
|
|
911 |
}
|
|
|
912 |
|
| 24417 |
govind |
913 |
}
|