diff --git a/src/main/java/com/dl/officialsite/mail/EmailService.java b/src/main/java/com/dl/officialsite/mail/EmailService.java index 92ede1c..6cf213c 100644 --- a/src/main/java/com/dl/officialsite/mail/EmailService.java +++ b/src/main/java/com/dl/officialsite/mail/EmailService.java @@ -9,7 +9,6 @@ import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; -import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.mail.SimpleMailMessage; @@ -19,7 +18,6 @@ @Component -@Slf4j public class EmailService { @@ -62,27 +60,6 @@ public void sendMail(String to, String subject, String text) { emailSender.send(message); } - public void sendMail(List to, String subject, String text, List cc) { - SimpleMailMessage message = new SimpleMailMessage(); - message.setFrom(from); - - // 将 List 转换为 String[] 并设置多个收件人 - message.setTo(to.toArray(new String[0])); - - // 如果 cc 不为空,将其转换为 String[] 并设置多个抄送人 - if (cc != null && !cc.isEmpty()) { - message.setCc(cc.toArray(new String[0])); - } - - message.setSubject(subject); - message.setText(text); - - // 发送邮件 - log.info("Sending email to: {}, tile: {}, content: {}", to, subject, text); - emailSender.send(message); - } - - public void sendMailWithFile(String to, String subject, String text, MultipartFile file) throws Exception { //1.创建一封邮件的实例对象 diff --git a/src/main/java/com/dl/officialsite/redpacket/RedPacketController.java b/src/main/java/com/dl/officialsite/redpacket/RedPacketController.java index a414487..5015978 100644 --- a/src/main/java/com/dl/officialsite/redpacket/RedPacketController.java +++ b/src/main/java/com/dl/officialsite/redpacket/RedPacketController.java @@ -18,7 +18,6 @@ import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.util.ObjectUtils; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -127,9 +126,4 @@ public Predicate toPredicate(Root root, CriteriaQuery criteriaQuer return BaseResponse.successWithData(redPacketRepository.findAll(queryParam, pageable)); } - @GetMapping("/test") - public void test(){ - redPacketService.updateRedpacketStatus(); - } - } diff --git a/src/main/java/com/dl/officialsite/sharing/Share.java b/src/main/java/com/dl/officialsite/sharing/Share.java index 1b40b3f..428d5ea 100644 --- a/src/main/java/com/dl/officialsite/sharing/Share.java +++ b/src/main/java/com/dl/officialsite/sharing/Share.java @@ -154,7 +154,4 @@ public class Share { @Transient private String shareCount; - - @Column(columnDefinition = "MEDIUMTEXT") - private String outline; } diff --git a/src/main/java/com/dl/officialsite/sharing/SharingService.java b/src/main/java/com/dl/officialsite/sharing/SharingService.java index 8b0ada0..5432b39 100644 --- a/src/main/java/com/dl/officialsite/sharing/SharingService.java +++ b/src/main/java/com/dl/officialsite/sharing/SharingService.java @@ -1,5 +1,6 @@ package com.dl.officialsite.sharing; +import cn.hutool.core.lang.Assert; import com.dl.officialsite.bot.constant.BotEnum; import com.dl.officialsite.bot.constant.ChannelEnum; import com.dl.officialsite.bot.event.EventNotify; @@ -20,18 +21,7 @@ import com.dl.officialsite.sharing.model.req.UpdateSharingReq; import com.dl.officialsite.sharing.model.resp.ShareTagResp; import com.dl.officialsite.team.TeamService; -import java.math.BigInteger; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import javax.persistence.criteria.Predicate; -import javax.servlet.http.HttpServletRequest; +import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -42,6 +32,16 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.criteria.Predicate; +import javax.servlet.http.HttpServletRequest; +import java.math.BigInteger; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; import org.springframework.util.StringUtils; @Service @@ -75,66 +75,27 @@ public SharingService(EmailService emailService, ApplicationContext applicationC @Transactional(rollbackFor = Exception.class) public Share createSharing(Share share, String address) { - // 保存分享记录 + /** + * 登陆用户转member + */ +// SessionUserInfo userInfo = HttpSessionUtils.getMember(request.getSession()); +// Preconditions.checkState(userInfo != null, "User info not null"); +// Optional memberOpt = this.memberRepository.findByAddress(userInfo.getAddress()); +// Member member = memberOpt.get(); +// if(member.getId() != req.) share = sharingRepository.save(share); - - // 查找分享创建者的信息 - Member creatorInfo = memberRepository.findByAddress(address) - .orElseThrow(() -> new IllegalArgumentException("Member not found by address: " + address)); - - // 格式化日期 - String formattedDate = formatDate(share.getDate()); - - // 发布事件通知 - publishShareCreationEvent(creatorInfo, share, formattedDate); - - // 准备邮件内容 - String emailTitle = "New Sharing Created"; - String emailContent = createEmailContent(share, creatorInfo); - - // 定义邮件收件人列表 - List toAddressList = Stream.of( - "0xstan.com@gmail.com", "yanyanho126@gmail.com", "longdacao2@gmail.com" - ).collect(Collectors.toList()); - - // 发送邮件 - emailService.sendMail(toAddressList, emailTitle, emailContent, null); - - return share; - } - - private String formatDate(Date date) { - // 格式化日期为字符串 + Member creatorInfo = memberRepository.findByAddress(address).orElse(null); + Assert.isNull(creatorInfo, "not found member by address"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - return format.format(date); - } - - private void publishShareCreationEvent(Member creatorInfo, Share share, String formattedDate) { - // 发布创建分享事件的通知 - applicationContext.publishEvent(new EventNotify( - Member.class, - BotEnum.TELEGRAM, + String formatDate = format.format(share.getDate()); + applicationContext.publishEvent(new EventNotify(Member.class, BotEnum.TELEGRAM, ChannelEnum.SHARING, - NotifyMessageFactory.sharingMessage( - "👏Create New Share👏", - creatorInfo.getNickName(), - share.getTheme(), - formattedDate - ) - )); - } - - private String createEmailContent(Share share, Member creatorInfo) { - // 构造邮件内容 - return String.format( - "Have a new sharing\n👉👉👉Theme: %s👈👈👈\nCreator: %s", - share.getTheme(), - creatorInfo.getNickName() - ); + NotifyMessageFactory.sharingMessage("👏Create New Share👏", creatorInfo.getNickName(), share.getTheme(), + formatDate))); + return share; } - public void updateSharing(UpdateSharingReq req, String address) { //Verify Optional existed = this.sharingRepository.findById(req.getId());