using 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.MengQi
|
{
|
/// <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 Biz.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 Biz.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 = Biz.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 = Biz.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;
|
}
|
}
|
}
|