85 lines
2.4 KiB
C#
85 lines
2.4 KiB
C#
using System.Data;
|
||
using JNPF.Common.Core.Manager;
|
||
using JNPF.Common.Enums;
|
||
using JNPF.Common.Extension;
|
||
using JNPF.Common.Filter;
|
||
using JNPF.Common.Security;
|
||
using JNPF.DependencyInjection;
|
||
using JNPF.DynamicApiController;
|
||
using JNPF.Extend.Entitys;
|
||
using JNPF.Extend.Entitys.Dto.WoekLog;
|
||
using JNPF.Extend.Entitys.Dto.WorkLog;
|
||
using JNPF.FriendlyException;
|
||
using JNPF.Systems.Entitys.Permission;
|
||
using JNPF.Systems.Interfaces.Permission;
|
||
using Mapster;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using SqlSugar;
|
||
using Yitter.IdGenerator;
|
||
|
||
namespace JNPF.Extend;
|
||
|
||
/// <summary>
|
||
/// 工作日志
|
||
/// 版 本:V3.2
|
||
/// 版 权:拓通智联科技有限公司(http://www.tuotong-tech.com)
|
||
/// 日 期:2021-06-01 .
|
||
/// </summary>
|
||
[ApiDescriptionSettings(Tag = "Extend", Name = "DataMgr", Order = 600)]
|
||
[Route("api/extend/[controller]")]
|
||
public class DataMgrService : IDynamicApiController, ITransient
|
||
{
|
||
private readonly SqlSugarScope _sugar;
|
||
private readonly ITenant _db;
|
||
|
||
public DataMgrService(ISqlSugarClient context)
|
||
{
|
||
_sugar = (SqlSugarScope)context;
|
||
_db = context.AsTenant();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 使用雪花Id
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost("renew-snow-id")]
|
||
[AllowAnonymous]
|
||
public async Task<dynamic> RenewSnowIdAsync(DbMainTable mainTbl)
|
||
{
|
||
int count = 0;
|
||
var tbl = await _sugar.Queryable<dynamic>().AS(mainTbl.MainTable).ToDataTableAsync();
|
||
if (!tbl.Columns.Contains(mainTbl.PrimaryKey))
|
||
{
|
||
return count;
|
||
}
|
||
foreach (DataRow row in tbl.Rows)
|
||
{
|
||
var oldid = row[mainTbl.PrimaryKey].ToString();
|
||
var snowid = SnowflakeIdHelper.NextId();
|
||
count += await _sugar.Updateable<dynamic>().AS(mainTbl.MainTable).Where($"{mainTbl.PrimaryKey}='{oldid}'").SetColumns(mainTbl.PrimaryKey, snowid).ExecuteCommandAsync();
|
||
foreach (var refTbl in mainTbl.RefTables)
|
||
{
|
||
count += await _sugar.Updateable<dynamic>().AS(refTbl.RefTable).Where($"{refTbl.RefField}='{oldid}'").SetColumns(refTbl.RefField, snowid).ExecuteCommandAsync();
|
||
}
|
||
}
|
||
return count;
|
||
}
|
||
}
|
||
|
||
public class DbMainTable
|
||
{
|
||
public string MainTable { get; set; }
|
||
public string PrimaryKey { get; set; } = "f_id";
|
||
public List<DbTableRef> RefTables { get; set; } = new List<DbTableRef>();
|
||
public DbMainTable(string tblName)
|
||
{
|
||
MainTable = tblName;
|
||
}
|
||
}
|
||
public class DbTableRef
|
||
{
|
||
public string RefTable { get; set; }
|
||
public string RefField { get; set; }
|
||
|
||
} |