using Model.ModelDto;
|
using Model.ModelDto.BllSoDto;
|
using Model.ModelDto.SysDto;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Diagnostics;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using System.Text;
|
using WMS.DAL;
|
using WMS.Entity.BllSoEntity;
|
using WMS.Entity.Context;
|
using WMS.Entity.SysEntity;
|
using WMS.IBLL.ISysServer;
|
|
namespace WMS.BLL.SysServer
|
{
|
/// <summary>
|
/// 物料类别管理方法
|
/// </summary>
|
public class MaterialCategoryServer : DbHelper<SysMaterialCategory>, IMaterialCategoryServer
|
{
|
|
private static readonly SqlSugarScope Db = DataContext.Db;
|
public MaterialCategoryServer() : base(Db)
|
{
|
}
|
|
/// <summary>
|
/// 获取物料类别信息
|
/// </summary>
|
/// <param name="categoryName">类别名称</param>
|
/// <param name="areaNo">区域编码</param>
|
/// <returns></returns>
|
/// <exception cref="Exception"></exception>
|
public List<MaterialCategoryDto> GetMaterialCategories(string categoryName, string areaNo)
|
{
|
try
|
{
|
//var list = Db.Queryable<MaterialCategoryDto>()
|
// .WhereIF(!string.IsNullOrWhiteSpace(categoryName), a => a.CategoryName == categoryName)
|
// .WhereIF(!string.IsNullOrWhiteSpace(areaNo), a => a.AreaNo == areaNo)
|
// .Where(a => a.IsDel == "0").ToList();
|
|
|
Expression<Func<SysMaterialCategory, bool>> item = Expressionable.Create<SysMaterialCategory>()
|
.AndIF(!string.IsNullOrWhiteSpace(categoryName), it => it.CategoryName.Contains(categoryName))
|
.AndIF(!string.IsNullOrWhiteSpace(areaNo), it => it.AreaNo.Contains(areaNo))
|
.And(it => it.IsDel == "0")
|
.ToExpression();//注意 这一句 不能少
|
|
var data = GetAllWhereAsync(item)
|
.Includes(x => x.CreateUserInfo)
|
.Includes(x => x.UpdateUserInfo).ToList();
|
//.LeftJoin<SysWareHouse>((a, b) => a.WareHouseNo == b.WareHouseNo)
|
//.LeftJoin<SysUserInfor>((a, b, c) => a.CreateUser == c.Id)
|
//.LeftJoin<SysUserInfor>((a, b, c, d) => a.UpdateUser == d.Id)
|
var data2 = data.Select(a => new MaterialCategoryDto()
|
{
|
Id = a.Id,
|
|
CategoryNo = a.CategoryNo, //类别编码
|
CategoryName = a.CategoryName, //类别名称
|
|
AreaNo = a.AreaNo, //区域号
|
AreaName = GetStorageArea(a.AreaNo), //区域名称
|
|
//WareHouseNo = a.WareHouseNo, //仓库号
|
//WareHouseName = a.WareHouseInfo.WareHouseName, //仓库名称
|
|
Demo = a.Demo, //备注
|
IsDel = a.IsDel,
|
|
CreateName = a.CreateUserInfo.RealName,
|
UpdateName = a.UpdateUserInfo == null ? "" : a.UpdateUserInfo.RealName,
|
|
CreateTime = a.CreateTime,
|
UpdateTime = a.UpdateTime,
|
}).ToList();
|
|
|
|
return data2;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取物料类别下拉菜单信息
|
/// </summary>
|
/// <returns></returns>
|
/// <exception cref="Exception"></exception>
|
public List<SysMaterialCategory> GetMaterialCategories()
|
{
|
try
|
{
|
//var list = Db.Queryable<MaterialCategoryDto>()
|
// .WhereIF(!string.IsNullOrWhiteSpace(categoryName), a => a.CategoryName == categoryName)
|
// .WhereIF(!string.IsNullOrWhiteSpace(areaNo), a => a.AreaNo == areaNo)
|
// .Where(a => a.IsDel == "0").ToList();
|
|
var list = Db.Queryable<SysMaterialCategory>().Where(a => a.IsDel == "0").ToList();
|
return list;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 根据Id获取物料类别信息
|
/// </summary>
|
/// <param name="Id">Id</param>
|
/// <returns></returns>
|
/// <exception cref="Exception"></exception>
|
public SysMaterialCategory GetMaterialCategoriesById(int Id)
|
{
|
try
|
{
|
var list = Db.Queryable<SysMaterialCategory>().Where(a => a.IsDel == "0" && a.Id == Id).First();
|
return list;
|
}
|
catch (Exception ex)
|
{
|
|
throw new Exception(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取巷道信息
|
/// </summary>
|
/// <param name="AreaNo">巷道号</param>
|
/// <returns></returns>
|
/// <exception cref="Exception"></exception>
|
public string GetStorageArea(string AreaNo)
|
{
|
try
|
{
|
string str = "";
|
if (string.IsNullOrWhiteSpace(AreaNo))
|
{
|
return str;
|
}
|
else
|
{
|
//判断是否需要进行分割字符串
|
var arr = AreaNo.Split(',');
|
//获取区域信息
|
var list = Db.Queryable<SysStorageArea>().Where(a => a.IsDel == "0" && arr.Contains(a.AreaNo)).ToList();
|
//拼接字符串
|
|
foreach (var item in list)
|
{
|
str += item.AreaName + ";";
|
}
|
return str;
|
}
|
|
}
|
catch (Exception ex)
|
{
|
|
throw new Exception("获取巷道信息异常" + ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取库区域信息
|
/// </summary>
|
/// <returns></returns>
|
public List<SysStorageArea> GetStorageAreaList()
|
{
|
try
|
{
|
var list = Db.Queryable<SysStorageArea>().Where(a => a.IsDel == "0").ToList();
|
return list;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 新增类别信息
|
/// </summary>
|
/// <param name="category">物料类别实体</param>
|
/// <returns></returns>
|
/// <exception cref="Exception"></exception>
|
public string InsertMaterialCategories(SysMaterialCategory category)
|
{
|
try
|
{
|
string msg = "";
|
//获取类别信息
|
var categoryInfo = Db.Queryable<SysMaterialCategory>().First(a => a.IsDel == "0" && a.CategoryNo == category.CategoryNo);
|
//获取区域信息
|
var area = Db.Queryable<SysStorageArea>().Where(a => category.AreaNo.Contains(a.AreaNo) && a.IsDel == "0").ToList();
|
if (categoryInfo != null)
|
{
|
throw new Exception("当前类别信息已被创建,请重新填写信息!");
|
}
|
if (area.Count == 0)
|
{
|
throw new Exception("当前选择区域信息异常,请重新选择或联系管理员!");
|
}
|
|
Db.BeginTran();
|
SysMaterialCategory list = new SysMaterialCategory()
|
{
|
CategoryNo = category.CategoryNo, //类别编码
|
CategoryName = category.CategoryName, //类别名称
|
|
AreaNo = category.AreaNo, //区域编码
|
Demo = category.Demo, //备注
|
|
IsDel = "0", //是否删除
|
CreateUser = category.CreateUser, //创建人
|
CreateTime = Db.GetDate(), //创建时间
|
};
|
|
Db.Insertable(list).ExecuteCommand();
|
|
|
Db.CommitTran();
|
|
msg = "新增类别信息成功!";
|
return msg;
|
|
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw new Exception(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 编辑类别信息
|
/// </summary>
|
/// <param name="category">物料类别实体</param>
|
/// <returns></returns>
|
/// <exception cref="Exception"></exception>
|
public string ExitMaterialCategories(SysMaterialCategory category)
|
{
|
try
|
{
|
string msg = "";
|
//获取类别信息
|
var categoryInfo = Db.Queryable<SysMaterialCategory>().First(a => a.IsDel == "0" && a.Id == category.Id);
|
//获取类别对应物料信息
|
var matelist = Db.Queryable<SysMaterials>().Where(a=>a.IsDel == "0" && a.CategoryNo == categoryInfo.CategoryNo).ToList();
|
//获取区域信息
|
var area = Db.Queryable<SysStorageArea>().First(a => category.AreaNo.Contains(a.AreaNo) && a.IsDel == "0");
|
|
if (area == null)
|
{
|
throw new Exception("当前选择区域信息异常,请重新选择或联系管理员!");
|
}
|
|
Db.BeginTran();
|
categoryInfo.CategoryNo = category.CategoryNo; //类别编码
|
categoryInfo.CategoryName = category.CategoryName; //类别名称
|
categoryInfo.AreaNo = category.AreaNo; //区域编码
|
categoryInfo.Demo = category.Demo; //备注
|
categoryInfo.UpdateUser = category.CreateUser; //更改人
|
categoryInfo.UpdateTime = Db.GetDate(); //更改时间
|
|
Db.Updateable(categoryInfo).ExecuteCommand();
|
|
foreach (var item in matelist)
|
{
|
item.CategoryNo = categoryInfo.CategoryNo;
|
}
|
Db.Updateable(matelist).ExecuteCommand();
|
|
Db.CommitTran();
|
|
msg = "编辑类别信息成功!";
|
return msg;
|
|
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw new Exception(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 删除类别信息
|
/// </summary>
|
/// <param name="category">物料类别实体</param>
|
/// <returns></returns>
|
/// <exception cref="Exception"></exception>
|
public string DeleteMaterialCategories(MaterialCategoryDto category)
|
{
|
try
|
{
|
string msg = "";
|
//获取类别信息
|
var categoryInfo = Db.Queryable<SysMaterialCategory>().First(a => a.IsDel == "0" && a.Id == category.Id);
|
//获取区域信息
|
var area = Db.Queryable<SysStorageArea>().First(a => categoryInfo.AreaNo.Contains(a.AreaNo) && a.IsDel == "0");
|
//获取是否存在有物料已绑定当前类别
|
var mate = Db.Queryable<SysMaterials>().Where(a => a.IsDel == "0" && a.CategoryNo == categoryInfo.CategoryNo).ToList();
|
|
//判断是否存在有物料已绑定当前类别
|
if (mate.Count > 0)
|
{
|
throw new Exception("当前类别已有物料进行绑定,无法删除!");
|
}
|
if (categoryInfo == null)
|
{
|
throw new Exception("当前类别信息已被删除,请重新选择!");
|
}
|
if (area == null)
|
{
|
throw new Exception("当前选择区域信息异常,请重新选择或联系管理员!");
|
}
|
|
Db.BeginTran();
|
|
categoryInfo.IsDel = "1";
|
categoryInfo.UpdateUser = int.Parse(category.UpdateUser);
|
categoryInfo.UpdateTime = Db.GetDate();
|
|
Db.Updateable(categoryInfo).ExecuteCommand();
|
|
Db.CommitTran();
|
|
msg = "删除类别信息成功!";
|
return msg;
|
|
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw new Exception(ex.Message);
|
}
|
}
|
}
|
}
|