Authored by Lixiaodi

新销售日历

... ... @@ -178,6 +178,36 @@ public class ProductSearchController {
JSONObject timeJson = productSearchService.getSaleCalendarCountData();
return new ApiResponse.ApiResponseBuilder().code(200).message("product.search.saleCalendar").data(timeJson).build();
}
@ApiOperation(name = "ufo.product.search.newSaleCalendar", desc="销售日历列表")
@RequestMapping(params = "method=ufo.product.search.newSaleCalendar")
@IgnoreSession
public ApiResponse searchNewSaleCalendar(@RequestParam(value = "uid", required = false)Integer uid,
@RequestParam(value = "start_time", required = false)String startTime,
@RequestParam(value = "end_time", required = false)String endTime) {
if (StringUtils.isBlank(startTime) || StringUtils.isBlank(endTime)) {
return new ApiResponse.ApiResponseBuilder().code(400).message("参数错误!").data(null).build();
}
LOG.info("in method=ufo.product.search.newSaleCalendar uid={}, start_time={}, end_time={}", uid, startTime, endTime);
Integer start = getValidTimestamp(startTime, true);
Integer end = getValidTimestamp(endTime, false);
if (start == null || end == null) {
return new ApiResponse.ApiResponseBuilder().code(400).message("参数错误!").data(null).build();
}
JSONObject productJson = productSearchService.searchNewSaleCalendar(start, end);
productSearchService.processUserFavoriteProductList(productJson, uid);
return new ApiResponse.ApiResponseBuilder().code(200).message("product.search.newSaleCalendar").data(productJson).build();
}
@ApiOperation(name = "ufo.product.search.newSaleCalendarCount", desc="销售日历列汇总数量")
@RequestMapping(params = "method=ufo.product.search.newSaleCalendarCount")
@IgnoreSession
@Cachable(expire=180)
public ApiResponse searchNewSaleCalendarCount() {
LOG.info("in method=ufo.product.search.newSaleCalendarCount");
JSONObject timeJson = productSearchService.getNewSaleCalendarCountData();
return new ApiResponse.ApiResponseBuilder().code(200).message("product.search.newSaleCalendarCount").data(timeJson).build();
}
@IgnoreSignature
@ApiOperation(name = "ufo.product.search.hotSale", desc="热销列表")
... ...
... ... @@ -28,12 +28,14 @@ public interface ProductSearchService {
List<ProductBrandSeriesResp> searchSeriesList();
JSONObject searchSaleCalendar(Integer startTime, Integer endTime);
JSONObject searchNewSaleCalendar(Integer startTime, Integer endTime);
JSONObject searchHotSale(Integer page, Integer limit);
void processUserFavoriteProductList(JSONObject productJSON, Integer uid);
JSONObject getSaleCalendarCountData();
JSONObject getNewSaleCalendarCountData();
JSONObject searchUvscoreProductList(ProductSearchReq req);
... ...
... ... @@ -91,6 +91,10 @@ public class ProductSearchServiceImpl implements ProductSearchService {
public static final String SALE_CALENDAR_LIST_URL = "/yohosearch/ufo/saleCalendarProductList.json";
public static final String SALE_CALENDAR_COUNT_URL = "/yohosearch/ufo/SaleDateCountList.json";
public static final String NEW_SALE_CALENDAR_LIST_URL = "/yohosearch/ufo/saleCalendarNewProductList.json";
public static final String NEW_SALE_CALENDAR_COUNT_URL = "/yohosearch/ufo/saleDateNewCountList.json";
public static final String HOT_SALE_LIST_URL = "/yohosearch/ufo/hotSaleProductList.json";
public static final String PRODUCT_POOL_URL = "/yohosearch/ufo/pool/productList.json";
... ... @@ -463,39 +467,47 @@ public class ProductSearchServiceImpl implements ProductSearchService {
@Override
public JSONObject getSaleCalendarCountData() {
JSONObject countMap = new JSONObject();
try {
SearchParam searchParam = new SearchParam();
String url = SALE_CALENDAR_COUNT_URL;
countMap = search(searchParam.getParam(), url).getJSONObject("sale_date_count_list");
} catch (Exception e) {
logger.error("调用销售日历汇总数据出错: " + e.getMessage(), e);
}
JSONObject jo = new JSONObject();
String ymd = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
jo.put("today", ymd);
JSONArray yearArray = new JSONArray();
int year = Integer.parseInt(ymd.substring(0, 4));
int month = Integer.parseInt(ymd.substring(5, 7));
for (int y = year - 1; y <= year + 1; y++) {
JSONObject yearData = new JSONObject();
JSONArray monthArray = new JSONArray();
for (int m = ((y == year - 1)? month:1); m <= ((y == year + 1)?month:12); m++) {
String ym = y + "-" + (m < 10 ? "0" + m : Integer.toString(m));
Integer count = countMap.getInteger(ym);
JSONObject ymData = new JSONObject();
ymData.put("month", m);
ymData.put("count", count == null ? Integer.valueOf(0) : count);
monthArray.add(ymData);
}
yearData.put(Integer.toString(y), monthArray);
yearArray.add(yearData);
}
jo.put("countData", yearArray);
return jo;
return getSaleCalendarCountData(SALE_CALENDAR_COUNT_URL);
}
@Override
public JSONObject getNewSaleCalendarCountData() {
return getSaleCalendarCountData(NEW_SALE_CALENDAR_COUNT_URL);
}
private JSONObject getSaleCalendarCountData(String url) {
JSONObject countMap = new JSONObject();
try {
SearchParam searchParam = new SearchParam();
countMap = search(searchParam.getParam(), url).getJSONObject("sale_date_count_list");
} catch (Exception e) {
logger.error("调用销售日历汇总数据出错: " + e.getMessage(), e);
}
JSONObject jo = new JSONObject();
String ymd = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
jo.put("today", ymd);
JSONArray yearArray = new JSONArray();
int year = Integer.parseInt(ymd.substring(0, 4));
int month = Integer.parseInt(ymd.substring(5, 7));
for (int y = year - 1; y <= year + 1; y++) {
JSONObject yearData = new JSONObject();
JSONArray monthArray = new JSONArray();
for (int m = ((y == year - 1)? month:1); m <= ((y == year + 1)?month:12); m++) {
String ym = y + "-" + (m < 10 ? "0" + m : Integer.toString(m));
Integer count = countMap.getInteger(ym);
JSONObject ymData = new JSONObject();
ymData.put("month", m);
ymData.put("count", count == null ? Integer.valueOf(0) : count);
monthArray.add(ymData);
}
yearData.put(Integer.toString(y), monthArray);
yearArray.add(yearData);
}
jo.put("countData", yearArray);
return jo;
}
@Override
@Cachable(expire=180)
... ... @@ -511,6 +523,20 @@ public class ProductSearchServiceImpl implements ProductSearchService {
return data;
}
@Override
@Cachable(expire=180)
public JSONObject searchNewSaleCalendar(Integer startTime, Integer endTime) {
ProductSearchReq req = new ProductSearchReq();
req.setStartTime(startTime).setEndTime(endTime);
SearchParam searchParam = new SearchParam().buildPageSearchParam(req);
JSONObject data = search(searchParam.getParam(), NEW_SALE_CALENDAR_LIST_URL);
// 将图片的相对路径转成绝对路径
if (null != data) {
processProductList(data.getJSONArray("product_list"));
}
return data;
}
@Override
public JSONObject searchHotSale(Integer page, Integer limit) {
ProductSearchReq req = new ProductSearchReq().setViewNum(limit).setPage(page);
... ...