| | |
| | | using AutoMapper; |
| | | using Model.ModelDto.SysDto; |
| | | using SqlSugar; |
| | | using WMS.DAL; |
| | | using WMS.Entity.Context; |
| | | using WMS.Entity.SysEntity; |
| | | using WMS.IBLL.ISysServer; |
| | | using WMS.IDAL.ISysInterface; |
| | | |
| | | namespace WMS.BLL.SysServer |
| | | { |
| | | public class MaterialsServer : IMaterialsServer |
| | | public class MaterialsServer : DbHelper<SysMaterialCategory>, IMaterialsServer |
| | | { |
| | | /// <summary> |
| | | /// 依赖注入 |
| | | /// </summary> |
| | | public IMaterialsRepository _mate { get; set; } |
| | | private readonly IMapper _mapper; |
| | | private static readonly SqlSugarScope Db = DataContext.Db; |
| | | /// <summary> |
| | | /// 构造函数 |
| | | /// </summary> |
| | | /// <param name="mate">物料编码</param> |
| | | /// <param name="mapper">automapper</param> |
| | | public MaterialsServer(IMaterialsRepository mate, IMapper mapper) |
| | | public MaterialsServer(IMaterialsRepository mate, IMapper mapper) : base(Db) |
| | | { |
| | | _mate = mate; //物料编码 |
| | | _mapper = mapper; //automapper |
| | |
| | | /// <param name="isControlled">是否受控</param> |
| | | /// <param name="isInspect">是否免检</param> |
| | | /// <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) |
| | | public 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); |
| | | List<MaterialsDto> matedto = _mate.GetMateList(skuNo, skuName, auditStatusNo, type, isControlled, isInspect, environment, categoryNo); |
| | | return matedto; |
| | | } |
| | | |
| | |
| | | { |
| | | //映射模型 |
| | | SysMaterials mate = _mapper.Map<SysMaterials>(matedto); |
| | | //判断物料号是否唯一 |
| | | int count = GetMateByNo(mate.SkuNo); |
| | | int i = 0; |
| | | if (matedto.AdventTime > 365 && matedto.AdventTime < 30) |
| | | { |
| | | return 2; |
| | | } |
| | | //else if (matedto.LowInventory > 1000) |
| | | //{ |
| | | // return 4; |
| | | //} |
| | | else |
| | | { |
| | | if (count > 0) |
| | | { |
| | | i = 3; |
| | | } |
| | | else if (count == 0) |
| | | { |
| | | //新增 |
| | | i = await _mate.AddMate(mate); |
| | | } |
| | | return i; |
| | | } |
| | | 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.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); |
| | | } |
| | |
| | | //映射模型 |
| | | SysMaterials mate = _mapper.Map<SysMaterials>(matedto); |
| | | //编辑 |
| | | int i = await _mate.ExitMate(mate); |
| | | //根据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; |
| | | } |
| | | } |