...
|
...
|
@@ -5,8 +5,10 @@ import com.yoho.search.dal.*; |
|
|
import com.yoho.search.dal.model.BigdataMonitor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class BigdataMonitorService {
|
...
|
...
|
@@ -32,65 +34,121 @@ public class BigdataMonitorService { |
|
|
@Autowired
|
|
|
private ProductModelValueMapper productModelValueMapper;
|
|
|
|
|
|
private static final int SIMILAR_SKN_THRESHOLD = 1;
|
|
|
private static final int SKN_PRICEAREA_THRESHOLD = 1;
|
|
|
private static final int SORTBRAND_VECTOR_THRESHOLD = 1;
|
|
|
private static final int PRODUCT15DAY_SALESUM_THRESHOLD = 1;
|
|
|
private static final int PRODUCT_SALESINFO_THRESHOLD = 1;
|
|
|
private static final int PRODUCTHEAT_VALUES_THRESHOLD = 1;
|
|
|
private static final int PRODUCTHEATVALUES_ONEDAY_THRESHOLD = 1;
|
|
|
private static final int SKN_FLOW_THRESHOLD = 1;
|
|
|
private static final int PRODUCTVECTOR_FEATURE_THRESHOLD = 1;
|
|
|
private static final int PRODUCTMODEL_VALUE_THRESHOLD = 1;
|
|
|
private static final String ERROR_MESSAGE_FORMAT = "tableName: %s; data_id: %s; num: %d.";
|
|
|
|
|
|
|
|
|
private static final int SIMILAR_SKN_THRESHOLD = 2; //83315 / 2;
|
|
|
private static final int SKN_PRICEAREA_THRESHOLD = 2; //560000 / 2
|
|
|
private static final int SORTBRAND_VECTOR_THRESHOLD = 20000; //2513 / 2
|
|
|
private static final int PRODUCT15DAY_SALESUM_THRESHOLD = 2;
|
|
|
private static final int PRODUCT_SALESINFO_THRESHOLD = 3; //30000 / 2
|
|
|
private static final int PRODUCTHEAT_VALUES_THRESHOLD = 2; //60000 / 2
|
|
|
private static final int PRODUCTHEATVALUES_ONEDAY_THRESHOLD = 2; //30000 / 2
|
|
|
private static final int SKN_FLOW_1_THRESHOLD = 2; //110000 / 2
|
|
|
private static final int SKN_FLOW_2_THRESHOLD = 2; //12000 / 2
|
|
|
private static final int PRODUCTVECTOR_FEATURE_THRESHOLD = 2; //102311 / 2
|
|
|
private static final int PRODUCTMODEL_VALUE_THRESHOLD = 2; //81000 / 2
|
|
|
|
|
|
public ApiResponse similarSkn() {
|
|
|
List<BigdataMonitor> result = similarSknMapper.selectCountGroupByDateId();
|
|
|
return ApiResponse.create(200, result.get(0));
|
|
|
List<BigdataMonitor> results = similarSknMapper.selectCountGroupByDateId();
|
|
|
if (CollectionUtils.isEmpty(results)) {
|
|
|
return ApiResponse.createError("bigdata_similar_skn: 没有数据", null);
|
|
|
}
|
|
|
return ifNeedAlarm(results, SIMILAR_SKN_THRESHOLD, "bigdata_similar_skn");
|
|
|
}
|
|
|
|
|
|
public ApiResponse sknPricearea() {
|
|
|
List<BigdataMonitor> result = bigdataSknPriceareaMapper.selectCountGroupByDateId();
|
|
|
return ApiResponse.create(200, result.get(0));
|
|
|
List<BigdataMonitor> results = bigdataSknPriceareaMapper.selectCountGroupByDateId();
|
|
|
if (CollectionUtils.isEmpty(results)) {
|
|
|
return ApiResponse.createError("bigdata_skn_pricearea: 没有数据", null);
|
|
|
}
|
|
|
return ifNeedAlarm(results, SKN_PRICEAREA_THRESHOLD, "bigdata_skn_pricearea");
|
|
|
}
|
|
|
|
|
|
public ApiResponse sortBrandVector() {
|
|
|
List<BigdataMonitor> result = bigdataSortBrandVectorMapper.selectCountGroupByDateId();
|
|
|
return ApiResponse.create(200, result.get(0));
|
|
|
List<BigdataMonitor> results = bigdataSortBrandVectorMapper.selectCountGroupByDateId();
|
|
|
if (CollectionUtils.isEmpty(results)) {
|
|
|
return ApiResponse.createError("bigdata_sort_brand_vector: 没有数据", null);
|
|
|
}
|
|
|
return ifNeedAlarm(results, SORTBRAND_VECTOR_THRESHOLD, "bigdata_sort_brand_vector");
|
|
|
}
|
|
|
|
|
|
public ApiResponse product15daySalesnum() {
|
|
|
List<BigdataMonitor> result = product15DaySalesNumMapper.selectCountGroupByDateId();
|
|
|
return ApiResponse.create(200, result.get(0));
|
|
|
List<BigdataMonitor> results = product15DaySalesNumMapper.selectCountGroupByDateId();
|
|
|
if (CollectionUtils.isEmpty(results)) {
|
|
|
return ApiResponse.createError("product_15day_salesnum: 没有数据", null);
|
|
|
}
|
|
|
return ifNeedAlarm(results, PRODUCT15DAY_SALESUM_THRESHOLD, "product_15day_salesnum");
|
|
|
}
|
|
|
|
|
|
public ApiResponse productSalesInfo() {
|
|
|
List<BigdataMonitor> result = productSalesInfoMapper.selectCountGroupByDateId();
|
|
|
return ApiResponse.create(200, result.get(0));
|
|
|
List<BigdataMonitor> results = productSalesInfoMapper.selectCountGroupByDateId();
|
|
|
if (CollectionUtils.isEmpty(results)) {
|
|
|
return ApiResponse.createError("product_sales_info: 没有数据", null);
|
|
|
}
|
|
|
return ifNeedAlarm(results, PRODUCT_SALESINFO_THRESHOLD, "product_sales_info");
|
|
|
}
|
|
|
|
|
|
public ApiResponse productHeatValues() {
|
|
|
List<BigdataMonitor> result = productHeatValuesMapper.selectCountGroupByDateId();
|
|
|
return ApiResponse.create(200, result.get(0));
|
|
|
List<BigdataMonitor> results = productHeatValuesMapper.selectCountGroupByDateId();
|
|
|
if (CollectionUtils.isEmpty(results)) {
|
|
|
return ApiResponse.createError("product_heat_values: 没有数据", null);
|
|
|
}
|
|
|
return ifNeedAlarm(results, PRODUCTHEAT_VALUES_THRESHOLD, "product_heat_values");
|
|
|
}
|
|
|
|
|
|
public ApiResponse productHeatValuesOneday() {
|
|
|
List<BigdataMonitor> result = productHeatValuesOneDayMapper.selectCountGroupByDateId();
|
|
|
return ApiResponse.create(200, result.get(0));
|
|
|
List<BigdataMonitor> results = productHeatValuesOneDayMapper.selectCountGroupByDateId();
|
|
|
if (CollectionUtils.isEmpty(results)) {
|
|
|
return ApiResponse.createError("product_heat_values_oneday: 没有数据", null);
|
|
|
}
|
|
|
return ifNeedAlarm(results, PRODUCTHEATVALUES_ONEDAY_THRESHOLD, "product_heat_values_oneday");
|
|
|
}
|
|
|
|
|
|
public ApiResponse sknFlow() {
|
|
|
List<BigdataMonitor> result = sknFlowMapper.selectCountGroupByDateId();
|
|
|
return ApiResponse.create(200, result);
|
|
|
List<BigdataMonitor> results = sknFlowMapper.selectCountGroupByDateId();
|
|
|
if (CollectionUtils.isEmpty(results)) {
|
|
|
return ApiResponse.createError("skn_flow: 没有数据", null);
|
|
|
}
|
|
|
List<BigdataMonitor> results1 = results.stream().filter(e -> e.getFlowType().equals(1) && e.getNum() < SKN_FLOW_1_THRESHOLD).collect(Collectors.toList());
|
|
|
List<BigdataMonitor> results2 = results.stream().filter(e -> e.getFlowType().equals(2) && e.getNum() < SKN_FLOW_2_THRESHOLD).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(results1) && CollectionUtils.isEmpty(results1)) {
|
|
|
return ApiResponse.createSuccess(null);
|
|
|
}
|
|
|
String message = "";
|
|
|
if (!CollectionUtils.isEmpty(results1)) {
|
|
|
String message1 = results1.stream().map(e -> String.format(ERROR_MESSAGE_FORMAT, "skn_flow", e.getDateId(), e.getNum())).collect(Collectors.joining());
|
|
|
message = message1;
|
|
|
}
|
|
|
if (!CollectionUtils.isEmpty(results2)) {
|
|
|
String message2 = results2.stream().map(e -> String.format(ERROR_MESSAGE_FORMAT, "skn_flow", e.getDateId(), e.getNum())).collect(Collectors.joining());
|
|
|
message = message + message2;
|
|
|
}
|
|
|
return ApiResponse.createError(message, null);
|
|
|
}
|
|
|
|
|
|
public ApiResponse productVectorFeature() {
|
|
|
List<BigdataMonitor> result = productVectorFeatureMapper.selectCountGroupByDateId();
|
|
|
return ApiResponse.create(200, result.get(0));
|
|
|
List<BigdataMonitor> results = productVectorFeatureMapper.selectCountGroupByDateId();
|
|
|
if (CollectionUtils.isEmpty(results)) {
|
|
|
return ApiResponse.createError("product_vector_feature: 没有数据", null);
|
|
|
}
|
|
|
return ifNeedAlarm(results, PRODUCTVECTOR_FEATURE_THRESHOLD, "product_vector_feature");
|
|
|
}
|
|
|
|
|
|
public ApiResponse productModelValue() {
|
|
|
List<BigdataMonitor> result = productModelValueMapper.selectCountGroupByDateId();
|
|
|
return ApiResponse.create(200, result.get(0));
|
|
|
List<BigdataMonitor> results = productModelValueMapper.selectCountGroupByDateId();
|
|
|
if (CollectionUtils.isEmpty(results)) {
|
|
|
return ApiResponse.createError("product_model_value: 没有数据", null);
|
|
|
}
|
|
|
return ifNeedAlarm(results, PRODUCTMODEL_VALUE_THRESHOLD, "product_model_value");
|
|
|
}
|
|
|
|
|
|
private ApiResponse ifNeedAlarm(List<BigdataMonitor> results, int threshold, String tableName) {
|
|
|
results = results.stream().filter(e -> e.getNum() < threshold).collect(Collectors.toList());
|
|
|
if (!CollectionUtils.isEmpty(results)) {
|
|
|
String message = results.stream().map(e -> String.format(ERROR_MESSAGE_FORMAT, tableName, e.getDateId(), e.getNum())).collect(Collectors.joining());
|
|
|
return ApiResponse.createError(message, null);
|
|
|
}
|
|
|
return ApiResponse.createSuccess(null);
|
|
|
}
|
|
|
} |
...
|
...
|
|