Browse Source

Merge branch 'bzq/dev' of eta_mini/eta_mini_crm into debug

baoziqiang 6 tháng trước cách đây
mục cha
commit
67307454b9

+ 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()

+ 20 - 16
models/report_pdf.go

@@ -117,7 +117,7 @@ func (r *ReportPdf) Update(cols []string) (err error) {
 	if err != nil {
 		return
 	}
-	if (reportPushStatus == nil || err.Error() == utils.ErrNoRow()) && r.State == 1 {
+	if (reportPushStatus == nil || err.Error() == utils.ErrNoRow()) && r.State == utils.ReportStatusUp {
 		insertPushStatus := &ReportPushStatus{
 			ReportId:           r.ReportPdfId,
 			State:              0,
@@ -137,22 +137,26 @@ func (r *ReportPdf) Update(cols []string) (err error) {
 			ModifyTime:         time.Now(),
 		}
 		_, err = tx.Insert(insertPushStatus)
-	} else {
-		reportPushStatus.Title = r.Title
-		reportPushStatus.Abstract = r.Abstract
-		reportPushStatus.Stage = r.Stage
-		reportPushStatus.ClassifyIdFirst = r.ClassifyIdFirst
-		reportPushStatus.ClassifyNameFirst = r.ClassifyNameFirst
-		reportPushStatus.ClassifyIdSecond = r.ClassifyIdSecond
-		reportPushStatus.ClassifyNameSecond = r.ClassifyNameSecond
-		reportPushStatus.ClassifyIdThird = r.ClassifyIdThird
-		reportPushStatus.ClassifyNameThird = r.ClassifyNameThird
-		reportPushStatus.Author = r.Author
-		reportPushStatus.PublishTime = r.PublishTime
-		reportPushStatus.ModifyTime = time.Now()
-		_, err = tx.Update(reportPushStatus)
+	} else if reportPushStatus != nil || err.Error() != utils.ErrNoRow() {
+		// pdf报告发布后编辑,则更新report_push_status表, 若取消发布,则在推送表中删除
+		if r.State == utils.ReportStatusDown {
+			err = reportPushStatus.Delete()
+		} else {
+			reportPushStatus.Title = r.Title
+			reportPushStatus.Abstract = r.Abstract
+			reportPushStatus.Stage = r.Stage
+			reportPushStatus.ClassifyIdFirst = r.ClassifyIdFirst
+			reportPushStatus.ClassifyNameFirst = r.ClassifyNameFirst
+			reportPushStatus.ClassifyIdSecond = r.ClassifyIdSecond
+			reportPushStatus.ClassifyNameSecond = r.ClassifyNameSecond
+			reportPushStatus.ClassifyIdThird = r.ClassifyIdThird
+			reportPushStatus.ClassifyNameThird = r.ClassifyNameThird
+			reportPushStatus.Author = r.Author
+			reportPushStatus.PublishTime = r.PublishTime
+			reportPushStatus.ModifyTime = time.Now()
+			_, err = tx.Update(reportPushStatus)
+		}
 	}
-
 	return
 }
 

+ 37 - 11
models/report_push_status.go

@@ -85,10 +85,16 @@ func (r *ReportPushStatus) Update(cols []string) (err error) {
 	return
 }
 
-func GetReportPushStatusByReportId(reportId, state int) (item *ReportPushStatus, err error) {
+func (r *ReportPushStatus) Delete() (err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM report_push_status WHERE report_id=? AND state=?`
-	err = o.Raw(sql, reportId, state).QueryRow(&item)
+	_, err = o.Delete(r)
+	return
+}
+
+func GetReportPushStatusByReportId(reportPushStatusId, state int) (item *ReportPushStatus, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM report_push_status WHERE report_push_status_id=? AND state=?`
+	err = o.Raw(sql, reportPushStatusId, state).QueryRow(&item)
 	return
 }
 
@@ -102,6 +108,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 +162,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 +190,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 {