KPI绩效考核系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
5.2 KiB

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) AddSystemRole(c *gin.Context) {
var receivedValue systemRole
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if receivedValue.Name == "" {
publicmethod.Result(101, receivedValue, c)
return
}
if receivedValue.Sort == 0 {
receivedValue.Sort = 50
}
var systemRoleCont modelssystempermission.SystemRole
err = systemRoleCont.GetCont(map[string]interface{}{"`name`": receivedValue.Name}, "`id`")
if err == nil {
publicmethod.Result(103, systemRoleCont, c)
return
}
systemRoleCont.Name = receivedValue.Name
systemRoleCont.Sort = receivedValue.Sort
systemRoleCont.State = 1
systemRoleCont.Time = time.Now().Unix()
err = overall.CONSTANT_DB_System_Permission.Create(&systemRoleCont).Error
if err != nil {
publicmethod.Result(104, err, c)
return
}
publicmethod.Result(0, err, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2022-11-09 08:30:04
@ 功能: 系统角色编辑
@ 参数
#Id 项目ID
#Name 角色名称
#Sort 角色排序
@ 返回值
#
*/
func (a *ApiMethod) EditSystemRole(c *gin.Context) {
var receivedValue editSystemRoleCont
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if receivedValue.Id == "" {
publicmethod.Result(101, receivedValue, c)
return
}
if receivedValue.Name == "" {
publicmethod.Result(101, receivedValue, c)
return
}
if receivedValue.Sort == 0 {
receivedValue.Sort = 50
}
var systemRoleCont modelssystempermission.SystemRole
err = systemRoleCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id}, "`name`")
if err != nil {
publicmethod.Result(107, err, c)
return
}
editCont := publicmethod.MapOut[string]()
if receivedValue.Sort != systemRoleCont.Sort {
editCont["`sort`"] = receivedValue.Sort
}
if systemRoleCont.Name != receivedValue.Name {
err = systemRoleCont.GetCont(map[string]interface{}{"`name`": receivedValue.Name}, "`id`")
if err == nil {
publicmethod.Result(103, systemRoleCont, c)
return
}
editCont["`name`"] = receivedValue.Name
}
if len(editCont) > 0 {
editCont["`time`"] = time.Now().Unix()
editCont["`state`"] = 1
err = systemRoleCont.EiteCont(map[string]interface{}{"`id`": receivedValue.Id}, editCont)
if err != nil {
publicmethod.Result(106, err, c)
return
}
}
publicmethod.Result(0, systemRoleCont, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2022-11-09 08:41:20
@ 功能: 角色列表
@ 参数
#
@ 返回值
#
*/
func (a *ApiMethod) SystemRoleList(c *gin.Context) {
var receivedValue systemRoleContList
c.ShouldBindJSON(&receivedValue)
var systemRoleInfoList []modelssystempermission.SystemRole
gormDb := overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.SystemRole{}).Where("`state` BETWEEN ? AND ?", 1, 2)
if receivedValue.Name != "" {
gormDb = gormDb.Where("`name` LIKE ?", "%"+receivedValue.Name+"%")
}
err := gormDb.Order("`sort` ASC").Order("`id` DESC").Find(&systemRoleInfoList).Error
if err != nil {
publicmethod.Result(107, err, c)
return
}
var sendList []sendSystemRoleList
for _, v := range systemRoleInfoList {
var sendCont sendSystemRoleList
sendCont.Id = v.Id
sendCont.Name = v.Name //角色名称"`
sendCont.State = v.State //状态(1:启用;2:禁用;3:删除)"`
sendCont.Time = v.Time //创建时间"`
sendCont.Sort = v.Sort //排序"`
if v.State == 1 {
sendCont.IsTrue = true
} else {
sendCont.IsTrue = false
}
sendList = append(sendList, sendCont)
}
publicmethod.Result(0, sendList, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2022-11-09 08:52:56
@ 功能: 编辑角色状态
@ 参数
#
@ 返回值
#
*/
func (a *ApiMethod) EditSystemRoleState(c *gin.Context) {
var receivedValue publicmethod.PublicState
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if receivedValue.Id == "" {
publicmethod.Result(101, receivedValue, c)
return
}
if receivedValue.State == 0 {
receivedValue.State = 2
}
wheAry := publicmethod.MapOut[string]()
wheAry["`id`"] = receivedValue.Id
var systemRoleCont modelssystempermission.SystemRole
err = systemRoleCont.GetCont(wheAry, "`state`")
if err != nil {
publicmethod.Result(107, err, c)
return
}
if receivedValue.State != 3 {
editCont := publicmethod.MapOut[string]()
if receivedValue.State != systemRoleCont.State {
editCont["`state`"] = receivedValue.State
}
if len(editCont) > 0 {
editCont["`time`"] = time.Now().Unix()
err = systemRoleCont.EiteCont(wheAry, editCont)
}
} else {
if receivedValue.IsTrue != 1 {
editCont := publicmethod.MapOut[string]()
if receivedValue.State != systemRoleCont.State {
editCont["`state`"] = receivedValue.State
}
if len(editCont) > 0 {
editCont["`time`"] = time.Now().Unix()
err = systemRoleCont.EiteCont(wheAry, editCont)
}
} else {
err = systemRoleCont.DelCont(wheAry)
}
}
if err != nil {
publicmethod.Result(106, err, c)
return
}
publicmethod.Result(0, err, c)
}