Browse Source

no message

xingzai 11 months ago
parent
commit
f7b0cb1f4b
1 changed files with 129 additions and 1 deletions
  1. 129 1
      controllers/cygx/enter_score.go

+ 129 - 1
controllers/cygx/enter_score.go

@@ -495,6 +495,7 @@ func (this *EnterScoreController) EnterScoreUpdate() {
 // @Param   KeyWord   query   string  true       "搜索关键词"
 // @Param   CompanyName   query   string  true       "客户名称"
 // @Param   AdminId   query   string  true       "销售id,多个用英文逗号隔开,空字符串为全部"
+// @Param   IsExport   query   bool  false       "是否导出excel,默认是false"
 // @Success 200 {object} cygx.GetCygxEnterScoreListRep
 // @router /enterScore/list [get]
 func (this *EnterScoreController) EnterScoreList() {
@@ -514,7 +515,8 @@ func (this *EnterScoreController) EnterScoreList() {
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	keyWord := this.GetString("KeyWord")
 	adminId := this.GetString("AdminId")
-
+	//是否导出报表
+	isExport, _ := this.GetBool("IsExport")
 	var startSize int
 	if pageSize <= 0 {
 		pageSize = utils.PageSize20
@@ -522,7 +524,12 @@ func (this *EnterScoreController) EnterScoreList() {
 	if currentIndex <= 0 {
 		currentIndex = 1
 	}
+	fmt.Println(isExport)
 	startSize = utils.StartIndex(currentIndex, pageSize)
+	if isExport {
+		startSize = 0
+		pageSize = 9999
+	}
 	var condition string
 	var pars []interface{}
 	//如果不是权益管理员和admin,就做可见权限限制
@@ -587,6 +594,11 @@ func (this *EnterScoreController) EnterScoreList() {
 			resp.List = append(resp.List, item)
 		}
 	}
+	//导出excel
+	if isExport {
+		EnterScoreScoreListExport(this, resp, br)
+		return
+	}
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp.Paging = page
 	br.Ret = 200
@@ -595,6 +607,122 @@ func (this *EnterScoreController) EnterScoreList() {
 	br.Data = resp
 }
 
+// EnterScoreScoreListExport 导出Excel
+func EnterScoreScoreListExport(this *EnterScoreController, resp *cygx.GetCygxEnterScoreListRep, br *models.BaseResponse) {
+	dir, err := os.Executable()
+	exPath := filepath.Dir(dir)
+	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	xlsxFile := xlsx.NewFile()
+	if err != nil {
+		br.Msg = "生成文件失败"
+		br.ErrMsg = "生成文件失败"
+		return
+	}
+	style := xlsx.NewStyle()
+	alignment := xlsx.Alignment{
+		Horizontal: "center",
+		Vertical:   "center",
+		WrapText:   true,
+	}
+
+	style.Alignment = alignment
+	style.ApplyAlignment = true
+
+	sheel, err := xlsxFile.AddSheet("录分记录")
+	if err != nil {
+		br.Msg = "新增Sheet失败"
+		br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
+		return
+	}
+	sheel.SetColWidth(0, 0, 30)
+	sheel.SetColWidth(1, 1, 15)
+	sheel.SetColWidth(2, 2, 15)
+	sheel.SetColWidth(3, 3, 18)
+
+	titleRow := sheel.AddRow()
+
+	cellA := titleRow.AddCell()
+	cellA.SetStyle(style)
+	cellA.SetValue("客户名称")
+
+	cellB := titleRow.AddCell()
+	cellB.SetStyle(style)
+	cellB.SetValue("销售")
+
+	cellC := titleRow.AddCell()
+	cellC.SetStyle(style)
+	cellC.SetValue("季度")
+
+	cellD := titleRow.AddCell()
+	cellD.SetStyle(style)
+	cellD.SetValue("总分")
+
+	cellE := titleRow.AddCell()
+	cellE.SetStyle(style)
+	cellE.SetValue("排名")
+
+	cellF := titleRow.AddCell()
+	cellF.SetStyle(style)
+	cellF.SetValue("合并打分")
+
+	cellG := titleRow.AddCell()
+	cellG.SetStyle(style)
+	cellG.SetValue("券商名称")
+
+	for _, v := range resp.List {
+		dataRow := sheel.AddRow()
+		dataRow.SetHeight(20)
+
+		cellA := dataRow.AddCell()
+		cellA.SetStyle(style)
+		cellA.SetValue(v.CompanyName)
+
+		cellB := dataRow.AddCell()
+		cellB.SetStyle(style)
+		cellB.SetValue(v.SellerName)
+
+		cellC := dataRow.AddCell()
+		cellC.SetStyle(style)
+		cellC.SetValue(strings.Join(v.Quarter, ","))
+
+		cellD := dataRow.AddCell()
+		cellD.SetStyle(style)
+		cellD.SetValue(v.ProportionTotal)
+
+		cellE := dataRow.AddCell()
+		cellE.SetStyle(style)
+		cellE.SetValue(v.Ranking)
+
+		cellF := dataRow.AddCell()
+		cellF.SetStyle(style)
+		if v.IsMergeScoring == 1 {
+			cellF.SetValue("是")
+		} else {
+			cellF.SetValue("否")
+		}
+
+		cellG := dataRow.AddCell()
+		cellG.SetStyle(style)
+		cellG.SetValue(v.SecuritiesFirmsName)
+
+	}
+	err = xlsxFile.Save(downLoadnFilePath)
+	if err != nil {
+		br.Msg = "保存文件失败"
+		br.ErrMsg = "保存文件失败"
+		return
+	}
+	randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
+	downloadFileName := "录分记录导出数据_" + randStr + ".xlsx"
+	this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
+	defer func() {
+		os.Remove(downLoadnFilePath)
+	}()
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "导出成功"
+}
+
 // @Title 删除录分
 // @Description 删除录分接口
 // @Param	request	body cygx.UpdateEnterScoreReq true "type json string"