Commit 0697acd4 authored by haoyanbin's avatar haoyanbin

User

parent f1b3496a
......@@ -88,6 +88,7 @@ func (e *SysDept) Insert(c *dto.SysDeptInsertReq) error {
e.Log.Errorf("db error:%s", err)
return err
}
c.DeptId = data.DeptId
return nil
}
......
......@@ -123,6 +123,30 @@ func (e OrgClub) Insert(c *gin.Context) {
return
}
sSysDept := sService.SysDept{}
reqSysDept := sDto.SysDeptInsertReq{}
err = e.MakeContext(c).
MakeOrm().
MakeService(&sSysDept.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
reqSysDept.ParentId = 1
reqSysDept.DeptName = req.ClubName
reqSysDept.Leader = req.ClubContacts
reqSysDept.Status = 2
// 设置创建人
reqSysDept.SetCreateBy(user.GetUserId(c))
err = sSysDept.Insert(&reqSysDept)
if err != nil {
e.Error(500, err, "创建失败")
return
}
sSysUser := sService.SysUser{}
reqSysUser := sDto.SysUserInsertReq{}
e.MakeContext(c).MakeOrm().MakeService(&sSysUser.Service)
......@@ -135,8 +159,8 @@ func (e OrgClub) Insert(c *gin.Context) {
reqSysUser.Avatar = ""
reqSysUser.Sex = "0"
reqSysUser.Email = ""
reqSysUser.DeptId = 1
reqSysUser.PostId = 1
reqSysUser.DeptId = reqSysDept.DeptId
reqSysUser.PostId = 6
reqSysUser.Remark = "俱乐部"
reqSysUser.Status = "2"
reqSysUser.UserType = "3"
......
......@@ -6,6 +6,8 @@ import (
"github.com/go-admin-team/go-admin-core/sdk/api"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
sService "go-admin/app/admin/service"
sDto "go-admin/app/admin/service/dto"
"strconv"
"go-admin/app/operate/models"
......@@ -134,8 +136,9 @@ func (e OrgTeam) Insert(c *gin.Context) {
e.Error(500, err, err.Error())
return
}
userId := user.GetUserId(c)
// 设置创建人
req.SetCreateBy(user.GetUserId(c))
req.CreateBy = userId
err = s.Insert(&req)
if err != nil {
......@@ -143,6 +146,32 @@ func (e OrgTeam) Insert(c *gin.Context) {
return
}
sSysDept := sService.SysDept{}
reqSysDept := sDto.SysDeptInsertReq{}
err = e.MakeContext(c).
MakeOrm().
MakeService(&sSysDept.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
_, reqSysDept.ParentId = s.GetParentDeptId(req.ClubId)
_, reqSysDept.DeptName = s.GetTeamName(req.Id)
reqSysDept.Leader = reqSysDept.DeptName
reqSysDept.Status = 2
// 设置创建人
reqSysDept.CreateBy = userId
err = sSysDept.Insert(&reqSysDept)
if err != nil {
e.Error(500, err, "创建失败")
return
}
s.InsertTeamDept(req.Id, reqSysDept.DeptId)
e.OK(req.GetId(), "创建成功")
}
......
......@@ -113,6 +113,7 @@ func (e OrgTeamUser) Insert(c *gin.Context) {
e.Error(500, err, err.Error())
return
}
sSysUser := sService.SysUser{}
reqSysUser := sDto.SysUserInsertReq{}
e.MakeContext(c).MakeOrm().MakeService(&sSysUser.Service)
......@@ -125,8 +126,8 @@ func (e OrgTeamUser) Insert(c *gin.Context) {
reqSysUser.Avatar = ""
reqSysUser.Sex = req.Sex
reqSysUser.Email = ""
reqSysUser.DeptId = 1
reqSysUser.PostId = 1
_, reqSysUser.DeptId = s.GetParentDeptId(req.TeamId)
reqSysUser.PostId = 7
reqSysUser.Remark = "球队工作人员"
reqSysUser.Status = "2"
reqSysUser.UserType = "4"
......
package models
import (
// "gorm.io/gorm"
"go-admin/common/models"
)
type OrgTeamDept struct {
models.Model
TeamId int `json:"teamId" gorm:"type:bigint(20);comment:TeamId"`
DeptId int `json:"deptId" gorm:"type:bigint(20);comment:DeptId"`
models.ModelTime
models.ControlBy
}
func (OrgTeamDept) TableName() string {
return "org_team_dept"
}
func (e *OrgTeamDept) Generate() models.ActiveRecord {
o := *e
return &o
}
func (e *OrgTeamDept) GetId() interface{} {
return e.Id
}
......@@ -99,3 +99,8 @@ type OrgTeamDeleteReq struct {
func (s *OrgTeamDeleteReq) GetId() interface{} {
return s.Ids
}
type Dept struct {
Id int `json:"id"`
DeptId int `json:"deptId"`
}
......@@ -114,3 +114,47 @@ func (e *OrgTeam) Remove(d *dto.OrgTeamDeleteReq, p *actions.DataPermission) err
}
return nil
}
// 根据工作人员id获取userId
func (e *OrgTeam) GetTeamName(teamId int) (error, string) {
data := new(models.OrgTeam)
err := e.Orm.Table("org_team").
Select("team_name").
Where("id=?", teamId).
First(&data).Error
if err != nil {
e.Log.Errorf("db error:%s", err)
return err, ""
}
return nil, data.TeamName
}
func (e *OrgTeam) GetParentDeptId(clubId string) (error, int) {
data := dto.Dept{}
err := e.Orm.Table("org_club_user as ocu").
Select("ocu.id, su.dept_id").
Joins("left join sys_user as su on su.user_id=ocu.user_id").
Where("id=?", clubId).
First(&data).Error
if err != nil {
e.Log.Errorf("db error:%s", err)
return err, 0
}
return nil, data.DeptId
}
// Insert 创建OrgTeam对象
func (e *OrgTeam) InsertTeamDept(teamId int, deptId int) error {
var err error
var data models.OrgTeamDept
data.TeamId = teamId
data.DeptId = deptId
err = e.Orm.Table("org_team_dept").Create(&data).Error
if err != nil {
e.Log.Errorf("OrgTeamService Insert error:%s \r\n", err)
return err
}
return nil
}
......@@ -182,3 +182,17 @@ func (e *OrgTeamUser) GetUserId(teamUserId int) (error, string) {
}
return nil, data.UserId
}
func (e *OrgTeamUser) GetParentDeptId(teamId string) (error, int) {
data := dto.Dept{}
err := e.Orm.Table("org_team_dept").
Select("dept_id").
Where("team_id=?", teamId).
First(&data).Error
if err != nil {
e.Log.Errorf("db error:%s", err)
return err, 0
}
return nil, data.DeptId
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment