diff --git a/adi-admin/src/main/java/com/moyz/adi/admin/controller/AdminConvController.java b/adi-admin/src/main/java/com/moyz/adi/admin/controller/AdminConvController.java new file mode 100644 index 0000000..cc77f0e --- /dev/null +++ b/adi-admin/src/main/java/com/moyz/adi/admin/controller/AdminConvController.java @@ -0,0 +1,14 @@ +package com.moyz.adi.admin.controller; + +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 聊天会话管理 + */ +@RestController +@RequestMapping("/admin/conv") +@Validated +public class AdminConvController { +} diff --git a/adi-admin/src/main/java/com/moyz/adi/admin/controller/AdminKbController.java b/adi-admin/src/main/java/com/moyz/adi/admin/controller/AdminKbController.java new file mode 100644 index 0000000..73a390e --- /dev/null +++ b/adi-admin/src/main/java/com/moyz/adi/admin/controller/AdminKbController.java @@ -0,0 +1,31 @@ +package com.moyz.adi.admin.controller; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.moyz.adi.common.dto.KbInfoResp; +import com.moyz.adi.common.dto.KbSearchReq; +import com.moyz.adi.common.service.KnowledgeBaseService; +import jakarta.annotation.Resource; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Knowledge Base + */ +@RestController +@RequestMapping("/admin/kb") +@Validated +public class AdminKbController { + + @Resource + private KnowledgeBaseService knowledgeBaseService; + + @PostMapping("/search") + public Page search(@RequestBody KbSearchReq kbSearchReq, @NotNull @Min(1) Integer currentPage, @NotNull @Min(10) Integer pageSize) { + return knowledgeBaseService.search(kbSearchReq, currentPage, pageSize); + } +} diff --git a/adi-admin/src/main/java/com/moyz/adi/admin/controller/AdminUserController.java b/adi-admin/src/main/java/com/moyz/adi/admin/controller/AdminUserController.java index 1eaf03f..6bacb84 100644 --- a/adi-admin/src/main/java/com/moyz/adi/admin/controller/AdminUserController.java +++ b/adi-admin/src/main/java/com/moyz/adi/admin/controller/AdminUserController.java @@ -1,29 +1,20 @@ package com.moyz.adi.admin.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.moyz.adi.common.base.ThreadContext; import com.moyz.adi.common.dto.UserAddReq; import com.moyz.adi.common.dto.UserEditReq; import com.moyz.adi.common.dto.UserInfoDto; -import com.moyz.adi.common.dto.UsersReq; +import com.moyz.adi.common.dto.UserSearchReq; import com.moyz.adi.common.entity.User; import com.moyz.adi.common.service.UserService; -import com.talanlabs.avatargenerator.Avatar; -import com.talanlabs.avatargenerator.cat.CatAvatar; import io.swagger.v3.oas.annotations.Operation; import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; import org.springframework.beans.BeanUtils; -import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.IOException; - @RestController @RequestMapping("/admin/user") @Validated @@ -32,9 +23,9 @@ public class AdminUserController { @Resource private UserService userService; - @PostMapping("/list") - public Page userList(@RequestBody UsersReq usersReq, @NotNull @Min(1) Integer currentPage, @NotNull @Min(10) Integer pageSize) { - return userService.listUsers(usersReq, currentPage, pageSize); + @PostMapping("/search") + public Page search(@RequestBody UserSearchReq userSearchReq, @NotNull @Min(1) Integer currentPage, @NotNull @Min(10) Integer pageSize) { + return userService.search(userSearchReq, currentPage, pageSize); } @Operation(summary = "用户信息") diff --git a/adi-admin/src/main/java/com/moyz/adi/admin/controller/StatisticController.java b/adi-admin/src/main/java/com/moyz/adi/admin/controller/StatisticController.java new file mode 100644 index 0000000..53947d5 --- /dev/null +++ b/adi-admin/src/main/java/com/moyz/adi/admin/controller/StatisticController.java @@ -0,0 +1,28 @@ +package com.moyz.adi.admin.controller; + +import com.moyz.adi.common.dto.StatisticDto; +import com.moyz.adi.common.service.StatisticService; +import jakarta.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/admin/statistic") +@Validated +public class StatisticController { + + @Resource + private StatisticService statisticService; + + @GetMapping("/info") + public StatisticDto statistic() { + StatisticDto result = new StatisticDto(); + result.setKbStatistic(statisticService.calKbStat()); + result.setUserStatistic(statisticService.calUserStat()); + result.setTokenCostStatistic(statisticService.calTokenCostStat()); + result.setConvStatistic(statisticService.calConvStatistic()); + return result; + } +} diff --git a/adi-bootstrap/src/main/java/com/moyz/adi/BootstrapApplication.java b/adi-bootstrap/src/main/java/com/moyz/adi/BootstrapApplication.java index 6008ece..b5a9ebf 100644 --- a/adi-bootstrap/src/main/java/com/moyz/adi/BootstrapApplication.java +++ b/adi-bootstrap/src/main/java/com/moyz/adi/BootstrapApplication.java @@ -2,12 +2,14 @@ package com.moyz.adi; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableAsync @EnableScheduling +@EnableCaching public class BootstrapApplication { public static void main(String[] args) { diff --git a/adi-bootstrap/src/main/resources/application-dev.yml b/adi-bootstrap/src/main/resources/application-dev.yml index 27199e5..ff23610 100644 --- a/adi-bootstrap/src/main/resources/application-dev.yml +++ b/adi-bootstrap/src/main/resources/application-dev.yml @@ -24,6 +24,8 @@ spring: logging: file: path: D:/data/logs + level: + com.baomidou.mybatisplus: DEBUG adi: frontend-url: http://localhost:1002 diff --git a/adi-bootstrap/src/main/resources/application.yml b/adi-bootstrap/src/main/resources/application.yml index 0ab6efe..d25adda 100644 --- a/adi-bootstrap/src/main/resources/application.yml +++ b/adi-bootstrap/src/main/resources/application.yml @@ -21,8 +21,8 @@ spring: cache: type: redis redis: - key-prefix: CACHE - time-to-live: 1d + key-prefix: 'AUTO_CACHE\:' + time-to-live: 1h mail: default-encoding: UTF-8 protocol: smtps diff --git a/adi-chat/src/main/java/com/moyz/adi/chat/controller/KnowledgeBaseController.java b/adi-chat/src/main/java/com/moyz/adi/chat/controller/KnowledgeBaseController.java index 9fbdac1..d1ef78e 100644 --- a/adi-chat/src/main/java/com/moyz/adi/chat/controller/KnowledgeBaseController.java +++ b/adi-chat/src/main/java/com/moyz/adi/chat/controller/KnowledgeBaseController.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.moyz.adi.common.base.ThreadContext; import com.moyz.adi.common.dto.KbEditReq; import com.moyz.adi.common.dto.KbInfoResp; +import com.moyz.adi.common.dto.KbSearchReq; import com.moyz.adi.common.entity.AdiFile; import com.moyz.adi.common.entity.KnowledgeBase; import com.moyz.adi.common.service.KnowledgeBaseService; @@ -47,7 +48,7 @@ public class KnowledgeBaseController { @GetMapping("/searchPublic") public Page searchPublic(@RequestParam(defaultValue = "") String keyword, @NotNull @Min(1) Integer currentPage, @NotNull @Min(10) Integer pageSize) { - return knowledgeBaseService.searchPublic(keyword, currentPage, pageSize); + return knowledgeBaseService.search(KbSearchReq.builder().isPublic(true).title(keyword).build(), currentPage, pageSize); } @GetMapping("/info/{uuid}") diff --git a/adi-chat/src/main/java/com/moyz/adi/chat/controller/UserController.java b/adi-chat/src/main/java/com/moyz/adi/chat/controller/UserController.java index 3951774..5b1852f 100644 --- a/adi-chat/src/main/java/com/moyz/adi/chat/controller/UserController.java +++ b/adi-chat/src/main/java/com/moyz/adi/chat/controller/UserController.java @@ -91,6 +91,10 @@ public class UserController { } private synchronized void writeToResponse(Long userId, HttpServletResponse response) throws IOException{ + response.setHeader("Cache-Control", "max-age=" + 3600 * 24 * 7); + // 设置Expires头,指示响应过期的具体日期时间 + long expiresTime = System.currentTimeMillis() + 3600 * 24 * 7 * 1000; + response.setDateHeader("Expires", expiresTime); Avatar avatar = CatAvatar.newAvatarBuilder().size(64, 64).build(); BufferedImage bufferedImage = avatar.create(userId); ImageIO.write(bufferedImage, "png", response.getOutputStream()); diff --git a/adi-common/src/main/java/com/moyz/adi/common/cosntant/RedisKeyConstant.java b/adi-common/src/main/java/com/moyz/adi/common/cosntant/RedisKeyConstant.java index ca04bb5..cc06546 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/cosntant/RedisKeyConstant.java +++ b/adi-common/src/main/java/com/moyz/adi/common/cosntant/RedisKeyConstant.java @@ -97,4 +97,10 @@ public class RedisKeyConstant { * 值:知识库uuid */ public static final String KB_STATISTIC_RECALCULATE_SIGNAL = "kb:statistic:recalculate:signal"; + + public static final String STATISTIC = "statistic"; + public static final String STATISTIC_USER = "user"; + public static final String STATISTIC_KNOWLEDGE_BASE = "kb"; + public static final String STATISTIC_TOKEN_COST = "token_cost"; + public static final String STATISTIC_CONVERSATION = "conversation"; } diff --git a/adi-common/src/main/java/com/moyz/adi/common/dto/KbInfoResp.java b/adi-common/src/main/java/com/moyz/adi/common/dto/KbInfoResp.java index 1c4804e..b53b06b 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/dto/KbInfoResp.java +++ b/adi-common/src/main/java/com/moyz/adi/common/dto/KbInfoResp.java @@ -2,8 +2,11 @@ package com.moyz.adi.common.dto; import lombok.Data; +import java.time.LocalDateTime; + @Data public class KbInfoResp { + private Long id; private String uuid; private String title; private String remark; @@ -13,4 +16,6 @@ public class KbInfoResp { private String ownerName; private Integer itemCount; private Integer embeddingCount; + private LocalDateTime createTime; + private LocalDateTime updateTime; } diff --git a/adi-common/src/main/java/com/moyz/adi/common/dto/KbSearchReq.java b/adi-common/src/main/java/com/moyz/adi/common/dto/KbSearchReq.java new file mode 100644 index 0000000..8edbc35 --- /dev/null +++ b/adi-common/src/main/java/com/moyz/adi/common/dto/KbSearchReq.java @@ -0,0 +1,19 @@ +package com.moyz.adi.common.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class KbSearchReq { + private String title; + private Boolean isPublic; + private Integer minItemCount; + private Integer minEmbeddingCount; + private Long[] createTime; + private Long[] updateTime; +} diff --git a/adi-common/src/main/java/com/moyz/adi/common/dto/StatisticDto.java b/adi-common/src/main/java/com/moyz/adi/common/dto/StatisticDto.java new file mode 100644 index 0000000..436a84c --- /dev/null +++ b/adi-common/src/main/java/com/moyz/adi/common/dto/StatisticDto.java @@ -0,0 +1,15 @@ +package com.moyz.adi.common.dto; + +import com.moyz.adi.common.vo.ConvStatistic; +import com.moyz.adi.common.vo.KbStatistic; +import com.moyz.adi.common.vo.TokenCostStatistic; +import com.moyz.adi.common.vo.UserStatistic; +import lombok.Data; + +@Data +public class StatisticDto { + private UserStatistic userStatistic; + private KbStatistic kbStatistic; + private TokenCostStatistic tokenCostStatistic; + private ConvStatistic convStatistic; +} diff --git a/adi-common/src/main/java/com/moyz/adi/common/dto/UserSearchReq.java b/adi-common/src/main/java/com/moyz/adi/common/dto/UserSearchReq.java new file mode 100644 index 0000000..5c4ad6d --- /dev/null +++ b/adi-common/src/main/java/com/moyz/adi/common/dto/UserSearchReq.java @@ -0,0 +1,15 @@ +package com.moyz.adi.common.dto; + +import com.moyz.adi.common.enums.UserStatusEnum; +import lombok.Data; + +@Data +public class UserSearchReq { + private String name; + private String email; + private String uuid; + private Integer userStatus; + private Boolean isAdmin; + private Long[] createTime; + private Long[] updateTime; +} diff --git a/adi-common/src/main/java/com/moyz/adi/common/dto/UsersReq.java b/adi-common/src/main/java/com/moyz/adi/common/dto/UsersReq.java deleted file mode 100644 index 6d0ed0a..0000000 --- a/adi-common/src/main/java/com/moyz/adi/common/dto/UsersReq.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.moyz.adi.common.dto; - -import com.moyz.adi.common.enums.UserStatusEnum; -import lombok.Data; - -@Data -public class UsersReq { - String name; - String email; - String uuid; - - UserStatusEnum userStatus; - - Boolean isAdmin; -} diff --git a/adi-common/src/main/java/com/moyz/adi/common/enums/UserStatusEnum.java b/adi-common/src/main/java/com/moyz/adi/common/enums/UserStatusEnum.java index 7026d58..76f4da6 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/enums/UserStatusEnum.java +++ b/adi-common/src/main/java/com/moyz/adi/common/enums/UserStatusEnum.java @@ -3,6 +3,8 @@ package com.moyz.adi.common.enums; import lombok.AllArgsConstructor; import lombok.Getter; +import java.util.Arrays; + @Getter @AllArgsConstructor public enum UserStatusEnum implements BaseEnum { @@ -14,4 +16,8 @@ public enum UserStatusEnum implements BaseEnum { private final Integer value; private final String desc; + public static UserStatusEnum getByValue(Integer val) { + return Arrays.stream(UserStatusEnum.values()).filter(item -> item.value.equals(val)).findFirst().orElse(null); + } + } diff --git a/adi-common/src/main/java/com/moyz/adi/common/filter/TokenFilter.java b/adi-common/src/main/java/com/moyz/adi/common/filter/TokenFilter.java index 3a64e14..4df0314 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/filter/TokenFilter.java +++ b/adi-common/src/main/java/com/moyz/adi/common/filter/TokenFilter.java @@ -79,7 +79,6 @@ public class TokenFilter extends OncePerRequestFilter { } ThreadContext.setCurrentUser(user); ThreadContext.setToken(token); - log.info("response::" + response); filterChain.doFilter(request, response); } diff --git a/adi-common/src/main/java/com/moyz/adi/common/mapper/ConversationMapper.java b/adi-common/src/main/java/com/moyz/adi/common/mapper/ConversationMapper.java index 0031045..a7c0c9c 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/mapper/ConversationMapper.java +++ b/adi-common/src/main/java/com/moyz/adi/common/mapper/ConversationMapper.java @@ -1,8 +1,11 @@ package com.moyz.adi.common.mapper; -import com.moyz.adi.common.entity.Conversation; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.moyz.adi.common.entity.Conversation; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.time.LocalDateTime; /** *

@@ -14,5 +17,7 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface ConversationMapper extends BaseMapper { + Integer countCreatedByTimePeriod(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + Integer countAllCreated(); } diff --git a/adi-common/src/main/java/com/moyz/adi/common/mapper/KnowledgeBaseItemMapper.java b/adi-common/src/main/java/com/moyz/adi/common/mapper/KnowledgeBaseItemMapper.java index 6c860c6..103ae00 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/mapper/KnowledgeBaseItemMapper.java +++ b/adi-common/src/main/java/com/moyz/adi/common/mapper/KnowledgeBaseItemMapper.java @@ -8,6 +8,8 @@ import com.moyz.adi.common.entity.KnowledgeBaseItem; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.time.LocalDateTime; + @Mapper public interface KnowledgeBaseItemMapper extends BaseMapper { @@ -15,4 +17,8 @@ public interface KnowledgeBaseItemMapper extends BaseMapper { Page searchByKb(Page page, @Param("kbUuid") String kbUuid, @Param("keyword") String keyword); KnowledgeBaseItem getByUuid(String uuid); + + Integer countCreatedByTimePeriod(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + + Integer countAllCreated(); } diff --git a/adi-common/src/main/java/com/moyz/adi/common/mapper/KnowledgeBaseMapper.java b/adi-common/src/main/java/com/moyz/adi/common/mapper/KnowledgeBaseMapper.java index fe9fe6a..5c4dd94 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/mapper/KnowledgeBaseMapper.java +++ b/adi-common/src/main/java/com/moyz/adi/common/mapper/KnowledgeBaseMapper.java @@ -6,6 +6,8 @@ import com.moyz.adi.common.entity.KnowledgeBase; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.time.LocalDateTime; + @Mapper public interface KnowledgeBaseMapper extends BaseMapper { @@ -32,4 +34,8 @@ public interface KnowledgeBaseMapper extends BaseMapper { * @param uuid */ void updateStatByUuid(@Param("uuid") String uuid); + + Integer countCreatedByTimePeriod(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + + Integer countAllCreated(); } diff --git a/adi-common/src/main/java/com/moyz/adi/common/mapper/UserDayCostMapper.java b/adi-common/src/main/java/com/moyz/adi/common/mapper/UserDayCostMapper.java index a1eb69b..6b8594c 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/mapper/UserDayCostMapper.java +++ b/adi-common/src/main/java/com/moyz/adi/common/mapper/UserDayCostMapper.java @@ -3,7 +3,11 @@ package com.moyz.adi.common.mapper; import com.moyz.adi.common.entity.UserDayCost; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; @Mapper public interface UserDayCostMapper extends BaseMapper { + Long sumCostByDay(@Param("day") Integer day); + + Long sumCostByDayPeriod(@Param("beginDate") Integer beginDate, @Param("endDate") Integer endDate); } diff --git a/adi-common/src/main/java/com/moyz/adi/common/service/AiModelService.java b/adi-common/src/main/java/com/moyz/adi/common/service/AiModelService.java index dee7c3d..22ea198 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/service/AiModelService.java +++ b/adi-common/src/main/java/com/moyz/adi/common/service/AiModelService.java @@ -19,6 +19,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import static com.moyz.adi.common.util.LocalCache.MODEL_ID_TO_OBJ; @@ -92,6 +93,14 @@ public class AiModelService extends ServiceImpl { baseMapper.updateById(model); } + public List listEnable() { + List aiModels = ChainWrappers.lambdaQueryChain(baseMapper) + .eq(AiModel::getIsEnable, true) + .eq(AiModel::getIsDeleted, false) + .list(); + return MPPageUtil.convertToList(aiModels, AiModelDto.class); + } + public void softDelete(Long id) { AiModel existModel = getByIdOrThrow(id); diff --git a/adi-common/src/main/java/com/moyz/adi/common/service/ConversationService.java b/adi-common/src/main/java/com/moyz/adi/common/service/ConversationService.java index eccff2e..be9a99d 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/service/ConversationService.java +++ b/adi-common/src/main/java/com/moyz/adi/common/service/ConversationService.java @@ -18,6 +18,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -182,4 +183,14 @@ public class ConversationService extends ServiceImpl searchPublic(String keyword, Integer currentPage, Integer pageSize) { + public Page search(KbSearchReq req, Integer currentPage, Integer pageSize) { Page result = new Page<>(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); - wrapper.eq(KnowledgeBase::getIsPublic, true); - wrapper.eq(KnowledgeBase::getIsDeleted, false); - if (StringUtils.isNotBlank(keyword)) { - wrapper.like(KnowledgeBase::getTitle, keyword); + if (StringUtils.isNotBlank(req.getTitle())) { + wrapper.like(KnowledgeBase::getTitle, req.getTitle()); } + if (null != req.getIsPublic()) { + wrapper.eq(KnowledgeBase::getIsPublic, req.getIsPublic()); + } + if (null != req.getMinItemCount()) { + wrapper.ge(KnowledgeBase::getItemCount, req.getMinItemCount()); + } + if (null != req.getMinEmbeddingCount()) { + wrapper.ge(KnowledgeBase::getEmbeddingCount, req.getMinEmbeddingCount()); + } + if (null != req.getCreateTime() && req.getCreateTime().length == 2) { + wrapper.between(KnowledgeBase::getCreateTime, LocalDateTimeUtil.parse(req.getCreateTime()[0]), LocalDateTimeUtil.parse(req.getCreateTime()[1])); + } + if (null != req.getUpdateTime() && req.getUpdateTime().length == 2) { + wrapper.between(KnowledgeBase::getUpdateTime, LocalDateTimeUtil.parse(req.getUpdateTime()[0]), LocalDateTimeUtil.parse(req.getUpdateTime()[1])); + } + wrapper.eq(KnowledgeBase::getIsDeleted, false); wrapper.orderByDesc(KnowledgeBase::getStarCount, KnowledgeBase::getUpdateTime); Page knowledgeBasePage = baseMapper.selectPage(new Page<>(currentPage, pageSize), wrapper); return MPPageUtil.convertToPage(knowledgeBasePage, result, KbInfoResp.class, null); @@ -359,6 +370,17 @@ public class KnowledgeBaseService extends ServiceImpl { return user; } - public Page listUsers(UsersReq usersReq, Integer currentPage, Integer pageSize) { + public Page search(UserSearchReq req, Integer currentPage, Integer pageSize) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - if (StringUtils.isNotBlank(usersReq.getName())) { - wrapper.eq(User::getName, usersReq.getName()); + if (StringUtils.isNotBlank(req.getName())) { + wrapper.like(User::getName, req.getName()); } - if (StringUtils.isNotBlank(usersReq.getUuid())) { - wrapper.eq(User::getUuid, usersReq.getUuid()); + if (StringUtils.isNotBlank(req.getUuid())) { + wrapper.eq(User::getUuid, req.getUuid()); } - if (StringUtils.isNotBlank(usersReq.getEmail())) { - wrapper.eq(User::getEmail, usersReq.getEmail()); + if (StringUtils.isNotBlank(req.getEmail())) { + wrapper.eq(User::getEmail, req.getEmail()); } - if (null != usersReq.getUserStatus()) { - wrapper.eq(User::getUserStatus, usersReq.getUserStatus()); + if (null != req.getUserStatus()) { + wrapper.eq(User::getUserStatus, UserStatusEnum.getByValue(req.getUserStatus())); } + if (null != req.getCreateTime() && req.getCreateTime().length == 2) { + wrapper.between(User::getCreateTime, LocalDateTimeUtil.parse(req.getCreateTime()[0]), LocalDateTimeUtil.parse(req.getCreateTime()[1])); + } + if (null != req.getUpdateTime() && req.getUpdateTime().length == 2) { + wrapper.between(User::getUpdateTime, LocalDateTimeUtil.parse(req.getUpdateTime()[0]), LocalDateTimeUtil.parse(req.getUpdateTime()[1])); + } + wrapper.eq(User::getIsDeleted, false); wrapper.orderByDesc(User::getUpdateTime); Page page = baseMapper.selectPage(new Page<>(currentPage, pageSize), wrapper); Page result = new Page<>(); @@ -395,6 +403,7 @@ public class UserService extends ServiceImpl { newOne.setEmail(addUserReq.getEmail()); newOne.setPassword(hashed); newOne.setUserStatus(UserStatusEnum.NORMAL); + newOne.setActiveTime(LocalDateTime.now()); baseMapper.insert(newOne); UserInfoDto result = new UserInfoDto(); diff --git a/adi-common/src/main/java/com/moyz/adi/common/util/LocalDateTimeUtil.java b/adi-common/src/main/java/com/moyz/adi/common/util/LocalDateTimeUtil.java index b8928ef..cb0c88f 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/util/LocalDateTimeUtil.java +++ b/adi-common/src/main/java/com/moyz/adi/common/util/LocalDateTimeUtil.java @@ -4,7 +4,9 @@ import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import org.apache.commons.lang3.StringUtils; +import java.time.Instant; import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; public class LocalDateTimeUtil { @@ -23,6 +25,10 @@ public class LocalDateTimeUtil { return LocalDateTime.parse(localDateTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); } + public static LocalDateTime parse(Long epochMilli) { + return LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMilli), ZoneId.systemDefault()); + } + public static String format(LocalDateTime localDateTime) { if (null == localDateTime) { return StringUtils.EMPTY; diff --git a/adi-common/src/main/java/com/moyz/adi/common/vo/ConvStatistic.java b/adi-common/src/main/java/com/moyz/adi/common/vo/ConvStatistic.java new file mode 100644 index 0000000..abd72fd --- /dev/null +++ b/adi-common/src/main/java/com/moyz/adi/common/vo/ConvStatistic.java @@ -0,0 +1,23 @@ +package com.moyz.adi.common.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 会话统计信息 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ConvStatistic implements Serializable { + + private static final long serialVersionUID = 1L; + + private Integer todayCreated; + private Integer total; +} diff --git a/adi-common/src/main/java/com/moyz/adi/common/vo/KbStatistic.java b/adi-common/src/main/java/com/moyz/adi/common/vo/KbStatistic.java new file mode 100644 index 0000000..d7e68b6 --- /dev/null +++ b/adi-common/src/main/java/com/moyz/adi/common/vo/KbStatistic.java @@ -0,0 +1,19 @@ +package com.moyz.adi.common.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 知识库的统计信息 + */ +@Data +public class KbStatistic implements Serializable { + + private static final long serialVersionUID = 1L; + + private Integer kbTodayCreated; + private Integer itemTodayCreated; + private Integer kbTotal; + private Integer itemTotal; +} diff --git a/adi-common/src/main/java/com/moyz/adi/common/vo/TokenCostStatistic.java b/adi-common/src/main/java/com/moyz/adi/common/vo/TokenCostStatistic.java new file mode 100644 index 0000000..8208ba9 --- /dev/null +++ b/adi-common/src/main/java/com/moyz/adi/common/vo/TokenCostStatistic.java @@ -0,0 +1,17 @@ +package com.moyz.adi.common.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * LLM相关的统计 + */ +@Data +public class TokenCostStatistic implements Serializable { + + private static final long serialVersionUID = 1L; + + private Long todayTokenCost; + private Long monthTokenCost; +} diff --git a/adi-common/src/main/java/com/moyz/adi/common/vo/UserStatistic.java b/adi-common/src/main/java/com/moyz/adi/common/vo/UserStatistic.java new file mode 100644 index 0000000..9b17ffd --- /dev/null +++ b/adi-common/src/main/java/com/moyz/adi/common/vo/UserStatistic.java @@ -0,0 +1,18 @@ +package com.moyz.adi.common.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 用户的统计信息 + */ +@Data +public class UserStatistic implements Serializable { + + private static final long serialVersionUID = 1L; + + private Integer todayCreated; + private Integer todayActivated; + private Integer totalNormal; +} diff --git a/adi-common/src/main/resources/mapper/ConversationMapper.xml b/adi-common/src/main/resources/mapper/ConversationMapper.xml index 2fb1e01..d4b1803 100644 --- a/adi-common/src/main/resources/mapper/ConversationMapper.xml +++ b/adi-common/src/main/resources/mapper/ConversationMapper.xml @@ -2,5 +2,17 @@ + + + diff --git a/adi-common/src/main/resources/mapper/KnowledgeBaseItemMapper.xml b/adi-common/src/main/resources/mapper/KnowledgeBaseItemMapper.xml index c8a11fb..bc45355 100644 --- a/adi-common/src/main/resources/mapper/KnowledgeBaseItemMapper.xml +++ b/adi-common/src/main/resources/mapper/KnowledgeBaseItemMapper.xml @@ -19,4 +19,17 @@ from adi_knowledge_base_item a where uuid = #{uuid} + + + + diff --git a/adi-common/src/main/resources/mapper/KnowledgeBaseMapper.xml b/adi-common/src/main/resources/mapper/KnowledgeBaseMapper.xml index 14487e5..d93c308 100644 --- a/adi-common/src/main/resources/mapper/KnowledgeBaseMapper.xml +++ b/adi-common/src/main/resources/mapper/KnowledgeBaseMapper.xml @@ -29,6 +29,19 @@ order by star_count,update_time desc + + + + update adi_knowledge_base set item_count = (select count(1) diff --git a/adi-common/src/main/resources/mapper/UserDayCostMapper.xml b/adi-common/src/main/resources/mapper/UserDayCostMapper.xml new file mode 100644 index 0000000..c9adf76 --- /dev/null +++ b/adi-common/src/main/resources/mapper/UserDayCostMapper.xml @@ -0,0 +1,14 @@ + + + + + +