134 lines
5.5 KiB
C#
134 lines
5.5 KiB
C#
using BaseOUDAL;
|
|
|
|
namespace YLErp.Modules.MarginModule
|
|
{
|
|
public class MarginCalculationThresholdService : YLBaseService
|
|
{
|
|
public MarginCalculationThresholdService(OptUserInfo userInfo) : base(userInfo)
|
|
{
|
|
}
|
|
public void SaveMarginCalcuThreshold(MarginCalculationThreshold marginCalcuThreshold, bool canCover = false)
|
|
{
|
|
if (marginCalcuThreshold == null)
|
|
{
|
|
throw new ServiceException("无数据");
|
|
}
|
|
if (marginCalcuThreshold.ClientId == 0)
|
|
{
|
|
throw new ServiceException("客户选择必填");
|
|
}
|
|
|
|
if (marginCalcuThreshold.TakeEffectDate == DateTime.MinValue)
|
|
{
|
|
throw new ServiceException("生效日期必填");
|
|
}
|
|
var dbMarginCalcuThreshold = new MarginCalculationThreshold();
|
|
if (marginCalcuThreshold.id != 0)
|
|
{
|
|
dbMarginCalcuThreshold = DbContext.MarginCalculationThreshold.Find(marginCalcuThreshold.id);
|
|
if (dbMarginCalcuThreshold == null)
|
|
{
|
|
throw new ServiceException("未找到该记录");
|
|
}
|
|
dbMarginCalcuThreshold.ClientId = marginCalcuThreshold.ClientId;
|
|
dbMarginCalcuThreshold.TakeEffectDate = marginCalcuThreshold.TakeEffectDate;
|
|
dbMarginCalcuThreshold.MarginCalcuThreshold = marginCalcuThreshold.MarginCalcuThreshold;
|
|
dbMarginCalcuThreshold.OptId = UserId;
|
|
dbMarginCalcuThreshold.OptName = UserName;
|
|
dbMarginCalcuThreshold.OptDate = DateTime.Now;
|
|
if (DbContext.MarginCalculationThreshold.Any(o =>
|
|
o.ClientId == dbMarginCalcuThreshold.ClientId
|
|
&& o.TakeEffectDate == dbMarginCalcuThreshold.TakeEffectDate
|
|
&& o.id != dbMarginCalcuThreshold.id))
|
|
{
|
|
throw new ServiceException("同一客户不支持在同一天有多条记录");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbMarginCalcuThreshold = DbContext.MarginCalculationThreshold.Where(o =>
|
|
o.ClientId == marginCalcuThreshold.ClientId
|
|
&& o.TakeEffectDate == marginCalcuThreshold.TakeEffectDate).FirstOrDefault();
|
|
if (dbMarginCalcuThreshold == null)
|
|
{
|
|
dbMarginCalcuThreshold = new MarginCalculationThreshold();
|
|
dbMarginCalcuThreshold.ClientId = marginCalcuThreshold.ClientId;
|
|
dbMarginCalcuThreshold.TakeEffectDate = marginCalcuThreshold.TakeEffectDate;
|
|
dbMarginCalcuThreshold.MarginCalcuThreshold = marginCalcuThreshold.MarginCalcuThreshold;
|
|
dbMarginCalcuThreshold.OptId = UserId;
|
|
dbMarginCalcuThreshold.OptName = UserName;
|
|
dbMarginCalcuThreshold.OptDate = DateTime.Now;
|
|
DbContext.MarginCalculationThreshold.Add(dbMarginCalcuThreshold);
|
|
}
|
|
else if (canCover)
|
|
{
|
|
dbMarginCalcuThreshold.OptId = UserId;
|
|
dbMarginCalcuThreshold.OptName = UserName;
|
|
dbMarginCalcuThreshold.OptDate = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
throw new ServiceException("同一客户不支持在同一天有多条记录");
|
|
}
|
|
}
|
|
|
|
DbContext.SaveChanges();
|
|
}
|
|
public void DeleteMarginCalculationThreshold(int id)
|
|
{
|
|
var model = DbContext.MarginCalculationThreshold.FirstOrDefault(l => l.id == id);
|
|
if (model == null) throw new ServiceException("找不到该条数据");
|
|
else
|
|
{
|
|
DbContext.MarginCalculationThreshold.Remove(model);
|
|
}
|
|
DbContext.SaveChanges();
|
|
}
|
|
public SearchListResult<MarginCalculationThreshold> SearchList(MarginCalculationThresholdReq req)
|
|
{
|
|
|
|
var query = from source in DbContext.MarginCalculationThreshold select source;
|
|
if (req.ClientId > 0)
|
|
{
|
|
query = query.Where(o => o.ClientId == req.ClientId);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(req.ThresholdStart))
|
|
{
|
|
if (double.TryParse(req.ThresholdStart, out var a))
|
|
{
|
|
query = query.Where(o => o.MarginCalcuThreshold >= a);
|
|
}
|
|
else
|
|
{
|
|
throw new ServiceException("请输入正确的数值格式");
|
|
}
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(req.ThresholdEnd))
|
|
{
|
|
if (double.TryParse(req.ThresholdEnd, out var b))
|
|
{
|
|
query = query.Where(o => o.MarginCalcuThreshold <= b);
|
|
}
|
|
else
|
|
{
|
|
throw new ServiceException("请输入正确的数值格式");
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(req.sidx))
|
|
{
|
|
req.sidx = "id";
|
|
req.sord = "desc";
|
|
}
|
|
|
|
return query.ToSearchList(req);
|
|
}
|
|
|
|
public class MarginCalculationThresholdReq : BaseSearchReq
|
|
{
|
|
public int ClientId { get; set; }
|
|
public string ThresholdStart { get; set; }
|
|
public string ThresholdEnd { get; set; }
|
|
}
|
|
}
|
|
}
|