refactor(wms/mes): 统一多场景查询逻辑,移除关键字混搜
1. 移除所有多字段关键字混搜,改为各筛选字段独立查询 2. 调整excel导出相关逻辑,优化文件名处理与导入模板 3. 修复物料导入的类型解析与token获取逻辑 4. 更新依赖与前端页面文案、筛选参数
This commit is contained in:
@@ -71,24 +71,25 @@ func (s *Service) DeleteProductType(ctx context.Context, id int) error {
|
||||
// ListProductTypes 全量列表(下拉/兼容形态,id asc 新建在底部)。
|
||||
// degraded=false 表示 WMS 不可达、数据来自本地只读缓存。
|
||||
func (s *Service) ListProductTypes(ctx context.Context) ([]wmsclient.ProductTypeRow, bool, error) {
|
||||
list, err := s.ctx.Wms.ProductTypes(ctx, "", "")
|
||||
list, err := s.ctx.Wms.ProductTypes(ctx, "")
|
||||
if err == nil {
|
||||
return list, true, nil
|
||||
}
|
||||
fallback, ferr := s.localProductTypes(ctx, "")
|
||||
fallback, ferr := s.localProductTypes(ctx, "", "", "")
|
||||
if ferr != nil {
|
||||
return nil, false, errors.New("WMS 不可达且本地缓存读取失败")
|
||||
}
|
||||
return fallback, false, nil
|
||||
}
|
||||
|
||||
// ListProductTypesPage 分页+搜索(管理页真分页)
|
||||
func (s *Service) ListProductTypesPage(ctx context.Context, keyword, isActive string, page, pageSize int) (int64, []wmsclient.ProductTypeRow, bool, error) {
|
||||
total, list, err := s.ctx.Wms.ProductTypePage(ctx, keyword, isActive, page, pageSize)
|
||||
// ListProductTypesPage 分页+搜索(管理页真分页)。
|
||||
// 2026-09-08 禁止关键字混搜:编码/名称/类别各自独立模糊。
|
||||
func (s *Service) ListProductTypesPage(ctx context.Context, code, name, category, isActive string, page, pageSize int) (int64, []wmsclient.ProductTypeRow, bool, error) {
|
||||
total, list, err := s.ctx.Wms.ProductTypePage(ctx, code, name, category, isActive, page, pageSize)
|
||||
if err == nil {
|
||||
return total, list, true, nil
|
||||
}
|
||||
fallback, ferr := s.localProductTypes(ctx, keyword)
|
||||
fallback, ferr := s.localProductTypes(ctx, code, name, category)
|
||||
if ferr != nil {
|
||||
return 0, nil, false, errors.New("WMS 不可达且本地缓存读取失败")
|
||||
}
|
||||
@@ -104,7 +105,7 @@ func (s *Service) ListProductTypesPage(ctx context.Context, keyword, isActive st
|
||||
}
|
||||
|
||||
func (s *Service) productTypeByID(ctx context.Context, id int) (*wmsclient.ProductTypeRow, error) {
|
||||
list, err := s.ctx.Wms.ProductTypes(ctx, "", "")
|
||||
list, err := s.ctx.Wms.ProductTypes(ctx, "")
|
||||
if err == nil {
|
||||
for i := range list {
|
||||
if list[i].ID == id {
|
||||
@@ -121,18 +122,24 @@ func (s *Service) productTypeByID(ctx context.Context, id int) (*wmsclient.Produ
|
||||
return &wmsclient.ProductTypeRow{ID: pt.ID, Code: pt.Code, Name: pt.Name}, nil
|
||||
}
|
||||
|
||||
func (s *Service) localProductTypes(ctx context.Context, keyword string) ([]wmsclient.ProductTypeRow, error) {
|
||||
// localProductTypes 本地只读缓存过滤(降级用):编码/名称/类别各自独立模糊匹配
|
||||
func (s *Service) localProductTypes(ctx context.Context, code, name, category string) ([]wmsclient.ProductTypeRow, error) {
|
||||
list, err := s.ctx.EntClient.ProductType.Query().Order(ent.Asc(producttype.FieldID)).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
codeKw := strings.ToLower(strings.TrimSpace(code))
|
||||
nameKw := strings.ToLower(strings.TrimSpace(name))
|
||||
catKw := strings.ToLower(strings.TrimSpace(category))
|
||||
rows := make([]wmsclient.ProductTypeRow, 0, len(list))
|
||||
kw := strings.ToLower(strings.TrimSpace(keyword))
|
||||
for _, p := range list {
|
||||
if kw != "" &&
|
||||
!strings.Contains(strings.ToLower(p.Code), kw) &&
|
||||
!strings.Contains(strings.ToLower(p.Name), kw) &&
|
||||
!strings.Contains(strings.ToLower(p.Category), kw) {
|
||||
if codeKw != "" && !strings.Contains(strings.ToLower(p.Code), codeKw) {
|
||||
continue
|
||||
}
|
||||
if nameKw != "" && !strings.Contains(strings.ToLower(p.Name), nameKw) {
|
||||
continue
|
||||
}
|
||||
if catKw != "" && !strings.Contains(strings.ToLower(p.Category), catKw) {
|
||||
continue
|
||||
}
|
||||
rows = append(rows, wmsclient.ProductTypeRow{
|
||||
|
||||
Reference in New Issue
Block a user