/*
|
*所有关于Dt_selection_standards类的业务代码应在此处编写
|
*可使用repository.调用常用方法,获取EF/Dapper等信息
|
*如果需要事务请使用repository.DbContextBeginTransaction
|
*也可使用DBServerProvider.手动获取数据库相关信息
|
*用户信息、权限、角色等使用UserContext.Current操作
|
*Dt_selection_standardsService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
|
*/
|
using WIDESEA.Core.BaseProvider;
|
using WIDESEA.Core.Extensions.AutofacManager;
|
using WIDESEA.Entity.DomainModels;
|
using System.Linq;
|
using WIDESEA.Core.Utilities;
|
using System.Linq.Expressions;
|
using WIDESEA.Core.Extensions;
|
using Microsoft.EntityFrameworkCore;
|
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.AspNetCore.Http;
|
using WIDESEA.Services.IRepositories;
|
using Microsoft.Extensions.Caching.Memory;
|
using System;
|
using HttpContext = WIDESEA.Core.Utilities.HttpContext;
|
using WIDESEA.Services.Repositories;
|
using WIDESEA.Core.ManageUser;
|
using System.Collections.Generic;
|
using WIDESEA_Common.LogEnum;
|
|
namespace WIDESEA.Services.Services
|
{
|
public partial class Dt_selection_standardsService
|
{
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IDt_selection_standardsRepository _repository;//访问数据库
|
|
[ActivatorUtilitiesConstructor]
|
public Dt_selection_standardsService(
|
IDt_selection_standardsRepository dbRepository,
|
IHttpContextAccessor httpContextAccessor
|
)
|
: base(dbRepository)
|
{
|
_httpContextAccessor = httpContextAccessor;
|
_repository = dbRepository;
|
//多租户会用到这init代码,其他情况可以不用
|
//base.Init(dbRepository);
|
}
|
|
|
public override WebResponseContent Add(SaveModel saveDataModel)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
saveDataModel.MainData.Add("selection_create_date", DateTime.Now);
|
saveDataModel.MainData.Add("selection_creator", UserContext.Current.UserTrueName);
|
string materielId = saveDataModel.MainData["selection_carId"]?.ToString();
|
string materielMode = saveDataModel.MainData["selection_zcId"]?.ToString();
|
string manufact = saveDataModel.MainData["selection_zc_manufacturer"]?.ToString();
|
//选配类型
|
string standardtype = saveDataModel.MainData["selection_standard_type"]?.ToString();
|
//检修类型
|
string selection_zc_type = saveDataModel.MainData["selection_zc_type"]?.ToString();
|
if (repository.Exists(r => r.selection_carId == materielId && r.selection_zcId == materielMode && r.selection_zc_manufacturer == manufact
|
&& r.selection_standard_type == standardtype && r.selection_zc_type == selection_zc_type))
|
return content.Error("不可重复添加当前数据,请重新确认.");
|
//下限值
|
string selection_negative_value = saveDataModel.MainData["selection_negative_value"]?.ToString();
|
//上限制
|
string selection_positive_value = saveDataModel.MainData["selection_positive_value"]?.ToString();
|
if (decimal.Parse(selection_positive_value) < decimal.Parse(selection_negative_value))
|
return content.Error("上限差值不能小于下限差值,请重新确认.");
|
|
content = base.Add(saveDataModel);
|
}
|
catch (Exception ex)
|
{
|
content.Error("添加选配标准失败:" + ex.Message);
|
}
|
return content;
|
}
|
|
public override WebResponseContent Update(SaveModel saveDataModel)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
saveDataModel.MainData.Add("selection_modify_date", DateTime.Now);
|
saveDataModel.MainData.Add("selection_modifyor", UserContext.Current.UserTrueName);
|
return base.Update(saveDataModel);
|
}
|
catch (Exception ex)
|
{
|
content.Error("修改选配标准失败:" + ex.Message);
|
}
|
return content;
|
}
|
|
|
public override WebResponseContent Del(object[] keys, bool delList = true)
|
{
|
List<Guid> listKeys = new List<Guid>();
|
foreach (var item in keys)
|
{
|
listKeys.Add(Guid.Parse(item.ToString()));
|
}
|
List<Dt_selection_standards> listMateriel = repository.Find(r => listKeys.Contains(r.selection_id));
|
LogRecord.WriteLog((int)LogEnum.System, $"{DateTime.Now + UserContext.Current.UserTrueName}->选配标准删除:" + listMateriel.Serialize());
|
//todo 将删除物料添加到历史记录
|
return base.Del(keys, delList);
|
}
|
}
|
}
|