zoujiajian há 3 anos atrás
pai
commit
624aa7789f

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mail/MailService.java

@@ -20,5 +20,5 @@ public interface MailService {
 	/**
 	 * 发送课程给用户
 	 */
-	void sendCoursewareByGoodsId(Long goodsId, String goodsTitle, String email) throws Exception;
+	void sendCoursewareByGoodsId(Long goodsId, Long relationId, String goodsTitle, String email) throws Exception;
 }

+ 22 - 10
netflix-service/src/main/java/com/cyksj/service/mail/impl/MailServiceImpl.java

@@ -3,9 +3,12 @@ package com.cyksj.service.mail.impl;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
 import com.cyksj.common.util.StringUtil;
 import com.cyksj.mapper.GoodsCoursewareFileMapper;
+import com.cyksj.mapper.GroupsRelationMapper;
 import com.cyksj.model.entity.GoodsCoursewareFile;
+import com.cyksj.model.entity.GroupsRelation;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.mail.MailService;
 import lombok.RequiredArgsConstructor;
@@ -41,7 +44,11 @@ public class MailServiceImpl implements MailService {
 
 	private final GoodsCoursewareFileMapper coursewareFileMapper;
 
-	private static String IMG_HTML = "<p><img src='%s'></p>";
+	private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
+
+	private final GroupsRelationMapper groupsRelationMapper;
+
+	private static String IMG_HTML = "<p><img src='%s' width=200></p>";
 
 	@Override
 	public String sendLoginCodeEmailToPeople(Integer digit, String toAddress) {
@@ -76,7 +83,7 @@ public class MailServiceImpl implements MailService {
 	}
 
 	@Override
-	public void sendCoursewareByGoodsId(Long goodsId, String goodsTitle, String email) throws Exception {
+	public void sendCoursewareByGoodsId(Long goodsId, Long relationId, String goodsTitle, String email) throws Exception {
 		//获取当前目前下的课程文件
 		MimeMessage msg = mailSender.createMimeMessage();
 		MimeMessageHelper helper = new MimeMessageHelper(msg,true);
@@ -110,14 +117,19 @@ public class MailServiceImpl implements MailService {
 			subject.append("银河录像局AI课程");
 		}
 		helper.setSubject(subject.toString());
-		try {
-			helper.setText(sb.toString(), true);
-			helper.setFrom(from);
-			helper.setTo(email);
-			mailSender.send(msg);
-		} catch (Exception e) {
-			throw BusinessRuntimeException.getInstance("发送课件失败,请联系客服..");
-		}
+		helper.setText(sb.toString(), true);
+		helper.setFrom(from);
+		helper.setTo(email);
+		TASK_EXECUTOR.execute(() -> {
+			try {
+				mailSender.send(msg);
+			} catch (Exception e) {
+				groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
+						.set(GroupsRelation::getAccount, null)
+						.eq(GroupsRelation::getId, relationId)
+						.and(qr -> qr.isNotNull(GroupsRelation::getAccount).or().ne(GroupsRelation::getAccount, StrUtil.EMPTY)));
+			}
+		});
 	}
 
 

+ 2 - 13
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -215,7 +215,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 			throw BusinessRuntimeException.getInstance("");
 		}
 		//是否已发送
-		if (StrUtil.isNotBlank(relation.getAccount())) {
+		if (StrUtil.isNotBlank(relation.getGrAccount())) {
 			throw BusinessRuntimeException.getInstance("已领取课件,请前往邮箱查看");
 		}
 		if (!Validator.isEmail(email)) {
@@ -226,18 +226,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 				.and(qr -> qr.isNull(GroupsRelation::getAccount).or().eq(GroupsRelation::getAccount, StrUtil.EMPTY))
 				.eq(GroupsRelation::getId, relationId));
 		if (update > 0) {
-			TASK_EXECUTOR.execute(() -> {
-				Long goodsId = relation.getGoodsId();
-				Long rid = relationId;
-				try {
-					mailService.sendCoursewareByGoodsId(goodsId, relation.getTitle(), email);
-				} catch (Exception e) {
-					groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
-							.set(GroupsRelation::getAccount, null)
-							.eq(GroupsRelation::getId, rid)
-							.and(qr -> qr.isNotNull(GroupsRelation::getAccount).or().ne(GroupsRelation::getAccount, StrUtil.EMPTY)));
-				}
-			});
+			mailService.sendCoursewareByGoodsId(relation.getGoodsId(), relation.getRelationId(), relation.getTitle(), email);
 		}
 	}
 }