sys_department.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package crm
  2. import (
  3. "hongze/hz_crm_eta/global"
  4. "time"
  5. )
  6. type SysDepartment struct {
  7. DepartmentId int `gorm:"primaryKey;column:department_id;type:int(11);not null" json:"department_id"`
  8. DepartmentName string `gorm:"unique;column:department_name;type:varchar(255);default:''" json:"department_name"` // 部门名称
  9. CreateTime time.Time `gorm:"column:create_time;type:datetime" json:"create_time"` // 创建时间
  10. Sort int `gorm:"column:sort;type:int(10);not null;default:0" json:"sort"` // 排序
  11. }
  12. func (m *SysDepartment) TableName() string {
  13. return "sys_department"
  14. }
  15. // Create 新增部门
  16. func (m *SysDepartment) Create() (err error) {
  17. err = global.MYSQL["hz_crm"].Create(m).Error
  18. return
  19. }
  20. // Update 更新部门
  21. func (m *SysDepartment) Update(cols []string) (err error) {
  22. err = global.MYSQL["hz_crm"].Model(m).Select(cols).Updates(m).Error
  23. return
  24. }
  25. // GetDepartmentById 主键获取部门
  26. func GetDepartmentById(departmentId int) (item *SysDepartment, err error) {
  27. err = global.MYSQL["hz_crm"].Where("department_id = ?", departmentId).First(&item).Error
  28. return
  29. }
  30. // DeleteDepartmentById 主键删除部门
  31. func DeleteDepartmentById(departmentId int) (err error) {
  32. sql := `DELETE FROM sys_department WHERE department_id = ? LIMIT 1`
  33. err = global.MYSQL["hz_crm"].Exec(sql, departmentId).Error
  34. return
  35. }