Merge branch 'release/3.0' into test/stable

This commit is contained in:
shahaibo
2024-05-17 10:22:42 +08:00
17 changed files with 294 additions and 26 deletions

View File

@@ -16,8 +16,8 @@ import org.springframework.beans.factory.annotation.Value;
public class MQConfig {
public static final String GENERATE_EXCHANGE_FANOUT = "generate-exchange";
// public static final String GENERATE_QUEUE = "generate-queue-prod";
public static final String GENERATE_QUEUE = "generate-queue-test";
public static final String GENERATE_QUEUE = "generate-queue-prod";
// public static final String GENERATE_QUEUE = "generate-queue-test";
public MQConfig() {
}

View File

@@ -2,13 +2,25 @@ package com.ai.da.common.config;
import com.ai.da.common.utils.SendEmailUtil;
import com.ai.da.mapper.AccountMapper;
import com.ai.da.mapper.TrialOrderMapper;
import com.ai.da.mapper.entity.Account;
import com.ai.da.mapper.entity.TrialOrder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
@Component
@@ -17,6 +29,14 @@ public class MyTaskScheduler {
@Resource
private AccountMapper accountMapper;
@Resource
private TrialOrderMapper trialOrderMapper;
// @PostConstruct
// public void executeWeeklyHeavyStockReport() {
// sendTrialOrderExcelToManagements();
// }
// 定时任务,每十五天执行一次
// @Scheduled(cron = "0 0 0 ? * MON")
@Scheduled(cron = "0 0 0 */15 * ?")
@@ -53,4 +73,65 @@ public class MyTaskScheduler {
}
}
}
@Scheduled(cron = "0 0 8 * * ?")
public void sendTrialOrderExcelToManagements() {
// 获取前一天日期
LocalDate yesterday = LocalDate.now().minusDays(1);
// 查询前一天的试用订单
QueryWrapper<TrialOrder> qw = new QueryWrapper<>();
qw.lambda().between(TrialOrder::getCreateTime, yesterday.atStartOfDay(), yesterday.atTime(23, 59, 59));
List<TrialOrder> trialOrders = trialOrderMapper.selectList(qw);
if (!trialOrders.isEmpty()) {
// 创建Excel工作簿
try (Workbook workbook = new XSSFWorkbook()) {
// 创建工作表
Sheet sheet = workbook.createSheet("Trial Orders");
// 创建标题行
Row headerRow = sheet.createRow(0);
headerRow.createCell(0).setCellValue("ID");
headerRow.createCell(1).setCellValue("Title");
headerRow.createCell(2).setCellValue("Surname");
headerRow.createCell(3).setCellValue("Given Name");
headerRow.createCell(4).setCellValue("Username");
headerRow.createCell(5).setCellValue("Email");
headerRow.createCell(6).setCellValue("Country");
headerRow.createCell(7).setCellValue("Occupation");
headerRow.createCell(8).setCellValue("Create Time");
headerRow.createCell(9).setCellValue("Update Time");
headerRow.createCell(10).setCellValue("Status");
// 填充数据
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
int rowNum = 1;
for (TrialOrder trialOrder : trialOrders) {
Row row = sheet.createRow(rowNum++);
row.createCell(0).setCellValue(trialOrder.getId());
row.createCell(1).setCellValue(trialOrder.getTitle());
row.createCell(2).setCellValue(trialOrder.getSurname());
row.createCell(3).setCellValue(trialOrder.getGivenName());
row.createCell(4).setCellValue(trialOrder.getUserName());
row.createCell(5).setCellValue(trialOrder.getEmail());
row.createCell(6).setCellValue(trialOrder.getCountry());
row.createCell(7).setCellValue(trialOrder.getOccupation());
row.createCell(8).setCellValue(trialOrder.getCreateTime().format(formatter));
row.createCell(9).setCellValue(trialOrder.getUpdateTime().format(formatter));
row.createCell(10).setCellValue(trialOrder.getStatus());
}
// 保存Excel文件
String fileName = "trialOrder-" + yesterday.format(DateTimeFormatter.ofPattern("yyyyMMdd")) + ".xlsx";
try (FileOutputStream fileOut = new FileOutputStream(fileName)) {
workbook.write(fileOut);
SendEmailUtil.sendExcelEmail("1023316923@qq.com", null, Files.readAllBytes(Paths.get(fileName)), fileName);
SendEmailUtil.sendExcelEmail("calvinwong@aidlab.hk", null, Files.readAllBytes(Paths.get(fileName)), fileName);
SendEmailUtil.sendExcelEmail("kaicpang.pang@connect.polyu.hk", null, Files.readAllBytes(Paths.get(fileName)), fileName);
SendEmailUtil.sendExcelEmail("kimwong@code-create.com.hk", null, Files.readAllBytes(Paths.get(fileName)), fileName);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

View File

@@ -58,7 +58,7 @@ public class AsyncCallerUtil {
return null;
} catch (InterruptedException | ExecutionException | BusinessException e) {
// 处理异常
log.error("发生错误 " + e);
log.error("发生错误 " + e, e);
// 取消定时任务
assert timeoutTask != null;
timeoutTask.cancel(true);

View File

@@ -9,12 +9,14 @@ import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.ses.v20201002.SesClient;
import com.tencentcloudapi.ses.v20201002.models.Attachment;
import com.tencentcloudapi.ses.v20201002.models.SendEmailRequest;
import com.tencentcloudapi.ses.v20201002.models.SendEmailResponse;
import com.tencentcloudapi.ses.v20201002.models.Template;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import java.util.Base64;
import java.util.Date;
/**
@@ -130,7 +132,9 @@ public class SendEmailUtil {
private final static Long YOUR_TRIAL_TEMPLATE_ID = 117214L;
private final static Long APPROVAL_TEMPLATE_ID = 117215L;
private final static Long NOTIFICATION_TEMPLATE_ID = 117216L;
public static void sendCustomEmail(String receiverAddress, String senderAddress, TrialOrder trialOrder, int emailType) {
private final static Long NOTIFICATION_CHINESE_TEMPLATE_ID = 122229L;
private final static Long TRIAL_ORDER_LIST_ID = 122273L;
public static void sendCustomEmail(String receiverAddress, String senderAddress, TrialOrder trialOrder, int emailType, String country) {
try {
// 实例化一个认证对象
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
@@ -162,7 +166,11 @@ public class SendEmailUtil {
break;
case 3:
subject = "Approval Confirmation for AiDA System Trial Access";
template.setTemplateID(NOTIFICATION_TEMPLATE_ID);
if (country.equals("China")) {
template.setTemplateID(NOTIFICATION_CHINESE_TEMPLATE_ID);
}else {
template.setTemplateID(NOTIFICATION_TEMPLATE_ID);
}
template.setTemplateData(buildNotificationData(trialOrder));
break;
default:
@@ -180,6 +188,45 @@ public class SendEmailUtil {
throw new BusinessException("failed.to.send.mail");
}
}
public static void sendExcelEmail(String receiverAddress, String senderAddress, byte[] fileContent, String fileName) {
try {
// 实例化一个认证对象
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("ses.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
SesClient client = new SesClient(cred, "ap-hongkong", clientProfile);
SendEmailRequest req = new SendEmailRequest();
if (StringUtils.isEmpty(senderAddress)) {
senderAddress = SEND_ADDRESS;
}
req.setFromEmailAddress(senderAddress);
req.setDestination(new String[]{receiverAddress});
// 根据邮件类型设置不同的主题和模板
String subject = "";
Template template = new Template();
subject = "昨日试用订单数据";
template.setTemplateID(TRIAL_ORDER_LIST_ID);
req.setSubject(subject);
req.setTemplate(template);
Attachment attachment = new Attachment();
attachment.setFileName(fileName); // 设置附件文件名
// 设置附件内容
attachment.setContent(Base64.getEncoder().encodeToString(fileContent));
req.setAttachments(new Attachment[] {attachment});
// 发送邮件
SendEmailResponse resp = client.SendEmail(req);
log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) {
log.info("邮件发送失败###{}", e.toString());
throw new BusinessException("failed.to.send.mail");
}
}
private final static Long WILLBEEXPIRED_TEMPLATE_ID = 118178L;
public static void sendWillBeExpiredEmail(Account account, String senderAddress) {
try {

View File

@@ -0,0 +1,54 @@
package com.ai.da.controller;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.response.Response;
import com.ai.da.mapper.DesignMapper;
import com.ai.da.mapper.TrialOrderMapper;
import com.ai.da.mapper.entity.TrialOrder;
import com.ai.da.model.dto.UserDesignStatisticDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@Api(tags = "便利查询")
@Slf4j
@RestController
@RequestMapping("/api/inquiry")
public class ConvenientInquiryController {
@Resource
private TrialOrderMapper trialOrderMapper;
@Resource
private DesignMapper designMapper;
@ApiOperation("获取当前所有试用用户")
@GetMapping("/getTrial")
public Response<List<TrialOrder>> getTrial(){
Long accountId = UserContext.getUserHolder().getId();
if (accountId.equals(31L) || accountId.equals(87L) || accountId.equals(83L)){
List<TrialOrder> trialOrders = trialOrderMapper.selectList(null);
return Response.success(trialOrders);
}else {
return Response.fail("Sorry, you don't have permission");
}
}
@ApiOperation("获取指定时间区间内所有用户design的使用情况")
@GetMapping("/getDesignStatistic")
public Response<List<UserDesignStatisticDTO>> getDesignStatistic(@RequestParam String startTime,@RequestParam String endTime){
Long accountId = UserContext.getUserHolder().getId();
if (accountId.equals(31L) || accountId.equals(87L) || accountId.equals(83L)){
List<UserDesignStatisticDTO> designStatistic = designMapper.getDesignStatistic(startTime, endTime);
return Response.success(designStatistic);
}else {
return Response.fail("Sorry, you don't have permission");
}
}
}

View File

@@ -42,8 +42,8 @@ public class ThirdPartyController {
@CrossOrigin
@ApiOperation(value = "Add user information")
@PostMapping("/addTrialUser")
public Response<Boolean> addTrialUser(@RequestBody AccountTrialDTO accountTrialDTO) {
return Response.success(accountService.addTrialUser(accountTrialDTO));
public Response<Boolean> addTrialUser(@RequestBody AccountTrialDTO accountTrialDTO, HttpServletRequest request) {
return Response.success(accountService.addTrialUser(accountTrialDTO, request));
}
@CrossOrigin

View File

@@ -1,8 +1,10 @@
package com.ai.da.mapper;
import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.entity.Collection;
import com.ai.da.mapper.entity.Design;
import com.ai.da.model.dto.UserDesignStatisticDTO;
import java.util.List;
/**
* Mapper 接口
@@ -14,4 +16,6 @@ public interface DesignMapper extends CommonMapper<Design> {
//返回插入数据后生成的主键
Long insertDesign(Design design);
List<UserDesignStatisticDTO> getDesignStatistic(String startTime, String endTime);
}

View File

@@ -64,4 +64,5 @@ public class TrialOrder implements Serializable {
*/
private Integer status;
private Integer isDeleted;
private String ip;
}

View File

@@ -0,0 +1,17 @@
package com.ai.da.model.dto;
import lombok.Data;
@Data
public class UserDesignStatisticDTO {
private Long accountId;
private Long useDesignTimes;
private String userEmail;
private String userName;
private String isTrial;
}

View File

@@ -2295,6 +2295,7 @@ public class PythonService {
Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful");
if (result && jsonObject.get("code").equals(200)) {
log.info("Generate##responseObject###{}", jsonObject);
return setGenerateImageList(jsonObject.getJSONObject("data"));
}
log.info("generateSketchOrPrintPrint失败###{}", jsonObject);

View File

@@ -102,7 +102,7 @@ public interface AccountService extends IService<Account> {
Boolean completeGuidance();
Boolean addTrialUser(AccountTrialDTO accountTrialDTO);
Boolean addTrialUser(AccountTrialDTO accountTrialDTO, HttpServletRequest request);
IPage<TrialOrder> trialOrderList(TrialOrderDTO trialOrderDTO);

View File

@@ -9,9 +9,7 @@ import com.ai.da.common.response.ResultEnum;
import com.ai.da.common.security.jwt.JWTTokenHelper;
import com.ai.da.common.utils.*;
import com.ai.da.mapper.AccountMapper;
import com.ai.da.mapper.LibraryMapper;
import com.ai.da.mapper.TrialOrderMapper;
import com.ai.da.mapper.UserLikeGroupMapper;
import com.ai.da.mapper.entity.Account;
import com.ai.da.mapper.entity.AccountLoginLog;
import com.ai.da.mapper.entity.TrialOrder;
@@ -32,7 +30,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
@@ -289,8 +286,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
private Account getOneByEmail(String email) {
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Account::getUserEmail, email);
queryWrapper.lambda().last("limit 1");
queryWrapper.eq("BINARY user_email", email);
List<Account> accountList = accountMapper.selectList(queryWrapper);
if (CollectionUtil.isEmpty(accountList)) {
throw new BusinessException("email.does.not.exist", ResultEnum.PROMPT.getCode());
@@ -298,6 +294,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
return accountList.get(0);
}
private Account getOneByUserName(String userName) {
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Account::getUserName, userName);
@@ -468,7 +465,20 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
@Override
public Boolean addTrialUser(AccountTrialDTO accountTrialDTO) {
public Boolean addTrialUser(AccountTrialDTO accountTrialDTO, HttpServletRequest request) {
// 获取用户申请试用IP
String ipAddress = RequestInfoUtil.getIpAddress(request);
// 先检测试用订单
QueryWrapper<TrialOrder> trialOrderQueryWrapper = new QueryWrapper<>();
trialOrderQueryWrapper.lambda().eq(TrialOrder::getIp, ipAddress);
trialOrderQueryWrapper.lambda().and(wrapper ->
wrapper.eq(TrialOrder::getEmail, accountTrialDTO.getEmail())
.or() // OR
.like(TrialOrder::getUserName, accountTrialDTO.getUserName()));
List<TrialOrder> trialOrders = trialOrderMapper.selectList(trialOrderQueryWrapper);
if (CollectionUtil.isNotEmpty(trialOrders)) {
throw new BusinessException("You have submitted a trial application, please wait for approval.");
}
// 先检测用户名和邮箱
QueryWrapper<Account> qw = new QueryWrapper<>();
qw.lambda().eq(Account::getUserEmail, accountTrialDTO.getEmail())
@@ -489,8 +499,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
TrialOrder trialOrder = CopyUtil.copyObject(accountTrialDTO, TrialOrder.class);
trialOrder.setCreateTime(LocalDateTime.now());
trialOrder.setStatus(0);
trialOrder.setIp(ipAddress);
trialOrderMapper.insert(trialOrder);
SendEmailUtil.sendCustomEmail("1023316923@qq.com", null, trialOrder,1);
// SendEmailUtil.sendCustomEmail("1023316923@qq.com", null, trialOrder,1, trialOrder.getCountry());
// SendEmailUtil.sendCustomEmail("calvinwong@aidlab.hk", null, trialOrder,1, trialOrder.getCountry());
// SendEmailUtil.sendCustomEmail("kaicpang.pang@connect.polyu.hk", null, trialOrder,1, trialOrder.getCountry());
// 判断当前的试用订单是否自动批准
if (AutoApproved.getStatus()) {
// 改变试用订单状态,新增试用用户
@@ -518,8 +531,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
accountMapper.insert(account);
}
// 发送邮件提醒用户试用用户已创建
SendEmailUtil.sendCustomEmail("1023316923@qq.com", null, trialOrder,2);
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3);
// SendEmailUtil.sendCustomEmail("1023316923@qq.com", null, trialOrder,2, trialOrder.getCountry());
// SendEmailUtil.sendCustomEmail("calvinwong@aidlab.hk", null, trialOrder,2, trialOrder.getCountry());
// SendEmailUtil.sendCustomEmail("kaicpang.pang@connect.polyu.hk", null, trialOrder,2, trialOrder.getCountry());
if (trialOrder.getCountry().equals("China")) {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry());
}else {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry());
}
}
return Boolean.TRUE;
}
@@ -566,8 +585,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
accountMapper.insert(account);
}
// 发送邮件提醒用户试用用户已创建
SendEmailUtil.sendCustomEmail("1023316923@qq.com", null, trialOrder,2);
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3);
// SendEmailUtil.sendCustomEmail("1023316923@qq.com", null, trialOrder,2, trialOrder.getCountry());
// SendEmailUtil.sendCustomEmail("calvinwong@aidlab.hk", null, trialOrder,2, trialOrder.getCountry());
// SendEmailUtil.sendCustomEmail("kaicpang.pang@connect.polyu.hk", null, trialOrder,2, trialOrder.getCountry());
if (trialOrder.getCountry().equals("China")) {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry());
}else {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry());
}
}
return Boolean.TRUE;
}