递归生成文档序列数组.
(parentId int, prefix, dpath string, this *DocumentController, book *models.BookResult, docs []*models.Document, paths *list.List)
| 1698 | |
| 1699 | // 递归生成文档序列数组. |
| 1700 | func RecursiveFun(parentId int, prefix, dpath string, this *DocumentController, book *models.BookResult, docs []*models.Document, paths *list.List) { |
| 1701 | for _, item := range docs { |
| 1702 | if item.ParentId == parentId { |
| 1703 | name := prefix + strconv.Itoa(item.ParentId) + strconv.Itoa(item.OrderSort) + strconv.Itoa(item.DocumentId) |
| 1704 | fpath := dpath + "/" + name + ".html" |
| 1705 | paths.PushBack(fpath) |
| 1706 | |
| 1707 | f, err := os.OpenFile(fpath, os.O_CREATE|os.O_RDWR, 0777) |
| 1708 | |
| 1709 | if err != nil { |
| 1710 | beego.Error(err) |
| 1711 | this.Abort("404") |
| 1712 | } |
| 1713 | |
| 1714 | html, err := this.ExecuteViewPathTemplate("document/export.html", map[string]interface{}{"Model": book, "Lists": item, "BaseUrl": this.BaseUrl()}) |
| 1715 | if err != nil { |
| 1716 | f.Close() |
| 1717 | beego.Error(err) |
| 1718 | this.Abort("404") |
| 1719 | } |
| 1720 | |
| 1721 | buf := bytes.NewReader([]byte(html)) |
| 1722 | doc, _ := goquery.NewDocumentFromReader(buf) |
| 1723 | doc.Find("img").Each(func(i int, contentSelection *goquery.Selection) { |
| 1724 | if src, ok := contentSelection.Attr("src"); ok && strings.HasPrefix(src, "/uploads/") { |
| 1725 | contentSelection.SetAttr("src", this.BaseUrl()+src) |
| 1726 | } |
| 1727 | }) |
| 1728 | html, err = doc.Html() |
| 1729 | |
| 1730 | if err != nil { |
| 1731 | f.Close() |
| 1732 | beego.Error(err) |
| 1733 | this.Abort("404") |
| 1734 | } |
| 1735 | //html = strings.Replace(html, "<img src=\"/uploads", "<img src=\""+this.BaseUrl()+"/uploads", -1) |
| 1736 | |
| 1737 | f.WriteString(html) |
| 1738 | f.Close() |
| 1739 | |
| 1740 | for _, sub := range docs { |
| 1741 | if sub.ParentId == item.DocumentId { |
| 1742 | RecursiveFun(item.DocumentId, name, dpath, this, book, docs, paths) |
| 1743 | break |
| 1744 | } |
| 1745 | } |
| 1746 | } |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | // |
nothing calls this directly
no test coverage detected