作者 yangfu

refactor: 计划管理

... ... @@ -79,7 +79,7 @@ func FastPgWorkstation(transactionContext application.TransactionContext, worksh
if mod, err = rep.FindOne(map[string]interface{}{"workshopId": workshopId}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该工作位置不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -113,7 +113,7 @@ func FastPgProductJob(transactionContext application.TransactionContext, id int,
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该工位不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -142,7 +142,7 @@ func FastPgProductGroup(transactionContext application.TransactionContext, id in
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该生产班组不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -171,7 +171,7 @@ func FastPgProduct(transactionContext application.TransactionContext, id int, op
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该产品不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -197,7 +197,7 @@ func FastPgDevice(transactionContext application.TransactionContext, id int, opt
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该设备档案不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -223,7 +223,7 @@ func FastPgProductCalendar(transactionContext application.TransactionContext, id
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间日历不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -249,7 +249,7 @@ func FastPgUnitConversion(transactionContext application.TransactionContext, id
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该单位换算不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -273,9 +273,9 @@ func FastPgProductPlan(transactionContext application.TransactionContext, id int
rep = value
}
if id > 0 {
if mod, err = rep.FindOne(map[string]interface{}{"productJobId": id}); err != nil {
if mod, err = rep.FindOne(map[string]interface{}{"productPlanId": id}); err != nil {
if err == domain.ErrorNotFound {
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该车间不存在")
return nil, nil, application.ThrowError(application.RES_NO_FIND_ERROR, "该生产计划不存在")
}
return nil, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -367,10 +367,44 @@ func (productPlanService *ProductPlanService) Exchange(switchCommand *command.Sw
defer func() {
transactionContext.RollbackTransaction()
}()
var fromPlan, toPlan *domain.ProductPlan
var productPlanRepository domain.ProductPlanRepository
productPlanRepository, fromPlan, err = factory.FastPgProductPlan(transactionContext, switchCommand.FromProductPlanId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_, toPlan, err = factory.FastPgProductPlan(transactionContext, switchCommand.ToProductPlanId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 计划下线
if err = fromPlan.ChangeStatus(domain.PlanOffline); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err = productPlanRepository.Save(fromPlan); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var workStation *domain.WorkStation
fromWorkStation := fromPlan.WorkStation
_, workStation, err = factory.FastPgWorkstation(transactionContext, fromWorkStation.WorkshopId, fromWorkStation.LineId, fromWorkStation.SectionId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 计划上线
toPlan.WorkStation = workStation
if err = toPlan.ChangeStatus(domain.PlanOnline); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if _, err = productPlanRepository.Save(toPlan); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return struct{}{}, nil
}
// 更新生产计划服务
... ...
... ... @@ -95,13 +95,13 @@ func (productPlan *ProductPlan) Update(data map[string]interface{}) error {
}
func (productPlan *ProductPlan) ChangeStatus(status int) error {
if productPlan.PlanStatus == status && productPlan.PlanStatus == PlanOnline {
if productPlan.PlanStatus == status && status == PlanOnline {
return errors.New("计划已经上线")
}
if productPlan.PlanStatus == status && productPlan.PlanStatus == PlanOffline {
if productPlan.PlanStatus == status && status == PlanOffline {
return errors.New("计划已经下线")
}
if !(productPlan.PlanStatus == PlanOnline || productPlan.PlanStatus == PlanOffline) {
if !(status == PlanOnline || status == PlanOffline) {
return errors.New("计划状态有误")
}
productPlan.PlanStatus = status
... ...
... ... @@ -148,7 +148,7 @@ func (repository *DeviceRepository) FindOne(queryOptions map[string]interface{})
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -153,7 +153,7 @@ func (repository *ProductAttendanceRecordRepository) FindOne(queryOptions map[st
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -138,7 +138,7 @@ func (repository *ProductCalendarRepository) FindOne(queryOptions map[string]int
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -133,7 +133,7 @@ func (repository *ProductGroupRepository) FindOne(queryOptions map[string]interf
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -128,7 +128,7 @@ func (repository *ProductJobRepository) FindOne(queryOptions map[string]interfac
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -156,7 +156,7 @@ func (repository *ProductPlanRepository) FindOne(queryOptions map[string]interfa
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -133,7 +133,7 @@ func (repository *ProductRecordRepository) FindOne(queryOptions map[string]inter
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -130,7 +130,7 @@ func (repository *ProductRepository) FindOne(queryOptions map[string]interface{}
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -128,7 +128,7 @@ func (repository *UnitConversionRepository) FindOne(queryOptions map[string]inte
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -121,7 +121,7 @@ func (repository *WorkshopRepository) FindOne(queryOptions map[string]interface{
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
return nil, domain.ErrorNotFound
} else {
return nil, err
}
... ...
... ... @@ -15,7 +15,7 @@ func init() {
web.Router("/product-plans/return-material", &controllers.ProductPlanController{}, "Post:ReturnMaterial")
web.Router("/product-plans/set-online", &controllers.ProductPlanController{}, "Post:SetOnline")
web.Router("/product-plans/set-offline", &controllers.ProductPlanController{}, "Post:SetOffline")
web.Router("/product-plans/switch", &controllers.ProductPlanController{}, "Post:Switch")
web.Router("/product-plans/exchange", &controllers.ProductPlanController{}, "Post:Switch")
web.Router("/product-plans/submit-product-record", &controllers.ProductPlanController{}, "Post:SubmitProductRecord")
web.Router("/product-plans/search", &controllers.ProductPlanController{}, "Post:SearchProductPlan")
}
... ...