huodongdong 7 years ago
parent
commit
5a764d1100

+ 1 - 1
rankin-data-api/src/main/java/cn/rankin/data/api/product/entity/Tag.java

@@ -52,6 +52,6 @@ public class Tag implements Serializable {
     private String groupName;
 
     @Transient
-    private List<MerchantProduct> products;
+    private List<MerchantProduct> productList;
 
 }

+ 1 - 1
rankin-data-api/src/main/java/cn/rankin/data/api/product/vo/TagVo.java

@@ -31,5 +31,5 @@ public class TagVo implements Serializable {
 
     private BaseStatusEnum status;
 
-    private List<MerchantProduct> products;
+    private List<MerchantProduct> productList;
 }

+ 7 - 1
rankin-product-service/src/main/java/cn/rankin/productservice/repository/ProductTagRelationRepository.java

@@ -1,5 +1,6 @@
 package cn.rankin.productservice.repository;
 
+import cn.rankin.common.utils.enums.BaseStatusEnum;
 import cn.rankin.common.utils.jpa.BasicJpaRepository;
 import cn.rankin.data.api.product.entity.MerchantProductTagRelation;
 import org.springframework.data.jpa.repository.Modifying;
@@ -10,6 +11,9 @@ import java.util.List;
 
 public interface ProductTagRelationRepository extends BasicJpaRepository<MerchantProductTagRelation, String> {
 
+    @Query(value = "select p from MerchantProductTagRelation p where p.tagId = ?1 and p.status = ?2 order by p.sort")
+    List<MerchantProductTagRelation> findByTagId(String tagId, BaseStatusEnum status);
+
     List<MerchantProductTagRelation> findByTagId(String tagId);
 
     List<MerchantProductTagRelation> findByTagIdIn(List<String> tagIds);
@@ -17,7 +21,9 @@ public interface ProductTagRelationRepository extends BasicJpaRepository<Merchan
     @Query(value = "select p from MerchantProductTagRelation p where p.pid in (?1) and p.merchantId in (?2) and p.status = 0")
     List<MerchantProductTagRelation> findByPidsAndMerchantIds(List<String> pids, List<String> merchantIds);
 
-    @Query(value = "select r from MerchantProductTagRelation r where r.pid = ?1 and r.merchantId = ?2 and r.status = 0")
+    @Query(value = "select r from MerchantProductTagRelation r where r.pid = ?1 and r.merchantId = ?2 and r.status = ?3")
+    List<MerchantProductTagRelation> findByPidAndMerchantId(String pid, String merchantId, BaseStatusEnum status);
+
     List<MerchantProductTagRelation> findByPidAndMerchantId(String pid, String merchantId);
 
     @Modifying

+ 1 - 0
rankin-product-service/src/main/java/cn/rankin/productservice/repository/TagRepository.java

@@ -10,6 +10,7 @@ import java.util.List;
 
 public interface TagRepository extends BasicJpaRepository<Tag, String> {
 
+    @Query(value = "select t from Tag t where t.groupId = ?1 order by t.sort")
     List<Tag> findByGroupId(String groupId);
 
     @Query(value = "select t from Tag t where t.id in (?1) and t.status = ?2")

+ 5 - 1
rankin-product-service/src/main/java/cn/rankin/productservice/service/MerchantProductTagRelationService.java

@@ -23,13 +23,17 @@ public class MerchantProductTagRelationService {
         return relationRepository.findByTagId(tagId);
     }
 
+    public List<MerchantProductTagRelation> findByTagId(String tagId, BaseStatusEnum status) {
+        return relationRepository.findByTagId(tagId, status);
+    }
+
     public List<MerchantProductTagRelation> findByPidsAndMerchantIds(List<String> pids, List<String> merchantIds) {
         List<MerchantProductTagRelation> merchantProductTagRelationList = relationRepository.findByPidsAndMerchantIds(pids, merchantIds);
         return merchantProductTagRelationList;
     }
 
     public List<MerchantProductTagRelation> findByPidAndMerchantId(String pid, String merchantId) {
-        return relationRepository.findByPidAndMerchantId(pid, merchantId);
+        return relationRepository.findByPidAndMerchantId(pid, merchantId, BaseStatusEnum.NORMAL);
     }
 
     @Transactional

+ 15 - 5
rankin-product-service/src/main/java/cn/rankin/productservice/service/TagService.java

@@ -73,14 +73,24 @@ public class TagService {
     }
 
     public List<MerchantProduct> getMerchantProductList(String tagId, String merchantId) {
-        List<MerchantProductTagRelation> relationList = merchantProductTagRelationService.findByTagId(tagId);
+        List<MerchantProductTagRelation> relationList = merchantProductTagRelationService.findByTagId(tagId, BaseStatusEnum.NORMAL);
         if (CollectionUtils.isEmpty(relationList)) {
             return new ArrayList<>();
         }
 
         List<String> productIdList = new ArrayList<>();
         relationList.forEach(relation -> productIdList.add(relation.getPid()));
-        return merchantProductRepository.findByPidsAndMerchantId(productIdList, merchantId);
+        List<MerchantProduct> merchantProductList = merchantProductRepository.findByPidsAndMerchantId(productIdList, merchantId);
+        Map<String, MerchantProduct> merchantProductMap = ListUtil.convert(merchantProductList, "pid", MerchantProduct.class);
+
+        List<MerchantProduct> sortMerchantProductList = new ArrayList<>();
+        for (String productId : productIdList) {
+            MerchantProduct merchantProduct = merchantProductMap.get(productId);
+            if (merchantProduct != null) {
+                sortMerchantProductList.add(merchantProduct);
+            }
+        }
+        return sortMerchantProductList;
     }
 
     // 搜索标签
@@ -104,7 +114,7 @@ public class TagService {
         String merchantId = tag.getMerchantId();
 
         List<MerchantProduct> merchantProductList = getMerchantProductList(tagId, merchantId);
-        tag.setProducts(merchantProductList);
+        tag.setProductList(merchantProductList);
         return APIResult.ok(tag);
     }
 
@@ -127,7 +137,7 @@ public class TagService {
         merchantProductTagRelationService.updateByTagId(tagId, merchantId, productIdList);
 
         List<MerchantProduct> merchantProductList = getMerchantProductList(tagId, merchantId);
-        tag.setProducts(merchantProductList);
+        tag.setProductList(merchantProductList);
 
         return APIResult.ok(tag);
     }
@@ -143,7 +153,7 @@ public class TagService {
         merchantProductTagRelationService.updateByTagId(tagId, merchantId, productIdList);
 
         List<MerchantProduct> merchantProductList = getMerchantProductList(tagId, merchantId);
-        tag.setProducts(merchantProductList);
+        tag.setProductList(merchantProductList);
 
         return APIResult.ok(tag);
     }

+ 16 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/service/CollectionService.java

@@ -1,5 +1,9 @@
 package cn.rankin.userservice.service;
 
+import cn.rankin.common.utils.api.model.APIResult;
+import cn.rankin.common.utils.api.page.Page;
+import cn.rankin.data.api.user.dto.CollectionDTO;
+import cn.rankin.data.api.user.entity.Collection;
 import cn.rankin.userservice.repository.CollectionRepository;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -11,4 +15,16 @@ public class CollectionService {
 
     @Autowired
     private CollectionRepository collectionRepository;
+
+    public APIResult<Boolean> put(CollectionDTO collectionDTO) {
+        return null;
+    }
+
+    public APIResult<Page<Collection>> getCollections(String userId, Integer start, Integer size) {
+        return null;
+    }
+
+    public APIResult<Boolean> delete(String userId, String productId) {
+        return null;
+    }
 }

+ 1 - 1
rankin-user-service/src/main/java/cn/rankin/userservice/service/PayingService.java

@@ -44,7 +44,7 @@ public class PayingService {
         }
 
         // 插入流水
-        ledgerService.insert(merchantId, quantity.negate(), merchant.getBalance(), type, receiptId, note);
+        ledgerService.insert(merchantId, quantity, merchant.getBalance(), type, receiptId, note);
 
         return APIResult.ok();
     }

+ 3 - 0
rankin-user-service/src/main/java/cn/rankin/userservice/utils/DTOConverter.java

@@ -12,11 +12,14 @@ import cn.rankin.data.api.user.entity.Merchant;
 import cn.rankin.data.api.user.entity.TerminalUser;
 import org.springframework.beans.BeanUtils;
 
+import java.math.BigDecimal;
+
 public class DTOConverter {
 
     public static Merchant convert(MerchantDTO merchantDTO) {
         Merchant merchant = new Merchant();
         BeanUtils.copyProperties(merchantDTO, merchant);
+        merchant.setBalance(BigDecimal.ZERO);
         return merchant;
     }