|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Data;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.WMS.Core.Code.Dtos;
|
|
|
|
|
using DS.WMS.Core.Code.Entity;
|
|
|
|
|
using DS.WMS.Core.Info.Dtos;
|
|
|
|
|
using DS.WMS.Core.Info.Interface;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
|
using Mapster;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Info.Method
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 客户参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ClientParamService : ServiceBase, IClientParamService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
|
public ClientParamService(IServiceProvider serviceProvider) : base(serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取客户参数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T">参数值的类型</typeparam>
|
|
|
|
|
/// <param name="businessId">业务ID</param>
|
|
|
|
|
/// <param name="paramName">参数名</param>
|
|
|
|
|
/// <param name="joinExpression">客户类别连接条件</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<Param<T>> GetParamAsync<T>(long businessId, string paramName,
|
|
|
|
|
Expression<Func<InfoClientParam, SeaExport, bool>> joinExpression)
|
|
|
|
|
{
|
|
|
|
|
Param<T?> param = new() { Name = paramName };
|
|
|
|
|
var model = await TenantDb.Queryable<InfoClientParam>()
|
|
|
|
|
.InnerJoin(joinExpression)
|
|
|
|
|
.Where((x, y) => y.Id == businessId && x.ParamCode == paramName)
|
|
|
|
|
.Select((x, y) => new
|
|
|
|
|
{
|
|
|
|
|
x.ItemCode,
|
|
|
|
|
x.ItemName
|
|
|
|
|
}).FirstAsync();
|
|
|
|
|
|
|
|
|
|
param.DisplayValue = model?.ItemName;
|
|
|
|
|
if (model == null)
|
|
|
|
|
return param;
|
|
|
|
|
|
|
|
|
|
var type = typeof(T);
|
|
|
|
|
var targetType = Nullable.GetUnderlyingType(type);
|
|
|
|
|
if (targetType != null)
|
|
|
|
|
type = targetType;
|
|
|
|
|
|
|
|
|
|
if (type.IsEnum && Enum.TryParse(type, model.ItemCode, true, out object? enumValue)) //枚举特殊处理
|
|
|
|
|
{
|
|
|
|
|
param.Value = (T)enumValue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
param.Value = (T)Convert.ChangeType(model.ItemCode, type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return param;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<List<ClientParamRes>> GetListByPage(PageRequest request)
|
|
|
|
|
{
|
|
|
|
|
//序列化查询条件
|
|
|
|
|
var whereList = request.GetConditionalModels(Db);
|
|
|
|
|
var data = TenantDb.Queryable<InfoClientParam>()
|
|
|
|
|
.Where(whereList)
|
|
|
|
|
.Select<ClientParamRes>().ToQueryPage(request.PageCondition);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 编辑
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult EditClientParam(ClientParamReq req)
|
|
|
|
|
{
|
|
|
|
|
if (req.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (TenantDb.Queryable<InfoClientParam>().Where(x => x.ParamId == req.ParamId && x.CustomerId == req.CustomerId).Any())
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("往来单位参数已存在!", MultiLanguageConst.ClientParamExist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var data = req.Adapt<InfoClientParam>();
|
|
|
|
|
|
|
|
|
|
var entity = TenantDb.Insertable(data).ExecuteReturnEntity();
|
|
|
|
|
|
|
|
|
|
return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var info = TenantDb.Queryable<InfoClientParam>().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<ClientParamRes> GetClientParamInfo(string id)
|
|
|
|
|
{
|
|
|
|
|
var data = TenantDb.Queryable<InfoClientParam>()
|
|
|
|
|
.Where(a => a.Id == long.Parse(id))
|
|
|
|
|
.Select<ClientParamRes>()
|
|
|
|
|
.First();
|
|
|
|
|
return DataResult<ClientParamRes>.Success(data, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DataResult BatchDelClientParam(IdModel req)
|
|
|
|
|
{
|
|
|
|
|
var list = TenantDb.Queryable<InfoClientParam>().Where(x => req.Ids.Contains(x.Id)).ToList();
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
TenantDb.Deleteable(list).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DataResult<List<TenantParamSelectRes>> GetTenantParamSelectList()
|
|
|
|
|
{
|
|
|
|
|
var data = Db.Queryable<SysTenantParam>().Where(x => x.Status == StatusEnum.Enable)
|
|
|
|
|
.Select<TenantParamSelectRes>()
|
|
|
|
|
.ToList();
|
|
|
|
|
return DataResult<List<TenantParamSelectRes>>.Success(data, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DataResult<List<TenantParamDataSelectRes>> GetTenantParamDataSelectList(string code = "")
|
|
|
|
|
{
|
|
|
|
|
var data = Db.Queryable<SysTenantParamData>().Where(x => x.Status == StatusEnum.Enable)
|
|
|
|
|
.WhereIF(code.IsNotEmptyOrNull(), x => x.ParamCode.ToLower() == code.ToLower())
|
|
|
|
|
.Select<TenantParamDataSelectRes>()
|
|
|
|
|
.ToList();
|
|
|
|
|
return DataResult<List<TenantParamDataSelectRes>>.Success(data, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|