ziwen 1 жил өмнө
parent
commit
bd5ad14dae

+ 42 - 0
controllers/yanxuan_special.go

@@ -706,4 +706,46 @@ func (this *YanxuanSpecialController) CompanySearch() {
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
+}
+
+// @Title 专栏取消发布
+// @Description 专栏取消发布
+// @Param	request	body help_doc.AddHelpDocReq true "type json string"
+// @Success 200 {object} models.AddEnglishReportResp
+// @router /cancel [post]
+func (this *YanxuanSpecialController) Cancel() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.User
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req models.CancelPublishCygxYanxuanSpecialReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.Id <= 0 {
+		br.Msg = "文章id错误"
+		return
+	}
+
+	if tmpErr := models.CancelPublishYanxuanSpecial(req.Id); tmpErr != nil {
+		br.Msg = "取消发布失败"
+		br.ErrMsg = "取消发布失败, Err:" + tmpErr.Error()
+		return
+	}
+
+	br.Msg = "取消发布成功"
+	br.Ret = 200
+	br.Success = true
 }

+ 11 - 0
models/cygx_yanxuan_special.go

@@ -129,3 +129,14 @@ func GetYanxuanSpecialIndustry(keyword string) (IndustryNames []string, err erro
 	_, err = o.Raw(sql).QueryRows(&IndustryNames)
 	return
 }
+
+type CancelPublishCygxYanxuanSpecialReq struct {
+	Id     int    // 文章id
+}
+func CancelPublishYanxuanSpecial(id int) (err error) {
+	o := orm.NewOrm()
+	sql := ``
+	sql = `UPDATE cygx_yanxuan_special SET status=1,publish_time=NOW() WHERE id = ? `
+	_, err = o.Raw(sql, id).Exec()
+	return
+}

+ 8 - 9
models/cygx_yanxuan_special_company.go

@@ -3,16 +3,16 @@ package models
 import "github.com/beego/beego/v2/client/orm"
 
 type CygxYanxuanSpecialCompany struct {
-	Id        int     `orm:"column(id);pk"`
-	TradeCode string  // 交易代码
-	SecName   string  // 公司名
-	PyName    string  // 拼音名
-	Region    string  // 地区
+	Id        int    `orm:"column(id);pk"`
+	TradeCode string `json:"trade_code"` // 交易代码
+	SecName   string `json:"sec_name"`   // 公司名
+	PyName    string `json:"py_name"`    // 拼音名
+	Region    string `json:"region"`     // 地区
 }
 
 type VmpStocks struct {
 	Code int
-	Msg string
+	Msg  string
 	Data []CygxYanxuanSpecialCompany
 }
 
@@ -26,11 +26,10 @@ func AddCygxYanxuanSpecialCompanyMulti(items []*CygxYanxuanSpecialCompany) (err
 	return
 }
 
-
 func GetYanxuanSpecialCompany(keyword string) (IndustryNames []string, err error) {
 	o := orm.NewOrm()
 	sql := ``
-	sql = `SELECT sec_name FROM cygx_yanxuan_special_company WHERE sec_name LIKE '%`+keyword+`%' `
+	sql = `SELECT sec_name FROM cygx_yanxuan_special_company WHERE sec_name LIKE '%` + keyword + `%' `
 	_, err = o.Raw(sql).QueryRows(&IndustryNames)
 	return
-}
+}

+ 9 - 0
routers/commentsRouter.go

@@ -1663,6 +1663,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:YanxuanSpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:YanxuanSpecialController"],
+        beego.ControllerComments{
+            Method: "Cancel",
+            Router: `/cancel`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:YanxuanSpecialController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:YanxuanSpecialController"],
         beego.ControllerComments{
             Method: "Center",

+ 13 - 3
services/cygx_yanxuan_special_company.go

@@ -8,7 +8,7 @@ import (
 	"net/http"
 )
 
-func GetCom()  {
+func GetStocksFromVmp()  {
 	getUrl := "https://vmp.hzinsights.com/v2api/articles/stock"
 	result, err := http.Get(getUrl)
 	if err != nil {
@@ -29,8 +29,18 @@ func GetCom()  {
 	}
 
 	items := make([]*models.CygxYanxuanSpecialCompany, 0)
-	for _, v := range resp.Data {
-		items = append(items, &v)
+
+
+	for i, _ := range resp.Data {
+		items = append(items, &resp.Data[i])
+		if len(items) > 5000 {
+			err  = models.AddCygxYanxuanSpecialCompanyMulti(items)
+			if err != nil {
+				fmt.Println("AddCygxYanxuanSpecialCompanyMulti Err:%s", err.Error())
+				return
+			}
+			items = []*models.CygxYanxuanSpecialCompany{}
+		}
 	}
 
 	err  = models.AddCygxYanxuanSpecialCompanyMulti(items)