|
@@ -1,6 +1,10 @@
|
|
|
package model
|
|
|
|
|
|
import (
|
|
|
+ "database/sql/driver"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "gorm.io/gorm"
|
|
|
"project_management/app/e"
|
|
|
"project_management/global"
|
|
|
"project_management/unity"
|
|
@@ -12,27 +16,55 @@ import (
|
|
|
type Apply struct {
|
|
|
//gorm.Model
|
|
|
utils.BaseModel
|
|
|
- AppID string `gorm:"type:varchar(50);not null;unique" json:"app_id"` // 应用id
|
|
|
- UserId int `gorm:"type:int;" json:"user_id"` // 用户id
|
|
|
- UserName string `gorm:"type:varchar(50);" json:"user_name"` // 用户名
|
|
|
- AppName string `gorm:"type:varchar(50);index:idx_name,unique" json:"app_name" validate:"required" min:"3" max:"20"` // 应用名称
|
|
|
- AppDescription string `gorm:"type:varchar(50);" json:"app_description" validate:"required"` // 应用描述
|
|
|
- CertificationTime utils.Time `gorm:"type:datetime;" json:"certification_time"` // 认证到期时间
|
|
|
- State int `gorm:"type:int;" json:"state"` // 状态 1 正常 2 停用 3 过期 4 禁用
|
|
|
- Icon string `gorm:"type:varchar(50);" json:"icon"` // 应用图标
|
|
|
- StartupDiagramPc string `gorm:"type:varchar(50);" json:"startup_diagram_pc"` // 启动图pc
|
|
|
- StartupDiagramMobile string `gorm:"type:varchar(50);" json:"startup_diagram_mobile"` // 启动图移动
|
|
|
- LoginMode int `gorm:"type:int;" json:"login_mode"` // 登录模式 1 公开注册 2禁止注册
|
|
|
- LoginMethod int `gorm:"type:int;" json:"login_method"` // 登录方式 1 短信登录 2 微信登录
|
|
|
- BackgroundImage string `gorm:"type:varchar(50);" json:"background_image"` // 背景图
|
|
|
- BackgroundImageObscure int `gorm:"type:int;" json:"background_image_obscure"` // 背景图模糊度
|
|
|
+ AppID string `gorm:"type:varchar(50);not null;unique" json:"app_id"` // 应用id
|
|
|
+ UserId int `gorm:"type:int;" json:"user_id"` // 用户id
|
|
|
+ UserName string `gorm:"type:varchar(50);" json:"user_name"` // 用户名
|
|
|
+ AppName string `gorm:"type:varchar(50);index:idx_name,unique" json:"app_name" validate:"required" min:"3" max:"20"` // 应用名称
|
|
|
+ AppDescription string `gorm:"type:varchar(255);" json:"app_description" validate:"required"` // 应用描述
|
|
|
+ CertificationTime utils.Time `gorm:"type:datetime;" json:"certification_time"` // 认证到期时间
|
|
|
+ State int `gorm:"type:int;" json:"state"` // 状态 1 正常 2 停用 3 过期 4 禁用
|
|
|
+ Icon string `gorm:"type:varchar(255);" json:"icon"` // 应用图标
|
|
|
+ StartupDiagramPc string `gorm:"type:varchar(255);" json:"startup_diagram_pc"` // 启动图pc
|
|
|
+ StartupDiagramMobile string `gorm:"type:varchar(255);" json:"startup_diagram_mobile"` // 启动图移动
|
|
|
+ LoginMode int `gorm:"type:int;" json:"login_mode"` // 注册模式 1 公开注册 2禁止注册
|
|
|
+ LoginMethod LoginMethod `gorm:"type:json" json:"login_method"` // 登录方式 1 短信 2 微信登录
|
|
|
+ BackgroundImagePc string `gorm:"type:varchar(255);" json:"background_image_pc"` // 背景图pc
|
|
|
+ BackgroundImageMobile string `gorm:"type:varchar(255);" json:"background_image_mobile"` // 背景图移动
|
|
|
+ BackgroundImageObscure float32 `gorm:"type:double;" json:"background_image_obscure"` // 背景图模糊度
|
|
|
+ TopicPC int `gorm:"type:int;" json:"topic_pc"` // 主题pc
|
|
|
+ TopicMobile int `gorm:"type:int;" json:"topic_mobile"` // 主题移动
|
|
|
+ Caps string `gorm:"type:varchar(255);" json:"caps"` // 应用能力
|
|
|
}
|
|
|
|
|
|
+type LoginMethod []int
|
|
|
type AppDto struct {
|
|
|
Apply
|
|
|
AppUserCount int64 `json:"app_user_count"`
|
|
|
}
|
|
|
+type ApplyCapabilities struct {
|
|
|
+ AppID string `json:"app_id" validate:"required"`
|
|
|
+ CapID string `json:"cap_id" validate:"required"`
|
|
|
+}
|
|
|
|
|
|
+func (lo LoginMethod) Value() (driver.Value, error) {
|
|
|
+ return json.Marshal(lo)
|
|
|
+}
|
|
|
+func (fn *LoginMethod) Scan(src interface{}) error {
|
|
|
+ if src == nil {
|
|
|
+ *fn = make(LoginMethod, 0)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ var u []byte
|
|
|
+ switch v := src.(type) {
|
|
|
+ case string:
|
|
|
+ u = []byte(v)
|
|
|
+ case []byte:
|
|
|
+ u = v
|
|
|
+ default:
|
|
|
+ return fmt.Errorf("unsupported type: %T", src)
|
|
|
+ }
|
|
|
+ return json.Unmarshal(u, (*[]int)(fn))
|
|
|
+}
|
|
|
func (a Apply) GetApplyAminList(params unity.QueryPageParams, apply Apply, queryCond string) (result []AppDto, total int64, err error) {
|
|
|
//TODO implement me
|
|
|
query := global.DBLink.Table(apply.TableName())
|
|
@@ -103,50 +135,89 @@ func (a Apply) UserUpdateApply(apply Apply) e.Rescode {
|
|
|
return e.ERROR
|
|
|
}
|
|
|
|
|
|
+// func (a Apply) GetApplyList(params unity.QueryPageParams, apply Apply, queryCond string) (result []Apply, total int64, err error) {
|
|
|
+// var count int64
|
|
|
+// if params.Query != "%%" && params.State != "" {
|
|
|
+// if err = global.DBLink.Model(apply).Where(queryCond, params.Query).Where("user_id=?", apply.UserId).Count(&count).Error; err != nil {
|
|
|
+// return nil, 0, err
|
|
|
+// }
|
|
|
+// // 计算查询的偏移量,并设置每次查询的记录数量
|
|
|
+// offset := (params.Page - 1) * params.Size
|
|
|
+// // 执行分页查询,包括偏移量设置、限制查询数量、排序及应用额外查询条件
|
|
|
+// if err = global.DBLink.Offset(offset).Limit(params.Size).Order(params.Desc).Where(queryCond, params.Query).Where("user_id=?", apply.UserId).Find(&result).Error; err != nil {
|
|
|
+// return nil, 0, err
|
|
|
+// }
|
|
|
+// } else if params.State != "" && params.Query == "%%" {
|
|
|
+// if err = global.DBLink.Model(apply).Where("state=?", params.State).Where("user_id=?", apply.UserId).Count(&count).Error; err != nil {
|
|
|
+// return nil, 0, err
|
|
|
+// }
|
|
|
+// // 计算查询的偏移量,并设置每次查询的记录数量
|
|
|
+// offset := (params.Page - 1) * params.Size
|
|
|
+// // 执行分页查询,包括偏移量设置、限制查询数量、排序及应用额外查询条件
|
|
|
+// if err = global.DBLink.Offset(offset).Limit(params.Size).Order(params.Desc).Where("state=?", params.State).Where("user_id=?", apply.UserId).Find(&result).Error; err != nil {
|
|
|
+// return nil, 0, err
|
|
|
+// }
|
|
|
+// } else if params.State != "" && params.Query != "%%" {
|
|
|
+// if err = global.DBLink.Model(apply).Where(queryCond, params.Query).Where("state=?", params.State).Where("user_id=?", apply.UserId).Count(&count).Error; err != nil {
|
|
|
+// return nil, 0, err
|
|
|
+// }
|
|
|
+// // 计算查询的偏移量,并设置每次查询的记录数量
|
|
|
+// offset := (params.Page - 1) * params.Size
|
|
|
+// // 执行分页查询,包括偏移量设置、限制查询数量、排序及应用额外查询条件
|
|
|
+// if err = global.DBLink.Offset(offset).Limit(params.Size).Order(params.Desc).Where(queryCond, params.Query).Where("state=?", params.State).Where("user_id=?", apply.UserId).Find(&result).Error; err != nil {
|
|
|
+// return nil, 0, err
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// if err = global.DBLink.Model(apply).Where("user_id=?", apply.UserId).Count(&count).Error; err != nil {
|
|
|
+// return nil, 0, err
|
|
|
+// }
|
|
|
+// // 计算查询的偏移量,并设置每次查询的记录数量
|
|
|
+// offset := (params.Page - 1) * params.Size
|
|
|
+// // 执行分页查询,包括偏移量设置、限制查询数量、排序及应用额外查询条件
|
|
|
+// if err = global.DBLink.Where("user_id=?", apply.UserId).Offset(offset).Limit(params.Size).Order(params.Desc).Find(&result).Error; err != nil {
|
|
|
+// return nil, 0, err
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return result, count, nil
|
|
|
+// }
|
|
|
func (a Apply) GetApplyList(params unity.QueryPageParams, apply Apply, queryCond string) (result []Apply, total int64, err error) {
|
|
|
- var count int64
|
|
|
- if params.Query != "%%" && params.State != "" {
|
|
|
- if err = global.DBLink.Model(apply).Where(queryCond, params.Query).Where("user_id=?", apply.UserId).Count(&count).Error; err != nil {
|
|
|
- return nil, 0, err
|
|
|
- }
|
|
|
- // 计算查询的偏移量,并设置每次查询的记录数量
|
|
|
- offset := (params.Page - 1) * params.Size
|
|
|
- // 执行分页查询,包括偏移量设置、限制查询数量、排序及应用额外查询条件
|
|
|
- if err = global.DBLink.Offset(offset).Limit(params.Size).Order(params.Desc).Where(queryCond, params.Query).Where("user_id=?", apply.UserId).Find(&result).Error; err != nil {
|
|
|
- return nil, 0, err
|
|
|
- }
|
|
|
- } else if params.State != "" && params.Query == "%%" {
|
|
|
- if err = global.DBLink.Model(apply).Where("state=?", params.State).Where("user_id=?", apply.UserId).Count(&count).Error; err != nil {
|
|
|
- return nil, 0, err
|
|
|
- }
|
|
|
- // 计算查询的偏移量,并设置每次查询的记录数量
|
|
|
- offset := (params.Page - 1) * params.Size
|
|
|
- // 执行分页查询,包括偏移量设置、限制查询数量、排序及应用额外查询条件
|
|
|
- if err = global.DBLink.Offset(offset).Limit(params.Size).Order(params.Desc).Where("state=?", params.State).Where("user_id=?", apply.UserId).Find(&result).Error; err != nil {
|
|
|
- return nil, 0, err
|
|
|
- }
|
|
|
- } else if params.State != "" && params.Query != "%%" {
|
|
|
- if err = global.DBLink.Model(apply).Where(queryCond, params.Query).Where("state=?", params.State).Where("user_id=?", apply.UserId).Count(&count).Error; err != nil {
|
|
|
- return nil, 0, err
|
|
|
- }
|
|
|
- // 计算查询的偏移量,并设置每次查询的记录数量
|
|
|
- offset := (params.Page - 1) * params.Size
|
|
|
- // 执行分页查询,包括偏移量设置、限制查询数量、排序及应用额外查询条件
|
|
|
- if err = global.DBLink.Offset(offset).Limit(params.Size).Order(params.Desc).Where(queryCond, params.Query).Where("state=?", params.State).Where("user_id=?", apply.UserId).Find(&result).Error; err != nil {
|
|
|
- return nil, 0, err
|
|
|
- }
|
|
|
- } else {
|
|
|
- if err = global.DBLink.Model(apply).Where("user_id=?", apply.UserId).Count(&count).Error; err != nil {
|
|
|
- return nil, 0, err
|
|
|
- }
|
|
|
- // 计算查询的偏移量,并设置每次查询的记录数量
|
|
|
- offset := (params.Page - 1) * params.Size
|
|
|
- // 执行分页查询,包括偏移量设置、限制查询数量、排序及应用额外查询条件
|
|
|
- if err = global.DBLink.Where("user_id=?", apply.UserId).Offset(offset).Limit(params.Size).Order(params.Desc).Find(&result).Error; err != nil {
|
|
|
- return nil, 0, err
|
|
|
- }
|
|
|
+ var conditions []interface{}
|
|
|
+ var whereClauses []string
|
|
|
+
|
|
|
+ // 基础条件:按用户ID查询
|
|
|
+ whereClauses = append(whereClauses, "user_id = ?")
|
|
|
+ conditions = append(conditions, apply.UserId)
|
|
|
+
|
|
|
+ // 添加状态查询条件
|
|
|
+ if params.State != "" {
|
|
|
+ whereClauses = append(whereClauses, "state = ?")
|
|
|
+ conditions = append(conditions, params.State)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加自定义查询条件,如果提供且不为默认值
|
|
|
+ if params.Query != "%%" {
|
|
|
+ whereClauses = append(whereClauses, queryCond)
|
|
|
+ conditions = append(conditions, params.Query)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算总数
|
|
|
+ if err = global.DBLink.Model(apply).Where(strings.Join(whereClauses, " AND "), conditions...).Count(&total).Error; err != nil {
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 分页查询准备
|
|
|
+ offset := (params.Page - 1) * params.Size
|
|
|
+
|
|
|
+ // 执行分页查询
|
|
|
+ if err = global.DBLink.Model(apply).
|
|
|
+ Where(strings.Join(whereClauses, " AND "), conditions...).
|
|
|
+ Offset(offset).
|
|
|
+ Limit(params.Size).
|
|
|
+ Order(params.Desc).
|
|
|
+ Find(&result).Error; err != nil {
|
|
|
+ return nil, 0, err
|
|
|
}
|
|
|
- return result, count, nil
|
|
|
+ return result, total, nil
|
|
|
}
|
|
|
|
|
|
func (a Apply) AddApply(apply Apply) e.Rescode {
|
|
@@ -156,6 +227,9 @@ func (a Apply) AddApply(apply Apply) e.Rescode {
|
|
|
tiem := time.Now().AddDate(0, 0, 365)
|
|
|
apply.CertificationTime = utils.Time(tiem)
|
|
|
apply.State = 1
|
|
|
+ apply.BackgroundImageObscure = 0.5
|
|
|
+ apply.TopicPC = 1
|
|
|
+ apply.TopicMobile = 1
|
|
|
tx := global.DBLink.Create(&apply)
|
|
|
if tx.Error != nil {
|
|
|
errMsg := tx.Error.Error()
|
|
@@ -166,7 +240,7 @@ func (a Apply) AddApply(apply Apply) e.Rescode {
|
|
|
if tx.RowsAffected > 0 {
|
|
|
return e.SUCCESS
|
|
|
}
|
|
|
- return e.SUCCESS
|
|
|
+ return e.INSERTFAIL
|
|
|
}
|
|
|
|
|
|
// AppIdISRepeat 检查id是否重复
|
|
@@ -190,3 +264,50 @@ func IsRegist(appid string) bool {
|
|
|
}
|
|
|
return false
|
|
|
}
|
|
|
+
|
|
|
+// ApplyAddCap 添加应用能力
|
|
|
+func (a Apply) ApplyAddCap(applycap ApplyCapabilities) e.Rescode {
|
|
|
+ var caps Capabilities
|
|
|
+
|
|
|
+ tx := global.DBLink.Begin()
|
|
|
+
|
|
|
+ if err := tx.Table(a.TableName()).
|
|
|
+ Where("app_id = ?", applycap.AppID).
|
|
|
+ Update("caps", applycap.CapID).Error; err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ return e.INSERTFAIL
|
|
|
+ }
|
|
|
+
|
|
|
+ split := strings.Split(applycap.CapID, ",")
|
|
|
+
|
|
|
+ for _, v := range split {
|
|
|
+ if err := tx.Table(caps.TableName()).Where("cap_id = ?", v).
|
|
|
+ Update("count", gorm.Expr("count + ?", 1)).
|
|
|
+ Update("updated_at", utils.Time(time.Now())).Error; err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ return e.INSERTFAIL
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := tx.Commit().Error; err != nil {
|
|
|
+ return e.INSERTFAIL
|
|
|
+ }
|
|
|
+ return e.SUCCESS
|
|
|
+}
|
|
|
+
|
|
|
+func (a Apply) UpDateApplyCap(applycap ApplyCapabilities) e.Rescode {
|
|
|
+ //TODO implement me
|
|
|
+ begin := global.DBLink.Begin()
|
|
|
+
|
|
|
+ begin.Table(a.TableName()).Where("app_id = ?", applycap.AppID).First(&a)
|
|
|
+ if a.Caps == applycap.CapID {
|
|
|
+
|
|
|
+ }
|
|
|
+ if err := begin.Table(a.TableName()).
|
|
|
+ Where("app_id = ?", applycap.AppID).
|
|
|
+ Update("caps", applycap.CapID).Error; err != nil {
|
|
|
+ begin.Rollback()
|
|
|
+ return e.UPDATEFAIL
|
|
|
+ }
|
|
|
+ return e.UPDATEFAIL
|
|
|
+}
|