|
@@ -0,0 +1,170 @@
|
|
|
+package db
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "fmt"
|
|
|
+ "reflect"
|
|
|
+ "time"
|
|
|
+ "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"
|
|
|
+)
|
|
|
+
|
|
|
+// GetTaskSketchList 查询上传初稿的task list
|
|
|
+func GetTaskSketchList(ctx context.Context, projectID string, pageSize, pageNum int64, conditions *common_model.TalentConditions) ([]*http_model.TaskSketchInfo, 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 == "sketch_status" {
|
|
|
+ fmt.Printf("sketch %+v", value.Interface() == int64(0))
|
|
|
+ if value.Interface() == int64(0) {
|
|
|
+ db = db.Where("sketch_status>=? AND sketch_status < ?", 2, 5)
|
|
|
+ } else {
|
|
|
+ db = db.Where("sketch_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.YounggeeSketchInfo{})
|
|
|
+
|
|
|
+ // 根据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 SketchInfos []gorm_model.YounggeeSketchInfo
|
|
|
+ db1 = db1.Model(gorm_model.YounggeeSketchInfo{}).Where("task_id IN ? AND is_submit=? ", taskIds, 1).Find(&SketchInfos)
|
|
|
+ fmt.Printf("初稿查询:%+v", SketchInfos)
|
|
|
+ SketchMap := make(map[int]gorm_model.YounggeeSketchInfo)
|
|
|
+ for _, SketchInfo := range SketchInfos {
|
|
|
+ SketchMap[conv.MustInt(SketchInfo.TaskID)] = SketchInfo
|
|
|
+ }
|
|
|
+ // 查询总数
|
|
|
+ var totalSketch int64
|
|
|
+ if err := db1.Count(&totalSketch).Error; err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetProjectTalentList] error query mysql total, err:%+v", err)
|
|
|
+ return nil, 0, err
|
|
|
+ }
|
|
|
+ var misNum int64
|
|
|
+ if totalSketch > totalTask {
|
|
|
+ misNum = totalSketch - totalTask
|
|
|
+ } else {
|
|
|
+ misNum = totalTask - totalSketch
|
|
|
+ }
|
|
|
+ logrus.Println("totalSketch,totalTalent,misNum:", totalSketch, totalTask, misNum)
|
|
|
+
|
|
|
+ // 查询该页数据
|
|
|
+ limit := pageSize + misNum
|
|
|
+ offset := pageSize * pageNum // assert pageNum start with 0
|
|
|
+ //fmt.Printf("limit %+v offset %+v \n", limit, offset)
|
|
|
+ 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 TaskSketches []*http_model.TaskSketch
|
|
|
+ var taskSketches []*http_model.TaskSketchInfo
|
|
|
+ for _, taskId := range taskIds {
|
|
|
+ TaskSketch := new(http_model.TaskSketch)
|
|
|
+ TaskSketch.Talent = taskMap[taskId]
|
|
|
+ TaskSketch.Sketch = SketchMap[taskId]
|
|
|
+ TaskSketches = append(TaskSketches, TaskSketch)
|
|
|
+ }
|
|
|
+
|
|
|
+ taskSketches = pack.TaskSketchToTaskInfo(TaskSketches)
|
|
|
+
|
|
|
+ for _, v := range taskSketches {
|
|
|
+ fmt.Printf("taskSketch: %+v \n", *v)
|
|
|
+ }
|
|
|
+ // return fulltaskSketch, total, nil
|
|
|
+ return taskSketches, totalTask, nil
|
|
|
+}
|
|
|
+
|
|
|
+// SketchOption 提交意见
|
|
|
+func SketchOption(ctx context.Context, TaskID int, ReviseOpinion string) error {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ fmt.Printf("初稿意见 %d %+v", TaskID, ReviseOpinion)
|
|
|
+ err := db.Model(gorm_model.YounggeeSketchInfo{}).Where("task_id = ?", TaskID).Updates(map[string]interface{}{"revise_opinion": ReviseOpinion, "reject_at": time.Now(), "is_review": 1}).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[Sketch db] call RevisieOption error,err:%+v", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ err = db.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", TaskID).Updates(gorm_model.YoungeeTaskInfo{SketchStatus: 3}).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[Sketch db] call RevisieOption error,err:%+v", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+// AcceptSketch 同意初稿
|
|
|
+func AcceptSketch(ctx context.Context, TaskID int) error {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ err := db.Model(gorm_model.YounggeeSketchInfo{}).Where("task_id = ?", TaskID).Updates(map[string]interface{}{"is_ok": 1, "is_review": 1, "agree_at": time.Now()}).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[Sketch db] call AcceptSketch error,err:%+v", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ err = db.Model(gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", TaskID).Updates(gorm_model.YoungeeTaskInfo{SketchStatus: 5}).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[Sketch db] call AcceptSketch error,err:%+v", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+// FindPhoto
|
|
|
+func FindPhoto(ctx context.Context, SketchID int64) ([]gorm_model.YounggeeSketchPhoto, error) {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ var SketchPhotos []gorm_model.YounggeeSketchPhoto
|
|
|
+ err := db.Model(gorm_model.YounggeeSketchPhoto{}).Where("sketch_id=?", SketchID).Find(&SketchPhotos).Error
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ return SketchPhotos, nil
|
|
|
+
|
|
|
+}
|