服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-04-12 964a430c977cfc2f539d6b7fab6161827fdd71db
Tiger.Business/WMS/MengQi/Biz.Mq.Customer.cs
对比新文件
@@ -0,0 +1,113 @@
锘縰sing Rhea.Common;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tiger.IBusiness;
using Tiger.Model;
namespace Tiger.Business
{
    public partial class Biz
    {
        /// <summary>
        /// 瀹㈡埛
        /// </summary>
        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>
            public async Task<ApiAction<List<Customer>>> GetCustomerInfo()
            {
                var res = new ApiAction<List<Customer>>();
                try
                {
                    List<Customer> result = await Db.Queryable<Customer>().ToListAsync();
                    res.Data = result;
                }
                catch (Exception ex)
                {
                    res.CatchExceptionWithLog(ex, "鑾峰彇瀹㈡埛淇℃伅寮傚父");
                }
                return res;
            }
            public async Task<ApiAction> SaveImportCustomerInfo(List<Customer> list)
            {
                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;
            }
        }
    }
}