Esempio n. 1
0
        public async Task <NewErrorModel> PrintAndSend(PrintAndSendModel printAndSendModel)
        {
            try
            {
                string       TaskId    = printAndSendModel.TaskId;
                string       UserId    = printAndSendModel.UserId;
                string       OldPath   = printAndSendModel.OldPath;
                PDFHelperNew pdfHelper = new PDFHelperNew();
                using (DDContext context = new DDContext())
                {
                    //获取表单信息
                    Tasks  tasks     = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First();
                    string FlowId    = tasks.FlowId.ToString();
                    string ProjectId = tasks.ProjectId;

                    //判断流程是否已结束
                    List <Tasks> tasksList = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.IsSend != true && t.State == 0).ToList();
                    if (tasksList.Count > 0)
                    {
                        return(new NewErrorModel()
                        {
                            error = new Error(1, "流程未结束!", "")
                            {
                            },
                        });
                    }

                    List <Purchase> PurchaseList = context.Purchase.Where(u => u.TaskId == TaskId).ToList();

                    var SelectPurchaseList = from p in PurchaseList
                                             select new
                    {
                        p.DrawingNo,
                        p.Name,
                        p.Count,
                        p.MaterialScience,
                        p.Unit,
                        p.SingleWeight,
                        p.AllWeight,
                        p.Sorts,
                        p.NeedTime,
                        p.Mark
                    };

                    DataTable dtSourse = DtLinqOperators.CopyToDataTable(SelectPurchaseList);
                    //ClassChangeHelper.ToDataTable(SelectPurchaseList);
                    List <NodeInfo> NodeInfoList = context.NodeInfo.Where(u => u.FlowId == FlowId && u.NodeId != 0 && u.NodeName != "结束" && u.IsSend != true).ToList();
                    foreach (NodeInfo nodeInfo in NodeInfoList)
                    {
                        if (string.IsNullOrEmpty(nodeInfo.NodePeople))
                        {
                            string strNodePeople = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyMan;
                            string ApplyTime     = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime;
                            nodeInfo.NodePeople = strNodePeople + "  " + ApplyTime;
                        }
                        else
                        {
                            string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime;
                            nodeInfo.NodePeople = nodeInfo.NodePeople + "  " + ApplyTime;
                        }
                    }
                    DataTable dtApproveView = ClassChangeHelper.ToDataTable(NodeInfoList);
                    string    FlowName      = context.Flows.Where(f => f.FlowId.ToString() == FlowId).First().FlowName.ToString();

                    ProjectInfo projectInfo = context.ProjectInfo.Where(p => p.ProjectId == ProjectId).First();
                    string      ProjectName = projectInfo.ProjectName;
                    string      ProjectNo   = projectInfo.ProjectId;
                    //绘制BOM表单PDF
                    List <string> contentList = new List <string>()
                    {
                        "序号", "代号", "名称", "数量", "材料", "单位", "单重", "总重", "类别", "需用日期", "备注"
                    };

                    float[] contentWithList = new float[]
                    {
                        50, 80, 80, 30, 60, 30, 60, 60, 60, 60, 60
                    };

                    string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime,
                                                        ProjectName, ProjectNo, "1", 380, 710, contentList, contentWithList, dtSourse, dtApproveView, null);
                    string RelativePath = "~/UploadFile/PDF/" + Path.GetFileName(path);

                    string[] Paths = OldPath.Split(',');

                    List <string> newPaths = new List <string>();
                    RelativePath = AppDomain.CurrentDomain.BaseDirectory + RelativePath.Substring(2, RelativePath.Length - 2).Replace('/', '\\');
                    newPaths.Add(RelativePath);
                    foreach (string pathChild in Paths)
                    {
                        string AbPath = AppDomain.CurrentDomain.BaseDirectory + pathChild.Substring(2, pathChild.Length - 2);
                        //PDF盖章 保存路径
                        newPaths.Add(pdfHelper.PDFWatermark(AbPath,
                                                            string.Format(@"{0}\UploadFile\PDF\{1}",
                                                                          AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(pathChild)),
                                                            string.Format(@"{0}\Content\images\受控章.png", AppDomain.CurrentDomain.BaseDirectory),
                                                            100, 100));
                    }
                    string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip", AppDomain.CurrentDomain.BaseDirectory, "图纸审核" + DateTime.Now.ToString("yyyyMMddHHmmss"));
                    //文件压缩打包
                    IonicHelper.CompressMulti(newPaths, SavePath, false);

                    //上传盯盘获取MediaId
                    DingTalkServersController otherController = new DingTalkServersController();
                    SavePath = string.Format(@"~\UploadFile\Ionic\{0}", Path.GetFileName(SavePath));
                    var resultUploadMedia = await otherController.UploadMedia(SavePath);

                    //推送用户
                    FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia);
                    fileSendModel.UserId = UserId;
                    var result = await otherController.SendFileMessage(fileSendModel);

                    return(new NewErrorModel()
                    {
                        error = new Error(0, "已推送至钉钉!", "")
                        {
                        },
                    });
                }
            }
            catch (Exception ex)
            {
                return(new NewErrorModel()
                {
                    error = new Error(2, ex.Message, "")
                    {
                    },
                });
            }
        }
        public async Task <object> PrintAndSend([FromBody] PrintModel printAndSendModel)
        {
            try
            {
                string       TaskId    = printAndSendModel.TaskId;
                string       UserId    = printAndSendModel.UserId;
                PDFHelperNew pdfHelper = new PDFHelperNew();
                using (DDContext context = new DDContext())
                {
                    //获取表单信息
                    Tasks  tasks  = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First();
                    string FlowId = tasks.FlowId.ToString();

                    //判断流程是否已结束
                    List <Tasks> tasksList = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.State == 0 && t.IsSend == false).ToList();
                    if (tasksList.Count > 0)
                    {
                        return(new NewErrorModel()
                        {
                            error = new Error(1, "流程尚未结束", "")
                            {
                            },
                        });
                    }

                    List <OfficeSuppliesPurchase> OfficeSuppliesPurchaseList = context.OfficeSuppliesPurchase.Where(u => u.TaskId == TaskId).ToList();

                    var SelectGoDownList = from g in OfficeSuppliesPurchaseList
                                           select new
                    {
                        g.CodeNo,
                        g.Name,
                        g.Standard,
                        g.Unit,
                        g.Count,
                        g.Price
                    };
                    DataTable dtSourse = DtLinqOperators.CopyToDataTable(SelectGoDownList);
                    //ClassChangeHelper.ToDataTable(SelectPurchaseList);
                    List <NodeInfo> NodeInfoList = context.NodeInfo.Where(u => u.FlowId == FlowId && u.NodeId != 0 && u.IsSend != true && u.NodeName != "结束").ToList();
                    foreach (NodeInfo nodeInfo in NodeInfoList)
                    {
                        if (string.IsNullOrEmpty(nodeInfo.NodePeople))
                        {
                            string strNodePeople = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyMan;
                            string ApplyTime     = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime;
                            nodeInfo.NodePeople = strNodePeople + "  " + ApplyTime;
                        }
                        else
                        {
                            string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime;
                            nodeInfo.NodePeople = nodeInfo.NodePeople + "  " + ApplyTime;
                        }
                    }
                    DataTable dtApproveView = ClassChangeHelper.ToDataTable(NodeInfoList);
                    string    FlowName      = context.Flows.Where(f => f.FlowId.ToString() == FlowId).First().FlowName.ToString();

                    //绘制BOM表单PDF
                    List <string> contentList = new List <string>()
                    {
                        "序号", "物料编码", "物料名称", "规格型号", "单位", "数量", "预计单价"
                    };

                    float[] contentWithList = new float[]
                    {
                        50, 90, 90, 90, 60, 60, 60
                    };

                    float sum = 0;

                    foreach (var item in OfficeSuppliesPurchaseList)
                    {
                        sum += (float.Parse(item.Price) * float.Parse(item.Count));
                    }
                    Dictionary <string, string> keyValuePairs = new Dictionary <string, string>();
                    keyValuePairs.Add("总价", sum.ToString());

                    string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime,
                                                        null, null, "2", 300, 650, contentList, contentWithList, dtSourse, dtApproveView, null, keyValuePairs);
                    string RelativePath = "~/UploadFile/PDF/" + Path.GetFileName(path);

                    List <string> newPaths = new List <string>();
                    RelativePath = AppDomain.CurrentDomain.BaseDirectory + RelativePath.Substring(2, RelativePath.Length - 2).Replace('/', '\\');
                    newPaths.Add(RelativePath);
                    string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip", AppDomain.CurrentDomain.BaseDirectory, FlowName + DateTime.Now.ToString("yyyyMMddHHmmss"));
                    //文件压缩打包
                    IonicHelper.CompressMulti(newPaths, SavePath, false);


                    //上传盯盘获取MediaId
                    SavePath = string.Format(@"~\UploadFile\Ionic\{0}", Path.GetFileName(SavePath));
                    DingTalkServersController dingTalkServersController = new DingTalkServersController();
                    var resultUploadMedia = await dingTalkServersController.UploadMedia(SavePath);

                    //推送用户
                    FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia);
                    fileSendModel.UserId = UserId;
                    var result = await dingTalkServersController.SendFileMessage(fileSendModel);

                    return(new NewErrorModel()
                    {
                        error = new Error(0, result, "")
                        {
                        },
                    });
                }
            }
            catch (Exception ex)
            {
                return(new NewErrorModel()
                {
                    error = new Error(1, ex.Message, "")
                    {
                    },
                });
            }
        }
        public async Task <object> PrintAndSend([FromBody] PrintModel printAndSendModel)
        {
            try
            {
                string       TaskId    = printAndSendModel.TaskId;
                string       UserId    = printAndSendModel.UserId;
                PDFHelperNew pdfHelper = new PDFHelperNew();
                using (DDContext context = new DDContext())
                {
                    //获取表单信息
                    Tasks  tasks  = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 0).First();
                    string FlowId = tasks.FlowId.ToString();

                    //判断流程是否已结束
                    List <Tasks> tasksList = context.Tasks.Where(t => t.TaskId.ToString() == TaskId && t.State == 0 && t.IsSend == false).ToList();
                    if (tasksList.Count > 0)
                    {
                        return(new NewErrorModel()
                        {
                            error = new Error(1, "流程尚未结束", "")
                            {
                            },
                        });
                    }

                    CreateProject createProject = context.CreateProject.Where(u => u.TaskId == TaskId).First();


                    List <NodeInfo> NodeInfoList = context.NodeInfo.Where(u => u.FlowId == FlowId && u.NodeId != 0 && u.IsSend != true && u.NodeName != "结束").ToList();
                    foreach (NodeInfo nodeInfo in NodeInfoList)
                    {
                        if (string.IsNullOrEmpty(nodeInfo.NodePeople))
                        {
                            string strNodePeople = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyMan;
                            string ApplyTime     = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime;
                            nodeInfo.NodePeople = strNodePeople + "  " + ApplyTime;
                        }
                        else
                        {
                            string ApplyTime = context.Tasks.Where(q => q.TaskId.ToString() == TaskId && q.NodeId == nodeInfo.NodeId).First().ApplyTime;
                            nodeInfo.NodePeople = nodeInfo.NodePeople + "  " + ApplyTime;
                        }
                    }
                    DataTable dtApproveView = ClassChangeHelper.ToDataTable(NodeInfoList);
                    string    FlowName      = context.Flows.Where(f => f.FlowId.ToString() == FlowId).First().FlowName.ToString();

                    Dictionary <string, string> keyValuePairs = new Dictionary <string, string>();
                    keyValuePairs.Add("项目名称", createProject.ProjectName);
                    keyValuePairs.Add("项目编号", createProject.ProjectId);
                    keyValuePairs.Add("承担部门", createProject.DeptName);
                    keyValuePairs.Add("公司名称", createProject.CompanyName);
                    keyValuePairs.Add("项目类型", createProject.ProjectType);
                    keyValuePairs.Add("项目负责人", createProject.ResponsibleMan);
                    keyValuePairs.Add("项目组成员", createProject.TeamMembers);
                    keyValuePairs.Add("是否评审", createProject.IsReview == true ? "是" : "否");

                    string path = pdfHelper.GeneratePDF(FlowName, TaskId, tasks.ApplyMan, tasks.Dept, tasks.ApplyTime,
                                                        null, null, "2", 300, 650, null, null, null, dtApproveView, null, keyValuePairs);
                    string RelativePath = "~/UploadFile/PDF/" + Path.GetFileName(path);

                    List <string> newPaths = new List <string>();
                    RelativePath = AppDomain.CurrentDomain.BaseDirectory + RelativePath.Substring(2, RelativePath.Length - 2).Replace('/', '\\');
                    newPaths.Add(RelativePath);
                    string SavePath = string.Format(@"{0}\UploadFile\Ionic\{1}.zip", AppDomain.CurrentDomain.BaseDirectory, FlowName + DateTime.Now.ToString("yyyyMMddHHmmss"));
                    //文件压缩打包
                    IonicHelper.CompressMulti(newPaths, SavePath, false);

                    //上传盯盘获取MediaId
                    SavePath = string.Format(@"~\UploadFile\Ionic\{0}", Path.GetFileName(SavePath));
                    DingTalkServersController dingTalkServersController = new DingTalkServersController();
                    var resultUploadMedia = await dingTalkServersController.UploadMedia(SavePath);

                    //推送用户
                    FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia);
                    fileSendModel.UserId = UserId;
                    var result = await dingTalkServersController.SendFileMessage(fileSendModel);

                    return(new NewErrorModel()
                    {
                        error = new Error(0, result, "")
                        {
                        },
                    });
                }
            }
            catch (Exception ex)
            {
                return(new NewErrorModel()
                {
                    error = new Error(1, ex.Message, "")
                    {
                    },
                });
            }
        }