Commit 9bca3333 authored by 张永's avatar 张永

需求 #14665

parent de7a7adc
package com.egolm.shop.api.service.impl; package com.egolm.shop.api.service.impl;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.egolm.common.StringUtil; 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.api.service.CartQueryService; import com.egolm.shop.api.service.CartQueryService;
import com.egolm.shop.api.service.CartService; import com.egolm.shop.api.service.CartService;
@Service @Service
public class CartServiceImpl implements CartService { public class CartServiceImpl implements CartService {
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
@Autowired @Autowired
private CartQueryService cartRedisService; private CartQueryService cartRedisService;
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(Util.objTo("190.0999", BigDecimal.class, null)); System.out.println(Util.objTo("190.0999", BigDecimal.class, null));
} }
public String append(JSONObject obj,String terminal) { public String append(JSONObject obj,String terminal) {
String shopNO = obj.getString("shopNO"); String shopNO = obj.getString("shopNO");
String orgNo = obj.getString("orgNo"); String orgNo = obj.getString("orgNo");
JSONArray cartList = obj.getJSONArray("cartList"); JSONArray cartList = obj.getJSONArray("cartList");
Integer nMaxIdx = jdbcTemplate.queryForInt("select max(nIdx) from tCart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "'"); Integer nMaxIdx = jdbcTemplate.queryForInt("select max(nIdx) from tCart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "'");
if(nMaxIdx == null) { if(nMaxIdx == null) {
nMaxIdx = 0; nMaxIdx = 0;
} }
if(cartList != null && cartList.size() > 0) { if(cartList != null && cartList.size() > 0) {
for(int i = 0; i<cartList.size();i++) { for(int i = 0; i<cartList.size();i++) {
JSONObject cartObj = cartList.getJSONObject(i); JSONObject cartObj = cartList.getJSONObject(i);
Integer nGoodsTypeID = Util.objTo(cartObj.get("goodsTypeID"), Integer.class, 0); Integer nGoodsTypeID = Util.objTo(cartObj.get("goodsTypeID"), Integer.class, 0);
Integer nSaleQty = Util.objTo(cartObj.get("saleQty"), Integer.class, null); Integer nSaleQty = Util.objTo(cartObj.get("saleQty"), Integer.class, null);
BigDecimal nSetPrice = Util.objTo(cartObj.get("setPrice"), BigDecimal.class, null); BigDecimal nSetPrice = Util.objTo(cartObj.get("setPrice"), BigDecimal.class, null);
Integer nGoodsID = Util.objTo(cartObj.get("goodsID"), Integer.class, null); Integer nGoodsID = Util.objTo(cartObj.get("goodsID"), Integer.class, null);
String sAgentContractNO = Util.objTo(cartObj.get("agentContractNO"), String.class); String sAgentContractNO = Util.objTo(cartObj.get("agentContractNO"), String.class);
String sPromoPaperNO = Util.objTo(cartObj.get("promoPaperNO"), String.class, null); String sPromoPaperNO = Util.objTo(cartObj.get("promoPaperNO"), String.class, null);
String sPromoGroupNO = Util.objTo(cartObj.get("promoGroupNO"), String.class, null); String sPromoGroupNO = Util.objTo(cartObj.get("promoGroupNO"), String.class, null);
if(StringUtil.isNotBlank(sPromoPaperNO)) { if(StringUtil.isNotBlank(sPromoPaperNO)) {
jdbcTemplate.executeUpdate("update tCart set sPromoPaperNO = ?, sPromoGroupNO = ? where sOrgNO = ? and sShopNO = ? and sAgentContractNO = ? and nGoodsID = ? and nTag = ? and (sPromoPaperNO is null or sPromoPaperNO = '')",sPromoPaperNO, sPromoGroupNO, orgNo, shopNO, sAgentContractNO, nGoodsID, nGoodsTypeID); jdbcTemplate.executeUpdate("update tCart set sPromoPaperNO = ?, sPromoGroupNO = ? where sOrgNO = ? and sShopNO = ? and sAgentContractNO = ? and nGoodsID = ? and nTag = ? and (sPromoPaperNO is null or sPromoPaperNO = '')",sPromoPaperNO, sPromoGroupNO, orgNo, shopNO, sAgentContractNO, nGoodsID, nGoodsTypeID);
} }
List<String> strs = new ArrayList<String>(); List<String> strs = new ArrayList<String>();
strs.add("sOrgNO = '" + orgNo + "'"); strs.add("sOrgNO = '" + orgNo + "'");
strs.add("sShopNO = '" + shopNO + "'"); strs.add("sShopNO = '" + shopNO + "'");
strs.add("nTag = " + nGoodsTypeID); strs.add("nTag = " + nGoodsTypeID);
strs.add("sAgentContractNO = '" + sAgentContractNO + "'"); strs.add("sAgentContractNO = '" + sAgentContractNO + "'");
strs.add("nGoodsID = " + nGoodsID); strs.add("nGoodsID = " + nGoodsID);
if(StringUtil.isNotBlank(sPromoPaperNO)) { if(StringUtil.isNotBlank(sPromoPaperNO)) {
strs.add("sPromoPaperNO = '" + sPromoPaperNO + "'"); strs.add("sPromoPaperNO = '" + sPromoPaperNO + "'");
} else { } else {
strs.add("(sPromoPaperNO = '' or sPromoPaperNO is null)"); strs.add("(sPromoPaperNO = '' or sPromoPaperNO is null)");
} }
if(StringUtil.isNotBlank(sPromoGroupNO)) { if(StringUtil.isNotBlank(sPromoGroupNO)) {
strs.add("sPromoGroupNO = '" + sPromoGroupNO + "'"); strs.add("sPromoGroupNO = '" + sPromoGroupNO + "'");
} else { } else {
strs.add("(sPromoGroupNO = '' or sPromoGroupNO is null)"); strs.add("(sPromoGroupNO = '' or sPromoGroupNO is null)");
} }
List<Map<String, Object>> list = jdbcTemplate.queryForList("select nIdx, nSaleQty, sPromoPaperNO from tCart" + StringUtil.join(" and ", " where ", "", strs)); List<Map<String, Object>> list = jdbcTemplate.queryForList("select nIdx, nSaleQty, sPromoPaperNO from tCart" + StringUtil.join(" and ", " where ", "", strs));
if(list.size() == 0) { if(list.size() == 0) {
Object[] args = new Object[]{shopNO, orgNo, ++nMaxIdx, nGoodsTypeID, sAgentContractNO, nGoodsID, nSaleQty, nSetPrice, sPromoPaperNO, sPromoGroupNO}; Object[] args = new Object[]{shopNO, orgNo, ++nMaxIdx, nGoodsTypeID, sAgentContractNO, nGoodsID, nSaleQty, nSetPrice, sPromoPaperNO, sPromoGroupNO};
jdbcTemplate.executeUpdate("insert into tCart (sShopNO, sOrgNO, nIdx, nTag, sAgentContractNO, nGoodsID, nSaleQty, nSetPrice, dLastUpdateTime, sPromoPaperNO, sPromoGroupNO) values (?, ?, ?, ?, ?, ?, ?, ?, getdate(), ?, ?)", args); jdbcTemplate.executeUpdate("insert into tCart (sShopNO, sOrgNO, nIdx, nTag, sAgentContractNO, nGoodsID, nSaleQty, nSetPrice, dLastUpdateTime, sPromoPaperNO, sPromoGroupNO) values (?, ?, ?, ?, ?, ?, ?, ?, getdate(), ?, ?)", args);
} else { } else {
Integer nIdx = Util.objTo(list.get(0).get("nIdx"), Integer.class); Integer nIdx = Util.objTo(list.get(0).get("nIdx"), Integer.class);
Double nQty = Util.objTo(list.get(0).get("nSaleQty"), Double.class); Double nQty = Util.objTo(list.get(0).get("nSaleQty"), Double.class);
jdbcTemplate.executeUpdate("update tCart set nSaleQty = " + (nSaleQty + nQty) + ", nSetPrice = ? where sOrgNO = ? and sShopNO = ? and nIdx = ?", nSetPrice, orgNo, shopNO, nIdx); jdbcTemplate.executeUpdate("update tCart set nSaleQty = " + (nSaleQty + nQty) + ", nSetPrice = ? where sOrgNO = ? and sShopNO = ? and nIdx = ?", nSetPrice, orgNo, shopNO, nIdx);
} }
} }
} }
return Rjx.jsonOk().set("count", count(orgNo, shopNO)).toJson(); return Rjx.jsonOk().set("count", count(orgNo, shopNO)).toJson();
} }
/** /**
* 统计购物车数量 * 统计购物车数量
* @Title: count * @Title: count
* @Description: TODO(这里用一句话描述这个方法的作用) * @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param shopNO * @param: @param shopNO
* @param: @return * @param: @return
* @return: Integer * @return: Integer
* @throws * @throws
*/ */
public Map<String, Object> count(String orgNo, String shopNO) { public Map<String, Object> count(String orgNo, String shopNO) {
return jdbcTemplate.queryForMap("select count(nSaleQty) totalCount , isnull(sum(nSaleQty), 0) totalSaleQty from V_Cart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "'"); return jdbcTemplate.queryForMap("select count(nSaleQty) totalCount , isnull(sum(nSaleQty), 0) totalSaleQty from V_Cart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "'");
} }
/** /**
* 删除购物车 * 删除购物车
* <p>Title: remove</p> * <p>Title: remove</p>
* <p>Description: </p> * <p>Description: </p>
* @param obj * @param obj
* @return * @return
* @see com.egolm.shop.api.service.CartService#remove(com.alibaba.fastjson.JSONObject) * @see com.egolm.shop.api.service.CartService#remove(com.alibaba.fastjson.JSONObject)
* *
* {"shopNO": "00029975","terminal": "wechat","langID": "936","idxs": [1,2,3]} * {"shopNO": "00029975","terminal": "wechat","langID": "936","idxs": [1,2,3]}
*/ */
@Override @Override
public String remove(JSONObject obj,String terminal) { public String remove(JSONObject obj,String terminal) {
String orgNo = obj.getString("orgNo"); String orgNo = obj.getString("orgNo");
String shopNO = obj.getString("shopNO"); String shopNO = obj.getString("shopNO");
JSONArray idxArray = obj.getJSONArray("idxs"); JSONArray idxArray = obj.getJSONArray("idxs");
System.out.println("idxArray----"+idxArray); System.out.println("idxArray----"+idxArray);
List<String> nIdx = new ArrayList<String>(); List<String> nIdx = new ArrayList<String>();
if(idxArray == null) { if(idxArray == null) {
nIdx.add("0"); nIdx.add("0");
}else { }else {
for(int i = 0;i<idxArray.size();i++) { for(int i = 0;i<idxArray.size();i++) {
nIdx.add(idxArray.get(i)+""); nIdx.add(idxArray.get(i)+"");
} }
} }
String sql = "select sPromoPaperNO from tCart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "' and nTag = 0" + StringUtil.join(", ", " and nIdx in (", ")", nIdx); 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 + ")"; String sql1 = "delete from tCart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "' and nTag = 1 and sPromoPaperNO in (" + sql + ")";
jdbcTemplate.executeUpdate(sql); String sql2 = "delete from tCartTempItem where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "' and nTag = 1 and sPromoPaperNO in (" + sql + ")";
jdbcTemplate.executeUpdate("delete from tCart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "'" + StringUtil.join(", ", " and nIdx in (", ")", nIdx));
jdbcTemplate.executeUpdate(sql1);
return Rjx.jsonOk().set("count", count(orgNo, shopNO)).toJson(); jdbcTemplate.executeUpdate(sql2);
} jdbcTemplate.executeUpdate("delete from tCart where sOrgNO = '" + orgNo + "' and sShopNO = '" + shopNO + "'" + StringUtil.join(", ", " and nIdx in (", ")", nIdx));
/** return Rjx.jsonOk().set("count", count(orgNo, shopNO)).toJson();
* 修改数量 }
* @Title: updateQty
* @Description: TODO(这里用一句话描述这个方法的作用) /**
* @param: @param obj * 修改数量
* @param: @return * @Title: updateQty
* @return: String * @Description: TODO(这里用一句话描述这个方法的作用)
* @throws * @param: @param obj
* {"shopNO": "00029975","terminal": "wechat","langID": "936", "idx": 2,"saleQty": "23" } * @param: @return
*/ * @return: String
public String updateQty (JSONObject obj,String terminal) { * @throws
String orgNo = obj.getString("orgNo"); * {"shopNO": "00029975","terminal": "wechat","langID": "936", "idx": 2,"saleQty": "23" }
String shopNO = obj.getString("shopNO"); */
Integer idx = obj.getInteger("idx"); public String updateQty (JSONObject obj,String terminal) {
BigDecimal saleQty = obj.getBigDecimal("saleQty"); String orgNo = obj.getString("orgNo");
String langID = obj.getString("langID"); String shopNO = obj.getString("shopNO");
if(saleQty.compareTo(BigDecimal.ZERO) == 0) { Integer idx = obj.getInteger("idx");
JSONObject removeObj = new JSONObject(); BigDecimal saleQty = obj.getBigDecimal("saleQty");
removeObj.put("shopNO", shopNO); String langID = obj.getString("langID");
removeObj.put("terminal", terminal); if(saleQty.compareTo(BigDecimal.ZERO) == 0) {
removeObj.put("langID", langID); JSONObject removeObj = new JSONObject();
JSONArray removeIdxArray = new JSONArray(); removeObj.put("shopNO", shopNO);
removeIdxArray.add(idx); removeObj.put("terminal", terminal);
removeObj.put("idxs", removeIdxArray); removeObj.put("langID", langID);
System.out.println(removeObj); JSONArray removeIdxArray = new JSONArray();
this.remove(removeObj,terminal); removeIdxArray.add(idx);
} else { removeObj.put("idxs", removeIdxArray);
String sql = "update tCart set nSaleQty = ? where sOrgNO = ? and sShopNO = ? and nIdx = ?"; System.out.println(removeObj);
jdbcTemplate.executeUpdate(sql, saleQty, orgNo, shopNO, idx); this.remove(removeObj,terminal);
} } else {
return Rjx.jsonOk().set("count", count(orgNo, shopNO)).toJson(); String sql = "update tCart set nSaleQty = ? where sOrgNO = ? and sShopNO = ? and nIdx = ?";
} jdbcTemplate.executeUpdate(sql, saleQty, orgNo, shopNO, idx);
}
return Rjx.jsonOk().set("count", count(orgNo, shopNO)).toJson();
@Override }
public String setPrice(JSONObject obj, String terminal) {
String orgNo = obj.getString("orgNo");
String shopNO = obj.getString("shopNO"); @Override
Integer idx = obj.getInteger("idx"); public String setPrice(JSONObject obj, String terminal) {
BigDecimal setPrice = obj.getBigDecimal("setPrice"); String orgNo = obj.getString("orgNo");
String sql = "update tCart set nSetPrice = ? where sOrgNO = ? and sShopNO = ? and nIdx = ?"; String shopNO = obj.getString("shopNO");
jdbcTemplate.executeUpdate(sql, setPrice, orgNo, shopNO, idx); Integer idx = obj.getInteger("idx");
return Rjx.jsonOk().toJson(); BigDecimal setPrice = obj.getBigDecimal("setPrice");
} String sql = "update tCart set nSetPrice = ? where sOrgNO = ? and sShopNO = ? and nIdx = ?";
jdbcTemplate.executeUpdate(sql, setPrice, orgNo, shopNO, idx);
return Rjx.jsonOk().toJson();
/** }
* 查询购物车
* <p>Title: query</p>
* <p>Description: </p> /**
* @param params * 查询购物车
* @return * <p>Title: query</p>
* @see com.egolm.shop.api.service.CartService#query(java.util.Map) * <p>Description: </p>
*/ * @param params
@Override * @return
public String query(Map<String, Object> params) { * @see com.egolm.shop.api.service.CartService#query(java.util.Map)
String orgNo = (String)params.get("orgNo"); */
String shopNO = params.get("shopNO")+""; @Override
String terminal = params.get("terminal")+""; public String query(Map<String, Object> params) {
Map<String, Object> queryMap = cartRedisService.query(orgNo, shopNO, terminal); String orgNo = (String)params.get("orgNo");
Map<String, Object> countMap = this.count(orgNo, shopNO); String shopNO = params.get("shopNO")+"";
queryMap.putAll(countMap); String terminal = params.get("terminal")+"";
return Rjx.jsonOk().setData(queryMap).toJson(); Map<String, Object> queryMap = cartRedisService.query(orgNo, shopNO, terminal);
} Map<String, Object> countMap = this.count(orgNo, shopNO);
queryMap.putAll(countMap);
@Override return Rjx.jsonOk().setData(queryMap).toJson();
public void clear(String orgNo, String shopNo) { }
jdbcTemplate.executeUpdate("delete from tCart where sOrgNO = ? and sShopNO = ?", orgNo, shopNo);
} @Override
public void clear(String orgNo, String shopNo) {
} jdbcTemplate.executeUpdate("delete from tCart where sOrgNO = ? and sShopNO = ?", orgNo, shopNo);
}
}
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