Przeglądaj źródła

fix:新增获取研究员列表接口

Roc 2 lat temu
rodzic
commit
e41e4e1c5a

+ 26 - 29
controllers/yb/community_question.go

@@ -7,7 +7,6 @@ import (
 	ybRequest "hongze/hongze_mobile_admin/models/request/yb"
 	ybRequest "hongze/hongze_mobile_admin/models/request/yb"
 	"hongze/hongze_mobile_admin/services/yb"
 	"hongze/hongze_mobile_admin/services/yb"
 	"hongze/hongze_mobile_admin/utils"
 	"hongze/hongze_mobile_admin/utils"
-	"strings"
 )
 )
 
 
 type CommunityQuestionController struct {
 type CommunityQuestionController struct {
@@ -17,10 +16,10 @@ type CommunityQuestionController struct {
 // QuestionList
 // QuestionList
 // @Title 获取问答列表
 // @Title 获取问答列表
 // @Description 获取问答列表
 // @Description 获取问答列表
+// @Param   CommunityQuestionId	query	int		false	"问答的id,如果传入了问答的id,那么其他条件就默认过滤掉了"
 // @Param   ReplyStatus	query	int		false	"提问状态 1-待分配 2-待回答 3-已回答"
 // @Param   ReplyStatus	query	int		false	"提问状态 1-待分配 2-待回答 3-已回答"
 // @Param   ReplierIds	query	string	false	"回复人ID,多个用英文逗号分割"
 // @Param   ReplierIds	query	string	false	"回复人ID,多个用英文逗号分割"
-// @Param   SortParam   query   string  false     "排序字段参数,用来排序的字段, 枚举值:'ClickNum':点击量"
-// @Param   SortType   query   string  true       "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
+// @Param   Keyword	query	string	false	"关键字搜索"
 // @Success 200 {object} response.CommunityQuestionListResp
 // @Success 200 {object} response.CommunityQuestionListResp
 // @router /community/question/list [get]
 // @router /community/question/list [get]
 func (c *CommunityQuestionController) QuestionList() {
 func (c *CommunityQuestionController) QuestionList() {
@@ -35,32 +34,30 @@ func (c *CommunityQuestionController) QuestionList() {
 
 
 	condition := ""
 	condition := ""
 	pars := make([]interface{}, 0)
 	pars := make([]interface{}, 0)
-	replyStatus, _ := c.GetInt("ReplyStatus", 0)
-	if replyStatus > 0 {
-		condition += ` AND q.reply_status = ?`
-		pars = append(pars, replyStatus)
-	}
-	replierIds := c.GetString("ReplierIds", "")
-	if replierIds != "" {
-		condition += ` AND q.replier_admin_id IN (` + replierIds + `)`
-	}
-	// 排序相关
-	sortParam := c.GetString("SortParam")
-	sortType := c.GetString("SortType")
-	orderStr := ""
-	if sortType != "" && strings.ToLower(sortType) != "desc" && strings.ToLower(sortType) != "asc" {
-		c.FailWithMessage("请输入正确的排序类型", "请输入正确的排序类型")
-		return
-	}
-	if sortParam == "ClickNum" {
-		orderStr = "  ORDER BY l.click_num"
-		if sortType != "" {
-			orderStr += " " + sortType
-		} else {
-			orderStr += " DESC"
+	//问答id
+	communityQuestionId, _ := c.GetInt("CommunityQuestionId", 0)
+
+	//如果有传入特定的问答id,那么就不用考虑其他状态了
+	if communityQuestionId > 0 {
+		condition += ` AND q.community_question_id = ? `
+		pars = append(pars, communityQuestionId)
+	} else {
+		//提问状态
+		replyStatus, _ := c.GetInt("ReplyStatus", 0)
+		if replyStatus > 0 {
+			condition += ` AND q.reply_status = ? `
+			pars = append(pars, replyStatus)
+		}
+		//回复人ID
+		replierIds := c.GetString("ReplierIds", "")
+		if replierIds != "" {
+			condition += ` AND q.replier_admin_id IN (` + replierIds + `)`
+		}
+		//关键字
+		keyword := c.GetString("Keyword", "")
+		if keyword != "" {
+			condition += ` AND q.question_content like  "%` + keyword + `%"`
 		}
 		}
-
-		orderStr += ", q.create_time DESC"
 	}
 	}
 	var startSize int
 	var startSize int
 	pageSize, _ := c.GetInt("PageSize")
 	pageSize, _ := c.GetInt("PageSize")
@@ -73,7 +70,7 @@ func (c *CommunityQuestionController) QuestionList() {
 	}
 	}
 	startSize = paging.StartIndex(currentIndex, pageSize)
 	startSize = paging.StartIndex(currentIndex, pageSize)
 
 
-	total, resp, err := yb.GetQuestionList(condition, pars, orderStr, startSize, pageSize)
+	total, resp, err := yb.GetQuestionList(condition, pars, startSize, pageSize)
 	if err != nil {
 	if err != nil {
 		c.FailWithMessage("获取问答列表失败", "QuestionList ErrMsg:"+err.Error())
 		c.FailWithMessage("获取问答列表失败", "QuestionList ErrMsg:"+err.Error())
 		return
 		return

+ 26 - 0
models/db_init.go

@@ -30,12 +30,16 @@ import (
 	"hongze/hongze_mobile_admin/models/tables/contract_template"
 	"hongze/hongze_mobile_admin/models/tables/contract_template"
 	"hongze/hongze_mobile_admin/models/tables/h5_admin_session"
 	"hongze/hongze_mobile_admin/models/tables/h5_admin_session"
 	"hongze/hongze_mobile_admin/models/tables/report"
 	"hongze/hongze_mobile_admin/models/tables/report"
+	"hongze/hongze_mobile_admin/models/tables/research_variety_tag_relation"
 	"hongze/hongze_mobile_admin/models/tables/resource"
 	"hongze/hongze_mobile_admin/models/tables/resource"
 	"hongze/hongze_mobile_admin/models/tables/seal"
 	"hongze/hongze_mobile_admin/models/tables/seal"
 	"hongze/hongze_mobile_admin/models/tables/sys_role"
 	"hongze/hongze_mobile_admin/models/tables/sys_role"
 	"hongze/hongze_mobile_admin/models/tables/sys_role_admin"
 	"hongze/hongze_mobile_admin/models/tables/sys_role_admin"
+	"hongze/hongze_mobile_admin/models/tables/variety_classify"
+	"hongze/hongze_mobile_admin/models/tables/variety_tag"
 	"hongze/hongze_mobile_admin/models/tables/wx_token"
 	"hongze/hongze_mobile_admin/models/tables/wx_token"
 	"hongze/hongze_mobile_admin/models/tables/wx_user"
 	"hongze/hongze_mobile_admin/models/tables/wx_user"
+	"hongze/hongze_mobile_admin/models/tables/yb_price_driven_tag"
 	"hongze/hongze_mobile_admin/utils"
 	"hongze/hongze_mobile_admin/utils"
 	"time"
 	"time"
 )
 )
@@ -101,6 +105,12 @@ func init() {
 
 
 	// 社区问答相关
 	// 社区问答相关
 	initCommunity()
 	initCommunity()
+
+	// 品种标签相关
+	initVariety()
+
+	// 价格驱动相关
+	initPriceDriven()
 }
 }
 
 
 // initCommunity 社区问答相关
 // initCommunity 社区问答相关
@@ -110,4 +120,20 @@ func initCommunity() {
 	)
 	)
 }
 }
 
 
+// initVariety 品种标签相关
+func initVariety() {
+	orm.RegisterModel(
+		new(variety_classify.VarietyClassify),                         //品种标签分类
+		new(variety_tag.VarietyTag),                                   //品种标签
+		new(research_variety_tag_relation.ResearchVarietyTagRelation), //品种标签关系
+	)
+}
+
+// initPriceDriven 价格驱动相关
+func initPriceDriven() {
+	orm.RegisterModel(
+		new(yb_price_driven_tag.PriceDrivenTag), //价格驱动标签
+	)
+}
+
 func InitDb() {}
 func InitDb() {}

+ 1 - 1
models/response/yb/community_question.go

@@ -7,7 +7,7 @@ import (
 type CommunityQuestionListResp struct {
 type CommunityQuestionListResp struct {
 	Paging *paging.PagingItem
 	Paging *paging.PagingItem
 	List   []*CommunityQuestionItem `description:"列表数据"`
 	List   []*CommunityQuestionItem `description:"列表数据"`
-	Count  *CommunityQuestionCount
+	//Count  *CommunityQuestionCount
 }
 }
 
 
 type CommunityQuestionItem struct {
 type CommunityQuestionItem struct {

+ 10 - 17
models/tables/community_question/community_question.go

@@ -60,27 +60,20 @@ func GetQuestionById(questionId int) (item *CommunityQuestion, err error) {
 }
 }
 
 
 // GetCommunityQuestionList 获取问答列表
 // GetCommunityQuestionList 获取问答列表
-func GetCommunityQuestionList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*CommunityQuestionMore, err error) {
+func GetCommunityQuestionList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*CommunityQuestionMore, err error) {
 	o := orm.NewOrm()
 	o := orm.NewOrm()
-	sql := `SELECT
-	q.*,
-	l.click_num
-FROM
-	yb_community_question q
-	LEFT JOIN ( SELECT count( * ) AS click_num, community_question_id FROM yb_community_audio_listen_log GROUP BY community_question_id ) AS l ON q.community_question_id = l.community_question_id 
-WHERE
-	q.is_deleted = 0 `
-	sql += condition
-	if order != "" {
-		sql += order
-	} else {
-		sql += ` ORDER BY q.create_time DESC`
-	}
-	totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
+
+	//汇总数据
+	totalSQl := `SELECT COUNT(1) total FROM yb_community_question q WHERE q.is_deleted = 0 `
+	totalSQl += condition
 	if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
 	if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
 		return
 		return
 	}
 	}
-	sql += ` LIMIT ?,?`
+
+	// 列表数据
+	sql := `SELECT q.* FROM yb_community_question q WHERE q.is_deleted = 0 `
+	sql += condition
+	sql += ` ORDER BY q.create_time DESC LIMIT ?,?`
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
 	return
 	return
 }
 }

+ 9 - 0
routers/commentsRouter.go

@@ -619,6 +619,15 @@ func init() {
             Filters: nil,
             Filters: nil,
             Params: nil})
             Params: nil})
 
 
+    beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers:VarietyTagController"] = append(beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers:VarietyTagController"],
+        beego.ControllerComments{
+            Method: "TagTree",
+            Router: `/variety_tag/tag_tree`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers:WeChatCommon"] = append(beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers:WeChatCommon"],
     beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers:WeChatCommon"] = append(beego.GlobalControllerRouter["hongze/hongze_mobile_admin/controllers:WeChatCommon"],
         beego.ControllerComments{
         beego.ControllerComments{
             Method: "WeChatLogin",
             Method: "WeChatLogin",

+ 5 - 0
routers/router.go

@@ -87,6 +87,11 @@ func init() {
 				&yb.CommunityQuestionController{},
 				&yb.CommunityQuestionController{},
 			),
 			),
 		),
 		),
+		web.NSNamespace("/taglib",
+			web.NSInclude(
+				&controllers.VarietyTagController{},
+			),
+		),
 	)
 	)
 	web.AddNamespace(ns)
 	web.AddNamespace(ns)
 }
 }

+ 39 - 33
services/yb/community_question.go

@@ -18,9 +18,9 @@ import (
 )
 )
 
 
 // GetQuestionList 问题列表
 // GetQuestionList 问题列表
-func GetQuestionList(condition string, pars []interface{}, orderStr string, startSize, pageSize int) (total int, resp *ybResponse.CommunityQuestionListResp, err error) {
+func GetQuestionList(condition string, pars []interface{}, startSize, pageSize int) (total int, resp *ybResponse.CommunityQuestionListResp, err error) {
 	resp = new(ybResponse.CommunityQuestionListResp)
 	resp = new(ybResponse.CommunityQuestionListResp)
-	total, list, e := community_question.GetCommunityQuestionList(condition, pars, orderStr, startSize, pageSize)
+	total, list, e := community_question.GetCommunityQuestionList(condition, pars, startSize, pageSize)
 	if e != nil {
 	if e != nil {
 		err = errors.New("获取问题列表失败 Err:" + e.Error())
 		err = errors.New("获取问题列表失败 Err:" + e.Error())
 		return
 		return
@@ -36,16 +36,22 @@ func GetQuestionList(condition string, pars []interface{}, orderStr string, star
 			adminIdArr = append(adminIdArr, strconv.Itoa(list[i].ReplierAdminId))
 			adminIdArr = append(adminIdArr, strconv.Itoa(list[i].ReplierAdminId))
 		}
 		}
 	}
 	}
-	adminIds := strings.Join(adminIdArr, ",")
-	adminList, err := admin.GetAdminListByIds(adminIds)
-	if err != nil {
-		return
-	}
-	adminLen := len(adminList)
+
+	//管理员信息
 	adminEnableMap := make(map[int]int, 0)
 	adminEnableMap := make(map[int]int, 0)
-	if adminLen > 0 {
-		for i := 0; i < adminLen; i++ {
-			adminEnableMap[adminList[i].AdminId] = adminList[i].Enabled
+
+	if len(adminIdArr) > 0 {
+		adminIds := strings.Join(adminIdArr, ",")
+		adminList, tmpErr := admin.GetAdminListByIds(adminIds)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		adminLen := len(adminList)
+		if adminLen > 0 {
+			for i := 0; i < adminLen; i++ {
+				adminEnableMap[adminList[i].AdminId] = adminList[i].Enabled
+			}
 		}
 		}
 	}
 	}
 
 
@@ -86,29 +92,29 @@ func GetQuestionList(condition string, pars []interface{}, orderStr string, star
 		respList = append(respList, item)
 		respList = append(respList, item)
 	}
 	}
 	// 数量统计
 	// 数量统计
-	countList, e := community_question.GetCommunityQuestionCount()
-	if e != nil {
-		err = errors.New("获取问题数量统计失败 Err:" + e.Error())
-		return
-	}
-	respCount := new(ybResponse.CommunityQuestionCount)
-	for _, v := range countList {
-		if v.ReplyStatus == 1 {
-			respCount.Free = v.Total
-			continue
-		}
-		if v.ReplyStatus == 2 {
-			respCount.Wait = v.Total
-			continue
-		}
-		if v.ReplyStatus == 3 {
-			respCount.Replied = v.Total
-			continue
-		}
-	}
-	respCount.Total = respCount.Free + respCount.Wait + respCount.Replied
+	//countList, e := community_question.GetCommunityQuestionCount()
+	//if e != nil {
+	//	err = errors.New("获取问题数量统计失败 Err:" + e.Error())
+	//	return
+	//}
+	//respCount := new(ybResponse.CommunityQuestionCount)
+	//for _, v := range countList {
+	//	if v.ReplyStatus == 1 {
+	//		respCount.Free = v.Total
+	//		continue
+	//	}
+	//	if v.ReplyStatus == 2 {
+	//		respCount.Wait = v.Total
+	//		continue
+	//	}
+	//	if v.ReplyStatus == 3 {
+	//		respCount.Replied = v.Total
+	//		continue
+	//	}
+	//}
+	//respCount.Total = respCount.Free + respCount.Wait + respCount.Replied
 	resp.List = respList
 	resp.List = respList
-	resp.Count = respCount
+	//resp.Count = respCount
 	return
 	return
 }
 }