/// <summary> /// 创建报告 /// </summary> /// <param name="tigerPath">目标路径</param> /// <returns></returns> public Result CreatReport(string tigerPath) { return(RunFun(logpath => { tigerPath = ToolFile.GetAbsolutelyPath(tigerPath); string modthPath = ToolFile.GetUpIndex(base.ModelPath, 1) + "Custom\\宝龙-满意度版块PDF的副本.rdl"; string sqlStr = @" Select distinct r.FormReportItemID,c.Text From AskForm_FormReportItemParam r INNER JOIN AskForm_Choice c ON c.ChoiceID = r.[Value] Where r.CompanyID=@CompanyID And r.FormApplicationID =@FormApplicationID And r.IsDeleted=0"; DataTable dt = DbContent.GetTable(GetSqlParam() + sqlStr); foreach (DataRow dr in dt.Rows) { ReportParameterCollection reportParameters = new ReportParameterCollection { new ReportParameter("CompanyID", @CompanyID), new ReportParameter("FormApplicationID", FormApplicationID), new ReportParameter("FormID", FormID), new ReportParameter("MinValue", "0"), new ReportParameter("ReportTitle", "板块报告"), new ReportParameter("FormReportItemID", dr["FormReportItemID"] + "") }; ToolReport.GenerateLocalReport(modthPath, tigerPath, dr["Text"] + ".pdf", reportParameters, true); } return Res; })); }
/// <summary> /// 检查报告是否全部生成 /// </summary> /// <param name="tigerPath"></param> /// <param name="formId"></param> /// <returns></returns> public Result CheckReportIsAll(string tigerPath, long formId) { return(RunFun(logPath => { tigerPath = ToolFile.GetAbsolutelyPath(tigerPath); List <FileInfo> list = new DirectoryInfo(tigerPath).GetFiles().ToList(); DataRow dr = GetFormInfo(formId); DataTable dt = DbContent.GetTable(string.Format(GetObservedList(), dr["CompanyID"] + "", dr["FormApplicationID"] + "")); WriteLog(logPath, "共" + dt.Rows.Count + "人"); foreach (DataRow item in dt.Rows) { string name = item["FullName"] + "_" + item["EntryID"]; if (!list.Exists(c => c.Name.Contains(name))) { WriteLog(logPath, name); } } return Res; })); }
/// <summary> /// 生成报告 /// </summary> /// <param name="modelPath">报告模板</param> /// <param name="tigerPath">生成地址</param> /// <param name="formId">问卷编号</param> /// <param name="entryId">被评估人编号</param> /// <param name="suffix">报告格式</param> /// <param name="maxLength">最多生成报告数,0为不限制</param> /// <returns></returns> public Result CreateReport(string modelPath, string tigerPath, long formId, long entryId, string suffix, int maxLength) { return(RunFun(logPath => { tigerPath = ToolFile.GetAbsolutelyPath(tigerPath); modelPath = base.ModelPath + modelPath; DataRow dr = GetFormInfo(formId); if (entryId > 0) { ReportParameterCollection col = new ReportParameterCollection { new ReportParameter("CompanyID", dr["CompanyID"] + ""), new ReportParameter("FormApplicationID", dr["FormApplicationID"] + ""), new ReportParameter("FormID", dr["FormID"] + ""), new ReportParameter("ObservedID", entryId + ""), new ReportParameter("EntryID", entryId + ""), new ReportParameter("MinValue", "1") }; col = ToolReport.BindPara(modelPath, col); ToolReport.GenerateLocalReport(modelPath, tigerPath, entryId + "." + suffix, col, false); } else { DataTable dt = DbContent.GetTable(string.Format(GetObservedList(), dr["CompanyID"] + "", dr["FormApplicationID"] + "")); int con = 0; foreach (DataRow item in dt.Rows) { if (maxLength > 0 && con >= maxLength) { break; } ReportParameterCollection col = new ReportParameterCollection { new ReportParameter("CompanyID", dr["CompanyID"] + ""), new ReportParameter("FormApplicationID", dr["FormApplicationID"] + ""), new ReportParameter("FormID", dr["FormID"] + ""), new ReportParameter("ObservedID", item["EntryID"] + ""), new ReportParameter("EntryID", item["EntryID"] + ""), new ReportParameter("MinValue", "1") }; col = ToolReport.BindPara(modelPath, col); con++; WriteLog(logPath, dt.Rows.IndexOf(item) + "\t" + item["FullName"] + "_" + item["EntryID"]); ToolReport.GenerateLocalReport(modelPath, tigerPath, item["FullName"] + "_" + item["EntryID"] + "." + suffix, col, false); } } return Res; })); }
/// <summary> /// 写入日志 /// </summary> /// <param name="logPath">日志路径</param> /// <param name="msg">日志消息</param> /// <param name="append">是否追加</param> /// <param name="hasDate">是否包含时间</param> protected void WriteLog(string logPath, string msg, bool append = true, bool hasDate = true) { logPath = ToolFile.GetAbsolutelyPath(logPath); if (File.Exists(logPath) && !append) { File.Delete(logPath); } ToolFile.CreatFile(logPath, (hasDate ? (DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")) + "\t\t" : "") + msg, true); }
/// <summary> /// 生成团队报告 /// </summary> /// <param name="modelPath">报告模板</param> /// <param name="tigerPath">生成地址</param> /// <param name="formId">问卷编号</param> /// <param name="suffix">报告格式</param> /// <returns></returns> public Result CreateTeamReport(string modelPath, string tigerPath, long formId, string suffix) { return(RunFun(logPath => { tigerPath = ToolFile.GetAbsolutelyPath(tigerPath); modelPath = base.ModelPath + modelPath; string sqlFilter = $"SELECT * FROM AskForm_FormFilter ff WHERE ff.FormID = {formId} AND ff.Name LIKE '%FieldFilter%' AND ff.IsDeleted = 0"; DataTable dtFilter = DbContent.GetTable(sqlFilter); // 循环过滤条件 foreach (DataRow filter in dtFilter.Rows) { ReportParameterCollection col = new ReportParameterCollection { new ReportParameter("CompanyID", filter["CompanyID"] + ""), new ReportParameter("FormApplicationID", filter["FormApplicationID"] + ""), new ReportParameter("FormID", filter["FormID"] + ""), new ReportParameter("FormFilterID", filter["FormFilterID"] + ""), new ReportParameter("MinValue", "1") }; col = ToolReport.BindPara(modelPath, col); // 获取过滤字段 string sqlField = $"SELECT f.FieldID,f.Title,fff.Content FROM AskForm_FormFilterField fff INNER JOIN AskForm_Field f ON f.FieldID = fff.FieldID WHERE FormFilterID = {filter["FormFilterID"]} AND fff.IsDeleted = 0"; DataTable dtField = DbContent.GetTable(sqlField); // 循环字段 foreach (DataRow field in dtField.Rows) { string sqlContent = $"SELECT distinct [Value] FROM AskForm_EntryText et WHERE et.FieldID = {field["FieldID"]} AND et.IsDeleted = 0"; DataTable dtContent = DbContent.GetTable(sqlContent); // 循环内容 foreach (DataRow content in dtContent.Rows) { // 修改内容 string sqlUpFilterField = $"UPDATE AskForm_FormFilterField SET Content='{content["Value"]}' WHERE FormFilterID = {filter["FormFilterID"]} AND FieldID ={field["FieldID"]} "; WriteLog(logPath, "修改【" + field["Title"] + "】为【" + content["Value"] + "】," + DbContent.ExecuteNonQuery(sqlUpFilterField)); ToolReport.GenerateLocalReport(modelPath, tigerPath, field["Title"] + "_" + content["Value"] + "." + suffix, col, false); } } } return Res; })); }
/// <summary> /// 获取所有文件 /// </summary> /// <param name="dirPath">文件夹路径</param> /// <param name="suffix">文件后缀</param> /// <returns></returns> public Result GetDirFileName(string dirPath, string suffix) { return(RunFun((logPath) => { DirectoryInfo info = new DirectoryInfo(ToolFile.GetAbsolutelyPath(dirPath)); if (info == null) { Res.Msg = "文件夹不存在"; return Res; } if (string.IsNullOrWhiteSpace(suffix)) { suffix = ""; } suffix = suffix.Replace(".", "").Trim().ToLower(); string tmp = string.Format(SegmentingLine, "不包含的文件") + "\n"; foreach (var item in info.GetFiles().OrderByDescending(c => c.FullName)) { if (string.IsNullOrWhiteSpace(suffix) || ToolFile.GetSuffix(item.FullName).ToLower() == suffix) { WriteLog(logPath, item.Name, true, false); } else { tmp += item.FullName + "\t" + item.CreationTime + "\n"; } } tmp += string.Format(SegmentingLine, "") + "\n"; WriteLog(logPath, tmp, true, false); return Res; })); }
/// <summary> /// 提取日志文件 /// </summary> /// <param name="path">日志文件路径</param> /// <param name="targetPath">日志提取路径</param> /// <param name="str">包含的字符串</param> /// <returns></returns> public Result FilterLog(string path, string targetPath, string str) { return(RunFun((logPath) => { DirectoryInfo dirinfo = new DirectoryInfo(ToolFile.GetAbsolutelyPath(path)); foreach (FileInfo file in dirinfo.GetFiles()) { List <string> list = File.ReadAllLines(file.FullName).ToList(); int count = 0; foreach (var line in list) { if (line.ToUpper().IndexOf(str, StringComparison.InvariantCultureIgnoreCase) > 0) { WriteLog(ToolFile.GetAbsolutelyPath(targetPath) + "Res_" + file.Name, line, true); } count++; } } return Res; })); }
/// <summary> /// 移动文件 /// </summary> /// <param name="logFile">日志文件</param> /// <param name="filePath">原始文件夹路径</param> /// <param name="targetPath">目标文件夹</param> /// <returns></returns> public Result MoveFile(string logFile, string filePath, string targetPath) { return(RunFun((logPath) => { List <FileInfo> fileList = new DirectoryInfo(filePath).GetFiles().ToList(); List <string> lines = File.ReadAllLines(ToolFile.GetAbsolutelyPath(logFile)).ToList(); foreach (var item in lines) { FileInfo file = fileList.Where(c => item.ToLower().Contains(c.Name.ToLower())).FirstOrDefault(); if (file != null) { continue; //file.CopyTo(ToolFile.GetAbsolutelyPath(targetPath) + file.Name, true); } else { WriteLog(logPath, item, true, false); } } return Res; })); }
/// <summary> /// 返回Excel文本 /// </summary> /// <param name="dirPath"></param> /// <param name="length">被评估人信息长度</param> /// <returns></returns> public Result GetExcelTxt(string dirPath, int length) { return(RunFun(logPath => { dirPath = ToolFile.GetAbsolutelyPath(dirPath); if (!Directory.Exists(dirPath)) { Res.Msg = "文件夹不存在"; return Res; } // 获取所有子文件夹 List <DirectoryInfo> listDir = new DirectoryInfo(dirPath).GetDirectories().ToList(); foreach (var dir in listDir) { // 获取待整理的名单文件 List <FileInfo> fileList = dir.GetFiles().Where(c => c.Name.Contains("_") && c.Extension.ToLower().Contains("txt") && !c.Name.Contains("Res")).ToList(); // 循环名单文件 foreach (var file in fileList) { List <ExcelFormat> excelList = new List <ExcelFormat>(); //WriteLog(logPath, file.FullName); // 循环行 foreach (var line in File.ReadAllLines(file.FullName)) { List <ExcelFormat> tmpList = new List <ExcelFormat>(); // 获取被评估人信息 string[] edArr = line.Split(' ').Where(c => !string.IsNullOrWhiteSpace(c)).Select(c => c.Replace(" ", "")).ToArray(); if (edArr.Length != length) { WriteLog(logPath, file.FullName + "\t" + "被评估人信息\t" + line); continue; } string t = "名单"; if (edArr[4].Contains(t)) { string name = ToolString.GetLetter(edArr[4]); for (int i = 0; i < name.Length; i++) { // 循环名单列表 foreach (var nameLine in File.ReadAllLines(ToolFile.GetAbsolutelyPath(file.DirectoryName) + t + name[i] + ".txt")) { string[] nameArr = nameLine.Split(' ').Where(c => !string.IsNullOrWhiteSpace(c)).Select(c => c.Replace(" ", "")).ToArray(); if (nameArr.Length != 2) { WriteLog(logPath, file.FullName + "\t" + line + "\t" + "循环名单列表\t" + nameLine); continue; } if (edArr[1] == nameArr[1]) { WriteLog(logPath, file.FullName + "\t" + edArr[1] + "\t" + "重名\t" + name[i] + ".txt"); continue; } ExcelFormat excel = new ExcelFormat(); // 基础信息 excel.ObservedDepartment = edArr[0]; excel.ObservedName = edArr[1]; excel.Mapping = edArr[2]; excel.Weight = edArr[3]; excel.ObserverDepartment = nameArr[0]; excel.ObserverName = nameArr[1]; tmpList.Add(excel); } } } else { // 添加分割属性 edArr[4] += "、"; // 获取多评估人信息, string[] erArr = edArr[4].Split('、').Where(c => !string.IsNullOrWhiteSpace(c)).ToArray(); foreach (var er in erArr) { ExcelFormat excel = new ExcelFormat(); // 基础信息 excel.ObservedDepartment = edArr[0]; excel.ObservedName = edArr[1]; excel.Mapping = edArr[2]; excel.Weight = edArr[3]; excel.ObserverName = er; tmpList.Add(excel); } } excelList.AddRange(tmpList); } ExcelFormat.CreateText(ToolFile.GetAbsolutelyPath(file.DirectoryName) + "Res" + file.Name, excelList); } } return Res; })); }
/// <summary> /// 报告分组 /// </summary> /// <param name="tigerPath">文件夹</param> /// <param name="group">分组条件,多个用','分割</param> /// <param name="max">文件夹最大占用</param> /// <returns></returns> public Result ReportGroup(string tigerPath, string group, double max) { return(RunFun(logpath => { string res = "分组" + DateTime.Now.Millisecond + "\\"; tigerPath = ToolFile.GetAbsolutelyPath(tigerPath); DirectoryInfo dir = new DirectoryInfo(tigerPath); // 移除所有文件夹 while (dir.GetDirectories().Length > 0) { Directory.Delete(dir.GetDirectories()[0].FullName, true); } List <string> groupList = group.Split(',').Where(c => !string.IsNullOrWhiteSpace(c)).ToList(); Dictionary <string, long> dic = new Dictionary <string, long>(); List <Task> taskList = new List <Task>(); for (int i = 0; i < dir.GetFiles().Length; i++) { WriteLog(logpath, i + ""); string path = tigerPath + res; FileInfo field = dir.GetFiles()[i]; List <string> nameList = field.Name.Replace("." + ToolFile.GetSuffix(field.Name), "").Split('_').Where(c => !string.IsNullOrWhiteSpace(c)).ToList(); if (nameList.Count != 2) { WriteLog(logpath, field.Name); continue; } DataRow dr = GetEntryInfo(nameList[1]); foreach (var item in groupList) { if (dr.Table.Columns.Contains(item)) { path += dr[item] + "\\"; } } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } else { if (dic.Keys.Contains(path) && max > 0) { double memory = dic[path] * 1.0; if (max * 1024 * 1024 < memory + field.Length) { path = ToolString.RemoveCharAfter(path, "\\", true) + "(" + dic.Keys.Where(c => c.Contains(path)).Count() + ")\\"; Directory.CreateDirectory(path); } } } if (dic.Keys.Contains(path)) { dic[path] += field.Length; } else { dic.Add(path, field.Length); } taskList.Add(Task.Run(() => { File.Copy(field.FullName, path + field.Name, true); })); } Task.WaitAll(taskList.ToArray()); dir = new DirectoryInfo(tigerPath + res); foreach (var key in dic.Keys) { WriteLog(logpath, (dic[key] * 1.0 / 1020 / 1024) + "M\t" + key); } return Res; })); }