using System.Text;
|
using Gs.Sys.Models;
|
using Gs.Toolbox;
|
using Gs.Toolbox.ApiCore.Abstract.Mvc;
|
using Gs.Toolbox.ApiCore.Common.Mvc;
|
using Gs.Toolbox.ApiCore.Group;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using Newtonsoft.Json.Linq;
|
|
namespace Gs.Sys.Services;
|
|
/// <summary>
|
/// </summary>
|
[ApiGroup(ApiGroupNames.Sys)]
|
public class DocNoRuleController : Repository<SysDocRule>, IRomteService
|
{
|
private readonly IHttpContextAccessor _http;
|
private readonly string _userCode, _userGuid, _orgFids;
|
|
public DocNoRuleController(IHttpContextAccessor httpContextAccessor)
|
{
|
_http = httpContextAccessor;
|
(_userCode, _userGuid, _orgFids) =
|
UtilityHelper.GetUserGuidAndOrgGuid(_http);
|
}
|
|
/// <summary>
|
/// 查询列表,支持分页
|
/// </summary>
|
/// <param name="query"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<PageList<SysDocRule>> GetListPage(PageQuery query)
|
{
|
var pageList = new PageList<SysDocRule>();
|
try
|
{
|
var _sbWhere = new StringBuilder(" 1=1" + query.keyWhere);
|
var _sbBy =
|
new StringBuilder(query.sortName + " " + query.sortOrder);
|
var totalCount = 0;
|
var itemsList = Db.Queryable<SysDocRule>()
|
.Where(_sbWhere.ToString())
|
.OrderBy(_sbBy.ToString())
|
.ToPageList(query.currentPage, query.everyPageSize,
|
ref totalCount);
|
|
pageList = new PageList<SysDocRule>(itemsList, totalCount,
|
query.everyPageSize);
|
return ReturnDto<PageList<SysDocRule>>.QuickReturn(pageList,
|
ReturnCode.Success, "读取成功");
|
}
|
catch (Exception ex)
|
{
|
return ReturnDto<PageList<SysDocRule>>.QuickReturn(pageList,
|
ReturnCode.Default, ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 读取一个实体
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<SysDocRule> GetModel([FromBody] SysDocRule model)
|
{
|
var m = base.GetById(model.Guid);
|
if (m != null)
|
return ReturnDto<SysDocRule>.QuickReturn(m, ReturnCode.Success,
|
"读取成功!");
|
return ReturnDto<SysDocRule>.QuickReturn(m, ReturnCode.Default,
|
"读取失败!");
|
}
|
|
/// <summary>
|
/// 增加或编辑实体
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<string?> EditModel([FromBody] SysDocRule model)
|
{
|
if (UtilityHelper.CheckGuid(model.Guid))
|
{
|
var cont = 0;
|
cont = IsChkOrUnChk(model.Guid.ToString(), true);
|
if (cont > 0)
|
return ReturnDto<string>.QuickReturn("", ReturnCode.Exception, "修改失败,该信息已被审核!");
|
}
|
var _bl = false;
|
try
|
{
|
if (!UtilityHelper.CheckGuid(model.Guid))
|
{
|
model.Guid = Guid.NewGuid();
|
model.CreateBy = _userCode;
|
model.CreateTime = DateTime.Now;
|
model.CheckStatus = false;
|
_bl = base.Insert(model);
|
}
|
else
|
{
|
model.LastupdateBy = _userCode;
|
model.LastupdateTime = DateTime.Now;
|
}
|
//_bl = base.Update(model);
|
_bl = Db.Updateable(model).IgnoreColumns(true).ExecuteCommand() > 0
|
? true
|
: false;
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Debug(ToString(), "EditModel error:" + ex.Message);
|
return ReturnDto<string>.QuickReturn("", ReturnCode.Exception,
|
ex.Message);
|
}
|
|
if (_bl)
|
return ReturnDto<string>.QuickReturn(model.Guid.ToString(),
|
ReturnCode.Success, "操作成功!");
|
return ReturnDto<string>.QuickReturn("", ReturnCode.Exception,
|
"增加失败,请重试!");
|
}
|
|
/// <summary>
|
/// 删除实体,支持批量删除
|
/// </summary>
|
/// <param name="guid"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<int?> DeleteModel([FromBody] JArray guidList)
|
{
|
var intArray = guidList.ToObject<string[]>();
|
|
var cont = 0;
|
cont = IsChkOrUnChk(intArray[0], true);
|
if (cont > 0)
|
return ReturnDto<int>.QuickReturn(default(int?),
|
ReturnCode.Exception, "删除失败,该信息已被审核!");
|
|
|
int? rtnInt = (int)ReturnCode.Default;
|
rtnInt = base.DeleteById(intArray) ? guidList.Count : 0;
|
if (rtnInt > 0)
|
return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Success,
|
"操作成功,共删除" + rtnInt + "条数据!");
|
return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception,
|
"删除失败,请重试!");
|
}
|
|
private int IsChkOrUnChk(string guidList, bool status)
|
{
|
var cont = 0;
|
cont = base.GetList(it =>
|
it.Guid == Guid.Parse(guidList) && it.CheckStatus == status).Count;
|
return cont;
|
}
|
}
|