正在显示
7 个修改的文件
包含
265 行增加
和
135 行删除
@@ -11,9 +11,9 @@ type AchievementController struct { | @@ -11,9 +11,9 @@ type AchievementController struct { | ||
11 | BaseController | 11 | BaseController |
12 | } | 12 | } |
13 | 13 | ||
14 | -//List 成果列表 | 14 | +//AchievementList 成果列表 |
15 | //@router /achievement/list | 15 | //@router /achievement/list |
16 | -func (c AchievementController) List() { | 16 | +func (c AchievementController) AchievementList() { |
17 | var msg *protocol.ResponseMessage | 17 | var msg *protocol.ResponseMessage |
18 | defer func() { | 18 | defer func() { |
19 | c.ResposeJson(msg) | 19 | c.ResposeJson(msg) |
@@ -33,3 +33,43 @@ func (c AchievementController) List() { | @@ -33,3 +33,43 @@ func (c AchievementController) List() { | ||
33 | msg = protocol.NewReturnResponse(rspdata, nil) | 33 | msg = protocol.NewReturnResponse(rspdata, nil) |
34 | return | 34 | return |
35 | } | 35 | } |
36 | + | ||
37 | +//AddAchievement 添加成果列表 | ||
38 | +//@router /achievement/add | ||
39 | +func (c AchievementController) AddAchievement() { | ||
40 | + var msg *protocol.ResponseMessage | ||
41 | + defer func() { | ||
42 | + c.ResposeJson(msg) | ||
43 | + }() | ||
44 | + | ||
45 | + var param protocol.RequestAddAchievement | ||
46 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
47 | + log.Error("json 解析失败 err:%s", err) | ||
48 | + msg = protocol.BadRequestParam("1") | ||
49 | + return | ||
50 | + } | ||
51 | + companyid := c.GetCompanyId() | ||
52 | + err := serveachievement.AddAchievement(¶m, companyid) | ||
53 | + msg = protocol.NewReturnResponse(nil, err) | ||
54 | + return | ||
55 | +} | ||
56 | + | ||
57 | +//EditAchievement 编辑成果 | ||
58 | +//@router /achievement/edit | ||
59 | +func (c AchievementController) EditAchievement() { | ||
60 | + var msg *protocol.ResponseMessage | ||
61 | + defer func() { | ||
62 | + c.ResposeJson(msg) | ||
63 | + }() | ||
64 | + | ||
65 | + var param protocol.RequestEditAchievement | ||
66 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
67 | + log.Error("json 解析失败 err:%s", err) | ||
68 | + msg = protocol.BadRequestParam("1") | ||
69 | + return | ||
70 | + } | ||
71 | + companyid := c.GetCompanyId() | ||
72 | + err := serveachievement.EditAchievement(¶m, companyid) | ||
73 | + msg = protocol.NewReturnResponse(nil, err) | ||
74 | + return | ||
75 | +} |
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 Achievement struct { | 11 | type Achievement struct { |
14 | - Id int `orm:"column(id);pk" description:"id 主键"` | 12 | + Id int64 `orm:"column(id);auto" description:"id 主键"` |
15 | CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"` | 13 | CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"` |
16 | DepartmentId int64 `orm:"column(department_id);null" description:"表department.id 部门id (创建成果指定的部门)"` | 14 | DepartmentId int64 `orm:"column(department_id);null" description:"表department.id 部门id (创建成果指定的部门)"` |
17 | UserCompanyId int64 `orm:"column(user_company_id)" description:"把握人 表user_company.id id"` | 15 | UserCompanyId int64 `orm:"column(user_company_id)" description:"把握人 表user_company.id id"` |
@@ -39,15 +37,20 @@ func init() { | @@ -39,15 +37,20 @@ func init() { | ||
39 | 37 | ||
40 | // AddAchievement insert a new Achievement into database and returns | 38 | // AddAchievement insert a new Achievement into database and returns |
41 | // last inserted Id on success. | 39 | // last inserted Id on success. |
42 | -func AddAchievement(m *Achievement) (id int64, err error) { | ||
43 | - o := orm.NewOrm() | 40 | +func AddAchievement(m *Achievement, om ...orm.Ormer) (id int64, err error) { |
41 | + var o orm.Ormer | ||
42 | + if len(om) > 0 { | ||
43 | + o = om[0] | ||
44 | + } else { | ||
45 | + o = orm.NewOrm() | ||
46 | + } | ||
44 | id, err = o.Insert(m) | 47 | id, err = o.Insert(m) |
45 | return | 48 | return |
46 | } | 49 | } |
47 | 50 | ||
48 | // GetAchievementById retrieves Achievement by Id. Returns error if | 51 | // GetAchievementById retrieves Achievement by Id. Returns error if |
49 | // Id doesn't exist | 52 | // Id doesn't exist |
50 | -func GetAchievementById(id int) (v *Achievement, err error) { | 53 | +func GetAchievementById(id int64) (v *Achievement, err error) { |
51 | o := orm.NewOrm() | 54 | o := orm.NewOrm() |
52 | v = &Achievement{Id: id} | 55 | v = &Achievement{Id: id} |
53 | if err = o.Read(v); err == nil { | 56 | if err = o.Read(v); err == nil { |
@@ -56,102 +59,30 @@ func GetAchievementById(id int) (v *Achievement, err error) { | @@ -56,102 +59,30 @@ func GetAchievementById(id int) (v *Achievement, err error) { | ||
56 | return nil, err | 59 | return nil, err |
57 | } | 60 | } |
58 | 61 | ||
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 | - } | 62 | +// UpdateAchievement updates Achievement by Id and returns error if |
63 | +// the record to be updated doesn't exist | ||
64 | +func UpdateAchievementById(m *Achievement, cols []string, om ...orm.Ormer) (err error) { | ||
65 | + var o orm.Ormer | ||
66 | + if len(om) > 0 { | ||
67 | + o = om[0] | ||
108 | } else { | 68 | } else { |
109 | - if len(order) != 0 { | ||
110 | - return nil, errors.New("Error: unused 'order' fields") | ||
111 | - } | 69 | + o = orm.NewOrm() |
112 | } | 70 | } |
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 | 71 | + m.UpdateAt = time.Now() |
72 | + if len(cols) > 0 { | ||
73 | + cols = append(cols, "UpdateAt") | ||
133 | } | 74 | } |
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 | - } | 75 | + var num int64 |
76 | + if num, err = o.Update(m, cols...); err == nil { | ||
77 | + log.Info("Number of records updated in database:", num) | ||
148 | } | 78 | } |
79 | + | ||
149 | return | 80 | return |
150 | } | 81 | } |
151 | 82 | ||
152 | // DeleteAchievement deletes Achievement by Id and returns error if | 83 | // DeleteAchievement deletes Achievement by Id and returns error if |
153 | // the record to be deleted doesn't exist | 84 | // the record to be deleted doesn't exist |
154 | -func DeleteAchievement(id int) (err error) { | 85 | +func DeleteAchievement(id int64) (err error) { |
155 | o := orm.NewOrm() | 86 | o := orm.NewOrm() |
156 | v := Achievement{Id: id} | 87 | v := Achievement{Id: id} |
157 | // ascertain id exists in the database | 88 | // ascertain id exists in the database |
1 | package protocol | 1 | package protocol |
2 | 2 | ||
3 | +//ProviderData 成果提供者 | ||
4 | +type AchievementProvider struct { | ||
5 | + UserCompanyId int64 `json:"user_company_id"` //用户的id | ||
6 | + UserName string `json:"user_name"` //用户名称 | ||
7 | + DepartmentId int64 `json:"department_id"` //部门id | ||
8 | + UserGraspScore float64 `json:"user_grasp_score"` //把握人得分 | ||
9 | +} | ||
10 | + | ||
11 | +//AchievementChance 成果的机会列表 | ||
12 | +type AchievementChance struct { | ||
13 | + Id int64 `json:"id"` | ||
14 | + Code string `json:"code"` | ||
15 | +} | ||
16 | + | ||
3 | //RequestAddAchievement 添加成果 | 17 | //RequestAddAchievement 添加成果 |
4 | type RequestAddAchievement struct { | 18 | type RequestAddAchievement struct { |
5 | ChanceData []AchievementChance `json:"chance_data"` | 19 | ChanceData []AchievementChance `json:"chance_data"` |
@@ -14,18 +28,19 @@ type RequestAddAchievement struct { | @@ -14,18 +28,19 @@ type RequestAddAchievement struct { | ||
14 | Images []string `json:"image"` //图片 | 28 | Images []string `json:"image"` //图片 |
15 | } | 29 | } |
16 | 30 | ||
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"` | 31 | +//RequestAddAchievement 添加成果 |
32 | +type RequestEditAchievement struct { | ||
33 | + AchievementId int64 `json:"achievement_id"` | ||
34 | + ChanceData []AchievementChance `json:"chance_data"` | ||
35 | + TypeIdA int `json:"type_id_a"` //机会一级分类 chance_type | ||
36 | + TypeIdB int `json:"type_id_b"` //机会二级分类 | ||
37 | + DepartmentId int64 `json:"department_id"` //把握人的部门 | ||
38 | + UserCompanyId int64 `json:"user_company_id"` //把握人的id | ||
39 | + GraspScore float64 `json:"grasp_score"` //把握分 | ||
40 | + UserGraspScore float64 `json:"user_grasp_score"` //把握人总得分 | ||
41 | + Provider []AchievementProvider `json:"provider"` //机会提供者 | ||
42 | + SourceContent string `json:"source_content"` //成果描述文本 | ||
43 | + Images []string `json:"image"` //图片 | ||
29 | } | 44 | } |
30 | 45 | ||
31 | // ResponseRankSeasonList 赛季列表 | 46 | // ResponseRankSeasonList 赛季列表 |
@@ -21,13 +21,22 @@ type RankSeasonItem struct { | @@ -21,13 +21,22 @@ type RankSeasonItem struct { | ||
21 | Status int8 `json:"status" orm:"column(status)"` | 21 | Status int8 `json:"status" orm:"column(status)"` |
22 | } | 22 | } |
23 | 23 | ||
24 | -//RankRangeItem 赛季参与人列表项 | ||
25 | -type RankRangeItem struct { | 24 | +//RankRangeListItem 赛季参与人列表项 |
25 | +type RankRangeListItem 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)"` | 29 | Status int8 `json:"status" orm:"column(status)"` |
30 | RangeData string `json:"range_data" orm:"-"` | 30 | RangeData string `json:"range_data" orm:"-"` |
31 | + SortNum int `json:"sort_num"` | ||
32 | +} | ||
33 | + | ||
34 | +type RankRangeList []RankRangeListItem | ||
35 | + | ||
36 | +func (a RankRangeList) Len() int { return len(a) } | ||
37 | +func (a RankRangeList) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | ||
38 | +func (a RankRangeList) Less(i, j int) bool { | ||
39 | + return a[i].SortNum < a[j].SortNum | ||
31 | } | 40 | } |
32 | 41 | ||
33 | //ResponseRankRangeInfo 赛季参与人详情 | 42 | //ResponseRankRangeInfo 赛季参与人详情 |
@@ -121,7 +121,9 @@ func init() { | @@ -121,7 +121,9 @@ func init() { | ||
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"), | 124 | + beego.NSRouter("/list", &controllers.AchievementController{}, "post:AchievementList"), |
125 | + beego.NSRouter("/add", &controllers.AchievementController{}, "post:AddAchievement"), | ||
126 | + beego.NSRouter("/edit", &controllers.AchievementController{}, "post:EditAchievement"), | ||
125 | ), | 127 | ), |
126 | ) | 128 | ) |
127 | 129 |
1 | package achievement | 1 | package achievement |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "encoding/json" | ||
4 | "fmt" | 5 | "fmt" |
5 | "oppmg/common/log" | 6 | "oppmg/common/log" |
6 | "oppmg/models" | 7 | "oppmg/models" |
7 | "oppmg/protocol" | 8 | "oppmg/protocol" |
8 | "oppmg/utils" | 9 | "oppmg/utils" |
10 | + "time" | ||
11 | + | ||
12 | + "github.com/astaxie/beego/orm" | ||
9 | ) | 13 | ) |
10 | 14 | ||
11 | -func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) error { | ||
12 | - // var ( | ||
13 | - // achievementData *models.Achievement | ||
14 | - // chanceList []models.AchievementChance | ||
15 | - // providerList []models.AchievementProvider | ||
16 | - // err error | ||
17 | - // ) | ||
18 | - // imgData, | ||
19 | - // //操作achievement 成果表 | ||
20 | - // achievementData = &models.Achievement{ | ||
21 | - // CompanyId: companyid, | ||
22 | - // DepartmentId: addData.DepartmentId, | ||
23 | - // UserCompanyId: addData.UserCompanyId, | ||
24 | - // ChanceTypeId: addData.TypeIdA, | ||
25 | - // AuditTemplateId: addData.TypeIdB, | ||
26 | - // SourceContent: addData.SourceContent, | ||
27 | - // GraspScore: addData.GraspScore, | ||
28 | - // UserGraspScore: addData.UserGraspScore, | ||
29 | - // } | 15 | +//addAchievementProvider 操作achievement_provider 成果提供人表 |
16 | +func addAchievementProvider(addData []protocol.AchievementProvider, achievementId int64, om orm.Ormer) error { | ||
17 | + var ( | ||
18 | + providerList []models.AchievementProvider | ||
19 | + err error | ||
20 | + ) | ||
21 | + nowTime := time.Now() | ||
22 | + for _, v := range addData { | ||
23 | + m := models.AchievementProvider{ | ||
24 | + AchievementId: achievementId, | ||
25 | + UserCompanyId: v.UserCompanyId, | ||
26 | + UserGraspScore: v.UserGraspScore, | ||
27 | + CreateAt: nowTime, | ||
28 | + } | ||
29 | + providerList = append(providerList, m) | ||
30 | + } | ||
31 | + _, err = om.InsertMulti(10, providerList) | ||
32 | + return err | ||
33 | +} | ||
30 | 34 | ||
35 | +//addAchievementChance 操作 achievement_chance 机会来源表 | ||
36 | +func addAchievementChance(addData []protocol.AchievementChance, achievementId int64, om orm.Ormer) error { | ||
37 | + var ( | ||
38 | + chanceList []models.AchievementChance | ||
39 | + err error | ||
40 | + ) | ||
41 | + nowTime := time.Now() | ||
42 | + for _, v := range addData { | ||
43 | + m := models.AchievementChance{ | ||
44 | + AchievementId: achievementId, | ||
45 | + ChanceId: v.Id, | ||
46 | + ChanceCode: v.Code, | ||
47 | + CreateAt: nowTime, | ||
48 | + } | ||
49 | + chanceList = append(chanceList, m) | ||
50 | + } | ||
51 | + _, err = om.InsertMulti(10, chanceList) | ||
52 | + return err | ||
53 | +} | ||
54 | + | ||
55 | +//AddAchievement 添加成果 | ||
56 | +func AddAchievement(addData *protocol.RequestAddAchievement, companyid int64) error { | ||
57 | + var ( | ||
58 | + achievementData *models.Achievement | ||
59 | + err error | ||
60 | + ) | ||
61 | + nowTime := time.Now() | ||
62 | + achievementData = &models.Achievement{ | ||
63 | + CompanyId: companyid, | ||
64 | + DepartmentId: addData.DepartmentId, | ||
65 | + UserCompanyId: addData.UserCompanyId, | ||
66 | + ChanceTypeId: addData.TypeIdA, | ||
67 | + AuditTemplateId: addData.TypeIdB, | ||
68 | + SourceContent: addData.SourceContent, | ||
69 | + GraspScore: addData.GraspScore, | ||
70 | + UserGraspScore: addData.UserGraspScore, | ||
71 | + CreateAt: nowTime, | ||
72 | + UpdateAt: nowTime, | ||
73 | + } | ||
74 | + if imgData, err := json.Marshal(addData.Images); err == nil { | ||
75 | + achievementData.Images = string(imgData) | ||
76 | + } else { | ||
77 | + achievementData.Images = "[]" | ||
78 | + } | ||
79 | + o := orm.NewOrm() | ||
80 | + o.Begin() | ||
81 | + //操作achievement 成果表 | ||
82 | + achievementId, err := models.AddAchievement(achievementData, o) | ||
83 | + if err != nil { | ||
84 | + log.Error("添加Achievement数据失败:%s", err) | ||
85 | + o.Rollback() | ||
86 | + return protocol.NewErrWithMessage("1") | ||
87 | + } | ||
31 | //操作 achievement_chance 机会来源表 | 88 | //操作 achievement_chance 机会来源表 |
89 | + err = addAchievementChance(addData.ChanceData, achievementId, o) | ||
90 | + if err != nil { | ||
91 | + log.Error("添加achievement_chance失败:%s", err) | ||
92 | + o.Rollback() | ||
93 | + return protocol.NewErrWithMessage("1") | ||
94 | + } | ||
32 | //操作achievement_provider 成果提供人表 | 95 | //操作achievement_provider 成果提供人表 |
33 | - | 96 | + err = addAchievementProvider(addData.Provider, achievementId, o) |
97 | + if err != nil { | ||
98 | + log.Error("添加achievement_provider失败:%s", err) | ||
99 | + o.Rollback() | ||
100 | + return protocol.NewErrWithMessage("1") | ||
101 | + } | ||
102 | + o.Commit() | ||
34 | return nil | 103 | return nil |
35 | } | 104 | } |
36 | 105 | ||
37 | -func EditAchievement() error { | 106 | +func EditAchievement(editData *protocol.RequestEditAchievement, companyid int64) error { |
107 | + var ( | ||
108 | + achievementData *models.Achievement | ||
109 | + err error | ||
110 | + ) | ||
111 | + achievementData, err = models.GetAchievementById(editData.AchievementId) | ||
112 | + if err != nil { | ||
113 | + log.Error("获取achievement失败:%s", err) | ||
114 | + return protocol.NewErrWithMessage("1") | ||
115 | + } | ||
116 | + nowTime := time.Now() | ||
117 | + achievementData.UpdateAt = nowTime | ||
118 | + achievementData.DepartmentId = editData.DepartmentId | ||
119 | + achievementData.UserCompanyId = editData.UserCompanyId | ||
120 | + achievementData.ChanceTypeId = editData.TypeIdA | ||
121 | + achievementData.AuditTemplateId = editData.TypeIdB | ||
122 | + achievementData.SourceContent = editData.SourceContent | ||
123 | + achievementData.GraspScore = editData.GraspScore | ||
124 | + achievementData.UserGraspScore = editData.UserGraspScore | ||
125 | + achievementData.UpdateAt = nowTime | ||
126 | + cols := []string{ | ||
127 | + "UpdateAt", "DepartmentId", "UserCompanyId", "ChanceTypeId", "AuditTemplateId", "SourceContent", "GraspScore", | ||
128 | + } | ||
129 | + o := orm.NewOrm() | ||
130 | + o.Begin() | ||
131 | + //更新Achievement 数据 | ||
132 | + err = models.UpdateAchievementById(achievementData, cols, o) | ||
133 | + if err != nil { | ||
134 | + o.Rollback() | ||
135 | + log.Info("更新Achievement数据失败:%s", err) | ||
136 | + return protocol.NewErrWithMessage("1") | ||
137 | + } | ||
138 | + //删除achievement_chance旧数据 | ||
139 | + _, err = o.QueryTable(&models.AchievementChance{}). | ||
140 | + Filter("achievement_id", editData.AchievementId). | ||
141 | + Delete() | ||
142 | + if err != nil { | ||
143 | + o.Rollback() | ||
144 | + log.Info("删除achievement_chance数据失败:%s", err) | ||
145 | + return protocol.NewErrWithMessage("1") | ||
146 | + } | ||
147 | + //删除achievement_prover旧数据 | ||
148 | + _, err = o.QueryTable(&models.AchievementProvider{}). | ||
149 | + Filter("achievement_id", editData.AchievementId). | ||
150 | + Delete() | ||
151 | + if err != nil { | ||
152 | + o.Rollback() | ||
153 | + log.Info("删除achievement_chance数据失败:%s", err) | ||
154 | + return protocol.NewErrWithMessage("1") | ||
155 | + } | ||
156 | + err = addAchievementChance(editData.ChanceData, achievementData.Id, o) | ||
157 | + if err != nil { | ||
158 | + log.Error("添加achievement_chance失败:%s", err) | ||
159 | + o.Rollback() | ||
160 | + return protocol.NewErrWithMessage("1") | ||
161 | + } | ||
162 | + //操作achievement_provider 成果提供人表 | ||
163 | + err = addAchievementProvider(editData.Provider, achievementData.Id, o) | ||
164 | + if err != nil { | ||
165 | + log.Error("添加achievement_provider失败:%s", err) | ||
166 | + o.Rollback() | ||
167 | + return protocol.NewErrWithMessage("1") | ||
168 | + } | ||
169 | + o.Commit() | ||
38 | return nil | 170 | return nil |
39 | } | 171 | } |
40 | 172 |
@@ -248,12 +248,12 @@ func EditRankPeriod(id int64, beginTime int64, endTime int64, name string, compa | @@ -248,12 +248,12 @@ func EditRankPeriod(id int64, beginTime int64, endTime int64, name string, compa | ||
248 | } | 248 | } |
249 | 249 | ||
250 | //获取赛季参与人列表 | 250 | //获取赛季参与人列表 |
251 | -func GetRankRangeList(companyid int64, rankTypeId int64) []protocol.RankRangeItem { | 251 | +func GetRankRangeList(companyid int64, rankTypeId int64) []protocol.RankRangeListItem { |
252 | var ( | 252 | var ( |
253 | err error | 253 | err error |
254 | - rspData = make([]protocol.RankRangeItem, 0) | 254 | + rspData = make([]protocol.RankRangeListItem, 0) |
255 | ) | 255 | ) |
256 | - datasql := `SELECT a.id ,a.name,a.type,a.status FROM rank_range AS a WHERE company_id=? AND rank_type_id=?` | 256 | + datasql := `SELECT a.id ,a.name,a.type,a.status,a.sort_num FROM rank_range AS a WHERE company_id=? AND rank_type_id=?` |
257 | err = utils.ExecuteQueryAll(&rspData, datasql, companyid, rankTypeId) | 257 | err = utils.ExecuteQueryAll(&rspData, datasql, companyid, rankTypeId) |
258 | if err != nil { | 258 | if err != nil { |
259 | log.Error("获取参与人列表失败:%s", err) | 259 | log.Error("获取参与人列表失败:%s", err) |
@@ -266,6 +266,7 @@ func GetRankRangeList(companyid int64, rankTypeId int64) []protocol.RankRangeIte | @@ -266,6 +266,7 @@ func GetRankRangeList(companyid int64, rankTypeId int64) []protocol.RankRangeIte | ||
266 | } | 266 | } |
267 | rspData[i].RangeData = strings.Join(nameList, ",") | 267 | rspData[i].RangeData = strings.Join(nameList, ",") |
268 | } | 268 | } |
269 | + sort.Sort(protocol.RankRangeList(rspData)) | ||
269 | return rspData | 270 | return rspData |
270 | } | 271 | } |
271 | 272 |
-
请 注册 或 登录 后发表评论