Skip to content

Commit

Permalink
用import导入脚本分割template.xml。添加pg的crud模板
Browse files Browse the repository at this point in the history
  • Loading branch information
NoneDay committed Nov 21, 2024
1 parent 682d9f0 commit 3bbd52a
Show file tree
Hide file tree
Showing 17 changed files with 688 additions and 731 deletions.
Binary file modified end/CellReport.dll
Binary file not shown.
199 changes: 91 additions & 108 deletions end/reportWeb/Controllers/DesignController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,74 +339,58 @@ public IActionResult test_expr(String expr, int line, int column, string word)

public async Task<IActionResult> exec_expr(String expr, String report_content)
{
Env report_env = null;
try
{
BaseExprFaced exprFaced;

CellReport.dataSet.GroupMap cur_GroupMap = null;


if (String.IsNullOrEmpty(report_content))
{
exprFaced = new ExprFaced2();
exprFaced.addNewScopeForScript();
report_env = new Env("exec_expr1");
cur_GroupMap = new();
exprFaced.addVariable("env", report_env);
exprFaced.addVariable("__env__", report_env);
exprFaced.addVariable("_user_", null);
exprFaced.addVariable("_zb_url_", configuration["zb_url"]);
exprFaced.addVariable("_zb_user_", rpt_group.zb_user);
exprFaced.addVariable("_zb_password_", rpt_group.zb_password);
exprFaced.addVariable("_zb_var_", new Dictionary<String, object>());
exprFaced.addVariable("_rpt_group_", rpt_group);
exprFaced.getVariableDefine("__page__").value = HttpContext.Request;

}
else
{
System.Xml.XmlDocument xmlDoc = Content2XmlDoc(report_content);
string reportName = null;
if (reportName != null && reportName.Contains(":"))
reportName = reportName.Split(":")[1];
using var reportDefine = await XmlReport.loadReportFromXmlDoc(xmlDoc, this.rpt_group.report_path, reportName ?? "temp.cr");
report_env = reportDefine.getEnv();
exprFaced = report_env.getExprFaced();
exprFaced.getVariableDefine("__page__").value = HttpContext.Request;
exprFaced.addVariableForRoot("_page_size_", getFormValue("_page_size_"));
exprFaced.addVariableForRoot("_cur_page_num_", getFormValue("_cur_page_num_"));
cur_GroupMap = report_env.getDataSetResultMap();
}
object exec_result = null;
if (String.IsNullOrEmpty(report_content))
{
BaseExprFaced exprFaced = new ExprFaced2();
exprFaced.addNewScopeForScript();
using Env report_env = new Env("exec_expr1");
CellReport.dataSet.GroupMap cur_GroupMap = new();
exprFaced.addVariable("env", report_env);
exprFaced.addVariable("__env__", report_env);
exprFaced.addVariable("_user_", null);
exprFaced.addVariable("_zb_url_", configuration["zb_url"]);
exprFaced.addVariable("_zb_user_", rpt_group.zb_user);
exprFaced.addVariable("_zb_password_", rpt_group.zb_password);
exprFaced.addVariable("_zb_var_", new Dictionary<String, object>());
exprFaced.addVariable("_rpt_group_", rpt_group);
exprFaced.getVariableDefine("__page__").value = HttpContext.Request;
report_env.logger = logger;
foreach (var one in this.rpt_group.db_connection_list)
{
report_env.addDataSource(one.name, one.conn_str, one.db_type, "0", one.sql_prefix, one.sql_suffix);
}

var exec_result = exprFaced.calculate("{ " + expr + "\n}", cur_GroupMap, "当前脚本");
exec_result = exprFaced.calculate("{ " + expr + "\n}", cur_GroupMap, "当前脚本");
if (exec_result is Exception ex)
{
throw ex;
}
return Json(new { errcode = 0, message = "", result = exec_result }, json_option);
}
catch (Exception ex)
else
{
StringBuilder sb_err = new();
sb_err.AppendLine(ex.Message);
while (ex.InnerException != null)
System.Xml.XmlDocument xmlDoc = Content2XmlDoc(report_content);
string reportName = null;
if (reportName != null && reportName.Contains(":"))
reportName = reportName.Split(":")[1];
using var reportDefine = await XmlReport.loadReportFromXmlDoc(xmlDoc, this.rpt_group.report_path, reportName ?? "temp.cr");
using Env report_env = reportDefine.getEnv();
BaseExprFaced exprFaced = report_env.getExprFaced();
exprFaced.getVariableDefine("__page__").value = HttpContext.Request;
exprFaced.addVariableForRoot("_page_size_", getFormValue("_page_size_"));
exprFaced.addVariableForRoot("_cur_page_num_", getFormValue("_cur_page_num_"));
CellReport.dataSet.GroupMap cur_GroupMap = report_env.getDataSetResultMap();
report_env.logger = logger;
foreach (var one in this.rpt_group.db_connection_list)
{
ex = ex.InnerException;
sb_err.AppendLine(ex.Message);
report_env.addDataSource(one.name, one.conn_str, one.db_type, "0", one.sql_prefix, one.sql_suffix);
}
exec_result = exprFaced.calculate("{ " + expr + "\n}", cur_GroupMap, "当前脚本");
if (exec_result is Exception ex)
{
throw ex;
}
return Json(new { errcode = 1, message = sb_err.ToString() }, json_option);
}
finally
{
if (report_env != null)
report_env.Dispose();
}
return Json(new { errcode = 0, message = "", result = exec_result }, json_option);
}
public IActionResult exec_cmd(String cmd, string from, string to)
{
Expand Down Expand Up @@ -677,68 +661,67 @@ private async Task insert_ds_param(string reportName, string zb_dict_str, string
xmlDoc.Save(file_path);

}
public async Task<IActionResult> Save(String reportName, String content, String cur_version, IFormFile imgFile, string desc)
public async Task<IActionResult> Save(String reportName, String content, IFormFile imgFile, String cur_version, String last_version, string desc)
{
if (reportName.StartsWith("/"))
reportName = reportName.Substring(1);
if (!Directory.Exists(this.rpt_group.report_path))
Directory.CreateDirectory(this.rpt_group.report_path);
var file_path = Path.Combine(this.rpt_group.report_path, reportName);

if (file_path.StartsWith(this.rpt_group.report_path))
{
var fileInfo = new FileInfo(file_path);
if (!Directory.Exists(fileInfo.DirectoryName))
Directory.CreateDirectory(fileInfo.DirectoryName);
if (imgFile != null)
{
using (var stream = System.IO.File.Create(file_path + ".jpg"))
{
await imgFile.CopyToAsync(stream);
}
return Json(new { errcode = 0, message = "保存图片成功" }); ;
}
var now_time = DateTime.Now;
var all_versions = ReportVersions(reportName);
var LastWriteTime = fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
var interval_day = TimeSpan.FromDays(configuration.GetValue<double>("auto_save_interval_day", 7.0d));
var back_file_path = Path.Combine(this.rpt_group.report_path, ".backup", reportName + now_time.ToString("yyyy_MM_dd_HH_mm_ss"));
var back_fileInfo = new FileInfo(back_file_path);
if (!Directory.Exists(back_fileInfo.DirectoryName))
Directory.CreateDirectory(back_fileInfo.DirectoryName);

if (fileInfo.Exists && fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss") != cur_version)
{//旧版本报表覆盖新版本报表,先备份旧版本
System.IO.File.Copy(file_path, back_file_path);
System.IO.File.AppendAllLines(Path.Combine(this.rpt_group.report_path, ".backup", reportName + "_desc")
, new String[] { version_split + now_time.ToString("yyyy-MM-dd HH:mm:ss"),
$"恢复旧版本【{cur_version}】前的备份"
});
}
else if (fileInfo.Exists && now_time - fileInfo.LastWriteTime > interval_day)
{//超过指定间隔时间
System.IO.File.Copy(file_path, back_file_path);
System.IO.File.AppendAllLines(Path.Combine(this.rpt_group.report_path, ".backup", reportName + "_desc")
, new String[] { version_split + now_time.ToString("yyyy-MM-dd HH:mm:ss"),
$"间隔超过{interval_day}天自动对【{LastWriteTime}】备份"
});
}
//保存报表
System.Xml.XmlDocument xmlDoc = Content2XmlDoc(content.Replace("\r", ""));
xmlDoc.Save(file_path);

if (!string.IsNullOrWhiteSpace(desc))
{//如果有版本描述,备份当前报表
System.IO.File.Copy(file_path, back_file_path);
System.IO.File.AppendAllLines(Path.Combine(this.rpt_group.report_path, ".backup", reportName + "_desc")
, new String[] { version_split + now_time.ToString("yyyy-MM-dd HH:mm:ss"), desc });
}
XmlReport.MemoryCacheInstance.Remove(file_path);
return Json(new { errcode = 0, message = "保存成功", versions = ReportVersions(reportName) });
}
return Json(new { errcode = 1, message = "路径错误" });

if (!file_path.StartsWith(this.rpt_group.report_path))
return Json(new { errcode = 1, message = "路径错误" });
var fileInfo = new FileInfo(file_path);
var LastWriteTime = fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
if (fileInfo.Exists && last_version != LastWriteTime)
return Json(new { errcode = 1, message = "报表已被更改,请重载后重试!" });

if (!Directory.Exists(fileInfo.DirectoryName))
Directory.CreateDirectory(fileInfo.DirectoryName);
if (imgFile != null)
{
using (var stream = System.IO.File.Create(file_path + ".jpg"))
{
await imgFile.CopyToAsync(stream);
}
return Json(new { errcode = 0, message = "保存图片成功" });
}
var now_time = DateTime.Now;
var all_versions = ReportVersions(reportName);
var interval_day = TimeSpan.FromDays(configuration.GetValue<double>("auto_save_interval_day", 7.0d));
var back_file_path = Path.Combine(this.rpt_group.report_path, ".backup", reportName + now_time.ToString("yyyy_MM_dd_HH_mm_ss"));
var back_fileInfo = new FileInfo(back_file_path);
if (!Directory.Exists(back_fileInfo.DirectoryName))
Directory.CreateDirectory(back_fileInfo.DirectoryName);

if (fileInfo.Exists && last_version != cur_version)
{//旧版本报表覆盖新版本报表,先备份旧版本
System.IO.File.Copy(file_path, back_file_path);
System.IO.File.AppendAllLines(Path.Combine(this.rpt_group.report_path, ".backup", reportName + "_desc")
, new String[] { version_split + now_time.ToString("yyyy-MM-dd HH:mm:ss"),
$"恢复旧版本【{cur_version}】前的备份"
});
}
else if (fileInfo.Exists && now_time - fileInfo.LastWriteTime > interval_day)
{//超过指定间隔时间
System.IO.File.Copy(file_path, back_file_path);
System.IO.File.AppendAllLines(Path.Combine(this.rpt_group.report_path, ".backup", reportName + "_desc")
, new String[] { version_split + now_time.ToString("yyyy-MM-dd HH:mm:ss"),
$"间隔超过{interval_day}天自动对【{LastWriteTime}】备份"
});
}
//保存报表
System.Xml.XmlDocument xmlDoc = Content2XmlDoc(content.Replace("\r", ""));
xmlDoc.Save(file_path);

if (!string.IsNullOrWhiteSpace(desc))
{//如果有版本描述,备份当前报表
System.IO.File.Copy(file_path, back_file_path);
System.IO.File.AppendAllLines(Path.Combine(this.rpt_group.report_path, ".backup", reportName + "_desc")
, new String[] { version_split + now_time.ToString("yyyy-MM-dd HH:mm:ss"), desc });
}
XmlReport.MemoryCacheInstance.Remove(file_path);
return Json(new { errcode = 0, message = "保存成功", versions = ReportVersions(reportName) });
}
private static string version_split = "=========版本说明============";
static System.Xml.XmlDocument Content2XmlDoc(string content)
Expand Down
2 changes: 1 addition & 1 deletion end/reportWeb/Pages/ReportModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public async Task Page_Load()
//Console.WriteLine("before_exec:" + (DateTime.Now - start_time) / 10000 + "秒");
if (false == pre_page_load())
return;
if (exprFaced.hasVariable("before_exec"))
if (report_name != "/" && exprFaced.hasVariable("before_exec"))
{
before_exec_result =exprFaced.calculate("=before_exec()", report_env.getDataSetResultMap()) as CR_Object;
if (before_exec_result != null)
Expand Down
81 changes: 41 additions & 40 deletions end/reportWeb/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Expressions" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"reportWeb": "Information",
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft": "Warning",
"System": "Warning"
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Expressions" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"reportWeb": "Information",
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft": "Warning",
"System": "Warning"

}
},
"WriteTo": [
{ "Name": "Console" }, //,{"Name": "File", "Args": { "path": "Logs/log.txt" } }
{
"Name": "File",
"Args": {
"path": "Logs/error.txt",
"rollingInterval": "Day",
"RestrictedToMinimumLevel": "Warning",
"outputTemplate": "{Timestamp:HH:mm:ss.fff} [{Level}] {Message} {NewLine}"
}
}
]
}
},
"aes_key": "ONxYDyNaCoyTzsp83JoQ3YYuMPHxk3j7",
"AllowedHosts": "*",
"cache_prefix": "report5",
"Jwt": {
"Issuer": "issuer",
"Audience": "audience",
"SigningKey": "c0d32c63-z43d-4917-bbc2-5e726d087452",
"Expires": 10080,
"ValidateLifetime": true
},
//"redis_str": "127.0.0.1:6379,password=",
"zb_url": "",
"admin_user": "admin",
"admin_password": "database!123",
//"static_path": "",
"WriteTo": [
{ "Name": "Console" }, //,{"Name": "File", "Args": { "path": "Logs/log.txt" } }
{
"Name": "File",
"Args": {
"path": "Logs/error.txt",
"rollingInterval": "Day",
"RestrictedToMinimumLevel": "Warning",
"outputTemplate": "{Timestamp:HH:mm:ss.fff} [{Level}] {Message} {NewLine}"
}
}
]
},
"aes_key": "ONxYDyNaCoyTzsp83JoQ3YYuMPHxk3j7",
"AllowedHosts": "*",
"cache_prefix": "report5",
"Jwt": {
"Issuer": "issuer",
"Audience": "audience",
"SigningKey": "c0d32c63-z43d-4917-bbc2-5e726d087452",
"Expires": 10080,
"ValidateLifetime": true
},
//"redis_str": "127.0.0.1:6379,password=",
"zb_url": "",
"admin_user": "admin",
"admin_password": "database!123",
"auto_save_interval_day": 1.0,
//"static_path": "",
"DbProviderFactories": [
{
"name": "SqlClient",
Expand All @@ -52,7 +53,7 @@
"dllName": "Oracle.ManagedDataAccess",
"FactoryClass": "Oracle.ManagedDataAccess.Client.OracleClientFactory",
"InstanceName": "Instance",
"link_str": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ip地址)(PORT=端口))(CONNECT_DATA=(SERVER = SERVER名字)(SERVICE_NAME = 数据库)));User Id=用户;Password=口令;",
"link_str": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ip地址)(PORT=端口))(CONNECT_DATA=(SERVER = SERVER名字)(SERVICE_NAME = 数据库)));User Id=用户;Password=口令;"
},
{
"name": "Npgsql",
Expand All @@ -74,7 +75,7 @@
"dllName": "System.Data.Odbc",
"FactoryClass": "System.Data.Odbc.OdbcFactory",
"InstanceName": "Instance",
"link_str":"Dsn=odbc数据源名称;"
"link_str": "Dsn=odbc数据源名称;"
},
{
"name": "DaMeng",
Expand Down
10 changes: 8 additions & 2 deletions end/reportWeb/reportWeb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.1" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.7" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="6.0.7" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.10" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="8.0.10" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.2" />
<PackageReference Include="MySqlConnector" Version="2.3.5" />
<PackageReference Include="Npgsql" Version="6.0.11" />
Expand Down Expand Up @@ -60,6 +60,12 @@
<None Update="template.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="t_before_exec.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="t_crud.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand Down
11 changes: 11 additions & 0 deletions end/reportWeb/t_before_exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function download_img(url) {
var result = web_request({ 'url': url, 'raw': true });
if (result.GetType().ToString().Contains("Exception"))
return { 'errcode': -1, 'message': result.Message };
var content_type = result.response.Content.Headers['ContentType']['MediaType'];
if (content_type.StartsWith('image/'))
return { 'data': result.content, 'type': content_type };
else
return { 'errcode': -1, 'message': "不是图片类型:" + content_type };
}
return { download_img };
Loading

0 comments on commit 3bbd52a

Please sign in to comment.