智慧食堂
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.

svc_enterprise.go 3.6 KiB

1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 EnterpriseDetailV2(enterpriseId int) (data md.EnterpriseDetailRespV2, err error) {
  86. //1、查找所在单位
  87. enterpriseDb := db.EnterpriseDb{}
  88. enterpriseDb.Set()
  89. enterprise, err := enterpriseDb.GetEnterprise(enterpriseId)
  90. if err != nil {
  91. return
  92. }
  93. data.Enterprise = *enterprise
  94. //2、查找对应年级
  95. gradeDb := db.GradeDb{}
  96. gradeDb.Set(enterpriseId)
  97. gradeList, err := gradeDb.FindGrade()
  98. if err != nil {
  99. return
  100. }
  101. for _, v := range *gradeList {
  102. //3、查找对应班级
  103. classDb := db.ClassDb{}
  104. classDb.Set(v.Id)
  105. classes, err1 := classDb.FindClass()
  106. if err1 != nil {
  107. err = err1
  108. return
  109. }
  110. data.GradeList = append(data.GradeList, md.GradeListStructV2{
  111. Grade: v,
  112. ClassList: *classes,
  113. })
  114. }
  115. return
  116. }
  117. func EnterpriseDelete(enterpriseIds []int) (err error) {
  118. session := db.Db.NewSession()
  119. defer session.Close()
  120. session.Begin()
  121. //1、删除所在单位
  122. enterpriseDb := db.EnterpriseDb{}
  123. enterpriseDb.Set()
  124. _, err = enterpriseDb.EnterpriseDeleteBySession(session, enterpriseIds)
  125. if err != nil {
  126. _ = session.Rollback()
  127. return
  128. }
  129. //2、删除年级
  130. gradeDb := db.GradeDb{}
  131. gradeDb.Set(0)
  132. _, err = gradeDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds)
  133. if err != nil {
  134. _ = session.Rollback()
  135. return
  136. }
  137. //3、删除班级
  138. classDb := db.ClassDb{}
  139. classDb.Set(0)
  140. _, err = classDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds)
  141. if err != nil {
  142. _ = session.Rollback()
  143. return
  144. }
  145. return session.Commit()
  146. }