|
@@ -0,0 +1,122 @@
|
|
|
|
+package db
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "context"
|
|
|
|
+ "fmt"
|
|
|
|
+ "reflect"
|
|
|
|
+ "youngee_b_api/model/common_model"
|
|
|
|
+ "youngee_b_api/model/gorm_model"
|
|
|
|
+ "youngee_b_api/model/http_model"
|
|
|
|
+ "youngee_b_api/pack"
|
|
|
|
+ "youngee_b_api/util"
|
|
|
|
+
|
|
|
|
+ "github.com/issue9/conv"
|
|
|
|
+ "github.com/sirupsen/logrus"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+// 查询上传脚本的task list
|
|
|
|
+func GetTaskScriptList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskScriptInfo, 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 tag == "script_status" {
|
|
|
|
+ fmt.Printf("script %+v", value.Interface() == int64(2))
|
|
|
|
+ if value.Interface() == int64(2) {
|
|
|
|
+ db = db.Where("script_status>=? AND script_status < ?", 2, 5)
|
|
|
|
+ } else {
|
|
|
|
+ db = db.Where("script_status =? ", 5)
|
|
|
|
+ }
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ 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.YounggeeScriptInfo{})
|
|
|
|
+
|
|
|
|
+ // 根据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 taskIdsbase:1,2,3 string
|
|
|
|
+ fmt.Printf("Test %s = ?\n", tag)
|
|
|
|
+ db1 = db1.Where(fmt.Sprintf("%s = ?", tag), value.Interface())
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ var ScriptInfos []gorm_model.YounggeeScriptInfo
|
|
|
|
+ db1 = db1.Model(gorm_model.YounggeeScriptInfo{}).Where("task_id IN ? AND is_submit=? AND is_review=?", taskIds, 1, 0).Find(&ScriptInfos)
|
|
|
|
+ ScriptMap := make(map[int]gorm_model.YounggeeScriptInfo)
|
|
|
|
+ for _, ScriptInfo := range ScriptInfos {
|
|
|
|
+ ScriptMap[conv.MustInt(ScriptInfo.TaskID)] = ScriptInfo
|
|
|
|
+ }
|
|
|
|
+ // 查询总数
|
|
|
|
+ var totalScript int64
|
|
|
|
+ if err := db1.Count(&totalScript).Error; err != nil {
|
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
|
|
|
|
+ return nil, 0, err
|
|
|
|
+ }
|
|
|
|
+ var misNum int64
|
|
|
|
+ if totalScript > totalTask {
|
|
|
|
+ misNum = totalScript - totalTask
|
|
|
|
+ } else {
|
|
|
|
+ misNum = totalTask - totalScript
|
|
|
|
+ }
|
|
|
|
+ logrus.Println("totalScript,totalTalent,misNum:", totalScript, 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
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var TaskScripts []*http_model.TaskScript
|
|
|
|
+ var taskScripts []*http_model.TaskScriptInfo
|
|
|
|
+ for _, taskId := range taskIds {
|
|
|
|
+ TaskScript := new(http_model.TaskScript)
|
|
|
|
+ TaskScript.Talent = taskMap[taskId]
|
|
|
|
+ TaskScript.Script = ScriptMap[taskId]
|
|
|
|
+ TaskScripts = append(TaskScripts, TaskScript)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ taskScripts = pack.TaskScriptToTaskInfo(TaskScripts)
|
|
|
|
+
|
|
|
|
+ for _, v := range taskScripts {
|
|
|
|
+ fmt.Println("taskScript: \n", *v)
|
|
|
|
+ }
|
|
|
|
+ // return fulltaskScript, total, nil
|
|
|
|
+ return taskScripts, totalTask, nil
|
|
|
|
+}
|