Commit 25c37be3 authored by Quxl's avatar Quxl

x

parent 6cd6b30f
......@@ -30,6 +30,7 @@ public class CartController {
@ApiOperation("购物车信息")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "orgNo", dataType = "String", required = true),
@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"),
......@@ -38,8 +39,9 @@ public class CartController {
})
@RequestMapping(value = "/cartQuery",method=RequestMethod.GET)
public String cartQuery(HttpServletRequest request, HttpServletResponse response) {
public String cartQuery(String orgNo, HttpServletRequest request, HttpServletResponse response) {
Map<String,Object> params = new HashMap<String,Object>();
params.put("orgNo", orgNo);
params.put("shopNO",request.getParameter("shopNO"));
params.put("terminal",request.getParameter("terminal"));
params.put("langID",request.getParameter("langID"));
......@@ -71,15 +73,17 @@ public class CartController {
@ApiOperation("删除购物车(JSON格式)")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "orgNo", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query",name = "data", dataType = "String", required = false, value = "JSON格式", defaultValue = "{\"shopNO\": \"00029975\",\"terminal\": \"wechat\",\"langID\": \"936\",\"idxs\": [1,2,3]}"),
@ApiImplicitParam(paramType = "query", name = "sign", dataType = "String", required = true, value = "签名", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "timestamp", dataType = "String", required = true, value = "时间戳", defaultValue = "")
})
@RequestMapping(value = "/remove",method=RequestMethod.POST)
public String remove(HttpServletRequest request, HttpServletResponse response) {
public String remove(String orgNo, HttpServletRequest request, HttpServletResponse response) {
String reqJson = request.getParameter("data");
JSONObject jsonObj = JSONObject.parseObject(reqJson);
jsonObj.put("orgNo", orgNo);
System.out.println("remove-------"+reqJson);
String terminal = request.getParameter("terminal");
return cartService.remove(jsonObj,terminal);
......@@ -87,15 +91,17 @@ public class CartController {
@ApiOperation("修改数量(JSON格式)")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "orgNo", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name = "data", dataType = "String", required = false, value = "JSON格式", defaultValue = "{\"shopNO\": \"00029975\", \"idx\": 2,\"saleQty\": \"23\" }"),
@ApiImplicitParam(paramType = "query", name = "sign", dataType = "String", required = true, value = "签名", defaultValue = ""),
@ApiImplicitParam(paramType = "query", name = "timestamp", dataType = "String", required = true, value = "时间戳", defaultValue = "")
})
@RequestMapping(value = "/updateQty",method=RequestMethod.POST)
public String updateQty(HttpServletRequest request, HttpServletResponse response) {
public String updateQty(String orgNo, HttpServletRequest request, HttpServletResponse response) {
String reqJson = request.getParameter("data");
JSONObject jsonObj = JSONObject.parseObject(reqJson);
jsonObj.put("orgNo", orgNo);
System.out.println("updateQty-------"+reqJson);
String terminal = request.getParameter("terminal");
return cartService.updateQty(jsonObj,terminal);
......
......@@ -3,8 +3,7 @@ package com.egolm.shop.service;
import java.util.Map;
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) ;
public void reCache(String orgNo, String shopNo, String terminal);
public void changeQty(String orgNo, String shopNo, String terminal, Integer nIdx, Double nSaleQty);
public Map<String, Object> querySync(String orgNo, String shopNo, String terminal) ;
}
......@@ -47,11 +47,11 @@ public class CartRedisServiceImpl implements CartRedisService {
private JdbcTemplate jdbcTemplate;
@Async
public void changeQty(String shopNo, String terminal, Integer nIdx, Double nSaleQty) {
public void changeQty(String orgNo, String shopNo, String terminal, Integer nIdx, Double nSaleQty) {
if (useCache) {
String json = (String) redisTemplate.opsForHash().get("CART_" + shopNo, terminal);
String json = (String) redisTemplate.opsForHash().get("CART_" + orgNo + "_" + shopNo, terminal);
if (json == null) {
this.querySync(shopNo, terminal);
this.querySync(orgNo, shopNo, terminal);
} else {
Rjx rjx = Rjx.json(GsonUtil.toMap(json));
Map<String, Object> shopGoodsObj = (Map) rjx.get("shopGoodsObj");
......@@ -61,51 +61,51 @@ public class CartRedisServiceImpl implements CartRedisService {
if (nIdx_.intValue() == nIdx.intValue()) {
obj.put("saleQty", nSaleQty);
this.processPayAmount(rjx);
this.cacheData(shopNo, terminal, rjx);
this.cacheData(orgNo, shopNo, terminal, rjx);
}
}
}
}
}
public void clearCache(String shopNo) {
redisTemplate.delete("CART_" + shopNo);
public void clearCache(String orgNo, String shopNo) {
redisTemplate.delete("CART_" + orgNo + "_" + shopNo);
}
@Async
public void reCache(String shopNo, String terminal) {
public void reCache(String orgNo, String shopNo, String terminal) {
if (useCache) {
redisTemplate.delete("CART_" + shopNo);
this.querySync(shopNo, terminal);
redisTemplate.delete("CART_" + orgNo + "_" + shopNo);
this.querySync(orgNo, shopNo, terminal);
logger.info("刷新购物车缓存全量缓存:sShopNO=" + shopNo + ",sTerminalType=" + terminal);
}
}
@Async
public void queryAsync(String shopNo, String terminal) {
querySync(shopNo, terminal);
public void queryAsync(String orgNo, String shopNo, String terminal) {
querySync(orgNo, shopNo, terminal);
}
public Map<String, Object> querySync(String shopNo, String terminal) {
public Map<String, Object> querySync(String orgNo, String shopNo, String terminal) {
Integer queryCount = 0;
System.out.println("useCache: " + useCache);
logger.info("useCache: " + useCache);
while (useCache) {
queryCount++;
String json = (String) this.redisTemplate.opsForHash().get("CART_" + shopNo, terminal);
String json = (String) this.redisTemplate.opsForHash().get("CART_" + orgNo + "_" + shopNo, terminal);
if (json == null) {
this.cacheTmpData(shopNo, terminal);
this.cacheTmpData(orgNo, shopNo, terminal);
break;
} else {
Map<String, Object> cache = GsonUtil.toMap(json);
Double nCacheStatus = (Double) cache.get("nCacheStatus");
if (nCacheStatus == null) {
this.redisTemplate.expire("CART_" + shopNo, 5, TimeUnit.MINUTES);
this.redisTemplate.expire("CART_" + orgNo + "_" + shopNo, 5, TimeUnit.MINUTES);
logger.info("购物车查询缓存命中:sShopNO=" + shopNo + ",sTerminalType=" +terminal);
return GsonUtil.toMap(json);
} else if (nCacheStatus == 1D) {
if (queryCount >= 4) {
this.clearCache(shopNo);
this.clearCache(orgNo, shopNo);
break;
} else {
try {
......@@ -123,7 +123,7 @@ public class CartRedisServiceImpl implements CartRedisService {
throw new ReflectException("Query the shopping cart parameter error:"
+ Rjx.json().set("terminal", terminal).set("shopNo", shopNo).jsonValue());
}
List<Map<String, Object>> datas = this.getGoodsList(shopNo, terminal);
List<Map<String, Object>> datas = this.getGoodsList(orgNo, shopNo, terminal);
System.out.println("datas: " + GsonUtil.toJson(datas));
Set<String> chooseGroups = new HashSet<String>();
Set<String> chooseGifts = new HashSet<String>();
......@@ -178,20 +178,20 @@ public class CartRedisServiceImpl implements CartRedisService {
this.processPromoGoods(promos, shopNo);
rjx.set("promoData", Util.listToMM(promos, "promoNo"));
this.processPayAmount(rjx);
this.cacheData(shopNo, terminal, rjx);
this.cacheData(orgNo, shopNo, terminal, rjx);
return rjx;
}
private void cacheTmpData(String shopNo, String terminal) {
this.redisTemplate.opsForHash().put("CART_" + shopNo, terminal,
private void cacheTmpData(String orgNo, String shopNo, String terminal) {
this.redisTemplate.opsForHash().put("CART_" + orgNo + "_" + shopNo, terminal,
Rjx.json().set("nCacheStatus", 1).toJson());
this.redisTemplate.expire("CART_" + shopNo, 5, TimeUnit.SECONDS);
this.redisTemplate.expire("CART_" + orgNo + "_" + shopNo, 5, TimeUnit.SECONDS);
}
private void cacheData(String shopNo, String terminal, Rjx rjx) {
private void cacheData(String orgNo, String shopNo, String terminal, Rjx rjx) {
if (useCache) {
this.redisTemplate.opsForHash().put("CART_" + shopNo, terminal, rjx);
this.redisTemplate.expire("CART_" + shopNo, 5, TimeUnit.MINUTES);
this.redisTemplate.opsForHash().put("CART_" + orgNo + "_" + shopNo, terminal, rjx);
this.redisTemplate.expire("CART_" + orgNo + "_" + shopNo, 5, TimeUnit.MINUTES);
logger.info("购物车查询数据缓存已完成,缓存有效期5分钟:sShopNO=" + shopNo + ",sTerminalType=" + terminal);
}
}
......@@ -838,7 +838,7 @@ public class CartRedisServiceImpl implements CartRedisService {
return wmsList;
}
private List<Map<String, Object>> getGoodsList(String shopNo, String terminal) {
private List<Map<String, Object>> getGoodsList(String orgNo, String shopNo, String terminal) {
String sqlPromoTag = "" + "SELECT " + "c.sPromoPaperNO, " + "p.nTag, " + "p.dPromoBeginDate, "
+ "p.dPromoEndDate " + "FROM " + "tCart c "
+ "LEFT JOIN tYWPromoMain p ON p.sPromoPaperNO = c.sPromoPaperNO " + "WHERE " + "c.sShopNO = '" + shopNo
......@@ -851,7 +851,7 @@ public class CartRedisServiceImpl implements CartRedisService {
+ "AND sPromoPaperNO IN (" + sqlClearPromoNo + ")" + Util.LINE_SEPARATOR + "UPDATE tCart SET "
+ "sPromoGroupNO = NULL, " + "sPromoPaperNO = NULL " + "WHERE " + "sShopNO = '" + shopNo + "' "
+ "AND sPromoPaperNO IN (" + sqlClearPromoNo + ")";
String sqlACart = "select * from V_Cart where sShopNO = '" + shopNo + "' order by nIdx";
String sqlACart = "select * from V_Cart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNo + "' order by nIdx";
String sqlp = ""
+ " SELECT "
......
......@@ -32,7 +32,7 @@ public class CartServiceImpl implements CartService {
String orgNo = obj.getString("orgNo");
JSONArray cartList = obj.getJSONArray("cartList");
Integer nMaxIdx = jdbcTemplate.queryForInt("select max(nIdx) from tCart where sShopNO = '" + shopNO + "'");
Integer nMaxIdx = jdbcTemplate.queryForInt("select max(nIdx) from tCart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "'");
if(nMaxIdx == null) {
nMaxIdx = 0;
}
......@@ -52,6 +52,7 @@ public class CartServiceImpl implements CartService {
} else {
List<String> strs = new ArrayList<String>();
strs.add("sOrgNO = '" + orgNo + "'");
strs.add("sShopNO = '" + shopNO + "'");
strs.add("nTag = " + nGoodsTypeID);
strs.add("sAgentContractNO = '" + sAgentContractNO + "'");
......@@ -73,13 +74,13 @@ public class CartServiceImpl implements CartService {
} else {
Integer nIdx = Util.objTo(list.get(0).get("nIdx"), Integer.class);
Double nQty = Util.objTo(list.get(0).get("nSaleQty"), Double.class);
jdbcTemplate.executeUpdate("update tCart set nSaleQty = " + (nSaleQty + nQty) + " where sShopNO = '" + shopNO + "' and nIdx = " + nIdx);
jdbcTemplate.executeUpdate("update tCart set nSaleQty = " + (nSaleQty + nQty) + " where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "' and nIdx = " + nIdx);
}
}
}
}
cartRedisService.reCache(shopNO, terminal);
return Rjx.jsonOk().set("count", count(shopNO)).toJson();
cartRedisService.reCache(orgNo, shopNO, terminal);
return Rjx.jsonOk().set("count", count(orgNo, shopNO)).toJson();
}
/**
......@@ -91,8 +92,8 @@ public class CartServiceImpl implements CartService {
* @return: Integer
* @throws
*/
public Integer count(String shopNO) {
return jdbcTemplate.queryForInt("select count(1) from tCart where sShopNO = '" + shopNO + "'");
public Integer count(String orgNo, String shopNO) {
return jdbcTemplate.queryForInt("select count(1) from tCart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "'");
}
......@@ -108,6 +109,7 @@ public class CartServiceImpl implements CartService {
*/
@Override
public String remove(JSONObject obj,String terminal) {
String orgNo = obj.getString("orgNo");
String shopNO = obj.getString("shopNO");
JSONArray idxArray = obj.getJSONArray("idxs");
System.out.println("idxArray----"+idxArray);
......@@ -120,13 +122,13 @@ public class CartServiceImpl implements CartService {
}
}
String sql = "select sPromoPaperNO from tCart where sShopNO = '" + shopNO + "' and nTag = 0" + StringUtil.join(", ", " and nIdx in (", ")", nIdx);
sql = "delete from tCart where sShopNO = '" + shopNO + "' and nTag = 1 and sPromoPaperNO in (" + sql + ")";
String sql = "select sPromoPaperNO from tCart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "' and nTag = 0" + StringUtil.join(", ", " and nIdx in (", ")", nIdx);
sql = "delete from tCart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "' and nTag = 1 and sPromoPaperNO in (" + sql + ")";
jdbcTemplate.executeUpdate(sql);
jdbcTemplate.executeUpdate("delete from tCart where sShopNO = '" + shopNO + "'" + StringUtil.join(", ", " and nIdx in (", ")", nIdx));
jdbcTemplate.executeUpdate("delete from tCart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "'" + StringUtil.join(", ", " and nIdx in (", ")", nIdx));
cartRedisService.reCache(shopNO, terminal);
return Rjx.jsonOk().set("count", count(shopNO)).toJson();
cartRedisService.reCache(orgNo, shopNO, terminal);
return Rjx.jsonOk().set("count", count(orgNo, shopNO)).toJson();
}
/**
......@@ -140,6 +142,7 @@ public class CartServiceImpl implements CartService {
* {"shopNO": "00029975","terminal": "wechat","langID": "936", "idx": 2,"saleQty": "23" }
*/
public String updateQty (JSONObject obj,String terminal) {
String orgNo = obj.getString("orgNo");
String shopNO = obj.getString("shopNO");
Integer idx = obj.getInteger("idx");
Double saleQty = obj.getDouble("saleQty");
......@@ -157,10 +160,10 @@ public class CartServiceImpl implements CartService {
System.out.println(removeObj);
this.remove(removeObj,terminal);
} else {
jdbcTemplate.executeUpdate("update tCart set nSaleQty = " + saleQty + " where sShopNO = '" + shopNO + "' and nIdx = " + idx);
jdbcTemplate.executeUpdate("update tCart set nSaleQty = " + saleQty + " where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "' and nIdx = " + idx);
}
cartRedisService.changeQty(shopNO, terminal, idx, saleQty);
return Rjx.jsonOk().set("count", count(shopNO)).toJson();
cartRedisService.changeQty(orgNo, shopNO, terminal, idx, saleQty);
return Rjx.jsonOk().set("count", count(orgNo, shopNO)).toJson();
}
/**
......@@ -173,10 +176,11 @@ public class CartServiceImpl implements CartService {
*/
@Override
public String query(Map<String, Object> params) {
String orgNo = (String)params.get("orgNo");
String shopNO = params.get("shopNO")+"";
String terminal = params.get("terminal")+"";
Map<String, Object> queryMap = cartRedisService.querySync(shopNO, terminal);
Map<String, Object> queryMap = cartRedisService.querySync(orgNo, 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