18 changed files with 494 additions and 23 deletions
@ -0,0 +1,91 @@ |
|||
package jurisdictionpc |
|||
|
|||
import ( |
|||
"key_performance_indicators/models/modelssystempermission" |
|||
"key_performance_indicators/overall" |
|||
"key_performance_indicators/overall/publicmethod" |
|||
"strconv" |
|||
"strings" |
|||
"time" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
// 编辑权限
|
|||
func (a *ApiMethod) EditPower(c *gin.Context) { |
|||
var receivedValue appPowerStruct |
|||
err := c.ShouldBindJSON(&receivedValue) |
|||
if err != nil { |
|||
publicmethod.Result(100, err, c) |
|||
return |
|||
} |
|||
if receivedValue.OrdId == "" { |
|||
publicmethod.Result(1, receivedValue, c, "请指定要配置的行政组织!") |
|||
return |
|||
} |
|||
if receivedValue.PostId == "" { |
|||
publicmethod.Result(1, receivedValue, c, "请指定要配置的岗位!") |
|||
return |
|||
} |
|||
if receivedValue.SystemName == "" { |
|||
publicmethod.Result(1, err, c, "请提交系统识别符!") |
|||
return |
|||
} |
|||
if len(receivedValue.PointId) < 1 { |
|||
publicmethod.Result(1, err, c, "请至少指定一项权限!") |
|||
return |
|||
} |
|||
var empowerCont modelssystempermission.Empower |
|||
err = empowerCont.GetCont(map[string]interface{}{"`ordid`": receivedValue.OrdId, "`post_id`": receivedValue.PostId, "`system`": receivedValue.SystemName}, "`id`") |
|||
postIdStr := strings.Join(receivedValue.PointId, ",") |
|||
if err == nil { |
|||
|
|||
err = empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`state`": 1, "`point_id`": postIdStr, "`time`": time.Now().Unix()}) |
|||
} else { |
|||
ordIdInt64, _ := strconv.ParseInt(receivedValue.OrdId, 10, 64) |
|||
empowerCont.OrdId = ordIdInt64 //行政组织"`
|
|||
postIdInt64, _ := strconv.ParseInt(receivedValue.PostId, 10, 64) |
|||
empowerCont.PostId = postIdInt64 //岗位ID"`
|
|||
empowerCont.System = receivedValue.SystemName //系统"`
|
|||
empowerCont.PointId = postIdStr //权限点位"`
|
|||
empowerCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
|||
empowerCont.Time = time.Now().Unix() //创建时间"`
|
|||
err = overall.CONSTANT_DB_System_Permission.Create(&empowerCont).Error |
|||
} |
|||
if err != nil { |
|||
publicmethod.Result(104, err, c) |
|||
return |
|||
} |
|||
publicmethod.Result(0, err, c) |
|||
// for i := 0; i < len(receivedValue.PointId); i++ {
|
|||
// var empowerCont modelssystempermission.Empower
|
|||
// err = empowerCont.GetCont(map[string]interface{}{"`post_id`": receivedValue.PostId, "`system`": receivedValue.SystemName, "`point_id`": receivedValue.PointId[i]})
|
|||
// if err == nil {
|
|||
// if empowerCont.State != 1 {
|
|||
// empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`state`": 1, "`time`": time.Now().Unix()})
|
|||
// }
|
|||
// } else {
|
|||
// postIdInt64, _ := strconv.ParseInt(receivedValue.PostId, 10, 64)
|
|||
// empowerCont.PostId = postIdInt64 //岗位ID"`
|
|||
// empowerCont.System = receivedValue.SystemName //系统"`
|
|||
// poinIdInt64, _ := strconv.ParseInt(receivedValue.PointId[i], 10, 64)
|
|||
// empowerCont.PointId = poinIdInt64 //权限点位"`
|
|||
// empowerCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
|||
// empowerCont.Time = time.Now().Unix() //创建时间"`
|
|||
// saveData = append(saveData, empowerCont)
|
|||
// }
|
|||
// }
|
|||
// if len(saveData) > 0 {
|
|||
// err = overall.CONSTANT_DB_System_Permission.Create(&saveData).Error
|
|||
// }
|
|||
// if err != nil {
|
|||
// publicmethod.Result(104, err, c)
|
|||
// return
|
|||
// }
|
|||
// //清除其他权限
|
|||
// otherSaveData := publicmethod.MapOut[string]()
|
|||
// otherSaveData["`state`"] = 2
|
|||
// otherSaveData["`time`"] = time.Now().Unix()
|
|||
// overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.Empower{}).Where("`state` = 1 AND `post_id` = ? AND `system` = ?", receivedValue.PostId, receivedValue.SystemName).Not(map[string]interface{}{"point_id": receivedValue.PointId}).Updates(&otherSaveData)
|
|||
// publicmethod.Result(0, saveData, c)
|
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
package jurisdictionpc |
|||
|
|||
import ( |
|||
"key_performance_indicators/overall/publicmethod" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
type ApiMethod struct{} |
|||
|
|||
// 权限配置
|
|||
func (a *ApiMethod) Index(c *gin.Context) { |
|||
outputCont := publicmethod.MapOut[string]() |
|||
outputCont["index"] = "权限配置" |
|||
publicmethod.Result(0, outputCont, c) |
|||
} |
|||
|
|||
// 添加权限参数
|
|||
type appPowerStruct struct { |
|||
OrdId string `json:"ordid"` //岗位
|
|||
PostId string `json:"postid"` //岗位
|
|||
SystemName string `json:"systemname"` //系统识别符
|
|||
PointId []string `json:"pointid"` //权限点位
|
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package systempower |
|||
|
|||
import ( |
|||
"key_performance_indicators/api/version1" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
// 权限管理PC端
|
|||
func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { |
|||
apiRouter := router.Group("powerpc") |
|||
|
|||
var methodBinding = version1.AppApiEntry.JurisdictionpcApi |
|||
{ |
|||
apiRouter.GET("", methodBinding.Index) //入口
|
|||
apiRouter.POST("", methodBinding.Index) //入口
|
|||
apiRouter.POST("edit_power", methodBinding.EditPower) //编辑权限
|
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
package systempower |
|||
|
|||
//系统权限
|
|||
type ApiRouter struct{} |
|||
@ -0,0 +1,61 @@ |
|||
package modelssystempermission |
|||
|
|||
import ( |
|||
"key_performance_indicators/overall" |
|||
"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:行政组织"` |
|||
PostId int64 `json:"postid" gorm:"column:post_id;type:bigint(20) unsigned;default:0;not null;comment:岗位ID"` |
|||
System string `json:"system" gorm:"column:system;type:varchar(255) ;comment:系统"` |
|||
PointId string `json:"pointid" gorm:"column:point_id;type:longtext;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:创建时间"` |
|||
} |
|||
|
|||
func (Empower *Empower) TableName() string { |
|||
return "Empower" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *Empower) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *Empower) 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 *Empower) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *Empower) ContMap(whereMap interface{}, field ...string) (countAry []Empower, 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 *Empower) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
package systempermission |
|||
|
|||
import ( |
|||
"key_performance_indicators/overall" |
|||
"strings" |
|||
) |
|||
|
|||
type Empower struct { |
|||
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` |
|||
PostId int64 `json:"postid" gorm:"column:post_id;type:bigint(20) unsigned;default:0;not null;comment:岗位ID"` |
|||
System string `json:"system" gorm:"column:system;type:varchar(255) ;comment:系统"` |
|||
PointId int64 `json:"pointid" gorm:"column:point_id;type:bigint(20) unsigned;default:0;not null;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:创建时间"` |
|||
} |
|||
|
|||
func (Empower *Empower) TableName() string { |
|||
return "Empower" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *Empower) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *Empower) 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 *Empower) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *Empower) ContMap(whereMap interface{}, field ...string) (countAry []Empower, 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 *Empower) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
Loading…
Reference in new issue