...
|
...
|
@@ -256,15 +256,28 @@ func (productPlanService *ProductPlanService) SetOffline(setOfflineCommand *comm |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var productPlanRepository domain.ProductPlanRepository
|
|
|
var productPlan *domain.ProductPlan
|
|
|
productPlanRepository, productPlan, _ = factory.FastPgProductPlan(transactionContext, setOfflineCommand.ProductPlanId)
|
|
|
|
|
|
if err = productPlan.ChangeStatus(domain.PlanOffline); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if productPlan, err = productPlanRepository.Save(productPlan); 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 productPlan, nil
|
|
|
}
|
|
|
|
|
|
// 计划上线
|
|
|
func (productPlanService *ProductPlanService) SetOnline(setOnlineCommand *command.SetOnlineCommand) (interface{}, error) {
|
|
|
if err := setOnlineCommand.ValidateCommand(); err != nil {
|
|
|
func (productPlanService *ProductPlanService) SetOnline(cmd *command.SetOnlineCommand) (interface{}, error) {
|
|
|
if err := cmd.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -277,10 +290,45 @@ func (productPlanService *ProductPlanService) SetOnline(setOnlineCommand *comman |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var productPlanRepository domain.ProductPlanRepository
|
|
|
var productPlan *domain.ProductPlan
|
|
|
|
|
|
productPlanRepository, productPlan, err = factory.FastPgProductPlan(transactionContext, cmd.ProductPlanId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
if err = productPlan.ChangeStatus(domain.PlanOnline); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
var workshop *domain.Workshop
|
|
|
_, workshop, err = factory.FastPgWorkshop(transactionContext, cmd.WorkshopId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
line, section, err := workshop.FindSectionById(cmd.SectionId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
var workStation *domain.WorkStation
|
|
|
workStation, err = workshop.FindWorkStation(workshop.WorkshopId, line.LineId, section.SectionId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
productPlan.WorkStation = workStation
|
|
|
|
|
|
if productPlan, err = productPlanRepository.Save(productPlan); 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 productPlan, nil
|
|
|
}
|
|
|
|
|
|
// 提交成品记录 (成品 二级品)
|
...
|
...
|
@@ -319,15 +367,49 @@ 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
|
|
|
}
|
|
|
|
|
|
// 更新生产计划服务
|
|
|
func (productPlanService *ProductPlanService) UpdateProductPlan(updateProductPlanCommand *command.UpdateProductPlanCommand) (interface{}, error) {
|
|
|
if err := updateProductPlanCommand.ValidateCommand(); err != nil {
|
|
|
func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.UpdateProductPlanCommand) (interface{}, error) {
|
|
|
if err := cmd.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -341,31 +423,38 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(updateProductPla |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var productPlanRepository domain.ProductPlanRepository
|
|
|
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
var productPlan *domain.ProductPlan
|
|
|
productPlanRepository, productPlan, err = factory.FastPgProductPlan(transactionContext, cmd.ProductPlanId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productPlanRepository = value
|
|
|
}
|
|
|
productPlan, err := productPlanRepository.FindOne(map[string]interface{}{"productPlanId": updateProductPlanCommand.ProductPlanId})
|
|
|
|
|
|
//if productPlan.Workshop.WorkshopId != cmd.WorkshopId{
|
|
|
// // 检查批次号是否有重复的
|
|
|
// if item, err := productPlanRepository.FindOne(map[string]interface{}{"companyId": cmd.CompanyId, "orgId": cmd.OrgId, "batchNumber": cmd.BatchNumber}); err == nil && item != nil {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "批次号重复")
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
_, workshop, err := factory.FastPgWorkshop(transactionContext, cmd.WorkshopId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if productPlan == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductPlanCommand.ProductPlanId)))
|
|
|
}
|
|
|
if err := productPlan.Update(tool_funs.SimpleStructToMap(updateProductPlanCommand)); err != nil {
|
|
|
productPlan.Workshop = workshop.CloneSample()
|
|
|
|
|
|
if err := productPlan.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if productPlan, err := productPlanRepository.Save(productPlan); err != nil {
|
|
|
if productPlan, err = productPlanRepository.Save(productPlan); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return productPlan, nil
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
result := &dto.ProductPlanDto{}
|
|
|
return result.LoadDto(productPlan, cmd.OrgId), nil
|
|
|
}
|
|
|
|
|
|
// 搜索生产计划服务列表
|
...
|
...
|
|