Browse Source

新增导出路演问题统计

317699326@qq.com 1 week ago
parent
commit
3a944e98aa

+ 181 - 7
controllers/roadshow/calendar_researcher_question.go

@@ -4,9 +4,12 @@ import (
 	"encoding/json"
 	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"github.com/tealeg/xlsx"
 	"hongze/hz_crm_api/models"
 	"hongze/hz_crm_api/models/roadshow"
 	"hongze/hz_crm_api/utils"
+	"os"
+	"path/filepath"
 	"strconv"
 	"strings"
 	"time"
@@ -107,12 +110,12 @@ func (this *CalendarController) QuestionList() {
 	var pars []interface{}
 
 	if rsCalendarId > 0 {
-		condition += ` AND rs_calendar_id = ? `
+		condition += ` AND a.rs_calendar_id = ? `
 		pars = append(pars, rsCalendarId)
 	}
 
 	if rsCalendarResearcherId > 0 {
-		condition += ` AND rs_calendar_researcher_id = ? `
+		condition += ` AND a.rs_calendar_researcher_id = ? `
 		pars = append(pars, rsCalendarResearcherId)
 	}
 
@@ -134,7 +137,7 @@ func (this *CalendarController) QuestionList() {
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Param   StartDate   query   string  true       "开始日期"
 // @Param   EndDate   query   string  true       "结束日期"
-// @Param   ResearcherId   query   int  true       "研究员id"
+// @Param   ResearcherId   query   string  true       "研究员id"
 // @Param   CompanyId   query   int  true       "客户ID"
 // @Param   CompanyIndustry			query	string	false	"客户行业"
 // @Param   CompanyClassify			query	string	false	"客户分类"
@@ -160,7 +163,7 @@ func (this *CalendarController) CalendarSummaryList() {
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	startDate := this.GetString("StartDate")
 	endDate := this.GetString("EndDate")
-	researcherId, _ := this.GetInt("ResearcherId")
+	researcherId := this.GetString("ResearcherId")
 	companyIndustry := this.GetString("CompanyIndustry")
 	companyClassify := this.GetString("CompanyClassify")
 	keyword := this.GetString("Keyword")
@@ -192,9 +195,8 @@ func (this *CalendarController) CalendarSummaryList() {
 		pars = append(pars, endDate)
 	}
 
-	if researcherId > 0 {
-		condition += ` AND b.researcher_id = ?`
-		pars = append(pars, researcherId)
+	if researcherId != "" {
+		condition += ` AND b.researcher_id IN(` + researcherId + `)`
 	}
 
 	if companyIndustry != "" {
@@ -240,3 +242,175 @@ func (this *CalendarController) CalendarSummaryList() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 导出客户路演问题汇总
+// @Description 导出客户路演问题汇总
+// @Param   StartDate   query   string  true       "开始日期"
+// @Param   EndDate   query   string  true       "结束日期"
+// @Param   ResearcherId   query   string  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/export [get]
+func (this *CalendarController) CalendarSummaryExport() {
+	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
+	}
+
+	startDate := this.GetString("StartDate")
+	endDate := this.GetString("EndDate")
+	researcherId := this.GetString("ResearcherId")
+	companyIndustry := this.GetString("CompanyIndustry")
+	companyClassify := this.GetString("CompanyClassify")
+	keyword := this.GetString("Keyword")
+
+	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 != "" {
+		condition += ` AND b.researcher_id IN(` + 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)
+	}
+
+	dataList, err := roadshow.GetQuestionSummaryExport(condition, pars)
+	if err != nil {
+		br.Msg = "获取指标信息失败"
+		br.ErrMsg = "获取数据失败,GetQuestionSummaryList,Err:" + err.Error()
+		return
+	}
+
+	var rsCalendarIdArr []string
+
+	for _, v := range dataList {
+		rsCalendarIdArr = append(rsCalendarIdArr, strconv.Itoa(v.RsCalendarId))
+	}
+
+	questionMap := make(map[int][]*roadshow.RsCalendarResearcherQuestionView)
+	var questionMax int
+
+	if len(rsCalendarIdArr) > 0 {
+		var questionCondition string
+		var questionPars []interface{}
+
+		condition += ` AND a.rs_calendar_id IN (` + strings.Join(rsCalendarIdArr, ",") + `) `
+
+		questionList, err := roadshow.GetRoadShowQuestionList(questionCondition, questionPars)
+		if err != nil {
+			br.Msg = "获取指标信息失败"
+			br.ErrMsg = "获取数据失败,GetRoadShowQuestionList,Err:" + err.Error()
+			return
+		}
+
+		for _, qv := range questionList {
+			if items, ok := questionMap[qv.RsCalendarId]; ok {
+				items = append(items, qv)
+				questionMap[qv.RsCalendarId] = items
+
+				if len(items) > questionMax {
+					questionMax = len(items)
+				}
+			} else {
+				items = make([]*roadshow.RsCalendarResearcherQuestionView, 0)
+				items = append(items, qv)
+				questionMap[qv.RsCalendarId] = items
+				if len(items) > questionMax {
+					questionMax = len(items)
+				}
+			}
+		}
+	}
+
+	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("客户分类")
+
+	for i := 1; i <= questionMax; i++ {
+		titleRow.AddCell().SetString("Q" + strconv.Itoa(i))
+		titleRow.AddCell().SetString("A" + strconv.Itoa(i))
+	}
+
+	for _, v := range dataList {
+		dataRow := sheet.AddRow()
+		dataRow.AddCell().SetString(v.StartDate + " " + v.StartTime)
+		dataRow.AddCell().SetString(v.CompanyName)
+		dataRow.AddCell().SetString(v.SysUserRealName)
+		dataRow.AddCell().SetString(v.ResearcherName)
+		dataRow.AddCell().SetString(v.CompanyIndustry)
+		dataRow.AddCell().SetString(v.CompanyClassify)
+		questionList := questionMap[v.RsCalendarId]
+		for _, qv := range questionList {
+			titleRow.AddCell().SetString(qv.QuestionContent)
+			titleRow.AddCell().SetString(qv.ReplyContent)
+		}
+	}
+
+	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)
+	}()
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}

+ 28 - 0
controllers/roadshow/company.go

@@ -10,6 +10,7 @@ import (
 	"hongze/hz_crm_api/utils"
 	"strconv"
 	"strings"
+	"time"
 )
 
 // @Title 我的日历列表
@@ -65,6 +66,7 @@ func (this *CalendarController) CompanySearch() {
 // @Param   EnglishCompany   query   int  true       "是否为英文客户"
 // @Param   CompanyType   query   string  true       "客户类型:'ficc','权益',传空默认为ficc,"
 // @Param   RsReportRecordId   query   int	  true       "路演统计Id"
+// @Param   SellerId   query   int	  true       "销售ID"
 // @Success 200 {object} roadshow.CompanyDetailView
 // @router /company/detail [get]
 func (this *CalendarController) CompanyDetail() {
@@ -91,6 +93,8 @@ func (this *CalendarController) CompanyDetail() {
 	englishCompany, _ := this.GetInt("EnglishCompany")
 	companyType := this.GetString("CompanyType")
 	rsReportRecordId, _ := this.GetInt("RsReportRecordId")
+	sellerId, _ := this.GetInt("SellerId")
+
 	productId := services.GetProductId(sysUser.RoleTypeCode)
 	if productId == 0 {
 		productId = 1
@@ -99,6 +103,30 @@ func (this *CalendarController) CompanyDetail() {
 	if companyType == utils.COMPANY_CLASSIFY_RAI {
 		productId = 2
 	}
+
+	ficcSellerMap := make(map[int]int)
+	//raiSellerMap := make(map[int]int)
+	_, 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
+	}
+
+	if _, ok := ficcSellerMap[sellerId]; ok {
+		if productId != 1 {
+			productId = 1
+		}
+	} else {
+		if productId != 2 {
+			productId = 2
+		}
+	}
+
 	detailView := new(roadshow.CompanyDetailView)
 	if englishCompany == 0 {
 		var companyStatus string

+ 21 - 0
controllers/roadshow/report.go

@@ -783,6 +783,27 @@ func (this *CalendarController) ReportCalendarList() {
 		br.ErrMsg = "获取失败,ERR:" + err.Error()
 		return
 	}
+
+	ficcSellerMap := make(map[int]int)
+	//raiSellerMap := make(map[int]int)
+	_, 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
+	}
+
+	for _, v := range list {
+		if _, ok := ficcSellerMap[v.SellerId]; ok {
+			v.CompanyType = "FICC"
+		} else {
+			v.CompanyType = "权益"
+		}
+	}
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 42 - 3
models/roadshow/calendar_researcher_question.go

@@ -65,13 +65,27 @@ func RoadShowQuestionSave(req *RoadShowQuestionSaveReq) (err error) {
 	return err
 }
 
-func GetRoadShowQuestionList(condition string, pars []interface{}) (item []*RsCalendarResearcherQuestion, err error) {
+type RsCalendarResearcherQuestionView 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:"回复内容"`
+	ResearcherId                   int    `description:"研究员ID"`
+	ResearcherName                 string `description:"研究员名称"`
+	CreateTime                     string `description:"创建时间"`
+	ModifyTime                     string `description:"更新时间"`
+}
+
+func GetRoadShowQuestionList(condition string, pars []interface{}) (item []*RsCalendarResearcherQuestionView, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM rs_calendar_researcher_question WHERE 1=1 `
+	sql := `SELECT a.*,b.researcher_id,b.researcher_name FROM rs_calendar_researcher_question AS a
+         LEFT JOIN rs_calendar_researcher AS b ON a.rs_calendar_researcher_id=b.rs_calendar_researcher_id
+         WHERE 1=1 `
 	if condition != "" {
 		sql += condition
 	}
-	sql += ` ORDER BY create_time DESC  `
+	sql += ` ORDER BY a.create_time DESC  `
 	_, err = o.Raw(sql, pars).QueryRows(&item)
 	return
 }
@@ -165,3 +179,28 @@ func GetQuestionSummaryList(condition string, pars []interface{}, startSize, pag
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
 	return
 }
+
+func GetQuestionSummaryExport(condition string, pars []interface{}) (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 `
+
+	_, err = o.Raw(sql, pars).QueryRows(&list)
+	return
+}

+ 1 - 0
models/roadshow/report_record.go

@@ -150,6 +150,7 @@ type RsReportRecordList struct {
 	CompanyClassify            string    `description:"客户分类"`
 	QuestionStatus             int       `description:"问答状态:0-未填写;1-已填写"`
 	QuestionMsgStatus          int       `description:"问答模板消息:0-未发送;1-已发送"`
+	CompanyType                string    `description:"客户类型:FICC/权益"`
 }
 
 // GetRsReportRecordList 获取路演统计详情返回数据

+ 9 - 0
routers/commentsRouter.go

@@ -7792,6 +7792,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/roadshow:CalendarController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/roadshow:CalendarController"],
+        beego.ControllerComments{
+            Method: "CalendarSummaryExport",
+            Router: `/question/summary/export`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/roadshow:CalendarController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/roadshow:CalendarController"],
         beego.ControllerComments{
             Method: "CalendarSummaryList",