Pārlūkot izejas kodu

Merge branch 'ETA_1.13' into debug

ziwen 1 gadu atpakaļ
vecāks
revīzija
f2bb2dd441

+ 45 - 0
controllers/meeting_probabilities.go

@@ -0,0 +1,45 @@
+package controllers
+
+import (
+	"eta/eta_api/models"
+)
+
+// MeetingProbabilitiesController 加息概率
+type MeetingProbabilitiesController struct {
+	BaseAuthController
+}
+
+// Detail
+// @Title 获取表格详情
+// @Description 获取表格详情接口
+// @Param   ExcelInfoId   query   int  true       "表格id"
+// @Success 200 {object} data_manage.ExcelInfo
+// @router /detail [get]
+func (c *MeetingProbabilitiesController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+	sysUser := c.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	date := c.GetString("DateTime")
+
+	// 获取数据详情bu
+	excelDetail, err := models.GetMeetingInfoById(date)
+	if err != nil {
+		br.ErrMsg = err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = excelDetail
+}

+ 35 - 0
models/data_manage/request/meeting_probabilities.go

@@ -0,0 +1,35 @@
+package request
+
+type ISheet struct {
+	ScrollTop                int                 `json:"scrollTop"`
+	ScrollLeft               int                 `json:"scrollLeft"`
+	Index                    string              `json:"index"`
+	Status                   int                 `json:"status"`
+	JfGirdSelectSave         []struct{}          `json:"jfgird_select_save"`
+	LuckySheetSelectSave     []struct{}          `json:"luckysheet_select_save"`
+	Data                     [][]interface{}     `json:"data"`
+	Config                   map[string]struct{} `json:"config"`
+	VisibleDataRow           []int               `json:"visibledatarow"`
+	VisibleDataColumn        []int               `json:"visibledatacolumn"`
+	ChWidth                  int                 `json:"ch_width"`
+	RhHeight                 int                 `json:"rh_height"`
+	LuckySheetSelectionRange []int               `json:"luckysheet_selection_range"`
+	ZoomRatio                int                 `json:"zoomRatio"`
+	CellData                 []ISheetCellData    `json:"celldata"`
+}
+type ISheetData struct {
+	M  string       `json:"m"`
+	Ct ISheetDataCt `json:"ct"`
+	V  string       `json:"v"`
+}
+
+type ISheetDataCt struct {
+	Fa string `json:"fa"`
+	T  string `json:"t"`
+}
+
+type ISheetCellData struct {
+	R int        `json:"r"`
+	C int        `json:"c"`
+	V ISheetData `json:"v"`
+}

+ 31 - 0
models/meeting_probabilities.go

@@ -0,0 +1,31 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// MeetingProbabilities 加息表格详情表
+type MeetingProbabilities struct {
+	MeetingInfoId int    `orm:"column(meeting_info_id);pk"`
+	DateTime      string // 数据日期
+	Content       string // 表格内容
+	FileUrl       string // excel下载地址
+	ExcelImage    string // 表格图片
+	IsDelete      int    // 是否删除,0:未删除,1:已删除
+	CreateTime    time.Time
+	ModifyTime    time.Time
+}
+
+// GetMeetingInfoById 根据id 获取加息概率表格详情
+func GetMeetingInfoById(dateTime string) (item *MeetingProbabilities, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ``
+	if dateTime == "" {
+		sql = ` SELECT * FROM meeting_probabilities WHERE is_delete=0 ORDER BY create_time DESC LIMIT 1 `
+	} else {
+		sql = ` SELECT * FROM meeting_probabilities WHERE date_time=? AND is_delete=0 `
+	}
+	err = o.Raw(sql, dateTime).QueryRow(&item)
+	return
+}

+ 9 - 0
routers/commentsRouter.go

@@ -4804,6 +4804,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers:MeetingProbabilitiesController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:MeetingProbabilitiesController"],
+        beego.ControllerComments{
+            Method: "Detail",
+            Router: `/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers:OutLinkController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers:OutLinkController"],
         beego.ControllerComments{
             Method: "AllList",

+ 153 - 0
services/meeting_probabilities.go

@@ -0,0 +1,153 @@
+package services
+
+import (
+	"encoding/json"
+	"eta/eta_api/models/data_manage"
+	"eta/eta_api/models/data_manage/request"
+	"eta/eta_api/utils"
+	"fmt"
+	"github.com/xuri/excelize/v2"
+	"strconv"
+	"time"
+)
+
+func MeetingProbabilities() (err error) {
+	templatePath := "/Users/xiexiaoyuan/1111.xlsx"
+	f, tmpErr := excelize.OpenFile(templatePath)
+	if tmpErr != nil {
+		fmt.Println("打开文件失败,Err:" + tmpErr.Error())
+		err = tmpErr
+		return
+	}
+	defer func() {
+		// 关闭工作簿
+		if err := f.Close(); err != nil {
+			fmt.Println(err)
+		}
+	}()
+	// 获取工作表中指定单元格的值
+	cell, err := f.GetCellValue("Sheet1", "B5")
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	fmt.Println(cell)
+	// 获取 Sheet1 上所有单元格
+	rows, err := f.GetRows("Sheet1")
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	minCowLength := 60
+	minRowlength := 84
+	realCowLength := minCowLength
+	realRowLength := minRowlength
+	data := make([][]interface{}, 0)
+	var null []struct{}
+	cellData := make([]request.ISheetCellData, 0)
+	var tmpCt request.ISheetDataCt
+	tmpCt.Fa = "General"
+	tmpCt.T = "g"
+
+	for r, row := range rows {
+		lenCow := len(row)
+		var dataRow []interface{}
+		for c, colCell := range row {
+			if colCell == "" {
+				dataRow = append(dataRow, null)
+			} else {
+				var tmp request.ISheetData
+				tmp.M = colCell
+				tmp.Ct = tmpCt
+				tmp.V = colCell
+				dataRow = append(dataRow, tmp)
+
+				var tmpS request.ISheetCellData
+				tmpS.R = r
+				tmpS.C = c
+				tmpS.V = tmp
+				cellData = append(cellData, tmpS)
+			}
+			fmt.Print(colCell, "\t")
+		}
+		if lenCow < minCowLength {
+			lastCow := minCowLength - lenCow
+			for i := 0; i < lastCow; i++ {
+				dataRow = append(dataRow, null)
+			}
+		}
+		realCowLength = len(dataRow)
+		data = append(data, dataRow)
+	}
+	lenRow := len(rows)
+	//补充剩余的单元格
+	if lenRow < minRowlength {
+		lastRow := minRowlength - lenRow
+		for i := 0; i < lastRow; i++ {
+			var dataRow []interface{}
+			for j := 0; j < minCowLength; j++ {
+				dataRow = append(dataRow, null)
+			}
+			data = append(data, dataRow)
+		}
+	}
+	realRowLength = len(data)
+	//visibleDataRow
+	var visibleDataRow []int
+	tmpVdr := 0
+	for i := 1; i <= realRowLength; i++ {
+		tmpVdr = i * 20
+		visibleDataRow = append(visibleDataRow, tmpVdr)
+	}
+	var visibleDataColumn []int
+	tmpVdr = 0
+	for i := 1; i <= realCowLength; i++ {
+		tmpVdr = i * 74
+		visibleDataColumn = append(visibleDataColumn, tmpVdr)
+	}
+	sheet := new(request.ISheet)
+	sheet.ScrollTop = 0
+	sheet.ScrollLeft = 0
+	sheet.Index = "Sheet_pekSifat0Kci_1694244624851"
+	sheet.Status = 1
+	sheet.JfGirdSelectSave = []struct{}{}
+	sheet.LuckySheetSelectSave = []struct{}{}
+	sheet.Data = data
+	sheet.Config = make(map[string]struct{}, 0)
+	sheet.VisibleDataRow = visibleDataRow
+	sheet.VisibleDataColumn = visibleDataColumn
+	sheet.ChWidth = 4560
+	sheet.RhHeight = 1760
+	sheet.LuckySheetSelectionRange = make([]int, 0)
+	sheet.ZoomRatio = 1
+	sheet.CellData = cellData
+
+	var content []byte
+	content, err = json.Marshal(sheet)
+	if err != nil {
+		return
+	}
+	var req request.AddExcelInfoReq
+	req.ExcelClassifyId = 19
+	timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
+	req.ExcelName = "Meeting" + timestamp
+	excelInfo := &data_manage.ExcelInfo{
+		//ExcelInfoId:     0,
+		ExcelName:       req.ExcelName,
+		Source:          1,
+		ExcelType:       req.ExcelType,
+		UniqueCode:      utils.MD5(utils.EXCEL_DATA_PREFIX + "_" + timestamp),
+		ExcelClassifyId: req.ExcelClassifyId,
+		SysUserId:       19,
+		SysUserRealName: "admin",
+		Content:         string(content),
+		ExcelImage:      req.ExcelImage,
+		Sort:            0,
+		IsDelete:        0,
+		ModifyTime:      time.Now(),
+		CreateTime:      time.Now(),
+	}
+
+	err = data_manage.AddExcelInfo(excelInfo)
+	return
+}