department.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package dao
  2. import "server/global"
  3. type Department struct {
  4. Id int `gorm:"primarykey" from:"id" json:"ID"`
  5. Name string `json:"name" from:"name" gorm:"comment:部门名称"`
  6. Desc string `json:"desc" from:"desc" gorm:"comment:部门描述"`
  7. PrincipalId int `json:"principalId" from:"principal_id" gorm:"comment:负责人id"`
  8. PrincipalName string `json:"principalName" from:"principal_name" gorm:"comment:负责人姓名"`
  9. Users []SysUser `json:"users" gorm:"-"`
  10. IsStart bool `json:"isStart" from:"is_start" gorm:"comment:是否启用"`
  11. }
  12. func (Department) TableName() string {
  13. return "department"
  14. }
  15. // TODO:部门查询
  16. // QueryAllDep 查询所有部门
  17. func QueryAllDep() (deps []Department, err error) {
  18. err = global.GVA_DB.Model(&Department{}).Find(&deps).Error
  19. return deps, err
  20. }
  21. // QueryDepByStart 查询启用部门
  22. func QueryDepByStart() (deps []Department, err error) {
  23. err = global.GVA_DB.Model(&Department{}).Where("is_start = ?", true).Find(&deps).Error
  24. return deps, err
  25. }
  26. // QueryUsersByDepId 查询部门下的用户
  27. func QueryUsersByDepId(depId int) (users []SysUser, err error) {
  28. err = global.GVA_DB.Model(&SysUser{}).Where("department_id =?", depId).Find(&users).Error
  29. return users, err
  30. }
  31. // TODO:部门新增
  32. // CreateDep 创建部门
  33. func (d Department) CreateDep() error {
  34. return global.GVA_DB.Create(&d).Error
  35. }
  36. // TODO:部门修改
  37. // UpdateDep 修改部门
  38. func (d Department) UpdateDep() error {
  39. return global.GVA_DB.Model(&d).Updates(d).Error
  40. }
  41. // UpdateDepStatus 修改部门状态
  42. func UpdateDepStatus(depId int, isStart bool) error {
  43. return global.GVA_DB.Model(&Department{}).Where("id = ?", depId).Update("is_start", isStart).Error
  44. }
  45. // TODO:部门删除
  46. // DeleteDep 删除部门
  47. func DeleteDep(depId int) error {
  48. return global.GVA_DB.Where("id = ?", depId).Delete(&Department{}).Error
  49. }