...
|
...
|
@@ -6,8 +6,12 @@ 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/productGroup/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/dto"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/productGroup/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// 生产班组服务
|
...
|
...
|
@@ -15,8 +19,8 @@ type ProductGroupService struct { |
|
|
}
|
|
|
|
|
|
// 创建生产班组服务
|
|
|
func (productGroupService *ProductGroupService) CreateProductGroup(createProductGroupCommand *command.CreateProductGroupCommand) (interface{}, error) {
|
|
|
if err := createProductGroupCommand.ValidateCommand(); err != nil {
|
|
|
func (productGroupService *ProductGroupService) CreateProductGroup(operateInfo *domain.OperateInfo, cmd *command.CreateProductGroupCommand) (interface{}, error) {
|
|
|
if err := cmd.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -29,25 +33,47 @@ func (productGroupService *ProductGroupService) CreateProductGroup(createProduct |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
newProductGroup := &domain.ProductGroup{
|
|
|
CompanyId: createProductGroupCommand.CompanyId,
|
|
|
OrgId: createProductGroupCommand.OrgId,
|
|
|
//WorkshopId: createProductGroupCommand.WorkshopId,
|
|
|
//LineId: createProductGroupCommand.LineId,
|
|
|
//SectionId: createProductGroupCommand.SectionId,
|
|
|
GroupName: createProductGroupCommand.GroupName,
|
|
|
//GroupLeader: createProductGroupCommand.GroupLeader,
|
|
|
GroupMembers: createProductGroupCommand.GroupMembers,
|
|
|
WorkOn: createProductGroupCommand.WorkOn,
|
|
|
}
|
|
|
|
|
|
var productGroupRepository domain.ProductGroupRepository
|
|
|
if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0)
|
|
|
|
|
|
var workStation *domain.WorkStation
|
|
|
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
var leader *domain.User
|
|
|
var members []*domain.User
|
|
|
userService := domainService.NewUserService()
|
|
|
leader, err = userService.User(cmd.GroupLeaderId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productGroupRepository = value
|
|
|
}
|
|
|
members, err = userService.Users(cmd.GroupMembers)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
newProductGroup := &domain.ProductGroup{
|
|
|
CompanyId: operateInfo.CompanyId,
|
|
|
OrgId: operateInfo.OrgId,
|
|
|
GroupName: cmd.GroupName,
|
|
|
GroupLeader: leader,
|
|
|
GroupMembers: members,
|
|
|
WorkStation: workStation,
|
|
|
WorkOn: cmd.WorkOn,
|
|
|
CreatedAt: time.Now(),
|
|
|
UpdatedAt: time.Now(),
|
|
|
}
|
|
|
if group, err := productGroupRepository.FindOne(map[string]interface{}{
|
|
|
"groupName": cmd.GroupName,
|
|
|
"workshopId": workStation.WorkshopId,
|
|
|
"lineId": workStation.LineId,
|
|
|
}); err == nil && group != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "有重复的生产班组")
|
|
|
}
|
|
|
|
|
|
if productGroup, err := productGroupRepository.Save(newProductGroup); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
@@ -172,8 +198,8 @@ func (productGroupService *ProductGroupService) RemoveProductGroup(removeProduct |
|
|
}
|
|
|
|
|
|
// 更新生产班组服务
|
|
|
func (productGroupService *ProductGroupService) UpdateProductGroup(updateProductGroupCommand *command.UpdateProductGroupCommand) (interface{}, error) {
|
|
|
if err := updateProductGroupCommand.ValidateCommand(); err != nil {
|
|
|
func (productGroupService *ProductGroupService) UpdateProductGroup(cmd *command.UpdateProductGroupCommand) (interface{}, error) {
|
|
|
if err := cmd.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
...
|
...
|
@@ -187,21 +213,44 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(updateProduct |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
var productGroupRepository domain.ProductGroupRepository
|
|
|
if value, err := factory.CreateProductGroupRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
var productGroup *domain.ProductGroup
|
|
|
productGroupRepository, productGroup, err = factory.FastPgProductGroup(transactionContext, cmd.ProductGroupId)
|
|
|
|
|
|
var workStation *domain.WorkStation
|
|
|
_, workStation, err = factory.FastPgWorkstation(transactionContext, cmd.WorkshopId, cmd.LineId, cmd.SectionId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
productGroupRepository = value
|
|
|
}
|
|
|
productGroup, err := productGroupRepository.FindOne(map[string]interface{}{"productGroupId": updateProductGroupCommand.ProductGroupId})
|
|
|
|
|
|
// 更新名称
|
|
|
if productGroup.GroupName != cmd.GroupName {
|
|
|
if group, err := productGroupRepository.FindOne(map[string]interface{}{
|
|
|
"groupName": cmd.GroupName,
|
|
|
"workshopId": workStation.WorkshopId,
|
|
|
"lineId": workStation.LineId,
|
|
|
}); err == nil && group != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "有重复的生产班组")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var leader *domain.User
|
|
|
var members []*domain.User
|
|
|
userService := domainService.NewUserService()
|
|
|
leader, err = userService.User(cmd.GroupLeaderId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if productGroup == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProductGroupCommand.ProductGroupId)))
|
|
|
members, err = userService.Users(cmd.GroupMembers)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if err := productGroup.Update(tool_funs.SimpleStructToMap(updateProductGroupCommand)); err != nil {
|
|
|
productGroup.GroupLeader = leader
|
|
|
productGroup.GroupMembers = members
|
|
|
productGroup.WorkOn = cmd.WorkOn
|
|
|
productGroup.WorkStation = workStation
|
|
|
productGroup.GroupName = cmd.GroupName
|
|
|
|
|
|
if err := productGroup.Update(tool_funs.SimpleStructToMap(cmd)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if productGroup, err := productGroupRepository.Save(productGroup); err != nil {
|
...
|
...
|
@@ -214,6 +263,40 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(updateProduct |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 返回生产班组服务列表
|
|
|
func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *domain.OperateInfo, q *query.SearchProductGroupQuery) (int64, interface{}, error) {
|
|
|
q.OrgId = operateInfo.OrgId
|
|
|
q.CompanyId = operateInfo.CompanyId
|
|
|
if err := q.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 productGroupRepository domain.ProductGroupRepository
|
|
|
productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0)
|
|
|
count, productGroups, err := productGroupRepository.Find(utils.ObjectToMap(q))
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
var results = make([]*dto.ProductGroupDto, 0)
|
|
|
for i := range productGroups {
|
|
|
newItem := &dto.ProductGroupDto{}
|
|
|
results = append(results, newItem.LoadDto(productGroups[i]))
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return count, results, nil
|
|
|
}
|
|
|
|
|
|
func NewProductGroupService(options map[string]interface{}) *ProductGroupService {
|
|
|
newProductGroupService := &ProductGroupService{}
|
|
|
return newProductGroupService
|
...
|
...
|
|