作者 tangxvhui

bug 修复

... ... @@ -296,18 +296,18 @@ func (c RankController) RankRangeAdd() {
switch param.RangeType {
case 1:
//员工
if len(param.RelationId) == 0 {
param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEEALL
} else {
param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE
}
// if len(param.RelationId) == 0 {
// param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEEALL
// } else {
param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE
// }
case 2:
//部门
if len(param.RelationId) == 0 {
param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENTALL
} else {
param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT
}
// if len(param.RelationId) == 0 {
// param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENTALL
// } else {
param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT
// }
default:
log.Error("param.RangeType err")
msg = protocol.BadRequestParam("1")
... ...
... ... @@ -191,6 +191,7 @@ func GetDepartmentByCompanyId(companyId int64) ([]Department, error) {
o := orm.NewOrm()
_, err = o.QueryTable(&Department{}).
Filter("company_id", companyId).
Filter("delete_at", 0).
All(&result)
return result, err
}
... ...
... ... @@ -341,18 +341,21 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in
return protocol.NewErrWithMessage("1")
}
for i := range relationId {
//获取部门或人员数据
newRelationId := getDataForRankRnageRelation(companyid, rangetype, relationId)
for i := range newRelationId {
m := models.RankRangeData{
RankRangeId: rankRange.Id,
RangeType: rangetype,
RelationId: relationId[i],
RelationId: newRelationId[i],
RankTypeId: rankTypeId,
}
rankRangeDatas = append(rankRangeDatas, m)
}
if len(rankRangeDatas) > 0 {
//TODO 去除其他分组的重复项
err = deleteRankRangeDataByRelation(rankTypeId, rangetype, relationId, o)
err = deleteRankRangeDataByRelation(rankTypeId, rangetype, newRelationId, o)
if err != nil {
log.Error(err.Error())
o.Rollback()
... ... @@ -369,6 +372,49 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in
return nil
}
func getDataForRankRnageRelation(companyid int64, rangeType int8, relationId []int64) (newRelationId []int64) {
o := orm.NewOrm()
var (
err error
)
switch rangeType {
case models.RANK_RANGE_TYPE_EMPLAYEE:
var (
users []models.UserCompany
)
qs := o.QueryTable(&models.UserCompany{}).
Filter("delete_at", 0).
Filter("company_id", companyid)
if len(relationId) > 0 {
qs = qs.Filter("id__in", relationId)
}
_, err = qs.All(&users, "Id")
if err == nil {
for _, v := range users {
newRelationId = append(newRelationId, v.Id)
}
}
case models.RANK_RANGE_TYPE_DEPARTMENT:
var (
departments []models.Department
)
qs := o.QueryTable(&models.Department{}).
Filter("delete_at", 0).
Filter("company_id", companyid).
Filter("is_top", 0)
if len(relationId) > 0 {
qs = qs.Filter("id__in", relationId)
}
_, err = qs.All(&departments, "Id")
if err == nil {
for _, v := range departments {
newRelationId = append(newRelationId, v.Id)
}
}
}
return newRelationId
}
func EditRankRange(id int64, name string, rangetype int8, relationId []int64, companyid int64) error {
var (
rankRangeDatas []models.RankRangeData
... ... @@ -398,14 +444,15 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co
var (
addRangeData []models.RankRangeData
)
for i := range relationId {
r := models.RankRangeData{
RankRangeId: id,
newRelationId := getDataForRankRnageRelation(companyid, rangetype, relationId)
for i := range newRelationId {
m := models.RankRangeData{
RankRangeId: rankRange.Id,
RangeType: rangetype,
RelationId: relationId[i],
RelationId: newRelationId[i],
RankTypeId: rankRange.RankTypeId,
}
addRangeData = append(addRangeData, r)
addRangeData = append(addRangeData, m)
}
rankRange.Name = name
rankRange.Type = rangetype
... ... @@ -426,9 +473,9 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co
return protocol.NewErrWithMessage("1")
}
}
if len(relationId) > 0 {
if len(newRelationId) > 0 {
//TODO 去除其他分组的重复项
err = deleteRankRangeDataByRelation(rankRange.RankTypeId, rangetype, relationId, o)
err = deleteRankRangeDataByRelation(rankRange.RankTypeId, rangetype, newRelationId, o)
if err != nil {
log.Error(err.Error())
o.Rollback()
... ...