fix
wangpengfei
2023-08-11 be953da6ecba5036e63eac2bb5851e04dca1e8f7
fix

add conditional matching to collectionProjection
5个文件已修改
39 ■■■■ 已修改文件
api/v1/collectionProjection.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/collectionProjection.go 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/contact.go 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/collectionProjection.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/collectionProjection.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/collectionProjection.go
@@ -125,7 +125,7 @@
        return
    }
    total, errCode, list := collectionProjectionService.GetCollectionProjectionList(params.Page, params.PageSize)
    total, errCode, list := collectionProjectionService.GetCollectionProjectionList(params.Page, params.PageSize, params.SearchMap)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
model/collectionProjection.go
@@ -19,10 +19,11 @@
    CollectionProjectionSearch struct {
        CollectionProjection
        Orm      *gorm.DB
        OrderBy  string
        PageNum  int
        PageSize int
        Orm       *gorm.DB
        SearchMap map[string]interface{}
        OrderBy   string
        PageNum   int
        PageSize  int
    }
)
@@ -40,6 +41,21 @@
    var db = slf.Orm.Model(&CollectionProjection{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if len(slf.SearchMap) > 0 {
        for key, value := range slf.SearchMap {
            switch v := value.(type) {
            case string:
                if key == "estimated_collection_date" {
                    db = db.Where(key+" = ?", v)
                }
            case int:
                if key == "client_id" {
                    db = db.Where(key+" = ?", v)
                }
            }
        }
    }
    return db
@@ -92,3 +108,8 @@
    slf.PageNum, slf.PageSize = page, size
    return slf
}
func (slf *CollectionProjectionSearch) SetSearchMap(data map[string]interface{}) *CollectionProjectionSearch {
    slf.SearchMap = data
    return slf
}
model/contact.go
@@ -93,6 +93,9 @@
                    }
                }
            case int:
                if key == "client_id" {
                    db = db.Where("client_id = ?", v)
                }
            }
        }
    }
model/request/collectionProjection.go
@@ -17,4 +17,5 @@
type GetCollectionProjectionList struct {
    PageInfo
    SearchMap map[string]interface{}
}
service/collectionProjection.go
@@ -34,9 +34,9 @@
    return ecode.OK
}
func (CollectionProjectionService) GetCollectionProjectionList(page, pageSize int) (int64, int, []*model.CollectionProjection) {
func (CollectionProjectionService) GetCollectionProjectionList(page, pageSize int, data map[string]interface{}) (int64, int, []*model.CollectionProjection) {
    total, err, list := model.NewCollectionProjectionSearch().SetPage(page, pageSize).Find()
    total, err, list := model.NewCollectionProjectionSearch().SetPage(page, pageSize).SetSearchMap(data).Find()
    if err != nil {
        return total, ecode.CollectionProjectionListErr, list
    }