123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- package controllers
- import (
- "eta/eta_mini_crm_ht/models"
- "eta/eta_mini_crm_ht/models/response"
- "eta/eta_mini_crm_ht/services"
- "eta/eta_mini_crm_ht/utils"
- "github.com/rdlucklib/rdluck_tools/paging"
- "strconv"
- "strings"
- )
- type ProductController struct {
- BaseAuthController
- }
- // UnSetProductList
- // @Title 未设置的产品列表
- // @Description 未设置的产品列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyIds query string true "二级分类id,可多选用英文,隔开"
- // @Param KeyWord query string true "报告标题/创建人"
- // @Param SortType query string true "排序方式"
- // @Success 200 {object} models.ReportAuthorResp
- // @router /unSetProductList [get]
- func (this *ProductController) UnSetProductList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- sortType := this.GetString("SortType")
- ProductType := this.GetString("ProductType")
- permissionIds := this.GetString("PermissionIds")
- KeyWord := this.GetString("KeyWord")
- var condition string
- var pars []interface{}
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- if ProductType == "" {
- br.Msg = "产品类型不能为空"
- br.ErrMsg = "获取未设置产品列表失败,Err:产品类型为空"
- return
- }
- if KeyWord != "" {
- switch ProductType {
- case "report":
- condition += " AND title like '%?%'"
- case "media":
- condition += " AND media_name like '%?%'"
- }
- pars = append(pars, KeyWord)
- }
- sortCondition := " ORDER BY published_time "
- if sortType == "" {
- sortType = "DESC"
- }
- sortCondition = sortCondition + sortType
- var permissionIdsList []int
- if permissionIds != "" {
- permissionStr := strings.Split(permissionIds, ",")
- for _, permissionItem := range permissionStr {
- permissionId, _ := strconv.Atoi(permissionItem)
- permissionIdsList = append(permissionIdsList, permissionId)
- }
- }
- total, ids, err := services.GetUnsetProductCountByCondition(ProductType, permissionIdsList, condition, pars)
- if err != nil {
- br.Msg = "获取未设置产品列表失败"
- br.ErrMsg = "获取未设置产品列表失败,Err:" + err.Error()
- return
- }
- var list []*services.ProductView
- if len(ids) > 0 {
- startSize := utils.StartIndex(currentIndex, pageSize)
- list, err = services.GetUnsetProductByCondition(ProductType, ids, sortCondition, startSize, pageSize)
- if err != nil {
- br.Msg = "获取未设置产品列表失败"
- br.ErrMsg = "获取未设置产品列表失败,Err:" + err.Error()
- return
- }
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(response.ProductListResp)
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Data = resp
- br.Msg = "获取成功"
- }
- //
- //// UploadFile @Title 上传图片
- //// @Description 上传视频
- //// @Param File query file true "文件"
- //// @Success 200 {object} models.ReportAuthorResp
- //// @router /uploadFile [post]
- //func (this *VideoController) UploadFile() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // this.Data["json"] = br
- // this.ServeJSON()
- // }()
- // f, h, err := this.GetFile("File")
- // if err != nil {
- // br.Msg = "获取资源信息失败"
- // br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
- // return
- // }
- // defer f.Close()
- // size, err := strconv.Atoi(utils.UPLOAD_IMG_SIZE)
- // if err != nil {
- // size = 100
- // }
- // if h.Size > 1024*1024*int64(size) {
- // br.Msg = fmt.Sprintf("图片大小不能超过%dK", size)
- // br.ErrMsg = "图片上传失败,Err:" + err.Error()
- // return
- // }
- // ext := path.Ext(h.Filename)
- // //if ext != ".mp3" {
- // // br.Msg = "音频格式不正确"
- // // br.ErrMsg = "音频上传失败,Err:" + err.Error()
- // // return
- // //}
- // dateDir := time.Now().Format("20060102")
- // uploadDir := utils.STATIC_DIR + "ht/audio" + dateDir
- // err = os.MkdirAll(uploadDir, utils.DIR_MOD)
- // if err != nil {
- // br.Msg = "存储目录创建失败"
- // br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
- // return
- // }
- // randStr := utils.GetRandStringNoSpecialChar(28)
- // fileName := randStr + ext
- // fpath := uploadDir + "/" + fileName
- // err = this.SaveToFile("File", fpath)
- // if err != nil {
- // br.Msg = "图片上传失败"
- // br.ErrMsg = "图片上传失败,Err:" + err.Error()
- // return
- // }
- // audioUploadDir := utils.RESOURCE_DIR + "img/"
- // savePdfToOssPath := audioUploadDir + time.Now().Format("200601/20060102/")
- // audioName := utils.GetRandStringNoSpecialChar(28)
- // savePdfToOssPath += audioName + ext
- //
- // defer func() {
- // err = os.Remove(fpath)
- // fmt.Sprintf("删除文件失败:%v", err)
- // }()
- // ossClient := services.NewOssClient()
- // if ossClient == nil {
- // br.Msg = "图片上传失败"
- // br.ErrMsg = "初始化OSS服务失败"
- // return
- // }
- // mp3Url, err := ossClient.UploadFile("", fpath, savePdfToOssPath)
- // if err != nil {
- // br.Msg = "图片上传失败"
- // br.ErrMsg = "图片上传失败,Err:" + err.Error()
- // return
- // }
- // base := path.Base(h.Filename)
- // resp := new(response.MediaUploadResp)
- // resp.Url = mp3Url
- // resp.FileName = base
- // br.Data = resp
- // br.Msg = "上传成功"
- // br.Ret = 200
- // br.Success = true
- //}
|