1
This commit is contained in:
14
EquipMgr/Tnb.EquipMgr.Entities/Dto/BaseInput.cs
Normal file
14
EquipMgr/Tnb.EquipMgr.Entities/Dto/BaseInput.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Tnb.EquipMgr.Entities.Dto
|
||||||
|
{
|
||||||
|
public class BaseInput
|
||||||
|
{
|
||||||
|
public string item_group_id { get; set; }
|
||||||
|
public List<string> ids { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ namespace Tnb.EquipMgr.Entities.Dto
|
|||||||
{
|
{
|
||||||
public class RelevanceMoldListOutput
|
public class RelevanceMoldListOutput
|
||||||
{
|
{
|
||||||
|
public string mold_id { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Desc:模具编号
|
/// Desc:模具编号
|
||||||
/// Default:NULL::character varying
|
/// Default:NULL::character varying
|
||||||
|
|||||||
@@ -9,15 +9,7 @@ namespace Tnb.EquipMgr.Entities.Dto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 关联保养组与模具输入参数
|
/// 关联保养组与模具输入参数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MoldMaintainGroupItemRelationInput
|
public class MoldMaintainGroupItemRelationInput :BaseInput
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 项目组Id
|
|
||||||
/// </summary>
|
|
||||||
public string item_group_id { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// 模具Id
|
|
||||||
/// </summary>
|
|
||||||
public string mold_id { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,16 +9,8 @@ namespace Tnb.EquipMgr.Entities.Dto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模具保养项输入参数
|
/// 模具保养项输入参数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MoldMaintainGroupItemInput
|
public class MoldMaintainGroupItemInput : BaseInput
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 项目组Id
|
|
||||||
/// </summary>
|
|
||||||
public string item_group_id { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// 保养项Id
|
|
||||||
/// </summary>
|
|
||||||
public string item_id { get; set; }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ namespace Tnb.EquipMgr.Entities.Dto
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class MoldMaintainItemListOutput
|
public class MoldMaintainItemListOutput
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 检查项Id
|
||||||
|
/// </summary>
|
||||||
|
public string item_id { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 项目名称
|
/// 项目名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ namespace Tnb.EquipMgr.Entities.Mapper
|
|||||||
{
|
{
|
||||||
public void Register(TypeAdapterConfig config)
|
public void Register(TypeAdapterConfig config)
|
||||||
{
|
{
|
||||||
|
config.ForType<MoldMaintenance, MoldMaintainItemListOutput>()
|
||||||
|
.Map(dest => dest.item_id, src => src.id);
|
||||||
|
config.ForType<ToolMolds, RelevanceMoldListOutput>()
|
||||||
|
.Map(dest => dest.mold_id, src => src.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Aspose.Cells.Drawing;
|
using Aspose.Cells.Drawing;
|
||||||
@@ -12,6 +14,9 @@ using JNPF.DynamicApiController;
|
|||||||
using JNPF.FriendlyException;
|
using JNPF.FriendlyException;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using NPOI.SS.Formula.Functions;
|
||||||
|
using Qiniu.Util;
|
||||||
|
using Spire.Pdf.Widget;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Tnb.Common.Contracts;
|
using Tnb.Common.Contracts;
|
||||||
using Tnb.EquipMgr.Entities;
|
using Tnb.EquipMgr.Entities;
|
||||||
@@ -82,7 +87,7 @@ namespace Tnb.EquipMgr
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task RelevanceMaintianGroupAndItem(MoldMaintainGroupItemInput input) =>
|
public async Task RelevanceMaintianGroupAndItem(MoldMaintainGroupItemInput input) =>
|
||||||
await Relevance<MoldMaintainGroupItemInput, ToolMoldMaintainGroupItem>(input);
|
await Relevance<MoldMaintainGroupItemInput, ToolMoldMaintainGroupItem>(input, nameof(ToolMoldMaintainGroupItem.item_id), it => it.item_group_id == input.item_group_id);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 关联项目组与模具
|
/// 关联项目组与模具
|
||||||
@@ -91,20 +96,64 @@ namespace Tnb.EquipMgr
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task RelevanceMaintianGroupAndMold(MoldMaintainGroupItemRelationInput input) =>
|
public async Task RelevanceMaintianGroupAndMold(MoldMaintainGroupItemRelationInput input) =>
|
||||||
await Relevance<MoldMaintainGroupItemRelationInput, ToolMoldMaintainGroupRelation>(input);
|
await Relevance<MoldMaintainGroupItemRelationInput, ToolMoldMaintainGroupRelation>(input, nameof(ToolMoldMaintainGroupRelation.mold_id), it => it.item_group_id == input.item_group_id);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private async Task Relevance<TSrc, TDest>(TSrc input) where TDest : BaseEntity<string>, new()
|
private async Task Relevance<TSrc, TDest>(TSrc input, string name, Expression<Func<TDest, bool>> deleleExp) where TDest : BaseEntity<string>, new()
|
||||||
|
where TSrc : BaseInput
|
||||||
{
|
{
|
||||||
|
|
||||||
|
await _db.Deleteable<TDest>().Where(deleleExp).ExecuteCommandAsync();
|
||||||
|
var itemGroupId = nameof(ToolMoldMaintainGroupRelation.item_group_id);
|
||||||
if (input == null) throw new ArgumentNullException(nameof(input));
|
if (input == null) throw new ArgumentNullException(nameof(input));
|
||||||
var entity = input.Adapt<TDest>();
|
var entities = new List<TDest>();
|
||||||
entity.id = SnowflakeIdHelper.NextId();
|
if (input.ids?.Count > 0)
|
||||||
var row = await _db.Insertable(entity).ExecuteCommandAsync();
|
{
|
||||||
|
foreach (var id in input.ids)
|
||||||
|
{
|
||||||
|
var pk = id;
|
||||||
|
TDest entity = new();
|
||||||
|
entity.id = SnowflakeIdHelper.NextId();
|
||||||
|
if (!PropertySet<TDest>.ValueFactories.TryGetValue(itemGroupId, out Action<object, object> setGroupIdAction))
|
||||||
|
{
|
||||||
|
setGroupIdAction = PropertySet<TDest>.CreateSetPropertyValueAction(itemGroupId);
|
||||||
|
PropertySet<TDest>.ValueFactories.Add(itemGroupId, setGroupIdAction);
|
||||||
|
}
|
||||||
|
setGroupIdAction(entity, input.item_group_id);
|
||||||
|
if (!PropertySet<TDest>.ValueFactories.TryGetValue(name, out Action<object, object> setAction))
|
||||||
|
{
|
||||||
|
setAction = PropertySet<TDest>.CreateSetPropertyValueAction(name);
|
||||||
|
PropertySet<TDest>.ValueFactories.Add(name, setAction);
|
||||||
|
}
|
||||||
|
setAction(entity, pk);
|
||||||
|
entities.Add(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var row = await _db.Insertable(entities).ExecuteCommandAsync();
|
||||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
|
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class PropertySet<T>
|
||||||
|
{
|
||||||
|
public static Dictionary<string, Action<object, object>> ValueFactories = new Dictionary<string, Action<object, object>>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
public static Action<object, object> CreateSetPropertyValueAction(string propertyName)
|
||||||
|
{
|
||||||
|
var property = typeof(T).GetProperty(propertyName);
|
||||||
|
var target = Expression.Parameter(typeof(object));
|
||||||
|
var propertyValue = Expression.Parameter(typeof(object));
|
||||||
|
var castTarget = Expression.Convert(target, typeof(T));
|
||||||
|
var castPropertyValue = Expression.Convert(propertyValue, property.PropertyType);
|
||||||
|
var setPropertyValue = Expression.Call(castTarget, property.GetSetMethod(), castPropertyValue);
|
||||||
|
return Expression.Lambda<Action<object, object>>(setPropertyValue, target, propertyValue).Compile();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user