正在显示
9 个修改的文件
包含
248 行增加
和
8 行删除
1 | +package dto | ||
2 | + | ||
3 | +type RewardStandardList struct { | ||
4 | + Id int `json:"id"` //奖惩标准id | ||
5 | + WorkshopId int `json:"workshopId"` //车间id | ||
6 | + WorkshopName string `json:"workshopName"` //车间名称 | ||
7 | + LineId int `json:"lineId"` //生产线ID | ||
8 | + LineName string `json:"lineName"` //生产线名称 | ||
9 | + SectionId int `json:"sectionId"` //工段ID | ||
10 | + SectionName string `json:"sectionName"` //工段名称 | ||
11 | + Remark string `json:"remark"` //备注 | ||
12 | + TargetType int `json:"targetType"` //指标类别 1:产效 2:合格率 3:安全事故 4:质量事故 5:异物次数 | ||
13 | + TargetTypeName string `json:"targetTypeName"` //指标类别 | ||
14 | + TargeReward string `json:"targeReward"` //描述功劳指标 | ||
15 | + TargeFault string `json:"targeVal2"` //描述过失指标 | ||
16 | + | ||
17 | +} |
1 | +package query | ||
2 | + | ||
3 | +type ListRewardStandard struct { | ||
4 | + // 当前公司 | ||
5 | + CompanyId int `cname:"当前公司" json:"companyId"` | ||
6 | + // 当前登录的组织 | ||
7 | + OrgId int `cname:"当前登录的组织" json:"orgId"` | ||
8 | + // 页码 | ||
9 | + PageNumber int `cname:"页码" json:"pageNumber"` | ||
10 | + // 页数 | ||
11 | + PageSize int `cname:"页数" json:"pageSize"` | ||
12 | + // 车间名称 | ||
13 | + WorkshopName string `cname:"车间名称" json:"workshopName"` | ||
14 | + // 线别名称 | ||
15 | + LineName string `cname:"线别名称" json:"lineName"` | ||
16 | + // 工段名称 | ||
17 | + SectionName string `cname:"工段名称" json:"sectionName"` | ||
18 | +} |
@@ -13,13 +13,13 @@ import ( | @@ -13,13 +13,13 @@ import ( | ||
13 | 13 | ||
14 | type RewardStandardService struct{} | 14 | type RewardStandardService struct{} |
15 | 15 | ||
16 | -func NewProductService(options map[string]interface{}) *RewardStandardService { | 16 | +func NewRewardStandardService(options map[string]interface{}) *RewardStandardService { |
17 | newService := &RewardStandardService{} | 17 | newService := &RewardStandardService{} |
18 | return newService | 18 | return newService |
19 | } | 19 | } |
20 | 20 | ||
21 | //SaveRewardStandard 保存奖惩标准数据 | 21 | //SaveRewardStandard 保存奖惩标准数据 |
22 | -func (srv RewardStandardService) SaveRewardStandard(operateInfo domain.OperateInfo, param *command.SaveRewardStandardCommand) (*command.SaveRewardStandardCommand, error) { | 22 | +func (srv RewardStandardService) SaveRewardStandard(operateInfo *domain.OperateInfo, param *command.SaveRewardStandardCommand) (*command.SaveRewardStandardCommand, error) { |
23 | if err := param.ValidateCommand(); err != nil { | 23 | if err := param.ValidateCommand(); err != nil { |
24 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 24 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
25 | } | 25 | } |
@@ -118,7 +118,7 @@ func (srv RewardStandardService) SaveRewardStandard(operateInfo domain.OperateIn | @@ -118,7 +118,7 @@ func (srv RewardStandardService) SaveRewardStandard(operateInfo domain.OperateIn | ||
118 | } | 118 | } |
119 | 119 | ||
120 | //GetRewardStandard 根据id获取奖惩标准数据 | 120 | //GetRewardStandard 根据id获取奖惩标准数据 |
121 | -func (srv RewardStandardService) GetRewardStandard(param *query.GetRewardStandard) (*dto.RewardStandardInfo, error) { | 121 | +func (srv RewardStandardService) GetRewardStandard(operateInfo *domain.OperateInfo, param *query.GetRewardStandard) (*dto.RewardStandardInfo, error) { |
122 | transactionContext, err := factory.CreateTransactionContext(nil) | 122 | transactionContext, err := factory.CreateTransactionContext(nil) |
123 | if err != nil { | 123 | if err != nil { |
124 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 124 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
@@ -142,6 +142,9 @@ func (srv RewardStandardService) GetRewardStandard(param *query.GetRewardStandar | @@ -142,6 +142,9 @@ func (srv RewardStandardService) GetRewardStandard(param *query.GetRewardStandar | ||
142 | if err := transactionContext.CommitTransaction(); err != nil { | 142 | if err := transactionContext.CommitTransaction(); err != nil { |
143 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 143 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
144 | } | 144 | } |
145 | + if operateInfo.CompanyId != rewardStandardData.CompanyId { | ||
146 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在") | ||
147 | + } | ||
145 | 148 | ||
146 | result := dto.RewardStandardInfo{ | 149 | result := dto.RewardStandardInfo{ |
147 | Id: rewardStandardData.Id, | 150 | Id: rewardStandardData.Id, |
@@ -162,7 +165,7 @@ func (srv RewardStandardService) GetRewardStandard(param *query.GetRewardStandar | @@ -162,7 +165,7 @@ func (srv RewardStandardService) GetRewardStandard(param *query.GetRewardStandar | ||
162 | } | 165 | } |
163 | 166 | ||
164 | //DeleteRewardStandard 根据id删除奖惩标准 | 167 | //DeleteRewardStandard 根据id删除奖惩标准 |
165 | -func (srv RewardStandardService) DeleteRewardStandard(param *query.GetRewardStandard) (*domain.RewardStandard, error) { | 168 | +func (srv RewardStandardService) DeleteRewardStandard(operateInfo *domain.OperateInfo, param *query.GetRewardStandard) (*domain.RewardStandard, error) { |
166 | transactionContext, err := factory.CreateTransactionContext(nil) | 169 | transactionContext, err := factory.CreateTransactionContext(nil) |
167 | if err != nil { | 170 | if err != nil { |
168 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 171 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
@@ -181,10 +184,84 @@ func (srv RewardStandardService) DeleteRewardStandard(param *query.GetRewardStan | @@ -181,10 +184,84 @@ func (srv RewardStandardService) DeleteRewardStandard(param *query.GetRewardStan | ||
181 | "id": param.Id, | 184 | "id": param.Id, |
182 | }) | 185 | }) |
183 | if err != nil { | 186 | if err != nil { |
184 | - return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在"+err.Error()) | 187 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在:"+err.Error()) |
188 | + } | ||
189 | + | ||
190 | + if operateInfo.CompanyId != rewardStandardData.CompanyId { | ||
191 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "指标数据不存在") | ||
192 | + } | ||
193 | + _, err = rewardStandardRepo.Remove(rewardStandardData) | ||
194 | + if err != nil { | ||
195 | + return nil, application.ThrowError(application.BUSINESS_ERROR, "操作指标数据失败"+err.Error()) | ||
185 | } | 196 | } |
186 | if err := transactionContext.CommitTransaction(); err != nil { | 197 | if err := transactionContext.CommitTransaction(); err != nil { |
187 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 198 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
188 | } | 199 | } |
189 | return rewardStandardData, nil | 200 | return rewardStandardData, nil |
190 | } | 201 | } |
202 | + | ||
203 | +func (srv RewardStandardService) ListRewardStandard(param *query.ListRewardStandard) (int64, []dto.RewardStandardList, error) { | ||
204 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
205 | + if err != nil { | ||
206 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
207 | + } | ||
208 | + if err := transactionContext.StartTransaction(); err != nil { | ||
209 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
210 | + } | ||
211 | + defer func() { | ||
212 | + transactionContext.RollbackTransaction() | ||
213 | + }() | ||
214 | + | ||
215 | + rewardStandardRepo, _ := factory.CreateRewardStandardRepository(map[string]interface{}{ | ||
216 | + "transactionContext": transactionContext, | ||
217 | + }) | ||
218 | + | ||
219 | + condition := map[string]interface{}{ | ||
220 | + "limit": 20, | ||
221 | + "offset": 0, | ||
222 | + "companyId": param.CompanyId, | ||
223 | + } | ||
224 | + if param.PageSize > 0 { | ||
225 | + condition["limit"] = param.PageSize | ||
226 | + } | ||
227 | + offset := param.PageSize * (param.PageSize - 1) | ||
228 | + if offset > 0 { | ||
229 | + condition["offset"] = offset | ||
230 | + } | ||
231 | + if len(param.WorkshopName) > 0 { | ||
232 | + condition["workshopName"] = param.WorkshopName | ||
233 | + } | ||
234 | + if len(param.SectionName) > 0 { | ||
235 | + condition["sectionName"] = param.SectionName | ||
236 | + } | ||
237 | + if len(param.LineName) > 0 { | ||
238 | + condition["lineName"] = param.LineName | ||
239 | + } | ||
240 | + cnt, rewardStandardList, err := rewardStandardRepo.Find(condition) | ||
241 | + if err != nil { | ||
242 | + return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
243 | + } | ||
244 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
245 | + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
246 | + } | ||
247 | + var listResult []dto.RewardStandardList | ||
248 | + var temp dto.RewardStandardList | ||
249 | + for _, v := range rewardStandardList { | ||
250 | + temp = dto.RewardStandardList{ | ||
251 | + Id: v.Id, | ||
252 | + WorkshopId: v.Workshop.WorkshopId, | ||
253 | + WorkshopName: v.Workshop.WorkshopName, | ||
254 | + LineId: v.ProductLine.LineId, | ||
255 | + LineName: v.ProductLine.LineName, | ||
256 | + SectionId: v.ProductSection.SectionId, | ||
257 | + SectionName: v.ProductSection.SectionName, | ||
258 | + Remark: v.Remark, | ||
259 | + TargetType: v.TargetType, | ||
260 | + TargetTypeName: v.TargetTypeName(), | ||
261 | + TargeReward: v.ShowTargeReward(), | ||
262 | + TargeFault: v.ShowTargeFault(), | ||
263 | + } | ||
264 | + listResult = append(listResult, temp) | ||
265 | + } | ||
266 | + return cnt, listResult, nil | ||
267 | +} |
@@ -28,7 +28,7 @@ var MQTT_HOST = "47.97.5.102" | @@ -28,7 +28,7 @@ var MQTT_HOST = "47.97.5.102" | ||
28 | var MQTT_PORT = "6000" | 28 | var MQTT_PORT = "6000" |
29 | var MQTT_USER = "admin" | 29 | var MQTT_USER = "admin" |
30 | var MQTT_PASSWORD = "123456" | 30 | var MQTT_PASSWORD = "123456" |
31 | -var MQTT_UP = true | 31 | +var MQTT_UP = false |
32 | 32 | ||
33 | func init() { | 33 | func init() { |
34 | MQTT_HOST = Configurator.DefaultString("MQTT_HOST", MQTT_HOST) | 34 | MQTT_HOST = Configurator.DefaultString("MQTT_HOST", MQTT_HOST) |
@@ -2,6 +2,7 @@ package domain | @@ -2,6 +2,7 @@ package domain | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "errors" | 4 | "errors" |
5 | + "fmt" | ||
5 | "strconv" | 6 | "strconv" |
6 | "time" | 7 | "time" |
7 | ) | 8 | ) |
@@ -104,6 +105,7 @@ func (m *RewardStandard) UpdateTarge(targetType int, targeVal1 string, targeVal2 | @@ -104,6 +105,7 @@ func (m *RewardStandard) UpdateTarge(targetType int, targeVal1 string, targeVal2 | ||
104 | return nil | 105 | return nil |
105 | } | 106 | } |
106 | 107 | ||
108 | +//TargetTypeName | ||
107 | func (m *RewardStandard) TargetTypeName() string { | 109 | func (m *RewardStandard) TargetTypeName() string { |
108 | switch m.TargetType { | 110 | switch m.TargetType { |
109 | case TargetType1: | 111 | case TargetType1: |
@@ -119,3 +121,39 @@ func (m *RewardStandard) TargetTypeName() string { | @@ -119,3 +121,39 @@ func (m *RewardStandard) TargetTypeName() string { | ||
119 | } | 121 | } |
120 | return "" | 122 | return "" |
121 | } | 123 | } |
124 | + | ||
125 | +//ShowTargeReward 功过指标描述,功劳 | ||
126 | +func (m *RewardStandard) ShowTargeReward() string { | ||
127 | + show := "" | ||
128 | + switch m.TargetType { | ||
129 | + case TargetType1: | ||
130 | + show = fmt.Sprintf(">=%skg/小时", m.TargeVal1) | ||
131 | + case TargetType2: | ||
132 | + show = fmt.Sprintf(">=%s%%", m.TargeVal1) | ||
133 | + case TargetType3: | ||
134 | + show = fmt.Sprintf("<=%s次或损失<=%s元", m.TargeVal1, m.TargeVal2) | ||
135 | + case TargetType4: | ||
136 | + show = fmt.Sprintf("<=%s次或损失<=%s元", m.TargeVal1, m.TargeVal2) | ||
137 | + case TargetType5: | ||
138 | + show = fmt.Sprintf("金属<=%s次或非金属<=%s", m.TargeVal1, m.TargeVal2) | ||
139 | + } | ||
140 | + return show | ||
141 | +} | ||
142 | + | ||
143 | +//ShowTargeFault 功过指标描述,过失 | ||
144 | +func (m *RewardStandard) ShowTargeFault() string { | ||
145 | + show := "" | ||
146 | + switch m.TargetType { | ||
147 | + case TargetType1: | ||
148 | + show = fmt.Sprintf("<%skg/小时", m.TargeVal1) | ||
149 | + case TargetType2: | ||
150 | + show = fmt.Sprintf("<%s%%", m.TargeVal1) | ||
151 | + case TargetType3: | ||
152 | + show = fmt.Sprintf(">%s次或损失>%s元", m.TargeVal1, m.TargeVal2) | ||
153 | + case TargetType4: | ||
154 | + show = fmt.Sprintf("<=%s次或损失>%s元", m.TargeVal1, m.TargeVal2) | ||
155 | + case TargetType5: | ||
156 | + show = fmt.Sprintf("金属>%s次或非金属>%s", m.TargeVal1, m.TargeVal2) | ||
157 | + } | ||
158 | + return show | ||
159 | +} |
@@ -116,7 +116,6 @@ func (repo *RewardStandardRepository) Find(queryOptions map[string]interface{}) | @@ -116,7 +116,6 @@ func (repo *RewardStandardRepository) Find(queryOptions map[string]interface{}) | ||
116 | if v, ok := queryOptions["offset"].(int); ok { | 116 | if v, ok := queryOptions["offset"].(int); ok { |
117 | query.Offset(v) | 117 | query.Offset(v) |
118 | } | 118 | } |
119 | - | ||
120 | if v, ok := queryOptions["workshopId"]; ok { | 119 | if v, ok := queryOptions["workshopId"]; ok { |
121 | query.Where("work_shop->>'workshopId'='?'", v) | 120 | query.Where("work_shop->>'workshopId'='?'", v) |
122 | } | 121 | } |
@@ -131,6 +130,16 @@ func (repo *RewardStandardRepository) Find(queryOptions map[string]interface{}) | @@ -131,6 +130,16 @@ func (repo *RewardStandardRepository) Find(queryOptions map[string]interface{}) | ||
131 | query.Where("target_type=?", v) | 130 | query.Where("target_type=?", v) |
132 | } | 131 | } |
133 | 132 | ||
133 | + if v, ok := queryOptions["workshopName"]; ok && len(v.(string)) > 0 { | ||
134 | + query.Where(fmt.Sprintf(`work_shop->>'workshopName' like '%%%v%%'`, v)) | ||
135 | + } | ||
136 | + if v, ok := queryOptions["lineName"]; ok && len(v.(string)) > 0 { | ||
137 | + query.Where(fmt.Sprintf(`product_line->>'lineName' like '%%%v%%'`, v)) | ||
138 | + } | ||
139 | + if v, ok := queryOptions["sectionName"]; ok && len(v.(string)) > 0 { | ||
140 | + query.Where(fmt.Sprintf(`product_section->>'sectionName' like '%%%v%%'`, v)) | ||
141 | + } | ||
142 | + | ||
134 | cnt, err := query.SelectAndCount() | 143 | cnt, err := query.SelectAndCount() |
135 | if err != nil { | 144 | if err != nil { |
136 | return 0, nil, err | 145 | return 0, nil, err |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/rewardStandard/command" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/rewardStandard/query" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/rewardStandard/service" | ||
8 | +) | ||
9 | + | ||
10 | +type RewardStandardController struct { | ||
11 | + beego.BaseController | ||
12 | +} | ||
13 | + | ||
14 | +//创建奖惩标准 | ||
15 | +func (c RewardStandardController) CreatedRewardStandard() { | ||
16 | + srv := service.NewRewardStandardService(nil) | ||
17 | + createCommand := &command.SaveRewardStandardCommand{} | ||
18 | + Must(c.Unmarshal(createCommand)) | ||
19 | + operater := ParseOperateInfo(c.BaseController) | ||
20 | + data, err := srv.SaveRewardStandard(operater, createCommand) | ||
21 | + c.Response(data, err) | ||
22 | +} | ||
23 | + | ||
24 | +//更新奖惩标准 | ||
25 | +func (c RewardStandardController) UpdateRewardStandard() { | ||
26 | + srv := service.NewRewardStandardService(nil) | ||
27 | + createCommand := &command.SaveRewardStandardCommand{} | ||
28 | + Must(c.Unmarshal(createCommand)) | ||
29 | + operater := ParseOperateInfo(c.BaseController) | ||
30 | + data, err := srv.SaveRewardStandard(operater, createCommand) | ||
31 | + c.Response(data, err) | ||
32 | +} | ||
33 | + | ||
34 | +//获取奖惩标准 | ||
35 | +func (c RewardStandardController) GetRewardStandard() { | ||
36 | + srv := service.NewRewardStandardService(nil) | ||
37 | + id, _ := c.GetInt(":id") | ||
38 | + getQuery := &query.GetRewardStandard{ | ||
39 | + Id: id, | ||
40 | + } | ||
41 | + operater := ParseOperateInfo(c.BaseController) | ||
42 | + data, err := srv.GetRewardStandard(operater, getQuery) | ||
43 | + c.Response(data, err) | ||
44 | +} | ||
45 | + | ||
46 | +//删除奖惩标准 | ||
47 | +func (c RewardStandardController) DeleteRewardStandard() { | ||
48 | + srv := service.NewRewardStandardService(nil) | ||
49 | + getQuery := &query.GetRewardStandard{} | ||
50 | + Must(c.Unmarshal(getQuery)) | ||
51 | + operater := ParseOperateInfo(c.BaseController) | ||
52 | + data, err := srv.DeleteRewardStandard(operater, getQuery) | ||
53 | + c.Response(data, err) | ||
54 | +} | ||
55 | + | ||
56 | +//列表展示奖惩标准 | ||
57 | +func (c RewardStandardController) ListRewardStandard() { | ||
58 | + srv := service.NewRewardStandardService(nil) | ||
59 | + cmd := &query.ListRewardStandard{} | ||
60 | + Must(c.Unmarshal(cmd)) | ||
61 | + operateInfo := ParseOperateInfo(c.BaseController) | ||
62 | + cmd.CompanyId = operateInfo.CompanyId | ||
63 | + total, data, err := srv.ListRewardStandard(cmd) | ||
64 | + ResponseGrid(c.BaseController, total, data, err) | ||
65 | +} |
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/reward-standard/", &controllers.RewardStandardController{}, "Post:CreatedRewardStandard") | ||
10 | + web.Router("/reward-standard/:id", &controllers.RewardStandardController{}, "Put:UpdateRewardStandard") | ||
11 | + web.Router("/reward-standard/:id", &controllers.RewardStandardController{}, "Get:GetRewardStandard") | ||
12 | + web.Router("/reward-standard/remove", &controllers.RewardStandardController{}, "Post:DeleteRewardStandard") | ||
13 | + web.Router("/reward-standard/search", &controllers.RewardStandardController{}, "Post:ListRewardStandard") | ||
14 | + | ||
15 | +} |
-
请 注册 或 登录 后发表评论