智慧食堂
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

svc_enterprise.go 2.4 KiB

1 anno fa
1 anno fa
1 anno fa
1 anno fa
1 anno fa
1 anno fa
1 anno fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. gradeDb := db.GradeDb{}
  50. gradeDb.Set(enterpriseId)
  51. gradeList, err := gradeDb.FindGrade()
  52. if err != nil {
  53. return
  54. }
  55. for _, v := range *gradeList {
  56. //3、查找对应班级
  57. classDb := db.ClassDb{}
  58. classDb.Set(v.Id)
  59. classes, err1 := classDb.FindClass()
  60. if err1 != nil {
  61. err = err1
  62. return
  63. }
  64. data.GradeList = append(data.GradeList, md.GradeListStruct{
  65. Grade: v,
  66. ClassList: *classes,
  67. })
  68. }
  69. return
  70. }
  71. func EnterpriseDelete(enterpriseIds []int) (err error) {
  72. session := db.Db.NewSession()
  73. defer session.Close()
  74. session.Begin()
  75. //1、删除所在单位
  76. enterpriseDb := db.EnterpriseDb{}
  77. enterpriseDb.Set()
  78. _, err = enterpriseDb.EnterpriseDeleteBySession(session, enterpriseIds)
  79. if err != nil {
  80. _ = session.Rollback()
  81. return
  82. }
  83. //2、删除年级
  84. gradeDb := db.GradeDb{}
  85. gradeDb.Set(0)
  86. _, err = gradeDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds)
  87. if err != nil {
  88. _ = session.Rollback()
  89. return
  90. }
  91. //3、删除班级
  92. classDb := db.ClassDb{}
  93. classDb.Set(0)
  94. _, err = classDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds)
  95. if err != nil {
  96. _ = session.Rollback()
  97. return
  98. }
  99. return session.Commit()
  100. }