6 changed files with 316 additions and 0 deletions
@ -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) |
||||
|
} |
||||
@ -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 |
||||
|
} |
||||
Loading…
Reference in new issue