497 lines
16 KiB
C#
497 lines
16 KiB
C#
using log4net;
|
|
using Microsoft.Extensions.Hosting;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.ServiceModel;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
using System.Web.Http.Description;
|
|
using System.Web.UI.WebControls;
|
|
using UFIDA.U8.Framework.Api.Common.Entity;
|
|
using UFIDA.U8.Framework.Api.ControlObject.Common;
|
|
using UFIDA.U8.Framework.Api.ControlObject.Entity;
|
|
using UFIDA.U8.Framework.Api.ControlObject.Json;
|
|
using UFIDA.U8.Framework.Api.ControlObject.U8M;
|
|
using UFIDA.U8.Framework.Api.Entity;
|
|
using UFIDA.U8.Framework.Api.Models;
|
|
using UFIDA.U8.Framework.Api.Unit;
|
|
using SysU8AccountConfig = UFIDA.U8.Framework.Api.ControlObject.Entity.SysU8AccountConfig;
|
|
|
|
namespace UFIDA.U8.Framework.Api.Controllers.U8
|
|
{
|
|
/// <summary>
|
|
/// 平台功能
|
|
/// </summary>
|
|
public class DPController : ApiController
|
|
{
|
|
/// <summary>
|
|
/// 日志组件
|
|
/// </summary>
|
|
protected readonly ILog _logInfo = LogManager.GetLogger("logInfo");
|
|
|
|
/// <summary>
|
|
/// U8登录接口
|
|
/// </summary>
|
|
/// <param name="cAccId">系统号</param>
|
|
/// <param name="input">登录参数</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/DP/Login")]
|
|
public async Task<BaseResult<string>> Login(string cAccId, [FromBody] LoginInput input)
|
|
{
|
|
try
|
|
{
|
|
|
|
_logInfo.Debug($"当前接口:api/U8/DP/Login,参数:{input.ToJson()}");
|
|
|
|
var db = CommUnit.GetDbClient();
|
|
|
|
var account = await db.Queryable<SysU8AccountConfig>().FirstAsync(a => a.Status == StatusEnum.Enable && a.cAccountNo == cAccId);
|
|
|
|
if (account == null)
|
|
{
|
|
throw new Exception($"未能找到[{cAccId}]的配置信息");
|
|
}
|
|
|
|
var param = new LoginParamter()
|
|
{
|
|
cSrv = account.cSrv,
|
|
pAccId = account.cAcc_DataSource,
|
|
pDate = string.IsNullOrWhiteSpace(input.pDate) ? $"{DateTime.Today:yyyy-MM-dd}" : input.pDate,
|
|
pPassword = string.IsNullOrWhiteSpace(input.pPassword) ? "" : CommUnit.GetDecrypt(input.pPassword),
|
|
pYearId = string.IsNullOrWhiteSpace(input.pDate) ? $"{DateTime.Today.Year}" : $"{DateTime.Parse(input.pDate).Year}",
|
|
pSubId = "DP",
|
|
pUserId = input.pUserId
|
|
};
|
|
|
|
var login = new BaseLogin();
|
|
|
|
login.Init(param, false);
|
|
|
|
var userToken = login.userToken;
|
|
|
|
if (!string.IsNullOrWhiteSpace(userToken))
|
|
{
|
|
var output = new LoginOutput
|
|
{
|
|
cAccId = cAccId,
|
|
userToken = CommUnit.GetEncrypt(userToken),
|
|
loginParamter = param
|
|
};
|
|
|
|
return new BaseResult<string>() { bSuccess = true, message = "登录成功", result = CommUnit.GetEncrypt(output.ToJson()) };
|
|
}
|
|
|
|
throw new Exception("未知错误,请检查系统日志");
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
await Task.Delay(1);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "登录失败", result = ex.Message };
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// U8登录接口
|
|
/// </summary>
|
|
/// <param name="input">用户令牌</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/DP/Login/Token")]
|
|
public async Task<BaseResult<string>> Login([FromBody] UserTokenInput input)
|
|
{
|
|
try
|
|
{
|
|
|
|
_logInfo.Debug($"当前接口:api/U8/DP/Login/Token,参数:{input.ToJson()}");
|
|
|
|
var token = CommUnit.GetUserToken(input.userToken);
|
|
|
|
var login = new BaseLogin();
|
|
|
|
login.Init(token, false);
|
|
|
|
var userToken = login.userToken;
|
|
|
|
if (!string.IsNullOrWhiteSpace(userToken))
|
|
{
|
|
return new BaseResult<string>() { bSuccess = true, message = "登录成功", result = "登录成功" };
|
|
}
|
|
|
|
throw new Exception("未知错误,请检查系统日志");
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
await Task.Delay(1);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "登录失败", result = ex.Message };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取U8密码
|
|
/// </summary>
|
|
/// <param name="cPwd"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("api/U8/DP/GetPassword")]
|
|
public async Task<BaseResult<string>> GetPassword(string cPwd)
|
|
{
|
|
try
|
|
{
|
|
await Task.Delay(1);
|
|
|
|
return new BaseResult<string>() { bSuccess = true, message = "加密成功", result = CommonHelper.U8Encrypt(cPwd) };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "登录失败", result = ex.Message };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取对接账套设置
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/DP/GetAccountConfig")]
|
|
public async Task<BaseResult<dynamic>> GetAccountConfig([FromBody] U8AccountConfigInput input)
|
|
{
|
|
try
|
|
{
|
|
var db = CommUnit.GetDbClient();
|
|
|
|
var res = await db.Queryable<Common.Entity.SysU8AccountConfig>()
|
|
.Where(a => a.cAccountNo == input.cAccId)
|
|
.FirstAsync();
|
|
|
|
return new BaseResult<dynamic> { bSuccess = true, message = "查询成功", result = res };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<dynamic> { bSuccess = false, message = "查询失败", result = ex.Message };
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取加密字符串
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("api/U8/DP/GetEncryptString")]
|
|
public async Task<BaseResult<string>> GetEncryptString(string input)
|
|
{
|
|
try
|
|
{
|
|
await Task.Delay(1);
|
|
|
|
return new BaseResult<string> { bSuccess = true, message = "加密成功", result = CommUnit.GetEncrypt(input) };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "加密失败", result = ex.Message };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取解密字符串
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("api/U8/DP/GetDecryptString")]
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
public async Task<BaseResult<string>> GetDecryptString(string input)
|
|
{
|
|
try
|
|
{
|
|
await Task.Delay(1);
|
|
|
|
return new BaseResult<string> { bSuccess = true, message = "解密成功", result = CommUnit.GetDecrypt(input) };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "解密失败", result = ex.Message };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 注册对接系统
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/DP/AddAccountConfig")]
|
|
public async Task<BaseResult<dynamic>> AddAccountConfig([FromBody] AddU8AccountConfigInput input)
|
|
{
|
|
try
|
|
{
|
|
var db = CommUnit.GetDbClient();
|
|
|
|
var isExists = await db.Queryable<SysU8AccountConfig>().AnyAsync(a => a.cAccountNo == input.cAccountNo);
|
|
|
|
if (isExists)
|
|
{
|
|
throw new Exception($"已存在系统号为{input.cAccountNo}的数据");
|
|
}
|
|
|
|
try
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(input.cPassword))
|
|
{
|
|
CommUnit.GetDecrypt(input.cPassword);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Debug($"密码未加密:{ex.Message},将进行密码加密");
|
|
|
|
input.cPassword = CommUnit.GetEncrypt(input.cPassword);
|
|
}
|
|
|
|
var id = await db.Insertable(input).ExecuteReturnIdentityAsync();
|
|
|
|
return new BaseResult<dynamic> { bSuccess = true, message = "新增成功", result = id };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<dynamic> { bSuccess = false, message = "新增失败", result = ex.Message };
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新对接系统
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/DP/UpdateAccountConfig")]
|
|
public async Task<BaseResult<dynamic>> UpdateAccountConfig([FromBody] AddU8AccountConfigInput input)
|
|
{
|
|
try
|
|
{
|
|
var db = CommUnit.GetDbClient();
|
|
|
|
var isExists = await db.Queryable<Common.Entity.SysU8AccountConfig>().AnyAsync(a => a.Id == input.Id);
|
|
|
|
if (!isExists)
|
|
{
|
|
throw new Exception($"不存在系统号为{input.cAccountNo}的数据");
|
|
}
|
|
|
|
try
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(input.cPassword))
|
|
{
|
|
CommUnit.GetDecrypt(input.cPassword);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Debug($"密码未加密:{ex.Message},将进行密码加密");
|
|
|
|
input.cPassword = CommUnit.GetEncrypt(input.cPassword);
|
|
}
|
|
|
|
var id = await db.Updateable(input).ExecuteCommandAsync();
|
|
|
|
return new BaseResult<dynamic> { bSuccess = true, message = "更新成功", result = id };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<dynamic> { bSuccess = false, message = "更新失败", result = ex.Message };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取对接系统列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/DP/ListAccountConfig")]
|
|
public async Task<BaseResult<dynamic>> ListAccountConfig([FromBody] ListU8AccountConfigInput input)
|
|
{
|
|
try
|
|
{
|
|
var db = CommUnit.GetDbClient();
|
|
|
|
var res = await db.Queryable<Common.Entity.SysU8AccountConfig>()
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.cAccId), a => a.cAccountNo == input.cAccId)
|
|
.ToListAsync();
|
|
|
|
return new BaseResult<dynamic> { bSuccess = true, message = "查询成功", result = res };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
return new BaseResult<dynamic> { bSuccess = false, message = "查询失败", result = ex.Message };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 上传配置
|
|
/// </summary>
|
|
/// <param name="cKey"></param>
|
|
/// <param name="inputs"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/DP/UploadConfig")]
|
|
public async Task<BaseResult<string>> UploadConfig(string cKey,[FromBody] List<Dictionary<string,object>> inputs)
|
|
{
|
|
try
|
|
{
|
|
var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"App_Data/{cKey}.json");
|
|
|
|
File.WriteAllText(fileName, inputs.ToJson());
|
|
|
|
return new BaseResult<string>()
|
|
{
|
|
result = "上传成功",
|
|
message = "上传成功",
|
|
bSuccess = true
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
await Task.Delay(1);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "查询失败", result = ex.Message };
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 下载配置
|
|
/// </summary>
|
|
/// <param name="cKey"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/DP/DownloadConfig")]
|
|
public async Task<BaseResult<string>> DownloadConfig(string cKey)
|
|
{
|
|
try
|
|
{
|
|
var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"App_Data/{cKey}.json");
|
|
|
|
var txt=File.ReadAllText(fileName );
|
|
|
|
return new BaseResult<string>()
|
|
{
|
|
result = txt,
|
|
message = "上传成功",
|
|
bSuccess = true
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
await Task.Delay(1);
|
|
|
|
return new BaseResult<string> { bSuccess = false, message = "查询失败", result = ex.Message };
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询日志
|
|
/// </summary>
|
|
/// <param name="dDate"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("api/U8/DP/LoadLog")]
|
|
public async Task<string> LoadLog(string dDate)
|
|
{
|
|
try
|
|
{
|
|
if (!DateTime.TryParse(dDate, out var cDate))
|
|
{
|
|
throw new Exception("日期格式错误");
|
|
}
|
|
|
|
var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Log/Log_{cDate:yyyyMMdd}.log");
|
|
|
|
var txt = File.ReadAllLines(fileName);
|
|
|
|
return string.Join(Environment.NewLine, txt);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
await Task.Delay(1);
|
|
|
|
return ex.Message;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("api/U8/DP/InitSubSystem")]
|
|
public async Task<BaseResult<long>> InitSubSystem(Dictionary<string,string> input)
|
|
{
|
|
try
|
|
{
|
|
if (!input.TryGetValue("cAppInfo", out var cValue) || string.IsNullOrWhiteSpace(cValue))
|
|
{
|
|
throw new Exception("参数错误");
|
|
}
|
|
var info = CommUnit.GetDecrypt(cValue).ToObject<SysSubSystem>();
|
|
|
|
var db = CommUnit.GetDbClient();
|
|
if (await db.Queryable<SysSubSystem>().AnyAsync(a => a.AppKey == info.AppKey))
|
|
{
|
|
throw new Exception("当前子系统已注册");
|
|
}
|
|
|
|
info.Id=SnowFlakeSingle.instance.NextId();
|
|
|
|
await db.Insertable(info).ExecuteCommandAsync();
|
|
|
|
return new BaseResult<long>() { bSuccess = true, message = "注册成功", result = info.Id };
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error(ex.Message, ex);
|
|
|
|
await Task.Delay(1);
|
|
|
|
return new BaseResult<long>() { bSuccess = false, message = "子系统初始化失败", result = 0 };
|
|
}
|
|
}
|
|
}
|
|
}
|