From 32253c35234d5355affe25af7f5e3596f22f3fa0 Mon Sep 17 00:00:00 2001 From: Larry-bird Date: Tue, 31 Dec 2024 00:44:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E9=83=A8=E5=88=86=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E4=BB=A3=E7=A0=81=E5=92=8C=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/ai/annotation/LogicStrategy.java | 18 + .../system/ai/chain/AbstractLogicChain.java | 30 + .../system/ai/chain/BackListLogicChain.java | 36 + .../system/ai/chain/DefaultChainFactory.java | 70 ++ .../system/ai/chain/DefaultLogicChain.java | 35 + .../ruoyi/system/ai/chain/ILogicChain.java | 17 + .../system/ai/chain/ILogicChainArmory.java | 14 + .../ai/chain/MusicProcessAggregate.java | 30 + .../system/ai/chain/RuleWeightLogicChain.java | 40 + .../ai/chain/UserAccountQuotaEntity.java | 36 + .../ruoyi/system/ai/config/ChatConfig.java | 24 + .../system/ai/config/CustomWordAllow.java | 32 + .../system/ai/config/CustomWordDeny.java | 30 + .../ruoyi/system/ai/config/LogicConfig.java | 70 ++ .../system/ai/config/MessageMqConfig.java | 85 ++ .../system/ai/config/SensitiveWordConfig.java | 30 + .../ai/config/WebSocketConfiguration.java | 34 + .../ruoyi/system/ai/config/server/Client.java | 524 +++++++++++ .../ai/config/server/WebSocketServer.java | 187 ++++ .../com/ruoyi/system/ai/domain/AiKey.java | 50 ++ .../ai/domain/ChatCompletionMessage.java | 40 + .../ruoyi/system/ai/domain/ChatConfig.java | 26 + .../ruoyi/system/ai/domain/MessageEntity.java | 46 + .../ruoyi/system/ai/domain/MessageFile.java | 55 ++ .../system/ai/domain/MessageSession.java | 35 + .../system/ai/domain/RuleLogicEntity.java | 23 + .../ai/domain/dto/MessageHistoryKimi.java | 26 + .../ruoyi/system/ai/domain/dto/PostDTO.java | 45 + .../system/ai/domain/event/MessageEvent.java | 31 + .../ruoyi/system/ai/enums/LogicCheckEnum.java | 22 + .../com/ruoyi/system/ai/enums/RoleEnum.java | 8 + .../ai/factory/DefaultLogicFactory.java | 35 + .../ruoyi/system/ai/mapper/AiKeyMapper.java | 70 ++ .../system/ai/mapper/ChatConfigMapper.java | 61 ++ .../system/ai/mapper/MessageFileMapper.java | 13 + .../ruoyi/system/ai/mapper/MessageMapper.java | 20 + .../ai/mapper/MessageSessionMapper.java | 16 + .../ai/mq/listener/MessageListener.java | 39 + .../system/ai/mq/producer/MessageSender.java | 49 ++ .../ruoyi/system/ai/service/HelloWorld.java | 563 ++++++++++++ .../system/ai/service/IAiKeyService.java | 87 ++ .../system/ai/service/IChatConfigService.java | 49 ++ .../ruoyi/system/ai/service/IChatService.java | 20 + .../system/ai/service/IChatUploadService.java | 13 + .../ruoyi/system/ai/service/ILogicFilter.java | 16 + .../ai/service/IMessageFileService.java | 16 + .../system/ai/service/IMessageService.java | 19 + .../ai/service/IMessageSessionService.java | 11 + .../system/ai/service/IModelService.java | 7 + .../ai/service/impl/AiKeyServiceImpl.java | 163 ++++ .../ai/service/impl/BaseChatService.java | 75 ++ .../service/impl/ChatConfigServiceImpl.java | 83 ++ .../ai/service/impl/KimiChatService.java | 110 +++ .../service/impl/MessageFileServiceImpl.java | 117 +++ .../ai/service/impl/MessageServiceImpl.java | 31 + .../impl/MessageSessionServiceImpl.java | 15 + .../system/ai/service/impl/ModelService.java | 36 + .../ai/service/impl/SensitiveWordFilter.java | 52 ++ .../system/ai/service/impl/TokenFilter.java | 62 ++ .../ai/service/impl/UserQuotaFilter.java | 46 + .../system/ai/util/DocumentReaderUtils.java | 69 ++ .../ruoyi/system/ai/util/MoonshotAiUtils.java | 154 ++++ .../system/aipay/AlipaySystemOauthToken.java | 69 ++ .../com/ruoyi/system/aipay/TestLogin.java | 13 + .../com/ruoyi/system/basics/domain/Kamil.java | 72 ++ .../system/basics/domain/dto/KamilAddDTO.java | 34 + .../basics/domain/dto/KamilConDefDTO.java | 25 + .../factory/kamil/KamilConsumption.java | 12 + .../factory/kamil/KamilTypeFactory.java | 37 + .../impl/IntegrationKamilConsumption.java | 36 + .../kamil/impl/SvipKamilConsumption.java | 53 ++ .../kamil/impl/VipKamilConsumption.java | 53 ++ .../system/basics/mapper/KamilMapper.java | 64 ++ .../system/basics/service/IKamilService.java | 72 ++ .../basics/service/impl/KamilServiceImpl.java | 190 ++++ .../algorrirhm/DistributionDataFilter.java | 50 ++ .../system/distribution/domain/FundsLog.java | 27 + .../mapper/DistributionDataMapper.java | 17 + .../distribution/mapper/FundsLogMapper.java | 15 + .../service/DistributionService.java | 8 + .../service/impl/DistributionService.java | 60 ++ .../service/impl/DistributionServiceImpl.java | 225 +++++ .../com/ruoyi/system/file/FileSignature.java | 24 + .../system/lesong/domain/LesongLyrics.java | 40 + .../domain/LesongLyricsUserRelative.java | 39 + .../system/lesong/domain/LesongSong.java | 51 ++ .../domain/LesongSongStyleRelative.java | 44 + .../lesong/domain/LesongSongUserRelative.java | 37 + .../lesong/mapper/LesongLyricsMapper.java | 61 ++ .../LesongLyricsUserRelativeMapper.java | 61 ++ .../lesong/mapper/LesongSongMapper.java | 61 ++ .../mapper/LesongSongStyleRelativeMapper.java | 61 ++ .../mapper/LesongSongUserRelativeMapper.java | 61 ++ .../lesong/service/ILesongLyricsService.java | 61 ++ .../ILesongLyricsUserRelativeService.java | 61 ++ .../lesong/service/ILesongSongService.java | 61 ++ .../ILesongSongStyleRelativeService.java | 61 ++ .../ILesongSongUserRelativeService.java | 61 ++ .../service/impl/LesongLyricsServiceImpl.java | 90 ++ .../LesongLyricsUserRelativeServiceImpl.java | 88 ++ .../service/impl/LesongSongServiceImpl.java | 89 ++ .../LesongSongStyleRelativeServiceImpl.java | 87 ++ .../LesongSongUserRelativeServiceImpl.java | 87 ++ .../system/log/aop/IntegralLogAspect.java | 98 +++ .../system/log/aop/SimpleLogInsertAspect.java | 98 +++ .../ruoyi/system/log/config/LogConfig.java | 28 + .../ruoyi/system/log/domain/IntegralLog.java | 51 ++ .../ruoyi/system/log/domain/InviteLog.java | 54 ++ .../system/log/domain/dto/InviteLogDTO.java | 24 + .../log/factory/IntegralLogFactory.java | 43 + .../system/log/mapper/IntegralLogMapper.java | 21 + .../system/log/mapper/InviteLogMapper.java | 21 + .../log/service/IIntegralLogService.java | 27 + .../system/log/service/IInviteLogService.java | 40 + .../impl/DistributionIntegralServiceImpl.java | 56 ++ .../impl/InviteIntegralLogServiceImpl.java | 45 + .../service/impl/InviteLogServiceImpl.java | 78 ++ .../service/impl/KamilIntegralLogService.java | 58 ++ .../impl/MessageIntegralLogServiceImpl.java | 44 + .../impl/RegisterIntegralLogServiceImpl.java | 52 ++ .../impl/ShopIntegralLogServiceImpl.java | 53 ++ .../impl/SigninIntegralLogServiceImpl.java | 58 ++ .../ruoyi/system/pay/config/AliPayConfig.java | 58 ++ .../system/pay/config/OrderQueueConfig.java | 67 ++ .../ruoyi/system/pay/config/PayUrlConfig.java | 21 + .../system/pay/constant/PayConstant.java | 15 + .../ruoyi/system/pay/domain/OrderEntity.java | 55 ++ .../ruoyi/system/pay/domain/dto/PayDTO.java | 24 + .../ruoyi/system/pay/mapper/OrderMapper.java | 18 + .../pay/mq/listener/OrderAfterListener.java | 56 ++ .../pay/mq/sender/OrderDeadTimeSender.java | 9 + .../system/pay/service/IAliPayService.java | 15 + .../system/pay/service/IOrderService.java | 23 + .../pay/service/impl/AliPayServiceImpl.java | 134 +++ .../pay/service/impl/OrderServiceImpl.java | 127 +++ .../com/ruoyi/system/pay/task/PayTask.java | 28 + .../ruoyi/system/pay/util/OutTradeNoUtil.java | 24 + .../payConfig/domain/entity/Alipay.java | 26 + .../payConfig/domain/entity/PayConfig.java | 34 + .../system/payConfig/mapper/AlipayMapper.java | 14 + .../payConfig/mapper/PayConfigMapper.java | 26 + .../payConfig/service/PayConfigService.java | 23 + .../service/impl/PayConfigServiceImpl.java | 72 ++ .../system/system/domain/CommonSetting.java | 42 + .../system/system/domain/FileConfig.java | 47 + .../ruoyi/system/system/domain/Message.java | 54 ++ .../com/ruoyi/system/system/domain/Model.java | 60 ++ .../system/system/domain/PageResult.java | 18 + .../ruoyi/system/system/domain/Signin.java | 21 + .../ruoyi/system/system/domain/SigninLog.java | 26 + .../system/system/domain/SigninTable.java | 21 + .../ruoyi/system/system/domain/SmsLogin.java | 16 + .../ruoyi/system/system/domain/SysCache.java | 81 ++ .../ruoyi/system/system/domain/SysConfig.java | 111 +++ .../system/system/domain/SysLogininfor.java | 144 +++ .../ruoyi/system/system/domain/SysNotice.java | 112 +++ .../system/system/domain/SysOperLog.java | 269 ++++++ .../ruoyi/system/system/domain/SysPost.java | 124 +++ .../system/system/domain/SysRoleDept.java | 46 + .../system/system/domain/SysRoleMenu.java | 46 + .../system/system/domain/SysUserOnline.java | 113 +++ .../system/system/domain/SysUserPost.java | 46 + .../system/system/domain/SysUserRole.java | 46 + .../system/system/domain/TableColumns.java | 21 + .../com/ruoyi/system/system/domain/Vip.java | 37 + .../system/domain/dto/PageQueryDTO.java | 20 + .../ruoyi/system/system/domain/vo/MetaVo.java | 106 +++ .../system/system/domain/vo/RouterVo.java | 148 ++++ .../ruoyi/system/system/domain/vo/UserVO.java | 22 + .../system/factory/RegisterFactory.java | 10 + .../system/system/mapper/ColumnsMapper.java | 9 + .../system/mapper/CommonSettingMapper.java | 38 + .../system/mapper/FileConfigMapper.java | 29 + .../system/system/mapper/SigninLogMapper.java | 14 + .../system/system/mapper/SigninMapper.java | 16 + .../system/system/mapper/SysConfigMapper.java | 76 ++ .../system/system/mapper/SysDeptMapper.java | 118 +++ .../system/mapper/SysDictDataMapper.java | 95 ++ .../system/mapper/SysDictTypeMapper.java | 83 ++ .../system/mapper/SysLogininforMapper.java | 42 + .../system/system/mapper/SysMenuMapper.java | 125 +++ .../system/system/mapper/SysNoticeMapper.java | 60 ++ .../system/mapper/SysOperLogMapper.java | 48 + .../system/system/mapper/SysPostMapper.java | 99 +++ .../system/mapper/SysRoleDeptMapper.java | 44 + .../system/system/mapper/SysRoleMapper.java | 107 +++ .../system/mapper/SysRoleMenuMapper.java | 44 + .../system/system/mapper/SysUserMapper.java | 139 +++ .../system/mapper/SysUserPostMapper.java | 45 + .../system/mapper/SysUserRoleMapper.java | 65 ++ .../system/system/mapper/UserExtraMapper.java | 33 + .../ruoyi/system/system/mapper/VipMapper.java | 13 + .../system/system/service/ColumnsService.java | 10 + .../system/service/ICommonSettingService.java | 51 ++ .../system/service/IFileConfigService.java | 19 + .../system/service/IRegisterService.java | 9 + .../system/service/ISysConfigService.java | 89 ++ .../system/service/ISysDeptService.java | 124 +++ .../system/service/ISysDictDataService.java | 60 ++ .../system/service/ISysDictTypeService.java | 98 +++ .../system/service/ISysLogininforService.java | 40 + .../system/service/ISysMenuService.java | 144 +++ .../system/service/ISysNoticeService.java | 60 ++ .../system/service/ISysOperLogService.java | 48 + .../system/service/ISysPostService.java | 99 +++ .../system/service/ISysRoleService.java | 173 ++++ .../system/service/ISysUserOnlineService.java | 48 + .../system/service/ISysUserService.java | 238 +++++ .../system/service/IUserExtraService.java | 29 + .../system/system/service/IVipService.java | 17 + .../system/service/SigninLogService.java | 12 + .../system/system/service/SigninService.java | 17 + .../service/impl/AliOssServiceImpl.java | 91 ++ .../service/impl/ColumnsServiceImpl.java | 25 + .../impl/CommonSettingServiceImpl.java | 108 +++ .../service/impl/FileConfigServiceImpl.java | 36 + .../service/impl/SigninLogServiceImpl.java | 25 + .../service/impl/SigninServiceImpl.java | 146 ++++ .../service/impl/SysConfigServiceImpl.java | 234 +++++ .../service/impl/SysDeptServiceImpl.java | 340 ++++++++ .../service/impl/SysDictDataServiceImpl.java | 111 +++ .../service/impl/SysDictTypeServiceImpl.java | 223 +++++ .../impl/SysLogininforServiceImpl.java | 65 ++ .../service/impl/SysMenuServiceImpl.java | 531 +++++++++++ .../service/impl/SysNoticeServiceImpl.java | 92 ++ .../service/impl/SysOperLogServiceImpl.java | 76 ++ .../service/impl/SysPostServiceImpl.java | 178 ++++ .../service/impl/SysRoleServiceImpl.java | 423 +++++++++ .../impl/SysUserOnlineServiceImpl.java | 93 ++ .../service/impl/SysUserServiceImpl.java | 823 ++++++++++++++++++ .../service/impl/UserExtraServiceImpl.java | 67 ++ .../system/service/impl/VipServiceImpl.java | 94 ++ .../service/impl/WeiXinRegisterService.java | 17 + .../ruoyi/system/system/task/SigninTask.java | 40 + .../com/ruoyi/system/system/task/VipTask.java | 89 ++ .../com/ruoyi/system/trade/domain/PayLog.java | 64 ++ .../ruoyi/system/trade/domain/Product.java | 85 ++ .../system/trade/domain/UserProductDTO.java | 73 ++ .../system/trade/mapper/PayLogMapper.java | 13 + .../system/trade/mapper/ProductMapper.java | 63 ++ .../system/trade/service/IPayLogService.java | 15 + .../system/trade/service/IProductService.java | 66 ++ .../trade/service/impl/PayLogServiceImpl.java | 26 + .../service/impl/ProductServiceImpl.java | 117 +++ 244 files changed, 17085 insertions(+) create mode 100644 src/main/java/com/ruoyi/system/ai/annotation/LogicStrategy.java create mode 100644 src/main/java/com/ruoyi/system/ai/chain/AbstractLogicChain.java create mode 100644 src/main/java/com/ruoyi/system/ai/chain/BackListLogicChain.java create mode 100644 src/main/java/com/ruoyi/system/ai/chain/DefaultChainFactory.java create mode 100644 src/main/java/com/ruoyi/system/ai/chain/DefaultLogicChain.java create mode 100644 src/main/java/com/ruoyi/system/ai/chain/ILogicChain.java create mode 100644 src/main/java/com/ruoyi/system/ai/chain/ILogicChainArmory.java create mode 100644 src/main/java/com/ruoyi/system/ai/chain/MusicProcessAggregate.java create mode 100644 src/main/java/com/ruoyi/system/ai/chain/RuleWeightLogicChain.java create mode 100644 src/main/java/com/ruoyi/system/ai/chain/UserAccountQuotaEntity.java create mode 100644 src/main/java/com/ruoyi/system/ai/config/ChatConfig.java create mode 100644 src/main/java/com/ruoyi/system/ai/config/CustomWordAllow.java create mode 100644 src/main/java/com/ruoyi/system/ai/config/CustomWordDeny.java create mode 100644 src/main/java/com/ruoyi/system/ai/config/LogicConfig.java create mode 100644 src/main/java/com/ruoyi/system/ai/config/MessageMqConfig.java create mode 100644 src/main/java/com/ruoyi/system/ai/config/SensitiveWordConfig.java create mode 100644 src/main/java/com/ruoyi/system/ai/config/WebSocketConfiguration.java create mode 100644 src/main/java/com/ruoyi/system/ai/config/server/Client.java create mode 100644 src/main/java/com/ruoyi/system/ai/config/server/WebSocketServer.java create mode 100644 src/main/java/com/ruoyi/system/ai/domain/AiKey.java create mode 100644 src/main/java/com/ruoyi/system/ai/domain/ChatCompletionMessage.java create mode 100644 src/main/java/com/ruoyi/system/ai/domain/ChatConfig.java create mode 100644 src/main/java/com/ruoyi/system/ai/domain/MessageEntity.java create mode 100644 src/main/java/com/ruoyi/system/ai/domain/MessageFile.java create mode 100644 src/main/java/com/ruoyi/system/ai/domain/MessageSession.java create mode 100644 src/main/java/com/ruoyi/system/ai/domain/RuleLogicEntity.java create mode 100644 src/main/java/com/ruoyi/system/ai/domain/dto/MessageHistoryKimi.java create mode 100644 src/main/java/com/ruoyi/system/ai/domain/dto/PostDTO.java create mode 100644 src/main/java/com/ruoyi/system/ai/domain/event/MessageEvent.java create mode 100644 src/main/java/com/ruoyi/system/ai/enums/LogicCheckEnum.java create mode 100644 src/main/java/com/ruoyi/system/ai/enums/RoleEnum.java create mode 100644 src/main/java/com/ruoyi/system/ai/factory/DefaultLogicFactory.java create mode 100644 src/main/java/com/ruoyi/system/ai/mapper/AiKeyMapper.java create mode 100644 src/main/java/com/ruoyi/system/ai/mapper/ChatConfigMapper.java create mode 100644 src/main/java/com/ruoyi/system/ai/mapper/MessageFileMapper.java create mode 100644 src/main/java/com/ruoyi/system/ai/mapper/MessageMapper.java create mode 100644 src/main/java/com/ruoyi/system/ai/mapper/MessageSessionMapper.java create mode 100644 src/main/java/com/ruoyi/system/ai/mq/listener/MessageListener.java create mode 100644 src/main/java/com/ruoyi/system/ai/mq/producer/MessageSender.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/HelloWorld.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/IAiKeyService.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/IChatConfigService.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/IChatService.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/IChatUploadService.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/ILogicFilter.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/IMessageFileService.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/IMessageService.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/IMessageSessionService.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/IModelService.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/impl/AiKeyServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/impl/BaseChatService.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/impl/ChatConfigServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/impl/KimiChatService.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/impl/MessageFileServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/impl/MessageServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/impl/MessageSessionServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/impl/ModelService.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/impl/SensitiveWordFilter.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/impl/TokenFilter.java create mode 100644 src/main/java/com/ruoyi/system/ai/service/impl/UserQuotaFilter.java create mode 100644 src/main/java/com/ruoyi/system/ai/util/DocumentReaderUtils.java create mode 100644 src/main/java/com/ruoyi/system/ai/util/MoonshotAiUtils.java create mode 100644 src/main/java/com/ruoyi/system/aipay/AlipaySystemOauthToken.java create mode 100644 src/main/java/com/ruoyi/system/aipay/TestLogin.java create mode 100644 src/main/java/com/ruoyi/system/basics/domain/Kamil.java create mode 100644 src/main/java/com/ruoyi/system/basics/domain/dto/KamilAddDTO.java create mode 100644 src/main/java/com/ruoyi/system/basics/domain/dto/KamilConDefDTO.java create mode 100644 src/main/java/com/ruoyi/system/basics/factory/kamil/KamilConsumption.java create mode 100644 src/main/java/com/ruoyi/system/basics/factory/kamil/KamilTypeFactory.java create mode 100644 src/main/java/com/ruoyi/system/basics/factory/kamil/impl/IntegrationKamilConsumption.java create mode 100644 src/main/java/com/ruoyi/system/basics/factory/kamil/impl/SvipKamilConsumption.java create mode 100644 src/main/java/com/ruoyi/system/basics/factory/kamil/impl/VipKamilConsumption.java create mode 100644 src/main/java/com/ruoyi/system/basics/mapper/KamilMapper.java create mode 100644 src/main/java/com/ruoyi/system/basics/service/IKamilService.java create mode 100644 src/main/java/com/ruoyi/system/basics/service/impl/KamilServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/distribution/algorrirhm/DistributionDataFilter.java create mode 100644 src/main/java/com/ruoyi/system/distribution/domain/FundsLog.java create mode 100644 src/main/java/com/ruoyi/system/distribution/mapper/DistributionDataMapper.java create mode 100644 src/main/java/com/ruoyi/system/distribution/mapper/FundsLogMapper.java create mode 100644 src/main/java/com/ruoyi/system/distribution/service/DistributionService.java create mode 100644 src/main/java/com/ruoyi/system/distribution/service/impl/DistributionService.java create mode 100644 src/main/java/com/ruoyi/system/distribution/service/impl/DistributionServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/file/FileSignature.java create mode 100644 src/main/java/com/ruoyi/system/lesong/domain/LesongLyrics.java create mode 100644 src/main/java/com/ruoyi/system/lesong/domain/LesongLyricsUserRelative.java create mode 100644 src/main/java/com/ruoyi/system/lesong/domain/LesongSong.java create mode 100644 src/main/java/com/ruoyi/system/lesong/domain/LesongSongStyleRelative.java create mode 100644 src/main/java/com/ruoyi/system/lesong/domain/LesongSongUserRelative.java create mode 100644 src/main/java/com/ruoyi/system/lesong/mapper/LesongLyricsMapper.java create mode 100644 src/main/java/com/ruoyi/system/lesong/mapper/LesongLyricsUserRelativeMapper.java create mode 100644 src/main/java/com/ruoyi/system/lesong/mapper/LesongSongMapper.java create mode 100644 src/main/java/com/ruoyi/system/lesong/mapper/LesongSongStyleRelativeMapper.java create mode 100644 src/main/java/com/ruoyi/system/lesong/mapper/LesongSongUserRelativeMapper.java create mode 100644 src/main/java/com/ruoyi/system/lesong/service/ILesongLyricsService.java create mode 100644 src/main/java/com/ruoyi/system/lesong/service/ILesongLyricsUserRelativeService.java create mode 100644 src/main/java/com/ruoyi/system/lesong/service/ILesongSongService.java create mode 100644 src/main/java/com/ruoyi/system/lesong/service/ILesongSongStyleRelativeService.java create mode 100644 src/main/java/com/ruoyi/system/lesong/service/ILesongSongUserRelativeService.java create mode 100644 src/main/java/com/ruoyi/system/lesong/service/impl/LesongLyricsServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/lesong/service/impl/LesongLyricsUserRelativeServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/lesong/service/impl/LesongSongServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/lesong/service/impl/LesongSongStyleRelativeServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/lesong/service/impl/LesongSongUserRelativeServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/log/aop/IntegralLogAspect.java create mode 100644 src/main/java/com/ruoyi/system/log/aop/SimpleLogInsertAspect.java create mode 100644 src/main/java/com/ruoyi/system/log/config/LogConfig.java create mode 100644 src/main/java/com/ruoyi/system/log/domain/IntegralLog.java create mode 100644 src/main/java/com/ruoyi/system/log/domain/InviteLog.java create mode 100644 src/main/java/com/ruoyi/system/log/domain/dto/InviteLogDTO.java create mode 100644 src/main/java/com/ruoyi/system/log/factory/IntegralLogFactory.java create mode 100644 src/main/java/com/ruoyi/system/log/mapper/IntegralLogMapper.java create mode 100644 src/main/java/com/ruoyi/system/log/mapper/InviteLogMapper.java create mode 100644 src/main/java/com/ruoyi/system/log/service/IIntegralLogService.java create mode 100644 src/main/java/com/ruoyi/system/log/service/IInviteLogService.java create mode 100644 src/main/java/com/ruoyi/system/log/service/impl/DistributionIntegralServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/log/service/impl/InviteIntegralLogServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/log/service/impl/InviteLogServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/log/service/impl/KamilIntegralLogService.java create mode 100644 src/main/java/com/ruoyi/system/log/service/impl/MessageIntegralLogServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/log/service/impl/RegisterIntegralLogServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/log/service/impl/ShopIntegralLogServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/log/service/impl/SigninIntegralLogServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/pay/config/AliPayConfig.java create mode 100644 src/main/java/com/ruoyi/system/pay/config/OrderQueueConfig.java create mode 100644 src/main/java/com/ruoyi/system/pay/config/PayUrlConfig.java create mode 100644 src/main/java/com/ruoyi/system/pay/constant/PayConstant.java create mode 100644 src/main/java/com/ruoyi/system/pay/domain/OrderEntity.java create mode 100644 src/main/java/com/ruoyi/system/pay/domain/dto/PayDTO.java create mode 100644 src/main/java/com/ruoyi/system/pay/mapper/OrderMapper.java create mode 100644 src/main/java/com/ruoyi/system/pay/mq/listener/OrderAfterListener.java create mode 100644 src/main/java/com/ruoyi/system/pay/mq/sender/OrderDeadTimeSender.java create mode 100644 src/main/java/com/ruoyi/system/pay/service/IAliPayService.java create mode 100644 src/main/java/com/ruoyi/system/pay/service/IOrderService.java create mode 100644 src/main/java/com/ruoyi/system/pay/service/impl/AliPayServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/pay/service/impl/OrderServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/pay/task/PayTask.java create mode 100644 src/main/java/com/ruoyi/system/pay/util/OutTradeNoUtil.java create mode 100644 src/main/java/com/ruoyi/system/payConfig/domain/entity/Alipay.java create mode 100644 src/main/java/com/ruoyi/system/payConfig/domain/entity/PayConfig.java create mode 100644 src/main/java/com/ruoyi/system/payConfig/mapper/AlipayMapper.java create mode 100644 src/main/java/com/ruoyi/system/payConfig/mapper/PayConfigMapper.java create mode 100644 src/main/java/com/ruoyi/system/payConfig/service/PayConfigService.java create mode 100644 src/main/java/com/ruoyi/system/payConfig/service/impl/PayConfigServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/CommonSetting.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/FileConfig.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/Message.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/Model.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/PageResult.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/Signin.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SigninLog.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SigninTable.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SmsLogin.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SysCache.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SysConfig.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SysLogininfor.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SysNotice.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SysOperLog.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SysPost.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SysRoleDept.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SysRoleMenu.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SysUserOnline.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SysUserPost.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/SysUserRole.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/TableColumns.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/Vip.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/dto/PageQueryDTO.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/vo/MetaVo.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/vo/RouterVo.java create mode 100644 src/main/java/com/ruoyi/system/system/domain/vo/UserVO.java create mode 100644 src/main/java/com/ruoyi/system/system/factory/RegisterFactory.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/ColumnsMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/CommonSettingMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/FileConfigMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SigninLogMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SigninMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysConfigMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysDeptMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysDictDataMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysDictTypeMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysLogininforMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysMenuMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysNoticeMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysOperLogMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysPostMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysRoleDeptMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysRoleMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysRoleMenuMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysUserMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysUserPostMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/SysUserRoleMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/UserExtraMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/mapper/VipMapper.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ColumnsService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ICommonSettingService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/IFileConfigService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/IRegisterService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ISysConfigService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ISysDeptService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ISysDictDataService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ISysDictTypeService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ISysLogininforService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ISysMenuService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ISysNoticeService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ISysOperLogService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ISysPostService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ISysRoleService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ISysUserOnlineService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/ISysUserService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/IUserExtraService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/IVipService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/SigninLogService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/SigninService.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/AliOssServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/ColumnsServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/CommonSettingServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/FileConfigServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SigninLogServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SigninServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SysConfigServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SysDeptServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SysDictDataServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SysDictTypeServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SysLogininforServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SysMenuServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SysNoticeServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SysOperLogServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SysPostServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SysRoleServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SysUserOnlineServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/SysUserServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/UserExtraServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/VipServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/system/service/impl/WeiXinRegisterService.java create mode 100644 src/main/java/com/ruoyi/system/system/task/SigninTask.java create mode 100644 src/main/java/com/ruoyi/system/system/task/VipTask.java create mode 100644 src/main/java/com/ruoyi/system/trade/domain/PayLog.java create mode 100644 src/main/java/com/ruoyi/system/trade/domain/Product.java create mode 100644 src/main/java/com/ruoyi/system/trade/domain/UserProductDTO.java create mode 100644 src/main/java/com/ruoyi/system/trade/mapper/PayLogMapper.java create mode 100644 src/main/java/com/ruoyi/system/trade/mapper/ProductMapper.java create mode 100644 src/main/java/com/ruoyi/system/trade/service/IPayLogService.java create mode 100644 src/main/java/com/ruoyi/system/trade/service/IProductService.java create mode 100644 src/main/java/com/ruoyi/system/trade/service/impl/PayLogServiceImpl.java create mode 100644 src/main/java/com/ruoyi/system/trade/service/impl/ProductServiceImpl.java diff --git a/src/main/java/com/ruoyi/system/ai/annotation/LogicStrategy.java b/src/main/java/com/ruoyi/system/ai/annotation/LogicStrategy.java new file mode 100644 index 0000000..739e6a9 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/annotation/LogicStrategy.java @@ -0,0 +1,18 @@ +package com.ruoyi.system.ai.annotation; +import com.muta.ai.chain.DefaultChainFactory; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +/** + * @author: Larry + * @Date: 2024 /05 /01 / 0:10 + * @Description: 规则过滤注解 + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +public @interface LogicStrategy { + DefaultChainFactory.LogicModel logicMode(); + +} diff --git a/src/main/java/com/ruoyi/system/ai/chain/AbstractLogicChain.java b/src/main/java/com/ruoyi/system/ai/chain/AbstractLogicChain.java new file mode 100644 index 0000000..008351a --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/chain/AbstractLogicChain.java @@ -0,0 +1,30 @@ +package com.ruoyi.system.ai.chain; + +import com.muta.ai.domain.RuleLogicEntity; +import lombok.extern.slf4j.Slf4j; + +/** + * @author Fuzhengwei bugstack.cn @小傅哥 + * @description 抽奖策略责任链,判断走那种抽奖策略。如;默认抽象、权重抽奖、黑名单抽奖 + * @create 2024-01-20 09:37 + */ +@Slf4j +public abstract class AbstractLogicChain implements ILogicChain { + + private ILogicChain next; + + @Override + public ILogicChain next() { + return next; + } + + @Override + public ILogicChain appendNext(ILogicChain next) { + this.next = next; + return next; + } + + protected abstract String ruleModel(); + + public abstract RuleLogicEntity logic(UserAccountQuotaEntity userAccountQuotaEntity, MusicProcessAggregate chatProcessAggregate); +} diff --git a/src/main/java/com/ruoyi/system/ai/chain/BackListLogicChain.java b/src/main/java/com/ruoyi/system/ai/chain/BackListLogicChain.java new file mode 100644 index 0000000..b7e148c --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/chain/BackListLogicChain.java @@ -0,0 +1,36 @@ +package com.ruoyi.system.ai.chain; + +import com.muta.ai.annotation.LogicStrategy; +import com.muta.ai.chain.MusicProcessAggregate; +import com.muta.ai.domain.RuleLogicEntity; +import com.muta.ai.chain.UserAccountQuotaEntity; +import com.muta.ai.chain.DefaultChainFactory; +import com.muta.ai.chain.AbstractLogicChain; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @author Fuzhengwei bugstack.cn @小傅哥 + * @description 黑名单责任链 + * @create 2024-01-20 10:23 + */ +@Slf4j +@Component("rule_blacklist") +@LogicStrategy(logicMode = DefaultChainFactory.LogicModel.RULE_BLACKLIST) +public class BackListLogicChain extends AbstractLogicChain { + + ; + + @Override + protected String ruleModel() { + return DefaultChainFactory.LogicModel.RULE_BLACKLIST.getCode(); + } + + + @Override + public RuleLogicEntity logic(UserAccountQuotaEntity userAccountQuotaEntity, MusicProcessAggregate chatProcessAggregate) { + return null; + } + + +} diff --git a/src/main/java/com/ruoyi/system/ai/chain/DefaultChainFactory.java b/src/main/java/com/ruoyi/system/ai/chain/DefaultChainFactory.java new file mode 100644 index 0000000..dad19bd --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/chain/DefaultChainFactory.java @@ -0,0 +1,70 @@ +package com.ruoyi.system.ai.chain; + +import com.muta.ai.annotation.LogicStrategy; +import lombok.*; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author Fuzhengwei bugstack.cn @小傅哥 + * @description 工厂 + * @create 2024-01-20 10:54 + */ +@Service +public class DefaultChainFactory { + public Map> logicFilterMap = new ConcurrentHashMap<>(); + + public DefaultChainFactory(List> logicFilters) { + logicFilters.forEach(logic -> { + LogicStrategy strategy = AnnotationUtils.findAnnotation(logic.getClass(), LogicStrategy.class); + if (null != strategy) { + logicFilterMap.put(strategy.logicMode().getCode(), logic); + } + }); + } + + /** + * 通过策略ID,构建责任链 + * @return LogicChain + */ + public ILogicChain openLogicChain(Long test) { + + List ruleModels = new ArrayList<>(); + ruleModels.add(LogicModel.RULE_BLACKLIST.code); + ruleModels.add(LogicModel.RULE_WEIGHT.code); + ILogicChain current = logicFilterMap.get(LogicModel.RULE_BLACKLIST.getCode()); + System.out.println(current+"current"); + for (int i = 1; i < ruleModels.size(); i++) { + System.out.println(ruleModels.get(i)); + ILogicChain nextChain = logicFilterMap.get(ruleModels.get(i)); + System.out.println(nextChain); + current = current.appendNext(nextChain); + } + current.appendNext(logicFilterMap.get(LogicModel.RULE_DEFAULT.code)); + + return current; + } + + + + @Getter + @AllArgsConstructor + public enum LogicModel { + + RULE_DEFAULT("rule_default", "默认抽奖"), + RULE_BLACKLIST("rule_blacklist", "黑名单抽奖"), + RULE_WEIGHT("rule_weight", "权重规则"), + RULE_SENSITIVE_WORDS("rule_sensitive_words", "敏感词规则过滤"), + RULE_SING("rule_sing", "歌曲过滤"), + ; + private final String code; + private final String info; + + } + +} diff --git a/src/main/java/com/ruoyi/system/ai/chain/DefaultLogicChain.java b/src/main/java/com/ruoyi/system/ai/chain/DefaultLogicChain.java new file mode 100644 index 0000000..9256eca --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/chain/DefaultLogicChain.java @@ -0,0 +1,35 @@ +package com.ruoyi.system.ai.chain; + +import com.muta.ai.annotation.LogicStrategy; +import com.muta.ai.chain.MusicProcessAggregate; +import com.muta.ai.domain.RuleLogicEntity; +import com.muta.ai.chain.UserAccountQuotaEntity; +import com.muta.ai.chain.DefaultChainFactory; +import com.muta.ai.chain.AbstractLogicChain; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +/** + * @author Fuzhengwei bugstack.cn @小傅哥 + * @description 默认的责任链「作为最后一个链」 + * @create 2024-01-20 10:06 + */ +@Slf4j +@Component("rule_default") +@LogicStrategy(logicMode = DefaultChainFactory.LogicModel.RULE_DEFAULT) +public class DefaultLogicChain extends AbstractLogicChain { + + + @Override + protected String ruleModel() { + return DefaultChainFactory.LogicModel.RULE_DEFAULT.getCode(); + } + + @Override + public RuleLogicEntity logic(UserAccountQuotaEntity userAccountQuotaEntity, MusicProcessAggregate chatProcessAggregate) { + System.out.println("测试注入"); + return null; + } + + +} diff --git a/src/main/java/com/ruoyi/system/ai/chain/ILogicChain.java b/src/main/java/com/ruoyi/system/ai/chain/ILogicChain.java new file mode 100644 index 0000000..e2ae8ae --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/chain/ILogicChain.java @@ -0,0 +1,17 @@ +package com.ruoyi.system.ai.chain; + +import com.muta.ai.domain.RuleLogicEntity; + +/** + * @author Fuzhengwei bugstack.cn @小傅哥 + * @description 抽奖策略规则责任链接口 + * @create 2024-01-20 09:40 + */ +public interface ILogicChain extends ILogicChainArmory, Cloneable { + + /** + * 责任链接口 + */ + RuleLogicEntity logic(UserAccountQuotaEntity userAccountQuotaEntity, MusicProcessAggregate data); + +} diff --git a/src/main/java/com/ruoyi/system/ai/chain/ILogicChainArmory.java b/src/main/java/com/ruoyi/system/ai/chain/ILogicChainArmory.java new file mode 100644 index 0000000..12b1150 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/chain/ILogicChainArmory.java @@ -0,0 +1,14 @@ +package com.ruoyi.system.ai.chain; + +/** + * @author Fuzhengwei bugstack.cn @小傅哥 + * @description 责任链装配 + * @create 2024-01-20 11:53 + */ +public interface ILogicChainArmory { + + ILogicChain next(); + + ILogicChain appendNext(ILogicChain next); + +} diff --git a/src/main/java/com/ruoyi/system/ai/chain/MusicProcessAggregate.java b/src/main/java/com/ruoyi/system/ai/chain/MusicProcessAggregate.java new file mode 100644 index 0000000..24988ed --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/chain/MusicProcessAggregate.java @@ -0,0 +1,30 @@ +package com.ruoyi.system.ai.chain; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author Fuzhengwei bugstack.cn @小傅哥 + * @description + * @create 2023-07-22 21:09 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MusicProcessAggregate { + /** + * 歌手ID + */ + private Long singerId; + /** + * 音乐ID + */ + private Integer musicId; + /** 提示词 */ + private String prompt; + +} diff --git a/src/main/java/com/ruoyi/system/ai/chain/RuleWeightLogicChain.java b/src/main/java/com/ruoyi/system/ai/chain/RuleWeightLogicChain.java new file mode 100644 index 0000000..9ef25a8 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/chain/RuleWeightLogicChain.java @@ -0,0 +1,40 @@ +package com.ruoyi.system.ai.chain; + + +import com.muta.ai.annotation.LogicStrategy; +import com.muta.ai.chain.MusicProcessAggregate; +import com.muta.ai.domain.RuleLogicEntity; +import com.muta.ai.chain.UserAccountQuotaEntity; +import com.muta.ai.chain.DefaultChainFactory; +import com.muta.ai.chain.AbstractLogicChain; +import com.muta.system.service.IUserExtraService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * @author Fuzhengwei bugstack.cn @小傅哥 + * @description 权重抽奖责任链 + * @create 2024-01-20 10:38 + */ +@Slf4j +@Component("rule_UserAccountQuota") +@LogicStrategy(logicMode = DefaultChainFactory.LogicModel.RULE_WEIGHT) +public class RuleWeightLogicChain extends AbstractLogicChain { + @Resource + private IUserExtraService userExtraService; + + @Override + protected String ruleModel() { + return DefaultChainFactory.LogicModel.RULE_WEIGHT.getCode(); + } + + @Override + public RuleLogicEntity logic(UserAccountQuotaEntity userAccountQuotaEntity, MusicProcessAggregate chatProcessAggregate) { + return null; + } + + + +} diff --git a/src/main/java/com/ruoyi/system/ai/chain/UserAccountQuotaEntity.java b/src/main/java/com/ruoyi/system/ai/chain/UserAccountQuotaEntity.java new file mode 100644 index 0000000..5b27984 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/chain/UserAccountQuotaEntity.java @@ -0,0 +1,36 @@ +package com.ruoyi.system.ai.chain; + + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Arrays; +import java.util.List; + +/** + * @author Fuzhengwei bugstack.cn @小傅哥 + * @description 用户账户额度实体对象 + * @create 2023-10-03 16:49 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class UserAccountQuotaEntity { + /** + * 用户ID + */ + private Long userId; + /** + * 剩余额度 + */ + private Integer integral; + /** + * 会员等级 + */ + private Integer vipGrade; + + +} diff --git a/src/main/java/com/ruoyi/system/ai/config/ChatConfig.java b/src/main/java/com/ruoyi/system/ai/config/ChatConfig.java new file mode 100644 index 0000000..86b1f32 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/config/ChatConfig.java @@ -0,0 +1,24 @@ +package com.ruoyi.system.ai.config; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author: Larry + * @Date: 2024 /05 /11 / 14:18 + * @Description: + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class ChatConfig { + private Long id; + private Long userId; + private float temperature; + private Integer maxToken; + private Integer n; + private float top; +} diff --git a/src/main/java/com/ruoyi/system/ai/config/CustomWordAllow.java b/src/main/java/com/ruoyi/system/ai/config/CustomWordAllow.java new file mode 100644 index 0000000..f2da3f4 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/config/CustomWordAllow.java @@ -0,0 +1,32 @@ +package com.ruoyi.system.ai.config; + +import com.github.houbb.sensitive.word.api.IWordAllow; +import org.apache.commons.compress.utils.Lists; + +import java.util.ArrayList; +import java.util.List; + +/** + * 自定义敏感词白名单 + * + * @author Larry + * @date 2024-05-18 15:07:01 + */ +public class CustomWordAllow implements IWordAllow { + + /** + * 允许的内容-返回的内容不被当做敏感词 + * + * @return + */ + @Override + public List allow() { + // 可以获取数据库数据或文件内容 + List list = new ArrayList<>(); + list.add("草"); + list.add("小草"); + list.add(""); + return list; + } + +} \ No newline at end of file diff --git a/src/main/java/com/ruoyi/system/ai/config/CustomWordDeny.java b/src/main/java/com/ruoyi/system/ai/config/CustomWordDeny.java new file mode 100644 index 0000000..54fc1f3 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/config/CustomWordDeny.java @@ -0,0 +1,30 @@ +package com.ruoyi.system.ai.config; + +import com.github.houbb.sensitive.word.api.IWordDeny; +import org.apache.commons.compress.utils.Lists; + +import java.util.ArrayList; +import java.util.List; + +/** + * 自定义敏感词黑名单 + * + * @author Larry + * @date 2024-05-08 14:59:51 + */ +public class CustomWordDeny implements IWordDeny { + + /** + * 拒绝出现的数据-返回的内容被当做是敏感词 + * + * @return + */ + @Override + public List deny() { + // 可以获取数据库数据或文件内容 + List list = new ArrayList<>(); + list.add("测试"); + return list; + } + +} \ No newline at end of file diff --git a/src/main/java/com/ruoyi/system/ai/config/LogicConfig.java b/src/main/java/com/ruoyi/system/ai/config/LogicConfig.java new file mode 100644 index 0000000..b158dbf --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/config/LogicConfig.java @@ -0,0 +1,70 @@ +package com.ruoyi.system.ai.config;//package com.muta.ai.config; +// +//import com.muta.ai.chain.UserAccountQuotaEntity; +//import com.muta.ai.service.ILogicFilter; +//import com.muta.ai.service.impl.SensitiveWordFilter; +//import com.muta.ai.service.impl.TokenFilter; +//import com.muta.ai.service.impl.UserQuotaFilter; +// +//import javax.annotation.PostConstruct; +//import javax.annotation.Resource; +//import java.util.Map; +//import java.util.concurrent.ConcurrentHashMap; +// +///** +// * @author: Larry +// * @Date: 2024 /05 /09 / 20:35 +// * @Description: +// */ +//public class LogicConfig { +// public Map> logicFilterMap = new ConcurrentHashMap<>(); +// @Resource +// private SensitiveWordFilter sensitiveWordFilter; +// @Resource +// private TokenFilter tokenFilter; +// @Resource +// private UserQuotaFilter userQuotaFilter; +// @PostConstruct +// private void init(){ +// logicFilterMap.put(LogicModel.SENSITIVE_WORD.code,sensitiveWordFilter); +// logicFilterMap.put(LogicModel.MAX_TOKEN.code,tokenFilter); +// logicFilterMap.put(LogicModel.USER_QUOTA.code, userQuotaFilter); +// +// } +// public enum LogicModel { +// +// NULL("NULL", "放行不用过滤"), +// MAX_TOKEN("TOKEN_LIMIT", "限制最大会话数"), +// SENSITIVE_WORD("SENSITIVE_WORD", "敏感词过滤"), +// USER_QUOTA("USER_QUOTA", "用户额度过滤"), +//// MODEL_TYPE("MODEL_TYPE", "模型可用范围过滤"), +//// ACCOUNT_STATUS("ACCOUNT_STATUS", "账户状态过滤"), +// +// ; +// +// private String code; +// private String info; +// +// LogicModel(String code, String info) { +// this.code = code; +// this.info = info; +// } +// +// public String getCode() { +// return code; +// } +// +// public void setCode(String code) { +// this.code = code; +// } +// +// public String getInfo() { +// return info; +// } +// +// public void setInfo(String info) { +// this.info = info; +// } +// } +// +//} diff --git a/src/main/java/com/ruoyi/system/ai/config/MessageMqConfig.java b/src/main/java/com/ruoyi/system/ai/config/MessageMqConfig.java new file mode 100644 index 0000000..e8eda82 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/config/MessageMqConfig.java @@ -0,0 +1,85 @@ +package com.ruoyi.system.ai.config; +import lombok.Data; +import org.springframework.amqp.core.Binding; +import org.springframework.amqp.core.Exchange; +import org.springframework.amqp.core.Queue; +import org.springframework.amqp.core.TopicExchange; +import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; + +import javax.annotation.Resource; + +/** + * @ClassName RabbitMQConfig + * @Author Larr + * @create 2024/5/12 15:23 + */ +@Configuration +@Data +public class MessageMqConfig { + /** + * 交换机 + */ + @Value("${mqconfig.message_event_exchange}") + private String eventExchange; + /** + * 第⼀个队列延迟队列, + */ + + @Value("${mqconfig.message_queue}") + private String MessageQueue; + /** + * 第⼀个队列的路由key + * 进⼊队列的路由key + */ + + @Value("${mqconfig.message_routing_key}") + private String MessageRoutingKey; + /** + * 过期时间 + */ + @Value("${mqconfig.ttl}") + private Integer ttl; + @Bean + public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) { + RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory); + rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter()); + return rabbitTemplate; + } + + @Bean + public Exchange MessageEventExchange() { + return new TopicExchange(eventExchange, true, false); + } + @Bean + public Queue MessageQueue() { + return new Queue(MessageQueue, true, false, false); + } + @Bean + public Binding couponRelaseBinding() { + return new Binding(MessageQueue, Binding.DestinationType.QUEUE, eventExchange, MessageRoutingKey, null); + } + + + + /** + * @Author Administrator + * 延迟队列 + **/ +// @Bean +// public Queue couponReleaseDelayQueue() { +// Map args = new HashMap<>(3); +// args.put("x-message-ttl", ttl); +// args.put("x-dead-letter-routing-key", couponReleaseRoutingKey); +// args.put("x-dead-letter-exchange", eventExchange); +// return new Queue(couponReleaseDelayQueue, true, false, false, args); +// } + +} diff --git a/src/main/java/com/ruoyi/system/ai/config/SensitiveWordConfig.java b/src/main/java/com/ruoyi/system/ai/config/SensitiveWordConfig.java new file mode 100644 index 0000000..e6ce8bb --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/config/SensitiveWordConfig.java @@ -0,0 +1,30 @@ +package com.ruoyi.system.ai.config; + +import com.github.houbb.sensitive.word.bs.SensitiveWordBs; +import com.github.houbb.sensitive.word.core.SensitiveWordHelper; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * 敏感词过滤配置 + * + * @author 一个肥鲇鱼 + * @date 2023-09-08 14:28:45 + */ +@Configuration +public class SensitiveWordConfig { + + /** + * 初始化引导类 + * + * @return 初始化引导类 + * @since 1.0.0 + */ + @Bean(value = "sensitiveWordBsBean") + public SensitiveWordBs sensitiveWordBs() { + System.out.println("测试"); + // 设置系统默认敏感词 + return SensitiveWordBs.newInstance().wordDeny(new CustomWordDeny()).wordAllow(new CustomWordAllow()).init(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/ruoyi/system/ai/config/WebSocketConfiguration.java b/src/main/java/com/ruoyi/system/ai/config/WebSocketConfiguration.java new file mode 100644 index 0000000..31cfd94 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/config/WebSocketConfiguration.java @@ -0,0 +1,34 @@ +package com.ruoyi.system.ai.config; + +import org.springframework.boot.web.servlet.ServletContextInitializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.server.standard.ServerEndpointExporter; +import org.springframework.web.util.WebAppRootListener; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; + +/** + * @author Frankiefly + * 2024/3/23 + */ + +@Configuration +public class WebSocketConfiguration implements ServletContextInitializer { + + @Bean + public ServerEndpointExporter serverEndpointExporter(){ + return new ServerEndpointExporter(); + } + + @Override + public void onStartup(ServletContext servletContext) throws ServletException { + servletContext.addListener(WebAppRootListener.class); + //这里设置了1024M的缓冲区 + //Tomcat每次请求过来时在创建session时都会把这个webSocketContainer作为参数传进去所以对所有的session都生效了 + servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize","1024000"); + + } + +} diff --git a/src/main/java/com/ruoyi/system/ai/config/server/Client.java b/src/main/java/com/ruoyi/system/ai/config/server/Client.java new file mode 100644 index 0000000..6fb304d --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/config/server/Client.java @@ -0,0 +1,524 @@ +package com.ruoyi.system.ai.config.server; + +import com.alibaba.fastjson.JSONObject; +import com.google.gson.annotations.SerializedName; +import com.google.gson.Gson; +import com.muta.ai.domain.ChatCompletionMessage; +import io.reactivex.BackpressureStrategy; +import io.reactivex.Flowable; +import netscape.javascript.JSObject; + +import java.io.IOException; +import java.util.List; +import java.util.Objects; + +public class Client { + private static final String DEFAULT_BASE_URL = "https://api.moonshot.cn/v1"; + + private static final String CHAT_COMPLETION_SUFFIX = "/chat/completions"; + private static final String MODELS_SUFFIX = "/models"; + private static final String FILES_SUFFIX = "/files"; + + private String baseUrl; + private String apiKey; + + public Client(String apiKey) { + this(apiKey, DEFAULT_BASE_URL); + } + + public Client(String apiKey, String baseUrl) { + this.apiKey = apiKey; + if (baseUrl.endsWith("/")) { + baseUrl = baseUrl.substring(0, baseUrl.length() - 1); + } + this.baseUrl = baseUrl; + } + + public String getChatCompletionUrl() { + return baseUrl + CHAT_COMPLETION_SUFFIX; + } + + public String getModelsUrl() { + return baseUrl + MODELS_SUFFIX; + } + + public String getFilesUrl() { + return baseUrl + FILES_SUFFIX; + } + + public String getApiKey() { + return apiKey; + } + + public ModelsList ListModels() throws IOException { + okhttp3.OkHttpClient client = new okhttp3.OkHttpClient(); + okhttp3.Request request = new okhttp3.Request.Builder() + .url(getModelsUrl()) + .addHeader("Authorization", "Bearer " + getApiKey()) + .build(); + try { + okhttp3.Response response = client.newCall(request).execute(); + String body = response.body().string(); + Gson gson = new Gson(); + return gson.fromJson(body, ModelsList.class); + } catch (IOException e) { + e.printStackTrace(); + throw e; + } + } + + + public ChatCompletionResponse ChatCompletion(ChatCompletionRequest request) throws IOException { + request.stream = false; + okhttp3.OkHttpClient client = new okhttp3.OkHttpClient(); + okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json"); + okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, new Gson().toJson(request)); + okhttp3.Request httpRequest = new okhttp3.Request.Builder() + .url(getChatCompletionUrl()) + .addHeader("Authorization", "Bearer " + getApiKey()) + .addHeader("Content-Type", "application/json") + .post(body) + .build(); + try { + okhttp3.Response response = client.newCall(httpRequest).execute(); + String responseBody = response.body().string(); + System.out.println(responseBody); + Gson gson = new Gson(); + return gson.fromJson(responseBody, ChatCompletionResponse.class); + } catch (IOException e) { + e.printStackTrace(); + throw e; + } + } + + // return a stream of ChatCompletionStreamResponse + public Flowable ChatCompletionStream(ChatCompletionRequest request) throws IOException { + request.stream = true; + okhttp3.OkHttpClient client = new okhttp3.OkHttpClient(); + okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json"); + okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, new Gson().toJson(request)); + okhttp3.Request httpRequest = new okhttp3.Request.Builder() + .url(getChatCompletionUrl()) + .addHeader("Authorization", "Bearer " + getApiKey()) + .addHeader("Content-Type", "application/json") + .post(body) + .build(); + okhttp3.Response response = client.newCall(httpRequest).execute(); + if (response.code() != 200) { + System.err.println(response); + throw new RuntimeException("Failed to start stream: " + response.body().string()); + } + + // get response body line by line + return Flowable.create(emitter -> { + okhttp3.ResponseBody responseBody = response.body(); + if (responseBody == null) { + emitter.onError(new RuntimeException("Response body is null")); + return; + } + String line; + while ((line = responseBody.source().readUtf8Line()) != null) { + if (line.startsWith("data:")) { + line = line.substring(5); + line = line.trim(); + } + if (Objects.equals(line, "[DONE]")) { + emitter.onComplete(); + return; + } + line = line.trim(); + if (line.isEmpty()) { + continue; + } + //System.out.println(line); + Gson gson = new Gson(); + ChatCompletionStreamResponse streamResponse = gson.fromJson(line, ChatCompletionStreamResponse.class); + emitter.onNext(streamResponse); + } + emitter.onComplete(); + }, BackpressureStrategy.BUFFER); + } +} + + + +enum ChatMessageRole { + SYSTEM, USER, ASSISTANT; + + public String value() { + return this.name().toLowerCase(); + } +} + + + +class ChatCompletionStreamChoiceDelta { + private String content; + private String role; + + public String getContent() { + return content; + } + + public String getRole() { + return role; + } + + public void setContent(String content) { + this.content = content; + } + + public void setRole(String role) { + this.role = role; + } + + public ChatCompletionStreamChoiceDelta(String content, String role) { + this.content = content; + this.role = role; + } + + @Override + public String toString() { + return "ChatCompletionStreamChoiceDelta{" + + "content='" + content + '\'' + + ", role='" + role + '\'' + + '}'; + } +} + +class Usage { + private int prompt_tokens; + private int completion_tokens; + private int total_tokens; + + public int getPrompt_tokens() { + return prompt_tokens; + } + + public void setPrompt_tokens(int prompt_tokens) { + this.prompt_tokens = prompt_tokens; + } + + public int getCompletion_tokens() { + return completion_tokens; + } + + public void setCompletion_tokens(int completion_tokens) { + this.completion_tokens = completion_tokens; + } + + public int getTotal_tokens() { + return total_tokens; + } + + public void setTotal_tokens(int total_tokens) { + this.total_tokens = total_tokens; + } + + public Usage(int prompt_tokens, int completion_tokens, int total_tokens) { + this.prompt_tokens = prompt_tokens; + this.completion_tokens = completion_tokens; + this.total_tokens = total_tokens; + } + + public Usage() { + } + + @Override + public String toString() { + return "Usage{" + + "prompt_tokens=" + prompt_tokens + + ", completion_tokens=" + completion_tokens + + ", total_tokens=" + total_tokens + + '}'; + } +} + +class ChatCompletionStreamChoice { + private int index; + private ChatCompletionStreamChoiceDelta delta; + + @SerializedName("finish_reason") + private String finishReason; + private Usage usage; + + public int getIndex() { + return index; + } + + public ChatCompletionStreamChoiceDelta getDelta() { + return delta; + } + + public String getFinishReason() { + return finishReason; + } + + public Usage getUsage() { + return usage; + } + + public void setIndex(int index) { + this.index = index; + } + + public void setDelta(ChatCompletionStreamChoiceDelta delta) { + this.delta = delta; + } + + public void setFinishReason(String finishReason) { + this.finishReason = finishReason; + } + + public void setUsage(Usage usage) { + this.usage = usage; + } + + public ChatCompletionStreamChoice(int index, ChatCompletionStreamChoiceDelta delta, String finishReason, Usage usage) { + this.index = index; + this.delta = delta; + this.finishReason = finishReason; + this.usage = usage; + } + + @Override + public String toString() { + return "ChatCompletionStreamChoice{" + + "index=" + index + + ", delta=" + delta + + ", finishReason='" + finishReason + '\'' + + ", usage=" + usage + + '}'; + } +} + +class ChatCompletionStreamResponse { + private String id; + private String object; + private long created; + private String model; + private List choices; + + public String getId() { + return id; + } + + public String getObject() { + return object; + } + + public long getCreated() { + return created; + } + + public String getModel() { + return model; + } + + public List getChoices() { + return choices; + } + + public void setId(String id) { + this.id = id; + } + + public void setObject(String object) { + this.object = object; + } + + public void setCreated(long created) { + this.created = created; + } + + @Override + public String toString() { + return "ChatCompletionStreamResponse{" + + "id='" + id + '\'' + + ", object='" + object + '\'' + + ", created=" + created + + ", model='" + model + '\'' + + ", choices=" + choices + + '}'; + } +} + +class ChatCompletionChoice { + private int index; + private ChatCompletionMessage message; + + @SerializedName("finish_reason") + private String finishReason; + + public int getIndex() { + return index; + } + + public ChatCompletionMessage getMessage() { + return message; + } + + public String getFinishReason() { + return finishReason; + } + + public void setIndex(int index) { + this.index = index; + } + + public void setMessage(ChatCompletionMessage message) { + this.message = message; + } + + public void setFinishReason(String finishReason) { + this.finishReason = finishReason; + } + +} + +class ChatCompletionResponse { + private String id; + private String object; + private long created; + private String model; + private List choices; + private Usage usage; + + public String getId() { + return id; + } + + public String getObject() { + return object; + } + + public long getCreated() { + return created; + } + + public String getModel() { + return model; + } + + public List getChoices() { + if (choices == null) { + return List.of(); + } + return choices; + } +} + + +class ChatCompletionRequest { + public String model; + public List messages; + + @SerializedName("max_tokens") + public int maxTokens; + + @SerializedName("temperature") + public float temperature; + public float topP; + + public Integer n; + public boolean stream; + public List stop; + + @SerializedName("presence_penalty") + public float presencePenalty; + + @SerializedName("frequency_penalty") + public float frequencyPenalty; + + public String user; + + public List getMessages() { + return messages; + } + + public ChatCompletionRequest(String model, List messages, int maxTokens, float temperature, int n, float topP) { + this.model = model; + this.messages = messages; + this.maxTokens = maxTokens; + this.temperature = temperature; + this.n = n; + this.topP = topP; + } + +} + +class Model { + private String id; + private String object; + + @SerializedName("owner_by") + private String ownedBy; + private String root; + private String parent; + + public String getId() { + return id; + } + + public String getObject() { + return object; + } + + public String getOwnedBy() { + return ownedBy; + } + + public String getRoot() { + return root; + } + + public String getParent() { + return parent; + } + + public void setId(String id) { + this.id = id; + } + + public void setObject(String object) { + this.object = object; + } + + public void setOwnedBy(String ownedBy) { + this.ownedBy = ownedBy; + } + + public void setRoot(String root) { + this.root = root; + } + + public void setParent(String parent) { + this.parent = parent; + } + + public Model(String id, String object, String ownedBy, String root, String parent) { + this.id = id; + this.object = object; + this.ownedBy = ownedBy; + this.root = root; + this.parent = parent; + } +} + +class ModelsList { + private List data; + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public ModelsList(List data) { + this.data = data; + } +} + + diff --git a/src/main/java/com/ruoyi/system/ai/config/server/WebSocketServer.java b/src/main/java/com/ruoyi/system/ai/config/server/WebSocketServer.java new file mode 100644 index 0000000..3ef75b4 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/config/server/WebSocketServer.java @@ -0,0 +1,187 @@ +package com.ruoyi.system.ai.config.server; + +import cn.hutool.core.collection.CollectionUtil; +import com.muta.ai.chain.MusicProcessAggregate; +import com.muta.ai.chain.UserAccountQuotaEntity; +import com.muta.ai.config.ChatConfig; +import com.muta.ai.domain.*; +import com.muta.ai.enums.LogicCheckEnum; +import com.muta.ai.service.IChatConfigService; +import com.muta.ai.service.IMessageFileService; +import com.muta.ai.service.impl.KimiChatService; +import com.muta.common.utils.StringUtils; +import org.json.JSONObject; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; +import javax.annotation.Resource; +import javax.websocket.*; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; + + +@Component +@ServerEndpoint(value = "/chatgpt/{sid}") +public class WebSocketServer { + + private static IChatConfigService chatConfigService; + + private static RedisTemplate redisTemplate; + + private static KimiChatService kimiChatService; + + private static IMessageFileService messageFileService; + + @Resource + public void setChatConfigService(IChatConfigService chatConfigService) { + WebSocketServer.chatConfigService = chatConfigService; + } + + @Resource + public void setMessageFileService(IMessageFileService messageFileService) { + WebSocketServer.messageFileService = messageFileService; + } + + @Resource + public void setKimiChatService(KimiChatService kimiChatService) { + WebSocketServer.kimiChatService = kimiChatService; + } + + @Resource + public void setChatgptService(RedisTemplate redisTemplate) { + WebSocketServer.redisTemplate = redisTemplate; + } + + private static Map sessionMap = new HashMap<>(); + + @OnOpen + public void onOpen(Session session, @PathParam("sid") String sid) { + System.out.println("客户端: " + sid + "建立连接"); + sessionMap.put(sid, session); + } + + @OnMessage + public void onMessage(String jsonFrom, @PathParam("sid") String sid) throws Exception { + JSONObject jsonParse = new JSONObject(jsonFrom); + + String url = jsonFrom.contains("\"url\"") ? jsonParse.getString("url") : null; + String content = jsonParse.getString("content"); + String model = jsonParse.getString("model"); + + if (StringUtils.isNotEmpty(url)) { + content += " " + messageFileService.getContentByUrl(url); + } + + Long userId = Long.valueOf(sid.split(":")[0]); + + List history = redisTemplate.opsForSet().members(sid).stream().collect(Collectors.toList()); + List messages = CollectionUtil.isEmpty(history) ? new ArrayList<>() : history; + messages.add(new ChatCompletionMessage(ChatMessageRole.USER.value(), content)); + + for (ChatCompletionMessage message : messages) { + System.out.println(message.toString()); + } + + + MusicProcessAggregate chatProcessAggregate = kimiChatService.initChatData(userId, model, messages); + System.out.println(chatProcessAggregate.toString()); + UserAccountQuotaEntity userAccountQuotaEntity = kimiChatService.initUserData(userId); + System.out.println(userAccountQuotaEntity.toString()); + // + RuleLogicEntity logicRes = kimiChatService.doCheckLogic(chatProcessAggregate, userAccountQuotaEntity); + if(logicRes.getType().equals(LogicCheckEnum.REFUSE)){ + sendToClient(sid, logicRes.getInfo()); + } + else { + System.err.println(chatProcessAggregate.getKey()); + Client client = new Client(chatProcessAggregate.getKey()); + StringBuffer stringBuffer = new StringBuffer(); + + AtomicBoolean flag = new AtomicBoolean(true); + AtomicReference role = new AtomicReference<>(); + ChatConfig config = chatConfigService.selectChatConfigById(userId); + + + try { + + String finalContent = content; + client.ChatCompletionStream(new ChatCompletionRequest( + model, + messages, + userAccountQuotaEntity.getMaxToken(), + config.getTemperature(), + config.getN(), + config.getTop() + )).subscribe( + streamResponse -> { + if (streamResponse.getChoices().isEmpty()) { + return; + } + for (ChatCompletionStreamChoice choice : streamResponse.getChoices()) { + if (flag.getAndSet(false)) { + role.set(choice.getDelta().getRole()); + } + String finishReason = choice.getFinishReason(); + System.out.println(choice.getDelta().getContent()); + stringBuffer.append(choice.getDelta().getContent()); + if (finishReason != null) { + System.out.println(streamResponse); + System.out.println(sid); + MessageEntity messageEntity + = MessageEntity.builder() + .model(streamResponse.getModel()) + .role(role.get()) + .userId(userId) + .content(stringBuffer.toString()) + .finishReason(finishReason) + .promptTokens(choice.getUsage().getPrompt_tokens()) + .completionTokens(choice.getUsage().getCompletion_tokens()) + .totalTokens(choice.getUsage().getTotal_tokens()) + .sessionId(sid) + .build(); + + System.out.println(messageEntity.toString()); + kimiChatService.PostRule(chatProcessAggregate,userAccountQuotaEntity, messageEntity); + continue; + } + sendToClient(sid, choice.getDelta().getContent()); + } + }, + error -> { + error.printStackTrace(); + }, + () -> { + System.out.println("complete"); + +// redisTemplate.opsForSet().remove(sid); +// Set members = redisTemplate.opsForSet().members(sid); +// members.add(new ChatCompletionMessage(ChatMessageRole.USER.value(), finalContent)); + redisTemplate.opsForSet().add(sid, new ChatCompletionMessage(ChatMessageRole.USER.value(), finalContent)); + } + ); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + @OnClose + public void onClose(@PathParam("sid") String sid){ + System.out.println("连接断开: " + sid); + sessionMap.remove(sid); + } + + public void sendToClient(String sid, String result){ + Session session = sessionMap.get(sid); + try { + session.getBasicRemote().sendText(result); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} + diff --git a/src/main/java/com/ruoyi/system/ai/domain/AiKey.java b/src/main/java/com/ruoyi/system/ai/domain/AiKey.java new file mode 100644 index 0000000..4ead0f6 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/domain/AiKey.java @@ -0,0 +1,50 @@ +package com.ruoyi.system.ai.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.muta.common.core.MutaBaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AiKey extends MutaBaseEntity { + + /** 主键 */ + @TableId(value = "id",type = IdType.AUTO) + private Long id; + + /** key值 */ + @TableField("`key`") + private String key; + + /** 代理 */ + @TableField("`host`") + private String host; + + /** 可用模型 */ + @TableField("`model_list`") + private String modelList; + + /** ai类型 */ + @TableField("`type`") + private Integer type; + + /** 状态 */ + @TableField("`status`") + private String status; + + /** 额度 */ + @TableField("`limit`") + private BigDecimal limit; + /** 用户id */ + @TableField("`user_id`") + private Long userId; +} diff --git a/src/main/java/com/ruoyi/system/ai/domain/ChatCompletionMessage.java b/src/main/java/com/ruoyi/system/ai/domain/ChatCompletionMessage.java new file mode 100644 index 0000000..05199ce --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/domain/ChatCompletionMessage.java @@ -0,0 +1,40 @@ +package com.ruoyi.system.ai.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@Builder +public class ChatCompletionMessage { + public String role; + public String name; + public String content; + public Boolean partial; + + public ChatCompletionMessage(String role, String content) { + this.role = role; + this.content = content; + } + + public ChatCompletionMessage(String role, String name, String content, Boolean partial) { + this.role = role; + this.name = name; + this.content = content; + this.partial = partial; + } + + public String getName() { + return name; + } + + public String getContent() { + return content; + } + + public Boolean getPartial() { + return partial; + } +} \ No newline at end of file diff --git a/src/main/java/com/ruoyi/system/ai/domain/ChatConfig.java b/src/main/java/com/ruoyi/system/ai/domain/ChatConfig.java new file mode 100644 index 0000000..b3428d9 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/domain/ChatConfig.java @@ -0,0 +1,26 @@ +package com.ruoyi.system.ai.domain;//package com.muta.ai.domain; +// +//import com.baomidou.mybatisplus.annotation.TableName; +//import lombok.AllArgsConstructor; +//import lombok.Builder; +//import lombok.Data; +//import lombok.NoArgsConstructor; +// +///** +// * @author: Larry +// * @Date: 2024 /05 /11 / 14:18 +// * @Description: +// */ +//@Data +//@AllArgsConstructor +//@NoArgsConstructor +//@Builder +//@TableName("chat_config") +//public class ChatConfig { +// private Long id; +// private Long userId; +// private float temperature; +// private String maxToken; +// private Integer n; +// private float top; +//} diff --git a/src/main/java/com/ruoyi/system/ai/domain/MessageEntity.java b/src/main/java/com/ruoyi/system/ai/domain/MessageEntity.java new file mode 100644 index 0000000..be9b29f --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/domain/MessageEntity.java @@ -0,0 +1,46 @@ +package com.ruoyi.system.ai.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.muta.common.core.MutaBaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * @author: Larry + * @Date: 2024 /05 /09 / 13:17 + * @Description: + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class MessageEntity extends MutaBaseEntity { + @TableId(type = IdType.AUTO) + private Long id; + private Long userId; + + private String content; + + private String role; + + private String model; + + private String url; + + private String finishReason; + + private String sessionId; + + private Integer promptTokens; + + private Integer completionTokens; + + private Integer totalTokens; + + +} diff --git a/src/main/java/com/ruoyi/system/ai/domain/MessageFile.java b/src/main/java/com/ruoyi/system/ai/domain/MessageFile.java new file mode 100644 index 0000000..0a29a6b --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/domain/MessageFile.java @@ -0,0 +1,55 @@ +package com.ruoyi.system.ai.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.muta.common.core.MutaBaseEntity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * @author 马兰友 + * @Date: 2024/05/17/14:57 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@AllArgsConstructor +@NoArgsConstructor +public class MessageFile extends MutaBaseEntity { + + /** + * 主键 + */ + @TableId(type = IdType.AUTO) + @JsonFormat(shape =JsonFormat.Shape.STRING) + private Long id; + + /** + * 文件名(传进来时) + */ + private String name; + + /** + * 文件url,也就是阿里云存储的url + */ + private String url; + + /** + * 文件大小 + */ + private String size; + + /** + * 解析后文件内容 + */ + private String analysisContent; + + /** + * 对应的消息id + */ + @JsonFormat(shape =JsonFormat.Shape.STRING) + private Long messageId; + +} diff --git a/src/main/java/com/ruoyi/system/ai/domain/MessageSession.java b/src/main/java/com/ruoyi/system/ai/domain/MessageSession.java new file mode 100644 index 0000000..a64f289 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/domain/MessageSession.java @@ -0,0 +1,35 @@ +package com.ruoyi.system.ai.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.muta.common.core.MutaBaseEntity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +/** + * @author 马兰友 + * @Date: 2024/05/13/15:52 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@AllArgsConstructor +@NoArgsConstructor +public class MessageSession extends MutaBaseEntity { + + /** + * id + */ + @TableId(type = IdType.AUTO) + @JsonFormat(shape =JsonFormat.Shape.STRING) + private Long id; + + /** + * userId + */ + @JsonFormat(shape =JsonFormat.Shape.STRING) + private Long userId; + +} diff --git a/src/main/java/com/ruoyi/system/ai/domain/RuleLogicEntity.java b/src/main/java/com/ruoyi/system/ai/domain/RuleLogicEntity.java new file mode 100644 index 0000000..909ca48 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/domain/RuleLogicEntity.java @@ -0,0 +1,23 @@ +package com.ruoyi.system.ai.domain; +import com.muta.ai.enums.LogicCheckEnum; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author Fuzhengwei bugstack.cn @小傅哥 + * @description 规则校验结果实体 + * @create 2023-09-16 17:02 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class RuleLogicEntity { + + private LogicCheckEnum type; + private String info; + private T data; + +} diff --git a/src/main/java/com/ruoyi/system/ai/domain/dto/MessageHistoryKimi.java b/src/main/java/com/ruoyi/system/ai/domain/dto/MessageHistoryKimi.java new file mode 100644 index 0000000..a8ce10b --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/domain/dto/MessageHistoryKimi.java @@ -0,0 +1,26 @@ +package com.ruoyi.system.ai.domain.dto; + +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author: Larry + * @Date: 2024 /05 /10 / 18:41 + * @Description: + */ + +@NoArgsConstructor +@Data +@Builder +public class MessageHistoryKimi { + private String role; + + private String content; + + public MessageHistoryKimi(String role, String content) { + this.role = role; + this.content = content; + + } +} diff --git a/src/main/java/com/ruoyi/system/ai/domain/dto/PostDTO.java b/src/main/java/com/ruoyi/system/ai/domain/dto/PostDTO.java new file mode 100644 index 0000000..bf8ad38 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/domain/dto/PostDTO.java @@ -0,0 +1,45 @@ +package com.ruoyi.system.ai.domain.dto; + +import com.muta.ai.domain.ChatCompletionMessage; +import com.muta.ai.domain.MessageEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /05 /21 / 17:55 + * @Description: + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PostDTO { + private MessageEntity message; + /** + * 用户ID + */ + private Long userId; + /** + * 所选模型 + */ + private String model; + /** 历史消息 */ + private List messages; + /** + * 所用key + */ + private String key; + /** + * 模型单位积分对应key + */ + private Integer modelConsumer; + /** + * 上下文token数量 + */ + private Integer tokenNum; +} diff --git a/src/main/java/com/ruoyi/system/ai/domain/event/MessageEvent.java b/src/main/java/com/ruoyi/system/ai/domain/event/MessageEvent.java new file mode 100644 index 0000000..b618ab2 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/domain/event/MessageEvent.java @@ -0,0 +1,31 @@ +package com.ruoyi.system.ai.domain.event; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @author: Larry + * @Date: 2024 /05 /15 / 17:44 + * @Description: + */ +@AllArgsConstructor +@NoArgsConstructor +@Data +@Builder +public class MessageEvent implements Serializable { + private static final long serialVersionUID = 3349917261877342192L; + private Long userId; + private String finishReason; + private String promptTokens; + private String completionTokens; + private Integer totalTokens; + private String content; + private String role; + private String model; + private String username; + private Long sessionId; +} diff --git a/src/main/java/com/ruoyi/system/ai/enums/LogicCheckEnum.java b/src/main/java/com/ruoyi/system/ai/enums/LogicCheckEnum.java new file mode 100644 index 0000000..0c3e7b4 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/enums/LogicCheckEnum.java @@ -0,0 +1,22 @@ +package com.ruoyi.system.ai.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author Larry + * @description 逻辑校验类型,值对象 + * @create 2024-05-06 17:04 + */ +@Getter +@AllArgsConstructor +public enum LogicCheckEnum { + + SUCCESS("0000", "校验通过"), + REFUSE("0001","校验拒绝"), + ; + + private final String code; + private final String info; + +} diff --git a/src/main/java/com/ruoyi/system/ai/enums/RoleEnum.java b/src/main/java/com/ruoyi/system/ai/enums/RoleEnum.java new file mode 100644 index 0000000..d8ed2d5 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/enums/RoleEnum.java @@ -0,0 +1,8 @@ +package com.ruoyi.system.ai.enums; + + +public enum RoleEnum { + system, + user, + assistant; +} \ No newline at end of file diff --git a/src/main/java/com/ruoyi/system/ai/factory/DefaultLogicFactory.java b/src/main/java/com/ruoyi/system/ai/factory/DefaultLogicFactory.java new file mode 100644 index 0000000..cf8d566 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/factory/DefaultLogicFactory.java @@ -0,0 +1,35 @@ +package com.ruoyi.system.ai.factory;//package com.muta.ai.factory; +// +// +//import com.muta.ai.annotation.LogicStrategy; +//import com.muta.ai.config.LogicConfig; +//import com.muta.ai.chain.UserAccountQuotaEntity; +//import com.muta.ai.service.ILogicFilter; +//import org.springframework.core.annotation.AnnotationUtils; +//import org.springframework.stereotype.Service; +// +//import javax.annotation.PostConstruct; +//import javax.annotation.Resource; +//import java.util.List; +//import java.util.Map; +//import java.util.concurrent.ConcurrentHashMap; +// +///** +// * @author Fuzhengwei bugstack.cn @小傅哥 +// * @description 规则工厂 +// * @create 2023-09-16 17:42 +// */ +//@Service +//public class DefaultLogicFactory extends LogicConfig { +// +// //后期可加入参数,自动选择过滤器 +// public Map> openLogicFilter() { +// return logicFilterMap; +// } +// +// +// /** +// * 规则逻辑枚举 +// */ +// +//} diff --git a/src/main/java/com/ruoyi/system/ai/mapper/AiKeyMapper.java b/src/main/java/com/ruoyi/system/ai/mapper/AiKeyMapper.java new file mode 100644 index 0000000..7c2a2b7 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/mapper/AiKeyMapper.java @@ -0,0 +1,70 @@ +package com.ruoyi.system.ai.mapper; + +import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.ai.domain.AiKey; +import com.muta.common.annotation.AutoFill; +import com.muta.common.enums.BaseOperatorType; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +/** + * 【请填写功能名称】Mapper接口 + * + * @author mutaai + * @date 2024-05-16 + */ +@Mapper +public interface AiKeyMapper extends BaseMapper { + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + public AiKey selectAiKeyById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @return 【请填写功能名称】集合 + */ + public List selectAiKeyList(); + + /** + * 新增【请填写功能名称】 + * + * @param aiKey 【请填写功能名称】 + * @return 结果 + */ + @AutoFill(BaseOperatorType.INSERT) + public int insertAiKey(AiKey aiKey); + + /** + * 修改【请填写功能名称】 + * + * @param aiKey 【请填写功能名称】 + * @return 结果 + */ + @AutoFill(BaseOperatorType.UPDATE) + public int updateAiKey(AiKey aiKey); + + /** + * 删除【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + public int deleteAiKeyById(Long id); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteAiKeyByIds(Long[] ids); + + @Select("select `key`, host, model_list, type, status, `limit`, create_time, create_by, update_time, update_by, user_id, is_del from ai_key where is_del = 0 and user_id = #{userId}") + List list(Long userId); +} diff --git a/src/main/java/com/ruoyi/system/ai/mapper/ChatConfigMapper.java b/src/main/java/com/ruoyi/system/ai/mapper/ChatConfigMapper.java new file mode 100644 index 0000000..0bd58df --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/mapper/ChatConfigMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.ai.mapper; + +import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.ai.config.ChatConfig; + +/** + * 【请填写功能名称】Mapper接口 + * + * @author mutaai + * @date 2024-05-13 + */ +public interface ChatConfigMapper extends BaseMapper { + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + public ChatConfig selectChatConfigById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @param chatConfig 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectChatConfigList(ChatConfig chatConfig); + + /** + * 新增【请填写功能名称】 + * + * @param chatConfig 【请填写功能名称】 + * @return 结果 + */ + public int insertChatConfig(ChatConfig chatConfig); + + /** + * 修改【请填写功能名称】 + * + * @param chatConfig 【请填写功能名称】 + * @return 结果 + */ + public int updateChatConfig(ChatConfig chatConfig); + + /** + * 删除【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + public int deleteChatConfigById(Long id); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteChatConfigByIds(Long[] ids); +} diff --git a/src/main/java/com/ruoyi/system/ai/mapper/MessageFileMapper.java b/src/main/java/com/ruoyi/system/ai/mapper/MessageFileMapper.java new file mode 100644 index 0000000..615fe71 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/mapper/MessageFileMapper.java @@ -0,0 +1,13 @@ +package com.ruoyi.system.ai.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.ai.domain.MessageFile; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author 马兰友 + * @Date: 2024/05/17/15:16 + */ +@Mapper +public interface MessageFileMapper extends BaseMapper { +} diff --git a/src/main/java/com/ruoyi/system/ai/mapper/MessageMapper.java b/src/main/java/com/ruoyi/system/ai/mapper/MessageMapper.java new file mode 100644 index 0000000..23f1ee4 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/mapper/MessageMapper.java @@ -0,0 +1,20 @@ +package com.ruoyi.system.ai.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.ai.domain.MessageEntity; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.system.domain.Message; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /05 /20 / 13:02 + * @Description: + */ +@Mapper +public interface MessageMapper extends BaseMapper { + + List selectByFilter(SysUser sysUser); +} diff --git a/src/main/java/com/ruoyi/system/ai/mapper/MessageSessionMapper.java b/src/main/java/com/ruoyi/system/ai/mapper/MessageSessionMapper.java new file mode 100644 index 0000000..15218d0 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/mapper/MessageSessionMapper.java @@ -0,0 +1,16 @@ +package com.ruoyi.system.ai.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.ai.domain.MessageSession; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author 马兰友 + * @Date: 2024/05/13/16:09 + */ +@Mapper +public interface MessageSessionMapper extends BaseMapper { + + + +} diff --git a/src/main/java/com/ruoyi/system/ai/mq/listener/MessageListener.java b/src/main/java/com/ruoyi/system/ai/mq/listener/MessageListener.java new file mode 100644 index 0000000..5c7d501 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/mq/listener/MessageListener.java @@ -0,0 +1,39 @@ +package com.ruoyi.system.ai.mq.listener;//package com.muta.ai.mq.listener; +// +//import cn.hutool.json.JSONUtil; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.muta.ai.domain.MessageEntity; +//import com.muta.ai.domain.event.MessageEvent; +//import com.muta.ai.service.IMessageService; +//import com.muta.ai.service.impl.BaseChatService; +//import com.rabbitmq.client.Channel; +//import org.springframework.amqp.core.Message; +//import org.springframework.amqp.rabbit.annotation.RabbitHandler; +//import org.springframework.amqp.rabbit.annotation.RabbitListener; +//import org.springframework.amqp.rabbit.core.RabbitTemplate; +//import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +//import org.springframework.amqp.support.converter.MessageConverter; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.context.annotation.Bean; +//import org.springframework.stereotype.Component; +// +//import javax.annotation.Resource; +// +///** +// * @author: Larry +// * @Date: 2024 /05 /15 / 17:44 +// * @Description: +// */ +//@Component +// +//public class MessageListener { +// @Resource +// private BaseChatService baseChatService; +// @RabbitHandler +// @RabbitListener(queues = "message.queue") +// public void listenMessage(String message, Channel channel){ +// MessageEntity messageEntity = JSONUtil.toBean(message, MessageEntity.class); +// System.out.println(messageEntity.getContent()); +// } +// +//} diff --git a/src/main/java/com/ruoyi/system/ai/mq/producer/MessageSender.java b/src/main/java/com/ruoyi/system/ai/mq/producer/MessageSender.java new file mode 100644 index 0000000..d680deb --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/mq/producer/MessageSender.java @@ -0,0 +1,49 @@ +package com.ruoyi.system.ai.mq.producer; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.muta.ai.domain.MessageEntity; +import com.muta.ai.domain.event.MessageEvent; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +import org.springframework.amqp.support.converter.MessageConverter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * @author: Larry + * @Date: 2024 /05 /16 / 20:29 + * @Description: + */ + +@Component +public class MessageSender { + + @Value("${mqconfig.message_event_exchange}") + private String eventExchange; + /** + * 第⼀个队列延迟队列, + */ + + @Value("${mqconfig.message_queue}") + private String MessageQueue; + /** + * 第⼀个队列的路由key + * 进⼊队列的路由key + */ + + @Value("${mqconfig.message_routing_key}") + private String MessageRoutingKey; + + @Resource + private RabbitTemplate rabbitTemplate; + public void addSyncMessage(MessageEntity message){ + rabbitTemplate.convertAndSend(eventExchange,MessageRoutingKey,message); + } + + +} diff --git a/src/main/java/com/ruoyi/system/ai/service/HelloWorld.java b/src/main/java/com/ruoyi/system/ai/service/HelloWorld.java new file mode 100644 index 0000000..fc6b961 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/HelloWorld.java @@ -0,0 +1,563 @@ +package com.ruoyi.system.ai.service;//package com.muta.ai.service; +// +//import com.alibaba.fastjson.JSONObject; +//import com.google.gson.annotations.SerializedName; +//import com.google.gson.Gson; +//import io.reactivex.BackpressureStrategy; +//import io.reactivex.Flowable; +//import netscape.javascript.JSObject; +// +//import java.io.IOException; +//import java.util.List; +//import java.util.Objects; +// +// +// +//enum ChatMessageRole { +// SYSTEM, USER, ASSISTANT; +// +// public String value() { +// return this.name().toLowerCase(); +// } +//} +// +//class ChatCompletionMessage { +// public String role; +// public String name; +// public String content; +// public Boolean partial; +// +// public ChatCompletionMessage(String role, String content) { +// this.role = role; +// this.content = content; +// } +// +// public ChatCompletionMessage(String role, String name, String content, Boolean partial) { +// this.role = role; +// this.name = name; +// this.content = content; +// this.partial = partial; +// } +// +// public String getName() { +// return name; +// } +// +// public String getContent() { +// return content; +// } +// +// public Boolean getPartial() { +// return partial; +// } +//} +// +//class ChatCompletionStreamChoiceDelta { +// private String content; +// private String role; +// +// public String getContent() { +// return content; +// } +// +// public String getRole() { +// return role; +// } +// +// public void setContent(String content) { +// this.content = content; +// } +// +// public void setRole(String role) { +// this.role = role; +// } +// +// public ChatCompletionStreamChoiceDelta(String content, String role) { +// this.content = content; +// this.role = role; +// } +//} +// +//class Usage { +// private int promptTokens; +// private int completionTokens; +// private int totalTokens; +// +// public int getPromptTokens() { +// return promptTokens; +// } +// +// public int getCompletionTokens() { +// return completionTokens; +// } +// +// public int getTotalTokens() { +// return totalTokens; +// } +//} +// +//class ChatCompletionStreamChoice { +// private int index; +// private ChatCompletionStreamChoiceDelta delta; +// +// @SerializedName("finish_reason") +// private String finishReason; +// private Usage usage; +// +// public int getIndex() { +// return index; +// } +// +// public ChatCompletionStreamChoiceDelta getDelta() { +// return delta; +// } +// +// public String getFinishReason() { +// return finishReason; +// } +// +// public Usage getUsage() { +// return usage; +// } +// +// public void setIndex(int index) { +// this.index = index; +// } +// +// public void setDelta(ChatCompletionStreamChoiceDelta delta) { +// this.delta = delta; +// } +// +// public void setFinishReason(String finishReason) { +// this.finishReason = finishReason; +// } +// +// public void setUsage(Usage usage) { +// this.usage = usage; +// } +// +// public ChatCompletionStreamChoice(int index, ChatCompletionStreamChoiceDelta delta, String finishReason, Usage usage) { +// this.index = index; +// this.delta = delta; +// this.finishReason = finishReason; +// this.usage = usage; +// } +//} +// +//class ChatCompletionStreamResponse { +// private String id; +// private String object; +// private long created; +// private String model; +// private List choices; +// +// public String getId() { +// return id; +// } +// +// public String getObject() { +// return object; +// } +// +// public long getCreated() { +// return created; +// } +// +// public String getModel() { +// return model; +// } +// +// public List getChoices() { +// return choices; +// } +// +// public void setId(String id) { +// this.id = id; +// } +// +// public void setObject(String object) { +// this.object = object; +// } +// +// public void setCreated(long created) { +// this.created = created; +// } +//} +// +//class ChatCompletionChoice { +// private int index; +// private ChatCompletionMessage message; +// +// @SerializedName("finish_reason") +// private String finishReason; +// +// public int getIndex() { +// return index; +// } +// +// public ChatCompletionMessage getMessage() { +// return message; +// } +// +// public String getFinishReason() { +// return finishReason; +// } +// +// public void setIndex(int index) { +// this.index = index; +// } +// +// public void setMessage(ChatCompletionMessage message) { +// this.message = message; +// } +// +// public void setFinishReason(String finishReason) { +// this.finishReason = finishReason; +// } +// +//} +// +//class ChatCompletionResponse { +// private String id; +// private String object; +// private long created; +// private String model; +// private List choices; +// private Usage usage; +// +// public String getId() { +// return id; +// } +// +// public String getObject() { +// return object; +// } +// +// public long getCreated() { +// return created; +// } +// +// public String getModel() { +// return model; +// } +// +// public List getChoices() { +// if (choices == null) { +// return List.of(); +// } +// return choices; +// } +//} +// +// +//class ChatCompletionRequest { +// public String model; +// public List messages; +// +// @SerializedName("max_tokens") +// public int maxTokens; +// +// @SerializedName("temperature") +// public float temperature; +// public float topP; +// +// public Integer n; +// public boolean stream; +// public List stop; +// +// @SerializedName("presence_penalty") +// public float presencePenalty; +// +// @SerializedName("frequency_penalty") +// public float frequencyPenalty; +// +// public String user; +// +// public List getMessages() { +// return messages; +// } +// +// public ChatCompletionRequest(String model, List messages, int maxTokens, float temperature, int n) { +// this.model = model; +// this.messages = messages; +// this.maxTokens = maxTokens; +// this.temperature = temperature; +// this.n = n; +// } +// +//} +// +//class Model { +// private String id; +// private String object; +// +// @SerializedName("owner_by") +// private String ownedBy; +// private String root; +// private String parent; +// +// public String getId() { +// return id; +// } +// +// public String getObject() { +// return object; +// } +// +// public String getOwnedBy() { +// return ownedBy; +// } +// +// public String getRoot() { +// return root; +// } +// +// public String getParent() { +// return parent; +// } +// +// public void setId(String id) { +// this.id = id; +// } +// +// public void setObject(String object) { +// this.object = object; +// } +// +// public void setOwnedBy(String ownedBy) { +// this.ownedBy = ownedBy; +// } +// +// public void setRoot(String root) { +// this.root = root; +// } +// +// public void setParent(String parent) { +// this.parent = parent; +// } +// +// public Model(String id, String object, String ownedBy, String root, String parent) { +// this.id = id; +// this.object = object; +// this.ownedBy = ownedBy; +// this.root = root; +// this.parent = parent; +// } +//} +// +//class ModelsList { +// private List data; +// +// public List getData() { +// return data; +// } +// +// public void setData(List data) { +// this.data = data; +// } +// +// public ModelsList(List data) { +// this.data = data; +// } +//} +// +//class Client { +// private static final String DEFAULT_BASE_URL = "https://api.moonshot.cn/v1"; +// +// private static final String CHAT_COMPLETION_SUFFIX = "/chat/completions"; +// private static final String MODELS_SUFFIX = "/models"; +// private static final String FILES_SUFFIX = "/files"; +// +// private String baseUrl; +// private String apiKey; +// +// public Client(String apiKey) { +// this(apiKey, DEFAULT_BASE_URL); +// } +// +// public Client(String apiKey, String baseUrl) { +// this.apiKey = apiKey; +// if (baseUrl.endsWith("/")) { +// baseUrl = baseUrl.substring(0, baseUrl.length() - 1); +// } +// this.baseUrl = baseUrl; +// } +// +// public String getChatCompletionUrl() { +// return baseUrl + CHAT_COMPLETION_SUFFIX; +// } +// +// public String getModelsUrl() { +// return baseUrl + MODELS_SUFFIX; +// } +// +// public String getFilesUrl() { +// return baseUrl + FILES_SUFFIX; +// } +// +// public String getApiKey() { +// return apiKey; +// } +// +// public ModelsList ListModels() throws IOException { +// okhttp3.OkHttpClient client = new okhttp3.OkHttpClient(); +// okhttp3.Request request = new okhttp3.Request.Builder() +// .url(getModelsUrl()) +// .addHeader("Authorization", "Bearer " + getApiKey()) +// .build(); +// try { +// okhttp3.Response response = client.newCall(request).execute(); +// String body = response.body().string(); +// Gson gson = new Gson(); +// return gson.fromJson(body, ModelsList.class); +// } catch (java.io.IOException e) { +// e.printStackTrace(); +// throw e; +// } +// } +// +// +// public ChatCompletionResponse ChatCompletion(ChatCompletionRequest request) throws IOException { +// request.stream = false; +// okhttp3.OkHttpClient client = new okhttp3.OkHttpClient(); +// okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json"); +// okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, new Gson().toJson(request)); +// okhttp3.Request httpRequest = new okhttp3.Request.Builder() +// .url(getChatCompletionUrl()) +// .addHeader("Authorization", "Bearer " + getApiKey()) +// .addHeader("Content-Type", "application/json") +// .post(body) +// .build(); +// try { +// okhttp3.Response response = client.newCall(httpRequest).execute(); +// String responseBody = response.body().string(); +// System.out.println(responseBody); +// Gson gson = new Gson(); +// return gson.fromJson(responseBody, ChatCompletionResponse.class); +// } catch (java.io.IOException e) { +// e.printStackTrace(); +// throw e; +// } +// } +// +// // return a stream of ChatCompletionStreamResponse +// public Flowable ChatCompletionStream(ChatCompletionRequest request) throws IOException { +// request.stream = true; +// okhttp3.OkHttpClient client = new okhttp3.OkHttpClient(); +// okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json"); +// okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, new Gson().toJson(request)); +// okhttp3.Request httpRequest = new okhttp3.Request.Builder() +// .url(getChatCompletionUrl()) +// .addHeader("Authorization", "Bearer " + getApiKey()) +// .addHeader("Content-Type", "application/json") +// .post(body) +// .build(); +// okhttp3.Response response = client.newCall(httpRequest).execute(); +// if (response.code() != 200) { +// throw new RuntimeException("Failed to start stream: " + response.body().string()); +// } +// +// // get response body line by line +// return Flowable.create(emitter -> { +// okhttp3.ResponseBody responseBody = response.body(); +// if (responseBody == null) { +// emitter.onError(new RuntimeException("Response body is null")); +// return; +// } +// String line; +// while ((line = responseBody.source().readUtf8Line()) != null) { +// if (line.startsWith("data:")) { +// line = line.substring(5); +// line = line.trim(); +// } +// if (Objects.equals(line, "[DONE]")) { +// emitter.onComplete(); +// return; +// } +// line = line.trim(); +// if (line.isEmpty()) { +// continue; +// } +// Gson gson = new Gson(); +// JSONObject json = gson.fromJson(line, JSONObject.class); +// json.getJSONArray("choices").getJSONObject(0).getJSONObject("finish_reason"); +// ChatCompletionStreamResponse streamResponse = gson.fromJson(line, ChatCompletionStreamResponse.class); +// emitter.onNext(streamResponse); +// } +// emitter.onComplete(); +// }, BackpressureStrategy.BUFFER); +// } +//} +// +//public class rld { +// public static void main(String... args) { +// String apiKey = System.getenv("MOONSHOT_API_KEY"); +// if (apiKey == null) { +// System.out.println("Please set MOONSHOT_API_KEY env"); +// return; +// } +// Client client = new Client(apiKey); +// try { +// ModelsList models = client.ListModels(); +// for (Model model : models.getData()) { +// System.out.println(model.getId()); +// } +// } catch (IOException e) { +// e.printStackTrace(); +// } +// +// final List messages = List.of( +// new ChatCompletionMessage(ChatMessageRole.SYSTEM.value(), +// "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一些涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。"), +// new ChatCompletionMessage(ChatMessageRole.USER.value(), +// "你好,我叫李雷,1+1等于多少?") +// ); +// +//// try { +//// ChatCompletionResponse response = client.ChatCompletion(new ChatCompletionRequest( +//// "moonshot-v1-8k", +//// messages, +//// 50, +//// 0.3f, +//// 1 +//// )); +//// for (ChatCompletionChoice choice : response.getChoices()) { +//// System.out.println(choice.getMessage().getContent()); +//// } +//// } catch (IOException e) { +//// e.printStackTrace(); +//// } +//AtomicR +// try { +// client.ChatCompletionStream(new ChatCompletionRequest( +// "moonshot-v1-8k", +// messages, +// 50, +// 0.3f, +// 1 +// )).subscribe( +// streamResponse -> { +// if (streamResponse.getChoices().isEmpty()) { +// return; +// } +// for (ChatCompletionStreamChoice choice : streamResponse.getChoices()) { +// String finishReason = choice.getFinishReason(); +// if (finishReason != null) { +// System.out.println("finish reason: " + finishReason); +// continue; +// } +// System.out.println(choice.getDelta().getContent()); +// } +// }, +// error -> { +// error.printStackTrace(); +// }, +// () -> { +// System.out.println("complete"); +// } +// ); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +//} \ No newline at end of file diff --git a/src/main/java/com/ruoyi/system/ai/service/IAiKeyService.java b/src/main/java/com/ruoyi/system/ai/service/IAiKeyService.java new file mode 100644 index 0000000..937bc38 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/IAiKeyService.java @@ -0,0 +1,87 @@ +package com.ruoyi.system.ai.service; + +import java.util.List; +import com.muta.ai.domain.AiKey; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * 【请填写功能名称】Service接口 + * + * @author mutaai + * @date 2024-05-16 + */ +public interface IAiKeyService extends IService { + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + public AiKey selectAiKeyById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @return 【请填写功能名称】集合 + */ + public List selectAiKeyList(); + + /** + * 新增【请填写功能名称】 + * + * @param aiKey 【请填写功能名称】 + * @return 结果 + */ + public int insertAiKey(AiKey aiKey); + + /** + * 修改【请填写功能名称】 + * + * @param aiKey 【请填写功能名称】 + * @return 结果 + */ + public int updateAiKey(AiKey aiKey); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】主键集合 + * @return 结果 + */ + public int deleteAiKeyByIds(Long[] ids); + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + public int deleteAiKeyById(Long id); + + /** + * 查询额度 + * + * @param key + * @return + */ + public String getLimitByKey(String key); + + /** + * 判断key是否可用 + * @param key + * @return + */ + public Integer isAvailable(String key); + + /** + * 通过id获得AiKey(String) + * @param + * @return + */ + List getAiKeyStrById(Long userId); + + /** + * 刷新Key额度 + */ + void updateKeyLimit(); +} diff --git a/src/main/java/com/ruoyi/system/ai/service/IChatConfigService.java b/src/main/java/com/ruoyi/system/ai/service/IChatConfigService.java new file mode 100644 index 0000000..9eb7cf1 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/IChatConfigService.java @@ -0,0 +1,49 @@ +package com.ruoyi.system.ai.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.ai.config.ChatConfig; + +import java.util.List; + +/** + * 【请填写功能名称】Service接口 + * + * @author mutaai + * @date 2024-05-13 + */ +public interface IChatConfigService extends IService { + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + public ChatConfig selectChatConfigById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @param chatConfig 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectChatConfigList(ChatConfig chatConfig); + + /** + * 新增【请填写功能名称】 + * + * @param chatConfig 【请填写功能名称】 + * @return 结果 + */ + public int insertChatConfig(ChatConfig chatConfig); + + /** + * 修改【请填写功能名称】 + * + * @param chatConfig 【请填写功能名称】 + * @return 结果 + */ + public int updateChatConfig(ChatConfig chatConfig); + + +} diff --git a/src/main/java/com/ruoyi/system/ai/service/IChatService.java b/src/main/java/com/ruoyi/system/ai/service/IChatService.java new file mode 100644 index 0000000..e718f17 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/IChatService.java @@ -0,0 +1,20 @@ +package com.ruoyi.system.ai.service; + +import com.muta.ai.domain.ChatCompletionMessage; +import com.muta.ai.chain.MusicProcessAggregate; +import com.muta.ai.chain.UserAccountQuotaEntity; + +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /05 /09 / 20:06 + * @Description: + */ +public interface IChatService { + + + + MusicProcessAggregate initChatData(Long userId, String model, List messages); + UserAccountQuotaEntity initUserData(Long userId); +} diff --git a/src/main/java/com/ruoyi/system/ai/service/IChatUploadService.java b/src/main/java/com/ruoyi/system/ai/service/IChatUploadService.java new file mode 100644 index 0000000..9b46fe1 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/IChatUploadService.java @@ -0,0 +1,13 @@ +package com.ruoyi.system.ai.service; + +import org.springframework.web.multipart.MultipartFile; + +/** + * @author: Larry + * @Date: 2024 /05 /15 / 20:59 + * @Description: + */ +public interface IChatUploadService { + String upload(MultipartFile file); + String analyzeFile(String path); +} diff --git a/src/main/java/com/ruoyi/system/ai/service/ILogicFilter.java b/src/main/java/com/ruoyi/system/ai/service/ILogicFilter.java new file mode 100644 index 0000000..86fcc92 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/ILogicFilter.java @@ -0,0 +1,16 @@ +package com.ruoyi.system.ai.service; + + +import com.muta.ai.chain.MusicProcessAggregate; +import com.muta.ai.domain.RuleLogicEntity; + +/** + * @author Fuzhengwei bugstack.cn @小傅哥 + * @description 规则过滤接口 + * @create 2023-09-16 16:59 + */ +public interface ILogicFilter { + + RuleLogicEntity filter(MusicProcessAggregate chatProcess, T data) throws Exception; + +} diff --git a/src/main/java/com/ruoyi/system/ai/service/IMessageFileService.java b/src/main/java/com/ruoyi/system/ai/service/IMessageFileService.java new file mode 100644 index 0000000..e192f58 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/IMessageFileService.java @@ -0,0 +1,16 @@ +package com.ruoyi.system.ai.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.ai.domain.MessageFile; +import org.springframework.web.multipart.MultipartFile; + +/** + * @author 马兰友 + * @Date: 2024/05/17/15:15 + */ +public interface IMessageFileService extends IService { + MessageFile upload(MultipartFile file) throws Exception; + + //根据url获取文件解析信息 + String getContentByUrl(String url); +} diff --git a/src/main/java/com/ruoyi/system/ai/service/IMessageService.java b/src/main/java/com/ruoyi/system/ai/service/IMessageService.java new file mode 100644 index 0000000..c3eb27c --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/IMessageService.java @@ -0,0 +1,19 @@ +package com.ruoyi.system.ai.service; + +import com.muta.ai.domain.MessageEntity; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.system.domain.Message; + +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /05 /20 / 13:01 + * @Description: + */ +public interface IMessageService { + //根据权限返回对应消息列表 + List getList(SysUser sysUser); + + void add(MessageEntity message); +} diff --git a/src/main/java/com/ruoyi/system/ai/service/IMessageSessionService.java b/src/main/java/com/ruoyi/system/ai/service/IMessageSessionService.java new file mode 100644 index 0000000..bc3f456 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/IMessageSessionService.java @@ -0,0 +1,11 @@ +package com.ruoyi.system.ai.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.ai.domain.MessageSession; + +/** + * @author 马兰友 + * @Date: 2024/05/13/16:07 + */ +public interface IMessageSessionService extends IService { +} diff --git a/src/main/java/com/ruoyi/system/ai/service/IModelService.java b/src/main/java/com/ruoyi/system/ai/service/IModelService.java new file mode 100644 index 0000000..286a0bb --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/IModelService.java @@ -0,0 +1,7 @@ +package com.ruoyi.system.ai.service; + +import java.util.List; + +public interface IModelService { + List getModelList(); +} diff --git a/src/main/java/com/ruoyi/system/ai/service/impl/AiKeyServiceImpl.java b/src/main/java/com/ruoyi/system/ai/service/impl/AiKeyServiceImpl.java new file mode 100644 index 0000000..65b4873 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/impl/AiKeyServiceImpl.java @@ -0,0 +1,163 @@ +package com.ruoyi.system.ai.service.impl; + +import com.alibaba.fastjson2.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.ai.mapper.AiKeyMapper; +import com.muta.ai.util.MoonshotAiUtils; +import com.muta.common.utils.SecurityUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import com.muta.ai.domain.AiKey; +import com.muta.ai.service.IAiKeyService; +import org.web3j.crypto.MnemonicUtils; + +import java.math.BigDecimal; +import java.security.Security; +import java.util.List; + +/** + * 【请填写功能名称】Service业务层处理 + * + * @author mutaai + * @date 2024-05-16 + */ +@Service +public class AiKeyServiceImpl extends ServiceImpl implements IAiKeyService { + @Autowired + private AiKeyMapper aiKeyMapper; + + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + @Override + public AiKey selectAiKeyById(Long id) { + return aiKeyMapper.selectAiKeyById(id); + } + + /** + * 查询【请填写功能名称】列表 + * + * @return 【请填写功能名称】 + */ + @Override + public List selectAiKeyList() { + return aiKeyMapper.selectAiKeyList(); + } + + /** + * 新增【请填写功能名称】 + * + * @param aiKey 【请填写功能名称】 + * @return 结果 + */ + @Override + public int insertAiKey(AiKey aiKey) { + String limit = getLimitByKey(aiKey.getKey()); + aiKey.setLimit(new BigDecimal(limit)); + aiKey.setUserId(SecurityUtils.getUserId()); + return aiKeyMapper.insertAiKey(aiKey); + } + + /** + * 修改【请填写功能名称】 + * + * @param aiKey 【请填写功能名称】 + * @return 结果 + */ + @Override + public int updateAiKey(AiKey aiKey) { + return aiKeyMapper.updateAiKey(aiKey); + } + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】主键 + * @return 结果 + */ + @Override + public int deleteAiKeyByIds(Long[] ids) { + return aiKeyMapper.deleteAiKeyByIds(ids); + } + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + @Override + public int deleteAiKeyById(Long id) { + return aiKeyMapper.deleteAiKeyById(id); + } + + /** + * 查询额度 + * + * @param key + * @return + */ + @Override + public String getLimitByKey(String key) { + String balance = MoonshotAiUtils.getBalanceByKey(key); + Object availableBalance = JSON.parseObject(balance) + .getJSONObject("data") + .get("available_balance"); + return availableBalance.toString(); + } + + /** + * 判断key是否可用 + * @param key + * @return + */ + @Override + public Integer isAvailable(String key) { + if (ObjectUtils.isEmpty(key)) return 1; + + // 0可用 1不可用 + String response = MoonshotAiUtils.getBalanceByKey(key); + Object error = JSON.parseObject(response).get("error"); + if (ObjectUtils.isEmpty(error)) { + return 0; + } else { + return 1; + } + } + + /** + * 通过user_id获得AiKey + * @param + * @return + */ + @Override + public List getAiKeyStrById(Long userId) { + System.out.println(userId); + return aiKeyMapper.list(userId); + } + + /** + * 刷新Key额度。 + * 该方法不接受参数,也不返回任何值。 + * 功能描述:获取当前用户ID,查询该用户所有的Key信息,并更新每个Key的额度。 + */ + @Override + public void updateKeyLimit() { + // 获取当前登录用户的ID + Long userId = SecurityUtils.getUserId(); + // 构造查询条件,查询当前用户所有的Key + QueryWrapper wrapper = new QueryWrapper().eq("user_id", userId); + List aiKeyList = aiKeyMapper.selectList(wrapper); + // 遍历查询结果,更新每个Key的额度 + aiKeyList.forEach(key -> { + key.setLimit(new BigDecimal(getLimitByKey(key.getKey()))); + }); + } +} diff --git a/src/main/java/com/ruoyi/system/ai/service/impl/BaseChatService.java b/src/main/java/com/ruoyi/system/ai/service/impl/BaseChatService.java new file mode 100644 index 0000000..71bdcd3 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/impl/BaseChatService.java @@ -0,0 +1,75 @@ +package com.ruoyi.system.ai.service.impl;//package com.muta.ai.service.impl; +// +//import com.muta.ai.chain.MusicProcessAggregate; +//import com.muta.ai.domain.MessageEntity; +//import com.muta.ai.domain.RuleLogicEntity; +//import com.muta.ai.chain.UserAccountQuotaEntity; +//import com.muta.ai.enums.LogicCheckEnum; +//import com.muta.ai.factory.DefaultLogicFactory; +//import com.muta.ai.service.ILogicFilter; +//import com.muta.ai.service.IMessageService; +//import com.muta.common.constant.Constants; +//import com.muta.common.core.domain.entity.UserExtra; +//import com.muta.common.utils.SecurityUtils; +//import com.muta.log.domain.IntegralLog; +//import com.muta.log.service.impl.MessageIntegralLogServiceImpl; +//import com.muta.system.mapper.UserExtraMapper; +//import org.springframework.transaction.annotation.Transactional; +// +//import javax.annotation.Resource; +//import java.util.Map; +// +///** +// * @author: Larry +// * @Date: 2024 /05 /09 / 16:05 +// * @Description: 前置过滤规则处理 +// */ +//public class BaseChatService { +// @Resource +// private DefaultLogicFactory logicFactory; +// //后面可拓展为根据需要传入对应过滤器执行 +// @Resource +// private UserExtraMapper userExtraMapper; +// @Resource +// private IMessageService messageService; +// @Resource +// private MessageIntegralLogServiceImpl messageIntegralLogService; +// //前置过滤 +// protected RuleLogicEntity doCheckLogic(MusicProcessAggregate chatProcess, UserAccountQuotaEntity userAccountQuotaEntity) throws Exception { +// //获得所有的拦截器 +// Map> logicFilterMap = logicFactory.openLogicFilter(); +// //定义返回结果 +// RuleLogicEntity entity = null; +// //遍历所有拦截器,如果拦截则结束并返回,否则放行 +// for (ILogicFilter filter : logicFilterMap.values()) { +// entity = filter.filter(chatProcess,userAccountQuotaEntity); +// if(entity.getType().equals(LogicCheckEnum.REFUSE)){ +// return entity; +// } +// } +// //全部方向后通过 +// return entity != null ? entity : RuleLogicEntity.builder() +// .type(LogicCheckEnum.SUCCESS).data(chatProcess).build(); +// +// } +// //后置过滤 +// @Transactional +// public void PostRule(MusicProcessAggregate chatProcess, UserAccountQuotaEntity userAccountQuotaEntity, MessageEntity message){ +// double result = chatProcess.getTokenNum() / (double) chatProcess.getModelConsumer(); +// Integer consumption = Math.toIntExact(Math.round(result)); +// //扣减积分 +// increaseIntegral(consumption,userAccountQuotaEntity.getUserId()); +// //新增积分记录 +// IntegralLog integralLog = IntegralLog.builder() +// .value(consumption+"积分") +// .build(); +// messageIntegralLogService.insertLog(integralLog); +// //新增消息记录 +//// messageService.add(message); +// } +// private void increaseIntegral(Integer integral,Long userId){ +// userExtraMapper.IncreaseIntegralByUserId(integral,userId); +// } +// +// +//} diff --git a/src/main/java/com/ruoyi/system/ai/service/impl/ChatConfigServiceImpl.java b/src/main/java/com/ruoyi/system/ai/service/impl/ChatConfigServiceImpl.java new file mode 100644 index 0000000..d3d671d --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/impl/ChatConfigServiceImpl.java @@ -0,0 +1,83 @@ +package com.ruoyi.system.ai.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.util.List; + +import com.muta.ai.config.ChatConfig; +import com.muta.ai.mapper.ChatConfigMapper; +import com.muta.ai.service.IChatConfigService; +import com.muta.common.utils.SecurityUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * 【请填写功能名称】Service业务层处理 + * + * @author mutaai + * @date 2024-05-13 + */ +@Service +public class ChatConfigServiceImpl extends ServiceImpl implements IChatConfigService { + @Resource + private ChatConfigMapper chatConfigMapper; + + /** + * 查询【请填写功能名称】 + * + * @param 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + @Override + public ChatConfig selectChatConfigById(Long userId) { + LambdaQueryWrapper chatConfigLambdaQueryWrapper = new LambdaQueryWrapper<>(); + chatConfigLambdaQueryWrapper.eq(userId!=null,ChatConfig::getUserId, userId); + return chatConfigMapper.selectOne(chatConfigLambdaQueryWrapper); + } + + /** + * 查询【请填写功能名称】列表 + * + * @param chatConfig 【请填写功能名称】 + * @return 【请填写功能名称】 + */ + @Override + public List selectChatConfigList(ChatConfig chatConfig) { + return chatConfigMapper.selectChatConfigList(chatConfig); + } + + /** + * 新增【请填写功能名称】 + * + * @param chatConfig 【请填写功能名称】 + * @return 结果 + */ + @Override + public int insertChatConfig(ChatConfig chatConfig) { + return chatConfigMapper.insert(chatConfig); + } + + /** + * 修改【请填写功能名称】 + * + * @param chatConfig 【请填写功能名称】 + * @return 结果 + */ + @Override + public int updateChatConfig(ChatConfig chatConfig) { + System.out.println(chatConfig.getUserId()); + LambdaQueryWrapper chatConfigLambdaQueryWrapper = new LambdaQueryWrapper<>(); + chatConfigLambdaQueryWrapper.eq(SecurityUtils.getUserId()!=null,ChatConfig::getUserId, SecurityUtils.getUserId()); + return chatConfigMapper.update(chatConfig,chatConfigLambdaQueryWrapper); + } + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】主键 + * @return 结果 + */ + +} diff --git a/src/main/java/com/ruoyi/system/ai/service/impl/KimiChatService.java b/src/main/java/com/ruoyi/system/ai/service/impl/KimiChatService.java new file mode 100644 index 0000000..43ee9ba --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/impl/KimiChatService.java @@ -0,0 +1,110 @@ +package com.ruoyi.system.ai.service.impl;//package com.muta.ai.service.impl; +// +//import com.alibaba.fastjson2.JSON; +//import com.alibaba.fastjson2.JSONObject; +//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +//import com.muta.ai.config.ChatConfig; +// +//import com.muta.ai.domain.*; +//import com.muta.ai.domain.dto.MessageHistoryKimi; +//import com.muta.ai.service.IAiKeyService; +//import com.muta.ai.service.IChatConfigService; +//import com.muta.ai.service.IChatService; +//import com.muta.ai.util.MoonshotAiUtils; +//import com.muta.common.core.domain.entity.UserExtra; +//import com.muta.system.mapper.UserExtraMapper; +//import com.muta.system.service.ICommonSettingService; +//import com.muta.system.service.impl.CommonSettingServiceImpl; +//import org.springframework.stereotype.Service; +// +//import javax.annotation.Resource; +//import java.math.BigDecimal; +//import java.util.Comparator; +//import java.util.List; +//import java.util.Optional; +//import java.util.stream.Collectors; +// +///** +// * @author: Larry +// * @Date: 2024 /05 /09 / 18:06 +// * @Description: +// */ +//@SuppressWarnings("all") +//@Service +//public class KimiChatService extends BaseChatService implements IChatService { +// @Resource +// private IAiKeyService aiKeyService; +// @Resource +// private UserExtraMapper userExtraMapper; +// @Resource +// private IChatConfigService chatConfigService; +// @Resource +// private ICommonSettingService commonSettingService; +// +// @Override +// public UserAccountQuotaEntity initUserData(Long userId) { +// LambdaQueryWrapper userExtraLambdaQueryWrapper = new LambdaQueryWrapper<>(); +// userExtraLambdaQueryWrapper.eq(userId!=null,UserExtra::getUserId,userId); +// UserExtra userExtra = userExtraMapper.selectOne(userExtraLambdaQueryWrapper); +// ChatConfig config = chatConfigService.selectChatConfigById(userId); +// return UserAccountQuotaEntity.builder() +// .userId(userId) +// .integral(userExtra.getIntegral()) +// .maxToken(config.getMaxToken()) +// .build(); +// } +// +// @Override +// public MusicProcessAggregate initChatData(Long userId, String model, List messages) { +// String key = LoadBalancingKey(userId); +// Integer tokenNum = getTokenNum(model, messages); +// return MusicProcessAggregate.builder() +// .messages(messages) +// .model(model) +// .userId(userId) +// .key(key) +// .tokenNum(tokenNum) +// .modelConsumer(commonSettingService.getRatioByName(model)) +// .build(); +// } +// +// private Integer getTokenNum(String model, List messages) { +// List messageHistoryKimis = messages.stream().map( +// chatCompletionMessage -> MessageHistoryKimi.builder() +// .role(chatCompletionMessage.getRole()) +// .content(chatCompletionMessage.getContent()) +// .build() +//).collect(Collectors.toList()); +// // 调用工具类方法,估算对话的令牌数量 +// String response = MoonshotAiUtils.estimateTokenCount(model, messageHistoryKimis); +// JSONObject jsonObject = JSON.parseObject(response); +// return jsonObject.getJSONObject("data").getInteger("total_tokens"); +// } +// +// @Override +// public RuleLogicEntity doCheckLogic(MusicProcessAggregate chatProcess, UserAccountQuotaEntity userAccountQuotaEntity) throws Exception { +// return super.doCheckLogic(chatProcess, userAccountQuotaEntity); +// } +// +// @Override +// public void PostRule(MusicProcessAggregate chatProcess, UserAccountQuotaEntity userAccountQuotaEntity, MessageEntity message) { +// super.PostRule(chatProcess, userAccountQuotaEntity, message); +// } +// +// private String LoadBalancingKey(Long userId) { +// //找到该用户的最近代理 +// LambdaQueryWrapper userExtraMapperLambdaQueryWrapper = new LambdaQueryWrapper<>(); +// userExtraMapperLambdaQueryWrapper.eq(userId != null, UserExtra::getUserId, userId); +// UserExtra extraInfo = userExtraMapper.selectOne(userExtraMapperLambdaQueryWrapper); +// List aiKeyList = aiKeyService.getAiKeyStrById(extraInfo.getLowestId()); +// //找到下面额度最大的key,实现负载均衡 +// if (aiKeyList != null && !aiKeyList.isEmpty()) { +// AiKey max = aiKeyList.stream() +// .filter(aiKey -> aiKey.getKey() != null) +// .max(Comparator.comparing(AiKey::getLimit)) +// .orElse(null); +// return max.getKey(); +// } +// return null; +// } +//} \ No newline at end of file diff --git a/src/main/java/com/ruoyi/system/ai/service/impl/MessageFileServiceImpl.java b/src/main/java/com/ruoyi/system/ai/service/impl/MessageFileServiceImpl.java new file mode 100644 index 0000000..abdce51 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/impl/MessageFileServiceImpl.java @@ -0,0 +1,117 @@ +package com.ruoyi.system.ai.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.ai.domain.MessageFile; +import com.muta.ai.mapper.MessageFileMapper; +import com.muta.ai.service.IMessageFileService; +import com.muta.ai.util.DocumentReaderUtils; +import com.muta.common.core.service.ISysFileService; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.stereotype.Service; +import org.springframework.util.FileCopyUtils; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +/** + * @author 马兰友 + * @Date: 2024/05/17/15:15 + */ +@Service +public class MessageFileServiceImpl extends ServiceImpl implements IMessageFileService { + + @Resource + private MessageFileMapper messageFileMapper; + + @Resource + private ISysFileService aliOssServiceImpl; + + @Resource + @Qualifier("asyncPoolTaskExecutor") + ThreadPoolTaskExecutor executor; + + + @Override + public MessageFile upload(MultipartFile file) throws Exception { + MessageFile messageFile = new MessageFile(); + messageFile.setUrl(aliOssServiceImpl.uploadFile(file)); + File tempFile = multipartFile2File(file); + messageFile.setAnalysisContent(DocumentReaderUtils.readDocument(tempFile)); + if (tempFile.exists()) { + tempFile.delete(); + } + messageFile.setName(file.getOriginalFilename()); + messageFile.setSize(formatFileSize(file.getSize())); + messageFileMapper.insert(messageFile); + + return messageFile; + } + + @Override + public String getContentByUrl(String url) { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(MessageFile::getUrl, url); + MessageFile messageFile = messageFileMapper.selectOne(lqw); + return messageFile.getAnalysisContent(); + } + + private CompletableFuture futureUpload(MultipartFile file){ + return CompletableFuture.supplyAsync(() -> { + try { + MessageFile messageFile = new MessageFile(); + messageFile.setUrl(aliOssServiceImpl.uploadFile(file)); + File tempFile = multipartFile2File(file); + messageFile.setAnalysisContent(DocumentReaderUtils.readDocument(tempFile)); + deleteTempFile(tempFile); + messageFile.setName(file.getOriginalFilename()); + messageFile.setSize(formatFileSize(file.getSize())); + messageFileMapper.insert(messageFile); + return messageFile; + } catch (Exception e) { + // 根据需要处理异常,或者重新抛出 + throw new RuntimeException(e); + } + }, executor); // 使用提供的线程池执行上传任务 + } + + private void deleteTempFile(File tempFile) throws IOException { + if (tempFile.exists()) { + boolean delete = tempFile.delete(); + if (!delete) { + throw new IOException("Failed to delete temporary file: " + tempFile.getAbsolutePath()); + } + } + } + + + public File multipartFile2File (MultipartFile multipartFile) throws IOException { + // 获取原始文件名 + String originalFilename = multipartFile.getOriginalFilename(); + // 获取文件扩展名 + String fileExtension = originalFilename.substring(originalFilename.lastIndexOf(".")); + // 创建临时文件 + File file = File.createTempFile("temp-" + UUID.randomUUID(), fileExtension); + System.err.println(file); + // 将MultipartFile对象的内容写入临时文件 + multipartFile.transferTo(file); + return file; + } + public String formatFileSize(long bytes) { + double kilobytes = bytes / 1024.0; + double megabytes = kilobytes / 1024.0; + + if (megabytes >= 1) { + return String.format("%.2f MB", megabytes); + } else { + return String.format("%.2f KB", kilobytes); + } + } +} diff --git a/src/main/java/com/ruoyi/system/ai/service/impl/MessageServiceImpl.java b/src/main/java/com/ruoyi/system/ai/service/impl/MessageServiceImpl.java new file mode 100644 index 0000000..2dfcff2 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/impl/MessageServiceImpl.java @@ -0,0 +1,31 @@ +package com.ruoyi.system.ai.service.impl; + +import com.muta.ai.domain.MessageEntity; +import com.muta.ai.mapper.MessageMapper; +import com.muta.ai.service.IMessageService; +import com.muta.common.core.domain.entity.SysUser; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /05 /20 / 13:01 + * @Description: + */ +@Service +public class MessageServiceImpl implements IMessageService { + @Resource + private MessageMapper messageMapper; + + @Override + public void add(MessageEntity message) { + messageMapper.insert(message); + } + + @Override + public List getList(SysUser sysUser) { + return messageMapper.selectByFilter(sysUser); + } +} diff --git a/src/main/java/com/ruoyi/system/ai/service/impl/MessageSessionServiceImpl.java b/src/main/java/com/ruoyi/system/ai/service/impl/MessageSessionServiceImpl.java new file mode 100644 index 0000000..c84065d --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/impl/MessageSessionServiceImpl.java @@ -0,0 +1,15 @@ +package com.ruoyi.system.ai.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.ai.domain.MessageSession; +import com.muta.ai.mapper.MessageSessionMapper; +import com.muta.ai.service.IMessageSessionService; +import org.springframework.stereotype.Service; + +/** + * @author 马兰友 + * @Date: 2024/05/13/16:07 + */ +@Service +public class MessageSessionServiceImpl extends ServiceImpl implements IMessageSessionService { +} diff --git a/src/main/java/com/ruoyi/system/ai/service/impl/ModelService.java b/src/main/java/com/ruoyi/system/ai/service/impl/ModelService.java new file mode 100644 index 0000000..5e12768 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/impl/ModelService.java @@ -0,0 +1,36 @@ +package com.ruoyi.system.ai.service.impl; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.muta.ai.service.IModelService; +import com.muta.ai.util.MoonshotAiUtils; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class ModelService implements IModelService { + + /** + * 从MoonshotAiUtils工具类中获取模型列表的JSON字符串,解析并返回模型ID的列表 + * @return 模型ID列表 + */ + @Override + public List getModelList() { + List models = new ArrayList<>(); + + // 获取模型列表的JSON字符串 + String modelListJSON = MoonshotAiUtils.getModelList(); + // 解析JSON字符串,获取模型数据数组 + JSONArray data = JSON.parseObject(modelListJSON).getJSONArray("data"); + // 遍历数据数组,提取模型ID并添加到列表中 + data.forEach(item -> { + JSONObject model = (JSONObject) item; + models.add(model.getString("id")); + }); + return models; + } +} + diff --git a/src/main/java/com/ruoyi/system/ai/service/impl/SensitiveWordFilter.java b/src/main/java/com/ruoyi/system/ai/service/impl/SensitiveWordFilter.java new file mode 100644 index 0000000..0ebbec7 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/impl/SensitiveWordFilter.java @@ -0,0 +1,52 @@ +package com.ruoyi.system.ai.service.impl;//package com.muta.ai.service.impl; +// +//import com.github.houbb.sensitive.word.bs.SensitiveWordBs; +//import com.github.houbb.sensitive.word.core.SensitiveWordHelper; +//import com.muta.ai.annotation.LogicStrategy; +//import com.muta.ai.domain.*; +//import com.muta.ai.enums.LogicCheckEnum; +//import com.muta.ai.factory.DefaultLogicFactory; +//import com.muta.ai.service.ILogicFilter; +//import com.muta.common.annotation.Log; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.beans.factory.annotation.Qualifier; +//import org.springframework.stereotype.Component; +// +//import javax.annotation.Resource; +//import java.util.List; +// +///** +// * @author Larry +// * @description 敏感词过滤 +// * @create 2024-05-10 17:39 +// */ +//@Slf4j +//@Component +//@LogicStrategy(logicMode = DefaultLogicFactory.LogicModel.SENSITIVE_WORD) +//public class SensitiveWordFilter implements ILogicFilter { +// @Resource +// @Qualifier("sensitiveWordBsBean") +// SensitiveWordBs sensitiveWordBs; +// @Override +// public RuleLogicEntity filter(MusicProcessAggregate chatProcess, UserAccountQuotaEntity data) throws Exception { +// //只对当前的信息进行敏感词过滤 +// ChatCompletionMessage nowMessage = chatProcess.getMessages().get(chatProcess.getMessages().size() -1); +// System.out.println(); +// //调用外部依赖进行敏感词查找 +// if (sensitiveWordBs.contains(nowMessage.getContent())) { +// //如果有敏感词,返回相关结果 +// return RuleLogicEntity.builder() +// .type(LogicCheckEnum.REFUSE) +// .info("您的对话含有敏感词,请注意!") +// .data(chatProcess).build(); +// } +// +// return RuleLogicEntity.builder() +// .type(LogicCheckEnum.SUCCESS).data(chatProcess).build(); +// } +// +// public static void main(String[] args) { +// +// +// } +//} diff --git a/src/main/java/com/ruoyi/system/ai/service/impl/TokenFilter.java b/src/main/java/com/ruoyi/system/ai/service/impl/TokenFilter.java new file mode 100644 index 0000000..cb66880 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/impl/TokenFilter.java @@ -0,0 +1,62 @@ +package com.ruoyi.system.ai.service.impl;//package com.muta.ai.service.impl; +// +//import com.alibaba.fastjson2.JSON; +//import com.alibaba.fastjson2.JSONObject; +//import com.muta.ai.annotation.LogicStrategy; +//import com.muta.ai.domain.*; +//import com.muta.ai.domain.dto.MessageHistoryKimi; +//import com.muta.ai.enums.LogicCheckEnum; +//import com.muta.ai.factory.DefaultLogicFactory; +//import com.muta.ai.service.ILogicFilter; +//import com.muta.ai.util.MoonshotAiUtils; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.stereotype.Component; +// +//import java.util.ArrayList; +//import java.util.List; +//import java.util.stream.Collectors; +// +///** +// * 该类实现了ILogicFilter接口,用于过滤total_tokens。 +// * 通过评估对话中消息的令牌数量,决定是否继续处理或拒绝该对话。 +// */ +//@Slf4j +//@LogicStrategy(logicMode = DefaultLogicFactory.LogicModel.MAX_TOKEN) +//@Component +//public class TokenFilter implements ILogicFilter { +// +// /** +// * 过滤方法,检查对话的total_tokens数量是否超过限制。 +// * @param chatProcess +// * @param data +// * @return 如果超过限制,返回拒绝信息;否则返回成功。 +// * @throws Exception 如果过程中发生错误,抛出异常。 +// */ +//// List messageHistoryKimis = chatProcess.getMessages().stream().map( +//// chatCompletionMessage -> MessageHistoryKimi.builder() +//// .role(chatCompletionMessage.getRole()) +//// .content(chatCompletionMessage.getContent()) +//// .build() +//// ).collect(Collectors.toList()); +//// // 调用工具类方法,估算对话的令牌数量 +//// String response = MoonshotAiUtils.estimateTokenCount(chatProcess.getModel(), messageHistoryKimis); +//// JSONObject jsonObject = JSON.parseObject(response); +//// Integer total_tokens = jsonObject.getJSONObject("data").getInteger("total_tokens"); +// @Override +// public RuleLogicEntity filter(MusicProcessAggregate chatProcess, UserAccountQuotaEntity data) throws Exception { +// // 检查数量是否超过配置的最大值 +// if (chatProcess.getTokenNum() > data.getMaxToken()) { +// // 如果超过最大值,返回拒绝信息 +// return RuleLogicEntity.builder() +// .type(LogicCheckEnum.REFUSE) +// .info("您的对话所含token数超过限制!") +// .data(chatProcess).build(); +// } +// +// // 如果未超过最大值,返回成功 +// return RuleLogicEntity.builder() +// .type(LogicCheckEnum.SUCCESS) +// .data(chatProcess).build(); +// } +//} +// diff --git a/src/main/java/com/ruoyi/system/ai/service/impl/UserQuotaFilter.java b/src/main/java/com/ruoyi/system/ai/service/impl/UserQuotaFilter.java new file mode 100644 index 0000000..0600280 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/service/impl/UserQuotaFilter.java @@ -0,0 +1,46 @@ +package com.ruoyi.system.ai.service.impl;//package com.muta.ai.service.impl; +//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +//import com.muta.ai.annotation.LogicStrategy; +//import com.muta.ai.chain.MusicProcessAggregate; +//import com.muta.ai.domain.RuleLogicEntity; +//import com.muta.ai.chain.UserAccountQuotaEntity; +//import com.muta.ai.enums.LogicCheckEnum; +//import com.muta.ai.factory.DefaultLogicFactory; +//import com.muta.ai.service.ILogicFilter; +//import com.muta.common.core.domain.entity.UserExtra; +//import com.muta.system.mapper.UserExtraMapper; +//import com.muta.system.service.ICommonSettingService; +//import com.muta.system.service.impl.CommonSettingServiceImpl; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.stereotype.Component; +// +//import javax.annotation.Resource; +// +///** +// * @author Fuzhengwei bugstack.cn @小傅哥 +// * @description 用户额度扣减规则过滤 +// * @create 2023-10-03 16:48 +// */ +//@Slf4j +//@Component +//@LogicStrategy(logicMode = DefaultLogicFactory.LogicModel.USER_QUOTA) +//public class UserQuotaFilter implements ILogicFilter { +// //调用基础业务查询积分 +// @Resource +// private UserExtraMapper userExtraMapper; +// @Override +// public RuleLogicEntity filter(MusicProcessAggregate chatProcess, UserAccountQuotaEntity data) throws Exception { +// +// if(data.getIntegral()builder() +// .info("积分不足,请及时充值") +// .type(LogicCheckEnum.REFUSE) +// .data(chatProcess).build(); +// } +// +// return RuleLogicEntity.builder() +// .type(LogicCheckEnum.SUCCESS).data(chatProcess).build(); +// } +// +// +//} diff --git a/src/main/java/com/ruoyi/system/ai/util/DocumentReaderUtils.java b/src/main/java/com/ruoyi/system/ai/util/DocumentReaderUtils.java new file mode 100644 index 0000000..23c1201 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/util/DocumentReaderUtils.java @@ -0,0 +1,69 @@ +package com.ruoyi.system.ai.util; + +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.text.PDFTextStripper; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.apache.poi.xwpf.usermodel.XWPFParagraph; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.io.IOException; +import java.util.List; + +public class DocumentReaderUtils { + + public static String readDocument(File file) { + + if(file.length()>200 *1024){ + return "文件过大"; + } + String content = ""; + String extension = file.getName().substring(file.getName().lastIndexOf('.') + 1).toLowerCase(); + System.out.println(extension); + try { + switch (extension) { + case "txt": + case "md": + case "csv": + case "markdown": + // 对于文本文件,可以直接读取内容 + List lines = java.nio.file.Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); + content = String.join("\n", lines); + break; + case "docx": + // 对于Word文档,使用Apache POI库 + try (XWPFDocument docxDocument = new XWPFDocument(OPCPackage.open(file))) { + StringBuilder contentBuilder = new StringBuilder(); + for (XWPFParagraph paragraph : docxDocument.getParagraphs()) { + contentBuilder.append(paragraph.getText()).append("\n"); + } + content = contentBuilder.toString(); + } + break; + case "pdf": + // 对于PDF文档,使用PDFBox库 + try (PDDocument pdfDocument = PDDocument.load(file)) { + PDFTextStripper stripper = new PDFTextStripper(); + content = stripper.getText(pdfDocument); + } + break; + // 可以根据需要添加更多文件类型和相应的处理逻辑 + default: + content = "Unsupported file type"; + } + } catch (IOException | InvalidFormatException e) { + content = "Error reading file: " + e.getMessage(); + e.printStackTrace(); + } + + return content; + } + + public static void main(String[] args) { + File file = new File("C:\\Users\\weizh\\Desktop\\packageIO.csv"); // 替换为实际文件路径 + String documentContent = readDocument(file); + System.out.println(documentContent); + } +} \ No newline at end of file diff --git a/src/main/java/com/ruoyi/system/ai/util/MoonshotAiUtils.java b/src/main/java/com/ruoyi/system/ai/util/MoonshotAiUtils.java new file mode 100644 index 0000000..e183e70 --- /dev/null +++ b/src/main/java/com/ruoyi/system/ai/util/MoonshotAiUtils.java @@ -0,0 +1,154 @@ +package com.ruoyi.system.ai.util; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.ContentType; +import cn.hutool.http.Header; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.Method; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.muta.ai.domain.dto.MessageHistoryKimi; +import lombok.NonNull; +import lombok.SneakyThrows; +import okhttp3.*; + +import java.io.BufferedReader; +import java.io.File; +import java.util.List; +import java.util.Optional; + + +public class MoonshotAiUtils { + + private static final String API_KEY = "sk-SgNVCgBxkVPVHjINo708cqiuXPNMNKWdT2JORNkika6FOAht"; + private static final String MODELS_URL = "https://api.moonshot.cn/v1/models"; + private static final String FILES_URL = "https://api.moonshot.cn/v1/files"; + private static final String ESTIMATE_TOKEN_COUNT_URL = "https://api.moonshot.cn/v1/tokenizers/estimate-token-count"; + private static final String CHAT_COMPLETION_URL = "https://api.moonshot.cn/v1/chat/completions"; + + private static final String CHECK_BALANCE ="https://api.moonshot.cn/v1/users/me/balance"; + public static String getModelList() { + return getCommonRequest(MODELS_URL) + .execute() + .body(); + } + public static String getBalance() { + return getCommonRequest(CHECK_BALANCE) + .execute() + .body(); + } + public static String getBalanceByKey(String key) { + return getCommonRequestByKey(CHECK_BALANCE, key) + .execute() + .body(); + } + + public static String uploadFile(@NonNull File file) { + return getCommonRequest(FILES_URL) + .method(Method.POST) + .header("purpose", "file-extract") + .form("file", file) + .execute() + .body(); + } + + public static String getFileList() { + return getCommonRequest(FILES_URL) + .execute() + .body(); + } + + public static String deleteFile(@NonNull String fileId) { + return getCommonRequest(FILES_URL + "/" + fileId) + .method(Method.DELETE) + .execute() + .body(); + } + + public static String getFileDetail(@NonNull String fileId) { + return getCommonRequest(FILES_URL + "/" + fileId) + .execute() + .body(); + } + + public static String getFileContent(@NonNull String fileId) { + return getCommonRequest(FILES_URL + "/" + fileId + "/content") + .execute() + .body(); + } + + public static String estimateTokenCount(@NonNull String model, @NonNull List messages) { + String requestBody = new JSONObject() + .putOpt("model", model) + .putOpt("messages", messages) + .toString(); + return getCommonRequest(ESTIMATE_TOKEN_COUNT_URL) + .method(Method.POST) + .header(Header.CONTENT_TYPE, ContentType.JSON.getValue()) + .body(requestBody) + .execute() + .body(); + } + + @SneakyThrows + public static void chat(@NonNull String model, @NonNull List messages) { + String requestBody = new JSONObject() + .putOpt("model", model) + .putOpt("messages", messages) + .putOpt("stream", true) + .toString(); + + Request okhttpRequest = new Request.Builder() + .url(CHAT_COMPLETION_URL) + .post(RequestBody.create(MediaType.get(ContentType.JSON.getValue()), requestBody)) + .addHeader("Authorization", "Bearer " + API_KEY) + .build(); + Call call = new OkHttpClient().newCall(okhttpRequest); + Response okhttpResponse = call.execute(); + BufferedReader reader = new BufferedReader(okhttpResponse.body().charStream()); + String line; + StringBuffer content = new StringBuffer(); + while ((line = reader.readLine()) != null) { + if (StrUtil.isBlank(line)) { + continue; + } + if (JSONUtil.isTypeJSON(line)) { + Optional.of(JSONUtil.parseObj(line)) + .map(x -> x.getJSONObject("error")) + .map(x -> x.getStr("message")) + .ifPresent(x -> System.out.println("error: " + x)); + return; + } + line = StrUtil.replace(line, "data: ", StrUtil.EMPTY); + if (StrUtil.equals("[DONE]", line) || !JSONUtil.isTypeJSON(line)) { + System.out.println(content); + return; + } + Optional.of(JSONUtil.parseObj(line)) + .map(x -> x.getJSONArray("choices")) + .filter(CollUtil::isNotEmpty) + .map(x -> (JSONObject) x.get(0)) + .map(x -> x.getJSONObject("delta")) + .map(x -> x.getStr("content")) + .ifPresent(x ->{ + System.out.println("rowData: " + x); + content.append(x); + } ); + } + + } + + private static HttpRequest getCommonRequest(@NonNull String url) { + return HttpRequest.of(url).header(Header.AUTHORIZATION, "Bearer " + API_KEY); + } + + private static HttpRequest getCommonRequestByKey(@NonNull String url, @NonNull String key) { + return HttpRequest.of(url).header(Header.AUTHORIZATION, "Bearer " + key); + } + + public static void main(String[] args) { + + } + +} \ No newline at end of file diff --git a/src/main/java/com/ruoyi/system/aipay/AlipaySystemOauthToken.java b/src/main/java/com/ruoyi/system/aipay/AlipaySystemOauthToken.java new file mode 100644 index 0000000..fc7e707 --- /dev/null +++ b/src/main/java/com/ruoyi/system/aipay/AlipaySystemOauthToken.java @@ -0,0 +1,69 @@ +package com.ruoyi.system.aipay; + +import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayClient; +import com.alipay.api.DefaultAlipayClient; +import com.alipay.api.AlipayConfig; +import com.alipay.api.request.AlipayUserInfoShareRequest; +import com.alipay.api.response.AlipaySystemOauthTokenResponse; +import com.alipay.api.request.AlipaySystemOauthTokenRequest; + +import com.alipay.api.FileItem; +import com.alipay.api.response.AlipayUserInfoShareResponse; +import com.muta.pay.config.AliPayConfig; + +import java.util.Base64; +import java.util.ArrayList; +import java.util.List; + +public class AlipaySystemOauthToken { + + public static void main(String[] args) throws AlipayApiException { +// AlipayClient alipayClient1 = AliPayConfig.getInstance(); +// AlipayUserInfoShareRequest request1 = new AlipayUserInfoShareRequest(); +// AlipayUserInfoShareResponse response1 = alipayClient1.execute(request1,accessToken); +// if(response1.isSuccess()){ +// System.out.println("调用成功"); +// } else { +// System.out.println("调用失败"); +// } + // 初始化SDK + AlipayClient alipayClient = new DefaultAlipayClient(getAlipayConfig()); + + // 构造请求参数以调用接口 + AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest(); + +// // 设置刷新令牌 +// request.setRefreshToken("201208134b203fe6c11548bcabd8da5bb087a83b"); +// +// // 设置授权码 +// request.setCode("4b203fe6c11548bcabd8da5bb087a83b"); + + // 设置授权方式 + request.setGrantType("authorization_code"); + + AlipaySystemOauthTokenResponse response = alipayClient.execute(request); + System.out.println(response.getBody()); + + if (response.isSuccess()) { + System.out.println("调用成功"); + } else { + System.out.println("调用失败"); + // sdk版本是"4.38.0.ALL"及以上,可以参考下面的示例获取诊断链接 + // String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(response); + // System.out.println(diagnosisUrl); + } + } + + private static AlipayConfig getAlipayConfig() { + AlipayConfig alipayConfig = new AlipayConfig(); + alipayConfig.setServerUrl(AliPayConfig.PAY_GATEWAY); + alipayConfig.setAppId(AliPayConfig.APPID); + alipayConfig.setPrivateKey(AliPayConfig.APP_PRI_KEY); + alipayConfig.setFormat("json"); + alipayConfig.setAlipayPublicKey(AliPayConfig.APP_PUB_KEY); + alipayConfig.setCharset("UTF-8"); + alipayConfig.setSignType("RSA2"); + return alipayConfig; + } +} \ No newline at end of file diff --git a/src/main/java/com/ruoyi/system/aipay/TestLogin.java b/src/main/java/com/ruoyi/system/aipay/TestLogin.java new file mode 100644 index 0000000..8334edf --- /dev/null +++ b/src/main/java/com/ruoyi/system/aipay/TestLogin.java @@ -0,0 +1,13 @@ +package com.ruoyi.system.aipay; + +/** + * @author: Larry + * @Date: 2024 /08 /01 / 16:15 + * @Description: + */ +public class TestLogin { + + public void test(){ + + } +} diff --git a/src/main/java/com/ruoyi/system/basics/domain/Kamil.java b/src/main/java/com/ruoyi/system/basics/domain/Kamil.java new file mode 100644 index 0000000..eb7ef75 --- /dev/null +++ b/src/main/java/com/ruoyi/system/basics/domain/Kamil.java @@ -0,0 +1,72 @@ +package com.ruoyi.system.basics.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.muta.common.core.MutaBaseEntity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * @author 马兰友 + * @Date: 2024/04/20/16:22 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@AllArgsConstructor +@NoArgsConstructor +public class Kamil extends MutaBaseEntity { + + /** + * id + */ + @TableId(type = IdType.AUTO) + @JsonFormat(shape =JsonFormat.Shape.STRING) + private Long id; + + /** + * 卡密被使用时使用者的ip + */ + private String ip; + + /** + * 使用者的id + */ + @JsonFormat(shape =JsonFormat.Shape.STRING) + private Long userId; + + /** + * 卡密 + */ + @TableField(value = "`key`") + private String key; + + /** + * 值,若type是积分(0),该值为积分数 + * 若type是会员(1),该值为会员天数 + * 若type是svip(2),该值为svip天数 + */ + private Integer value; + + /** + * 状态 0:有效 1:已使用 + */ + private Integer status; + + /** + * 卡密类型 0:积分 1:会员 2:svip + */ + private Integer type; + + /** + * 截止日期 该字段只有自定义的卡密有值 批量生成的没有 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date endTime; + +} diff --git a/src/main/java/com/ruoyi/system/basics/domain/dto/KamilAddDTO.java b/src/main/java/com/ruoyi/system/basics/domain/dto/KamilAddDTO.java new file mode 100644 index 0000000..89da413 --- /dev/null +++ b/src/main/java/com/ruoyi/system/basics/domain/dto/KamilAddDTO.java @@ -0,0 +1,34 @@ +package com.ruoyi.system.basics.domain.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author 马兰友 + * @Date: 2024/04/21/20:24 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class KamilAddDTO { + + /** + * 卡密类型 0:积分 1:普通会员 2:超级会员 + */ + private Integer type; + + /** + * 卡密的值 根据type不同 含义也有所不同 + * type为0 表示积分的数量 type为1或2 表示天数 + */ + private Integer value; + + /** + * 本次生成的卡密数量 + */ + private Integer quantity; + +} diff --git a/src/main/java/com/ruoyi/system/basics/domain/dto/KamilConDefDTO.java b/src/main/java/com/ruoyi/system/basics/domain/dto/KamilConDefDTO.java new file mode 100644 index 0000000..f371105 --- /dev/null +++ b/src/main/java/com/ruoyi/system/basics/domain/dto/KamilConDefDTO.java @@ -0,0 +1,25 @@ +package com.ruoyi.system.basics.domain.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * @author 马兰友 + * @Date: 2024/05/06/16:36 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class KamilConDefDTO { + + private String key; + private Integer value; + private Integer type; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date endTime; + +} diff --git a/src/main/java/com/ruoyi/system/basics/factory/kamil/KamilConsumption.java b/src/main/java/com/ruoyi/system/basics/factory/kamil/KamilConsumption.java new file mode 100644 index 0000000..0c8a9a1 --- /dev/null +++ b/src/main/java/com/ruoyi/system/basics/factory/kamil/KamilConsumption.java @@ -0,0 +1,12 @@ +package com.ruoyi.system.basics.factory.kamil; + +import com.muta.basics.domain.Kamil; + +/** + * @author 马兰友 + * @Date: 2024/04/22/19:45 + */ +public interface KamilConsumption { + + void consumption(Kamil kamil); +} diff --git a/src/main/java/com/ruoyi/system/basics/factory/kamil/KamilTypeFactory.java b/src/main/java/com/ruoyi/system/basics/factory/kamil/KamilTypeFactory.java new file mode 100644 index 0000000..468d032 --- /dev/null +++ b/src/main/java/com/ruoyi/system/basics/factory/kamil/KamilTypeFactory.java @@ -0,0 +1,37 @@ +package com.ruoyi.system.basics.factory.kamil; + +import com.muta.basics.factory.kamil.impl.SvipKamilConsumption; +import com.muta.basics.factory.kamil.impl.VipKamilConsumption; +import com.muta.basics.factory.kamil.impl.IntegrationKamilConsumption; +import com.muta.basics.domain.Kamil; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author 马兰友 + * @Date: 2024/04/22/18:31 + */ +@Service +public class KamilTypeFactory { + public Map kamilConsumptionMap = new ConcurrentHashMap<>(); + @Resource + private IntegrationKamilConsumption integrationKamilConsumption; + @Resource + private VipKamilConsumption vipKamilConsumption; + @Resource + private SvipKamilConsumption svipKamilConsumption; + @PostConstruct + public void init() { + kamilConsumptionMap.put(0, integrationKamilConsumption); + kamilConsumptionMap.put(1, vipKamilConsumption); + kamilConsumptionMap.put(2, svipKamilConsumption); + } + public void consumption(Kamil kamil) { + KamilConsumption kamilConsumption = kamilConsumptionMap.get(kamil.getType()); + kamilConsumption.consumption(kamil); + } +} diff --git a/src/main/java/com/ruoyi/system/basics/factory/kamil/impl/IntegrationKamilConsumption.java b/src/main/java/com/ruoyi/system/basics/factory/kamil/impl/IntegrationKamilConsumption.java new file mode 100644 index 0000000..1bce65d --- /dev/null +++ b/src/main/java/com/ruoyi/system/basics/factory/kamil/impl/IntegrationKamilConsumption.java @@ -0,0 +1,36 @@ +package com.ruoyi.system.basics.factory.kamil.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.muta.basics.factory.kamil.KamilConsumption; +import com.muta.common.annotation.IntegralLogInsert; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.entity.UserExtra; +import com.muta.common.utils.SecurityUtils; +import com.muta.basics.domain.Kamil; +import com.muta.system.mapper.UserExtraMapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * @author 马兰友 + * @Date: 2024/04/22/19:48 + */ +@Service +public class IntegrationKamilConsumption implements KamilConsumption { + + @Resource + private UserExtraMapper userExtraMapper; + + @Override + @IntegralLogInsert(operation = OperationConstants.Kamil) + public void consumption(Kamil kamil) { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(UserExtra::getUserId, SecurityUtils.getUserId()); + UserExtra userExtra = userExtraMapper.selectOne(lqw); + Integer value = kamil.getValue(); + userExtra.setIntegral(userExtra.getIntegral() + value); + userExtraMapper.updateById(userExtra); + } + +} diff --git a/src/main/java/com/ruoyi/system/basics/factory/kamil/impl/SvipKamilConsumption.java b/src/main/java/com/ruoyi/system/basics/factory/kamil/impl/SvipKamilConsumption.java new file mode 100644 index 0000000..d7f9882 --- /dev/null +++ b/src/main/java/com/ruoyi/system/basics/factory/kamil/impl/SvipKamilConsumption.java @@ -0,0 +1,53 @@ +package com.ruoyi.system.basics.factory.kamil.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.muta.basics.factory.kamil.KamilConsumption; +import com.muta.common.annotation.IntegralLogInsert; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.entity.UserExtra; +import com.muta.common.utils.SecurityUtils; +import com.muta.basics.domain.Kamil; +import com.muta.system.domain.Vip; +import com.muta.system.mapper.UserExtraMapper; +import com.muta.system.mapper.VipMapper; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.Calendar; +import java.util.Date; + +/** + * @author 马兰友 + * @Date: 2024/04/22/19:49 + */ +@Component +public class SvipKamilConsumption implements KamilConsumption { + + @Resource + private VipMapper vipMapper; + + @Override + @IntegralLogInsert(operation = OperationConstants.Kamil) + public void consumption(Kamil kamil) { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(Vip::getUserId, SecurityUtils.getUserId()); + Vip vip = vipMapper.selectOne(lqw); + Integer value = kamil.getValue(); + Date now = new Date(); + + Date svipExpireTime = vip.getSvipExpireTime(); + Calendar calendar = Calendar.getInstance(); + //首先判断用户当前是不是svip 若是则在截止日期后加上value天 + if (null != svipExpireTime && svipExpireTime.after(now)) + calendar.setTime(vip.getVipExpireTime()); + + else { + //若不是 则在从今天开始加上value天 作为截止日期 并更新开始时间为今日 + calendar.setTime(now); + vip.setSvipBeginTime(now); + } + calendar.add(Calendar.DAY_OF_YEAR, value); + vip.setSvipExpireTime(calendar.getTime()); + vipMapper.updateById(vip); + } +} diff --git a/src/main/java/com/ruoyi/system/basics/factory/kamil/impl/VipKamilConsumption.java b/src/main/java/com/ruoyi/system/basics/factory/kamil/impl/VipKamilConsumption.java new file mode 100644 index 0000000..68ecba5 --- /dev/null +++ b/src/main/java/com/ruoyi/system/basics/factory/kamil/impl/VipKamilConsumption.java @@ -0,0 +1,53 @@ +package com.ruoyi.system.basics.factory.kamil.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.muta.basics.factory.kamil.KamilConsumption; +import com.muta.common.annotation.IntegralLogInsert; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.entity.UserExtra; +import com.muta.common.utils.SecurityUtils; +import com.muta.basics.domain.Kamil; +import com.muta.system.domain.Vip; +import com.muta.system.mapper.UserExtraMapper; +import com.muta.system.mapper.VipMapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Calendar; +import java.util.Date; + +/** + * @author 马兰友 + * @Date: 2024/04/22/19:49 + */ +@Service +public class VipKamilConsumption implements KamilConsumption { + + @Resource + private UserExtraMapper userExtraMapper; + @Resource + private VipMapper vipMapper; + + @Override + @IntegralLogInsert(operation = OperationConstants.Kamil) + public void consumption(Kamil kamil) { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(Vip::getUserId, SecurityUtils.getUserId()); + Vip vip = vipMapper.selectOne(lqw); + Integer value = kamil.getValue(); + Date now = new Date(); + Date vipExpireTime = vip.getVipExpireTime(); + Calendar expCalendar = Calendar.getInstance(); + //首先判断用户当前是不是svip 若是则在截止日期后加上value天 + if (null != vipExpireTime && vipExpireTime.after(now)) + expCalendar.setTime(vip.getVipExpireTime()); + else { + //若不是 则在从今天开始加上value天 作为截止日期 并更新开始日期为今日 + expCalendar.setTime(now); + vip.setVipBeginTime(now); + } + expCalendar.add(Calendar.DAY_OF_YEAR, value); + vip.setVipExpireTime(expCalendar.getTime()); + vipMapper.updateById(vip); + } +} diff --git a/src/main/java/com/ruoyi/system/basics/mapper/KamilMapper.java b/src/main/java/com/ruoyi/system/basics/mapper/KamilMapper.java new file mode 100644 index 0000000..d2c7b48 --- /dev/null +++ b/src/main/java/com/ruoyi/system/basics/mapper/KamilMapper.java @@ -0,0 +1,64 @@ +package com.ruoyi.system.basics.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.basics.domain.Kamil; + +import java.util.List; + +/** + * 【请填写功能名称】Mapper接口 + * + * @author mutaai + * @date 2024-04-21 + */ +public interface KamilMapper extends BaseMapper { + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + public Kamil selectKamilById(String id); + + /** + * 查询【请填写功能名称】列表 + * + * @param kamil 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectKamilList(Kamil kamil); + + /** + * 新增【请填写功能名称】 + * + * @param kamil 【请填写功能名称】 + * @return 结果 + */ + public int insertKamil(Kamil kamil); + + /** + * 修改【请填写功能名称】 + * + * @param kamil 【请填写功能名称】 + * @return 结果 + */ + public int updateKamil(Kamil kamil); + + /** + * 删除【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + public int deleteKamilById(String id); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteKamilByIds(String[] ids); + +} diff --git a/src/main/java/com/ruoyi/system/basics/service/IKamilService.java b/src/main/java/com/ruoyi/system/basics/service/IKamilService.java new file mode 100644 index 0000000..527ee02 --- /dev/null +++ b/src/main/java/com/ruoyi/system/basics/service/IKamilService.java @@ -0,0 +1,72 @@ +package com.ruoyi.system.basics.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.common.core.domain.AjaxResult; +import com.muta.basics.domain.Kamil; +import com.muta.basics.domain.dto.KamilAddDTO; +import com.muta.basics.domain.dto.KamilConDefDTO; + +import java.util.List; + +/** + * 【请填写功能名称】Service接口 + * + * @author mutaai + * @date 2024-04-21 + */ +public interface IKamilService extends IService { + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + public Kamil selectKamilById(String id); + + /** + * 查询【请填写功能名称】列表 + * + * @param kamil 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectKamilList(Kamil kamil); + + /** + * 新增【请填写功能名称】 + * + * @param kamil 【请填写功能名称】 + * @return 结果 + */ + public int insertKamil(Kamil kamil); + + /** + * 修改【请填写功能名称】 + * + * @param kamil 【请填写功能名称】 + * @return 结果 + */ + public int updateKamil(Kamil kamil); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】主键集合 + * @return 结果 + */ + public int deleteKamilByIds(String[] ids); + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + public int deleteKamilById(String id); + + void addBatch(KamilAddDTO kamilAddDTO); + + AjaxResult use(String key); + + AjaxResult conDef(KamilConDefDTO kamilConDefDTO); +} diff --git a/src/main/java/com/ruoyi/system/basics/service/impl/KamilServiceImpl.java b/src/main/java/com/ruoyi/system/basics/service/impl/KamilServiceImpl.java new file mode 100644 index 0000000..ab168db --- /dev/null +++ b/src/main/java/com/ruoyi/system/basics/service/impl/KamilServiceImpl.java @@ -0,0 +1,190 @@ +package com.ruoyi.system.basics.service.impl; + + +import cn.hutool.core.util.ObjUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.crypto.digest.MD5; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.common.annotation.RepeatSubmit; +import com.muta.common.core.domain.AjaxResult; +import com.muta.common.utils.DateUtils; +import com.muta.common.utils.SecurityUtils; +import com.muta.basics.domain.dto.KamilConDefDTO; +import com.muta.basics.factory.kamil.KamilTypeFactory; +import com.muta.basics.domain.Kamil; +import com.muta.basics.domain.dto.KamilAddDTO; +import com.muta.basics.mapper.KamilMapper; +import com.muta.basics.service.IKamilService; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +import static com.muta.common.constant.CacheConstants.KAMIL_KEY; + + +/** + * 【请填写功能名称】Service业务层处理 + * + * @author mutaai + * @date 2024-04-21 + */ +@Service +public class KamilServiceImpl extends ServiceImpl implements IKamilService { + @Resource + private KamilMapper kamilMapper; + + @Resource + private KamilTypeFactory kamilTypeFactory; + + @Resource + private StringRedisTemplate stringRedisTemplate; + + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + @Override + public Kamil selectKamilById(String id) { + return kamilMapper.selectKamilById(id); + } + + /** + * 查询【请填写功能名称】列表 + * + * @param kamil 【请填写功能名称】 + * @return 【请填写功能名称】 + */ + @Override + public List selectKamilList(Kamil kamil) { + return kamilMapper.selectList(new LambdaQueryWrapper<>()); + } + + /** + * 新增【请填写功能名称】 + * + * @param kamil 【请填写功能名称】 + * @return 结果 + */ + @Override + public int insertKamil(Kamil kamil) { + kamil.setCreateTime(DateUtils.getNowDate()); + return kamilMapper.insertKamil(kamil); + } + + /** + * 修改【请填写功能名称】 + * + * @param kamil 【请填写功能名称】 + * @return 结果 + */ + @Override + public int updateKamil(Kamil kamil) { + kamil.setUpdateTime(DateUtils.getNowDate()); + return kamilMapper.updateKamil(kamil); + } + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】主键 + * @return 结果 + */ + @Override + public int deleteKamilByIds(String[] ids) { + return kamilMapper.deleteKamilByIds(ids); + } + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + @Override + public int deleteKamilById(String id) { + return kamilMapper.deleteKamilById(id); + } + + @Override + @Transactional + public void addBatch(KamilAddDTO kamilAddDTO) { + int n = kamilAddDTO.getQuantity(); + Kamil kamil = new Kamil(); + kamil.setType(kamilAddDTO.getType()); + kamil.setValue(kamilAddDTO.getValue()); + //生成n个卡密 + for (int i = 0; i < n; i++) { + //卡密的key为对当前时间戳进行md5加密获得的32位字符串 + kamil.setKey(MD5.create().digestHex(String.valueOf(System.currentTimeMillis()))); + kamilMapper.insert(kamil); + } + } + + @Override + @RepeatSubmit + public AjaxResult use(String key) { + Long userId = SecurityUtils.getUserId(); + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(Kamil::getKey, key); + //根据用户输入的key查找卡密 对其存在与否以及状态进行判断 + Kamil kamil = kamilMapper.selectOne(lqw); + System.out.println(kamil); + if (ObjUtil.isEmpty(kamil)) + return AjaxResult.error("卡密不存在"); + if (kamil.getEndTime() == null) { + if (kamil.getStatus() == 1) + return AjaxResult.error("卡密已被使用"); + //校验通过 修改数据库卡密状态 + kamil.setStatus(1); + kamil.setUserId(userId); + kamilMapper.updateById(kamil); + } else { + //是存在截止时间的自定义卡密 + if (kamil.getEndTime().before(new Date())) { + //判断是否已过期 + if (kamil.getStatus() == 0) { + //过期 且status为0 则将其status设置为1 并将该key从redis中删除 + kamil.setStatus(1); + stringRedisTemplate.delete(KAMIL_KEY + key); + kamilMapper.updateById(kamil); + } + return AjaxResult.error("卡密已过期"); + } + //该卡密未过期 判断该用户是否使用过 也就是判断以该卡密的key为 key的set列表中有没有该用户的userId 若有 则使用过 + if (Boolean.TRUE.equals(stringRedisTemplate.opsForSet().isMember(KAMIL_KEY + key, userId.toString()))) { + return AjaxResult.error("您已使用过该卡密"); + } else { + //没使用过该卡密 将用户id添加到set列表中 + stringRedisTemplate.opsForSet().add(KAMIL_KEY + key, userId.toString()); + } + } + //调用工厂 消耗卡密 为用户增加相应的值 + kamilTypeFactory.consumption(kamil); + return AjaxResult.success(); + } + + @Override + public AjaxResult conDef(KamilConDefDTO kamilConDefDTO) { + Kamil kamil = new Kamil(); + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(Kamil::getKey, kamilConDefDTO.getKey()); //构建查询条件 查询卡密的key是否被占用 + if (ObjectUtil.isNotEmpty(kamilMapper.selectList(lqw))) { + return AjaxResult.error("卡密已存在"); //卡密已存在 返回错误信息 生成失败 + }; + //校验成功 将dto中的值拷贝到kamil对象中 + kamil.setKey(kamilConDefDTO.getKey()); + kamil.setValue(kamilConDefDTO.getValue()); + kamil.setType(kamilConDefDTO.getType()); + kamil.setEndTime(kamilConDefDTO.getEndTime()); + //新增 + kamilMapper.insert(kamil); + return AjaxResult.success(); + } +} diff --git a/src/main/java/com/ruoyi/system/distribution/algorrirhm/DistributionDataFilter.java b/src/main/java/com/ruoyi/system/distribution/algorrirhm/DistributionDataFilter.java new file mode 100644 index 0000000..6e06d39 --- /dev/null +++ b/src/main/java/com/ruoyi/system/distribution/algorrirhm/DistributionDataFilter.java @@ -0,0 +1,50 @@ +package com.ruoyi.system.distribution.algorrirhm; + +import com.muta.common.utils.SecurityUtils; +import com.muta.distribution.mapper.DistributionDataMapper; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.lang.reflect.Field; +import java.security.Security; +import java.util.ArrayList; +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /04 /27 / 14:42 + * @Description: + */ +@Component +public class DistributionDataFilter { + @Resource + private DistributionDataMapper distributionDataConfig; + //因为每个log的存username的字段都不一样,所以要传入相应的字段名,再根据反射获取username + public List dataFilter(List data,String filterName){ + if(SecurityUtils.hasRole("admin")){ + return data; + } + //过滤出所有符合条件的username + List usernameList = distributionDataConfig.usernameList(SecurityUtils.getUserId()); + System.out.println(usernameList); + List res = new ArrayList<>(); + try { + System.out.println(data.size()); + for (T item : data) { + Field field = item.getClass().getDeclaredField(filterName); + field.setAccessible(true); // 设置字段可访问 + Object username = field.get(item); // 获取username + System.out.println(username); + //如果数据符合要求,存入集合 + if(usernameList.contains(username.toString())){ + res.add(item); + } + } + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + System.out.println(res.size()); + return res; + } + +} diff --git a/src/main/java/com/ruoyi/system/distribution/domain/FundsLog.java b/src/main/java/com/ruoyi/system/distribution/domain/FundsLog.java new file mode 100644 index 0000000..b59626f --- /dev/null +++ b/src/main/java/com/ruoyi/system/distribution/domain/FundsLog.java @@ -0,0 +1,27 @@ +package com.ruoyi.system.distribution.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class FundsLog { + + private Long id; + private String consumer; + private String beneficiaries; + private BigDecimal consume; + private BigDecimal earnings; + private Integer persent; + private Long userId; + @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss") + private LocalDateTime createTime; +} diff --git a/src/main/java/com/ruoyi/system/distribution/mapper/DistributionDataMapper.java b/src/main/java/com/ruoyi/system/distribution/mapper/DistributionDataMapper.java new file mode 100644 index 0000000..08fac15 --- /dev/null +++ b/src/main/java/com/ruoyi/system/distribution/mapper/DistributionDataMapper.java @@ -0,0 +1,17 @@ +package com.ruoyi.system.distribution.mapper; + +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /04 /27 / 15:34 + * @Description: + */ +@Mapper +public interface DistributionDataMapper { + public List usernameList(Long id); + + +} diff --git a/src/main/java/com/ruoyi/system/distribution/mapper/FundsLogMapper.java b/src/main/java/com/ruoyi/system/distribution/mapper/FundsLogMapper.java new file mode 100644 index 0000000..d052892 --- /dev/null +++ b/src/main/java/com/ruoyi/system/distribution/mapper/FundsLogMapper.java @@ -0,0 +1,15 @@ +package com.ruoyi.system.distribution.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.distribution.domain.FundsLog; +import com.muta.system.domain.SigninLog; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface FundsLogMapper extends BaseMapper { + + List logList(SysUser sysUser); +} diff --git a/src/main/java/com/ruoyi/system/distribution/service/DistributionService.java b/src/main/java/com/ruoyi/system/distribution/service/DistributionService.java new file mode 100644 index 0000000..8892310 --- /dev/null +++ b/src/main/java/com/ruoyi/system/distribution/service/DistributionService.java @@ -0,0 +1,8 @@ +package com.ruoyi.system.distribution.service; + +import com.baomidou.mybatisplus.extension.service.IService; + +public interface DistributionService { + + void benefit(Double basic); +} diff --git a/src/main/java/com/ruoyi/system/distribution/service/impl/DistributionService.java b/src/main/java/com/ruoyi/system/distribution/service/impl/DistributionService.java new file mode 100644 index 0000000..0cd2818 --- /dev/null +++ b/src/main/java/com/ruoyi/system/distribution/service/impl/DistributionService.java @@ -0,0 +1,60 @@ +package com.ruoyi.system.distribution.service.impl; + +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.core.domain.entity.UserExtra; +import com.muta.common.utils.SecurityUtils; +import com.muta.distribution.domain.FundsLog; +import com.muta.distribution.mapper.FundsLogMapper; +import com.muta.system.service.ISysUserService; +import com.muta.system.service.IUserExtraService; + +import javax.annotation.Resource; +import java.math.BigDecimal; + +/** + * @author: Larry + * @Date: 2024 /08 /12 / 1:23 + * @Description: + */ +public class DistributionService { + @Resource + private IUserExtraService userExtraService; + @Resource + private FundsLogMapper fundsLogMapper; + @Resource + private ISysUserService sysUserService; + + public void distribute(BigDecimal money){ + Long userId = SecurityUtils.getUserId(); + SysUser sysUser = sysUserService.selectUserById(userId); + SysUser father = sysUserService.selectUserById(sysUser.getUserExtra().getLowestId()); + //如果最近代理直接是管理员 + if(SecurityUtils.isAdmin(sysUser.getUserExtra().getLowestId())){ + FundsLog fundsLog = new FundsLog(); + fundsLog.setConsume(money); + fundsLog.setPersent(100); + fundsLog.setBeneficiaries(SecurityUtils.getUsername()); + fundsLogMapper.insert(fundsLog); + } + //如果是一级代理 + else if(father.getRoleId() == 1){ + //一级 + FundsLog fundsLog = new FundsLog(); + fundsLog.setConsume(money.divide(BigDecimal.valueOf(father.getUserExtra().getPercentage()))); + fundsLog.setPersent(father.getUserExtra().getPercentage()); + fundsLog.setBeneficiaries(SecurityUtils.getUsername()); + fundsLogMapper.insert(fundsLog); + //超管 + FundsLog fundsLog1 = new FundsLog(); + fundsLog.setConsume(money.subtract(money.divide(BigDecimal.valueOf(father.getUserExtra().getPercentage())))); + fundsLog.setPersent(100); + fundsLog.setBeneficiaries(SecurityUtils.getUsername()); + fundsLogMapper.insert(fundsLog); + } + else { + + } + } + + +} diff --git a/src/main/java/com/ruoyi/system/distribution/service/impl/DistributionServiceImpl.java b/src/main/java/com/ruoyi/system/distribution/service/impl/DistributionServiceImpl.java new file mode 100644 index 0000000..4f4aabc --- /dev/null +++ b/src/main/java/com/ruoyi/system/distribution/service/impl/DistributionServiceImpl.java @@ -0,0 +1,225 @@ +package com.ruoyi.system.distribution.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.muta.common.core.domain.entity.UserExtra; +import com.muta.common.utils.SecurityUtils; +import com.muta.distribution.domain.FundsLog; +import com.muta.distribution.mapper.FundsLogMapper; +import com.muta.distribution.service.DistributionService; +import com.muta.log.service.impl.DistributionIntegralServiceImpl; +import com.muta.system.mapper.UserExtraMapper; +import com.muta.system.service.ISysUserService; +import com.muta.system.service.IUserExtraService; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.Objects; + +@Service +public class DistributionServiceImpl implements DistributionService { + + @Resource + private IUserExtraService userExtraService; + + @Resource + private ISysUserService sysUserService; + + @Resource + private FundsLogMapper fundsLogMapper; + + @Resource + private UserExtraMapper userExtraMapper; + + @Resource + private DistributionIntegralServiceImpl distributionIntegralService; + + + /*@Override + public void efit(Double basic) { + Long userId = SecurityUtils.getUserId(); + Long pid = 0L, lid = 0L, fid = 0L; + double persent; + double template = basic; + + do { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(UserExtra::getUserId, userId); + UserExtra tree = userExtraService.getOne(lqw); + + pid = tree.getSuperiorId(); + lid = tree.getLowestId(); + fid = tree.getFirstId(); + + userId = check(pid, lid, fid) ? doCash(tree, basic) : doIntegral(pid, template); + LambdaQueryWrapper fatherLqw = new LambdaQueryWrapper<>(); + fatherLqw.eq(UserExtra::getUserId, pid); + UserExtra father = userExtraService.getOne(fatherLqw); + + persent = father.getPercentage(); + template *= persent; + } while (check(pid, lid, fid)); + } + + public Long doIntegral(Long pid, double template) { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(UserExtra::getUserId, pid); + UserExtra one = userExtraService.getOne(lqw); + + LambdaQueryWrapper fatherLqw = new LambdaQueryWrapper<>(); + fatherLqw.eq(UserExtra::getUserId, one.getSuperiorId()); + UserExtra father = userExtraService.getOne(fatherLqw); + + one.setIntegral((int) (one.getIntegral() + template)); + if (!check(one.getSuperiorId(), one.getLowestId(), one.getFirstId())) + one.setIntegral((int) (one.getIntegral() - template * father.getPercentage())); + + // TODO 积分记录 + userExtraMapper.update(one, lqw); + + return pid; + }*/ + + public Long doCash(UserExtra tree, double baisc) { + double persent = 1; + + while (!Objects.equals(tree.getSuperiorId(), tree.getLowestId())) { + System.out.println("find"); + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(UserExtra::getUserId, tree.getSuperiorId()); + tree = userExtraMapper.selectOne(lqw); + } + + do { + System.err.println("cash"); + UserExtra last = tree; + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(UserExtra::getUserId, tree.getSuperiorId()); + tree = userExtraService.getOne(lqw); + System.err.println("last=>" + last); + System.err.println("tree=>" + tree); + BigDecimal before = tree.getCash(); + + tree.setCash(tree.getCash().add(new BigDecimal(String.valueOf(baisc * persent)))); + baisc *= persent; + if (ObjectUtils.isNotEmpty(tree.getSuperiorId())) { + LambdaQueryWrapper fatherLqw = new LambdaQueryWrapper<>(); + + fatherLqw.eq(UserExtra::getUserId, tree.getSuperiorId()); + UserExtra father = userExtraService.getOne(fatherLqw); + + persent = (double) father.getPercentage() / 100; + tree.setCash(tree.getCash().subtract(new BigDecimal(String.valueOf(baisc * persent)))); + } + BigDecimal after = tree.getCash(); + + fundsLogMapper.insert(FundsLog.builder() + .consume(new BigDecimal(String.valueOf(baisc))) + .earnings(after.subtract(before)) + .consumer(sysUserService.getNameById(last.getUserId())) + .beneficiaries(sysUserService.getNameById(tree.getUserId())) + .persent(tree.getPercentage()) + .createTime(LocalDateTime.now()) + .userId(last.getUserId()) + .build()); + userExtraMapper.update(tree, lqw); + } while (ObjectUtils.isNotEmpty(tree.getSuperiorId())); + + return tree.getUserId(); + } + + public boolean check(Long pid, Long lid, Long fid) { + return Objects.equals(pid, lid) || Objects.equals(pid, fid) || pid == 1L; + } + + @Override + public void benefit(Double basic) { + Long userId = SecurityUtils.getUserId(); + if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){ + return; + } + UserExtra user = userExtraMapper.selectOne(new LambdaQueryWrapper().eq(UserExtra::getUserId, userId)); + + if (!check(user.getSuperiorId(), user.getLowestId(), user.getFirstId())) { + UserExtra father = userExtraMapper.selectOne(new LambdaQueryWrapper().eq(UserExtra::getUserId, user.getSuperiorId())); + father.setIntegral(father.getIntegral() + 100); + + distributionIntegralService.insertDisLog(father.getId()); + + userExtraMapper.update(father, new LambdaQueryWrapper().eq(UserExtra::getUserId, user.getSuperiorId())); + } + + doCash(user, basic); + +// UserExtra lowest = userExtraMapper.selectOne(new LambdaQueryWrapper().eq(UserExtra::getUserId, user.getLowestId())); +// UserExtra first = userExtraMapper.selectOne(new LambdaQueryWrapper().eq(UserExtra::getUserId, user.getFirstId())); +// UserExtra root = userExtraMapper.selectOne(new LambdaQueryWrapper().eq(UserExtra::getUserId, 1L)); +// +// +// double persent = 1; +// if (ObjectUtils.isNotEmpty(lowest) && lowest.getId() != 1L) { +// lowest.setCash(lowest.getCash().add(new BigDecimal(String.valueOf(basic * persent)))); +// BigDecimal bl = lowest.getCash(); +// BigDecimal bf = first.getCash(); +// BigDecimal br = root.getCash(); +// if (lowest.getFirstId() != null) { +// persent = (double) first.getPercentage() / 100; +// lowest.setCash(lowest.getCash().subtract(new BigDecimal(String.valueOf(basic * persent)))); +// +// first.setCash(first.getCash().add(new BigDecimal(String.valueOf(basic * persent)))); +// +// basic *= persent; +// persent = (double) root.getPercentage() / 100; +// first.setCash(first.getCash().subtract(new BigDecimal(String.valueOf(basic * persent)))); +// root.setCash(root.getCash().add(new BigDecimal(String.valueOf(basic * persent)))); +// +// // TODO 资金记录 +// +// userExtraMapper.update(first, new LambdaQueryWrapper().eq(UserExtra::getUserId, lowest.getFirstId())); +// userExtraMapper.update(root, new LambdaQueryWrapper().eq(UserExtra::getUserId, 1L)); +// } +// BigDecimal al = lowest.getCash(); +// BigDecimal af = first.getCash(); +// BigDecimal ar = root.getCash(); +// +// fundsLogMapper.insert(FundsLog.builder() +// .beneficiaries(sysUserService.getNameById(lowest.getUserId())) +// .consumer(sysUserService.getNameById(userId)) +// .consume(new BigDecimal(String.valueOf(basic))) +// .earnings(al.subtract(bl)) +// .persent(lowest.getPercentage()) +// .build()); +// +// if (ObjectUtils.isNotEmpty(first)) +// fundsLogMapper.insert(FundsLog.builder() +// .beneficiaries(sysUserService.getNameById(first.getUserId())) +// .consumer(sysUserService.getNameById(lowest.getUserId())) +// .consume(al.subtract(bl)) +// .earnings(af.subtract(bf)) +// .persent(first.getPercentage()) +// .build()); +// +// if (ObjectUtils.isNotEmpty()) +// +// userExtraMapper.update(lowest, new LambdaQueryWrapper().eq(UserExtra::getUserId, user.getLowestId())); +// } else if (ObjectUtils.isNotEmpty(first)) { +// first.setCash(first.getCash().add(new BigDecimal(String.valueOf(basic * persent)))); +// +// persent = (double) root.getPercentage() / 100; +// first.setCash(first.getCash().subtract(new BigDecimal(String.valueOf(basic * persent)))); +// root.setCash(root.getCash().add(new BigDecimal(String.valueOf(basic * persent)))); +// +// userExtraMapper.update(first, new LambdaQueryWrapper().eq(UserExtra::getUserId, lowest.getFirstId())); +// userExtraMapper.update(root, new LambdaQueryWrapper().eq(UserExtra::getUserId, 1L)); +// } else { +// root.setCash(root.getCash().add(new BigDecimal(String.valueOf(basic * persent)))); +// +// userExtraMapper.update(root, new LambdaQueryWrapper().eq(UserExtra::getUserId, 1L)); +// } + } + + + +} diff --git a/src/main/java/com/ruoyi/system/file/FileSignature.java b/src/main/java/com/ruoyi/system/file/FileSignature.java new file mode 100644 index 0000000..43946ce --- /dev/null +++ b/src/main/java/com/ruoyi/system/file/FileSignature.java @@ -0,0 +1,24 @@ +package com.ruoyi.system.file; + +import com.muta.common.config.AliConfig; +import com.muta.common.core.service.ISysFileService; +import com.muta.common.utils.oss.OSSSignatureExample; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * @author: Larry + * @Date: 2024 /06 /06 / 16:23 + * @Description: + */ +@Component +public class FileSignature { + @Resource + private ISysFileService aliOssService; + public String getSignUrl(String fileUrl){ + AliConfig aliConfig = new AliConfig(); + aliOssService.getConfig(aliConfig); + return OSSSignatureExample.generateSignedUrl(aliConfig, fileUrl.substring(fileUrl.lastIndexOf("/") + 1)); + } +} diff --git a/src/main/java/com/ruoyi/system/lesong/domain/LesongLyrics.java b/src/main/java/com/ruoyi/system/lesong/domain/LesongLyrics.java new file mode 100644 index 0000000..74ee458 --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/domain/LesongLyrics.java @@ -0,0 +1,40 @@ +package com.ruoyi.system.lesong.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * 歌词对象 lesong_lyrics + * + * @author mutaai + * @date 2024-05-30 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class LesongLyrics { + private static final long serialVersionUID = 1L; + + /** + * 唯一id + */ + private Long id; + + /** + * AI创作歌词ID + */ + private String lyricsId; + + /** + * 歌词内容 + */ + private String lyricsContent; + + private Date createTime; + +} diff --git a/src/main/java/com/ruoyi/system/lesong/domain/LesongLyricsUserRelative.java b/src/main/java/com/ruoyi/system/lesong/domain/LesongLyricsUserRelative.java new file mode 100644 index 0000000..ac9db98 --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/domain/LesongLyricsUserRelative.java @@ -0,0 +1,39 @@ +package com.ruoyi.system.lesong.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 歌词-用户关联对象 lesong_lyrics_user_relative + * + * @author mutaai + * @date 2024-05-30 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class LesongLyricsUserRelative { + private static final long serialVersionUID = 1L; + + /** + * 唯一id + */ + private Long id; + + /** + * 用户id + */ + private Long userId; + + /** + * 歌词id + */ + private Long lyricsId; + + +} diff --git a/src/main/java/com/ruoyi/system/lesong/domain/LesongSong.java b/src/main/java/com/ruoyi/system/lesong/domain/LesongSong.java new file mode 100644 index 0000000..9a2d215 --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/domain/LesongSong.java @@ -0,0 +1,51 @@ +package com.ruoyi.system.lesong.domain; + +import com.muta.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * 歌曲对象 lesong_song + * + * @author mutaai + * @date 2024-05-30 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class LesongSong { + private static final long serialVersionUID = 1L; + + /** + * 唯一id + */ + private Long id; + + /** + * 歌曲suno_id + */ + private String songId; + + /** + * 歌曲名词 + */ + private String songTitle; + + /** + * 歌曲文件oss存储地址 + */ + private String songUrl; + + /** + * 歌曲封面图片oss存储地址 + */ + private String songCoverImageUrl; + + private Date createTime; + +} diff --git a/src/main/java/com/ruoyi/system/lesong/domain/LesongSongStyleRelative.java b/src/main/java/com/ruoyi/system/lesong/domain/LesongSongStyleRelative.java new file mode 100644 index 0000000..1f1523c --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/domain/LesongSongStyleRelative.java @@ -0,0 +1,44 @@ +package com.ruoyi.system.lesong.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.muta.common.annotation.Excel; +import com.muta.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 歌曲-风格关联对象 lesong_song_style_relative + * + * @author mutaai + * @date 2024-05-30 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class LesongSongStyleRelative { + private static final long serialVersionUID = 1L; + + /** + * 唯一id + */ + private Long id; + + /** + * 歌曲id + */ + private Long songId; + + /** + * 歌曲风格id(数据字典id) + */ + private Long songStyleId; + + +} diff --git a/src/main/java/com/ruoyi/system/lesong/domain/LesongSongUserRelative.java b/src/main/java/com/ruoyi/system/lesong/domain/LesongSongUserRelative.java new file mode 100644 index 0000000..d35af01 --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/domain/LesongSongUserRelative.java @@ -0,0 +1,37 @@ +package com.ruoyi.system.lesong.domain; + + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 歌曲-用户关联对象 lesong_song_user_relative + * + * @author mutaai + * @date 2024-05-30 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class LesongSongUserRelative { + + /** + * 唯一id + */ + private Long id; + + /** + * 用户id + */ + private Long userId; + + /** + * 歌曲id + */ + private Long songId; + + +} diff --git a/src/main/java/com/ruoyi/system/lesong/mapper/LesongLyricsMapper.java b/src/main/java/com/ruoyi/system/lesong/mapper/LesongLyricsMapper.java new file mode 100644 index 0000000..03e6aca --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/mapper/LesongLyricsMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.lesong.mapper; + +import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.lesong.domain.LesongLyrics; + +/** + * 歌词Mapper接口 + * + * @author mutaai + * @date 2024-05-30 + */ +public interface LesongLyricsMapper extends BaseMapper { + /** + * 查询歌词 + * + * @param id 歌词主键 + * @return 歌词 + */ + public LesongLyrics selectLesongLyricsById(Long id); + + /** + * 查询歌词列表 + * + * @param lesongLyrics 歌词 + * @return 歌词集合 + */ + public List selectLesongLyricsList(LesongLyrics lesongLyrics); + + /** + * 新增歌词 + * + * @param lesongLyrics 歌词 + * @return 结果 + */ + public int insertLesongLyrics(LesongLyrics lesongLyrics); + + /** + * 修改歌词 + * + * @param lesongLyrics 歌词 + * @return 结果 + */ + public int updateLesongLyrics(LesongLyrics lesongLyrics); + + /** + * 删除歌词 + * + * @param id 歌词主键 + * @return 结果 + */ + public int deleteLesongLyricsById(Long id); + + /** + * 批量删除歌词 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteLesongLyricsByIds(Long[] ids); +} diff --git a/src/main/java/com/ruoyi/system/lesong/mapper/LesongLyricsUserRelativeMapper.java b/src/main/java/com/ruoyi/system/lesong/mapper/LesongLyricsUserRelativeMapper.java new file mode 100644 index 0000000..e646b01 --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/mapper/LesongLyricsUserRelativeMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.lesong.mapper; + +import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.lesong.domain.LesongLyricsUserRelative; + +/** + * 歌词-用户关联Mapper接口 + * + * @author mutaai + * @date 2024-05-30 + */ +public interface LesongLyricsUserRelativeMapper extends BaseMapper { + /** + * 查询歌词-用户关联 + * + * @param id 歌词-用户关联主键 + * @return 歌词-用户关联 + */ + public LesongLyricsUserRelative selectLesongLyricsUserRelativeById(Long id); + + /** + * 查询歌词-用户关联列表 + * + * @param lesongLyricsUserRelative 歌词-用户关联 + * @return 歌词-用户关联集合 + */ + public List selectLesongLyricsUserRelativeList(LesongLyricsUserRelative lesongLyricsUserRelative); + + /** + * 新增歌词-用户关联 + * + * @param lesongLyricsUserRelative 歌词-用户关联 + * @return 结果 + */ + public int insertLesongLyricsUserRelative(LesongLyricsUserRelative lesongLyricsUserRelative); + + /** + * 修改歌词-用户关联 + * + * @param lesongLyricsUserRelative 歌词-用户关联 + * @return 结果 + */ + public int updateLesongLyricsUserRelative(LesongLyricsUserRelative lesongLyricsUserRelative); + + /** + * 删除歌词-用户关联 + * + * @param id 歌词-用户关联主键 + * @return 结果 + */ + public int deleteLesongLyricsUserRelativeById(Long id); + + /** + * 批量删除歌词-用户关联 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteLesongLyricsUserRelativeByIds(Long[] ids); +} diff --git a/src/main/java/com/ruoyi/system/lesong/mapper/LesongSongMapper.java b/src/main/java/com/ruoyi/system/lesong/mapper/LesongSongMapper.java new file mode 100644 index 0000000..8fd6dbd --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/mapper/LesongSongMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.lesong.mapper; + +import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.lesong.domain.LesongSong; + +/** + * 歌曲Mapper接口 + * + * @author mutaai + * @date 2024-05-30 + */ +public interface LesongSongMapper extends BaseMapper { + /** + * 查询歌曲 + * + * @param id 歌曲主键 + * @return 歌曲 + */ + public LesongSong selectLesongSongById(Long id); + + /** + * 查询歌曲列表 + * + * @param lesongSong 歌曲 + * @return 歌曲集合 + */ + public List selectLesongSongList(LesongSong lesongSong); + + /** + * 新增歌曲 + * + * @param lesongSong 歌曲 + * @return 结果 + */ + public int insertLesongSong(LesongSong lesongSong); + + /** + * 修改歌曲 + * + * @param lesongSong 歌曲 + * @return 结果 + */ + public int updateLesongSong(LesongSong lesongSong); + + /** + * 删除歌曲 + * + * @param id 歌曲主键 + * @return 结果 + */ + public int deleteLesongSongById(Long id); + + /** + * 批量删除歌曲 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteLesongSongByIds(Long[] ids); +} diff --git a/src/main/java/com/ruoyi/system/lesong/mapper/LesongSongStyleRelativeMapper.java b/src/main/java/com/ruoyi/system/lesong/mapper/LesongSongStyleRelativeMapper.java new file mode 100644 index 0000000..1ddea90 --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/mapper/LesongSongStyleRelativeMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.lesong.mapper; + +import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.lesong.domain.LesongSongStyleRelative; + +/** + * 歌曲-风格关联Mapper接口 + * + * @author mutaai + * @date 2024-05-30 + */ +public interface LesongSongStyleRelativeMapper extends BaseMapper { + /** + * 查询歌曲-风格关联 + * + * @param id 歌曲-风格关联主键 + * @return 歌曲-风格关联 + */ + public LesongSongStyleRelative selectLesongSongStyleRelativeById(Long id); + + /** + * 查询歌曲-风格关联列表 + * + * @param lesongSongStyleRelative 歌曲-风格关联 + * @return 歌曲-风格关联集合 + */ + public List selectLesongSongStyleRelativeList(LesongSongStyleRelative lesongSongStyleRelative); + + /** + * 新增歌曲-风格关联 + * + * @param lesongSongStyleRelative 歌曲-风格关联 + * @return 结果 + */ + public int insertLesongSongStyleRelative(LesongSongStyleRelative lesongSongStyleRelative); + + /** + * 修改歌曲-风格关联 + * + * @param lesongSongStyleRelative 歌曲-风格关联 + * @return 结果 + */ + public int updateLesongSongStyleRelative(LesongSongStyleRelative lesongSongStyleRelative); + + /** + * 删除歌曲-风格关联 + * + * @param id 歌曲-风格关联主键 + * @return 结果 + */ + public int deleteLesongSongStyleRelativeById(Long id); + + /** + * 批量删除歌曲-风格关联 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteLesongSongStyleRelativeByIds(Long[] ids); +} diff --git a/src/main/java/com/ruoyi/system/lesong/mapper/LesongSongUserRelativeMapper.java b/src/main/java/com/ruoyi/system/lesong/mapper/LesongSongUserRelativeMapper.java new file mode 100644 index 0000000..4c91536 --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/mapper/LesongSongUserRelativeMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.lesong.mapper; + +import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.lesong.domain.LesongSongUserRelative; + +/** + * 歌曲-用户关联Mapper接口 + * + * @author mutaai + * @date 2024-05-30 + */ +public interface LesongSongUserRelativeMapper extends BaseMapper { + /** + * 查询歌曲-用户关联 + * + * @param id 歌曲-用户关联主键 + * @return 歌曲-用户关联 + */ + public LesongSongUserRelative selectLesongSongUserRelativeById(Long id); + + /** + * 查询歌曲-用户关联列表 + * + * @param lesongSongUserRelative 歌曲-用户关联 + * @return 歌曲-用户关联集合 + */ + public List selectLesongSongUserRelativeList(LesongSongUserRelative lesongSongUserRelative); + + /** + * 新增歌曲-用户关联 + * + * @param lesongSongUserRelative 歌曲-用户关联 + * @return 结果 + */ + public int insertLesongSongUserRelative(LesongSongUserRelative lesongSongUserRelative); + + /** + * 修改歌曲-用户关联 + * + * @param lesongSongUserRelative 歌曲-用户关联 + * @return 结果 + */ + public int updateLesongSongUserRelative(LesongSongUserRelative lesongSongUserRelative); + + /** + * 删除歌曲-用户关联 + * + * @param id 歌曲-用户关联主键 + * @return 结果 + */ + public int deleteLesongSongUserRelativeById(Long id); + + /** + * 批量删除歌曲-用户关联 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteLesongSongUserRelativeByIds(Long[] ids); +} diff --git a/src/main/java/com/ruoyi/system/lesong/service/ILesongLyricsService.java b/src/main/java/com/ruoyi/system/lesong/service/ILesongLyricsService.java new file mode 100644 index 0000000..bcb869a --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/service/ILesongLyricsService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.lesong.service; + +import java.util.List; +import com.muta.lesong.domain.LesongLyrics; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * 歌词Service接口 + * + * @author mutaai + * @date 2024-05-30 + */ +public interface ILesongLyricsService extends IService { + /** + * 查询歌词 + * + * @param id 歌词主键 + * @return 歌词 + */ + public LesongLyrics selectLesongLyricsById(Long id); + + /** + * 查询歌词列表 + * + * @param lesongLyrics 歌词 + * @return 歌词集合 + */ + public List selectLesongLyricsList(LesongLyrics lesongLyrics); + + /** + * 新增歌词 + * + * @param lesongLyrics 歌词 + * @return 结果 + */ + public int insertLesongLyrics(LesongLyrics lesongLyrics); + + /** + * 修改歌词 + * + * @param lesongLyrics 歌词 + * @return 结果 + */ + public int updateLesongLyrics(LesongLyrics lesongLyrics); + + /** + * 批量删除歌词 + * + * @param ids 需要删除的歌词主键集合 + * @return 结果 + */ + public int deleteLesongLyricsByIds(Long[] ids); + + /** + * 删除歌词信息 + * + * @param id 歌词主键 + * @return 结果 + */ + public int deleteLesongLyricsById(Long id); +} diff --git a/src/main/java/com/ruoyi/system/lesong/service/ILesongLyricsUserRelativeService.java b/src/main/java/com/ruoyi/system/lesong/service/ILesongLyricsUserRelativeService.java new file mode 100644 index 0000000..a9bd8c5 --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/service/ILesongLyricsUserRelativeService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.lesong.service; + +import java.util.List; +import com.muta.lesong.domain.LesongLyricsUserRelative; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * 歌词-用户关联Service接口 + * + * @author mutaai + * @date 2024-05-30 + */ +public interface ILesongLyricsUserRelativeService extends IService { + /** + * 查询歌词-用户关联 + * + * @param id 歌词-用户关联主键 + * @return 歌词-用户关联 + */ + public LesongLyricsUserRelative selectLesongLyricsUserRelativeById(Long id); + + /** + * 查询歌词-用户关联列表 + * + * @param lesongLyricsUserRelative 歌词-用户关联 + * @return 歌词-用户关联集合 + */ + public List selectLesongLyricsUserRelativeList(LesongLyricsUserRelative lesongLyricsUserRelative); + + /** + * 新增歌词-用户关联 + * + * @param lesongLyricsUserRelative 歌词-用户关联 + * @return 结果 + */ + public int insertLesongLyricsUserRelative(LesongLyricsUserRelative lesongLyricsUserRelative); + + /** + * 修改歌词-用户关联 + * + * @param lesongLyricsUserRelative 歌词-用户关联 + * @return 结果 + */ + public int updateLesongLyricsUserRelative(LesongLyricsUserRelative lesongLyricsUserRelative); + + /** + * 批量删除歌词-用户关联 + * + * @param ids 需要删除的歌词-用户关联主键集合 + * @return 结果 + */ + public int deleteLesongLyricsUserRelativeByIds(Long[] ids); + + /** + * 删除歌词-用户关联信息 + * + * @param id 歌词-用户关联主键 + * @return 结果 + */ + public int deleteLesongLyricsUserRelativeById(Long id); +} diff --git a/src/main/java/com/ruoyi/system/lesong/service/ILesongSongService.java b/src/main/java/com/ruoyi/system/lesong/service/ILesongSongService.java new file mode 100644 index 0000000..686d001 --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/service/ILesongSongService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.lesong.service; + +import java.util.List; +import com.muta.lesong.domain.LesongSong; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * 歌曲Service接口 + * + * @author mutaai + * @date 2024-05-30 + */ +public interface ILesongSongService extends IService { + /** + * 查询歌曲 + * + * @param id 歌曲主键 + * @return 歌曲 + */ + public LesongSong selectLesongSongById(Long id); + + /** + * 查询歌曲列表 + * + * @param lesongSong 歌曲 + * @return 歌曲集合 + */ + public List selectLesongSongList(LesongSong lesongSong); + + /** + * 新增歌曲 + * + * @param lesongSong 歌曲 + * @return 结果 + */ + public int insertLesongSong(LesongSong lesongSong); + + /** + * 修改歌曲 + * + * @param lesongSong 歌曲 + * @return 结果 + */ + public int updateLesongSong(LesongSong lesongSong); + + /** + * 批量删除歌曲 + * + * @param ids 需要删除的歌曲主键集合 + * @return 结果 + */ + public int deleteLesongSongByIds(Long[] ids); + + /** + * 删除歌曲信息 + * + * @param id 歌曲主键 + * @return 结果 + */ + public int deleteLesongSongById(Long id); +} diff --git a/src/main/java/com/ruoyi/system/lesong/service/ILesongSongStyleRelativeService.java b/src/main/java/com/ruoyi/system/lesong/service/ILesongSongStyleRelativeService.java new file mode 100644 index 0000000..8a65cfb --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/service/ILesongSongStyleRelativeService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.lesong.service; + +import java.util.List; +import com.muta.lesong.domain.LesongSongStyleRelative; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * 歌曲-风格关联Service接口 + * + * @author mutaai + * @date 2024-05-30 + */ +public interface ILesongSongStyleRelativeService extends IService { + /** + * 查询歌曲-风格关联 + * + * @param id 歌曲-风格关联主键 + * @return 歌曲-风格关联 + */ + public LesongSongStyleRelative selectLesongSongStyleRelativeById(Long id); + + /** + * 查询歌曲-风格关联列表 + * + * @param lesongSongStyleRelative 歌曲-风格关联 + * @return 歌曲-风格关联集合 + */ + public List selectLesongSongStyleRelativeList(LesongSongStyleRelative lesongSongStyleRelative); + + /** + * 新增歌曲-风格关联 + * + * @param lesongSongStyleRelative 歌曲-风格关联 + * @return 结果 + */ + public int insertLesongSongStyleRelative(LesongSongStyleRelative lesongSongStyleRelative); + + /** + * 修改歌曲-风格关联 + * + * @param lesongSongStyleRelative 歌曲-风格关联 + * @return 结果 + */ + public int updateLesongSongStyleRelative(LesongSongStyleRelative lesongSongStyleRelative); + + /** + * 批量删除歌曲-风格关联 + * + * @param ids 需要删除的歌曲-风格关联主键集合 + * @return 结果 + */ + public int deleteLesongSongStyleRelativeByIds(Long[] ids); + + /** + * 删除歌曲-风格关联信息 + * + * @param id 歌曲-风格关联主键 + * @return 结果 + */ + public int deleteLesongSongStyleRelativeById(Long id); +} diff --git a/src/main/java/com/ruoyi/system/lesong/service/ILesongSongUserRelativeService.java b/src/main/java/com/ruoyi/system/lesong/service/ILesongSongUserRelativeService.java new file mode 100644 index 0000000..0a744af --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/service/ILesongSongUserRelativeService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.lesong.service; + +import java.util.List; +import com.muta.lesong.domain.LesongSongUserRelative; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * 歌曲-用户关联Service接口 + * + * @author mutaai + * @date 2024-05-30 + */ +public interface ILesongSongUserRelativeService extends IService { + /** + * 查询歌曲-用户关联 + * + * @param id 歌曲-用户关联主键 + * @return 歌曲-用户关联 + */ + public LesongSongUserRelative selectLesongSongUserRelativeById(Long id); + + /** + * 查询歌曲-用户关联列表 + * + * @param lesongSongUserRelative 歌曲-用户关联 + * @return 歌曲-用户关联集合 + */ + public List selectLesongSongUserRelativeList(LesongSongUserRelative lesongSongUserRelative); + + /** + * 新增歌曲-用户关联 + * + * @param lesongSongUserRelative 歌曲-用户关联 + * @return 结果 + */ + public int insertLesongSongUserRelative(LesongSongUserRelative lesongSongUserRelative); + + /** + * 修改歌曲-用户关联 + * + * @param lesongSongUserRelative 歌曲-用户关联 + * @return 结果 + */ + public int updateLesongSongUserRelative(LesongSongUserRelative lesongSongUserRelative); + + /** + * 批量删除歌曲-用户关联 + * + * @param ids 需要删除的歌曲-用户关联主键集合 + * @return 结果 + */ + public int deleteLesongSongUserRelativeByIds(Long[] ids); + + /** + * 删除歌曲-用户关联信息 + * + * @param id 歌曲-用户关联主键 + * @return 结果 + */ + public int deleteLesongSongUserRelativeById(Long id); +} diff --git a/src/main/java/com/ruoyi/system/lesong/service/impl/LesongLyricsServiceImpl.java b/src/main/java/com/ruoyi/system/lesong/service/impl/LesongLyricsServiceImpl.java new file mode 100644 index 0000000..ebbc596 --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/service/impl/LesongLyricsServiceImpl.java @@ -0,0 +1,90 @@ +package com.ruoyi.system.lesong.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.lesong.domain.LesongLyrics; +import com.muta.lesong.mapper.LesongLyricsMapper; +import com.muta.lesong.service.ILesongLyricsService; +import com.muta.common.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 歌词Service业务层处理 + * + * @author mutaai + * @date 2024-05-30 + */ +@Service +public class LesongLyricsServiceImpl extends ServiceImpl implements ILesongLyricsService { + @Autowired + private LesongLyricsMapper lesongLyricsMapper; + + /** + * 查询歌词 + * + * @param id 歌词主键 + * @return 歌词 + */ + @Override + public LesongLyrics selectLesongLyricsById(Long id) { + return lesongLyricsMapper.selectLesongLyricsById(id); + } + + /** + * 查询歌词列表 + * + * @param lesongLyrics 歌词 + * @return 歌词 + */ + @Override + public List selectLesongLyricsList(LesongLyrics lesongLyrics) { + return lesongLyricsMapper.selectLesongLyricsList(lesongLyrics); + } + + /** + * 新增歌词 + * + * @param lesongLyrics 歌词 + * @return 结果 + */ + @Override + public int insertLesongLyrics(LesongLyrics lesongLyrics) { + lesongLyrics.setCreateTime(DateUtils.getNowDate()); + return lesongLyricsMapper.insertLesongLyrics(lesongLyrics); + } + + /** + * 修改歌词 + * + * @param lesongLyrics 歌词 + * @return 结果 + */ + @Override + public int updateLesongLyrics(LesongLyrics lesongLyrics) { + return lesongLyricsMapper.updateLesongLyrics(lesongLyrics); + } + + /** + * 批量删除歌词 + * + * @param ids 需要删除的歌词主键 + * @return 结果 + */ + @Override + public int deleteLesongLyricsByIds(Long[] ids) { + return lesongLyricsMapper.deleteLesongLyricsByIds(ids); + } + + /** + * 删除歌词信息 + * + * @param id 歌词主键 + * @return 结果 + */ + @Override + public int deleteLesongLyricsById(Long id) { + return lesongLyricsMapper.deleteLesongLyricsById(id); + } +} diff --git a/src/main/java/com/ruoyi/system/lesong/service/impl/LesongLyricsUserRelativeServiceImpl.java b/src/main/java/com/ruoyi/system/lesong/service/impl/LesongLyricsUserRelativeServiceImpl.java new file mode 100644 index 0000000..333ab93 --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/service/impl/LesongLyricsUserRelativeServiceImpl.java @@ -0,0 +1,88 @@ +package com.ruoyi.system.lesong.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.lesong.domain.LesongLyricsUserRelative; +import com.muta.lesong.mapper.LesongLyricsUserRelativeMapper; +import com.muta.lesong.service.ILesongLyricsUserRelativeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 歌词-用户关联Service业务层处理 + * + * @author mutaai + * @date 2024-05-30 + */ +@Service +public class LesongLyricsUserRelativeServiceImpl extends ServiceImpl implements ILesongLyricsUserRelativeService { + @Autowired + private LesongLyricsUserRelativeMapper lesongLyricsUserRelativeMapper; + + /** + * 查询歌词-用户关联 + * + * @param id 歌词-用户关联主键 + * @return 歌词-用户关联 + */ + @Override + public LesongLyricsUserRelative selectLesongLyricsUserRelativeById(Long id) { + return lesongLyricsUserRelativeMapper.selectLesongLyricsUserRelativeById(id); + } + + /** + * 查询歌词-用户关联列表 + * + * @param lesongLyricsUserRelative 歌词-用户关联 + * @return 歌词-用户关联 + */ + @Override + public List selectLesongLyricsUserRelativeList(LesongLyricsUserRelative lesongLyricsUserRelative) { + return lesongLyricsUserRelativeMapper.selectLesongLyricsUserRelativeList(lesongLyricsUserRelative); + } + + /** + * 新增歌词-用户关联 + * + * @param lesongLyricsUserRelative 歌词-用户关联 + * @return 结果 + */ + @Override + public int insertLesongLyricsUserRelative(LesongLyricsUserRelative lesongLyricsUserRelative) { + return lesongLyricsUserRelativeMapper.insertLesongLyricsUserRelative(lesongLyricsUserRelative); + } + + /** + * 修改歌词-用户关联 + * + * @param lesongLyricsUserRelative 歌词-用户关联 + * @return 结果 + */ + @Override + public int updateLesongLyricsUserRelative(LesongLyricsUserRelative lesongLyricsUserRelative) { + return lesongLyricsUserRelativeMapper.updateLesongLyricsUserRelative(lesongLyricsUserRelative); + } + + /** + * 批量删除歌词-用户关联 + * + * @param ids 需要删除的歌词-用户关联主键 + * @return 结果 + */ + @Override + public int deleteLesongLyricsUserRelativeByIds(Long[] ids) { + return lesongLyricsUserRelativeMapper.deleteLesongLyricsUserRelativeByIds(ids); + } + + /** + * 删除歌词-用户关联信息 + * + * @param id 歌词-用户关联主键 + * @return 结果 + */ + @Override + public int deleteLesongLyricsUserRelativeById(Long id) { + return lesongLyricsUserRelativeMapper.deleteLesongLyricsUserRelativeById(id); + } +} diff --git a/src/main/java/com/ruoyi/system/lesong/service/impl/LesongSongServiceImpl.java b/src/main/java/com/ruoyi/system/lesong/service/impl/LesongSongServiceImpl.java new file mode 100644 index 0000000..ec08fac --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/service/impl/LesongSongServiceImpl.java @@ -0,0 +1,89 @@ +package com.ruoyi.system.lesong.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.util.List; + import com.muta.common.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.muta.lesong.mapper.LesongSongMapper; +import com.muta.lesong.domain.LesongSong; +import com.muta.lesong.service.ILesongSongService; + +/** + * 歌曲Service业务层处理 + * + * @author mutaai + * @date 2024-05-30 + */ +@Service +public class LesongSongServiceImpl extends ServiceImpl implements ILesongSongService { + @Autowired + private LesongSongMapper lesongSongMapper; + + /** + * 查询歌曲 + * + * @param id 歌曲主键 + * @return 歌曲 + */ + @Override + public LesongSong selectLesongSongById(Long id) { + return lesongSongMapper.selectLesongSongById(id); + } + + /** + * 查询歌曲列表 + * + * @param lesongSong 歌曲 + * @return 歌曲 + */ + @Override + public List selectLesongSongList(LesongSong lesongSong) { + return lesongSongMapper.selectLesongSongList(lesongSong); + } + + /** + * 新增歌曲 + * + * @param lesongSong 歌曲 + * @return 结果 + */ + @Override + public int insertLesongSong(LesongSong lesongSong) { + lesongSong.setCreateTime(DateUtils.getNowDate()); + return lesongSongMapper.insertLesongSong(lesongSong); + } + + /** + * 修改歌曲 + * + * @param lesongSong 歌曲 + * @return 结果 + */ + @Override + public int updateLesongSong(LesongSong lesongSong) { + return lesongSongMapper.updateLesongSong(lesongSong); + } + + /** + * 批量删除歌曲 + * + * @param ids 需要删除的歌曲主键 + * @return 结果 + */ + @Override + public int deleteLesongSongByIds(Long[] ids) { + return lesongSongMapper.deleteLesongSongByIds(ids); + } + + /** + * 删除歌曲信息 + * + * @param id 歌曲主键 + * @return 结果 + */ + @Override + public int deleteLesongSongById(Long id) { + return lesongSongMapper.deleteLesongSongById(id); + } +} diff --git a/src/main/java/com/ruoyi/system/lesong/service/impl/LesongSongStyleRelativeServiceImpl.java b/src/main/java/com/ruoyi/system/lesong/service/impl/LesongSongStyleRelativeServiceImpl.java new file mode 100644 index 0000000..f80dbdc --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/service/impl/LesongSongStyleRelativeServiceImpl.java @@ -0,0 +1,87 @@ +package com.ruoyi.system.lesong.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.muta.lesong.mapper.LesongSongStyleRelativeMapper; +import com.muta.lesong.domain.LesongSongStyleRelative; +import com.muta.lesong.service.ILesongSongStyleRelativeService; + +/** + * 歌曲-风格关联Service业务层处理 + * + * @author mutaai + * @date 2024-05-30 + */ +@Service +public class LesongSongStyleRelativeServiceImpl extends ServiceImpl implements ILesongSongStyleRelativeService { + @Autowired + private LesongSongStyleRelativeMapper lesongSongStyleRelativeMapper; + + /** + * 查询歌曲-风格关联 + * + * @param id 歌曲-风格关联主键 + * @return 歌曲-风格关联 + */ + @Override + public LesongSongStyleRelative selectLesongSongStyleRelativeById(Long id) { + return lesongSongStyleRelativeMapper.selectLesongSongStyleRelativeById(id); + } + + /** + * 查询歌曲-风格关联列表 + * + * @param lesongSongStyleRelative 歌曲-风格关联 + * @return 歌曲-风格关联 + */ + @Override + public List selectLesongSongStyleRelativeList(LesongSongStyleRelative lesongSongStyleRelative) { + return lesongSongStyleRelativeMapper.selectLesongSongStyleRelativeList(lesongSongStyleRelative); + } + + /** + * 新增歌曲-风格关联 + * + * @param lesongSongStyleRelative 歌曲-风格关联 + * @return 结果 + */ + @Override + public int insertLesongSongStyleRelative(LesongSongStyleRelative lesongSongStyleRelative) { + return lesongSongStyleRelativeMapper.insertLesongSongStyleRelative(lesongSongStyleRelative); + } + + /** + * 修改歌曲-风格关联 + * + * @param lesongSongStyleRelative 歌曲-风格关联 + * @return 结果 + */ + @Override + public int updateLesongSongStyleRelative(LesongSongStyleRelative lesongSongStyleRelative) { + return lesongSongStyleRelativeMapper.updateLesongSongStyleRelative(lesongSongStyleRelative); + } + + /** + * 批量删除歌曲-风格关联 + * + * @param ids 需要删除的歌曲-风格关联主键 + * @return 结果 + */ + @Override + public int deleteLesongSongStyleRelativeByIds(Long[] ids) { + return lesongSongStyleRelativeMapper.deleteLesongSongStyleRelativeByIds(ids); + } + + /** + * 删除歌曲-风格关联信息 + * + * @param id 歌曲-风格关联主键 + * @return 结果 + */ + @Override + public int deleteLesongSongStyleRelativeById(Long id) { + return lesongSongStyleRelativeMapper.deleteLesongSongStyleRelativeById(id); + } +} diff --git a/src/main/java/com/ruoyi/system/lesong/service/impl/LesongSongUserRelativeServiceImpl.java b/src/main/java/com/ruoyi/system/lesong/service/impl/LesongSongUserRelativeServiceImpl.java new file mode 100644 index 0000000..4700446 --- /dev/null +++ b/src/main/java/com/ruoyi/system/lesong/service/impl/LesongSongUserRelativeServiceImpl.java @@ -0,0 +1,87 @@ +package com.ruoyi.system.lesong.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.muta.lesong.mapper.LesongSongUserRelativeMapper; +import com.muta.lesong.domain.LesongSongUserRelative; +import com.muta.lesong.service.ILesongSongUserRelativeService; + +/** + * 歌曲-用户关联Service业务层处理 + * + * @author mutaai + * @date 2024-05-30 + */ +@Service +public class LesongSongUserRelativeServiceImpl extends ServiceImpl implements ILesongSongUserRelativeService { + @Autowired + private LesongSongUserRelativeMapper lesongSongUserRelativeMapper; + + /** + * 查询歌曲-用户关联 + * + * @param id 歌曲-用户关联主键 + * @return 歌曲-用户关联 + */ + @Override + public LesongSongUserRelative selectLesongSongUserRelativeById(Long id) { + return lesongSongUserRelativeMapper.selectLesongSongUserRelativeById(id); + } + + /** + * 查询歌曲-用户关联列表 + * + * @param lesongSongUserRelative 歌曲-用户关联 + * @return 歌曲-用户关联 + */ + @Override + public List selectLesongSongUserRelativeList(LesongSongUserRelative lesongSongUserRelative) { + return lesongSongUserRelativeMapper.selectLesongSongUserRelativeList(lesongSongUserRelative); + } + + /** + * 新增歌曲-用户关联 + * + * @param lesongSongUserRelative 歌曲-用户关联 + * @return 结果 + */ + @Override + public int insertLesongSongUserRelative(LesongSongUserRelative lesongSongUserRelative) { + return lesongSongUserRelativeMapper.insertLesongSongUserRelative(lesongSongUserRelative); + } + + /** + * 修改歌曲-用户关联 + * + * @param lesongSongUserRelative 歌曲-用户关联 + * @return 结果 + */ + @Override + public int updateLesongSongUserRelative(LesongSongUserRelative lesongSongUserRelative) { + return lesongSongUserRelativeMapper.updateLesongSongUserRelative(lesongSongUserRelative); + } + + /** + * 批量删除歌曲-用户关联 + * + * @param ids 需要删除的歌曲-用户关联主键 + * @return 结果 + */ + @Override + public int deleteLesongSongUserRelativeByIds(Long[] ids) { + return lesongSongUserRelativeMapper.deleteLesongSongUserRelativeByIds(ids); + } + + /** + * 删除歌曲-用户关联信息 + * + * @param id 歌曲-用户关联主键 + * @return 结果 + */ + @Override + public int deleteLesongSongUserRelativeById(Long id) { + return lesongSongUserRelativeMapper.deleteLesongSongUserRelativeById(id); + } +} diff --git a/src/main/java/com/ruoyi/system/log/aop/IntegralLogAspect.java b/src/main/java/com/ruoyi/system/log/aop/IntegralLogAspect.java new file mode 100644 index 0000000..721cd5f --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/aop/IntegralLogAspect.java @@ -0,0 +1,98 @@ +package com.ruoyi.system.log.aop; +import com.muta.common.annotation.IntegralLogInsert; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.model.RegisterBody; +import com.muta.common.utils.SecurityUtils; +import com.muta.log.domain.IntegralLog; +import com.muta.log.factory.IntegralLogFactory; +import com.muta.basics.domain.Kamil; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.After; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Objects; + +/** + * @author: Larry + * @Date: 2024 /04 /22 / 17:07 + * @Description: + */ +@Aspect +@Component() +public class IntegralLogAspect { + + @Resource + private IntegralLogFactory integralLogFactory; + @Async("asyncPoolTaskExecutor") // 指定使用自定义的 Executor + @After("@annotation(com.muta.common.annotation.IntegralLogInsert)") + public void before(JoinPoint joinPoint) { + MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); + // 获取方法对象 + Method method = methodSignature.getMethod(); + // 获取注解实例 + IntegralLogInsert integralLogInsert = method.getAnnotation(IntegralLogInsert.class); + System.err.println("进入"); + System.err.println(SecurityUtils.getUsername()); + //签到操作记录 + if (Objects.equals(integralLogInsert.operation(), OperationConstants.SIGNIN)) { + integralLogFactory.getInstance(integralLogInsert.operation()).insertLog(new IntegralLog()); + } + //注册操作记录 +// else if (Objects.equals(integralLogInsert.operation(), OperationConstants.REGISTER)) { +// +// Object[] args = joinPoint.getArgs(); // 获取方法参数列表 +// IntegralLog integralLog = new IntegralLog(); +// String phone = null; +// for (Object arg : args) { +// if (arg instanceof RegisterBody) { +// try { +// Field phoneField = arg.getClass().getDeclaredField("phone"); +// phoneField.setAccessible(true); +// phone = (String) phoneField.get(arg); // 获取 RegisterBody 对象中的 phone 字段的值 +// break; +// } catch (NoSuchFieldException | IllegalAccessException e) { +// e.printStackTrace(); +// } +// } +// } +// integralLog.setCreateBy(phone); +// integralLogFactory.getInstance(integralLogInsert.operation()).insertLog(integralLog); +// } + //卡密操作记录 + else if (Objects.equals(integralLogInsert.operation(), OperationConstants.Kamil)) { + System.err.println("我进来了+++++====="); + Object[] args = joinPoint.getArgs(); + IntegralLog integralLog = new IntegralLog(); + for (Object arg : args) { + if (arg instanceof Kamil) { + try { + Field fieldValue = Kamil.class.getDeclaredField("value"); + Field fieldType = Kamil.class.getDeclaredField("type"); + // 设置字段可访问,因为它可能是私有的 + fieldValue.setAccessible(true); + fieldType.setAccessible(true); + Integer v= (Integer) fieldValue.get(arg); // 使用 arg 对象获取字段的值 + Integer typeValue = (Integer) fieldType.get(arg); // 使用 arg 对象获取字段的值 + integralLog.setValue(v.toString()); + integralLog.setType(typeValue); + break; + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + } + } + integralLogFactory.getInstance(integralLogInsert.operation()).insertLog(integralLog); + } else { + // 默认情况下的处理 + } + + } + + +} diff --git a/src/main/java/com/ruoyi/system/log/aop/SimpleLogInsertAspect.java b/src/main/java/com/ruoyi/system/log/aop/SimpleLogInsertAspect.java new file mode 100644 index 0000000..24cb0c2 --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/aop/SimpleLogInsertAspect.java @@ -0,0 +1,98 @@ +package com.ruoyi.system.log.aop;//package com.muta.log.aop; +// +//import com.muta.common.annotation.LogInsert; +// +//import com.muta.common.core.service.BaseLogService; +//import com.muta.common.enums.LogType; +//import com.muta.log.config.LogConfig; +//import org.aspectj.lang.JoinPoint; +//import org.aspectj.lang.annotation.After; +//import org.aspectj.lang.annotation.Aspect; +//import org.aspectj.lang.reflect.MethodSignature; +//import org.springframework.core.DefaultParameterNameDiscoverer; +//import org.springframework.core.ParameterNameDiscoverer; +//import org.springframework.scheduling.annotation.Async; +//import org.springframework.stereotype.Component; +// +//import java.lang.reflect.Field; +//import java.lang.reflect.Method; +//import java.util.HashMap; +//import java.util.Map; +// +///** +// * @author: Larry +// * @Date: 2024 /04 /18 / 20:29 +// * @Description: +// */ +// +//@Aspect +//@Component() +//public class SimpleLogInsertAspect extends LogConfig { +// +// +// private final ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); +// private final Map parameterMap = new HashMap<>(); +// +// @After("@annotation(com.muta.common.annotation.LogInsert)") +// public void before(JoinPoint joinPoint) { +// MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); +// // 获取方法对象 +// Method method = methodSignature.getMethod(); +// // 获取注解实例 +// LogInsert logInsertAnnotation = method.getAnnotation(LogInsert.class); +// LogType value = logInsertAnnotation.value(); +// switch (value) { +// case ORDER: +// +// break; +// case SIGNIN: +// // 处理用户类型的日志 +// break; +// // 可以根据需要添加其他枚举值的处理逻辑 +// case INVITEE: +// +// break; +// +// default: +// // 默认处理逻辑 +// break; +// } +// getParameterNames(joinPoint); +// +// +// } +// +// private void getParameterNames(JoinPoint joinPoint){ +// MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); +// String[] parameterNames = methodSignature.getParameterNames(); +// if (parameterNames == null) { +// parameterNames = parameterNameDiscoverer.getParameterNames(methodSignature.getMethod()); +// } +// Object[] args = joinPoint.getArgs(); +// for (int i = 0; i < args.length; i++) { +// if (parameterNames != null) { +// System.out.println("参数名:" + parameterNames[i]); +// } +// if (args[i] != null) { +// Class parameterType = methodSignature.getMethod().getParameterTypes()[i]; +// if (parameterType.isAssignableFrom(args[i].getClass())) { +// Field[] fields = parameterType.getDeclaredFields(); +// for (Field field : fields) { +// field.setAccessible(true); +// try { +// Object value = field.get(args[i]); +// parameterMap.put(field.getName(),value); +// System.out.println(parameterMap.get(field.getName())); +// } catch (IllegalAccessException e) { +// e.printStackTrace(); +// } +// } +// } +// } +// } +// } +// +//} +// +// +// diff --git a/src/main/java/com/ruoyi/system/log/config/LogConfig.java b/src/main/java/com/ruoyi/system/log/config/LogConfig.java new file mode 100644 index 0000000..0c9768e --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/config/LogConfig.java @@ -0,0 +1,28 @@ +package com.ruoyi.system.log.config; + +import com.muta.common.core.domain.entity.UserExtra; +import com.muta.common.core.service.BaseLogService; +import com.muta.system.service.IUserExtraService; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author: Larry + * @Date: 2024 /04 /19 / 12:21 + * @Description:日志工厂数据支持类 + */ +@Component +public class LogConfig { + @Resource + private IUserExtraService userExtraService; + protected static Map logsMap = new ConcurrentHashMap<>(); + + + public BaseLogService getByType(String type){ + return logsMap.get(type); + } +} diff --git a/src/main/java/com/ruoyi/system/log/domain/IntegralLog.java b/src/main/java/com/ruoyi/system/log/domain/IntegralLog.java new file mode 100644 index 0000000..bb75cab --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/domain/IntegralLog.java @@ -0,0 +1,51 @@ +package com.ruoyi.system.log.domain; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.muta.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + + +/** + * 【请填写功能名称】对象 integral_log + * + * @author mutaai + * @date 2024-04-22 + */ +@TableName("integral_log") +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class IntegralLog { + private static final long serialVersionUID = 1L; + /** 主键 */ + @TableId() + private Long id; + /** 值 */ + private String value; + /** 操作类型 */ + private String operationType; + /** 1有效0无效 */ + private Long status; + /** 类型:增还是减 1增 0 减 */ + private Integer type; + /** 操作人 */ + private String createBy; + /** 操作时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + private Long userId; + + } + diff --git a/src/main/java/com/ruoyi/system/log/domain/InviteLog.java b/src/main/java/com/ruoyi/system/log/domain/InviteLog.java new file mode 100644 index 0000000..ed2c735 --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/domain/InviteLog.java @@ -0,0 +1,54 @@ +package com.ruoyi.system.log.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Builder; +import lombok.Data; + +import java.util.Date; + + +/** + * 【请填写功能名称】对象 invite_log + * + * @author mutaai + * @date 2024-04-23 + */ + +@Data +@TableName() +public class InviteLog +{ + + + /** 主键 */ + @TableId(value = "id",type = IdType.AUTO) + private Long id; + + /** 被邀请人 */ + + private String invitee; + + /** 邀请人 */ + + private String inviter; + + /** 报酬 */ + + private String reward; + + /** $column.columnComment */ + + private String ip; + + /** 邀请码 */ + + private String inviteCode; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; + private Long userId; + +} diff --git a/src/main/java/com/ruoyi/system/log/domain/dto/InviteLogDTO.java b/src/main/java/com/ruoyi/system/log/domain/dto/InviteLogDTO.java new file mode 100644 index 0000000..126d394 --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/domain/dto/InviteLogDTO.java @@ -0,0 +1,24 @@ +package com.ruoyi.system.log.domain.dto; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Builder; +import lombok.Data; + +/** + * @author: Larry + * @Date: 2024 /04 /23 / 16:05 + * @Description: + */ +@Data +@Builder +public class InviteLogDTO { + private Long userId; + /** 邀请人 */ + private String inviter; + /** 邀请码 */ + + private String inviteCode; + /** 被邀请人 */ + private String invitee; +} diff --git a/src/main/java/com/ruoyi/system/log/factory/IntegralLogFactory.java b/src/main/java/com/ruoyi/system/log/factory/IntegralLogFactory.java new file mode 100644 index 0000000..70d3158 --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/factory/IntegralLogFactory.java @@ -0,0 +1,43 @@ +package com.ruoyi.system.log.factory; + +import com.muta.common.constant.OperationConstants; +import com.muta.log.service.IIntegralLogService; +import com.muta.log.service.impl.InviteIntegralLogServiceImpl; +import com.muta.log.service.impl.KamilIntegralLogService; +import com.muta.log.service.impl.RegisterIntegralLogServiceImpl; +import com.muta.log.service.impl.SigninIntegralLogServiceImpl; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author: Larry + * @Date: 2024 /04 /22 / 16:55 + * @Description: + */ +@Component +public class IntegralLogFactory { + public Map iIntegralLogServiceMap = new ConcurrentHashMap<>(); + @Resource + private InviteIntegralLogServiceImpl inviteIntegralLogService; + @Resource + private RegisterIntegralLogServiceImpl registerIntegralLogService; + @Resource + private SigninIntegralLogServiceImpl signinIntegralLogService; + @Resource + private KamilIntegralLogService kamilIntegralLogService; + @PostConstruct + public void init(){ + iIntegralLogServiceMap.put(OperationConstants.INVITE,inviteIntegralLogService); + iIntegralLogServiceMap.put(OperationConstants.Kamil,kamilIntegralLogService); + iIntegralLogServiceMap.put(OperationConstants.REGISTER,registerIntegralLogService); + iIntegralLogServiceMap.put(OperationConstants.SIGNIN,signinIntegralLogService); + } + public IIntegralLogService getInstance(String type){ + return iIntegralLogServiceMap.get(type); + } + + } diff --git a/src/main/java/com/ruoyi/system/log/mapper/IntegralLogMapper.java b/src/main/java/com/ruoyi/system/log/mapper/IntegralLogMapper.java new file mode 100644 index 0000000..c3a6efc --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/mapper/IntegralLogMapper.java @@ -0,0 +1,21 @@ +package com.ruoyi.system.log.mapper; + +import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +import com.muta.common.annotation.DataPermission; +import com.muta.common.annotation.DataScope; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.log.domain.IntegralLog; + + +/** + * 【请填写功能名称】Mapper接口 + * + * @author mutaai + * @date 2024-04-22 + */ +public interface IntegralLogMapper extends BaseMapper { + + List selectByFilter(SysUser sysUser); +} diff --git a/src/main/java/com/ruoyi/system/log/mapper/InviteLogMapper.java b/src/main/java/com/ruoyi/system/log/mapper/InviteLogMapper.java new file mode 100644 index 0000000..f11655d --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/mapper/InviteLogMapper.java @@ -0,0 +1,21 @@ +package com.ruoyi.system.log.mapper; + +import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.log.domain.InviteLog; +import org.apache.ibatis.annotations.Mapper; + + +/** + * 【请填写功能名称】Mapper接口 + * + * @author mutaai + * @date 2024-04-23 + */ + +public interface InviteLogMapper extends BaseMapper { + + + List selectByFilter(SysUser sysUser); +} diff --git a/src/main/java/com/ruoyi/system/log/service/IIntegralLogService.java b/src/main/java/com/ruoyi/system/log/service/IIntegralLogService.java new file mode 100644 index 0000000..6a34909 --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/service/IIntegralLogService.java @@ -0,0 +1,27 @@ +package com.ruoyi.system.log.service; + +import java.util.List; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.common.annotation.DataScope; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.log.domain.IntegralLog; +import org.springframework.scheduling.annotation.Async; + +/** + * 【请填写功能名称】Service接口 + * + * @author mutaai + * @date 2024-04-22 + */ +public interface IIntegralLogService extends IService { + + + + List getList(SysUser sysUser); + + void insertLog(IntegralLog integralLog); + + List getByUser(); + +} diff --git a/src/main/java/com/ruoyi/system/log/service/IInviteLogService.java b/src/main/java/com/ruoyi/system/log/service/IInviteLogService.java new file mode 100644 index 0000000..7d2e6bc --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/service/IInviteLogService.java @@ -0,0 +1,40 @@ +package com.ruoyi.system.log.service; + +import java.util.List; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.log.domain.InviteLog; +import com.muta.log.domain.dto.InviteLogDTO; + +/** + * 【请填写功能名称】Service接口 + * + * @author mutaai + * @date 2024-04-23 + */ +public interface IInviteLogService extends IService { + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + + + /** + * 查询【请填写功能名称】列表 + * +// * @param inviteLog 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectInviteLogListByFilter(SysUser sysUser); + + /** + * 新增【请填写功能名称】 + * + * @param inviteLog 【请填写功能名称】 + * @return 结果 + */ + void insert(InviteLogDTO inviteLog); +} diff --git a/src/main/java/com/ruoyi/system/log/service/impl/DistributionIntegralServiceImpl.java b/src/main/java/com/ruoyi/system/log/service/impl/DistributionIntegralServiceImpl.java new file mode 100644 index 0000000..391090d --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/service/impl/DistributionIntegralServiceImpl.java @@ -0,0 +1,56 @@ +package com.ruoyi.system.log.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.common.constant.ConsumerConstants; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.core.domain.entity.UserExtra; +import com.muta.log.domain.IntegralLog; +import com.muta.log.mapper.IntegralLogMapper; +import com.muta.log.service.IIntegralLogService; +import com.muta.system.mapper.UserExtraMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /05 /24 / 15:43 + * @Description: + */ +@Service +public class DistributionIntegralServiceImpl extends ServiceImpl implements IIntegralLogService{ + @Resource + private UserExtraMapper userExtraMapper; + @Resource + private IntegralLogMapper integralLogMapper; + + @Override + public List getByUser() { + return null; + } + + @Override + public List getList(SysUser sysUser) { + return null; + } + + @Override + public void insertLog(IntegralLog integralLog) { + integralLog.setType(1); + integralLog.setOperationType(OperationConstants.DISTRIBUTION); + integralLog.setValue(ConsumerConstants.DISTRIBUTION); + integralLog.setCreateTime(new Date()); + integralLogMapper.insert(integralLog); + } + @Transactional + public void insertDisLog(Long id){ + IntegralLog integralLog = new IntegralLog(); + userExtraMapper.addIntegralByUserId(100,id); + this.insertLog(integralLog); + } + +} diff --git a/src/main/java/com/ruoyi/system/log/service/impl/InviteIntegralLogServiceImpl.java b/src/main/java/com/ruoyi/system/log/service/impl/InviteIntegralLogServiceImpl.java new file mode 100644 index 0000000..423f602 --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/service/impl/InviteIntegralLogServiceImpl.java @@ -0,0 +1,45 @@ +package com.ruoyi.system.log.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.common.constant.ConsumerConstants; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.utils.SecurityUtils; +import com.muta.log.domain.IntegralLog; +import com.muta.log.mapper.IntegralLogMapper; +import com.muta.log.service.IIntegralLogService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /05 /08 / 11:04 + * @Description: + */ +@Service +public class InviteIntegralLogServiceImpl extends ServiceImpl implements IIntegralLogService { + @Resource + private IntegralLogMapper integralLogMapper; + + @Override + public List getByUser() { + return null; + } + + @Override + public List getList(SysUser sysUser) { + return null; + } + + @Override + public void insertLog(IntegralLog integralLog) { + integralLog.setType(1); + integralLog.setOperationType(OperationConstants.INVITE); + integralLog.setValue(ConsumerConstants.INVITE); + integralLog.setCreateTime(new Date()); + integralLogMapper.insert(integralLog); + } +} diff --git a/src/main/java/com/ruoyi/system/log/service/impl/InviteLogServiceImpl.java b/src/main/java/com/ruoyi/system/log/service/impl/InviteLogServiceImpl.java new file mode 100644 index 0000000..4bc4a24 --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/service/impl/InviteLogServiceImpl.java @@ -0,0 +1,78 @@ +package com.ruoyi.system.log.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import java.util.Date; +import java.util.List; + +import com.muta.common.annotation.DataScope; +import com.muta.common.constant.ConsumerConstants; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.utils.SecurityUtils; +import com.muta.log.domain.InviteLog; +import com.muta.log.domain.dto.InviteLogDTO; +import com.muta.log.mapper.InviteLogMapper; +import com.muta.log.service.IInviteLogService; + +import com.muta.system.mapper.SysUserMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + + +/** + * 【请填写功能名称】Service业务层处理 + * + * @author mutaai + * @date 2024-04-23 + */ +@Service +public class InviteLogServiceImpl extends ServiceImpl implements IInviteLogService { + @Autowired + private InviteLogMapper inviteLogMapper; + @Resource + private SysUserMapper sysUserMapper; + + + + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + + + /** + * 查询【请填写功能名称】列表 + * +// * @param inviteLog 【请填写功能名称】 + * @return 【请填写功能名称】 + */ + + @DataScope(type = "log") + @Override + public List selectInviteLogListByFilter(SysUser sysUser) { + return inviteLogMapper.selectByFilter(sysUser); + } + + /** + * 新增【请填写功能名称】 + * +// * @param inviteLog 【请填写功能名称】 + * @return 结果 + */ + @Override + public void insert(InviteLogDTO inviteLogDTO) { + InviteLog inviteLog = new InviteLog(); + inviteLog.setInvitee(inviteLogDTO.getInvitee()); + inviteLog.setInviter(inviteLogDTO.getInviter()); + inviteLog.setUserId(inviteLogDTO.getUserId()); + inviteLog.setInviteCode(inviteLogDTO.getInviteCode()); + inviteLog.setReward(ConsumerConstants.REGISTER); + inviteLog.setCreateTime(new Date()); + inviteLogMapper.insert(inviteLog); + } + +} diff --git a/src/main/java/com/ruoyi/system/log/service/impl/KamilIntegralLogService.java b/src/main/java/com/ruoyi/system/log/service/impl/KamilIntegralLogService.java new file mode 100644 index 0000000..128f0f0 --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/service/impl/KamilIntegralLogService.java @@ -0,0 +1,58 @@ +package com.ruoyi.system.log.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.utils.SecurityUtils; +import com.muta.log.domain.IntegralLog; +import com.muta.log.mapper.IntegralLogMapper; +import com.muta.log.service.IIntegralLogService; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /04 /23 / 14:12 + * @Description: + */ +@Service +public class KamilIntegralLogService extends ServiceImpl implements IIntegralLogService { + @Resource + private IntegralLogMapper integralLogMapper; + public KamilIntegralLogService() { + super(); + } + + @Override + public List getList(SysUser sysUser) { + return null; + } + + @Override + public List getByUser() { + return null; + } + + @Override + public void insertLog(IntegralLog integralLog) { + if (integralLog.getType().equals(0)) { + // 处理 type 字段为 0 的情况 + integralLog.setValue(integralLog.getValue()+"积分"); + } else if (integralLog.getType().equals(1)) { + // 处理 type 字段为 1 的情况 + integralLog.setValue("普通会员"+integralLog.getValue()+"天"); + } else if (integralLog.getType().equals(2)) { + // 处理 type 字段为 2 的情况 + integralLog.setValue("超级会员"+integralLog.getValue()+"天"); + } + integralLog.setCreateBy(SecurityContextHolder.getContext().getAuthentication().getName()); + integralLog.setOperationType(OperationConstants.Kamil); + integralLog.setCreateTime(new Date()); + integralLog.setUserId(SecurityUtils.getUserId()); + integralLogMapper.insert(integralLog); + } +} diff --git a/src/main/java/com/ruoyi/system/log/service/impl/MessageIntegralLogServiceImpl.java b/src/main/java/com/ruoyi/system/log/service/impl/MessageIntegralLogServiceImpl.java new file mode 100644 index 0000000..98122c8 --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/service/impl/MessageIntegralLogServiceImpl.java @@ -0,0 +1,44 @@ +package com.ruoyi.system.log.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.common.constant.ConsumerConstants; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.log.domain.IntegralLog; +import com.muta.log.mapper.IntegralLogMapper; +import com.muta.log.service.IIntegralLogService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /05 /24 / 12:15 + * @Description: + */ +@Service +public class MessageIntegralLogServiceImpl extends ServiceImpl implements IIntegralLogService { + @Resource + private IntegralLogMapper integralLogMapper; + + + @Override + public List getList(SysUser sysUser) { + return null; + } + + @Override + public List getByUser() { + return null; + } + + @Override + public void insertLog(IntegralLog integralLog) { + integralLog.setType(1); + integralLog.setOperationType(OperationConstants.MESSAGE); + integralLog.setCreateTime(new Date()); + integralLogMapper.insert(integralLog); + } +} diff --git a/src/main/java/com/ruoyi/system/log/service/impl/RegisterIntegralLogServiceImpl.java b/src/main/java/com/ruoyi/system/log/service/impl/RegisterIntegralLogServiceImpl.java new file mode 100644 index 0000000..142d8b5 --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/service/impl/RegisterIntegralLogServiceImpl.java @@ -0,0 +1,52 @@ +package com.ruoyi.system.log.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.common.annotation.DataScope; +import com.muta.common.constant.ConsumerConstants; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.utils.SecurityUtils; +import com.muta.log.domain.IntegralLog; +import com.muta.log.mapper.IntegralLogMapper; +import com.muta.log.service.IIntegralLogService; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /04 /22 / 17:03 + * @Description:注册积分日志插入服务类 + */ +//默认查询时使用这个类 +@Primary +@Service +public class RegisterIntegralLogServiceImpl extends ServiceImpl implements IIntegralLogService { + @Resource + private IntegralLogMapper integralLogMapper; + @DataScope(type = "2") + @Override + public List getList(SysUser sysUser) { + sysUser.setUserId(SecurityUtils.getUserId()); + return integralLogMapper.selectByFilter(sysUser); + } + + @Override + public List getByUser() { + LambdaQueryWrapper integralLogLambdaQueryWrapper = new LambdaQueryWrapper<>(); + integralLogLambdaQueryWrapper.orderByDesc(IntegralLog::getCreateTime); + return integralLogMapper.selectList(integralLogLambdaQueryWrapper); + } + + @Override + public void insertLog(IntegralLog integralLog) { + integralLog.setType(1); + integralLog.setOperationType(OperationConstants.REGISTER); + integralLog.setCreateTime(new Date()); + integralLogMapper.insert(integralLog); + } +} diff --git a/src/main/java/com/ruoyi/system/log/service/impl/ShopIntegralLogServiceImpl.java b/src/main/java/com/ruoyi/system/log/service/impl/ShopIntegralLogServiceImpl.java new file mode 100644 index 0000000..74767c7 --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/service/impl/ShopIntegralLogServiceImpl.java @@ -0,0 +1,53 @@ +package com.ruoyi.system.log.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.utils.SecurityUtils; +import com.muta.log.domain.IntegralLog; +import com.muta.log.mapper.IntegralLogMapper; +import com.muta.log.service.IIntegralLogService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /06 /07 / 16:22 + * @Description: + */ +@Service +public class ShopIntegralLogServiceImpl extends ServiceImpl implements IIntegralLogService { + @Override + public List getByUser() { + return null; + } + + @Resource + private IntegralLogMapper integralLogMapper; + + + + @Override + public List getList(SysUser sysUser) { + return null; + } + + @Override + public void insertLog(IntegralLog integralLog) { + integralLog.setType(1); + integralLog.setOperationType(OperationConstants.SHOP); + integralLog.setCreateBy(SecurityUtils.getUsername()); + integralLog.setCreateTime(new Date()); + integralLog.setUserId(SecurityUtils.getUserId()); + integralLogMapper.insert(integralLog); + } + public void insertShop(Integer value){ + IntegralLog integralLog =IntegralLog.builder() + .value(value+"积分") + .build(); + this.insertLog(integralLog); + } +} diff --git a/src/main/java/com/ruoyi/system/log/service/impl/SigninIntegralLogServiceImpl.java b/src/main/java/com/ruoyi/system/log/service/impl/SigninIntegralLogServiceImpl.java new file mode 100644 index 0000000..802593a --- /dev/null +++ b/src/main/java/com/ruoyi/system/log/service/impl/SigninIntegralLogServiceImpl.java @@ -0,0 +1,58 @@ +package com.ruoyi.system.log.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import com.muta.common.constant.ConsumerConstants; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.utils.SecurityUtils; +import com.muta.log.domain.IntegralLog; +import com.muta.log.mapper.IntegralLogMapper; + +import com.muta.log.service.IIntegralLogService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + + +/** + * 【请填写功能名称】Service业务层处理 + * @author Larry + * @date 2024 -04 -22 + * 签到类型消费日志增加 + */ +@Service +public class SigninIntegralLogServiceImpl extends ServiceImpl implements IIntegralLogService { + @Override + public List getByUser() { + return null; + } + + @Resource + private IntegralLogMapper integralLogMapper; + + + + @Override + public List getList(SysUser sysUser) { + return null; + } + + @Override + public void insertLog(IntegralLog integralLog) { + integralLog.setType(1); + integralLog.setOperationType(OperationConstants.SIGNIN); + integralLog.setCreateBy(SecurityUtils.getUsername()); + integralLog.setCreateTime(new Date()); + integralLog.setUserId(SecurityUtils.getUserId()); + integralLogMapper.insert(integralLog); + } + public void insertSign(Integer value){ + IntegralLog integralLog =IntegralLog.builder() + .value(value+"积分") + .build(); + this.insertLog(integralLog); + } +} diff --git a/src/main/java/com/ruoyi/system/pay/config/AliPayConfig.java b/src/main/java/com/ruoyi/system/pay/config/AliPayConfig.java new file mode 100644 index 0000000..18d264b --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/config/AliPayConfig.java @@ -0,0 +1,58 @@ +package com.ruoyi.system.pay.config; + +import com.alipay.api.AlipayClient; +import com.alipay.api.DefaultAlipayClient; +import org.springframework.stereotype.Component; + +/** + * @ClassName AliPayConfig + * @Author 周政 + * @create 2023/2/7 0007 16:56 + */ +@Component +public class AliPayConfig { + /** + * 网关地址 + **/ + public static final String PAY_GATEWAY = "https://openapi.alipay.com/gateway.do"; + /** + * 支付宝 APPID + **/ + public static final String APPID = "2021004141689061"; + /* + * 应用私钥 + **/ + public static final String APP_PRI_KEY = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCG8XWy6d19dF6ZGboB41KSPqtOGHkW3/40To6P+5F0AP7wU+Nl14OxrQxogmAojTgf/tyQs5tt+soRwv17Lfj5WYoFTr7KJPqg38X8AUJrNCqJiwkPhJGeWtB+jmy/30aOQ1MCBuU2KmHEGcYsZAJmtV09ql22HdnZNoXl6Fq3f2Wpfrnq6xyjLWmHuOuZU9rejTh8Syy3xoNWhqWK7OhP8ykXnSZmw3xa1+MLNt6lokuH5ZnLd5V08RrcqvvCuWVAZjENh2JhjvQPirI9a2drPkC1IAqJdlVoCJxSEwwSCMyPSxa5WaWpIDDWP7W4IT/1w8rnNKRfFnmngHTlbjqbAgMBAAECggEAYNlTnAD1EmE+s6sfMNOyI3wO/pHZ9mz0yR3Ie9YV4qgEUQAkKKewwQht62QHF5OjQHNuYfxGBX0FIhJMUuf/1RZKVNzbWcGIj4WLVv6gaMib7vN2oUiIKpsLIImfy2W4AcqX/NBuGZ35ZQEKljmA764jKWrorxhljdvv5b4JvcAIHiIj7C1KvLDyFrfe9zgH2U+6Oi//bnUcbqjnk5ry/x2vaa9txTbISG6KQectWloWWc2r+q//rqBWajT4b1aIQZ7bRZaXGwhNhb9ZzrvsbcP3aZbch4nWGHtLZC97Zt4Z0wTQRePUwgTl5Ql4czjcx+Y8fpYdAQZp4qooL6QBQQKBgQDVgNfFchFUUwZSElW7v6sJTukWPXtiPDR806vjxFNKD9Jb/Sr45qk7JtCFvmzHvjN22QJsMf5dv3ygCHcx88JNyGQGw6QQs1vxRp92IpC3wvGHd2S+wuT4RMrj4j17+aUHK0ZAeNbshO0wv7QudOqr94at9lsVq9j8Hx/jWuU3UwKBgQChzY1Guvup0tJCJwZIY/669LliZIy6k6rfJrbYWV0Jzr5MI1AcGit3kY++C8DBAsehC0KAbz0eM4GlM8zXvWx7EXlVFk2qGohkWW1Wi3bDi+ijT0nAQcEpvxxYzTbblTExvJbE0iIidRFdhEs7WEerAB3Id3Fox9EJDernp9vumQKBgQDDJ9eTenXOr2lqoanOSR/NDV1P3/klTUTpCQ7ozm8XlqjBPwQFqcns8MjQR8TlO72NGEX3oicRiFQhcDuL5HWqZc7QxAn23gvf2p8t++BuqHngSslC+aEUMsWGUinDZelsSSkZC5vhbIvm8ISBpotPj52C7FpLz94ybzzVtCMrUwKBgGjwkOVD1n8hLZ8cAlYnDIoiuK2Y+zDzHwqV6FbPNqlqvj9RU962FmT5MloW80/7RpArZlk4TFJvI3GK9BskTtxOy/ukeICPrtAus9xCnadb8WkhvnqD6wzxVyg9CIxH6d0RLFPA2cSxWq7lY4m8ytacP7TJyvMjTW7q6OSQGPNZAoGAQQ6mmLoq3NM3V7aZI7s8rPIsyrAARK59p944GOAI32Dyo5Puo8sq2n8ZuRLJF800J361m8s/lEvMLBtEzbwN2RBC8KJc/BS/mG2c407hrMLGgbryABd+LdrHekGvd173oeJm/sEY4FEa6ZuCENwVfKgNw2ZKgEjMXXi6e4Pmafk="; + /* + * 支付宝公钥 + **/ + public static final String APP_PUB_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkPr/2sjg6tLpLxGQ0lT8za7wONaeJA/g6bz77+R9rw5LcoRjohHellKBv5fFys/EOK3vq1tOC5zritvv42AC2u9sZjRUg5nUQ9/K7xeOf36OmaGVHmhsKAnJA/PFODvhzdww/sxNi/aBMspPZrNyporPUpuDEMIsApHBmNhhDRONirmHIL2P6nJKOLcVN026RcfF2zEWvzaNSIf3b+cEpxyKHDHEHgTUOydod0eqU0QeDE8s5cKhhNpMkbpnmnHU2ulngoMyqAeJNFSWIYBpTCYFFqIrEKtDZwZuj6XwZVLkmcZ4JYeYyqRPKWUBTsm87d6cslobegd/Gm0Jwbl5twIDAQAB"; + /** + * 商户生成签名 + **/ + public static final String SIGN_TYPE = "RSA2"; + /** + * 字符编码 + **/ + public static final String CHARSET = "UTF-8"; + /** + * 返回参数 + **/ + public static final String FORMAT = "json"; + + private volatile static AlipayClient instance = null; + + /** + * 单例模式获取,双重检查校验 + **/ + public static AlipayClient getInstance() { + if (instance == null) { + synchronized (AliPayConfig.class) { + if (instance == null) { + instance = new DefaultAlipayClient(PAY_GATEWAY, APPID, APP_PRI_KEY, FORMAT, CHARSET, APP_PUB_KEY, SIGN_TYPE); + } + } + } + return instance; + } +} diff --git a/src/main/java/com/ruoyi/system/pay/config/OrderQueueConfig.java b/src/main/java/com/ruoyi/system/pay/config/OrderQueueConfig.java new file mode 100644 index 0000000..692f0e5 --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/config/OrderQueueConfig.java @@ -0,0 +1,67 @@ +package com.ruoyi.system.pay.config; + +import org.springframework.amqp.core.Binding; +import org.springframework.amqp.core.BindingBuilder; +import org.springframework.amqp.core.DirectExchange; +import org.springframework.amqp.core.Queue; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Larry + * @time: 2024/5/14 15:03 + * @description: 订单消息队列配置 + */ +@Configuration +public class OrderQueueConfig { + + @Bean + public Queue orderDelayQueue() { + Map config = new HashMap<>(); + //支付单每30秒检测一次 message在该队列queue的存活时间最大为30秒 + config.put("x-message-ttl", 30000); + //x-dead-letter-exchange参数是设置该队列的死信交换器(DLX) + config.put("x-dead-letter-exchange", "orderDeadExchange"); + //x-dead-letter-routing-key参数是给这个DLX指定路由键 + config.put("x-dead-letter-routing-key", "order-dead"); + // 返回QueueA实例 + return new Queue("order-delay-queue", true, true, false, config); + } + + + @Bean + public DirectExchange directExchangeOrderDelay() { + return new DirectExchange("directExchangeOrderDelay"); + } + + + @Bean + public Binding bindingA() { + return BindingBuilder + .bind(orderDelayQueue()) + .to(directExchangeOrderDelay()) + .with("make-order"); + } + + + @Bean + public Queue orderDeadQueue() { + return new Queue("order-dead-queue"); + } + + @Bean + public DirectExchange orderDeadExchange() { + return new DirectExchange("orderDeadExchange"); + } + + @Bean + public Binding bindingB() { + return BindingBuilder + .bind(orderDeadQueue()) + .to(orderDeadExchange()) + .with("order-dead"); + } +} diff --git a/src/main/java/com/ruoyi/system/pay/config/PayUrlConfig.java b/src/main/java/com/ruoyi/system/pay/config/PayUrlConfig.java new file mode 100644 index 0000000..ea8aed1 --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/config/PayUrlConfig.java @@ -0,0 +1,21 @@ +package com.ruoyi.system.pay.config;//package com.muta.pay.config; +// +//import lombok.Data; +//import org.springframework.beans.factory.annotation.Value; +//import org.springframework.context.annotation.Configuration; +// +///** +// * @ClassName PayUrlConfig +// * @Author Larry +// * @create 2024/5/17 17:24 +// */ +//@Configuration +//@Data +//public class PayUrlConfig { +// @Value("${alipay.success_return_url}") +// private String alipaySuccessReturnUrl; +// +// @Value("${alipay.callback_url}") +// private String callbackUrl; +// +//} diff --git a/src/main/java/com/ruoyi/system/pay/constant/PayConstant.java b/src/main/java/com/ruoyi/system/pay/constant/PayConstant.java new file mode 100644 index 0000000..ce685b4 --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/constant/PayConstant.java @@ -0,0 +1,15 @@ +package com.ruoyi.system.pay.constant; + +/** + * @author: Larry + * @Date: 2024 /06 /02 / 15:39 + * @Description: + */ +public class PayConstant { + public static final Integer SUCCESS = 1; + //钱不够 其它 + public static final Integer FAIL = 2; + public static final Integer WAIT = 3; + public static final Integer OVERTIME = 4; + +} diff --git a/src/main/java/com/ruoyi/system/pay/domain/OrderEntity.java b/src/main/java/com/ruoyi/system/pay/domain/OrderEntity.java new file mode 100644 index 0000000..369153f --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/domain/OrderEntity.java @@ -0,0 +1,55 @@ +package com.ruoyi.system.pay.domain; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @author 33 + * @time: 2024/3/7 14:49 + * @description: 支付单信息 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@TableName("orders") +public class OrderEntity implements Serializable { + /** + * 自增的ID + */ + private Long id; + /** + * 订单编号 + */ + private String outTradeNo; + /** + * 商品id + */ + private Long productId; + /** + * 创建时间 + */ + private Date createTime; + /** + * 用户id + */ + private Long userId; + /** + * 支付状态 + */ + private Integer payStatus; + +// /** +// * 支付渠道 +// */ +// private String payChannel; + + +} diff --git a/src/main/java/com/ruoyi/system/pay/domain/dto/PayDTO.java b/src/main/java/com/ruoyi/system/pay/domain/dto/PayDTO.java new file mode 100644 index 0000000..48aed6a --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/domain/dto/PayDTO.java @@ -0,0 +1,24 @@ +package com.ruoyi.system.pay.domain.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * @author: Larry + * @Date: 2024 /05 /25 / 19:36 + * @Description: + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PayDTO { + private String title; + private BigDecimal count; + private String payStatus; + private String payChannel; +} diff --git a/src/main/java/com/ruoyi/system/pay/mapper/OrderMapper.java b/src/main/java/com/ruoyi/system/pay/mapper/OrderMapper.java new file mode 100644 index 0000000..b319521 --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/mapper/OrderMapper.java @@ -0,0 +1,18 @@ +package com.ruoyi.system.pay.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.pay.domain.OrderEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author: Larry + * @Date: 2024 /05 /25 / 21:53 + * @Description: + */ +@Mapper +public interface OrderMapper extends BaseMapper { + +// List list(SysUser sysUser); + + +} diff --git a/src/main/java/com/ruoyi/system/pay/mq/listener/OrderAfterListener.java b/src/main/java/com/ruoyi/system/pay/mq/listener/OrderAfterListener.java new file mode 100644 index 0000000..f7be60c --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/mq/listener/OrderAfterListener.java @@ -0,0 +1,56 @@ +package com.ruoyi.system.pay.mq.listener; + +import cn.hutool.json.JSONUtil; +import com.muta.ai.domain.MessageEntity; +import com.muta.common.utils.SecurityUtils; +import com.muta.pay.constant.PayConstant; +import com.muta.pay.domain.OrderEntity; +import com.muta.pay.service.IOrderService; +import com.muta.trade.domain.PayLog; +import com.muta.trade.domain.Product; +import com.muta.trade.service.IPayLogService; +import com.muta.trade.service.IProductService; +import com.rabbitmq.client.Channel; +import org.apache.catalina.security.SecurityUtil; +import org.springframework.amqp.rabbit.annotation.RabbitHandler; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.core.Ordered; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.Calendar; +import java.util.Date; + +/** + * @author: Larry + * @Date: 2024 /05 /12 / 20:52 + * @Description: + */ + +public class OrderAfterListener { + @Resource + private IOrderService orderService; + @Resource + private IPayLogService payLogService; + @Resource + private IProductService productService; + @RabbitHandler + @RabbitListener(queues = "order-delay-queue") + public void listenMessage(String message, Channel channel){ + OrderEntity orderEntity = JSONUtil.toBean(message, OrderEntity.class); + if(orderEntity.getPayStatus().equals(PayConstant.WAIT)){ + Product product = productService.selectProductById(orderEntity.getProductId()); + PayLog payLog = PayLog + .builder() + .userId(orderEntity.getUserId()) + .outTradeNo(orderEntity.getOutTradeNo()) + .title(product.getTitle()) + .username(SecurityUtils.getUsername()) + .payStatus(PayConstant.OVERTIME) + .payChannel("支付宝--电脑网站支付") + .payAmount(BigDecimal.valueOf(product.getPrice())) + .build(); + payLogService.insertPay(payLog); + } + } +} diff --git a/src/main/java/com/ruoyi/system/pay/mq/sender/OrderDeadTimeSender.java b/src/main/java/com/ruoyi/system/pay/mq/sender/OrderDeadTimeSender.java new file mode 100644 index 0000000..b0a1ce3 --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/mq/sender/OrderDeadTimeSender.java @@ -0,0 +1,9 @@ +package com.ruoyi.system.pay.mq.sender; + +/** + * @author: Larry + * @Date: 2024 /06 /10 / 17:57 + * @Description: + */ +public class OrderDeadTimeSender { +} diff --git a/src/main/java/com/ruoyi/system/pay/service/IAliPayService.java b/src/main/java/com/ruoyi/system/pay/service/IAliPayService.java new file mode 100644 index 0000000..b0d0362 --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/service/IAliPayService.java @@ -0,0 +1,15 @@ +package com.ruoyi.system.pay.service; + +import com.alipay.api.AlipayApiException; + +import java.math.BigDecimal; + +/** + * @author: Larry + * @Date: 2024 /05 /25 / 21:08 + * @Description: + */ +public interface IAliPayService { + public String genPayOrder(Long productId) throws AlipayApiException; + public String queryOrderStatus(String outTradeNo) throws AlipayApiException; +} diff --git a/src/main/java/com/ruoyi/system/pay/service/IOrderService.java b/src/main/java/com/ruoyi/system/pay/service/IOrderService.java new file mode 100644 index 0000000..535b1cf --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/service/IOrderService.java @@ -0,0 +1,23 @@ +package com.ruoyi.system.pay.service; + +import com.muta.pay.domain.OrderEntity; +import org.aspectj.weaver.ast.Or; + +import java.math.BigDecimal; +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /05 /25 / 21:52 + * @Description: + */ +public interface IOrderService { + void PaySuccess(String outTradeNo); + //延时任务 + void PayOverTime(String outTradeNo); + + void GenOrder(String outTradeNo, Long productId); + + + List list(); +} diff --git a/src/main/java/com/ruoyi/system/pay/service/impl/AliPayServiceImpl.java b/src/main/java/com/ruoyi/system/pay/service/impl/AliPayServiceImpl.java new file mode 100644 index 0000000..d622035 --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/service/impl/AliPayServiceImpl.java @@ -0,0 +1,134 @@ +package com.ruoyi.system.pay.service.impl; + +import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayClient; +import com.alipay.api.AlipayConstants; +import com.alipay.api.domain.AlipayTradePagePayModel; +import com.alipay.api.domain.AlipayTradeQueryModel; +import com.alipay.api.internal.util.AlipaySignature; +import com.alipay.api.request.AlipayTradePagePayRequest; +import com.alipay.api.request.AlipayTradeQueryRequest; +import com.alipay.api.response.AlipayTradePagePayResponse; +import com.alipay.api.response.AlipayTradeQueryResponse; +import com.muta.log.service.IIntegralLogService; +import com.muta.pay.config.AliPayConfig; +import com.muta.pay.service.IAliPayService; +import com.muta.pay.service.IOrderService; +import com.muta.pay.util.OutTradeNoUtil; +import com.muta.system.service.IVipService; +import com.muta.trade.domain.Product; +import com.muta.trade.service.IProductService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /05 /25 / 17:51 + * @Description: + */ +@Service +public class AliPayServiceImpl implements IAliPayService { + @Resource + private IOrderService orderService; + @Resource + private IIntegralLogService iIntegralLogService; + @Resource + private IVipService vipService; + @Resource + private IProductService productService; + + @Override + public String genPayOrder(Long productId) throws AlipayApiException { + // 初始化SDK + AlipayClient alipayClient = AliPayConfig.getInstance(); + // 构造请求参数以调用接口 + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); + AlipayTradePagePayModel model = new AlipayTradePagePayModel(); + LocalDateTime now = LocalDateTime.now(); + // 在当前时间上加上30分钟 + LocalDateTime futureTime = now.plusMinutes(30); + // 定义日期时间格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + // 格式化futureTime为字符串 + String timeExpire = futureTime.format(formatter); + // 假设model是某个对象,它有一个setTimeExpire方法 + model.setTimeExpire(timeExpire); + Product product = productService.getById(productId); + // 设置订单标题 + model.setSubject(product.getTitle()); + model.setTotalAmount(String.valueOf(product.getPrice()/100)); + // 设置产品码 + model.setProductCode("FAST_INSTANT_TRADE_PAY"); + // 设置PC扫码支付的方式 + model.setQrPayMode("2"); + // 设置请求后页面的集成方式 + model.setIntegrationType("PCWEB"); +// // 设置商户自定义二维码宽度 +// model.setQrcodeWidth(100L); + // 设置商户订单号 + String outTradeNo= OutTradeNoUtil.genOutTrade(); + model.setOutTradeNo(outTradeNo); + System.out.println("xxxxxx"); + System.out.println(outTradeNo); + request.setBizModel(model); + request.setNotifyUrl("http://lesong.nas.cpolar.cn/trade/notify"); + request.setReturnUrl("https://lesong-app.nas.cpolar.cn/shop"); + //设置并记录初始订单 +// String payChannel = "支付宝-电脑网站支付"; + orderService.GenOrder(outTradeNo,productId); + AlipayTradePagePayResponse response = alipayClient.pageExecute(request, "POST"); + // 如果需要返回GET请求,请使用 + // AlipayTradePagePayResponse response = alipayClient.pageExecute(request, "GET"); + String pageRedirectionData = response.getBody(); + System.out.println(pageRedirectionData); + return pageRedirectionData; + } + + + public String queryOrderStatus(String outTradeNo) throws AlipayApiException { + // 初始化SDK + AlipayClient alipayClient = AliPayConfig.getInstance(); + + // 构造请求参数以调用接口 + AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); + AlipayTradeQueryModel model = new AlipayTradeQueryModel(); + + // 设置订单支付时传入的商户订单号 + model.setOutTradeNo(outTradeNo); + orderService.PaySuccess(outTradeNo); + + // 设置查询选项 + List queryOptions = new ArrayList(); + queryOptions.add("trade_settle_info"); + model.setQueryOptions(queryOptions); + + request.setBizModel(model); + AlipayTradeQueryResponse response = alipayClient.execute(request); + System.out.println(response.getBody()); + if (response.isSuccess()) { + System.out.println("调用成功"); + return "success"; + } else { + System.out.println("调用失败"); + return "fail"; + // sdk版本是"4.38.0.ALL"及以上,可以参考下面的示例获取诊断链接 + // String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(response); + // System.out.println(diagnosisUrl); + } + } + + + + + + + + + +} diff --git a/src/main/java/com/ruoyi/system/pay/service/impl/OrderServiceImpl.java b/src/main/java/com/ruoyi/system/pay/service/impl/OrderServiceImpl.java new file mode 100644 index 0000000..784bf4f --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/service/impl/OrderServiceImpl.java @@ -0,0 +1,127 @@ +package com.ruoyi.system.pay.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.muta.common.enums.ShopType; +import com.muta.common.utils.SecurityUtils; +import com.muta.distribution.service.DistributionService; +import com.muta.log.service.impl.ShopIntegralLogServiceImpl; +import com.muta.pay.constant.PayConstant; +import com.muta.pay.domain.OrderEntity; +import com.muta.pay.service.IOrderService; +import com.muta.pay.mapper.OrderMapper; +import com.muta.system.service.IUserExtraService; +import com.muta.system.service.IVipService; +import com.muta.trade.domain.PayLog; +import com.muta.trade.domain.Product; +import com.muta.trade.service.IPayLogService; +import com.muta.trade.service.IProductService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Objects; + +/** + * @author: Larry + * @Date: 2024 /05 /25 / 21:52 + * @Description: + */ +@Service +public class OrderServiceImpl implements IOrderService { + @Resource + private IProductService productService; + @Resource + private IPayLogService payLogService; + @Resource + private IVipService vipService; + @Resource + private ShopIntegralLogServiceImpl shopIntegralLogService; + @Resource + private IUserExtraService userExtraService; + @Override + public void PayOverTime(String outTradeNo) { + updateStatus(outTradeNo,PayConstant.OVERTIME); + } + + @Override + @Transactional + public void PaySuccess(String outTradeNo) { + updateStatus(outTradeNo,PayConstant.SUCCESS); + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(outTradeNo!=null,OrderEntity::getOutTradeNo,outTradeNo); + OrderEntity orderEntity = orderMapper.selectOne(lambdaQueryWrapper); + //发货 + Product product = productService.selectProductById(orderEntity.getProductId()); + System.err.println("发货"+product); + + deliverGood(product,orderEntity.getUserId()); + //分销 + distributionService.benefit(product.getPrice().doubleValue()); + //生成支付记录 + PayLog payLog = PayLog.builder() + .payTime(new Date()) + //单位是分 + .payAmount(BigDecimal.valueOf(product.getPrice())) + .payStatus(PayConstant.SUCCESS) + .payChannel("支付宝-电脑网站支付") + .username(SecurityUtils.getUsername()) + .userId(orderEntity.getUserId()) + .title(product.getTitle()) + .outTradeNo(outTradeNo) + .build(); + payLogService.insertPay(payLog); + //修改订单状态 + updateStatus(outTradeNo,PayConstant.SUCCESS); + } + + @Resource + private OrderMapper orderMapper; + @Resource + private DistributionService distributionService; + //延时任务 + + private void updateStatus(String outTradeNo,Integer status) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(outTradeNo!=null,OrderEntity::getOutTradeNo,outTradeNo); + OrderEntity orderEntity = orderMapper.selectOne(lambdaQueryWrapper); + if(Objects.equals(orderEntity.getPayStatus(), PayConstant.WAIT)){ + orderEntity.setPayStatus(status); + orderMapper.updateById(orderEntity); + } + } + + + @Override + public void GenOrder(String outTradeNo,Long productId){ + OrderEntity order = OrderEntity.builder() + .userId(SecurityUtils.getUserId()) + .outTradeNo(outTradeNo) + .productId(productId) + .createTime(new Date()) + .payStatus(PayConstant.WAIT) + .build(); + orderMapper.insert(order); + } + + + + @Override + public List list() { + return orderMapper.selectList(null); + } + private void deliverGood(Product product,Long userId){ + //如果是积分直购 + if(product.getType().equals(ShopType.INTEGRAL.getCode())){ + userExtraService.addIntegral(product.getValue(),userId); + shopIntegralLogService.insertShop(product.getValue()); + } + //如果是充值vip + else{ + System.err.println("vip--"); + vipService.addVipDate(userId,product.getType(),product.getValue()); + } + } +} diff --git a/src/main/java/com/ruoyi/system/pay/task/PayTask.java b/src/main/java/com/ruoyi/system/pay/task/PayTask.java new file mode 100644 index 0000000..6c29222 --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/task/PayTask.java @@ -0,0 +1,28 @@ +package com.ruoyi.system.pay.task; +import com.muta.pay.domain.OrderEntity; +import com.muta.pay.service.IOrderService; +import org.springframework.scheduling.annotation.Scheduled; + +import javax.annotation.Resource; +import java.util.List; + + +/** + * @author: Larry + * @Date: 2024 /06 /07 / 14:35 + * @Description: + */ +public class PayTask { + @Resource + private IOrderService orderService; + @Scheduled(cron = "0 0 0 1 * ?") + public void checkPay() { + List orderEntityList = orderService.list(); + orderEntityList.forEach( + orderEntity -> { + + } + ); + + } +} diff --git a/src/main/java/com/ruoyi/system/pay/util/OutTradeNoUtil.java b/src/main/java/com/ruoyi/system/pay/util/OutTradeNoUtil.java new file mode 100644 index 0000000..8482ccd --- /dev/null +++ b/src/main/java/com/ruoyi/system/pay/util/OutTradeNoUtil.java @@ -0,0 +1,24 @@ +package com.ruoyi.system.pay.util; + +import com.muta.common.utils.SecurityUtils; +import com.muta.common.utils.uuid.UUID; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * @author: Larry + * @Date: 2024 /05 /25 / 20:46 + * @Description: 根据当前时间戳和uuid生成唯一订单号 + */ +public class OutTradeNoUtil { + public static String genOutTrade(){ + LocalDateTime dateTime = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); + String date = dateTime.format(formatter); + System.out.println(date); // 输出格式化后的日期时间字符 + String uuid = String.valueOf(UUID.fastUUID()); + return date+uuid; + } + +} diff --git a/src/main/java/com/ruoyi/system/payConfig/domain/entity/Alipay.java b/src/main/java/com/ruoyi/system/payConfig/domain/entity/Alipay.java new file mode 100644 index 0000000..1c8d9ac --- /dev/null +++ b/src/main/java/com/ruoyi/system/payConfig/domain/entity/Alipay.java @@ -0,0 +1,26 @@ +package com.ruoyi.system.payConfig.domain.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Alipay { + private Long id; + private String appId; + private String keyType; + private String privateKey; + private String alipayPublicKey; + private Long configId; + + + +} + diff --git a/src/main/java/com/ruoyi/system/payConfig/domain/entity/PayConfig.java b/src/main/java/com/ruoyi/system/payConfig/domain/entity/PayConfig.java new file mode 100644 index 0000000..8b02398 --- /dev/null +++ b/src/main/java/com/ruoyi/system/payConfig/domain/entity/PayConfig.java @@ -0,0 +1,34 @@ +package com.ruoyi.system.payConfig.domain.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PayConfig { + + private Long id; + private String channelName; + private String channelCode; + private String availableChannels; + private String status; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime updateTime; + + private String operation; + private Integer isDel; + private Integer payWay; + @TableField(exist = false) + private Alipay alipay; +} diff --git a/src/main/java/com/ruoyi/system/payConfig/mapper/AlipayMapper.java b/src/main/java/com/ruoyi/system/payConfig/mapper/AlipayMapper.java new file mode 100644 index 0000000..20ff405 --- /dev/null +++ b/src/main/java/com/ruoyi/system/payConfig/mapper/AlipayMapper.java @@ -0,0 +1,14 @@ +package com.ruoyi.system.payConfig.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.payConfig.domain.entity.Alipay; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +@Mapper +public interface AlipayMapper extends BaseMapper { + + @Select("select * from alipay where config_id = #{id}") + Alipay getOne(Long id); + +} diff --git a/src/main/java/com/ruoyi/system/payConfig/mapper/PayConfigMapper.java b/src/main/java/com/ruoyi/system/payConfig/mapper/PayConfigMapper.java new file mode 100644 index 0000000..f7c8d1b --- /dev/null +++ b/src/main/java/com/ruoyi/system/payConfig/mapper/PayConfigMapper.java @@ -0,0 +1,26 @@ +package com.ruoyi.system.payConfig.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.payConfig.domain.entity.PayConfig; +import org.apache.ibatis.annotations.*; + +import java.util.List; + +@Mapper +public interface PayConfigMapper { + @Insert("insert into pay_config (channel_name,channel_code, available_channels, status, create_time, update_time, pay_way) values (#{channelName}, #{channelCode}, #{availableChannels}, #{status}, #{createTime}, #{updateTime}, #{payWay})") + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") + void insertPayConfig(PayConfig payConfig); + + @Update("update pay_config set channel_name = #{channelName}, channel_code = #{channelCode}, available_channels = #{availableChannels}, status = #{status}, create_time = #{createTime}, update_time = #{updateTime}, pay_way = #{payWay} where id = #{id}") + void updatePayConfig(PayConfig payConfig); + + @Update("update pay_config set is_del = 1 where id = #{id}") + void delete(Long id); + + @Select("select * from pay_config where id = #{id}") + PayConfig show(Long id); + + @Select("select * from pay_config where is_del = 0") + List list(); +} diff --git a/src/main/java/com/ruoyi/system/payConfig/service/PayConfigService.java b/src/main/java/com/ruoyi/system/payConfig/service/PayConfigService.java new file mode 100644 index 0000000..b56edd2 --- /dev/null +++ b/src/main/java/com/ruoyi/system/payConfig/service/PayConfigService.java @@ -0,0 +1,23 @@ +package com.ruoyi.system.payConfig.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.payConfig.domain.entity.Alipay; +import com.muta.payConfig.domain.entity.PayConfig; + +import java.util.List; + +public interface PayConfigService { + + + void del(Long id); + + Alipay getInfoByWay(Long id); + + void add(PayConfig payConfig); + + void updatePayConfig(PayConfig payConfig); + + PayConfig getOne(Long id); + + List list(); +} diff --git a/src/main/java/com/ruoyi/system/payConfig/service/impl/PayConfigServiceImpl.java b/src/main/java/com/ruoyi/system/payConfig/service/impl/PayConfigServiceImpl.java new file mode 100644 index 0000000..2693045 --- /dev/null +++ b/src/main/java/com/ruoyi/system/payConfig/service/impl/PayConfigServiceImpl.java @@ -0,0 +1,72 @@ +package com.ruoyi.system.payConfig.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.payConfig.domain.entity.Alipay; +import com.muta.payConfig.domain.entity.PayConfig; +import com.muta.payConfig.mapper.AlipayMapper; +import com.muta.payConfig.mapper.PayConfigMapper; +import com.muta.payConfig.service.PayConfigService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service +@Slf4j +public class PayConfigServiceImpl implements PayConfigService { + + @Resource + private PayConfigMapper payConfigMapper; + + @Resource + private AlipayMapper alipayMapper; + + @Override + public void del(Long id) { + payConfigMapper.delete(id); + } + + @Override + public Alipay getInfoByWay(Long id) { + return alipayMapper.getOne(id); + } + + @Override + public void add(PayConfig payConfig) { + + payConfigMapper.insertPayConfig(payConfig); + + if (payConfig.getPayWay() == 1) { + Alipay alipay = payConfig.getAlipay(); + alipay.setConfigId(payConfig.getId()); + payConfig.setAlipay(alipay); + log.info("{}", payConfig); + + alipayMapper.insert(payConfig.getAlipay()); + } + + } + + @Override + public void updatePayConfig(PayConfig payConfig) { + log.info("{}", payConfig); + payConfigMapper.updatePayConfig(payConfig); + if (payConfig.getPayWay() == 1) { + + alipayMapper.update(payConfig.getAlipay(), new LambdaQueryWrapper().eq(Alipay::getConfigId, payConfig.getId())); + } + } + + @Override + public PayConfig getOne(Long id) { + PayConfig show = payConfigMapper.show(id); + return show; + } + + @Override + public List list() { + return payConfigMapper.list(); + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/CommonSetting.java b/src/main/java/com/ruoyi/system/system/domain/CommonSetting.java new file mode 100644 index 0000000..3dcbd38 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/CommonSetting.java @@ -0,0 +1,42 @@ +package com.ruoyi.system.system.domain; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import java.util.Date; +import com.baomidou.mybatisplus.annotation.TableId; +import java.io.Serializable; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * 设置表 + *

+ * + * @author cleveronion + * @since 2024-04-22 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("common_setting") +public class CommonSetting implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + private String name; + + private String showName; + + private String value; + + private String remark; + + private Date updateTime; + + private String updateBy; + + private String other; +} diff --git a/src/main/java/com/ruoyi/system/system/domain/FileConfig.java b/src/main/java/com/ruoyi/system/system/domain/FileConfig.java new file mode 100644 index 0000000..7216556 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/FileConfig.java @@ -0,0 +1,47 @@ +package com.ruoyi.system.system.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.muta.common.core.MutaBaseEntity; +import lombok.*; + +/** + * @author: Larry + * @Date: 2024 /04 /21 / 13:47 + * @Description: 文件存储配置信息类 + */ + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class FileConfig{ + /** + * 主键 + */ + @TableId(type = IdType.AUTO) + private Integer id; + /** + * 存储服务名称 + */ + private String name; + /** + * key + */ + private String accessKeyId; + /** + * 密钥 + */ + private String accessKeySecret; + /** + * 桶名称 + */ + private String bucket; + /** + * 服务地区 + */ + private String region; + + private String endpoint; + +} diff --git a/src/main/java/com/ruoyi/system/system/domain/Message.java b/src/main/java/com/ruoyi/system/system/domain/Message.java new file mode 100644 index 0000000..f06f92b --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/Message.java @@ -0,0 +1,54 @@ +package com.ruoyi.system.system.domain; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import java.util.Date; +import com.baomidou.mybatisplus.annotation.TableId; +import java.io.Serializable; + +import com.muta.common.core.MutaBaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * + *

+ * + * @author fly + * @since 2024-04-18 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("message") +public class Message extends MutaBaseEntity implements Serializable { + + private static final long serialVersionUID = 1L; + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + private Long userId; + + /** + * user-用户提问 system-ai回答 + */ + private String role; + + /** + * 内容 + */ + private String content; + + /** + * 最大字符数 + */ + private Integer maxTokens; + + /** + * 模型id + */ + private Integer modelId; + + +} diff --git a/src/main/java/com/ruoyi/system/system/domain/Model.java b/src/main/java/com/ruoyi/system/system/domain/Model.java new file mode 100644 index 0000000..385f4ae --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/Model.java @@ -0,0 +1,60 @@ +package com.ruoyi.system.system.domain; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import java.util.Date; +import com.baomidou.mybatisplus.annotation.TableId; +import java.io.Serializable; + +import com.muta.common.core.MutaBaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + *

+ * + *

+ * + * @author fly + * @since 2024-04-18 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("model") +public class Model extends MutaBaseEntity implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + /** + * 模型名称 + */ + private String name; + + /** + * 单次对话花费 + */ + private Integer charge; + + /** + * 需要会员等级 + */ + private String grade; + + /** + * 可携带历史聊天数量 + */ + private Integer carryCount; + + /** + * 模型类型:聊天|绘画 + */ + private Integer type; + + +} diff --git a/src/main/java/com/ruoyi/system/system/domain/PageResult.java b/src/main/java/com/ruoyi/system/system/domain/PageResult.java new file mode 100644 index 0000000..b5e3584 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/PageResult.java @@ -0,0 +1,18 @@ +package com.ruoyi.system.system.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PageResult { + private Long total; + private List list; +} diff --git a/src/main/java/com/ruoyi/system/system/domain/Signin.java b/src/main/java/com/ruoyi/system/system/domain/Signin.java new file mode 100644 index 0000000..a943062 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/Signin.java @@ -0,0 +1,21 @@ +package com.ruoyi.system.system.domain; + +import com.muta.common.core.MutaBaseEntity; +import com.muta.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Signin extends MutaBaseEntity { + + private Long id; + private Long userId; + private String ip; + private Integer count; + private String status; +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SigninLog.java b/src/main/java/com/ruoyi/system/system/domain/SigninLog.java new file mode 100644 index 0000000..66aa8d3 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SigninLog.java @@ -0,0 +1,26 @@ +package com.ruoyi.system.system.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class SigninLog { + + private Long id; + private String userName; + private String ip; + private String status; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime signinTime; + private Long userId; +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SigninTable.java b/src/main/java/com/ruoyi/system/system/domain/SigninTable.java new file mode 100644 index 0000000..8469898 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SigninTable.java @@ -0,0 +1,21 @@ +package com.ruoyi.system.system.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; +import java.util.Date; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class SigninTable { + + @JsonFormat(pattern = "yyyy-MM-dd") + private LocalDate date; + private String status; +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SmsLogin.java b/src/main/java/com/ruoyi/system/system/domain/SmsLogin.java new file mode 100644 index 0000000..2be83f8 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SmsLogin.java @@ -0,0 +1,16 @@ +package com.ruoyi.system.system.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class SmsLogin { + + private String phoneNumber; + private String code; +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SysCache.java b/src/main/java/com/ruoyi/system/system/domain/SysCache.java new file mode 100644 index 0000000..845f3d2 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SysCache.java @@ -0,0 +1,81 @@ +package com.ruoyi.system.system.domain; + +import com.muta.common.utils.StringUtils; + +/** + * 缓存信息 + * + * @author mutaai + */ +public class SysCache +{ + /** 缓存名称 */ + private String cacheName = ""; + + /** 缓存键名 */ + private String cacheKey = ""; + + /** 缓存内容 */ + private String cacheValue = ""; + + /** 备注 */ + private String remark = ""; + + public SysCache() + { + + } + + public SysCache(String cacheName, String remark) + { + this.cacheName = cacheName; + this.remark = remark; + } + + public SysCache(String cacheName, String cacheKey, String cacheValue) + { + this.cacheName = StringUtils.replace(cacheName, ":", ""); + this.cacheKey = StringUtils.replace(cacheKey, cacheName, ""); + this.cacheValue = cacheValue; + } + + public String getCacheName() + { + return cacheName; + } + + public void setCacheName(String cacheName) + { + this.cacheName = cacheName; + } + + public String getCacheKey() + { + return cacheKey; + } + + public void setCacheKey(String cacheKey) + { + this.cacheKey = cacheKey; + } + + public String getCacheValue() + { + return cacheValue; + } + + public void setCacheValue(String cacheValue) + { + this.cacheValue = cacheValue; + } + + public String getRemark() + { + return remark; + } + + public void setRemark(String remark) + { + this.remark = remark; + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SysConfig.java b/src/main/java/com/ruoyi/system/system/domain/SysConfig.java new file mode 100644 index 0000000..eec2142 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SysConfig.java @@ -0,0 +1,111 @@ +package com.ruoyi.system.system.domain; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.muta.common.annotation.Excel; +import com.muta.common.annotation.Excel.ColumnType; +import com.muta.common.core.domain.BaseEntity; + +/** + * 参数配置表 sys_config + * + * @author mutaai + */ +public class SysConfig extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 参数主键 */ + @Excel(name = "参数主键", cellType = ColumnType.NUMERIC) + private Long configId; + + /** 参数名称 */ + @Excel(name = "参数名称") + private String configName; + + /** 参数键名 */ + @Excel(name = "参数键名") + private String configKey; + + /** 参数键值 */ + @Excel(name = "参数键值") + private String configValue; + + /** 系统内置(Y是 N否) */ + @Excel(name = "系统内置", readConverterExp = "Y=是,N=否") + private String configType; + + public Long getConfigId() + { + return configId; + } + + public void setConfigId(Long configId) + { + this.configId = configId; + } + + @NotBlank(message = "参数名称不能为空") + @Size(min = 0, max = 100, message = "参数名称不能超过100个字符") + public String getConfigName() + { + return configName; + } + + public void setConfigName(String configName) + { + this.configName = configName; + } + + @NotBlank(message = "参数键名长度不能为空") + @Size(min = 0, max = 100, message = "参数键名长度不能超过100个字符") + public String getConfigKey() + { + return configKey; + } + + public void setConfigKey(String configKey) + { + this.configKey = configKey; + } + + @NotBlank(message = "参数键值不能为空") + @Size(min = 0, max = 500, message = "参数键值长度不能超过500个字符") + public String getConfigValue() + { + return configValue; + } + + public void setConfigValue(String configValue) + { + this.configValue = configValue; + } + + public String getConfigType() + { + return configType; + } + + public void setConfigType(String configType) + { + this.configType = configType; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("configId", getConfigId()) + .append("configName", getConfigName()) + .append("configKey", getConfigKey()) + .append("configValue", getConfigValue()) + .append("configType", getConfigType()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SysLogininfor.java b/src/main/java/com/ruoyi/system/system/domain/SysLogininfor.java new file mode 100644 index 0000000..8ceca18 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SysLogininfor.java @@ -0,0 +1,144 @@ +package com.ruoyi.system.system.domain; + +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.muta.common.annotation.Excel; +import com.muta.common.annotation.Excel.ColumnType; +import com.muta.common.core.domain.BaseEntity; + +/** + * 系统访问记录表 sys_logininfor + * + * @author mutaai + */ +public class SysLogininfor extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** ID */ + @Excel(name = "序号", cellType = ColumnType.NUMERIC) + private Long infoId; + + /** 用户账号 */ + @Excel(name = "用户账号") + private String userName; + + /** 登录状态 0成功 1失败 */ + @Excel(name = "登录状态", readConverterExp = "0=成功,1=失败") + private String status; + + /** 登录IP地址 */ + @Excel(name = "登录地址") + private String ipaddr; + + /** 登录地点 */ + @Excel(name = "登录地点") + private String loginLocation; + + /** 浏览器类型 */ + @Excel(name = "浏览器") + private String browser; + + /** 操作系统 */ + @Excel(name = "操作系统") + private String os; + + /** 提示消息 */ + @Excel(name = "提示消息") + private String msg; + + /** 访问时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "访问时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date loginTime; + + public Long getInfoId() + { + return infoId; + } + + public void setInfoId(Long infoId) + { + this.infoId = infoId; + } + + public String getUserName() + { + return userName; + } + + public void setUserName(String userName) + { + this.userName = userName; + } + + public String getStatus() + { + return status; + } + + public void setStatus(String status) + { + this.status = status; + } + + public String getIpaddr() + { + return ipaddr; + } + + public void setIpaddr(String ipaddr) + { + this.ipaddr = ipaddr; + } + + public String getLoginLocation() + { + return loginLocation; + } + + public void setLoginLocation(String loginLocation) + { + this.loginLocation = loginLocation; + } + + public String getBrowser() + { + return browser; + } + + public void setBrowser(String browser) + { + this.browser = browser; + } + + public String getOs() + { + return os; + } + + public void setOs(String os) + { + this.os = os; + } + + public String getMsg() + { + return msg; + } + + public void setMsg(String msg) + { + this.msg = msg; + } + + public Date getLoginTime() + { + return loginTime; + } + + public void setLoginTime(Date loginTime) + { + this.loginTime = loginTime; + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SysNotice.java b/src/main/java/com/ruoyi/system/system/domain/SysNotice.java new file mode 100644 index 0000000..acb4cca --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SysNotice.java @@ -0,0 +1,112 @@ +package com.ruoyi.system.system.domain; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.muta.common.core.domain.BaseEntity; +import com.muta.common.xss.Xss; + +/** + * 通知公告表 sys_notice + * + * @author mutaai + */ +public class SysNotice extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 公告ID */ + private Long noticeId; + + public Integer getSort() { + return sort; + } + + public void setSort(Integer sort) { + this.sort = sort; + } + + /** 公告标题 */ + private String noticeTitle; + + /** 公告类型(1通知 2公告) */ + private String noticeType; + + /** 公告内容 */ + private String noticeContent; + + /** 公告状态(0正常 1关闭) */ + private String status; + /** 排序 */ + private Integer sort; + + public Long getNoticeId() + { + return noticeId; + } + + public void setNoticeId(Long noticeId) + { + this.noticeId = noticeId; + } + + public void setNoticeTitle(String noticeTitle) + { + this.noticeTitle = noticeTitle; + } + + @Xss(message = "公告标题不能包含脚本字符") + @NotBlank(message = "公告标题不能为空") + @Size(min = 0, max = 50, message = "公告标题不能超过50个字符") + public String getNoticeTitle() + { + return noticeTitle; + } + + public void setNoticeType(String noticeType) + { + this.noticeType = noticeType; + } + + public String getNoticeType() + { + return noticeType; + } + + public void setNoticeContent(String noticeContent) + { + this.noticeContent = noticeContent; + } + + public String getNoticeContent() + { + return noticeContent; + } + + public void setStatus(String status) + { + this.status = status; + } + + public String getStatus() + { + return status; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("noticeId", getNoticeId()) + .append("noticeTitle", getNoticeTitle()) + .append("noticeType", getNoticeType()) + .append("noticeContent", getNoticeContent()) + .append("status", getStatus()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SysOperLog.java b/src/main/java/com/ruoyi/system/system/domain/SysOperLog.java new file mode 100644 index 0000000..6f74689 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SysOperLog.java @@ -0,0 +1,269 @@ +package com.ruoyi.system.system.domain; + +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.muta.common.annotation.Excel; +import com.muta.common.annotation.Excel.ColumnType; +import com.muta.common.core.domain.BaseEntity; + +/** + * 操作日志记录表 oper_log + * + * @author mutaai + */ +public class SysOperLog extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 日志主键 */ + @Excel(name = "操作序号", cellType = ColumnType.NUMERIC) + private Long operId; + + /** 操作模块 */ + @Excel(name = "操作模块") + private String title; + + /** 业务类型(0其它 1新增 2修改 3删除) */ + @Excel(name = "业务类型", readConverterExp = "0=其它,1=新增,2=修改,3=删除,4=授权,5=导出,6=导入,7=强退,8=生成代码,9=清空数据") + private Integer businessType; + + /** 业务类型数组 */ + private Integer[] businessTypes; + + /** 请求方法 */ + @Excel(name = "请求方法") + private String method; + + /** 请求方式 */ + @Excel(name = "请求方式") + private String requestMethod; + + /** 操作类别(0其它 1后台用户 2手机端用户) */ + @Excel(name = "操作类别", readConverterExp = "0=其它,1=后台用户,2=手机端用户") + private Integer operatorType; + + /** 操作人员 */ + @Excel(name = "操作人员") + private String operName; + + /** 部门名称 */ + @Excel(name = "部门名称") + private String deptName; + + /** 请求url */ + @Excel(name = "请求地址") + private String operUrl; + + /** 操作地址 */ + @Excel(name = "操作地址") + private String operIp; + + /** 操作地点 */ + @Excel(name = "操作地点") + private String operLocation; + + /** 请求参数 */ + @Excel(name = "请求参数") + private String operParam; + + /** 返回参数 */ + @Excel(name = "返回参数") + private String jsonResult; + + /** 操作状态(0正常 1异常) */ + @Excel(name = "状态", readConverterExp = "0=正常,1=异常") + private Integer status; + + /** 错误消息 */ + @Excel(name = "错误消息") + private String errorMsg; + + /** 操作时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") + private Date operTime; + + /** 消耗时间 */ + @Excel(name = "消耗时间", suffix = "毫秒") + private Long costTime; + + public Long getOperId() + { + return operId; + } + + public void setOperId(Long operId) + { + this.operId = operId; + } + + public String getTitle() + { + return title; + } + + public void setTitle(String title) + { + this.title = title; + } + + public Integer getBusinessType() + { + return businessType; + } + + public void setBusinessType(Integer businessType) + { + this.businessType = businessType; + } + + public Integer[] getBusinessTypes() + { + return businessTypes; + } + + public void setBusinessTypes(Integer[] businessTypes) + { + this.businessTypes = businessTypes; + } + + public String getMethod() + { + return method; + } + + public void setMethod(String method) + { + this.method = method; + } + + public String getRequestMethod() + { + return requestMethod; + } + + public void setRequestMethod(String requestMethod) + { + this.requestMethod = requestMethod; + } + + public Integer getOperatorType() + { + return operatorType; + } + + public void setOperatorType(Integer operatorType) + { + this.operatorType = operatorType; + } + + public String getOperName() + { + return operName; + } + + public void setOperName(String operName) + { + this.operName = operName; + } + + public String getDeptName() + { + return deptName; + } + + public void setDeptName(String deptName) + { + this.deptName = deptName; + } + + public String getOperUrl() + { + return operUrl; + } + + public void setOperUrl(String operUrl) + { + this.operUrl = operUrl; + } + + public String getOperIp() + { + return operIp; + } + + public void setOperIp(String operIp) + { + this.operIp = operIp; + } + + public String getOperLocation() + { + return operLocation; + } + + public void setOperLocation(String operLocation) + { + this.operLocation = operLocation; + } + + public String getOperParam() + { + return operParam; + } + + public void setOperParam(String operParam) + { + this.operParam = operParam; + } + + public String getJsonResult() + { + return jsonResult; + } + + public void setJsonResult(String jsonResult) + { + this.jsonResult = jsonResult; + } + + public Integer getStatus() + { + return status; + } + + public void setStatus(Integer status) + { + this.status = status; + } + + public String getErrorMsg() + { + return errorMsg; + } + + public void setErrorMsg(String errorMsg) + { + this.errorMsg = errorMsg; + } + + public Date getOperTime() + { + return operTime; + } + + public void setOperTime(Date operTime) + { + this.operTime = operTime; + } + + public Long getCostTime() + { + return costTime; + } + + public void setCostTime(Long costTime) + { + this.costTime = costTime; + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SysPost.java b/src/main/java/com/ruoyi/system/system/domain/SysPost.java new file mode 100644 index 0000000..a2ef755 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SysPost.java @@ -0,0 +1,124 @@ +package com.ruoyi.system.system.domain; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.muta.common.annotation.Excel; +import com.muta.common.annotation.Excel.ColumnType; +import com.muta.common.core.domain.BaseEntity; + +/** + * 岗位表 sys_post + * + * @author mutaai + */ +public class SysPost extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 岗位序号 */ + @Excel(name = "岗位序号", cellType = ColumnType.NUMERIC) + private Long postId; + + /** 岗位编码 */ + @Excel(name = "岗位编码") + private String postCode; + + /** 岗位名称 */ + @Excel(name = "岗位名称") + private String postName; + + /** 岗位排序 */ + @Excel(name = "岗位排序") + private Integer postSort; + + /** 状态(0正常 1停用) */ + @Excel(name = "状态", readConverterExp = "0=正常,1=停用") + private String status; + + /** 用户是否存在此岗位标识 默认不存在 */ + private boolean flag = false; + + public Long getPostId() + { + return postId; + } + + public void setPostId(Long postId) + { + this.postId = postId; + } + + @NotBlank(message = "岗位编码不能为空") + @Size(min = 0, max = 64, message = "岗位编码长度不能超过64个字符") + public String getPostCode() + { + return postCode; + } + + public void setPostCode(String postCode) + { + this.postCode = postCode; + } + + @NotBlank(message = "岗位名称不能为空") + @Size(min = 0, max = 50, message = "岗位名称长度不能超过50个字符") + public String getPostName() + { + return postName; + } + + public void setPostName(String postName) + { + this.postName = postName; + } + + @NotNull(message = "显示顺序不能为空") + public Integer getPostSort() + { + return postSort; + } + + public void setPostSort(Integer postSort) + { + this.postSort = postSort; + } + + public String getStatus() + { + return status; + } + + public void setStatus(String status) + { + this.status = status; + } + + public boolean isFlag() + { + return flag; + } + + public void setFlag(boolean flag) + { + this.flag = flag; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("postId", getPostId()) + .append("postCode", getPostCode()) + .append("postName", getPostName()) + .append("postSort", getPostSort()) + .append("status", getStatus()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SysRoleDept.java b/src/main/java/com/ruoyi/system/system/domain/SysRoleDept.java new file mode 100644 index 0000000..674e7d4 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SysRoleDept.java @@ -0,0 +1,46 @@ +package com.ruoyi.system.system.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 角色和部门关联 sys_role_dept + * + * @author mutaai + */ +public class SysRoleDept +{ + /** 角色ID */ + private Long roleId; + + /** 部门ID */ + private Long deptId; + + public Long getRoleId() + { + return roleId; + } + + public void setRoleId(Long roleId) + { + this.roleId = roleId; + } + + public Long getDeptId() + { + return deptId; + } + + public void setDeptId(Long deptId) + { + this.deptId = deptId; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("roleId", getRoleId()) + .append("deptId", getDeptId()) + .toString(); + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SysRoleMenu.java b/src/main/java/com/ruoyi/system/system/domain/SysRoleMenu.java new file mode 100644 index 0000000..d702285 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SysRoleMenu.java @@ -0,0 +1,46 @@ +package com.ruoyi.system.system.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 角色和菜单关联 sys_role_menu + * + * @author mutaai + */ +public class SysRoleMenu +{ + /** 角色ID */ + private Long roleId; + + /** 菜单ID */ + private Long menuId; + + public Long getRoleId() + { + return roleId; + } + + public void setRoleId(Long roleId) + { + this.roleId = roleId; + } + + public Long getMenuId() + { + return menuId; + } + + public void setMenuId(Long menuId) + { + this.menuId = menuId; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("roleId", getRoleId()) + .append("menuId", getMenuId()) + .toString(); + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SysUserOnline.java b/src/main/java/com/ruoyi/system/system/domain/SysUserOnline.java new file mode 100644 index 0000000..8b5e9fe --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SysUserOnline.java @@ -0,0 +1,113 @@ +package com.ruoyi.system.system.domain; + +/** + * 当前在线会话 + * + * @author mutaai + */ +public class SysUserOnline +{ + /** 会话编号 */ + private String tokenId; + + /** 部门名称 */ + private String deptName; + + /** 用户名称 */ + private String userName; + + /** 登录IP地址 */ + private String ipaddr; + + /** 登录地址 */ + private String loginLocation; + + /** 浏览器类型 */ + private String browser; + + /** 操作系统 */ + private String os; + + /** 登录时间 */ + private Long loginTime; + + public String getTokenId() + { + return tokenId; + } + + public void setTokenId(String tokenId) + { + this.tokenId = tokenId; + } + + public String getDeptName() + { + return deptName; + } + + public void setDeptName(String deptName) + { + this.deptName = deptName; + } + + public String getUserName() + { + return userName; + } + + public void setUserName(String userName) + { + this.userName = userName; + } + + public String getIpaddr() + { + return ipaddr; + } + + public void setIpaddr(String ipaddr) + { + this.ipaddr = ipaddr; + } + + public String getLoginLocation() + { + return loginLocation; + } + + public void setLoginLocation(String loginLocation) + { + this.loginLocation = loginLocation; + } + + public String getBrowser() + { + return browser; + } + + public void setBrowser(String browser) + { + this.browser = browser; + } + + public String getOs() + { + return os; + } + + public void setOs(String os) + { + this.os = os; + } + + public Long getLoginTime() + { + return loginTime; + } + + public void setLoginTime(Long loginTime) + { + this.loginTime = loginTime; + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SysUserPost.java b/src/main/java/com/ruoyi/system/system/domain/SysUserPost.java new file mode 100644 index 0000000..c3bafb5 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SysUserPost.java @@ -0,0 +1,46 @@ +package com.ruoyi.system.system.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 用户和岗位关联 sys_user_post + * + * @author mutaai + */ +public class SysUserPost +{ + /** 用户ID */ + private Long userId; + + /** 岗位ID */ + private Long postId; + + public Long getUserId() + { + return userId; + } + + public void setUserId(Long userId) + { + this.userId = userId; + } + + public Long getPostId() + { + return postId; + } + + public void setPostId(Long postId) + { + this.postId = postId; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("userId", getUserId()) + .append("postId", getPostId()) + .toString(); + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/SysUserRole.java b/src/main/java/com/ruoyi/system/system/domain/SysUserRole.java new file mode 100644 index 0000000..26bb3d6 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/SysUserRole.java @@ -0,0 +1,46 @@ +package com.ruoyi.system.system.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 用户和角色关联 sys_user_role + * + * @author mutaai + */ +public class SysUserRole +{ + /** 用户ID */ + private Long userId; + + /** 角色ID */ + private Long roleId; + + public Long getUserId() + { + return userId; + } + + public void setUserId(Long userId) + { + this.userId = userId; + } + + public Long getRoleId() + { + return roleId; + } + + public void setRoleId(Long roleId) + { + this.roleId = roleId; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("userId", getUserId()) + .append("roleId", getRoleId()) + .toString(); + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/TableColumns.java b/src/main/java/com/ruoyi/system/system/domain/TableColumns.java new file mode 100644 index 0000000..5f15243 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/TableColumns.java @@ -0,0 +1,21 @@ +package com.ruoyi.system.system.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class TableColumns { + private Integer id; + private String label; + private String prop; + private String width; + private String tag; + private String tagStyle; + private String view; + private String tableName; +} diff --git a/src/main/java/com/ruoyi/system/system/domain/Vip.java b/src/main/java/com/ruoyi/system/system/domain/Vip.java new file mode 100644 index 0000000..ebc790f --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/Vip.java @@ -0,0 +1,37 @@ +package com.ruoyi.system.system.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * @author 马兰友 + * @Date: 2024/06/05/13:30 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Vip { + + @TableId(type = IdType.AUTO) + @JsonFormat(shape =JsonFormat.Shape.STRING) + private Long id; + @JsonFormat(shape =JsonFormat.Shape.STRING) + private Long userId; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date vipBeginTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date svipBeginTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date vipExpireTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date svipExpireTime; + +} diff --git a/src/main/java/com/ruoyi/system/system/domain/dto/PageQueryDTO.java b/src/main/java/com/ruoyi/system/system/domain/dto/PageQueryDTO.java new file mode 100644 index 0000000..e551104 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/dto/PageQueryDTO.java @@ -0,0 +1,20 @@ +package com.ruoyi.system.system.domain.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * @author 马兰友 + * @Date: 2024/04/22/11:49 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class PageQueryDTO { + + private Integer pageNum; + private Integer pageSize; + +} diff --git a/src/main/java/com/ruoyi/system/system/domain/vo/MetaVo.java b/src/main/java/com/ruoyi/system/system/domain/vo/MetaVo.java new file mode 100644 index 0000000..f0288cc --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/vo/MetaVo.java @@ -0,0 +1,106 @@ +package com.ruoyi.system.system.domain.vo; + +import com.muta.common.utils.StringUtils; + +/** + * 路由显示信息 + * + * @author mutaai + */ +public class MetaVo +{ + /** + * 设置该路由在侧边栏和面包屑中展示的名字 + */ + private String title; + + /** + * 设置该路由的图标,对应路径src/assets/icons/svg + */ + private String icon; + + /** + * 设置为true,则不会被 缓存 + */ + private boolean noCache; + + /** + * 内链地址(http(s)://开头) + */ + private String link; + + public MetaVo() + { + } + + public MetaVo(String title, String icon) + { + this.title = title; + this.icon = icon; + } + + public MetaVo(String title, String icon, boolean noCache) + { + this.title = title; + this.icon = icon; + this.noCache = noCache; + } + + public MetaVo(String title, String icon, String link) + { + this.title = title; + this.icon = icon; + this.link = link; + } + + public MetaVo(String title, String icon, boolean noCache, String link) + { + this.title = title; + this.icon = icon; + this.noCache = noCache; + if (StringUtils.ishttp(link)) + { + this.link = link; + } + } + + public boolean isNoCache() + { + return noCache; + } + + public void setNoCache(boolean noCache) + { + this.noCache = noCache; + } + + public String getTitle() + { + return title; + } + + public void setTitle(String title) + { + this.title = title; + } + + public String getIcon() + { + return icon; + } + + public void setIcon(String icon) + { + this.icon = icon; + } + + public String getLink() + { + return link; + } + + public void setLink(String link) + { + this.link = link; + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/vo/RouterVo.java b/src/main/java/com/ruoyi/system/system/domain/vo/RouterVo.java new file mode 100644 index 0000000..c7f5758 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/vo/RouterVo.java @@ -0,0 +1,148 @@ +package com.ruoyi.system.system.domain.vo; + +import com.fasterxml.jackson.annotation.JsonInclude; +import java.util.List; + +/** + * 路由配置信息 + * + * @author mutaai + */ +@JsonInclude(JsonInclude.Include.NON_EMPTY) +public class RouterVo +{ + /** + * 路由名字 + */ + private String name; + + /** + * 路由地址 + */ + private String path; + + /** + * 是否隐藏路由,当设置 true 的时候该路由不会再侧边栏出现 + */ + private boolean hidden; + + /** + * 重定向地址,当设置 noRedirect 的时候该路由在面包屑导航中不可被点击 + */ + private String redirect; + + /** + * 组件地址 + */ + private String component; + + /** + * 路由参数:如 {"id": 1, "name": "ry"} + */ + private String query; + + /** + * 当你一个路由下面的 children 声明的路由大于1个时,自动会变成嵌套的模式--如组件页面 + */ + private Boolean alwaysShow; + + /** + * 其他元素 + */ + private MetaVo meta; + + /** + * 子路由 + */ + private List children; + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getPath() + { + return path; + } + + public void setPath(String path) + { + this.path = path; + } + + public boolean getHidden() + { + return hidden; + } + + public void setHidden(boolean hidden) + { + this.hidden = hidden; + } + + public String getRedirect() + { + return redirect; + } + + public void setRedirect(String redirect) + { + this.redirect = redirect; + } + + public String getComponent() + { + return component; + } + + public void setComponent(String component) + { + this.component = component; + } + + public String getQuery() + { + return query; + } + + public void setQuery(String query) + { + this.query = query; + } + + public Boolean getAlwaysShow() + { + return alwaysShow; + } + + public void setAlwaysShow(Boolean alwaysShow) + { + this.alwaysShow = alwaysShow; + } + + public MetaVo getMeta() + { + return meta; + } + + public void setMeta(MetaVo meta) + { + this.meta = meta; + } + + public List getChildren() + { + return children; + } + + public void setChildren(List children) + { + this.children = children; + } +} diff --git a/src/main/java/com/ruoyi/system/system/domain/vo/UserVO.java b/src/main/java/com/ruoyi/system/system/domain/vo/UserVO.java new file mode 100644 index 0000000..7da297e --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/domain/vo/UserVO.java @@ -0,0 +1,22 @@ +package com.ruoyi.system.system.domain.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author: Larry + * @Date: 2024 /06 /05 / 13:09 + * @Description: + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class UserVO { + private String username; + private String avatar; + private String vipType; + private Integer integral; +} diff --git a/src/main/java/com/ruoyi/system/system/factory/RegisterFactory.java b/src/main/java/com/ruoyi/system/system/factory/RegisterFactory.java new file mode 100644 index 0000000..eb59bf4 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/factory/RegisterFactory.java @@ -0,0 +1,10 @@ +package com.ruoyi.system.system.factory; + +/** + * @author: Larry + * @Date: 2024 /08 /02 / 9:20 + * @Description: + */ +public class RegisterFactory { + +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/ColumnsMapper.java b/src/main/java/com/ruoyi/system/system/mapper/ColumnsMapper.java new file mode 100644 index 0000000..3fbdb53 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/ColumnsMapper.java @@ -0,0 +1,9 @@ +package com.ruoyi.system.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.system.domain.TableColumns; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ColumnsMapper extends BaseMapper { +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/CommonSettingMapper.java b/src/main/java/com/ruoyi/system/system/mapper/CommonSettingMapper.java new file mode 100644 index 0000000..2421865 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/CommonSettingMapper.java @@ -0,0 +1,38 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.system.domain.CommonSetting; +import org.apache.ibatis.annotations.Mapper; + +/** + * 设置Mapper接口 + * + * @author mutaai + * @date 2024-04-22 + */ +@Mapper +public interface CommonSettingMapper extends BaseMapper { + /** + * 查询设置 + * + * @param id 设置主键 + * @return 设置 + */ + public CommonSetting selectCommonSettingById(Long id); + + /** + * 查询设置列表 + * + * @return 设置集合 + */ + public List selectCommonSettingList(); + + /** + * 修改设置 + * + * @param commonSetting 设置 + * @return 结果 + */ + public int updateCommonSetting(CommonSetting commonSetting); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/FileConfigMapper.java b/src/main/java/com/ruoyi/system/system/mapper/FileConfigMapper.java new file mode 100644 index 0000000..8581780 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/FileConfigMapper.java @@ -0,0 +1,29 @@ +package com.ruoyi.system.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.system.domain.FileConfig; +import com.muta.system.domain.SysConfig; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; + +/** + * @author: Larry + * @Date: 2024 /04 /21 / 13:42 + * @Description: 文件存储配置查询 + */ +@Mapper +public interface FileConfigMapper extends BaseMapper { + /** + * 查询参数配置信息 + * + * @param name 存储方式名称 + * @return 参数配置信息 + */ + @Select("select * from file_config where name =#{name}") + public FileConfig selectConfig(String name); + + + int updateConfig(FileConfig fileConfig); + +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SigninLogMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SigninLogMapper.java new file mode 100644 index 0000000..368930e --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SigninLogMapper.java @@ -0,0 +1,14 @@ +package com.ruoyi.system.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.system.domain.SigninLog; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface SigninLogMapper extends BaseMapper { + + List logList(SysUser sysUser); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SigninMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SigninMapper.java new file mode 100644 index 0000000..599ba6e --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SigninMapper.java @@ -0,0 +1,16 @@ +package com.ruoyi.system.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.system.domain.Signin; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +@Mapper +public interface SigninMapper extends BaseMapper { + + @Select("select * from signin") + List selectAllSignin(); + +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysConfigMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysConfigMapper.java new file mode 100644 index 0000000..e195c32 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysConfigMapper.java @@ -0,0 +1,76 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import com.muta.system.domain.SysConfig; + +/** + * 参数配置 数据层 + * + * @author mutaai + */ +public interface SysConfigMapper +{ + /** + * 查询参数配置信息 + * + * @param config 参数配置信息 + * @return 参数配置信息 + */ + public SysConfig selectConfig(SysConfig config); + + /** + * 通过ID查询配置 + * + * @param configId 参数ID + * @return 参数配置信息 + */ + public SysConfig selectConfigById(Long configId); + + /** + * 查询参数配置列表 + * + * @param config 参数配置信息 + * @return 参数配置集合 + */ + public List selectConfigList(SysConfig config); + + /** + * 根据键名查询参数配置信息 + * + * @param configKey 参数键名 + * @return 参数配置信息 + */ + public SysConfig checkConfigKeyUnique(String configKey); + + /** + * 新增参数配置 + * + * @param config 参数配置信息 + * @return 结果 + */ + public int insertConfig(SysConfig config); + + /** + * 修改参数配置 + * + * @param config 参数配置信息 + * @return 结果 + */ + public int updateConfig(SysConfig config); + + /** + * 删除参数配置 + * + * @param configId 参数ID + * @return 结果 + */ + public int deleteConfigById(Long configId); + + /** + * 批量删除参数信息 + * + * @param configIds 需要删除的参数ID + * @return 结果 + */ + public int deleteConfigByIds(Long[] configIds); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysDeptMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysDeptMapper.java new file mode 100644 index 0000000..d6b3c9f --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysDeptMapper.java @@ -0,0 +1,118 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import org.apache.ibatis.annotations.Param; +import com.muta.common.core.domain.entity.SysDept; + +/** + * 部门管理 数据层 + * + * @author mutaai + */ +public interface SysDeptMapper +{ + /** + * 查询部门管理数据 + * + * @param dept 部门信息 + * @return 部门信息集合 + */ + public List selectDeptList(SysDept dept); + + /** + * 根据角色ID查询部门树信息 + * + * @param roleId 角色ID + * @param deptCheckStrictly 部门树选择项是否关联显示 + * @return 选中部门列表 + */ + public List selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly); + + /** + * 根据部门ID查询信息 + * + * @param deptId 部门ID + * @return 部门信息 + */ + public SysDept selectDeptById(Long deptId); + + /** + * 根据ID查询所有子部门 + * + * @param deptId 部门ID + * @return 部门列表 + */ + public List selectChildrenDeptById(Long deptId); + + /** + * 根据ID查询所有子部门(正常状态) + * + * @param deptId 部门ID + * @return 子部门数 + */ + public int selectNormalChildrenDeptById(Long deptId); + + /** + * 是否存在子节点 + * + * @param deptId 部门ID + * @return 结果 + */ + public int hasChildByDeptId(Long deptId); + + /** + * 查询部门是否存在用户 + * + * @param deptId 部门ID + * @return 结果 + */ + public int checkDeptExistUser(Long deptId); + + /** + * 校验部门名称是否唯一 + * + * @param deptName 部门名称 + * @param parentId 父部门ID + * @return 结果 + */ + public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId); + + /** + * 新增部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + public int insertDept(SysDept dept); + + /** + * 修改部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + public int updateDept(SysDept dept); + + /** + * 修改所在部门正常状态 + * + * @param deptIds 部门ID组 + */ + public void updateDeptStatusNormal(Long[] deptIds); + + /** + * 修改子元素关系 + * + * @param depts 子元素 + * @return 结果 + */ + public int updateDeptChildren(@Param("depts") List depts); + + /** + * 删除部门管理信息 + * + * @param deptId 部门ID + * @return 结果 + */ + public int deleteDeptById(Long deptId); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysDictDataMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysDictDataMapper.java new file mode 100644 index 0000000..6755c97 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysDictDataMapper.java @@ -0,0 +1,95 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import org.apache.ibatis.annotations.Param; +import com.muta.common.core.domain.entity.SysDictData; + +/** + * 字典表 数据层 + * + * @author mutaai + */ +public interface SysDictDataMapper +{ + /** + * 根据条件分页查询字典数据 + * + * @param dictData 字典数据信息 + * @return 字典数据集合信息 + */ + public List selectDictDataList(SysDictData dictData); + + /** + * 根据字典类型查询字典数据 + * + * @param dictType 字典类型 + * @return 字典数据集合信息 + */ + public List selectDictDataByType(String dictType); + + /** + * 根据字典类型和字典键值查询字典数据信息 + * + * @param dictType 字典类型 + * @param dictValue 字典键值 + * @return 字典标签 + */ + public String selectDictLabel(@Param("dictType") String dictType, @Param("dictValue") String dictValue); + + /** + * 根据字典数据ID查询信息 + * + * @param dictCode 字典数据ID + * @return 字典数据 + */ + public SysDictData selectDictDataById(Long dictCode); + + /** + * 查询字典数据 + * + * @param dictType 字典类型 + * @return 字典数据 + */ + public int countDictDataByType(String dictType); + + /** + * 通过字典ID删除字典数据信息 + * + * @param dictCode 字典数据ID + * @return 结果 + */ + public int deleteDictDataById(Long dictCode); + + /** + * 批量删除字典数据信息 + * + * @param dictCodes 需要删除的字典数据ID + * @return 结果 + */ + public int deleteDictDataByIds(Long[] dictCodes); + + /** + * 新增字典数据信息 + * + * @param dictData 字典数据信息 + * @return 结果 + */ + public int insertDictData(SysDictData dictData); + + /** + * 修改字典数据信息 + * + * @param dictData 字典数据信息 + * @return 结果 + */ + public int updateDictData(SysDictData dictData); + + /** + * 同步修改字典类型 + * + * @param oldDictType 旧字典类型 + * @param newDictType 新旧字典类型 + * @return 结果 + */ + public int updateDictDataType(@Param("oldDictType") String oldDictType, @Param("newDictType") String newDictType); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysDictTypeMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysDictTypeMapper.java new file mode 100644 index 0000000..905df56 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysDictTypeMapper.java @@ -0,0 +1,83 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import com.muta.common.core.domain.entity.SysDictType; + +/** + * 字典表 数据层 + * + * @author mutaai + */ +public interface SysDictTypeMapper +{ + /** + * 根据条件分页查询字典类型 + * + * @param dictType 字典类型信息 + * @return 字典类型集合信息 + */ + public List selectDictTypeList(SysDictType dictType); + + /** + * 根据所有字典类型 + * + * @return 字典类型集合信息 + */ + public List selectDictTypeAll(); + + /** + * 根据字典类型ID查询信息 + * + * @param dictId 字典类型ID + * @return 字典类型 + */ + public SysDictType selectDictTypeById(Long dictId); + + /** + * 根据字典类型查询信息 + * + * @param dictType 字典类型 + * @return 字典类型 + */ + public SysDictType selectDictTypeByType(String dictType); + + /** + * 通过字典ID删除字典信息 + * + * @param dictId 字典ID + * @return 结果 + */ + public int deleteDictTypeById(Long dictId); + + /** + * 批量删除字典类型信息 + * + * @param dictIds 需要删除的字典ID + * @return 结果 + */ + public int deleteDictTypeByIds(Long[] dictIds); + + /** + * 新增字典类型信息 + * + * @param dictType 字典类型信息 + * @return 结果 + */ + public int insertDictType(SysDictType dictType); + + /** + * 修改字典类型信息 + * + * @param dictType 字典类型信息 + * @return 结果 + */ + public int updateDictType(SysDictType dictType); + + /** + * 校验字典类型称是否唯一 + * + * @param dictType 字典类型 + * @return 结果 + */ + public SysDictType checkDictTypeUnique(String dictType); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysLogininforMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysLogininforMapper.java new file mode 100644 index 0000000..cda8c7e --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysLogininforMapper.java @@ -0,0 +1,42 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import com.muta.system.domain.SysLogininfor; + +/** + * 系统访问日志情况信息 数据层 + * + * @author mutaai + */ +public interface SysLogininforMapper +{ + /** + * 新增系统登录日志 + * + * @param logininfor 访问日志对象 + */ + public void insertLogininfor(SysLogininfor logininfor); + + /** + * 查询系统登录日志集合 + * + * @param logininfor 访问日志对象 + * @return 登录记录集合 + */ + public List selectLogininforList(SysLogininfor logininfor); + + /** + * 批量删除系统登录日志 + * + * @param infoIds 需要删除的登录日志ID + * @return 结果 + */ + public int deleteLogininforByIds(Long[] infoIds); + + /** + * 清空系统登录日志 + * + * @return 结果 + */ + public int cleanLogininfor(); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysMenuMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysMenuMapper.java new file mode 100644 index 0000000..bded931 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysMenuMapper.java @@ -0,0 +1,125 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import org.apache.ibatis.annotations.Param; +import com.muta.common.core.domain.entity.SysMenu; + +/** + * 菜单表 数据层 + * + * @author mutaai + */ +public interface SysMenuMapper +{ + /** + * 查询系统菜单列表 + * + * @param menu 菜单信息 + * @return 菜单列表 + */ + public List selectMenuList(SysMenu menu); + + /** + * 根据用户所有权限 + * + * @return 权限列表 + */ + public List selectMenuPerms(); + + /** + * 根据用户查询系统菜单列表 + * + * @param menu 菜单信息 + * @return 菜单列表 + */ + public List selectMenuListByUserId(SysMenu menu); + + /** + * 根据角色ID查询权限 + * + * @param roleId 角色ID + * @return 权限列表 + */ + public List selectMenuPermsByRoleId(Long roleId); + + /** + * 根据用户ID查询权限 + * + * @param userId 用户ID + * @return 权限列表 + */ + public List selectMenuPermsByUserId(Long userId); + + /** + * 根据用户ID查询菜单 + * + * @return 菜单列表 + */ + public List selectMenuTreeAll(); + + /** + * 根据用户ID查询菜单 + * + * @param userId 用户ID + * @return 菜单列表 + */ + public List selectMenuTreeByUserId(Long userId); + + /** + * 根据角色ID查询菜单树信息 + * + * @param roleId 角色ID + * @param menuCheckStrictly 菜单树选择项是否关联显示 + * @return 选中菜单列表 + */ + public List selectMenuListByRoleId(@Param("roleId") Long roleId, @Param("menuCheckStrictly") boolean menuCheckStrictly); + + /** + * 根据菜单ID查询信息 + * + * @param menuId 菜单ID + * @return 菜单信息 + */ + public SysMenu selectMenuById(Long menuId); + + /** + * 是否存在菜单子节点 + * + * @param menuId 菜单ID + * @return 结果 + */ + public int hasChildByMenuId(Long menuId); + + /** + * 新增菜单信息 + * + * @param menu 菜单信息 + * @return 结果 + */ + public int insertMenu(SysMenu menu); + + /** + * 修改菜单信息 + * + * @param menu 菜单信息 + * @return 结果 + */ + public int updateMenu(SysMenu menu); + + /** + * 删除菜单管理信息 + * + * @param menuId 菜单ID + * @return 结果 + */ + public int deleteMenuById(Long menuId); + + /** + * 校验菜单名称是否唯一 + * + * @param menuName 菜单名称 + * @param parentId 父菜单ID + * @return 结果 + */ + public SysMenu checkMenuNameUnique(@Param("menuName") String menuName, @Param("parentId") Long parentId); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysNoticeMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysNoticeMapper.java new file mode 100644 index 0000000..bae1a9b --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysNoticeMapper.java @@ -0,0 +1,60 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import com.muta.system.domain.SysNotice; + +/** + * 通知公告表 数据层 + * + * @author mutaai + */ +public interface SysNoticeMapper +{ + /** + * 查询公告信息 + * + * @param noticeId 公告ID + * @return 公告信息 + */ + public SysNotice selectNoticeById(Long noticeId); + + /** + * 查询公告列表 + * + * @param notice 公告信息 + * @return 公告集合 + */ + public List selectNoticeList(SysNotice notice); + + /** + * 新增公告 + * + * @param notice 公告信息 + * @return 结果 + */ + public int insertNotice(SysNotice notice); + + /** + * 修改公告 + * + * @param notice 公告信息 + * @return 结果 + */ + public int updateNotice(SysNotice notice); + + /** + * 批量删除公告 + * + * @param noticeId 公告ID + * @return 结果 + */ + public int deleteNoticeById(Long noticeId); + + /** + * 批量删除公告信息 + * + * @param noticeIds 需要删除的公告ID + * @return 结果 + */ + public int deleteNoticeByIds(Long[] noticeIds); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysOperLogMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysOperLogMapper.java new file mode 100644 index 0000000..835a747 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysOperLogMapper.java @@ -0,0 +1,48 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import com.muta.system.domain.SysOperLog; + +/** + * 操作日志 数据层 + * + * @author mutaai + */ +public interface SysOperLogMapper +{ + /** + * 新增操作日志 + * + * @param operLog 操作日志对象 + */ + public void insertOperlog(SysOperLog operLog); + + /** + * 查询系统操作日志集合 + * + * @param operLog 操作日志对象 + * @return 操作日志集合 + */ + public List selectOperLogList(SysOperLog operLog); + + /** + * 批量删除系统操作日志 + * + * @param operIds 需要删除的操作日志ID + * @return 结果 + */ + public int deleteOperLogByIds(Long[] operIds); + + /** + * 查询操作日志详细 + * + * @param operId 操作ID + * @return 操作日志对象 + */ + public SysOperLog selectOperLogById(Long operId); + + /** + * 清空操作日志 + */ + public void cleanOperLog(); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysPostMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysPostMapper.java new file mode 100644 index 0000000..f1c36c6 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysPostMapper.java @@ -0,0 +1,99 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import com.muta.system.domain.SysPost; + +/** + * 岗位信息 数据层 + * + * @author mutaai + */ +public interface SysPostMapper +{ + /** + * 查询岗位数据集合 + * + * @param post 岗位信息 + * @return 岗位数据集合 + */ + public List selectPostList(SysPost post); + + /** + * 查询所有岗位 + * + * @return 岗位列表 + */ + public List selectPostAll(); + + /** + * 通过岗位ID查询岗位信息 + * + * @param postId 岗位ID + * @return 角色对象信息 + */ + public SysPost selectPostById(Long postId); + + /** + * 根据用户ID获取岗位选择框列表 + * + * @param userId 用户ID + * @return 选中岗位ID列表 + */ + public List selectPostListByUserId(Long userId); + + /** + * 查询用户所属岗位组 + * + * @param userName 用户名 + * @return 结果 + */ + public List selectPostsByUserName(String userName); + + /** + * 删除岗位信息 + * + * @param postId 岗位ID + * @return 结果 + */ + public int deletePostById(Long postId); + + /** + * 批量删除岗位信息 + * + * @param postIds 需要删除的岗位ID + * @return 结果 + */ + public int deletePostByIds(Long[] postIds); + + /** + * 修改岗位信息 + * + * @param post 岗位信息 + * @return 结果 + */ + public int updatePost(SysPost post); + + /** + * 新增岗位信息 + * + * @param post 岗位信息 + * @return 结果 + */ + public int insertPost(SysPost post); + + /** + * 校验岗位名称 + * + * @param postName 岗位名称 + * @return 结果 + */ + public SysPost checkPostNameUnique(String postName); + + /** + * 校验岗位编码 + * + * @param postCode 岗位编码 + * @return 结果 + */ + public SysPost checkPostCodeUnique(String postCode); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysRoleDeptMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysRoleDeptMapper.java new file mode 100644 index 0000000..2f90917 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysRoleDeptMapper.java @@ -0,0 +1,44 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import com.muta.system.domain.SysRoleDept; + +/** + * 角色与部门关联表 数据层 + * + * @author mutaai + */ +public interface SysRoleDeptMapper +{ + /** + * 通过角色ID删除角色和部门关联 + * + * @param roleId 角色ID + * @return 结果 + */ + public int deleteRoleDeptByRoleId(Long roleId); + + /** + * 批量删除角色部门关联信息 + * + * @param ids 需要删除的数据ID + * @return 结果 + */ + public int deleteRoleDept(Long[] ids); + + /** + * 查询部门使用数量 + * + * @param deptId 部门ID + * @return 结果 + */ + public int selectCountRoleDeptByDeptId(Long deptId); + + /** + * 批量新增角色部门信息 + * + * @param roleDeptList 角色部门列表 + * @return 结果 + */ + public int batchRoleDept(List roleDeptList); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysRoleMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysRoleMapper.java new file mode 100644 index 0000000..334f090 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysRoleMapper.java @@ -0,0 +1,107 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import com.muta.common.core.domain.entity.SysRole; + +/** + * 角色表 数据层 + * + * @author mutaai + */ +public interface SysRoleMapper +{ + /** + * 根据条件分页查询角色数据 + * + * @param role 角色信息 + * @return 角色数据集合信息 + */ + public List selectRoleList(SysRole role); + + /** + * 根据用户ID查询角色 + * + * @param userId 用户ID + * @return 角色列表 + */ + public List selectRolePermissionByUserId(Long userId); + + /** + * 查询所有角色 + * + * @return 角色列表 + */ + public List selectRoleAll(); + + /** + * 根据用户ID获取角色选择框列表 + * + * @param userId 用户ID + * @return 选中角色ID列表 + */ + public List selectRoleListByUserId(Long userId); + + /** + * 通过角色ID查询角色 + * + * @param roleId 角色ID + * @return 角色对象信息 + */ + public SysRole selectRoleById(Long roleId); + + /** + * 根据用户ID查询角色 + * + * @param userName 用户名 + * @return 角色列表 + */ + public List selectRolesByUserName(String userName); + + /** + * 校验角色名称是否唯一 + * + * @param roleName 角色名称 + * @return 角色信息 + */ + public SysRole checkRoleNameUnique(String roleName); + + /** + * 校验角色权限是否唯一 + * + * @param roleKey 角色权限 + * @return 角色信息 + */ + public SysRole checkRoleKeyUnique(String roleKey); + + /** + * 修改角色信息 + * + * @param role 角色信息 + * @return 结果 + */ + public int updateRole(SysRole role); + + /** + * 新增角色信息 + * + * @param role 角色信息 + * @return 结果 + */ + public int insertRole(SysRole role); + + /** + * 通过角色ID删除角色 + * + * @param roleId 角色ID + * @return 结果 + */ + public int deleteRoleById(Long roleId); + + /** + * 批量删除角色信息 + * + * @param roleIds 需要删除的角色ID + * @return 结果 + */ + public int deleteRoleByIds(Long[] roleIds); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysRoleMenuMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysRoleMenuMapper.java new file mode 100644 index 0000000..a853e28 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysRoleMenuMapper.java @@ -0,0 +1,44 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; +import com.muta.system.domain.SysRoleMenu; + +/** + * 角色与菜单关联表 数据层 + * + * @author mutaai + */ +public interface SysRoleMenuMapper +{ + /** + * 查询菜单使用数量 + * + * @param menuId 菜单ID + * @return 结果 + */ + public int checkMenuExistRole(Long menuId); + + /** + * 通过角色ID删除角色和菜单关联 + * + * @param roleId 角色ID + * @return 结果 + */ + public int deleteRoleMenuByRoleId(Long roleId); + + /** + * 批量删除角色菜单关联信息 + * + * @param ids 需要删除的数据ID + * @return 结果 + */ + public int deleteRoleMenu(Long[] ids); + + /** + * 批量新增角色菜单信息 + * + * @param roleMenuList 角色菜单列表 + * @return 结果 + */ + public int batchRoleMenu(List roleMenuList); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysUserMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysUserMapper.java new file mode 100644 index 0000000..3af84da --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysUserMapper.java @@ -0,0 +1,139 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.common.annotation.AutoFill; +import com.muta.common.annotation.DataPermission; +import com.muta.common.enums.BaseOperatorType; +import org.apache.ibatis.annotations.Param; +import com.muta.common.core.domain.entity.SysUser; +import org.apache.ibatis.annotations.Select; + +/** + * 用户表 数据层 + * + * @author mutaai + */ +public interface SysUserMapper { + /** + * 根据条件分页查询用户列表 + * + * @param + * @return 用户信息集合信息 + */ + @Select("select user_name from sys_user where user_id =#{userId}") + String getNameById(Long userId); + + @DataPermission + public List selectUserList(SysUser sysUser); + + /** + * 根据条件分页查询已配用户角色列表 + * + * @param user 用户信息 + * @return 用户信息集合信息 + */ + public List selectAllocatedList(SysUser user); + + /** + * 根据条件分页查询未分配用户角色列表 + * + * @param user 用户信息 + * @return 用户信息集合信息 + */ + public List selectUnallocatedList(SysUser user); + + /** + * 通过用户名查询用户 + * + * @param userName 用户名 + * @return 用户对象信息 + */ + public SysUser selectUserByUserName(String userName); + + /** + * 通过用户ID查询用户 + * + * @param userId 用户ID + * @return 用户对象信息 + */ + public SysUser selectUserById(Long userId); + + /** + * 新增用户信息 + * + * @param user 用户信息 + * @return 结果 + */ +// @AutoFill(BaseOperatorType.INSERT) + public int insertUser(SysUser user); + + /** + * 修改用户信息 + * + * @param user 用户信息 + * @return 结果 + */ + public int updateUser(SysUser user); + + /** + * 修改用户头像 + * + * @param userName 用户名 + * @param avatar 头像地址 + * @return 结果 + */ + public int updateUserAvatar(@Param("userName") String userName, @Param("avatar") String avatar); + + /** + * 重置用户密码 + * + * @param userName 用户名 + * @param password 密码 + * @return 结果 + */ + public int resetUserPwd(@Param("userName") String userName, @Param("password") String password); + + /** + * 通过用户ID删除用户 + * + * @param userId 用户ID + * @return 结果 + */ + public int deleteUserById(Long userId); + + /** + * 批量删除用户信息 + * + * @param userIds 需要删除的用户ID + * @return 结果 + */ + public int deleteUserByIds(Long[] userIds); + + /** + * 校验用户名称是否唯一 + * + * @param userName 用户名称 + * @return 结果 + */ + public SysUser checkUserNameUnique(String userName); + + /** + * 校验手机号码是否唯一 + * + * @param phonenumber 手机号码 + * @return 结果 + */ + public SysUser checkPhoneUnique(String phonenumber); + + /** + * 校验email是否唯一 + * + * @param email 用户邮箱 + * @return 结果 + */ + public SysUser checkEmailUnique(String email); + @Select("select avatar, user_name from sys_user where user_id = #{id} and del_flag = '0'") + public SysUser getUserInfo(Long id); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysUserPostMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysUserPostMapper.java new file mode 100644 index 0000000..9feee9e --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysUserPostMapper.java @@ -0,0 +1,45 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; + +import com.muta.system.domain.SysUserPost; + +/** + * 用户与岗位关联表 数据层 + * + * @author mutaai + */ +public interface SysUserPostMapper +{ + /** + * 通过用户ID删除用户和岗位关联 + * + * @param userId 用户ID + * @return 结果 + */ + public int deleteUserPostByUserId(Long userId); + + /** + * 通过岗位ID查询岗位使用数量 + * + * @param postId 岗位ID + * @return 结果 + */ + public int countUserPostById(Long postId); + + /** + * 批量删除用户和岗位关联 + * + * @param ids 需要删除的数据ID + * @return 结果 + */ + public int deleteUserPost(Long[] ids); + + /** + * 批量新增用户岗位信息 + * + * @param userPostList 用户岗位列表 + * @return 结果 + */ + public int batchUserPost(List userPostList); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/SysUserRoleMapper.java b/src/main/java/com/ruoyi/system/system/mapper/SysUserRoleMapper.java new file mode 100644 index 0000000..3182554 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/SysUserRoleMapper.java @@ -0,0 +1,65 @@ +package com.ruoyi.system.system.mapper; + +import java.util.List; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; +import com.muta.system.domain.SysUserRole; + +/** + * 用户与角色关联表 数据层 + * + * @author mutaai + */ +public interface SysUserRoleMapper extends BaseMapper +{ + /** + * 通过用户ID删除用户和角色关联 + * + * @param userId 用户ID + * @return 结果 + */ + public int deleteUserRoleByUserId(Long userId); + + /** + * 批量删除用户和角色关联 + * + * @param ids 需要删除的数据ID + * @return 结果 + */ + public int deleteUserRole(Long[] ids); + + /** + * 通过角色ID查询角色使用数量 + * + * @param roleId 角色ID + * @return 结果 + */ + public int countUserRoleByRoleId(Long roleId); + + /** + * 批量新增用户角色信息 + * + * @param userRoleList 用户角色列表 + * @return 结果 + */ + public int batchUserRole(List userRoleList); + + /** + * 删除用户和角色关联信息 + * + * @param userRole 用户和角色关联信息 + * @return 结果 + */ + public int deleteUserRoleInfo(SysUserRole userRole); + + /** + * 批量取消授权用户角色 + * + * @param roleId 角色ID + * @param userIds 需要删除的用户数据ID + * @return 结果 + */ + public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds); + +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/UserExtraMapper.java b/src/main/java/com/ruoyi/system/system/mapper/UserExtraMapper.java new file mode 100644 index 0000000..2fc8c81 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/UserExtraMapper.java @@ -0,0 +1,33 @@ +package com.ruoyi.system.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.common.core.domain.entity.UserExtra; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Service; + +/** + *

+ * Mapper 接口 + *

+ * + * @author zy + * @since 2024-04-17 + */ +@Mapper +public interface UserExtraMapper extends BaseMapper { + + void deleteUserExtraByUserId(Long userId); + + void deleteUserExtra(Long[] userIds); + @Update("update user_extra SET integral = integral + #{count} WHERE user_id = #{userId} ") + + void addIntegralByUserId(@Param("count") int count, @Param("userId") Long userId); + @Update("update user_extra SET integral = integral - #{count} WHERE user_id = #{userId} ") + + Integer IncreaseIntegralByUserId(@Param("count") int count, @Param("userId") Long userId); + @Select("select integral from user_extra where user_id = #{userId} ") + Integer getIntegralByUserId(Long userId); +} diff --git a/src/main/java/com/ruoyi/system/system/mapper/VipMapper.java b/src/main/java/com/ruoyi/system/system/mapper/VipMapper.java new file mode 100644 index 0000000..4aa9d4a --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/mapper/VipMapper.java @@ -0,0 +1,13 @@ +package com.ruoyi.system.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.system.domain.Vip; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author 马兰友 + * @Date: 2024/06/05/13:35 + */ +@Mapper +public interface VipMapper extends BaseMapper { +} diff --git a/src/main/java/com/ruoyi/system/system/service/ColumnsService.java b/src/main/java/com/ruoyi/system/system/service/ColumnsService.java new file mode 100644 index 0000000..ca3c636 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ColumnsService.java @@ -0,0 +1,10 @@ +package com.ruoyi.system.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.system.domain.TableColumns; + +import java.util.List; + +public interface ColumnsService extends IService { + List getColumns(String tableName); +} diff --git a/src/main/java/com/ruoyi/system/system/service/ICommonSettingService.java b/src/main/java/com/ruoyi/system/system/service/ICommonSettingService.java new file mode 100644 index 0000000..765049e --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ICommonSettingService.java @@ -0,0 +1,51 @@ +package com.ruoyi.system.system.service; + +import java.util.List; +import com.muta.system.domain.CommonSetting; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * 设置Service接口 + * + * @author mutaai + * @date 2024-04-22 + */ +public interface ICommonSettingService extends IService { + /** + * 查询设置 + * + * @param id 设置主键 + * @return 设置 + */ + public CommonSetting selectCommonSettingById(Long id); + + /** + * 查询设置列表 + * + * @return 设置集合 + */ + public List selectCommonSettingList(); + + /** + * 修改设置 + * + * @param commonSetting 设置 + * @return 结果 + */ + public int updateCommonSetting(CommonSetting commonSetting); + + /** + * 批量修改设置 + * @param commonSettings + */ + public void batchUpdateCommonSetting(List commonSettings); + + /** + * 通过名字获取比例 + * @param name + * @return + */ + public Integer getRatioByName(String name); + + public String getByName(String name); +} diff --git a/src/main/java/com/ruoyi/system/system/service/IFileConfigService.java b/src/main/java/com/ruoyi/system/system/service/IFileConfigService.java new file mode 100644 index 0000000..d3df5b8 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/IFileConfigService.java @@ -0,0 +1,19 @@ +package com.ruoyi.system.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.system.domain.FileConfig; + +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /04 /21 / 15:14 + * @Description: + */ +public interface IFileConfigService extends IService { + List selectFileConfigList(FileConfig fileConfig); + + void updateFileConfigList(FileConfig fileConfig); + + FileConfig getByName(String name); +} diff --git a/src/main/java/com/ruoyi/system/system/service/IRegisterService.java b/src/main/java/com/ruoyi/system/system/service/IRegisterService.java new file mode 100644 index 0000000..6d2fd04 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/IRegisterService.java @@ -0,0 +1,9 @@ +package com.ruoyi.system.system.service; + +/** + * @author: Larry + * @Date: 2024 /08 /02 / 9:20 + * @Description: + */ +public interface IRegisterService { +} diff --git a/src/main/java/com/ruoyi/system/system/service/ISysConfigService.java b/src/main/java/com/ruoyi/system/system/service/ISysConfigService.java new file mode 100644 index 0000000..9c09ab4 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ISysConfigService.java @@ -0,0 +1,89 @@ +package com.ruoyi.system.system.service; + +import java.util.List; +import com.muta.system.domain.SysConfig; + +/** + * 参数配置 服务层 + * + * @author mutaai + */ +public interface ISysConfigService +{ + /** + * 查询参数配置信息 + * + * @param configId 参数配置ID + * @return 参数配置信息 + */ + public SysConfig selectConfigById(Long configId); + + /** + * 根据键名查询参数配置信息 + * + * @param configKey 参数键名 + * @return 参数键值 + */ + public String selectConfigByKey(String configKey); + + /** + * 获取验证码开关 + * + * @return true开启,false关闭 + */ + public boolean selectCaptchaEnabled(); + + /** + * 查询参数配置列表 + * + * @param config 参数配置信息 + * @return 参数配置集合 + */ + public List selectConfigList(SysConfig config); + + /** + * 新增参数配置 + * + * @param config 参数配置信息 + * @return 结果 + */ + public int insertConfig(SysConfig config); + + /** + * 修改参数配置 + * + * @param config 参数配置信息 + * @return 结果 + */ + public int updateConfig(SysConfig config); + + /** + * 批量删除参数信息 + * + * @param configIds 需要删除的参数ID + */ + public void deleteConfigByIds(Long[] configIds); + + /** + * 加载参数缓存数据 + */ + public void loadingConfigCache(); + + /** + * 清空参数缓存数据 + */ + public void clearConfigCache(); + + /** + * 重置参数缓存数据 + */ + public void resetConfigCache(); + + /** + * 校验参数键名是否唯一 + * + * @param config 参数信息 + * @return 结果 + */ + public boolean checkConfigKeyUnique(SysConfig config); +} diff --git a/src/main/java/com/ruoyi/system/system/service/ISysDeptService.java b/src/main/java/com/ruoyi/system/system/service/ISysDeptService.java new file mode 100644 index 0000000..5b9eec0 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ISysDeptService.java @@ -0,0 +1,124 @@ +package com.ruoyi.system.system.service; + +import java.util.List; +import com.muta.common.core.domain.TreeSelect; +import com.muta.common.core.domain.entity.SysDept; + +/** + * 部门管理 服务层 + * + * @author mutaai + */ +public interface ISysDeptService +{ + /** + * 查询部门管理数据 + * + * @param dept 部门信息 + * @return 部门信息集合 + */ + public List selectDeptList(SysDept dept); + + /** + * 查询部门树结构信息 + * + * @param dept 部门信息 + * @return 部门树信息集合 + */ + public List selectDeptTreeList(SysDept dept); + + /** + * 构建前端所需要树结构 + * + * @param depts 部门列表 + * @return 树结构列表 + */ + public List buildDeptTree(List depts); + + /** + * 构建前端所需要下拉树结构 + * + * @param depts 部门列表 + * @return 下拉树结构列表 + */ + public List buildDeptTreeSelect(List depts); + + /** + * 根据角色ID查询部门树信息 + * + * @param roleId 角色ID + * @return 选中部门列表 + */ + public List selectDeptListByRoleId(Long roleId); + + /** + * 根据部门ID查询信息 + * + * @param deptId 部门ID + * @return 部门信息 + */ + public SysDept selectDeptById(Long deptId); + + /** + * 根据ID查询所有子部门(正常状态) + * + * @param deptId 部门ID + * @return 子部门数 + */ + public int selectNormalChildrenDeptById(Long deptId); + + /** + * 是否存在部门子节点 + * + * @param deptId 部门ID + * @return 结果 + */ + public boolean hasChildByDeptId(Long deptId); + + /** + * 查询部门是否存在用户 + * + * @param deptId 部门ID + * @return 结果 true 存在 false 不存在 + */ + public boolean checkDeptExistUser(Long deptId); + + /** + * 校验部门名称是否唯一 + * + * @param dept 部门信息 + * @return 结果 + */ + public boolean checkDeptNameUnique(SysDept dept); + + /** + * 校验部门是否有数据权限 + * + * @param deptId 部门id + */ + public void checkDeptDataScope(Long deptId); + + /** + * 新增保存部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + public int insertDept(SysDept dept); + + /** + * 修改保存部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + public int updateDept(SysDept dept); + + /** + * 删除部门管理信息 + * + * @param deptId 部门ID + * @return 结果 + */ + public int deleteDeptById(Long deptId); +} diff --git a/src/main/java/com/ruoyi/system/system/service/ISysDictDataService.java b/src/main/java/com/ruoyi/system/system/service/ISysDictDataService.java new file mode 100644 index 0000000..deb9038 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ISysDictDataService.java @@ -0,0 +1,60 @@ +package com.ruoyi.system.system.service; + +import java.util.List; +import com.muta.common.core.domain.entity.SysDictData; + +/** + * 字典 业务层 + * + * @author mutaai + */ +public interface ISysDictDataService +{ + /** + * 根据条件分页查询字典数据 + * + * @param dictData 字典数据信息 + * @return 字典数据集合信息 + */ + public List selectDictDataList(SysDictData dictData); + + /** + * 根据字典类型和字典键值查询字典数据信息 + * + * @param dictType 字典类型 + * @param dictValue 字典键值 + * @return 字典标签 + */ + public String selectDictLabel(String dictType, String dictValue); + + /** + * 根据字典数据ID查询信息 + * + * @param dictCode 字典数据ID + * @return 字典数据 + */ + public SysDictData selectDictDataById(Long dictCode); + + /** + * 批量删除字典数据信息 + * + * @param dictCodes 需要删除的字典数据ID + */ + public void deleteDictDataByIds(Long[] dictCodes); + + /** + * 新增保存字典数据信息 + * + * @param dictData 字典数据信息 + * @return 结果 + */ + public int insertDictData(SysDictData dictData); + + /** + * 修改保存字典数据信息 + * + * @param dictData 字典数据信息 + * @return 结果 + */ + public int updateDictData(SysDictData dictData); +} diff --git a/src/main/java/com/ruoyi/system/system/service/ISysDictTypeService.java b/src/main/java/com/ruoyi/system/system/service/ISysDictTypeService.java new file mode 100644 index 0000000..ec4beee --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ISysDictTypeService.java @@ -0,0 +1,98 @@ +package com.ruoyi.system.system.service; + +import java.util.List; +import com.muta.common.core.domain.entity.SysDictData; +import com.muta.common.core.domain.entity.SysDictType; + +/** + * 字典 业务层 + * + * @author mutaai + */ +public interface ISysDictTypeService +{ + /** + * 根据条件分页查询字典类型 + * + * @param dictType 字典类型信息 + * @return 字典类型集合信息 + */ + public List selectDictTypeList(SysDictType dictType); + + /** + * 根据所有字典类型 + * + * @return 字典类型集合信息 + */ + public List selectDictTypeAll(); + + /** + * 根据字典类型查询字典数据 + * + * @param dictType 字典类型 + * @return 字典数据集合信息 + */ + public List selectDictDataByType(String dictType); + + /** + * 根据字典类型ID查询信息 + * + * @param dictId 字典类型ID + * @return 字典类型 + */ + public SysDictType selectDictTypeById(Long dictId); + + /** + * 根据字典类型查询信息 + * + * @param dictType 字典类型 + * @return 字典类型 + */ + public SysDictType selectDictTypeByType(String dictType); + + /** + * 批量删除字典信息 + * + * @param dictIds 需要删除的字典ID + */ + public void deleteDictTypeByIds(Long[] dictIds); + + /** + * 加载字典缓存数据 + */ + public void loadingDictCache(); + + /** + * 清空字典缓存数据 + */ + public void clearDictCache(); + + /** + * 重置字典缓存数据 + */ + public void resetDictCache(); + + /** + * 新增保存字典类型信息 + * + * @param dictType 字典类型信息 + * @return 结果 + */ + public int insertDictType(SysDictType dictType); + + /** + * 修改保存字典类型信息 + * + * @param dictType 字典类型信息 + * @return 结果 + */ + public int updateDictType(SysDictType dictType); + + /** + * 校验字典类型称是否唯一 + * + * @param dictType 字典类型 + * @return 结果 + */ + public boolean checkDictTypeUnique(SysDictType dictType); +} diff --git a/src/main/java/com/ruoyi/system/system/service/ISysLogininforService.java b/src/main/java/com/ruoyi/system/system/service/ISysLogininforService.java new file mode 100644 index 0000000..8630946 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ISysLogininforService.java @@ -0,0 +1,40 @@ +package com.ruoyi.system.system.service; + +import java.util.List; +import com.muta.system.domain.SysLogininfor; + +/** + * 系统访问日志情况信息 服务层 + * + * @author mutaai + */ +public interface ISysLogininforService +{ + /** + * 新增系统登录日志 + * + * @param logininfor 访问日志对象 + */ + public void insertLogininfor(SysLogininfor logininfor); + + /** + * 查询系统登录日志集合 + * + * @param logininfor 访问日志对象 + * @return 登录记录集合 + */ + public List selectLogininforList(SysLogininfor logininfor); + + /** + * 批量删除系统登录日志 + * + * @param infoIds 需要删除的登录日志ID + * @return 结果 + */ + public int deleteLogininforByIds(Long[] infoIds); + + /** + * 清空系统登录日志 + */ + public void cleanLogininfor(); +} diff --git a/src/main/java/com/ruoyi/system/system/service/ISysMenuService.java b/src/main/java/com/ruoyi/system/system/service/ISysMenuService.java new file mode 100644 index 0000000..e914162 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ISysMenuService.java @@ -0,0 +1,144 @@ +package com.ruoyi.system.system.service; + +import java.util.List; +import java.util.Set; +import com.muta.common.core.domain.TreeSelect; +import com.muta.common.core.domain.entity.SysMenu; +import com.muta.system.domain.vo.RouterVo; + +/** + * 菜单 业务层 + * + * @author mutaai + */ +public interface ISysMenuService +{ + /** + * 根据用户查询系统菜单列表 + * + * @param userId 用户ID + * @return 菜单列表 + */ + public List selectMenuList(Long userId); + + /** + * 根据用户查询系统菜单列表 + * + * @param menu 菜单信息 + * @param userId 用户ID + * @return 菜单列表 + */ + public List selectMenuList(SysMenu menu, Long userId); + + /** + * 根据用户ID查询权限 + * + * @param userId 用户ID + * @return 权限列表 + */ + public Set selectMenuPermsByUserId(Long userId); + + /** + * 根据角色ID查询权限 + * + * @param roleId 角色ID + * @return 权限列表 + */ + public Set selectMenuPermsByRoleId(Long roleId); + + /** + * 根据用户ID查询菜单树信息 + * + * @param userId 用户ID + * @return 菜单列表 + */ + public List selectMenuTreeByUserId(Long userId); + + /** + * 根据角色ID查询菜单树信息 + * + * @param roleId 角色ID + * @return 选中菜单列表 + */ + public List selectMenuListByRoleId(Long roleId); + + /** + * 构建前端路由所需要的菜单 + * + * @param menus 菜单列表 + * @return 路由列表 + */ + public List buildMenus(List menus); + + /** + * 构建前端所需要树结构 + * + * @param menus 菜单列表 + * @return 树结构列表 + */ + public List buildMenuTree(List menus); + + /** + * 构建前端所需要下拉树结构 + * + * @param menus 菜单列表 + * @return 下拉树结构列表 + */ + public List buildMenuTreeSelect(List menus); + + /** + * 根据菜单ID查询信息 + * + * @param menuId 菜单ID + * @return 菜单信息 + */ + public SysMenu selectMenuById(Long menuId); + + /** + * 是否存在菜单子节点 + * + * @param menuId 菜单ID + * @return 结果 true 存在 false 不存在 + */ + public boolean hasChildByMenuId(Long menuId); + + /** + * 查询菜单是否存在角色 + * + * @param menuId 菜单ID + * @return 结果 true 存在 false 不存在 + */ + public boolean checkMenuExistRole(Long menuId); + + /** + * 新增保存菜单信息 + * + * @param menu 菜单信息 + * @return 结果 + */ + public int insertMenu(SysMenu menu); + + /** + * 修改保存菜单信息 + * + * @param menu 菜单信息 + * @return 结果 + */ + public int updateMenu(SysMenu menu); + + /** + * 删除菜单管理信息 + * + * @param menuId 菜单ID + * @return 结果 + */ + public int deleteMenuById(Long menuId); + + /** + * 校验菜单名称是否唯一 + * + * @param menu 菜单信息 + * @return 结果 + */ + public boolean checkMenuNameUnique(SysMenu menu); +} diff --git a/src/main/java/com/ruoyi/system/system/service/ISysNoticeService.java b/src/main/java/com/ruoyi/system/system/service/ISysNoticeService.java new file mode 100644 index 0000000..a30703c --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ISysNoticeService.java @@ -0,0 +1,60 @@ +package com.ruoyi.system.system.service; + +import java.util.List; +import com.muta.system.domain.SysNotice; + +/** + * 公告 服务层 + * + * @author mutaai + */ +public interface ISysNoticeService +{ + /** + * 查询公告信息 + * + * @param noticeId 公告ID + * @return 公告信息 + */ + public SysNotice selectNoticeById(Long noticeId); + + /** + * 查询公告列表 + * + * @param notice 公告信息 + * @return 公告集合 + */ + public List selectNoticeList(SysNotice notice); + + /** + * 新增公告 + * + * @param notice 公告信息 + * @return 结果 + */ + public int insertNotice(SysNotice notice); + + /** + * 修改公告 + * + * @param notice 公告信息 + * @return 结果 + */ + public int updateNotice(SysNotice notice); + + /** + * 删除公告信息 + * + * @param noticeId 公告ID + * @return 结果 + */ + public int deleteNoticeById(Long noticeId); + + /** + * 批量删除公告信息 + * + * @param noticeIds 需要删除的公告ID + * @return 结果 + */ + public int deleteNoticeByIds(Long[] noticeIds); +} diff --git a/src/main/java/com/ruoyi/system/system/service/ISysOperLogService.java b/src/main/java/com/ruoyi/system/system/service/ISysOperLogService.java new file mode 100644 index 0000000..7c66d20 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ISysOperLogService.java @@ -0,0 +1,48 @@ +package com.ruoyi.system.system.service; + +import java.util.List; +import com.muta.system.domain.SysOperLog; + +/** + * 操作日志 服务层 + * + * @author mutaai + */ +public interface ISysOperLogService +{ + /** + * 新增操作日志 + * + * @param operLog 操作日志对象 + */ + public void insertOperlog(SysOperLog operLog); + + /** + * 查询系统操作日志集合 + * + * @param operLog 操作日志对象 + * @return 操作日志集合 + */ + public List selectOperLogList(SysOperLog operLog); + + /** + * 批量删除系统操作日志 + * + * @param operIds 需要删除的操作日志ID + * @return 结果 + */ + public int deleteOperLogByIds(Long[] operIds); + + /** + * 查询操作日志详细 + * + * @param operId 操作ID + * @return 操作日志对象 + */ + public SysOperLog selectOperLogById(Long operId); + + /** + * 清空操作日志 + */ + public void cleanOperLog(); +} diff --git a/src/main/java/com/ruoyi/system/system/service/ISysPostService.java b/src/main/java/com/ruoyi/system/system/service/ISysPostService.java new file mode 100644 index 0000000..2afc9a0 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ISysPostService.java @@ -0,0 +1,99 @@ +package com.ruoyi.system.system.service; + +import java.util.List; +import com.muta.system.domain.SysPost; + +/** + * 岗位信息 服务层 + * + * @author mutaai + */ +public interface ISysPostService +{ + /** + * 查询岗位信息集合 + * + * @param post 岗位信息 + * @return 岗位列表 + */ + public List selectPostList(SysPost post); + + /** + * 查询所有岗位 + * + * @return 岗位列表 + */ + public List selectPostAll(); + + /** + * 通过岗位ID查询岗位信息 + * + * @param postId 岗位ID + * @return 角色对象信息 + */ + public SysPost selectPostById(Long postId); + + /** + * 根据用户ID获取岗位选择框列表 + * + * @param userId 用户ID + * @return 选中岗位ID列表 + */ + public List selectPostListByUserId(Long userId); + + /** + * 校验岗位名称 + * + * @param post 岗位信息 + * @return 结果 + */ + public boolean checkPostNameUnique(SysPost post); + + /** + * 校验岗位编码 + * + * @param post 岗位信息 + * @return 结果 + */ + public boolean checkPostCodeUnique(SysPost post); + + /** + * 通过岗位ID查询岗位使用数量 + * + * @param postId 岗位ID + * @return 结果 + */ + public int countUserPostById(Long postId); + + /** + * 删除岗位信息 + * + * @param postId 岗位ID + * @return 结果 + */ + public int deletePostById(Long postId); + + /** + * 批量删除岗位信息 + * + * @param postIds 需要删除的岗位ID + * @return 结果 + */ + public int deletePostByIds(Long[] postIds); + + /** + * 新增保存岗位信息 + * + * @param post 岗位信息 + * @return 结果 + */ + public int insertPost(SysPost post); + + /** + * 修改保存岗位信息 + * + * @param post 岗位信息 + * @return 结果 + */ + public int updatePost(SysPost post); +} diff --git a/src/main/java/com/ruoyi/system/system/service/ISysRoleService.java b/src/main/java/com/ruoyi/system/system/service/ISysRoleService.java new file mode 100644 index 0000000..613606f --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ISysRoleService.java @@ -0,0 +1,173 @@ +package com.ruoyi.system.system.service; + +import java.util.List; +import java.util.Set; +import com.muta.common.core.domain.entity.SysRole; +import com.muta.system.domain.SysUserRole; + +/** + * 角色业务层 + * + * @author mutaai + */ +public interface ISysRoleService +{ + /** + * 根据条件分页查询角色数据 + * + * @param role 角色信息 + * @return 角色数据集合信息 + */ + public List selectRoleList(SysRole role); + + /** + * 根据用户ID查询角色列表 + * + * @param userId 用户ID + * @return 角色列表 + */ + public List selectRolesByUserId(Long userId); + + /** + * 根据用户ID查询角色权限 + * + * @param userId 用户ID + * @return 权限列表 + */ + public Set selectRolePermissionByUserId(Long userId); + + /** + * 查询所有角色 + * + * @return 角色列表 + */ + public List selectRoleAll(); + + /** + * 根据用户ID获取角色选择框列表 + * + * @param userId 用户ID + * @return 选中角色ID列表 + */ + public List selectRoleListByUserId(Long userId); + + /** + * 通过角色ID查询角色 + * + * @param roleId 角色ID + * @return 角色对象信息 + */ + public SysRole selectRoleById(Long roleId); + + /** + * 校验角色名称是否唯一 + * + * @param role 角色信息 + * @return 结果 + */ + public boolean checkRoleNameUnique(SysRole role); + + /** + * 校验角色权限是否唯一 + * + * @param role 角色信息 + * @return 结果 + */ + public boolean checkRoleKeyUnique(SysRole role); + + /** + * 校验角色是否允许操作 + * + * @param role 角色信息 + */ + public void checkRoleAllowed(SysRole role); + + /** + * 校验角色是否有数据权限 + * + * @param roleId 角色id + */ + public void checkRoleDataScope(Long roleId); + + /** + * 通过角色ID查询角色使用数量 + * + * @param roleId 角色ID + * @return 结果 + */ + public int countUserRoleByRoleId(Long roleId); + + /** + * 新增保存角色信息 + * + * @param role 角色信息 + * @return 结果 + */ + public int insertRole(SysRole role); + + /** + * 修改保存角色信息 + * + * @param role 角色信息 + * @return 结果 + */ + public int updateRole(SysRole role); + + /** + * 修改角色状态 + * + * @param role 角色信息 + * @return 结果 + */ + public int updateRoleStatus(SysRole role); + + /** + * 修改数据权限信息 + * + * @param role 角色信息 + * @return 结果 + */ + public int authDataScope(SysRole role); + + /** + * 通过角色ID删除角色 + * + * @param roleId 角色ID + * @return 结果 + */ + public int deleteRoleById(Long roleId); + + /** + * 批量删除角色信息 + * + * @param roleIds 需要删除的角色ID + * @return 结果 + */ + public int deleteRoleByIds(Long[] roleIds); + + /** + * 取消授权用户角色 + * + * @param userRole 用户和角色关联信息 + * @return 结果 + */ + public int deleteAuthUser(SysUserRole userRole); + + /** + * 批量取消授权用户角色 + * + * @param roleId 角色ID + * @param userIds 需要取消授权的用户数据ID + * @return 结果 + */ + public int deleteAuthUsers(Long roleId, Long[] userIds); + + /** + * 批量选择授权用户角色 + * + * @param roleId 角色ID + * @param userIds 需要删除的用户数据ID + * @return 结果 + */ + public int insertAuthUsers(Long roleId, Long[] userIds); +} diff --git a/src/main/java/com/ruoyi/system/system/service/ISysUserOnlineService.java b/src/main/java/com/ruoyi/system/system/service/ISysUserOnlineService.java new file mode 100644 index 0000000..0fc0b50 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ISysUserOnlineService.java @@ -0,0 +1,48 @@ +package com.ruoyi.system.system.service; + +import com.muta.common.core.domain.model.LoginUser; +import com.muta.system.domain.SysUserOnline; + +/** + * 在线用户 服务层 + * + * @author mutaai + */ +public interface ISysUserOnlineService +{ + /** + * 通过登录地址查询信息 + * + * @param ipaddr 登录地址 + * @param user 用户信息 + * @return 在线用户信息 + */ + public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user); + + /** + * 通过用户名称查询信息 + * + * @param userName 用户名称 + * @param user 用户信息 + * @return 在线用户信息 + */ + public SysUserOnline selectOnlineByUserName(String userName, LoginUser user); + + /** + * 通过登录地址/用户名称查询信息 + * + * @param ipaddr 登录地址 + * @param userName 用户名称 + * @param user 用户信息 + * @return 在线用户信息 + */ + public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user); + + /** + * 设置在线用户信息 + * + * @param user 用户信息 + * @return 在线用户 + */ + public SysUserOnline loginUserToUserOnline(LoginUser user); +} diff --git a/src/main/java/com/ruoyi/system/system/service/ISysUserService.java b/src/main/java/com/ruoyi/system/system/service/ISysUserService.java new file mode 100644 index 0000000..13e87d7 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/ISysUserService.java @@ -0,0 +1,238 @@ +package com.ruoyi.system.system.service; + +import java.util.List; + +import com.muta.common.annotation.IntegralLogInsert; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.core.domain.entity.UserExtra; +import com.muta.system.domain.vo.UserVO; +import org.springframework.scheduling.annotation.Async; + +/** + * 用户 业务层 + * + * @author mutaai + */ +public interface ISysUserService +{ + /** + * 根据条件分页查询用户列表 + * + * + * @return 用户信息集合信息 + + */ + String getNameById(Long userId); + + public List selectUserList(SysUser user); + + /** + * 根据条件分页查询已分配用户角色列表 + * + * @param user 用户信息 + * @return 用户信息集合信息 + */ + public List selectAllocatedList(SysUser user); + + /** + * 根据条件分页查询未分配用户角色列表 + * + * @param user 用户信息 + * @return 用户信息集合信息 + */ + public List selectUnallocatedList(SysUser user); + + /** + * 通过用户名查询用户 + * + * @param userName 用户名 + * @return 用户对象信息 + */ + public SysUser selectUserByUserName(String userName); + + /** + * 通过用户ID查询用户 + * + * @param userId 用户ID + * @return 用户对象信息 + */ + public SysUser selectUserById(Long userId); + + /** + * 根据用户ID查询用户所属角色组 + * + * @param userName 用户名 + * @return 结果 + */ + public String selectUserRoleGroup(String userName); + + /** + * 根据用户ID查询用户所属岗位组 + * + * @param userName 用户名 + * @return 结果 + */ + public String selectUserPostGroup(String userName); + + /** + * 校验用户名称是否唯一 + * + * @param user 用户信息 + * @return 结果 + */ + public boolean checkUserNameUnique(SysUser user); + + /** + * 校验手机号码是否唯一 + * + * @param user 用户信息 + * @return 结果 + */ + public boolean checkPhoneUnique(SysUser user); + + /** + * 校验email是否唯一 + * + * @param user 用户信息 + * @return 结果 + */ + public boolean checkEmailUnique(SysUser user); + + /** + * 校验用户是否允许操作 + * + * @param user 用户信息 + */ + public void checkUserAllowed(SysUser user); + + /** + * 校验用户是否有数据权限 + * + * @param userId 用户id + */ + public void checkUserDataScope(Long userId); + + + public long checkRegisterInvitedCode(UserExtra userExtra, String invitedCode, String username); + + /** + * 新增用户信息 + * + * @param user 用户信息 + * @return 结果 + */ + public int insertUser(SysUser user); + + /** + * 注册用户信息 + * + * @param user 用户信息 + * @return 结果 + */ + public boolean registerUser(SysUser user); + + /** + * 修改用户信息 + * + * @param user 用户信息 + * @return 结果 + */ + public int updateUser(SysUser user); + + /** + * 用户授权角色 + * + * @param userId 用户ID + * @param roleIds 角色组 + */ + public void insertUserAuth(Long userId, Long[] roleIds); + + /** + * 修改用户状态 + * + * @param user 用户信息 + * @return 结果 + */ + public int updateUserStatus(SysUser user); + + /** + * 修改用户基本信息 + * + * @param user 用户信息 + * @return 结果 + */ + public int updateUserProfile(SysUser user); + + /** + * 修改用户头像 + * + * @param userName 用户名 + * @param avatar 头像地址 + * @return 结果 + */ + public boolean updateUserAvatar(String userName, String avatar); + + /** + * 重置用户密码 + * + * @param user 用户信息 + * @return 结果 + */ + public int resetPwd(SysUser user); + + /** + * 重置用户密码 + * + * @param userName 用户名 + * @param password 密码 + * @return 结果 + */ + public int resetUserPwd(String userName, String password); + + /** + * 通过用户ID删除用户 + * + * @param userId 用户ID + * @return 结果 + */ + public int deleteUserById(Long userId); + + /** + * 批量删除用户信息 + * + * @param userIds 需要删除的用户ID + * @return 结果 + */ + public int deleteUserByIds(Long[] userIds); + + /** + * 导入用户数据 + * + * @param userList 用户数据列表 + * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据 + * @param operName 操作用户 + * @return 结果 + */ + public String importUser(List userList, Boolean isUpdateSupport, String operName); + + /** + * 初始化用户 + * @return + */ + public void initUser(SysUser user); + + /** + * 判断是否要生成admin_invited_code + * @param invitedCode + * @return + */ + public boolean checkInitAdminInviteCode(String invitedCode); + + /** + * 分发邀请奖励 + * @param user + */ + public void handOutAward(SysUser user); + public UserVO getUserInfo(); +} diff --git a/src/main/java/com/ruoyi/system/system/service/IUserExtraService.java b/src/main/java/com/ruoyi/system/system/service/IUserExtraService.java new file mode 100644 index 0000000..a1fc3b2 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/IUserExtraService.java @@ -0,0 +1,29 @@ +package com.ruoyi.system.system.service; +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.core.domain.entity.UserExtra; + +/** + *

+ * 服务类 + *

+ * + * @author zy + * @since 2024-04-17 + */ +public interface IUserExtraService extends IService { + + UserExtra getByUserId(Long userId); + + /** + * 插入用户额外信息 + * @param userExtra + */ + void insert(UserExtra userExtra); + void addIntegral(int count, Long userId); + Boolean IncreaseIntegral(int count, Long userId); + + Integer getIntegral(Long userId); + + +} diff --git a/src/main/java/com/ruoyi/system/system/service/IVipService.java b/src/main/java/com/ruoyi/system/system/service/IVipService.java new file mode 100644 index 0000000..c474b77 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/IVipService.java @@ -0,0 +1,17 @@ +package com.ruoyi.system.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.common.enums.VipType; +import com.muta.system.domain.Vip; + +import java.util.List; + +/** + * @author 马兰友 + * @Date: 2024/06/05/13:36 + */ +public interface IVipService extends IService { + List getList(); + VipType getVipTypeByUserId(Long userId); + void addVipDate(Long userId, Integer type, Integer value); +} diff --git a/src/main/java/com/ruoyi/system/system/service/SigninLogService.java b/src/main/java/com/ruoyi/system/system/service/SigninLogService.java new file mode 100644 index 0000000..f61b3fb --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/SigninLogService.java @@ -0,0 +1,12 @@ +package com.ruoyi.system.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.system.domain.SigninLog; + +import java.util.List; + +public interface SigninLogService extends IService { + + + List logList(); +} diff --git a/src/main/java/com/ruoyi/system/system/service/SigninService.java b/src/main/java/com/ruoyi/system/system/service/SigninService.java new file mode 100644 index 0000000..582fe31 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/SigninService.java @@ -0,0 +1,17 @@ +package com.ruoyi.system.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.system.domain.Signin; +import com.muta.system.domain.SigninTable; + +import java.util.List; + +public interface SigninService extends IService { + + + void insertUserSignin(Long userId); + + void tick(); + + List getTable(); +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/AliOssServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/AliOssServiceImpl.java new file mode 100644 index 0000000..2362a6b --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/AliOssServiceImpl.java @@ -0,0 +1,91 @@ +package com.ruoyi.system.system.service.impl; + +import com.muta.common.core.domain.R; +import com.muta.common.core.service.ISysFileService; +import com.muta.common.config.AliConfig; +import com.muta.common.utils.oss.OSSSignatureExample; +import com.muta.system.domain.FileConfig; +import com.muta.system.mapper.FileConfigMapper; +import com.muta.common.utils.oss.AliOSSUtils; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.io.*; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +/** + * @author: Larry + * @Date: 2024 /04 /20 / 21:47 + * @Description: + */ +@Service +public class AliOssServiceImpl implements ISysFileService { + + @Resource + private FileConfigMapper fileConfigMapper; + + private static AliConfig aliConfig; + + + @Override + public String uploadFile(MultipartFile file) throws Exception { + getConfig(); + String url = AliOSSUtils.upload(file, aliConfig); + return OSSSignatureExample.generateSignedUrl(aliConfig, url.substring(url.lastIndexOf("/") + 1)); + } + + @Override + public File getFileByUrl(String url) throws IOException { + // 创建URL对象 + URL fileUrl = new URL(url); + // 打开URL连接并获取输入流 + InputStream inputStream = fileUrl.openStream(); + // 将输入流转换为ByteArrayOutputStream + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + + // 将ByteArrayOutputStream转换为字节数组 + byte[] data = outputStream.toByteArray(); + + // 创建File对象 + File file = File.createTempFile("file", ".tmp"); + + // 将字节数组写入文件 + FileOutputStream fileOutputStream = new FileOutputStream(file); + fileOutputStream.write(data); + fileOutputStream.close(); + // 现在您可以使用file对象进行进一步的操作,例如读取文件内容等 + + return file; + } + + private void getConfig(){ + aliConfig = new AliConfig(); + getAliConfig(aliConfig); + } + + public void getConfig(AliConfig aliConfig){ + getAliConfig(aliConfig); + } + + private void getAliConfig(AliConfig aliConfig) { + FileConfig fileConfig = fileConfigMapper.selectConfig(aliConfig.getName()); + aliConfig.setId(fileConfig.getId()); + aliConfig.setAccessKeyId(fileConfig.getAccessKeyId()); + aliConfig.setAccessKeySecret(fileConfig.getAccessKeySecret()); + aliConfig.setBucket(fileConfig.getBucket()); + aliConfig.setRegion(fileConfig.getRegion()); + aliConfig.setEndpoint(fileConfig.getEndpoint()); + } + + +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/ColumnsServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/ColumnsServiceImpl.java new file mode 100644 index 0000000..3d77f04 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/ColumnsServiceImpl.java @@ -0,0 +1,25 @@ +package com.ruoyi.system.system.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.system.domain.TableColumns; +import com.muta.system.mapper.ColumnsMapper; +import com.muta.system.service.ColumnsService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service +public class ColumnsServiceImpl extends ServiceImpl implements ColumnsService { + + @Resource + private ColumnsMapper columnsMapper; + + @Override + public List getColumns(String tableName) { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(TableColumns::getTableName, tableName); + return columnsMapper.selectList(lqw); + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/CommonSettingServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/CommonSettingServiceImpl.java new file mode 100644 index 0000000..298aca0 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/CommonSettingServiceImpl.java @@ -0,0 +1,108 @@ +package com.ruoyi.system.system.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import java.util.List; + +import com.muta.common.constant.ModelConstants; +import com.muta.common.exception.ServiceException; +import com.muta.common.utils.DateUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.muta.system.mapper.CommonSettingMapper; +import com.muta.system.domain.CommonSetting; +import com.muta.system.service.ICommonSettingService; + +/** + * 设置Service业务层处理 + * + * @author mutaai + * @date 2024-04-22 + */ +@Service +public class CommonSettingServiceImpl extends ServiceImpl implements ICommonSettingService { + @Autowired + private CommonSettingMapper commonSettingMapper; + + /** + * 查询设置 + * + * @param id 设置主键 + * @return 设置 + */ + @Override + public CommonSetting selectCommonSettingById(Long id) { + return commonSettingMapper.selectCommonSettingById(id); + } + + /** + * 查询设置列表 + * + * @return 设置 + */ + @Override + public List selectCommonSettingList() { + return commonSettingMapper.selectCommonSettingList(); + } + + /** + * 修改设置 + * + * @param commonSetting 设置 + * @return 结果 + */ + @Override + public int updateCommonSetting(CommonSetting commonSetting) { + commonSetting.setUpdateTime(DateUtils.getNowDate()); + return commonSettingMapper.updateCommonSetting(commonSetting); + } + + /** + * 批量修改设置 + * + * @param commonSettings + */ + @Override + public void batchUpdateCommonSetting(List commonSettings) { + this.updateBatchById(commonSettings); + } + + /** + * 通过名字获取比例 + * + * @param name + * @return + */ + @Override + public Integer getRatioByName(String name) { + QueryWrapper wrapper = null; + CommonSetting setting = commonSettingMapper.selectOne(new QueryWrapper().eq("other", name)); + + if (ObjectUtils.isEmpty(setting)) { + return 0; + } + + name = setting.getName(); + if (name.equals(ModelConstants.KIMI_8K) + || name.equals(ModelConstants.KIMI_32K) + || name.equals(ModelConstants.KIMI_128K)) + { + wrapper = new QueryWrapper().eq("name", name); + return Integer.valueOf(commonSettingMapper.selectOne(wrapper).getValue()); + } + return 0; + } + + + @Override + public String getByName(String name) { + CommonSetting setting + = commonSettingMapper.selectOne(new QueryWrapper().eq("name", name)); + if (ObjectUtils.isEmpty(setting)) { + throw new ServiceException("未找到该配置"); + } + return setting.getValue(); + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/FileConfigServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/FileConfigServiceImpl.java new file mode 100644 index 0000000..817d2b9 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/FileConfigServiceImpl.java @@ -0,0 +1,36 @@ +package com.ruoyi.system.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.system.domain.FileConfig; +import com.muta.system.mapper.FileConfigMapper; +import com.muta.system.service.IFileConfigService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /04 /21 / 15:14 + * @Description: + */ +@Service +public class FileConfigServiceImpl extends ServiceImpl implements IFileConfigService { + @Resource + private FileConfigMapper fileConfigMapper; + + @Override + public FileConfig getByName(String name) { + return fileConfigMapper.selectConfig(name); + } + + @Override + public List selectFileConfigList(FileConfig fileConfig) { + return fileConfigMapper.selectList(null); + } + + @Override + public void updateFileConfigList(FileConfig fileConfig) { + fileConfigMapper.updateConfig(fileConfig); + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SigninLogServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SigninLogServiceImpl.java new file mode 100644 index 0000000..1444991 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SigninLogServiceImpl.java @@ -0,0 +1,25 @@ +package com.ruoyi.system.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.system.domain.SigninLog; +import com.muta.system.mapper.SigninLogMapper; +import com.muta.system.service.SigninLogService; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service("mySingnLlog") +public class SigninLogServiceImpl extends ServiceImpl implements SigninLogService { + + @Resource + private SigninLogMapper signinLogMapper; + + + @Override + public List logList() { + return signinLogMapper.logList(new SysUser()); + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SigninServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SigninServiceImpl.java new file mode 100644 index 0000000..382bccc --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SigninServiceImpl.java @@ -0,0 +1,146 @@ +package com.ruoyi.system.system.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.common.enums.SigninStatus; +import com.muta.common.utils.SecurityUtils; +import com.muta.common.utils.ip.IpUtils; +import com.muta.log.service.impl.SigninIntegralLogServiceImpl; +import com.muta.system.domain.Signin; +import com.muta.system.domain.SigninLog; +import com.muta.system.domain.SigninTable; +import com.muta.system.mapper.SigninLogMapper; +import com.muta.system.mapper.SigninMapper; +import com.muta.system.service.IUserExtraService; +import com.muta.system.service.SigninService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + +@Service +public class SigninServiceImpl extends ServiceImpl implements SigninService { + + private static final Integer WEEK_COUNT = 7; + private static final Integer BASIC_INTEGRAL = 100; + private static final Integer BASIC_WEIGHT = 1; + private static final Integer PERSENT = 100; + + private static final String NOT_SIGNIN = "未签到"; + private static final String SIGNIN = "已签到"; + + @Resource + private SigninMapper signinMapper; + + @Resource + private SigninLogMapper signinLogMapper; + + @Resource + private IUserExtraService userExtraService; + @Resource + private SigninIntegralLogServiceImpl signinIntegralLogService; + /** + * 新增用户时 同步新增签到数据 + * @param userId + * @author FrankieFly + */ + @Override + public void insertUserSignin(Long userId) { + // 日历函数 获取本月天数 + Calendar calendar = Calendar.getInstance(); + Integer days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); + + // 二进制模拟签到(置为全部未签) + String status = SigninStatus.NOT_SIGNIN.getCode().repeat(days); + + signinMapper.insert( + Signin.builder() + .ip(IpUtils.getIpAddr()) + .status(status) + .userId(userId) + .build() + ); + } + + /** + * 签到 + * @author FrankieFly + */ + @Override + public void tick() { + Long userId = SecurityUtils.getUserId(); + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + + // 根据 userId 获取签到对象 + lqw.eq(Signin::getUserId, userId); + Signin signin = signinMapper.selectOne(lqw); + + // 计算当前为本月第几天 + LocalDate today = LocalDate.now(); + int index = today.getDayOfMonth(); + + // StringBuffer 对字符串天数对应位置改动 置为签到 + StringBuffer status = new StringBuffer(signin.getStatus()); + status.setCharAt(index - 1, SigninStatus.SIGNIN.getCode().charAt(0)); + + // 累积签到天数加 1 + signin.setCount(signin.getCount() + 1); + signin.setStatus(status.toString()); + + // 每连续签到一周 积分权重增加 1%(仅当天) + Integer integral = BASIC_INTEGRAL; + if (signin.getCount() % WEEK_COUNT == 0) + integral = integral * (BASIC_WEIGHT + signin.getCount() / WEEK_COUNT / PERSENT); + + signinMapper.update(signin, lqw); + signinLogMapper.insert(SigninLog.builder() + .ip(IpUtils.getIpAddr()) + .userName(SecurityUtils.getUsername()) + .userId(userId) + .signinTime(LocalDateTime.now()) + .status(SIGNIN) + .build()); + + signinIntegralLogService.insertSign(integral); + userExtraService.addIntegral(integral, userId); + } + + /** + * 签到i表格 + * @author FrankieFly + */ + @Override + public List getTable() { + List list = new ArrayList<>(); + Long userId = SecurityUtils.getUserId(); + + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(Signin::getUserId, userId); + + Signin signin = signinMapper.selectOne(lqw); + // 获取当前日期 + LocalDate today = LocalDate.now(); + + // 获取本月第一天的日期 + LocalDate firstDayOfMonth = today.withDayOfMonth(1); + + LocalDate firstDayOfNextMonth = firstDayOfMonth.plusMonths(1); + + // 计算本月的所有日期 + LocalDate currentDay = firstDayOfMonth; + + char[] statusArray = signin.getStatus().toCharArray(); + + for (char c : statusArray) { + list.add(new SigninTable(currentDay, c == '0' ? NOT_SIGNIN : SIGNIN)); + if (currentDay.isBefore(firstDayOfNextMonth)) + currentDay = currentDay.plusDays(1); + } + + return list; + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SysConfigServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SysConfigServiceImpl.java new file mode 100644 index 0000000..b665b1d --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SysConfigServiceImpl.java @@ -0,0 +1,234 @@ +package com.ruoyi.system.system.service.impl; + +import java.util.Collection; +import java.util.List; +import javax.annotation.PostConstruct; + +import cn.hutool.core.convert.Convert; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.muta.common.annotation.DataSource; +import com.muta.common.constant.CacheConstants; +import com.muta.common.constant.UserConstants; +import com.muta.common.core.redis.RedisCache; + +import com.muta.common.enums.DataSourceType; +import com.muta.common.exception.ServiceException; +import com.muta.common.utils.StringUtils; +import com.muta.system.domain.SysConfig; +import com.muta.system.mapper.SysConfigMapper; +import com.muta.system.service.ISysConfigService; + +/** + * 参数配置 服务层实现 + * + * @author mutaai + */ +@Service +public class SysConfigServiceImpl implements ISysConfigService +{ + @Autowired + private SysConfigMapper configMapper; + + @Autowired + private RedisCache redisCache; + + /** + * 项目启动时,初始化参数到缓存 + */ + @PostConstruct + public void init() + { + loadingConfigCache(); + } + + /** + * 查询参数配置信息 + * + * @param configId 参数配置ID + * @return 参数配置信息 + */ + @Override + @DataSource(DataSourceType.MASTER) + public SysConfig selectConfigById(Long configId) + { + SysConfig config = new SysConfig(); + config.setConfigId(configId); + return configMapper.selectConfig(config); + } + + /** + * 根据键名查询参数配置信息 + * + * @param configKey 参数key + * @return 参数键值 + */ + @Override + public String selectConfigByKey(String configKey) + { + String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey))); + if (StringUtils.isNotEmpty(configValue)) + { + return configValue; + } + SysConfig config = new SysConfig(); + config.setConfigKey(configKey); + SysConfig retConfig = configMapper.selectConfig(config); + if (StringUtils.isNotNull(retConfig)) + { + redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue()); + return retConfig.getConfigValue(); + } + return StringUtils.EMPTY; + } + + /** + * 获取验证码开关 + * + * @return true开启,false关闭 + */ + @Override + public boolean selectCaptchaEnabled() + { + String captchaEnabled = selectConfigByKey("sys.account.captchaEnabled"); + if (StringUtils.isEmpty(captchaEnabled)) + { + return true; + } + return Convert.toBool(captchaEnabled); + } + + /** + * 查询参数配置列表 + * + * @param config 参数配置信息 + * @return 参数配置集合 + */ + @Override + public List selectConfigList(SysConfig config) + { + return configMapper.selectConfigList(config); + } + + /** + * 新增参数配置 + * + * @param config 参数配置信息 + * @return 结果 + */ + @Override + public int insertConfig(SysConfig config) + { + int row = configMapper.insertConfig(config); + if (row > 0) + { + redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + } + return row; + } + + /** + * 修改参数配置 + * + * @param config 参数配置信息 + * @return 结果 + */ + @Override + public int updateConfig(SysConfig config) + { + SysConfig temp = configMapper.selectConfigById(config.getConfigId()); + if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) + { + redisCache.deleteObject(getCacheKey(temp.getConfigKey())); + } + + int row = configMapper.updateConfig(config); + if (row > 0) + { + redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + } + return row; + } + + /** + * 批量删除参数信息 + * + * @param configIds 需要删除的参数ID + */ + @Override + public void deleteConfigByIds(Long[] configIds) + { + for (Long configId : configIds) + { + SysConfig config = selectConfigById(configId); + if (StringUtils.equals(UserConstants.YES, config.getConfigType())) + { + throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey())); + } + configMapper.deleteConfigById(configId); + redisCache.deleteObject(getCacheKey(config.getConfigKey())); + } + } + + /** + * 加载参数缓存数据 + */ + @Override + public void loadingConfigCache() + { + List configsList = configMapper.selectConfigList(new SysConfig()); + for (SysConfig config : configsList) + { + redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + } + } + + /** + * 清空参数缓存数据 + */ + @Override + public void clearConfigCache() + { + Collection keys = redisCache.keys(CacheConstants.SYS_CONFIG_KEY + "*"); + redisCache.deleteObject(keys); + } + + /** + * 重置参数缓存数据 + */ + @Override + public void resetConfigCache() + { + clearConfigCache(); + loadingConfigCache(); + } + + /** + * 校验参数键名是否唯一 + * + * @param config 参数配置信息 + * @return 结果 + */ + @Override + public boolean checkConfigKeyUnique(SysConfig config) + { + Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId(); + SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey()); + if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 设置cache key + * + * @param configKey 参数键 + * @return 缓存键key + */ + private String getCacheKey(String configKey) + { + return CacheConstants.SYS_CONFIG_KEY + configKey; + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SysDeptServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SysDeptServiceImpl.java new file mode 100644 index 0000000..08a057e --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SysDeptServiceImpl.java @@ -0,0 +1,340 @@ +package com.ruoyi.system.system.service.impl; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +import cn.hutool.core.convert.Convert; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.muta.common.annotation.DataScope; +import com.muta.common.constant.UserConstants; +import com.muta.common.core.domain.TreeSelect; +import com.muta.common.core.domain.entity.SysDept; +import com.muta.common.core.domain.entity.SysRole; +import com.muta.common.core.domain.entity.SysUser; + +import com.muta.common.exception.ServiceException; +import com.muta.common.utils.SecurityUtils; +import com.muta.common.utils.StringUtils; +import com.muta.common.utils.spring.SpringUtils; +import com.muta.system.mapper.SysDeptMapper; +import com.muta.system.mapper.SysRoleMapper; +import com.muta.system.service.ISysDeptService; + +/** + * 部门管理 服务实现 + * + * @author mutaai + */ +@Service +public class SysDeptServiceImpl implements ISysDeptService +{ + @Autowired + private SysDeptMapper deptMapper; + + @Autowired + private SysRoleMapper roleMapper; + + /** + * 查询部门管理数据 + * + * @param dept 部门信息 + * @return 部门信息集合 + */ + @Override + + public List selectDeptList(SysDept dept) + { + return deptMapper.selectDeptList(dept); + } + + /** + * 查询部门树结构信息 + * + * @param dept 部门信息 + * @return 部门树信息集合 + */ + @Override + public List selectDeptTreeList(SysDept dept) + { + List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); + return buildDeptTreeSelect(depts); + } + + /** + * 构建前端所需要树结构 + * + * @param depts 部门列表 + * @return 树结构列表 + */ + @Override + public List buildDeptTree(List depts) + { + List returnList = new ArrayList(); + List tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList()); + for (SysDept dept : depts) + { + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(dept.getParentId())) + { + recursionFn(depts, dept); + returnList.add(dept); + } + } + if (returnList.isEmpty()) + { + returnList = depts; + } + return returnList; + } + + /** + * 构建前端所需要下拉树结构 + * + * @param depts 部门列表 + * @return 下拉树结构列表 + */ + @Override + public List buildDeptTreeSelect(List depts) + { + List deptTrees = buildDeptTree(depts); + return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + /** + * 根据角色ID查询部门树信息 + * + * @param roleId 角色ID + * @return 选中部门列表 + */ + @Override + public List selectDeptListByRoleId(Long roleId) + { + SysRole role = roleMapper.selectRoleById(roleId); + return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly()); + } + + /** + * 根据部门ID查询信息 + * + * @param deptId 部门ID + * @return 部门信息 + */ + @Override + public SysDept selectDeptById(Long deptId) + { + return deptMapper.selectDeptById(deptId); + } + + /** + * 根据ID查询所有子部门(正常状态) + * + * @param deptId 部门ID + * @return 子部门数 + */ + @Override + public int selectNormalChildrenDeptById(Long deptId) + { + return deptMapper.selectNormalChildrenDeptById(deptId); + } + + /** + * 是否存在子节点 + * + * @param deptId 部门ID + * @return 结果 + */ + @Override + public boolean hasChildByDeptId(Long deptId) + { + int result = deptMapper.hasChildByDeptId(deptId); + return result > 0; + } + + /** + * 查询部门是否存在用户 + * + * @param deptId 部门ID + * @return 结果 true 存在 false 不存在 + */ + @Override + public boolean checkDeptExistUser(Long deptId) + { + int result = deptMapper.checkDeptExistUser(deptId); + return result > 0; + } + + /** + * 校验部门名称是否唯一 + * + * @param dept 部门信息 + * @return 结果 + */ + @Override + public boolean checkDeptNameUnique(SysDept dept) + { + Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId(); + SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId()); + if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 校验部门是否有数据权限 + * + * @param deptId 部门id + */ + @Override + public void checkDeptDataScope(Long deptId) + { + if (!SysUser.isAdmin(SecurityUtils.getUserId())) + { + SysDept dept = new SysDept(); + dept.setDeptId(deptId); + List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); + if (StringUtils.isEmpty(depts)) + { + throw new ServiceException("没有权限访问部门数据!"); + } + } + } + + /** + * 新增保存部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + @Override + public int insertDept(SysDept dept) + { + SysDept info = deptMapper.selectDeptById(dept.getParentId()); + // 如果父节点不为正常状态,则不允许新增子节点 + if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) + { + throw new ServiceException("部门停用,不允许新增"); + } + dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); + return deptMapper.insertDept(dept); + } + + /** + * 修改保存部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + @Override + public int updateDept(SysDept dept) + { + SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId()); + SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId()); + if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) + { + String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId(); + String oldAncestors = oldDept.getAncestors(); + dept.setAncestors(newAncestors); + updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); + } + int result = deptMapper.updateDept(dept); + if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) + && !StringUtils.equals("0", dept.getAncestors())) + { + // 如果该部门是启用状态,则启用该部门的所有上级部门 + updateParentDeptStatusNormal(dept); + } + return result; + } + + /** + * 修改该部门的父级部门状态 + * + * @param dept 当前部门 + */ + private void updateParentDeptStatusNormal(SysDept dept) + { + String ancestors = dept.getAncestors(); + Long[] deptIds = Convert.toLongArray(ancestors); + deptMapper.updateDeptStatusNormal(deptIds); + } + + /** + * 修改子元素关系 + * + * @param deptId 被修改的部门ID + * @param newAncestors 新的父ID集合 + * @param oldAncestors 旧的父ID集合 + */ + public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) + { + List children = deptMapper.selectChildrenDeptById(deptId); + for (SysDept child : children) + { + child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); + } + if (children.size() > 0) + { + deptMapper.updateDeptChildren(children); + } + } + + /** + * 删除部门管理信息 + * + * @param deptId 部门ID + * @return 结果 + */ + @Override + public int deleteDeptById(Long deptId) + { + return deptMapper.deleteDeptById(deptId); + } + + /** + * 递归列表 + */ + private void recursionFn(List list, SysDept t) + { + // 得到子节点列表 + List childList = getChildList(list, t); + t.setChildren(childList); + for (SysDept tChild : childList) + { + if (hasChild(list, tChild)) + { + recursionFn(list, tChild); + } + } + } + + /** + * 得到子节点列表 + */ + private List getChildList(List list, SysDept t) + { + List tlist = new ArrayList(); + Iterator it = list.iterator(); + while (it.hasNext()) + { + SysDept n = (SysDept) it.next(); + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) + { + tlist.add(n); + } + } + return tlist; + } + + /** + * 判断是否有子节点 + */ + private boolean hasChild(List list, SysDept t) + { + return getChildList(list, t).size() > 0; + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SysDictDataServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SysDictDataServiceImpl.java new file mode 100644 index 0000000..c90a941 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SysDictDataServiceImpl.java @@ -0,0 +1,111 @@ +package com.ruoyi.system.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.muta.common.core.domain.entity.SysDictData; +import com.muta.common.utils.DictUtils; +import com.muta.system.mapper.SysDictDataMapper; +import com.muta.system.service.ISysDictDataService; + +/** + * 字典 业务层处理 + * + * @author mutaai + */ +@Service +public class SysDictDataServiceImpl implements ISysDictDataService +{ + @Autowired + private SysDictDataMapper dictDataMapper; + + /** + * 根据条件分页查询字典数据 + * + * @param dictData 字典数据信息 + * @return 字典数据集合信息 + */ + @Override + public List selectDictDataList(SysDictData dictData) + { + return dictDataMapper.selectDictDataList(dictData); + } + + /** + * 根据字典类型和字典键值查询字典数据信息 + * + * @param dictType 字典类型 + * @param dictValue 字典键值 + * @return 字典标签 + */ + @Override + public String selectDictLabel(String dictType, String dictValue) + { + return dictDataMapper.selectDictLabel(dictType, dictValue); + } + + /** + * 根据字典数据ID查询信息 + * + * @param dictCode 字典数据ID + * @return 字典数据 + */ + @Override + public SysDictData selectDictDataById(Long dictCode) + { + return dictDataMapper.selectDictDataById(dictCode); + } + + /** + * 批量删除字典数据信息 + * + * @param dictCodes 需要删除的字典数据ID + */ + @Override + public void deleteDictDataByIds(Long[] dictCodes) + { + for (Long dictCode : dictCodes) + { + SysDictData data = selectDictDataById(dictCode); + dictDataMapper.deleteDictDataById(dictCode); + List dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); + DictUtils.setDictCache(data.getDictType(), dictDatas); + } + } + + /** + * 新增保存字典数据信息 + * + * @param data 字典数据信息 + * @return 结果 + */ + @Override + public int insertDictData(SysDictData data) + { + int row = dictDataMapper.insertDictData(data); + if (row > 0) + { + List dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); + DictUtils.setDictCache(data.getDictType(), dictDatas); + } + return row; + } + + /** + * 修改保存字典数据信息 + * + * @param data 字典数据信息 + * @return 结果 + */ + @Override + public int updateDictData(SysDictData data) + { + int row = dictDataMapper.updateDictData(data); + if (row > 0) + { + List dictDatas = dictDataMapper.selectDictDataByType(data.getDictType()); + DictUtils.setDictCache(data.getDictType(), dictDatas); + } + return row; + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SysDictTypeServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SysDictTypeServiceImpl.java new file mode 100644 index 0000000..197c625 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SysDictTypeServiceImpl.java @@ -0,0 +1,223 @@ +package com.ruoyi.system.system.service.impl; + +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import javax.annotation.PostConstruct; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.muta.common.constant.UserConstants; +import com.muta.common.core.domain.entity.SysDictData; +import com.muta.common.core.domain.entity.SysDictType; +import com.muta.common.exception.ServiceException; +import com.muta.common.utils.DictUtils; +import com.muta.common.utils.StringUtils; +import com.muta.system.mapper.SysDictDataMapper; +import com.muta.system.mapper.SysDictTypeMapper; +import com.muta.system.service.ISysDictTypeService; + +/** + * 字典 业务层处理 + * + * @author mutaai + */ +@Service +public class SysDictTypeServiceImpl implements ISysDictTypeService +{ + @Autowired + private SysDictTypeMapper dictTypeMapper; + + @Autowired + private SysDictDataMapper dictDataMapper; + + /** + * 项目启动时,初始化字典到缓存 + */ + @PostConstruct + public void init() + { + loadingDictCache(); + } + + /** + * 根据条件分页查询字典类型 + * + * @param dictType 字典类型信息 + * @return 字典类型集合信息 + */ + @Override + public List selectDictTypeList(SysDictType dictType) + { + return dictTypeMapper.selectDictTypeList(dictType); + } + + /** + * 根据所有字典类型 + * + * @return 字典类型集合信息 + */ + @Override + public List selectDictTypeAll() + { + return dictTypeMapper.selectDictTypeAll(); + } + + /** + * 根据字典类型查询字典数据 + * + * @param dictType 字典类型 + * @return 字典数据集合信息 + */ + @Override + public List selectDictDataByType(String dictType) + { + List dictDatas = DictUtils.getDictCache(dictType); + if (StringUtils.isNotEmpty(dictDatas)) + { + return dictDatas; + } + dictDatas = dictDataMapper.selectDictDataByType(dictType); + if (StringUtils.isNotEmpty(dictDatas)) + { + DictUtils.setDictCache(dictType, dictDatas); + return dictDatas; + } + return null; + } + + /** + * 根据字典类型ID查询信息 + * + * @param dictId 字典类型ID + * @return 字典类型 + */ + @Override + public SysDictType selectDictTypeById(Long dictId) + { + return dictTypeMapper.selectDictTypeById(dictId); + } + + /** + * 根据字典类型查询信息 + * + * @param dictType 字典类型 + * @return 字典类型 + */ + @Override + public SysDictType selectDictTypeByType(String dictType) + { + return dictTypeMapper.selectDictTypeByType(dictType); + } + + /** + * 批量删除字典类型信息 + * + * @param dictIds 需要删除的字典ID + */ + @Override + public void deleteDictTypeByIds(Long[] dictIds) + { + for (Long dictId : dictIds) + { + SysDictType dictType = selectDictTypeById(dictId); + if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) + { + throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName())); + } + dictTypeMapper.deleteDictTypeById(dictId); + DictUtils.removeDictCache(dictType.getDictType()); + } + } + + /** + * 加载字典缓存数据 + */ + @Override + public void loadingDictCache() + { + SysDictData dictData = new SysDictData(); + dictData.setStatus("0"); + Map> dictDataMap = dictDataMapper.selectDictDataList(dictData).stream().collect(Collectors.groupingBy(SysDictData::getDictType)); + for (Map.Entry> entry : dictDataMap.entrySet()) + { + DictUtils.setDictCache(entry.getKey(), entry.getValue().stream().sorted(Comparator.comparing(SysDictData::getDictSort)).collect(Collectors.toList())); + } + } + + /** + * 清空字典缓存数据 + */ + @Override + public void clearDictCache() + { + DictUtils.clearDictCache(); + } + + /** + * 重置字典缓存数据 + */ + @Override + public void resetDictCache() + { + clearDictCache(); + loadingDictCache(); + } + + /** + * 新增保存字典类型信息 + * + * @param dict 字典类型信息 + * @return 结果 + */ + @Override + public int insertDictType(SysDictType dict) + { + int row = dictTypeMapper.insertDictType(dict); + if (row > 0) + { + DictUtils.setDictCache(dict.getDictType(), null); + } + return row; + } + + /** + * 修改保存字典类型信息 + * + * @param dict 字典类型信息 + * @return 结果 + */ + @Override + @Transactional + public int updateDictType(SysDictType dict) + { + SysDictType oldDict = dictTypeMapper.selectDictTypeById(dict.getDictId()); + dictDataMapper.updateDictDataType(oldDict.getDictType(), dict.getDictType()); + int row = dictTypeMapper.updateDictType(dict); + if (row > 0) + { + List dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType()); + DictUtils.setDictCache(dict.getDictType(), dictDatas); + } + return row; + } + + /** + * 校验字典类型称是否唯一 + * + * @param dict 字典类型 + * @return 结果 + */ + @Override + public boolean checkDictTypeUnique(SysDictType dict) + { + Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId(); + SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType()); + if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SysLogininforServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SysLogininforServiceImpl.java new file mode 100644 index 0000000..4edb2f0 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SysLogininforServiceImpl.java @@ -0,0 +1,65 @@ +package com.ruoyi.system.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.muta.system.domain.SysLogininfor; +import com.muta.system.mapper.SysLogininforMapper; +import com.muta.system.service.ISysLogininforService; + +/** + * 系统访问日志情况信息 服务层处理 + * + * @author mutaai + */ +@Service +public class SysLogininforServiceImpl implements ISysLogininforService +{ + + @Autowired + private SysLogininforMapper logininforMapper; + + /** + * 新增系统登录日志 + * + * @param logininfor 访问日志对象 + */ + @Override + public void insertLogininfor(SysLogininfor logininfor) + { + logininforMapper.insertLogininfor(logininfor); + } + + /** + * 查询系统登录日志集合 + * + * @param logininfor 访问日志对象 + * @return 登录记录集合 + */ + @Override + public List selectLogininforList(SysLogininfor logininfor) + { + return logininforMapper.selectLogininforList(logininfor); + } + + /** + * 批量删除系统登录日志 + * + * @param infoIds 需要删除的登录日志ID + * @return 结果 + */ + @Override + public int deleteLogininforByIds(Long[] infoIds) + { + return logininforMapper.deleteLogininforByIds(infoIds); + } + + /** + * 清空系统登录日志 + */ + @Override + public void cleanLogininfor() + { + logininforMapper.cleanLogininfor(); + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SysMenuServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SysMenuServiceImpl.java new file mode 100644 index 0000000..ac02614 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SysMenuServiceImpl.java @@ -0,0 +1,531 @@ +package com.ruoyi.system.system.service.impl; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.muta.common.constant.Constants; +import com.muta.common.constant.UserConstants; +import com.muta.common.core.domain.TreeSelect; +import com.muta.common.core.domain.entity.SysMenu; +import com.muta.common.core.domain.entity.SysRole; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.utils.SecurityUtils; +import com.muta.common.utils.StringUtils; +import com.muta.system.domain.vo.MetaVo; +import com.muta.system.domain.vo.RouterVo; +import com.muta.system.mapper.SysMenuMapper; +import com.muta.system.mapper.SysRoleMapper; +import com.muta.system.mapper.SysRoleMenuMapper; +import com.muta.system.service.ISysMenuService; + +/** + * 菜单 业务层处理 + * + * @author mutaai + */ +@Service +public class SysMenuServiceImpl implements ISysMenuService +{ + public static final String PREMISSION_STRING = "perms[\"{0}\"]"; + + @Autowired + private SysMenuMapper menuMapper; + + @Autowired + private SysRoleMapper roleMapper; + + @Autowired + private SysRoleMenuMapper roleMenuMapper; + + /** + * 根据用户查询系统菜单列表 + * + * @param userId 用户ID + * @return 菜单列表 + */ + @Override + public List selectMenuList(Long userId) + { + return selectMenuList(new SysMenu(), userId); + } + + /** + * 查询系统菜单列表 + * + * @param menu 菜单信息 + * @return 菜单列表 + */ + @Override + public List selectMenuList(SysMenu menu, Long userId) + { + List menuList = null; + // 管理员显示所有菜单信息 + if (SysUser.isAdmin(userId)) + { + menuList = menuMapper.selectMenuList(menu); + } + else + { + menu.getParams().put("userId", userId); + menuList = menuMapper.selectMenuListByUserId(menu); + } + return menuList; + } + + /** + * 根据用户ID查询权限 + * + * @param userId 用户ID + * @return 权限列表 + */ + @Override + public Set selectMenuPermsByUserId(Long userId) + { + List perms = menuMapper.selectMenuPermsByUserId(userId); + Set permsSet = new HashSet<>(); + for (String perm : perms) + { + if (StringUtils.isNotEmpty(perm)) + { + permsSet.addAll(Arrays.asList(perm.trim().split(","))); + } + } + return permsSet; + } + + /** + * 根据角色ID查询权限 + * + * @param roleId 角色ID + * @return 权限列表 + */ + @Override + public Set selectMenuPermsByRoleId(Long roleId) + { + List perms = menuMapper.selectMenuPermsByRoleId(roleId); + Set permsSet = new HashSet<>(); + for (String perm : perms) + { + if (StringUtils.isNotEmpty(perm)) + { + permsSet.addAll(Arrays.asList(perm.trim().split(","))); + } + } + return permsSet; + } + + /** + * 根据用户ID查询菜单 + * + * @param userId 用户名称 + * @return 菜单列表 + */ + @Override + public List selectMenuTreeByUserId(Long userId) + { + List menus = null; + if (SecurityUtils.isAdmin(userId)) + { + menus = menuMapper.selectMenuTreeAll(); + } + else + { + menus = menuMapper.selectMenuTreeByUserId(userId); + } + return getChildPerms(menus, 0); + } + + /** + * 根据角色ID查询菜单树信息 + * + * @param roleId 角色ID + * @return 选中菜单列表 + */ + @Override + public List selectMenuListByRoleId(Long roleId) + { + SysRole role = roleMapper.selectRoleById(roleId); + return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly()); + } + + /** + * 构建前端路由所需要的菜单 + * + * @param menus 菜单列表 + * @return 路由列表 + */ + @Override + public List buildMenus(List menus) + { + List routers = new LinkedList(); + for (SysMenu menu : menus) + { + RouterVo router = new RouterVo(); + router.setHidden("1".equals(menu.getVisible())); + router.setName(getRouteName(menu)); + router.setPath(getRouterPath(menu)); + router.setComponent(getComponent(menu)); + router.setQuery(menu.getQuery()); + router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); + List cMenus = menu.getChildren(); + if (StringUtils.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType())) + { + router.setAlwaysShow(true); + router.setRedirect("noRedirect"); + router.setChildren(buildMenus(cMenus)); + } + else if (isMenuFrame(menu)) + { + router.setMeta(null); + List childrenList = new ArrayList(); + RouterVo children = new RouterVo(); + children.setPath(menu.getPath()); + children.setComponent(menu.getComponent()); + children.setName(StringUtils.capitalize(menu.getPath())); + children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath())); + children.setQuery(menu.getQuery()); + childrenList.add(children); + router.setChildren(childrenList); + } + else if (menu.getParentId().intValue() == 0 && isInnerLink(menu)) + { + router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); + router.setPath("/"); + List childrenList = new ArrayList(); + RouterVo children = new RouterVo(); + String routerPath = innerLinkReplaceEach(menu.getPath()); + children.setPath(routerPath); + children.setComponent(UserConstants.INNER_LINK); + children.setName(StringUtils.capitalize(routerPath)); + children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getPath())); + childrenList.add(children); + router.setChildren(childrenList); + } + routers.add(router); + } + return routers; + } + + /** + * 构建前端所需要树结构 + * + * @param menus 菜单列表 + * @return 树结构列表 + */ + @Override + public List buildMenuTree(List menus) + { + List returnList = new ArrayList(); + List tempList = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList()); + for (Iterator iterator = menus.iterator(); iterator.hasNext();) + { + SysMenu menu = (SysMenu) iterator.next(); + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(menu.getParentId())) + { + recursionFn(menus, menu); + returnList.add(menu); + } + } + if (returnList.isEmpty()) + { + returnList = menus; + } + return returnList; + } + + /** + * 构建前端所需要下拉树结构 + * + * @param menus 菜单列表 + * @return 下拉树结构列表 + */ + @Override + public List buildMenuTreeSelect(List menus) + { + List menuTrees = buildMenuTree(menus); + return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + /** + * 根据菜单ID查询信息 + * + * @param menuId 菜单ID + * @return 菜单信息 + */ + @Override + public SysMenu selectMenuById(Long menuId) + { + return menuMapper.selectMenuById(menuId); + } + + /** + * 是否存在菜单子节点 + * + * @param menuId 菜单ID + * @return 结果 + */ + @Override + public boolean hasChildByMenuId(Long menuId) + { + int result = menuMapper.hasChildByMenuId(menuId); + return result > 0; + } + + /** + * 查询菜单使用数量 + * + * @param menuId 菜单ID + * @return 结果 + */ + @Override + public boolean checkMenuExistRole(Long menuId) + { + int result = roleMenuMapper.checkMenuExistRole(menuId); + return result > 0; + } + + /** + * 新增保存菜单信息 + * + * @param menu 菜单信息 + * @return 结果 + */ + @Override + public int insertMenu(SysMenu menu) + { + return menuMapper.insertMenu(menu); + } + + /** + * 修改保存菜单信息 + * + * @param menu 菜单信息 + * @return 结果 + */ + @Override + public int updateMenu(SysMenu menu) + { + return menuMapper.updateMenu(menu); + } + + /** + * 删除菜单管理信息 + * + * @param menuId 菜单ID + * @return 结果 + */ + @Override + public int deleteMenuById(Long menuId) + { + return menuMapper.deleteMenuById(menuId); + } + + /** + * 校验菜单名称是否唯一 + * + * @param menu 菜单信息 + * @return 结果 + */ + @Override + public boolean checkMenuNameUnique(SysMenu menu) + { + Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId(); + SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId()); + if (StringUtils.isNotNull(info) && info.getMenuId().longValue() != menuId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 获取路由名称 + * + * @param menu 菜单信息 + * @return 路由名称 + */ + public String getRouteName(SysMenu menu) + { + String routerName = StringUtils.capitalize(menu.getPath()); + // 非外链并且是一级目录(类型为目录) + if (isMenuFrame(menu)) + { + routerName = StringUtils.EMPTY; + } + return routerName; + } + + /** + * 获取路由地址 + * + * @param menu 菜单信息 + * @return 路由地址 + */ + public String getRouterPath(SysMenu menu) + { + String routerPath = menu.getPath(); + // 内链打开外网方式 + if (menu.getParentId().intValue() != 0 && isInnerLink(menu)) + { + routerPath = innerLinkReplaceEach(routerPath); + } + // 非外链并且是一级目录(类型为目录) + if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType()) + && UserConstants.NO_FRAME.equals(menu.getIsFrame())) + { + routerPath = "/" + menu.getPath(); + } + // 非外链并且是一级目录(类型为菜单) + else if (isMenuFrame(menu)) + { + routerPath = "/"; + } + return routerPath; + } + + /** + * 获取组件信息 + * + * @param menu 菜单信息 + * @return 组件信息 + */ + public String getComponent(SysMenu menu) + { + String component = UserConstants.LAYOUT; + if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu)) + { + component = menu.getComponent(); + } + else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu)) + { + component = UserConstants.INNER_LINK; + } + else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) + { + component = UserConstants.PARENT_VIEW; + } + return component; + } + + /** + * 是否为菜单内部跳转 + * + * @param menu 菜单信息 + * @return 结果 + */ + public boolean isMenuFrame(SysMenu menu) + { + return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType()) + && menu.getIsFrame().equals(UserConstants.NO_FRAME); + } + + /** + * 是否为内链组件 + * + * @param menu 菜单信息 + * @return 结果 + */ + public boolean isInnerLink(SysMenu menu) + { + return menu.getIsFrame().equals(UserConstants.NO_FRAME) && StringUtils.ishttp(menu.getPath()); + } + + /** + * 是否为parent_view组件 + * + * @param menu 菜单信息 + * @return 结果 + */ + public boolean isParentView(SysMenu menu) + { + return menu.getParentId().intValue() != 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType()); + } + + /** + * 根据父节点的ID获取所有子节点 + * + * @param list 分类表 + * @param parentId 传入的父节点ID + * @return String + */ + public List getChildPerms(List list, int parentId) + { + List returnList = new ArrayList(); + for (Iterator iterator = list.iterator(); iterator.hasNext();) + { + SysMenu t = (SysMenu) iterator.next(); + // 一、根据传入的某个父节点ID,遍历该父节点的所有子节点 + if (t.getParentId() == parentId) + { + recursionFn(list, t); + returnList.add(t); + } + } + return returnList; + } + + /** + * 递归列表 + * + * @param list 分类表 + * @param t 子节点 + */ + private void recursionFn(List list, SysMenu t) + { + // 得到子节点列表 + List childList = getChildList(list, t); + t.setChildren(childList); + for (SysMenu tChild : childList) + { + if (hasChild(list, tChild)) + { + recursionFn(list, tChild); + } + } + } + + /** + * 得到子节点列表 + */ + private List getChildList(List list, SysMenu t) + { + List tlist = new ArrayList(); + Iterator it = list.iterator(); + while (it.hasNext()) + { + SysMenu n = (SysMenu) it.next(); + if (n.getParentId().longValue() == t.getMenuId().longValue()) + { + tlist.add(n); + } + } + return tlist; + } + + /** + * 判断是否有子节点 + */ + private boolean hasChild(List list, SysMenu t) + { + return getChildList(list, t).size() > 0; + } + + /** + * 内链域名特殊字符替换 + * + * @return 替换后的内链域名 + */ + public String innerLinkReplaceEach(String path) + { + return StringUtils.replaceEach(path, new String[] { Constants.HTTP, Constants.HTTPS, Constants.WWW, ".", ":" }, + new String[] { "", "", "", "/", "/" }); + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SysNoticeServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SysNoticeServiceImpl.java new file mode 100644 index 0000000..e739524 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SysNoticeServiceImpl.java @@ -0,0 +1,92 @@ +package com.ruoyi.system.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.muta.system.domain.SysNotice; +import com.muta.system.mapper.SysNoticeMapper; +import com.muta.system.service.ISysNoticeService; + +/** + * 公告 服务层实现 + * + * @author mutaai + */ +@Service +public class SysNoticeServiceImpl implements ISysNoticeService +{ + @Autowired + private SysNoticeMapper noticeMapper; + + /** + * 查询公告信息 + * + * @param noticeId 公告ID + * @return 公告信息 + */ + @Override + public SysNotice selectNoticeById(Long noticeId) + { + return noticeMapper.selectNoticeById(noticeId); + } + + /** + * 查询公告列表 + * + * @param notice 公告信息 + * @return 公告集合 + */ + @Override + public List selectNoticeList(SysNotice notice) + { + return noticeMapper.selectNoticeList(notice); + } + + /** + * 新增公告 + * + * @param notice 公告信息 + * @return 结果 + */ + @Override + public int insertNotice(SysNotice notice) + { + return noticeMapper.insertNotice(notice); + } + + /** + * 修改公告 + * + * @param notice 公告信息 + * @return 结果 + */ + @Override + public int updateNotice(SysNotice notice) + { + return noticeMapper.updateNotice(notice); + } + + /** + * 删除公告对象 + * + * @param noticeId 公告ID + * @return 结果 + */ + @Override + public int deleteNoticeById(Long noticeId) + { + return noticeMapper.deleteNoticeById(noticeId); + } + + /** + * 批量删除公告信息 + * + * @param noticeIds 需要删除的公告ID + * @return 结果 + */ + @Override + public int deleteNoticeByIds(Long[] noticeIds) + { + return noticeMapper.deleteNoticeByIds(noticeIds); + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SysOperLogServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SysOperLogServiceImpl.java new file mode 100644 index 0000000..ab53762 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SysOperLogServiceImpl.java @@ -0,0 +1,76 @@ +package com.ruoyi.system.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.muta.system.domain.SysOperLog; +import com.muta.system.mapper.SysOperLogMapper; +import com.muta.system.service.ISysOperLogService; + +/** + * 操作日志 服务层处理 + * + * @author mutaai + */ +@Service +public class SysOperLogServiceImpl implements ISysOperLogService +{ + @Autowired + private SysOperLogMapper operLogMapper; + + /** + * 新增操作日志 + * + * @param operLog 操作日志对象 + */ + @Override + public void insertOperlog(SysOperLog operLog) + { + operLogMapper.insertOperlog(operLog); + } + + /** + * 查询系统操作日志集合 + * + * @param operLog 操作日志对象 + * @return 操作日志集合 + */ + @Override + public List selectOperLogList(SysOperLog operLog) + { + return operLogMapper.selectOperLogList(operLog); + } + + /** + * 批量删除系统操作日志 + * + * @param operIds 需要删除的操作日志ID + * @return 结果 + */ + @Override + public int deleteOperLogByIds(Long[] operIds) + { + return operLogMapper.deleteOperLogByIds(operIds); + } + + /** + * 查询操作日志详细 + * + * @param operId 操作ID + * @return 操作日志对象 + */ + @Override + public SysOperLog selectOperLogById(Long operId) + { + return operLogMapper.selectOperLogById(operId); + } + + /** + * 清空操作日志 + */ + @Override + public void cleanOperLog() + { + operLogMapper.cleanOperLog(); + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SysPostServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SysPostServiceImpl.java new file mode 100644 index 0000000..c0d6932 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SysPostServiceImpl.java @@ -0,0 +1,178 @@ +package com.ruoyi.system.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.muta.common.constant.UserConstants; +import com.muta.common.exception.ServiceException; +import com.muta.common.utils.StringUtils; +import com.muta.system.domain.SysPost; +import com.muta.system.mapper.SysPostMapper; +import com.muta.system.mapper.SysUserPostMapper; +import com.muta.system.service.ISysPostService; + +/** + * 岗位信息 服务层处理 + * + * @author mutaai + */ +@Service +public class SysPostServiceImpl implements ISysPostService +{ + @Autowired + private SysPostMapper postMapper; + + @Autowired + private SysUserPostMapper userPostMapper; + + /** + * 查询岗位信息集合 + * + * @param post 岗位信息 + * @return 岗位信息集合 + */ + @Override + public List selectPostList(SysPost post) + { + return postMapper.selectPostList(post); + } + + /** + * 查询所有岗位 + * + * @return 岗位列表 + */ + @Override + public List selectPostAll() + { + return postMapper.selectPostAll(); + } + + /** + * 通过岗位ID查询岗位信息 + * + * @param postId 岗位ID + * @return 角色对象信息 + */ + @Override + public SysPost selectPostById(Long postId) + { + return postMapper.selectPostById(postId); + } + + /** + * 根据用户ID获取岗位选择框列表 + * + * @param userId 用户ID + * @return 选中岗位ID列表 + */ + @Override + public List selectPostListByUserId(Long userId) + { + return postMapper.selectPostListByUserId(userId); + } + + /** + * 校验岗位名称是否唯一 + * + * @param post 岗位信息 + * @return 结果 + */ + @Override + public boolean checkPostNameUnique(SysPost post) + { + Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); + SysPost info = postMapper.checkPostNameUnique(post.getPostName()); + if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 校验岗位编码是否唯一 + * + * @param post 岗位信息 + * @return 结果 + */ + @Override + public boolean checkPostCodeUnique(SysPost post) + { + Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); + SysPost info = postMapper.checkPostCodeUnique(post.getPostCode()); + if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 通过岗位ID查询岗位使用数量 + * + * @param postId 岗位ID + * @return 结果 + */ + @Override + public int countUserPostById(Long postId) + { + return userPostMapper.countUserPostById(postId); + } + + /** + * 删除岗位信息 + * + * @param postId 岗位ID + * @return 结果 + */ + @Override + public int deletePostById(Long postId) + { + return postMapper.deletePostById(postId); + } + + /** + * 批量删除岗位信息 + * + * @param postIds 需要删除的岗位ID + * @return 结果 + */ + @Override + public int deletePostByIds(Long[] postIds) + { + for (Long postId : postIds) + { + SysPost post = selectPostById(postId); + if (countUserPostById(postId) > 0) + { + throw new ServiceException(String.format("%1$s已分配,不能删除", post.getPostName())); + } + } + return postMapper.deletePostByIds(postIds); + } + + /** + * 新增保存岗位信息 + * + * @param post 岗位信息 + * @return 结果 + */ + @Override + public int insertPost(SysPost post) + { + return postMapper.insertPost(post); + } + + /** + * 修改保存岗位信息 + * + * @param post 岗位信息 + * @return 结果 + */ + @Override + public int updatePost(SysPost post) + { + return postMapper.updatePost(post); + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SysRoleServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SysRoleServiceImpl.java new file mode 100644 index 0000000..044124b --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SysRoleServiceImpl.java @@ -0,0 +1,423 @@ +package com.ruoyi.system.system.service.impl; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.muta.common.annotation.DataScope; +import com.muta.common.constant.UserConstants; +import com.muta.common.core.domain.entity.SysRole; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.exception.ServiceException; +import com.muta.common.utils.SecurityUtils; +import com.muta.common.utils.StringUtils; +import com.muta.common.utils.spring.SpringUtils; +import com.muta.system.domain.SysRoleDept; +import com.muta.system.domain.SysRoleMenu; +import com.muta.system.domain.SysUserRole; +import com.muta.system.mapper.SysRoleDeptMapper; +import com.muta.system.mapper.SysRoleMapper; +import com.muta.system.mapper.SysRoleMenuMapper; +import com.muta.system.mapper.SysUserRoleMapper; +import com.muta.system.service.ISysRoleService; + +/** + * 角色 业务层处理 + * + * @author mutaai + */ +@Service +public class SysRoleServiceImpl implements ISysRoleService +{ + @Autowired + private SysRoleMapper roleMapper; + + @Autowired + private SysRoleMenuMapper roleMenuMapper; + + @Autowired + private SysUserRoleMapper userRoleMapper; + + @Autowired + private SysRoleDeptMapper roleDeptMapper; + + /** + * 根据条件分页查询角色数据 + * + * @param role 角色信息 + * @return 角色数据集合信息 + */ + @Override + public List selectRoleList(SysRole role) + { + return roleMapper.selectRoleList(role); + } + + /** + * 根据用户ID查询角色 + * + * @param userId 用户ID + * @return 角色列表 + */ + @Override + public List selectRolesByUserId(Long userId) + { + List userRoles = roleMapper.selectRolePermissionByUserId(userId); + List roles = selectRoleAll(); + for (SysRole role : roles) + { + for (SysRole userRole : userRoles) + { + if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) + { + role.setFlag(true); + break; + } + } + } + return roles; + } + + /** + * 根据用户ID查询权限 + * + * @param userId 用户ID + * @return 权限列表 + */ + @Override + public Set selectRolePermissionByUserId(Long userId) + { + List perms = roleMapper.selectRolePermissionByUserId(userId); + Set permsSet = new HashSet<>(); + for (SysRole perm : perms) + { + if (StringUtils.isNotNull(perm)) + { + permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(","))); + } + } + return permsSet; + } + + /** + * 查询所有角色 + * + * @return 角色列表 + */ + @Override + public List selectRoleAll() + { + return SpringUtils.getAopProxy(this).selectRoleList(new SysRole()); + } + + /** + * 根据用户ID获取角色选择框列表 + * + * @param userId 用户ID + * @return 选中角色ID列表 + */ + @Override + public List selectRoleListByUserId(Long userId) + { + return roleMapper.selectRoleListByUserId(userId); + } + + /** + * 通过角色ID查询角色 + * + * @param roleId 角色ID + * @return 角色对象信息 + */ + @Override + public SysRole selectRoleById(Long roleId) + { + return roleMapper.selectRoleById(roleId); + } + + /** + * 校验角色名称是否唯一 + * + * @param role 角色信息 + * @return 结果 + */ + @Override + public boolean checkRoleNameUnique(SysRole role) + { + Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); + SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName()); + if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 校验角色权限是否唯一 + * + * @param role 角色信息 + * @return 结果 + */ + @Override + public boolean checkRoleKeyUnique(SysRole role) + { + Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); + SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey()); + if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 校验角色是否允许操作 + * + * @param role 角色信息 + */ + @Override + public void checkRoleAllowed(SysRole role) + { + if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) + { + throw new ServiceException("不允许操作超级管理员角色"); + } + } + + /** + * 校验角色是否有数据权限 + * + * @param roleId 角色id + */ + @Override + public void checkRoleDataScope(Long roleId) + { + if (!SysUser.isAdmin(SecurityUtils.getUserId())) + { + SysRole role = new SysRole(); + role.setRoleId(roleId); + List roles = SpringUtils.getAopProxy(this).selectRoleList(role); + if (StringUtils.isEmpty(roles)) + { + throw new ServiceException("没有权限访问角色数据!"); + } + } + } + + /** + * 通过角色ID查询角色使用数量 + * + * @param roleId 角色ID + * @return 结果 + */ + @Override + public int countUserRoleByRoleId(Long roleId) + { + return userRoleMapper.countUserRoleByRoleId(roleId); + } + + /** + * 新增保存角色信息 + * + * @param role 角色信息 + * @return 结果 + */ + @Override + @Transactional + public int insertRole(SysRole role) + { + // 新增角色信息 + roleMapper.insertRole(role); + return insertRoleMenu(role); + } + + /** + * 修改保存角色信息 + * + * @param role 角色信息 + * @return 结果 + */ + @Override + @Transactional + public int updateRole(SysRole role) + { + // 修改角色信息 + roleMapper.updateRole(role); + // 删除角色与菜单关联 + roleMenuMapper.deleteRoleMenuByRoleId(role.getRoleId()); + return insertRoleMenu(role); + } + + /** + * 修改角色状态 + * + * @param role 角色信息 + * @return 结果 + */ + @Override + public int updateRoleStatus(SysRole role) + { + return roleMapper.updateRole(role); + } + + /** + * 修改数据权限信息 + * + * @param role 角色信息 + * @return 结果 + */ + @Override + @Transactional + public int authDataScope(SysRole role) + { + // 修改角色信息 + roleMapper.updateRole(role); + // 删除角色与部门关联 + roleDeptMapper.deleteRoleDeptByRoleId(role.getRoleId()); + // 新增角色和部门信息(数据权限) + return insertRoleDept(role); + } + + /** + * 新增角色菜单信息 + * + * @param role 角色对象 + */ + public int insertRoleMenu(SysRole role) + { + int rows = 1; + // 新增用户与角色管理 + List list = new ArrayList(); + for (Long menuId : role.getMenuIds()) + { + SysRoleMenu rm = new SysRoleMenu(); + rm.setRoleId(role.getRoleId()); + rm.setMenuId(menuId); + list.add(rm); + } + if (list.size() > 0) + { + rows = roleMenuMapper.batchRoleMenu(list); + } + return rows; + } + + /** + * 新增角色部门信息(数据权限) + * + * @param role 角色对象 + */ + public int insertRoleDept(SysRole role) + { + int rows = 1; + // 新增角色与部门(数据权限)管理 + List list = new ArrayList(); + for (Long deptId : role.getDeptIds()) + { + SysRoleDept rd = new SysRoleDept(); + rd.setRoleId(role.getRoleId()); + rd.setDeptId(deptId); + list.add(rd); + } + if (list.size() > 0) + { + rows = roleDeptMapper.batchRoleDept(list); + } + return rows; + } + + /** + * 通过角色ID删除角色 + * + * @param roleId 角色ID + * @return 结果 + */ + @Override + @Transactional + public int deleteRoleById(Long roleId) + { + // 删除角色与菜单关联 + roleMenuMapper.deleteRoleMenuByRoleId(roleId); + // 删除角色与部门关联 + roleDeptMapper.deleteRoleDeptByRoleId(roleId); + return roleMapper.deleteRoleById(roleId); + } + + /** + * 批量删除角色信息 + * + * @param roleIds 需要删除的角色ID + * @return 结果 + */ + @Override + @Transactional + public int deleteRoleByIds(Long[] roleIds) + { + for (Long roleId : roleIds) + { + checkRoleAllowed(new SysRole(roleId)); + checkRoleDataScope(roleId); + SysRole role = selectRoleById(roleId); + if (countUserRoleByRoleId(roleId) > 0) + { + throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName())); + } + } + // 删除角色与菜单关联 + roleMenuMapper.deleteRoleMenu(roleIds); + // 删除角色与部门关联 + roleDeptMapper.deleteRoleDept(roleIds); + return roleMapper.deleteRoleByIds(roleIds); + } + + /** + * 取消授权用户角色 + * + * @param userRole 用户和角色关联信息 + * @return 结果 + */ + @Override + public int deleteAuthUser(SysUserRole userRole) + { + return userRoleMapper.deleteUserRoleInfo(userRole); + } + + /** + * 批量取消授权用户角色 + * + * @param roleId 角色ID + * @param userIds 需要取消授权的用户数据ID + * @return 结果 + */ + @Override + public int deleteAuthUsers(Long roleId, Long[] userIds) + { + return userRoleMapper.deleteUserRoleInfos(roleId, userIds); + } + + /** + * 批量选择授权用户角色 + * + * @param roleId 角色ID + * @param userIds 需要授权的用户数据ID + * @return 结果 + */ + @Override + public int insertAuthUsers(Long roleId, Long[] userIds) + { + // 新增用户与角色管理 + List list = new ArrayList(); + for (Long userId : userIds) + { + SysUserRole ur = new SysUserRole(); + ur.setUserId(userId); + ur.setRoleId(roleId); + list.add(ur); + } + return userRoleMapper.batchUserRole(list); + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SysUserOnlineServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SysUserOnlineServiceImpl.java new file mode 100644 index 0000000..3d9d812 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SysUserOnlineServiceImpl.java @@ -0,0 +1,93 @@ +package com.ruoyi.system.system.service.impl; + +import org.springframework.stereotype.Service; +import com.muta.common.core.domain.model.LoginUser; +import com.muta.common.utils.StringUtils; +import com.muta.system.domain.SysUserOnline; +import com.muta.system.service.ISysUserOnlineService; + +/** + * 在线用户 服务层处理 + * + * @author mutaai + */ +@Service +public class SysUserOnlineServiceImpl implements ISysUserOnlineService +{ + /** + * 通过登录地址查询信息 + * + * @param ipaddr 登录地址 + * @param user 用户信息 + * @return 在线用户信息 + */ + @Override + public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user) + { + if (StringUtils.equals(ipaddr, user.getIpaddr())) + { + return loginUserToUserOnline(user); + } + return null; + } + + /** + * 通过用户名称查询信息 + * + * @param userName 用户名称 + * @param user 用户信息 + * @return 在线用户信息 + */ + @Override + public SysUserOnline selectOnlineByUserName(String userName, LoginUser user) + { + if (StringUtils.equals(userName, user.getUsername())) + { + return loginUserToUserOnline(user); + } + return null; + } + + /** + * 通过登录地址/用户名称查询信息 + * + * @param ipaddr 登录地址 + * @param userName 用户名称 + * @param user 用户信息 + * @return 在线用户信息 + */ + @Override + public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user) + { + if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) + { + return loginUserToUserOnline(user); + } + return null; + } + + /** + * 设置在线用户信息 + * + * @param user 用户信息 + * @return 在线用户 + */ + @Override + public SysUserOnline loginUserToUserOnline(LoginUser user) + { + if (StringUtils.isNull(user) || StringUtils.isNull(user.getUser())) + { + return null; + } + SysUserOnline sysUserOnline = new SysUserOnline(); + sysUserOnline.setTokenId(user.getToken()); + sysUserOnline.setUserName(user.getUsername()); + sysUserOnline.setIpaddr(user.getIpaddr()); + sysUserOnline.setLoginLocation(user.getLoginLocation()); + sysUserOnline.setBrowser(user.getBrowser()); + sysUserOnline.setOs(user.getOs()); + sysUserOnline.setLoginTime(user.getLoginTime()); + + return sysUserOnline; + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/SysUserServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/SysUserServiceImpl.java new file mode 100644 index 0000000..7238bd2 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/SysUserServiceImpl.java @@ -0,0 +1,823 @@ +package com.ruoyi.system.system.service.impl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import javax.annotation.Resource; +import javax.validation.Validator; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.muta.common.annotation.DataPermission; +import com.muta.common.annotation.IntegralLogInsert; +import com.muta.common.constant.OperationConstants; +import com.muta.common.core.domain.entity.UserExtra; +import com.muta.common.enums.VipType; +import com.muta.log.domain.IntegralLog; +import com.muta.log.domain.InviteLog; +import com.muta.log.domain.dto.InviteLogDTO; +import com.muta.log.factory.IntegralLogFactory; +import com.muta.log.service.IInviteLogService; +import com.muta.system.domain.vo.UserVO; +import com.muta.system.mapper.*; +import com.muta.system.service.ISysUserService; +import com.muta.system.service.IUserExtraService; +import com.muta.system.service.IVipService; +import org.apache.commons.lang3.RandomStringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; +import com.muta.common.annotation.DataScope; +import com.muta.common.constant.UserConstants; +import com.muta.common.core.domain.entity.SysRole; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.exception.ServiceException; +import com.muta.common.utils.SecurityUtils; +import com.muta.common.utils.StringUtils; +import com.muta.common.utils.bean.BeanValidators; +import com.muta.common.utils.spring.SpringUtils; +import com.muta.system.domain.SysPost; +import com.muta.system.domain.SysUserPost; +import com.muta.system.domain.SysUserRole; +import com.muta.system.service.ISysConfigService; +import org.springframework.util.ObjectUtils; + +/** + * 用户 业务层处理 + * + * @author mutaai + */ +@Service +public class SysUserServiceImpl implements ISysUserService +{ + private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class); + + @Autowired + private SysUserMapper userMapper; + + @Autowired + private SysRoleMapper roleMapper; + + @Autowired + private SysPostMapper postMapper; + + @Autowired + private SysUserRoleMapper userRoleMapper; + + @Autowired + private SysUserPostMapper userPostMapper; + + @Autowired + private ISysConfigService configService; + @Autowired + private IUserExtraService userExtraService; + + @Autowired + protected Validator validator; + @Autowired + private UserExtraMapper userExtraMapper; + @Resource + private IInviteLogService iInviteLogService; + @Resource + private IntegralLogFactory integralLogFactory; + @Resource + private IVipService vipService; + + + @Override + public String getNameById(Long userId) { + return userMapper.getNameById(userId); + } + + /** + * 根据条件分页查询用户列表 + * + * @param user 用户信息 + * @return 用户信息集合信息 + */ + + @Override + @DataScope() + public List selectUserList(SysUser user) + { + + List userList = userMapper.selectUserList(user); + userList.forEach( + sysUser -> System.out.println(sysUser.getUserExtra()) + ); + return userList; + } + + /** + * 根据条件分页查询已分配用户角色列表 + * + * @param user 用户信息 + * @return 用户信息集合信息 + */ + @Override + @DataScope(userExtra = "ue", userAlias = "u") + public List selectAllocatedList(SysUser user) + { + return userMapper.selectAllocatedList(user); + } + + /** + * 根据条件分页查询未分配用户角色列表 + * + * @param user 用户信息 + * @return 用户信息集合信息 + */ + @Override + public List selectUnallocatedList(SysUser user) + { + return userMapper.selectUnallocatedList(user); + } + + /** + * 通过用户名查询用户 + * + * @param userName 用户名 + * @return 用户对象信息 + */ + @Override + public SysUser selectUserByUserName(String userName) + { + return userMapper.selectUserByUserName(userName); + } + + /** + * 通过用户ID查询用户 + * + * @param userId 用户ID + * @return 用户对象信息 + */ + @Override + public SysUser selectUserById(Long userId) + { + SysUser sysUser = userMapper.selectUserById(userId); + UserExtra userExtra = + userExtraMapper.selectOne(new QueryWrapper().eq("user_id", userId)); + sysUser.setUserExtra(userExtra); + return sysUser; + } + + /** + * 查询用户所属角色组 + * + * @param userName 用户名 + * @return 结果 + */ + @Override + public String selectUserRoleGroup(String userName) + { + List list = roleMapper.selectRolesByUserName(userName); + if (CollectionUtils.isEmpty(list)) + { + return StringUtils.EMPTY; + } + return list.stream().map(SysRole::getRoleName).collect(Collectors.joining(",")); + } + + /** + * 查询用户所属岗位组 + * + * @param userName 用户名 + * @return 结果 + */ + @Override + public String selectUserPostGroup(String userName) + { + List list = postMapper.selectPostsByUserName(userName); + if (CollectionUtils.isEmpty(list)) + { + return StringUtils.EMPTY; + } + return list.stream().map(SysPost::getPostName).collect(Collectors.joining(",")); + } + + /** + * 校验用户名称是否唯一 + * + * @param user 用户信息 + * @return 结果 + */ + @Override + public boolean checkUserNameUnique(SysUser user) + { + Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); + SysUser info = userMapper.checkUserNameUnique(user.getUserName()); + if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 校验手机号码是否唯一 + * + * @param user 用户信息 + * @return + */ + @Override + public boolean checkPhoneUnique(SysUser user) + { + Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); + SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber()); + if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 校验email是否唯一 + * + * @param user 用户信息 + * @return + */ + @Override + public boolean checkEmailUnique(SysUser user) + { + Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId(); + SysUser info = userMapper.checkEmailUnique(user.getEmail()); + if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) + { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 校验用户是否允许操作 + * + * @param user 用户信息 + */ + @Override + public void checkUserAllowed(SysUser user) + { + if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) + { + throw new ServiceException("不允许操作超级管理员用户"); + } + } + + /** + * 校验用户是否有数据权限 + * + * @param userId 用户id + */ + @Override + public void checkUserDataScope(Long userId) + { + if (!SysUser.isAdmin(SecurityUtils.getUserId())) + { + SysUser user = new SysUser(); + user.setUserId(userId); + List users = SpringUtils.getAopProxy(this).selectUserList(user); + if (StringUtils.isEmpty(users)) + { + throw new ServiceException("没有权限访问用户数据!"); + } + } + } + + /** + * 校验用户注册时填入的邀请码 + * @param userExtra 用户 + * @param invitedCode 用户注册时填入的验证码 + * @return 权限id + */ + public long checkRegisterInvitedCode (UserExtra userExtra, String invitedCode, String username) { + if (StrUtil.isEmpty(invitedCode)) { + //没填邀请码 最近管理员id 和父级id直接设为超级管理员id + userExtra.setLowestId(1L); + userExtra.setSuperiorId(1L); + return 2; + } + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(UserExtra::getInviteCode, invitedCode); + //首先查询该邀请码是否是用户邀请码 若是 是谁的邀请码 + UserExtra parent = userExtraMapper.selectOne(lqw); + if (!ObjectUtils.isEmpty(parent)) { + checkLog(userExtra, invitedCode, username, parent); + LambdaQueryWrapper surLqw = new LambdaQueryWrapper<>(); + surLqw.eq(SysUserRole::getUserId, parent.getUserId()); + //判断上级身份 + List sysUserRoles = userRoleMapper.selectList(surLqw); + if (sysUserRoles.stream().anyMatch(sur -> sur.getRoleId() == 104)) { + //若是二级管理员 那最近管理员id就是该管理员 + userExtra.setLowestId(parent.getUserId()); + //其一级代理的id就是最近管理员的一级代理id + userExtra.setFirstId(parent.getFirstId()); + } else if (sysUserRoles.stream().anyMatch(sur -> sur.getRoleId() == 103)) { + //若是一级管理员 那么最近管理员id就是该管理员 + userExtra.setLowestId(parent.getUserId()); + //其一级代理id就是该管理员id + userExtra.setFirstId(parent.getUserId()); + } + else { + //若是用户 那最近管理员id就是父级用户的最近管理员id 这里用了并查集的思想 + userExtra.setLowestId(parent.getLowestId()); + userExtra.setFirstId(parent.getFirstId()); + } + return 2; + } + lqw = new LambdaQueryWrapper<>(); + lqw.eq(UserExtra::getAdminInviteCode, invitedCode); + //该邀请码不是用户邀请码 所以查看他是不是管理员邀请码 + parent = userExtraMapper.selectOne(lqw); + if (!ObjectUtils.isEmpty(parent)) { + checkLog(userExtra, invitedCode, username, parent); + userExtra.setLowestId(parent.getUserId()); + userExtra.setFirstId(parent.getUserId()); + LambdaQueryWrapper surLqw = new LambdaQueryWrapper<>(); + surLqw.eq(SysUserRole::getUserId, parent.getUserId()); + //查询上级身份 + List sysUserRoles = userRoleMapper.selectList(surLqw); + if (sysUserRoles.stream().anyMatch(sur -> sur.getRoleId() == 1)) { + //若是超级管理员 因为超级管理员只能邀请一级管理员 故返回权限码103 + userExtra.setAdminInviteCode(RandomStringUtils.randomAlphanumeric(10)); + return 103; + } + else { + //若不是 那只能是一级管理员了 一级管理员只能邀请二级管理员 故返回权限码104 + return 104; + } + } + //看来既不为空 又不是用户邀请码 也不是管理员邀请码 那这个邀请码就不存在了 返回-1 终止添加 + return -1; + } + + private void checkLog(UserExtra userExtra, String invitedCode, String username, UserExtra parent) { + SysUser parentUser = userMapper.selectUserById(parent.getUserId()); + integralLogFactory.getInstance(OperationConstants.INVITE).insertLog(IntegralLog.builder() + .userId(parentUser.getUserId()) + .createBy(parentUser.getUserName()) + .build()); + insertLog(InviteLogDTO.builder() + .inviter(parentUser.getUserName()) + .inviteCode(invitedCode) + .invitee(username) + .userId(parentUser.getUserId()) + .build()); + System.out.println(parentUser.getUserId()+"====000000000000111111111111112222222"); + //非空 将本次注册用户的上级id设为parent的id + userExtra.setSuperiorId(parent.getUserId()); + } + + private void insertLog (InviteLogDTO inviteLogDTO) { + iInviteLogService.insert(inviteLogDTO); + } + + /** + * 新增保存用户信息 + * + * @param user 用户信息 + * @return 结果 + */ + @Override + @Transactional + public int insertUser(SysUser user) + { + // 新增用户信息 + int rows = userMapper.insertUser(user); + // 新增用户岗位关联 + insertUserPost(user); + // 新增用户与角色管理 + insertUserRole(user); + // 新增用户额外信息、初始化用户信息 + UserExtra userExtra = user.getUserExtra(); + userExtra.setUserId(user.getUserId()); + this.initUser(user); + userExtraService.insert(userExtra); + + return rows; + } + + /** + * 注册用户信息 + * + * @param user 用户信息 + * @return 结果 + */ + @Override + public boolean registerUser(SysUser user) + { + return userMapper.insertUser(user) > 0; + } + + /** + * 修改保存用户信息 + * + * @param user 用户信息 + * @return 结果 + */ + @Override + @Transactional + public int updateUser(SysUser user) + { + Long userId = user.getUserId(); + // 删除用户与角色关联 + userRoleMapper.deleteUserRoleByUserId(userId); + // 新增用户与角色管理 + insertUserRole(user); + // 删除用户与岗位关联 + userPostMapper.deleteUserPostByUserId(userId); + // 新增用户与岗位管理 + insertUserPost(user); + // 删除用户额外信息 + userExtraMapper.deleteUserExtraByUserId(userId); + // 新增用户额外信息 + insertUserExtra(user); + + return userMapper.updateUser(user); + } + + /** + * 插入用户额外信息 + * @param user + */ + private void insertUserExtra(SysUser user) { + // 初始化 + this.initUser(user); + + UserExtra userExtra = user.getUserExtra(); + userExtra.setUserId(user.getUserId()); + + userExtraService.insert(userExtra); + } + + /** + * 用户授权角色 + * + * @param userId 用户ID + * @param roleIds 角色组 + */ + @Override + @Transactional + public void insertUserAuth(Long userId, Long[] roleIds) + { + userRoleMapper.deleteUserRoleByUserId(userId); + insertUserRole(userId, roleIds); + } + + /** + * 修改用户状态 + * + * @param user 用户信息 + * @return 结果 + */ + @Override + public int updateUserStatus(SysUser user) + { + return userMapper.updateUser(user); + } + + /** + * 修改用户基本信息 + * + * @param user 用户信息 + * @return 结果 + */ + @Override + public int updateUserProfile(SysUser user) + { + return userMapper.updateUser(user); + } + + /** + * 修改用户头像 + * + * @param userName 用户名 + * @param avatar 头像地址 + * @return 结果 + */ + @Override + public boolean updateUserAvatar(String userName, String avatar) + { + return userMapper.updateUserAvatar(userName, avatar) > 0; + } + + /** + * 重置用户密码 + * + * @param user 用户信息 + * @return 结果 + */ + @Override + public int resetPwd(SysUser user) + { + return userMapper.updateUser(user); + } + + /** + * 重置用户密码 + * + * @param userName 用户名 + * @param password 密码 + * @return 结果 + */ + @Override + public int resetUserPwd(String userName, String password) + { + return userMapper.resetUserPwd(userName, password); + } + + /** + * 新增用户角色信息 + * + * @param user 用户对象 + */ + public void insertUserRole(SysUser user) + { + this.insertUserRole(user.getUserId(), user.getRoleIds()); + } + + /** + * 新增用户岗位信息 + * + * @param user 用户对象 + */ + public void insertUserPost(SysUser user) + { + Long[] posts = user.getPostIds(); + if (StringUtils.isNotEmpty(posts)) + { + // 新增用户与岗位管理 + List list = new ArrayList(posts.length); + for (Long postId : posts) + { + SysUserPost up = new SysUserPost(); + up.setUserId(user.getUserId()); + up.setPostId(postId); + list.add(up); + } + userPostMapper.batchUserPost(list); + } + } + + /** + * 新增用户角色信息 + * + * @param userId 用户ID + * @param roleIds 角色组 + */ + public void insertUserRole(Long userId, Long[] roleIds) + { + if (StringUtils.isNotEmpty(roleIds)) + { + // 新增用户与角色管理 + List list = new ArrayList(roleIds.length); + for (Long roleId : roleIds) + { + SysUserRole ur = new SysUserRole(); + ur.setUserId(userId); + ur.setRoleId(roleId); + list.add(ur); + } + userRoleMapper.batchUserRole(list); + } + } + + /** + * 通过用户ID删除用户 + * + * @param userId 用户ID + * @return 结果 + */ + @Override + @Transactional + public int deleteUserById(Long userId) + { + + // 删除用户与角色关联 + userRoleMapper.deleteUserRoleByUserId(userId); + // 删除用户与岗位表 + userPostMapper.deleteUserPostByUserId(userId); + return userMapper.deleteUserById(userId); + } + + /** + * 批量删除用户信息 + * + * @param userIds 需要删除的用户ID + * @return 结果 + */ + @Override + @Transactional + public int deleteUserByIds(Long[] userIds) + { + for (Long userId : userIds) + { + checkUserAllowed(new SysUser(userId)); + checkUserDataScope(userId); + } + // 删除用户与角色关联 + userRoleMapper.deleteUserRole(userIds); + // 删除用户与岗位关联 + userPostMapper.deleteUserPost(userIds); + // 删除用户额外信息 + userExtraMapper.deleteUserExtra(userIds); + + return userMapper.deleteUserByIds(userIds); + } + + /** + * 导入用户数据 + * + * @param userList 用户数据列表 + * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据 + * @param operName 操作用户 + * @return 结果 + */ + @Override + public String importUser(List userList, Boolean isUpdateSupport, String operName) + { + if (StringUtils.isNull(userList) || userList.size() == 0) + { + throw new ServiceException("导入用户数据不能为空!"); + } + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + String password = configService.selectConfigByKey("sys.user.initPassword"); + for (SysUser user : userList) + { + try + { + // 验证是否存在这个用户 + SysUser u = userMapper.selectUserByUserName(user.getUserName()); + if (StringUtils.isNull(u)) + { + BeanValidators.validateWithException(validator, user); + user.setPassword(SecurityUtils.encryptPassword(password)); + user.setCreateBy(operName); + userMapper.insertUser(user); + successNum++; + successMsg.append("
" + successNum + "、账号 " + user.getUserName() + " 导入成功"); + } + else if (isUpdateSupport) + { + BeanValidators.validateWithException(validator, user); + checkUserAllowed(u); + checkUserDataScope(u.getUserId()); + user.setUserId(u.getUserId()); + user.setUpdateBy(operName); + userMapper.updateUser(user); + successNum++; + successMsg.append("
" + successNum + "、账号 " + user.getUserName() + " 更新成功"); + } + else + { + failureNum++; + failureMsg.append("
" + failureNum + "、账号 " + user.getUserName() + " 已存在"); + } + } + catch (Exception e) + { + failureNum++; + String msg = "
" + failureNum + "、账号 " + user.getUserName() + " 导入失败:"; + failureMsg.append(msg + e.getMessage()); + log.error(msg, e); + } + } + if (failureNum > 0) + { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new ServiceException(failureMsg.toString()); + } + else + { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + } + return successMsg.toString(); + } + + /** + * 初始化用户 + * @return + */ + + @Override + public void initUser(SysUser user) { + + UserExtra userExtra = user.getUserExtra(); + + /** + * 初始化积分 + */ + + // 积分是否为空 + if (Objects.isNull(userExtra.getIntegral())) { + // 初始化积分 + user.getUserExtra().setIntegral(10); + } + + /** + * 初始化邀请码 + */ + + // 是否生成admin_invite_code + if (Objects.nonNull(user.getUserExtra().getInvitedCode())) { + if (checkInitAdminInviteCode(user.getUserExtra().getInvitedCode())) { + // 初始化admin_invite_code + String adminInvitedCode = RandomStringUtils.randomAlphanumeric(10); + user.getUserExtra().setAdminInviteCode(adminInvitedCode); + } + } + + if(Objects.isNull(user.getUserExtra().getInviteCode())) { + // 初始化invite_code + user.getUserExtra().setInviteCode(RandomStringUtils.randomAlphanumeric(6)); + } + + /** + * 分发(初始化)邀请奖励/生成邀请记录 + */ + // 如果userId存在,则说明是编辑用户,不需要分发奖励 + if (Objects.isNull(user.getUserId())) { + handOutAward(user); + } + } + + /** + * 判断是否要生成admin_invite_code + * @return + */ + @Override + public boolean checkInitAdminInviteCode(String invitedCode) { + QueryWrapper adminInviteCodeWrapper + = new QueryWrapper().eq("admin_invite_code", invitedCode); + + // 邀请该用户的用户的userExtra + UserExtra userExtraEd = userExtraMapper.selectOne(adminInviteCodeWrapper); + + if (Objects.isNull(userExtraEd)) { + throw new ServiceException("邀请码错误"); + } + + QueryWrapper userRoleQueryWrapper + = new QueryWrapper().eq("user_id", userExtraEd.getUserId()); + List userRoles = userRoleMapper.selectList(userRoleQueryWrapper); + List roleIds = userRoles.stream() + .map(SysUserRole::getRoleId) + .collect(Collectors.toList()); + + // 如果不是空,并且邀请人为超级管理员,则初始化admin_invite_code + if (Objects.nonNull(userExtraEd.getAdminInviteCode()) && roleIds.contains(1L)) { + return true; + } + return false; + } + + @Override + public UserVO getUserInfo() { + SysUser sysUser = userMapper.getUserInfo(SecurityUtils.getUserId()); + VipType vipType = vipService.getVipTypeByUserId(SecurityUtils.getUserId()); + return UserVO.builder() + .avatar(sysUser.getAvatar()) + .username(sysUser.getUserName()) + .vipType(vipType.getInfo()) + .integral(userExtraService.getIntegral(SecurityUtils.getUserId())) + .build(); + } + + /** + * 分发邀请奖励 + * @param user + */ + @Override + public void handOutAward(SysUser user) { + // 通过邀请码查询邀请人 + String invitedCode = user.getUserExtra().getInvitedCode(); + + QueryWrapper inviteCodeWrapper + = new QueryWrapper().eq("invite_code", invitedCode); + QueryWrapper adminInviteCodeWrapper + = new QueryWrapper().eq("admin_invite_code", invitedCode); + + UserExtra inviteUserExtra = userExtraMapper.selectOne(inviteCodeWrapper); + UserExtra adminInviteUserExtra = userExtraMapper.selectOne(adminInviteCodeWrapper); + + if (Objects.isNull(inviteUserExtra) && Objects.isNull(adminInviteUserExtra)) { + throw new ServiceException("邀请码错误"); + } + + UserExtra trueUserExtra = Objects.isNull(inviteUserExtra) ? adminInviteUserExtra : inviteUserExtra; + + // 给邀请人分发奖励 + // TODO TODO TODO 积分数量是可配置的 + userExtraService.addIntegral(10, trueUserExtra.getUserId()); + } + + +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/UserExtraServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/UserExtraServiceImpl.java new file mode 100644 index 0000000..434bf65 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/UserExtraServiceImpl.java @@ -0,0 +1,67 @@ +package com.ruoyi.system.system.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.common.core.domain.entity.SysUser; +import com.muta.common.core.domain.entity.UserExtra; +import com.muta.system.mapper.UserExtraMapper; +import com.muta.system.service.IUserExtraService; +import io.netty.util.internal.ObjectUtil; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Objects; + +/** + *

+ * 服务实现类 + *

+ * + * @author zy + * @since 2024-04-17 + */ +@Service +public class UserExtraServiceImpl extends ServiceImpl implements IUserExtraService { + @Resource + private UserExtraMapper userExtraMapper; + @Override + public UserExtra getByUserId(Long userId) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(UserExtra::getUserId,userId); + return userExtraMapper.selectOne(lambdaQueryWrapper); + } + + @Override + public void addIntegral(int count, Long userId) { + userExtraMapper.addIntegralByUserId(count,userId); + } + + @Override + public Boolean IncreaseIntegral(int count, Long userId) { + UserExtra userExtra =this.getByUserId(userId); + //如果扣减积分大于已有积分,返回false + if(userExtra.getIntegral()< count){ + return false; + } + userExtraMapper.IncreaseIntegralByUserId(count,userId); + return true; + } + + @Override + public Integer getIntegral(Long userId) { + return userExtraMapper.getIntegralByUserId(userId); + } + + /** + * 插入用户额外信息 + * @param userExtra + */ + @Override + public void insert(UserExtra userExtra) { + userExtraMapper.insert(userExtra); + } + + + +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/VipServiceImpl.java b/src/main/java/com/ruoyi/system/system/service/impl/VipServiceImpl.java new file mode 100644 index 0000000..c4f11cf --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/VipServiceImpl.java @@ -0,0 +1,94 @@ +package com.ruoyi.system.system.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.common.enums.VipType; +import com.muta.log.service.IInviteLogService; +import com.muta.log.service.impl.ShopIntegralLogServiceImpl; +import com.muta.system.domain.Vip; +import com.muta.system.mapper.VipMapper; +import com.muta.system.service.IUserExtraService; +import com.muta.system.service.IVipService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +/** + * @author 马兰友 + * @Date: 2024/06/05/13:36 + */ +@Service +public class VipServiceImpl extends ServiceImpl implements IVipService { + @Value("${vipRewards.vipIntegral}") + private Integer vipIntegral; + @Value("${vipRewards.svipIntegral}") + private Integer svipIntegral; + @Resource + private IInviteLogService iInviteLogService; + @Resource + private VipMapper vipMapper; + @Resource + private IUserExtraService userExtraService; + @Resource + private ShopIntegralLogServiceImpl shopIntegralLogService; + + @Override + public VipType getVipTypeByUserId(Long userId) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(userId!=null,Vip::getUserId,userId); + Vip vip = vipMapper.selectOne(lambdaQueryWrapper); + Date date =new Date(); + if(vip.getSvipExpireTime()!=null &&vip.getSvipExpireTime().getTime()>date.getTime()){ + return VipType.SVIP; + } + else if(vip.getVipExpireTime()!=null &&vip.getVipExpireTime().getTime()>date.getTime()){ + return VipType.VIP; + } + return VipType.NORMAL; + } + @Override + public void addVipDate(Long userId,Integer type,Integer value) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(userId!=null,Vip::getUserId,userId); + Date now = new Date(); + Vip vip = new Vip(); + // 使用Calendar来添加天数 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(now); + calendar.add(Calendar.DAY_OF_MONTH, value); + // 将Calendar对象转换回Date对象 + Date expireTime = calendar.getTime(); + //如果是普通会员 + if(type.equals(VipType.VIP.getCode())){ + log.debug("vip"); + vip = Vip.builder() + .vipBeginTime(now) + .vipExpireTime(expireTime) + .build(); + //增加积分 + userExtraService.addIntegral(vipIntegral,userId); + //增加积分记录 + shopIntegralLogService.insertShop(svipIntegral); + } + else if (type.equals(VipType.SVIP.getCode())){ + log.debug("svip"); + //超级会员 + vip = Vip.builder() + .svipBeginTime(now) + .svipExpireTime(expireTime) + .build(); + userExtraService.addIntegral(svipIntegral,userId); + shopIntegralLogService.insertShop(vipIntegral); + } + //修改会员时间 + vipMapper.update(vip,lambdaQueryWrapper); + } + @Override + public List getList() { + return vipMapper.selectList(null); + } +} diff --git a/src/main/java/com/ruoyi/system/system/service/impl/WeiXinRegisterService.java b/src/main/java/com/ruoyi/system/system/service/impl/WeiXinRegisterService.java new file mode 100644 index 0000000..66dda9d --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/service/impl/WeiXinRegisterService.java @@ -0,0 +1,17 @@ +package com.ruoyi.system.system.service.impl; + +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author: Larry + * @Date: 2024 /08 /02 / 9:21 + * @Description: + */ +@Service +public class WeiXinRegisterService { + public void register(){ + + } +} diff --git a/src/main/java/com/ruoyi/system/system/task/SigninTask.java b/src/main/java/com/ruoyi/system/system/task/SigninTask.java new file mode 100644 index 0000000..5086c21 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/task/SigninTask.java @@ -0,0 +1,40 @@ +package com.ruoyi.system.system.task; + +import com.muta.common.enums.SigninStatus; +import com.muta.system.domain.Signin; +import com.muta.system.mapper.SigninMapper; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.Calendar; +import java.util.List; + +@Component +public class SigninTask { + + @Resource + private SigninMapper signinMapper; + + + /** + * 每月第一天 将所有存在用户的签到数据重置 + */ + @Scheduled(cron = "0 0 0 1 * ?") + public void resetDate() { + Calendar calendar = Calendar.getInstance(); + Integer days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); + + // 状态置为全部未签 + String status = SigninStatus.NOT_SIGNIN.getCode().repeat(days); + + List list = signinMapper.selectAllSignin(); + + list.forEach(l -> { + //特判月份更改时是否继续维持连续签到的状态 + if (l.getStatus().charAt(l.getStatus().length() - 1) == '0') + l.setCount(0); + l.setStatus(status); + }); + } +} diff --git a/src/main/java/com/ruoyi/system/system/task/VipTask.java b/src/main/java/com/ruoyi/system/system/task/VipTask.java new file mode 100644 index 0000000..e074728 --- /dev/null +++ b/src/main/java/com/ruoyi/system/system/task/VipTask.java @@ -0,0 +1,89 @@ +package com.ruoyi.system.system.task; + +import com.muta.system.domain.Vip; +import com.muta.system.service.IUserExtraService; +import com.muta.system.service.IVipService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Scheduled; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * @author: Larry + * @Date: 2024 /05 /30 / 13:32 + * @Description: + */ +@Resource +public class VipTask { + @Resource + private IUserExtraService userExtraService; + @Resource + private IVipService vipService; + @Value("${vipRewards.vipIntegral}") + private Integer vipIntegral; + @Value("${vipRewards.svipIntegral}") + private Integer svipIntegral; + @Scheduled(cron = "0 0 0 * * ?") + public void sendIntegralByVip() { + List vipList = vipService.getList(); + vipList.forEach( + vip -> { + Boolean isVip = judgeTime(vip.getVipBeginTime(), vip.getVipExpireTime()); + Boolean isSvip =judgeTime(vip.getSvipBeginTime(),vip.getSvipBeginTime()); + if(isSvip){ + userExtraService.addIntegral(vipIntegral,vip.getUserId()); + } + if(isVip){ + userExtraService.addIntegral(svipIntegral,vip.getUserId()); + } + } + ); + + } + private Boolean judgeTime(Date beginTime, Date endTime){ + Date now = new Date(); + long increase =(endTime.getTime() - now.getTime())/(24 * 60 * 60 * 1000); + //保证和充值时间不是同一天(充值当天是秒到账)同时没有过期,同时是每一个30天到账 + return increase % 30 == 0 && endTime.getTime() > now.getTime() && isNoSameDay(now, beginTime) && isNoSameDay(now, endTime); + } +// public static void main(String[] args) { +// // 设置时区为GMT,以确保时间的正确性 +// TimeZone timeZone = TimeZone.getTimeZone("GMT"); +// Calendar calendar = Calendar.getInstance(timeZone); +// +// // 定义2023年6月1日 00:00:00 GMT +// calendar.set(2023, Calendar.JUNE, 2); +// calendar.set(Calendar.HOUR_OF_DAY, 0); +// calendar.set(Calendar.MINUTE, 0); +// calendar.set(Calendar.SECOND, 0); +// calendar.set(Calendar.MILLISECOND, 0); +// Date begin = calendar.getTime(); +// Date now = new Date(); +// +// // 定义2023年7月1日 00:00:00 GMT +// calendar.set(2023, Calendar.JULY, 1); // 注意月份是从0开始的,所以6是7月 +// calendar.set(Calendar.HOUR_OF_DAY, 0); +// calendar.set(Calendar.MINUTE, 0); +// calendar.set(Calendar.SECOND, 0); +// calendar.set(Calendar.MILLISECOND, 0); +// Date expire = calendar.getTime(); +// // 输出时间戳进行验证 +// System.out.println("2023年6月1日的时间戳: " + now.getTime()); +// System.out.println("2023年7月1日的时间戳: " + expire.getTime()); +// long increase =(expire.getTime() - now.getTime())/(24 * 60 * 60 * 1000); +// if( increase%30 == 0 && expire.getTime()>now.getTime() &&isSameDay(now,begin)){ +// System.out.println("送积分辣"); +// } +// } + public static boolean isNoSameDay(Date date1, Date date2) { + // 将两个Date对象的时间戳转换为自当天开始以来的毫秒数 + long time1 = date1.getTime() / (24 * 60 * 60 * 1000) * (24 * 60 * 60 * 1000); + long time2 = date2.getTime() / (24 * 60 * 60 * 1000) * (24 * 60 * 60 * 1000); + // 比较两个时间戳是否相同 + return time1 != time2; + } +} + + diff --git a/src/main/java/com/ruoyi/system/trade/domain/PayLog.java b/src/main/java/com/ruoyi/system/trade/domain/PayLog.java new file mode 100644 index 0000000..bfdca62 --- /dev/null +++ b/src/main/java/com/ruoyi/system/trade/domain/PayLog.java @@ -0,0 +1,64 @@ +package com.ruoyi.system.trade.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @author 马兰友 + * @Date: 2024/06/05/16:29 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class PayLog { + + /** + * 自增的ID + */ + @TableId(type = IdType.AUTO) + @JsonFormat(shape =JsonFormat.Shape.STRING) + private Long id; + /** + * 订单编号 + */ + private String outTradeNo; + /** + * 商品标题 + */ + private String title; + /** + * 实际支付的总价 + */ + private BigDecimal payAmount; + /** + * 支付的状态 0-等待支付 1-支付完成 2-支付超时 + */ + private Integer payStatus; + /** + * 用户id + */ + @JsonFormat(shape =JsonFormat.Shape.STRING) + private Long userId; + /** + * 支付时间 + */ + private Date payTime; + /** + * 支付渠道 + */ + private String payChannel; + /** + * 用户账号 + */ + private String username; + +} diff --git a/src/main/java/com/ruoyi/system/trade/domain/Product.java b/src/main/java/com/ruoyi/system/trade/domain/Product.java new file mode 100644 index 0000000..762f820 --- /dev/null +++ b/src/main/java/com/ruoyi/system/trade/domain/Product.java @@ -0,0 +1,85 @@ +package com.ruoyi.system.trade.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.muta.common.core.MutaBaseEntity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * @author 马兰友 + * @Date: 2024/04/24/13:33 + */ +@EqualsAndHashCode(callSuper = true) +@Data +@AllArgsConstructor +@NoArgsConstructor +public class Product extends MutaBaseEntity { + + /** + * id + */ + @TableId(type = IdType.AUTO) + @JsonFormat(shape =JsonFormat.Shape.STRING) + private Long id; + + /** + * 标题 + */ + private String title; + + /** + * 价格 + */ + private Integer price; + + /** + * 值 根据type不同 含义也有所不同 + * type=0 该值表示积分数量 + * type=1或2 该值表示天数 + */ + private Integer value; + + /** + * 角标 + */ + private String badge; + + /** + * 状态 0:在售 1:停售 + */ + private Integer status; + + /** + * 类型 0:积分 1:普通会员 2:超级会员 + */ + private Integer type; + + /** + * 商品描述 + */ + @TableField(value = "`describe`") + private String describe; + + /** + * 排序 + */ + private Integer sort; + + /** + * vip享受的折扣 + */ + private BigDecimal vipDiscount; + + /** + * svip享受的折扣 + */ + private BigDecimal svipDiscount; + +} diff --git a/src/main/java/com/ruoyi/system/trade/domain/UserProductDTO.java b/src/main/java/com/ruoyi/system/trade/domain/UserProductDTO.java new file mode 100644 index 0000000..958c667 --- /dev/null +++ b/src/main/java/com/ruoyi/system/trade/domain/UserProductDTO.java @@ -0,0 +1,73 @@ +package com.ruoyi.system.trade.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * @author 马兰友 + * @Date: 2024/05/12/21:05 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class UserProductDTO { + /** + * id + */ + @TableId(type = IdType.AUTO) + @JsonFormat(shape =JsonFormat.Shape.STRING) + private Long id; + + /** + * 标题 + */ + private String title; + + /** + * 价格 + */ + private Integer price; + + /** + * 值 根据type不同 含义也有所不同 + * type=0 该值表示积分数量 + * type=1或2 该值表示天数 + */ + private Integer value; + + /** + * 角标 + */ + private String badge; + + + /** + * 类型 0:积分 1:普通会员 2:超级会员 + */ + private Integer type; + + /** + * 商品描述 + */ + @TableField(value = "`describe`") + private String describe; + + /** + * vip享受的折扣 + */ + private BigDecimal vipDiscount; + + /** + * svip享受的折扣 + */ + private BigDecimal svipDiscount; +} diff --git a/src/main/java/com/ruoyi/system/trade/mapper/PayLogMapper.java b/src/main/java/com/ruoyi/system/trade/mapper/PayLogMapper.java new file mode 100644 index 0000000..f736fff --- /dev/null +++ b/src/main/java/com/ruoyi/system/trade/mapper/PayLogMapper.java @@ -0,0 +1,13 @@ +package com.ruoyi.system.trade.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.trade.domain.PayLog; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author 马兰友 + * @Date: 2024/06/05/16:32 + */ +@Mapper +public interface PayLogMapper extends BaseMapper { +} diff --git a/src/main/java/com/ruoyi/system/trade/mapper/ProductMapper.java b/src/main/java/com/ruoyi/system/trade/mapper/ProductMapper.java new file mode 100644 index 0000000..e6d4069 --- /dev/null +++ b/src/main/java/com/ruoyi/system/trade/mapper/ProductMapper.java @@ -0,0 +1,63 @@ +package com.ruoyi.system.trade.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muta.trade.domain.Product; + +import java.util.List; + +/** + * 【请填写功能名称】Mapper接口 + * + * @author mutaai + * @date 2024-04-24 + */ +public interface ProductMapper extends BaseMapper { + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + public Product selectProductById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @param product 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectProductList(Product product); + + /** + * 新增【请填写功能名称】 + * + * @param product 【请填写功能名称】 + * @return 结果 + */ + public int insertProduct(Product product); + + /** + * 修改【请填写功能名称】 + * + * @param product 【请填写功能名称】 + * @return 结果 + */ + public int updateProduct(Product product); + + /** + * 删除【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + public int deleteProductById(String id); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteProductByIds(String[] ids); +} diff --git a/src/main/java/com/ruoyi/system/trade/service/IPayLogService.java b/src/main/java/com/ruoyi/system/trade/service/IPayLogService.java new file mode 100644 index 0000000..b606cf0 --- /dev/null +++ b/src/main/java/com/ruoyi/system/trade/service/IPayLogService.java @@ -0,0 +1,15 @@ +package com.ruoyi.system.trade.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.trade.domain.PayLog; +import com.muta.trade.mapper.PayLogMapper; + +import javax.annotation.Resource; + +/** + * @author 马兰友 + * @Date: 2024/06/05/16:31 + */ +public interface IPayLogService extends IService { + void insertPay(PayLog payLog); +} diff --git a/src/main/java/com/ruoyi/system/trade/service/IProductService.java b/src/main/java/com/ruoyi/system/trade/service/IProductService.java new file mode 100644 index 0000000..3ec4c03 --- /dev/null +++ b/src/main/java/com/ruoyi/system/trade/service/IProductService.java @@ -0,0 +1,66 @@ +package com.ruoyi.system.trade.service; + +import java.util.List; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muta.common.core.domain.AjaxResult; +import com.muta.trade.domain.Product; +import com.muta.trade.domain.UserProductDTO; + +/** + * 【请填写功能名称】Service接口 + * + * @author mutaai + * @date 2024-04-24 + */ +public interface IProductService extends IService { + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + public Product selectProductById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @param product 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectProductList(Product product); + + /** + * 新增【请填写功能名称】 + * + * @param product 【请填写功能名称】 + * @return 结果 + */ + public int insertProduct(Product product); + + /** + * 修改【请填写功能名称】 + * + * @param product 【请填写功能名称】 + * @return 结果 + */ + public int updateProduct(Product product); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】主键集合 + * @return 结果 + */ + public int deleteProductByIds(String[] ids); + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + public int deleteProductById(String id); + + List userGetList(); +} diff --git a/src/main/java/com/ruoyi/system/trade/service/impl/PayLogServiceImpl.java b/src/main/java/com/ruoyi/system/trade/service/impl/PayLogServiceImpl.java new file mode 100644 index 0000000..825c611 --- /dev/null +++ b/src/main/java/com/ruoyi/system/trade/service/impl/PayLogServiceImpl.java @@ -0,0 +1,26 @@ +package com.ruoyi.system.trade.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muta.trade.domain.PayLog; +import com.muta.trade.mapper.PayLogMapper; +import com.muta.trade.service.IPayLogService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * @author 马兰友 + * @Date: 2024/06/05/16:32 + */ +@Service +public class PayLogServiceImpl extends ServiceImpl implements IPayLogService { + @Resource + private PayLogMapper payLogMapper; + + @Override + public void insertPay(PayLog payLog) { + payLogMapper.insert(payLog);; + } + + +} diff --git a/src/main/java/com/ruoyi/system/trade/service/impl/ProductServiceImpl.java b/src/main/java/com/ruoyi/system/trade/service/impl/ProductServiceImpl.java new file mode 100644 index 0000000..de5470f --- /dev/null +++ b/src/main/java/com/ruoyi/system/trade/service/impl/ProductServiceImpl.java @@ -0,0 +1,117 @@ +package com.ruoyi.system.trade.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.util.List; +import java.util.stream.Collectors; + +import com.muta.common.core.domain.AjaxResult; +import com.muta.common.utils.DateUtils; +import com.muta.trade.domain.Product; +import com.muta.trade.domain.UserProductDTO; +import com.muta.trade.mapper.ProductMapper; +import com.muta.trade.service.IProductService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + + +/** + * 【请填写功能名称】Service业务层处理 + * + * @author mutaai + * @date 2024-04-24 + */ +@Service +public class ProductServiceImpl extends ServiceImpl implements IProductService { + @Resource + private ProductMapper productMapper; + + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】主键 + * @return 【请填写功能名称】 + */ + @Override + public Product selectProductById(Long id) { + return productMapper.selectProductById(id); + } + + /** + * 查询【请填写功能名称】列表 + * + * @param product 【请填写功能名称】 + * @return 【请填写功能名称】 + */ + @Override + public List selectProductList(Product product) { + return productMapper.selectProductList(product); + } + + /** + * 新增【请填写功能名称】 + * + * @param product 【请填写功能名称】 + * @return 结果 + */ + @Override + public int insertProduct(Product product) { + product.setCreateTime(DateUtils.getNowDate()); + return productMapper.insertProduct(product); + } + + /** + * 修改【请填写功能名称】 + * + * @param product 【请填写功能名称】 + * @return 结果 + */ + @Override + public int updateProduct(Product product) { + product.setUpdateTime(DateUtils.getNowDate()); + return productMapper.updateProduct(product); + } + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】主键 + * @return 结果 + */ + @Override + public int deleteProductByIds(String[] ids) { + return productMapper.deleteProductByIds(ids); + } + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】主键 + * @return 结果 + */ + @Override + public int deleteProductById(String id) { + return productMapper.deleteProductById(id); + } + + @Override + public List userGetList() { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.orderByDesc(Product::getSort) + .eq(Product::getStatus, 0); + List products = productMapper.selectList(lqw); + List list = products.stream().map(product -> UserProductDTO.builder() + .id(product.getId()) + .title(product.getTitle()) + .price(product.getPrice()) + .value(product.getValue()) + .badge(product.getBadge()) + .type(product.getType()) + .describe(product.getDescribe()) + .vipDiscount(product.getVipDiscount()) + .svipDiscount(product.getSvipDiscount()) + .build()).collect(Collectors.toList()); + return list; + } +}