namespace Yw.CAL.LocalClient
|
{
|
/// <summary>
|
/// 单位类型
|
/// </summary>
|
public partial class SysUnitType : ISysUnitType
|
{
|
private readonly Yw.Service.SysUnitType _service = new();
|
|
|
#region Query
|
|
/// <summary>
|
/// 获取所有
|
/// </summary>
|
public async Task<List<SysUnitTypeDto>> GetAll()
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var list = _service.GetAll();
|
var vm_list = list?.Select(x => new SysUnitTypeDto(x)).ToList();
|
return vm_list;
|
});
|
}
|
|
/// <summary>
|
/// 通过 ID 获取
|
/// </summary>
|
public async Task<SysUnitTypeDto> GetByID(long ID)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var model = _service.GetByID(ID);
|
return model == null ? null : new SysUnitTypeDto(model);
|
});
|
}
|
|
/// <summary>
|
/// 通过 Ids 获取
|
/// </summary>
|
public async Task<List<SysUnitTypeDto>> GetByIds(List<long> Ids)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var list = _service.GetByIds(Ids);
|
var vm_list = list?.Select(x => new SysUnitTypeDto(x)).ToList();
|
return vm_list;
|
});
|
}
|
|
#endregion
|
|
#region Insert
|
|
/// <summary>
|
/// 插入一条
|
/// </summary>
|
public async Task<long> Insert(AddSysUnitTypeInput input)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
if (_service.IsExistCode(input.Code))
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"Code:{input.Code} 编码已存在");
|
}
|
var model = input.Adapt<AddSysUnitTypeInput, Model.SysUnitType>();
|
model.SortCode = _service.GetMaxSortCode() + 1;
|
var id = _service.Insert(model);
|
return id;
|
});
|
}
|
|
/// <summary>
|
/// 批量插入
|
/// </summary>
|
public async Task<bool> Inserts(List<AddSysUnitTypeInput> inputList)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var list = inputList.Select(x => x.Adapt<AddSysUnitTypeInput, Model.SysUnitType>()).ToList();
|
list.ForEach(x =>
|
{
|
x.SortCode = _service.GetMaxSortCode() + 1 + list.IndexOf(x);
|
});
|
var bol = _service.Inserts(list);
|
return bol;
|
});
|
}
|
|
/// <summary>
|
/// 大批量插入
|
/// </summary>
|
public async Task<bool> BulkInserts(List<AddSysUnitTypeInput> list)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
return false;
|
});
|
}
|
|
#endregion
|
|
#region Update
|
|
/// <summary>
|
/// 更新一条
|
/// </summary>
|
public async Task<bool> Update(UpdateSysUnitTypeInput input)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var model = _service.GetByID(input.ID);
|
if (model == null)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D001, $"ID:{input.ID} 数据不存在");
|
}
|
|
if (_service.IsExistCodeExceptID(input.Code, input.ID))
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.V001, $"Code:{input.Code} 编码已存在");
|
}
|
|
var rhs = new Model.SysUnitType(model);
|
input.Adapt(rhs);
|
var bol = _service.Update(rhs);
|
return bol;
|
});
|
}
|
|
/// <summary>
|
/// 批量更新
|
/// </summary>
|
public async Task<bool> Updates(List<UpdateSysUnitTypeInput> inputList)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
if (inputList == null || inputList.Count < 1)
|
{
|
return false;
|
}
|
var list = inputList.Select(x => x.Adapt<UpdateSysUnitTypeInput, Model.SysUnitType>()).ToList();
|
var bol = _service.Updates(list);
|
return bol;
|
});
|
}
|
|
/// <summary>
|
/// 大批量更新
|
/// </summary>
|
public async Task<bool> BulkUpdates(List<UpdateSysUnitTypeInput> list)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
return false;
|
});
|
}
|
|
/// <summary>
|
/// 更新编码
|
/// </summary>
|
public async Task<bool> UpdateCode(long ID, string Code)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
return false;
|
});
|
}
|
|
/// <summary>
|
/// 更新排序码
|
/// </summary>
|
public async Task<bool> UpdateSortCode(long ID, int SortCode)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var bol = _service.UpdateSortCode(ID, SortCode);
|
return bol;
|
});
|
}
|
|
/// <summary>
|
/// 更新排序
|
/// </summary>
|
public async Task<bool> UpdateSorter(List<UpdateSortCodeInput> inputList)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var list = inputList.Select(x => x.Adapt<Model.Sorter>()).ToList();
|
var bol = _service.UpdateSorter(list);
|
return bol;
|
});
|
}
|
|
#endregion
|
|
#region Exist
|
|
/// <summary>
|
/// 判断 Code 是否存在
|
/// </summary>
|
public async Task<bool> IsExistCode(string Code)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var bol = _service.IsExistCode(Code);
|
return bol;
|
});
|
}
|
|
/// <summary>
|
/// 判断 Code 是否存在 ExceptID
|
/// </summary>
|
public async Task<bool> IsExistCodeExceptID(string Code, long ExceptID)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var bol = _service.IsExistCodeExceptID(Code, ExceptID);
|
return bol;
|
});
|
}
|
|
#endregion
|
|
#region Delete
|
|
/// <summary>
|
/// 通过 ID 删除
|
/// </summary>
|
public async Task<bool> DeleteByID(long ID)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
var bol = _service.DeleteByID(ID, out string msg);
|
if (!bol)
|
{
|
throw YOops.Oh(eResultCode.Alert, InternalErrorCodes.D999, msg);
|
}
|
return true;
|
});
|
}
|
|
/// <summary>
|
/// 通过 Ids 删除
|
/// </summary>
|
public async Task<bool> DeleteByIds(List<long> Ids)
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
return false;
|
});
|
}
|
|
|
/// <summary>
|
/// 删除全部
|
/// </summary>
|
/// <returns></returns>
|
public async Task<bool> DeleteAll()
|
{
|
return await Task.Factory.StartNew(() =>
|
{
|
return false;
|
});
|
}
|
|
#endregion
|
|
|
}
|
}
|