作者 tangxvhui

榜单配置调整

#app的名称
appname = ability
#运行模式
runmode =${RUN_MODE||test}
runmode =${RUN_MODE||dev}
#是否自动渲染页面
autorender = false
#是否复制请求body
... ...
... ... @@ -2,10 +2,13 @@ package controllers
import (
"encoding/json"
"fmt"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
serverank "oppmg/services/rank"
"strings"
"time"
)
type RankController struct {
... ... @@ -57,7 +60,7 @@ func (c RankController) RankTypeForbidAllow() {
}()
type Parameter struct {
Id int64 `json:"id"`
status int `json:"status"`
Status int `json:"status"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
... ... @@ -67,11 +70,13 @@ func (c RankController) RankTypeForbidAllow() {
}
var err error
companyid := c.GetCompanyId()
switch param.status {
switch param.Status {
case 1:
err = serverank.ForbidRank(param.Id, companyid)
case 2:
err = serverank.AllowRank(param.Id, companyid)
default:
err = protocol.NewErrWithMessage("1")
}
msg = protocol.NewReturnResponse(nil, err)
return
... ... @@ -116,12 +121,29 @@ func (c RankController) RankSeasonAdd() {
msg = protocol.BadRequestParam("1")
return
}
param.Name = strings.TrimSpace(param.Name)
if len(param.Name) == 0 {
msg = protocol.BadRequestParam("1")
return
}
var (
beginTime int64
endTime int64
)
t1, err := time.ParseInLocation("2006-01-02", param.BeginTime, time.Local)
if err != nil {
msg = protocol.BadRequestParam("1")
return
}
beginTime = t1.Unix()
t2, err := time.ParseInLocation("2006-01-02", param.EndTime, time.Local)
if err != nil {
msg = protocol.BadRequestParam("1")
return
}
endTime = t2.Unix() + 86399 //60*60*24-1
companyid := c.GetCompanyId()
err := serverank.AddRankPeriod(param.RankTypeId, beginTime, endTime, param.Name, companyid)
err = serverank.AddRankPeriod(param.RankTypeId, beginTime, endTime, param.Name, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
... ... @@ -145,12 +167,31 @@ func (c RankController) RankSeasonEdit() {
msg = protocol.BadRequestParam("1")
return
}
param.Name = strings.TrimSpace(param.Name)
if len(param.Name) == 0 {
msg = protocol.BadRequestParam("1")
return
}
var (
beginTime int64
endTime int64
)
t1, err := time.ParseInLocation("2006-01-02", param.BeginTime, time.Local)
if err != nil {
msg = protocol.BadRequestParam("1")
return
}
beginTime = t1.Unix()
t2, err := time.ParseInLocation("2006-01-02", param.EndTime, time.Local)
if err != nil {
msg = protocol.BadRequestParam("1")
return
}
endTime = t2.Unix() + 86399 //60*60*24-1
companyid := c.GetCompanyId()
err := serverank.EditRankPeriod(param.Id, beginTime, endTime, param.Name, companyid)
fmt.Println(beginTime, endTime)
err = serverank.EditRankPeriod(param.Id, beginTime, endTime, param.Name, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
... ... @@ -259,6 +300,37 @@ func (c RankController) RankRangeEdit() {
return
}
//RankRangeForbidAllow ...
//@router /rank/range/forbid_allow
func (c RankController) RankRangeForbidAllow() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
Status int `json:"status"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
var err error
companyid := c.GetCompanyId()
switch param.Status {
case 1:
err = serverank.ForbidRankRange(param.Id, companyid)
case 2:
err = serverank.AllowRankRange(param.Id, companyid)
default:
err = protocol.NewErrWithMessage("1")
}
msg = protocol.NewReturnResponse(nil, err)
return
}
//RankRangeInfo ...
//@router /rank/range/info
func (c RankController) RankRangeInfo() {
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
)
type Achievement struct {
Id int `orm:"column(id);pk" description:"id 主键"`
CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"`
DepartmentId int64 `orm:"column(department_id);null" description:"表department.id 部门id (创建成果指定的部门)"`
UserCompanyId int64 `orm:"column(user_company_id)" description:"把握人 表user_company.id id"`
ChanceTypeId int `orm:"column(chance_type_id);null" description:"表chance_type.id 机会类型 "`
AuditTemplateId int `orm:"column(audit_template_id);null" description:"表audit_template.id 所属审批模板编号"`
SourceContent string `orm:"column(source_content);null" description:"成果详情文本"`
GraspScore float64 `orm:"column(grasp_score);digits(4);decimals(1)" description:"把握分"`
UserGraspScore float64 `orm:"column(user_grasp_score);digits(4);decimals(1)" description:"把握人得分"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
ViewTotal int `orm:"column(view_total);null" description:"查看总数"`
CommentTotal int `orm:"column(comment_total);null" description:"评论总数"`
ZanTotal int `orm:"column(zan_total);null" description:"点赞总数"`
Status int8 `orm:"column(status);null" description:"机会状态 1:开启 2:关闭 0:删除"`
Images string `orm:"column(images);null" description:"图片 json"`
}
func (t *Achievement) TableName() string {
return "achievement"
}
func init() {
orm.RegisterModel(new(Achievement))
}
// AddAchievement insert a new Achievement into database and returns
// last inserted Id on success.
func AddAchievement(m *Achievement) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAchievementById retrieves Achievement by Id. Returns error if
// Id doesn't exist
func GetAchievementById(id int) (v *Achievement, err error) {
o := orm.NewOrm()
v = &Achievement{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// GetAllAchievement retrieves all Achievement matches certain condition. Returns empty list if
// no records exist
func GetAllAchievement(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(Achievement))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []Achievement
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateAchievement updates Achievement by Id and returns error if
// the record to be updated doesn't exist
func UpdateAchievementById(m *Achievement) (err error) {
o := orm.NewOrm()
v := Achievement{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteAchievement deletes Achievement by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAchievement(id int) (err error) {
o := orm.NewOrm()
v := Achievement{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&Achievement{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
)
type AchievementChance struct {
Id int `orm:"column(id);pk"`
AchievementId int64 `orm:"column(achievement_id);null" description:"成果编号 表achievement.id"`
ChanceId int64 `orm:"column(chance_id);null" description:"机会编号 表chance.id"`
ChanceCode string `orm:"column(chance_code);size(255);null" description:"机会编号 表chance.code"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
}
func (t *AchievementChance) TableName() string {
return "achievement_chance"
}
func init() {
orm.RegisterModel(new(AchievementChance))
}
// AddAchievementChance insert a new AchievementChance into database and returns
// last inserted Id on success.
func AddAchievementChance(m *AchievementChance) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAchievementChanceById retrieves AchievementChance by Id. Returns error if
// Id doesn't exist
func GetAchievementChanceById(id int) (v *AchievementChance, err error) {
o := orm.NewOrm()
v = &AchievementChance{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// GetAllAchievementChance retrieves all AchievementChance matches certain condition. Returns empty list if
// no records exist
func GetAllAchievementChance(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(AchievementChance))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []AchievementChance
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateAchievementChance updates AchievementChance by Id and returns error if
// the record to be updated doesn't exist
func UpdateAchievementChanceById(m *AchievementChance) (err error) {
o := orm.NewOrm()
v := AchievementChance{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteAchievementChance deletes AchievementChance by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAchievementChance(id int) (err error) {
o := orm.NewOrm()
v := AchievementChance{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&AchievementChance{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
)
type AchievementProvider struct {
Id int `orm:"column(id);pk" description:"主键id"`
AchievementId int64 `orm:"column(achievement_id);null" description:"表achievement.id"`
UserCompanyId int64 `orm:"column(user_company_id);null" description:"user_company.id"`
UserGraspScore float64 `orm:"column(user_grasp_score);null;digits(4);decimals(1)" description:"把握人得分"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
}
func (t *AchievementProvider) TableName() string {
return "achievement_provider"
}
func init() {
orm.RegisterModel(new(AchievementProvider))
}
// AddAchievementProvider insert a new AchievementProvider into database and returns
// last inserted Id on success.
func AddAchievementProvider(m *AchievementProvider) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAchievementProviderById retrieves AchievementProvider by Id. Returns error if
// Id doesn't exist
func GetAchievementProviderById(id int) (v *AchievementProvider, err error) {
o := orm.NewOrm()
v = &AchievementProvider{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// GetAllAchievementProvider retrieves all AchievementProvider matches certain condition. Returns empty list if
// no records exist
func GetAllAchievementProvider(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(AchievementProvider))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []AchievementProvider
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateAchievementProvider updates AchievementProvider by Id and returns error if
// the record to be updated doesn't exist
func UpdateAchievementProviderById(m *AchievementProvider) (err error) {
o := orm.NewOrm()
v := AchievementProvider{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteAchievementProvider deletes AchievementProvider by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAchievementProvider(id int) (err error) {
o := orm.NewOrm()
v := AchievementProvider{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&AchievementProvider{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
... ... @@ -29,6 +29,11 @@ func init() {
// AddRankItem insert a new NewRankItem into database and returns
// last inserted Id on success.
func AddRankItem(m []RankItem, om orm.Ormer) (successSum int64, err error) {
nowTime := time.Now()
for i := range m {
m[i].CreateAt = nowTime
m[i].UpdateAt = nowTime
}
successSum, err = om.InsertMulti(10, &m)
return
}
... ... @@ -52,7 +57,7 @@ func GetRankItemByCompanyid(companyid int64, rankTypeId int64) ([]RankItem, erro
o := orm.NewOrm()
_, err = o.QueryTable(&RankItem{}).
Filter("company_id", companyid).
Filter("rank_yype_id", rankTypeId).
Filter("rank_type_id", rankTypeId).
All(&data)
if err == orm.ErrNoRows {
return data, nil
... ... @@ -74,7 +79,7 @@ func UpdateRankItemById(m *RankItem, cols []string, om orm.Ormer) (err error) {
m.UpdateAt = time.Now()
var num int64
if num, err = om.Update(m, cols...); err == nil {
log.Info("Number of records updated in database:", num)
log.Info("Number of records updated in database:%d", num)
}
return
}
... ...
package models
import (
"fmt"
"oppmg/common/log"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -40,6 +40,8 @@ const (
// last inserted Id on success.
func AddRankPeriod(m *RankPeriod) (id int64, err error) {
o := orm.NewOrm()
m.CreateAt = time.Now()
m.UpdateAt = time.Now()
id, err = o.Insert(m)
return
}
... ... @@ -57,15 +59,16 @@ func GetRankPeriodById(id int64) (v *RankPeriod, err error) {
// UpdateNewRankPeriod updates RankPeriod by Id and returns error if
// the record to be updated doesn't exist
func UpdateRankPeriodById(m *RankPeriod) (err error) {
func UpdateRankPeriodById(m *RankPeriod, cols []string) (err error) {
o := orm.NewOrm()
v := RankPeriod{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
m.UpdateAt = time.Now()
if len(cols) > 0 {
cols = append(cols, "UpdateAt")
}
var num int64
if num, err = o.Update(m, cols...); err == nil {
log.Info("Number of records updated in database:", num)
}
return
}
... ...
... ... @@ -18,6 +18,7 @@ type RankRange struct {
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
SortNum int `orm:"column(sort_num)"`
Status int8 `orm:"column(status)"`
}
func (t *RankRange) TableName() string {
... ...
... ... @@ -13,7 +13,7 @@ type RankType struct {
Name string `orm:"column(name)"`
EnableStatus int8 `orm:"column(enable_status)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdataAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
Type int8 `orm:"column(type)"`
}
... ... @@ -43,7 +43,7 @@ func AddRank(m *RankType) (id int64, err error) {
o := orm.NewOrm()
nowTime := time.Now()
m.CreateAt = nowTime
m.UpdataAt = nowTime
m.UpdateAt = nowTime
id, err = o.Insert(m)
return
}
... ... @@ -68,7 +68,7 @@ func UpdateRankById(m *RankType, cols []string, om ...orm.Ormer) (err error) {
} else {
o = orm.NewOrm()
}
m.UpdataAt = time.Now()
m.UpdateAt = time.Now()
if len(cols) > 0 {
cols = append(cols, "UpdateAt")
}
... ...
... ... @@ -4,8 +4,8 @@ package protocol
type ResponseRankType struct {
Id int `json:"id" orm:"column(id)"`
Name string `json:"name" orm:"column(name)"`
Status int8 `json:"status" orm:"column(status)"`
RankType int8 `json:"rank_type" orm:"column(rank_type)"`
EnableStatus int8 `json:"enable_status" orm:"column(enable_status)"`
Type int8 `json:"type" orm:"column(type)"`
}
// ResponseRankSeasonList 赛季列表
... ... @@ -15,7 +15,7 @@ type ResponseRankSeasonList struct {
}
type RankSeasonItem struct {
Id int64 `json:"id" orm:"column(id)"`
SeasonName string `json:"season_name" orm:"column(season_name)"`
Name string `json:"name" orm:"column(name)"`
BeginTime string `json:"begin_time" orm:"column(begin_time)"`
EndTime string `json:"end_time" orm:"column(end_time)"`
Status int8 `json:"status" orm:"column(status)"`
... ...
... ... @@ -104,15 +104,16 @@ func init() {
beego.NSRouter("/allow_forbid", &controllers.AuditController{}, "post:AllowForbidAudit"),
),
beego.NSNamespace("/rank",
beego.NSRouter("/list", &controllers.RankController{}, "post:GetRankType"),
beego.NSRouter("/edit", &controllers.RankController{}, "post:EditRankType"),
beego.NSRouter("/forbid_allow", &controllers.RankController{}, "post:RankTypeForbidAllow"),
beego.NSRouter("/type/list", &controllers.RankController{}, "post:GetRankType"),
beego.NSRouter("/type/edit", &controllers.RankController{}, "post:EditRankType"),
beego.NSRouter("/type/forbid_allow", &controllers.RankController{}, "post:RankTypeForbidAllow"),
beego.NSRouter("/season/add", &controllers.RankController{}, "post:RankSeasonAdd"),
beego.NSRouter("/season/list", &controllers.RankController{}, "post:RankSeasonList"),
beego.NSRouter("/season/edit", &controllers.RankController{}, "post:RankSeasonEdit"),
beego.NSRouter("/range/list", &controllers.RankController{}, "post:RankRangeList"),
beego.NSRouter("/range/edit", &controllers.RankController{}, "post:RankRangeEdit"),
beego.NSRouter("/range/add", &controllers.RankController{}, "post:RankRangeAdd"),
beego.NSRouter("/range/forbid_allow", &controllers.RankController{}, "post:RankRangeForbidAllow"),
beego.NSRouter("/range/info", &controllers.RankController{}, "post:RankRangeInfo"),
beego.NSRouter("/range/sort", &controllers.RankController{}, "post:RankRangeSort"),
beego.NSRouter("/item/list", &controllers.RankController{}, "post:RankItemList"),
... ...
... ... @@ -18,7 +18,7 @@ func GetRankList(companyid int64) []protocol.ResponseRankType {
rspData = make([]protocol.ResponseRankType, 0)
err error
)
sqlString := `SELECT id,name,status,rank_type FROM rank WHERE company_id=?`
sqlString := `SELECT id,name,enable_status,type FROM rank_type WHERE company_id=?`
err = utils.ExecuteQueryAll(&rspData, sqlString, companyid)
if err != nil {
log.Error("获取榜单列表失败,err%s", err)
... ... @@ -148,7 +148,7 @@ func RankSeasonList(pageindex int, pagesize int, companyid int64) (protocol.Resp
var (
err error
listdata []protocol.RankSeasonItem
cnt int64
cnt int
)
rspData := protocol.ResponseRankSeasonList{
ResponsePageInfo: protocol.ResponsePageInfo{
... ... @@ -173,6 +173,8 @@ func RankSeasonList(pageindex int, pagesize int, companyid int64) (protocol.Resp
log.Error("EXCUTE SQL ERR:%s", err)
return rspData, nil
}
rspData.TotalPage = cnt
rspData.List = listdata
return rspData, err
}
... ... @@ -184,8 +186,8 @@ func AddRankPeriod(rankTypeId int64, beginTime int64, endTime int64, name string
CompanyId: companyid,
SeasonName: name,
RankTypeId: rankTypeId,
BeginTime: time.Unix(beginTime, 0),
EndTime: time.Unix(endTime, 0),
BeginTime: time.Unix(beginTime, 0).Local(),
EndTime: time.Unix(endTime, 0).Local(),
Status: 0,
}
_, err = models.AddRankPeriod(m)
... ... @@ -212,7 +214,7 @@ func EditRankPeriod(id int64, beginTime int64, endTime int64, name string, compa
m.SeasonName = name
m.BeginTime = time.Unix(beginTime, 0)
m.EndTime = time.Unix(endTime, 0)
err = models.UpdateRankPeriodById(m)
err = models.UpdateRankPeriodById(m, []string{"SeasonName", "BeginTime", "EndTime"})
if err != nil {
log.Error("更新赛季失败;%s", err)
}
... ... @@ -226,7 +228,7 @@ func GetRankRangeList(companyid int64) []protocol.RankRangeItem {
rspData = make([]protocol.RankRangeItem, 0)
)
datasql := `SELECT a.id ,a.name,a.type FROM rank_range AS a WHERE company_id=?`
err = utils.ExecuteQueryAll(rspData, datasql, companyid)
err = utils.ExecuteQueryAll(&rspData, datasql, companyid)
if err != nil {
log.Error("获取参与人列表失败:%s", err)
}
... ... @@ -497,6 +499,7 @@ func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error
RankTypeId: rankTypeid,
ItemName: AllRankItem[ii].ItemName,
SortNum: i,
ItemKey: itemKey[i],
}
newItems = append(newItems, m)
break
... ... @@ -526,7 +529,7 @@ func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error
for i := range newItems {
var has bool = false
for ii := range rankitemData {
if rankitemData[i].ItemKey == newItems[ii].ItemKey {
if rankitemData[ii].ItemKey == newItems[i].ItemKey {
has = true
break
}
... ... @@ -538,15 +541,17 @@ func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error
o := orm.NewOrm()
o.Begin()
//添加
if len(addItems) > 0 {
_, err = models.AddRankItem(addItems, o)
if err != nil {
o.Rollback()
log.Error("添加rank_item记录失败:%s", err)
return protocol.NewErrWithMessage("1")
}
}
//更新
for i := range updateItems {
err = models.UpdateRankItemById(&updateItems[i], []string{"SortNum"}, o)
err = models.UpdateRankItemById(&updateItems[i], []string{"SortNum", "ItemName", "ItemKey"}, o)
if err != nil {
o.Rollback()
log.Error("更新rank_item记录失败:%s", err)
... ... @@ -554,12 +559,51 @@ func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error
}
}
//删除
if len(delItemIds) > 0 {
err = models.DeleteRanKItemByIds(delItemIds, o)
if err != nil {
o.Rollback()
log.Error("删除rank_item记录失败:%s", err)
return protocol.NewErrWithMessage("1")
}
}
o.Commit()
return nil
}
func ForbidRankRange(id int64, companyid int64) error {
var (
err error
rankRange *models.RankRange
)
rankRange, err = models.GetRankRangeById(id)
if err != nil {
log.Error("获取rank_range数据失败:%s", err)
return protocol.NewErrWithMessage("1")
}
rankRange.Status = 1
err = models.UpdateRankRangeById(rankRange, []string{"Status"})
if err != nil {
log.Error("更新rank_range数据失败:%s", err)
}
return nil
}
func AllowRankRange(id int64, companyid int64) error {
var (
err error
rankRange *models.RankRange
)
rankRange, err = models.GetRankRangeById(id)
if err != nil {
log.Error("获取rank_range数据失败:%s", err)
return protocol.NewErrWithMessage("1")
}
rankRange.Status = 0
err = models.UpdateRankRangeById(rankRange, []string{"Status"})
if err != nil {
log.Error("更新rank_range数据失败:%s", err)
}
return nil
}
... ...