新增对象深拷贝通用函数,新增wms载具更换函数
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Entities.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 更换载具输入参数
|
||||
/// </summary>
|
||||
|
||||
public class ExChangeCarryInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 老载具ID
|
||||
/// </summary>
|
||||
public string old_carry_id { get; set; }
|
||||
/// <summary>
|
||||
/// 新载具ID
|
||||
/// </summary>
|
||||
public string new_carry_id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -97,12 +97,12 @@ public partial class WmsCarryCode : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public string create_id { get; set; } = string.Empty;
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime create_time { get; set; } = DateTime.Now;
|
||||
public DateTime? create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
|
||||
@@ -42,12 +42,12 @@ public partial class WmsCarryD : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public string create_id { get; set; } = string.Empty;
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime create_time { get; set; } = DateTime.Now;
|
||||
public DateTime? create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后修改人员ID
|
||||
|
||||
@@ -42,7 +42,7 @@ public partial class WmsCarryH : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 载具状态
|
||||
/// </summary>
|
||||
public string carry_status { get; set; } = string.Empty;
|
||||
public int carry_status { get; set; };
|
||||
|
||||
/// <summary>
|
||||
/// 载具分类ID
|
||||
@@ -114,4 +114,19 @@ public partial class WmsCarryH : BaseEntity<string>
|
||||
/// </summary>
|
||||
public DateTime? timestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 打包号
|
||||
/// </summary>
|
||||
public string? bale_num { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 齐套搭配方案ID
|
||||
/// </summary>
|
||||
public string? collocation_scheme_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 齐套搭配方案编号
|
||||
/// </summary>
|
||||
public string? collocation_scheme_code { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -82,12 +82,12 @@ public partial class WmsCarryMat : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 时间戳
|
||||
/// </summary>
|
||||
public DateTime time_stamp { get; set; } = DateTime.Now;
|
||||
public DateTime? time_stamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public string create_id { get; set; } = string.Empty;
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
|
||||
@@ -77,12 +77,12 @@ public partial class WmsCarryReplaceCode : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public string create_id { get; set; } = string.Empty;
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime create_time { get; set; } = DateTime.Now;
|
||||
public DateTime? create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户
|
||||
@@ -94,9 +94,4 @@ public partial class WmsCarryReplaceCode : BaseEntity<string>
|
||||
/// </summary>
|
||||
public DateTime? modify_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 行号
|
||||
/// </summary>
|
||||
public int no { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public partial class WmsCarryReplaceH : BaseEntity<string>
|
||||
/// <summary>
|
||||
/// 租户ID
|
||||
/// </summary>
|
||||
public string tenant_id { get; set; } = string.Empty;
|
||||
public string? tenant_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属组织ID
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Entities.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 载具状态枚举
|
||||
/// </summary>
|
||||
public enum EnumCarryStatus
|
||||
{
|
||||
空闲 = 0,
|
||||
占用 = 1,
|
||||
齐套 = 3,
|
||||
寄存 = 4,
|
||||
齐套分拣 = 5,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Entities.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 出库状态
|
||||
/// </summary>
|
||||
public enum EnumOutStatus
|
||||
{
|
||||
正常 = 0,
|
||||
全部出 = 1,
|
||||
分拣出 = 2,
|
||||
齐套出 = 3,
|
||||
寄存出 = 4,
|
||||
齐套分拣出 = 5,
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Tnb.WarehouseMgr.Interfaces
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
13
WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsCarryEntity.cs
Normal file
13
WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsCarryEntity.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Interfaces
|
||||
{
|
||||
public class IWmsCarryEntity
|
||||
{
|
||||
string carry_id { get; set; }
|
||||
}
|
||||
}
|
||||
17
WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsCarryService.cs
Normal file
17
WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWmsCarryService.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// 载具服务接口
|
||||
/// </summary>
|
||||
public interface IWmsCarryService
|
||||
{
|
||||
/// <summary>
|
||||
/// 更新空载具
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> UpdateNullCarry(WmsCarryH carryObj);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
137
WarehouseMgr/Tnb.WarehouseMgr/WmsCarryService.cs
Normal file
137
WarehouseMgr/Tnb.WarehouseMgr/WmsCarryService.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.Common.Utils;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Entities.Dto;
|
||||
using Tnb.WarehouseMgr.Entities.Enums;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
/// <summary>
|
||||
/// 载具服务
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
|
||||
public class WmsCarryService : IWmsCarryService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IUserManager _userManager;
|
||||
public WmsCarryService(ISqlSugarRepository<WmsCarryH> repository, IUserManager userManager)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_userManager = userManager;
|
||||
}
|
||||
/// <summary>
|
||||
/// 更换载具
|
||||
/// </summary>
|
||||
/// <param name="input">
|
||||
/// 输入参数:
|
||||
/// <br/>{
|
||||
/// <br/> old_carry_id:老载具id
|
||||
/// <br/> new_carry_id:新载具ID
|
||||
/// <br/>}
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
[HttpPost]
|
||||
public async Task Exchange(ExChangeCarryInput input)
|
||||
{
|
||||
var row = -1;
|
||||
if (input == null) throw new ArgumentNullException("input");
|
||||
var oldCarry = await _db.Queryable<WmsCarryH>().FirstAsync(it => it.id == input.old_carry_id && it.is_lock == 0 && it.status == 0 && it.carry_status != 0);
|
||||
var newCarry = await _db.Queryable<WmsCarryH>().FirstAsync(it => it.id == input.new_carry_id && it.is_lock == 0 && it.status == 0 && it.carry_status == 0);
|
||||
if (oldCarry != null && newCarry != null)
|
||||
{
|
||||
var subCarrys = await _db.Queryable<WmsCarryD>().Where(it => it.carry_id == oldCarry.id).ToListAsync();
|
||||
if (subCarrys?.Count > 0)
|
||||
{
|
||||
List<WmsCarryD> newSubCarrys = DeepCopyHelper<WmsCarryD>.DeepCopyList(subCarrys);
|
||||
if (newSubCarrys?.Count > 0)
|
||||
{
|
||||
newSubCarrys.ForEach(x => x.carry_id = newCarry.id);
|
||||
row = await _db.Insertable(newSubCarrys).ExecuteCommandAsync();
|
||||
}
|
||||
if (row > 0)
|
||||
{
|
||||
row = await _db.Deleteable(subCarrys).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
var subCarryMats = await _db.Queryable<WmsCarryMat>().Where(it => it.carry_id == oldCarry.id).ToListAsync();
|
||||
if (subCarryMats?.Count > 0)
|
||||
{
|
||||
List<WmsCarryMat> newCarryMats = DeepCopyHelper<WmsCarryMat>.DeepCopyList(subCarryMats);
|
||||
if (newCarryMats?.Count > 0)
|
||||
{
|
||||
newCarryMats.ForEach(x => x.carry_id = newCarry.id);
|
||||
row = await _db.Insertable(newCarryMats).ExecuteCommandAsync();
|
||||
}
|
||||
if (row > 0)
|
||||
{
|
||||
row = await _db.Deleteable(subCarryMats).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
var subCarryCodes = await _db.Queryable<WmsCarryCode>().Where(it => it.carry_id == oldCarry.id).ToListAsync();
|
||||
if (subCarryCodes?.Count > 0)
|
||||
{
|
||||
List<WmsCarryCode> newCarrayCodes = DeepCopyHelper<WmsCarryCode>.DeepCopyList(subCarryCodes);
|
||||
if (newCarrayCodes?.Count > 0)
|
||||
{
|
||||
newCarrayCodes.ForEach(x => x.carry_id = newCarry.id);
|
||||
row = await _db.Insertable(newCarrayCodes).ExecuteCommandAsync();
|
||||
}
|
||||
if (row > 0)
|
||||
{
|
||||
row = await _db.Deleteable(subCarryCodes).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
if (row > 0)
|
||||
{
|
||||
newCarry.carry_name = oldCarry.carry_name;
|
||||
newCarry.status = oldCarry.status;
|
||||
newCarry.carry_status = oldCarry.carry_status;
|
||||
newCarry.carrystd_id = oldCarry.carrystd_id;
|
||||
newCarry.location_id = oldCarry.location_id;
|
||||
newCarry.carry_code = oldCarry.location_code;
|
||||
newCarry.is_lock = oldCarry.is_lock;
|
||||
newCarry.out_status = oldCarry.out_status;
|
||||
newCarry.is_check = oldCarry.is_check;
|
||||
newCarry.bale_num = oldCarry.bale_num;
|
||||
newCarry.collocation_scheme_id = oldCarry.collocation_scheme_id;
|
||||
newCarry.collocation_scheme_code = oldCarry.collocation_scheme_code;
|
||||
newCarry.source_id = oldCarry.source_id;
|
||||
newCarry.source_code = oldCarry.source_code;
|
||||
newCarry.create_id = _userManager.UserId;
|
||||
newCarry.create_time = DateTime.Now;
|
||||
row = await _db.Updateable(newCarry).ExecuteCommandAsync();
|
||||
row = await UpdateNullCarry(oldCarry);
|
||||
}
|
||||
}
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
|
||||
}
|
||||
|
||||
public Task<int> UpdateNullCarry(WmsCarryH carryObj)
|
||||
{
|
||||
carryObj.carry_name = null;
|
||||
carryObj.status = 0;
|
||||
carryObj.carry_status = 0;
|
||||
carryObj.carrystd_id = null;
|
||||
carryObj.location_id = null;
|
||||
carryObj.carry_code = null;
|
||||
carryObj.out_status = null;
|
||||
carryObj.is_check = 0;
|
||||
carryObj.bale_num = null;
|
||||
carryObj.collocation_scheme_id = null;
|
||||
carryObj.collocation_scheme_code = null;
|
||||
carryObj.source_id = null;
|
||||
carryObj.source_code = null;
|
||||
return _db.Updateable(carryObj).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
76
common/Tnb.Common/Utils/DeepCopyHelper.cs
Normal file
76
common/Tnb.Common/Utils/DeepCopyHelper.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.Common.Utils
|
||||
{
|
||||
public class DeepCopyHelper<T> where T : class, new() // 需要无参构造函数,构造表达式树的时候需要利用无参构造函数创建对象
|
||||
{
|
||||
/// <summary>
|
||||
/// 映射表达式,泛型缓存每个类型存一份
|
||||
/// </summary>
|
||||
private static readonly Func<T, T> s_CopyFunc = null;
|
||||
|
||||
/// <summary>
|
||||
/// 静态构造函数,每个泛型类型会且只会执行一次
|
||||
/// </summary>
|
||||
static DeepCopyHelper()
|
||||
{
|
||||
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
||||
ParameterExpression parameterExpression = Expression.Parameter(typeof(T), "m"); // 参数m :m =>
|
||||
List<MemberBinding> memberBindingList = new List<MemberBinding>();
|
||||
foreach (var item in typeof(T).GetProperties(bindingFlags))
|
||||
{
|
||||
if (!item.CanWrite) // 只读属性不拷贝
|
||||
{
|
||||
continue;
|
||||
}
|
||||
MemberExpression property = Expression.Property(parameterExpression, item); // m.Name
|
||||
MemberBinding memberBinding = Expression.Bind(item, property); // Name = m.Name
|
||||
memberBindingList.Add(memberBinding);
|
||||
}
|
||||
foreach (var item in typeof(T).GetFields(bindingFlags))
|
||||
{
|
||||
MemberExpression property = Expression.Field(parameterExpression, item);
|
||||
MemberBinding memberBinding = Expression.Bind(item, property);
|
||||
memberBindingList.Add(memberBinding);
|
||||
}
|
||||
MemberInitExpression memberInitExpression = Expression.MemberInit(Expression.New(typeof(T)), memberBindingList.ToArray());// new T() {Name = m.Name}
|
||||
Expression<Func<T, T>> lambda = Expression.Lambda<Func<T, T>>(memberInitExpression, new ParameterExpression[]
|
||||
{
|
||||
parameterExpression
|
||||
}); // m => new T() {Name = m.Name}
|
||||
|
||||
s_CopyFunc = lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对象拷贝(拷贝private/public:实例成员、属性、静态成员)
|
||||
/// </summary>
|
||||
/// <param name="data">源</param>
|
||||
/// <returns></returns>
|
||||
public static T DeepCopy(T data)
|
||||
{
|
||||
return s_CopyFunc(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 集合拷贝(拷贝private/public:实例成员、属性、静态成员)
|
||||
/// </summary>
|
||||
/// <param name="data">源</param>
|
||||
/// <returns></returns>
|
||||
public static List<T> DeepCopyList(List<T> data)
|
||||
{
|
||||
if (data == null || data.Count < 1)
|
||||
{
|
||||
return Enumerable.Empty<T>().ToList();
|
||||
}
|
||||
return data.Select(a => DeepCopy(a)).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user