xinyb
2024-07-18 80430d52f7716e3eb3e517dc96f94c4a6f9657bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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;
    }
}