智慧食堂
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

128 Zeilen
2.8 KiB

  1. package svc
  2. import (
  3. enum2 "applet/app/admin/enum"
  4. "applet/app/admin/md"
  5. "applet/app/db"
  6. "applet/app/db/model"
  7. )
  8. func EnterpriseList(admin model.Admin, req md.EnterpriseListReq) (m []model.Enterprise, total int64, err error) {
  9. sess := db.Db.Desc("id")
  10. if admin.IsSuperAdministrator != enum2.IsSuperAdministratorTure {
  11. adminWithEnterpriseDb := db.AdminWithEnterpriseDb{}
  12. adminWithEnterpriseDb.Set()
  13. adminWithEnterprise, err1 := adminWithEnterpriseDb.FindAdminWithEnterprise(admin.AdmId)
  14. if err1 != nil {
  15. return nil, 0, err1
  16. }
  17. var enterPriseIds []int
  18. for _, v1 := range *adminWithEnterprise {
  19. enterPriseIds = append(enterPriseIds, v1.EnterpriseId)
  20. }
  21. if len(enterPriseIds) == 0 {
  22. return
  23. }
  24. sess.In("id", enterPriseIds)
  25. }
  26. sess.Limit(req.Limit, (req.Page-1)*req.Limit)
  27. if req.Name != "" {
  28. sess.And("name like ?", "%"+req.Name+"%")
  29. }
  30. if req.Kind != 0 {
  31. sess.And("kind = ?", req.Kind)
  32. }
  33. total, err = sess.FindAndCount(&m)
  34. if err != nil {
  35. return
  36. }
  37. return
  38. }
  39. func EnterpriseDetail(enterpriseId int) (data md.EnterpriseDetailResp, err error) {
  40. //1、查找所在单位
  41. enterpriseDb := db.EnterpriseDb{}
  42. enterpriseDb.Set()
  43. enterprise, err := enterpriseDb.GetEnterprise(enterpriseId)
  44. if err != nil {
  45. return
  46. }
  47. data.Enterprise = *enterprise
  48. //2、查找对应学段
  49. periodDb := db.PeriodDb{}
  50. periodDb.Set(enterpriseId)
  51. gradeDb := db.GradeDb{}
  52. gradeDb.Set(enterpriseId)
  53. classDb := db.ClassDb{}
  54. periodList, err := periodDb.FindPeriod()
  55. if err != nil {
  56. return
  57. }
  58. for _, v := range *periodList {
  59. //3、查找对应年级
  60. gradeList, err1 := gradeDb.FindGradeByPeriodId(v.Id)
  61. if err1 != nil {
  62. return
  63. }
  64. var tmpGradeListStruct []md.GradeListStruct
  65. for _, v1 := range *gradeList {
  66. //3、查找对应班级
  67. classDb.Set(v1.Id)
  68. classes, err2 := classDb.FindClass()
  69. if err2 != nil {
  70. err = err2
  71. return
  72. }
  73. tmpGradeListStruct = append(tmpGradeListStruct, md.GradeListStruct{
  74. Grade: v1,
  75. ClassList: *classes,
  76. })
  77. }
  78. data.PeriodList = append(data.PeriodList, md.PeriodListStruct{
  79. Period: v,
  80. GradeList: tmpGradeListStruct,
  81. })
  82. }
  83. return
  84. }
  85. func EnterpriseDelete(enterpriseIds []int) (err error) {
  86. session := db.Db.NewSession()
  87. defer session.Close()
  88. session.Begin()
  89. //1、删除所在单位
  90. enterpriseDb := db.EnterpriseDb{}
  91. enterpriseDb.Set()
  92. _, err = enterpriseDb.EnterpriseDeleteBySession(session, enterpriseIds)
  93. if err != nil {
  94. _ = session.Rollback()
  95. return
  96. }
  97. //2、删除年级
  98. gradeDb := db.GradeDb{}
  99. gradeDb.Set(0)
  100. _, err = gradeDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds)
  101. if err != nil {
  102. _ = session.Rollback()
  103. return
  104. }
  105. //3、删除班级
  106. classDb := db.ClassDb{}
  107. classDb.Set(0)
  108. _, err = classDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds)
  109. if err != nil {
  110. _ = session.Rollback()
  111. return
  112. }
  113. return session.Commit()
  114. }