管理员系统功能添加

This commit is contained in:
2024-08-05 15:19:02 +08:00
parent 1093ac68b6
commit ea4ba74989
8 changed files with 434 additions and 50 deletions

View File

@@ -1,28 +1,43 @@
package com.ai.da.service.impl;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.constant.CommonConstant;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.enums.CreditsEventsEnum;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.mapper.primary.AccountMapper;
import com.ai.da.mapper.primary.QuestionnaireMapper;
import com.ai.da.mapper.primary.ToProductImageResultMapper;
import com.ai.da.mapper.primary.TrialOrderMapper;
import com.ai.da.mapper.primary.entity.Account;
import com.ai.da.mapper.primary.entity.Questionnaire;
import com.ai.da.mapper.primary.entity.TrialOrder;
import com.ai.da.model.dto.AccountAddDTO;
import com.ai.da.model.enums.Language;
import com.ai.da.model.vo.QuestionnaireFeedbackVO;
import com.ai.da.model.vo.QuestionnaireVO;
import com.ai.da.model.vo.QueryUserConditionsVO;
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.mysql.cj.util.StringUtils;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Slf4j
public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMapper, Questionnaire> implements ConvenientInquiryService {
@Resource
@@ -31,6 +46,56 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
@Resource
private AccountLoginLogService accountLoginLogService;
public IPage<TrialOrder> getTrial(QueryUserConditionsVO queryUserConditionsVO) {
log.info("getTrial parameter : {},page:{}, size:{}",queryUserConditionsVO,queryUserConditionsVO.getPage(),queryUserConditionsVO.getSize());
/* 添加按条件查询试用用户 */
// 按用户邮箱/用户名/用户id查指定用户
QueryWrapper<TrialOrder> queryWrapper = new QueryWrapper<>();
if (!Objects.isNull(queryUserConditionsVO.getIds()) && !queryUserConditionsVO.getIds().isEmpty()) {
queryWrapper.in("id", queryUserConditionsVO.getIds());
}
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getUserName())) {
queryWrapper.eq("user_name", queryUserConditionsVO.getUserName());
}
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getEmail())) {
queryWrapper.eq("email", queryUserConditionsVO.getEmail());
}
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getCountry())) {
queryWrapper.eq("country", queryUserConditionsVO.getCountry());
}
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getOccupation())) {
queryWrapper.eq("occupation", queryUserConditionsVO.getOccupation());
}
// 按时间区间查
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getStartTime())) {
queryWrapper.gt("create_time", queryUserConditionsVO.getStartTime());
}
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getEndTime())) {
queryWrapper.lt("create_time", queryUserConditionsVO.getEndTime());
}
// 排序
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getOrder()) && !StringUtils.isNullOrEmpty(queryUserConditionsVO.getOrderBy())) {
String orderBy = "id";
if (queryUserConditionsVO.getOrderBy().equals("time")) {
orderBy = "create_time";
}
switch (queryUserConditionsVO.getOrder()) {
case "Ascending":
queryWrapper.orderByAsc(orderBy);
break;
case "Descending":
queryWrapper.orderByDesc(orderBy);
break;
}
}
// 分页查询
return trialOrderMapper.selectPage(new Page<>(queryUserConditionsVO.getPage(), queryUserConditionsVO.getSize()), queryWrapper);
// List<TrialOrder> trialOrders = trialOrderMapper.selectList(null);
}
public QuestionnaireFeedbackVO getQuestionnaireInfo() {
String title = "AiDA_3.0 Feedback Survey--06/2024";
@@ -195,6 +260,10 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
if (StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime)) {
return null;
}
if (!StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime)) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
endTime = LocalDateTime.now().format(formatter);
}
Integer type = null;
if (!StringUtil.isNullOrEmpty(userType)) {
type = userType.equals("visitor") ? 0 : userType.equals("trial") ? 1 : 2;
@@ -208,6 +277,10 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
if (StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime)) {
return null;
}
if (!StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime)) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
endTime = LocalDateTime.now().format(formatter);
}
Integer type = null;
if (!StringUtil.isNullOrEmpty(userType)) {
type = userType.equals("visitor") ? 0 : userType.equals("trial") ? 1 : 2;
@@ -232,17 +305,24 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
// 近期活跃用户
public IPage<Account> recentActiveUser(String startTime, String endTime, int pageNum, int size) {
if (!StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime)) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
endTime = LocalDateTime.now().format(formatter);
}
List<Long> accountIds = accountLoginLogService.getByDate(startTime, endTime);
return accountService.getPageByIds(accountIds, pageNum, size);
}
// 图表数据
public int recentActiveUserChart(String startTime, String endTime) {
if (!StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime)) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
endTime = LocalDateTime.now().format(formatter);
}
List<Long> accountIds = accountLoginLogService.getByDate(startTime, endTime);
return accountIds.size();
}
@Resource
private GenerateService generateService;
@Resource
@@ -255,6 +335,8 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
private ChatRobotService chatRobotService;
public Map<String, List<Object>> getActiveUserFunc(String startTime, String endTime, List<Long> ids) {
log.info("getActiveUserFunc ==> startTime:{}, endTime:{}, accountList:{}", startTime, endTime, ids);
// 必须指定时间区间
if (StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime)) {
return null;
@@ -306,7 +388,199 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
return resp;
}
//
@Resource
private TrialOrderMapper trialOrderMapper;
// 试用用户到正式用户的转化率
public Map<String, Float> conversionRate() {
QueryWrapper<TrialOrder> queryWrapper = new QueryWrapper<>();
// 获取试用用户总数
queryWrapper.select("count(distinct email) as count");
List<Map<String, Object>> trialMaps = trialOrderMapper.selectMaps(queryWrapper);
Long totalTrials = (Long) trialMaps.get(0).get("count");
// 获取从试用用户转为正式用户的用户数量
Map<String, Long> officialMaps = trialOrderMapper.countOfficialUser();
Long trialToOfficial = officialMaps.get("count");
// 计算转化率
HashMap<String, Float> resp = new HashMap<>();
resp.put("trialUserCount", totalTrials.floatValue());
resp.put("trialToOfficialCount", trialToOfficial.floatValue());
resp.put("conversionRate", new BigDecimal(trialToOfficial).divide(new BigDecimal(totalTrials), 2, RoundingMode.HALF_UP).floatValue());
return resp;
}
// 试用用户地区统计
public Map<String, List<Object>> trialUserCountry() {
QueryWrapper<TrialOrder> queryWrapper = new QueryWrapper<>();
queryWrapper.select("country, count(id) as count")
.groupBy("country");
List<Map<String, Object>> countryCount = trialOrderMapper.selectMaps(queryWrapper);
Map<Object, Object> countryCountMap = countryCount.stream().collect(Collectors.toMap(
map -> map.get("country"),
map -> map.get("count")
));
HashMap<String, List<Object>> resp = new HashMap<>();
resp.put("names", new ArrayList<>(countryCountMap.keySet()));
resp.put("values", new ArrayList<>(countryCountMap.values()));
return resp;
}
// 新增用户
public Boolean addUser(AccountAddDTO accountAddDTO) {
// 需要给的数据 用户邮箱、用户名、账号有效期截止时间、账号类型
Account account = CopyUtil.copyObject(accountAddDTO, Account.class);
// 添加正式用户
if (Objects.isNull(accountAddDTO.getSystemUser())) {
throw new BusinessException("you have to choose user type");
} else {
switch (accountAddDTO.getSystemUser()) {
case 0:
account.setCredits(new BigDecimal(0));
account.setIsTrial(0);
break;
case 1:
account.setCredits(new BigDecimal(CreditsEventsEnum.INIT_YEARLY.getValue()));
account.setIsTrial(0);
break;
case 2:
account.setCredits(new BigDecimal(CreditsEventsEnum.INIT_MONTHLY.getValue()));
account.setIsTrial(0);
break;
case 3:
account.setCredits(new BigDecimal(CreditsEventsEnum.INIT_TRIAL.getValue()));
account.setIsTrial(1);
break;
}
}
account.setValidStartTime(Long.parseLong(accountAddDTO.getValidStartTime()));
account.setValidEndTime(Long.parseLong(accountAddDTO.getValidEndTime()));
account.setUserPassword("Third-000000");
account.setLanguage(Language.ENGLISH.name());
account.setCreateDate(new Date());
account.setIsBeginner(1);
log.info("添加用户:{}", accountAddDTO.getUserEmail());
return accountService.save(account);
}
// 修改用户信息
public Boolean modifyUser(Long accountId, Long validEndTime, Integer systemUser, Long credits) {
log.info("modifyUser ==> accountId:{}, validEndTime:{}, systemUser:{}, systemUser:{}", accountId, validEndTime, systemUser, credits);
if (Objects.isNull(accountId) && Objects.isNull(validEndTime) && Objects.isNull(systemUser) && Objects.isNull(credits)) {
return null;
} else if (Objects.isNull(accountId)) {
throw new BusinessException("you have to choose a user");
}
Account account = new Account();
// 修改用户有效期截止日期、用户类型、积分
if (!Objects.isNull(validEndTime)) {
account.setValidEndTime(validEndTime);
}
if (!Objects.isNull(systemUser)) {
account.setSystemUser(systemUser);
}
/*if (!StringUtils.isNullOrEmpty(systemUser)) {
int systemUser = 0;
switch (systemUser) {
case "yearly":
systemUser = 1;
break;
case "monthly":
systemUser = 2;
break;
case "trial":
systemUser = 3;
break;
case "visitor":
systemUser = 0;
break;
}
account.setSystemUser(systemUser);
}*/
if (!Objects.isNull(credits)) {
account.setCredits(new BigDecimal(credits));
}
account.setId(accountId);
account.setUpdateDate(new Date());
log.info("修改用户信息:{}", accountId);
return accountMapper.updateById(account) == 1;
// accountService.update(account,null);
}
@Resource
private AccountMapper accountMapper;
// 按条件查询用户信息
public IPage<Account> getUserInfo(QueryUserConditionsVO queryUserConditionsVO) {
log.info("getUserInfo parameter : {},page:{}, size:{}",queryUserConditionsVO,queryUserConditionsVO.getPage(),queryUserConditionsVO.getSize());
// 按用户邮箱/用户名/用户id查指定用户
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
if (!Objects.isNull(queryUserConditionsVO.getIds()) && !queryUserConditionsVO.getIds().isEmpty()) {
queryWrapper.in("id", queryUserConditionsVO.getIds());
}
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getUserName())) {
queryWrapper.eq("user_name", queryUserConditionsVO.getUserName());
}
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getEmail())) {
queryWrapper.eq("user_email", queryUserConditionsVO.getEmail());
}
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getCountry())) {
queryWrapper.eq("country", queryUserConditionsVO.getCountry());
}
if (!Objects.isNull(queryUserConditionsVO.getSystemUser())) {
queryWrapper.eq("system_user", queryUserConditionsVO.getSystemUser());
}
// 按时间区间查
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getStartTime())) {
queryWrapper.gt("create_date", queryUserConditionsVO.getStartTime());
}
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getEndTime())) {
queryWrapper.lt("create_date", queryUserConditionsVO.getEndTime());
}
// 排序
if (!StringUtils.isNullOrEmpty(queryUserConditionsVO.getOrder()) && !StringUtils.isNullOrEmpty(queryUserConditionsVO.getOrderBy())) {
String orderBy = "id";
switch (queryUserConditionsVO.getOrderBy()) {
case "time":
orderBy = "create_date";
break;
case "credits":
orderBy = "credits";
break;
}
switch (queryUserConditionsVO.getOrder()) {
case "Ascending":
queryWrapper.orderByAsc(orderBy);
break;
case "Descending":
queryWrapper.orderByDesc(orderBy);
break;
}
}
// 分页查询
return accountMapper.selectPage(new Page<>(queryUserConditionsVO.getPage(), queryUserConditionsVO.getSize()), queryWrapper);
}
public List<Map<String, Object>> getAllUserIdList() {
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.select("id as value, user_name as label");
return accountMapper.selectMaps(queryWrapper);
// return maps.stream().map(map -> (Long)map.get("id")).collect(Collectors.toList());
}
}

View File

@@ -1292,7 +1292,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
.lt("create_date", endTime)
.select("count(id) as count");
if (!accountIds.isEmpty()){
if (!Objects.isNull(accountIds) && !accountIds.isEmpty() ){
queryWrapper.in("account_id", accountIds);
}