1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package eta
- import (
- "eta_gn/eta_bridge/global"
- "fmt"
- "strings"
- "time"
- )
- type SysGroup struct {
- GroupId int `gorm:"primaryKey;column:group_id;type:int(11);not null" json:"group_id"`
- DepartmentId int `gorm:"index:idx_department_id;column:department_id;type:int(11)" json:"department_id"` // 部门id
- GroupName string `gorm:"column:group_name;type:varchar(255);default:''" json:"group_name"` // 分组名称
- CreateTime time.Time `gorm:"column:create_time;type:datetime" json:"create_time"`
- ParentId int `gorm:"column:parent_id;type:int(11);default:0" json:"parent_id"`
- Sort int `gorm:"column:sort;type:int(10);not null;default:0" json:"sort"` // 排序
- OutID string `gorm:"column:out_id" json:"out_id"` // 外部id
- }
- func (m *SysGroup) TableName() string {
- return "sys_group"
- }
- // Create 新增分组
- func (m *SysGroup) Create() (err error) {
- err = global.MYSQL["hz_eta"].Create(m).Error
- return
- }
- // Update 更新分组
- func (m *SysGroup) Update(cols []string) (err error) {
- err = global.MYSQL["hz_eta"].Model(m).Select(cols).Updates(m).Error
- return
- }
- // GetSysGroupByGroupId 获取分组-根据主键
- func GetSysGroupByGroupId(groupId int) (item *SysGroup, err error) {
- err = global.MYSQL["hz_eta"].Where("group_id = ?", groupId).First(&item).Error
- return
- }
- // GetAllSysGroup 获取所有的分组
- func GetAllSysGroup() (items []*SysGroup, err error) {
- sql := `SELECT * FROM sys_group `
- err = global.MYSQL["hz_eta"].Raw(sql).Find(&items).Error
- return
- }
- // DeleteGroupByGroupId 删除分组-根据主键
- func DeleteGroupByGroupId(groupId int) (err error) {
- sql := `DELETE FROM sys_group WHERE group_id = ? LIMIT 1`
- err = global.MYSQL["hz_eta"].Exec(sql, groupId).Error
- if err != nil {
- return
- }
- // 清除关联
- sql = `UPDATE admin SET group_id = 0, group_name = '' WHERE group_id = ? `
- err = global.MYSQL["hz_eta"].Exec(sql, groupId).Error
- return
- }
- func (m *SysGroup) GetItemByCondition(condition string, pars []interface{}) (item *SysGroup, err error) {
- sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
- err = global.MYSQL["hz_eta"].Raw(sql, pars...).First(&item).Error
- return
- }
- func (m *SysGroup) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SysGroup, err error) {
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := ``
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
- err = global.MYSQL["hz_eta"].Raw(sql, pars...).Find(&items).Error
- return
- }
- // GetSysGroupByOutId 获取分组-根据OutId
- func GetSysGroupByOutId(outId string) (item *SysGroup, err error) {
- err = global.MYSQL["hz_eta"].Where("out_id = ?", outId).First(&item).Error
- return
- }
|