init: initial commit

This commit is contained in:
Blizzard
2026-02-06 14:44:06 +08:00
commit 3115b58cb2
133 changed files with 25889 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
package request
import (
"gorm.io/gorm"
)
// PageInfo Paging common input parameter structure
type PageInfo struct {
Current int `json:"current" form:"current"` // 页码
PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
Keyword string `json:"keyword" form:"keyword"` // 关键字
}
func (r *PageInfo) Paginate() func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
if r.Current <= 0 {
r.Current = 1
}
switch {
case r.PageSize > 100:
r.PageSize = 100
case r.PageSize <= 0:
r.PageSize = 10
}
offset := (r.Current - 1) * r.PageSize
return db.Offset(offset).Limit(r.PageSize)
}
}
// GetById Find by id structure
type GetById struct {
ID string `json:"id" form:"id"` // 主键ID
}
func (r *GetById) Uint() string {
return string(r.ID)
}
type IdsReq struct {
Ids []string `json:"ids" form:"ids"`
}
// GetAuthorityId Get role by id structure
type GetAuthorityId struct {
AuthorityId string `json:"authorityId" form:"authorityId"` // 角色ID
}
type Empty struct{}
type UploadOss struct {
Id string `json:"id" binding:"required"` //数据主键
OssIds []string `json:"ossIds" binding:"required"` // ossIds
}
type DeleteOss struct {
Id string `json:"id" binding:"required"` //数据主键
OssIds []string `json:"ossIds" binding:"required"`
}
type UploadFile struct {
Id string `json:"id" binding:"required"` //数据主键
OssId string `json:"ossIds" binding:"required"` // ossId
}
+12
View File
@@ -0,0 +1,12 @@
package response
type PageResult struct {
List interface{} `json:"list"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}
type ListResult struct {
List interface{} `json:"list"`
}
+60
View File
@@ -0,0 +1,60 @@
package response
import (
"github.com/gin-gonic/gin"
"net/http"
)
type Response struct {
Code int `json:"code"`
Data interface{} `json:"data"`
Msg string `json:"msg"`
}
const (
SUCCESS = 200
ERROR = 7
)
// Result 返回结果
func Result(code int, data interface{}, msg string, c *gin.Context) {
c.JSON(http.StatusOK, Response{
code,
data,
msg,
})
}
// Ok 成功返回
func Ok(c *gin.Context) {
Result(SUCCESS, map[string]interface{}{}, "操作成功", c)
}
// OkWithData 带数据成功返回
func OkWithData(data interface{}, c *gin.Context) {
Result(SUCCESS, data, "操作成功", c)
}
// OkWithMsg 带信息成功返回
func OkWithMsg(msg string, c *gin.Context) {
Result(SUCCESS, map[string]interface{}{}, msg, c)
}
// Fail 失败返回
func Fail(code int, msg string, c *gin.Context) {
Result(code, map[string]interface{}{}, "操作失败", c)
}
// FailWithMsg 带信息失败返回
func FailWithMsg(msg string, c *gin.Context) {
Result(ERROR, map[string]interface{}{}, msg, c)
}
// NoAuth 未授权返回
func NoAuth(message string, c *gin.Context) {
c.JSON(http.StatusUnauthorized, Response{
7,
nil,
message,
})
}
+50
View File
@@ -0,0 +1,50 @@
package plant
import (
"sundynix-go/global"
"sundynix-go/model/system"
"sundynix-go/utils/timer"
"time"
"gorm.io/gorm"
)
// MyPlant 我的植物
type MyPlant struct {
global.BaseModel
UserId string `json:"userId" form:"userId" gorm:"size:50;column:user_id;comment:用户id"`
Name string `json:"name" form:"name" gorm:"size:20;column:name;comment:名称"`
PlantTime time.Time `json:"plantTime" form:"plantTime" gorm:"column:plant_time;comment:种植时间"`
Status int `json:"status" form:"status" gorm:"column:status;comment:生长状态"`
Placement string `json:"placement" form:"placement" gorm:"size:50;column:placement;comment:摆放位置"`
PotMaterial string `json:"potMaterial" form:"potMaterial" gorm:"column:pot_material;size:50;comment:花盆材质"`
PotSize string `json:"potSize" form:"potSize" gorm:"column:pot_size;size:50;comment:花盆大小"` // 花盆大小 如直径 20cm × 高度 18cm
Sunlight string `json:"sunlight" form:"sunlight" gorm:"column:sunlight;size:50;comment:光照条件"` // 如每日12小时
PlantingMaterial string `json:"plantingMaterial" form:"plantingMaterial" gorm:"column:planting_material;size:50;comment:植料"`
ImgList []*system.Oss `json:"imgList" form:"imgList" gorm:"many2many:my_plant_oss;comment:图片列表"`
CarePlans []*CarePlan `json:"carePlans" form:"carePlans" gorm:"foreignKey:PlantId;comment:养护计划"`
CareRecords []*CareRecord `json:"careRecords" form:"careRecords" gorm:"foreignKey:PlantId;comment:养护记录"`
}
// AfterCreate 钩子函数 创建plant时自动创建careTask
func (p *MyPlant) AfterCreate(tx *gorm.DB) (err error) {
today := timer.GetZeroTime()
for _, v := range p.CarePlans {
dueDate := today.AddDate(0, 0, v.Period)
task := CareTask{
UserId: p.UserId,
PlantId: p.Id,
PlanId: v.Id,
Name: v.Name,
Icon: v.Icon,
DueDate: dueDate,
Status: 1,
}
err = tx.Create(&task).Error
if err != nil {
return err
}
}
return
}
+15
View File
@@ -0,0 +1,15 @@
package plant
import (
"sundynix-go/global"
)
// CarePlan 养护计划
type CarePlan struct {
global.BaseModel
UserId string `json:"userId" form:"userId" gorm:"size:50;column:user_id;comment:用户id"`
PlantId string `json:"plantId" form:"plantId" gorm:"size:50;column:plant_id;comment:植物id"`
Icon string `json:"icon" form:"icon" gorm:"type:text;"`
Name string `json:"name"`
Period int `json:"period" form:"period" gorm:"column:period;comment:周期"`
}
+13
View File
@@ -0,0 +1,13 @@
package plant
import "sundynix-go/global"
type CareRecord struct {
global.BaseModel
UserId string `json:"userId" form:"userId" gorm:"size:50;column:user_id;comment:用户id"`
PlantId string `json:"plantId" form:"plantId" gorm:"index;size:50;column:plant_id;comment:植物id"`
PlanId string `json:"planId" form:"plantId" gorm:"index;column:plan_id;comment:计划id"`
Name string `json:"name" form:"name" gorm:"column:name"`
Remark string `json:"remark" form:"remark" gorm:"column:remark"`
Icon string `json:"icon" form:"icon" gorm:"type:text;column:icon"`
}
+18
View File
@@ -0,0 +1,18 @@
package plant
import (
"sundynix-go/global"
"time"
)
type CareTask struct {
global.BaseModel
PlantId string `json:"plantId" gorm:"index"`
PlanId string `json:"planId" gorm:"index"`
UserId string `json:"userId" gorm:"index"`
Name string `json:"name"`
Icon string `json:"icon" gorm:"type:text"`
DueDate time.Time `json:"dueDate"` // 应做时间(用于判断逾期)
CompletedAt *time.Time `json:"completedAt" gorm:"column:completed_at"` // 完成时间(为nil表示未完成)
Status int `json:"status"` // 1:待执行 2:已完成 3:已跳过
}
+36
View File
@@ -0,0 +1,36 @@
package request
type CarePlan struct {
Icon string `json:"icon"` // icon信息
Name string `json:"name"` // 农事名称
Period int `json:"period"` // 周期
}
// CreateMyPlant 创建植物
type CreateMyPlant struct {
Name string `json:"name"` // 植物名称
PlantTime string `json:"plantTime"` // 种植时间
PotMaterial string `json:"potMaterial"` //花盆材质
PotSize string `json:"potSize"` // 花盆大小 如直径 20cm × 高度 18cm
Placement string `json:"placement"` //摆放位置
Sunlight string `json:"sunlight"` //光照条件如每日12小时
PlantingMaterial string `json:"plantingMaterial"` //植料(即土的材质)
OssIds []string `json:"ossIds"` // 图片ids
CarePlans []*CarePlan `json:"carePlans"` // 养护计划
}
// UpdateMyPlant 修改植物
type UpdateMyPlant struct {
Id string `json:"id" binding:"required"`
Name string `json:"name"` // 植物名称
PotMaterial string `json:"potMaterial"` // 花盆材质
PotSize string `json:"potSize"` // 花盆大小 如直径 20cm × 高度 18cm
Placement string `json:"placement"` // 摆放位置
Sunlight string `json:"sunlight"` // 光照条件如每日12小时
PlantingMaterial string `json:"plantingMaterial"` // 植料(即土的材质)
}
type CompleteTask struct {
TaskId string `json:"taskId" binding:"required"`
Remark string `json:"remark"`
}
+6
View File
@@ -0,0 +1,6 @@
package response
//type BadgeGroup struct {
// CategoryName string `json:"categoryName" comment:"分类名称"`
// BadgeList []plant.Badge `json:"badgeList"`
//}
+12
View File
@@ -0,0 +1,12 @@
package response
import (
"sundynix-go/model/plant"
)
// PlantTaskVO 植物任务
type PlantTaskVO struct {
MyPlant *plant.MyPlant
HasExpired bool `json:"hasExpired"`
Tasks []*plant.CareTask `json:"tasks"`
}
+22
View File
@@ -0,0 +1,22 @@
package response
// BaikeInfo 植物百科信息(baike_info子对象)
type BaikeInfo struct {
BaikeUrl string `json:"baike_url"` // 百度百科链接
ImageUrl string `json:"image_url"` // 植物图片链接
Description string `json:"description"` // 植物百科描述文本
}
// ResultItem 识别结果项(result数组中的单个元素)
type ResultItem struct {
Score float64 `json:"score"` // 匹配相似度得分(0-1
Name string `json:"name"` // 植物名称
BaikeInfo *BaikeInfo `json:"baike_info"` // 植物百科信息(部分结果可能无此字段,用指针避免空值解析问题)
}
// PlantRecognitionResponse 植物识别接口的HTTP响应结构体
// 字段标签仅保留 json,严格匹配返回的JSON字段名
type PlantRecognitionResponse struct {
LogId uint64 `json:"log_id"` // 识别请求日志ID(唯一标识)
Result []ResultItem `json:"result"` // 植物识别结果列表
}
+17
View File
@@ -0,0 +1,17 @@
package system
import (
"sundynix-go/global"
)
type Oss struct {
global.BaseModel
Name string `json:"name" form:"name" gorm:"column:name;comment:文件名"`
Url string `json:"url" form:"url" gorm:"column:url;comment:文件地址"`
Tag string `json:"tag" form:"tag" gorm:"column:tag;comment:文件标签"`
Key string `json:"key" form:"key" gorm:"column:key;comment:文件key"`
Suffix string `json:"suffix" form:"suffix" gorm:"column:suffix;comment:文件后缀"`
MD5 string `json:"md5" form:"md5" gorm:"column:md5;comment:文件md5"`
Height int `json:"height" form:"height" gorm:"column:height;comment:图片高度"`
Width int `json:"width" form:"width" gorm:"column:width;comment:图片宽度"`
}
+15
View File
@@ -0,0 +1,15 @@
package request
import "github.com/mojocn/base64Captcha"
// configJsonBody json request body.
type CaptchaReqBody struct {
Id string
CaptchaType string
VerifyValue string
DriverAudio *base64Captcha.DriverAudio
DriverString *base64Captcha.DriverString
DriverChinese *base64Captcha.DriverChinese
DriverMath *base64Captcha.DriverMath
DriverDigit *base64Captcha.DriverDigit
}
+18
View File
@@ -0,0 +1,18 @@
package request
import (
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
)
type CustomClaims struct {
BaseClaims
BufferTime int64
jwt.RegisteredClaims
}
type BaseClaims struct {
UUID uuid.UUID
ID string
Account string
}
+8
View File
@@ -0,0 +1,8 @@
package request
import common "sundynix-go/model/commom/request"
type GetOssFileList struct {
common.PageInfo
Name string `json:"name" form:"name"`
}
+9
View File
@@ -0,0 +1,9 @@
package request
import common "sundynix-go/model/commom/request"
type GetClientList struct {
common.PageInfo
ClientId string `json:"clientId" form:"clientId"`
Name string `json:"name" form:"name"`
}
+6
View File
@@ -0,0 +1,6 @@
package request
type GetMenuTree struct {
Category int `json:"category" form:"category"`
ParentId string `json:"parentId" form:"parentId"`
}
@@ -0,0 +1,14 @@
package request
import (
common "sundynix-go/model/commom/request"
)
type GetOperationRecordList struct {
common.PageInfo
Ip string `json:"ip" form:"ip"`
Method string `json:"method" form:"method"`
Path string `json:"path" form:"path"`
UserId string `json:"userId" form:"userId"`
Status int `json:"status" form:"status"`
}
+14
View File
@@ -0,0 +1,14 @@
package request
import common "sundynix-go/model/commom/request"
type GetRoleList struct {
common.PageInfo
Code string `json:"code" form:"code"`
Name string `json:"name" form:"name"`
}
type GrantMenu struct {
RoleId string `json:"roleId"`
MenuIds []string `json:"menuIds"`
}
+26
View File
@@ -0,0 +1,26 @@
package request
import common "sundynix-go/model/commom/request"
type Login struct {
Account string `json:"account"`
Password string `json:"password"`
Captcha string `json:"captcha"`
CaptchaId string `json:"captchaId"`
}
type GetUserList struct {
common.PageInfo
Account string `json:"account" form:"account"`
Phone string `json:"phone" form:"phone"`
}
type ChangePwd struct {
Id string `json:"id"`
NewPwd string `json:"newPwd"`
}
type GrantRole struct {
UserId string `json:"userId"`
RoleIds []string `json:"roleIds"`
}
@@ -0,0 +1,9 @@
package response
type WxCode2SessionResp struct {
SessionKey string `json:"session_key"`
Unionid string `json:"unionid"`
Openid string `json:"openid"`
Errcode int32 `json:"errcode"`
Errmsg string `json:"errmsg"`
}
+7
View File
@@ -0,0 +1,7 @@
package response
import "sundynix-go/model/system"
type UploadFileResponse struct {
File system.Oss `json:"file"`
}
+6
View File
@@ -0,0 +1,6 @@
package response
type CaptchaRes struct {
CaptchaId string `json:"captchaId"`
Captcha string `json:"captcha"`
}
+9
View File
@@ -0,0 +1,9 @@
package response
import "sundynix-go/model/system"
type LoginResponse struct {
User system.User `json:"user"`
Token string `json:"token"`
ExpiresAt int64 `json:"expiresAt"`
}
+12
View File
@@ -0,0 +1,12 @@
package system
import "sundynix-go/global"
type Client struct {
global.BaseModel
ClientId string `gorm:"size:20;" json:"clientId"`
Name string `gorm:"size:50;" json:"name"`
GrantType string `gorm:"size:50;" json:"grantType"`
AdditionalInfo string `gorm:"type:text" json:"additionalInfo"`
ActiveTimeout int64 `json:"activeTimeout"`
}
+17
View File
@@ -0,0 +1,17 @@
package system
import "sundynix-go/global"
type Menu struct {
global.BaseModel
ParentId string `gorm:"size:100;default:'0'" json:"parentId" form:"parentId"`
Category int `json:"category" form:"category"`
Name string `gorm:"size:20" json:"name" form:"name"`
Title string `gorm:"size:20" json:"title" form:"title"`
Code string `gorm:"size:20" json:"code" form:"code"`
Permission string `gorm:"size:20" json:"permission" form:"permission"`
Locale string `gorm:"size:50" json:"locale" form:"locale"`
Icon string `gorm:"size:20" json:"icon" form:"icon"`
Sort int `json:"sort" form:"sort"`
Children []*Menu `json:"children" gorm:"-"`
}
+21
View File
@@ -0,0 +1,21 @@
package system
import (
"sundynix-go/global"
"time"
)
type SysOperationRecord struct {
global.BaseModel
Ip string `json:"ip" form:"ip" gorm:"column:ip;comment:请求ip"` // 请求ip
Method string `json:"method" form:"method" gorm:"column:method;comment:请求方法"` // 请求方法
Path string `json:"path" form:"path" gorm:"column:path;comment:请求路径"` // 请求路径
Status int `json:"status" form:"status" gorm:"column:status;comment:请求状态"` // 请求状态
Latency time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:延迟" swaggertype:"string"` // 延迟
Agent string `json:"agent" form:"agent" gorm:"type:text;column:agent;comment:代理"` // 代理
ErrorMessage string `json:"erroMessage" form:"error_message" gorm:"column:error_message;comment:错误信息"` // 错误信息
Body string `json:"body" form:"body" gorm:"type:text;column:body;comment:请求Body"` // 请求Body
Resp string `json:"resp" form:"resp" gorm:"type:text;column:resp;comment:响应Body"` // 响应Body
UserId string `json:"userId" form:"user_id" gorm:"column:user_id;comment:用户id"` // 用户id
User User `json:"user"`
}
+11
View File
@@ -0,0 +1,11 @@
package system
import "sundynix-go/global"
type Role struct {
global.BaseModel
Name string `gorm:"size:20" json:"name" form:"name"`
Code string `gorm:"size:20" json:"code" form:"code"`
Sort int `json:"sort" form:"sort"`
Menus []*Menu `gorm:"many2many:role_menu;"`
}
+6
View File
@@ -0,0 +1,6 @@
package system
type RoleMenu struct {
RoleId string `json:"roleId" gorm:"size:100;column:role_id;comment:角色id"`
MenuId string `json:"menuId" gorm:"size:100;column:menu_id;comment:菜单id"`
}
+38
View File
@@ -0,0 +1,38 @@
package system
import (
"sundynix-go/global"
)
type Login interface {
GetAccount() string
GetUserId() string
GetUserInfo() any
}
type User struct {
global.BaseModel
TenantId string `gorm:"size:20;" json:"tenantId" form:"tenantId"`
ClientId string `gorm:"size:20;" json:"clientId"`
Name string `gorm:"size:20" json:"name" form:"name"`
Account string `gorm:"size:11;" json:"account" form:"account"`
Password string `gorm:"size:100;" json:"-" form:"password"`
NickName string `gorm:"size:20;column:nick_name" json:"nickName" form:"nickName"`
Phone string `gorm:"size:20;column:phone" json:"phone" form:"phone"`
SessionKey string `gorm:"size:80;column:session_key" json:"sessionKey" form:"sessionKey"`
UnionId string `gorm:"size:80;column:union_id" json:"unionId"`
MiniOpenId string `gorm:"size:80;column:mini_open_id" json:"miniOpenId" form:"miniOpenId"`
SaOpenId string `gorm:"size:80;column:sa_open_id" json:"saOpenId"`
AvatarId string `gorm:"size:50;column:avatar_id" json:"avatarId"`
Avatar *Oss `gorm:"foreignKey:AvatarId" json:"avatar"`
}
func (u *User) GetAccount() string {
return u.Account
}
func (u *User) GetUserId() string {
return u.Id
}
func (u *User) GetUserInfo() any {
return *u
}
+6
View File
@@ -0,0 +1,6 @@
package system
type UserRole struct {
UserId string `json:"userId" gorm:"size:100;column:user_id;comment:用户id"`
RoleId string `json:"roleId" gorm:"size:100;column:role_id;comment:角色id"`
}