Browse Source

fix:修改报告推送

zqbao 5 months ago
parent
commit
7bf9f5b5a0
3 changed files with 83 additions and 64 deletions
  1. 51 52
      controllers/report_push_status.go
  2. 31 11
      models/report_push_status.go
  3. 1 1
      models/request/report_push_status.go

+ 51 - 52
controllers/report_push_status.go

@@ -254,7 +254,7 @@ func (this *ReportPushStatusController) PushCancel() {
 		return
 	}
 
-	reportPush, err := models.GetReportPushStatusByReportId(req.ReportId, 1)
+	reportPush, err := models.GetReportPushStatusByReportId(req.ReportPushStatusId, 1)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "推送失败"
 		br.ErrMsg = "获取推送消息失败,Err:" + err.Error()
@@ -295,17 +295,7 @@ func (this *ReportPushStatusController) Push() {
 		return
 	}
 
-	count, err := models.GetReportCountById(req.ReportId)
-	if err != nil {
-		br.Msg = "研报未发布或已删除"
-		br.ErrMsg = "研报查询失败,Err:" + err.Error()
-		return
-	}
-	if count == 0 {
-		br.Msg = "研报未发布或已删除"
-		return
-	}
-	reportPush, err := models.GetReportPushStatusByReportId(req.ReportId, 0)
+	reportPush, err := models.GetReportPushStatusByReportId(req.ReportPushStatusId, 0)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "推送失败"
 		br.ErrMsg = "获取推送消息失败,Err:" + err.Error()
@@ -349,6 +339,7 @@ func (this *ReportPushStatusController) BatchPush() {
 	}
 	var condition string
 	var pars []interface{}
+	condition = ` AND state = 0 `
 	if req.PublishStartDate != "" && req.PublishEndDate != "" {
 		condition += " AND publish_time >= ?"
 		publishStartTime, err := time.Parse(utils.FormatDate, req.PublishStartDate)
@@ -414,39 +405,39 @@ func (this *ReportPushStatusController) BatchPush() {
 	}
 	if req.IsSelectAll {
 		if len(req.SelectedIds) > 0 {
-			condition += ` AND report_id NOT IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
+			condition += ` AND report_push_status_id NOT IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
 			pars = append(pars, req.SelectedIds)
 		}
 	} else {
 		if len(req.SelectedIds) > 0 {
-			condition += ` AND report_id IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
+			condition += ` AND report_push_status_id IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
 			pars = append(pars, req.SelectedIds)
 		}
 	}
-	reportIds, err := models.GetReportIdListByCondition(condition, pars)
+	reportPushStatusIds, err := models.GetReportPushStatusIdListByCondition(condition, pars)
 	if err != nil {
 		br.Msg = "批量推送失败"
 		br.ErrMsg = "查询研报失败,Err:" + err.Error()
 		return
 	}
-	reportPush, err := models.GetReportPushStatusByReportIdAndState(reportIds, 0)
-	if err != nil {
-		br.Msg = "批量推送失败"
-		br.ErrMsg = "查询推送状态失败,Err:" + err.Error()
-		return
-	}
-	existReportMap := make(map[int]struct{})
-	for _, v := range reportPush {
-		existReportMap[v.ReportId] = struct{}{}
-	}
-	existReportIds := make([]int, 0)
-	for _, v := range reportIds {
-		if _, ok := existReportMap[v]; ok {
-			existReportIds = append(existReportIds, v)
-		}
-	}
+	// reportPush, err := models.GetReportPushStatusByIdAndState(reportIds, 0)
+	// if err != nil {
+	// 	br.Msg = "批量推送失败"
+	// 	br.ErrMsg = "查询推送状态失败,Err:" + err.Error()
+	// 	return
+	// }
+	// existReportMap := make(map[int]struct{})
+	// for _, v := range reportPush {
+	// 	existReportMap[v.ReportId] = struct{}{}
+	// }
+	// existReportIds := make([]int, 0)
+	// for _, v := range reportIds {
+	// 	if _, ok := existReportMap[v]; ok {
+	// 		existReportIds = append(existReportIds, v)
+	// 	}
+	// }
 
-	err = models.BatchPushReport(existReportIds)
+	err = models.BatchPushReport(reportPushStatusIds)
 	if err != nil {
 		br.Msg = "批量推送失败"
 		br.ErrMsg = "批量修改推送失败,Err:" + err.Error()
@@ -478,6 +469,7 @@ func (this *ReportPushStatusController) BatchPushCancel() {
 	}
 	var condition string
 	var pars []interface{}
+	condition = ` AND state = 1 `
 	if req.PublishStartDate != "" && req.PublishEndDate != "" {
 		condition += " AND publish_time >= ?"
 		publishStartTime, err := time.Parse(utils.FormatDate, req.PublishStartDate)
@@ -543,39 +535,46 @@ func (this *ReportPushStatusController) BatchPushCancel() {
 	}
 	if req.IsSelectAll {
 		if len(req.SelectedIds) > 0 {
-			condition += ` AND report_id NOT IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
+			condition += ` AND report_push_status_id NOT IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
 			pars = append(pars, req.SelectedIds)
 		}
 	} else {
 		if len(req.SelectedIds) > 0 {
-			condition += ` AND report_id IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
+			condition += ` AND report_push_status_id IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
 			pars = append(pars, req.SelectedIds)
 		}
 	}
-	reportIds, err := models.GetReportIdListByCondition(condition, pars)
+
+	reportPushStatusIds, err := models.GetReportPushStatusIdListByCondition(condition, pars)
 	if err != nil {
 		br.Msg = "批量推送失败"
 		br.ErrMsg = "查询研报失败,Err:" + err.Error()
 		return
 	}
-	reportPush, err := models.GetReportPushStatusByReportIdAndState(reportIds, 1)
-	if err != nil {
-		br.Msg = "批量推送失败"
-		br.ErrMsg = "查询推送状态失败,Err:" + err.Error()
-		return
-	}
-	existReportMap := make(map[int]struct{})
-	for _, v := range reportPush {
-		existReportMap[v.ReportId] = struct{}{}
-	}
-	existReportIds := make([]int, 0)
-	for _, v := range reportIds {
-		if _, ok := existReportMap[v]; ok {
-			existReportIds = append(existReportIds, v)
-		}
-	}
+	// reportIds, err := models.GetReportIdListByCondition(condition, pars)
+	// if err != nil {
+	// 	br.Msg = "批量推送失败"
+	// 	br.ErrMsg = "查询研报失败,Err:" + err.Error()
+	// 	return
+	// }
+	// reportPush, err := models.GetReportPushStatusByReportIdAndState(reportIds, 1)
+	// if err != nil {
+	// 	br.Msg = "批量推送失败"
+	// 	br.ErrMsg = "查询推送状态失败,Err:" + err.Error()
+	// 	return
+	// }
+	// existReportMap := make(map[int]struct{})
+	// for _, v := range reportPush {
+	// 	existReportMap[v.ReportId] = struct{}{}
+	// }
+	// existReportIds := make([]int, 0)
+	// for _, v := range reportIds {
+	// 	if _, ok := existReportMap[v]; ok {
+	// 		existReportIds = append(existReportIds, v)
+	// 	}
+	// }
 
-	err = models.BatchPushCancelReport(existReportIds)
+	err = models.BatchPushCancelReport(reportPushStatusIds)
 	if err != nil {
 		br.Msg = "批量取消推送失败"
 		br.ErrMsg = "批量修改推送失败,Err:" + err.Error()

+ 31 - 11
models/report_push_status.go

@@ -85,10 +85,10 @@ func (r *ReportPushStatus) Update(cols []string) (err error) {
 	return
 }
 
-func GetReportPushStatusByReportId(reportId, state int) (item *ReportPushStatus, err error) {
+func GetReportPushStatusByReportId(reportPushStatusId, state int) (item *ReportPushStatus, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM report_push_status WHERE report_id=? AND state=?`
-	err = o.Raw(sql, reportId, state).QueryRow(&item)
+	sql := `SELECT * FROM report_push_status WHERE report_push_status_id=? AND state=?`
+	err = o.Raw(sql, reportPushStatusId, state).QueryRow(&item)
 	return
 }
 
@@ -102,6 +102,16 @@ func GetReportPushStatusByReportIdAndState(reportId []int, state int) (items []*
 	return
 }
 
+func GetReportPushStatusByIdAndState(Id []int, state int) (items []*ReportPushStatus, err error) {
+	if len(Id) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := `SELECT * FROM report_push_status WHERE report_push_status_id IN (` + utils.GetOrmReplaceHolder(len(Id)) + `) AND state=?`
+	_, err = o.Raw(sql, Id, state).QueryRows(&items)
+	return
+}
+
 func GetReportPushStatusByReportIds(reportType int, reportId []int) (items []*ReportPushStatus, err error) {
 	if len(reportId) == 0 {
 		return
@@ -146,6 +156,16 @@ func GetReportIdListByCondition(condition string, pars []interface{}) (reportId
 	return
 }
 
+func GetReportPushStatusIdListByCondition(condition string, pars []interface{}) (reportPushStatusId []int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT report_push_status_id FROM report_push_status WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&reportPushStatusId)
+	return
+}
+
 func GetReportCountById(id int) (count int, err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	sql := `SELECT COUNT(*) AS count FROM report WHERE (state=2 OR state=6) AND id=?`
@@ -164,24 +184,24 @@ func GetReportCountByCondition(condition string, pars []interface{}) (count int,
 }
 
 // BatchPushReport 批量推送报告
-func BatchPushReport(reportId []int) (err error) {
-	if len(reportId) == 0 {
+func BatchPushReport(reportPushStatusId []int) (err error) {
+	if len(reportPushStatusId) == 0 {
 		return
 	}
 	o := orm.NewOrm()
-	sql := `UPDATE report_push_status SET state=1, push_time=NOW() WHERE report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `)`
-	_, err = o.Raw(sql, reportId).Exec()
+	sql := `UPDATE report_push_status SET state=1, push_time=NOW() WHERE report_push_status_id IN (` + utils.GetOrmReplaceHolder(len(reportPushStatusId)) + `)`
+	_, err = o.Raw(sql, reportPushStatusId).Exec()
 	return
 }
 
 // BatchPushCancelReport 批量撤销推送报告
-func BatchPushCancelReport(reportId []int) (err error) {
-	if len(reportId) == 0 {
+func BatchPushCancelReport(reportPushStatusId []int) (err error) {
+	if len(reportPushStatusId) == 0 {
 		return
 	}
 	o := orm.NewOrm()
-	sql := `UPDATE report_push_status SET state=0, modify_time=NOW() WHERE report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `)`
-	_, err = o.Raw(sql, reportId).Exec()
+	sql := `UPDATE report_push_status SET state=0, modify_time=NOW() WHERE report_push_status_id IN (` + utils.GetOrmReplaceHolder(len(reportPushStatusId)) + `)`
+	_, err = o.Raw(sql, reportPushStatusId).Exec()
 	return
 }
 

+ 1 - 1
models/request/report_push_status.go

@@ -1,7 +1,7 @@
 package request
 
 type ReportPushStatusReq struct {
-	ReportId int
+	ReportPushStatusId int
 }
 
 type BatchReportModifyPushStatusReq struct {