task_sketch.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. package youngee_task_service
  2. import (
  3. "fmt"
  4. "strings"
  5. "youngmini_server/app/dao"
  6. "youngmini_server/app/model"
  7. "youngmini_server/app/model/youngee_talent_model"
  8. "github.com/gogf/gf/frame/g"
  9. "github.com/gogf/gf/net/ghttp"
  10. "github.com/gogf/gf/os/gtime"
  11. )
  12. // 添加初稿service done
  13. func AddTaskSketch(r *ghttp.Request) *TalentHttpResult {
  14. var sketchInfoReq *youngee_talent_model.AddTaskSketchRequest
  15. //解析添加初稿的图文
  16. err := r.ParseForm(&sketchInfoReq)
  17. if err != nil {
  18. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  19. }
  20. photoUrl := strings.Split(sketchInfoReq.PhotoUrl, ",")
  21. taskSketchInfo := []youngee_talent_model.TaskSketchInfo{}
  22. err = g.DB().Model(model.YounggeeSketchInfo{}).Where("task_id = ? ", sketchInfoReq.TaskId).OrderDesc("create_at").Scan(&taskSketchInfo)
  23. if err != nil {
  24. return &TalentHttpResult{Code: -2, Msg: "YounggeeSketchInfo find failed"}
  25. }
  26. //上传过但是被拒了
  27. var condition1 bool = len(taskSketchInfo) != 0 && taskSketchInfo[0].IsReview == 1 && taskSketchInfo[0].IsOk == 0
  28. //没有上传过初稿
  29. var condition2 bool = len(taskSketchInfo) == 0
  30. //最新sketch数据
  31. sketchInfo := model.YounggeeSketchInfo{
  32. TaskId: sketchInfoReq.TaskId,
  33. Title: sketchInfoReq.Title,
  34. Type: sketchInfoReq.Type,
  35. Content: sketchInfoReq.Content,
  36. CreateAt: gtime.Now(),
  37. IsReview: 0,
  38. IsSubmit: 0, //忽略
  39. IsOk: 0,
  40. }
  41. if condition1 || condition2 {
  42. //插入新数据
  43. sketchId, err := g.DB().Model(model.YounggeeSketchInfo{}).Data(sketchInfo).InsertAndGetId()
  44. if err != nil {
  45. return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchInfo insert failed"}
  46. }
  47. //上传过,把旧的删掉
  48. if condition1 {
  49. _, err := g.DB().Model(model.YounggeeSketchPhoto{}).Where("sketch_id=?", sketchId).Delete()
  50. if err != nil {
  51. fmt.Println("err:", err.Error())
  52. }
  53. }
  54. //插入新的
  55. for _, v := range photoUrl {
  56. _, err := g.DB().Model(model.YounggeeSketchPhoto{}).Data(g.Map{"sketch_id": sketchId, "photo_url": v, "symbol": sketchInfoReq.Type, "create_at": gtime.Now()}).Insert()
  57. if err != nil {
  58. return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchPhoto insert failed"}
  59. }
  60. }
  61. } else { //有数据,但是,还没有被审核,更新
  62. sketchId := taskSketchInfo[0].SketchId
  63. // 使用主键 ID 更新记录
  64. _, err := g.DB().Model(model.YounggeeSketchInfo{}).Where("sketch_id = ?", sketchId).Data(sketchInfo).Update()
  65. //上传过,把旧的删掉
  66. _, err = g.DB().Model(model.YounggeeSketchPhoto{}).Where("sketch_id=?", sketchId).Delete()
  67. if err != nil {
  68. fmt.Println("err:", err.Error())
  69. }
  70. //插入新的
  71. for _, v := range photoUrl {
  72. _, err := g.DB().Model(model.YounggeeSketchPhoto{}).Data(g.Map{"sketch_id": sketchId, "photo_url": v, "symbol": sketchInfoReq.Type, "create_at": gtime.Now()}).Insert()
  73. if err != nil {
  74. return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchPhoto insert failed"}
  75. }
  76. }
  77. if err != nil {
  78. return &TalentHttpResult{Code: -4, Msg: "YounggeeSketchInfo update failed"}
  79. }
  80. }
  81. //修改task表中的字段待添加变成已添加,待修改变成已修改
  82. sketchStatus, err := g.DB().Model(model.YoungeeTaskInfo{}).Fields("sketch_status").Where("task_id = ?", sketchInfoReq.TaskId).Value()
  83. if err != nil {
  84. return &TalentHttpResult{Code: -5, Msg: "Get task info failed"}
  85. }
  86. if sketchStatus.Int64() == 1 {
  87. _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", sketchInfoReq.TaskId).Update(g.Map{"sketch_status": 2})
  88. if err != nil {
  89. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  90. }
  91. } else if sketchStatus.Int64() == 3 {
  92. _, err = g.Model(dao.YoungeeTaskInfo.Table).Where("task_id = ?", sketchInfoReq.TaskId).Update(g.Map{"sketch_status": 4})
  93. if err != nil {
  94. return &TalentHttpResult{Code: -6, Msg: "YoungeeTaskInfo update failed"}
  95. }
  96. }
  97. taskInfo := youngee_talent_model.YoungeeTaskInfo{}
  98. //task设置为初稿待审核
  99. fmt.Println("&&&&****")
  100. _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "10"}).Where("task_id = ?", sketchInfoReq.TaskId).Update()
  101. // 若处于违约状态则解除
  102. if taskInfo.CurDefaultType == 3 || taskInfo.CurDefaultType == 9 {
  103. //将task设置为位违约
  104. _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"cur_default_type": "0", "err_break_rate": 0}).Where("task_id = ?", sketchInfoReq.TaskId).Update()
  105. if err != nil {
  106. return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
  107. }
  108. // 更新违约记录表,default_status设置为已重新上传
  109. _, 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()
  110. if err != nil {
  111. return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
  112. }
  113. }
  114. // 记录任务日志-上传初稿
  115. taskLog := model.YounggeeTaskLog{
  116. TaskId: sketchInfoReq.TaskId,
  117. Content: "上传初稿",
  118. LogAt: gtime.Now(),
  119. }
  120. //上传日志,用于详情页判断上一个状态是什么
  121. _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
  122. if err != nil {
  123. return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"}
  124. }
  125. //todo 添加初稿报错 ProjectInfo find failed
  126. //插入一条消息
  127. //projectInfo := model.ProjectInfo{}
  128. //err1 := g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo)
  129. //if err1 != nil {
  130. // return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"}
  131. //}
  132. //messageInfo := model.YounggeeMessageInfo{
  133. // MessageId: 11,
  134. // MessageType: 2,
  135. // CreatedAt: gtime.Now(),
  136. // TalentId: taskInfo.TalentId,
  137. // ProjectName: projectInfo.ProjectName,
  138. // IsReaded: 0,
  139. // IsDeleted: 0,
  140. //}
  141. //_, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
  142. //if err != nil {
  143. // return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"}
  144. //}
  145. return &TalentHttpResult{Code: 0, Msg: "success"}
  146. }
  147. // 提交初稿service
  148. //func SubmitTaskSketch(r *ghttp.Request) *TalentHttpResult {
  149. // taskId, _ := r.Get("task_id").(string) // 查询是否处于违约状态
  150. // taskInfo := model.YoungeeTaskInfo{}
  151. // // 查询是否处于违约状态
  152. // err1 := g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Scan(&taskInfo)
  153. // if err1 != nil {
  154. // return &TalentHttpResult{Code: -1, Msg: "YoungeeTaskInfo find failed"}
  155. // }
  156. // //若当前是违约状态
  157. //
  158. // //如果有提交过,且被拒绝
  159. //
  160. // // 查询该任务是否有已添加或已修改初稿
  161. // //add之后is_submit就是0 && sketch_status变成已添加/已修改
  162. // //
  163. // res, err := g.DB().Model(model.YounggeeSketchInfo{}).Where("task_id = ? and is_submit = 0", taskId).Count()
  164. // if err != nil {
  165. // return &TalentHttpResult{Code: -1, Msg: "YounggeeSketchInfo find failed"}
  166. // }
  167. // // add之后一定会满足此条件
  168. // if res == 1 && (taskInfo.SketchStatus == 2 || taskInfo.SketchStatus == 4) {
  169. // //将这条task改成已提交并修改提交时间
  170. // _, 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()
  171. // if err != nil {
  172. // return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchInfo update failed"}
  173. // }
  174. // //将这条task_stage改成10(初稿待审)
  175. // _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "10"}).Where("task_id = ?", taskId).Update()
  176. // if err != nil {
  177. // return &TalentHttpResult{Code: -4, Msg: "YoungeeTaskInfo update failed"}
  178. // }
  179. // // 记录任务日志-上传初稿
  180. // taskLog := model.YounggeeTaskLog{
  181. // TaskId: taskId,
  182. // Content: "上传初稿",
  183. // LogAt: gtime.Now(),
  184. // }
  185. // //上传日志,用于详情页判断上一个状态是什么
  186. // _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
  187. // if err != nil {
  188. // return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"}
  189. // }
  190. // //插入一条消息
  191. // projectInfo := model.ProjectInfo{}
  192. // err1 := g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo)
  193. // if err1 != nil {
  194. // return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"}
  195. // }
  196. // messageInfo := model.YounggeeMessageInfo{
  197. // MessageId: 11,
  198. // MessageType: 2,
  199. // CreatedAt: gtime.Now(),
  200. // TalentId: taskInfo.TalentId,
  201. // ProjectName: projectInfo.ProjectName,
  202. // IsReaded: 0,
  203. // IsDeleted: 0,
  204. // }
  205. // _, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
  206. // if err != nil {
  207. // return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"}
  208. // }
  209. // }
  210. //
  211. // return &TalentHttpResult{Code: 0, Msg: "success"}
  212. //}
  213. // 查询初稿提交审阅记录service done
  214. func GetTaskSketch(r *ghttp.Request) *TalentHttpResult {
  215. taskId := r.Get("task_id")
  216. var sketchInfoList []*youngee_talent_model.TaskSketchInfo
  217. err := g.DB().Model(dao.YounggeeSketchInfo.Table).Where("is_review = 1 and task_id = ?", taskId).OrderAsc("create_at").Scan(&sketchInfoList)
  218. if err != nil {
  219. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  220. }
  221. for _, v := range sketchInfoList {
  222. var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto
  223. err = g.DB().Model(dao.YounggeeSketchPhoto.Table).Where("sketch_id = ?", v.SketchId).Scan(&sketchPhotoList)
  224. if err != nil {
  225. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  226. }
  227. v.Photo = sketchPhotoList
  228. }
  229. return &TalentHttpResult{Code: 0, Msg: "success", Data: sketchInfoList}
  230. }
  231. // 查询未提交初稿service,进入上传初稿页面时访问
  232. func GetUnSubmitTaskSketch(r *ghttp.Request) *TalentHttpResult {
  233. taskId := r.Get("task_id")
  234. var unSubmitSketch []*youngee_talent_model.TaskSketchInfo
  235. err := g.DB().Model(dao.YounggeeSketchInfo.Table).Where("is_review = 0 and task_id = ?", taskId).OrderDesc("create_at").Scan(&unSubmitSketch)
  236. if err != nil {
  237. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  238. }
  239. if len(unSubmitSketch) == 0 {
  240. return &TalentHttpResult{Code: 0, Msg: "success", Data: nil}
  241. } else {
  242. var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto
  243. err = g.DB().Model(dao.YounggeeSketchPhoto.Table).Where("sketch_id = ?", unSubmitSketch[0].SketchId).Scan(&sketchPhotoList)
  244. if err != nil {
  245. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  246. }
  247. unSubmitSketch[0].Photo = sketchPhotoList
  248. return &TalentHttpResult{Code: 0, Msg: "success", Data: unSubmitSketch[0]}
  249. }
  250. }