Browse Source

应用能力配置

huangyan 9 months ago
parent
commit
7c996de268

+ 0 - 27
app/controller/admin/adminApply.go

@@ -1,27 +0,0 @@
-package admin
-
-import (
-	"github.com/gin-gonic/gin"
-	"project_management/app/e"
-	"project_management/app/model"
-	"project_management/unity"
-)
-
-// AdminApplyList 管理员获取所有应用列表
-func AdminApplyList(c *gin.Context) {
-	var params unity.QueryPageParams
-	if err := c.ShouldBindJSON(&params); err != nil {
-		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
-		return
-	}
-	queryCond := "app_name like ?"
-	params.Query = "%" + params.Query + "%"
-	result, total, err := unity.PaginateWithCondition(params, model.Apply{}, queryCond)
-	if err != nil {
-		e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
-		return
-	} else {
-		e.ResPonsePage(c, result, total, params)
-		return
-	}
-}

+ 24 - 18
app/controller/appUser.go

@@ -2,11 +2,12 @@ package controller
 
 import (
 	"github.com/gin-gonic/gin"
+	"github.com/go-playground/validator/v10"
 	"project_management/app/e"
 	"project_management/app/model"
 	"project_management/app/services"
 	"project_management/unity"
-	"strconv"
+	"strings"
 )
 
 var AppUser services.AppUser = &model.AppUser{}
@@ -37,8 +38,8 @@ func AddAppUser(c *gin.Context) {
 		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
 		return
 	}
-	//validate := validator.New()
-	err := unity.Validate.Struct(appuser)
+	validate := validator.New()
+	err := validate.Struct(appuser)
 	if err != nil {
 		e.ResponseWithMsg(c, e.JSONParsingFailed, err.Error())
 	}
@@ -62,7 +63,8 @@ func GetAppUserList(c *gin.Context) {
 		return
 	}
 	app_id := c.Query("app_id")
-	err := unity.Validate.Var(app_id, "required")
+	validate := validator.New()
+	err := validate.Var(app_id, "required")
 	if err != nil {
 		e.ResponseWithMsg(c, e.JSONParsingFailed, "缺少appid")
 		return
@@ -72,6 +74,10 @@ func GetAppUserList(c *gin.Context) {
 	params.Query = "%" + params.Query + "%"
 	result, total, err := AppUser.GetAppUserList(params, tableName, queryCond)
 	if err != nil {
+		if strings.Contains(err.Error(), "当前系统没有该表") {
+			e.ResponseWithMsg(c, e.SUCCESS, "当前用户为空")
+			return
+		}
 		e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
 		return
 	}
@@ -85,12 +91,12 @@ func UpdateAppUser(c *gin.Context) {
 		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
 		return
 	}
-	app_id := c.Query("app_id")
-	if err := unity.Validate.Var(app_id, "required"); err != nil {
-		e.ResponseWithMsg(c, e.JSONParsingFailed, "缺少appid")
+	validate := validator.New()
+	if err := validate.Struct(appuser); err != nil {
+		e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
 		return
 	}
-	tablename := "appuser_" + app_id
+	tablename := "appuser_" + appuser.AppID
 	user := AppUser.UpdateAppUser(appuser, tablename)
 	if user == e.SUCCESS {
 		e.ResponseSuccess(c, "")
@@ -101,23 +107,23 @@ func UpdateAppUser(c *gin.Context) {
 
 // DeleteAppUserByID 删除用户
 func DeleteAppUserByID(c *gin.Context) {
-	id := c.PostForm("id")
-	app_id := c.PostForm("app_id")
-	if err := unity.Validate.Var(id, "required"); err != nil {
-		e.ResponseWithMsg(c, e.JSONParsingFailed, "缺少id")
+	var deldate model.AppUserDel
+	err := c.ShouldBindJSON(&deldate)
+	if err != nil {
+		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
 		return
 	}
-	if err := unity.Validate.Var(app_id, "required"); err != nil {
-		e.ResponseWithMsg(c, e.JSONParsingFailed, "缺少appid")
-		return
+	validate := validator.New()
+	err = validate.Struct(deldate)
+	if err != nil {
+		e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
 	}
-	tablename := "appuser_" + app_id
-	atoi, err := strconv.Atoi(id)
+	tablename := "appuser_" + deldate.AppID
 	if err != nil {
 		e.ResponseWithMsg(c, e.JSONParsingFailed, "id格式错误")
 		return
 	}
-	byID := AppUser.DeleteAppUserByID(atoi, tablename)
+	byID := AppUser.DeleteAppUserByID(deldate.ID, tablename)
 	if byID == e.SUCCESS {
 		e.ResponseSuccess(c, "")
 		return

+ 2 - 3
app/controller/apply.go

@@ -37,14 +37,13 @@ func GetApplyList(c *gin.Context) {
 func GetApplyState(c *gin.Context) {
 	var params unity.QueryPageParams
 	var apply model.Apply
-	_, _, role := unity.GetUId(c)
+	uId, _, role := unity.GetUId(c)
 	if err := c.ShouldBindJSON(&params); err != nil {
 		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
 		return
 	}
 	queryCond := "app_name like ?"
 	params.Query = "%" + params.Query + "%"
-	uId, _, _ := unity.GetUId(c)
 	apply.UserId = uId
 	if role == "admin" {
 		result, total, err := Apply.GetApplyAminList(params, apply, queryCond)
@@ -116,7 +115,7 @@ func UserUpdateApply(c *gin.Context) {
 	apply.UserId = id
 	updateApply := Apply.UserUpdateApply(apply)
 	if updateApply != e.SUCCESS {
-		e.ResponseWithMsg(c, updateApply, updateApply.GetMsg())
+		e.ResponseWithMsg(c, updateApply, "更新失败")
 		return
 	}
 	e.ResponseSuccess(c, nil)

+ 90 - 0
app/controller/applyCap.go

@@ -0,0 +1,90 @@
+package controller
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/go-playground/validator/v10"
+	"project_management/app/e"
+	"project_management/app/model"
+	"project_management/app/services"
+)
+
+var ApplyCap services.ApplyCap = &model.ApplyCap{}
+
+// ApplyAddCap 添加应用能力
+func ApplyAddCap(c *gin.Context) {
+	var applyCap model.ApplyCapabilities
+	if err := c.ShouldBindJSON(&applyCap); err != nil {
+		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
+		return
+	}
+	validate := validator.New()
+	if err := validate.Struct(applyCap); err != nil {
+		e.ResponseWithMsg(c, e.ERROR, "请检查必填项")
+		return
+	}
+	addCap := ApplyCap.ApplyAddCap(applyCap)
+	if addCap != e.SUCCESS {
+		e.ResponseWithMsg(c, addCap, addCap.GetMsg())
+		return
+	}
+	e.ResponseSuccess(c, nil)
+}
+
+// GetApplyCapList 获取应用能力列表
+func GetApplyCapList(c *gin.Context) {
+	appid := c.Query("appid")
+	validate := validator.New()
+	err := validate.Var(appid, "required")
+	if err != nil {
+		e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
+		return
+	}
+	applycap, err := ApplyCap.ApplyCapList(appid)
+	if err != nil {
+		e.ResponseWithMsg(c, e.SUCCESS, err.Error())
+		return
+	}
+	e.ResponseSuccess(c, applycap)
+}
+
+// UpDateApplyCap 更新应用能力
+func UpDateApplyCap(c *gin.Context) {
+	var applyCap model.ApplyCap
+	if err := c.ShouldBindJSON(&applyCap); err != nil {
+		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
+		return
+	}
+	validate := validator.New()
+	if err := validate.Struct(applyCap); err != nil {
+		e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
+		return
+	}
+	dateApplyCap := ApplyCap.UpDateApplyCap(applyCap)
+	if dateApplyCap != e.SUCCESS {
+		e.ResponseWithMsg(c, dateApplyCap, dateApplyCap.GetMsg())
+		return
+	}
+	e.ResponseSuccess(c, nil)
+
+}
+
+// DeleteApplyCap 删除应用能力
+func DeleteApplyCap(c *gin.Context) {
+	var applyCap model.ApplyCapabilities
+	if err := c.ShouldBindJSON(&applyCap); err != nil {
+		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
+		return
+	}
+	validate := validator.New()
+	if err := validate.Struct(applyCap); err != nil {
+		e.ResponseWithMsg(c, e.PleaseCheckTherRquiredFields, e.PleaseCheckTherRquiredFields.GetMsg())
+		return
+	}
+	dateApplyCap := ApplyCap.DeleteApplyCAp(applyCap)
+	if dateApplyCap != e.SUCCESS {
+		e.ResponseWithMsg(c, dateApplyCap, dateApplyCap.GetMsg())
+		return
+	}
+	e.ResponseSuccess(c, nil)
+
+}

+ 36 - 3
app/controller/capabilities.go

@@ -13,16 +13,49 @@ var Capabilities services.Capabilities = &model.Capabilities{}
 // GetCapabilities 获取所有能力
 func GetCapabilities(c *gin.Context) {
 	var params unity.QueryPageParams
-	if err := c.ShouldBindQuery(&params); err != nil {
+	var capabilities model.Capabilities
+	_, _, role := unity.GetUId(c)
+	if err := c.ShouldBindJSON(&params); err != nil {
 		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
 		return
 	}
 	queryCond := "cap_name like ?"
 	params.Query = "%" + params.Query + "%"
-	result, total, err := Capabilities.GetCapabilitiesList(params, model.Capabilities{}, queryCond)
+	if role == "admin" {
+		result, total, err := Capabilities.AdminGetCapabilitiesList(params, capabilities, queryCond)
+		if err != nil {
+			e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
+			return
+		}
+		e.ResPonsePage(c, result, total, params)
+		return
+	}
+	result, total, err := Capabilities.GetCapabilitiesList(params, capabilities, queryCond)
 	if err != nil {
 		e.ResponseWithMsg(c, e.PaginationFailed, e.PaginationFailed.GetMsg())
 		return
+	} else {
+		e.ResPonsePage(c, result, total, params)
+		return
+	}
+}
+
+// AdminAddGetCapabilities 添加能力
+func AdminAddGetCapabilities(c *gin.Context) {
+	var capabilities model.Capabilities
+	if err := c.ShouldBindJSON(&capabilities); err != nil {
+		e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
+		return
+	}
+	id := unity.RandomIds(4)
+	for model.CapIdISRepeat(id) {
+		id = unity.RandomIds(4)
+	}
+	capabilities.CapId = id
+	addCapabilities := Capabilities.AddCapabilities(capabilities)
+	if addCapabilities == e.SUCCESS {
+		e.ResponseWithMsg(c, addCapabilities, addCapabilities.GetMsg())
+		return
 	}
-	e.ResPonsePage(c, result, total, params)
+	e.ResponseWithMsg(c, addCapabilities, addCapabilities.GetMsg())
 }

+ 20 - 8
app/e/code_msg.go

@@ -31,6 +31,12 @@ const (
 	AddAppUserFail
 	RegistrationFailed
 	TheSystemCannotBeRegistered
+	INSERTFAIL
+	PleaseCheckTherRquiredFields
+	TheParametersAreRepeated
+	CAPISNOT
+	ThereAreNoFeatures
+	FINDFAIL
 )
 
 var MsgFlags = map[Rescode]string{
@@ -51,14 +57,20 @@ var MsgFlags = map[Rescode]string{
 	TheVerificationCodeWasNotSent: "验证码未发送",
 	AnExceptionOccursWhenSendingAnSMSVerificationCode: "发送短信验证码出现异常",
 	ThePasswordIsWrongOrThePhoneNumberIsIncorrect:     "手机号或者密码错误",
-	TokenIsInvalid:              "Token 无效",
-	TokenIsExpired:              "Token 过期",
-	TokenIsFaild:                "Token 生成失败",
-	TheUserIsEmpty:              "用户为空",
-	Repeat:                      "应用名重复",
-	AddAppUserFail:              "添加用户失败",
-	RegistrationFailed:          "注册失败",
-	TheSystemCannotBeRegistered: "该系统未开放注册",
+	TokenIsInvalid:               "Token 无效",
+	TokenIsExpired:               "Token 过期",
+	TokenIsFaild:                 "Token 生成失败",
+	TheUserIsEmpty:               "用户为空",
+	Repeat:                       "应用名重复",
+	AddAppUserFail:               "添加用户失败",
+	RegistrationFailed:           "注册失败",
+	TheSystemCannotBeRegistered:  "该系统未开放注册",
+	INSERTFAIL:                   "添加失败",
+	PleaseCheckTherRquiredFields: "请检查必填项",
+	TheParametersAreRepeated:     "参数重复",
+	CAPISNOT:                     "该功能不存在",
+	ThereAreNoFeatures:           "该系统未配置功能项,请前往添加",
+	FINDFAIL:                     "查询失败",
 }
 
 func (c Rescode) GetMsg() string {

+ 20 - 12
app/model/appUser.go

@@ -2,6 +2,7 @@ package model
 
 import (
 	"context"
+	"errors"
 	"project_management/app/e"
 	"project_management/global"
 	"project_management/unity"
@@ -13,14 +14,14 @@ import (
 type AppUser struct {
 	//gorm.Model
 	utils.BaseModel
-	Username      string `gorm:"type:varchar(50);index:username_name,unique" json:"username" min:"3" max:"50"` // 用户名
-	Phone         string `gorm:"type:varchar(50);" json:"phone" min:"11" max:"11"`                             // 手机号
-	Nickname      string `gorm:"type:varchar(50);" json:"nickname"`                                            // 昵称
-	Password      string `gorm:"type:varchar(50);" json:"password"`                                            // 密码
-	LastLoginTime string `gorm:"type:datetime;" json:"last_login_time"`                                        // 最后登录时间
-	State         int    `gorm:"type:int;" json:"state"`                                                       // 状态 0:正常 1:禁用
-	AppID         string `gorm:"type:varchar(50);" json:"app_id" `                                             // 应用id
-	RegistMethod  int    `gorm:"type:int;" json:"regist_method"`                                               // 注册方式 1 短信登录 2 微信登录 3 系统添加
+	Username      string     `gorm:"type:varchar(50);index:username_name,unique" json:"username" min:"3" max:"50"` // 用户名
+	Phone         string     `gorm:"type:varchar(50);" json:"phone" min:"11" max:"11"`                             // 手机号
+	Nickname      string     `gorm:"type:varchar(50);" json:"nickname"`                                            // 昵称
+	Password      string     `gorm:"type:varchar(50);" json:"password"`                                            // 密码
+	LastLoginTime utils.Time `gorm:"type:datetime;" json:"last_login_time"`                                        // 最后登录时间
+	State         int        `gorm:"type:int;" json:"state"`                                                       // 状态 0:正常 1:禁用
+	AppID         string     `gorm:"type:varchar(50);" json:"app_id" validate:"required"`                          // 应用id
+	RegistMethod  int        `gorm:"type:int;" json:"regist_method"`                                               // 注册方式 1 短信登录 2 微信登录 3 系统添加
 }
 
 type AppUserRegist struct {
@@ -32,6 +33,10 @@ type AppUserRegist struct {
 	Code         string `json:"code" validate:"required" min:"6" max:"6"`                                                         // 验证码
 	RegistMethod int    `gorm:"type:int;" json:"regist_method"`                                                                   // 注册方式 1 短信登录 2 微信登录 3 系统添加
 }
+type AppUserDel struct {
+	ID    int    `json:"id" validate:"required"`
+	AppID string `json:"app_id" validate:"required"`
+}
 
 func (a AppUser) DeleteAppUserByID(id int, tableName string) e.Rescode {
 	//TODO implement me
@@ -59,6 +64,9 @@ func (a AppUser) GetAppUserList(params unity.QueryPageParams, tableName string,
 		query = query.Where("state=?", params.State)
 	}
 	if err = query.Count(&total).Error; err != nil {
+		if strings.Contains(err.Error(), "Error 1146 (42S02)") {
+			return nil, 0, errors.New("当前系统没有该表,请检查appid是否正确")
+		}
 		return nil, 0, err
 	}
 	offset := (params.Page - 1) * params.Size
@@ -81,13 +89,13 @@ func (a AppUser) RegistAppUser(appUser AppUserRegist) e.Rescode {
 	}
 	if tx.RowsAffected == 0 {
 		a.AppID = appUser.AppID
-		a.State = 0
+		a.State = 1
 		a.Phone = appUser.Phone
 		a.Username = appUser.Username
 		a.Nickname = "游客" + unity.RandomId()
 		md5 := utils.MD5(appUser.Password)
 		a.Password = md5
-		a.LastLoginTime = time.Now().Format("2006-01-02 15:04:05")
+		a.LastLoginTime = utils.Time(time.Now())
 		a.RegistMethod = appUser.RegistMethod
 		tableName := "appUser_" + appUser.AppID
 		//验证表是否已经创建,没有则创建
@@ -114,11 +122,11 @@ func (a AppUser) AddAppUser(appUser AppUser) e.Rescode {
 		global.DBLink.Table(tableName).AutoMigrate(&AppUser{})
 	}
 	a.AppID = appUser.AppID
-	a.State = 0
+	a.State = 1
 	a.Nickname = appUser.Nickname
 	a.Username = appUser.Username
 	a.Password = utils.MD5(appUser.Password)
-	a.LastLoginTime = time.Now().Format("2006-01-02 15:04:05")
+	a.LastLoginTime = utils.Time(time.Now())
 	a.RegistMethod = 3
 	if err := global.DBLink.Table(tableName).Create(&a).Error; err != nil {
 		if strings.Contains(err.Error(), "Duplicate entry") {

+ 178 - 57
app/model/apply.go

@@ -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
+}

+ 86 - 0
app/model/applyCap.go

@@ -0,0 +1,86 @@
+package model
+
+import (
+	"errors"
+	"project_management/app/e"
+	"project_management/global"
+	"project_management/utils"
+	"strings"
+)
+
+type ApplyCap struct {
+	utils.BaseModel
+	CapId        string `gorm:"type:varchar(50);" json:"cap_id" validate:"required"`
+	CapName      string `gorm:"type:varchar(50);" json:"cap_name" `
+	AppId        string `gorm:"type:varchar(50);" json:"app_id" validate:"required"`
+	PcIsShow     int    `gorm:"type:int;" json:"pc_is_show"`     // 是否pc端显示 1 显示 2 不显示
+	MobileIsShow int    `gorm:"type:int;" json:"mobile_is_show"` // 是否移动端显示 1 显示 2 不显示
+	Sort         int    `gorm:"type:int;" json:"sort"`           // 排序
+
+}
+
+func (a ApplyCap) DeleteApplyCAp(applycap ApplyCapabilities) e.Rescode {
+	//TODO implement me
+	tableName := "appcap_" + applycap.AppID
+	tx := global.DBLink.Table(tableName).Where("cap_id = ?", applycap.CapID).Delete(ApplyCap{})
+	if tx.Error != nil {
+		return e.DELETEFAIL
+	}
+	if tx.RowsAffected > 0 {
+		return e.SUCCESS
+	}
+	return e.DELETEFAIL
+}
+
+func (a ApplyCap) UpDateApplyCap(applycap ApplyCap) e.Rescode {
+	//TODO implement me
+	tableName := "appcap_" + applycap.AppId
+	tx := global.DBLink.Table(tableName).Where("cap_id = ?", applycap.CapId).Updates(applycap)
+	if tx.Error != nil {
+		return e.UPDATEFAIL
+	}
+	if tx.RowsAffected > 0 {
+		return e.SUCCESS
+	}
+	return e.UPDATEFAIL
+}
+
+func (a ApplyCap) ApplyCapList(appid string) ([]ApplyCap, error) {
+	//TODO implement me
+	tableName := "appcap_" + appid
+	var applycap []ApplyCap
+	tx := global.DBLink.Table(tableName).Order("sort asc").Find(&applycap)
+	if tx.Error != nil {
+		if strings.Contains(tx.Error.Error(), "Error 1146 (42S02)") {
+			return applycap, errors.New(e.ThereAreNoFeatures.GetMsg())
+		}
+	}
+	if tx.RowsAffected > 0 {
+		return applycap, nil
+	}
+	return applycap, errors.New(e.FINDFAIL.GetMsg())
+}
+
+func (a ApplyCap) ApplyAddCap(applycap ApplyCapabilities) e.Rescode {
+	//TODO implement me
+	var caps Capabilities
+	tableName := "appcap_" + applycap.AppID
+	table := global.DBLink.Migrator().HasTable(tableName)
+	if !table {
+		global.DBLink.Table(tableName).AutoMigrate(&ApplyCap{})
+	}
+	tx := global.DBLink.Where("cap_id = ?", applycap.CapID).First(&caps)
+	if tx.Error != nil {
+		return e.CAPISNOT
+	}
+	a.CapId = applycap.CapID
+	a.CapName = caps.CapName
+	a.AppId = applycap.AppID
+	a.PcIsShow = 1
+	a.MobileIsShow = 1
+	create := global.DBLink.Table(tableName).Create(&a)
+	if create.Error != nil {
+		return e.INSERTFAIL
+	}
+	return e.SUCCESS
+}

+ 84 - 9
app/model/capabilities.go

@@ -2,31 +2,106 @@ package model
 
 import (
 	"project_management/app/e"
+	"project_management/global"
 	"project_management/unity"
 	"project_management/utils"
+	"strings"
 )
 
 type Capabilities struct {
-	//gorm.Model
 	utils.BaseModel
-	CapName string `gorm:"type:varchar(50);" json:"cap_name"` // 应用名
-	CpaType string `gorm:"type:varchar(50);" json:"cap_type"` // 应用类型
-	Image   string `gorm:"type:varchar(50);" json:"image"`    // 应用图标
-	CapId   string `gorm:"type:varchar(50);" json:"cap_id"`   // 应用id
-	Price   int    `gorm:"type:int;" json:"price"`
+	CapName        string  `gorm:"type:varchar(255);index:idx_name,unique" json:"cap_name"` // 应用名
+	CpaType        string  `gorm:"type:varchar(50);" json:"cap_type"`                       // 应用类型
+	Image          string  `gorm:"type:varchar(255);" json:"image"`                         // 应用图片
+	CapId          string  `gorm:"type:varchar(50);unique" json:"cap_id"`                   // 应用id
+	CapDescription string  `gorm:"type:varchar(255);" json:"cap_description"`               // 应用描述
+	State          int     `gorm:"type:int;" json:"state"`                                  // 状态 1启用 2禁用
+	CapUrl         string  `gorm:"type:varchar(255);" json:"cap_url"`                       // 应用地址
+	Price          float64 `gorm:"type:decimal(10,5);" json:"price"`                        //价格
+	Count          int64   `gorm:"type:int;" json:"count"`                                  // 使用数量
+	PcIsShow       int     `gorm:"type:int;" json:"pc_is_show"`                             // 是否pc端显示
+	MobileIsShow   int     `gorm:"type:int;" json:"mobile_is_show"`                         // 是否移动端显示
+}
+type CapabilitiesApply struct {
+	utils.BaseModel
+	CapId string `gorm:"type:varchar(50);" json:"cap_id"` // 功能id
+	AppId string `gorm:"type:varchar(50);" json:"app_id"` // 应用id
+}
+
+type CapabilitiesDto struct {
+	Capabilities
+	Count int64 `json:"count"` // 使用数量
 }
 
+func (c Capabilities) TableName() string {
+	return "capabilities"
+}
 func (c Capabilities) AddCapabilities(capabilities Capabilities) e.Rescode {
 	//TODO implement me
-	panic("implement me")
+
+	capabilities.State = 1
+	tx := global.DBLink.Table(c.TableName()).Create(&capabilities)
+	if tx.Error != nil {
+		if strings.Contains(tx.Error.Error(), "Duplicate entry") {
+			return e.TheParametersAreRepeated
+		}
+		return e.INSERTFAIL
+	}
+	if tx.RowsAffected > 0 {
+		return e.SUCCESS
+	}
+	return e.INSERTFAIL
 }
 
 func (c Capabilities) GetCapabilitiesList(params unity.QueryPageParams, capabilities Capabilities, queryCond interface{}) (result []Capabilities, total int64, err error) {
 	//TODO implement me
-	panic("implement me")
+	query := global.DBLink.Table(capabilities.TableName())
+	if params.Query != "%%" {
+		query = query.Where(queryCond, params.Query)
+	}
+	if params.State != "" {
+		query = query.Where("state=?", params.State)
+	}
+	if err = query.Count(&total).Error; err != nil {
+		return nil, 0, err
+	}
+	offset := (params.Page - 1) * params.Size
+	if err = query.Offset(offset).Limit(params.Size).Order(params.Desc).Find(&result).Error; err != nil {
+		return nil, 0, err
+	}
+	return result, total, nil
+}
+func (c Capabilities) AdminGetCapabilitiesList(params unity.QueryPageParams, capabilities Capabilities, queryCond interface{}) (result []CapabilitiesDto, total int64, err error) {
+	//TODO implement me
+	query := global.DBLink.Table(capabilities.TableName())
+	if params.Query != "%%" {
+		query = query.Where(queryCond, params.Query)
+	}
+	if params.State != "" {
+		query = query.Where("state=?", params.State)
+	}
+	if err = query.Count(&total).Error; err != nil {
+		return nil, 0, err
+	}
+	offset := (params.Page - 1) * params.Size
+	if err = query.Offset(offset).Limit(params.Size).Order(params.Desc).Find(&result).Error; err != nil {
+		return nil, 0, err
+	}
+	//for i, _ := range result {
+	//
+	//}
+	return result, total, nil
 }
-
 func (c Capabilities) GetCapabilitiesById(id string) (Capabilities, error) {
 	//TODO implement me
 	panic("implement me")
 }
+
+// CapIdISRepeat 检查CapId是否重复
+func CapIdISRepeat(id string) bool {
+	tx := global.DBLink.Where("cap_id = ?", id).First(&Capabilities{})
+	if tx.RowsAffected > 0 {
+		return true
+	}
+	return false
+}

+ 2 - 1
app/router.go

@@ -18,8 +18,9 @@ func InitRouter() error {
 	routers.ApplyNotLogin(engine)
 	//用户登录
 	engine.Use(middlewares.LoginMiddleware())
+	routers.ApplyCapRouter(engine)
 	routers.ApplyRouter(engine)
+	routers.CapabilitiesRoutes(engine)
 	//系统管理员
-
 	return engine.Run(global.ServerSetting.Port)
 }

+ 1 - 0
app/routers/apply.go

@@ -12,4 +12,5 @@ func ApplyRouter(r *gin.Engine) {
 	group.POST("/applystate", controller.GetApplyState)
 	group.PUT("/apply", controller.UserUpdateApply)
 	group.GET("/apply", controller.GetApplyByAPPID)
+	group.PUT("/applycap", controller.ApplyAddCap)
 }

+ 14 - 0
app/routers/applyCap.go

@@ -0,0 +1,14 @@
+package routers
+
+import (
+	"github.com/gin-gonic/gin"
+	"project_management/app/controller"
+)
+
+func ApplyCapRouter(r *gin.Engine) {
+	group := r.Group("/api")
+	group.POST("/apply/addcap", controller.ApplyAddCap)
+	group.GET("/apply/cap", controller.GetApplyCapList)
+	group.PUT("/apply/cap", controller.UpDateApplyCap)
+	group.DELETE("/apply/cap", controller.DeleteApplyCap)
+}

+ 12 - 0
app/routers/capabilities.go

@@ -0,0 +1,12 @@
+package routers
+
+import (
+	"github.com/gin-gonic/gin"
+	"project_management/app/controller"
+)
+
+func CapabilitiesRoutes(r *gin.Engine) {
+	group := r.Group("/api")
+	group.POST("/capabilitiesall", controller.GetCapabilities)
+	group.POST("/capabilities", controller.AdminAddGetCapabilities)
+}

+ 2 - 0
app/services/apply.go

@@ -13,4 +13,6 @@ type Apply interface {
 	GetApplyById(appid string) (model.Apply, error)
 	QueryApplyByAppName(appName string) ([]model.Apply, error)
 	GetApplyAminList(params unity.QueryPageParams, apply model.Apply, queryCond string) (result []model.AppDto, total int64, err error)
+	ApplyAddCap(applycap model.ApplyCapabilities) e.Rescode
+	UpDateApplyCap(applycap model.ApplyCapabilities) e.Rescode
 }

+ 13 - 0
app/services/applyCap.go

@@ -0,0 +1,13 @@
+package services
+
+import (
+	"project_management/app/e"
+	"project_management/app/model"
+)
+
+type ApplyCap interface {
+	ApplyAddCap(applycap model.ApplyCapabilities) e.Rescode
+	ApplyCapList(appid string) (applycap []model.ApplyCap, err error)
+	UpDateApplyCap(applycap model.ApplyCap) e.Rescode
+	DeleteApplyCAp(applycap model.ApplyCapabilities) e.Rescode
+}

+ 1 - 0
app/services/capabilities.go

@@ -9,5 +9,6 @@ import (
 type Capabilities interface {
 	AddCapabilities(capabilities model.Capabilities) e.Rescode
 	GetCapabilitiesList(params unity.QueryPageParams, capabilities model.Capabilities, queryCond interface{}) (result []model.Capabilities, total int64, err error)
+	AdminGetCapabilitiesList(params unity.QueryPageParams, capabilities model.Capabilities, queryCond interface{}) (result []model.CapabilitiesDto, total int64, err error)
 	GetCapabilitiesById(id string) (model.Capabilities, error)
 }

+ 0 - 12
database/createNewTable.go

@@ -1,12 +0,0 @@
-package database
-
-import (
-	"gorm.io/gorm"
-	"project_management/app/model"
-)
-
-// CreateNewTable 动态创建新表
-func CreateNewTable(db *gorm.DB, tableName string) {
-	db.Table(tableName).AutoMigrate(&model.AppUser{})
-
-}

+ 9 - 0
unity/randomId.go

@@ -15,6 +15,15 @@ func RandomId() string {
 	}
 	return string(b)
 }
+func RandomIds(lenght int) string {
+	const letterBytes = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+	rand.Seed(time.Now().UnixNano())
+	b := make([]byte, lenght)
+	for i := range b {
+		b[i] = letterBytes[rand.Intn(len(letterBytes))]
+	}
+	return string(b)
+}
 
 // RandomAppID 生成12位随机appid
 func RandomAppID() string {