xingzai пре 1 година
родитељ
комит
9b3216a4c4

+ 102 - 0
controllers/cygx/askserie_video.go

@@ -0,0 +1,102 @@
+package cygx
+
+import (
+	"encoding/json"
+	"hongze/hz_crm_api/controllers"
+	"hongze/hz_crm_api/models"
+	"hongze/hz_crm_api/models/cygx"
+	"strconv"
+	"strings"
+	"time"
+)
+
+// 系列问答视频
+type AskserieVideoController struct {
+	controllers.BaseAuthController
+}
+
+// @Title 新增
+// @Description 新增系列问答接口
+// @Param	request	body cygx.AddProductInteriorReq true "type json string"
+// @Success 200 {object} "保存成功"
+// @router /askserie_video/preserveAndEdit [post]
+func (this *AskserieVideoController) PreserveAndPublish() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req cygx.AddAskserieVideoReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	askserieVideoId := req.AskserieVideoId
+	videoName := req.VideoName
+	videoUrl := req.VideoUrl
+	videoDuration := req.VideoDuration
+	chartPermissionId := req.ChartPermissionId
+	chartPermissionName := req.ChartPermissionName
+	industrialManagementIds := req.IndustrialManagementIds
+	backgroundImg := req.BackgroundImg
+	shareImg := req.ShareImg
+	// 产业ID校验
+	if industrialManagementIds != "" {
+		industrialManagementIdList := strings.Split(industrialManagementIds, ",")
+		for _, v := range industrialManagementIdList {
+			_, err := strconv.Atoi(v)
+			if err != nil {
+				br.Msg = "参数解析异常!"
+				br.ErrMsg = "产业ID不规范,Err:" + err.Error() + industrialManagementIds
+				return
+			}
+		}
+	}
+
+	item := new(cygx.CygxAskserieVideo)
+	item.AskserieVideoId = askserieVideoId
+	item.VideoName = videoName
+	item.VideoUrl = videoUrl
+	item.VideoDuration = videoDuration
+	item.ChartPermissionId = chartPermissionId
+	item.ChartPermissionName = chartPermissionName
+	item.PublishStatus = 1
+	item.BackgroundImg = backgroundImg
+	item.ShareImg = shareImg
+	item.AdminId = sysUser.AdminId
+	item.ModifyDate = time.Now()
+	item.PublishDate = time.Now()
+	item.CreateTime = time.Now()
+
+	if askserieVideoId == 0 {
+		//新增
+		err = cygx.AddCygxAskserieVideo(item, industrialManagementIds)
+	} else {
+		//更新
+		_, err := cygx.GetCygxAskserieVideoDetail(askserieVideoId)
+		if err != nil {
+			br.Msg = "详情不存在"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		err = cygx.UpdateCygxAskserieVideo(item, industrialManagementIds)
+	}
+	if err != nil {
+		br.Msg = "保存失败"
+		br.ErrMsg = "保存失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.IsAddLog = true
+	br.Msg = "操作成功"
+}

+ 159 - 0
models/cygx/askserie_video.go

@@ -0,0 +1,159 @@
+package cygx
+
+import (
+	//"github.com/beego/beego/v2/client/orm"
+	//"github.com/rdlucklib/rdluck_tools/paging"
+	//"strconv"
+	//"strings"
+	"github.com/beego/beego/v2/client/orm"
+	"strconv"
+	"strings"
+	"time"
+)
+
+type CygxAskserieVideo struct {
+	AskserieVideoId     int       `orm:"column(askserie_video_id);pk"description:"视频id"`
+	VideoName           string    `description:"视频标题"`
+	VideoUrl            string    `description:"视频地址"`
+	VideoDuration       string    `description:"视频时长"`
+	ChartPermissionId   int       `description:"行业ID"`
+	ChartPermissionName string    `description:"行业名称"`
+	PublishStatus       int       `description:"发布状态 1发布 0没有"`
+	VideoCounts         int       `description:"播放量"`
+	BackgroundImg       string    `description:"封面图片"`
+	ShareImg            string    `description:"分享图片"`
+	AdminId             int       `description:"管理员、销售ID"`
+	ModifyDate          time.Time `description:"更新时间"`
+	PublishDate         time.Time `description:"发布时间"`
+	CreateTime          time.Time `description:"创建时间"`
+}
+
+type AddAskserieVideoReq struct {
+	AskserieVideoId         int    `description:"askserie_video_id"`
+	VideoName               string `description:"视频标题"`
+	VideoUrl                string `description:"视频地址"`
+	VideoDuration           string `description:"视频时长"`
+	ChartPermissionId       int    `description:"行业ID"`
+	ChartPermissionName     string `description:"行业名称"`
+	IndustrialManagementIds string `description:"产业id 多个用 , 隔开"`
+	BackgroundImg           string `description:"封面图片"`
+	ShareImg                string `description:"分享图片"`
+}
+
+type CygxAskserieVideoResp struct {
+	AskserieVideoId     int       `orm:"column(askserie_video_id);pk"description:"视频id"`
+	VideoName           string    `description:"视频标题"`
+	VideoUrl            string    `description:"视频地址"`
+	VideoDuration       string    `description:"视频时长"`
+	ChartPermissionId   int       `description:"行业ID"`
+	ChartPermissionName string    `description:"行业名称"`
+	PublishStatus       int       `description:"发布状态 1发布 0没有"`
+	VideoCounts         int       `description:"播放量"`
+	BackgroundImg       string    `description:"封面图片"`
+	ShareImg            string    `description:"分享图片"`
+	AdminId             int       `description:"管理员、销售ID"`
+	ModifyDate          time.Time `description:"更新时间"`
+	PublishDate         time.Time `description:"发布时间"`
+	CreateTime          time.Time `description:"创建时间"`
+}
+
+// 通过ID获取详情
+func GetCygxAskserieVideoDetail(askserieVideoId int) (item *CygxAskserieVideoResp, err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	sql := `SELECT * FROM cygx_askserie_video  WHERE askserie_video_id=? `
+	err = o.Raw(sql, askserieVideoId).QueryRow(&item)
+	return
+}
+
+// 添加
+func AddCygxAskserieVideo(item *CygxAskserieVideo, industrialManagementIds string) (err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+	newId, err := to.Insert(item)
+	if err != nil {
+		return
+	}
+	//添加与产业的关联
+	//new(cygx.CygxIndustrialAskserieVideoGroupManagement),
+	industrialManagementIdList := strings.Split(industrialManagementIds, ",")
+	for _, v := range industrialManagementIdList {
+		itemIndustrialManagementGroup := new(CygxIndustrialAskserieVideoGroupManagement)
+		newIndustrialId, _ := strconv.Atoi(v)
+		itemIndustrialManagementGroup.CreateTime = time.Now()
+		itemIndustrialManagementGroup.AskserieVideoId = int(newId)
+		itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
+		_, err = to.Insert(itemIndustrialManagementGroup)
+		if err != nil {
+			return
+		}
+	}
+	return
+}
+
+// 修改
+func UpdateCygxAskserieVideo(item *CygxAskserieVideo, industrialManagementIds string) (err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+
+	updateParams := make(map[string]interface{})
+	updateParams["VideoName"] = item.VideoName
+	updateParams["VideoUrl"] = item.VideoUrl
+	updateParams["VideoDuration"] = item.VideoDuration
+	updateParams["ChartPermissionId"] = item.ChartPermissionId
+	updateParams["ChartPermissionName"] = item.ChartPermissionName
+	updateParams["BackgroundImg"] = item.BackgroundImg
+	updateParams["ShareImg"] = item.ShareImg
+	updateParams["ModifyDate"] = time.Now()
+	ptrStructOrTableName := "cygx_askserie_video"
+	whereParam := map[string]interface{}{"askserie_video_id": item.AskserieVideoId}
+	qs := to.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range whereParam {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err = qs.Update(updateParams)
+	if err != nil {
+		return
+	}
+
+	//删除关联产业 (避免截断表时产生的脏数据,故不用update而是先删除再增加)
+	sql := `	DELETE FROM cygx_industrial_askserie_video_group_management WHERE askserie_video_id = ?`
+	_, err = to.Raw(sql, item.AskserieVideoId).Exec()
+	if err != nil {
+		return
+	}
+
+	industrialManagementIdList := strings.Split(industrialManagementIds, ",")
+	for _, v := range industrialManagementIdList {
+		itemIndustrialManagementGroup := new(CygxIndustrialAskserieVideoGroupManagement)
+		newIndustrialId, _ := strconv.Atoi(v)
+		itemIndustrialManagementGroup.CreateTime = time.Now()
+		itemIndustrialManagementGroup.AskserieVideoId = item.AskserieVideoId
+		itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
+		_, err = to.Insert(itemIndustrialManagementGroup)
+		if err != nil {
+			return
+		}
+	}
+
+	return
+}

+ 14 - 0
models/cygx/industrial_askserie_video_group_management.go

@@ -0,0 +1,14 @@
+package cygx
+
+import (
+	//"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// 首页资源表与产业的关系
+type CygxIndustrialAskserieVideoGroupManagement struct {
+	Id                     int       `orm:"column(id);pk" description:"主键ID"`
+	AskserieVideoId        int       `description:"askserie_video_id"`
+	IndustrialManagementId int       `description:"cygx_industrial_management表的主键ID"`
+	CreateTime             time.Time `description:"创建时间"`
+}

+ 2 - 0
models/db.go

@@ -458,6 +458,8 @@ func initCygx() {
 		new(cygx.CygxAllocationCompanyContractPermissionLog),
 		new(cygx.CygxQuestionnaire),
 		new(cygx.CygxQuestionnaireTheme),
+		new(cygx.CygxAskserieVideo),
+		new(cygx.CygxIndustrialAskserieVideoGroupManagement),
 	)
 }
 

+ 9 - 0
routers/commentsRouter.go

@@ -1285,6 +1285,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:AskserieVideoController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:AskserieVideoController"],
+        beego.ControllerComments{
+            Method: "PreserveAndPublish",
+            Router: `/askserie_video/preserveAndEdit`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:BannerCoAntroller"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:BannerCoAntroller"],
         beego.ControllerComments{
             Method: "PreserveAndPublish",

+ 1 - 0
routers/router.go

@@ -155,6 +155,7 @@ func init() {
 				&cygx.YanxuanSpecialController{},
 				&cygx.ContractAllocationController{},
 				&cygx.QuestionnaireController{},
+				&cygx.AskserieVideoController{},
 			),
 		),
 		web.NSNamespace("/advisory",