作者 yangfu

设备车间位置实时查询

@@ -334,18 +334,20 @@ func (deviceService *DeviceService) SearchDevice(operateInfo *domain.OperateInfo @@ -334,18 +334,20 @@ func (deviceService *DeviceService) SearchDevice(operateInfo *domain.OperateInfo
334 if err != nil { 334 if err != nil {
335 return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 335 return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
336 } 336 }
337 -  
338 - if err := transactionContext.CommitTransaction(); err != nil {  
339 - return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
340 - } 337 + workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
341 338
342 var result = make([]*dto.DeviceDto, 0) 339 var result = make([]*dto.DeviceDto, 0)
343 for i := range devices { 340 for i := range devices {
344 item := devices[i] 341 item := devices[i]
345 newJobDto := &dto.DeviceDto{} 342 newJobDto := &dto.DeviceDto{}
  343 + item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
346 newJobDto.LoadDto(item, operateInfo.OrgId) 344 newJobDto.LoadDto(item, operateInfo.OrgId)
347 result = append(result, newJobDto) 345 result = append(result, newJobDto)
348 } 346 }
  347 +
  348 + if err := transactionContext.CommitTransaction(); err != nil {
  349 + return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  350 + }
349 return count, result, nil 351 return count, result, nil
350 } 352 }
351 353
@@ -119,12 +119,17 @@ func (productGroupService *ProductGroupService) GetProductGroup(getProductGroupQ @@ -119,12 +119,17 @@ func (productGroupService *ProductGroupService) GetProductGroup(getProductGroupQ
119 } 119 }
120 if productGroup == nil { 120 if productGroup == nil {
121 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductGroupQuery.ProductGroupId))) 121 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProductGroupQuery.ProductGroupId)))
122 - } else {  
123 - if err := transactionContext.CommitTransaction(); err != nil {  
124 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
125 - }  
126 - return productGroup, nil  
127 } 122 }
  123 + _, workshop, err := factory.FastPgWorkshop(transactionContext, productGroup.WorkStation.WorkshopId)
  124 + if err != nil {
  125 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  126 + }
  127 + productGroup.WorkStation, _ = workshop.FindWorkStation(productGroup.WorkStation.WorkshopId, productGroup.WorkStation.LineId, productGroup.WorkStation.SectionId)
  128 +
  129 + if err := transactionContext.CommitTransaction(); err != nil {
  130 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  131 + }
  132 + return productGroup, nil
128 } 133 }
129 134
130 // 返回生产班组服务列表 135 // 返回生产班组服务列表
@@ -323,8 +328,8 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(cmd *command. @@ -323,8 +328,8 @@ func (productGroupService *ProductGroupService) UpdateProductGroup(cmd *command.
323 } 328 }
324 329
325 // 返回生产班组服务列表 330 // 返回生产班组服务列表
326 -func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *domain.OperateInfo, q *query.SearchProductGroupQuery) (int64, interface{}, error) {  
327 - if err := q.ValidateQuery(); err != nil { 331 +func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *domain.OperateInfo, cmd *query.SearchProductGroupQuery) (int64, interface{}, error) {
  332 + if err := cmd.ValidateQuery(); err != nil {
328 return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error()) 333 return 0, nil, application.ThrowError(application.ARG_ERROR, err.Error())
329 } 334 }
330 transactionContext, err := factory.CreateTransactionContext(nil) 335 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -337,16 +342,24 @@ func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo * @@ -337,16 +342,24 @@ func (productGroupService *ProductGroupService) SearchProductGroup(operateInfo *
337 defer func() { 342 defer func() {
338 transactionContext.RollbackTransaction() 343 transactionContext.RollbackTransaction()
339 }() 344 }()
  345 +
  346 + workshops, _ := factory.FastPgWorkshops(transactionContext, operateInfo.CompanyId)
  347 + queryOptions := utils.ObjectToMap(cmd)
  348 + queryOptions = workshops.FindByNameWithQuery(queryOptions, cmd.WorkshopName, cmd.LineName, "")
  349 +
340 var productGroupRepository domain.ProductGroupRepository 350 var productGroupRepository domain.ProductGroupRepository
341 productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0) 351 productGroupRepository, _, _ = factory.FastPgProductGroup(transactionContext, 0)
342 - count, productGroups, err := productGroupRepository.Find(utils.ObjectToMap(q)) 352 + count, productGroups, err := productGroupRepository.Find(queryOptions)
343 if err != nil { 353 if err != nil {
344 return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 354 return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
345 } 355 }
346 var results = make([]*dto.ProductGroupDto, 0) 356 var results = make([]*dto.ProductGroupDto, 0)
347 for i := range productGroups { 357 for i := range productGroups {
  358 + item := productGroups[i]
348 newItem := &dto.ProductGroupDto{} 359 newItem := &dto.ProductGroupDto{}
349 - results = append(results, newItem.LoadDto(productGroups[i], operateInfo.OrgId)) 360 + newItem.LoadDto(productGroups[i], operateInfo.OrgId)
  361 + item.WorkStation = workshops.FindWorkStation(item.WorkStation.WorkshopId, item.WorkStation.LineId, item.WorkStation.SectionId)
  362 + results = append(results, newItem)
350 } 363 }
351 if err := transactionContext.CommitTransaction(); err != nil { 364 if err := transactionContext.CommitTransaction(); err != nil {
352 return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 365 return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/models"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/pg/transform"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
9 10
10 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" 11 "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
11 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 12 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
@@ -153,6 +154,18 @@ func (repository *ProductGroupRepository) Find(queryOptions map[string]interface @@ -153,6 +154,18 @@ func (repository *ProductGroupRepository) Find(queryOptions map[string]interface
153 if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 { 154 if v, ok := queryOptions["inOrgIds"]; ok && len(v.([]int)) > 0 {
154 query.Where(`org_id in (?)`, pg.In(v)) 155 query.Where(`org_id in (?)`, pg.In(v))
155 } 156 }
  157 + if v, ok := queryOptions["inWorkshopIds"]; ok && len(v.([]int)) > 0 {
  158 + query.Where(`work_station->>'workshopId' in (?)`, pg.In(utils.ToArrayString(v.([]int))))
  159 + }
  160 + if v, ok := queryOptions["inLineIds"]; ok && len(v.([]int)) > 0 {
  161 + query.Where(`work_station->>'lineId' in (?)`, pg.In(utils.ToArrayString(v.([]int))))
  162 + }
  163 + if v, ok := queryOptions["inSectionIds"]; ok && len(v.([]int)) > 0 {
  164 + query.Where(`work_station->>'sectionId' in (?)`, pg.In(utils.ToArrayString(v.([]int))))
  165 + }
  166 + if v, ok := queryOptions["groupName"]; ok && len(v.(string)) > 0 {
  167 + query.Where(fmt.Sprintf(`group_name like '%%%v%%'`, v))
  168 + }
156 query.SetOffsetAndLimit(20) 169 query.SetOffsetAndLimit(20)
157 query.SetOrderDirect("product_group_id", "DESC") 170 query.SetOrderDirect("product_group_id", "DESC")
158 if count, err := query.SelectAndCount(); err != nil { 171 if count, err := query.SelectAndCount(); err != nil {