作者 yangfu

设备车间位置实时查询

... ... @@ -334,18 +334,20 @@ func (deviceService *DeviceService) SearchDevice(operateInfo *domain.OperateInfo
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())
}
workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
var result = make([]*dto.DeviceDto, 0)
for i := range devices {
item := devices[i]
newJobDto := &dto.DeviceDto{}
item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
newJobDto.LoadDto(item, operateInfo.OrgId)
result = append(result, newJobDto)
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return count, result, nil
}
... ...
... ... @@ -119,12 +119,17 @@ func (productGroupService *ProductGroupService) GetProductGroup(getProductGroupQ
}
if productGroup == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductGroupQuery.ProductGroupId)))
} else {
}
_, workshop, err := factory.FastPgWorkshop(transactionContext, productGroup.WorkStation.WorkshopId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
productGroup.WorkStation, _ = workshop.FindWorkStation(productGroup.WorkStation.WorkshopId, productGroup.WorkStation.LineId, productGroup.WorkStation.SectionId)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return productGroup, nil
}
}
// 返回生产班组服务列表
... ... @@ -323,8 +328,8 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(cmd *command.
}
// 返回生产班组服务列表
func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *domain.OperateInfo, q *query.SearchProductGroupQuery) (int64, interface{}, error) {
if err := q.ValidateQuery(); err != nil {
func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *domain.OperateInfo, cmd *query.SearchProductGroupQuery) (int64, interface{}, error) {
if err := cmd.ValidateQuery(); err != nil {
return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
... ... @@ -337,16 +342,24 @@ func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *
defer func() {
transactionContext.RollbackTransaction()
}()
workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
queryOptions := utils.ObjectToMap(cmd)
queryOptions = workshops.FindByNameWithQuery(queryOptions, cmd.WorkshopName, cmd.LineName, "")
var productGroupRepository domain.ProductGroupRepository
productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0)
count, productGroups, err := productGroupRepository.Find(utils.ObjectToMap(q))
count, productGroups, err := productGroupRepository.Find(queryOptions)
if err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var results = make([]*dto.ProductGroupDto, 0)
for i := range productGroups {
item := productGroups[i]
newItem := &dto.ProductGroupDto{}
results = append(results, newItem.LoadDto(productGroups[i], operateInfo.OrgId))
newItem.LoadDto(productGroups[i], operateInfo.OrgId)
item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
results = append(results, newItem)
}
if err := transactionContext.CommitTransaction(); err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -6,6 +6,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -153,6 +154,18 @@ func (repository *ProductGroupRepository) Find(queryOptions map[string]interface
if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
query.Where(`org_id in (?)`, pg.In(v))
}
if v, ok := queryOptions["inWorkshopIds"]; ok && len(v.([]int)) > 0 {
query.Where(`work_station->>'workshopId' in (?)`, pg.In(utils.ToArrayString(v.([]int))))
}
if v, ok := queryOptions["inLineIds"]; ok && len(v.([]int)) > 0 {
query.Where(`work_station->>'lineId' in (?)`, pg.In(utils.ToArrayString(v.([]int))))
}
if v, ok := queryOptions["inSectionIds"]; ok && len(v.([]int)) > 0 {
query.Where(`work_station->>'sectionId' in (?)`, pg.In(utils.ToArrayString(v.([]int))))
}
if v, ok := queryOptions["groupName"]; ok && len(v.(string)) > 0 {
query.Where(fmt.Sprintf(`group_name like '%%%v%%'`, v))
}
query.SetOffsetAndLimit(20)
query.SetOrderDirect("product_group_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...