|
@@ -341,18 +341,21 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in |
|
@@ -341,18 +341,21 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in |
341
|
return protocol.NewErrWithMessage("1")
|
341
|
return protocol.NewErrWithMessage("1")
|
342
|
}
|
342
|
}
|
343
|
|
343
|
|
344
|
- for i := range relationId {
|
344
|
+ //获取部门或人员数据
|
|
|
345
|
+ newRelationId := getDataForRankRnageRelation(companyid, rangetype, relationId)
|
|
|
346
|
+ for i := range newRelationId {
|
345
|
m := models.RankRangeData{
|
347
|
m := models.RankRangeData{
|
346
|
RankRangeId: rankRange.Id,
|
348
|
RankRangeId: rankRange.Id,
|
347
|
RangeType: rangetype,
|
349
|
RangeType: rangetype,
|
348
|
- RelationId: relationId[i],
|
350
|
+ RelationId: newRelationId[i],
|
349
|
RankTypeId: rankTypeId,
|
351
|
RankTypeId: rankTypeId,
|
350
|
}
|
352
|
}
|
351
|
rankRangeDatas = append(rankRangeDatas, m)
|
353
|
rankRangeDatas = append(rankRangeDatas, m)
|
352
|
}
|
354
|
}
|
|
|
355
|
+
|
353
|
if len(rankRangeDatas) > 0 {
|
356
|
if len(rankRangeDatas) > 0 {
|
354
|
//TODO 去除其他分组的重复项
|
357
|
//TODO 去除其他分组的重复项
|
355
|
- err = deleteRankRangeDataByRelation(rankTypeId, rangetype, relationId, o)
|
358
|
+ err = deleteRankRangeDataByRelation(rankTypeId, rangetype, newRelationId, o)
|
356
|
if err != nil {
|
359
|
if err != nil {
|
357
|
log.Error(err.Error())
|
360
|
log.Error(err.Error())
|
358
|
o.Rollback()
|
361
|
o.Rollback()
|
|
@@ -369,6 +372,49 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in |
|
@@ -369,6 +372,49 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in |
369
|
return nil
|
372
|
return nil
|
370
|
}
|
373
|
}
|
371
|
|
374
|
|
|
|
375
|
+func getDataForRankRnageRelation(companyid int64, rangeType int8, relationId []int64) (newRelationId []int64) {
|
|
|
376
|
+ o := orm.NewOrm()
|
|
|
377
|
+ var (
|
|
|
378
|
+ err error
|
|
|
379
|
+ )
|
|
|
380
|
+ switch rangeType {
|
|
|
381
|
+ case models.RANK_RANGE_TYPE_EMPLAYEE:
|
|
|
382
|
+ var (
|
|
|
383
|
+ users []models.UserCompany
|
|
|
384
|
+ )
|
|
|
385
|
+ qs := o.QueryTable(&models.UserCompany{}).
|
|
|
386
|
+ Filter("delete_at", 0).
|
|
|
387
|
+ Filter("company_id", companyid)
|
|
|
388
|
+ if len(relationId) > 0 {
|
|
|
389
|
+ qs = qs.Filter("id__in", relationId)
|
|
|
390
|
+ }
|
|
|
391
|
+ _, err = qs.All(&users, "Id")
|
|
|
392
|
+ if err == nil {
|
|
|
393
|
+ for _, v := range users {
|
|
|
394
|
+ newRelationId = append(newRelationId, v.Id)
|
|
|
395
|
+ }
|
|
|
396
|
+ }
|
|
|
397
|
+ case models.RANK_RANGE_TYPE_DEPARTMENT:
|
|
|
398
|
+ var (
|
|
|
399
|
+ departments []models.Department
|
|
|
400
|
+ )
|
|
|
401
|
+ qs := o.QueryTable(&models.Department{}).
|
|
|
402
|
+ Filter("delete_at", 0).
|
|
|
403
|
+ Filter("company_id", companyid).
|
|
|
404
|
+ Filter("is_top", 0)
|
|
|
405
|
+ if len(relationId) > 0 {
|
|
|
406
|
+ qs = qs.Filter("id__in", relationId)
|
|
|
407
|
+ }
|
|
|
408
|
+ _, err = qs.All(&departments, "Id")
|
|
|
409
|
+ if err == nil {
|
|
|
410
|
+ for _, v := range departments {
|
|
|
411
|
+ newRelationId = append(newRelationId, v.Id)
|
|
|
412
|
+ }
|
|
|
413
|
+ }
|
|
|
414
|
+ }
|
|
|
415
|
+ return newRelationId
|
|
|
416
|
+}
|
|
|
417
|
+
|
372
|
func EditRankRange(id int64, name string, rangetype int8, relationId []int64, companyid int64) error {
|
418
|
func EditRankRange(id int64, name string, rangetype int8, relationId []int64, companyid int64) error {
|
373
|
var (
|
419
|
var (
|
374
|
rankRangeDatas []models.RankRangeData
|
420
|
rankRangeDatas []models.RankRangeData
|
|
@@ -398,14 +444,15 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co |
|
@@ -398,14 +444,15 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co |
398
|
var (
|
444
|
var (
|
399
|
addRangeData []models.RankRangeData
|
445
|
addRangeData []models.RankRangeData
|
400
|
)
|
446
|
)
|
401
|
- for i := range relationId {
|
|
|
402
|
- r := models.RankRangeData{
|
|
|
403
|
- RankRangeId: id,
|
447
|
+ newRelationId := getDataForRankRnageRelation(companyid, rangetype, relationId)
|
|
|
448
|
+ for i := range newRelationId {
|
|
|
449
|
+ m := models.RankRangeData{
|
|
|
450
|
+ RankRangeId: rankRange.Id,
|
404
|
RangeType: rangetype,
|
451
|
RangeType: rangetype,
|
405
|
- RelationId: relationId[i],
|
452
|
+ RelationId: newRelationId[i],
|
406
|
RankTypeId: rankRange.RankTypeId,
|
453
|
RankTypeId: rankRange.RankTypeId,
|
407
|
}
|
454
|
}
|
408
|
- addRangeData = append(addRangeData, r)
|
455
|
+ addRangeData = append(addRangeData, m)
|
409
|
}
|
456
|
}
|
410
|
rankRange.Name = name
|
457
|
rankRange.Name = name
|
411
|
rankRange.Type = rangetype
|
458
|
rankRange.Type = rangetype
|
|
@@ -426,9 +473,9 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co |
|
@@ -426,9 +473,9 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co |
426
|
return protocol.NewErrWithMessage("1")
|
473
|
return protocol.NewErrWithMessage("1")
|
427
|
}
|
474
|
}
|
428
|
}
|
475
|
}
|
429
|
- if len(relationId) > 0 {
|
476
|
+ if len(newRelationId) > 0 {
|
430
|
//TODO 去除其他分组的重复项
|
477
|
//TODO 去除其他分组的重复项
|
431
|
- err = deleteRankRangeDataByRelation(rankRange.RankTypeId, rangetype, relationId, o)
|
478
|
+ err = deleteRankRangeDataByRelation(rankRange.RankTypeId, rangetype, newRelationId, o)
|
432
|
if err != nil {
|
479
|
if err != nil {
|
433
|
log.Error(err.Error())
|
480
|
log.Error(err.Error())
|
434
|
o.Rollback()
|
481
|
o.Rollback()
|