Compare commits
No commits in common. "841f48e2915ea952b7781c3233a3e72069016485" and "17ec9cbe3bfd1e260d18fdef553b19a1beab1bb0" have entirely different histories.
841f48e291
...
17ec9cbe3b
|
@ -55,13 +55,6 @@ public class GlobalExceptionHandler {
|
||||||
return Result.error(null, 500, "[" + primaryKeyErrorMatcher.group(1) + "]已存在");
|
return Result.error(null, 500, "[" + primaryKeyErrorMatcher.group(1) + "]已存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// corn表达式错误
|
|
||||||
String cronExpression = "CronExpression '(.*?)' is invalid";
|
|
||||||
Matcher cronExpressionMatcher = Pattern.compile(cronExpression).matcher(message);
|
|
||||||
if (cronExpressionMatcher.find()) {
|
|
||||||
return Result.error(null, 500, "表达式 " + cronExpressionMatcher.group(1) + " 不合法");
|
|
||||||
}
|
|
||||||
|
|
||||||
log.error("GlobalExceptionHandler===>运行时异常信息:{}", message);
|
log.error("GlobalExceptionHandler===>运行时异常信息:{}", message);
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
return Result.error(null, 500, "服务器异常");
|
return Result.error(null, 500, "服务器异常");
|
||||||
|
|
|
@ -4,38 +4,14 @@ import cn.bunny.dao.pojo.common.EmailSend;
|
||||||
import cn.bunny.dao.pojo.common.EmailSendInit;
|
import cn.bunny.dao.pojo.common.EmailSendInit;
|
||||||
import jakarta.mail.MessagingException;
|
import jakarta.mail.MessagingException;
|
||||||
import jakarta.mail.internet.MimeMessage;
|
import jakarta.mail.internet.MimeMessage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
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.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
public class MailSenderUtil {
|
public class MailSenderUtil {
|
||||||
|
|
||||||
/**
|
|
||||||
* 如果启用SSL需要配置以下
|
|
||||||
*
|
|
||||||
* @param emailSendInit 邮件发送初始化
|
|
||||||
*/
|
|
||||||
private static @NotNull Properties getProperties(EmailSendInit emailSendInit) {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
// 开启认证
|
|
||||||
properties.setProperty("mail.smtp.auth", "true");
|
|
||||||
// 启用调试
|
|
||||||
properties.setProperty("mail.debug", "false");
|
|
||||||
// 设置链接超时
|
|
||||||
properties.setProperty("mail.smtp.timeout", "200000");
|
|
||||||
// 设置端口
|
|
||||||
properties.setProperty("mail.smtp.port", Integer.toString(25));
|
|
||||||
// 设置ssl端口
|
|
||||||
properties.setProperty("mail.smtp.socketFactory.port", Integer.toString(emailSendInit.getPort()));
|
|
||||||
properties.setProperty("mail.smtp.socketFactory.fallback", "false");
|
|
||||||
properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 邮件发送初始化
|
* * 邮件发送初始化
|
||||||
*
|
*
|
||||||
|
@ -50,12 +26,6 @@ public class MailSenderUtil {
|
||||||
javaMailSender.setProtocol(emailSendInit.getProtocol());
|
javaMailSender.setProtocol(emailSendInit.getProtocol());
|
||||||
javaMailSender.setDefaultEncoding("UTF-8");
|
javaMailSender.setDefaultEncoding("UTF-8");
|
||||||
|
|
||||||
// 如果开启SSL
|
|
||||||
if (emailSendInit.getOpenSSL()) {
|
|
||||||
Properties properties = getProperties(emailSendInit);
|
|
||||||
javaMailSender.setJavaMailProperties(properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
return javaMailSender;
|
return javaMailSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class MinioUtil {
|
||||||
return minioFile;
|
return minioFile;
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
throw new AuthCustomerException(ResultCodeEnum.UPLOAD_ERROR);
|
throw new AuthCustomerException(ResultCodeEnum.UPDATE_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ public class MinioUtil {
|
||||||
minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(filename).stream(inputStream, size, -1).build());
|
minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(filename).stream(inputStream, size, -1).build());
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
log.error("上传文件失败:{}", (Object) exception.getStackTrace());
|
log.error("上传文件失败:{}", (Object) exception.getStackTrace());
|
||||||
throw new AuthCustomerException(ResultCodeEnum.UPLOAD_ERROR);
|
throw new AuthCustomerException(ResultCodeEnum.UPDATE_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cn.bunny.dao.dto.quartz.schedule;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -16,19 +17,32 @@ public class SchedulersUpdateDto {
|
||||||
|
|
||||||
@Schema(name = "jobName", title = "任务名称")
|
@Schema(name = "jobName", title = "任务名称")
|
||||||
@NotBlank(message = "任务名称不能为空")
|
@NotBlank(message = "任务名称不能为空")
|
||||||
|
@NotNull(message = "任务名称不能为空")
|
||||||
private String jobName;
|
private String jobName;
|
||||||
|
|
||||||
@Schema(name = "jobGroup", title = "任务分组")
|
@Schema(name = "jobGroup", title = "任务分组")
|
||||||
@NotBlank(message = "任务分组不能为空")
|
@NotBlank(message = "任务分组不能为空")
|
||||||
|
@NotNull(message = "任务分组不能为空")
|
||||||
private String jobGroup;
|
private String jobGroup;
|
||||||
|
|
||||||
@Schema(name = "description", title = "任务详情")
|
@Schema(name = "description", title = "任务详情")
|
||||||
@NotBlank(message = "任务详情不能为空")
|
@NotBlank(message = "任务详情不能为空")
|
||||||
|
@NotNull(message = "任务详情不能为空")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@Schema(name = "jobClassName", title = "任务类名称")
|
||||||
|
@NotBlank(message = "corn表达式不能为空")
|
||||||
|
@NotNull(message = "corn表达式不能为空")
|
||||||
|
private String jobClassName;
|
||||||
|
|
||||||
@Schema(name = "cronExpression", title = "corn表达式")
|
@Schema(name = "cronExpression", title = "corn表达式")
|
||||||
@NotBlank(message = "corn表达式不能为空")
|
@NotBlank(message = "corn表达式不能为空")
|
||||||
|
@NotNull(message = "corn表达式不能为空")
|
||||||
private String cronExpression;
|
private String cronExpression;
|
||||||
|
|
||||||
|
@Schema(name = "jobMethodName", title = "执行方法")
|
||||||
|
@NotBlank(message = "执行方法不能为空")
|
||||||
|
@NotNull(message = "执行方法不能为空")
|
||||||
|
private String jobMethodName;
|
||||||
|
|
||||||
}
|
}
|
|
@ -36,9 +36,4 @@ public class EmailTemplateAddDto {
|
||||||
|
|
||||||
@Schema(name = "type", title = "邮件类型")
|
@Schema(name = "type", title = "邮件类型")
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
@Schema(name = "isDefault", title = "是否默认")
|
|
||||||
@NotNull(message = "是否默认不能为空")
|
|
||||||
private Boolean isDefault;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,5 @@ public class EmailTemplateDto {
|
||||||
|
|
||||||
@Schema(name = "type", title = "邮件类型")
|
@Schema(name = "type", title = "邮件类型")
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
@Schema(name = "isDefault", title = "是否默认")
|
|
||||||
private Boolean isDefault;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,4 @@ public class EmailTemplateUpdateDto {
|
||||||
|
|
||||||
@Schema(name = "type", title = "邮件类型")
|
@Schema(name = "type", title = "邮件类型")
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
@Schema(name = "isDefault", title = "是否默认")
|
|
||||||
@NotNull(message = "是否默认不能为空")
|
|
||||||
private Boolean isDefault;
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -46,12 +46,6 @@ public class AdminUser extends BaseEntity {
|
||||||
@Schema(name = "summary", title = "个人描述")
|
@Schema(name = "summary", title = "个人描述")
|
||||||
private String summary;
|
private String summary;
|
||||||
|
|
||||||
@Schema(name = "weekBillReport", title = "周报提醒", description = "1:启用 0:关闭")
|
|
||||||
private Boolean weekBillReport;
|
|
||||||
|
|
||||||
@Schema(name = "mouthBillReport", title = "周报提醒", description = "1:启用 0:关闭")
|
|
||||||
private Boolean mouthBillReport;
|
|
||||||
|
|
||||||
@Schema(name = "ipAddress", title = "登录Ip")
|
@Schema(name = "ipAddress", title = "登录Ip")
|
||||||
private String ipAddress;
|
private String ipAddress;
|
||||||
|
|
||||||
|
|
|
@ -40,4 +40,4 @@ public class EmailTemplate extends BaseEntity {
|
||||||
@Schema(name = "isDefault", title = "是否默认")
|
@Schema(name = "isDefault", title = "是否默认")
|
||||||
private Boolean isDefault;
|
private Boolean isDefault;
|
||||||
|
|
||||||
}
|
}
|
|
@ -40,7 +40,4 @@ public class EmailSendInit {
|
||||||
@NotNull(message = "密码不能为空")
|
@NotNull(message = "密码不能为空")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@Schema(name = "openSSL", description = "启用SSL")
|
|
||||||
private Boolean openSSL;
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,7 +7,6 @@ import lombok.Getter;
|
||||||
@Schema(description = "Email Template Types")
|
@Schema(description = "Email Template Types")
|
||||||
public enum EmailTemplateEnums {
|
public enum EmailTemplateEnums {
|
||||||
VERIFICATION_CODE("verification_code", "邮箱验证码发送"),
|
VERIFICATION_CODE("verification_code", "邮箱验证码发送"),
|
||||||
BILL_WEEK_NOTIFICATION("bill_week_notification", "周账单提醒"),
|
|
||||||
NOTIFICATION("notification", "通知型邮件"),
|
NOTIFICATION("notification", "通知型邮件"),
|
||||||
WARNING("warning", "警告型邮件"),
|
WARNING("warning", "警告型邮件"),
|
||||||
;
|
;
|
||||||
|
|
|
@ -18,7 +18,6 @@ public enum ResultCodeEnum {
|
||||||
LOGOUT_SUCCESS(200, "退出成功"),
|
LOGOUT_SUCCESS(200, "退出成功"),
|
||||||
EMAIL_CODE_REFRESH(200, "邮箱验证码已刷新"),
|
EMAIL_CODE_REFRESH(200, "邮箱验证码已刷新"),
|
||||||
EMAIL_CODE_SEND_SUCCESS(200, "邮箱验证码已发送"),
|
EMAIL_CODE_SEND_SUCCESS(200, "邮箱验证码已发送"),
|
||||||
EMAIL_SEND_SUCCESS(200, "邮件已发送"),
|
|
||||||
|
|
||||||
// 验证错误 201
|
// 验证错误 201
|
||||||
USERNAME_OR_PASSWORD_NOT_EMPTY(201, "用户名或密码不能为空"),
|
USERNAME_OR_PASSWORD_NOT_EMPTY(201, "用户名或密码不能为空"),
|
||||||
|
@ -60,7 +59,6 @@ public enum ResultCodeEnum {
|
||||||
THE_SAME_USER_HAS_LOGGED_IN(209, "相同用户已登录"),
|
THE_SAME_USER_HAS_LOGGED_IN(209, "相同用户已登录"),
|
||||||
|
|
||||||
// 提示错误
|
// 提示错误
|
||||||
UPDATE_ERROR(216, "修改失败"),
|
|
||||||
URL_ENCODE_ERROR(216, "URL编码失败"),
|
URL_ENCODE_ERROR(216, "URL编码失败"),
|
||||||
ILLEGAL_CALLBACK_REQUEST_ERROR(217, "非法回调请求"),
|
ILLEGAL_CALLBACK_REQUEST_ERROR(217, "非法回调请求"),
|
||||||
FETCH_USERINFO_ERROR(219, "获取用户信息失败"),
|
FETCH_USERINFO_ERROR(219, "获取用户信息失败"),
|
||||||
|
@ -78,7 +76,7 @@ public enum ResultCodeEnum {
|
||||||
// 系统错误 500
|
// 系统错误 500
|
||||||
UNKNOWN_EXCEPTION(500, "服务异常"),
|
UNKNOWN_EXCEPTION(500, "服务异常"),
|
||||||
SERVICE_ERROR(500, "服务异常"),
|
SERVICE_ERROR(500, "服务异常"),
|
||||||
UPLOAD_ERROR(500, "上传失败"),
|
UPDATE_ERROR(500, "上传文件失败"),
|
||||||
FAIL(500, "失败"),
|
FAIL(500, "失败"),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,6 @@ public class EmailTemplateVo extends BaseUserVo {
|
||||||
@Schema(name = "type", title = "邮件类型")
|
@Schema(name = "type", title = "邮件类型")
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
@Schema(name = "summary", title = "邮件类型详情")
|
|
||||||
private String summary;
|
|
||||||
|
|
||||||
@Schema(name = "isDefault", title = "是否默认")
|
@Schema(name = "isDefault", title = "是否默认")
|
||||||
private Boolean isDefault;
|
private Boolean isDefault;
|
||||||
|
|
||||||
|
|
|
@ -36,12 +36,6 @@ public class AdminUserVo extends BaseUserVo {
|
||||||
@Schema(name = "summary", title = "个人描述")
|
@Schema(name = "summary", title = "个人描述")
|
||||||
private String summary;
|
private String summary;
|
||||||
|
|
||||||
@Schema(name = "weekBillReport", title = "周报提醒", description = "1:启用 0:关闭")
|
|
||||||
private Boolean weekBillReport;
|
|
||||||
|
|
||||||
@Schema(name = "mouthBillReport", title = "周报提醒", description = "1:启用 0:关闭")
|
|
||||||
private Boolean mouthBillReport;
|
|
||||||
|
|
||||||
@Schema(name = "ipAddress", title = "登录Ip")
|
@Schema(name = "ipAddress", title = "登录Ip")
|
||||||
private String ipAddress;
|
private String ipAddress;
|
||||||
|
|
||||||
|
|
|
@ -48,12 +48,6 @@ public class LoginVo extends BaseVo {
|
||||||
@Schema(name = "ipRegion", title = "登录Ip归属地")
|
@Schema(name = "ipRegion", title = "登录Ip归属地")
|
||||||
private String ipRegion;
|
private String ipRegion;
|
||||||
|
|
||||||
@Schema(name = "weekBillReport", title = "周报提醒", description = "1:启用 0:关闭")
|
|
||||||
private Boolean weekBillReport;
|
|
||||||
|
|
||||||
@Schema(name = "mouthBillReport", title = "周报提醒", description = "1:启用 0:关闭")
|
|
||||||
private Boolean mouthBillReport;
|
|
||||||
|
|
||||||
@Schema(name = "status", title = "1:禁用 0:正常")
|
@Schema(name = "status", title = "1:禁用 0:正常")
|
||||||
private Boolean status;
|
private Boolean status;
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,6 @@ public class UserVo extends BaseVo {
|
||||||
@Schema(name = "avatar", title = "头像")
|
@Schema(name = "avatar", title = "头像")
|
||||||
private String avatar;
|
private String avatar;
|
||||||
|
|
||||||
@Schema(name = "weekBillReport", title = "周报提醒", description = "1:启用 0:关闭")
|
|
||||||
private Boolean weekBillReport;
|
|
||||||
|
|
||||||
@Schema(name = "mouthBillReport", title = "周报提醒", description = "1:启用 0:关闭")
|
|
||||||
private Boolean mouthBillReport;
|
|
||||||
|
|
||||||
@Schema(name = "sex", title = "0:女 1:男")
|
@Schema(name = "sex", title = "0:女 1:男")
|
||||||
private Byte sex;
|
private Byte sex;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package cn.bunny.dao.vo.system.user;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Schema(description = "验证码响应结果实体类")
|
||||||
|
public class ValidateCodeVo {
|
||||||
|
@Schema(description = "验证码key")
|
||||||
|
private String codeKey;
|
||||||
|
|
||||||
|
@Schema(description = "验证码value")
|
||||||
|
private String codeValue;
|
||||||
|
}
|
|
@ -77,13 +77,6 @@ public class BillController {
|
||||||
return Mono.just(Result.success(vo));
|
return Mono.just(Result.success(vo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "发送账单提醒", description = "发送账单提醒")
|
|
||||||
@GetMapping("noManage/sendBillReport")
|
|
||||||
public Result<String> sendBillReport(String type) {
|
|
||||||
billService.sendBillReport(type);
|
|
||||||
return Result.success(ResultCodeEnum.EMAIL_SEND_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "使用Excel导入用户账单", description = "使用Excel导入用户账单")
|
@Operation(summary = "使用Excel导入用户账单", description = "使用Excel导入用户账单")
|
||||||
@PostMapping("noManage/importBill")
|
@PostMapping("noManage/importBill")
|
||||||
public Mono<Result<Result<String>>> importBill(MultipartFile file) {
|
public Mono<Result<Result<String>>> importBill(MultipartFile file) {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package cn.bunny.services.controller.schedule;
|
||||||
import cn.bunny.dao.dto.quartz.SchedulersOperationDto;
|
import cn.bunny.dao.dto.quartz.SchedulersOperationDto;
|
||||||
import cn.bunny.dao.dto.quartz.schedule.SchedulersAddDto;
|
import cn.bunny.dao.dto.quartz.schedule.SchedulersAddDto;
|
||||||
import cn.bunny.dao.dto.quartz.schedule.SchedulersDto;
|
import cn.bunny.dao.dto.quartz.schedule.SchedulersDto;
|
||||||
import cn.bunny.dao.dto.quartz.schedule.SchedulersUpdateDto;
|
|
||||||
import cn.bunny.dao.entity.quartz.Schedulers;
|
import cn.bunny.dao.entity.quartz.Schedulers;
|
||||||
import cn.bunny.dao.pojo.result.PageResult;
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
import cn.bunny.dao.pojo.result.Result;
|
import cn.bunny.dao.pojo.result.Result;
|
||||||
|
@ -65,13 +64,6 @@ public class SchedulersController {
|
||||||
return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
|
return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "更新任务", description = "更新任务")
|
|
||||||
@PutMapping("updateSchedulers")
|
|
||||||
public Result<String> updateSchedulers(@Valid @RequestBody SchedulersUpdateDto dto) {
|
|
||||||
schedulersService.updateSchedulers(dto);
|
|
||||||
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "暂停任务", description = "暂停任务")
|
@Operation(summary = "暂停任务", description = "暂停任务")
|
||||||
@PutMapping("/pauseSchedulers")
|
@PutMapping("/pauseSchedulers")
|
||||||
public Result<String> pause(@RequestBody SchedulersOperationDto dto) {
|
public Result<String> pause(@RequestBody SchedulersOperationDto dto) {
|
||||||
|
|
|
@ -82,13 +82,6 @@ public class UserController {
|
||||||
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "更新用户账单是否启用", description = "更新用户账单是否启用")
|
|
||||||
@PutMapping("noManage/updateUserBillReportByLocalUser")
|
|
||||||
public Result<String> updateUserBillReportByLocalUser(String type, Boolean status) {
|
|
||||||
userService.updateUserBillReportByLocalUser(type, status);
|
|
||||||
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "管理员修改用户密码", description = "管理员修改管理员用户密码")
|
@Operation(summary = "管理员修改用户密码", description = "管理员修改管理员用户密码")
|
||||||
@PutMapping("updateUserPasswordByAdmin")
|
@PutMapping("updateUserPasswordByAdmin")
|
||||||
public Result<String> updateUserPasswordByAdmin(@Valid @RequestBody AdminUserUpdateWithPasswordDto dto) {
|
public Result<String> updateUserPasswordByAdmin(@Valid @RequestBody AdminUserUpdateWithPasswordDto dto) {
|
||||||
|
|
|
@ -1,42 +1,29 @@
|
||||||
package cn.bunny.services.factory;
|
package cn.bunny.services.factory;
|
||||||
|
|
||||||
import cn.bunny.common.service.exception.AuthCustomerException;
|
import cn.bunny.common.service.exception.AuthCustomerException;
|
||||||
import cn.bunny.dao.dto.financial.bill.BillDto;
|
|
||||||
import cn.bunny.dao.dto.financial.bill.IncomeExpenseQueryDto;
|
import cn.bunny.dao.dto.financial.bill.IncomeExpenseQueryDto;
|
||||||
import cn.bunny.dao.dto.financial.bill.excel.BillExportDto;
|
import cn.bunny.dao.dto.financial.bill.excel.BillExportDto;
|
||||||
import cn.bunny.dao.entity.system.AdminUser;
|
|
||||||
import cn.bunny.dao.entity.system.EmailTemplate;
|
|
||||||
import cn.bunny.dao.excel.BillExportExcelByUser;
|
import cn.bunny.dao.excel.BillExportExcelByUser;
|
||||||
import cn.bunny.dao.pojo.constant.LocalDateTimeConstant;
|
|
||||||
import cn.bunny.dao.pojo.enums.EmailTemplateEnums;
|
|
||||||
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
||||||
import cn.bunny.dao.vo.financial.admin.BillVo;
|
|
||||||
import cn.bunny.dao.vo.financial.user.expendAndIncome.ExpendWithIncome;
|
import cn.bunny.dao.vo.financial.user.expendAndIncome.ExpendWithIncome;
|
||||||
import cn.bunny.services.mapper.email.EmailTemplateMapper;
|
|
||||||
import cn.bunny.services.mapper.financial.BillMapper;
|
import cn.bunny.services.mapper.financial.BillMapper;
|
||||||
import cn.bunny.services.mapper.system.UserMapper;
|
|
||||||
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.EasyExcel;
|
||||||
import com.alibaba.excel.ExcelWriter;
|
import com.alibaba.excel.ExcelWriter;
|
||||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class BillFactory {
|
public class BillFactory {
|
||||||
|
@ -44,15 +31,6 @@ public class BillFactory {
|
||||||
@Autowired
|
@Autowired
|
||||||
private BillMapper billMapper;
|
private BillMapper billMapper;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EmailFactory emailFactory;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EmailTemplateMapper emailTemplateMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserMapper userMapper;
|
|
||||||
|
|
||||||
public void exportBill(BillExportDto dto, HttpServletResponse response) {
|
public void exportBill(BillExportDto dto, HttpServletResponse response) {
|
||||||
LocalDate startDate = dto.getStartDate();
|
LocalDate startDate = dto.getStartDate();
|
||||||
LocalDate endDate = dto.getEndDate();
|
LocalDate endDate = dto.getEndDate();
|
||||||
|
@ -116,100 +94,4 @@ public class BillFactory {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 账单报告
|
|
||||||
*
|
|
||||||
* @param startOfDay 开始日期
|
|
||||||
* @param endOfDay 结束日期
|
|
||||||
*/
|
|
||||||
public void billReport(LocalDate startOfDay, LocalDate endOfDay) {
|
|
||||||
// 查询验证码邮件模板
|
|
||||||
LambdaQueryWrapper<EmailTemplate> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
lambdaQueryWrapper.eq(EmailTemplate::getIsDefault, true);
|
|
||||||
lambdaQueryWrapper.eq(EmailTemplate::getType, EmailTemplateEnums.BILL_WEEK_NOTIFICATION.getType());
|
|
||||||
EmailTemplate emailTemplate = emailTemplateMapper.selectOne(lambdaQueryWrapper);
|
|
||||||
|
|
||||||
// 查询需要发送邮件的用户
|
|
||||||
LambdaQueryWrapper<AdminUser> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
queryWrapper.eq(AdminUser::getWeekBillReport, true)
|
|
||||||
.eq(AdminUser::getStatus, false)// 没有被禁用的
|
|
||||||
.isNotNull(AdminUser::getEmail);// 有邮箱的
|
|
||||||
List<AdminUser> userList = userMapper.selectList(queryWrapper);
|
|
||||||
|
|
||||||
userList.forEach(user -> {
|
|
||||||
// 查询当前用户账单数据
|
|
||||||
BillDto billDto = new BillDto();
|
|
||||||
billDto.setUserId(user.getId());
|
|
||||||
billDto.setStartDate(startOfDay);
|
|
||||||
billDto.setEndDate(endOfDay.plusDays(1));
|
|
||||||
List<BillVo> billVoList = billMapper.selectListByBillNotification(billDto);
|
|
||||||
|
|
||||||
// 发送邮件
|
|
||||||
executeSendEmail(startOfDay, endOfDay, billVoList, user, emailTemplate);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 整理当前日期和参数并发送邮件
|
|
||||||
*
|
|
||||||
* @param startOfDay 开始日期
|
|
||||||
* @param endOfDay 结束日期
|
|
||||||
* @param billVoList 账单列表
|
|
||||||
* @param adminUser 用户信息
|
|
||||||
* @param emailTemplate 邮件模板
|
|
||||||
*/
|
|
||||||
public void executeSendEmail(LocalDate startOfDay, LocalDate endOfDay, List<BillVo> billVoList, AdminUser adminUser, EmailTemplate emailTemplate) {
|
|
||||||
// 发送账单日期
|
|
||||||
String sendDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern(LocalDateTimeConstant.YYYY_MM_DD_HH_MM_SS));
|
|
||||||
String startDate = startOfDay.format(DateTimeFormatter.ofPattern(LocalDateTimeConstant.YYYY_MM_DD));
|
|
||||||
String endDate = endOfDay.format(DateTimeFormatter.ofPattern(LocalDateTimeConstant.YYYY_MM_DD));
|
|
||||||
|
|
||||||
// 计算总收入
|
|
||||||
double income = billVoList.stream()
|
|
||||||
.filter(billVo -> billVo.getType().equals(Byte.parseByte("1")))
|
|
||||||
.collect(Collectors.summarizingDouble(billVo -> billVo.getAmount().doubleValue()))
|
|
||||||
.getSum();
|
|
||||||
|
|
||||||
// 计算总支出
|
|
||||||
double expend = billVoList.stream()
|
|
||||||
.filter(billVo -> billVo.getType().equals(Byte.parseByte("-1")))
|
|
||||||
.collect(Collectors.summarizingDouble(billVo -> billVo.getAmount().doubleValue()))
|
|
||||||
.getSum();
|
|
||||||
|
|
||||||
// 计算盈利
|
|
||||||
double profit = income - expend;
|
|
||||||
|
|
||||||
// 计算盈利
|
|
||||||
double percentValue = (income + expend) == 0 ? 0 : expend / (income + expend);
|
|
||||||
BigDecimal percent = new BigDecimal(percentValue * 100);
|
|
||||||
|
|
||||||
// 表格字符串
|
|
||||||
StringBuilder billTable = new StringBuilder();
|
|
||||||
billVoList.forEach(billVo -> {
|
|
||||||
// 计算是支出还是收入
|
|
||||||
BigDecimal amount = billVo.getAmount();
|
|
||||||
int type = billVo.getType();
|
|
||||||
amount = amount.multiply(new BigDecimal(type));
|
|
||||||
|
|
||||||
String tr = " <td style=\"font-weight:bolder;\">" + billVo.getCategoryName() + "</td>\n" +
|
|
||||||
" <td style=\"color:#DC684A;font-weight:bolder;\">" + amount + " ¥</td>\n" +
|
|
||||||
" <td style=\"font-weight:bolder;\">" + billVo.getDescription() + "</td>\n" +
|
|
||||||
"</tr>";
|
|
||||||
billTable.append(tr);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 替换整理参数
|
|
||||||
HashMap<String, Object> hashMap = new HashMap<>();
|
|
||||||
hashMap.put("##billName##", adminUser.getNickname());
|
|
||||||
hashMap.put("##billDate##", startDate + "~" + endDate);
|
|
||||||
hashMap.put("##income##", income);
|
|
||||||
hashMap.put("##expend##", expend);
|
|
||||||
hashMap.put("##profit##", new BigDecimal(profit).setScale(2, RoundingMode.HALF_UP));
|
|
||||||
hashMap.put("##percent##", percent.setScale(2, RoundingMode.HALF_UP));
|
|
||||||
hashMap.put("##billTable##", billTable);
|
|
||||||
hashMap.put("##sendDate##", sendDate);
|
|
||||||
|
|
||||||
emailFactory.sendEmailTemplate(adminUser.getEmail(), emailTemplate, hashMap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@ public class EmailFactory {
|
||||||
BeanUtils.copyProperties(emailUsers, emailSendInit);
|
BeanUtils.copyProperties(emailUsers, emailSendInit);
|
||||||
emailSendInit.setUsername(emailUsers.getEmail());
|
emailSendInit.setUsername(emailUsers.getEmail());
|
||||||
emailSendInit.setProtocol(emailUsers.getSmtpAgreement());
|
emailSendInit.setProtocol(emailUsers.getSmtpAgreement());
|
||||||
emailSendInit.setOpenSSL(true);
|
|
||||||
|
|
||||||
// 邮件发送模板
|
// 邮件发送模板
|
||||||
EmailSend emailSend = new EmailSend();
|
EmailSend emailSend = new EmailSend();
|
||||||
|
|
|
@ -32,7 +32,7 @@ public interface BillMapper extends BaseMapper<Bill> {
|
||||||
void deleteBatchIdsWithPhysics(List<Long> ids);
|
void deleteBatchIdsWithPhysics(List<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询账单信息内容
|
* * 分页查询账单信息内容
|
||||||
*
|
*
|
||||||
* @param pageParams 账单信息分页参数
|
* @param pageParams 账单信息分页参数
|
||||||
* @param dto 账单信息查询表单
|
* @param dto 账单信息查询表单
|
||||||
|
@ -40,15 +40,6 @@ public interface BillMapper extends BaseMapper<Bill> {
|
||||||
*/
|
*/
|
||||||
IPage<BillVo> selectListByPage(@Param("page") Page<Bill> pageParams, @Param("dto") BillDto dto);
|
IPage<BillVo> selectListByPage(@Param("page") Page<Bill> pageParams, @Param("dto") BillDto dto);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询账单信息内容
|
|
||||||
*
|
|
||||||
* @param dto 账单信息查询表单
|
|
||||||
* @return 账单信息结果
|
|
||||||
*/
|
|
||||||
List<BillVo> selectListByBillNotification(@Param("dto") BillDto dto);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 账单收入和支出
|
* 账单收入和支出
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
package cn.bunny.services.quartz;
|
||||||
|
|
||||||
|
import cn.bunny.services.aop.annotation.QuartzSchedulers;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.quartz.Job;
|
||||||
|
import org.quartz.JobDataMap;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@QuartzSchedulers(type = "backup", description = "数据库备份(仅限本地docker中MySQL)")
|
||||||
|
@Component
|
||||||
|
public class DatabaseBackupJob implements Job {
|
||||||
|
|
||||||
|
@Value("${bunny.backPath}")
|
||||||
|
private String backPath;
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public void execute(JobExecutionContext context) {
|
||||||
|
// 读取资源目录下脚本文件并写入到主机中
|
||||||
|
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("static/backup.sh")) {
|
||||||
|
if (inputStream == null) return;
|
||||||
|
byte[] bytes = inputStream.readAllBytes();
|
||||||
|
Files.write(Path.of(backPath + "/backup.sh"), bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行脚本
|
||||||
|
System.setProperty("TERM", "xterm");
|
||||||
|
ProcessBuilder processBuilder = new ProcessBuilder("sh", backPath + "/backup.sh");
|
||||||
|
processBuilder.redirectErrorStream(true);
|
||||||
|
Process process = processBuilder.start();
|
||||||
|
|
||||||
|
// 执行命令
|
||||||
|
ProcessHandle handle = process.toHandle();
|
||||||
|
|
||||||
|
// 执行任务的pid
|
||||||
|
long pid = handle.pid();
|
||||||
|
|
||||||
|
// 执行任务系统信息
|
||||||
|
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
|
||||||
|
Map<String, String> environment = processBuilder.environment();
|
||||||
|
String info = handle.info().toString();
|
||||||
|
jobDataMap.put("pid", pid);
|
||||||
|
jobDataMap.put("systemInfo", info);
|
||||||
|
jobDataMap.put("environment", environment);
|
||||||
|
|
||||||
|
// 进程是否结束
|
||||||
|
if (process.waitFor(5, TimeUnit.MINUTES)) {
|
||||||
|
int waitedFor = process.waitFor();
|
||||||
|
jobDataMap.put("existCode", waitedFor);
|
||||||
|
} else process.destroyForcibly();
|
||||||
|
|
||||||
|
// 执行后读取内容
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
String line;
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
stringBuilder.append(line);
|
||||||
|
System.out.println(line);
|
||||||
|
}
|
||||||
|
jobDataMap.put("output", stringBuilder.toString());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,29 +0,0 @@
|
||||||
package cn.bunny.services.quartz;
|
|
||||||
|
|
||||||
import cn.bunny.services.aop.annotation.QuartzSchedulers;
|
|
||||||
import cn.bunny.services.factory.BillFactory;
|
|
||||||
import org.quartz.Job;
|
|
||||||
import org.quartz.JobExecutionContext;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
@QuartzSchedulers(type = "email-bill-mouth-report", description = "账单邮件任务-月")
|
|
||||||
@Component
|
|
||||||
public class MailBillReportByMouth implements Job {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private BillFactory billFactory;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(JobExecutionContext jobExecutionContext) {
|
|
||||||
LocalDate today = LocalDate.now();
|
|
||||||
|
|
||||||
// 这个日期的开始月份和结束月份
|
|
||||||
LocalDate startOfMouth = today.withDayOfMonth(1);
|
|
||||||
LocalDate endOfMouth = today.withDayOfMonth(today.lengthOfMonth());
|
|
||||||
|
|
||||||
billFactory.billReport(startOfMouth, endOfMouth);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package cn.bunny.services.quartz;
|
|
||||||
|
|
||||||
import cn.bunny.services.aop.annotation.QuartzSchedulers;
|
|
||||||
import cn.bunny.services.factory.BillFactory;
|
|
||||||
import org.quartz.Job;
|
|
||||||
import org.quartz.JobExecutionContext;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.time.DayOfWeek;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.temporal.TemporalAdjusters;
|
|
||||||
|
|
||||||
@QuartzSchedulers(type = "email-bill-week-report", description = "账单邮件任务-周")
|
|
||||||
@Component
|
|
||||||
public class MailBillReportByWeek implements Job {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private BillFactory billFactory;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(JobExecutionContext jobExecutionContext) {
|
|
||||||
LocalDate today = LocalDate.now();
|
|
||||||
|
|
||||||
// 这周的开始日期和结束日期
|
|
||||||
LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
||||||
LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
|
||||||
|
|
||||||
billFactory.billReport(startOfWeek, endOfWeek);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package cn.bunny.services.quartz;
|
||||||
|
|
||||||
|
import cn.bunny.services.aop.annotation.QuartzSchedulers;
|
||||||
|
import cn.bunny.services.factory.EmailFactory;
|
||||||
|
import org.quartz.Job;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.quartz.JobExecutionException;
|
||||||
|
|
||||||
|
@QuartzSchedulers(type = "email-overhead-report", description = "定时邮件任务")
|
||||||
|
public class MailingJob implements Job {
|
||||||
|
@Override
|
||||||
|
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||||
|
EmailFactory emailFactory = new EmailFactory();
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,6 @@ import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
||||||
import cn.bunny.dao.vo.system.email.EmailTemplateVo;
|
import cn.bunny.dao.vo.system.email.EmailTemplateVo;
|
||||||
import cn.bunny.services.mapper.email.EmailTemplateMapper;
|
import cn.bunny.services.mapper.email.EmailTemplateMapper;
|
||||||
import cn.bunny.services.service.email.EmailTemplateService;
|
import cn.bunny.services.service.email.EmailTemplateService;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
@ -19,9 +18,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -32,7 +33,6 @@ import java.util.*;
|
||||||
* @since 2024-10-10 21:24:08
|
* @since 2024-10-10 21:24:08
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Transactional
|
|
||||||
public class EmailTemplateServiceImpl extends ServiceImpl<EmailTemplateMapper, EmailTemplate> implements EmailTemplateService {
|
public class EmailTemplateServiceImpl extends ServiceImpl<EmailTemplateMapper, EmailTemplate> implements EmailTemplateService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,22 +45,9 @@ public class EmailTemplateServiceImpl extends ServiceImpl<EmailTemplateMapper, E
|
||||||
@Override
|
@Override
|
||||||
public PageResult<EmailTemplateVo> getEmailTemplateList(Page<EmailTemplate> pageParams, EmailTemplateDto dto) {
|
public PageResult<EmailTemplateVo> getEmailTemplateList(Page<EmailTemplate> pageParams, EmailTemplateDto dto) {
|
||||||
IPage<EmailTemplateVo> page = baseMapper.selectListByPage(pageParams, dto);
|
IPage<EmailTemplateVo> page = baseMapper.selectListByPage(pageParams, dto);
|
||||||
List<EmailTemplateVo> emailTemplateVos = page.getRecords().stream()
|
|
||||||
.map(emailTemplateVo -> {
|
|
||||||
EmailTemplateVo vo = new EmailTemplateVo();
|
|
||||||
BeanUtils.copyProperties(emailTemplateVo, vo);
|
|
||||||
|
|
||||||
// 查找枚举内容并设置详情
|
|
||||||
List<EmailTemplateEnums> emailTemplateEnums = Arrays.stream(EmailTemplateEnums.values())
|
|
||||||
.filter(enums -> enums.getType().equals(vo.getType()))
|
|
||||||
.toList();
|
|
||||||
vo.setSummary(emailTemplateEnums.get(0).getSummary());
|
|
||||||
return vo;
|
|
||||||
})
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
return PageResult.<EmailTemplateVo>builder()
|
return PageResult.<EmailTemplateVo>builder()
|
||||||
.list(emailTemplateVos)
|
.list(page.getRecords())
|
||||||
.pageNo(page.getCurrent())
|
.pageNo(page.getCurrent())
|
||||||
.pageSize(page.getSize())
|
.pageSize(page.getSize())
|
||||||
.total(page.getTotal())
|
.total(page.getTotal())
|
||||||
|
@ -74,28 +61,9 @@ public class EmailTemplateServiceImpl extends ServiceImpl<EmailTemplateMapper, E
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addEmailTemplate(@Valid EmailTemplateAddDto dto) {
|
public void addEmailTemplate(@Valid EmailTemplateAddDto dto) {
|
||||||
String type = dto.getType();
|
|
||||||
|
|
||||||
// 保存数据
|
// 保存数据
|
||||||
EmailTemplate emailTemplate = new EmailTemplate();
|
EmailTemplate emailTemplate = new EmailTemplate();
|
||||||
BeanUtils.copyProperties(dto, emailTemplate);
|
BeanUtils.copyProperties(dto, emailTemplate);
|
||||||
|
|
||||||
// 判断当前类型是否已有默认,如果是不设置为默认直接保存
|
|
||||||
if (!dto.getIsDefault()) {
|
|
||||||
save(emailTemplate);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LambdaQueryWrapper<EmailTemplate> emailTemplateLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
emailTemplateLambdaQueryWrapper.eq(EmailTemplate::getType, type);
|
|
||||||
emailTemplateLambdaQueryWrapper.eq(EmailTemplate::getIsDefault, Boolean.TRUE);
|
|
||||||
List<EmailTemplate> emailTemplateList = list(emailTemplateLambdaQueryWrapper);
|
|
||||||
|
|
||||||
// 更新列表
|
|
||||||
List<EmailTemplate> updateList = emailTemplateList.stream().map(template -> template.setIsDefault(false)).toList();
|
|
||||||
if (!updateList.isEmpty()) {
|
|
||||||
updateBatchById(updateList);
|
|
||||||
}
|
|
||||||
save(emailTemplate);
|
save(emailTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,8 +74,6 @@ public class EmailTemplateServiceImpl extends ServiceImpl<EmailTemplateMapper, E
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void updateEmailTemplate(@Valid EmailTemplateUpdateDto dto) {
|
public void updateEmailTemplate(@Valid EmailTemplateUpdateDto dto) {
|
||||||
String type = dto.getType();
|
|
||||||
|
|
||||||
// 查询是否有这个模板
|
// 查询是否有这个模板
|
||||||
List<EmailTemplate> emailTemplateList = list(Wrappers.<EmailTemplate>lambdaQuery().eq(EmailTemplate::getId, dto.getId()));
|
List<EmailTemplate> emailTemplateList = list(Wrappers.<EmailTemplate>lambdaQuery().eq(EmailTemplate::getId, dto.getId()));
|
||||||
if (emailTemplateList.isEmpty()) throw new AuthCustomerException(ResultCodeEnum.DATA_NOT_EXIST);
|
if (emailTemplateList.isEmpty()) throw new AuthCustomerException(ResultCodeEnum.DATA_NOT_EXIST);
|
||||||
|
@ -115,31 +81,7 @@ public class EmailTemplateServiceImpl extends ServiceImpl<EmailTemplateMapper, E
|
||||||
// 更新内容
|
// 更新内容
|
||||||
EmailTemplate emailTemplate = new EmailTemplate();
|
EmailTemplate emailTemplate = new EmailTemplate();
|
||||||
BeanUtils.copyProperties(dto, emailTemplate);
|
BeanUtils.copyProperties(dto, emailTemplate);
|
||||||
|
updateById(emailTemplate);
|
||||||
// 判断当前类型是否已有默认,如果是不设置为默认直接保存
|
|
||||||
List<EmailTemplate> updateList = new ArrayList<>();
|
|
||||||
if (dto.getIsDefault()) {
|
|
||||||
LambdaQueryWrapper<EmailTemplate> emailTemplateLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
emailTemplateLambdaQueryWrapper.eq(EmailTemplate::getType, type);
|
|
||||||
emailTemplateLambdaQueryWrapper.eq(EmailTemplate::getIsDefault, Boolean.TRUE);
|
|
||||||
|
|
||||||
// 更新数据列表
|
|
||||||
List<EmailTemplate> checkEmailTemplateList = list(emailTemplateLambdaQueryWrapper);
|
|
||||||
updateList = new ArrayList<>(checkEmailTemplateList.stream().map(template -> template.setIsDefault(false)).toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新数据
|
|
||||||
updateList.add(emailTemplate);
|
|
||||||
updateBatchById(updateList);
|
|
||||||
|
|
||||||
// 默认邮件
|
|
||||||
List<EmailTemplate> emailTemplates = list(Wrappers.<EmailTemplate>lambdaQuery().eq(EmailTemplate::getType, type));
|
|
||||||
List<EmailTemplate> isEmailTemplateListEmpty = emailTemplates.stream().filter(template -> template.getIsDefault().equals(true)).toList();
|
|
||||||
if (isEmailTemplateListEmpty.isEmpty()) {
|
|
||||||
EmailTemplate template = emailTemplates.get(0);
|
|
||||||
template.setIsDefault(Boolean.TRUE);
|
|
||||||
updateById(template);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -115,11 +115,4 @@ public interface BillService extends IService<Bill> {
|
||||||
* @param file 文件
|
* @param file 文件
|
||||||
*/
|
*/
|
||||||
void importBill(MultipartFile file);
|
void importBill(MultipartFile file);
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送账单提醒
|
|
||||||
*
|
|
||||||
* @param type 账单类型
|
|
||||||
*/
|
|
||||||
void sendBillReport(String type);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,6 @@ import cn.bunny.dao.dto.financial.bill.excel.BillImportByUserDto;
|
||||||
import cn.bunny.dao.dto.financial.bill.user.BillAddByUserDto;
|
import cn.bunny.dao.dto.financial.bill.user.BillAddByUserDto;
|
||||||
import cn.bunny.dao.dto.financial.bill.user.BillUpdateByUserDto;
|
import cn.bunny.dao.dto.financial.bill.user.BillUpdateByUserDto;
|
||||||
import cn.bunny.dao.entity.financial.Bill;
|
import cn.bunny.dao.entity.financial.Bill;
|
||||||
import cn.bunny.dao.entity.system.AdminUser;
|
|
||||||
import cn.bunny.dao.entity.system.EmailTemplate;
|
|
||||||
import cn.bunny.dao.pojo.enums.EmailTemplateEnums;
|
|
||||||
import cn.bunny.dao.pojo.result.PageResult;
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
||||||
import cn.bunny.dao.vo.financial.admin.BillVo;
|
import cn.bunny.dao.vo.financial.admin.BillVo;
|
||||||
|
@ -24,15 +21,12 @@ import cn.bunny.dao.vo.financial.user.expendAndIncome.ExpendWithIncomeListVo;
|
||||||
import cn.bunny.services.excel.BillAddUserListener;
|
import cn.bunny.services.excel.BillAddUserListener;
|
||||||
import cn.bunny.services.factory.BillFactory;
|
import cn.bunny.services.factory.BillFactory;
|
||||||
import cn.bunny.services.factory.HomeFactory;
|
import cn.bunny.services.factory.HomeFactory;
|
||||||
import cn.bunny.services.mapper.email.EmailTemplateMapper;
|
|
||||||
import cn.bunny.services.mapper.financial.BillMapper;
|
import cn.bunny.services.mapper.financial.BillMapper;
|
||||||
import cn.bunny.services.mapper.financial.CategoryMapper;
|
import cn.bunny.services.mapper.financial.CategoryMapper;
|
||||||
import cn.bunny.services.mapper.message.MessageMapper;
|
import cn.bunny.services.mapper.message.MessageMapper;
|
||||||
import cn.bunny.services.mapper.message.MessageReceivedMapper;
|
import cn.bunny.services.mapper.message.MessageReceivedMapper;
|
||||||
import cn.bunny.services.mapper.system.UserMapper;
|
|
||||||
import cn.bunny.services.service.financial.BillService;
|
import cn.bunny.services.service.financial.BillService;
|
||||||
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.EasyExcel;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
@ -41,13 +35,10 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.DayOfWeek;
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.temporal.TemporalAdjusters;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -70,16 +61,10 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CategoryMapper categoryMapper;
|
private CategoryMapper categoryMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessageMapper messageMapper;
|
private MessageMapper messageMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessageReceivedMapper messageReceivedMapper;
|
private MessageReceivedMapper messageReceivedMapper;
|
||||||
@Autowired
|
|
||||||
private UserMapper userMapper;
|
|
||||||
@Autowired
|
|
||||||
private EmailTemplateMapper emailTemplateMapper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 账单信息 服务实现类
|
* * 账单信息 服务实现类
|
||||||
|
@ -278,55 +263,7 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
|
||||||
try {
|
try {
|
||||||
EasyExcel.read(file.getInputStream(), BillImportByUserDto.class, new BillAddUserListener(categoryMapper, messageMapper, messageReceivedMapper, this)).sheet().doRead();
|
EasyExcel.read(file.getInputStream(), BillImportByUserDto.class, new BillAddUserListener(categoryMapper, messageMapper, messageReceivedMapper, this)).sheet().doRead();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new AuthCustomerException(ResultCodeEnum.UPLOAD_ERROR);
|
throw new AuthCustomerException(ResultCodeEnum.UPDATE_ERROR);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送账单提醒
|
|
||||||
*
|
|
||||||
* @param type 账单类型
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void sendBillReport(String type) {
|
|
||||||
LocalDate today = LocalDate.now();
|
|
||||||
|
|
||||||
if (!StringUtils.hasText(type)) {
|
|
||||||
throw new AuthCustomerException(ResultCodeEnum.ILLEGAL_DATA_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 这个日期的开始星期和结束星期
|
|
||||||
LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
||||||
LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
|
||||||
|
|
||||||
// 这个日期的开始月份和结束月份
|
|
||||||
LocalDate startOfMouth = today.withDayOfMonth(1);
|
|
||||||
LocalDate endOfMouth = today.withDayOfMonth(today.lengthOfMonth());
|
|
||||||
|
|
||||||
// 查询当前用户
|
|
||||||
Long userId = BaseContext.getUserId();
|
|
||||||
AdminUser adminUser = userMapper.selectById(userId);
|
|
||||||
|
|
||||||
// 查询验证码邮件模板
|
|
||||||
LambdaQueryWrapper<EmailTemplate> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
lambdaQueryWrapper.eq(EmailTemplate::getIsDefault, true);
|
|
||||||
lambdaQueryWrapper.eq(EmailTemplate::getType, EmailTemplateEnums.BILL_WEEK_NOTIFICATION.getType());
|
|
||||||
EmailTemplate emailTemplate = emailTemplateMapper.selectOne(lambdaQueryWrapper);
|
|
||||||
|
|
||||||
// 查询当前用户账单数据
|
|
||||||
BillDto billDto = new BillDto();
|
|
||||||
billDto.setUserId(userId);
|
|
||||||
|
|
||||||
if (type.equals("week")) {
|
|
||||||
billDto.setStartDate(startOfWeek);
|
|
||||||
billDto.setEndDate(endOfWeek.plusDays(1));
|
|
||||||
List<BillVo> billVoList = baseMapper.selectListByBillNotification(billDto);
|
|
||||||
billFactory.executeSendEmail(startOfWeek, endOfWeek, billVoList, adminUser, emailTemplate);
|
|
||||||
} else if (type.equals("mouth")) {
|
|
||||||
billDto.setStartDate(startOfMouth);
|
|
||||||
billDto.setEndDate(endOfMouth.plusDays(1));
|
|
||||||
List<BillVo> billVoList = baseMapper.selectListByBillNotification(billDto);
|
|
||||||
billFactory.executeSendEmail(startOfMouth, endOfMouth, billVoList, adminUser, emailTemplate);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package cn.bunny.services.service.schedule;
|
||||||
import cn.bunny.dao.dto.quartz.SchedulersOperationDto;
|
import cn.bunny.dao.dto.quartz.SchedulersOperationDto;
|
||||||
import cn.bunny.dao.dto.quartz.schedule.SchedulersAddDto;
|
import cn.bunny.dao.dto.quartz.schedule.SchedulersAddDto;
|
||||||
import cn.bunny.dao.dto.quartz.schedule.SchedulersDto;
|
import cn.bunny.dao.dto.quartz.schedule.SchedulersDto;
|
||||||
import cn.bunny.dao.dto.quartz.schedule.SchedulersUpdateDto;
|
|
||||||
import cn.bunny.dao.entity.quartz.Schedulers;
|
import cn.bunny.dao.entity.quartz.Schedulers;
|
||||||
import cn.bunny.dao.pojo.result.PageResult;
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
import cn.bunny.dao.vo.quartz.SchedulersVo;
|
import cn.bunny.dao.vo.quartz.SchedulersVo;
|
||||||
|
@ -65,11 +64,4 @@ public interface SchedulersService extends IService<Schedulers> {
|
||||||
* @return 所有调度任务内容
|
* @return 所有调度任务内容
|
||||||
*/
|
*/
|
||||||
List<Map<String, String>> getAllScheduleJobList();
|
List<Map<String, String>> getAllScheduleJobList();
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新任务
|
|
||||||
*
|
|
||||||
* @param dto 更新任务表单
|
|
||||||
*/
|
|
||||||
void updateSchedulers(SchedulersUpdateDto dto);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,8 @@ import cn.bunny.common.service.exception.AuthCustomerException;
|
||||||
import cn.bunny.dao.dto.quartz.SchedulersOperationDto;
|
import cn.bunny.dao.dto.quartz.SchedulersOperationDto;
|
||||||
import cn.bunny.dao.dto.quartz.schedule.SchedulersAddDto;
|
import cn.bunny.dao.dto.quartz.schedule.SchedulersAddDto;
|
||||||
import cn.bunny.dao.dto.quartz.schedule.SchedulersDto;
|
import cn.bunny.dao.dto.quartz.schedule.SchedulersDto;
|
||||||
import cn.bunny.dao.dto.quartz.schedule.SchedulersUpdateDto;
|
|
||||||
import cn.bunny.dao.entity.quartz.Schedulers;
|
import cn.bunny.dao.entity.quartz.Schedulers;
|
||||||
import cn.bunny.dao.pojo.result.PageResult;
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
|
||||||
import cn.bunny.dao.vo.quartz.SchedulersVo;
|
import cn.bunny.dao.vo.quartz.SchedulersVo;
|
||||||
import cn.bunny.services.aop.AnnotationScanner;
|
import cn.bunny.services.aop.AnnotationScanner;
|
||||||
import cn.bunny.services.aop.annotation.QuartzSchedulers;
|
import cn.bunny.services.aop.annotation.QuartzSchedulers;
|
||||||
|
@ -22,7 +20,10 @@ import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -91,36 +92,6 @@ public class SchedulersServiceImpl extends ServiceImpl<SchedulersMapper, Schedul
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新任务
|
|
||||||
*
|
|
||||||
* @param dto 更新任务表单
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void updateSchedulers(SchedulersUpdateDto dto) {
|
|
||||||
String jobName = dto.getJobName();
|
|
||||||
String jobGroup = dto.getJobGroup();
|
|
||||||
String cronExpression = dto.getCronExpression();
|
|
||||||
|
|
||||||
CronTrigger trigger = TriggerBuilder.newTrigger()
|
|
||||||
.withIdentity(jobName, jobGroup)
|
|
||||||
.withDescription(dto.getDescription())
|
|
||||||
.startNow()
|
|
||||||
.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try {
|
|
||||||
TriggerKey key = new TriggerKey(jobName, jobGroup);
|
|
||||||
Trigger oldTrigger = scheduler.getTrigger(key);
|
|
||||||
Date date = scheduler.rescheduleJob(oldTrigger.getKey(), trigger);
|
|
||||||
if (date == null) {
|
|
||||||
throw new AuthCustomerException(ResultCodeEnum.UPDATE_ERROR);
|
|
||||||
}
|
|
||||||
} catch (SchedulerException e) {
|
|
||||||
throw new AuthCustomerException(ResultCodeEnum.UPDATE_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加Schedulers视图
|
* 添加Schedulers视图
|
||||||
*
|
*
|
||||||
|
|
|
@ -134,12 +134,4 @@ public interface UserService extends IService<AdminUser> {
|
||||||
* @param password 更新本地用户密码
|
* @param password 更新本地用户密码
|
||||||
*/
|
*/
|
||||||
void updateUserPasswordByLocalUser(@Valid String password);
|
void updateUserPasswordByLocalUser(@Valid String password);
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新用户账单是否启用
|
|
||||||
*
|
|
||||||
* @param type 类型
|
|
||||||
* @param status 状态
|
|
||||||
*/
|
|
||||||
void updateUserBillReportByLocalUser(String type, Boolean status);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -327,7 +327,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public LoginVo getUserinfo() {
|
public LoginVo getUserinfo() {
|
||||||
|
|
||||||
return BaseContext.getLoginVo();
|
return BaseContext.getLoginVo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,34 +388,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
||||||
redisTemplate.delete(RedisUserConstant.getAdminLoginInfoPrefix(adminUser.getUsername()));
|
redisTemplate.delete(RedisUserConstant.getAdminLoginInfoPrefix(adminUser.getUsername()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新用户账单是否启用
|
|
||||||
*
|
|
||||||
* @param type 类型
|
|
||||||
* @param status 状态
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void updateUserBillReportByLocalUser(String type, Boolean status) {
|
|
||||||
AdminUser adminUser = new AdminUser();
|
|
||||||
adminUser.setId(BaseContext.getUserId());
|
|
||||||
|
|
||||||
if (!StringUtils.hasText(type)) {
|
|
||||||
throw new AuthCustomerException(ResultCodeEnum.ILLEGAL_DATA_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 判断类型是什么
|
|
||||||
if (type.equals("week")) {
|
|
||||||
adminUser.setWeekBillReport(status);
|
|
||||||
} else if (type.equals("mouth")) {
|
|
||||||
adminUser.setMouthBillReport(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateById(adminUser);
|
|
||||||
|
|
||||||
adminUser = getById(adminUser.getId());
|
|
||||||
userFactory.buildUserVo(adminUser, RedisUserConstant.REDIS_EXPIRATION_TIME);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 用户信息 服务实现类
|
* * 用户信息 服务实现类
|
||||||
*
|
*
|
||||||
|
|
|
@ -46,9 +46,6 @@
|
||||||
<if test="dto.type != null and dto.type != ''">
|
<if test="dto.type != null and dto.type != ''">
|
||||||
and template.type like CONCAT('%',#{dto.type},'%')
|
and template.type like CONCAT('%',#{dto.type},'%')
|
||||||
</if>
|
</if>
|
||||||
<if test="dto.isDefault != null and dto.isDefault != ''">
|
|
||||||
and template.isDefault = #{dto.isDefault}
|
|
||||||
</if>
|
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
|
@ -75,41 +75,6 @@
|
||||||
order by b.amount desc
|
order by b.amount desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- 查询账单信息内容 -->
|
|
||||||
<select id="selectListByBillNotification" resultType="cn.bunny.dao.vo.financial.admin.BillVo">
|
|
||||||
select
|
|
||||||
base.*,
|
|
||||||
category.category_name,
|
|
||||||
category.id as category_id,
|
|
||||||
baseuser.username as username,
|
|
||||||
create_user.username as create_username,
|
|
||||||
update_user.username as update_username
|
|
||||||
from t_bill base
|
|
||||||
left join t_category category on category.id = base.category_id
|
|
||||||
left join sys_user baseuser on baseuser.id = base.user_id
|
|
||||||
left join sys_user create_user on create_user.id = base.create_user
|
|
||||||
left join sys_user update_user on update_user.id = base.update_user
|
|
||||||
<where>
|
|
||||||
base.is_deleted = 0
|
|
||||||
<if test="dto.userId != null and dto.userId != ''">
|
|
||||||
and base.user_id = #{dto.userId}
|
|
||||||
</if>
|
|
||||||
<if test="dto.type != null and dto.type != ''">
|
|
||||||
and base.type = #{dto.type}
|
|
||||||
</if>
|
|
||||||
<if test="dto.description != null and dto.description != ''">
|
|
||||||
and base.description like CONCAT('%',#{dto.description},'%')
|
|
||||||
</if>
|
|
||||||
<if test="dto.amount != null">
|
|
||||||
and base.amount like CONCAT('%',#{dto.amount},'%')
|
|
||||||
</if>
|
|
||||||
<if test="dto.startDate != null and dto.endDate != null">
|
|
||||||
and base.transaction_date between #{dto.startDate} and #{dto.endDate}
|
|
||||||
</if>
|
|
||||||
</where>
|
|
||||||
order by base.transaction_date
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<!-- 物理删除账单信息 -->
|
<!-- 物理删除账单信息 -->
|
||||||
<delete id="deleteBatchIdsWithPhysics">
|
<delete id="deleteBatchIdsWithPhysics">
|
||||||
delete
|
delete
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# 设置备份文件存放目录
|
||||||
|
backup_dir="/home/backup/"
|
||||||
|
# 获取当前时间并格式化为 yyyy_MM_dd_HH_mm_ss_SSS 格式
|
||||||
|
timestamp=$(date +"%Y_%m_%d_%H_%M_%S_%3N")
|
||||||
|
# 设置数据库用户名、密码和数据库名
|
||||||
|
db_user="root"
|
||||||
|
db_pass="02120212"
|
||||||
|
db_name="auth_admin"
|
||||||
|
# 设置备份文件名
|
||||||
|
backup_file="${backup_dir}backup_${db_name}_${timestamp}.sql"
|
||||||
|
# 执行备份命令
|
||||||
|
docker exec -i slave_3304 bash -c "mysqldump -u ${db_user} -p${db_pass} ${db_name} > ${backup_file}"
|
||||||
|
# 输出备份文件路径
|
||||||
|
echo "Backup completed: ${backup_file}"
|
|
@ -1,15 +0,0 @@
|
||||||
package cn.bunny.services;
|
|
||||||
|
|
||||||
import cn.bunny.dao.pojo.enums.EmailTemplateEnums;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class EnumsTest {
|
|
||||||
|
|
||||||
@org.junit.jupiter.api.Test
|
|
||||||
void emailEnums() {
|
|
||||||
List<EmailTemplateEnums> verificationCode = Arrays.stream(EmailTemplateEnums.values()).filter(emailTemplateEnums -> emailTemplateEnums.getType().equals("verification_code")).toList();
|
|
||||||
System.out.println(verificationCode.get(0).getSummary());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,115 +0,0 @@
|
||||||
package cn.bunny.services.quartz;
|
|
||||||
|
|
||||||
import cn.bunny.dao.dto.financial.bill.BillDto;
|
|
||||||
import cn.bunny.dao.entity.system.AdminUser;
|
|
||||||
import cn.bunny.dao.entity.system.EmailTemplate;
|
|
||||||
import cn.bunny.dao.pojo.constant.LocalDateTimeConstant;
|
|
||||||
import cn.bunny.dao.pojo.enums.EmailTemplateEnums;
|
|
||||||
import cn.bunny.dao.vo.financial.admin.BillVo;
|
|
||||||
import cn.bunny.services.factory.EmailFactory;
|
|
||||||
import cn.bunny.services.mapper.email.EmailTemplateMapper;
|
|
||||||
import cn.bunny.services.mapper.financial.BillMapper;
|
|
||||||
import cn.bunny.services.mapper.system.UserMapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.time.DayOfWeek;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.time.temporal.TemporalAdjusters;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class MailBillReportByWeekTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EmailTemplateMapper emailTemplateMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private EmailFactory emailFactory;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private BillMapper billMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserMapper userMapper;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void executeWeekBillNotification() {
|
|
||||||
long userId = 1849444494908125181L;
|
|
||||||
String email = "q122l@freesourcecodes.com";
|
|
||||||
LocalDate today = LocalDate.now();
|
|
||||||
LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
||||||
LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
|
||||||
|
|
||||||
// 查询当前用户信息
|
|
||||||
AdminUser adminUser = userMapper.selectById(userId);
|
|
||||||
|
|
||||||
// 查询验证码邮件模板
|
|
||||||
LambdaQueryWrapper<EmailTemplate> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
lambdaQueryWrapper.eq(EmailTemplate::getIsDefault, true);
|
|
||||||
lambdaQueryWrapper.eq(EmailTemplate::getType, EmailTemplateEnums.BILL_WEEK_NOTIFICATION.getType());
|
|
||||||
EmailTemplate emailTemplate = emailTemplateMapper.selectOne(lambdaQueryWrapper);
|
|
||||||
|
|
||||||
// 查询当前用户账单数据
|
|
||||||
BillDto billDto = new BillDto();
|
|
||||||
billDto.setUserId(userId);
|
|
||||||
billDto.setStartDate(startOfWeek);
|
|
||||||
billDto.setEndDate(endOfWeek.plusDays(1));
|
|
||||||
List<BillVo> billVoList = billMapper.selectListByBillNotification(billDto);
|
|
||||||
|
|
||||||
// 发送账单日期
|
|
||||||
String sendDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern(LocalDateTimeConstant.YYYY_MM_DD_HH_MM_SS));
|
|
||||||
String startDate = startOfWeek.format(DateTimeFormatter.ofPattern(LocalDateTimeConstant.YYYY_MM_DD));
|
|
||||||
String endDate = endOfWeek.format(DateTimeFormatter.ofPattern(LocalDateTimeConstant.YYYY_MM_DD));
|
|
||||||
|
|
||||||
// 计算总收入
|
|
||||||
double income = billVoList.stream()
|
|
||||||
.filter(billVo -> billVo.getType().equals(Byte.parseByte("1")))
|
|
||||||
.collect(Collectors.summarizingDouble(billVo -> billVo.getAmount().doubleValue()))
|
|
||||||
.getSum();
|
|
||||||
|
|
||||||
// 计算总支出
|
|
||||||
double expend = billVoList.stream()
|
|
||||||
.filter(billVo -> billVo.getType().equals(Byte.parseByte("-1")))
|
|
||||||
.collect(Collectors.summarizingDouble(billVo -> billVo.getAmount().doubleValue()))
|
|
||||||
.getSum();
|
|
||||||
|
|
||||||
// 计算盈利
|
|
||||||
double profit = income - expend;
|
|
||||||
|
|
||||||
// 计算盈利
|
|
||||||
double percentValue = (income + expend) == 0 ? 0 : expend / (income + expend);
|
|
||||||
BigDecimal percent = new BigDecimal(percentValue);
|
|
||||||
|
|
||||||
// 表格字符串
|
|
||||||
StringBuilder billTable = new StringBuilder();
|
|
||||||
billVoList.forEach(billVo -> {
|
|
||||||
String tr = " <td style=\"font-weight:bolder;\">" + billVo.getCategoryName() + "</td>\n" +
|
|
||||||
" <td style=\"color:#DC684A;font-weight:bolder;\">" + billVo.getAmount() + " ¥</td>\n" +
|
|
||||||
" <td style=\"color:#DC684A;font-weight:bolder;\">" + billVo.getDescription() + "</td>\n" +
|
|
||||||
"</tr>";
|
|
||||||
billTable.append(tr);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 替换整理参数
|
|
||||||
HashMap<String, Object> hashMap = new HashMap<>();
|
|
||||||
hashMap.put("##billName##", adminUser.getNickname());
|
|
||||||
hashMap.put("##billDate##", startDate + "~" + endDate);
|
|
||||||
hashMap.put("##income##", income);
|
|
||||||
hashMap.put("##expend##", expend);
|
|
||||||
hashMap.put("##profit##", new BigDecimal(profit).setScale(2, RoundingMode.HALF_UP));
|
|
||||||
hashMap.put("##percent##", percent.setScale(2, RoundingMode.HALF_UP));
|
|
||||||
hashMap.put("##billTable##", billTable);
|
|
||||||
hashMap.put("##sendDate##", sendDate);
|
|
||||||
|
|
||||||
emailFactory.sendEmailTemplate(email, emailTemplate, hashMap);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue