作者 tangxvhui

提交

@@ -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
@@ -14,18 +14,23 @@ type ModuleEmployee struct { @@ -14,18 +14,23 @@ type ModuleEmployee struct {
14 14
15 var _ PlatformAction = ModuleEmployee{} 15 var _ PlatformAction = ModuleEmployee{}
16 16
  17 +//DoAction PlatformAction 的接口实现
17 func (m ModuleEmployee) DoAction(code string) error { 18 func (m ModuleEmployee) DoAction(code string) error {
  19 +
18 return nil 20 return nil
19 } 21 }
20 22
  23 +// UpdateEmployeeData ...
21 func UpdateEmployeeData(data ModuleEmployee) error { 24 func UpdateEmployeeData(data ModuleEmployee) error {
22 return nil 25 return nil
23 } 26 }
24 27
  28 +// AddEmployeeData ...
25 func AddEmployeeData(data ModuleEmployee) error { 29 func AddEmployeeData(data ModuleEmployee) error {
26 return nil 30 return nil
27 } 31 }
28 32
  33 +// DeleteEmployeeData ...
29 func DeleteEmployeeData(data ModuleEmployee) error { 34 func DeleteEmployeeData(data ModuleEmployee) error {
30 return nil 35 return nil
31 } 36 }
@@ -22,6 +22,7 @@ type ModulePositionData struct { @@ -22,6 +22,7 @@ type ModulePositionData struct {
22 22
23 var _ PlatformAction = ModulePositionData{} 23 var _ PlatformAction = ModulePositionData{}
24 24
  25 +//DoAction PlatformAction 的接口实现
25 func (m ModulePositionData) DoAction(code string) error { 26 func (m ModulePositionData) DoAction(code string) error {
26 return nil 27 return nil
27 } 28 }