organization.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. if info.PARENTCODE != "" {
  47. db.Where("PARENT_CODE=?", info.PARENTCODE)
  48. }
  49. var organizations []autocode.Organization
  50. // 如果有条件搜索 下方会自动创建搜索语句
  51. err = db.Count(&total).Error
  52. err = db.Limit(limit).Offset(offset).Find(&organizations).Error
  53. return err, organizations, total
  54. }
  55. func (organizationService *OrganizationService) GetOrganizationInfoLists() (err error, list []autocode.Organization) {
  56. // 创建db
  57. db := global.GVA_DB.Model(&autocode.Organization{})
  58. var organizations []autocode.Organization
  59. err = db.Find(&organizations).Error
  60. return err, organizations
  61. }
  62. func (organizationService *OrganizationService) GetBaseChildrenList(org *autocode.Organization, treeMap map[string][]autocode.Organization) (err error) {
  63. org.Children = treeMap[org.CODE]
  64. for i := 0; i < len(org.Children); i++ {
  65. err = organizationService.GetBaseChildrenList(&org.Children[i], treeMap)
  66. }
  67. return err
  68. }