DengBiao преди 1 година
родител
ревизия
ee1007d5cb
променени са 3 файла, в които са добавени 169 реда и са изтрити 0 реда
  1. +150
    -0
      app/admin/hdl/hdl_enterprise.go
  2. +18
    -0
      app/admin/md/md_enterprise_v2.go
  3. +1
    -0
      app/router/admin_router.go

+ 150
- 0
app/admin/hdl/hdl_enterprise.go Целия файл

@@ -464,6 +464,156 @@ func EnterpriseUpdate(c *gin.Context) {
return
}

func EnterpriseUpdateV2(c *gin.Context) {
var req md.EnterpriseUpdateReqV2
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}

//1、更新 enterprise
enterpriseDb := db.EnterpriseDb{}
enterpriseDb.Set()
enterprise, err := enterpriseDb.GetEnterprise(req.Id)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
if enterprise == nil {
e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录")
return
}
var pvd = 2
if req.Kind == enum.EnterprisePvdByCentralKitchenForSchool || req.Kind == enum.EnterprisePvdByCentralKitchenForFactory || req.Kind == enum.EnterprisePvdByNursingHome {
pvd = 1
}

now := time.Now()
enterprise.Name = req.Name
enterprise.Memo = req.Memo
enterprise.Pvd = int32(pvd)
enterprise.Kind = req.Kind
enterprise.CompanyId = req.CompanyId
enterprise.UpdateAt = now.Format("2006-01-02 15:04:05")
_, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "memo", "pvd", "kind", "company_id", "update_at")
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}

//2、更新 grade && class 数据

//2、删除 grade && class 数据
gradeDb := db.GradeDb{}
gradeDb.Set(req.Id)
//_, err = gradeDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id)
//if err != nil {
// e.OutErr(c, e.ERR_DB_ORM, err.Error())
// return
//}
classDb := db.ClassDb{}
classDb.Set(0)
//_, err = classDb.ClassDeleteBySessionForEnterprise(db.Db.NewSession(), req.Id)
//if err != nil {
// e.OutErr(c, e.ERR_DB_ORM, err.Error())
// return
//}

//新增 grade 数据 && class 数据
for _, v := range req.GradeList {
var classes []*model.Class

if v.Id == 0 {
//TODO::新增
insertId, err1 := gradeDb.GradeInsert(&model.Grade{
EnterpriseId: req.Id,
Name: v.Name,
Memo: "",
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err1 != nil {
e.OutErr(c, e.ERR_DB_ORM, err1.Error())
return
}
for _, v1 := range v.ClassList {
classes = append(classes, &model.Class{
Name: v1.Name,
Memo: "",
GradeId: insertId,
EnterpriseId: req.Id,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
}

} else {
//TODO::编辑
grade, err3 := gradeDb.GetGrade(v.Id)
if err3 != nil {
e.OutErr(c, e.ERR_DB_ORM, err3.Error())
return
}
if grade == nil {
e.OutErr(c, e.ERR_NO_DATA, "未查询到相关年级信息")
return
}

grade.Name = v.Name
_, err4 := gradeDb.GradeUpdate(grade, "name")
if err4 != nil {
e.OutErr(c, e.ERR_DB_ORM, err4.Error())
return
}

for _, v1 := range v.ClassList {
if v1.Id == 0 {
//新增
classes = append(classes, &model.Class{
Name: v1.Name,
Memo: "",
GradeId: grade.Id,
EnterpriseId: req.Id,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
} else {
//编辑
class, err5 := classDb.GetClass(v1.Id)
if err5 != nil {
e.OutErr(c, e.ERR_DB_ORM, err5.Error())
return
}
if class == nil {
e.OutErr(c, e.ERR_NO_DATA, "未查询到相关班级信息")
return
}
class.Name = v1.Name
_, err6 := classDb.ClassUpdate(class, "name")
if err6 != nil {
e.OutErr(c, e.ERR_DB_ORM, err6.Error())
return
}
}
}
}

if len(classes) > 0 {
_, err2 := classDb.BatchAddClass(classes)
if err2 != nil {
e.OutErr(c, e.ERR_DB_ORM, err2.Error())
return
}
}
}

e.OutSuc(c, "success", nil)
return
}

func EnterpriseAddGrade(c *gin.Context) {
var req md.EnterpriseUpdateStateReq
err := c.ShouldBindJSON(&req)


+ 18
- 0
app/admin/md/md_enterprise_v2.go Целия файл

@@ -11,3 +11,21 @@ type GradeListStructV2 struct {
Grade model.Grade `json:"grade"`
ClassList []model.Class `json:"class_list"`
}

type EnterpriseUpdateReqV2 struct {
Id int `json:"id" binding:"required" label:"企业id"`
Name string `json:"name" binding:"required" label:"名称"`
Pvd int32 `json:"pvd" label:"场景"`
Kind int32 `json:"kind" binding:"required" label:"种类(1:央厨-学校 2:央厨-工厂 3:自营-学校 4:自营-工厂 5:养老院)"`
CompanyId int `json:"company_id" binding:"required" label:"所属公司id"`
Memo string `json:"memo" label:"备注"`
State int32 `json:"state" label:"状态"`
GradeList []struct {
Id int `json:"id" label:"年级id"`
Name string `json:"name" label:"名称"`
ClassList []struct {
Id int `json:"id" label:"班级id"`
Name string `json:"name" label:"名称"`
} `json:"class_list" label:"班级"`
} `json:"grade_list" label:"年级"`
}

+ 1
- 0
app/router/admin_router.go Целия файл

@@ -136,6 +136,7 @@ func rEnterprise(r *gin.RouterGroup) {
r.POST("/list", hdl2.EnterpriseList)
r.POST("/add", hdl2.EnterpriseAdd)
r.POST("/update", hdl2.EnterpriseUpdate)
r.POST("/updateV2", hdl2.EnterpriseUpdateV2)
r.POST("/delete", hdl2.EnterpriseDelete)
r.POST("/updateState", hdl2.EnterpriseUpdateState)
r.POST("/addGrade", hdl2.EnterpriseAddGrade)


Зареждане…
Отказ
Запис