瀏覽代碼

添加mongo插入数据的控制逻辑

macro 1 年之前
父節點
當前提交
f2647f2ea6

+ 21 - 0
mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberAttentionServiceImpl.java

@@ -1,11 +1,15 @@
 package com.macro.mall.portal.service.impl;
 
+import com.macro.mall.mapper.PmsBrandMapper;
+import com.macro.mall.mapper.PmsProductMapper;
+import com.macro.mall.model.PmsBrand;
 import com.macro.mall.model.UmsMember;
 import com.macro.mall.portal.domain.MemberBrandAttention;
 import com.macro.mall.portal.repository.MemberBrandAttentionRepository;
 import com.macro.mall.portal.service.MemberAttentionService;
 import com.macro.mall.portal.service.UmsMemberService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
@@ -19,6 +23,10 @@ import java.util.Date;
  */
 @Service
 public class MemberAttentionServiceImpl implements MemberAttentionService {
+    @Value("${mongo.insert.sqlEnable}")
+    private Boolean sqlEnable;
+    @Autowired
+    private PmsBrandMapper brandMapper;
     @Autowired
     private MemberBrandAttentionRepository memberBrandAttentionRepository;
     @Autowired
@@ -27,6 +35,9 @@ public class MemberAttentionServiceImpl implements MemberAttentionService {
     @Override
     public int add(MemberBrandAttention memberBrandAttention) {
         int count = 0;
+        if(memberBrandAttention.getBrandId()==null){
+            return 0;
+        }
         UmsMember member = memberService.getCurrentMember();
         memberBrandAttention.setMemberId(member.getId());
         memberBrandAttention.setMemberNickname(member.getNickname());
@@ -34,6 +45,16 @@ public class MemberAttentionServiceImpl implements MemberAttentionService {
         memberBrandAttention.setCreateTime(new Date());
         MemberBrandAttention findAttention = memberBrandAttentionRepository.findByMemberIdAndBrandId(memberBrandAttention.getMemberId(), memberBrandAttention.getBrandId());
         if (findAttention == null) {
+            if(sqlEnable){
+                PmsBrand brand = brandMapper.selectByPrimaryKey(memberBrandAttention.getBrandId());
+                if(brand==null){
+                    return 0;
+                }else{
+                    memberBrandAttention.setBrandCity(null);
+                    memberBrandAttention.setBrandName(brand.getName());
+                    memberBrandAttention.setBrandLogo(brand.getLogo());
+                }
+            }
             memberBrandAttentionRepository.save(memberBrandAttention);
             count = 1;
         }

+ 20 - 0
mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberCollectionServiceImpl.java

@@ -1,11 +1,14 @@
 package com.macro.mall.portal.service.impl;
 
+import com.macro.mall.mapper.PmsProductMapper;
+import com.macro.mall.model.PmsProduct;
 import com.macro.mall.model.UmsMember;
 import com.macro.mall.portal.domain.MemberProductCollection;
 import com.macro.mall.portal.repository.MemberProductCollectionRepository;
 import com.macro.mall.portal.service.MemberCollectionService;
 import com.macro.mall.portal.service.UmsMemberService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
@@ -17,6 +20,10 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class MemberCollectionServiceImpl implements MemberCollectionService {
+    @Value("${mongo.insert.sqlEnable}")
+    private Boolean sqlEnable;
+    @Autowired
+    private PmsProductMapper productMapper;
     @Autowired
     private MemberProductCollectionRepository productCollectionRepository;
     @Autowired
@@ -25,12 +32,25 @@ public class MemberCollectionServiceImpl implements MemberCollectionService {
     @Override
     public int add(MemberProductCollection productCollection) {
         int count = 0;
+        if (productCollection.getProductId() == null) {
+            return 0;
+        }
         UmsMember member = memberService.getCurrentMember();
         productCollection.setMemberId(member.getId());
         productCollection.setMemberNickname(member.getNickname());
         productCollection.setMemberIcon(member.getIcon());
         MemberProductCollection findCollection = productCollectionRepository.findByMemberIdAndProductId(productCollection.getMemberId(), productCollection.getProductId());
         if (findCollection == null) {
+            if (sqlEnable) {
+                PmsProduct product = productMapper.selectByPrimaryKey(productCollection.getProductId());
+                if (product == null || product.getDeleteStatus() == 1) {
+                    return 0;
+                }
+                productCollection.setProductName(product.getName());
+                productCollection.setProductSubTitle(product.getSubTitle());
+                productCollection.setProductPrice(product.getPrice() + "");
+                productCollection.setProductPic(product.getPic());
+            }
             productCollectionRepository.save(productCollection);
             count = 1;
         }

+ 21 - 0
mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberReadHistoryServiceImpl.java

@@ -1,11 +1,14 @@
 package com.macro.mall.portal.service.impl;
 
+import com.macro.mall.mapper.PmsProductMapper;
+import com.macro.mall.model.PmsProduct;
 import com.macro.mall.model.UmsMember;
 import com.macro.mall.portal.domain.MemberReadHistory;
 import com.macro.mall.portal.repository.MemberReadHistoryRepository;
 import com.macro.mall.portal.service.MemberReadHistoryService;
 import com.macro.mall.portal.service.UmsMemberService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
@@ -21,18 +24,36 @@ import java.util.List;
  */
 @Service
 public class MemberReadHistoryServiceImpl implements MemberReadHistoryService {
+
+    @Value("${mongo.insert.sqlEnable}")
+    private Boolean sqlEnable;
+    @Autowired
+    private PmsProductMapper productMapper;
     @Autowired
     private MemberReadHistoryRepository memberReadHistoryRepository;
     @Autowired
     private UmsMemberService memberService;
     @Override
     public int create(MemberReadHistory memberReadHistory) {
+        if (memberReadHistory.getProductId() == null) {
+            return 0;
+        }
         UmsMember member = memberService.getCurrentMember();
         memberReadHistory.setMemberId(member.getId());
         memberReadHistory.setMemberNickname(member.getNickname());
         memberReadHistory.setMemberIcon(member.getIcon());
         memberReadHistory.setId(null);
         memberReadHistory.setCreateTime(new Date());
+        if (sqlEnable) {
+            PmsProduct product = productMapper.selectByPrimaryKey(memberReadHistory.getProductId());
+            if (product == null || product.getDeleteStatus() == 1) {
+                return 0;
+            }
+            memberReadHistory.setProductName(product.getName());
+            memberReadHistory.setProductSubTitle(product.getSubTitle());
+            memberReadHistory.setProductPrice(product.getPrice() + "");
+            memberReadHistory.setProductPic(product.getPic());
+        }
         memberReadHistoryRepository.save(memberReadHistory);
         return 1;
     }

+ 4 - 0
mall-portal/src/main/resources/application-prod.yml

@@ -36,6 +36,10 @@ spring:
     username: mall
     password: mall
 
+mongo:
+  insert:
+    sqlEnable: true # 用于控制是否通过数据库数据来插入mongo
+
 logging:
   file:
     path: /var/logs

+ 4 - 0
mall-portal/src/main/resources/application.yml

@@ -48,6 +48,10 @@ redis:
     authCode: 90 # 验证码超期时间
     common: 86400 # 24小时
 
+mongo:
+  insert:
+    sqlEnable: true # 用于控制是否通过数据库数据来插入mongo
+
 # 消息队列定义
 rabbitmq:
   queue: