正在显示
14 个修改的文件
包含
58 行增加
和
24 行删除
| @@ -79,7 +79,7 @@ func FastPgWorkstation(transactionContext application.TransactionContext, worksh | @@ -79,7 +79,7 @@ func FastPgWorkstation(transactionContext application.TransactionContext, worksh | ||
| 79 | 79 | ||
| 80 | if mod, err = rep.FindOne(map[string]interface{}{"workshopId": workshopId}); err != nil { | 80 | if mod, err = rep.FindOne(map[string]interface{}{"workshopId": workshopId}); err != nil { |
| 81 | if err == domain.ErrorNotFound { | 81 | if err == domain.ErrorNotFound { |
| 82 | - return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在") | 82 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该工作位置不存在") |
| 83 | } | 83 | } |
| 84 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 84 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 85 | } | 85 | } |
| @@ -113,7 +113,7 @@ func FastPgProductJob(transactionContext application.TransactionContext, id int, | @@ -113,7 +113,7 @@ func FastPgProductJob(transactionContext application.TransactionContext, id int, | ||
| 113 | if id > 0 { | 113 | if id > 0 { |
| 114 | if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { | 114 | if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { |
| 115 | if err == domain.ErrorNotFound { | 115 | if err == domain.ErrorNotFound { |
| 116 | - return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在") | 116 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该工位不存在") |
| 117 | } | 117 | } |
| 118 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 118 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 119 | } | 119 | } |
| @@ -142,7 +142,7 @@ func FastPgProductGroup(transactionContext application.TransactionContext, id in | @@ -142,7 +142,7 @@ func FastPgProductGroup(transactionContext application.TransactionContext, id in | ||
| 142 | if id > 0 { | 142 | if id > 0 { |
| 143 | if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { | 143 | if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { |
| 144 | if err == domain.ErrorNotFound { | 144 | if err == domain.ErrorNotFound { |
| 145 | - return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在") | 145 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该生产班组不存在") |
| 146 | } | 146 | } |
| 147 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 147 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 148 | } | 148 | } |
| @@ -171,7 +171,7 @@ func FastPgProduct(transactionContext application.TransactionContext, id int, op | @@ -171,7 +171,7 @@ func FastPgProduct(transactionContext application.TransactionContext, id int, op | ||
| 171 | if id > 0 { | 171 | if id > 0 { |
| 172 | if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { | 172 | if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { |
| 173 | if err == domain.ErrorNotFound { | 173 | if err == domain.ErrorNotFound { |
| 174 | - return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在") | 174 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该产品不存在") |
| 175 | } | 175 | } |
| 176 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 176 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 177 | } | 177 | } |
| @@ -197,7 +197,7 @@ func FastPgDevice(transactionContext application.TransactionContext, id int, opt | @@ -197,7 +197,7 @@ func FastPgDevice(transactionContext application.TransactionContext, id int, opt | ||
| 197 | if id > 0 { | 197 | if id > 0 { |
| 198 | if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { | 198 | if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { |
| 199 | if err == domain.ErrorNotFound { | 199 | if err == domain.ErrorNotFound { |
| 200 | - return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在") | 200 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该设备档案不存在") |
| 201 | } | 201 | } |
| 202 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 202 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 203 | } | 203 | } |
| @@ -223,7 +223,7 @@ func FastPgProductCalendar(transactionContext application.TransactionContext, id | @@ -223,7 +223,7 @@ func FastPgProductCalendar(transactionContext application.TransactionContext, id | ||
| 223 | if id > 0 { | 223 | if id > 0 { |
| 224 | if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { | 224 | if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { |
| 225 | if err == domain.ErrorNotFound { | 225 | if err == domain.ErrorNotFound { |
| 226 | - return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在") | 226 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间日历不存在") |
| 227 | } | 227 | } |
| 228 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 228 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 229 | } | 229 | } |
| @@ -249,7 +249,7 @@ func FastPgUnitConversion(transactionContext application.TransactionContext, id | @@ -249,7 +249,7 @@ func FastPgUnitConversion(transactionContext application.TransactionContext, id | ||
| 249 | if id > 0 { | 249 | if id > 0 { |
| 250 | if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { | 250 | if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { |
| 251 | if err == domain.ErrorNotFound { | 251 | if err == domain.ErrorNotFound { |
| 252 | - return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在") | 252 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该单位换算不存在") |
| 253 | } | 253 | } |
| 254 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 254 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 255 | } | 255 | } |
| @@ -273,9 +273,9 @@ func FastPgProductPlan(transactionContext application.TransactionContext, id int | @@ -273,9 +273,9 @@ func FastPgProductPlan(transactionContext application.TransactionContext, id int | ||
| 273 | rep = value | 273 | rep = value |
| 274 | } | 274 | } |
| 275 | if id > 0 { | 275 | if id > 0 { |
| 276 | - if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil { | 276 | + if mod, err = rep.FindOne(map[string]interface{}{"productPlanId": id}); err != nil { |
| 277 | if err == domain.ErrorNotFound { | 277 | if err == domain.ErrorNotFound { |
| 278 | - return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在") | 278 | + return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该生产计划不存在") |
| 279 | } | 279 | } |
| 280 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 280 | return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 281 | } | 281 | } |
| @@ -367,10 +367,44 @@ func (productPlanService *ProductPlanService) Exchange(switchCommand *command.Sw | @@ -367,10 +367,44 @@ func (productPlanService *ProductPlanService) Exchange(switchCommand *command.Sw | ||
| 367 | defer func() { | 367 | defer func() { |
| 368 | transactionContext.RollbackTransaction() | 368 | transactionContext.RollbackTransaction() |
| 369 | }() | 369 | }() |
| 370 | + var fromPlan, toPlan *domain.ProductPlan | ||
| 371 | + var productPlanRepository domain.ProductPlanRepository | ||
| 372 | + productPlanRepository, fromPlan, err = factory.FastPgProductPlan(transactionContext, switchCommand.FromProductPlanId) | ||
| 373 | + if err != nil { | ||
| 374 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 375 | + } | ||
| 376 | + _, toPlan, err = factory.FastPgProductPlan(transactionContext, switchCommand.ToProductPlanId) | ||
| 377 | + if err != nil { | ||
| 378 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 379 | + } | ||
| 380 | + | ||
| 381 | + // 计划下线 | ||
| 382 | + if err = fromPlan.ChangeStatus(domain.PlanOffline); err != nil { | ||
| 383 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 384 | + } | ||
| 385 | + if _, err = productPlanRepository.Save(fromPlan); err != nil { | ||
| 386 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 387 | + } | ||
| 388 | + | ||
| 389 | + var workStation *domain.WorkStation | ||
| 390 | + fromWorkStation := fromPlan.WorkStation | ||
| 391 | + _, workStation, err = factory.FastPgWorkstation(transactionContext, fromWorkStation.WorkshopId, fromWorkStation.LineId, fromWorkStation.SectionId) | ||
| 392 | + if err != nil { | ||
| 393 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 394 | + } | ||
| 395 | + // 计划上线 | ||
| 396 | + toPlan.WorkStation = workStation | ||
| 397 | + if err = toPlan.ChangeStatus(domain.PlanOnline); err != nil { | ||
| 398 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 399 | + } | ||
| 400 | + if _, err = productPlanRepository.Save(toPlan); err != nil { | ||
| 401 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 402 | + } | ||
| 403 | + | ||
| 370 | if err := transactionContext.CommitTransaction(); err != nil { | 404 | if err := transactionContext.CommitTransaction(); err != nil { |
| 371 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 405 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 372 | } | 406 | } |
| 373 | - return nil, nil | 407 | + return struct{}{}, nil |
| 374 | } | 408 | } |
| 375 | 409 | ||
| 376 | // 更新生产计划服务 | 410 | // 更新生产计划服务 |
| @@ -95,13 +95,13 @@ func (productPlan *ProductPlan) Update(data map[string]interface{}) error { | @@ -95,13 +95,13 @@ func (productPlan *ProductPlan) Update(data map[string]interface{}) error { | ||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | func (productPlan *ProductPlan) ChangeStatus(status int) error { | 97 | func (productPlan *ProductPlan) ChangeStatus(status int) error { |
| 98 | - if productPlan.PlanStatus == status && productPlan.PlanStatus == PlanOnline { | 98 | + if productPlan.PlanStatus == status && status == PlanOnline { |
| 99 | return errors.New("计划已经上线") | 99 | return errors.New("计划已经上线") |
| 100 | } | 100 | } |
| 101 | - if productPlan.PlanStatus == status && productPlan.PlanStatus == PlanOffline { | 101 | + if productPlan.PlanStatus == status && status == PlanOffline { |
| 102 | return errors.New("计划已经下线") | 102 | return errors.New("计划已经下线") |
| 103 | } | 103 | } |
| 104 | - if !(productPlan.PlanStatus == PlanOnline || productPlan.PlanStatus == PlanOffline) { | 104 | + if !(status == PlanOnline || status == PlanOffline) { |
| 105 | return errors.New("计划状态有误") | 105 | return errors.New("计划状态有误") |
| 106 | } | 106 | } |
| 107 | productPlan.PlanStatus = status | 107 | productPlan.PlanStatus = status |
| @@ -148,7 +148,7 @@ func (repository *DeviceRepository) FindOne(queryOptions map[string]interface{}) | @@ -148,7 +148,7 @@ func (repository *DeviceRepository) FindOne(queryOptions map[string]interface{}) | ||
| 148 | } | 148 | } |
| 149 | if err := query.First(); err != nil { | 149 | if err := query.First(); err != nil { |
| 150 | if err.Error() == "pg: no rows in result set" { | 150 | if err.Error() == "pg: no rows in result set" { |
| 151 | - return nil, fmt.Errorf("没有此资源") | 151 | + return nil, domain.ErrorNotFound |
| 152 | } else { | 152 | } else { |
| 153 | return nil, err | 153 | return nil, err |
| 154 | } | 154 | } |
| @@ -153,7 +153,7 @@ func (repository *ProductAttendanceRecordRepository) FindOne(queryOptions map[st | @@ -153,7 +153,7 @@ func (repository *ProductAttendanceRecordRepository) FindOne(queryOptions map[st | ||
| 153 | } | 153 | } |
| 154 | if err := query.First(); err != nil { | 154 | if err := query.First(); err != nil { |
| 155 | if err.Error() == "pg: no rows in result set" { | 155 | if err.Error() == "pg: no rows in result set" { |
| 156 | - return nil, fmt.Errorf("没有此资源") | 156 | + return nil, domain.ErrorNotFound |
| 157 | } else { | 157 | } else { |
| 158 | return nil, err | 158 | return nil, err |
| 159 | } | 159 | } |
| @@ -138,7 +138,7 @@ func (repository *ProductCalendarRepository) FindOne(queryOptions map[string]int | @@ -138,7 +138,7 @@ func (repository *ProductCalendarRepository) FindOne(queryOptions map[string]int | ||
| 138 | } | 138 | } |
| 139 | if err := query.First(); err != nil { | 139 | if err := query.First(); err != nil { |
| 140 | if err.Error() == "pg: no rows in result set" { | 140 | if err.Error() == "pg: no rows in result set" { |
| 141 | - return nil, fmt.Errorf("没有此资源") | 141 | + return nil, domain.ErrorNotFound |
| 142 | } else { | 142 | } else { |
| 143 | return nil, err | 143 | return nil, err |
| 144 | } | 144 | } |
| @@ -133,7 +133,7 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf | @@ -133,7 +133,7 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf | ||
| 133 | } | 133 | } |
| 134 | if err := query.First(); err != nil { | 134 | if err := query.First(); err != nil { |
| 135 | if err.Error() == "pg: no rows in result set" { | 135 | if err.Error() == "pg: no rows in result set" { |
| 136 | - return nil, fmt.Errorf("没有此资源") | 136 | + return nil, domain.ErrorNotFound |
| 137 | } else { | 137 | } else { |
| 138 | return nil, err | 138 | return nil, err |
| 139 | } | 139 | } |
| @@ -128,7 +128,7 @@ func (repository *ProductJobRepository) FindOne(queryOptions map[string]interfac | @@ -128,7 +128,7 @@ func (repository *ProductJobRepository) FindOne(queryOptions map[string]interfac | ||
| 128 | } | 128 | } |
| 129 | if err := query.First(); err != nil { | 129 | if err := query.First(); err != nil { |
| 130 | if err.Error() == "pg: no rows in result set" { | 130 | if err.Error() == "pg: no rows in result set" { |
| 131 | - return nil, fmt.Errorf("没有此资源") | 131 | + return nil, domain.ErrorNotFound |
| 132 | } else { | 132 | } else { |
| 133 | return nil, err | 133 | return nil, err |
| 134 | } | 134 | } |
| @@ -156,7 +156,7 @@ func (repository *ProductPlanRepository) FindOne(queryOptions map[string]interfa | @@ -156,7 +156,7 @@ func (repository *ProductPlanRepository) FindOne(queryOptions map[string]interfa | ||
| 156 | } | 156 | } |
| 157 | if err := query.First(); err != nil { | 157 | if err := query.First(); err != nil { |
| 158 | if err.Error() == "pg: no rows in result set" { | 158 | if err.Error() == "pg: no rows in result set" { |
| 159 | - return nil, fmt.Errorf("没有此资源") | 159 | + return nil, domain.ErrorNotFound |
| 160 | } else { | 160 | } else { |
| 161 | return nil, err | 161 | return nil, err |
| 162 | } | 162 | } |
| @@ -133,7 +133,7 @@ func (repository *ProductRecordRepository) FindOne(queryOptions map[string]inter | @@ -133,7 +133,7 @@ func (repository *ProductRecordRepository) FindOne(queryOptions map[string]inter | ||
| 133 | } | 133 | } |
| 134 | if err := query.First(); err != nil { | 134 | if err := query.First(); err != nil { |
| 135 | if err.Error() == "pg: no rows in result set" { | 135 | if err.Error() == "pg: no rows in result set" { |
| 136 | - return nil, fmt.Errorf("没有此资源") | 136 | + return nil, domain.ErrorNotFound |
| 137 | } else { | 137 | } else { |
| 138 | return nil, err | 138 | return nil, err |
| 139 | } | 139 | } |
| @@ -130,7 +130,7 @@ func (repository *ProductRepository) FindOne(queryOptions map[string]interface{} | @@ -130,7 +130,7 @@ func (repository *ProductRepository) FindOne(queryOptions map[string]interface{} | ||
| 130 | } | 130 | } |
| 131 | if err := query.First(); err != nil { | 131 | if err := query.First(); err != nil { |
| 132 | if err.Error() == "pg: no rows in result set" { | 132 | if err.Error() == "pg: no rows in result set" { |
| 133 | - return nil, fmt.Errorf("没有此资源") | 133 | + return nil, domain.ErrorNotFound |
| 134 | } else { | 134 | } else { |
| 135 | return nil, err | 135 | return nil, err |
| 136 | } | 136 | } |
| @@ -128,7 +128,7 @@ func (repository *UnitConversionRepository) FindOne(queryOptions map[string]inte | @@ -128,7 +128,7 @@ func (repository *UnitConversionRepository) FindOne(queryOptions map[string]inte | ||
| 128 | } | 128 | } |
| 129 | if err := query.First(); err != nil { | 129 | if err := query.First(); err != nil { |
| 130 | if err.Error() == "pg: no rows in result set" { | 130 | if err.Error() == "pg: no rows in result set" { |
| 131 | - return nil, fmt.Errorf("没有此资源") | 131 | + return nil, domain.ErrorNotFound |
| 132 | } else { | 132 | } else { |
| 133 | return nil, err | 133 | return nil, err |
| 134 | } | 134 | } |
| @@ -121,7 +121,7 @@ func (repository *WorkshopRepository) FindOne(queryOptions map[string]interface{ | @@ -121,7 +121,7 @@ func (repository *WorkshopRepository) FindOne(queryOptions map[string]interface{ | ||
| 121 | } | 121 | } |
| 122 | if err := query.First(); err != nil { | 122 | if err := query.First(); err != nil { |
| 123 | if err.Error() == "pg: no rows in result set" { | 123 | if err.Error() == "pg: no rows in result set" { |
| 124 | - return nil, fmt.Errorf("没有此资源") | 124 | + return nil, domain.ErrorNotFound |
| 125 | } else { | 125 | } else { |
| 126 | return nil, err | 126 | return nil, err |
| 127 | } | 127 | } |
| @@ -15,7 +15,7 @@ func init() { | @@ -15,7 +15,7 @@ func init() { | ||
| 15 | web.Router("/product-plans/return-material", &controllers.ProductPlanController{}, "Post:ReturnMaterial") | 15 | web.Router("/product-plans/return-material", &controllers.ProductPlanController{}, "Post:ReturnMaterial") |
| 16 | web.Router("/product-plans/set-online", &controllers.ProductPlanController{}, "Post:SetOnline") | 16 | web.Router("/product-plans/set-online", &controllers.ProductPlanController{}, "Post:SetOnline") |
| 17 | web.Router("/product-plans/set-offline", &controllers.ProductPlanController{}, "Post:SetOffline") | 17 | web.Router("/product-plans/set-offline", &controllers.ProductPlanController{}, "Post:SetOffline") |
| 18 | - web.Router("/product-plans/switch", &controllers.ProductPlanController{}, "Post:Switch") | 18 | + web.Router("/product-plans/exchange", &controllers.ProductPlanController{}, "Post:Switch") |
| 19 | web.Router("/product-plans/submit-product-record", &controllers.ProductPlanController{}, "Post:SubmitProductRecord") | 19 | web.Router("/product-plans/submit-product-record", &controllers.ProductPlanController{}, "Post:SubmitProductRecord") |
| 20 | web.Router("/product-plans/search", &controllers.ProductPlanController{}, "Post:SearchProductPlan") | 20 | web.Router("/product-plans/search", &controllers.ProductPlanController{}, "Post:SearchProductPlan") |
| 21 | } | 21 | } |
-
请 注册 或 登录 后发表评论