| 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 |
|
| 28457 |
tejbeer |
267 |
|
|
|
268 |
List<Position> positions = positionRepository.selectAllPosition();
|
|
|
269 |
LOGGER.info("positions"+positions);
|
|
|
270 |
|
| 24500 |
govind |
271 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = csService
|
|
|
272 |
.getAuthUserIdAndAuthUserMapUsingPositions(positions);
|
|
|
273 |
Map<Integer, TicketCategory> categoryIdAndCategoryMap = csService
|
|
|
274 |
.getCategoryIdAndCategoryUsingPositions(positions);
|
|
|
275 |
Map<Integer, Region> regionIdAndRegionMap = csService.getRegionIdAndRegionMap(positions);
|
| 25570 |
tejbeer |
276 |
|
| 27410 |
tejbeer |
277 |
// Map<Integer, List<CustomRetailer>> positionIdAndpartnerRegionMap = csService
|
|
|
278 |
// .getpositionIdAndpartnerRegionMap(positions);
|
| 25570 |
tejbeer |
279 |
|
| 27410 |
tejbeer |
280 |
// Map<Integer, List<CustomRetailer>> addedpositionIdAndCustomRetailerMap = csService
|
|
|
281 |
// .getPositionCustomRetailerMap(positions);
|
|
|
282 |
// LOGGER.info("fofoIdAndCustomRetailerMap" + addedpositionIdAndCustomRetailerMap);
|
| 28457 |
tejbeer |
283 |
|
| 24500 |
govind |
284 |
|
| 24471 |
govind |
285 |
model.addAttribute("start", offset + 1);
|
| 28457 |
tejbeer |
286 |
|
| 24471 |
govind |
287 |
model.addAttribute("positions", positions);
|
|
|
288 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
289 |
model.addAttribute("categoryIdAndCategoryMap", categoryIdAndCategoryMap);
|
|
|
290 |
model.addAttribute("regionIdAndRegionMap", regionIdAndRegionMap);
|
| 27410 |
tejbeer |
291 |
// model.addAttribute("positionIdAndCustomRetailerMap",
|
|
|
292 |
// addedpositionIdAndCustomRetailerMap);
|
|
|
293 |
// model.addAttribute("positionIdAndpartnerRegionMap",
|
|
|
294 |
// positionIdAndpartnerRegionMap);
|
| 25570 |
tejbeer |
295 |
|
| 24417 |
govind |
296 |
return "create-position";
|
|
|
297 |
}
|
| 24500 |
govind |
298 |
|
| 24471 |
govind |
299 |
@GetMapping(value = "/cs/position-paginated")
|
| 24500 |
govind |
300 |
public String positionPaginated(HttpServletRequest request,
|
|
|
301 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 24471 |
govind |
302 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) {
|
| 24500 |
govind |
303 |
|
|
|
304 |
List<Position> positions = positionRepository.selectAll(offset, limit);
|
|
|
305 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = csService
|
|
|
306 |
.getAuthUserIdAndAuthUserMapUsingPositions(positions);
|
|
|
307 |
Map<Integer, TicketCategory> categoryIdAndCategoryMap = csService
|
|
|
308 |
.getCategoryIdAndCategoryUsingPositions(positions);
|
|
|
309 |
Map<Integer, Region> regionIdAndRegionMap = csService.getRegionIdAndRegionMap(positions);
|
| 27410 |
tejbeer |
310 |
/*
|
|
|
311 |
* Map<Integer, List<CustomRetailer>> positionIdAndpartnerRegionMap = csService
|
|
|
312 |
* .getpositionIdAndpartnerRegionMap(positions);
|
|
|
313 |
*
|
|
|
314 |
* Map<Integer, List<CustomRetailer>> addedpositionIdAndCustomRetailerMap =
|
|
|
315 |
* csService .getPositionCustomRetailerMap(positions);
|
|
|
316 |
*/
|
| 25570 |
tejbeer |
317 |
|
| 24471 |
govind |
318 |
model.addAttribute("positions", positions);
|
|
|
319 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
320 |
model.addAttribute("categoryIdAndCategoryMap", categoryIdAndCategoryMap);
|
|
|
321 |
model.addAttribute("regionIdAndRegionMap", regionIdAndRegionMap);
|
| 27410 |
tejbeer |
322 |
// model.addAttribute("positionIdAndCustomRetailerMap",
|
|
|
323 |
// addedpositionIdAndCustomRetailerMap);
|
|
|
324 |
// model.addAttribute("positionIdAndpartnerRegionMap",
|
|
|
325 |
// positionIdAndpartnerRegionMap);
|
| 25570 |
tejbeer |
326 |
|
| 24471 |
govind |
327 |
return "position-paginated";
|
|
|
328 |
}
|
| 24417 |
govind |
329 |
|
|
|
330 |
@PostMapping(value = "/cs/createPosition")
|
| 25570 |
tejbeer |
331 |
public String createPosition(HttpServletRequest request, @RequestBody CreatePositionModel createPositionModel,
|
|
|
332 |
Model model) throws Exception {
|
| 24417 |
govind |
333 |
|
| 25570 |
tejbeer |
334 |
Position position = positionRepository.selectPosition(createPositionModel.getAuthUserId(),
|
|
|
335 |
createPositionModel.getCategoryId(), createPositionModel.getRegionId(),
|
|
|
336 |
createPositionModel.getEscalationType());
|
| 24417 |
govind |
337 |
if (position == null) {
|
|
|
338 |
position = new Position();
|
| 25570 |
tejbeer |
339 |
position.setAuthUserId(createPositionModel.getAuthUserId());
|
|
|
340 |
position.setCategoryId(createPositionModel.getCategoryId());
|
|
|
341 |
position.setEscalationType(createPositionModel.getEscalationType());
|
|
|
342 |
position.setRegionId(createPositionModel.getRegionId());
|
| 24417 |
govind |
343 |
position.setCreateTimestamp(LocalDateTime.now());
|
|
|
344 |
positionRepository.persist(position);
|
| 25570 |
tejbeer |
345 |
|
|
|
346 |
for (int fofoId : createPositionModel.getFofoIds()) {
|
|
|
347 |
|
|
|
348 |
PartnerPosition partnerPosition = new PartnerPosition();
|
|
|
349 |
partnerPosition.setFofoId(fofoId);
|
|
|
350 |
partnerPosition.setRegionId(createPositionModel.getRegionId());
|
|
|
351 |
partnerPosition.setPositionId(position.getId());
|
|
|
352 |
partnersPositionRepository.persist(partnerPosition);
|
|
|
353 |
LOGGER.info("partnerPosition" + partnerPosition);
|
|
|
354 |
}
|
|
|
355 |
|
| 24417 |
govind |
356 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
357 |
} else {
|
| 25570 |
tejbeer |
358 |
throw new ProfitMandiBusinessException("Position", createPositionModel.getAuthUserId(), "already exists!");
|
| 24417 |
govind |
359 |
}
|
|
|
360 |
return "response";
|
|
|
361 |
}
|
|
|
362 |
|
| 25570 |
tejbeer |
363 |
@PostMapping(value = "/cs/updatePartnerPosition")
|
|
|
364 |
public String updatePartnerPosition(HttpServletRequest request, @RequestParam(name = "regionId") int regionId,
|
|
|
365 |
@RequestBody List<Integer> selectedFofoIds, @RequestParam(name = "positionId") int positionId, Model model)
|
|
|
366 |
throws Exception {
|
|
|
367 |
|
|
|
368 |
partnersPositionRepository.delete(positionId);
|
|
|
369 |
for (int fofoId : selectedFofoIds) {
|
|
|
370 |
PartnerPosition partnerPosition = new PartnerPosition();
|
|
|
371 |
partnerPosition.setFofoId(fofoId);
|
|
|
372 |
partnerPosition.setRegionId(regionId);
|
|
|
373 |
partnerPosition.setPositionId(positionId);
|
|
|
374 |
partnersPositionRepository.persist(partnerPosition);
|
|
|
375 |
}
|
|
|
376 |
|
|
|
377 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
378 |
|
|
|
379 |
return "response";
|
|
|
380 |
}
|
|
|
381 |
|
| 24417 |
govind |
382 |
@GetMapping(value = "/cs/createTicket")
|
| 24824 |
govind |
383 |
public String createTicket(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
384 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24500 |
govind |
385 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
| 24824 |
govind |
386 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 24417 |
govind |
387 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
388 |
return "create-ticket";
|
|
|
389 |
}
|
|
|
390 |
|
|
|
391 |
@GetMapping(value = "/cs/getSubCategoriesByCategoryId")
|
|
|
392 |
public String getSubCategoriesByCategoryId(HttpServletRequest request,
|
|
|
393 |
@RequestParam(name = "categoryId", defaultValue = "0") int categoryId, Model model) {
|
|
|
394 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll(categoryId);
|
|
|
395 |
LOGGER.info(ticketSubCategories);
|
|
|
396 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
|
|
397 |
return "ticket-sub-categories";
|
|
|
398 |
}
|
|
|
399 |
|
|
|
400 |
@PostMapping(value = "/cs/createTicket")
|
|
|
401 |
public String createTicket(HttpServletRequest request, @RequestParam(name = "categoryId") int categoryId,
|
|
|
402 |
@RequestParam(name = "subCategoryId") int subCategoryId, @RequestParam(name = "message") String message,
|
|
|
403 |
Model model) throws Exception {
|
|
|
404 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24837 |
govind |
405 |
List<Ticket> tickets = ticketRepository.selectAllResolvedMarkedTicketByCreator(loginDetails.getFofoId());
|
| 24620 |
govind |
406 |
if (tickets.size() > 3 || tickets.size() == 3) {
|
|
|
407 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
408 |
} else {
|
|
|
409 |
csService.createTicket(loginDetails.getFofoId(), categoryId, subCategoryId, message);
|
|
|
410 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
411 |
}
|
| 24417 |
govind |
412 |
return "response";
|
|
|
413 |
}
|
|
|
414 |
|
|
|
415 |
@GetMapping(value = "/cs/myticket")
|
| 24699 |
govind |
416 |
public String getTicket(HttpServletRequest request,
|
|
|
417 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
418 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
| 24787 |
govind |
419 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
420 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
| 24699 |
govind |
421 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 24417 |
govind |
422 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
423 |
throws ProfitMandiBusinessException {
|
|
|
424 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
425 |
List<Ticket> tickets = null;
|
| 24500 |
govind |
426 |
List<TicketAssigned> ticketAssigneds = null;
|
| 24417 |
govind |
427 |
long size = 0;
|
| 24500 |
govind |
428 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = null;
|
| 24417 |
govind |
429 |
if (roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))) {
|
|
|
430 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 24787 |
govind |
431 |
if (ticketSearchType == null) {
|
| 24791 |
govind |
432 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
433 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(), Optional.empty(), sortOrder, null,
|
|
|
434 |
searchTerm, offset, limit);
|
|
|
435 |
size = ticketRepository.selectAllCountByAssignee(authUser.getId(), Optional.empty(), null,
|
|
|
436 |
searchTerm);
|
|
|
437 |
} else {
|
| 24787 |
govind |
438 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(),
|
| 27124 |
amit.gupta |
439 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), sortOrder, null, searchTerm, offset,
|
| 24787 |
govind |
440 |
limit);
|
|
|
441 |
size = ticketRepository.selectAllCountByAssignee(authUser.getId(),
|
| 27124 |
amit.gupta |
442 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), null, searchTerm);
|
| 24791 |
govind |
443 |
}
|
|
|
444 |
|
| 24787 |
govind |
445 |
} else {
|
| 24791 |
govind |
446 |
|
|
|
447 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
448 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(), Optional.empty(), sortOrder,
|
|
|
449 |
ticketSearchType, searchTerm, offset, limit);
|
|
|
450 |
size = ticketRepository.selectAllCountByAssignee(authUser.getId(), Optional.empty(),
|
|
|
451 |
ticketSearchType, searchTerm);
|
|
|
452 |
} else {
|
| 24787 |
govind |
453 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(),
|
| 27124 |
amit.gupta |
454 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), sortOrder, ticketSearchType,
|
| 24787 |
govind |
455 |
searchTerm, offset, limit);
|
|
|
456 |
size = ticketRepository.selectAllCountByAssignee(authUser.getId(),
|
| 27124 |
amit.gupta |
457 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), ticketSearchType, searchTerm);
|
| 24791 |
govind |
458 |
}
|
| 24787 |
govind |
459 |
}
|
| 24824 |
govind |
460 |
// LOGGER.info(size + "size");
|
| 24791 |
govind |
461 |
if (tickets.size() > 0) {
|
|
|
462 |
ticketAssigneds = ticketAssignedRepository
|
|
|
463 |
.selectByTicketIds(tickets.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
|
|
464 |
authUserIdAndAuthUserMap = csService.getAuthUserIdAndAuthUserMap(ticketAssigneds);
|
|
|
465 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
466 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
| 24787 |
govind |
467 |
}
|
| 24620 |
govind |
468 |
|
| 24417 |
govind |
469 |
} else {
|
| 24699 |
govind |
470 |
tickets = ticketRepository.selectAllByCreator(loginDetails.getFofoId(),
|
| 24751 |
govind |
471 |
Optional.of(TicketStatus.OPENED.equals(ticketStatus)), sortOrder, offset, limit);
|
| 24699 |
govind |
472 |
size = ticketRepository.selectAllCountByCreator(loginDetails.getFofoId(),
|
| 24751 |
govind |
473 |
Optional.of(TicketStatus.OPENED.equals(ticketStatus)));
|
| 24699 |
govind |
474 |
}
|
|
|
475 |
authUserIdAndAuthUserMap = csService.getTicketIdAndAuthUserMapUsingTickets(tickets);
|
| 24500 |
govind |
476 |
|
| 24417 |
govind |
477 |
if (size < limit) {
|
|
|
478 |
model.addAttribute("end", offset + size);
|
|
|
479 |
} else {
|
|
|
480 |
model.addAttribute("end", offset + limit);
|
|
|
481 |
}
|
|
|
482 |
model.addAttribute("start", offset + 1);
|
|
|
483 |
model.addAttribute("size", size);
|
| 24500 |
govind |
484 |
model.addAttribute("roleType", roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds())));
|
| 24417 |
govind |
485 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService
|
|
|
486 |
.getSubCategoryIdAndSubCategoryMap(tickets);
|
|
|
487 |
model.addAttribute("tickets", tickets);
|
| 24620 |
govind |
488 |
model.addAttribute("resolved", ActivityType.RESOLVED);
|
|
|
489 |
model.addAttribute("resolved-accepted", ActivityType.RESOLVED_ACCEPTED);
|
|
|
490 |
model.addAttribute("resolved-rejected", ActivityType.RESOLVED_REJECTED);
|
| 24417 |
govind |
491 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
492 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
| 24699 |
govind |
493 |
model.addAttribute("ticketStatusValues", TicketStatus.values());
|
|
|
494 |
model.addAttribute("orderByValues", SortOrder.values());
|
|
|
495 |
model.addAttribute("selectedticketStatus", ticketStatus);
|
|
|
496 |
model.addAttribute("selectedorderby", sortOrder);
|
| 24787 |
govind |
497 |
model.addAttribute("ticketSearchTypes", TicketSearchType.values());
|
|
|
498 |
model.addAttribute("ticketSearchType", ticketSearchType);
|
|
|
499 |
model.addAttribute("searchTerm", searchTerm);
|
| 24417 |
govind |
500 |
return "ticket";
|
|
|
501 |
}
|
| 24500 |
govind |
502 |
|
| 24417 |
govind |
503 |
@GetMapping(value = "/cs/myticketPaginated")
|
| 24500 |
govind |
504 |
public String getMyTicketPaginated(HttpServletRequest request,
|
| 24699 |
govind |
505 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
506 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
| 24787 |
govind |
507 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
508 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
| 24500 |
govind |
509 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 24417 |
govind |
510 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
511 |
throws ProfitMandiBusinessException {
|
|
|
512 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
513 |
List<Ticket> tickets = null;
|
| 24500 |
govind |
514 |
List<TicketAssigned> ticketAssigneds = null;
|
| 24824 |
govind |
515 |
|
| 24500 |
govind |
516 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = null;
|
| 24824 |
govind |
517 |
|
| 24417 |
govind |
518 |
if (roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))) {
|
|
|
519 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 24791 |
govind |
520 |
if (ticketSearchType == null) {
|
|
|
521 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
522 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(), Optional.empty(), sortOrder, null,
|
|
|
523 |
searchTerm, offset, limit);
|
|
|
524 |
} else {
|
|
|
525 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(),
|
| 27195 |
amit.gupta |
526 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), sortOrder, null, searchTerm, offset,
|
| 24791 |
govind |
527 |
limit);
|
|
|
528 |
}
|
| 24787 |
govind |
529 |
|
|
|
530 |
} else {
|
| 24791 |
govind |
531 |
|
|
|
532 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
533 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(), Optional.empty(), sortOrder,
|
|
|
534 |
ticketSearchType, searchTerm, offset, limit);
|
|
|
535 |
} else {
|
|
|
536 |
tickets = ticketRepository.selectAllByAssignee(authUser.getId(),
|
| 27195 |
amit.gupta |
537 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), sortOrder, ticketSearchType,
|
| 24791 |
govind |
538 |
searchTerm, offset, limit);
|
|
|
539 |
}
|
| 24787 |
govind |
540 |
}
|
| 24747 |
govind |
541 |
ticketAssigneds = ticketAssignedRepository
|
|
|
542 |
.selectByTicketIds(tickets.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 24620 |
govind |
543 |
authUserIdAndAuthUserMap = csService.getAuthUserIdAndAuthUserMap(ticketAssigneds);
|
|
|
544 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
545 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
| 24417 |
govind |
546 |
} else {
|
| 24747 |
govind |
547 |
tickets = ticketRepository.selectAllByCreator(loginDetails.getFofoId(),
|
| 24751 |
govind |
548 |
Optional.of(TicketStatus.OPENED.equals(ticketStatus)), sortOrder, offset, limit);
|
| 24500 |
govind |
549 |
authUserIdAndAuthUserMap = csService.getTicketIdAndAuthUserMapUsingTickets(tickets);
|
| 24417 |
govind |
550 |
}
|
| 24500 |
govind |
551 |
model.addAttribute("roleType", roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds())));
|
| 24417 |
govind |
552 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService
|
|
|
553 |
.getSubCategoryIdAndSubCategoryMap(tickets);
|
|
|
554 |
model.addAttribute("tickets", tickets);
|
|
|
555 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
556 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
| 24699 |
govind |
557 |
model.addAttribute("resolved", ActivityType.RESOLVED);
|
|
|
558 |
model.addAttribute("resolved-accepted", ActivityType.RESOLVED_ACCEPTED);
|
|
|
559 |
model.addAttribute("resolved-rejected", ActivityType.RESOLVED_REJECTED);
|
| 24417 |
govind |
560 |
return "ticket-paginated";
|
|
|
561 |
}
|
|
|
562 |
|
|
|
563 |
@GetMapping(value = "/cs/getActivities")
|
|
|
564 |
public String getActivity(HttpServletRequest request,
|
|
|
565 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) throws Exception {
|
| 24824 |
govind |
566 |
List<Activity> allactivities = activityRepository.selectAll(ticketId);
|
| 27270 |
tejbeer |
567 |
List<List<ActivityAttachment>> activityAttachments = allactivities.stream().map(x -> x.getActivityAttachment())
|
|
|
568 |
.collect(Collectors.toList());
|
|
|
569 |
for (List<ActivityAttachment> aA : activityAttachments) {
|
|
|
570 |
// List<ActivityAttachment> documentId = aA.stream().map(x ->
|
|
|
571 |
// x).collect(Collectors.toList());
|
|
|
572 |
for (ActivityAttachment attachment : aA) {
|
|
|
573 |
Document document = documentRepository.selectById(attachment.getDocumentId());
|
|
|
574 |
attachment.setDocumentName(document.getDisplayName());
|
|
|
575 |
activityAttachmentRepository.persist(attachment);
|
|
|
576 |
}
|
|
|
577 |
}
|
| 24824 |
govind |
578 |
List<Activity> activities = null;
|
| 24572 |
amit.gupta |
579 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24620 |
govind |
580 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 24824 |
govind |
581 |
Set<Integer> authUserIds = allactivities.stream().map(x -> x.getCreatedBy()).collect(Collectors.toSet());
|
| 24572 |
amit.gupta |
582 |
List<AuthUser> users = authRepository.selectAllAuthUserByIds(new ArrayList<>(authUserIds));
|
| 24620 |
govind |
583 |
Map<Integer, String> authUserNameMap = users.stream()
|
|
|
584 |
.collect(Collectors.toMap(AuthUser::getId, x -> x.getFirstName() + " " + x.getLastName()));
|
| 24824 |
govind |
585 |
allactivities.stream().forEach(x -> x.setName(authUserNameMap.get(x.getCreatedBy())));
|
|
|
586 |
activities = allactivities;
|
|
|
587 |
} else {
|
| 27139 |
amit.gupta |
588 |
activities = allactivities.stream().filter(x -> ActivityType.PARTNER_ACTIVITIES.contains(x.getType()))
|
| 24824 |
govind |
589 |
.collect(Collectors.toList());
|
| 24572 |
amit.gupta |
590 |
}
|
| 24417 |
govind |
591 |
if (activities == null) {
|
|
|
592 |
throw new ProfitMandiBusinessException("Activity", ticketId, "No Activity Found");
|
|
|
593 |
}
|
|
|
594 |
model.addAttribute("response", mvcResponseSender.createResponseString(activities));
|
|
|
595 |
return "response";
|
|
|
596 |
|
|
|
597 |
}
|
|
|
598 |
|
|
|
599 |
@PostMapping(value = "/cs/createActivity")
|
|
|
600 |
public String createActivity(HttpServletRequest request,
|
|
|
601 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId,
|
| 24500 |
govind |
602 |
@RequestParam(name = "assigneeId", defaultValue = "0") int assigneeId,
|
| 24824 |
govind |
603 |
@RequestParam(name = "internal", defaultValue = "true") boolean internal,
|
| 27270 |
tejbeer |
604 |
@RequestParam(name = "message", defaultValue = "") String message, @RequestBody List<Integer> documentIds,
|
|
|
605 |
|
|
|
606 |
Model model) throws Exception {
|
|
|
607 |
|
|
|
608 |
LOGGER.info("documentIds" + documentIds);
|
| 24417 |
govind |
609 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24500 |
govind |
610 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
| 27150 |
amit.gupta |
611 |
List<TicketAssigned> ticketAssignedList = ticketAssignedRepository.selectByTicketIds(Arrays.asList(ticketId));
|
| 27270 |
tejbeer |
612 |
List<Integer> authUserIds = ticketAssignedList.stream().map(x -> x.getAssineeId()).collect(Collectors.toList());
|
|
|
613 |
authUserIds.add(ticketAssignedList.get(ticketAssignedList.size() - 1).getManagerId());
|
|
|
614 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectAllAuthUserByIds(authUserIds).stream()
|
|
|
615 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 24500 |
govind |
616 |
if (ticket.getCloseTimestamp() == null) {
|
| 27124 |
amit.gupta |
617 |
Activity activity = new Activity();
|
|
|
618 |
activity.setCreatedBy(0);
|
|
|
619 |
activity.setCreateTimestamp(LocalDateTime.now());
|
| 27150 |
amit.gupta |
620 |
String subject = null;
|
| 27270 |
tejbeer |
621 |
String mailMessage = null;
|
| 27159 |
amit.gupta |
622 |
activity.setMessage(message);
|
| 24500 |
govind |
623 |
if (!roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))) {
|
| 27150 |
amit.gupta |
624 |
CustomRetailer customRetailer = retailerService.getFofoRetailers(true).get(loginDetails.getFofoId());
|
| 24500 |
govind |
625 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
| 27270 |
tejbeer |
626 |
subject = String.format("Ticket Update #%s by franchisee %s", ticket.getId(),
|
|
|
627 |
customRetailer.getBusinessName() + "(" + customRetailer.getCode() + ")");
|
| 27197 |
amit.gupta |
628 |
mailMessage = String.format("Franchisee message - %s", message);
|
| 24500 |
govind |
629 |
} else {
|
| 27156 |
amit.gupta |
630 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 27164 |
amit.gupta |
631 |
activity.setCreatedBy(authUser.getId());
|
| 27162 |
amit.gupta |
632 |
authUsersMap.remove(authUser.getId());
|
| 27150 |
amit.gupta |
633 |
subject = String.format("Ticket Update #%s by %s", ticket.getId(), authUser.getName());
|
| 27197 |
amit.gupta |
634 |
mailMessage = String.format("%s's message - %s", authUser.getFirstName(), message);
|
| 24824 |
govind |
635 |
if (internal) {
|
|
|
636 |
activity.setType(ActivityType.COMMUNICATION_INTERNAL);
|
| 27124 |
amit.gupta |
637 |
// String subject = String.format(ACTIVITY_SUBJECT, ticket.getId());
|
| 24824 |
govind |
638 |
} else {
|
| 27186 |
amit.gupta |
639 |
String updatedBy = "SD Team";
|
| 27192 |
amit.gupta |
640 |
CustomRetailer customRetailer = retailerService.getFofoRetailers(true).get(ticket.getFofoId());
|
| 27186 |
amit.gupta |
641 |
subject = String.format("Ticket Update #%s by %s", ticket.getId(), updatedBy);
|
| 27197 |
amit.gupta |
642 |
String partnerMessage = String.format("%s's message - %s", updatedBy, message);
|
|
|
643 |
this.activityRelatedMail(customRetailer.getEmail(), null, "subject", partnerMessage);
|
| 24824 |
govind |
644 |
activity.setType(ActivityType.COMMUNICATION_OUT);
|
|
|
645 |
}
|
| 24500 |
govind |
646 |
}
|
| 27124 |
amit.gupta |
647 |
activityRepository.persist(activity);
|
| 27270 |
tejbeer |
648 |
|
|
|
649 |
for (Integer documentId : documentIds) {
|
|
|
650 |
ActivityAttachment activityAttachment = new ActivityAttachment();
|
|
|
651 |
activityAttachment.setActivityId(activity.getId());
|
|
|
652 |
activityAttachment.setDocumentId(documentId);
|
|
|
653 |
activityAttachmentRepository.persist(activityAttachment);
|
|
|
654 |
}
|
|
|
655 |
|
| 27124 |
amit.gupta |
656 |
csService.addActivity(ticket, activity);
|
| 27150 |
amit.gupta |
657 |
AuthUser authUser = authUsersMap.remove(authUserIds.get(0));
|
| 27270 |
tejbeer |
658 |
if (authUser == null) {
|
| 27163 |
amit.gupta |
659 |
authUser = authUsersMap.remove(authUserIds.get(1));
|
|
|
660 |
}
|
| 27150 |
amit.gupta |
661 |
model.addAttribute("response", mvcResponseSender.createResponseString(authUser));
|
| 27410 |
tejbeer |
662 |
String[] cc = authUsersMap.entrySet().stream().map(x -> x.getValue().getEmailId()).toArray(String[]::new);
|
| 27197 |
amit.gupta |
663 |
this.activityRelatedMail(authUser.getEmailId(), cc, subject, mailMessage);
|
| 24417 |
govind |
664 |
} else {
|
|
|
665 |
throw new ProfitMandiBusinessException("Ticket", ticket.getId(), "Already closed ticket");
|
|
|
666 |
}
|
|
|
667 |
return "response";
|
|
|
668 |
}
|
| 24500 |
govind |
669 |
|
| 24620 |
govind |
670 |
private void activityRelatedMail(String to, String[] cc, String subject, String message)
|
|
|
671 |
throws ProfitMandiBusinessException {
|
|
|
672 |
try {
|
|
|
673 |
Utils.sendMailWithAttachments(mailSender, to, cc, subject, message, null);
|
|
|
674 |
} catch (Exception e) {
|
|
|
675 |
throw new ProfitMandiBusinessException("Ticket Activity", to, "Could not send ticket activity mail");
|
|
|
676 |
}
|
|
|
677 |
}
|
|
|
678 |
|
| 24500 |
govind |
679 |
@PostMapping(value = "/cs/closeTicket")
|
| 24417 |
govind |
680 |
public String closeTicket(HttpServletRequest request,
|
| 24439 |
govind |
681 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId,
|
| 24500 |
govind |
682 |
@RequestParam(name = "happyCode") String happyCode, Model model) throws Exception {
|
|
|
683 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
684 |
if (ticket.getHappyCode().equals(happyCode)) {
|
|
|
685 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
|
|
686 |
ticketRepository.persist(ticket);
|
|
|
687 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
688 |
} else {
|
|
|
689 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Happy Code can't match");
|
| 24439 |
govind |
690 |
}
|
| 24417 |
govind |
691 |
return "response";
|
|
|
692 |
}
|
| 24500 |
govind |
693 |
|
|
|
694 |
@GetMapping(value = "/cs/managerTicket")
|
| 27124 |
amit.gupta |
695 |
public String getManagerTickets(HttpServletRequest request,
|
| 24699 |
govind |
696 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
697 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
| 24747 |
govind |
698 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
699 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
| 24500 |
govind |
700 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
701 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
702 |
throws ProfitMandiBusinessException {
|
| 24439 |
govind |
703 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
704 |
long size = 0;
|
| 24500 |
govind |
705 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
706 |
List<Ticket> tickets = null;
|
| 24569 |
govind |
707 |
Map<Integer, List<AuthUser>> authUserListMap = null;
|
| 27318 |
amit.gupta |
708 |
if (ticketSearchType == null) {
|
|
|
709 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
710 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder, Optional.empty(), null,
|
|
|
711 |
searchTerm, offset, limit);
|
|
|
712 |
size = ticketRepository.selectAllCountByManagerTicket(authUser.getId(), Optional.empty(), null, 0);
|
|
|
713 |
} else {
|
|
|
714 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder,
|
|
|
715 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), null, searchTerm, offset, limit);
|
|
|
716 |
size = ticketRepository.selectAllCountByManagerTicket(authUser.getId(),
|
|
|
717 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), null, 0);
|
|
|
718 |
}
|
| 24500 |
govind |
719 |
} else {
|
| 27318 |
amit.gupta |
720 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
721 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder, Optional.empty(),
|
|
|
722 |
ticketSearchType, searchTerm, offset, limit);
|
|
|
723 |
size = ticketRepository.selectAllCountByManagerTicket(authUser.getId(), Optional.empty(),
|
|
|
724 |
ticketSearchType, searchTerm);
|
| 24747 |
govind |
725 |
} else {
|
| 27318 |
amit.gupta |
726 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder,
|
|
|
727 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), ticketSearchType, searchTerm, offset,
|
|
|
728 |
limit);
|
|
|
729 |
size = ticketRepository.selectAllCountByManagerTicket(authUser.getId(),
|
|
|
730 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), ticketSearchType, searchTerm);
|
| 24747 |
govind |
731 |
}
|
|
|
732 |
|
| 24439 |
govind |
733 |
}
|
| 27318 |
amit.gupta |
734 |
authUserListMap = csService.getAssignedAuthList(tickets);
|
|
|
735 |
|
|
|
736 |
if (tickets.size() > 0) {
|
|
|
737 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
738 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
|
|
739 |
}
|
| 24439 |
govind |
740 |
if (size < limit) {
|
|
|
741 |
model.addAttribute("end", offset + size);
|
|
|
742 |
} else {
|
|
|
743 |
model.addAttribute("end", offset + limit);
|
|
|
744 |
}
|
|
|
745 |
model.addAttribute("start", offset + 1);
|
|
|
746 |
model.addAttribute("size", size);
|
|
|
747 |
model.addAttribute("tickets", tickets);
|
| 24500 |
govind |
748 |
|
| 24439 |
govind |
749 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService
|
|
|
750 |
.getSubCategoryIdAndSubCategoryMap(tickets);
|
| 24699 |
govind |
751 |
model.addAttribute("ticketStatusValues", TicketStatus.values());
|
|
|
752 |
model.addAttribute("orderByValues", SortOrder.values());
|
|
|
753 |
model.addAttribute("selectedticketStatus", ticketStatus);
|
|
|
754 |
model.addAttribute("selectedorderby", sortOrder);
|
| 24439 |
govind |
755 |
model.addAttribute("tickets", tickets);
|
| 24747 |
govind |
756 |
model.addAttribute("ticketSearchTypes", TicketSearchType.values());
|
| 24750 |
govind |
757 |
model.addAttribute("ticketSearchType", ticketSearchType);
|
| 24747 |
govind |
758 |
model.addAttribute("searchTerm", searchTerm);
|
| 24500 |
govind |
759 |
model.addAttribute("authUserListMap", authUserListMap);
|
| 24439 |
govind |
760 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
|
|
761 |
return "managerTicket";
|
|
|
762 |
}
|
| 24500 |
govind |
763 |
|
|
|
764 |
@GetMapping(value = "/cs/managerTicket-paginated")
|
| 27205 |
amit.gupta |
765 |
public String getManagerTicketsPaginated(HttpServletRequest request,
|
| 24699 |
govind |
766 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
767 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
| 24747 |
govind |
768 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
769 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
| 24500 |
govind |
770 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
771 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
772 |
throws ProfitMandiBusinessException {
|
| 24467 |
govind |
773 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24500 |
govind |
774 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 24557 |
govind |
775 |
Map<Integer, List<AuthUser>> authUserListMap = null;
|
| 24500 |
govind |
776 |
List<Ticket> tickets = null;
|
| 27318 |
amit.gupta |
777 |
if (ticketSearchType == null) {
|
|
|
778 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
779 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder, Optional.empty(), null,
|
|
|
780 |
searchTerm, offset, limit);
|
| 24787 |
govind |
781 |
|
| 24747 |
govind |
782 |
} else {
|
| 27318 |
amit.gupta |
783 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder,
|
|
|
784 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), null, searchTerm, offset, limit);
|
| 24787 |
govind |
785 |
|
| 27318 |
amit.gupta |
786 |
}
|
|
|
787 |
} else {
|
|
|
788 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
789 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder, Optional.empty(),
|
|
|
790 |
ticketSearchType, searchTerm, offset, limit);
|
| 24787 |
govind |
791 |
|
| 27318 |
amit.gupta |
792 |
} else {
|
|
|
793 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder,
|
|
|
794 |
Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), ticketSearchType, searchTerm, offset,
|
|
|
795 |
limit);
|
| 24747 |
govind |
796 |
}
|
| 27318 |
amit.gupta |
797 |
|
| 24467 |
govind |
798 |
}
|
| 27318 |
amit.gupta |
799 |
authUserListMap = csService.getAssignedAuthList(tickets);
|
|
|
800 |
if (tickets.size() > 0) {
|
|
|
801 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
802 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
|
|
803 |
}
|
| 24467 |
govind |
804 |
model.addAttribute("tickets", tickets);
|
|
|
805 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService
|
|
|
806 |
.getSubCategoryIdAndSubCategoryMap(tickets);
|
|
|
807 |
model.addAttribute("tickets", tickets);
|
| 24500 |
govind |
808 |
model.addAttribute("authUserListMap", authUserListMap);
|
| 24467 |
govind |
809 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
|
|
810 |
return "managerTicket-paginated";
|
|
|
811 |
}
|
| 24500 |
govind |
812 |
|
|
|
813 |
@GetMapping(value = "/cs/edit-ticket")
|
|
|
814 |
public String getEditTicket(HttpServletRequest request,
|
|
|
815 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) {
|
|
|
816 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
817 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
|
|
818 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
819 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository
|
| 27124 |
amit.gupta |
820 |
.selectAll(ticketSubCategory.getCategoryId());
|
|
|
821 |
List<AuthUser> authUsers = new ArrayList<>();
|
| 24467 |
govind |
822 |
model.addAttribute("ticket", ticket);
|
|
|
823 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
824 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
| 24575 |
govind |
825 |
model.addAttribute("ticketSubCategory", ticketSubCategory);
|
| 24500 |
govind |
826 |
model.addAttribute("authUsers", authUsers);
|
| 24467 |
govind |
827 |
return "edit-ticket-modal";
|
|
|
828 |
}
|
| 24500 |
govind |
829 |
|
|
|
830 |
@PostMapping(value = "/cs/edit-ticket")
|
|
|
831 |
public String editTicket(HttpServletRequest request,
|
|
|
832 |
@RequestParam(name = "ticketId", defaultValue = "0") int ticketId,
|
|
|
833 |
@RequestParam(name = "subCategoryId", defaultValue = "0") int subCategoryId,
|
|
|
834 |
@RequestParam(name = "categoryId", defaultValue = "0") int categoryId,
|
|
|
835 |
@RequestParam(name = "authUserId", defaultValue = "0") int authUserId, Model model) throws Exception {
|
| 27152 |
amit.gupta |
836 |
LOGGER.info("Ticket Id {}, CategoryId {}, SubCategory Id {}", ticketId, categoryId, subCategoryId);
|
| 24500 |
govind |
837 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
| 27124 |
amit.gupta |
838 |
csService.updateTicket(categoryId, subCategoryId, ticket);
|
|
|
839 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 24467 |
govind |
840 |
return "response";
|
| 27124 |
amit.gupta |
841 |
|
| 24467 |
govind |
842 |
}
|
| 24500 |
govind |
843 |
|
|
|
844 |
@DeleteMapping(value = "/cs/removePosition")
|
|
|
845 |
public String removePosition(HttpServletRequest request,
|
|
|
846 |
@RequestParam(name = "positionId", defaultValue = "0") int positionId, Model model) throws Exception {
|
| 24471 |
govind |
847 |
positionRepository.delete(positionId);
|
|
|
848 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
849 |
return "response";
|
|
|
850 |
}
|
| 24620 |
govind |
851 |
|
|
|
852 |
@PostMapping(value = "/cs/create-last-activity")
|
|
|
853 |
public String createlastActivity(HttpServletRequest request, @RequestParam(name = "ticketId") int ticketId,
|
|
|
854 |
@RequestParam(name = "lastactivity") ActivityType lastActivity, Model model) throws Exception {
|
|
|
855 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
856 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
857 |
Activity activity = new Activity();
|
|
|
858 |
String subject = String.format(ACTIVITY_SUBJECT, ticket.getId());
|
|
|
859 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
860 |
ticket.setLastActivity(lastActivity);
|
|
|
861 |
String to = retailerService.getFofoRetailer(ticket.getFofoId()).getEmail();
|
| 24699 |
govind |
862 |
String message = String.format(PARTNER_RESOLVED_TICKET_MAIL, ticketId, "REOPEN");
|
| 24620 |
govind |
863 |
activity.setMessage(message);
|
|
|
864 |
activity.setCreatedBy(authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getId());
|
|
|
865 |
activity.setTicketId(ticketId);
|
|
|
866 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
867 |
activity.setType(ActivityType.COMMUNICATION_OUT);
|
| 24621 |
govind |
868 |
this.activityRelatedMail(to, null, subject, message);
|
| 24620 |
govind |
869 |
} else {
|
|
|
870 |
if (ActivityType.RESOLVED_ACCEPTED == lastActivity) {
|
|
|
871 |
ticket.setLastActivity(lastActivity);
|
|
|
872 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
| 27139 |
amit.gupta |
873 |
activity.setMessage(ActivityType.RESOLVED_ACCEPTED.toString());
|
| 24620 |
govind |
874 |
activity.setCreatedBy(0);
|
|
|
875 |
activity.setTicketId(ticketId);
|
|
|
876 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
|
|
877 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
878 |
} else {
|
| 24699 |
govind |
879 |
String message = String.format(INTERNAL_REOPEN_MAIL, ticketId,
|
|
|
880 |
retailerService.getFofoRetailer(loginDetails.getFofoId()).getBusinessName());
|
| 24620 |
govind |
881 |
String to = authRepository.selectById(ticket.getL1AuthUser()).getEmailId();
|
| 27270 |
tejbeer |
882 |
String[] ccTo = authRepository
|
|
|
883 |
.selectAllAuthUserByIds(Arrays.asList(ticket.getL2AuthUser(), ticket.getL3AuthUser(),
|
|
|
884 |
ticket.getL4AuthUser(), ticket.getL5AuthUser()))
|
|
|
885 |
.stream().map(x -> x.getEmailId()).toArray(String[]::new);
|
| 24620 |
govind |
886 |
ticket.setLastActivity(lastActivity);
|
| 24638 |
govind |
887 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
888 |
ticketAssignedRepository.deleteByTicketId(ticketId);
|
| 24699 |
govind |
889 |
TicketAssigned ticketAssigned = new TicketAssigned();
|
| 24638 |
govind |
890 |
ticketAssigned.setAssineeId(ticket.getL1AuthUser());
|
|
|
891 |
ticketAssigned.setTicketId(ticketId);
|
|
|
892 |
ticketAssignedRepository.persist(ticketAssigned);
|
| 24620 |
govind |
893 |
activity.setMessage(INTERNAL_REOPEN_ACTIVITY_MESSAGE);
|
|
|
894 |
activity.setCreatedBy(0);
|
|
|
895 |
activity.setTicketId(ticketId);
|
|
|
896 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
|
|
897 |
activity.setCreateTimestamp(LocalDateTime.now());
|
| 27139 |
amit.gupta |
898 |
this.activityRelatedMail(to, ccTo, subject, message);
|
| 24699 |
govind |
899 |
this.activityRelatedMail(retailerService.getFofoRetailer(loginDetails.getFofoId()).getEmail(), null,
|
|
|
900 |
subject, String.format(PARTNER_REOPEN, ticketId));
|
| 24620 |
govind |
901 |
}
|
|
|
902 |
|
|
|
903 |
}
|
|
|
904 |
activityRepository.persist(activity);
|
|
|
905 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
906 |
return "response";
|
|
|
907 |
}
|
|
|
908 |
|
| 24417 |
govind |
909 |
}
|