提交 | 用户 | age
|
a6a76f
|
1 |
package com.yc.sdk.shopping.service; |
F |
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
|
|
7 |
import org.springframework.context.annotation.Scope; |
|
8 |
import org.springframework.dao.DataAccessException; |
|
9 |
import org.springframework.dao.EmptyResultDataAccessException; |
|
10 |
import org.springframework.stereotype.Service; |
|
11 |
|
a92f52
|
12 |
import com.yc.action.grid.GridUtils; |
a6a76f
|
13 |
import com.yc.sdk.shopping.entity.NavigatorEntity; |
F |
14 |
import com.yc.sdk.shopping.util.SettingKey; |
|
15 |
import com.yc.service.BaseService; |
|
16 |
|
|
17 |
@Service("NavigatorImpl") |
|
18 |
@Scope("prototype") |
|
19 |
public class NavigatorImpl extends BaseService implements NavigatorIfc { |
|
20 |
|
|
21 |
@Override |
|
22 |
public List<NavigatorEntity> getNavigator(String fromMatGroup,String fromBrand,String fromMatCode,String shopCcCode) { |
|
23 |
List<NavigatorEntity> navList = new ArrayList<NavigatorEntity>() ; |
|
24 |
String matGroupPath = "" ; |
|
25 |
try { |
|
26 |
// 商品分类 |
|
27 |
if (fromMatGroup != null && ! "".equals(fromMatGroup)) { |
|
28 |
String matGroups[] = fromMatGroup.split(SettingKey.NAVSPLIT); |
|
29 |
String matGroup = "" ; |
|
30 |
for(int k = 0 ; k< matGroups.length; k ++) { |
|
31 |
matGroup = (matGroup.equals("") ? "" : matGroup + ",") +"'" + matGroups[k].trim() + "'"; |
|
32 |
} |
|
33 |
|
|
34 |
String sql = " set nocount on ; \n" |
a92f52
|
35 |
+ " declare @ShopCcCode varchar(50) = "+GridUtils.prossSqlParm(shopCcCode)+" \n" |
a6a76f
|
36 |
+ " select MatGroup,MatGroupName \n" |
F |
37 |
+ " from t110501 a \n" |
|
38 |
+ " where a.MatGroup in (" + matGroup + ") and isnull(a.Status,0) = 1 \n" |
|
39 |
+ " and (isnull(@ShopCcCode,'') = '' or a.ShopCcCode = @ShopCcCode ) \n" |
|
40 |
+ " order by a.treecontrol asc; \n" ; |
|
41 |
List<Map<String,Object>> list = null ; |
|
42 |
|
a92f52
|
43 |
list = this.jdbcTemplate.queryForList(sql) ; |
a6a76f
|
44 |
for (int i = 0 ; list != null && i < list.size();i++) { |
F |
45 |
Map<String,Object> map = list.get(i) ; |
|
46 |
matGroupPath = (matGroupPath.equals("") ? "" : matGroupPath + SettingKey.NAVSPLIT ) |
|
47 |
+ (map.get("MatGroup") == null ? "": (String)map.get("MatGroup")) ; |
|
48 |
|
|
49 |
NavigatorEntity nav = new NavigatorEntity(); |
|
50 |
nav.setCode(map.get("MatGroup") == null ? "": (String)map.get("MatGroup")); |
|
51 |
nav.setName(map.get("MatGroupName") == null ? "": (String)map.get("MatGroupName")); |
|
52 |
nav.setIsMatGroup(true); |
|
53 |
nav.setMatGroupPath(matGroupPath); |
|
54 |
navList.add(nav); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
//品牌 |
|
59 |
if (fromBrand != null && ! "".equals(fromBrand)) { |
|
60 |
String sql2 = " set nocount on ; \n" |
a92f52
|
61 |
+ " declare @BrandId int = "+fromBrand+" \n" |
J |
62 |
+ " declare @ShopCcCode varchar(50) = "+GridUtils.prossSqlParm(shopCcCode)+" \n" |
a6a76f
|
63 |
+ " select cast(BrandId as varchar) as BrandId,Brand \n" |
F |
64 |
+ " from t110504 a \n" |
|
65 |
+ " where a.BrandId = @BrandId and isnull(a.Status,0) = 1 \n " |
|
66 |
+ " and (isnull(@ShopCcCode,'') = '' or a.ShopCcCode = @ShopCcCode ) \n"; |
a92f52
|
67 |
List<Map<String,Object>> list = this.jdbcTemplate.queryForList(sql2) ; |
a6a76f
|
68 |
for (int i = 0 ; list != null && i < list.size();i++) { |
F |
69 |
Map<String,Object> map = list.get(i) ; |
|
70 |
NavigatorEntity nav = new NavigatorEntity(); |
|
71 |
nav.setCode(map.get("BrandId") == null ? "": (String)map.get("BrandId")); |
|
72 |
nav.setName(map.get("Brand") == null ? "": (String)map.get("Brand")); |
|
73 |
nav.setBrand(true); |
|
74 |
nav.setMatGroupPath(fromBrand); //设置最后一次的路径 |
|
75 |
navList.add(nav); |
|
76 |
} |
|
77 |
|
|
78 |
} |
|
79 |
|
|
80 |
//商品 |
|
81 |
if (fromMatCode != null && ! "".equals(fromMatCode)) { |
|
82 |
String sql2 = " set nocount on ; \n" |
a92f52
|
83 |
+ " declare @MatCode varchar(50) = "+GridUtils.prossSqlParm(fromMatCode)+" \n" |
J |
84 |
+ " declare @ShopCcCode varchar(50) = "+GridUtils.prossSqlParm(shopCcCode)+" \n" |
a6a76f
|
85 |
+ " select MatCode,MatName \n" |
F |
86 |
+ " from t110503 a \n" |
|
87 |
+ " where a.MatCode = @MatCode and isnull(a.Status,0) = 1 \n " |
|
88 |
+ " and (isnull(@ShopCcCode,'') = '' or a.ShopCcCode = @ShopCcCode ) \n"; |
a92f52
|
89 |
List<Map<String,Object>> list = this.jdbcTemplate.queryForList(sql2) ; |
a6a76f
|
90 |
for (int i = 0 ; list != null && i < list.size();i++) { |
F |
91 |
Map<String,Object> map = list.get(i) ; |
|
92 |
NavigatorEntity nav = new NavigatorEntity(); |
|
93 |
nav.setCode(map.get("MatCode") == null ? "": (String)map.get("MatCode")); |
|
94 |
nav.setName(map.get("MatName") == null ? "": (String)map.get("MatName")); |
|
95 |
nav.setIsMatGroup(false); |
|
96 |
nav.setMatGroupPath(matGroupPath); //设置最后一次的路径 |
|
97 |
navList.add(nav); |
|
98 |
} |
|
99 |
} |
|
100 |
}catch(DataAccessException e ) { |
|
101 |
if (e instanceof EmptyResultDataAccessException){ |
|
102 |
return null ; |
|
103 |
}else { |
|
104 |
e.printStackTrace(); |
|
105 |
throw e; |
|
106 |
} |
|
107 |
}catch(Exception e){ |
|
108 |
e.printStackTrace(); |
|
109 |
throw e; |
|
110 |
} |
|
111 |
|
|
112 |
return navList; |
|
113 |
} |
|
114 |
|
|
115 |
} |