You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.0 KiB
C#

using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
using DS.WMS.Core.Info.Dtos;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Info.Interface;
using Mapster;
namespace DS.WMS.Core.Info.Method;
/// <summary>
/// 往来单位联系人
/// </summary>
public class ClientContactService : ServiceBase, IClientContactService
{
/// <summary>
/// 初始化
/// </summary>
/// <param name="serviceProvider"></param>
public ClientContactService(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<ClientContactRes>> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = request.GetConditionalModels(Db);
var data = TenantDb.Queryable<InfoClientContact>()
.Where(whereList)
.Select<ClientContactRes>().ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public DataResult EditClientContact(ClientContactReq req)
{
if (req.Id == 0)
{
if (TenantDb.Queryable<InfoClientContact>().Any(x => x.Name == req.Name && x.Email == req.Email && x.Mobile == req.Mobile))
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.ClientContactExist));
var data = req.Adapt<InfoClientContact>();
var entity = TenantDb.Insertable(data).ExecuteReturnEntity();
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
}
else
{
var info = TenantDb.Queryable<InfoClientContact>().Where(x => x.Id == req.Id).First();
info = req.Adapt(info);
TenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess);
}
}
/// <summary>
/// 详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<ClientContactRes> GetClientContactInfo(string id)
{
var data = TenantDb.Queryable<InfoClientContact>()
.Where(a => a.Id == long.Parse(id))
.Select<ClientContactRes>()
.First();
return DataResult<ClientContactRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
}
/// <summary>
/// 根据ID批量删除
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public async Task<DataResult> DeleteAsync(IdModel model)
{
int rows = await TenantDb.Deleteable<InfoClientContact>().Where(x => model.Ids.Contains(x.Id)).ExecuteCommandAsync();
return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
}