|
|
package com.yoho.search.consumer.service.logicService;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.yoho.search.consumer.service.bo.BigdataBrandVectorBO;
|
|
|
import com.yoho.search.consumer.service.bo.BigdataSortBrandVectorBO;
|
|
|
import com.yoho.search.dal.model.BigdataBrandVector;
|
|
|
import com.yoho.search.dal.model.BigdataSortBrandVector;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Component
|
|
|
public class BrandVectorBOLogicService {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(BrandVectorBOLogicService.class);
|
|
|
|
|
|
private List<Double> splitStringToDoubleList(String vector,String split){
|
|
|
try {
|
|
|
String [] parts = vector.split(split);
|
|
|
List<Double> results = new ArrayList<>();
|
|
|
for (String part: parts){
|
|
|
results.add(Double.parseDouble(part));
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<Double> getDoubleList(String vector) {
|
|
|
try {
|
|
|
if (vector.startsWith("[") && vector.endsWith("]")) {
|
|
|
return JSONArray.parseArray(vector, Double.class);
|
|
|
} else {
|
|
|
return this.splitStringToDoubleList(vector,",");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public BigdataBrandVectorBO getBigdataBrandVectorBO(BigdataBrandVector vector) {
|
|
|
try {
|
|
|
BigdataBrandVectorBO vectorBO = new BigdataBrandVectorBO();
|
|
|
vectorBO.setId(vector.getBrandId().longValue());
|
|
|
vectorBO.setBrandId(vector.getBrandId());
|
|
|
vectorBO.setVector(this.getDoubleList(vector.getVector()));
|
|
|
vectorBO.setUpdateTime(vector.getUpdateTime());
|
|
|
return vectorBO;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public BigdataSortBrandVectorBO getBigdataSortBrandVectorBO(BigdataSortBrandVector vector) {
|
|
|
try {
|
|
|
BigdataSortBrandVectorBO vectorBO = new BigdataSortBrandVectorBO();
|
|
|
vectorBO.setId(vector.getBrandId() + "_" + vector.getMiddleSortId());
|
|
|
vectorBO.setBrandId(vector.getBrandId());
|
|
|
vectorBO.setMiddleSortId(vector.getMiddleSortId());
|
|
|
vectorBO.setVector(this.getDoubleList(vector.getVector()));
|
|
|
vectorBO.setUpdateTime(vector.getUpdateTime());
|
|
|
return vectorBO;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|