| | |
| | | using WMS.IBLL.ISysServer; |
| | | using WMS.IDAL.ISysInterface; |
| | | using Model.ModelVm.SysVm; |
| | | using System.Threading.Tasks; |
| | | using Utility; |
| | | using WMS.Entity.Context; |
| | | |
| | | namespace WMS.BLL.SysServer |
| | | { |
| | | public class PackagServer : IPackagServer |
| | | { |
| | | public IPackagRepository PackagRst { get; set; } |
| | | public IMaterialsServer materials { get; set; } |
| | | private static readonly SqlSugarScope Db = DataContext.Db; |
| | | |
| | | public PackagServer(IPackagRepository packagRst) |
| | | { |
| | |
| | | /// <param name="packagName">包装名称</param> |
| | | /// <param name="level">等级</param> |
| | | /// <returns>包装集合</returns> |
| | | public List<PackagDto> GetPackagList(string packagNo, string packagName, int? level, int page, int limit, out int count) |
| | | public async Task<List<PackagDto>> GetPackagList(string packagNo, string packagName, int? level, int page, int limit, RefAsync<int> count) |
| | | { |
| | | try |
| | | { |
| | |
| | | .AndIF(level != null, it => it.Level.Equals(level)) |
| | | .ToExpression();//注意 这一句 不能少 |
| | | |
| | | var data = PackagRst.GetAllByOrderPageAsync(item, limit, page, out int counts) |
| | | var data = await PackagRst.GetAllByOrderPage(item, limit, page, out int counts) |
| | | .Includes(x => x.CreateUserInfo) |
| | | .Includes(x => x.UpdateUserInfo).ToList(); |
| | | .Includes(x => x.UpdateUserInfo).ToListAsync(); |
| | | count = counts; |
| | | |
| | | return data.Select(m => new PackagDto() |
| | |
| | | /// </summary> |
| | | /// <param name="id">包装id</param> |
| | | /// <returns></returns> |
| | | public SysPackag GetPackagById(int id) |
| | | public async Task<SysPackag> GetPackagById(int id) |
| | | { |
| | | SysPackag packag = PackagRst.GetOneById(id); |
| | | return packag; |
| | | return await PackagRst.GetOneByIdAsync(id); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="model">包装信息</param> |
| | | /// <returns>true:成功 flase:失败</returns> |
| | | public int AddPackag(AddEditPackagVm model) |
| | | public async Task<int> AddPackag(AddEditPackagVm model) |
| | | { |
| | | try |
| | | var rowCount = await PackagRst.GetAllWhere(m => m.PackagNo == model.PackagNo).CountAsync(); |
| | | if (rowCount > 0) |
| | | { |
| | | var rowCount = PackagRst.GetAllWhereAsync(m => m.PackagNo == model.PackagNo).Count(); |
| | | if (rowCount > 0) |
| | | { |
| | | throw new Exception("包装编号已存在!"); |
| | | } |
| | | throw Oops.Bah("包装编号已存在!"); |
| | | } |
| | | |
| | | rowCount = PackagRst.GetAllWhereAsync(m => m.PackagName == model.PackagName).Count(); |
| | | if (rowCount > 0) |
| | | { |
| | | throw new Exception("包装名称已存在!"); |
| | | } |
| | | rowCount = await PackagRst.GetAllWhere(m => m.PackagName == model.PackagName).CountAsync(); |
| | | if (rowCount > 0) |
| | | { |
| | | throw Oops.Bah("包装名称已存在!"); |
| | | } |
| | | |
| | | SysPackag packagModel = new SysPackag(); |
| | | packagModel.PackagNo = model.PackagNo; |
| | | packagModel.PackagName = model.PackagName; |
| | | packagModel.Level = 0; |
| | | SysPackag packagModel = new SysPackag(); |
| | | packagModel.PackagNo = model.PackagNo; |
| | | packagModel.PackagName = model.PackagName; |
| | | packagModel.Level = 0; |
| | | |
| | | //判断五级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L5Num) && !string.IsNullOrEmpty(model.L5Name)) |
| | | { |
| | | packagModel.L5Num = int.Parse(model.L5Num); |
| | | packagModel.L5Name = model.L5Name; |
| | | packagModel.Level += 1; |
| | | //判断四级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L4Num) && string.IsNullOrEmpty(model.L4Name)) |
| | | { |
| | | return 2; |
| | | } |
| | | } |
| | | //判断五级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L5Num) && !string.IsNullOrEmpty(model.L5Name)) |
| | | { |
| | | packagModel.L5Num = int.Parse(model.L5Num); |
| | | packagModel.L5Name = model.L5Name; |
| | | packagModel.Level += 1; |
| | | //判断四级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L4Num) && !string.IsNullOrEmpty(model.L4Name)) |
| | | if (string.IsNullOrEmpty(model.L4Num) && string.IsNullOrEmpty(model.L4Name)) |
| | | { |
| | | packagModel.L4Num = int.Parse(model.L4Num); |
| | | packagModel.L4Name = model.L4Name; |
| | | packagModel.Level += 1; |
| | | //判断三级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L3Num) && string.IsNullOrEmpty(model.L3Name)) |
| | | { |
| | | return 2; |
| | | } |
| | | throw Oops.Bah("包装等级不可越级添加!"); |
| | | } |
| | | //判断三级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L3Num) && !string.IsNullOrEmpty(model.L3Name)) |
| | | { |
| | | packagModel.L3Num = int.Parse(model.L3Num); |
| | | packagModel.L3Name = model.L3Name; |
| | | packagModel.Level += 1; |
| | | //判断二级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L2Num) && string.IsNullOrEmpty(model.L2Name)) |
| | | { |
| | | return 2; |
| | | } |
| | | } |
| | | //判断二级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L2Num) && !string.IsNullOrEmpty(model.L2Name)) |
| | | { |
| | | packagModel.L2Num = int.Parse(model.L2Num); |
| | | packagModel.L2Name = model.L2Name; |
| | | packagModel.Level += 1; |
| | | //判断一级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L1Num) && string.IsNullOrEmpty(model.L1Name)) |
| | | { |
| | | return 2; |
| | | } |
| | | } |
| | | //判断一级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L1Num) && !string.IsNullOrEmpty(model.L1Name)) |
| | | { |
| | | packagModel.L1Num = int.Parse(model.L1Num); |
| | | packagModel.L1Name = model.L1Name; |
| | | packagModel.Level += 1; |
| | | } |
| | | else |
| | | { |
| | | return 2; |
| | | } |
| | | |
| | | packagModel.CreateUser = (int)model.CreateUser; |
| | | |
| | | int rowNum = PackagRst.Add(packagModel); |
| | | if (rowNum > 0) |
| | | { |
| | | return 1; |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | catch (Exception e) |
| | | //判断四级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L4Num) && !string.IsNullOrEmpty(model.L4Name)) |
| | | { |
| | | throw new Exception(e.Message); |
| | | packagModel.L4Num = int.Parse(model.L4Num); |
| | | packagModel.L4Name = model.L4Name; |
| | | packagModel.Level += 1; |
| | | //判断三级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L3Num) && string.IsNullOrEmpty(model.L3Name)) |
| | | { |
| | | throw Oops.Bah("包装等级不可越级添加!"); |
| | | } |
| | | } |
| | | //判断三级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L3Num) && !string.IsNullOrEmpty(model.L3Name)) |
| | | { |
| | | packagModel.L3Num = int.Parse(model.L3Num); |
| | | packagModel.L3Name = model.L3Name; |
| | | packagModel.Level += 1; |
| | | //判断二级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L2Num) && string.IsNullOrEmpty(model.L2Name)) |
| | | { |
| | | throw Oops.Bah("包装等级不可越级添加!"); |
| | | } |
| | | } |
| | | //判断二级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L2Num) && !string.IsNullOrEmpty(model.L2Name)) |
| | | { |
| | | packagModel.L2Num = int.Parse(model.L2Num); |
| | | packagModel.L2Name = model.L2Name; |
| | | packagModel.Level += 1; |
| | | //判断一级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L1Num) && string.IsNullOrEmpty(model.L1Name)) |
| | | { |
| | | throw Oops.Bah("包装等级不可越级添加!"); |
| | | } |
| | | } |
| | | //判断一级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L1Num) && !string.IsNullOrEmpty(model.L1Name)) |
| | | { |
| | | packagModel.L1Num = int.Parse(model.L1Num); |
| | | packagModel.L1Name = model.L1Name; |
| | | packagModel.Level += 1; |
| | | } |
| | | else |
| | | { |
| | | throw Oops.Bah("包装等级不可越级添加!"); |
| | | } |
| | | |
| | | packagModel.CreateUser = (int)model.CreateUser; |
| | | |
| | | return await PackagRst.AddAsync(packagModel); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="model">包装信息</param> |
| | | /// <returns>true:成功 flase:失败</returns> |
| | | public int EditPackag(AddEditPackagVm model) |
| | | public async Task<int> EditPackag(AddEditPackagVm model) |
| | | { |
| | | try |
| | | if (string.IsNullOrEmpty(model.PackagName)) |
| | | { |
| | | if (string.IsNullOrEmpty(model.PackagName)) |
| | | var date = await PackagRst.GetAllWhere(m => m.Id != model.Id && (m.PackagName == model.PackagName)).CountAsync(); |
| | | if (date > 0) |
| | | { |
| | | var date = PackagRst.GetAllWhereAsync(m => m.Id != model.Id && (m.PackagName == model.PackagName)).Count(); |
| | | if (date > 0) |
| | | { |
| | | throw new Exception("包装名称已存在!"); |
| | | } |
| | | throw Oops.Bah("包装名称已存在!"); |
| | | } |
| | | var packagItems = PackagRst.GetOneById(model.Id); |
| | | packagItems.Id = model.Id; //id |
| | | packagItems.PackagNo = model.PackagNo; //包装编号 |
| | | packagItems.PackagName = model.PackagName; //包装描述 |
| | | //packagItems.IsDel = model.IsDel; 原因: 修改时不需要修改IsDel字段 |
| | | packagItems.UpdateTime = DateTime.Now; //修改时间 |
| | | packagItems.UpdateUser = model.CreateUser; //修改人 |
| | | packagItems.Level = 0; |
| | | } |
| | | var packagItems = PackagRst.GetOneById(model.Id); |
| | | packagItems.Id = model.Id; //id |
| | | packagItems.PackagNo = model.PackagNo; //包装编号 |
| | | packagItems.PackagName = model.PackagName; //包装描述 |
| | | //packagItems.IsDel = model.IsDel; 原因: 修改时不需要修改IsDel字段 |
| | | packagItems.UpdateTime = DateTime.Now; //修改时间 |
| | | packagItems.UpdateUser = model.CreateUser; //修改人 |
| | | packagItems.Level = 0; |
| | | |
| | | //判断五级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L5Num) && !string.IsNullOrEmpty(model.L5Name)) |
| | | { |
| | | packagItems.L5Num = int.Parse(model.L5Num); |
| | | packagItems.L5Name = model.L5Name; |
| | | packagItems.Level += 1; |
| | | //判断四级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L4Num) && string.IsNullOrEmpty(model.L4Name)) |
| | | { |
| | | return 2; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | packagItems.L5Num = null; |
| | | packagItems.L5Name = null; |
| | | } |
| | | //判断五级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L5Num) && !string.IsNullOrEmpty(model.L5Name)) |
| | | { |
| | | packagItems.L5Num = int.Parse(model.L5Num); |
| | | packagItems.L5Name = model.L5Name; |
| | | packagItems.Level += 1; |
| | | //判断四级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L4Num) && !string.IsNullOrEmpty(model.L4Name)) |
| | | if (string.IsNullOrEmpty(model.L4Num) && string.IsNullOrEmpty(model.L4Name)) |
| | | { |
| | | packagItems.L4Num = int.Parse(model.L4Num); |
| | | packagItems.L4Name = model.L4Name; |
| | | packagItems.Level += 1; |
| | | //判断三级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L3Num) && string.IsNullOrEmpty(model.L3Name)) |
| | | { |
| | | return 2; |
| | | } |
| | | throw Oops.Bah("包装等级不可越级修改 请重新输入"); |
| | | } |
| | | else |
| | | { |
| | | packagItems.L4Num = null; |
| | | packagItems.L4Name = null; |
| | | } |
| | | //判断三级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L3Num) && !string.IsNullOrEmpty(model.L3Name)) |
| | | { |
| | | packagItems.L3Num = int.Parse(model.L3Num); |
| | | packagItems.L3Name = model.L3Name; |
| | | packagItems.Level += 1; |
| | | //判断二级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L2Num) && string.IsNullOrEmpty(model.L2Name)) |
| | | { |
| | | return 2; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | packagItems.L3Num = null; |
| | | packagItems.L3Name = null; |
| | | } |
| | | //判断二级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L2Num) && !string.IsNullOrEmpty(model.L2Name)) |
| | | { |
| | | packagItems.L2Num = int.Parse(model.L2Num); |
| | | packagItems.L2Name = model.L2Name; |
| | | packagItems.Level += 1; |
| | | //判断一级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L1Num) && string.IsNullOrEmpty(model.L1Name)) |
| | | { |
| | | return 2; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | packagItems.L3Num = null; |
| | | packagItems.L3Name = null; |
| | | } |
| | | //判断一级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L1Num) && !string.IsNullOrEmpty(model.L1Name)) |
| | | { |
| | | packagItems.L1Num = int.Parse(model.L1Num); |
| | | packagItems.L1Name = model.L1Name; |
| | | packagItems.Level += 1; |
| | | } |
| | | else |
| | | { |
| | | packagItems.L1Num = null; |
| | | packagItems.L1Name = null; |
| | | |
| | | return 2; |
| | | } |
| | | |
| | | var rowCount = PackagRst.Edit(packagItems); |
| | | return rowCount; |
| | | } |
| | | catch (Exception e) |
| | | else |
| | | { |
| | | throw new Exception(e.Message); |
| | | packagItems.L5Num = null; |
| | | packagItems.L5Name = null; |
| | | } |
| | | //判断四级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L4Num) && !string.IsNullOrEmpty(model.L4Name)) |
| | | { |
| | | packagItems.L4Num = int.Parse(model.L4Num); |
| | | packagItems.L4Name = model.L4Name; |
| | | packagItems.Level += 1; |
| | | //判断三级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L3Num) && string.IsNullOrEmpty(model.L3Name)) |
| | | { |
| | | throw Oops.Bah("包装等级不可越级修改 请重新输入"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | packagItems.L4Num = null; |
| | | packagItems.L4Name = null; |
| | | } |
| | | //判断三级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L3Num) && !string.IsNullOrEmpty(model.L3Name)) |
| | | { |
| | | packagItems.L3Num = int.Parse(model.L3Num); |
| | | packagItems.L3Name = model.L3Name; |
| | | packagItems.Level += 1; |
| | | //判断二级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L2Num) && string.IsNullOrEmpty(model.L2Name)) |
| | | { |
| | | throw Oops.Bah("包装等级不可越级修改 请重新输入"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | packagItems.L3Num = null; |
| | | packagItems.L3Name = null; |
| | | } |
| | | //判断二级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L2Num) && !string.IsNullOrEmpty(model.L2Name)) |
| | | { |
| | | packagItems.L2Num = int.Parse(model.L2Num); |
| | | packagItems.L2Name = model.L2Name; |
| | | packagItems.Level += 1; |
| | | //判断一级包装是否为空 |
| | | if (string.IsNullOrEmpty(model.L1Num) && string.IsNullOrEmpty(model.L1Name)) |
| | | { |
| | | throw Oops.Bah("包装等级不可越级修改 请重新输入"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | packagItems.L3Num = null; |
| | | packagItems.L3Name = null; |
| | | } |
| | | //判断一级包装是否为空 |
| | | if (!string.IsNullOrEmpty(model.L1Num) && !string.IsNullOrEmpty(model.L1Name)) |
| | | { |
| | | packagItems.L1Num = int.Parse(model.L1Num); |
| | | packagItems.L1Name = model.L1Name; |
| | | packagItems.Level += 1; |
| | | } |
| | | else |
| | | { |
| | | packagItems.L1Num = null; |
| | | packagItems.L1Name = null; |
| | | |
| | | throw Oops.Bah("包装等级不可越级修改 请重新输入"); |
| | | } |
| | | |
| | | return await PackagRst.EditAsync(packagItems); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="packagId">包装信息主键ID</param> |
| | | /// <returns>true:成功 flase:失败</returns> |
| | | public bool DelPackag(int packagId, int userId) |
| | | public async Task<bool> DelPackag(int packagId, int userId) |
| | | { |
| | | try |
| | | var packagItems = await PackagRst.GetOneByIdAsync(packagId); |
| | | if (packagItems == null) |
| | | { |
| | | var packagItems = PackagRst.GetOneById(packagId); |
| | | if (packagItems == null) |
| | | { |
| | | throw new Exception("包装信息不存在!"); |
| | | } |
| | | |
| | | packagItems.IsDel = "1"; |
| | | packagItems.UpdateTime = DateTime.Now; |
| | | packagItems.UpdateUser = userId; |
| | | |
| | | var rowCount = PackagRst.Edit(packagItems); |
| | | return rowCount > 0; |
| | | throw Oops.Bah("包装信息不存在!"); |
| | | } |
| | | catch (Exception e) |
| | | var modMaterial = await Db.Queryable<SysMaterials>().FirstAsync(a => a.IsDel == "0" && a.PackagNo == packagItems.PackagNo); |
| | | if (modMaterial != null) |
| | | { |
| | | throw new Exception(e.Message); |
| | | throw Oops.Bah("存在正在使用此包装的物料!"); |
| | | } |
| | | |
| | | packagItems.IsDel = "1"; |
| | | packagItems.UpdateTime = DateTime.Now; |
| | | packagItems.UpdateUser = userId; |
| | | |
| | | return await PackagRst.EditAsync(packagItems) > 0; |
| | | } |
| | | } |
| | | } |