| 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;
|
| 32812 |
shampa |
5 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 24620 |
govind |
6 |
import com.spice.profitmandi.common.util.Utils;
|
| 24417 |
govind |
7 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 27690 |
amit.gupta |
8 |
import com.spice.profitmandi.dao.entity.cs.*;
|
| 35626 |
amit |
9 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 27270 |
tejbeer |
10 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
| 35626 |
amit |
11 |
import com.spice.profitmandi.dao.entity.cs.TicketReadStatus.UserType;
|
| 24417 |
govind |
12 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
|
|
13 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 24699 |
govind |
14 |
import com.spice.profitmandi.dao.enumuration.cs.TicketStatus;
|
| 25570 |
tejbeer |
15 |
import com.spice.profitmandi.dao.model.CreatePositionModel;
|
| 24417 |
govind |
16 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 27690 |
amit.gupta |
17 |
import com.spice.profitmandi.dao.repository.cs.*;
|
| 27270 |
tejbeer |
18 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| 25570 |
tejbeer |
19 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24417 |
govind |
20 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
|
|
21 |
import com.spice.profitmandi.service.user.RetailerService;
|
|
|
22 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
23 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
24 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 27690 |
amit.gupta |
25 |
import org.apache.logging.log4j.LogManager;
|
|
|
26 |
import org.apache.logging.log4j.Logger;
|
|
|
27 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
28 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
29 |
import org.springframework.stereotype.Controller;
|
|
|
30 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
31 |
import org.springframework.ui.Model;
|
|
|
32 |
import org.springframework.web.bind.annotation.*;
|
| 24417 |
govind |
33 |
|
| 27690 |
amit.gupta |
34 |
import javax.servlet.http.HttpServletRequest;
|
| 35571 |
amit |
35 |
import javax.swing.SortOrder;
|
| 27690 |
amit.gupta |
36 |
import java.time.LocalDateTime;
|
|
|
37 |
import java.util.*;
|
|
|
38 |
import java.util.stream.Collectors;
|
|
|
39 |
|
| 24417 |
govind |
40 |
@Controller
|
|
|
41 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
42 |
public class CsController {
|
|
|
43 |
|
| 31762 |
tejbeer |
44 |
private static final Logger LOGGER = LogManager.getLogger(CsController.class);
|
|
|
45 |
private static final String ACTIVITY_SUBJECT = "Message related ticketId#%s";
|
|
|
46 |
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";
|
|
|
47 |
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";
|
|
|
48 |
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";
|
|
|
49 |
private static final String INTERNAL_REOPEN_ACTIVITY_MESSAGE = "Hi,My ticket is not resolved yet,so I have reopened it";
|
| 24699 |
govind |
50 |
|
| 31762 |
tejbeer |
51 |
@Autowired
|
|
|
52 |
JavaMailSender mailSender;
|
| 24620 |
govind |
53 |
|
| 31762 |
tejbeer |
54 |
@Autowired
|
|
|
55 |
private CsService csService;
|
| 24417 |
govind |
56 |
|
| 31762 |
tejbeer |
57 |
@Autowired
|
|
|
58 |
private CookiesProcessor cookiesProcessor;
|
| 24417 |
govind |
59 |
|
| 31762 |
tejbeer |
60 |
@Autowired
|
|
|
61 |
private TicketCategoryRepository ticketCategoryRepository;
|
| 24417 |
govind |
62 |
|
| 31762 |
tejbeer |
63 |
@Autowired
|
|
|
64 |
private TicketSubCategoryRepository ticketSubCategoryRepository;
|
| 24417 |
govind |
65 |
|
| 31762 |
tejbeer |
66 |
@Autowired
|
|
|
67 |
private RegionRepository regionRepository;
|
| 24417 |
govind |
68 |
|
| 31762 |
tejbeer |
69 |
@Autowired
|
|
|
70 |
private RetailerService retailerService;
|
| 24417 |
govind |
71 |
|
| 31762 |
tejbeer |
72 |
@Autowired
|
|
|
73 |
private MVCResponseSender mvcResponseSender;
|
| 24417 |
govind |
74 |
|
| 31762 |
tejbeer |
75 |
@Autowired
|
|
|
76 |
private AuthRepository authRepository;
|
| 24417 |
govind |
77 |
|
| 31762 |
tejbeer |
78 |
@Autowired
|
|
|
79 |
private PositionRepository positionRepository;
|
| 24417 |
govind |
80 |
|
| 31762 |
tejbeer |
81 |
@Autowired
|
|
|
82 |
private TicketRepository ticketRepository;
|
| 24417 |
govind |
83 |
|
| 31762 |
tejbeer |
84 |
@Autowired
|
|
|
85 |
private RoleManager roleManager;
|
| 24417 |
govind |
86 |
|
| 31762 |
tejbeer |
87 |
@Autowired
|
|
|
88 |
private ActivityRepository activityRepository;
|
| 24417 |
govind |
89 |
|
| 31762 |
tejbeer |
90 |
@Autowired
|
|
|
91 |
private ActivityAttachmentRepository activityAttachmentRepository;
|
| 27270 |
tejbeer |
92 |
|
| 31762 |
tejbeer |
93 |
@Autowired
|
|
|
94 |
private TicketAssignedRepository ticketAssignedRepository;
|
| 24569 |
govind |
95 |
|
| 31762 |
tejbeer |
96 |
@Autowired
|
|
|
97 |
private PartnerRegionRepository partnerRegionRepository;
|
| 24500 |
govind |
98 |
|
| 31762 |
tejbeer |
99 |
@Autowired
|
| 32493 |
amit.gupta |
100 |
PartnerPositionRepository partnerPositionRepository;
|
| 25570 |
tejbeer |
101 |
|
| 31762 |
tejbeer |
102 |
@Autowired
|
|
|
103 |
FofoStoreRepository fofoStoreRepository;
|
| 25570 |
tejbeer |
104 |
|
| 31762 |
tejbeer |
105 |
@Autowired
|
|
|
106 |
DocumentRepository documentRepository;
|
| 27270 |
tejbeer |
107 |
|
| 31762 |
tejbeer |
108 |
@GetMapping(value = "/cs/createCategory")
|
|
|
109 |
public String getCreateCategory(HttpServletRequest request, Model model) {
|
|
|
110 |
List<TicketCategory> ticketCategories = ticketCategoryRepository.selectAll();
|
|
|
111 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
112 |
return "create-ticket-category";
|
|
|
113 |
}
|
| 24417 |
govind |
114 |
|
| 31762 |
tejbeer |
115 |
@PostMapping(value = "/cs/createCategory")
|
| 33081 |
ranu |
116 |
public String createCategory(HttpServletRequest request,
|
|
|
117 |
@RequestParam(name = "name") String name,
|
|
|
118 |
@RequestParam(name = "categoryType") int categoryType,
|
|
|
119 |
@RequestParam(name = "description") String description,
|
|
|
120 |
Model model) throws ProfitMandiBusinessException {
|
| 31762 |
tejbeer |
121 |
TicketCategory ticketCategory = ticketCategoryRepository.selectByName(name);
|
|
|
122 |
if (ticketCategory != null) {
|
|
|
123 |
throw new ProfitMandiBusinessException("name", name, "already exists!");
|
|
|
124 |
}
|
| 33081 |
ranu |
125 |
|
| 31762 |
tejbeer |
126 |
ticketCategory = new TicketCategory();
|
|
|
127 |
ticketCategory.setName(name);
|
|
|
128 |
ticketCategory.setDescription(description);
|
| 33081 |
ranu |
129 |
|
|
|
130 |
ticketCategory.setCategoryType(categoryType == 1);
|
| 31762 |
tejbeer |
131 |
ticketCategoryRepository.persist(ticketCategory);
|
|
|
132 |
return "create-ticket-category";
|
|
|
133 |
}
|
| 24417 |
govind |
134 |
|
| 33081 |
ranu |
135 |
|
| 31762 |
tejbeer |
136 |
@GetMapping(value = "/cs/createSubCategory")
|
|
|
137 |
public String getCreateSubCategory(HttpServletRequest request, Model model) {
|
|
|
138 |
List<TicketCategory> ticketCategories = ticketCategoryRepository.selectAll();
|
|
|
139 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
140 |
return "create-ticket-sub-category";
|
|
|
141 |
}
|
| 24417 |
govind |
142 |
|
| 31762 |
tejbeer |
143 |
@GetMapping(value = "/cs/getSubCategoryByCategoryId")
|
|
|
144 |
public String getSubCategoryByCategoryId(HttpServletRequest request, @RequestParam(name = "ticketCategoryId", defaultValue = "") int ticketCategoryId, Model model) {
|
|
|
145 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll(ticketCategoryId);
|
|
|
146 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(ticketCategoryId);
|
| 33081 |
ranu |
147 |
LOGGER.info("ticketSubCategories {}", ticketSubCategories);
|
|
|
148 |
LOGGER.info("ticketCategory {}", ticketCategory);
|
| 31762 |
tejbeer |
149 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
|
|
150 |
model.addAttribute("ticketCategory", ticketCategory);
|
|
|
151 |
return "ticket-sub-category";
|
|
|
152 |
}
|
| 24417 |
govind |
153 |
|
| 31762 |
tejbeer |
154 |
@PostMapping(value = "/cs/createSubCategory")
|
|
|
155 |
public String createSubCategory(HttpServletRequest request, @RequestParam(name = "categoryId", defaultValue = "0") int categoryId, @RequestParam(name = "name") String name, @RequestParam(name = "description") String description, Model model) throws ProfitMandiBusinessException {
|
| 24417 |
govind |
156 |
|
| 31762 |
tejbeer |
157 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectTicketSubCategory(categoryId, name);
|
|
|
158 |
if (ticketSubCategory != null) {
|
|
|
159 |
throw new ProfitMandiBusinessException("name & categoryId", name + " " + categoryId, "already exists!");
|
|
|
160 |
}
|
| 24417 |
govind |
161 |
|
| 31762 |
tejbeer |
162 |
ticketSubCategory = new TicketSubCategory();
|
|
|
163 |
ticketSubCategory.setCategoryId(categoryId);
|
|
|
164 |
ticketSubCategory.setName(name);
|
|
|
165 |
ticketSubCategory.setDescription(description);
|
|
|
166 |
ticketSubCategoryRepository.persist(ticketSubCategory);
|
|
|
167 |
return "create-ticket-sub-category";
|
|
|
168 |
}
|
| 24417 |
govind |
169 |
|
| 31762 |
tejbeer |
170 |
@GetMapping(value = "/cs/createRegion")
|
|
|
171 |
public String createRegion(HttpServletRequest request, Model model) {
|
|
|
172 |
List<Region> regions = regionRepository.selectAll();
|
|
|
173 |
model.addAttribute("regions", regions);
|
|
|
174 |
return "create-region";
|
|
|
175 |
}
|
| 24417 |
govind |
176 |
|
| 31762 |
tejbeer |
177 |
@PostMapping(value = "/cs/createRegion")
|
|
|
178 |
public String createRegion(HttpServletRequest request, @RequestParam(name = "name") String name, @RequestParam(name = "description") String description, Model model) throws Exception {
|
|
|
179 |
Region region = regionRepository.selectByName(name);
|
|
|
180 |
if (region != null) {
|
|
|
181 |
throw new ProfitMandiBusinessException("name", name, "already exists!");
|
|
|
182 |
}
|
|
|
183 |
region = new Region();
|
|
|
184 |
region.setName(name);
|
|
|
185 |
region.setDescription(description);
|
|
|
186 |
regionRepository.persist(region);
|
|
|
187 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
188 |
return "response";
|
|
|
189 |
}
|
| 24417 |
govind |
190 |
|
| 31762 |
tejbeer |
191 |
@GetMapping(value = "/cs/getPartners")
|
| 33244 |
ranu |
192 |
public String getPartners(HttpServletRequest request, @RequestParam(name = "regionId", defaultValue = "0") int regionId, Model model) throws ProfitMandiBusinessException {
|
| 31762 |
tejbeer |
193 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
194 |
List<Integer> addedfofoIds = partnerRegionRepository.selectByRegionId(regionId).stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| 30426 |
tejbeer |
195 |
|
| 31762 |
tejbeer |
196 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
197 |
Map<Integer, CustomRetailer> fofoRetailers = fofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
198 |
model.addAttribute("fofoRetailers", fofoRetailers);
|
|
|
199 |
model.addAttribute("addedfofoIds", addedfofoIds);
|
|
|
200 |
return "added-region-partners";
|
|
|
201 |
}
|
| 24569 |
govind |
202 |
|
| 31762 |
tejbeer |
203 |
@GetMapping(value = "/cs/getPartnersByRegion")
|
| 33244 |
ranu |
204 |
public String getPartnersByRegion(HttpServletRequest request, @RequestParam(name = "regionId", defaultValue = "0") int regionId, Model model) throws ProfitMandiBusinessException {
|
| 31762 |
tejbeer |
205 |
List<Integer> fofoIds = null;
|
|
|
206 |
fofoIds = partnerRegionRepository.selectByRegionId(regionId).stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| 25570 |
tejbeer |
207 |
|
| 31762 |
tejbeer |
208 |
if (fofoIds.contains(0)) {
|
|
|
209 |
fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).collect(Collectors.toList()).stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 25570 |
tejbeer |
210 |
|
| 31762 |
tejbeer |
211 |
}
|
|
|
212 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 25570 |
tejbeer |
213 |
|
| 31762 |
tejbeer |
214 |
Map<Integer, CustomRetailer> fofoRetailers = fofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
215 |
model.addAttribute("fofoRetailers", fofoRetailers);
|
|
|
216 |
return "added-subregion-partners";
|
|
|
217 |
}
|
| 25570 |
tejbeer |
218 |
|
| 31762 |
tejbeer |
219 |
@GetMapping(value = "/cs/createPartnerRegion")
|
|
|
220 |
public String createPartnerRegion(HttpServletRequest request, Model model) {
|
|
|
221 |
List<Region> regions = regionRepository.selectAll();
|
|
|
222 |
model.addAttribute("regions", regions);
|
|
|
223 |
return "create-partner-region";
|
|
|
224 |
}
|
| 24417 |
govind |
225 |
|
| 31762 |
tejbeer |
226 |
@PostMapping(value = "/cs/createPartnerRegion")
|
|
|
227 |
public String createPartnerRegion(HttpServletRequest request, @RequestParam(name = "regionId") int regionId, @RequestBody List<Integer> selectedFofoIds, Model model) throws Exception {
|
|
|
228 |
partnerRegionRepository.delete(regionId);
|
|
|
229 |
LOGGER.info("successfully removed");
|
|
|
230 |
LOGGER.info(selectedFofoIds.size());
|
|
|
231 |
csService.addPartnerToRegion(regionId, selectedFofoIds);
|
|
|
232 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
233 |
return "response";
|
|
|
234 |
}
|
| 24417 |
govind |
235 |
|
| 31762 |
tejbeer |
236 |
@GetMapping(value = "/cs/getPosition")
|
| 33244 |
ranu |
237 |
public String getPosition(HttpServletRequest request, @RequestParam int positionId, Model model) throws ProfitMandiBusinessException {
|
| 27410 |
tejbeer |
238 |
|
| 31762 |
tejbeer |
239 |
Position position = positionRepository.selectById(positionId);
|
| 27410 |
tejbeer |
240 |
|
| 31762 |
tejbeer |
241 |
List<CustomRetailer> positionIdCustomRetailer = csService.getPositionCustomRetailerMap(Arrays.asList(position)).get(position.getId());
|
| 27410 |
tejbeer |
242 |
|
| 31762 |
tejbeer |
243 |
Map<Integer, CustomRetailer> regionRetailerMap = csService.getRegionPartners(Arrays.asList(position)).get(position.getRegionId()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 27410 |
tejbeer |
244 |
|
| 31762 |
tejbeer |
245 |
model.addAttribute("position", position);
|
|
|
246 |
model.addAttribute("regionRetailerMap", regionRetailerMap);
|
|
|
247 |
model.addAttribute("positionIdCustomRetailer", positionIdCustomRetailer);
|
| 27410 |
tejbeer |
248 |
|
| 31762 |
tejbeer |
249 |
return "position-partner";
|
|
|
250 |
}
|
| 27410 |
tejbeer |
251 |
|
| 31762 |
tejbeer |
252 |
@GetMapping(value = "/cs/createPosition")
|
|
|
253 |
public String createPosition(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) {
|
|
|
254 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
|
|
255 |
List<TicketCategory> ticketCategories = ticketCategoryRepository.selectAll();
|
|
|
256 |
List<Region> regions = regionRepository.selectAll();
|
|
|
257 |
model.addAttribute("escalationTypes", EscalationType.values());
|
|
|
258 |
model.addAttribute("authUsers", authUsers);
|
|
|
259 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
260 |
model.addAttribute("regions", regions);
|
| 24500 |
govind |
261 |
|
| 31762 |
tejbeer |
262 |
List<Position> positions = positionRepository.selectAllPosition();
|
|
|
263 |
LOGGER.info("positions" + positions);
|
| 30426 |
tejbeer |
264 |
|
| 31762 |
tejbeer |
265 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = csService.getAuthUserIdAndAuthUserMapUsingPositions(positions);
|
|
|
266 |
Map<Integer, TicketCategory> categoryIdAndCategoryMap = csService.getCategoryIdAndCategoryUsingPositions(positions);
|
|
|
267 |
Map<Integer, Region> regionIdAndRegionMap = csService.getRegionIdAndRegionMap(positions);
|
| 25570 |
tejbeer |
268 |
|
| 27410 |
tejbeer |
269 |
// Map<Integer, List<CustomRetailer>> positionIdAndpartnerRegionMap = csService
|
|
|
270 |
// .getpositionIdAndpartnerRegionMap(positions);
|
| 25570 |
tejbeer |
271 |
|
| 27410 |
tejbeer |
272 |
// Map<Integer, List<CustomRetailer>> addedpositionIdAndCustomRetailerMap = csService
|
|
|
273 |
// .getPositionCustomRetailerMap(positions);
|
|
|
274 |
// LOGGER.info("fofoIdAndCustomRetailerMap" + addedpositionIdAndCustomRetailerMap);
|
| 24500 |
govind |
275 |
|
| 31762 |
tejbeer |
276 |
model.addAttribute("start", offset + 1);
|
| 30426 |
tejbeer |
277 |
|
| 31762 |
tejbeer |
278 |
model.addAttribute("positions", positions);
|
|
|
279 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
280 |
model.addAttribute("categoryIdAndCategoryMap", categoryIdAndCategoryMap);
|
|
|
281 |
model.addAttribute("regionIdAndRegionMap", regionIdAndRegionMap);
|
|
|
282 |
// model.addAttribute("positionIdAndCustomRetailerMap",
|
|
|
283 |
// addedpositionIdAndCustomRetailerMap);
|
|
|
284 |
// model.addAttribute("positionIdAndpartnerRegionMap",
|
| 27410 |
tejbeer |
285 |
// positionIdAndpartnerRegionMap);
|
| 25570 |
tejbeer |
286 |
|
| 31762 |
tejbeer |
287 |
return "create-position";
|
|
|
288 |
}
|
| 24500 |
govind |
289 |
|
| 31762 |
tejbeer |
290 |
@GetMapping(value = "/cs/position-paginated")
|
|
|
291 |
public String positionPaginated(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) {
|
| 24500 |
govind |
292 |
|
| 31762 |
tejbeer |
293 |
List<Position> positions = positionRepository.selectAll(offset, limit);
|
|
|
294 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = csService.getAuthUserIdAndAuthUserMapUsingPositions(positions);
|
|
|
295 |
Map<Integer, TicketCategory> categoryIdAndCategoryMap = csService.getCategoryIdAndCategoryUsingPositions(positions);
|
|
|
296 |
Map<Integer, Region> regionIdAndRegionMap = csService.getRegionIdAndRegionMap(positions);
|
|
|
297 |
/*
|
|
|
298 |
* Map<Integer, List<CustomRetailer>> positionIdAndpartnerRegionMap = csService
|
|
|
299 |
* .getpositionIdAndpartnerRegionMap(positions);
|
|
|
300 |
*
|
|
|
301 |
* Map<Integer, List<CustomRetailer>> addedpositionIdAndCustomRetailerMap =
|
|
|
302 |
* csService .getPositionCustomRetailerMap(positions);
|
|
|
303 |
*/
|
| 25570 |
tejbeer |
304 |
|
| 31762 |
tejbeer |
305 |
model.addAttribute("positions", positions);
|
|
|
306 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
307 |
model.addAttribute("categoryIdAndCategoryMap", categoryIdAndCategoryMap);
|
|
|
308 |
model.addAttribute("regionIdAndRegionMap", regionIdAndRegionMap);
|
|
|
309 |
// model.addAttribute("positionIdAndCustomRetailerMap",
|
|
|
310 |
// addedpositionIdAndCustomRetailerMap);
|
|
|
311 |
// model.addAttribute("positionIdAndpartnerRegionMap",
|
|
|
312 |
// positionIdAndpartnerRegionMap);
|
| 25570 |
tejbeer |
313 |
|
| 31762 |
tejbeer |
314 |
return "position-paginated";
|
|
|
315 |
}
|
| 24417 |
govind |
316 |
|
| 31762 |
tejbeer |
317 |
@PostMapping(value = "/cs/createPosition")
|
|
|
318 |
public String createPosition(HttpServletRequest request, @RequestBody CreatePositionModel createPositionModel, Model model) throws Exception {
|
| 24417 |
govind |
319 |
|
| 35570 |
amit |
320 |
LOGGER.info("partnerPosition" + createPositionModel.isTicketAssigned());
|
| 25570 |
tejbeer |
321 |
|
| 35570 |
amit |
322 |
// Validate authUserId exists
|
|
|
323 |
int authUserId = createPositionModel.getAuthUserId();
|
|
|
324 |
if (authUserId <= 0 || authRepository.selectById(authUserId) == null) {
|
|
|
325 |
throw new ProfitMandiBusinessException("Position", authUserId, "Invalid authUserId");
|
|
|
326 |
}
|
|
|
327 |
|
|
|
328 |
// Validate categoryId exists (0 means "All Categories")
|
|
|
329 |
int categoryId = createPositionModel.getCategoryId();
|
|
|
330 |
if (categoryId > 0 && ticketCategoryRepository.selectById(categoryId) == null) {
|
|
|
331 |
throw new ProfitMandiBusinessException("Position", categoryId, "Invalid categoryId");
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
// Validate regionId exists (0 or 5 typically means "All Partners/Regions")
|
|
|
335 |
int regionId = createPositionModel.getRegionId();
|
|
|
336 |
if (regionId > 0 && regionId != 5 && regionRepository.selectById(regionId) == null) {
|
|
|
337 |
throw new ProfitMandiBusinessException("Position", regionId, "Invalid regionId");
|
|
|
338 |
}
|
|
|
339 |
|
| 35589 |
amit |
340 |
// Validate fofoIds exist (0 means "All Partners")
|
| 35570 |
amit |
341 |
List<Integer> fofoIds = createPositionModel.getFofoIds();
|
| 35590 |
amit |
342 |
if (fofoIds == null || fofoIds.isEmpty()) {
|
|
|
343 |
throw new ProfitMandiBusinessException("Position", 0, "At least one partner must be specified");
|
|
|
344 |
}
|
|
|
345 |
boolean hasAllPartners = fofoIds.contains(0);
|
|
|
346 |
if (hasAllPartners && fofoIds.size() > 1) {
|
|
|
347 |
throw new ProfitMandiBusinessException("Position", 0, "Cannot mix 'All Partners' (0) with specific partner IDs");
|
|
|
348 |
}
|
|
|
349 |
if (!hasAllPartners) {
|
|
|
350 |
Map<Integer, CustomRetailer> validRetailers = retailerService.getFofoRetailers(false);
|
|
|
351 |
for (int fofoId : fofoIds) {
|
|
|
352 |
if (!validRetailers.containsKey(fofoId)) {
|
|
|
353 |
throw new ProfitMandiBusinessException("Position", fofoId, "Invalid fofoId");
|
| 35570 |
amit |
354 |
}
|
|
|
355 |
}
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
Position position = positionRepository.selectPosition(authUserId, categoryId, regionId, createPositionModel.getEscalationType());
|
| 31762 |
tejbeer |
359 |
if (position == null) {
|
|
|
360 |
position = new Position();
|
| 35570 |
amit |
361 |
position.setAuthUserId(authUserId);
|
|
|
362 |
position.setCategoryId(categoryId);
|
| 31762 |
tejbeer |
363 |
position.setEscalationType(createPositionModel.getEscalationType());
|
| 35570 |
amit |
364 |
position.setRegionId(regionId);
|
| 31762 |
tejbeer |
365 |
position.setCreateTimestamp(LocalDateTime.now());
|
|
|
366 |
position.setTicketAssignee(createPositionModel.isTicketAssigned());
|
|
|
367 |
positionRepository.persist(position);
|
| 25570 |
tejbeer |
368 |
|
| 35570 |
amit |
369 |
if (fofoIds != null) {
|
|
|
370 |
for (int fofoId : fofoIds) {
|
|
|
371 |
PartnerPosition partnerPosition = new PartnerPosition();
|
|
|
372 |
partnerPosition.setFofoId(fofoId);
|
|
|
373 |
partnerPosition.setRegionId(regionId);
|
|
|
374 |
partnerPosition.setPositionId(position.getId());
|
|
|
375 |
partnerPositionRepository.persist(partnerPosition);
|
|
|
376 |
LOGGER.info("partnerPosition" + partnerPosition);
|
|
|
377 |
}
|
| 31762 |
tejbeer |
378 |
}
|
| 24417 |
govind |
379 |
|
| 31762 |
tejbeer |
380 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
381 |
} else {
|
| 35570 |
amit |
382 |
throw new ProfitMandiBusinessException("Position", authUserId, "already exists!");
|
| 31762 |
tejbeer |
383 |
}
|
|
|
384 |
return "response";
|
|
|
385 |
}
|
| 25570 |
tejbeer |
386 |
|
| 31762 |
tejbeer |
387 |
@PostMapping(value = "/cs/updatePartnerPosition")
|
|
|
388 |
public String updatePartnerPosition(HttpServletRequest request, @RequestParam(name = "regionId") int regionId, @RequestBody List<Integer> selectedFofoIds, @RequestParam(name = "positionId") int positionId, Model model) throws Exception {
|
| 25570 |
tejbeer |
389 |
|
| 35571 |
amit |
390 |
// Validate positionId exists
|
|
|
391 |
Position position = positionRepository.selectById(positionId);
|
|
|
392 |
if (position == null) {
|
|
|
393 |
throw new ProfitMandiBusinessException("Position", positionId, "Position not found");
|
|
|
394 |
}
|
|
|
395 |
|
|
|
396 |
// Validate regionId exists (0 or 5 typically means "All Partners/Regions")
|
|
|
397 |
if (regionId > 0 && regionId != 5 && regionRepository.selectById(regionId) == null) {
|
|
|
398 |
throw new ProfitMandiBusinessException("Position", regionId, "Invalid regionId");
|
|
|
399 |
}
|
|
|
400 |
|
| 35589 |
amit |
401 |
// Validate fofoIds exist (0 means "All Partners")
|
| 35590 |
amit |
402 |
if (selectedFofoIds == null || selectedFofoIds.isEmpty()) {
|
|
|
403 |
throw new ProfitMandiBusinessException("Position", 0, "At least one partner must be specified");
|
|
|
404 |
}
|
|
|
405 |
boolean hasAllPartners = selectedFofoIds.contains(0);
|
|
|
406 |
if (hasAllPartners && selectedFofoIds.size() > 1) {
|
|
|
407 |
throw new ProfitMandiBusinessException("Position", 0, "Cannot mix 'All Partners' (0) with specific partner IDs");
|
|
|
408 |
}
|
|
|
409 |
if (!hasAllPartners) {
|
| 35607 |
amit |
410 |
// Use direct database query instead of cached retailerService to include newly added partners
|
|
|
411 |
Set<Integer> validFofoIds = fofoStoreRepository.selectAll().stream()
|
|
|
412 |
.map(fs -> fs.getId())
|
|
|
413 |
.collect(Collectors.toSet());
|
| 35590 |
amit |
414 |
for (int fofoId : selectedFofoIds) {
|
| 35607 |
amit |
415 |
if (!validFofoIds.contains(fofoId)) {
|
| 35590 |
amit |
416 |
throw new ProfitMandiBusinessException("Position", fofoId, "Invalid fofoId");
|
| 35571 |
amit |
417 |
}
|
|
|
418 |
}
|
|
|
419 |
}
|
|
|
420 |
|
| 32493 |
amit.gupta |
421 |
partnerPositionRepository.delete(positionId);
|
| 35571 |
amit |
422 |
if (selectedFofoIds != null) {
|
|
|
423 |
for (int fofoId : selectedFofoIds) {
|
|
|
424 |
PartnerPosition partnerPosition = new PartnerPosition();
|
|
|
425 |
partnerPosition.setFofoId(fofoId);
|
|
|
426 |
partnerPosition.setRegionId(regionId);
|
|
|
427 |
partnerPosition.setPositionId(positionId);
|
|
|
428 |
partnerPositionRepository.persist(partnerPosition);
|
|
|
429 |
}
|
| 31762 |
tejbeer |
430 |
}
|
| 25570 |
tejbeer |
431 |
|
| 31762 |
tejbeer |
432 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 25570 |
tejbeer |
433 |
|
| 31762 |
tejbeer |
434 |
return "response";
|
|
|
435 |
}
|
| 24417 |
govind |
436 |
|
| 31762 |
tejbeer |
437 |
@GetMapping(value = "/cs/createTicket")
|
|
|
438 |
public String createTicket(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
439 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 35594 |
amit |
440 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
441 |
boolean isCrmUser = false;
|
|
|
442 |
|
| 31762 |
tejbeer |
443 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
| 35594 |
amit |
444 |
|
|
|
445 |
if (isAdmin) {
|
|
|
446 |
AuthUser currentAuthUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
447 |
isCrmUser = positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
448 |
|
|
|
449 |
// CRM users should not see Sales and RBM categories
|
|
|
450 |
if (isCrmUser) {
|
|
|
451 |
ticketCategories = ticketCategories.stream()
|
|
|
452 |
.filter(tc -> tc.getId() != ProfitMandiConstants.TICKET_CATEGORY_SALES
|
|
|
453 |
&& tc.getId() != ProfitMandiConstants.TICKET_CATEGORY_RBM)
|
|
|
454 |
.collect(Collectors.toList());
|
|
|
455 |
}
|
| 35626 |
amit |
456 |
} else {
|
|
|
457 |
// For partners/customers: hide categories where ALL subcategories are invisible
|
|
|
458 |
ticketCategories = ticketCategories.stream()
|
|
|
459 |
.filter(category -> {
|
|
|
460 |
List<TicketSubCategory> subs = ticketSubCategoryRepository.selectAll(category.getId());
|
|
|
461 |
// Keep category if at least one subcategory is visible
|
|
|
462 |
return subs.stream().anyMatch(TicketSubCategory::isVisibility);
|
|
|
463 |
})
|
|
|
464 |
.collect(Collectors.toList());
|
| 35594 |
amit |
465 |
}
|
|
|
466 |
|
|
|
467 |
model.addAttribute("roleType", isAdmin);
|
| 31762 |
tejbeer |
468 |
model.addAttribute("ticketCategories", ticketCategories);
|
| 35594 |
amit |
469 |
model.addAttribute("isCrmUser", isCrmUser);
|
| 31762 |
tejbeer |
470 |
return "create-ticket";
|
|
|
471 |
}
|
| 24417 |
govind |
472 |
|
| 31762 |
tejbeer |
473 |
@GetMapping(value = "/cs/getSubCategoriesByCategoryId")
|
| 35594 |
amit |
474 |
public String getSubCategoriesByCategoryId(HttpServletRequest request, @RequestParam(name = "categoryId", defaultValue = "0") int categoryId, Model model) throws ProfitMandiBusinessException {
|
|
|
475 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
476 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
477 |
boolean isCrmUser = false;
|
|
|
478 |
|
|
|
479 |
if (isAdmin) {
|
|
|
480 |
AuthUser currentAuthUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
481 |
isCrmUser = positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
482 |
}
|
|
|
483 |
|
| 31830 |
amit.gupta |
484 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAllVisible(categoryId);
|
| 35594 |
amit |
485 |
|
| 35617 |
amit |
486 |
// CRM users should not see invisible subcategories
|
| 35594 |
amit |
487 |
if (isCrmUser) {
|
|
|
488 |
ticketSubCategories = ticketSubCategories.stream()
|
| 35617 |
amit |
489 |
.filter(TicketSubCategory::isVisibility)
|
| 35594 |
amit |
490 |
.collect(Collectors.toList());
|
|
|
491 |
}
|
|
|
492 |
|
| 31762 |
tejbeer |
493 |
LOGGER.info(ticketSubCategories);
|
|
|
494 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
|
|
495 |
return "ticket-sub-categories";
|
|
|
496 |
}
|
| 24417 |
govind |
497 |
|
| 24791 |
govind |
498 |
|
| 31762 |
tejbeer |
499 |
@GetMapping(value = "/cs/getEscalationTypeByCategoryId")
|
|
|
500 |
public String getEscalationTypeByCategoryId(HttpServletRequest request, @RequestParam(name = "categoryId", defaultValue = "0") int categoryId, @RequestParam(name = "authId", defaultValue = "0") int authId, Model model) {
|
|
|
501 |
List<Position> positions = positionRepository.selectPositionbyCategoryIdAndAuthId(categoryId, authId);
|
|
|
502 |
List<EscalationType> escalationTypes = new ArrayList<>();
|
| 24791 |
govind |
503 |
|
| 31762 |
tejbeer |
504 |
if (!positions.isEmpty()) {
|
|
|
505 |
escalationTypes = positions.stream().map(x -> x.getEscalationType()).distinct().collect(Collectors.toList());
|
|
|
506 |
}
|
| 24620 |
govind |
507 |
|
| 31762 |
tejbeer |
508 |
LOGGER.info("escalationTypes {}", escalationTypes);
|
| 24500 |
govind |
509 |
|
| 31762 |
tejbeer |
510 |
model.addAttribute("escalationTypes", escalationTypes);
|
|
|
511 |
return "ticket-escalationtype";
|
|
|
512 |
}
|
| 24500 |
govind |
513 |
|
| 24824 |
govind |
514 |
|
| 31762 |
tejbeer |
515 |
@GetMapping(value = "/cs/getCategoriesByAuthId")
|
|
|
516 |
public String getCategoriesByAuthId(HttpServletRequest request, @RequestParam(name = "authId", defaultValue = "0") int authId, Model model) {
|
| 24824 |
govind |
517 |
|
| 24787 |
govind |
518 |
|
| 31762 |
tejbeer |
519 |
List<Position> positions = positionRepository.selectPositionByAuthId(authId);
|
| 24791 |
govind |
520 |
|
| 31762 |
tejbeer |
521 |
LOGGER.info("positions {}", positions);
|
| 24417 |
govind |
522 |
|
| 31762 |
tejbeer |
523 |
List<TicketCategory> ticketCategories = new ArrayList<TicketCategory>();
|
| 24417 |
govind |
524 |
|
| 31762 |
tejbeer |
525 |
if (!positions.isEmpty()) {
|
| 24417 |
govind |
526 |
|
| 31762 |
tejbeer |
527 |
List<Integer> categoryIds = positions.stream().map(x -> x.getCategoryId()).collect(Collectors.toList());
|
|
|
528 |
ticketCategories = ticketCategoryRepository.selectAll(categoryIds);
|
|
|
529 |
}
|
|
|
530 |
LOGGER.info("ticketCategories {}", ticketCategories);
|
|
|
531 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
532 |
return "ticket-categories";
|
|
|
533 |
}
|
| 27270 |
tejbeer |
534 |
|
| 31762 |
tejbeer |
535 |
@PostMapping(value = "/cs/createTicket")
|
|
|
536 |
public String createTicket(HttpServletRequest request, @RequestParam(name = "categoryId") int categoryId, @RequestParam(name = "subCategoryId") int subCategoryId, @RequestParam(name = "message") String message, Model model) throws Exception {
|
|
|
537 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
538 |
List<Ticket> tickets = ticketRepository.selectAllResolvedMarkedTicketByCreator(loginDetails.getFofoId());
|
|
|
539 |
if (tickets.size() > 3 || tickets.size() == 3) {
|
|
|
540 |
model.addAttribute("response1", mvcResponseSender.createResponseString(false));
|
|
|
541 |
} else {
|
|
|
542 |
csService.createTicket(loginDetails.getFofoId(), categoryId, subCategoryId, message);
|
|
|
543 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
544 |
}
|
|
|
545 |
return "response";
|
|
|
546 |
}
|
| 27270 |
tejbeer |
547 |
|
| 31762 |
tejbeer |
548 |
@GetMapping(value = "/cs/myticket")
|
| 35626 |
amit |
549 |
public String getTicket(HttpServletRequest request,
|
|
|
550 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
551 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
|
|
552 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
553 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
|
|
554 |
@RequestParam(name = "page", defaultValue = "0") int page,
|
|
|
555 |
@RequestParam(name = "pageSize", defaultValue = "25") int pageSize,
|
|
|
556 |
@RequestParam(name = "search", required = false) String searchText,
|
|
|
557 |
Model model) throws ProfitMandiBusinessException {
|
|
|
558 |
populateMyTicketModel(request, sortOrder, ticketStatus, ticketSearchType, searchTerm, page, pageSize, searchText, model);
|
|
|
559 |
return "ticket";
|
|
|
560 |
}
|
|
|
561 |
|
|
|
562 |
@GetMapping(value = "/cs/myticket-content")
|
|
|
563 |
public String getTicketContent(HttpServletRequest request,
|
|
|
564 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
565 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
|
|
566 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
567 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
|
|
568 |
@RequestParam(name = "page", defaultValue = "0") int page,
|
|
|
569 |
@RequestParam(name = "pageSize", defaultValue = "25") int pageSize,
|
|
|
570 |
@RequestParam(name = "search", required = false) String searchText,
|
|
|
571 |
Model model) throws ProfitMandiBusinessException {
|
|
|
572 |
populateMyTicketModel(request, sortOrder, ticketStatus, ticketSearchType, searchTerm, page, pageSize, searchText, model);
|
|
|
573 |
return "ticket-content";
|
|
|
574 |
}
|
|
|
575 |
|
|
|
576 |
private void populateMyTicketModel(HttpServletRequest request, SortOrder sortOrder, TicketStatus ticketStatus,
|
|
|
577 |
TicketSearchType ticketSearchType, int searchTerm, int page, int pageSize,
|
|
|
578 |
String searchText, Model model) throws ProfitMandiBusinessException {
|
| 31762 |
tejbeer |
579 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
580 |
List<Ticket> tickets = null;
|
|
|
581 |
List<TicketAssigned> ticketAssigneds = null;
|
| 35626 |
amit |
582 |
long totalRecords = 0;
|
| 31762 |
tejbeer |
583 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = null;
|
| 35569 |
amit |
584 |
boolean isAdmin = roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()));
|
|
|
585 |
AuthUser currentAuthUser = isAdmin ? authRepository.selectByEmailOrMobile(loginDetails.getEmailId()) : null;
|
|
|
586 |
|
| 35592 |
amit |
587 |
boolean isCrmUser = isAdmin && currentAuthUser != null && positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
| 35603 |
amit |
588 |
boolean isSalesUser = isAdmin && currentAuthUser != null && positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
589 |
boolean isRbmUser = isAdmin && currentAuthUser != null && positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_RBM);
|
| 35592 |
amit |
590 |
|
| 35626 |
amit |
591 |
List<Integer> userCategoryIds = isAdmin && currentAuthUser != null
|
|
|
592 |
? positionRepository.selectCategoryIdsByAuthUserId(currentAuthUser.getId())
|
|
|
593 |
: Collections.emptyList();
|
|
|
594 |
|
|
|
595 |
int offset = page * pageSize;
|
|
|
596 |
|
| 35569 |
amit |
597 |
if (isAdmin) {
|
|
|
598 |
int authUserId = currentAuthUser.getId();
|
| 35592 |
amit |
599 |
|
|
|
600 |
if (isCrmUser) {
|
| 35626 |
amit |
601 |
Optional<Boolean> resolvedOpt = ticketStatus.equals(TicketStatus.RESOLVED) ? Optional.empty() : Optional.of(TicketStatus.CLOSED.equals(ticketStatus));
|
|
|
602 |
tickets = ticketRepository.selectAllTicketsPaginated(
|
|
|
603 |
resolvedOpt, sortOrder, ticketSearchType, searchTerm, searchText,
|
|
|
604 |
userCategoryIds, offset, pageSize);
|
|
|
605 |
totalRecords = ticketRepository.selectAllTicketsPaginatedCount(
|
|
|
606 |
resolvedOpt, ticketSearchType, searchTerm, searchText, userCategoryIds);
|
| 31762 |
tejbeer |
607 |
} else {
|
| 35626 |
amit |
608 |
Optional<Boolean> resolvedOpt = ticketStatus.equals(TicketStatus.RESOLVED) ? Optional.empty() : Optional.of(TicketStatus.CLOSED.equals(ticketStatus));
|
|
|
609 |
tickets = ticketRepository.selectAllByAssigneePaginated(
|
|
|
610 |
authUserId, resolvedOpt, sortOrder, ticketSearchType, searchTerm, searchText,
|
|
|
611 |
offset, pageSize);
|
|
|
612 |
totalRecords = ticketRepository.selectAllByAssigneePaginatedCount(
|
|
|
613 |
authUserId, resolvedOpt, ticketSearchType, searchTerm, searchText);
|
| 31762 |
tejbeer |
614 |
}
|
| 35626 |
amit |
615 |
|
| 31762 |
tejbeer |
616 |
if (tickets.size() > 0) {
|
|
|
617 |
ticketAssigneds = ticketAssignedRepository.selectByTicketIds(tickets.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
|
|
618 |
authUserIdAndAuthUserMap = csService.getAuthUserIdAndAuthUserMap(ticketAssigneds);
|
|
|
619 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
620 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
|
|
621 |
}
|
| 24500 |
govind |
622 |
|
| 31762 |
tejbeer |
623 |
} else {
|
|
|
624 |
tickets = ticketRepository.selectAllByCreator(loginDetails.getFofoId(), Optional.of(TicketStatus.OPENED.equals(ticketStatus)), sortOrder);
|
| 35626 |
amit |
625 |
totalRecords = ticketRepository.selectAllCountByCreator(loginDetails.getFofoId(), Optional.of(TicketStatus.OPENED.equals(ticketStatus)));
|
| 31762 |
tejbeer |
626 |
}
|
|
|
627 |
authUserIdAndAuthUserMap = csService.getTicketIdAndAuthUserMapUsingTickets(tickets);
|
| 35571 |
amit |
628 |
if (authUserIdAndAuthUserMap == null) {
|
|
|
629 |
authUserIdAndAuthUserMap = new HashMap<>();
|
|
|
630 |
}
|
| 24620 |
govind |
631 |
|
| 35626 |
amit |
632 |
int totalPages = (int) Math.ceil((double) totalRecords / pageSize);
|
|
|
633 |
if (totalPages == 0) totalPages = 1;
|
|
|
634 |
int startRecord = totalRecords > 0 ? offset + 1 : 0;
|
|
|
635 |
int endRecord = (int) Math.min(offset + pageSize, totalRecords);
|
|
|
636 |
|
|
|
637 |
model.addAttribute("size", totalRecords);
|
|
|
638 |
model.addAttribute("totalRecords", totalRecords);
|
|
|
639 |
model.addAttribute("currentPage", page);
|
|
|
640 |
model.addAttribute("pageSize", pageSize);
|
|
|
641 |
model.addAttribute("totalPages", totalPages);
|
|
|
642 |
model.addAttribute("startRecord", startRecord);
|
|
|
643 |
model.addAttribute("endRecord", endRecord);
|
|
|
644 |
model.addAttribute("searchText", searchText != null ? searchText : "");
|
|
|
645 |
model.addAttribute("currentPageDisplay", page + 1);
|
|
|
646 |
model.addAttribute("prevPage", page - 1);
|
|
|
647 |
model.addAttribute("nextPage", page + 1);
|
|
|
648 |
model.addAttribute("lastPage", totalPages - 1);
|
|
|
649 |
|
| 35569 |
amit |
650 |
model.addAttribute("roleType", isAdmin);
|
|
|
651 |
model.addAttribute("isCrmUser", isCrmUser);
|
| 35603 |
amit |
652 |
model.addAttribute("isSalesUser", isSalesUser);
|
|
|
653 |
model.addAttribute("salesCategoryId", ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
654 |
model.addAttribute("isRbmUser", isRbmUser);
|
|
|
655 |
model.addAttribute("rbmCategoryId", ProfitMandiConstants.TICKET_CATEGORY_RBM);
|
| 35626 |
amit |
656 |
model.addAttribute("userCategoryIds", userCategoryIds);
|
| 24500 |
govind |
657 |
|
| 31762 |
tejbeer |
658 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
|
|
659 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
| 35571 |
amit |
660 |
if (subCategoryIdAndSubCategoryMap == null) {
|
|
|
661 |
subCategoryIdAndSubCategoryMap = new HashMap<>();
|
|
|
662 |
}
|
| 24747 |
govind |
663 |
|
| 31762 |
tejbeer |
664 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
| 35571 |
amit |
665 |
if (subCategoryIdAndCategoryMap == null) {
|
|
|
666 |
subCategoryIdAndCategoryMap = new HashMap<>();
|
|
|
667 |
}
|
| 27318 |
amit.gupta |
668 |
|
| 31762 |
tejbeer |
669 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 24500 |
govind |
670 |
|
| 35569 |
amit |
671 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
| 33864 |
ranu |
672 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
| 35569 |
amit |
673 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|
| 24500 |
govind |
674 |
|
| 31762 |
tejbeer |
675 |
if (!ticketIds.isEmpty()) {
|
| 35569 |
amit |
676 |
List<Activity> allActivities = activityRepository.selectAll(ticketIds);
|
|
|
677 |
activityMap = allActivities.stream().collect(Collectors.groupingBy(Activity::getTicketId));
|
|
|
678 |
activityMapWithActivityId = allActivities.stream().collect(Collectors.groupingBy(Activity::getId));
|
| 24787 |
govind |
679 |
|
| 35569 |
amit |
680 |
Set<Integer> activityCreatorIds = allActivities.stream()
|
|
|
681 |
.map(Activity::getCreatedBy)
|
|
|
682 |
.filter(id -> id > 0)
|
|
|
683 |
.collect(Collectors.toSet());
|
|
|
684 |
if (!activityCreatorIds.isEmpty()) {
|
|
|
685 |
authUserMap = authRepository.selectByIds(new ArrayList<>(activityCreatorIds))
|
|
|
686 |
.stream().collect(Collectors.toMap(AuthUser::getId, x -> x));
|
|
|
687 |
}
|
| 31762 |
tejbeer |
688 |
}
|
| 24787 |
govind |
689 |
|
| 35626 |
amit |
690 |
int currentUserId;
|
|
|
691 |
UserType currentUserType;
|
|
|
692 |
if (isAdmin) {
|
|
|
693 |
currentUserId = currentAuthUser.getId();
|
|
|
694 |
currentUserType = UserType.AUTH_USER;
|
|
|
695 |
} else {
|
|
|
696 |
currentUserId = loginDetails.getFofoId();
|
|
|
697 |
currentUserType = UserType.PARTNER;
|
|
|
698 |
}
|
|
|
699 |
Map<Integer, Boolean> unreadMap = csService.getUnreadStatusForTickets(tickets, currentUserId, currentUserType);
|
|
|
700 |
Map<Integer, Activity> lastActivityMap = csService.getLastActivitiesForTickets(ticketIds);
|
|
|
701 |
model.addAttribute("unreadMap", unreadMap);
|
|
|
702 |
model.addAttribute("lastActivityMap", lastActivityMap);
|
|
|
703 |
|
| 31762 |
tejbeer |
704 |
model.addAttribute("tickets", tickets);
|
|
|
705 |
model.addAttribute("resolved", ActivityType.RESOLVED);
|
|
|
706 |
model.addAttribute("resolved-accepted", ActivityType.RESOLVED_ACCEPTED);
|
|
|
707 |
model.addAttribute("resolved-rejected", ActivityType.RESOLVED_REJECTED);
|
|
|
708 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
709 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
| 27318 |
amit.gupta |
710 |
|
| 31762 |
tejbeer |
711 |
model.addAttribute("subCategoryIdAndCategoryMap", subCategoryIdAndCategoryMap);
|
|
|
712 |
model.addAttribute("activityMap", activityMap);
|
| 33864 |
ranu |
713 |
model.addAttribute("authUserMap", authUserMap);
|
|
|
714 |
model.addAttribute("activityMapWithActivityId", activityMapWithActivityId);
|
| 24500 |
govind |
715 |
|
| 31762 |
tejbeer |
716 |
model.addAttribute("ticketStatusValues", TicketStatus.values());
|
|
|
717 |
model.addAttribute("orderByValues", SortOrder.values());
|
|
|
718 |
model.addAttribute("selectedticketStatus", ticketStatus);
|
|
|
719 |
model.addAttribute("selectedorderby", sortOrder);
|
|
|
720 |
model.addAttribute("ticketSearchTypes", TicketSearchType.values());
|
|
|
721 |
model.addAttribute("ticketSearchType", ticketSearchType);
|
|
|
722 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
723 |
}
|
| 24500 |
govind |
724 |
|
| 27124 |
amit.gupta |
725 |
|
| 31762 |
tejbeer |
726 |
@GetMapping(value = "/cs/getActivities")
|
|
|
727 |
public String getActivity(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) throws Exception {
|
| 35592 |
amit |
728 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
729 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
730 |
|
|
|
731 |
if (ticket == null) {
|
|
|
732 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Ticket not found");
|
|
|
733 |
}
|
|
|
734 |
|
|
|
735 |
// Authorization check: verify user has access to this ticket
|
|
|
736 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
737 |
if (!isAdmin) {
|
|
|
738 |
// Partners can only view their own tickets
|
|
|
739 |
if (ticket.getFofoId() != loginDetails.getFofoId()) {
|
|
|
740 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "You do not have permission to view this ticket");
|
|
|
741 |
}
|
|
|
742 |
} else {
|
|
|
743 |
// Admins must be assigned to the ticket OR be CRM user OR be in the escalation chain
|
|
|
744 |
AuthUser currentAuthUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
745 |
boolean isCrmUser = positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
746 |
|
|
|
747 |
if (!isCrmUser) {
|
|
|
748 |
// Check if user is assigned or in escalation chain
|
|
|
749 |
List<TicketAssigned> assignments = ticketAssignedRepository.selectByTicketIds(Arrays.asList(ticketId));
|
|
|
750 |
boolean isAssigned = assignments.stream().anyMatch(ta -> ta.getAssineeId() == currentAuthUser.getId() || ta.getManagerId() == currentAuthUser.getId());
|
|
|
751 |
boolean isInEscalationChain = ticket.getL1AuthUser() == currentAuthUser.getId() ||
|
|
|
752 |
ticket.getL2AuthUser() == currentAuthUser.getId() ||
|
|
|
753 |
ticket.getL3AuthUser() == currentAuthUser.getId() ||
|
|
|
754 |
ticket.getL4AuthUser() == currentAuthUser.getId() ||
|
|
|
755 |
ticket.getL5AuthUser() == currentAuthUser.getId();
|
|
|
756 |
|
|
|
757 |
if (!isAssigned && !isInEscalationChain) {
|
|
|
758 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "You do not have permission to view this ticket");
|
|
|
759 |
}
|
|
|
760 |
}
|
|
|
761 |
}
|
|
|
762 |
|
| 31762 |
tejbeer |
763 |
List<Activity> allactivities = activityRepository.selectAll(ticketId);
|
| 35570 |
amit |
764 |
|
|
|
765 |
// Batch fetch all documents for attachments (fix N+1 query)
|
|
|
766 |
List<Integer> documentIds = allactivities.stream()
|
|
|
767 |
.flatMap(a -> a.getActivityAttachment().stream())
|
|
|
768 |
.map(ActivityAttachment::getDocumentId)
|
|
|
769 |
.distinct()
|
|
|
770 |
.collect(Collectors.toList());
|
|
|
771 |
|
|
|
772 |
Map<Integer, Document> documentMap = Collections.emptyMap();
|
|
|
773 |
if (!documentIds.isEmpty()) {
|
|
|
774 |
documentMap = documentRepository.selectByIds(documentIds).stream()
|
|
|
775 |
.collect(Collectors.toMap(Document::getId, d -> d));
|
|
|
776 |
}
|
|
|
777 |
|
|
|
778 |
// Set document names transiently (do not persist during GET)
|
|
|
779 |
for (Activity activity : allactivities) {
|
|
|
780 |
for (ActivityAttachment attachment : activity.getActivityAttachment()) {
|
|
|
781 |
Document document = documentMap.get(attachment.getDocumentId());
|
|
|
782 |
if (document != null) {
|
|
|
783 |
attachment.setDocumentName(document.getDisplayName());
|
|
|
784 |
}
|
| 31762 |
tejbeer |
785 |
}
|
|
|
786 |
}
|
|
|
787 |
List<Activity> activities = null;
|
| 35592 |
amit |
788 |
if (isAdmin) {
|
| 31762 |
tejbeer |
789 |
Set<Integer> authUserIds = allactivities.stream().map(x -> x.getCreatedBy()).collect(Collectors.toSet());
|
| 35395 |
amit |
790 |
List<AuthUser> users = authRepository.selectByIds(new ArrayList<>(authUserIds));
|
| 31762 |
tejbeer |
791 |
Map<Integer, String> authUserNameMap = users.stream().collect(Collectors.toMap(AuthUser::getId, x -> x.getFirstName() + " " + x.getLastName()));
|
|
|
792 |
allactivities.stream().forEach(x -> x.setName(authUserNameMap.get(x.getCreatedBy())));
|
|
|
793 |
activities = allactivities;
|
|
|
794 |
} else {
|
|
|
795 |
activities = allactivities.stream().filter(x -> ActivityType.PARTNER_ACTIVITIES.contains(x.getType())).collect(Collectors.toList());
|
|
|
796 |
}
|
|
|
797 |
if (activities == null) {
|
|
|
798 |
throw new ProfitMandiBusinessException("Activity", ticketId, "No Activity Found");
|
|
|
799 |
}
|
|
|
800 |
model.addAttribute("response1", mvcResponseSender.createResponseString(activities));
|
|
|
801 |
return "response";
|
| 24500 |
govind |
802 |
|
| 31762 |
tejbeer |
803 |
}
|
| 24620 |
govind |
804 |
|
| 31762 |
tejbeer |
805 |
@PostMapping(value = "/cs/createActivity")
|
|
|
806 |
public String createActivity(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, @RequestParam(name = "assigneeId", defaultValue = "0") int assigneeId, @RequestParam(name = "internal", defaultValue = "true") boolean internal, @RequestParam(name = "message", defaultValue = "") String message, @RequestBody List<Integer> documentIds,
|
| 24620 |
govind |
807 |
|
| 31762 |
tejbeer |
808 |
Model model) throws Exception {
|
| 24620 |
govind |
809 |
|
| 31762 |
tejbeer |
810 |
LOGGER.info("documentIds" + documentIds);
|
|
|
811 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
812 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
| 35592 |
amit |
813 |
|
|
|
814 |
if (ticket == null) {
|
|
|
815 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Ticket not found");
|
|
|
816 |
}
|
|
|
817 |
|
|
|
818 |
// Authorization check: verify user has access to add activity to this ticket
|
|
|
819 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
820 |
if (!isAdmin) {
|
|
|
821 |
// Partners can only add activity to their own tickets
|
|
|
822 |
if (ticket.getFofoId() != loginDetails.getFofoId()) {
|
|
|
823 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "You do not have permission to add activity to this ticket");
|
|
|
824 |
}
|
|
|
825 |
} else {
|
|
|
826 |
// Admins must be assigned to the ticket OR be CRM user OR be in the escalation chain
|
|
|
827 |
AuthUser currentAuthUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
828 |
boolean isCrmUser = positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
829 |
|
|
|
830 |
if (!isCrmUser) {
|
|
|
831 |
List<TicketAssigned> assignments = ticketAssignedRepository.selectByTicketIds(Arrays.asList(ticketId));
|
|
|
832 |
boolean isAssigned = assignments.stream().anyMatch(ta -> ta.getAssineeId() == currentAuthUser.getId() || ta.getManagerId() == currentAuthUser.getId());
|
|
|
833 |
boolean isInEscalationChain = ticket.getL1AuthUser() == currentAuthUser.getId() ||
|
|
|
834 |
ticket.getL2AuthUser() == currentAuthUser.getId() ||
|
|
|
835 |
ticket.getL3AuthUser() == currentAuthUser.getId() ||
|
|
|
836 |
ticket.getL4AuthUser() == currentAuthUser.getId() ||
|
|
|
837 |
ticket.getL5AuthUser() == currentAuthUser.getId();
|
|
|
838 |
|
|
|
839 |
if (!isAssigned && !isInEscalationChain) {
|
|
|
840 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "You do not have permission to add activity to this ticket");
|
|
|
841 |
}
|
|
|
842 |
}
|
|
|
843 |
}
|
| 31762 |
tejbeer |
844 |
List<TicketAssigned> ticketAssignedList = ticketAssignedRepository.selectByTicketIds(Arrays.asList(ticketId));
|
|
|
845 |
List<Integer> authUserIds = ticketAssignedList.stream().map(x -> x.getAssineeId()).collect(Collectors.toList());
|
|
|
846 |
authUserIds.add(ticketAssignedList.get(ticketAssignedList.size() - 1).getManagerId());
|
| 35395 |
amit |
847 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectByIds(authUserIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 31762 |
tejbeer |
848 |
if (ticket.getCloseTimestamp() == null) {
|
|
|
849 |
Activity activity = new Activity();
|
|
|
850 |
activity.setCreatedBy(0);
|
|
|
851 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
852 |
String subject = null;
|
|
|
853 |
String mailMessage = null;
|
|
|
854 |
activity.setMessage(message);
|
|
|
855 |
if (!roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))) {
|
|
|
856 |
CustomRetailer customRetailer = retailerService.getFofoRetailers(true).get(loginDetails.getFofoId());
|
|
|
857 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
|
|
858 |
subject = String.format("Ticket Update #%s by franchisee %s", ticket.getId(), customRetailer.getBusinessName() + "(" + customRetailer.getCode() + ")");
|
|
|
859 |
mailMessage = String.format("Franchisee message - %s", message);
|
|
|
860 |
} else {
|
|
|
861 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
862 |
activity.setCreatedBy(authUser.getId());
|
|
|
863 |
authUsersMap.remove(authUser.getId());
|
|
|
864 |
subject = String.format("Ticket Update #%s by %s", ticket.getId(), authUser.getName());
|
|
|
865 |
mailMessage = String.format("%s's message - %s", authUser.getFirstName(), message);
|
| 35569 |
amit |
866 |
// Only CRM users can send external communications
|
|
|
867 |
boolean isCrmUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
868 |
if (internal || !isCrmUser) {
|
| 31762 |
tejbeer |
869 |
activity.setType(ActivityType.COMMUNICATION_INTERNAL);
|
|
|
870 |
} else {
|
|
|
871 |
String updatedBy = "SD Team";
|
| 31854 |
amit.gupta |
872 |
CustomRetailer customRetailer = retailerService.getFofoRetailers(false).get(ticket.getFofoId());
|
| 31762 |
tejbeer |
873 |
subject = String.format("Ticket Update #%s by %s", ticket.getId(), updatedBy);
|
|
|
874 |
String partnerMessage = String.format("%s's message - %s", updatedBy, message);
|
|
|
875 |
this.activityRelatedMail(customRetailer.getEmail(), null, "subject", partnerMessage);
|
|
|
876 |
activity.setType(ActivityType.COMMUNICATION_OUT);
|
|
|
877 |
}
|
|
|
878 |
}
|
|
|
879 |
activityRepository.persist(activity);
|
|
|
880 |
|
|
|
881 |
for (Integer documentId : documentIds) {
|
|
|
882 |
ActivityAttachment activityAttachment = new ActivityAttachment();
|
|
|
883 |
activityAttachment.setActivityId(activity.getId());
|
|
|
884 |
activityAttachment.setDocumentId(documentId);
|
|
|
885 |
activityAttachmentRepository.persist(activityAttachment);
|
|
|
886 |
}
|
|
|
887 |
|
|
|
888 |
csService.addActivity(ticket, activity);
|
|
|
889 |
AuthUser authUser = authUsersMap.remove(authUserIds.get(0));
|
|
|
890 |
if (authUser == null) {
|
|
|
891 |
authUser = authUsersMap.remove(authUserIds.get(1));
|
|
|
892 |
}
|
|
|
893 |
model.addAttribute("response1", mvcResponseSender.createResponseString(authUser));
|
|
|
894 |
String[] cc = authUsersMap.entrySet().stream().map(x -> x.getValue().getEmailId()).toArray(String[]::new);
|
|
|
895 |
this.activityRelatedMail(authUser.getEmailId(), cc, subject, mailMessage);
|
|
|
896 |
} else {
|
|
|
897 |
throw new ProfitMandiBusinessException("Ticket", ticket.getId(), "Already closed ticket");
|
|
|
898 |
}
|
|
|
899 |
return "response";
|
|
|
900 |
}
|
|
|
901 |
|
|
|
902 |
private void activityRelatedMail(String to, String[] cc, String subject, String message) throws ProfitMandiBusinessException {
|
|
|
903 |
try {
|
|
|
904 |
Utils.sendMailWithAttachments(mailSender, to, cc, subject, message, null);
|
|
|
905 |
} catch (Exception e) {
|
|
|
906 |
throw new ProfitMandiBusinessException("Ticket Activity", to, "Could not send ticket activity mail");
|
|
|
907 |
}
|
|
|
908 |
}
|
|
|
909 |
|
|
|
910 |
@PostMapping(value = "/cs/closeTicket")
|
|
|
911 |
public String closeTicket(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, @RequestParam(name = "happyCode") String happyCode, Model model) throws Exception {
|
| 35592 |
amit |
912 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 31762 |
tejbeer |
913 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
| 35592 |
amit |
914 |
|
|
|
915 |
if (ticket == null) {
|
|
|
916 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Ticket not found");
|
|
|
917 |
}
|
|
|
918 |
|
|
|
919 |
// Authorization check: only the ticket owner (partner) can close the ticket
|
|
|
920 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
921 |
if (isAdmin) {
|
|
|
922 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Only partners can close tickets using happy code");
|
|
|
923 |
}
|
|
|
924 |
|
|
|
925 |
// Verify the partner owns this ticket
|
|
|
926 |
if (ticket.getFofoId() != loginDetails.getFofoId()) {
|
|
|
927 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "You do not have permission to close this ticket");
|
|
|
928 |
}
|
|
|
929 |
|
| 31762 |
tejbeer |
930 |
if (ticket.getHappyCode().equals(happyCode)) {
|
|
|
931 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
|
|
932 |
ticketRepository.persist(ticket);
|
|
|
933 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
934 |
} else {
|
|
|
935 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Happy Code can't match");
|
|
|
936 |
}
|
|
|
937 |
return "response";
|
|
|
938 |
}
|
|
|
939 |
|
| 34913 |
ranu |
940 |
@GetMapping(value = "/cs/myPartyTicketTicket")
|
|
|
941 |
public String getMyPartyTicketTicket(HttpServletRequest request, @RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder, @RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus, @RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType, @RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm, Model model) throws ProfitMandiBusinessException {
|
| 35626 |
amit |
942 |
populateMyPartnerTicketModel(request, sortOrder, ticketStatus, ticketSearchType, searchTerm, model);
|
|
|
943 |
return "my-partner-tickets";
|
|
|
944 |
}
|
|
|
945 |
|
|
|
946 |
@GetMapping(value = "/cs/myPartyTicket-content")
|
|
|
947 |
public String getMyPartyTicketContent(HttpServletRequest request,
|
|
|
948 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
949 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
|
|
950 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
951 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
|
|
952 |
Model model) throws ProfitMandiBusinessException {
|
|
|
953 |
populateMyPartnerTicketModel(request, sortOrder, ticketStatus, ticketSearchType, searchTerm, model);
|
|
|
954 |
return "my-partner-tickets-content";
|
|
|
955 |
}
|
|
|
956 |
|
|
|
957 |
private void populateMyPartnerTicketModel(HttpServletRequest request, SortOrder sortOrder, TicketStatus ticketStatus,
|
|
|
958 |
TicketSearchType ticketSearchType, int searchTerm, Model model) throws ProfitMandiBusinessException {
|
| 34913 |
ranu |
959 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
960 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
961 |
List<Ticket> tickets = new ArrayList<>();
|
|
|
962 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
|
|
963 |
Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
|
|
|
964 |
|
|
|
965 |
Map<Integer, List<AuthUser>> authUserListMap = null;
|
|
|
966 |
if (fofoIds != null && !fofoIds.isEmpty()) {
|
| 35571 |
amit |
967 |
List<Ticket> allPartnerTickets = ticketRepository.selectAllOpenTickets(new ArrayList<>(fofoIds));
|
|
|
968 |
if (allPartnerTickets != null && !allPartnerTickets.isEmpty()) {
|
|
|
969 |
tickets = allPartnerTickets.stream()
|
|
|
970 |
.filter(ticket -> ticket.getLastActivity() == null ||
|
|
|
971 |
ticket.getLastActivity() != ActivityType.RESOLVED)
|
|
|
972 |
.collect(Collectors.toList());
|
| 34913 |
ranu |
973 |
}
|
|
|
974 |
}
|
|
|
975 |
|
|
|
976 |
authUserListMap = csService.getAssignedAuthList(tickets);
|
|
|
977 |
|
|
|
978 |
if (tickets.size() > 0) {
|
|
|
979 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
980 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
|
|
981 |
}
|
|
|
982 |
|
| 35626 |
amit |
983 |
// Pagination for partner tickets (in-memory since selectAllOpenTickets doesn't support DB-level pagination)
|
|
|
984 |
long totalRecords = tickets.size();
|
|
|
985 |
int totalPages = totalRecords > 0 ? (int) Math.ceil((double) totalRecords / 25) : 1;
|
|
|
986 |
model.addAttribute("totalRecords", totalRecords);
|
|
|
987 |
model.addAttribute("currentPage", 0);
|
|
|
988 |
model.addAttribute("pageSize", 25);
|
|
|
989 |
model.addAttribute("totalPages", totalPages);
|
|
|
990 |
model.addAttribute("startRecord", totalRecords > 0 ? 1 : 0);
|
|
|
991 |
model.addAttribute("endRecord", totalRecords);
|
|
|
992 |
model.addAttribute("currentPageDisplay", 1);
|
|
|
993 |
model.addAttribute("prevPage", 0);
|
|
|
994 |
model.addAttribute("nextPage", 1);
|
|
|
995 |
model.addAttribute("lastPage", totalPages - 1);
|
|
|
996 |
|
| 34913 |
ranu |
997 |
model.addAttribute("size", tickets.size());
|
|
|
998 |
model.addAttribute("tickets", tickets);
|
|
|
999 |
|
|
|
1000 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
|
|
1001 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
| 35571 |
amit |
1002 |
if (subCategoryIdAndSubCategoryMap == null) {
|
|
|
1003 |
subCategoryIdAndSubCategoryMap = new HashMap<>();
|
|
|
1004 |
}
|
| 34913 |
ranu |
1005 |
|
|
|
1006 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
| 35571 |
amit |
1007 |
if (subCategoryIdAndCategoryMap == null) {
|
|
|
1008 |
subCategoryIdAndCategoryMap = new HashMap<>();
|
|
|
1009 |
}
|
| 34913 |
ranu |
1010 |
|
|
|
1011 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
1012 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
|
|
1013 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
| 35569 |
amit |
1014 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|
| 34913 |
ranu |
1015 |
|
|
|
1016 |
if (!ticketIds.isEmpty()) {
|
| 35569 |
amit |
1017 |
List<Activity> allActivities = activityRepository.selectAll(ticketIds);
|
|
|
1018 |
activityMap = allActivities.stream().collect(Collectors.groupingBy(Activity::getTicketId));
|
|
|
1019 |
activityMapWithActivityId = allActivities.stream().collect(Collectors.groupingBy(Activity::getId));
|
| 34913 |
ranu |
1020 |
|
| 35569 |
amit |
1021 |
Set<Integer> activityCreatorIds = allActivities.stream()
|
|
|
1022 |
.map(Activity::getCreatedBy)
|
|
|
1023 |
.filter(id -> id > 0)
|
|
|
1024 |
.collect(Collectors.toSet());
|
|
|
1025 |
if (!activityCreatorIds.isEmpty()) {
|
|
|
1026 |
authUserMap = authRepository.selectByIds(new ArrayList<>(activityCreatorIds))
|
|
|
1027 |
.stream().collect(Collectors.toMap(AuthUser::getId, x -> x));
|
|
|
1028 |
}
|
| 34913 |
ranu |
1029 |
}
|
|
|
1030 |
|
| 35626 |
amit |
1031 |
Map<Integer, Boolean> unreadMap = csService.getUnreadStatusForTickets(tickets, authUser.getId(), UserType.AUTH_USER);
|
|
|
1032 |
Map<Integer, Activity> lastActivityMap = csService.getLastActivitiesForTickets(
|
|
|
1033 |
tickets.stream().map(Ticket::getId).collect(Collectors.toList()));
|
|
|
1034 |
model.addAttribute("unreadMap", unreadMap);
|
|
|
1035 |
model.addAttribute("lastActivityMap", lastActivityMap);
|
|
|
1036 |
|
| 34913 |
ranu |
1037 |
model.addAttribute("ticketStatusValues", TicketStatus.values());
|
|
|
1038 |
model.addAttribute("orderByValues", SortOrder.values());
|
|
|
1039 |
model.addAttribute("selectedticketStatus", ticketStatus);
|
|
|
1040 |
model.addAttribute("selectedorderby", sortOrder);
|
|
|
1041 |
model.addAttribute("ticketSearchTypes", TicketSearchType.values());
|
|
|
1042 |
model.addAttribute("ticketSearchType", ticketSearchType);
|
|
|
1043 |
model.addAttribute("searchTerm", searchTerm);
|
| 35571 |
amit |
1044 |
model.addAttribute("authUserListMap", authUserListMap != null ? authUserListMap : new HashMap<>());
|
| 34913 |
ranu |
1045 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
|
|
1046 |
|
|
|
1047 |
model.addAttribute("subCategoryIdAndCategoryMap", subCategoryIdAndCategoryMap);
|
|
|
1048 |
|
|
|
1049 |
model.addAttribute("activityMap", activityMap);
|
|
|
1050 |
model.addAttribute("authUserMap", authUserMap);
|
|
|
1051 |
model.addAttribute("activityMapWithActivityId", activityMapWithActivityId);
|
| 35569 |
amit |
1052 |
boolean isCrmUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
1053 |
model.addAttribute("isCrmUser", isCrmUser);
|
| 35626 |
amit |
1054 |
}
|
| 34913 |
ranu |
1055 |
|
| 35626 |
amit |
1056 |
@GetMapping(value = "/cs/managerTicket")
|
|
|
1057 |
public String getManagerTickets(HttpServletRequest request,
|
|
|
1058 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
1059 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
|
|
1060 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
1061 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
|
|
1062 |
@RequestParam(name = "page", defaultValue = "0") int page,
|
|
|
1063 |
@RequestParam(name = "pageSize", defaultValue = "25") int pageSize,
|
|
|
1064 |
@RequestParam(name = "search", required = false) String searchText,
|
|
|
1065 |
Model model) throws ProfitMandiBusinessException {
|
|
|
1066 |
populateManagerTicketModel(request, sortOrder, ticketStatus, ticketSearchType, searchTerm, page, pageSize, searchText, model);
|
|
|
1067 |
return "managerTicket";
|
| 34913 |
ranu |
1068 |
}
|
|
|
1069 |
|
| 35626 |
amit |
1070 |
@GetMapping(value = "/cs/managerTicket-content")
|
|
|
1071 |
public String getManagerTicketContent(HttpServletRequest request,
|
|
|
1072 |
@RequestParam(name = "orderby", defaultValue = "DESCENDING") SortOrder sortOrder,
|
|
|
1073 |
@RequestParam(name = "ticketStatus", defaultValue = "OPENED") TicketStatus ticketStatus,
|
|
|
1074 |
@RequestParam(name = "ticketSearchType", defaultValue = "") TicketSearchType ticketSearchType,
|
|
|
1075 |
@RequestParam(name = "searchTerm", defaultValue = "0") int searchTerm,
|
|
|
1076 |
@RequestParam(name = "page", defaultValue = "0") int page,
|
|
|
1077 |
@RequestParam(name = "pageSize", defaultValue = "25") int pageSize,
|
|
|
1078 |
@RequestParam(name = "search", required = false) String searchText,
|
|
|
1079 |
Model model) throws ProfitMandiBusinessException {
|
|
|
1080 |
populateManagerTicketModel(request, sortOrder, ticketStatus, ticketSearchType, searchTerm, page, pageSize, searchText, model);
|
|
|
1081 |
return "managerTicket-content";
|
|
|
1082 |
}
|
|
|
1083 |
|
|
|
1084 |
private void populateManagerTicketModel(HttpServletRequest request, SortOrder sortOrder, TicketStatus ticketStatus,
|
|
|
1085 |
TicketSearchType ticketSearchType, int searchTerm, int page, int pageSize,
|
|
|
1086 |
String searchText, Model model) throws ProfitMandiBusinessException {
|
| 31762 |
tejbeer |
1087 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 35626 |
amit |
1088 |
long totalRecords = 0;
|
| 31762 |
tejbeer |
1089 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 35626 |
amit |
1090 |
|
|
|
1091 |
// Block L1-only users from accessing manager tickets
|
|
|
1092 |
List<Position> positions = positionRepository.selectAllByAuthUserId(authUser.getId());
|
|
|
1093 |
boolean isAboveL1 = positions.stream().anyMatch(pos -> pos.getEscalationType() != EscalationType.L1);
|
|
|
1094 |
if (!isAboveL1) {
|
|
|
1095 |
throw new ProfitMandiBusinessException("ManagerTicket", 0, "Access denied: requires at least L2 position");
|
|
|
1096 |
}
|
|
|
1097 |
|
| 35594 |
amit |
1098 |
boolean isCrmUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
1099 |
|
| 35626 |
amit |
1100 |
List<Integer> userCategoryIds = positionRepository.selectCategoryIdsByAuthUserId(authUser.getId());
|
|
|
1101 |
|
| 31762 |
tejbeer |
1102 |
List<Ticket> tickets = null;
|
|
|
1103 |
Map<Integer, List<AuthUser>> authUserListMap = null;
|
| 35594 |
amit |
1104 |
|
| 35626 |
amit |
1105 |
int offset = page * pageSize;
|
|
|
1106 |
Optional<Boolean> resolvedOpt = ticketStatus.equals(TicketStatus.RESOLVED) ? Optional.empty() : Optional.of(TicketStatus.CLOSED.equals(ticketStatus));
|
|
|
1107 |
|
| 35594 |
amit |
1108 |
if (isCrmUser) {
|
| 35626 |
amit |
1109 |
tickets = ticketRepository.selectAllTicketsPaginated(
|
|
|
1110 |
resolvedOpt, sortOrder, ticketSearchType, searchTerm, searchText,
|
|
|
1111 |
userCategoryIds, offset, pageSize);
|
|
|
1112 |
totalRecords = ticketRepository.selectAllTicketsPaginatedCount(
|
|
|
1113 |
resolvedOpt, ticketSearchType, searchTerm, searchText, userCategoryIds);
|
| 31762 |
tejbeer |
1114 |
} else {
|
| 35626 |
amit |
1115 |
tickets = ticketRepository.selectAllManagerTicketPaginated(
|
|
|
1116 |
authUser.getId(), sortOrder, resolvedOpt, ticketSearchType, searchTerm, searchText,
|
|
|
1117 |
offset, pageSize);
|
|
|
1118 |
totalRecords = ticketRepository.selectAllCountByManagerTicketPaginated(
|
|
|
1119 |
authUser.getId(), resolvedOpt, ticketSearchType, searchTerm, searchText);
|
| 31762 |
tejbeer |
1120 |
}
|
|
|
1121 |
authUserListMap = csService.getAssignedAuthList(tickets);
|
|
|
1122 |
|
|
|
1123 |
if (tickets.size() > 0) {
|
|
|
1124 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
1125 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
|
|
1126 |
}
|
|
|
1127 |
|
| 35626 |
amit |
1128 |
int totalPages = (int) Math.ceil((double) totalRecords / pageSize);
|
|
|
1129 |
if (totalPages == 0) totalPages = 1;
|
|
|
1130 |
int startRecord = totalRecords > 0 ? offset + 1 : 0;
|
|
|
1131 |
int endRecord = (int) Math.min(offset + pageSize, totalRecords);
|
|
|
1132 |
|
|
|
1133 |
model.addAttribute("size", totalRecords);
|
|
|
1134 |
model.addAttribute("totalRecords", totalRecords);
|
|
|
1135 |
model.addAttribute("currentPage", page);
|
|
|
1136 |
model.addAttribute("pageSize", pageSize);
|
|
|
1137 |
model.addAttribute("totalPages", totalPages);
|
|
|
1138 |
model.addAttribute("startRecord", startRecord);
|
|
|
1139 |
model.addAttribute("endRecord", endRecord);
|
|
|
1140 |
model.addAttribute("searchText", searchText != null ? searchText : "");
|
|
|
1141 |
model.addAttribute("currentPageDisplay", page + 1);
|
|
|
1142 |
model.addAttribute("prevPage", page - 1);
|
|
|
1143 |
model.addAttribute("nextPage", page + 1);
|
|
|
1144 |
model.addAttribute("lastPage", totalPages - 1);
|
| 31762 |
tejbeer |
1145 |
model.addAttribute("tickets", tickets);
|
|
|
1146 |
|
|
|
1147 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
|
|
1148 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
| 35571 |
amit |
1149 |
if (subCategoryIdAndSubCategoryMap == null) {
|
|
|
1150 |
subCategoryIdAndSubCategoryMap = new HashMap<>();
|
|
|
1151 |
}
|
| 31762 |
tejbeer |
1152 |
|
|
|
1153 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
| 35571 |
amit |
1154 |
if (subCategoryIdAndCategoryMap == null) {
|
|
|
1155 |
subCategoryIdAndCategoryMap = new HashMap<>();
|
|
|
1156 |
}
|
| 31762 |
tejbeer |
1157 |
|
|
|
1158 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
1159 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
| 33778 |
ranu |
1160 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
| 35570 |
amit |
1161 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|
| 31762 |
tejbeer |
1162 |
|
|
|
1163 |
if (!ticketIds.isEmpty()) {
|
| 35570 |
amit |
1164 |
List<Activity> allActivities = activityRepository.selectAll(ticketIds);
|
|
|
1165 |
activityMap = allActivities.stream().collect(Collectors.groupingBy(Activity::getTicketId));
|
|
|
1166 |
activityMapWithActivityId = allActivities.stream().collect(Collectors.groupingBy(Activity::getId));
|
| 31762 |
tejbeer |
1167 |
|
| 35570 |
amit |
1168 |
Set<Integer> activityCreatorIds = allActivities.stream()
|
|
|
1169 |
.map(Activity::getCreatedBy)
|
|
|
1170 |
.filter(id -> id > 0)
|
|
|
1171 |
.collect(Collectors.toSet());
|
|
|
1172 |
if (!activityCreatorIds.isEmpty()) {
|
|
|
1173 |
authUserMap = authRepository.selectByIds(new ArrayList<>(activityCreatorIds))
|
|
|
1174 |
.stream().collect(Collectors.toMap(AuthUser::getId, x -> x));
|
|
|
1175 |
}
|
| 31762 |
tejbeer |
1176 |
}
|
| 33778 |
ranu |
1177 |
|
| 35626 |
amit |
1178 |
Map<Integer, Boolean> unreadMap = csService.getUnreadStatusForTickets(tickets, authUser.getId(), UserType.AUTH_USER);
|
|
|
1179 |
Map<Integer, Activity> lastActivityMap = csService.getLastActivitiesForTickets(
|
|
|
1180 |
tickets.stream().map(Ticket::getId).collect(Collectors.toList()));
|
|
|
1181 |
model.addAttribute("unreadMap", unreadMap);
|
|
|
1182 |
model.addAttribute("lastActivityMap", lastActivityMap);
|
|
|
1183 |
|
| 31762 |
tejbeer |
1184 |
model.addAttribute("ticketStatusValues", TicketStatus.values());
|
|
|
1185 |
model.addAttribute("orderByValues", SortOrder.values());
|
|
|
1186 |
model.addAttribute("selectedticketStatus", ticketStatus);
|
|
|
1187 |
model.addAttribute("selectedorderby", sortOrder);
|
|
|
1188 |
model.addAttribute("ticketSearchTypes", TicketSearchType.values());
|
|
|
1189 |
model.addAttribute("ticketSearchType", ticketSearchType);
|
|
|
1190 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
1191 |
model.addAttribute("authUserListMap", authUserListMap);
|
|
|
1192 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
|
|
1193 |
|
|
|
1194 |
model.addAttribute("subCategoryIdAndCategoryMap", subCategoryIdAndCategoryMap);
|
|
|
1195 |
|
|
|
1196 |
model.addAttribute("activityMap", activityMap);
|
| 33778 |
ranu |
1197 |
model.addAttribute("authUserMap", authUserMap);
|
|
|
1198 |
model.addAttribute("activityMapWithActivityId", activityMapWithActivityId);
|
| 35594 |
amit |
1199 |
model.addAttribute("isCrmUser", isCrmUser);
|
| 31762 |
tejbeer |
1200 |
}
|
|
|
1201 |
|
|
|
1202 |
|
|
|
1203 |
@GetMapping(value = "/cs/edit-ticket")
|
| 35594 |
amit |
1204 |
public String getEditTicket(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) throws ProfitMandiBusinessException {
|
|
|
1205 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1206 |
AuthUser currentAuthUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1207 |
boolean isCrmUser = positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
1208 |
|
| 31762 |
tejbeer |
1209 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
| 35626 |
amit |
1210 |
if (ticket == null) {
|
|
|
1211 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Ticket not found");
|
|
|
1212 |
}
|
|
|
1213 |
|
|
|
1214 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
1215 |
int ticketCategoryId = ticketSubCategory.getCategoryId();
|
|
|
1216 |
boolean isVisibleSubCategory = ticketSubCategory.isVisibility();
|
|
|
1217 |
|
|
|
1218 |
// Check permissions
|
|
|
1219 |
boolean hasPositionInCategory = positionRepository.hasCategory(currentAuthUser.getId(), ticketCategoryId);
|
|
|
1220 |
List<TicketAssigned> assignments = ticketAssignedRepository.selectByTicketIds(Arrays.asList(ticketId));
|
|
|
1221 |
boolean isAssigned = assignments.stream().anyMatch(ta -> ta.getAssineeId() == currentAuthUser.getId() || ta.getManagerId() == currentAuthUser.getId());
|
|
|
1222 |
boolean isInEscalationChain = ticket.getL1AuthUser() == currentAuthUser.getId() ||
|
|
|
1223 |
ticket.getL2AuthUser() == currentAuthUser.getId() ||
|
|
|
1224 |
ticket.getL3AuthUser() == currentAuthUser.getId() ||
|
|
|
1225 |
ticket.getL4AuthUser() == currentAuthUser.getId() ||
|
|
|
1226 |
ticket.getL5AuthUser() == currentAuthUser.getId();
|
|
|
1227 |
|
|
|
1228 |
boolean canEdit = (isCrmUser && isVisibleSubCategory)
|
|
|
1229 |
|| hasPositionInCategory
|
|
|
1230 |
|| isAssigned
|
|
|
1231 |
|| isInEscalationChain;
|
|
|
1232 |
|
|
|
1233 |
if (!canEdit) {
|
|
|
1234 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "You do not have permission to edit this ticket");
|
|
|
1235 |
}
|
|
|
1236 |
|
| 31762 |
tejbeer |
1237 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
|
|
1238 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll(ticketSubCategory.getCategoryId());
|
|
|
1239 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 35594 |
amit |
1240 |
|
| 35617 |
amit |
1241 |
// CRM users should not see invisible subcategories
|
| 35594 |
amit |
1242 |
if (isCrmUser) {
|
|
|
1243 |
ticketSubCategories = ticketSubCategories.stream()
|
| 35617 |
amit |
1244 |
.filter(TicketSubCategory::isVisibility)
|
| 35594 |
amit |
1245 |
.collect(Collectors.toList());
|
|
|
1246 |
}
|
|
|
1247 |
|
|
|
1248 |
// Get partner name for modal title
|
|
|
1249 |
String partnerName = retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName();
|
|
|
1250 |
|
| 31762 |
tejbeer |
1251 |
model.addAttribute("ticket", ticket);
|
|
|
1252 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
1253 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
|
|
1254 |
model.addAttribute("ticketSubCategory", ticketSubCategory);
|
|
|
1255 |
model.addAttribute("authUsers", authUsers);
|
| 35594 |
amit |
1256 |
model.addAttribute("isCrmUser", isCrmUser);
|
|
|
1257 |
model.addAttribute("partnerName", partnerName);
|
| 31762 |
tejbeer |
1258 |
return "edit-ticket-modal";
|
|
|
1259 |
}
|
|
|
1260 |
|
| 34913 |
ranu |
1261 |
@GetMapping(value = "/cs/edit-partner-ticket")
|
| 35594 |
amit |
1262 |
public String getEditPartnerTicket(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) throws ProfitMandiBusinessException {
|
|
|
1263 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1264 |
AuthUser currentAuthUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1265 |
boolean isCrmUser = positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
1266 |
|
| 34913 |
ranu |
1267 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
1268 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
|
|
1269 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
1270 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll(ticketSubCategory.getCategoryId());
|
|
|
1271 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
| 35594 |
amit |
1272 |
|
| 35617 |
amit |
1273 |
// CRM users should not see invisible subcategories
|
| 35594 |
amit |
1274 |
if (isCrmUser) {
|
|
|
1275 |
ticketSubCategories = ticketSubCategories.stream()
|
| 35617 |
amit |
1276 |
.filter(TicketSubCategory::isVisibility)
|
| 35594 |
amit |
1277 |
.collect(Collectors.toList());
|
|
|
1278 |
}
|
|
|
1279 |
|
|
|
1280 |
// Get partner name for modal title
|
|
|
1281 |
String partnerName = retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName();
|
|
|
1282 |
|
| 34913 |
ranu |
1283 |
model.addAttribute("ticket", ticket);
|
|
|
1284 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
1285 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
|
|
1286 |
model.addAttribute("ticketSubCategory", ticketSubCategory);
|
|
|
1287 |
model.addAttribute("authUsers", authUsers);
|
| 35594 |
amit |
1288 |
model.addAttribute("isCrmUser", isCrmUser);
|
|
|
1289 |
model.addAttribute("partnerName", partnerName);
|
| 34913 |
ranu |
1290 |
return "edit-ticket-partner-modal";
|
|
|
1291 |
}
|
|
|
1292 |
|
| 31762 |
tejbeer |
1293 |
@PostMapping(value = "/cs/edit-ticket")
|
|
|
1294 |
public String editTicket(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, @RequestParam(name = "subCategoryId", defaultValue = "0") int subCategoryId, @RequestParam(name = "categoryId", defaultValue = "0") int categoryId, @RequestParam(name = "authUserId", defaultValue = "0") int authUserId, @RequestParam(name = "escalationType", defaultValue = "L1") EscalationType escalationType, Model model) throws Exception {
|
|
|
1295 |
LOGGER.info("Ticket Id {}, CategoryId {}, SubCategory Id {} authUserId {}", ticketId, categoryId, subCategoryId, authUserId);
|
| 35592 |
amit |
1296 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1297 |
|
|
|
1298 |
// Only admins can edit tickets
|
|
|
1299 |
if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
1300 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Only admins can edit tickets");
|
|
|
1301 |
}
|
|
|
1302 |
|
| 31762 |
tejbeer |
1303 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
| 35592 |
amit |
1304 |
if (ticket == null) {
|
|
|
1305 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Ticket not found");
|
|
|
1306 |
}
|
|
|
1307 |
|
| 35626 |
amit |
1308 |
// Verify admin has access to this ticket
|
| 35592 |
amit |
1309 |
AuthUser currentAuthUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1310 |
boolean isCrmUser = positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
1311 |
|
| 35626 |
amit |
1312 |
// Get ticket's subcategory to check visibility
|
|
|
1313 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
1314 |
int ticketCategoryId = ticketSubCategory.getCategoryId();
|
|
|
1315 |
boolean isVisibleSubCategory = ticketSubCategory.isVisibility();
|
| 35592 |
amit |
1316 |
|
| 35626 |
amit |
1317 |
// Check if user has position in ticket's category
|
|
|
1318 |
boolean hasPositionInCategory = positionRepository.hasCategory(currentAuthUser.getId(), ticketCategoryId);
|
|
|
1319 |
|
|
|
1320 |
// Check if assigned or in escalation chain
|
|
|
1321 |
List<TicketAssigned> assignments = ticketAssignedRepository.selectByTicketIds(Arrays.asList(ticketId));
|
|
|
1322 |
boolean isAssigned = assignments.stream().anyMatch(ta -> ta.getAssineeId() == currentAuthUser.getId() || ta.getManagerId() == currentAuthUser.getId());
|
|
|
1323 |
boolean isInEscalationChain = ticket.getL1AuthUser() == currentAuthUser.getId() ||
|
|
|
1324 |
ticket.getL2AuthUser() == currentAuthUser.getId() ||
|
|
|
1325 |
ticket.getL3AuthUser() == currentAuthUser.getId() ||
|
|
|
1326 |
ticket.getL4AuthUser() == currentAuthUser.getId() ||
|
|
|
1327 |
ticket.getL5AuthUser() == currentAuthUser.getId();
|
|
|
1328 |
|
|
|
1329 |
// Permission rules:
|
|
|
1330 |
// 1. CRM user AND ticket has visible subcategory, OR
|
|
|
1331 |
// 2. Has position in ticket's category (can edit even invisible), OR
|
|
|
1332 |
// 3. Is assigned to ticket, OR
|
|
|
1333 |
// 4. Is in escalation chain
|
|
|
1334 |
boolean canEdit = (isCrmUser && isVisibleSubCategory)
|
|
|
1335 |
|| hasPositionInCategory
|
|
|
1336 |
|| isAssigned
|
|
|
1337 |
|| isInEscalationChain;
|
|
|
1338 |
|
|
|
1339 |
if (!canEdit) {
|
|
|
1340 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "You do not have permission to edit this ticket");
|
| 35592 |
amit |
1341 |
}
|
|
|
1342 |
|
| 31762 |
tejbeer |
1343 |
csService.updateTicket(categoryId, subCategoryId, ticket, authUserId, escalationType);
|
|
|
1344 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
1345 |
return "response";
|
|
|
1346 |
|
|
|
1347 |
}
|
|
|
1348 |
|
| 34913 |
ranu |
1349 |
@PostMapping(value = "/cs/edit-partner-ticket")
|
|
|
1350 |
public String editPartnerTicket(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, @RequestParam(name = "subCategoryId", defaultValue = "0") int subCategoryId, @RequestParam(name = "categoryId", defaultValue = "0") int categoryId, @RequestParam(name = "authUserId", defaultValue = "0") int authUserId, @RequestParam(name = "escalationType", defaultValue = "L1") EscalationType escalationType, Model model) throws Exception {
|
|
|
1351 |
LOGGER.info("Ticket Id {}, CategoryId {}, SubCategory Id {} authUserId {}", ticketId, categoryId, subCategoryId, authUserId);
|
| 35592 |
amit |
1352 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1353 |
|
|
|
1354 |
// Only admins can edit partner tickets
|
|
|
1355 |
if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
1356 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Only admins can edit partner tickets");
|
|
|
1357 |
}
|
|
|
1358 |
|
| 34913 |
ranu |
1359 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
| 35592 |
amit |
1360 |
if (ticket == null) {
|
|
|
1361 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Ticket not found");
|
|
|
1362 |
}
|
|
|
1363 |
|
|
|
1364 |
// Verify admin has access (must be in Sales, ABM, or RBM position for the partner)
|
|
|
1365 |
AuthUser currentAuthUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1366 |
Map<String, Set<Integer>> authUserPartnerMap = csService.getAuthUserPartnerIdMapping();
|
|
|
1367 |
Set<Integer> allowedPartnerIds = authUserPartnerMap.get(currentAuthUser.getEmailId());
|
|
|
1368 |
|
|
|
1369 |
if (allowedPartnerIds == null || !allowedPartnerIds.contains(ticket.getFofoId())) {
|
|
|
1370 |
// Also allow CRM users
|
|
|
1371 |
boolean isCrmUser = positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
1372 |
if (!isCrmUser) {
|
|
|
1373 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "You do not have permission to edit this partner's ticket");
|
|
|
1374 |
}
|
|
|
1375 |
}
|
|
|
1376 |
|
| 34913 |
ranu |
1377 |
csService.updateTicket(categoryId, subCategoryId, ticket, authUserId, escalationType);
|
|
|
1378 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
1379 |
return "response";
|
|
|
1380 |
|
|
|
1381 |
}
|
|
|
1382 |
|
| 31762 |
tejbeer |
1383 |
@PostMapping(value = "/cs/changeTicketAssignee")
|
|
|
1384 |
public String changeTicketAssignee(HttpServletRequest request, @RequestParam(name = "positionId", defaultValue = "0") int positionId, Model model) throws Exception {
|
|
|
1385 |
Position position = positionRepository.selectById(positionId);
|
|
|
1386 |
if (position.isTicketAssignee()) {
|
|
|
1387 |
position.setTicketAssignee(false);
|
|
|
1388 |
} else {
|
|
|
1389 |
position.setTicketAssignee(true);
|
|
|
1390 |
}
|
|
|
1391 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
1392 |
return "response";
|
|
|
1393 |
}
|
|
|
1394 |
|
|
|
1395 |
|
|
|
1396 |
@DeleteMapping(value = "/cs/removePosition")
|
|
|
1397 |
public String removePosition(HttpServletRequest request, @RequestParam(name = "positionId", defaultValue = "0") int positionId, Model model) throws Exception {
|
|
|
1398 |
positionRepository.delete(positionId);
|
|
|
1399 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
1400 |
return "response";
|
|
|
1401 |
}
|
|
|
1402 |
|
|
|
1403 |
@PostMapping(value = "/cs/create-last-activity")
|
|
|
1404 |
public String createlastActivity(HttpServletRequest request, @RequestParam(name = "ticketId") int ticketId, @RequestParam(name = "lastactivity") ActivityType lastActivity, Model model) throws Exception {
|
|
|
1405 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1406 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
| 35592 |
amit |
1407 |
|
|
|
1408 |
if (ticket == null) {
|
|
|
1409 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Ticket not found");
|
|
|
1410 |
}
|
|
|
1411 |
|
|
|
1412 |
// Authorization check for partners: can only update their own tickets
|
|
|
1413 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
1414 |
if (!isAdmin && ticket.getFofoId() != loginDetails.getFofoId()) {
|
|
|
1415 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "You do not have permission to update this ticket");
|
|
|
1416 |
}
|
|
|
1417 |
|
| 31762 |
tejbeer |
1418 |
Activity activity = new Activity();
|
|
|
1419 |
String subject = String.format(ACTIVITY_SUBJECT, ticket.getId());
|
| 35592 |
amit |
1420 |
if (isAdmin) {
|
| 35603 |
amit |
1421 |
// CRM team members can resolve any ticket
|
|
|
1422 |
// Sales team members can resolve their own Sales category tickets
|
|
|
1423 |
// RBM team members can resolve their own RBM category tickets
|
| 35592 |
amit |
1424 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1425 |
boolean isCrmUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
| 35603 |
amit |
1426 |
boolean isSalesUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
1427 |
boolean isRbmUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_RBM);
|
|
|
1428 |
|
|
|
1429 |
// Check if ticket belongs to Sales or RBM category
|
|
|
1430 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
1431 |
boolean isSalesTicket = ticketSubCategory != null && ticketSubCategory.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES;
|
|
|
1432 |
boolean isRbmTicket = ticketSubCategory != null && ticketSubCategory.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_RBM;
|
|
|
1433 |
|
|
|
1434 |
// Allow if CRM user OR (Sales user AND Sales ticket) OR (RBM user AND RBM ticket)
|
|
|
1435 |
if (!isCrmUser && !(isSalesUser && isSalesTicket) && !(isRbmUser && isRbmTicket)) {
|
|
|
1436 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Only CRM, Sales (for Sales tickets), or RBM (for RBM tickets) team can mark tickets as resolved");
|
| 35592 |
amit |
1437 |
}
|
| 31762 |
tejbeer |
1438 |
ticket.setLastActivity(lastActivity);
|
|
|
1439 |
String to = retailerService.getFofoRetailer(ticket.getFofoId()).getEmail();
|
|
|
1440 |
String message = String.format(PARTNER_RESOLVED_TICKET_MAIL, ticketId, "REOPEN");
|
|
|
1441 |
activity.setMessage(message);
|
| 35592 |
amit |
1442 |
activity.setCreatedBy(authUser.getId());
|
| 31762 |
tejbeer |
1443 |
activity.setTicketId(ticketId);
|
|
|
1444 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
1445 |
activity.setType(ActivityType.COMMUNICATION_OUT);
|
|
|
1446 |
this.activityRelatedMail(to, null, subject, message);
|
|
|
1447 |
} else {
|
|
|
1448 |
if (ActivityType.RESOLVED_ACCEPTED == lastActivity) {
|
|
|
1449 |
ticket.setLastActivity(lastActivity);
|
|
|
1450 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
|
|
1451 |
activity.setMessage(ActivityType.RESOLVED_ACCEPTED.toString());
|
|
|
1452 |
activity.setCreatedBy(0);
|
|
|
1453 |
activity.setTicketId(ticketId);
|
|
|
1454 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
|
|
1455 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
1456 |
} else {
|
|
|
1457 |
String message = String.format(INTERNAL_REOPEN_MAIL, ticketId, retailerService.getFofoRetailer(loginDetails.getFofoId()).getBusinessName());
|
|
|
1458 |
String to = authRepository.selectById(ticket.getL1AuthUser()).getEmailId();
|
| 35395 |
amit |
1459 |
String[] ccTo = authRepository.selectByIds(Arrays.asList(ticket.getL2AuthUser(), ticket.getL3AuthUser(), ticket.getL4AuthUser(), ticket.getL5AuthUser())).stream().map(x -> x.getEmailId()).toArray(String[]::new);
|
| 31762 |
tejbeer |
1460 |
ticket.setLastActivity(lastActivity);
|
|
|
1461 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
1462 |
ticketAssignedRepository.deleteByTicketId(ticketId);
|
|
|
1463 |
TicketAssigned ticketAssigned = new TicketAssigned();
|
|
|
1464 |
ticketAssigned.setAssineeId(ticket.getL1AuthUser());
|
|
|
1465 |
ticketAssigned.setTicketId(ticketId);
|
|
|
1466 |
ticketAssignedRepository.persist(ticketAssigned);
|
|
|
1467 |
activity.setMessage(INTERNAL_REOPEN_ACTIVITY_MESSAGE);
|
|
|
1468 |
activity.setCreatedBy(0);
|
|
|
1469 |
activity.setTicketId(ticketId);
|
|
|
1470 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
|
|
1471 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
1472 |
this.activityRelatedMail(to, ccTo, subject, message);
|
|
|
1473 |
this.activityRelatedMail(retailerService.getFofoRetailer(loginDetails.getFofoId()).getEmail(), null, subject, String.format(PARTNER_REOPEN, ticketId));
|
|
|
1474 |
}
|
|
|
1475 |
|
|
|
1476 |
}
|
|
|
1477 |
activityRepository.persist(activity);
|
|
|
1478 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
1479 |
return "response";
|
|
|
1480 |
}
|
|
|
1481 |
|
| 32812 |
shampa |
1482 |
|
|
|
1483 |
|
|
|
1484 |
|
|
|
1485 |
|
|
|
1486 |
@PostMapping(value = "/partner-position/update")
|
|
|
1487 |
public String positionUpdated(Model model, @RequestBody List<PartnerPositonUpdateModel> partnerPositionUpdateModels)
|
|
|
1488 |
throws Exception {
|
|
|
1489 |
|
| 32821 |
shampa |
1490 |
Map<Integer, List<String>> positionIdsToAddMap = partnerPositionUpdateModels.stream().filter(x->x.getPositionIdTo()!=0).collect(Collectors.groupingBy(x->x.getPositionIdTo(),
|
| 32812 |
shampa |
1491 |
Collectors.mapping(x->x.getStoreCode(), Collectors.toList())));
|
|
|
1492 |
|
| 32821 |
shampa |
1493 |
Map<Integer, List<String>> positionIdsToRemoveMap = partnerPositionUpdateModels.stream().filter(x->x.getPositionIdFrom()!=0).collect(Collectors.groupingBy(x->x.getPositionIdFrom(),
|
| 32812 |
shampa |
1494 |
Collectors.mapping(x->x.getStoreCode(), Collectors.toList())));
|
|
|
1495 |
|
|
|
1496 |
List<Integer> positionIdsToUpdate = new ArrayList<>();
|
|
|
1497 |
positionIdsToUpdate.addAll(positionIdsToAddMap.keySet());
|
|
|
1498 |
positionIdsToUpdate.addAll(positionIdsToRemoveMap.keySet());
|
|
|
1499 |
|
| 35395 |
amit |
1500 |
Map<Integer, Position> positionsToUpdateMap = positionRepository.selectByIds(positionIdsToUpdate).stream().collect(Collectors.toMap(x->x.getId(), x->x));
|
| 32812 |
shampa |
1501 |
List<Integer> invalidPositionIds = positionsToUpdateMap.values().stream().filter(x-> x.getCategoryId()!= ProfitMandiConstants.TICKET_CATEGORY_RBM
|
| 34908 |
ranu |
1502 |
&& x.getCategoryId() != ProfitMandiConstants.TICKET_CATEGORY_SALES && x.getCategoryId() != ProfitMandiConstants.TICKET_CATEGORY_ABM).map(x -> x.getId()).collect(Collectors.toList());
|
| 32812 |
shampa |
1503 |
if(invalidPositionIds.size() > 0) {
|
| 34908 |
ranu |
1504 |
String message = "Non RBM/Sales/ABM are not allowed - " + invalidPositionIds;
|
| 32812 |
shampa |
1505 |
throw new ProfitMandiBusinessException(message, message, message);
|
|
|
1506 |
}
|
|
|
1507 |
|
|
|
1508 |
for (Map.Entry<Integer, List<String>> positionIdStoreMapEntry : positionIdsToAddMap.entrySet()) {
|
|
|
1509 |
int positionId = positionIdStoreMapEntry.getKey();
|
|
|
1510 |
Position position = positionsToUpdateMap.get(positionId);
|
| 32821 |
shampa |
1511 |
LOGGER.info("positionId - {}, Position - {}", positionId, position);
|
| 32812 |
shampa |
1512 |
List<String> storeCodesToAdd = positionIdStoreMapEntry.getValue();
|
|
|
1513 |
List<Integer> retailerIdsToAdd = fofoStoreRepository.selectByStoreCodes(storeCodesToAdd).stream().map(x->x.getId()).collect(Collectors.toList());
|
|
|
1514 |
Map<Integer, PartnerPosition> partnerPositionsMapByFofoId = partnerPositionRepository
|
| 32821 |
shampa |
1515 |
.selectByRegionIdAndPostionId(Arrays.asList(position.getRegionId())
|
|
|
1516 |
,Arrays.asList(positionId)).stream().collect(Collectors.toMap(x->x.getFofoId(),x->x));
|
| 32812 |
shampa |
1517 |
for (Integer retailerIdToAdd : retailerIdsToAdd) {
|
|
|
1518 |
if (!partnerPositionsMapByFofoId.containsKey(retailerIdToAdd)) {
|
|
|
1519 |
PartnerPosition partnerPositionNew = new PartnerPosition();
|
|
|
1520 |
partnerPositionNew.setPositionId(positionId);
|
|
|
1521 |
partnerPositionNew.setFofoId(retailerIdToAdd);
|
|
|
1522 |
partnerPositionNew.setRegionId(position.getRegionId());
|
| 32865 |
amit.gupta |
1523 |
partnerPositionRepository.persist(partnerPositionNew);
|
| 32812 |
shampa |
1524 |
}
|
|
|
1525 |
}
|
|
|
1526 |
}
|
|
|
1527 |
|
|
|
1528 |
for (Map.Entry<Integer, List<String>> positionIdStoreMapEntry : positionIdsToRemoveMap.entrySet()) {
|
|
|
1529 |
|
|
|
1530 |
int positionId = positionIdStoreMapEntry.getKey();
|
|
|
1531 |
Position position = positionsToUpdateMap.get(positionId);
|
|
|
1532 |
List<String> storeCodesToRemove = positionIdStoreMapEntry.getValue();
|
|
|
1533 |
List<Integer> retailerIdsToRemove = fofoStoreRepository.selectByStoreCodes(storeCodesToRemove).stream().map(x->x.getId()).collect(Collectors.toList());
|
|
|
1534 |
Map<Integer, PartnerPosition> partnerPositionsMapByFofoId = partnerPositionRepository
|
|
|
1535 |
.selectByRegionIdAndPostionId(Arrays.asList(position.getRegionId()),Arrays.asList(positionId)).stream().collect(Collectors.toMap(x->x.getFofoId(),x->x));
|
|
|
1536 |
for (Integer retailerIdToRemove : retailerIdsToRemove) {
|
|
|
1537 |
if (partnerPositionsMapByFofoId.containsKey(retailerIdToRemove)) {
|
|
|
1538 |
PartnerPosition partnerPositionToRemove = partnerPositionsMapByFofoId.get(retailerIdToRemove);
|
|
|
1539 |
partnerPositionRepository.delete(partnerPositionToRemove);
|
|
|
1540 |
}
|
|
|
1541 |
}
|
|
|
1542 |
}
|
|
|
1543 |
|
|
|
1544 |
|
|
|
1545 |
|
|
|
1546 |
/*partnerPositionUpdateModels.str
|
|
|
1547 |
|
|
|
1548 |
Map<Integer, Position> positionIdMap = positionsToUpdate.stream().collect(Collectors.toMap(x->x.getId(), x->x));
|
|
|
1549 |
for (PartnerPositonUpdateModel partnerPositionUpdateModel : partnerPositionUpdateModels) {
|
|
|
1550 |
FofoStore fofoStore = fofoStoreRepository.selectByStoreCode(partnerPositionUpdateModel.getStoreCode());
|
|
|
1551 |
Position positionFrom = positionIdMap.get(partnerPositionUpdateModel.getPositionIdFrom());
|
|
|
1552 |
Position positionTo = positionIdMap.get(partnerPositionUpdateModel.getPositionIdTo());
|
|
|
1553 |
if(positionFrom != null) {
|
|
|
1554 |
partnerPositionRepository.selectByRegionIdAndPostionId(Arrays.)
|
|
|
1555 |
int regionId = positionFrom.getRegionId()
|
|
|
1556 |
}
|
|
|
1557 |
if(positionTo != null) {
|
|
|
1558 |
|
|
|
1559 |
}
|
|
|
1560 |
}*/
|
|
|
1561 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
1562 |
return "response";
|
|
|
1563 |
|
|
|
1564 |
}
|
|
|
1565 |
|
| 35626 |
amit |
1566 |
@PostMapping(value = "/cs/markTicketRead")
|
|
|
1567 |
@ResponseBody
|
|
|
1568 |
public Map<String, Object> markTicketRead(HttpServletRequest request,
|
|
|
1569 |
@RequestParam(name = "ticketId") int ticketId,
|
|
|
1570 |
Model model) throws ProfitMandiBusinessException {
|
|
|
1571 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1572 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
1573 |
Map<String, Object> response = new HashMap<>();
|
| 32812 |
shampa |
1574 |
|
| 35626 |
amit |
1575 |
if (isAdmin) {
|
|
|
1576 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1577 |
csService.markTicketAsRead(ticketId, authUser.getId(), UserType.AUTH_USER);
|
|
|
1578 |
} else {
|
|
|
1579 |
csService.markTicketAsRead(ticketId, loginDetails.getFofoId(), UserType.PARTNER);
|
|
|
1580 |
}
|
|
|
1581 |
|
|
|
1582 |
response.put("success", true);
|
|
|
1583 |
return response;
|
|
|
1584 |
}
|
|
|
1585 |
|
|
|
1586 |
@GetMapping(value = "/cs/unreadCount")
|
|
|
1587 |
@ResponseBody
|
|
|
1588 |
public Map<String, Object> getUnreadCount(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
1589 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1590 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
1591 |
Map<String, Object> response = new HashMap<>();
|
|
|
1592 |
|
|
|
1593 |
List<Ticket> tickets;
|
|
|
1594 |
int userId;
|
|
|
1595 |
UserType userType;
|
|
|
1596 |
|
|
|
1597 |
if (isAdmin) {
|
|
|
1598 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1599 |
userId = authUser.getId();
|
|
|
1600 |
userType = UserType.AUTH_USER;
|
|
|
1601 |
boolean isCrmUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
1602 |
List<Integer> userCategoryIds = positionRepository.selectCategoryIdsByAuthUserId(authUser.getId());
|
|
|
1603 |
if (isCrmUser) {
|
|
|
1604 |
tickets = ticketRepository.selectAllTicketsPaginated(
|
|
|
1605 |
Optional.of(false), null, null, 0, null,
|
|
|
1606 |
userCategoryIds, 0, 1000);
|
|
|
1607 |
} else {
|
|
|
1608 |
tickets = ticketRepository.selectAllByAssigneePaginated(
|
|
|
1609 |
authUser.getId(), Optional.of(false), null, null, 0, null,
|
|
|
1610 |
0, 1000);
|
|
|
1611 |
}
|
|
|
1612 |
} else {
|
|
|
1613 |
userId = loginDetails.getFofoId();
|
|
|
1614 |
userType = UserType.PARTNER;
|
|
|
1615 |
tickets = ticketRepository.selectAllByCreator(loginDetails.getFofoId(), Optional.of(true), null);
|
|
|
1616 |
}
|
|
|
1617 |
|
|
|
1618 |
Map<Integer, Boolean> unreadMap = csService.getUnreadStatusForTickets(tickets, userId, userType);
|
|
|
1619 |
long unreadCount = unreadMap.values().stream().filter(v -> v).count();
|
|
|
1620 |
|
|
|
1621 |
response.put("success", true);
|
|
|
1622 |
response.put("unreadCount", unreadCount);
|
|
|
1623 |
return response;
|
|
|
1624 |
}
|
|
|
1625 |
|
| 24417 |
govind |
1626 |
}
|