|
@@ -3,12 +3,14 @@ package db
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
"fmt"
|
|
"fmt"
|
|
- "github.com/sirupsen/logrus"
|
|
|
|
- "gorm.io/gorm"
|
|
|
|
"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/pack"
|
|
"youngee_b_api/util"
|
|
"youngee_b_api/util"
|
|
|
|
+
|
|
|
|
+ "github.com/sirupsen/logrus"
|
|
|
|
+ "gorm.io/gorm"
|
|
)
|
|
)
|
|
|
|
|
|
func CreateProject(ctx context.Context, projectInfo gorm_model.ProjectInfo) (*int64, error) {
|
|
func CreateProject(ctx context.Context, projectInfo gorm_model.ProjectInfo) (*int64, error) {
|
|
@@ -27,11 +29,11 @@ func UpdateProject(ctx context.Context, project gorm_model.ProjectInfo) (*int64,
|
|
}
|
|
}
|
|
return &project.ProjectID, nil
|
|
return &project.ProjectID, nil
|
|
}
|
|
}
|
|
|
|
+
|
|
func GetFullProjectList(ctx context.Context, enterpriseID int64, pageSize, pageNum int32, condition *common_model.ProjectCondition) ([]*gorm_model.ProjectInfo, int64, error) {
|
|
func GetFullProjectList(ctx context.Context, enterpriseID int64, pageSize, pageNum int32, condition *common_model.ProjectCondition) ([]*gorm_model.ProjectInfo, int64, error) {
|
|
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()
|
|
@@ -39,21 +41,19 @@ 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)
|
|
- //if ! isBlank(value) {
|
|
|
|
- // db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
|
- //}
|
|
|
|
|
|
+ if tag == "project_status" && util.IsBlank(value) {
|
|
|
|
+ db = db.Where(fmt.Sprintf("project_status != 1"))
|
|
|
|
+ }
|
|
if !util.IsBlank(value) && tag != "updated_at" && tag != "project_name" {
|
|
if !util.IsBlank(value) && tag != "updated_at" && tag != "project_name" {
|
|
db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
}
|
|
}
|
|
if tag == "updated_at" {
|
|
if tag == "updated_at" {
|
|
- fmt.Println(value.Interface())
|
|
|
|
db = db.Where(fmt.Sprintf("%s > ?", tag), value.Interface())
|
|
db = db.Where(fmt.Sprintf("%s > ?", tag), value.Interface())
|
|
}
|
|
}
|
|
if tag == "project_name" && !util.IsBlank(value) {
|
|
if tag == "project_name" && !util.IsBlank(value) {
|
|
db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
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
|
|
@@ -72,6 +72,100 @@ func GetFullProjectList(ctx context.Context, enterpriseID int64, pageSize, pageN
|
|
return fullProjects, total, nil
|
|
return fullProjects, total, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func GetProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum int32, conditions *common_model.TaskConditions) ([]*gorm_model.ProjectTaskInfo, int64, error) {
|
|
|
|
+ db := GetReadDB(ctx)
|
|
|
|
+ // 查询task表信息
|
|
|
|
+ db = db.Debug().Model(gorm_model.YoungeeTaskInfo{})
|
|
|
|
+ // 根据Project条件过滤
|
|
|
|
+ conditionType := reflect.TypeOf(conditions).Elem()
|
|
|
|
+ conditionValue := reflect.ValueOf(conditions).Elem()
|
|
|
|
+ for i := 0; i < conditionType.NumField(); i++ {
|
|
|
|
+ field := conditionType.Field(i)
|
|
|
|
+ tag := field.Tag.Get("condition")
|
|
|
|
+ value := conditionValue.FieldByName(field.Name)
|
|
|
|
+ if !util.IsBlank(value) && tag != "platform_nickname" {
|
|
|
|
+ db = db.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
|
+ } else if tag == "platform_nickname" {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ var taskInfos []gorm_model.YoungeeTaskInfo
|
|
|
|
+ db = db.Model(gorm_model.YoungeeTaskInfo{})
|
|
|
|
+ // 查询总数
|
|
|
|
+ var totalTask int64
|
|
|
|
+ if err := db.Count(&totalTask).Error; err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
|
|
|
|
+ return nil, 0, err
|
|
|
|
+ }
|
|
|
|
+ // 查询该页数据
|
|
|
|
+ limit := pageSize
|
|
|
|
+ offset := pageSize * pageNum // assert pageNum start with 0
|
|
|
|
+ err := db.Order("task_id").Limit(int(limit)).Offset(int(offset)).Find(&taskInfos).Error
|
|
|
|
+ if err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
|
|
|
|
+ return nil, 0, err
|
|
|
|
+ }
|
|
|
|
+ // 查询账号id
|
|
|
|
+
|
|
|
|
+ var accountIds []int
|
|
|
|
+ taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
|
|
|
|
+ for _, taskInfo := range taskInfos {
|
|
|
|
+ accountIds = append(accountIds, taskInfo.AccountID)
|
|
|
|
+ taskMap[taskInfo.AccountID] = taskInfo
|
|
|
|
+ }
|
|
|
|
+ db1 := GetReadDB(ctx)
|
|
|
|
+ db1 = db1.Debug().Model(gorm_model.YoungeePlatformAccountInfo{})
|
|
|
|
+ // 根据Project条件过滤
|
|
|
|
+ conditionType2 := reflect.TypeOf(conditions).Elem()
|
|
|
|
+ conditionValue2 := reflect.ValueOf(conditions).Elem()
|
|
|
|
+ for i := 0; i < conditionType2.NumField(); i++ {
|
|
|
|
+ field := conditionType2.Field(i)
|
|
|
|
+ tag := field.Tag.Get("condition")
|
|
|
|
+ value := conditionValue2.FieldByName(field.Name)
|
|
|
|
+ if !util.IsBlank(value) && tag == "platform_nickname" {
|
|
|
|
+ db1 = db1.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ var accountInfos []gorm_model.YoungeePlatformAccountInfo
|
|
|
|
+ db1 = db1.Model(gorm_model.YoungeePlatformAccountInfo{}).Where("account_id IN ?", accountIds).Find(&accountInfos)
|
|
|
|
+ // 查询总数
|
|
|
|
+ var totalAccount int64
|
|
|
|
+ if err := db1.Count(&totalAccount).Error; err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
|
|
|
|
+ return nil, 0, err
|
|
|
|
+ }
|
|
|
|
+ accountMap := make(map[int]gorm_model.YoungeePlatformAccountInfo)
|
|
|
|
+ for _, accountInfo := range accountInfos {
|
|
|
|
+ accountMap[accountInfo.AccountID] = accountInfo
|
|
|
|
+ }
|
|
|
|
+ var taskAccounts []*gorm_model.TaskAccount
|
|
|
|
+ var projectTasks []*gorm_model.ProjectTaskInfo
|
|
|
|
+ for _, accountId := range accountIds {
|
|
|
|
+ taskAccount := new(gorm_model.TaskAccount)
|
|
|
|
+ _, ok := taskMap[accountId]
|
|
|
|
+ _, ok2 := accountMap[accountId]
|
|
|
|
+ if ok && ok2 {
|
|
|
|
+ taskAccount.Task = taskMap[accountId]
|
|
|
|
+ taskAccount.Account = accountMap[accountId]
|
|
|
|
+ }
|
|
|
|
+ taskAccounts = append(taskAccounts, taskAccount)
|
|
|
|
+ }
|
|
|
|
+ projectTasks = pack.TaskAccountToTaskInfo(taskAccounts)
|
|
|
|
+ // 删除只存在于一个表中的元素
|
|
|
|
+ for i := 0; i < len(projectTasks); i++ {
|
|
|
|
+ if projectTasks[i].TaskID == "" || projectTasks[i].PlatformNickname == "" {
|
|
|
|
+ projectTasks = append(projectTasks[:i], projectTasks[i+1:]...)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ var total int64
|
|
|
|
+ if totalTask > totalAccount {
|
|
|
|
+ total = totalAccount
|
|
|
|
+ } else {
|
|
|
|
+ total = totalTask
|
|
|
|
+ }
|
|
|
|
+ return projectTasks, total, nil
|
|
|
|
+}
|
|
|
|
+
|
|
func GetProjectDetail(ctx context.Context, projectID int64) (*gorm_model.ProjectInfo, error) {
|
|
func GetProjectDetail(ctx context.Context, projectID int64) (*gorm_model.ProjectInfo, error) {
|
|
db := GetReadDB(ctx)
|
|
db := GetReadDB(ctx)
|
|
var ProjectDetail *gorm_model.ProjectInfo
|
|
var ProjectDetail *gorm_model.ProjectInfo
|
|
@@ -105,3 +199,15 @@ func GetRecruitStrategys(ctx context.Context, ProjectID int64) ([]gorm_model.Rec
|
|
}
|
|
}
|
|
return RecruitStrategys, nil
|
|
return RecruitStrategys, nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func ChangeTaskStatus(ctx context.Context, data []string, taskStatus string) error {
|
|
|
|
+ db := GetReadDB(ctx)
|
|
|
|
+ taskInfo := gorm_model.YoungeeTaskInfo{}
|
|
|
|
+ if err := db.Debug().Model(&taskInfo).Where("task_id IN ?", data).
|
|
|
|
+ Updates(gorm_model.YoungeeTaskInfo{TaskStatus: taskStatus}).Error; err != nil {
|
|
|
|
+
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[ChangeTaskStatus] error query mysql total, err:%+v", err)
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+}
|