package svc import ( enum2 "applet/app/admin/enum" "applet/app/admin/md" "applet/app/db" "applet/app/db/model" ) func EnterpriseList(admin model.Admin, req md.EnterpriseListReq) (m []model.Enterprise, total int64, err error) { sess := db.Db.Desc("id") if admin.IsSuperAdministrator != enum2.IsSuperAdministratorTure { adminWithEnterpriseDb := db.AdminWithEnterpriseDb{} adminWithEnterpriseDb.Set() adminWithEnterprise, err1 := adminWithEnterpriseDb.FindAdminWithEnterprise(admin.AdmId) if err1 != nil { return nil, 0, err1 } var enterPriseIds []int for _, v1 := range *adminWithEnterprise { enterPriseIds = append(enterPriseIds, v1.EnterpriseId) } if len(enterPriseIds) == 0 { return } sess.In("id", enterPriseIds) } sess.Limit(req.Limit, (req.Page-1)*req.Limit) if req.Name != "" { sess.And("name like ?", "%"+req.Name+"%") } if req.Kind != 0 { sess.And("kind = ?", req.Kind) } total, err = sess.FindAndCount(&m) if err != nil { return } return } func EnterpriseDetail(enterpriseId int) (data md.EnterpriseDetailResp, err error) { //1、查找所在单位 enterpriseDb := db.EnterpriseDb{} enterpriseDb.Set() enterprise, err := enterpriseDb.GetEnterprise(enterpriseId) if err != nil { return } data.Enterprise = *enterprise //2、查找对应年级 gradeDb := db.GradeDb{} gradeDb.Set(enterpriseId) gradeList, err := gradeDb.FindGrade() if err != nil { return } for _, v := range *gradeList { //3、查找对应班级 classDb := db.ClassDb{} classDb.Set(v.Id) classes, err1 := classDb.FindClass() if err1 != nil { err = err1 return } data.GradeList = append(data.GradeList, md.GradeListStruct{ Grade: v, ClassList: *classes, }) } return } func EnterpriseDelete(enterpriseIds []int) (err error) { session := db.Db.NewSession() defer session.Close() session.Begin() //1、删除所在单位 enterpriseDb := db.EnterpriseDb{} enterpriseDb.Set() _, err = enterpriseDb.EnterpriseDeleteBySession(session, enterpriseIds) if err != nil { _ = session.Rollback() return } //2、删除年级 gradeDb := db.GradeDb{} gradeDb.Set(0) _, err = gradeDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds) if err != nil { _ = session.Rollback() return } //3、删除班级 classDb := db.ClassDb{} classDb.Set(0) _, err = classDb.ClassDeleteBySessionForEnterprise(session, enterpriseIds) if err != nil { _ = session.Rollback() return } return session.Commit() }