Authored by wangnan

新建brandBO

package com.yoho.search.consumer.index.fullbuild;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yoho.search.consumer.index.common.IIndexBuilder;
import com.yoho.search.consumer.service.base.BrandService;
import com.yoho.search.consumer.service.logic.BrandLogicService;
import com.yoho.search.dal.model.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class BrandIndexBuilder extends IIndexBuilder {
@Autowired
private BrandService brandService;
@Override
public int getTotalCount() throws Exception {
return brandService.count();
}
@Override
public List<?> getPageLists(int offset, int limit) throws Exception {
return brandService.getBrandPageLists(offset, limit);
}
@Override
public String getId(Object object) {
return ((Brand)object).getId().toString();
}
@Autowired
private BrandService brandService;
@Autowired
private BrandLogicService brandLogicService;
@Override
public int getTotalCount() throws Exception {
return brandService.count();
}
@Override
public List<?> getPageLists(int offset, int limit) throws Exception {
return brandLogicService.getBrandBOs(offset, limit);
}
@Override
public String getId(Object object) {
return ((Brand) object).getId().toString();
}
}
... ...
package com.yoho.search.consumer.service.bo;
import com.yoho.search.dal.model.Brand;
/**
* Created by wangnan on 2017/3/27.
*/
public class BrandBO extends Brand {
private Integer yohoBrandId;
private String isGlobal = "N";
public Integer getYohoBrandId() {
return yohoBrandId;
}
public void setYohoBrandId(Integer yohoBrandId) {
this.yohoBrandId = yohoBrandId;
}
public String getIsGlobal() {
return isGlobal;
}
public void setIsGlobal(String isGlobal) {
this.isGlobal = isGlobal;
}
}
... ...
package com.yoho.search.consumer.service.logic;
import com.yoho.search.consumer.service.base.BrandService;
import com.yoho.search.consumer.service.bo.BrandBO;
import com.yoho.search.dal.model.Brand;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* Created by wangnan on 2017/3/27.
*/
@Component
public class BrandLogicService {
@Autowired
private BrandService brandService;
public List<BrandBO> getBrandBOs(int start, int limit) {
List<Brand> brandList = brandService.getBrandPageLists(start, limit);
List<BrandBO> brandBOList = new ArrayList<>();
for (Brand brand : brandList) {
BrandBO brandBO = new BrandBO();
BeanUtils.copyProperties(brand, brandBO);
brandBOList.add(brandBO);
}
return brandBOList;
}
}
... ...
package com.yoho.search.consumer.service.logic.tbl;
import com.yoho.search.consumer.service.base.TblBrandService;
import com.yoho.search.dal.model.Brand;
import com.yoho.search.consumer.service.bo.BrandBO;
import com.yoho.search.dal.model.TblBrand;
import com.yoho.search.dal.model.TblBrandRelation;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -24,7 +24,7 @@ public class TblBrandLogicService {
/**
* 增量
*/
public List<Brand> getBrand(List<Integer> ids) {
public List<BrandBO> getBrand(List<Integer> ids) {
List<TblBrand> tblBrands = tblBrandService.selectByIds(ids);
return generateBrand(tblBrands);
}
... ... @@ -32,7 +32,7 @@ public class TblBrandLogicService {
/**
* 全量
*/
public List<Brand> getBrand(int start, int limit) {
public List<BrandBO> getBrand(int start, int limit) {
List<TblBrand> tblBrands = tblBrandService.selectBrandPageList(start, limit);
return generateBrand(tblBrands);
}
... ... @@ -40,39 +40,39 @@ public class TblBrandLogicService {
/**
* 生成BO
*/
private List<Brand> generateBrand(List<TblBrand> tblBrands) {
private List<BrandBO> generateBrand(List<TblBrand> tblBrands) {
Map<Integer, TblBrandRelation> tblBrandRelationMap = tblBrandRelationLogicService.getTblBrandRelationMap();
List<Brand> brands = new ArrayList<>();
List<BrandBO> brandBOList = new ArrayList<>();
for (TblBrand tblBrand : tblBrands) {
Brand brand = new Brand();
brand.setId(tblBrand.getBrandId() * (-1));
BrandBO brandBO = new BrandBO();
brandBO.setId(tblBrand.getBrandId() * (-1));
String brandAlif = tblBrand.getBrandNameEn().substring(0, 1).toUpperCase();
brand.setBrandAlif(brandAlif);
brand.setBrandName(tblBrand.getBrandNameEn());
brand.setBrandNameEn(tblBrand.getBrandNameEn());
brand.setBrandNameCn(tblBrand.getBrandNameCn());
brandBO.setBrandAlif(brandAlif);
brandBO.setBrandName(tblBrand.getBrandNameEn());
brandBO.setBrandNameEn(tblBrand.getBrandNameEn());
brandBO.setBrandNameCn(tblBrand.getBrandNameCn());
//如果全球购和有货之间存在映射
if (tblBrandRelationMap.containsKey(tblBrand.getBrandId())) {
TblBrandRelation tblBrandRelation = tblBrandRelationMap.get(tblBrand.getBrandId());
brand.setYohoBrandId(tblBrandRelation.getYohoBrandId());
brandBO.setYohoBrandId(tblBrandRelation.getYohoBrandId());
}
if (tblBrand.getHot().equals("1")) {
brand.setIsHot("N");
brandBO.setIsHot("N");
} else {
brand.setIsHot("Y");
brandBO.setIsHot("Y");
}
if (tblBrand.getStatus().equals("1")) {
brand.setStatus(0);
brandBO.setStatus(0);
} else {
brand.setStatus(1);
brandBO.setStatus(1);
}
brand.setIsGlobal("Y");
brand.setBrandIco(tblBrand.getLogo());
brand.setBrandDomain(null);
brand.setBrandKeyword(null);
brand.setHotKeyword(null);
brands.add(brand);
brandBO.setIsGlobal("Y");
brandBO.setBrandIco(tblBrand.getLogo());
brandBO.setBrandDomain(null);
brandBO.setBrandKeyword(null);
brandBO.setHotKeyword(null);
brandBOList.add(brandBO);
}
return brands;
return brandBOList;
}
}
... ...