| Line 6... |
Line 6... |
| 6 |
import com.spice.profitmandi.dao.entity.catalog.ModelHotDeal;
|
6 |
import com.spice.profitmandi.dao.entity.catalog.ModelHotDeal;
|
| 7 |
import com.spice.profitmandi.dao.repository.catalog.CatalogRepository;
|
7 |
import com.spice.profitmandi.dao.repository.catalog.CatalogRepository;
|
| 8 |
import com.spice.profitmandi.service.catalog.BrandsService;
|
8 |
import com.spice.profitmandi.service.catalog.BrandsService;
|
| 9 |
import com.spice.profitmandi.service.catalog.HotDealAttributes;
|
9 |
import com.spice.profitmandi.service.catalog.HotDealAttributes;
|
| 10 |
import com.spice.profitmandi.service.catalog.ModelHotDealService;
|
10 |
import com.spice.profitmandi.service.catalog.ModelHotDealService;
|
| - |
|
11 |
import com.spice.profitmandi.dao.service.solr.FofoSolr;
|
| 11 |
import com.spice.profitmandi.web.model.LoginDetails;
|
12 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 12 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
13 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 13 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
14 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 14 |
import org.slf4j.Logger;
|
15 |
import org.slf4j.Logger;
|
| 15 |
import org.slf4j.LoggerFactory;
|
16 |
import org.slf4j.LoggerFactory;
|
| Line 109... |
Line 110... |
| 109 |
public String addHotDeal(HttpServletRequest request, @RequestParam int brandId,
|
110 |
public String addHotDeal(HttpServletRequest request, @RequestParam int brandId,
|
| 110 |
@RequestParam int catalogItemId, @RequestParam String startDate,
|
111 |
@RequestParam int catalogItemId, @RequestParam String startDate,
|
| 111 |
@RequestParam String endDate,
|
112 |
@RequestParam String endDate,
|
| 112 |
@RequestParam(required = false) Integer warrantyMonths,
|
113 |
@RequestParam(required = false) Integer warrantyMonths,
|
| 113 |
@RequestParam(required = false) String condition,
|
114 |
@RequestParam(required = false) String condition,
|
| 114 |
@RequestParam(required = false) Boolean activated,
|
115 |
@RequestParam(required = false) Boolean fresh,
|
| 115 |
@RequestParam(required = false) Boolean financeMapping,
|
116 |
@RequestParam(required = false) Boolean financeMapping,
|
| 116 |
@RequestParam(required = false) Boolean affordability,
|
117 |
@RequestParam(required = false) Boolean affordability,
|
| 117 |
Model model) throws Exception {
|
118 |
Model model) throws Exception {
|
| 118 |
// required=false so a missing field reaches the service's mandatory-field
|
119 |
// 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
|
120 |
// validation and comes back as a readable message instead of a Spring 400
|
| 120 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
121 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 121 |
try {
|
122 |
try {
|
| 122 |
HotDealAttributes attributes = new HotDealAttributes(warrantyMonths, condition,
|
123 |
HotDealAttributes attributes = new HotDealAttributes(warrantyMonths, condition,
|
| 123 |
activated, financeMapping, affordability);
|
124 |
fresh, financeMapping, affordability);
|
| 124 |
modelHotDealService.addDeal(brandId, catalogItemId, LocalDate.parse(startDate),
|
125 |
modelHotDealService.addDeal(brandId, catalogItemId, LocalDate.parse(startDate),
|
| 125 |
LocalDate.parse(endDate), attributes, loginDetails.getEmailId());
|
126 |
LocalDate.parse(endDate), attributes, loginDetails.getEmailId());
|
| 126 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
127 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 127 |
} catch (ProfitMandiBusinessException e) {
|
128 |
} catch (ProfitMandiBusinessException e) {
|
| 128 |
LOGGER.warn("Hot deal add rejected: {}", e.getMessage());
|
129 |
LOGGER.warn("Hot deal add rejected: {}", e.getMessage());
|
| Line 134... |
Line 135... |
| 134 |
@RequestMapping(value = "/hotDeals/update", method = RequestMethod.POST)
|
135 |
@RequestMapping(value = "/hotDeals/update", method = RequestMethod.POST)
|
| 135 |
public String updateHotDeal(HttpServletRequest request, @RequestParam int id,
|
136 |
public String updateHotDeal(HttpServletRequest request, @RequestParam int id,
|
| 136 |
@RequestParam String startDate, @RequestParam String endDate,
|
137 |
@RequestParam String startDate, @RequestParam String endDate,
|
| 137 |
@RequestParam(required = false) Integer warrantyMonths,
|
138 |
@RequestParam(required = false) Integer warrantyMonths,
|
| 138 |
@RequestParam(required = false) String condition,
|
139 |
@RequestParam(required = false) String condition,
|
| 139 |
@RequestParam(required = false) Boolean activated,
|
140 |
@RequestParam(required = false) Boolean fresh,
|
| 140 |
@RequestParam(required = false) Boolean financeMapping,
|
141 |
@RequestParam(required = false) Boolean financeMapping,
|
| 141 |
@RequestParam(required = false) Boolean affordability,
|
142 |
@RequestParam(required = false) Boolean affordability,
|
| 142 |
Model model) throws Exception {
|
143 |
Model model) throws Exception {
|
| 143 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
144 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 144 |
try {
|
145 |
try {
|
| 145 |
HotDealAttributes attributes = new HotDealAttributes(warrantyMonths, condition,
|
146 |
HotDealAttributes attributes = new HotDealAttributes(warrantyMonths, condition,
|
| 146 |
activated, financeMapping, affordability);
|
147 |
fresh, financeMapping, affordability);
|
| 147 |
modelHotDealService.updateDeal(id, LocalDate.parse(startDate), LocalDate.parse(endDate),
|
148 |
modelHotDealService.updateDeal(id, LocalDate.parse(startDate), LocalDate.parse(endDate),
|
| 148 |
attributes, loginDetails.getEmailId());
|
149 |
attributes, loginDetails.getEmailId());
|
| 149 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
150 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 150 |
} catch (ProfitMandiBusinessException e) {
|
151 |
} catch (ProfitMandiBusinessException e) {
|
| 151 |
LOGGER.warn("Hot deal update rejected: {}", e.getMessage());
|
152 |
LOGGER.warn("Hot deal update rejected: {}", e.getMessage());
|
| 152 |
model.addAttribute("response1", e.getMessage());
|
153 |
model.addAttribute("response1", e.getMessage());
|
| 153 |
}
|
154 |
}
|
| 154 |
return "response";
|
155 |
return "response";
|
| 155 |
}
|
156 |
}
|
| 156 |
|
157 |
|
| - |
|
158 |
@Autowired
|
| - |
|
159 |
private FofoSolr fofoSolr;
|
| - |
|
160 |
|
| - |
|
161 |
/**
|
| - |
|
162 |
* Manual, explicit Solr push for the selected deal models (Category team button).
|
| - |
|
163 |
* Calls the indexer directly - deliberately NOT the prod-gated change event - so
|
| - |
|
164 |
* curated models are searchable immediately without waiting for the daily sync.
|
| - |
|
165 |
*/
|
| - |
|
166 |
@RequestMapping(value = "/hotDeals/pushSolr", method = RequestMethod.POST)
|
| - |
|
167 |
public String pushDealsToSolr(@RequestParam String catalogIds, Model model) throws Exception {
|
| - |
|
168 |
List<String> ok = new java.util.ArrayList<>();
|
| - |
|
169 |
List<String> failed = new java.util.ArrayList<>();
|
| - |
|
170 |
for (String raw : catalogIds.split(",")) {
|
| - |
|
171 |
String id = raw.trim();
|
| - |
|
172 |
if (id.isEmpty()) {
|
| - |
|
173 |
continue;
|
| - |
|
174 |
}
|
| - |
|
175 |
try {
|
| - |
|
176 |
fofoSolr.updateSingleCatalog(Integer.parseInt(id));
|
| - |
|
177 |
ok.add(id);
|
| - |
|
178 |
} catch (Exception e) {
|
| - |
|
179 |
LOGGER.error("Manual Solr push failed for catalogId={}", id, e);
|
| - |
|
180 |
failed.add(id + " (" + e.getMessage() + ")");
|
| - |
|
181 |
}
|
| - |
|
182 |
}
|
| - |
|
183 |
String summary = "Pushed " + ok.size() + " model(s) to Solr"
|
| - |
|
184 |
+ (failed.isEmpty() ? "" : "; FAILED: " + String.join(", ", failed));
|
| - |
|
185 |
model.addAttribute("response1", summary);
|
| - |
|
186 |
return "response";
|
| - |
|
187 |
}
|
| - |
|
188 |
|
| 157 |
@RequestMapping(value = "/hotDeals/remove", method = RequestMethod.POST)
|
189 |
@RequestMapping(value = "/hotDeals/remove", method = RequestMethod.POST)
|
| 158 |
public String removeHotDeal(@RequestParam int id, Model model) throws Exception {
|
190 |
public String removeHotDeal(@RequestParam int id, Model model) throws Exception {
|
| 159 |
try {
|
191 |
try {
|
| 160 |
modelHotDealService.removeDeal(id);
|
192 |
modelHotDealService.removeDeal(id);
|
| 161 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
193 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|