123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- using System.Drawing;
- using GxPress.Service.Interface.Doc;
- using Spire.Doc;
- using Spire.Doc.Documents;
- using GxPress.Service.Interface;
- using System.Threading.Tasks;
- using GxPress.Result.App.Flow;
- using GxPress.Common.Tools;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace GxPress.Service.Implement.Doc
- {
- public class DocService : IDocService
- {
- private readonly IFlowService _flowService;
- public DocService(IFlowService flowService)
- {
- _flowService = flowService;
- }
- public async Task<string> MakeDoc(int flowId, int userId)
- {
-
- var flowDto = await _flowService.GetFlowResult(flowId, userId);
-
- Document doc = new Document();
-
- Section sec = doc.AddSection();
-
- Paragraph para1 = sec.AddParagraph();
- para1.AppendText(flowDto.Name);
-
- ParagraphStyle style1 = new ParagraphStyle(doc);
- style1.Name = "titleStyle";
- style1.CharacterFormat.Bold = true;
- style1.CharacterFormat.TextColor = Color.Black;
- style1.CharacterFormat.FontName = "楷体";
- style1.CharacterFormat.FontSize = 18f;
- doc.Styles.Add(style1);
- para1.ApplyStyle("titleStyle");
-
- ParagraphStyle style2 = new ParagraphStyle(doc);
- style2.Name = "paraStyle";
- style2.CharacterFormat.FontName = "楷体";
- style2.CharacterFormat.FontSize = 15f;
- doc.Styles.Add(style2);
-
- para1.Format.HorizontalAlignment = HorizontalAlignment.Center;
-
-
-
- para1.Format.AfterSpacing = 15f;
-
- var teable = CreateDocHeadTable(sec, flowDto);
-
-
-
- var ticks = DateTime.Now.Ticks.ToString();
- doc.SaveToFile($"wwwroot/cache/doc/{ticks}.docx", FileFormat.Docx2013);
- return $"/cache/doc/{ticks}.docx";
- }
-
-
-
-
-
- private Table CreateDocHeadTable(Section section, FlowResult flowDto)
- {
- var site = new Dictionary<string, string>();
- site.Add("审批标号", flowDto.No);
- site.Add("所在部门", flowDto.DepartmentName);
- site.Add("提交时间", Convert.ToDateTime(flowDto.CreatedDate).ToString("yyyy-MM-dd HH:mm:ss"));
- Table table = section.AddTable(true);
- table.ResetCells(site.Count + flowDto.FormFields.Count + 2 + flowDto.Nodes.Count + 1, 4);
- TableRow row = table.Rows[0];
- row.IsHeader = true;
- int i = 0;
- foreach (var item in site)
- {
-
- table.ApplyHorizontalMerge(i, 0, 1);
- var para = table[i, 0].AddParagraph();
- var TR1 = para.AppendText(item.Key);
-
- table.ApplyHorizontalMerge(i, 2, 3);
- para = table[i, 2].AddParagraph();
- TR1 = para.AppendText(item.Value);
- i++;
- }
- foreach (var item in flowDto.FormFields)
- {
- table.ApplyHorizontalMerge(i, 0, 1);
- var TR2 = table[i, 0].AddParagraph().AppendText(item.Label);
- TR2.CharacterFormat.FontName = "Arial";
- TR2.CharacterFormat.FontSize = 10;
- table.ApplyHorizontalMerge(i, 2, 3);
- TR2 = table[i, 2].AddParagraph().AppendText(item.Value);
- TR2.CharacterFormat.FontName = "Arial";
- TR2.CharacterFormat.FontSize = 10;
- i++;
- }
- table.ApplyHorizontalMerge(i, 0, 3);
- var TR = table[i, 0].AddParagraph().AppendText("审核流程");
- TR.CharacterFormat.FontName = "Arial";
- TR.CharacterFormat.FontSize = 14;
- i++;
-
- TR = table[i, 0].AddParagraph().AppendText("姓名");
- TR = table[i, 1].AddParagraph().AppendText("状态");
- TR = table[i, 2].AddParagraph().AppendText("备注");
- TR = table[i, 3].AddParagraph().AppendText("时间");
- i++;
- foreach (var item in flowDto.Nodes)
- {
- var TR3 = table[i, 0].AddParagraph().AppendText(item.Name);
- TR3.CharacterFormat.FontName = "Arial";
- TR3.CharacterFormat.FontSize = 10;
- TR3 = table[i, 1].AddParagraph().AppendText(item.Action);
- TR3.CharacterFormat.FontName = "Arial";
- TR3.CharacterFormat.FontSize = 10;
- TR3 = table[i, 2].AddParagraph().AppendText(item.Message);
- TR3.CharacterFormat.FontName = "Arial";
- TR3.CharacterFormat.FontSize = 10;
- TR3 = table[i, 3].AddParagraph().AppendText(Convert.ToDateTime(item.CreatedDate).ToString("yyyy-MM-dd HH:mm:ss"));
- TR3.CharacterFormat.FontName = "Arial";
- TR3.CharacterFormat.FontSize = 10;
- i++;
- }
- TR = table[i, 0].AddParagraph().AppendText("抄送人");
- TR.CharacterFormat.FontName = "Arial";
- TR.CharacterFormat.FontSize = 10;
- table.ApplyHorizontalMerge(i, 1, 3);
- TR = table[i, 0].AddParagraph().AppendText(StringUtils.ObjectCollectionToString(flowDto.CarbonCopyUsers.Select(n => n.Name), "丶"));
- TR.CharacterFormat.FontName = "Arial";
- TR.CharacterFormat.FontSize = 10;
- return table;
- }
- }
- }
|