achievement.go
5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package controllers
import (
"encoding/json"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
serveachievement "oppmg/services/achievement"
)
type AchievementController struct {
BaseController
}
//AchievementList 成果列表
//@router /achievement/list
func (c AchievementController) AchievementList() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
protocol.RequestPageInfo
Status int `json:"status"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
rspdata := serveachievement.GetAchievementList(param.PageIndex, param.PageSize, companyid, param.Status)
msg = protocol.NewPageDataResponse(rspdata, nil)
return
}
//AddAchievement 添加成果列表
//@router /achievement/add
func (c AchievementController) AddAchievement() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestAddAchievement
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if len(param.ChanceData) == 0 {
log.Error("len(param.ChanceData) == 0 ")
msg = protocol.BadRequestParam("10109")
return
}
if param.ChanceTypeId == 0 {
log.Error(" param.ChanceTypeId == 0 ")
msg = protocol.BadRequestParam("10108")
return
}
companyid := c.GetCompanyId()
err := serveachievement.AddAchievement(¶m, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
//EditAchievement 编辑成果
//@router /achievement/edit
func (c AchievementController) EditAchievement() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestEditAchievement
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if len(param.ChanceData) == 0 {
log.Error("len(param.ChanceData) == 0 ")
msg = protocol.BadRequestParam("10109")
return
}
if param.ChanceTypeId == 0 {
log.Error(" param.ChanceTypeId == 0 ")
msg = protocol.BadRequestParam("10108")
return
}
companyid := c.GetCompanyId()
err := serveachievement.EditAchievement(¶m, companyid)
msg = protocol.NewReturnResponse(nil, err)
return
}
//EditAchievement 成果详情
//@router /achievement/info
func (c AchievementController) AchievementInfo() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
rspData := serveachievement.GetAchievementInfo(param.Id, companyid)
msg = protocol.NewReturnResponse(rspData, nil)
return
}
//EditAchievement 删除成果
//@router /achievement/delete
func (c AchievementController) DeleteAchievement() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
var (
err error
achievementData *models.Achievement
)
achievementData, err = models.GetAchievementById(param.Id)
if err != nil {
log.Error("获取achievement数据失败:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if achievementData.CompanyId != companyid {
log.Error("achievement数据公司不匹配")
msg = protocol.BadRequestParam("1")
return
}
achievementData.Status = models.ACHIEVEMENT_STATUS_DEL
err = models.UpdateAchievementById(achievementData, []string{"Status"})
if err != nil {
log.Error("更新achievement数据失败:%s", err)
}
msg = protocol.NewReturnResponse(nil, nil)
return
}
//EditAchievement 显示隐藏成果
//@router /achievement/forbid_allow
func (c AchievementController) ForbidAllowAchievement() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Id int64 `json:"id"`
Status int8 `json:"status"` //[1:显示][2:隐藏]
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if param.Status != 1 && param.Status != 2 {
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
var (
err error
achievementData *models.Achievement
)
achievementData, err = models.GetAchievementById(param.Id)
if err != nil {
log.Error("获取achievement数据失败:%s", err)
msg = protocol.BadRequestParam("1")
return
}
if achievementData.CompanyId != companyid {
log.Error("achievement数据公司不匹配")
msg = protocol.BadRequestParam("1")
return
}
achievementData.Status = param.Status
err = models.UpdateAchievementById(achievementData, []string{"Status"})
if err != nil {
log.Error("更新achievement数据失败:%s", err)
}
msg = protocol.NewReturnResponse(nil, nil)
return
}