12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package eta
- import (
- "eta_gn/eta_bridge/global"
- "fmt"
- "strings"
- "time"
- )
- type SysDepartment struct {
- DepartmentId int `gorm:"primaryKey;column:department_id;type:int(11);not null" json:"department_id"`
- DepartmentName string `gorm:"unique;column:department_name;type:varchar(255);default:''" json:"department_name"` // 部门名称
- OutID string `gorm:"column:out_id" json:"out_id"` // 外部id
- CreateTime time.Time `gorm:"column:create_time;type:datetime" json:"create_time"` // 创建时间
- Sort int `gorm:"column:sort;type:int(10);not null;default:0" json:"sort"` // 排序
- }
- func (m *SysDepartment) TableName() string {
- return "sys_department"
- }
- // Create 新增部门
- func (m *SysDepartment) Create() (err error) {
- err = global.MYSQL["hz_eta"].Create(m).Error
- return
- }
- // Update 更新部门
- func (m *SysDepartment) Update(cols []string) (err error) {
- err = global.MYSQL["hz_eta"].Model(m).Select(cols).Updates(m).Error
- return
- }
- // GetDepartmentById 主键获取部门
- func GetDepartmentById(departmentId int) (item *SysDepartment, err error) {
- err = global.MYSQL["hz_eta"].Where("department_id = ?", departmentId).First(&item).Error
- return
- }
- // GetAllDepartment 获取所有部门
- func GetAllDepartment() (items []*SysDepartment, err error) {
- //sql := `SELECT * FROM sys_department WHERE out_id <> ""`
- sql := `SELECT * FROM sys_department `
- err = global.MYSQL["hz_eta"].Raw(sql).Find(&items).Error
- return
- }
- // DeleteDepartmentById 主键删除部门
- func DeleteDepartmentById(departmentId int) (err error) {
- sql := `DELETE FROM sys_department WHERE department_id = ? LIMIT 1`
- err = global.MYSQL["hz_eta"].Exec(sql, departmentId).Error
- return
- }
- func (m *SysDepartment) GetItemByCondition(condition string, pars []interface{}) (item *SysDepartment, 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 *SysDepartment) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SysDepartment, 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
- }
- // GetSysDepartmentByOutId 获取部门-根据OutId
- func GetSysDepartmentByOutId(outId string) (item *SysDepartment, err error) {
- err = global.MYSQL["hz_eta"].Where("out_id = ?", outId).First(&item).Error
- return
- }
|