using log4net; using System; using System.Threading.Tasks; using System.Web.Http; using UFIDA.U8.Framework.Api.ControlObject.Models; using UFIDA.U8.Framework.Api.Models; using UFIDA.U8.Framework.Api.Unit; // ReSharper disable InconsistentNaming // ReSharper disable IdentifierTypo namespace UFIDA.U8.Framework.Api.Controllers { /// /// 公共服务 /// public class CommonController : ApiController { /// /// 日志对象 /// protected readonly ILog logInfo = LogManager.GetLogger("logInfo"); /// /// 获取加密字符串 /// /// /// [HttpGet] [Route("api/Common/GetEncryptString")] public BaseResult GetEncryptString(string input) { try { return new BaseResult { bSuccess = true, message = "加密成功", result = CommUnit.GetEncrypt(input) }; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = true, message = "加密失败", result = ex.Message }; } } /// /// 获取解密字符串 /// /// /// [HttpGet] [Route("api/Common/GetDecryptString")] public BaseResult GetDecryptString(string input) { try { return new BaseResult { bSuccess = true, message = "解密成功", result = CommUnit.GetDecrypt(input) }; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = true, message = "解密失败", result =ex.Message }; } } /// /// 获取对接账套设置 /// /// /// [HttpPost] [Route("api/Common/GetAccountConfig")] public async Task> GetAccountConfig([FromBody]U8AccountConfigInput input) { try { var db = CommUnit.GetDbClient(); var res=await db.Queryable() .Where(a => a.cAccountNo == input.cAccId) .FirstAsync(); return new BaseResult { bSuccess = false, message = "查询成功", result = res }; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = "查询失败", result = ex.Message }; } } /// /// 新增对接账套设置 /// /// /// [HttpPost] [Route("api/Common/AddAccountConfig")] public async Task> AddAccountConfig([FromBody] AddU8AccountConfigInput input) { try { var db = CommUnit.GetDbClient(); var isExists = await db.Queryable().AnyAsync(a => a.cAccountNo == input.cAccountNo); if (isExists) { throw new Exception($"已存在系统号为{input.cAccountNo}的数据"); } var id = await db.Insertable(input).ExecuteReturnIdentityAsync(); return new BaseResult { bSuccess = true, message = "新增成功", result = id }; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = "新增失败", result = ex.Message }; } } /// /// 更新对接账套设置 /// /// /// [HttpPost] [Route("api/Common/UpdateAccountConfig")] public async Task> UpdateAccountConfig([FromBody]AddU8AccountConfigInput input) { try { var db = CommUnit.GetDbClient(); var isExists = await db.Queryable().AnyAsync(a => a.Id==input.Id); if (!isExists) { throw new Exception($"不存在系统号为{input.cAccountNo}的数据"); } var id = await db.Updateable(input).ExecuteCommandAsync(); return new BaseResult { bSuccess = true, message = "更新成功", result = id }; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = "更新失败", result = ex.Message }; } } /// /// 获取对接账套设置列表 /// /// /// [HttpPost] [Route("api/Common/ListAccountConfig")] public async Task> ListAccountConfig([FromBody] ListU8AccountConfigInput input) { try { var db = CommUnit.GetDbClient(); var res =await db.Queryable() .WhereIF(!string.IsNullOrWhiteSpace(input.cAccId), a => a.cAccountNo == input.cAccId) .ToListAsync(); return new BaseResult { bSuccess = true, message = "查询成功", result = res }; } catch (Exception ex) { logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = "查询失败", result = ex.Message }; } } } }