作者 yangfu

榜单编辑修改

... ... @@ -383,7 +383,7 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in
log.Error("添加rank_range_data记录失败;%s", err)
return protocol.NewErrWithMessage("1")
}
if err = removeAllRanks(o, companyid, rankTypeId, newRelationId); err != nil {
if err = removeAllRanks(o, companyid, rankTypeId, 0, newRelationId); err != nil {
log.Error("更新rank数据失败:%s", err)
o.Rollback()
return protocol.NewErrWithMessage("1")
... ... @@ -513,19 +513,21 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co
return protocol.NewErrWithMessage("1")
}
}
if err = removeRanksNotIn(o, companyid, rankRange.RankTypeId, rankRange.Id, relationId); err != nil {
log.Error("更新rank数据失败:%s", err)
o.Rollback()
return protocol.NewErrWithMessage("1")
if len(relationId) == 0 {
//移除当前范围所有榜单数据
if err = removeAllRanks(o, companyid, rankRange.RankTypeId, rankRange.Id, []int64{}); err != nil {
log.Error("更新rank数据失败:%s", err)
o.Rollback()
return protocol.NewErrWithMessage("1")
}
} else {
//移除不在当前范围的榜单数据
if err = removeRanksOutRange(o, companyid, rankRange.RankTypeId, rankRange.Id, relationId); err != nil {
log.Error("更新rank数据失败:%s", err)
o.Rollback()
return protocol.NewErrWithMessage("1")
}
}
//if len(relationId)>0{
// if err = updateRanks(o, companyid, rankRange.RankTypeId, rankRange.Id, relationId,1); err != nil {
// log.Error("更新rank数据失败:%s", err)
// o.Rollback()
// return protocol.NewErrWithMessage("1")
// }
//}
o.Commit()
return nil
}
... ... @@ -937,20 +939,22 @@ where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
}
return
}
func removeRanksNotIn(o orm.Ormer, companyId, rankTypeId, rankRangeId int64, relationIds []int64) (err error) {
//移除参与范围外 其他参与范围的已统计版本记录
//@rankRangeId 当前参与范围编号
func removeRanksOutRange(o orm.Ormer, companyId, rankTypeId, rankRangeId int64, relationIds []int64) (err error) {
var sqlRemoveRanks = fmt.Sprintf(`
update rank set enable_status=0,update_at=NOW()
where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
where company_id=%v and rank_type_id=%v and rank_range_id<>%v and enable_status=1 and rank_period_id in
(
select id from rank_period where company_id=? and rank_type_id=? and status=1
select id from rank_period where company_id=%v and rank_type_id=%v and status=1
)
`)
`, companyId, rankTypeId, rankRangeId,
companyId, rankTypeId)
if len(relationIds) > 0 {
sqlRemoveRanks += fmt.Sprintf(" and relation_id not in (%v)", utils.JoinInt64s(relationIds, ","))
sqlRemoveRanks += fmt.Sprintf(" and relation_id in (%v)", utils.JoinInt64s(relationIds, ","))
}
if _, err = o.Raw(sqlRemoveRanks, companyId, rankTypeId, rankRangeId,
companyId, rankTypeId,
).Exec(); err != nil {
if err = utils.ExecuteSQLWithOrmer(o, sqlRemoveRanks); err != nil {
return
}
return
... ... @@ -958,21 +962,21 @@ where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
//移除已存在的榜单记录(榜单周期内)
//同时只会存在在一个排行榜单里面
func removeAllRanks(o orm.Ormer, companyId, rankTypeId int64, relationIds []int64) (err error) {
if len(relationIds) == 0 {
return nil
}
func removeAllRanks(o orm.Ormer, companyId, rankTypeId int64, rankRangeId int64, relationIds []int64) (err error) {
var sqlRemoveRanks = fmt.Sprintf(`
update rank set enable_status=0,update_at=NOW()
where company_id=? and rank_type_id=? and enable_status =1 and rank_period_id in
where company_id=%v and rank_type_id=%v and enable_status =1 and rank_period_id in
(
select id from rank_period where company_id=? and rank_type_id=? and status=1
select id from rank_period where company_id=%v and rank_type_id=%v and status=1
)
`)
`, companyId, rankTypeId, companyId, rankTypeId)
if len(relationIds) > 0 {
sqlRemoveRanks += fmt.Sprintf(" and relation_id in (%v)", utils.JoinInt64s(relationIds, ","))
}
if err = utils.ExecuteSQLWithOrmer(o, sqlRemoveRanks, companyId, rankTypeId, companyId, rankTypeId); err != nil {
if rankRangeId > 0 {
sqlRemoveRanks += fmt.Sprintf(" and rank_range_id =%v", rankRangeId)
}
if err = utils.ExecuteSQLWithOrmer(o, sqlRemoveRanks); err != nil {
return
}
return
... ...