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

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