|
@@ -3,6 +3,7 @@ package db
|
|
|
import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
+ "github.com/issue9/conv"
|
|
|
"reflect"
|
|
|
"strconv"
|
|
|
"youngee_b_api/model/common_model"
|
|
@@ -105,8 +106,8 @@ func GetProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum
|
|
|
var accountIds []int
|
|
|
taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
|
|
|
for _, taskInfo := range taskInfos {
|
|
|
- accountIds = append(accountIds, taskInfo.AccountId)
|
|
|
- taskMap[taskInfo.AccountId] = taskInfo
|
|
|
+ accountIds = append(accountIds, taskInfo.AccountID)
|
|
|
+ taskMap[taskInfo.AccountID] = taskInfo
|
|
|
}
|
|
|
db1 := GetReadDB(ctx)
|
|
|
db1 = db1.Debug().Model(gorm_model.YoungeePlatformAccountInfo{})
|
|
@@ -228,3 +229,131 @@ func ChangeTaskStatus(ctx context.Context, data []string, taskStatus string) err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+func GetProjectTalentList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TaskConditions) ([]*http_model.ProjectTalentInfo, 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
|
|
|
+ }
|
|
|
+ db.Order("task_id").Find(&taskInfos)
|
|
|
+
|
|
|
+ // 查询账号id
|
|
|
+ var taskIds []int
|
|
|
+ taskMap := make(map[int]gorm_model.YoungeeTaskInfo)
|
|
|
+ for _, taskInfo := range taskInfos {
|
|
|
+ taskIds = append(taskIds, taskInfo.TaskID)
|
|
|
+ taskMap[taskInfo.TaskID] = taskInfo
|
|
|
+ }
|
|
|
+ db1 := GetReadDB(ctx)
|
|
|
+ db1 = db1.Debug().Model(gorm_model.YoungeeTaskLogistics{})
|
|
|
+ // 根据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" { // input:1 database:1,2,3 string
|
|
|
+ db1 = db1.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var logisticsInfos []gorm_model.YoungeeTaskLogistics
|
|
|
+ db1 = db1.Model(gorm_model.YoungeeTaskLogistics{}).Where("task_id IN ?", taskIds).Find(&logisticsInfos)
|
|
|
+ logisticsMap := make(map[int]gorm_model.YoungeeTaskLogistics)
|
|
|
+ for _, logisticsInfo := range logisticsInfos {
|
|
|
+ logisticsMap[conv.MustInt(logisticsInfo.TaskID)] = logisticsInfo
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ 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" { // input:1 database:1,2,3 string
|
|
|
+ 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("[GetProjectTalentList] error query mysql total, err:%+v", err)
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ var misNum int64
|
|
|
+ if totalAccount > totalTask {
|
|
|
+ misNum = totalAccount - totalTask
|
|
|
+ } else {
|
|
|
+ misNum = totalTask - totalAccount
|
|
|
+ }
|
|
|
+ logrus.Println("totalAccount,totalTalent,misNum:", totalAccount, totalTask, misNum)
|
|
|
+
|
|
|
+ // 查询该页数据
|
|
|
+ limit := pageSize + misNum
|
|
|
+ offset := pageSize * pageNum // assert pageNum start with 0
|
|
|
+ err := db.Order("task_id").Limit(int(limit)).Offset(int(offset)).Error
|
|
|
+ if 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 talentAccounts []*http_model.TalentAccount
|
|
|
+ var projectTalents []*http_model.ProjectTalentInfo
|
|
|
+ for _, taskId := range taskIds {
|
|
|
+ talentAccount := new(http_model.TalentAccount)
|
|
|
+ _, ok := taskMap[taskId]
|
|
|
+ _, ok2 := logisticsMap[taskId]
|
|
|
+ if ok && ok2 {
|
|
|
+ talentAccount.Talent = taskMap[taskId]
|
|
|
+ talentAccount.Logistics = logisticsMap[taskId]
|
|
|
+ }
|
|
|
+ talentAccounts = append(talentAccounts, talentAccount)
|
|
|
+ }
|
|
|
+
|
|
|
+ projectTalents = pack.TalentAccountToTaskInfo(talentAccounts)
|
|
|
+ var fullProjectTalents []*http_model.ProjectTalentInfo
|
|
|
+ // 删除只存在于一个表中的元素
|
|
|
+ for i := 0; i < len(projectTalents); i++ {
|
|
|
+ if projectTalents[i].TaskID != 0 {
|
|
|
+ fullProjectTalents = append(fullProjectTalents, projectTalents[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var total int64
|
|
|
+ if totalTask > totalAccount {
|
|
|
+ total = totalAccount
|
|
|
+ } else {
|
|
|
+ total = totalTask
|
|
|
+ }
|
|
|
+ return fullProjectTalents, total, nil
|
|
|
+}
|