Commit 97320b74 authored by Quxl's avatar Quxl

x

parent 6203a9d3
package com.egolm.shop.api.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
import com.egolm.common.DateUtil;
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.common.jdbc.Page;
import com.egolm.common.jdbc.dialect.SqlServerDialect;
import com.egolm.shop.api.service.GoodsService;
import com.egolm.shop.common.XException;
import com.egolm.shop.common.utils.I18NUtils;
@Service
public class GoodsServiceImpl implements GoodsService {
@Autowired
private JdbcTemplate jdbcTemplate;
/**
* 获取当前用户历史购买的商品同分类(三级)下的三个月内购买数量最多的商品Top 20,
* 未登录时获取当前区域三个月内购买数量最多的商品Top 20
*/
@Override
public List<Map<String,Object>> listThinkLike(Map<String,Object> params, Page page){
String userNO = params.get("userNO")+"";
String orgNO = params.get("orgNO")+"";
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -90);
Date date = new Date(cal.getTime().getTime());
String beginDate = DateUtil.format(date);
String endDate = DateUtil.format(new Date());
String sql = "select a.nGoodsID GoodsID, g.sGoodsNO GoodsNO, g.sGoodsDesc GoodsName, acg.nSalePrice Price, acg.sSpec Spec, acg.sUnit Unit, acg.nMinSaleQty MinQty, "
+ " acg.nSaleUnits SaleUnit, acg.nMarketPrice MarketPrice, sum(a.nSaleQty) SaleQty from tAgentGoodsDailyOnline a join tGoods g on a.nGoodsID = g.nGoodsID "
+ " join tAgentContractGoods acg on a.sAgentContractNO = acg.sAgentContractNO and a.nGoodsID = acg.nGoodsID ";
if(!userNO.equals("nouserNO")&&!StringUtil.isEmpty(userNO)) {
sql += " ,tUserOrg tu, tUserAgent ua where acg.sOrgNO = '" + orgNO + "' and acg.sOrgNO = tu.sOrgNO and tu.sUserNO = '" + userNO + "' and tu.nTag&1 = 0"
+ " and acg.nAgentID = ua.nAgentID and ua.sUserNO = '" + userNO + "' and ua.nTag&1 = 0 and a.dTradeDate >= '" + beginDate + "' and a.dTradeDate < '" + endDate + "' ";
}else {
sql += " where acg.sOrgNO = '" + orgNO + "' and a.dTradeDate >= '" + beginDate + "' and a.dTradeDate < '" + endDate +"'";
}
sql += " group by a.nGoodsID, g.sGoodsNO, g.sGoodsDesc, acg.nSalePrice, acg.sSpec, acg.sUnit, acg.nMinSaleQty, acg.nSaleUnits, acg.nMarketPrice, acg.sMarketUnit";
jdbcTemplate.setDialect(new SqlServerDialect());
return jdbcTemplate.limit(sql, page);
}
@Override
public List<Map<String, Object>> getHotSaleGoods(Map<String, Object> map, Page page) {
String sql="SELECT GoodsID = agd.nGoodsID,ContractNO = agd.sAgentContractNO ,SaleQty = sum(agd.nSaleQty), ImageUrl = isnull(g.sURL ,'') "
+ " FROM tAgentGoodsDailyOnline agd JOIN tAgentContractGoods acg ON agd.sAgentContractNO = acg.sAgentContractNO "
+ " LEFT JOIN tGoodsPic g ON agd.nGoodsID = g.nGoodsID AND g.sPicTypeID = '1' AND g.nItem = 1 AND g.nTag&1=0 "
+ " WHERE acg.nTag&1=0 AND acg.sOrgNO = ? "
+ " GROUP BY agd.nGoodsID,agd.sAgentContractNO,g.sURL ";
String OrgNO=(String) map.get("OrgNO");
jdbcTemplate.setDialect(new SqlServerDialect());
return jdbcTemplate.limit(sql, page,OrgNO);
}
@Override
public List<Map<String, Object>> GetCategoryGoods(Map<String, Object> map, Page page) {
String OrgNO=(String) map.get("OrgNO");
String ShopNO=(String) map.get("ShopNO");
String CategoryNOA=(String) map.get("CategoryNOA");
String CategoryNOB=(String) map.get("CategoryNOB");
String DistrictID;
String sql_0="SELECT DistrictID=sDistrictID FROM tShop WHERE sOrgNO =? AND sShopNO = ?";
try {
DistrictID=jdbcTemplate.queryForString(sql_0, OrgNO,ShopNO);
} catch (EmptyResultDataAccessException e) {
DistrictID="";
}
String sql=" SELECT GoodsID = acg.nGoodsID,"+
" GoodsNO = acg.sGoodsNO, " +
" GoodsName = acg.sGoodsDesc, " +
" Price = acg.nSalePrice, " +
" Unit = acg.sUnit, " +
" Spec = acg.sSpec, " +
" MinQty = acg.nMinSaleQty, " +
" SaleUnit = acg.nSaleUnits, " +
" MarketPrice = acg.nMarketPrice, " +
" MarketUnit = acg.sMarketUnit, " +
" ImagePath = ISNULL(g.sURL,'')," +
" PopImagePath = '' " +
" FROM tAgentContractWarehouse acw, tAgentContractGoods acg "
+ "LEFT JOIN tGoodsPic g ON acg.nGoodsID = g.nGoodsID " +
" AND g.sPicTypeID = '1' " +
" AND g.nItem = 1, " +
"(SELECT a.sWarehouseNO FROM tWarehouseDistrict a, (SELECT sDistrictID, nDCPriority = max(nDCPriority) FROM tWarehouseDistrict " +
" GROUP BY sDistrictID) b WHERE a.sDistrictID = b.sDistrictID AND a.nDCPriority = b.nDCPriority AND (a.sDistrictID = ? OR ? = '') " +
" ) d, tCategory c " +
" WHERE acw.sAgentContractNO = acg.sAgentContractNO " +
" AND acw.sWarehouseNO = d.sWarehouseNO " +
" AND acg.sCategoryNO = c.sCategoryNO " +
" AND acg.nTag&1=0 " +
" AND acg.sOrgNO = '"+OrgNO+"' " +
" AND (c.sPath LIKE ISNULL((SELECT sPath FROM tCategory WHERE sCategoryNO = ?),'') + '%') " +
" AND (c.sPath LIKE ISNULL((SELECT sPath FROM tCategory WHERE sCategoryNO = ?),'') + '%') " ;
jdbcTemplate.setDialect(new SqlServerDialect());
return jdbcTemplate.limit(sql,page, DistrictID,DistrictID,CategoryNOA,CategoryNOB);
}
/**
* 热搜词
* <p>Title: hotSearchKey</p>
* <p>Description: </p>
* @param map
* @param page
* @return
* @see com.egolm.shop.api.service.GoodsService#hotSearchKey(java.util.Map, com.egolm.common.jdbc.Page)
*/
@Override
public List<Map<String, Object>> hotSearchKey(Map<String, Object> map, Page page) {
String orgNO=(String) map.get("orgNO");
String sql="SELECT "
+ " searchCount = COUNT (sKeyword), "
+ " keyword = sKeyword "
+ "FROM "
+ " tShopSearchLog slog LEFT JOIN tShop s on(s.sShopNO=slog.sShopNO) "
+ "WHERE "
+ " s.sShopNO=slog.sShopNO "
+ " AND s.sOrgNO='"+orgNO+"' "
+ " GROUP BY "
+ " s.sOrgNO, "
+ " sKeyword ";
jdbcTemplate.setDialect(new SqlServerDialect());
return jdbcTemplate.limit(sql,page);
}
/**
* 商品详情
* <p>Title: goodsDetail</p>
* <p>Description: </p>
* @param map
* @param page
* @return
* @see com.egolm.shop.api.service.GoodsService#goodsDetail(java.util.Map, com.egolm.common.jdbc.Page)
*/
@Override
public String goodsDetail(Map<String, Object> map) {
String orgNo = (String)map.get("orgNo");
String goodsId=(String) map.get("goodsId");
String contractNo=(String) map.get("contractNo");
String custTypeId=(String) map.get("custTypeId");
String gSql = "select t.*, ap.nRealSalePrice nApSalePrice from V_OrgGoods t left join tAgentCustTypePrice ap on ap.sCustTypeID = ? and ap.sAgentContractNO = t.sAgentContractNO and ap.nGoodsID = t.nGoodsID where t.sOrgNO = ? and t.sAgentContractNO = ? and t.nGoodsID = ?";
Map<String, Object> detail = null;
try {
detail = jdbcTemplate.queryForMap(gSql, custTypeId, orgNo, contractNo, goodsId);
BigDecimal nApSalePrice = (BigDecimal) detail.get("nApSalePrice");
if(nApSalePrice != null) {
detail.put("nRealSalePrice", nApSalePrice);
}
} catch (EmptyResultDataAccessException e) {
throw new XException("商品已下架");
}
String sql = "select t.nGoodsID, t.sSubCode, t.nParentID, t.sSpecName, t.sSpec, isnull(ap.nRealSalePrice, og.nRealSalePrice) nRealSalePrice, og.nStockQty, og.nLockedQty from tGoodsSubCode t left join V_OrgGoods og on og.sOrgNO = ? and og.sAgentContractNO = ? and og.nGoodsID = t.nGoodsID left join tAgentCustTypePrice ap on ap.sCustTypeID = ? and ap.sAgentContractNO = og.sAgentContractNO and ap.nGoodsID = og.nGoodsID where t.nParentID = ? and t.nTag&1 = 0";
List<Map<String, Object>> specList = jdbcTemplate.queryForList(sql, orgNo, contractNo, custTypeId, goodsId);
Map<String, Map<String, Object>> specMap = Util.listToMM(specList, ";", "sSpecName", "sSpec");
Set<String> specNames = specList.stream().map(o -> (String)o.get("sSpecName")).collect(Collectors.toSet());
Set<String> specs = specList.stream().map(o -> (String)o.get("sSpec")).collect(Collectors.toSet());
BigDecimal nMarketPrice = (BigDecimal)detail.get("nMarketPrice");
BigDecimal nRealSalePrice = (BigDecimal)detail.get("nRealSalePrice");
BigDecimal nProfitMargin = BigDecimal.ZERO;
if(nRealSalePrice != null && nRealSalePrice.compareTo(BigDecimal.ZERO) != 0) {
nProfitMargin = nMarketPrice.subtract(nRealSalePrice).multiply(new BigDecimal(100)).divide(nRealSalePrice, 2, BigDecimal.ROUND_HALF_UP);
}
detail.put("nProfitMargin", nProfitMargin);
Map<String, List<Map<String, Object>>> picList = goodsPicList(goodsId, contractNo);
String promoSql = "select pm.* from tYWPromoMain pm, tYWPromoDtl pd, tPromoCustBWList bw where pm.sPromoPaperNO = bw.sPromoPaperNO and bw.sShopNO = ? and pm.sPromoActionTypeID != '3' and pm.sOrgNO = ? and pm.sPromoPaperNO = pd.sPromoPaperNO and pm.nTag&3 = 2 and (pd.sAgentContractNO = ?) and (pd.nGoodsID = ?)";
Object[] args = new Object[] {custTypeId, orgNo, contractNo, goodsId};
List<Map<String, Object>> promoList = jdbcTemplate.queryForList(promoSql, args);
detail.put("promoList", promoList);
Rjx rjx = Rjx.jsonOk().set("goodsDetail", detail).set("specList", specList).set("specMap", specMap).set("specNames", specNames).set("specs", specs);
rjx.putAll(picList);
return rjx.toJson();
}
/**
* 查询商品图片
* @Title: goodsPicList
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param goodsID
* @param: @param agentContractNO
* @param: @return
* @return: List<Map<String,Object>>
* @throws
*/
public Map<String, List<Map<String, Object>>> goodsPicList(String goodsID,String agentContractNO ){
String sql1 = "select agp.sURL, agp.nLength, agp.sPicTypeID from tAgentGoodsPic agp, tAgentContractGoods acg where agp.nAgentID = acg.nAgentID and agp.nGoodsID = acg.nGoodsID and acg.sAgentContractNO = ? and acg.nGoodsID = ? and agp.nTag&1 = 0 order by agp.nIdx";
List<Map<String, Object>> picList1 = jdbcTemplate.queryForList(sql1, agentContractNO, goodsID);
Map<String, List<Map<String,Object>>> picML1 = Util.listToML(picList1, "sPicTypeID");
Map<String, List<Map<String, Object>>> pics = new HashMap<String, List<Map<String, Object>>>();
for(String sPicTypeID : new String[] {"1", "2", "3", "4"}) {
List<Map<String, Object>> picList = picML1.get(sPicTypeID);
pics.put("ImgGroup_" + sPicTypeID, picList);
}
return pics;
}
/**
* 收藏及取消收藏
* @Title: updateFlavor
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param params
* @param: @return
* @return: String
* @throws
*/
public String updateFlavor(Map<String,Object> params){
String goodsID=(String)params.get("goodsID");
String shopNO=(String)params.get("shopNO");
String override=(String)params.get("override");
String langID=(String) params.get("langID");
String sqlD="delete from tFlavorGoods where sShopNO =? and nGoodsID = ?";
String sqlIn=" if not exists (select 1 from tFlavorGoods where sShopNO = ? and nGoodsID = ?)"
+" insert into tFlavorGoods (sShopNO, nGoodsID, dLastUpdateTime) "
+" values (?,?,getdate())";
jdbcTemplate.setDialect(new SqlServerDialect());
if("0".equals(override)) {
try {
jdbcTemplate.executeUpdate(sqlD, shopNO,goodsID);
return Rjx.jsonOk().setMessage(I18NUtils.getMessage(langID, "Msg_CancelCollect_success")).toJson();
} catch (Exception e) {
e.printStackTrace();
return Rjx.jsonErr().setCode(-1).setMessage(I18NUtils.getMessage(langID, "Msg_CancelCollect_failure")).toJson();
}
}else if("1".equals(override)) {
try {
jdbcTemplate.executeUpdate(sqlIn, shopNO,goodsID, shopNO,goodsID);
return Rjx.jsonOk().setMessage(I18NUtils.getMessage(langID, "Msg_Collection_success")).toJson();
} catch (Exception e) {
e.printStackTrace();
return Rjx.jsonErr().setCode(-1).setMessage(I18NUtils.getMessage(langID, "Msg_Collection_failure")).toJson();
}
}
return Rjx.jsonErr().setCode(-1).setMessage(I18NUtils.getMessage(langID, "Msg_Operate_failure")).toJson();
}
@Override
public Map<String, Map<String, Object>> queryStockPrice(String orgNo, String shopNo, String[] uidAry) {
List<String> args = new ArrayList<String>();
for(String uid : uidAry) {
if(StringUtil.isBlank(uid)) {
continue;
}
String[] kv = uid.split(":", 2);
args.add("(t.sAgentContractNO = '" + kv[0] + "' and t.nGoodsID = " + kv[1] + ")");
}
String sCustTypeID = "99999999999999";
try {
sCustTypeID = jdbcTemplate.queryForString("select c.sCustTypeID from tCustomer c, tShop s where c.sCustNO = s.sCustNO and s.sShopNO = ?", shopNo);
} catch (Exception e) {
//shopNo为空,没有登陆
}
String sql = "select t.sAgentContractNO, t.nGoodsID, t.nStockQty, t.nDefaultPrice, isnull(ap.nRealSalePrice, t.nRealSalePrice) nRealSalePrice from V_OrgGoods t left join tAgentCustTypePrice ap on ap.sCustTypeID = '" + sCustTypeID + "' and t.sAgentContractNO = ap.sAgentContractNO and t.nGoodsID = ap.nGoodsID where t.sOrgNO = '" + orgNo + "' " + StringUtil.join(" OR ", " and (", ")", " and (1 = 0) ", args);
List<Map<String, Object>> datas = jdbcTemplate.queryForList(sql);
Map<String, Map<String, Object>> mm = Util.listToMM(datas, ":", "sAgentContractNO", "nGoodsID");
String sql1 = "select t.sAgentContractNO, t.nGoodsID, p.sPromoTheme, p.sPromoName, p.sPromoPaperNO, p.sPromoActionTypeID, t.sGroupNO sPromoGroupNO from tYWPromoDtl t, tYWPromoMain p where p.sPromoActionTypeID != '3' and t.sPromoPaperNO = p.sPromoPaperNO and p.nTag&3 = 2 and p.sOrgNO = '" + orgNo + "' " + StringUtil.join(" OR ", " and (", ")", " and (1 = 0) ", args) + " group by t.sAgentContractNO, t.nGoodsID, p.sPromoTheme, p.sPromoName, p.sPromoPaperNO, p.sPromoActionTypeID, t.sGroupNO";
List<Map<String, Object>> plist = jdbcTemplate.queryForList(sql1);
Map<String, List<Map<String, Object>>> pmm = Util.listToML(plist, ":", "sAgentContractNO", "nGoodsID");
for(String key : mm.keySet()) {
mm.get(key).put("promoList", pmm.get(key));
}
return mm;
}
}
package com.egolm.shop.api.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
import com.egolm.common.DateUtil;
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.common.jdbc.Page;
import com.egolm.common.jdbc.dialect.SqlServerDialect;
import com.egolm.shop.api.service.GoodsService;
import com.egolm.shop.common.XException;
import com.egolm.shop.common.utils.I18NUtils;
@Service
public class GoodsServiceImpl implements GoodsService {
@Autowired
private JdbcTemplate jdbcTemplate;
/**
* 获取当前用户历史购买的商品同分类(三级)下的三个月内购买数量最多的商品Top 20,
* 未登录时获取当前区域三个月内购买数量最多的商品Top 20
*/
@Override
public List<Map<String,Object>> listThinkLike(Map<String,Object> params, Page page){
String userNO = params.get("userNO")+"";
String orgNO = params.get("orgNO")+"";
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -90);
Date date = new Date(cal.getTime().getTime());
String beginDate = DateUtil.format(date);
String endDate = DateUtil.format(new Date());
String sql = "select a.nGoodsID GoodsID, g.sGoodsNO GoodsNO, g.sGoodsDesc GoodsName, acg.nSalePrice Price, acg.sSpec Spec, acg.sUnit Unit, acg.nMinSaleQty MinQty, "
+ " acg.nSaleUnits SaleUnit, acg.nMarketPrice MarketPrice, sum(a.nSaleQty) SaleQty from tAgentGoodsDailyOnline a join tGoods g on a.nGoodsID = g.nGoodsID "
+ " join tAgentContractGoods acg on a.sAgentContractNO = acg.sAgentContractNO and a.nGoodsID = acg.nGoodsID ";
if(!userNO.equals("nouserNO")&&!StringUtil.isEmpty(userNO)) {
sql += " ,tUserOrg tu, tUserAgent ua where acg.sOrgNO = '" + orgNO + "' and acg.sOrgNO = tu.sOrgNO and tu.sUserNO = '" + userNO + "' and tu.nTag&1 = 0"
+ " and acg.nAgentID = ua.nAgentID and ua.sUserNO = '" + userNO + "' and ua.nTag&1 = 0 and a.dTradeDate >= '" + beginDate + "' and a.dTradeDate < '" + endDate + "' ";
}else {
sql += " where acg.sOrgNO = '" + orgNO + "' and a.dTradeDate >= '" + beginDate + "' and a.dTradeDate < '" + endDate +"'";
}
sql += " group by a.nGoodsID, g.sGoodsNO, g.sGoodsDesc, acg.nSalePrice, acg.sSpec, acg.sUnit, acg.nMinSaleQty, acg.nSaleUnits, acg.nMarketPrice, acg.sMarketUnit";
jdbcTemplate.setDialect(new SqlServerDialect());
return jdbcTemplate.limit(sql, page);
}
@Override
public List<Map<String, Object>> getHotSaleGoods(Map<String, Object> map, Page page) {
String sql="SELECT GoodsID = agd.nGoodsID,ContractNO = agd.sAgentContractNO ,SaleQty = sum(agd.nSaleQty), ImageUrl = isnull(g.sURL ,'') "
+ " FROM tAgentGoodsDailyOnline agd JOIN tAgentContractGoods acg ON agd.sAgentContractNO = acg.sAgentContractNO "
+ " LEFT JOIN tGoodsPic g ON agd.nGoodsID = g.nGoodsID AND g.sPicTypeID = '1' AND g.nItem = 1 AND g.nTag&1=0 "
+ " WHERE acg.nTag&1=0 AND acg.sOrgNO = ? "
+ " GROUP BY agd.nGoodsID,agd.sAgentContractNO,g.sURL ";
String OrgNO=(String) map.get("OrgNO");
jdbcTemplate.setDialect(new SqlServerDialect());
return jdbcTemplate.limit(sql, page,OrgNO);
}
@Override
public List<Map<String, Object>> GetCategoryGoods(Map<String, Object> map, Page page) {
String OrgNO=(String) map.get("OrgNO");
String ShopNO=(String) map.get("ShopNO");
String CategoryNOA=(String) map.get("CategoryNOA");
String CategoryNOB=(String) map.get("CategoryNOB");
String DistrictID;
String sql_0="SELECT DistrictID=sDistrictID FROM tShop WHERE sOrgNO =? AND sShopNO = ?";
try {
DistrictID=jdbcTemplate.queryForString(sql_0, OrgNO,ShopNO);
} catch (EmptyResultDataAccessException e) {
DistrictID="";
}
String sql=" SELECT GoodsID = acg.nGoodsID,"+
" GoodsNO = acg.sGoodsNO, " +
" GoodsName = acg.sGoodsDesc, " +
" Price = acg.nSalePrice, " +
" Unit = acg.sUnit, " +
" Spec = acg.sSpec, " +
" MinQty = acg.nMinSaleQty, " +
" SaleUnit = acg.nSaleUnits, " +
" MarketPrice = acg.nMarketPrice, " +
" MarketUnit = acg.sMarketUnit, " +
" ImagePath = ISNULL(g.sURL,'')," +
" PopImagePath = '' " +
" FROM tAgentContractWarehouse acw, tAgentContractGoods acg "
+ "LEFT JOIN tGoodsPic g ON acg.nGoodsID = g.nGoodsID " +
" AND g.sPicTypeID = '1' " +
" AND g.nItem = 1, " +
"(SELECT a.sWarehouseNO FROM tWarehouseDistrict a, (SELECT sDistrictID, nDCPriority = max(nDCPriority) FROM tWarehouseDistrict " +
" GROUP BY sDistrictID) b WHERE a.sDistrictID = b.sDistrictID AND a.nDCPriority = b.nDCPriority AND (a.sDistrictID = ? OR ? = '') " +
" ) d, tCategory c " +
" WHERE acw.sAgentContractNO = acg.sAgentContractNO " +
" AND acw.sWarehouseNO = d.sWarehouseNO " +
" AND acg.sCategoryNO = c.sCategoryNO " +
" AND acg.nTag&1=0 " +
" AND acg.sOrgNO = '"+OrgNO+"' " +
" AND (c.sPath LIKE ISNULL((SELECT sPath FROM tCategory WHERE sCategoryNO = ?),'') + '%') " +
" AND (c.sPath LIKE ISNULL((SELECT sPath FROM tCategory WHERE sCategoryNO = ?),'') + '%') " ;
jdbcTemplate.setDialect(new SqlServerDialect());
return jdbcTemplate.limit(sql,page, DistrictID,DistrictID,CategoryNOA,CategoryNOB);
}
/**
* 热搜词
* <p>Title: hotSearchKey</p>
* <p>Description: </p>
* @param map
* @param page
* @return
* @see com.egolm.shop.api.service.GoodsService#hotSearchKey(java.util.Map, com.egolm.common.jdbc.Page)
*/
@Override
public List<Map<String, Object>> hotSearchKey(Map<String, Object> map, Page page) {
String orgNO=(String) map.get("orgNO");
String sql="SELECT "
+ " searchCount = COUNT (sKeyword), "
+ " keyword = sKeyword "
+ "FROM "
+ " tShopSearchLog slog LEFT JOIN tShop s on(s.sShopNO=slog.sShopNO) "
+ "WHERE "
+ " s.sShopNO=slog.sShopNO "
+ " AND s.sOrgNO='"+orgNO+"' "
+ " GROUP BY "
+ " s.sOrgNO, "
+ " sKeyword ";
jdbcTemplate.setDialect(new SqlServerDialect());
return jdbcTemplate.limit(sql,page);
}
/**
* 商品详情
* <p>Title: goodsDetail</p>
* <p>Description: </p>
* @param map
* @param page
* @return
* @see com.egolm.shop.api.service.GoodsService#goodsDetail(java.util.Map, com.egolm.common.jdbc.Page)
*/
@Override
public String goodsDetail(Map<String, Object> map) {
String orgNo = (String)map.get("orgNo");
String goodsId=(String) map.get("goodsId");
String contractNo=(String) map.get("contractNo");
String custTypeId=(String) map.get("custTypeId");
String gSql = "select t.*, ap.nRealSalePrice nApSalePrice from V_OrgGoods t left join tAgentCustTypePrice ap on ap.sCustTypeID = ? and ap.sAgentContractNO = t.sAgentContractNO and ap.nGoodsID = t.nGoodsID where t.sOrgNO = ? and t.sAgentContractNO = ? and t.nGoodsID = ?";
Map<String, Object> detail = null;
try {
detail = jdbcTemplate.queryForMap(gSql, custTypeId, orgNo, contractNo, goodsId);
BigDecimal nApSalePrice = (BigDecimal) detail.get("nApSalePrice");
if(nApSalePrice != null) {
detail.put("nRealSalePrice", nApSalePrice);
}
} catch (EmptyResultDataAccessException e) {
throw new XException("商品已下架");
}
String sql = "select t.nGoodsID, t.sSubCode, t.nParentID, t.sSpecName, t.sSpec, isnull(ap.nRealSalePrice, og.nRealSalePrice) nRealSalePrice, og.nStockQty, og.nLockedQty from tGoodsSubCode t left join V_OrgGoods og on og.sOrgNO = ? and og.sAgentContractNO = ? and og.nGoodsID = t.nGoodsID left join tAgentCustTypePrice ap on ap.sCustTypeID = ? and ap.sAgentContractNO = og.sAgentContractNO and ap.nGoodsID = og.nGoodsID where t.nParentID = ? and t.nTag&1 = 0";
List<Map<String, Object>> specList = jdbcTemplate.queryForList(sql, orgNo, contractNo, custTypeId, goodsId);
Map<String, Map<String, Object>> specMap = Util.listToMM(specList, ";", "sSpecName", "sSpec");
Set<String> specNames = specList.stream().map(o -> (String)o.get("sSpecName")).collect(Collectors.toSet());
Set<String> specs = specList.stream().map(o -> (String)o.get("sSpec")).collect(Collectors.toSet());
BigDecimal nMarketPrice = (BigDecimal)detail.get("nMarketPrice");
BigDecimal nRealSalePrice = (BigDecimal)detail.get("nRealSalePrice");
BigDecimal nProfitMargin = BigDecimal.ZERO;
if(nRealSalePrice != null && nRealSalePrice.compareTo(BigDecimal.ZERO) != 0) {
nProfitMargin = nMarketPrice.subtract(nRealSalePrice).multiply(new BigDecimal(100)).divide(nRealSalePrice, 2, BigDecimal.ROUND_HALF_UP);
}
detail.put("nProfitMargin", nProfitMargin);
Map<String, List<Map<String, Object>>> picList = goodsPicList(goodsId, contractNo);
String promoSql = "select pm.* from tYWPromoMain pm, tYWPromoDtl pd, tPromoCustBWList bw where pm.sPromoPaperNO = bw.sPromoPaperNO and bw.sShopNO = ? and pm.sPromoActionTypeID != '3' and pm.sOrgNO = ? and pm.sPromoPaperNO = pd.sPromoPaperNO and pm.nTag&3 = 2 and (pd.sAgentContractNO = ?) and (pd.nGoodsID = ?)";
Object[] args = new Object[] {custTypeId, orgNo, contractNo, goodsId};
List<Map<String, Object>> promoList = jdbcTemplate.queryForList(promoSql, args);
detail.put("promoList", promoList);
Rjx rjx = Rjx.jsonOk().set("goodsDetail", detail).set("specList", specList).set("specMap", specMap).set("specNames", specNames).set("specs", specs);
rjx.putAll(picList);
return rjx.toJson();
}
/**
* 查询商品图片
* @Title: goodsPicList
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param goodsID
* @param: @param agentContractNO
* @param: @return
* @return: List<Map<String,Object>>
* @throws
*/
public Map<String, List<Map<String, Object>>> goodsPicList(String goodsID,String agentContractNO ){
String sql1 = "select agp.sURL, agp.nLength, agp.sPicTypeID from tAgentGoodsPic agp, tAgentContractGoods acg where agp.nAgentID = acg.nAgentID and agp.nGoodsID = acg.nGoodsID and acg.sAgentContractNO = ? and acg.nGoodsID = ? and agp.nTag&1 = 0 order by agp.nIdx";
List<Map<String, Object>> picList1 = jdbcTemplate.queryForList(sql1, agentContractNO, goodsID);
Map<String, List<Map<String,Object>>> picML1 = Util.listToML(picList1, "sPicTypeID");
Map<String, List<Map<String, Object>>> pics = new HashMap<String, List<Map<String, Object>>>();
for(String sPicTypeID : new String[] {"1", "2", "3", "4"}) {
List<Map<String, Object>> picList = picML1.get(sPicTypeID);
pics.put("ImgGroup_" + sPicTypeID, picList);
}
return pics;
}
/**
* 收藏及取消收藏
* @Title: updateFlavor
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param params
* @param: @return
* @return: String
* @throws
*/
public String updateFlavor(Map<String,Object> params){
String goodsID=(String)params.get("goodsID");
String shopNO=(String)params.get("shopNO");
String override=(String)params.get("override");
String langID=(String) params.get("langID");
String sqlD="delete from tFlavorGoods where sShopNO =? and nGoodsID = ?";
String sqlIn=" if not exists (select 1 from tFlavorGoods where sShopNO = ? and nGoodsID = ?)"
+" insert into tFlavorGoods (sShopNO, nGoodsID, dLastUpdateTime) "
+" values (?,?,getdate())";
jdbcTemplate.setDialect(new SqlServerDialect());
if("0".equals(override)) {
try {
jdbcTemplate.executeUpdate(sqlD, shopNO,goodsID);
return Rjx.jsonOk().setMessage(I18NUtils.getMessage(langID, "Msg_CancelCollect_success")).toJson();
} catch (Exception e) {
e.printStackTrace();
return Rjx.jsonErr().setCode(-1).setMessage(I18NUtils.getMessage(langID, "Msg_CancelCollect_failure")).toJson();
}
}else if("1".equals(override)) {
try {
jdbcTemplate.executeUpdate(sqlIn, shopNO,goodsID, shopNO,goodsID);
return Rjx.jsonOk().setMessage(I18NUtils.getMessage(langID, "Msg_Collection_success")).toJson();
} catch (Exception e) {
e.printStackTrace();
return Rjx.jsonErr().setCode(-1).setMessage(I18NUtils.getMessage(langID, "Msg_Collection_failure")).toJson();
}
}
return Rjx.jsonErr().setCode(-1).setMessage(I18NUtils.getMessage(langID, "Msg_Operate_failure")).toJson();
}
@Override
public Map<String, Map<String, Object>> queryStockPrice(String orgNo, String shopNo, String[] uidAry) {
List<String> args = new ArrayList<String>();
for(String uid : uidAry) {
if(StringUtil.isBlank(uid)) {
continue;
}
String[] kv = uid.split(":", 2);
args.add("(t.sAgentContractNO = '" + kv[0] + "' and t.nGoodsID = " + kv[1] + ")");
}
String sCustTypeID = "99999999999999";
try {
sCustTypeID = jdbcTemplate.queryForString("select c.sCustTypeID from tCustomer c, tShop s where c.sCustNO = s.sCustNO and s.sShopNO = ?", shopNo);
} catch (Exception e) {
//shopNo为空,没有登陆
}
String sql = "select t.sAgentContractNO, t.nGoodsID, t.nStockQty, t.nRealStockQty, t.nDefaultPrice, isnull(ap.nRealSalePrice, t.nRealSalePrice) nRealSalePrice from V_OrgGoods t left join tAgentCustTypePrice ap on ap.sCustTypeID = '" + sCustTypeID + "' and t.sAgentContractNO = ap.sAgentContractNO and t.nGoodsID = ap.nGoodsID where t.sOrgNO = '" + orgNo + "' " + StringUtil.join(" OR ", " and (", ")", " and (1 = 0) ", args);
List<Map<String, Object>> datas = jdbcTemplate.queryForList(sql);
Map<String, Map<String, Object>> mm = Util.listToMM(datas, ":", "sAgentContractNO", "nGoodsID");
String sql1 = "select t.sAgentContractNO, t.nGoodsID, p.sPromoTheme, p.sPromoName, p.sPromoPaperNO, p.sPromoActionTypeID, t.sGroupNO sPromoGroupNO from tYWPromoDtl t, tYWPromoMain p where p.sPromoActionTypeID != '3' and t.sPromoPaperNO = p.sPromoPaperNO and p.nTag&3 = 2 and p.sOrgNO = '" + orgNo + "' " + StringUtil.join(" OR ", " and (", ")", " and (1 = 0) ", args) + " group by t.sAgentContractNO, t.nGoodsID, p.sPromoTheme, p.sPromoName, p.sPromoPaperNO, p.sPromoActionTypeID, t.sGroupNO";
List<Map<String, Object>> plist = jdbcTemplate.queryForList(sql1);
Map<String, List<Map<String, Object>>> pmm = Util.listToML(plist, ":", "sAgentContractNO", "nGoodsID");
for(String key : mm.keySet()) {
mm.get(key).put("promoList", pmm.get(key));
}
return mm;
}
}
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