using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using System.Security.Permissions;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Dm;
|
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 StorageAreaServer : DbHelper<SysStorageArea>, IStorageAreaServer
|
{
|
private static readonly SqlSugarScope Db = DataContext.Db;
|
public IStorageAreaRepository AreaRst { get; set; }
|
public StorageAreaServer(IStorageAreaRepository areaRst) : base(Db)
|
{
|
AreaRst = areaRst;
|
}
|
|
/// <summary>
|
/// 获取库区域信息
|
/// </summary>
|
/// <param name="areaName">区域名称</param>
|
/// <param name="wareHouseNo">仓库编号</param>
|
/// <param name="status">状态</param>
|
/// <param name="type">类别</param>
|
/// <param name="page"></param>
|
/// <param name="limit"></param>
|
/// <param name="count"></param>
|
/// <returns></returns>
|
public List<AreaDto> GetStorageAreaList(string areaName, string wareHouseNo, string status, string type, int page, int limit, out int count)
|
{
|
try
|
{
|
//创建表达式
|
Expression<Func<SysStorageArea, bool>> item = Expressionable.Create<SysStorageArea>()
|
.AndIF(!string.IsNullOrWhiteSpace(areaName), it => it.AreaName.Contains(areaName.Trim()))
|
.AndIF(!string.IsNullOrWhiteSpace(wareHouseNo), it => it.WareHouseNo == wareHouseNo)
|
.AndIF(!string.IsNullOrWhiteSpace(status), it => it.Status == status)
|
.AndIF(!string.IsNullOrWhiteSpace(type), it => it.Type == type)
|
.ToExpression();//注意 这一句 不能少
|
|
|
var data = AreaRst.GetAllByOrderPageAsync(item, limit, page, out int counts)
|
.Includes(x => x.WareHouseInfo)
|
.Includes(x => x.TemperatureInfo)
|
.Includes(x => x.CreateUserInfo)
|
.Includes(x => x.UpdateUserInfo).ToList();
|
count = counts;
|
return data.Select(m => new AreaDto()
|
{
|
Id = m.Id,
|
AreaNo = m.AreaNo,
|
AreaName = m.AreaName,
|
WareHouseNo = m.WareHouseNo,
|
WareHouseName = m.WareHouseInfo == null ? "" : m.WareHouseInfo.WareHouseName,
|
RoadwayNo = m.RoadwayNo,
|
Status = m.Status,
|
Priority = m.Priority,
|
Type = m.Type,
|
TypeName = GetTypeName(m.Type),//类别名称
|
Temp = m.Temperature,
|
TempName = m.TemperatureInfo == null ? "" : m.TemperatureInfo.DictName,
|
DeviceCode=m.DeviceCode,
|
CreateTime = m.CreateTime,
|
CreateUserName = m.CreateUserInfo == null ? "" : m.CreateUserInfo.RealName,
|
UpdateTime = m.UpdateTime,
|
UpdateUserName = m.UpdateUserInfo == null ? "" : m.UpdateUserInfo.RealName
|
}).OrderBy(w=>w.WareHouseNo).OrderBy(w => w.AreaNo).ToList();
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
/// <summary>
|
/// 获取单条库区域信息
|
/// </summary>
|
/// <param name="id">ID</param>
|
/// <returns></returns>
|
public SysStorageArea GetStorageArea(int id)
|
{
|
try
|
{
|
var data = AreaRst.GetOneById(id);
|
return data;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取单条库区域信息
|
/// </summary>
|
/// <param name="id">ID</param>
|
/// <returns></returns>
|
public SysStorageArea GetStorageMaxArea()
|
{
|
try
|
{
|
var data = Db.Queryable<SysStorageArea>().Where(a => a.IsDel == "0" && a.WareHouseNo == "W01").OrderByDescending(a => a.CreateTime).First();
|
return data;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取区域信息(根据仓库号)
|
/// </summary>
|
/// <param name="wareHouseNo">仓库号</param>
|
/// <returns></returns>
|
public List<SysStorageArea> GetStorageAreaByHouseNo(string wareHouseNo)
|
{
|
try
|
{
|
var data = AreaRst.GetAllAsync().ToList();
|
if (!string.IsNullOrWhiteSpace(wareHouseNo))
|
{
|
data = data.Where(m => m.WareHouseNo == wareHouseNo).ToList();
|
}
|
return data;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 修改库区域信息
|
/// </summary>
|
/// <param name="model">区域实体</param>
|
/// <returns>是否成功</returns>
|
public string InsertStorageArea(SysStorageArea model)
|
{
|
try
|
{
|
string str = "";
|
|
var area = Db.Queryable<SysStorageArea>().First(a => a.IsDel == "0" && a.AreaNo == model.AreaNo);
|
if (area != null)
|
{
|
throw new Exception("当前区域编码对应的区域已存在");
|
}
|
if (!string.IsNullOrEmpty(model.DeviceCode))
|
{
|
var area2 = Db.Queryable<SysStorageArea>().First(a => a.IsDel == "0" && a.DeviceCode == model.AreaNo);
|
if (area2 != null)
|
{
|
throw new Exception("当前设备编码对应的区域已存在");
|
}
|
}
|
Db.BeginTran();
|
|
//新增区域信息
|
SysStorageArea list = new SysStorageArea()
|
{
|
AreaNo = model.AreaNo, //区域编码
|
AreaName = model.AreaName, //区域名称
|
DeviceCode=model.DeviceCode,//设备编码
|
WareHouseNo = model.WareHouseNo, //所属仓库
|
RoadwayNo = null, //所属巷道
|
Status = model.Status, //是否启用
|
Priority = model.Priority, //优先级
|
Type = model.Type, //存储类别
|
Temperature = model.Temperature, //存储环境
|
IsDel = "0", //是否删除
|
CreateUser = model.CreateUser, //创建人
|
CreateTime = Db.GetDate(), //创建时间
|
UpdateUser = null, //修改人
|
UpdateTime = null, //修改时间
|
};
|
Db.Insertable(list).ExecuteCommand();
|
|
Db.CommitTran();
|
|
str = "添加成功";
|
return str;
|
}
|
catch (Exception e)
|
{
|
Db.RollbackTran();
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 修改库区域信息
|
/// </summary>
|
/// <param name="id">ID</param>
|
/// <param name="name">区域名称</param>
|
/// <param name="priority">优先级</param>
|
/// <param name="type">类别</param>
|
/// <param name="temp">存储环境</param>
|
/// <param name="userId">操作人</param>
|
/// <returns>是否成功</returns>
|
public bool EditStorageArea(int id, string name, int priority, string type, string temp,string deviceCode, int userId)
|
{
|
try
|
{
|
//判断除当前id信息以外是否含有编号和名称
|
//var bol = AreaRst.GetAllAsync()
|
// .Any(m => m.Id != id && m.AreaName == name.Trim());
|
//if (bol)
|
//{
|
// throw new Exception("当前区域号或区域名称已存在");
|
//}
|
if (!string.IsNullOrEmpty(deviceCode))
|
{
|
var bol2 = AreaRst.GetAllAsync().Any(m => m.Id != id && m.DeviceCode == deviceCode.Trim());
|
if (bol2)
|
{
|
throw new Exception("当前设备编码对应的区域已存在");
|
}
|
}
|
|
var area = AreaRst.GetOneById(id);
|
if (area == null)
|
{
|
throw new Exception("为查询到当前区域信息");
|
}
|
|
area.AreaName = name;
|
area.Priority = priority;
|
area.Type = type;
|
area.Temperature = temp;
|
area.DeviceCode = deviceCode;
|
area.UpdateUser = userId;
|
area.UpdateTime = DateTime.Now;
|
var num = AreaRst.Edit(area);
|
if (num > 0)
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
/// <summary>
|
/// 修改区域状态
|
/// </summary>
|
/// <param name="id">Id</param>
|
/// <param name="status">状态 0 启用 1停用</param>
|
/// <param name="userId">操作人ID</param>
|
/// <returns></returns>
|
public bool EditStorageAreaStatus(int id, string status, int userId)
|
{
|
try
|
{
|
var area = AreaRst.GetOneById(id);
|
if (area == null)
|
{
|
throw new Exception("为查询到当前区域信息");
|
}
|
|
area.Status = status;
|
area.UpdateUser = userId;
|
area.UpdateTime = DateTime.Now;
|
var num = AreaRst.EditStorageAreaStatus(area);
|
if (num > 0)
|
{
|
return true;
|
}
|
else
|
{
|
return false;
|
}
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
|
/// <summary>
|
/// 获取区域类型
|
/// </summary>
|
/// <param name="code">类别编号</param>
|
/// <returns></returns>
|
public string GetTypeName(string code)
|
{
|
if (string.IsNullOrWhiteSpace(code))
|
{
|
return "";
|
}
|
else
|
{
|
var str = "";
|
switch (code)
|
{
|
case "0":
|
str = "净桶区";
|
break;
|
case "1":
|
str = "满桶区";
|
break;
|
case "2":
|
str = "脏桶区";
|
break;
|
case "3":
|
str = "转运区";
|
break;
|
case "4":
|
str = "设备区";
|
break;
|
default:
|
str = "";
|
break;
|
}
|
|
return str;
|
}
|
}
|
}
|
|
}
|