package youngee_task_service import ( "fmt" "strings" "youngmini_server/app/dao" "youngmini_server/app/model" "youngmini_server/app/model/youngee_talent_model" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp" "github.com/gogf/gf/os/gtime" ) // 添加初稿service done func AddTaskSketch(r *ghttp.Request) *TalentHttpResult { var sketchInfoReq *youngee_talent_model.AddTaskSketchRequest //解析添加初稿的图文 err := r.ParseForm(&sketchInfoReq) if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } photoUrl := strings.Split(sketchInfoReq.PhotoUrl, ",") taskSketchInfo := []youngee_talent_model.TaskSketchInfo{} err = g.DB().Model(model.YounggeeSketchInfo{}).Where("task_id = ? ", sketchInfoReq.TaskId).OrderDesc("create_at").Scan(&taskSketchInfo) if err != nil { return &TalentHttpResult{Code: -2, Msg: "YounggeeSketchInfo find failed"} } //上传过但是被拒了 var condition1 bool = len(taskSketchInfo) != 0 && taskSketchInfo[0].IsReview == 1 && taskSketchInfo[0].IsOk == 0 //没有上传过初稿 var condition2 bool = len(taskSketchInfo) == 0 //最新sketch数据 sketchInfo := model.YounggeeSketchInfo{ TaskId: sketchInfoReq.TaskId, Title: sketchInfoReq.Title, Type: sketchInfoReq.Type, Content: sketchInfoReq.Content, CreateAt: gtime.Now(), IsReview: 0, IsSubmit: 0, //忽略 IsOk: 0, } if condition1 || condition2 { //插入新数据 sketchId, err := g.DB().Model(model.YounggeeSketchInfo{}).Data(sketchInfo).InsertAndGetId() if err != nil { return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchInfo insert failed"} } //上传过,把旧的删掉 if condition1 { _, err := g.DB().Model(model.YounggeeSketchPhoto{}).Where("sketch_id=?", sketchId).Delete() if err != nil { fmt.Println("err:", err.Error()) } } //插入新的 for _, v := range photoUrl { _, err := g.DB().Model(model.YounggeeSketchPhoto{}).Data(g.Map{"sketch_id": sketchId, "photo_url": v, "symbol": sketchInfoReq.Type, "create_at": gtime.Now()}).Insert() if err != nil { return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchPhoto insert failed"} } } } else { //有数据,但是,还没有被审核,更新 sketchId := taskSketchInfo[0].SketchId // 使用主键 ID 更新记录 _, err := g.DB().Model(model.YounggeeSketchInfo{}).Where("sketch_id = ?", sketchId).Data(sketchInfo).Update() //上传过,把旧的删掉 _, err = g.DB().Model(model.YounggeeSketchPhoto{}).Where("sketch_id=?", sketchId).Delete() if err != nil { fmt.Println("err:", err.Error()) } //插入新的 for _, v := range photoUrl { _, err := g.DB().Model(model.YounggeeSketchPhoto{}).Data(g.Map{"sketch_id": sketchId, "photo_url": v, "symbol": sketchInfoReq.Type, "create_at": gtime.Now()}).Insert() if err != nil { return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchPhoto insert failed"} } } if err != nil { return &TalentHttpResult{Code: -4, Msg: "YounggeeSketchInfo update failed"} } } //修改task表中的字段待添加变成已添加,待修改变成已修改 sketchStatus, err := g.DB().Model(model.YoungeeTaskInfo{}).Fields("sketch_status").Where("task_id = ?", sketchInfoReq.TaskId).Value() if err != nil { return &TalentHttpResult{Code: -5, Msg: "Get task info failed"} } if sketchStatus.Int64() == 1 { _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", sketchInfoReq.TaskId).Update(g.Map{"sketch_status": 2}) if err != nil { return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"} } } else if sketchStatus.Int64() == 3 { _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", sketchInfoReq.TaskId).Update(g.Map{"sketch_status": 4}) if err != nil { return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"} } } taskInfo := youngee_talent_model.YoungeeTaskInfo{} //task设置为初稿待审核 fmt.Println("&&&&****") _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "10"}).Where("task_id = ?", sketchInfoReq.TaskId).Update() // 若处于违约状态则解除 if taskInfo.CurDefaultType == 3 || taskInfo.CurDefaultType == 9 { //将task设置为位违约 _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"cur_default_type": "0", "err_break_rate": 0}).Where("task_id = ?", sketchInfoReq.TaskId).Update() if err != nil { return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"} } // 更新违约记录表,default_status设置为已重新上传 _, err = g.DB().Model(model.YoungeeContractInfo{}).Data(g.Map{"default_status": 2}).Where("task_id = ? and default_status in (?)", sketchInfoReq.TaskId, g.Slice{1, 3, 4}).Update() if err != nil { return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"} } } // 记录任务日志-上传初稿 taskLog := model.YounggeeTaskLog{ TaskId: sketchInfoReq.TaskId, Content: "上传初稿", LogAt: gtime.Now(), } //上传日志,用于详情页判断上一个状态是什么 _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert() if err != nil { return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"} } //todo 添加初稿报错 ProjectInfo find failed //插入一条消息 //projectInfo := model.ProjectInfo{} //err1 := g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo) //if err1 != nil { // return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"} //} //messageInfo := model.YounggeeMessageInfo{ // MessageId: 11, // MessageType: 2, // CreatedAt: gtime.Now(), // TalentId: taskInfo.TalentId, // ProjectName: projectInfo.ProjectName, // IsReaded: 0, // IsDeleted: 0, //} //_, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert() //if err != nil { // return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"} //} return &TalentHttpResult{Code: 0, Msg: "success"} } // 提交初稿service //func SubmitTaskSketch(r *ghttp.Request) *TalentHttpResult { // taskId, _ := r.Get("task_id").(string) // 查询是否处于违约状态 // taskInfo := model.YoungeeTaskInfo{} // // 查询是否处于违约状态 // err1 := g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Scan(&taskInfo) // if err1 != nil { // return &TalentHttpResult{Code: -1, Msg: "YoungeeTaskInfo find failed"} // } // //若当前是违约状态 // // //如果有提交过,且被拒绝 // // // 查询该任务是否有已添加或已修改初稿 // //add之后is_submit就是0 && sketch_status变成已添加/已修改 // // // res, err := g.DB().Model(model.YounggeeSketchInfo{}).Where("task_id = ? and is_submit = 0", taskId).Count() // if err != nil { // return &TalentHttpResult{Code: -1, Msg: "YounggeeSketchInfo find failed"} // } // // add之后一定会满足此条件 // if res == 1 && (taskInfo.SketchStatus == 2 || taskInfo.SketchStatus == 4) { // //将这条task改成已提交并修改提交时间 // _, err = g.DB().Model(model.YounggeeSketchInfo{}).Data(g.Map{"is_submit": "1", "submit_at": gtime.Now()}).Where("task_id = ? and is_submit = 0", taskId).Update() // if err != nil { // return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchInfo update failed"} // } // //将这条task_stage改成10(初稿待审) // _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "10"}).Where("task_id = ?", taskId).Update() // if err != nil { // return &TalentHttpResult{Code: -4, Msg: "YoungeeTaskInfo update failed"} // } // // 记录任务日志-上传初稿 // taskLog := model.YounggeeTaskLog{ // TaskId: taskId, // Content: "上传初稿", // LogAt: gtime.Now(), // } // //上传日志,用于详情页判断上一个状态是什么 // _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert() // if err != nil { // return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"} // } // //插入一条消息 // projectInfo := model.ProjectInfo{} // err1 := g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo) // if err1 != nil { // return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"} // } // messageInfo := model.YounggeeMessageInfo{ // MessageId: 11, // MessageType: 2, // CreatedAt: gtime.Now(), // TalentId: taskInfo.TalentId, // ProjectName: projectInfo.ProjectName, // IsReaded: 0, // IsDeleted: 0, // } // _, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert() // if err != nil { // return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"} // } // } // // return &TalentHttpResult{Code: 0, Msg: "success"} //} // 查询初稿提交审阅记录service done func GetTaskSketch(r *ghttp.Request) *TalentHttpResult { taskId := r.Get("task_id") var sketchInfoList []*youngee_talent_model.TaskSketchInfo err := g.DB().Model(dao.YounggeeSketchInfo.Table).Where("is_review = 1 and task_id = ?", taskId).OrderAsc("create_at").Scan(&sketchInfoList) if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } for _, v := range sketchInfoList { var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto err = g.DB().Model(dao.YounggeeSketchPhoto.Table).Where("sketch_id = ?", v.SketchId).Scan(&sketchPhotoList) if err != nil { return &TalentHttpResult{Code: -2, Msg: err.Error()} } v.Photo = sketchPhotoList } return &TalentHttpResult{Code: 0, Msg: "success", Data: sketchInfoList} } // 查询未提交初稿service,进入上传初稿页面时访问 func GetUnSubmitTaskSketch(r *ghttp.Request) *TalentHttpResult { taskId := r.Get("task_id") var unSubmitSketch []*youngee_talent_model.TaskSketchInfo err := g.DB().Model(dao.YounggeeSketchInfo.Table).Where("is_review = 0 and task_id = ?", taskId).OrderDesc("create_at").Scan(&unSubmitSketch) if err != nil { return &TalentHttpResult{Code: -1, Msg: err.Error()} } if len(unSubmitSketch) == 0 { return &TalentHttpResult{Code: 0, Msg: "success", Data: nil} } else { var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto err = g.DB().Model(dao.YounggeeSketchPhoto.Table).Where("sketch_id = ?", unSubmitSketch[0].SketchId).Scan(&sketchPhotoList) if err != nil { return &TalentHttpResult{Code: -2, Msg: err.Error()} } unSubmitSketch[0].Photo = sketchPhotoList return &TalentHttpResult{Code: 0, Msg: "success", Data: unSubmitSketch[0]} } }