package services import ( "encoding/json" "errors" "fmt" "hongze/hongze_ETA_mobile_api/models" "hongze/hongze_ETA_mobile_api/models/ppt_english" "hongze/hongze_ETA_mobile_api/services/alarm_msg" "hongze/hongze_ETA_mobile_api/utils" "sort" ) const ( ElementsTypeText = "text" ElementsTypeImage = "image" ElementsTypeChart = "chart" ElementsTypeSheet = "sheet" ) type PPTContent struct { //Id int `json:"id" description:"此处因目录改版类型有int也有string且并没有使用到该字段所以注释掉"` Key int `json:"key"` ModelId int `json:"modelId"` Title string `json:"title"` Elements []PPTContentElements `json:"elements"` } type PPTContentElements struct { Type string `json:"type"` Position int `json:"position"` Content string `json:"content"` RichContent string `json:"richContent"` ChartId string `json:"chartId"` SheetId string `json:"sheetId"` SheetHeight string `json:"sheetHeight"` Src string `json:"src"` } // PPT2内容转HTML func pptContent2Html(content string, isEnglish bool) (htm string, err error) { contents := make([]PPTContent, 0) if e := json.Unmarshal([]byte(content), &contents); e != nil { err = errors.New("PPT内容转换失败") return } pageLen := len(contents) htmlContent := `` // iframe图表/表格域名 chartRoot := `https://chartlib.hzinsights.com` if utils.RunMode == "debug" { chartRoot = `https://charttest.hzinsights.com` } if pageLen > 0 { htmlPrefix := `
` htmlSuffix := `
` htmlBr := `` htmlContent += title htmlContent += `
` } ele := contents[i].Elements // 每页元素按照Position升序排序 sort.Slice(ele, func(k, j int) bool { return ele[k].Position < ele[j].Position }) for _, v := range ele { // 根据不同的Type拼接不同的内容 htmlContent += htmlPrefix switch v.Type { case ElementsTypeText: htmlContent += v.RichContent case ElementsTypeImage: htmlContent += fmt.Sprint(`