using Gs.Entity.BaseInfo; 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 System.Data; using System.Text; namespace Gs.Warehouse.Services; [ApiGroup(ApiGroupNames.PerMission)] public class MesDepotSectionsManager : Repository, IRomteService { private readonly IHttpContextAccessor _http; private readonly string _userCode, _userGuid, _orgFids; public MesDepotSectionsManager() { //_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 queryBase = Db.Queryable() .LeftJoin((a, b) => a.Guid == b.DepotGuid); //.LeftJoin((a, b, c) => a.FSubsidiary == c.Fid) //.LeftJoin((a, b, c, d) => a.CreateBy == d.Id.ToString()) //.LeftJoin((a, b, c, d, e) => e.Id.ToString() == a.ClientId) //.LeftJoin((a, b, c, d, e, f) => f.Id.ToString() == a.SuppLierId) //.LeftJoin((a, b, c, d, e, f, g) => g.Id.ToString() == a.department); // 然后进行选择和分页 var itemsList = queryBase.Select((a, b) => new MesDepotSections { Guid = b.Guid, DepotSectionCode = b.DepotSectionCode, DepotSectionName = b.DepotSectionName }) .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> GetListPage2(PageQuery model) { var currentPage = model.currentPage; var everyPageSize = model.everyPageSize; var sortName = string.IsNullOrEmpty(model.sortName) ? "a.USER_NAME" : model.sortName; var keyWhere = model.keyWhere; string keyType = model.keyType; System.Text.StringBuilder sbJoin = new StringBuilder(); sbJoin.Append(" from [dbo].[MES_DEPOT_SECTIONS] a "); sbJoin.Append(" left join [dbo].[MES_DEPOTS] d on a.depot_guid=d.depot_id"); sbJoin.Append(" left join SYS_ORGANIZATION org on d.FSubsidiary=org.FID"); sbJoin.Append(keyWhere); var sbSql = new StringBuilder(); sbSql.Append(" SELECT * FROM "); sbSql.Append(" (SELECT N'(' +[Org].[FNumber] + N')' +[Org].[NAME] AS [FSubsidiary2]"); sbSql.Append(", a.depot_section_code as cwCode,a.depot_section_name as cwName,d.depot_name as ckName,d.depot_id as ckId,d.depot_code as ckCode ,ROW_NUMBER() OVER(ORDER BY a.depot_section_code asc) AS RowIndex "); //如果无关键字,无需找查绑定 if (string.IsNullOrEmpty(keyType)) { sbSql.Append(",cast(0 as bit) as chkInt"); } else sbSql.Append(",cast( (select count(1) from SYS_USER_BIND bind where bind.userGuid='" + keyType + "' and bind.aboutGuid=a.depot_section_code and bind.fType='库位') as bit) as chkInt "); sbSql.Append(sbJoin); sbSql.Append(") T"); sbSql.Append(" where T.rowindex>(" + currentPage + "-1)*" + everyPageSize + " and T.rowindex<=" + currentPage + "*" + everyPageSize); sbSql.Append(" select count(1) as intTotal "); sbSql.Append(sbJoin); var dset = new DataSet(); try { dset = DbHelperSQL.Query(sbSql.ToString()); } catch (Exception ex) { LogHelper.Debug(ToString(), "GetListPage error:" + ex.Message); return ReturnDto>.QuickReturn(default(PageList), ReturnCode.Exception, "读取失败"); } var _pglist = new PageList { total = 0, everyPageSize = 0, pages = 0, list = new List() }; if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0) //有数据 { var intTotal = int.Parse(dset.Tables[1].Rows[0]["intTotal"].ToString()); var pages = intTotal % everyPageSize != 0 ? intTotal / everyPageSize + 1 : intTotal / everyPageSize; _pglist.total = intTotal; _pglist.everyPageSize = everyPageSize; _pglist.pages = pages; var _dy = dset.Tables[0].TableToDynamicList(); _pglist.list = _dy; } return ReturnDto>.QuickReturn(_pglist, ReturnCode.Success, "读取成功"); } }