123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package system
- import (
- "context"
- "hongze/fms_api/global"
- "hongze/fms_api/models/base"
- )
- // 角色表
- type SysRole struct {
- RoleId int64 `gorm:"primaryKey;column:role_id" json:"role_id"` //序号
- RoleName string `gorm:"column:role_name" json:"role_name"` //角色名称
- base.TimeBase
- }
- // TableName get sql table name.获取数据库表名
- func (r *SysRole) TableName() string {
- return "sys_role"
- }
- // 新增
- func (r *SysRole) Add() (err error) {
- err = global.DEFAULT_MYSQL.Create(r).Error
- return
- }
- // 修改
- func (r *SysRole) Update(updateCols []string) (err error) {
- err = global.DEFAULT_MYSQL.Model(r).Select(updateCols).Updates(r).Error
- return
- }
- type SysRoleAddReq struct {
- RoleName string `json:"role_name" binding:"required"` //角色名称
- }
- type SysRoleEditReq struct {
- RoleId int64 `json:"role_id" binding:"required"` //序号
- RoleName string `json:"role_name" binding:"required"` //角色名称
- }
- type SysRoleDelReq struct {
- RoleId int64 `json:"role_id" binding:"required"` //序号
- }
- type SysRoleMenuEditReq struct {
- RoleId int64 `json:"role_id" binding:"required,gte=1"` //序号
- MenuIdList []int64 `json:"menu_id_list" ` //绑定的菜单ID
- }
- func (r *SysRole) GetRoleByRoleId(roleId int64) (item *SysRole, err error) {
- err = global.DEFAULT_MYSQL.Model(r).Where("role_id = ?", roleId).First(&item).Error
- return
- }
- func (r *SysRole) GetRoleByRoleName(roleName string) (item *SysRole, err error) {
- err = global.DEFAULT_MYSQL.Model(r).Where("role_name = ?", roleName).First(&item).Error
- return
- }
- type SysRoleListItem struct {
- RoleId int64 `json:"role_id"` //序号
- RoleName string `json:"role_name"` //角色名称
- CreateTime string `json:"create_time"` //创建时间
- ModifyTime string `json:"modify_time"` //最后更新时间
- }
- // SelectPage 分页查询
- func (r *SysRole) SelectPage(page base.IPage, condition string, pars []interface{}) (count int64, results []SysRole, err error) {
- query := global.DEFAULT_MYSQL.WithContext(context.TODO()).Model(r).Where(condition, pars...)
- query.Count(&count)
- if len(page.GetOrderItemsString()) > 0 {
- query = query.Order(page.GetOrderItemsString())
- }
- err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&results).Error
- return
- }
- func (r *SysRole) GetRoleNameList() (list []*SysRole, err error) {
- err = global.DEFAULT_MYSQL.Model(r).Find(&list).Error
- return
- }
- type SysRoleListReq struct {
- RoleName string `json:"role_name" form:"role_name"` //序号
- base.PageReq
- }
- type SysRoleMenuListReq struct {
- RoleId int64 `json:"role_id" form:"role_id"` //序号
- }
- type SysRoleMenuResp struct {
- List []*MenuListItemResp `json:"list"`
- ChoiceList []int64 `json:"choice_list"`
- }
- // 删除
- func (r *SysRole) Delete() (err error) {
- err = global.DEFAULT_MYSQL.Delete(r).Error
- return
- }
|