| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using AutoMapper; |
| | | using Model.InterFaceModel; |
| | | using Model.ModelDto.BllSoDto; |
| | | using Model.ModelDto.SysDto; |
| | | using Model.ModelVm.SysVm; |
| | | using SqlSugar; |
| | | using Utility; |
| | | using WMS.DAL; |
| | | using WMS.Entity.BllSoEntity; |
| | | using WMS.Entity.Context; |
| | | using WMS.Entity.SysEntity; |
| | | using WMS.IBLL.ISysServer; |
| | |
| | | |
| | | namespace WMS.BLL.SysServer |
| | | { |
| | | public class MaterialsServer : DbHelper<SysMaterialCategory>, IMaterialsServer |
| | | public class MaterialsServer : DbHelper<SysMaterials>, IMaterialsServer |
| | | { |
| | | /// <summary> |
| | | /// 依赖注入 |
| | |
| | | /// <param name="environment">存储环境</param> |
| | | /// <param name="categoryNo">类别编码</param> |
| | | /// <returns></returns> |
| | | public Task<List<MaterialsDto>> GetMateList(string skuNo, string skuName, string auditStatusNo, string type, string isControlled, string isInspect, string environment, string categoryNo) |
| | | public async Task<List<MaterialsDto>> GetMateList(GetMaterialsVm model, RefAsync<int> count) |
| | | { |
| | | return Db.Queryable<SysMaterials>() |
| | | .LeftJoin<SysUserInfor>((a, b) => a.CreateUser == b.Id) |
| | | .LeftJoin<SysPackag>((a, b,c) => a.PackagNo == c.PackagNo) |
| | | .LeftJoin<SysUnit> ((a,b,c,d)=>a.UnitNo == d.UnitNo) |
| | | .LeftJoin<SysMaterialCategory>((a,b,c,d,e)=>a.CategoryNo == e.CategoryNo) |
| | | .Where((a,b,c,d,e) => d.IsDel == "0" && e.IsDel =="0") |
| | | .WhereIF(!string.IsNullOrEmpty(skuNo), a => a.SkuNo.Contains(skuNo)) |
| | | .WhereIF(!string.IsNullOrEmpty(skuName), a => a.SkuName.Contains(skuName)) |
| | | .WhereIF(!string.IsNullOrEmpty(auditStatusNo), a => a.AuditStatusNo == auditStatusNo) |
| | | .WhereIF(!string.IsNullOrEmpty(type), a => a.Type == type) |
| | | .WhereIF(!string.IsNullOrEmpty(isControlled), a => a.IsControlled == isControlled) |
| | | .WhereIF(!string.IsNullOrEmpty(isInspect), a => a.IsInspect == isInspect) |
| | | .WhereIF(!string.IsNullOrEmpty(environment), a => a.Environment == environment) |
| | | .WhereIF(!string.IsNullOrEmpty(categoryNo), a => a.CategoryNo == categoryNo) |
| | | .Where(a => a.IsDel == "0" ) |
| | | .Select<MaterialsDto>((a, b, c,d,e) => new MaterialsDto() { CreateUserName = b.RealName,PackagName = c.PackagName }, true) |
| | | .ToListAsync(); |
| | | Expression<Func<SysMaterials, bool>> item = Expressionable.Create<SysMaterials>() |
| | | .AndIF(!string.IsNullOrWhiteSpace(model.SkuNo), it => it.SkuNo.Contains(model.SkuNo.Trim())) |
| | | .AndIF(!string.IsNullOrWhiteSpace(model.SkuName), it => it.SkuName.Contains(model.SkuName.Trim())) |
| | | .AndIF(!string.IsNullOrWhiteSpace(model.AuditStatusNo), it => it.AuditStatusNo == model.AuditStatusNo) |
| | | .AndIF(!string.IsNullOrWhiteSpace(model.Type), it => it.Type == model.Type) |
| | | .AndIF(!string.IsNullOrWhiteSpace(model.IsControlled), it => it.IsControlled == model.IsControlled) |
| | | .AndIF(!string.IsNullOrWhiteSpace(model.IsInspect), it => it.IsInspect == model.IsInspect) |
| | | .AndIF(!string.IsNullOrWhiteSpace(model.Environment), it => it.Environment == model.Environment) |
| | | .AndIF(!string.IsNullOrWhiteSpace(model.CategoryNo), it => it.CategoryNo == model.CategoryNo) |
| | | .And(it => it.IsDel == "0") |
| | | .ToExpression();//注意 这一句 不能少 |
| | | //Db.Aop.OnLogExecuting = (sql, data) => |
| | | //{ |
| | | // var nl = sql; |
| | | //}; |
| | | var data = await GetAllWhereAsync(item) |
| | | .LeftJoin<SysUserInfor>((a, b) => a.CreateUser == b.Id && b.IsDel == "0") |
| | | .LeftJoin<SysPackag>((a, b, c) => a.PackagNo == c.PackagNo && c.IsDel == "0") |
| | | .LeftJoin<SysMaterialCategory>((a, b, c, d) => a.CategoryNo == d.CategoryNo && d.IsDel == "0") |
| | | .Select((a, b, c, d) => new MaterialsDto() |
| | | { |
| | | Id = a.Id, |
| | | SkuNo = a.SkuNo, |
| | | SkuName = a.SkuName, |
| | | Standard = a.Standard, |
| | | Type = a.Type, |
| | | IsControlled = a.IsControlled, |
| | | IsInspect = a.IsInspect, |
| | | IsPasteCode = a.IsPasteCode, |
| | | Origin = a.Origin, |
| | | UnitNo = a.UnitNo, |
| | | PackagName = c.PackagName, |
| | | Environment = a.Environment, |
| | | CategoryNo = d.CategoryNo, |
| | | Weight = a.Weight, |
| | | Warranty = a.Warranty, |
| | | UnpackWarranty = a.UnpackWarranty, |
| | | AdventTime = a.AdventTime, |
| | | LowInventory = a.LowInventory, |
| | | Demo = a.Demo, |
| | | CreateUserName = b.UserName, |
| | | CreateTime = a.CreateTime |
| | | }) |
| | | .Distinct() |
| | | .OrderByDescending(a => a.CreateTime) |
| | | .ToPageListAsync(model.Page, model.Limit, count); |
| | | |
| | | return data; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// 获取包装信息列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public async Task<List<SysPackag>> GetPackagList() |
| | | public async Task<List<SysPackag>> GetPackagList(int page) |
| | | { |
| | | return await Db.Queryable<SysPackag>().Where(s => s.IsDel == "0").ToListAsync(); |
| | | int pageSize = 3000; |
| | | int skipCount = pageSize * (page - 1); |
| | | return await Db.Queryable<SysPackag>().Where(s => s.IsDel == "0").Skip(skipCount).Take(pageSize).ToListAsync(); |
| | | } |
| | | |
| | | #endregion |
| | |
| | | #endregion |
| | | |
| | | #region erp |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取erp数据 |
| | | /// </summary> |
| | |
| | | |
| | | #endregion |
| | | |
| | | #region sap |
| | | |
| | | /// <summary> |
| | | /// SAP新增物料主数据数据 |
| | | /// </summary> |
| | | /// <param name="model">erp实体</param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception">捕获异常</exception> |
| | | public async Task<string> AddSkuSap(SendSkuInfoVm model) |
| | | { |
| | | //捕获异常 |
| | | try |
| | | { |
| | | if (string.IsNullOrWhiteSpace(model.skuNo.ToString()) || string.IsNullOrWhiteSpace(model.skuName) || string.IsNullOrWhiteSpace(model.categoryNo)) |
| | | { |
| | | throw new Exception("参数错误"); |
| | | } |
| | | //判断是否唯一 |
| | | var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == model.skuNo.ToString()); |
| | | if (sku != null) |
| | | { |
| | | throw new Exception("当前物料已存在"); |
| | | } |
| | | //开启事务 |
| | | Db.BeginTran(); |
| | | |
| | | var category = Db.Queryable<SysMaterialCategory>().First(w => w.IsDel == "0" && w.CategoryNo == model.categoryNo); |
| | | if (category == null) |
| | | { |
| | | category = new SysMaterialCategory() |
| | | { |
| | | CategoryNo = model.categoryNo, |
| | | CategoryName = model.categoryName, |
| | | CreateUser = 1 |
| | | }; |
| | | //添加物料类别信息 |
| | | Db.Insertable(category).ExecuteCommand(); |
| | | } |
| | | var pack = new SysPackag() |
| | | { |
| | | PackagNo = model.skuNo.ToString(), |
| | | PackagName = model.skuName, |
| | | L1Num = 1, |
| | | L1Name = model.unit, |
| | | L2Num = Convert.ToInt32(model.packageQty), |
| | | L2Name = model.packageName |
| | | }; |
| | | //添加包装信息 |
| | | Db.Insertable(pack).ExecuteCommand(); |
| | | |
| | | var addSku = new SysMaterials() |
| | | { |
| | | SkuNo = model.skuNo.ToString(), |
| | | SkuName = model.skuName, |
| | | Standard = model.specification, |
| | | CategoryNo = category.CategoryNo, |
| | | AuditStatusNo = "9", //model.AuditStatusNo |
| | | Type = "0", |
| | | IsControlled = "0",//是否请验,0:是 1:否 |
| | | IsInspect = model.consume.ToString() == "0" ? "1" : "0", |
| | | IsPasteCode = "1", |
| | | Origin = "SAP", |
| | | UnitNo = model.unit, |
| | | PackagNo = pack.PackagNo, |
| | | Environment = null, |
| | | Weight = null, |
| | | Warranty = Convert.ToInt32(model.shelfLife.Trim()), |
| | | UnpackWarranty = null, |
| | | Price = null, |
| | | AdventTime = Convert.ToInt32(model.remainingDays) |
| | | }; |
| | | await Db.Insertable(addSku).ExecuteCommandAsync(); |
| | | |
| | | //提交事务 |
| | | Db.CommitTran(); |
| | | |
| | | return "0"; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //回滚事务 |
| | | Db.RollbackTran(); |
| | | //抛出异常 |
| | | throw new Exception("新增erp数据异常", ex); |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | } |