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; /// /// [ApiGroup(ApiGroupNames.Sys)] public class OrganizationController : Repository, IRomteService { private readonly IHttpContextAccessor _http; private readonly string _userCode, _userGuid, _orgFids; public OrganizationController(IHttpContextAccessor httpContextAccessor) { _http = httpContextAccessor; (_userCode, _userGuid, _orgFids) = GetUserGuidAndOrgGuid(_http); } /// /// 查询列表,支持分页 /// /// /// [RequestMethod(RequestMethods.POST)] public ReturnDto> GetListPage(PageQuery query) { string keyWord = query.keyWord; 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); 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>.QuickReturn(pageList, ReturnCode.Success, "读取成功"); } catch (Exception ex) { return ReturnDto>.QuickReturn(pageList, ReturnCode.Default, ex.Message); } } ///// ///// 删除机构 ///// ///// ///// //[RequestMethod(RequestMethods.POST)] //public ReturnDto DeleteModel([FromBody] JArray guidList) //{ // string[] intArray = guidList.ToObject(); // string guid = intArray[0]; // int cont = 0; // cont = IsChkOrUnChk(intArray[0], true); // if (cont > 0) // return ReturnDto.QuickReturn(default(int?), ReturnCode.Exception, "删除失败,该信息已被审核!"); // int? rtnInt = (int)ReturnCode.Default; // int it1 = 0; // int it2 = 0; // cont = Db.Queryable().Where(c => c.Guid == Guid.Parse(guid) && c.IsSys == 1).Count(); // if (cont > 0) // { // return ReturnDto.QuickReturn(default(int?), ReturnCode.Exception, "删除失败,该条目为系统内置,不可删除!"); // } // try // { // Db.Ado.BeginTran(); // it1 = Db.Deleteable().In(guid).ExecuteCommand(); // it2 = Db.Deleteable().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.QuickReturn(rtnInt, ReturnCode.Exception, "删除失败,请重试!"); // } // rtnInt = (it2 + it1); // return ReturnDto.QuickReturn(rtnInt, ReturnCode.Success, "操作成功,共删除" + rtnInt.ToString() + "条数据!"); //} ///// ///// 增加机构 ///// ///// ///// //[RequestMethod(RequestMethods.POST)] //public ReturnDto EditModel([FromBody] SysOrganization model) //{ // if (UtilityHelper.CheckGuid(model.Guid)) // { // int cont = 0; // cont = IsChkOrUnChk(model.Guid.ToString(), true); // if (cont > 0) // return ReturnDto.QuickReturn("", ReturnCode.Exception, "修改失败,该信息已被审核!"); // } // if (!UtilityHelper.CheckGuid(model.UpGuid))//只能有一个根组织 // { // int cont = 0; // cont = Db.Queryable().Where(c => c.UpGuid == null).Count(); // if (cont > 0) // { // return ReturnDto.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.QuickReturn("", ReturnCode.Exception, ex.Message); // } // if (_bl) // return ReturnDto.QuickReturn(model.Guid.ToString(), ReturnCode.Success, "操作成功!"); // return ReturnDto.QuickReturn("", ReturnCode.Exception, "增加失败,请重试!"); //} /// /// 读取机构 /// /// /// [RequestMethod(RequestMethods.POST)] [AllowAnonymous] public ReturnDto GetModel([FromBody] SysOrganization model) { var m = base.GetById(model.Guid); if (m != null) return ReturnDto.QuickReturn(m, ReturnCode.Success, "读取成功!"); return ReturnDto.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; } }