using Dm; using Model.ModelDto.SysDto; using SqlSugar; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using WMS.Entity.Context; using WMS.Entity.SysEntity; using WMS.IDAL.ISysInterface; namespace WMS.DAL.SysInfrastructure { public class MaterialsRepository : BaseRepository, IMaterialsRepository { private static readonly SqlSugarScope Db = DataContext.Db; public MaterialsRepository() : base(Db) { } #region wms /// /// 获取物料信息列表 /// /// 物料号 /// 物料名称 /// 审核状态 /// 类型 /// 是否受控 /// 是否免检 /// 存储环境 /// public List GetMateList(string skuNo, string SkuName, string AuditStatusNo, string Type, string IsControlled, string IsInspect, string Environment) { string str = "select mate.*,user1.RealName CreateUserName,pack.PackagName PackagName,unit.UnitName UnitName from SysMaterials mate left join SysUserInfor user1 on mate.CreateUser = user1.Id left join SysPackag pack on mate.PackagNo = pack.PackagNo left join SysUnit unit on mate.UnitNo = unit.UnitNo where mate.IsDel = @isdel"; //判断物料号是否为空 if (skuNo != "undefined") { if (!string.IsNullOrEmpty(skuNo)) { str += " and mate.SkuNo like @skuno"; } } //判断物料名称 if (SkuName != "undefined") { if (!string.IsNullOrEmpty(SkuName)) { str += " and mate.SkuName like @skuname"; } } //判断审核状态 if (AuditStatusNo != "undefined") { if (!string.IsNullOrEmpty(AuditStatusNo)) { str += " and mate.AuditStatusNo = @auditstatusno"; } } //判断类型 if (Type != "undefined") { if (!string.IsNullOrEmpty(Type)) { str += " and mate.Type = @type"; } } //判断是否受控 if (IsControlled != "undefined") { if (!string.IsNullOrEmpty(IsControlled)) { str += " and mate.IsControlled = @iscontrolled"; } } //判断是否免检 if (IsInspect != "undefined") { if (!string.IsNullOrEmpty(IsInspect)) { str += " and mate.IsInspect = @isinspect"; } } //判断存储环境 if (Environment != "undefined") { if (!string.IsNullOrEmpty(Environment)) { str += " and mate.Environment = @environment"; } } str += " order by mate.SkuNo"; List matedto = Db.Ado.SqlQuery(str, new { isdel = "0", //是否删除 skuno = "%" + skuNo + "%", //物料号 skuname = "%" + SkuName + "%",// 物料名称 auditstatusno = AuditStatusNo,// 审核状态 type = Type,// 类型 iscontrolled = IsControlled,// 是否受控 isinspect = IsInspect,// 是否免检 environment = Environment,// 存储环境 }); return matedto; } /// /// 根据id查询物料信息 /// /// /// public SysMaterials GetMateById(int id) { string str = "select * from SysMaterials where IsDel = @isdel and Id = @id"; SysMaterials mate = Db.Ado.SqlQuerySingle(str, new { isdel = "0", //是否删除 id //id }); return mate; } /// /// 根据编号查询物料信息 /// /// 物料编号 /// public List GetMateByNo(string SkuNo) { string str = "select * from SysMaterials where SkuNo = @skuno"; List mate = Db.Ado.SqlQuery(str, new { skuno = SkuNo //物料编号 }); return mate; } /// /// 新增物料信息 /// /// 物料实体 /// public async Task AddMate(SysMaterials mate) { //string str = "insert into SysMaterials values(@skuno, @skuname, @standard, @auditstatusno, @type, @iscontrolled, @isinspect, @origin, @unitno, @packagno, @environment, @weight, @warranty, @price,null,null, @demo, @isdel, @createTime, @createUser, null, null,@adventtime,@lowinventory)"; //mate.CreateTime = Db.GetDate(); //int i = await Db.Ado.ExecuteCommandAsync(str, new //{ // skuno = mate.SkuNo, //物料号 // skuname = mate.SkuName, //物料名称 // standard = mate.Standard, //规格 // auditstatusno = "0", //审核状态 // type = mate.Type, //类型 // iscontrolled = "1", //是否受控 // isinspect = "0", //是否免检 // origin = "WMS", //来源 // unitno = mate.UnitNo, //单位 // packagno = mate.PackagNo, //包装 // environment = mate.Environment, //存储环境 // weight = mate.Weight, //理论重量 // warranty = mate.Warranty, //保质期 // price = mate.Price, //理论单价 // demo = mate.Demo, //备注 // isdel = "0", //是否删除 // createtime = Db.GetDate(), //创建时间 // createUser = mate.CreateUser, //创建人 // adventtime = mate.AdventTime, //临期 // lowinventory = mate.LowInventory //低库存 //}); mate.AuditStatusNo = "0"; int i = await Db.Insertable(mate).ExecuteCommandAsync(); return i; } /// /// 删除物料信息 /// /// 物料实体 /// public async Task DelMate(SysMaterials mate) { //string str = "update SysMaterials set IsDel = @isdel, UpdateTime = @updatetime, UpdateUser = @updateuser where Id = @id"; //int i = await Db.Ado.ExecuteCommandAsync(str, new //{ // isdel = "1", //是否删除 // updatetime = Db.GetDate(), //更改时间 // updateuser = mate.UpdateUser, //更改人 // id = mate.Id //id //}); mate.IsDel = "1"; mate.UpdateTime = Db.GetDate(); //更改时间 int i = await Db.Updateable(mate).ExecuteCommandAsync(); return i; } /// /// 编辑物料信息 /// /// 物料实体 /// public async Task ExitMate(SysMaterials mate) { //string str = "update SysMaterials set SkuName = @skuname, Standard = @standard, AuditStatusNo = @auditstatusno, Type = @type, IsControlled = @iscontrolled, IsInspect = @isinspect, UnitNo = @unitno, PackagNo = @packagno, Environment = @environment, Weight = @weight, Warranty = @warranty, Price = @price, Demo = @demo, UpdateTime = @updatetime, UpdateUser = @updateuser,AdventTime = @adventtime,LowInventory = @lowinventory where Id = @id"; //int i = await Db.Ado.ExecuteCommandAsync(str, new //{ // skuname = mate.SkuName, //物料名称 // standard = mate.Standard, //规格 // auditstatusno = mate.AuditStatusNo, //审核状态 // type = mate.Type, //类型 // iscontrolled = mate.IsControlled, //是否受控 // isinspect = mate.IsInspect, //是否免检 // unitno = mate.UnitNo, //单位 // packagno = mate.PackagNo, //包装 // environment = mate.Environment, //存储环境 // weight = mate.Weight, //理论重量 // warranty = mate.Warranty, //保质期 // price = mate.Price, //理论单价 // demo = mate.Demo, //备注 // updatetime = Db.GetDate(), //更改时间 // updateuser = mate.UpdateUser, //更改人 // adventtime = mate.AdventTime, //临期 // lowinventory = mate.LowInventory, //低库存 // id = mate.Id //id //}); int i = await Db.Updateable(mate).ExecuteCommandAsync(); return i; } #region 包装 单位 /// /// 获取计量单位信息列表 /// /// public List GetUnitList() { string str = "select * from SysUnit where IsDel = @isdel"; List unitlist = Db.Ado.SqlQuery(str, new { isdel = "0" //是否删除 }); return unitlist; } /// /// 获取包装信息列表 /// /// public List GetPackagList() { string str = "select * from SysPackag where IsDel = @isdel"; List packlist = Db.Ado.SqlQuery(str, new { isdel = "0" //是否删除 }); return packlist; } #endregion #endregion #region erp /// /// 获取erp数据 /// /// public List GetERPList() { string str = "select * from SysERPTest where isdel = @isdel"; List list = Db.Ado.SqlQuery(str, new { isdel = "0" //是否删除 }); return list; } /// /// 根据id获取erp数据 /// /// id /// public SysERPTest GetERPListById(int id) { string str = "select * from SysERPTest where isdel = @isdel and Id = @id"; SysERPTest list = Db.Ado.SqlQuerySingle(str, new { id, //id isdel = "0" //是否删除 }); return list; } /// /// 新增erp数据 /// /// erp测试实体 /// public async Task AddERP(SysERPTest erp) { string str = "Insert into SysERPTest values(@skuno, @skuname, @standard, @auditstatusno, @type, @iscontrolled, @isinspect, @origin, @unitno, @packagno, @environment, @weight, @warranty, @price, @demo, @isdel, @createTime, @createUser, null, null)"; int i = await Db.Ado.ExecuteCommandAsync(str, new { skuno = erp.SkuNo, //物料号 skuname = erp.SkuName, //物料名称 standard = erp.Standard, //规格 auditstatusno = "0", //审核状态 type = erp.Type, //类型 iscontrolled = "1", //是否受控 isinspect = "0", //是否免检 origin = "ERP", //来源 unitno = erp.UnitNo, //单位 packagno = erp.PackagNo, //包装 environment = erp.Environment, //存储环境 weight = erp.Weight, //理论重量 warranty = erp.Warranty, //保质期 price = erp.Price, //理论单价 demo = erp.Demo, //备注 isdel = "0", //是否删除 createtime = Db.GetDate(), //创建时间 createUser = erp.CreateUser //创建人 }); return i; } /// /// 删除erp数据 /// /// erp测试实体 /// public async Task DelERP(SysERPTest erp) { string str = "update SysERPTest set IsDel = @isdel, UpdateTime = @updatetime, UpdateUser = @updateuser where Id = @id"; int i = await Db.Ado.ExecuteCommandAsync(str, new { isdel = "1", //是否删除 updatetime = Db.GetDate(), //更改时间 updateuser = erp.UpdateUser, //更改人 id = erp.Id //id }); return i; } /// /// 编辑erp数据 /// /// erp测试实体 /// public async Task EditERP(SysERPTest erp) { string str = "update SysERPTest set SkuName = @skuname, Standard = @standard, AuditStatusNo = @auditstatusno, Type = @type, IsControlled = @iscontrolled, IsInspect = @isinspect, Origin = @origin, UnitNo = @unitno, PackagNo = @packagno, Environment = @environment, Weight = @weight, Warranty = @warranty, Price = @price, Demo = @demo, UpdateTime = @updatetime, UpdateUser = @updateuser where Id = @id"; int i = await Db.Ado.ExecuteCommandAsync(str, new { skuname = erp.SkuName, //物料名称 standard = erp.Standard, //规格 auditstatusno = erp.AuditStatusNo, //审核状态 type = erp.Type, //类型 iscontrolled = erp.IsControlled, //是否受控 isinspect = erp.IsInspect, //是否免检 origin = erp.Origin, //来源 unitno = erp.UnitNo, //单位 packagno = erp.PackagNo, //包装 environment = erp.Environment, //存储环境 weight = erp.Weight, //理论重量 warranty = erp.Warranty, //保质期 price = erp.Price, //理论单价 demo = erp.Demo, //备注 updatetime = Db.GetDate(), //更改时间 updateuser = erp.UpdateUser, //更改人 id = erp.Id //id }); return i; } #endregion } }