project_task_info_dao.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. package dao
  2. import (
  3. "youngee_b_api/app/entity"
  4. "youngee_b_api/app/vo"
  5. )
  6. type ProjectTaskInfoDao struct{}
  7. // 获取指定违约类型的种草子任务数量
  8. func (d ProjectTaskInfoDao) CountByDefaultType(projectId string, defaultType int64) int64 {
  9. var total int64
  10. Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND cur_default_type = ?", projectId, defaultType).Count(&total)
  11. return total
  12. }
  13. // 获取指定任务阶段的种草子任务数量
  14. func (d ProjectTaskInfoDao) CountByTaskStage(projectId string, taskStage int64) int64 {
  15. var total int64
  16. Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND task_stage = ?", projectId, taskStage).Count(&total)
  17. return total
  18. }
  19. // 根据openid获取报名的种草子任务阶段
  20. func (d ProjectTaskInfoDao) CountAllByOpenid(openid string) int64 {
  21. var total int64
  22. Db.Model(&entity.ProjectTaskInfo{}).Where("open_id = ?", openid).Count(&total)
  23. return total
  24. }
  25. // 根据openid获取指定任务阶段的种草子任务阶段
  26. func (d ProjectTaskInfoDao) CountByOpenid(openid string, taskStage int) int64 {
  27. var total int64
  28. Db.Model(&entity.ProjectTaskInfo{}).Where("open_id = ? AND task_stage = ?", openid, taskStage).Count(&total)
  29. return total
  30. }
  31. // 根据openid获取执行中的种草子任务阶段
  32. func (d ProjectTaskInfoDao) CountExcuteNumByOpenid(openid string) int64 {
  33. var total int64
  34. Db.Model(&entity.ProjectTaskInfo{}).
  35. Where("open_id = ? AND task_stage NOT IN (?)", openid, []int{1, 3, 15, 16, 17}).
  36. Count(&total)
  37. return total
  38. }
  39. // 获取指定任务阶段的种草子任务
  40. func (d ProjectTaskInfoDao) GetListByTaskStage(projectId string, taskStage int64, time string, page int, pageSize int, talentNickname string) ([]*entity.ProjectTaskInfo, int64, error) {
  41. var taskInfos []*entity.ProjectTaskInfo
  42. var total int64
  43. query := Db.Model(&entity.ProjectTaskInfo{})
  44. if taskStage == 6 {
  45. query = query.Where("project_id = ? AND task_stage >= ?", projectId, taskStage)
  46. } else {
  47. query = query.Where("project_id = ? AND task_stage = ?", projectId, taskStage)
  48. }
  49. if talentNickname != "" {
  50. var talentInfos []entity.PlatformKuaishouUserInfo
  51. err1 := Db.Model(&entity.PlatformKuaishouUserInfo{}).Where("nick_name = ?", talentNickname).Find(&talentInfos).Error
  52. if err1 != nil {
  53. return nil, 0, err1
  54. }
  55. var openIds []string
  56. for _, talentInfo := range talentInfos {
  57. openIds = append(openIds, talentInfo.OpenID)
  58. }
  59. query = query.Where("open_id in ?", openIds)
  60. }
  61. // 计算偏移量
  62. offset := (page - 1) * pageSize
  63. var err error
  64. if taskStage == 4 {
  65. query.Count(&total)
  66. err = query.Order("create_date desc").Offset(offset).Limit(pageSize).Find(&taskInfos).Error
  67. } else if taskStage == 5 {
  68. if time != "" {
  69. query = query.Where("DATE(delivery_date) = ?", time)
  70. }
  71. query.Count(&total)
  72. err = query.Order("delivery_date desc").Offset(offset).Limit(pageSize).Find(&taskInfos).Error
  73. } else if taskStage == 6 {
  74. query.Count(&total)
  75. err = query.Order("signed_time desc").Offset(offset).Limit(pageSize).Find(&taskInfos).Error
  76. }
  77. if err != nil {
  78. return nil, 0, err
  79. }
  80. return taskInfos, total, nil
  81. }
  82. // 获取未传初稿的种草子任务数据
  83. func (d ProjectTaskInfoDao) GetListBySketchDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  84. projectTaskInfos := []entity.ProjectTaskInfo{}
  85. var total int64
  86. query := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND cur_default_type = ?", param.TaskId, 4)
  87. query.Count(&total)
  88. query = query.Select("task_id, talent_id, settle_amount, draft_fee, sketch_missing_time, open_id")
  89. offset := (param.Page - 1) * param.PageSize
  90. if err := query.Order("sketch_missing_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  91. return nil, 0, err
  92. }
  93. return projectTaskInfos, total, nil
  94. }
  95. // 获取未发作品的种草子任务数据
  96. func (d ProjectTaskInfoDao) GetListByLinkDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  97. projectTaskInfos := []entity.ProjectTaskInfo{}
  98. var total int64
  99. query := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND cur_default_type = ?", param.TaskId, 6)
  100. query.Count(&total)
  101. query = query.Select("task_id, talent_id, settle_amount, draft_fee, link_missing_time, open_id")
  102. offset := (param.Page - 1) * param.PageSize
  103. if err := query.Order("link_missing_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  104. return nil, 0, err
  105. }
  106. return projectTaskInfos, total, nil
  107. }
  108. // 获取未传数据的种草子任务数据
  109. func (d ProjectTaskInfoDao) GetListByDataDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  110. projectTaskInfos := []entity.ProjectTaskInfo{}
  111. var total int64
  112. query := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND cur_default_type = ?", param.TaskId, 8)
  113. query.Count(&total)
  114. query = query.Select("task_id, talent_id, settle_amount, draft_fee, data_missing_time, open_id")
  115. offset := (param.Page - 1) * param.PageSize
  116. if err := query.Order("data_missing_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  117. return nil, 0, err
  118. }
  119. return projectTaskInfos, total, nil
  120. }
  121. // 获取终止合作的种草子任务数据
  122. func (d ProjectTaskInfoDao) GetListByTerminateDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  123. projectTaskInfos := []entity.ProjectTaskInfo{}
  124. var total int64
  125. query := Db.Debug().Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND task_stage = ?", param.TaskId, 17)
  126. query.Count(&total)
  127. query = query.Select("task_id, talent_id, settle_amount, draft_fee, terminate_time, terminate_reason, terminate_operator_type, terminate_operator, open_id")
  128. offset := (param.Page - 1) * param.PageSize
  129. if err := query.Order("terminate_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  130. return nil, 0, err
  131. }
  132. return projectTaskInfos, total, nil
  133. }
  134. // 获取已解约的种草子任务数据
  135. func (d ProjectTaskInfoDao) GetListByCancelDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  136. projectTaskInfos := []entity.ProjectTaskInfo{}
  137. var total int64
  138. query := Db.Debug().Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND task_stage = ?", param.TaskId, 16)
  139. query.Count(&total)
  140. query = query.Select("task_id, talent_id, settle_amount, draft_fee, cancel_time, cancel_reason, cancel_operator_type, cancel_operator, open_id")
  141. offset := (param.Page - 1) * param.PageSize
  142. if err := query.Order("cancel_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  143. return nil, 0, err
  144. }
  145. return projectTaskInfos, total, nil
  146. }
  147. // 更新字段
  148. func (d ProjectTaskInfoDao) UpdateField(taskId string, updateData map[string]interface{}) error {
  149. err := Db.Model(&entity.ProjectTaskInfo{}).Where("task_id = ?", taskId).Updates(updateData).Error
  150. if err != nil {
  151. return err
  152. }
  153. return nil
  154. }
  155. // 批量更新字段
  156. func (d ProjectTaskInfoDao) UpdateFieldBatch(taskIds []string, updateData map[string]interface{}) error {
  157. err := Db.Model(&entity.ProjectTaskInfo{}).Where("task_id IN ?", taskIds).Updates(updateData).Error
  158. if err != nil {
  159. return err
  160. }
  161. return nil
  162. }
  163. func (d ProjectTaskInfoDao) GetProjectInfoByTalentId(talentid string, others string, sortField []string, sortOrder []string, page int, pageSize int, reltype int, enterpriseid string, platform int) ([]*entity.ProjectTaskInfo, int64, error) {
  164. projectTaskInfos := []*entity.ProjectTaskInfo{}
  165. var total int64
  166. query := Db.Model(&entity.ProjectTaskInfo{}).
  167. Joins("JOIN project_info pi ON pi.project_id = youngee_task_info.project_id").
  168. Where("youngee_task_info.talent_id = ? AND youngee_task_info.task_stage = ? AND youngee_task_info.platform_id = ?", talentid, 15, platform)
  169. // 搜索条件(针对project_name)
  170. if others != "" {
  171. query = query.Where("pi.project_name LIKE ?", "%"+others+"%")
  172. }
  173. if reltype == 2 {
  174. query = query.Where("pi.enterprise_id = ?", enterpriseid)
  175. }
  176. // 排序处理
  177. if len(sortField) > 0 && len(sortOrder) > 0 && len(sortField) == len(sortOrder) {
  178. for i := 0; i < len(sortField); i++ {
  179. sortfield := sortField[i]
  180. sortorder := sortOrder[i]
  181. switch sortfield {
  182. case "commit_avg":
  183. if sortorder == "asc" {
  184. query = query.Order("youngee_task_info.commit_avg asc")
  185. } else {
  186. query = query.Order("youngee_task_info.commit_avg desc")
  187. }
  188. case "collect_num":
  189. if sortorder == "asc" {
  190. query = query.Order("youngee_task_info.collect_num asc")
  191. } else {
  192. query = query.Order("youngee_task_info.collect_num desc")
  193. }
  194. case "vote_avg":
  195. if sortorder == "asc" {
  196. query = query.Order("youngee_task_info.vote_avg asc")
  197. } else {
  198. query = query.Order("youngee_task_info.vote_avg desc")
  199. }
  200. case "view_num":
  201. if sortorder == "asc" {
  202. query = query.Order("youngee_task_info.view_num asc")
  203. } else {
  204. query = query.Order("youngee_task_info.view_num desc")
  205. }
  206. }
  207. }
  208. }
  209. // 获取总数
  210. if err := query.Count(&total).Error; err != nil {
  211. return nil, 0, err
  212. }
  213. // 选择字段(明确指定表名)
  214. query = query.Select(`
  215. youngee_task_info.project_id,
  216. youngee_task_info.task_id,
  217. pi.project_name,
  218. youngee_task_info.commit_avg,
  219. youngee_task_info.collect_num,
  220. youngee_task_info.vote_avg,
  221. youngee_task_info.view_num
  222. `)
  223. // 分页查询
  224. offset := (page - 1) * pageSize
  225. err := query.Offset(offset).Limit(pageSize).Find(&projectTaskInfos).Error
  226. if err != nil {
  227. return nil, 0, err
  228. }
  229. return projectTaskInfos, total, nil
  230. }