模具保养代码提交
This commit is contained in:
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Tnb.EquipMgr.Entities.Dto
|
namespace Tnb.EquipMgr.Entities.Dto
|
||||||
{
|
{
|
||||||
public class BaseInput
|
public class BaseMoldMaintainInput
|
||||||
{
|
{
|
||||||
public string item_group_id { get; set; }
|
public string item_group_id { get; set; }
|
||||||
public List<string> ids { get; set; }
|
public List<string> ids { get; set; }
|
||||||
@@ -9,7 +9,7 @@ namespace Tnb.EquipMgr.Entities.Dto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模具保养删除参数
|
/// 模具保养删除参数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MoldMaintainDelInput : BaseInput
|
public class MoldMaintainDelInput : BaseMoldMaintainInput
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除的表名
|
/// 删除的表名
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Tnb.EquipMgr.Entities.Dto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 关联保养组与模具输入参数
|
/// 关联保养组与模具输入参数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MoldMaintainGroupItemRelationInput :BaseInput
|
public class MoldMaintainGroupItemRelationInput :BaseMoldMaintainInput
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Tnb.EquipMgr.Entities.Dto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模具保养项输入参数
|
/// 模具保养项输入参数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MoldMaintainGroupItemInput : BaseInput
|
public class MoldMaintainGroupItemInput : BaseMoldMaintainInput
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,15 +9,11 @@ namespace Tnb.EquipMgr.Entities.Dto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模具规则定义,关键模具输入参数
|
/// 模具规则定义,关键模具输入参数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RelevanceMoldInput
|
public class RelevanceMoldInput : BaseMoldMaintainInput
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 规则Id
|
/// 规则Id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? rule_id { get; set; }
|
public string? rule_id { get; set; }
|
||||||
/// <summary>
|
|
||||||
/// 模具Id
|
|
||||||
/// </summary>
|
|
||||||
public string? mold_id { get; set;}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using JNPF.Common.Security;
|
using JNPF.Common.Security;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using Tnb.Common.Contracts;
|
||||||
|
|
||||||
namespace Tnb.EquipMgr.Entities
|
namespace Tnb.EquipMgr.Entities
|
||||||
{
|
{
|
||||||
@@ -10,20 +11,8 @@ namespace Tnb.EquipMgr.Entities
|
|||||||
///模具保养规则与模具关联
|
///模具保养规则与模具关联
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarTable("tool_mold_maintain_rule_relation")]
|
[SugarTable("tool_mold_maintain_rule_relation")]
|
||||||
public partial class ToolMoldMaintainRuleRelation
|
public partial class ToolMoldMaintainRuleRelation:BaseEntity<string>
|
||||||
{
|
{
|
||||||
public ToolMoldMaintainRuleRelation(){
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Desc:主键
|
|
||||||
/// Default:
|
|
||||||
/// Nullable:False
|
|
||||||
/// </summary>
|
|
||||||
[SugarColumn(IsPrimaryKey=true)]
|
|
||||||
public string id {get;set;} = SnowflakeIdHelper.NextId();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Desc:保养规则id
|
/// Desc:保养规则id
|
||||||
/// Default:
|
/// Default:
|
||||||
|
|||||||
60
EquipMgr/Tnb.EquipMgr/BaseMoldMaintainService.cs
Normal file
60
EquipMgr/Tnb.EquipMgr/BaseMoldMaintainService.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using JNPF.Common.Enums;
|
||||||
|
using JNPF.Common.Security;
|
||||||
|
using JNPF.FriendlyException;
|
||||||
|
using SqlSugar;
|
||||||
|
using Tnb.Common.Contracts;
|
||||||
|
using Tnb.EquipMgr.Entities.Dto;
|
||||||
|
using Tnb.EquipMgr.Entities;
|
||||||
|
using Tnb.EquipMgr.Utils;
|
||||||
|
|
||||||
|
namespace Tnb.EquipMgr
|
||||||
|
{
|
||||||
|
public class BaseMoldMaintainService
|
||||||
|
{
|
||||||
|
private readonly ISqlSugarClient _db;
|
||||||
|
public BaseMoldMaintainService(ISqlSugarClient db)
|
||||||
|
{
|
||||||
|
_db = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task Relevance<TSrc, TDest>(TSrc input,string masterTableName, string name, Expression<Func<TDest, bool>> deleleExp) where TDest : BaseEntity<string>, new()
|
||||||
|
where TSrc : BaseMoldMaintainInput
|
||||||
|
{
|
||||||
|
|
||||||
|
await _db.Deleteable<TDest>().Where(deleleExp).ExecuteCommandAsync();
|
||||||
|
//var itemGroupId = nameof(ToolMoldMaintainGroupRelation.item_group_id);
|
||||||
|
if (input == null) throw new ArgumentNullException(nameof(input));
|
||||||
|
var entities = new List<TDest>();
|
||||||
|
if (input.ids?.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var id in input.ids)
|
||||||
|
{
|
||||||
|
var pk = id;
|
||||||
|
TDest entity = new();
|
||||||
|
entity.id = SnowflakeIdHelper.NextId();
|
||||||
|
if (!PropertySet<TDest>.ValueFactories.TryGetValue(masterTableName, out Action<object, object>? setGroupIdAction))
|
||||||
|
{
|
||||||
|
setGroupIdAction = PropertySet<TDest>.CreateSetPropertyValueAction(masterTableName);
|
||||||
|
PropertySet<TDest>.ValueFactories.Add(masterTableName, 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,9 +14,6 @@ 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;
|
||||||
@@ -29,15 +26,12 @@ namespace Tnb.EquipMgr
|
|||||||
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||||
[Route("api/[area]/[controller]/[action]")]
|
[Route("api/[area]/[controller]/[action]")]
|
||||||
|
|
||||||
public class ToolMoldMaintainGroupService : IToolMoldMaintainGroupService, IDynamicApiController, ITransient
|
public class ToolMoldMaintainGroupService : BaseMoldMaintainService, IToolMoldMaintainGroupService, IDynamicApiController, ITransient
|
||||||
{
|
{
|
||||||
private readonly ISqlSugarRepository<ToolMoldMaintainGroup> _repository;
|
private readonly ISqlSugarRepository<ToolMoldMaintainGroup> _repository;
|
||||||
private readonly IUserManager _userManager;
|
|
||||||
private readonly ISqlSugarClient _db;
|
private readonly ISqlSugarClient _db;
|
||||||
public ToolMoldMaintainGroupService(ISqlSugarRepository<ToolMoldMaintainGroup> repository, IUserManager userManager)
|
public ToolMoldMaintainGroupService(ISqlSugarRepository<ToolMoldMaintainGroup> repository) : base(repository.AsSugarClient())
|
||||||
{
|
{
|
||||||
_repository = repository;
|
|
||||||
_userManager = userManager;
|
|
||||||
_db = repository.AsSugarClient();
|
_db = repository.AsSugarClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +81,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, nameof(ToolMoldMaintainGroupItem.item_id), it => it.item_group_id == input.item_group_id);
|
await Relevance<MoldMaintainGroupItemInput, ToolMoldMaintainGroupItem>(input, nameof(ToolMoldMaintainGroupItem.item_group_id), nameof(ToolMoldMaintainGroupItem.item_id), it => it.item_group_id == input.item_group_id);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 关联项目组与模具
|
/// 关联项目组与模具
|
||||||
@@ -96,7 +90,7 @@ 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, nameof(ToolMoldMaintainGroupRelation.mold_id), it => it.item_group_id == input.item_group_id);
|
await Relevance<MoldMaintainGroupItemRelationInput, ToolMoldMaintainGroupRelation>(input, nameof(ToolMoldMaintainGroupRelation.item_group_id), nameof(ToolMoldMaintainGroupRelation.mold_id), it => it.item_group_id == input.item_group_id);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除项目组与模具检查项信息
|
/// 删除项目组与模具检查项信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -110,7 +104,7 @@ namespace Tnb.EquipMgr
|
|||||||
{
|
{
|
||||||
await Delete<ToolMoldMaintainGroupItem>(it => it.item_group_id == input.item_group_id && input.ids.Contains(it.item_id));
|
await Delete<ToolMoldMaintainGroupItem>(it => it.item_group_id == input.item_group_id && input.ids.Contains(it.item_id));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Delete<ToolMoldMaintainGroupRelation>(it => it.item_group_id == input.item_group_id && input.ids.Contains(it.mold_id));
|
await Delete<ToolMoldMaintainGroupRelation>(it => it.item_group_id == input.item_group_id && input.ids.Contains(it.mold_id));
|
||||||
}
|
}
|
||||||
@@ -125,57 +119,6 @@ namespace Tnb.EquipMgr
|
|||||||
await _db.Deleteable<T>().Where(deleteExp).ExecuteCommandAsync();
|
await _db.Deleteable<T>().Where(deleteExp).ExecuteCommandAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
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));
|
|
||||||
var entities = new List<TDest>();
|
|
||||||
if (input.ids?.Count > 0)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -23,15 +23,11 @@ namespace Tnb.EquipMgr
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||||
[Route("api/[area]/[controller]/[action]")]
|
[Route("api/[area]/[controller]/[action]")]
|
||||||
public class ToolMoldMaintainRuleService : IToolMoldMaintainRuleService, IDynamicApiController, ITransient
|
public class ToolMoldMaintainRuleService : BaseMoldMaintainService, IToolMoldMaintainRuleService, IDynamicApiController, ITransient
|
||||||
{
|
{
|
||||||
private readonly ISqlSugarRepository<ToolMoldMaintainRule> _repository;
|
|
||||||
private readonly IUserManager _userManager;
|
|
||||||
private readonly ISqlSugarClient _db;
|
private readonly ISqlSugarClient _db;
|
||||||
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository, IUserManager userManager)
|
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository, IUserManager userManager) : base(repository.AsSugarClient())
|
||||||
{
|
{
|
||||||
_repository = repository;
|
|
||||||
_userManager = userManager;
|
|
||||||
_db = repository.AsSugarClient();
|
_db = repository.AsSugarClient();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -41,12 +37,8 @@ namespace Tnb.EquipMgr
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="ArgumentNullException"></exception>
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task RelevanceMold(RelevanceMoldInput input)
|
public async Task RelevanceMold(RelevanceMoldInput input) =>
|
||||||
{
|
await Relevance<RelevanceMoldInput, ToolMoldMaintainRuleRelation>(input, nameof(ToolMoldMaintainRuleRelation.rule_id), nameof(ToolMoldMaintainRuleRelation.mold_id), it => it.rule_id == input.rule_id);
|
||||||
if (input is null) throw new ArgumentNullException(nameof(input));
|
|
||||||
var entity = input.Adapt<ToolMoldMaintainRuleRelation>();
|
|
||||||
var row = await _db.Insertable(entity).ExecuteCommandAsync();
|
|
||||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
EquipMgr/Tnb.EquipMgr/Utils/PropertySet.cs
Normal file
23
EquipMgr/Tnb.EquipMgr/Utils/PropertySet.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace Tnb.EquipMgr.Utils
|
||||||
|
{
|
||||||
|
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