Rick.Lan vor 1 Monat
Ursprung
Commit
b54c88065a

+ 5 - 0
conf/app.conf Datei anzeigen

@@ -49,6 +49,11 @@ readxtuser = root
49 49
 readxtpass = 1Q2W3e4r!@#$
50 50
 readxtname = sgj_xt
51 51
 
52
+artdbhost = rm-wz9rg531npf61q03tro.mysql.rds.aliyuncs.com
53
+artdbport = 3306
54
+artdbuser = root
55
+artdbpass = 1Q2W3e4r!@#$
56
+artdbname = shengws_test
52 57
 
53 58
 #appid = "wx25576346fbca6905"
54 59
 #appsecret="f6d53ccb4a529dc4d3bd543a7634b6bd"

+ 5 - 0
controllers/api_base_controller.go Datei anzeigen

@@ -53,6 +53,11 @@ func ApiControllersRegisterRouters() {
53 53
 	beego.Router("/xcx/api/checkrecord/qrcodecheckrecord", &CheckRecordApiController{}, "Get:QrCodeCheckRecord")
54 54
 	beego.Router("/xcx/api/checkrecord/getcheckrecorditemreport", &CheckRecordApiController{}, "Get:GetCheckRecordItemReport")
55 55
 
56
+	beego.Router("/xcx/api/article/getarticlelist", &ArticleApiController{}, "Get:GetArticleList")
57
+	beego.Router("/xcx/api/article/getarticlebyid", &ArticleApiController{}, "Get:GetArticleByID")
58
+	beego.Router("/xcx/api/article/getarticlemenu", &ArticleApiController{}, "Get:GetArticleMenu")
59
+	beego.Router("/xcx/api/article/getramdonarticlelist", &ArticleApiController{}, "Get:GetRamdonArticleList")
60
+
56 61
 }
57 62
 
58 63
 type BaseApiController struct {

+ 88 - 0
controllers/article_api_controller.go Datei anzeigen

@@ -0,0 +1,88 @@
1
+package controllers
2
+
3
+import (
4
+	"sws_xcx/enums"
5
+	"sws_xcx/service"
6
+)
7
+
8
+type ArticleApiController struct {
9
+	BaseApiController
10
+}
11
+
12
+// @Title GetArticleList
13
+// @Description 获取文章列表
14
+// @Param   pageNum query int true "当前页(从1开始)"
15
+// @Param   pageSize query int true "分页大小"
16
+// @Param   menuid query int false "分类ID"
17
+// @Param   keyword query string false "搜索关键字"
18
+// @Success 200 {array} models.SyhArticlesVO success
19
+// @Failure 500 error
20
+// @router /getarticlelist [get]
21
+func (c *ArticleApiController) GetArticleList() {
22
+	pageNum, _ := c.GetInt("pageNum", 1)
23
+	pageSize, _ := c.GetInt("pageSize", 30)
24
+	menuid, _ := c.GetInt("menuid", 0)
25
+	keyword := c.GetString("keyword")
26
+	arts, toltal, err := service.NewArticleService().GetArticleList(pageNum, pageSize, menuid, keyword)
27
+	if err != nil {
28
+		c.ServeDynamicFailJsonSend(err.Error())
29
+		return
30
+
31
+	}
32
+	c.ServeSuccessPageJSON(arts, toltal)
33
+}
34
+
35
+// @Title GetArticleByID
36
+// @Description 获取文章详情
37
+// @Param   id query int true "文章id"
38
+// @Success 200 {object} models.SyhArticlesVO success
39
+// @Failure 500 error
40
+// @router /getarticlebyid [get]
41
+func (c *ArticleApiController) GetArticleByID() {
42
+	id, err := c.GetInt64("id")
43
+	if err != nil || id == 0 {
44
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
45
+
46
+	}
47
+	art, err := service.NewArticleService().GetArticleByID(id)
48
+	if err != nil {
49
+		c.ServeDynamicFailJsonSend(err.Error())
50
+		return
51
+
52
+	}
53
+	c.ServeSuccessJSON(art)
54
+}
55
+
56
+// @Title GetArticleMenu
57
+// @Description 获取文章分类
58
+// @Param   type query int true "类型:0全部1主2辅"
59
+// @Success 200 {array} models.SyhArticlesMenu success
60
+// @Failure 500 error
61
+// @router /getarticlemenu [get]
62
+func (c *ArticleApiController) GetArticleMenu() {
63
+	t, _ := c.GetInt("type", 0)
64
+	menus, err := service.NewArticleService().GetArticleMenu(t)
65
+	if err != nil {
66
+		c.ServeDynamicFailJsonSend(err.Error())
67
+		return
68
+	}
69
+	c.ServeSuccessJSON(menus)
70
+
71
+}
72
+
73
+// @Title GetRamdonArticleList
74
+// @Description 获取随机文章列表
75
+// @Param   limit query int true "文章数量"
76
+// @Success 200 {array} models.SyhArticlesVO success
77
+// @Failure 500 error
78
+// @router /getramdonarticlelist [get]
79
+func (c *ArticleApiController) GetRamdonArticleList() {
80
+	limit, _ := c.GetInt("limit", 20)
81
+	arts, err := service.NewArticleService().GetRamdonArticleList(limit)
82
+	if err != nil {
83
+		c.ServeDynamicFailJsonSend(err.Error())
84
+		return
85
+
86
+	}
87
+	c.ServeSuccessJSON(arts)
88
+}

+ 66 - 0
models/dbmodels.go Datei anzeigen

@@ -288,3 +288,69 @@ func (XcxPatients) TableName() string {
288 288
 
289 289
 	return "xt_patients"
290 290
 }
291
+
292
+// SyhArticles 表示文章表的模型
293
+type SyhArticles struct {
294
+	ID          uint   `json:"id" gorm:"column:id; type:int(10) unsigned; primary_key; auto_increment; comment:'自增主键ID'" description:"自增主键ID"`
295
+	Title       string `json:"title" gorm:"column:title; type:varchar(255); not null; comment:'标题'" description:"标题"`
296
+	Summary     string `json:"summary" gorm:"column:summary; type:varchar(255); not null; default:''; comment:'简介'" description:"简介"`
297
+	Content     string `json:"content" gorm:"column:content; type:longtext; not null; comment:'内容'" description:"内容"`
298
+	ArticleType uint8  `json:"article_type" gorm:"column:article_type; type:tinyint(1) unsigned; not null; default:'1'; comment:'1普通2视频'" description:"文章类型"`
299
+	Num         uint   `json:"num" gorm:"column:num; type:int(10) unsigned; default:'0'; comment:'点击次数'" description:"点击次数"`
300
+	Ctime       int    `json:"ctime" gorm:"column:ctime; type:int(10); not null; default:'0'; comment:'创建时间'" description:"创建时间"`
301
+	NewTime     int    `json:"new_time" gorm:"column:new_time; type:int(10); not null; default:'0'; comment:'作为新建时间,ctime作为发布修改时间'" description:"新建时间"`
302
+	Img         string `json:"img" gorm:"column:img; type:varchar(255); comment:'图片'" description:"图片"`
303
+	MenuID      uint   `json:"menu_id" gorm:"column:menu_id; type:int(10) unsigned; not null; default:'1'; comment:'辅分类'" description:"辅分类"`
304
+	ClassID     uint   `json:"class_id" gorm:"column:class_id; type:int(10) unsigned; not null; default:'1'; comment:'主分类'" description:"主分类"`
305
+	Author      string `json:"author" gorm:"column:author; type:varchar(20); not null; default:''; comment:'作者'" description:"作者"`
306
+	Tags        string `json:"tags" gorm:"column:tags; type:varchar(50); comment:'标签'" description:"标签"`
307
+	IsDel       uint8  `json:"is_del" gorm:"column:is_del; type:tinyint(1) unsigned; not null; default:'0'; comment:'是否删除'" description:"是否删除"`
308
+	Status      uint8  `json:"status" gorm:"column:status; type:tinyint(1) unsigned; not null; default:'0'; comment:'状态'" description:"状态"`
309
+	Reason      string `json:"reason" gorm:"column:reason; type:varchar(100); comment:'原因'" description:"原因"`
310
+	FromID      uint   `json:"from_id" gorm:"column:from_id; type:int(10) unsigned; not null; default:'0'; comment:'医生/机构ID'" description:"医生/机构ID"`
311
+	Type        uint8  `json:"type" gorm:"column:type; type:tinyint(1) unsigned; not null; default:'0'; comment:'类型'" description:"类型"`
312
+	StarNum     uint   `json:"star_num" gorm:"column:star_num; type:int(10) unsigned; not null; default:'0'; comment:'点赞数'" description:"点赞数"`
313
+	CommentNum  uint   `json:"comment_num" gorm:"column:comment_num; type:int(10) unsigned; not null; default:'0'; comment:'评论数'" description:"评论数"`
314
+	TID         uint   `json:"t_id" gorm:"column:t_id; type:int(10) unsigned; comment:'原表ID,移动数据用'" description:"原表ID"`
315
+	TModule     string `json:"t_module" gorm:"column:t_module; type:varchar(50); comment:'模块'" description:"模块"`
316
+	OrgID       uint   `json:"org_id" gorm:"column:org_id; type:int(10); comment:'orgId'" description:"orgId"`
317
+}
318
+
319
+// TableName 设置表名
320
+func (SyhArticles) TableName() string {
321
+	return "syh_articles"
322
+}
323
+
324
+type SyhArticlesMenu struct {
325
+	ID      uint   `json:"id" gorm:"column:id; type:int(10) unsigned; primary_key; auto_increment; comment:'自增主键ID'" description:"自增主键ID"`
326
+	Name    string `json:"name" gorm:"column:name; type:varchar(255); not null; default:''; comment:'分类名'" description:"分类名"`
327
+	Order   uint16 `json:"order" gorm:"column:order; type:smallint(4) unsigned; not null; default:'0'; comment:'排序'" description:"排序"`
328
+	Status  uint8  `json:"status" gorm:"column:status; type:tinyint(1) unsigned; not null; default:'1'; comment:'状态'" description:"状态"`
329
+	Img     string `json:"img" gorm:"column:img; type:varchar(255); comment:'图片'" description:"图片"`
330
+	Summary string `json:"summary" gorm:"column:summary; type:varchar(255); default:''; comment:'介绍'" description:"介绍"`
331
+	Type    uint8  `json:"type" gorm:"column:type; type:tinyint(1) unsigned; not null; comment:'分类1主2辅'" description:"分类类型"`
332
+}
333
+
334
+// TableName 设置表名
335
+func (SyhArticlesMenu) TableName() string {
336
+	return "syh_articles_menu"
337
+}
338
+
339
+// SyhArticlesComment 表示文章评论表的模型
340
+type SyhArticlesComment struct {
341
+	ID         uint      `json:"id" gorm:"column:id; type:int(10) unsigned; primary_key; auto_increment; comment:'自增主键ID'" description:"自增主键ID"`
342
+	ArticleID  uint      `json:"article_id" gorm:"column:article_id; type:int(10) unsigned; not null; comment:'动态ID'" description:"动态ID"`
343
+	UserID     uint      `json:"user_id" gorm:"column:user_id; type:int(10) unsigned; not null; comment:'评论者用户ID'" description:"评论者用户ID"`
344
+	PID        uint      `json:"pid" gorm:"column:pid; type:int(10) unsigned; not null; default:'0'; comment:'父级ID'" description:"父级ID"`
345
+	Content    string    `json:"content" gorm:"column:content; type:text; not null; comment:'评论内容'" description:"评论内容"`
346
+	Ctime      time.Time `json:"ctime" gorm:"column:ctime; type:int(10) unsigned; not null; comment:'评论时间'" description:"评论时间"`
347
+	Status     uint8     `json:"status" gorm:"column:status; type:tinyint(1) unsigned; not null; default:'1'; comment:'状态'" description:"状态"`
348
+	IsDel      uint8     `json:"is_del" gorm:"column:is_del; type:tinyint(1) unsigned; not null; default:'0'; comment:'1:删除 0:未删除'" description:"是否删除"`
349
+	Type       uint8     `json:"type" gorm:"column:type; type:tinyint(1) unsigned zerofill; not null; default:'1'; comment:'0用户1医生2科室3企业'" description:"类型"`
350
+	TAID       uint      `json:"t_aid" gorm:"column:t_aid; type:int(10) unsigned; comment:'原表ID,移动数据用'" description:"原表ID"`
351
+	TModule    string    `json:"t_module" gorm:"column:t_module; type:varchar(50); not null; default:'0'; comment:'模块'" description:"模块"`
352
+	TID        int       `json:"t_id" gorm:"column:t_id; type:int(11); not null; default:'0'; comment:'备用ID'" description:"备用ID"`
353
+	StarNum    uint      `json:"star_num" gorm:"column:star_num; type:int(10) unsigned; not null; default:'0'; comment:'点赞数'" description:"点赞数"`
354
+	CommentNum uint      `json:"comment_num" gorm:"column:comment_num; type:int(10) unsigned; not null; default:'0'; comment:'评论数'" description:"评论数"`
355
+	CommentID  uint      `json:"comment_id" gorm:"column:comment_id; type:int(10) unsigned; not null; default:'0'; comment:'在评论详情页面时用'" description:"评论ID"`
356
+}

+ 42 - 0
models/httpmodels.go Datei anzeigen

@@ -231,3 +231,45 @@ type AppCheckRecordItemReportVO struct {
231 231
 	ID              int    `json:"id" description:"id"`
232 232
 	Date            Time   `json:"date" description:"检测时间"`
233 233
 }
234
+
235
+type SyhArticlesVO struct {
236
+	ID          uint   `json:"id" gorm:"column:id; type:int(10) unsigned; primary_key; auto_increment; comment:'自增主键ID'" description:"自增主键ID"`
237
+	Title       string `json:"title" gorm:"column:title; type:varchar(255); not null; comment:'标题'" description:"标题"`
238
+	Summary     string `json:"summary" gorm:"column:summary; type:varchar(255); not null; default:''; comment:'简介'" description:"简介"`
239
+	Content     string `json:"content" gorm:"column:content; type:longtext; not null; comment:'内容'" description:"内容"`
240
+	ArticleType uint8  `json:"article_type" gorm:"column:article_type; type:tinyint(1) unsigned; not null; default:'1'; comment:'1普通2视频'" description:"文章类型"`
241
+	Num         uint   `json:"num" gorm:"column:num; type:int(10) unsigned; default:'0'; comment:'点击次数'" description:"点击次数"`
242
+	Ctime       Time   `json:"ctime" gorm:"column:ctime; type:int(10); not null; default:'0'; comment:'创建时间'" description:"创建时间"`
243
+	NewTime     Time   `json:"new_time" gorm:"column:new_time; type:int(10); not null; default:'0'; comment:'作为新建时间,ctime作为发布修改时间'" description:"新建时间"`
244
+	Img         string `json:"img" gorm:"column:img; type:varchar(255); comment:'图片'" description:"图片"`
245
+	MenuID      uint   `json:"menu_id" gorm:"column:menu_id; type:int(10) unsigned; not null; default:'1'; comment:'辅分类'" description:"辅分类"`
246
+	ClassID     uint   `json:"class_id" gorm:"column:class_id; type:int(10) unsigned; not null; default:'1'; comment:'主分类'" description:"主分类"`
247
+	Author      string `json:"author" gorm:"column:author; type:varchar(20); not null; default:''; comment:'作者'" description:"作者"`
248
+	Tags        string `json:"tags" gorm:"column:tags; type:varchar(50); comment:'标签'" description:"标签"`
249
+	IsDel       uint8  `json:"is_del" gorm:"column:is_del; type:tinyint(1) unsigned; not null; default:'0'; comment:'是否删除'" description:"是否删除"`
250
+	Status      uint8  `json:"status" gorm:"column:status; type:tinyint(1) unsigned; not null; default:'0'; comment:'状态'" description:"状态 0正在审核,1通过,2未通过,3草稿,4通过且大图显示视频"`
251
+	Reason      string `json:"reason" gorm:"column:reason; type:varchar(100); comment:'原因'" description:"原因"`
252
+	FromID      uint   `json:"from_id" gorm:"column:from_id; type:int(10) unsigned; not null; default:'0'; comment:'医生/机构ID'" description:"医生/机构ID"`
253
+	Type        uint8  `json:"type" gorm:"column:type; type:tinyint(1) unsigned; not null; default:'0'; comment:'类型'" description:"类型'0系统1医生2机构"`
254
+	StarNum     uint   `json:"star_num" gorm:"column:star_num; type:int(10) unsigned; not null; default:'0'; comment:'点赞数'" description:"点赞数"`
255
+	CommentNum  uint   `json:"comment_num" gorm:"column:comment_num; type:int(10) unsigned; not null; default:'0'; comment:'评论数'" description:"评论数"`
256
+	TModule     string `json:"t_module" gorm:"column:t_module; type:varchar(50); comment:'模块'" description:"模块"`
257
+	OrgID       uint   `json:"org_id" gorm:"column:org_id; type:int(10); comment:'orgId'" description:"orgId"`
258
+}
259
+
260
+// SyhArticlesComment 表示文章评论表的模型
261
+type SyhArticlesCommentVO struct {
262
+	ID         uint   `json:"id" gorm:"column:id; type:int(10) unsigned; primary_key; auto_increment; comment:'自增主键ID'" description:"自增主键ID"`
263
+	ArticleID  uint   `json:"article_id" gorm:"column:article_id; type:int(10) unsigned; not null; comment:'动态ID'" description:"动态ID"`
264
+	UserID     uint   `json:"user_id" gorm:"column:user_id; type:int(10) unsigned; not null; comment:'评论者用户ID'" description:"评论者用户ID"`
265
+	PID        uint   `json:"pid" gorm:"column:pid; type:int(10) unsigned; not null; default:'0'; comment:'父级ID'" description:"父级ID"`
266
+	Content    string `json:"content" gorm:"column:content; type:text; not null; comment:'评论内容'" description:"评论内容"`
267
+	Ctime      Time   `json:"ctime" gorm:"column:ctime; type:int(10) unsigned; not null; comment:'评论时间'" description:"评论时间"`
268
+	Status     uint8  `json:"status" gorm:"column:status; type:tinyint(1) unsigned; not null; default:'1'; comment:'状态'" description:"状态"`
269
+	IsDel      uint8  `json:"is_del" gorm:"column:is_del; type:tinyint(1) unsigned; not null; default:'0'; comment:'1:删除 0:未删除'" description:"是否删除"`
270
+	Type       uint8  `json:"type" gorm:"column:type; type:tinyint(1) unsigned zerofill; not null; default:'1'; comment:'0用户1医生2科室3企业'" description:"类型"`
271
+	TModule    string `json:"t_module" gorm:"column:t_module; type:varchar(50); not null; default:'0'; comment:'模块'" description:"模块"`
272
+	StarNum    uint   `json:"star_num" gorm:"column:star_num; type:int(10) unsigned; not null; default:'0'; comment:'点赞数'" description:"点赞数"`
273
+	CommentNum uint   `json:"comment_num" gorm:"column:comment_num; type:int(10) unsigned; not null; default:'0'; comment:'评论数'" description:"评论数"`
274
+	CommentID  uint   `json:"comment_id" gorm:"column:comment_id; type:int(10) unsigned; not null; default:'0'; comment:'在评论详情页面时用'" description:"评论ID"`
275
+}

+ 4 - 0
routers/router.go Datei anzeigen

@@ -43,6 +43,10 @@ func init() {
43 43
 				beego.NSInclude(
44 44
 					&controllers.CheckRecordApiController{},
45 45
 				)),
46
+			beego.NSNamespace("/api/article",
47
+				beego.NSInclude(
48
+					&controllers.ArticleApiController{},
49
+				)),
46 50
 		)
47 51
 	beego.AddNamespace(ns)
48 52
 	controllers.ApiControllersRegisterRouters()

+ 89 - 0
service/articleservice.go Datei anzeigen

@@ -0,0 +1,89 @@
1
+package service
2
+
3
+import (
4
+	"sws_xcx/models"
5
+	"time"
6
+
7
+	"github.com/jinzhu/gorm"
8
+)
9
+
10
+type ArticleService struct {
11
+	artDb *gorm.DB
12
+}
13
+
14
+func NewArticleService() *ArticleService {
15
+	return &ArticleService{artDb: ArtDB()}
16
+}
17
+
18
+func (s *ArticleService) GetArticleMenu(t int) (menus []*models.SyhArticlesMenu, err error) {
19
+
20
+	db := s.artDb.Model(&models.SyhArticlesMenu{}).Where("status = ? ", 1)
21
+	if t > 0 {
22
+		db = db.Where("type = ?", t)
23
+	}
24
+	err = db.Order("`order` asc").Find(&menus).Error
25
+	return
26
+}
27
+func (s *ArticleService) GetArticleByID(id int64) (article models.SyhArticlesVO, err error) {
28
+	var art models.SyhArticles
29
+	err = s.artDb.Model(&art).Where("id = ?", id).First(&art).Error
30
+	article = MapArticlesVO(art)
31
+	return
32
+}
33
+func MapArticlesVO(art models.SyhArticles) (article models.SyhArticlesVO) {
34
+	article.ID = art.ID
35
+	article.Title = art.Title
36
+	article.Summary = art.Summary
37
+	nt := time.Unix(int64(art.NewTime), 0)
38
+	article.NewTime = models.Time(nt)
39
+	ct := time.Unix(int64(art.Ctime), 0)
40
+	article.Ctime = models.Time(ct)
41
+	article.MenuID = art.MenuID
42
+	article.Status = art.Status
43
+	article.Img = art.Img
44
+	article.Tags = art.Tags
45
+	article.Content = art.Content
46
+	article.Author = art.Author
47
+	article.Reason = art.Reason
48
+	article.FromID = art.FromID
49
+	article.ClassID = art.ClassID
50
+	article.ArticleType = art.ArticleType
51
+	article.Type = art.Type
52
+	article.TModule = art.TModule
53
+	article.CommentNum = art.CommentNum
54
+	article.Num = art.Num
55
+	article.StarNum = art.StarNum
56
+	article.IsDel = art.IsDel
57
+	article.OrgID = art.OrgID
58
+	return
59
+}
60
+
61
+func (s *ArticleService) GetRamdonArticleList(limit int) (articles []*models.SyhArticlesVO, err error) {
62
+	var arts []models.SyhArticles
63
+	err = s.artDb.Model(&models.SyhArticles{}).Where("status in(?,?) and is_del = 0", 1, 4).Order("ctime desc").Limit(limit).Find(&arts).Error
64
+	articles = make([]*models.SyhArticlesVO, len(arts))
65
+	for i, v := range arts {
66
+		a := MapArticlesVO(v)
67
+		articles[i] = &a
68
+	}
69
+	return
70
+}
71
+
72
+func (s *ArticleService) GetArticleList(pageNum, pageSize, menuId int, keyword string) (articles []*models.SyhArticlesVO, total int, err error) {
73
+	offset := (pageNum - 1) * pageSize
74
+	var arts []models.SyhArticles
75
+	db := s.artDb.Model(&models.SyhArticles{}).Where("status in(?,?) and is_del = 0", 1, 4)
76
+	if menuId > 0 {
77
+		db = db.Where("menu_id = ?", menuId)
78
+	}
79
+	if keyword != "" {
80
+		db = db.Where("title like ? or summary like ?", "%"+keyword+"%", "%"+keyword+"%")
81
+	}
82
+	err = db.Count(&total).Order("new_time desc").Offset(offset).Limit(pageSize).Find(&arts).Error
83
+	articles = make([]*models.SyhArticlesVO, len(arts))
84
+	for i, v := range arts {
85
+		a := MapArticlesVO(v)
86
+		articles[i] = &a
87
+	}
88
+	return
89
+}

+ 25 - 4
service/db.go Datei anzeigen

@@ -31,6 +31,8 @@ var writeDb *gorm.DB
31 31
 var readUserDb *gorm.DB
32 32
 var readXtDb *gorm.DB
33 33
 
34
+var artDb *gorm.DB
35
+
34 36
 // var writeUserDb *gorm.DB
35 37
 
36 38
 // var readMiddleDb *gorm.DB
@@ -72,6 +74,12 @@ func ConnectDB() {
72 74
 	readXtPass := beego.AppConfig.String("readxtpass")
73 75
 	readXtName := beego.AppConfig.String("readxtname")
74 76
 
77
+	artdbHost := beego.AppConfig.String("artdbhost")
78
+	artdbPort := beego.AppConfig.String("artdbport")
79
+	artdbUser := beego.AppConfig.String("artdbuser")
80
+	artdbPass := beego.AppConfig.String("artdbpass")
81
+	artdbName := beego.AppConfig.String("artdbname")
82
+
75 83
 	// writeUserHost := beego.AppConfig.String("writeuserhost")
76 84
 	// writeUserPort := beego.AppConfig.String("writeuserport")
77 85
 	// writeUserUser := beego.AppConfig.String("writeuseruser")
@@ -144,10 +152,11 @@ func ConnectDB() {
144 152
 
145 153
 	// rudsnT := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", readUserUserT, readUserPassT, readUserHostT, readUserPortT, readUserNameT)
146 154
 	// wudsnT := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", writeUserUserT, writeUserPassT, writeUserHostT, writeUserPortT, writeUserNameT)
147
-
155
+	// 定义artdb 的sn
156
+	artsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", artdbUser, artdbPass, artdbHost, artdbPort, artdbName)
148 157
 	readDb, err = gorm.Open("mysql", rdsn)
149 158
 	if err != nil {
150
-		utils.ErrorLog("init DB err %v", err)
159
+		utils.ErrorLog("init rDB err %v", err)
151 160
 	}
152 161
 	readDb.DB().SetMaxIdleConns(10)
153 162
 	readDb.DB().SetMaxOpenConns(100)
@@ -155,12 +164,20 @@ func ConnectDB() {
155 164
 
156 165
 	writeDb, err = gorm.Open("mysql", wdsn)
157 166
 	if err != nil {
158
-		utils.ErrorLog("init DB err %v", err)
167
+		utils.ErrorLog("init wDB err %v", err)
159 168
 	}
160 169
 	writeDb.DB().SetMaxIdleConns(10)
161 170
 	writeDb.DB().SetMaxOpenConns(100)
162 171
 	writeDb.LogMode(true)
163 172
 
173
+	artDb, err = gorm.Open("mysql", artsn)
174
+	if err != nil {
175
+		utils.ErrorLog("init art DB err %v", err)
176
+	}
177
+	artDb.DB().SetMaxIdleConns(10)
178
+	artDb.DB().SetMaxOpenConns(100)
179
+	artDb.LogMode(true)
180
+
164 181
 	// readUserDbT, err = gorm.Open("mysql", rudsnT)
165 182
 	// if err != nil {
166 183
 	// 	//beego.Error(err)
@@ -187,7 +204,7 @@ func ConnectDB() {
187 204
 
188 205
 	readXtDb, err = gorm.Open("mysql", rxdsn)
189 206
 	if err != nil {
190
-		utils.ErrorLog("init DB err %v", err)
207
+		utils.ErrorLog("init rxDB err %v", err)
191 208
 	}
192 209
 	readXtDb.DB().SetMaxIdleConns(10)
193 210
 	readXtDb.DB().SetMaxOpenConns(100)
@@ -271,6 +288,10 @@ func ReadXtDB() *gorm.DB {
271 288
 	return readXtDb
272 289
 }
273 290
 
291
+func ArtDB() *gorm.DB {
292
+	return artDb
293
+}
294
+
274 295
 // func UserWriteDB() *gorm.DB {
275 296
 // 	return writeUserDb
276 297
 // }

+ 294 - 0
swagger/swagger.json Datei anzeigen

@@ -11,6 +11,156 @@
11 11
     },
12 12
     "basePath": "/xcx",
13 13
     "paths": {
14
+        "/api/article/getarticlebyid": {
15
+            "get": {
16
+                "tags": [
17
+                    "api/article"
18
+                ],
19
+                "description": "获取文章详情\n\u003cbr\u003e",
20
+                "operationId": "ArticleApiController.GetArticleByID",
21
+                "parameters": [
22
+                    {
23
+                        "in": "query",
24
+                        "name": "id",
25
+                        "description": "文章id",
26
+                        "required": true,
27
+                        "type": "integer",
28
+                        "format": "int64"
29
+                    }
30
+                ],
31
+                "responses": {
32
+                    "200": {
33
+                        "description": "success",
34
+                        "schema": {
35
+                            "$ref": "#/definitions/models.SyhArticlesVO"
36
+                        }
37
+                    },
38
+                    "500": {
39
+                        "description": "error"
40
+                    }
41
+                }
42
+            }
43
+        },
44
+        "/api/article/getarticlelist": {
45
+            "get": {
46
+                "tags": [
47
+                    "api/article"
48
+                ],
49
+                "description": "获取文章列表\n\u003cbr\u003e",
50
+                "operationId": "ArticleApiController.GetArticleList",
51
+                "parameters": [
52
+                    {
53
+                        "in": "query",
54
+                        "name": "pageNum",
55
+                        "description": "当前页(从1开始)",
56
+                        "required": true,
57
+                        "type": "integer",
58
+                        "format": "int64"
59
+                    },
60
+                    {
61
+                        "in": "query",
62
+                        "name": "pageSize",
63
+                        "description": "分页大小",
64
+                        "required": true,
65
+                        "type": "integer",
66
+                        "format": "int64"
67
+                    },
68
+                    {
69
+                        "in": "query",
70
+                        "name": "menuid",
71
+                        "description": "分类ID",
72
+                        "type": "integer",
73
+                        "format": "int64"
74
+                    },
75
+                    {
76
+                        "in": "query",
77
+                        "name": "keyword",
78
+                        "description": "搜索关键字",
79
+                        "type": "string"
80
+                    }
81
+                ],
82
+                "responses": {
83
+                    "200": {
84
+                        "description": "success",
85
+                        "schema": {
86
+                            "type": "array",
87
+                            "items": {
88
+                                "$ref": "#/definitions/models.SyhArticlesVO"
89
+                            }
90
+                        }
91
+                    },
92
+                    "500": {
93
+                        "description": "error"
94
+                    }
95
+                }
96
+            }
97
+        },
98
+        "/api/article/getarticlemenu": {
99
+            "get": {
100
+                "tags": [
101
+                    "api/article"
102
+                ],
103
+                "description": "获取文章分类\n\u003cbr\u003e",
104
+                "operationId": "ArticleApiController.GetArticleMenu",
105
+                "parameters": [
106
+                    {
107
+                        "in": "query",
108
+                        "name": "type",
109
+                        "description": "类型:0全部1主2辅",
110
+                        "required": true,
111
+                        "type": "integer",
112
+                        "format": "int64"
113
+                    }
114
+                ],
115
+                "responses": {
116
+                    "200": {
117
+                        "description": "success",
118
+                        "schema": {
119
+                            "type": "array",
120
+                            "items": {
121
+                                "$ref": "#/definitions/models.SyhArticlesMenu"
122
+                            }
123
+                        }
124
+                    },
125
+                    "500": {
126
+                        "description": "error"
127
+                    }
128
+                }
129
+            }
130
+        },
131
+        "/api/article/getramdonarticlelist": {
132
+            "get": {
133
+                "tags": [
134
+                    "api/article"
135
+                ],
136
+                "description": "获取随机文章列表\n\u003cbr\u003e",
137
+                "operationId": "ArticleApiController.GetRamdonArticleList",
138
+                "parameters": [
139
+                    {
140
+                        "in": "query",
141
+                        "name": "limit",
142
+                        "description": "文章数量",
143
+                        "required": true,
144
+                        "type": "integer",
145
+                        "format": "int64"
146
+                    }
147
+                ],
148
+                "responses": {
149
+                    "200": {
150
+                        "description": "success",
151
+                        "schema": {
152
+                            "type": "array",
153
+                            "items": {
154
+                                "$ref": "#/definitions/models.SyhArticlesVO"
155
+                            }
156
+                        }
157
+                    },
158
+                    "500": {
159
+                        "description": "error"
160
+                    }
161
+                }
162
+            }
163
+        },
14 164
         "/api/checkrecord/getcheckrecorditembyid": {
15 165
             "get": {
16 166
                 "tags": [
@@ -1228,6 +1378,150 @@
1228 1378
                 }
1229 1379
             }
1230 1380
         },
1381
+        "models.SyhArticlesMenu": {
1382
+            "title": "SyhArticlesMenu",
1383
+            "type": "object",
1384
+            "properties": {
1385
+                "id": {
1386
+                    "description": "自增主键ID",
1387
+                    "type": "integer",
1388
+                    "format": "int32"
1389
+                },
1390
+                "img": {
1391
+                    "description": "图片",
1392
+                    "type": "string"
1393
+                },
1394
+                "name": {
1395
+                    "description": "分类名",
1396
+                    "type": "string"
1397
+                },
1398
+                "order": {
1399
+                    "description": "排序",
1400
+                    "type": "integer",
1401
+                    "format": "int32"
1402
+                },
1403
+                "status": {
1404
+                    "description": "状态",
1405
+                    "type": "integer",
1406
+                    "format": "int32"
1407
+                },
1408
+                "summary": {
1409
+                    "description": "介绍",
1410
+                    "type": "string"
1411
+                },
1412
+                "type": {
1413
+                    "description": "分类类型",
1414
+                    "type": "integer",
1415
+                    "format": "int32"
1416
+                }
1417
+            }
1418
+        },
1419
+        "models.SyhArticlesVO": {
1420
+            "title": "SyhArticlesVO",
1421
+            "type": "object",
1422
+            "properties": {
1423
+                "article_type": {
1424
+                    "description": "文章类型",
1425
+                    "type": "integer",
1426
+                    "format": "int32"
1427
+                },
1428
+                "author": {
1429
+                    "description": "作者",
1430
+                    "type": "string"
1431
+                },
1432
+                "class_id": {
1433
+                    "description": "主分类",
1434
+                    "type": "integer",
1435
+                    "format": "int32"
1436
+                },
1437
+                "comment_num": {
1438
+                    "description": "评论数",
1439
+                    "type": "integer",
1440
+                    "format": "int32"
1441
+                },
1442
+                "content": {
1443
+                    "description": "内容",
1444
+                    "type": "string"
1445
+                },
1446
+                "ctime": {
1447
+                    "$ref": "#/definitions/models.Time",
1448
+                    "description": "创建时间"
1449
+                },
1450
+                "from_id": {
1451
+                    "description": "医生/机构ID",
1452
+                    "type": "integer",
1453
+                    "format": "int32"
1454
+                },
1455
+                "id": {
1456
+                    "description": "自增主键ID",
1457
+                    "type": "integer",
1458
+                    "format": "int32"
1459
+                },
1460
+                "img": {
1461
+                    "description": "图片",
1462
+                    "type": "string"
1463
+                },
1464
+                "is_del": {
1465
+                    "description": "是否删除",
1466
+                    "type": "integer",
1467
+                    "format": "int32"
1468
+                },
1469
+                "menu_id": {
1470
+                    "description": "辅分类",
1471
+                    "type": "integer",
1472
+                    "format": "int32"
1473
+                },
1474
+                "new_time": {
1475
+                    "$ref": "#/definitions/models.Time",
1476
+                    "description": "新建时间"
1477
+                },
1478
+                "num": {
1479
+                    "description": "点击次数",
1480
+                    "type": "integer",
1481
+                    "format": "int32"
1482
+                },
1483
+                "org_id": {
1484
+                    "description": "orgId",
1485
+                    "type": "integer",
1486
+                    "format": "int32"
1487
+                },
1488
+                "reason": {
1489
+                    "description": "原因",
1490
+                    "type": "string"
1491
+                },
1492
+                "star_num": {
1493
+                    "description": "点赞数",
1494
+                    "type": "integer",
1495
+                    "format": "int32"
1496
+                },
1497
+                "status": {
1498
+                    "description": "状态 0正在审核,1通过,2未通过,3草稿,4通过且大图显示视频",
1499
+                    "type": "integer",
1500
+                    "format": "int32"
1501
+                },
1502
+                "summary": {
1503
+                    "description": "简介",
1504
+                    "type": "string"
1505
+                },
1506
+                "t_module": {
1507
+                    "description": "模块",
1508
+                    "type": "string"
1509
+                },
1510
+                "tags": {
1511
+                    "description": "标签",
1512
+                    "type": "string"
1513
+                },
1514
+                "title": {
1515
+                    "description": "标题",
1516
+                    "type": "string"
1517
+                },
1518
+                "type": {
1519
+                    "description": "类型'0系统1医生2机构",
1520
+                    "type": "integer",
1521
+                    "format": "int32"
1522
+                }
1523
+            }
1524
+        },
1231 1525
         "models.Time": {
1232 1526
             "title": "Time",
1233 1527
             "type": "object"

+ 220 - 0
swagger/swagger.yml Datei anzeigen

@@ -8,6 +8,115 @@ info:
8 8
     name: 领透科技
9 9
 basePath: /xcx
10 10
 paths:
11
+  /api/article/getarticlebyid:
12
+    get:
13
+      tags:
14
+      - api/article
15
+      description: |-
16
+        获取文章详情
17
+        <br>
18
+      operationId: ArticleApiController.GetArticleByID
19
+      parameters:
20
+      - in: query
21
+        name: id
22
+        description: 文章id
23
+        required: true
24
+        type: integer
25
+        format: int64
26
+      responses:
27
+        "200":
28
+          description: success
29
+          schema:
30
+            $ref: '#/definitions/models.SyhArticlesVO'
31
+        "500":
32
+          description: error
33
+  /api/article/getarticlelist:
34
+    get:
35
+      tags:
36
+      - api/article
37
+      description: |-
38
+        获取文章列表
39
+        <br>
40
+      operationId: ArticleApiController.GetArticleList
41
+      parameters:
42
+      - in: query
43
+        name: pageNum
44
+        description: 当前页(从1开始)
45
+        required: true
46
+        type: integer
47
+        format: int64
48
+      - in: query
49
+        name: pageSize
50
+        description: 分页大小
51
+        required: true
52
+        type: integer
53
+        format: int64
54
+      - in: query
55
+        name: menuid
56
+        description: 分类ID
57
+        type: integer
58
+        format: int64
59
+      - in: query
60
+        name: keyword
61
+        description: 搜索关键字
62
+        type: string
63
+      responses:
64
+        "200":
65
+          description: success
66
+          schema:
67
+            type: array
68
+            items:
69
+              $ref: '#/definitions/models.SyhArticlesVO'
70
+        "500":
71
+          description: error
72
+  /api/article/getarticlemenu:
73
+    get:
74
+      tags:
75
+      - api/article
76
+      description: |-
77
+        获取文章分类
78
+        <br>
79
+      operationId: ArticleApiController.GetArticleMenu
80
+      parameters:
81
+      - in: query
82
+        name: type
83
+        description: 类型:0全部1主2辅
84
+        required: true
85
+        type: integer
86
+        format: int64
87
+      responses:
88
+        "200":
89
+          description: success
90
+          schema:
91
+            type: array
92
+            items:
93
+              $ref: '#/definitions/models.SyhArticlesMenu'
94
+        "500":
95
+          description: error
96
+  /api/article/getramdonarticlelist:
97
+    get:
98
+      tags:
99
+      - api/article
100
+      description: |-
101
+        获取随机文章列表
102
+        <br>
103
+      operationId: ArticleApiController.GetRamdonArticleList
104
+      parameters:
105
+      - in: query
106
+        name: limit
107
+        description: 文章数量
108
+        required: true
109
+        type: integer
110
+        format: int64
111
+      responses:
112
+        "200":
113
+          description: success
114
+          schema:
115
+            type: array
116
+            items:
117
+              $ref: '#/definitions/models.SyhArticlesVO'
118
+        "500":
119
+          description: error
11 120
   /api/checkrecord/getcheckrecorditembyid:
12 121
     get:
13 122
       tags:
@@ -890,6 +999,117 @@ definitions:
890 999
       real_name:
891 1000
         description: 真实姓名
892 1001
         type: string
1002
+  models.SyhArticlesMenu:
1003
+    title: SyhArticlesMenu
1004
+    type: object
1005
+    properties:
1006
+      id:
1007
+        description: 自增主键ID
1008
+        type: integer
1009
+        format: int32
1010
+      img:
1011
+        description: 图片
1012
+        type: string
1013
+      name:
1014
+        description: 分类名
1015
+        type: string
1016
+      order:
1017
+        description: 排序
1018
+        type: integer
1019
+        format: int32
1020
+      status:
1021
+        description: 状态
1022
+        type: integer
1023
+        format: int32
1024
+      summary:
1025
+        description: 介绍
1026
+        type: string
1027
+      type:
1028
+        description: 分类类型
1029
+        type: integer
1030
+        format: int32
1031
+  models.SyhArticlesVO:
1032
+    title: SyhArticlesVO
1033
+    type: object
1034
+    properties:
1035
+      article_type:
1036
+        description: 文章类型
1037
+        type: integer
1038
+        format: int32
1039
+      author:
1040
+        description: 作者
1041
+        type: string
1042
+      class_id:
1043
+        description: 主分类
1044
+        type: integer
1045
+        format: int32
1046
+      comment_num:
1047
+        description: 评论数
1048
+        type: integer
1049
+        format: int32
1050
+      content:
1051
+        description: 内容
1052
+        type: string
1053
+      ctime:
1054
+        $ref: '#/definitions/models.Time'
1055
+        description: 创建时间
1056
+      from_id:
1057
+        description: 医生/机构ID
1058
+        type: integer
1059
+        format: int32
1060
+      id:
1061
+        description: 自增主键ID
1062
+        type: integer
1063
+        format: int32
1064
+      img:
1065
+        description: 图片
1066
+        type: string
1067
+      is_del:
1068
+        description: 是否删除
1069
+        type: integer
1070
+        format: int32
1071
+      menu_id:
1072
+        description: 辅分类
1073
+        type: integer
1074
+        format: int32
1075
+      new_time:
1076
+        $ref: '#/definitions/models.Time'
1077
+        description: 新建时间
1078
+      num:
1079
+        description: 点击次数
1080
+        type: integer
1081
+        format: int32
1082
+      org_id:
1083
+        description: orgId
1084
+        type: integer
1085
+        format: int32
1086
+      reason:
1087
+        description: 原因
1088
+        type: string
1089
+      star_num:
1090
+        description: 点赞数
1091
+        type: integer
1092
+        format: int32
1093
+      status:
1094
+        description: 状态 0正在审核,1通过,2未通过,3草稿,4通过且大图显示视频
1095
+        type: integer
1096
+        format: int32
1097
+      summary:
1098
+        description: 简介
1099
+        type: string
1100
+      t_module:
1101
+        description: 模块
1102
+        type: string
1103
+      tags:
1104
+        description: 标签
1105
+        type: string
1106
+      title:
1107
+        description: 标题
1108
+        type: string
1109
+      type:
1110
+        description: 类型'0系统1医生2机构
1111
+        type: integer
1112
+        format: int32
893 1113
   models.Time:
894 1114
     title: Time
895 1115
     type: object