...
|
...
|
@@ -286,14 +286,17 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in |
|
|
RankRangeId: rankRange.Id,
|
|
|
RangeType: rangetype,
|
|
|
RelationId: relationId[i],
|
|
|
RankTypeId: rankTypeId,
|
|
|
}
|
|
|
rankRangeDatas = append(rankRangeDatas, m)
|
|
|
}
|
|
|
_, err = models.AddRankRangeDataMulti(rankRangeDatas, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("添加rank_range_data记录失败;%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
if len(rankRangeDatas) > 0 {
|
|
|
_, err = models.AddRankRangeDataMulti(rankRangeDatas, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("添加rank_range_data记录失败;%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
}
|
|
|
o.Commit()
|
|
|
return nil
|
...
|
...
|
@@ -377,6 +380,19 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func deleteRankRangeDataByRelation(rankTypeId int64, rangeType int8, relationId []int64, om orm.Ormer) error {
|
|
|
_, err := om.QueryTable(&models.RankRangeData{}).
|
|
|
Filter("rank_type_id", rankTypeId).
|
|
|
Filter("range_type", rangeType).
|
|
|
Filter("relation_id__in", relationId).
|
|
|
Delete()
|
|
|
if err != nil {
|
|
|
log.Error("删除rank_range_data数据失败:%s", err)
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func GetRankRangeInfo(id int64) protocol.ResponseRankRangeInfo {
|
|
|
var (
|
|
|
rankRange *models.RankRange
|
...
|
...
|
@@ -633,9 +649,117 @@ func AllowRankRange(id int64, companyid int64) error { |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func RankRangeMove(fromId int64, toId int64, RelationId []int64, companyid int64) error {
|
|
|
func RankRangeMove(fromId int64, toId int64, relationId []int64, companyid int64) error {
|
|
|
var (
|
|
|
fromRankRange *models.RankRange
|
|
|
toRankRange *models.RankRange
|
|
|
err error
|
|
|
)
|
|
|
fromRankRange, err = models.GetRankRangeById(fromId)
|
|
|
if err != nil {
|
|
|
log.Error("获取rank_range 数据失败;%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if fromRankRange.CompanyId != companyid {
|
|
|
log.Error("rank_range的公司不匹配;%s")
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
toRankRange, err = models.GetRankRangeById(toId)
|
|
|
if err != nil {
|
|
|
log.Error("获取rank_range 数据失败;%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if toRankRange.CompanyId != companyid {
|
|
|
log.Error("rank_range的公司不匹配;%s")
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
|
|
|
typeIn := map[int8]int{
|
|
|
models.RANK_RANGE_TYPE_DEPARTMENT: 1,
|
|
|
models.RANK_RANGE_TYPE_DEPARTMENTALL: 1,
|
|
|
models.RANK_RANGE_TYPE_EMPLAYEE: 2,
|
|
|
models.RANK_RANGE_TYPE_EMPLAYEEALL: 2,
|
|
|
}
|
|
|
var (
|
|
|
fromTypeFlag int
|
|
|
ToTypeFlag int
|
|
|
ok bool
|
|
|
)
|
|
|
if fromTypeFlag, ok = typeIn[fromRankRange.Type]; !ok {
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if ToTypeFlag, ok = typeIn[toRankRange.Type]; !ok {
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if fromTypeFlag != ToTypeFlag {
|
|
|
log.Error("RankRange类型不一致")
|
|
|
return protocol.NewErrWithMessage("10102")
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
addNew []models.RankRangeData
|
|
|
rangeType int8
|
|
|
)
|
|
|
if typeIn[toRankRange.Type] == 1 {
|
|
|
rangeType = models.RANK_RANGE_TYPE_DEPARTMENT
|
|
|
} else {
|
|
|
rangeType = models.RANK_RANGE_TYPE_EMPLAYEE
|
|
|
}
|
|
|
|
|
|
for i := range relationId {
|
|
|
m := models.RankRangeData{
|
|
|
RankRangeId: toRankRange.Id,
|
|
|
RangeType: rangeType,
|
|
|
RelationId: relationId[i],
|
|
|
}
|
|
|
addNew = append(addNew, m)
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
_, err = o.QueryTable(&models.RankRangeData{}).
|
|
|
Filter("rank_range_id", fromId).
|
|
|
Filter("relation_id__in", relationId).
|
|
|
Delete()
|
|
|
if err != nil {
|
|
|
log.Error("删除rank_range_data数据失败:%s", err)
|
|
|
o.Rollback()
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
cnt, err := o.QueryTable(&models.RankRangeData{}).Filter("rank_range_id", fromId).Count()
|
|
|
if err != nil {
|
|
|
log.Error("统计rank_range_data 数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if cnt == 0 {
|
|
|
if fromTypeFlag == 1 {
|
|
|
fromRankRange.Type = models.RANK_RANGE_TYPE_DEPARTMENTALL
|
|
|
} else {
|
|
|
fromRankRange.Type = models.RANK_RANGE_TYPE_EMPLAYEEALL
|
|
|
}
|
|
|
err = models.UpdateRankRangeById(fromRankRange, []string{"Type"}, o)
|
|
|
if err != nil {
|
|
|
log.Error("更新rank_range数据失败:%s", err)
|
|
|
o.Rollback()
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
}
|
|
|
_, err = models.AddRankRangeDataMulti(addNew, o)
|
|
|
if err != nil {
|
|
|
log.Error("添加rank_range_data数据失败:%s", err)
|
|
|
o.Rollback()
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if ToTypeFlag == 1 {
|
|
|
toRankRange.Type = models.RANK_RANGE_TYPE_DEPARTMENT
|
|
|
} else {
|
|
|
toRankRange.Type = models.RANK_RANGE_TYPE_EMPLAYEE
|
|
|
}
|
|
|
err = models.UpdateRankRangeById(toRankRange, []string{"Type"}, o)
|
|
|
if err != nil {
|
|
|
log.Error("更新rank_range数据失败:%s", err)
|
|
|
o.Rollback()
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
o.Commit()
|
|
|
return nil
|
|
|
} |
...
|
...
|
|