|
|
@@ -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) |
|
|
|