package com.yc.sdk.shopping.service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.springframework.context.annotation.Scope;
|
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.EmptyResultDataAccessException;
|
import org.springframework.stereotype.Service;
|
|
import com.yc.action.grid.GridUtils;
|
import com.yc.sdk.shopping.entity.BrandEntity;
|
import com.yc.service.BaseService;
|
|
@Service("BrandImpl")
|
@Scope("prototype")
|
public class BrandImpl extends BaseService implements BrandIfc {
|
|
@Override
|
public List<BrandEntity> getBrands(String shopCcCode) {
|
String sql = " set nocount on ; \n"
|
+ " declare @ShopCcCode varchar(50) = "+GridUtils.prossSqlParm(shopCcCode)+" \n"
|
+ " select a.BrandId,a.Brand,a.BrandName,a.Image, a.SortOrder, \n"
|
+ " dbo.fGetPinYinFirstAlphabet(a.Brand) as FirstAlphabet,a.ShopBrand \n"
|
+ " from t110504 a \n"
|
+ " where ISNULL(a.Status,0) = 1 \n"
|
+ " and (isnull(@ShopCcCode,'') = '' or a.ShopCcCode = @ShopCcCode ) \n"
|
+ " order by a.SortOrder asc,a.Brand asc ;" ;
|
List<Map<String,Object>> list = null ;
|
List<BrandEntity> brandList = null ;
|
try {
|
list = this.jdbcTemplate.queryForList(sql) ;
|
brandList = new ArrayList<BrandEntity>() ;
|
for (int i = 0 ; list != null && i < list.size();i++) {
|
Map<String,Object> map = list.get(i) ;
|
BrandEntity brand = new BrandEntity();
|
brand.setBrandId(map.get("BrandId") == null ? 0: (Integer)map.get("BrandId"));
|
brand.setBrand(map.get("Brand") == null ? "": (String)map.get("Brand"));
|
brand.setBrandName(map.get("BrandName") == null ? "": (String)map.get("BrandName"));
|
brand.setImage(map.get("Image") == null ? "": (String)map.get("Image"));
|
brand.setFirstAlphabet(map.get("FirstAlphabet") == null ? "": (String)map.get("FirstAlphabet"));
|
brand.setShopBrand(map.get("ShopBrand") == null ? "": (String)map.get("ShopBrand"));
|
brandList.add(brand);
|
}
|
}catch(DataAccessException e ) {
|
if (e instanceof EmptyResultDataAccessException){
|
return null ;
|
}else {
|
e.printStackTrace();
|
throw e;
|
}
|
}catch(Exception e){
|
e.printStackTrace();
|
throw e;
|
}
|
return brandList;
|
}
|
|
|
@Override
|
public List<BrandEntity> getBrandFirstAlphabet(String shopCcCode) {
|
String sql = " set nocount on ; \n"
|
+ " declare @ShopCcCode varchar(50) = "+GridUtils.prossSqlParm(shopCcCode)+" \n"
|
+ " select distinct dbo.fGetPinYinFirstAlphabet(a.Brand) as FirstAlphabet,a.ShopBrand \n"
|
+ " from t110504 a \n"
|
+ " where ISNULL(a.Status,0) = 1 \n"
|
+ " and (isnull(@ShopCcCode,'') = '' or a.ShopCcCode = @ShopCcCode ) \n"
|
+ " order by dbo.fGetPinYinFirstAlphabet(a.Brand) asc ;" ;
|
List<Map<String,Object>> list = null ;
|
List<BrandEntity> brandList = null ;
|
try {
|
list = this.jdbcTemplate.queryForList(sql) ;
|
brandList = new ArrayList<BrandEntity>() ;
|
for (int i = 0 ; list != null && i < list.size();i++) {
|
Map<String,Object> map = list.get(i) ;
|
BrandEntity brand = new BrandEntity();
|
brand.setFirstAlphabet(map.get("FirstAlphabet") == null ? "": (String)map.get("FirstAlphabet"));
|
brand.setShopBrand(map.get("ShopBrand") == null ? "": (String)map.get("ShopBrand"));
|
brandList.add(brand);
|
}
|
}catch(DataAccessException e ) {
|
if (e instanceof EmptyResultDataAccessException){
|
return null ;
|
}else {
|
e.printStackTrace();
|
throw e;
|
}
|
}catch(Exception e){
|
e.printStackTrace();
|
throw e;
|
}
|
return brandList;
|
}
|
|
|
|
@Override
|
public BrandEntity getBrand(Integer brandId,String shopCcCode) {
|
String sql = " set nocount on ; \n"
|
+ " declare @BrandId int = "+brandId+" \n"
|
+ " declare @ShopCcCode varchar(50) = "+GridUtils.prossSqlParm(shopCcCode)+" \n"
|
+ " select a.BrandId,a.Brand,a.BrandName,a.Image,a.ShopBrand \n"
|
+ " from t110504 a \n"
|
+ " where a.BrandId = @BrandId and ISNULL(a.Status,0) = 1 \n"
|
+ " and (isnull(@ShopCcCode,'') = '' or a.ShopCcCode = @ShopCcCode ) \n"
|
+ " order by a.SortOrder asc,a.Brand asc ;" ;
|
BrandEntity brand = null ;
|
Map<String,Object> map = null ;
|
try {
|
map = this.jdbcTemplate.queryForMap(sql) ;
|
if (map != null && map.size() > 0 ) {
|
brand = new BrandEntity();
|
brand.setBrandId(map.get("BrandId") == null ? 0: (Integer)map.get("BrandId"));
|
brand.setBrand(map.get("Brand") == null ? "": (String)map.get("Brand"));
|
brand.setBrandName(map.get("BrandName") == null ? "": (String)map.get("BrandName"));
|
brand.setImage((String)map.get("Image") == null ? "": (String)map.get("Image"));
|
brand.setShopBrand(map.get("ShopBrand") == null ? "": (String)map.get("ShopBrand"));
|
}
|
}catch(DataAccessException e ) {
|
if (e instanceof EmptyResultDataAccessException){
|
return null ;
|
}else {
|
e.printStackTrace();
|
throw e;
|
}
|
}catch(Exception e){
|
e.printStackTrace();
|
throw e;
|
}
|
return brand;
|
}
|
}
|