作者 tangxvhui

榜单配置调整

1 #app的名称 1 #app的名称
2 appname = ability 2 appname = ability
3 #运行模式 3 #运行模式
4 -runmode =${RUN_MODE||test} 4 +runmode =${RUN_MODE||dev}
5 #是否自动渲染页面 5 #是否自动渲染页面
6 autorender = false 6 autorender = false
7 #是否复制请求body 7 #是否复制请求body
@@ -2,10 +2,13 @@ package controllers @@ -2,10 +2,13 @@ package controllers
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
  5 + "fmt"
5 "oppmg/common/log" 6 "oppmg/common/log"
6 "oppmg/models" 7 "oppmg/models"
7 "oppmg/protocol" 8 "oppmg/protocol"
8 serverank "oppmg/services/rank" 9 serverank "oppmg/services/rank"
  10 + "strings"
  11 + "time"
9 ) 12 )
10 13
11 type RankController struct { 14 type RankController struct {
@@ -57,7 +60,7 @@ func (c RankController) RankTypeForbidAllow() { @@ -57,7 +60,7 @@ func (c RankController) RankTypeForbidAllow() {
57 }() 60 }()
58 type Parameter struct { 61 type Parameter struct {
59 Id int64 `json:"id"` 62 Id int64 `json:"id"`
60 - status int `json:"status"` 63 + Status int `json:"status"`
61 } 64 }
62 var param Parameter 65 var param Parameter
63 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil { 66 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
@@ -67,11 +70,13 @@ func (c RankController) RankTypeForbidAllow() { @@ -67,11 +70,13 @@ func (c RankController) RankTypeForbidAllow() {
67 } 70 }
68 var err error 71 var err error
69 companyid := c.GetCompanyId() 72 companyid := c.GetCompanyId()
70 - switch param.status { 73 + switch param.Status {
71 case 1: 74 case 1:
72 err = serverank.ForbidRank(param.Id, companyid) 75 err = serverank.ForbidRank(param.Id, companyid)
73 case 2: 76 case 2:
74 err = serverank.AllowRank(param.Id, companyid) 77 err = serverank.AllowRank(param.Id, companyid)
  78 + default:
  79 + err = protocol.NewErrWithMessage("1")
75 } 80 }
76 msg = protocol.NewReturnResponse(nil, err) 81 msg = protocol.NewReturnResponse(nil, err)
77 return 82 return
@@ -116,12 +121,29 @@ func (c RankController) RankSeasonAdd() { @@ -116,12 +121,29 @@ func (c RankController) RankSeasonAdd() {
116 msg = protocol.BadRequestParam("1") 121 msg = protocol.BadRequestParam("1")
117 return 122 return
118 } 123 }
  124 + param.Name = strings.TrimSpace(param.Name)
  125 + if len(param.Name) == 0 {
  126 + msg = protocol.BadRequestParam("1")
  127 + return
  128 + }
119 var ( 129 var (
120 beginTime int64 130 beginTime int64
121 endTime int64 131 endTime int64
122 ) 132 )
  133 + t1, err := time.ParseInLocation("2006-01-02", param.BeginTime, time.Local)
  134 + if err != nil {
  135 + msg = protocol.BadRequestParam("1")
  136 + return
  137 + }
  138 + beginTime = t1.Unix()
  139 + t2, err := time.ParseInLocation("2006-01-02", param.EndTime, time.Local)
  140 + if err != nil {
  141 + msg = protocol.BadRequestParam("1")
  142 + return
  143 + }
  144 + endTime = t2.Unix() + 86399 //60*60*24-1
123 companyid := c.GetCompanyId() 145 companyid := c.GetCompanyId()
124 - err := serverank.AddRankPeriod(param.RankTypeId, beginTime, endTime, param.Name, companyid) 146 + err = serverank.AddRankPeriod(param.RankTypeId, beginTime, endTime, param.Name, companyid)
125 msg = protocol.NewReturnResponse(nil, err) 147 msg = protocol.NewReturnResponse(nil, err)
126 return 148 return
127 } 149 }
@@ -145,12 +167,31 @@ func (c RankController) RankSeasonEdit() { @@ -145,12 +167,31 @@ func (c RankController) RankSeasonEdit() {
145 msg = protocol.BadRequestParam("1") 167 msg = protocol.BadRequestParam("1")
146 return 168 return
147 } 169 }
  170 + param.Name = strings.TrimSpace(param.Name)
  171 + if len(param.Name) == 0 {
  172 + msg = protocol.BadRequestParam("1")
  173 + return
  174 + }
148 var ( 175 var (
149 beginTime int64 176 beginTime int64
150 endTime int64 177 endTime int64
151 ) 178 )
  179 + t1, err := time.ParseInLocation("2006-01-02", param.BeginTime, time.Local)
  180 + if err != nil {
  181 + msg = protocol.BadRequestParam("1")
  182 + return
  183 + }
  184 + beginTime = t1.Unix()
  185 + t2, err := time.ParseInLocation("2006-01-02", param.EndTime, time.Local)
  186 + if err != nil {
  187 + msg = protocol.BadRequestParam("1")
  188 + return
  189 + }
  190 +
  191 + endTime = t2.Unix() + 86399 //60*60*24-1
152 companyid := c.GetCompanyId() 192 companyid := c.GetCompanyId()
153 - err := serverank.EditRankPeriod(param.Id, beginTime, endTime, param.Name, companyid) 193 + fmt.Println(beginTime, endTime)
  194 + err = serverank.EditRankPeriod(param.Id, beginTime, endTime, param.Name, companyid)
154 msg = protocol.NewReturnResponse(nil, err) 195 msg = protocol.NewReturnResponse(nil, err)
155 return 196 return
156 } 197 }
@@ -259,6 +300,37 @@ func (c RankController) RankRangeEdit() { @@ -259,6 +300,37 @@ func (c RankController) RankRangeEdit() {
259 return 300 return
260 } 301 }
261 302
  303 +//RankRangeForbidAllow ...
  304 +//@router /rank/range/forbid_allow
  305 +func (c RankController) RankRangeForbidAllow() {
  306 + var msg *protocol.ResponseMessage
  307 + defer func() {
  308 + c.ResposeJson(msg)
  309 + }()
  310 + type Parameter struct {
  311 + Id int64 `json:"id"`
  312 + Status int `json:"status"`
  313 + }
  314 + var param Parameter
  315 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  316 + log.Error("json 解析失败 err:%s", err)
  317 + msg = protocol.BadRequestParam("1")
  318 + return
  319 + }
  320 + var err error
  321 + companyid := c.GetCompanyId()
  322 + switch param.Status {
  323 + case 1:
  324 + err = serverank.ForbidRankRange(param.Id, companyid)
  325 + case 2:
  326 + err = serverank.AllowRankRange(param.Id, companyid)
  327 + default:
  328 + err = protocol.NewErrWithMessage("1")
  329 + }
  330 + msg = protocol.NewReturnResponse(nil, err)
  331 + return
  332 +}
  333 +
262 //RankRangeInfo ... 334 //RankRangeInfo ...
263 //@router /rank/range/info 335 //@router /rank/range/info
264 func (c RankController) RankRangeInfo() { 336 func (c RankController) RankRangeInfo() {
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type Achievement struct {
  14 + Id int `orm:"column(id);pk" description:"id 主键"`
  15 + CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"`
  16 + DepartmentId int64 `orm:"column(department_id);null" description:"表department.id 部门id (创建成果指定的部门)"`
  17 + UserCompanyId int64 `orm:"column(user_company_id)" description:"把握人 表user_company.id id"`
  18 + ChanceTypeId int `orm:"column(chance_type_id);null" description:"表chance_type.id 机会类型 "`
  19 + AuditTemplateId int `orm:"column(audit_template_id);null" description:"表audit_template.id 所属审批模板编号"`
  20 + SourceContent string `orm:"column(source_content);null" description:"成果详情文本"`
  21 + GraspScore float64 `orm:"column(grasp_score);digits(4);decimals(1)" description:"把握分"`
  22 + UserGraspScore float64 `orm:"column(user_grasp_score);digits(4);decimals(1)" description:"把握人得分"`
  23 + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
  24 + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
  25 + ViewTotal int `orm:"column(view_total);null" description:"查看总数"`
  26 + CommentTotal int `orm:"column(comment_total);null" description:"评论总数"`
  27 + ZanTotal int `orm:"column(zan_total);null" description:"点赞总数"`
  28 + Status int8 `orm:"column(status);null" description:"机会状态 1:开启 2:关闭 0:删除"`
  29 + Images string `orm:"column(images);null" description:"图片 json"`
  30 +}
  31 +
  32 +func (t *Achievement) TableName() string {
  33 + return "achievement"
  34 +}
  35 +
  36 +func init() {
  37 + orm.RegisterModel(new(Achievement))
  38 +}
  39 +
  40 +// AddAchievement insert a new Achievement into database and returns
  41 +// last inserted Id on success.
  42 +func AddAchievement(m *Achievement) (id int64, err error) {
  43 + o := orm.NewOrm()
  44 + id, err = o.Insert(m)
  45 + return
  46 +}
  47 +
  48 +// GetAchievementById retrieves Achievement by Id. Returns error if
  49 +// Id doesn't exist
  50 +func GetAchievementById(id int) (v *Achievement, err error) {
  51 + o := orm.NewOrm()
  52 + v = &Achievement{Id: id}
  53 + if err = o.Read(v); err == nil {
  54 + return v, nil
  55 + }
  56 + return nil, err
  57 +}
  58 +
  59 +// GetAllAchievement retrieves all Achievement matches certain condition. Returns empty list if
  60 +// no records exist
  61 +func GetAllAchievement(query map[string]string, fields []string, sortby []string, order []string,
  62 + offset int64, limit int64) (ml []interface{}, err error) {
  63 + o := orm.NewOrm()
  64 + qs := o.QueryTable(new(Achievement))
  65 + // query k=v
  66 + for k, v := range query {
  67 + // rewrite dot-notation to Object__Attribute
  68 + k = strings.Replace(k, ".", "__", -1)
  69 + if strings.Contains(k, "isnull") {
  70 + qs = qs.Filter(k, (v == "true" || v == "1"))
  71 + } else {
  72 + qs = qs.Filter(k, v)
  73 + }
  74 + }
  75 + // order by:
  76 + var sortFields []string
  77 + if len(sortby) != 0 {
  78 + if len(sortby) == len(order) {
  79 + // 1) for each sort field, there is an associated order
  80 + for i, v := range sortby {
  81 + orderby := ""
  82 + if order[i] == "desc" {
  83 + orderby = "-" + v
  84 + } else if order[i] == "asc" {
  85 + orderby = v
  86 + } else {
  87 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  88 + }
  89 + sortFields = append(sortFields, orderby)
  90 + }
  91 + qs = qs.OrderBy(sortFields...)
  92 + } else if len(sortby) != len(order) && len(order) == 1 {
  93 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  94 + for _, v := range sortby {
  95 + orderby := ""
  96 + if order[0] == "desc" {
  97 + orderby = "-" + v
  98 + } else if order[0] == "asc" {
  99 + orderby = v
  100 + } else {
  101 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  102 + }
  103 + sortFields = append(sortFields, orderby)
  104 + }
  105 + } else if len(sortby) != len(order) && len(order) != 1 {
  106 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  107 + }
  108 + } else {
  109 + if len(order) != 0 {
  110 + return nil, errors.New("Error: unused 'order' fields")
  111 + }
  112 + }
  113 +
  114 + var l []Achievement
  115 + qs = qs.OrderBy(sortFields...)
  116 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  117 + if len(fields) == 0 {
  118 + for _, v := range l {
  119 + ml = append(ml, v)
  120 + }
  121 + } else {
  122 + // trim unused fields
  123 + for _, v := range l {
  124 + m := make(map[string]interface{})
  125 + val := reflect.ValueOf(v)
  126 + for _, fname := range fields {
  127 + m[fname] = val.FieldByName(fname).Interface()
  128 + }
  129 + ml = append(ml, m)
  130 + }
  131 + }
  132 + return ml, nil
  133 + }
  134 + return nil, err
  135 +}
  136 +
  137 +// UpdateAchievement updates Achievement by Id and returns error if
  138 +// the record to be updated doesn't exist
  139 +func UpdateAchievementById(m *Achievement) (err error) {
  140 + o := orm.NewOrm()
  141 + v := Achievement{Id: m.Id}
  142 + // ascertain id exists in the database
  143 + if err = o.Read(&v); err == nil {
  144 + var num int64
  145 + if num, err = o.Update(m); err == nil {
  146 + fmt.Println("Number of records updated in database:", num)
  147 + }
  148 + }
  149 + return
  150 +}
  151 +
  152 +// DeleteAchievement deletes Achievement by Id and returns error if
  153 +// the record to be deleted doesn't exist
  154 +func DeleteAchievement(id int) (err error) {
  155 + o := orm.NewOrm()
  156 + v := Achievement{Id: id}
  157 + // ascertain id exists in the database
  158 + if err = o.Read(&v); err == nil {
  159 + var num int64
  160 + if num, err = o.Delete(&Achievement{Id: id}); err == nil {
  161 + fmt.Println("Number of records deleted in database:", num)
  162 + }
  163 + }
  164 + return
  165 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type AchievementChance struct {
  14 + Id int `orm:"column(id);pk"`
  15 + AchievementId int64 `orm:"column(achievement_id);null" description:"成果编号 表achievement.id"`
  16 + ChanceId int64 `orm:"column(chance_id);null" description:"机会编号 表chance.id"`
  17 + ChanceCode string `orm:"column(chance_code);size(255);null" description:"机会编号 表chance.code"`
  18 + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
  19 +}
  20 +
  21 +func (t *AchievementChance) TableName() string {
  22 + return "achievement_chance"
  23 +}
  24 +
  25 +func init() {
  26 + orm.RegisterModel(new(AchievementChance))
  27 +}
  28 +
  29 +// AddAchievementChance insert a new AchievementChance into database and returns
  30 +// last inserted Id on success.
  31 +func AddAchievementChance(m *AchievementChance) (id int64, err error) {
  32 + o := orm.NewOrm()
  33 + id, err = o.Insert(m)
  34 + return
  35 +}
  36 +
  37 +// GetAchievementChanceById retrieves AchievementChance by Id. Returns error if
  38 +// Id doesn't exist
  39 +func GetAchievementChanceById(id int) (v *AchievementChance, err error) {
  40 + o := orm.NewOrm()
  41 + v = &AchievementChance{Id: id}
  42 + if err = o.Read(v); err == nil {
  43 + return v, nil
  44 + }
  45 + return nil, err
  46 +}
  47 +
  48 +// GetAllAchievementChance retrieves all AchievementChance matches certain condition. Returns empty list if
  49 +// no records exist
  50 +func GetAllAchievementChance(query map[string]string, fields []string, sortby []string, order []string,
  51 + offset int64, limit int64) (ml []interface{}, err error) {
  52 + o := orm.NewOrm()
  53 + qs := o.QueryTable(new(AchievementChance))
  54 + // query k=v
  55 + for k, v := range query {
  56 + // rewrite dot-notation to Object__Attribute
  57 + k = strings.Replace(k, ".", "__", -1)
  58 + if strings.Contains(k, "isnull") {
  59 + qs = qs.Filter(k, (v == "true" || v == "1"))
  60 + } else {
  61 + qs = qs.Filter(k, v)
  62 + }
  63 + }
  64 + // order by:
  65 + var sortFields []string
  66 + if len(sortby) != 0 {
  67 + if len(sortby) == len(order) {
  68 + // 1) for each sort field, there is an associated order
  69 + for i, v := range sortby {
  70 + orderby := ""
  71 + if order[i] == "desc" {
  72 + orderby = "-" + v
  73 + } else if order[i] == "asc" {
  74 + orderby = v
  75 + } else {
  76 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  77 + }
  78 + sortFields = append(sortFields, orderby)
  79 + }
  80 + qs = qs.OrderBy(sortFields...)
  81 + } else if len(sortby) != len(order) && len(order) == 1 {
  82 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  83 + for _, v := range sortby {
  84 + orderby := ""
  85 + if order[0] == "desc" {
  86 + orderby = "-" + v
  87 + } else if order[0] == "asc" {
  88 + orderby = v
  89 + } else {
  90 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  91 + }
  92 + sortFields = append(sortFields, orderby)
  93 + }
  94 + } else if len(sortby) != len(order) && len(order) != 1 {
  95 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  96 + }
  97 + } else {
  98 + if len(order) != 0 {
  99 + return nil, errors.New("Error: unused 'order' fields")
  100 + }
  101 + }
  102 +
  103 + var l []AchievementChance
  104 + qs = qs.OrderBy(sortFields...)
  105 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  106 + if len(fields) == 0 {
  107 + for _, v := range l {
  108 + ml = append(ml, v)
  109 + }
  110 + } else {
  111 + // trim unused fields
  112 + for _, v := range l {
  113 + m := make(map[string]interface{})
  114 + val := reflect.ValueOf(v)
  115 + for _, fname := range fields {
  116 + m[fname] = val.FieldByName(fname).Interface()
  117 + }
  118 + ml = append(ml, m)
  119 + }
  120 + }
  121 + return ml, nil
  122 + }
  123 + return nil, err
  124 +}
  125 +
  126 +// UpdateAchievementChance updates AchievementChance by Id and returns error if
  127 +// the record to be updated doesn't exist
  128 +func UpdateAchievementChanceById(m *AchievementChance) (err error) {
  129 + o := orm.NewOrm()
  130 + v := AchievementChance{Id: m.Id}
  131 + // ascertain id exists in the database
  132 + if err = o.Read(&v); err == nil {
  133 + var num int64
  134 + if num, err = o.Update(m); err == nil {
  135 + fmt.Println("Number of records updated in database:", num)
  136 + }
  137 + }
  138 + return
  139 +}
  140 +
  141 +// DeleteAchievementChance deletes AchievementChance by Id and returns error if
  142 +// the record to be deleted doesn't exist
  143 +func DeleteAchievementChance(id int) (err error) {
  144 + o := orm.NewOrm()
  145 + v := AchievementChance{Id: id}
  146 + // ascertain id exists in the database
  147 + if err = o.Read(&v); err == nil {
  148 + var num int64
  149 + if num, err = o.Delete(&AchievementChance{Id: id}); err == nil {
  150 + fmt.Println("Number of records deleted in database:", num)
  151 + }
  152 + }
  153 + return
  154 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type AchievementProvider struct {
  14 + Id int `orm:"column(id);pk" description:"主键id"`
  15 + AchievementId int64 `orm:"column(achievement_id);null" description:"表achievement.id"`
  16 + UserCompanyId int64 `orm:"column(user_company_id);null" description:"user_company.id"`
  17 + UserGraspScore float64 `orm:"column(user_grasp_score);null;digits(4);decimals(1)" description:"把握人得分"`
  18 + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
  19 +}
  20 +
  21 +func (t *AchievementProvider) TableName() string {
  22 + return "achievement_provider"
  23 +}
  24 +
  25 +func init() {
  26 + orm.RegisterModel(new(AchievementProvider))
  27 +}
  28 +
  29 +// AddAchievementProvider insert a new AchievementProvider into database and returns
  30 +// last inserted Id on success.
  31 +func AddAchievementProvider(m *AchievementProvider) (id int64, err error) {
  32 + o := orm.NewOrm()
  33 + id, err = o.Insert(m)
  34 + return
  35 +}
  36 +
  37 +// GetAchievementProviderById retrieves AchievementProvider by Id. Returns error if
  38 +// Id doesn't exist
  39 +func GetAchievementProviderById(id int) (v *AchievementProvider, err error) {
  40 + o := orm.NewOrm()
  41 + v = &AchievementProvider{Id: id}
  42 + if err = o.Read(v); err == nil {
  43 + return v, nil
  44 + }
  45 + return nil, err
  46 +}
  47 +
  48 +// GetAllAchievementProvider retrieves all AchievementProvider matches certain condition. Returns empty list if
  49 +// no records exist
  50 +func GetAllAchievementProvider(query map[string]string, fields []string, sortby []string, order []string,
  51 + offset int64, limit int64) (ml []interface{}, err error) {
  52 + o := orm.NewOrm()
  53 + qs := o.QueryTable(new(AchievementProvider))
  54 + // query k=v
  55 + for k, v := range query {
  56 + // rewrite dot-notation to Object__Attribute
  57 + k = strings.Replace(k, ".", "__", -1)
  58 + if strings.Contains(k, "isnull") {
  59 + qs = qs.Filter(k, (v == "true" || v == "1"))
  60 + } else {
  61 + qs = qs.Filter(k, v)
  62 + }
  63 + }
  64 + // order by:
  65 + var sortFields []string
  66 + if len(sortby) != 0 {
  67 + if len(sortby) == len(order) {
  68 + // 1) for each sort field, there is an associated order
  69 + for i, v := range sortby {
  70 + orderby := ""
  71 + if order[i] == "desc" {
  72 + orderby = "-" + v
  73 + } else if order[i] == "asc" {
  74 + orderby = v
  75 + } else {
  76 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  77 + }
  78 + sortFields = append(sortFields, orderby)
  79 + }
  80 + qs = qs.OrderBy(sortFields...)
  81 + } else if len(sortby) != len(order) && len(order) == 1 {
  82 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  83 + for _, v := range sortby {
  84 + orderby := ""
  85 + if order[0] == "desc" {
  86 + orderby = "-" + v
  87 + } else if order[0] == "asc" {
  88 + orderby = v
  89 + } else {
  90 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  91 + }
  92 + sortFields = append(sortFields, orderby)
  93 + }
  94 + } else if len(sortby) != len(order) && len(order) != 1 {
  95 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  96 + }
  97 + } else {
  98 + if len(order) != 0 {
  99 + return nil, errors.New("Error: unused 'order' fields")
  100 + }
  101 + }
  102 +
  103 + var l []AchievementProvider
  104 + qs = qs.OrderBy(sortFields...)
  105 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  106 + if len(fields) == 0 {
  107 + for _, v := range l {
  108 + ml = append(ml, v)
  109 + }
  110 + } else {
  111 + // trim unused fields
  112 + for _, v := range l {
  113 + m := make(map[string]interface{})
  114 + val := reflect.ValueOf(v)
  115 + for _, fname := range fields {
  116 + m[fname] = val.FieldByName(fname).Interface()
  117 + }
  118 + ml = append(ml, m)
  119 + }
  120 + }
  121 + return ml, nil
  122 + }
  123 + return nil, err
  124 +}
  125 +
  126 +// UpdateAchievementProvider updates AchievementProvider by Id and returns error if
  127 +// the record to be updated doesn't exist
  128 +func UpdateAchievementProviderById(m *AchievementProvider) (err error) {
  129 + o := orm.NewOrm()
  130 + v := AchievementProvider{Id: m.Id}
  131 + // ascertain id exists in the database
  132 + if err = o.Read(&v); err == nil {
  133 + var num int64
  134 + if num, err = o.Update(m); err == nil {
  135 + fmt.Println("Number of records updated in database:", num)
  136 + }
  137 + }
  138 + return
  139 +}
  140 +
  141 +// DeleteAchievementProvider deletes AchievementProvider by Id and returns error if
  142 +// the record to be deleted doesn't exist
  143 +func DeleteAchievementProvider(id int) (err error) {
  144 + o := orm.NewOrm()
  145 + v := AchievementProvider{Id: id}
  146 + // ascertain id exists in the database
  147 + if err = o.Read(&v); err == nil {
  148 + var num int64
  149 + if num, err = o.Delete(&AchievementProvider{Id: id}); err == nil {
  150 + fmt.Println("Number of records deleted in database:", num)
  151 + }
  152 + }
  153 + return
  154 +}
@@ -29,6 +29,11 @@ func init() { @@ -29,6 +29,11 @@ func init() {
29 // AddRankItem insert a new NewRankItem into database and returns 29 // AddRankItem insert a new NewRankItem into database and returns
30 // last inserted Id on success. 30 // last inserted Id on success.
31 func AddRankItem(m []RankItem, om orm.Ormer) (successSum int64, err error) { 31 func AddRankItem(m []RankItem, om orm.Ormer) (successSum int64, err error) {
  32 + nowTime := time.Now()
  33 + for i := range m {
  34 + m[i].CreateAt = nowTime
  35 + m[i].UpdateAt = nowTime
  36 + }
32 successSum, err = om.InsertMulti(10, &m) 37 successSum, err = om.InsertMulti(10, &m)
33 return 38 return
34 } 39 }
@@ -52,7 +57,7 @@ func GetRankItemByCompanyid(companyid int64, rankTypeId int64) ([]RankItem, erro @@ -52,7 +57,7 @@ func GetRankItemByCompanyid(companyid int64, rankTypeId int64) ([]RankItem, erro
52 o := orm.NewOrm() 57 o := orm.NewOrm()
53 _, err = o.QueryTable(&RankItem{}). 58 _, err = o.QueryTable(&RankItem{}).
54 Filter("company_id", companyid). 59 Filter("company_id", companyid).
55 - Filter("rank_yype_id", rankTypeId). 60 + Filter("rank_type_id", rankTypeId).
56 All(&data) 61 All(&data)
57 if err == orm.ErrNoRows { 62 if err == orm.ErrNoRows {
58 return data, nil 63 return data, nil
@@ -74,7 +79,7 @@ func UpdateRankItemById(m *RankItem, cols []string, om orm.Ormer) (err error) { @@ -74,7 +79,7 @@ func UpdateRankItemById(m *RankItem, cols []string, om orm.Ormer) (err error) {
74 m.UpdateAt = time.Now() 79 m.UpdateAt = time.Now()
75 var num int64 80 var num int64
76 if num, err = om.Update(m, cols...); err == nil { 81 if num, err = om.Update(m, cols...); err == nil {
77 - log.Info("Number of records updated in database:", num) 82 + log.Info("Number of records updated in database:%d", num)
78 } 83 }
79 return 84 return
80 } 85 }
1 package models 1 package models
2 2
3 import ( 3 import (
4 - "fmt" 4 + "oppmg/common/log"
5 "time" 5 "time"
6 6
7 "github.com/astaxie/beego/orm" 7 "github.com/astaxie/beego/orm"
@@ -40,6 +40,8 @@ const ( @@ -40,6 +40,8 @@ const (
40 // last inserted Id on success. 40 // last inserted Id on success.
41 func AddRankPeriod(m *RankPeriod) (id int64, err error) { 41 func AddRankPeriod(m *RankPeriod) (id int64, err error) {
42 o := orm.NewOrm() 42 o := orm.NewOrm()
  43 + m.CreateAt = time.Now()
  44 + m.UpdateAt = time.Now()
43 id, err = o.Insert(m) 45 id, err = o.Insert(m)
44 return 46 return
45 } 47 }
@@ -57,15 +59,16 @@ func GetRankPeriodById(id int64) (v *RankPeriod, err error) { @@ -57,15 +59,16 @@ func GetRankPeriodById(id int64) (v *RankPeriod, err error) {
57 59
58 // UpdateNewRankPeriod updates RankPeriod by Id and returns error if 60 // UpdateNewRankPeriod updates RankPeriod by Id and returns error if
59 // the record to be updated doesn't exist 61 // the record to be updated doesn't exist
60 -func UpdateRankPeriodById(m *RankPeriod) (err error) { 62 +func UpdateRankPeriodById(m *RankPeriod, cols []string) (err error) {
61 o := orm.NewOrm() 63 o := orm.NewOrm()
62 - v := RankPeriod{Id: m.Id}  
63 - // ascertain id exists in the database  
64 - if err = o.Read(&v); err == nil {  
65 - var num int64  
66 - if num, err = o.Update(m); err == nil {  
67 - fmt.Println("Number of records updated in database:", num) 64 + m.UpdateAt = time.Now()
  65 + if len(cols) > 0 {
  66 + cols = append(cols, "UpdateAt")
68 } 67 }
  68 + var num int64
  69 + if num, err = o.Update(m, cols...); err == nil {
  70 + log.Info("Number of records updated in database:", num)
69 } 71 }
  72 +
70 return 73 return
71 } 74 }
@@ -18,6 +18,7 @@ type RankRange struct { @@ -18,6 +18,7 @@ type RankRange struct {
18 CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` 18 CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
19 UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` 19 UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
20 SortNum int `orm:"column(sort_num)"` 20 SortNum int `orm:"column(sort_num)"`
  21 + Status int8 `orm:"column(status)"`
21 } 22 }
22 23
23 func (t *RankRange) TableName() string { 24 func (t *RankRange) TableName() string {
@@ -13,7 +13,7 @@ type RankType struct { @@ -13,7 +13,7 @@ type RankType struct {
13 Name string `orm:"column(name)"` 13 Name string `orm:"column(name)"`
14 EnableStatus int8 `orm:"column(enable_status)"` 14 EnableStatus int8 `orm:"column(enable_status)"`
15 CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` 15 CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
16 - UpdataAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` 16 + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
17 Type int8 `orm:"column(type)"` 17 Type int8 `orm:"column(type)"`
18 } 18 }
19 19
@@ -43,7 +43,7 @@ func AddRank(m *RankType) (id int64, err error) { @@ -43,7 +43,7 @@ func AddRank(m *RankType) (id int64, err error) {
43 o := orm.NewOrm() 43 o := orm.NewOrm()
44 nowTime := time.Now() 44 nowTime := time.Now()
45 m.CreateAt = nowTime 45 m.CreateAt = nowTime
46 - m.UpdataAt = nowTime 46 + m.UpdateAt = nowTime
47 id, err = o.Insert(m) 47 id, err = o.Insert(m)
48 return 48 return
49 } 49 }
@@ -68,7 +68,7 @@ func UpdateRankById(m *RankType, cols []string, om ...orm.Ormer) (err error) { @@ -68,7 +68,7 @@ func UpdateRankById(m *RankType, cols []string, om ...orm.Ormer) (err error) {
68 } else { 68 } else {
69 o = orm.NewOrm() 69 o = orm.NewOrm()
70 } 70 }
71 - m.UpdataAt = time.Now() 71 + m.UpdateAt = time.Now()
72 if len(cols) > 0 { 72 if len(cols) > 0 {
73 cols = append(cols, "UpdateAt") 73 cols = append(cols, "UpdateAt")
74 } 74 }
@@ -4,8 +4,8 @@ package protocol @@ -4,8 +4,8 @@ package protocol
4 type ResponseRankType struct { 4 type ResponseRankType struct {
5 Id int `json:"id" orm:"column(id)"` 5 Id int `json:"id" orm:"column(id)"`
6 Name string `json:"name" orm:"column(name)"` 6 Name string `json:"name" orm:"column(name)"`
7 - Status int8 `json:"status" orm:"column(status)"`  
8 - RankType int8 `json:"rank_type" orm:"column(rank_type)"` 7 + EnableStatus int8 `json:"enable_status" orm:"column(enable_status)"`
  8 + Type int8 `json:"type" orm:"column(type)"`
9 } 9 }
10 10
11 // ResponseRankSeasonList 赛季列表 11 // ResponseRankSeasonList 赛季列表
@@ -15,7 +15,7 @@ type ResponseRankSeasonList struct { @@ -15,7 +15,7 @@ type ResponseRankSeasonList struct {
15 } 15 }
16 type RankSeasonItem struct { 16 type RankSeasonItem struct {
17 Id int64 `json:"id" orm:"column(id)"` 17 Id int64 `json:"id" orm:"column(id)"`
18 - SeasonName string `json:"season_name" orm:"column(season_name)"` 18 + Name string `json:"name" orm:"column(name)"`
19 BeginTime string `json:"begin_time" orm:"column(begin_time)"` 19 BeginTime string `json:"begin_time" orm:"column(begin_time)"`
20 EndTime string `json:"end_time" orm:"column(end_time)"` 20 EndTime string `json:"end_time" orm:"column(end_time)"`
21 Status int8 `json:"status" orm:"column(status)"` 21 Status int8 `json:"status" orm:"column(status)"`
@@ -104,15 +104,16 @@ func init() { @@ -104,15 +104,16 @@ func init() {
104 beego.NSRouter("/allow_forbid", &controllers.AuditController{}, "post:AllowForbidAudit"), 104 beego.NSRouter("/allow_forbid", &controllers.AuditController{}, "post:AllowForbidAudit"),
105 ), 105 ),
106 beego.NSNamespace("/rank", 106 beego.NSNamespace("/rank",
107 - beego.NSRouter("/list", &controllers.RankController{}, "post:GetRankType"),  
108 - beego.NSRouter("/edit", &controllers.RankController{}, "post:EditRankType"),  
109 - beego.NSRouter("/forbid_allow", &controllers.RankController{}, "post:RankTypeForbidAllow"), 107 + beego.NSRouter("/type/list", &controllers.RankController{}, "post:GetRankType"),
  108 + beego.NSRouter("/type/edit", &controllers.RankController{}, "post:EditRankType"),
  109 + beego.NSRouter("/type/forbid_allow", &controllers.RankController{}, "post:RankTypeForbidAllow"),
110 beego.NSRouter("/season/add", &controllers.RankController{}, "post:RankSeasonAdd"), 110 beego.NSRouter("/season/add", &controllers.RankController{}, "post:RankSeasonAdd"),
111 beego.NSRouter("/season/list", &controllers.RankController{}, "post:RankSeasonList"), 111 beego.NSRouter("/season/list", &controllers.RankController{}, "post:RankSeasonList"),
112 beego.NSRouter("/season/edit", &controllers.RankController{}, "post:RankSeasonEdit"), 112 beego.NSRouter("/season/edit", &controllers.RankController{}, "post:RankSeasonEdit"),
113 beego.NSRouter("/range/list", &controllers.RankController{}, "post:RankRangeList"), 113 beego.NSRouter("/range/list", &controllers.RankController{}, "post:RankRangeList"),
114 beego.NSRouter("/range/edit", &controllers.RankController{}, "post:RankRangeEdit"), 114 beego.NSRouter("/range/edit", &controllers.RankController{}, "post:RankRangeEdit"),
115 beego.NSRouter("/range/add", &controllers.RankController{}, "post:RankRangeAdd"), 115 beego.NSRouter("/range/add", &controllers.RankController{}, "post:RankRangeAdd"),
  116 + beego.NSRouter("/range/forbid_allow", &controllers.RankController{}, "post:RankRangeForbidAllow"),
116 beego.NSRouter("/range/info", &controllers.RankController{}, "post:RankRangeInfo"), 117 beego.NSRouter("/range/info", &controllers.RankController{}, "post:RankRangeInfo"),
117 beego.NSRouter("/range/sort", &controllers.RankController{}, "post:RankRangeSort"), 118 beego.NSRouter("/range/sort", &controllers.RankController{}, "post:RankRangeSort"),
118 beego.NSRouter("/item/list", &controllers.RankController{}, "post:RankItemList"), 119 beego.NSRouter("/item/list", &controllers.RankController{}, "post:RankItemList"),
@@ -18,7 +18,7 @@ func GetRankList(companyid int64) []protocol.ResponseRankType { @@ -18,7 +18,7 @@ func GetRankList(companyid int64) []protocol.ResponseRankType {
18 rspData = make([]protocol.ResponseRankType, 0) 18 rspData = make([]protocol.ResponseRankType, 0)
19 err error 19 err error
20 ) 20 )
21 - sqlString := `SELECT id,name,status,rank_type FROM rank WHERE company_id=?` 21 + sqlString := `SELECT id,name,enable_status,type FROM rank_type WHERE company_id=?`
22 err = utils.ExecuteQueryAll(&rspData, sqlString, companyid) 22 err = utils.ExecuteQueryAll(&rspData, sqlString, companyid)
23 if err != nil { 23 if err != nil {
24 log.Error("获取榜单列表失败,err%s", err) 24 log.Error("获取榜单列表失败,err%s", err)
@@ -148,7 +148,7 @@ func RankSeasonList(pageindex int, pagesize int, companyid int64) (protocol.Resp @@ -148,7 +148,7 @@ func RankSeasonList(pageindex int, pagesize int, companyid int64) (protocol.Resp
148 var ( 148 var (
149 err error 149 err error
150 listdata []protocol.RankSeasonItem 150 listdata []protocol.RankSeasonItem
151 - cnt int64 151 + cnt int
152 ) 152 )
153 rspData := protocol.ResponseRankSeasonList{ 153 rspData := protocol.ResponseRankSeasonList{
154 ResponsePageInfo: protocol.ResponsePageInfo{ 154 ResponsePageInfo: protocol.ResponsePageInfo{
@@ -173,6 +173,8 @@ func RankSeasonList(pageindex int, pagesize int, companyid int64) (protocol.Resp @@ -173,6 +173,8 @@ func RankSeasonList(pageindex int, pagesize int, companyid int64) (protocol.Resp
173 log.Error("EXCUTE SQL ERR:%s", err) 173 log.Error("EXCUTE SQL ERR:%s", err)
174 return rspData, nil 174 return rspData, nil
175 } 175 }
  176 + rspData.TotalPage = cnt
  177 + rspData.List = listdata
176 return rspData, err 178 return rspData, err
177 } 179 }
178 180
@@ -184,8 +186,8 @@ func AddRankPeriod(rankTypeId int64, beginTime int64, endTime int64, name string @@ -184,8 +186,8 @@ func AddRankPeriod(rankTypeId int64, beginTime int64, endTime int64, name string
184 CompanyId: companyid, 186 CompanyId: companyid,
185 SeasonName: name, 187 SeasonName: name,
186 RankTypeId: rankTypeId, 188 RankTypeId: rankTypeId,
187 - BeginTime: time.Unix(beginTime, 0),  
188 - EndTime: time.Unix(endTime, 0), 189 + BeginTime: time.Unix(beginTime, 0).Local(),
  190 + EndTime: time.Unix(endTime, 0).Local(),
189 Status: 0, 191 Status: 0,
190 } 192 }
191 _, err = models.AddRankPeriod(m) 193 _, err = models.AddRankPeriod(m)
@@ -212,7 +214,7 @@ func EditRankPeriod(id int64, beginTime int64, endTime int64, name string, compa @@ -212,7 +214,7 @@ func EditRankPeriod(id int64, beginTime int64, endTime int64, name string, compa
212 m.SeasonName = name 214 m.SeasonName = name
213 m.BeginTime = time.Unix(beginTime, 0) 215 m.BeginTime = time.Unix(beginTime, 0)
214 m.EndTime = time.Unix(endTime, 0) 216 m.EndTime = time.Unix(endTime, 0)
215 - err = models.UpdateRankPeriodById(m) 217 + err = models.UpdateRankPeriodById(m, []string{"SeasonName", "BeginTime", "EndTime"})
216 if err != nil { 218 if err != nil {
217 log.Error("更新赛季失败;%s", err) 219 log.Error("更新赛季失败;%s", err)
218 } 220 }
@@ -226,7 +228,7 @@ func GetRankRangeList(companyid int64) []protocol.RankRangeItem { @@ -226,7 +228,7 @@ func GetRankRangeList(companyid int64) []protocol.RankRangeItem {
226 rspData = make([]protocol.RankRangeItem, 0) 228 rspData = make([]protocol.RankRangeItem, 0)
227 ) 229 )
228 datasql := `SELECT a.id ,a.name,a.type FROM rank_range AS a WHERE company_id=?` 230 datasql := `SELECT a.id ,a.name,a.type FROM rank_range AS a WHERE company_id=?`
229 - err = utils.ExecuteQueryAll(rspData, datasql, companyid) 231 + err = utils.ExecuteQueryAll(&rspData, datasql, companyid)
230 if err != nil { 232 if err != nil {
231 log.Error("获取参与人列表失败:%s", err) 233 log.Error("获取参与人列表失败:%s", err)
232 } 234 }
@@ -497,6 +499,7 @@ func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error @@ -497,6 +499,7 @@ func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error
497 RankTypeId: rankTypeid, 499 RankTypeId: rankTypeid,
498 ItemName: AllRankItem[ii].ItemName, 500 ItemName: AllRankItem[ii].ItemName,
499 SortNum: i, 501 SortNum: i,
  502 + ItemKey: itemKey[i],
500 } 503 }
501 newItems = append(newItems, m) 504 newItems = append(newItems, m)
502 break 505 break
@@ -526,7 +529,7 @@ func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error @@ -526,7 +529,7 @@ func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error
526 for i := range newItems { 529 for i := range newItems {
527 var has bool = false 530 var has bool = false
528 for ii := range rankitemData { 531 for ii := range rankitemData {
529 - if rankitemData[i].ItemKey == newItems[ii].ItemKey { 532 + if rankitemData[ii].ItemKey == newItems[i].ItemKey {
530 has = true 533 has = true
531 break 534 break
532 } 535 }
@@ -538,15 +541,17 @@ func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error @@ -538,15 +541,17 @@ func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error
538 o := orm.NewOrm() 541 o := orm.NewOrm()
539 o.Begin() 542 o.Begin()
540 //添加 543 //添加
  544 + if len(addItems) > 0 {
541 _, err = models.AddRankItem(addItems, o) 545 _, err = models.AddRankItem(addItems, o)
542 if err != nil { 546 if err != nil {
543 o.Rollback() 547 o.Rollback()
544 log.Error("添加rank_item记录失败:%s", err) 548 log.Error("添加rank_item记录失败:%s", err)
545 return protocol.NewErrWithMessage("1") 549 return protocol.NewErrWithMessage("1")
546 } 550 }
  551 + }
547 //更新 552 //更新
548 for i := range updateItems { 553 for i := range updateItems {
549 - err = models.UpdateRankItemById(&updateItems[i], []string{"SortNum"}, o) 554 + err = models.UpdateRankItemById(&updateItems[i], []string{"SortNum", "ItemName", "ItemKey"}, o)
550 if err != nil { 555 if err != nil {
551 o.Rollback() 556 o.Rollback()
552 log.Error("更新rank_item记录失败:%s", err) 557 log.Error("更新rank_item记录失败:%s", err)
@@ -554,12 +559,51 @@ func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error @@ -554,12 +559,51 @@ func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error
554 } 559 }
555 } 560 }
556 //删除 561 //删除
  562 + if len(delItemIds) > 0 {
557 err = models.DeleteRanKItemByIds(delItemIds, o) 563 err = models.DeleteRanKItemByIds(delItemIds, o)
558 if err != nil { 564 if err != nil {
559 o.Rollback() 565 o.Rollback()
560 log.Error("删除rank_item记录失败:%s", err) 566 log.Error("删除rank_item记录失败:%s", err)
561 return protocol.NewErrWithMessage("1") 567 return protocol.NewErrWithMessage("1")
562 } 568 }
  569 + }
  570 +
563 o.Commit() 571 o.Commit()
564 return nil 572 return nil
565 } 573 }
  574 +
  575 +func ForbidRankRange(id int64, companyid int64) error {
  576 + var (
  577 + err error
  578 + rankRange *models.RankRange
  579 + )
  580 + rankRange, err = models.GetRankRangeById(id)
  581 + if err != nil {
  582 + log.Error("获取rank_range数据失败:%s", err)
  583 + return protocol.NewErrWithMessage("1")
  584 + }
  585 + rankRange.Status = 1
  586 + err = models.UpdateRankRangeById(rankRange, []string{"Status"})
  587 + if err != nil {
  588 + log.Error("更新rank_range数据失败:%s", err)
  589 + }
  590 + return nil
  591 +}
  592 +
  593 +func AllowRankRange(id int64, companyid int64) error {
  594 + var (
  595 + err error
  596 + rankRange *models.RankRange
  597 + )
  598 + rankRange, err = models.GetRankRangeById(id)
  599 + if err != nil {
  600 + log.Error("获取rank_range数据失败:%s", err)
  601 + return protocol.NewErrWithMessage("1")
  602 + }
  603 + rankRange.Status = 0
  604 + err = models.UpdateRankRangeById(rankRange, []string{"Status"})
  605 + if err != nil {
  606 + log.Error("更新rank_range数据失败:%s", err)
  607 + }
  608 + return nil
  609 +}