浏览代码

更新项目列表

yuliang1112 3 年之前
父节点
当前提交
1036e9b10d

+ 23 - 20
consts/project.go

@@ -1,7 +1,16 @@
 package consts
 
 var projectStatusMap = map[int64]string{
-	1: "",
+	1: "创建中",
+	2: "待审核",
+	3: "审核通过",
+	4: "招募中",
+	5: "招募完毕",
+	6: "待支付",
+	7: "已支付",
+	8: "失效",
+	9: "执行中",
+	10: "已结案",
 }
 
 func GetProjectStatus(status int64) string {
@@ -13,7 +22,13 @@ func GetProjectStatus(status int64) string {
 }
 
 var ProjectPlatformMap = map[int64]string{
-	1: "",
+	1: "小红书",
+	2: "抖音",
+	3: "微博",
+	4: "快手",
+	5: "b站",
+	6: "大众点评",
+	7: "知乎",
 }
 
 func GetProjectPlatform(status int64) string {
@@ -25,7 +40,10 @@ func GetProjectPlatform(status int64) string {
 }
 
 var ProjectFormMap = map[int64]string{
-	1: "",
+	1: "实体商品寄拍",
+	2: "虚拟产品测评",
+	3: "线下探店打卡",
+	4: "素材微原创",
 }
 
 func GetProjectForm(status int64) string {
@@ -36,24 +54,9 @@ func GetProjectForm(status int64) string {
 	return "未知"
 }
 
-var ProjectFeeFormMap = map[int64]string{
-	1: "",
-}
-
-func GetProjectFeeForms(statuses ...int64) []string {
-	var toasts []string
-	for _, status := range statuses {
-		toast, contain := ProjectFeeFormMap[status]
-		if !contain {
-			toast = "未知"
-		}
-		toasts = append(toasts, toast)
-	}
-	return toasts
-}
-
 var ProjectContentTypeMap = map[int64]string{
-	1: "",
+	1: "图文",
+	2: "视频",
 }
 
 func GetProjectContentType(status int64) string {

+ 16 - 5
db/project.go

@@ -7,6 +7,7 @@ import (
 	"reflect"
 	"youngee_b_api/model/common_model"
 	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/util"
 )
 
 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)
 	// 根据企业id过滤
 	db = db.Debug().Model(gorm_model.ProjectInfo{}).Where("enterprise_id = ?", enterpriseID)
-	logrus.Printf("db:%V",db)
 	// 根据Project条件过滤
 	conditionType := reflect.TypeOf(condition).Elem()
 	conditionValue := reflect.ValueOf(condition).Elem()
@@ -30,9 +30,20 @@ func GetFullProjectList(ctx context.Context, enterpriseID int64, pageSize, pageN
 		field := conditionType.Field(i)
 		tag := field.Tag.Get("condition")
 		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 fullProjects []*gorm_model.ProjectInfo
@@ -41,9 +52,9 @@ func GetFullProjectList(ctx context.Context, enterpriseID int64, pageSize, pageN
 		return nil, 0, err
 	}
 	// 查询该页数据
-	limit := pageNum
+	limit := pageSize
 	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 {
 		logrus.WithContext(ctx).Errorf("[GetFullProjectList] error query mysql total, err:%+v", err)
 		return nil, 0, err

+ 12 - 3
handler/project_list.go

@@ -4,6 +4,7 @@ import (
 	"errors"
 	"fmt"
 	"github.com/issue9/conv"
+	"time"
 	"youngee_b_api/consts"
 	"youngee_b_api/middleware"
 	"youngee_b_api/model/http_model"
@@ -68,20 +69,28 @@ func (h *FullProjectListHandler) run() {
 }
 func (h *FullProjectListHandler) checkParam() error {
 	var errs []error
-	if h.req.PageNum <= 0 || h.req.PageSize <= 0 {
+	if h.req.PageNum < 0 || h.req.PageSize <= 0 {
 		errs = append(errs, errors.New("page param error"))
 	}
+	h.req.PageNum--
 	h.req.ProjectForm = util.IsNull(h.req.ProjectForm)
-	h.req.PageNum++
 	if _, err := conv.Int64(h.req.ProjectForm); err != nil {
 		errs = append(errs, err)
 	}
+	h.req.ProjectId = util.IsNull(h.req.ProjectId)
+	if _, err := conv.Int64(h.req.ProjectId); err != nil {
+		errs = append(errs, err)
+	}
+	//h.req.ProjectName = util.IsNull(h.req.ProjectName)
+
 	h.req.ProjectStatus = util.IsNull(h.req.ProjectStatus)
 	if _, err := conv.Int64(h.req.ProjectStatus); err != nil {
 		errs = append(errs, err)
 	}
+	formatTime, _ := time.Parse("2006-01-02 15:04:05", h.req.ProjectUpdated)
+	//fmt.Println(h.req.ProjectUpdated)
 	h.req.ProjectUpdated = util.IsNull(h.req.ProjectUpdated)
-	if _, err := conv.Int64(h.req.ProjectUpdated); err != nil {
+	if _, err := conv.Int64(formatTime.Unix()); err != nil {
 		errs = append(errs, err)
 	}
 	h.req.ProjectContentType = util.IsNull(h.req.ProjectContentType)

+ 2 - 0
model/common_model/project_condition.go

@@ -1,6 +1,8 @@
 package common_model
 
 type ProjectCondition struct {
+	ProjectId          int64 `condition:"project_id"`       // 项目ID
+	ProjectName        string `condition:"project_name"`     // 项目名
 	ProjectStatus      int64  `condition:"project_status"`   // 项目状态
 	ProjectPlatform    int64  `condition:"project_platform"` // 项目平台
 	ProjectForm        int64  `condition:"project_form"`     // 项目形式

+ 4 - 2
model/http_model/full_project_list.go

@@ -3,10 +3,12 @@ package http_model
 type FullProjectListRequest struct {
 	PageSize           int32  `json:"page_size"`
 	PageNum            int32  `json:"page_num"`
+	ProjectId          string `json:"project_id"`           // 项目ID
+	ProjectName        string `json:"project_name"`         // 项目名
 	ProjectStatus      string `json:"project_status"`       // 项目状态
 	ProjectPlatform    string `json:"project_platform"`     // 项目平台
 	ProjectForm        string `json:"project_form"`         // 项目形式
-	ProjectFeeForms    string `json:"project_fee_forms"`    // 稿费形式
+	//ProjectFeeForms    string `json:"project_fee_forms"`    // 稿费形式
 	ProjectContentType string `json:"project_content_type"` // 内容形式
 	ProjectUpdated     string `json:"project_updated"`      // 最后操作时间
 }
@@ -16,7 +18,7 @@ type FullProjectPreview struct {
 	ProjectStatus      string   `json:"project_status"`       // 项目状态
 	ProjectPlatform    string   `json:"project_platform"`     // 项目平台
 	ProjectForm        string   `json:"project_form"`         // 项目形式
-	ProjectFeeForms    []string `json:"project_fee_forms"`    // 稿费形式
+	//ProjectFeeForms    []string `json:"project_fee_forms"`    // 稿费形式
 	ProjectContentType string   `json:"project_content_type"` // 内容形式
 	ProjectUpdated     string   `json:"project_updated"`      // 最后操作时间
 }

+ 4 - 5
pack/full_project.go

@@ -16,16 +16,15 @@ func MGormFullProjectToHttpFullProjectPreview(gormProjectInfos []*gorm_model.Pro
 	return httpProjectPreviews
 }
 func GormFullProjectToHttpFullProjectPreview(gormProjectInfo *gorm_model.ProjectInfo) *http_model.FullProjectPreview {
-	var feeForms []int64
-
+	updatedTime := conv.MustString(gormProjectInfo.UpdatedAt)
+	updatedTime = updatedTime[0:19]
 	return &http_model.FullProjectPreview{
 		ProjectId:          conv.MustString(gormProjectInfo.ProjectID),
 		ProjectName:        gormProjectInfo.ProjectName,
 		ProjectStatus:      consts.GetProjectStatus(gormProjectInfo.ProjectStatus),
 		ProjectPlatform:    consts.GetProjectPlatform(gormProjectInfo.ProjectPlatform),
 		ProjectForm:        consts.GetProjectForm(gormProjectInfo.ProjectForm),
-		ProjectFeeForms:    consts.GetProjectFeeForms(feeForms...),
-		ProjectContentType: consts.GetProjectContentType(gormProjectInfo.ProjectType),
-		ProjectUpdated:     conv.MustString(gormProjectInfo.UpdatedAt.Unix()),
+		ProjectContentType: consts.GetProjectContentType(gormProjectInfo.ContentType),
+		ProjectUpdated:     updatedTime,
 	}
 }

+ 5 - 3
pack/full_project_condition.go

@@ -2,18 +2,20 @@ package pack
 
 import (
 	"github.com/issue9/conv"
-	"time"
 	"youngee_b_api/model/common_model"
 	"youngee_b_api/model/http_model"
 )
 
 func HttpFullProjectRequestToCondition(req *http_model.FullProjectListRequest) *common_model.ProjectCondition {
-	projectUpdated := time.UnixMilli(conv.MustInt64(req.ProjectUpdated))
+	projectUpdated := conv.MustString(req.ProjectUpdated)
+	projectName := req.ProjectName
 	return &common_model.ProjectCondition{
+		ProjectId:          conv.MustInt64(req.ProjectId,0),
+		ProjectName:        projectName,
 		ProjectStatus:      conv.MustInt64(req.ProjectStatus,0),
 		ProjectPlatform:    conv.MustInt64(req.ProjectPlatform,0),
 		ProjectForm:        conv.MustInt64(req.ProjectForm,0),
 		ProjectContentType: conv.MustInt64(req.ProjectContentType,0),
-		ProjectUpdated:     projectUpdated.String(),
+		ProjectUpdated:     projectUpdated,
 	}
 }

+ 22 - 0
util/type.go

@@ -1,8 +1,30 @@
 package util
 
+import "reflect"
+
+// 判断是否为空字符串
 func IsNull(s string) string {
 	if s == ""{
 		return "0"
 	}
 	return s
 }
+
+// 判断 reflect.Value 是否为空
+func IsBlank(value reflect.Value) bool {
+	switch value.Kind() {
+	case reflect.String:
+		return value.Len() == 0
+	case reflect.Bool:
+		return !value.Bool()
+	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
+		return value.Int() == 0
+	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
+		return value.Uint() == 0
+	case reflect.Float32, reflect.Float64:
+		return value.Float() == 0
+	case reflect.Interface, reflect.Ptr:
+		return value.IsNil()
+	}
+	return reflect.DeepEqual(value.Interface(), reflect.Zero(value.Type()).Interface())
+}