...
|
...
|
@@ -43,7 +43,7 @@ type ModuleEmployee struct { |
|
|
Email string `json:"email"`
|
|
|
ExtensionNum string `json:"extension_num"` //分机号
|
|
|
EntryTime string `json:"entry_time"` //入职时间
|
|
|
WorkSpace string `json:"work_space"`
|
|
|
WorkSpace string `json:"workspace"`
|
|
|
IsBusiness int8 `json:"is_business"`
|
|
|
Status int8 `json:"status"`
|
|
|
Avatar string `json:"avatar"`
|
...
|
...
|
@@ -72,6 +72,11 @@ type RemoveUserDepartmentData struct { |
|
|
DepartmentIds []int64 `json:"department_ids"`
|
|
|
}
|
|
|
|
|
|
type ImportEmployeeData struct {
|
|
|
Add []ModuleEmployee `json:"add"`
|
|
|
Edit []ModuleEmployee `json:"edit"`
|
|
|
}
|
|
|
|
|
|
var _ PlatformAction = ModuleEmployee{}
|
|
|
|
|
|
//DoAction PlatformAction 的接口实现
|
...
|
...
|
@@ -133,14 +138,18 @@ func (m ModuleEmployee) DoAction(code string, jsondata []byte) error { |
|
|
case "import":
|
|
|
//导入用户
|
|
|
var (
|
|
|
data []ModuleEmployee
|
|
|
data ImportEmployeeData
|
|
|
err error
|
|
|
)
|
|
|
err = json.Unmarshal(jsondata, &data)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("数据解析失败:%s", err)
|
|
|
}
|
|
|
return AddEmployeeData(data)
|
|
|
AddEmployeeData(data.Add)
|
|
|
for i := range data.Edit {
|
|
|
UpdateEmployeeData(data.Edit[i])
|
|
|
}
|
|
|
return nil
|
|
|
default:
|
|
|
return errors.New("action not found")
|
|
|
}
|
...
|
...
|
@@ -148,7 +157,7 @@ func (m ModuleEmployee) DoAction(code string, jsondata []byte) error { |
|
|
}
|
|
|
|
|
|
// AddEmployeeData ...
|
|
|
func AddEmployeeData(data []ModuleEmployee) error {
|
|
|
func AddEmployeeData(data []ModuleEmployee, om ...orm.Ormer) error {
|
|
|
if len(data) == 0 {
|
|
|
return nil
|
|
|
}
|
...
|
...
|
@@ -263,7 +272,12 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
|
userpositionData = append(userpositionData, p)
|
|
|
}
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
var o orm.Ormer
|
|
|
if len(om) > 0 {
|
|
|
o = om[0]
|
|
|
} else {
|
|
|
o = orm.NewOrm()
|
|
|
}
|
|
|
o.Begin()
|
|
|
_, err = o.InsertMulti(20, &usercompanydata)
|
|
|
if err != nil {
|
...
|
...
|
@@ -295,23 +309,37 @@ func AddEmployeeData(data []ModuleEmployee) error { |
|
|
}
|
|
|
|
|
|
// UpdateEmployeeData ...
|
|
|
func UpdateEmployeeData(data ModuleEmployee) error {
|
|
|
func UpdateEmployeeData(data ModuleEmployee, om ...orm.Ormer) error {
|
|
|
var (
|
|
|
err error
|
|
|
ucompany *models.UserCompany
|
|
|
companyInfo *models.Company
|
|
|
userdata *models.User
|
|
|
)
|
|
|
companyInfo, err = models.GetCompanyByUCenter(data.CompanyId)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("获取公司数据失败:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
var o orm.Ormer
|
|
|
if len(om) > 0 {
|
|
|
o = om[0]
|
|
|
} else {
|
|
|
o = orm.NewOrm()
|
|
|
}
|
|
|
o.Begin()
|
|
|
ucompany, err = models.GetUserCompanyById(data.Id)
|
|
|
if err == orm.ErrNoRows {
|
|
|
log.Error("编辑操作,未找到数据,执行添加操作")
|
|
|
return AddEmployeeData([]ModuleEmployee{data})
|
|
|
return AddEmployeeData([]ModuleEmployee{data}, om...)
|
|
|
}
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("获取用户和公司的关联数据失败:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
//更新用户数据
|
|
|
ucenterReturn, err := ucenter.RequestUCenterAddUser(data.Phone, data.Name, "")
|
|
|
if err != nil {
|
|
|
log.Error("请求统一用户中心数据失败:%s", err)
|
...
|
...
|
@@ -324,16 +352,6 @@ func UpdateEmployeeData(data ModuleEmployee) error { |
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
companyInfo, err = models.GetCompanyByUCenter(data.CompanyId)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("获取公司数据失败:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
//更新用户数据
|
|
|
userdata.NickName = data.Name
|
|
|
userdata.Phone = data.Phone
|
|
|
userdata.UserCenterId = data.OpenId
|
...
|
...
|
|