正在显示
4 个修改的文件
包含
87 行增加
和
118 行删除
@@ -22,6 +22,7 @@ type Department struct { | @@ -22,6 +22,7 @@ type Department struct { | ||
22 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | 22 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` |
23 | Manages string `orm:"column(managers)" description:"部门负责人id列表 json 数组 []"` //存user_company_id | 23 | Manages string `orm:"column(managers)" description:"部门负责人id列表 json 数组 []"` //存user_company_id |
24 | IsTop int8 `orm:"column(is_top)" ` | 24 | IsTop int8 `orm:"column(is_top)" ` |
25 | + Level int `orm:"column(level)" ` | ||
25 | } | 26 | } |
26 | 27 | ||
27 | func (t *Department) TableName() string { | 28 | func (t *Department) TableName() string { |
@@ -17,7 +17,7 @@ type Position struct { | @@ -17,7 +17,7 @@ type Position struct { | ||
17 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | 17 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` |
18 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` | 18 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` |
19 | EnableStatus string `orm:"column(enable_status);size(255)" description:"有效状态 1:有效 0:无效"` | 19 | EnableStatus string `orm:"column(enable_status);size(255)" description:"有效状态 1:有效 0:无效"` |
20 | - //关联企业总后台的id | 20 | + Level int `orm:"column(level)"` |
21 | } | 21 | } |
22 | 22 | ||
23 | //关联企业总后台的id | 23 | //关联企业总后台的id |
@@ -13,12 +13,12 @@ import ( | @@ -13,12 +13,12 @@ import ( | ||
13 | 13 | ||
14 | // ModuleDeparmentData 主管理平台发送过来的数据 | 14 | // ModuleDeparmentData 主管理平台发送过来的数据 |
15 | type ModuleDeparmentData struct { | 15 | type ModuleDeparmentData struct { |
16 | - Id int64 `json:"id"` //id | ||
17 | - Name string `json:"name"` //部门名称 | ||
18 | - ParentId int64 `json:"parent_id"` //父级id | ||
19 | - CompanyId int64 `json:"company_id"` | ||
20 | - Relation string `json:"relation"` | ||
21 | - Manages []int64 `json:"manages"` | 16 | + Id int64 `json:"id"` //id |
17 | + Name string `json:"name"` //部门名称 | ||
18 | + ParentId int64 `json:"parent_id"` //父级id | ||
19 | + CompanyId int64 `json:"company_id"` | ||
20 | + Path string `json:"path"` | ||
21 | + Level int `json:"level"` | ||
22 | } | 22 | } |
23 | 23 | ||
24 | var _ PlatformAction = ModuleDeparmentData{} | 24 | var _ PlatformAction = ModuleDeparmentData{} |
@@ -28,7 +28,7 @@ func (m ModuleDeparmentData) DoAction(code string, jsondata []byte) error { | @@ -28,7 +28,7 @@ func (m ModuleDeparmentData) DoAction(code string, jsondata []byte) error { | ||
28 | switch code { | 28 | switch code { |
29 | case "edit": | 29 | case "edit": |
30 | var ( | 30 | var ( |
31 | - data []ModuleDeparmentData | 31 | + data ModuleDeparmentData |
32 | err error | 32 | err error |
33 | ) | 33 | ) |
34 | err = json.Unmarshal(jsondata, &data) | 34 | err = json.Unmarshal(jsondata, &data) |
@@ -38,7 +38,7 @@ func (m ModuleDeparmentData) DoAction(code string, jsondata []byte) error { | @@ -38,7 +38,7 @@ func (m ModuleDeparmentData) DoAction(code string, jsondata []byte) error { | ||
38 | return UpdateDepartmentData(data) | 38 | return UpdateDepartmentData(data) |
39 | case "add": | 39 | case "add": |
40 | var ( | 40 | var ( |
41 | - data []ModuleDeparmentData | 41 | + data ModuleDeparmentData |
42 | err error | 42 | err error |
43 | ) | 43 | ) |
44 | err = json.Unmarshal(jsondata, &data) | 44 | err = json.Unmarshal(jsondata, &data) |
@@ -68,80 +68,64 @@ func (m ModuleDeparmentData) DoAction(code string, jsondata []byte) error { | @@ -68,80 +68,64 @@ func (m ModuleDeparmentData) DoAction(code string, jsondata []byte) error { | ||
68 | //同步 部门数据 | 68 | //同步 部门数据 |
69 | 69 | ||
70 | //UpdateDepartmentData .... | 70 | //UpdateDepartmentData .... |
71 | -func UpdateDepartmentData(data []ModuleDeparmentData) error { | 71 | +func UpdateDepartmentData(data ModuleDeparmentData) error { |
72 | var ( | 72 | var ( |
73 | departmentData *models.Department | 73 | departmentData *models.Department |
74 | err error | 74 | err error |
75 | ) | 75 | ) |
76 | - o := orm.NewOrm() | ||
77 | - o.Begin() | ||
78 | - for _, v := range data { | ||
79 | - departmentData, err = models.GetDepartmentById(v.Id) | ||
80 | - if err != nil { | ||
81 | - e := fmt.Errorf("获取部门数据失败,err:%s", err) | ||
82 | - log.Error(e.Error()) | ||
83 | - return errors.New("获取部门数据失败") | ||
84 | - } | ||
85 | - departmentData.Name = v.Name | ||
86 | - departmentData.ParentId = v.ParentId | ||
87 | - departmentData.Relation = v.Relation | ||
88 | - if bt, err := json.Marshal(v.Manages); err == nil { | ||
89 | - departmentData.Manages = string(bt) | ||
90 | - } | ||
91 | - err = models.UpdateDepartmentById(departmentData, []string{"Name", "Manage", "ParentId", "Relation"}, o) | ||
92 | - if err != nil { | ||
93 | - o.Rollback() | ||
94 | - e := fmt.Errorf("更新部门数据失败,err:%s", err) | ||
95 | - log.Error(e.Error()) | ||
96 | - return errors.New("更新部门数据失败") | ||
97 | - } | 76 | + |
77 | + departmentData, err = models.GetDepartmentById(data.Id) | ||
78 | + if err != nil { | ||
79 | + e := fmt.Errorf("获取部门数据失败,err:%s", err) | ||
80 | + log.Error(e.Error()) | ||
81 | + return errors.New("获取部门数据失败") | ||
82 | + } | ||
83 | + departmentData.Name = data.Name | ||
84 | + departmentData.ParentId = data.ParentId | ||
85 | + departmentData.Relation = data.Path | ||
86 | + departmentData.Level = data.Level | ||
87 | + | ||
88 | + err = models.UpdateDepartmentById(departmentData, []string{"Name", "Manage", "ParentId", "Relation"}) | ||
89 | + if err != nil { | ||
90 | + | ||
91 | + e := fmt.Errorf("更新部门数据失败,err:%s", err) | ||
92 | + log.Error(e.Error()) | ||
93 | + return errors.New("更新部门数据失败") | ||
98 | } | 94 | } |
99 | - o.Commit() | 95 | + |
100 | return nil | 96 | return nil |
101 | } | 97 | } |
102 | 98 | ||
103 | //AddDepartmentData ... | 99 | //AddDepartmentData ... |
104 | -func AddDepartmentData(data []ModuleDeparmentData) error { | ||
105 | - if len(data) == 0 { | ||
106 | - return nil | ||
107 | - } | 100 | +func AddDepartmentData(data ModuleDeparmentData) error { |
108 | var ( | 101 | var ( |
109 | companyinfo *models.Company | 102 | companyinfo *models.Company |
110 | err error | 103 | err error |
111 | ) | 104 | ) |
112 | - companyinfo, err = models.GetCompanyByUCenter(data[0].CompanyId) | 105 | + companyinfo, err = models.GetCompanyByUCenter(data.CompanyId) |
113 | if err != nil { | 106 | if err != nil { |
114 | - e := fmt.Errorf("获取公司数据失败,err:%s", err) | 107 | + e := fmt.Errorf("获取公司数据失败,id=%d,err:%s", data.CompanyId, err) |
115 | log.Error(e.Error()) | 108 | log.Error(e.Error()) |
116 | return errors.New("获取公司数据失败") | 109 | return errors.New("获取公司数据失败") |
117 | } | 110 | } |
118 | - o := orm.NewOrm() | ||
119 | - o.Begin() | ||
120 | - var isRollback bool | ||
121 | - for _, v := range data { | ||
122 | - departmentData := &models.Department{ | ||
123 | - Id: v.Id, | ||
124 | - CompanyId: companyinfo.Id, | ||
125 | - Name: v.Name, | ||
126 | - ParentId: v.ParentId, | ||
127 | - Manages: "[]", | ||
128 | - Relation: v.Relation, //TODO 格式转化 | ||
129 | - } | ||
130 | - if bt, err := json.Marshal(v.Manages); err == nil { | ||
131 | - departmentData.Manages = string(bt) | ||
132 | - } | ||
133 | - _, err = models.AddDepartment(departmentData, o) | ||
134 | - if err != nil { | ||
135 | - e := fmt.Errorf("存储部门数据失败,err:%s", err) | ||
136 | - log.Error(e.Error()) | ||
137 | - isRollback = true | ||
138 | - } | 111 | + |
112 | + departmentData := &models.Department{ | ||
113 | + Id: data.Id, | ||
114 | + CompanyId: companyinfo.Id, | ||
115 | + Name: data.Name, | ||
116 | + ParentId: data.ParentId, | ||
117 | + Manages: "[]", | ||
118 | + Relation: data.Path, //TODO 格式转化 | ||
119 | + Level: data.Level, | ||
139 | } | 120 | } |
140 | - if isRollback { | ||
141 | - o.Rollback() | ||
142 | - return errors.New("存储部门数据失败") | 121 | + |
122 | + _, err = models.AddDepartment(departmentData) | ||
123 | + if err != nil { | ||
124 | + e := fmt.Errorf("存储部门数据失败,err:%s", err) | ||
125 | + log.Error(e.Error()) | ||
126 | + | ||
143 | } | 127 | } |
144 | - o.Commit() | 128 | + |
145 | return nil | 129 | return nil |
146 | } | 130 | } |
147 | 131 |
@@ -13,10 +13,11 @@ import ( | @@ -13,10 +13,11 @@ import ( | ||
13 | 13 | ||
14 | type ModulePositionData struct { | 14 | type ModulePositionData struct { |
15 | Id int64 `json:"id"` | 15 | Id int64 `json:"id"` |
16 | - Name string `json:"nick_name"` | 16 | + Name string `json:"name"` |
17 | ParentId int64 `json:"parent_id"` | 17 | ParentId int64 `json:"parent_id"` |
18 | CompanyId int64 `json:"company_id"` | 18 | CompanyId int64 `json:"company_id"` |
19 | - Relation string `json:"relation"` | 19 | + Path string `json:"path"` |
20 | + Level int `json:"level"` | ||
20 | } | 21 | } |
21 | 22 | ||
22 | var _ PlatformAction = ModulePositionData{} | 23 | var _ PlatformAction = ModulePositionData{} |
@@ -27,7 +28,7 @@ func (m ModulePositionData) DoAction(code string, jsondata []byte) error { | @@ -27,7 +28,7 @@ func (m ModulePositionData) DoAction(code string, jsondata []byte) error { | ||
27 | case "edit": | 28 | case "edit": |
28 | var ( | 29 | var ( |
29 | err error | 30 | err error |
30 | - data []ModulePositionData | 31 | + data ModulePositionData |
31 | ) | 32 | ) |
32 | err = json.Unmarshal(jsondata, &data) | 33 | err = json.Unmarshal(jsondata, &data) |
33 | if err != nil { | 34 | if err != nil { |
@@ -36,7 +37,7 @@ func (m ModulePositionData) DoAction(code string, jsondata []byte) error { | @@ -36,7 +37,7 @@ func (m ModulePositionData) DoAction(code string, jsondata []byte) error { | ||
36 | return UpdatePosition(data) | 37 | return UpdatePosition(data) |
37 | case "add": | 38 | case "add": |
38 | var ( | 39 | var ( |
39 | - data []ModulePositionData | 40 | + data ModulePositionData |
40 | err error | 41 | err error |
41 | ) | 42 | ) |
42 | err = json.Unmarshal(jsondata, &data) | 43 | err = json.Unmarshal(jsondata, &data) |
@@ -47,17 +48,19 @@ func (m ModulePositionData) DoAction(code string, jsondata []byte) error { | @@ -47,17 +48,19 @@ func (m ModulePositionData) DoAction(code string, jsondata []byte) error { | ||
47 | case "delete": | 48 | case "delete": |
48 | var ( | 49 | var ( |
49 | err error | 50 | err error |
50 | - ids []int64 | ||
51 | ) | 51 | ) |
52 | + ids := struct { | ||
53 | + Ids []int64 `json:"ids"` | ||
54 | + }{} | ||
52 | err = json.Unmarshal(jsondata, &ids) | 55 | err = json.Unmarshal(jsondata, &ids) |
53 | if err != nil { | 56 | if err != nil { |
54 | return fmt.Errorf("数据解析失败:%s", err) | 57 | return fmt.Errorf("数据解析失败:%s", err) |
55 | } | 58 | } |
56 | - if len(ids) == 0 { | ||
57 | - return fmt.Errorf("参数错误") | 59 | + if len(ids.Ids) == 0 { |
60 | + return fmt.Errorf("没有删除项") | ||
58 | } | 61 | } |
59 | 62 | ||
60 | - return DeletePosition(ids) | 63 | + return DeletePosition(ids.Ids) |
61 | default: | 64 | default: |
62 | return errors.New("action not found") | 65 | return errors.New("action not found") |
63 | } | 66 | } |
@@ -73,29 +76,21 @@ func (m ModulePositionData) validate() error { | @@ -73,29 +76,21 @@ func (m ModulePositionData) validate() error { | ||
73 | return nil | 76 | return nil |
74 | } | 77 | } |
75 | 78 | ||
76 | -//同步职位数据 | ||
77 | -func UpdatePosition(data []ModulePositionData) error { | ||
78 | - if len(data) == 0 { | ||
79 | - return nil | 79 | +//UpdatePosition 同步职位数据 |
80 | +//TODO 父级数据变更 | ||
81 | +func UpdatePosition(data ModulePositionData) error { | ||
82 | + positioninfo, err := models.GetPositionById(data.Id) | ||
83 | + if err != nil { | ||
84 | + log.Error("获取职位数据失败:%s", err) | ||
85 | + return fmt.Errorf("获取职位数据失败,Id=%d", data.Id) | ||
80 | } | 86 | } |
81 | - o := orm.NewOrm() | ||
82 | - o.Begin() | ||
83 | - for _, v := range data { | ||
84 | - positioninfo, err := models.GetPositionById(v.Id) | ||
85 | - if err != nil { | ||
86 | - log.Error("获取职位数据失败:%s", err) | ||
87 | - return fmt.Errorf("获取职位数据失败,Id=%d", v.Id) | ||
88 | - } | ||
89 | - positioninfo.Name = v.Name | ||
90 | - positioninfo.ParentId = v.ParentId | ||
91 | - positioninfo.Relation = v.Relation | ||
92 | - err = models.UpdatePositionById(positioninfo, []string{"Name", "ParentId", "Relation"}, o) | ||
93 | - if err != nil { | ||
94 | - o.Rollback() | ||
95 | - return err | ||
96 | - } | 87 | + positioninfo.Name = data.Name |
88 | + // positioninfo.ParentId = data.ParentId | ||
89 | + // positioninfo.Relation = data.Path | ||
90 | + err = models.UpdatePositionById(positioninfo, []string{"Name"}) | ||
91 | + if err != nil { | ||
92 | + return err | ||
97 | } | 93 | } |
98 | - o.Commit() | ||
99 | return nil | 94 | return nil |
100 | } | 95 | } |
101 | 96 | ||
@@ -152,42 +147,31 @@ func UpdatePosition(data []ModulePositionData) error { | @@ -152,42 +147,31 @@ func UpdatePosition(data []ModulePositionData) error { | ||
152 | // return nil | 147 | // return nil |
153 | // } | 148 | // } |
154 | 149 | ||
155 | -func AddPosition(data []ModulePositionData) error { | ||
156 | - if len(data) == 0 { | ||
157 | - return nil | ||
158 | - } | 150 | +func AddPosition(data ModulePositionData) error { |
159 | var ( | 151 | var ( |
160 | companyinfo *models.Company | 152 | companyinfo *models.Company |
161 | err error | 153 | err error |
162 | - isRollback bool | ||
163 | ) | 154 | ) |
164 | - companyinfo, err = models.GetCompanyByUCenter(data[0].CompanyId) | 155 | + companyinfo, err = models.GetCompanyByUCenter(data.CompanyId) |
165 | if err != nil { | 156 | if err != nil { |
166 | log.Error("获取公司数据失败:s%", err) | 157 | log.Error("获取公司数据失败:s%", err) |
167 | return errors.New("无效公司") | 158 | return errors.New("无效公司") |
168 | } | 159 | } |
169 | - o := orm.NewOrm() | ||
170 | - o.Begin() | ||
171 | - for _, v := range data { | ||
172 | - positioninfo := &models.Position{ | ||
173 | - Id: v.Id, | ||
174 | - Name: v.Name, | ||
175 | - ParentId: v.ParentId, | ||
176 | - CompanyId: companyinfo.Id, | ||
177 | - Relation: v.Relation, //TODO 格式转换 | ||
178 | - } | ||
179 | - _, err = models.AddPosition(positioninfo) | ||
180 | - if err != nil { | ||
181 | - log.Error("添加职位失败:%s", err) | ||
182 | - isRollback = true | ||
183 | - break | ||
184 | - } | 160 | + |
161 | + positioninfo := &models.Position{ | ||
162 | + Id: data.Id, | ||
163 | + Name: data.Name, | ||
164 | + ParentId: data.ParentId, | ||
165 | + CompanyId: companyinfo.Id, | ||
166 | + Relation: data.Path, //TODO 格式转换 | ||
167 | + Level: data.Level, | ||
185 | } | 168 | } |
186 | - if isRollback { | ||
187 | - o.Rollback() | 169 | + _, err = models.AddPosition(positioninfo) |
170 | + if err != nil { | ||
171 | + log.Error("添加职位失败:%s", err) | ||
188 | return errors.New("添加职位失败") | 172 | return errors.New("添加职位失败") |
189 | } | 173 | } |
190 | - o.Commit() | 174 | + |
191 | return nil | 175 | return nil |
192 | } | 176 | } |
193 | 177 |
-
请 注册 或 登录 后发表评论