using BPA.KitChen.GroupMeal.Application.Service.Shop.Dtos;
using BPA.KitChen.GroupMeal.Core.Common.Const;
using BPA.KitChen.GroupMeal.Core.Entity;
using BPA.KitChen.GroupMeal.SqlSugar;
using Furion;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Mapster;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace BPA.KitChen.GroupMeal.Application.Service.Shop
{
[ApiDescriptionSettings("店铺管理", Tag = "店铺管理", SplitCamelCase = false)]
public class ShopService : IDynamicApiController, ITransient, IShopService
{
///
/// 分页查询
///
///
///
[HttpPost]
public async Task GetPage(ShopPageDto inputDto)
{
var total = new RefAsync();
var data =await SqlSugarDb.Db.Queryable()
.WhereIF(!string.IsNullOrEmpty(inputDto.Name),x=>x.Name.Contains(inputDto.Name))
.WhereIF(!string.IsNullOrEmpty(inputDto.Phone), x => x.Phone.Contains(inputDto.Phone))
.WhereIF(!string.IsNullOrEmpty(inputDto.OrgId), x => x.OrgId==inputDto.OrgId)
.OrderBy(a => a.CreateAt, OrderByType.Desc)
.ToPageListAsync(inputDto.Current, inputDto.PageSize, total);
return new PageOutDto()
{
Data = data,
Total = total
};
}
public async Task> GetAllList()
{
var data = await SqlSugarDb.Db.Queryable().Where(x=>x.IsDeleted==0).ToListAsync();
return data;
}
///
/// 新增
///
///
///
public async Task Add(ShopCreateOrUpdateDto inputDto)
{
inputDto.Id=Guid.NewGuid().ToString();
var data=await SqlSugarDb.Db.Queryable< ShopEntity >().FirstAsync(x=>x.Name==inputDto.Name);
if (data != null)
{
throw Oops.Oh($"名称重复");
}
var res =await SqlSugarDb.Db.Insertable(inputDto.Adapt()).ExecuteCommandAsync();
return res > 0;
}
///
/// 修改
///
///
///
public async Task Update(ShopCreateOrUpdateDto inputDto)
{
var data = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Id == inputDto.Id);
if (data == null)
{
throw Oops.Oh($"数据不存在");
}
var data2= await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Id != inputDto.Id&&x.Name==inputDto.Name);
if (data2 != null)
{
throw Oops.Oh($"名称存在");
}
data.Name = inputDto.Name;
data.OrgId = inputDto.OrgId;
data.Phone = inputDto.Phone;
var res=await SqlSugarDb.Db.Updateable(data).ExecuteCommandAsync();
return res > 0;
}
public async Task Del(string id)
{
var data = await SqlSugarDb.Db.Queryable().FirstAsync(x => x.Id == id);
var res =await SqlSugarDb.Db.Updateable()
.SetColumns(it => new ShopEntity {IsDeleted=1 })//类只能在表达示里面不能提取
.Where(it => it.Id==id)
.ExecuteCommandAsync();
return res > 0;
}
}
}