Files
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

178 lines
5.1 KiB
Go

package versionctrl
import (
"encoding/json"
"91porn-server/common"
"91porn-server/common/constant"
"91porn-server/common/stderr"
"91porn-server/common/version"
"91porn-server/models/l/operatorlgmod"
"91porn-server/models/v/versionmod"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// Findlist doc
// @Summary 版本信息查询
// @Description 根据字段信息条件查询
// @Tags product
// @Accept mpfd,json
// @Produce json,html
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /ver/list [get]
func FindList(ctx *gin.Context) {
var arg struct {
common.StandQuery
versionmod.VersionQueryReq
}
if err := ctx.ShouldBind(&arg); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
total, data, err := versionmod.FindMany(common.StandQueryMap(arg.StandQuery, arg.VersionQueryReq))
if err != nil {
common.ServeJSON(ctx, stderr.ErrDbQueryError, "")
return
}
common.ServeJSON(ctx, stderr.Success, map[string]interface{}{
"total": total,
"history": data,
})
}
// Insert doc
// @Summary 新增
// @Description 新增
// @Tags product
// @Accept mpfd,json
// @Produce json,html
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /web/ver [post]
func Insert(ctx *gin.Context) {
manager, err := common.GetAdminAct(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
return
}
v := versionmod.Version{}
if err = ctx.ShouldBind(&v); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
return
}
cv, err := version.New(v.VersionName)
if err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
}
v.VersionName = cv.String()
v.Code = cv.GetCode()
if v.VersionRange.Major != "" && v.VersionRange.Minor != "" {
major, _ := version.New(v.VersionRange.Major)
minor, _ := version.New(v.VersionRange.Minor)
if major.LT(minor) {
common.ServeJSON(ctx, stderr.ErrVersionRange, nil)
return
}
}
if v.SpecVersion != "" {
spc, _ := version.New(v.SpecVersion)
if spc.GTE(cv) {
common.ServeJSON(ctx, stderr.ErrVersionTooLow, nil)
return
}
}
if err = versionmod.Insert(&v); err != nil {
common.ServeJSON(ctx, stderr.ErrDbInsertError, err.Error())
return
}
log, _ := json.Marshal(v)
_ = operatorlgmod.RecordOperation(manager, constant.SystemManageVersion, constant.Add, string(log), ctx.Request.URL.RequestURI())
common.ServeJSON(ctx, stderr.Success, nil)
}
// Update doc
// @Summary 修改producttype
// @Description 修改producttype
// @Tags product
// @Accept mpfd,json
// @Produce json,html
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /web [put]
func Update(ctx *gin.Context) {
manager, err := common.GetAdminAct(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
return
}
var q struct {
ID primitive.ObjectID `json:"id" form:"id" binding:"required"`
versionmod.VersionUpdateReq
}
if err = ctx.ShouldBind(&q); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, err)
return
}
if q.VersionRange.Major != "" && q.VersionRange.Minor != "" {
major, _ := version.New(q.VersionRange.Major)
minor, _ := version.New(q.VersionRange.Minor)
if major.LT(minor) {
common.ServeJSON(ctx, stderr.ErrVersionRange, nil)
return
}
}
if q.SpecVersion != nil {
vmod, _ := versionmod.FindOneByID(q.ID)
if vmod != nil {
vname, _ := version.New(vmod.VersionName)
spc, _ := version.New(*q.SpecVersion)
if vname.GTE(spc) {
common.ServeJSON(ctx, stderr.ErrVersionTooLow, nil)
return
}
}
}
if err = versionmod.Update(q.ID, q.VersionUpdateReq); err != nil {
common.ServeJSON(ctx, stderr.ErrDbUpdateError, "")
return
}
log, _ := json.Marshal(q)
_ = operatorlgmod.RecordOperation(manager, constant.SystemManageVersion, constant.Modify, string(log), ctx.Request.URL.RequestURI())
common.ServeJSON(ctx, stderr.Success, nil)
}
// Delete doc
// @Summary 删除
// @Description 删除
// @Tags product
// @Accept mpfd,json
// @Produce json,html
// @Param id formData int true "product等级""
// @Success 200 {string} json "{"msg": "操作成功"}"
// @Failure 400 {string} json "{"msg": "操作失败"}"
// @Router /web/ver [Delete]
func Delete(ctx *gin.Context) {
manager, err := common.GetAdminAct(ctx)
if err != nil {
common.ServeJSON(ctx, stderr.AdminIDErr, err.Error())
return
}
var p struct {
ID primitive.ObjectID `json:"id" form:"id" binding:"required"`
}
if err = ctx.ShouldBind(&p); err != nil {
common.ServeJSON(ctx, stderr.ErrParamError, nil)
return
}
if err = versionmod.Delete(p.ID); err != nil {
common.ServeJSON(ctx, stderr.ErrDbDeleteError, "")
return
}
log, _ := json.Marshal(p)
_ = operatorlgmod.RecordOperation(manager, constant.SystemManageVersion, constant.Delete, string(log), ctx.Request.URL.RequestURI())
common.ServeJSON(ctx, stderr.Success, nil)
}