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