作者 tangxvhui

提交保存

  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "oppmg/common/log"
  6 + "oppmg/protocol"
  7 + serveachievement "oppmg/services/achievement"
  8 +)
  9 +
  10 +type AchievementController struct {
  11 + BaseController
  12 +}
  13 +
  14 +//List 成果列表
  15 +//@router /achievement/list
  16 +func (c AchievementController) List() {
  17 + var msg *protocol.ResponseMessage
  18 + defer func() {
  19 + c.ResposeJson(msg)
  20 + }()
  21 + type Parameter struct {
  22 + protocol.RequestPageInfo
  23 + Status int `json:"status"`
  24 + }
  25 + var param Parameter
  26 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  27 + log.Error("json 解析失败 err:%s", err)
  28 + msg = protocol.BadRequestParam("1")
  29 + return
  30 + }
  31 + companyid := c.GetCompanyId()
  32 + rspdata := serveachievement.GetAchievementList(param.PageIndex, param.PageSize, companyid, param.Status)
  33 + msg = protocol.NewReturnResponse(rspdata, nil)
  34 + return
  35 +}
@@ -191,12 +191,14 @@ func (c RankController) RankSeasonEdit() { @@ -191,12 +191,14 @@ func (c RankController) RankSeasonEdit() {
191 ) 191 )
192 t1, err := time.ParseInLocation("2006-01-02", param.BeginTime, time.Local) 192 t1, err := time.ParseInLocation("2006-01-02", param.BeginTime, time.Local)
193 if err != nil { 193 if err != nil {
  194 + log.Error(err.Error())
194 msg = protocol.BadRequestParam("1") 195 msg = protocol.BadRequestParam("1")
195 return 196 return
196 } 197 }
197 beginTime = t1.Unix() 198 beginTime = t1.Unix()
198 t2, err := time.ParseInLocation("2006-01-02", param.EndTime, time.Local) 199 t2, err := time.ParseInLocation("2006-01-02", param.EndTime, time.Local)
199 if err != nil { 200 if err != nil {
  201 + log.Error(err.Error())
200 msg = protocol.BadRequestParam("1") 202 msg = protocol.BadRequestParam("1")
201 return 203 return
202 } 204 }
1 package models 1 package models
2 2
3 import ( 3 import (
4 - "errors"  
5 "fmt" 4 "fmt"
6 - "reflect"  
7 - "strings"  
8 "time" 5 "time"
9 6
10 "github.com/astaxie/beego/orm" 7 "github.com/astaxie/beego/orm"
11 ) 8 )
12 9
13 type AchievementChance struct { 10 type AchievementChance struct {
14 - Id int `orm:"column(id);pk"` 11 + Id int64 `orm:"column(id);pk"`
15 AchievementId int64 `orm:"column(achievement_id);null" description:"成果编号 表achievement.id"` 12 AchievementId int64 `orm:"column(achievement_id);null" description:"成果编号 表achievement.id"`
16 ChanceId int64 `orm:"column(chance_id);null" description:"机会编号 表chance.id"` 13 ChanceId int64 `orm:"column(chance_id);null" description:"机会编号 表chance.id"`
17 ChanceCode string `orm:"column(chance_code);size(255);null" description:"机会编号 表chance.code"` 14 ChanceCode string `orm:"column(chance_code);size(255);null" description:"机会编号 表chance.code"`
@@ -36,7 +33,7 @@ func AddAchievementChance(m *AchievementChance) (id int64, err error) { @@ -36,7 +33,7 @@ func AddAchievementChance(m *AchievementChance) (id int64, err error) {
36 33
37 // GetAchievementChanceById retrieves AchievementChance by Id. Returns error if 34 // GetAchievementChanceById retrieves AchievementChance by Id. Returns error if
38 // Id doesn't exist 35 // Id doesn't exist
39 -func GetAchievementChanceById(id int) (v *AchievementChance, err error) { 36 +func GetAchievementChanceById(id int64) (v *AchievementChance, err error) {
40 o := orm.NewOrm() 37 o := orm.NewOrm()
41 v = &AchievementChance{Id: id} 38 v = &AchievementChance{Id: id}
42 if err = o.Read(v); err == nil { 39 if err = o.Read(v); err == nil {
@@ -45,84 +42,6 @@ func GetAchievementChanceById(id int) (v *AchievementChance, err error) { @@ -45,84 +42,6 @@ func GetAchievementChanceById(id int) (v *AchievementChance, err error) {
45 return nil, err 42 return nil, err
46 } 43 }
47 44
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 45 // UpdateAchievementChance updates AchievementChance by Id and returns error if
127 // the record to be updated doesn't exist 46 // the record to be updated doesn't exist
128 func UpdateAchievementChanceById(m *AchievementChance) (err error) { 47 func UpdateAchievementChanceById(m *AchievementChance) (err error) {
@@ -140,7 +59,7 @@ func UpdateAchievementChanceById(m *AchievementChance) (err error) { @@ -140,7 +59,7 @@ func UpdateAchievementChanceById(m *AchievementChance) (err error) {
140 59
141 // DeleteAchievementChance deletes AchievementChance by Id and returns error if 60 // DeleteAchievementChance deletes AchievementChance by Id and returns error if
142 // the record to be deleted doesn't exist 61 // the record to be deleted doesn't exist
143 -func DeleteAchievementChance(id int) (err error) { 62 +func DeleteAchievementChance(id int64) (err error) {
144 o := orm.NewOrm() 63 o := orm.NewOrm()
145 v := AchievementChance{Id: id} 64 v := AchievementChance{Id: id}
146 // ascertain id exists in the database 65 // ascertain id exists in the database
1 package models 1 package models
2 2
3 import ( 3 import (
4 - "errors"  
5 "fmt" 4 "fmt"
6 - "reflect"  
7 - "strings"  
8 "time" 5 "time"
9 6
10 "github.com/astaxie/beego/orm" 7 "github.com/astaxie/beego/orm"
11 ) 8 )
12 9
13 type AchievementProvider struct { 10 type AchievementProvider struct {
14 - Id int `orm:"column(id);pk" description:"主键id"` 11 + Id int64 `orm:"column(id);pk" description:"主键id"`
15 AchievementId int64 `orm:"column(achievement_id);null" description:"表achievement.id"` 12 AchievementId int64 `orm:"column(achievement_id);null" description:"表achievement.id"`
16 UserCompanyId int64 `orm:"column(user_company_id);null" description:"user_company.id"` 13 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:"把握人得分"` 14 UserGraspScore float64 `orm:"column(user_grasp_score);null;digits(4);decimals(1)" description:"把握人得分"`
@@ -36,7 +33,7 @@ func AddAchievementProvider(m *AchievementProvider) (id int64, err error) { @@ -36,7 +33,7 @@ func AddAchievementProvider(m *AchievementProvider) (id int64, err error) {
36 33
37 // GetAchievementProviderById retrieves AchievementProvider by Id. Returns error if 34 // GetAchievementProviderById retrieves AchievementProvider by Id. Returns error if
38 // Id doesn't exist 35 // Id doesn't exist
39 -func GetAchievementProviderById(id int) (v *AchievementProvider, err error) { 36 +func GetAchievementProviderById(id int64) (v *AchievementProvider, err error) {
40 o := orm.NewOrm() 37 o := orm.NewOrm()
41 v = &AchievementProvider{Id: id} 38 v = &AchievementProvider{Id: id}
42 if err = o.Read(v); err == nil { 39 if err = o.Read(v); err == nil {
@@ -45,84 +42,6 @@ func GetAchievementProviderById(id int) (v *AchievementProvider, err error) { @@ -45,84 +42,6 @@ func GetAchievementProviderById(id int) (v *AchievementProvider, err error) {
45 return nil, err 42 return nil, err
46 } 43 }
47 44
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 45 // UpdateAchievementProvider updates AchievementProvider by Id and returns error if
127 // the record to be updated doesn't exist 46 // the record to be updated doesn't exist
128 func UpdateAchievementProviderById(m *AchievementProvider) (err error) { 47 func UpdateAchievementProviderById(m *AchievementProvider) (err error) {
@@ -140,7 +59,7 @@ func UpdateAchievementProviderById(m *AchievementProvider) (err error) { @@ -140,7 +59,7 @@ func UpdateAchievementProviderById(m *AchievementProvider) (err error) {
140 59
141 // DeleteAchievementProvider deletes AchievementProvider by Id and returns error if 60 // DeleteAchievementProvider deletes AchievementProvider by Id and returns error if
142 // the record to be deleted doesn't exist 61 // the record to be deleted doesn't exist
143 -func DeleteAchievementProvider(id int) (err error) { 62 +func DeleteAchievementProvider(id int64) (err error) {
144 o := orm.NewOrm() 63 o := orm.NewOrm()
145 v := AchievementProvider{Id: id} 64 v := AchievementProvider{Id: id}
146 // ascertain id exists in the database 65 // ascertain id exists in the database
@@ -156,8 +156,8 @@ func GetUserCompanyReal(ids []int64) ([]UserCompany, error) { @@ -156,8 +156,8 @@ func GetUserCompanyReal(ids []int64) ([]UserCompany, error) {
156 func GetUserCompanyAll(companyId int64) (v []*UserCompany, err error) { 156 func GetUserCompanyAll(companyId int64) (v []*UserCompany, err error) {
157 o := orm.NewOrm() 157 o := orm.NewOrm()
158 sql := `select a.*,b.nick_name from ( 158 sql := `select a.*,b.nick_name from (
159 -select id,user_id from user_company where company_id=? and enable=1  
160 -)a inner join user b on a.user_id = b.id` 159 + select id,user_id from user_company where company_id=? and enable=1
  160 + )a inner join user b on a.user_id = b.id`
161 if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil { 161 if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil {
162 return v, nil 162 return v, nil
163 } 163 }
  1 +package protocol
  2 +
  3 +//RequestAddAchievement 添加成果
  4 +type RequestAddAchievement struct {
  5 + ChanceData []AchievementChance `json:"chance_data"`
  6 + TypeA int `json:"type_a"` //机会一级分类 chance_type
  7 + TypeB int `json:"type_b"` //机会二级分类
  8 + DepartmentId int64 `json:"department_id"` //把握人的部门
  9 + UserCompanyId int64 `json:"user_company_id"` //把握人的id
  10 + GraspScore int `json:"grasp_score"` //把握分
  11 + UserGraspScore int `json:"user_grasp_score"` //把握人总得分
  12 + Provider []AchievementProvider `json:"provider"` //机会提供者
  13 + SourceContent string `json:"source_content"` //成果描述文本
  14 + Images []string `json:"image"` //图片
  15 +}
  16 +
  17 +//ProviderData 成果提供者
  18 +type AchievementProvider struct {
  19 + UserCompanyId int64 `json:"user_company_id"` //用户的id
  20 + UserName string `json:"user_name"` //用户名称
  21 + DepartmentId int64 `json:"department_id"` //部门id
  22 + UserGraspScore int64 `json:"user_grasp_score"` //把握人得分
  23 +}
  24 +
  25 +//AchievementChance 成果的机会列表
  26 +type AchievementChance struct {
  27 + Id int64 `json:"id"`
  28 + Code string `json:"code"`
  29 +}
  30 +
  31 +// ResponseRankSeasonList 赛季列表
  32 +type AchievementList struct {
  33 + ResponsePageInfo
  34 + List []AchievementListItem `json:"lists"`
  35 +}
  36 +
  37 +//AchievementListItem 成果列表
  38 +type AchievementListItem struct {
  39 + Id int64 `json:"id"`
  40 + CreateTime string `json:"create_time"`
  41 + TypeA string `json:"type_a"`
  42 + TypeB string `json:"type_b"`
  43 + GraspScore string `json:"grasp_score"`
  44 + Status int `json:"status"`
  45 + UserGrasp string `json:"user_grasp"`
  46 +}
@@ -26,6 +26,8 @@ type RankRangeItem struct { @@ -26,6 +26,8 @@ type RankRangeItem struct {
26 Id int64 `json:"id" orm:"column(id)"` 26 Id int64 `json:"id" orm:"column(id)"`
27 Name string `json:"name" orm:"column(name)"` 27 Name string `json:"name" orm:"column(name)"`
28 RangeType int8 `json:"range_type" orm:"column(type)"` 28 RangeType int8 `json:"range_type" orm:"column(type)"`
  29 + Status int8 `json:"status" orm:"column(status)"`
  30 + RangeData string `json:"range_data" orm:"-"`
29 } 31 }
30 32
31 //ResponseRankRangeInfo 赛季参与人详情 33 //ResponseRankRangeInfo 赛季参与人详情
@@ -120,7 +120,9 @@ func init() { @@ -120,7 +120,9 @@ func init() {
120 beego.NSRouter("/item/list", &controllers.RankController{}, "post:RankItemList"), 120 beego.NSRouter("/item/list", &controllers.RankController{}, "post:RankItemList"),
121 beego.NSRouter("/item/edit", &controllers.RankController{}, "post:RankItemEdit"), 121 beego.NSRouter("/item/edit", &controllers.RankController{}, "post:RankItemEdit"),
122 ), 122 ),
123 - beego.NSNamespace("/achievement"), 123 + beego.NSNamespace("/achievement",
  124 + beego.NSRouter("/list", &controllers.AchievementController{}, "post:List"),
  125 + ),
124 ) 126 )
125 127
126 nsAuth := beego.NewNamespace("/auth", 128 nsAuth := beego.NewNamespace("/auth",
  1 +package achievement
  2 +
  3 +import (
  4 + "fmt"
  5 + "oppmg/common/log"
  6 + "oppmg/models"
  7 + "oppmg/protocol"
  8 + "oppmg/utils"
  9 +)
  10 +
  11 +func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) error {
  12 +
  13 + //操作achievement 成果表
  14 + //操作 achievement_chance 机会来源表
  15 + //操作achievement_provider 成果提供人表
  16 +
  17 + return nil
  18 +}
  19 +
  20 +func EditAchievement() error {
  21 + return nil
  22 +}
  23 +
  24 +func GetAchievementList(pageIndex int, pageSize int, companyId int64, status int) protocol.AchievementList {
  25 + dataSql := `SELECT a.id,a.chance_type_id,a.grasp_score,user_company_id
  26 + ,a.create_at,a.status,a.audit_template_id
  27 + FROM achievement AS a WHERE a.company_id=? `
  28 + countSql := ` SELECT COUNT(*) FROM achievement AS a WHERE a.company_id=? `
  29 + pageStart := (pageIndex - 1) * pageSize
  30 + cond := []interface{}{companyId}
  31 + if status > 0 {
  32 + dataSql += ` AND a.status=? `
  33 + countSql += ` AND a.status=? `
  34 + cond = append(cond, status)
  35 + } else {
  36 + dataSql += ` AND a.status>0 `
  37 + countSql += ` AND a.status>0 `
  38 + }
  39 + dataSql = fmt.Sprintf("%s ORDER BY a.create_at LIMIT %d,%d", dataSql, pageStart, pageSize)
  40 + type SqlData struct {
  41 + Id int64 `orm:"column(id)"`
  42 + ChanceTypeId int `orm:"column(chance_type_id)"`
  43 + GraspScore string `orm:"column(grasp_score)"`
  44 + UserCompanyId int64 `orm:"column(user_company_id)"`
  45 + CreateAt string `orm:"column(create_at)"`
  46 + Status int `orm:"column(status)"`
  47 + AuditTemplateId int64 `orm:"column(audit_template_id)"`
  48 + }
  49 + var (
  50 + sqldata []SqlData
  51 + cnt int
  52 + err error
  53 + )
  54 + rspData := protocol.AchievementList{
  55 + ResponsePageInfo: protocol.ResponsePageInfo{
  56 + TotalPage: 0, CurrentPage: pageIndex,
  57 + },
  58 + List: make([]protocol.AchievementListItem, 0),
  59 + }
  60 + err = utils.ExecuteQueryOne(&cnt, countSql, cond...)
  61 + if err != nil {
  62 + log.Error("SQL EXECUTE ERR:%s", err)
  63 + return rspData
  64 + }
  65 + if cnt == 0 {
  66 + return rspData
  67 + }
  68 + err = utils.ExecuteQueryOne(&sqldata, dataSql, cond...)
  69 + if err != nil {
  70 + log.Error("SQL EXECUTE ERR:%s", err)
  71 + return rspData
  72 + }
  73 + for i := range sqldata {
  74 + m := protocol.AchievementListItem{
  75 + Id: sqldata[i].Id,
  76 + CreateTime: sqldata[i].CreateAt,
  77 + GraspScore: sqldata[i].GraspScore,
  78 + Status: sqldata[i].Status,
  79 + }
  80 + var (
  81 + chanceTypeA *models.ChanceType //一级分类
  82 + chanceTypeB *models.AuditTemplate //二级分类
  83 + usercompany *models.UserCompany
  84 + err error
  85 + )
  86 + chanceTypeA, err = models.GetChanceTypeById(sqldata[i].ChanceTypeId)
  87 + if err == nil {
  88 + m.TypeA = chanceTypeA.Name
  89 + } else {
  90 + log.Error(err.Error())
  91 + }
  92 + chanceTypeB, err = models.GetAuditTemplateById(sqldata[i].AuditTemplateId)
  93 + if err == nil {
  94 + m.TypeB = chanceTypeB.Name
  95 + } else {
  96 + log.Error(err.Error())
  97 + }
  98 + usercompany, err = models.GetUserCompanyById(sqldata[i].UserCompanyId)
  99 + if err == nil {
  100 + usr, err := models.GetUserById(usercompany.UserId)
  101 + if err == nil {
  102 + m.UserGrasp = usr.NickName
  103 + } else {
  104 + log.Error(err.Error())
  105 + }
  106 + } else {
  107 + log.Error(err.Error())
  108 + }
  109 + rspData.List = append(rspData.List, m)
  110 + }
  111 +
  112 + return rspData
  113 +}
@@ -7,6 +7,7 @@ import ( @@ -7,6 +7,7 @@ import (
7 "oppmg/protocol" 7 "oppmg/protocol"
8 "oppmg/utils" 8 "oppmg/utils"
9 "sort" 9 "sort"
  10 + "strings"
10 "time" 11 "time"
11 12
12 "github.com/astaxie/beego/orm" 13 "github.com/astaxie/beego/orm"
@@ -252,14 +253,61 @@ func GetRankRangeList(companyid int64) []protocol.RankRangeItem { @@ -252,14 +253,61 @@ func GetRankRangeList(companyid int64) []protocol.RankRangeItem {
252 err error 253 err error
253 rspData = make([]protocol.RankRangeItem, 0) 254 rspData = make([]protocol.RankRangeItem, 0)
254 ) 255 )
255 - datasql := `SELECT a.id ,a.name,a.type FROM rank_range AS a WHERE company_id=?` 256 + datasql := `SELECT a.id ,a.name,a.type,a.status FROM rank_range AS a WHERE company_id=?`
256 err = utils.ExecuteQueryAll(&rspData, datasql, companyid) 257 err = utils.ExecuteQueryAll(&rspData, datasql, companyid)
257 if err != nil { 258 if err != nil {
258 log.Error("获取参与人列表失败:%s", err) 259 log.Error("获取参与人列表失败:%s", err)
259 } 260 }
  261 + for i := range rspData {
  262 + var nameList []string
  263 + relations := getRangeDataRelationLsit(rspData[i].Id, rspData[i].RangeType)
  264 + for ii := range relations {
  265 + nameList = append(nameList, relations[ii].Name)
  266 + }
  267 + rspData[i].RangeData = strings.Join(nameList, ",")
  268 + }
260 return rspData 269 return rspData
261 } 270 }
262 271
  272 +//getRangeDataLsit 获取range_data的数据
  273 +func getRangeDataRelationLsit(rankRangeId int64, rangeType int8) []protocol.RankRangeRelation {
  274 + rankRangeData, _ := models.GetRankRangeDataByRangeId(rankRangeId)
  275 + var relationIds []int64
  276 + for i := range rankRangeData {
  277 + relationIds = append(relationIds, rankRangeData[i].RelationId)
  278 + }
  279 + datalist := make([]protocol.RankRangeRelation, 0)
  280 + switch rangeType {
  281 + case models.RANK_RANGE_TYPE_DEPARTMENT:
  282 + //员工
  283 + users, err := models.GetUserCompanyByIds(relationIds)
  284 + if err != nil {
  285 + log.Error("获取员工数据失败")
  286 + }
  287 + for i := range users {
  288 + m := protocol.RankRangeRelation{
  289 + Id: users[i].Id,
  290 + Name: users[i].NickName,
  291 + }
  292 + datalist = append(datalist, m)
  293 + }
  294 + case models.RANK_RANGE_TYPE_EMPLAYEE:
  295 + //部门
  296 + departments, err := models.GetDepartmentByIds(relationIds)
  297 + if err != nil {
  298 + log.Error("获取部门数据失败")
  299 + }
  300 + for i := range departments {
  301 + m := protocol.RankRangeRelation{
  302 + Id: departments[i].Id,
  303 + Name: departments[i].Name,
  304 + }
  305 + datalist = append(datalist, m)
  306 + }
  307 + }
  308 + return datalist
  309 +}
  310 +
263 func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []int64, companyid int64) error { 311 func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []int64, companyid int64) error {
264 var ( 312 var (
265 rankRangeDatas []models.RankRangeData 313 rankRangeDatas []models.RankRangeData