服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-04-18 c701f4c3a21a159e9b1efcfc6e9c4769e87b1e6f
Tiger.Business/WMS/MengQi/Biz.Mq.Customer.cs
@@ -1,4 +1,5 @@
using Rhea.Common;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
@@ -18,6 +19,28 @@
        public partial class MqCustomer : ICustomer
        {
            /// <summary>
            /// 获取分页
            /// </summary>
            /// <param name="pageList"></param>
            /// <returns></returns>
            public async Task<ApiAction<PageAble<Customer>>> GetCustomers(PageAble<Customer> pageList)
            {
                var res = new ApiAction<PageAble<Customer>>();
                try
                {
                    RefAsync<int> total = 0;
                    pageList.data = await Db.Queryable<Customer>().WhereIF(!string.IsNullOrEmpty(pageList.sqlcmd), x => x.CustomerCode.Contains(pageList.sqlcmd)).OrderBy(x=>x.CustomerCode).ToPageListAsync(pageList.pageIndex, pageList.pageSize, total);
                    pageList.totals = total;
                }
                catch (Exception ex)
                {
                    res.CatchExceptionWithLog(ex, "获取客户信息异常");
                }
                res.Data = pageList;
                return res;
            }
            /// <summary>
            /// 获取客户信息
            /// </summary>
            /// <returns></returns>
@@ -36,9 +59,54 @@
                return res;
            }
            public async Task<Result> SaveImportCustomerInfo(DataTable dt)
            public async Task<ApiAction> SaveImportCustomerInfo(List<Customer> list)
            {
                throw new NotImplementedException();
                var res = new ApiAction();
                //更新客户记录
                var db = Db;
                var dbTran = await db.UseTranAsync(async () =>
                {
                    await db.Saveable(list).ExecuteCommandAsync();
                });
                if (!dbTran.IsSuccess)
                {
                    res.IsSuccessed = false;
                    res.Message = $"导入异常";
                }
                return res;
            }
            /// <summary>
            /// 保存客户
            /// </summary>
            /// <param name="user"></param>
            /// <returns></returns>
            public async Task<ApiAction> SaveCustomer(Customer customer)
            {
                var result = new ApiAction();
                try
                {
                    var db = Db;
                    var dbTran = db.UseTran(() =>
                    {
                        var y = db.Storageable(customer)
                           .WhereColumns(t => new { t.CustomerCode })
                           .ToStorage();
                        y.AsInsertable.ExecuteCommand();
                        y.AsUpdateable.ExecuteCommand();
                    });
                    if (!dbTran.IsSuccess)
                    {
                        result.IsSuccessed = false;
                        result.Message = $"导入异常";
                    }
                }
                catch (Exception ex)
                {
                    result.CatchExceptionWithLog(ex, "保存客户异常");
                }
                return result;
            }
        }
    }