|
@@ -6,6 +6,7 @@ import (
|
|
|
"errors"
|
|
|
"eta/eta_api/models"
|
|
|
"eta/eta_api/models/company"
|
|
|
+ "eta/eta_api/models/data_manage/excel"
|
|
|
"eta/eta_api/models/report"
|
|
|
"eta/eta_api/models/report_approve"
|
|
|
"eta/eta_api/models/system"
|
|
@@ -121,6 +122,11 @@ func AddReportAndChapter(reportInfo *models.Report, inheritReportId int, grantAd
|
|
|
go models.ModifyReportCode(reportId, reportCode)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ if reportInfo.InheritReportId > 0 {
|
|
|
+ handlerReportTableReferenced(reportInfo)
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
go handleReportPermission(reportId, minClassifyId)
|
|
|
|
|
@@ -1477,6 +1483,51 @@ func handleReportPermission(reportId int64, minClassifyId int) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func handlerReportTableReferenced(reportInfo *models.Report) {
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Error("报告表关联处理失败,旧报告ID:%d,新报告ID:%d,Err:%s", reportInfo.InheritReportId, reportInfo.Id, err.Error())
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ addList, err := excel.CopyReferencedExcelConfigByReferencedIdAndFromScene(reportInfo.InheritReportId, utils.TableReferencedByReport, reportInfo.Id, utils.TableReferencedByReport, reportInfo.AdminId, reportInfo.AdminRealName)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(addList) > 0 {
|
|
|
+
|
|
|
+ reportInfo.Content = HandleReportContentTable(reportInfo.Id, reportInfo.Content)
|
|
|
+ reportInfo.ContentStruct = HandleReportContentStructTable(reportInfo.Id, reportInfo.ContentStruct)
|
|
|
+ err = reportInfo.Update([]string{"Content", "ContentStruct"})
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if reportInfo.HasChapter == 1 {
|
|
|
+ chapterList, tmpErr := models.GetChapterListByReportId(reportInfo.Id)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range chapterList {
|
|
|
+ v.Content = HandleReportContentTable(reportInfo.Id, v.Content)
|
|
|
+ v.ContentStruct = HandleReportContentStructTable(reportInfo.Id, v.ContentStruct)
|
|
|
+ err = v.Update([]string{"Content", "ContentStruct"})
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -1716,6 +1767,150 @@ func ResetMiniProgramReportDetailCover(reportId int) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func HandleReportContentTable(reportId int, body string) (newBody string) {
|
|
|
+ if body == `` {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newBody = body
|
|
|
+
|
|
|
+
|
|
|
+ doc, err := html2.Parse(strings.NewReader(body))
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error parsing HTML:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ replaceIframeSrcTable(doc, reportId)
|
|
|
+
|
|
|
+
|
|
|
+ var modifiedHtml strings.Builder
|
|
|
+ err = html2.Render(&modifiedHtml, doc)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error rendering HTML:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ newBody = modifiedHtml.String()
|
|
|
+ fmt.Println(newBody)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func replaceIframeSrcTable(n *html2.Node, reportId int) {
|
|
|
+ if n.Type == html2.ElementNode && n.Data == "iframe" {
|
|
|
+ for i, attr := range n.Attr {
|
|
|
+ if attr.Key == "src" {
|
|
|
+ newLink := handleTableLinkReportId(attr.Val, reportId)
|
|
|
+
|
|
|
+ n.Attr[i].Val = newLink
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for c := n.FirstChild; c != nil; c = c.NextSibling {
|
|
|
+ replaceIframeSrcTable(c, reportId)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func handleTableLinkReportId(link string, reportId int) string {
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("处理链接失败,ERR:" + err.Error())
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ parsedURL, err := url.Parse(link)
|
|
|
+ if err != nil {
|
|
|
+ return link
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ queryParams := parsedURL.Query()
|
|
|
+
|
|
|
+
|
|
|
+ queryParams.Del("sourceId")
|
|
|
+
|
|
|
+ queryParams.Add("sourceId", fmt.Sprint(reportId))
|
|
|
+
|
|
|
+
|
|
|
+ return parsedURL.String()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func HandleReportContentStructTable(reportId int, body string) (newBody string) {
|
|
|
+ if body == `` {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newBody = body
|
|
|
+
|
|
|
+
|
|
|
+ var jsonData []map[string]interface{}
|
|
|
+ if err := json.Unmarshal([]byte(body), &jsonData); err != nil {
|
|
|
+ fmt.Println("Error parsing JSON:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for i := range jsonData {
|
|
|
+ if err := processMapTable(jsonData[i], reportId); err != nil {
|
|
|
+ fmt.Println("Error processing component:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ modifiedJSON, err := json.MarshalIndent(jsonData, "", " ")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("Error marshaling JSON:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newBody = string(modifiedJSON)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func processMapTable(data map[string]interface{}, reportId int) error {
|
|
|
+ for key, value := range data {
|
|
|
+ switch v := value.(type) {
|
|
|
+ case string:
|
|
|
+ if key == "content" {
|
|
|
+ newContent := handleTableLinkReportId(v, reportId)
|
|
|
+ data[key] = newContent
|
|
|
+ }
|
|
|
+ case map[string]interface{}:
|
|
|
+ if err := processMapTable(v, reportId); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ case []interface{}:
|
|
|
+ for i := range v {
|
|
|
+ if m, ok := v[i].(map[string]interface{}); ok {
|
|
|
+ if err := processMapTable(m, reportId); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
|