wbc
7 天以前 e19f8a13e2b35e6836ce46c17402c44327814a00
WebApi/Gs.Warehouse/Services/MesDepotSectionsManager.cs
@@ -1,11 +1,11 @@
using System.Data;
using System.Text;
using Gs.Entity.BaseInfo;
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;
@@ -16,6 +16,58 @@
    private readonly IHttpContextAccessor _http;
    private readonly string _userCode, _userGuid, _orgFids;
    public MesDepotSectionsManager()
    {
        //_http = httpContextAccessor;
        //(_userCode, _userGuid, _orgFids) =
        //    UtilityHelper.GetUserGuidAndOrgGuid(_http);
    }
      /// <summary>
    ///     查询列表,支持分页
    /// </summary>
    /// <param name="query"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<PageList<MesDepotSections>> GetListPage(PageQuery query)
    {
        var pageList = new PageList<MesDepotSections>();
        try
        {
            var _sbWhere = new StringBuilder(" 1=1" + query.keyWhere);
            var _sbBy = new StringBuilder(query.sortName + " " + query.sortOrder);
            var totalCount = 0;
            // 先构建基础查询
            var queryBase = Db.Queryable<MesDepots>()
                .LeftJoin<MesDepotSections>((a, b) => a.Guid == b.DepotGuid);
                //.LeftJoin<SysOrganization>((a, b, c) => a.FSubsidiary == c.Fid)
                //.LeftJoin<MesStaff>((a, b, c, d) => a.CreateBy == d.Id.ToString())
                //.LeftJoin<MesCustomer>((a, b, c, d, e) => e.Id.ToString() == a.ClientId)
                //.LeftJoin<MesSupplier>((a, b, c, d, e, f) => f.Id.ToString() == a.SuppLierId)
                //.LeftJoin<SysDepartment>((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<MesDepotSections>(itemsList, totalCount,
                query.everyPageSize);
            return ReturnDto<PageList<MesDepotSections>>.QuickReturn(pageList,
                ReturnCode.Success, "读取成功");
        }
        catch (Exception ex)
        {
            return ReturnDto<PageList<MesDepotSections>>.QuickReturn(pageList,
                ReturnCode.Default, ex.Message);
        }
    }
    /// <summary>
@@ -28,37 +80,28 @@
    {
        var currentPage = model.currentPage;
        var everyPageSize = model.everyPageSize;
        var sortName = string.IsNullOrEmpty(model.sortName)
            ? "a.USER_NAME"
            : model.sortName;
        var sortName = string.IsNullOrEmpty(model.sortName) ? "a.USER_NAME" : model.sortName;
        var keyWhere = model.keyWhere;
        var keyType = model.keyType;
        var sbJoin = new StringBuilder();
        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(" 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 ");
        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(",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(" 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();
@@ -69,10 +112,8 @@
        catch (Exception ex)
        {
            LogHelper.Debug(ToString(), "GetListPage error:" + ex.Message);
            return ReturnDto<PageList<dynamic>>.QuickReturn(
                default(PageList<dynamic>), ReturnCode.Exception, "读取失败");
            return ReturnDto<PageList<dynamic>>.QuickReturn(default(PageList<dynamic>), ReturnCode.Exception, "读取失败");
        }
        var _pglist = new PageList<dynamic>
        {
            total = 0,
@@ -83,8 +124,7 @@
        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 intTotal = int.Parse(dset.Tables[1].Rows[0]["intTotal"].ToString());
            var pages = intTotal % everyPageSize != 0
                ? intTotal / everyPageSize + 1
                : intTotal / everyPageSize;
@@ -94,8 +134,10 @@
            var _dy = dset.Tables[0].TableToDynamicList();
            _pglist.list = _dy;
        }
        return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist,
            ReturnCode.Success, "读取成功");
    }
}