提交 | 用户 | age
a6a76f 1 package com.yc.sdk.shopping.service;
F 2
5a4acf 3 import com.google.gson.Gson;
F 4 import com.google.gson.reflect.TypeToken;
5 import com.yc.sdk.shopping.entity.*;
6 import com.yc.sdk.shopping.service.imagedata.ShoppingImageDataIfc;
7 import com.yc.sdk.shopping.util.SettingKey;
8 import com.yc.service.BaseService;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.context.annotation.Scope;
11 import org.springframework.dao.DataAccessException;
12 import org.springframework.dao.EmptyResultDataAccessException;
13 import org.springframework.stereotype.Service;
14
15 import javax.servlet.http.HttpServletRequest;
a6a76f 16 import java.math.BigDecimal;
F 17 import java.math.RoundingMode;
18 import java.util.ArrayList;
19 import java.util.Date;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Map.Entry;
23
24 @Service("CartImpl")
25 @Scope("prototype")
26 public class CartImpl extends BaseService implements CartIfc {
27     static Gson gson=new Gson();
28     @Autowired
29     MatPriceIfc matPriceIfc ;
30     @Autowired
31     SettingIfc settingIfc;
32     @Autowired
33     CurrencyIfc currencyIfc;
34     @Autowired    ShoppingImageDataIfc shoppingImageDataIfc;
35     
36     @Override
37     public Integer addToCart(CartEntity cart) {
38         String sql = " set nocount on ;  \n"
39                 + " declare @UserCode varchar(20) = ?,@UserName varchar(50) = ? ,@SessionId varchar(200) = ?,@OpenId varchar(200) = ?; \n"
40                 + " declare @CltCode varchar(50) = ?,@CltName varchar(100) = ? ;  \n"
41                 + " declare @MatCode varchar(50) = ?,@MatName varchar(200),@Special varchar(200); \n "
42                 + " declare @PhotoPath varchar(200) ,@WeightUom varchar(50) ;\n"
43                 + " declare @RecurringId int = ? ,@OptionJson varchar(2000) = ?,@OptionText varchar(2000)  = ?;\n"
a25d9c 44                 + " declare @Quantity money = ?,@Price money = ?,@manualPrice money=? \n" +
F 45                 "   declare @Amount money = round(isnull(@Quantity,0) * isnull(@manualPrice,0),2),@VoucherDocCode varchar(50) = ?,@CartId int ; \n"
a6a76f 46                 + " declare @found int = 0 ;"
F 47                 + "    declare @refDocCode varchar(50) = ?,@refFormId int = ?,@refFormType int = ?,@refRowId varchar(50) = ? \n"
48                 + " declare @isGoShop int = ? \n"
49                 + " declare @skuId1 int = ?,@skuId2 int = ?,@skuId3 int = ?,@skuId4 int = ?, \n"
a25d9c 50                 + "   @skuId5 int = ?,@skuId6 int = ?,@skuId7 int = ?,@skuId8 int = ?,@skuId9 int = ?,@skuId10 int = ? \n"
a6a76f 51                 + " declare @skuName1 varchar(50),@skuName2 varchar(50),@skuName3 varchar(50),@skuName4 varchar(50),@skuName5 varchar(50), \n"
F 52                 + "   @skuName6 varchar(50),@skuName7 varchar(50),@skuName8 varchar(50),@skuName9 varchar(50),@skuName10 varchar(50) \n"
53
54                 + " select @CartId = CartId from t710205 a \n"
55                 + " where isnull(a.UserCode,'') = isnull(@UserCode,'')  \n"
56                 + " and isnull(a.SessionId,'') = isnull(@SessionId,'')\n"
57                 + " and isnull(a.CltCode,'') = isnull(@CltCode,'')  \n"
58                 + " and isnull(a.OpenId,'') = isnull(@OpenId,'')  \n"
59                 + " and isnull(a.MatCode,'') = isnull(@MatCode,'') \n"
60                 + " and ISNULL(a.OptionJson,'') = ISNULL(@OptionJson,'')   \n"
61                 + " and ISNULL(a.refDocCode,'') = ISNULL(@refDocCode,'')   \n"
62                 + " and isnull(a.skuId1,0) = isnull(@skuId1,0) and isnull(a.skuId2,0) = isnull(@skuId2,0) and isnull(a.skuId3,0) = isnull(@skuId3,0)  and isnull(a.skuId4,0) = isnull(@skuId4,0) and isnull(a.skuId5,0) = isnull(@skuId5,0) \n"
63                 + " and isnull(a.skuId6,0) = isnull(@skuId6,0) and isnull(a.skuId7,0) = isnull(@skuId7,0) and isnull(a.skuId8,0) = isnull(@skuId8,0) and isnull(a.skuId9,0) = isnull(@skuId9,0) and isnull(a.skuId10,0) = isnull(@skuId10,0) ; \n"
64                 + " if isnull(@@rowcount,0) > 0  select @found = 1  \n"
65                 + " if isnull(@found,0) = 0 \n"
66                 + " begin \n"
67                 + "    select @CartId = CartId from t710205 a \n"
68                 + "    where isnull(@UserCode,'') <> '' and isnull(a.UserCode,'') = isnull(@UserCode,'')  \n"
69                 + "    and isnull(a.MatCode,'') = isnull(@MatCode,'') \n"
70                 + "    and ISNULL(a.OptionJson,'') = ISNULL(@OptionJson,'')   \n"
71                 + "    and ISNULL(a.refDocCode,'') = ISNULL(@refDocCode,'')   \n"
72                 + "    and isnull(a.skuId1,0) = isnull(@skuId1,0) and isnull(a.skuId2,0) = isnull(@skuId2,0) and isnull(a.skuId3,0) = isnull(@skuId3,0)  and isnull(a.skuId4,0) = isnull(@skuId4,0) and isnull(a.skuId5,0) = isnull(@skuId5,0) \n"
73                 + "    and isnull(a.skuId6,0) = isnull(@skuId6,0) and isnull(a.skuId7,0) = isnull(@skuId7,0) and isnull(a.skuId8,0) = isnull(@skuId8,0) and isnull(a.skuId9,0) = isnull(@skuId9,0) and isnull(a.skuId10,0) = isnull(@skuId10,0) ; \n"
74                 + " end \n"
75
76                 + " if isnull(@@rowcount,0) > 0  select @found = 1  \n"
77                 
78                 + " if isnull(@found,0) = 0 \n"
79                 + " begin \n"
80                 + "    select @CartId = CartId from t710205 a \n"
81                 + "    where isnull(@SessionId,'') <> '' and isnull(a.SessionId,'') = isnull(@SessionId,'')  \n"
82                 + "    and isnull(a.MatCode,'') = isnull(@MatCode,'') \n"
83                 + "    and ISNULL(a.refDocCode,'') = ISNULL(@refDocCode,'')   \n"
84                 + "    and ISNULL(a.OptionJson,'') = ISNULL(@OptionJson,'')   \n"
85                 + "    and isnull(a.skuId1,0) = isnull(@skuId1,0) and isnull(a.skuId2,0) = isnull(@skuId2,0) and isnull(a.skuId3,0) = isnull(@skuId3,0)  and isnull(a.skuId4,0) = isnull(@skuId4,0) and isnull(a.skuId5,0) = isnull(@skuId5,0) \n"
86                 + "    and isnull(a.skuId6,0) = isnull(@skuId6,0) and isnull(a.skuId7,0) = isnull(@skuId7,0) and isnull(a.skuId8,0) = isnull(@skuId8,0) and isnull(a.skuId9,0) = isnull(@skuId9,0) and isnull(a.skuId10,0) = isnull(@skuId10,0) ; \n"
87                 + "    if isnull(@@rowcount,0) > 0  select @found = 1  \n"
88                 + " end \n"
89                 
90                 + " if isnull(@found,0) = 0 \n"
91                 + " begin \n"
92                 + "    select @CartId = CartId from t710205 a \n"
93                 + "    where isnull(@CltCode,'') <> '' and isnull(a.CltCode,'') = isnull(@CltCode,'')  \n"
94                 + "    and isnull(a.MatCode,'') = isnull(@MatCode,'') \n"
95                 + "    and ISNULL(a.refDocCode,'') = ISNULL(@refDocCode,'')   \n"
96                 + "    and ISNULL(a.OptionJson,'') = ISNULL(@OptionJson,'')   \n"
97                 + "    and isnull(a.skuId1,0) = isnull(@skuId1,0) and isnull(a.skuId2,0) = isnull(@skuId2,0) and isnull(a.skuId3,0) = isnull(@skuId3,0)  and isnull(a.skuId4,0) = isnull(@skuId4,0) and isnull(a.skuId5,0) = isnull(@skuId5,0) \n"
98                 + "    and isnull(a.skuId6,0) = isnull(@skuId6,0) and isnull(a.skuId7,0) = isnull(@skuId7,0) and isnull(a.skuId8,0) = isnull(@skuId8,0) and isnull(a.skuId9,0) = isnull(@skuId9,0) and isnull(a.skuId10,0) = isnull(@skuId10,0) ; \n"
99                 
100                 + "    if isnull(@@rowcount,0) > 0  select @found = 1  \n"
101                 + " end \n"
102                 
103                 + " if isnull(@found,0) = 0 \n"
104                 + " begin \n"
105                 + "    select @CartId = CartId from t710205 a \n"
106                 + "    where isnull(@OpenId,'') <> '' and isnull(a.OpenId,'') = isnull(@OpenId,'')  \n"
107                 + "    and isnull(a.MatCode,'') = isnull(@MatCode,'') \n"
108                 + "    and ISNULL(a.refDocCode,'') = ISNULL(@refDocCode,'')   \n"
109                 + "    and ISNULL(a.OptionJson,'') = ISNULL(@OptionJson,'')   \n"
110                 + "    and isnull(a.skuId1,0) = isnull(@skuId1,0) and isnull(a.skuId2,0) = isnull(@skuId2,0) and isnull(a.skuId3,0) = isnull(@skuId3,0)  and isnull(a.skuId4,0) = isnull(@skuId4,0) and isnull(a.skuId5,0) = isnull(@skuId5,0) \n"
111                 + "    and isnull(a.skuId6,0) = isnull(@skuId6,0) and isnull(a.skuId7,0) = isnull(@skuId7,0) and isnull(a.skuId8,0) = isnull(@skuId8,0) and isnull(a.skuId9,0) = isnull(@skuId9,0) and isnull(a.skuId10,0) = isnull(@skuId10,0) ; \n"
112                 
113                 + "    if isnull(@@rowcount,0) > 0  select @found = 1  \n"
114                 + " end \n"
115                 
116                 + " if isnull(@found,0) = 1 \n"
117                 + " begin \n"
118                 + "    update a set Quantity = case when isnull(@isGoShop,0) = 0 then isnull(a.Quantity,0) + isnull(@Quantity,0) else isnull(@Quantity,0) end,isSelected=1 \n"
119                 + "    from t710205 a where CartId = @CartId ; \n "
120                 //+ "    select @CartId as 'Identity' \n"
121                 + " end \n"
122                 + " else begin \n"
123                 + "    select @MatName = MatName ,@Special = Special,@PhotoPath=PhotoPath,@WeightUom = WeightUom \n"
124                 + "    from t110503 where MatCode = @MatCode; \n "
125                 + "    if @@rowcount = 0 begin \n"
126                 + "         raiserror('商品编号【%s】不存在,请在110503功能号中设置该商品信息',16,1,@MatCode) ;  \n"
127                 + "         return ;  \n"
128                 + "    end \n"
129                 + "    if isnull(@WeightUom,'') = ''  select @WeightUom = WeightClassId from t714001   ; \n"
130
131                 + "    select top 1 @skuName1=a.skuName1,@skuName2=a.skuName2,@skuName3=a.skuName3,@skuName4=a.skuName4,@skuName5=a.skuName5,  \n"
132                 + "      @skuName6=a.skuName6,@skuName7=a.skuName7,@skuName8=a.skuName8,@skuName9=a.skuName9,@skuName10=a.skuName10 \n"
133                 + "    from t710175D a \n"
134                 + "    join t110503 b on a.MatCode = b.MatCode \n"
135                 + "    where a.MatCode = isnull(@MatCode,'') and isnull(a.skuId1,0) = isnull(@skuId1,0) and isnull(a.skuId2,0) = isnull(@skuId2,0) and isnull(a.skuId3,0) = isnull(@skuId3,0)  and isnull(a.skuId4,0) = isnull(@skuId4,0) and isnull(a.skuId5,0) = isnull(@skuId5,0) \n"
136                 + "    and isnull(a.skuId6,0) = isnull(@skuId6,0) and isnull(a.skuId7,0) = isnull(@skuId7,0) and isnull(a.skuId8,0) = isnull(@skuId8,0) and isnull(a.skuId9,0) = isnull(@skuId9,0) and isnull(a.skuId10,0) = isnull(@skuId10,0) \n"
5a4acf 137
a6a76f 138                 + "    insert into t710205 (UserCode,UserName,SessionId,OpenId,CltCode,CltName,  \n"
F 139                 + "      MatCode,MatName,Special,PhotoPath,RecurringId, \n"
a25d9c 140                 + "      OptionJson,OptionText,Quantity,Price,manualPrice,Amount,WeightUom,DateAdded,VoucherDocCode,\n"
a6a76f 141                 + "      refDocCode,refFormId,refFormType,refRowId,isSelected,MatGroupStatus,\n"
F 142                 + "      skuId1,skuName1,skuId2,skuName2,skuId3,skuName3,skuId4,skuName4,skuId5,skuName5,\n"
a25d9c 143                 + "      skuId6,skuName6,skuId7,skuName7,skuId8,skuName8,skuId9,skuName9,skuId10,skuName10)  \n"
a6a76f 144                 + "    values(isnull(@UserCode,''),isnull(@UserName,''),isnull(@SessionId,''),isnull(@OpenId,''), \n"
F 145                 + "      isnull(@CltCode,''),isnull(@CltName,''), isnull(@MatCode,''),isnull(@MatName,''), \n"
a25d9c 146                 + "      @Special,@PhotoPath,@RecurringId,  isnull(@OptionJson,''),isnull(@OptionText,''),@Quantity,@Price,@manualPrice,@Amount, \n"
a6a76f 147                 + "      @WeightUom,getdate(),isnull(@VoucherDocCode,''),isnull(@refDocCode,''),@refFormId,@refFormType,@refRowId,1,1,"
F 148                 + "      @skuId1,@skuName1,@skuId2,@skuName2,@skuId3,@skuName3,@skuId4,@skuName4,@skuId5,@skuName5,"
a25d9c 149                 + "      @skuId6,@skuName6,@skuId7,@skuName7,@skuId8,@skuName8,@skuId9,@skuName9,@skuId10,@skuName10) ; \n"
a6a76f 150                 + "    SELECT @CartId = @@IDENTITY  ; \n"
F 151                 + " end \n"
152                 + " exec p710205v8 @CartId = @CartId \n"   //刷新购物车中的价格、积分和重量
153                 + " select  @CartId as 'Identity' \n";
154         Integer cartId = null ;
155         try{
0cbf06 156             cartId = this.jdbcTemplate.queryForObject(sql, Integer.class,
5a4acf 157                     new Object[]{cart.getUserCode(), cart.getUserName(), cart.getSessionId(), cart.getOpenId(),
F 158                             cart.getCltCode(), cart.getCltName(),
159                             cart.getMatCode(), cart.getRecurringId(),
160                             cart.getOptionJson(), cart.getOptionText(), cart.getQuantity(),
a25d9c 161                             cart.getPrice(), cart.getManualPrice(),
5a4acf 162                             cart.getVoucherDocCode(), cart.getRefDocCode(),
F 163                             cart.getRefFormId(), cart.getRefFormType(), cart.getRefRowId(), cart.isGoShop() ? 1 : 0,
164                             cart.getSkuId1(), cart.getSkuId2(), cart.getSkuId3(), cart.getSkuId4(), cart.getSkuId5(),
0cbf06 165                             cart.getSkuId6(), cart.getSkuId7(), cart.getSkuId8(), cart.getSkuId9(), cart.getSkuId10()});
a6a76f 166 //            if (cart.isRefreshPrice()) {
F 167 //                //刷新购物车中的价格、积分和重量
168 //                this.refrshCart(cartId,cart.getCltCode());
169 //            }
170         }catch(DataAccessException e ) {
171             if (e instanceof EmptyResultDataAccessException){
172                 return null ;
173             }else {
174                 e.printStackTrace();
175                  throw e;
176             }
177         }catch(Exception e){
178             e.printStackTrace();
179             throw e;
180         }
181             
182         return cartId ;    
183     }
184     
185     
186     @Override
187     public Integer saveCartByPicture(CartEntity cart) {
188         String sql = " set nocount on ;  \n"
189                 + " declare @CltCode varchar(50) = ?,@CltName varchar(100)  = ?;  \n"
190                 + " declare @MatCode varchar(50) = ?,@MatName varchar(200),@Special varchar(200); \n "
191                 + " declare @PhotoPath varchar(200)  ;\n"
192                 + " declare @Quantity money = ?,@Price money = ?,@Amount money = ?,@CartId int ; \n"
193                 + " declare @found int = 0 ;"
194
195                 + " select @CartId = CartId from t710401 a \n"
196                 + " where isnull(a.CltCode,'') = isnull(@CltCode,'')  \n"
197                 + " and isnull(a.MatCode,'') = isnull(@MatCode,'') \n"
198
199                 + " if isnull(@@rowcount,0) > 0  select @found = 1  \n"
200                 
201                 
202                 + " if isnull(@found,0) = 1 begin \n"
203                 + "    update a set Quantity = isnull(Quantity,0) + isnull(@Quantity,0), \n"
204                 + "       Amount = round((isnull(Quantity,0) + isnull(@Quantity,0)) * isnull(Price,0),2) "
205                 + "    from t710401 a where CartId = @CartId ; \n "
206                 + "    select @CartId as 'Identity' \n"
207                 + " end \n"
208                 + " else begin \n"
209                 + "    select @MatName = MatName ,@Special = Special,@PhotoPath=PhotoPath \n"
210                 + "    from t110503 where MatCode = @MatCode; \n "
211                 + "    if @@rowcount = 0 begin \n"
212                 + "         raiserror('商品编号【%s】不存在,请在110503功能号中设置该商品信息',16,1,@MatCode) ;  \n"
213                 + "         return ;  \n"
214                 + "    end \n"
215
216                 + "    insert into t710401 (CltCode,CltName,  \n"
217                 + "      MatCode,MatName,Special,PhotoPath,\n"
218                 + "      Quantity,Price,Amount,DateAdded)  \n"
219                 + "    values(isnull(@CltCode,''),isnull(@CltName,''), isnull(@MatCode,''),isnull(@MatName,''), \n"
220                 + "      @Special,@PhotoPath,@Quantity,@Price,round(isnull(@Quantity,0) * isnull(@Price,0),2) , \n"
221                 + "      getdate()) ; \n"
222                 + "    SELECT @@IDENTITY AS 'Identity' ; \n"
223                 + " end \n";
224         Integer cartId = null ;
225         try{
0cbf06 226             cartId =  this.jdbcTemplate.queryForObject(sql, Integer.class, 
a6a76f 227                     new Object[] {cart.getCltCode(),cart.getCltName(),
F 228                             cart.getMatCode(),cart.getQuantity(),
0cbf06 229                             cart.getPrice(),cart.getAmount()}) ;
a6a76f 230         }catch(DataAccessException e ) {
F 231             if (e instanceof EmptyResultDataAccessException){
232                 return null ;
233             }else {
234                 e.printStackTrace();
235                  throw e;
236             }
237         }catch(Exception e){
238             e.printStackTrace();
239             throw e;
240         }
241     
242         return cartId ;    
243     }
244
245     @Deprecated
246     @Override
247     public void refrshCart(Integer cartId,String cltCode) {
248         CartEntity myCart = this.getCart(cartId);
249         if (myCart == null)  return ;
250         
251         Double price = null;
252         double points = 0,weight = 0 ;
253         //取价格
254         MatPriceEntity matPriceEntity = matPriceIfc.getOrderPrice(myCart.getMatCode(), cltCode, myCart.getDateAdded(), myCart.getQuantity());
255         if (matPriceEntity != null) {
256             price = matPriceEntity.getPrice();
257             points = matPriceEntity.getPoints();
258             weight = matPriceEntity.getWeight();
259         }
260         //取出选项附加的价格
261         MatOptionPriceEntity matOptionPrice = matPriceIfc.getOptionPriceAndWeight(cartId);
262         if (matOptionPrice != null) {
263             if (matOptionPrice.getPrice()!=null) {
264                 if (price != null) {
265                     price += matOptionPrice.getPrice();
266                 }else {
267                     price = matOptionPrice.getPrice();
268                 }
269             }
270             points += matOptionPrice.getPoints();
271             weight += matOptionPrice.getWeight();
272         }
273                 
274         //四舍五入后汇总
275         Double   amount = null ;
276         if (price!=null) {
277             BigDecimal   a   =   new   BigDecimal(myCart.getQuantity() * price); 
278             amount   = a.setScale(2,RoundingMode.HALF_UP).doubleValue();  
279         }
280         
281         //四舍五入后汇总
282         BigDecimal   b   =   new   BigDecimal(points*myCart.getQuantity()); 
283         points = b.setScale(2,RoundingMode.HALF_UP).doubleValue();  
284
285         //四舍五入后汇总
286         BigDecimal   c   =   new   BigDecimal(weight*myCart.getQuantity()); 
287         weight = c.setScale(2,RoundingMode.HALF_UP).doubleValue();  
288         
289         //再次更新价格,因为有可能数量变化后,会引起价格变动
290         this.updateCartPrice(cartId, price, amount,points,weight);
291             
292     }
293     
294     @Override
295     public List<CartEntity> getMatCodesByGroupBuying(String matCode,Double quantity,SkuMatCodeEntity skuMatCodeEntity) {
296         if (matCode==null||"".equals(matCode)) return null ;
297         String sql = " set nocount on ; \n"
298                 + " declare @MatCode varchar(20) = ? ,@Quantity money = ? \n;"
299                 + " declare @TotalQuantity money,@TotalAmount money,@TotalWeight money \n"
300                 + " declare @MaxPreSendDateTime datetime = getdate() ,@MaxPreSendMinutes int; \n"
301                 + " declare @table table(CartId int,UserCode varchar(20),UserName varchar(50), \n"
302                 + "     SessionId varchar(200),CltCode varchar(50),CltName varchar(200),\n"
303                 + "     MatCode varchar(50),MatName varchar(200), \n"
304                 + "     Special varchar(200),PhotoPath varchar(200),BaseUomWeight money,\n"
305                 + "     RecurringId int,OptionJson varchar(200),OptionText varchar(200),\n"
306                 + "     Quantity money,Price money,Amount money,DateAdded datetime,\n"
307                 + "     TotalQuantity money,TotalAmount money,TotalWeight money, \n"
308                 + "     ShopMatCode varchar(50),ShopCcCode varchar(50),Brand varchar(50),isSelected int,\n"
309                 + "     PreSendMinutes int,PreSendMinutesDesc varchar(50), \n"
310                 + "     MaxPreSendMinutes int, MaxPreSendMinutesDesc varchar(50),MaxPreSendDateTime datetime , isStartupGroupBuying int,\n"
311                 + "     skuId1 int,skuName1 varchar(50),skuId2 int,skuName2 varchar(50),skuId3 int,skuName3 varchar(50),skuId4 int,skuName4 varchar(50),"
312                 + "     skuId5 int,skuName5 varchar(50),skuId6 int,skuName6 varchar(50),skuId7 int,skuName7 varchar(50),skuId8 int,skuName8 varchar(50),"
313                 + "     skuId9 int,skuName9 varchar(50),skuId10 int,skuName10 varchar(50)) ; \n"
314                 
315                 + " declare @skuId1 int = ?,@skuId2 int = ?,@skuId3 int = ?,@skuId4 int = ?, \n"
316                 + "   @skuId5 int = ?,@skuId6 int = ?,@skuId7 int = ?,@skuId8 int = ?,@skuId9 int = ?,@skuId10 int = ? \n"
317                 + " declare @skuName1 varchar(50),@skuName2 varchar(50),@skuName3 varchar(50),@skuName4 varchar(50),@skuName5 varchar(50), \n"
318                 + "   @skuName6 varchar(50),@skuName7 varchar(50),@skuName8 varchar(50),@skuName9 varchar(50),@skuName10 varchar(50) \n"
319
320                 + "  select top 1 @skuName1=a.skuName1,@skuName2=a.skuName2,@skuName3=a.skuName3,@skuName4=a.skuName4,@skuName5=a.skuName5,  \n"
321                 + "      @skuName6=a.skuName6,@skuName7=a.skuName7,@skuName8=a.skuName8,@skuName9=a.skuName9,@skuName10=a.skuName10 \n"
322                 + "  from t710175D a \n"
323                 + "  join t110503 b on a.MatCode = b.MatCode \n"
324                 + "  where a.MatCode = isnull(@MatCode,'') and isnull(a.skuId1,0) = isnull(@skuId1,0) and isnull(a.skuId2,0) = isnull(@skuId2,0) and isnull(a.skuId3,0) = isnull(@skuId3,0)  and isnull(a.skuId4,0) = isnull(@skuId4,0) and isnull(a.skuId5,0) = isnull(@skuId5,0) \n"
325                 + "  and isnull(a.skuId6,0) = isnull(@skuId6,0) and isnull(a.skuId7,0) = isnull(@skuId7,0) and isnull(a.skuId8,0) = isnull(@skuId8,0) and isnull(a.skuId9,0) = isnull(@skuId9,0) and isnull(a.skuId10,0) = isnull(@skuId10,0) \n"
326
327                 + " insert into @table(    CartId,UserCode,UserName,SessionId,CltCode,CltName,MatCode,MatName, \n"
328                 + "     Special,PhotoPath,BaseUomWeight,RecurringId,OptionJson,OptionText,\n"
329                 + "     Quantity,Price,Amount,DateAdded,ShopMatCode,ShopCcCode,Brand,isSelected,PreSendMinutes ,PreSendMinutesDesc ,isStartupGroupBuying, \n"
330                 + "     skuId1,skuName1,skuId2,skuName2,skuId3,skuName3,skuId4,skuName4,skuId5,skuName5,\n"
331                 + "     skuId6,skuName6,skuId7,skuName7,skuId8,skuName8,skuId9,skuName9,skuId10,skuName10)  \n"
332                 + " select null as CartId,null as UserCode,null as UserName,null as SessionId,null as CltCode,null as CltName,b.MatCode,b.MatName, \n"
333                 + "     b.Special,b.PhotoPath,b.BaseUomWeight,null as RecurringId,null as OptionJson,null as OptionText,\n "
334                 + "     @Quantity as Quantity,b.GroupBuyingPrice as Price,round(isnull(@Quantity,0) * isnull(b.GroupBuyingPrice,0),2) as Amount,\n"
335                 + "     getdate() as DateAdded,b.ShopMatCode,b.ShopCcCode,b.Brand,1 as isSelected, \n"
336                 + "     b.PreSendMinutes,dbo.f110503v2 (b.PreSendMinutes) as PreSendMinutesDesc , b.isStartupGroupBuying,\n"
337                 + "     @skuId1,@skuName1,@skuId2,@skuName2,@skuId3,@skuName3,@skuId4,@skuName4,@skuId5,@skuName5,\n"
338                 + "     @skuId6,@skuName6,@skuId7,@skuName7,@skuId8,@skuName8,@skuId9,@skuName9,@skuId10,@skuName10 \n"
339                 + " from t110503 b \n"
340                 + " join t110504 c on b.Brand = c.Brand \n"
341                 //+ " left join t710175D d on b.MatCode = d.MatCode \n"
342                 + " where b.MatCode = @MatCode\n"
343                 +"  and isnull(b.Status,0) = 1 \n"
344                 + " and isnull(c.Status,0) = 1 \n"
345                 + " and exists (select 1 from t710104 g join t110501 e on g.MatGroup = e.MatGroup  \n"
346                 + "             where b.DocCode = g.doccode \n"
347                 + "             and isnull(e.Status,0) = 1 ) \n"
348                 + " order by b.MatName asc ; \n "
349                 + " select @TotalQuantity = SUM(isnull(Quantity,0)),@TotalAmount = SUM(isnull(Amount,0)), \n"
350                 + "       @TotalWeight = sum(isnull(Quantity,0) * isnull(BaseUomWeight,0)), \n"
351                 + "    @MaxPreSendMinutes = max(PreSendMinutes) \n"
352                 + " from @table \n"
353                 + " update a set TotalQuantity= @TotalQuantity,TotalAmount = @TotalAmount,TotalWeight=@TotalWeight, \n"
354                 + "    MaxPreSendMinutes = @MaxPreSendMinutes,MaxPreSendMinutesDesc = dbo.f110503v2 (@MaxPreSendMinutes), \n"
355                 + "    MaxPreSendDateTime = dateadd(minute, @MaxPreSendMinutes, @MaxPreSendDateTime) \n"
356                 + " from @table a  \n"
357                 + " select a.CartId,a.UserCode,a.UserName,a.SessionId,a.CltCode,a.CltName,a.MatCode,a.MatName, \n"
358                 + "    a.Special,a.PhotoPath,a.BaseUomWeight,a.RecurringId,a.OptionJson,a.OptionText, \n"
359                 + "    a.Quantity,a.Price,a.Amount,a.DateAdded ,a.TotalQuantity,a.TotalAmount ,a.TotalWeight, \n"
360                 + "    a.ShopMatCode,a.ShopCcCode,a.Brand,a.isSelected, \n"
361                 + "    a.PreSendMinutes,a.PreSendMinutesDesc,a.MaxPreSendMinutes,a.MaxPreSendMinutesDesc,a.MaxPreSendDateTime,a.isStartupGroupBuying, \n"
362                 + "    a.skuId1,a.skuName1,a.skuId2,a.skuName2,a.skuId3,a.skuName3,a.skuId4,a.skuName4,a.skuId5,a.skuName5, \n"
363                 + "    a.skuId6,a.skuName6,a.skuId7,a.skuName7,a.skuId8,a.skuName8,a.skuId9,a.skuName9,a.skuId10,a.skuName10 \n"
364                 + " from @table  a \n"; 
365                         
366         List<Map<String,Object>> list = null ;
367         try {
368             list = this.jdbcTemplate.queryForList(sql,new Object[] {matCode,quantity,
369                     skuMatCodeEntity.getSkuId1(),skuMatCodeEntity.getSkuId2(),skuMatCodeEntity.getSkuId3(),skuMatCodeEntity.getSkuId4(),
370                     skuMatCodeEntity.getSkuId5(),skuMatCodeEntity.getSkuId6(),skuMatCodeEntity.getSkuId7(),skuMatCodeEntity.getSkuId8(),
371                     skuMatCodeEntity.getSkuId9(),skuMatCodeEntity.getSkuId10()}) ;
372         
373             List<CartEntity> cartList = new ArrayList<CartEntity>() ;
374             for (int i = 0 ; list != null && i < list.size();i++) {
375                 Map<String,Object> map = list.get(i) ;
376                 CartEntity cart = getCartEntity(map);
377                 cartList.add(cart);
378             }
379             return cartList;
380         }catch(DataAccessException e ) {
381             if (e instanceof EmptyResultDataAccessException){
382                 return null ;
383             }else {
384                 e.printStackTrace();
385                  throw e;
386             }
387         }catch(Exception e){
388             e.printStackTrace();
389             throw e;
390         }            
391                 
392     }
393     
394     @Override
395     public List<CartEntity> getCarts(String cartIds) {
396         if ( cartIds==null|| "".equals(cartIds)) return null ;
397         String sql = " set nocount on ; \n"
398                 + " declare @cartIds varchar(max) = ? \n;"
399                 + " declare @TotalQuantity money,@TotalAmount money,@TotalWeight money \n"
400                 + " declare @MaxPreSendDateTime datetime = getdate() ,@MaxPreSendMinutes int; \n"
401                 + " declare @table table(CartId int,UserCode varchar(20),UserName varchar(50), \n"
402                 + "     SessionId varchar(200),CltCode varchar(50),CltName varchar(200),\n"
403                 + "     MatCode varchar(50),MatName varchar(200), \n"
404                 + "     Special varchar(200),PhotoPath varchar(200),BaseUomWeight money,\n"
405                 + "     RecurringId int,OptionJson varchar(200),OptionText varchar(200),\n"
406                 + "     Quantity money,Price money,Amount money,DateAdded datetime,\n"
407                 + "     TotalQuantity money,TotalAmount money,TotalWeight money, \n"
408                 + "     ShopMatCode varchar(50),ShopCcCode varchar(50),Brand varchar(50),isSelected int,\n"
409                 + "     PreSendMinutes int,PreSendMinutesDesc varchar(50), \n"
410                 + "     MaxPreSendMinutes int, MaxPreSendMinutesDesc varchar(50),MaxPreSendDateTime datetime,isStartupGroupBuying int,\n"
411                 + "     skuId1 int,skuName1 varchar(50),skuId2 int,skuName2 varchar(50),skuId3 int,skuName3 varchar(50),skuId4 int,skuName4 varchar(50),"
412                 + "     skuId5 int,skuName5 varchar(50),skuId6 int,skuName6 varchar(50),skuId7 int,skuName7 varchar(50),skuId8 int,skuName8 varchar(50),"
413                 + "     skuId9 int,skuName9 varchar(50),skuId10 int,skuName10 varchar(50)) ; \n"
414                 + " insert into @table(    CartId,UserCode,UserName,SessionId,CltCode,CltName,MatCode,MatName, \n"
415                 + "     Special,PhotoPath,BaseUomWeight,RecurringId,OptionJson,OptionText,\n"
416                 + "     Quantity,Price,Amount,DateAdded,ShopMatCode,ShopCcCode,Brand,isSelected,PreSendMinutes ,PreSendMinutesDesc ,isStartupGroupBuying,\n"
417                 + "     skuId1,skuName1,skuId2,skuName2,skuId3,skuName3,skuId4,skuName4,skuId5,skuName5,\n"
418                 + "     skuId6,skuName6,skuId7,skuName7,skuId8,skuName8,skuId9,skuName9,skuId10,skuName10)  \n"
419                 + " select a.CartId,a.UserCode,a.UserName,a.SessionId,a.CltCode,a.CltName,a.MatCode,b.MatName, \n"
420                 + "     b.Special,b.PhotoPath,b.BaseUomWeight,a.RecurringId,a.OptionJson,a.OptionText,\n "
421                 + "     a.Quantity,a.Price,a.Amount,a.DateAdded,b.ShopMatCode,b.ShopCcCode,b.Brand,a.isSelected, \n"
422                 + "     b.PreSendMinutes,dbo.f110503v2 (b.PreSendMinutes) as PreSendMinutesDesc ,b.isStartupGroupBuying, \n"
423                 + "     a.skuId1,a.skuName1,a.skuId2,a.skuName2,a.skuId3,a.skuName3,a.skuId4,a.skuName4,a.skuId5,a.skuName5,\n"
424                 + "     a.skuId6,a.skuName6,a.skuId7,a.skuName7,a.skuId8,a.skuName8,a.skuId9,a.skuName9,a.skuId10,a.skuName10 \n"
425                 + " from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
426                 + " join t110504 c on b.Brand = c.Brand \n"
427                 //+ " left join t710175D d on a.MatCode = d.MatCode \n"
428                 + " where (isnull(@cartIds,'') <> '' and a.CartId in (select list from getinstr(@cartIds))) \n"
429                 +"  and isnull(b.Status,0) = 1 \n"
430                 + " and isnull(c.Status,0) = 1 \n"
431                 + " and exists (select 1 from t710104 g join t110501 e on g.MatGroup = e.MatGroup  \n"
432                 + "             where b.DocCode = g.doccode \n"
433                 + "             and isnull(e.Status,0) = 1 ) \n"
434                 + " order by b.MatName asc ; \n "
435                 + " select @TotalQuantity = SUM(isnull(Quantity,0)),@TotalAmount = SUM(isnull(Amount,0)), \n"
436                 + "       @TotalWeight = sum(isnull(Quantity,0) * isnull(BaseUomWeight,0)), \n"
437                 + "    @MaxPreSendMinutes = max(PreSendMinutes) \n"
438                 + " from @table \n"
439                 + " update a set TotalQuantity= @TotalQuantity,TotalAmount = @TotalAmount,TotalWeight=@TotalWeight, \n"
440                 + "    MaxPreSendMinutes = @MaxPreSendMinutes,MaxPreSendMinutesDesc = dbo.f110503v2 (@MaxPreSendMinutes), \n"
441                 + "    MaxPreSendDateTime = dateadd(minute, @MaxPreSendMinutes, @MaxPreSendDateTime) \n"
442                 + " from @table a  \n"
443                 + " select a.CartId,a.UserCode,a.UserName,a.SessionId,a.CltCode,a.CltName,a.MatCode,a.MatName, \n"
444                 + "    a.Special,a.PhotoPath,a.BaseUomWeight,a.RecurringId,a.OptionJson,a.OptionText, \n"
445                 + "    a.Quantity,a.Price,a.Amount,a.DateAdded ,a.TotalQuantity,a.TotalAmount ,a.TotalWeight, \n"
446                 + "    a.ShopMatCode,a.ShopCcCode,a.Brand,a.isSelected, \n"
447                 + "    a.PreSendMinutes,a.PreSendMinutesDesc,a.MaxPreSendMinutes,a.MaxPreSendMinutesDesc,a.MaxPreSendDateTime ,a.isStartupGroupBuying,\n"
448                 + "    a.skuId1,a.skuName1,a.skuId2,a.skuName2,a.skuId3,a.skuName3,a.skuId4,a.skuName4,a.skuId5,a.skuName5, \n"
449                 + "    a.skuId6,a.skuName6,a.skuId7,a.skuName7,a.skuId8,a.skuName8,a.skuId9,a.skuName9,a.skuId10,a.skuName10 \n"
450                 + " from @table  a \n"; 
451                         
452         List<Map<String,Object>> list = null ;
453         try {
454             list = this.jdbcTemplate.queryForList(sql,cartIds) ;
455         
456             List<CartEntity> cartList = new ArrayList<CartEntity>() ;
457             for (int i = 0 ; list != null && i < list.size();i++) {
458                 Map<String,Object> map = list.get(i) ;
459                 CartEntity cart = getCartEntity(map);
460                 cartList.add(cart);
461             }
462             return cartList;
463         }catch(DataAccessException e ) {
464             if (e instanceof EmptyResultDataAccessException){
465                 return null ;
466             }else {
467                 e.printStackTrace();
468                  throw e;
469             }
470         }catch(Exception e){
471             e.printStackTrace();
472             throw e;
473         }            
474
475         
476     }
477     
478     @Override
479     public List<CartEntity> getCartsByPicture(String cartIds,String cltCode) {
480         String sql = " set nocount on ; \n"
481                 + " declare @cartIds varchar(max) = ? , @CltCode varchar(50) = ? \n;"
482                 + " declare @TotalQuantity money,@TotalAmount money; \n"
483                 + " declare @table table(CartId int,UserCode varchar(20),UserName varchar(50), \n"
484                 + "     SessionId varchar(200),CltCode varchar(50),CltName varchar(200),\n"
485                 + "     MatCode varchar(50),MatName varchar(200), \n"
486                 + "     Special varchar(200),PhotoPath varchar(200),BaseUomWeight money,\n"
487                 + "     RecurringId int,OptionJson varchar(200),OptionText varchar(200),\n"
488                 + "     Quantity money,Price money,Amount money,DateAdded datetime,\n"
489                 + "     TotalQuantity money,TotalAmount money,TotalWeight money, \n"
490                 + "     ShopMatCode varchar(50),ShopCcCode varchar(50),Mininum bigint) ; \n"
491                 + " insert into @table(    CartId,CltCode,CltName,MatCode,MatName, \n"
492                 + "     Special,PhotoPath,BaseUomWeight,\n"
493                 + "     Quantity,Price,Amount,DateAdded,ShopMatCode,ShopCcCode,Mininum  )  \n"
494                 + " select a.CartId,a.CltCode,a.CltName,a.MatCode,b.MatName, \n"
495                 + "     b.Special,b.PhotoPath,b.BaseUomWeight,\n "
496                 + "     a.Quantity,a.Price,a.Amount,a.DateAdded,b.ShopMatCode,b.ShopCcCode,b.Mininum  \n"
497                 + " from t710401 a join t110503 b on a.MatCode = b.MatCode \n"
498                 + " join t110504 c on b.Brand = c.Brand \n"
499                 + " join t110501 e on b.MatGroup = e.MatGroup \n"
500                 + " where (isnull(@cartIds,'') <> '' and a.CartId in (select list from getinstr(@cartIds))) \n"
501                 +"  and isnull(b.Status,0) = 1 \n"
502                 + " and isnull(c.Status,0) = 1 \n"
503                 + " and isnull(e.Status,0) = 1 \n"
504                 + " and isnull(a.CltCode,'') = @CltCode \n"
505                 + " order by b.MatName asc ; \n "
506                 + " select @TotalQuantity = SUM(isnull(Quantity,0)),@TotalAmount = SUM(isnull(Amount,0)) \n"
507                 + " from @table \n"
508                 + " update a set TotalQuantity= @TotalQuantity,TotalAmount = @TotalAmount \n"
509                 + " from @table a  \n"
510                 + " select CartId,UserCode,UserName,SessionId,CltCode,CltName,MatCode,MatName, \n"
511                 + "    Special,PhotoPath,BaseUomWeight,RecurringId,OptionJson,OptionText, \n"
512                 + "    Quantity,Price,Amount,DateAdded ,TotalQuantity,TotalAmount ,TotalWeight, \n"
513                 + "    ShopMatCode,ShopCcCode,Mininum \n"
514                 + " from @table \n"; 
515                         
516         List<Map<String,Object>> list = null ;
517         try {
518             list = this.jdbcTemplate.queryForList(sql,cartIds ,cltCode) ;
519         
520             List<CartEntity> cartList = new ArrayList<CartEntity>() ;
521             for (int i = 0 ; list != null && i < list.size();i++) {
522                 Map<String,Object> map = list.get(i) ;
523                 CartEntity cart = getCartEntity(map);
524                 cartList.add(cart);
525             }
526             return cartList;
527         }catch(DataAccessException e ) {
528             if (e instanceof EmptyResultDataAccessException){
529                 return null ;
530             }else {
531                 e.printStackTrace();
532                  throw e;
533             }
534         }catch(Exception e){
535             e.printStackTrace();
536             throw e;
537         }            
538     }
539     
540     @Override
541     public Integer saveSelectedCartIds(String userCode, String sessionId,String openId,String cltCode,String shopCcCode,String selectedCartIds) {
abc52b 542         //if (selectedCartIds == null || "".equals(selectedCartIds)) return  null ;   //这句话必须注释掉,因为 selectedCartIds 值为空值时,表示去掉全选的意思,Modified by Johns Wang,2021-11-09
a6a76f 543         String sql = " set nocount on ; \n"
F 544                 + " declare @UserCode varchar(20) = ? ,@SessionId varchar(200) = ? ; \n"
545                 + " declare @OpenId varchar(200) = ?, @CltCode varchar(50) = ? \n;"
546                 + " declare @ShopCcCode varchar(50) = ? \n"
547                 + " declare @SelectedCartIds varchar(max) = ? ,@myRowCount int \n"
548                 + " update a set isSelected = 0 \n"
549                 + " from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
550                 + "    where isnull(a.UserCode,'') <> '' and isnull(a.UserCode,'') = isnull(@UserCode,'') \n"
551                 + " and (isnull(@ShopCcCode,'') = '' or b.ShopCcCode = @ShopCcCode ) \n"
552                 + " update a set isSelected = 0 \n"
553                 + " from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
554                 + "    where isnull(a.SessionId,'') <> '' and isnull(a.SessionId,'') = isnull(@SessionId,'') \n"
555                 + " and (isnull(@ShopCcCode,'') = '' or b.ShopCcCode = @ShopCcCode ) \n"
556                 + " update a set isSelected = 0 \n"
557                 + " from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
558                 + "    where isnull(a.CltCode,'') <> '' and isnull(a.CltCode,'') = isnull(@CltCode,'') \n"
559                 + " and (isnull(@ShopCcCode,'') = '' or b.ShopCcCode = @ShopCcCode ) \n"
560                 + " update a set isSelected = 0 \n"
561                 + " from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
562                 + "    where isnull(a.OpenId,'') <> '' and isnull(a.OpenId,'') = isnull(@OpenId,'') \n"
563                 + " and (isnull(@ShopCcCode,'') = '' or b.ShopCcCode = @ShopCcCode ) \n"
564                 + " if isnull(@SelectedCartIds,'') <> '' \n"
565                 + " begin \n"
566                 + "    update a set isSelected = 1 \n"
567                 + "    from t710205 a  \n"
568                 + "    where a.CartId in (select list from getinstr(@SelectedCartIds)) \n"
569                 + "    select @myRowCount = @@rowcount \n"
570                 + " end \n"
571                 + " select @myRowCount \n";
572         try {
0cbf06 573             return this.jdbcTemplate.queryForObject(sql, Integer.class,new Object[] {userCode,sessionId,openId,cltCode,shopCcCode,selectedCartIds}) ;
a6a76f 574         } catch(DataAccessException e ) {
F 575             if (e instanceof EmptyResultDataAccessException){
576                 return null ;
577             }else {
578                 e.printStackTrace();
579                  throw e;
580             }
581         }catch(Exception e){
582             e.printStackTrace();
583             throw e;
584         }    
585     }
586     
587     @Override
588     public Integer addSelectedCartId(Integer cartId,boolean isSelected) {
589         String sql = " set nocount on ; \n"
590                 + " declare @CartId int = ? , @isSelected int = ? \n"
591                 + " update a set isSelected = @isSelected \n"
592                 + " from t710205 a where CartId = @CartId \n"
593                 + " select @@rowcount \n";
594         try {
0cbf06 595             return this.jdbcTemplate.queryForObject(sql, Integer.class,new Object[] {cartId,isSelected}) ;
a6a76f 596         } catch(DataAccessException e ) {
F 597             if (e instanceof EmptyResultDataAccessException){
598                 return null ;
599             }else {
600                 e.printStackTrace();
601                  throw e;
602             }
603         }catch(Exception e){
604             e.printStackTrace();
605             throw e;
606         }    
607     }
608     
609     /**
610      * 此过程是生成订单前显示的购物车列表,与 p120230v3 过程中获取购物车的SQL语句必须一致,否则可能导致页面显示的记录条数与实现生成的记录条数不一致
611      * @author JohnsWang , 2016-07-22
612      */
613     @Override
614     public List<CartEntity> getCartList(String userCode, String sessionId,String openId,String cltCode,String shopCcCode) {
615         String sql = " set nocount on ; \n"
616                 + " declare @MaxPreSendDateTime datetime = getdate() ,@MaxPreSendMinutes int; \n"
617                 + " declare @UserCode varchar(20) = ? ,@SessionId varchar(200) = ? ; \n"
618                 + " declare @OpenId varchar(200) = ?, @CltCode varchar(50) = ? \n;"
619                 + " declare @ShopCcCode varchar(50) = ? \n"
620                 + " declare @TotalQuantity money,@SelectedTotalQuantity money,@TotalAmount money ; \n"
621                 + " declare @SelectedTotalAmount money,@TotalWeight money,@SelectedTotalWeight money ; \n"
52123d 622                 
a6a76f 623                 + " declare @table table(CartId int Primary Key,UserCode varchar(20),UserName varchar(50), \n"
F 624                 + "     SessionId varchar(200),CltCode varchar(50),CltName varchar(200),\n"
625                 + "     MatCode varchar(50),MatName varchar(200), \n"
626                 + "     Special varchar(200),PhotoPath varchar(200),PhotoPathUrl varchar(200),BaseUomWeight money,\n"
627                 + "     RecurringId int,OptionJson varchar(200),OptionText varchar(200),\n"
628                 + "     Quantity money,Price money,Amount money,DateAdded datetime,\n"
629                 + "     TotalQuantity money,SelectedTotalQuantity money,TotalAmount money,SelectedTotalAmount money,\n"
630                 + "     TotalWeight money,SelectedTotalWeight money,\n"
631                 + "     ShopMatCode varchar(50),ShopCcCode varchar(50),Mininum bigint,\n"
632                 + "     MatName2 varchar(80),MatName3 varchar(80),MatName4 varchar(80),Brand varchar(50),isSelected int ,\n"
633                 + "     PreSendMinutes int,PreSendMinutesDesc varchar(50), \n" 
634                 + "        MaxPreSendMinutes int, MaxPreSendMinutesDesc varchar(50),MaxPreSendDateTime datetime, isStartupGroupBuying int,\n"
635                 + "     skuId1 int,skuName1 varchar(50),skuId2 int,skuName2 varchar(50),skuId3 int,skuName3 varchar(50),skuId4 int,skuName4 varchar(50),"
636                 + "     skuId5 int,skuName5 varchar(50),skuId6 int,skuName6 varchar(50),skuId7 int,skuName7 varchar(50),skuId8 int,skuName8 varchar(50),"
52123d 637                 + "     skuId9 int,skuName9 varchar(50),skuId10 int,skuName10 varchar(50),isRestrictQuantity int,RestrictQuantity money, \n"
d223ec 638                 + "     CartRowCountForMatCode int,CartQuantitySumForMatCode money, \n"
J 639                 + "     index index1 (matcode) ) ; \n"
a6a76f 640                 
F 641                 + " insert into @table(    CartId,UserCode,UserName,SessionId,CltCode,CltName,MatCode,MatName, \n"
642                 + "      Special,PhotoPath,PhotoPathUrl,BaseUomWeight,RecurringId,OptionJson,OptionText,\n"
643                 + "         Quantity,Price,Amount,DateAdded,ShopMatCode,ShopCcCode ,Mininum,\n"
644                 + "      MatName2 ,MatName3 ,MatName4 ,Brand ,isSelected,PreSendMinutes,PreSendMinutesDesc,isStartupGroupBuying, \n"
419647 645                 + "      skuId1,skuName1,skuId2,skuName2,skuId3,skuName3,skuId4,skuName4,skuId5,skuName5,\n"
J 646                 + "      skuId6,skuName6,skuId7,skuName7,skuId8,skuName8,skuId9,skuName9,skuId10,skuName10, \n"
647                 + "      isRestrictQuantity,RestrictQuantity)  \n"
a6a76f 648                 + "     select a.CartId,a.UserCode,a.UserName,a.SessionId,a.CltCode,a.CltName,a.MatCode,b.MatName, \n"
F 649                 + "         b.Special,b.PhotoPath,b.PhotoPathUrl,b.BaseUomWeight,a.RecurringId,a.OptionJson,a.OptionText,\n"
650                 + "         a.Quantity,a.Price,a.Amount,a.DateAdded,b.ShopMatCode,b.ShopCcCode,b.Mininum , \n"
651                 + "      b.MatName2 ,b.MatName3 ,b.MatName4 ,b.Brand, a.isSelected, \n"
652                 + "      b.PreSendMinutes,dbo.f110503v2 (b.PreSendMinutes) as PreSendMinutesDesc,b.isStartupGroupBuying, \n"
653                 + "      a.skuId1,a.skuName1,a.skuId2,a.skuName2,a.skuId3,a.skuName3,a.skuId4,a.skuName4,a.skuId5,a.skuName5,\n"
419647 654                 + "      a.skuId6,a.skuName6,a.skuId7,a.skuName7,a.skuId8,a.skuName8,a.skuId9,a.skuName9,a.skuId10,a.skuName10, \n"
J 655                 + "      b.isRestrictQuantity ,case isnull(b.isRestrictQuantity,0) when 0 then 0 when 1 then b.Quantity when 2 then b.StockDigitForShoppingSaleable else 0 end as RestrictQuantity \n"
a6a76f 656                 + "     from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
F 657                 + "  join t110504 c on b.Brand = c.Brand \n"
658                 //+ "  left join t710175D d on a.MatCode = d.MatCode \n"
659                 + "     where isnull(a.UserCode,'') <> '' and isnull(a.UserCode,'') = isnull(@UserCode,'') \n"
660                 +"   and isnull(b.Status,0) = 1 \n"
661                 + "  and isnull(c.Status,0) = 1 \n"
662                 + "  and isnull(a.MatGroupStatus,0) = 1 \n"
663 //                + "  and exists (select 1 from t710104 t join t110501 e on t.MatGroup = e.MatGroup  \n"
664 //                + "              where b.DocCode = t.doccode and isnull(e.Status,0) = 1 ) \n"
665 //                + "              and (isnull(@ShopCcCode,'') = '' or b.ShopCcCode = @ShopCcCode ) \n"
666                      
667                 + "     insert into @table(CartId,UserCode,UserName,SessionId,CltCode,CltName,MatCode,MatName, \n"
668                 + "         Special,PhotoPath,PhotoPathUrl,BaseUomWeight,RecurringId,OptionJson,OptionText,\n"
669                 + "         Quantity,Price,Amount,DateAdded ,ShopMatCode,ShopCcCode,Mininum, \n"
670                 + "      MatName2 ,MatName3 ,MatName4 ,Brand ,isSelected,PreSendMinutes,PreSendMinutesDesc, isStartupGroupBuying,\n"
419647 671                 + "      skuId1,skuName1,skuId2,skuName2,skuId3,skuName3,skuId4,skuName4,skuId5,skuName5,\n"
J 672                 + "      skuId6,skuName6,skuId7,skuName7,skuId8,skuName8,skuId9,skuName9,skuId10,skuName10, \n"
673                 + "      isRestrictQuantity ,RestrictQuantity)  \n"
a6a76f 674                 + "      select a.CartId,a.UserCode,a.UserName,a.SessionId,a.CltCode,a.CltName,a.MatCode,b.MatName, \n"
F 675                 + "         b.Special,b.PhotoPath,b.PhotoPathUrl,b.BaseUomWeight,a.RecurringId,a.OptionJson,a.OptionText,\n"
676                 + "         a.Quantity,a.Price,a.Amount,a.DateAdded,b.ShopMatCode,b.ShopCcCode,b.Mininum ,\n"
677                 + "      b.MatName2 ,b.MatName3 ,b.MatName4 ,b.Brand ,a.isSelected, \n"
678                 + "      b.PreSendMinutes,dbo.f110503v2 (b.PreSendMinutes) as PreSendMinutesDesc,b.isStartupGroupBuying, \n"
679                 + "      a.skuId1,a.skuName1,a.skuId2,a.skuName2,a.skuId3,a.skuName3,a.skuId4,a.skuName4,a.skuId5,a.skuName5,\n"
419647 680                 + "      a.skuId6,a.skuName6,a.skuId7,a.skuName7,a.skuId8,a.skuName8,a.skuId9,a.skuName9,a.skuId10,a.skuName10 ,\n"
J 681                 + "      b.isRestrictQuantity ,case isnull(b.isRestrictQuantity,0) when 0 then 0 when 1 then b.Quantity when 2 then b.StockDigitForShoppingSaleable else 0 end as RestrictQuantity \n"
a6a76f 682                 + "     from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
F 683                 + "  join t110504 c on b.Brand = c.Brand \n"
684                 //+ "  left join t710175D d on a.MatCode = d.MatCode \n"
685                 + "     where isnull(a.SessionId,'') <> '' and isnull(a.SessionId,'') = isnull(@SessionId,'')\n"
686                 + "     and not exists(select 1 from @table c where a.CartId = c.CartId)\n"
687                 +"   and isnull(b.Status,0) = 1 \n"
688                 + "  and isnull(c.Status,0) = 1 \n"
689                 + "  and isnull(a.MatGroupStatus,0) = 1 \n"
690 //                + "  and exists (select 1 from t710104 t join t110501 e on t.MatGroup = e.MatGroup  \n"
691 //                + "              where b.DocCode = t.doccode and isnull(e.Status,0) = 1 ) \n"
692 //                + "              and (isnull(@ShopCcCode,'') = '' or b.ShopCcCode = @ShopCcCode ) \n"
693                      
694                 + "      insert into @table(CartId,UserCode,UserName,SessionId,CltCode,CltName,MatCode,MatName, \n"
695                 + "         Special,PhotoPath,PhotoPathUrl,BaseUomWeight,RecurringId,OptionJson,OptionText,\n"
696                 + "         Quantity,Price,Amount,DateAdded ,ShopMatCode,ShopCcCode,Mininum ,\n"
697                 + "      MatName2 ,MatName3 ,MatName4 ,Brand ,isSelected,PreSendMinutes,PreSendMinutesDesc, isStartupGroupBuying, \n"
419647 698                 + "      skuId1,skuName1,skuId2,skuName2,skuId3,skuName3,skuId4,skuName4,skuId5,skuName5,\n"
J 699                 + "      skuId6,skuName6,skuId7,skuName7,skuId8,skuName8,skuId9,skuName9,skuId10,skuName10 ,\n"
700                 + "      isRestrictQuantity ,RestrictQuantity)  \n"
a6a76f 701                 + "      select a.CartId,a.UserCode,a.UserName,a.SessionId,a.CltCode,a.CltName,a.MatCode,b.MatName, \n"
F 702                 + "         b.Special,b.PhotoPath,b.PhotoPathUrl,b.BaseUomWeight,a.RecurringId,a.OptionJson,a.OptionText,\n"
703                 + "         a.Quantity,a.Price,a.Amount,a.DateAdded,b.ShopMatCode,b.ShopCcCode ,b.Mininum, \n"
704                 + "      b.MatName2 ,b.MatName3 ,b.MatName4 ,b.Brand ,a.isSelected, \n"
705                 + "      b.PreSendMinutes,dbo.f110503v2 (b.PreSendMinutes) as PreSendMinutesDesc ,b.isStartupGroupBuying,\n"
706                 + "      a.skuId1,a.skuName1,a.skuId2,a.skuName2,a.skuId3,a.skuName3,a.skuId4,a.skuName4,a.skuId5,a.skuName5,\n"
419647 707                 + "      a.skuId6,a.skuName6,a.skuId7,a.skuName7,a.skuId8,a.skuName8,a.skuId9,a.skuName9,a.skuId10,a.skuName10, \n"
J 708                 + "      b.isRestrictQuantity ,case isnull(b.isRestrictQuantity,0) when 0 then 0 when 1 then b.Quantity when 2 then b.StockDigitForShoppingSaleable else 0 end as RestrictQuantity \n"
a6a76f 709                 + "     from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
F 710                 + "  join t110504 c on b.Brand = c.Brand \n"
711 //                + "  left join t710175D d on a.MatCode = d.MatCode \n"
712                 + "     where isnull(a.CltCode,'') <> '' and isnull(a.CltCode,'') = isnull(@CltCode,'') \n"
713                 + "     and not exists(select 1 from @table c where a.CartId = c.CartId)\n"
714                 +"   and isnull(b.Status,0) = 1 \n"
715                 + "  and isnull(c.Status,0) = 1 \n"
716                 + "  and isnull(a.MatGroupStatus,0) = 1 \n"
717 //                + "  and exists (select 1 from t710104 t join t110501 e on t.MatGroup = e.MatGroup  \n"
718 //                + "              where b.DocCode = t.doccode and isnull(e.Status,0) = 1 ) \n"
719 //                + "              and (isnull(@ShopCcCode,'') = '' or b.ShopCcCode = @ShopCcCode ) \n"
720                      
721                 + "      insert into @table(CartId,UserCode,UserName,SessionId,CltCode,CltName,MatCode,MatName, \n"
722                 + "         Special,PhotoPath,PhotoPathUrl,BaseUomWeight,RecurringId,OptionJson,OptionText,\n"
723                 + "         Quantity,Price,Amount,DateAdded ,ShopMatCode,ShopCcCode,Mininum ,\n"
724                 + "      MatName2 ,MatName3 ,MatName4 ,Brand ,isSelected,PreSendMinutes,PreSendMinutesDesc,isStartupGroupBuying, \n"
419647 725                 + "      skuId1,skuName1,skuId2,skuName2,skuId3,skuName3,skuId4,skuName4,skuId5,skuName5,\n"
J 726                 + "      skuId6,skuName6,skuId7,skuName7,skuId8,skuName8,skuId9,skuName9,skuId10,skuName10 ,\n"
727                 + "      isRestrictQuantity ,RestrictQuantity)  \n"
a6a76f 728                 + "      select a.CartId,a.UserCode,a.UserName,a.SessionId,a.CltCode,a.CltName,a.MatCode,b.MatName, \n"
F 729                 + "         b.Special,b.PhotoPath,b.PhotoPathUrl,b.BaseUomWeight,a.RecurringId,a.OptionJson,a.OptionText,\n"
730                 + "         a.Quantity,a.Price,a.Amount,a.DateAdded,b.ShopMatCode,b.ShopCcCode,b.Mininum , \n"
731                 + "      b.MatName2 ,b.MatName3 ,b.MatName4 ,b.Brand ,a.isSelected, \n"
732                 + "      b.PreSendMinutes,dbo.f110503v2 (b.PreSendMinutes) as PreSendMinutesDesc,b.isStartupGroupBuying, \n"
733                 + "      a.skuId1,a.skuName1,a.skuId2,a.skuName2,a.skuId3,a.skuName3,a.skuId4,a.skuName4,a.skuId5,a.skuName5,\n"
419647 734                 + "      a.skuId6,a.skuName6,a.skuId7,a.skuName7,a.skuId8,a.skuName8,a.skuId9,a.skuName9,a.skuId10,a.skuName10, \n"
J 735                 + "      b.isRestrictQuantity ,case isnull(b.isRestrictQuantity,0) when 0 then 0 when 1 then b.Quantity when 2 then b.StockDigitForShoppingSaleable else 0 end as RestrictQuantity \n"
a6a76f 736                 + "     from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
F 737                 + "  join t110504 c on b.Brand = c.Brand \n"
738 //                + "  left join t710175D d on a.MatCode = d.MatCode \n"
739                 + "     where isnull(a.OpenId,'') <> '' and isnull(a.OpenId,'') = isnull(@OpenId,'') \n"
740                 + "     and not exists(select 1 from @table c where a.CartId = c.CartId)\n"
741                 +"   and isnull(b.Status,0) = 1 \n"
742                 + "  and isnull(c.Status,0) = 1 \n"
743                 + "  and isnull(a.MatGroupStatus,0) = 1 \n"
744 //                + "  and exists (select 1 from t710104 t join t110501 e on t.MatGroup = e.MatGroup  \n"
745 //                + "              where b.DocCode = t.doccode and isnull(e.Status,0) = 1 ) \n"
746 //                + "              and (isnull(@ShopCcCode,'') = '' or b.ShopCcCode = @ShopCcCode ) \n"            
747  
748                 + " select @TotalQuantity = SUM(isnull(Quantity,0)), \n"
749                 + "    @SelectedTotalQuantity = SUM(case when isnull(isSelected,0) = 1 then isnull(Quantity,0) else 0 end),\n"
750                 + "    @TotalAmount = SUM(isnull(Amount,0)), \n"
751                 + "    @SelectedTotalAmount = SUM(case when isnull(isSelected,0) = 1 then isnull(Amount,0) else 0 end), \n"
752                 + "       @TotalWeight = sum(isnull(Quantity,0) * isnull(BaseUomWeight,0)), \n"
753                 + "    @SelectedTotalWeight = SUM(case when isnull(isSelected,0) = 1 then isnull(Quantity,0) * isnull(BaseUomWeight,0) else 0 end), \n"
754                 + "    @MaxPreSendMinutes = max(PreSendMinutes) \n"
755                 + " from @table \n"
52123d 756                 
J 757                 //更新所有商品总数量
a6a76f 758                 + " update a set TotalQuantity= @TotalQuantity,SelectedTotalQuantity= @SelectedTotalQuantity,\n"
F 759                 + "    TotalAmount = @TotalAmount,SelectedTotalAmount = @SelectedTotalAmount,\n"
760                 + "    TotalWeight=@TotalWeight,SelectedTotalWeight=@SelectedTotalWeight, \n"
761                 + "    MaxPreSendMinutes = @MaxPreSendMinutes,MaxPreSendMinutesDesc = dbo.f110503v2 (@MaxPreSendMinutes), \n"
762                 + "    MaxPreSendDateTime = dateadd(minute, @MaxPreSendMinutes, @MaxPreSendDateTime) \n"
763                 + " from @table a  \n"
52123d 764                 
J 765                 //更新每个商品条数和每个商品总数量
766                 + " update a set CartRowCountForMatCode = b.CartRowCount,CartQuantitySumForMatCode = b.CartQuantitySum \n"
767                 + " from @table a \n"
768                 + " join (select MatCode,count(MatCode) as CartRowCount,sum(isnull(Quantity,0)) as CartQuantitySum \n"
769                 + "      from @table group by MatCode ) b on a.MatCode = b.MatCode \n"
770                 
a6a76f 771                 + " select a.CartId,a.UserCode,a.UserName,a.SessionId,a.CltCode,a.CltName,a.MatCode,a.MatName, \n"
F 772                 + "    a.Special,a.PhotoPath,a.PhotoPathUrl,a.BaseUomWeight,a.RecurringId,a.OptionJson,a.OptionText, \n"
773                 + "    a.Quantity,a.Price,a.Amount,a.DateAdded ,a.TotalQuantity,a.SelectedTotalQuantity,\n"
774                 + "    a.TotalAmount,a.SelectedTotalAmount ,a.TotalWeight,a.SelectedTotalWeight,\n"
775                 + "    a.ShopMatCode,a.ShopCcCode,a.Mininum ,a.MatName2 ,a.MatName3 ,a.MatName4 ,a.Brand ,a.isSelected, \n"
776                 + "    a.PreSendMinutes,a.PreSendMinutesDesc,a.MaxPreSendMinutes,a.MaxPreSendMinutesDesc,a.MaxPreSendDateTime ,a.isStartupGroupBuying, \n"
777                 + "    a.skuId1,a.skuName1,a.skuId2,a.skuName2,a.skuId3,a.skuName3,a.skuId4,a.skuName4,a.skuId5,a.skuName5, \n"
419647 778                 + "    a.skuId6,a.skuName6,a.skuId7,a.skuName7,a.skuId8,a.skuName8,a.skuId9,a.skuName9,a.skuId10,a.skuName10, \n"
52123d 779                 + "    a.isRestrictQuantity ,a.RestrictQuantity,a.CartRowCountForMatCode,a.CartQuantitySumForMatCode \n"
a6a76f 780                 + " from @table a \n"
F 781                 + " order by a.MatName asc ; "; 
782                         
783         List<Map<String,Object>> list = null ;
784         try {
d223ec 785             //System.out.println(getClass() + "  sql: " + sql ) ;
a6a76f 786             list = this.jdbcTemplate.queryForList(sql,userCode,sessionId,openId,cltCode,shopCcCode) ;
F 787         
788             List<CartEntity> cartList = new ArrayList<CartEntity>() ;
789             for (int i = 0 ; list != null && i < list.size();i++) {
790                 Map<String,Object> map = list.get(i) ;
791                 CartEntity cart = getCartEntity(map);
792                 cartList.add(cart);
793             }
794             return cartList;
795         }catch(DataAccessException e ) {
796             if (e instanceof EmptyResultDataAccessException){
797                 return null ;
798             }else {
799                 e.printStackTrace();
800                  throw e;
801             }
802         }catch(Exception e){
803             e.printStackTrace();
804             throw e;
805         }            
806
807         
808     }
809     
810     
811     @Override
812     public List<CartEntity> getCartsByPicture(String cltCode) {
813         String sql = " set nocount on ; \n"
814                 
815                 + " declare @CltCode varchar(50) = ? \n;"
816                 + " declare @TotalQuantity money,@TotalAmount money,@TotalWeight money ; \n"
817                 + " declare @table table(CartId int,CltCode varchar(50),CltName varchar(200),\n"
818                 + "     MatCode varchar(50),MatName varchar(200), \n"
819                 + "     Special varchar(200),PhotoPath varchar(200),\n"
820                 + "     Quantity money,Price money,Amount money,DateAdded datetime,\n"
821                 + "     TotalQuantity money,TotalAmount money,\n"
822                 + "     ShopMatCode varchar(50),ShopCcCode varchar(50),ShopCcName varchar(50)) ; \n"
823                      
824                 + "      insert into @table(    CartId,CltCode,CltName,MatCode,MatName, \n"
825                 + "         Special,PhotoPath,\n"
826                 + "         Quantity,Price,Amount,DateAdded ,ShopMatCode,ShopCcCode,ShopCcName )  \n"
827                 + "      select a.CartId,a.CltCode,a.CltName,a.MatCode,b.MatName, \n"
828                 + "         b.Special,b.PhotoPath,\n"
829                 + "         a.Quantity,a.Price,a.Amount,a.DateAdded,b.ShopMatCode,b.ShopCcCode ,d.ccname as ShopCcName \n"
830                 + "     from t710401 a join t110503 b on a.MatCode = b.MatCode \n"
831                 + "  join t110504 c on b.Brand = c.Brand \n"
832                 + "  join t110601 d on b.ShopCcCode = d.CcCode \n"
833                 //+ "  join t110501 e on b.MatGroup = e.MatGroup \n"
834                 + "     where isnull(a.CltCode,'') <> '' and isnull(a.CltCode,'') = isnull(@CltCode,'') \n"
835                 + "     and not exists(select 1 from @table c where a.CartId = c.CartId)\n"
836                 +"   and isnull(b.Status,0) = 1 \n"
837                 + "  and isnull(c.Status,0) = 1 \n"
838                 + "  and exists (select 1 from t710104 t join t110501 e on t.MatGroup = e.MatGroup  \n"
839                 + "              where b.DocCode = t.doccode and isnull(e.Status,0) = 1 ) \n"
840                      
841  
842                 + " select @TotalQuantity = SUM(isnull(Quantity,0)),@TotalAmount = SUM(isnull(Amount,0)) \n"
843                 + " from @table \n"
844                 + " update a set TotalQuantity= @TotalQuantity,TotalAmount = @TotalAmount \n"
845                 + " from @table a  \n"
846                 + " select CartId,CltCode,CltName,MatCode,MatName, \n"
847                 + "    Special,PhotoPath, \n"
848                 + "    Quantity,Price,Amount,DateAdded ,TotalQuantity,TotalAmount ,\n"
849                 + "    ShopMatCode,ShopCcCode,ShopCcName \n"
850                 + " from @table a \n"
851                 + " order by a.MatName asc ; "; 
852                         
853         List<Map<String,Object>> list = null ;
854         try {
855             list = this.jdbcTemplate.queryForList(sql,cltCode) ;
856         
857             List<CartEntity> cartList = new ArrayList<CartEntity>() ;
858             for (int i = 0 ; list != null && i < list.size();i++) {
859                 Map<String,Object> map = list.get(i) ;
860                 CartEntity cart = getCartEntity(map);
861                 cartList.add(cart);
862             }
863             return cartList;
864         }catch(DataAccessException e ) {
865             if (e instanceof EmptyResultDataAccessException){
866                 return null ;
867             }else {
868                 e.printStackTrace();
869                  throw e;
870             }
871         }catch(Exception e){
872             e.printStackTrace();
873             throw e;
874         }            
875
876         
877     }
878
879     @Override
880     public CartEntity getCartEntity(Map<String,Object> map) {
881         CartEntity cart = new CartEntity() ;
882         if (map != null && map.size() > 0 ) {
883             cart.setCartId(map.get("CartId") == null ? null: (Integer)map.get("CartId"));
884             cart.setUserCode(map.get("UserCode") == null ? "": (String)map.get("UserCode"));
885             cart.setUserName(map.get("UserName") == null ? "": (String)map.get("UserName"));
886             cart.setSessionId(map.get("SessionId") == null ? "": (String)map.get("SessionId"));
887             cart.setCltCode(map.get("CltCode") == null ? "": (String)map.get("CltCode"));
888             cart.setCltName(map.get("CltName") == null ? "": (String)map.get("CltName"));
889             cart.setMatCode(map.get("MatCode") == null ? "": (String)map.get("MatCode"));
890             cart.setMatName(map.get("MatName") == null ? "": (String)map.get("MatName"));
891             cart.setSpecial(map.get("Special") == null ? "": (String)map.get("Special"));
892             cart.setRecurringId(map.get("RecurringId") == null ?null: (Integer)map.get("RecurringId"));
893             cart.setOptionJson(map.get("OptionJson") == null ? "": (String)map.get("OptionJson"));
894             cart.setOptionText(map.get("OptionText") == null ? "": (String)map.get("OptionText"));
895             cart.setQuantity(map.get("Quantity") == null ? 0: Double.parseDouble(map.get("Quantity").toString()));
896             cart.setPrice(map.get("Price") == null ? 0: Double.parseDouble(map.get("Price").toString()));
897             cart.setAmount(map.get("Amount") == null ? 0: Double.parseDouble(map.get("Amount").toString()));
898             cart.setWeight(map.get("BaseUomWeight") == null ? 0: Double.parseDouble(map.get("BaseUomWeight").toString()));
899             cart.setDateAdded(map.get("DateAdded") == null ? null: (Date)map.get("DateAdded"));
900             cart.setPhotoPath(map.get("PhotoPath") == null ? "": (String)map.get("PhotoPath"));
901             cart.setPhotoPathUrl(map.get("PhotoPathUrl") == null ? "": (String)map.get("PhotoPathUrl"));
902             cart.setTotalQuantity(map.get("TotalQuantity") == null ? 0: Double.parseDouble(map.get("TotalQuantity").toString()));
903             cart.setSelectedTotalQuantity(map.get("SelectedTotalQuantity") == null ? 0: Double.parseDouble(map.get("SelectedTotalQuantity").toString()));
904             cart.setTotalAmount(map.get("TotalAmount") == null ? 0: Double.parseDouble(map.get("TotalAmount").toString()));
905             cart.setSelectedTotalAmount(map.get("SelectedTotalAmount") == null ? 0: Double.parseDouble(map.get("SelectedTotalAmount").toString()));
906             cart.setTotalWeight(map.get("TotalWeight") == null ? 0: Double.parseDouble(map.get("TotalWeight").toString()));
907             cart.setSelectedTotalWeight(map.get("SelectedTotalWeight") == null ? 0: Double.parseDouble(map.get("SelectedTotalWeight").toString()));
908             cart.setShopMatCode(map.get("ShopMatCode") == null ? "": (String)map.get("ShopMatCode"));
909             cart.setShopCcCode(map.get("ShopCcCode") == null ? "": (String)map.get("ShopCcCode"));
910             cart.setShopCcName(map.get("ShopCcName") == null ? "": (String)map.get("ShopCcName"));
911             
912             cart.setMininum(map.get("Mininum") == null ? 0.00: Double.parseDouble(map.get("Mininum").toString()));
913             cart.setMatName2(map.get("MatName2") == null ? "": (String)map.get("MatName2"));
914             cart.setMatName3(map.get("MatName3") == null ? "": (String)map.get("MatName3"));
915             cart.setMatName4(map.get("MatName4") == null ? "": (String)map.get("MatName4"));
916             cart.setBrand(map.get("Brand") == null ? "": (String)map.get("Brand"));
917             cart.setSelected(map.get("isSelected") != null &&map.get("isSelected").equals(1)?true:false);
918             
919             cart.setPreSendMinutes(map.get("PreSendMinutes") == null ? null: (Integer)map.get("PreSendMinutes"));
920             cart.setPreSendMinutesDesc(map.get("PreSendMinutesDesc") == null ? "": (String)map.get("PreSendMinutesDesc"));
921             cart.setMaxPreSendMinutes(map.get("MaxPreSendMinutes") == null ? null: (Integer)map.get("MaxPreSendMinutes"));
922             cart.setMaxPreSendMinutesDesc(map.get("MaxPreSendMinutesDesc") == null ? "": (String)map.get("MaxPreSendMinutesDesc"));
923             cart.setMaxPreSendDateTime(map.get("MaxPreSendDateTime") == null ? null: (Date)map.get("MaxPreSendDateTime"));
924             cart.setStartupGroupBuying(map.get("isStartupGroupBuying") != null&&map.get("isStartupGroupBuying").equals(1) ? true:false);
925
926             cart.setSkuId1(map.get("skuId1")==null?null:(Integer)map.get("skuId1"));
927             cart.setSkuName1(map.get("skuName1")==null?"":(String)map.get("skuName1"));
928             cart.setSkuId2(map.get("skuId2")==null?null:(Integer)map.get("skuId2"));
929             cart.setSkuName2(map.get("skuName2")==null?"":(String)map.get("skuName2"));
930             cart.setSkuId3(map.get("skuId3")==null?null:(Integer)map.get("skuId3"));
931             cart.setSkuName3(map.get("skuName3")==null?"":(String)map.get("skuName3"));
932             cart.setSkuId4(map.get("skuId4")==null?null:(Integer)map.get("skuId4"));
933             cart.setSkuName4(map.get("skuName4")==null?"":(String)map.get("skuName4"));
934             cart.setSkuId5(map.get("skuId5")==null?null:(Integer)map.get("skuId5"));
935             cart.setSkuName5(map.get("skuName5")==null?"":(String)map.get("skuName5"));
936             cart.setSkuId6(map.get("skuId6")==null?null:(Integer)map.get("skuId6"));
937             cart.setSkuName6(map.get("skuName6")==null?"":(String)map.get("skuName6"));
938             cart.setSkuId7(map.get("skuId7")==null?null:(Integer)map.get("skuId7"));
939             cart.setSkuName7(map.get("skuName7")==null?"":(String)map.get("skuName7"));
940             cart.setSkuId8(map.get("skuId8")==null?null:(Integer)map.get("skuId8"));
941             cart.setSkuName8(map.get("skuName8")==null?"":(String)map.get("skuName8"));
942             cart.setSkuId9(map.get("skuId9")==null?null:(Integer)map.get("skuId9"));
943             cart.setSkuName9(map.get("skuName9")==null?"":(String)map.get("skuName9"));
944             cart.setSkuId10(map.get("skuId10")==null?null:(Integer)map.get("skuId10"));
945             cart.setSkuName10(map.get("skuName10")==null?"":(String)map.get("skuName10"));
6a5d4e 946             cart.setCartRowCount(map.get("CartRowCount") == null ?0: (Integer)map.get("CartRowCount"));
J 947             cart.setCartQuantitySum(map.get("CartQuantitySum") == null ? 0: Double.parseDouble(map.get("CartQuantitySum").toString()));
419647 948             cart.setIsRestrictQuantity(map.get("isRestrictQuantity") == null? 0: (Integer)map.get("isRestrictQuantity"));
J 949             cart.setRestrictQuantity(map.get("RestrictQuantity") == null ? 0: Double.parseDouble(map.get("RestrictQuantity").toString()));
d223ec 950             cart.setCartRowCountForMatCode(map.get("CartRowCountForMatCode") == null ?0: (Integer)map.get("CartRowCountForMatCode"));
J 951             cart.setCartQuantitySumForMatCode(map.get("CartQuantitySumForMatCode") == null ? 0: Double.parseDouble(map.get("CartQuantitySumForMatCode").toString()));
a6a76f 952         }
F 953         return cart;
954     }
955     
956     @Override
957     public String getCartsHtml(String userCode,String sessionId,String openId,String cltCode,String hostUrl,
958             Integer freeId,double freeCost,String freeName,
959             String couponCode,double couponCost,String couponName,
960             String voucherCode ,double voucherCost,String wxQueryString,String shopCcCode,HttpServletRequest request) {
961         SettingEntity settingEntity = settingIfc.getSettingEntity() ;
962         CurrencyEntity currencyEntity = currencyIfc.getUserCurrency(userCode);
963         List<CartEntity> cartList =  this.getCartList(userCode,  sessionId,openId,cltCode,shopCcCode);
964         boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request);
965         double totalQuantity = (cartList!=null&&cartList.size()>0?cartList.get(0).getTotalQuantity():0);
966         double totalAmount = (cartList!=null&&cartList.size()>0?cartList.get(0).getTotalAmount():0);
967         String ret = "";
968         ret +="    <div id=\"cart\" class=\"btn-group btn-block\">\n";
969         ret +="      <button type=\"button\" data-toggle=\"dropdown\" data-loading-text=\"正在加载...\" class=\"btn btn-inverse btn-block btn-lg dropdown-toggle\"><i class=\"fa fa-shopping-cart\"></i> <span id=\"cart-total\">" +cartList.size() +" 种商品(共" + (new Double(totalQuantity)).intValue() +"件)"+(settingEntity.isShowPrice()? " - "+currencyEntity.getCurrencySign()+""+totalAmount : "") +"</span></button>\n";
970         ret +="      <ul class=\"dropdown-menu pull-right\">\n";
971         if (cartList != null &&  cartList.size() > 0 ) {
972             ret +="          <li>\n";
973             ret +="          <table class=\"table table-striped\">\n";
974             
975             for (int i = 0 ;cartList != null && i < cartList.size();i++) {
976                 CartEntity cart = cartList.get(i);
977                 ret +="            <tr>\n";
978                 ret +="              <td class=\"text-center\"><a href=\""+hostUrl +SettingKey.getMatCodeUrl(null,cart.getMatCode(),isMoblieBrowser) +(wxQueryString == null||"".equals(wxQueryString)?"":"&" + wxQueryString) + "\"> \n";
979                 ret +="             <img src=\"" + shoppingImageDataIfc.getImageUrl(cart.getPhotoPath(), settingEntity.getImageCartWidth(), settingEntity.getImageCartHeight(),settingEntity.isShowCartOrgImage(),settingEntity.isFromCached(),request)+ "\" alt=\""+(settingEntity.isShowMatName()? cart.getMatName():"")+"\" title=\""+(settingEntity.isShowMatName()? cart.getMatName():"")+"\" class=\"img-thumbnail\" /></a>\n";
980                 ret +="              </td>\n";
981                 ret +="              <td class=\"text-left\"><a href=\""+hostUrl +SettingKey.getMatCodeUrl(null,cart.getMatCode(),isMoblieBrowser) +(wxQueryString == null||"".equals(wxQueryString)?"":"&" + wxQueryString)+"\">"+(settingEntity.isShowMatName()? cart.getMatName():"")+"</a>\n";
982                 ret +="                <br/>";
983             
984                 Map<String,Object> lists=null ;
985                 if (cart.getOptionJson() != null && !"".equals(cart.getOptionJson())) {
986                     lists = gson.fromJson(cart.getOptionJson(),new TypeToken<Map<String,Object>>(){}.getType());
987                     for (Entry<String, Object> entry : lists.entrySet()) {                        
988                         ret +="                - <small>" + this.getOptionStr(Integer.parseInt(entry.getKey()), (String)entry.getValue()) +"</small><br/>\n" ;
989                     }
990                 }
991                 ret +="                </td>\n";
992                 ret +="              <td class=\"text-right\">x "+ (new Double( cart.getQuantity())).intValue()+"</td>\n";
993                 if (settingEntity.isShowPrice()) {
994                     ret +="              <td class=\"text-right\">"+currencyEntity.getCurrencySign()+""+cart.getAmount()+"</td>\n";
995                 }
996                 ret +="              <td class=\"text-center\"><button type=\"button\" onclick=\"cart.remove('"+ cart.getCartId()+"');\" title=\"移除\" class=\"btn btn-danger btn-xs\"><i class=\"fa fa-times\"></i></button></td>\n";
997                 ret +="            </tr>\n";
998             } 
999             ret +="        </table>\n";
1000             ret +="        </li>\n";
1001             
1002             
1003             ret +="        <li>\n";
1004             ret +="          <div>\n";
1005             if (settingEntity.isShowPrice()) {
1006                 ret +="            <table class=\"table table-bordered\">\n";
1007                 ret +="              <tr>\n";
1008                 ret +="                <td class=\"text-right\"><strong>商品总额</strong></td>\n";
1009                 ret +="                <td class=\"text-right\">"+currencyEntity.getCurrencySign()+""+ totalAmount+"</td>\n";
1010                 ret +="              </tr>\n";
1011                 
1012                 //预优配送费用
1013                 if (freeId != null) {
1014                     ret +="           <tr>";
1015                     ret +="             <td class=\"text-right\"><strong>"+freeName  + "</strong></td>";
1016                     ret +="             <td class=\"text-right\">" + currencyEntity.getCurrencySign() + freeCost + "</td>";
1017                     ret +="           </tr>";
1018                 }
1019         
1020                 //优惠劵
1021                 if (couponCode != null) {
1022                       ret +="            <tr>";
1023                       ret +="        <td class=\"text-right\"><strong>优惠券("+ couponCode  +")</strong></td>";
1024                       ret +="        <td class=\"text-right\">"+currencyEntity.getCurrencySign() +"" + ( 0L - couponCost) + "</td>";
1025                       ret +="      </tr>";  
1026                 } 
1027                 
1028                 //礼品劵
1029                 if (voucherCode != null) {
1030                     ret +="     <tr>";
1031                     ret +="        <td class=\"text-right\"><strong>礼品劵("+ voucherCode + ")</strong></td>";
1032                     ret +="        <td class=\"text-right\">"+currencyEntity.getCurrencySign() +""+ ( 0L - voucherCost ) +"</td>";
1033                     ret +="      </tr>";
1034                 }          
1035                 
1036                 ret +="              <tr>\n";
1037                 ret +="                <td class=\"text-right\"><strong>订单总额</strong></td>\n";
1038                 ret +="                <td class=\"text-right\">"+currencyEntity.getCurrencySign()+""+ ( totalAmount + freeCost - couponCost - voucherCost )+"</td>\n";
1039                 ret +="              </tr>\n";
1040                 ret +="            </table>\n";
1041             }
1042             ret +="            <p class=\"text-right\"><a href=\""+hostUrl+"/shopping/cart/" + (wxQueryString == null||"".equals(wxQueryString)?"":"?" + wxQueryString) + "\"><strong><i class=\"fa fa-shopping-cart\"></i> 查看购物车</strong></a>&nbsp;&nbsp;&nbsp;<a href=\""+hostUrl + "/shopping/checkoutnew/" + (wxQueryString == null||"".equals(wxQueryString)?"":"?" + wxQueryString) + "\"><strong><i class=\"fa fa-share\"></i> 去结账</strong></a></p>\n";
1043             ret +="          </div>\n";
1044             ret +="        </li>\n";
1045             
1046             
1047         } else {
1048             ret +="            <li><p class=\"text-center\">您的购物车内没有商品!</p></li>\n";
1049         }
1050         ret +="      </ul>\n";
1051         ret +="    </div>\n";    
1052         return ret ;
1053     }
1054     
1055     
1056     @Override
1057     public String getOptionStr(Integer optionId, String value) {
1058         String sql = "set nocount on ; \n"
1059                 + " select OptionName,Type from t710116 where OptionId = ? \n" ; 
1060         Map<String,Object> map = null ; 
1061         try {
1062             map = this.jdbcTemplate.queryForMap(sql,new Object[] { optionId } ) ;
1063             String ret = "" ;
1064             if (map != null ) {
1065                 String optionName = (map.get("OptionName") == null?"":(String) map.get("OptionName") );
1066                 String type = (map.get("Type") == null ?"": (String) map.get("Type"));
1067                 if (type!=null &&  "file".equals(type))
1068                     ret = optionName;
1069                 else
1070                     ret = optionName + ": " + (value == null || "".equals(value)?"" : value) ;
1071             }
1072             return ret.trim();
1073         }catch(DataAccessException e ) {
1074             if (e instanceof EmptyResultDataAccessException){
1075                 return null ;
1076             }else {
1077                 e.printStackTrace();
1078                  throw e;
1079             }
1080         }catch(Exception e){
1081             e.printStackTrace();
1082             throw e;
1083         }            
1084
1085     }
1086
1087     @Override
d223ec 1088     public String delCart(String cartIds) {
a6a76f 1089         String sql = " set nocount on ;  \n"
d223ec 1090                 + " declare @cartIds varchar(max) = ?, @matCodes varchar(max) \n"
J 1091                 + " select @matCodes = isnull(@matCodes,'') + case when isnull(@matCodes,'') = '' then '' else ',' end + isnull(matcode,'') \n"
1092                 + " from t710205 where CartId in (select list from getinstr(@cartIds) as a ) \n"
1093                 + " delete from t710205 where CartId in (select list from getinstr(@cartIds) as a )  ; \n"
1094                 + " select isnull(@matCodes,'') as MatCodes ;  \n";
a6a76f 1095         try {
d223ec 1096             return  this.jdbcTemplate.queryForObject(sql, String.class, new Object[] { cartIds}) ;
a6a76f 1097         }catch(DataAccessException e ) {
F 1098             if (e instanceof EmptyResultDataAccessException){
1099                 return null ;
1100             }else {
1101                 e.printStackTrace();
1102                  throw e;
1103             }
1104         }catch(Exception e){
1105             e.printStackTrace();
1106             throw e;
1107         }
1108     }
1109
1110     
1111     @Override
1112     public Integer delCartByPicture(Integer cartId) {
1113         String sql = " set nocount on ;  \n"
1114                 + " delete from t710401 where CartId = ? ; \n"
1115                 + " select @@rowcount ;  \n";
1116                 
1117         Integer ret = null ;
1118         try {
0cbf06 1119             ret =  this.jdbcTemplate.queryForObject(sql, Integer.class, new Object[] { cartId}) ;
a6a76f 1120         }catch(DataAccessException e ) {
F 1121             if (e instanceof EmptyResultDataAccessException){
1122                 return null ;
1123             }else {
1124                 e.printStackTrace();
1125                  throw e;
1126             }
1127         }catch(Exception e){
1128             e.printStackTrace();
1129             throw e;
1130         }
1131         return ret ;
1132     }
1133     
1134     @Override
1135     public Integer delAllCart(String selectCartId) {
1136         String sql = " set nocount on ;  \n"
1137                 + " delete from t710205 where CartId in (select list from getinstr(?) ) ; \n"
1138                 + " select @@rowcount ;  \n";
1139                 
1140         Integer ret = null ;
1141         try {
0cbf06 1142             ret =  this.jdbcTemplate.queryForObject(sql, Integer.class, new Object[] { selectCartId}) ;
a6a76f 1143         }catch(DataAccessException e ) {
F 1144             if (e instanceof EmptyResultDataAccessException){
1145                 return null ;
1146             }else {
1147                 e.printStackTrace();
1148                  throw e;
1149             }
1150         }catch(Exception e){
1151             e.printStackTrace();
1152             throw e;
1153         }
1154         return ret ;
1155     }
1156     
1157     @Override
1158     public Integer delAllCartByPicture(String selectCartId) {
1159         String sql = " set nocount on ;  \n"
1160                 + " delete from t710401 where CartId in (select list from getinstr(?) ) ; \n"
1161                 + " select @@rowcount ;  \n";
1162                 
1163         Integer ret = null ;
1164         try {
0cbf06 1165             ret =  this.jdbcTemplate.queryForObject(sql, Integer.class, new Object[] { selectCartId}) ;
a6a76f 1166         }catch(DataAccessException e ) {
F 1167             if (e instanceof EmptyResultDataAccessException){
1168                 return null ;
1169             }else {
1170                 e.printStackTrace();
1171                  throw e;
1172             }
1173         }catch(Exception e){
1174             e.printStackTrace();
1175             throw e;
1176         }
1177         return ret ;
1178     }
1179     
1180     @Override
1181     public Integer delAllCart(String userCode,String sessionId,String openId) {
1182         String sql = " set nocount on ;  \n"
1183                 + " delete from t710205 where UserCode = ? or SessionId = ? or OpenId = ? ; \n"
1184                 + " select @@rowcount ;  \n";
1185                 
1186         Integer ret = null ;
1187         try {
0cbf06 1188             ret =  this.jdbcTemplate.queryForObject(sql, Integer.class, new Object[] { userCode,sessionId,openId}) ;
a6a76f 1189         }catch(DataAccessException e ) {
F 1190             if (e instanceof EmptyResultDataAccessException){
1191                 return null ;
1192             }else {
1193                 e.printStackTrace();
1194                  throw e;
1195             }
1196         }catch(Exception e){
1197             e.printStackTrace();
1198             throw e;
1199         }
1200         return ret ;
1201     }
6a5d4e 1202
J 1203     @Override
1204     public CartEntity getCart(Integer cartId,String openId) {
1205         String sql = " set nocount on ; \n"
1206                 + " declare @CartId int = ?, @OpenId varchar(200) = ? , @CartRowCount int,@CartQuantitySum money \n"
1207                 + " select @CartRowCount = count(1) , @CartQuantitySum = sum(isnull(Quantity,0)) \n"
1208                 + " from t710205 where OpenId = @OpenId \n"
1209                 + " select a.CartId,a.UserCode,a.UserName,a.SessionId,a.CltCode,a.CltName,a.MatCode,b.MatName, \n"
1210                 + "    b.Special,b.PhotoPath,b.BaseUomWeight,a.RecurringId,a.OptionJson, \n"
1211                 + "    a.Quantity,a.Price,a.Amount,a.DateAdded,b.ShopMatCode,b.ShopCcCode, \n"
1212                 + "    @CartRowCount as CartRowCount,@CartQuantitySum as CartQuantitySum  \n"
1213                 + " from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
1214                 + " where a.CartId = @CartId \n";
1215         Map<String,Object> map = null ;
1216         try {
1217             map = this.jdbcTemplate.queryForMap(sql,new Object[] {cartId,openId}) ;
1218         }catch(DataAccessException e){
1219             if (e instanceof EmptyResultDataAccessException){
1220                 map = null ;
1221             } else {
1222                 e.printStackTrace();
1223                 throw e ;
1224             }
1225         }
1226         
1227         return getCartEntity(map);    
1228     }
1229     
a6a76f 1230     @Override
F 1231     public CartEntity getCart(Integer cartId) {
1232         String sql = " set nocount on ; \n"
1233                 + " select a.CartId,a.UserCode,a.UserName,a.SessionId,a.CltCode,a.CltName,a.MatCode,b.MatName, \n"
1234                 + " b.Special,b.PhotoPath,b.BaseUomWeight,a.RecurringId,a.OptionJson, \n"
1235                 + " a.Quantity,a.Price,a.Amount,a.DateAdded,b.ShopMatCode,b.ShopCcCode  \n"
1236                 + " from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
1237                 + " where a.CartId = ? \n";
1238         Map<String,Object> map = null ;
1239         try {
1240             map = this.jdbcTemplate.queryForMap(sql,cartId) ;
1241         }catch(DataAccessException e){
1242             if (e instanceof EmptyResultDataAccessException){
1243                 map = null ;
1244             } else {
1245                 e.printStackTrace();
1246                 throw e ;
1247             }
1248         }
1249         
1250         return getCartEntity(map);    
1251     }
1252     @Override
1253     public Integer updateCartPrice(Integer cartId,Double price,Double amount,double points,double weight) {
1254         String sql = " set nocount on ;  \n"
a25d9c 1255                 + " update a set price = ? ,ManualPrice=?,Amount = ?,Points = ?,Weight = ? from t710205 a where CartId = ? \n"
a6a76f 1256                 + " select @@rowcount ;  \n";
F 1257
1258         Integer ret = null ;
1259         try {
0cbf06 1260             ret =  this.jdbcTemplate.queryForObject(sql, Integer.class,new Object[] {price,price,amount,points,weight,cartId}) ;
a6a76f 1261         }catch(DataAccessException e ) {
F 1262             if (e instanceof EmptyResultDataAccessException){
1263                 return null ;
1264             }else {
1265                 e.printStackTrace();
1266                  throw e;
1267             }
1268         }catch(Exception e){
1269             e.printStackTrace();
1270             throw e;
1271         }
1272         return ret ;    
1273     }
1274     @Override
d223ec 1275     public String updateCartQuantity(Integer cartId,double quantity,String cltCode) {
a6a76f 1276         String sql = " set nocount on ;  \n"
d223ec 1277                 + " declare @myrowcount int ,@Quantity money = ?,@CartId int = ? ,@MatCode varchar(50) \n"
a6a76f 1278                 + " update a set Quantity = @Quantity  from t710205 a where CartId = @CartId \n"
F 1279                 + " select @myrowcount = @@rowcount \n"
1280                 + " exec p710205v8 @CartId = @CartId \n"   //刷新购物车中的价格、积分和重量
d223ec 1281                 + " select @MatCode = MatCode from t710205 where CartId = @CartId ;  \n"
J 1282                 + " select isnull(@MatCode,'') as MatCode \n";
a6a76f 1283
F 1284         try {
1285             //System.out.println(this.getClass()+ " start updateCartQuantity: SpObserver.getCurrentInstance():" +SpObserver.getCurrentInstance()+" SessionKey.SHOPPING_DBID:"+dbId );
d223ec 1286             return this.jdbcTemplate.queryForObject(sql, String.class,new Object[] {quantity,cartId}) ;    
a6a76f 1287         }catch(DataAccessException e ) {
F 1288             if (e instanceof EmptyResultDataAccessException){
1289                 return null ;
1290             }else {
1291                 e.printStackTrace();
1292                  throw e;
1293             }
1294         }catch(Exception e){
1295             e.printStackTrace();
1296             throw e;
1297         }
1298         //刷新购物车中的价格、积分和重量
1299         //this.refrshCart(cartId,cltCode);            
1300     }
1301     
1302     @Override
1303     public Integer updateCartQuantityByPicture(Integer cartId,double quantity) {
1304         String sql = " set nocount on ;  \n"
1305                 + " declare @Quantity money = ? \n"
1306                 + " update a set Quantity = @Quantity,Amount = round(isnull(@Quantity,0) * isnull(Price,0),2)   from t710401 a where CartId = ? \n"
1307                 + " select @@rowcount ;  \n";
1308
1309         Integer ret = null ;
1310         try {
1311             //System.out.println(this.getClass()+ " start updateCartQuantity: SpObserver.getCurrentInstance():" +SpObserver.getCurrentInstance()+" SessionKey.SHOPPING_DBID:"+dbId );
0cbf06 1312             ret =  this.jdbcTemplate.queryForObject(sql, Integer.class,new Object[] {quantity,cartId}) ;    
a6a76f 1313         }catch(DataAccessException e ) {
F 1314             if (e instanceof EmptyResultDataAccessException){
1315                 return null ;
1316             }else {
1317                 e.printStackTrace();
1318                  throw e;
1319             }
1320         }catch(Exception e){
1321             e.printStackTrace();
1322             throw e;
1323         }    
1324         
1325         return ret ;    
1326     }
1327
1328     @Override
1329     public boolean isShipping(String userCode, String sessionId,String openId,String cltCode) {
1330         String sql = " set nocount on ;  \n"
1331                 + " declare @UserCode varchar(20) = ? ,@SessionId varchar(200) = ? ; \n"
1332                 + " declare @OpenId varchar(200) = ?, @CltCode varchar(50) = ? \n; "
1333                 + " declare @found int = 0 ; \n"
1334                 + " if isnull(@found,0) = 0 and exists (select top 1 1   \n "
1335                 + "    from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
1336                 + "    where a.UserCode = @UserCode and isnull(b.Shipping,0) = 1 )  \n"
1337                 + " begin   select @found = 1 ; end  \n"
1338                 + " if isnull(@found,0) = 0 and exists (select top 1 1   \n "
1339                 + "    from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
1340                 + "    where a.SessionId = @SessionId and isnull(b.Shipping,0) = 1 )  \n"
1341                 + " begin   select @found = 1 ; end  \n"
1342                 + " if isnull(@found,0) = 0 and exists (select top 1 1   \n "
1343                 + "    from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
1344                 + "    where a.OpenId = @OpenId and isnull(b.Shipping,0) = 1 )  \n"
1345                 + " begin   select @found = 1 ; end  \n"
1346                 + " if isnull(@found,0) = 0 and exists (select top 1 1   \n "
1347                 + "    from t710205 a join t110503 b on a.MatCode = b.MatCode \n"
1348                 + "    where a.CltCode = @CltCode and isnull(b.Shipping,0) = 1 )  \n"
1349                 + " begin   select @found = 1 ; end  \n"
1350                 + " select @found ; \n";
1351
1352
1353         Integer ret = null ;
1354         try {
0cbf06 1355             ret =  this.jdbcTemplate.queryForObject(sql, Integer.class,new Object[] {userCode,sessionId,openId,cltCode}) ;    
a6a76f 1356         }catch(DataAccessException e ) {
F 1357             if (e instanceof EmptyResultDataAccessException){
1358                 return false ;
1359             }else {
1360                 e.printStackTrace();
1361                  throw e;
1362             }
1363         }catch(Exception e){
1364             e.printStackTrace();
1365             throw e;
1366         }
1367         return (ret == null || ret == 0 ? false : true ) ;
1368     }
1369
1370 }