|
@@ -1,12 +1,14 @@
|
|
|
package com.sqx.modules.goods.service.impl;
|
|
package com.sqx.modules.goods.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.sqx.common.exception.SqxException;
|
|
|
import com.sqx.common.utils.PageUtils;
|
|
import com.sqx.common.utils.PageUtils;
|
|
|
import com.sqx.common.utils.Result;
|
|
import com.sqx.common.utils.Result;
|
|
|
import com.sqx.modules.activity.service.ActivityShopService;
|
|
import com.sqx.modules.activity.service.ActivityShopService;
|
|
@@ -20,8 +22,18 @@ import com.sqx.modules.goods.dao.GoodsDao;
|
|
|
import com.sqx.modules.goods.dao.GoodsShopDao;
|
|
import com.sqx.modules.goods.dao.GoodsShopDao;
|
|
|
import com.sqx.modules.goods.dao.GoodsShopRelevancyDao;
|
|
import com.sqx.modules.goods.dao.GoodsShopRelevancyDao;
|
|
|
import com.sqx.modules.goods.dao.GoodsSkuDao;
|
|
import com.sqx.modules.goods.dao.GoodsSkuDao;
|
|
|
-import com.sqx.modules.goods.entity.*;
|
|
|
|
|
-import com.sqx.modules.goods.service.*;
|
|
|
|
|
|
|
+import com.sqx.modules.goods.dto.ShopQueryDTO;
|
|
|
|
|
+import com.sqx.modules.goods.entity.Goods;
|
|
|
|
|
+import com.sqx.modules.goods.entity.GoodsAttr;
|
|
|
|
|
+import com.sqx.modules.goods.entity.GoodsAttrValue;
|
|
|
|
|
+import com.sqx.modules.goods.entity.GoodsClassify;
|
|
|
|
|
+import com.sqx.modules.goods.entity.GoodsShop;
|
|
|
|
|
+import com.sqx.modules.goods.entity.GoodsShopRelevancy;
|
|
|
|
|
+import com.sqx.modules.goods.entity.GoodsSku;
|
|
|
|
|
+import com.sqx.modules.goods.service.GoodsAttrService;
|
|
|
|
|
+import com.sqx.modules.goods.service.GoodsAttrValueService;
|
|
|
|
|
+import com.sqx.modules.goods.service.GoodsService;
|
|
|
|
|
+import com.sqx.modules.goods.service.GoodsSkuService;
|
|
|
import com.sqx.modules.goods.utils.SkuUtil;
|
|
import com.sqx.modules.goods.utils.SkuUtil;
|
|
|
import com.sqx.modules.order.entity.Evaluate;
|
|
import com.sqx.modules.order.entity.Evaluate;
|
|
|
import com.sqx.modules.shop.dao.ShopMessageDao;
|
|
import com.sqx.modules.shop.dao.ShopMessageDao;
|
|
@@ -35,7 +47,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -486,65 +502,29 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsDao, Goods> implements Go
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public Result selectShop(Integer page, Integer limit, Integer screen, Integer shopTypeId, Double lng, Double lat, String impotr, Long activityId) {
|
|
|
|
|
|
|
+ public Result selectShop(ShopQueryDTO queryDTO) {
|
|
|
//如果没有经纬度,则默认为北京的经纬度
|
|
//如果没有经纬度,则默认为北京的经纬度
|
|
|
|
|
+ Double lat = queryDTO.getLat();
|
|
|
|
|
+ Double lng = queryDTO.getLng();
|
|
|
if (lng == null || lat == null || lng == 0 || lat == 0) {
|
|
if (lng == null || lat == null || lng == 0 || lat == 0) {
|
|
|
-// lng = 108.8927;
|
|
|
|
|
-// lat = 34.2408;
|
|
|
|
|
lng = 121.47;
|
|
lng = 121.47;
|
|
|
lat = 31.23;
|
|
lat = 31.23;
|
|
|
}
|
|
}
|
|
|
- Page<GoodsShop> pages = new Page<>(page, limit);
|
|
|
|
|
- String way = commonInfoService.findOne(416).getValue();
|
|
|
|
|
- String city;
|
|
|
|
|
- if ("1".equals(way)) {
|
|
|
|
|
- CommonInfo one = commonInfoService.findOne(235);
|
|
|
|
|
- String url = "https://apis.map.qq.com/ws/geocoder/v1/";
|
|
|
|
|
- Map<String, String> maps = new HashMap<>();
|
|
|
|
|
- maps.put("location", lat + "," + lng);
|
|
|
|
|
- maps.put("key", one.getValue());
|
|
|
|
|
- String data = HttpClientUtil.doGet(url, maps);
|
|
|
|
|
- JSONObject jsonObject = JSON.parseObject(data);
|
|
|
|
|
- String status = jsonObject.getString("status");
|
|
|
|
|
- if ("0".equals(status)) {
|
|
|
|
|
- JSONObject result = jsonObject.getJSONObject("result");
|
|
|
|
|
- JSONObject adInfo = result.getJSONObject("ad_info");
|
|
|
|
|
- city = adInfo.getString("city");
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("转换失败!!!原因:" + jsonObject.getString("message"));
|
|
|
|
|
- return Result.error("获取定位失败!");
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- String value = commonInfoService.findOne(417).getValue();
|
|
|
|
|
- String url = "http://api.tianditu.gov.cn/geocoder";
|
|
|
|
|
- Map<String, String> param = new HashMap<>();
|
|
|
|
|
- JSONObject postStr = new JSONObject();
|
|
|
|
|
- postStr.put("lon", lng);
|
|
|
|
|
- postStr.put("lat", lat);
|
|
|
|
|
- postStr.put("ver", "1");
|
|
|
|
|
- param.put("postStr", postStr.toJSONString());
|
|
|
|
|
- param.put("type", "geocode");
|
|
|
|
|
- param.put("tk", value);
|
|
|
|
|
- String s = HttpClientUtil.doGet(url, param);
|
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
- String status = jsonObject.getString("status");
|
|
|
|
|
- if ("0".equals(status)) {
|
|
|
|
|
- JSONObject result = jsonObject.getJSONObject("result");
|
|
|
|
|
- JSONObject addressComponent = result.getJSONObject("addressComponent");
|
|
|
|
|
- city = addressComponent.getString("city");
|
|
|
|
|
- } else {
|
|
|
|
|
- return Result.error("获取定位失败!");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Page<GoodsShop> pages = new Page<>(queryDTO.getPage(), queryDTO.getLimit());
|
|
|
|
|
+
|
|
|
|
|
+ String city = queryDTO.getCity();
|
|
|
|
|
+ if (StrUtil.isBlank(city)) {
|
|
|
|
|
+ city = getCity(lat, lng);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- IPage<GoodsShop> goodsShopIPage = goodsShopDao.selectShop(pages, screen, shopTypeId, lng, lat, city, impotr, activityId);
|
|
|
|
|
|
|
+ IPage<GoodsShop> goodsShopIPage = goodsShopDao.selectShop(pages, queryDTO.getScreen(), queryDTO.getShopTypeId(), lng, lat, city, queryDTO.getImpotr(), queryDTO.getActivityId());
|
|
|
List<GoodsShop> records = goodsShopIPage.getRecords();
|
|
List<GoodsShop> records = goodsShopIPage.getRecords();
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(records)) {
|
|
if (CollUtil.isNotEmpty(records)) {
|
|
|
CommonInfo one1 = commonInfoService.findOne(292);
|
|
CommonInfo one1 = commonInfoService.findOne(292);
|
|
|
CommonInfo one2 = commonInfoService.findOne(293);
|
|
CommonInfo one2 = commonInfoService.findOne(293);
|
|
|
List<Long> shopIdList = records.stream().map(GoodsShop::getShopId).collect(Collectors.toList());
|
|
List<Long> shopIdList = records.stream().map(GoodsShop::getShopId).collect(Collectors.toList());
|
|
|
- List<Goods> goodsList = goodsDao.selectGoodsBySalesAndGoodsNameAndShopIds(shopIdList, impotr);
|
|
|
|
|
|
|
+ List<Goods> goodsList = goodsDao.selectGoodsBySalesAndGoodsNameAndShopIds(shopIdList, queryDTO.getImpotr());
|
|
|
Map<Long, List<Goods>> goodsMap = goodsList.stream().collect(Collectors.groupingBy(Goods::getShopId));
|
|
Map<Long, List<Goods>> goodsMap = goodsList.stream().collect(Collectors.groupingBy(Goods::getShopId));
|
|
|
|
|
|
|
|
List<TbCoupon> tbCoupons = tbCouponDao.selectCouponListByShopIdList(shopIdList, null);
|
|
List<TbCoupon> tbCoupons = tbCouponDao.selectCouponListByShopIdList(shopIdList, null);
|
|
@@ -562,7 +542,7 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsDao, Goods> implements Go
|
|
|
// 设置活动信息
|
|
// 设置活动信息
|
|
|
goodsShop.setShopActivityList(shopActivityMap.get(shopId));
|
|
goodsShop.setShopActivityList(shopActivityMap.get(shopId));
|
|
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(impotr)) {
|
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(queryDTO.getImpotr())) {
|
|
|
goodsShop.setGoodsList(goodsMap.get(shopId));
|
|
goodsShop.setGoodsList(goodsMap.get(shopId));
|
|
|
} else {
|
|
} else {
|
|
|
goodsShop.setGoodsList(new ArrayList<>());
|
|
goodsShop.setGoodsList(new ArrayList<>());
|
|
@@ -580,6 +560,57 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsDao, Goods> implements Go
|
|
|
return Result.success().put("data", pageUtils);
|
|
return Result.success().put("data", pageUtils);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据经纬度查询城市
|
|
|
|
|
+ * @param lat lat
|
|
|
|
|
+ * @param lng lng
|
|
|
|
|
+ * @return 城市
|
|
|
|
|
+ */
|
|
|
|
|
+ private String getCity(double lat, double lng) {
|
|
|
|
|
+ String way = commonInfoService.findOne(416).getValue();
|
|
|
|
|
+ String city;
|
|
|
|
|
+ if ("1".equals(way)) {
|
|
|
|
|
+ CommonInfo one = commonInfoService.findOne(235);
|
|
|
|
|
+ String url = "https://apis.map.qq.com/ws/geocoder/v1/";
|
|
|
|
|
+ Map<String, String> maps = new HashMap<>();
|
|
|
|
|
+ maps.put("location", lat + "," + lng);
|
|
|
|
|
+ maps.put("key", one.getValue());
|
|
|
|
|
+ String data = HttpClientUtil.doGet(url, maps);
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(data);
|
|
|
|
|
+ String status = jsonObject.getString("status");
|
|
|
|
|
+ if ("0".equals(status)) {
|
|
|
|
|
+ JSONObject result = jsonObject.getJSONObject("result");
|
|
|
|
|
+ JSONObject adInfo = result.getJSONObject("ad_info");
|
|
|
|
|
+ city = adInfo.getString("city");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new SqxException("获取地址失败,原因:" + jsonObject.getString("message"));
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ String value = commonInfoService.findOne(417).getValue();
|
|
|
|
|
+ String url = "http://api.tianditu.gov.cn/geocoder";
|
|
|
|
|
+ Map<String, String> param = new HashMap<>();
|
|
|
|
|
+ JSONObject postStr = new JSONObject();
|
|
|
|
|
+ postStr.put("lon", lng);
|
|
|
|
|
+ postStr.put("lat", lat);
|
|
|
|
|
+ postStr.put("ver", "1");
|
|
|
|
|
+ param.put("postStr", postStr.toJSONString());
|
|
|
|
|
+ param.put("type", "geocode");
|
|
|
|
|
+ param.put("tk", value);
|
|
|
|
|
+ String s = HttpClientUtil.doGet(url, param);
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
+ String status = jsonObject.getString("status");
|
|
|
|
|
+ if ("0".equals(status)) {
|
|
|
|
|
+ JSONObject result = jsonObject.getJSONObject("result");
|
|
|
|
|
+ JSONObject addressComponent = result.getJSONObject("addressComponent");
|
|
|
|
|
+ city = addressComponent.getString("city");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new SqxException("获取定位失败!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return city;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Result selectSearch(Integer page, Integer limit, String impotr, Double lng, Double lat) {
|
|
public Result selectSearch(Integer page, Integer limit, String impotr, Double lng, Double lat) {
|
|
|
Page<GoodsShop> pages = new Page<>(page, limit);
|
|
Page<GoodsShop> pages = new Page<>(page, limit);
|