فهرست منبع

未设置产品

kobe6258 4 ماه پیش
والد
کامیت
27a59e6df3
10فایلهای تغییر یافته به همراه446 افزوده شده و 9 حذف شده
  1. 182 0
      controllers/product.go
  2. 8 8
      models/chart_permission.go
  3. 14 0
      models/media.go
  4. 17 0
      models/merchant_product.go
  5. 27 1
      models/permission.go
  6. 15 0
      models/report.go
  7. 11 0
      models/response/product.go
  8. 9 0
      routers/commentsRouter.go
  9. 5 0
      routers/router.go
  10. 158 0
      services/product.go

+ 182 - 0
controllers/product.go

@@ -0,0 +1,182 @@
+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
+//}

+ 8 - 8
models/chart_permission.go

@@ -122,13 +122,13 @@ func GetChartPermissionList() (items []*ChartPermission, err error) {
 	return
 }
 
-//func GetPermissionNames(ids []int) (items []string, err error) {
-//	o := orm.NewOrmUsingDB("rddp")
-//	condition := " AND chart_permission_id in (" + utils.GetOrmReplaceHolder(len(ids)) + ")"
-//	sql := `SELECT distinct  permission_name FROM chart_permission WHERE enabled=1 AND product_id=1` + condition
-//	_, err = o.Raw(sql, ids).QueryRows(&items)
-//	return
-//}
+//	func GetPermissionNames(ids []int) (items []string, err error) {
+//		o := orm.NewOrmUsingDB("rddp")
+//		condition := " AND chart_permission_id in (" + utils.GetOrmReplaceHolder(len(ids)) + ")"
+//		sql := `SELECT distinct  permission_name FROM chart_permission WHERE enabled=1 AND product_id=1` + condition
+//		_, err = o.Raw(sql, ids).QueryRows(&items)
+//		return
+//	}
 func GetPermissionNameById(id int) (items string, err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	sql := `SELECT distinct  permission_name FROM chart_permission WHERE enabled=1 AND product_id=1 and chart_permission_id=?`
@@ -143,7 +143,7 @@ func GetChartPermissionByParentId(parentId int) (items []*ChartPermissionList, e
 }
 func GetClassifyIdsByPermissionIds(condition string, pars []interface{}) (classifyIds []int, err error) {
 	o := orm.NewOrmUsingDB("rddp")
-	sql := "select distinct classify_id from chart_permission_search_key_word_mapping where 1=1 "
+	sql := "select distinct classify_id from permission_classify_mapping where 1=1 "
 	if condition != "" {
 		sql += condition
 	}

+ 14 - 0
models/media.go

@@ -195,6 +195,13 @@ func GetMediaById(media MediaType, id int) (item *Media, err error) {
 	err = o.Raw(sql, media, id).QueryRow(&item)
 	return
 }
+func GetMediasById(ids []int, sortCondition string, startPage, pageSize int) (medias []Media, err error) {
+	o := orm.NewOrm()
+	condition := " and id in (" + utils.GetOrmReplaceHolder(len(ids)) + ") AND deleted=0" + sortCondition + " limit ?,?"
+	sql := `SELECT * FROM media WHERE 1=1 ` + condition
+	_, err = o.Raw(sql, ids, startPage, pageSize).QueryRows(&medias)
+	return
+}
 func GetMediaByCondition(media MediaType, condition string, sortCondition string, pars []interface{}, startPage, pageSize int) (items []*Media, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM media WHERE 1 = 1 AND media_type = ? AND deleted=0`
@@ -327,3 +334,10 @@ func FilterMediaIdIdsBySourceId(mediaType MediaType, ids []int) (mediaIds []int,
 	_, err = o.Raw(sql, ids, mediaType).QueryRows(&mediaIds)
 	return
 }
+
+func GetMediaIdsByCondition(condition string, pars []interface{}) (mediaIds []int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT distinct id FROM media WHERE ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&mediaIds)
+	return
+}

+ 17 - 0
models/merchant_product.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"errors"
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/shopspring/decimal"
 	"time"
@@ -54,3 +55,19 @@ func (m *MerchantProduct) InsertPackage() (err error) {
 	_, err = o.Insert(m)
 	return
 }
+
+func GetProductSourceIdsByProductType(productType string) (ids []int, err error) {
+	var condition string
+	switch productType {
+	case "report":
+		condition = "and type ='report'"
+	case "media":
+		condition = "and type in ('audio','video')"
+	default:
+		err = errors.New("不支持的产品类型查询")
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.Raw("select source_id from merchant_products where deleted = 0 " + condition).QueryRows(&ids)
+	return
+}

+ 27 - 1
models/permission.go

@@ -62,7 +62,21 @@ func GetPermissionNames(ids []int) (permissionNameList []string, err error) {
 	}
 	return
 }
-
+func GetPermissionNamesWithRiskLevel(ids []int) (permissionNameList []string, err error) {
+	o := orm.NewOrm()
+	var sql string
+	if len(ids) == 0 {
+		sql = `SELECT  distinct name FROM permissions  where  risk_level !=''  order by permission_id asc`
+	} else {
+		condition := " permission_id in (" + utils.GetOrmReplaceHolder(len(ids)) + ")"
+		sql = `SELECT  distinct name FROM permissions  where  risk_level !='' and ` + condition + `  order by permission_id asc`
+	}
+	_, err = o.Raw(sql, ids).QueryRows(&permissionNameList)
+	if err != nil {
+		return
+	}
+	return
+}
 func GetClassifyIdByPermissionIds(permissionIds []int) (classifyIds []int, err error) {
 	o := orm.NewOrm()
 	if len(permissionIds) == 0 {
@@ -72,3 +86,15 @@ func GetClassifyIdByPermissionIds(permissionIds []int) (classifyIds []int, err e
 	_, err = o.Raw(sql, permissionIds).QueryRows(&classifyIds)
 	return
 }
+
+func FilterPermissionIdsWithRiskLevel(ids []int) (permissionIds []int, err error) {
+	o := orm.NewOrm()
+	var sql string
+	if len(ids) == 0 {
+		sql = `SELECT distinct permission_id FROM permissions  where risk_level!='' order by permission_id asc`
+	} else {
+		sql = `SELECT distinct permission_id FROM permissions  where risk_level!='' and permission_id in (?) order by permission_id asc`
+	}
+	_, err = o.Raw(sql, permissionIds).QueryRows(&permissionIds)
+	return
+}

+ 15 - 0
models/report.go

@@ -149,3 +149,18 @@ func GetReportIdByPlateName(names []string) (reportIds []int, err error) {
 	_, err = o.Raw(sql, names).QueryRows(&reportIds)
 	return
 }
+
+func GetReportByIds(sortCondition string, ids []int, startSize int, pageSize int) (reports []Report, err error) {
+	o := orm.NewOrm()
+	condition := "id in (" + utils.GetOrmReplaceHolder(len(ids)) + ") " + sortCondition + " limit ?,?"
+	sql := `SELECT * FROM reports WHERE  ` + condition
+	_, err = o.Raw(sql, ids, startSize, pageSize).QueryRows(&reports)
+	return
+}
+
+func GetReportIdsByCondition(condition string, pars []interface{}) (ids []int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT id FROM reports WHERE 1=1  ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&ids)
+	return
+}

+ 11 - 0
models/response/product.go

@@ -0,0 +1,11 @@
+package response
+
+import (
+	"eta/eta_mini_crm_ht/services"
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+type ProductListResp struct {
+	List   []*services.ProductView
+	Paging *paging.PagingItem `description:"分页数据"`
+}

+ 9 - 0
routers/commentsRouter.go

@@ -351,6 +351,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:ProductController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:ProductController"],
+        beego.ControllerComments{
+            Method: "UnSetProductList",
+            Router: `/unSetProductList`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:RiskConfigController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:RiskConfigController"],
         beego.ControllerComments{
             Method: "GetCustomerRiskList",

+ 5 - 0
routers/router.go

@@ -87,6 +87,11 @@ func init() {
 				&controllers.MerchantController{},
 			),
 		),
+		beego.NSNamespace("/product",
+			beego.NSInclude(
+				&controllers.ProductController{},
+			),
+		),
 	)
 	beego.AddNamespace(ns)
 }

+ 158 - 0
services/product.go

@@ -0,0 +1,158 @@
+package services
+
+import (
+	"errors"
+	"eta/eta_mini_crm_ht/models"
+	"eta/eta_mini_crm_ht/utils"
+	"time"
+)
+
+func GetUnsetProductCountByCondition(productType string, permissionIds []int, condition string, pars []interface{}) (total int, ids []int, err error) {
+	setIds, err := models.GetProductSourceIdsByProductType(productType)
+	if err != nil {
+		return
+	}
+	switch productType {
+	case "report":
+		return getReportIdsByCondition(setIds, permissionIds, condition, pars)
+	case "media":
+		return getMediaIdsByCondition(setIds, permissionIds, condition, pars)
+	default:
+		err = errors.New("不支持的产品类型查询")
+		return
+	}
+}
+
+func getReportIdsByCondition(setIds []int, permissionIds []int, condition string, pars []interface{}) (total int, filterIds []int, err error) {
+	permissionNames, err := models.GetPermissionNamesWithRiskLevel(permissionIds)
+	var conditionHT string
+	var conditionETA string
+	if err != nil {
+		utils.FileLog.Error("查询品种名称失败", err.Error)
+		return
+	}
+	if len(permissionNames) > 0 {
+		conditionHT = "(source ='HT' and plate_name in (" + utils.GetOrmReplaceHolder(len(permissionNames)) + "))"
+	}
+	filterPermissionIds, err := models.FilterPermissionIdsWithRiskLevel(permissionIds)
+	if err != nil {
+		utils.FileLog.Error("过滤品种Id失败", err.Error)
+		return
+	}
+	classifyCondition := utils.GetOrmReplaceHolder(len(filterPermissionIds))
+	var classifyPars []interface{}
+	classifyPars = append(classifyPars, filterPermissionIds)
+	classifyIds, err := models.GetClassifyIdsByPermissionIds(classifyCondition, classifyPars)
+	if len(classifyIds) > 0 {
+		conditionETA = "(source ='ETA' and classify_id in (" + utils.GetOrmReplaceHolder(len(classifyIds)) + "))"
+	}
+	if conditionHT != "" {
+		if conditionETA != "" {
+			condition += "and ( " + conditionHT + " or " + conditionETA + ")"
+			pars = append(pars, permissionNames)
+			pars = append(pars, classifyIds)
+		} else {
+			condition += "and " + conditionHT
+			pars = append(pars, permissionNames)
+		}
+	} else {
+		if conditionETA != "" {
+			condition += "and " + conditionETA
+			pars = append(pars, classifyIds)
+		}
+	}
+	var ids []int
+	ids, err = models.GetReportIdsByCondition(condition, pars)
+	if err != nil {
+		utils.FileLog.Error("查询报告Id失败", err.Error)
+		return
+	}
+	filterMap := make(map[int]bool)
+	for _, filterId := range setIds {
+		filterMap[filterId] = true
+	}
+	for _, id := range ids {
+		if !filterMap[id] {
+			filterIds = append(filterIds, id)
+			total++
+		}
+	}
+	return
+}
+
+func getMediaIdsByCondition(setIds []int, permissionIds []int, condition string, pars []interface{}) (total int, filterIds []int, err error) {
+	filterPermissionIds, err := models.FilterPermissionIdsWithRiskLevel(permissionIds)
+	if err != nil {
+		utils.FileLog.Error("过滤品种id失败", err.Error)
+		return
+	}
+	mediaIds, err := models.GetMediaIdIdsByPermissionId(filterPermissionIds)
+	if err != nil {
+		utils.FileLog.Error("过滤媒体Id失败", err.Error)
+		return
+	}
+	if condition != "" {
+		condition += "and id in (" + utils.GetOrmReplaceHolder(len(mediaIds)) + ")"
+		pars = append(pars, mediaIds)
+		mediaIds, err = models.GetMediaIdsByCondition(condition, pars)
+	}
+	filterMap := make(map[int]bool)
+	for _, filterId := range setIds {
+		filterMap[filterId] = true
+	}
+	for _, id := range mediaIds {
+		if !filterMap[id] {
+			total++
+			filterIds = append(filterIds, id)
+		}
+	}
+	return
+}
+
+func GetUnsetProductByCondition(productType string, ids []int, sortCondition string, startSize int, pageSize int) (products []*ProductView, err error) {
+	switch productType {
+	case "report":
+		var reports []models.Report
+		reports, err = models.GetReportByIds(sortCondition, ids, startSize, pageSize)
+		if err != nil {
+			utils.FileLog.Error("查询报告产品失败", err.Error)
+			return
+		}
+		for _, report := range reports {
+			products = append(products, &ProductView{
+				ProductName:   report.Title,
+				SourceId:      report.Id,
+				ProductType:   "report",
+				PublishedTime: report.PublishedTime,
+			})
+		}
+		return
+	case "media":
+		var medias []models.Media
+		medias, err = models.GetMediasById(ids, sortCondition, startSize, pageSize)
+		if err != nil {
+			utils.FileLog.Error("查询报告产品失败", err.Error)
+			return
+		}
+		for _, media := range medias {
+			products = append(products, &ProductView{
+				ProductName:   media.MediaName,
+				SourceId:      media.Id,
+				ProductType:   media.SourceType,
+				PublishedTime: media.PublishedTime.Format(time.DateTime),
+			})
+		}
+		return
+	default:
+		err = errors.New("不支持的产品类型查询")
+		return
+	}
+}
+
+type ProductView struct {
+	ProductName   string
+	SourceId      int
+	ProductType   string
+	RiskLevel     string
+	PublishedTime string
+}