Commit 5cafdfaf authored by zhangyong's avatar zhangyong

1

parent a65c2b03
package com.egolm.shop.controller; package com.egolm.shop.controller;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -25,6 +28,26 @@ public class CartController { ...@@ -25,6 +28,26 @@ public class CartController {
@Autowired @Autowired
private CartService cartService; private CartService cartService;
@ApiOperation("购物车信息")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="shopNO", dataType = "String", required = true, value = "店铺编号", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = false, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = false, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/cartQuery",method=RequestMethod.GET)
public String cartQuery(HttpServletRequest request, HttpServletResponse response) {
Map<String,Object> params = new HashMap<String,Object>();
params.put("shopNO",request.getParameter("shopNO"));
params.put("terminal",request.getParameter("terminal"));
params.put("langID",request.getParameter("langID"));
return cartService.query(params);
}
@ApiOperation("加入购物车(JSON格式)") @ApiOperation("加入购物车(JSON格式)")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType = "String", required = false, value = "JSON格式", defaultValue = "{\"shopNO\": \"00029975\",\"terminal\": \"wechat\",\"langID\": \"936\",\"cartList\": [{\"goodsID\": \"30771\",\"goodsTypeID\": 0,\"saleQty\": \"24\",\"agentContractNO\": \"600327002\",\"promoGroupNO\":\"\",\"promoPaperNO\":\"00001810100007\" }]}"), @ApiImplicitParam(paramType = "query", dataType = "String", required = false, value = "JSON格式", defaultValue = "{\"shopNO\": \"00029975\",\"terminal\": \"wechat\",\"langID\": \"936\",\"cartList\": [{\"goodsID\": \"30771\",\"goodsTypeID\": 0,\"saleQty\": \"24\",\"agentContractNO\": \"600327002\",\"promoGroupNO\":\"\",\"promoPaperNO\":\"00001810100007\" }]}"),
......
package com.egolm.shop.service;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
public interface CartRedisService {
public void reCache(String shopNo, String terminal);
public void changeQty(String shopNo, String terminal, Integer nIdx, Double nSaleQty);
public Map<String, Object> querySync(String shopNo, String terminal) ;
}
package com.egolm.shop.service; package com.egolm.shop.service;
import java.util.Map;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
public interface CartService { public interface CartService {
...@@ -9,4 +11,6 @@ public interface CartService { ...@@ -9,4 +11,6 @@ public interface CartService {
public String remove(JSONObject obj); public String remove(JSONObject obj);
public String updateQty (JSONObject obj); public String updateQty (JSONObject obj);
public String query (Map<String,Object> params);
} }
...@@ -15,6 +15,7 @@ import com.egolm.common.StringUtil; ...@@ -15,6 +15,7 @@ import com.egolm.common.StringUtil;
import com.egolm.common.Util; import com.egolm.common.Util;
import com.egolm.common.bean.Rjx; import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.shop.service.CartRedisService;
import com.egolm.shop.service.CartService; import com.egolm.shop.service.CartService;
@Service @Service
...@@ -23,6 +24,8 @@ public class CartServiceImpl implements CartService { ...@@ -23,6 +24,8 @@ public class CartServiceImpl implements CartService {
private static final Log logger = LogFactory.getLog(CartServiceImpl.class); private static final Log logger = LogFactory.getLog(CartServiceImpl.class);
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
@Autowired
private CartRedisService cartRedisService;
/** /**
* { * {
...@@ -96,7 +99,7 @@ public class CartServiceImpl implements CartService { ...@@ -96,7 +99,7 @@ public class CartServiceImpl implements CartService {
} }
} }
} }
cartRedisService.reCache(shopNO, terminal);
return Rjx.jsonOk().set("count", count(shopNO)).toJson(); return Rjx.jsonOk().set("count", count(shopNO)).toJson();
} }
...@@ -143,6 +146,8 @@ public class CartServiceImpl implements CartService { ...@@ -143,6 +146,8 @@ public class CartServiceImpl implements CartService {
sql = "delete from tCart where sShopNO = '" + shopNO + "' and nTag = 1 and sPromoPaperNO in (" + sql + ")"; sql = "delete from tCart where sShopNO = '" + shopNO + "' and nTag = 1 and sPromoPaperNO in (" + sql + ")";
jdbcTemplate.executeUpdate(sql); jdbcTemplate.executeUpdate(sql);
jdbcTemplate.executeUpdate("delete from tCart where sShopNO = '" + shopNO + "'" + StringUtil.join(", ", " and nIdx in (", ")", nIdx)); jdbcTemplate.executeUpdate("delete from tCart where sShopNO = '" + shopNO + "'" + StringUtil.join(", ", " and nIdx in (", ")", nIdx));
cartRedisService.reCache(shopNO, terminal);
return Rjx.jsonOk().set("count", count(shopNO)).toJson(); return Rjx.jsonOk().set("count", count(shopNO)).toJson();
} }
...@@ -158,7 +163,7 @@ public class CartServiceImpl implements CartService { ...@@ -158,7 +163,7 @@ public class CartServiceImpl implements CartService {
*/ */
public String updateQty (JSONObject obj) { public String updateQty (JSONObject obj) {
String shopNO = obj.getString("shopNO"); String shopNO = obj.getString("shopNO");
String idx = obj.getString("idx"); Integer idx = obj.getInteger("idx");
Double saleQty = obj.getDouble("saleQty"); Double saleQty = obj.getDouble("saleQty");
String terminal = obj.getString("terminal"); String terminal = obj.getString("terminal");
String langID = obj.getString("langID"); String langID = obj.getString("langID");
...@@ -177,7 +182,25 @@ public class CartServiceImpl implements CartService { ...@@ -177,7 +182,25 @@ public class CartServiceImpl implements CartService {
} else { } else {
jdbcTemplate.executeUpdate("update tCart set nSaleQty = " + saleQty + " where sShopNO = '" + shopNO + "' and nIdx = " + idx); jdbcTemplate.executeUpdate("update tCart set nSaleQty = " + saleQty + " where sShopNO = '" + shopNO + "' and nIdx = " + idx);
} }
cartRedisService.changeQty(shopNO, terminal, idx, saleQty);
return Rjx.jsonOk().set("count", count(shopNO)).toJson(); return Rjx.jsonOk().set("count", count(shopNO)).toJson();
} }
/**
* 查询购物车
* <p>Title: query</p>
* <p>Description: </p>
* @param params
* @return
* @see com.egolm.shop.service.CartService#query(java.util.Map)
*/
@Override
public String query(Map<String, Object> params) {
String shopNO = params.get("shopNO")+"";
String terminal = params.get("terminal")+"";
Map<String, Object> queryMap = cartRedisService.querySync(shopNO, terminal);
return Rjx.jsonOk().setData(queryMap).toJson();
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment