|
@@ -19,9 +19,13 @@ import (
|
|
|
"hongze/hongze_mobile_admin/models/tables/contract_template"
|
|
|
"hongze/hongze_mobile_admin/utils"
|
|
|
"html/template"
|
|
|
+ "os"
|
|
|
+ "os/exec"
|
|
|
+ "path"
|
|
|
"reflect"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
type TableData struct {
|
|
@@ -569,21 +573,27 @@ func GetHtmlByContractDetail(contractDetail *contract.ContractDetail, htmlType s
|
|
|
|
|
|
|
|
|
{
|
|
|
-
|
|
|
- newDecimal := decimal.NewFromFloat(contractDetail.EndDate.Sub(contractDetail.StartDate).Hours())
|
|
|
-
|
|
|
- newDecimal2 := decimal.NewFromInt(24 * 365)
|
|
|
-
|
|
|
- numYearDecimal := newDecimal.Div(newDecimal2).Round(1)
|
|
|
-
|
|
|
- minDecimal := decimal.NewFromFloat(0.1)
|
|
|
-
|
|
|
- if numYearDecimal.LessThan(minDecimal) {
|
|
|
- numYearDecimal = minDecimal
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ tmpPrintContent, tmpErr := CalculationDate(contractDetail.StartDate, contractDetail.EndDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- data.NumYear = numYearDecimal.String()
|
|
|
+ data.NumYear = tmpPrintContent
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1056,6 +1066,726 @@ func getColList(item *contract_service_detail.ContractServiceDetail) (cellList [
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+type WordElement struct {
|
|
|
+ ElementType string `json:"element_type" description:"元素类型"`
|
|
|
+ ElementName string `json:"element_name" description:"元素名称"`
|
|
|
+ RelationName string `json:"relation_name" description:"关联元素名称"`
|
|
|
+ Content string `json:"content" description:"元素内容"`
|
|
|
+ Background string `json:"background" description:"背景色"`
|
|
|
+ IsBold bool `json:"is_bold" description:"是否加粗显示"`
|
|
|
+ TextAlign string `json:"text_align" description:"对齐方式"`
|
|
|
+ FontSize float64 `json:"font_size" description:"字体大小"`
|
|
|
+ ElementList []WordElement `json:"list" description:"子元素"`
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func GenerateWordV2(contractDetail *contract.ContractDetail, wordPath string) (err error) {
|
|
|
+ contractTemplate, err := contract_template.GetContractTemplateByTemplateId(contractDetail.TemplateId)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ jsonStr := contractTemplate.WordConfig
|
|
|
+
|
|
|
+ var contractData []WordElement
|
|
|
+ err = json.Unmarshal([]byte(jsonStr), &contractData)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("json字符串解析失败,ERR:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ doc := document.New()
|
|
|
+
|
|
|
+
|
|
|
+ cp := doc.CoreProperties
|
|
|
+
|
|
|
+ cp.SetTitle("弘则弥道(上海)投资咨询有限公司 & 研究服务合同")
|
|
|
+ cp.SetAuthor("弘则弥道(上海)投资咨询有限公司")
|
|
|
+ cp.SetCategory("合同")
|
|
|
+
|
|
|
+ cp.SetLastModifiedBy("弘则弥道(上海)投资咨询有限公司")
|
|
|
+ cp.SetCreated(time.Now())
|
|
|
+ cp.SetModified(time.Now())
|
|
|
+ cp.SetDescription("弘则弥道(上海)投资咨询有限公司 研究服务合同")
|
|
|
+ cp.SetLanguage("中文")
|
|
|
+
|
|
|
+ for _, data := range contractData {
|
|
|
+ fontSize := data.FontSize
|
|
|
+ if fontSize <= 0 {
|
|
|
+ fontSize = 15
|
|
|
+ }
|
|
|
+
|
|
|
+ printContent := ``
|
|
|
+ if data.ElementName == "services" {
|
|
|
+ tableTitleSlice := make([]string, 0)
|
|
|
+ title := ""
|
|
|
+ if contractDetail.ProductId == 1 {
|
|
|
+ title = "依照《【弘则研究】FICC客户客户服务列表2021》中"
|
|
|
+ } else {
|
|
|
+ title = "依照《【弘则研究】私募客户客户服务列表2021》中"
|
|
|
+ }
|
|
|
+ TableDataListSlice := make([]TableData, 0)
|
|
|
+
|
|
|
+ for i := 0; i < len(contractDetail.Service); i++ {
|
|
|
+
|
|
|
+ var tableDataList TableData
|
|
|
+
|
|
|
+ item := contractDetail.Service[i]
|
|
|
+
|
|
|
+ tableTitleSlice = append(tableTitleSlice, item.Title)
|
|
|
+
|
|
|
+ if item.HasDetail == "是" && len(item.DetailList) > 0 {
|
|
|
+
|
|
|
+ tableRowList := make([]TableRow, 0)
|
|
|
+
|
|
|
+
|
|
|
+ for j := 0; j < len(item.DetailList); j++ {
|
|
|
+
|
|
|
+ isBold := false
|
|
|
+ backgrandColor := ""
|
|
|
+ fontSize := 10.0
|
|
|
+
|
|
|
+
|
|
|
+ if j == 0 {
|
|
|
+ isBold = true
|
|
|
+ backgrandColor = "gray_2"
|
|
|
+ fontSize = 12.0
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ tmpCellList, colErr := getColList(item.DetailList[j])
|
|
|
+ if colErr != nil {
|
|
|
+ err = colErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ tableCelList := make([]TableCel, 0)
|
|
|
+ lenCell := len(tmpCellList)
|
|
|
+ for k := 0; k < len(tmpCellList); k++ {
|
|
|
+
|
|
|
+
|
|
|
+ newDecimal := decimal.NewFromFloat(100)
|
|
|
+
|
|
|
+ newDecimal2 := decimal.NewFromInt(int64(lenCell))
|
|
|
+
|
|
|
+ widthPercent, _ := newDecimal.Div(newDecimal2).Round(3).Float64()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ tableCel := TableCel{
|
|
|
+ Value: tmpCellList[k],
|
|
|
+ TextAlign: "center",
|
|
|
+
|
|
|
+
|
|
|
+ Background: backgrandColor,
|
|
|
+ IsBold: isBold,
|
|
|
+ FontSize: fontSize,
|
|
|
+ WidthPercent: widthPercent,
|
|
|
+ }
|
|
|
+ tableCelList = append(tableCelList, tableCel)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ tableRow := TableRow{
|
|
|
+ RowList: tableCelList,
|
|
|
+ }
|
|
|
+ tableRowList = append(tableRowList, tableRow)
|
|
|
+ }
|
|
|
+
|
|
|
+ tableDataList.List = tableRowList
|
|
|
+ } else {
|
|
|
+
|
|
|
+ contractServiceTemplate, tmpErr := contract_service_template.GetContractServiceTemplateById(item.ServiceTemplateId)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ jsonStr := contractServiceTemplate.TableValue
|
|
|
+ err = json.Unmarshal([]byte(jsonStr), &tableDataList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ TableDataListSlice = append(TableDataListSlice, tableDataList)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ titleStr := strings.Join(tableTitleSlice, "、")
|
|
|
+ title += titleStr + "的服务内容,详细如下:"
|
|
|
+
|
|
|
+
|
|
|
+ headerPar := doc.AddParagraph()
|
|
|
+ headerParPro := headerPar.Properties()
|
|
|
+
|
|
|
+ textAlign := getTextAlignConf(data.TextAlign)
|
|
|
+ headerParPro.SetAlignment(textAlign)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ headerRun := headerPar.AddRun()
|
|
|
+ headerRunPro := headerRun.Properties()
|
|
|
+ headerRunPro.SetBold(data.IsBold)
|
|
|
+ headerRunPro.SetSize(measurement.Distance(fontSize * measurement.Point))
|
|
|
+ headerRunPro.SetFontFamily("宋体")
|
|
|
+
|
|
|
+ headerRun.AddText(title)
|
|
|
+
|
|
|
+
|
|
|
+ for _, tableDataList := range TableDataListSlice {
|
|
|
+ tmpErr := addTableV2(tableDataList, doc)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ continue
|
|
|
+ } else {
|
|
|
+ isPrint, tmpPrintContent, tmpErr := getPrintData(data, contractDetail)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if isPrint == false {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ printContent = tmpPrintContent
|
|
|
+ }
|
|
|
+
|
|
|
+ printContentRune := []rune(printContent)
|
|
|
+ strLen := len(printContentRune)
|
|
|
+
|
|
|
+ addTabNum := 0
|
|
|
+ printContentList := make([]map[int]string, 0)
|
|
|
+ firstLen := 17
|
|
|
+ secondLen := 14
|
|
|
+ if data.ElementType == "column" {
|
|
|
+ if strLen > firstLen {
|
|
|
+ maxLine := ((strLen - firstLen) / secondLen) + 1
|
|
|
+ for i := 0; i < maxLine; i++ {
|
|
|
+ printContentMap := make(map[int]string)
|
|
|
+ startIndex := secondLen*i + firstLen
|
|
|
+ endIndex := secondLen*(i+1) + firstLen
|
|
|
+ if endIndex > strLen {
|
|
|
+ endIndex = strLen
|
|
|
+ }
|
|
|
+ tmpPrintContent := string(printContentRune[startIndex:endIndex])
|
|
|
+ printContentMap[0] = tmpPrintContent
|
|
|
+ printContentList = append(printContentList, printContentMap)
|
|
|
+ }
|
|
|
+ printContent = string(printContentRune[:firstLen])
|
|
|
+ strLen = firstLen
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ addTabNum = firstLen - strLen
|
|
|
+ }
|
|
|
+ addTabNum += 3
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ headerPar := doc.AddParagraph()
|
|
|
+ headerParPro := headerPar.Properties()
|
|
|
+
|
|
|
+ headerParPro.Spacing().SetLineSpacing(measurement.Distance(1.5*fontSize*measurement.Point), wml.ST_LineSpacingRuleAuto)
|
|
|
+
|
|
|
+ textAlign := getTextAlignConf(data.TextAlign)
|
|
|
+ headerParPro.SetAlignment(textAlign)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ headerRun := headerPar.AddRun()
|
|
|
+ headerRunPro := headerRun.Properties()
|
|
|
+ headerRunPro.SetBold(data.IsBold)
|
|
|
+ headerRunPro.SetSize(measurement.Distance(fontSize * measurement.Point))
|
|
|
+ headerRunPro.SetFontFamily("宋体")
|
|
|
+
|
|
|
+ headerRun.AddText(printContent)
|
|
|
+
|
|
|
+ for _, text := range data.ElementList {
|
|
|
+ if text.ElementName == "services" {
|
|
|
+ tableTitleSlice := make([]string, 0)
|
|
|
+ title := ""
|
|
|
+ if contractDetail.ProductId == 1 {
|
|
|
+ title = "依照《【弘则研究】FICC客户客户服务列表2021》中 "
|
|
|
+ } else {
|
|
|
+ title = "依照《【弘则研究】私募客户客户服务列表2021》中 "
|
|
|
+ }
|
|
|
+ TableDataListSlice := make([]TableData, 0)
|
|
|
+ for i := len(contractDetail.Service) - 1; i >= 0; i-- {
|
|
|
+
|
|
|
+ var tableDataList TableData
|
|
|
+
|
|
|
+ item := contractDetail.Service[i]
|
|
|
+
|
|
|
+ tableTitleSlice = append(tableTitleSlice, item.Title)
|
|
|
+
|
|
|
+ if item.HasDetail == "是" && len(item.DetailList) > 0 {
|
|
|
+
|
|
|
+ tableRowList := make([]TableRow, 0)
|
|
|
+
|
|
|
+
|
|
|
+ for j := 0; j < len(item.DetailList); j++ {
|
|
|
+
|
|
|
+ isBold := false
|
|
|
+ backgrandColor := ""
|
|
|
+ fontSize := 10.0
|
|
|
+
|
|
|
+
|
|
|
+ if j == 0 {
|
|
|
+ isBold = true
|
|
|
+ backgrandColor = "gray_2"
|
|
|
+ fontSize = 12.0
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ tmpCellList, colErr := getColList(item.DetailList[j])
|
|
|
+ if colErr != nil {
|
|
|
+ err = colErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ tableCelList := make([]TableCel, 0)
|
|
|
+ lenCell := len(tmpCellList)
|
|
|
+ for k := 0; k < len(tmpCellList); k++ {
|
|
|
+
|
|
|
+
|
|
|
+ newDecimal := decimal.NewFromFloat(100)
|
|
|
+
|
|
|
+ newDecimal2 := decimal.NewFromInt(int64(lenCell))
|
|
|
+
|
|
|
+ widthPercent, _ := newDecimal.Div(newDecimal2).Round(3).Float64()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ tableCel := TableCel{
|
|
|
+ Value: tmpCellList[k],
|
|
|
+ TextAlign: "center",
|
|
|
+
|
|
|
+
|
|
|
+ Background: backgrandColor,
|
|
|
+ IsBold: isBold,
|
|
|
+ FontSize: fontSize,
|
|
|
+ WidthPercent: widthPercent,
|
|
|
+ }
|
|
|
+ tableCelList = append(tableCelList, tableCel)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ tableRow := TableRow{
|
|
|
+ RowList: tableCelList,
|
|
|
+ }
|
|
|
+ tableRowList = append(tableRowList, tableRow)
|
|
|
+ }
|
|
|
+
|
|
|
+ tableDataList.List = tableRowList
|
|
|
+ } else {
|
|
|
+
|
|
|
+ contractServiceTemplate, tmpErr := contract_service_template.GetContractServiceTemplateById(item.ServiceTemplateId)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ jsonStr := contractServiceTemplate.TableValue
|
|
|
+ err = json.Unmarshal([]byte(jsonStr), &tableDataList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ TableDataListSlice = append(TableDataListSlice, tableDataList)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ titleStr := strings.Join(tableTitleSlice, "、")
|
|
|
+ title += titleStr + "的服务内容,详细如下:"
|
|
|
+
|
|
|
+ headerRun := headerPar.AddRun()
|
|
|
+ headerRun.AddBreak()
|
|
|
+ headerRunPro := headerRun.Properties()
|
|
|
+ headerRunPro.SetBold(text.IsBold)
|
|
|
+ headerRunPro.SetSize(measurement.Distance(fontSize * measurement.Point))
|
|
|
+ headerRunPro.SetFontFamily("宋体")
|
|
|
+
|
|
|
+ headerRun.AddText(title)
|
|
|
+
|
|
|
+
|
|
|
+ for _, tableDataList := range TableDataListSlice {
|
|
|
+ tmpErr := addTableV2(tableDataList, doc)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isPrint, printContent, tmpErr := getPrintData(text, contractDetail)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if isPrint == false {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if data.ElementType == "column" {
|
|
|
+ for j := 0; j < addTabNum; j++ {
|
|
|
+
|
|
|
+ printContent = " " + printContent
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fontSize := text.FontSize
|
|
|
+ if fontSize <= 0 {
|
|
|
+ fontSize = 15
|
|
|
+ }
|
|
|
+ headerRun2 := headerPar.AddRun()
|
|
|
+ headerRunPro2 := headerRun2.Properties()
|
|
|
+ headerRunPro2.SetBold(text.IsBold)
|
|
|
+ headerRunPro2.SetSize(measurement.Distance(fontSize * measurement.Point))
|
|
|
+ headerRunPro2.SetFontFamily("宋体")
|
|
|
+
|
|
|
+ headerRun2.AddText(printContent)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, printMap := range printContentList {
|
|
|
+
|
|
|
+ headerPar := doc.AddParagraph()
|
|
|
+ headerParPro := headerPar.Properties()
|
|
|
+ headerParPro.Spacing().SetLineSpacing(measurement.Distance(1.5*fontSize*measurement.Point), wml.ST_LineSpacingRuleAuto)
|
|
|
+
|
|
|
+
|
|
|
+ textAlign := getTextAlignConf(data.TextAlign)
|
|
|
+ headerParPro.SetAlignment(textAlign)
|
|
|
+
|
|
|
+ headerParPro.SetStartIndent(measurement.Distance(3 * fontSize * measurement.Point))
|
|
|
+
|
|
|
+ headerRun := headerPar.AddRun()
|
|
|
+ headerRunPro := headerRun.Properties()
|
|
|
+ headerRunPro.SetBold(data.IsBold)
|
|
|
+ headerRunPro.SetSize(measurement.Distance(fontSize * measurement.Point))
|
|
|
+ headerRunPro.SetFontFamily("宋体")
|
|
|
+
|
|
|
+
|
|
|
+ headerRun.AddText(printMap[0])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ err = doc.SaveToFile(wordPath)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func getPrintData(data WordElement, contractDetail *contract.ContractDetail) (isPrint bool, printContent string, err error) {
|
|
|
+ printContent = data.Content
|
|
|
+ if data.RelationName != "" {
|
|
|
+ switch data.RelationName {
|
|
|
+ case "address":
|
|
|
+ if contractDetail.Address == "" && contractDetail.Province == "" && contractDetail.City == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ case "postcode":
|
|
|
+ if contractDetail.Postcode == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ case "phone":
|
|
|
+ if contractDetail.Phone == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ case "fax":
|
|
|
+ if contractDetail.Fax == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ case "remark":
|
|
|
+ if contractDetail.Remark == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ case "price":
|
|
|
+
|
|
|
+ if contractDetail.OriginalPrice == contractDetail.Price {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ case "price_cn":
|
|
|
+
|
|
|
+ if contractDetail.OriginalPrice == contractDetail.Price {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ case "pay_remark":
|
|
|
+ if contractDetail.PayRemark == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ case "company_name":
|
|
|
+ if contractDetail.CompanyName == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ switch data.ElementName {
|
|
|
+ case "address":
|
|
|
+ if contractDetail.Address == "" && contractDetail.Province == "" && contractDetail.City == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ printContent = getContractAddress(contractDetail)
|
|
|
+ case "postcode":
|
|
|
+ if contractDetail.Postcode == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ printContent = contractDetail.Postcode
|
|
|
+ case "phone":
|
|
|
+ if contractDetail.Phone == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ printContent = contractDetail.Phone
|
|
|
+ case "fax":
|
|
|
+ if contractDetail.Fax == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ printContent = contractDetail.Fax
|
|
|
+ case "remark":
|
|
|
+ if contractDetail.Remark == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ printContent = contractDetail.Remark
|
|
|
+ case "start_date":
|
|
|
+ printContent = contractDetail.StartDate.Format("2006年01月02日")
|
|
|
+ case "end_date":
|
|
|
+ printContent = contractDetail.EndDate.Format("2006年01月02日")
|
|
|
+ case "num_year":
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ tmpPrintContent, tmpErr := CalculationDate(contractDetail.StartDate, contractDetail.EndDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ printContent = tmpPrintContent
|
|
|
+ case "original_price":
|
|
|
+
|
|
|
+ newDecimal := decimal.NewFromFloat(contractDetail.OriginalPrice)
|
|
|
+ printContent = newDecimal.String()
|
|
|
+ case "original_price_cn":
|
|
|
+
|
|
|
+ originalCnyPrice, cnyErr := utils.ConvertNumToCny(contractDetail.OriginalPrice)
|
|
|
+ if cnyErr != nil {
|
|
|
+ err = cnyErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ printContent = originalCnyPrice
|
|
|
+ case "price":
|
|
|
+
|
|
|
+ if contractDetail.OriginalPrice == contractDetail.Price {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ newDecimal := decimal.NewFromFloat(contractDetail.Price)
|
|
|
+ printContent = newDecimal.String()
|
|
|
+ case "price_cn":
|
|
|
+
|
|
|
+ if contractDetail.OriginalPrice == contractDetail.Price {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ cnyPrice, cnyErr := utils.ConvertNumToCny(contractDetail.Price)
|
|
|
+ if cnyErr != nil {
|
|
|
+ err = cnyErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ printContent = cnyPrice
|
|
|
+
|
|
|
+ case "pay_remark":
|
|
|
+ if contractDetail.PayRemark == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ printContent = contractDetail.PayRemark
|
|
|
+ case "company_name":
|
|
|
+ if contractDetail.CompanyName == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ printContent = contractDetail.CompanyName
|
|
|
+ case "company_name_sign":
|
|
|
+ if contractDetail.CompanyName == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ printContent = "甲方:" + contractDetail.CompanyName
|
|
|
+ }
|
|
|
+ isPrint = true
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func addTableV2(tableDataList TableData, doc *document.Document) (err error) {
|
|
|
+
|
|
|
+
|
|
|
+ nowParagraph := doc.AddParagraph()
|
|
|
+
|
|
|
+
|
|
|
+ table := doc.InsertTableAfter(nowParagraph)
|
|
|
+
|
|
|
+ tableWidth := 6.5
|
|
|
+ table.Properties().SetWidth(measurement.Distance(tableWidth * measurement.Inch))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ borders := table.Properties().Borders()
|
|
|
+
|
|
|
+ borders.SetAll(wml.ST_BorderSingle, color.Auto, measurement.Zero)
|
|
|
+
|
|
|
+
|
|
|
+ rowList := tableDataList.List
|
|
|
+
|
|
|
+ rowIsMeged := make(map[int]bool)
|
|
|
+
|
|
|
+
|
|
|
+ for i := 0; i < len(rowList); i++ {
|
|
|
+
|
|
|
+ row := table.AddRow()
|
|
|
+
|
|
|
+ row.Properties().SetHeight(30*measurement.Point, wml.ST_HeightRuleAtLeast)
|
|
|
+
|
|
|
+
|
|
|
+ rowDataList := rowList[i].RowList
|
|
|
+ if rowDataList != nil {
|
|
|
+ for j := 0; j < len(rowDataList); j++ {
|
|
|
+
|
|
|
+ var isMeged bool
|
|
|
+ isMeged, ok := rowIsMeged[j]
|
|
|
+ if !ok {
|
|
|
+ rowIsMeged[j] = false
|
|
|
+ isMeged = false
|
|
|
+ }
|
|
|
+
|
|
|
+ cell := row.AddCell()
|
|
|
+ cellPara := cell.AddParagraph()
|
|
|
+ run := cellPara.AddRun()
|
|
|
+
|
|
|
+ cellData := rowDataList[j]
|
|
|
+
|
|
|
+
|
|
|
+ if cellData.ColumnSpan > 0 {
|
|
|
+
|
|
|
+ cell.Properties().SetColumnSpan(cellData.ColumnSpan)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if cellData.IsMerged {
|
|
|
+
|
|
|
+ rowIsMeged[j] = true
|
|
|
+
|
|
|
+ var mergeVal wml.ST_Merge
|
|
|
+
|
|
|
+ if isMeged {
|
|
|
+ mergeVal = wml.ST_MergeContinue
|
|
|
+ } else {
|
|
|
+ mergeVal = wml.ST_MergeRestart
|
|
|
+ }
|
|
|
+ cell.Properties().SetVerticalMerge(mergeVal)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ rowIsMeged[j] = false
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if cellData.Background != "" {
|
|
|
+ cell.Properties().SetShading(wml.ST_ShdSolid, getColorConf(cellData.Background), color.Auto)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ cell.Properties().SetVerticalAlignment(wml.ST_VerticalJcCenter)
|
|
|
+
|
|
|
+
|
|
|
+ if cellData.WidthPercent > 0 {
|
|
|
+
|
|
|
+
|
|
|
+ cellWidth := tableWidth * cellData.WidthPercent * measurement.Inch / 100
|
|
|
+ cell.Properties().SetWidth(measurement.Distance(cellWidth))
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if cellData.TextAlign != "" {
|
|
|
+ cellPara.Properties().SetAlignment(getTextAlignConf(cellData.TextAlign))
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ run.Properties().SetBold(cellData.IsBold)
|
|
|
+
|
|
|
+
|
|
|
+ fontSize := 10.0
|
|
|
+ if cellData.FontSize > 0 {
|
|
|
+ fontSize = cellData.FontSize
|
|
|
+ }
|
|
|
+ run.Properties().SetSize(measurement.Distance(fontSize * measurement.Point))
|
|
|
+
|
|
|
+
|
|
|
+ cellPara.Properties().Spacing().SetLineSpacing(measurement.Distance(1.4*fontSize*measurement.Point), wml.ST_LineSpacingRuleAuto)
|
|
|
+
|
|
|
+ cellPara.Properties().Spacing().SetBefore(measurement.Distance(0.9 * fontSize * measurement.Point))
|
|
|
+
|
|
|
+ cellPara.Properties().Spacing().SetAfter(measurement.Distance(0.5 * fontSize * measurement.Point))
|
|
|
+
|
|
|
+
|
|
|
+ run.Properties().SetFontFamily("宋体")
|
|
|
+
|
|
|
+
|
|
|
+ run.Properties().SetVerticalAlignment(sharedTypes.ST_VerticalAlignRunBaseline)
|
|
|
+
|
|
|
+
|
|
|
+ if cellData.Value != "" {
|
|
|
+ strSlice := strings.Split(cellData.Value, "<br/>")
|
|
|
+ for s := 0; s < len(strSlice); s++ {
|
|
|
+ if s > 0 {
|
|
|
+ run.AddBreak()
|
|
|
+ }
|
|
|
+ run.AddText(strSlice[s])
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ run.AddText("")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
func getContractAddress(contractDetail *contract.ContractDetail) (address string) {
|
|
|
ignoreStrs := []string{"北京市", "上海市", "天津市", "重庆市"}
|
|
@@ -1066,3 +1796,143 @@ func getContractAddress(contractDetail *contract.ContractDetail) (address string
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+*@tips libreoffice 转换指令:
|
|
|
+* libreoffice6.2 invisible --convert-to pdf csDoc.doc --outdir /home/[转出目录]
|
|
|
+*
|
|
|
+* @function 实现文档类型转换为pdf或html
|
|
|
+* @param command:libreofficed的命令(具体以版本为准);win:soffice; linux:libreoffice6.2
|
|
|
+* fileSrcPath:转换文件的路径
|
|
|
+* fileOutDir:转换后文件存储目录
|
|
|
+* converterType:转换的类型pdf/html
|
|
|
+* @return fileOutPath 转换成功生成的文件的路径 error 转换错误
|
|
|
+ */
|
|
|
+func FuncDocs2Pdf(command string, fileSrcPath string, fileOutDir string, converterType string) (fileOutPath string, error error) {
|
|
|
+
|
|
|
+ srcFile, erByOpenSrcFile := os.Open(fileSrcPath)
|
|
|
+ if erByOpenSrcFile != nil && os.IsNotExist(erByOpenSrcFile) {
|
|
|
+ return "", erByOpenSrcFile
|
|
|
+ }
|
|
|
+
|
|
|
+ outFileDir, erByOpenFileOutDir := os.Open(fileOutDir)
|
|
|
+ if erByOpenFileOutDir != nil && os.IsNotExist(erByOpenFileOutDir) {
|
|
|
+ erByCreateFileOutDir := os.MkdirAll(fileOutDir, os.ModePerm)
|
|
|
+ if erByCreateFileOutDir != nil {
|
|
|
+ fmt.Println("File ouput dir create error.....", erByCreateFileOutDir.Error())
|
|
|
+ return "", erByCreateFileOutDir
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ defer func() {
|
|
|
+ _ = srcFile.Close()
|
|
|
+ _ = outFileDir.Close()
|
|
|
+ }()
|
|
|
+
|
|
|
+ cmd := exec.Command(command, "--invisible", "--convert-to", converterType,
|
|
|
+ fileSrcPath, "--outdir", fileOutDir)
|
|
|
+ _, errByCmdStart := cmd.Output()
|
|
|
+
|
|
|
+ if errByCmdStart != nil {
|
|
|
+ return "", errByCmdStart
|
|
|
+ }
|
|
|
+
|
|
|
+ fileOutPath = fileOutDir + "/" + strings.Split(path.Base(fileSrcPath), ".")[0]
|
|
|
+ if converterType == "html" {
|
|
|
+ fileOutPath += ".html"
|
|
|
+ } else {
|
|
|
+ fileOutPath += ".pdf"
|
|
|
+ }
|
|
|
+
|
|
|
+ return fileOutPath, nil
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func CalculationDate(startDate, endDate time.Time) (beetweenDay string, err error) {
|
|
|
+
|
|
|
+
|
|
|
+ numYear := endDate.Year() - startDate.Year()
|
|
|
+
|
|
|
+ numMonth := int(endDate.Month()) - int(startDate.Month())
|
|
|
+
|
|
|
+ numDay := 0
|
|
|
+
|
|
|
+ endDateDays := getMonthDay(endDate.Year(), int(endDate.Month()))
|
|
|
+
|
|
|
+
|
|
|
+ endDatePrevMonthDate := endDate.AddDate(0, -1, 0)
|
|
|
+
|
|
|
+ endDatePrevMonthDays := getMonthDay(endDatePrevMonthDate.Year(), int(endDatePrevMonthDate.Month()))
|
|
|
+
|
|
|
+ startDateMonthDays := getMonthDay(startDate.Year(), int(startDate.Month()))
|
|
|
+
|
|
|
+
|
|
|
+ if endDate.Day() == endDateDays {
|
|
|
+ numDay = startDateMonthDays - startDate.Day() + 1
|
|
|
+
|
|
|
+
|
|
|
+ if numDay == startDateMonthDays {
|
|
|
+ numMonth++
|
|
|
+ numDay = 0
|
|
|
+
|
|
|
+ if numMonth == 12 {
|
|
|
+ numYear++
|
|
|
+ numMonth = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ numDay = endDate.Day() - startDate.Day() + 1
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if numDay < 0 {
|
|
|
+
|
|
|
+ numDay += endDatePrevMonthDays
|
|
|
+
|
|
|
+
|
|
|
+ numMonth = numMonth - 1
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if numMonth < 0 {
|
|
|
+
|
|
|
+ numMonth += 12
|
|
|
+
|
|
|
+
|
|
|
+ numYear = numYear - 1
|
|
|
+ }
|
|
|
+ if numYear < 0 {
|
|
|
+ err = errors.New("日期异常")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if numYear > 0 {
|
|
|
+ beetweenDay += fmt.Sprint(numYear, "年")
|
|
|
+ }
|
|
|
+ if numMonth > 0 {
|
|
|
+ beetweenDay += fmt.Sprint(numMonth, "个月")
|
|
|
+ }
|
|
|
+ if numDay > 0 {
|
|
|
+ beetweenDay += fmt.Sprint(numDay, "天")
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func getMonthDay(year, month int) (days int) {
|
|
|
+ if month != 2 {
|
|
|
+ if month == 4 || month == 6 || month == 9 || month == 11 {
|
|
|
+ days = 30
|
|
|
+
|
|
|
+ } else {
|
|
|
+ days = 31
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ((year%4) == 0 && (year%100) != 0) || (year%400) == 0 {
|
|
|
+ days = 29
|
|
|
+ } else {
|
|
|
+ days = 28
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|