| | |
| | | // @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)) |
| | | } |
| | |
| | | } |
| | | } |
| | | var ( |
| | | amounts []*models.LocationProductAmount |
| | | total int64 |
| | | err error |
| | | 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, total, err = models.NewLocationProductAmountSearch().SetPage(params.Page, params.PageSize).SetPreload(true).SetKeyword(params.KeyWord).SetProductId(params.ProductId).SetLocationIds(ids).FindByPage() |
| | | 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 service.InitLocationReportData() |
| | | go service.InitHistoryReportData() |
| | | |
| | | logx.Error(server.ListenAndServe().Error()) |
| | | } |
| | |
| | | ReorderRule{}, |
| | | Attachment{}, |
| | | LogisticCompany{}, |
| | | 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 |
| | | } |
| | |
| | | package blevex |
| | | |
| | | import ( |
| | | "fmt" |
| | | "github.com/blevesearch/bleve/v2" |
| | | "github.com/blevesearch/bleve/v2/mapping" |
| | | "github.com/yanyiwu/gojieba" |
| | |
| | | } |
| | | return index, err |
| | | } |
| | | func Search(indexName string, keyword string) (ids []string, err error) { |
| | | func Search(indexName string, keyword string, from, size int) (ids []string, total uint64, err error) { |
| | | index, err := LoadIndex(indexName) |
| | | if err != nil { |
| | | return nil, err |
| | | return |
| | | } |
| | | req := bleve.NewSearchRequest(bleve.NewQueryStringQuery(keyword)) |
| | | req.From = from |
| | | req.Size = size |
| | | res, err := index.Search(req) |
| | | if err != nil { |
| | | panic(err) |
| | | return nil, 0, err |
| | | } |
| | | if res == nil || res.Total == 0 { |
| | | return ids, nil |
| | | if res == nil { |
| | | return |
| | | } |
| | | for _, ret := range dealResult(res) { |
| | | ids = append(ids, ret.Id) |
| | | } |
| | | return ids, nil |
| | | 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 { |
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 |
| | | } |
| | | } |
| | |
| | | return |
| | | } |
| | | |
| | | func SearchLocationReport(keyword string, page, pageSize int) (list []*models.LocationProductAmount, total int64, err error) { |
| | | ids, err := blevex.Search(LocationReportIndexName, keyword) |
| | | 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 |
| | | } |
| | |
| | | for _, id := range ids { |
| | | recordIds = append(recordIds, cast.ToInt(id)) |
| | | } |
| | | list, total, err = models.NewLocationProductAmountSearch().SetPage(page, pageSize).SetPreload(true).SetIds(recordIds).FindByPage() |
| | | list, err = models.NewLocationProductAmountSearch().SetPreload(true).SetIds(recordIds).Find() |
| | | return |
| | | } |
| | | |