|
@@ -2,6 +2,9 @@ package platform |
|
@@ -2,6 +2,9 @@ package platform |
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
4
|
"errors"
|
4
|
"errors"
|
|
|
5
|
+ "fmt"
|
|
|
6
|
+ "oppmg/common/log"
|
|
|
7
|
+ "oppmg/models"
|
5
|
)
|
8
|
)
|
6
|
|
9
|
|
7
|
// ModuleDeparmentData 主管理平台发送过来的数据
|
10
|
// ModuleDeparmentData 主管理平台发送过来的数据
|
|
@@ -15,6 +18,7 @@ type ModuleDeparmentData struct { |
|
@@ -15,6 +18,7 @@ type ModuleDeparmentData struct { |
15
|
|
18
|
|
16
|
var _ PlatformAction = ModuleDeparmentData{}
|
19
|
var _ PlatformAction = ModuleDeparmentData{}
|
17
|
|
20
|
|
|
|
21
|
+//DoAction PlatformAction 的接口实现
|
18
|
func (m ModuleDeparmentData) DoAction(code string) error {
|
22
|
func (m ModuleDeparmentData) DoAction(code string) error {
|
19
|
switch code {
|
23
|
switch code {
|
20
|
case "edit":
|
24
|
case "edit":
|
|
@@ -30,15 +34,49 @@ func (m ModuleDeparmentData) DoAction(code string) error { |
|
@@ -30,15 +34,49 @@ func (m ModuleDeparmentData) DoAction(code string) error { |
30
|
|
34
|
|
31
|
//同步 部门数据
|
35
|
//同步 部门数据
|
32
|
func UpdateDepartmentData(data ModuleDeparmentData) error {
|
36
|
func UpdateDepartmentData(data ModuleDeparmentData) error {
|
|
|
37
|
+
|
33
|
return nil
|
38
|
return nil
|
34
|
}
|
39
|
}
|
35
|
|
40
|
|
|
|
41
|
+//AddDepartmentData ...
|
|
|
42
|
+//TODO :部门管理员数据填充
|
36
|
func AddDepartmentData(data ModuleDeparmentData) error {
|
43
|
func AddDepartmentData(data ModuleDeparmentData) error {
|
37
|
- // var (
|
|
|
38
|
- // companyinfo *models.Company
|
|
|
39
|
- // err error
|
|
|
40
|
- // )
|
|
|
41
|
- // models.GetCompanyByUCenter(data.CompanyId)
|
44
|
+ var (
|
|
|
45
|
+ companyinfo *models.Company
|
|
|
46
|
+ err error
|
|
|
47
|
+ parentDepartment *models.Department
|
|
|
48
|
+ )
|
|
|
49
|
+ companyinfo, err = models.GetCompanyByUCenter(data.CompanyId)
|
|
|
50
|
+ if err != nil {
|
|
|
51
|
+ e := fmt.Errorf("获取公司数据失败,err:%s", err)
|
|
|
52
|
+ log.Error(e.Error())
|
|
|
53
|
+ return errors.New("获取公司数据失败")
|
|
|
54
|
+
|
|
|
55
|
+ }
|
|
|
56
|
+ departmentData := &models.Department{
|
|
|
57
|
+ Id: data.Id,
|
|
|
58
|
+ CompanyId: companyinfo.Id,
|
|
|
59
|
+ Name: data.Name,
|
|
|
60
|
+ ParentId: data.ParentId,
|
|
|
61
|
+ Manages: "[]",
|
|
|
62
|
+ Relation: fmt.Sprintf("%d", data.Id),
|
|
|
63
|
+ }
|
|
|
64
|
+ if data.ParentId > 0 {
|
|
|
65
|
+ parentDepartment, err = models.GetDepartmentById(data.ParentId)
|
|
|
66
|
+ if err != nil {
|
|
|
67
|
+ e := fmt.Errorf("获取父级部门数据失败,err:%s", err)
|
|
|
68
|
+ log.Error(e.Error())
|
|
|
69
|
+ return errors.New("获取父级部门数据失败")
|
|
|
70
|
+ }
|
|
|
71
|
+ departmentData.Relation = fmt.Sprintf("%s/%d", parentDepartment.Relation, data.Id)
|
|
|
72
|
+ }
|
|
|
73
|
+ _, err = models.AddDepartment(departmentData)
|
|
|
74
|
+ if err != nil {
|
|
|
75
|
+
|
|
|
76
|
+ e := fmt.Errorf("存储部门数据失败,err:%s", err)
|
|
|
77
|
+ log.Error(e.Error())
|
|
|
78
|
+ return errors.New("存储部门数据失败")
|
|
|
79
|
+ }
|
42
|
return nil
|
80
|
return nil
|
43
|
}
|
81
|
}
|
44
|
|
82
|
|