|
@@ -286,14 +286,17 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in |
|
@@ -286,14 +286,17 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in |
286
|
RankRangeId: rankRange.Id,
|
286
|
RankRangeId: rankRange.Id,
|
287
|
RangeType: rangetype,
|
287
|
RangeType: rangetype,
|
288
|
RelationId: relationId[i],
|
288
|
RelationId: relationId[i],
|
|
|
289
|
+ RankTypeId: rankTypeId,
|
289
|
}
|
290
|
}
|
290
|
rankRangeDatas = append(rankRangeDatas, m)
|
291
|
rankRangeDatas = append(rankRangeDatas, m)
|
291
|
}
|
292
|
}
|
292
|
- _, err = models.AddRankRangeDataMulti(rankRangeDatas, o)
|
|
|
293
|
- if err != nil {
|
|
|
294
|
- o.Rollback()
|
|
|
295
|
- log.Error("添加rank_range_data记录失败;%s", err)
|
|
|
296
|
- return protocol.NewErrWithMessage("1")
|
293
|
+ if len(rankRangeDatas) > 0 {
|
|
|
294
|
+ _, err = models.AddRankRangeDataMulti(rankRangeDatas, o)
|
|
|
295
|
+ if err != nil {
|
|
|
296
|
+ o.Rollback()
|
|
|
297
|
+ log.Error("添加rank_range_data记录失败;%s", err)
|
|
|
298
|
+ return protocol.NewErrWithMessage("1")
|
|
|
299
|
+ }
|
297
|
}
|
300
|
}
|
298
|
o.Commit()
|
301
|
o.Commit()
|
299
|
return nil
|
302
|
return nil
|
|
@@ -377,6 +380,19 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co |
|
@@ -377,6 +380,19 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co |
377
|
return nil
|
380
|
return nil
|
378
|
}
|
381
|
}
|
379
|
|
382
|
|
|
|
383
|
+func deleteRankRangeDataByRelation(rankTypeId int64, rangeType int8, relationId []int64, om orm.Ormer) error {
|
|
|
384
|
+ _, err := om.QueryTable(&models.RankRangeData{}).
|
|
|
385
|
+ Filter("rank_type_id", rankTypeId).
|
|
|
386
|
+ Filter("range_type", rangeType).
|
|
|
387
|
+ Filter("relation_id__in", relationId).
|
|
|
388
|
+ Delete()
|
|
|
389
|
+ if err != nil {
|
|
|
390
|
+ log.Error("删除rank_range_data数据失败:%s", err)
|
|
|
391
|
+ return err
|
|
|
392
|
+ }
|
|
|
393
|
+ return nil
|
|
|
394
|
+}
|
|
|
395
|
+
|
380
|
func GetRankRangeInfo(id int64) protocol.ResponseRankRangeInfo {
|
396
|
func GetRankRangeInfo(id int64) protocol.ResponseRankRangeInfo {
|
381
|
var (
|
397
|
var (
|
382
|
rankRange *models.RankRange
|
398
|
rankRange *models.RankRange
|
|
@@ -633,9 +649,117 @@ func AllowRankRange(id int64, companyid int64) error { |
|
@@ -633,9 +649,117 @@ func AllowRankRange(id int64, companyid int64) error { |
633
|
return nil
|
649
|
return nil
|
634
|
}
|
650
|
}
|
635
|
|
651
|
|
636
|
-func RankRangeMove(fromId int64, toId int64, RelationId []int64, companyid int64) error {
|
652
|
+func RankRangeMove(fromId int64, toId int64, relationId []int64, companyid int64) error {
|
|
|
653
|
+ var (
|
|
|
654
|
+ fromRankRange *models.RankRange
|
|
|
655
|
+ toRankRange *models.RankRange
|
|
|
656
|
+ err error
|
|
|
657
|
+ )
|
|
|
658
|
+ fromRankRange, err = models.GetRankRangeById(fromId)
|
|
|
659
|
+ if err != nil {
|
|
|
660
|
+ log.Error("获取rank_range 数据失败;%s", err)
|
|
|
661
|
+ return protocol.NewErrWithMessage("1")
|
|
|
662
|
+ }
|
|
|
663
|
+ if fromRankRange.CompanyId != companyid {
|
|
|
664
|
+ log.Error("rank_range的公司不匹配;%s")
|
|
|
665
|
+ return protocol.NewErrWithMessage("1")
|
|
|
666
|
+ }
|
|
|
667
|
+ toRankRange, err = models.GetRankRangeById(toId)
|
|
|
668
|
+ if err != nil {
|
|
|
669
|
+ log.Error("获取rank_range 数据失败;%s", err)
|
|
|
670
|
+ return protocol.NewErrWithMessage("1")
|
|
|
671
|
+ }
|
|
|
672
|
+ if toRankRange.CompanyId != companyid {
|
|
|
673
|
+ log.Error("rank_range的公司不匹配;%s")
|
|
|
674
|
+ return protocol.NewErrWithMessage("1")
|
|
|
675
|
+ }
|
|
|
676
|
+
|
|
|
677
|
+ typeIn := map[int8]int{
|
|
|
678
|
+ models.RANK_RANGE_TYPE_DEPARTMENT: 1,
|
|
|
679
|
+ models.RANK_RANGE_TYPE_DEPARTMENTALL: 1,
|
|
|
680
|
+ models.RANK_RANGE_TYPE_EMPLAYEE: 2,
|
|
|
681
|
+ models.RANK_RANGE_TYPE_EMPLAYEEALL: 2,
|
|
|
682
|
+ }
|
|
|
683
|
+ var (
|
|
|
684
|
+ fromTypeFlag int
|
|
|
685
|
+ ToTypeFlag int
|
|
|
686
|
+ ok bool
|
|
|
687
|
+ )
|
|
|
688
|
+ if fromTypeFlag, ok = typeIn[fromRankRange.Type]; !ok {
|
|
|
689
|
+ return protocol.NewErrWithMessage("1")
|
|
|
690
|
+ }
|
|
|
691
|
+ if ToTypeFlag, ok = typeIn[toRankRange.Type]; !ok {
|
|
|
692
|
+ return protocol.NewErrWithMessage("1")
|
|
|
693
|
+ }
|
|
|
694
|
+ if fromTypeFlag != ToTypeFlag {
|
|
|
695
|
+ log.Error("RankRange类型不一致")
|
|
|
696
|
+ return protocol.NewErrWithMessage("10102")
|
|
|
697
|
+ }
|
|
|
698
|
+
|
|
|
699
|
+ var (
|
|
|
700
|
+ addNew []models.RankRangeData
|
|
|
701
|
+ rangeType int8
|
|
|
702
|
+ )
|
|
|
703
|
+ if typeIn[toRankRange.Type] == 1 {
|
|
|
704
|
+ rangeType = models.RANK_RANGE_TYPE_DEPARTMENT
|
|
|
705
|
+ } else {
|
|
|
706
|
+ rangeType = models.RANK_RANGE_TYPE_EMPLAYEE
|
|
|
707
|
+ }
|
|
|
708
|
+
|
|
|
709
|
+ for i := range relationId {
|
|
|
710
|
+ m := models.RankRangeData{
|
|
|
711
|
+ RankRangeId: toRankRange.Id,
|
|
|
712
|
+ RangeType: rangeType,
|
|
|
713
|
+ RelationId: relationId[i],
|
|
|
714
|
+ }
|
|
|
715
|
+ addNew = append(addNew, m)
|
|
|
716
|
+ }
|
637
|
o := orm.NewOrm()
|
717
|
o := orm.NewOrm()
|
638
|
o.Begin()
|
718
|
o.Begin()
|
|
|
719
|
+ _, err = o.QueryTable(&models.RankRangeData{}).
|
|
|
720
|
+ Filter("rank_range_id", fromId).
|
|
|
721
|
+ Filter("relation_id__in", relationId).
|
|
|
722
|
+ Delete()
|
|
|
723
|
+ if err != nil {
|
|
|
724
|
+ log.Error("删除rank_range_data数据失败:%s", err)
|
|
|
725
|
+ o.Rollback()
|
|
|
726
|
+ return protocol.NewErrWithMessage("1")
|
|
|
727
|
+ }
|
|
|
728
|
+ cnt, err := o.QueryTable(&models.RankRangeData{}).Filter("rank_range_id", fromId).Count()
|
|
|
729
|
+ if err != nil {
|
|
|
730
|
+ log.Error("统计rank_range_data 数据失败:%s", err)
|
|
|
731
|
+ return protocol.NewErrWithMessage("1")
|
|
|
732
|
+ }
|
|
|
733
|
+ if cnt == 0 {
|
|
|
734
|
+ if fromTypeFlag == 1 {
|
|
|
735
|
+ fromRankRange.Type = models.RANK_RANGE_TYPE_DEPARTMENTALL
|
|
|
736
|
+ } else {
|
|
|
737
|
+ fromRankRange.Type = models.RANK_RANGE_TYPE_EMPLAYEEALL
|
|
|
738
|
+ }
|
|
|
739
|
+ err = models.UpdateRankRangeById(fromRankRange, []string{"Type"}, o)
|
|
|
740
|
+ if err != nil {
|
|
|
741
|
+ log.Error("更新rank_range数据失败:%s", err)
|
|
|
742
|
+ o.Rollback()
|
|
|
743
|
+ return protocol.NewErrWithMessage("1")
|
|
|
744
|
+ }
|
|
|
745
|
+ }
|
|
|
746
|
+ _, err = models.AddRankRangeDataMulti(addNew, o)
|
|
|
747
|
+ if err != nil {
|
|
|
748
|
+ log.Error("添加rank_range_data数据失败:%s", err)
|
|
|
749
|
+ o.Rollback()
|
|
|
750
|
+ return protocol.NewErrWithMessage("1")
|
|
|
751
|
+ }
|
|
|
752
|
+ if ToTypeFlag == 1 {
|
|
|
753
|
+ toRankRange.Type = models.RANK_RANGE_TYPE_DEPARTMENT
|
|
|
754
|
+ } else {
|
|
|
755
|
+ toRankRange.Type = models.RANK_RANGE_TYPE_EMPLAYEE
|
|
|
756
|
+ }
|
|
|
757
|
+ err = models.UpdateRankRangeById(toRankRange, []string{"Type"}, o)
|
|
|
758
|
+ if err != nil {
|
|
|
759
|
+ log.Error("更新rank_range数据失败:%s", err)
|
|
|
760
|
+ o.Rollback()
|
|
|
761
|
+ return protocol.NewErrWithMessage("1")
|
|
|
762
|
+ }
|
639
|
o.Commit()
|
763
|
o.Commit()
|
640
|
return nil
|
764
|
return nil
|
641
|
} |
765
|
} |