...
|
...
|
@@ -91,12 +91,21 @@ func (unitConversionService *UnitConversionService) GetUnitConversion(getUnitCon |
|
|
//var unitConversionRepository domain.UnitConversionRepository
|
|
|
var unitConversion *domain.UnitConversion
|
|
|
_, unitConversion, err = factory.FastPgUnitConversion(transactionContext, getUnitConversionQuery.UnitConversionId)
|
|
|
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
var productMaterial *domain.ProductMaterial
|
|
|
if unitConversion.Material.ProductMaterialId > 0 {
|
|
|
_, productMaterial, err = factory.FastProductMaterial(transactionContext, unitConversion.Material.ProductMaterialId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
result := &dto.UnitConversionDto{}
|
|
|
result.LoadDto(unitConversion, 0)
|
|
|
result.LoadDto(unitConversion, 0, productMaterial)
|
|
|
return result, nil
|
|
|
|
|
|
}
|
...
|
...
|
@@ -293,17 +302,29 @@ func (unitConversionService *UnitConversionService) SearchUnitConversion(operate |
|
|
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 mapProductMaterial = make(map[int]*domain.ProductMaterial, 0)
|
|
|
productMaterialIds := domain.UnitConversions(unitConversions).ProductMaterialIds()
|
|
|
if len(productMaterialIds) > 0 {
|
|
|
productMaterialRepository, _, _ := factory.FastProductMaterial(transactionContext, 0)
|
|
|
_, productMaterials, err := productMaterialRepository.Find(map[string]interface{}{"productMaterialIds": productMaterialIds})
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
mapProductMaterial = domain.ProductMaterials(productMaterials).ToMapById()
|
|
|
}
|
|
|
|
|
|
var result = make([]*dto.UnitConversionDto, 0)
|
|
|
for i := range unitConversions {
|
|
|
item := unitConversions[i]
|
|
|
newItem := &dto.UnitConversionDto{}
|
|
|
newItem.LoadDto(item, operateInfo.OrgId)
|
|
|
newItem.LoadDto(item, operateInfo.OrgId, mapProductMaterial[item.Material.ProductMaterialId])
|
|
|
result = append(result, newItem)
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return count, result, nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -331,11 +352,22 @@ func (unitConversionService *UnitConversionService) SearchMaterial(operateInfo * |
|
|
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
var mapProductMaterial = make(map[int]*domain.ProductMaterial, 0)
|
|
|
productMaterialIds := domain.UnitConversions(unitConversions).ProductMaterialIds()
|
|
|
if len(productMaterialIds) > 0 {
|
|
|
productMaterialRepository, _, _ := factory.FastProductMaterial(transactionContext, 0)
|
|
|
_, productMaterials, err := productMaterialRepository.Find(map[string]interface{}{"productMaterialIds": productMaterialIds})
|
|
|
if err != nil {
|
|
|
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
mapProductMaterial = domain.ProductMaterials(productMaterials).ToMapById()
|
|
|
}
|
|
|
|
|
|
var result = make([]*dto.MaterialUnitConversionDto, 0)
|
|
|
for i := range unitConversions {
|
|
|
item := unitConversions[i]
|
|
|
newItem := &dto.MaterialUnitConversionDto{}
|
|
|
newItem.LoadDto(item)
|
|
|
newItem.LoadDto(item, mapProductMaterial[item.Material.ProductMaterialId])
|
|
|
result = append(result, newItem)
|
|
|
}
|
|
|
return count, map[string]interface{}{
|
...
|
...
|
|