Browse Source

add:添加报告推送app

zqbao 7 months ago
parent
commit
0b9b5c5352

+ 632 - 0
controllers/report_push_status.go

@@ -0,0 +1,632 @@
+package controllers
+
+import (
+	"encoding/json"
+	"eta/eta_mini_crm/models"
+	"eta/eta_mini_crm/models/request"
+	"eta/eta_mini_crm/models/response"
+	"eta/eta_mini_crm/utils"
+	"fmt"
+	"strconv"
+	"strings"
+	"time"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+type ReportPushStatusController struct {
+	BaseAuthController
+}
+
+// List
+// @Title pdf研报列表
+// @Description pdf研报列表
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   ClassifyIds   query   string  true       "分类id,可多选用英文,隔开"
+// @Param   ChartPermissionIds   query   string  true       "品种id,可多选用英文,隔开"
+// @Param   PublishStartDate   query   string  true       "发布开始时间"
+// @Param   PublishEndDate   query   string  true       "发布结束时间"
+// @Param   PushStartDate   query   string  true       "推送开始时间"
+// @Param   PushEndDate   query   string  true       "推送结束时间"
+// @Param   KeyWord   query   string  true       "报告标题/创建人"
+// @Param   SelectedIds   query   string  true       "选择的报告id, isSelectAll:为true时,反选"
+// @Param   IsSelectAll   query   bool  true       "是否全选"
+// @Param   SortParam   query   string  true       "排序字段"
+// @Param   SortType   query   string  true       "排序方式"
+// @Success 200 {object} models.ReportAuthorResp
+// @router /list [get]
+func (this *ReportPushStatusController) List() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	classifyIds := this.GetString("ClassifyIds")
+	selectedIds := this.GetString("SelectedIds")
+	isSelectAll, _ := this.GetBool("IsSelectAll")
+	chartPermissionIds := this.GetString("ChartPermissionIds")
+	publishStartDate := this.GetString("PublishStartDate")
+	publishEndDate := this.GetString("PublishEndDate")
+	pushStartDate := this.GetString("PushStartDate")
+	pushEndDate := this.GetString("PushEndDate")
+	keyWord := this.GetString("KeyWord")
+	sortParam := this.GetString("SortParam")
+	sortType := this.GetString("SortType")
+
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	var condition string
+	var pars []interface{}
+	if publishStartDate != "" && publishEndDate != "" {
+		condition += " AND a.publish_time >= ?"
+		publishStartTime, err := time.Parse(utils.FormatDate, publishStartDate)
+		if err != nil {
+			br.Msg = "日期格式有误"
+			br.ErrMsg = "日期格式有误,Err:" + err.Error()
+			return
+		}
+		publishStartDateStr := publishStartTime.Format(utils.FormatDateTime)
+		pars = append(pars, publishStartDateStr)
+
+		condition += " AND a.publish_time <= ?"
+		publishEndTime, err := time.Parse(utils.FormatDate, publishEndDate)
+		if err != nil {
+			br.Msg = "日期格式有误"
+			br.ErrMsg = "日期格式有误,Err:" + err.Error()
+			return
+		}
+		publishEndTime = publishEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
+		publishEndDateStr := publishEndTime.Format(utils.FormatDateTime)
+		pars = append(pars, publishEndDateStr)
+	}
+	if pushStartDate != "" && pushEndDate != "" {
+		condition += " AND b.push_time >= ?"
+		pushStartTime, err := time.Parse(utils.FormatDate, pushStartDate)
+		if err != nil {
+			br.Msg = "日期格式有误"
+			br.ErrMsg = "日期格式有误,Err:" + err.Error()
+			return
+		}
+		pushStartDateStr := pushStartTime.Format(utils.FormatDateTime)
+		pars = append(pars, pushStartDateStr)
+
+		condition += " AND b.push_time <= ?"
+		pushEndTime, err := time.Parse(utils.FormatDate, pushEndDate)
+		if err != nil {
+			br.Msg = "日期格式有误"
+			br.ErrMsg = "日期格式有误,Err:" + err.Error()
+			return
+		}
+		pushEndTime = pushEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
+		pushEndDateStr := pushEndTime.Format(utils.FormatDateTime)
+		pars = append(pars, pushEndDateStr)
+	}
+	if keyWord != "" {
+		condition += ` AND a.title like ?  `
+		pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
+	}
+	var sortCondition string
+	if sortParam != "" && sortType != "" {
+		sortCondition = " ORDER BY "
+		var param, sort string
+		switch sortParam {
+		case "PublishTime":
+			param = "a.publish_time"
+		case "PushTime":
+			param = "b.push_time"
+		}
+		switch sortType {
+		case "asc":
+			sort = " ASC "
+		case "desc":
+			sort = " DESC "
+		}
+		if param != "" && sort != "" {
+			sortCondition += param + " " + sort
+		} else {
+			sortCondition = ""
+		}
+	}
+	if sortCondition == "" {
+		sortCondition = ` ORDER BY a.publish_time DESC `
+	}
+
+	classifyIdList := make([]int, 0)
+	if classifyIds != "" {
+		classifyArrStr := strings.Split(classifyIds, ",")
+		if len(classifyArrStr) > 0 {
+			for _, v := range classifyArrStr {
+				tmp, _ := strconv.Atoi(v)
+				classifyIdList = append(classifyIdList, tmp)
+			}
+		}
+	}
+	if chartPermissionIds != "" {
+		idStrs := strings.Split(chartPermissionIds, ",")
+		idInts := make([]int, 0)
+		for _, id := range idStrs {
+			tmp, _ := strconv.Atoi(id)
+			idInts = append(idInts, tmp)
+		}
+		tmpClassifyList, err := models.GetClassifyIdsListByIds(idInts)
+		if err != nil {
+			br.Msg = "获取研报列表失败"
+			br.ErrMsg = "品种获取分类失败,Err:" + err.Error()
+			return
+		}
+		classifyIdList = append(classifyIdList, tmpClassifyList...)
+	}
+	if len(classifyIdList) > 0 {
+		classifyIdList = utils.Unique(classifyIdList)
+		condition += ` AND (a.classify_id_first IN (%s) AND a.classify_id_second IN (%s) AND a.classify_id_third IN (%s))`
+		condition = fmt.Sprintf(condition, utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)))
+		pars = append(pars, classifyIdList, classifyIdList, classifyIdList)
+	}
+	if isSelectAll {
+		if selectedIds != "" {
+			selectIdStrs := strings.Split(selectedIds, ",")
+			if len(selectIdStrs) > 0 {
+				condition += ` AND a.id NOT IN (` + utils.GetOrmReplaceHolder(len(selectIdStrs)) + `)`
+				pars = append(pars, selectedIds)
+			}
+		}
+	} else {
+		if selectedIds != "" {
+			selectIdStrs := strings.Split(selectedIds, ",")
+			if len(selectIdStrs) > 0 {
+				condition += ` AND a.id IN (` + utils.GetOrmReplaceHolder(len(selectIdStrs)) + `)`
+				pars = append(pars, selectedIds)
+			}
+		}
+	}
+	startSize := utils.StartIndex(currentIndex, pageSize)
+	total, err := models.GetReportCountByCondition(condition, pars)
+	if err != nil {
+		br.Msg = "获取研报列表失败"
+		br.ErrMsg = "获取研报列表统计失败,Err:" + err.Error()
+		return
+	}
+	reportList, err := models.GetReportPushStatusListByCondition(condition, pars, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取研报列表失败"
+		br.ErrMsg = "获取研报列表失败,Err:" + err.Error()
+		return
+	}
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(response.ReportPushStatusResp)
+	resp.List = reportList
+	resp.Paging = page
+
+	br.Data = resp
+	br.Msg = "获取成功"
+	br.Ret = 200
+	br.Success = true
+}
+
+// PushCancel
+// @Title 取消推送报告
+// @Description 取消推送报告
+// @Param	request	body request.ReportPdfEditReq true "type json string"
+// @Success 200 {object} models.ReportAuthorResp
+// @router /pushCancel [post]
+func (this *ReportPushStatusController) PushCancel() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req request.ReportPushStatusReq
+	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,Err:" + err.Error()
+		return
+	}
+
+	reportPush, err := models.GetReportPushStatusByReportId(req.ReportId, 1)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "推送失败"
+		br.ErrMsg = "获取推送消息失败,Err:" + err.Error()
+		return
+	}
+	if reportPush != nil {
+		reportPush.State = 0
+		reportPush.ModifyTime = time.Now()
+		err = reportPush.Update([]string{"state", "modify_time"})
+		if err != nil {
+			br.Msg = "取消推送失败"
+			br.ErrMsg = "取消推送失败,Err:" + err.Error()
+			return
+		}
+	} else {
+		reportPush := &models.ReportPushStatus{}
+		reportPush.ReportId = req.ReportId
+		reportPush.ReportType = 1
+		reportPush.State = 0
+		reportPush.CreateTime = time.Now()
+		reportPush.ModifyTime = time.Now()
+		_, err = reportPush.Insert()
+		if err != nil {
+			br.Msg = "取消推送失败"
+			br.ErrMsg = "新增推送记录失败,Err:" + err.Error()
+			return
+		}
+	}
+
+	br.Msg = "取消推送成功"
+	br.Success = true
+	br.Ret = 200
+}
+
+// Push
+// @Title 推送报告
+// @Description 推送报告
+// @Param	request	body request.ReportPdfEditReq true "type json string"
+// @Success 200 {object} models.ReportAuthorResp
+// @router /push [post]
+func (this *ReportPushStatusController) Push() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req request.ReportPushStatusReq
+	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,Err:" + err.Error()
+		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)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "推送失败"
+		br.ErrMsg = "获取推送消息失败,Err:" + err.Error()
+		return
+	}
+	if reportPush != nil {
+		reportPush.State = 1
+		reportPush.ModifyTime = time.Now()
+		reportPush.PushTime = time.Now()
+		err = reportPush.Update([]string{"state", "modify_time", "push_time"})
+		if err != nil {
+			br.Msg = "推送失败"
+			br.ErrMsg = "推送失败,Err:" + err.Error()
+			return
+		}
+
+	} else {
+		reportPush := &models.ReportPushStatus{}
+		reportPush.ReportId = req.ReportId
+		reportPush.ReportType = 1
+		reportPush.State = 1
+		reportPush.PushTime = time.Now()
+		reportPush.CreateTime = time.Now()
+		reportPush.ModifyTime = time.Now()
+		_, err = reportPush.Insert()
+		if err != nil {
+			br.Msg = "推送失败"
+			br.ErrMsg = "推送失败,Err:" + err.Error()
+			return
+		}
+	}
+
+	br.Msg = "推送成功"
+	br.Success = true
+	br.Ret = 200
+}
+
+// BatchPush
+// @Title 批量推送报告
+// @Description 批量推送报告
+// @Param	request	body request.BatchReportModifyPushStatusReq true "type json string"
+// @Success 200 {object} models.ReportAuthorResp
+// @router /batch/push [post]
+func (this *ReportPushStatusController) BatchPush() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req request.BatchReportModifyPushStatusReq
+	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,Err:" + err.Error()
+		return
+	}
+	var condition string
+	var pars []interface{}
+	if req.PublishStartDate != "" && req.PublishEndDate != "" {
+		condition += " AND a.publish_time >= ?"
+		publishStartTime, err := time.Parse(utils.FormatDate, req.PublishStartDate)
+		if err != nil {
+			br.Msg = "日期格式有误"
+			br.ErrMsg = "日期格式有误,Err:" + err.Error()
+			return
+		}
+		publishStartDateStr := publishStartTime.Format(utils.FormatDateTime)
+		pars = append(pars, publishStartDateStr)
+
+		condition += " AND a.publish_time <= ?"
+		publishEndTime, err := time.Parse(utils.FormatDate, req.PublishEndDate)
+		if err != nil {
+			br.Msg = "日期格式有误"
+			br.ErrMsg = "日期格式有误,Err:" + err.Error()
+			return
+		}
+		publishEndTime = publishEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
+		publishEndDateStr := publishEndTime.Format(utils.FormatDateTime)
+		pars = append(pars, publishEndDateStr)
+	}
+	if req.PushStartDate != "" && req.PushEndDate != "" {
+		condition += " AND b.push_time >= ?"
+		pushStartTime, err := time.Parse(utils.FormatDate, req.PushStartDate)
+		if err != nil {
+			br.Msg = "日期格式有误"
+			br.ErrMsg = "日期格式有误,Err:" + err.Error()
+			return
+		}
+		pushStartDateStr := pushStartTime.Format(utils.FormatDateTime)
+		pars = append(pars, pushStartDateStr)
+
+		condition += " AND b.push_time <= ?"
+		pushEndTime, err := time.Parse(utils.FormatDate, req.PushEndDate)
+		if err != nil {
+			br.Msg = "日期格式有误"
+			br.ErrMsg = "日期格式有误,Err:" + err.Error()
+			return
+		}
+		pushEndTime = pushEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
+		pushEndDateStr := pushEndTime.Format(utils.FormatDateTime)
+		pars = append(pars, pushEndDateStr)
+	}
+	if req.KeyWord != "" {
+		condition += ` AND a.title like ?  `
+		pars = utils.GetLikeKeywordPars(pars, req.KeyWord, 1)
+	}
+	classifyIdList := make([]int, 0)
+	classifyIdList = append(classifyIdList, req.ClassifyIds...)
+	tmpClassifyList, err := models.GetClassifyIdsListByIds(req.ChartPermissionIds)
+	if err != nil {
+		br.Msg = "获取研报列表失败"
+		br.ErrMsg = "品种获取分类失败,Err:" + err.Error()
+		return
+	}
+	classifyIdList = append(classifyIdList, tmpClassifyList...)
+	if len(classifyIdList) > 0 {
+		classifyIdList = utils.Unique(classifyIdList)
+		condition += ` AND (a.classify_id_first IN (%s) AND a.classify_id_second IN (%s) AND a.classify_id_third IN (%s))`
+		condition = fmt.Sprintf(condition, utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)))
+		pars = append(pars, classifyIdList, classifyIdList, classifyIdList)
+	}
+	if req.IsSelectAll {
+		if len(req.SelectedIds) > 0 {
+			condition += ` AND a.id NOT IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
+			pars = append(pars, req.SelectedIds)
+		}
+	} else {
+		if len(req.SelectedIds) > 0 {
+			condition += ` AND a.id IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
+			pars = append(pars, req.SelectedIds)
+		}
+	}
+	reportIds, err := models.GetReportIdListByCondition(condition, pars)
+	if err != nil {
+		br.Msg = "批量推送失败"
+		br.ErrMsg = "查询研报失败,Err:" + err.Error()
+		return
+	}
+	reportPush, err := models.GetReportPushStatusByReportIds(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)
+	noExistReportIds := make([]int, 0)
+	for _, v := range reportIds {
+		if _, ok := existReportMap[v]; !ok {
+			noExistReportIds = append(noExistReportIds, v)
+		} else {
+			existReportIds = append(existReportIds, v)
+		}
+	}
+
+	err = models.BatchPushReport(existReportIds)
+	if err != nil {
+		br.Msg = "批量推送失败"
+		br.ErrMsg = "批量修改推送失败,Err:" + err.Error()
+		return
+	}
+	insertReportPushList := make([]*models.ReportPushStatus, 0)
+	for _, v := range noExistReportIds {
+		insertReportPushList = append(insertReportPushList, &models.ReportPushStatus{
+			ReportId:   v,
+			State:      1,
+			ReportType: 1,
+			CreateTime: time.Now(),
+			ModifyTime: time.Now(),
+			PushTime:   time.Now(),
+		})
+	}
+	obj := &models.ReportPushStatus{}
+	err = obj.MultiInsert(insertReportPushList)
+	if err != nil {
+		br.Msg = "批量推送失败"
+		br.ErrMsg = "批量插入推送状态失败,Err:" + err.Error()
+		return
+	}
+
+	br.Msg = "推送成功"
+	br.Success = true
+	br.Ret = 200
+}
+
+// BatchPushCancel
+// @Title 批量撤销推送报告
+// @Description 批量撤销推送报告
+// @Param	request	body request.BatchReportModifyPushStatusReq true "type json string"
+// @Success 200 {object} models.ReportAuthorResp
+// @router /batch/pushCancel [post]
+func (this *ReportPushStatusController) BatchPushCancel() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req request.BatchReportModifyPushStatusReq
+	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,Err:" + err.Error()
+		return
+	}
+	var condition string
+	var pars []interface{}
+	if req.PublishStartDate != "" && req.PublishEndDate != "" {
+		condition += " AND a.publish_time >= ?"
+		publishStartTime, err := time.Parse(utils.FormatDate, req.PublishStartDate)
+		if err != nil {
+			br.Msg = "日期格式有误"
+			br.ErrMsg = "日期格式有误,Err:" + err.Error()
+			return
+		}
+		publishStartDateStr := publishStartTime.Format(utils.FormatDateTime)
+		pars = append(pars, publishStartDateStr)
+
+		condition += " AND a.publish_time <= ?"
+		publishEndTime, err := time.Parse(utils.FormatDate, req.PublishEndDate)
+		if err != nil {
+			br.Msg = "日期格式有误"
+			br.ErrMsg = "日期格式有误,Err:" + err.Error()
+			return
+		}
+		publishEndTime = publishEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
+		publishEndDateStr := publishEndTime.Format(utils.FormatDateTime)
+		pars = append(pars, publishEndDateStr)
+	}
+	if req.PushStartDate != "" && req.PushEndDate != "" {
+		condition += " AND b.push_time >= ?"
+		pushStartTime, err := time.Parse(utils.FormatDate, req.PushStartDate)
+		if err != nil {
+			br.Msg = "日期格式有误"
+			br.ErrMsg = "日期格式有误,Err:" + err.Error()
+			return
+		}
+		pushStartDateStr := pushStartTime.Format(utils.FormatDateTime)
+		pars = append(pars, pushStartDateStr)
+
+		condition += " AND b.push_time <= ?"
+		pushEndTime, err := time.Parse(utils.FormatDate, req.PushEndDate)
+		if err != nil {
+			br.Msg = "日期格式有误"
+			br.ErrMsg = "日期格式有误,Err:" + err.Error()
+			return
+		}
+		pushEndTime = pushEndTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
+		pushEndDateStr := pushEndTime.Format(utils.FormatDateTime)
+		pars = append(pars, pushEndDateStr)
+	}
+	if req.KeyWord != "" {
+		condition += ` AND a.title like ?  `
+		pars = utils.GetLikeKeywordPars(pars, req.KeyWord, 1)
+	}
+	classifyIdList := make([]int, 0)
+	classifyIdList = append(classifyIdList, req.ClassifyIds...)
+	tmpClassifyList, err := models.GetClassifyIdsListByIds(req.ChartPermissionIds)
+	if err != nil {
+		br.Msg = "获取研报列表失败"
+		br.ErrMsg = "品种获取分类失败,Err:" + err.Error()
+		return
+	}
+	classifyIdList = append(classifyIdList, tmpClassifyList...)
+	if len(classifyIdList) > 0 {
+		classifyIdList = utils.Unique(classifyIdList)
+		condition += ` AND (a.classify_id_first IN (%s) AND a.classify_id_second IN (%s) AND a.classify_id_third IN (%s))`
+		condition = fmt.Sprintf(condition, utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)), utils.GetOrmReplaceHolder(len(classifyIdList)))
+		pars = append(pars, classifyIdList, classifyIdList, classifyIdList)
+	}
+	if req.IsSelectAll {
+		if len(req.SelectedIds) > 0 {
+			condition += ` AND a.id NOT IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
+			pars = append(pars, req.SelectedIds)
+		}
+	} else {
+		if len(req.SelectedIds) > 0 {
+			condition += ` AND a.id IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
+			pars = append(pars, req.SelectedIds)
+		}
+	}
+	reportIds, err := models.GetReportIdListByCondition(condition, pars)
+	if err != nil {
+		br.Msg = "批量推送失败"
+		br.ErrMsg = "查询研报失败,Err:" + err.Error()
+		return
+	}
+	reportPush, err := models.GetReportPushStatusByReportIds(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)
+	noExistReportIds := make([]int, 0)
+	for _, v := range reportIds {
+		if _, ok := existReportMap[v]; !ok {
+			noExistReportIds = append(noExistReportIds, v)
+		} else {
+			existReportIds = append(existReportIds, v)
+		}
+	}
+
+	err = models.BatchPushCancelReport(existReportIds)
+	if err != nil {
+		br.Msg = "批量取消推送失败"
+		br.ErrMsg = "批量修改推送失败,Err:" + err.Error()
+		return
+	}
+	insertReportPushList := make([]*models.ReportPushStatus, 0)
+	for _, v := range noExistReportIds {
+		insertReportPushList = append(insertReportPushList, &models.ReportPushStatus{
+			ReportId:   v,
+			State:      0,
+			ReportType: 1,
+			CreateTime: time.Now(),
+			ModifyTime: time.Now(),
+		})
+	}
+	obj := &models.ReportPushStatus{}
+	err = obj.MultiInsert(insertReportPushList)
+	if err != nil {
+		br.Msg = "批量撤销推送失败"
+		br.ErrMsg = "批量插入推送状态失败,Err:" + err.Error()
+		return
+	}
+
+	br.Msg = "撤销推送成功"
+	br.Success = true
+	br.Ret = 200
+}

+ 90 - 0
models/chart_permission_search_key_word_mapping.go

@@ -0,0 +1,90 @@
+package models
+
+import (
+	"eta/eta_mini_crm/utils"
+	"fmt"
+	"strings"
+
+	"github.com/beego/beego/v2/client/orm"
+)
+
+type ChartPermissionSearchKeyWordMapping struct {
+	Id                int `orm:"pk" description:"id"`
+	ChartPermissionId int `description:"品种id"`
+	ClassifyId        int `description:"分类id"`
+}
+
+func GetClassifyIdsListById(chartPermissionId int) (classifyIds []int, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT classify_id
+		FROM chart_permission_search_key_word_mapping	
+		WHERE chart_permission_id = ? `
+	_, err = o.Raw(sql, chartPermissionId).QueryRows(&classifyIds)
+	return
+}
+
+func GetChartPermissionIdsListByClassifyId(classifyId int) (chartPermissionIds []string, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT chart_permission_id
+		FROM chart_permission_search_key_word_mapping	
+		WHERE classify_id = ? `
+	_, err = o.Raw(sql, classifyId).QueryRows(&chartPermissionIds)
+	return
+}
+
+func GetChartPermissionIdsListByClassifyIds(classifyId []int) (chartPermissionIds []int, err error) {
+	if len(classifyId) == 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT chart_permission_id
+		FROM chart_permission_search_key_word_mapping	
+		WHERE classify_id = (%s) `
+	sql = fmt.Sprintf(sql, utils.GetOrmReplaceHolder(len(classifyId)))
+
+	_, err = o.Raw(sql, classifyId).QueryRows(&chartPermissionIds)
+	return
+}
+
+func GetChartPermissionListByClassifyStrIds(classifyIds []string) (items []*ChartPermissionSearchKeyWordMapping, err error) {
+	if len(classifyIds) == 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM chart_permission_search_key_word_mapping	WHERE 1=1 `
+	var idsStr string
+	if len(classifyIds) > 0 {
+		idsStr = strings.Join(classifyIds, ",")
+		sql += fmt.Sprintf(" AND classify_id in (%s) ", idsStr)
+	}
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+func GetChartPermissionListByClassifyIds(classifyIds []int) (items []*ChartPermissionSearchKeyWordMapping, err error) {
+	if len(classifyIds) == 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT * FROM chart_permission_search_key_word_mapping	WHERE 1=1 `
+	if len(classifyIds) > 0 {
+		sql += fmt.Sprintf(" AND classify_id in (%s) ", utils.GetOrmReplaceHolder(len(classifyIds)))
+	}
+	_, err = o.Raw(sql, classifyIds).QueryRows(&items)
+	return
+}
+
+func GetClassifyIdsListByIds(chartPermissionIds []int) (classifyIds []int, err error) {
+	if len(chartPermissionIds) == 0 {
+		return
+	}
+	o := orm.NewOrmUsingDB("rddp")
+	sql := ` SELECT classify_id
+		FROM chart_permission_search_key_word_mapping	
+		WHERE 1=1 `
+	if len(chartPermissionIds) > 0 {
+		sql += fmt.Sprintf(" AND chart_permission_id in (%s) ", utils.GetOrmReplaceHolder(len(chartPermissionIds)))
+	}
+	_, err = o.Raw(sql, chartPermissionIds).QueryRows(&classifyIds)
+	return
+}

+ 1 - 0
models/db.go

@@ -40,5 +40,6 @@ func init() {
 		new(CrmConfig),
 		new(UserChangeRecord),
 		new(ReportPdf),
+		new(ReportPushStatus),
 	)
 }

+ 137 - 0
models/report_push_status.go

@@ -0,0 +1,137 @@
+package models
+
+import (
+	"eta/eta_mini_crm/utils"
+	"time"
+
+	"github.com/beego/beego/v2/client/orm"
+)
+
+type ReportPushStatus struct {
+	ReportPushStatusId int       `orm:"pk"`
+	ReportId           int       `description:"报告id"`
+	State              int       `description:"报告状态:0-未推送,1-已推送"`
+	ReportType         int       `description:"报告类型:1-eta报告"`
+	CreateTime         time.Time `description:"创建时间"`
+	ModifyTime         time.Time `description:"修改时间"`
+	PushTime           time.Time `description:"推送时间"`
+}
+
+type ReportPushView struct {
+	ReportPushStatusId int    `orm:"pk"`
+	ReportId           int    `description:"报告id"`
+	Title              string `description:"报告标题"`
+	Abstract           string `description:"报告摘要"`
+	ClassifyIdFirst    int    `description:"一级分类id"`
+	ClassifyNameFirst  string `description:"一级分类名称"`
+	ClassifyIdSecond   int    `description:"二级分类id"`
+	ClassifyNameSecond string `description:"二级分类名称"`
+	ClassifyIdThird    int    `description:"二级分类id"`
+	ClassifyNameThird  string `description:"二级分类名称"`
+	Author             string `description:"报告作者"`
+	State              int    `description:"报告状态:0-未推送,1-已推送"`
+	PushTime           string `description:"推送时间"`
+	PublishTime        string `description:"报告发布时间"`
+	ReportType         int    `description:"报告类型:1-eta报告"`
+	CreateTime         string `description:"创建时间"`
+	ModifyTime         string `description:"修改时间"`
+}
+
+func (r *ReportPushStatus) Insert() (insertId int64, err error) {
+	o := orm.NewOrm()
+	insertId, err = o.Insert(r)
+	return
+}
+
+func (r *ReportPushStatus) MultiInsert(items []*ReportPushStatus) (err error) {
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(500, items)
+	return
+}
+
+func (r *ReportPushStatus) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(r, cols...)
+	return
+}
+
+func GetReportPushStatusByReportId(reportId, 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)
+	return
+}
+
+func GetReportPushStatusByReportIds(reportId []int, state int) (items []*ReportPushStatus, err error) {
+	if len(reportId) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := `SELECT * FROM report_push_status WHERE report_id IN (` + utils.GetOrmReplaceHolder(len(reportId)) + `) AND state=?`
+	_, err = o.Raw(sql, reportId, state).QueryRows(&items)
+	return
+}
+
+func GetReportPushStatusListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ReportPushView, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT a.id AS report_id, a.title, a.abstract, a.classify_id_first, a.classify_name_first, a.classify_id_second, a.classify_name_second, a.classify_id_third, a.classify_name_third,
+		a.author, b.report_push_status_id, b.create_time, b.state, b.modify_time, b.push_time, b.create_time
+		FROM test_v2_hongze_rddp.report AS a
+		LEFT JOIN report_push_status AS b ON a.id=b.report_id	
+		WHERE 1=1 AND (a.state=2 OR a.state=6) `
+	if condition != "" {
+		sql += condition
+	}
+	sql += `LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+func GetReportIdListByCondition(condition string, pars []interface{}) (reportId []int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT a.id AS report_id
+		FROM test_v2_hongze_rddp.report AS a
+		LEFT JOIN report_push_status AS b ON a.id=b.report_id	
+		WHERE 1=1 AND (a.state=2 OR a.state=6) `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&reportId)
+	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=?`
+	err = o.Raw(sql, id).QueryRow(&count)
+	return
+}
+
+func GetReportCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(*) AS count
+		FROM test_v2_hongze_rddp.report AS a
+		LEFT JOIN report_push_status AS b ON a.id=b.report_id	
+		WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+// BatchPushReport 批量推送报告
+func BatchPushReport(reportId []int) (err error) {
+	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()
+	return
+}
+
+// BatchPushCancelReport 批量撤销推送报告
+func BatchPushCancelReport(reportId []int) (err error) {
+	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()
+	return
+}

+ 17 - 0
models/request/report_push_status.go

@@ -0,0 +1,17 @@
+package request
+
+type ReportPushStatusReq struct {
+	ReportId int
+}
+
+type BatchReportModifyPushStatusReq struct {
+	ChartPermissionIds []int
+	ClassifyIds        []int
+	SelectedIds        []int
+	IsSelectAll        bool
+	PublishStartDate   string
+	PublishEndDate     string
+	PushStartDate      string
+	PushEndDate        string
+	KeyWord            string
+}

+ 12 - 0
models/response/report_push_status.go

@@ -0,0 +1,12 @@
+package response
+
+import (
+	"eta/eta_mini_crm/models"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+type ReportPushStatusResp struct {
+	List   []*models.ReportPushView `description:"列表数据"`
+	Paging *paging.PagingItem       `description:"分页数据"`
+}

+ 45 - 0
routers/commentsRouter.go

@@ -106,6 +106,51 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:ReportPushStatusController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:ReportPushStatusController"],
+        beego.ControllerComments{
+            Method: "BatchPush",
+            Router: `/batch/push`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:ReportPushStatusController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:ReportPushStatusController"],
+        beego.ControllerComments{
+            Method: "BatchPushCancel",
+            Router: `/batch/pushCancel`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:ReportPushStatusController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:ReportPushStatusController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:ReportPushStatusController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:ReportPushStatusController"],
+        beego.ControllerComments{
+            Method: "Push",
+            Router: `/push`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:ReportPushStatusController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:ReportPushStatusController"],
+        beego.ControllerComments{
+            Method: "PushCancel",
+            Router: `/pushCancel`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:SellerController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm/controllers:SellerController"],
         beego.ControllerComments{
             Method: "List",

+ 5 - 0
routers/router.go

@@ -67,6 +67,11 @@ func init() {
 				&controllers.ReportPdfController{},
 			),
 		),
+		beego.NSNamespace("/report_push",
+			beego.NSInclude(
+				&controllers.ReportPushStatusController{},
+			),
+		),
 	)
 	beego.AddNamespace(ns)
 }

+ 0 - 0
test/conf/app_dev.conf


+ 13 - 0
utils/common.go

@@ -96,3 +96,16 @@ func GetOrmReplaceHolder(num int) string {
 	}
 	return stringBuffer.String()
 }
+
+func Unique[T comparable](slice []T) []T {
+	seen := make(map[T]struct{})
+	var unique []T
+
+	for _, v := range slice {
+		if _, exists := seen[v]; !exists {
+			unique = append(unique, v)
+			seen[v] = struct{}{}
+		}
+	}
+	return unique
+}