|
@@ -3,9 +3,7 @@ package db
|
|
|
import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
- "github.com/issue9/conv"
|
|
|
"reflect"
|
|
|
- "strconv"
|
|
|
"youngee_b_api/model/common_model"
|
|
|
"youngee_b_api/model/gorm_model"
|
|
|
"youngee_b_api/model/http_model"
|
|
@@ -13,6 +11,7 @@ import (
|
|
|
"youngee_b_api/util"
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
+ log "github.com/sirupsen/logrus"
|
|
|
"gorm.io/gorm"
|
|
|
)
|
|
|
|
|
@@ -118,7 +117,7 @@ func GetProjectTaskList(ctx context.Context, projectID string, pageSize, pageNum
|
|
|
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
|
|
|
+ if !util.IsBlank(value) && tag == "platform_nickname" { // input:1 taskIdsbase:1,2,3 string
|
|
|
db1 = db1.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
}
|
|
|
}
|
|
@@ -214,146 +213,13 @@ func GetRecruitStrategys(ctx context.Context, ProjectID int64) ([]gorm_model.Rec
|
|
|
return RecruitStrategys, nil
|
|
|
}
|
|
|
|
|
|
-func ChangeTaskStatus(ctx context.Context, data []string, taskStatus string) error {
|
|
|
+func UpdateProjectStatus(ctx context.Context, projectId int64, status int64) error {
|
|
|
db := GetReadDB(ctx)
|
|
|
- taskInfo := gorm_model.YoungeeTaskInfo{}
|
|
|
- taskSta, err := strconv.Atoi(taskStatus)
|
|
|
+ err := db.Model(gorm_model.ProjectInfo{}).
|
|
|
+ Where("project_id = ?", projectId).Update("project_status", status).Error
|
|
|
if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- if err := db.Debug().Model(&taskInfo).Where("task_id IN ?", data).
|
|
|
- Updates(gorm_model.YoungeeTaskInfo{TaskStatus: taskSta}).Error; err != nil {
|
|
|
-
|
|
|
- logrus.WithContext(ctx).Errorf("[ChangeTaskStatus] error query mysql total, err:%+v", err)
|
|
|
+ log.Println("DB UpdateProjectStatus error :", err)
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
-
|
|
|
-func GetProjectTalentList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*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
|
|
|
-}
|