|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 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()
- }
|