123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587 |
- 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 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 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 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 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 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 = "publish_time"
- case "PushTime":
- param = "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 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)
- }
- tmpClassifyIds, err := models.GetClassifyIdsListByIds(idInts)
- if err != nil {
- br.Msg = "获取研报列表失败"
- br.ErrMsg = "品种获取分类失败,Err:" + err.Error()
- return
- }
- if len(tmpClassifyIds) == 0 {
- resp := new(response.ReportPushStatusResp)
- resp.Paging = paging.GetPaging(currentIndex, pageSize, 0)
- br.Data = resp
- br.Msg = "查询成功"
- br.Success = true
- br.Ret = 200
- return
- }
- classifyIdList = append(classifyIdList, tmpClassifyIds...)
- }
- if len(classifyIdList) > 0 {
- classifyStrIds := make([]string, 0)
- for _, v := range classifyIdList {
- classifyStrIds = append(classifyStrIds, strconv.Itoa(v))
- }
- classifyList, err := models.GetClassifyListByIds(classifyStrIds)
- if err != nil {
- br.Msg = "获取研报列表失败"
- br.ErrMsg = "获取研报分类失败,Err:" + err.Error()
- return
- }
- childClasifyIdList := make([]int, 0)
- for _, v := range classifyList {
- if v.HasChild == 0 {
- childClasifyIdList = append(childClasifyIdList, v.Id)
- }
- }
- condition += ` AND (classify_id_first IN (%s) OR classify_id_second IN (%s) OR classify_id_third IN (%s))`
- condition = fmt.Sprintf(condition, utils.GetOrmReplaceHolder(len(childClasifyIdList)), utils.GetOrmReplaceHolder(len(childClasifyIdList)), utils.GetOrmReplaceHolder(len(childClasifyIdList)))
- pars = append(pars, childClasifyIdList, childClasifyIdList, childClasifyIdList)
- }
- if isSelectAll {
- if selectedIds != "" {
- selectIdStrs := strings.Split(selectedIds, ",")
- if len(selectIdStrs) > 0 {
- condition += ` AND report_id NOT IN (` + utils.GetOrmReplaceHolder(len(selectIdStrs)) + `)`
- pars = append(pars, selectIdStrs)
- }
- }
- } else {
- if selectedIds != "" {
- selectIdStrs := strings.Split(selectedIds, ",")
- if len(selectIdStrs) > 0 {
- condition += ` AND report_id IN (` + utils.GetOrmReplaceHolder(len(selectIdStrs)) + `)`
- pars = append(pars, selectIdStrs)
- }
- }
- }
- 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, sortCondition, 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.ReportPushStatusId, 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
- }
- }
- 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
- }
- reportPush, err := models.GetReportPushStatusByReportId(req.ReportPushStatusId, 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
- }
- }
- 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{}
- condition = ` AND state = 0 `
- if req.PublishStartDate != "" && req.PublishEndDate != "" {
- condition += " AND 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 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 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 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 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 (classify_id_first IN (%s) AND classify_id_second IN (%s) AND 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 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_push_status_id IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
- pars = append(pars, req.SelectedIds)
- }
- }
- reportPushStatusIds, err := models.GetReportPushStatusIdListByCondition(condition, pars)
- if err != nil {
- br.Msg = "批量推送失败"
- br.ErrMsg = "查询研报失败,Err:" + err.Error()
- return
- }
- // 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(reportPushStatusIds)
- 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{}
- condition = ` AND state = 1 `
- if req.PublishStartDate != "" && req.PublishEndDate != "" {
- condition += " AND 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 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 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 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 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 (classify_id_first IN (%s) AND classify_id_second IN (%s) AND 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 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_push_status_id IN (` + utils.GetOrmReplaceHolder(len(req.SelectedIds)) + `)`
- pars = append(pars, req.SelectedIds)
- }
- }
- reportPushStatusIds, err := models.GetReportPushStatusIdListByCondition(condition, pars)
- if err != nil {
- br.Msg = "批量推送失败"
- br.ErrMsg = "查询研报失败,Err:" + err.Error()
- return
- }
- // 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(reportPushStatusIds)
- if err != nil {
- br.Msg = "批量取消推送失败"
- br.ErrMsg = "批量修改推送失败,Err:" + err.Error()
- return
- }
- br.Msg = "撤销推送成功"
- br.Success = true
- br.Ret = 200
- }
|