Merge branch 'dev' of https://git.tuotong-tech.com/tnb/tnb.server into dev
This commit is contained in:
@@ -183,6 +183,11 @@ public static class DictConst
|
|||||||
/// 模具维修TypeId
|
/// 模具维修TypeId
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string WXTypeId = "26149320818965";
|
public const string WXTypeId = "26149320818965";
|
||||||
|
/// <summary>
|
||||||
|
/// 设备维修状态
|
||||||
|
/// </summary>
|
||||||
|
public const string RepairStatus = "RepairStatus";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
namespace Tnb.EquipMgr.Entities.Dto
|
||||||
|
{
|
||||||
|
public class PdaRepairApplyListOutput
|
||||||
|
{
|
||||||
|
public string id { get; set; }
|
||||||
|
public string code { get; set; }
|
||||||
|
public string name { get; set; }
|
||||||
|
public string equip_id { get; set; }
|
||||||
|
public string equip_id_id { get; set; }
|
||||||
|
public string? expect_complete_time { get; set; }
|
||||||
|
public string? is_ugent { get; set; }
|
||||||
|
public string description { get; set; }
|
||||||
|
public string status { get; set; }
|
||||||
|
public string repairer_id { get; set; }
|
||||||
|
public string? repairer_id_id { get; set; }
|
||||||
|
|
||||||
|
public string apply_user_id { get; set; }
|
||||||
|
public string apply_user_id_id { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
119
EquipMgr/Tnb.EquipMgr/App/AppEqpRepairApplyService.cs
Normal file
119
EquipMgr/Tnb.EquipMgr/App/AppEqpRepairApplyService.cs
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
using JNPF.Common.Core.Manager;
|
||||||
|
using JNPF.Common.Enums;
|
||||||
|
using JNPF.Common.Filter;
|
||||||
|
using JNPF.Common.Security;
|
||||||
|
using JNPF.DependencyInjection;
|
||||||
|
using JNPF.DynamicApiController;
|
||||||
|
using JNPF.FriendlyException;
|
||||||
|
using JNPF.Systems.Entitys.Permission;
|
||||||
|
using JNPF.Systems.Entitys.System;
|
||||||
|
using JNPF.VisualDev;
|
||||||
|
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
||||||
|
using JNPF.VisualDev.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using SqlSugar;
|
||||||
|
using Tnb.BasicData;
|
||||||
|
using Tnb.EquipMgr.Entities;
|
||||||
|
using Tnb.EquipMgr.Entities.Dto;
|
||||||
|
using Tnb.EquipMgr.Interfaces;
|
||||||
|
|
||||||
|
namespace Tnb.EquipMgr
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// app设备维修登记
|
||||||
|
/// </summary>
|
||||||
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||||
|
[Route("api/[area]/[controller]/[action]")]
|
||||||
|
[OverideVisualDev(ModuleId)]
|
||||||
|
public class AppEqpRepairApplyService : IOverideVisualDevService,IDynamicApiController, ITransient
|
||||||
|
{
|
||||||
|
private const string ModuleId = "28621611210261";
|
||||||
|
private readonly ISqlSugarRepository<EqpRepairApply> _repository;
|
||||||
|
private readonly IUserManager _userManager;
|
||||||
|
private readonly IRunService _runService;
|
||||||
|
private readonly IVisualDevService _visualDevService;
|
||||||
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||||||
|
|
||||||
|
public AppEqpRepairApplyService(ISqlSugarRepository<EqpRepairApply> repository,
|
||||||
|
IRunService runService,
|
||||||
|
IVisualDevService visualDevService,
|
||||||
|
IUserManager userManager)
|
||||||
|
{
|
||||||
|
_repository = repository;
|
||||||
|
_userManager = userManager;
|
||||||
|
_runService = runService;
|
||||||
|
_visualDevService = visualDevService;
|
||||||
|
OverideFuncs.GetListAsync = GetList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
|
||||||
|
{
|
||||||
|
var db = _repository.AsSugarClient();
|
||||||
|
Dictionary<string, object> queryJson = !string.IsNullOrEmpty(input.queryJson) ? JsonConvert.DeserializeObject<Dictionary<string, object>>(input.queryJson) : new Dictionary<string, object>();
|
||||||
|
string code = queryJson!=null && queryJson.ContainsKey("code") ? queryJson["code"].ToString() : "";
|
||||||
|
string name = queryJson!=null && queryJson.ContainsKey("name") ? queryJson["name"].ToString() : "";
|
||||||
|
string userId = _userManager.UserId;
|
||||||
|
var result = await db.Queryable<EqpRepairApply>()
|
||||||
|
.LeftJoin<EqpEquipment>((a, b) => a.equip_id == b.id)
|
||||||
|
.LeftJoin<UserEntity>((a, b, c) => a.apply_user_id == c.Id)
|
||||||
|
.LeftJoin<DictionaryTypeEntity>((a,b,c,d)=>d.EnCode==DictConst.RepairStatus)
|
||||||
|
.LeftJoin<DictionaryDataEntity>((a,b,c,d,e)=>a.status==e.EnCode && d.Id==e.DictionaryTypeId)
|
||||||
|
.WhereIF(!string.IsNullOrEmpty("code"), (a, b, c) => a.code.Contains(code))
|
||||||
|
.WhereIF(!string.IsNullOrEmpty("name"), (a, b, c) => a.name.Contains(name))
|
||||||
|
.Where((a, b, c) => a.repairer_id == userId)
|
||||||
|
.Where((a, b, c) => a.status == "2" || a.status=="3")
|
||||||
|
.Select((a, b, c,d,e) => new PdaRepairApplyListOutput
|
||||||
|
{
|
||||||
|
id = a.id,
|
||||||
|
code = a.code,
|
||||||
|
name = a.name,
|
||||||
|
equip_id = b.code+"/"+b.name,
|
||||||
|
equip_id_id = a.equip_id,
|
||||||
|
expect_complete_time = a.expect_complete_time==null ? "" : a.expect_complete_time.Value.ToString("yyyy-MM-dd"),
|
||||||
|
is_ugent = a.is_ugent==null ? "" : a.is_ugent==0 ? "否" : "是",
|
||||||
|
description = a.description,
|
||||||
|
status = e.FullName,
|
||||||
|
apply_user_id = SqlFunc.IsNull(c.RealName,"异常停机"),
|
||||||
|
apply_user_id_id = a.create_id,
|
||||||
|
// repairer_id = c.RealName,
|
||||||
|
// repairer_id_id = a.repairer_id,
|
||||||
|
}).ToPagedListAsync(input.currentPage,input.pageSize);
|
||||||
|
|
||||||
|
return PageResult<PdaRepairApplyListOutput>.SqlSugarPageResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据id获取维修相关信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dic"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<dynamic> GetRepairInfoById(Dictionary<string,string> dic)
|
||||||
|
{
|
||||||
|
string id = dic.ContainsKey("id") ? dic["id"] : "";
|
||||||
|
if (string.IsNullOrEmpty(id)) return null;
|
||||||
|
var db = _repository.AsSugarClient();
|
||||||
|
return await db.Queryable<EqpRepairApply>()
|
||||||
|
.LeftJoin<EqpEquipment>((a, b) => a.equip_id == b.id)
|
||||||
|
.Where((a, b) => a.id == id)
|
||||||
|
.Select((a, b) => new
|
||||||
|
{
|
||||||
|
id = a.id,
|
||||||
|
a.code,
|
||||||
|
a.name,
|
||||||
|
equip_id = a.equip_id,
|
||||||
|
equip_code = b.code,
|
||||||
|
equip_name = b.name,
|
||||||
|
expect_complete_time = a.expect_complete_time==null?"":a.expect_complete_time.Value.ToString("yyyy-MM-dd"),
|
||||||
|
is_ugent = a.is_ugent,
|
||||||
|
description = a.description,
|
||||||
|
status = a.status,
|
||||||
|
repairer_id = a.repairer_id,
|
||||||
|
}).FirstAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ using Tnb.EquipMgr.Interfaces;
|
|||||||
namespace Tnb.EquipMgr
|
namespace Tnb.EquipMgr
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设备维修延期
|
/// 设备维修登记
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||||
[Route("api/[area]/[controller]/[action]")]
|
[Route("api/[area]/[controller]/[action]")]
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public partial class WmsDistaskCode : BaseEntity<string>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 时间戳
|
/// 时间戳
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime time_stamp { get; set; } = DateTime.Now;
|
//public DateTime? time_stamp { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建用户
|
/// 创建用户
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Linq.Expressions;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Aop.Api.Domain;
|
using Aop.Api.Domain;
|
||||||
|
using JNPF.Common.Const;
|
||||||
using JNPF.Common.Contracts;
|
using JNPF.Common.Contracts;
|
||||||
using JNPF.Common.Core.Manager;
|
using JNPF.Common.Core.Manager;
|
||||||
using JNPF.Common.Dtos.VisualDev;
|
using JNPF.Common.Dtos.VisualDev;
|
||||||
@@ -19,6 +20,7 @@ using JNPF.VisualDev.Interfaces;
|
|||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using NPOI.SS.Formula.Functions;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using SqlSugar.DbConvert;
|
using SqlSugar.DbConvert;
|
||||||
using Tnb.BasicData.Entities;
|
using Tnb.BasicData.Entities;
|
||||||
@@ -76,14 +78,63 @@ namespace Tnb.WarehouseMgr
|
|||||||
OverideFuncs.CreateAsync = OutStockApplyFor;
|
OverideFuncs.CreateAsync = OutStockApplyFor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task<dynamic> OutStockApplyFor(VisualDevModelDataCrInput input)
|
private async Task<dynamic> OutStockApplyFor(VisualDevModelDataCrInput input)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _db.Ado.BeginTranAsync();
|
await _db.Ado.BeginTranAsync();
|
||||||
//判断目标库位是否自动签收
|
//判断目标库位是否自动签收
|
||||||
var loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == input.data[nameof(WmsPointH.location_id)].ToString());
|
BasLocation? loc = null;
|
||||||
|
if (input.data.ContainsKey(nameof(WmsPointH.location_id)) && input.data[nameof(WmsPointH.location_id)].IsNotEmptyOrNull())
|
||||||
|
{
|
||||||
|
loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == input.data[nameof(WmsPointH.location_id)].ToString());
|
||||||
|
}
|
||||||
|
else if (input.data.ContainsKey(nameof(WmsOutstockH.station_id)) && input.data[nameof(WmsOutstockH.station_id)].IsNotEmptyOrNull())
|
||||||
|
{
|
||||||
|
//多个投料库位
|
||||||
|
/*
|
||||||
|
* 天益
|
||||||
|
* 2、不管库位是否为空, 获取到所有库位 A B
|
||||||
|
* 2.1 根据这些库位去查任务执行 目的库位是这些库位的未完成任务数。 A 10 B 9
|
||||||
|
* 2.2 哪个最少给哪个
|
||||||
|
*/
|
||||||
|
var org = await _db.Queryable<OrganizeEntity>().FirstAsync(it => it.Id == input.data[nameof(WmsOutstockH.station_id)].ToString());
|
||||||
|
if (!org?.FeedingLocationId.IsNullOrWhiteSpace() ?? false)
|
||||||
|
{
|
||||||
|
var fLocIds = JArray.Parse(org.FeedingLocationId).Values<string>().ToList();
|
||||||
|
var minTaskNumLocs = await _db.Queryable<WmsPretaskH>().Where(it => it.status != WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID && fLocIds.Contains(it.endlocation_id))
|
||||||
|
.GroupBy(it => it.endlocation_id)
|
||||||
|
.Select(it => new
|
||||||
|
{
|
||||||
|
it.endlocation_id,
|
||||||
|
count = SqlFunc.AggregateCount(it.endlocation_id)
|
||||||
|
})
|
||||||
|
.MergeTable()
|
||||||
|
.OrderBy(it => it.count)
|
||||||
|
.ToListAsync();
|
||||||
|
if (minTaskNumLocs?.Count > 0)
|
||||||
|
{
|
||||||
|
var freeLocIds = fLocIds.Except(minTaskNumLocs.Select(x => x.endlocation_id)).ToList();
|
||||||
|
if (freeLocIds?.Count > 0)
|
||||||
|
{
|
||||||
|
var rIdx = new Random().Next(0, freeLocIds.Count);
|
||||||
|
loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == freeLocIds[rIdx]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var firstLocId = minTaskNumLocs.FirstOrDefault().endlocation_id;
|
||||||
|
loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == firstLocId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (minTaskNumLocs?.Count < 1)
|
||||||
|
{
|
||||||
|
var rIdx = new Random().Next(0, fLocIds.Count);
|
||||||
|
loc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == fLocIds[rIdx]);
|
||||||
|
}
|
||||||
|
input.data[nameof(WmsOutstockH.location_id)] = loc.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var carryIds = new List<string>();
|
var carryIds = new List<string>();
|
||||||
//tablefield120 出库物料明细
|
//tablefield120 出库物料明细
|
||||||
@@ -98,13 +149,13 @@ namespace Tnb.WarehouseMgr
|
|||||||
{
|
{
|
||||||
var OutStockStrategyInput = new OutStockStrategyQuery
|
var OutStockStrategyInput = new OutStockStrategyQuery
|
||||||
{
|
{
|
||||||
carry_id = input.data[nameof(OutStockStrategyQuery.carry_id)].ToString(),
|
carry_id = input.data[nameof(OutStockStrategyQuery.carry_id)]?.ToString() ?? string.Empty,
|
||||||
warehouse_id = input.data[nameof(WmsOutstockH.warehouse_id)].ToString(),
|
warehouse_id = input.data[nameof(WmsOutstockH.warehouse_id)]?.ToString() ?? string.Empty,
|
||||||
material_id = os.material_id,
|
material_id = os.material_id,
|
||||||
code_batch = os.code_batch,
|
code_batch = os.code_batch,
|
||||||
};
|
};
|
||||||
var outStkCarrys = await _wareHouseService.OutStockStrategy(OutStockStrategyInput);
|
var outStkCarrys = await _wareHouseService.OutStockStrategy(OutStockStrategyInput);
|
||||||
Expression<Func<WmsCarryH, WmsCarryCode, bool>> whereExp = input.data.ContainsKey(nameof(WmsOutstockH.carry_id))
|
Expression<Func<WmsCarryH, WmsCarryCode, bool>> whereExp = input.data.ContainsKey(nameof(WmsOutstockH.carry_id)) && input.data[nameof(WmsOutstockH.carry_id)].IsNotEmptyOrNull()
|
||||||
? (a, b) => a.id == input.data[nameof(WmsOutstockH.carry_id)].ToString()
|
? (a, b) => a.id == input.data[nameof(WmsOutstockH.carry_id)].ToString()
|
||||||
: (a, b) => outStkCarrys.Select(x => x.id).Contains(b.carry_id);
|
: (a, b) => outStkCarrys.Select(x => x.id).Contains(b.carry_id);
|
||||||
|
|
||||||
@@ -177,8 +228,21 @@ namespace Tnb.WarehouseMgr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
carryIds = allOutIds.Concat(sortingOutIds).ToList();
|
carryIds = allOutIds.Concat(sortingOutIds).ToList();
|
||||||
await _db.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.全部出).ToString(), source_id = input.data[nameof(WmsOutstockH.source_id)].ToString(), source_code = input.data[nameof(WmsOutstockH.source_code)].ToString() }).Where(it => allOutIds.Contains(it.id)).ExecuteCommandAsync();
|
var carryH = new WmsCarryH
|
||||||
await _db.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.分拣出).ToString(), source_id = input.data[nameof(WmsOutstockH.source_id)].ToString(), source_code = input.data[nameof(WmsOutstockH.source_code)].ToString() }).Where(it => sortingOutIds.Contains(it.id)).ExecuteCommandAsync();
|
{
|
||||||
|
out_status = ((int)EnumOutStatus.全部出).ToString(),
|
||||||
|
source_id = input.data.ContainsKey(nameof(WmsOutstockH.source_id)) ? input.data[nameof(WmsOutstockH.source_id)]?.ToString() ?? string.Empty : string.Empty,
|
||||||
|
source_code = input.data.ContainsKey(nameof(WmsOutstockH.source_code)) ? input.data[nameof(WmsOutstockH.source_code)]?.ToString() ?? string.Empty : string.Empty,
|
||||||
|
};
|
||||||
|
await _db.Updateable(carryH)
|
||||||
|
.UpdateColumns(it => new { it.out_status, it.source_id, it.source_code })
|
||||||
|
.Where(it => allOutIds.Contains(it.id))
|
||||||
|
.ExecuteCommandAsync();
|
||||||
|
carryH.out_status = ((int)EnumOutStatus.分拣出).ToString();
|
||||||
|
await _db.Updateable(carryH)
|
||||||
|
.UpdateColumns(it => new { it.out_status, it.source_id, it.source_code })
|
||||||
|
.Where(it => sortingOutIds.Contains(it.id))
|
||||||
|
.ExecuteCommandAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -186,9 +250,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
var carrys = await _db.Queryable<WmsCarryH>().Where(it => carryIds.Contains(it.id)).ToListAsync();
|
var carrys = await _db.Queryable<WmsCarryH>().Where(it => carryIds.Contains(it.id)).ToListAsync();
|
||||||
if (carrys?.Count > 0)
|
if (carrys?.Count > 0)
|
||||||
{
|
{
|
||||||
var curCarry = carrys[^carrys.Count];
|
|
||||||
var isMatch = await IsCarryAndLocationMatchByCarryStd(curCarry, loc);
|
|
||||||
if (!isMatch) throw new AppFriendlyException("该载具无法放置到目标库位", 500);
|
|
||||||
|
|
||||||
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSOUTSTOCK_ID, true);
|
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSOUTSTOCK_ID, true);
|
||||||
await _runService.Create(templateEntity, input);
|
await _runService.Create(templateEntity, input);
|
||||||
@@ -197,6 +259,9 @@ namespace Tnb.WarehouseMgr
|
|||||||
List<string> locIds = new();
|
List<string> locIds = new();
|
||||||
foreach (var carry in carrys)
|
foreach (var carry in carrys)
|
||||||
{
|
{
|
||||||
|
var isMatch = await IsCarryAndLocationMatchByCarryStd(carry, loc);
|
||||||
|
if (!isMatch) throw new AppFriendlyException("该载具无法放置到目标库位", 500);
|
||||||
|
|
||||||
WmsPointH sPoint = null!;
|
WmsPointH sPoint = null!;
|
||||||
WmsPointH ePoint = null!;
|
WmsPointH ePoint = null!;
|
||||||
if (input.data.ContainsKey(nameof(WmsPointH.location_id)))
|
if (input.data.ContainsKey(nameof(WmsPointH.location_id)))
|
||||||
@@ -205,37 +270,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
}
|
}
|
||||||
if (input.data.ContainsKey(nameof(WmsPointH.location_id)) && input.data[nameof(WmsPointH.location_id)].IsNotEmptyOrNull())
|
if (input.data.ContainsKey(nameof(WmsPointH.location_id)) && input.data[nameof(WmsPointH.location_id)].IsNotEmptyOrNull())
|
||||||
{
|
{
|
||||||
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == input.data[nameof(WmsPointH.location_id)].ToString());
|
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == loc.id);
|
||||||
}
|
|
||||||
else if (input.data.ContainsKey(nameof(WmsOutstockH.station_id)))
|
|
||||||
{
|
|
||||||
//多个投料库位
|
|
||||||
/*
|
|
||||||
* 潍柴
|
|
||||||
* 1、那个库位状态是空的出那个
|
|
||||||
* 1.1、没有空位直接抛异常
|
|
||||||
*
|
|
||||||
* 天益
|
|
||||||
* 2、不管库位是否为空, 获取到所有库位 A B
|
|
||||||
* 2.1 根据这些库位去查任务执行 目的库位是这些库位的未完成任务数。 A 10 B 9
|
|
||||||
* 2.2 哪个最少给哪个
|
|
||||||
*/
|
|
||||||
var org = await _db.Queryable<OrganizeEntity>().FirstAsync(it => it.Id == input.data[nameof(WmsOutstockH.station_id)].ToString());
|
|
||||||
if (!org?.FeedingLocationId.IsNullOrWhiteSpace() ?? false)
|
|
||||||
{
|
|
||||||
var fLocIds = JArray.Parse(org.FeedingLocationId).Values<string>();
|
|
||||||
var minTaskNumLoc = await _db.Queryable<WmsPretaskH>().Where(it => it.status != WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID && fLocIds.Contains(it.endlocation_id))
|
|
||||||
.GroupBy(it => it.endlocation_id)
|
|
||||||
.Select(it => new
|
|
||||||
{
|
|
||||||
it.endlocation_id,
|
|
||||||
count = SqlFunc.AggregateCount(it.endlocation_id)
|
|
||||||
})
|
|
||||||
.MergeTable()
|
|
||||||
.OrderBy(it => it.count)
|
|
||||||
.FirstAsync();
|
|
||||||
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == minTaskNumLoc.endlocation_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sPoint != null && ePoint != null)
|
if (sPoint != null && ePoint != null)
|
||||||
@@ -323,8 +358,9 @@ namespace Tnb.WarehouseMgr
|
|||||||
|
|
||||||
await _db.Ado.CommitTranAsync();
|
await _db.Ado.CommitTranAsync();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
JNPF.Logging.Log.Error(ex.ToString());
|
||||||
await _db.Ado.RollbackTranAsync();
|
await _db.Ado.RollbackTranAsync();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
@@ -608,11 +644,12 @@ namespace Tnb.WarehouseMgr
|
|||||||
{
|
{
|
||||||
|
|
||||||
await _db.Ado.BeginTranAsync();
|
await _db.Ado.BeginTranAsync();
|
||||||
|
var curUser = await GetUserIdentity();
|
||||||
var carryId = input.carryIds[^input.carryIds.Count];
|
var carryId = input.carryIds[^input.carryIds.Count];
|
||||||
var carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == carryId);
|
var carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == carryId);
|
||||||
if (carry != null)
|
if (carry != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
var otds = await _db.Queryable<WmsOutstockD>().Where(it => it.bill_id == input.requireId).ToListAsync();
|
var otds = await _db.Queryable<WmsOutstockD>().Where(it => it.bill_id == input.requireId).ToListAsync();
|
||||||
var outStatus = carry.out_status.ToEnum<EnumOutStatus>();
|
var outStatus = carry.out_status.ToEnum<EnumOutStatus>();
|
||||||
if (outStatus == EnumOutStatus.全部出)
|
if (outStatus == EnumOutStatus.全部出)
|
||||||
@@ -621,6 +658,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
var carryCodes = await _db.Queryable<WmsCarryCode>().Where(it => it.carry_id == carryId).ToListAsync();
|
var carryCodes = await _db.Queryable<WmsCarryCode>().Where(it => it.carry_id == carryId).ToListAsync();
|
||||||
var outStockCodes = carryCodes.Adapt<List<WmsOutstockCode>>();
|
var outStockCodes = carryCodes.Adapt<List<WmsOutstockCode>>();
|
||||||
|
|
||||||
|
|
||||||
outStockCodes.ForEach(x =>
|
outStockCodes.ForEach(x =>
|
||||||
{
|
{
|
||||||
var billDId = otds?.Find(xx => xx.material_id == x.material_id && xx.code_batch == x.code_batch)?.id;
|
var billDId = otds?.Find(xx => xx.material_id == x.material_id && xx.code_batch == x.code_batch)?.id;
|
||||||
@@ -631,8 +669,8 @@ namespace Tnb.WarehouseMgr
|
|||||||
x.id = SnowflakeIdHelper.NextId();
|
x.id = SnowflakeIdHelper.NextId();
|
||||||
x.bill_id = input.requireId;
|
x.bill_id = input.requireId;
|
||||||
x.bill_d_id = billDId!;
|
x.bill_d_id = billDId!;
|
||||||
x.org_id = _userManager.User.OrganizeId;
|
x.org_id = _userManager.User?.OrganizeId ?? curUser.FindFirst(ClaimConst.CLAINMORGID)?.Value ?? string.Empty;
|
||||||
x.create_id = _userManager.UserId;
|
x.create_id = _userManager.UserId ?? curUser.FindFirst(ClaimConst.CLAINMUSERID)?.Value ?? string.Empty; ;
|
||||||
x.create_time = DateTime.Now;
|
x.create_time = DateTime.Now;
|
||||||
});
|
});
|
||||||
await _db.Insertable(outStockCodes).ExecuteCommandAsync();
|
await _db.Insertable(outStockCodes).ExecuteCommandAsync();
|
||||||
@@ -683,8 +721,8 @@ namespace Tnb.WarehouseMgr
|
|||||||
x.id = SnowflakeIdHelper.NextId();
|
x.id = SnowflakeIdHelper.NextId();
|
||||||
x.bill_id = input.requireId;
|
x.bill_id = input.requireId;
|
||||||
x.bill_d_id = billDId!;
|
x.bill_d_id = billDId!;
|
||||||
x.org_id = _userManager.User.OrganizeId;
|
x.org_id = _userManager.User?.OrganizeId ?? curUser.FindFirst(ClaimConst.CLAINMORGID)?.Value ?? string.Empty;
|
||||||
x.create_id = _userManager.UserId;
|
x.create_id = _userManager.UserId?? curUser.FindFirst(ClaimConst.CLAINMUSERID)?.Value ?? string.Empty;
|
||||||
x.create_time = DateTime.Now;
|
x.create_time = DateTime.Now;
|
||||||
});
|
});
|
||||||
await _db.Insertable(osCodes).ExecuteCommandAsync();
|
await _db.Insertable(osCodes).ExecuteCommandAsync();
|
||||||
|
|||||||
@@ -115,8 +115,8 @@ public class Startup : AppStartup
|
|||||||
|
|
||||||
SnowflakeIdHelper.InitYitIdWorker();
|
SnowflakeIdHelper.InitYitIdWorker();
|
||||||
|
|
||||||
bool isStartTimeJob = App.GetConfig<bool>("IsStartTimeJob");
|
//bool isStartTimeJob = App.GetConfig<bool>("IsStartTimeJob");
|
||||||
if (isStartTimeJob)
|
//if (isStartTimeJob)
|
||||||
serviceProvider.GetRequiredService<ITimeTaskService>().StartTimerJob();
|
// serviceProvider.GetRequiredService<ITimeTaskService>().StartTimerJob();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,14 @@
|
|||||||
<None Remove="logs\**" />
|
<None Remove="logs\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="wwwroot\Template\VengineSqlSugar\AppService.cshtml" />
|
||||||
|
<None Include="wwwroot\Template\VengineSqlSugar\EntityDto.cshtml" />
|
||||||
|
<None Include="wwwroot\Template\VengineSqlSugar\EntityDtoAcmen.cshtml" />
|
||||||
|
<None Include="wwwroot\Template\VengineSqlSugar\EntityInfo.cshtml" />
|
||||||
|
<None Include="wwwroot\Template\VengineSqlSugar\EntityInfoAcmen.cshtml" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<!--<ItemGroup>
|
<!--<ItemGroup>
|
||||||
<None Remove="lib\regworkerid_lib_v1.3.1\yitidgengo.dll" />
|
<None Remove="lib\regworkerid_lib_v1.3.1\yitidgengo.dll" />
|
||||||
<None Remove="lib\regworkerid_lib_v1.3.1\yitidgengo.so" />
|
<None Remove="lib\regworkerid_lib_v1.3.1\yitidgengo.so" />
|
||||||
@@ -43,6 +51,7 @@
|
|||||||
<ProjectReference Include="..\..\system\Tnb.OAuth\Tnb.OAuth.csproj" />
|
<ProjectReference Include="..\..\system\Tnb.OAuth\Tnb.OAuth.csproj" />
|
||||||
<ProjectReference Include="..\..\system\Tnb.Systems\Tnb.Systems.csproj" />
|
<ProjectReference Include="..\..\system\Tnb.Systems\Tnb.Systems.csproj" />
|
||||||
<ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" />
|
<ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" />
|
||||||
|
<ProjectReference Include="..\..\visualdev\Tnb.Vengine\Tnb.Vengine.csproj" />
|
||||||
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev\Tnb.VisualDev.csproj" />
|
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev\Tnb.VisualDev.csproj" />
|
||||||
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr\Tnb.WarehouseMgr.csproj" />
|
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr\Tnb.WarehouseMgr.csproj" />
|
||||||
<ProjectReference Include="..\..\workflow\Tnb.WorkFlow\Tnb.WorkFlow.csproj" />
|
<ProjectReference Include="..\..\workflow\Tnb.WorkFlow\Tnb.WorkFlow.csproj" />
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||||
|
// https://git.tuotong-tech.com/tnb/tnb-server //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@using Tnb.Core;
|
||||||
|
@using Tnb.Vengine;
|
||||||
|
@using Tnb.Vengine.Domain;
|
||||||
|
@{
|
||||||
|
AcmenVmodelContext context = Model;
|
||||||
|
Vmodel vm = context.Vm;
|
||||||
|
}
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Tnb.Core;
|
||||||
|
using Tnb.Vengine.AppService;
|
||||||
|
using Tnb.Vengine.DataAccess;
|
||||||
|
using Tnb.Vengine.Domain;
|
||||||
|
using @(context.NsPrefix + "." + vm.areaCode + ".Domain");
|
||||||
|
|
||||||
|
namespace @(context.NsPrefix + "." + vm.areaCode + ".AppService");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 模型 @vm.vmName 应用服务类
|
||||||
|
/// </summary>
|
||||||
|
[ApiExplorerSettings(GroupName = Consts.ApiGroupCode)]
|
||||||
|
public class @(vm.vmCode)AppService : VengineAppService<@(vm.vmCode)>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 构造函数
|
||||||
|
/// </summary>
|
||||||
|
public @(vm.vmCode)AppService(IDataAccess da) : base(da)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||||
|
// https://git.tuotong-tech.com/tnb/tnb-server //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@using Tnb.Core;
|
||||||
|
@using Tnb.Vengine;
|
||||||
|
@using Tnb.Vengine.Domain;
|
||||||
|
@{
|
||||||
|
AcmenVmodelContext context = Model;
|
||||||
|
Vmodel vm = context.Vm;
|
||||||
|
}
|
||||||
|
using Tnb.Core;
|
||||||
|
|
||||||
|
namespace @(context.NsPrefix + "." + vm.areaCode + ".AppService");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// @(vm.vmCode)Dto对象
|
||||||
|
/// </summary>
|
||||||
|
public partial class @(vm.vmCode)Dto
|
||||||
|
{
|
||||||
|
@foreach (var col in vm.dbProps.OrderBy(a => a.ordinal)){
|
||||||
|
@://public @(col.required ? col.csType : (col.csType + "?")) @col.code { get; set; }@(col.GetDefaultValueString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
////////////////////////////////////////////////////
|
||||||
|
// 本文件由拓通低代码开发平台自动生成,请不要修改 //
|
||||||
|
// ________ ___ ________ //
|
||||||
|
// /__ __/ / \ /__ __/ //
|
||||||
|
// / / / / / / //
|
||||||
|
// / / / / / / //
|
||||||
|
// /__/ \___/ /__/ //
|
||||||
|
// //
|
||||||
|
////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@using Tnb.Core;
|
||||||
|
@using Tnb.Vengine;
|
||||||
|
@using Tnb.Vengine.Domain;
|
||||||
|
@{
|
||||||
|
AcmenVmodelContext context = Model;
|
||||||
|
Vmodel vm = context.Vm;
|
||||||
|
}
|
||||||
|
using Tnb.Core;
|
||||||
|
|
||||||
|
namespace @(context.NsPrefix + "." + vm.areaCode + ".AppService");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// @(vm.vmCode)Dto对象
|
||||||
|
/// </summary>
|
||||||
|
public partial class @(vm.vmCode)Dto
|
||||||
|
{
|
||||||
|
@foreach (var col in vm.dbProps.OrderBy(a => a.ordinal)){
|
||||||
|
@://public @(col.required ? col.csType : (col.csType + "?")) @col.code { get; set; }@(col.GetDefaultValueString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||||
|
// https://git.tuotong-tech.com/tnb/tnb-server //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@using Tnb.Core;
|
||||||
|
@using Tnb.Vengine;
|
||||||
|
@using Tnb.Vengine.Domain;
|
||||||
|
@{
|
||||||
|
AcmenVmodelContext context = Model;
|
||||||
|
Vmodel vm = context.Vm;
|
||||||
|
}
|
||||||
|
using Tnb.Core;
|
||||||
|
|
||||||
|
namespace @(context.NsPrefix + "." + vm.areaCode + ".Domain");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// @vm.vmName
|
||||||
|
/// </summary>
|
||||||
|
public partial class @vm.vmCode
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
////////////////////////////////////////////////////
|
||||||
|
// 本文件由拓通低代码开发平台自动生成,请不要修改 //
|
||||||
|
// ________ ___ ________ //
|
||||||
|
// /__ __/ / \ /__ __/ //
|
||||||
|
// / / / / / / //
|
||||||
|
// / / / / / / //
|
||||||
|
// /__/ \___/ /__/ //
|
||||||
|
// //
|
||||||
|
////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@using JNPF.Common.Extension;
|
||||||
|
@using Tnb.Core;
|
||||||
|
@using Tnb.Vengine;
|
||||||
|
@using Tnb.Vengine.Domain;
|
||||||
|
@{
|
||||||
|
AcmenVmodelContext context = Model;
|
||||||
|
Vmodel vm = context.Vm;
|
||||||
|
}
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using SqlSugar;
|
||||||
|
using Tnb.Core;
|
||||||
|
using Yitter.IdGenerator;
|
||||||
|
|
||||||
|
namespace @(context.NsPrefix + "." + vm.areaCode + ".Domain");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// @vm.vmName
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("@vm.tableName")]
|
||||||
|
public partial class @vm.vmCode : Entity
|
||||||
|
{
|
||||||
|
#region Properties
|
||||||
|
@foreach (var col in vm.dbProps.OrderBy(a=>a.ordinal)) {
|
||||||
|
@:/// <summary>
|
||||||
|
@:/// @col.name
|
||||||
|
@:/// </summary>
|
||||||
|
@col.GetAttributeString()
|
||||||
|
@:public @(col.required ? col.csType : (col.csType + "?")) @col.code { get; set; }@(col.GetDefaultValueString())
|
||||||
|
@:
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 主键
|
||||||
|
/// </summary>
|
||||||
|
public override object[] GetKeys()
|
||||||
|
{
|
||||||
|
return new object[] { @(vm.dbProps.Where(a=>a.pkey).Select(a=>a.code).JoinAsString(", ")) };
|
||||||
|
}
|
||||||
|
|
||||||
|
@foreach (var col in vm.dbProps.OrderBy(a => a.ordinal)){
|
||||||
|
@://public @(col.required ? col.csType : (col.csType + "?")) @col.code { get; set; }@(col.GetDefaultValueString())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -87,4 +87,15 @@ public static class EnumerableExtensions
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 连接为字符串
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
|
/// <param name="separator"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string JoinAsString(this IEnumerable<string> source, string separator)
|
||||||
|
{
|
||||||
|
return string.Join(separator, source);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -956,283 +956,4 @@ public static class StringExtensions
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 转换,来自Abp
|
|
||||||
/// <summary>
|
|
||||||
/// Converts PascalCase string to camelCase string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">String to convert</param>
|
|
||||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
|
||||||
/// <param name="handleAbbreviations">set true to if you want to convert 'XYZ' to 'xyz'.</param>
|
|
||||||
/// <returns>camelCase of the string</returns>
|
|
||||||
public static string ToCamelCase(this string str, bool useCurrentCulture = false, bool handleAbbreviations = false)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(str))
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str.Length == 1)
|
|
||||||
{
|
|
||||||
return useCurrentCulture ? str.ToLower() : str.ToLowerInvariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (handleAbbreviations && IsAllUpperCase(str))
|
|
||||||
{
|
|
||||||
return useCurrentCulture ? str.ToLower() : str.ToLowerInvariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (useCurrentCulture ? char.ToLower(str[0]) : char.ToLowerInvariant(str[0])) + str.Substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts given PascalCase/camelCase string to sentence (by splitting words by space).
|
|
||||||
/// Example: "ThisIsSampleSentence" is converted to "This is a sample sentence".
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">String to convert.</param>
|
|
||||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
|
||||||
public static string ToSentenceCase(this string str, bool useCurrentCulture = false)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(str))
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
return useCurrentCulture
|
|
||||||
? Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLower(m.Value[1]))
|
|
||||||
: Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLowerInvariant(m.Value[1]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts given PascalCase/camelCase string to kebab-case.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">String to convert.</param>
|
|
||||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
|
||||||
public static string ToKebabCase(this string str, bool useCurrentCulture = false)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(str))
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
str = str.ToCamelCase();
|
|
||||||
|
|
||||||
return useCurrentCulture
|
|
||||||
? Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + "-" + char.ToLower(m.Value[1]))
|
|
||||||
: Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + "-" + char.ToLowerInvariant(m.Value[1]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts given PascalCase/camelCase string to snake case.
|
|
||||||
/// Example: "ThisIsSampleSentence" is converted to "this_is_a_sample_sentence".
|
|
||||||
/// https://github.com/npgsql/npgsql/blob/dev/src/Npgsql/NameTranslation/NpgsqlSnakeCaseNameTranslator.cs#L51
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">String to convert.</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static string ToSnakeCase(this string str)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(str))
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
var builder = new StringBuilder(str.Length + Math.Min(2, str.Length / 5));
|
|
||||||
var previousCategory = default(UnicodeCategory?);
|
|
||||||
|
|
||||||
for (var currentIndex = 0; currentIndex < str.Length; currentIndex++)
|
|
||||||
{
|
|
||||||
var currentChar = str[currentIndex];
|
|
||||||
if (currentChar == '_')
|
|
||||||
{
|
|
||||||
builder.Append('_');
|
|
||||||
previousCategory = null;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var currentCategory = char.GetUnicodeCategory(currentChar);
|
|
||||||
switch (currentCategory)
|
|
||||||
{
|
|
||||||
case UnicodeCategory.UppercaseLetter:
|
|
||||||
case UnicodeCategory.TitlecaseLetter:
|
|
||||||
if (previousCategory == UnicodeCategory.SpaceSeparator ||
|
|
||||||
previousCategory == UnicodeCategory.LowercaseLetter ||
|
|
||||||
previousCategory != UnicodeCategory.DecimalDigitNumber &&
|
|
||||||
previousCategory != null &&
|
|
||||||
currentIndex > 0 &&
|
|
||||||
currentIndex + 1 < str.Length &&
|
|
||||||
char.IsLower(str[currentIndex + 1]))
|
|
||||||
{
|
|
||||||
builder.Append('_');
|
|
||||||
}
|
|
||||||
|
|
||||||
currentChar = char.ToLower(currentChar);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case UnicodeCategory.LowercaseLetter:
|
|
||||||
case UnicodeCategory.DecimalDigitNumber:
|
|
||||||
if (previousCategory == UnicodeCategory.SpaceSeparator)
|
|
||||||
{
|
|
||||||
builder.Append('_');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (previousCategory != null)
|
|
||||||
{
|
|
||||||
previousCategory = UnicodeCategory.SpaceSeparator;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.Append(currentChar);
|
|
||||||
previousCategory = currentCategory;
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts camelCase string to PascalCase string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">String to convert</param>
|
|
||||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
|
||||||
/// <returns>PascalCase of the string</returns>
|
|
||||||
public static string ToPascalCase(this string str, bool useCurrentCulture = false)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(str))
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str.Length == 1)
|
|
||||||
{
|
|
||||||
return useCurrentCulture ? str.ToUpper() : str.ToUpperInvariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (useCurrentCulture ? char.ToUpper(str[0]) : char.ToUpperInvariant(str[0])) + str.Substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Removes first occurrence of the given prefixes from beginning of the given string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">The string.</param>
|
|
||||||
/// <param name="preFixes">one or more prefix.</param>
|
|
||||||
/// <returns>Modified string or the same string if it has not any of given prefixes</returns>
|
|
||||||
public static string RemovePreFix(this string str, params string[] preFixes)
|
|
||||||
{
|
|
||||||
return str.RemovePreFix(StringComparison.Ordinal, preFixes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Removes first occurrence of the given prefixes from beginning of the given string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">The string.</param>
|
|
||||||
/// <param name="comparisonType">String comparison type</param>
|
|
||||||
/// <param name="preFixes">one or more prefix.</param>
|
|
||||||
/// <returns>Modified string or the same string if it has not any of given prefixes</returns>
|
|
||||||
public static string RemovePreFix(this string str, StringComparison comparisonType, params string[] preFixes)
|
|
||||||
{
|
|
||||||
if (str.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preFixes.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var preFix in preFixes)
|
|
||||||
{
|
|
||||||
if (str.StartsWith(preFix, comparisonType))
|
|
||||||
{
|
|
||||||
return str.Right(str.Length - preFix.Length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Removes first occurrence of the given postfixes from end of the given string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">The string.</param>
|
|
||||||
/// <param name="postFixes">one or more postfix.</param>
|
|
||||||
/// <returns>Modified string or the same string if it has not any of given postfixes</returns>
|
|
||||||
public static string RemovePostFix(this string str, params string[] postFixes)
|
|
||||||
{
|
|
||||||
return str.RemovePostFix(StringComparison.Ordinal, postFixes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Removes first occurrence of the given postfixes from end of the given string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">The string.</param>
|
|
||||||
/// <param name="comparisonType">String comparison type</param>
|
|
||||||
/// <param name="postFixes">one or more postfix.</param>
|
|
||||||
/// <returns>Modified string or the same string if it has not any of given postfixes</returns>
|
|
||||||
public static string RemovePostFix(this string str, StringComparison comparisonType, params string[] postFixes)
|
|
||||||
{
|
|
||||||
if (str.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (postFixes.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var postFix in postFixes)
|
|
||||||
{
|
|
||||||
if (str.EndsWith(postFix, comparisonType))
|
|
||||||
{
|
|
||||||
return str.Left(str.Length - postFix.Length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a substring of a string from beginning of the string.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
|
|
||||||
/// <exception cref="ArgumentException">Thrown if <paramref name="len"/> is bigger that string's length</exception>
|
|
||||||
public static string Left(this string str, int len)
|
|
||||||
{
|
|
||||||
if (str.Length < len)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("len argument can not be bigger than given string's length!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.Substring(0, len);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a substring of a string from end of the string.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
|
|
||||||
/// <exception cref="ArgumentException">Thrown if <paramref name="len"/> is bigger that string's length</exception>
|
|
||||||
public static string Right(this string str, int len)
|
|
||||||
{
|
|
||||||
if (str.Length < len)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("len argument can not be bigger than given string's length!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.Substring(str.Length - len, len);
|
|
||||||
}
|
|
||||||
private static bool IsAllUpperCase(string input)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < input.Length; i++)
|
|
||||||
{
|
|
||||||
if (Char.IsLetter(input[i]) && !Char.IsUpper(input[i]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
186
common/Tnb.Common/Extension/TnbStringExtensions.cs
Normal file
186
common/Tnb.Common/Extension/TnbStringExtensions.cs
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using JNPF.Common.Extension;
|
||||||
|
|
||||||
|
namespace System;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 字符串<see cref="string"/>类型的扩展辅助操作类.
|
||||||
|
/// </summary>
|
||||||
|
public static class StringExtensions
|
||||||
|
{
|
||||||
|
#region 转换,来自Abp
|
||||||
|
/// <summary>
|
||||||
|
/// Removes first occurrence of the given prefixes from beginning of the given string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str">The string.</param>
|
||||||
|
/// <param name="preFixes">one or more prefix.</param>
|
||||||
|
/// <returns>Modified string or the same string if it has not any of given prefixes</returns>
|
||||||
|
public static string RemovePreFix(this string str, params string[] preFixes)
|
||||||
|
{
|
||||||
|
return str.RemovePreFix(StringComparison.Ordinal, preFixes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes first occurrence of the given prefixes from beginning of the given string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str">The string.</param>
|
||||||
|
/// <param name="comparisonType">String comparison type</param>
|
||||||
|
/// <param name="preFixes">one or more prefix.</param>
|
||||||
|
/// <returns>Modified string or the same string if it has not any of given prefixes</returns>
|
||||||
|
public static string RemovePreFix(this string str, StringComparison comparisonType, params string[] preFixes)
|
||||||
|
{
|
||||||
|
if (str.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preFixes.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var preFix in preFixes)
|
||||||
|
{
|
||||||
|
if (str.StartsWith(preFix, comparisonType))
|
||||||
|
{
|
||||||
|
return str.Right(str.Length - preFix.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes first occurrence of the given postfixes from end of the given string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str">The string.</param>
|
||||||
|
/// <param name="postFixes">one or more postfix.</param>
|
||||||
|
/// <returns>Modified string or the same string if it has not any of given postfixes</returns>
|
||||||
|
public static string RemovePostFix(this string str, params string[] postFixes)
|
||||||
|
{
|
||||||
|
return str.RemovePostFix(StringComparison.Ordinal, postFixes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes first occurrence of the given postfixes from end of the given string.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str">The string.</param>
|
||||||
|
/// <param name="comparisonType">String comparison type</param>
|
||||||
|
/// <param name="postFixes">one or more postfix.</param>
|
||||||
|
/// <returns>Modified string or the same string if it has not any of given postfixes</returns>
|
||||||
|
public static string RemovePostFix(this string str, StringComparison comparisonType, params string[] postFixes)
|
||||||
|
{
|
||||||
|
if (str.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (postFixes.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var postFix in postFixes)
|
||||||
|
{
|
||||||
|
if (str.EndsWith(postFix, comparisonType))
|
||||||
|
{
|
||||||
|
return str.Left(str.Length - postFix.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a substring of a string from beginning of the string.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
|
||||||
|
/// <exception cref="ArgumentException">Thrown if <paramref name="len"/> is bigger that string's length</exception>
|
||||||
|
public static string Left(this string str, int len)
|
||||||
|
{
|
||||||
|
if (str.Length < len)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("len argument can not be bigger than given string's length!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return str.Substring(0, len);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a substring of a string from end of the string.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
|
||||||
|
/// <exception cref="ArgumentException">Thrown if <paramref name="len"/> is bigger that string's length</exception>
|
||||||
|
public static string Right(this string str, int len)
|
||||||
|
{
|
||||||
|
if (str.Length < len)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("len argument can not be bigger than given string's length!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return str.Substring(str.Length - len, len);
|
||||||
|
}
|
||||||
|
private static bool IsAllUpperCase(string input)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < input.Length; i++)
|
||||||
|
{
|
||||||
|
if (Char.IsLetter(input[i]) && !Char.IsUpper(input[i]))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 判断字符串是否为空,为空时返回defaultVal,不为空时返回自身或者Func
|
||||||
|
/// </summary>
|
||||||
|
public static string IfNullOrEmpty(this string? str, string defaultVal, Func<string, string>? result = null)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(str)) return defaultVal;
|
||||||
|
else if (result == null) return str;
|
||||||
|
else return result(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string Format(this string str, params object?[] args)
|
||||||
|
{
|
||||||
|
return string.Format(str, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将字符串首字母改成大写
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string UpperFirst(this string str)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(str)) return str;
|
||||||
|
if (str.Length == 1)
|
||||||
|
{
|
||||||
|
return str.ToUpper();
|
||||||
|
}
|
||||||
|
return char.ToUpper(str[0]) + str.Substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将camelCase,PascalCase,kebab-case,snake_case,sentence case分隔为单词列表,并转成小写
|
||||||
|
/// </summary>
|
||||||
|
public static string[] SplitWord(this string str, bool toLower = true)
|
||||||
|
{
|
||||||
|
if (str == null) return Array.Empty<string>();
|
||||||
|
if (string.IsNullOrWhiteSpace(str)) return new string[] { str };
|
||||||
|
if (str.Length == 1) return new string[] { str };
|
||||||
|
|
||||||
|
var q = Regex.Split(str, @"(?=\p{Lu}\p{Ll})|(?<=\p{Ll})(?=\p{Lu})|[-_ ]+").Where(u => u.Length > 0);
|
||||||
|
//useCurrentCulture ? char.ToLower(chars[i], CultureInfo.InvariantCulture) : char.ToLowerInvariant(chars[i]);
|
||||||
|
if (toLower) q = q.Select(u => u.ToLower());
|
||||||
|
return q.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ToSnake(this string str) => str.SplitWord().JoinAsString("_");
|
||||||
|
public static string ToKebab(this string str) => str.SplitWord().JoinAsString("-");
|
||||||
|
public static string ToPascal(this string str) => str.SplitWord().Select(a => a.UpperFirst()).JoinAsString("");
|
||||||
|
public static string ToCamel(this string str) => str.SplitWord().Select((a, i) => i == 0 ? a : a.UpperFirst()).JoinAsString("");
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
45
common/Tnb.Common/Models/DObject.cs
Normal file
45
common/Tnb.Common/Models/DObject.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
namespace Tnb.Core;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 字典对象
|
||||||
|
/// </summary>
|
||||||
|
public class DObject : Dictionary<string, object>
|
||||||
|
{
|
||||||
|
public DObject() { }
|
||||||
|
public DObject(string key, object value)
|
||||||
|
{
|
||||||
|
Add(key, value);
|
||||||
|
}
|
||||||
|
public DObject(Dictionary<string, object> dictionary) : base(dictionary)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public void AddCascade(string code, object value)
|
||||||
|
{
|
||||||
|
var keys = code.Split('.');
|
||||||
|
if (keys.Length == 1)
|
||||||
|
{
|
||||||
|
Add(code, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < keys.Length; i++)
|
||||||
|
{
|
||||||
|
DObject temp = this;
|
||||||
|
if (i < keys.Length - 1)
|
||||||
|
{
|
||||||
|
if (!ContainsKey(keys[i]))
|
||||||
|
{
|
||||||
|
temp = new DObject();
|
||||||
|
Add(keys[i], temp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
temp = (DObject)temp[keys[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
temp.Add(keys[i], value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -643,7 +643,7 @@ public class DataBaseService : IDynamicApiController, ITransient
|
|||||||
var prefix = tbl.Name.Split('_')[0] + "_";
|
var prefix = tbl.Name.Split('_')[0] + "_";
|
||||||
if (!nsMapper.ContainsKey(prefix)) continue;
|
if (!nsMapper.ContainsKey(prefix)) continue;
|
||||||
|
|
||||||
var entityName = string.Join("", tbl.Name.Split('_').Select(a => a.ToPascalCase()));
|
var entityName = string.Join("", tbl.Name.Split('_').Select(a => a.ToPascal()));
|
||||||
//sugar.MappingTables.Add(entityName, tbl.Name);
|
//sugar.MappingTables.Add(entityName, tbl.Name);
|
||||||
DbEntityInfo model = new() { tableName = tbl.Name, descrip = tbl.Description, clsName = entityName, nsName = nsMapper[prefix] };
|
DbEntityInfo model = new() { tableName = tbl.Name, descrip = tbl.Description, clsName = entityName, nsName = nsMapper[prefix] };
|
||||||
foreach (var field in sugar.DbMaintenance.GetColumnInfosByTableName(tbl.Name))
|
foreach (var field in sugar.DbMaintenance.GetColumnInfosByTableName(tbl.Name))
|
||||||
|
|||||||
16
visualdev/Tnb.Vengine/AppService/IVengineAppService.cs
Normal file
16
visualdev/Tnb.Vengine/AppService/IVengineAppService.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||||
|
// https://git.tuotong-tech.com/tnb/tnb-server //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
using JNPF.DependencyInjection;
|
||||||
|
|
||||||
|
namespace Tnb.Vengine.AppService;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 通用服务接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IVengineAppService : ITransient
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
// https://git.tuotong-tech.com/tnb/tnb-server //
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
using JNPF.DependencyInjection;
|
using JNPF.DependencyInjection;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
// https://git.tuotong-tech.com/tnb/tnb-server //
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
using JNPF.DependencyInjection;
|
using JNPF.DependencyInjection;
|
||||||
|
|||||||
203
visualdev/Tnb.Vengine/AppService/VengineAppService.cs
Normal file
203
visualdev/Tnb.Vengine/AppService/VengineAppService.cs
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||||
|
// https://git.tuotong-tech.com/tnb/tnb-server //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
using JNPF.Common.Security;
|
||||||
|
using Mapster;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using SqlSugar;
|
||||||
|
using Tnb.Core;
|
||||||
|
using Tnb.Vengine.DataAccess;
|
||||||
|
using Tnb.Vengine.Domain;
|
||||||
|
|
||||||
|
namespace Tnb.Vengine.AppService;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 增删改查基类
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 100)]
|
||||||
|
[Route("/")]
|
||||||
|
public class VengineAppService : BaseAppService, IVengineAppService
|
||||||
|
{
|
||||||
|
private readonly IDataAccess _dataAccess;
|
||||||
|
private readonly ISqlSugarClient _db;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构造函数
|
||||||
|
/// </summary>
|
||||||
|
public VengineAppService(IDataAccess da)
|
||||||
|
{
|
||||||
|
_dataAccess = da;
|
||||||
|
_db = _dataAccess.GetSqlSugar();
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 按模型的id进行增删改查接口
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取一条 数据信息
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("api/[area]/[controller]/{vmid}/get")]
|
||||||
|
public async Task<dynamic?> GetAsync(string vmid, VmGetInput input)
|
||||||
|
{
|
||||||
|
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
||||||
|
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||||
|
if (input.id != null)
|
||||||
|
{
|
||||||
|
if (arg.q == null) arg.q = new DObject();
|
||||||
|
arg.q.Add(vm.GetPrimary().code, input.id);
|
||||||
|
}
|
||||||
|
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||||
|
return ls.items.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取多条 数据列表
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("api/[area]/[controller]/{vmid}/get-list")]
|
||||||
|
public async Task<VmPagedOutput> GetListAsync(string vmid, VmGetListInput input)
|
||||||
|
{
|
||||||
|
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
||||||
|
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||||
|
if (!string.IsNullOrEmpty(input.q))
|
||||||
|
{
|
||||||
|
arg.q = input.q.ToObject<DObject>();
|
||||||
|
}
|
||||||
|
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||||
|
return ls;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取多条 数据列表
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("api/[area]/[controller]/{vmid}/query")]
|
||||||
|
public async Task<VmPagedOutput> QueryAsync(string vmid, VmQueryInput input)
|
||||||
|
{
|
||||||
|
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
||||||
|
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
||||||
|
return ls;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增 数据
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("api/[area]/[controller]/{vmid}/create")]
|
||||||
|
public async Task<dynamic> CreateAsync(string vmid, VmCreateInput input)
|
||||||
|
{
|
||||||
|
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
||||||
|
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新 数据
|
||||||
|
/// </summary>
|
||||||
|
[HttpPut("api/[area]/[controller]/{vmid}/update")]
|
||||||
|
public async Task<dynamic> UpdateAsync(string vmid, VmUpdateInput input)
|
||||||
|
{
|
||||||
|
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
||||||
|
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除 数据
|
||||||
|
/// </summary>
|
||||||
|
[HttpDelete("api/[area]/[controller]/{vmid}/delete")]
|
||||||
|
public async Task<dynamic> DeleteAsync(string vmid, VmDeleteInput input)
|
||||||
|
{
|
||||||
|
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
||||||
|
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 按模型的areaCode和vmcode进行增删改查接口
|
||||||
|
|
||||||
|
private async Task<Vmodel> GetVmodelAsync(string areaCode, string vmCode)
|
||||||
|
{
|
||||||
|
var vm = await _dataAccess.GetVmodelAsync(areaCode, vmCode, false);
|
||||||
|
return vm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取一条 数据信息
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("api/{areaCode}/{vmCode}/get")]
|
||||||
|
public async Task<dynamic?> GetAsync(string areaCode, string vmCode, VmGetInput input)
|
||||||
|
{
|
||||||
|
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||||
|
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||||
|
if (input.id != null)
|
||||||
|
{
|
||||||
|
if (arg.q == null) arg.q = new DObject();
|
||||||
|
arg.q.Add(vm.GetPrimary().code, input.id);
|
||||||
|
}
|
||||||
|
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||||
|
return ls.items.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取多条 数据列表
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("api/{areaCode}/{vmCode}/get-list")]
|
||||||
|
public async Task<VmPagedOutput> GetListAsync(string areaCode, string vmCode, VmGetListInput input)
|
||||||
|
{
|
||||||
|
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||||
|
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||||
|
if (!string.IsNullOrEmpty(input.q))
|
||||||
|
{
|
||||||
|
arg.q = input.q.ToObject<DObject>();
|
||||||
|
}
|
||||||
|
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||||
|
return ls;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取多条 数据列表
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("api/{areaCode}/{vmCode}/query")]
|
||||||
|
public async Task<VmPagedOutput> QueryAsync(string areaCode, string vmCode, VmQueryInput input)
|
||||||
|
{
|
||||||
|
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||||
|
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
||||||
|
return ls;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增 数据
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost("api/{areaCode}/{vmCode}/create")]
|
||||||
|
public async Task<dynamic> CreateAsync(string areaCode, string vmCode, VmCreateInput input)
|
||||||
|
{
|
||||||
|
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||||
|
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新 数据
|
||||||
|
/// </summary>
|
||||||
|
[HttpPut("api/{areaCode}/{vmCode}/update")]
|
||||||
|
public async Task<dynamic> UpdateAsync(string areaCode, string vmCode, VmUpdateInput input)
|
||||||
|
{
|
||||||
|
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||||
|
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除 数据
|
||||||
|
/// </summary>
|
||||||
|
[HttpDelete("api/{areaCode}/{vmCode}/delete")]
|
||||||
|
public async Task<dynamic> DeleteAsync(string areaCode, string vmCode, VmDeleteInput input)
|
||||||
|
{
|
||||||
|
var vm = await GetVmodelAsync(areaCode, vmCode);
|
||||||
|
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
140
visualdev/Tnb.Vengine/AppService/VengineAppServiceT.cs
Normal file
140
visualdev/Tnb.Vengine/AppService/VengineAppServiceT.cs
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||||
|
// https://git.tuotong-tech.com/tnb/tnb-server //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
using System.Reflection;
|
||||||
|
using JNPF;
|
||||||
|
using JNPF.Common.Security;
|
||||||
|
using Mapster;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using SqlSugar;
|
||||||
|
using Tnb.Core;
|
||||||
|
using Tnb.Vengine.DataAccess;
|
||||||
|
using Tnb.Vengine.Domain;
|
||||||
|
|
||||||
|
namespace Tnb.Vengine.AppService;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 增删改查基类
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
//[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
|
||||||
|
[Route("api/[area]/[controller]/[action]")]
|
||||||
|
public class VengineAppService<TEntity> : BaseAppService where TEntity : Entity
|
||||||
|
{
|
||||||
|
protected readonly IDataAccess _dataAccess;
|
||||||
|
protected readonly ISqlSugarClient _db;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构造函数
|
||||||
|
/// </summary>
|
||||||
|
public VengineAppService(IDataAccess dataAccess)
|
||||||
|
{
|
||||||
|
_dataAccess = dataAccess;
|
||||||
|
_db = _dataAccess.GetSqlSugar();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<Vmodel> GetVmodelAsync()
|
||||||
|
{
|
||||||
|
var tp = typeof(TEntity);
|
||||||
|
string? area = null, code = null;
|
||||||
|
var vset = tp.GetCustomAttribute<VmodelSettingAttribute>();
|
||||||
|
if (vset != null)
|
||||||
|
{
|
||||||
|
area = vset.Area;
|
||||||
|
code = vset.Code;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(area))
|
||||||
|
{
|
||||||
|
ThrowIf.IsNullOrEmpty(tp.Namespace, $"类型 {nameof(tp)} 的命名空间不可为空");
|
||||||
|
area = tp.Namespace.RemovePreFix(ModuleConst.NsPrefix + ".").Replace(".Domain", "").Replace(".Entities", "").ToKebab();
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(code))
|
||||||
|
{
|
||||||
|
code = tp.Name.ToKebab();
|
||||||
|
}
|
||||||
|
var vm = await _dataAccess.GetVmodelAsync(area, code, true);
|
||||||
|
|
||||||
|
return vm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取一条 数据信息
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet]
|
||||||
|
public virtual async Task<dynamic> GetAsync(VmGetInput input)
|
||||||
|
{
|
||||||
|
var vm = await GetVmodelAsync();
|
||||||
|
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||||
|
if (input.id != null)
|
||||||
|
{
|
||||||
|
if (arg.q == null) arg.q = new DObject();
|
||||||
|
arg.q.Add(vm.GetPrimary().code, input.id);
|
||||||
|
}
|
||||||
|
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||||
|
return ls.items.FirstOrDefault()!;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取多条 数据列表
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet]
|
||||||
|
public virtual async Task<VmPagedOutput> GetListAsync(VmGetListInput input)
|
||||||
|
{
|
||||||
|
var vm = await GetVmodelAsync();
|
||||||
|
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
||||||
|
if (!string.IsNullOrEmpty(input.q))
|
||||||
|
{
|
||||||
|
arg.q = input.q.ToObject<DObject>();
|
||||||
|
}
|
||||||
|
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
||||||
|
return ls;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取多条 数据列表
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost]
|
||||||
|
public virtual async Task<VmPagedOutput> QueryAsync(VmQueryInput input)
|
||||||
|
{
|
||||||
|
var vm = await GetVmodelAsync();
|
||||||
|
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
||||||
|
return ls;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增 数据
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost]
|
||||||
|
public virtual async Task<dynamic> CreateAsync(VmCreateInput input)
|
||||||
|
{
|
||||||
|
var vm = await GetVmodelAsync();
|
||||||
|
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新 数据
|
||||||
|
/// </summary>
|
||||||
|
[HttpPut]
|
||||||
|
public virtual async Task<dynamic> UpdateAsync(VmUpdateInput input)
|
||||||
|
{
|
||||||
|
var vm = await GetVmodelAsync();
|
||||||
|
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除 数据
|
||||||
|
/// </summary>
|
||||||
|
[HttpDelete]
|
||||||
|
public virtual async Task<dynamic> DeleteAsync(VmDeleteInput input)
|
||||||
|
{
|
||||||
|
var vm = await GetVmodelAsync();
|
||||||
|
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
|
||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
using JNPF.Common.Security;
|
|
||||||
using Mapster;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using SqlSugar;
|
|
||||||
using Tnb.Vengine.DataAccess;
|
|
||||||
using Tnb.Vengine.Domain;
|
|
||||||
|
|
||||||
namespace Tnb.Vengine.AppService;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 增删改查基类
|
|
||||||
/// </summary>
|
|
||||||
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 10, KeepVerb = true)]
|
|
||||||
[Route("api")]
|
|
||||||
public class VmAppService : BaseAppService
|
|
||||||
{
|
|
||||||
private readonly IDataAccess _dataAccess;
|
|
||||||
private readonly ISqlSugarClient _db;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
public VmAppService(IDataAccess da)
|
|
||||||
{
|
|
||||||
_dataAccess = da;
|
|
||||||
_db = _dataAccess.GetSqlSugar();
|
|
||||||
}
|
|
||||||
|
|
||||||
#region 根据vmodel id进行增删改查接口
|
|
||||||
/// <summary>
|
|
||||||
/// 获取一条 数据信息
|
|
||||||
/// </summary>
|
|
||||||
[HttpGet("[area]/[controller]/{vmid}/[action]")]
|
|
||||||
public async Task<dynamic?> GetAsync(string vmid, [FromQuery] VmGetInput input)
|
|
||||||
{
|
|
||||||
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
|
||||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
|
||||||
if (input.id != null)
|
|
||||||
{
|
|
||||||
if (arg.q == null) arg.q = new DObject();
|
|
||||||
arg.q.Add(vm.GetPrimary().code, input.id);
|
|
||||||
}
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
|
||||||
return ls.items.FirstOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取多条 数据列表
|
|
||||||
/// </summary>
|
|
||||||
[HttpGet("[area]/[controller]/{vmid}/[action]")]
|
|
||||||
public async Task<VmPagedOutput> GetListAsync(string vmid, [FromQuery] VmGetListInput input)
|
|
||||||
{
|
|
||||||
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
|
||||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
|
||||||
if (!string.IsNullOrEmpty(input.q))
|
|
||||||
{
|
|
||||||
arg.q = input.q.ToObject<DObject>();
|
|
||||||
}
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
|
||||||
return ls;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取多条 数据列表
|
|
||||||
/// </summary>
|
|
||||||
[HttpPost("[area]/[controller]/{vmid}/[action]")]
|
|
||||||
public async Task<VmPagedOutput> QueryAsync(string vmid, [FromBody] VmQueryInput input)
|
|
||||||
{
|
|
||||||
var vm = await _dataAccess.GetVmodelAsync(vmid, true);
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
|
||||||
return ls;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 新增 数据
|
|
||||||
/// </summary>
|
|
||||||
[HttpPost("[area]/[controller]/{vmid}/[action]")]
|
|
||||||
public async Task<dynamic> CreateAsync(string vmid, VmCreateInput input)
|
|
||||||
{
|
|
||||||
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
|
||||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 更新 数据
|
|
||||||
/// </summary>
|
|
||||||
[HttpPut("[area]/[controller]/{vmid}/[action]")]
|
|
||||||
public async Task<dynamic> UpdateAsync(string vmid, VmUpdateInput input)
|
|
||||||
{
|
|
||||||
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
|
||||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 删除 数据
|
|
||||||
/// </summary>
|
|
||||||
[HttpDelete("[area]/[controller]/{vmid}/[action]")]
|
|
||||||
public async Task<dynamic> DeleteAsync(string vmid, [FromQuery] VmDeleteInput input)
|
|
||||||
{
|
|
||||||
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
|
||||||
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<Vmodel> GetVmodelAsync(string area, string vmCode)
|
|
||||||
{
|
|
||||||
var vm = await _dataAccess.GetVmodelAsync(area.SnakeToPascalCase(), vmCode.SnakeToPascalCase(), true);
|
|
||||||
return vm;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 根据vmode的area和code进行增删改查接口
|
|
||||||
/// <summary>
|
|
||||||
/// 获取一条 数据信息
|
|
||||||
/// </summary>
|
|
||||||
[HttpGet("{areaCode}/{vmCode}/[action]")]
|
|
||||||
public async Task<dynamic?> GetAsync(string areaCode, string vmCode, [FromQuery] VmGetInput input)
|
|
||||||
{
|
|
||||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
|
||||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
|
||||||
if (input.id != null)
|
|
||||||
{
|
|
||||||
if (arg.q == null) arg.q = new DObject();
|
|
||||||
arg.q.Add(vm.GetPrimary().code, input.id);
|
|
||||||
}
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
|
||||||
return ls.items.FirstOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取多条 数据列表
|
|
||||||
/// </summary>
|
|
||||||
[HttpGet("{areaCode}/{vmCode}/[action]")]
|
|
||||||
public async Task<VmPagedOutput> GetListAsync(string areaCode, string vmCode, [FromQuery] VmGetListInput input)
|
|
||||||
{
|
|
||||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
|
||||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
|
||||||
if (!string.IsNullOrEmpty(input.q))
|
|
||||||
{
|
|
||||||
arg.q = input.q.ToObject<DObject>();
|
|
||||||
}
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
|
||||||
return ls;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取多条 数据列表
|
|
||||||
/// </summary>
|
|
||||||
[HttpPost("{areaCode}/{vmCode}/[action]")]
|
|
||||||
public async Task<VmPagedOutput> QueryAsync(string areaCode, string vmCode, [FromBody] VmQueryInput input)
|
|
||||||
{
|
|
||||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
|
||||||
return ls;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 新增 数据
|
|
||||||
/// </summary>
|
|
||||||
[HttpPost("{areaCode}/{vmCode}/[action]")]
|
|
||||||
public async Task<dynamic> CreateAsync(string areaCode, string vmCode, VmCreateInput input)
|
|
||||||
{
|
|
||||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
|
||||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 更新 数据
|
|
||||||
/// </summary>
|
|
||||||
[HttpPut("{areaCode}/{vmCode}/[action]")]
|
|
||||||
public async Task<dynamic> UpdateAsync(string areaCode, string vmCode, VmUpdateInput input)
|
|
||||||
{
|
|
||||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
|
||||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 删除 数据
|
|
||||||
/// </summary>
|
|
||||||
[HttpDelete("{areaCode}/{vmCode}/[action]")]
|
|
||||||
public async Task<dynamic> DeleteAsync(string areaCode, string vmCode, [FromQuery] VmDeleteInput input)
|
|
||||||
{
|
|
||||||
var vm = await GetVmodelAsync(areaCode, vmCode);
|
|
||||||
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
|
||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
using JNPF.Common.Contracts;
|
|
||||||
using JNPF.Common.Security;
|
|
||||||
using Mapster;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using SqlSugar;
|
|
||||||
using Tnb.Vengine.DataAccess;
|
|
||||||
using Tnb.Vengine.Domain;
|
|
||||||
|
|
||||||
namespace Tnb.Vengine.AppService;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 增删改查基类
|
|
||||||
/// </summary>
|
|
||||||
[ApiDescriptionSettings(Area = ModuleConst.Area, Order = 10, KeepVerb = true)]
|
|
||||||
[Route("api/[area]/[controller]/[action]")]
|
|
||||||
public class VmAppService<TEntity> : BaseAppService where TEntity : IEntity
|
|
||||||
{
|
|
||||||
protected readonly IDataAccess _dataAccess;
|
|
||||||
protected readonly ISqlSugarClient _db;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 构造函数
|
|
||||||
/// </summary>
|
|
||||||
public VmAppService(IDataAccess dataAccess)
|
|
||||||
{
|
|
||||||
_dataAccess = dataAccess;
|
|
||||||
_db = _dataAccess.GetSqlSugar();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async Task<Vmodel> GetVmodelAsync()
|
|
||||||
{
|
|
||||||
var tp = typeof(TEntity);
|
|
||||||
if (string.IsNullOrEmpty(tp?.Namespace))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException($"类型 {nameof(tp)} 的命名空间不可为空");
|
|
||||||
}
|
|
||||||
var area = tp.Namespace.Split('.').Last().ToKebabCase();
|
|
||||||
var vm = await _dataAccess.GetVmodelAsync(area, tp.Name, true);
|
|
||||||
|
|
||||||
return vm;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取一条 数据信息
|
|
||||||
/// </summary>
|
|
||||||
public virtual async Task<dynamic> GetAsync([FromQuery] VmGetInput input)
|
|
||||||
{
|
|
||||||
var vm = await GetVmodelAsync();
|
|
||||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
|
||||||
if (input.id != null)
|
|
||||||
{
|
|
||||||
if (arg.q == null) arg.q = new DObject();
|
|
||||||
arg.q.Add(vm.GetPrimary().code, input.id);
|
|
||||||
}
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
|
||||||
return ls.items.FirstOrDefault()!;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取多条 数据列表
|
|
||||||
/// </summary>
|
|
||||||
public virtual async Task<VmPagedOutput> GetListAsync([FromQuery] VmGetListInput input)
|
|
||||||
{
|
|
||||||
var vm = await GetVmodelAsync();
|
|
||||||
VmQueryInput arg = input.Adapt<VmQueryInput>();
|
|
||||||
if (!string.IsNullOrEmpty(input.q))
|
|
||||||
{
|
|
||||||
arg.q = input.q.ToObject<DObject>();
|
|
||||||
}
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, arg);
|
|
||||||
return ls;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取多条 数据列表
|
|
||||||
/// </summary>
|
|
||||||
[HttpPost]
|
|
||||||
public virtual async Task<VmPagedOutput> QueryAsync([FromBody] VmQueryInput input)
|
|
||||||
{
|
|
||||||
var vm = await GetVmodelAsync();
|
|
||||||
var ls = await _dataAccess.QueryDataAsync(vm, input);
|
|
||||||
return ls;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 新增 数据
|
|
||||||
/// </summary>
|
|
||||||
public virtual async Task<dynamic> CreateAsync(VmCreateInput input)
|
|
||||||
{
|
|
||||||
var vm = await GetVmodelAsync();
|
|
||||||
var ret = await _dataAccess.CreateDataAsync(vm, input);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 更新 数据
|
|
||||||
/// </summary>
|
|
||||||
public virtual async Task<dynamic> UpdateAsync(VmUpdateInput input)
|
|
||||||
{
|
|
||||||
var vm = await GetVmodelAsync();
|
|
||||||
var ret = await _dataAccess.UpdateDataAsync(vm, input);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 删除 数据
|
|
||||||
/// </summary>
|
|
||||||
public virtual async Task<dynamic> DeleteAsync([FromQuery] VmDeleteInput input)
|
|
||||||
{
|
|
||||||
var vm = await GetVmodelAsync();
|
|
||||||
var ret = await _dataAccess.DeleteDataAsync(vm, input);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,27 +1,35 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
// https://git.tuotong-tech.com/tnb/tnb-server //
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
using JNPF.Common.Configuration;
|
||||||
|
using JNPF.Systems.Entitys.Dto.Database;
|
||||||
|
using JNPF;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using Tnb.Core;
|
||||||
using Tnb.Vengine.DataAccess;
|
using Tnb.Vengine.DataAccess;
|
||||||
using Tnb.Vengine.Domain;
|
using Tnb.Vengine.Domain;
|
||||||
|
using JNPF.ViewEngine;
|
||||||
|
|
||||||
namespace Tnb.Vengine.AppService;
|
namespace Tnb.Vengine.AppService;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 视图模型服务类
|
/// 视图模型服务类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class VmodelAppService : VmAppService<Vmodel>, IVmodelAppService
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, KeepVerb = true, Order = 1102)]
|
||||||
|
[Route("api/[area]/[controller]/[action]")]
|
||||||
|
public class VmodelAppService : VengineAppService<Vmodel>, IVmodelAppService
|
||||||
{
|
{
|
||||||
|
private readonly ViewEngine _viewEngine;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public VmodelAppService(IDataAccess da) : base(da)
|
public VmodelAppService(IDataAccess da, ViewEngine viewEngine) : base(da)
|
||||||
{
|
{
|
||||||
|
_viewEngine = viewEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -29,12 +37,12 @@ public class VmodelAppService : VmAppService<Vmodel>, IVmodelAppService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override async Task<dynamic> GetAsync(VmGetInput input)
|
public override async Task<dynamic> GetAsync(VmGetInput input)
|
||||||
{
|
{
|
||||||
//return await _dataAccess.GetVmodelAsync(input.id);
|
|
||||||
var query = _db.Queryable<Vmodel>().Where(a => a.deleted == 0);
|
var query = _db.Queryable<Vmodel>().Where(a => a.deleted == 0);
|
||||||
Vmodel vm;
|
Vmodel vm;
|
||||||
if (long.TryParse(input.id, out long id))
|
if (long.TryParse(input.id, out long id))
|
||||||
{
|
{
|
||||||
vm = await query.FirstAsync(a => a.id == input.id);
|
query.Where(a => a.id == input.id);
|
||||||
|
vm = await query.FirstAsync();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -68,11 +76,13 @@ public class VmodelAppService : VmAppService<Vmodel>, IVmodelAppService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override async Task<dynamic> CreateAsync(VmCreateInput input)
|
public override async Task<dynamic> CreateAsync(VmCreateInput input)
|
||||||
{
|
{
|
||||||
//ThrowIf.IsNull(input.data, nameof(input));
|
ThrowIf.IsNull(input.data);
|
||||||
ArgumentNullException.ThrowIfNull(input.data);
|
//ArgumentNullException.ThrowIfNull(input.data);
|
||||||
Vmodel vm = input.data.Adapt<Vmodel>();
|
Vmodel vm = input.data.Adapt<Vmodel>();
|
||||||
|
vm.areaCode = vm.areaCode.ToKebab();
|
||||||
|
vm.vmCode = vm.vmCode.ToKebab();
|
||||||
await _db.Insertable(vm).ExecuteCommandAsync();
|
await _db.Insertable(vm).ExecuteCommandAsync();
|
||||||
return input;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -80,8 +90,11 @@ public class VmodelAppService : VmAppService<Vmodel>, IVmodelAppService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override async Task<dynamic> UpdateAsync(VmUpdateInput input)
|
public override async Task<dynamic> UpdateAsync(VmUpdateInput input)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(input.data);
|
ThrowIf.IsNull(input.data);
|
||||||
|
//ArgumentNullException.ThrowIfNull(input.data);
|
||||||
Vmodel vm = input.data.Adapt<Vmodel>();
|
Vmodel vm = input.data.Adapt<Vmodel>();
|
||||||
|
vm.areaCode = vm.areaCode.ToKebab();
|
||||||
|
vm.vmCode = vm.vmCode.ToKebab();
|
||||||
await _db.Updateable(vm).WhereColumns(a => a.id).ExecuteCommandAsync();
|
await _db.Updateable(vm).WhereColumns(a => a.id).ExecuteCommandAsync();
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
@@ -100,10 +113,10 @@ public class VmodelAppService : VmAppService<Vmodel>, IVmodelAppService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<List<Vmodel>> CreateFromTable(VmodelCreateFromTableInput input)
|
public async Task<List<Vmodel>> CreateFromTable(VmodelCreateFromTableInput input)
|
||||||
{
|
{
|
||||||
ThrowIf.IsNull(input.tableName, nameof(input.tableName));
|
ThrowIf.IsNullOrEmpty(input.tableName);
|
||||||
var sugar = _dataAccess.GetSqlSugar(input.dbCode);
|
var sugar = _dataAccess.GetSqlSugar(input.dbCode);
|
||||||
var lsTable = sugar.DbMaintenance.GetTableInfoList().WhereIF(input.tableName != "ALL", a => a.Name == input.tableName);
|
var lsTable = sugar.DbMaintenance.GetTableInfoList().WhereIF(input.tableName != "ALL", a => a.Name == input.tableName);
|
||||||
|
input.areaCode = input.areaCode.ToPascal();
|
||||||
List<Vmodel> lsToAdd = new List<Vmodel>();
|
List<Vmodel> lsToAdd = new List<Vmodel>();
|
||||||
List<Vmodel> lsToUpdate = new List<Vmodel>();
|
List<Vmodel> lsToUpdate = new List<Vmodel>();
|
||||||
foreach (var tb in lsTable)
|
foreach (var tb in lsTable)
|
||||||
@@ -111,8 +124,8 @@ public class VmodelAppService : VmAppService<Vmodel>, IVmodelAppService
|
|||||||
if (!string.IsNullOrEmpty(input.removePrefix) && !tb.Name.StartsWith(input.removePrefix)) continue;
|
if (!string.IsNullOrEmpty(input.removePrefix) && !tb.Name.StartsWith(input.removePrefix)) continue;
|
||||||
var colInfo = sugar.DbMaintenance.GetColumnInfosByTableName(tb.Name);
|
var colInfo = sugar.DbMaintenance.GetColumnInfosByTableName(tb.Name);
|
||||||
Vmodel model = new() { dbCode = input.dbCode, vmName = tb.Description, tableName = tb.Name };
|
Vmodel model = new() { dbCode = input.dbCode, vmName = tb.Description, tableName = tb.Name };
|
||||||
model.area = input.area;
|
model.areaCode = input.areaCode.ToKebab();
|
||||||
model.vmCode = (string.IsNullOrEmpty(input.removePrefix) ? tb.Name : tb.Name.RemovePreFix(input.removePrefix)).SnakeToPascalCase();
|
model.vmCode = (string.IsNullOrEmpty(input.removePrefix) ? tb.Name.ToKebab() : tb.Name.RemovePreFix(input.removePrefix)).ToKebab();
|
||||||
//model.createId = CurrentUser.Id;
|
//model.createId = CurrentUser.Id;
|
||||||
int n = 1;
|
int n = 1;
|
||||||
foreach (var p in colInfo)
|
foreach (var p in colInfo)
|
||||||
@@ -120,6 +133,9 @@ public class VmodelAppService : VmAppService<Vmodel>, IVmodelAppService
|
|||||||
var prop = p.Adapt<VmDbProp>();
|
var prop = p.Adapt<VmDbProp>();
|
||||||
prop.ordinal = n++;
|
prop.ordinal = n++;
|
||||||
prop.csType = sugar.Ado.DbBind.GetPropertyTypeName(p.DataType);
|
prop.csType = sugar.Ado.DbBind.GetPropertyTypeName(p.DataType);
|
||||||
|
//var s1 = sugar.Ado.DbBind.GetCsharpTypeName(p.DataType); // 和DataType是一样的
|
||||||
|
//var s2 = sugar.Ado.DbBind.GetCsharpTypeNameByDbTypeName(p.DataType); // 和GetPropertyTypeName是一样的
|
||||||
|
//Console.WriteLine($"dbType = {p.DataType}, csType = {prop.csType} | {s1} | {s2}");
|
||||||
model.dbProps.Add(prop);
|
model.dbProps.Add(prop);
|
||||||
}
|
}
|
||||||
var exist = await _db.Queryable<Vmodel>().FirstAsync(a => a.dbCode == input.dbCode && a.tableName == tb.Name);
|
var exist = await _db.Queryable<Vmodel>().FirstAsync(a => a.dbCode == input.dbCode && a.tableName == tb.Name);
|
||||||
@@ -129,10 +145,8 @@ public class VmodelAppService : VmAppService<Vmodel>, IVmodelAppService
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
exist.area = model.area;
|
exist.dbProps.Clear();
|
||||||
model.dbProps.Adapt(exist.dbProps);
|
exist.dbProps.AddRange(model.dbProps.OrderBy(a => a.ordinal));
|
||||||
//exist.dbProps.Clear();
|
|
||||||
//exist.dbProps.AddRange(model.dbProps.OrderBy(a => a.ordinal));
|
|
||||||
lsToUpdate.Add(exist);
|
lsToUpdate.Add(exist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,5 +161,69 @@ public class VmodelAppService : VmAppService<Vmodel>, IVmodelAppService
|
|||||||
return lsToAdd.Union(lsToUpdate).ToList();
|
return lsToAdd.Union(lsToUpdate).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生成模型代码
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<dynamic> BuildEntityCodeAsync(string vmid)
|
||||||
|
{
|
||||||
|
var vm = await _dataAccess.GetVmodelAsync(vmid);
|
||||||
|
var ignores = new string[] { };//"SysViewModel", "SysViewProp"
|
||||||
|
ThrowIf.When(ignores.Contains(vm.vmCode), $"模型 {vm.vmCode} 不允许自动生成");
|
||||||
|
ThrowIf.When(!vm.dbProps.Any(), $"模型 {vm.vmCode} 属性不可为空");
|
||||||
|
|
||||||
|
vm.areaCode = vm.areaCode.ToPascal();
|
||||||
|
vm.vmCode = vm.vmCode.ToPascal();
|
||||||
|
AcmenVmodelContext ctx = new AcmenVmodelContext(_dataAccess, vm);
|
||||||
|
string tplPath = Path.Combine(App.WebHostEnvironment.WebRootPath, "Template", "VengineSqlSugar");
|
||||||
|
string entityPath = Path.Combine(ctx.BasePath, ctx.NsPrefix + "." + vm.areaCode, "AppService", vm.vmCode);
|
||||||
|
|
||||||
|
string filePath, code, tplContent;
|
||||||
|
//创建模型码农类
|
||||||
|
tplContent = File.ReadAllText(Path.Combine(tplPath, "EntityInfoAcmen.cshtml"));
|
||||||
|
code = _viewEngine.RunCompileFromCached(tplContent, ctx);
|
||||||
|
CodeHelper.SaveCodeToFile(code, Path.Combine(entityPath, $"{vm.vmCode}.acmen.cs"));
|
||||||
|
//创建模型手动代码类
|
||||||
|
filePath = Path.Combine(entityPath, $"{vm.vmCode}.cs");
|
||||||
|
if (!File.Exists(filePath))
|
||||||
|
{
|
||||||
|
tplContent = File.ReadAllText(Path.Combine(tplPath, "EntityInfo.cshtml"));
|
||||||
|
code = _viewEngine.RunCompileFromCached(tplContent, ctx);
|
||||||
|
CodeHelper.SaveCodeToFile(code, filePath);
|
||||||
|
}
|
||||||
|
//创建模型Dto码农类
|
||||||
|
tplContent = File.ReadAllText(Path.Combine(tplPath, "EntityDtoAcmen.cshtml"));
|
||||||
|
code = _viewEngine.RunCompileFromCached(tplContent, ctx);
|
||||||
|
CodeHelper.SaveCodeToFile(code, Path.Combine(entityPath, $"{vm.vmCode}Dto.acmen.cs"));
|
||||||
|
//创建模型Dto手动代码类
|
||||||
|
filePath = Path.Combine(entityPath, $"{vm.vmCode}Dto.cs");
|
||||||
|
if (!File.Exists(filePath))
|
||||||
|
{
|
||||||
|
tplContent = File.ReadAllText(Path.Combine(tplPath, "EntityDto.cshtml"));
|
||||||
|
code = _viewEngine.RunCompileFromCached(tplContent, ctx);
|
||||||
|
CodeHelper.SaveCodeToFile(code, filePath);
|
||||||
|
}
|
||||||
|
//创建模型服务手动代码类
|
||||||
|
filePath = Path.Combine(entityPath, $"{vm.vmCode}AppService.cs");
|
||||||
|
if (!File.Exists(filePath))
|
||||||
|
{
|
||||||
|
tplContent = File.ReadAllText(Path.Combine(tplPath, "AppService.cshtml"));
|
||||||
|
code = _viewEngine.RunCompileFromCached(tplContent, ctx);
|
||||||
|
CodeHelper.SaveCodeToFile(code, filePath);
|
||||||
|
}
|
||||||
|
////创建页面视图文件
|
||||||
|
////string vueFileName = view.ViewCode == entity.EntityCode ? "index" : view.ViewCode.ToKebabCase();
|
||||||
|
//string vueFileName = "index";
|
||||||
|
//filePath = Path.Combine(ctx.PagePath, entityKebabName, vueFileName + ".vue");
|
||||||
|
//if (File.Exists(filePath))
|
||||||
|
//{
|
||||||
|
// filePath = Path.Combine(ctx.PagePath, entityKebabName, vueFileName + ".acmen.txt");
|
||||||
|
//}
|
||||||
|
//code = CodeHelper.RunCompile($"{TemplateContext.KeyEntityPageVue}.cshtml", ctx, null, "SqlSugar");
|
||||||
|
//CodeHelper.SaveCodeToFile(code, filePath);
|
||||||
|
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
34
visualdev/Tnb.Vengine/AppService/VmodelDto.cs
Normal file
34
visualdev/Tnb.Vengine/AppService/VmodelDto.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||||
|
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
namespace Tnb.Vengine.AppService;
|
||||||
|
|
||||||
|
public class VmodelCreateFromTableInput
|
||||||
|
{
|
||||||
|
public string? dbCode { get; set; }
|
||||||
|
|
||||||
|
public string tableName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string? removePrefix { get; set; }
|
||||||
|
public string areaCode { get; set; } = "edp";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CreatePageFromVmodelInput
|
||||||
|
{
|
||||||
|
public Guid? viewId { get; set; }
|
||||||
|
public string? vmid { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class VmodelGetInput
|
||||||
|
{
|
||||||
|
public long? id { get; set; }
|
||||||
|
public string? moduleCode { get; set; }
|
||||||
|
public string? vmCode { get; set; }
|
||||||
|
public string? dbCode { get; set; }
|
||||||
|
public string? tableName { get; set; }
|
||||||
|
public bool drill { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
// https://git.tuotong-tech.com/tnb/tnb-server //
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
using System.Text;
|
|
||||||
using JNPF.Common.Security;
|
using JNPF.Common.Security;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using System.Text;
|
||||||
|
using Tnb.Core;
|
||||||
using Tnb.Vengine.DataAccess;
|
using Tnb.Vengine.DataAccess;
|
||||||
using Tnb.Vengine.Domain;
|
using Tnb.Vengine.Domain;
|
||||||
|
|
||||||
@@ -16,7 +19,9 @@ namespace Tnb.Vengine.AppService;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 视图模型服务类
|
/// 视图模型服务类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class VmodelPageAppService : VmAppService<VmodelPage>, IVmodelPageAppService
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1104, KeepVerb = true)]
|
||||||
|
[Route("api/[area]/[controller]/[action]")]
|
||||||
|
public class VmodelPageAppService : VengineAppService<VmodelPage>, IVmodelPageAppService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造函数
|
/// 构造函数
|
||||||
@@ -30,8 +35,8 @@ public class VmodelPageAppService : VmAppService<VmodelPage>, IVmodelPageAppServ
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override async Task<dynamic> GetAsync(VmGetInput input)
|
public override async Task<dynamic> GetAsync(VmGetInput input)
|
||||||
{
|
{
|
||||||
var query = _db.Queryable<VmodelPage>().Where(a => a.deleted == 0);
|
var query = _db.Queryable<VmodelPage>().Where(a => a.deleted == 0 && a.id == input.id);
|
||||||
VmodelPage vm = await query.FirstAsync(a => a.id == input.id);
|
VmodelPage vm = await query.FirstAsync();
|
||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +59,7 @@ public class VmodelPageAppService : VmAppService<VmodelPage>, IVmodelPageAppServ
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override async Task<dynamic> CreateAsync(VmCreateInput input)
|
public override async Task<dynamic> CreateAsync(VmCreateInput input)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(input.data);
|
ThrowIf.IsNull(input.data);
|
||||||
VmodelPage vpage = input.data.Adapt<VmodelPage>();
|
VmodelPage vpage = input.data.Adapt<VmodelPage>();
|
||||||
await _db.Insertable(vpage).ExecuteCommandAsync();
|
await _db.Insertable(vpage).ExecuteCommandAsync();
|
||||||
return vpage;
|
return vpage;
|
||||||
@@ -65,14 +70,14 @@ public class VmodelPageAppService : VmAppService<VmodelPage>, IVmodelPageAppServ
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override async Task<dynamic> UpdateAsync(VmUpdateInput input)
|
public override async Task<dynamic> UpdateAsync(VmUpdateInput input)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(input.data);
|
ThrowIf.IsNull(input.data);
|
||||||
if (!input.data.ContainsKey(nameof(VmodelPage.id)))
|
if (!input.data.ContainsKey(nameof(VmodelPage.id)))
|
||||||
{
|
{
|
||||||
throw new Exception($"更新数据时主键({nameof(VmodelPage.id)})不可为空");
|
throw new Exception($"更新数据时主键({nameof(VmodelPage.id)})不可为空");
|
||||||
}
|
}
|
||||||
var id = input.data[nameof(VmodelPage.id)].ToString();
|
var id = input.data[nameof(VmodelPage.id)].ToString();
|
||||||
var model = await _db.Queryable<VmodelPage>().FirstAsync(a => a.id == id);
|
var model = await _db.Queryable<VmodelPage>().FirstAsync(a => a.id == id);
|
||||||
ArgumentNullException.ThrowIfNull(model);
|
ThrowIf.IsNull(model, $"找不到id={id}的视图页面数据");
|
||||||
input.data.Adapt(model, TypeAdapter.IgnoreNull);
|
input.data.Adapt(model, TypeAdapter.IgnoreNull);
|
||||||
await _db.Updateable(model).WhereColumns(a => a.id).ExecuteCommandAsync();
|
await _db.Updateable(model).WhereColumns(a => a.id).ExecuteCommandAsync();
|
||||||
return model;
|
return model;
|
||||||
@@ -92,19 +97,20 @@ public class VmodelPageAppService : VmAppService<VmodelPage>, IVmodelPageAppServ
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<VmodelPage> CreateByVmodel(CreatePageFromVmodelInput input)
|
public async Task<VmodelPage> CreateByVmodel(CreatePageFromVmodelInput input)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(input.vmid);
|
ThrowIf.IsNull(input.vmid);
|
||||||
var vm = await _dataAccess.GetVmodelAsync(input.vmid);
|
var vm = await _dataAccess.GetVmodelAsync(input.vmid);
|
||||||
ArgumentNullException.ThrowIfNull(vm);
|
ThrowIf.IsNull(vm, $"找不到id={input.vmid}的模型数据");
|
||||||
|
|
||||||
var page = await _db.Queryable<VmodelPage>().FirstAsync(a => a.vmid == vm.id);
|
var page = await _db.Queryable<VmodelPage>().FirstAsync(a => a.vmid == vm.id);
|
||||||
if (page == null)
|
if (page == null)
|
||||||
{
|
{
|
||||||
page = new VmodelPage { vmid = vm.id, code = vm.vmCode, name = vm.vmName };
|
page = new VmodelPage { vmid = vm.id, code = vm.fullCode, name = vm.vmName };
|
||||||
page.pageSchema = CreatePageSchema(vm, page.id);
|
page.pageSchema = CreatePageSchema(vm, page.id);
|
||||||
await _db.Insertable(page).ExecuteCommandAsync();
|
await _db.Insertable(page).ExecuteCommandAsync();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
page.code = vm.fullCode;
|
||||||
page.pageSchema = CreatePageSchema(vm, page.id);
|
page.pageSchema = CreatePageSchema(vm, page.id);
|
||||||
await _db.Updateable(page).ExecuteCommandAsync();
|
await _db.Updateable(page).ExecuteCommandAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
17
visualdev/Tnb.Vengine/Atrributes/VmodelSettingAttribute.cs
Normal file
17
visualdev/Tnb.Vengine/Atrributes/VmodelSettingAttribute.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
namespace Tnb.Vengine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 字典对象
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
public class VmodelSettingAttribute : Attribute
|
||||||
|
{
|
||||||
|
public string Area { get; set; }
|
||||||
|
public string? Code { get; set; }
|
||||||
|
|
||||||
|
public VmodelSettingAttribute(string area, string? code = null)
|
||||||
|
{
|
||||||
|
Area = area;
|
||||||
|
Code = code;
|
||||||
|
}
|
||||||
|
}
|
||||||
29
visualdev/Tnb.Vengine/CodeGenerator/AcmenVmodelContext.cs
Normal file
29
visualdev/Tnb.Vengine/CodeGenerator/AcmenVmodelContext.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using Tnb.Vengine.DataAccess;
|
||||||
|
using Tnb.Vengine.Domain;
|
||||||
|
|
||||||
|
namespace Tnb.Vengine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 代码生成AppService的数据上下文
|
||||||
|
/// </summary>
|
||||||
|
public class AcmenVmodelContext : TemplateContext
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 构造函数
|
||||||
|
/// </summary>
|
||||||
|
public AcmenVmodelContext(IDataAccess da, Vmodel vm) : base(vm.areaCode)
|
||||||
|
{
|
||||||
|
_da = da;
|
||||||
|
Vm = vm;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public IDataAccess _da { get; set; }
|
||||||
|
public Vmodel Vm { get; }
|
||||||
|
|
||||||
|
public string NsPrefix { get { return "Tnb"; } }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
123
visualdev/Tnb.Vengine/CodeGenerator/CodeHelper.cs
Normal file
123
visualdev/Tnb.Vengine/CodeGenerator/CodeHelper.cs
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace Tnb.Vengine;
|
||||||
|
|
||||||
|
public class CodeHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 从当前目录往上查找解决方案sln文件所在的目录
|
||||||
|
/// </summary>
|
||||||
|
public static string? GetSolutionDirectoryPath(bool includeParent = false)
|
||||||
|
{
|
||||||
|
var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
|
||||||
|
|
||||||
|
while (Directory.GetParent(currentDirectory.FullName) != null)
|
||||||
|
{
|
||||||
|
currentDirectory = Directory.GetParent(currentDirectory.FullName);
|
||||||
|
if (currentDirectory == null) return null;
|
||||||
|
|
||||||
|
if (Directory.GetFiles(currentDirectory!.FullName).FirstOrDefault(f => f.EndsWith(".sln")) != null)
|
||||||
|
{
|
||||||
|
if (includeParent && currentDirectory.Parent != null) return currentDirectory.Parent.FullName;
|
||||||
|
else return currentDirectory.FullName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保存代码到文件
|
||||||
|
/// </summary>
|
||||||
|
public static void SaveCodeToFile(string code, string saveTo)
|
||||||
|
{
|
||||||
|
var dir = Path.GetDirectoryName(saveTo);
|
||||||
|
if (!Directory.Exists(dir))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(dir!);
|
||||||
|
}
|
||||||
|
code = System.Web.HttpUtility.HtmlDecode(code);
|
||||||
|
File.WriteAllText(saveTo, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// MD5加密
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="szValue"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string String2MD5(string szValue)
|
||||||
|
{
|
||||||
|
string pwd = string.Empty;
|
||||||
|
MD5 md5 = MD5.Create();
|
||||||
|
byte[] byt = md5.ComputeHash(Encoding.Unicode.GetBytes(szValue));
|
||||||
|
for (int i = 0; i < byt.Length; i++)
|
||||||
|
{
|
||||||
|
pwd += byt[i].ToString("x"); //16进制
|
||||||
|
}
|
||||||
|
char[] arr = pwd.ToCharArray();
|
||||||
|
Array.Reverse(arr);
|
||||||
|
return new string(arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// newtonsoft json 转小驼峰
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="s"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string ToCamelCase(string s)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(s) || !char.IsUpper(s[0]))
|
||||||
|
{
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
char[] array = s.ToCharArray();
|
||||||
|
for (int i = 0; i < array.Length && (i != 1 || char.IsUpper(array[i])); i++)
|
||||||
|
{
|
||||||
|
bool flag = i + 1 < array.Length;
|
||||||
|
if (i > 0 && flag && !char.IsUpper(array[i + 1]))
|
||||||
|
{
|
||||||
|
if (char.IsSeparator(array[i + 1]))
|
||||||
|
{
|
||||||
|
array[i] = char.ToLower(array[i], CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
array[i] = char.ToLower(array[i], CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new string(array);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string LengthToString(int strLength)
|
||||||
|
{
|
||||||
|
var l = "DbConsts.";
|
||||||
|
if (strLength <= 0) { l += nameof(DbConsts.LengthText); }
|
||||||
|
else if (strLength <= DbConsts.LengthXXS) { l += nameof(DbConsts.LengthXXS); }
|
||||||
|
else if (strLength <= DbConsts.LengthXS) { l += nameof(DbConsts.LengthXS); }
|
||||||
|
else if (strLength <= DbConsts.LengthS) { l += nameof(DbConsts.LengthS); }
|
||||||
|
else if (strLength <= DbConsts.LengthM) { l += nameof(DbConsts.LengthM); }
|
||||||
|
else if (strLength <= DbConsts.LengthL) { l += nameof(DbConsts.LengthL); }
|
||||||
|
else if (strLength <= DbConsts.LengthXL) { l += nameof(DbConsts.LengthXL); }
|
||||||
|
else if (strLength <= DbConsts.LengthXXL) { l += nameof(DbConsts.LengthXXL); }
|
||||||
|
else if (strLength <= DbConsts.LengthXXXL) { l += nameof(DbConsts.LengthXXXL); }
|
||||||
|
else { l += nameof(DbConsts.LengthXXXXL); }
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int PropDefineToLength(string? propDefine)
|
||||||
|
{
|
||||||
|
float.TryParse(propDefine, out float f);
|
||||||
|
return (int)f;
|
||||||
|
}
|
||||||
|
public static int PropDefineToScale(string? propDefine)
|
||||||
|
{
|
||||||
|
float.TryParse(propDefine, out float f);
|
||||||
|
return (int)(f * 10) % 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
77
visualdev/Tnb.Vengine/CodeGenerator/TemplateContext.cs
Normal file
77
visualdev/Tnb.Vengine/CodeGenerator/TemplateContext.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Tnb.Core;
|
||||||
|
|
||||||
|
namespace Tnb.Vengine;
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public class TemplateContext
|
||||||
|
{
|
||||||
|
#region 模板文件名,同时作为模板Key
|
||||||
|
public const string KeyAppService = "AppService";
|
||||||
|
public const string KeyDto = "AppServiceDto";
|
||||||
|
public const string KeyEntity = "EntityInfo";
|
||||||
|
public const string KeyEntityDto = "EntityDto";
|
||||||
|
public const string KeyEntityAppService = "EntityController";
|
||||||
|
public const string KeyEntityPageVue = "EntityPageVue";
|
||||||
|
public const string KeyTableForeigns = "TableForeigns";
|
||||||
|
public const string KeyVmodel = "Vmodel";
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public TemplateContext(string moduleCode)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
BasePath = CodeHelper.GetSolutionDirectoryPath(false)!;
|
||||||
|
#else
|
||||||
|
BasePath = EApp.Options.App.AcmenBasePath;
|
||||||
|
#endif
|
||||||
|
ModuleCode = moduleCode;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string BasePath { get; set; }
|
||||||
|
private string ModuleCode { get; }
|
||||||
|
|
||||||
|
private string ModulePath => Path.Combine(BasePath, $"{ModuleCode}.Acmen");
|
||||||
|
private string UiProjPath => Path.Combine(BasePath, "ItMgrWeb");
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string AppServicePath => Path.Combine(ModulePath, "AppServices");
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public string PagePath => Path.Combine(UiProjPath, "src", "views");
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string GetCsName(string name)
|
||||||
|
{
|
||||||
|
name = Regex.Replace(name.TrimStart('@', '.'), @"[^\w]", "_");
|
||||||
|
name = char.IsLetter(name, 0) ? name : string.Concat("_", name);
|
||||||
|
IEnumerable<string> arrs = name.Split('_');
|
||||||
|
//if (arrs.Count() > 1 && Config.IsRemovePrefix) { arrs = arrs.Skip(1); }
|
||||||
|
//if (Config.IsSnakeCaseToPascalCase) { arrs = arrs.Select(a => a.ToPascalCase()); }
|
||||||
|
if (arrs.Count() > 0) { arrs = arrs.Select(a => a.ToPascal()); }
|
||||||
|
|
||||||
|
return string.Join("", arrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum eLambdaType
|
||||||
|
{
|
||||||
|
Join,
|
||||||
|
ManyToMany,
|
||||||
|
Where,
|
||||||
|
MemberBinding,
|
||||||
|
OneToMany
|
||||||
|
}
|
||||||
@@ -4,4 +4,5 @@ public class ModuleConst
|
|||||||
{
|
{
|
||||||
public const string Tag = "Tnb";
|
public const string Tag = "Tnb";
|
||||||
public const string Area = "tnb";
|
public const string Area = "tnb";
|
||||||
|
public const string NsPrefix = "Tnb";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
using JNPF;
|
||||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
using JNPF.Common.Core.Manager;
|
||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using JNPF;
|
|
||||||
using JNPF.DependencyInjection;
|
using JNPF.DependencyInjection;
|
||||||
using Mapster;
|
using Microsoft.Extensions.Configuration;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using Tnb.Core;
|
||||||
using Tnb.Vengine.Domain;
|
using Tnb.Vengine.Domain;
|
||||||
|
|
||||||
namespace Tnb.Vengine.DataAccess;
|
namespace Tnb.Vengine.DataAccess;
|
||||||
@@ -18,35 +15,23 @@ namespace Tnb.Vengine.DataAccess;
|
|||||||
public class DataAccess : IDataAccess, ITransient, IDisposable
|
public class DataAccess : IDataAccess, ITransient, IDisposable
|
||||||
{
|
{
|
||||||
const int MAX_PAGE_SIZE = 1000;
|
const int MAX_PAGE_SIZE = 1000;
|
||||||
private ISqlSugarClient? sugar;
|
private ISqlSugarClient? _db;
|
||||||
protected ISqlSugarClient Db
|
protected ISqlSugarClient Db
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (sugar == null)
|
if (_db == null)
|
||||||
{
|
{
|
||||||
ConnectionStringsOptions conn = App.GetConfig<ConnectionStringsOptions>("ConnectionStrings", true);
|
var dbType = App.Configuration.GetConnectionString("DbType");
|
||||||
//var DBType = (DbType)Enum.Parse(typeof(DbType), conn.DBType);
|
var dbConn = App.Configuration.GetConnectionString("DbConn");
|
||||||
sugar = new SqlSugarScope(new ConnectionConfig
|
_db = SugarHelper.CreateSugarClient("_db_default_", dbType, dbConn);
|
||||||
{
|
|
||||||
ConnectionString = conn.ConnectString,
|
|
||||||
DbType = conn.DBType.Adapt<DbType>(),
|
|
||||||
IsAutoCloseConnection = true,
|
|
||||||
ConfigId = conn.ConfigId,
|
|
||||||
InitKeyType = InitKeyType.Attribute,
|
|
||||||
MoreSettings = new ConnMoreSettings()
|
|
||||||
{
|
|
||||||
IsAutoRemoveDataCache = true, // 自动清理缓存
|
|
||||||
IsAutoToUpper = false,
|
|
||||||
PgSqlIsAutoToLower = false,
|
|
||||||
DisableNvarchar = true
|
|
||||||
},
|
|
||||||
}, SugarHelper.ConfigSugar);
|
|
||||||
}
|
}
|
||||||
return sugar;
|
return _db;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly IUserManager _user;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 全局缓存
|
/// 全局缓存
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -55,8 +40,9 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造
|
/// 构造
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DataAccess()
|
public DataAccess(IUserManager currentUser)
|
||||||
{
|
{
|
||||||
|
_user = currentUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -85,27 +71,9 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
return DbCache[dbCode];
|
return DbCache[dbCode];
|
||||||
}
|
}
|
||||||
|
|
||||||
var dblink = GetVmLink(dbCode);
|
var dblink = GetVmodelLink(dbCode);
|
||||||
if (dblink == null)
|
ThrowIf.IsNull(dblink, $"没有此数据库{dbCode}连接信息");
|
||||||
{
|
var sugar = SugarHelper.CreateSugarClient(dblink.dbCode, dblink.dbType, dblink.dbConnection);
|
||||||
throw new Exception($"没有此数据库{dbCode}连接信息");
|
|
||||||
}
|
|
||||||
var dbType = Enum.Parse<DbType>(dblink.dbType.ToString(), true);
|
|
||||||
var sugar = new SqlSugarScope(new ConnectionConfig
|
|
||||||
{
|
|
||||||
ConnectionString = dblink.dbConnection,
|
|
||||||
DbType = dbType,
|
|
||||||
IsAutoCloseConnection = true,
|
|
||||||
ConfigId = dblink.dbCode,
|
|
||||||
InitKeyType = InitKeyType.Attribute,
|
|
||||||
MoreSettings = new ConnMoreSettings()
|
|
||||||
{
|
|
||||||
IsAutoRemoveDataCache = true, // 自动清理缓存
|
|
||||||
IsAutoToUpper = false,
|
|
||||||
PgSqlIsAutoToLower = false,
|
|
||||||
DisableNvarchar = true
|
|
||||||
},
|
|
||||||
}, SugarHelper.ConfigSugar);
|
|
||||||
if (sugar.Ado.IsValidConnection())
|
if (sugar.Ado.IsValidConnection())
|
||||||
{
|
{
|
||||||
DbCache[dbCode] = sugar;
|
DbCache[dbCode] = sugar;
|
||||||
@@ -121,7 +89,7 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取 DbLink
|
/// 获取 DbLink
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public VmodelLink GetVmLink(string dbCode)
|
public VmodelLink GetVmodelLink(string dbCode)
|
||||||
{
|
{
|
||||||
var model = Db.Queryable<VmodelLink>().First(a => a.dbCode == dbCode);
|
var model = Db.Queryable<VmodelLink>().First(a => a.dbCode == dbCode);
|
||||||
return model;
|
return model;
|
||||||
@@ -146,7 +114,7 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
public async Task<Vmodel> GetVmodelAsync(string id, bool loadNavigate = false)
|
public async Task<Vmodel> GetVmodelAsync(string id, bool loadNavigate = false)
|
||||||
{
|
{
|
||||||
Vmodel vm = await Db.Queryable<Vmodel>().FirstAsync(a => a.id == id && a.deleted == 0);
|
Vmodel vm = await Db.Queryable<Vmodel>().FirstAsync(a => a.id == id && a.deleted == 0);
|
||||||
ArgumentNullException.ThrowIfNull(vm, $"找不到vmid={id}的模型");
|
ThrowIf.IsNull(vm, $"找不到id={id}的模型");
|
||||||
if (loadNavigate)
|
if (loadNavigate)
|
||||||
{
|
{
|
||||||
await LoadVmodelNavigateAsync(vm);
|
await LoadVmodelNavigateAsync(vm);
|
||||||
@@ -157,9 +125,9 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取 Vmodel, 为空时不抛异常
|
/// 获取 Vmodel, 为空时不抛异常
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<Vmodel?> TryGetVmodelAsync(string area, string vmCode, bool loadNavigate = false)
|
public async Task<Vmodel?> TryGetVmodelAsync(string areaCode, string vmCode, bool loadNavigate = false)
|
||||||
{
|
{
|
||||||
Vmodel vm = await Db.Queryable<Vmodel>().FirstAsync(a => a.area == area && a.vmCode == vmCode && a.deleted == 0);
|
Vmodel vm = await Db.Queryable<Vmodel>().FirstAsync(a => a.areaCode == areaCode && a.vmCode == vmCode && a.deleted == 0);
|
||||||
if (vm != null && loadNavigate)
|
if (vm != null && loadNavigate)
|
||||||
{
|
{
|
||||||
await LoadVmodelNavigateAsync(vm);
|
await LoadVmodelNavigateAsync(vm);
|
||||||
@@ -171,10 +139,10 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取 Vmodel, 为空时抛异常
|
/// 获取 Vmodel, 为空时抛异常
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<Vmodel> GetVmodelAsync(string area, string vmCode, bool loadNavigate = false)
|
public async Task<Vmodel> GetVmodelAsync(string areaCode, string vmCode, bool loadNavigate = false)
|
||||||
{
|
{
|
||||||
Vmodel vm = await Db.Queryable<Vmodel>().FirstAsync(a => a.area == area && a.vmCode == vmCode && a.deleted == 0);
|
Vmodel vm = await Db.Queryable<Vmodel>().FirstAsync(a => a.areaCode == areaCode && a.vmCode == vmCode && a.deleted == 0);
|
||||||
ArgumentNullException.ThrowIfNull(vm, $"找不到area={area}, vmCode={vmCode}的模型");
|
ThrowIf.IsNull(vm, $"找不到areaCode={areaCode}, vmCode={vmCode}的模型");
|
||||||
if (loadNavigate)
|
if (loadNavigate)
|
||||||
{
|
{
|
||||||
await LoadVmodelNavigateAsync(vm);
|
await LoadVmodelNavigateAsync(vm);
|
||||||
@@ -222,6 +190,9 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
//处理导航属性联表
|
//处理导航属性联表
|
||||||
List<JoinInfoParameter> joins = vm.GetJoinInfos(selProps);
|
List<JoinInfoParameter> joins = vm.GetJoinInfos(selProps);
|
||||||
query.AddJoinInfo(joins);
|
query.AddJoinInfo(joins);
|
||||||
|
//if (joins.Count > 0)
|
||||||
|
//{
|
||||||
|
//}
|
||||||
List<IConditionalModel> wheres = vm.GetConditionalModels(input.q);
|
List<IConditionalModel> wheres = vm.GetConditionalModels(input.q);
|
||||||
if (!string.IsNullOrEmpty(input.k))
|
if (!string.IsNullOrEmpty(input.k))
|
||||||
{
|
{
|
||||||
@@ -229,13 +200,16 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
var wType = WhereType.And;
|
var wType = WhereType.And;
|
||||||
foreach (var prop in vm.dbProps.Where(a => a.fuzzy))
|
foreach (var prop in vm.dbProps.Where(a => a.fuzzy))
|
||||||
{
|
{
|
||||||
lsCondition.Add(new(wType, new ConditionalModel() { FieldName = prop.field, ConditionalType = ConditionalType.Like, FieldValue = input.k }));
|
lsCondition.Add(new(wType, new ConditionalModel() { FieldName = prop.field, ConditionalType = ConditionalType.Like, FieldValue = input.k, CSharpTypeName = prop.csType }));
|
||||||
wType = WhereType.Or;
|
wType = WhereType.Or;
|
||||||
}
|
}
|
||||||
wheres.Add(new ConditionalCollections() { ConditionalList = lsCondition });
|
wheres.Add(new ConditionalCollections() { ConditionalList = lsCondition });
|
||||||
}
|
}
|
||||||
//处理查询参数
|
//处理查询参数
|
||||||
query.Where(wheres);
|
query.Where(wheres);
|
||||||
|
//if (wheres.Count > 0)
|
||||||
|
//{
|
||||||
|
//}
|
||||||
if (!string.IsNullOrEmpty(input.sort))
|
if (!string.IsNullOrEmpty(input.sort))
|
||||||
{
|
{
|
||||||
query.OrderBy(input.sort);
|
query.OrderBy(input.sort);
|
||||||
@@ -253,7 +227,7 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
//组装输出对象
|
//组装输出对象
|
||||||
foreach (var data in ls)
|
foreach (var data in ls)
|
||||||
{
|
{
|
||||||
DObject ret = await NestedOutputAsync(vm, data, selProps);
|
DObject ret = await NestedOutputAsync(vm, new DObject(data), selProps);
|
||||||
result.items.Add(ret);
|
result.items.Add(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +241,7 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
/// <param name="src"></param>
|
/// <param name="src"></param>
|
||||||
/// <param name="selProps"></param>
|
/// <param name="selProps"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private async Task<DObject> NestedOutputAsync(Vmodel vm, Dictionary<string, object> src, List<VmSelectProp> selProps)
|
private async Task<DObject> NestedOutputAsync(Vmodel vm, DObject src, List<VmSelectProp> selProps)
|
||||||
{
|
{
|
||||||
DObject ret = new();
|
DObject ret = new();
|
||||||
foreach (var prop in selProps)
|
foreach (var prop in selProps)
|
||||||
@@ -330,31 +304,61 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
public async Task<dynamic> CreateDataAsync(Vmodel vm, VmCreateInput input)
|
public async Task<dynamic> CreateDataAsync(Vmodel vm, VmCreateInput input)
|
||||||
{
|
{
|
||||||
ISqlSugarClient db = GetSqlSugar(vm.dbCode);
|
ISqlSugarClient db = GetSqlSugar(vm.dbCode);
|
||||||
int num = 0;
|
ThrowIf.When(input.data == null && input.items == null, "新增数据时,data和items不可同时为空");
|
||||||
|
//新增一条数据
|
||||||
if (input.data != null)
|
if (input.data != null)
|
||||||
{
|
{
|
||||||
var model = vm.PropToField(input.data);
|
var pkey = vm.GetPrimary();
|
||||||
num = await db.Insertable(model).AS(vm.tableName).ExecuteCommandAsync();
|
var model = vm.ToCreateEntity(input.data, _user);
|
||||||
return input.data;
|
if (pkey.csType == "int" || pkey.csType == "long")
|
||||||
}
|
|
||||||
else if (input.items != null)
|
|
||||||
{
|
{
|
||||||
List<DObject> lst = new List<DObject>();
|
var id = await db.Insertable(model).AS(vm.tableName).ExecuteReturnBigIdentityAsync();
|
||||||
foreach (var item in input.items)
|
if ((long)input.data[pkey.code] != id) input.data[pkey.code] = id;
|
||||||
{
|
|
||||||
lst.Add(vm.PropToField(item));
|
|
||||||
}
|
|
||||||
num = await db.Insertable(lst).AS(vm.tableName).ExecuteCommandAsync();
|
|
||||||
return input.items;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
input.data = vm.GetDefaultDObject();
|
await db.Insertable(model).AS(vm.tableName).ExecuteCommandAsync();
|
||||||
var model = vm.PropToField(input.data);
|
}
|
||||||
num = await db.Insertable(model).AS(vm.tableName).ExecuteCommandAsync();
|
|
||||||
return input.data;
|
return input.data;
|
||||||
}
|
}
|
||||||
|
//批量新增数据
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var pkey = vm.GetPrimary();
|
||||||
|
List<DObject> lst = new List<DObject>();
|
||||||
|
foreach (var item in input.items!)
|
||||||
|
{
|
||||||
|
lst.Add(vm.ToCreateEntity(item, _user));
|
||||||
|
}
|
||||||
|
if (pkey.csType == "int")
|
||||||
|
{
|
||||||
|
var ids = await db.Insertable(lst).AS(vm.tableName).ExecuteReturnPkListAsync<int>();
|
||||||
|
for (int i = 0; i < input.items.Count; i++)
|
||||||
|
{
|
||||||
|
input.items[i][pkey.code] = ids[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (pkey.csType == "long")
|
||||||
|
{
|
||||||
|
var ids = await db.Insertable(lst).AS(vm.tableName).ExecuteReturnPkListAsync<long>();
|
||||||
|
for (int i = 0; i < input.items.Count; i++)
|
||||||
|
{
|
||||||
|
input.items[i][pkey.code] = ids[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await db.Insertable(lst).AS(vm.tableName).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
return input.items;
|
||||||
|
}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// input.data = vm.GetDefaultDObject();
|
||||||
|
// var model = vm.PropToField(input.data);
|
||||||
|
// num = await db.Insertable(model).AS(vm.tableName).ExecuteCommandAsync();
|
||||||
|
// return input.data;
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -365,9 +369,10 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
ISqlSugarClient db = GetSqlSugar(vm.dbCode);
|
ISqlSugarClient db = GetSqlSugar(vm.dbCode);
|
||||||
var pk = vm.GetPrimary();
|
var pk = vm.GetPrimary();
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
//修改一条数据
|
||||||
if (input.data != null)
|
if (input.data != null)
|
||||||
{
|
{
|
||||||
var model = vm.PropToField(input.data);
|
var model = vm.ToUpdateEntity(input.data, _user);
|
||||||
if (!model.ContainsKey(pk.field))
|
if (!model.ContainsKey(pk.field))
|
||||||
{
|
{
|
||||||
throw new Exception($"更新数据时主键({pk.code})不可为空");
|
throw new Exception($"更新数据时主键({pk.code})不可为空");
|
||||||
@@ -378,12 +383,13 @@ public class DataAccess : IDataAccess, ITransient, IDisposable
|
|||||||
//}
|
//}
|
||||||
num = await db.Updateable(model).AS(vm.tableName).WhereColumns(pk.field).ExecuteCommandAsync();
|
num = await db.Updateable(model).AS(vm.tableName).WhereColumns(pk.field).ExecuteCommandAsync();
|
||||||
}
|
}
|
||||||
|
//批量修改数据
|
||||||
else if (input.items != null)
|
else if (input.items != null)
|
||||||
{
|
{
|
||||||
List<DObject> lst = new();
|
List<DObject> lst = new();
|
||||||
foreach (var item in input.items)
|
foreach (var item in input.items)
|
||||||
{
|
{
|
||||||
var model = vm.PropToField(item);
|
var model = vm.ToUpdateEntity(item, _user);
|
||||||
if (model.ContainsKey(pk.field))
|
if (model.ContainsKey(pk.field))
|
||||||
{
|
{
|
||||||
lst.Add(model);
|
lst.Add(model);
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
using JNPF.DependencyInjection;
|
||||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
|
||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
using JNPF.DependencyInjection;
|
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Tnb.Vengine.Domain;
|
using Tnb.Vengine.Domain;
|
||||||
|
|
||||||
@@ -26,7 +21,7 @@ public interface IDataAccess : ITransient
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dbCode"></param>
|
/// <param name="dbCode"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
VmodelLink GetVmLink(string dbCode);
|
VmodelLink GetVmodelLink(string dbCode);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取 Vmodel, 为空时不抛异常
|
/// 获取 Vmodel, 为空时不抛异常
|
||||||
|
|||||||
@@ -1,10 +1,41 @@
|
|||||||
using JNPF.Logging;
|
using JNPF.Logging;
|
||||||
|
using Mapster;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using Yitter.IdGenerator;
|
||||||
|
|
||||||
namespace Tnb.Vengine.DataAccess;
|
namespace Tnb.Vengine.DataAccess;
|
||||||
|
|
||||||
public class SugarHelper
|
public class SugarHelper
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 创建SugarClient实例
|
||||||
|
/// </summary>
|
||||||
|
public static ISqlSugarClient CreateSugarClient(string dbCode, string dbType, string dbConnection, Action<ConnectionConfig>? configConnection = null, Action<ISqlSugarClient>? configSugar = null)
|
||||||
|
{
|
||||||
|
var config = new ConnectionConfig
|
||||||
|
{
|
||||||
|
ConnectionString = dbConnection,
|
||||||
|
DbType = dbType.Adapt<DbType>(),
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
ConfigId = dbCode,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
MoreSettings = new ConnMoreSettings()
|
||||||
|
{
|
||||||
|
IsAutoRemoveDataCache = true, // 自动清理缓存
|
||||||
|
IsAutoToUpper = false,
|
||||||
|
PgSqlIsAutoToLower = false,
|
||||||
|
DisableNvarchar = true
|
||||||
|
},
|
||||||
|
};
|
||||||
|
configConnection?.Invoke(config);
|
||||||
|
var sugar = new SqlSugarScope(config, configSugar == null ? ConfigSugar : configSugar);
|
||||||
|
return sugar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// SqlSugar默认配置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="db"></param>
|
||||||
public static void ConfigSugar(ISqlSugarClient db)
|
public static void ConfigSugar(ISqlSugarClient db)
|
||||||
{
|
{
|
||||||
// 设置超时时间
|
// 设置超时时间
|
||||||
@@ -31,4 +62,12 @@ public class SugarHelper
|
|||||||
Log.Error(UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, ex.Sql, (SugarParameter[])ex.Parametres));
|
Log.Error(UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, ex.Sql, (SugarParameter[])ex.Parametres));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CustomSnowId()
|
||||||
|
{
|
||||||
|
StaticConfig.CustomSnowFlakeFunc = () =>
|
||||||
|
{
|
||||||
|
return YitIdHelper.NextId();
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
155
visualdev/Tnb.Vengine/Domain/VengineDto.cs
Normal file
155
visualdev/Tnb.Vengine/Domain/VengineDto.cs
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 宁波拓通e智造平台 ToTong Next Builder //
|
||||||
|
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
using Tnb.Core;
|
||||||
|
|
||||||
|
namespace Tnb.Vengine.Domain;
|
||||||
|
|
||||||
|
public class VmBaseInput
|
||||||
|
{
|
||||||
|
///// <summary>
|
||||||
|
///// 视图模型id
|
||||||
|
///// </summary>
|
||||||
|
//public string vmid { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
public class VmGetInput : VmBaseInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 要获取数据的id
|
||||||
|
/// </summary>
|
||||||
|
public string? id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 过滤条件
|
||||||
|
/// </summary>
|
||||||
|
public string? q { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 输出字段
|
||||||
|
/// </summary>
|
||||||
|
public string o { get; set; } = "*";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class VmGetListInput : 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 string? q { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 输出字段
|
||||||
|
/// </summary>
|
||||||
|
public string o { get; set; } = "*";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取多条数据输入参数
|
||||||
|
/// </summary>
|
||||||
|
public class VmQueryInput : VmGetListInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 查询条件
|
||||||
|
/// </summary>
|
||||||
|
public new DObject? q { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 高级查询
|
||||||
|
/// </summary>
|
||||||
|
public DObject? adv { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增数据输入参数
|
||||||
|
/// </summary>
|
||||||
|
public class VmCreateInput : VmBaseInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 数据
|
||||||
|
/// </summary>
|
||||||
|
public DObject? data { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 批量添加
|
||||||
|
/// </summary>
|
||||||
|
public List<DObject>? items { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改数据输入参数
|
||||||
|
/// </summary>
|
||||||
|
public class VmUpdateInput : VmCreateInput
|
||||||
|
{
|
||||||
|
///// <summary>
|
||||||
|
///// 要更新的数据id
|
||||||
|
///// </summary>
|
||||||
|
//public string? id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 删除数据输入参数
|
||||||
|
/// </summary>
|
||||||
|
public class VmDeleteInput : VmBaseInput
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 要删除的数据id
|
||||||
|
/// </summary>
|
||||||
|
public string? id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 要删除的id列表
|
||||||
|
/// </summary>
|
||||||
|
public List<string>? ids { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分页列表输出对象
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
public class PagedOutput<T>
|
||||||
|
{
|
||||||
|
public int total { get; set; }
|
||||||
|
public List<T> items { get; set; } = new List<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 动态分页列表输出对象
|
||||||
|
/// </summary>
|
||||||
|
public class VmPagedOutput : PagedOutput<dynamic>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询属性信息
|
||||||
|
/// </summary>
|
||||||
|
public class VmSelectProp
|
||||||
|
{
|
||||||
|
public const string MAIN_ALIES = "m";
|
||||||
|
public string code { get; set; } = string.Empty;
|
||||||
|
public string field { get; set; } = string.Empty;
|
||||||
|
public string navCode { get; set; } = MAIN_ALIES;
|
||||||
|
public ePropType propType { get; set; }
|
||||||
|
public eNavigateType navType { get; set; }
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
using JNPF.Common.Extension;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Yitter.IdGenerator;
|
using Yitter.IdGenerator;
|
||||||
|
|
||||||
namespace Tnb.Vengine.Domain;
|
namespace Tnb.Vengine.Domain;
|
||||||
@@ -21,6 +23,7 @@ public class VmDbProp : VmBaseProp
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 数据类型
|
/// 数据类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
public string dataType { get; set; } = "varchar";
|
public string dataType { get; set; } = "varchar";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -76,18 +79,8 @@ public class VmDbProp : VmBaseProp
|
|||||||
public object? GetDefaultValue()
|
public object? GetDefaultValue()
|
||||||
{
|
{
|
||||||
object? val = null;
|
object? val = null;
|
||||||
|
if(!required) { return val; }
|
||||||
if (string.IsNullOrEmpty(defValue))
|
if (string.IsNullOrEmpty(defValue))
|
||||||
{
|
|
||||||
val = defValue switch
|
|
||||||
{
|
|
||||||
"@@snowid" => YitIdHelper.NextId().ToString(),
|
|
||||||
"@@now" => DateTime.Now,
|
|
||||||
"@@userid" => YitIdHelper.NextId().ToString(),
|
|
||||||
"@@orgid" => YitIdHelper.NextId().ToString(),
|
|
||||||
_ => null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
val = csType switch
|
val = csType switch
|
||||||
{
|
{
|
||||||
@@ -98,9 +91,49 @@ public class VmDbProp : VmBaseProp
|
|||||||
_ => null
|
_ => null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
val = defValue switch
|
||||||
|
{
|
||||||
|
"@@snowid" => YitIdHelper.NextId().ToString(),
|
||||||
|
"@@now" => DateTime.Now,
|
||||||
|
"@@userid" => YitIdHelper.NextId().ToString(),
|
||||||
|
"@@orgid" => YitIdHelper.NextId().ToString(),
|
||||||
|
_ => null
|
||||||
|
};
|
||||||
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取默认值文本
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public object? GetDefaultValueString()
|
||||||
|
{
|
||||||
|
string val = "";
|
||||||
|
if (!required) return val;
|
||||||
|
if (!string.IsNullOrWhiteSpace(defValue))
|
||||||
|
{
|
||||||
|
val = defValue switch
|
||||||
|
{
|
||||||
|
"@@snowid" => "YitIdHelper.NextId().ToString()",
|
||||||
|
"@@now" => "DateTime.Now",
|
||||||
|
_ => defValue
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(val))
|
||||||
|
{
|
||||||
|
val = csType switch
|
||||||
|
{
|
||||||
|
"string" => "string.Empty;",
|
||||||
|
"DateTime" => "DateTime.Now;",
|
||||||
|
_ => ""
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return string.IsNullOrEmpty(val) ? "" : " = " + val;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取默认宽度
|
/// 获取默认宽度
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -146,4 +179,32 @@ public class VmDbProp : VmBaseProp
|
|||||||
};
|
};
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取SqlSugar特性文本
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public string GetAttributeString()
|
||||||
|
{
|
||||||
|
var attr = "";
|
||||||
|
var sb = new List<string>();
|
||||||
|
if (!string.IsNullOrEmpty(field) && code != field) sb.Add($"ColumnName = \"{field}\"");
|
||||||
|
if (pkey) sb.Add("IsPrimaryKey = true");
|
||||||
|
//sb.Add("IsIdentity = true");
|
||||||
|
if (required && !pkey) sb.Add("IsNullable = false");
|
||||||
|
if (csType == "string" && length > 0)
|
||||||
|
{
|
||||||
|
sb.Add($"Length = {CodeHelper.LengthToString(length)}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (csType == "decimal")
|
||||||
|
{
|
||||||
|
if (length > 0) sb.Add($"Length = {length}");
|
||||||
|
if (digit > 0) sb.Add($"DecimalDigits = {digit}");
|
||||||
|
}
|
||||||
|
//if(isJson) sb.Add("IsJson = true")
|
||||||
|
if (sb.Any()) attr += $"\t[SugarColumn({sb.JoinAsString(", ")})]{Environment.NewLine}";
|
||||||
|
return attr;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
|
||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
namespace Tnb.Vengine.Domain;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 字典对象
|
|
||||||
/// </summary>
|
|
||||||
public class DObject : Dictionary<string, object>
|
|
||||||
{
|
|
||||||
public DObject() { }
|
|
||||||
public DObject(string key, object value)
|
|
||||||
{
|
|
||||||
Add(key, value);
|
|
||||||
}
|
|
||||||
public DObject(Dictionary<string, object> dictionary) : base(dictionary)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
public void AddCascade(string code, object value)
|
|
||||||
{
|
|
||||||
var keys = code.Split('.');
|
|
||||||
if (keys.Length == 1)
|
|
||||||
{
|
|
||||||
Add(code, value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < keys.Length; i++)
|
|
||||||
{
|
|
||||||
DObject temp = this;
|
|
||||||
if (i < keys.Length - 1)
|
|
||||||
{
|
|
||||||
if (!ContainsKey(keys[i]))
|
|
||||||
{
|
|
||||||
temp = new DObject();
|
|
||||||
Add(keys[i], temp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
temp = (DObject)temp[keys[i]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
temp.Add(keys[i], value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class VmBaseInput
|
|
||||||
{
|
|
||||||
///// <summary>
|
|
||||||
///// 视图模型id
|
|
||||||
///// </summary>
|
|
||||||
//public string vmid { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
public class VmGetInput : VmBaseInput
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 要获取数据的id
|
|
||||||
/// </summary>
|
|
||||||
public string? id { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 过滤条件
|
|
||||||
/// </summary>
|
|
||||||
public string? q { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 输出字段
|
|
||||||
/// </summary>
|
|
||||||
public string o { get; set; } = "*";
|
|
||||||
}
|
|
||||||
|
|
||||||
public class VmGetListInput : 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 string? q { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 输出字段
|
|
||||||
/// </summary>
|
|
||||||
public string o { get; set; } = "*";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取多条数据输入参数
|
|
||||||
/// </summary>
|
|
||||||
public class VmQueryInput : VmGetListInput
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 查询条件
|
|
||||||
/// </summary>
|
|
||||||
public new DObject? q { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 高级查询
|
|
||||||
/// </summary>
|
|
||||||
public DObject? adv { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 新增数据输入参数
|
|
||||||
/// </summary>
|
|
||||||
public class VmCreateInput : VmBaseInput
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 数据
|
|
||||||
/// </summary>
|
|
||||||
public DObject? data { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 批量添加
|
|
||||||
/// </summary>
|
|
||||||
public List<DObject>? items { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 修改数据输入参数
|
|
||||||
/// </summary>
|
|
||||||
public class VmUpdateInput : VmCreateInput
|
|
||||||
{
|
|
||||||
///// <summary>
|
|
||||||
///// 要更新的数据id
|
|
||||||
///// </summary>
|
|
||||||
//public string? id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 删除数据输入参数
|
|
||||||
/// </summary>
|
|
||||||
public class VmDeleteInput : VmBaseInput
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 要删除的数据id
|
|
||||||
/// </summary>
|
|
||||||
public string? id { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 要删除的id列表
|
|
||||||
/// </summary>
|
|
||||||
public List<string>? ids { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 分页列表输出对象
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T"></typeparam>
|
|
||||||
public class PagedOutput<T>
|
|
||||||
{
|
|
||||||
public int total { get; set; }
|
|
||||||
public List<T> items { get; set; } = new List<T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 动态分页列表输出对象
|
|
||||||
/// </summary>
|
|
||||||
public class VmPagedOutput : PagedOutput<dynamic>
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查询属性信息
|
|
||||||
/// </summary>
|
|
||||||
public class VmSelectProp
|
|
||||||
{
|
|
||||||
public const string MAIN_ALIES = "m";
|
|
||||||
public string code { get; set; } = string.Empty;
|
|
||||||
public string field { get; set; } = string.Empty;
|
|
||||||
public string navCode { get; set; } = MAIN_ALIES;
|
|
||||||
public ePropType propType { get; set; }
|
|
||||||
public eNavigateType navType { get; set; }
|
|
||||||
}
|
|
||||||
@@ -12,6 +12,8 @@ namespace Tnb.Vengine.Domain;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class VmNavProp : VmBaseProp
|
public class VmNavProp : VmBaseProp
|
||||||
{
|
{
|
||||||
|
#region Properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 导航属性模型id
|
/// 导航属性模型id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -51,4 +53,6 @@ public class VmNavProp : VmBaseProp
|
|||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Vmodel? naviModel { get; set; }
|
public Vmodel? naviModel { get; set; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,16 @@
|
|||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
// https://git.tuotong-tech.com/tnb/tnb.server //
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
using JNPF.Common.Core.Manager;
|
||||||
|
using JNPF.Common.Extension;
|
||||||
|
using Mapster;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using SqlSugar;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Mapster;
|
using Tnb.Core;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using SqlSugar;
|
|
||||||
using Yitter.IdGenerator;
|
using Yitter.IdGenerator;
|
||||||
|
|
||||||
namespace Tnb.Vengine.Domain;
|
namespace Tnb.Vengine.Domain;
|
||||||
@@ -30,8 +33,8 @@ public partial class Vmodel : Entity
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模块代码
|
/// 模块代码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnName = "area", Length = DbConsts.LengthS)]
|
[SugarColumn(ColumnName = "area_code", Length = DbConsts.LengthS)]
|
||||||
public string area { get; set; } = "edp";
|
public string areaCode { get; set; } = "edp";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 视图代码
|
/// 视图代码
|
||||||
@@ -129,6 +132,9 @@ public partial class Vmodel : Entity
|
|||||||
[SugarColumn(ColumnName = "modify_id", Length = DbConsts.LengthS)]
|
[SugarColumn(ColumnName = "modify_id", Length = DbConsts.LengthS)]
|
||||||
public string? modifyId { get; set; }
|
public string? modifyId { get; set; }
|
||||||
|
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
|
public string fullCode { get { return areaCode + "/" + vmCode; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 主键
|
/// 主键
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -355,23 +361,23 @@ public partial class Vmodel : Entity
|
|||||||
switch (op)
|
switch (op)
|
||||||
{
|
{
|
||||||
case "><":
|
case "><":
|
||||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThan });
|
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThan, CSharpTypeName = prop.csType });
|
||||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThan });
|
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThan, CSharpTypeName = prop.csType });
|
||||||
break;
|
break;
|
||||||
case ">=<":
|
case ">=<":
|
||||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThanOrEqual });
|
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThanOrEqual, CSharpTypeName = prop.csType });
|
||||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThan });
|
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThan, CSharpTypeName = prop.csType });
|
||||||
break;
|
break;
|
||||||
case "><=":
|
case "><=":
|
||||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThan });
|
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThan, CSharpTypeName = prop.csType });
|
||||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThanOrEqual });
|
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThanOrEqual, CSharpTypeName = prop.csType });
|
||||||
break;
|
break;
|
||||||
case ">=<=":
|
case ">=<=":
|
||||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThanOrEqual });
|
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThanOrEqual, CSharpTypeName = prop.csType });
|
||||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThanOrEqual });
|
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThanOrEqual, CSharpTypeName = prop.csType });
|
||||||
break;
|
break;
|
||||||
case "in":
|
case "in":
|
||||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val.Skip(1).ToString(), ConditionalType = ConditionalType.In });
|
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = val.Skip(1).ToString(), ConditionalType = ConditionalType.In, CSharpTypeName = prop.csType });
|
||||||
break;
|
break;
|
||||||
default: op = string.Empty; break;
|
default: op = string.Empty; break;
|
||||||
}
|
}
|
||||||
@@ -404,7 +410,7 @@ public partial class Vmodel : Entity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = value, ConditionalType = conditionalType });
|
wheres.Add(new ConditionalModel { FieldName = prop.field, FieldValue = value, ConditionalType = conditionalType, CSharpTypeName = prop.csType });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return wheres;
|
return wheres;
|
||||||
@@ -438,6 +444,65 @@ public partial class Vmodel : Entity
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 转换为待新增的实体对象
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public DObject ToCreateEntity(DObject input, IUserManager user)
|
||||||
|
{
|
||||||
|
DObject obj = new();
|
||||||
|
foreach (var p in dbProps)
|
||||||
|
{
|
||||||
|
if (input.ContainsKey(p.code))
|
||||||
|
{
|
||||||
|
obj.Add(p.field, input[p.code]);
|
||||||
|
}
|
||||||
|
//当提交的数据与内置规则有重复时,采用内置规则,如果要优先采用提交的数据,这里要使用else if
|
||||||
|
if ((p.pkey && p.code == "id") || p.defValue == "@snowid")
|
||||||
|
{
|
||||||
|
obj[p.field] = YitIdHelper.NextId().ToString();
|
||||||
|
}
|
||||||
|
else if (p.csType == "DateTime" && (p.code == "createTime" || p.defValue == "@createTime"))
|
||||||
|
{
|
||||||
|
obj[p.field] = DateTime.Now;
|
||||||
|
}
|
||||||
|
else if (p.csType == "string" && (p.code == "createId" || p.defValue == "@createId"))
|
||||||
|
{
|
||||||
|
obj[p.field] = user.UserId;
|
||||||
|
}
|
||||||
|
else if (obj.GetOrDefault(p.field) == null && (p.required || !string.IsNullOrEmpty(p.defValue)))
|
||||||
|
{
|
||||||
|
obj[p.field] = p.GetDefaultValue()!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 转换为待修改的实体对象
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public DObject ToUpdateEntity(DObject input, IUserManager user)
|
||||||
|
{
|
||||||
|
DObject obj = new();
|
||||||
|
foreach (var p in dbProps)
|
||||||
|
{
|
||||||
|
if (input.ContainsKey(p.code))
|
||||||
|
{
|
||||||
|
obj.Add(p.field, input[p.code]);
|
||||||
|
}
|
||||||
|
//当提交的数据与内置规则有重复时,采用内置规则,如果要优先采用提交的数据,这里要使用else if
|
||||||
|
if (p.csType == "DateTime" && (p.code == "updateTime" || p.code == "modifyTime" || p.defValue == "@updateTime"))
|
||||||
|
{
|
||||||
|
obj[p.field] = DateTime.Now;
|
||||||
|
}
|
||||||
|
else if (p.csType == "string" && (p.code == "updateId" || p.code == "modifyId" || p.defValue == "@updateId"))
|
||||||
|
{
|
||||||
|
obj[p.field] = user.UserId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
|
||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
namespace Tnb.Vengine.Domain;
|
|
||||||
|
|
||||||
public class VmodelCreateFromTableInput
|
|
||||||
{
|
|
||||||
public string? dbCode { get; set; }
|
|
||||||
|
|
||||||
public string tableName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public string? removePrefix { get; set; }
|
|
||||||
public string area { get; set; } = "edp";
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CreatePageFromVmodelInput
|
|
||||||
{
|
|
||||||
public Guid? viewId { get; set; }
|
|
||||||
public string? vmid { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class VmodelGetInput
|
|
||||||
{
|
|
||||||
public long? id { get; set; }
|
|
||||||
public string? moduleCode { get; set; }
|
|
||||||
public string? vmCode { get; set; }
|
|
||||||
public string? dbCode { get; set; }
|
|
||||||
public string? tableName { get; set; }
|
|
||||||
public bool drill { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using Tnb.Core;
|
||||||
using Yitter.IdGenerator;
|
using Yitter.IdGenerator;
|
||||||
|
|
||||||
namespace Tnb.Vengine.Domain;
|
namespace Tnb.Vengine.Domain;
|
||||||
@@ -22,14 +23,14 @@ public partial class VmodelLink : Entity
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 数据库连接
|
/// 数据库连接
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnName = "db_code", Length = DbConsts.LengthS)]
|
[SugarColumn(ColumnName = "db_code", IsNullable = false, Length = DbConsts.LengthS)]
|
||||||
public string? dbCode { get; set; }
|
public string dbCode { get; set; } = "PostgreSQL";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 数据库类型
|
/// 数据库类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnName = "db_type", IsNullable = false)]
|
[SugarColumn(ColumnName = "db_type", IsNullable = false, Length = DbConsts.LengthS)]
|
||||||
public eDbType dbType { get; set; }
|
public string dbType { get; set; } = "PostgreSQL";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 连接串
|
/// 连接串
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using Tnb.Core;
|
||||||
using Yitter.IdGenerator;
|
using Yitter.IdGenerator;
|
||||||
|
|
||||||
namespace Tnb.Vengine.Domain;
|
namespace Tnb.Vengine.Domain;
|
||||||
@@ -102,6 +103,5 @@ public partial class VmodelPage : Entity
|
|||||||
return new object[] { id };
|
return new object[] { id };
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,577 +0,0 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 宁波拓通e智造平台 ToTong Next Builder //
|
|
||||||
// https://git.tuotong-tech.com/tnb/tnb.server //
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using JNPF.Common.Extension;
|
|
||||||
using JNPF.DependencyInjection;
|
|
||||||
|
|
||||||
namespace System;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 字符串扩展类,来自Abp
|
|
||||||
/// </summary>
|
|
||||||
[SuppressSniffer]
|
|
||||||
public static class StringExtensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Adds a char to end of given string if it does not ends with the char.
|
|
||||||
/// </summary>
|
|
||||||
public static string EnsureEndsWith(this string str, char c, StringComparison comparisonType = StringComparison.Ordinal)
|
|
||||||
{
|
|
||||||
ThrowIf.IsNull(str, nameof(str));
|
|
||||||
|
|
||||||
if (str.EndsWith(c.ToString(), comparisonType))
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str + c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds a char to beginning of given string if it does not starts with the char.
|
|
||||||
/// </summary>
|
|
||||||
public static string EnsureStartsWith(this string str, char c, StringComparison comparisonType = StringComparison.Ordinal)
|
|
||||||
{
|
|
||||||
ThrowIf.IsNull(str, nameof(str));
|
|
||||||
|
|
||||||
if (str.StartsWith(c.ToString(), comparisonType))
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
return c + str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Indicates whether this string is null or an System.String.Empty string.
|
|
||||||
/// </summary>
|
|
||||||
public static bool IsNullOrEmpty(this string str)
|
|
||||||
{
|
|
||||||
return string.IsNullOrEmpty(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// indicates whether this string is null, empty, or consists only of white-space characters.
|
|
||||||
/// </summary>
|
|
||||||
public static bool IsNullOrWhiteSpace(this string str)
|
|
||||||
{
|
|
||||||
return string.IsNullOrWhiteSpace(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a substring of a string from beginning of the string.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
|
|
||||||
/// <exception cref="ArgumentException">Thrown if <paramref name="len"/> is bigger that string's length</exception>
|
|
||||||
public static string Left(this string str, int len)
|
|
||||||
{
|
|
||||||
ThrowIf.IsNull(str, nameof(str));
|
|
||||||
|
|
||||||
if (str.Length < len)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("len argument can not be bigger than given string's length!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.Substring(0, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts line endings in the string to <see cref="Environment.NewLine"/>.
|
|
||||||
/// </summary>
|
|
||||||
public static string NormalizeLineEndings(this string str)
|
|
||||||
{
|
|
||||||
return str.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", Environment.NewLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets index of nth occurrence of a char in a string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">source string to be searched</param>
|
|
||||||
/// <param name="c">Char to search in <paramref name="str"/></param>
|
|
||||||
/// <param name="n">Count of the occurrence</param>
|
|
||||||
public static int NthIndexOf(this string str, char c, int n)
|
|
||||||
{
|
|
||||||
ThrowIf.IsNull(str, nameof(str));
|
|
||||||
|
|
||||||
var count = 0;
|
|
||||||
for (var i = 0; i < str.Length; i++)
|
|
||||||
{
|
|
||||||
if (str[i] != c)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((++count) == n)
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Removes first occurrence of the given postfixes from end of the given string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">The string.</param>
|
|
||||||
/// <param name="postFixes">one or more postfix.</param>
|
|
||||||
/// <returns>Modified string or the same string if it has not any of given postfixes</returns>
|
|
||||||
public static string RemovePostFix(this string str, params string[] postFixes)
|
|
||||||
{
|
|
||||||
return str.RemovePostFix(StringComparison.Ordinal, postFixes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Removes first occurrence of the given postfixes from end of the given string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">The string.</param>
|
|
||||||
/// <param name="comparisonType">String comparison type</param>
|
|
||||||
/// <param name="postFixes">one or more postfix.</param>
|
|
||||||
/// <returns>Modified string or the same string if it has not any of given postfixes</returns>
|
|
||||||
public static string RemovePostFix(this string str, StringComparison comparisonType, params string[] postFixes)
|
|
||||||
{
|
|
||||||
if (str.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (postFixes.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var postFix in postFixes)
|
|
||||||
{
|
|
||||||
if (str.EndsWith(postFix, comparisonType))
|
|
||||||
{
|
|
||||||
return str.Left(str.Length - postFix.Length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Removes first occurrence of the given prefixes from beginning of the given string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">The string.</param>
|
|
||||||
/// <param name="preFixes">one or more prefix.</param>
|
|
||||||
/// <returns>Modified string or the same string if it has not any of given prefixes</returns>
|
|
||||||
public static string RemovePreFix(this string str, params string[] preFixes)
|
|
||||||
{
|
|
||||||
return str.RemovePreFix(StringComparison.Ordinal, preFixes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Removes first occurrence of the given prefixes from beginning of the given string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">The string.</param>
|
|
||||||
/// <param name="comparisonType">String comparison type</param>
|
|
||||||
/// <param name="preFixes">one or more prefix.</param>
|
|
||||||
/// <returns>Modified string or the same string if it has not any of given prefixes</returns>
|
|
||||||
public static string RemovePreFix(this string str, StringComparison comparisonType, params string[] preFixes)
|
|
||||||
{
|
|
||||||
if (str.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preFixes.IsNullOrEmpty())
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var preFix in preFixes)
|
|
||||||
{
|
|
||||||
if (str.StartsWith(preFix, comparisonType))
|
|
||||||
{
|
|
||||||
return str.Right(str.Length - preFix.Length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string ReplaceFirst(this string str, string search, string replace, StringComparison comparisonType = StringComparison.Ordinal)
|
|
||||||
{
|
|
||||||
|
|
||||||
var pos = str.IndexOf(search, comparisonType);
|
|
||||||
if (pos < 0)
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.Substring(0, pos) + replace + str.Substring(pos + search.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a substring of a string from end of the string.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
|
|
||||||
/// <exception cref="ArgumentException">Thrown if <paramref name="len"/> is bigger that string's length</exception>
|
|
||||||
public static string Right(this string str, int len)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (str.Length < len)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("len argument can not be bigger than given string's length!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.Substring(str.Length - len, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Uses string.Split method to split given string by given separator.
|
|
||||||
/// </summary>
|
|
||||||
public static string[] Split(this string str, string separator)
|
|
||||||
{
|
|
||||||
return str.Split(new[] { separator }, StringSplitOptions.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Uses string.Split method to split given string by given separator.
|
|
||||||
/// </summary>
|
|
||||||
public static string[] Split(this string str, string separator, StringSplitOptions options)
|
|
||||||
{
|
|
||||||
return str.Split(new[] { separator }, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Uses string.Split method to split given string by <see cref="Environment.NewLine"/>.
|
|
||||||
/// </summary>
|
|
||||||
public static string[] SplitToLines(this string str)
|
|
||||||
{
|
|
||||||
return str.Split(Environment.NewLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Uses string.Split method to split given string by <see cref="Environment.NewLine"/>.
|
|
||||||
/// </summary>
|
|
||||||
public static string[] SplitToLines(this string str, StringSplitOptions options)
|
|
||||||
{
|
|
||||||
return str.Split(Environment.NewLine, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts PascalCase string to camelCase string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">String to convert</param>
|
|
||||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
|
||||||
/// <param name="handleAbbreviations">set true to if you want to convert 'XYZ' to 'xyz'.</param>
|
|
||||||
/// <returns>camelCase of the string</returns>
|
|
||||||
public static string ToCamelCase(this string str, bool useCurrentCulture = false, bool handleAbbreviations = false)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(str))
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str.Length == 1)
|
|
||||||
{
|
|
||||||
return useCurrentCulture ? str.ToLower() : str.ToLowerInvariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (handleAbbreviations && IsAllUpperCase(str))
|
|
||||||
{
|
|
||||||
return useCurrentCulture ? str.ToLower() : str.ToLowerInvariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (useCurrentCulture ? char.ToLower(str[0]) : char.ToLowerInvariant(str[0])) + str.Substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts given PascalCase/camelCase string to sentence (by splitting words by space).
|
|
||||||
/// Example: "ThisIsSampleSentence" is converted to "This is a sample sentence".
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">String to convert.</param>
|
|
||||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
|
||||||
public static string ToSentenceCase(this string str, bool useCurrentCulture = false)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(str))
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
return useCurrentCulture
|
|
||||||
? Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLower(m.Value[1]))
|
|
||||||
: Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLowerInvariant(m.Value[1]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts given PascalCase/camelCase string to kebab-case.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">String to convert.</param>
|
|
||||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
|
||||||
public static string ToKebabCase(this string str, bool useCurrentCulture = false)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(str))
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
str = str.ToCamelCase();
|
|
||||||
|
|
||||||
return useCurrentCulture
|
|
||||||
? Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + "-" + char.ToLower(m.Value[1]))
|
|
||||||
: Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + "-" + char.ToLowerInvariant(m.Value[1]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts given PascalCase/camelCase string to snake case.
|
|
||||||
/// Example: "ThisIsSampleSentence" is converted to "this_is_a_sample_sentence".
|
|
||||||
/// https://github.com/npgsql/npgsql/blob/dev/src/Npgsql/NameTranslation/NpgsqlSnakeCaseNameTranslator.cs#L51
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">String to convert.</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static string ToSnakeCase(this string str)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(str))
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
var builder = new StringBuilder(str.Length + Math.Min(2, str.Length / 5));
|
|
||||||
var previousCategory = default(UnicodeCategory?);
|
|
||||||
|
|
||||||
for (var currentIndex = 0; currentIndex < str.Length; currentIndex++)
|
|
||||||
{
|
|
||||||
var currentChar = str[currentIndex];
|
|
||||||
if (currentChar == '_')
|
|
||||||
{
|
|
||||||
builder.Append('_');
|
|
||||||
previousCategory = null;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var currentCategory = char.GetUnicodeCategory(currentChar);
|
|
||||||
switch (currentCategory)
|
|
||||||
{
|
|
||||||
case UnicodeCategory.UppercaseLetter:
|
|
||||||
case UnicodeCategory.TitlecaseLetter:
|
|
||||||
if (previousCategory == UnicodeCategory.SpaceSeparator ||
|
|
||||||
previousCategory == UnicodeCategory.LowercaseLetter ||
|
|
||||||
previousCategory != UnicodeCategory.DecimalDigitNumber &&
|
|
||||||
previousCategory != null &&
|
|
||||||
currentIndex > 0 &&
|
|
||||||
currentIndex + 1 < str.Length &&
|
|
||||||
char.IsLower(str[currentIndex + 1]))
|
|
||||||
{
|
|
||||||
builder.Append('_');
|
|
||||||
}
|
|
||||||
|
|
||||||
currentChar = char.ToLower(currentChar);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case UnicodeCategory.LowercaseLetter:
|
|
||||||
case UnicodeCategory.DecimalDigitNumber:
|
|
||||||
if (previousCategory == UnicodeCategory.SpaceSeparator)
|
|
||||||
{
|
|
||||||
builder.Append('_');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
if (previousCategory != null)
|
|
||||||
{
|
|
||||||
previousCategory = UnicodeCategory.SpaceSeparator;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.Append(currentChar);
|
|
||||||
previousCategory = currentCategory;
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts string to enum value.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">Type of enum</typeparam>
|
|
||||||
/// <param name="value">String value to convert</param>
|
|
||||||
/// <returns>Returns enum object</returns>
|
|
||||||
public static T ToEnum<T>(this string value)
|
|
||||||
where T : struct
|
|
||||||
{
|
|
||||||
ThrowIf.IsNull(value, nameof(value));
|
|
||||||
return (T)Enum.Parse(typeof(T), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts string to enum value.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">Type of enum</typeparam>
|
|
||||||
/// <param name="value">String value to convert</param>
|
|
||||||
/// <param name="ignoreCase">Ignore case</param>
|
|
||||||
/// <returns>Returns enum object</returns>
|
|
||||||
public static T ToEnum<T>(this string value, bool ignoreCase)
|
|
||||||
where T : struct
|
|
||||||
{
|
|
||||||
ThrowIf.IsNull(value, nameof(value));
|
|
||||||
return (T)Enum.Parse(typeof(T), value, ignoreCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string ToMd5(this string str)
|
|
||||||
{
|
|
||||||
using (var md5 = MD5.Create())
|
|
||||||
{
|
|
||||||
var inputBytes = Encoding.UTF8.GetBytes(str);
|
|
||||||
var hashBytes = md5.ComputeHash(inputBytes);
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
foreach (var hashByte in hashBytes)
|
|
||||||
{
|
|
||||||
sb.Append(hashByte.ToString("X2"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts camelCase string to PascalCase string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">String to convert</param>
|
|
||||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
|
||||||
/// <returns>PascalCase of the string</returns>
|
|
||||||
public static string ToPascalCase(this string str, bool useCurrentCulture = false)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(str))
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str.Length == 1)
|
|
||||||
{
|
|
||||||
return useCurrentCulture ? str.ToUpper() : str.ToUpperInvariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (useCurrentCulture ? char.ToUpper(str[0]) : char.ToUpperInvariant(str[0])) + str.Substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a substring of a string from beginning of the string if it exceeds maximum length.
|
|
||||||
/// </summary>
|
|
||||||
public static string Truncate(this string str, int maxLength)
|
|
||||||
{
|
|
||||||
if (str.Length <= maxLength)
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.Left(maxLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a substring of a string from Ending of the string if it exceeds maximum length.
|
|
||||||
/// </summary>
|
|
||||||
public static string TruncateFromBeginning(this string str, int maxLength)
|
|
||||||
{
|
|
||||||
if (str.Length <= maxLength)
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.Right(maxLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a substring of a string from beginning of the string if it exceeds maximum length.
|
|
||||||
/// It adds a "..." postfix to end of the string if it's truncated.
|
|
||||||
/// Returning string can not be longer than maxLength.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
|
|
||||||
public static string TruncateWithPostfix(this string str, int maxLength)
|
|
||||||
{
|
|
||||||
return TruncateWithPostfix(str, maxLength, "...");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a substring of a string from beginning of the string if it exceeds maximum length.
|
|
||||||
/// It adds given <paramref name="postfix"/> to end of the string if it's truncated.
|
|
||||||
/// Returning string can not be longer than maxLength.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
|
|
||||||
public static string TruncateWithPostfix(this string str, int maxLength, string postfix)
|
|
||||||
{
|
|
||||||
if (str == string.Empty || maxLength == 0)
|
|
||||||
{
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str.Length <= maxLength)
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maxLength <= postfix.Length)
|
|
||||||
{
|
|
||||||
return postfix.Left(maxLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
return str.Left(maxLength - postfix.Length) + postfix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts given string to a byte array using <see cref="Encoding.UTF8"/> encoding.
|
|
||||||
/// </summary>
|
|
||||||
public static byte[] GetBytes(this string str)
|
|
||||||
{
|
|
||||||
return str.GetBytes(Encoding.UTF8);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts given string to a byte array using the given <paramref name="encoding"/>
|
|
||||||
/// </summary>
|
|
||||||
public static byte[] GetBytes([NotNull] this string str, [NotNull] Encoding encoding)
|
|
||||||
{
|
|
||||||
ThrowIf.IsNull(str, nameof(str));
|
|
||||||
ThrowIf.IsNull(encoding, nameof(encoding));
|
|
||||||
|
|
||||||
return encoding.GetBytes(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsAllUpperCase(string input)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < input.Length; i++)
|
|
||||||
{
|
|
||||||
if (Char.IsLetter(input[i]) && !Char.IsUpper(input[i]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts snake_case string to PascalCase string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">String to convert</param>
|
|
||||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
|
||||||
/// <returns>PascalCase of the string</returns>
|
|
||||||
public static string SnakeToPascalCase(this string str, bool useCurrentCulture = false)
|
|
||||||
{
|
|
||||||
var sArr = str.Split(new char[] { '-', '_' }).Select(a => a.ToPascalCase(useCurrentCulture));
|
|
||||||
return string.Join("", sArr);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Converts snake_case string to PascalCase string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="str">String to convert</param>
|
|
||||||
/// <param name="useCurrentCulture">set true to use current culture. Otherwise, invariant culture will be used.</param>
|
|
||||||
/// <returns>PascalCase of the string</returns>
|
|
||||||
public static string SnakeToCamelCase(this string str, bool useCurrentCulture = false)
|
|
||||||
{
|
|
||||||
return SnakeToPascalCase(str, useCurrentCulture).ToCamelCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
using JNPF.Common.Security;
|
using JNPF.Common.Security;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using Tnb.Core;
|
||||||
using Tnb.Vengine.Domain;
|
using Tnb.Vengine.Domain;
|
||||||
|
|
||||||
namespace Tnb.Vengine;
|
namespace Tnb.Vengine;
|
||||||
@@ -21,7 +22,7 @@ public class VmodelMapper : IRegister
|
|||||||
config.ForType<VmGetListInput, VmQueryInput>()
|
config.ForType<VmGetListInput, VmQueryInput>()
|
||||||
.Map(dest => dest.q, src => string.IsNullOrEmpty(src.q) ? null : src.q.ToObject<DObject>());
|
.Map(dest => dest.q, src => string.IsNullOrEmpty(src.q) ? null : src.q.ToObject<DObject>());
|
||||||
config.ForType<DbColumnInfo, VmDbProp>()
|
config.ForType<DbColumnInfo, VmDbProp>()
|
||||||
.Map(dest => dest.code, src => src.DbColumnName.SnakeToCamelCase(false))
|
.Map(dest => dest.code, src => src.DbColumnName.ToCamel())
|
||||||
.Map(dest => dest.name, src => src.ColumnDescription)
|
.Map(dest => dest.name, src => src.ColumnDescription)
|
||||||
.Map(dest => dest.field, src => src.DbColumnName)
|
.Map(dest => dest.field, src => src.DbColumnName)
|
||||||
.Map(dest => dest.dataType, src => src.DataType)
|
.Map(dest => dest.dataType, src => src.DataType)
|
||||||
|
|||||||
@@ -7,7 +7,12 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\common\Tnb.Common.Core\Tnb.Common.Core.csproj" />
|
||||||
<ProjectReference Include="..\..\common\Tnb.Common\Tnb.Common.csproj" />
|
<ProjectReference Include="..\..\common\Tnb.Common\Tnb.Common.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Extension\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user