jiangshuai
2023-11-22 ed81fc8d860adb66676d4990e4ce0ff56cff79a6
Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS
8个文件已添加
11个文件已修改
590418 ■■■■■ 已修改文件
.gitignore 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
conf/dictionary.txt 589032 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/location_product_amount.go 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/reorder_rule_controller.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/report_forms_controller.go 166 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
go.mod 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
go.sum 60 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/db.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/move_history.go 246 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/blevex/analyzer.go 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/blevex/bleve.go 134 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/blevex/operate.go 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/blevex/tokenizer.go 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
proto/purchase_wms.proto 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
proto/purchase_wms/purchase_wms.pb.go 358 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
proto/purchase_wms/purchase_wms_grpc.pb.go 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/input_history_search.go 96 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/search.go 86 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -28,3 +28,4 @@
logs
wms*
WMS*
*.bleve
conf/dictionary.txt
New file
Diff too large
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
}
controllers/reorder_rule_controller.go
@@ -373,6 +373,7 @@
        SupplierId: params.SupplierId,
        ProductId:  params.ProductId,
        Amount:     params.OrderNumber.IntPart(),
        Source:     "APS",
    })
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "grpc调用失败")
controllers/report_forms_controller.go
@@ -10,6 +10,7 @@
    "wms/models"
    "wms/request"
    "wms/response"
    "wms/service"
)
type ReportFormsController struct {
@@ -156,64 +157,125 @@
// @Success   200 {object} util.ResponseList{data=[]response.InventoryHistory}    "成功"
// @Router    /api-wms/v1/forms/getHistory [post]
func (slf ReportFormsController) GetHistory(c *gin.Context) {
    slf.GetHistoryNew(c)
    return
    //var params request.GetInventoryHistory
    //if err := c.BindJSON(&params); err != nil {
    //    util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
    //    return
    //}
    ////获取操作详情
    //detailsSearch := models.NewOperationDetailsSearch()
    //var (
    //    result []*response.InventoryHistory
    //    total  int64
    //    ids    []int
    //    err    error
    //)
    //if params.KeyWord != "" {
    //    ids, err = service.SearchHistoryReport(params.KeyWord, params.BaseOperationType)
    //
    //    if err != nil {
    //        util.ResponseFormat(c, code.InternalError, err.Error())
    //        return
    //    }
    //    if len(ids) == 0 {
    //        util.ResponseFormatList(c, code.Success, result, 0)
    //    }
    //}
    //
    //detailsSearch.Orm = detailsSearch.Orm.Model(&models.OperationDetails{}).
    //    Select("wms_operation.number, wms_operation.updated_at as date, material.name as product_name, wms_operation.from_location_id,"+
    //        "wms_operation.to_location_id, wms_operation_details.amount, material.unit, wms_operation.contacter_name as contacted_name,"+
    //        "wms_operation.base_operation_type, material.weight, wms_operation_details.product_id").
    //    Joins("left join wms_operation on wms_operation_details.operation_id = wms_operation.id").
    //    Joins("left join material on wms_operation_details.product_id = material.id").
    //    Where("wms_operation.status = ?", constvar.OperationStatus_Finish).Order("wms_operation.created_at desc")
    //if len(ids) > 0 {
    //    detailsSearch.Orm = detailsSearch.Orm.Where("wms_operation_details.id in ?", ids)
    //}
    //if params.ProduceId != "" {
    //    detailsSearch.Orm = detailsSearch.Orm.Where("wms_operation_details.product_id = ?", params.ProduceId)
    //}
    //if params.BaseOperationType != 0 {
    //    detailsSearch.Orm = detailsSearch.Orm.Where("wms_operation.base_operation_type = ?", params.BaseOperationType)
    //}
    //
    //err = detailsSearch.Orm.Count(&total).Error
    //if err != nil {
    //    util.ResponseFormat(c, code.RequestParamError, "查询total失败")
    //    return
    //}
    //if params.Page*params.PageSize > 0 {
    //    detailsSearch.Orm = detailsSearch.Orm.Offset((params.Page - 1) * params.PageSize).Limit(params.PageSize)
    //}
    //
    //err = detailsSearch.Orm.Find(&result).Error
    //if err != nil {
    //    util.ResponseFormat(c, code.RequestParamError, fmt.Errorf("查询操作明细失败: %v", err))
    //    return
    //}
    //var locationIds []int
    //for _, history := range result {
    //    locationIds = append(locationIds, history.FromLocationId, history.ToLocationId)
    //}
    //locations, err := models.NewLocationSearch().SetIds(locationIds).FindNotTotal()
    //if err != nil {
    //    util.ResponseFormat(c, code.RequestParamError, fmt.Errorf("查询位置失败: %v", err))
    //    return
    //}
    //for _, history := range result {
    //    history.Status = "完成"
    //    for _, location := range locations {
    //        if history.ToLocationId == location.Id {
    //            history.ToLocation = location.Name
    //        }
    //        if history.FromLocationId == location.Id {
    //            history.FromLocation = location.Name
    //        }
    //    }
    //}
    //util.ResponseFormatList(c, code.Success, result, int(total))
}
func (slf ReportFormsController) GetHistoryNew(c *gin.Context) {
    var params request.GetInventoryHistory
    if err := c.BindJSON(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    //获取操作详情
    detailsSearch := models.NewOperationDetailsSearch()
    detailsSearch := models.NewMoveHistorySearch()
    var (
        result []*response.InventoryHistory
        total  int64
        total  uint64
        ids    []int
        err    error
    )
    detailsSearch.Orm = detailsSearch.Orm.Model(&models.OperationDetails{}).
        Select("wms_operation.number, wms_operation.updated_at as date, material.name as product_name, wms_operation.from_location_id,"+
            "wms_operation.to_location_id, wms_operation_details.amount, material.unit, wms_operation.contacter_name as contacted_name,"+
            "wms_operation.base_operation_type, material.weight, wms_operation_details.product_id").
        Joins("left join wms_operation on wms_operation_details.operation_id = wms_operation.id").
        Joins("left join material on wms_operation_details.product_id = material.id").
        Where("wms_operation.status = ?", constvar.OperationStatus_Finish).Order("wms_operation.created_at desc")
    if params.ProduceId != "" {
        detailsSearch.Orm = detailsSearch.Orm.Where("wms_operation_details.product_id = ?", params.ProduceId)
    if params.KeyWord != "" {
        ids, total, err = service.SearchHistoryReport(params.KeyWord, params.BaseOperationType, params.Page, params.PageSize)
        if err != nil {
            util.ResponseFormat(c, code.InternalError, err.Error())
            return
        }
        if len(ids) == 0 {
            util.ResponseFormatList(c, code.Success, result, 0)
        }
    }
    detailsSearch.Orm = detailsSearch.Orm.Model(&models.MoveHistory{}).
        Select("number, updated_at as date, product_name as product_name, from_location_id," +
            "to_location_id, amount, unit, operator as contacted_name, base_operation_type, weight, product_id, from_location, to_location").Order("id desc")
    if len(ids) > 0 {
        detailsSearch.Orm = detailsSearch.Orm.Where("id in ?", ids)
    }
    if params.BaseOperationType != 0 {
        detailsSearch.Orm = detailsSearch.Orm.Where("wms_operation.base_operation_type = ?", params.BaseOperationType)
        detailsSearch.Orm = detailsSearch.Orm.Where("base_operation_type = ?", params.BaseOperationType)
    }
    err := detailsSearch.Orm.Count(&total).Error
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询total失败")
        return
    }
    if params.Page*params.PageSize > 0 {
        detailsSearch.Orm = detailsSearch.Orm.Offset((params.Page - 1) * params.PageSize).Limit(params.PageSize)
    }
    err = detailsSearch.Orm.Find(&result).Error
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, fmt.Errorf("查询操作明细失败: %v", err))
        return
    }
    var locationIds []int
    for _, history := range result {
        locationIds = append(locationIds, history.FromLocationId, history.ToLocationId)
    }
    locations, err := models.NewLocationSearch().SetIds(locationIds).FindNotTotal()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, fmt.Errorf("查询位置失败: %v", err))
        return
    }
    for _, history := range result {
        history.Status = "完成"
        for _, location := range locations {
            if history.ToLocationId == location.Id {
                history.ToLocation = location.Name
            }
            if history.FromLocationId == location.Id {
                history.FromLocation = location.Name
            }
        }
    }
    util.ResponseFormatList(c, code.Success, result, int(total))
}
@@ -245,11 +307,21 @@
            ids = append(ids, location.Id)
        }
    }
    amounts, total, err := models.NewLocationProductAmountSearch().SetPage(params.Page, params.PageSize).SetPreload(true).SetKeyword(params.KeyWord).SetProductId(params.ProductId).SetLocationIds(ids).FindByPage()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询数量失败")
        return
    var (
        amounts    []*models.LocationProductAmount
        total      uint64
        totalInt64 int64
        err        error
    )
    if params.KeyWord != "" {
        amounts, total, err = service.SearchLocationReport(params.KeyWord, params.Page, params.PageSize)
    } else {
        amounts, totalInt64, err = models.NewLocationProductAmountSearch().SetPage(params.Page, params.PageSize).SetPreload(true).SetKeyword(params.KeyWord).SetProductId(params.ProductId).SetLocationIds(ids).FindByPage()
        if err != nil {
            util.ResponseFormat(c, code.RequestParamError, "查询数量失败")
            return
        }
        total = uint64(totalInt64)
    }
    var result []response.LocationForms
go.mod
@@ -5,18 +5,23 @@
require (
    basic.com/aps/nsqclient.git v0.0.0-20230517072415-37491f4a5d25
    basic.com/fileserver/WeedFSClient.git v0.0.0-20231110020027-b2e7576d21e7
    github.com/blevesearch/bleve/v2 v2.3.10
    github.com/dgrijalva/jwt-go v3.2.0+incompatible
    github.com/gin-gonic/gin v1.9.0
    github.com/golang-jwt/jwt/v4 v4.5.0
    github.com/google/uuid v1.3.1
    github.com/huichen/sego v0.0.0-20210824061530-c87651ea5c76
    github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
    github.com/nsqio/go-nsq v1.1.0
    github.com/open-policy-agent/opa v0.57.1
    github.com/satori/go.uuid v1.2.0
    github.com/shopspring/decimal v1.3.1
    github.com/spf13/cast v1.5.0
    github.com/spf13/viper v1.15.0
    github.com/swaggo/files v1.0.1
    github.com/swaggo/gin-swagger v1.6.0
    github.com/swaggo/swag v1.16.1
    github.com/xuri/excelize/v2 v2.8.0
    go.uber.org/zap v1.24.0
    golang.org/x/crypto v0.15.0
    google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98
@@ -31,8 +36,26 @@
require (
    github.com/KyleBanks/depth v1.2.1 // indirect
    github.com/OneOfOne/xxhash v1.2.8 // indirect
    github.com/RoaringBitmap/roaring v1.2.3 // indirect
    github.com/adamzy/cedar-go v0.0.0-20170805034717-80a9c64b256d // indirect
    github.com/agnivade/levenshtein v1.1.1 // indirect
    github.com/beorn7/perks v1.0.1 // indirect
    github.com/bits-and-blooms/bitset v1.2.0 // indirect
    github.com/blevesearch/bleve_index_api v1.0.6 // indirect
    github.com/blevesearch/geo v0.1.18 // indirect
    github.com/blevesearch/go-porterstemmer v1.0.3 // indirect
    github.com/blevesearch/gtreap v0.1.1 // indirect
    github.com/blevesearch/mmap-go v1.0.4 // indirect
    github.com/blevesearch/scorch_segment_api/v2 v2.1.6 // indirect
    github.com/blevesearch/segment v0.9.1 // indirect
    github.com/blevesearch/snowballstem v0.9.0 // indirect
    github.com/blevesearch/upsidedown_store_api v1.0.2 // indirect
    github.com/blevesearch/vellum v1.0.10 // indirect
    github.com/blevesearch/zapx/v11 v11.3.10 // indirect
    github.com/blevesearch/zapx/v12 v12.3.10 // indirect
    github.com/blevesearch/zapx/v13 v13.3.10 // indirect
    github.com/blevesearch/zapx/v14 v14.3.10 // indirect
    github.com/blevesearch/zapx/v15 v15.3.13 // indirect
    github.com/bytedance/sonic v1.9.2 // indirect
    github.com/cespare/xxhash/v2 v2.2.0 // indirect
    github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
@@ -52,6 +75,7 @@
    github.com/go-sql-driver/mysql v1.7.0 // indirect
    github.com/gobwas/glob v0.2.3 // indirect
    github.com/goccy/go-json v0.10.2 // indirect
    github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect
    github.com/golang/protobuf v1.5.3 // indirect
    github.com/golang/snappy v0.0.4 // indirect
    github.com/gorilla/mux v1.8.0 // indirect
@@ -71,7 +95,7 @@
    github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
    github.com/modern-go/reflect2 v1.0.2 // indirect
    github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
    github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
    github.com/mschoch/smat v0.2.0 // indirect
    github.com/pelletier/go-toml/v2 v2.0.9 // indirect
    github.com/prometheus/client_golang v1.16.0 // indirect
    github.com/prometheus/client_model v0.3.0 // indirect
@@ -80,7 +104,6 @@
    github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
    github.com/richardlehane/mscfb v1.0.4 // indirect
    github.com/richardlehane/msoleps v1.0.3 // indirect
    github.com/satori/go.uuid v1.2.0 // indirect
    github.com/sirupsen/logrus v1.9.3 // indirect
    github.com/spf13/afero v1.9.3 // indirect
    github.com/spf13/jwalterweatherman v1.1.0 // indirect
@@ -92,9 +115,9 @@
    github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
    github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
    github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirect
    github.com/xuri/excelize/v2 v2.8.0 // indirect
    github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect
    github.com/yashtewari/glob-intersection v0.2.0 // indirect
    go.etcd.io/bbolt v1.3.7 // indirect
    go.opentelemetry.io/otel v1.19.0 // indirect
    go.opentelemetry.io/otel/metric v1.19.0 // indirect
    go.opentelemetry.io/otel/sdk v1.19.0 // indirect
go.sum
@@ -1,7 +1,5 @@
basic.com/aps/nsqclient.git v0.0.0-20230517072415-37491f4a5d25 h1:sZyNfIISgP1eoY94LG48Kav6HYVLem6EzaEbCeXlcXQ=
basic.com/aps/nsqclient.git v0.0.0-20230517072415-37491f4a5d25/go.mod h1:1RnwEtePLR7ATQorQTxdgvs1o7uuUy1Vw8W7GYtVnoY=
basic.com/fileserver/WeedFSClient.git v0.0.0-20210224075854-9e78086ab4bf h1:HGhtGSBibh1OV4oUe1SWw8DLfL4hXGGBFNW3dpcr+70=
basic.com/fileserver/WeedFSClient.git v0.0.0-20210224075854-9e78086ab4bf/go.mod h1:oiXPn3wwwOi/Sbm6cDWpNWofoG5iV2Nb1V/DxLEAqYY=
basic.com/fileserver/WeedFSClient.git v0.0.0-20231110020027-b2e7576d21e7 h1:oiqEv6At6JhABnPtG6btvCf4Aq1MJflB9bL5arazkE0=
basic.com/fileserver/WeedFSClient.git v0.0.0-20231110020027-b2e7576d21e7/go.mod h1:oiXPn3wwwOi/Sbm6cDWpNWofoG5iV2Nb1V/DxLEAqYY=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
@@ -48,6 +46,11 @@
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/RoaringBitmap/roaring v1.2.3 h1:yqreLINqIrX22ErkKI0vY47/ivtJr6n+kMhVOVmhWBY=
github.com/RoaringBitmap/roaring v1.2.3/go.mod h1:plvDsJQpxOC5bw8LRteu/MLWHsHez/3y6cubLI4/1yE=
github.com/adamzy/cedar-go v0.0.0-20170805034717-80a9c64b256d h1:ir/IFJU5xbja5UaBEQLjcvn7aAU01nqU/NUyOBEU+ew=
github.com/adamzy/cedar-go v0.0.0-20170805034717-80a9c64b256d/go.mod h1:PRWNwWq0yifz6XDPZu48aSld8BWwBfr2JKB2bGWiEd4=
github.com/adamzy/sego v0.0.0-20151004184924-5eab9a44f8e8/go.mod h1:KQxo+Xesl2wLJ3yJcX443KaoWzXpbPzU1GNRyE8kNEY=
github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q=
@@ -56,6 +59,40 @@
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bits-and-blooms/bitset v1.2.0 h1:Kn4yilvwNtMACtf1eYDlG8H77R07mZSPbMjLyS07ChA=
github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/blevesearch/bleve/v2 v2.3.10 h1:z8V0wwGoL4rp7nG/O3qVVLYxUqCbEwskMt4iRJsPLgg=
github.com/blevesearch/bleve/v2 v2.3.10/go.mod h1:RJzeoeHC+vNHsoLR54+crS1HmOWpnH87fL70HAUCzIA=
github.com/blevesearch/bleve_index_api v1.0.6 h1:gyUUxdsrvmW3jVhhYdCVL6h9dCjNT/geNU7PxGn37p8=
github.com/blevesearch/bleve_index_api v1.0.6/go.mod h1:YXMDwaXFFXwncRS8UobWs7nvo0DmusriM1nztTlj1ms=
github.com/blevesearch/geo v0.1.18 h1:Np8jycHTZ5scFe7VEPLrDoHnnb9C4j636ue/CGrhtDw=
github.com/blevesearch/geo v0.1.18/go.mod h1:uRMGWG0HJYfWfFJpK3zTdnnr1K+ksZTuWKhXeSokfnM=
github.com/blevesearch/go-porterstemmer v1.0.3 h1:GtmsqID0aZdCSNiY8SkuPJ12pD4jI+DdXTAn4YRcHCo=
github.com/blevesearch/go-porterstemmer v1.0.3/go.mod h1:angGc5Ht+k2xhJdZi511LtmxuEf0OVpvUUNrwmM1P7M=
github.com/blevesearch/gtreap v0.1.1 h1:2JWigFrzDMR+42WGIN/V2p0cUvn4UP3C4Q5nmaZGW8Y=
github.com/blevesearch/gtreap v0.1.1/go.mod h1:QaQyDRAT51sotthUWAH4Sj08awFSSWzgYICSZ3w0tYk=
github.com/blevesearch/mmap-go v1.0.4 h1:OVhDhT5B/M1HNPpYPBKIEJaD0F3Si+CrEKULGCDPWmc=
github.com/blevesearch/mmap-go v1.0.4/go.mod h1:EWmEAOmdAS9z/pi/+Toxu99DnsbhG1TIxUoRmJw/pSs=
github.com/blevesearch/scorch_segment_api/v2 v2.1.6 h1:CdekX/Ob6YCYmeHzD72cKpwzBjvkOGegHOqhAkXp6yA=
github.com/blevesearch/scorch_segment_api/v2 v2.1.6/go.mod h1:nQQYlp51XvoSVxcciBjtvuHPIVjlWrN1hX4qwK2cqdc=
github.com/blevesearch/segment v0.9.1 h1:+dThDy+Lvgj5JMxhmOVlgFfkUtZV2kw49xax4+jTfSU=
github.com/blevesearch/segment v0.9.1/go.mod h1:zN21iLm7+GnBHWTao9I+Au/7MBiL8pPFtJBJTsk6kQw=
github.com/blevesearch/snowballstem v0.9.0 h1:lMQ189YspGP6sXvZQ4WZ+MLawfV8wOmPoD/iWeNXm8s=
github.com/blevesearch/snowballstem v0.9.0/go.mod h1:PivSj3JMc8WuaFkTSRDW2SlrulNWPl4ABg1tC/hlgLs=
github.com/blevesearch/upsidedown_store_api v1.0.2 h1:U53Q6YoWEARVLd1OYNc9kvhBMGZzVrdmaozG2MfoB+A=
github.com/blevesearch/upsidedown_store_api v1.0.2/go.mod h1:M01mh3Gpfy56Ps/UXHjEO/knbqyQ1Oamg8If49gRwrQ=
github.com/blevesearch/vellum v1.0.10 h1:HGPJDT2bTva12hrHepVT3rOyIKFFF4t7Gf6yMxyMIPI=
github.com/blevesearch/vellum v1.0.10/go.mod h1:ul1oT0FhSMDIExNjIxHqJoGpVrBpKCdgDQNxfqgJt7k=
github.com/blevesearch/zapx/v11 v11.3.10 h1:hvjgj9tZ9DeIqBCxKhi70TtSZYMdcFn7gDb71Xo/fvk=
github.com/blevesearch/zapx/v11 v11.3.10/go.mod h1:0+gW+FaE48fNxoVtMY5ugtNHHof/PxCqh7CnhYdnMzQ=
github.com/blevesearch/zapx/v12 v12.3.10 h1:yHfj3vXLSYmmsBleJFROXuO08mS3L1qDCdDK81jDl8s=
github.com/blevesearch/zapx/v12 v12.3.10/go.mod h1:0yeZg6JhaGxITlsS5co73aqPtM04+ycnI6D1v0mhbCs=
github.com/blevesearch/zapx/v13 v13.3.10 h1:0KY9tuxg06rXxOZHg3DwPJBjniSlqEgVpxIqMGahDE8=
github.com/blevesearch/zapx/v13 v13.3.10/go.mod h1:w2wjSDQ/WBVeEIvP0fvMJZAzDwqwIEzVPnCPrz93yAk=
github.com/blevesearch/zapx/v14 v14.3.10 h1:SG6xlsL+W6YjhX5N3aEiL/2tcWh3DO75Bnz77pSwwKU=
github.com/blevesearch/zapx/v14 v14.3.10/go.mod h1:qqyuR0u230jN1yMmE4FIAuCxmahRQEOehF78m6oTgns=
github.com/blevesearch/zapx/v15 v15.3.13 h1:6EkfaZiPlAxqXz0neniq35my6S48QI94W/wyhnpDHHQ=
github.com/blevesearch/zapx/v15 v15.3.13/go.mod h1:Turk/TNRKj9es7ZpKK95PS7f6D44Y7fAFy8F4LXQtGg=
github.com/bytecodealliance/wasmtime-go/v3 v3.0.2 h1:3uZCA/BLTIu+DqCfguByNMJa2HVHpXvjfy0Dy7g6fuA=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.2 h1:GDaNjuWSGu09guE9Oql0MSTNhNCLlWwO8y/xM5BzcbM=
@@ -146,6 +183,8 @@
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 h1:gtexQ/VGyN+VVFRXSFiguSNcXmS6rkKT+X7FdIrTtfo=
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -221,8 +260,12 @@
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/huichen/sego v0.0.0-20210824061530-c87651ea5c76 h1:qNQ2+1IQT9Mor/vfEHePOQSbiapLoNI7sQmpxM7l1Ew=
github.com/huichen/sego v0.0.0-20210824061530-c87651ea5c76/go.mod h1:Fymg8+khR/cKSuIwqRxy/jmZg7PIPLk7CauXzrbcMUM=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/issue9/assert v1.4.1 h1:gUtOpMTeaE4JTe9kACma5foOHBvVt1p5XTFrULDwdXI=
github.com/issue9/assert v1.4.1/go.mod h1:Yktk83hAVl1SPSYtd9kjhBizuiBIqUQyj+D5SE2yjVY=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
@@ -272,6 +315,8 @@
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM=
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
@@ -370,6 +415,8 @@
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ=
go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
@@ -413,8 +460,6 @@
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
@@ -429,6 +474,7 @@
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo=
golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
@@ -492,8 +538,6 @@
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -562,8 +606,6 @@
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
@@ -581,8 +623,6 @@
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
main.go
@@ -17,6 +17,7 @@
    "wms/proto/product_inventory"
    "wms/proto/purchase_wms"
    "wms/router"
    "wms/service"
)
func main() {
@@ -66,6 +67,10 @@
            panic(fmt.Sprintf("grpc server init error: %v", err.Error()))
        }
    }()
    go service.InitLocationReportData()
    go service.InitHistoryReportData()
    logx.Error(server.ListenAndServe().Error())
}
models/db.go
@@ -117,6 +117,7 @@
        Attachment{},
        LogisticCompany{},
        FileTemplateAttachment{},
        MoveHistory{},
    )
    return err
}
models/move_history.go
New file
@@ -0,0 +1,246 @@
package models
import (
    "fmt"
    "google.golang.org/genproto/googleapis/type/decimal"
    "gorm.io/gorm"
    "wms/constvar"
    "wms/pkg/mysqlx"
)
type (
    // MoveHistory 移动历史
    MoveHistory struct {
        WmsModel
        Id                int                        `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Number            string                     `json:"number" gorm:"column:number;type:varchar(255)"`                  //单号
        BaseOperationType constvar.BaseOperationType `json:"baseOperationType" gorm:"type:tinyint;not null;comment:基础作业类型"`  //基础作业类型
        OperationTypeId   int                        `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"`        //作业类型id
        OperationTypeName string                     `json:"operationTypeName" gorm:"type:int;not null;comment:作业类型名称"`      //作业类型名称
        OperationId       int                        `json:"operationRecordId" gorm:"type:int;not null;comment:操作id"`        //操作id
        ProductId         int                        `json:"productId" gorm:"type:int;not null;comment:产品id"`                //产品id
        ProductName       string                     `json:"productName" gorm:"type:varchar(255);not null;comment:产品名称"`     //产品名称
        Amount            decimal.Decimal            `json:"amount" gorm:"type:decimal(20,2);not null;comment:数量"`           //数量
        Unit              string                     `json:"unit" gorm:"type:char(10);not null;comment:单位"`                  //单位
        Weight            string                     `json:"weight" gorm:"type:decimal(20,2);not null;comment:重量"`           //重量
        FromLocationId    int                        `json:"fromLocationId"   gorm:"type:int;not null;comment:源位置id"`        //源位置id
        FromLocation      string                     `json:"fromLocation"     gorm:"type:varchar(255);not null;comment:源位置"` //源位置
        ToLocationId      int                        `json:"toLocationId"  gorm:"type:int;not null;comment:目标位置id"`          //目标位置id
        ToLocation        string                     `json:"toLocation"    gorm:"type:varchar(255);not null;comment:目标位置"`   //目标位置
        Operator          string                     `json:"operator"    gorm:"type:varchar(255);not null;comment:操作者"`      //操作者
    }
    MoveHistorySearch struct {
        MoveHistory
        Order    string
        PageNum  int
        PageSize int
        Keyword  string
        Orm      *gorm.DB
        Preload  bool
    }
)
func (slf *MoveHistory) TableName() string {
    return "wms_move_history"
}
func NewMoveHistorySearch() *MoveHistorySearch {
    return &MoveHistorySearch{Orm: mysqlx.GetDB()}
}
func (slf *MoveHistorySearch) SetOrm(tx *gorm.DB) *MoveHistorySearch {
    slf.Orm = tx
    return slf
}
func (slf *MoveHistorySearch) SetPage(page, size int) *MoveHistorySearch {
    slf.PageNum, slf.PageSize = page, size
    return slf
}
func (slf *MoveHistorySearch) SetOrder(order string) *MoveHistorySearch {
    slf.Order = order
    return slf
}
func (slf *MoveHistorySearch) SetID(id uint) *MoveHistorySearch {
    slf.ID = id
    return slf
}
func (slf *MoveHistorySearch) SetKeyword(keyword string) *MoveHistorySearch {
    slf.Keyword = keyword
    return slf
}
func (slf *MoveHistorySearch) SetPreload(preload bool) *MoveHistorySearch {
    slf.Preload = preload
    return slf
}
func (slf *MoveHistorySearch) build() *gorm.DB {
    var db = slf.Orm.Model(&MoveHistory{})
    if slf.ID != 0 {
        db = db.Where("id = ?", slf.ID)
    }
    if slf.Order != "" {
        db = db.Order(slf.Order)
    }
    if slf.Keyword != "" {
        db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
    }
    return db
}
// Create 单条插入
func (slf *MoveHistorySearch) Create(record *MoveHistory) error {
    var db = slf.build()
    if err := db.Create(record).Error; err != nil {
        return err
    }
    return nil
}
// CreateBatch 批量插入
func (slf *MoveHistorySearch) CreateBatch(records []*MoveHistory) error {
    var db = slf.build()
    if err := db.Create(&records).Error; err != nil {
        return fmt.Errorf("create batch err: %v, records: %+v", err, records)
    }
    return nil
}
func (slf *MoveHistorySearch) Update(record *MoveHistory) error {
    var db = slf.build()
    if err := db.Omit("CreatedAt").Updates(record).Error; err != nil {
        return fmt.Errorf("save err: %v, record: %+v", err, record)
    }
    return nil
}
func (slf *MoveHistorySearch) UpdateByMap(upMap map[string]interface{}) error {
    var (
        db = slf.build()
    )
    if err := db.Updates(upMap).Error; err != nil {
        return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
    }
    return nil
}
func (slf *MoveHistorySearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error {
    var (
        db = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if err := db.Updates(upMap).Error; err != nil {
        return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap)
    }
    return nil
}
func (slf *MoveHistorySearch) Delete() error {
    var db = slf.build()
    return db.Delete(&MoveHistory{}).Error
}
func (slf *MoveHistorySearch) First() (*MoveHistory, error) {
    var (
        record = new(MoveHistory)
        db     = slf.build()
    )
    if err := db.First(record).Error; err != nil {
        return record, err
    }
    return record, nil
}
func (slf *MoveHistorySearch) Find() ([]*MoveHistory, int64, error) {
    var (
        records = make([]*MoveHistory, 0)
        total   int64
        db      = slf.build()
    )
    if err := db.Count(&total).Error; err != nil {
        return records, total, fmt.Errorf("find count err: %v", err)
    }
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, total, fmt.Errorf("find records err: %v", err)
    }
    return records, total, nil
}
func (slf *MoveHistorySearch) FindNotTotal() ([]*MoveHistory, error) {
    var (
        records = make([]*MoveHistory, 0)
        db      = slf.build()
    )
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, fmt.Errorf("find records err: %v", err)
    }
    return records, nil
}
// FindByQuery 指定条件查询.
func (slf *MoveHistorySearch) FindByQuery(query string, args []interface{}) ([]*MoveHistory, int64, error) {
    var (
        records = make([]*MoveHistory, 0)
        total   int64
        db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if err := db.Count(&total).Error; err != nil {
        return records, total, fmt.Errorf("find by query count err: %v", err)
    }
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
    }
    return records, total, nil
}
// FindByQueryNotTotal 指定条件查询&不查询总条数.
func (slf *MoveHistorySearch) FindByQueryNotTotal(query string, args []interface{}) ([]*MoveHistory, error) {
    var (
        records = make([]*MoveHistory, 0)
        db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
    }
    return records, nil
}
pkg/blevex/analyzer.go
New file
@@ -0,0 +1,54 @@
package blevex
import (
    "errors"
    "github.com/blevesearch/bleve/v2/analysis"
    "github.com/blevesearch/bleve/v2/registry"
)
// SegoAnalyzer from analysis.DefaultAnalyzer
type SegoAnalyzer struct {
    CharFilters  []analysis.CharFilter
    Tokenizer    *SegoTokenizer
    TokenFilters []analysis.TokenFilter
}
func (a *SegoAnalyzer) Analyze(input []byte) analysis.TokenStream {
    if a.CharFilters != nil {
        for _, cf := range a.CharFilters {
            input = cf.Filter(input)
        }
    }
    tokens := a.Tokenizer.Tokenize(input)
    if a.TokenFilters != nil {
        for _, tf := range a.TokenFilters {
            tokens = tf.Filter(tokens)
        }
    }
    return tokens
}
func analyzerConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.Analyzer, error) {
    tokenizerName, ok := config["tokenizer"].(string)
    if !ok {
        return nil, errors.New("must specify tokenizer")
    }
    tokenizer, err := cache.TokenizerNamed(tokenizerName)
    if err != nil {
        return nil, err
    }
    segoTokenizer, ok := tokenizer.(*SegoTokenizer)
    if !ok {
        return nil, errors.New("tokenizer must be of type sego")
    }
    alz := &SegoAnalyzer{
        Tokenizer: segoTokenizer,
    }
    return alz, nil
}
func init() {
    registry.RegisterAnalyzer("sego", analyzerConstructor)
}
pkg/blevex/bleve.go
New file
@@ -0,0 +1,134 @@
package blevex
import (
    "fmt"
    "github.com/blevesearch/bleve/v2"
    "github.com/blevesearch/bleve/v2/mapping"
    "sync"
)
// InitAnalyzer 加载自定义分词器(sego)
var defaultAnalyzer *mapping.IndexMappingImpl
func InitAnalyzer() {
    indexMapping := bleve.NewIndexMapping()
    err := indexMapping.AddCustomTokenizer("sego",
        map[string]interface{}{
            "dictpath": "conf/dictionary.txt", // 替换为实际的字典路径
            "type":     "sego",
        },
    )
    if err != nil {
        panic(err)
    }
    err = indexMapping.AddCustomAnalyzer("sego",
        map[string]interface{}{
            "type":      "sego",
            "tokenizer": "sego",
        },
    )
    if err != nil {
        panic(err)
    }
    indexMapping.DefaultAnalyzer = "sego"
    defaultAnalyzer = indexMapping
}
var indexMap sync.Map
func NewIndex(indexName string) (bleve.Index, error) {
    if defaultAnalyzer == nil {
        InitAnalyzer()
    }
    index, err := bleve.New(indexName, defaultAnalyzer)
    if err == bleve.ErrorIndexPathExists {
        index, err = bleve.Open(indexName)
        if err != nil {
            return nil, err
        }
        return index, nil
    } else if err != nil {
        return nil, err
    }
    return index, nil
}
func LoadIndex(indexName string) (bleve.Index, error) {
    if v, ok := indexMap.Load(indexName); ok {
        return v.(bleve.Index), nil
    }
    index, err := NewIndex(indexName)
    if err == nil {
        indexMap.Store(indexName, index)
    }
    return index, err
}
func Search(indexName string, keyword string, from, size int) (ids []string, total uint64, err error) {
    index, err := LoadIndex(indexName)
    if err != nil {
        return
    }
    req := bleve.NewSearchRequest(bleve.NewQueryStringQuery(keyword))
    req.From = from
    req.Size = size
    res, err := index.Search(req)
    if err != nil {
        return nil, 0, err
    }
    if res == nil {
        return
    }
    for _, ret := range dealResult(res) {
        ids = append(ids, ret.Id)
    }
    return ids, res.Total, nil
}
func ComplexSearch(indexName string, keyword string, conditions map[string]interface{}, from, size int) (ids []string, total uint64, err error) {
    index, err := LoadIndex(indexName)
    if err != nil {
        return nil, 0, err
    }
    // Create a boolean query with a should clause for fuzzy search
    boolQuery := bleve.NewBooleanQuery()
    fuzzyQuery := bleve.NewFuzzyQuery(keyword)
    fuzzyQuery.SetFuzziness(2) // Set the fuzziness level as needed
    boolQuery.AddShould(fuzzyQuery)
    // Add a must clause for category filtering
    for key, val := range conditions {
        query := bleve.NewQueryStringQuery(fmt.Sprintf("%s:%s", key, val))
        boolQuery.AddMust(query)
    }
    req := bleve.NewSearchRequest(boolQuery)
    req.From = from
    req.Size = size
    res, err := index.Search(req)
    if err != nil {
        return nil, 0, err
    }
    if res == nil {
        return
    }
    for _, ret := range dealResult(res) {
        ids = append(ids, ret.Id)
    }
    return ids, res.Total, nil
}
type Result struct {
    Id    string  `json:"id"`
    Score float64 `json:"score"`
}
func dealResult(res *bleve.SearchResult) []Result {
    var results []Result
    for _, item := range res.Hits {
        results = append(results, Result{item.ID, item.Score})
    }
    return results
}
pkg/blevex/operate.go
New file
@@ -0,0 +1,37 @@
package blevex
func Add(indexName string, id string, data interface{}) error {
    i, err := LoadIndex(indexName)
    if err != nil {
        return err
    }
    return i.Index(id, data)
}
func Delete(indexName string, id string) error {
    i, err := LoadIndex(indexName)
    if err != nil {
        return err
    }
    return i.Delete(id)
}
func Exists(indexName string, id string) (ok bool, err error) {
    i, err := LoadIndex(indexName)
    if err != nil {
        return false, err
    }
    doc, err := i.Document(id)
    if err != nil {
        return false, err
    }
    return doc.ID() == id, nil
}
func DocCount(indexName string) (uint64, error) {
    i, err := LoadIndex(indexName)
    if err != nil {
        return 0, err
    }
    return i.DocCount()
}
pkg/blevex/tokenizer.go
New file
@@ -0,0 +1,51 @@
package blevex
import (
    "errors"
    "github.com/huichen/sego"
    "github.com/blevesearch/bleve/v2/analysis"
    "github.com/blevesearch/bleve/v2/registry"
)
type SegoTokenizer struct {
    segmenter sego.Segmenter
}
var _ analysis.Tokenizer = &SegoTokenizer{}
func NewSegoTokenizer(dictpath string) *SegoTokenizer {
    segmenter := sego.Segmenter{}
    segmenter.LoadDictionary(dictpath)
    return &SegoTokenizer{segmenter: segmenter}
}
func (st *SegoTokenizer) Tokenize(sentence []byte) analysis.TokenStream {
    result := make(analysis.TokenStream, 0)
    pos := 1
    segments := st.segmenter.Segment(sentence)
    for _, segment := range segments {
        token := analysis.Token{
            Term:     []byte(segment.Token().Text()),
            Start:    segment.Start(),
            End:      segment.End(),
            Position: pos,
            Type:     analysis.Ideographic,
        }
        result = append(result, &token)
        pos++
    }
    return result
}
func tokenizerConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.Tokenizer, error) {
    dictpath, ok := config["dictpath"].(string)
    if !ok {
        return nil, errors.New("config dictpath not found")
    }
    return NewSegoTokenizer(dictpath), nil
}
func init() {
    registry.RegisterTokenizer("sego", tokenizerConstructor)
}
proto/purchase_wms.proto
@@ -7,6 +7,7 @@
  rpc UpdatePurchaseStatus(UpdatePurchaseStatusRequest) returns (UpdatePurchaseStatusResponse) {}
  rpc GetSupplierListByProductId(GetSupplierListByProductIdRequest) returns (GetSupplierListByProductIdResponse) {}
  rpc CreatePurchaseByWms(CreatePurchaseByWmsRequest) returns (CreatePurchaseByWmsResponse) {}
  rpc GetPurchaseInfo(GetPurchaseInfoRequest) returns (GetPurchaseInfoResponse) {}
}
//------------------------------------------PurchaseToWms--------------------------------
@@ -62,6 +63,7 @@
  int64 SupplierId = 1;
  string ProductId = 2;
  int64 Amount = 3;
  string Source = 4;
}
message CreatePurchaseByWmsResponse {
@@ -70,3 +72,23 @@
  string PurchaseNumber = 3;
}
//-------------------------------------------------------GetPurchaseInfo---------------------------------------
message GetPurchaseInfoRequest {
  repeated string PurchaseNumbers = 1;
}
message PurchaseInfo {
  string purchaseNumber = 1;
  string purchaseName = 2;
  string supplierName = 3;
  int64 amount = 4;
  int64 status = 5;
}
message GetPurchaseInfoResponse {
  repeated PurchaseInfo Infos = 1;
}
proto/purchase_wms/purchase_wms.pb.go
@@ -476,6 +476,7 @@
    SupplierId int64  `protobuf:"varint,1,opt,name=SupplierId,proto3" json:"SupplierId,omitempty"`
    ProductId  string `protobuf:"bytes,2,opt,name=ProductId,proto3" json:"ProductId,omitempty"`
    Amount     int64  `protobuf:"varint,3,opt,name=Amount,proto3" json:"Amount,omitempty"`
    Source     string `protobuf:"bytes,4,opt,name=Source,proto3" json:"Source,omitempty"`
}
func (x *CreatePurchaseByWmsRequest) Reset() {
@@ -529,6 +530,13 @@
        return x.Amount
    }
    return 0
}
func (x *CreatePurchaseByWmsRequest) GetSource() string {
    if x != nil {
        return x.Source
    }
    return ""
}
type CreatePurchaseByWmsResponse struct {
@@ -594,6 +602,179 @@
    return ""
}
type GetPurchaseInfoRequest struct {
    state         protoimpl.MessageState
    sizeCache     protoimpl.SizeCache
    unknownFields protoimpl.UnknownFields
    PurchaseNumbers []string `protobuf:"bytes,1,rep,name=PurchaseNumbers,proto3" json:"PurchaseNumbers,omitempty"`
}
func (x *GetPurchaseInfoRequest) Reset() {
    *x = GetPurchaseInfoRequest{}
    if protoimpl.UnsafeEnabled {
        mi := &file_purchase_wms_proto_msgTypes[10]
        ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
        ms.StoreMessageInfo(mi)
    }
}
func (x *GetPurchaseInfoRequest) String() string {
    return protoimpl.X.MessageStringOf(x)
}
func (*GetPurchaseInfoRequest) ProtoMessage() {}
func (x *GetPurchaseInfoRequest) ProtoReflect() protoreflect.Message {
    mi := &file_purchase_wms_proto_msgTypes[10]
    if protoimpl.UnsafeEnabled && x != nil {
        ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
        if ms.LoadMessageInfo() == nil {
            ms.StoreMessageInfo(mi)
        }
        return ms
    }
    return mi.MessageOf(x)
}
// Deprecated: Use GetPurchaseInfoRequest.ProtoReflect.Descriptor instead.
func (*GetPurchaseInfoRequest) Descriptor() ([]byte, []int) {
    return file_purchase_wms_proto_rawDescGZIP(), []int{10}
}
func (x *GetPurchaseInfoRequest) GetPurchaseNumbers() []string {
    if x != nil {
        return x.PurchaseNumbers
    }
    return nil
}
type PurchaseInfo struct {
    state         protoimpl.MessageState
    sizeCache     protoimpl.SizeCache
    unknownFields protoimpl.UnknownFields
    PurchaseNumber string `protobuf:"bytes,1,opt,name=purchaseNumber,proto3" json:"purchaseNumber,omitempty"`
    PurchaseName   string `protobuf:"bytes,2,opt,name=purchaseName,proto3" json:"purchaseName,omitempty"`
    SupplierName   string `protobuf:"bytes,3,opt,name=supplierName,proto3" json:"supplierName,omitempty"`
    Amount         int64  `protobuf:"varint,4,opt,name=amount,proto3" json:"amount,omitempty"`
    Status         int64  `protobuf:"varint,5,opt,name=status,proto3" json:"status,omitempty"`
}
func (x *PurchaseInfo) Reset() {
    *x = PurchaseInfo{}
    if protoimpl.UnsafeEnabled {
        mi := &file_purchase_wms_proto_msgTypes[11]
        ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
        ms.StoreMessageInfo(mi)
    }
}
func (x *PurchaseInfo) String() string {
    return protoimpl.X.MessageStringOf(x)
}
func (*PurchaseInfo) ProtoMessage() {}
func (x *PurchaseInfo) ProtoReflect() protoreflect.Message {
    mi := &file_purchase_wms_proto_msgTypes[11]
    if protoimpl.UnsafeEnabled && x != nil {
        ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
        if ms.LoadMessageInfo() == nil {
            ms.StoreMessageInfo(mi)
        }
        return ms
    }
    return mi.MessageOf(x)
}
// Deprecated: Use PurchaseInfo.ProtoReflect.Descriptor instead.
func (*PurchaseInfo) Descriptor() ([]byte, []int) {
    return file_purchase_wms_proto_rawDescGZIP(), []int{11}
}
func (x *PurchaseInfo) GetPurchaseNumber() string {
    if x != nil {
        return x.PurchaseNumber
    }
    return ""
}
func (x *PurchaseInfo) GetPurchaseName() string {
    if x != nil {
        return x.PurchaseName
    }
    return ""
}
func (x *PurchaseInfo) GetSupplierName() string {
    if x != nil {
        return x.SupplierName
    }
    return ""
}
func (x *PurchaseInfo) GetAmount() int64 {
    if x != nil {
        return x.Amount
    }
    return 0
}
func (x *PurchaseInfo) GetStatus() int64 {
    if x != nil {
        return x.Status
    }
    return 0
}
type GetPurchaseInfoResponse struct {
    state         protoimpl.MessageState
    sizeCache     protoimpl.SizeCache
    unknownFields protoimpl.UnknownFields
    Infos []*PurchaseInfo `protobuf:"bytes,1,rep,name=Infos,proto3" json:"Infos,omitempty"`
}
func (x *GetPurchaseInfoResponse) Reset() {
    *x = GetPurchaseInfoResponse{}
    if protoimpl.UnsafeEnabled {
        mi := &file_purchase_wms_proto_msgTypes[12]
        ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
        ms.StoreMessageInfo(mi)
    }
}
func (x *GetPurchaseInfoResponse) String() string {
    return protoimpl.X.MessageStringOf(x)
}
func (*GetPurchaseInfoResponse) ProtoMessage() {}
func (x *GetPurchaseInfoResponse) ProtoReflect() protoreflect.Message {
    mi := &file_purchase_wms_proto_msgTypes[12]
    if protoimpl.UnsafeEnabled && x != nil {
        ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
        if ms.LoadMessageInfo() == nil {
            ms.StoreMessageInfo(mi)
        }
        return ms
    }
    return mi.MessageOf(x)
}
// Deprecated: Use GetPurchaseInfoResponse.ProtoReflect.Descriptor instead.
func (*GetPurchaseInfoResponse) Descriptor() ([]byte, []int) {
    return file_purchase_wms_proto_rawDescGZIP(), []int{12}
}
func (x *GetPurchaseInfoResponse) GetInfos() []*PurchaseInfo {
    if x != nil {
        return x.Infos
    }
    return nil
}
var File_purchase_wms_proto protoreflect.FileDescriptor
var file_purchase_wms_proto_rawDesc = []byte{
@@ -641,45 +822,70 @@
    0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x21, 0x0a, 0x04,
    0x4c, 0x69, 0x73, 0x74, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x53, 0x75, 0x70,
    0x70, 0x6c, 0x69, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x22,
    0x72, 0x0a, 0x1a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73,
    0x65, 0x42, 0x79, 0x57, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a,
    0x0a, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
    0x03, 0x52, 0x0a, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1c, 0x0a,
    0x09, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
    0x52, 0x09, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x41,
    0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x41, 0x6d, 0x6f,
    0x75, 0x6e, 0x74, 0x22, 0x6b, 0x0a, 0x1b, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x75, 0x72,
    0x63, 0x68, 0x61, 0x73, 0x65, 0x42, 0x79, 0x57, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
    0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05,
    0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20,
    0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x26, 0x0a, 0x0e, 0x50, 0x75, 0x72, 0x63,
    0x68, 0x61, 0x73, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
    0x52, 0x0e, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72,
    0x32, 0xe5, 0x02, 0x0a, 0x0f, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x53, 0x65, 0x72,
    0x76, 0x69, 0x63, 0x65, 0x12, 0x3e, 0x0a, 0x0d, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65,
    0x54, 0x6f, 0x57, 0x6d, 0x73, 0x12, 0x15, 0x2e, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65,
    0x54, 0x6f, 0x57, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x50,
    0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x54, 0x6f, 0x57, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70,
    0x6f, 0x6e, 0x73, 0x65, 0x12, 0x55, 0x0a, 0x14, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x75,
    0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1c, 0x2e, 0x55,
    0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x53, 0x74, 0x61,
    0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x55, 0x70, 0x64,
    0x8a, 0x01, 0x0a, 0x1a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61,
    0x73, 0x65, 0x42, 0x79, 0x57, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e,
    0x0a, 0x0a, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
    0x28, 0x03, 0x52, 0x0a, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1c,
    0x0a, 0x09, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
    0x09, 0x52, 0x09, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06,
    0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x41, 0x6d,
    0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x04,
    0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x22, 0x6b, 0x0a, 0x1b,
    0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x42, 0x79,
    0x57, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x43,
    0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12,
    0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73,
    0x67, 0x12, 0x26, 0x0a, 0x0e, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x4e, 0x75, 0x6d,
    0x62, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x50, 0x75, 0x72, 0x63, 0x68,
    0x61, 0x73, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x42, 0x0a, 0x16, 0x47, 0x65, 0x74,
    0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75,
    0x65, 0x73, 0x74, 0x12, 0x28, 0x0a, 0x0f, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x4e,
    0x75, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0f, 0x50, 0x75,
    0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x22, 0xae, 0x01,
    0x0a, 0x0c, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x26,
    0x0a, 0x0e, 0x70, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72,
    0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x70, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65,
    0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x22, 0x0a, 0x0c, 0x70, 0x75, 0x72, 0x63, 0x68, 0x61,
    0x73, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x75,
    0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x75,
    0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
    0x52, 0x0c, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x16,
    0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06,
    0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73,
    0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x3e,
    0x0a, 0x17, 0x47, 0x65, 0x74, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x49, 0x6e, 0x66,
    0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x23, 0x0a, 0x05, 0x49, 0x6e, 0x66,
    0x6f, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x50, 0x75, 0x72, 0x63, 0x68,
    0x61, 0x73, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x49, 0x6e, 0x66, 0x6f, 0x73, 0x32, 0xad,
    0x03, 0x0a, 0x0f, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69,
    0x63, 0x65, 0x12, 0x3e, 0x0a, 0x0d, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x54, 0x6f,
    0x57, 0x6d, 0x73, 0x12, 0x15, 0x2e, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x54, 0x6f,
    0x57, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x50, 0x75, 0x72,
    0x63, 0x68, 0x61, 0x73, 0x65, 0x54, 0x6f, 0x57, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
    0x73, 0x65, 0x12, 0x55, 0x0a, 0x14, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x75, 0x72, 0x63,
    0x68, 0x61, 0x73, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1c, 0x2e, 0x55, 0x70, 0x64,
    0x61, 0x74, 0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75,
    0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x67, 0x0a, 0x1a, 0x47,
    0x65, 0x74, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x79,
    0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x22, 0x2e, 0x47, 0x65, 0x74, 0x53,
    0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x79, 0x50, 0x72, 0x6f,
    0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e,
    0x47, 0x65, 0x74, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x42,
    0x79, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
    0x73, 0x65, 0x22, 0x00, 0x12, 0x52, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x75,
    0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x42, 0x79, 0x57, 0x6d, 0x73, 0x12, 0x1b, 0x2e, 0x43, 0x72,
    0x65, 0x61, 0x74, 0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x42, 0x79, 0x57, 0x6d,
    0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74,
    0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x42, 0x79, 0x57, 0x6d, 0x73, 0x52, 0x65,
    0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x10, 0x5a, 0x0e, 0x2e, 0x2f, 0x70, 0x75,
    0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x5f, 0x77, 0x6d, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
    0x6f, 0x33,
    0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74,
    0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52,
    0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x67, 0x0a, 0x1a, 0x47, 0x65, 0x74,
    0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x79, 0x50, 0x72,
    0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x12, 0x22, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x70,
    0x70, 0x6c, 0x69, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x79, 0x50, 0x72, 0x6f, 0x64, 0x75,
    0x63, 0x74, 0x49, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x47, 0x65,
    0x74, 0x53, 0x75, 0x70, 0x70, 0x6c, 0x69, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x79, 0x50,
    0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x49, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
    0x22, 0x00, 0x12, 0x52, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x75, 0x72, 0x63,
    0x68, 0x61, 0x73, 0x65, 0x42, 0x79, 0x57, 0x6d, 0x73, 0x12, 0x1b, 0x2e, 0x43, 0x72, 0x65, 0x61,
    0x74, 0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x42, 0x79, 0x57, 0x6d, 0x73, 0x52,
    0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50,
    0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x42, 0x79, 0x57, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70,
    0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x50, 0x75, 0x72,
    0x63, 0x68, 0x61, 0x73, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x17, 0x2e, 0x47, 0x65, 0x74, 0x50,
    0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65,
    0x73, 0x74, 0x1a, 0x18, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65,
    0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x10,
    0x5a, 0x0e, 0x2e, 0x2f, 0x70, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x5f, 0x77, 0x6d, 0x73,
    0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -694,7 +900,7 @@
    return file_purchase_wms_proto_rawDescData
}
var file_purchase_wms_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_purchase_wms_proto_msgTypes = make([]protoimpl.MessageInfo, 13)
var file_purchase_wms_proto_goTypes = []interface{}{
    (*PurchaseProduct)(nil),                    // 0: PurchaseProduct
    (*PurchaseToWmsRequest)(nil),               // 1: PurchaseToWmsRequest
@@ -706,23 +912,29 @@
    (*GetSupplierListByProductIdResponse)(nil), // 7: GetSupplierListByProductIdResponse
    (*CreatePurchaseByWmsRequest)(nil),         // 8: CreatePurchaseByWmsRequest
    (*CreatePurchaseByWmsResponse)(nil),        // 9: CreatePurchaseByWmsResponse
    (*GetPurchaseInfoRequest)(nil),             // 10: GetPurchaseInfoRequest
    (*PurchaseInfo)(nil),                       // 11: PurchaseInfo
    (*GetPurchaseInfoResponse)(nil),            // 12: GetPurchaseInfoResponse
}
var file_purchase_wms_proto_depIdxs = []int32{
    0, // 0: PurchaseToWmsRequest.Product:type_name -> PurchaseProduct
    6, // 1: GetSupplierListByProductIdResponse.List:type_name -> SupplierList
    1, // 2: PurchaseService.PurchaseToWms:input_type -> PurchaseToWmsRequest
    3, // 3: PurchaseService.UpdatePurchaseStatus:input_type -> UpdatePurchaseStatusRequest
    5, // 4: PurchaseService.GetSupplierListByProductId:input_type -> GetSupplierListByProductIdRequest
    8, // 5: PurchaseService.CreatePurchaseByWms:input_type -> CreatePurchaseByWmsRequest
    2, // 6: PurchaseService.PurchaseToWms:output_type -> PurchaseToWmsResponse
    4, // 7: PurchaseService.UpdatePurchaseStatus:output_type -> UpdatePurchaseStatusResponse
    7, // 8: PurchaseService.GetSupplierListByProductId:output_type -> GetSupplierListByProductIdResponse
    9, // 9: PurchaseService.CreatePurchaseByWms:output_type -> CreatePurchaseByWmsResponse
    6, // [6:10] is the sub-list for method output_type
    2, // [2:6] is the sub-list for method input_type
    2, // [2:2] is the sub-list for extension type_name
    2, // [2:2] is the sub-list for extension extendee
    0, // [0:2] is the sub-list for field type_name
    0,  // 0: PurchaseToWmsRequest.Product:type_name -> PurchaseProduct
    6,  // 1: GetSupplierListByProductIdResponse.List:type_name -> SupplierList
    11, // 2: GetPurchaseInfoResponse.Infos:type_name -> PurchaseInfo
    1,  // 3: PurchaseService.PurchaseToWms:input_type -> PurchaseToWmsRequest
    3,  // 4: PurchaseService.UpdatePurchaseStatus:input_type -> UpdatePurchaseStatusRequest
    5,  // 5: PurchaseService.GetSupplierListByProductId:input_type -> GetSupplierListByProductIdRequest
    8,  // 6: PurchaseService.CreatePurchaseByWms:input_type -> CreatePurchaseByWmsRequest
    10, // 7: PurchaseService.GetPurchaseInfo:input_type -> GetPurchaseInfoRequest
    2,  // 8: PurchaseService.PurchaseToWms:output_type -> PurchaseToWmsResponse
    4,  // 9: PurchaseService.UpdatePurchaseStatus:output_type -> UpdatePurchaseStatusResponse
    7,  // 10: PurchaseService.GetSupplierListByProductId:output_type -> GetSupplierListByProductIdResponse
    9,  // 11: PurchaseService.CreatePurchaseByWms:output_type -> CreatePurchaseByWmsResponse
    12, // 12: PurchaseService.GetPurchaseInfo:output_type -> GetPurchaseInfoResponse
    8,  // [8:13] is the sub-list for method output_type
    3,  // [3:8] is the sub-list for method input_type
    3,  // [3:3] is the sub-list for extension type_name
    3,  // [3:3] is the sub-list for extension extendee
    0,  // [0:3] is the sub-list for field type_name
}
func init() { file_purchase_wms_proto_init() }
@@ -851,6 +1063,42 @@
                return nil
            }
        }
        file_purchase_wms_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
            switch v := v.(*GetPurchaseInfoRequest); i {
            case 0:
                return &v.state
            case 1:
                return &v.sizeCache
            case 2:
                return &v.unknownFields
            default:
                return nil
            }
        }
        file_purchase_wms_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} {
            switch v := v.(*PurchaseInfo); i {
            case 0:
                return &v.state
            case 1:
                return &v.sizeCache
            case 2:
                return &v.unknownFields
            default:
                return nil
            }
        }
        file_purchase_wms_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} {
            switch v := v.(*GetPurchaseInfoResponse); i {
            case 0:
                return &v.state
            case 1:
                return &v.sizeCache
            case 2:
                return &v.unknownFields
            default:
                return nil
            }
        }
    }
    type x struct{}
    out := protoimpl.TypeBuilder{
@@ -858,7 +1106,7 @@
            GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
            RawDescriptor: file_purchase_wms_proto_rawDesc,
            NumEnums:      0,
            NumMessages:   10,
            NumMessages:   13,
            NumExtensions: 0,
            NumServices:   1,
        },
proto/purchase_wms/purchase_wms_grpc.pb.go
@@ -22,6 +22,7 @@
    UpdatePurchaseStatus(ctx context.Context, in *UpdatePurchaseStatusRequest, opts ...grpc.CallOption) (*UpdatePurchaseStatusResponse, error)
    GetSupplierListByProductId(ctx context.Context, in *GetSupplierListByProductIdRequest, opts ...grpc.CallOption) (*GetSupplierListByProductIdResponse, error)
    CreatePurchaseByWms(ctx context.Context, in *CreatePurchaseByWmsRequest, opts ...grpc.CallOption) (*CreatePurchaseByWmsResponse, error)
    GetPurchaseInfo(ctx context.Context, in *GetPurchaseInfoRequest, opts ...grpc.CallOption) (*GetPurchaseInfoResponse, error)
}
type purchaseServiceClient struct {
@@ -68,6 +69,15 @@
    return out, nil
}
func (c *purchaseServiceClient) GetPurchaseInfo(ctx context.Context, in *GetPurchaseInfoRequest, opts ...grpc.CallOption) (*GetPurchaseInfoResponse, error) {
    out := new(GetPurchaseInfoResponse)
    err := c.cc.Invoke(ctx, "/PurchaseService/GetPurchaseInfo", in, out, opts...)
    if err != nil {
        return nil, err
    }
    return out, nil
}
// PurchaseServiceServer is the server API for PurchaseService service.
// All implementations must embed UnimplementedPurchaseServiceServer
// for forward compatibility
@@ -76,6 +86,7 @@
    UpdatePurchaseStatus(context.Context, *UpdatePurchaseStatusRequest) (*UpdatePurchaseStatusResponse, error)
    GetSupplierListByProductId(context.Context, *GetSupplierListByProductIdRequest) (*GetSupplierListByProductIdResponse, error)
    CreatePurchaseByWms(context.Context, *CreatePurchaseByWmsRequest) (*CreatePurchaseByWmsResponse, error)
    GetPurchaseInfo(context.Context, *GetPurchaseInfoRequest) (*GetPurchaseInfoResponse, error)
    mustEmbedUnimplementedPurchaseServiceServer()
}
@@ -94,6 +105,9 @@
}
func (UnimplementedPurchaseServiceServer) CreatePurchaseByWms(context.Context, *CreatePurchaseByWmsRequest) (*CreatePurchaseByWmsResponse, error) {
    return nil, status.Errorf(codes.Unimplemented, "method CreatePurchaseByWms not implemented")
}
func (UnimplementedPurchaseServiceServer) GetPurchaseInfo(context.Context, *GetPurchaseInfoRequest) (*GetPurchaseInfoResponse, error) {
    return nil, status.Errorf(codes.Unimplemented, "method GetPurchaseInfo not implemented")
}
func (UnimplementedPurchaseServiceServer) mustEmbedUnimplementedPurchaseServiceServer() {}
@@ -180,6 +194,24 @@
    return interceptor(ctx, in, info, handler)
}
func _PurchaseService_GetPurchaseInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
    in := new(GetPurchaseInfoRequest)
    if err := dec(in); err != nil {
        return nil, err
    }
    if interceptor == nil {
        return srv.(PurchaseServiceServer).GetPurchaseInfo(ctx, in)
    }
    info := &grpc.UnaryServerInfo{
        Server:     srv,
        FullMethod: "/PurchaseService/GetPurchaseInfo",
    }
    handler := func(ctx context.Context, req interface{}) (interface{}, error) {
        return srv.(PurchaseServiceServer).GetPurchaseInfo(ctx, req.(*GetPurchaseInfoRequest))
    }
    return interceptor(ctx, in, info, handler)
}
// PurchaseService_ServiceDesc is the grpc.ServiceDesc for PurchaseService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@@ -203,6 +235,10 @@
            MethodName: "CreatePurchaseByWms",
            Handler:    _PurchaseService_CreatePurchaseByWms_Handler,
        },
        {
            MethodName: "GetPurchaseInfo",
            Handler:    _PurchaseService_GetPurchaseInfo_Handler,
        },
    },
    Streams:  []grpc.StreamDesc{},
    Metadata: "purchase_wms.proto",
service/input_history_search.go
New file
@@ -0,0 +1,96 @@
package service
import (
    "github.com/spf13/cast"
    "gorm.io/gorm"
    "strconv"
    "wms/constvar"
    "wms/models"
    "wms/pkg/blevex"
    "wms/pkg/logx"
    "wms/pkg/structx"
)
type HistoryReport struct {
    ID                int
    BaseOperationType constvar.BaseOperationType
    Number            string //操作单号
    ProductId         string //产品编号
    ProductName       string //产品名称
    OperationTypeName string //业务名称
    FromLocation      string //源位置名称
    ToLocation        string //目标位置名称
}
const (
    HistoryReportIndexName = "HistoryReport.bleve"
)
func InitHistoryReportData() {
    docCount, err := blevex.DocCount(HistoryReportIndexName)
    if err != nil {
        logx.Errorf("InitHistoryReportData get doc count err:%v", err)
        return
    }
    if docCount > 0 {
        return
    }
    records := make([]*models.MoveHistory, 0, 100)
    reports := make([]*HistoryReport, 0, 100)
    err = models.NewMoveHistorySearch().Orm.FindInBatches(&records, 100, func(tx *gorm.DB, batch int) error {
        err = structx.AssignTo(records, &reports)
        if err != nil {
            logx.Errorf("AddNewHistoryReportRecord AssignTo err:%v", err)
            return err
        }
        for _, report := range reports {
            err = blevex.Add(HistoryReportIndexName, strconv.Itoa(report.ID), report)
            if err != nil {
                logx.Errorf("InitHistoryReportData add failed, err:%v, index:%v, data:%v", err, HistoryReportIndexName, report)
                return err
            }
        }
        return nil
    }).Error
    if err != nil {
        logx.Errorf("InitHistoryReportData scan err:%v", err)
    }
    return
}
func SearchHistoryReport(keyword string, operationType constvar.BaseOperationType, page, pageSize int) (recordIds []int, total uint64, err error) {
    var ids []string
    from := (page - 1) * pageSize
    ids, total, err = blevex.ComplexSearch(HistoryReportIndexName, keyword, map[string]interface{}{"BaseOperationType": operationType}, from, pageSize)
    if err != nil {
        return
    }
    if len(ids) == 0 {
        return
    }
    recordIds = make([]int, 0, len(ids))
    for _, id := range ids {
        recordIds = append(recordIds, cast.ToInt(id))
    }
    return
}
func AddNewHistoryReportRecord(moveHistoryId int) {
    var report HistoryReport
    record, err := models.NewMoveHistorySearch().SetID(uint(moveHistoryId)).First()
    if err != nil {
        logx.Errorf("AddNewHistoryReportRecord Find err:%v", err)
        return
    }
    err = structx.AssignTo(record, &report)
    if err != nil {
        logx.Errorf("AddNewHistoryReportRecord AssignTo err:%v", err)
        return
    }
    err = blevex.Add(HistoryReportIndexName, strconv.Itoa(moveHistoryId), report)
    if err != nil {
        logx.Errorf("AddNewHistoryReportRecord bleve add err:%v", err)
        return
    }
}
service/search.go
New file
@@ -0,0 +1,86 @@
package service
import (
    "github.com/spf13/cast"
    "strconv"
    "wms/models"
    "wms/pkg/blevex"
    "wms/pkg/logx"
)
type LocationReport struct {
    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 (
    LocationReportIndexName = "locationReport.bleve"
)
func InitLocationReportData() {
    docCount, err := blevex.DocCount(LocationReportIndexName)
    if err != nil {
        logx.Errorf("InitLocationReportData get doc count err:%v", err)
        return
    }
    if docCount > 0 {
        return
    }
    reports := make([]*LocationReport, 0)
    search := models.NewLocationProductAmountSearch()
    err = search.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").Scan(&reports).Error
    if err != nil {
        logx.Errorf("InitLocationReportData scan err:%v", err)
    }
    for _, result := range reports {
        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)
        }
    }
    return
}
func SearchLocationReport(keyword string, page, pageSize int) (list []*models.LocationProductAmount, total uint64, err error) {
    var ids []string
    from := (page - 1) * pageSize
    ids, total, err = blevex.Search(LocationReportIndexName, keyword, from, pageSize)
    if err != nil {
        return
    }
    if len(ids) == 0 {
        return
    }
    recordIds := make([]int, 0, len(ids))
    for _, id := range ids {
        recordIds = append(recordIds, cast.ToInt(id))
    }
    list, err = models.NewLocationProductAmountSearch().SetPreload(true).SetIds(recordIds).Find()
    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
    }
}