|
@@ -138,8 +138,29 @@ func (c *TotalController) GetPolicyFile() {
|
|
|
func (c *TotalController) GetFunctionCard() {
|
|
func (c *TotalController) GetFunctionCard() {
|
|
|
//问题类型,0为AI问答,1为安全培训
|
|
//问题类型,0为AI问答,1为安全培训
|
|
|
functionType, _ := c.GetInt("function_type")
|
|
functionType, _ := c.GetInt("function_type")
|
|
|
|
|
+ limit := 4
|
|
|
|
|
+
|
|
|
|
|
+ var count int64
|
|
|
|
|
+ models.DB.Model(&models.FunctionCard{}).Where("function_type = ? AND is_deleted = ?", functionType, 0).Count(&count)
|
|
|
|
|
+
|
|
|
var functionCard []models.FunctionCard
|
|
var functionCard []models.FunctionCard
|
|
|
- models.DB.Model(&models.FunctionCard{}).Order("rand()").Limit(4).Where("function_type = ? AND is_deleted = ?", functionType, 0).Find(&functionCard)
|
|
|
|
|
|
|
+ if count == 0 {
|
|
|
|
|
+ c.Data["json"] = map[string]interface{}{
|
|
|
|
|
+ "statusCode": 200,
|
|
|
|
|
+ "msg": "success",
|
|
|
|
|
+ "data": functionCard,
|
|
|
|
|
+ }
|
|
|
|
|
+ c.ServeJSON()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if int64(limit) >= count {
|
|
|
|
|
+ models.DB.Model(&models.FunctionCard{}).Where("function_type = ? AND is_deleted = ?", functionType, 0).Find(&functionCard)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ offset := rand.Intn(int(count) - limit + 1)
|
|
|
|
|
+ models.DB.Model(&models.FunctionCard{}).Where("function_type = ? AND is_deleted = ?", functionType, 0).Offset(offset).Limit(limit).Find(&functionCard)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
c.Data["json"] = map[string]interface{}{
|
|
c.Data["json"] = map[string]interface{}{
|
|
|
"statusCode": 200,
|
|
"statusCode": 200,
|
|
|
"msg": "success",
|
|
"msg": "success",
|
|
@@ -148,12 +169,33 @@ func (c *TotalController) GetFunctionCard() {
|
|
|
c.ServeJSON()
|
|
c.ServeJSON()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 随机返回三条热点问题
|
|
|
|
|
|
|
+// 随机返回四条热点问题
|
|
|
func (c *TotalController) GetHotQuestion() {
|
|
func (c *TotalController) GetHotQuestion() {
|
|
|
//问题类型,0为AI问答,1为安全培训
|
|
//问题类型,0为AI问答,1为安全培训
|
|
|
questionType, _ := c.GetInt("question_type")
|
|
questionType, _ := c.GetInt("question_type")
|
|
|
|
|
+ limit := 4
|
|
|
|
|
+
|
|
|
|
|
+ var count int64
|
|
|
|
|
+ models.DB.Model(&models.HotQuestion{}).Where("question_type = ? AND is_deleted = ?", questionType, 0).Count(&count)
|
|
|
|
|
+
|
|
|
var hotQuestion []models.HotQuestion
|
|
var hotQuestion []models.HotQuestion
|
|
|
- models.DB.Model(&models.HotQuestion{}).Order("rand()").Limit(4).Where("question_type = ? AND is_deleted = ?", questionType, 0).Find(&hotQuestion)
|
|
|
|
|
|
|
+ if count == 0 {
|
|
|
|
|
+ c.Data["json"] = map[string]interface{}{
|
|
|
|
|
+ "statusCode": 200,
|
|
|
|
|
+ "msg": "success",
|
|
|
|
|
+ "data": hotQuestion,
|
|
|
|
|
+ }
|
|
|
|
|
+ c.ServeJSON()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if int64(limit) >= count {
|
|
|
|
|
+ models.DB.Model(&models.HotQuestion{}).Where("question_type = ? AND is_deleted = ?", questionType, 0).Find(&hotQuestion)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ offset := rand.Intn(int(count) - limit + 1)
|
|
|
|
|
+ models.DB.Model(&models.HotQuestion{}).Where("question_type = ? AND is_deleted = ?", questionType, 0).Offset(offset).Limit(limit).Find(&hotQuestion)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
c.Data["json"] = map[string]interface{}{
|
|
c.Data["json"] = map[string]interface{}{
|
|
|
"statusCode": 200,
|
|
"statusCode": 200,
|
|
|
"msg": "success",
|
|
"msg": "success",
|