From f2647f2ea68dd811900a398abedd05aaf24518cc Mon Sep 17 00:00:00 2001 From: macro Date: Tue, 16 May 2023 16:50:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0mongo=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84=E6=8E=A7=E5=88=B6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/MemberAttentionServiceImpl.java | 21 +++++++++++++++++++ .../impl/MemberCollectionServiceImpl.java | 20 ++++++++++++++++++ .../impl/MemberReadHistoryServiceImpl.java | 21 +++++++++++++++++++ .../src/main/resources/application-prod.yml | 4 ++++ .../src/main/resources/application.yml | 4 ++++ 5 files changed, 70 insertions(+) diff --git a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberAttentionServiceImpl.java b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberAttentionServiceImpl.java index e58baa1..7ab8e73 100644 --- a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberAttentionServiceImpl.java +++ b/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; } diff --git a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberCollectionServiceImpl.java b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberCollectionServiceImpl.java index 8ee4994..cf11c2f 100644 --- a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberCollectionServiceImpl.java +++ b/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; } diff --git a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberReadHistoryServiceImpl.java b/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberReadHistoryServiceImpl.java index 7b5e884..7b02102 100644 --- a/mall-portal/src/main/java/com/macro/mall/portal/service/impl/MemberReadHistoryServiceImpl.java +++ b/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; } diff --git a/mall-portal/src/main/resources/application-prod.yml b/mall-portal/src/main/resources/application-prod.yml index 32b8d22..0782b34 100644 --- a/mall-portal/src/main/resources/application-prod.yml +++ b/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 diff --git a/mall-portal/src/main/resources/application.yml b/mall-portal/src/main/resources/application.yml index e9c3e4b..2547f1f 100644 --- a/mall-portal/src/main/resources/application.yml +++ b/mall-portal/src/main/resources/application.yml @@ -48,6 +48,10 @@ redis: authCode: 90 # 验证码超期时间 common: 86400 # 24小时 +mongo: + insert: + sqlEnable: true # 用于控制是否通过数据库数据来插入mongo + # 消息队列定义 rabbitmq: queue: