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;
///
///
[ApiGroup(ApiGroupNames.Sys)]
public class DocNoRuleController : Repository, IRomteService
{
private readonly IHttpContextAccessor _http;
private readonly string _userCode, _userGuid, _orgFids;
public DocNoRuleController(IHttpContextAccessor httpContextAccessor)
{
_http = httpContextAccessor;
(_userCode, _userGuid, _orgFids) =
UtilityHelper.GetUserGuidAndOrgGuid(_http);
}
///
/// 查询列表,支持分页
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto> GetListPage(PageQuery query)
{
var pageList = new PageList();
try
{
var _sbWhere = new StringBuilder(" 1=1" + query.keyWhere);
var _sbBy =
new StringBuilder(query.sortName + " " + query.sortOrder);
var totalCount = 0;
var itemsList = Db.Queryable()
.Where(_sbWhere.ToString())
.OrderBy(_sbBy.ToString())
.ToPageList(query.currentPage, query.everyPageSize,
ref totalCount);
pageList = new PageList(itemsList, totalCount,
query.everyPageSize);
return ReturnDto>.QuickReturn(pageList,
ReturnCode.Success, "读取成功");
}
catch (Exception ex)
{
return ReturnDto>.QuickReturn(pageList,
ReturnCode.Default, ex.Message);
}
}
///
/// 读取一个实体
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto GetModel([FromBody] SysDocRule model)
{
var m = base.GetById(model.Guid);
if (m != null)
return ReturnDto.QuickReturn(m, ReturnCode.Success,
"读取成功!");
return ReturnDto.QuickReturn(m, ReturnCode.Default,
"读取失败!");
}
///
/// 增加或编辑实体
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto EditModel([FromBody] SysDocRule model)
{
if (UtilityHelper.CheckGuid(model.Guid))
{
var cont = 0;
cont = IsChkOrUnChk(model.Guid.ToString(), true);
if (cont > 0)
return ReturnDto.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.QuickReturn("", ReturnCode.Exception,
ex.Message);
}
if (_bl)
return ReturnDto.QuickReturn(model.Guid.ToString(),
ReturnCode.Success, "操作成功!");
return ReturnDto.QuickReturn("", ReturnCode.Exception,
"增加失败,请重试!");
}
///
/// 删除实体,支持批量删除
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto DeleteModel([FromBody] JArray guidList)
{
var intArray = guidList.ToObject();
var cont = 0;
cont = IsChkOrUnChk(intArray[0], true);
if (cont > 0)
return ReturnDto.QuickReturn(default(int?),
ReturnCode.Exception, "删除失败,该信息已被审核!");
int? rtnInt = (int)ReturnCode.Default;
rtnInt = base.DeleteById(intArray) ? guidList.Count : 0;
if (rtnInt > 0)
return ReturnDto.QuickReturn(rtnInt, ReturnCode.Success,
"操作成功,共删除" + rtnInt + "条数据!");
return ReturnDto.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;
}
}