作者 yangfu

refactor: 计划管理、生产班组、物料

... ... @@ -159,27 +159,6 @@ func (productPlanService *ProductPlanService) ListProductPlan(listProductPlanQue
}
}
// 领料
func (productPlanService *ProductPlanService) ReceiveMaterial(receiveMaterialCommand *command.ReceiveMaterialCommand) (interface{}, error) {
if err := receiveMaterialCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 移除生产计划服务
func (productPlanService *ProductPlanService) RemoveProductPlan(removeProductPlanCommand *command.RemoveProductPlanCommand) (interface{}, error) {
if err := removeProductPlanCommand.ValidateCommand(); err != nil {
... ... @@ -220,9 +199,9 @@ func (productPlanService *ProductPlanService) RemoveProductPlan(removeProductPla
}
}
// 退料
func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialCommand *command.ReturnMaterialCommand) (interface{}, error) {
if err := returnMaterialCommand.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)
... ... @@ -235,10 +214,79 @@ func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialComma
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 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())
}
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 {
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
result := &dto.ProductPlanDto{}
return result.LoadDto(productPlan, cmd.OrgId), nil
}
// 搜索生产计划服务列表
func (productPlanService *ProductPlanService) SearchProductPlan(operateInfo *domain.OperateInfo, cmd *query.SearchProductPlanQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var productPlanRepository domain.ProductPlanRepository
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
count, productPlans, err := productPlanRepository.Find(utils.ObjectToMap(cmd))
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.ProductPlanDto, 0)
for i := range productPlans {
item := productPlans[i]
newItem := &dto.ProductPlanDto{}
newItem.LoadDto(item, operateInfo.OrgId)
result = append(result, newItem)
}
return count, result, nil
}
// 计划下线
... ... @@ -331,27 +379,6 @@ func (productPlanService *ProductPlanService) SetOnline(cmd *command.SetOnlineCo
return productPlan, nil
}
// 提交成品记录 (成品 二级品)
func (productPlanService *ProductPlanService) SubmitProductRecord(submitProductRecordCommand *command.SubmitProductRecordCommand) (interface{}, error) {
if err := submitProductRecordCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
// 换单
func (productPlanService *ProductPlanService) Exchange(switchCommand *command.SwitchCommand) (interface{}, error) {
if err := switchCommand.ValidateCommand(); err != nil {
... ... @@ -407,9 +434,9 @@ func (productPlanService *ProductPlanService) Exchange(switchCommand *command.Sw
return struct{}{}, nil
}
// 更新生产计划服务
func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.UpdateProductPlanCommand) (interface{}, error) {
if err := cmd.ValidateCommand(); err != nil {
// 领料
func (productPlanService *ProductPlanService) ReceiveMaterial(receiveMaterialCommand *command.ReceiveMaterialCommand) (interface{}, error) {
if err := receiveMaterialCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -422,79 +449,52 @@ func (productPlanService *ProductPlanService) UpdateProductPlan(cmd *command.Upd
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 := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
}
//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())
// 退料
func (productPlanService *ProductPlanService) ReturnMaterial(returnMaterialCommand *command.ReturnMaterialCommand) (interface{}, error) {
if err := returnMaterialCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
productPlan.Workshop = workshop.CloneSample()
if err := productPlan.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if productPlan, err = productPlanRepository.Save(productPlan); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
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
return nil, nil
}
// 搜索生产计划服务列表
func (productPlanService *ProductPlanService) SearchProductPlan(operateInfo *domain.OperateInfo, cmd *query.SearchProductPlanQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
// 提交成品记录 (成品 二级品)
func (productPlanService *ProductPlanService) SubmitProductRecord(submitProductRecordCommand *command.SubmitProductRecordCommand) (interface{}, error) {
if err := submitProductRecordCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var productPlanRepository domain.ProductPlanRepository
if value, err := factory.CreateProductPlanRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
productPlanRepository = value
}
count, productPlans, err := productPlanRepository.Find(utils.ObjectToMap(cmd))
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var result = make([]*dto.ProductPlanDto, 0)
for i := range productPlans {
item := productPlans[i]
newItem := &dto.ProductPlanDto{}
newItem.LoadDto(item, operateInfo.OrgId)
result = append(result, newItem)
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return count, result, nil
return nil, nil
}
func NewProductPlanService(options map[string]interface{}) *ProductPlanService {
... ...
... ... @@ -6,10 +6,10 @@ import "time"
type ProductAttendanceRecord struct {
// 考勤记录ID
ProductAttendanceId int `json:"productAttendanceId,omitempty"`
// 企业id
CompanyId int `json:"companyId,omitempty"`
// 组织ID
OrgId int `json:"orgId,omitempty"`
// 产品ID
ProductId int `json:"productId,omitempty"`
// 考勤类型 1.正常 2.支援
AttendanceType int `json:"attendanceType,omitempty"`
// 生产工人
... ... @@ -57,9 +57,6 @@ func (productAttendanceRecord *ProductAttendanceRecord) Update(data map[string]i
if orgId, ok := data["orgId"]; ok {
productAttendanceRecord.OrgId = orgId.(int)
}
if productId, ok := data["productId"]; ok {
productAttendanceRecord.ProductId = productId.(int)
}
if attendanceType, ok := data["attendanceType"]; ok {
productAttendanceRecord.AttendanceType = attendanceType.(int)
}
... ...
... ... @@ -13,8 +13,6 @@ type ProductAttendanceRecord struct {
CompanyId int `comment:"企业id"`
// 组织ID
OrgId int `comment:"组织ID"`
// 产品ID
ProductId int `comment:"产品ID"`
// 考勤类型 1.正常 2.支援
AttendanceType int `comment:"考勤类型 1.正常 2.支援"`
// 生产工人
... ...
... ... @@ -9,7 +9,7 @@ func TransformToProductAttendanceRecordDomainModelFromPgModels(productAttendance
return &domain.ProductAttendanceRecord{
ProductAttendanceId: productAttendanceRecordModel.ProductAttendanceId,
OrgId: productAttendanceRecordModel.OrgId,
ProductId: productAttendanceRecordModel.ProductId,
CompanyId: productAttendanceRecordModel.CompanyId,
AttendanceType: productAttendanceRecordModel.AttendanceType,
ProductWorker: productAttendanceRecordModel.ProductWorker,
WorkStation: productAttendanceRecordModel.WorkStation,
... ...