...
|
...
|
@@ -6,8 +6,11 @@ import ( |
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productJob/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productJob/dto"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productJob/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 工位服务
|
...
|
...
|
@@ -15,8 +18,8 @@ type ProductJobService struct { |
|
|
}
|
|
|
|
|
|
// 创建工位服务
|
|
|
func (productJobService *ProductJobService) CreateProductJob(createProductJobCommand *command.CreateProductJobCommand) (interface{}, error) {
|
|
|
if err := createProductJobCommand.ValidateCommand(); err != nil {
|
|
|
func (productJobService *ProductJobService) CreateProductJob(operateInfo *domain.OperateInfo, cmd *command.CreateProductJobCommand) (interface{}, error) {
|
|
|
if err := cmd.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -29,24 +32,36 @@ func (productJobService *ProductJobService) CreateProductJob(createProductJobCom |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
newProductJob := &domain.ProductJob{
|
|
|
CompanyId: createProductJobCommand.CompanyId,
|
|
|
OrgId: createProductJobCommand.OrgId,
|
|
|
JobName: createProductJobCommand.JobName,
|
|
|
//WorkshopId: createProductJobCommand.WorkshopId,
|
|
|
//LineId: createProductJobCommand.LineId,
|
|
|
//SectionId: createProductJobCommand.SectionId,
|
|
|
RelatedDevices: createProductJobCommand.RelatedDevices,
|
|
|
|
|
|
//var workshopRepository domain.WorkshopRepository
|
|
|
var workStation *domain.WorkStation
|
|
|
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId, factory.WithSetPrincipal())
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
var productJobRepository domain.ProductJobRepository
|
|
|
if value, err := factory.CreateProductJobRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productJobRepository = value
|
|
|
var productJob *domain.ProductJob
|
|
|
productJobRepository, productJob, _ = factory.FastPgProductJob(transactionContext, 0)
|
|
|
|
|
|
if job, err := productJobRepository.FindOne(map[string]interface{}{
|
|
|
"jobName": cmd.JobName,
|
|
|
"workStationId": workStation.WorkStationId,
|
|
|
}); err == nil && job != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "有重复的工位")
|
|
|
}
|
|
|
if productJob, err := productJobRepository.Save(newProductJob); err != nil {
|
|
|
|
|
|
productJob = &domain.ProductJob{
|
|
|
CompanyId: operateInfo.CompanyId,
|
|
|
OrgId: operateInfo.OrgId,
|
|
|
JobName: cmd.JobName,
|
|
|
ProcessName: cmd.ProcessName,
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
WorkStation: workStation,
|
|
|
RelatedDevices: cmd.RelatedDevices,
|
|
|
}
|
|
|
if productJob, err := productJobRepository.Save(productJob); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
...
|
...
|
@@ -71,26 +86,17 @@ func (productJobService *ProductJobService) GetProductJob(getProductJobQuery *qu |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var productJobRepository domain.ProductJobRepository
|
|
|
if value, err := factory.CreateProductJobRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productJobRepository = value
|
|
|
}
|
|
|
productJob, err := productJobRepository.FindOne(map[string]interface{}{"productJobId": getProductJobQuery.ProductJobId})
|
|
|
//var productJobRepository domain.ProductJobRepository
|
|
|
_, productJob, err := factory.FastPgProductJob(transactionContext, getProductJobQuery.ProductJobId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if productJob == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductJobQuery.ProductJobId)))
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return productJob, nil
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
newJobDto := &dto.ProductJobDto{}
|
|
|
newJobDto.LoadDto(productJob)
|
|
|
return newJobDto, nil
|
|
|
}
|
|
|
|
|
|
// 返回工位服务列表
|
...
|
...
|
@@ -170,8 +176,8 @@ func (productJobService *ProductJobService) RemoveProductJob(removeProductJobCom |
|
|
}
|
|
|
|
|
|
// 更新工位服务
|
|
|
func (productJobService *ProductJobService) UpdateProductJob(updateProductJobCommand *command.UpdateProductJobCommand) (interface{}, error) {
|
|
|
if err := updateProductJobCommand.ValidateCommand(); err != nil {
|
|
|
func (productJobService *ProductJobService) UpdateProductJob(cmd *command.UpdateProductJobCommand) (interface{}, error) {
|
|
|
if err := cmd.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -184,24 +190,41 @@ func (productJobService *ProductJobService) UpdateProductJob(updateProductJobCom |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var productJobRepository domain.ProductJobRepository
|
|
|
if value, err := factory.CreateProductJobRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productJobRepository = value
|
|
|
}
|
|
|
productJob, err := productJobRepository.FindOne(map[string]interface{}{"productJobId": updateProductJobCommand.ProductJobId})
|
|
|
|
|
|
//var workshopRepository domain.WorkshopRepository
|
|
|
var workStation *domain.WorkStation
|
|
|
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId, factory.WithSetPrincipal())
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if productJob == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductJobCommand.ProductJobId)))
|
|
|
}
|
|
|
if err := productJob.Update(tool_funs.SimpleStructToMap(updateProductJobCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
|
|
|
var productJobRepository domain.ProductJobRepository
|
|
|
var productJob *domain.ProductJob
|
|
|
var checkDuplicateJobName = false
|
|
|
productJobRepository, productJob, _ = factory.FastPgProductJob(transactionContext, cmd.ProductJobId)
|
|
|
|
|
|
if cmd.JobName != productJob.JobName {
|
|
|
checkDuplicateJobName = true
|
|
|
}
|
|
|
if workStation.WorkStationId != productJob.WorkStation.WorkStationId {
|
|
|
checkDuplicateJobName = true
|
|
|
}
|
|
|
if checkDuplicateJobName {
|
|
|
if job, err := productJobRepository.FindOne(map[string]interface{}{
|
|
|
"jobName": cmd.JobName,
|
|
|
"companyId": productJob.CompanyId,
|
|
|
"orgId": productJob.OrgId,
|
|
|
"workStationId": workStation.WorkStationId,
|
|
|
}); err == nil && job != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "有重复的工位")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
productJob.WorkStation = workStation
|
|
|
productJob.JobName = cmd.JobName
|
|
|
productJob.RelatedDevices = cmd.RelatedDevices
|
|
|
productJob.UpdatedAt = time.Now()
|
|
|
|
|
|
if productJob, err := productJobRepository.Save(productJob); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -212,6 +235,46 @@ func (productJobService *ProductJobService) UpdateProductJob(updateProductJobCom |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 搜索工位服务列表
|
|
|
func (productJobService *ProductJobService) SearchProductJob(operateInfo *domain.OperateInfo, listProductJobQuery *query.SearchProductJobQuery) (int64, interface{}, error) {
|
|
|
listProductJobQuery.OrgId = operateInfo.OrgId
|
|
|
listProductJobQuery.CompanyId = operateInfo.CompanyId
|
|
|
if err := listProductJobQuery.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 productJobRepository domain.ProductJobRepository
|
|
|
if value, err := factory.CreateProductJobRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productJobRepository = value
|
|
|
}
|
|
|
|
|
|
count, productJobs, err := productJobRepository.Find(utils.ObjectToMap(listProductJobQuery))
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var result = make([]*dto.ProductJobDto, 0)
|
|
|
for i := range productJobs {
|
|
|
item := productJobs[i]
|
|
|
newJobDto := &dto.ProductJobDto{}
|
|
|
newJobDto.LoadDto(item)
|
|
|
result = append(result, newJobDto)
|
|
|
}
|
|
|
return count, result, nil
|
|
|
}
|
|
|
|
|
|
func NewProductJobService(options map[string]interface{}) *ProductJobService {
|
|
|
newProductJobService := &ProductJobService{}
|
|
|
return newProductJobService
|
...
|
...
|
|