| 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.*;
|
| 27270 |
tejbeer |
9 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
| 24417 |
govind |
10 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
|
|
11 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 24699 |
govind |
12 |
import com.spice.profitmandi.dao.enumuration.cs.TicketStatus;
|
| 25570 |
tejbeer |
13 |
import com.spice.profitmandi.dao.model.CreatePositionModel;
|
| 24417 |
govind |
14 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 27690 |
amit.gupta |
15 |
import com.spice.profitmandi.dao.repository.cs.*;
|
| 27270 |
tejbeer |
16 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| 25570 |
tejbeer |
17 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24417 |
govind |
18 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
|
|
19 |
import com.spice.profitmandi.service.user.RetailerService;
|
|
|
20 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
21 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
22 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 27690 |
amit.gupta |
23 |
import org.apache.logging.log4j.LogManager;
|
|
|
24 |
import org.apache.logging.log4j.Logger;
|
|
|
25 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
26 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
27 |
import org.springframework.stereotype.Controller;
|
|
|
28 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
29 |
import org.springframework.ui.Model;
|
|
|
30 |
import org.springframework.web.bind.annotation.*;
|
| 24417 |
govind |
31 |
|
| 27690 |
amit.gupta |
32 |
import javax.servlet.http.HttpServletRequest;
|
| 35571 |
amit |
33 |
import javax.swing.SortOrder;
|
| 27690 |
amit.gupta |
34 |
import java.time.LocalDateTime;
|
|
|
35 |
import java.util.*;
|
|
|
36 |
import java.util.stream.Collectors;
|
|
|
37 |
|
| 24417 |
govind |
38 |
@Controller
|
|
|
39 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
40 |
public class CsController {
|
|
|
41 |
|
| 31762 |
tejbeer |
42 |
private static final Logger LOGGER = LogManager.getLogger(CsController.class);
|
|
|
43 |
private static final String ACTIVITY_SUBJECT = "Message related ticketId#%s";
|
|
|
44 |
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";
|
|
|
45 |
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";
|
|
|
46 |
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";
|
|
|
47 |
private static final String INTERNAL_REOPEN_ACTIVITY_MESSAGE = "Hi,My ticket is not resolved yet,so I have reopened it";
|
| 24699 |
govind |
48 |
|
| 31762 |
tejbeer |
49 |
@Autowired
|
|
|
50 |
JavaMailSender mailSender;
|
| 24620 |
govind |
51 |
|
| 31762 |
tejbeer |
52 |
@Autowired
|
|
|
53 |
private CsService csService;
|
| 24417 |
govind |
54 |
|
| 31762 |
tejbeer |
55 |
@Autowired
|
|
|
56 |
private CookiesProcessor cookiesProcessor;
|
| 24417 |
govind |
57 |
|
| 31762 |
tejbeer |
58 |
@Autowired
|
|
|
59 |
private TicketCategoryRepository ticketCategoryRepository;
|
| 24417 |
govind |
60 |
|
| 31762 |
tejbeer |
61 |
@Autowired
|
|
|
62 |
private TicketSubCategoryRepository ticketSubCategoryRepository;
|
| 24417 |
govind |
63 |
|
| 31762 |
tejbeer |
64 |
@Autowired
|
|
|
65 |
private RegionRepository regionRepository;
|
| 24417 |
govind |
66 |
|
| 31762 |
tejbeer |
67 |
@Autowired
|
|
|
68 |
private RetailerService retailerService;
|
| 24417 |
govind |
69 |
|
| 31762 |
tejbeer |
70 |
@Autowired
|
|
|
71 |
private MVCResponseSender mvcResponseSender;
|
| 24417 |
govind |
72 |
|
| 31762 |
tejbeer |
73 |
@Autowired
|
|
|
74 |
private AuthRepository authRepository;
|
| 24417 |
govind |
75 |
|
| 31762 |
tejbeer |
76 |
@Autowired
|
|
|
77 |
private PositionRepository positionRepository;
|
| 24417 |
govind |
78 |
|
| 31762 |
tejbeer |
79 |
@Autowired
|
|
|
80 |
private TicketRepository ticketRepository;
|
| 24417 |
govind |
81 |
|
| 31762 |
tejbeer |
82 |
@Autowired
|
|
|
83 |
private RoleManager roleManager;
|
| 24417 |
govind |
84 |
|
| 31762 |
tejbeer |
85 |
@Autowired
|
|
|
86 |
private ActivityRepository activityRepository;
|
| 24417 |
govind |
87 |
|
| 31762 |
tejbeer |
88 |
@Autowired
|
|
|
89 |
private ActivityAttachmentRepository activityAttachmentRepository;
|
| 27270 |
tejbeer |
90 |
|
| 31762 |
tejbeer |
91 |
@Autowired
|
|
|
92 |
private TicketAssignedRepository ticketAssignedRepository;
|
| 24569 |
govind |
93 |
|
| 31762 |
tejbeer |
94 |
@Autowired
|
|
|
95 |
private PartnerRegionRepository partnerRegionRepository;
|
| 24500 |
govind |
96 |
|
| 31762 |
tejbeer |
97 |
@Autowired
|
| 32493 |
amit.gupta |
98 |
PartnerPositionRepository partnerPositionRepository;
|
| 25570 |
tejbeer |
99 |
|
| 31762 |
tejbeer |
100 |
@Autowired
|
|
|
101 |
FofoStoreRepository fofoStoreRepository;
|
| 25570 |
tejbeer |
102 |
|
| 31762 |
tejbeer |
103 |
@Autowired
|
|
|
104 |
DocumentRepository documentRepository;
|
| 27270 |
tejbeer |
105 |
|
| 31762 |
tejbeer |
106 |
@GetMapping(value = "/cs/createCategory")
|
|
|
107 |
public String getCreateCategory(HttpServletRequest request, Model model) {
|
|
|
108 |
List<TicketCategory> ticketCategories = ticketCategoryRepository.selectAll();
|
|
|
109 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
110 |
return "create-ticket-category";
|
|
|
111 |
}
|
| 24417 |
govind |
112 |
|
| 31762 |
tejbeer |
113 |
@PostMapping(value = "/cs/createCategory")
|
| 33081 |
ranu |
114 |
public String createCategory(HttpServletRequest request,
|
|
|
115 |
@RequestParam(name = "name") String name,
|
|
|
116 |
@RequestParam(name = "categoryType") int categoryType,
|
|
|
117 |
@RequestParam(name = "description") String description,
|
|
|
118 |
Model model) throws ProfitMandiBusinessException {
|
| 31762 |
tejbeer |
119 |
TicketCategory ticketCategory = ticketCategoryRepository.selectByName(name);
|
|
|
120 |
if (ticketCategory != null) {
|
|
|
121 |
throw new ProfitMandiBusinessException("name", name, "already exists!");
|
|
|
122 |
}
|
| 33081 |
ranu |
123 |
|
| 31762 |
tejbeer |
124 |
ticketCategory = new TicketCategory();
|
|
|
125 |
ticketCategory.setName(name);
|
|
|
126 |
ticketCategory.setDescription(description);
|
| 33081 |
ranu |
127 |
|
|
|
128 |
ticketCategory.setCategoryType(categoryType == 1);
|
| 31762 |
tejbeer |
129 |
ticketCategoryRepository.persist(ticketCategory);
|
|
|
130 |
return "create-ticket-category";
|
|
|
131 |
}
|
| 24417 |
govind |
132 |
|
| 33081 |
ranu |
133 |
|
| 31762 |
tejbeer |
134 |
@GetMapping(value = "/cs/createSubCategory")
|
|
|
135 |
public String getCreateSubCategory(HttpServletRequest request, Model model) {
|
|
|
136 |
List<TicketCategory> ticketCategories = ticketCategoryRepository.selectAll();
|
|
|
137 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
138 |
return "create-ticket-sub-category";
|
|
|
139 |
}
|
| 24417 |
govind |
140 |
|
| 31762 |
tejbeer |
141 |
@GetMapping(value = "/cs/getSubCategoryByCategoryId")
|
|
|
142 |
public String getSubCategoryByCategoryId(HttpServletRequest request, @RequestParam(name = "ticketCategoryId", defaultValue = "") int ticketCategoryId, Model model) {
|
|
|
143 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll(ticketCategoryId);
|
|
|
144 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(ticketCategoryId);
|
| 33081 |
ranu |
145 |
LOGGER.info("ticketSubCategories {}", ticketSubCategories);
|
|
|
146 |
LOGGER.info("ticketCategory {}", ticketCategory);
|
| 31762 |
tejbeer |
147 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
|
|
148 |
model.addAttribute("ticketCategory", ticketCategory);
|
|
|
149 |
return "ticket-sub-category";
|
|
|
150 |
}
|
| 24417 |
govind |
151 |
|
| 31762 |
tejbeer |
152 |
@PostMapping(value = "/cs/createSubCategory")
|
|
|
153 |
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 |
154 |
|
| 31762 |
tejbeer |
155 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectTicketSubCategory(categoryId, name);
|
|
|
156 |
if (ticketSubCategory != null) {
|
|
|
157 |
throw new ProfitMandiBusinessException("name & categoryId", name + " " + categoryId, "already exists!");
|
|
|
158 |
}
|
| 24417 |
govind |
159 |
|
| 31762 |
tejbeer |
160 |
ticketSubCategory = new TicketSubCategory();
|
|
|
161 |
ticketSubCategory.setCategoryId(categoryId);
|
|
|
162 |
ticketSubCategory.setName(name);
|
|
|
163 |
ticketSubCategory.setDescription(description);
|
|
|
164 |
ticketSubCategoryRepository.persist(ticketSubCategory);
|
|
|
165 |
return "create-ticket-sub-category";
|
|
|
166 |
}
|
| 24417 |
govind |
167 |
|
| 31762 |
tejbeer |
168 |
@GetMapping(value = "/cs/createRegion")
|
|
|
169 |
public String createRegion(HttpServletRequest request, Model model) {
|
|
|
170 |
List<Region> regions = regionRepository.selectAll();
|
|
|
171 |
model.addAttribute("regions", regions);
|
|
|
172 |
return "create-region";
|
|
|
173 |
}
|
| 24417 |
govind |
174 |
|
| 31762 |
tejbeer |
175 |
@PostMapping(value = "/cs/createRegion")
|
|
|
176 |
public String createRegion(HttpServletRequest request, @RequestParam(name = "name") String name, @RequestParam(name = "description") String description, Model model) throws Exception {
|
|
|
177 |
Region region = regionRepository.selectByName(name);
|
|
|
178 |
if (region != null) {
|
|
|
179 |
throw new ProfitMandiBusinessException("name", name, "already exists!");
|
|
|
180 |
}
|
|
|
181 |
region = new Region();
|
|
|
182 |
region.setName(name);
|
|
|
183 |
region.setDescription(description);
|
|
|
184 |
regionRepository.persist(region);
|
|
|
185 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
186 |
return "response";
|
|
|
187 |
}
|
| 24417 |
govind |
188 |
|
| 31762 |
tejbeer |
189 |
@GetMapping(value = "/cs/getPartners")
|
| 33244 |
ranu |
190 |
public String getPartners(HttpServletRequest request, @RequestParam(name = "regionId", defaultValue = "0") int regionId, Model model) throws ProfitMandiBusinessException {
|
| 31762 |
tejbeer |
191 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
192 |
List<Integer> addedfofoIds = partnerRegionRepository.selectByRegionId(regionId).stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| 30426 |
tejbeer |
193 |
|
| 31762 |
tejbeer |
194 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
195 |
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));
|
|
|
196 |
model.addAttribute("fofoRetailers", fofoRetailers);
|
|
|
197 |
model.addAttribute("addedfofoIds", addedfofoIds);
|
|
|
198 |
return "added-region-partners";
|
|
|
199 |
}
|
| 24569 |
govind |
200 |
|
| 31762 |
tejbeer |
201 |
@GetMapping(value = "/cs/getPartnersByRegion")
|
| 33244 |
ranu |
202 |
public String getPartnersByRegion(HttpServletRequest request, @RequestParam(name = "regionId", defaultValue = "0") int regionId, Model model) throws ProfitMandiBusinessException {
|
| 31762 |
tejbeer |
203 |
List<Integer> fofoIds = null;
|
|
|
204 |
fofoIds = partnerRegionRepository.selectByRegionId(regionId).stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| 25570 |
tejbeer |
205 |
|
| 31762 |
tejbeer |
206 |
if (fofoIds.contains(0)) {
|
|
|
207 |
fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).collect(Collectors.toList()).stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 25570 |
tejbeer |
208 |
|
| 31762 |
tejbeer |
209 |
}
|
|
|
210 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 25570 |
tejbeer |
211 |
|
| 31762 |
tejbeer |
212 |
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));
|
|
|
213 |
model.addAttribute("fofoRetailers", fofoRetailers);
|
|
|
214 |
return "added-subregion-partners";
|
|
|
215 |
}
|
| 25570 |
tejbeer |
216 |
|
| 31762 |
tejbeer |
217 |
@GetMapping(value = "/cs/createPartnerRegion")
|
|
|
218 |
public String createPartnerRegion(HttpServletRequest request, Model model) {
|
|
|
219 |
List<Region> regions = regionRepository.selectAll();
|
|
|
220 |
model.addAttribute("regions", regions);
|
|
|
221 |
return "create-partner-region";
|
|
|
222 |
}
|
| 24417 |
govind |
223 |
|
| 31762 |
tejbeer |
224 |
@PostMapping(value = "/cs/createPartnerRegion")
|
|
|
225 |
public String createPartnerRegion(HttpServletRequest request, @RequestParam(name = "regionId") int regionId, @RequestBody List<Integer> selectedFofoIds, Model model) throws Exception {
|
|
|
226 |
partnerRegionRepository.delete(regionId);
|
|
|
227 |
LOGGER.info("successfully removed");
|
|
|
228 |
LOGGER.info(selectedFofoIds.size());
|
|
|
229 |
csService.addPartnerToRegion(regionId, selectedFofoIds);
|
|
|
230 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
231 |
return "response";
|
|
|
232 |
}
|
| 24417 |
govind |
233 |
|
| 31762 |
tejbeer |
234 |
@GetMapping(value = "/cs/getPosition")
|
| 33244 |
ranu |
235 |
public String getPosition(HttpServletRequest request, @RequestParam int positionId, Model model) throws ProfitMandiBusinessException {
|
| 27410 |
tejbeer |
236 |
|
| 31762 |
tejbeer |
237 |
Position position = positionRepository.selectById(positionId);
|
| 27410 |
tejbeer |
238 |
|
| 31762 |
tejbeer |
239 |
List<CustomRetailer> positionIdCustomRetailer = csService.getPositionCustomRetailerMap(Arrays.asList(position)).get(position.getId());
|
| 27410 |
tejbeer |
240 |
|
| 31762 |
tejbeer |
241 |
Map<Integer, CustomRetailer> regionRetailerMap = csService.getRegionPartners(Arrays.asList(position)).get(position.getRegionId()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 27410 |
tejbeer |
242 |
|
| 31762 |
tejbeer |
243 |
model.addAttribute("position", position);
|
|
|
244 |
model.addAttribute("regionRetailerMap", regionRetailerMap);
|
|
|
245 |
model.addAttribute("positionIdCustomRetailer", positionIdCustomRetailer);
|
| 27410 |
tejbeer |
246 |
|
| 31762 |
tejbeer |
247 |
return "position-partner";
|
|
|
248 |
}
|
| 27410 |
tejbeer |
249 |
|
| 31762 |
tejbeer |
250 |
@GetMapping(value = "/cs/createPosition")
|
|
|
251 |
public String createPosition(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) {
|
|
|
252 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
|
|
253 |
List<TicketCategory> ticketCategories = ticketCategoryRepository.selectAll();
|
|
|
254 |
List<Region> regions = regionRepository.selectAll();
|
|
|
255 |
model.addAttribute("escalationTypes", EscalationType.values());
|
|
|
256 |
model.addAttribute("authUsers", authUsers);
|
|
|
257 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
258 |
model.addAttribute("regions", regions);
|
| 24500 |
govind |
259 |
|
| 31762 |
tejbeer |
260 |
List<Position> positions = positionRepository.selectAllPosition();
|
|
|
261 |
LOGGER.info("positions" + positions);
|
| 30426 |
tejbeer |
262 |
|
| 31762 |
tejbeer |
263 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = csService.getAuthUserIdAndAuthUserMapUsingPositions(positions);
|
|
|
264 |
Map<Integer, TicketCategory> categoryIdAndCategoryMap = csService.getCategoryIdAndCategoryUsingPositions(positions);
|
|
|
265 |
Map<Integer, Region> regionIdAndRegionMap = csService.getRegionIdAndRegionMap(positions);
|
| 25570 |
tejbeer |
266 |
|
| 27410 |
tejbeer |
267 |
// Map<Integer, List<CustomRetailer>> positionIdAndpartnerRegionMap = csService
|
|
|
268 |
// .getpositionIdAndpartnerRegionMap(positions);
|
| 25570 |
tejbeer |
269 |
|
| 27410 |
tejbeer |
270 |
// Map<Integer, List<CustomRetailer>> addedpositionIdAndCustomRetailerMap = csService
|
|
|
271 |
// .getPositionCustomRetailerMap(positions);
|
|
|
272 |
// LOGGER.info("fofoIdAndCustomRetailerMap" + addedpositionIdAndCustomRetailerMap);
|
| 24500 |
govind |
273 |
|
| 31762 |
tejbeer |
274 |
model.addAttribute("start", offset + 1);
|
| 30426 |
tejbeer |
275 |
|
| 31762 |
tejbeer |
276 |
model.addAttribute("positions", positions);
|
|
|
277 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
278 |
model.addAttribute("categoryIdAndCategoryMap", categoryIdAndCategoryMap);
|
|
|
279 |
model.addAttribute("regionIdAndRegionMap", regionIdAndRegionMap);
|
|
|
280 |
// model.addAttribute("positionIdAndCustomRetailerMap",
|
|
|
281 |
// addedpositionIdAndCustomRetailerMap);
|
|
|
282 |
// model.addAttribute("positionIdAndpartnerRegionMap",
|
| 27410 |
tejbeer |
283 |
// positionIdAndpartnerRegionMap);
|
| 25570 |
tejbeer |
284 |
|
| 31762 |
tejbeer |
285 |
return "create-position";
|
|
|
286 |
}
|
| 24500 |
govind |
287 |
|
| 31762 |
tejbeer |
288 |
@GetMapping(value = "/cs/position-paginated")
|
|
|
289 |
public String positionPaginated(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) {
|
| 24500 |
govind |
290 |
|
| 31762 |
tejbeer |
291 |
List<Position> positions = positionRepository.selectAll(offset, limit);
|
|
|
292 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = csService.getAuthUserIdAndAuthUserMapUsingPositions(positions);
|
|
|
293 |
Map<Integer, TicketCategory> categoryIdAndCategoryMap = csService.getCategoryIdAndCategoryUsingPositions(positions);
|
|
|
294 |
Map<Integer, Region> regionIdAndRegionMap = csService.getRegionIdAndRegionMap(positions);
|
|
|
295 |
/*
|
|
|
296 |
* Map<Integer, List<CustomRetailer>> positionIdAndpartnerRegionMap = csService
|
|
|
297 |
* .getpositionIdAndpartnerRegionMap(positions);
|
|
|
298 |
*
|
|
|
299 |
* Map<Integer, List<CustomRetailer>> addedpositionIdAndCustomRetailerMap =
|
|
|
300 |
* csService .getPositionCustomRetailerMap(positions);
|
|
|
301 |
*/
|
| 25570 |
tejbeer |
302 |
|
| 31762 |
tejbeer |
303 |
model.addAttribute("positions", positions);
|
|
|
304 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
305 |
model.addAttribute("categoryIdAndCategoryMap", categoryIdAndCategoryMap);
|
|
|
306 |
model.addAttribute("regionIdAndRegionMap", regionIdAndRegionMap);
|
|
|
307 |
// model.addAttribute("positionIdAndCustomRetailerMap",
|
|
|
308 |
// addedpositionIdAndCustomRetailerMap);
|
|
|
309 |
// model.addAttribute("positionIdAndpartnerRegionMap",
|
|
|
310 |
// positionIdAndpartnerRegionMap);
|
| 25570 |
tejbeer |
311 |
|
| 31762 |
tejbeer |
312 |
return "position-paginated";
|
|
|
313 |
}
|
| 24417 |
govind |
314 |
|
| 31762 |
tejbeer |
315 |
@PostMapping(value = "/cs/createPosition")
|
|
|
316 |
public String createPosition(HttpServletRequest request, @RequestBody CreatePositionModel createPositionModel, Model model) throws Exception {
|
| 24417 |
govind |
317 |
|
| 35570 |
amit |
318 |
LOGGER.info("partnerPosition" + createPositionModel.isTicketAssigned());
|
| 25570 |
tejbeer |
319 |
|
| 35570 |
amit |
320 |
// Validate authUserId exists
|
|
|
321 |
int authUserId = createPositionModel.getAuthUserId();
|
|
|
322 |
if (authUserId <= 0 || authRepository.selectById(authUserId) == null) {
|
|
|
323 |
throw new ProfitMandiBusinessException("Position", authUserId, "Invalid authUserId");
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
// Validate categoryId exists (0 means "All Categories")
|
|
|
327 |
int categoryId = createPositionModel.getCategoryId();
|
|
|
328 |
if (categoryId > 0 && ticketCategoryRepository.selectById(categoryId) == null) {
|
|
|
329 |
throw new ProfitMandiBusinessException("Position", categoryId, "Invalid categoryId");
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
// Validate regionId exists (0 or 5 typically means "All Partners/Regions")
|
|
|
333 |
int regionId = createPositionModel.getRegionId();
|
|
|
334 |
if (regionId > 0 && regionId != 5 && regionRepository.selectById(regionId) == null) {
|
|
|
335 |
throw new ProfitMandiBusinessException("Position", regionId, "Invalid regionId");
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
// Validate fofoIds exist
|
|
|
339 |
List<Integer> fofoIds = createPositionModel.getFofoIds();
|
|
|
340 |
if (fofoIds != null && !fofoIds.isEmpty()) {
|
|
|
341 |
Map<Integer, CustomRetailer> validRetailers = retailerService.getFofoRetailers(false);
|
|
|
342 |
for (int fofoId : fofoIds) {
|
|
|
343 |
if (!validRetailers.containsKey(fofoId)) {
|
|
|
344 |
throw new ProfitMandiBusinessException("Position", fofoId, "Invalid fofoId");
|
|
|
345 |
}
|
|
|
346 |
}
|
|
|
347 |
}
|
|
|
348 |
|
|
|
349 |
Position position = positionRepository.selectPosition(authUserId, categoryId, regionId, createPositionModel.getEscalationType());
|
| 31762 |
tejbeer |
350 |
if (position == null) {
|
|
|
351 |
position = new Position();
|
| 35570 |
amit |
352 |
position.setAuthUserId(authUserId);
|
|
|
353 |
position.setCategoryId(categoryId);
|
| 31762 |
tejbeer |
354 |
position.setEscalationType(createPositionModel.getEscalationType());
|
| 35570 |
amit |
355 |
position.setRegionId(regionId);
|
| 31762 |
tejbeer |
356 |
position.setCreateTimestamp(LocalDateTime.now());
|
|
|
357 |
position.setTicketAssignee(createPositionModel.isTicketAssigned());
|
|
|
358 |
positionRepository.persist(position);
|
| 25570 |
tejbeer |
359 |
|
| 35570 |
amit |
360 |
if (fofoIds != null) {
|
|
|
361 |
for (int fofoId : fofoIds) {
|
|
|
362 |
PartnerPosition partnerPosition = new PartnerPosition();
|
|
|
363 |
partnerPosition.setFofoId(fofoId);
|
|
|
364 |
partnerPosition.setRegionId(regionId);
|
|
|
365 |
partnerPosition.setPositionId(position.getId());
|
|
|
366 |
partnerPositionRepository.persist(partnerPosition);
|
|
|
367 |
LOGGER.info("partnerPosition" + partnerPosition);
|
|
|
368 |
}
|
| 31762 |
tejbeer |
369 |
}
|
| 24417 |
govind |
370 |
|
| 31762 |
tejbeer |
371 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
372 |
} else {
|
| 35570 |
amit |
373 |
throw new ProfitMandiBusinessException("Position", authUserId, "already exists!");
|
| 31762 |
tejbeer |
374 |
}
|
|
|
375 |
return "response";
|
|
|
376 |
}
|
| 25570 |
tejbeer |
377 |
|
| 31762 |
tejbeer |
378 |
@PostMapping(value = "/cs/updatePartnerPosition")
|
|
|
379 |
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 |
380 |
|
| 35571 |
amit |
381 |
// Validate positionId exists
|
|
|
382 |
Position position = positionRepository.selectById(positionId);
|
|
|
383 |
if (position == null) {
|
|
|
384 |
throw new ProfitMandiBusinessException("Position", positionId, "Position not found");
|
|
|
385 |
}
|
|
|
386 |
|
|
|
387 |
// Validate regionId exists (0 or 5 typically means "All Partners/Regions")
|
|
|
388 |
if (regionId > 0 && regionId != 5 && regionRepository.selectById(regionId) == null) {
|
|
|
389 |
throw new ProfitMandiBusinessException("Position", regionId, "Invalid regionId");
|
|
|
390 |
}
|
|
|
391 |
|
|
|
392 |
// Validate fofoIds exist
|
|
|
393 |
if (selectedFofoIds != null && !selectedFofoIds.isEmpty()) {
|
|
|
394 |
Map<Integer, CustomRetailer> validRetailers = retailerService.getFofoRetailers(false);
|
|
|
395 |
for (int fofoId : selectedFofoIds) {
|
|
|
396 |
if (!validRetailers.containsKey(fofoId)) {
|
|
|
397 |
throw new ProfitMandiBusinessException("Position", fofoId, "Invalid fofoId");
|
|
|
398 |
}
|
|
|
399 |
}
|
|
|
400 |
}
|
|
|
401 |
|
| 32493 |
amit.gupta |
402 |
partnerPositionRepository.delete(positionId);
|
| 35571 |
amit |
403 |
if (selectedFofoIds != null) {
|
|
|
404 |
for (int fofoId : selectedFofoIds) {
|
|
|
405 |
PartnerPosition partnerPosition = new PartnerPosition();
|
|
|
406 |
partnerPosition.setFofoId(fofoId);
|
|
|
407 |
partnerPosition.setRegionId(regionId);
|
|
|
408 |
partnerPosition.setPositionId(positionId);
|
|
|
409 |
partnerPositionRepository.persist(partnerPosition);
|
|
|
410 |
}
|
| 31762 |
tejbeer |
411 |
}
|
| 25570 |
tejbeer |
412 |
|
| 31762 |
tejbeer |
413 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 25570 |
tejbeer |
414 |
|
| 31762 |
tejbeer |
415 |
return "response";
|
|
|
416 |
}
|
| 24417 |
govind |
417 |
|
| 31762 |
tejbeer |
418 |
@GetMapping(value = "/cs/createTicket")
|
|
|
419 |
public String createTicket(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
420 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
421 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
|
|
422 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
|
|
423 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
424 |
return "create-ticket";
|
|
|
425 |
}
|
| 24417 |
govind |
426 |
|
| 31762 |
tejbeer |
427 |
@GetMapping(value = "/cs/getSubCategoriesByCategoryId")
|
|
|
428 |
public String getSubCategoriesByCategoryId(HttpServletRequest request, @RequestParam(name = "categoryId", defaultValue = "0") int categoryId, Model model) {
|
| 31830 |
amit.gupta |
429 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAllVisible(categoryId);
|
| 31762 |
tejbeer |
430 |
LOGGER.info(ticketSubCategories);
|
|
|
431 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
|
|
432 |
return "ticket-sub-categories";
|
|
|
433 |
}
|
| 24417 |
govind |
434 |
|
| 24791 |
govind |
435 |
|
| 31762 |
tejbeer |
436 |
@GetMapping(value = "/cs/getEscalationTypeByCategoryId")
|
|
|
437 |
public String getEscalationTypeByCategoryId(HttpServletRequest request, @RequestParam(name = "categoryId", defaultValue = "0") int categoryId, @RequestParam(name = "authId", defaultValue = "0") int authId, Model model) {
|
|
|
438 |
List<Position> positions = positionRepository.selectPositionbyCategoryIdAndAuthId(categoryId, authId);
|
|
|
439 |
List<EscalationType> escalationTypes = new ArrayList<>();
|
| 24791 |
govind |
440 |
|
| 31762 |
tejbeer |
441 |
if (!positions.isEmpty()) {
|
|
|
442 |
escalationTypes = positions.stream().map(x -> x.getEscalationType()).distinct().collect(Collectors.toList());
|
|
|
443 |
}
|
| 24620 |
govind |
444 |
|
| 31762 |
tejbeer |
445 |
LOGGER.info("escalationTypes {}", escalationTypes);
|
| 24500 |
govind |
446 |
|
| 31762 |
tejbeer |
447 |
model.addAttribute("escalationTypes", escalationTypes);
|
|
|
448 |
return "ticket-escalationtype";
|
|
|
449 |
}
|
| 24500 |
govind |
450 |
|
| 24824 |
govind |
451 |
|
| 31762 |
tejbeer |
452 |
@GetMapping(value = "/cs/getCategoriesByAuthId")
|
|
|
453 |
public String getCategoriesByAuthId(HttpServletRequest request, @RequestParam(name = "authId", defaultValue = "0") int authId, Model model) {
|
| 24824 |
govind |
454 |
|
| 24787 |
govind |
455 |
|
| 31762 |
tejbeer |
456 |
List<Position> positions = positionRepository.selectPositionByAuthId(authId);
|
| 24791 |
govind |
457 |
|
| 31762 |
tejbeer |
458 |
LOGGER.info("positions {}", positions);
|
| 24417 |
govind |
459 |
|
| 31762 |
tejbeer |
460 |
List<TicketCategory> ticketCategories = new ArrayList<TicketCategory>();
|
| 24417 |
govind |
461 |
|
| 31762 |
tejbeer |
462 |
if (!positions.isEmpty()) {
|
| 24417 |
govind |
463 |
|
| 31762 |
tejbeer |
464 |
List<Integer> categoryIds = positions.stream().map(x -> x.getCategoryId()).collect(Collectors.toList());
|
|
|
465 |
ticketCategories = ticketCategoryRepository.selectAll(categoryIds);
|
|
|
466 |
}
|
|
|
467 |
LOGGER.info("ticketCategories {}", ticketCategories);
|
|
|
468 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
469 |
return "ticket-categories";
|
|
|
470 |
}
|
| 27270 |
tejbeer |
471 |
|
| 31762 |
tejbeer |
472 |
@PostMapping(value = "/cs/createTicket")
|
|
|
473 |
public String createTicket(HttpServletRequest request, @RequestParam(name = "categoryId") int categoryId, @RequestParam(name = "subCategoryId") int subCategoryId, @RequestParam(name = "message") String message, Model model) throws Exception {
|
|
|
474 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
475 |
List<Ticket> tickets = ticketRepository.selectAllResolvedMarkedTicketByCreator(loginDetails.getFofoId());
|
|
|
476 |
if (tickets.size() > 3 || tickets.size() == 3) {
|
|
|
477 |
model.addAttribute("response1", mvcResponseSender.createResponseString(false));
|
|
|
478 |
} else {
|
|
|
479 |
csService.createTicket(loginDetails.getFofoId(), categoryId, subCategoryId, message);
|
|
|
480 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
481 |
}
|
|
|
482 |
return "response";
|
|
|
483 |
}
|
| 27270 |
tejbeer |
484 |
|
| 31762 |
tejbeer |
485 |
@GetMapping(value = "/cs/myticket")
|
|
|
486 |
public String getTicket(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 {
|
|
|
487 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
488 |
List<Ticket> tickets = null;
|
|
|
489 |
List<TicketAssigned> ticketAssigneds = null;
|
|
|
490 |
long size = 0;
|
|
|
491 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = null;
|
| 35569 |
amit |
492 |
boolean isAdmin = roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()));
|
|
|
493 |
AuthUser currentAuthUser = isAdmin ? authRepository.selectByEmailOrMobile(loginDetails.getEmailId()) : null;
|
|
|
494 |
|
|
|
495 |
if (isAdmin) {
|
|
|
496 |
int authUserId = currentAuthUser.getId();
|
| 31762 |
tejbeer |
497 |
if (ticketSearchType == null) {
|
|
|
498 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
| 35569 |
amit |
499 |
tickets = ticketRepository.selectAllByAssignee(authUserId, Optional.empty(), sortOrder, null, searchTerm);
|
|
|
500 |
size = ticketRepository.selectAllCountByAssignee(authUserId, Optional.empty(), null, searchTerm);
|
| 31762 |
tejbeer |
501 |
} else {
|
| 35569 |
amit |
502 |
tickets = ticketRepository.selectAllByAssignee(authUserId, Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), sortOrder, null, searchTerm);
|
|
|
503 |
size = ticketRepository.selectAllCountByAssignee(authUserId, Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), null, searchTerm);
|
| 31762 |
tejbeer |
504 |
}
|
| 27270 |
tejbeer |
505 |
|
| 31762 |
tejbeer |
506 |
} else {
|
| 27270 |
tejbeer |
507 |
|
| 31762 |
tejbeer |
508 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
| 35569 |
amit |
509 |
tickets = ticketRepository.selectAllByAssignee(authUserId, Optional.empty(), sortOrder, ticketSearchType, searchTerm);
|
|
|
510 |
size = ticketRepository.selectAllCountByAssignee(authUserId, Optional.empty(), ticketSearchType, searchTerm);
|
| 31762 |
tejbeer |
511 |
} else {
|
| 35569 |
amit |
512 |
tickets = ticketRepository.selectAllByAssignee(authUserId, Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), sortOrder, ticketSearchType, searchTerm);
|
|
|
513 |
size = ticketRepository.selectAllCountByAssignee(authUserId, Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), ticketSearchType, searchTerm);
|
| 31762 |
tejbeer |
514 |
}
|
|
|
515 |
}
|
|
|
516 |
// LOGGER.info(size + "size");
|
|
|
517 |
if (tickets.size() > 0) {
|
|
|
518 |
ticketAssigneds = ticketAssignedRepository.selectByTicketIds(tickets.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
|
|
519 |
authUserIdAndAuthUserMap = csService.getAuthUserIdAndAuthUserMap(ticketAssigneds);
|
|
|
520 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
521 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
|
|
522 |
}
|
| 24500 |
govind |
523 |
|
| 31762 |
tejbeer |
524 |
} else {
|
|
|
525 |
tickets = ticketRepository.selectAllByCreator(loginDetails.getFofoId(), Optional.of(TicketStatus.OPENED.equals(ticketStatus)), sortOrder);
|
|
|
526 |
size = ticketRepository.selectAllCountByCreator(loginDetails.getFofoId(), Optional.of(TicketStatus.OPENED.equals(ticketStatus)));
|
|
|
527 |
}
|
|
|
528 |
authUserIdAndAuthUserMap = csService.getTicketIdAndAuthUserMapUsingTickets(tickets);
|
| 35571 |
amit |
529 |
if (authUserIdAndAuthUserMap == null) {
|
|
|
530 |
authUserIdAndAuthUserMap = new HashMap<>();
|
|
|
531 |
}
|
| 24620 |
govind |
532 |
|
| 31762 |
tejbeer |
533 |
model.addAttribute("size", size);
|
| 35569 |
amit |
534 |
model.addAttribute("roleType", isAdmin);
|
|
|
535 |
// Check if user is in CRM category (only CRM can send external communications)
|
| 35571 |
amit |
536 |
boolean isCrmUser = isAdmin && currentAuthUser != null && positionRepository.hasCategory(currentAuthUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
| 35569 |
amit |
537 |
model.addAttribute("isCrmUser", isCrmUser);
|
| 24500 |
govind |
538 |
|
| 31762 |
tejbeer |
539 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
|
|
540 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
| 35571 |
amit |
541 |
if (subCategoryIdAndSubCategoryMap == null) {
|
|
|
542 |
subCategoryIdAndSubCategoryMap = new HashMap<>();
|
|
|
543 |
}
|
| 24747 |
govind |
544 |
|
| 31762 |
tejbeer |
545 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
| 35571 |
amit |
546 |
if (subCategoryIdAndCategoryMap == null) {
|
|
|
547 |
subCategoryIdAndCategoryMap = new HashMap<>();
|
|
|
548 |
}
|
| 27318 |
amit.gupta |
549 |
|
| 31762 |
tejbeer |
550 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 24500 |
govind |
551 |
|
| 35569 |
amit |
552 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
| 33864 |
ranu |
553 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
| 35569 |
amit |
554 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|
| 24500 |
govind |
555 |
|
| 31762 |
tejbeer |
556 |
if (!ticketIds.isEmpty()) {
|
| 35569 |
amit |
557 |
// Fetch activities once and group by both ticketId and activityId
|
|
|
558 |
List<Activity> allActivities = activityRepository.selectAll(ticketIds);
|
|
|
559 |
activityMap = allActivities.stream().collect(Collectors.groupingBy(Activity::getTicketId));
|
|
|
560 |
activityMapWithActivityId = allActivities.stream().collect(Collectors.groupingBy(Activity::getId));
|
| 24787 |
govind |
561 |
|
| 35569 |
amit |
562 |
// Only fetch AuthUsers who created activities (instead of all users)
|
|
|
563 |
Set<Integer> activityCreatorIds = allActivities.stream()
|
|
|
564 |
.map(Activity::getCreatedBy)
|
|
|
565 |
.filter(id -> id > 0)
|
|
|
566 |
.collect(Collectors.toSet());
|
|
|
567 |
if (!activityCreatorIds.isEmpty()) {
|
|
|
568 |
authUserMap = authRepository.selectByIds(new ArrayList<>(activityCreatorIds))
|
|
|
569 |
.stream().collect(Collectors.toMap(AuthUser::getId, x -> x));
|
|
|
570 |
}
|
| 31762 |
tejbeer |
571 |
}
|
| 24787 |
govind |
572 |
|
| 31762 |
tejbeer |
573 |
model.addAttribute("tickets", tickets);
|
|
|
574 |
model.addAttribute("resolved", ActivityType.RESOLVED);
|
|
|
575 |
model.addAttribute("resolved-accepted", ActivityType.RESOLVED_ACCEPTED);
|
|
|
576 |
model.addAttribute("resolved-rejected", ActivityType.RESOLVED_REJECTED);
|
|
|
577 |
model.addAttribute("authUserIdAndAuthUserMap", authUserIdAndAuthUserMap);
|
|
|
578 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
| 27318 |
amit.gupta |
579 |
|
| 31762 |
tejbeer |
580 |
model.addAttribute("subCategoryIdAndCategoryMap", subCategoryIdAndCategoryMap);
|
|
|
581 |
model.addAttribute("activityMap", activityMap);
|
| 33864 |
ranu |
582 |
model.addAttribute("authUserMap", authUserMap);
|
|
|
583 |
model.addAttribute("activityMapWithActivityId", activityMapWithActivityId);
|
| 24500 |
govind |
584 |
|
| 31762 |
tejbeer |
585 |
model.addAttribute("ticketStatusValues", TicketStatus.values());
|
|
|
586 |
model.addAttribute("orderByValues", SortOrder.values());
|
|
|
587 |
model.addAttribute("selectedticketStatus", ticketStatus);
|
|
|
588 |
model.addAttribute("selectedorderby", sortOrder);
|
|
|
589 |
model.addAttribute("ticketSearchTypes", TicketSearchType.values());
|
|
|
590 |
model.addAttribute("ticketSearchType", ticketSearchType);
|
|
|
591 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
592 |
return "ticket";
|
|
|
593 |
}
|
| 24500 |
govind |
594 |
|
| 27124 |
amit.gupta |
595 |
|
| 31762 |
tejbeer |
596 |
@GetMapping(value = "/cs/getActivities")
|
|
|
597 |
public String getActivity(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) throws Exception {
|
|
|
598 |
List<Activity> allactivities = activityRepository.selectAll(ticketId);
|
| 35570 |
amit |
599 |
|
|
|
600 |
// Batch fetch all documents for attachments (fix N+1 query)
|
|
|
601 |
List<Integer> documentIds = allactivities.stream()
|
|
|
602 |
.flatMap(a -> a.getActivityAttachment().stream())
|
|
|
603 |
.map(ActivityAttachment::getDocumentId)
|
|
|
604 |
.distinct()
|
|
|
605 |
.collect(Collectors.toList());
|
|
|
606 |
|
|
|
607 |
Map<Integer, Document> documentMap = Collections.emptyMap();
|
|
|
608 |
if (!documentIds.isEmpty()) {
|
|
|
609 |
documentMap = documentRepository.selectByIds(documentIds).stream()
|
|
|
610 |
.collect(Collectors.toMap(Document::getId, d -> d));
|
|
|
611 |
}
|
|
|
612 |
|
|
|
613 |
// Set document names transiently (do not persist during GET)
|
|
|
614 |
for (Activity activity : allactivities) {
|
|
|
615 |
for (ActivityAttachment attachment : activity.getActivityAttachment()) {
|
|
|
616 |
Document document = documentMap.get(attachment.getDocumentId());
|
|
|
617 |
if (document != null) {
|
|
|
618 |
attachment.setDocumentName(document.getDisplayName());
|
|
|
619 |
}
|
| 31762 |
tejbeer |
620 |
}
|
|
|
621 |
}
|
|
|
622 |
List<Activity> activities = null;
|
|
|
623 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
624 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
625 |
Set<Integer> authUserIds = allactivities.stream().map(x -> x.getCreatedBy()).collect(Collectors.toSet());
|
| 35395 |
amit |
626 |
List<AuthUser> users = authRepository.selectByIds(new ArrayList<>(authUserIds));
|
| 31762 |
tejbeer |
627 |
Map<Integer, String> authUserNameMap = users.stream().collect(Collectors.toMap(AuthUser::getId, x -> x.getFirstName() + " " + x.getLastName()));
|
|
|
628 |
allactivities.stream().forEach(x -> x.setName(authUserNameMap.get(x.getCreatedBy())));
|
|
|
629 |
activities = allactivities;
|
|
|
630 |
} else {
|
|
|
631 |
activities = allactivities.stream().filter(x -> ActivityType.PARTNER_ACTIVITIES.contains(x.getType())).collect(Collectors.toList());
|
|
|
632 |
}
|
|
|
633 |
if (activities == null) {
|
|
|
634 |
throw new ProfitMandiBusinessException("Activity", ticketId, "No Activity Found");
|
|
|
635 |
}
|
|
|
636 |
model.addAttribute("response1", mvcResponseSender.createResponseString(activities));
|
|
|
637 |
return "response";
|
| 24500 |
govind |
638 |
|
| 31762 |
tejbeer |
639 |
}
|
| 24620 |
govind |
640 |
|
| 31762 |
tejbeer |
641 |
@PostMapping(value = "/cs/createActivity")
|
|
|
642 |
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 |
643 |
|
| 31762 |
tejbeer |
644 |
Model model) throws Exception {
|
| 24620 |
govind |
645 |
|
| 31762 |
tejbeer |
646 |
LOGGER.info("documentIds" + documentIds);
|
|
|
647 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
648 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
649 |
List<TicketAssigned> ticketAssignedList = ticketAssignedRepository.selectByTicketIds(Arrays.asList(ticketId));
|
|
|
650 |
List<Integer> authUserIds = ticketAssignedList.stream().map(x -> x.getAssineeId()).collect(Collectors.toList());
|
|
|
651 |
authUserIds.add(ticketAssignedList.get(ticketAssignedList.size() - 1).getManagerId());
|
| 35395 |
amit |
652 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectByIds(authUserIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 31762 |
tejbeer |
653 |
if (ticket.getCloseTimestamp() == null) {
|
|
|
654 |
Activity activity = new Activity();
|
|
|
655 |
activity.setCreatedBy(0);
|
|
|
656 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
657 |
String subject = null;
|
|
|
658 |
String mailMessage = null;
|
|
|
659 |
activity.setMessage(message);
|
|
|
660 |
if (!roleManager.isAdmin(new HashSet<>(loginDetails.getRoleIds()))) {
|
|
|
661 |
CustomRetailer customRetailer = retailerService.getFofoRetailers(true).get(loginDetails.getFofoId());
|
|
|
662 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
|
|
663 |
subject = String.format("Ticket Update #%s by franchisee %s", ticket.getId(), customRetailer.getBusinessName() + "(" + customRetailer.getCode() + ")");
|
|
|
664 |
mailMessage = String.format("Franchisee message - %s", message);
|
|
|
665 |
} else {
|
|
|
666 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
667 |
activity.setCreatedBy(authUser.getId());
|
|
|
668 |
authUsersMap.remove(authUser.getId());
|
|
|
669 |
subject = String.format("Ticket Update #%s by %s", ticket.getId(), authUser.getName());
|
|
|
670 |
mailMessage = String.format("%s's message - %s", authUser.getFirstName(), message);
|
| 35569 |
amit |
671 |
// Only CRM users can send external communications
|
|
|
672 |
boolean isCrmUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
673 |
if (internal || !isCrmUser) {
|
| 31762 |
tejbeer |
674 |
activity.setType(ActivityType.COMMUNICATION_INTERNAL);
|
|
|
675 |
} else {
|
|
|
676 |
String updatedBy = "SD Team";
|
| 31854 |
amit.gupta |
677 |
CustomRetailer customRetailer = retailerService.getFofoRetailers(false).get(ticket.getFofoId());
|
| 31762 |
tejbeer |
678 |
subject = String.format("Ticket Update #%s by %s", ticket.getId(), updatedBy);
|
|
|
679 |
String partnerMessage = String.format("%s's message - %s", updatedBy, message);
|
|
|
680 |
this.activityRelatedMail(customRetailer.getEmail(), null, "subject", partnerMessage);
|
|
|
681 |
activity.setType(ActivityType.COMMUNICATION_OUT);
|
|
|
682 |
}
|
|
|
683 |
}
|
|
|
684 |
activityRepository.persist(activity);
|
|
|
685 |
|
|
|
686 |
for (Integer documentId : documentIds) {
|
|
|
687 |
ActivityAttachment activityAttachment = new ActivityAttachment();
|
|
|
688 |
activityAttachment.setActivityId(activity.getId());
|
|
|
689 |
activityAttachment.setDocumentId(documentId);
|
|
|
690 |
activityAttachmentRepository.persist(activityAttachment);
|
|
|
691 |
}
|
|
|
692 |
|
|
|
693 |
csService.addActivity(ticket, activity);
|
|
|
694 |
AuthUser authUser = authUsersMap.remove(authUserIds.get(0));
|
|
|
695 |
if (authUser == null) {
|
|
|
696 |
authUser = authUsersMap.remove(authUserIds.get(1));
|
|
|
697 |
}
|
|
|
698 |
model.addAttribute("response1", mvcResponseSender.createResponseString(authUser));
|
|
|
699 |
String[] cc = authUsersMap.entrySet().stream().map(x -> x.getValue().getEmailId()).toArray(String[]::new);
|
|
|
700 |
this.activityRelatedMail(authUser.getEmailId(), cc, subject, mailMessage);
|
|
|
701 |
} else {
|
|
|
702 |
throw new ProfitMandiBusinessException("Ticket", ticket.getId(), "Already closed ticket");
|
|
|
703 |
}
|
|
|
704 |
return "response";
|
|
|
705 |
}
|
|
|
706 |
|
|
|
707 |
private void activityRelatedMail(String to, String[] cc, String subject, String message) throws ProfitMandiBusinessException {
|
|
|
708 |
try {
|
|
|
709 |
Utils.sendMailWithAttachments(mailSender, to, cc, subject, message, null);
|
|
|
710 |
} catch (Exception e) {
|
|
|
711 |
throw new ProfitMandiBusinessException("Ticket Activity", to, "Could not send ticket activity mail");
|
|
|
712 |
}
|
|
|
713 |
}
|
|
|
714 |
|
|
|
715 |
@PostMapping(value = "/cs/closeTicket")
|
|
|
716 |
public String closeTicket(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, @RequestParam(name = "happyCode") String happyCode, Model model) throws Exception {
|
|
|
717 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
718 |
if (ticket.getHappyCode().equals(happyCode)) {
|
|
|
719 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
|
|
720 |
ticketRepository.persist(ticket);
|
|
|
721 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
722 |
} else {
|
|
|
723 |
throw new ProfitMandiBusinessException("Ticket", ticketId, "Happy Code can't match");
|
|
|
724 |
}
|
|
|
725 |
return "response";
|
|
|
726 |
}
|
|
|
727 |
|
| 34913 |
ranu |
728 |
@GetMapping(value = "/cs/myPartyTicketTicket")
|
|
|
729 |
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 {
|
|
|
730 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
731 |
long size = 0;
|
|
|
732 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
733 |
List<Ticket> tickets = new ArrayList<>();
|
|
|
734 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
|
|
735 |
Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
|
|
|
736 |
|
|
|
737 |
Map<Integer, List<AuthUser>> authUserListMap = null;
|
|
|
738 |
if (fofoIds != null && !fofoIds.isEmpty()) {
|
| 35571 |
amit |
739 |
// Batch fetch all open tickets for all fofoIds (fix N+1 query)
|
|
|
740 |
List<Ticket> allPartnerTickets = ticketRepository.selectAllOpenTickets(new ArrayList<>(fofoIds));
|
|
|
741 |
if (allPartnerTickets != null && !allPartnerTickets.isEmpty()) {
|
|
|
742 |
// Filter tickets where last_activity is not "RESOLVED"
|
|
|
743 |
tickets = allPartnerTickets.stream()
|
|
|
744 |
.filter(ticket -> ticket.getLastActivity() == null ||
|
|
|
745 |
ticket.getLastActivity() != ActivityType.RESOLVED)
|
|
|
746 |
.collect(Collectors.toList());
|
| 34913 |
ranu |
747 |
}
|
|
|
748 |
}
|
|
|
749 |
|
|
|
750 |
authUserListMap = csService.getAssignedAuthList(tickets);
|
|
|
751 |
|
|
|
752 |
|
|
|
753 |
if (tickets.size() > 0) {
|
|
|
754 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
755 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
|
|
756 |
}
|
|
|
757 |
|
|
|
758 |
model.addAttribute("size", tickets.size());
|
|
|
759 |
model.addAttribute("tickets", tickets);
|
|
|
760 |
|
|
|
761 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
|
|
762 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
| 35571 |
amit |
763 |
if (subCategoryIdAndSubCategoryMap == null) {
|
|
|
764 |
subCategoryIdAndSubCategoryMap = new HashMap<>();
|
|
|
765 |
}
|
| 34913 |
ranu |
766 |
|
|
|
767 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
| 35571 |
amit |
768 |
if (subCategoryIdAndCategoryMap == null) {
|
|
|
769 |
subCategoryIdAndCategoryMap = new HashMap<>();
|
|
|
770 |
}
|
| 34913 |
ranu |
771 |
|
|
|
772 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
773 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
|
|
774 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
| 35569 |
amit |
775 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|
| 34913 |
ranu |
776 |
|
|
|
777 |
if (!ticketIds.isEmpty()) {
|
| 35569 |
amit |
778 |
// Fetch activities once and group by both ticketId and activityId
|
|
|
779 |
List<Activity> allActivities = activityRepository.selectAll(ticketIds);
|
|
|
780 |
activityMap = allActivities.stream().collect(Collectors.groupingBy(Activity::getTicketId));
|
|
|
781 |
activityMapWithActivityId = allActivities.stream().collect(Collectors.groupingBy(Activity::getId));
|
| 34913 |
ranu |
782 |
|
| 35569 |
amit |
783 |
// Only fetch AuthUsers who created activities (instead of all users)
|
|
|
784 |
Set<Integer> activityCreatorIds = allActivities.stream()
|
|
|
785 |
.map(Activity::getCreatedBy)
|
|
|
786 |
.filter(id -> id > 0)
|
|
|
787 |
.collect(Collectors.toSet());
|
|
|
788 |
if (!activityCreatorIds.isEmpty()) {
|
|
|
789 |
authUserMap = authRepository.selectByIds(new ArrayList<>(activityCreatorIds))
|
|
|
790 |
.stream().collect(Collectors.toMap(AuthUser::getId, x -> x));
|
|
|
791 |
}
|
| 34913 |
ranu |
792 |
}
|
|
|
793 |
|
|
|
794 |
model.addAttribute("ticketStatusValues", TicketStatus.values());
|
|
|
795 |
model.addAttribute("orderByValues", SortOrder.values());
|
|
|
796 |
model.addAttribute("selectedticketStatus", ticketStatus);
|
|
|
797 |
model.addAttribute("selectedorderby", sortOrder);
|
|
|
798 |
model.addAttribute("tickets", tickets);
|
|
|
799 |
model.addAttribute("ticketSearchTypes", TicketSearchType.values());
|
|
|
800 |
model.addAttribute("ticketSearchType", ticketSearchType);
|
|
|
801 |
model.addAttribute("searchTerm", searchTerm);
|
| 35571 |
amit |
802 |
model.addAttribute("authUserListMap", authUserListMap != null ? authUserListMap : new HashMap<>());
|
| 34913 |
ranu |
803 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
|
|
804 |
|
|
|
805 |
model.addAttribute("subCategoryIdAndCategoryMap", subCategoryIdAndCategoryMap);
|
|
|
806 |
|
|
|
807 |
model.addAttribute("activityMap", activityMap);
|
|
|
808 |
model.addAttribute("authUserMap", authUserMap);
|
|
|
809 |
model.addAttribute("activityMapWithActivityId", activityMapWithActivityId);
|
| 35569 |
amit |
810 |
// Check if user is in CRM category (only CRM can send external communications)
|
|
|
811 |
boolean isCrmUser = positionRepository.hasCategory(authUser.getId(), ProfitMandiConstants.TICKET_CATEGORY_CRM);
|
|
|
812 |
model.addAttribute("isCrmUser", isCrmUser);
|
| 34913 |
ranu |
813 |
|
|
|
814 |
return "my-partner-tickets";
|
|
|
815 |
}
|
|
|
816 |
|
| 31762 |
tejbeer |
817 |
@GetMapping(value = "/cs/managerTicket")
|
|
|
818 |
public String getManagerTickets(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 {
|
|
|
819 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
820 |
long size = 0;
|
|
|
821 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
822 |
List<Ticket> tickets = null;
|
|
|
823 |
Map<Integer, List<AuthUser>> authUserListMap = null;
|
|
|
824 |
if (ticketSearchType == null) {
|
|
|
825 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
826 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder, Optional.empty(), null, searchTerm);
|
|
|
827 |
size = ticketRepository.selectAllCountByManagerTicket(authUser.getId(), Optional.empty(), null, 0);
|
|
|
828 |
} else {
|
|
|
829 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder, Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), null, searchTerm);
|
|
|
830 |
size = ticketRepository.selectAllCountByManagerTicket(authUser.getId(), Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), null, 0);
|
|
|
831 |
}
|
|
|
832 |
} else {
|
|
|
833 |
if (ticketStatus.equals(TicketStatus.RESOLVED)) {
|
|
|
834 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder, Optional.empty(), ticketSearchType, searchTerm);
|
|
|
835 |
size = ticketRepository.selectAllCountByManagerTicket(authUser.getId(), Optional.empty(), ticketSearchType, searchTerm);
|
|
|
836 |
} else {
|
|
|
837 |
tickets = ticketRepository.selectAllManagerTicket(authUser.getId(), sortOrder, Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), ticketSearchType, searchTerm);
|
|
|
838 |
size = ticketRepository.selectAllCountByManagerTicket(authUser.getId(), Optional.of(TicketStatus.CLOSED.equals(ticketStatus)), ticketSearchType, searchTerm);
|
|
|
839 |
}
|
|
|
840 |
|
|
|
841 |
}
|
|
|
842 |
authUserListMap = csService.getAssignedAuthList(tickets);
|
|
|
843 |
|
|
|
844 |
if (tickets.size() > 0) {
|
|
|
845 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = csService.getPartnerByFofoIds(tickets);
|
|
|
846 |
model.addAttribute("fofoIdsAndCustomRetailer", fofoIdsAndCustomRetailer);
|
|
|
847 |
}
|
|
|
848 |
|
|
|
849 |
model.addAttribute("size", size);
|
|
|
850 |
model.addAttribute("tickets", tickets);
|
|
|
851 |
|
|
|
852 |
List<Integer> subCategoryIds = tickets.stream().map(x -> x.getSubCategoryId()).collect(Collectors.toList());
|
|
|
853 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = csService.getSubCategoryIdAndSubCategoryMap(subCategoryIds);
|
| 35571 |
amit |
854 |
if (subCategoryIdAndSubCategoryMap == null) {
|
|
|
855 |
subCategoryIdAndSubCategoryMap = new HashMap<>();
|
|
|
856 |
}
|
| 31762 |
tejbeer |
857 |
|
|
|
858 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
| 35571 |
amit |
859 |
if (subCategoryIdAndCategoryMap == null) {
|
|
|
860 |
subCategoryIdAndCategoryMap = new HashMap<>();
|
|
|
861 |
}
|
| 31762 |
tejbeer |
862 |
|
|
|
863 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
864 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
| 33778 |
ranu |
865 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
| 35570 |
amit |
866 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|
| 31762 |
tejbeer |
867 |
|
|
|
868 |
if (!ticketIds.isEmpty()) {
|
| 35570 |
amit |
869 |
// Fetch activities once and reuse for both maps (fix duplicate query)
|
|
|
870 |
List<Activity> allActivities = activityRepository.selectAll(ticketIds);
|
|
|
871 |
activityMap = allActivities.stream().collect(Collectors.groupingBy(Activity::getTicketId));
|
|
|
872 |
activityMapWithActivityId = allActivities.stream().collect(Collectors.groupingBy(Activity::getId));
|
| 31762 |
tejbeer |
873 |
|
| 35570 |
amit |
874 |
// Only fetch users who created activities (fix loading ALL users)
|
|
|
875 |
Set<Integer> activityCreatorIds = allActivities.stream()
|
|
|
876 |
.map(Activity::getCreatedBy)
|
|
|
877 |
.filter(id -> id > 0)
|
|
|
878 |
.collect(Collectors.toSet());
|
|
|
879 |
if (!activityCreatorIds.isEmpty()) {
|
|
|
880 |
authUserMap = authRepository.selectByIds(new ArrayList<>(activityCreatorIds))
|
|
|
881 |
.stream().collect(Collectors.toMap(AuthUser::getId, x -> x));
|
|
|
882 |
}
|
| 31762 |
tejbeer |
883 |
}
|
| 33778 |
ranu |
884 |
|
| 31762 |
tejbeer |
885 |
model.addAttribute("ticketStatusValues", TicketStatus.values());
|
|
|
886 |
model.addAttribute("orderByValues", SortOrder.values());
|
|
|
887 |
model.addAttribute("selectedticketStatus", ticketStatus);
|
|
|
888 |
model.addAttribute("selectedorderby", sortOrder);
|
|
|
889 |
model.addAttribute("tickets", tickets);
|
|
|
890 |
model.addAttribute("ticketSearchTypes", TicketSearchType.values());
|
|
|
891 |
model.addAttribute("ticketSearchType", ticketSearchType);
|
|
|
892 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
893 |
model.addAttribute("authUserListMap", authUserListMap);
|
|
|
894 |
model.addAttribute("subCategoryIdAndSubCategoryMap", subCategoryIdAndSubCategoryMap);
|
|
|
895 |
|
|
|
896 |
model.addAttribute("subCategoryIdAndCategoryMap", subCategoryIdAndCategoryMap);
|
|
|
897 |
|
|
|
898 |
model.addAttribute("activityMap", activityMap);
|
| 33778 |
ranu |
899 |
model.addAttribute("authUserMap", authUserMap);
|
|
|
900 |
model.addAttribute("activityMapWithActivityId", activityMapWithActivityId);
|
| 31762 |
tejbeer |
901 |
|
|
|
902 |
return "managerTicket";
|
|
|
903 |
}
|
|
|
904 |
|
|
|
905 |
|
|
|
906 |
@GetMapping(value = "/cs/edit-ticket")
|
|
|
907 |
public String getEditTicket(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) {
|
|
|
908 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
909 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
|
|
910 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
911 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll(ticketSubCategory.getCategoryId());
|
|
|
912 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
|
|
913 |
model.addAttribute("ticket", ticket);
|
|
|
914 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
915 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
|
|
916 |
model.addAttribute("ticketSubCategory", ticketSubCategory);
|
|
|
917 |
model.addAttribute("authUsers", authUsers);
|
|
|
918 |
return "edit-ticket-modal";
|
|
|
919 |
}
|
|
|
920 |
|
| 34913 |
ranu |
921 |
@GetMapping(value = "/cs/edit-partner-ticket")
|
|
|
922 |
public String getEditPartnerTicket(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) {
|
|
|
923 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
924 |
List<TicketCategory> ticketCategories = csService.getAllTicketCategotyFromSubCategory();
|
|
|
925 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
926 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll(ticketSubCategory.getCategoryId());
|
|
|
927 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
|
|
928 |
model.addAttribute("ticket", ticket);
|
|
|
929 |
model.addAttribute("ticketCategories", ticketCategories);
|
|
|
930 |
model.addAttribute("ticketSubCategories", ticketSubCategories);
|
|
|
931 |
model.addAttribute("ticketSubCategory", ticketSubCategory);
|
|
|
932 |
model.addAttribute("authUsers", authUsers);
|
|
|
933 |
return "edit-ticket-partner-modal";
|
|
|
934 |
}
|
|
|
935 |
|
| 31762 |
tejbeer |
936 |
@PostMapping(value = "/cs/edit-ticket")
|
|
|
937 |
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 {
|
|
|
938 |
LOGGER.info("Ticket Id {}, CategoryId {}, SubCategory Id {} authUserId {}", ticketId, categoryId, subCategoryId, authUserId);
|
|
|
939 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
940 |
csService.updateTicket(categoryId, subCategoryId, ticket, authUserId, escalationType);
|
|
|
941 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
942 |
return "response";
|
|
|
943 |
|
|
|
944 |
}
|
|
|
945 |
|
| 34913 |
ranu |
946 |
@PostMapping(value = "/cs/edit-partner-ticket")
|
|
|
947 |
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 {
|
|
|
948 |
LOGGER.info("Ticket Id {}, CategoryId {}, SubCategory Id {} authUserId {}", ticketId, categoryId, subCategoryId, authUserId);
|
|
|
949 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
950 |
csService.updateTicket(categoryId, subCategoryId, ticket, authUserId, escalationType);
|
|
|
951 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
952 |
return "response";
|
|
|
953 |
|
|
|
954 |
}
|
|
|
955 |
|
| 31762 |
tejbeer |
956 |
@PostMapping(value = "/cs/changeTicketAssignee")
|
|
|
957 |
public String changeTicketAssignee(HttpServletRequest request, @RequestParam(name = "positionId", defaultValue = "0") int positionId, Model model) throws Exception {
|
|
|
958 |
Position position = positionRepository.selectById(positionId);
|
|
|
959 |
if (position.isTicketAssignee()) {
|
|
|
960 |
position.setTicketAssignee(false);
|
|
|
961 |
} else {
|
|
|
962 |
position.setTicketAssignee(true);
|
|
|
963 |
}
|
|
|
964 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
965 |
return "response";
|
|
|
966 |
}
|
|
|
967 |
|
|
|
968 |
|
|
|
969 |
@DeleteMapping(value = "/cs/removePosition")
|
|
|
970 |
public String removePosition(HttpServletRequest request, @RequestParam(name = "positionId", defaultValue = "0") int positionId, Model model) throws Exception {
|
|
|
971 |
positionRepository.delete(positionId);
|
|
|
972 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
973 |
return "response";
|
|
|
974 |
}
|
|
|
975 |
|
|
|
976 |
@PostMapping(value = "/cs/create-last-activity")
|
|
|
977 |
public String createlastActivity(HttpServletRequest request, @RequestParam(name = "ticketId") int ticketId, @RequestParam(name = "lastactivity") ActivityType lastActivity, Model model) throws Exception {
|
|
|
978 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
979 |
Ticket ticket = ticketRepository.selectById(ticketId);
|
|
|
980 |
Activity activity = new Activity();
|
|
|
981 |
String subject = String.format(ACTIVITY_SUBJECT, ticket.getId());
|
|
|
982 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
983 |
ticket.setLastActivity(lastActivity);
|
|
|
984 |
String to = retailerService.getFofoRetailer(ticket.getFofoId()).getEmail();
|
|
|
985 |
String message = String.format(PARTNER_RESOLVED_TICKET_MAIL, ticketId, "REOPEN");
|
|
|
986 |
activity.setMessage(message);
|
|
|
987 |
activity.setCreatedBy(authRepository.selectByEmailOrMobile(loginDetails.getEmailId()).getId());
|
|
|
988 |
activity.setTicketId(ticketId);
|
|
|
989 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
990 |
activity.setType(ActivityType.COMMUNICATION_OUT);
|
|
|
991 |
this.activityRelatedMail(to, null, subject, message);
|
|
|
992 |
} else {
|
|
|
993 |
if (ActivityType.RESOLVED_ACCEPTED == lastActivity) {
|
|
|
994 |
ticket.setLastActivity(lastActivity);
|
|
|
995 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
|
|
996 |
activity.setMessage(ActivityType.RESOLVED_ACCEPTED.toString());
|
|
|
997 |
activity.setCreatedBy(0);
|
|
|
998 |
activity.setTicketId(ticketId);
|
|
|
999 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
|
|
1000 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
1001 |
} else {
|
|
|
1002 |
String message = String.format(INTERNAL_REOPEN_MAIL, ticketId, retailerService.getFofoRetailer(loginDetails.getFofoId()).getBusinessName());
|
|
|
1003 |
String to = authRepository.selectById(ticket.getL1AuthUser()).getEmailId();
|
| 35395 |
amit |
1004 |
String[] ccTo = authRepository.selectByIds(Arrays.asList(ticket.getL2AuthUser(), ticket.getL3AuthUser(), ticket.getL4AuthUser(), ticket.getL5AuthUser())).stream().map(x -> x.getEmailId()).toArray(String[]::new);
|
| 31762 |
tejbeer |
1005 |
ticket.setLastActivity(lastActivity);
|
|
|
1006 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
1007 |
ticketAssignedRepository.deleteByTicketId(ticketId);
|
|
|
1008 |
TicketAssigned ticketAssigned = new TicketAssigned();
|
|
|
1009 |
ticketAssigned.setAssineeId(ticket.getL1AuthUser());
|
|
|
1010 |
ticketAssigned.setTicketId(ticketId);
|
|
|
1011 |
ticketAssignedRepository.persist(ticketAssigned);
|
|
|
1012 |
activity.setMessage(INTERNAL_REOPEN_ACTIVITY_MESSAGE);
|
|
|
1013 |
activity.setCreatedBy(0);
|
|
|
1014 |
activity.setTicketId(ticketId);
|
|
|
1015 |
activity.setType(ActivityType.COMMUNICATION_IN);
|
|
|
1016 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
1017 |
this.activityRelatedMail(to, ccTo, subject, message);
|
|
|
1018 |
this.activityRelatedMail(retailerService.getFofoRetailer(loginDetails.getFofoId()).getEmail(), null, subject, String.format(PARTNER_REOPEN, ticketId));
|
|
|
1019 |
}
|
|
|
1020 |
|
|
|
1021 |
}
|
|
|
1022 |
activityRepository.persist(activity);
|
|
|
1023 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
1024 |
return "response";
|
|
|
1025 |
}
|
|
|
1026 |
|
| 32812 |
shampa |
1027 |
|
|
|
1028 |
|
|
|
1029 |
|
|
|
1030 |
|
|
|
1031 |
@PostMapping(value = "/partner-position/update")
|
|
|
1032 |
public String positionUpdated(Model model, @RequestBody List<PartnerPositonUpdateModel> partnerPositionUpdateModels)
|
|
|
1033 |
throws Exception {
|
|
|
1034 |
|
| 32821 |
shampa |
1035 |
Map<Integer, List<String>> positionIdsToAddMap = partnerPositionUpdateModels.stream().filter(x->x.getPositionIdTo()!=0).collect(Collectors.groupingBy(x->x.getPositionIdTo(),
|
| 32812 |
shampa |
1036 |
Collectors.mapping(x->x.getStoreCode(), Collectors.toList())));
|
|
|
1037 |
|
| 32821 |
shampa |
1038 |
Map<Integer, List<String>> positionIdsToRemoveMap = partnerPositionUpdateModels.stream().filter(x->x.getPositionIdFrom()!=0).collect(Collectors.groupingBy(x->x.getPositionIdFrom(),
|
| 32812 |
shampa |
1039 |
Collectors.mapping(x->x.getStoreCode(), Collectors.toList())));
|
|
|
1040 |
|
|
|
1041 |
List<Integer> positionIdsToUpdate = new ArrayList<>();
|
|
|
1042 |
positionIdsToUpdate.addAll(positionIdsToAddMap.keySet());
|
|
|
1043 |
positionIdsToUpdate.addAll(positionIdsToRemoveMap.keySet());
|
|
|
1044 |
|
| 35395 |
amit |
1045 |
Map<Integer, Position> positionsToUpdateMap = positionRepository.selectByIds(positionIdsToUpdate).stream().collect(Collectors.toMap(x->x.getId(), x->x));
|
| 32812 |
shampa |
1046 |
List<Integer> invalidPositionIds = positionsToUpdateMap.values().stream().filter(x-> x.getCategoryId()!= ProfitMandiConstants.TICKET_CATEGORY_RBM
|
| 34908 |
ranu |
1047 |
&& x.getCategoryId() != ProfitMandiConstants.TICKET_CATEGORY_SALES && x.getCategoryId() != ProfitMandiConstants.TICKET_CATEGORY_ABM).map(x -> x.getId()).collect(Collectors.toList());
|
| 32812 |
shampa |
1048 |
if(invalidPositionIds.size() > 0) {
|
| 34908 |
ranu |
1049 |
String message = "Non RBM/Sales/ABM are not allowed - " + invalidPositionIds;
|
| 32812 |
shampa |
1050 |
throw new ProfitMandiBusinessException(message, message, message);
|
|
|
1051 |
}
|
|
|
1052 |
|
|
|
1053 |
for (Map.Entry<Integer, List<String>> positionIdStoreMapEntry : positionIdsToAddMap.entrySet()) {
|
|
|
1054 |
int positionId = positionIdStoreMapEntry.getKey();
|
|
|
1055 |
Position position = positionsToUpdateMap.get(positionId);
|
| 32821 |
shampa |
1056 |
LOGGER.info("positionId - {}, Position - {}", positionId, position);
|
| 32812 |
shampa |
1057 |
List<String> storeCodesToAdd = positionIdStoreMapEntry.getValue();
|
|
|
1058 |
List<Integer> retailerIdsToAdd = fofoStoreRepository.selectByStoreCodes(storeCodesToAdd).stream().map(x->x.getId()).collect(Collectors.toList());
|
|
|
1059 |
Map<Integer, PartnerPosition> partnerPositionsMapByFofoId = partnerPositionRepository
|
| 32821 |
shampa |
1060 |
.selectByRegionIdAndPostionId(Arrays.asList(position.getRegionId())
|
|
|
1061 |
,Arrays.asList(positionId)).stream().collect(Collectors.toMap(x->x.getFofoId(),x->x));
|
| 32812 |
shampa |
1062 |
for (Integer retailerIdToAdd : retailerIdsToAdd) {
|
|
|
1063 |
if (!partnerPositionsMapByFofoId.containsKey(retailerIdToAdd)) {
|
|
|
1064 |
PartnerPosition partnerPositionNew = new PartnerPosition();
|
|
|
1065 |
partnerPositionNew.setPositionId(positionId);
|
|
|
1066 |
partnerPositionNew.setFofoId(retailerIdToAdd);
|
|
|
1067 |
partnerPositionNew.setRegionId(position.getRegionId());
|
| 32865 |
amit.gupta |
1068 |
partnerPositionRepository.persist(partnerPositionNew);
|
| 32812 |
shampa |
1069 |
}
|
|
|
1070 |
}
|
|
|
1071 |
}
|
|
|
1072 |
|
|
|
1073 |
for (Map.Entry<Integer, List<String>> positionIdStoreMapEntry : positionIdsToRemoveMap.entrySet()) {
|
|
|
1074 |
|
|
|
1075 |
int positionId = positionIdStoreMapEntry.getKey();
|
|
|
1076 |
Position position = positionsToUpdateMap.get(positionId);
|
|
|
1077 |
List<String> storeCodesToRemove = positionIdStoreMapEntry.getValue();
|
|
|
1078 |
List<Integer> retailerIdsToRemove = fofoStoreRepository.selectByStoreCodes(storeCodesToRemove).stream().map(x->x.getId()).collect(Collectors.toList());
|
|
|
1079 |
Map<Integer, PartnerPosition> partnerPositionsMapByFofoId = partnerPositionRepository
|
|
|
1080 |
.selectByRegionIdAndPostionId(Arrays.asList(position.getRegionId()),Arrays.asList(positionId)).stream().collect(Collectors.toMap(x->x.getFofoId(),x->x));
|
|
|
1081 |
for (Integer retailerIdToRemove : retailerIdsToRemove) {
|
|
|
1082 |
if (partnerPositionsMapByFofoId.containsKey(retailerIdToRemove)) {
|
|
|
1083 |
PartnerPosition partnerPositionToRemove = partnerPositionsMapByFofoId.get(retailerIdToRemove);
|
|
|
1084 |
partnerPositionRepository.delete(partnerPositionToRemove);
|
|
|
1085 |
}
|
|
|
1086 |
}
|
|
|
1087 |
}
|
|
|
1088 |
|
|
|
1089 |
|
|
|
1090 |
|
|
|
1091 |
/*partnerPositionUpdateModels.str
|
|
|
1092 |
|
|
|
1093 |
Map<Integer, Position> positionIdMap = positionsToUpdate.stream().collect(Collectors.toMap(x->x.getId(), x->x));
|
|
|
1094 |
for (PartnerPositonUpdateModel partnerPositionUpdateModel : partnerPositionUpdateModels) {
|
|
|
1095 |
FofoStore fofoStore = fofoStoreRepository.selectByStoreCode(partnerPositionUpdateModel.getStoreCode());
|
|
|
1096 |
Position positionFrom = positionIdMap.get(partnerPositionUpdateModel.getPositionIdFrom());
|
|
|
1097 |
Position positionTo = positionIdMap.get(partnerPositionUpdateModel.getPositionIdTo());
|
|
|
1098 |
if(positionFrom != null) {
|
|
|
1099 |
partnerPositionRepository.selectByRegionIdAndPostionId(Arrays.)
|
|
|
1100 |
int regionId = positionFrom.getRegionId()
|
|
|
1101 |
}
|
|
|
1102 |
if(positionTo != null) {
|
|
|
1103 |
|
|
|
1104 |
}
|
|
|
1105 |
}*/
|
|
|
1106 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
|
|
1107 |
return "response";
|
|
|
1108 |
|
|
|
1109 |
}
|
|
|
1110 |
|
|
|
1111 |
|
| 24417 |
govind |
1112 |
}
|