using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Reflection;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_Core.Utilities;
|
using WIDESEA_ISystemRepository;
|
using WIDESEA_ISystemService;
|
using WIDESEA_Model.Models.System;
|
|
namespace WIDESEA_SystemService
|
{
|
public class Dt_palletService : ServiceBase<Dt_pallet, IDt_palletRepository>, IDt_palletService
|
{
|
public Dt_palletService(IDt_palletRepository BaseDal) : base(BaseDal)
|
{
|
}
|
|
public IDt_palletRepository Repository => BaseDal;
|
|
public WebResponseContent SetCacheList()
|
{
|
var data = BaseDal.QueryData().Select(x => new { x.palletname, x.palletnumber }).Distinct().ToList();
|
return WebResponseContent.Instance.OK(data: data);
|
}
|
|
/// <summary>
|
/// 添加数据
|
/// </summary>
|
/// <param name="saveModel"></param>
|
/// <returns></returns>
|
public virtual WebResponseContent AddData(SaveModel saveModel)
|
{
|
try
|
{
|
if (saveModel == null || saveModel.MainData == null || saveModel.MainData.Count == 0)//判断参数是否传入
|
{
|
return WebResponseContent.Instance.Error("传参错误,参数不能为空");
|
}
|
string validResult = typeof(Dt_pallet).ValidateDicInEntity(saveModel.MainData, true, TProperties);
|
|
if (!string.IsNullOrEmpty(validResult))
|
{
|
return WebResponseContent.Instance.Error(validResult);
|
}
|
|
PropertyInfo keyPro = typeof(Dt_pallet).GetKeyProperty();
|
if (keyPro == null)
|
{
|
return WebResponseContent.Instance.Error("请先设置主键");
|
}
|
if (keyPro.PropertyType == typeof(Guid))
|
{
|
saveModel.MainData.Add(keyPro.Name, Guid.NewGuid());
|
}
|
else if (keyPro.PropertyType == typeof(int) || keyPro.PropertyType == typeof(long))
|
{
|
SugarColumn? sugarColumn = keyPro.GetCustomAttribute<SugarColumn>();
|
if (sugarColumn?.IsIdentity ?? true)
|
{
|
saveModel.MainData.Remove(keyPro.Name.FirstLetterToUpper());
|
saveModel.MainData.Remove(keyPro.Name.FirstLetterToLower());
|
}
|
}
|
Dt_pallet entity = saveModel.MainData.DicToModel<Dt_pallet>();
|
|
List<Dt_pallet> dt_Pallet = BaseDal.QueryData(x => x.palletnumber == entity.palletnumber).ToList();
|
if(dt_Pallet.Count > 0)
|
{
|
return WebResponseContent.Instance.Error("已添加该类型编号!!!");
|
}
|
List<Dt_pallet> dt_Pallet2 = BaseDal.QueryData(x => x.palletname == entity.palletname).ToList();
|
if (dt_Pallet2.Count > 0)
|
{
|
return WebResponseContent.Instance.Error("已添加该类型名称!!!");
|
}
|
|
if (saveModel.DetailData == null || saveModel.DetailData.Count == 0)
|
{
|
BaseDal.AddData(entity);
|
return WebResponseContent.Instance.OK();
|
}
|
|
if (typeof(Dt_pallet).GetNavigatePro() == null)
|
{
|
return WebResponseContent.Instance.Error("未配置导航属性");
|
}
|
|
Type detailType = typeof(Dt_pallet).GetDetailType();
|
MethodInfo? methodInfo = GetType().GetMethod("AddDataIncludesDetail");
|
methodInfo = methodInfo?.MakeGenericMethod(new Type[] { detailType });
|
object? obj = methodInfo?.Invoke(this, new object[] { entity, detailType, saveModel.DetailData });
|
return obj as WebResponseContent;
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
}
|
}
|