初始化项目,复制原投票系统后台代码
This commit is contained in:
parent
92a1a77bc1
commit
22cb271ff1
9
.gitignore
vendored
9
.gitignore
vendored
@ -6,12 +6,13 @@
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
*.log
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
.idea/
|
||||
.git/
|
||||
.DS_Store/
|
||||
.tmp/
|
||||
5
api/amqp/consumer/base.go
Normal file
5
api/amqp/consumer/base.go
Normal file
@ -0,0 +1,5 @@
|
||||
package consumer
|
||||
|
||||
func checkHandleNumber(key string) {
|
||||
|
||||
}
|
||||
431
api/controller/Article.go
Normal file
431
api/controller/Article.go
Normal file
@ -0,0 +1,431 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
"vote-admin-video-api/api/dao"
|
||||
"vote-admin-video-api/api/dto"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/api/requests"
|
||||
"vote-admin-video-api/api/responses"
|
||||
"vote-admin-video-api/global"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
type Article struct{}
|
||||
|
||||
// GetArticlePage 获取图文列表-分页
|
||||
func (r *Article) GetArticlePage(c *gin.Context) {
|
||||
articleRequest := requests.ArticleRequest{}
|
||||
req := articleRequest.GetArticlePage
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
if req.Order != nil {
|
||||
if req.Order.VoteNum != "" {
|
||||
if req.Order.VoteNum != "desc" && req.Order.VoteNum != "asc" {
|
||||
responses.FailWithMessage("排序字段错误", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
articleDao := dao.ArticleDao{}
|
||||
articles, total, err := articleDao.GetArticlePageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetArticleListDto(articles)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetArticle 获取图文详情
|
||||
func (r *Article) GetArticle(c *gin.Context) {
|
||||
id := c.Param("article_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
articleId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
articleDao := dao.ArticleDao{}
|
||||
article, err := articleDao.GetArticleById(articleId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("文章错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取作者数据
|
||||
articleAuthorDao := dao.ArticleAuthorDao{}
|
||||
maps := make(map[string]interface{})
|
||||
maps["article_id"] = articleId
|
||||
articleAuthors, err := articleAuthorDao.GetArticleAuthorPreloadList(maps)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("文章错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取排名
|
||||
rank, _ := articleDao.GetArticleRank(article.ArticleId)
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetArticleDto(article)
|
||||
|
||||
// 加载数据-作者
|
||||
g.LoadArticleAuthor(articleAuthors)
|
||||
|
||||
// 加载数据-作者排名
|
||||
g.LoadRank(rank)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
|
||||
// PutArticle 修改图文详情
|
||||
func (r *Article) PutArticle(c *gin.Context) {
|
||||
articleRequest := requests.ArticleRequest{}
|
||||
req := articleRequest.PutArticle
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("article_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
articleId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.VoteNum != nil {
|
||||
if *req.VoteNum < 0 {
|
||||
responses.FailWithMessage("票数需大于0", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单数据
|
||||
articleDao := dao.ArticleDao{}
|
||||
article, err := articleDao.GetArticleById(articleId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("图文异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
fmt.Println(r)
|
||||
}
|
||||
}()
|
||||
|
||||
articleData := make(map[string]interface{})
|
||||
|
||||
// 文章标题
|
||||
if article.ArticleTitle != req.ArticleTitle {
|
||||
articleData["article_title"] = req.ArticleTitle
|
||||
}
|
||||
|
||||
// 文章状态
|
||||
if article.ArticleStatus != req.ArticleStatus {
|
||||
articleData["article_status"] = req.ArticleStatus
|
||||
}
|
||||
|
||||
// 文章内容
|
||||
if article.ArticleContent != req.ArticleContent {
|
||||
articleData["article_content"] = req.ArticleContent
|
||||
}
|
||||
|
||||
// 票数
|
||||
if req.VoteNum != nil {
|
||||
if article.VoteNum != *req.VoteNum {
|
||||
articleData["vote_num"] = *req.VoteNum
|
||||
}
|
||||
}
|
||||
|
||||
// 修改
|
||||
if len(articleData) > 0 {
|
||||
err = articleDao.EditArticleById(tx, articleId, articleData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 删除作者
|
||||
articleAuthorDao := dao.ArticleAuthorDao{}
|
||||
maps := make(map[string]interface{})
|
||||
maps["article_id"] = articleId
|
||||
err = articleAuthorDao.DeleteArticleAuthor(tx, maps)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
baseHospitalDao := dao.BaseHospitalDao{}
|
||||
// 新增作者
|
||||
for _, author := range req.ArticleAuthor {
|
||||
if author.HospitalId == "" {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("请选择作者所属医院", c)
|
||||
return
|
||||
}
|
||||
|
||||
if author.AuthorName == "" {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("请输入作者名称", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 检测医院
|
||||
hospitalId, err := strconv.ParseInt(author.HospitalId, 10, 64)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
baseHospital, err := baseHospitalDao.GetBaseHospitalById(hospitalId)
|
||||
if err != nil || baseHospital == nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("医院错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
ArticleAuthor := &model.ArticleAuthor{
|
||||
ArticleId: articleId,
|
||||
AuthorName: author.AuthorName,
|
||||
HospitalId: hospitalId,
|
||||
}
|
||||
ArticleAuthor, err = articleAuthorDao.AddArticleAuthor(tx, ArticleAuthor)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// AddArticle 新增图文详情
|
||||
func (r *Article) AddArticle(c *gin.Context) {
|
||||
articleRequest := requests.ArticleRequest{}
|
||||
req := articleRequest.AddArticle
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.VoteNum != nil {
|
||||
if *req.VoteNum < 0 {
|
||||
responses.FailWithMessage("票数需大于0", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("操作失败", c)
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
articleDao := dao.ArticleDao{}
|
||||
|
||||
article := &model.Article{
|
||||
ArticleTitle: req.ArticleTitle,
|
||||
ArticleStatus: req.ArticleStatus,
|
||||
ArticleContent: req.ArticleContent,
|
||||
}
|
||||
|
||||
if req.VoteNum != nil {
|
||||
article.VoteNum = *req.VoteNum
|
||||
}
|
||||
|
||||
// 生成文章编号
|
||||
maps := make(map[string]interface{})
|
||||
total, err := articleDao.GetArticleCount(maps)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
article.ArticleNumber = fmt.Sprintf("%d", 1000+total+1)
|
||||
|
||||
article, err = articleDao.AddArticle(tx, article)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 新增作者
|
||||
baseHospitalDao := dao.BaseHospitalDao{}
|
||||
articleAuthorDao := dao.ArticleAuthorDao{}
|
||||
for _, author := range req.ArticleAuthor {
|
||||
if author.HospitalId == "" {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("请选择作者所属医院", c)
|
||||
return
|
||||
}
|
||||
|
||||
if author.AuthorName == "" {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("请输入作者名称", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 检测医院
|
||||
hospitalId, err := strconv.ParseInt(author.HospitalId, 10, 64)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
baseHospital, err := baseHospitalDao.GetBaseHospitalById(hospitalId)
|
||||
if err != nil || baseHospital == nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("医院错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
ArticleAuthor := &model.ArticleAuthor{
|
||||
ArticleId: article.ArticleId,
|
||||
AuthorName: author.AuthorName,
|
||||
HospitalId: hospitalId,
|
||||
}
|
||||
ArticleAuthor, err = articleAuthorDao.AddArticleAuthor(tx, ArticleAuthor)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutArticleStatus 操作图文状态
|
||||
func (r *Article) PutArticleStatus(c *gin.Context) {
|
||||
articleRequest := requests.ArticleRequest{}
|
||||
req := articleRequest.PutArticleStatus
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("article_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
articleId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取订单数据
|
||||
articleDao := dao.ArticleDao{}
|
||||
article, err := articleDao.GetArticleById(articleId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("图文异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
articleData := make(map[string]interface{})
|
||||
if req.ArticleStatus != article.ArticleStatus {
|
||||
articleData["article_status"] = req.ArticleStatus
|
||||
}
|
||||
|
||||
if len(articleData) > 0 {
|
||||
err = articleDao.EditArticleById(tx, articleId, articleData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("修改失败", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
14
api/controller/Base.go
Normal file
14
api/controller/Base.go
Normal file
@ -0,0 +1,14 @@
|
||||
package controller
|
||||
|
||||
// Api api接口
|
||||
type Api struct {
|
||||
Public // 公共方法
|
||||
Article // 图文
|
||||
Video // 视频
|
||||
BaseAgreement // 基础数据-协议
|
||||
User // 用户
|
||||
UserVoteDay // 投票记录
|
||||
System // 配置
|
||||
BaseHospital // 基础数据-医院
|
||||
Editor // 配置-编辑器
|
||||
}
|
||||
198
api/controller/BaseAgreement.go
Normal file
198
api/controller/BaseAgreement.go
Normal file
@ -0,0 +1,198 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
"vote-admin-video-api/api/dao"
|
||||
"vote-admin-video-api/api/dto"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/api/requests"
|
||||
"vote-admin-video-api/api/responses"
|
||||
"vote-admin-video-api/global"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
type BaseAgreement struct{}
|
||||
|
||||
// GetBaseAgreementPage 获取协议列表-分页
|
||||
func (b *BaseAgreement) GetBaseAgreementPage(c *gin.Context) {
|
||||
baseAgreementRequest := requests.BaseAgreementRequest{}
|
||||
req := baseAgreementRequest.GetBaseAgreementPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
// 获取分类数据
|
||||
baseAgreementDao := dao.BaseAgreementDao{}
|
||||
baseAgreement, total, err := baseAgreementDao.GetBaseAgreementPageSearch(req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetBaseAgreementListDto(baseAgreement)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetBaseAgreement 获取协议详情
|
||||
func (b *BaseAgreement) GetBaseAgreement(c *gin.Context) {
|
||||
id := c.Param("agreement_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
agreementId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取协议数据
|
||||
baseAgreementDao := dao.BaseAgreementDao{}
|
||||
baseAgreement, err := baseAgreementDao.GetBaseAgreementById(agreementId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("分类异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetBaseAgreementDto(baseAgreement)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
|
||||
// PutBaseAgreement 修改协议
|
||||
func (b *BaseAgreement) PutBaseAgreement(c *gin.Context) {
|
||||
BaseAgreementRequest := requests.BaseAgreementRequest{}
|
||||
req := BaseAgreementRequest.PutBaseAgreement
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("agreement_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
agreementId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取协议数据
|
||||
baseAgreementDao := dao.BaseAgreementDao{}
|
||||
baseAgreement, err := baseAgreementDao.GetBaseAgreementById(agreementId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("分类异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 修改值
|
||||
baseAgreementData := make(map[string]interface{})
|
||||
|
||||
// 协议标题
|
||||
if req.AgreementTitle != baseAgreement.AgreementTitle {
|
||||
baseAgreementData["agreement_title"] = req.AgreementTitle
|
||||
}
|
||||
|
||||
// 协议内容
|
||||
if req.AgreementContent != baseAgreement.AgreementContent {
|
||||
baseAgreementData["agreement_content"] = req.AgreementContent
|
||||
}
|
||||
|
||||
if len(baseAgreementData) > 0 {
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
err = baseAgreementDao.EditBaseAgreementById(tx, agreementId, baseAgreementData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("操作失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// AddBaseAgreement 新增协议
|
||||
func (b *BaseAgreement) AddBaseAgreement(c *gin.Context) {
|
||||
BaseAgreementRequest := requests.BaseAgreementRequest{}
|
||||
req := BaseAgreementRequest.AddBaseAgreement
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
baseAgreement := &model.BaseAgreement{
|
||||
AgreementTitle: req.AgreementTitle,
|
||||
AgreementType: req.AgreementType,
|
||||
AgreementContent: req.AgreementContent,
|
||||
}
|
||||
|
||||
baseAgreementDao := dao.BaseAgreementDao{}
|
||||
baseAgreement, err := baseAgreementDao.AddBaseAgreement(tx, baseAgreement)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
41
api/controller/BaseHospital.go
Normal file
41
api/controller/BaseHospital.go
Normal file
@ -0,0 +1,41 @@
|
||||
// Package controller 科室管理
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"vote-admin-video-api/api/dao"
|
||||
"vote-admin-video-api/api/dto"
|
||||
"vote-admin-video-api/api/requests"
|
||||
"vote-admin-video-api/api/responses"
|
||||
"vote-admin-video-api/global"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
type BaseHospital struct{}
|
||||
|
||||
// GetHospitalList 获取医院列表
|
||||
func (b *BaseHospital) GetHospitalList(c *gin.Context) {
|
||||
baseHospitalRequest := requests.BaseHospitalRequest{}
|
||||
req := baseHospitalRequest.GetBaseHospitalList
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
baseHospitalDao := dao.BaseHospitalDao{}
|
||||
baseHospitals, err := baseHospitalDao.GetBaseHospitalLimitByMaps(req)
|
||||
if err != nil {
|
||||
responses.Ok(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
getHospitalLimitResponse := dto.GetBaseHospitalListDto(baseHospitals)
|
||||
responses.OkWithData(getHospitalLimitResponse, c)
|
||||
}
|
||||
139
api/controller/Editor.go
Normal file
139
api/controller/Editor.go
Normal file
@ -0,0 +1,139 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"math/rand"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"time"
|
||||
"vote-admin-video-api/api/responses"
|
||||
e "vote-admin-video-api/extend/Editor"
|
||||
"vote-admin-video-api/extend/aliyun"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
type Editor struct{}
|
||||
|
||||
// GetEditorConfig 编辑器-获取配置
|
||||
func (b *Editor) GetEditorConfig(c *gin.Context) {
|
||||
action := c.Query("action")
|
||||
if action == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取配置 config
|
||||
if action == "config" {
|
||||
config := e.GetConfig()
|
||||
c.JSON(http.StatusOK, config)
|
||||
return
|
||||
}
|
||||
|
||||
// 图片列表 listImage
|
||||
if action == "listImage" {
|
||||
responses.Ok(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 文件列表 listFile
|
||||
if action == "listFile" {
|
||||
responses.Ok(c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
return
|
||||
}
|
||||
|
||||
// EditorUpload 编辑器-上传
|
||||
func (b *Editor) EditorUpload(c *gin.Context) {
|
||||
action := c.Query("action")
|
||||
if action == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
file, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
responses.FailWithMessage("文件错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
f, err := file.Open()
|
||||
if err != nil {
|
||||
responses.FailWithMessage("文件错误", c)
|
||||
return
|
||||
}
|
||||
defer func(f multipart.File) {
|
||||
err := f.Close()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}(f)
|
||||
|
||||
// 读取文件内容到字节切片
|
||||
fileBytes, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("文件错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 添加图片水印
|
||||
fileBytes, err = utils.AddWatermarkToImage(fileBytes, "./resource/3061726102564.png")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
fileType := "jpg"
|
||||
if file.Filename != "" {
|
||||
fileType = utils.GetExtension(file.Filename)
|
||||
if fileType == "" {
|
||||
fileType = "jpg"
|
||||
}
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
dateTimeString := now.Format("20060102150405") // 当前时间字符串
|
||||
rand.New(rand.NewSource(time.Now().UnixNano())) // 设置随机数
|
||||
|
||||
var ossPath string
|
||||
|
||||
// 上传图片 image
|
||||
if action == "image" {
|
||||
ossPath = "static/images/" + fmt.Sprintf("%d", rand.Intn(9000)+1000) + dateTimeString + "." + fileType
|
||||
}
|
||||
|
||||
// 上传视频 video
|
||||
if action == "video" {
|
||||
ossPath = "static/video/" + fmt.Sprintf("%d", rand.Intn(9000)+1000) + dateTimeString + "." + fileType
|
||||
}
|
||||
|
||||
// 上传文件 file
|
||||
if action == "file" {
|
||||
ossPath = "static/file/" + fmt.Sprintf("%d", rand.Intn(9000)+1000) + dateTimeString + "." + fileType
|
||||
}
|
||||
|
||||
if ossPath == "" {
|
||||
responses.FailWithMessage("上传失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 上传oss
|
||||
_, err = aliyun.PutObjectByte(ossPath, fileBytes)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
var g e.UploadDto
|
||||
g.Url = utils.AddOssDomain("/" + ossPath)
|
||||
g.State = "SUCCESS"
|
||||
g.Title = dateTimeString + "." + fileType
|
||||
g.Original = dateTimeString + "." + fileType
|
||||
g.Type = fileType
|
||||
|
||||
c.JSON(http.StatusOK, g)
|
||||
return
|
||||
}
|
||||
226
api/controller/Public.go
Normal file
226
api/controller/Public.go
Normal file
@ -0,0 +1,226 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"time"
|
||||
"vote-admin-video-api/api/dao"
|
||||
"vote-admin-video-api/api/dto"
|
||||
"vote-admin-video-api/api/requests"
|
||||
"vote-admin-video-api/api/responses"
|
||||
"vote-admin-video-api/config"
|
||||
"vote-admin-video-api/global"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
type Public struct{}
|
||||
|
||||
// Login 登陆
|
||||
func (b *Public) Login(c *gin.Context) {
|
||||
publicRequest := requests.PublicRequest{}
|
||||
req := publicRequest.Login
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 验证验证码
|
||||
if config.C.Env == "prod" {
|
||||
isValid := utils.VerifyCaptcha(req.CaptchaId, req.Captcha)
|
||||
if !isValid {
|
||||
// 验证码错误
|
||||
responses.FailWithMessage("验证码错误", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
AdminUserDao := dao.AdminUserDao{}
|
||||
maps := make(map[string]interface{})
|
||||
maps["access"] = req.Access
|
||||
adminUser, err := AdminUserDao.GetAdminUser(maps)
|
||||
if err != nil || adminUser == nil {
|
||||
responses.FailWithMessage("用户名或密码错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 检测用户密码
|
||||
password := md5.Sum([]byte(req.Password + adminUser.Salt))
|
||||
// 将哈希值转换为16进制字符串
|
||||
passwordString := hex.EncodeToString(password[:])
|
||||
|
||||
fmt.Println(passwordString)
|
||||
if passwordString != adminUser.Password {
|
||||
responses.FailWithMessage("用户名或密码错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 检测用户状态
|
||||
if adminUser.IsDeleted == 1 {
|
||||
responses.FailWithMessage("非法用户", c)
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.IsDisabled == 1 {
|
||||
responses.FailWithMessage("您的账号已被禁用,请联系管理员处理", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 下发token
|
||||
token := &utils.Token{
|
||||
UserId: fmt.Sprintf("%d", adminUser.UserId),
|
||||
}
|
||||
|
||||
// 生成jwt
|
||||
jwt, err := token.NewJWT()
|
||||
if err != nil || jwt == "" {
|
||||
responses.FailWithMessage("登陆失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
g := dto.AdminLoginDto(adminUser)
|
||||
|
||||
g.LoadToken(jwt)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
|
||||
// GetCaptcha 获取验证码
|
||||
func (b *Public) GetCaptcha(c *gin.Context) {
|
||||
id, b64s, err := utils.GenerateCaptcha()
|
||||
if err != nil {
|
||||
responses.FailWithMessage("验证码获取失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(gin.H{
|
||||
"id": id,
|
||||
"b64s": b64s,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// GetIndex 首页
|
||||
func (b *Public) GetIndex(c *gin.Context) {
|
||||
dataDao := dao.DataDao{}
|
||||
data, err := dataDao.GetDataById(1)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
g := dto.IndexDto{
|
||||
ViewNum: data.ViewNum,
|
||||
VoteNum: data.VoteNum,
|
||||
}
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
|
||||
// GetIndexData 首页动态统计数据
|
||||
func (b *Public) GetIndexData(c *gin.Context) {
|
||||
publicRequest := requests.PublicRequest{}
|
||||
req := publicRequest.GetIndexData
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 返回值
|
||||
var g []*dto.IndexDataDto
|
||||
results := make(map[string]int64)
|
||||
|
||||
// 分类(1:新增用户数 2:图文投票数 3:视频投票数)
|
||||
if req.Type == 1 {
|
||||
// 新增用户数
|
||||
endTime, _ := time.Parse("2006-01-02", req.EndTime)
|
||||
req.EndTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second).Format("2006-01-02 15:04:05")
|
||||
|
||||
userDao := dao.UserDao{}
|
||||
maps := make(map[string]interface{})
|
||||
users, err := userDao.GetUserListByTime(maps, req.StartTime, req.EndTime, "created_at")
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
date := time.Time(user.CreatedAt).Format("2006-01-02")
|
||||
results[date]++
|
||||
}
|
||||
}
|
||||
|
||||
// 图文投票数
|
||||
if req.Type == 2 {
|
||||
endTime, _ := time.Parse("2006-01-02", req.EndTime)
|
||||
req.EndTime = endTime.Format("2006-01-02")
|
||||
|
||||
articleVoteDayDao := dao.ArticleVoteDayDao{}
|
||||
maps := make(map[string]interface{})
|
||||
articleVoteDays, err := articleVoteDayDao.GetArticleVoteDayListByTime(maps, req.StartTime, req.EndTime, "voted_at")
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
for _, articleVoteDay := range articleVoteDays {
|
||||
votedAt := time.Time(*articleVoteDay.VotedAt)
|
||||
date := votedAt.Format("2006-01-02")
|
||||
results[date]++
|
||||
}
|
||||
}
|
||||
|
||||
// 视频投票数
|
||||
if req.Type == 3 {
|
||||
endTime, _ := time.Parse("2006-01-02", req.EndTime)
|
||||
req.EndTime = endTime.Format("2006-01-02")
|
||||
|
||||
videoVoteDayDao := dao.VideoVoteDayDao{}
|
||||
maps := make(map[string]interface{})
|
||||
videoVoteDays, err := videoVoteDayDao.GetVideoVoteDayListByTime(maps, req.StartTime, req.EndTime, "voted_at")
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
for _, videoVoteDay := range videoVoteDays {
|
||||
votedAt := time.Time(*videoVoteDay.VotedAt)
|
||||
date := votedAt.Format("2006-01-02")
|
||||
results[date]++
|
||||
}
|
||||
}
|
||||
|
||||
for k, v := range results {
|
||||
response := &dto.IndexDataDto{
|
||||
Date: k,
|
||||
Count: v,
|
||||
}
|
||||
|
||||
g = append(g, response)
|
||||
}
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
153
api/controller/System.go
Normal file
153
api/controller/System.go
Normal file
@ -0,0 +1,153 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
"time"
|
||||
"vote-admin-video-api/api/dao"
|
||||
"vote-admin-video-api/api/dto"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/api/requests"
|
||||
"vote-admin-video-api/api/responses"
|
||||
"vote-admin-video-api/global"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
type System struct{}
|
||||
|
||||
// GetSystemTime 获取投票时间详情
|
||||
func (r *System) GetSystemTime(c *gin.Context) {
|
||||
id := c.Param("system_time_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
systemTimeId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
systemTimeDao := dao.SystemTimeDao{}
|
||||
systemTime, err := systemTimeDao.GetSystemTimeById(systemTimeId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("数据异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetSystemTimeDto(systemTime)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
|
||||
// PutSystemTime 修改投票时间
|
||||
func (b *System) PutSystemTime(c *gin.Context) {
|
||||
systemRequest := requests.SystemRequest{}
|
||||
req := systemRequest.PutSystemTime
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("system_time_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
systemTimeId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
systemTimeDao := dao.SystemTimeDao{}
|
||||
systemTime, err := systemTimeDao.GetSystemTimeById(systemTimeId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("数据异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 修改值
|
||||
systemTimeData := make(map[string]interface{})
|
||||
|
||||
// 获取本地时区
|
||||
location, err := time.LoadLocation("Local")
|
||||
if err != nil {
|
||||
responses.FailWithMessage("修改失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
startTime, err := time.ParseInLocation("2006-01-02 15:04:05", req.StartTime, location)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("修改失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
if model.LocalTime(startTime) != *systemTime.StartTime {
|
||||
systemTimeData["start_time"] = req.StartTime
|
||||
}
|
||||
|
||||
endTime, err := time.ParseInLocation("2006-01-02 15:04:05", req.EndTime, location)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("修改失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
if model.LocalTime(endTime) != *systemTime.EndTime {
|
||||
systemTimeData["end_time"] = req.EndTime
|
||||
}
|
||||
|
||||
if len(systemTimeData) > 0 {
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
err = systemTimeDao.EditSystemTimeById(tx, systemTimeId, systemTimeData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("操作失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 增加过期时间缓存
|
||||
redisKey := "VoteSystemTime"
|
||||
// 当前时间
|
||||
now := time.Now()
|
||||
|
||||
duration := endTime.Sub(now)
|
||||
if duration < 0 {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("结束时间错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 添加缓存
|
||||
_, err = global.Redis.Set(c, redisKey, "1", duration).Result()
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("修改失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
147
api/controller/User.go
Normal file
147
api/controller/User.go
Normal file
@ -0,0 +1,147 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
"vote-admin-video-api/api/dao"
|
||||
"vote-admin-video-api/api/dto"
|
||||
"vote-admin-video-api/api/requests"
|
||||
"vote-admin-video-api/api/responses"
|
||||
"vote-admin-video-api/global"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
type User struct{}
|
||||
|
||||
// GetUserPage 获取用户列表-分页
|
||||
func (r *User) GetUserPage(c *gin.Context) {
|
||||
userRequest := requests.UserRequest{}
|
||||
req := userRequest.GetUserPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
userDao := dao.UserDao{}
|
||||
user, total, err := userDao.GetUserPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetUserListDto(user)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetUser 获取用户详情
|
||||
func (r *User) GetUser(c *gin.Context) {
|
||||
id := c.Param("user_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
userId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("用户异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetUserDto(user)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
|
||||
// PutUserStatus 操作用户状态
|
||||
func (r *User) PutUserStatus(c *gin.Context) {
|
||||
userRequest := requests.UserRequest{}
|
||||
req := userRequest.PutUserStatus
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("user_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
userId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("用户异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.UserStatus == user.UserStatus {
|
||||
responses.Ok(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
userData := make(map[string]interface{})
|
||||
userData["user_status"] = req.UserStatus
|
||||
err = userDao.EditUserById(tx, userId, userData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("操作失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
262
api/controller/UserVoteDay.go
Normal file
262
api/controller/UserVoteDay.go
Normal file
@ -0,0 +1,262 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
"time"
|
||||
"vote-admin-video-api/api/dao"
|
||||
"vote-admin-video-api/api/dto"
|
||||
"vote-admin-video-api/api/requests"
|
||||
"vote-admin-video-api/api/responses"
|
||||
"vote-admin-video-api/global"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
type UserVoteDay struct{}
|
||||
|
||||
// GetUserArticleVotePage 用户投票记录列表-图文-分页
|
||||
func (r *UserVoteDay) GetUserArticleVotePage(c *gin.Context) {
|
||||
userVoteDayRequest := requests.UserVoteDayRequest{}
|
||||
req := userVoteDayRequest.GetArticleUserVoteDayPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
userId, err := strconv.ParseInt(req.UserId, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
var total int64
|
||||
|
||||
articleVoteDayDao := dao.ArticleVoteDayDao{}
|
||||
articleVoteDay, total, err := articleVoteDayDao.GetArticleVoteDayByUserIdPageSearch(userId, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := make([]*dto.UserVoteDto, len(articleVoteDay))
|
||||
for i, v := range articleVoteDay {
|
||||
createdAt := time.Time(v.CreatedAt).Format("2006-01-02 15:04:05")
|
||||
|
||||
response := &dto.UserVoteDto{
|
||||
Id: fmt.Sprintf("%d", v.ArticleId),
|
||||
Title: v.Article.ArticleTitle,
|
||||
VotedAt: createdAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
g[i] = response
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetUserVideoVotePage 用户投票记录列表-视频-分页
|
||||
func (r *UserVoteDay) GetUserVideoVotePage(c *gin.Context) {
|
||||
userVoteDayRequest := requests.UserVoteDayRequest{}
|
||||
req := userVoteDayRequest.GetVideoUserVoteDayPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
userId, err := strconv.ParseInt(req.UserId, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
var total int64
|
||||
|
||||
videoVoteDayDao := dao.VideoVoteDayDao{}
|
||||
videoVoteDay, total, err := videoVoteDayDao.GetVideoVoteDayByUserIdPageSearch(userId, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := make([]*dto.UserVoteDto, len(videoVoteDay))
|
||||
for i, v := range videoVoteDay {
|
||||
createdAt := time.Time(v.CreatedAt).Format("2006-01-02 15:04:05")
|
||||
|
||||
response := &dto.UserVoteDto{
|
||||
Id: fmt.Sprintf("%d", v.VideoId),
|
||||
Title: v.Video.VideoTitle,
|
||||
VotedAt: createdAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
g[i] = response
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetArticleVotePage 投票记录列表-图文-分页
|
||||
func (r *UserVoteDay) GetArticleVotePage(c *gin.Context) {
|
||||
userVoteDayRequest := requests.UserVoteDayRequest{}
|
||||
req := userVoteDayRequest.GetArticleVoteDayPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
articleId, err := strconv.ParseInt(req.ArticleId, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
var total int64
|
||||
|
||||
articleVoteDayDao := dao.ArticleVoteDayDao{}
|
||||
articleVoteDay, total, err := articleVoteDayDao.GetArticleVoteDayByArticleIdPageSearch(articleId, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := make([]*dto.UserVoteDto, len(articleVoteDay))
|
||||
for i, v := range articleVoteDay {
|
||||
createdAt := time.Time(v.CreatedAt).Format("2006-01-02 15:04:05")
|
||||
|
||||
response := &dto.UserVoteDto{
|
||||
Id: fmt.Sprintf("%d", v.ArticleId),
|
||||
AppIden: v.User.AppIden,
|
||||
OpenId: v.User.OpenId,
|
||||
VotedAt: createdAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
g[i] = response
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetVideoVotePage 投票记录列表-视频-分页
|
||||
func (r *UserVoteDay) GetVideoVotePage(c *gin.Context) {
|
||||
userVoteDayRequest := requests.UserVoteDayRequest{}
|
||||
req := userVoteDayRequest.GetVideoVoteDayPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
videoId, err := strconv.ParseInt(req.VideoId, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
var total int64
|
||||
|
||||
videoVoteDayDao := dao.VideoVoteDayDao{}
|
||||
videoVoteDay, total, err := videoVoteDayDao.GetVideoVoteDayByVideoIdPageSearch(videoId, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := make([]*dto.UserVoteDto, len(videoVoteDay))
|
||||
for i, v := range videoVoteDay {
|
||||
createdAt := time.Time(v.CreatedAt).Format("2006-01-02 15:04:05")
|
||||
|
||||
response := &dto.UserVoteDto{
|
||||
Id: fmt.Sprintf("%d", v.VideoId),
|
||||
AppIden: v.User.AppIden,
|
||||
OpenId: v.User.OpenId,
|
||||
VotedAt: createdAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
g[i] = response
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
437
api/controller/Video.go
Normal file
437
api/controller/Video.go
Normal file
@ -0,0 +1,437 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"strconv"
|
||||
"vote-admin-video-api/api/dao"
|
||||
"vote-admin-video-api/api/dto"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/api/requests"
|
||||
"vote-admin-video-api/api/responses"
|
||||
"vote-admin-video-api/global"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
type Video struct{}
|
||||
|
||||
// GetVideoPage 获取视频列表-分页
|
||||
func (r *Video) GetVideoPage(c *gin.Context) {
|
||||
VideoRequest := requests.VideoRequest{}
|
||||
req := VideoRequest.GetVideoPage
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
if req.Order != nil {
|
||||
if req.Order.VoteNum != "" {
|
||||
if req.Order.VoteNum != "desc" && req.Order.VoteNum != "asc" {
|
||||
responses.FailWithMessage("排序字段错误", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
VideoDao := dao.VideoDao{}
|
||||
Videos, total, err := VideoDao.GetVideoPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetVideoListDto(Videos)
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = g
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetVideo 获取视频详情
|
||||
func (r *Video) GetVideo(c *gin.Context) {
|
||||
id := c.Param("video_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
videoId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
VideoDao := dao.VideoDao{}
|
||||
video, err := VideoDao.GetVideoById(videoId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("视频错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取作者数据
|
||||
VideoAuthorDao := dao.VideoAuthorDao{}
|
||||
maps := make(map[string]interface{})
|
||||
maps["video_id"] = videoId
|
||||
VideoAuthors, err := VideoAuthorDao.GetVideoAuthorPreloadList(maps)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("视频错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取排名
|
||||
rank, _ := VideoDao.GetVideoRank(video.VideoId)
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetVideoDto(video)
|
||||
|
||||
// 加载数据-作者
|
||||
g.LoadVideoAuthor(VideoAuthors)
|
||||
|
||||
// 加载数据-作者排名
|
||||
g.LoadRank(rank)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
|
||||
// PutVideo 修改视频详情
|
||||
func (r *Video) PutVideo(c *gin.Context) {
|
||||
VideoRequest := requests.VideoRequest{}
|
||||
req := VideoRequest.PutVideo
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("video_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
videoId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.VoteNum != nil {
|
||||
if *req.VoteNum < 0 {
|
||||
responses.FailWithMessage("票数需大于0", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单数据
|
||||
videoDao := dao.VideoDao{}
|
||||
video, err := videoDao.GetVideoById(videoId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("视频异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
fmt.Println(r)
|
||||
}
|
||||
}()
|
||||
|
||||
videoData := make(map[string]interface{})
|
||||
|
||||
// 视频标题
|
||||
if video.VideoTitle != req.VideoTitle {
|
||||
videoData["video_title"] = req.VideoTitle
|
||||
}
|
||||
|
||||
// 视频状态
|
||||
if video.VideoStatus != req.VideoStatus {
|
||||
videoData["video_status"] = req.VideoStatus
|
||||
}
|
||||
|
||||
if req.VoteNum != nil {
|
||||
if video.VoteNum != *req.VoteNum {
|
||||
videoData["vote_num"] = *req.VoteNum
|
||||
}
|
||||
}
|
||||
|
||||
// 视频编号
|
||||
if video.VideoNo != req.VideoNo {
|
||||
videoData["video_no"] = req.VideoNo
|
||||
}
|
||||
|
||||
// 视频内容
|
||||
if video.VideoContent != req.VideoContent {
|
||||
videoData["video_content"] = req.VideoContent
|
||||
}
|
||||
|
||||
// 修改
|
||||
if len(videoData) > 0 {
|
||||
err = videoDao.EditVideoById(tx, videoId, videoData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 删除作者
|
||||
VideoAuthorDao := dao.VideoAuthorDao{}
|
||||
maps := make(map[string]interface{})
|
||||
maps["video_id"] = videoId
|
||||
err = VideoAuthorDao.DeleteVideoAuthor(tx, maps)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
baseHospitalDao := dao.BaseHospitalDao{}
|
||||
// 新增作者
|
||||
for _, author := range req.VideoAuthor {
|
||||
if author.HospitalId == "" {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("请选择作者所属医院", c)
|
||||
return
|
||||
}
|
||||
|
||||
if author.AuthorName == "" {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("请输入作者名称", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 检测医院
|
||||
hospitalId, err := strconv.ParseInt(author.HospitalId, 10, 64)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
baseHospital, err := baseHospitalDao.GetBaseHospitalById(hospitalId)
|
||||
if err != nil || baseHospital == nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("医院错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
videoAuthor := &model.VideoAuthor{
|
||||
VideoId: videoId,
|
||||
AuthorName: author.AuthorName,
|
||||
HospitalId: hospitalId,
|
||||
}
|
||||
videoAuthor, err = VideoAuthorDao.AddVideoAuthor(tx, videoAuthor)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// AddVideo 新增视频详情
|
||||
func (r *Video) AddVideo(c *gin.Context) {
|
||||
videoRequest := requests.VideoRequest{}
|
||||
req := videoRequest.AddVideo
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.VoteNum != nil {
|
||||
if *req.VoteNum < 0 {
|
||||
responses.FailWithMessage("票数需大于0", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("操作失败", c)
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
videoDao := dao.VideoDao{}
|
||||
|
||||
video := &model.Video{
|
||||
VideoTitle: req.VideoTitle,
|
||||
VideoStatus: req.VideoStatus,
|
||||
VideoNo: req.VideoNo,
|
||||
VideoContent: req.VideoContent,
|
||||
}
|
||||
|
||||
if req.VoteNum != nil {
|
||||
video.VoteNum = *req.VoteNum
|
||||
}
|
||||
|
||||
// 获取总数量
|
||||
maps := make(map[string]interface{})
|
||||
total, err := videoDao.GetVideoCount(maps)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 生成视频编号
|
||||
video.VideoNumber = fmt.Sprintf("%d", 2000+total+1)
|
||||
|
||||
video, err = videoDao.AddVideo(tx, video)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 新增作者
|
||||
baseHospitalDao := dao.BaseHospitalDao{}
|
||||
videoAuthorDao := dao.VideoAuthorDao{}
|
||||
for _, author := range req.VideoAuthor {
|
||||
if author.HospitalId == "" {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("请选择作者所属医院", c)
|
||||
return
|
||||
}
|
||||
|
||||
if author.AuthorName == "" {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("请输入作者名称", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 检测医院
|
||||
hospitalId, err := strconv.ParseInt(author.HospitalId, 10, 64)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
baseHospital, err := baseHospitalDao.GetBaseHospitalById(hospitalId)
|
||||
if err != nil || baseHospital == nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("医院错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
videoAuthor := &model.VideoAuthor{
|
||||
VideoId: video.VideoId,
|
||||
AuthorName: author.AuthorName,
|
||||
HospitalId: hospitalId,
|
||||
}
|
||||
videoAuthor, err = videoAuthorDao.AddVideoAuthor(tx, videoAuthor)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// PutVideoStatus 操作视频状态
|
||||
func (r *Video) PutVideoStatus(c *gin.Context) {
|
||||
videoRequest := requests.VideoRequest{}
|
||||
req := videoRequest.PutVideoStatus
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("video_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
videoId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取订单数据
|
||||
videoDao := dao.VideoDao{}
|
||||
video, err := videoDao.GetVideoById(videoId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("视频异常", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
videoData := make(map[string]interface{})
|
||||
if req.VideoStatus != video.VideoStatus {
|
||||
videoData["video_status"] = req.VideoStatus
|
||||
}
|
||||
|
||||
if len(videoData) > 0 {
|
||||
err = videoDao.EditVideoById(tx, videoId, videoData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("修改失败", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
108
api/dao/AdminUser.go
Normal file
108
api/dao/AdminUser.go
Normal file
@ -0,0 +1,108 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type AdminUserDao struct {
|
||||
}
|
||||
|
||||
// GetAdminUserById 获取数据-id
|
||||
func (r *AdminUserDao) GetAdminUserById(AdminUserId int64) (m *model.AdminUser, err error) {
|
||||
err = global.Db.First(&m, AdminUserId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetAdminUserPreloadById 获取数据-加载全部关联-id
|
||||
func (r *AdminUserDao) GetAdminUserPreloadById(AdminUserId int64) (m *model.AdminUser, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, AdminUserId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteAdminUser 删除
|
||||
func (r *AdminUserDao) DeleteAdminUser(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.AdminUser{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteAdminUserById 删除-id
|
||||
func (r *AdminUserDao) DeleteAdminUserById(tx *gorm.DB, AdminUserId int64) error {
|
||||
if err := tx.Delete(&model.AdminUser{}, AdminUserId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditAdminUser 修改
|
||||
func (r *AdminUserDao) EditAdminUser(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.AdminUser{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditAdminUserById 修改-id
|
||||
func (r *AdminUserDao) EditAdminUserById(tx *gorm.DB, AdminUserId int64, data interface{}) error {
|
||||
err := tx.Model(&model.AdminUser{}).Where("AdminUser_id = ?", AdminUserId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAdminUserList 获取列表
|
||||
func (r *AdminUserDao) GetAdminUserList(maps interface{}) (m []*model.AdminUser, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetAdminUserCount 获取数量
|
||||
func (r *AdminUserDao) GetAdminUserCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.AdminUser{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetAdminUserListRand 获取列表-随机
|
||||
func (r *AdminUserDao) GetAdminUserListRand(maps interface{}, limit int) (m []*model.AdminUser, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddAdminUser 新增
|
||||
func (r *AdminUserDao) AddAdminUser(tx *gorm.DB, model *model.AdminUser) (*model.AdminUser, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetAdminUser 获取
|
||||
func (r *AdminUserDao) GetAdminUser(maps interface{}) (m *model.AdminUser, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
228
api/dao/Article.go
Normal file
228
api/dao/Article.go
Normal file
@ -0,0 +1,228 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/api/requests"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type ArticleDao struct {
|
||||
}
|
||||
|
||||
// GetArticleById 获取数据-id
|
||||
func (r *ArticleDao) GetArticleById(ArticleId int64) (m *model.Article, err error) {
|
||||
err = global.Db.First(&m, ArticleId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticlePreloadById 获取数据-加载全部关联-id
|
||||
func (r *ArticleDao) GetArticlePreloadById(ArticleId int64) (m *model.Article, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, ArticleId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteArticle 删除
|
||||
func (r *ArticleDao) DeleteArticle(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.Article{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteArticleById 删除-id
|
||||
func (r *ArticleDao) DeleteArticleById(tx *gorm.DB, ArticleId int64) error {
|
||||
if err := tx.Delete(&model.Article{}, ArticleId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditArticle 修改
|
||||
func (r *ArticleDao) EditArticle(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.Article{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditArticleById 修改-id
|
||||
func (r *ArticleDao) EditArticleById(tx *gorm.DB, ArticleId int64, data interface{}) error {
|
||||
err := tx.Model(&model.Article{}).Where("article_id = ?", ArticleId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetArticleList 获取列表
|
||||
func (r *ArticleDao) GetArticleList(maps interface{}) (m []*model.Article, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticleCount 获取数量
|
||||
func (r *ArticleDao) GetArticleCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.Article{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetArticleListRand 获取列表-随机
|
||||
func (r *ArticleDao) GetArticleListRand(maps interface{}, limit int) (m []*model.Article, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddArticle 新增
|
||||
func (r *ArticleDao) AddArticle(tx *gorm.DB, model *model.Article) (*model.Article, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetArticle 获取
|
||||
func (r *ArticleDao) GetArticle(maps interface{}) (m *model.Article, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Inc 自增
|
||||
func (r *ArticleDao) Inc(tx *gorm.DB, ArticleId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.Article{}).Where("article_id = ?", ArticleId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dec 自减
|
||||
func (r *ArticleDao) Dec(tx *gorm.DB, ArticleId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.Article{}).Where("article_id = ?", ArticleId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetArticlePageSearch 获取图文列表-分页
|
||||
func (r *ArticleDao) GetArticlePageSearch(req requests.GetArticlePage, page, pageSize int) (m []*model.Article, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.Article{})
|
||||
|
||||
// 作者
|
||||
query = query.Preload("ArticleAuthor")
|
||||
|
||||
// 作者关联医院
|
||||
query = query.Preload("ArticleAuthor.BaseHospital")
|
||||
|
||||
// 搜索关键字
|
||||
if req.Keyword != "" {
|
||||
keyword := "%" + req.Keyword + "%" //
|
||||
|
||||
// 标题
|
||||
orQuery := global.Db.Model(&model.Article{}).Or("article_title LIKE ?", keyword)
|
||||
|
||||
// 医院名称
|
||||
hospitalSubQuery := global.Db.Model(&model.BaseHospital{}).
|
||||
Select("hospital_id").
|
||||
Where("hospital_name LIKE ?", keyword)
|
||||
|
||||
articleAuthorSubQuery := global.Db.Model(&model.ArticleAuthor{}).
|
||||
Select("article_id").
|
||||
Where(gorm.Expr("hospital_id IN (?)", hospitalSubQuery))
|
||||
|
||||
orQuery = orQuery.Or(gorm.Expr("article_id IN (?)", articleAuthorSubQuery))
|
||||
|
||||
// 作者姓名
|
||||
subQuery := global.Db.Model(&model.ArticleAuthor{}).
|
||||
Select("article_id").
|
||||
Where("author_name LIKE ?", keyword)
|
||||
|
||||
orQuery = orQuery.Or(gorm.Expr("article_id IN (?)", subQuery))
|
||||
|
||||
// 执行组建
|
||||
query = query.Where(orQuery)
|
||||
}
|
||||
|
||||
// 文章状态
|
||||
if req.ArticleStatus != nil {
|
||||
query = query.Where("article_status = ?", req.ArticleStatus)
|
||||
}
|
||||
|
||||
// 排序
|
||||
if req.Order != nil {
|
||||
if req.Order.VoteNum != "" {
|
||||
query = query.Order("vote_num " + req.Order.VoteNum)
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetArticleOrderList 获取列表-排序
|
||||
func (r *ArticleDao) GetArticleOrderList(maps interface{}, orderField string, limit int) (m []*model.Article, err error) {
|
||||
err = global.Db.Where(maps).Preload(clause.Associations).Order(orderField).Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticleRank 获取某一条数据的排名
|
||||
func (r *ArticleDao) GetArticleRank(articleID int64) (int, error) {
|
||||
var rank int
|
||||
|
||||
// 定义子查询
|
||||
subQuery := global.Db.Model(&model.Article{}).
|
||||
Select("article_id, vote_num, (@rank := @rank + 1) AS rank").
|
||||
Where("article_status = ?", 1).
|
||||
Order("vote_num DESC").
|
||||
Joins(", (SELECT @rank := 0) AS r")
|
||||
|
||||
// 将子查询作为命名子查询的一部分进行查询
|
||||
err := global.Db.Table("(?) AS sub", subQuery).
|
||||
Where("sub.article_id = ?", articleID).
|
||||
Pluck("sub.rank", &rank).Error
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return rank, nil
|
||||
}
|
||||
135
api/dao/ArticleAuthor.go
Normal file
135
api/dao/ArticleAuthor.go
Normal file
@ -0,0 +1,135 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type ArticleAuthorDao struct {
|
||||
}
|
||||
|
||||
// GetArticleAuthorById 获取数据-id
|
||||
func (r *ArticleAuthorDao) GetArticleAuthorById(AuthorId int64) (m *model.ArticleAuthor, err error) {
|
||||
err = global.Db.First(&m, AuthorId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticleAuthorPreloadById 获取数据-加载全部关联-id
|
||||
func (r *ArticleAuthorDao) GetArticleAuthorPreloadById(AuthorId int64) (m *model.ArticleAuthor, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, AuthorId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteArticleAuthor 删除
|
||||
func (r *ArticleAuthorDao) DeleteArticleAuthor(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.ArticleAuthor{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteArticleAuthorById 删除-id
|
||||
func (r *ArticleAuthorDao) DeleteArticleAuthorById(tx *gorm.DB, ArticleAuthorId int64) error {
|
||||
if err := tx.Delete(&model.ArticleAuthor{}, ArticleAuthorId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditArticleAuthor 修改
|
||||
func (r *ArticleAuthorDao) EditArticleAuthor(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.ArticleAuthor{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditArticleAuthorById 修改-id
|
||||
func (r *ArticleAuthorDao) EditArticleAuthorById(tx *gorm.DB, AuthorId int64, data interface{}) error {
|
||||
err := tx.Model(&model.ArticleAuthor{}).Where("author_id = ?", AuthorId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetArticleAuthorList 获取列表
|
||||
func (r *ArticleAuthorDao) GetArticleAuthorList(maps interface{}) (m []*model.ArticleAuthor, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticleAuthorPreloadList 获取列表-加载全部关联
|
||||
func (r *ArticleAuthorDao) GetArticleAuthorPreloadList(maps interface{}) (m []*model.ArticleAuthor, err error) {
|
||||
err = global.Db.Preload(clause.Associations).Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticleAuthorCount 获取数量
|
||||
func (r *ArticleAuthorDao) GetArticleAuthorCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.ArticleAuthor{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetArticleAuthorListRand 获取列表-随机
|
||||
func (r *ArticleAuthorDao) GetArticleAuthorListRand(maps interface{}, limit int) (m []*model.ArticleAuthor, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddArticleAuthor 新增
|
||||
func (r *ArticleAuthorDao) AddArticleAuthor(tx *gorm.DB, model *model.ArticleAuthor) (*model.ArticleAuthor, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetArticleAuthor 获取
|
||||
func (r *ArticleAuthorDao) GetArticleAuthor(maps interface{}) (m *model.ArticleAuthor, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Inc 自增
|
||||
func (r *ArticleAuthorDao) Inc(tx *gorm.DB, AuthorId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.ArticleAuthor{}).Where("author_id = ?", AuthorId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dec 自减
|
||||
func (r *ArticleAuthorDao) Dec(tx *gorm.DB, AuthorId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.ArticleAuthor{}).Where("author_id = ?", AuthorId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
187
api/dao/ArticleVoteDay.go
Normal file
187
api/dao/ArticleVoteDay.go
Normal file
@ -0,0 +1,187 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type ArticleVoteDayDao struct {
|
||||
}
|
||||
|
||||
// GetArticleVoteDayById 获取数据-id
|
||||
func (r *ArticleVoteDayDao) GetArticleVoteDayById(voteDayId int64) (m *model.ArticleVoteDay, err error) {
|
||||
err = global.Db.First(&m, voteDayId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticleVoteDayPreloadById 获取数据-加载全部关联-id
|
||||
func (r *ArticleVoteDayDao) GetArticleVoteDayPreloadById(voteDayId int64) (m *model.ArticleVoteDay, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, voteDayId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteArticleVoteDay 删除
|
||||
func (r *ArticleVoteDayDao) DeleteArticleVoteDay(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.ArticleVoteDay{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteArticleVoteDayById 删除-id
|
||||
func (r *ArticleVoteDayDao) DeleteArticleVoteDayById(tx *gorm.DB, voteDayId int64) error {
|
||||
if err := tx.Delete(&model.ArticleVoteDay{}, voteDayId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditArticleVoteDay 修改
|
||||
func (r *ArticleVoteDayDao) EditArticleVoteDay(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.ArticleVoteDay{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditArticleVoteDayById 修改-id
|
||||
func (r *ArticleVoteDayDao) EditArticleVoteDayById(tx *gorm.DB, voteDayId int64, data interface{}) error {
|
||||
err := tx.Model(&model.ArticleVoteDay{}).Where("vote_day_id = ?", voteDayId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetArticleVoteDayList 获取列表
|
||||
func (r *ArticleVoteDayDao) GetArticleVoteDayList(maps interface{}) (m []*model.ArticleVoteDay, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticleVoteDayCount 获取数量
|
||||
func (r *ArticleVoteDayDao) GetArticleVoteDayCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.ArticleVoteDay{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetArticleVoteDayListRand 获取列表-随机
|
||||
func (r *ArticleVoteDayDao) GetArticleVoteDayListRand(maps interface{}, limit int) (m []*model.ArticleVoteDay, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddArticleVoteDay 新增
|
||||
func (r *ArticleVoteDayDao) AddArticleVoteDay(tx *gorm.DB, model *model.ArticleVoteDay) (*model.ArticleVoteDay, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetArticleVoteDay 获取
|
||||
func (r *ArticleVoteDayDao) GetArticleVoteDay(maps interface{}) (m *model.ArticleVoteDay, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Inc 自增
|
||||
func (r *ArticleVoteDayDao) Inc(tx *gorm.DB, voteDayId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.ArticleVoteDay{}).Where("vote_day_id = ?", voteDayId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dec 自减
|
||||
func (r *ArticleVoteDayDao) Dec(tx *gorm.DB, voteDayId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.ArticleVoteDay{}).Where("vote_day_id = ?", voteDayId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetArticleVoteDayByUserIdPageSearch 获取列表-分页-用户id
|
||||
func (r *ArticleVoteDayDao) GetArticleVoteDayByUserIdPageSearch(userId int64, page, pageSize int) (m []*model.ArticleVoteDay, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.ArticleVoteDay{})
|
||||
|
||||
// 图文
|
||||
query = query.Preload("Article")
|
||||
|
||||
query = query.Where("user_id = ?", userId)
|
||||
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetArticleVoteDayByArticleIdPageSearch 获取列表-分页-文章id
|
||||
func (r *ArticleVoteDayDao) GetArticleVoteDayByArticleIdPageSearch(articleId int64, page, pageSize int) (m []*model.ArticleVoteDay, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.ArticleVoteDay{})
|
||||
|
||||
// 用户
|
||||
query = query.Preload("User")
|
||||
|
||||
query = query.Where("article_id = ?", articleId)
|
||||
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetArticleVoteDayListByTime 获取列表-开始时间/过期时间
|
||||
func (r *ArticleVoteDayDao) GetArticleVoteDayListByTime(maps interface{}, startTime, endTime, field string) (m []*model.ArticleVoteDay, err error) {
|
||||
err = global.Db.Where(maps).Where(field+" BETWEEN ? AND ?", startTime, endTime).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
148
api/dao/BaseAgreement.go
Normal file
148
api/dao/BaseAgreement.go
Normal file
@ -0,0 +1,148 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type BaseAgreementDao struct {
|
||||
}
|
||||
|
||||
// GetBaseAgreementById 获取数据-id
|
||||
func (r *BaseAgreementDao) GetBaseAgreementById(AgreementId int64) (m *model.BaseAgreement, err error) {
|
||||
err = global.Db.First(&m, AgreementId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetBaseAgreementPreloadById 获取数据-加载全部关联-id
|
||||
func (r *BaseAgreementDao) GetBaseAgreementPreloadById(AgreementId int64) (m *model.BaseAgreement, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, AgreementId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteBaseAgreement 删除
|
||||
func (r *BaseAgreementDao) DeleteBaseAgreement(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.BaseAgreement{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteBaseAgreementById 删除-id
|
||||
func (r *BaseAgreementDao) DeleteBaseAgreementById(tx *gorm.DB, voteDayId int64) error {
|
||||
if err := tx.Delete(&model.BaseAgreement{}, voteDayId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditBaseAgreement 修改
|
||||
func (r *BaseAgreementDao) EditBaseAgreement(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.BaseAgreement{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditBaseAgreementById 修改-id
|
||||
func (r *BaseAgreementDao) EditBaseAgreementById(tx *gorm.DB, AgreementId int64, data interface{}) error {
|
||||
err := tx.Model(&model.BaseAgreement{}).Where("agreement_id = ?", AgreementId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBaseAgreementList 获取列表
|
||||
func (r *BaseAgreementDao) GetBaseAgreementList(maps interface{}) (m []*model.BaseAgreement, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetBaseAgreementCount 获取数量
|
||||
func (r *BaseAgreementDao) GetBaseAgreementCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.BaseAgreement{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetBaseAgreementListRand 获取列表-随机
|
||||
func (r *BaseAgreementDao) GetBaseAgreementListRand(maps interface{}, limit int) (m []*model.BaseAgreement, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddBaseAgreement 新增
|
||||
func (r *BaseAgreementDao) AddBaseAgreement(tx *gorm.DB, model *model.BaseAgreement) (*model.BaseAgreement, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetBaseAgreement 获取
|
||||
func (r *BaseAgreementDao) GetBaseAgreement(maps interface{}) (m *model.BaseAgreement, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Inc 自增
|
||||
func (r *BaseAgreementDao) Inc(tx *gorm.DB, AgreementId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.BaseAgreement{}).Where("agreement_id = ?", AgreementId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dec 自减
|
||||
func (r *BaseAgreementDao) Dec(tx *gorm.DB, AgreementId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.BaseAgreement{}).Where("agreement_id = ?", AgreementId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBaseAgreementPageSearch 获取列表-分页
|
||||
func (r *BaseAgreementDao) GetBaseAgreementPageSearch(page, pageSize int) (m []*model.BaseAgreement, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.BaseAgreement{})
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
72
api/dao/BaseArea.go
Normal file
72
api/dao/BaseArea.go
Normal file
@ -0,0 +1,72 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type BaseAreaDao struct {
|
||||
}
|
||||
|
||||
// GetBaseAreaById 获取地区-地区id
|
||||
func (r *BaseAreaDao) GetBaseAreaById(BaseAreaId int) (m *model.BaseArea, err error) {
|
||||
err = global.Db.First(&m, BaseAreaId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteBaseArea 删除地区
|
||||
func (r *BaseAreaDao) DeleteBaseArea(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.BaseArea{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditBaseArea 修改地区
|
||||
func (r *BaseAreaDao) EditBaseArea(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.BaseArea{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditBaseAreaById 修改地区-医生id
|
||||
func (r *BaseAreaDao) EditBaseAreaById(tx *gorm.DB, BaseAreaId int, data interface{}) error {
|
||||
err := tx.Model(&model.BaseArea{}).Where("BaseArea_id = ?", BaseAreaId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBaseAreaList 获取地区列表
|
||||
func (r *BaseAreaDao) GetBaseAreaList(maps interface{}) (m []*model.BaseArea, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddBaseArea 新增地区
|
||||
func (r *BaseAreaDao) AddBaseArea(tx *gorm.DB, model *model.BaseArea) (*model.BaseArea, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// AddBaseAreaByMap 新增地区-map
|
||||
func (r *BaseAreaDao) AddBaseAreaByMap(tx *gorm.DB, data map[string]interface{}) (*model.BaseArea, error) {
|
||||
userDoctorInfo := &model.BaseArea{}
|
||||
if err := tx.Model(&model.BaseArea{}).Create(data).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userDoctorInfo, nil
|
||||
}
|
||||
145
api/dao/BaseHospital.go
Normal file
145
api/dao/BaseHospital.go
Normal file
@ -0,0 +1,145 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/api/requests"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type BaseHospitalDao struct {
|
||||
}
|
||||
|
||||
// GetBaseHospitalById 获取数据-id
|
||||
func (r *BaseHospitalDao) GetBaseHospitalById(HospitalId int64) (m *model.BaseHospital, err error) {
|
||||
err = global.Db.First(&m, HospitalId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetBaseHospitalPreloadById 获取数据-加载全部关联-id
|
||||
func (r *BaseHospitalDao) GetBaseHospitalPreloadById(HospitalId int64) (m *model.BaseHospital, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, HospitalId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteBaseHospital 删除
|
||||
func (r *BaseHospitalDao) DeleteBaseHospital(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.BaseHospital{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteBaseHospitalById 删除-id
|
||||
func (r *BaseHospitalDao) DeleteBaseHospitalById(tx *gorm.DB, HospitalId int64) error {
|
||||
if err := tx.Delete(&model.BaseHospital{}, HospitalId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditBaseHospital 修改
|
||||
func (r *BaseHospitalDao) EditBaseHospital(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.BaseHospital{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditBaseHospitalById 修改-id
|
||||
func (r *BaseHospitalDao) EditBaseHospitalById(tx *gorm.DB, HospitalId int64, data interface{}) error {
|
||||
err := tx.Model(&model.BaseHospital{}).Where("hospital_id = ?", HospitalId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBaseHospitalList 获取列表
|
||||
func (r *BaseHospitalDao) GetBaseHospitalList(maps interface{}) (m []*model.BaseHospital, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetBaseHospitalCount 获取数量
|
||||
func (r *BaseHospitalDao) GetBaseHospitalCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.BaseHospital{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetBaseHospitalListRand 获取列表-随机
|
||||
func (r *BaseHospitalDao) GetBaseHospitalListRand(maps interface{}, limit int) (m []*model.BaseHospital, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddBaseHospital 新增
|
||||
func (r *BaseHospitalDao) AddBaseHospital(tx *gorm.DB, model *model.BaseHospital) (*model.BaseHospital, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetBaseHospital 获取
|
||||
func (r *BaseHospitalDao) GetBaseHospital(maps interface{}) (m *model.BaseHospital, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Inc 自增
|
||||
func (r *BaseHospitalDao) Inc(tx *gorm.DB, HospitalId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.BaseHospital{}).Where("hospital_id = ?", HospitalId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dec 自减
|
||||
func (r *BaseHospitalDao) Dec(tx *gorm.DB, HospitalId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.BaseHospital{}).Where("hospital_id = ?", HospitalId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBaseHospitalLimitByMaps 获取医院列表-限制条数
|
||||
func (r *BaseHospitalDao) GetBaseHospitalLimitByMaps(hospitalRequest requests.GetBaseHospitalList) (m []*model.BaseHospital, err error) {
|
||||
result := global.Db
|
||||
if hospitalRequest.HospitalName != "" {
|
||||
result = result.Where("hospital_name like ?", "%"+hospitalRequest.HospitalName+"%")
|
||||
}
|
||||
|
||||
if hospitalRequest.HospitalLevelName != "" {
|
||||
result = result.Where("hospital_level_name like ?", "%"+hospitalRequest.HospitalLevelName+"%")
|
||||
}
|
||||
|
||||
err = result.Limit(10).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
135
api/dao/Data.go
Normal file
135
api/dao/Data.go
Normal file
@ -0,0 +1,135 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type DataDao struct {
|
||||
}
|
||||
|
||||
// GetDataById 获取数据-id
|
||||
func (r *DataDao) GetDataById(DataId int64) (m *model.Data, err error) {
|
||||
err = global.Db.First(&m, DataId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetDataPreloadById 获取数据-加载全部关联-id
|
||||
func (r *DataDao) GetDataPreloadById(DataId int64) (m *model.Data, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, DataId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteData 删除
|
||||
func (r *DataDao) DeleteData(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.Data{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteDataById 删除-id
|
||||
func (r *DataDao) DeleteDataById(tx *gorm.DB, DataId int64) error {
|
||||
if err := tx.Delete(&model.Data{}, DataId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditData 修改
|
||||
func (r *DataDao) EditData(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.Data{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditDataById 修改-id
|
||||
func (r *DataDao) EditDataById(tx *gorm.DB, DataId int64, data interface{}) error {
|
||||
err := tx.Model(&model.Data{}).Where("data_id = ?", DataId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDataList 获取列表
|
||||
func (r *DataDao) GetDataList(maps interface{}) (m []*model.Data, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetDataCount 获取数量
|
||||
func (r *DataDao) GetDataCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.Data{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetDataListRand 获取列表-随机
|
||||
func (r *DataDao) GetDataListRand(maps interface{}, limit int) (m []*model.Data, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddData 新增
|
||||
func (r *DataDao) AddData(tx *gorm.DB, model *model.Data) (*model.Data, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetData 获取
|
||||
func (r *DataDao) GetData(maps interface{}) (m *model.Data, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetDataListByMemberValidTime 获取列表-今天开始时间/过期时间
|
||||
func (r *DataDao) GetDataListByMemberValidTime(maps interface{}, startTime, endTime string) (m []*model.Data, err error) {
|
||||
err = global.Db.Where(maps).Where("member_expire_date BETWEEN ? AND ?", startTime, endTime).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Inc 自增
|
||||
func (r *DataDao) Inc(tx *gorm.DB, DataId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.Data{}).Where("data_id = ?", DataId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dec 自减
|
||||
func (r *DataDao) Dec(tx *gorm.DB, DataId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.Data{}).Where("data_id = ?", DataId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
117
api/dao/SystemTime.go
Normal file
117
api/dao/SystemTime.go
Normal file
@ -0,0 +1,117 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type SystemTimeDao struct {
|
||||
}
|
||||
|
||||
// GetSystemTimeById 获取数据-id
|
||||
func (r *SystemTimeDao) GetSystemTimeById(SystemTimeId int64) (m *model.SystemTime, err error) {
|
||||
err = global.Db.First(&m, SystemTimeId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetSystemTimePreloadById 获取数据-加载全部关联-id
|
||||
func (r *SystemTimeDao) GetSystemTimePreloadById(SystemTimeId int64) (m *model.SystemTime, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, SystemTimeId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteSystemTime 删除
|
||||
func (r *SystemTimeDao) DeleteSystemTime(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.SystemTime{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteSystemTimeById 删除-id
|
||||
func (r *SystemTimeDao) DeleteSystemTimeById(tx *gorm.DB, SystemTimeId int64) error {
|
||||
if err := tx.Delete(&model.SystemTime{}, SystemTimeId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditSystemTime 修改
|
||||
func (r *SystemTimeDao) EditSystemTime(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.SystemTime{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditSystemTimeById 修改-id
|
||||
func (r *SystemTimeDao) EditSystemTimeById(tx *gorm.DB, SystemTimeId int64, data interface{}) error {
|
||||
err := tx.Model(&model.SystemTime{}).Where("system_time_id = ?", SystemTimeId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSystemTimeList 获取列表
|
||||
func (r *SystemTimeDao) GetSystemTimeList(maps interface{}) (m []*model.SystemTime, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetSystemTimeCount 获取数量
|
||||
func (r *SystemTimeDao) GetSystemTimeCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.SystemTime{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetSystemTimeListRand 获取列表-随机
|
||||
func (r *SystemTimeDao) GetSystemTimeListRand(maps interface{}, limit int) (m []*model.SystemTime, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddSystemTime 新增
|
||||
func (r *SystemTimeDao) AddSystemTime(tx *gorm.DB, model *model.SystemTime) (*model.SystemTime, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// Inc 自增
|
||||
func (r *SystemTimeDao) Inc(tx *gorm.DB, SystemTimeId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.SystemTime{}).Where("SystemTime_id = ?", SystemTimeId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dec 自减
|
||||
func (r *SystemTimeDao) Dec(tx *gorm.DB, SystemTimeId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.SystemTime{}).Where("SystemTime_id = ?", SystemTimeId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
177
api/dao/User.go
Normal file
177
api/dao/User.go
Normal file
@ -0,0 +1,177 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/api/requests"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type UserDao struct {
|
||||
}
|
||||
|
||||
// GetUserById 获取数据-id
|
||||
func (r *UserDao) GetUserById(UserId int64) (m *model.User, err error) {
|
||||
err = global.Db.First(&m, UserId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetUserPreloadById 获取数据-加载全部关联-id
|
||||
func (r *UserDao) GetUserPreloadById(UserId int64) (m *model.User, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, UserId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteUser 删除
|
||||
func (r *UserDao) DeleteUser(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.User{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteUserById 删除-id
|
||||
func (r *UserDao) DeleteUserById(tx *gorm.DB, UserId int64) error {
|
||||
if err := tx.Delete(&model.User{}, UserId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditUser 修改
|
||||
func (r *UserDao) EditUser(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.User{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditUserById 修改-id
|
||||
func (r *UserDao) EditUserById(tx *gorm.DB, UserId int64, data interface{}) error {
|
||||
err := tx.Model(&model.User{}).Where("User_id = ?", UserId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUserList 获取列表
|
||||
func (r *UserDao) GetUserList(maps interface{}) (m []*model.User, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetUserCount 获取数量
|
||||
func (r *UserDao) GetUserCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.User{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetUserListRand 获取列表-随机
|
||||
func (r *UserDao) GetUserListRand(maps interface{}, limit int) (m []*model.User, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddUser 新增
|
||||
func (r *UserDao) AddUser(tx *gorm.DB, model *model.User) (*model.User, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetUser 获取
|
||||
func (r *UserDao) GetUser(maps interface{}) (m *model.User, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Inc 自增
|
||||
func (r *UserDao) Inc(tx *gorm.DB, UserId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.User{}).Where("User_id = ?", UserId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dec 自减
|
||||
func (r *UserDao) Dec(tx *gorm.DB, UserId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.User{}).Where("User_id = ?", UserId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUserPageSearch 获取列表-分页
|
||||
func (r *UserDao) GetUserPageSearch(req requests.GetUserPage, page, pageSize int) (m []*model.User, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.User{})
|
||||
|
||||
// 用户id
|
||||
if req.UserId != "" {
|
||||
query = query.Where("user_id = ?", req.UserId)
|
||||
}
|
||||
|
||||
// app唯一标识
|
||||
if req.AppIden != "" {
|
||||
query = query.Where("app_iden = ?", req.AppIden)
|
||||
}
|
||||
|
||||
// 状态
|
||||
if req.UserStatus != 0 {
|
||||
query = query.Where("user_status = ?", req.UserStatus)
|
||||
}
|
||||
|
||||
// 用户微信标识
|
||||
if req.OpenId != "" {
|
||||
query = query.Where("open_id LIKE ?", "%"+req.OpenId+"%")
|
||||
}
|
||||
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetUserListByTime 获取列表-今天开始时间/过期时间
|
||||
func (r *UserDao) GetUserListByTime(maps interface{}, startTime, endTime, field string) (m []*model.User, err error) {
|
||||
err = global.Db.Where(maps).Where(field+" BETWEEN ? AND ?", startTime, endTime).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
233
api/dao/Video.go
Normal file
233
api/dao/Video.go
Normal file
@ -0,0 +1,233 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/api/requests"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type VideoDao struct {
|
||||
}
|
||||
|
||||
// GetVideoById 获取数据-id
|
||||
func (r *VideoDao) GetVideoById(VideoId int64) (m *model.Video, err error) {
|
||||
err = global.Db.First(&m, VideoId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoPreloadById 获取数据-加载全部关联-id
|
||||
func (r *VideoDao) GetVideoPreloadById(VideoId int64) (m *model.Video, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, VideoId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteVideo 删除
|
||||
func (r *VideoDao) DeleteVideo(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.Video{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteVideoById 删除-id
|
||||
func (r *VideoDao) DeleteVideoById(tx *gorm.DB, VideoId int64) error {
|
||||
if err := tx.Delete(&model.Video{}, VideoId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditVideo 修改
|
||||
func (r *VideoDao) EditVideo(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.Video{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditVideoById 修改-id
|
||||
func (r *VideoDao) EditVideoById(tx *gorm.DB, VideoId int64, data interface{}) error {
|
||||
err := tx.Model(&model.Video{}).Where("video_id = ?", VideoId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetVideoList 获取列表
|
||||
func (r *VideoDao) GetVideoList(maps interface{}) (m []*model.Video, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoCount 获取数量
|
||||
func (r *VideoDao) GetVideoCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.Video{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetVideoListRand 获取列表-随机
|
||||
func (r *VideoDao) GetVideoListRand(maps interface{}, limit int) (m []*model.Video, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddVideo 新增
|
||||
func (r *VideoDao) AddVideo(tx *gorm.DB, model *model.Video) (*model.Video, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetVideo 获取
|
||||
func (r *VideoDao) GetVideo(maps interface{}) (m *model.Video, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Inc 自增
|
||||
func (r *VideoDao) Inc(tx *gorm.DB, VideoId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.Video{}).Where("video_id = ?", VideoId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dec 自减
|
||||
func (r *VideoDao) Dec(tx *gorm.DB, VideoId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.Video{}).Where("video_id = ?", VideoId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetVideoPageSearch 获取列表-分页
|
||||
func (r *VideoDao) GetVideoPageSearch(req requests.GetVideoPage, page, pageSize int) (m []*model.Video, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.Video{})
|
||||
|
||||
// 作者
|
||||
query = query.Preload("VideoAuthor")
|
||||
|
||||
// 作者关联医院
|
||||
query = query.Preload("VideoAuthor.BaseHospital")
|
||||
|
||||
// 视频编号
|
||||
if req.VideoNo != "" {
|
||||
query = query.Where("video_no LIKE ?", "%"+req.VideoNo+"%")
|
||||
}
|
||||
|
||||
// 搜索关键字
|
||||
if req.Keyword != "" {
|
||||
keyword := "%" + req.Keyword + "%" //
|
||||
|
||||
// 标题
|
||||
orQuery := global.Db.Model(&model.Video{}).Or("video_title LIKE ?", keyword)
|
||||
|
||||
// 医院名称
|
||||
hospitalSubQuery := global.Db.Model(&model.BaseHospital{}).
|
||||
Select("hospital_id").
|
||||
Where("hospital_name LIKE ?", keyword)
|
||||
|
||||
articleAuthorSubQuery := global.Db.Model(&model.VideoAuthor{}).
|
||||
Select("video_id").
|
||||
Where(gorm.Expr("hospital_id IN (?)", hospitalSubQuery))
|
||||
|
||||
orQuery = orQuery.Or(gorm.Expr("video_id IN (?)", articleAuthorSubQuery))
|
||||
|
||||
// 作者姓名
|
||||
subQuery := global.Db.Model(&model.VideoAuthor{}).
|
||||
Select("video_id").
|
||||
Where("author_name LIKE ?", keyword)
|
||||
|
||||
orQuery = orQuery.Or(gorm.Expr("video_id IN (?)", subQuery))
|
||||
|
||||
// 执行组建
|
||||
query = query.Where(orQuery)
|
||||
}
|
||||
|
||||
// 文章状态
|
||||
if req.VideoStatus != nil {
|
||||
query = query.Where("video_status = ?", req.VideoStatus)
|
||||
}
|
||||
|
||||
// 排序
|
||||
if req.Order != nil {
|
||||
if req.Order.VoteNum != "" {
|
||||
query = query.Order("vote_num " + req.Order.VoteNum)
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetVideoOrderList 获取列表-排序
|
||||
func (r *VideoDao) GetVideoOrderList(maps interface{}, orderField string, limit int) (m []*model.Video, err error) {
|
||||
err = global.Db.Where(maps).Preload(clause.Associations).Order(orderField).Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoRank 获取某一条数据的排名
|
||||
func (r *VideoDao) GetVideoRank(videoID int64) (int, error) {
|
||||
var rank int
|
||||
|
||||
// 定义子查询
|
||||
subQuery := global.Db.Model(&model.Video{}).
|
||||
Select("video_id, vote_num, (@rank := @rank + 1) AS rank").
|
||||
Where("video_status = ?", 1).
|
||||
Order("vote_num DESC").
|
||||
Joins(", (SELECT @rank := 0) AS r")
|
||||
|
||||
// 将子查询作为命名子查询的一部分进行查询
|
||||
err := global.Db.Table("(?) AS sub", subQuery).
|
||||
Where("sub.video_id = ?", videoID).
|
||||
Pluck("sub.rank", &rank).Error
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return rank, nil
|
||||
}
|
||||
135
api/dao/VideoAuthor.go
Normal file
135
api/dao/VideoAuthor.go
Normal file
@ -0,0 +1,135 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type VideoAuthorDao struct {
|
||||
}
|
||||
|
||||
// GetVideoAuthorById 获取数据-id
|
||||
func (r *VideoAuthorDao) GetVideoAuthorById(authorId int64) (m *model.VideoAuthor, err error) {
|
||||
err = global.Db.First(&m, authorId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoAuthorPreloadById 获取数据-加载全部关联-id
|
||||
func (r *VideoAuthorDao) GetVideoAuthorPreloadById(authorId int64) (m *model.VideoAuthor, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, authorId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteVideoAuthor 删除
|
||||
func (r *VideoAuthorDao) DeleteVideoAuthor(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.VideoAuthor{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteVideoAuthorById 删除-id
|
||||
func (r *VideoAuthorDao) DeleteVideoAuthorById(tx *gorm.DB, authorId int64) error {
|
||||
if err := tx.Delete(&model.VideoAuthor{}, authorId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditVideoAuthor 修改
|
||||
func (r *VideoAuthorDao) EditVideoAuthor(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.VideoAuthor{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditVideoAuthorById 修改-id
|
||||
func (r *VideoAuthorDao) EditVideoAuthorById(tx *gorm.DB, authorId int64, data interface{}) error {
|
||||
err := tx.Model(&model.VideoAuthor{}).Where("authorId = ?", authorId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetVideoAuthorList 获取列表
|
||||
func (r *VideoAuthorDao) GetVideoAuthorList(maps interface{}) (m []*model.VideoAuthor, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoAuthorPreloadList 获取列表-加载全部关联
|
||||
func (r *VideoAuthorDao) GetVideoAuthorPreloadList(maps interface{}) (m []*model.VideoAuthor, err error) {
|
||||
err = global.Db.Preload(clause.Associations).Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoAuthorCount 获取数量
|
||||
func (r *VideoAuthorDao) GetVideoAuthorCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.VideoAuthor{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetVideoAuthorListRand 获取列表-随机
|
||||
func (r *VideoAuthorDao) GetVideoAuthorListRand(maps interface{}, limit int) (m []*model.VideoAuthor, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddVideoAuthor 新增
|
||||
func (r *VideoAuthorDao) AddVideoAuthor(tx *gorm.DB, model *model.VideoAuthor) (*model.VideoAuthor, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetVideoAuthor 获取
|
||||
func (r *VideoAuthorDao) GetVideoAuthor(maps interface{}) (m *model.VideoAuthor, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Inc 自增
|
||||
func (r *VideoAuthorDao) Inc(tx *gorm.DB, authorId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.VideoAuthor{}).Where("authorId = ?", authorId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dec 自减
|
||||
func (r *VideoAuthorDao) Dec(tx *gorm.DB, authorId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.VideoAuthor{}).Where("authorId = ?", authorId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
186
api/dao/VideoVoteDay.go
Normal file
186
api/dao/VideoVoteDay.go
Normal file
@ -0,0 +1,186 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type VideoVoteDayDao struct {
|
||||
}
|
||||
|
||||
// GetVideoVoteDayById 获取数据-id
|
||||
func (r *VideoVoteDayDao) GetVideoVoteDayById(voteDayId int64) (m *model.VideoVoteDay, err error) {
|
||||
err = global.Db.First(&m, voteDayId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoVoteDayPreloadById 获取数据-加载全部关联-id
|
||||
func (r *VideoVoteDayDao) GetVideoVoteDayPreloadById(voteDayId int64) (m *model.VideoVoteDay, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, voteDayId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteVideoVoteDay 删除
|
||||
func (r *VideoVoteDayDao) DeleteVideoVoteDay(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.VideoVoteDay{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteVideoVoteDayById 删除-id
|
||||
func (r *VideoVoteDayDao) DeleteVideoVoteDayById(tx *gorm.DB, authorId int64) error {
|
||||
if err := tx.Delete(&model.VideoVoteDay{}, authorId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditVideoVoteDay 修改
|
||||
func (r *VideoVoteDayDao) EditVideoVoteDay(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.VideoVoteDay{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditVideoVoteDayById 修改-id
|
||||
func (r *VideoVoteDayDao) EditVideoVoteDayById(tx *gorm.DB, voteDayId int64, data interface{}) error {
|
||||
err := tx.Model(&model.VideoVoteDay{}).Where("vote_day_id = ?", voteDayId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetVideoVoteDayList 获取列表
|
||||
func (r *VideoVoteDayDao) GetVideoVoteDayList(maps interface{}) (m []*model.VideoVoteDay, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoVoteDayCount 获取数量
|
||||
func (r *VideoVoteDayDao) GetVideoVoteDayCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.VideoVoteDay{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetVideoVoteDayListRand 获取列表-随机
|
||||
func (r *VideoVoteDayDao) GetVideoVoteDayListRand(maps interface{}, limit int) (m []*model.VideoVoteDay, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddVideoVoteDay 新增
|
||||
func (r *VideoVoteDayDao) AddVideoVoteDay(tx *gorm.DB, model *model.VideoVoteDay) (*model.VideoVoteDay, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetVideoVoteDay 获取
|
||||
func (r *VideoVoteDayDao) GetVideoVoteDay(maps interface{}) (m *model.VideoVoteDay, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Inc 自增
|
||||
func (r *VideoVoteDayDao) Inc(tx *gorm.DB, voteDayId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.VideoVoteDay{}).Where("vote_day_id = ?", voteDayId).UpdateColumn(field, gorm.Expr(field+" + ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dec 自减
|
||||
func (r *VideoVoteDayDao) Dec(tx *gorm.DB, voteDayId int64, field string, numeral int) error {
|
||||
err := tx.Model(&model.VideoVoteDay{}).Where("vote_day_id = ?", voteDayId).UpdateColumn(field, gorm.Expr(field+" - ?", numeral)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetVideoVoteDayByUserIdPageSearch 获取列表-分页-用户id
|
||||
func (r *VideoVoteDayDao) GetVideoVoteDayByUserIdPageSearch(userId int64, page, pageSize int) (m []*model.VideoVoteDay, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.VideoVoteDay{})
|
||||
|
||||
query = query.Preload("video")
|
||||
|
||||
query = query.Where("user_id = ?", userId)
|
||||
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetVideoVoteDayByVideoIdPageSearch 获取列表-分页-视频id
|
||||
func (r *VideoVoteDayDao) GetVideoVoteDayByVideoIdPageSearch(videoId int64, page, pageSize int) (m []*model.VideoVoteDay, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.VideoVoteDay{})
|
||||
|
||||
// 用户
|
||||
query = query.Preload("User")
|
||||
|
||||
query = query.Where("video_id = ?", videoId)
|
||||
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetVideoVoteDayListByTime 获取列表-开始时间/过期时间
|
||||
func (r *VideoVoteDayDao) GetVideoVoteDayListByTime(maps interface{}, startTime, endTime, field string) (m []*model.VideoVoteDay, err error) {
|
||||
err = global.Db.Where(maps).Where(field+" BETWEEN ? AND ?", startTime, endTime).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
81
api/dto/Article.go
Normal file
81
api/dto/Article.go
Normal file
@ -0,0 +1,81 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-video-api/api/model"
|
||||
)
|
||||
|
||||
// ArticleDto 文章表
|
||||
type ArticleDto struct {
|
||||
ArticleId string `json:"article_id"` // 主键id
|
||||
ArticleTitle string `json:"article_title"` // 文章标题
|
||||
ArticleStatus int `json:"article_status"` // 文章状态(1:正常 2:禁用)
|
||||
ArticleNumber string `json:"article_number"` // 文章编号
|
||||
VoteNum uint `json:"vote_num"` // 总票数
|
||||
ArticleContent string `json:"article_content"` // 文章内容
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
ArticleAuthor []*ArticleAuthorDto `json:"article_author"` // 作者
|
||||
Rank *int `json:"rank"` // 排名
|
||||
}
|
||||
|
||||
// GetArticleListDto 列表-分页
|
||||
func GetArticleListDto(m []*model.Article) []*ArticleDto {
|
||||
// 处理返回值
|
||||
responses := make([]*ArticleDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &ArticleDto{
|
||||
ArticleId: fmt.Sprintf("%d", v.ArticleId),
|
||||
ArticleTitle: v.ArticleTitle,
|
||||
ArticleStatus: v.ArticleStatus,
|
||||
ArticleNumber: v.ArticleNumber,
|
||||
VoteNum: v.VoteNum,
|
||||
ArticleContent: v.ArticleContent,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 加载数据-作者
|
||||
if v.ArticleAuthor != nil {
|
||||
response = response.LoadArticleAuthor(v.ArticleAuthor)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// GetArticleDto 详情
|
||||
func GetArticleDto(m *model.Article) *ArticleDto {
|
||||
return &ArticleDto{
|
||||
ArticleId: fmt.Sprintf("%d", m.ArticleId),
|
||||
ArticleTitle: m.ArticleTitle,
|
||||
ArticleStatus: m.ArticleStatus,
|
||||
ArticleNumber: m.ArticleNumber,
|
||||
VoteNum: m.VoteNum,
|
||||
ArticleContent: m.ArticleContent,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// LoadArticleAuthor 加载数据-作者
|
||||
func (r *ArticleDto) LoadArticleAuthor(m []*model.ArticleAuthor) *ArticleDto {
|
||||
if len(m) > 0 {
|
||||
r.ArticleAuthor = GetArticleAuthorListDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadRank 加载数据-排名
|
||||
func (r *ArticleDto) LoadRank(m int) *ArticleDto {
|
||||
if m > 0 {
|
||||
r.Rank = &m
|
||||
}
|
||||
return r
|
||||
}
|
||||
49
api/dto/ArticleAuthor.go
Normal file
49
api/dto/ArticleAuthor.go
Normal file
@ -0,0 +1,49 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-video-api/api/model"
|
||||
)
|
||||
|
||||
type ArticleAuthorDto struct {
|
||||
AuthorId string `json:"author_id"` // 主键id
|
||||
ArticleId string `json:"article_id"` // 文章id
|
||||
AuthorName string `json:"author_name"` // 作者姓名
|
||||
HospitalId string `json:"hospital_id"` // 作者所属id
|
||||
HospitalName string `json:"hospital_name"` // 作者所属医院
|
||||
}
|
||||
|
||||
// GetArticleAuthorListDto 列表-分页
|
||||
func GetArticleAuthorListDto(m []*model.ArticleAuthor) []*ArticleAuthorDto {
|
||||
// 处理返回值
|
||||
responses := make([]*ArticleAuthorDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &ArticleAuthorDto{
|
||||
AuthorId: fmt.Sprintf("%d", v.AuthorId),
|
||||
ArticleId: fmt.Sprintf("%d", v.ArticleId),
|
||||
AuthorName: v.AuthorName,
|
||||
HospitalId: fmt.Sprintf("%d", v.HospitalId),
|
||||
}
|
||||
|
||||
// 加载数据-医院属性
|
||||
if v.BaseHospital != nil {
|
||||
response = response.LoadBaseHospital(v.BaseHospital)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadBaseHospital 加载数据-医院
|
||||
func (r *ArticleAuthorDto) LoadBaseHospital(m *model.BaseHospital) *ArticleAuthorDto {
|
||||
if m != nil {
|
||||
r.HospitalName = m.HospitalName
|
||||
}
|
||||
return r
|
||||
}
|
||||
52
api/dto/BaseAgreement.go
Normal file
52
api/dto/BaseAgreement.go
Normal file
@ -0,0 +1,52 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-video-api/api/model"
|
||||
)
|
||||
|
||||
// BaseAgreementDto 基础-协议
|
||||
type BaseAgreementDto struct {
|
||||
AgreementId string `json:"agreement_id"` // 主键id
|
||||
AgreementTitle string `json:"agreement_title"` // 协议名称
|
||||
AgreementType int `json:"agreement_type"` // 协议类型(1:大赛介绍 2:投票规则)
|
||||
AgreementContent string `json:"agreement_content"` // 协议内容
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
}
|
||||
|
||||
// GetBaseAgreementDto 详情
|
||||
func GetBaseAgreementDto(m *model.BaseAgreement) *BaseAgreementDto {
|
||||
return &BaseAgreementDto{
|
||||
AgreementId: fmt.Sprintf("%d", m.AgreementId),
|
||||
AgreementTitle: m.AgreementTitle,
|
||||
AgreementType: m.AgreementType,
|
||||
AgreementContent: m.AgreementContent,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// GetBaseAgreementListDto 列表-基础数据-协议
|
||||
func GetBaseAgreementListDto(m []*model.BaseAgreement) []*BaseAgreementDto {
|
||||
// 处理返回值
|
||||
responses := make([]*BaseAgreementDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &BaseAgreementDto{
|
||||
AgreementId: fmt.Sprintf("%d", v.AgreementId),
|
||||
AgreementTitle: v.AgreementTitle,
|
||||
AgreementType: v.AgreementType,
|
||||
AgreementContent: v.AgreementContent,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
85
api/dto/BaseHospital.go
Normal file
85
api/dto/BaseHospital.go
Normal file
@ -0,0 +1,85 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-video-api/api/model"
|
||||
)
|
||||
|
||||
type BaseHospitalDto struct {
|
||||
HospitalID string `json:"hospital_id"` // 主键id
|
||||
HospitalName string `json:"hospital_name"` // 医院名称
|
||||
HospitalStatus int `json:"hospital_status"` // 状态(0:禁用 1:正常 2:删除)
|
||||
HospitalLevelName string `json:"hospital_level_name"` // 医院等级名称
|
||||
PostCode string `json:"post_code"` // 邮政编码
|
||||
Telephone string `json:"telephone"` // 电话
|
||||
ProvinceID int `json:"province_id"` // 省份id
|
||||
Province string `json:"province"` // 省份
|
||||
CityID int `json:"city_id"` // 城市id
|
||||
City string `json:"city"` // 城市
|
||||
CountyID int `json:"county_id"` // 区县id
|
||||
County string `json:"county"` // 区县
|
||||
Address string `json:"address"` // 地址
|
||||
Latitude string `json:"latitude"` // 纬度
|
||||
Longitude string `json:"longitude"` // 经度
|
||||
Description string `json:"description"` // 简介
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
}
|
||||
|
||||
func GetBaseHospitalDto(m *model.BaseHospital) *BaseHospitalDto {
|
||||
return &BaseHospitalDto{
|
||||
HospitalID: fmt.Sprintf("%d", m.HospitalId),
|
||||
HospitalName: m.HospitalName,
|
||||
HospitalStatus: m.HospitalStatus,
|
||||
HospitalLevelName: m.HospitalLevelName,
|
||||
PostCode: m.PostCode,
|
||||
Telephone: m.HospitalName,
|
||||
ProvinceID: m.ProvinceId,
|
||||
Province: m.Province,
|
||||
CityID: m.CityId,
|
||||
City: m.City,
|
||||
CountyID: m.CountyId,
|
||||
County: m.County,
|
||||
Address: m.Address,
|
||||
Latitude: m.Lat,
|
||||
Longitude: m.HospitalName,
|
||||
Description: m.Desc,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func GetBaseHospitalListDto(m []*model.BaseHospital) []BaseHospitalDto {
|
||||
// 处理返回值
|
||||
responses := make([]BaseHospitalDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := BaseHospitalDto{
|
||||
HospitalID: fmt.Sprintf("%d", v.HospitalId),
|
||||
HospitalName: v.HospitalName,
|
||||
HospitalStatus: v.HospitalStatus,
|
||||
HospitalLevelName: v.HospitalLevelName,
|
||||
PostCode: v.PostCode,
|
||||
Telephone: v.HospitalName,
|
||||
ProvinceID: v.ProvinceId,
|
||||
Province: v.Province,
|
||||
CityID: v.CityId,
|
||||
City: v.City,
|
||||
CountyID: v.CountyId,
|
||||
County: v.County,
|
||||
Address: v.Address,
|
||||
Latitude: v.Lat,
|
||||
Longitude: v.HospitalName,
|
||||
Description: v.Desc,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
18
api/dto/Data.go
Normal file
18
api/dto/Data.go
Normal file
@ -0,0 +1,18 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"vote-admin-video-api/api/model"
|
||||
)
|
||||
|
||||
type DataDto struct {
|
||||
ViewNum uint `json:"view_num"` // 浏览数量
|
||||
VoteNum uint `json:"vote_num"` // 投票数量
|
||||
}
|
||||
|
||||
// GetDataDto 详情
|
||||
func GetDataDto(m *model.Data) *DataDto {
|
||||
return &DataDto{
|
||||
ViewNum: m.ViewNum,
|
||||
VoteNum: m.VoteNum,
|
||||
}
|
||||
}
|
||||
42
api/dto/Public.go
Normal file
42
api/dto/Public.go
Normal file
@ -0,0 +1,42 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-video-api/api/model"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
// LoginDto 登陆
|
||||
type LoginDto struct {
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
NickName string `json:"nick_name"` // 用户名称
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
Token string `json:"token"` // token
|
||||
}
|
||||
|
||||
// IndexDto 首页
|
||||
type IndexDto struct {
|
||||
ViewNum uint `json:"view_num"` // 浏览数量
|
||||
VoteNum uint `json:"vote_num"` // 投票数量
|
||||
}
|
||||
|
||||
// IndexDataDto 首页动态统计数据
|
||||
type IndexDataDto struct {
|
||||
Date string `json:"date"` // 日期
|
||||
Count int64 `json:"count"` // 数量
|
||||
}
|
||||
|
||||
// AdminLoginDto 微信登陆
|
||||
func AdminLoginDto(m *model.AdminUser) *LoginDto {
|
||||
return &LoginDto{
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
NickName: m.NickName,
|
||||
Avatar: utils.AddOssDomain(m.Avatar),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadToken 加载token
|
||||
func (r *LoginDto) LoadToken(token string) *LoginDto {
|
||||
r.Token = token
|
||||
return r
|
||||
}
|
||||
26
api/dto/SystemTime.go
Normal file
26
api/dto/SystemTime.go
Normal file
@ -0,0 +1,26 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-video-api/api/model"
|
||||
)
|
||||
|
||||
// SystemTimeDto 配置-时间
|
||||
type SystemTimeDto struct {
|
||||
SystemTimeId string `json:"system_time_id"` // 主键id
|
||||
StartTime *model.LocalTime `json:"start_time"` // 开始投票时间
|
||||
EndTime *model.LocalTime `json:"end_time"` // 结束投票时间
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
}
|
||||
|
||||
// GetSystemTimeDto 详情
|
||||
func GetSystemTimeDto(m *model.SystemTime) *SystemTimeDto {
|
||||
return &SystemTimeDto{
|
||||
SystemTimeId: fmt.Sprintf("%d", m.SystemTimeId),
|
||||
StartTime: m.StartTime,
|
||||
EndTime: m.EndTime,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
67
api/dto/User.go
Normal file
67
api/dto/User.go
Normal file
@ -0,0 +1,67 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-video-api/api/model"
|
||||
)
|
||||
|
||||
// UserDto 用户表
|
||||
type UserDto struct {
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
UserStatus int `json:"user_status"` // 状态(1:正常 2:禁用)
|
||||
OpenId string `json:"open_id"` // 用户微信标识
|
||||
AppIden string `json:"app_iden"` // app唯一标识
|
||||
LoginAt *model.LocalTime `json:"login_at"` // 登陆时间
|
||||
LoginIp string `json:"login_ip"` // 登陆ip
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
}
|
||||
|
||||
// UserVoteDto 用户投票记录
|
||||
type UserVoteDto struct {
|
||||
Id string `json:"id"` // 图文/视频标识
|
||||
AppIden string `json:"app_iden"` // app唯一标识
|
||||
OpenId string `json:"open_id"` // open_id
|
||||
Title string `json:"title"` // 标题
|
||||
VotedAt string `json:"voted_at"` // 投票时间
|
||||
}
|
||||
|
||||
// GetUserListDto 列表
|
||||
func GetUserListDto(m []*model.User) []*UserDto {
|
||||
// 处理返回值
|
||||
responses := make([]*UserDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &UserDto{
|
||||
UserId: fmt.Sprintf("%d", v.UserId),
|
||||
UserStatus: v.UserStatus,
|
||||
OpenId: v.OpenId,
|
||||
AppIden: v.AppIden,
|
||||
LoginAt: v.LoginAt,
|
||||
LoginIp: v.LoginIp,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// GetUserDto 详情-问题
|
||||
func GetUserDto(m *model.User) *UserDto {
|
||||
return &UserDto{
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
UserStatus: m.UserStatus,
|
||||
OpenId: m.OpenId,
|
||||
AppIden: m.AppIden,
|
||||
LoginAt: m.LoginAt,
|
||||
LoginIp: m.LoginIp,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
84
api/dto/Video.go
Normal file
84
api/dto/Video.go
Normal file
@ -0,0 +1,84 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-video-api/api/model"
|
||||
)
|
||||
|
||||
// VideoDto 视频表
|
||||
type VideoDto struct {
|
||||
VideoId string `json:"video_id"` // 主键id
|
||||
VideoTitle string `json:"video_title"` // 视频标题
|
||||
VideoStatus int `json:"video_status"` // 视频状态(1:正常 2:禁用)
|
||||
VideoNumber string `json:"video_number"` // 视频编号
|
||||
VideoNo string `json:"video_no"` // 视频编号
|
||||
VoteNum uint `json:"vote_num"` // 总票数
|
||||
VideoContent string `json:"video_content"` // 视频内容
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
VideoAuthor []*VideoAuthorDto `json:"video_author"` // 作者
|
||||
Rank *int `json:"rank"` // 排名
|
||||
}
|
||||
|
||||
// GetVideoListDto 列表-分页
|
||||
func GetVideoListDto(m []*model.Video) []*VideoDto {
|
||||
// 处理返回值
|
||||
responses := make([]*VideoDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &VideoDto{
|
||||
VideoId: fmt.Sprintf("%d", v.VideoId),
|
||||
VideoTitle: v.VideoTitle,
|
||||
VideoStatus: v.VideoStatus,
|
||||
VideoNumber: v.VideoNumber,
|
||||
VideoNo: v.VideoNo,
|
||||
VoteNum: v.VoteNum,
|
||||
VideoContent: v.VideoContent,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 加载数据-作者
|
||||
if v.VideoAuthor != nil {
|
||||
response = response.LoadVideoAuthor(v.VideoAuthor)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// GetVideoDto 详情
|
||||
func GetVideoDto(m *model.Video) *VideoDto {
|
||||
return &VideoDto{
|
||||
VideoId: fmt.Sprintf("%d", m.VideoId),
|
||||
VideoTitle: m.VideoTitle,
|
||||
VideoStatus: m.VideoStatus,
|
||||
VideoNumber: m.VideoNumber,
|
||||
VideoNo: m.VideoNo,
|
||||
VoteNum: m.VoteNum,
|
||||
VideoContent: m.VideoContent,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// LoadVideoAuthor 加载数据-作者
|
||||
func (r *VideoDto) LoadVideoAuthor(m []*model.VideoAuthor) *VideoDto {
|
||||
if len(m) > 0 {
|
||||
r.VideoAuthor = GetVideoAuthorListDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadRank 加载数据-排名
|
||||
func (r *VideoDto) LoadRank(m int) *VideoDto {
|
||||
if m > 0 {
|
||||
r.Rank = &m
|
||||
}
|
||||
return r
|
||||
}
|
||||
49
api/dto/VideoAuthor.go
Normal file
49
api/dto/VideoAuthor.go
Normal file
@ -0,0 +1,49 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-video-api/api/model"
|
||||
)
|
||||
|
||||
type VideoAuthorDto struct {
|
||||
AuthorId string `json:"author_id"` // 主键id
|
||||
VideoId string `json:"video_id"` // 文章id
|
||||
HospitalId string `json:"hospital_id"` // 作者所属id
|
||||
HospitalName string `json:"hospital_name"` // 作者所属医院
|
||||
AuthorName string `json:"author_name"` // 作者姓名
|
||||
}
|
||||
|
||||
// GetVideoAuthorListDto 列表-分页
|
||||
func GetVideoAuthorListDto(m []*model.VideoAuthor) []*VideoAuthorDto {
|
||||
// 处理返回值
|
||||
responses := make([]*VideoAuthorDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &VideoAuthorDto{
|
||||
AuthorId: fmt.Sprintf("%d", v.AuthorId),
|
||||
VideoId: fmt.Sprintf("%d", v.VideoId),
|
||||
AuthorName: v.AuthorName,
|
||||
HospitalId: fmt.Sprintf("%d", v.HospitalId),
|
||||
}
|
||||
|
||||
// 加载数据-医院属性
|
||||
if v.BaseHospital != nil {
|
||||
response = response.LoadBaseHospitalAttr(v.BaseHospital)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadBaseHospitalAttr 加载数据-医院属性
|
||||
func (r *VideoAuthorDto) LoadBaseHospitalAttr(m *model.BaseHospital) *VideoAuthorDto {
|
||||
if m != nil {
|
||||
r.HospitalName = m.HospitalName
|
||||
}
|
||||
return r
|
||||
}
|
||||
43
api/exception/exception.go
Normal file
43
api/exception/exception.go
Normal file
@ -0,0 +1,43 @@
|
||||
package exception
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
"vote-admin-video-api/consts"
|
||||
)
|
||||
|
||||
// Recover
|
||||
// @Description: 处理全局异常
|
||||
// @return gin.HandlerFunc
|
||||
func Recover() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
// 打印错误堆栈信息
|
||||
log.Printf("panic: %v\n", r)
|
||||
debug.PrintStack()
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"code": consts.ServerError,
|
||||
"message": errorToString(r),
|
||||
"data": "",
|
||||
})
|
||||
// 终止后续接口调用,不加的话recover到异常后,还会继续执行接口里后续代码
|
||||
c.Abort()
|
||||
}
|
||||
}()
|
||||
// 加载完 defer recover,继续后续接口调用
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// recover错误,转string
|
||||
func errorToString(r interface{}) string {
|
||||
switch v := r.(type) {
|
||||
case error:
|
||||
return v.Error()
|
||||
default:
|
||||
return r.(string)
|
||||
}
|
||||
}
|
||||
79
api/middlewares/auth.go
Normal file
79
api/middlewares/auth.go
Normal file
@ -0,0 +1,79 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"vote-admin-video-api/api/dao"
|
||||
"vote-admin-video-api/api/responses"
|
||||
"vote-admin-video-api/consts"
|
||||
)
|
||||
|
||||
// Auth Auth认证
|
||||
func Auth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// 获取用户id
|
||||
adminUserId := c.GetInt64("AdminUserId")
|
||||
if adminUserId == 0 {
|
||||
responses.Fail(c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
adminUserDao := dao.AdminUserDao{}
|
||||
adminUser, err := adminUserDao.GetAdminUserById(adminUserId)
|
||||
if err != nil || adminUser == nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户数据错误",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.Status == 2 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户审核中",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.Status == 3 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户状态异常",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.IsDisabled == 1 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户已被禁用",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
if adminUser.IsDeleted == 1 {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "用户状态异常",
|
||||
"code": consts.UserStatusError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("AdminUserId", adminUserId) // 用户id
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
29
api/middlewares/cors.go
Normal file
29
api/middlewares/cors.go
Normal file
@ -0,0 +1,29 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Cors
|
||||
// @Description: 跨域中间件
|
||||
// @return gin.HandlerFunc
|
||||
func Cors() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
method := c.Request.Method
|
||||
origin := c.Request.Header.Get("Origin")
|
||||
if origin != "" {
|
||||
c.Header("Access-Control-Allow-Origin", origin)
|
||||
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
|
||||
c.Header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
|
||||
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Cache-Control, Content-Language, Content-Type")
|
||||
c.Header("Access-Control-Allow-Credentials", "false")
|
||||
c.Set("content-type", "application/json")
|
||||
}
|
||||
if method == "OPTIONS" {
|
||||
c.AbortWithStatus(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
82
api/middlewares/jwt.go
Normal file
82
api/middlewares/jwt.go
Normal file
@ -0,0 +1,82 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"vote-admin-video-api/consts"
|
||||
"vote-admin-video-api/global"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
// Jwt jwt认证
|
||||
func Jwt() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
authorization := c.Request.Header.Get("Authorization")
|
||||
if authorization == "" || !strings.HasPrefix(authorization, "Bearer ") {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{
|
||||
"message": "请求未授权",
|
||||
"code": consts.TokenError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 去除Bearer
|
||||
authorization = authorization[7:] // 截取字符
|
||||
if authorization == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "token错误/过期",
|
||||
"code": consts.TokenError,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 检测是否存在黑名单
|
||||
res, _ := global.Redis.Get(c, "jwt_black_"+authorization).Result()
|
||||
if res != "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "token错误/过期",
|
||||
"code": consts.TokenError,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 解析jwt
|
||||
t, err := utils.ParseJwt(authorization)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "token错误/过期",
|
||||
"code": consts.TokenError,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 转换类型
|
||||
userId, err := strconv.ParseInt(t.UserId, 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "token错误",
|
||||
"code": consts.TokenError,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("AdminUserId", userId) // 用户id
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
60
api/middlewares/logrus.go
Normal file
60
api/middlewares/logrus.go
Normal file
@ -0,0 +1,60 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// Logrus 日志中间件
|
||||
func Logrus() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
// 开始时间
|
||||
startTime := time.Now()
|
||||
|
||||
// 处理请求
|
||||
c.Next()
|
||||
|
||||
// 获取 请求 参数
|
||||
params := make(map[string]string)
|
||||
|
||||
paramsRaw, ok := c.Get("params")
|
||||
if ok {
|
||||
requestParams, ok := paramsRaw.(map[string]string)
|
||||
if ok || len(requestParams) > 0 {
|
||||
params = requestParams
|
||||
}
|
||||
}
|
||||
|
||||
// 结束时间
|
||||
endTime := time.Now()
|
||||
|
||||
// 执行时间
|
||||
latencyTime := fmt.Sprintf("%6v", endTime.Sub(startTime))
|
||||
|
||||
// 请求方式
|
||||
reqMethod := c.Request.Method
|
||||
|
||||
// 请求路由
|
||||
reqUri := c.Request.RequestURI
|
||||
|
||||
// 状态码
|
||||
statusCode := c.Writer.Status()
|
||||
|
||||
// 请求IP
|
||||
clientIP := c.ClientIP()
|
||||
|
||||
// 日志格式
|
||||
global.Logger.WithFields(logrus.Fields{
|
||||
"http_status": statusCode,
|
||||
"total_time": latencyTime,
|
||||
"ip": clientIP,
|
||||
"method": reqMethod,
|
||||
"uri": reqUri,
|
||||
"params": params,
|
||||
}).Info("access")
|
||||
}
|
||||
}
|
||||
92
api/middlewares/requestParamsMiddleware.go
Normal file
92
api/middlewares/requestParamsMiddleware.go
Normal file
@ -0,0 +1,92 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"net/http"
|
||||
"vote-admin-video-api/consts"
|
||||
)
|
||||
|
||||
// RequestParamsMiddleware 获取请求参数中间件
|
||||
func RequestParamsMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
contentType := c.Request.Header.Get("Content-Type")
|
||||
|
||||
params := make(map[string]string)
|
||||
|
||||
// 判断请求参数类型
|
||||
switch contentType {
|
||||
case "application/json":
|
||||
// 解析 application/json 请求体
|
||||
bodyBytes, err := io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read request body"})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 创建新的请求对象,并设置请求体数据
|
||||
c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||
|
||||
var jsonParams map[string]interface{}
|
||||
err = json.Unmarshal(bodyBytes, &jsonParams)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "Invalid JSON data",
|
||||
"code": consts.HttpError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
for key, value := range jsonParams {
|
||||
params[key] = fmt.Sprintf("%v", value)
|
||||
}
|
||||
|
||||
// 存储参数到上下文
|
||||
c.Set("params", params)
|
||||
|
||||
case "multipart/form-data", "application/form-data", "application/x-www-form-urlencoded":
|
||||
// 解析 Form 表单参数
|
||||
err := c.Request.ParseForm()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "Invalid form data",
|
||||
"code": consts.HttpError,
|
||||
"data": "",
|
||||
})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
for key, values := range c.Request.Form {
|
||||
if len(values) > 0 {
|
||||
params[key] = fmt.Sprintf("%v", values[0])
|
||||
}
|
||||
}
|
||||
|
||||
// 存储参数到上下文
|
||||
c.Set("params", params)
|
||||
|
||||
default:
|
||||
// 解析 URL 参数
|
||||
queryParams := c.Request.URL.Query()
|
||||
|
||||
for key, values := range queryParams {
|
||||
if len(values) > 0 {
|
||||
params[key] = fmt.Sprintf("%v", values[0])
|
||||
}
|
||||
}
|
||||
|
||||
// 存储参数到上下文
|
||||
c.Set("params", params)
|
||||
}
|
||||
|
||||
// 继续处理请求
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
42
api/model/AdminUser.go
Normal file
42
api/model/AdminUser.go
Normal file
@ -0,0 +1,42 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// AdminUser 后台-用户表
|
||||
type AdminUser struct {
|
||||
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:主键id" json:"user_id"`
|
||||
Access string `gorm:"column:access;type:varchar(64);comment:账号;NOT NULL" json:"access"`
|
||||
Password string `gorm:"column:password;type:varchar(128);comment:密码;NOT NULL" json:"password"`
|
||||
Salt string `gorm:"column:salt;type:varchar(255);comment:密码掩码;NOT NULL" json:"salt"`
|
||||
NickName string `gorm:"column:nick_name;type:varchar(255);comment:昵称" json:"nick_name"`
|
||||
Status int `gorm:"column:status;type:tinyint(1);default:2;comment:状态(1:正常 2:审核中 3:审核失败)" json:"status"`
|
||||
IsDeleted int `gorm:"column:is_deleted;type:tinyint(1);default:0;comment:是否被删除(0:否 1:是)" json:"is_deleted"`
|
||||
IsDisabled int `gorm:"column:is_disabled;type:tinyint(1);default:0;comment:是否被禁用(0:否 1:是)" json:"is_disabled"`
|
||||
Phone string `gorm:"column:phone;type:varchar(11);comment:手机号" json:"phone"`
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
|
||||
Sex int `gorm:"column:sex;type:tinyint(1);comment:性别(1:男 2:女)" json:"sex"`
|
||||
Email string `gorm:"column:email;type:varchar(100);comment:邮箱" json:"email"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *AdminUser) TableName() string {
|
||||
return "admin_user"
|
||||
}
|
||||
|
||||
func (m *AdminUser) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.UserId == 0 {
|
||||
m.UserId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
37
api/model/Article.go
Normal file
37
api/model/Article.go
Normal file
@ -0,0 +1,37 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// Article 文章表
|
||||
type Article struct {
|
||||
ArticleId int64 `gorm:"column:article_id;type:bigint(19);primary_key;comment:主键id" json:"article_id"`
|
||||
ArticleTitle string `gorm:"column:article_title;type:varchar(200);comment:文章标题" json:"article_title"`
|
||||
ArticleStatus int `gorm:"column:article_status;type:tinyint(1);default:1;comment:文章状态(1:正常 2:禁用)" json:"article_status"`
|
||||
ArticleNumber string `gorm:"column:article_number;type:varchar(10);comment:文章编号;NOT NULL" json:"article_number"`
|
||||
VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;default:0;comment:总票数" json:"vote_num"`
|
||||
ArticleContent string `gorm:"column:article_content;type:text;comment:文章内容" json:"article_content"`
|
||||
Model
|
||||
ArticleAuthor []*ArticleAuthor `gorm:"foreignKey:ArticleId;references:article_id" json:"article_author"`
|
||||
}
|
||||
|
||||
func (m *Article) TableName() string {
|
||||
return "article"
|
||||
}
|
||||
|
||||
func (m *Article) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.ArticleId == 0 {
|
||||
m.ArticleId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
35
api/model/ArticleAuthor.go
Normal file
35
api/model/ArticleAuthor.go
Normal file
@ -0,0 +1,35 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// ArticleAuthor 文章-作者表
|
||||
type ArticleAuthor struct {
|
||||
AuthorId int64 `gorm:"column:author_id;type:bigint(19);primary_key;comment:主键id" json:"author_id"`
|
||||
ArticleId int64 `gorm:"column:article_id;type:bigint(19);comment:文章id;NOT NULL" json:"article_id"`
|
||||
AuthorName string `gorm:"column:author_name;type:varchar(100);comment:作者姓名" json:"author_name"`
|
||||
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);comment:作者所属医院id" json:"hospital_id"`
|
||||
Model
|
||||
BaseHospital *BaseHospital `gorm:"foreignKey:HospitalId;references:hospital_id" json:"base_hospital"`
|
||||
}
|
||||
|
||||
func (m *ArticleAuthor) TableName() string {
|
||||
return "article_author"
|
||||
}
|
||||
|
||||
func (m *ArticleAuthor) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.AuthorId == 0 {
|
||||
m.AuthorId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
36
api/model/ArticleVoteDay.go
Normal file
36
api/model/ArticleVoteDay.go
Normal file
@ -0,0 +1,36 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// ArticleVoteDay 文章-每日投票
|
||||
type ArticleVoteDay struct {
|
||||
VoteDayId int64 `gorm:"column:vote_day_id;type:bigint(19);primary_key;comment:主键id" json:"vote_day_id"`
|
||||
ArticleId int64 `gorm:"column:article_id;type:bigint(19);comment:文章id;NOT NULL" json:"article_id"`
|
||||
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
|
||||
VotedAt *LocalTime `gorm:"column:voted_at;type:date;comment:投票时间(日)" json:"voted_at"`
|
||||
Model
|
||||
Article *Article `gorm:"foreignKey:ArticleId;references:article_id" json:"article"`
|
||||
User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"`
|
||||
}
|
||||
|
||||
func (m *ArticleVoteDay) TableName() string {
|
||||
return "article_vote_day"
|
||||
}
|
||||
|
||||
func (m *ArticleVoteDay) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.VoteDayId == 0 {
|
||||
m.VoteDayId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
34
api/model/BaseAgreement.go
Normal file
34
api/model/BaseAgreement.go
Normal file
@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// BaseAgreement 基础-协议
|
||||
type BaseAgreement struct {
|
||||
AgreementId int64 `gorm:"column:agreement_id;type:bigint(19);primary_key;comment:主键id" json:"agreement_id"`
|
||||
AgreementTitle string `gorm:"column:agreement_title;type:varchar(255);comment:协议标题" json:"agreement_title"`
|
||||
AgreementType int `gorm:"column:agreement_type;type:tinyint(1);comment:协议类型(1:大赛介绍 2:投票规则);NOT NULL" json:"agreement_type"`
|
||||
AgreementContent string `gorm:"column:agreement_content;type:text;comment:协议内容" json:"agreement_content"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *BaseAgreement) TableName() string {
|
||||
return "base_agreement"
|
||||
}
|
||||
|
||||
func (m *BaseAgreement) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.AgreementId == 0 {
|
||||
m.AgreementId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
26
api/model/BaseArea.go
Normal file
26
api/model/BaseArea.go
Normal file
@ -0,0 +1,26 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// BaseArea 地区表
|
||||
type BaseArea struct {
|
||||
AreaId int64 `gorm:"column:area_id;type:bigint(19);primary_key;comment:地区编号" json:"area_id"`
|
||||
AreaName string `gorm:"column:area_name;type:varchar(255);comment:名称" json:"area_name"`
|
||||
ParentId int64 `gorm:"column:parent_id;type:bigint(19);comment:上级编号" json:"parent_id"`
|
||||
Zip string `gorm:"column:zip;type:varchar(10);comment:邮编" json:"zip"`
|
||||
AreaType int `gorm:"column:area_type;type:tinyint(4);comment:类型(1:国家,2:省,3:市,4:区县)" json:"area_type"`
|
||||
}
|
||||
|
||||
func (m *BaseArea) TableName() string {
|
||||
return "base_area"
|
||||
}
|
||||
|
||||
func (m *BaseArea) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.AreaId == 0 {
|
||||
m.AreaId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
46
api/model/BaseHospital.go
Normal file
46
api/model/BaseHospital.go
Normal file
@ -0,0 +1,46 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// BaseHospital 医院表
|
||||
type BaseHospital struct {
|
||||
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);primary_key;comment:主键id" json:"hospital_id"`
|
||||
HospitalName string `gorm:"column:hospital_name;type:varchar(255);comment:医院名称" json:"hospital_name"`
|
||||
HospitalStatus int `gorm:"column:hospital_status;type:tinyint(1);default:1;comment:状态(0:禁用 1:正常 2:删除)" json:"hospital_status"`
|
||||
HospitalLevelName string `gorm:"column:hospital_level_name;type:varchar(20);comment:医院等级名称" json:"hospital_level_name"`
|
||||
PostCode string `gorm:"column:post_code;type:varchar(50);comment:邮政编码" json:"post_code"`
|
||||
TelePhone string `gorm:"column:tele_phone;type:varchar(20);comment:电话" json:"tele_phone"`
|
||||
ProvinceId int `gorm:"column:province_id;type:int(11);comment:省份id" json:"province_id"`
|
||||
Province string `gorm:"column:province;type:varchar(50);comment:省份" json:"province"`
|
||||
CityId int `gorm:"column:city_id;type:int(11);comment:城市id" json:"city_id"`
|
||||
City string `gorm:"column:city;type:varchar(50);comment:城市" json:"city"`
|
||||
CountyId int `gorm:"column:county_id;type:int(11);comment:区县id" json:"county_id"`
|
||||
County string `gorm:"column:county;type:varchar(50);comment:区县" json:"county"`
|
||||
Address string `gorm:"column:address;type:varchar(255);comment:地址" json:"address"`
|
||||
Lat string `gorm:"column:lat;type:varchar(255);comment:纬度" json:"lat"`
|
||||
Lng string `gorm:"column:lng;type:varchar(255);comment:经度" json:"lng"`
|
||||
Desc string `gorm:"column:desc;type:varchar(255);comment:简介" json:"desc"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *BaseHospital) TableName() string {
|
||||
return "base_hospital"
|
||||
}
|
||||
|
||||
func (m *BaseHospital) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.HospitalId == 0 {
|
||||
m.HospitalId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
33
api/model/Data.go
Normal file
33
api/model/Data.go
Normal file
@ -0,0 +1,33 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// Data 数据表
|
||||
type Data struct {
|
||||
DataId int64 `gorm:"column:data_id;type:bigint(19);primary_key;comment:主键id" json:"data_id"`
|
||||
ViewNum uint `gorm:"column:view_num;type:int(10) unsigned;default:0;comment:浏览数量" json:"view_num"`
|
||||
VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;default:0;comment:投票数量" json:"vote_num"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *Data) TableName() string {
|
||||
return "data"
|
||||
}
|
||||
|
||||
func (m *Data) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.DataId == 0 {
|
||||
m.DataId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
33
api/model/SystemTime.go
Normal file
33
api/model/SystemTime.go
Normal file
@ -0,0 +1,33 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// SystemTime 配置-时间
|
||||
type SystemTime struct {
|
||||
SystemTimeId int64 `gorm:"column:system_time_id;type:bigint(19);primary_key;comment:主键id" json:"system_time_id"`
|
||||
StartTime *LocalTime `gorm:"column:start_time;type:datetime;comment:开始投票时间;NOT NULL" json:"start_time"`
|
||||
EndTime *LocalTime `gorm:"column:end_time;type:datetime;comment:结束投票时间;NOT NULL" json:"end_time"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *SystemTime) TableName() string {
|
||||
return "system_time"
|
||||
}
|
||||
|
||||
func (m *SystemTime) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.SystemTimeId == 0 {
|
||||
m.SystemTimeId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
36
api/model/User.go
Normal file
36
api/model/User.go
Normal file
@ -0,0 +1,36 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// User 用户表
|
||||
type User struct {
|
||||
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:用户id" json:"user_id"`
|
||||
AppIden string `gorm:"column:app_iden;type:varchar(50);comment:app唯一标识" json:"app_iden"`
|
||||
UserStatus int `gorm:"column:user_status;type:tinyint(1);default:1;comment:状态(1:正常 2:禁用)" json:"user_status"`
|
||||
OpenId string `gorm:"column:open_id;type:varchar(100);comment:用户微信标识" json:"open_id"`
|
||||
LoginAt *LocalTime `gorm:"column:login_at;type:datetime;comment:登陆时间" json:"login_at"`
|
||||
LoginIp string `gorm:"column:login_ip;type:varchar(255);comment:登陆ip" json:"login_ip"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *User) TableName() string {
|
||||
return "user"
|
||||
}
|
||||
|
||||
func (m *User) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.UserId == 0 {
|
||||
m.UserId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
38
api/model/Video.go
Normal file
38
api/model/Video.go
Normal file
@ -0,0 +1,38 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// Video 视频表
|
||||
type Video struct {
|
||||
VideoId int64 `gorm:"column:video_id;type:bigint(19);primary_key;comment:主键id" json:"video_id"`
|
||||
VideoTitle string `gorm:"column:video_title;type:varchar(200);comment:视频标题" json:"video_title"`
|
||||
VideoStatus int `gorm:"column:video_status;type:tinyint(1);default:1;comment:视频状态(1:正常 2:禁用)" json:"video_status"`
|
||||
VideoNumber string `gorm:"column:video_number;type:varchar(10);comment:视频编号;NOT NULL" json:"video_number"`
|
||||
VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;default:0;comment:总票数" json:"vote_num"`
|
||||
VideoNo string `gorm:"column:video_no;type:varchar(255);comment:视频编号(保利)" json:"video_no"`
|
||||
VideoContent string `gorm:"column:video_content;type:text;comment:视频内容" json:"video_content"`
|
||||
Model
|
||||
VideoAuthor []*VideoAuthor `gorm:"foreignKey:VideoId;references:video_id" json:"video_author"`
|
||||
}
|
||||
|
||||
func (m *Video) TableName() string {
|
||||
return "video"
|
||||
}
|
||||
|
||||
func (m *Video) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.VideoId == 0 {
|
||||
m.VideoId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
35
api/model/VideoAuthor.go
Normal file
35
api/model/VideoAuthor.go
Normal file
@ -0,0 +1,35 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// VideoAuthor 视频-作者表
|
||||
type VideoAuthor struct {
|
||||
AuthorId int64 `gorm:"column:author_id;type:bigint(19);primary_key;comment:主键id" json:"author_id"`
|
||||
VideoId int64 `gorm:"column:video_id;type:bigint(19);comment:视频id;NOT NULL" json:"video_id"`
|
||||
AuthorName string `gorm:"column:author_name;type:varchar(100);comment:作者姓名" json:"author_name"`
|
||||
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);comment:作者所属医院id" json:"hospital_id"`
|
||||
Model
|
||||
BaseHospital *BaseHospital `gorm:"foreignKey:HospitalId;references:hospital_id" json:"base_hospital"`
|
||||
}
|
||||
|
||||
func (m *VideoAuthor) TableName() string {
|
||||
return "video_author"
|
||||
}
|
||||
|
||||
func (m *VideoAuthor) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.AuthorId == 0 {
|
||||
m.AuthorId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
36
api/model/VideoVoteDay.go
Normal file
36
api/model/VideoVoteDay.go
Normal file
@ -0,0 +1,36 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// VideoVoteDay 视频-每日投票
|
||||
type VideoVoteDay struct {
|
||||
VoteDayId int64 `gorm:"column:vote_day_id;type:bigint(19);primary_key;comment:主键id" json:"vote_day_id"`
|
||||
VideoId int64 `gorm:"column:video_id;type:bigint(19);comment:视频id;NOT NULL" json:"video_id"`
|
||||
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
|
||||
VotedAt *LocalTime `gorm:"column:voted_at;type:date;comment:投票时间(日)" json:"voted_at"`
|
||||
Model
|
||||
Video *Video `gorm:"foreignKey:VideoId;references:video_id" json:"video"`
|
||||
User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"`
|
||||
}
|
||||
|
||||
func (m *VideoVoteDay) TableName() string {
|
||||
return "video_vote_day"
|
||||
}
|
||||
|
||||
func (m *VideoVoteDay) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.VoteDayId == 0 {
|
||||
m.VoteDayId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
87
api/model/model.go
Normal file
87
api/model/model.go
Normal file
@ -0,0 +1,87 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
CreatedAt LocalTime `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt LocalTime `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
// LocalTime 自定义数据类型
|
||||
type LocalTime time.Time
|
||||
|
||||
func (t *LocalTime) UnmarshalJSON(data []byte) error {
|
||||
if string(data) == "null" {
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
// 前端接收的时间字符串
|
||||
str := string(data)
|
||||
// 去除接收的str收尾多余的"
|
||||
timeStr := strings.Trim(str, "\"")
|
||||
t1, err := time.Parse("2006-01-02 15:04:05", timeStr)
|
||||
*t = LocalTime(t1)
|
||||
return err
|
||||
}
|
||||
|
||||
func (t LocalTime) MarshalJSON() ([]byte, error) {
|
||||
formatted := fmt.Sprintf("\"%v\"", time.Time(t).Format("2006-01-02 15:04:05"))
|
||||
return []byte(formatted), nil
|
||||
}
|
||||
|
||||
func (t LocalTime) Value() (driver.Value, error) {
|
||||
// MyTime 转换成 time.Time 类型
|
||||
tTime := time.Time(t)
|
||||
return tTime.Format("2006-01-02 15:04:05"), nil
|
||||
}
|
||||
|
||||
func (t *LocalTime) Scan(v interface{}) error {
|
||||
switch vt := v.(type) {
|
||||
case time.Time:
|
||||
// 字符串转成 time.Time 类型
|
||||
*t = LocalTime(vt)
|
||||
default:
|
||||
return errors.New("类型处理错误")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *LocalTime) String() string {
|
||||
return fmt.Sprintf("hhh:%s", time.Time(*t).String())
|
||||
}
|
||||
|
||||
func (t *LocalTime) IsEmpty() bool {
|
||||
return time.Time(*t).IsZero()
|
||||
}
|
||||
|
||||
func (m *Model) BeforeUpdate(tx *gorm.DB) (err error) {
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Paginate(page, pageSize int) func(db *gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
switch {
|
||||
case pageSize > 100:
|
||||
pageSize = 100
|
||||
case pageSize <= 0:
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
offset := (page - 1) * pageSize
|
||||
return db.Offset(offset).Limit(pageSize)
|
||||
}
|
||||
}
|
||||
57
api/requests/Article.go
Normal file
57
api/requests/Article.go
Normal file
@ -0,0 +1,57 @@
|
||||
package requests
|
||||
|
||||
type ArticleRequest struct {
|
||||
GetArticlePage // 获取图文列表-分页
|
||||
PutArticle // 修改图文详情
|
||||
AddArticle // 新增图文详情
|
||||
PutArticleStatus // 操作图文状态
|
||||
}
|
||||
|
||||
// GetArticlePage 获取图文列表-分页
|
||||
type GetArticlePage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
ArticleStatus *int `json:"article_status" form:"article_status" label:"文章状态"` // (1:正常 2:禁用)
|
||||
Keyword string `json:"keyword" form:"keyword" label:"搜索关键字"`
|
||||
Order *GetArticlePageOrder `json:"order" form:"order" label:"排序"`
|
||||
}
|
||||
|
||||
// GetArticlePageOrder 获取图文列表-分页-排序条件
|
||||
type GetArticlePageOrder struct {
|
||||
VoteNum string `json:"vote_num" form:"vote_num" label:"排序"` // 总票数
|
||||
}
|
||||
|
||||
// PutArticle 修改图文详情
|
||||
type PutArticle struct {
|
||||
ArticleTitle string `json:"article_title" form:"article_title" label:"文章标题" validate:"required"`
|
||||
ArticleStatus int `json:"article_status" form:"article_status" label:"文章状态" validate:"required,oneof=1 2"` // (1:正常 2:禁用)
|
||||
VoteNum *uint `json:"vote_num" form:"vote_num" label:"票数"`
|
||||
ArticleContent string `json:"article_content" form:"article_content" label:"文章内容" validate:"required"`
|
||||
ArticleAuthor []*PutArticleAuthor `json:"article_author" form:"article_author" label:"作者" validate:"required"`
|
||||
}
|
||||
|
||||
// PutArticleAuthor 修改图文详情-作者
|
||||
type PutArticleAuthor struct {
|
||||
AuthorName string `json:"author_name" form:"author_name" label:"作者姓名" validate:"required"`
|
||||
HospitalId string `json:"hospital_id" form:"hospital_id" label:"作者所属医院id" validate:"required"`
|
||||
}
|
||||
|
||||
// AddArticle 新增图文详情
|
||||
type AddArticle struct {
|
||||
ArticleTitle string `json:"article_title" form:"article_title" label:"文章标题" validate:"required"`
|
||||
ArticleStatus int `json:"article_status" form:"article_status" label:"文章状态" validate:"required,oneof=1 2"` // (1:正常 2:禁用)
|
||||
VoteNum *uint `json:"vote_num" form:"vote_num" label:"票数"`
|
||||
ArticleContent string `json:"article_content" form:"article_content" label:"文章内容" validate:"required"`
|
||||
ArticleAuthor []*PutArticleAuthor `json:"article_author" form:"article_author" label:"作者" validate:"required"`
|
||||
}
|
||||
|
||||
// AddArticleAuthor 新增图文详情-作者
|
||||
type AddArticleAuthor struct {
|
||||
AuthorName string `json:"author_name" form:"author_name" label:"作者姓名" validate:"required"`
|
||||
HospitalId string `json:"hospital_id" form:"hospital_id" label:"作者所属医院id" validate:"required"`
|
||||
}
|
||||
|
||||
// PutArticleStatus 操作图文状态
|
||||
type PutArticleStatus struct {
|
||||
ArticleStatus int `json:"article_status" form:"article_status" label:"文章状态" validate:"required,oneof=1 2"` // (1:正常 2:禁用)
|
||||
}
|
||||
26
api/requests/BaseAgreement.go
Normal file
26
api/requests/BaseAgreement.go
Normal file
@ -0,0 +1,26 @@
|
||||
package requests
|
||||
|
||||
type BaseAgreementRequest struct {
|
||||
GetBaseAgreementPage // 获取协议列表-分页
|
||||
PutBaseAgreement // 修改协议
|
||||
AddBaseAgreement // 新增协议
|
||||
}
|
||||
|
||||
// GetBaseAgreementPage 获取协议列表-分页
|
||||
type GetBaseAgreementPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
}
|
||||
|
||||
// PutBaseAgreement 修改协议
|
||||
type PutBaseAgreement struct {
|
||||
AgreementTitle string `json:"agreement_title" form:"agreement_title" label:"协议标题"`
|
||||
AgreementContent string `json:"agreement_content" form:"agreement_content" label:"协议内容"`
|
||||
}
|
||||
|
||||
// AddBaseAgreement 新增协议
|
||||
type AddBaseAgreement struct {
|
||||
AgreementTitle string `json:"agreement_title" form:"agreement_title" label:"协议标题"`
|
||||
AgreementType int `json:"agreement_type" form:"agreement_type" label:"协议类型" validate:"required,oneof=1 2"` // (1:大赛介绍 2:投票规则)
|
||||
AgreementContent string `json:"agreement_content" form:"agreement_content" label:"协议内容"`
|
||||
}
|
||||
18
api/requests/BaseHospital.go
Normal file
18
api/requests/BaseHospital.go
Normal file
@ -0,0 +1,18 @@
|
||||
package requests
|
||||
|
||||
type BaseHospitalRequest struct {
|
||||
GetBaseHospitalList // 获取医院列表
|
||||
}
|
||||
|
||||
// GetBaseHospitalList 获取医院列表
|
||||
type GetBaseHospitalList struct {
|
||||
HospitalName string `json:"hospital_name" form:"hospital_name" label:"医院名称"`
|
||||
HospitalLevelName string `json:"hospital_level_name" form:"hospital_level_name" label:"医院等级名称"`
|
||||
HospitalStatus int `json:"hospital_status" form:"hospital_status" label:"状态"` // 状态(0:禁用 1:正常 2:删除)
|
||||
ProvinceId int `json:"province_id" form:"province_id" label:"省份id"`
|
||||
Province string `json:"province" form:"province" label:"省份"`
|
||||
CityId int `json:"city_id" form:"city_id" label:"城市id"`
|
||||
City string `json:"city" form:"city" label:"城市"`
|
||||
CountyId int `json:"county_id" form:"county_id" label:"区县id"`
|
||||
County string `json:"county" form:"county" label:"区县"`
|
||||
}
|
||||
10
api/requests/Basic.go
Normal file
10
api/requests/Basic.go
Normal file
@ -0,0 +1,10 @@
|
||||
package requests
|
||||
|
||||
type BasicRequest struct {
|
||||
GetBasicAgreement // 获取协议详情
|
||||
}
|
||||
|
||||
// GetBasicAgreement 获取协议详情
|
||||
type GetBasicAgreement struct {
|
||||
AgreementType int `json:"agreement_type" form:"agreement_type" label:"协议类型" validate:"required,oneof=1 2"` // 协议类型(1:大赛介绍 2:投票规则)
|
||||
}
|
||||
21
api/requests/Public.go
Normal file
21
api/requests/Public.go
Normal file
@ -0,0 +1,21 @@
|
||||
package requests
|
||||
|
||||
type PublicRequest struct {
|
||||
Login // 登陆
|
||||
GetIndexData // 首页动态统计数据
|
||||
}
|
||||
|
||||
// Login 登陆
|
||||
type Login struct {
|
||||
Access string `json:"access" form:"access" validate:"required" label:"用户名"` // 用户名
|
||||
Password string `json:"password" form:"password" validate:"required" label:"密码"` // 密码
|
||||
Captcha string `json:"captcha" form:"captcha" validate:"required" label:"验证码"` // 验证码
|
||||
CaptchaId string `json:"captchaId" form:"captchaId" validate:"required"` // 验证码ID
|
||||
}
|
||||
|
||||
// GetIndexData 首页动态统计数据
|
||||
type GetIndexData struct {
|
||||
Type int `json:"type" form:"type" validate:"required,oneof=1 2 3" label:"分类"` // 分类(1:新增用户数 2:图文投票数 3:视频投票数)
|
||||
StartTime string `json:"start_time" form:"start_time" validate:"required" label:"开始时间"`
|
||||
EndTime string `json:"end_time" form:"end_time" validate:"required" label:"结束时间"`
|
||||
}
|
||||
11
api/requests/System.go
Normal file
11
api/requests/System.go
Normal file
@ -0,0 +1,11 @@
|
||||
package requests
|
||||
|
||||
type SystemRequest struct {
|
||||
PutSystemTime // 修改投票时间
|
||||
}
|
||||
|
||||
// PutSystemTime 修改投票时间
|
||||
type PutSystemTime struct {
|
||||
StartTime string `json:"start_time" form:"start_time" label:"开始投票时间" validate:"required"`
|
||||
EndTime string `json:"end_time" form:"end_time" label:"结束投票时间" validate:"required"`
|
||||
}
|
||||
21
api/requests/User.go
Normal file
21
api/requests/User.go
Normal file
@ -0,0 +1,21 @@
|
||||
package requests
|
||||
|
||||
type UserRequest struct {
|
||||
GetUserPage // 获取用户列表-分页
|
||||
PutUserStatus // 操作用户状态
|
||||
}
|
||||
|
||||
// GetUserPage 获取用户列表-分页
|
||||
type GetUserPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
UserId string `json:"user_id" form:"user_id" label:"用户id"`
|
||||
UserStatus int `json:"user_status" form:"user_status" label:"状态"`
|
||||
AppIden string `json:"app_iden" form:"app_iden" label:"app唯一标识"`
|
||||
OpenId string `json:"open_id" form:"open_id" label:"用户微信标识"`
|
||||
}
|
||||
|
||||
// PutUserStatus 操作用户状态
|
||||
type PutUserStatus struct {
|
||||
UserStatus int `json:"user_status" form:"user_status" label:"删除状态" validate:"required,oneof=1 2"` // 状态(1:正常 2:禁用)
|
||||
}
|
||||
36
api/requests/UserVoteDay.go
Normal file
36
api/requests/UserVoteDay.go
Normal file
@ -0,0 +1,36 @@
|
||||
package requests
|
||||
|
||||
type UserVoteDayRequest struct {
|
||||
GetArticleUserVoteDayPage // 用户投票记录列表-图文-分页
|
||||
GetVideoUserVoteDayPage // 用户投票记录列表-视频-分页
|
||||
GetArticleVoteDayPage // 投票记录列表-图文-分页
|
||||
GetVideoVoteDayPage // 投票记录列表-视频-分页
|
||||
}
|
||||
|
||||
// GetArticleUserVoteDayPage 用户投票记录列表-图文-分页
|
||||
type GetArticleUserVoteDayPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
UserId string `json:"user_id" form:"user_id" label:"用户id" validate:"required"`
|
||||
}
|
||||
|
||||
// GetVideoUserVoteDayPage 用户投票记录列表-视频-分页
|
||||
type GetVideoUserVoteDayPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
UserId string `json:"user_id" form:"user_id" label:"用户id" validate:"required"`
|
||||
}
|
||||
|
||||
// GetArticleVoteDayPage 投票记录列表-图文-分页
|
||||
type GetArticleVoteDayPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
ArticleId string `json:"article_id" form:"article_id" label:"文章id" validate:"required"`
|
||||
}
|
||||
|
||||
// GetVideoVoteDayPage 投票记录列表-视频-分页
|
||||
type GetVideoVoteDayPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
VideoId string `json:"video_id" form:"video_id" label:"视频id" validate:"required"`
|
||||
}
|
||||
60
api/requests/Video.go
Normal file
60
api/requests/Video.go
Normal file
@ -0,0 +1,60 @@
|
||||
package requests
|
||||
|
||||
type VideoRequest struct {
|
||||
GetVideoPage // 获取视频列表-分页
|
||||
PutVideo // 修改视频详情
|
||||
AddVideo // 新增视频详情
|
||||
PutVideoStatus // 操作视频状态
|
||||
}
|
||||
|
||||
// GetVideoPage 获取视频列表-分页
|
||||
type GetVideoPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
Keyword string `json:"keyword" form:"keyword" label:"搜索关键字"`
|
||||
VideoStatus *int `json:"video_status" form:"Video_status" label:"视频状态"` // (1:正常 2:禁用)
|
||||
VideoNo string `json:"video_no" form:"video_no" label:"视频编号"` // (保利)
|
||||
Order *GetVideoPageOrder `json:"order" form:"order" label:"排序"`
|
||||
}
|
||||
|
||||
// GetVideoPageOrder 获取视频列表-分页-排序条件
|
||||
type GetVideoPageOrder struct {
|
||||
VoteNum string `json:"vote_num" form:"vote_num" label:"排序"` // 总票数
|
||||
}
|
||||
|
||||
// PutVideo 修改视频详情
|
||||
type PutVideo struct {
|
||||
VideoTitle string `json:"video_title" form:"video_title" label:"视频标题" validate:"required"`
|
||||
VideoStatus int `json:"video_status" form:"video_status" label:"视频状态" validate:"required,oneof=1 2"` // (1:正常 2:禁用)
|
||||
VoteNum *uint `json:"vote_num" form:"vote_num" label:"总票数"`
|
||||
VideoNo string `json:"video_no" form:"video_no" label:"视频编号" validate:"required"` // (保利)
|
||||
VideoContent string `json:"video_content" form:"video_content" label:"视频内容"`
|
||||
VideoAuthor []*PutVideoAuthor `json:"video_author" form:"video_author" label:"作者" validate:"required"`
|
||||
}
|
||||
|
||||
// PutVideoAuthor 修改视频详情-作者
|
||||
type PutVideoAuthor struct {
|
||||
AuthorName string `json:"author_name" form:"author_name" label:"作者姓名" validate:"required"`
|
||||
HospitalId string `json:"hospital_id" form:"hospital_id" label:"作者所属医院id" validate:"required"`
|
||||
}
|
||||
|
||||
// AddVideo 新增视频详情
|
||||
type AddVideo struct {
|
||||
VideoTitle string `json:"video_title" form:"video_title" label:"视频标题" validate:"required"`
|
||||
VideoStatus int `json:"video_status" form:"video_status" label:"视频状态" validate:"required,oneof=1 2"` // (1:正常 2:禁用)
|
||||
VoteNum *uint `json:"vote_num" form:"vote_num" label:"总票数"`
|
||||
VideoNo string `json:"video_no" form:"video_no" label:"视频编号" validate:"required"` // (保利)
|
||||
VideoContent string `json:"video_content" form:"video_content" label:"视频内容"`
|
||||
VideoAuthor []*PutVideoAuthor `json:"video_author" form:"video_author" label:"作者" validate:"required"`
|
||||
}
|
||||
|
||||
// AddVideoAuthor 新增视频详情-作者
|
||||
type AddVideoAuthor struct {
|
||||
AuthorName string `json:"author_name" form:"author_name" label:"作者姓名" validate:"required"`
|
||||
HospitalId string `json:"hospital_id" form:"hospital_id" label:"作者所属医院id" validate:"required"`
|
||||
}
|
||||
|
||||
// PutVideoStatus 操作视频状态
|
||||
type PutVideoStatus struct {
|
||||
VideoStatus int `json:"video_status" form:"video_status" label:"状态" validate:"required,oneof=1 2"` // (1:正常 2:禁用)
|
||||
}
|
||||
4
api/requests/base.go
Normal file
4
api/requests/base.go
Normal file
@ -0,0 +1,4 @@
|
||||
package requests
|
||||
|
||||
type Requests struct {
|
||||
}
|
||||
52
api/responses/responses.go
Normal file
52
api/responses/responses.go
Normal file
@ -0,0 +1,52 @@
|
||||
package responses
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"vote-admin-video-api/consts"
|
||||
)
|
||||
|
||||
type res struct {
|
||||
Code int `json:"code"`
|
||||
Data interface{} `json:"data"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func result(code int, data interface{}, msg string, c *gin.Context) {
|
||||
//if data == nil {
|
||||
// data = gin.H{}
|
||||
//}
|
||||
c.JSON(http.StatusOK, res{
|
||||
code,
|
||||
data,
|
||||
msg,
|
||||
})
|
||||
}
|
||||
|
||||
func Ok(c *gin.Context) {
|
||||
result(consts.HttpSuccess, map[string]interface{}{}, "成功", c)
|
||||
}
|
||||
|
||||
func OkWithMessage(message string, c *gin.Context) {
|
||||
result(consts.HttpSuccess, map[string]interface{}{}, message, c)
|
||||
}
|
||||
|
||||
func OkWithData(data interface{}, c *gin.Context) {
|
||||
result(consts.HttpSuccess, data, "成功", c)
|
||||
}
|
||||
|
||||
func OkWithDetailed(data interface{}, message string, c *gin.Context) {
|
||||
result(consts.HttpSuccess, data, message, c)
|
||||
}
|
||||
|
||||
func Fail(c *gin.Context) {
|
||||
result(consts.HttpError, map[string]interface{}{}, "失败", c)
|
||||
}
|
||||
|
||||
func FailWithMessage(message string, c *gin.Context) {
|
||||
result(consts.HttpError, map[string]interface{}{}, message, c)
|
||||
}
|
||||
|
||||
func FailWithDetailed(data interface{}, message string, c *gin.Context) {
|
||||
result(consts.HttpError, data, message, c)
|
||||
}
|
||||
229
api/router/router.go
Normal file
229
api/router/router.go
Normal file
@ -0,0 +1,229 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"vote-admin-video-api/api/controller"
|
||||
"vote-admin-video-api/api/exception"
|
||||
"vote-admin-video-api/api/middlewares"
|
||||
"vote-admin-video-api/config"
|
||||
"vote-admin-video-api/consts"
|
||||
)
|
||||
|
||||
// Init 初始化路由
|
||||
func Init() *gin.Engine {
|
||||
r := gin.New()
|
||||
|
||||
// 环境设置
|
||||
if config.C.Env == "prod" {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
// 获取请求参数中间件-json格式下会导致接口获取不到请求数据
|
||||
r.Use(middlewares.RequestParamsMiddleware())
|
||||
|
||||
// 日志中间件
|
||||
r.Use(middlewares.Logrus())
|
||||
|
||||
// 异常
|
||||
r.Use(gin.Recovery())
|
||||
|
||||
// 404处理
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
path := c.Request.URL.Path
|
||||
method := c.Request.Method
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"msg": fmt.Sprintf("%s %s not found", method, path),
|
||||
"code": consts.ClientHttpNotFound,
|
||||
"data": "",
|
||||
})
|
||||
})
|
||||
|
||||
// 异常处理
|
||||
r.Use(exception.Recover())
|
||||
|
||||
// 跨域处理
|
||||
r.Use(middlewares.Cors())
|
||||
|
||||
// 加载基础路由
|
||||
api := controller.Api{}
|
||||
|
||||
// 公开路由-不验证权限
|
||||
publicRouter(r, api)
|
||||
|
||||
// 验证jwt
|
||||
r.Use(middlewares.Jwt())
|
||||
|
||||
// 验证权限
|
||||
r.Use(middlewares.Auth())
|
||||
|
||||
// 私有路由-验证权限
|
||||
privateRouter(r, api)
|
||||
|
||||
// 公共路由-验证权限
|
||||
adminRouter(r, api)
|
||||
|
||||
// 基础数据-验证权限
|
||||
basicRouter(r, api)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// publicRouter 公开路由-不验证权限
|
||||
func publicRouter(r *gin.Engine, api controller.Api) {
|
||||
adminGroup := r.Group("/admin")
|
||||
|
||||
// 登录
|
||||
adminGroup.POST("/login", api.Public.Login)
|
||||
|
||||
// 验证码
|
||||
adminGroup.GET("/captcha", api.Public.GetCaptcha)
|
||||
|
||||
// 配置
|
||||
systemGroup := adminGroup.Group("/system")
|
||||
{
|
||||
// 编辑器配置
|
||||
editorGroup := systemGroup.Group("/editor")
|
||||
{
|
||||
// 编辑器-获取配置
|
||||
editorGroup.GET("", api.Editor.GetEditorConfig)
|
||||
|
||||
// 编辑器-上传
|
||||
editorGroup.POST("", api.Editor.EditorUpload)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// adminRouter 公共路由-验证权限
|
||||
func adminRouter(r *gin.Engine, api controller.Api) {
|
||||
adminGroup := r.Group("/admin")
|
||||
|
||||
// 首页
|
||||
indexGroup := adminGroup.Group("/index")
|
||||
{
|
||||
// 首页
|
||||
indexGroup.GET("", api.Public.GetIndex)
|
||||
|
||||
// 首页动态统计数据
|
||||
indexGroup.GET("/data", api.Public.GetIndexData)
|
||||
}
|
||||
}
|
||||
|
||||
// basicRouter 基础数据-验证权限
|
||||
func basicRouter(r *gin.Engine, api controller.Api) {
|
||||
|
||||
}
|
||||
|
||||
// privateRouter 私有路由-验证权限
|
||||
func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
adminGroup := r.Group("/admin")
|
||||
|
||||
// 图文
|
||||
articleGroup := adminGroup.Group("/article")
|
||||
{
|
||||
// 获取图文列表-分页
|
||||
articleGroup.POST("/page", api.Article.GetArticlePage)
|
||||
|
||||
// 获取图文详情
|
||||
articleGroup.GET("/:article_id", api.Article.GetArticle)
|
||||
|
||||
// 修改图文详情
|
||||
articleGroup.PUT("/:article_id", api.Article.PutArticle)
|
||||
|
||||
// 新增图文详情
|
||||
articleGroup.POST("", api.Article.AddArticle)
|
||||
|
||||
// 操作图文状态
|
||||
articleGroup.PUT("/status/:article_id", api.Article.PutArticleStatus)
|
||||
|
||||
// 投票记录列表-图文-分页
|
||||
articleGroup.GET("/vote/page", api.UserVoteDay.GetArticleVotePage)
|
||||
}
|
||||
|
||||
// 视频
|
||||
videoGroup := adminGroup.Group("/video")
|
||||
{
|
||||
// 获取视频列表-分页
|
||||
videoGroup.POST("/page", api.Video.GetVideoPage)
|
||||
|
||||
// 获取视频详情
|
||||
videoGroup.GET("/:video_id", api.Video.GetVideo)
|
||||
|
||||
// 修改视频详情
|
||||
videoGroup.PUT("/:video_id", api.Video.PutVideo)
|
||||
|
||||
// 新增视频详情
|
||||
videoGroup.POST("", api.Video.AddVideo)
|
||||
|
||||
// 操作视频状态
|
||||
videoGroup.PUT("/status/:video_id", api.Video.PutVideoStatus)
|
||||
|
||||
// 投票记录列表-视频-分页
|
||||
videoGroup.GET("/vote/page", api.UserVoteDay.GetVideoVotePage)
|
||||
}
|
||||
|
||||
// 基础数据
|
||||
basicGroup := adminGroup.Group("/basic")
|
||||
{
|
||||
// 协议
|
||||
agreementGroup := basicGroup.Group("/agreement")
|
||||
{
|
||||
// 获取协议列表-分页
|
||||
agreementGroup.GET("/page", api.BaseAgreement.GetBaseAgreementPage)
|
||||
|
||||
// 获取协议详情
|
||||
agreementGroup.GET("/:agreement_id", api.BaseAgreement.GetBaseAgreement)
|
||||
|
||||
// 修改协议
|
||||
agreementGroup.PUT("/:agreement_id", api.BaseAgreement.PutBaseAgreement)
|
||||
|
||||
// 新增协议
|
||||
agreementGroup.POST("", api.BaseAgreement.AddBaseAgreement)
|
||||
}
|
||||
|
||||
// 医院管理
|
||||
hospitalGroup := basicGroup.Group("/hospital")
|
||||
{
|
||||
// 获取医院列表-限制条数
|
||||
hospitalGroup.GET("/page", api.BaseHospital.GetHospitalList)
|
||||
}
|
||||
}
|
||||
|
||||
// 用户
|
||||
userGroup := adminGroup.Group("/user")
|
||||
{
|
||||
// 获取用户列表-分页
|
||||
userGroup.GET("/page", api.User.GetUserPage)
|
||||
|
||||
// 获取用户详情
|
||||
userGroup.GET("/:user_id", api.User.GetUser)
|
||||
|
||||
// 操作用户状态
|
||||
userGroup.PUT("/status/:user_id", api.User.PutUserStatus)
|
||||
|
||||
// 用户投票记录
|
||||
voteGroup := userGroup.Group("/vote")
|
||||
{
|
||||
// 用户投票记录列表-图文-分页
|
||||
voteGroup.GET("/article/page", api.UserVoteDay.GetUserArticleVotePage)
|
||||
|
||||
// 用户投票记录列表-视频-分页
|
||||
voteGroup.GET("/video/page", api.UserVoteDay.GetUserVideoVotePage)
|
||||
}
|
||||
}
|
||||
|
||||
// 配置
|
||||
systemGroup := adminGroup.Group("/system")
|
||||
{
|
||||
// 投票时间
|
||||
timeGroup := systemGroup.Group("/time")
|
||||
{
|
||||
// 获取投票时间详情
|
||||
timeGroup.GET("/:system_time_id", api.System.GetSystemTime)
|
||||
|
||||
// 修改投票时间
|
||||
timeGroup.PUT("/:system_time_id", api.System.PutSystemTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
17
api/service/Public.go
Normal file
17
api/service/Public.go
Normal file
@ -0,0 +1,17 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type PublicService struct {
|
||||
}
|
||||
|
||||
// GetUserIP 获取用户ip
|
||||
func (r *PublicService) GetUserIP(h *http.Request) string {
|
||||
forwarded := h.Header.Get("X-FORWARDED-FOR")
|
||||
if forwarded != "" {
|
||||
return forwarded
|
||||
}
|
||||
return h.RemoteAddr
|
||||
}
|
||||
49
api/service/SystemTime.go
Normal file
49
api/service/SystemTime.go
Normal file
@ -0,0 +1,49 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"vote-admin-video-api/api/dao"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type SystemTimeService struct {
|
||||
}
|
||||
|
||||
// CheckVoteValidStatus 检测投票有效期
|
||||
// bool true:未结束 false:已结束
|
||||
func (r *SystemTimeService) CheckVoteValidStatus() bool {
|
||||
redisKey := "VoteSystemTime"
|
||||
res, _ := global.Redis.Get(context.Background(), redisKey).Result()
|
||||
if res == "" {
|
||||
// 获取配置-时间
|
||||
systemTimeDao := dao.SystemTimeDao{}
|
||||
systemTime, err := systemTimeDao.GetSystemTimeById(1)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if systemTime.EndTime == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// 结束时间
|
||||
endTime := time.Time(*systemTime.EndTime)
|
||||
|
||||
// 当前时间
|
||||
now := time.Now()
|
||||
|
||||
duration := endTime.Sub(now)
|
||||
if duration < 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// 添加缓存
|
||||
_, err = global.Redis.Set(context.Background(), redisKey, "1", duration).Result()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
109
api/service/User.go
Normal file
109
api/service/User.go
Normal file
@ -0,0 +1,109 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
"vote-admin-video-api/config"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
type UserService struct {
|
||||
}
|
||||
|
||||
// AddUserVoteDayCache 新增用户每日投票记录缓存
|
||||
// t 1:文章 2:视频
|
||||
func (r *UserService) AddUserVoteDayCache(userId, id int64, t int) bool {
|
||||
now := time.Now()
|
||||
|
||||
redisKey := "UserVoteDay" + fmt.Sprintf("%d", userId) + fmt.Sprintf("%d", id) + now.Format("2006-01-02") + fmt.Sprintf("%d", t)
|
||||
|
||||
// 缓存过期时间
|
||||
year, month, day := now.Date()
|
||||
location := now.Location()
|
||||
validTime := time.Date(year, month, day, 23, 59, 59, 0, location)
|
||||
duration := validTime.Sub(now)
|
||||
if duration < 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if config.C.Env == "dev" {
|
||||
duration = 60 * 5 * time.Second
|
||||
}
|
||||
|
||||
// 添加缓存
|
||||
_, err := global.Redis.Set(context.Background(), redisKey, "1", duration).Result()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// CheckUserVoteDay 检测用户今日是否投票
|
||||
// t 1:文章 2:视频
|
||||
func (r *UserService) CheckUserVoteDay(userId, id int64, t int) bool {
|
||||
if t != 1 && t != 2 {
|
||||
return false
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
redisKey := "UserVoteDay" + fmt.Sprintf("%d", userId) + fmt.Sprintf("%d", id) + now.Format("2006-01-02") + fmt.Sprintf("%d", t)
|
||||
res, _ := global.Redis.Get(context.Background(), redisKey).Result()
|
||||
if res == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
if res == "1" {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
//if res == "" {
|
||||
// // 是否已投票(1:已投票 0:未投票)
|
||||
// isVote := "0"
|
||||
// if t == 1 {
|
||||
// // 文章
|
||||
// maps := make(map[string]interface{})
|
||||
// maps["article_id"] = id
|
||||
// maps["user_id"] = userId
|
||||
// maps["voted_at"] = now.Format("2006-01-02")
|
||||
//
|
||||
// articleVoteDayDao := dao.ArticleVoteDayDao{}
|
||||
// articleVoteDay, _ := articleVoteDayDao.GetArticleVoteDayById(id)
|
||||
// if articleVoteDay != nil {
|
||||
// isVote = "1"
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if t == 2 {
|
||||
// // 视频
|
||||
// maps := make(map[string]interface{})
|
||||
// maps["article_id"] = id
|
||||
// maps["user_id"] = userId
|
||||
// maps["voted_at"] = now.Format("2006-01-02")
|
||||
//
|
||||
// videoVoteDayDao := dao.VideoVoteDayDao{}
|
||||
// videoVoteDay, _ := videoVoteDayDao.GetVideoVoteDayById(id)
|
||||
// if videoVoteDay != nil {
|
||||
// isVote = "1"
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 添加缓存
|
||||
// if isVote == "1" {
|
||||
// result := r.AddUserVoteDayCache(userId, id, t)
|
||||
// if result == false {
|
||||
// return false
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// res = isVote
|
||||
//}
|
||||
//
|
||||
//if res == "0" {
|
||||
// return false
|
||||
//} else {
|
||||
// return true
|
||||
//}
|
||||
}
|
||||
65
config.yaml
Normal file
65
config.yaml
Normal file
@ -0,0 +1,65 @@
|
||||
port: 8508 # 启动端口
|
||||
|
||||
env: dev # 环境配置
|
||||
|
||||
snowflake: 1 # 雪花算法机器id
|
||||
|
||||
# [数据库配置]
|
||||
mysql:
|
||||
host: '42.193.16.243'
|
||||
username: root
|
||||
password: 'gdxz123456^%$d'
|
||||
port: 30001
|
||||
db-name: vote-video
|
||||
max-idle-cons: 5
|
||||
max-open-cons: 20
|
||||
debug: true
|
||||
|
||||
log:
|
||||
file-path: "./log/"
|
||||
file-name: "vote-admin-video-api.log"
|
||||
|
||||
# [redis]
|
||||
redis:
|
||||
host: '139.155.127.177'
|
||||
port: 30002
|
||||
password: gdxz2022&dj.
|
||||
pool-size: 100
|
||||
db: 5
|
||||
|
||||
# [jwt]
|
||||
jwt:
|
||||
sign-key: 123456899 # 私钥
|
||||
ttl : 24 # 过期时间 小时
|
||||
algo : HS256 # 加密方式
|
||||
|
||||
oss:
|
||||
oss-access-key: LTAI5tKmFrVCghcxX7yHyGhm
|
||||
oss-access-key-secret: q1aiIZCJJuf92YbKk2cSXnPES4zx26
|
||||
oss-bucket: dev-vote-system
|
||||
oss-endpoint: oss-cn-beijing.aliyuncs.com
|
||||
oss-custom-domain-name: https://dev-vote-system.oss-cn-beijing.aliyuncs.com
|
||||
|
||||
# [阿里大鱼短信]
|
||||
dysms:
|
||||
dysms-access-key: LTAI4GGygjsKhyBwvvC3CghV
|
||||
dysms-access-secret: rcx7lO9kQxG10m8NqNPEfEtT9IS8EI
|
||||
|
||||
# [微信]
|
||||
wechat:
|
||||
app-id: wx68affaa9d23528f8
|
||||
app-secret: 2963c90242ddb2421c939591ad9e903d
|
||||
test-pay-app-id: wxa4132ef4701ac5e4
|
||||
single-pay-notify-url: callback/wxpay/single # 单项支付回调地址
|
||||
single-refund-notify-url: callback/wxpay/single/refund # 单项退款回调地址
|
||||
member-pay-notify-url: callback/wxpay/member # 会员支付回调地址
|
||||
member-refund-notify-url: callback/wxpay/member/refund # 会员退款回调地址
|
||||
notify-domain: https://dev-hepa.igandan.com/api/
|
||||
pay-1281030301:
|
||||
mch-id: 1281030301
|
||||
v3-api-secret: sB2tCkT70uwEy7cQCu1llA6nilTbek6F
|
||||
mch-certificate-serial-number: 3D1685894CEDD41753A470211F975D40AE1375F5
|
||||
platform-certs: extend/weChat/certs/1281030301/wechatpay_5B5C8A69CC86D1127F6B6AA06AAAF10531EEFE90.pem
|
||||
private-key: extend/weChat/certs/1281030301/apiclient_key.pem
|
||||
certificate: extend/weChat/certs/1281030301/apiclient_cert.pem
|
||||
|
||||
16
config/config.go
Normal file
16
config/config.go
Normal file
@ -0,0 +1,16 @@
|
||||
package config
|
||||
|
||||
var C Config
|
||||
|
||||
type Config struct {
|
||||
Port int `mapstructure:"port" json:"port" yaml:"port"`
|
||||
Env string `mapstructure:"env" json:"Env" yaml:"Env"`
|
||||
Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
|
||||
Log Log `mapstructure:"log" json:"log" yaml:"log"`
|
||||
Redis Redis `mapstructure:"redis" json:"redis" yaml:"redis"`
|
||||
Jwt Jwt `mapstructure:"jwt" json:"jwt" yaml:"jwt"`
|
||||
Oss Oss `mapstructure:"oss" json:"oss" yaml:"oss"`
|
||||
Snowflake int64 `mapstructure:"snowflake" json:"snowflake" yaml:"snowflake"`
|
||||
Dysms Dysms `mapstructure:"dysms" json:"dysms" yaml:"dysms"`
|
||||
Wechat Wechat `mapstructure:"wechat" json:"wechat" yaml:"wechat"`
|
||||
}
|
||||
6
config/dysms.go
Normal file
6
config/dysms.go
Normal file
@ -0,0 +1,6 @@
|
||||
package config
|
||||
|
||||
type Dysms struct {
|
||||
DysmsAccessKey string `mapstructure:"dysms-access-key" json:"dysms-access-key" yaml:"dysms-access-key"`
|
||||
DysmsAccessSecret string `mapstructure:"dysms-access-secret" json:"dysms-access-secret" yaml:"dysms-access-secret"`
|
||||
}
|
||||
7
config/jwt.go
Normal file
7
config/jwt.go
Normal file
@ -0,0 +1,7 @@
|
||||
package config
|
||||
|
||||
type Jwt struct {
|
||||
SignKey string `mapstructure:"sign-key" json:"sign-key" yaml:"sign-key"` // 私钥
|
||||
Ttl int `mapstructure:"ttl" json:"ttl" yaml:"ttl"` // 过期时间 小时
|
||||
Algo string `mapstructure:"algo" json:"algo" yaml:"algo"` // 加密方式
|
||||
}
|
||||
6
config/log.go
Normal file
6
config/log.go
Normal file
@ -0,0 +1,6 @@
|
||||
package config
|
||||
|
||||
type Log struct {
|
||||
FilePath string `mapstructure:"file-path" json:"file-path" yaml:"file-path"` // 日志目录
|
||||
FileName string `mapstructure:"file-name" json:"file-name" yaml:"file-name"` // 日志名称
|
||||
}
|
||||
12
config/mysql.go
Normal file
12
config/mysql.go
Normal file
@ -0,0 +1,12 @@
|
||||
package config
|
||||
|
||||
type Mysql struct {
|
||||
Host string `mapstructure:"host" json:"host" yaml:"host"` // 服务器地址
|
||||
Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口
|
||||
DbName string `mapstructure:"db-name" json:"db-name" yaml:"db-name"` // 数据库名
|
||||
Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
|
||||
MaxIdleConns int `mapstructure:"max-idle-cons" json:"MaxIdleConns" yaml:"max-idle-cons"` // 空闲中的最大连接数
|
||||
MaxOpenConns int `mapstructure:"max-open-cons" json:"MaxOpenConns" yaml:"max-open-cons"` // 打开到数据库的最大连接数
|
||||
Debug bool `mapstructure:"debug" json:"debug" yaml:"debug"` // 是否开启Gorm全局日志
|
||||
}
|
||||
9
config/oss.go
Normal file
9
config/oss.go
Normal file
@ -0,0 +1,9 @@
|
||||
package config
|
||||
|
||||
type Oss struct {
|
||||
OssAccessKey string `mapstructure:"oss-access-key" json:"oss-access-key" yaml:"oss-access-key"`
|
||||
OssAccessKeySecret string `mapstructure:"oss-access-key-secret" json:"oss-access-key-secret" yaml:"oss-access-key-secret"`
|
||||
OssBucket string `mapstructure:"oss-bucket" json:"oss-bucket" yaml:"oss-bucket"`
|
||||
OssEndpoint string `mapstructure:"oss-endpoint" json:"oss-endpoint" yaml:"oss-endpoint"`
|
||||
OssCustomDomainName string `mapstructure:"oss-custom-domain-name" json:"oss-custom-domain-name" yaml:"oss-custom-domain-name"`
|
||||
}
|
||||
9
config/redis.go
Normal file
9
config/redis.go
Normal file
@ -0,0 +1,9 @@
|
||||
package config
|
||||
|
||||
type Redis struct {
|
||||
Host string `mapstructure:"host" json:"host" yaml:"host"` // 服务器地址
|
||||
Port int `mapstructure:"port" json:"port" yaml:"port"` // 服务器端口
|
||||
Password string `mapstructure:"password" json:"password" yaml:"password"` // 密码
|
||||
PoolSize int `mapstructure:"pool-size" json:"pool-size" yaml:"pool-size"` // 连接池大小
|
||||
Db int `mapstructure:"db" json:"db" yaml:"db"` // 数据库
|
||||
}
|
||||
23
config/wechat.go
Normal file
23
config/wechat.go
Normal file
@ -0,0 +1,23 @@
|
||||
package config
|
||||
|
||||
type Wechat struct {
|
||||
AppId string `mapstructure:"app-id" json:"app-id" yaml:"app-id"`
|
||||
AppSecret string `mapstructure:"app-secret" json:"app-secret" yaml:"app-secret"`
|
||||
TestPayAppId string `mapstructure:"test-pay-app-id" json:"test-pay-app-id" yaml:"test-pay-app-id"`
|
||||
SinglePayNotifyUrl string `mapstructure:"single-pay-notify-url" json:"single-pay-notify-url" yaml:"single-pay-notify-url"` // 单项支付回调地址
|
||||
SingleRefundNotifyUrl string `mapstructure:"single-refund-notify-url" json:"single-refund-notify-url" yaml:"single-refund-notify-url"` // 单项退款回调地址
|
||||
MemberPayNotifyUrl string `mapstructure:"member-pay-notify-url" json:"member-pay-notify-url" yaml:"member-pay-notify-url"` // 会员支付回调地址
|
||||
MemberRefundNotifyUrl string `mapstructure:"member-refund-notify-url" json:"member-refund-notify-url" yaml:"member-refund-notify-url"` // 会员退款回调地址
|
||||
NotifyDomain string `mapstructure:"notify-domain" json:"notify-domain" yaml:"notify-domain"`
|
||||
Pay1281030301 Pay1281030301 `mapstructure:"pay-1281030301" json:"pay-1281030301" yaml:"pay-1281030301"`
|
||||
}
|
||||
|
||||
// Pay1281030301 app
|
||||
type Pay1281030301 struct {
|
||||
MchId string `mapstructure:"mch-id" json:"mch-id" yaml:"mch-id"` // 商户号
|
||||
V3ApiSecret string `mapstructure:"v3-api-secret" json:"v3-api-secret" yaml:"v3-api-secret"` // 商户APIv3密钥
|
||||
MchCertificateSerialNumber string `mapstructure:"mch-certificate-serial-number" json:"mch-certificate-serial-number" yaml:"mch-certificate-serial-number"` // 商户证书序列号
|
||||
PlatformCerts string `mapstructure:"platform-certs" json:"platform-certs" yaml:"platform-certs"` // 平台证书
|
||||
PrivateKey string `mapstructure:"private-key" json:"private-key" yaml:"private-key"`
|
||||
Certificate string `mapstructure:"certificate" json:"certificate" yaml:"certificate"`
|
||||
}
|
||||
24
consts/http.go
Normal file
24
consts/http.go
Normal file
@ -0,0 +1,24 @@
|
||||
package consts
|
||||
|
||||
// 业务状态码
|
||||
const (
|
||||
HttpSuccess = 200 // 成功
|
||||
|
||||
HttpError = -1 // 失败
|
||||
|
||||
UserStatusError = 201 // 用户状态异常
|
||||
|
||||
ClientHttpError = 400 // 错误请求
|
||||
|
||||
ClientHttpUnauthorized = 401 // 未授权
|
||||
|
||||
HttpProhibit = 403 // 禁止请求
|
||||
|
||||
ClientHttpNotFound = 404 // 资源未找到
|
||||
|
||||
TokenError = 405 // token错误/无效
|
||||
|
||||
TokenExptired = 406 // token过期
|
||||
|
||||
ServerError = 500 // 服务器异常
|
||||
)
|
||||
46
core/logrus.go
Normal file
46
core/logrus.go
Normal file
@ -0,0 +1,46 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"vote-admin-video-api/config"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// Logrus 日志记录到文件
|
||||
func Logrus() *logrus.Logger {
|
||||
// 日志文件
|
||||
fileName := path.Join(config.C.Log.FilePath, config.C.Log.FileName)
|
||||
|
||||
// 获取文件夹路径
|
||||
dirPath := filepath.Dir(fileName)
|
||||
|
||||
// 创建文件夹(如果不存在)
|
||||
err := os.MkdirAll(dirPath, os.ModePerm)
|
||||
if err != nil {
|
||||
panic("初始化日志文件失败")
|
||||
}
|
||||
|
||||
// 写入文件
|
||||
src, err := os.OpenFile(fileName, os.O_CREATE|os.O_APPEND|os.O_RDWR, os.ModePerm)
|
||||
if err != nil {
|
||||
panic("初始化日志文件失败")
|
||||
}
|
||||
|
||||
global.Logger = logrus.New()
|
||||
|
||||
// 设置输出
|
||||
global.Logger.Out = src
|
||||
|
||||
// 设置日志级别
|
||||
global.Logger.SetLevel(logrus.DebugLevel)
|
||||
|
||||
// 设置日志格式
|
||||
global.Logger.SetFormatter(&logrus.TextFormatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05",
|
||||
})
|
||||
|
||||
return global.Logger
|
||||
}
|
||||
56
core/mysql.go
Normal file
56
core/mysql.go
Normal file
@ -0,0 +1,56 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
"time"
|
||||
"vote-admin-video-api/config"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
func Mysql() {
|
||||
var err error
|
||||
|
||||
m := config.C.Mysql
|
||||
dsn := fmt.Sprintf("%s:%s@(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local&timeout=%s", m.Username,
|
||||
m.Password, m.Host, m.Port, m.DbName, "10s")
|
||||
|
||||
// newLogger := logger.New(
|
||||
// global.Logger,
|
||||
// logger.Config{
|
||||
// SlowThreshold: time.Second, // Slow SQL threshold
|
||||
// LogLevel: logger.Info, // Log level
|
||||
// IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
|
||||
// ParameterizedQueries: false, // Don't include params in the SQL log
|
||||
// Colorful: false, // Disable color
|
||||
// },
|
||||
// )
|
||||
|
||||
global.Db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Info),
|
||||
// Logger: newLogger,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
sqlDB, _ := global.Db.DB()
|
||||
|
||||
// SetMaxIdleConns 设置空闲连接池中连接的最大数量
|
||||
sqlDB.SetMaxIdleConns(m.MaxIdleConns)
|
||||
|
||||
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
||||
sqlDB.SetMaxOpenConns(m.MaxOpenConns)
|
||||
|
||||
// SetConnMaxLifetime 设置了连接可复用的最大时间。
|
||||
sqlDB.SetConnMaxLifetime(time.Hour)
|
||||
|
||||
// 调试模式
|
||||
//Db.LogMode(m.Debug) // 打印sql
|
||||
// Db.SingularTable(true) // 全局禁用表名复数
|
||||
fmt.Println("初始化数据库成功......")
|
||||
}
|
||||
25
core/redis.go
Normal file
25
core/redis.go
Normal file
@ -0,0 +1,25 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"strconv"
|
||||
"vote-admin-video-api/config"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// Redis redis缓存
|
||||
func Redis() {
|
||||
global.Redis = redis.NewClient(&redis.Options{
|
||||
Addr: config.C.Redis.Host + ":" + strconv.Itoa(config.C.Redis.Port),
|
||||
Password: config.C.Redis.Password,
|
||||
DB: config.C.Redis.Db,
|
||||
PoolSize: config.C.Redis.PoolSize,
|
||||
})
|
||||
_, err := global.Redis.Ping(context.Background()).Result()
|
||||
if err != nil {
|
||||
panic("redis初始化失败! " + err.Error())
|
||||
}
|
||||
fmt.Println("初始化redis成功......")
|
||||
}
|
||||
21
core/snowflake.go
Normal file
21
core/snowflake.go
Normal file
@ -0,0 +1,21 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/bwmarrin/snowflake"
|
||||
"vote-admin-video-api/config"
|
||||
"vote-admin-video-api/global"
|
||||
)
|
||||
|
||||
// Snowflake 雪花算法
|
||||
func Snowflake() {
|
||||
// 创建雪花算法实例
|
||||
node, err := snowflake.NewNode(config.C.Snowflake)
|
||||
if err != nil {
|
||||
panic("snowflake初始化失败! " + err.Error())
|
||||
}
|
||||
|
||||
global.Snowflake = node
|
||||
|
||||
fmt.Println("初始化snowflake成功......")
|
||||
}
|
||||
95
core/validator.go
Normal file
95
core/validator.go
Normal file
@ -0,0 +1,95 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"github.com/go-playground/locales/zh"
|
||||
ut "github.com/go-playground/universal-translator"
|
||||
"github.com/go-playground/validator/v10"
|
||||
zhTranslations "github.com/go-playground/validator/v10/translations/zh"
|
||||
"reflect"
|
||||
"vote-admin-video-api/global"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
// Validator 验证器
|
||||
func Validator() {
|
||||
chzh := zh.New()
|
||||
uni := ut.New(chzh, chzh)
|
||||
global.Trans, _ = uni.GetTranslator("zh")
|
||||
|
||||
global.Validate = validator.New()
|
||||
|
||||
// 通过label标签返回自定义错误内容
|
||||
global.Validate.RegisterTagNameFunc(func(field reflect.StructField) string {
|
||||
label := field.Tag.Get("label")
|
||||
if label == "" {
|
||||
return field.Name
|
||||
}
|
||||
return label
|
||||
})
|
||||
_ = zhTranslations.RegisterDefaultTranslations(global.Validate, global.Trans)
|
||||
// 注册自定义函数和标签
|
||||
// 手机号验证
|
||||
_ = global.Validate.RegisterValidation("Mobile", mobile) // 注册自定义函数,前一个参数是struct里tag自定义,后一个参数是自定义的函数
|
||||
|
||||
// 自定义required错误内容
|
||||
_ = global.Validate.RegisterTranslation("required", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("required", "{0}为必填字段!", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("required", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
// 自定义max错误内容
|
||||
_ = global.Validate.RegisterTranslation("max", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("max", "{0}超出最大长度", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("max", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
// 自定义min错误内容
|
||||
_ = global.Validate.RegisterTranslation("min", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("min", "{0}超出最小长度", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("min", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
// 自定义lt错误内容
|
||||
_ = global.Validate.RegisterTranslation("lt", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("lt", "{0}超出最大值", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("lt", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
// 自定义min错误内容
|
||||
_ = global.Validate.RegisterTranslation("gt", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("gt", "{0}不满足最小值", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("gt", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
// 自定义email错误内容
|
||||
_ = global.Validate.RegisterTranslation("email", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("email", "{0}邮件格式错误", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("email", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
// 自定义mobile错误内容
|
||||
_ = global.Validate.RegisterTranslation("Mobile", global.Trans, func(ut ut.Translator) error {
|
||||
return ut.Add("mobile", "手机号格式错误", false) // see universal-translator for details
|
||||
}, func(ut ut.Translator, fe validator.FieldError) string {
|
||||
t, _ := ut.T("mobile", fe.Field())
|
||||
return t
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// 自定义手机号验证
|
||||
func mobile(fl validator.FieldLevel) bool {
|
||||
return utils.RegexpMobile(fl.Field().String())
|
||||
}
|
||||
41
core/viper.go
Normal file
41
core/viper.go
Normal file
@ -0,0 +1,41 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/spf13/viper"
|
||||
"vote-admin-video-api/config"
|
||||
)
|
||||
|
||||
// Viper 初始化配置文件
|
||||
func Viper() {
|
||||
// 如需增加环境判断 在此处增加
|
||||
// 可根据 命令行 > 环境变量 > 默认值 等优先级进行判别读取
|
||||
viper.New()
|
||||
viper.SetConfigName("config")
|
||||
viper.AddConfigPath("./")
|
||||
viper.SetConfigType("yaml")
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
panic("未找到该文件")
|
||||
} else {
|
||||
panic("读取失败")
|
||||
}
|
||||
}
|
||||
|
||||
// 将读取的配置信息保存至全局变量Conf
|
||||
if err := viper.Unmarshal(&config.C); err != nil {
|
||||
panic(fmt.Errorf("解析配置文件失败, err:%s \n", err))
|
||||
}
|
||||
|
||||
// 自动监听配置修改
|
||||
viper.WatchConfig()
|
||||
|
||||
// 配置文件发生变化后同步到全局变量Conf
|
||||
viper.OnConfigChange(func(e fsnotify.Event) {
|
||||
fmt.Println("config file changed:", e.Name)
|
||||
if err := viper.Unmarshal(&config.C); err != nil {
|
||||
panic(fmt.Errorf("重载配置文件失败, err:%s \n", err))
|
||||
}
|
||||
})
|
||||
}
|
||||
128
extend/Editor/Editor.go
Normal file
128
extend/Editor/Editor.go
Normal file
@ -0,0 +1,128 @@
|
||||
package Editor
|
||||
|
||||
// Config 定义了上传和管理图片、视频、文件等的配置信息
|
||||
type Config struct {
|
||||
// 图片上传配置
|
||||
ImageActionName string `json:"imageActionName"` // 执行上传图片的action名称,默认值:image
|
||||
ImageFieldName string `json:"imageFieldName"` // 提交的图片表单名称,默认值:file
|
||||
ImageMaxSize int `json:"imageMaxSize"` // 上传大小限制,单位B,默认值:2048000
|
||||
ImageAllowFiles []string `json:"imageAllowFiles"` // 允许的图片格式,默认值:[".png", ".jpg", ".jpeg"]
|
||||
ImageCompressEnable bool `json:"imageCompressEnable"` // 是否压缩图片,默认值:true
|
||||
ImageCompressBorder int `json:"imageCompressBorder"` // 图片压缩最长边限制,默认值:1600
|
||||
ImageInsertAlign string `json:"imageInsertAlign"` // 插入图片时的浮动方式,默认值:none
|
||||
ImageUrlPrefix string `json:"imageUrlPrefix"` // 图片访问路径前缀,默认值:空
|
||||
|
||||
// 涂鸦上传配置
|
||||
ScrawlActionName string `json:"scrawlActionName"` // 执行上传涂鸦的action名称,默认值:scrawl
|
||||
ScrawlFieldName string `json:"scrawlFieldName"` // 提交的涂鸦表单名称,默认值:file
|
||||
ScrawlMaxSize int `json:"scrawlMaxSize"` // 涂鸦上传大小限制,单位B,默认值:2048000
|
||||
ScrawlUrlPrefix string `json:"scrawlUrlPrefix"` // 涂鸦访问路径前缀,默认值:空
|
||||
ScrawlInsertAlign string `json:"scrawlInsertAlign"` // 插入涂鸦时的浮动方式,默认值:none
|
||||
|
||||
// 截图上传配置
|
||||
SnapscreenActionName string `json:"snapscreenActionName"` // 执行上传截图的action名称,默认值:snap
|
||||
SnapscreenUrlPrefix string `json:"snapscreenUrlPrefix"` // 截图访问路径前缀,默认值:空
|
||||
SnapscreenInsertAlign string `json:"snapscreenInsertAlign"` // 插入截图时的浮动方式,默认值:none
|
||||
|
||||
// 图片抓取配置
|
||||
CatcherActionName string `json:"catcherActionName"` // 执行抓取远程图片的action名称,默认值:catch
|
||||
CatcherFieldName string `json:"catcherFieldName"` // 提交的图片列表表单名称,默认值:source
|
||||
CatcherLocalDomain []string `json:"catcherLocalDomain"` // 例外的图片抓取域名,默认值:["127.0.0.1", "localhost"]
|
||||
CatcherUrlPrefix string `json:"catcherUrlPrefix"` // 抓取图片访问路径前缀,默认值:空
|
||||
CatcherMaxSize int `json:"catcherMaxSize"` // 抓取图片上传大小限制,单位B,默认值:10485760
|
||||
CatcherAllowFiles []string `json:"catcherAllowFiles"` // 允许的抓取图片格式,默认值:[".png", ".jpg", ".jpeg"]
|
||||
|
||||
// 视频上传配置
|
||||
VideoActionName string `json:"videoActionName"` // 执行上传视频的action名称,默认值:video
|
||||
VideoFieldName string `json:"videoFieldName"` // 提交的视频表单名称,默认值:file
|
||||
VideoUrlPrefix string `json:"videoUrlPrefix"` // 视频访问路径前缀,默认值:空
|
||||
VideoMaxSize int `json:"videoMaxSize"` // 上传视频大小限制,单位B,默认值:102400000
|
||||
VideoAllowFiles []string `json:"videoAllowFiles"` // 允许的视频格式,默认值:[".mp4"]
|
||||
|
||||
// 文件上传配置
|
||||
FileActionName string `json:"fileActionName"` // 执行上传文件的action名称,默认值:file
|
||||
FileFieldName string `json:"fileFieldName"` // 提交的文件表单名称,默认值:file
|
||||
FileUrlPrefix string `json:"fileUrlPrefix"` // 文件访问路径前缀,默认值:空
|
||||
FileMaxSize int `json:"fileMaxSize"` // 上传文件大小限制,单位B,默认值:104857600
|
||||
FileAllowFiles []string `json:"fileAllowFiles"` // 允许的文件格式,默认值:[".zip", ".pdf", ".doc"]
|
||||
|
||||
// 图片列表配置
|
||||
ImageManagerActionName string `json:"imageManagerActionName"` // 执行图片管理的action名称,默认值:listImage
|
||||
ImageManagerListSize int `json:"imageManagerListSize"` // 每次列出文件数量,默认值:20
|
||||
ImageManagerUrlPrefix string `json:"imageManagerUrlPrefix"` // 图片管理访问路径前缀,默认值:空
|
||||
ImageManagerInsertAlign string `json:"imageManagerInsertAlign"` // 插入的图片浮动方式,默认值:none
|
||||
ImageManagerAllowFiles []string `json:"imageManagerAllowFiles"` // 列出的图片文件类型,默认值:[".jpg", ".png", ".jpeg"]
|
||||
|
||||
// 文件列表配置
|
||||
FileManagerActionName string `json:"fileManagerActionName"` // 执行文件管理的action名称,默认值:listFile
|
||||
FileManagerUrlPrefix string `json:"fileManagerUrlPrefix"` // 指定要列出文件的目录,默认值:空
|
||||
FileManagerListSize int `json:"fileManagerListSize"` // 每次列出文件数量,默认值:20
|
||||
FileManagerAllowFiles []string `json:"fileManagerAllowFiles"` // 列出的文件类型,默认值:[".zip", ".pdf", ".doc"]
|
||||
|
||||
// 公式配置
|
||||
FormulaConfig FormulaConfig `json:"formulaConfig"` // 公式渲染相关配置
|
||||
}
|
||||
|
||||
// FormulaConfig 定义了公式渲染的相关配置
|
||||
type FormulaConfig struct {
|
||||
ImageUrlTemplate string `json:"imageUrlTemplate"` // 公式渲染的图片URL模板
|
||||
}
|
||||
|
||||
// UploadDto 上传返回数据
|
||||
type UploadDto struct {
|
||||
Original string `json:"original"`
|
||||
State string `json:"state"`
|
||||
Title string `json:"title"`
|
||||
Type string `json:"type"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
// GetConfig 封装方法,返回配置信息
|
||||
func GetConfig() Config {
|
||||
return Config{
|
||||
ImageActionName: "image",
|
||||
ImageFieldName: "file",
|
||||
ImageMaxSize: 8388608,
|
||||
ImageAllowFiles: []string{".jpg", ".png", ".jpeg"},
|
||||
ImageCompressEnable: false,
|
||||
ImageCompressBorder: 5000,
|
||||
ImageInsertAlign: "none",
|
||||
ImageUrlPrefix: "",
|
||||
ScrawlActionName: "crawl",
|
||||
ScrawlFieldName: "file",
|
||||
ScrawlMaxSize: 10485760,
|
||||
ScrawlUrlPrefix: "",
|
||||
ScrawlInsertAlign: "none",
|
||||
SnapscreenActionName: "snap",
|
||||
SnapscreenUrlPrefix: "",
|
||||
SnapscreenInsertAlign: "none",
|
||||
CatcherActionName: "catch",
|
||||
CatcherFieldName: "source",
|
||||
CatcherLocalDomain: []string{"127.0.0.1", "localhost"},
|
||||
CatcherUrlPrefix: "",
|
||||
CatcherMaxSize: 10485760,
|
||||
CatcherAllowFiles: []string{".jpg", ".png", ".jpeg"},
|
||||
VideoActionName: "video",
|
||||
VideoFieldName: "file",
|
||||
VideoUrlPrefix: "",
|
||||
VideoMaxSize: 104857600,
|
||||
VideoAllowFiles: []string{".mp4"},
|
||||
FileActionName: "file",
|
||||
FileFieldName: "file",
|
||||
FileUrlPrefix: "",
|
||||
FileMaxSize: 104857600,
|
||||
FileAllowFiles: []string{".zip", ".pdf", ".doc"},
|
||||
ImageManagerActionName: "listImage",
|
||||
ImageManagerListSize: 20,
|
||||
ImageManagerUrlPrefix: "",
|
||||
ImageManagerInsertAlign: "none",
|
||||
ImageManagerAllowFiles: []string{".jpg", ".png", ".jpeg"},
|
||||
FileManagerActionName: "listFile",
|
||||
FileManagerUrlPrefix: "",
|
||||
FileManagerListSize: 20,
|
||||
FileManagerAllowFiles: []string{".zip", ".pdf", ".doc"},
|
||||
FormulaConfig: FormulaConfig{
|
||||
ImageUrlTemplate: "https://r.latexeasy.com/image.svg?{}",
|
||||
},
|
||||
}
|
||||
}
|
||||
104
extend/aliyun/dysms.go
Normal file
104
extend/aliyun/dysms.go
Normal file
@ -0,0 +1,104 @@
|
||||
// Package aliyun 短信
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
dysmsapi20170525 "github.com/alibabacloud-go/dysmsapi-20170525/v3/client"
|
||||
util "github.com/alibabacloud-go/tea-utils/v2/service"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"vote-admin-video-api/config"
|
||||
)
|
||||
|
||||
func createClient() (_result *dysmsapi20170525.Client, _err error) {
|
||||
accessKeyId := config.C.Dysms.DysmsAccessKey
|
||||
accessKeySecret := config.C.Dysms.DysmsAccessSecret
|
||||
|
||||
openapiConfig := &openapi.Config{
|
||||
// 必填,您的 AccessKey ID
|
||||
AccessKeyId: &accessKeyId,
|
||||
// 必填,您的 AccessKey Secret
|
||||
AccessKeySecret: &accessKeySecret,
|
||||
}
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
||||
openapiConfig.Endpoint = tea.String("dysmsapi.aliyuncs.com")
|
||||
_result = &dysmsapi20170525.Client{}
|
||||
_result, _err = dysmsapi20170525.NewClient(openapiConfig)
|
||||
return _result, _err
|
||||
}
|
||||
|
||||
// SendSms 发送短信
|
||||
func SendSms(phoneNumber, templateCode, sceneDesc string, templateParam map[string]interface{}) error {
|
||||
client, err := createClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
params, err := json.Marshal(templateParam)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
|
||||
PhoneNumbers: tea.String(phoneNumber),
|
||||
SignName: tea.String("肝胆相照"),
|
||||
TemplateCode: tea.String(templateCode),
|
||||
TemplateParam: tea.String(string(params)),
|
||||
}
|
||||
|
||||
tryErr := func() (e error) {
|
||||
defer func() {
|
||||
if r := tea.Recover(recover()); r != nil {
|
||||
e = r
|
||||
}
|
||||
}()
|
||||
|
||||
// 初始化运行时配置。
|
||||
runtime := &util.RuntimeOptions{}
|
||||
// 读取超时
|
||||
runtime.SetReadTimeout(10000)
|
||||
// 连接超时
|
||||
runtime.SetConnectTimeout(5000)
|
||||
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
response, err := client.SendSms(sendSmsRequest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if response.Body == nil {
|
||||
return errors.New("短信发送失败")
|
||||
}
|
||||
|
||||
if response.Body.Code != nil && *response.Body.Code != "OK" {
|
||||
if response.Body.Message != nil {
|
||||
return errors.New(*response.Body.Message)
|
||||
}
|
||||
}
|
||||
|
||||
// 检测唯一值返回
|
||||
if response.Body.RequestId == nil {
|
||||
if response.Body.Message != nil {
|
||||
return errors.New(*response.Body.Message)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}()
|
||||
|
||||
if tryErr != nil {
|
||||
var sdkError = &tea.SDKError{}
|
||||
if t, ok := tryErr.(*tea.SDKError); ok {
|
||||
sdkError = t
|
||||
} else {
|
||||
sdkError.Message = tea.String(tryErr.Error())
|
||||
}
|
||||
// 如有需要,请打印 error
|
||||
_, err = util.AssertAsString(sdkError.Message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
186
extend/aliyun/oss.go
Normal file
186
extend/aliyun/oss.go
Normal file
@ -0,0 +1,186 @@
|
||||
package aliyun
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/hmac"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
"vote-admin-video-api/config"
|
||||
)
|
||||
|
||||
// GetOssSignResponse 获取oss签名返回值
|
||||
type GetOssSignResponse struct {
|
||||
AccessId string `json:"access_id"` // 主键id
|
||||
Host string `json:"host"`
|
||||
Policy string `json:"policy"`
|
||||
Signature string `json:"signature"`
|
||||
Expire int64 `json:"expire"`
|
||||
Callback string `json:"callback"`
|
||||
Dir string `json:"dir"`
|
||||
}
|
||||
|
||||
// GetOssSign 获取oss签名
|
||||
func GetOssSign(dir string) (*GetOssSignResponse, error) {
|
||||
now := time.Now()
|
||||
expire := 30 // 设置该policy超时时间是30s,即这个policy过了这个有效时间,将不能访问。
|
||||
end := now.Add(time.Second * time.Duration(expire))
|
||||
expiration := strings.Replace(end.Format("2006-01-02T15:04:05.000Z"), "+00:00", ".000Z", 1)
|
||||
|
||||
start := []interface{}{"starts-with", "$key", dir}
|
||||
conditions := [][]interface{}{start}
|
||||
|
||||
arr := map[string]interface{}{
|
||||
"expiration": expiration,
|
||||
"conditions": conditions,
|
||||
}
|
||||
policy, _ := json.Marshal(arr)
|
||||
base64Policy := base64.StdEncoding.EncodeToString(policy)
|
||||
stringToSign := base64Policy
|
||||
h := hmac.New(sha1.New, []byte(config.C.Oss.OssAccessKeySecret))
|
||||
h.Write([]byte(stringToSign))
|
||||
signature := base64.StdEncoding.EncodeToString(h.Sum(nil))
|
||||
|
||||
response := &GetOssSignResponse{
|
||||
AccessId: config.C.Oss.OssAccessKey,
|
||||
Host: config.C.Oss.OssCustomDomainName,
|
||||
Policy: base64Policy,
|
||||
Signature: signature,
|
||||
Expire: end.Unix(),
|
||||
Callback: "",
|
||||
Dir: dir,
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// CreateClient 创建客户端
|
||||
func CreateClient() (*oss.Client, error) {
|
||||
// 创建OSSClient实例。
|
||||
client, err := oss.New(config.C.Oss.OssEndpoint, config.C.Oss.OssAccessKey, config.C.Oss.OssAccessKeySecret)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// GetCusTomObjectToRAM 下载自定义风格文件到内存
|
||||
func GetCusTomObjectToRAM(filename string, style string) (string, error) {
|
||||
if style == "" {
|
||||
style = "image/resize"
|
||||
}
|
||||
|
||||
ossClient, err := CreateClient()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// yourBucketName填写存储空间名称。
|
||||
bucket, err := ossClient.Bucket(config.C.Oss.OssBucket)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 下载文件到流。
|
||||
body, err := bucket.GetObject(filename, oss.Process(style))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
||||
defer func(body io.ReadCloser) {
|
||||
_ = body.Close()
|
||||
}(body)
|
||||
|
||||
data, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
// GetObjectToRAM 下载文件到内存
|
||||
func GetObjectToRAM(filename string) (string, error) {
|
||||
ossClient, err := CreateClient()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// yourBucketName填写存储空间名称。
|
||||
bucket, err := ossClient.Bucket(config.C.Oss.OssBucket)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 下载文件到流。
|
||||
body, err := bucket.GetObject(filename)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。
|
||||
defer func(body io.ReadCloser) {
|
||||
_ = body.Close()
|
||||
}(body)
|
||||
|
||||
data, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
}
|
||||
|
||||
// GetObjectToLocal 下载文件到本地
|
||||
func GetObjectToLocal(filename, local string) (bool, error) {
|
||||
ossClient, err := CreateClient()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// yourBucketName填写存储空间名称。
|
||||
bucket, err := ossClient.Bucket(config.C.Oss.OssBucket)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 下载文件到本地文件,并保存到指定的本地路径中。如果指定的本地文件存在会覆盖,不存在则新建。
|
||||
// 如果未指定本地路径,则下载后的文件默认保存到示例程序所属项目对应本地路径中。
|
||||
// 依次填写Object完整路径(例如exampledir/exampleobject.txt)和本地文件的完整路径(例如D:\\localpath\\examplefile.txt)。Object完整路径中不能包含Bucket名称。
|
||||
err = bucket.GetObjectToFile(filename, local)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// PutObjectByte 上传文件
|
||||
func PutObjectByte(filename string, content []byte) (bool, error) {
|
||||
ossClient, err := CreateClient()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// yourBucketName填写存储空间名称。
|
||||
bucket, err := ossClient.Bucket(config.C.Oss.OssBucket)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
err = bucket.PutObject(filename, bytes.NewReader(content))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
92
extend/app/base.go
Normal file
92
extend/app/base.go
Normal file
@ -0,0 +1,92 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"strings"
|
||||
"vote-admin-video-api/config"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
apiUrl = "https://dev-wx.igandan.com" // 接口地址
|
||||
secretKey = "RY8pcn04#TSdzHVX6YgWnyCue9!T&QP^" // 产品私有密钥,服务端生成签名信息使用,请严格保管,避免泄露
|
||||
platform = "suanyisuan" // 所属平台
|
||||
devImagePrefix = "https://dev-doc.igandan.com/app" // 测试环境图片地址前缀
|
||||
prodImagePrefix = "https://dev-doc.igandan.com/app" // 正式环境图片地址前缀
|
||||
)
|
||||
|
||||
// GenSignature 生成签名信息
|
||||
func GenSignature(params map[string]interface{}) (string, error) {
|
||||
// 对map的key进行排序,包括多层嵌套的情况
|
||||
data := sortMapRecursively(params)
|
||||
|
||||
// 转换为JSON
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
sing := utils.HmacSHA256(string(jsonData), secretKey)
|
||||
return sing, nil
|
||||
}
|
||||
|
||||
// sortMapRecursively 对map的key进行排序,包括多层嵌套的情况
|
||||
func sortMapRecursively(data map[string]interface{}) map[string]interface{} {
|
||||
sortedMap := make(map[string]interface{})
|
||||
keys := make([]string, 0, len(data))
|
||||
|
||||
// 收集所有的key
|
||||
for key := range data {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
|
||||
// 对key进行排序
|
||||
sort.Strings(keys)
|
||||
|
||||
// 通过排序后的key插入新map中
|
||||
for _, key := range keys {
|
||||
value := data[key]
|
||||
switch valueTyped := value.(type) {
|
||||
case map[string]interface{}:
|
||||
// 如果是嵌套的map,递归调用
|
||||
sortedMap[key] = sortMapRecursively(valueTyped)
|
||||
case []interface{}:
|
||||
// 如果是嵌套的slice,对其中的map进行递归调用
|
||||
for i, v := range valueTyped {
|
||||
if vMap, ok := v.(map[string]interface{}); ok {
|
||||
valueTyped[i] = sortMapRecursively(vMap)
|
||||
}
|
||||
}
|
||||
sortedMap[key] = valueTyped
|
||||
default:
|
||||
// 否则直接插入
|
||||
sortedMap[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
return sortedMap
|
||||
}
|
||||
|
||||
// HandleImagePrefix 处理app图片前缀
|
||||
func HandleImagePrefix(u string) (string, error) {
|
||||
if u == "" {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// 去除oss前缀
|
||||
u = utils.RemoveOssDomain(u)
|
||||
|
||||
var imgPath string
|
||||
if config.C.Env == "prod" {
|
||||
imgPath = strings.Replace(u, devImagePrefix, "", 1)
|
||||
} else {
|
||||
imgPath = strings.Replace(u, prodImagePrefix, "", 1)
|
||||
}
|
||||
|
||||
if imgPath == "/null" {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
return imgPath, nil
|
||||
}
|
||||
53
extend/app/pay.go
Normal file
53
extend/app/pay.go
Normal file
@ -0,0 +1,53 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// PayOrderRequest 获取订单支付请求数据
|
||||
type PayOrderRequest struct {
|
||||
OrderId string `json:"orderId" label:"订单编号" validate:"required"` // 订单id
|
||||
}
|
||||
|
||||
// PayOrderDataResponse 获取订单支付返回数据-data
|
||||
type PayOrderDataResponse struct {
|
||||
AppId string `json:"appid"` // 公众号id
|
||||
Total int `json:"total"` // 订单总金额(精确到分)
|
||||
Description string `json:"description"` // 订单描述
|
||||
OpenId string `json:"openid"` // 下单用户
|
||||
OutTradeNo string `json:"out_trade_no"` // 商户订单
|
||||
Attach string `json:"attach"` // 附加信息
|
||||
NotifyUrl string `json:"notify_url"` // 异步接收微信支付结果通知的回调地址
|
||||
GoodName string `json:"goodName"` // 商品名称
|
||||
}
|
||||
|
||||
// VerifySignature 验证签名
|
||||
func VerifySignature(req PayOrderRequest, requestSign string) error {
|
||||
// 将 JSON 数据编码为字节数组
|
||||
jsonData, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
err = json.Unmarshal(jsonData, &maps)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 生成签名
|
||||
sign, err := GenSignature(maps)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(sign)
|
||||
// 对比签名
|
||||
if sign != requestSign {
|
||||
return errors.New("签名错误")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
242
extend/app/userCase.go
Normal file
242
extend/app/userCase.go
Normal file
@ -0,0 +1,242 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
// GetUserCaseByAppIdenRequest 根据app唯一标识获取用户病例信息-请求数据
|
||||
type GetUserCaseByAppIdenRequest struct {
|
||||
PatientUuid string `json:"patientUuid"` // 患者 uuid
|
||||
Platform string `json:"platform"` // 所属平台
|
||||
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
|
||||
}
|
||||
|
||||
// UpdateUserCaseRequest 修改疾病信息-请求数据
|
||||
type UpdateUserCaseRequest struct {
|
||||
IsAllergy *int `json:"isAllergy"` // 是否过敏史 0否 1是
|
||||
AllergyInfo string `json:"allergyInfo"` // 过敏史详情
|
||||
IsHospital *int `json:"isHospital"` // 是否去医院 0否 1是
|
||||
IsMedication *int `json:"isMedication"` // 是否服药 0否 1是
|
||||
MedicationInfo string `json:"medicationInfo"` // 正在服用的药物
|
||||
LiverStatus string `json:"liverStatus"` // 目前肝脏状态
|
||||
OtherDisease string `json:"otherDisease"` // 合并其他慢性疾病 (多个英文逗号分隔拼接)
|
||||
DiseasesList []*DiseasesListRequest `json:"diseasesList"` // 所患疾病列表
|
||||
PatientUuid string `json:"patientUuid"` // 患者 uuid
|
||||
Platform string `json:"platform"` // 所属平台
|
||||
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
|
||||
}
|
||||
|
||||
type DiseasesListRequest struct {
|
||||
Uuid string `json:"uuid"` // 疾病 uuid
|
||||
Year *int `json:"year"` // 患病时长
|
||||
Info string `json:"info"` // 丙肝基因型(仅针对丙肝)
|
||||
Name string `json:"name"` // 疾病名称
|
||||
}
|
||||
|
||||
// GetUserCaseByAppIdenResponse 根据app唯一标识获取用户病例信息-返回数据
|
||||
type GetUserCaseByAppIdenResponse struct {
|
||||
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
||||
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
|
||||
Data *GetUserCaseByAppIdenData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// UpdateUserCaseResponse 修改用户病例-返回数据
|
||||
type UpdateUserCaseResponse struct {
|
||||
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
||||
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
|
||||
Data string `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// GetUserCaseByAppIdenData 根据app唯一标识获取用户病例信息-data详细数据
|
||||
type GetUserCaseByAppIdenData struct {
|
||||
AllergyInfo string `json:"allergyInfo" description:"过敏史详情"`
|
||||
PatientUUID string `json:"patientUuid" description:"患者 uuid"`
|
||||
DiseasesList []*DiseasesListData `json:"diseasesList" description:"所患疾病列表"`
|
||||
MedicationInfo string `json:"medicationInfo" description:"正在服用的药物"`
|
||||
OtherDisease string `json:"otherDisease" description:"合并其他慢性疾病 (多个英文逗号分隔拼接)"`
|
||||
IsMedication *int `json:"isMedication" description:"是否服药 0否 1是"`
|
||||
IsHospital *int `json:"isHospital" description:"是否去医院 0否 1是"`
|
||||
IsAllergy *int `json:"isAllergy" description:"是否过敏史 0否 1是"`
|
||||
LiverStatus string `json:"liverStatus" description:"目前肝脏状态"`
|
||||
}
|
||||
|
||||
// DiseasesListData 根据app唯一标识获取用户病例信息-data详细数据-所患疾病数据
|
||||
type DiseasesListData struct {
|
||||
UUID string `json:"uuid" description:"疾病 uuid"`
|
||||
Year *int `json:"year" description:"患病时长"`
|
||||
Info string `json:"info" description:"丙肝基因型(仅针对丙肝)"`
|
||||
Name string `json:"name" description:"疾病名称"`
|
||||
}
|
||||
|
||||
// GetUserCaseByAppIden 根据app唯一标识获取用户病例信息
|
||||
func GetUserCaseByAppIden(appIden string) (g *GetUserCaseByAppIdenResponse, err error) {
|
||||
// 准备要发送的 JSON 数据
|
||||
requestData := GetUserCaseByAppIdenRequest{
|
||||
PatientUuid: appIden,
|
||||
Platform: platform,
|
||||
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
}
|
||||
|
||||
// 将 JSON 数据编码为字节数组
|
||||
jsonData, err := json.Marshal(requestData)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
err = json.Unmarshal(jsonData, &maps)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 获取请求签名
|
||||
sign, err := GenSignature(maps)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 准备请求体
|
||||
requestBody := bytes.NewBuffer(jsonData)
|
||||
|
||||
// 设置请求 URL
|
||||
url := apiUrl + "/patient-api/getDiseaseInfo"
|
||||
|
||||
// 创建 POST 请求
|
||||
req, err := http.NewRequest("POST", url, requestBody)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("sign", sign)
|
||||
|
||||
// 发送请求
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
_ = Body.Close()
|
||||
}(resp.Body)
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 检查响应状态码
|
||||
if resp.StatusCode != 200 {
|
||||
return g, errors.New("失败")
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &g)
|
||||
if err != nil {
|
||||
// json解析失败
|
||||
return g, err
|
||||
}
|
||||
|
||||
utils.LogJsonInfo("获取app数据返回", g)
|
||||
|
||||
if g.Code != 200 {
|
||||
if g.Msg != "" {
|
||||
return g, errors.New(g.Msg)
|
||||
} else {
|
||||
return g, errors.New("失败")
|
||||
}
|
||||
}
|
||||
|
||||
return g, nil
|
||||
}
|
||||
|
||||
// UpdateUserCase 修改用户病例
|
||||
func UpdateUserCase(reqData UpdateUserCaseRequest) (g *UpdateUserCaseResponse, err error) {
|
||||
reqData.Platform = platform
|
||||
reqData.Timestamp = strconv.FormatInt(time.Now().Unix(), 10)
|
||||
|
||||
// 将 JSON 数据编码为字节数组
|
||||
jsonData, err := json.Marshal(reqData)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
err = json.Unmarshal(jsonData, &maps)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 获取请求签名
|
||||
sign, err := GenSignature(maps)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 准备请求体
|
||||
requestBody := bytes.NewBuffer(jsonData)
|
||||
|
||||
// 设置请求 URL
|
||||
url := apiUrl + "/patient-api/upDiseaseInfo"
|
||||
|
||||
// 创建 POST 请求
|
||||
req, err := http.NewRequest("POST", url, requestBody)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("sign", sign)
|
||||
|
||||
// 发送请求
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
_ = Body.Close()
|
||||
}(resp.Body)
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 检查响应状态码
|
||||
if resp.StatusCode != 200 {
|
||||
return g, errors.New("失败")
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &g)
|
||||
if err != nil {
|
||||
// json解析失败
|
||||
return g, err
|
||||
}
|
||||
|
||||
utils.LogJsonInfo("修改app数据返回", g)
|
||||
|
||||
if g.Code != 200 {
|
||||
if g.Msg != "" {
|
||||
return g, errors.New(g.Msg)
|
||||
} else {
|
||||
return g, errors.New("失败")
|
||||
}
|
||||
}
|
||||
|
||||
return g, nil
|
||||
}
|
||||
239
extend/app/userInfo.go
Normal file
239
extend/app/userInfo.go
Normal file
@ -0,0 +1,239 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
"vote-admin-video-api/utils"
|
||||
)
|
||||
|
||||
// GetInfoByMobileRequest 根据手机号获取用户信息-请求数据
|
||||
type GetInfoByMobileRequest struct {
|
||||
Mobile string `json:"mobile"` // 手机号
|
||||
Platform string `json:"platform"` // 所属平台
|
||||
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
|
||||
}
|
||||
|
||||
// UpdateInfoRequest 修改用户信息-请求数据
|
||||
type UpdateInfoRequest struct {
|
||||
Birthday string `json:"birthday"` // 出生日期
|
||||
IsPegnant *int `json:"isPegnant"` // 是否怀孕 1无计划 2计划中 3已怀孕 4家有宝宝
|
||||
Sex *int `json:"sex"` // 性别 0男 1女
|
||||
Weight *int `json:"weight"` // 体重 KG
|
||||
ExpectedDateOfChildbirth string `json:"expectedDateOfChildbirth"` // 预产期
|
||||
IsHbv *int `json:"isHbv"` // 市区 id
|
||||
NationUuid string `json:"nationUuid"` // 民族 uuid
|
||||
PatientUuid string `json:"patientUuid"` // 患者 uuid
|
||||
Name string `json:"name"` // 姓名
|
||||
ProvId *int64 `json:"provId"` // 省份 id
|
||||
CityId *int64 `json:"cityId"` // 城市 id
|
||||
CountyId *int64 `json:"countyId"` // 市区 id
|
||||
Height *int `json:"height"` // 身高 cm
|
||||
Platform string `json:"platform"` // 所属平台
|
||||
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
|
||||
}
|
||||
|
||||
// GetInfoByMobileResponse 根据手机号获取用户信息-返回数据
|
||||
type GetInfoByMobileResponse struct {
|
||||
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
||||
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
|
||||
Data GetInfoByMobileData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// UpdateInfoResponse 修改用户信息-返回数据
|
||||
type UpdateInfoResponse struct {
|
||||
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
||||
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
|
||||
Data string `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// GetInfoByMobileData 根据手机号获取用户信息-data详细数据
|
||||
type GetInfoByMobileData struct {
|
||||
Birthday string `json:"birthday" description:"出生日期"`
|
||||
IsPregnant *int `json:"isPregnant" description:"是否怀孕 1无计划 2计划中 3已怀孕 4家有宝宝"`
|
||||
Sex *int `json:"sex" description:"性别 0男 1女"`
|
||||
Mobile string `json:"mobile" description:"手机号"`
|
||||
Photo string `json:"photo" description:"头像地址"`
|
||||
Weight *int `json:"weight" description:"体重 KG"`
|
||||
CityID *int64 `json:"cityId" description:"城市 id"`
|
||||
ExpectedDateOfChildbirth string `json:"expectedDateOfChildbirth" description:"预产期"`
|
||||
CountyID *int64 `json:"countyId" description:"市区 id"`
|
||||
IsHBV *int `json:"isHbv" description:"有无 肝硬化或肝癌家族史 0无1有2未知"`
|
||||
NationUUID string `json:"nationUuid" description:"民族 uuid"`
|
||||
PatientUUID string `json:"patientUuid" description:"患者 uuid"`
|
||||
Name string `json:"name" description:"姓名"`
|
||||
ProvinceID *int64 `json:"provId" description:"省份 id"`
|
||||
Height *int `json:"height" description:"身高 cm"`
|
||||
OpenId string `json:"openid" description:"openid"`
|
||||
UnionId string `json:"unionid" description:"unionid"`
|
||||
}
|
||||
|
||||
// GetInfoByMobile 根据手机号获取用户信息
|
||||
func GetInfoByMobile(mobile string) (g *GetInfoByMobileResponse, err error) {
|
||||
// 准备要发送的 JSON 数据
|
||||
requestData := GetInfoByMobileRequest{
|
||||
Mobile: mobile,
|
||||
Platform: platform,
|
||||
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
}
|
||||
|
||||
// 将 JSON 数据编码为字节数组
|
||||
jsonData, err := json.Marshal(requestData)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
err = json.Unmarshal(jsonData, &maps)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 获取请求签名
|
||||
sign, err := GenSignature(maps)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 准备请求体
|
||||
requestBody := bytes.NewBuffer(jsonData)
|
||||
|
||||
// 设置请求 URL
|
||||
url := apiUrl + "/patient-api/getInfo"
|
||||
|
||||
// 创建 POST 请求
|
||||
req, err := http.NewRequest("POST", url, requestBody)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("sign", sign)
|
||||
|
||||
// 发送请求
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
_ = Body.Close()
|
||||
}(resp.Body)
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 检查响应状态码
|
||||
if resp.StatusCode != 200 {
|
||||
return g, errors.New("失败")
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &g)
|
||||
if err != nil {
|
||||
// json解析失败
|
||||
return g, err
|
||||
}
|
||||
|
||||
utils.LogJsonInfo("获取app数据返回", g)
|
||||
|
||||
if g.Code != 200 {
|
||||
if g.Msg != "" {
|
||||
return g, errors.New(g.Msg)
|
||||
} else {
|
||||
return g, errors.New("失败")
|
||||
}
|
||||
}
|
||||
|
||||
return g, nil
|
||||
}
|
||||
|
||||
// UpdateInfo 修改用户信息
|
||||
func UpdateInfo(reqData UpdateInfoRequest) (g *UpdateInfoResponse, err error) {
|
||||
reqData.Platform = platform
|
||||
reqData.Timestamp = strconv.FormatInt(time.Now().Unix(), 10)
|
||||
|
||||
// 将 JSON 数据编码为字节数组
|
||||
jsonData, err := json.Marshal(reqData)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
err = json.Unmarshal(jsonData, &maps)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 获取请求签名
|
||||
sign, err := GenSignature(maps)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 准备请求体
|
||||
requestBody := bytes.NewBuffer(jsonData)
|
||||
|
||||
// 设置请求 URL
|
||||
url := apiUrl + "/patient-api/updateInfo"
|
||||
|
||||
// 创建 POST 请求
|
||||
req, err := http.NewRequest("POST", url, requestBody)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("sign", sign)
|
||||
|
||||
// 发送请求
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
_ = Body.Close()
|
||||
}(resp.Body)
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 检查响应状态码
|
||||
if resp.StatusCode != 200 {
|
||||
return g, errors.New("失败")
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &g)
|
||||
if err != nil {
|
||||
// json解析失败
|
||||
return g, err
|
||||
}
|
||||
|
||||
utils.LogJsonInfo("修改app数据返回", g)
|
||||
|
||||
if g.Code != 200 {
|
||||
if g.Msg != "" {
|
||||
return g, errors.New(g.Msg)
|
||||
} else {
|
||||
return g, errors.New("失败")
|
||||
}
|
||||
}
|
||||
|
||||
return g, nil
|
||||
}
|
||||
103
extend/weChat/base.go
Normal file
103
extend/weChat/base.go
Normal file
@ -0,0 +1,103 @@
|
||||
package weChat
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/services/payments"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/utils"
|
||||
"vote-admin-video-api/config"
|
||||
)
|
||||
|
||||
// 创建客户端
|
||||
func createClient() (*core.Client, error) {
|
||||
mchId := config.C.Wechat.Pay1281030301.MchId // 商户号
|
||||
mchCertificateSerialNumber := config.C.Wechat.Pay1281030301.MchCertificateSerialNumber // 商户证书序列号
|
||||
v3ApiSecret := config.C.Wechat.Pay1281030301.V3ApiSecret // 商户APIv3密钥
|
||||
privateKeyPath := config.C.Wechat.Pay1281030301.PrivateKey // 商户私钥文件地址
|
||||
|
||||
if mchId == "" {
|
||||
return nil, errors.New("商户号错误")
|
||||
}
|
||||
|
||||
mchPrivateKey, err := utils.LoadPrivateKeyWithPath(privateKeyPath)
|
||||
if err != nil {
|
||||
return nil, errors.New("微信支付生成失败")
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
|
||||
opts := []core.ClientOption{
|
||||
option.WithWechatPayAutoAuthCipher(mchId, mchCertificateSerialNumber, mchPrivateKey, v3ApiSecret),
|
||||
}
|
||||
|
||||
client, err := core.NewClient(ctx, opts...)
|
||||
if err != nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// WxPayResult 支付结果
|
||||
type WxPayResult struct {
|
||||
OrderStatus int `json:"order_status"` // 订单状态(1:待支付 2:已完成 3:已取消)
|
||||
PayStatus int `json:"pay_status"` // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
PayTime *string `json:"pay_time"` // 支付时间
|
||||
}
|
||||
|
||||
// WxPayRefundResult 退款结果
|
||||
type WxPayRefundResult struct {
|
||||
RefundStatus int `json:"refundStatus"` // 订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款)
|
||||
SuccessTime *string `json:"successTime"` // 退款成功时间
|
||||
}
|
||||
|
||||
// HandlePayStatus 处理支付状态
|
||||
func HandlePayStatus(t *payments.Transaction) (w *WxPayResult, err error) {
|
||||
w = &WxPayResult{}
|
||||
|
||||
switch *t.TradeState {
|
||||
case "SUCCESS": // 支付成功
|
||||
w.OrderStatus = 2
|
||||
w.PayStatus = 2
|
||||
w.PayTime = t.SuccessTime
|
||||
case "CLOSED": // 已关闭
|
||||
w.PayStatus = 6
|
||||
case "REVOKED": // 已撤销(付款码支付)
|
||||
w.PayStatus = 7
|
||||
case "USERPAYING": // 用户支付中(付款码支付)
|
||||
w.PayStatus = 3
|
||||
case "PAYERROR": // 支付失败(其他原因,如银行返回失败)
|
||||
w.PayStatus = 4
|
||||
default:
|
||||
return nil, errors.New("未知支付状态")
|
||||
}
|
||||
|
||||
return w, nil
|
||||
}
|
||||
|
||||
// HandlePayRefundStatus 处理退款状态
|
||||
func HandlePayRefundStatus(r *refunddomestic.Refund) (w *WxPayRefundResult, err error) {
|
||||
w = &WxPayRefundResult{}
|
||||
|
||||
switch *r.Status {
|
||||
case "SUCCESS": // 退款成功
|
||||
w.RefundStatus = 3
|
||||
if r.SuccessTime != nil {
|
||||
successTime := r.SuccessTime.Format("2006-01-02 15:04:05")
|
||||
w.SuccessTime = &successTime
|
||||
}
|
||||
case "CLOSED": // 退款关闭
|
||||
w.RefundStatus = 5
|
||||
case "PROCESSING": // 退款处理中
|
||||
w.RefundStatus = 2
|
||||
case "ABNORMAL": // 退款异常
|
||||
return nil, errors.New("退款状态错误")
|
||||
default:
|
||||
return nil, errors.New("退款状态错误")
|
||||
}
|
||||
|
||||
return w, nil
|
||||
}
|
||||
28
extend/weChat/certs/1281030301/apiclient_key.pem
Normal file
28
extend/weChat/certs/1281030301/apiclient_key.pem
Normal file
@ -0,0 +1,28 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDR4fiYRUjnLQA+
|
||||
TPMslDvQIIyZm4ajWFcSXg6yozhdi/O+vuRhwgyeGXsE4SpvuxkK4HPZaocrsjqe
|
||||
68Y46DyhudzXIBy50IF2UeN5ilj7ydq5TJbBOi1iOF1lgOUNK6DGiOQ+folVNKyN
|
||||
sjrsA3RHUKHF/JdOfcpSGzvV79FnmjSll/KsdxEc9LCiAa5t7GYA9Hx7AIDG4i8b
|
||||
03d5EJXvE8BGUZQItE6VIpHwyySTHtGQkPyI6lqMKt2Jlx0TFHu0GkTEmhuA2Z5C
|
||||
5gOqYWclQO+X2ORgulL9Q3mNcpfy9uBynI/CJDbSvVTkNfwYB0Ny1knu/+in7C6p
|
||||
IPJYfZpPAgMBAAECggEAWb5tJPcjSC5W10ziAiLUPJdeZ2Q4OupQOPtc/4eJV367
|
||||
V8maMC7gZE3y61A4bBQtjhgRkVrat5V7OW8JkFXFb0XhJ1+EyPNeGDDFureseuWC
|
||||
EA+uuqrcsw306a0mw+3uzlXEevByWquuSNx4E2katE/HDLiIHjjtZRReDomAGfLw
|
||||
vLNZ40RgdNSXmwpVRoHOZnvX+C2Hxh4fKsrxs1HRCjFsSpTxKwsK6/Kdudj4hsaO
|
||||
Z5glqf4qopPlQIIkToxOe5p7ukwo7vqaqogixx3jOjruOMpzxZ24wU5AxneLcOYr
|
||||
ZC1659Uwv96TsKpueakWw0lq3TXkv9Qs+wDNI+NC6QKBgQDx4hWXplLYPYwgGgxG
|
||||
L9Pk+If9aDS9wj78JUaYBXKR5atXmf/62ufahW4IEDfmMugC1bm9MoYC7CmHv1nk
|
||||
nxckB84B20NOSiaxbkOaJuMHDtnNeXCmL8Gvtb8fTni1AM/g6XEleEw1r40LNZAq
|
||||
kdyQ1+OUFhRQGOvAe1SRr1rdGwKBgQDeIcauwMPkc3Seh6Fb66FQ4Lgmt1GvvuiG
|
||||
UJiwgwPFbEaKKczBHBL6hlKoAFweFa2Qw2xJ0H8jwb8RnkkNcAKYUyMc2wi85+Ih
|
||||
d568pvXMdYl4DGeGdd/sXKf4dGDjcb2AHzNfDuklbCsAojtO3pLWOs5U/RSKe8ps
|
||||
hhWa8nPO3QKBgQCIxuKU3X1tP+hz4qbcLYFxscQcXIeuYiABrwZrQnFV5Pxtzex9
|
||||
Krn+zIK61oj1iAXATKD6Ro6XKnoVg/POHtQUEMHCNP2rUKzumj5p9eFdBV3OHgTA
|
||||
RLMOrARGLLZ/C9WBBiBwIsVdekaUdxZtrAuAcEQFYjLcVCtDrbnVo8YKzwKBgEsg
|
||||
V0cBMP+RwM5hBsTE45Er/3wwofLzeUb7+Tgxh1P887qEuphRO2X5ifkB7iXKpSIB
|
||||
xh0M5AMe4tU9mG1wBaCo9YYr2j+xmTxCbbBWM2mMEwtD/rtuIGabS7/u9FnYPQQZ
|
||||
CVHMBDRA6iZTuAVLp5PG3cPGuGzBw0uC6cm22E4NAoGAKrbg3nFPKtzBJZ8Z0iNH
|
||||
G2gNotmHXbd4+gs4e3Iz9xsEabm4wCoEibNojNdMkX8zX267ebgfvesGEobROjW9
|
||||
Intvh39xi3aQ2Q5gvXzKdY0lDzgVvQ7udmLQ4dCUyYnpLr7Yac0asRxLge2esCWV
|
||||
x2uW2YTiUW3zsbHN/N/vJ5I=
|
||||
-----END PRIVATE KEY-----
|
||||
BIN
extend/weChat/certs/1636644248/apiclient_cert.p12
Normal file
BIN
extend/weChat/certs/1636644248/apiclient_cert.p12
Normal file
Binary file not shown.
25
extend/weChat/certs/1636644248/apiclient_cert.pem
Normal file
25
extend/weChat/certs/1636644248/apiclient_cert.pem
Normal file
@ -0,0 +1,25 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIELjCCAxagAwIBAgIUfewObFfg3HHwd/AvUkBlZq85vrswDQYJKoZIhvcNAQEL
|
||||
BQAwXjELMAkGA1UEBhMCQ04xEzARBgNVBAoTClRlbnBheS5jb20xHTAbBgNVBAsT
|
||||
FFRlbnBheS5jb20gQ0EgQ2VudGVyMRswGQYDVQQDExJUZW5wYXkuY29tIFJvb3Qg
|
||||
Q0EwHhcNMjMwMzAxMDExNzE3WhcNMjgwMjI4MDExNzE3WjCBhzETMBEGA1UEAwwK
|
||||
MTYzNjY0NDI0ODEbMBkGA1UECgwS5b6u5L+h5ZWG5oi357O757ufMTMwMQYDVQQL
|
||||
DCrljJfkuqzmrKPmrKPnm7jnhaflgaXlurfnp5HmioDmnInpmZDlhazlj7gxCzAJ
|
||||
BgNVBAYMAkNOMREwDwYDVQQHDAhTaGVuWmhlbjCCASIwDQYJKoZIhvcNAQEBBQAD
|
||||
ggEPADCCAQoCggEBAK7x9ywApasrs+xIt0XxHhYOK4xZeuNEj5o7pzTcZMRkd6CB
|
||||
1eX2ydlUfDe+FcNS03cwLNtUeAfrZXlhA807b4HuReaFqCrbt87hfIF/lOBpePdN
|
||||
sSr8Wi6OKfPakuLNZ4RCOdlvgxPMhOf2b9VFQwns8h72H6JrFz7xR+Heundy3KGH
|
||||
kEoG2qcl7nKyhkUVSRSH4/yzsxsDIwkpXjEiSL87E+A6GKik7jphYc+vfV9NURiA
|
||||
JwbVWbQMhpj3YLRxgXadLS4xMryB59fYKm+VFMNg/jSZG55Jz2DW02aR2h3KjegY
|
||||
SGA9qMKojkFVOrZvxKWOvtEWw2JQ/1dRvzYpgw0CAwEAAaOBuTCBtjAJBgNVHRME
|
||||
AjAAMAsGA1UdDwQEAwID+DCBmwYDVR0fBIGTMIGQMIGNoIGKoIGHhoGEaHR0cDov
|
||||
L2V2Y2EuaXRydXMuY29tLmNuL3B1YmxpYy9pdHJ1c2NybD9DQT0xQkQ0MjIwRTUw
|
||||
REJDMDRCMDZBRDM5NzU0OTg0NkMwMUMzRThFQkQyJnNnPUhBQ0M0NzFCNjU0MjJF
|
||||
MTJCMjdBOUQzM0E4N0FEMUNERjU5MjZFMTQwMzcxMA0GCSqGSIb3DQEBCwUAA4IB
|
||||
AQCBjjBeJTRtnsIISCfoQ7pj70dil5LTBNjpzV9swGOG7sY9dTMbHV0K2BUyRvbD
|
||||
eY2fuCcr3Qt3L1RykyomKbxD4O6b/ZPLTkiq2m+hq34g2Ig7zUx0a0sNKf/NPAq6
|
||||
6pVu5/XdIKYXz2OsByBI8aN2hkcUApmM1qlm+gb4FSmTzkdHaFRblhDlKfiRdAw8
|
||||
T4yliaOFovqhf/S8o5Xa76kQMOb3uJ/oE4KX02kp/ig5wZKj9nay46AyovBXOj+Z
|
||||
0oaeIPFDXCPzZV7LA4E45zDl43fL8r+9OzaVprRZ9ASO0cgnPsHyS+o/mpMEBOR4
|
||||
NIwdIaqYRQ/Rh6eZQvrqDZ4r
|
||||
-----END CERTIFICATE-----
|
||||
28
extend/weChat/certs/1636644248/apiclient_key.pem
Normal file
28
extend/weChat/certs/1636644248/apiclient_key.pem
Normal file
@ -0,0 +1,28 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCu8fcsAKWrK7Ps
|
||||
SLdF8R4WDiuMWXrjRI+aO6c03GTEZHeggdXl9snZVHw3vhXDUtN3MCzbVHgH62V5
|
||||
YQPNO2+B7kXmhagq27fO4XyBf5TgaXj3TbEq/Foujinz2pLizWeEQjnZb4MTzITn
|
||||
9m/VRUMJ7PIe9h+iaxc+8Ufh3rp3ctyhh5BKBtqnJe5ysoZFFUkUh+P8s7MbAyMJ
|
||||
KV4xIki/OxPgOhiopO46YWHPr31fTVEYgCcG1Vm0DIaY92C0cYF2nS0uMTK8gefX
|
||||
2CpvlRTDYP40mRueSc9g1tNmkdodyo3oGEhgPajCqI5BVTq2b8Sljr7RFsNiUP9X
|
||||
Ub82KYMNAgMBAAECggEAT7uNyGs/FkVjykPV67WZ3bl1lZDOljgQLt4TNd9gubWE
|
||||
ZA3om9efZULBHnKu3oeoQ0EcoJXd4tYhOHHD1szI5HHhP9AYtffPzSUtpqOsCZ9o
|
||||
d2XcYlgDDgbTDgXHPkEZdcjtLrFJD0P+Ku5BR/U6OZLZQs0v28ltHc2/0iy91WQt
|
||||
iB/NSf88dY1L5RVZc7dZfb8nFB2/BsITUXDFJpzdim3AXKvNYzDajs/yuoTp5r/b
|
||||
2EOjUIGPP55W/8iPwbezgDToF79toum6V7yUpCq5P+QQvnnbJfoc1yXB48zHjmgP
|
||||
I2P1cDVtFs+V9Edb6qsU3e4CMyBQg5Uykk3TUqZRIQKBgQDnXgGk8XnI1kG9jZMR
|
||||
wMkra87Dx76vrBdM47n+c2I1xubM9WSeSUxtXGyryTwJ9i6/BUyc3Eyb2wi4Q8AK
|
||||
1ZIEFhvIUkBJpUgevAksj4eX6z0qDwDc3ZhgAAWOplnOCCyJuOBKmZks4GaQb4Gv
|
||||
/aSFVQ9jefOc5e9RIDNzkHFkaQKBgQDBkigvmusjad95Jt34TwyE4Dr9z2LzBker
|
||||
6ebcyQmv4YdKvq0KaaVMrroH7pNu7CSFrj4CGqdS/Gg1BtK8Xaxn+gEWT6RPcsi1
|
||||
mPwy/7oiK0GodzNI6RW5HDZEHKG2icEb4ycDnHeLfThKmP/gckPifjcJHrP5OX1A
|
||||
V6qrq4iFBQKBgGdgB1gNVJ65rJHnCckq3Dd8advsCXUwbRC7x0S7hSwF/OWi1xwq
|
||||
H+3VF/EBbsP8rRJIadzESa5xhUnfa5Trq9wLjMpKhdLh+IFS/r5cOvdT8fYy0e3d
|
||||
TNHH8LO1+/YkjNHUOtLaIih88xah284ohDPWt5N4z7JQwkb7HkIKTb/RAoGARt51
|
||||
7Afx8sM+WCLMva5jTPqzXl1hQsyXzO8T4N2RuFz/pXPt8pP/OvX1khXc0I2QSYkj
|
||||
lq2feRiEJnXbDa/WATNc1ohOBfBmX2YlX56UzRG9Nip+EkGT/HPBwmohIq2Ij+c4
|
||||
T3AnrGAqDdW6SLhM9k1zZNli1uofW0E9cSCaGOkCgYAI29eelAwUxpbDXJB6vSyr
|
||||
LBvDV+C+/3OW4AjlJ5lWSzY8oMn21Xzp03MwXOXOSFuR6vTMkJDKJ3zIDHBt9vJ2
|
||||
evNmfMKzqNdsvNjORb79GAZ0paBF1XGzXvPO9JSUi6oZxNg+pW8oxIzx0xFIgtZL
|
||||
PxnzFj2IbraxYwuR1CI6rQ==
|
||||
-----END PRIVATE KEY-----
|
||||
@ -0,0 +1,24 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIEFDCCAvygAwIBAgIUES/M0bnsyCknA6tzY8c9dLav3BowDQYJKoZIhvcNAQEL
|
||||
BQAwXjELMAkGA1UEBhMCQ04xEzARBgNVBAoTClRlbnBheS5jb20xHTAbBgNVBAsT
|
||||
FFRlbnBheS5jb20gQ0EgQ2VudGVyMRswGQYDVQQDExJUZW5wYXkuY29tIFJvb3Qg
|
||||
Q0EwHhcNMjMwMzAxMDExNzE2WhcNMjgwMjI4MDExNzE2WjBuMRgwFgYDVQQDDA9U
|
||||
ZW5wYXkuY29tIHNpZ24xEzARBgNVBAoMClRlbnBheS5jb20xHTAbBgNVBAsMFFRl
|
||||
bnBheS5jb20gQ0EgQ2VudGVyMQswCQYDVQQGDAJDTjERMA8GA1UEBwwIU2hlblpo
|
||||
ZW4wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvM2YfnzwBvd+B5Ro1
|
||||
z+LaCVYhxia9/hQwRhi5ag2HmeZZNgMNf4+bC75Nv+t3RW0lklbM9qJSBk03eEBG
|
||||
75Q33VPGy//WCJZgXlHV+rZ7ejzWtwh9Muhd60HFXhIsM3pwlfWpPo6bkJie9Na0
|
||||
wMsgg/8UxsNydhEZF6HFLdqY+zqGOjRRCduIyJcFhtrkjNUMIFAOSkHBaGJjmGrm
|
||||
OXigAnYAsaD1VWLOoblA0HlOs144KQ/5Shj74Ggk2pFo/YDN+i5hazHZo9hZnjmX
|
||||
G5BV3KDJD0k3Gn/qymhiLlzGsYW79P+BbsmE/M6jKIP2jxcDDdpek0Z6Lk0Cz/au
|
||||
02UPAgMBAAGjgbkwgbYwCQYDVR0TBAIwADALBgNVHQ8EBAMCA/gwgZsGA1UdHwSB
|
||||
kzCBkDCBjaCBiqCBh4aBhGh0dHA6Ly9ldmNhLml0cnVzLmNvbS5jbi9wdWJsaWMv
|
||||
aXRydXNjcmw/Q0E9MUJENDIyMEU1MERCQzA0QjA2QUQzOTc1NDk4NDZDMDFDM0U4
|
||||
RUJEMiZzZz1IQUNDNDcxQjY1NDIyRTEyQjI3QTlEMzNBODdBRDFDREY1OTI2RTE0
|
||||
MDM3MTANBgkqhkiG9w0BAQsFAAOCAQEAJX6C/QMYF0F3IiK9P8tW2DKN8y9vCU20
|
||||
6Ws8u4bcO3AaiSmsdAJ6I1MyZkUg3dKijtnDbieY2P364IEp48TmI4k6UJwP4+/f
|
||||
i0NseOm3BmAJ3mBoNmuFul+61opKpeV67AYQuhbehVA4cDPqKb/hP0tEcb6nefIO
|
||||
mnys5GReLWLFV2XFR1h9QtsohPOEYlpBl6lmKHNoQZdAPtSHq2iVFLbuD7GMKoj7
|
||||
Br2puJEQgxla1AsNxAYjGttEIO9I30+L5av7SKesSGXvL6G5eOvFrZl0S4EsNVz4
|
||||
QeL4qmtFEKDi2eaxeyLuWe9TMI/IiI3ngekoDyTwdnUzadumbio+dg==
|
||||
-----END CERTIFICATE-----
|
||||
BIN
extend/weChat/certs/1659662936/apiclient_cert.p12
Normal file
BIN
extend/weChat/certs/1659662936/apiclient_cert.p12
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user