Browse Source

新增问答统计

317699326@qq.com 1 week ago
parent
commit
bac3463895

+ 135 - 2
controllers/roadshow/calendar_researcher_question.go

@@ -2,10 +2,13 @@ package roadshow
 
 import (
 	"encoding/json"
+	"fmt"
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hz_crm_api/models"
 	"hongze/hz_crm_api/models/roadshow"
 	"hongze/hz_crm_api/utils"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -82,6 +85,7 @@ func (this *CalendarController) QuestionAdd() {
 // ResearcherList
 // @Title 获取路演客户问答信息接口
 // @Description 获取路演客户问答信息接口
+// @Param   RsCalendarId   query   int  true       "路演日历ID"
 // @Param   RsCalendarResearcherId   query   int  true       "路演研究员记录ID"
 // @Success 200 {object} roadshow.ResearcherGroup
 // @router /question/list [get]
@@ -91,12 +95,28 @@ func (this *CalendarController) QuestionList() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
+	rsCalendarId, _ := this.GetInt("RsCalendarId")
+
 	rsCalendarResearcherId, _ := this.GetInt("RsCalendarResearcherId")
-	if rsCalendarResearcherId <= 0 {
+	if rsCalendarResearcherId <= 0 && rsCalendarId <= 0 {
 		br.Msg = "参数错误!"
 		return
 	}
-	list, err := roadshow.GetRoadShowQuestionList(rsCalendarResearcherId)
+
+	var condition string
+	var pars []interface{}
+
+	if rsCalendarId > 0 {
+		condition += ` AND rs_calendar_id = ? `
+		pars = append(pars, rsCalendarId)
+	}
+
+	if rsCalendarResearcherId > 0 {
+		condition += ` AND rs_calendar_researcher_id = ? `
+		pars = append(pars, rsCalendarResearcherId)
+	}
+
+	list, err := roadshow.GetRoadShowQuestionList(condition, pars)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取失败!"
 		br.ErrMsg = "获取失败,Err:" + err.Error()
@@ -107,3 +127,116 @@ func (this *CalendarController) QuestionList() {
 	br.Msg = "获取成功"
 	br.Data = list
 }
+
+// @Title 获取客户路演问题汇总
+// @Description 获取客户路演问题汇总
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   StartDate   query   string  true       "开始日期"
+// @Param   EndDate   query   string  true       "结束日期"
+// @Param   ResearcherId   query   int  true       "研究员id"
+// @Param   CompanyId   query   int  true       "客户ID"
+// @Param   CompanyIndustry			query	string	false	"客户行业"
+// @Param   CompanyClassify			query	string	false	"客户分类"
+// @Param   Keyword			query	string	false	"关键词: 客户名称/社会信用码"
+// @Success 200 {object} roadshow.QuestionSummaryListResp
+// @router /question/summary/list [get]
+func (this *CalendarController) CalendarSummaryList() {
+	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
+	}
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	startDate := this.GetString("StartDate")
+	endDate := this.GetString("EndDate")
+	researcherId, _ := this.GetInt("ResearcherId")
+	companyIndustry := this.GetString("CompanyIndustry")
+	companyClassify := this.GetString("CompanyClassify")
+	keyword := this.GetString("Keyword")
+
+	var total int
+	page := paging.GetPaging(currentIndex, pageSize, total)
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize10
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+
+	var condition string
+	var pars []interface{}
+
+	condition += ` AND b.question_status = 1 `
+
+	if startDate != "" {
+		condition += ` AND b.start_date >= ?`
+		pars = append(pars, startDate)
+	}
+
+	if endDate != "" {
+		condition += ` AND b.start_date <= ?`
+		pars = append(pars, endDate)
+	}
+
+	if researcherId > 0 {
+		condition += ` AND b.researcher_id = ?`
+		pars = append(pars, researcherId)
+	}
+
+	if companyIndustry != "" {
+		condition += ` AND b.company_industry = ?`
+		pars = append(pars, companyIndustry)
+	}
+
+	if companyClassify != "" {
+		condition += ` AND b.company_classify = ?`
+		pars = append(pars, companyClassify)
+	}
+
+	keyword = strings.TrimSpace(keyword)
+	if keyword != "" {
+		kw := fmt.Sprint("%", keyword, "%")
+		condition += ` AND a.company_name LIKE ? `
+		pars = append(pars, kw)
+	}
+
+	total, err := roadshow.GetQuestionSummaryListCount(condition, pars)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取数据总数失败,GetQuestionSummaryListCount,Err:" + err.Error()
+		return
+	}
+
+	dataList, err := roadshow.GetQuestionSummaryList(condition, pars, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取指标信息失败"
+		br.ErrMsg = "获取数据失败,GetQuestionSummaryList,Err:" + err.Error()
+		return
+	}
+
+	page = paging.GetPaging(currentIndex, pageSize, total)
+
+	resp := new(roadshow.QuestionSummaryListResp)
+
+	resp.Paging = page
+	resp.List = dataList
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 181 - 0
controllers/roadshow/report.go

@@ -3,6 +3,7 @@ package roadshow
 import (
 	"encoding/json"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"github.com/tealeg/xlsx"
 	"hongze/hz_crm_api/models"
 	"hongze/hz_crm_api/models/company"
 	"hongze/hz_crm_api/models/cygx"
@@ -11,6 +12,8 @@ import (
 	"hongze/hz_crm_api/services"
 	roadshowService "hongze/hz_crm_api/services/roadshow"
 	"hongze/hz_crm_api/utils"
+	"os"
+	"path/filepath"
 	"strconv"
 	"strings"
 	"time"
@@ -1885,3 +1888,181 @@ func (this *CalendarController) OverseasCalendarList() {
 	br.Data = list
 	return
 }
+
+// @Title 导出研究员路演统计
+// @Description 导出研究员路演统计接口
+// @Param   DataType   query   string  true       "枚举值:week、month、time_interval"
+// @Param   StartDate   query   string  true       "开始日期,格式:2022-04-06"
+// @Param   EndDate   query   string  true       "结束日期,格式:2022-04-06"
+// @Param   CompanyType   query   string  true       "客户类型:'ficc','权益',传空默认为ficc,"
+// @Success 200 {object} roadshow.RsReportRecordResp
+// @router /report/researcher/export [get]
+func (this *CalendarController) ResearcherReportExport() {
+	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
+	}
+	dataType := this.GetString("DataType")
+	startDate := this.GetString("StartDate")
+	endDate := this.GetString("EndDate")
+	companyType := this.GetString("CompanyType", "ficc")
+
+	var err error
+	//获取列表
+	switch dataType {
+	case "week":
+		startDate = utils.GetNowWeekMonday().AddDate(0, 0, -7).Format(utils.FormatDate)
+		endDate = utils.GetNowWeekLastDay().AddDate(0, 0, 7).Format(utils.FormatDate)
+	case "month":
+		startDate = utils.GetNowMonthFirstDay().AddDate(0, -4, 0).Format(utils.FormatDate)
+		endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate)
+	case "time_interval":
+		if startDate == `` || endDate == `` {
+			br.Msg = "开始日期或结束日期不能为空"
+			br.ErrMsg = "开始日期或结束日期不能为空,Err:" + err.Error()
+			return
+		}
+	}
+
+	var researcherIdArr []string
+	ficcSellerMap := make(map[int]int)
+	//raiSellerMap := make(map[int]int)
+	switch companyType {
+	case utils.COMPANY_CLASSIFY_FICC:
+		researcherList, err := roadshow.GetResearcherV2()
+		if err != nil {
+			br.Msg = "获取信息失败!"
+			br.ErrMsg = "获取分组信息失败!,GetResearcherV2 Err:" + err.Error()
+			return
+		}
+		for _, v := range researcherList {
+			if v.AdminId > 0 {
+				researcherId := strconv.Itoa(v.AdminId)
+				researcherIdArr = append(researcherIdArr, researcherId)
+			}
+		}
+
+		_, groupIdRelationMap, err := services.GetFiccSystemGroup()
+		if err != nil {
+			br.Msg = "获取信息失败!"
+			br.ErrMsg = "获取FICC销售信息失败!Err:" + err.Error()
+			return
+		}
+		ficcSellerList, err := services.GetFiccSeller(time.Now(), groupIdRelationMap)
+		for _, v := range ficcSellerList {
+			ficcSellerMap[v.AdminId] = v.AdminId
+		}
+	case utils.COMPANY_CLASSIFY_RAI:
+		askUserList, err := cygx.GetAskEmailListResearcher()
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,GetAskEmailListResearcher Err: " + err.Error()
+			return
+		}
+		for _, v := range askUserList {
+			if v.AdminId > 0 {
+				researcherId := strconv.Itoa(v.AdminId)
+				researcherIdArr = append(researcherIdArr, researcherId)
+			}
+		}
+
+		//_, groupIdRelationMap, err := services.GetRaiSystemGroup()
+		//if err != nil {
+		//	br.Msg = "获取信息失败!"
+		//	br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
+		//	return
+		//}
+		//raiSellList, err := services.GetRaiSeller(groupIdRelationMap)
+		//if err != nil {
+		//	br.Msg = "获取信息失败!"
+		//	br.ErrMsg = "获取权益销售信息失败!Err:" + err.Error()
+		//	return
+		//}
+		//
+		//for _, v := range raiSellList {
+		//	raiSellerMap[v.AdminId] = v.AdminId
+		//}
+	}
+
+	var condition string
+	var pars []interface{}
+
+	condition += ` AND c.researcher_id IN(` + strings.Join(researcherIdArr, ",") + `) `
+	pars = append(pars, startDate, endDate)
+
+	if startDate != "" {
+		condition = ` AND c.start_date >= ? `
+		pars = append(pars, startDate)
+	}
+
+	if endDate != "" {
+		condition += ` AND c.start_date <= ? `
+		pars = append(pars, endDate)
+	}
+
+	list, err := roadshow.GetReportResearcherExport(condition, pars)
+	if err != nil {
+		br.Msg = "获取信息失败!"
+		br.ErrMsg = "获取数据失败!Err:" + err.Error()
+		return
+	}
+
+	dir, _ := os.Executable()
+	exPath := filepath.Dir(dir)
+	downloadPath := exPath + "/" + time.Now().Format(utils.FormatDateUnSpace) + "研究员已完成路演统计" + ".xlsx"
+	xlsxFile := xlsx.NewFile()
+	sheet, e := xlsxFile.AddSheet("已完成路演统计")
+	if e != nil {
+		br.Msg = "新增Sheet失败"
+		br.ErrMsg = "新增Sheet失败, Err: " + e.Error()
+		return
+	}
+
+	titleRow := sheet.AddRow()
+	titleRow.AddCell().SetString("研究员")
+	titleRow.AddCell().SetString("路演时间")
+	titleRow.AddCell().SetString("客户名称")
+	titleRow.AddCell().SetString("路演形式")
+	titleRow.AddCell().SetString("发起人")
+	titleRow.AddCell().SetString("客户类型")
+	titleRow.AddCell().SetString("客户状态")
+	titleRow.AddCell().SetString("客户行业")
+	titleRow.AddCell().SetString("客户分类")
+
+	for _, v := range list {
+		dataRow := sheet.AddRow()
+		dataRow.AddCell().SetString(v.ResearcherName)
+		dataRow.AddCell().SetString(v.StartDate + " " + v.StartTime)
+		dataRow.AddCell().SetString(v.CompanyName)
+		dataRow.AddCell().SetString(v.RoadshowType)
+		dataRow.AddCell().SetString(v.SellerName)
+		if _, ok := ficcSellerMap[v.SellerId]; ok {
+			dataRow.AddCell().SetString("FICC")
+		} else {
+			dataRow.AddCell().SetString("权益")
+		}
+		dataRow.AddCell().SetString(v.CompanyStatus)
+		dataRow.AddCell().SetString(v.CompanyIndustry)
+		dataRow.AddCell().SetString(v.CompanyClassify)
+	}
+
+	if e = xlsxFile.Save(downloadPath); e != nil {
+		br.Msg = "导出失败"
+		br.ErrMsg = "保存文件失败"
+		return
+	}
+	fileName := time.Now().Format(utils.FormatDateUnSpace) + "研究员已完成路演统计" + ".xlsx"
+	this.Ctx.Output.Download(downloadPath, fileName)
+	defer func() {
+		_ = os.Remove(downloadPath)
+	}()
+	return
+}

+ 100 - 3
models/roadshow/calendar_researcher_question.go

@@ -3,11 +3,13 @@ package roadshow
 import (
 	"context"
 	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"time"
 )
 
 type RsCalendarResearcherQuestion struct {
 	RsCalendarResearcherQuestionId int       `orm:"column(rs_calendar_researcher_question_id);pk"`
+	RsCalendarId                   int       `description:"路演日历ID"`
 	RsCalendarResearcherId         int       `description:"路演研究员记录ID"`
 	QuestionContent                string    `description:"提问内容"`
 	ReplyContent                   string    `description:"回复内容"`
@@ -51,6 +53,7 @@ func RoadShowQuestionSave(req *RoadShowQuestionSaveReq) (err error) {
 	list := make([]*RsCalendarResearcherQuestion, 0)
 	for _, v := range req.QuestionList {
 		item := new(RsCalendarResearcherQuestion)
+		item.RsCalendarId = req.RsCalendarId
 		item.RsCalendarResearcherId = req.RsCalendarResearcherId
 		item.QuestionContent = v.QuestionContent
 		item.ReplyContent = v.ReplyContent
@@ -62,9 +65,103 @@ func RoadShowQuestionSave(req *RoadShowQuestionSaveReq) (err error) {
 	return err
 }
 
-func GetRoadShowQuestionList(rsCalendarResearcherId int) (item []*RsCalendarResearcherQuestion, err error) {
+func GetRoadShowQuestionList(condition string, pars []interface{}) (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)
+	sql := `SELECT * FROM rs_calendar_researcher_question WHERE 1=1 `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY create_time DESC  `
+	_, err = o.Raw(sql, pars).QueryRows(&item)
+	return
+}
+
+type QuestionSummary struct {
+	RsCalendarId           int    `orm:"column(rs_calendar_id);pk"`
+	SysUserId              int    `description:"创建人id"`
+	SysUserRealName        string `description:"创建人名称"`
+	ActivityType           string `description:"活动类型"`
+	RoadshowType           string `description:"路演形式"`
+	RoadshowPlatform       string `description:"路演平台"`
+	CompanyId              int    `description:"客户id"`
+	CompanyName            string `description:"客户名称"`
+	RsCalendarResearcherId int    `description:"活动研究员id"`
+	ResearcherId           string `description:"研究员id"`
+	ResearcherName         string `description:"研究员名称"`
+	StartDate              string `description:"开始日期"`
+	EndDate                string `description:"结束日期"`
+	StartTime              string `description:"开始时间"`
+	EndTime                string `description:"结束时间"`
+	StartWeek              string `description:"开始日期对应周"`
+	EndWeek                string `description:"结束日期对应周"`
+	Status                 int    `description:"状态:1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束"`
+	RefuseReason           string `description:"拒绝理由"`
+	RefuseTime             string `description:"拒绝时间"`
+	DeleteReason           string `description:"删除原因"`
+	Province               string `description:"省"`
+	ProvinceCode           string `description:"省编码"`
+	City                   string `description:"市"`
+	CityCode               string `description:"市编码"`
+	District               string `description:"区"`
+	Theme                  string `description:"会议主题"`
+	CooperationName        string `description:"合作方名称"`
+	ActivityCategory       string `description:"活动类别"`
+	Source                 int    `description:"来源,0:自系统,1:上海方的"`
+	Title                  string `description:"日历展示标题"`
+	CompanyStatus          string `description:"新增客户状态"`
+	UnionCode              string `description:"公开会议联合编码"`
+	EnglishCompany         int    `description:"是否为英文客户: 0-否; 1-是"`
+	EnglishCountry         string `description:"英文客户-国家"`
+	EnglishViewTotal       int    `description:"英文客户-累计点击量"`
+	SubmitButton           bool   `description:"提交按钮是否展示"`
+	ViewButton             bool   `description:"查看按钮是否展示"`
+	EditButton             bool   `description:"修改按钮是否展示"`
+	CompanyIndustry        string `description:"客户行业"`
+	CompanyClassify        string `description:"客户分类"`
+	QuestionStatus         int    `description:"问答状态:0-未填写;1-已填写"`
+	QuestionMsgStatus      int    `description:"问答模板消息:0-未发送;1-已发送"`
+}
+
+type QuestionSummaryListResp struct {
+	Paging *paging.PagingItem
+	List   []*QuestionSummary
+}
+
+func GetQuestionSummaryListCount(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS count FROM(SELECT COUNT(1) AS count
+				FROM  rs_calendar AS a
+				INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
+				WHERE 1=1  `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` GROUP BY a.rs_calendar_id ) AS t `
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func GetQuestionSummaryList(condition string, pars []interface{}, startSize, pageSize int) (list []*QuestionSummary, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT a.rs_calendar_id,a.activity_type,a.roadshow_type,a.activity_category,a.roadshow_platform,b.create_time,a.district,
+				b.modify_time,GROUP_CONCAT(b.researcher_id ORDER BY researcher_sort ASC) AS researcher_id,GROUP_CONCAT(b.researcher_name ORDER BY researcher_sort ASC) AS researcher_name,
+				b.rs_calendar_researcher_id,b.start_date,
+				b.end_date,b.start_time,b.end_time,b.start_week,b.end_week,b.status,b.refuse_reason,b.refuse_time,
+                b.delete_reason,a.sys_user_real_name,a.city,a.province,a.company_name,a.company_id,
+                a.cooperation_name,a.theme,a.activity_category,a.english_company,
+                b.question_status,b.question_msg_status,
+ 				GROUP_CONCAT(b.company_industry) AS company_industry,
+ 				GROUP_CONCAT(b.company_classify) AS company_classify
+				FROM  rs_calendar AS a
+				INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
+				WHERE 1=1
+ `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` GROUP BY a.rs_calendar_id
+				 ORDER BY b.create_time DESC LIMIT ?,? `
+
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
 	return
 }

+ 16 - 0
models/roadshow/report_record.go

@@ -488,3 +488,19 @@ func UpdateRsReportRecordInteractionNumnMulti(items []*RsReportRecord) (err erro
 	}
 	return
 }
+
+func GetReportResearcherExport(condition string, pars []interface{}) (list []*RsReportRecordList, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT a.*,b.theme,b.roadshow_platform,b.province,b.city,b.cooperation_name,c.company_industry,c.company_classify,c.question_status,c.question_msg_status
+				FROM  rs_report_record a 
+				join rs_calendar b on a.rs_calendar_id=b.rs_calendar_id
+				inner join rs_calendar_researcher AS c ON a.rs_calendar_id=c.rs_calendar_id AND a.rs_calendar_researcher_id=c.rs_calendar_researcher_id
+				WHERE 1=1 and a.rs_calendar_researcher_status = 2 
+ `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` order BY a.start_date DESC,a.start_time DESC`
+	_, err = o.Raw(sql, pars).QueryRows(&list)
+	return
+}