task_sketch.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "10"}).Where("task_id = ?", sketchInfoReq.TaskId).Update()
  100. // 若处于违约状态则解除
  101. if taskInfo.CurDefaultType == 3 || taskInfo.CurDefaultType == 9 {
  102. //将task设置为位违约
  103. _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"cur_default_type": "0", "err_break_rate": 0}).Where("task_id = ?", sketchInfoReq.TaskId).Update()
  104. if err != nil {
  105. return &TalentHttpResult{Code: -2, Msg: "YoungeeTaskInfo update failed"}
  106. }
  107. // 更新违约记录表,default_status设置为已重新上传
  108. _, 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()
  109. if err != nil {
  110. return &TalentHttpResult{Code: -2, Msg: "YoungeeContractInfo update failed"}
  111. }
  112. }
  113. // 记录任务日志-上传初稿
  114. taskLog := model.YounggeeTaskLog{
  115. TaskId: sketchInfoReq.TaskId,
  116. Content: "上传初稿",
  117. LogAt: gtime.Now(),
  118. }
  119. //上传日志,用于详情页判断上一个状态是什么
  120. _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
  121. if err != nil {
  122. return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"}
  123. }
  124. //插入一条消息
  125. projectInfo := model.ProjectInfo{}
  126. err1 := g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo)
  127. if err1 != nil {
  128. return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"}
  129. }
  130. messageInfo := model.YounggeeMessageInfo{
  131. MessageId: 11,
  132. MessageType: 2,
  133. CreatedAt: gtime.Now(),
  134. TalentId: taskInfo.TalentId,
  135. ProjectName: projectInfo.ProjectName,
  136. IsReaded: 0,
  137. IsDeleted: 0,
  138. }
  139. _, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
  140. if err != nil {
  141. return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"}
  142. }
  143. return &TalentHttpResult{Code: 0, Msg: "success"}
  144. }
  145. // 提交初稿service
  146. //func SubmitTaskSketch(r *ghttp.Request) *TalentHttpResult {
  147. // taskId, _ := r.Get("task_id").(string) // 查询是否处于违约状态
  148. // taskInfo := model.YoungeeTaskInfo{}
  149. // // 查询是否处于违约状态
  150. // err1 := g.DB().Model(model.YoungeeTaskInfo{}).Where("task_id = ?", taskId).Scan(&taskInfo)
  151. // if err1 != nil {
  152. // return &TalentHttpResult{Code: -1, Msg: "YoungeeTaskInfo find failed"}
  153. // }
  154. // //若当前是违约状态
  155. //
  156. // //如果有提交过,且被拒绝
  157. //
  158. // // 查询该任务是否有已添加或已修改初稿
  159. // //add之后is_submit就是0 && sketch_status变成已添加/已修改
  160. // //
  161. // res, err := g.DB().Model(model.YounggeeSketchInfo{}).Where("task_id = ? and is_submit = 0", taskId).Count()
  162. // if err != nil {
  163. // return &TalentHttpResult{Code: -1, Msg: "YounggeeSketchInfo find failed"}
  164. // }
  165. // // add之后一定会满足此条件
  166. // if res == 1 && (taskInfo.SketchStatus == 2 || taskInfo.SketchStatus == 4) {
  167. // //将这条task改成已提交并修改提交时间
  168. // _, 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()
  169. // if err != nil {
  170. // return &TalentHttpResult{Code: -3, Msg: "YounggeeSketchInfo update failed"}
  171. // }
  172. // //将这条task_stage改成10(初稿待审)
  173. // _, err = g.DB().Model(model.YoungeeTaskInfo{}).Data(g.Map{"task_stage": "10"}).Where("task_id = ?", taskId).Update()
  174. // if err != nil {
  175. // return &TalentHttpResult{Code: -4, Msg: "YoungeeTaskInfo update failed"}
  176. // }
  177. // // 记录任务日志-上传初稿
  178. // taskLog := model.YounggeeTaskLog{
  179. // TaskId: taskId,
  180. // Content: "上传初稿",
  181. // LogAt: gtime.Now(),
  182. // }
  183. // //上传日志,用于详情页判断上一个状态是什么
  184. // _, err = g.DB().Model(dao.YounggeeTaskLog.Table).Data(&taskLog).Insert()
  185. // if err != nil {
  186. // return &TalentHttpResult{Code: -5, Msg: "YounggeeTaskLog insert failed"}
  187. // }
  188. // //插入一条消息
  189. // projectInfo := model.ProjectInfo{}
  190. // err1 := g.DB().Model(model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo)
  191. // if err1 != nil {
  192. // return &TalentHttpResult{Code: -8, Msg: "ProjectInfo find failed"}
  193. // }
  194. // messageInfo := model.YounggeeMessageInfo{
  195. // MessageId: 11,
  196. // MessageType: 2,
  197. // CreatedAt: gtime.Now(),
  198. // TalentId: taskInfo.TalentId,
  199. // ProjectName: projectInfo.ProjectName,
  200. // IsReaded: 0,
  201. // IsDeleted: 0,
  202. // }
  203. // _, err = g.DB().Model(dao.YounggeeMessageInfo.Table).Data(&messageInfo).Insert()
  204. // if err != nil {
  205. // return &TalentHttpResult{Code: -9, Msg: "YounggeeMessageInfo insert failed"}
  206. // }
  207. // }
  208. //
  209. // return &TalentHttpResult{Code: 0, Msg: "success"}
  210. //}
  211. // 查询初稿提交审阅记录service done
  212. func GetTaskSketch(r *ghttp.Request) *TalentHttpResult {
  213. taskId := r.Get("task_id")
  214. var sketchInfoList []*youngee_talent_model.TaskSketchInfo
  215. err := g.DB().Model(dao.YounggeeSketchInfo.Table).Where("is_review = 1 and task_id = ?", taskId).OrderAsc("create_at").Scan(&sketchInfoList)
  216. if err != nil {
  217. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  218. }
  219. for _, v := range sketchInfoList {
  220. var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto
  221. err = g.DB().Model(dao.YounggeeSketchPhoto.Table).Where("sketch_id = ?", v.SketchId).Scan(&sketchPhotoList)
  222. if err != nil {
  223. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  224. }
  225. v.Photo = sketchPhotoList
  226. }
  227. return &TalentHttpResult{Code: 0, Msg: "success", Data: sketchInfoList}
  228. }
  229. // 查询未提交初稿service,进入上传初稿页面时访问
  230. func GetUnSubmitTaskSketch(r *ghttp.Request) *TalentHttpResult {
  231. taskId := r.Get("task_id")
  232. var unSubmitSketch []*youngee_talent_model.TaskSketchInfo
  233. err := g.DB().Model(dao.YounggeeSketchInfo.Table).Where("is_review = 0 and task_id = ?", taskId).OrderDesc("create_at").Scan(&unSubmitSketch)
  234. if err != nil {
  235. return &TalentHttpResult{Code: -1, Msg: err.Error()}
  236. }
  237. if len(unSubmitSketch) == 0 {
  238. return &TalentHttpResult{Code: 0, Msg: "success", Data: nil}
  239. } else {
  240. var sketchPhotoList []*youngee_talent_model.YounggeeSketchPhoto
  241. err = g.DB().Model(dao.YounggeeSketchPhoto.Table).Where("sketch_id = ?", unSubmitSketch[0].SketchId).Scan(&sketchPhotoList)
  242. if err != nil {
  243. return &TalentHttpResult{Code: -2, Msg: err.Error()}
  244. }
  245. unSubmitSketch[0].Photo = sketchPhotoList
  246. return &TalentHttpResult{Code: 0, Msg: "success", Data: unSubmitSketch[0]}
  247. }
  248. }