Files
tnb.server/system/Tnb.Systems/Common/TestService.cs
2024-07-12 15:01:12 +08:00

155 lines
5.4 KiB
C#

using JNPF.Common.Const;
using JNPF.Common.Contracts;
using JNPF.Common.Core.Manager;
using JNPF.Common.Security;
using JNPF.DataEncryption;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.JsonSerialization;
using JNPF.Logging.Attributes;
using JNPF.Systems.Entitys.Permission;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Npgsql.TypeHandlers;
using SqlSugar;
using Tnb.ProductionMgr.Entities.Entity;
namespace JNPF.Systems.Common;
/// <summary>
/// 测试接口.
/// </summary>
[ApiDescriptionSettings(Name = "Test", Order = 306)]
[Route("api")]
public class TestService : IDynamicApiController, ITransient
{
//private readonly ISqlSugarRepository<UserEntity> _repository;
private readonly SqlSugarScope _sugar;
private readonly IDataBaseManager _databaseService;
public TestService(ISqlSugarClient db, IDataBaseManager databaseService)
{
//_repository = repository;
_sugar = (SqlSugarScope)db;
_databaseService = databaseService;
}
/// <summary>
/// 用于健康检查应用程序
/// </summary>
/// <returns></returns>
[HttpGet("heart-beat")]
[AllowAnonymous]
[IgnoreLog]
[DisableCors]
public async Task<dynamic> Heartbeat()
{
return await Task.FromResult<dynamic>(new { reply = "应用程序运行正常" });
}
[HttpGet("test")]
[AllowAnonymous]
[IgnoreLog]
[DisableCors]
public async Task<dynamic> test()
{
try
{
//var aaaaa= JsEngineUtil.AggreFunction("COUNT('1','1','1')").ToString();
//var xx = App.HttpContext.Request.Host.ToString();
//var sql = "SELECT TOP 1 [F_PARENTID],[F_PROCESSID],[F_ENCODE],[F_FULLNAME],[F_FLOWURGENT],[F_FLOWID],[F_FLOWCODE],[F_FLOWNAME],[F_FLOWTYPE],[F_FLOWCATEGORY],[F_FLOWFORM],[F_FLOWFORMCONTENTJSON],[F_FLOWTEMPLATEJSON],[F_FLOWVERSION],[F_STARTTIME],[F_ENDTIME],[F_THISSTEP],[F_THISSTEPID],[F_GRADE],[F_STATUS],[F_COMPLETION],[F_DESCRIPTION],[F_SORTCODE],[F_ISASYNC],[F_ISBATCH],[F_TASKNODEID],[F_TEMPLATEID],[F_REJECTDATAID],[F_DELEGATEUSER],[F_CREATORTIME],[F_CREATORUSERID],[F_ENABLEDMARK],[F_LastModifyTime],[F_LastModifyUserId],[F_DeleteMark],[F_DeleteTime],[F_DeleteUserId],[F_Id] FROM [FLOW_TASK] WHERE (( [F_DeleteMark] IS NULL ) AND ( [F_Id] = N'367536153122855173' ))";
//var darta = _sqlSugarRepository.AsSugarClient().Ado.SqlQuery<dynamic>(sql);
var data = await _sugar.Queryable<UserEntity>().FirstAsync(a => true);
var json = App.GetService<IJsonSerializerProvider>();
return data;
}
catch (Exception e)
{
throw;
}
}
public async Task ImportMoldData()
{
}
public void xx(UserEntity user)
{
user.Account = "2312321";
}
public void xx1(UserEntity user)
{
user.Account = "2312321";
}
[HttpGet]
[AllowAnonymous]
public string test1()
{
return "测试成功";
}
[HttpGet]
[AllowAnonymous]
public async Task<string> insertUser()
{
List<TempErpUser> users = _sugar.Queryable<TempErpUser>().ToList();
List<UserEntity> insertUsers = new List<UserEntity>();
List<UserRelationEntity> insertUserRelations = new List<UserRelationEntity>();
List<ErpExtendField> insertErpExtendFields = new List<ErpExtendField>();
foreach (var user in users)
{
UserEntity userEntity = new UserEntity();
userEntity.Id = SnowflakeIdHelper.NextId();
userEntity.Account = user.code;
userEntity.RealName = user.name;
userEntity.Gender = 1;
userEntity.OrganizeId = "25193668006933";
userEntity.RoleId = "30327535942933";
userEntity.Secretkey = Guid.NewGuid().ToString();
userEntity.Password = MD5Encryption.Encrypt(MD5Encryption.Encrypt(CommonConst.DEFAULTPASSWORD) + userEntity.Secretkey);
userEntity.EntryDate = DateTime.Now;
userEntity.EnabledMark = 1;
userEntity.CreatorTime = DateTime.Now;
insertUsers.Add(userEntity);
UserRelationEntity userRelationEntity = new UserRelationEntity();
userRelationEntity.Id = SnowflakeIdHelper.NextId();
userRelationEntity.UserId = userEntity.Id;
userRelationEntity.ObjectType = "Role";
userRelationEntity.ObjectId = "30327535942933";
userRelationEntity.CreatorTime = DateTime.Now;
insertUserRelations.Add(userRelationEntity);
ErpExtendField extendField = new ErpExtendField();
extendField.id = SnowflakeIdHelper.NextId();
extendField.org_id = "25398501929509";
extendField.table_name = "base_user";
extendField.table_id = userEntity.Id;
extendField.user_id = user.id;
insertErpExtendFields.Add(extendField);
}
await _sugar.Insertable(insertUsers).ExecuteCommandAsync();
await _sugar.Insertable(insertUserRelations).ExecuteCommandAsync();
await _sugar.Insertable(insertErpExtendFields).ExecuteCommandAsync();
return "测试成功";
}
[SugarTable("temp_erp_user")]
public class TempErpUser : BaseEntity<string>
{
public string code { get; set; }
public string name { get; set; }
}
}