新增接口:调查问卷

This commit is contained in:
2024-06-20 10:27:04 +08:00
parent c317942447
commit 227c742f0d
12 changed files with 438 additions and 26 deletions

View File

@@ -50,7 +50,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
"/api/third/party/existNoLoginRequired","/api/third/party/getRedirectUrl",
"/api/python/flush","/api/account/healthy","/api/ali-pay/trade/notify","/api/paypal/ipn/back","/api/alipay-hk/trade/notify",
"/api/portfolio/page", "/api/portfolio/detail",
"/api/account/designWorksRegister"
"/api/account/designWorksRegister","/api/account/questionnaire"
);
@Override

View File

@@ -450,6 +450,106 @@ public class SendEmailUtil {
}
}
private final static Long QUESTIONNAIRE_FEEDBACK_EN_ID = 124151L;
private final static Long QUESTIONNAIRE_FEEDBACK_CN_ID = 124156L;
public static void questionnaireRelatedNotify(String userName, String email, String language){
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();
req.setFromEmailAddress(CODE_CREATE_SEND_ADDRESS);
req.setDestination(new String[]{email});
// 根据邮件类型设置不同的主题和模板
Template template = new Template();
String subject = "Thank You for Completing the AiDA System Survey";
template.setTemplateID(QUESTIONNAIRE_FEEDBACK_EN_ID);
if (language.equals("CN")) {
subject = "感谢您完成AiDA系统问卷调查";
template.setTemplateID(QUESTIONNAIRE_FEEDBACK_CN_ID);
}
JSONObject parameter = new JSONObject();
parameter.put("userName", userName);
template.setTemplateData(parameter.toJSONString());
req.setSubject(subject);
req.setTemplate(template);
// 发送邮件
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 NEW_USER_PAYMENT_NOTIFICATION_EN = 0L;
private final static Long NEW_USER_PAYMENT_NOTIFICATION_CN = 0L;
private final static Long RENEWAL_NOTIFICATION_FOR_OLD_USER_EN = 0L;
private final static Long RENEWAL_NOTIFICATION_FOR_OLD_USER_CN = 0L;
public static void notificationForPaidUser(String receiverAddress, int emailType, String country){
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();
req.setFromEmailAddress(SEND_ADDRESS);
req.setDestination(new String[]{receiverAddress});
// 根据邮件类型设置不同的主题和模板
String subject = "";
Template template = new Template();
switch (emailType) {
// 新用户
case 1:
subject = "Welcome to AiDA!";
if (country.equals("China")) {
template.setTemplateID(NEW_USER_PAYMENT_NOTIFICATION_CN);
}else {
template.setTemplateID(NEW_USER_PAYMENT_NOTIFICATION_EN);
}
break;
// 续费用户
case 2:
subject = "Account renewal notification";
if (country.equals("China")) {
template.setTemplateID(RENEWAL_NOTIFICATION_FOR_OLD_USER_CN);
}else {
template.setTemplateID(RENEWAL_NOTIFICATION_FOR_OLD_USER_EN);
}
break;
default:
break;
// template.setTemplateData(buildNotificationData(trialOrder, link));
}
req.setSubject(subject);
req.setTemplate(template);
// 发送邮件
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");
}
}
public static Boolean designWorksRegister(String userEmail, String randomVerifyCode) {
try {

View File

@@ -167,4 +167,14 @@ public class AccountController {
public Response<AccountLoginVO> designWorksRegisterCode(@Valid @RequestBody AccountDesignWorksRegisterDTO accountDesignWorksRegisterDTO) {
return Response.success(accountService.designWorksRegisterCode(accountDesignWorksRegisterDTO));
}
/**
* 填写调查问卷
* @return
*/
@ApiOperation(value = "填写调查问卷")
@PostMapping("/questionnaire")
public Response<Boolean> questionnaire(@Valid @RequestBody String questionnaireInfo){
return Response.success(accountService.collectQuestionnaires(questionnaireInfo));
}
}

View File

@@ -0,0 +1,7 @@
package com.ai.da.mapper.primary;
import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.primary.entity.Questionnaire;
public interface QuestionnaireMapper extends CommonMapper<Questionnaire> {
}

View File

@@ -0,0 +1,18 @@
package com.ai.da.mapper.primary.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("t_questionnaire")
public class Questionnaire extends BaseEntity{
/**
* 用户所填调查问卷结果
*/
private String questionnaireInfo;
/**
* 调查问卷标题
*/
private String title;
}

View File

@@ -0,0 +1,57 @@
package com.ai.da.model.vo;
import lombok.Data;
import java.util.List;
@Data
public class QuestionnaireVO {
/**
* 用户名
*/
private String userName;
/**
* 用户性别
*/
private String gender;
/**
* 职业
*/
private String occupation;
/**
* 国家
*/
private String country;
/**
* 电子邮件
*/
private String email;
/**
* 年龄区间
*/
private String age;
/**
* How has AiDA been helpful to you?
*/
private List<String> helpful;
/**
* What do you think AiDA should improve?
*/
private List<String> improve;
/**
* Will you subscribe to AiDA 3.0
*/
private String isSubscribe;
/**
* If NO, please share why:
*/
private List<String> reasonForNotSubscribe;
/**
* Are you currently using any design tools?
*/
private String designTools;
/**
* 用户所选语言
*/
private String language;
}

View File

@@ -134,4 +134,6 @@ public interface AccountService extends IService<Account> {
Boolean designWorksRegister(AccountDesignWorksRegisterDTO accountDesignWorksRegisterDTO);
AccountLoginVO designWorksRegisterCode(AccountDesignWorksRegisterDTO accountDesignWorksRegisterDTO);
Boolean collectQuestionnaires(String questionnaireInfo);
}

View File

@@ -30,4 +30,6 @@ public interface CreditsService extends IService<CreditsDetail> {
Boolean creditsPreDeduction(CreditsEventsEnum event, Integer num);
void taskCreditsDeduction(Long accountId, String taskId);
CreditsDetail getByAccountIdAndChangeEvent(Long accountId, String changeEvent, String changedCredits);
}

View File

@@ -3,31 +3,31 @@ package com.ai.da.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.enums.LoginTypeEnum;
import com.ai.da.common.enums.AuthenticationOperationTypeEnum;
import com.ai.da.common.enums.LoginTypeEnum;
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.primary.AccountMapper;
import com.ai.da.mapper.primary.QuestionnaireMapper;
import com.ai.da.mapper.primary.TrialOrderMapper;
import com.ai.da.mapper.primary.entity.Account;
import com.ai.da.mapper.primary.entity.AccountLoginLog;
import com.ai.da.mapper.primary.entity.TrialOrder;
import com.ai.da.mapper.primary.entity.*;
import com.ai.da.model.dto.*;
import com.ai.da.model.enums.AutoApproved;
import com.ai.da.model.enums.Language;
import com.ai.da.model.vo.AccountLoginVO;
import com.ai.da.model.vo.AccountPreLoginVO;
import com.ai.da.model.vo.AuthPrincipalVo;
import com.ai.da.service.AccountLoginLogService;
import com.ai.da.service.AccountService;
import com.ai.da.service.LibraryService;
import com.ai.da.service.UserLikeGroupService;
import com.ai.da.model.vo.QuestionnaireVO;
import com.ai.da.service.*;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@@ -36,9 +36,16 @@ import org.springframework.util.Assert;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
@@ -72,6 +79,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Resource
private TrialOrderMapper trialOrderMapper;
@Resource
private QuestionnaireMapper questionnaireMapper;
@Resource
private CreditsService creditsService;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -264,7 +276,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if (!verifyCode.equals(accountDTO.getEmailVerifyCode())) {
throw new BusinessException("verification.code.error", ResultEnum.PROMPT.getCode());
}
}else {
} else {
updatePwdByEmail(accountDTO.getPassword(), accountDTO.getEmail());
}
return Boolean.TRUE;
@@ -493,7 +505,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
if (CollectionUtil.isNotEmpty(accountList)) {
if (accountList.get(0).getIsTrial() == 1) {
throw new BusinessException("The email has already been registered", ResultEnum.PROMPT.getCode());
}else {
} else {
Account account = accountList.get(0);
if (null == account.getValidEndTime() || account.getValidEndTime() > System.currentTimeMillis()) {
throw new BusinessException("The email has already been registered", ResultEnum.PROMPT.getCode());
@@ -523,11 +535,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
account.setValidStartTime(System.currentTimeMillis());
if (link) {
account.setValidEndTime(Instant.now().plus(14, ChronoUnit.DAYS).toEpochMilli());
}else {
} else {
account.setValidEndTime(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli());
}
accountMapper.updateById(account);
}else {
} else {
account.setUserName(trialOrder.getUserName());
account.setUserPassword("Third-000000");
account.setUserEmail(trialOrder.getEmail());
@@ -535,7 +547,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
account.setValidStartTime(System.currentTimeMillis());
if (link) {
account.setValidEndTime(Instant.now().plus(14, ChronoUnit.DAYS).toEpochMilli());
}else {
} else {
account.setValidEndTime(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli());
}
account.setCreateDate(new Date());
@@ -550,7 +562,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// SendEmailUtil.sendCustomEmail("kaicpang.pang@connect.polyu.hk", null, trialOrder,2);
if (trialOrder.getCountry().equals("China")) {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry(), link);
}else {
} else {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry(), link);
}
}
@@ -584,7 +596,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
account.setValidStartTime(System.currentTimeMillis());
account.setValidEndTime(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli());
accountMapper.updateById(account);
}else {
} else {
account.setUserName(trialOrder.getUserName());
account.setUserPassword("Third-000000");
account.setUserEmail(trialOrder.getEmail());
@@ -603,7 +615,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// 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(), false);
}else {
} else {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry(), false);
}
}
@@ -707,7 +719,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
accountMapper.deleteById(accountDelete);
userToBeUpdate.setUserName(userName);
accountMapper.updateById(userToBeUpdate);
}else {
} else {
accountMapper.deleteById(accountDelete);
}
}
@@ -845,7 +857,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
"                        <body>\n" +
"                        </body>\n" +
"                            <script>\n" +
"                                window.location.href = 'https://polyu.aida.com.hk?"+id+"';\n" +
"                                window.location.href = 'https://polyu.aida.com.hk?" + id + "';\n" +
"                            </script>\n" +
"                        </html>";
}
@@ -889,7 +901,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
throw new BusinessException("Illegal serial number.");
}
queryWrapperDelete.lambda().eq(Account::getUserName, "PolyU-SFT-" + noLoginRequiredDTO.getId());
}else {
} else {
queryWrapperDelete.lambda().like(Account::getBrowserIdentifiers, ipAddress);
}
List<Account> accountList = accountMapper.selectList(queryWrapperDelete);
@@ -923,7 +935,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// SendEmailUtil.sendUpgradeNotification(account, null, 1);
if (account.getLanguage().equals(Language.CHINESE_SIMPLIFIED.name())) {
SendEmailUtil.sendUpgradeNotification(account, null, 0);
}else {
} else {
// 英文
SendEmailUtil.sendUpgradeNotification(account, null, 1);
}
@@ -937,7 +949,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// 未迁移过的进行迁移,注意模特数据迁移打点信息以及转换模特格式
}
public void updateCredits(Long accountId, String value){
public void updateCredits(Long accountId, String value) {
Account account = new Account();
account.setId(accountId);
account.setCredits(new BigDecimal(value));
@@ -954,7 +966,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
LocalCacheUtils.setVerifyCodeCache("DesignWorksRegister"+ "_" + accountDesignWorksRegisterDTO.getUserEmail(), randomVerifyCode);
LocalCacheUtils.setVerifyCodeCache("DesignWorksRegister" + "_" + accountDesignWorksRegisterDTO.getUserEmail(), randomVerifyCode);
Boolean b = SendEmailUtil.designWorksRegister(accountDesignWorksRegisterDTO.getUserEmail(), randomVerifyCode);
if (!b) {
@@ -966,7 +978,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Override
public AccountLoginVO designWorksRegisterCode(AccountDesignWorksRegisterDTO accountDesignWorksRegisterDTO) {
String verifyCode = LocalCacheUtils.getVerifyCodeCache("DesignWorksRegister"+ "_" + accountDesignWorksRegisterDTO.getUserEmail());
String verifyCode = LocalCacheUtils.getVerifyCodeCache("DesignWorksRegister" + "_" + accountDesignWorksRegisterDTO.getUserEmail());
if (StringUtils.isBlank(verifyCode)) {
throw new BusinessException("the.verification.code.has.expired", ResultEnum.PROMPT.getCode());
}
@@ -996,4 +1008,195 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
response.setSystemUser(account.getSystemUser());
return response;
}
private static final String QUERY_ORDER = "SELECT * FROM pmr_wc_order_stats " +
"WHERE status = 'wc-processing' AND date_paid > '2024-06-10 00:00:00'" +
" ORDER BY order_id DESC ";
private static final String QUERY_CUSTOMER_EMAIL = "SELECT username, email FROM pmr_wc_customer_lookup " +
"WHERE customer_id = ? ";
private static final String UPDATE_ORDER_STATUS = "UPDATE pmr_wc_order_stats " +
"SET status = 'wc-complete' , date_completed = ? " +
"WHERE order_id = ?";
private static final DataSource dataSource;
static {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://code-create.com.hk:3306/db1nfvsgmjp3b8");
config.setUsername("uafqtz4gsvfrw");
config.setPassword("aida123456.");
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
dataSource = new HikariDataSource(config);
}
/**
* 为Code-Create的用户延长有效期
*
* @return null
*/
public String extendValidityForCC() {
try (Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(QUERY_ORDER)) {
// preparedStatement.setString(1, "someCondition");
try (ResultSet queryOrderResultSet = preparedStatement.executeQuery()) {
while (queryOrderResultSet.next()) {
/* 处理结果集 */
int orderId = queryOrderResultSet.getInt("order_id");
int customerId = queryOrderResultSet.getInt("customer_id");
double totalSales = queryOrderResultSet.getDouble("total_sales");
String email = "";
String userName = "";
// 1、查pmr_wc_customer_lookup表确认当前订单对应的用户邮箱
PreparedStatement preparedQueryEmail = connection.prepareStatement(QUERY_CUSTOMER_EMAIL);
preparedQueryEmail.setInt(1, customerId);
try (ResultSet queryEmailResultSet = preparedQueryEmail.executeQuery()) {
if (queryEmailResultSet.next()) {
email = queryEmailResultSet.getString("email");
userName = queryEmailResultSet.getString("username");
} else {
log.error("未知错误。code-create的用户表中没有付费用户的信息");
throw new BusinessException("user info missing");
}
}
// 2、查t_account表中是否有该用户
// 2.1 没有 新建用户
Account userInfo = null;
Long validEndTime = null;
// 标志当前用户是不是新用户
Boolean flag = Boolean.FALSE;
try {
// 不是新用户 直接延长使用期限
userInfo = getOneByEmail(email);
} catch (BusinessException e) {
// 通过邮箱找不到用户 说明是新用户 => 创建用户
flag = Boolean.TRUE;
}
if (!Objects.isNull(userInfo) && !Objects.isNull(userInfo.getValidEndTime()))
validEndTime = userInfo.getValidEndTime();
// 2、获取当前续费费用能延长多长时间
Account account = extendValidity(validEndTime, totalSales);
if (flag) {
// 是新用户 => 新增一条数据
Boolean b = addUser(new AccountAddDTO(email, StringUtil.isNullOrEmpty(userName) ? email.substring(0, email.indexOf("@") - 1) : userName, account.getValidStartTime().toString(), account.getValidEndTime().toString(), 0));
if (b) log.info("付费新用户新增成功!");
} else {
userInfo.setValidEndTime(account.getValidEndTime());
baseMapper.updateById(account);
log.info("付费用户续订成功");
}
// 3、todo 邮件通知
// 3.1 判断用户语言
// 3.2 将用户信息填到邮件中
// 4、更新订单状态和日期
PreparedStatement preparedUpdateOrder = connection.prepareStatement(UPDATE_ORDER_STATUS);
LocalDateTime localDateTime = LocalDateTime.now();
String currentTime = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
preparedUpdateOrder.setString(1, currentTime);
preparedUpdateOrder.setInt(2, orderId);
int row = preparedUpdateOrder.executeUpdate();
if (row == 1) log.info("表 pmr_wc_order_stats 订单状态更新成功");
}
}
} catch (Exception e) {
// 记录异常并处理
e.printStackTrace();
}
return null;
}
private Account extendValidity(Long validEndTime, double totalSales) {
Instant specifiedInstant;
Account account = new Account();
long epochMilli = Instant.now().toEpochMilli();
if (!Objects.isNull(validEndTime) && validEndTime > epochMilli) {
// 将 Unix 毫秒级时间戳转换为 Instant
specifiedInstant = Instant.ofEpochMilli(validEndTime);
} else {
specifiedInstant = Instant.now();
account.setValidStartTime(specifiedInstant.toEpochMilli());
}
// 指定时区
ZoneId zoneId = ZoneId.of("Asia/Shanghai");
// 将 Instant 转换为 ZonedDateTime使用指定时区
ZonedDateTime specifiedDateTime = ZonedDateTime.ofInstant(specifiedInstant, zoneId);
ZonedDateTime validityExtension;
if (totalSales == 500) {
// 一个月
validityExtension = specifiedDateTime.plusMonths(1);
} else if (totalSales == 5000) {
// 一年
validityExtension = specifiedDateTime.plusYears(1);
} else {
// 测试 一天
validityExtension = specifiedDateTime.plusDays(1);
}
// 获取一个月之后的时间的 Unix 毫秒级时间戳
account.setValidEndTime(validityExtension.toInstant().toEpochMilli());
return account;
}
// 收集调查问卷的信息
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean collectQuestionnaires(String questionnaireInfo) {
log.info("调查问卷详细信息:{}", questionnaireInfo);
QuestionnaireVO questionnaireVO = JSON.parseObject(questionnaireInfo, QuestionnaireVO.class);
String email = questionnaireVO.getEmail();
// 1、通过邮箱判断当前用户有无系统账号
Account account;
try {
account = getOneByEmail(email);
} catch (BusinessException e) {
log.info(e.getMessage());
log.warn("当前用户 {} 在AiDA中没有账号", email);
throw new BusinessException("user.has.no.account",ResultEnum.PROMPT.getCode());
}
// 2、先判断当前用户是否已经填写过问卷
CreditsDetail record = creditsService.getByAccountIdAndChangeEvent(account.getId(), "Fill out the questionnaire", "+100");
if (!Objects.isNull(record)) {
log.info("当前用户 {} 已经填写过问卷", email);
throw new BusinessException("questionnaire.filled.out", ResultEnum.PROMPT.getCode());
}
// 3.1、将问卷信息存储到数据库
Questionnaire questionnaire = new Questionnaire();
questionnaire.setQuestionnaireInfo(questionnaireInfo);
questionnaire.setTitle("AiDA_3.0 Feedback Survey--06/2024");
questionnaire.setCreateTime(LocalDateTime.now());
int insert = questionnaireMapper.insert(questionnaire);
if (insert == 1) {
// 3.2、更新 t_credits_detail表
CreditsDetail creditsDetail = new CreditsDetail();
creditsDetail.setAccountId(account.getId());
creditsDetail.setChangeEvent("Fill out the questionnaire");
creditsDetail.setChangedCredits("+100");
BigDecimal added = account.getCredits().add(new BigDecimal("100"));
creditsDetail.setCredits(added);
creditsDetail.setCreateTime(LocalDateTime.now());
creditsService.save(creditsDetail);
// 3.3、更新 t_account 表
updateCredits(account.getId(), added.toString());
}
// 4、发邮件 区分中英文
SendEmailUtil.questionnaireRelatedNotify(questionnaireVO.getUserName(), email, questionnaireVO.getLanguage());
return Boolean.TRUE;
}
}

View File

@@ -243,4 +243,13 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
redisUtil.removeFromString(key);
}
public CreditsDetail getByAccountIdAndChangeEvent(Long accountId, String changeEvent, String changedCredits){
QueryWrapper<CreditsDetail> qw = new QueryWrapper<>();
qw.eq("account_id", accountId);
qw.eq("change_event", changeEvent);
qw.eq("changed_credits", changedCredits);
return baseMapper.selectOne(qw);
}
}