123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- package services
- import (
- "context"
- "encoding/json"
- "eta/eta_crawler/models"
- "eta/eta_crawler/services/alarm_msg"
- "eta/eta_crawler/utils"
- "fmt"
- "github.com/xuri/excelize/v2"
- "time"
- )
- func RefreshMeetingProbabilities(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshMeetingProbabilities Err:" + err.Error())
- msg := "失败提醒" + "RefreshMeetingProbabilities ErrMsg:" + err.Error()
- go alarm_msg.SendAlarmMsg(msg, 3)
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCoalJsm ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- }
- }()
- templatePath := "./static/%s.xlsx"
- //templatePath := "/Users/xi/Desktop/%s.xlsx"
- templatePath = fmt.Sprintf(templatePath, time.Now().Format(utils.FormatDate))
- fmt.Println(templatePath)
- 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("MEETING PROBABILITIES", "B5")
- if err != nil {
- fmt.Println("GetCellValue err:" +err.Error())
- return
- }
- fmt.Println(cell)
- // 获取 Sheet1 上所有单元格
- rows, err := f.GetRows("MEETING PROBABILITIES")
- if err != nil {
- fmt.Println("GetRows err:" +err.Error())
- fmt.Println(err)
- return
- }
- minCowLength := 60
- minRowlength := 84
- realCowLength := minCowLength
- realRowLength := minRowlength
- data := make([][]interface{}, 0)
- var null []struct{}
- cellData := make([]models.ISheetCellData, 0)
- var tmpCt models.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 models.ISheetData
- tmp.M = colCell
- tmp.Ct = tmpCt
- tmp.V = colCell
- dataRow = append(dataRow, tmp)
- var tmpS models.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(models.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 models.AddExcelInfoReq
- excelInfo := &models.MeetingProbabilities{
- //MeetingInfoId: 0,
- Content: string(content),
- ExcelImage: req.ExcelImage,
- DateTime: time.Now().Format(utils.FormatDate),
- IsDelete: 0,
- ModifyTime: time.Now(),
- CreateTime: time.Now(),
- }
- err = models.AddMeetingProbabilities(excelInfo)
- return
- }
|