便利查询--各版本管理员查看用户的design频次和各生成功能使用频次以及积分使用情况

This commit is contained in:
2025-04-13 17:20:14 +08:00
parent 7b75e6ac69
commit cbc760ebaf
7 changed files with 237 additions and 42 deletions

View File

@@ -7,9 +7,7 @@ import com.ai.da.common.response.Response;
import com.ai.da.mapper.primary.DesignMapper;
import com.ai.da.mapper.primary.entity.Account;
import com.ai.da.mapper.primary.entity.TrialOrder;
import com.ai.da.model.dto.AccountAddDTO;
import com.ai.da.model.dto.QueryPaymentInfoDTO;
import com.ai.da.model.dto.UserDesignStatisticDTO;
import com.ai.da.model.dto.*;
import com.ai.da.model.vo.PaymentInfoVO;
import com.ai.da.model.vo.QuestionnaireFeedbackVO;
import com.ai.da.model.vo.QuestionnaireVO;
@@ -17,7 +15,6 @@ import com.ai.da.model.vo.QueryUserConditionsVO;
import com.ai.da.service.AccountService;
import com.ai.da.service.ConvenientInquiryService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.netty.util.internal.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -63,26 +60,7 @@ public class ConvenientInquiryController {
@GetMapping("/getDesignStatistic")
public Response<List<UserDesignStatisticDTO>> getDesignStatistic(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) List<Long> ids, @RequestParam(required = false) String email) {
Long accountId = UserContext.getUserHolder().getId();
String userEmail = accountService.getById(accountId).getUserEmail();
if (accountId.equals(31L) || accountId.equals(87L) || accountId.equals(83L)
|| accountId.equals(6L) || accountId.equals(4L) || accountId.equals(73L)
|| userEmail.equals("joho8228@hotmail.com") || userEmail.equals("wanninghua160@gmail.com")
) {
if (StringUtil.isNullOrEmpty(startTime)) startTime = "2024-02-01 00:00:00";
if (StringUtil.isNullOrEmpty(endTime)) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date date = new Date();
endTime = simpleDateFormat.format(date);
}
if (!StringUtil.isNullOrEmpty(email)){
email = email.trim();
}
List<UserDesignStatisticDTO> designStatistic = designMapper.getDesignStatistic(startTime, endTime, ids, email);
return Response.success(designStatistic);
} else {
return Response.fail("Sorry, you don't have permission");
}
return Response.success(convenientInquiryService.getDesignStatistic(startTime, endTime, ids, email));
}
@@ -215,4 +193,10 @@ public class ConvenientInquiryController {
public Response<String> exportTransactionRecords(@Valid @RequestBody QueryPaymentInfoDTO queryPaymentInfoDTO, HttpServletResponse response){
return Response.success(convenientInquiryService.exportTransactionRecords(queryPaymentInfoDTO, response));
}
@ApiOperation("获取生成功能使用频次")
@PostMapping("/getGenerateFrequency")
public Response<PageBaseResponse<AccountCreditsUsageDTO>> getGenerateFrequency(@Valid @RequestBody AccountCreditsUsageQueryDTO queryDTO){
return Response.success(convenientInquiryService.getGenerateFrequency(queryDTO));
}
}

View File

@@ -2,8 +2,8 @@ package com.ai.da.mapper.primary;
import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.primary.entity.Account;
import com.ai.da.model.dto.AccountCreditsUsageDTO;
import java.util.Date;
import java.util.List;
/**
@@ -32,4 +32,8 @@ public interface AccountMapper extends CommonMapper<Account> {
void toVisitor(Long id);
List<AccountCreditsUsageDTO> selectCreditUsage(boolean groupByEvent, String changeEvent, String role, String userEmail, Long id, String startTime, String endTime, Integer size, Integer offset);
int countCreditUsage(boolean groupByEvent, String changeEvent, String role, String userEmail, Long id, String startTime, String endTime);
}

View File

@@ -18,7 +18,7 @@ public interface DesignMapper extends CommonMapper<Design> {
//返回插入数据后生成的主键
Long insertDesign(Design design);
List<UserDesignStatisticDTO> getDesignStatistic(String startTime, String endTime, List<Long> ids, String email);
List<UserDesignStatisticDTO> getDesignStatistic(String startTime, String endTime, List<Long> ids, String email, String role);
List<Design> selectDeleteList();
}

View File

@@ -4,8 +4,7 @@ import com.ai.da.common.response.PageBaseResponse;
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.dto.QueryPaymentInfoDTO;
import com.ai.da.model.dto.*;
import com.ai.da.model.vo.PaymentInfoVO;
import com.ai.da.model.vo.QuestionnaireFeedbackVO;
import com.ai.da.model.vo.QuestionnaireVO;
@@ -21,6 +20,8 @@ public interface ConvenientInquiryService extends IService<Questionnaire> {
IPage<TrialOrder> getTrial(QueryUserConditionsVO queryUserConditionsVO);
List<UserDesignStatisticDTO> getDesignStatistic(String startTime, String endTime, List<Long> ids, String email);
QuestionnaireFeedbackVO getQuestionnaireInfo();
List<QuestionnaireVO> getAllQuestionnaire();
@@ -53,4 +54,6 @@ public interface ConvenientInquiryService extends IService<Questionnaire> {
Map<String, List<String>> getCities();
String exportTransactionRecords(QueryPaymentInfoDTO queryPaymentInfoDTO, HttpServletResponse response);
PageBaseResponse<AccountCreditsUsageDTO> getGenerateFrequency(AccountCreditsUsageQueryDTO queryDTO);
}

View File

@@ -5,14 +5,14 @@ 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.response.PageBaseResponse;
import com.ai.da.common.response.ResultEnum;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.DateUtil;
import com.ai.da.mapper.primary.*;
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.dto.QueryPaymentInfoDTO;
import com.ai.da.model.dto.*;
import com.ai.da.model.enums.Language;
import com.ai.da.model.vo.*;
import com.ai.da.service.*;
@@ -41,6 +41,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@@ -68,10 +69,15 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
private TrialOrderMapper trialOrderMapper;
@Resource
private PaymentInfoMapper paymentInfoMapper;
@Resource
private DesignMapper designMapper;
@Value("${minio.bucketName.users}")
private String userBucket;
private static final List<Long> ADMIN_IDS = Arrays.asList(4L, 6L, 31L, 73L, 83L, 87L);
private static final List<Long> ADMIN_IDS_READ_ONLY = Arrays.asList(12592L, 12201L);
public IPage<TrialOrder> getTrial(QueryUserConditionsVO queryUserConditionsVO) {
log.info("getTrial parameter : {},page:{}, size:{}", queryUserConditionsVO, queryUserConditionsVO.getPage(), queryUserConditionsVO.getSize());
/* 添加按条件查询试用用户 */
@@ -122,6 +128,46 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
// List<TrialOrder> trialOrders = trialOrderMapper.selectList(null);
}
public List<UserDesignStatisticDTO> getDesignStatistic(String startTime, String endTime, List<Long> ids,
String email) {
Long accountId = UserContext.getUserHolder().getId();
Account account = accountService.getById(accountId);
// 允许查看数据的用户id
if (Objects.nonNull(account.getSystemUser())
&& (account.getSystemUser().equals(5)
|| account.getSystemUser().equals(7)
|| ADMIN_IDS.contains(account.getId())
|| ADMIN_IDS_READ_ONLY.contains(account.getId())
)) {
if (StringUtil.isNullOrEmpty(startTime)) startTime = "2024-02-01 00:00:00";
if (StringUtil.isNullOrEmpty(endTime)) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date date = new Date();
endTime = simpleDateFormat.format(date);
}
if (!StringUtil.isNullOrEmpty(email)){
email = email.trim();
}
String role;
switch (account.getSystemUser()){
case 5:
role = "corp";
break;
case 7:
role = "edu";
break;
case 1:
role = "prsn";
break;
default:
throw new BusinessException("Sorry, you don't have permission", ResultEnum.PROMPT.getCode());
}
return designMapper.getDesignStatistic(startTime, endTime, ids, email, role);
} else {
throw new BusinessException("Sorry, you don't have permission", ResultEnum.PROMPT.getCode());
}
}
public QuestionnaireFeedbackVO getQuestionnaireInfo() {
String title = "AiDA_3.0 Feedback Survey--06/2024";
@@ -802,4 +848,61 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
}
}
/**
* 查询generate使用频次
* @param queryDTO
* @return
*/
public PageBaseResponse<AccountCreditsUsageDTO> getGenerateFrequency(AccountCreditsUsageQueryDTO queryDTO){
Long accountId = UserContext.getUserHolder().getId();
Account account = accountService.getById(accountId);
// 允许查看数据的用户id
if (Objects.nonNull(account.getSystemUser())
&& (account.getSystemUser().equals(5)
|| account.getSystemUser().equals(7)
|| ADMIN_IDS.contains(account.getId())
|| ADMIN_IDS_READ_ONLY.contains(account.getId())
)) {
boolean groupByEvent = !StringUtil.isNullOrEmpty(queryDTO.getChangeEvent());
String role;
switch (account.getSystemUser()){
case 5:
role = "corp";
break;
case 7:
role = "edu";
break;
case 1:
role = "prsn";
break;
default:
throw new BusinessException("Sorry, you don't have permission");
}
Integer size = queryDTO.getSize();
int offset = (queryDTO.getPage() - 1) * size;
List<AccountCreditsUsageDTO> creditsUsageDTOS = accountMapper.selectCreditUsage(
groupByEvent, queryDTO.getChangeEvent(), role, queryDTO.getUserEmail(), queryDTO.getId(),
queryDTO.getStartTime(), queryDTO.getEndTime(), size, offset);
if (!creditsUsageDTOS.isEmpty()){
int total = accountMapper.countCreditUsage(
groupByEvent, queryDTO.getChangeEvent(), role, queryDTO.getUserEmail(), queryDTO.getId(),
queryDTO.getStartTime(), queryDTO.getEndTime());
// 总页数
double totalPage = Math.ceil((double) total / size);
// 组装返回参数
PageBaseResponse<AccountCreditsUsageDTO> response = new PageBaseResponse<>();
response.setContent(creditsUsageDTOS);
response.setPage(queryDTO.getPage());
response.setSize(size);
response.setTotal(total);
response.setPages((long) totalPage);
return response;
}else {
return new PageBaseResponse<>();
}
}else {
throw new BusinessException("Sorry, you don't have permission");
}
}
}

View File

@@ -29,5 +29,106 @@
where id = #{id}
</update>
<!-- 查询用户积分使用情况,可灵活按事件类型查询或查询全部 -->
<select id="selectCreditUsage" resultType="com.ai.da.model.dto.AccountCreditsUsageDTO">
SELECT
a.id id,
a.user_email,
a.credits currentCredits,
<if test="groupByEvent">
cd.change_event generateFunction,
</if>
cd.total_changed_credits consumedCredits,
cd.count_account_id usageCount
FROM
t_account a
LEFT JOIN
(SELECT
account_id,
<if test="groupByEvent">
change_event,
</if>
SUM(changed_credits) AS total_changed_credits,
COUNT(account_id) AS count_account_id
FROM
t_credits_detail
WHERE
changed_credits &lt;= 0
<if test="changeEvent != null and changeEvent != ''">
AND change_event = #{changeEvent}
</if>
<!-- 添加时间区间查询条件 -->
<if test="startTime != null and startTime != ''">
AND cd.create_time &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND cd.create_time &lt;= #{endTime}
</if>
GROUP BY
account_id
<if test="groupByEvent">
, change_event
</if>
) cd
ON
a.id = cd.account_id
WHERE
<choose>
<when test="role == 'corp'">
a.system_user IN (5, 6)
</when>
<when test="role == 'edu'">
a.system_user IN (7, 8)
</when>
<when test="role == 'prsn'">
a.system_user IN (0, 1, 2, 3, 4)
</when>
</choose>
<if test="id != null">
AND a.id = #{id}
</if>
<if test="userEmail != null and userEmail != ''">
AND a.user_email = #{userEmail}
</if>
<!-- 添加分页查询 -->
ORDER BY a.id
<if test="size != null and offset != null">
LIMIT #{size} OFFSET #{offset}
</if>
</select>
<!-- 查询总记录数 (优化版) -->
<select id="countCreditUsage" resultType="int">
SELECT COUNT(1)
FROM t_account a
<if test="changeEvent != null or startTime != null or endTime != null">
LEFT JOIN t_credits_detail cd ON a.id = cd.account_id
AND cd.changed_credits &lt;= 0
<if test="changeEvent != null and changeEvent != ''">
AND cd.change_event = #{changeEvent}
</if>
<if test="startTime != null and startTime != ''">
AND cd.create_time &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
AND cd.create_time &lt;= #{endTime}
</if>
</if>
WHERE
<choose>
<when test="role == 'corp'">
a.system_user IN (5, 6)
</when>
<when test="role == 'edu'">
a.system_user IN (7, 8)
</when>
<when test="role == 'prsn'">
a.system_user IN (0, 1, 2, 3, 4)
</when>
</choose>
<if test="userEmail != null and userEmail != ''">
AND a.user_email = #{userEmail}
</if>
</select>
</mapper>

View File

@@ -34,8 +34,19 @@
from t_account a
left join t_design b on a.id = b.account_id
<where>
<choose>
<when test="role == 'corp'">
a.system_user IN (5, 6)
</when>
<when test="role == 'edu'">
a.system_user IN (7, 8)
</when>
<when test="role == 'prsn'">
a.system_user IN (0, 1, 2, 3, 4)
</when>
</choose>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
b.create_date between #{startTime} and #{endTime}
AND b.create_date between #{startTime} and #{endTime}
</if>
</where>
and b.create_date not like '%:01'
@@ -52,17 +63,6 @@
GROUP BY b.account_id
ORDER BY b.account_id asc) d
left join trial_order c on d.user_email = c.email
<!--select a.account_id,count(a.account_id) use_design_times,b.user_email,b.user_name,b.is_trial
from `t_account` b
left join t_design a
on a.account_id = b.id
<where>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
a.create_date between #{startTime} and #{endTime}
</if>
</where>
GROUP BY a.account_id
ORDER BY a.account_id ASC;-->
</select>
<select id="selectDeleteList" resultType="com.ai.da.mapper.primary.entity.Design">