| | |
| | | "wms/models" |
| | | "wms/request" |
| | | "wms/response" |
| | | "wms/service" |
| | | ) |
| | | |
| | | type LocationProductAmountController struct { |
| | |
| | | }); err != nil { |
| | | return err |
| | | } |
| | | |
| | | service.AddNewLocationReportRecord(locAmount.Id) |
| | | return nil |
| | | } |
| | | |
| | |
| | | "wms/models" |
| | | "wms/request" |
| | | "wms/response" |
| | | "wms/service" |
| | | ) |
| | | |
| | | type ReportFormsController struct { |
| | |
| | | // @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(¶ms); 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(¶ms); 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)) |
| | | } |
| | |
| | | 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 |
| | |
| | | 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/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 |
| | | github.com/yanyiwu/gojieba v1.3.0 |
| | | go.uber.org/zap v1.24.0 |
| | | golang.org/x/crypto v0.15.0 |
| | | google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 |
| | |
| | | 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/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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | 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= |
| | |
| | | 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/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= |
| | |
| | | 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= |
| | |
| | | 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= |
| | |
| | | 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= |
| | |
| | | github.com/xuri/nfp v0.0.0-20230819163627-dc951e3ffe1a/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ= |
| | | github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 h1:qhbILQo1K3mphbwKh1vNm4oGezE1eF9fQWmNiIpSfI4= |
| | | github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ= |
| | | github.com/yanyiwu/gojieba v1.3.0 h1:6VeaPOR+MawnImdeSvWNr7rP4tvUfnGlEKaoBnR33Ds= |
| | | github.com/yanyiwu/gojieba v1.3.0/go.mod h1:54wkP7sMJ6bklf7yPl6F+JG71dzVUU1WigZbR47nGdY= |
| | | github.com/yashtewari/glob-intersection v0.2.0 h1:8iuHdN88yYuCzCdjt0gDe+6bAhUwBeEWqThExu54RFg= |
| | | github.com/yashtewari/glob-intersection v0.2.0/go.mod h1:LK7pIC3piUjovexikBbJ26Yml7g8xa5bsjfx2v1fwok= |
| | | github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= |
| | |
| | | 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= |
| | |
| | | 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= |
| | |
| | | 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= |
| | |
| | | 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= |
| | |
| | | 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= |
| | |
| | | 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= |
| | |
| | | "wms/proto/product_inventory" |
| | | "wms/proto/purchase_wms" |
| | | "wms/router" |
| | | "wms/service" |
| | | ) |
| | | |
| | | func main() { |
| | |
| | | panic(fmt.Sprintf("grpc server init error: %v", err.Error())) |
| | | } |
| | | }() |
| | | |
| | | go service.InitLocationReportData() |
| | | go service.InitHistoryReportData() |
| | | |
| | | logx.Error(server.ListenAndServe().Error()) |
| | | } |
| | | |
| | |
| | | Attachment{}, |
| | | LogisticCompany{}, |
| | | FileTemplateAttachment{}, |
| | | MoveHistory{}, |
| | | ) |
| | | return err |
| | | } |
New file |
| | |
| | | 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 |
| | | } |
New file |
| | |
| | | package blevex |
| | | |
| | | import ( |
| | | "errors" |
| | | |
| | | "github.com/blevesearch/bleve/v2/analysis" |
| | | "github.com/blevesearch/bleve/v2/registry" |
| | | ) |
| | | |
| | | 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 |
| | | } |
| | | |
| | | jbtk, ok := tokenizer.(*JiebaTokenizer) |
| | | if !ok { |
| | | return nil, errors.New("tokenizer must be of type jieba") |
| | | } |
| | | alz := &JiebaAnalyzer{ |
| | | Tokenizer: jbtk, |
| | | } |
| | | return alz, nil |
| | | } |
| | | |
| | | func init() { |
| | | registry.RegisterAnalyzer("gojieba", analyzerConstructor) |
| | | } |
| | | |
| | | // JiebaAnalyzer from analysis.DefaultAnalyzer |
| | | type JiebaAnalyzer struct { |
| | | CharFilters []analysis.CharFilter |
| | | Tokenizer *JiebaTokenizer |
| | | TokenFilters []analysis.TokenFilter |
| | | } |
| | | |
| | | func (a *JiebaAnalyzer) 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 (a *JiebaAnalyzer) Free() { |
| | | if a.Tokenizer != nil { |
| | | a.Tokenizer.Free() |
| | | } else { |
| | | panic("JiebaAnalyzer.Tokenizer is nil, this should not happen") |
| | | } |
| | | } |
New file |
| | |
| | | package blevex |
| | | |
| | | import ( |
| | | "fmt" |
| | | "github.com/blevesearch/bleve/v2" |
| | | "github.com/blevesearch/bleve/v2/mapping" |
| | | "github.com/yanyiwu/gojieba" |
| | | "sync" |
| | | ) |
| | | |
| | | // InitAnalyzer 加载自定义分词器(结巴分词) |
| | | |
| | | var defaultAnalyzer *mapping.IndexMappingImpl |
| | | |
| | | func InitAnalyzer() { |
| | | indexMapping := bleve.NewIndexMapping() |
| | | //os.RemoveAll(IndexDir) |
| | | //// clean index when example finished |
| | | //defer os.RemoveAll(IndexDir) |
| | | |
| | | err := indexMapping.AddCustomTokenizer("gojieba", |
| | | map[string]interface{}{ |
| | | "dictpath": gojieba.DICT_PATH, |
| | | "hmmpath": gojieba.HMM_PATH, |
| | | "userdictpath": gojieba.USER_DICT_PATH, |
| | | "idf": gojieba.IDF_PATH, |
| | | "stop_words": gojieba.STOP_WORDS_PATH, |
| | | "type": "gojieba", |
| | | }, |
| | | ) |
| | | if err != nil { |
| | | panic(err) |
| | | } |
| | | err = indexMapping.AddCustomAnalyzer("gojieba", |
| | | map[string]interface{}{ |
| | | "type": "gojieba", |
| | | "tokenizer": "gojieba", |
| | | }, |
| | | ) |
| | | if err != nil { |
| | | panic(err) |
| | | } |
| | | indexMapping.DefaultAnalyzer = "gojieba" |
| | | 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 |
| | | } |
New file |
| | |
| | | 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() |
| | | } |
New file |
| | |
| | | package blevex |
| | | |
| | | import ( |
| | | "errors" |
| | | |
| | | "github.com/blevesearch/bleve/v2/analysis" |
| | | "github.com/blevesearch/bleve/v2/registry" |
| | | "github.com/yanyiwu/gojieba" |
| | | ) |
| | | |
| | | type JiebaTokenizer struct { |
| | | handle *gojieba.Jieba |
| | | } |
| | | |
| | | var _ analysis.Tokenizer = &JiebaTokenizer{} |
| | | |
| | | func NewJiebaTokenizer(dictpath, hmmpath, userdictpath, idf, stop_words string) *JiebaTokenizer { |
| | | x := gojieba.NewJieba(dictpath, hmmpath, userdictpath, idf, stop_words) |
| | | return &JiebaTokenizer{x} |
| | | } |
| | | |
| | | func (x *JiebaTokenizer) Free() { |
| | | x.handle.Free() |
| | | } |
| | | |
| | | // Analyze([]byte) TokenStream |
| | | func (x *JiebaTokenizer) Tokenize(sentence []byte) analysis.TokenStream { |
| | | result := make(analysis.TokenStream, 0) |
| | | pos := 1 |
| | | words := x.handle.Tokenize(string(sentence), gojieba.SearchMode, true) |
| | | for _, word := range words { |
| | | token := analysis.Token{ |
| | | Term: []byte(word.Str), |
| | | Start: word.Start, |
| | | End: word.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") |
| | | } |
| | | hmmpath, ok := config["hmmpath"].(string) |
| | | if !ok { |
| | | return nil, errors.New("config hmmpath not found") |
| | | } |
| | | userdictpath, ok := config["userdictpath"].(string) |
| | | if !ok { |
| | | return nil, errors.New("config userdictpath not found") |
| | | } |
| | | idf, ok := config["idf"].(string) |
| | | if !ok { |
| | | return nil, errors.New("config idf not found") |
| | | } |
| | | stop_words, ok := config["stop_words"].(string) |
| | | if !ok { |
| | | return nil, errors.New("config stop_words not found") |
| | | } |
| | | return NewJiebaTokenizer(dictpath, hmmpath, userdictpath, idf, stop_words), nil |
| | | } |
| | | |
| | | func init() { |
| | | registry.RegisterTokenizer("gojieba", tokenizerConstructor) |
| | | } |
New file |
| | |
| | | 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 |
| | | } |
| | | } |
New file |
| | |
| | | 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 |
| | | } |
| | | } |