| | |
| | | using AutoMapper; |
| | | using Model.ModelDto.SysDto; |
| | | using SqlSugar; |
| | | using Utility; |
| | | using WMS.DAL; |
| | | using WMS.Entity.Context; |
| | | using WMS.Entity.SysEntity; |
| | |
| | | public IMaterialsRepository _mate { get; set; } |
| | | private readonly IMapper _mapper; |
| | | private static readonly SqlSugarScope Db = DataContext.Db; |
| | | private readonly UserManager _userManager; |
| | | /// <summary> |
| | | /// 构造函数 |
| | | /// </summary> |
| | | /// <param name="mate">物料编码</param> |
| | | /// <param name="mapper">automapper</param> |
| | | public MaterialsServer(IMaterialsRepository mate, IMapper mapper) : base(Db) |
| | | public MaterialsServer(IMaterialsRepository mate, IMapper mapper, UserManager userManager) : base(Db) |
| | | { |
| | | _mate = mate; //物料编码 |
| | | _mapper = mapper; //automapper |
| | | _userManager = userManager; |
| | | } |
| | | |
| | | #region wms |
| | | |
| | | //public List<MaterialsDto> GetMaterialsList(string skuNo, string skuName, string type, string isInspect, int page, int limit, out int count) |
| | | //{ |
| | | // try |
| | | // { |
| | | // Expression<Func<SysMaterials, bool>> item = Expressionable.Create<SysMaterials>() |
| | | // .AndIF(!string.IsNullOrWhiteSpace(skuNo), it => it.SkuNo.Contains(skuNo.Trim())) |
| | | // .AndIF(!string.IsNullOrWhiteSpace(skuName), it => it.SkuName.Contains(skuName.Trim())) |
| | | // .AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type) |
| | | // .AndIF(!string.IsNullOrWhiteSpace(isInspect), it => it.IsInspect == isInspect) |
| | | // .ToExpression();//注意 这一句 不能少 |
| | | |
| | | // var data = _mate.GetAllByOrderPageAsync(item, limit, page, out int counts) |
| | | // .Includes(x => x.TypeInfo) |
| | | // .Includes(x => x.EnvironmentInfo) |
| | | // .Includes(x => x.UnitInfo) |
| | | // .Includes(x => x.PackagInfo) |
| | | // .Includes(x => x.CreateUserInfo) |
| | | // .Includes(x => x.UpdateUserInfo) |
| | | // .ToList(); |
| | | // count = counts; |
| | | |
| | | // return data.Select(m => new MaterialsDto() |
| | | // { |
| | | // Id = m.Id, |
| | | // SkuNo = m.SkuNo, |
| | | // SkuName = m.SkuName, |
| | | // Standard = m.Standard, |
| | | // AuditStatusNo = m.AuditStatusNo, |
| | | // Type = m.Type, |
| | | // TypeName = m.TypeInfo == null ? "" : m.TypeInfo.DictName, |
| | | // IsControlled = m.IsControlled, |
| | | // IsInspect = m.IsInspect, |
| | | // Origin = m.Origin, |
| | | // UnitNo = m.UnitNo, |
| | | // UnitName = m.UnitInfo == null ? "" : m.UnitInfo.UnitName, |
| | | // PackagNo = m.PackagNo, |
| | | // PackagName = m.PackagInfo == null ? "" : m.PackagInfo.PackagName, |
| | | // Environment = m.Environment, |
| | | // EnvironmentName = m.EnvironmentInfo == null ? "" : m.EnvironmentInfo.DictName, |
| | | // Weight = m.Weight, |
| | | // Warranty = m.Warranty, |
| | | // Price = m.Price, |
| | | // Demo = m.Demo, |
| | | |
| | | // CreateUserName = m.CreateUserInfo == null ? "" : m.CreateUserInfo.UserName, |
| | | // UpdateUserName = m.UpdateUserInfo == null ? "" : m.UpdateUserInfo.UserName, |
| | | // CreateTime = m.CreateTime, |
| | | // UpdateTime = m.UpdateTime |
| | | // }).ToList(); |
| | | // } |
| | | // catch (Exception e) |
| | | // { |
| | | // throw new Exception(e.Message); |
| | | // } |
| | | //} |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取物料信息列表 |
| | |
| | | /// <param name="environment">存储环境</param> |
| | | /// <param name="categoryNo">类别编码</param> |
| | | /// <returns></returns> |
| | | public List<MaterialsDto> GetMateList(string skuNo, string skuName, string auditStatusNo, string type, string isControlled, string isInspect, string environment, string categoryNo) |
| | | public Task<List<MaterialsDto>> GetMateList(string skuNo, string skuName, string auditStatusNo, string type, string isControlled, string isInspect, string environment, string categoryNo) |
| | | { |
| | | List<MaterialsDto> matedto = _mate.GetMateList(skuNo, skuName, auditStatusNo, type, isControlled, isInspect, environment, categoryNo); |
| | | return matedto; |
| | | return Db.Queryable<SysMaterials>() |
| | | .LeftJoin<SysUserInfor>((a, b) => a.CreateUser == b.Id) |
| | | .WhereIF(!string.IsNullOrEmpty(skuNo), a => a.SkuNo.Contains(skuNo)) |
| | | .WhereIF(!string.IsNullOrEmpty(skuName), a => a.SkuNo.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) => new MaterialsDto() { CreateUserName = b.RealName }, true) |
| | | .ToListAsync(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="id">物料id</param> |
| | | /// <returns></returns> |
| | | public SysMaterials GetMateById(int id) |
| | | public async Task<SysMaterials> GetMateById(int id) |
| | | { |
| | | SysMaterials mate = _mate.GetMateById(id); |
| | | return mate; |
| | | return await Db.Queryable<SysMaterials>().FirstAsync(s => s.Id == id); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="SkuNo">物料编号</param> |
| | | /// <returns></returns> |
| | | public int GetMateByNo(string SkuNo) |
| | | public async Task<int> GetMateByNo(string SkuNo) |
| | | { |
| | | List<SysMaterials> mate = _mate.GetMateByNo(SkuNo); |
| | | return mate.Count; |
| | | return await Db.Queryable<SysMaterials>().CountAsync(s => s.SkuNo == SkuNo && s.IsDel == "0"); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <exception cref="Exception">捕获异常</exception> |
| | | public async Task<int> AddMate(MaterialsDto matedto) |
| | | { |
| | | //捕获异常 |
| | | try |
| | | { |
| | | int count = GetMateByNo(matedto.SkuNo); |
| | | |
| | | if (count > 0) |
| | | { |
| | | throw new Exception("系统中已存在该物料"); |
| | | } |
| | | if (string.IsNullOrWhiteSpace(matedto.PackagNo)) |
| | | { |
| | | throw new Exception("包装信息不能为空"); |
| | | } |
| | | |
| | | |
| | | //映射模型 |
| | | SysMaterials mate = _mapper.Map<SysMaterials>(matedto); |
| | | mate.AuditStatusNo = "9"; //审核状态 |
| | | mate.Type = mate.Type; //类型 |
| | | mate.IsControlled = string.IsNullOrWhiteSpace(mate.IsControlled) ? "0" : mate.IsControlled; //是否受控 |
| | | mate.IsInspect = string.IsNullOrWhiteSpace(mate.IsInspect) ? "0" : mate.IsInspect; //是否免检 |
| | | mate.IsPasteCode = string.IsNullOrWhiteSpace(mate.IsPasteCode) ? "0" : mate.IsPasteCode; //是否免检 |
| | | mate.Origin = "WMS"; //来源 |
| | | mate.IsDel = "0"; |
| | | mate.CreateTime = Db.GetDate(); |
| | | Db.BeginTran(); |
| | | Db.Insertable(mate).ExecuteCommand(); |
| | | Db.CommitTran(); |
| | | return 1; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.RollbackTran(); |
| | | //抛出异常 |
| | | throw new Exception(ex.Message); |
| | | } |
| | | if (string.IsNullOrWhiteSpace(matedto.PackagNo)) |
| | | throw Oops.Bah("包装信息不能为空"); |
| | | if (await GetMateByNo(matedto.SkuNo) > 0) |
| | | throw Oops.Bah("系统中已存在该物料"); |
| | | //映射模型 |
| | | SysMaterials mate = _mapper.Map<SysMaterials>(matedto); |
| | | mate.AuditStatusNo = "9"; //审核状态 |
| | | mate.Type = mate.Type; //类型 |
| | | mate.IsControlled = string.IsNullOrWhiteSpace(mate.IsControlled) ? "0" : mate.IsControlled; //是否受控 |
| | | mate.IsInspect = string.IsNullOrWhiteSpace(mate.IsInspect) ? "0" : mate.IsInspect; //是否免检 |
| | | mate.IsPasteCode = string.IsNullOrWhiteSpace(mate.IsPasteCode) ? "0" : mate.IsPasteCode; //是否免检 |
| | | mate.Origin = "WMS"; //来源 |
| | | mate.IsDel = "0"; |
| | | mate.CreateTime = DateTime.Now; |
| | | mate.CreateUser = _userManager.UserId; |
| | | return await Db.Insertable(mate).ExecuteCommandAsync(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <exception cref="Exception">捕获异常</exception> |
| | | public async Task<int> DelMate(SysMaterials mate) |
| | | { |
| | | //捕获异常 |
| | | try |
| | | { |
| | | //删除 |
| | | int i = await _mate.DelMate(mate); |
| | | return i; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //抛出异常 |
| | | throw new Exception("删除物料异常", ex); |
| | | } |
| | | return await Db.Updateable<SysMaterials>() |
| | | .Where(s => s.Id == mate.Id) |
| | | .SetColumns(s => s.IsDel == "1") |
| | | .SetColumns(s => s.UpdateTime == DateTime.Now) |
| | | .SetColumns(s => s.UpdateUser == _userManager.UserId) |
| | | .ExecuteCommandAsync(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <exception cref="Exception">捕获异常</exception> |
| | | public async Task<int> ExitMate(MaterialsDto matedto) |
| | | { |
| | | //捕获异常 |
| | | try |
| | | if (matedto.AdventTime > 365 && matedto.AdventTime < 30) |
| | | { |
| | | if (matedto.AdventTime > 365 && matedto.AdventTime < 30) |
| | | { |
| | | return 2; |
| | | } |
| | | else if (string.IsNullOrWhiteSpace(matedto.PackagNo)) |
| | | { |
| | | throw new Exception("包装不能为空"); |
| | | } |
| | | //else if (matedto.LowInventory > 1000) |
| | | //{ |
| | | // return 4; |
| | | //} |
| | | else |
| | | { |
| | | //映射模型 |
| | | SysMaterials mate = _mapper.Map<SysMaterials>(matedto); |
| | | //编辑 |
| | | //根据id获取物料信息 |
| | | var list = Db.Queryable<SysMaterials>().First(a => a.IsDel == "0" && a.Id == mate.Id); |
| | | //mate.CategoryNo = list.CategoryNo; |
| | | mate.Origin = list.Origin; |
| | | mate.CreateUser = list.CreateUser; |
| | | mate.UpdateTime = Db.GetDate(); |
| | | mate.CreateTime = list.CreateTime; |
| | | |
| | | int i = Db.Updateable(mate).ExecuteCommand(); |
| | | return i; |
| | | } |
| | | throw Oops.Bah("临期天数不可大于365及小于30"); |
| | | } |
| | | catch (Exception ex) |
| | | else if (string.IsNullOrWhiteSpace(matedto.PackagNo)) |
| | | { |
| | | //抛出异常 |
| | | throw new Exception(ex.Message); |
| | | throw Oops.Bah("包装不能为空"); |
| | | } |
| | | //映射模型 |
| | | SysMaterials mate = _mapper.Map<SysMaterials>(matedto); |
| | | //编辑 |
| | | //根据id获取物料信息 |
| | | var modMaterial = await Db.Queryable<SysMaterials>().FirstAsync(a => a.IsDel == "0" && a.Id == mate.Id); |
| | | //mate.CategoryNo = list.CategoryNo; |
| | | mate.Origin = modMaterial.Origin; |
| | | mate.CreateUser = modMaterial.CreateUser; |
| | | mate.UpdateTime = DateTime.Now; |
| | | mate.UpdateUser = _userManager.UserId; |
| | | mate.CreateTime = modMaterial.CreateTime; |
| | | int i = Db.Updateable(mate).ExecuteCommand(); |
| | | return i; |
| | | } |
| | | |
| | | #region 包装 单位 |
| | |
| | | /// 获取计量单位信息列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<SysUnit> GetUnitList() |
| | | public async Task<List<SysUnit>> GetUnitList() |
| | | { |
| | | List<SysUnit> unitlist = _mate.GetUnitList(); |
| | | return unitlist; |
| | | return await Db.Queryable<SysUnit>().Where(s => s.IsDel == "0").ToListAsync(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取包装信息列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<SysPackag> GetPackagList() |
| | | public async Task<List<SysPackag>> GetPackagList() |
| | | { |
| | | List<SysPackag> packlist = _mate.GetPackagList(); |
| | | return packlist; |
| | | return await Db.Queryable<SysPackag>().Where(s => s.IsDel == "0").ToListAsync(); |
| | | } |
| | | |
| | | #endregion |