123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727 |
- package data_manage
- import (
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/models/data_source"
- "eta/eta_api/utils"
- "fmt"
- "github.com/tealeg/xlsx"
- "os"
- "path/filepath"
- "strconv"
- "strings"
- "time"
- )
- // @Title 隆众数据分类
- // @Description 隆众数据分类接口
- // @Success 200 {object} data_manage.LzClassify
- // @router /lz/classify [get]
- func (this *EdbInfoController) LzClassify() {
- 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
- }
- classifyList, err := data_manage.GetLzSurveyClassify()
- if err != nil {
- br.Msg = "获取分类失败"
- br.ErrMsg = "获取分类失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = classifyList
- }
- // @Title 隆众数据频度
- // @Description 隆众数据频度接口
- // @Param BreedId query int true "分类id"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /lz/frequency [get]
- func (this *EdbInfoController) LzFrequency() {
- 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
- }
- breedId, _ := this.GetInt("BreedId")
- if breedId <= 0 {
- br.Msg = "分类id错误"
- br.ErrMsg = "分类id错误:breedId" + strconv.Itoa(breedId)
- return
- }
- frequencyList, err := data_manage.GetLzFrequencyByClassifyId(breedId)
- if err != nil {
- br.Msg = "获取频度失败"
- br.ErrMsg = "获取频度失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = frequencyList
- }
- // @Title 获取隆众数据
- // @Description 获取隆众数据接口
- // @Param BreedId query int true "分类id"
- // @Param Frequency query int true "频度"
- // @Success 200 {object} data_manage.LzFrequency
- // @router /lz/data [get]
- func (this *EdbInfoController) LzData() {
- 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
- }
- breedId, _ := this.GetInt("BreedId")
- if breedId <= 0 {
- br.Msg = "分类id错误"
- br.ErrMsg = "分类id错误:breedId" + strconv.Itoa(breedId)
- return
- }
- frequency, _ := this.GetInt("Frequency")
- if frequency <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "频度错误:frequency" + strconv.Itoa(frequency)
- return
- }
- //获取指标
- fmt.Println("breedId:", breedId)
- fmt.Println("frequency:", frequency)
- productList, err := data_manage.GetLongzhongSurveyProduct(breedId, frequency)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resultList := make([]*data_manage.LzProductList, 0)
- for _, v := range productList {
- fmt.Println(v.SurveyProductId)
- product := new(data_manage.LzProductList)
- product.SurveyProductId = v.SurveyProductId
- product.BreedName = v.BreedName
- product.QuotaName = v.SampleName + v.BreedName + v.Custom + v.QuotaName
- product.UnitName = v.UnitName
- product.SampleType = v.SampleType
- product.SampleName = v.SampleName
- product.Device = v.Device
- product.Frequency = v.Frequency
- product.Custom = v.Custom
- product.StartDate = v.StartDate
- product.EndDate = v.EndDate
- product.ModifyTime = v.ModifyTime.Format(utils.FormatDateTime)
- product.LzCode = v.LzCode
- dataList, err := data_manage.GetLongzhongSurveyProductData(v.SurveyProductId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- if dataList == nil {
- dataList = make([]*data_manage.LzProductData, 0)
- }
- product.DataList = dataList
- resultList = append(resultList, product)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resultList
- }
- // LzSearchList
- // @Title 隆众模糊搜索
- // @Description 隆众模糊搜索
- // @Param Keyword query string ture "关键字搜索"
- // @Success 200 {object} models.BaseResponse
- // @router /lz/search_list [get]
- func (this *EdbInfoController) LzSearchList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- //关键字
- keyword := this.GetString("Keyword")
- list, err := data_source.GetLzItemList(keyword)
- if err != nil {
- br.ErrMsg = "获取失败,Err:" + err.Error()
- br.Msg = "获取失败"
- return
- }
- resultList := make([]*data_manage.LzProductList, 0)
- for _, v := range list {
- product := new(data_manage.LzProductList)
- product.SurveyProductId = v.SurveyProductId
- product.BreedName = v.BreedName
- product.QuotaName = v.SampleName + v.BreedName + v.Custom + v.QuotaName
- product.UnitName = v.UnitName
- product.SampleType = v.SampleType
- product.SampleName = v.SampleName
- product.Device = v.Device
- product.Frequency = v.Frequency
- product.Custom = v.Custom
- product.StartDate = v.StartDate
- product.EndDate = v.EndDate
- product.ModifyTime = v.ModifyTime.Format(utils.FormatDateTime)
- product.LzCode = v.LzCode
- dataList, err := data_manage.GetLongzhongSurveyProductData(v.SurveyProductId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- if dataList == nil {
- dataList = make([]*data_manage.LzProductData, 0)
- }
- product.DataList = dataList
- resultList = append(resultList, product)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resultList
- }
- // ExportLzList
- // @Title 导出隆众数据
- // @Description 导出数据列表
- // @Param QuotaName query string false "名称关键词"
- // @Param LzCode query string false "指标唯一编码"
- // @Param BreedName query string true "分类"
- // @Param Frequency query string true "频度"
- // @Param UnitName query string false "单位"
- // @Param ModifyTime query string false "更新时间"
- // @Success 200 导出成功
- // @router /export/lzList [get]
- func (this *EdbInfoController) ExportLzList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- breedName := this.GetString("BreedName") //分类
- //frequency := this.GetString("Frequency")
- secNameList := make([]*models.EdbdataExportList, 0)
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- xlsxFile := xlsx.NewFile()
- frequencies, err := models.GetLzFrequency(breedName)
- if err != nil {
- fmt.Println("GetLzFrequency err:", err.Error())
- utils.FileLog.Info("GetLzFrequency err:" + err.Error())
- return
- }
- if breedName != "" {
- for _, frequency := range frequencies {
- //获取指标
- secNameList, err := models.GetLzSurveyProductByNameAndFrequency(breedName, *frequency)
- if err != nil {
- fmt.Println("获取数据失败,Err:" + err.Error())
- return
- }
- if len(secNameList) <= 0 {
- fmt.Println("secNameList长度为0")
- return
- }
- var frequencyName string
- if *frequency == 1 {
- frequencyName = "日度"
- } else if *frequency == 2 {
- frequencyName = "周度"
- } else if *frequency == 3 {
- frequencyName = "月度"
- } else if *frequency == 4 {
- frequencyName = "季度"
- } else if *frequency == 5 {
- frequencyName = "年度"
- } else if *frequency == 99 {
- frequencyName = "无固定频率"
- }
- singalDataMax, err := data_source.GetLongzhongSurveyDataMaxCountByFrequency(breedName, *frequency)
- if err != nil {
- fmt.Println("获取指标最大数据量失败", err.Error())
- return
- }
- if singalDataMax <= 0 {
- continue
- }
- sheetNew, err := xlsxFile.AddSheet(frequencyName)
- if err != nil {
- fmt.Println("新增Sheet失败", err.Error())
- return
- }
- //sheetNew.SetColWidth()
- //获取指标数据
- windRow := sheetNew.AddRow()
- secNameRow := sheetNew.AddRow()
- indexCodeRow := sheetNew.AddRow()
- frequencyRow := sheetNew.AddRow()
- unitRow := sheetNew.AddRow()
- lastModifyDateRow := sheetNew.AddRow()
- //获取分类下指标最大数据量
- dataMax, err := data_source.GetLongzhongSurveyDataMaxCount(breedName)
- if err != nil {
- fmt.Println("获取指标最大数据量失败", err.Error())
- return
- }
- setRowIndex := 6
- for k, sv := range secNameList {
- //获取数据
- dataList, err := data_source.GetLongzhongSurveyDataById(sv.SurveyProductId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if len(dataList) > 0 {
- windRow.AddCell().SetValue("隆众")
- secNameRow.AddCell().SetValue("指标名称")
- indexCodeRow.AddCell().SetValue("指标ID")
- frequencyRow.AddCell().SetValue("频率")
- unitRow.AddCell().SetValue("单位")
- lastModifyDateRow.AddCell().SetValue("更新时间")
- secNameRow.AddCell().SetValue(sv.SampleName + sv.BreedName + sv.Custom + sv.QuotaName)
- indexCodeRow.AddCell().SetValue(sv.LzCode)
- if sv.Frequency == 1 {
- frequencyRow.AddCell().SetValue("日度")
- } else if sv.Frequency == 2 {
- frequencyRow.AddCell().SetValue("周度")
- } else if sv.Frequency == 3 {
- frequencyRow.AddCell().SetValue("月度")
- } else if sv.Frequency == 4 {
- frequencyRow.AddCell().SetValue("季度")
- } else if sv.Frequency == 5 {
- frequencyRow.AddCell().SetValue("年度")
- } else if sv.Frequency == 99 {
- frequencyRow.AddCell().SetValue("无固定频率")
- }
- unitRow.AddCell().SetValue(sv.UnitName)
- lastModifyDateRow.AddCell().SetValue(sv.EndDate)
- windRow.AddCell()
- windRow.AddCell()
- secNameRow.AddCell()
- indexCodeRow.AddCell()
- frequencyRow.AddCell()
- unitRow.AddCell()
- lastModifyDateRow.AddCell()
- min := k * 3
- sheetNew.SetColWidth(min, min, 15)
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := setRowIndex + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- row.AddCell().SetFloat(dv.InputValue)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- }
- }
- } else {
- name := this.GetString("QuotaName")
- lzCode := this.GetString("LzCode") //指标唯一编码
- unit := this.GetString("UnitName")
- modifyTime := this.GetString("ModifyTime")
- frequency, _ := this.GetInt("Frequency")
- sheet, err := xlsxFile.AddSheet("指标")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- //获取指标数据
- windRow := sheet.AddRow()
- windRow.AddCell().SetValue("隆众")
- rowSecName := sheet.AddRow()
- celSecName := rowSecName.AddCell()
- celSecName.SetValue("指标名称")
- cellSenName := rowSecName.AddCell()
- cellSenName.SetValue(name)
- indexCodeRow := sheet.AddRow()
- indexCodeRow.AddCell().SetValue("指标ID")
- indexCodeRow.AddCell().SetValue(lzCode)
- rowFrequency := sheet.AddRow()
- celFrequency := rowFrequency.AddCell()
- celFrequency.SetValue("频率")
- if frequency == 1 {
- rowFrequency.AddCell().SetValue("日度")
- } else if frequency == 2 {
- rowFrequency.AddCell().SetValue("周度")
- } else if frequency == 3 {
- rowFrequency.AddCell().SetValue("月度")
- } else if frequency == 4 {
- rowFrequency.AddCell().SetValue("季度")
- } else if frequency == 5 {
- rowFrequency.AddCell().SetValue("年度")
- } else if frequency == 99 {
- rowFrequency.AddCell().SetValue("无固定频率")
- }
- rowUnit := sheet.AddRow()
- celUnit := rowUnit.AddCell()
- celUnit.SetValue("单位")
- cellUnit := rowUnit.AddCell()
- cellUnit.SetValue(unit)
- rowModifyDate := sheet.AddRow()
- rowModifyCell := rowModifyDate.AddCell()
- rowModifyCell.SetValue("更新时间")
- rowModifyCell = rowModifyDate.AddCell()
- rowModifyCell.SetValue(modifyTime)
- surveyProductId, err := data_source.GetLzProductIdByCode(lzCode)
- //获取数据
- dataList, err := data_source.GetLongzhongSurveyDataById(surveyProductId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- fmt.Println("len(dataList):", len(dataList))
- dataMax, err := data_source.GetLzSurveyDataMaxCountByProductId(surveyProductId)
- fmt.Println("dataMax:", dataMax)
- if len(dataList) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := 6 + n
- row := sheet.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range dataList {
- rowIndex := 6 + rk
- row := sheet.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- row.AddCell().SetFloat(dv.InputValue)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(dataList) < dataMax {
- dataLen := dataMax - len(dataList)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheet.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- //有指标无数据时先导出一遍空表
- sheet, err := xlsxFile.AddSheet("无数据")
- if err != nil {
- br.Msg = "新增Sheet失败"
- br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
- return
- }
- rowSecName := sheet.AddRow()
- celSecName := rowSecName.AddCell()
- celSecName.SetValue("")
- err = xlsxFile.Save(downLoadnFilePath)
- if err != nil {
- br.Msg = "保存文件失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- }
- fileName := `隆众数据`
- if len(secNameList) > 0 {
- fileName = secNameList[0].ClassifyName
- }
- fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
- this.Ctx.Output.Download(downLoadnFilePath, fileName)
- defer func() {
- os.Remove(downLoadnFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
- // ExportLzQuotasData
- // @Title 导出隆众多个指标数据
- // @Description 导出隆众多个指标数据
- // @Param BreedIds query string false "品种ID集合"
- // @Success 200 导出成功
- // @router /export/lzQuotasData [get]
- func (this *EdbInfoController) ExportLzQuotasData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请重新登录"
- return
- }
- breedIdsStr := this.GetString("BreedIds")
- breedIds := strings.Split(breedIdsStr, ",")
- if len(breedIds) <= 0 {
- br.Msg = "请选择品种"
- br.ErrMsg = "请选择品种"
- return
- }
- // 获取多个品种的指标信息
- quotaList, err := models.GetExportLzSurveyProductByBreedIds(breedIds)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取指标信息失败, Err: " + err.Error()
- return
- }
- // 获取多个品种的指标最大数据量
- quotaMaxCountList, err := data_source.GetExportLzSurveyDataMaxCount(breedIds)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "获取指标最大数据量失败, Err: " + err.Error()
- return
- }
- quotaMaxCountMatch := make(map[string]int)
- for i := 0; i < len(quotaMaxCountList); i++ {
- quotaMaxCountMatch[strconv.Itoa(quotaMaxCountList[i].BreedId)] = quotaMaxCountList[i].Count
- }
- // 获取多个品种对应的指标数据
- productIdDataMatch := make(map[int][]*data_source.LongzhongSurveyData)
- for i := 0; i < len(quotaList); i++ {
- var iniArr []*data_source.LongzhongSurveyData
- productIdDataMatch[quotaList[i].SurveyProductId] = iniArr
- }
- quotaDataList, err := data_source.GetExportLzSurveyDataByBreedIds(breedIds)
- for k, _ := range productIdDataMatch {
- var tmpArr []*data_source.LongzhongSurveyData
- for _, qd := range quotaDataList {
- if k == qd.SurveyProductId {
- tmpArr = append(tmpArr, qd)
- }
- }
- productIdDataMatch[k] = tmpArr
- }
- dir, _ := os.Executable()
- exPath := filepath.Dir(dir)
- downloadFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
- excelFile := xlsx.NewFile()
- frequencyMatch := map[int64]string{
- 1: "日度",
- 2: "周度",
- 3: "月度",
- 4: "季度",
- 5: "年度",
- 99: "无固定频率",
- }
- for i := 0; i < len(breedIds); i++ {
- breedId := breedIds[i]
- breedName := ""
- var breedQuotas []*models.LongzhongSurveyProduct
- for _, quota := range quotaList {
- if quota.BreedId == breedId {
- breedName = quota.BreedName
- breedQuotas = append(breedQuotas, quota)
- }
- }
- if len(breedQuotas) <= 0 {
- continue
- }
- sheetNew, err := excelFile.AddSheet(breedName)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "新增sheet失败, Err: " + err.Error()
- return
- }
- windRow := sheetNew.AddRow()
- secNameRow := sheetNew.AddRow()
- indexCodeRow := sheetNew.AddRow()
- frequencyRow := sheetNew.AddRow()
- unitRow := sheetNew.AddRow()
- lastModifyDateRow := sheetNew.AddRow()
- dataMax := quotaMaxCountMatch[breedId] // 最大数据量
- setRowIndex := 6
- for k, sv := range breedQuotas {
- // 指标信息
- windRow.AddCell().SetValue("隆众")
- secNameRow.AddCell().SetValue("指标名称")
- indexCodeRow.AddCell().SetValue("指标ID")
- frequencyRow.AddCell().SetValue("频率")
- unitRow.AddCell().SetValue("单位")
- lastModifyDateRow.AddCell().SetValue("更新时间")
- secNameRow.AddCell().SetValue(sv.SampleName + sv.BreedName + sv.Custom + sv.QuotaName)
- indexCodeRow.AddCell().SetValue(sv.LzCode)
- frequencyRow.AddCell().SetValue(frequencyMatch[sv.Frequency])
- unitRow.AddCell().SetValue(sv.UnitName)
- lastModifyDateRow.AddCell().SetValue(sv.EndDate)
- windRow.AddCell()
- windRow.AddCell()
- secNameRow.AddCell()
- indexCodeRow.AddCell()
- frequencyRow.AddCell()
- unitRow.AddCell()
- lastModifyDateRow.AddCell()
- min := k * 3
- sheetNew.SetColWidth(min, min, 15)
- // 指标数据
- quotaData := productIdDataMatch[sv.SurveyProductId]
- if len(quotaData) <= 0 {
- for n := 0; n < dataMax; n++ {
- rowIndex := setRowIndex + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- } else {
- endRowIndex := 0
- for rk, dv := range quotaData {
- rowIndex := setRowIndex + rk
- row := sheetNew.Row(rowIndex)
- displayDate, _ := time.Parse(utils.FormatDate, dv.DataTime)
- displayDateCell := row.AddCell()
- style := new(xlsx.Style)
- style.ApplyAlignment = true
- style.Alignment.WrapText = true
- displayDateCell.SetStyle(style)
- displayDateCell.SetDate(displayDate)
- row.AddCell().SetFloat(dv.InputValue)
- row.AddCell()
- endRowIndex = rowIndex
- }
- if len(quotaData) < dataMax {
- dataLen := dataMax - len(quotaData)
- for n := 0; n < dataLen; n++ {
- rowIndex := (endRowIndex + 1) + n
- row := sheetNew.Row(rowIndex)
- row.AddCell()
- row.AddCell()
- row.AddCell()
- }
- }
- }
- }
- }
- err = excelFile.Save(downloadFilePath)
- if err != nil {
- br.Msg = "导出失败"
- br.ErrMsg = "保存文件失败"
- return
- }
- fileName := `隆众数据`
- fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
- this.Ctx.Output.Download(downloadFilePath, fileName)
- defer func() {
- os.Remove(downloadFilePath)
- }()
- br.Ret = 200
- br.Success = true
- br.Msg = "success"
- }
|