|
@@ -7,6 +7,7 @@ import (
|
|
"reflect"
|
|
"reflect"
|
|
"youngee_b_api/model/common_model"
|
|
"youngee_b_api/model/common_model"
|
|
"youngee_b_api/model/gorm_model"
|
|
"youngee_b_api/model/gorm_model"
|
|
|
|
+ "youngee_b_api/util"
|
|
)
|
|
)
|
|
|
|
|
|
func CreateProject(ctx context.Context, projectInfo gorm_model.ProjectInfo) (*int64, error) {
|
|
func CreateProject(ctx context.Context, projectInfo gorm_model.ProjectInfo) (*int64, error) {
|
|
@@ -22,7 +23,6 @@ func GetFullProjectList(ctx context.Context, enterpriseID int64, pageSize, pageN
|
|
db := GetReadDB(ctx)
|
|
db := GetReadDB(ctx)
|
|
// 根据企业id过滤
|
|
// 根据企业id过滤
|
|
db = db.Debug().Model(gorm_model.ProjectInfo{}).Where("enterprise_id = ?", enterpriseID)
|
|
db = db.Debug().Model(gorm_model.ProjectInfo{}).Where("enterprise_id = ?", enterpriseID)
|
|
- logrus.Printf("db:%V",db)
|
|
|
|
// 根据Project条件过滤
|
|
// 根据Project条件过滤
|
|
conditionType := reflect.TypeOf(condition).Elem()
|
|
conditionType := reflect.TypeOf(condition).Elem()
|
|
conditionValue := reflect.ValueOf(condition).Elem()
|
|
conditionValue := reflect.ValueOf(condition).Elem()
|
|
@@ -30,9 +30,20 @@ func GetFullProjectList(ctx context.Context, enterpriseID int64, pageSize, pageN
|
|
field := conditionType.Field(i)
|
|
field := conditionType.Field(i)
|
|
tag := field.Tag.Get("condition")
|
|
tag := field.Tag.Get("condition")
|
|
value := conditionValue.FieldByName(field.Name)
|
|
value := conditionValue.FieldByName(field.Name)
|
|
- db = db.Where(fmt.Sprintf("%s = ?", tag), value)
|
|
|
|
|
|
+ //if ! isBlank(value) {
|
|
|
|
+ // db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
|
+ //}
|
|
|
|
+ if ! util.IsBlank(value) && tag != "updated_at"&& tag != "project_name"{
|
|
|
|
+ db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
|
+ }
|
|
|
|
+ if tag == "updated_at"{
|
|
|
|
+ fmt.Println(value.Interface())
|
|
|
|
+ db = db.Where(fmt.Sprintf("%s > ?", tag), value.Interface())
|
|
|
|
+ }
|
|
|
|
+ if tag == "project_name" && ! util.IsBlank(value){
|
|
|
|
+ db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- logrus.Printf("db:%V",db)
|
|
|
|
// 查询总数
|
|
// 查询总数
|
|
var total int64
|
|
var total int64
|
|
var fullProjects []*gorm_model.ProjectInfo
|
|
var fullProjects []*gorm_model.ProjectInfo
|
|
@@ -41,9 +52,9 @@ func GetFullProjectList(ctx context.Context, enterpriseID int64, pageSize, pageN
|
|
return nil, 0, err
|
|
return nil, 0, err
|
|
}
|
|
}
|
|
// 查询该页数据
|
|
// 查询该页数据
|
|
- limit := pageNum
|
|
|
|
|
|
+ limit := pageSize
|
|
offset := pageSize * pageNum // assert pageNum start with 0
|
|
offset := pageSize * pageNum // assert pageNum start with 0
|
|
- err := db.Order("updated_at desc").Limit(int(limit)).Offset(int(offset)).Find(&fullProjects).Error
|
|
|
|
|
|
+ err := db.Order("project_id").Limit(int(limit)).Offset(int(offset)).Find(&fullProjects).Error
|
|
if err != nil {
|
|
if err != nil {
|
|
logrus.WithContext(ctx).Errorf("[GetFullProjectList] error query mysql total, err:%+v", err)
|
|
logrus.WithContext(ctx).Errorf("[GetFullProjectList] error query mysql total, err:%+v", err)
|
|
return nil, 0, err
|
|
return nil, 0, err
|