作者 tangxvhui

赛季配置

@@ -3,6 +3,7 @@ package controllers @@ -3,6 +3,7 @@ package controllers
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
5 "oppmg/common/log" 5 "oppmg/common/log"
  6 + "oppmg/models"
6 "oppmg/protocol" 7 "oppmg/protocol"
7 serverank "oppmg/services/rank" 8 serverank "oppmg/services/rank"
8 ) 9 )
@@ -152,3 +153,128 @@ func (c RankController) RankSeasonEdit() { @@ -152,3 +153,128 @@ func (c RankController) RankSeasonEdit() {
152 msg = protocol.NewReturnResponse(nil, err) 153 msg = protocol.NewReturnResponse(nil, err)
153 return 154 return
154 } 155 }
  156 +
  157 +//RankRangeList ...
  158 +//@router /rank/range/list
  159 +func (c RankController) RankRangeList() {
  160 + var msg *protocol.ResponseMessage
  161 + defer func() {
  162 + c.ResposeJson(msg)
  163 + }()
  164 +
  165 + companyid := c.GetCompanyId()
  166 + rspData := serverank.GetRankRangeList(companyid)
  167 + msg = protocol.NewReturnResponse(rspData, nil)
  168 + return
  169 +}
  170 +
  171 +//RankRangeAdd ...
  172 +//@router /rank/range/add
  173 +func (c RankController) RankRangeAdd() {
  174 + var msg *protocol.ResponseMessage
  175 + defer func() {
  176 + c.ResposeJson(msg)
  177 + }()
  178 + type Parameter struct {
  179 + Name string `json:"name"`
  180 + RangeType int8 `json:"range_type"`
  181 + RelationId []int64 `json:"relation_id"`
  182 + }
  183 + var param Parameter
  184 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  185 + log.Error("json 解析失败 err:%s", err)
  186 + msg = protocol.BadRequestParam("1")
  187 + return
  188 + }
  189 + switch param.RangeType {
  190 + case 1:
  191 + //员工
  192 + if len(param.RelationId) == 0 {
  193 + param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEEALL
  194 + } else {
  195 + param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE
  196 + }
  197 + case 2:
  198 + //部门
  199 + if len(param.RelationId) == 0 {
  200 + param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENTALL
  201 + } else {
  202 + param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT
  203 + }
  204 + default:
  205 + log.Error("param.RangeType err")
  206 + msg = protocol.BadRequestParam("1")
  207 + return
  208 + }
  209 + companyid := c.GetCompanyId()
  210 + err := serverank.AddRankRange(param.Name, param.RangeType, param.RelationId, companyid)
  211 + msg = protocol.NewReturnResponse(nil, err)
  212 + return
  213 +}
  214 +
  215 +//RankRangeEdit ...
  216 +//@router /rank/range/edit
  217 +func (c RankController) RankRangeEdit() {
  218 + var msg *protocol.ResponseMessage
  219 + defer func() {
  220 + c.ResposeJson(msg)
  221 + }()
  222 + type Parameter struct {
  223 + Id int64 `json:"id"`
  224 + Name string `json:"name"`
  225 + RangeType int8 `json:"range_type"`
  226 + RelationId []int64 `json:"relation_id"`
  227 + }
  228 + var param Parameter
  229 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  230 + log.Error("json 解析失败 err:%s", err)
  231 + msg = protocol.BadRequestParam("1")
  232 + return
  233 + }
  234 + switch param.RangeType {
  235 + case 1:
  236 + //员工
  237 + if len(param.RelationId) == 0 {
  238 + param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEEALL
  239 + } else {
  240 + param.RangeType = models.RANK_RANGE_TYPE_EMPLAYEE
  241 + }
  242 + case 2:
  243 + //部门
  244 + if len(param.RelationId) == 0 {
  245 + param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENTALL
  246 + } else {
  247 + param.RangeType = models.RANK_RANGE_TYPE_DEPARTMENT
  248 + }
  249 + default:
  250 + log.Error("param.RangeType err")
  251 + msg = protocol.BadRequestParam("1")
  252 + return
  253 + }
  254 + companyid := c.GetCompanyId()
  255 + err := serverank.EditRankRange(param.Id, param.Name, param.RangeType, param.RelationId, companyid)
  256 + msg = protocol.NewReturnResponse(nil, err)
  257 + return
  258 +}
  259 +
  260 +//RankRangeInfo ...
  261 +//@router /rank/range/info
  262 +func (c RankController) RankRangeInfo() {
  263 + var msg *protocol.ResponseMessage
  264 + defer func() {
  265 + c.ResposeJson(msg)
  266 + }()
  267 + type Parameter struct {
  268 + Id int64 `json:"id"`
  269 + }
  270 + var param Parameter
  271 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  272 + log.Error("json 解析失败 err:%s", err)
  273 + msg = protocol.BadRequestParam("1")
  274 + return
  275 + }
  276 + // companyid := c.GetCompanyId()
  277 + rspData := serverank.GetRankRangeInfo(param.Id)
  278 + msg = protocol.NewReturnResponse(rspData, nil)
  279 + return
  280 +}
1 package models 1 package models
2 2
3 import ( 3 import (
4 - "errors"  
5 "fmt" 4 "fmt"
6 - "reflect"  
7 - "strings" 5 + "oppmg/common/log"
8 "time" 6 "time"
9 7
10 "github.com/astaxie/beego/orm" 8 "github.com/astaxie/beego/orm"
11 ) 9 )
12 10
13 -type NewRankRange struct {  
14 - Id int `orm:"column(id);auto"` 11 +type RankRange struct {
  12 + Id int64 `orm:"column(id);auto"`
15 Name string `orm:"column(name);size(50);null" description:"名称"` 13 Name string `orm:"column(name);size(50);null" description:"名称"`
16 - CompanyId int `orm:"column(company_id);null" description:"公司编号 表company.id"` 14 + CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"`
17 Type int8 `orm:"column(type);null" description:"1:所有员工 2:指定员工 3:所有部门 4:指定部门"` 15 Type int8 `orm:"column(type);null" description:"1:所有员工 2:指定员工 3:所有部门 4:指定部门"`
18 Data string `orm:"column(data);size(1000);null" description:"人员范围数据(type:2,4 有值 对于人员数据/部门数据)"` 16 Data string `orm:"column(data);size(1000);null" description:"人员范围数据(type:2,4 有值 对于人员数据/部门数据)"`
19 CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` 17 CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
20 UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` 18 UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
21 } 19 }
22 20
23 -func (t *NewRankRange) TableName() string { 21 +func (t *RankRange) TableName() string {
24 return "rank_range" 22 return "rank_range"
25 } 23 }
26 24
27 func init() { 25 func init() {
28 - orm.RegisterModel(new(NewRankRange)) 26 + orm.RegisterModel(new(RankRange))
29 } 27 }
30 28
31 -// AddNewRankRange insert a new NewRankRange into database and returns 29 +//1:所有员工 2:指定员工 3:所有部门 4:指定部门
  30 +const (
  31 + RANK_RANGE_TYPE_EMPLAYEEALL int8 = 1
  32 + RANK_RANGE_TYPE_EMPLAYEE int8 = 2
  33 + RANK_RANGE_TYPE_DEPARTMENTALL int8 = 3
  34 + RANK_RANGE_TYPE_DEPARTMENT int8 = 4
  35 +)
  36 +
  37 +// AddRankRange insert a new RankRange into database and returns
32 // last inserted Id on success. 38 // last inserted Id on success.
33 -func AddNewRankRange(m *NewRankRange) (id int64, err error) {  
34 - o := orm.NewOrm() 39 +func AddRankRange(m *RankRange, om ...orm.Ormer) (id int64, err error) {
  40 + var o orm.Ormer
  41 + if len(om) > 0 {
  42 + o = om[0]
  43 + } else {
  44 + o = orm.NewOrm()
  45 + }
  46 + m.CreateAt = time.Now()
  47 + m.UpdateAt = time.Now()
35 id, err = o.Insert(m) 48 id, err = o.Insert(m)
36 return 49 return
37 } 50 }
38 51
39 -// GetNewRankRangeById retrieves NewRankRange by Id. Returns error if 52 +// GetRankRangeById retrieves RankRange by Id. Returns error if
40 // Id doesn't exist 53 // Id doesn't exist
41 -func GetNewRankRangeById(id int) (v *NewRankRange, err error) { 54 +func GetRankRangeById(id int64) (v *RankRange, err error) {
42 o := orm.NewOrm() 55 o := orm.NewOrm()
43 - v = &NewRankRange{Id: id} 56 + v = &RankRange{Id: id}
44 if err = o.Read(v); err == nil { 57 if err = o.Read(v); err == nil {
45 return v, nil 58 return v, nil
46 } 59 }
47 return nil, err 60 return nil, err
48 } 61 }
49 62
50 -// GetAllNewRankRange retrieves all NewRankRange matches certain condition. Returns empty list if  
51 -// no records exist  
52 -func GetAllNewRankRange(query map[string]string, fields []string, sortby []string, order []string,  
53 - offset int64, limit int64) (ml []interface{}, err error) {  
54 - o := orm.NewOrm()  
55 - qs := o.QueryTable(new(NewRankRange))  
56 - // query k=v  
57 - for k, v := range query {  
58 - // rewrite dot-notation to Object__Attribute  
59 - k = strings.Replace(k, ".", "__", -1)  
60 - if strings.Contains(k, "isnull") {  
61 - qs = qs.Filter(k, (v == "true" || v == "1"))  
62 - } else {  
63 - qs = qs.Filter(k, v)  
64 - }  
65 - }  
66 - // order by:  
67 - var sortFields []string  
68 - if len(sortby) != 0 {  
69 - if len(sortby) == len(order) {  
70 - // 1) for each sort field, there is an associated order  
71 - for i, v := range sortby {  
72 - orderby := ""  
73 - if order[i] == "desc" {  
74 - orderby = "-" + v  
75 - } else if order[i] == "asc" {  
76 - orderby = v  
77 - } else {  
78 - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")  
79 - }  
80 - sortFields = append(sortFields, orderby)  
81 - }  
82 - qs = qs.OrderBy(sortFields...)  
83 - } else if len(sortby) != len(order) && len(order) == 1 {  
84 - // 2) there is exactly one order, all the sorted fields will be sorted by this order  
85 - for _, v := range sortby {  
86 - orderby := ""  
87 - if order[0] == "desc" {  
88 - orderby = "-" + v  
89 - } else if order[0] == "asc" {  
90 - orderby = v  
91 - } else {  
92 - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")  
93 - }  
94 - sortFields = append(sortFields, orderby)  
95 - }  
96 - } else if len(sortby) != len(order) && len(order) != 1 {  
97 - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")  
98 - } 63 +// UpdateRankRangeById updates RankRange by Id and returns error if
  64 +// the record to be updated doesn't exist
  65 +func UpdateRankRangeById(m *RankRange, cols []string, om ...orm.Ormer) (err error) {
  66 + var o orm.Ormer
  67 + if len(om) > 0 {
  68 + o = om[0]
99 } else { 69 } else {
100 - if len(order) != 0 {  
101 - return nil, errors.New("Error: unused 'order' fields")  
102 - } 70 + o = orm.NewOrm()
103 } 71 }
104 -  
105 - var l []NewRankRange  
106 - qs = qs.OrderBy(sortFields...)  
107 - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {  
108 - if len(fields) == 0 {  
109 - for _, v := range l {  
110 - ml = append(ml, v)  
111 - }  
112 - } else {  
113 - // trim unused fields  
114 - for _, v := range l {  
115 - m := make(map[string]interface{})  
116 - val := reflect.ValueOf(v)  
117 - for _, fname := range fields {  
118 - m[fname] = val.FieldByName(fname).Interface()  
119 - }  
120 - ml = append(ml, m)  
121 - }  
122 - }  
123 - return ml, nil 72 + var num int64
  73 + m.UpdateAt = time.Now()
  74 + if len(cols) > 0 {
  75 + cols = append(cols, "UpdateAt")
124 } 76 }
125 - return nil, err  
126 -}  
127 -  
128 -// UpdateNewRankRange updates NewRankRange by Id and returns error if  
129 -// the record to be updated doesn't exist  
130 -func UpdateNewRankRangeById(m *NewRankRange) (err error) {  
131 - o := orm.NewOrm()  
132 - v := NewRankRange{Id: m.Id}  
133 - // ascertain id exists in the database  
134 - if err = o.Read(&v); err == nil {  
135 - var num int64  
136 - if num, err = o.Update(m); err == nil {  
137 - fmt.Println("Number of records updated in database:", num)  
138 - } 77 + if num, err = o.Update(m, cols...); err == nil {
  78 + log.Info("Number of records updated in database:%d", num)
139 } 79 }
140 return 80 return
141 } 81 }
142 82
143 -// DeleteNewRankRange deletes NewRankRange by Id and returns error if 83 +// DeleteRankRange deletes RankRange by Id and returns error if
144 // the record to be deleted doesn't exist 84 // the record to be deleted doesn't exist
145 -func DeleteNewRankRange(id int) (err error) { 85 +func DeleteRankRange(id int64) (err error) {
146 o := orm.NewOrm() 86 o := orm.NewOrm()
147 - v := NewRankRange{Id: id} 87 + v := RankRange{Id: id}
148 // ascertain id exists in the database 88 // ascertain id exists in the database
149 if err = o.Read(&v); err == nil { 89 if err = o.Read(&v); err == nil {
150 var num int64 90 var num int64
151 - if num, err = o.Delete(&NewRankRange{Id: id}); err == nil { 91 + if num, err = o.Delete(&RankRange{Id: id}); err == nil {
152 fmt.Println("Number of records deleted in database:", num) 92 fmt.Println("Number of records deleted in database:", num)
153 } 93 }
154 } 94 }
  1 +package models
  2 +
  3 +import (
  4 + "github.com/astaxie/beego/orm"
  5 +)
  6 +
  7 +type RankRangeData struct {
  8 + Id int64 `orm:"column(id);auto"`
  9 + RankRangeId int64 `orm:"column(rank_range_id)"`
  10 + RangeType int8 `orm:"column(range_type);" description:"类型"`
  11 + RelationId int64 `orm:"column(relation_id);"`
  12 +}
  13 +
  14 +func (t *RankRangeData) TableName() string {
  15 + return "rank_range_data"
  16 +}
  17 +
  18 +func init() {
  19 + orm.RegisterModel(new(RankRangeData))
  20 +}
  21 +
  22 +// AddRankRangeData insert a new RankRangeData into database and returns
  23 +// last inserted Id on success.
  24 +func AddRankRangeDataMulti(m []RankRangeData, om ...orm.Ormer) (successNums int64, err error) {
  25 + var o orm.Ormer
  26 + if len(om) > 0 {
  27 + o = om[0]
  28 + } else {
  29 + o = orm.NewOrm()
  30 + }
  31 + successNums, err = o.InsertMulti(20, m)
  32 + return
  33 +}
  34 +
  35 +// GetRankRangeDataById retrieves RankRangeData by Id. Returns error if
  36 +// Id doesn't exist
  37 +func GetRankRangeDataById(id int64) (v *RankRangeData, err error) {
  38 + o := orm.NewOrm()
  39 + v = &RankRangeData{Id: id}
  40 + if err = o.Read(v); err == nil {
  41 + return v, nil
  42 + }
  43 + return nil, err
  44 +}
  45 +
  46 +// DeleteRankRangeData deletes RankRangeData by Id and returns error if
  47 +// the record to be deleted doesn't exist
  48 +func DeleteRankRangeData(id []int64, om orm.Ormer) (err error) {
  49 +
  50 + _, err = om.QueryTable(&RankRangeData{}).
  51 + Filter("id__in", id).
  52 + Delete()
  53 + return err
  54 +}
  55 +
  56 +func GetRankRangeDataByRangeId(id int64) ([]RankRangeData, error) {
  57 + var (
  58 + data = make([]RankRangeData, 0)
  59 + err error
  60 + )
  61 + o := orm.NewOrm()
  62 + _, err = o.QueryTable(&RankRangeData{}).
  63 + Filter("rank_range_id", id).
  64 + All(&data)
  65 + if err == orm.ErrNoRows {
  66 + return data, nil
  67 + }
  68 + if err != nil {
  69 + return nil, err
  70 + }
  71 + return data, nil
  72 +}
@@ -20,3 +20,23 @@ type RankSeasonItem struct { @@ -20,3 +20,23 @@ type RankSeasonItem struct {
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)"`
22 } 22 }
  23 +
  24 +//RankRangeItem 赛季参与人列表项
  25 +type RankRangeItem struct {
  26 + Id int64 `json:"id" orm:"column(id)"`
  27 + Name string `json:"name" orm:"column(name)"`
  28 + RangeType int8 `json:"range_type" orm:"column(type)"`
  29 +}
  30 +
  31 +//ResponseRankRangeInfo 赛季参与人详情
  32 +type ResponseRankRangeInfo struct {
  33 + Id int64 `json:"id"`
  34 + Name string `json:"name"`
  35 + RangeType int8 `json:"range_type"`
  36 + Relation []RankRangeRelation `json:"relation"`
  37 +}
  38 +
  39 +type RankRangeRelation struct {
  40 + Id int64 `json:"id"`
  41 + Name string `json:"name"`
  42 +}
@@ -110,6 +110,10 @@ func init() { @@ -110,6 +110,10 @@ func init() {
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"),
  114 + beego.NSRouter("/range/edit", &controllers.RankController{}, "post:RankRangeEdit"),
  115 + beego.NSRouter("/range/add", &controllers.RankController{}, "post:RankRangeAdd"),
  116 + beego.NSRouter("/range/info", &controllers.RankController{}, "post:RankRangeInfo"),
113 ), 117 ),
114 ) 118 )
115 119
@@ -7,6 +7,8 @@ import ( @@ -7,6 +7,8 @@ import (
7 "oppmg/protocol" 7 "oppmg/protocol"
8 "oppmg/utils" 8 "oppmg/utils"
9 "time" 9 "time"
  10 +
  11 + "github.com/astaxie/beego/orm"
10 ) 12 )
11 13
12 //GetRankList 获取榜单类型列表 14 //GetRankList 获取榜单类型列表
@@ -216,6 +218,163 @@ func EditRankSeason(id int64, beginTime int64, endTime int64, name string, compa @@ -216,6 +218,163 @@ func EditRankSeason(id int64, beginTime int64, endTime int64, name string, compa
216 } 218 }
217 219
218 //获取赛季参与人列表 220 //获取赛季参与人列表
219 -func GetRankRangeList() { 221 +func GetRankRangeList(companyid int64) []protocol.RankRangeItem {
  222 + var (
  223 + err error
  224 + rspData = make([]protocol.RankRangeItem, 0)
  225 + )
  226 + datasql := `SELECT a.id ,a.name,a.type FROM rank_range AS a WHERE company_id=?`
  227 + err = utils.ExecuteQueryAll(rspData, datasql, companyid)
  228 + if err != nil {
  229 + log.Error("获取参与人列表失败:%s", err)
  230 + }
  231 + return rspData
  232 +}
  233 +
  234 +func AddRankRange(name string, rangetype int8, relationId []int64, companyid int64) error {
  235 + var (
  236 + rankRangeDatas []models.RankRangeData
  237 + rankRange *models.RankRange
  238 + err error
  239 + )
  240 + rankRange = &models.RankRange{
  241 + Name: name,
  242 + CompanyId: companyid,
  243 + Type: rangetype,
  244 + }
  245 + o := orm.NewOrm()
  246 + o.Begin()
  247 + _, err = models.AddRankRange(rankRange, o)
  248 + if err != nil {
  249 + o.Rollback()
  250 + log.Error("添加rank_range记录失败:%s", err)
  251 + return protocol.NewErrWithMessage("1")
  252 + }
  253 + //TODO 去除其他分组的重复项
  254 + for i := range relationId {
  255 + m := models.RankRangeData{
  256 + RankRangeId: rankRange.Id,
  257 + RangeType: rangetype,
  258 + RelationId: relationId[i],
  259 + }
  260 + rankRangeDatas = append(rankRangeDatas, m)
  261 + }
  262 + _, err = models.AddRankRangeDataMulti(rankRangeDatas, o)
  263 + if err != nil {
  264 + o.Rollback()
  265 + log.Error("添加rank_range_data记录失败;%s", err)
  266 + return protocol.NewErrWithMessage("1")
  267 + }
  268 + o.Commit()
  269 + return nil
  270 +}
  271 +
  272 +func EditRankRange(id int64, name string, rangetype int8, relationId []int64, companyid int64) error {
  273 + var (
  274 + rankRangeDatas []models.RankRangeData
  275 + rankRange *models.RankRange
  276 + err error
  277 + )
  278 + rankRange, err = models.GetRankRangeById(id)
  279 + if err != nil {
  280 + log.Error("获取rank_range数据失败;%s", err)
  281 + return protocol.NewErrWithMessage("1")
  282 + }
  283 + if rankRange.CompanyId != companyid {
  284 + log.Error("公司不匹配")
  285 + return protocol.NewErrWithMessage("1")
  286 + }
  287 + rankRangeDatas, err = models.GetRankRangeDataByRangeId(rankRange.Id)
  288 + if err != nil {
  289 + log.Error("获取rank_range_data数据失败;%s", err)
  290 + return protocol.NewErrWithMessage("1")
  291 + }
  292 + var (
  293 + oldids []int64
  294 + delids []int64
  295 + addids []int64
  296 + )
  297 + if rankRange.Type != rangetype {
  298 + //当rangeType不同时
  299 + delids = oldids
  300 + addids = relationId
  301 + } else {
  302 + for i := range rankRangeDatas {
  303 + oldids = append(oldids, rankRangeDatas[i].RelationId)
  304 + }
  305 + delids = utils.ArrayInt64Diff(oldids, relationId)
  306 + addids = utils.ArrayInt64Diff(relationId, oldids)
  307 + }
  308 + var (
  309 + addRangeData []models.RankRangeData
  310 + )
  311 + for i := range addids {
  312 + r := models.RankRangeData{
  313 + RankRangeId: id,
  314 + RangeType: rangetype,
  315 + RelationId: addids[i],
  316 + }
  317 + addRangeData = append(addRangeData, r)
  318 + }
  319 + rankRange.Name = name
  320 + rankRange.Type = rangetype
  321 + o := orm.NewOrm()
  322 + o.Begin()
  323 + //TODO 去除其他分组的重复项
  324 + err = models.UpdateRankRangeById(rankRange, []string{"Name", "Type"}, o)
  325 + if err != nil {
  326 + o.Rollback()
  327 + log.Error("添加rank_range数据失败:%s", err)
  328 + return protocol.NewErrWithMessage("1")
  329 + }
  330 + if len(delids) > 0 {
  331 + err = models.DeleteRankRangeData(delids, o)
  332 + if err != nil {
  333 + o.Rollback()
  334 + log.Error("删除rank_range_data数据失败:%s", err)
  335 + return protocol.NewErrWithMessage("1")
  336 + }
  337 + }
  338 + if len(addids) > 0 {
  339 + _, err = models.AddRankRangeDataMulti(addRangeData, o)
  340 + if err != nil {
  341 + o.Rollback()
  342 + log.Error("添加rank_range_data数据失败:%s", err)
  343 + return protocol.NewErrWithMessage("1")
  344 + }
  345 + }
  346 + o.Commit()
  347 + return nil
  348 +}
  349 +
  350 +func GetRankRangeInfo(id int64) protocol.ResponseRankRangeInfo {
  351 + var (
  352 + rankRange *models.RankRange
  353 + rankRangeData []models.RankRangeData
  354 + err error
  355 + )
  356 + rspdata := protocol.ResponseRankRangeInfo{
  357 + Relation: make([]protocol.RankRangeRelation, 0),
  358 + }
  359 + rankRange, err = models.GetRankRangeById(id)
  360 + if err != nil {
  361 + log.Error("获取rank_range数据失败:%s", err)
  362 + return rspdata
  363 + }
  364 + rspdata.Id = rankRange.Id
  365 + rspdata.Name = rankRange.Name
  366 + rspdata.RangeType = rankRange.Type
  367 + rankRangeData, _ = models.GetRankRangeDataByRangeId(id)
  368 + var relationIds []int64
  369 + for i := range rankRangeData {
  370 + relationIds = append(relationIds, rankRangeData[i].RelationId)
  371 + }
  372 + switch rankRange.Type {
  373 + case models.RANK_RANGE_TYPE_DEPARTMENT, models.RANK_RANGE_TYPE_DEPARTMENTALL:
  374 + //员工
  375 + case models.RANK_RANGE_TYPE_EMPLAYEE, models.RANK_RANGE_TYPE_EMPLAYEEALL:
  376 + //部门
  377 + }
  378 + return rspdata
220 379
221 } 380 }