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