You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

147 lines
5.0 KiB

using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Znyc.Cloudcar.Admin.AspNetCore.Controllers;
using Znyc.Cloudcar.Admin.AspNetCore.Entitys;
using Znyc.Cloudcar.Admin.AspNetCore.Mvc;
using Znyc.Cloudcar.Admin.Commons.Cache;
using Znyc.Cloudcar.Admin.Commons.Encrypt;
using Znyc.Cloudcar.Admin.Commons.Entitys;
using Znyc.Cloudcar.Admin.Commons.Helpers;
using Znyc.Cloudcar.Admin.Commons.Log;
using Znyc.Cloudcar.Admin.Security.Dtos;
using Znyc.Cloudcar.Admin.Security.Entitys;
using Znyc.Cloudcar.Admin.Security.IServices;
namespace Znyc.Cloudcar.Admin.WebApi.Controllers
{
/// <summary>
/// 系统类型
/// </summary>
[ApiController]
[Route("api/Security/[controller]")]
public class
SystemTypeController : AreaApiController<SystemTypeEntity, SystemTypeOutputDto, SystemTypeInputDto,
ISystemTypeService
, long>
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="service"></param>
public SystemTypeController(ISystemTypeService service) : base(service)
{
_service = service;
}
/// <summary>
/// 新增前处理数据
/// </summary>
/// <param name="info"></param>
protected override void OnBeforeInsert(SystemTypeEntity info)
{
info.Id = 0;
info.CreatedTime = DateTime.Now;
info.CreatedUserId = CurrentUser.UserId;
info.IsDeleted = false;
}
/// <summary>
/// 在更新数据前对数据的修改操作
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
protected override void OnBeforeUpdate(SystemTypeEntity info)
{
info.ModifiedUserId = CurrentUser.UserId;
info.ModifiedTime = DateTime.Now;
}
/// <summary>
/// 在软删除数据前对数据的修改操作
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
protected override void OnBeforeSoftDelete(SystemTypeEntity info)
{
info.IsDeleted = true;
}
/// <summary>
/// 异步更新数据
/// </summary>
/// <param name="tinfo"></param>
/// <returns></returns>
[HttpPost("Update")]
[FunctionAuthorize("Edit")]
public async Task<IActionResult> UpdateAsync(SystemTypeInputDto tinfo)
{
CommonResult result = new CommonResult();
SystemTypeEntity info = _service.Get(tinfo.Id);
//info.FullName = tinfo.FullName;
//info.EnCode = tinfo.EnCode;
//info.Url = tinfo.Url;
//info.AllowEdit = tinfo.AllowEdit;
//info.AllowDelete = tinfo.AllowDelete;
//info.SortCode = tinfo.SortCode;
//info.Description = tinfo.Description;
OnBeforeUpdate(info);
bool bl = await _service.UpdateAsync(info, tinfo.Id).ConfigureAwait(true);
if (bl)
{
result.ErrCode = ErrCode.successCode;
result.ErrMsg = ErrCode.err0;
}
else
{
result.ErrMsg = ErrCode.err43002;
result.ErrCode = "43002";
}
return ToJsonContent(result);
}
/// <summary>
/// 系统切换时获取凭据
/// 适用于不同子系统分别独立部署站点场景
/// </summary>
/// <param name="systype">子系统编码</param>
/// <returns></returns>
[HttpGet("ZnycConnecSys")]
[FunctionAuthorize("")]
public IActionResult ZnycConnecSys(string systype)
{
CommonResult result = new CommonResult();
try
{
if (!string.IsNullOrEmpty(systype))
{
SystemTypeEntity systemType = _service.GetByCode(systype);
string openmf = MD5Util.GetMD5_32(DEncrypt.Encrypt(CurrentUser.UserId + systemType.Id.ToString(),
GuidUtils.NewGuidFormatN())).ToLower();
CacheHelper cacheHelper = new CacheHelper();
TimeSpan expiresSliding = DateTime.Now.AddSeconds(200) - DateTime.Now;
cacheHelper.Add("openmf" + openmf, CurrentUser.UserId, expiresSliding);
result.ErrCode = ErrCode.successCode;
result.ResData = systemType.Url + "?openmf=" + openmf;
}
else
{
result.ErrCode = ErrCode.failCode;
result.ErrMsg = "切换子系统参数错误";
}
}
catch (Exception ex)
{
Log4NetHelper.Error("切换子系统异常", ex);
result.ErrMsg = ErrCode.err40110;
result.ErrCode = "40110";
}
return ToJsonContent(result);
}
}
}