Authored by hugufei

代码优化

... ... @@ -2,6 +2,7 @@ package com.yoho.search.consumer.index.fullbuild;
import com.yoho.search.consumer.index.common.IIndexBuilder;
import com.yoho.search.consumer.service.bo.BigdataBrandVectorBO;
import com.yoho.search.consumer.service.logicService.BrandVectorBOLogicService;
import com.yoho.search.dal.BigdataBrandVectorMapper;
import com.yoho.search.dal.model.BigdataBrandVector;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -16,6 +17,8 @@ import java.util.List;
public class BigdataBrandVectorIndexBuilder extends IIndexBuilder {
@Autowired
private BrandVectorBOLogicService brandVectorBOLogicService;
@Autowired
private BigdataBrandVectorMapper bigdataBrandVectorMapper;
@Override
... ... @@ -34,7 +37,11 @@ public class BigdataBrandVectorIndexBuilder extends IIndexBuilder {
if (vector.getBrandId() == null) {
continue;
}
vectorBOS.add(getBigdataBrandVectorBO(vector));
BigdataBrandVectorBO bigdataBrandVectorBO = brandVectorBOLogicService.getBigdataBrandVectorBO(vector);
if (bigdataBrandVectorBO == null) {
continue;
}
vectorBOS.add(bigdataBrandVectorBO);
}
return vectorBOS;
}
... ... @@ -44,13 +51,5 @@ public class BigdataBrandVectorIndexBuilder extends IIndexBuilder {
return ((BigdataBrandVectorBO) object).getId().toString();
}
public BigdataBrandVectorBO getBigdataBrandVectorBO(BigdataBrandVector vector) {
BigdataBrandVectorBO vectorBO = new BigdataBrandVectorBO();
vectorBO.setId(vector.getBrandId().longValue());
vectorBO.setBrandId(vector.getBrandId());
vectorBO.setVector(vector.getVector());
vectorBO.setUpdateTime(vector.getUpdateTime());
return vectorBO;
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.consumer.index.fullbuild;
import com.yoho.search.consumer.index.common.IIndexBuilder;
import com.yoho.search.consumer.service.bo.BigdataBrandVectorBO;
import com.yoho.search.consumer.service.logicService.BrandVectorBOLogicService;
import com.yoho.search.dal.BigdataBrandVectorMapperW2v;
import com.yoho.search.dal.model.BigdataBrandVectorW2v;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -16,6 +17,8 @@ import java.util.List;
public class BigdataBrandVectorW2vIndexBuilder extends IIndexBuilder {
@Autowired
private BrandVectorBOLogicService brandVectorBOLogicService;
@Autowired
private BigdataBrandVectorMapperW2v bigdataBrandVectorMapperW2v;
@Override
... ... @@ -34,7 +37,10 @@ public class BigdataBrandVectorW2vIndexBuilder extends IIndexBuilder {
if (vector.getBrandId() == null) {
continue;
}
vectorBOS.add(getBigdataBrandVectorBO(vector));
BigdataBrandVectorBO bigdataBrandVectorBO = brandVectorBOLogicService.getBigdataBrandVectorBO(vector);
if (bigdataBrandVectorBO != null) {
vectorBOS.add(bigdataBrandVectorBO);
}
}
return vectorBOS;
}
... ... @@ -44,12 +50,4 @@ public class BigdataBrandVectorW2vIndexBuilder extends IIndexBuilder {
return ((BigdataBrandVectorBO) object).getId().toString();
}
public BigdataBrandVectorBO getBigdataBrandVectorBO(BigdataBrandVectorW2v vector) {
BigdataBrandVectorBO vectorBO = new BigdataBrandVectorBO();
vectorBO.setId(vector.getBrandId().longValue());
vectorBO.setBrandId(vector.getBrandId());
vectorBO.setVector(vector.getVector());
vectorBO.setUpdateTime(vector.getUpdateTime());
return vectorBO;
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.consumer.index.fullbuild;
import com.yoho.search.consumer.index.common.IIndexBuilder;
import com.yoho.search.consumer.service.bo.BigdataSortBrandVectorBO;
import com.yoho.search.consumer.service.logicService.BrandVectorBOLogicService;
import com.yoho.search.dal.BigdataSortBrandVectorMapper;
import com.yoho.search.dal.model.BigdataSortBrandVector;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -16,6 +17,8 @@ import java.util.List;
public class BigdataSortBrandVectorIndexBuilder extends IIndexBuilder {
@Autowired
private BrandVectorBOLogicService brandVectorBOLogicService;
@Autowired
private BigdataSortBrandVectorMapper bigdataSortBrandVectorMapper;
@Override
... ... @@ -34,7 +37,11 @@ public class BigdataSortBrandVectorIndexBuilder extends IIndexBuilder {
if (vector.getBrandId() == null || vector.getMiddleSortId() == null) {
continue;
}
vectorBOS.add(getBigdataSortBrandVectorBO(vector));
BigdataSortBrandVectorBO bigdataSortBrandVectorBO = brandVectorBOLogicService.getBigdataSortBrandVectorBO(vector);
if(bigdataSortBrandVectorBO==null){
continue;
}
vectorBOS.add(bigdataSortBrandVectorBO);
}
return vectorBOS;
}
... ... @@ -44,13 +51,4 @@ public class BigdataSortBrandVectorIndexBuilder extends IIndexBuilder {
return ((BigdataSortBrandVectorBO) object).getId();
}
public BigdataSortBrandVectorBO getBigdataSortBrandVectorBO(BigdataSortBrandVector vector) {
BigdataSortBrandVectorBO vectorBO = new BigdataSortBrandVectorBO();
vectorBO.setId(vector.getBrandId() + "_" + vector.getMiddleSortId());
vectorBO.setBrandId(vector.getBrandId());
vectorBO.setMiddleSortId(vector.getMiddleSortId());
vectorBO.setVector(vector.getVector());
vectorBO.setUpdateTime(vector.getUpdateTime());
return vectorBO;
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.consumer.index.fullbuild;
import com.yoho.search.consumer.index.common.IIndexBuilder;
import com.yoho.search.consumer.service.bo.BigdataSortBrandVectorBO;
import com.yoho.search.consumer.service.logicService.BrandVectorBOLogicService;
import com.yoho.search.dal.BigdataSortBrandVectorW2vMapper;
import com.yoho.search.dal.model.BigdataSortBrandVectorW2v;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -16,6 +17,8 @@ import java.util.List;
public class BigdataSortBrandVectorW2vIndexBuilder extends IIndexBuilder {
@Autowired
private BrandVectorBOLogicService brandVectorBOLogicService;
@Autowired
private BigdataSortBrandVectorW2vMapper bigdataSortBrandVectorW2vMapper;
@Override
... ... @@ -34,7 +37,11 @@ public class BigdataSortBrandVectorW2vIndexBuilder extends IIndexBuilder {
if (vector.getBrandId() == null || vector.getMiddleSortId() == null) {
continue;
}
vectorBOS.add(getBigdataSortBrandVectorBO(vector));
BigdataSortBrandVectorBO bigdataSortBrandVectorBO = brandVectorBOLogicService.getBigdataSortBrandVectorBO(vector);
if(bigdataSortBrandVectorBO==null){
continue;
}
vectorBOS.add(bigdataSortBrandVectorBO);
}
return vectorBOS;
}
... ... @@ -44,13 +51,5 @@ public class BigdataSortBrandVectorW2vIndexBuilder extends IIndexBuilder {
return ((BigdataSortBrandVectorBO) object).getId();
}
public BigdataSortBrandVectorBO getBigdataSortBrandVectorBO(BigdataSortBrandVectorW2v vector) {
BigdataSortBrandVectorBO vectorBO = new BigdataSortBrandVectorBO();
vectorBO.setId(vector.getBrandId() + "_" + vector.getMiddleSortId());
vectorBO.setBrandId(vector.getBrandId());
vectorBO.setMiddleSortId(vector.getMiddleSortId());
vectorBO.setVector(vector.getVector());
vectorBO.setUpdateTime(vector.getUpdateTime());
return vectorBO;
}
}
... ...
... ... @@ -8,6 +8,7 @@ import com.yoho.search.consumer.index.common.IYohoIndexService;
import com.yoho.search.consumer.index.fullbuild.BigdataBrandVectorIndexBuilder;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.service.bo.BigdataBrandVectorBO;
import com.yoho.search.consumer.service.logicService.BrandVectorBOLogicService;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.model.BigdataBrandVector;
import org.slf4j.Logger;
... ... @@ -22,7 +23,7 @@ public class BigdataBrandVectorMqListener extends AbstractMqListener {
@Autowired
private IYohoIndexService indexService;
@Autowired
private BigdataBrandVectorIndexBuilder bigdataBrandVectorIndexBuilder;
private BrandVectorBOLogicService brandVectorBOLogicService;
@Override
protected String getIndexName() {
... ... @@ -36,15 +37,17 @@ public class BigdataBrandVectorMqListener extends AbstractMqListener {
@Override
protected void deleteData(String id) throws Exception {
indexService.deleteIndexData(ISearchConstants.INDEX_NAME_BIGDATA_BRAND_VECTOR, id);
indexService.deleteIndexData(this.getIndexName(), id);
}
@Override
protected void updateData(JSONObject data) throws Exception {
BigdataBrandVector vector = ConvertUtils.toJavaObject(BigdataBrandVector.class, data);
if (vector != null && vector.getBrandId() != null) {
BigdataBrandVectorBO vectorBO = bigdataBrandVectorIndexBuilder.getBigdataBrandVectorBO(vector);
indexService.updateIndexData(ISearchConstants.INDEX_NAME_BIGDATA_BRAND_VECTOR, vectorBO.getId().toString(), vectorBO);
BigdataBrandVectorBO vectorBO = brandVectorBOLogicService.getBigdataBrandVectorBO(vector);
if (vectorBO != null) {
indexService.updateIndexData(this.getIndexName(), vectorBO.getId().toString(), vectorBO);
}
}
}
}
... ...
... ... @@ -8,6 +8,7 @@ import com.yoho.search.consumer.index.common.IYohoIndexService;
import com.yoho.search.consumer.index.fullbuild.BigdataBrandVectorW2vIndexBuilder;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.service.bo.BigdataBrandVectorBO;
import com.yoho.search.consumer.service.logicService.BrandVectorBOLogicService;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.model.BigdataBrandVectorW2v;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -20,7 +21,7 @@ public class BigdataBrandVectorW2vMqListener extends AbstractMqListener {
@Autowired
private IYohoIndexService indexService;
@Autowired
private BigdataBrandVectorW2vIndexBuilder bigdataBrandVectorW2vIndexBuilder;
private BrandVectorBOLogicService brandVectorBOLogicService;
@Override
protected String getIndexName() {
... ... @@ -34,15 +35,17 @@ public class BigdataBrandVectorW2vMqListener extends AbstractMqListener {
@Override
protected void deleteData(String id) throws Exception {
indexService.deleteIndexData(ISearchConstants.INDEX_NAME_BIGDATA_BRAND_VECTOR_W2V, id);
indexService.deleteIndexData(this.getIndexName(), id);
}
@Override
protected void updateData(JSONObject data) throws Exception {
BigdataBrandVectorW2v vector = ConvertUtils.toJavaObject(BigdataBrandVectorW2v.class, data);
if (vector != null && vector.getBrandId() != null) {
BigdataBrandVectorBO vectorBO = bigdataBrandVectorW2vIndexBuilder.getBigdataBrandVectorBO(vector);
indexService.updateIndexData(ISearchConstants.INDEX_NAME_BIGDATA_BRAND_VECTOR_W2V, vectorBO.getId().toString(), vectorBO);
BigdataBrandVectorBO vectorBO = brandVectorBOLogicService.getBigdataBrandVectorBO(vector);
if (vectorBO != null) {
indexService.updateIndexData(this.getIndexName(), vectorBO.getId().toString(), vectorBO);
}
}
}
}
... ...
... ... @@ -8,6 +8,7 @@ import com.yoho.search.consumer.index.common.IYohoIndexService;
import com.yoho.search.consumer.index.fullbuild.BigdataSortBrandVectorIndexBuilder;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.service.bo.BigdataSortBrandVectorBO;
import com.yoho.search.consumer.service.logicService.BrandVectorBOLogicService;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.model.BigdataSortBrandVector;
import org.slf4j.Logger;
... ... @@ -24,7 +25,7 @@ public class BigdataSortBrandVectorMqListener extends AbstractMqListener {
@Autowired
private IYohoIndexService indexService;
@Autowired
private BigdataSortBrandVectorIndexBuilder bigdataSortBrandVectorIndexBuilder;
private BrandVectorBOLogicService brandVectorBOLogicService;
@Override
protected String getIndexName() {
... ... @@ -46,7 +47,7 @@ public class BigdataSortBrandVectorMqListener extends AbstractMqListener {
BigdataSortBrandVector bigdataSortBrandVector = ConvertUtils.toJavaObject(BigdataSortBrandVector.class, data);
if (bigdataSortBrandVector != null && bigdataSortBrandVector.getBrandId() != null && bigdataSortBrandVector.getMiddleSortId() != null) {
String indexId = bigdataSortBrandVector.getBrandId() + "_" + bigdataSortBrandVector.getMiddleSortId();
indexService.deleteIndexData(ISearchConstants.INDEX_NAME_BIGDATA_SORT_BRAND_VECTOR, indexId);
indexService.deleteIndexData(this.getIndexName(), indexId);
}
}
... ... @@ -54,8 +55,10 @@ public class BigdataSortBrandVectorMqListener extends AbstractMqListener {
protected void updateData(JSONObject data) throws Exception {
BigdataSortBrandVector vector = ConvertUtils.toJavaObject(BigdataSortBrandVector.class, data);
if (vector != null && vector.getBrandId() != null && vector.getMiddleSortId() != null) {
BigdataSortBrandVectorBO vectorBO = bigdataSortBrandVectorIndexBuilder.getBigdataSortBrandVectorBO(vector);
indexService.updateIndexData(ISearchConstants.INDEX_NAME_BIGDATA_SORT_BRAND_VECTOR, vectorBO.getId(), vectorBO);
BigdataSortBrandVectorBO vectorBO = brandVectorBOLogicService.getBigdataSortBrandVectorBO(vector);
if(vectorBO!=null){
indexService.updateIndexData(this.getIndexName(), vectorBO.getId(), vectorBO);
}
}
}
}
... ...
... ... @@ -8,6 +8,7 @@ import com.yoho.search.consumer.index.common.IYohoIndexService;
import com.yoho.search.consumer.index.fullbuild.BigdataSortBrandVectorW2vIndexBuilder;
import com.yoho.search.consumer.index.increment.AbstractMqListener;
import com.yoho.search.consumer.service.bo.BigdataSortBrandVectorBO;
import com.yoho.search.consumer.service.logicService.BrandVectorBOLogicService;
import com.yoho.search.core.message.beans.SearchMqConsumerListerner;
import com.yoho.search.dal.model.BigdataSortBrandVectorW2v;
import org.slf4j.Logger;
... ... @@ -24,7 +25,7 @@ public class BigdataSortBrandVectorW2vMqListener extends AbstractMqListener {
@Autowired
private IYohoIndexService indexService;
@Autowired
private BigdataSortBrandVectorW2vIndexBuilder bigdataSortBrandVectorW2vIndexBuilder;
private BrandVectorBOLogicService brandVectorBOLogicService;
@Override
protected String getIndexName() {
... ... @@ -46,7 +47,7 @@ public class BigdataSortBrandVectorW2vMqListener extends AbstractMqListener {
BigdataSortBrandVectorW2v bigdataSortBrandVector = ConvertUtils.toJavaObject(BigdataSortBrandVectorW2v.class, data);
if (bigdataSortBrandVector != null && bigdataSortBrandVector.getBrandId() != null && bigdataSortBrandVector.getMiddleSortId() != null) {
String indexId = bigdataSortBrandVector.getBrandId() + "_" + bigdataSortBrandVector.getMiddleSortId();
indexService.deleteIndexData(ISearchConstants.INDEX_NAME_BIGDATA_SORT_BRAND_VECTOR_W2V, indexId);
indexService.deleteIndexData(this.getIndexName(), indexId);
}
}
... ... @@ -54,8 +55,10 @@ public class BigdataSortBrandVectorW2vMqListener extends AbstractMqListener {
protected void updateData(JSONObject data) throws Exception {
BigdataSortBrandVectorW2v vector = ConvertUtils.toJavaObject(BigdataSortBrandVectorW2v.class, data);
if (vector != null && vector.getBrandId() != null && vector.getMiddleSortId() != null) {
BigdataSortBrandVectorBO vectorBO = bigdataSortBrandVectorW2vIndexBuilder.getBigdataSortBrandVectorBO(vector);
indexService.updateIndexData(ISearchConstants.INDEX_NAME_BIGDATA_SORT_BRAND_VECTOR_W2V, vectorBO.getId(), vectorBO);
BigdataSortBrandVectorBO vectorBO = brandVectorBOLogicService.getBigdataSortBrandVectorBO(vector);
if(vectorBO!=null){
indexService.updateIndexData(this.getIndexName(), vectorBO.getId(), vectorBO);
}
}
}
... ...
... ... @@ -25,5 +25,10 @@
<groupId>com.yoho.search</groupId>
<artifactId>search-consumer-dal</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework</artifactId>
<version>4.1.3</version>
</dependency>
</dependencies>
</project>
... ...
package com.yoho.search.consumer.service.bo;
import java.util.List;
public class BigdataBrandVectorBO {
private Long id;
private Integer brandId;
private String vector;
private List<Double> vector;
private Integer updateTime;
public Long getId() {
... ... @@ -22,11 +24,11 @@ public class BigdataBrandVectorBO {
this.brandId = brandId;
}
public String getVector() {
public List<Double> getVector() {
return vector;
}
public void setVector(String vector) {
public void setVector(List<Double> vector) {
this.vector = vector;
}
... ...
package com.yoho.search.consumer.service.bo;
import java.util.List;
public class BigdataSortBrandVectorBO {
private String id;
private Integer brandId;
private Integer middleSortId;
private String vector;
private List<Double> vector;
private Integer updateTime;
public String getId() {
... ... @@ -31,11 +34,11 @@ public class BigdataSortBrandVectorBO {
this.middleSortId = middleSortId;
}
public String getVector() {
public List<Double> getVector() {
return vector;
}
public void setVector(String vector) {
public void setVector(List<Double> vector) {
this.vector = vector;
}
... ...
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;
}
}
}
... ...