diff --git a/README.md b/README.md index 73c4428..839c78c 100644 --- a/README.md +++ b/README.md @@ -343,4 +343,23 @@ systemPermission: } else { fmt.Printf("%v数据库开启成功!\n", sqlConfig.Storage.Name) } +``` + + + +Time:2022-09-07
+数据库增加 应用系统 数据表 +
+ +``` +CREATE TABLE `appsystem` ( + `id` bigint(20) unsigned NOT NULL, + `title` varchar(255) DEFAULT '' COMMENT '系统名称', + `coder` varchar(255) NOT NULL DEFAULT '' COMMENT '识别符', + `state` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态(1:启用;2:禁用:3:删除)', + `time` bigint(20) unsigned NOT NULL DEFAULT '0', + `sort` int(5) unsigned NOT NULL DEFAULT '50' COMMENT '排序', + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COMMENT='应用系统'; + ``` \ No newline at end of file diff --git a/api/version1/jurisdiction/jurisdictionpc/appsystem.go b/api/version1/jurisdiction/jurisdictionpc/appsystem.go new file mode 100644 index 0000000..f79f4c6 --- /dev/null +++ b/api/version1/jurisdiction/jurisdictionpc/appsystem.go @@ -0,0 +1,209 @@ +package jurisdictionpc + +import ( + "key_performance_indicators/models/modelssystempermission" + "key_performance_indicators/overall" + "key_performance_indicators/overall/publicmethod" + "time" + + "github.com/gin-gonic/gin" +) + +//应用系统 + +// 添加应用系统 +func (a *ApiMethod) AddSystem(c *gin.Context) { + var receivedValue addsystemapp + err := c.ShouldBindJSON(&receivedValue) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if receivedValue.Name == "" { + publicmethod.Result(1, receivedValue, c, "请输入系统名称!") + return + } + if receivedValue.Coder == "" { + publicmethod.Result(1, receivedValue, c, "请输入系统识别符!") + return + } + if receivedValue.Sort == 0 { + receivedValue.Sort = 50 + } + var systemCont modelssystempermission.Appsystem + err = overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.Appsystem{}).Where("`title` = ? OR `coder` = ?", receivedValue.Name, receivedValue.Coder).First(&systemCont).Error + if err == nil { + publicmethod.Result(1, err, c, "该系统已经存在!请不要重复添加!") + return + } + systemCont.Id = publicmethod.GetUUid(2) + systemCont.Title = receivedValue.Name + systemCont.Coder = receivedValue.Coder + systemCont.Sort = receivedValue.Sort + systemCont.State = 1 + systemCont.Time = time.Now().Unix() + err = overall.CONSTANT_DB_System_Permission.Create(&systemCont).Error + if err != nil { + publicmethod.Result(104, err, c) + return + } + publicmethod.Result(0, err, c) +} + +// 系统列表 +func (a *ApiMethod) SystemList(c *gin.Context) { + var receivedValue systemList + c.ShouldBindJSON(&receivedValue) + if receivedValue.Page == 0 { + receivedValue.Page = 1 + } + if receivedValue.PageSize == 0 { + receivedValue.PageSize = 20 + } + var systemAry []modelssystempermission.Appsystem + gormDb := overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.Appsystem{}) + if receivedValue.Name != "" { + gormDb = gormDb.Where("`title` LIKE ?", "%"+receivedValue.Name+"%") + } + if receivedValue.Coder != "" { + gormDb = gormDb.Where("`coder` LIKE ?", "%"+receivedValue.Coder+"%") + } + if receivedValue.State != 0 { + gormDb = gormDb.Where("`state` = ?", receivedValue.State) + } else { + gormDb = gormDb.Where("`state` BETWEEN ? AND ?", 1, 2) + } + gormDb = publicmethod.PageTurningSettings(gormDb, receivedValue.Page, receivedValue.PageSize) + err := gormDb.Order("`sort` ASC").Order("`id` desc").Find(&systemAry).Error + var total int64 + totalErr := gormDb.Count(&total).Error + if totalErr != nil { + total = 0 + } + if err != nil || len(systemAry) < 1 { + publicmethod.Result(107, err, c) + return + } + publicmethod.ResultList(0, receivedValue.Page, receivedValue.PageSize, total, int64(len(systemAry)), systemAry, c) +} + +// 获取单一系统详情 +func (a *ApiMethod) GetSystemCont(c *gin.Context) { + var receivedValue publicmethod.PublicId + err := c.ShouldBindJSON(&receivedValue) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if receivedValue.Id == "" { + publicmethod.Result(1, err, c, "未知系统参数!") + return + } + var systemCont modelssystempermission.Appsystem + err = systemCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id}) + if err != nil { + publicmethod.Result(107, err, c) + return + } + publicmethod.Result(0, err, c) +} + +// 编辑应用系统信息 +func (a *ApiMethod) EditSystem(c *gin.Context) { + var receivedValue editSystemCont + err := c.ShouldBindJSON(&receivedValue) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if receivedValue.Id == "" { + publicmethod.Result(1, err, c, "未知系统参数!") + return + } + where := publicmethod.MapOut[string]() + where["`id`"] = receivedValue.Id + var oldSystemCont modelssystempermission.Appsystem + err = oldSystemCont.GetCont(where) + if err != nil { + publicmethod.Result(107, err, c) + return + } + saveData := publicmethod.MapOut[string]() + if receivedValue.Name != "" && receivedValue.Name != oldSystemCont.Title { + var systemCont modelssystempermission.Appsystem + err = overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.Appsystem{}).Where("`title` = ? ", receivedValue.Name).First(&systemCont).Error + if err == nil { + publicmethod.Result(1, err, c, "该系统已经存在!请不要重复添加!") + return + } + saveData["`title`"] = receivedValue.Name + } + if receivedValue.Coder == "" && receivedValue.Coder != oldSystemCont.Coder { + var systemCont modelssystempermission.Appsystem + err = overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.Appsystem{}).Where("`coder` = ?", receivedValue.Coder).First(&systemCont).Error + if err == nil { + publicmethod.Result(1, err, c, "该系统已经存在!请不要重复添加!") + return + } + saveData["`coder`"] = receivedValue.Coder + } + if receivedValue.Sort != 0 && receivedValue.Sort != oldSystemCont.Sort { + saveData["`sort`"] = receivedValue.Sort + } + if len(saveData) > 0 { + saveData["`time`"] = time.Now().Unix() + err = oldSystemCont.EiteCont(where, saveData) + } + if err != nil { + publicmethod.Result(106, err, c) + return + } + publicmethod.Result(0, err, c) +} + +// 更改状态或删除 +func (a *ApiMethod) EditStateOfDel(c *gin.Context) { + var receivedValue publicmethod.PublicState + err := c.ShouldBindJSON(&receivedValue) + if err != nil { + publicmethod.Result(100, err, c) + return + } + if receivedValue.IsTrue == 0 { + receivedValue.IsTrue = 2 + } + if receivedValue.State == 0 { + receivedValue.State = 1 + } + if receivedValue.Id == "" { + publicmethod.Result(1, err, c, "未知系统参数!") + return + } + where := map[string]interface{}{"`id`": receivedValue.Id} + var oldSystemCont modelssystempermission.Appsystem + err = oldSystemCont.GetCont(where) + if err != nil { + publicmethod.Result(107, err, c) + return + } + if receivedValue.State != 3 { + saveData := publicmethod.MapOut[string]() + saveData["`state`"] = receivedValue.State + saveData["`time`"] = time.Now().Unix() + err = oldSystemCont.EiteCont(where, saveData) + } else { + if receivedValue.IsTrue != 1 { + saveData := publicmethod.MapOut[string]() + saveData["`state`"] = receivedValue.State + saveData["`time`"] = time.Now().Unix() + err = oldSystemCont.EiteCont(where, saveData) + } else { + err = overall.CONSTANT_DB_System_Permission.Where(where).Delete(&oldSystemCont).Error + } + } + if err != nil { + publicmethod.Result(106, err, c) + return + } + publicmethod.Result(0, err, c) +} diff --git a/api/version1/jurisdiction/jurisdictionpc/type.go b/api/version1/jurisdiction/jurisdictionpc/type.go index 4ba1e8a..f2a1bd6 100644 --- a/api/version1/jurisdiction/jurisdictionpc/type.go +++ b/api/version1/jurisdiction/jurisdictionpc/type.go @@ -22,3 +22,24 @@ type appPowerStruct struct { SystemName string `json:"systemname"` //系统识别符 PointId []string `json:"pointid"` //权限点位 } + +// 添加应用系统 +type addsystemapp struct { + publicmethod.PublicName + Coder string `json:"coder"` + Sort int `json:"sort"` +} + +// 系统应用列表 +type systemList struct { + publicmethod.PagesTurn + publicmethod.PublicName + Coder string `json:"coder"` + State int `json:"state"` +} + +// 修改应用信息 +type editSystemCont struct { + publicmethod.PublicId + addsystemapp +} diff --git a/apirouter/v1/systempower/pc.go b/apirouter/v1/systempower/pc.go index 72558c2..f61097d 100644 --- a/apirouter/v1/systempower/pc.go +++ b/apirouter/v1/systempower/pc.go @@ -15,5 +15,10 @@ func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { apiRouter.GET("", methodBinding.Index) //入口 apiRouter.POST("", methodBinding.Index) //入口 apiRouter.POST("edit_power", methodBinding.EditPower) //编辑权限 + + apiRouter.POST("add_system", methodBinding.AddSystem) //添加应用系统 + apiRouter.POST("system_list", methodBinding.SystemList) //系统列表 + apiRouter.POST("edit_system", methodBinding.EditSystem) //编辑应用系统信息 + apiRouter.POST("edit_state_of_del", methodBinding.EditStateOfDel) //更改状态或删除 } } diff --git a/models/modelssystempermission/appsystem.go b/models/modelssystempermission/appsystem.go new file mode 100644 index 0000000..e1f8da4 --- /dev/null +++ b/models/modelssystempermission/appsystem.go @@ -0,0 +1,61 @@ +package modelssystempermission + +import ( + "key_performance_indicators/overall" + "strings" +) + +// 应用系统 +type Appsystem struct { + Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` + Title string `json:"title" gorm:"column:title;type:varchar(255) ;comment:系统名称"` + Coder string `json:"coder" gorm:"column:coder;type:varchar(255) ;comment:识别符"` + State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` + Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` + Sort int `json:"sort" gorm:"column:sort;type:int(5) unsigned;default:50;not null;comment:排序"` +} + +func (Appsystem *Appsystem) TableName() string { + return "appsystem" +} + +// 编辑内容 +func (cont *Appsystem) EiteCont(whereMap interface{}, saveData interface{}) (err error) { + err = overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Updates(saveData).Error + return +} + +// 获取内容 +func (cont *Appsystem) GetCont(whereMap interface{}, field ...string) (err error) { + gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + gormDb = gormDb.Where(whereMap) + err = gormDb.First(&cont).Error + return +} + +// 根据条件获取总数 +func (cont *Appsystem) CountCont(whereMap interface{}) (countId int64) { + overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Count(&countId) + return +} + +// 读取全部信息 +func (cont *Appsystem) ContMap(whereMap interface{}, field ...string) (countAry []Appsystem, err error) { + gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) + if len(field) > 0 { + fieldStr := strings.Join(field, ",") + gormDb = gormDb.Select(fieldStr) + } + err = gormDb.Where(whereMap).Find(&countAry).Error + return +} + +// 删除内容 +func (cont *Appsystem) DelCont(whereMap interface{}) (err error) { + err = overall.CONSTANT_DB_System_Permission.Where(whereMap).Delete(&cont).Error + return +} diff --git a/models/modelssystempermission/empower.go b/models/modelssystempermission/empower.go index 26c9018..083db87 100644 --- a/models/modelssystempermission/empower.go +++ b/models/modelssystempermission/empower.go @@ -5,6 +5,7 @@ import ( "strings" ) +// 权限配置 type Empower struct { Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` OrdId int64 `json:"ordid" gorm:"column:ordid;type:bigint(20) unsigned;default:0;not null;comment:行政组织"`