|
@@ -9,6 +9,7 @@ import com.izouma.dingdong.converter.LongArrayConverter;
|
|
|
import com.izouma.dingdong.domain.User;
|
|
import com.izouma.dingdong.domain.User;
|
|
|
import com.izouma.dingdong.domain.Verified;
|
|
import com.izouma.dingdong.domain.Verified;
|
|
|
import com.izouma.dingdong.domain.backstage.Category;
|
|
import com.izouma.dingdong.domain.backstage.Category;
|
|
|
|
|
+import com.izouma.dingdong.domain.merchant.Goods;
|
|
|
import com.izouma.dingdong.domain.merchant.Merchant;
|
|
import com.izouma.dingdong.domain.merchant.Merchant;
|
|
|
import com.izouma.dingdong.domain.merchant.MerchantClassification;
|
|
import com.izouma.dingdong.domain.merchant.MerchantClassification;
|
|
|
import com.izouma.dingdong.domain.merchant.MerchantSettings;
|
|
import com.izouma.dingdong.domain.merchant.MerchantSettings;
|
|
@@ -21,19 +22,20 @@ import com.izouma.dingdong.repo.CouponRepo;
|
|
|
import com.izouma.dingdong.repo.UserRepo;
|
|
import com.izouma.dingdong.repo.UserRepo;
|
|
|
import com.izouma.dingdong.repo.VerifiedRepo;
|
|
import com.izouma.dingdong.repo.VerifiedRepo;
|
|
|
import com.izouma.dingdong.repo.backstage.CategoryRepo;
|
|
import com.izouma.dingdong.repo.backstage.CategoryRepo;
|
|
|
-import com.izouma.dingdong.repo.merchant.FullReductionRepo;
|
|
|
|
|
-import com.izouma.dingdong.repo.merchant.MerchantClassificationRepo;
|
|
|
|
|
-import com.izouma.dingdong.repo.merchant.MerchantRepo;
|
|
|
|
|
-import com.izouma.dingdong.repo.merchant.MerchantSettingsRepo;
|
|
|
|
|
|
|
+import com.izouma.dingdong.repo.merchant.*;
|
|
|
import com.izouma.dingdong.repo.user.UserCouponRepo;
|
|
import com.izouma.dingdong.repo.user.UserCouponRepo;
|
|
|
import com.izouma.dingdong.utils.MapUtils;
|
|
import com.izouma.dingdong.utils.MapUtils;
|
|
|
import com.izouma.dingdong.utils.ObjUtils;
|
|
import com.izouma.dingdong.utils.ObjUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
|
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
@@ -57,6 +59,8 @@ public class MerchantService {
|
|
|
private UserCouponRepo userCouponRepo;
|
|
private UserCouponRepo userCouponRepo;
|
|
|
private CategoryRepo categoryRepo;
|
|
private CategoryRepo categoryRepo;
|
|
|
|
|
|
|
|
|
|
+ private GoodsRepo goodsRepo;
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
商户注册申请
|
|
商户注册申请
|
|
|
*/
|
|
*/
|
|
@@ -256,16 +260,23 @@ public class MerchantService {
|
|
|
* @param latitude 纬度
|
|
* @param latitude 纬度
|
|
|
* @param popularTag 热门标签
|
|
* @param popularTag 热门标签
|
|
|
* @param userId 用户Id
|
|
* @param userId 用户Id
|
|
|
- * @return
|
|
|
|
|
|
|
+ * @return 用户附近的上级列表
|
|
|
*/
|
|
*/
|
|
|
public List<MerchantDTO> showAll(PageQuery pageQuery, Double longitude, Double latitude, String popularTag, Long userId) {
|
|
public List<MerchantDTO> showAll(PageQuery pageQuery, Double longitude, Double latitude, String popularTag, Long userId) {
|
|
|
|
|
|
|
|
- //Specification<Merchant> specification = toSpecification(pageQuery, Merchant.class);
|
|
|
|
|
|
|
+// Specification<Merchant> specification = toSpecification(pageQuery, Merchant.class);
|
|
|
|
|
|
|
|
|
|
+ List<Merchant> merchantList = merchantRepo.findAll(toSpecification(pageQuery, Merchant.class));
|
|
|
|
|
|
|
|
- List<Merchant> merchants = merchantRepo.findAll(toSpecification(pageQuery, Merchant.class));
|
|
|
|
|
|
|
+ List<Goods> goods = goodsRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> criteriaQuery.where(
|
|
|
|
|
+ criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")).getRestriction()
|
|
|
|
|
+ ));
|
|
|
|
|
+ Set<Merchant> merchants = new HashSet<>(merchantList);
|
|
|
|
|
+ goods.forEach(g -> {
|
|
|
|
|
+ merchants.add(merchantRepo.findById(g.getMerchantId()).orElse(null));
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- //所有商家要按距离排序规则
|
|
|
|
|
|
|
+/* //所有商家要按距离排序规则
|
|
|
Map<Merchant, Double> map = new HashMap<>();
|
|
Map<Merchant, Double> map = new HashMap<>();
|
|
|
//算距离
|
|
//算距离
|
|
|
for (Merchant m : merchants) {
|
|
for (Merchant m : merchants) {
|
|
@@ -281,7 +292,10 @@ public class MerchantService {
|
|
|
List<Merchant> mers = new ArrayList<>();
|
|
List<Merchant> mers = new ArrayList<>();
|
|
|
for (Map.Entry<Merchant, Double> m : list) {
|
|
for (Map.Entry<Merchant, Double> m : list) {
|
|
|
mers.add(m.getKey());
|
|
mers.add(m.getKey());
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+ //排序
|
|
|
|
|
+ List<Merchant> mers = this.distanceSorting(merchants, longitude, latitude);
|
|
|
|
|
|
|
|
if (popularTag == null) {
|
|
if (popularTag == null) {
|
|
|
popularTag = pageQuery.getSearch();
|
|
popularTag = pageQuery.getSearch();
|
|
@@ -373,8 +387,8 @@ public class MerchantService {
|
|
|
/*
|
|
/*
|
|
|
距离排序
|
|
距离排序
|
|
|
*/
|
|
*/
|
|
|
- public List<Merchant> distanceSorting(Double longitude, Double latitude) {
|
|
|
|
|
- List<Merchant> merchants = merchantRepo.findAll();
|
|
|
|
|
|
|
+ public List<Merchant> distanceSorting(Set<Merchant> merchants, Double longitude, Double latitude) {
|
|
|
|
|
+ //List<Merchant> merchants = merchantRepo.findAll();
|
|
|
|
|
|
|
|
//所有商家要按距离排序规则
|
|
//所有商家要按距离排序规则
|
|
|
Map<Merchant, Double> map = new HashMap<>();
|
|
Map<Merchant, Double> map = new HashMap<>();
|