update 在离线和验证码邮件发送改为html
This commit is contained in:
@@ -3,6 +3,7 @@ package com.m2pool.system.api;
|
|||||||
import com.m2pool.common.core.Result.R;
|
import com.m2pool.common.core.Result.R;
|
||||||
import com.m2pool.common.core.constant.ServiceNameConstants;
|
import com.m2pool.common.core.constant.ServiceNameConstants;
|
||||||
import com.m2pool.system.api.entity.EmailEntity;
|
import com.m2pool.system.api.entity.EmailEntity;
|
||||||
|
import com.m2pool.system.api.entity.EmailTemplateEntity;
|
||||||
import com.m2pool.system.api.entity.GetEmailCodeEntity;
|
import com.m2pool.system.api.entity.GetEmailCodeEntity;
|
||||||
import com.m2pool.system.api.factory.RemoteMailFallbackFactory;
|
import com.m2pool.system.api.factory.RemoteMailFallbackFactory;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
@@ -32,5 +33,14 @@ public interface RemoteMailService
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/sendTextMail")
|
@PostMapping("/sendTextMail")
|
||||||
public R<?> sendTextMail(@RequestBody EmailEntity entity);
|
public R<?> sendTextMail(@RequestBody EmailEntity entity);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送html邮件
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@PostMapping("/sendHtmlMailMessage")
|
||||||
|
public R<?> sendHtmlMailMessage(@RequestBody EmailTemplateEntity entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.m2pool.system.api.factory;
|
|||||||
import com.m2pool.common.core.Result.R;
|
import com.m2pool.common.core.Result.R;
|
||||||
import com.m2pool.system.api.RemoteMailService;
|
import com.m2pool.system.api.RemoteMailService;
|
||||||
import com.m2pool.system.api.entity.EmailEntity;
|
import com.m2pool.system.api.entity.EmailEntity;
|
||||||
|
import com.m2pool.system.api.entity.EmailTemplateEntity;
|
||||||
import com.m2pool.system.api.entity.GetEmailCodeEntity;
|
import com.m2pool.system.api.entity.GetEmailCodeEntity;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -35,6 +36,11 @@ public class RemoteMailFallbackFactory implements FallbackFactory<RemoteMailServ
|
|||||||
return R.fail("邮箱发送失败:" + cause.getMessage());
|
return R.fail("邮箱发送失败:" + cause.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public R<?> sendHtmlMailMessage(@RequestBody EmailTemplateEntity entity) {
|
||||||
|
return R.fail("邮箱发送失败:" + cause.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,18 @@
|
|||||||
<artifactId>common-security</artifactId>
|
<artifactId>common-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Thymeleaf 用于发送邮箱 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct</artifactId>
|
||||||
|
<version>1.5.0.RC1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -6,12 +6,11 @@ import com.m2pool.auth.service.impl.MaliServiceImpl;
|
|||||||
import com.m2pool.common.core.Result.R;
|
import com.m2pool.common.core.Result.R;
|
||||||
import com.m2pool.common.core.utils.JwtUtils;
|
import com.m2pool.common.core.utils.JwtUtils;
|
||||||
import com.m2pool.common.core.utils.StringUtils;
|
import com.m2pool.common.core.utils.StringUtils;
|
||||||
import com.m2pool.common.core.web.Result.AjaxResult;
|
|
||||||
import com.m2pool.common.security.annotation.RequiresLogin;
|
import com.m2pool.common.security.annotation.RequiresLogin;
|
||||||
import com.m2pool.common.security.auth.AuthUtil;
|
import com.m2pool.common.security.auth.AuthUtil;
|
||||||
import com.m2pool.common.security.service.TokenService;
|
import com.m2pool.common.security.service.TokenService;
|
||||||
import com.m2pool.common.security.utils.SecurityUtils;
|
import com.m2pool.common.security.utils.SecurityUtils;
|
||||||
import com.m2pool.system.api.entity.SysUser;
|
import com.m2pool.system.api.entity.EmailTemplateEntity;
|
||||||
import com.m2pool.system.api.model.LoginUser;
|
import com.m2pool.system.api.model.LoginUser;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@@ -163,4 +162,13 @@ public class TokenController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("sendHtmlMailMessage")
|
||||||
|
public R<?> sendHtmlMailMessage(@Valid @RequestBody EmailTemplateEntity entity)
|
||||||
|
{
|
||||||
|
maliService.sendHtmlMailMessage(entity);
|
||||||
|
return R.success("邮件已发送");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.m2pool.auth.service;
|
|||||||
import com.m2pool.auth.entity.GetEmailCodeEntity;
|
import com.m2pool.auth.entity.GetEmailCodeEntity;
|
||||||
import com.m2pool.auth.entity.GetLoginEmailCodeEntity;
|
import com.m2pool.auth.entity.GetLoginEmailCodeEntity;
|
||||||
import com.m2pool.common.core.Result.R;
|
import com.m2pool.common.core.Result.R;
|
||||||
|
import com.m2pool.system.api.entity.EmailTemplateEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description TODO
|
* @Description TODO
|
||||||
@@ -19,12 +20,9 @@ public interface MailService {
|
|||||||
public void sendTextMailMessage(String to,String subject,String text);
|
public void sendTextMailMessage(String to,String subject,String text);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送html邮件
|
* 发送矿机离线数 html邮件
|
||||||
* @param to
|
|
||||||
* @param subject
|
|
||||||
* @param content
|
|
||||||
*/
|
*/
|
||||||
public void sendHtmlMailMessage(String to,String subject,String content);
|
public void sendHtmlMailMessage(EmailTemplateEntity entity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送带附件的邮件
|
* 发送带附件的邮件
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import com.m2pool.auth.service.MailService;
|
|||||||
import com.m2pool.common.core.RedisTransKey;
|
import com.m2pool.common.core.RedisTransKey;
|
||||||
import com.m2pool.common.core.Result.R;
|
import com.m2pool.common.core.Result.R;
|
||||||
import com.m2pool.common.core.constant.SecurityConstants;
|
import com.m2pool.common.core.constant.SecurityConstants;
|
||||||
import com.m2pool.common.core.exception.ServiceException;
|
|
||||||
import com.m2pool.common.core.utils.CodeUtils;
|
import com.m2pool.common.core.utils.CodeUtils;
|
||||||
import com.m2pool.common.core.utils.StringUtils;
|
import com.m2pool.common.core.utils.StringUtils;
|
||||||
import com.m2pool.common.redis.service.RedisService;
|
import com.m2pool.common.redis.service.RedisService;
|
||||||
import com.m2pool.common.security.utils.SecurityUtils;
|
import com.m2pool.common.security.utils.SecurityUtils;
|
||||||
import com.m2pool.system.api.RemoteUserService;
|
import com.m2pool.system.api.RemoteUserService;
|
||||||
|
import com.m2pool.system.api.entity.EmailTemplateEntity;
|
||||||
import com.m2pool.system.api.model.LoginUser;
|
import com.m2pool.system.api.model.LoginUser;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -21,9 +21,15 @@ import org.springframework.core.io.FileSystemResource;
|
|||||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.thymeleaf.TemplateEngine;
|
||||||
|
import org.thymeleaf.context.Context;
|
||||||
|
|
||||||
|
import javax.mail.MessagingException;
|
||||||
|
import javax.mail.internet.MimeMessage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,12 +48,19 @@ public class MaliServiceImpl implements MailService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RemoteUserService remoteUserService;
|
private RemoteUserService remoteUserService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TemplateEngine templateEngine;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
@Value("${spring.mail.username}")
|
@Value("${spring.mail.username}")
|
||||||
private String sendMailer;
|
private String sendMailer;
|
||||||
|
|
||||||
|
|
||||||
|
@Value("${image.prefix}")
|
||||||
|
private String imagePrefix;
|
||||||
|
|
||||||
public static String EMAIL_REGEX="^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
|
public static String EMAIL_REGEX="^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,42 +116,52 @@ public class MaliServiceImpl implements MailService {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送html邮件
|
* 发送HTML邮件
|
||||||
* @param to
|
* @param to
|
||||||
* @param subject
|
* @param subject
|
||||||
* @param content
|
* @param templateName 模版名
|
||||||
|
* @param variables 需要映射到html上的动态内容
|
||||||
|
* @throws MessagingException
|
||||||
*/
|
*/
|
||||||
|
public void sendHtmlEmail(String to, String subject, String templateName, Map<String, Object> variables) throws MessagingException {
|
||||||
|
// 创建 MimeMessage 对象
|
||||||
|
MimeMessage message = javaMailSender.createMimeMessage();
|
||||||
|
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||||
|
|
||||||
|
|
||||||
|
//邮件发信人
|
||||||
|
helper.setFrom(sendMailer);
|
||||||
|
|
||||||
|
// 收件人一个活多个
|
||||||
|
helper.setTo(to.split(","));
|
||||||
|
helper.setSubject(subject);
|
||||||
|
|
||||||
|
// 创建 Thymeleaf 上下文并添加变量
|
||||||
|
Context context = new Context();
|
||||||
|
//设置图片访问前缀
|
||||||
|
variables.put("imagePrefix", imagePrefix);
|
||||||
|
context.setVariables(variables);
|
||||||
|
|
||||||
|
// 处理 HTML 模板
|
||||||
|
String htmlContent = templateEngine.process(templateName, context);
|
||||||
|
|
||||||
|
// 设置邮件内容为 HTML
|
||||||
|
helper.setText(htmlContent, true);
|
||||||
|
|
||||||
|
//邮件发送时间
|
||||||
|
helper.setSentDate(new Date());
|
||||||
|
|
||||||
|
// 发送邮件
|
||||||
|
javaMailSender.send(message);
|
||||||
|
System.out.println("发送邮件成功:"+sendMailer+"->"+to);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendHtmlMailMessage(String to,String subject,String content){
|
public void sendHtmlMailMessage(EmailTemplateEntity entity){
|
||||||
|
|
||||||
content="<!DOCTYPE html>\n" +
|
|
||||||
"<html>\n" +
|
|
||||||
"<head>\n" +
|
|
||||||
"<meta charset=\"utf-8\">\n" +
|
|
||||||
"<title>邮件</title>\n" +
|
|
||||||
"</head>\n" +
|
|
||||||
"<body>\n" +
|
|
||||||
"\t<h3>这是一封HTML邮件!</h3>\n" +
|
|
||||||
"</body>\n" +
|
|
||||||
"</html>";
|
|
||||||
try {
|
try {
|
||||||
//true 代表支持复杂的类型
|
sendHtmlEmail(entity.getEmail(),entity.getSubject(),entity.getTemplateName(),entity.getData());
|
||||||
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(javaMailSender.createMimeMessage(),true);
|
|
||||||
//邮件发信人
|
|
||||||
mimeMessageHelper.setFrom(sendMailer);
|
|
||||||
//邮件收信人 1或多个
|
|
||||||
mimeMessageHelper.setTo(to.split(","));
|
|
||||||
//邮件主题
|
|
||||||
mimeMessageHelper.setSubject(subject);
|
|
||||||
//邮件内容 true 代表支持html
|
|
||||||
mimeMessageHelper.setText(content,true);
|
|
||||||
//邮件发送时间
|
|
||||||
mimeMessageHelper.setSentDate(new Date());
|
|
||||||
|
|
||||||
//发送邮件
|
|
||||||
javaMailSender.send(mimeMessageHelper.getMimeMessage());
|
|
||||||
System.out.println("发送邮件成功:"+sendMailer+"->"+to);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println("发送邮件失败:"+e.getMessage());
|
System.out.println("发送邮件失败:"+e.getMessage());
|
||||||
@@ -189,9 +212,13 @@ public class MaliServiceImpl implements MailService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void sendCodeMailMessage(String to, String code) {
|
public void sendCodeMailMessage(String to, String code) {
|
||||||
String subject = "账号注册,邮箱验证码";
|
//String subject = "账号注册,邮箱验证码";
|
||||||
String text = "注册验证码10分钟内有效:\n\t"+code;
|
//String text = "注册验证码10分钟内有效:\n\t"+code;
|
||||||
sendTextMailMessage(to,subject,text);
|
Map<String, Object> content = new HashMap<>();
|
||||||
|
content.put("code",code);
|
||||||
|
content.put("text","The verification code for registration is valid for 10 minutes");
|
||||||
|
EmailTemplateEntity message = new EmailTemplateEntity(to,"Account registration, email verification code","emailCode-en",content);
|
||||||
|
sendHtmlMailMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -201,25 +228,39 @@ public class MaliServiceImpl implements MailService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void sendLoginCodeMailMessage(String to, String code) {
|
public void sendLoginCodeMailMessage(String to, String code) {
|
||||||
String subject = "用户登录,邮箱验证码";
|
//String subject = "用户登录,邮箱验证码";
|
||||||
String text = "登录验证码10分钟内有效:\n\t"+code;
|
//String text = "登录验证码10分钟内有效:\n\t"+code;
|
||||||
sendTextMailMessage(to,subject,text);
|
Map<String, Object> content = new HashMap<>();
|
||||||
|
content.put("code",code);
|
||||||
|
content.put("text","Login verification code is valid within 10 minutes");
|
||||||
|
EmailTemplateEntity entity = new EmailTemplateEntity(to,"User login, email verification code","emailCode-en",content);
|
||||||
|
sendHtmlMailMessage(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendResetPwdMailMessage(String to, String code) {
|
public void sendResetPwdMailMessage(String to, String code) {
|
||||||
String subject = "账号重置密码,邮箱验证码";
|
//String subject = "账号重置密码,邮箱验证码";
|
||||||
String text = "您正在重置密码,如果不是您本人操作,请忽略。验证码10分钟内有效:\n\t"+code;
|
//String text = "您正在重置密码,如果不是您本人操作,请忽略。验证码10分钟内有效:\n\t"+code;
|
||||||
sendTextMailMessage(to,subject,text);
|
|
||||||
|
Map<String, Object> content = new HashMap<>();
|
||||||
|
content.put("code",code);
|
||||||
|
content.put("text","You are resetting your password. If this is not done by you, please ignore it. The verification code is valid for 10 minutes.");
|
||||||
|
EmailTemplateEntity entity = new EmailTemplateEntity(to,"Reset account password, email verification code","emailCode-en",content);
|
||||||
|
sendHtmlMailMessage(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendUpdatePwdMailMessage(String to, String code) {
|
public void sendUpdatePwdMailMessage(String to, String code) {
|
||||||
String subject = "修改密码,邮箱验证码";
|
//String subject = "修改密码,邮箱验证码";
|
||||||
String text = "您正在修改密码,如果不是您本人操作,请忽略。验证码10分钟内有效:\n\t"+code;
|
//String text = "您正在修改密码,如果不是您本人操作,请忽略。验证码10分钟内有效:\n\t"+code;
|
||||||
sendTextMailMessage(to,subject,text);
|
|
||||||
|
Map<String, Object> content = new HashMap<>();
|
||||||
|
content.put("code",code);
|
||||||
|
content.put("text","You are currently modifying your password. If this is not done by you, please ignore it. The verification code is valid for 10 minutes.");
|
||||||
|
EmailTemplateEntity entity = new EmailTemplateEntity(to,"Change password, email verification code","emailCode-en",content);
|
||||||
|
sendHtmlMailMessage(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -62,3 +62,5 @@ spring:
|
|||||||
namespace: m2_prod
|
namespace: m2_prod
|
||||||
group: m2_prod_group
|
group: m2_prod_group
|
||||||
|
|
||||||
|
image:
|
||||||
|
prefix: https://m2pool.com
|
||||||
|
|||||||
@@ -87,3 +87,5 @@ spring:
|
|||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
namespace: m2_test
|
namespace: m2_test
|
||||||
group: m2_test_group
|
group: m2_test_group
|
||||||
|
image:
|
||||||
|
prefix: https://test.m2pool.com
|
||||||
|
|||||||
@@ -126,8 +126,6 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-mail</artifactId>
|
<artifactId>spring-boot-starter-mail</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.m2pool.common.security.interceptor;
|
|||||||
|
|
||||||
import com.m2pool.common.core.constant.SecurityConstants;
|
import com.m2pool.common.core.constant.SecurityConstants;
|
||||||
import com.m2pool.common.core.context.SecurityContextHolder;
|
import com.m2pool.common.core.context.SecurityContextHolder;
|
||||||
|
import com.m2pool.common.core.utils.JwtUtils;
|
||||||
import com.m2pool.common.core.utils.ServletUtils;
|
import com.m2pool.common.core.utils.ServletUtils;
|
||||||
import com.m2pool.common.core.utils.StringUtils;
|
import com.m2pool.common.core.utils.StringUtils;
|
||||||
import com.m2pool.common.core.utils.ip.IpUtils;
|
import com.m2pool.common.core.utils.ip.IpUtils;
|
||||||
@@ -37,6 +38,11 @@ public class HeaderInterceptor implements AsyncHandlerInterceptor {
|
|||||||
SecurityContextHolder.setUserName(ServletUtils.getHeader(request,SecurityConstants.DETAILS_USERNAME));
|
SecurityContextHolder.setUserName(ServletUtils.getHeader(request,SecurityConstants.DETAILS_USERNAME));
|
||||||
SecurityContextHolder.setUserKey(ServletUtils.getHeader(request,SecurityConstants.USER_KEY));
|
SecurityContextHolder.setUserKey(ServletUtils.getHeader(request,SecurityConstants.USER_KEY));
|
||||||
|
|
||||||
|
//开发环境
|
||||||
|
String authorization = request.getHeader("Authorization");
|
||||||
|
String userName = JwtUtils.getUserName(authorization);
|
||||||
|
SecurityContextHolder.setUserName(userName);
|
||||||
|
|
||||||
String token = SecurityUtils.getToken();
|
String token = SecurityUtils.getToken();
|
||||||
if(StringUtils.isNotEmpty(token)){
|
if(StringUtils.isNotEmpty(token)){
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public class ManageTask {
|
|||||||
LocalDateTime maxDateData = manageWalletOutInMapper.getMaxDateIn();
|
LocalDateTime maxDateData = manageWalletOutInMapper.getMaxDateIn();
|
||||||
List<ManageWalletOutIn> manageWalletOutIns = new ArrayList<>();
|
List<ManageWalletOutIn> manageWalletOutIns = new ArrayList<>();
|
||||||
if (maxDateData != null){
|
if (maxDateData != null){
|
||||||
|
maxDateData = maxDateData.toLocalDate().atStartOfDay().minusDays(10);
|
||||||
//获取startDate 后的数据,用于比对
|
//获取startDate 后的数据,用于比对
|
||||||
manageWalletOutIns = manageWalletOutInMapper.selectList(new LambdaQueryWrapper<ManageWalletOutIn>()
|
manageWalletOutIns = manageWalletOutInMapper.selectList(new LambdaQueryWrapper<ManageWalletOutIn>()
|
||||||
.ge(ManageWalletOutIn::getShouldOutDate, maxDateData.toLocalDate().atStartOfDay())
|
.ge(ManageWalletOutIn::getShouldOutDate, maxDateData.toLocalDate().atStartOfDay())
|
||||||
|
|||||||
@@ -5017,4 +5017,183 @@ public class DataTask {
|
|||||||
dto.getLuck3d(),dto.getLuck7d(),dto.getLuck30d(),dto.getLuck90d());
|
dto.getLuck3d(),dto.getLuck7d(),dto.getLuck30d(),dto.getLuck90d());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(cron = "20 1,3,10,31,33,40 * * * ?")
|
||||||
|
public void Sha3x30mDataToDB(){
|
||||||
|
//String nowStr = DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:00");
|
||||||
|
if(!enable){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Date now = new Date();
|
||||||
|
int minute = (now.getMinutes() / 30) * 30;
|
||||||
|
now.setMinutes( minute);
|
||||||
|
now.setSeconds(0);
|
||||||
|
String nowStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, now);
|
||||||
|
|
||||||
|
System.out.println("SHA3X 30分钟定时任务执行时间:"+now);
|
||||||
|
System.out.println("格式化后的时间:"+nowStr);
|
||||||
|
|
||||||
|
//检查二级表是否有当前时间数据
|
||||||
|
int count = poolMapper.getLastDataTime(Pools.SHA3X.getMhs() + "30m", nowStr);
|
||||||
|
|
||||||
|
if(count == 0) {
|
||||||
|
List<MinerDataDto> list = poolMapper.getHourMinerDataList(Pools.SHA3X.getMhs()+"_realv2",nowStr);
|
||||||
|
if(list.size() > 0){
|
||||||
|
List<MinerDataDto> offlineList = new ArrayList<>();
|
||||||
|
list.stream().forEach(e -> {
|
||||||
|
if(StringUtils.isNotNull(e.getMhs())){
|
||||||
|
e.setMhs(e.getMhs() * Pools.SHA3X.getFac());
|
||||||
|
}
|
||||||
|
if("offline".equals(e.getState())){
|
||||||
|
offlineList.add(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
list = filterList(list,now);
|
||||||
|
|
||||||
|
boolean result = poolMapper.batchInsertMhsDataToDB(Pools.SHA3X.getMhs() + "30m", getToHourDBListByMinerDataList(list));
|
||||||
|
|
||||||
|
Map<Date, List<MinerDataDto>> map = list.stream().collect(Collectors.groupingBy(MinerDataDto::getDate));
|
||||||
|
map.forEach((date,dList) -> {
|
||||||
|
PoolPower poolPower = new PoolPower();
|
||||||
|
//poolPower.setDate(date);
|
||||||
|
poolPower.setDateStr(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,date));
|
||||||
|
Map<String, Long> stateCount = dList.stream().collect(Collectors.groupingBy(MinerDataDto::getState, Collectors.counting()));
|
||||||
|
poolPower.setMhs(dList.stream().map(e -> BigDecimal.valueOf(e.getMhs())).reduce(BigDecimal::add).get().stripTrailingZeros());
|
||||||
|
poolPower.setMiners(dList.size());
|
||||||
|
poolPower.setOnline(Convert.toInt(stateCount.get("online"),0));
|
||||||
|
poolPower.setOffline(Convert.toInt(stateCount.get("offline"),0));
|
||||||
|
|
||||||
|
boolean poolResult = poolMapper.insertPoolPower(Pools.SHA3X.getPoolTable() + "_30m", poolPower);
|
||||||
|
int time =0;
|
||||||
|
while (!poolResult){
|
||||||
|
poolResult = poolMapper.insertPoolPower(Pools.SHA3X.getPoolTable() + "_30m", poolPower);
|
||||||
|
if (time > 5) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
time ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("构造写入user算力表数据");
|
||||||
|
Map<String, List<MinerDataDto>> userMap = dList.stream().collect(Collectors.groupingBy(MinerDataDto::getUser));
|
||||||
|
List<MinerDataInsertDBDto> userList = new ArrayList<>();
|
||||||
|
userMap.forEach((user,uList)->{
|
||||||
|
MinerDataInsertDBDto uDto = new MinerDataInsertDBDto();
|
||||||
|
uDto.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,date));
|
||||||
|
uDto.setUser(user);
|
||||||
|
uDto.setMhs(uList.stream().map(e->BigDecimal.valueOf(e.getMhs())).reduce(BigDecimal::add).get().doubleValue());
|
||||||
|
userList.add(uDto);
|
||||||
|
} );
|
||||||
|
System.out.println("user算力表入库数据条数:"+userList.size());
|
||||||
|
boolean userResult = poolMapper.batchInsertUserMhsDateToDB(Pools.SHA3X.getName() + "_users_30m", userList);
|
||||||
|
int uTime =0;
|
||||||
|
while (!userResult){
|
||||||
|
userResult = poolMapper.batchInsertUserMhsDateToDB(Pools.SHA3X.getName() + "_users_30m", userList);
|
||||||
|
if (uTime > 5) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
uTime ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
Map<String, List<MinerDataDto>> userMap = list.stream().collect(Collectors.groupingBy(MinerDataDto::getMiner));
|
||||||
|
if (result) {
|
||||||
|
System.out.println(DateUtils.dateTimeNow() + "SHA3X 小时数据存入数据成功");
|
||||||
|
} else {
|
||||||
|
System.out.println(DateUtils.dateTimeNow() + "SHA3X 小时数据存入数据失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(offlineList.size() >0){
|
||||||
|
CompletableFuture.runAsync(()->{
|
||||||
|
|
||||||
|
//根据挖矿账户分组、统计离线矿机名单、离线矿机数
|
||||||
|
|
||||||
|
//对比redis中该挖矿账户上一次离线矿机数
|
||||||
|
//有redis数据 需要判断 上一次离线矿机数<本次矿机离线数 才执行通知 否则跳过
|
||||||
|
//无redis数据 说明是第一次 执行通知
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
//重来一次!
|
||||||
|
CompletableFuture.runAsync(()->{
|
||||||
|
System.out.println("SHA3X 30分钟定时任务执行失败 延时一分钟时间重新查询");
|
||||||
|
System.out.println("延迟后使用的查询时间:"+now);
|
||||||
|
System.out.println("延迟后 格式化后的时间:"+nowStr);
|
||||||
|
|
||||||
|
//检查二级表是否有当前时间数据
|
||||||
|
int newCount = poolMapper.getLastDataTime(Pools.SHA3X.getMhs() + "30m", nowStr);
|
||||||
|
if(newCount == 0){
|
||||||
|
List<MinerDataDto> newList = poolMapper.getHourMinerDataList(Pools.SHA3X.getMhs()+"_realv2",nowStr);
|
||||||
|
if(newList.size() > 0){
|
||||||
|
|
||||||
|
newList.stream().forEach(e -> {
|
||||||
|
if(StringUtils.isNotNull(e.getMhs())){
|
||||||
|
e.setMhs(e.getMhs() * Pools.SHA3X.getFac());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
newList = filterList(newList,now);
|
||||||
|
|
||||||
|
boolean newResult = poolMapper.batchInsertMhsDataToDB(Pools.SHA3X.getMhs() + "30m", getToHourDBListByMinerDataList(newList));
|
||||||
|
|
||||||
|
Map<Date, List<MinerDataDto>> map2 = newList.stream().collect(Collectors.groupingBy(MinerDataDto::getDate));
|
||||||
|
map2.forEach((date,dList) -> {
|
||||||
|
PoolPower poolPower = new PoolPower();
|
||||||
|
//poolPower.setDate(date);
|
||||||
|
poolPower.setDateStr(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,date));
|
||||||
|
Map<String, Long> stateCount = dList.stream().collect(Collectors.groupingBy(MinerDataDto::getState, Collectors.counting()));
|
||||||
|
poolPower.setMhs(dList.stream().map(e -> BigDecimal.valueOf(e.getMhs())).reduce(BigDecimal::add).get().stripTrailingZeros());
|
||||||
|
poolPower.setMiners(dList.size());
|
||||||
|
poolPower.setOnline(Convert.toInt(stateCount.get("online"),0));
|
||||||
|
poolPower.setOffline(Convert.toInt(stateCount.get("offline"),0));
|
||||||
|
|
||||||
|
boolean poolResult2 = poolMapper.insertPoolPower(Pools.SHA3X.getPoolTable() + "_30m", poolPower);
|
||||||
|
int time =0;
|
||||||
|
while (!poolResult2){
|
||||||
|
poolResult2 = poolMapper.insertPoolPower(Pools.SHA3X.getPoolTable() + "_30m", poolPower);
|
||||||
|
if (time > 5) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
time ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("延迟任务 构造写入user算力表数据");
|
||||||
|
Map<String, List<MinerDataDto>> userMap = dList.stream().collect(Collectors.groupingBy(MinerDataDto::getUser));
|
||||||
|
List<MinerDataInsertDBDto> userList = new ArrayList<>();
|
||||||
|
userMap.forEach((user,uList)->{
|
||||||
|
MinerDataInsertDBDto uDto = new MinerDataInsertDBDto();
|
||||||
|
uDto.setDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,date));
|
||||||
|
uDto.setUser(user);
|
||||||
|
uDto.setMhs(uList.stream().map(e->BigDecimal.valueOf(e.getMhs())).reduce(BigDecimal::add).get().doubleValue());
|
||||||
|
userList.add(uDto);
|
||||||
|
} );
|
||||||
|
System.out.println("延迟任务 user算力表入库数据条数:"+userList.size());
|
||||||
|
boolean userResult = poolMapper.batchInsertUserMhsDateToDB(Pools.SHA3X.getName() + "_users_30m", userList);
|
||||||
|
int uTime =0;
|
||||||
|
while (!userResult){
|
||||||
|
userResult = poolMapper.batchInsertUserMhsDateToDB(Pools.SHA3X.getName() + "_users_30m", userList);
|
||||||
|
if (uTime > 5) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
uTime ++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (newResult) {
|
||||||
|
System.out.println(DateUtils.dateTimeNow() + "SHA3X 30m数据 延迟存入数据成功");
|
||||||
|
} else {
|
||||||
|
System.out.println(DateUtils.dateTimeNow() + "SHA3X 30m数据 延迟存入数据失败");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.m2pool.pool.mapper.NoticeMapper;
|
|||||||
import com.m2pool.pool.mapper.PoolMapper;
|
import com.m2pool.pool.mapper.PoolMapper;
|
||||||
import com.m2pool.system.api.RemoteMailService;
|
import com.m2pool.system.api.RemoteMailService;
|
||||||
import com.m2pool.system.api.entity.EmailEntity;
|
import com.m2pool.system.api.entity.EmailEntity;
|
||||||
|
import com.m2pool.system.api.entity.EmailTemplateEntity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
@@ -40,11 +41,33 @@ public class OffLineNoticeTask {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RemoteMailService mailService;
|
private RemoteMailService mailService;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
|
|
||||||
|
//@Scheduled(cron = "0 0/2 * * * ?")
|
||||||
|
//public void test(){
|
||||||
|
// Map<String, Object> map = new HashMap<>();
|
||||||
|
// map.put("user","yyb");
|
||||||
|
// map.put("coin","sha3x");
|
||||||
|
// map.put("offOnlineNumbers",24);
|
||||||
|
// EmailTemplateEntity test = new EmailTemplateEntity("1416014977@qq.com", "测试邮件", "emailoffline-en", map);
|
||||||
|
// mailService.sendHtmlMailMessage(test);
|
||||||
|
//
|
||||||
|
// Map<String, Object> a = new HashMap<>();
|
||||||
|
// a.put("user","yyb");
|
||||||
|
// a.put("coin","sha3x");
|
||||||
|
// a.put("offOnlineNumbers",24);
|
||||||
|
// EmailTemplateEntity b = new EmailTemplateEntity("yaoyoubo89@gmail.com", "测试邮件", "emailoffline-en", a);
|
||||||
|
// mailService.sendHtmlMailMessage(b);
|
||||||
|
//
|
||||||
|
// //Map<String, Object> code = new HashMap<>();
|
||||||
|
// //code.put("code","123456");
|
||||||
|
// //code.put("type","Login");
|
||||||
|
// //EmailTemplateEntity test1 = new EmailTemplateEntity("1416014977@qq.com", "登录", "emailCode-en", code);
|
||||||
|
// //mailService.sendHtmlMailMessage(test1);
|
||||||
|
//}
|
||||||
|
|
||||||
@Scheduled(cron = "20 15,45 * * * ?")
|
@Scheduled(cron = "20 15,45 * * * ?")
|
||||||
public void NEXA30mDataToDB(){
|
public void NEXA30mDataToDB(){
|
||||||
//String nowStr = DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:00");
|
//String nowStr = DateUtils.dateTimeNow("yyyy-MM-dd HH:mm:00");
|
||||||
@@ -272,7 +295,7 @@ public class OffLineNoticeTask {
|
|||||||
list.stream().forEach(e -> {
|
list.stream().forEach(e -> {
|
||||||
long lastOff = 0;
|
long lastOff = 0;
|
||||||
if(StringUtils.isNotNull(map)){
|
if(StringUtils.isNotNull(map)){
|
||||||
lastOff =map.getOrDefault(e.getUser(),0L);
|
lastOff = map.getOrDefault(e.getUser(),0L);
|
||||||
}
|
}
|
||||||
if(e.getOffline() > lastOff){
|
if(e.getOffline() > lastOff){
|
||||||
//对比redis中该挖矿账户上一次离线矿机数 上一次不存在则设上一次离线数为0来进行比较
|
//对比redis中该挖矿账户上一次离线矿机数 上一次不存在则设上一次离线数为0来进行比较
|
||||||
|
|||||||
@@ -220,20 +220,52 @@ public class NodeRpc{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkAddress(String coin,String address) {
|
/**
|
||||||
//不同币种要单独设置验证方法
|
* 校验monero 钱包是否合法
|
||||||
String[] params = {address};
|
* @param address
|
||||||
if (coin.equals("monero")){
|
* @return
|
||||||
int length = address.length();
|
*/
|
||||||
|
public static boolean checkMonero(String address){
|
||||||
|
int length = address.length();
|
||||||
|
|
||||||
if(StringUtils.isNotEmpty(address) && (length == 95 || length == 106) ){
|
if(StringUtils.isNotEmpty(address) && (length == 95 || length == 106) ){
|
||||||
if (address.startsWith("4") || address.startsWith("8")){
|
if (address.startsWith("4") || address.startsWith("8")){
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验sha3x 钱包是否合法
|
||||||
|
* @param address
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean checkSha3x(String address){
|
||||||
|
int length = address.length();
|
||||||
|
|
||||||
|
if(StringUtils.isNotEmpty(address) && (length == 95 || length == 106) ){
|
||||||
|
if (address.startsWith("4") || address.startsWith("8")){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkAddress(String coin,String address) {
|
||||||
|
//不同币种要单独设置验证方法
|
||||||
|
String[] params = {address};
|
||||||
|
|
||||||
|
//下面新增的币种暂时不通过节点校验
|
||||||
|
if (coin.equals("monero")){
|
||||||
|
return checkMonero(address);
|
||||||
|
}
|
||||||
|
if (coin.equals("sha3x")){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
String result = getResultTest(coin, "validateaddress", params);
|
String result = getResultTest(coin, "validateaddress", params);
|
||||||
//处理result
|
//处理result
|
||||||
if(StringUtils.isBlank(result)){
|
if(StringUtils.isBlank(result)){
|
||||||
|
|||||||
Reference in New Issue
Block a user