fonchain-fiee/pkg/service/approval/approval_export.go
2025-02-19 14:24:15 +08:00

745 lines
26 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package approval
import (
"context"
"dubbo.apache.org/dubbo-go/v3/common/logger"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
approval "github.com/fonchain_enterprise/fonchain-main/api/approval"
"github.com/fonchain_enterprise/fonchain-main/pkg/common"
"github.com/fonchain_enterprise/fonchain-main/pkg/config"
"github.com/fonchain_enterprise/fonchain-main/pkg/model"
"github.com/fonchain_enterprise/fonchain-main/pkg/model/vo"
"github.com/fonchain_enterprise/fonchain-main/pkg/serializer"
"github.com/fonchain_enterprise/fonchain-main/pkg/service/account"
"github.com/fonchain_enterprise/fonchain-main/pkg/service/auth/department"
"github.com/fonchain_enterprise/fonchain-main/pkg/utils"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/signintech/gopdf"
"os"
"strconv"
"strings"
"time"
api "github.com/fonchain_enterprise/fonchain-main/api/approval"
"github.com/fonchain_enterprise/fonchain-main/pkg/e"
"github.com/fonchain_enterprise/fonchain-main/pkg/model/login"
"github.com/fonchain_enterprise/fonchain-main/pkg/service"
)
func FinancialFormExport(c *gin.Context) {
var req api.DetailRequest
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
service.Error(c, e.Error, err)
return
}
userInfo := login.GetUserInfoFromC(c)
req.UserId = userInfo.ID
res, err := service.ApprovalProvider.Detail(c, &req)
if err != nil {
service.Error(c, e.Error, err)
return
}
if res.Status != e.ApprovalWorkStatusOk {
service.Error(c, e.Error, err, "审批未通过,无法导出")
return
}
if res.SubmitterID != userInfo.ID {
service.Error(c, e.Error, err, "当前用户非提交人,无法导出")
return
}
fmt.Println("approval", res.FinancialForm)
dirPath, err := financialForm(res)
if err != nil {
service.Error(c, e.Error, err)
return
}
var httpType string
if config.IsHttps {
httpType = model.HttpsType
} else {
httpType = model.HttpType
}
var exportUrl = strings.Replace(strings.Join([]string{strings.Replace(dirPath, ".", fmt.Sprintf("%s%s", httpType, c.Request.Host), 1)}, ""), "runtime", "static", 1)
service.ResponseQuickMsg(c, e.Ok, "导出成功", map[string]string{
"ExportUrl": exportUrl,
})
}
func financialForm(form *api.CreateRequest) (string, error) {
xlsx := excelize.NewFile()
// 付款申请单
financialFormSheet1(xlsx, form.FinancialForm)
// 付款明细
financialFormSheet2(xlsx, form.FinancialForm)
dirPath := "./runtime/form"
utils.CheckDirPath(dirPath, true)
path := dirPath + "/" + form.SubmitterName + strings.Replace(time.Now().Format("2006-01-02 15:04:05"), " ", "_", -1) + ".xlsx"
err := xlsx.SaveAs(path)
if err != nil {
fmt.Println("save rows err :", err)
return "", err
}
return path, nil
}
func financialFormSheet1(xlsx *excelize.File, form *api.FinancialForm) {
index := "Sheet1"
// 公司抬头
songTi18BoldStyle, _ := xlsx.NewStyle(`{"alignment":{"horizontal":"center","vertical":"center"},"font":{"bold":true,"size":18,"family":"宋体"}}`)
// 付款申请单
songTi14BoldStyle, _ := xlsx.NewStyle(`{"alignment":{"horizontal":"center","vertical":"center"},"font":{"bold":true,"size":14,"family":"宋体"}}`)
// 日期 当前日期 例2023-04-26 经办部门:
// 居中
//songTi10BoldCenterStyle, _ := xlsx.NewStyle(`{"alignment":{"horizontal":"center"},"font":{"bold":true,"size":10,"family":"宋体"}}`)
songTi10BoldCenterBorderStyle, _ := xlsx.NewStyle(`{"alignment":{"horizontal":"center","vertical":"center"},"font":{"bold":true,"size":10,"family":"宋体"},"border":[{"type":"top","color":"#000000","style":1},{"type":"left","color":"#000000","style":1},{"type":"right","color":"#000000","style":1},{"type":"bottom","color":"#000000","style":1}]}`)
// 左对齐
songTi10BoldLeftStyle, _ := xlsx.NewStyle(`{"alignment":{"horizontal":"left"},"font":{"bold":true,"size":10,"family":"宋体"}}`)
songTi10BoldLeftBorderStyle, _ := xlsx.NewStyle(`{"alignment":{"horizontal":"left"},"font":{"bold":true,"size":10,"family":"宋体"},"border":[{"type":"top","color":"#000000","style":1},{"type":"left","color":"#000000","style":1},{"type":"right","color":"#000000","style":1},{"type":"bottom","color":"#000000","style":1}]}`)
// 右对齐
songTi10BoldRightStyle, _ := xlsx.NewStyle(`{"alignment":{"horizontal":"right"},"font":{"bold":true,"size":10,"family":"宋体"}}`)
//songTi10BoldRightBorderStyle, _ := xlsx.NewStyle(`{"alignment":{"horizontal":"right"},"font":{"bold":true,"size":10,"family":"宋体"},{"border":[
// {"type":"top","color":"#000000","style":1},
// {"type":"left","color":"#000000","style":1},
// {"type":"right","color":"#000000","style":1},
// {"type":"bottom","color":"#000000","style":1}
//]}}`)
// 经办部门 的具体 部门
songTi10Style, _ := xlsx.NewStyle(`{"alignment":{"horizontal":"center"},"font":{"size":10,"family":"宋体"}}`)
xlsx.SetCellStyle(index, "A2", "H2", songTi18BoldStyle)
xlsx.MergeCell(index, "A2", "H2")
xlsx.SetCellValue(index, "A2", form.PaymentCompany)
xlsx.SetCellStyle(index, "A3", "H3", songTi14BoldStyle)
xlsx.MergeCell(index, "A3", "H3")
xlsx.SetCellValue(index, "A3", "付款申请单")
// 日期 自动获取 2023年4月26日
xlsx.SetCellStyle(index, "D4", "F4", songTi14BoldStyle)
xlsx.MergeCell(index, "D4", "F4")
xlsx.SetCellFormula(index, "D4", "=now()")
dateFormat, _ := xlsx.NewStyle(`{"alignment":{"horizontal":"center"},"font":{"bold":true,"size":10,"family":"宋体"},"number_format":31,"lang":"zh-cn"}`)
xlsx.SetCellStyle(index, "D4", "D4", dateFormat)
// 经办部门
xlsx.SetCellStyle(index, "G4", "G4", songTi10BoldRightStyle)
xlsx.SetCellValue(index, "G4", "经办部门:")
xlsx.SetCellStyle(index, "H4", "H4", songTi10Style)
xlsx.SetCellValue(index, "H4", form.TransactionDepartment)
// 收款人信息
xlsx.SetCellStyle(index, "A5", "A7", songTi10BoldCenterBorderStyle)
xlsx.MergeCell(index, "A5", "A7")
xlsx.SetCellValue(index, "A5", "收款人信息")
// 全称
xlsx.SetCellStyle(index, "B5", "B5", songTi10BoldLeftBorderStyle)
xlsx.SetCellValue(index, "B5", "全称")
xlsx.SetCellStyle(index, "C5", "G5", songTi10BoldLeftBorderStyle)
xlsx.MergeCell(index, "C5", "G5")
xlsx.SetCellValue(index, "C5", form.Payee)
xlsx.SetColWidth(index, "H", "H", 11) // 设置 列宽
xlsx.SetCellStyle(index, "H5", "H5", songTi10BoldCenterBorderStyle)
xlsx.SetCellValue(index, "H5", "总经办意见")
xlsx.MergeCell(index, "H6", "H7")
xlsx.SetCellStyle(index, "H6", "H7", songTi10BoldCenterBorderStyle)
// 开户银行
xlsx.SetCellStyle(index, "B6", "B6", songTi10BoldLeftBorderStyle)
xlsx.SetCellValue(index, "B6", "开户银行")
xlsx.SetCellStyle(index, "C6", "G6", songTi10BoldLeftBorderStyle)
xlsx.MergeCell(index, "C6", "G6")
xlsx.SetCellValue(index, "C6", form.BeneficiaryBank)
// 账号
xlsx.SetCellStyle(index, "B7", "B7", songTi10BoldLeftBorderStyle)
xlsx.SetCellValue(index, "B7", "账号")
xlsx.SetCellStyle(index, "C7", "G7", songTi10BoldLeftBorderStyle)
xlsx.MergeCell(index, "C7", "G7")
xlsx.SetCellValue(index, "C7", form.BankNo)
// 摘要 等
xlsx.SetCellStyle(index, "A8", "B8", songTi10BoldCenterBorderStyle)
xlsx.MergeCell(index, "A8", "B8")
xlsx.SetCellValue(index, "A8", "摘要")
xlsx.SetCellStyle(index, "C8", "C8", songTi10BoldCenterBorderStyle)
xlsx.SetCellValue(index, "C8", "所属部门")
xlsx.SetCellStyle(index, "D8", "D8", songTi10BoldCenterBorderStyle)
xlsx.SetCellValue(index, "D8", "数量")
xlsx.SetCellStyle(index, "E8", "E8", songTi10BoldCenterBorderStyle)
xlsx.SetCellValue(index, "E8", "单位")
xlsx.SetCellStyle(index, "F8", "F8", songTi10BoldCenterBorderStyle)
xlsx.SetCellValue(index, "F8", "单价")
xlsx.SetCellStyle(index, "G8", "G8", songTi10BoldCenterBorderStyle)
xlsx.SetCellValue(index, "G8", "金额")
xlsx.SetCellStyle(index, "H8", "H8", songTi10BoldCenterBorderStyle)
xlsx.SetCellValue(index, "H8", "董事长意见")
startRowIndex := 9
var countPrice float64
for i := 0; i < len(form.CostInfo); i++ {
xlsx.MergeCell(index, fmt.Sprintf("A%v", startRowIndex), fmt.Sprintf("B%v", startRowIndex))
xlsx.SetCellStyle(index, fmt.Sprintf("A%v", startRowIndex), fmt.Sprintf("B%v", startRowIndex), songTi10BoldCenterBorderStyle)
xlsx.SetCellValue(index, fmt.Sprintf("A%v", startRowIndex), form.CostInfo[i].Description)
xlsx.SetCellStyle(index, fmt.Sprintf("C%v", startRowIndex), fmt.Sprintf("G%v", startRowIndex), songTi10BoldCenterBorderStyle)
xlsx.SetSheetRow(index, fmt.Sprintf("C%v", startRowIndex), &[]interface{}{form.CostInfo[i].UsedDepartment, form.CostInfo[i].CostNum, form.CostInfo[i].CostUnit, form.CostInfo[i].UnitPrice, form.CostInfo[i].TotalPrice})
totalPrice, _ := strconv.ParseFloat(form.CostInfo[i].TotalPrice, 10)
countPrice = countPrice + totalPrice
startRowIndex++
}
// 合并 董事长意见 单元格
// 预留 两行
for i := 0; i < 3; i++ {
xlsx.MergeCell(index, fmt.Sprintf("A%v", startRowIndex), fmt.Sprintf("B%v", startRowIndex))
xlsx.SetCellStyle(index, fmt.Sprintf("A%v", startRowIndex), fmt.Sprintf("B%v", startRowIndex), songTi10BoldCenterBorderStyle)
xlsx.SetCellStyle(index, fmt.Sprintf("C%v", startRowIndex), fmt.Sprintf("G%v", startRowIndex), songTi10BoldCenterBorderStyle)
startRowIndex++
}
xlsx.MergeCell(index, "H9", fmt.Sprintf("H%v", startRowIndex-1))
xlsx.SetCellStyle(index, "H9", fmt.Sprintf("H%v", startRowIndex-1), songTi10BoldCenterBorderStyle)
// 付款方式
xlsx.SetCellStyle(index, fmt.Sprintf("A%v", startRowIndex), fmt.Sprintf("A%v", startRowIndex+1), songTi10BoldCenterBorderStyle)
xlsx.MergeCell(index, fmt.Sprintf("A%v", startRowIndex), fmt.Sprintf("A%v", startRowIndex+1))
xlsx.SetCellValue(index, fmt.Sprintf("A%v", startRowIndex), "付款方式")
// √ □
xlsx.SetCellStyle(index, fmt.Sprintf("B%v", startRowIndex), fmt.Sprintf("B%v", startRowIndex+1), songTi10BoldCenterBorderStyle)
xlsx.MergeCell(index, fmt.Sprintf("B%v", startRowIndex), fmt.Sprintf("B%v", startRowIndex+1))
rowValue1 := "银行转账"
rowValue2 := "现金"
rowValue3 := "其他"
if form.PaymentMethod == rowValue1 {
rowValue1 = "√" + rowValue1
rowValue2 = " □" + rowValue2
rowValue3 = " □" + rowValue3
} else if form.PaymentMethod == rowValue2 {
rowValue1 = "□" + rowValue1
rowValue2 = " √" + rowValue2
rowValue3 = " □" + rowValue3
} else if form.PaymentMethod == rowValue3 {
rowValue3 = " √" + rowValue3
rowValue2 = " □" + rowValue2
rowValue1 = "□" + rowValue1
}
xlsx.SetCellValue(index, fmt.Sprintf("B%v", startRowIndex), rowValue1+"\n"+rowValue2+"\n"+rowValue3)
// 合计小写
xlsx.SetCellStyle(index, fmt.Sprintf("C%v", startRowIndex), fmt.Sprintf("C%v", startRowIndex), songTi10BoldCenterBorderStyle)
xlsx.SetCellValue(index, fmt.Sprintf("C%v", startRowIndex), "合计小写")
xlsx.SetCellStyle(index, fmt.Sprintf("D%v", startRowIndex), fmt.Sprintf("H%v", startRowIndex), songTi10BoldLeftBorderStyle)
xlsx.MergeCell(index, fmt.Sprintf("D%v", startRowIndex), fmt.Sprintf("H%v", startRowIndex))
xlsx.SetCellValue(index, fmt.Sprintf("D%v", startRowIndex), countPrice)
// 合计大写
xlsx.SetCellStyle(index, fmt.Sprintf("C%v", startRowIndex+1), fmt.Sprintf("C%v", startRowIndex+1), songTi10BoldCenterBorderStyle)
xlsx.SetCellValue(index, fmt.Sprintf("C%v", startRowIndex+1), "合计大写")
xlsx.SetCellStyle(index, fmt.Sprintf("D%v", startRowIndex+1), fmt.Sprintf("H%v", startRowIndex+1), songTi10BoldLeftBorderStyle)
xlsx.MergeCell(index, fmt.Sprintf("D%v", startRowIndex+1), fmt.Sprintf("H%v", startRowIndex+1))
price, _ := utils.ConvertNumToCny(countPrice)
xlsx.SetCellValue(index, fmt.Sprintf("D%v", startRowIndex+1), price)
startRowIndex = startRowIndex + 3
xlsx.SetCellStyle(index, fmt.Sprintf("A%v", startRowIndex), fmt.Sprintf("A%v", startRowIndex), songTi10BoldLeftStyle)
xlsx.SetCellValue(index, fmt.Sprintf("A%v", startRowIndex), "总监:")
xlsx.SetCellStyle(index, fmt.Sprintf("C%v", startRowIndex), fmt.Sprintf("C%v", startRowIndex), songTi10BoldLeftStyle)
xlsx.SetCellValue(index, fmt.Sprintf("C%v", startRowIndex), "财务审核:")
xlsx.SetCellStyle(index, fmt.Sprintf("E%v", startRowIndex), fmt.Sprintf("E%v", startRowIndex), songTi10BoldLeftStyle)
xlsx.SetCellValue(index, fmt.Sprintf("E%v", startRowIndex), "部门负责人:")
xlsx.SetCellStyle(index, fmt.Sprintf("G%v", startRowIndex), fmt.Sprintf("G%v", startRowIndex), songTi10BoldLeftStyle)
xlsx.SetCellValue(index, fmt.Sprintf("G%v", startRowIndex), "申请人:")
startRowIndex = startRowIndex + 1
xlsx.SetCellStyle(index, fmt.Sprintf("A%v", startRowIndex), fmt.Sprintf("H%v", startRowIndex), songTi10BoldLeftStyle)
xlsx.MergeCell(index, fmt.Sprintf("A%v", startRowIndex), fmt.Sprintf("H%v", startRowIndex))
xlsx.SetCellValue(index, fmt.Sprintf("A%v", startRowIndex), "备注1、适用于预付款或款项未结清的情况")
startRowIndex = startRowIndex + 1
xlsx.SetCellStyle(index, fmt.Sprintf("A%v", startRowIndex), fmt.Sprintf("H%v", startRowIndex), songTi10BoldLeftStyle)
xlsx.MergeCell(index, fmt.Sprintf("A%v", startRowIndex), fmt.Sprintf("H%v", startRowIndex))
xlsx.SetCellValue(index, fmt.Sprintf("A%v", startRowIndex), " 2、明细内容按实际情况可增加删减")
}
func financialFormSheet2(xlsx *excelize.File, form *api.FinancialForm) {
xlsx.NewSheet("Sheet2")
index := "Sheet2"
dengXian11BoldBorderStyle, _ := xlsx.NewStyle(`{"alignment":{"horizontal":"center"},"font":{"bold":false,"size":11,"family":"等线"},"border":[{"type":"top","color":"#000000","style":1},{"type":"left","color":"#000000","style":1},{"type":"right","color":"#000000","style":1},{"type":"bottom","color":"#000000","style":1}]}`)
dengXian11BoldStyle, _ := xlsx.NewStyle(`{"alignment":{"horizontal":"center"},"font":{"bold":false,"size":11,"family":"等线"}}`)
xlsx.SetCellStyle(index, "A1", "L1", dengXian11BoldBorderStyle)
xlsx.SetSheetRow(index, "A1", &[]string{"序号", "付款或报销月份", "发票日期", "发票号码(电子发票需提供)", "发票供应商名称", "发票或付款金额", "费用用途", "申请人", "付款方式", "付款或报销对象", "发票类型", "备注"})
rowIndex := 2
var countPrice float64
if len(form.InvoiceInfo) < 1 {
return
}
for i := 0; i < len(form.InvoiceInfo); i++ {
rowIndex = rowIndex + i
xlsx.SetCellStyle(index, fmt.Sprintf("A%v", rowIndex), fmt.Sprintf("L%v", rowIndex), dengXian11BoldBorderStyle)
xlsx.SetCellInt(index, fmt.Sprintf("A%v", rowIndex), i+1)
xlsx.SetSheetRow(index, fmt.Sprintf("B%v", rowIndex), &[]interface{}{form.InvoiceInfo[i].InvoiceDate, form.InvoiceInfo[i].InvoiceDate, form.InvoiceInfo[i].InvoiceNo, form.InvoiceInfo[i].InvoiceProvider, form.InvoiceInfo[i].Amount, form.InvoiceInfo[i].UseTo, form.InvoiceInfo[i].Applicant, form.InvoiceInfo[i].PaymentMethod, form.InvoiceInfo[i].PaymentObj, form.InvoiceInfo[i].InvoiceType, form.InvoiceInfo[i].Notes})
totalPrice, _ := strconv.ParseFloat(form.InvoiceInfo[i].Amount, 10)
countPrice = countPrice + totalPrice
}
rowIndex = rowIndex + 1
xlsx.SetCellStyle(index, fmt.Sprintf("A%v", rowIndex), fmt.Sprintf("L%v", rowIndex), dengXian11BoldBorderStyle)
rowIndex = rowIndex + 1
xlsx.SetCellStyle(index, fmt.Sprintf("A%v", rowIndex), fmt.Sprintf("L%v", rowIndex), dengXian11BoldBorderStyle)
rowIndex = rowIndex + 1
xlsx.SetCellStyle(index, fmt.Sprintf("A%v", rowIndex), fmt.Sprintf("L%v", rowIndex), dengXian11BoldBorderStyle)
rowIndex = rowIndex + 1
xlsx.SetCellStyle(index, fmt.Sprintf("E%v", rowIndex), fmt.Sprintf("E%v", rowIndex), dengXian11BoldStyle)
xlsx.SetCellValue(index, fmt.Sprintf("E%v", rowIndex), "合计")
xlsx.SetCellStyle(index, fmt.Sprintf("F%v", rowIndex), fmt.Sprintf("F%v", rowIndex), dengXian11BoldStyle)
xlsx.SetCellValue(index, fmt.Sprintf("F%v", rowIndex), countPrice)
}
// 采购以及付款申请 导出 (全部)
func ExportApproval(c *gin.Context) {
var req api.ListRequest
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
service.Error(c, e.Error, err)
return
}
if req.OrderBy == "" {
req.OrderBy = "desc"
}
list, err := service.ApprovalProvider.MySubmit(context.Background(), &req)
if err != nil {
service.Error(c, e.Error, err)
return
}
if list.Data == nil || len(list.Data) == 0 {
service.ResponseQuickMsg(c, e.Ok, "暂无数据可导出", nil)
return
}
// 文件的路径 压缩包的名字
now := strconv.FormatInt(time.Now().Unix(), 10)
dirPath := "./runtime/approval_export"
utils.CheckDirPath(dirPath, true)
zipPathName := now + ".zip"
zipPath := fmt.Sprintf("./runtime/")
utils.CheckDirPath(zipPath, true)
// 组装数据
for i := 0; i < len(list.Data); i++ {
fmt.Println("=============================== 打印 审批内容 ==================================")
fmt.Printf("approval content %+v\n", list.Data[i])
fmt.Println("=============================== 打印 审批内容 ==================================")
err = exportPDF(list.Data[i], dirPath)
if err != nil {
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
Msg: e.ErrWritePDF,
Status: e.Failed,
})
return
}
}
if err := utils.ZipFile(dirPath, zipPath+zipPathName); err != nil {
logger.Errorf("CompressByFiles err", err)
service.ResponseMsg(c, e.SUCCESS, serializer.Response{
Msg: e.ErrorZip,
Status: e.Failed,
})
return
}
if err = os.RemoveAll(dirPath); err != nil {
logger.Errorf("RemoveAll err", err)
}
var httpType string
if config.IsHttps {
httpType = model.HttpsType
} else {
httpType = model.HttpType
}
var exportUrl = strings.Replace(strings.Join([]string{strings.Replace(zipPath, ".", fmt.Sprintf("%s%s", httpType, c.Request.Host), 1), zipPathName}, ""), "runtime", "static", 1)
service.ResponseQuickMsg(c, e.Ok, "导出成功", map[string]string{
"ExportUrl": exportUrl,
})
}
// 写入 pdf 并保存成文件 添加到 文件夹中
// 审批 通过的 logo https://cdns.fontree.cn/fonchain-main/prod/image/139/avatar/b28c5a8b-c8a5-402e-9e5b-311bb42b2537.png
// 审批 不通过的 logo https://cdns.fontree.cn/fonchain-main/prod/image/139/avatar/741862fd-81b3-4987-883e-e1de69259baa.png
func exportPDF(detail *approval.CreateRequest, dirPath string) error {
pdf := gopdf.GoPdf{}
pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4})
pdf.AddPage()
defer pdf.Close()
// 设置文本和字体
addTTFFontErr := pdf.AddTTFFont("simfang", "./data/simfang.ttf")
if addTTFFontErr != nil {
fmt.Println("========================================= setFont ==========================================")
fmt.Printf("%+v\n", addTTFFontErr)
fmt.Println("========================================= setFont ==========================================")
return addTTFFontErr
}
setFontErr := pdf.SetFont("simfang", "", 16)
if setFontErr != nil {
fmt.Println("========================================= setFont ==========================================")
fmt.Printf("%+v\n", setFontErr)
fmt.Println("========================================= setFont ==========================================")
return setFontErr
}
accountInfo, err := account.GetUserInfoById(new(gin.Context), detail.SubmitterID, "")
if err != nil {
return err
}
submitterInfo := vo.SubmitterInfo{
Name: accountInfo.NickName,
DepartmentName: accountInfo.DepartmentName,
TelNum: accountInfo.TelNum,
}
printerInfo := vo.PrinterInfo{
Name: submitterInfo.Name,
TelNum: submitterInfo.TelNum,
}
var userIds []uint64
var copyUsers []string
var approvalUsers []string
var content []vo.ContentInfo
for _, tt := range detail.CopyUsers {
userIds = append(userIds, tt.ID)
}
for _, tt := range detail.WorkFlows {
userIds = append(userIds, tt.ID)
}
fmt.Println("1----查看", userIds)
departmentUserMap, err := department.GetDepartmentUsersMap(new(gin.Context), userIds)
fmt.Println("2----查看", departmentUserMap)
if err != nil {
return err
}
detailReq := api.TypeResponse{
Keyword: detail.Type,
}
detailRes, err := service.ApprovalProvider.DetailType(new(gin.Context), &detailReq)
if err != nil {
return err
}
fmt.Println("2----查看", detail)
for i, tt := range detail.CopyUsers {
if _, ok := departmentUserMap[tt.ID]; ok {
temp := fmt.Sprintf("第%s抄送人: %s %s", common.TransferNum(i+1), departmentUserMap[tt.ID], tt.Name)
copyUsers = append(copyUsers, temp)
} else {
temp := fmt.Sprintf("第%s抄送人: %s", common.TransferNum(i+1), tt.Name)
copyUsers = append(copyUsers, temp)
}
}
//fmt.Println(res.WorkFlows)
//fmt.Println(departmentUserMap)
for i, tt := range detail.WorkFlows {
passString := "审批中"
greetString := ""
if tt.Status == e.ApprovalWorkStatusOk {
passString = "通过"
greetString = "同意"
} else if tt.Status == e.ApprovalWorkStatusFail {
passString = "未通过"
greetString = "不同意"
}
if _, ok := departmentUserMap[tt.UserID]; ok {
temp := fmt.Sprintf("第%s审批人: %s %s %s %s %s", common.TransferNum(i+1), departmentUserMap[tt.ID], tt.Name, passString, tt.OperatedAt, greetString)
approvalUsers = append(approvalUsers, temp)
} else {
temp := fmt.Sprintf("第%s审批人: %s %s %s %s", common.TransferNum(i+1), tt.Name, passString, tt.OperatedAt, greetString)
approvalUsers = append(approvalUsers, temp)
}
}
switch detail.Type {
case e.TypeContent: //
temp := vo.ContentInfo{
Info: detail.Content,
Type: "string",
Title: "内容",
}
content = append(content, temp)
case e.TypeShow:
temp := vo.ContentInfo{
Info: detail.Content,
Type: "string",
Title: "具体内容",
}
content = append(content, temp)
case e.TypeWork:
if detail.Work != nil {
temp := vo.ContentInfo{
Info: detail.Work.ReceivedAt,
Type: "string",
Title: "领取时间",
}
content = append(content, temp)
title := ""
for _, t := range detail.Work.ApprovalWorks {
title = title + " " + t.ArtworkName
}
content = append(content, vo.ContentInfo{
Info: title,
Type: "string",
Title: "申请内容",
})
}
temp1 := vo.ContentInfo{
Info: detail.Content,
Type: "string",
Title: "具体内容",
}
content = append(content, temp1)
case e.TypeBundle:
if detail.Bundle != nil {
temp := vo.ContentInfo{
Info: detail.Bundle.ApplicationsNum,
Type: "num",
Title: "申请数量",
}
content = append(content, temp)
content = append(content, vo.ContentInfo{
Info: detail.Bundle.ReceivedAt,
Type: "string",
Title: "领取时间",
})
}
temp1 := vo.ContentInfo{
Info: detail.Content,
Type: "string",
Title: "具体内容",
}
content = append(content, temp1)
case e.TypeExhibition:
if detail.Exhibition != nil {
for i, t := range detail.Exhibition.ApprovalExhibitions {
content = append(content, vo.ContentInfo{
Info: t.PackageName,
Type: "string",
Title: "名称" + fmt.Sprintf("%d", i+1),
})
content = append(content, vo.ContentInfo{
Info: t.ShowDate,
Type: "string",
Title: "画展时间",
})
content = append(content, vo.ContentInfo{
Info: t.Address,
Type: "string",
Title: "画展地址",
})
}
content = append(content, vo.ContentInfo{
Info: detail.Bundle.ReceivedAt,
Type: "string",
Title: "领取时间",
})
}
temp1 := vo.ContentInfo{
Info: detail.Content,
Type: "string",
Title: "具体内容",
}
content = append(content, temp1)
default: //其它json
for _, tt := range detail.CustomizeInfo {
temp := vo.ContentInfo{
Info: tt.ApprovalValue,
Type: tt.ApprovalType,
Title: tt.ApprovalName,
}
content = append(content, temp)
}
}
approvalInfo := vo.ApprovalPrintInfo{
Status: detail.Status,
ApprovalNum: common.GenerateCode(detail.ID),
CreatedAt: detail.CreatedAt,
TypeString: detailRes.Title,
SubmitterInfo: submitterInfo,
PrinterInfo: printerInfo,
CopyUsers: copyUsers,
ApprovalUsers: approvalUsers,
ContentMap: content,
}
if detail.Status == model.ApprovalWorkStatusOk {
pdf.Image("./data/print-success.png",
480,
70, &gopdf.Rect{
W: 195 / 2,
H: 170 / 2,
})
} else if detail.Status == model.ApprovalWorkStatusOk {
pdf.Image("./data/print-no.png",
480,
70, &gopdf.Rect{
W: 195 / 2,
H: 170 / 2,
})
}
fmt.Println("==================================== approvalInfos ===================================================")
fmt.Printf("approvalInfos is %+v\n", approvalInfo)
fmt.Println("==================================== approvalInfos ===================================================")
var space float64 = 10
var rangeSpace float64 = 10
// 固定 大标题
pdf.SetXY(200, rangeSpace)
pdf.Cell(nil, "泰丰文化审批单-"+approvalInfo.TypeString)
rangeSpace = rangeSpace + space + 70
// 审核编号 及 日期
rangeSpace = rangeSpace + space
pdf.SetXY(0, rangeSpace)
pdf.Cell(nil, fmt.Sprintf("审核编号: %s 审核日期: %s", approvalInfo.ApprovalNum, approvalInfo.CreatedAt))
rangeSpace = rangeSpace + space
// 小标题
rangeSpace = rangeSpace + space
pdf.SetXY(0, rangeSpace)
pdf.Cell(nil, approvalInfo.TypeString)
rangeSpace = rangeSpace + space
for i := 0; i < len(approvalInfo.ContentMap); i++ {
rangeSpace = rangeSpace + space
pdf.SetXY(0, rangeSpace)
pdf.Cell(nil, fmt.Sprintf("%s:%s", approvalInfo.ContentMap[i].Title, approvalInfo.ContentMap[i].Info))
rangeSpace = rangeSpace + space
}
// 审核人
for i := 0; i < len(approvalInfo.ApprovalUsers); i++ {
rangeSpace = rangeSpace + space
pdf.SetXY(0, rangeSpace)
pdf.Cell(nil, fmt.Sprintf("%s", approvalInfo.ApprovalUsers[i]))
rangeSpace = rangeSpace + space
}
// 抄送人
for i := 0; i < len(approvalInfo.CopyUsers); i++ {
rangeSpace = rangeSpace + space
pdf.SetXY(0, rangeSpace)
pdf.Cell(nil, fmt.Sprintf("%s", approvalInfo.CopyUsers[i]))
rangeSpace = rangeSpace + space
}
rangeSpace = rangeSpace + space
pdf.SetXY(200, rangeSpace)
pdf.Cell(nil, fmt.Sprintf("打印日期:%s 打印人:%s", time.Now().Format("2006-01-02 15:04:05"), approvalInfo.SubmitterInfo.Name))
// 输出PDF
filePath := fmt.Sprintf(dirPath + "/" + approvalInfo.SubmitterInfo.Name + "_" + approvalInfo.TypeString + "_" + strconv.FormatInt(time.Now().Unix(), 10) + ".pdf")
err = pdf.WritePdf(filePath)
if err != nil {
fmt.Println("======================================================================== WritePdf ==========================================")
fmt.Printf("err is %+v\n", err)
fmt.Println("======================================================================== WritePdf ==========================================")
return err
}
return nil
}