智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 rivejä
3.7 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. if req.Pvd != 0 {
  34. sess.And("pvd = ?", req.Pvd)
  35. }
  36. if req.Mode != 0 {
  37. sess.And("mode = ?", req.Mode)
  38. }
  39. if req.State != 0 {
  40. sess.And("state = ?", req.State)
  41. }
  42. total, err = sess.FindAndCount(&m)
  43. if err != nil {
  44. return
  45. }
  46. return
  47. }
  48. func EnterpriseDetail(enterpriseId int) (data md.EnterpriseDetailResp, err error) {
  49. //1、查找所在单位
  50. enterpriseDb := db.EnterpriseDb{}
  51. enterpriseDb.Set()
  52. enterprise, err := enterpriseDb.GetEnterprise(enterpriseId)
  53. if err != nil {
  54. return
  55. }
  56. data.Enterprise = *enterprise
  57. //2、查找对应学段
  58. periodDb := db.PeriodDb{}
  59. periodDb.Set(enterpriseId)
  60. gradeDb := db.GradeDb{}
  61. gradeDb.Set(enterpriseId)
  62. classDb := db.ClassDb{}
  63. periodList, err := periodDb.FindPeriod()
  64. if err != nil {
  65. return
  66. }
  67. for _, v := range *periodList {
  68. //3、查找对应年级
  69. gradeList, err1 := gradeDb.FindGradeByPeriodId(v.Id)
  70. if err1 != nil {
  71. return
  72. }
  73. var tmpGradeListStruct []md.GradeListStruct
  74. for _, v1 := range *gradeList {
  75. //3、查找对应班级
  76. classDb.Set(v1.Id)
  77. classes, err2 := classDb.FindClass()
  78. if err2 != nil {
  79. err = err2
  80. return
  81. }
  82. tmpGradeListStruct = append(tmpGradeListStruct, md.GradeListStruct{
  83. Grade: v1,
  84. ClassList: *classes,
  85. })
  86. }
  87. data.PeriodList = append(data.PeriodList, md.PeriodListStruct{
  88. Period: v,
  89. GradeList: tmpGradeListStruct,
  90. })
  91. }
  92. return
  93. }
  94. func EnterpriseDetailV2(enterpriseId int) (data md.EnterpriseDetailRespV2, err error) {
  95. //1、查找所在单位
  96. enterpriseDb := db.EnterpriseDb{}
  97. enterpriseDb.Set()
  98. enterprise, err := enterpriseDb.GetEnterprise(enterpriseId)
  99. if err != nil {
  100. return
  101. }
  102. data.Enterprise = *enterprise
  103. //2、查找对应年级
  104. gradeDb := db.GradeDb{}
  105. gradeDb.Set(enterpriseId)
  106. gradeList, err := gradeDb.FindGrade()
  107. if err != nil {
  108. return
  109. }
  110. for _, v := range *gradeList {
  111. //3、查找对应班级
  112. classDb := db.ClassDb{}
  113. classDb.Set(v.Id)
  114. classes, err1 := classDb.FindClass()
  115. if err1 != nil {
  116. err = err1
  117. return
  118. }
  119. data.GradeList = append(data.GradeList, md.GradeListStructV2{
  120. Grade: v,
  121. ClassList: *classes,
  122. })
  123. }
  124. return
  125. }
  126. func EnterpriseDelete(enterpriseIds []int) (err error) {
  127. session := db.Db.NewSession()
  128. defer session.Close()
  129. session.Begin()
  130. //1、删除所在单位
  131. enterpriseDb := db.EnterpriseDb{}
  132. enterpriseDb.Set()
  133. _, err = enterpriseDb.EnterpriseDeleteBySession(session, enterpriseIds)
  134. if err != nil {
  135. _ = session.Rollback()
  136. return
  137. }
  138. //2、删除年级
  139. gradeDb := db.GradeDb{}
  140. gradeDb.Set(0)
  141. _, err = gradeDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds)
  142. if err != nil {
  143. _ = session.Rollback()
  144. return
  145. }
  146. //3、删除班级
  147. classDb := db.ClassDb{}
  148. classDb.Set(0)
  149. _, err = classDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds)
  150. if err != nil {
  151. _ = session.Rollback()
  152. return
  153. }
  154. return session.Commit()
  155. }