1
|
package platform
|
1
|
package platform
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "encoding/json"
|
4
|
"errors"
|
5
|
"errors"
|
5
|
"fmt"
|
6
|
"fmt"
|
6
|
"oppmg/common/log"
|
7
|
"oppmg/common/log"
|
7
|
"oppmg/models"
|
8
|
"oppmg/models"
|
8
|
- "oppmg/utils"
|
|
|
9
|
- "strings"
|
|
|
10
|
"time"
|
9
|
"time"
|
11
|
|
10
|
|
12
|
"github.com/astaxie/beego/orm"
|
11
|
"github.com/astaxie/beego/orm"
|
13
|
)
|
12
|
)
|
14
|
|
13
|
|
15
|
type ModulePositionData struct {
|
14
|
type ModulePositionData struct {
|
16
|
- Id int64 `json:"id"`
|
|
|
17
|
- Name string `json:"nick_name"`
|
|
|
18
|
- ParentId int64 `json:"parent_id"`
|
|
|
19
|
- CompanyId int64 `json:"company_id"`
|
|
|
20
|
- Ids []int64 `json:"ids"`
|
15
|
+ Id int64 `json:"id"`
|
|
|
16
|
+ Name string `json:"nick_name"`
|
|
|
17
|
+ ParentId int64 `json:"parent_id"`
|
|
|
18
|
+ CompanyId int64 `json:"company_id"`
|
|
|
19
|
+ Relation string `json:"relation"`
|
21
|
}
|
20
|
}
|
22
|
|
21
|
|
23
|
var _ PlatformAction = ModulePositionData{}
|
22
|
var _ PlatformAction = ModulePositionData{}
|
24
|
|
23
|
|
25
|
//DoAction PlatformAction 的接口实现
|
24
|
//DoAction PlatformAction 的接口实现
|
26
|
-func (m ModulePositionData) DoAction(code string) error {
|
|
|
27
|
- return nil
|
|
|
28
|
-}
|
|
|
29
|
-
|
|
|
30
|
-//同步职位数据
|
|
|
31
|
-func UpdatePosition(data ModulePositionData) error {
|
|
|
32
|
- var (
|
|
|
33
|
- positioninfo *models.Position
|
|
|
34
|
- err error
|
|
|
35
|
- parentPosition *models.Position
|
|
|
36
|
- companyinfo *models.Company
|
|
|
37
|
- )
|
|
|
38
|
- positioninfo, err = models.GetPositionById(data.Id)
|
|
|
39
|
- if err != nil {
|
|
|
40
|
- log.Error("获取职位数据失败:%s", err)
|
|
|
41
|
- return errors.New("获取职位数据失败")
|
|
|
42
|
- }
|
|
|
43
|
- companyinfo, err = models.GetCompanyByUCenter(data.CompanyId)
|
|
|
44
|
- if err != nil {
|
|
|
45
|
- log.Error("获取获取公司数据失败;%s", err)
|
|
|
46
|
- return errors.New("获取获取公司数据失败")
|
|
|
47
|
- }
|
|
|
48
|
- //检查上级
|
|
|
49
|
- if data.ParentId > 0 {
|
|
|
50
|
- parentPosition, err = models.GetPositionById(data.ParentId)
|
25
|
+func (m ModulePositionData) DoAction(code string, jsondata []byte) error {
|
|
|
26
|
+ switch code {
|
|
|
27
|
+ case "edit":
|
|
|
28
|
+ var (
|
|
|
29
|
+ err error
|
|
|
30
|
+ data []ModulePositionData
|
|
|
31
|
+ )
|
|
|
32
|
+ err = json.Unmarshal(jsondata, &data)
|
51
|
if err != nil {
|
33
|
if err != nil {
|
52
|
- log.Error("获取父级职位数据失败;%s", err)
|
|
|
53
|
- return errors.New("获取父级职位数据失败;")
|
34
|
+ return fmt.Errorf("数据解析失败:%s", err)
|
54
|
}
|
35
|
}
|
55
|
- if parentPosition.CompanyId == companyinfo.Id {
|
|
|
56
|
- log.Error("父级职位公司不匹配")
|
|
|
57
|
- return errors.New("父级职位公司不匹配")
|
36
|
+ return UpdatePosition(data)
|
|
|
37
|
+ case "add":
|
|
|
38
|
+ var (
|
|
|
39
|
+ data []ModulePositionData
|
|
|
40
|
+ err error
|
|
|
41
|
+ )
|
|
|
42
|
+ err = json.Unmarshal(jsondata, &data)
|
|
|
43
|
+ if err != nil {
|
|
|
44
|
+ return fmt.Errorf("数据解析失败:%s", err)
|
|
|
45
|
+ }
|
|
|
46
|
+ return AddPosition(data)
|
|
|
47
|
+ case "delete":
|
|
|
48
|
+ var (
|
|
|
49
|
+ err error
|
|
|
50
|
+ ids []int64
|
|
|
51
|
+ )
|
|
|
52
|
+ err = json.Unmarshal(jsondata, &ids)
|
|
|
53
|
+ if err != nil {
|
|
|
54
|
+ return fmt.Errorf("数据解析失败:%s", err)
|
58
|
}
|
55
|
}
|
|
|
56
|
+ if len(ids) == 0 {
|
|
|
57
|
+ return fmt.Errorf("参数错误")
|
|
|
58
|
+ }
|
|
|
59
|
+
|
|
|
60
|
+ return DeletePosition(ids)
|
|
|
61
|
+ default:
|
|
|
62
|
+ return errors.New("action not found")
|
59
|
}
|
63
|
}
|
60
|
- o := orm.NewOrm()
|
|
|
61
|
- o.Begin()
|
|
|
62
|
- positioninfo.Name = data.Name
|
|
|
63
|
- err = models.UpdatePositionById(positioninfo, []string{"Name", "UpdateAt"}, o)
|
|
|
64
|
- if err != nil {
|
|
|
65
|
- o.Rollback()
|
|
|
66
|
- return err
|
64
|
+}
|
|
|
65
|
+
|
|
|
66
|
+func (m ModulePositionData) validate() error {
|
|
|
67
|
+ if m.Id <= 0 {
|
|
|
68
|
+ return errors.New("错误:id<=0 ")
|
67
|
}
|
69
|
}
|
68
|
- err = positionRelationUpdate(positioninfo, parentPosition, o)
|
|
|
69
|
- if err != nil {
|
|
|
70
|
- o.Rollback()
|
|
|
71
|
- return err
|
70
|
+ if len(m.Name) == 0 {
|
|
|
71
|
+ return errors.New("错误:name长度为0")
|
72
|
}
|
72
|
}
|
73
|
- o.Commit()
|
|
|
74
|
return nil
|
73
|
return nil
|
75
|
}
|
74
|
}
|
76
|
|
75
|
|
77
|
-//positionRelationUpdate 处理部门上级发生变化的情况
|
|
|
78
|
-func positionRelationUpdate(positionUpdate *models.Position, newparent *models.Position, o orm.Ormer) error {
|
|
|
79
|
- const (
|
|
|
80
|
- //获取某个部门的下级部门 锁数据 select ... for update
|
|
|
81
|
- dataSql0 string = `SELECT id,relation FROM position WHERE relation LIKE ? AND delete_at = 0 FOR UPDATE`
|
|
|
82
|
- //更新关系树
|
|
|
83
|
- dataSql2 string = `update position set relation=? where id=?`
|
|
|
84
|
- //更新departUpdate的parent_id
|
|
|
85
|
- dataSql3 string = `update position set parent_id=? where id=?`
|
|
|
86
|
- )
|
|
|
87
|
- var (
|
|
|
88
|
- positionSubset []models.Position //子级部门
|
|
|
89
|
- err error
|
|
|
90
|
- oldRelation string = positionUpdate.Relation
|
|
|
91
|
- relationLike string = oldRelation + "%"
|
|
|
92
|
- newRelation string
|
|
|
93
|
- )
|
|
|
94
|
- if newparent == nil || newparent.Id == 0 {
|
|
|
95
|
- //修改节点为顶层节点的情况
|
|
|
96
|
- newparent = &models.Position{}
|
|
|
97
|
- newRelation = fmt.Sprintf("%d", positionUpdate.Id)
|
|
|
98
|
- } else {
|
|
|
99
|
- newRelation = fmt.Sprintf("%s/%d", newparent.Relation, positionUpdate.Id)
|
|
|
100
|
- }
|
|
|
101
|
- //修改部门的parent_id
|
|
|
102
|
- err = utils.ExecuteSQLWithOrmer(o, dataSql3, newparent.Id, positionUpdate.Id)
|
|
|
103
|
- if err != nil {
|
|
|
104
|
- e := fmt.Errorf("EXECUTE SQL err:%s", err)
|
|
|
105
|
- log.Error(e.Error())
|
|
|
106
|
- return errors.New("更新数据失败")
|
|
|
107
|
- }
|
|
|
108
|
- //获取部门及子级部门的relation和id
|
|
|
109
|
- err = utils.ExecuteQueryAllWithOrmer(o, &positionSubset, dataSql0, relationLike)
|
|
|
110
|
- if err != nil {
|
|
|
111
|
- e := fmt.Errorf("EXECUTE SQL err:%s", err)
|
|
|
112
|
- log.Error(e.Error())
|
|
|
113
|
- return errors.New("更新数据失败")
|
76
|
+//同步职位数据
|
|
|
77
|
+func UpdatePosition(data []ModulePositionData) error {
|
|
|
78
|
+ if len(data) == 0 {
|
|
|
79
|
+ return nil
|
114
|
}
|
80
|
}
|
115
|
- //修改部门及子级部门的relation
|
|
|
116
|
- for i := range positionSubset {
|
|
|
117
|
- //重建关系树
|
|
|
118
|
- s := strings.TrimPrefix(positionSubset[i].Relation, oldRelation)
|
|
|
119
|
- positionSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s))
|
|
|
120
|
- err = utils.ExecuteSQLWithOrmer(o, dataSql2, positionSubset[i].Relation, positionSubset[i].Id)
|
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)
|
121
|
if err != nil {
|
93
|
if err != nil {
|
122
|
- e := fmt.Errorf("EXECUTE SQL err:%s", err)
|
|
|
123
|
- log.Error(e.Error())
|
|
|
124
|
- return errors.New("更新数据失败")
|
94
|
+ o.Rollback()
|
|
|
95
|
+ return err
|
125
|
}
|
96
|
}
|
126
|
}
|
97
|
}
|
|
|
98
|
+ o.Commit()
|
127
|
return nil
|
99
|
return nil
|
128
|
}
|
100
|
}
|
129
|
|
101
|
|
130
|
-func AddPosition(data ModulePositionData) error {
|
102
|
+//positionRelationUpdate 处理部门上级发生变化的情况
|
|
|
103
|
+// func positionRelationUpdate(positionUpdate *models.Position, newparent *models.Position, o orm.Ormer) error {
|
|
|
104
|
+// const (
|
|
|
105
|
+// //获取某个部门的下级部门 锁数据 select ... for update
|
|
|
106
|
+// dataSql0 string = `SELECT id,relation FROM position WHERE relation LIKE ? AND delete_at = 0 FOR UPDATE`
|
|
|
107
|
+// //更新关系树
|
|
|
108
|
+// dataSql2 string = `update position set relation=? where id=?`
|
|
|
109
|
+// //更新departUpdate的parent_id
|
|
|
110
|
+// dataSql3 string = `update position set parent_id=? where id=?`
|
|
|
111
|
+// )
|
|
|
112
|
+// var (
|
|
|
113
|
+// positionSubset []models.Position //子级部门
|
|
|
114
|
+// err error
|
|
|
115
|
+// oldRelation string = positionUpdate.Relation
|
|
|
116
|
+// relationLike string = oldRelation + "%"
|
|
|
117
|
+// newRelation string
|
|
|
118
|
+// )
|
|
|
119
|
+// if newparent == nil || newparent.Id == 0 {
|
|
|
120
|
+// //修改节点为顶层节点的情况
|
|
|
121
|
+// newparent = &models.Position{}
|
|
|
122
|
+// newRelation = fmt.Sprintf("%d", positionUpdate.Id)
|
|
|
123
|
+// } else {
|
|
|
124
|
+// newRelation = fmt.Sprintf("%s/%d", newparent.Relation, positionUpdate.Id)
|
|
|
125
|
+// }
|
|
|
126
|
+// //修改部门的parent_id
|
|
|
127
|
+// err = utils.ExecuteSQLWithOrmer(o, dataSql3, newparent.Id, positionUpdate.Id)
|
|
|
128
|
+// if err != nil {
|
|
|
129
|
+// e := fmt.Errorf("EXECUTE SQL err:%s", err)
|
|
|
130
|
+// log.Error(e.Error())
|
|
|
131
|
+// return errors.New("更新数据失败")
|
|
|
132
|
+// }
|
|
|
133
|
+// //获取部门及子级部门的relation和id
|
|
|
134
|
+// err = utils.ExecuteQueryAllWithOrmer(o, &positionSubset, dataSql0, relationLike)
|
|
|
135
|
+// if err != nil {
|
|
|
136
|
+// e := fmt.Errorf("EXECUTE SQL err:%s", err)
|
|
|
137
|
+// log.Error(e.Error())
|
|
|
138
|
+// return errors.New("更新数据失败")
|
|
|
139
|
+// }
|
|
|
140
|
+// //修改部门及子级部门的relation
|
|
|
141
|
+// for i := range positionSubset {
|
|
|
142
|
+// //重建关系树
|
|
|
143
|
+// s := strings.TrimPrefix(positionSubset[i].Relation, oldRelation)
|
|
|
144
|
+// positionSubset[i].Relation = strings.TrimSpace(fmt.Sprintf("%s%s", newRelation, s))
|
|
|
145
|
+// err = utils.ExecuteSQLWithOrmer(o, dataSql2, positionSubset[i].Relation, positionSubset[i].Id)
|
|
|
146
|
+// if err != nil {
|
|
|
147
|
+// e := fmt.Errorf("EXECUTE SQL err:%s", err)
|
|
|
148
|
+// log.Error(e.Error())
|
|
|
149
|
+// return errors.New("更新数据失败")
|
|
|
150
|
+// }
|
|
|
151
|
+// }
|
|
|
152
|
+// return nil
|
|
|
153
|
+// }
|
|
|
154
|
+
|
|
|
155
|
+func AddPosition(data []ModulePositionData) error {
|
|
|
156
|
+ if len(data) == 0 {
|
|
|
157
|
+ return nil
|
|
|
158
|
+ }
|
131
|
var (
|
159
|
var (
|
132
|
- companyinfo *models.Company
|
|
|
133
|
- err error
|
|
|
134
|
- parentPosition *models.Position
|
160
|
+ companyinfo *models.Company
|
|
|
161
|
+ err error
|
|
|
162
|
+ isRollback bool
|
135
|
)
|
163
|
)
|
136
|
- companyinfo, err = models.GetCompanyByUCenter(data.CompanyId)
|
164
|
+ companyinfo, err = models.GetCompanyByUCenter(data[0].CompanyId)
|
137
|
if err != nil {
|
165
|
if err != nil {
|
138
|
log.Error("获取公司数据失败:s%", err)
|
166
|
log.Error("获取公司数据失败:s%", err)
|
139
|
return errors.New("无效公司")
|
167
|
return errors.New("无效公司")
|
140
|
}
|
168
|
}
|
141
|
- if data.ParentId > 0 {
|
|
|
142
|
- parentPosition, err = models.GetPositionById(data.ParentId)
|
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)
|
143
|
if err != nil {
|
180
|
if err != nil {
|
144
|
- log.Error("获取父级职位失败:%s", err)
|
|
|
145
|
- return errors.New("获取父级职位失败")
|
181
|
+ log.Error("添加职位失败:%s", err)
|
|
|
182
|
+ isRollback = true
|
|
|
183
|
+ break
|
146
|
}
|
184
|
}
|
147
|
- } else {
|
|
|
148
|
- parentPosition = &models.Position{}
|
|
|
149
|
}
|
185
|
}
|
150
|
-
|
|
|
151
|
- positioninfo := &models.Position{
|
|
|
152
|
- Id: data.Id,
|
|
|
153
|
- Name: data.Name,
|
|
|
154
|
- ParentId: data.ParentId,
|
|
|
155
|
- CompanyId: companyinfo.Id,
|
|
|
156
|
- }
|
|
|
157
|
-
|
|
|
158
|
- positioninfo.SetRelation(parentPosition)
|
|
|
159
|
- _, err = models.AddPosition(positioninfo)
|
|
|
160
|
- if err != nil {
|
|
|
161
|
- log.Error("添加职位失败:%s", err)
|
186
|
+ if isRollback {
|
|
|
187
|
+ o.Rollback()
|
162
|
return errors.New("添加职位失败")
|
188
|
return errors.New("添加职位失败")
|
163
|
}
|
189
|
}
|
|
|
190
|
+ o.Commit()
|
164
|
return nil
|
191
|
return nil
|
165
|
}
|
192
|
}
|
166
|
|
193
|
|
167
|
-func DeletePosition(ids []int64, ucompanyid int64) error {
|
|
|
168
|
- //检查是否可以被删除
|
|
|
169
|
- var (
|
|
|
170
|
- //根据参数获取的职位
|
|
|
171
|
- positionDelete []*models.Position
|
|
|
172
|
- //最终需要操作的职位
|
|
|
173
|
- toDelete = make(map[int64]*models.Position)
|
|
|
174
|
- companyinfo *models.Company
|
|
|
175
|
- err error
|
|
|
176
|
- )
|
|
|
177
|
- const (
|
|
|
178
|
- //获取部门子集,
|
|
|
179
|
- dataSql0 string = `SELECT id,relation FROM position WHERE relation LIKE ? AND delete_at = 0 `
|
|
|
180
|
- )
|
|
|
181
|
- companyinfo, err = models.GetCompanyByUCenter(ucompanyid)
|
|
|
182
|
- if err != nil {
|
|
|
183
|
- e := fmt.Errorf("获取公司数据失败")
|
|
|
184
|
- log.Error(e.Error())
|
|
|
185
|
- return e
|
|
|
186
|
- }
|
|
|
187
|
- for _, id := range ids {
|
|
|
188
|
- var p *models.Position
|
|
|
189
|
- p, err := models.GetPositionById(id)
|
|
|
190
|
- if err != nil {
|
|
|
191
|
- log.Error("获取职位失败Id:%d,err:%s", id, err)
|
|
|
192
|
- continue
|
|
|
193
|
- }
|
|
|
194
|
- if p.CompanyId != companyinfo.Id {
|
|
|
195
|
- log.Error("公司id不匹配")
|
|
|
196
|
- return errors.New("公司id不匹配")
|
|
|
197
|
- }
|
|
|
198
|
- positionDelete = append(positionDelete, p)
|
|
|
199
|
- toDelete[p.Id] = p
|
|
|
200
|
- }
|
|
|
201
|
- for _, pos := range positionDelete {
|
|
|
202
|
- var positionsubset []models.Position
|
|
|
203
|
- relationLike := pos.Relation + "%"
|
|
|
204
|
- err := utils.ExecuteQueryAll(&positionsubset, dataSql0, relationLike)
|
|
|
205
|
- if err != nil {
|
|
|
206
|
- e := fmt.Errorf("EXECUTE SQL err:%s", err)
|
|
|
207
|
- log.Error(e.Error())
|
|
|
208
|
- return e
|
|
|
209
|
- }
|
|
|
210
|
- for k, subset := range positionsubset {
|
|
|
211
|
- if _, ok := toDelete[subset.Id]; !ok {
|
|
|
212
|
- toDelete[subset.Id] = &positionsubset[k]
|
|
|
213
|
- }
|
|
|
214
|
- }
|
|
|
215
|
- }
|
|
|
216
|
- var (
|
|
|
217
|
- deleteIds []string
|
|
|
218
|
- dataSql2 string = `update position set delete_at=%s where id IN (%s)`
|
|
|
219
|
- nowTime string = time.Now().Format("2006-01-02 15:04:05")
|
|
|
220
|
- )
|
|
|
221
|
- for k, _ := range toDelete {
|
|
|
222
|
- deleteIds = append(deleteIds, fmt.Sprint(k))
|
|
|
223
|
- }
|
|
|
224
|
- if len(deleteIds) == 0 {
|
|
|
225
|
- return nil
|
|
|
226
|
- }
|
|
|
227
|
- dataSql2 = fmt.Sprintf(dataSql2, nowTime, strings.Join(deleteIds, ","))
|
194
|
+// DeletePosition ...
|
|
|
195
|
+func DeletePosition(ids []int64) error {
|
228
|
o := orm.NewOrm()
|
196
|
o := orm.NewOrm()
|
229
|
- o.Begin()
|
|
|
230
|
- err = utils.ExecuteSQLWithOrmer(o, dataSql2)
|
197
|
+ _, err := o.QueryTable(&models.Position{}).
|
|
|
198
|
+ Filter("id__in", ids).
|
|
|
199
|
+ Update(orm.Params{
|
|
|
200
|
+ "delete_at": time.Now().Format("2006-01-02 15:04:05"),
|
|
|
201
|
+ })
|
231
|
if err != nil {
|
202
|
if err != nil {
|
232
|
- e := fmt.Errorf("EXCUTE SQL ERR:%s", err)
|
|
|
233
|
- return e
|
203
|
+ log.Error("更新position数据失败,err:%s", err)
|
|
|
204
|
+ return errors.New("删除职位数据失败")
|
234
|
}
|
205
|
}
|
235
|
- o.Commit()
|
|
|
236
|
return nil
|
206
|
return nil
|
237
|
}
|
207
|
}
|
|
|
208
|
+
|
|
|
209
|
+// func DeletePosition(ids []int64, ucompanyid int64) error {
|
|
|
210
|
+// //检查是否可以被删除
|
|
|
211
|
+// var (
|
|
|
212
|
+// //根据参数获取的职位
|
|
|
213
|
+// positionDelete []*models.Position
|
|
|
214
|
+// //最终需要操作的职位
|
|
|
215
|
+// toDelete = make(map[int64]*models.Position)
|
|
|
216
|
+// companyinfo *models.Company
|
|
|
217
|
+// err error
|
|
|
218
|
+// )
|
|
|
219
|
+// const (
|
|
|
220
|
+// //获取部门子集,
|
|
|
221
|
+// dataSql0 string = `SELECT id,relation FROM position WHERE relation LIKE ? AND delete_at = 0 `
|
|
|
222
|
+// )
|
|
|
223
|
+// companyinfo, err = models.GetCompanyByUCenter(ucompanyid)
|
|
|
224
|
+// if err != nil {
|
|
|
225
|
+// e := fmt.Errorf("获取公司数据失败")
|
|
|
226
|
+// log.Error(e.Error())
|
|
|
227
|
+// return e
|
|
|
228
|
+// }
|
|
|
229
|
+// for _, id := range ids {
|
|
|
230
|
+// var p *models.Position
|
|
|
231
|
+// p, err := models.GetPositionById(id)
|
|
|
232
|
+// if err != nil {
|
|
|
233
|
+// log.Error("获取职位失败Id:%d,err:%s", id, err)
|
|
|
234
|
+// continue
|
|
|
235
|
+// }
|
|
|
236
|
+// if p.CompanyId != companyinfo.Id {
|
|
|
237
|
+// log.Error("公司id不匹配")
|
|
|
238
|
+// return errors.New("公司id不匹配")
|
|
|
239
|
+// }
|
|
|
240
|
+// positionDelete = append(positionDelete, p)
|
|
|
241
|
+// toDelete[p.Id] = p
|
|
|
242
|
+// }
|
|
|
243
|
+// for _, pos := range positionDelete {
|
|
|
244
|
+// var positionsubset []models.Position
|
|
|
245
|
+// relationLike := pos.Relation + "%"
|
|
|
246
|
+// err := utils.ExecuteQueryAll(&positionsubset, dataSql0, relationLike)
|
|
|
247
|
+// if err != nil {
|
|
|
248
|
+// e := fmt.Errorf("EXECUTE SQL err:%s", err)
|
|
|
249
|
+// log.Error(e.Error())
|
|
|
250
|
+// return e
|
|
|
251
|
+// }
|
|
|
252
|
+// for k, subset := range positionsubset {
|
|
|
253
|
+// if _, ok := toDelete[subset.Id]; !ok {
|
|
|
254
|
+// toDelete[subset.Id] = &positionsubset[k]
|
|
|
255
|
+// }
|
|
|
256
|
+// }
|
|
|
257
|
+// }
|
|
|
258
|
+// var (
|
|
|
259
|
+// deleteIds []string
|
|
|
260
|
+// dataSql2 string = `update position set delete_at=%s where id IN (%s)`
|
|
|
261
|
+// nowTime string = time.Now().Format("2006-01-02 15:04:05")
|
|
|
262
|
+// )
|
|
|
263
|
+// for k, _ := range toDelete {
|
|
|
264
|
+// deleteIds = append(deleteIds, fmt.Sprint(k))
|
|
|
265
|
+// }
|
|
|
266
|
+// if len(deleteIds) == 0 {
|
|
|
267
|
+// return nil
|
|
|
268
|
+// }
|
|
|
269
|
+// dataSql2 = fmt.Sprintf(dataSql2, nowTime, strings.Join(deleteIds, ","))
|
|
|
270
|
+// o := orm.NewOrm()
|
|
|
271
|
+// o.Begin()
|
|
|
272
|
+// err = utils.ExecuteSQLWithOrmer(o, dataSql2)
|
|
|
273
|
+// if err != nil {
|
|
|
274
|
+// e := fmt.Errorf("EXCUTE SQL ERR:%s", err)
|
|
|
275
|
+// return e
|
|
|
276
|
+// }
|
|
|
277
|
+// o.Commit()
|
|
|
278
|
+// return nil
|
|
|
279
|
+// } |