소스 검색

update

add_mode
DengBiao 1 년 전
부모
커밋
99ba9c7cf4
7개의 변경된 파일356개의 추가작업 그리고 5개의 파일을 삭제
  1. +58
    -0
      app/admin/hdl/hdl_user.go
  2. +16
    -2
      app/admin/md/md_enterprise_manage.go
  3. +159
    -0
      app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go
  4. +83
    -2
      app/admin/svc/enterprise_manage/svc_enterprise_manage.go
  5. +9
    -0
      app/db/db_user.go
  6. +26
    -0
      app/db/db_user_identity.go
  7. +5
    -1
      app/router/admin_router.go

+ 58
- 0
app/admin/hdl/hdl_user.go 파일 보기

@@ -4,6 +4,7 @@ import (
"applet/app/admin/lib/validate"
"applet/app/admin/md"
"applet/app/admin/svc"
svc2 "applet/app/admin/svc/enterprise_manage"
"applet/app/db"
"applet/app/e"
"applet/app/enum"
@@ -80,6 +81,63 @@ func UserList(c *gin.Context) {
return
}

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

resp, err := svc2.EnterpriseUserListByCentralKitchenForSchoolV2(req)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
e.OutSuc(c, resp, nil)
return
}

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

err = svc2.CentralKitchenForSchoolUserUpdateV2(req)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
e.OutSuc(c, "success", nil)
return
}

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

err = svc2.CentralKitchenForSchoolUserDeleteV2(req)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
e.OutSuc(c, "success", nil)
return
}

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


+ 16
- 2
app/admin/md/md_enterprise_manage.go 파일 보기

@@ -1,7 +1,7 @@
package md

type EnterpriseUserListReq struct {
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"`
EnterpriseId int `json:"enterprise_id" label:"企业id"`
Limit int `json:"limit" binding:"required"`
Page int `json:"page" binding:"required"`
Nickname string `json:"nickname" label:"支付宝昵称"`
@@ -48,8 +48,22 @@ type CentralKitchenForSchoolUserUpdateReq struct {
} `json:"user_identities" label:"身份列表"`
}

type CentralKitchenForSchoolUserUpdateReqV2 struct {
Uid int `json:"uid" binding:"required" label:"用户id"`
Nickname string `json:"nickname" binding:"required" label:"支付宝昵称"`
Phone string `json:"phone" binding:"required" label:"手机号"`
BindUserIdentities []struct {
EnterpriseId int `json:"enterprise_id" label:"企业id"`
UserIdentityId int `json:"user_identity_id" label:"用户身份id"`
IdNo string `json:"id_no" label:"身份证号"`
Name string `json:"name" label:"姓名"`
GradeId int `json:"grade_id" label:"年级"`
ClassId int `json:"class_id" label:"班级"`
} `json:"user_identities" label:"身份列表"`
}

type CentralKitchenForSchoolUserDeleteReq struct {
EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"`
EnterpriseId int `json:"enterprise_id" label:"企业id"`
Uids []int `json:"uids" binding:"required" label:"用户id"`
}



+ 159
- 0
app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go 파일 보기

@@ -145,6 +145,139 @@ func CentralKitchenForSchoolUserUpdate(req md.CentralKitchenForSchoolUserUpdateR
return session.Commit()
}

func CentralKitchenForSchoolUserUpdateV2(req md.CentralKitchenForSchoolUserUpdateReqV2) (err error) {
//1、删除当前用户&&央厨学校下的所有身份对应的 `class_with_user` 记录
var userIdentities []model.UserIdentity
err = db.Db.Where("uid =?", req.Uid).And("identity =? or identity =?", enum2.UserIdentityForCentralKitchenForTeacher, enum2.UserIdentityForCentralKitchenForStudent).Find(&userIdentities)
if err != nil {
return
}
var userIdentityIds []int
for _, v := range userIdentities {
userIdentityIds = append(userIdentityIds, v.Id)
}
_, err = db.Db.In("user_identity_id", userIdentityIds).Delete(model.ClassWithUser{})
if err != nil {
return
}

session := db.Db.NewSession()
defer session.Close()
session.Begin()

//2、新增 / 编辑 数据
now := time.Now()
userIdentityDb := db.UserIdentityDb{}
userIdentityDb.Set(req.Uid)

classWithUserDb := db.ClassWithUserDb{}
classWithUserDb.Set()

var newUserIdentityIds []string
for _, v := range req.BindUserIdentities {
if v.UserIdentityId == 0 {
// 新增
if v.ClassId == -1 {
//TODO::为老师身份
_, err3 := userIdentityDb.UserIdentityInsertBySession(session, &model.UserIdentity{
Uid: req.Uid,
Name: v.Name,
IdNo: v.IdNo,
Kind: enum2.UserIdentityKindForCommon,
Identity: enum2.UserIdentityForCentralKitchenForTeacher,
EnterpriseId: v.EnterpriseId,
State: enum2.UserIdentityStateForNormal,
Memo: "",
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err3 != nil {
_ = session.Rollback()
return err3
}
continue
}

insertId, err1 := userIdentityDb.UserIdentityInsertBySession(session, &model.UserIdentity{
Uid: req.Uid,
Name: v.Name,
IdNo: v.IdNo,
Kind: enum2.UserIdentityKindForCommon,
Identity: enum2.UserIdentityForCentralKitchenForStudent,
EnterpriseId: v.EnterpriseId,
State: enum2.UserIdentityStateForNormal,
Memo: "",
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err1 != nil {
_ = session.Rollback()
return err1
}

_, err2 := classWithUserDb.ClassWithUserInsertBySession(session, &model.ClassWithUser{
UserIdentityId: insertId,
ClassId: v.ClassId,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err2 != nil {
_ = session.Rollback()
return err1
}

newUserIdentityIds = append(newUserIdentityIds, utils.IntToStr(insertId))
} else {
//编辑
identity, err2 := userIdentityDb.GetUserIdentity(v.UserIdentityId)
if err != nil {
_ = session.Rollback()
return err2
}
if identity == nil {
_ = session.Rollback()
return errors.New("未查询到对应的身份信息记录")
}
identity.IdNo = v.IdNo
identity.Name = v.Name
if v.ClassId == -1 {
//TODO::为老师身份
identity.Identity = enum2.UserIdentityForCentralKitchenForTeacher
} else {
_, err3 := classWithUserDb.ClassWithUserInsertBySession(session, &model.ClassWithUser{
UserIdentityId: v.UserIdentityId,
ClassId: v.ClassId,
CreateAt: now.Format("2006-01-02 15:04:05"),
UpdateAt: now.Format("2006-01-02 15:04:05"),
})
if err3 != nil {
_ = session.Rollback()
return err3
}
}
_, err3 := userIdentityDb.UserIdentityUpdateBySession(session, v.UserIdentityId, identity, "id_no", "name", "identity")
if err3 != nil {
_ = session.Rollback()
return err3
}

newUserIdentityIds = append(newUserIdentityIds, utils.IntToStr(v.UserIdentityId))
}
}

//3、删除需要删除的身份信息
for _, v := range userIdentityIds {
if !utils.InArr(utils.IntToStr(v), newUserIdentityIds) {
_, err = session.Where("id = ?", v).Delete(model.UserIdentity{})
if err != nil {
_ = session.Rollback()
return
}
}
}
return session.Commit()
}

func CentralKitchenForSchoolUserDelete(req md.CentralKitchenForSchoolUserDeleteReq) (err error) {
//1、删除 class_with_user
var userIdentities []model.UserIdentity
@@ -169,6 +302,32 @@ func CentralKitchenForSchoolUserDelete(req md.CentralKitchenForSchoolUserDeleteR
return
}

func CentralKitchenForSchoolUserDeleteV2(req md.CentralKitchenForSchoolUserDeleteReq) (err error) {
//1、删除 class_with_user
var userIdentities []model.UserIdentity
err = db.Db.Where("identity =? or identity =?", enum2.UserIdentityForCentralKitchenForTeacher, enum2.UserIdentityForCentralKitchenForStudent).
In("uid", req.Uids).Find(&userIdentities)
if err != nil {
return
}
var userIdentityIds []int
for _, v := range userIdentities {
userIdentityIds = append(userIdentityIds, v.Id)
}
_, err = db.Db.In("user_identity_id", userIdentityIds).Delete(model.ClassWithUser{})
if err != nil {
return
}

//2、删除 user_identity
_, err = db.Db.Where("identity =? or identity =?", enum2.UserIdentityForCentralKitchenForTeacher, enum2.UserIdentityForCentralKitchenForStudent).
Delete(model.UserIdentity{})
if err != nil {
return
}
return
}

func CentralKitchenForSchoolStudentList(req md.CentralKitchenForSchoolStudentListReq) (resp []md.CentralKitchenForSchoolStudentListResp, count int64, err error) {
var classWithUserIdentityIdsOne []int
var classWithUserIdentityIdsTwo []int


+ 83
- 2
app/admin/svc/enterprise_manage/svc_enterprise_manage.go 파일 보기

@@ -64,7 +64,6 @@ func EnterpriseUserListByCentralKitchenForSchool(req md.EnterpriseUserListReq) (
CreateAt: v.CreateAt,
}
for _, v1 := range userIdentitiesMap[utils.IntToStr(v.Id)] {
fmt.Println(">>>>>>>>>>>>", userIdentitiesMap[utils.IntToStr(v.Id)])
//TODO::判断是否为老师
if v1.Identity == enum2.UserIdentityForCentralKitchenForTeacher {
temp.UserIdentities = append(temp.UserIdentities, struct {
@@ -103,6 +102,89 @@ func EnterpriseUserListByCentralKitchenForSchool(req md.EnterpriseUserListReq) (
return
}

func EnterpriseUserListByCentralKitchenForSchoolV2(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByCentralKitchenForSchoolResp, err error) {
sess := db.Db.Desc("user.id")
if req.Nickname != "" {
sess.And("user.nickname like ?", "%"+req.Nickname+"%")
}
if req.Phone != "" {
sess.And("user.phone like ?", "%"+req.Phone+"%")
}
if req.IsTeacher == 1 {
sess.And("user.phone like ?", "%"+req.Phone+"%")
}
if req.IsTeacher == 0 {
sess.And("user_identity.identity = ? or user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForTeacher, enum2.UserIdentityForCentralKitchenForStudent)
}
if req.IsTeacher == 1 {
sess.And("user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForTeacher)
}
if req.IsTeacher == 2 {
sess.And("user_identity.identity = ?", enum2.UserIdentityForCentralKitchenForStudent)
}
var m []*db.UserWithUserIdentity
count, err := sess.
Join("LEFT", "user_identity", "user.id = user_identity.uid").
Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m)

var userIdentitiesMap = map[string][]db.UserIdentityWithClass{}
userIdentityDb := db.UserIdentityDb{}
for _, v := range m {
userIdentityDb.Set(v.User.Id)
userIdentities, err1 := userIdentityDb.FindUserIdentityWithClass()
if err1 != nil {
return resp, err1
}
for _, v1 := range *userIdentities {
userIdentitiesMap[utils.IntToStr(v1.Uid)] = append(userIdentitiesMap[utils.IntToStr(v1.Uid)], v1)
}
}
fmt.Println("!!!!!!!!!")
resp.Total = count
classWithUserDb := db.ClassWithUserDb{}
classWithUserDb.Set()
for _, v := range m {
temp := md.EnterpriseUserListByCentralKitchenForSchoolStruct{
Id: v.User.Id,
Nickname: v.Nickname,
Phone: v.Phone,
Avatar: v.Avatar,
IsTeacher: 0,
CreateAt: v.User.CreateAt,
}
for _, v1 := range userIdentitiesMap[utils.IntToStr(v.User.Id)] {
//TODO::判断是否为老师
if v1.Identity == enum2.UserIdentityForCentralKitchenForTeacher {
temp.UserIdentities = append(temp.UserIdentities, struct {
Id int `json:"id" label:"身份id"`
IdNo string `json:"id_no" label:"身份证号"`
SchoolName string `json:"school_name" label:"学校名"`
Name string `json:"name" label:"姓名"`
Grade string `json:"grade" label:"年级"`
GradeId int `json:"grade_id" label:"年级id"`
Class string `json:"class" label:"班级"`
ClassId int `json:"class_id" label:"班级id"`
}{Id: v1.UserIdentity.Id, IdNo: v1.IdNo, SchoolName: "教师", Name: v1.UserIdentity.Name, Grade: "教师", Class: "教师", GradeId: 0, ClassId: 0})
temp.IsTeacher = 1
}
if v1.Identity == enum2.UserIdentityForCentralKitchenForStudent {
temp.UserIdentities = append(temp.UserIdentities, struct {
Id int `json:"id" label:"身份id"`
IdNo string `json:"id_no" label:"身份证号"`
SchoolName string `json:"school_name" label:"学校名"`
Name string `json:"name" label:"姓名"`
Grade string `json:"grade" label:"年级"`
GradeId int `json:"grade_id" label:"年级id"`
Class string `json:"class" label:"班级"`
ClassId int `json:"class_id" label:"班级id"`
}{Id: v1.UserIdentity.Id, IdNo: v1.UserIdentity.IdNo, SchoolName: v1.Enterprise.Name, Name: v1.UserIdentity.Name, Grade: v1.Grade.Name, Class: v1.Class.Name, GradeId: v1.Grade.Id, ClassId: v1.Class.Id})
}
}
resp.List = append(resp.List, temp)
}
return
}

func EnterpriseUserListByNursingHome(req md.EnterpriseUserListReq) (resp md.EnterpriseUserListByNursingHomeResp, err error) {
//1、判断是否过滤 "教师"
userIdentityDb := db.UserIdentityDb{}
@@ -140,7 +222,6 @@ func EnterpriseUserListByNursingHome(req md.EnterpriseUserListReq) (resp md.Ente
CreateAt: v.CreateAt,
}
for _, v1 := range userIdentitiesMap[utils.IntToStr(v.Id)] {
fmt.Println(">>>>>>>>>>>>", userIdentitiesMap[utils.IntToStr(v.Id)])
temp.UserIdentities = append(temp.UserIdentities, struct {
Id int `json:"id" label:"身份id"`
IdNo string `json:"id_no" label:"身份证号"`


+ 9
- 0
app/db/db_user.go 파일 보기

@@ -89,3 +89,12 @@ func (userDb *UserDb) DeleteUser(id interface{}) (int64, error) {
return userDb.Db.Where("enterprise_id = ?", id).Delete(model.User{})
}
}

type UserWithUserIdentity struct {
model.User `xorm:"extends"`
model.UserIdentity `xorm:"extends"`
}

func (UserWithUserIdentity) TableName() string {
return "user"
}

+ 26
- 0
app/db/db_user_identity.go 파일 보기

@@ -81,6 +81,20 @@ func (userIdentityDb *UserIdentityDb) FindUserIdentity() (*[]UserIdentityWithEnt
return &m, nil
}

func (userIdentityDb *UserIdentityDb) FindUserIdentityWithClass() (*[]UserIdentityWithClass, error) {
var m []UserIdentityWithClass
if err := userIdentityDb.Db.
Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id").
Join("LEFT", "class_with_user", "user_identity.id = class_with_user.user_identity_id").
Join("LEFT", "class", "class_with_user.class_id = class.id").
Join("LEFT", "grade", "class.grade_id = grade.id").
Where("user_identity.state =?", enum.UserIdentityStateForNormal).
And("user_identity.uid =?", userIdentityDb.Uid).Desc("user_identity.id").Find(&m); err != nil {
return nil, logx.Error(err)
}
return &m, nil
}

func (userIdentityDb *UserIdentityDb) UserIdentity(id int) (m *UserIdentityWithEnterprise, err error) {
m = new(UserIdentityWithEnterprise)
has, err := userIdentityDb.Db.Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id").
@@ -205,3 +219,15 @@ type UserIdentityWithEnterprise struct {
func (UserIdentityWithEnterprise) TableName() string {
return "user_identity"
}

type UserIdentityWithClass struct {
model.UserIdentity `xorm:"extends"`
model.Enterprise `xorm:"extends"`
model.ClassWithUser `xorm:"extends"`
model.Class `xorm:"extends"`
model.Grade `xorm:"extends"`
}

func (UserIdentityWithClass) TableName() string {
return "user_identity"
}

+ 5
- 1
app/router/admin_router.go 파일 보기

@@ -114,7 +114,11 @@ func rDataStatistics(r *gin.RouterGroup) {
}

func rUser(r *gin.RouterGroup) {
r.POST("/list", hdl2.UserList) //列表
r.POST("/list", hdl2.UserList) //列表
r.POST("centralKitchenForSchool/list", hdl2.CentralKitchenForSchoolUserList) //央厨用户列表
r.POST("/centralKitchenForSchool/userUpdate", hdl2.CentralKitchenForSchoolUserUpdate) //"央厨-学校"用户编辑
r.POST("/centralKitchenForSchool/userDelete", hdl2.CentralKitchenForSchoolUserDelete) //"央厨-学校"用户删除

r.POST("/update", hdl2.UserUpdate) //编辑
r.DELETE("/delete/:id", hdl2.UserDelete) //删除
}


불러오는 중...
취소
저장