organization.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package autocode
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
  5. autoCodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
  6. )
  7. type OrganizationService struct {
  8. }
  9. // CreateOrganization 创建Organization记录
  10. // Author [piexlmax](https://github.com/piexlmax)
  11. func (organizationService *OrganizationService) CreateOrganization(organization autocode.Organization) (err error) {
  12. err = global.GVA_DB.Create(&organization).Error
  13. return err
  14. }
  15. // DeleteOrganization 删除Organization记录
  16. // Author [piexlmax](https://github.com/piexlmax)
  17. func (organizationService *OrganizationService) DeleteOrganization(organization autocode.Organization) (err error) {
  18. err = global.GVA_DB.Delete(&organization).Error
  19. return err
  20. }
  21. // DeleteOrganizationByIds 批量删除Organization记录
  22. // Author [piexlmax](https://github.com/piexlmax)
  23. func (organizationService *OrganizationService) DeleteOrganizationByIds(codes []string) (err error) {
  24. err = global.GVA_DB.Delete(&[]autocode.Organization{}, "code in ?", codes).Error
  25. return err
  26. }
  27. // UpdateOrganization 更新Organization记录
  28. // Author [piexlmax](https://github.com/piexlmax)
  29. func (organizationService *OrganizationService) UpdateOrganization(organization autocode.Organization) (err error) {
  30. err = global.GVA_DB.Save(&organization).Error
  31. return err
  32. }
  33. // GetOrganization 根据id获取Organization记录
  34. // Author [piexlmax](https://github.com/piexlmax)
  35. func (organizationService *OrganizationService) GetOrganization(code string) (err error, organization autocode.Organization) {
  36. err = global.GVA_DB.Where("code = ?", code).First(&organization).Error
  37. return
  38. }
  39. // GetOrganizationInfoList 分页获取Organization记录
  40. // Author [piexlmax](https://github.com/piexlmax)
  41. func (organizationService *OrganizationService) GetOrganizationInfoList(info autoCodeReq.OrganizationSearch) (err error, list []autocode.Organization, total int64) {
  42. limit := info.PageSize
  43. offset := info.PageSize * (info.Page - 1)
  44. // 创建db
  45. db := global.GVA_DB.Model(&autocode.Organization{})
  46. var organizations []autocode.Organization
  47. // 如果有条件搜索 下方会自动创建搜索语句
  48. err = db.Count(&total).Error
  49. err = db.Limit(limit).Offset(offset).Find(&organizations).Error
  50. return err, organizations, total
  51. }
  52. func (organizationService *OrganizationService) GetOrganizationInfoLists() (err error, list []autocode.Organization) {
  53. // 创建db
  54. db := global.GVA_DB.Model(&autocode.Organization{})
  55. var organizations []autocode.Organization
  56. err = db.Find(&organizations).Error
  57. return err, organizations
  58. }
  59. func (organizationService *OrganizationService) GetBaseChildrenList(org *autocode.Organization, treeMap map[string][]autocode.Organization) (err error) {
  60. org.Children = treeMap[org.CODE]
  61. for i := 0; i < len(org.Children); i++ {
  62. err = organizationService.GetBaseChildrenList(&org.Children[i], treeMap)
  63. }
  64. return err
  65. }