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

需求 #14665

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