智慧食堂
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

92 行
1.9 KiB

  1. package svc
  2. import (
  3. "applet/app/admin/md"
  4. "applet/app/db"
  5. "applet/app/db/model"
  6. )
  7. func EnterpriseList(req md.EnterpriseListReq) (m []model.Enterprise, total int64, err error) {
  8. sess := db.Db.Desc("id").Limit(req.Limit, (req.Page-1)*req.Limit)
  9. if req.Name != "" {
  10. sess.And("name like ?", "%"+req.Name+"%")
  11. }
  12. if req.Kind != 0 {
  13. sess.And("kind = ?", req.Kind)
  14. }
  15. total, err = sess.FindAndCount(&m)
  16. if err != nil {
  17. return
  18. }
  19. return
  20. }
  21. func EnterpriseDetail(enterpriseId int) (data md.EnterpriseDetailResp, err error) {
  22. //1、查找所在单位
  23. enterpriseDb := db.EnterpriseDb{}
  24. enterpriseDb.Set()
  25. enterprise, err := enterpriseDb.GetEnterprise(enterpriseId)
  26. if err != nil {
  27. return
  28. }
  29. data.Enterprise = *enterprise
  30. //2、查找对应年级
  31. gradeDb := db.GradeDb{}
  32. gradeDb.Set(enterpriseId)
  33. gradeList, err := gradeDb.FindGrade()
  34. if err != nil {
  35. return
  36. }
  37. for _, v := range *gradeList {
  38. //3、查找对应班级
  39. classDb := db.ClassDb{}
  40. classDb.Set(v.Id)
  41. classes, err1 := classDb.FindClass()
  42. if err1 != nil {
  43. err = err1
  44. return
  45. }
  46. data.GradeList = append(data.GradeList, md.GradeListStruct{
  47. Grade: v,
  48. ClassList: *classes,
  49. })
  50. }
  51. return
  52. }
  53. func EnterpriseDelete(enterpriseIds []int) (err error) {
  54. session := db.Db.NewSession()
  55. defer session.Close()
  56. session.Begin()
  57. //1、删除所在单位
  58. enterpriseDb := db.EnterpriseDb{}
  59. enterpriseDb.Set()
  60. _, err = enterpriseDb.EnterpriseDeleteBySession(session, enterpriseIds)
  61. if err != nil {
  62. _ = session.Rollback()
  63. return
  64. }
  65. //2、删除年级
  66. gradeDb := db.GradeDb{}
  67. gradeDb.Set(0)
  68. _, err = gradeDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds)
  69. if err != nil {
  70. _ = session.Rollback()
  71. return
  72. }
  73. //3、删除班级
  74. classDb := db.ClassDb{}
  75. classDb.Set(0)
  76. _, err = classDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds)
  77. if err != nil {
  78. _ = session.Rollback()
  79. return
  80. }
  81. return session.Commit()
  82. }