| Line 55... |
Line 55... |
| 55 |
@Autowired
|
55 |
@Autowired
|
| 56 |
private ObjectMapper objectMapper;
|
56 |
private ObjectMapper objectMapper;
|
| 57 |
|
57 |
|
| 58 |
@RequestMapping(value = "/manageHotDeals", method = RequestMethod.GET)
|
58 |
@RequestMapping(value = "/manageHotDeals", method = RequestMethod.GET)
|
| 59 |
public String manageHotDeals(HttpServletRequest request, Model model) throws Exception {
|
59 |
public String manageHotDeals(HttpServletRequest request, Model model) throws Exception {
|
| - |
|
60 |
model.addAttribute("oemBrands", modelHotDealService.oemBrandNames());
|
| 60 |
return "hot-deals";
|
61 |
return "hot-deals";
|
| 61 |
}
|
62 |
}
|
| 62 |
|
63 |
|
| - |
|
64 |
/**
|
| 63 |
/** All hot deal models: server-side searched + paginated table fragment. */
|
65 |
* Every Hot Deal-brand model, with or without an attributes row: server-side searched +
|
| - |
|
66 |
* paginated table fragment. {@code attention} narrows to models missing attributes or an
|
| - |
|
67 |
* OEM brand - the ones that silently drop out of the partner app's brand chips.
|
| - |
|
68 |
*/
|
| 64 |
@RequestMapping(value = "/hotDeals/all", method = RequestMethod.GET)
|
69 |
@RequestMapping(value = "/hotDeals/all", method = RequestMethod.GET)
|
| 65 |
public String getAllHotDeals(@RequestParam(defaultValue = "1") int page,
|
70 |
public String getAllHotDeals(@RequestParam(defaultValue = "1") int page,
|
| 66 |
@RequestParam(required = false, defaultValue = "") String q,
|
71 |
@RequestParam(required = false, defaultValue = "") String q,
|
| - |
|
72 |
@RequestParam(required = false, defaultValue = "false") boolean attention,
|
| 67 |
Model model) throws Exception {
|
73 |
Model model) throws Exception {
|
| 68 |
int pageSize = 20;
|
74 |
int pageSize = 20;
|
| 69 |
long total = modelHotDealService.countDeals(q);
|
75 |
long total = modelHotDealService.countDeals(q, attention);
|
| 70 |
int pages = (int) Math.max(1, (total + pageSize - 1) / pageSize);
|
76 |
int pages = (int) Math.max(1, (total + pageSize - 1) / pageSize);
|
| 71 |
page = Math.min(Math.max(1, page), pages);
|
77 |
page = Math.min(Math.max(1, page), pages);
|
| - |
|
78 |
long[] stats = modelHotDealService.stats();
|
| 72 |
model.addAttribute("deals", modelHotDealService.listAll(q, page, pageSize));
|
79 |
model.addAttribute("deals", modelHotDealService.listAll(q, attention, page, pageSize));
|
| - |
|
80 |
model.addAttribute("oemBrands", modelHotDealService.oemBrandNames());
|
| - |
|
81 |
model.addAttribute("statTotal", stats[0]);
|
| - |
|
82 |
model.addAttribute("statNoAttributes", stats[1]);
|
| - |
|
83 |
model.addAttribute("statNoOemBrand", stats[2]);
|
| - |
|
84 |
model.addAttribute("attention", attention);
|
| 73 |
model.addAttribute("total", total);
|
85 |
model.addAttribute("total", total);
|
| 74 |
model.addAttribute("page", page);
|
86 |
model.addAttribute("page", page);
|
| 75 |
model.addAttribute("pages", pages);
|
87 |
model.addAttribute("pages", pages);
|
| 76 |
return "hot-deals-table";
|
88 |
return "hot-deals-table";
|
| 77 |
}
|
89 |
}
|
| Line 83... |
Line 95... |
| 83 |
*/
|
95 |
*/
|
| 84 |
@RequestMapping(value = "/hotDeals/models", method = RequestMethod.GET)
|
96 |
@RequestMapping(value = "/hotDeals/models", method = RequestMethod.GET)
|
| 85 |
public String getHotDealModels(Model model) throws Exception {
|
97 |
public String getHotDealModels(Model model) throws Exception {
|
| 86 |
List<Catalog> catalogs = catalogRepository.selectAllByCatalogIds(new java.util.ArrayList<>(
|
98 |
List<Catalog> catalogs = catalogRepository.selectAllByCatalogIds(new java.util.ArrayList<>(
|
| 87 |
catalogRepository.selectCatalogIdsByBrand(ProfitMandiConstants.HOT_DEAL_BRAND)));
|
99 |
catalogRepository.selectCatalogIdsByBrand(ProfitMandiConstants.HOT_DEAL_BRAND)));
|
| - |
|
100 |
// model_name holds the original brand on Hot Deal models; offered only when it is a real brand
|
| - |
|
101 |
Map<String, String> brandByLowerName = new HashMap<>();
|
| - |
|
102 |
for (String brand : modelHotDealService.oemBrandNames()) {
|
| - |
|
103 |
brandByLowerName.put(brand.toLowerCase(), brand);
|
| - |
|
104 |
}
|
| 88 |
List<Map<String, Object>> models = catalogs.stream()
|
105 |
List<Map<String, Object>> models = catalogs.stream()
|
| 89 |
.map(catalog -> {
|
106 |
.map(catalog -> {
|
| 90 |
Map<String, Object> entry = new HashMap<>();
|
107 |
Map<String, Object> entry = new HashMap<>();
|
| 91 |
entry.put("catalogId", catalog.getId());
|
108 |
entry.put("catalogId", catalog.getId());
|
| 92 |
entry.put("description", catalog.getDescription());
|
109 |
entry.put("description", catalog.getDescription());
|
| 93 |
// Drives the OEM mapping autosuggest, which is scoped to this brand.
|
110 |
// Pre-fills the OEM brand picker, which in turn scopes the OEM model autosuggest.
|
| 94 |
ModelHotDeal attributes = modelHotDealService.getAttributes(catalog.getId());
|
111 |
ModelHotDeal attributes = modelHotDealService.getAttributes(catalog.getId());
|
| 95 |
entry.put("oemBrand", attributes == null ? "" : attributes.getOemBrand());
|
112 |
String stored = attributes == null ? null : attributes.getOemBrand();
|
| - |
|
113 |
String suggested = catalog.getModelName() == null ? null
|
| - |
|
114 |
: brandByLowerName.get(catalog.getModelName().trim().toLowerCase());
|
| - |
|
115 |
entry.put("oemBrand", stored != null ? stored : (suggested == null ? "" : suggested));
|
| - |
|
116 |
entry.put("oemBrandSuggested", stored == null && suggested != null);
|
| 96 |
return entry;
|
117 |
return entry;
|
| 97 |
})
|
118 |
})
|
| 98 |
.collect(Collectors.toList());
|
119 |
.collect(Collectors.toList());
|
| 99 |
model.addAttribute("response1", objectMapper.writeValueAsString(models));
|
120 |
model.addAttribute("response1", objectMapper.writeValueAsString(models));
|
| 100 |
return "response";
|
121 |
return "response";
|
| Line 111... |
Line 132... |
| 111 |
@RequestParam(required = false) Integer warrantyMonths,
|
132 |
@RequestParam(required = false) Integer warrantyMonths,
|
| 112 |
@RequestParam(required = false) String condition,
|
133 |
@RequestParam(required = false) String condition,
|
| 113 |
@RequestParam(required = false) Boolean fresh,
|
134 |
@RequestParam(required = false) Boolean fresh,
|
| 114 |
@RequestParam(required = false) Boolean financeMapping,
|
135 |
@RequestParam(required = false) Boolean financeMapping,
|
| 115 |
@RequestParam(required = false) Boolean affordability,
|
136 |
@RequestParam(required = false) Boolean affordability,
|
| - |
|
137 |
@RequestParam(required = false) String oemBrand,
|
| 116 |
@RequestParam(required = false) Integer oemCatalogId,
|
138 |
@RequestParam(required = false) Integer oemCatalogId,
|
| 117 |
Model model) throws Exception {
|
139 |
Model model) throws Exception {
|
| 118 |
// required=false so a missing field reaches the service's mandatory-field
|
140 |
// required=false so a missing field reaches the service's mandatory-field
|
| 119 |
// validation and comes back as a readable message instead of a Spring 400
|
141 |
// validation and comes back as a readable message instead of a Spring 400
|
| 120 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
142 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 121 |
try {
|
143 |
try {
|
| 122 |
HotDealAttributes attributes = new HotDealAttributes(warrantyMonths, condition,
|
144 |
HotDealAttributes attributes = new HotDealAttributes(warrantyMonths, condition,
|
| 123 |
fresh, financeMapping, affordability);
|
145 |
fresh, financeMapping, affordability);
|
| 124 |
modelHotDealService.saveAttributes(catalogItemId, attributes, oemCatalogId, loginDetails.getEmailId());
|
146 |
modelHotDealService.saveAttributes(catalogItemId, attributes, oemBrand, oemCatalogId,
|
| - |
|
147 |
loginDetails.getEmailId());
|
| 125 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
148 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 126 |
} catch (ProfitMandiBusinessException e) {
|
149 |
} catch (ProfitMandiBusinessException e) {
|
| 127 |
LOGGER.warn("Hot deal attributes rejected: {}", e.getMessage());
|
150 |
LOGGER.warn("Hot deal attributes rejected: {}", e.getMessage());
|
| 128 |
model.addAttribute("response1", e.getMessage());
|
151 |
model.addAttribute("response1", e.getMessage());
|
| 129 |
}
|
152 |
}
|