211 lines
4.9 KiB
C#
211 lines
4.9 KiB
C#
/////////////////////////////////////////////////////////////////////////////////
|
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
|
// https://git.tuotong-tech.com/tnb/tnb.server //
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
using JNPF.Common.Security;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Newtonsoft.Json;
|
|
using Tnb.Core;
|
|
|
|
namespace Tnb.Vengine.Domain;
|
|
|
|
public class VmBaseInput
|
|
{
|
|
/// <summary>
|
|
/// 附加参数
|
|
/// </summary>
|
|
public object? extra { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询单条数据的输入参数
|
|
/// </summary>
|
|
public class VmGetInput : VmBaseInput
|
|
{
|
|
/// <summary>
|
|
/// 要获取数据的id
|
|
/// </summary>
|
|
public string? id { get; set; }
|
|
|
|
/// <summary>
|
|
/// 过滤条件
|
|
/// </summary>
|
|
public DObject q { get; set; } = new DObject();
|
|
|
|
/// <summary>
|
|
/// 输出字段
|
|
/// </summary>
|
|
public string o { get; set; } = "*";
|
|
/// <summary>
|
|
/// 从HttpContext中加载查询参数
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
public void LoadFromHttpContext(HttpContext? context)
|
|
{
|
|
if (context == null) return;
|
|
var qStr = context.Request.Query["q"].ToString();
|
|
if (!string.IsNullOrEmpty(qStr))
|
|
{
|
|
var arg = JsonConvert.DeserializeObject<DObject>(qStr);
|
|
q.AddRange(arg);
|
|
}
|
|
string[] filter = new string[] { "id", "q", "o" };
|
|
foreach (var item in context.Request.Query.Where(a => !filter.Contains(a.Key)))
|
|
{
|
|
if (item.Value.Count > 1)
|
|
{
|
|
q[item.Key] = item.Value.ToArray();
|
|
}
|
|
else
|
|
{
|
|
q[item.Key] = item.Value.ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询列表数据的输入参数
|
|
/// </summary>
|
|
public class VmQueryInput : VmBaseInput
|
|
{
|
|
/// <summary>
|
|
/// 当前页数
|
|
/// </summary>
|
|
public int pnum { get; set; }
|
|
|
|
/// <summary>
|
|
/// 每页记录数
|
|
/// </summary>
|
|
public int psize { get; set; }
|
|
|
|
/// <summary>
|
|
/// 排序
|
|
/// </summary>
|
|
public string? sort { get; set; } = null;
|
|
|
|
/// <summary>
|
|
/// 模糊查询
|
|
/// </summary>
|
|
public string? k { get; set; }
|
|
|
|
/// <summary>
|
|
/// 过滤条件
|
|
/// </summary>
|
|
public DObject q { get; set; } = new DObject();
|
|
|
|
/// <summary>
|
|
/// 输出字段
|
|
/// </summary>
|
|
public string o { get; set; } = "*";
|
|
|
|
/// <summary>
|
|
/// 从HttpContext中加载查询参数
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
public void LoadFromHttpContext(HttpContext? context)
|
|
{
|
|
if (context == null) return;
|
|
var qStr = context.Request.Query["q"].ToString();
|
|
if (!string.IsNullOrEmpty(qStr))
|
|
{
|
|
var arg = JsonConvert.DeserializeObject<DObject>(qStr);
|
|
q.AddRange(arg);
|
|
}
|
|
string[] filter = new string[] { "pnum", "psize", "sort", "k", "q", "o" };
|
|
foreach (var item in context.Request.Query.Where(a => !filter.Contains(a.Key)))
|
|
{
|
|
if (item.Value.Count > 1)
|
|
{
|
|
q[item.Key] = item.Value.ToArray();
|
|
}
|
|
else
|
|
{
|
|
q[item.Key] = item.Value.ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增或修改数据输入参数
|
|
/// </summary>
|
|
public class VmEditInput : VmBaseInput
|
|
{
|
|
/// <summary>
|
|
/// 数据
|
|
/// </summary>
|
|
public DObject? data { get; set; }
|
|
|
|
/// <summary>
|
|
/// 批量添加
|
|
/// </summary>
|
|
public List<DObject>? items { get; set; }
|
|
|
|
public virtual VmEditInput ToEditInput()
|
|
{
|
|
return this;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除数据输入参数
|
|
/// </summary>
|
|
public class VmDeleteInput : VmBaseInput
|
|
{
|
|
/// <summary>
|
|
/// 要删除的数据id
|
|
/// </summary>
|
|
public string? id { get; set; }
|
|
|
|
/// <summary>
|
|
/// 要删除的id列表
|
|
/// </summary>
|
|
public List<string>? ids { get; set; }
|
|
}
|
|
|
|
public class PagedOutput
|
|
{
|
|
public int total { get; set; }
|
|
public object? extra { get; set; }
|
|
public static PagedOutput<T> Create<T>(int totalNum, List<T> ls)
|
|
{
|
|
return new PagedOutput<T>(totalNum, ls);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页列表输出对象
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
public class PagedOutput<T> : PagedOutput
|
|
{
|
|
public List<T> items { get; set; } = new List<T>();
|
|
|
|
public PagedOutput()
|
|
{
|
|
}
|
|
public PagedOutput(int totalNum, List<T> ls)
|
|
{
|
|
total = totalNum;
|
|
items = ls;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 动态分页列表输出对象
|
|
/// </summary>
|
|
public class VmPagedOutput : PagedOutput<DObject>
|
|
{
|
|
public PagedOutput<T> ToPagedOutput<T>()
|
|
{
|
|
return new PagedOutput<T>()
|
|
{
|
|
total = total,
|
|
items = items.Adapt<List<T>>()
|
|
};
|
|
}
|
|
}
|