using System.Data;
|
using System.Text;
|
using Gs.Entity.Sys;
|
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.Authorization;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using static Gs.Toolbox.UtilityHelper;
|
|
|
namespace Gs.Sys.Services;
|
|
/// <summary>
|
/// </summary>
|
[ApiGroup(ApiGroupNames.Sys)]
|
public class OrganizationController : Repository<SysOrganization>, IRomteService
|
{
|
private readonly IHttpContextAccessor _http;
|
|
private readonly string _userCode, _userGuid, _orgFids;
|
|
public OrganizationController(IHttpContextAccessor httpContextAccessor)
|
{
|
_http = httpContextAccessor;
|
(_userCode, _userGuid, _orgFids) =
|
GetUserGuidAndOrgGuid(_http);
|
}
|
|
/// <summary>
|
/// 查询列表,支持分页
|
/// </summary>
|
/// <param name="query"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<PageList<SysOrganization>> GetListPage(PageQuery query)
|
{
|
string keyWord = query.keyWord;
|
var pageList = new PageList<SysOrganization>();
|
try
|
{
|
var _sbWhere = new StringBuilder(" 1=1" + query.keyWhere);
|
var _sbBy =
|
new StringBuilder(query.sortName + " " + query.sortOrder);
|
var totalCount = 0;
|
var itemsList = Db.Queryable<SysOrganization>()
|
.Where(_sbWhere.ToString())
|
.OrderBy(_sbBy.ToString())
|
.ToPageList(query.currentPage, query.everyPageSize,
|
ref totalCount);
|
pageList = new PageList<SysOrganization>(itemsList, totalCount,
|
query.everyPageSize);
|
if (!string.IsNullOrEmpty(keyWord))
|
{
|
System.Text.StringBuilder sbOrg = new StringBuilder();
|
System.Data.DataSet dataSet = new System.Data.DataSet();
|
dataSet = Gs.Toolbox.DbHelperSQL.Query(" select org_fid from [dbo].[SYS_USER_ORG] where user_guid='" + keyWord + "' order by org_fid asc");
|
if (dataSet != null && dataSet.Tables.Count > 0)
|
{
|
foreach (DataRow _row in dataSet.Tables[0].Rows)
|
{
|
if (sbOrg.Length > 0)
|
sbOrg.Append(", ");
|
sbOrg.Append(_row["org_fid"].ToString());
|
}
|
}
|
pageList.extendText = sbOrg.ToString();
|
}
|
return ReturnDto<PageList<SysOrganization>>.QuickReturn(pageList,
|
ReturnCode.Success, "读取成功");
|
}
|
catch (Exception ex)
|
{
|
return ReturnDto<PageList<SysOrganization>>.QuickReturn(pageList,
|
ReturnCode.Default, ex.Message);
|
}
|
}
|
|
///// <summary>
|
///// 删除机构
|
///// </summary>
|
///// <param name="model"></param>
|
///// <returns></returns>
|
//[RequestMethod(RequestMethods.POST)]
|
//public ReturnDto<int?> DeleteModel([FromBody] JArray guidList)
|
//{
|
// string[] intArray = guidList.ToObject<string[]>();
|
// string guid = intArray[0];
|
|
// int cont = 0;
|
// cont = IsChkOrUnChk(intArray[0], true);
|
// if (cont > 0)
|
// return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "删除失败,该信息已被审核!");
|
|
|
// int? rtnInt = (int)ReturnCode.Default;
|
|
// int it1 = 0;
|
// int it2 = 0;
|
// cont = Db.Queryable<SysOrganization>().Where(c => c.Guid == Guid.Parse(guid) && c.IsSys == 1).Count();
|
// if (cont > 0)
|
// {
|
// return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "删除失败,该条目为系统内置,不可删除!");
|
// }
|
// try
|
// {
|
// Db.Ado.BeginTran();
|
// it1 = Db.Deleteable<SysOrganization>().In(guid).ExecuteCommand();
|
// it2 = Db.Deleteable<SysRoleMenuAction>().Where(it => it.OrgGuid == Guid.Parse(guid)).ExecuteCommand();
|
// Db.Ado.CommitTran();
|
// }
|
// catch (Exception ex)
|
// {
|
// LogHelper.Debug(this.ToString(), "DeleteModel error:" + ex.Message);
|
// Db.Ado.RollbackTran();
|
// return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception, "删除失败,请重试!");
|
// }
|
// rtnInt = (it2 + it1);
|
// return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Success, "操作成功,共删除" + rtnInt.ToString() + "条数据!");
|
//}
|
|
///// <summary>
|
///// 增加机构
|
///// </summary>
|
///// <param name="model"></param>
|
///// <returns></returns>
|
//[RequestMethod(RequestMethods.POST)]
|
//public ReturnDto<string?> EditModel([FromBody] SysOrganization model)
|
//{
|
// if (UtilityHelper.CheckGuid(model.Guid))
|
// {
|
// int cont = 0;
|
// cont = IsChkOrUnChk(model.Guid.ToString(), true);
|
// if (cont > 0)
|
// return ReturnDto<string>.QuickReturn("", ReturnCode.Exception, "修改失败,该信息已被审核!");
|
// }
|
// if (!UtilityHelper.CheckGuid(model.UpGuid))//只能有一个根组织
|
// {
|
// int cont = 0;
|
// cont = Db.Queryable<SysOrganization>().Where(c => c.UpGuid == null).Count();
|
// if (cont > 0)
|
// {
|
// return ReturnDto<int>.QuickReturn(default(string?), ReturnCode.Exception, "增加失败,请选择上级组织!");
|
// }
|
// }
|
// bool _bl = false;
|
// try
|
// {
|
// if (!UtilityHelper.CheckGuid(model.Guid))
|
// {
|
// model.Guid = Guid.NewGuid();
|
// _bl = base.Insert(model);
|
// }
|
// else
|
// {
|
// // _bl = base.Update(model);
|
// _bl = Db.Updateable(model).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand() > 0 ? true : false;
|
// }
|
// }
|
// catch (Exception ex)
|
// {
|
// LogHelper.Debug(this.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)]
|
[AllowAnonymous]
|
public ReturnDto<SysOrganization> GetModel([FromBody] SysOrganization model)
|
{
|
var m = base.GetById(model.Guid);
|
if (m != null)
|
return ReturnDto<SysDocRule>.QuickReturn(m, ReturnCode.Success,
|
"读取成功!");
|
return ReturnDto<SysDocRule>.QuickReturn(m, ReturnCode.Default,
|
"读取失败!");
|
}
|
|
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;
|
}
|
}
|