project_task_info_dao.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. // 获取指定任务阶段的种草子任务
  20. func (d ProjectTaskInfoDao) GetListByTaskStage(projectId string, taskStage int64, time string, page int, pageSize int, talentNickname string) ([]*entity.ProjectTaskInfo, int64, error) {
  21. var taskInfos []*entity.ProjectTaskInfo
  22. var total int64
  23. query := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND task_stage = ?", projectId, taskStage)
  24. if talentNickname != "" {
  25. var talentInfos []entity.YoungeeTalentInfo
  26. err1 := Db.Model(&entity.YoungeeTalentInfo{}).Where("talent_wx_nickname = ?", talentNickname).Find(&talentInfos).Error
  27. if err1 != nil {
  28. return nil, 0, err1
  29. }
  30. var talentIds []string
  31. for _, talentInfo := range talentInfos {
  32. talentIds = append(talentIds, talentInfo.ID)
  33. }
  34. query = query.Where("talent_id in ?", talentIds)
  35. }
  36. // 计算偏移量
  37. offset := (page - 1) * pageSize
  38. var err error
  39. if taskStage == 4 {
  40. query.Count(&total)
  41. err = query.Order("create_date desc").Offset(offset).Limit(pageSize).Find(&taskInfos).Error
  42. } else if taskStage == 5 {
  43. if time != "" {
  44. query = query.Where("DATE(delivery_date) = ?", time)
  45. }
  46. query.Count(&total)
  47. err = query.Order("delivery_date desc").Offset(offset).Limit(pageSize).Find(&taskInfos).Error
  48. } else if taskStage == 6 {
  49. query.Count(&total)
  50. err = query.Order("signed_time desc").Offset(offset).Limit(pageSize).Find(&taskInfos).Error
  51. }
  52. if err != nil {
  53. return nil, 0, err
  54. }
  55. return taskInfos, total, nil
  56. }
  57. // 获取未传初稿的种草子任务数据
  58. func (d ProjectTaskInfoDao) GetListBySketchDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  59. projectTaskInfos := []entity.ProjectTaskInfo{}
  60. var total int64
  61. query := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND cur_default_type = ?", param.TaskId, 4)
  62. query.Count(&total)
  63. query = query.Select("task_id, talent_id, settle_amount, draft_fee, sketch_missing_time")
  64. offset := (param.Page - 1) * param.PageSize
  65. if err := query.Order("sketch_missing_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  66. return nil, 0, err
  67. }
  68. return projectTaskInfos, total, nil
  69. }
  70. // 获取未发作品的种草子任务数据
  71. func (d ProjectTaskInfoDao) GetListByLinkDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  72. projectTaskInfos := []entity.ProjectTaskInfo{}
  73. var total int64
  74. query := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND cur_default_type = ?", param.TaskId, 6)
  75. query.Count(&total)
  76. query = query.Select("task_id, talent_id, settle_amount, draft_fee, link_missing_time")
  77. offset := (param.Page - 1) * param.PageSize
  78. if err := query.Order("link_missing_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  79. return nil, 0, err
  80. }
  81. return projectTaskInfos, total, nil
  82. }
  83. // 获取未传数据的种草子任务数据
  84. func (d ProjectTaskInfoDao) GetListByDataDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  85. projectTaskInfos := []entity.ProjectTaskInfo{}
  86. var total int64
  87. query := Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND cur_default_type = ?", param.TaskId, 8)
  88. query.Count(&total)
  89. query = query.Select("task_id, talent_id, settle_amount, draft_fee, data_missing_time")
  90. offset := (param.Page - 1) * param.PageSize
  91. if err := query.Order("data_missing_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  92. return nil, 0, err
  93. }
  94. return projectTaskInfos, total, nil
  95. }
  96. // 获取终止合作的种草子任务数据
  97. func (d ProjectTaskInfoDao) GetListByTerminateDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  98. projectTaskInfos := []entity.ProjectTaskInfo{}
  99. var total int64
  100. query := Db.Debug().Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND task_stage = ?", param.TaskId, 17)
  101. query.Count(&total)
  102. query = query.Select("task_id, talent_id, settle_amount, draft_fee, terminate_time, terminate_reason, terminate_operator_type, terminate_operator")
  103. offset := (param.Page - 1) * param.PageSize
  104. if err := query.Order("terminate_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  105. return nil, 0, err
  106. }
  107. return projectTaskInfos, total, nil
  108. }
  109. // 获取已解约的种草子任务数据
  110. func (d ProjectTaskInfoDao) GetListByCancelDefault(param *vo.DefaultSearchParam) ([]entity.ProjectTaskInfo, int64, error) {
  111. projectTaskInfos := []entity.ProjectTaskInfo{}
  112. var total int64
  113. query := Db.Debug().Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND task_stage = ?", param.TaskId, 16)
  114. query.Count(&total)
  115. query = query.Select("task_id, talent_id, settle_amount, draft_fee, cancel_time, cancel_reason, cancel_operator_type, cancel_operator")
  116. offset := (param.Page - 1) * param.PageSize
  117. if err := query.Order("cancel_time desc").Offset(offset).Limit(param.PageSize).Find(&projectTaskInfos).Error; err != nil {
  118. return nil, 0, err
  119. }
  120. return projectTaskInfos, total, nil
  121. }
  122. // 更新字段
  123. func (d ProjectTaskInfoDao) UpdateField(taskId string, updateData map[string]interface{}) error {
  124. err := Db.Model(&entity.ProjectTaskInfo{}).Where("task_id = ?", taskId).Updates(updateData).Error
  125. if err != nil {
  126. return err
  127. }
  128. return nil
  129. }
  130. // 批量更新字段
  131. func (d ProjectTaskInfoDao) UpdateFieldBatch(taskIds []string, updateData map[string]interface{}) error {
  132. err := Db.Model(&entity.ProjectTaskInfo{}).Where("task_id IN ?", taskIds).Updates(updateData).Error
  133. if err != nil {
  134. return err
  135. }
  136. return nil
  137. }