|
@@ -0,0 +1,447 @@
|
|
|
+package data_source
|
|
|
+
|
|
|
+import (
|
|
|
+ "eta/eta_api/controllers"
|
|
|
+ "eta/eta_api/models"
|
|
|
+ "eta/eta_api/models/data_source"
|
|
|
+ "eta/eta_api/utils"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+)
|
|
|
+
|
|
|
+// 消费者价格指数
|
|
|
+type DataSourceIcpiController struct {
|
|
|
+ controllers.BaseAuthController
|
|
|
+}
|
|
|
+
|
|
|
+// ComTradeCountryList
|
|
|
+// @Title 获取居民消费价格指数分类
|
|
|
+// @Description 获取居民消费价格指数分类
|
|
|
+// @Success 200 {object} []data_manage.ComTradeCountryItem
|
|
|
+// @router /icpi/classify/list [get]
|
|
|
+func (this *DataSourceIcpiController) IcpiClassifyList() {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ icpiObj := new(data_source.BaseFromIcpiIndex)
|
|
|
+ classifyList, err := icpiObj.GetBaseFromIcpiClassifyAll()
|
|
|
+ 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 PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Param BaseFromIcpiClassifyId query int true "分类id"
|
|
|
+// @Param KeyWord query string true "关键词"
|
|
|
+// @Success 200 {object} data_source.BaseFromIcpiIndexView
|
|
|
+// @router /icpi/index/data [get]
|
|
|
+func (this *DataSourceIcpiController) IcpiData() {
|
|
|
+ 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")
|
|
|
+ var startSize int
|
|
|
+
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = utils.PageSize20
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ startSize = utils.StartIndex(currentIndex, pageSize)
|
|
|
+
|
|
|
+ baseFromIcpiClassifyId, _ := this.GetInt("BaseFromIcpiClassifyId")
|
|
|
+ if baseFromIcpiClassifyId < 0 {
|
|
|
+ br.Msg = "请选择分类"
|
|
|
+ br.ErrMsg = "请选择分类"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ keyword := this.GetString("KeyWord")
|
|
|
+
|
|
|
+ //获取指标
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+
|
|
|
+ if baseFromIcpiClassifyId >= 0 {
|
|
|
+ condition += ` AND base_from_icpi_classify_id=? `
|
|
|
+ pars = append(pars, baseFromIcpiClassifyId)
|
|
|
+ }
|
|
|
+
|
|
|
+ if keyword != "" {
|
|
|
+ condition += ` AND (index_code =? OR index_name LIKE ?) `
|
|
|
+ pars = append(pars, keyword)
|
|
|
+ pars = append(pars, "%"+keyword+"%")
|
|
|
+ }
|
|
|
+
|
|
|
+ icpiObj := new(data_source.BaseFromIcpiIndex)
|
|
|
+
|
|
|
+ baiinfoList, err := icpiObj.GetIcpiIndex(condition, pars)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取数据失败"
|
|
|
+ br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resultList := make([]*data_source.BaseFromIcpiIndexView, 0)
|
|
|
+ for _, v := range baiinfoList {
|
|
|
+ product := new(data_source.BaseFromIcpiIndexView)
|
|
|
+ product.BaseFromIcpiIndexId = v.BaseFromIcpiIndexId
|
|
|
+ product.IndexCode = v.IndexCode
|
|
|
+ product.IndexName = v.IndexName
|
|
|
+ product.Frequency = v.Frequency
|
|
|
+ product.ModifyTime = v.ModifyTime
|
|
|
+
|
|
|
+ total, err := icpiObj.GetIcpiIndexDataCount(v.IndexCode)
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
+ dataList, err := icpiObj.GetIcpiIndexData(v.IndexCode, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取数据失败"
|
|
|
+ br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if dataList == nil {
|
|
|
+ dataList = make([]*data_source.BaseFromIcpiDataView, 0)
|
|
|
+ }
|
|
|
+ product.DataList = dataList
|
|
|
+ product.Paging = page
|
|
|
+ resultList = append(resultList, product)
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resultList
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+//// ExportBaiinfoList
|
|
|
+//// @Title 导出ICPI数据
|
|
|
+//// @Description 导出ICPI数据
|
|
|
+//// @Param IndexName query string false "名称关键词"
|
|
|
+//// @Param IndexCode query string false "指标唯一编码"
|
|
|
+//// @Param ClassifyId query string true "分类"
|
|
|
+//// @Param Frequency query string true "频度"
|
|
|
+//// @Param UnitName query string false "单位"
|
|
|
+//// @Param ModifyTime query string false "更新时间"
|
|
|
+//// @Success 200 导出成功
|
|
|
+//// @router /export/icpiDataList [get]
|
|
|
+//func (this *DataSourceIcpiController) ExportIcpiDataList() {
|
|
|
+// br := new(models.BaseResponse).Init()
|
|
|
+// defer func() {
|
|
|
+// this.Data["json"] = br
|
|
|
+// this.ServeJSON()
|
|
|
+// }()
|
|
|
+//
|
|
|
+// sysUser := this.SysUser
|
|
|
+// if sysUser == nil {
|
|
|
+// br.Msg = "请重新登录"
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// //typeName := this.GetString("TypeName") //分类
|
|
|
+// //frequency := this.GetString("Frequency")
|
|
|
+//
|
|
|
+// indexCode := this.GetString("IndexCode") //指标唯一编码
|
|
|
+// classifyId, _ := this.GetInt("ClassifyId")
|
|
|
+// secNameList := make([]*models.EdbdataExportList, 0)
|
|
|
+//
|
|
|
+// dir, _ := os.Executable()
|
|
|
+// exPath := filepath.Dir(dir)
|
|
|
+//
|
|
|
+// downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
|
|
|
+// xlsxFile := xlsx.NewFile()
|
|
|
+//
|
|
|
+// if classifyId >= 0 && indexCode == "" {
|
|
|
+//
|
|
|
+// frequencies, err := data_manage.GetBaiinfoFrequency(classifyId)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("GetBaiinfoFrequency err:", err.Error())
|
|
|
+// utils.FileLog.Info("GetBaiinfoFrequency err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// for _, frequency := range frequencies {
|
|
|
+//
|
|
|
+// //获取指标
|
|
|
+// var pars []interface{}
|
|
|
+// pars = append(pars, classifyId)
|
|
|
+// pars = append(pars, frequency)
|
|
|
+// condition := " AND classify_id=? AND frequency=? "
|
|
|
+// secNameList, err := data_manage.GetBaiinfoIndex(condition, pars)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("获取数据失败,Err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if len(secNameList) <= 0 {
|
|
|
+// fmt.Println("secNameList长度为0")
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// var sheetNew *xlsx.Sheet
|
|
|
+// if *frequency == "" {
|
|
|
+// newFrequency := "无频度"
|
|
|
+// sheetNew, err = xlsxFile.AddSheet(newFrequency)
|
|
|
+// } else {
|
|
|
+// sheetNew, err = xlsxFile.AddSheet(*frequency)
|
|
|
+// }
|
|
|
+//
|
|
|
+// 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_manage.GetBaiinfoDataMaxCount(classifyId)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("获取指标最大数据量失败", err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// fmt.Println("dataMax:", dataMax)
|
|
|
+// setRowIndex := 6
|
|
|
+// for k, sv := range secNameList {
|
|
|
+// //获取数据
|
|
|
+// dataList, err := data_manage.GetBaiinfoIndexDataByCode(sv.IndexCode)
|
|
|
+// if err != nil {
|
|
|
+// br.Msg = "获取数据失败"
|
|
|
+// br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if len(dataList) > 0 {
|
|
|
+// windRow.AddCell().SetValue("Baiinfo")
|
|
|
+// secNameRow.AddCell().SetValue("指标名称")
|
|
|
+// indexCodeRow.AddCell().SetValue("指标ID")
|
|
|
+// frequencyRow.AddCell().SetValue("频率")
|
|
|
+// unitRow.AddCell().SetValue("单位")
|
|
|
+// lastModifyDateRow.AddCell().SetValue("更新时间")
|
|
|
+//
|
|
|
+// secNameRow.AddCell().SetValue(sv.IndexName)
|
|
|
+// indexCodeRow.AddCell().SetValue(sv.IndexCode)
|
|
|
+// frequencyRow.AddCell().SetValue(sv.Frequency)
|
|
|
+//
|
|
|
+// unitRow.AddCell().SetValue(sv.Unit)
|
|
|
+// lastModifyDateRow.AddCell().SetValue(sv.ModifyTime)
|
|
|
+//
|
|
|
+// 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().SetValue(dv.Value)
|
|
|
+// 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 {
|
|
|
+// frequencies, err := data_manage.GetBaiinfoFrequencyByCode(indexCode)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("GetBaiinfoFrequencyByCode err:", err.Error())
|
|
|
+// utils.FileLog.Info("GetBaiinfoFrequencyByCode err:" + err.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// for _, frequency := range frequencies {
|
|
|
+// //获取数据
|
|
|
+// dataList, err := data_manage.GetBaiinfoIndexDataByCode(indexCode)
|
|
|
+// if err != nil {
|
|
|
+// br.Msg = "获取数据失败"
|
|
|
+// br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if len(dataList) > 0 {
|
|
|
+// name := this.GetString("IndexName")
|
|
|
+// unit := this.GetString("UnitName")
|
|
|
+// modifyTime := this.GetString("ModifyTime")
|
|
|
+//
|
|
|
+// var sheet *xlsx.Sheet
|
|
|
+// if *frequency == "" {
|
|
|
+// newFrequency := "无频度"
|
|
|
+// sheet, err = xlsxFile.AddSheet(newFrequency)
|
|
|
+// } else {
|
|
|
+// sheet, err = xlsxFile.AddSheet(*frequency)
|
|
|
+// }
|
|
|
+//
|
|
|
+// if err != nil {
|
|
|
+// br.Msg = "新增Sheet失败"
|
|
|
+// br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// //获取指标数据
|
|
|
+// windRow := sheet.AddRow()
|
|
|
+// windRow.AddCell().SetValue("Baiinfo")
|
|
|
+// rowSecName := sheet.AddRow()
|
|
|
+// celSecName := rowSecName.AddCell()
|
|
|
+// celSecName.SetValue("指标名称")
|
|
|
+// cellSenName := rowSecName.AddCell()
|
|
|
+// cellSenName.SetValue(name)
|
|
|
+// indexCodeRow := sheet.AddRow()
|
|
|
+// indexCodeRow.AddCell().SetValue("指标ID")
|
|
|
+// indexCodeRow.AddCell().SetValue(indexCode)
|
|
|
+//
|
|
|
+// rowFrequency := sheet.AddRow()
|
|
|
+// celFrequency := rowFrequency.AddCell()
|
|
|
+// celFrequency.SetValue("频率")
|
|
|
+// cellFrequency := rowFrequency.AddCell()
|
|
|
+// cellFrequency.SetValue(*frequency)
|
|
|
+//
|
|
|
+// 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)
|
|
|
+// dataMax, err := data_manage.GetBaiinfoIndexDataCount(indexCode)
|
|
|
+// if err != nil {
|
|
|
+// br.Msg = "查询数量失败"
|
|
|
+// br.ErrMsg = "GetBaiinfoIndexDataCount,Err:" + err.Error()
|
|
|
+// return
|
|
|
+// }
|
|
|
+// 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().SetValue(dv.Value)
|
|
|
+// 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 := `Baiinfo数据`
|
|
|
+// 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"
|
|
|
+//
|
|
|
+//}
|