✨ init project
This commit is contained in:
10
plugin/announcement/api/enter.go
Normal file
10
plugin/announcement/api/enter.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package api
|
||||
|
||||
import "git.echol.cn/loser/lckt/plugin/announcement/service"
|
||||
|
||||
var (
|
||||
Api = new(api)
|
||||
serviceInfo = service.Service.Info
|
||||
)
|
||||
|
||||
type api struct{ Info info }
|
183
plugin/announcement/api/info.go
Normal file
183
plugin/announcement/api/info.go
Normal file
@@ -0,0 +1,183 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
"git.echol.cn/loser/lckt/model/common/response"
|
||||
"git.echol.cn/loser/lckt/plugin/announcement/model"
|
||||
"git.echol.cn/loser/lckt/plugin/announcement/model/request"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var Info = new(info)
|
||||
|
||||
type info struct{}
|
||||
|
||||
// CreateInfo 创建公告
|
||||
// @Tags Info
|
||||
// @Summary 创建公告
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.Info true "创建公告"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /info/createInfo [post]
|
||||
func (a *info) CreateInfo(c *gin.Context) {
|
||||
var info model.Info
|
||||
err := c.ShouldBindJSON(&info)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = serviceInfo.CreateInfo(&info)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("创建失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteInfo 删除公告
|
||||
// @Tags Info
|
||||
// @Summary 删除公告
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.Info true "删除公告"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /info/deleteInfo [delete]
|
||||
func (a *info) DeleteInfo(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
err := serviceInfo.DeleteInfo(ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteInfoByIds 批量删除公告
|
||||
// @Tags Info
|
||||
// @Summary 批量删除公告
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
||||
// @Router /info/deleteInfoByIds [delete]
|
||||
func (a *info) DeleteInfoByIds(c *gin.Context) {
|
||||
IDs := c.QueryArray("IDs[]")
|
||||
if err := serviceInfo.DeleteInfoByIds(IDs); err != nil {
|
||||
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量删除失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateInfo 更新公告
|
||||
// @Tags Info
|
||||
// @Summary 更新公告
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.Info true "更新公告"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
||||
// @Router /info/updateInfo [put]
|
||||
func (a *info) UpdateInfo(c *gin.Context) {
|
||||
var info model.Info
|
||||
err := c.ShouldBindJSON(&info)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = serviceInfo.UpdateInfo(info)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
||||
response.FailWithMessage("更新失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindInfo 用id查询公告
|
||||
// @Tags Info
|
||||
// @Summary 用id查询公告
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query model.Info true "用id查询公告"
|
||||
// @Success 200 {object} response.Response{data=model.Info,msg=string} "查询成功"
|
||||
// @Router /info/findInfo [get]
|
||||
func (a *info) FindInfo(c *gin.Context) {
|
||||
ID := c.Query("ID")
|
||||
reinfo, err := serviceInfo.GetInfo(ID)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(reinfo, c)
|
||||
}
|
||||
|
||||
// GetInfoList 分页获取公告列表
|
||||
// @Tags Info
|
||||
// @Summary 分页获取公告列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query request.InfoSearch true "分页获取公告列表"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /info/getInfoList [get]
|
||||
func (a *info) GetInfoList(c *gin.Context) {
|
||||
var pageInfo request.InfoSearch
|
||||
err := c.ShouldBindQuery(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := serviceInfo.GetInfoInfoList(pageInfo)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetInfoDataSource 获取Info的数据源
|
||||
// @Tags Info
|
||||
// @Summary 获取Info的数据源
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "查询成功"
|
||||
// @Router /info/getInfoDataSource [get]
|
||||
func (a *info) GetInfoDataSource(c *gin.Context) {
|
||||
// 此接口为获取数据源定义的数据
|
||||
dataSource, err := serviceInfo.GetInfoDataSource()
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(dataSource, c)
|
||||
}
|
||||
|
||||
// GetInfoPublic 不需要鉴权的公告接口
|
||||
// @Tags Info
|
||||
// @Summary 不需要鉴权的公告接口
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query request.InfoSearch true "分页获取公告列表"
|
||||
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
|
||||
// @Router /info/getInfoPublic [get]
|
||||
func (a *info) GetInfoPublic(c *gin.Context) {
|
||||
// 此接口不需要鉴权 示例为返回了一个固定的消息接口,一般本接口用于C端服务,需要自己实现业务逻辑
|
||||
response.OkWithDetailed(gin.H{"info": "不需要鉴权的公告接口信息"}, "获取成功", c)
|
||||
}
|
4
plugin/announcement/config/config.go
Normal file
4
plugin/announcement/config/config.go
Normal file
@@ -0,0 +1,4 @@
|
||||
package config
|
||||
|
||||
type Config struct {
|
||||
}
|
17
plugin/announcement/gen/gen.go
Normal file
17
plugin/announcement/gen/gen.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gorm.io/gen"
|
||||
"path/filepath" //go:generate go mod tidy
|
||||
//go:generate go mod download
|
||||
//go:generate go run gen.go
|
||||
"git.echol.cn/loser/lckt/plugin/announcement/model"
|
||||
)
|
||||
|
||||
func main() {
|
||||
g := gen.NewGenerator(gen.Config{OutPath: filepath.Join("..", "..", "..", "announcement", "blender", "model", "dao"), Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface})
|
||||
g.ApplyBasic(
|
||||
new(model.Info),
|
||||
)
|
||||
g.Execute()
|
||||
}
|
49
plugin/announcement/initialize/api.go
Normal file
49
plugin/announcement/initialize/api.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"context"
|
||||
model "git.echol.cn/loser/lckt/model/system"
|
||||
"git.echol.cn/loser/lckt/plugin/plugin-tool/utils"
|
||||
)
|
||||
|
||||
func Api(ctx context.Context) {
|
||||
entities := []model.SysApi{
|
||||
{
|
||||
Path: "/info/createInfo",
|
||||
Description: "新建公告",
|
||||
ApiGroup: "公告",
|
||||
Method: "POST",
|
||||
},
|
||||
{
|
||||
Path: "/info/deleteInfo",
|
||||
Description: "删除公告",
|
||||
ApiGroup: "公告",
|
||||
Method: "DELETE",
|
||||
},
|
||||
{
|
||||
Path: "/info/deleteInfoByIds",
|
||||
Description: "批量删除公告",
|
||||
ApiGroup: "公告",
|
||||
Method: "DELETE",
|
||||
},
|
||||
{
|
||||
Path: "/info/updateInfo",
|
||||
Description: "更新公告",
|
||||
ApiGroup: "公告",
|
||||
Method: "PUT",
|
||||
},
|
||||
{
|
||||
Path: "/info/findInfo",
|
||||
Description: "根据ID获取公告",
|
||||
ApiGroup: "公告",
|
||||
Method: "GET",
|
||||
},
|
||||
{
|
||||
Path: "/info/getInfoList",
|
||||
Description: "获取公告列表",
|
||||
ApiGroup: "公告",
|
||||
Method: "GET",
|
||||
},
|
||||
}
|
||||
utils.RegisterApis(entities...)
|
||||
}
|
20
plugin/announcement/initialize/gorm.go
Normal file
20
plugin/announcement/initialize/gorm.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
"git.echol.cn/loser/lckt/plugin/announcement/model"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func Gorm(ctx context.Context) {
|
||||
err := global.GVA_DB.WithContext(ctx).AutoMigrate(
|
||||
new(model.Info),
|
||||
)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "注册表失败!")
|
||||
zap.L().Error(fmt.Sprintf("%+v", err))
|
||||
}
|
||||
}
|
22
plugin/announcement/initialize/menu.go
Normal file
22
plugin/announcement/initialize/menu.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"context"
|
||||
model "git.echol.cn/loser/lckt/model/system"
|
||||
"git.echol.cn/loser/lckt/plugin/plugin-tool/utils"
|
||||
)
|
||||
|
||||
func Menu(ctx context.Context) {
|
||||
entities := []model.SysBaseMenu{
|
||||
{
|
||||
ParentId: 24,
|
||||
Path: "anInfo",
|
||||
Name: "anInfo",
|
||||
Hidden: false,
|
||||
Component: "plugin/announcement/view/info.vue",
|
||||
Sort: 5,
|
||||
Meta: model.Meta{Title: "公告管理", Icon: "box"},
|
||||
},
|
||||
}
|
||||
utils.RegisterMenus(entities...)
|
||||
}
|
15
plugin/announcement/initialize/router.go
Normal file
15
plugin/announcement/initialize/router.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
"git.echol.cn/loser/lckt/middleware"
|
||||
"git.echol.cn/loser/lckt/plugin/announcement/router"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Router(engine *gin.Engine) {
|
||||
public := engine.Group(global.GVA_CONFIG.System.RouterPrefix).Group("")
|
||||
private := engine.Group(global.GVA_CONFIG.System.RouterPrefix).Group("")
|
||||
private.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
|
||||
router.Router.Info.Init(public, private)
|
||||
}
|
17
plugin/announcement/initialize/viper.go
Normal file
17
plugin/announcement/initialize/viper.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
"git.echol.cn/loser/lckt/plugin/announcement/plugin"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func Viper() {
|
||||
err := global.GVA_VP.UnmarshalKey("announcement", &plugin.Config)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "初始化配置文件失败!")
|
||||
zap.L().Error(fmt.Sprintf("%+v", err))
|
||||
}
|
||||
}
|
20
plugin/announcement/model/info.go
Normal file
20
plugin/announcement/model/info.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
// Info 公告 结构体
|
||||
type Info struct {
|
||||
global.GVA_MODEL
|
||||
Title string `json:"title" form:"title" gorm:"column:title;comment:公告标题;"` //标题
|
||||
Content string `json:"content" form:"content" gorm:"column:content;comment:公告内容;type:text;"` //内容
|
||||
UserID *int `json:"userID" form:"userID" gorm:"column:user_id;comment:发布者;"` //作者
|
||||
Attachments datatypes.JSON `json:"attachments" form:"attachments" gorm:"column:attachments;comment:相关附件;" swaggertype:"array,object"` //附件
|
||||
}
|
||||
|
||||
// TableName 公告 Info自定义表名 gva_announcements_info
|
||||
func (Info) TableName() string {
|
||||
return "gva_announcements_info"
|
||||
}
|
12
plugin/announcement/model/request/info.go
Normal file
12
plugin/announcement/model/request/info.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/lckt/model/common/request"
|
||||
"time"
|
||||
)
|
||||
|
||||
type InfoSearch struct {
|
||||
StartCreatedAt *time.Time `json:"startCreatedAt" form:"startCreatedAt"`
|
||||
EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"`
|
||||
request.PageInfo
|
||||
}
|
26
plugin/announcement/plugin.go
Normal file
26
plugin/announcement/plugin.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package announcement
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.echol.cn/loser/lckt/plugin/announcement/initialize"
|
||||
interfaces "git.echol.cn/loser/lckt/utils/plugin/v2"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var _ interfaces.Plugin = (*plugin)(nil)
|
||||
|
||||
var Plugin = new(plugin)
|
||||
|
||||
type plugin struct{}
|
||||
|
||||
func (p *plugin) Register(group *gin.Engine) {
|
||||
ctx := context.Background()
|
||||
// 如果需要配置文件,请到config.Config中填充配置结构,且到下方发放中填入其在config.yaml中的key
|
||||
// initialize.Viper()
|
||||
// 安装插件时候自动注册的api数据请到下方法.Api方法中实现
|
||||
initialize.Api(ctx)
|
||||
// 安装插件时候自动注册的api数据请到下方法.Menu方法中实现
|
||||
initialize.Menu(ctx)
|
||||
initialize.Gorm(ctx)
|
||||
initialize.Router(group)
|
||||
}
|
5
plugin/announcement/plugin/plugin.go
Normal file
5
plugin/announcement/plugin/plugin.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package plugin
|
||||
|
||||
import "git.echol.cn/loser/lckt/plugin/announcement/config"
|
||||
|
||||
var Config config.Config
|
10
plugin/announcement/router/enter.go
Normal file
10
plugin/announcement/router/enter.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package router
|
||||
|
||||
import "git.echol.cn/loser/lckt/plugin/announcement/api"
|
||||
|
||||
var (
|
||||
Router = new(router)
|
||||
apiInfo = api.Api.Info
|
||||
)
|
||||
|
||||
type router struct{ Info info }
|
31
plugin/announcement/router/info.go
Normal file
31
plugin/announcement/router/info.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/lckt/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var Info = new(info)
|
||||
|
||||
type info struct{}
|
||||
|
||||
// Init 初始化 公告 路由信息
|
||||
func (r *info) Init(public *gin.RouterGroup, private *gin.RouterGroup) {
|
||||
{
|
||||
group := private.Group("info").Use(middleware.OperationRecord())
|
||||
group.POST("createInfo", apiInfo.CreateInfo) // 新建公告
|
||||
group.DELETE("deleteInfo", apiInfo.DeleteInfo) // 删除公告
|
||||
group.DELETE("deleteInfoByIds", apiInfo.DeleteInfoByIds) // 批量删除公告
|
||||
group.PUT("updateInfo", apiInfo.UpdateInfo) // 更新公告
|
||||
}
|
||||
{
|
||||
group := private.Group("info")
|
||||
group.GET("findInfo", apiInfo.FindInfo) // 根据ID获取公告
|
||||
group.GET("getInfoList", apiInfo.GetInfoList) // 获取公告列表
|
||||
}
|
||||
{
|
||||
group := public.Group("info")
|
||||
group.GET("getInfoDataSource", apiInfo.GetInfoDataSource) // 获取公告数据源
|
||||
group.GET("getInfoPublic", apiInfo.GetInfoPublic) // 获取公告列表
|
||||
}
|
||||
}
|
5
plugin/announcement/service/enter.go
Normal file
5
plugin/announcement/service/enter.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package service
|
||||
|
||||
var Service = new(service)
|
||||
|
||||
type service struct{ Info info }
|
78
plugin/announcement/service/info.go
Normal file
78
plugin/announcement/service/info.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
"git.echol.cn/loser/lckt/plugin/announcement/model"
|
||||
"git.echol.cn/loser/lckt/plugin/announcement/model/request"
|
||||
)
|
||||
|
||||
var Info = new(info)
|
||||
|
||||
type info struct{}
|
||||
|
||||
// CreateInfo 创建公告记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func (s *info) CreateInfo(info *model.Info) (err error) {
|
||||
err = global.GVA_DB.Create(info).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteInfo 删除公告记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func (s *info) DeleteInfo(ID string) (err error) {
|
||||
err = global.GVA_DB.Delete(&model.Info{}, "id = ?", ID).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteInfoByIds 批量删除公告记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func (s *info) DeleteInfoByIds(IDs []string) (err error) {
|
||||
err = global.GVA_DB.Delete(&[]model.Info{}, "id in ?", IDs).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateInfo 更新公告记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func (s *info) UpdateInfo(info model.Info) (err error) {
|
||||
err = global.GVA_DB.Model(&model.Info{}).Where("id = ?", info.ID).Updates(&info).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// GetInfo 根据ID获取公告记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func (s *info) GetInfo(ID string) (info model.Info, err error) {
|
||||
err = global.GVA_DB.Where("id = ?", ID).First(&info).Error
|
||||
return
|
||||
}
|
||||
|
||||
// GetInfoInfoList 分页获取公告记录
|
||||
// Author [piexlmax](https://github.com/piexlmax)
|
||||
func (s *info) GetInfoInfoList(info request.InfoSearch) (list []model.Info, total int64, err error) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
// 创建db
|
||||
db := global.GVA_DB.Model(&model.Info{})
|
||||
var infos []model.Info
|
||||
// 如果有条件搜索 下方会自动创建搜索语句
|
||||
if info.StartCreatedAt != nil && info.EndCreatedAt != nil {
|
||||
db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt)
|
||||
}
|
||||
err = db.Count(&total).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if limit != 0 {
|
||||
db = db.Limit(limit).Offset(offset)
|
||||
}
|
||||
err = db.Find(&infos).Error
|
||||
return infos, total, err
|
||||
}
|
||||
func (s *info) GetInfoDataSource() (res map[string][]map[string]any, err error) {
|
||||
res = make(map[string][]map[string]any)
|
||||
|
||||
userID := make([]map[string]any, 0)
|
||||
global.GVA_DB.Table("sys_users").Select("nick_name as label,id as value").Scan(&userID)
|
||||
res["userID"] = userID
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user