Browse Source

新增路演问答接口

317699326@qq.com 1 month ago
parent
commit
47a3cc4f21

+ 109 - 0
controllers/roadshow/calendar_researcher_question.go

@@ -0,0 +1,109 @@
+package roadshow
+
+import (
+	"encoding/json"
+	"hongze/hz_crm_api/models"
+	"hongze/hz_crm_api/models/roadshow"
+	"hongze/hz_crm_api/utils"
+	"strconv"
+	"time"
+)
+
+// @Title 路演客户问答保存接口
+// @Description 路演客户问答保存接口
+// @Param	request	body roadshow.RoadShowQuestionSaveReq true "type json string"
+// @Success Ret=200 保存成功
+// @router /question/save [post]
+func (this *CalendarController) QuestionAdd() {
+	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
+	}
+
+	deleteCache := true
+	cacheKey := "CACHE_RS_ACTIVITY_QUESTION_SAVE_" + strconv.Itoa(sysUser.AdminId)
+	defer func() {
+		if deleteCache {
+			utils.Rc.Delete(cacheKey)
+		}
+	}()
+	if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
+		deleteCache = false
+		br.Msg = "系统处理中,请稍后重试!"
+		br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
+		return
+	}
+	var req roadshow.RoadShowQuestionSaveReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
+		br.Msg = "参数错误!"
+		return
+	}
+
+	calendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
+	if err != nil {
+		br.Msg = "获取路演记录失败!"
+		br.ErrMsg = "获取路演记录失败,Err:" + err.Error()
+		return
+	}
+
+	if calendarResearcherItem.QuestionStatus == 1 {
+		br.Msg = "问答已填写,不可重复提交!"
+		return
+	}
+
+	err = roadshow.RoadShowQuestionSave(&req)
+	if err != nil {
+		br.Msg = "保存失败!"
+		br.ErrMsg = "保存失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "保存成功"
+	br.IsAddLog = true
+}
+
+// ResearcherList
+// @Title 获取路演客户问答信息接口
+// @Description 获取路演客户问答信息接口
+// @Param   RsCalendarResearcherId   query   int  true       "路演研究员记录ID"
+// @Success 200 {object} roadshow.ResearcherGroup
+// @router /question/list [get]
+func (this *CalendarController) QuestionList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	rsCalendarResearcherId, _ := this.GetInt("RsCalendarResearcherId")
+	if rsCalendarResearcherId <= 0 {
+		br.Msg = "参数错误!"
+		return
+	}
+	list, err := roadshow.GetRoadShowQuestionList(rsCalendarResearcherId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败!"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = list
+}

+ 1 - 1
go.mod

@@ -32,6 +32,7 @@ require (
 	github.com/tealeg/xlsx v1.0.5
 	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.541
 	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.541
+	github.com/wechatpay-apiv3/wechatpay-go v0.2.18
 	github.com/xuri/excelize/v2 v2.6.1
 	github.com/yidane/formula v0.0.0-20210902154546-0782e1736717
 	gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
@@ -97,7 +98,6 @@ require (
 	github.com/tidwall/match v1.1.1 // indirect
 	github.com/tidwall/pretty v1.2.0 // indirect
 	github.com/tjfoc/gmsm v1.3.2 // indirect
-	github.com/wechatpay-apiv3/wechatpay-go v0.2.18 // indirect
 	github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect
 	github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect
 	golang.org/x/crypto v0.5.0 // indirect

+ 1 - 0
go.sum

@@ -13,6 +13,7 @@ github.com/SebastiaanKlippert/go-wkhtmltopdf v1.7.2 h1:LORAatv6KuKheYq8HXehiwx3f
 github.com/SebastiaanKlippert/go-wkhtmltopdf v1.7.2/go.mod h1:TY8r0gmwEL1c5Lbd66NgQCkL4ZjGDJCMVqvbbFvUx20=
 github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
 github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
+github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
 github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
 github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
 github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=

+ 1 - 0
models/db.go

@@ -389,6 +389,7 @@ func initRoadShow() {
 		new(roadshow.RsCalendarMeetingLabelGroup), //路演参会名单关联的标签表
 		new(roadshow.RsCalendarApiLog),            //上海路演三方接口请求记录日志表
 		new(roadshow.RsReportRecordPermission),    //路演公司权限记录
+		new(roadshow.RsCalendarResearcherQuestion),
 	)
 }
 

+ 4 - 0
models/roadshow/calendar.go

@@ -90,6 +90,10 @@ type RsCalendarResearcher struct {
 	IsSynced               int       `description:"是否与上海同步 0:未同步 1:已同步"`
 	ResearcherSort         int       `description:"研究员新增排序"`
 	UnionCode              string    `description:"公开会议联合编码"`
+	CompanyIndustry        string    `description:"客户行业"`
+	CompanyClassify        string    `description:"客户分类"`
+	QuestionStatus         int       `description:"问答状态:0-未填写;1-已填写"`
+	QuestionMsgStatus      int       `description:"问答模板消息:0-未发送;1-已发送"`
 }
 
 func GetRsCalendarById(rsCalendarId int) (item *RsCalendar, err error) {

+ 62 - 0
models/roadshow/calendar_researcher_question.go

@@ -0,0 +1,62 @@
+package roadshow
+
+import (
+	"context"
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type RsCalendarResearcherQuestion struct {
+	RsCalendarResearcherQuestionId int       `orm:"column(rs_calendar_researcher_question_id);pk"`
+	RsCalendarResearcherId         int       `description:"路演研究员记录ID"`
+	QuestionContent                string    `description:"提问内容"`
+	ReplyContent                   string    `description:"客户分类"`
+	CreateTime                     time.Time `description:"创建时间"`
+	ModifyTime                     time.Time `description:"更新时间"`
+}
+
+type RoadShowQuestionSaveReq struct {
+	RsCalendarId           int                                    `description:"路演ID"`
+	RsCalendarResearcherId int                                    `description:"路演研究员记录ID"`
+	CompanyIndustry        string                                 `description:"客户行业"`
+	CompanyClassify        string                                 `description:"客户分类"`
+	QuestionList           []*RsCalendarResearcherQuestionSaveReq `description:"问答列表"`
+}
+
+type RsCalendarResearcherQuestionSaveReq struct {
+	QuestionContent string `description:"提问内容"`
+	ReplyContent    string `description:"客户分类"`
+}
+
+func RoadShowQuestionSave(req *RoadShowQuestionSaveReq) (err error) {
+	o := orm.NewOrm()
+	tx, err := o.BeginWithCtx(context.Background())
+	if err != nil {
+		return err
+	}
+
+	sql := ` UPDATE rs_calendar_researcher SET company_industry = ?,company_classify = ?,question_status=1 WHERE rs_calendar_researcher_id = ? `
+	_, err = tx.Raw(sql, req.CompanyIndustry, req.CompanyClassify, req.RsCalendarResearcherId).Exec()
+	if err != nil {
+		return err
+	}
+	list := make([]*RsCalendarResearcherQuestion, 0)
+	for _, v := range req.QuestionList {
+		item := new(RsCalendarResearcherQuestion)
+		item.RsCalendarResearcherId = req.RsCalendarResearcherId
+		item.QuestionContent = v.QuestionContent
+		item.ReplyContent = v.ReplyContent
+		item.ModifyTime = time.Now()
+		item.CreateTime = time.Now()
+		list = append(list, item)
+	}
+	_, err = tx.InsertMulti(len(list), &list)
+	return err
+}
+
+func GetRoadShowQuestionList(rsCalendarResearcherId int) (item []*RsCalendarResearcherQuestion, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM rs_calendar_researcher_question WHERE rs_calendar_researcher_id = ? ORDER BY create_time DESC `
+	_, err = o.Raw(sql, rsCalendarResearcherId).QueryRows(&item)
+	return
+}