...
|
...
|
@@ -15,16 +15,60 @@ import ( |
|
|
|
|
|
//同步 人员数据
|
|
|
|
|
|
//--------------------
|
|
|
type UserDepartData struct {
|
|
|
Id int64 `json:"id"`
|
|
|
CompanyId int64 `json:"company_id"`
|
|
|
DepartmentId int64 `json:"department_id"`
|
|
|
UserId int64 `json:"user_id"`
|
|
|
}
|
|
|
|
|
|
type UserPositionData struct {
|
|
|
Id int64 `json:"id"`
|
|
|
CompanyId int64 `json:"company_id"`
|
|
|
PositionId int64 `json:"position_id"`
|
|
|
UserId int64 `json:"user_id"`
|
|
|
}
|
|
|
|
|
|
//--------------------
|
|
|
type ModuleEmployee struct {
|
|
|
Userid int64 `json:"user_id"`
|
|
|
UCenterId int64 `json:"ucenter_id"` //同一用户中心的用户id
|
|
|
Id int64 `json:"id"` //用户的id,对应本地的user_company_id
|
|
|
OpenId int64 `json:"open_id"` //同一用户中心的用户id
|
|
|
Phone string `json:"phone"`
|
|
|
Nickname string `json:"nick_name"`
|
|
|
Companyid int64 `json:"company_id"` //同意用户中心的company_id
|
|
|
DepartmentId []int64 `json:"department_id"`
|
|
|
Position []int64 `json:"position"`
|
|
|
Name string `json:"name"`
|
|
|
Sex int8 `json:"sex"`
|
|
|
JobNum string `json:"job_num"`
|
|
|
PrivatePhone string `json:"private_phone"` //私人手机
|
|
|
CompanyId int64 `json:"company_id"` //总后台的company_id
|
|
|
Email string `json:"email"`
|
|
|
ExtensionNum string `json:"extension_num"` //分机号
|
|
|
EntryTime string `json:"entry_time"` //入职时间
|
|
|
WorkSpace string `json:"work_space"`
|
|
|
IsBusiness int8 `json:"is_business"`
|
|
|
Status int8 `json:"status"`
|
|
|
Avatar string `json:"avatar"`
|
|
|
ExtraText string `json:"extra_text"`
|
|
|
Remarks string `json:"remarks"`
|
|
|
AdminType int8 `json:"admin_type"`
|
|
|
ChargeStatus int8 `json:"charge_status"`
|
|
|
UserDepartments []UserDepartData `json:"user_departments"`
|
|
|
UserPositions []UserPositionData `json:"user_positions"`
|
|
|
}
|
|
|
|
|
|
type DeleteUserData struct {
|
|
|
CompanyId int64 `json:"company_id"`
|
|
|
Ids []int64 `json:"ids"`
|
|
|
}
|
|
|
|
|
|
type ForbidAllowUserData struct {
|
|
|
CompanyId int64 `json:"company_id"`
|
|
|
Ids []int64 `json:"ids"`
|
|
|
Status int8 `json:"status"`
|
|
|
}
|
|
|
|
|
|
type RemoveUserDepartmentData struct {
|
|
|
CompanyId int64 `json:"company_id"`
|
|
|
UserIds []int64 `json:"user_ids"`
|
|
|
DepartmentIds []int64 `json:"department_ids"`
|
|
|
}
|
|
|
|
|
|
var _ PlatformAction = ModuleEmployee{}
|
...
|
...
|
@@ -33,34 +77,73 @@ var _ PlatformAction = ModuleEmployee{} |
|
|
func (m ModuleEmployee) DoAction(code string, jsondata []byte) error {
|
|
|
switch code {
|
|
|
case "edit":
|
|
|
// return UpdateDepartmentData(m)
|
|
|
var (
|
|
|
data ModuleEmployee
|
|
|
err error
|
|
|
)
|
|
|
err = json.Unmarshal(jsondata, &data)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("数据解析失败:%s", err)
|
|
|
}
|
|
|
return UpdateEmployeeData(data)
|
|
|
case "add":
|
|
|
var (
|
|
|
data []ModuleEmployee
|
|
|
data ModuleEmployee
|
|
|
err error
|
|
|
)
|
|
|
err = json.Unmarshal(jsondata, &data)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("数据解析失败:%s", err)
|
|
|
}
|
|
|
return AddEmployeeData(data)
|
|
|
case "delete":
|
|
|
datas := []ModuleEmployee{data}
|
|
|
return AddEmployeeData(datas)
|
|
|
case "batchDelete":
|
|
|
var (
|
|
|
err error
|
|
|
ids []int64
|
|
|
data DeleteUserData
|
|
|
)
|
|
|
err = json.Unmarshal(jsondata, &ids)
|
|
|
err = json.Unmarshal(jsondata, &data)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("数据解析失败:%s", err)
|
|
|
}
|
|
|
if len(ids) == 0 {
|
|
|
return fmt.Errorf("参数错误")
|
|
|
return DeleteEmployeeData(data)
|
|
|
case "batchForbid":
|
|
|
//批量禁用、启用
|
|
|
var (
|
|
|
err error
|
|
|
data ForbidAllowUserData
|
|
|
)
|
|
|
err = json.Unmarshal(jsondata, &data)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("数据解析失败:%s", err)
|
|
|
}
|
|
|
return DeleteEmployeeData(ids)
|
|
|
return ForbidAllowEmployeeData(data)
|
|
|
case "batchRemove":
|
|
|
//移动通讯录用户部门
|
|
|
var (
|
|
|
err error
|
|
|
data RemoveUserDepartmentData
|
|
|
)
|
|
|
err = json.Unmarshal(jsondata, &data)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("数据解析失败:%s", err)
|
|
|
}
|
|
|
return RemoveUserDepartment(data)
|
|
|
case "import":
|
|
|
//导入用户
|
|
|
var (
|
|
|
data []ModuleEmployee
|
|
|
err error
|
|
|
)
|
|
|
err = json.Unmarshal(jsondata, &data)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("数据解析失败:%s", err)
|
|
|
}
|
|
|
return AddEmployeeData(data)
|
|
|
default:
|
|
|
return errors.New("action not found")
|
|
|
}
|
|
|
return nil
|
|
|
// return nil
|
|
|
}
|
|
|
|
|
|
// AddEmployeeData ...
|
...
|
...
|
@@ -76,9 +159,10 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
|
userpositionData []*models.UserPosition
|
|
|
nowTime = time.Now()
|
|
|
)
|
|
|
companydata, err = models.GetCompanyByUCenter(data[0].Companyid)
|
|
|
|
|
|
companydata, err = models.GetCompanyByUCenter(data[0].CompanyId)
|
|
|
if err != nil {
|
|
|
log.Error("GetCompanyByUCenter获取公司数据失败,ucenterId=%d,err:%s", data[0].Companyid, err)
|
|
|
log.Error("GetCompanyByUCenter获取公司数据失败,ucenterId=%d,err:%s", data[0].CompanyId, err)
|
|
|
return errors.New("获取公司数据失败")
|
|
|
}
|
|
|
|
...
|
...
|
@@ -86,7 +170,7 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
|
var (
|
|
|
userdata *models.User
|
|
|
)
|
|
|
userdata, err = models.GetUserByUCenter(v.UCenterId)
|
|
|
userdata, err = models.GetUserByUCenter(v.OpenId)
|
|
|
if err != nil && err != orm.ErrNoRows {
|
|
|
log.Error("获取用户数据失败,err:%s", err)
|
|
|
return errors.New("获取用户数据失败")
|
...
|
...
|
@@ -94,8 +178,8 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
|
if err == orm.ErrNoRows {
|
|
|
//添加用户
|
|
|
userdata = &models.User{
|
|
|
UserCenterId: v.UCenterId,
|
|
|
NickName: v.Nickname,
|
|
|
UserCenterId: v.OpenId,
|
|
|
NickName: v.Name,
|
|
|
Phone: v.Phone,
|
|
|
}
|
|
|
_, err = models.AddUser(userdata)
|
...
|
...
|
@@ -104,31 +188,47 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
|
return err
|
|
|
}
|
|
|
} else {
|
|
|
userdata.NickName = v.Nickname
|
|
|
userdata.NickName = v.Name
|
|
|
userdata.Phone = v.Phone
|
|
|
models.UpdateUserById(userdata, []string{"NickName", "Phone"})
|
|
|
}
|
|
|
uc := &models.UserCompany{
|
|
|
Id: v.Userid,
|
|
|
Id: v.Id,
|
|
|
CompanyId: companydata.Id,
|
|
|
UserId: userdata.Id,
|
|
|
NickName: v.Nickname,
|
|
|
}
|
|
|
NickName: v.Name,
|
|
|
OpenId: v.OpenId,
|
|
|
Sex: v.Sex,
|
|
|
JobNum: v.JobNum,
|
|
|
Phone: v.Phone,
|
|
|
PrivatePhone: v.PrivatePhone,
|
|
|
Email: v.Email,
|
|
|
ExtensionNum: v.ExtensionNum,
|
|
|
Workspace: v.WorkSpace,
|
|
|
IsBusiness: v.IsBusiness,
|
|
|
Enable: v.Status,
|
|
|
Avatar: v.Avatar,
|
|
|
Remarks: v.Remarks,
|
|
|
AdminType: v.AdminType,
|
|
|
ChargeStatus: v.ChargeStatus,
|
|
|
ExtraText: v.ExtraText,
|
|
|
}
|
|
|
uc.EntryTime, _ = time.ParseInLocation("2006-01-02", v.EntryTime, time.Local)
|
|
|
usercompanydata = append(usercompanydata, uc)
|
|
|
for i := range v.DepartmentId {
|
|
|
for i := range v.UserDepartments {
|
|
|
d := &models.UserDepartment{
|
|
|
CompanyId: companydata.Id,
|
|
|
UserCompanyId: v.Userid,
|
|
|
DepartmentId: v.DepartmentId[i],
|
|
|
UserCompanyId: v.UserDepartments[i].UserId,
|
|
|
DepartmentId: v.UserDepartments[i].DepartmentId,
|
|
|
CreateTime: nowTime,
|
|
|
}
|
|
|
userdepartmentData = append(userdepartmentData, d)
|
|
|
}
|
|
|
for i := range v.Position {
|
|
|
for i := range v.UserPositions {
|
|
|
p := &models.UserPosition{
|
|
|
CompanyId: companydata.Id,
|
|
|
UserCompanyId: v.Userid,
|
|
|
PositionId: v.Position[i],
|
|
|
UserCompanyId: v.UserPositions[i].UserId,
|
|
|
PositionId: v.UserPositions[i].PositionId,
|
|
|
CreateAt: nowTime,
|
|
|
}
|
|
|
userpositionData = append(userpositionData, p)
|
...
|
...
|
@@ -143,7 +243,7 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
|
o.Rollback()
|
|
|
return e
|
|
|
}
|
|
|
//添加部门职位
|
|
|
//添加用户的职位
|
|
|
_, err = o.InsertMulti(20, &userpositionData)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("插入user_position数据失败,err:%s", err)
|
...
|
...
|
@@ -151,6 +251,7 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
|
o.Rollback()
|
|
|
return e
|
|
|
}
|
|
|
//添加用户的部门
|
|
|
_, err = o.InsertMulti(20, &userdepartmentData)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("批量插入user_department数据失败,err:%s", err)
|
...
|
...
|
@@ -170,19 +271,19 @@ func UpdateEmployeeData(data ModuleEmployee) error { |
|
|
companyInfo *models.Company
|
|
|
userdata *models.User
|
|
|
)
|
|
|
userdata, err = models.GetUserByUCenter(data.UCenterId)
|
|
|
userdata, err = models.GetUserByUCenter(data.OpenId)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("获取用户数据失败:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
companyInfo, err = models.GetCompanyByUCenter(data.Companyid)
|
|
|
companyInfo, err = models.GetCompanyByUCenter(data.CompanyId)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("获取公司数据失败:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
ucompany, err = models.GetUserCompanyById(data.Userid)
|
|
|
ucompany, err = models.GetUserCompanyById(data.Id)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("获取用户和公司的关联数据失败:%s", err)
|
|
|
log.Error(e.Error())
|
...
|
...
|
@@ -191,30 +292,52 @@ func UpdateEmployeeData(data ModuleEmployee) error { |
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
//更新用户数据
|
|
|
userdata.NickName = data.Nickname
|
|
|
userdata.NickName = data.Name
|
|
|
userdata.Phone = data.Phone
|
|
|
|
|
|
err = models.UpdateUserById(userdata, []string{"NickName", "Phone"}, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("UpdateUserById err:%s", err)
|
|
|
return errors.New("更新用户数据失败")
|
|
|
}
|
|
|
ucompany.NickName = data.Nickname
|
|
|
models.UpdateUserCompanyById(ucompany, []string{"NickName"}, o)
|
|
|
ucompany.NickName = data.Name
|
|
|
ucompany.NickName = data.Name
|
|
|
ucompany.OpenId = data.OpenId
|
|
|
ucompany.Sex = data.Sex
|
|
|
ucompany.JobNum = data.JobNum
|
|
|
ucompany.Phone = data.Phone
|
|
|
ucompany.PrivatePhone = data.PrivatePhone
|
|
|
ucompany.Email = data.Email
|
|
|
ucompany.ExtensionNum = data.ExtensionNum
|
|
|
ucompany.Workspace = data.WorkSpace
|
|
|
ucompany.IsBusiness = data.IsBusiness
|
|
|
ucompany.Enable = data.Status
|
|
|
ucompany.Avatar = data.Avatar
|
|
|
ucompany.Remarks = data.Remarks
|
|
|
ucompany.AdminType = data.AdminType
|
|
|
ucompany.ChargeStatus = data.ChargeStatus
|
|
|
ucompany.ExtraText = data.ExtraText
|
|
|
cols := []string{"NickName", "OpenId", "Sex", "JobNum",
|
|
|
"Phone", "PrivatePhone", "Email", "ExtensionNum", "Workspace",
|
|
|
"IsBusiness", "Status", "Avatar", "Remarks", "AdminType", "ChargeStatus",
|
|
|
"ExtraText",
|
|
|
}
|
|
|
err = models.UpdateUserCompanyById(ucompany, cols, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("UpdateUserCompanyById err:%s", err)
|
|
|
return errors.New("更新用户数据失败")
|
|
|
}
|
|
|
//添加部门
|
|
|
err = editUserDepart(data.Userid, companyInfo.Id, data.DepartmentId, o)
|
|
|
err = editUserDepart(data.Id, companyInfo.Id, data.UserDepartments, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("editUserDepart err:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
//添加职位
|
|
|
err = editUserPosition(data.Userid, companyInfo.Id, data.Position, o)
|
|
|
err = editUserPosition(data.Id, companyInfo.Id, data.UserPositions, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("editUserDepart err:%s", err)
|
...
|
...
|
@@ -224,89 +347,154 @@ func UpdateEmployeeData(data ModuleEmployee) error { |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func editUserDepart(usercompanyid int64, companyid int64, departids []int64, o orm.Ormer) error {
|
|
|
func editUserDepart(usercompanyid int64, companyid int64, userDepart []UserDepartData, o orm.Ormer) error {
|
|
|
var (
|
|
|
oldDepartIds []int64
|
|
|
newDepartIds []int64
|
|
|
err error
|
|
|
delDepartIds []int64
|
|
|
addDepartIds []int64
|
|
|
addDepart []models.UserDepartment
|
|
|
)
|
|
|
dataSql := `SELECT department_id FROM user_department WHERE enable_status=1 AND user_company_id=?`
|
|
|
dataSql2 := `UPDATE user_department SET enable_status = 2 WHERE user_company_id=? AND department_id=?`
|
|
|
datasql3 := `INSERT INTO user_department (user_company_id,department_id,company_id,enable_status,create_time) VALUES (?,?,?,?,?)`
|
|
|
for i := range userDepart {
|
|
|
newDepartIds = append(newDepartIds, userDepart[i].DepartmentId)
|
|
|
}
|
|
|
dataSql := `SELECT department_id FROM user_department WHERE enable_status=1 AND user_company_id=? `
|
|
|
err = utils.ExecuteQueryAllWithOrmer(o, &oldDepartIds, dataSql, usercompanyid)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("Execute SQL err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
delDepartIds = utils.ArrayInt64Diff(oldDepartIds, departids)
|
|
|
addDepartIds = utils.ArrayInt64Diff(departids, oldDepartIds)
|
|
|
for _, v := range delDepartIds {
|
|
|
err = utils.ExecuteSQLWithOrmer(o, dataSql2, usercompanyid, v)
|
|
|
delDepartIds = utils.ArrayInt64Diff(oldDepartIds, newDepartIds)
|
|
|
addDepartIds = utils.ArrayInt64Diff(newDepartIds, oldDepartIds)
|
|
|
nowTime := time.Now()
|
|
|
for _, v := range addDepartIds {
|
|
|
m := models.UserDepartment{
|
|
|
UserCompanyId: usercompanyid,
|
|
|
DepartmentId: v,
|
|
|
EnableStatus: models.USER_DEPARTMENT_ENABLE_YES,
|
|
|
CompanyId: companyid,
|
|
|
CreateTime: nowTime,
|
|
|
}
|
|
|
addDepart = append(addDepart, m)
|
|
|
}
|
|
|
if len(delDepartIds) > 0 {
|
|
|
_, err = o.QueryTable(&models.UserDepartment{}).
|
|
|
Filter("id__in", delDepartIds).
|
|
|
Update(orm.Params{
|
|
|
"enable_status": models.USER_DEPARTMENT_ENABLE_NO,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("Execute SQL err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
log.Error("删除用户部门失败: 用户id=%d,err:%s", usercompanyid, err)
|
|
|
return errors.New("删除用户部门失败")
|
|
|
}
|
|
|
}
|
|
|
nowTime := time.Now().String()
|
|
|
for _, v := range addDepartIds {
|
|
|
err = utils.ExecuteSQLWithOrmer(o, datasql3, usercompanyid, v, companyid, models.USER_POSITION_ENABLE_YES, nowTime)
|
|
|
if len(addDepart) > 0 {
|
|
|
_, err = o.InsertMulti(10, addDepart)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("Execute SQL err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
log.Error("添加用户的部门失败 用户id=%d,err:%s", usercompanyid, err)
|
|
|
return errors.New("添加用户的部门失败")
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func editUserPosition(usercompanyid int64, companyid int64, positionids []int64, o orm.Ormer) error {
|
|
|
func editUserPosition(usercompanyid int64, companyid int64, userPosition []UserPositionData, o orm.Ormer) error {
|
|
|
var (
|
|
|
oldPositionIds []int64
|
|
|
newPositionIds []int64
|
|
|
err error
|
|
|
delPositionIds []int64
|
|
|
addPositionIds []int64
|
|
|
addPosition []models.UserPosition
|
|
|
)
|
|
|
for _, v := range userPosition {
|
|
|
newPositionIds = append(newPositionIds, v.PositionId)
|
|
|
}
|
|
|
dataSql := `SELECT position_id FROM user_position WHERE enable_status=1 AND user_company_id=?`
|
|
|
dataSql2 := `UPDATE user_position SET enable_status = 2 WHERE user_company_id=? AND position_id=?`
|
|
|
datasql3 := `INSERT INTO user_position (user_company_id,position_id,company_id,enable_status,create_at) VALUES (?,?,?,?,?)`
|
|
|
err = utils.ExecuteQueryAllWithOrmer(o, &oldPositionIds, dataSql, usercompanyid)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("Execute SQL err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
delPositionIds = utils.ArrayInt64Diff(oldPositionIds, positionids)
|
|
|
addPositionIds = utils.ArrayInt64Diff(positionids, oldPositionIds)
|
|
|
for _, v := range delPositionIds {
|
|
|
err = utils.ExecuteSQLWithOrmer(o, dataSql2, usercompanyid, v)
|
|
|
delPositionIds = utils.ArrayInt64Diff(oldPositionIds, newPositionIds)
|
|
|
addPositionIds = utils.ArrayInt64Diff(newPositionIds, oldPositionIds)
|
|
|
nowTime := time.Now()
|
|
|
for _, v := range addPositionIds {
|
|
|
m := models.UserPosition{
|
|
|
UserCompanyId: usercompanyid,
|
|
|
PositionId: v,
|
|
|
EnableStatus: models.USER_DEPARTMENT_ENABLE_YES,
|
|
|
CompanyId: companyid,
|
|
|
CreateAt: nowTime,
|
|
|
}
|
|
|
addPosition = append(addPosition, m)
|
|
|
}
|
|
|
if len(delPositionIds) > 0 {
|
|
|
_, err = o.QueryTable(&models.UserPosition{}).
|
|
|
Filter("id__in", delPositionIds).
|
|
|
Update(orm.Params{
|
|
|
"enable_status": models.USER_POSITION_ENABLE_NO,
|
|
|
})
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("Execute SQL err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
log.Error("删除用户职位失败: 用户id=%d,err:%s", usercompanyid, err)
|
|
|
return errors.New("删除用户部门失败")
|
|
|
}
|
|
|
}
|
|
|
nowTime := time.Now().String()
|
|
|
for _, v := range addPositionIds {
|
|
|
err = utils.ExecuteSQLWithOrmer(o, datasql3, usercompanyid, v, companyid, models.USER_POSITION_ENABLE_YES, nowTime)
|
|
|
if len(addPosition) > 0 {
|
|
|
_, err = o.InsertMulti(10, addPosition)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("Execute SQL err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
log.Error("添加用户的职位失败 用户id=%d,err:%s", usercompanyid, err)
|
|
|
return errors.New("添加用户的部门失败")
|
|
|
}
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// DeleteEmployeeData ...
|
|
|
func DeleteEmployeeData(ids []int64) error {
|
|
|
func DeleteEmployeeData(data DeleteUserData) error {
|
|
|
companyData, err := models.GetCompanyByUCenter(data.CompanyId)
|
|
|
if err != nil {
|
|
|
log.Error("h获取公司数据失败,user_center_id=%d,err:%s", data.CompanyId, err)
|
|
|
return errors.New("获取公司数据失败")
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
_, err = o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("id__in", data.Ids).
|
|
|
Filter("company_id", companyData.Id).
|
|
|
Update(orm.Params{
|
|
|
"delete_at": time.Now().Format("2006-01-02 15:04:05"),
|
|
|
"enable": models.USERCOMPANY_ENABLE_NO,
|
|
|
})
|
|
|
if err != nil {
|
|
|
log.Error("更新user_company数据失败:%s", err)
|
|
|
return errors.New("删除user_company数据失败")
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func ForbidAllowEmployeeData(data ForbidAllowUserData) error {
|
|
|
companyData, err := models.GetCompanyByUCenter(data.CompanyId)
|
|
|
if err != nil {
|
|
|
log.Error("h获取公司数据失败,user_center_id=%d,err:%s", data.CompanyId, err)
|
|
|
return errors.New("获取公司数据失败")
|
|
|
}
|
|
|
var status int8
|
|
|
switch data.Status {
|
|
|
case 1:
|
|
|
status = models.USERCOMPANY_ENABLE_YES
|
|
|
case 2:
|
|
|
status = models.USERCOMPANY_ENABLE_NO
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
_, err := o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("id__in", ids).
|
|
|
_, err = o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("id__in", data.Ids).
|
|
|
Filter("company_id", companyData.Id).
|
|
|
Update(orm.Params{
|
|
|
"delete_at": time.Now().String(),
|
|
|
"enable": status,
|
|
|
"update_at": time.Now().Format("2006-01-02 15:04:05"),
|
|
|
})
|
|
|
if err != nil {
|
|
|
log.Error("更新user_company数据失败:%s", err)
|
...
|
...
|
@@ -314,3 +502,41 @@ func DeleteEmployeeData(ids []int64) error { |
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func RemoveUserDepartment(data RemoveUserDepartmentData) error {
|
|
|
var (
|
|
|
err error
|
|
|
companyData *models.Company
|
|
|
)
|
|
|
userDepartmentDatas := make(map[int64][]UserDepartData)
|
|
|
companyData, err = models.GetCompanyByUCenter(data.CompanyId)
|
|
|
if err != nil {
|
|
|
log.Error("h获取公司数据失败,user_center_id=%d,err:%s", data.CompanyId, err)
|
|
|
return errors.New("获取公司数据失败")
|
|
|
}
|
|
|
for _, v := range data.UserIds {
|
|
|
var userDapart []UserDepartData
|
|
|
for _, vv := range data.DepartmentIds {
|
|
|
m := UserDepartData{
|
|
|
CompanyId: companyData.Id,
|
|
|
UserId: v,
|
|
|
DepartmentId: vv,
|
|
|
}
|
|
|
userDapart = append(userDapart, m)
|
|
|
}
|
|
|
userDepartmentDatas[v] = userDapart
|
|
|
}
|
|
|
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
for k, v := range userDepartmentDatas {
|
|
|
err = editUserDepart(k, companyData.Id, v, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("更新用户部门失败;user_company_id=%d,err:%s", k, err)
|
|
|
return errors.New("更新用户部门失败")
|
|
|
}
|
|
|
}
|
|
|
o.Commit()
|
|
|
return nil
|
|
|
} |
...
|
...
|
|