作者 tangxvhui

bug 修复

... ... @@ -145,7 +145,7 @@ func (c RankController) RankSeasonAdd() {
return
}
endTime = t2.Unix() + 86399 //60*60*24-1
if beginTime < endTime {
if beginTime > endTime {
msg = protocol.BadRequestParam("1")
return
}
... ... @@ -202,7 +202,7 @@ func (c RankController) RankSeasonEdit() {
}
endTime = t2.Unix() + 86399 //60*60*24-1
if beginTime < endTime {
if beginTime > endTime {
msg = protocol.BadRequestParam("1")
return
}
... ... @@ -464,8 +464,7 @@ func (c RankController) RankRangeMove() {
}()
type Parameter struct {
FromId int64 `json:"from_id"`
ToId string `json:"name"`
RankTypeId int8 `json:"rank_type_id"`
ToId int64 `json:"to_id"`
RelationId []int64 `json:"relation_id"`
}
var param Parameter
... ... @@ -474,6 +473,8 @@ func (c RankController) RankRangeMove() {
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
err := serverank.RankRangeMove(param.FromId, param.ToId, param.RelationId, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
... ...
... ... @@ -9,6 +9,7 @@ type RankRangeData struct {
RankRangeId int64 `orm:"column(rank_range_id)"`
RangeType int8 `orm:"column(range_type);" description:"类型"`
RelationId int64 `orm:"column(relation_id);"`
RankTypeId int64 `orm:"column(rank_type_id)"`
}
func (t *RankRangeData) TableName() string {
... ...
... ... @@ -108,6 +108,7 @@ var errmessge ErrorMap = map[string]string{
"10091": "至少选择一个特定部门",
//榜单设置
"10101": "赛季周期设置与其他赛季重叠",
"10102": "参与人类型不一致",
}
//错误码转换 ,兼容需要
... ...
... ... @@ -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
}
... ...