zhangqian
2023-11-17 ba5c9371fa8993acd703735fe4875aed8a267c26
位置报表索引新增数据
2个文件已修改
35 ■■■■ 已修改文件
controllers/location_product_amount.go 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/search.go 32 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/location_product_amount.go
@@ -14,6 +14,7 @@
    "wms/models"
    "wms/request"
    "wms/response"
    "wms/service"
)
type LocationProductAmountController struct {
@@ -174,6 +175,8 @@
    }); err != nil {
        return err
    }
    service.AddNewLocationReportRecord(locAmount.Id)
    return nil
}
service/search.go
@@ -9,11 +9,11 @@
)
type LocationReport struct {
    LocationProductAmount int
    LocationName          string `json:"name" gorm:"index;type:varchar(255);not null;comment:位置名称"` //位置名称
    LocationJointName     string `json:"jointName" gorm:"type:varchar(255);comment:拼接名称"`           //拼接名称
    MaterialName          string `json:"materialName"`                                              //物料名称
    ProductCategoryName   string `json:"productCategoryName"`                                       //分类名称
    LocationProductAmountID int
    LocationName            string `json:"name" gorm:"index;type:varchar(255);not null;comment:位置名称"` //位置名称
    LocationJointName       string `json:"jointName" gorm:"type:varchar(255);comment:拼接名称"`           //拼接名称
    MaterialName            string `json:"materialName"`                                              //物料名称
    ProductCategoryName     string `json:"productCategoryName"`                                       //分类名称
}
const (
@@ -33,7 +33,7 @@
    reports := make([]*LocationReport, 0)
    search := models.NewLocationProductAmountSearch()
    err = search.Orm.Model(&models.LocationProductAmount{}).
        Raw("select wms_location_product_amount.id as LocationProductAmount, wms_location.name as LocationName, wms_location.joint_name as LocationJointName, material.name as MaterialName, wms_product_category.Name as ProductCategoryName from wms_location_product_amount " +
        Raw("select wms_location_product_amount.id as LocationProductAmountID, wms_location.name as LocationName, wms_location.joint_name as LocationJointName, material.name as MaterialName, wms_product_category.Name as ProductCategoryName from wms_location_product_amount " +
            "left join wms_location on wms_location.id=wms_location_product_amount.location_id " +
            "left join material on material.id = wms_location_product_amount.product_id " +
            "left join wms_product_category on wms_product_category.id=material.category_id").Scan(&reports).Error
@@ -41,7 +41,7 @@
        logx.Errorf("InitLocationReportData scan err:%v", err)
    }
    for _, result := range reports {
        err = blevex.Add(LocationReportIndexName, strconv.Itoa(result.LocationProductAmount), result)
        err = blevex.Add(LocationReportIndexName, strconv.Itoa(result.LocationProductAmountID), result)
        if err != nil {
            logx.Errorf("InitLocationReportData add failed, err:%v, index:%v, data:%v", err, LocationReportIndexName, result)
        }
@@ -64,3 +64,21 @@
    list, total, err = models.NewLocationProductAmountSearch().SetPage(page, pageSize).SetPreload(true).SetIds(recordIds).FindByPage()
    return
}
func AddNewLocationReportRecord(id int) {
    var report LocationReport
    err := models.NewLocationProductAmountSearch().Orm.Model(&models.LocationProductAmount{}).
        Raw("select wms_location_product_amount.id as LocationProductAmountID, wms_location.name as LocationName, wms_location.joint_name as LocationJointName, material.name as MaterialName, wms_product_category.Name as ProductCategoryName from wms_location_product_amount "+
            "left join wms_location on wms_location.id=wms_location_product_amount.location_id "+
            "left join material on material.id = wms_location_product_amount.product_id "+
            "left join wms_product_category on wms_product_category.id=material.category_id where LocationProductAmountID = ?", id).Scan(&report).Error
    if err != nil {
        logx.Errorf("AddNewLocationReportRecord scan err:%v", err)
        return
    }
    err = blevex.Add(LocationReportIndexName, strconv.Itoa(id), report)
    if err != nil {
        logx.Errorf("AddNewLocationReportRecord add err:%v", err)
        return
    }
}