...
|
...
|
@@ -2,6 +2,9 @@ package platform |
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
)
|
|
|
|
|
|
// ModuleDeparmentData 主管理平台发送过来的数据
|
...
|
...
|
@@ -15,6 +18,7 @@ type ModuleDeparmentData struct { |
|
|
|
|
|
var _ PlatformAction = ModuleDeparmentData{}
|
|
|
|
|
|
//DoAction PlatformAction 的接口实现
|
|
|
func (m ModuleDeparmentData) DoAction(code string) error {
|
|
|
switch code {
|
|
|
case "edit":
|
...
|
...
|
@@ -30,15 +34,49 @@ func (m ModuleDeparmentData) DoAction(code string) error { |
|
|
|
|
|
//同步 部门数据
|
|
|
func UpdateDepartmentData(data ModuleDeparmentData) error {
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//AddDepartmentData ...
|
|
|
//TODO :部门管理员数据填充
|
|
|
func AddDepartmentData(data ModuleDeparmentData) error {
|
|
|
// var (
|
|
|
// companyinfo *models.Company
|
|
|
// err error
|
|
|
// )
|
|
|
// models.GetCompanyByUCenter(data.CompanyId)
|
|
|
var (
|
|
|
companyinfo *models.Company
|
|
|
err error
|
|
|
parentDepartment *models.Department
|
|
|
)
|
|
|
companyinfo, err = models.GetCompanyByUCenter(data.CompanyId)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("获取公司数据失败,err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return errors.New("获取公司数据失败")
|
|
|
|
|
|
}
|
|
|
departmentData := &models.Department{
|
|
|
Id: data.Id,
|
|
|
CompanyId: companyinfo.Id,
|
|
|
Name: data.Name,
|
|
|
ParentId: data.ParentId,
|
|
|
Manages: "[]",
|
|
|
Relation: fmt.Sprintf("%d", data.Id),
|
|
|
}
|
|
|
if data.ParentId > 0 {
|
|
|
parentDepartment, err = models.GetDepartmentById(data.ParentId)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("获取父级部门数据失败,err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return errors.New("获取父级部门数据失败")
|
|
|
}
|
|
|
departmentData.Relation = fmt.Sprintf("%s/%d", parentDepartment.Relation, data.Id)
|
|
|
}
|
|
|
_, err = models.AddDepartment(departmentData)
|
|
|
if err != nil {
|
|
|
|
|
|
e := fmt.Errorf("存储部门数据失败,err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return errors.New("存储部门数据失败")
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
...
|
...
|
|