!提交代码

This commit is contained in:
hehaibing-1996
2024-04-15 18:43:28 +08:00
commit e89b64ea3a
232 changed files with 22292 additions and 0 deletions

105
WCS.BLL/Config/LocalFile.cs Normal file
View File

@ -0,0 +1,105 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS.BLL.Config
{
/// <summary>
/// 本地文件
/// </summary>
public class LocalFile
{
/// <summary>
/// 程序运行名称BaseUi.exe
/// </summary>
public static readonly string AppName = AppDomain.CurrentDomain.FriendlyName;
/// <summary>
/// 程序运行目录
/// </summary>
public static readonly string AppDir = AppDomain.CurrentDomain.BaseDirectory;
/// <summary>
/// 数据目录
/// </summary>
public static readonly string DataDir = Path.Combine(AppDir, "data");
/// <summary>
/// 日志目录
/// </summary>
public static readonly string LogDir = Path.Combine(AppDir, "logs");
/// <summary>
/// 运行主程序
/// </summary>
public static readonly string AppPath = Path.Combine(AppDir, AppDomain.CurrentDomain.FriendlyName);
/// <summary>
/// 配置文件路径
/// </summary>
public static readonly string ConfigPath = Path.Combine(DataDir, "jsconfig.json");
/// <summary>
/// 货架模组编码正则表达式
/// </summary>
public static readonly string ModuleCodePattern = "^[ABCD][0-9]{2}-R[0-9]{1,2}C[0-9]{1,2}$";
static object lockConfig = new object();
//static JsConfig config;
///// <summary>
///// 配置信息
///// </summary>
//public static JsConfig Config
//{
// get
// {
// if (config != null)
// return config;
// else
// {
// try
// {
// if (File.Exists(ConfigPath))
// lock (lockConfig)
// config = JsonConvert.DeserializeObject<JsConfig>(File.ReadAllText(ConfigPath, Encoding.UTF8));
// else
// config = null;
// }
// catch (Exception)
// {
// config = null;
// }
// }
// return config ?? new JsConfig();
// }
//}
///// <summary>
///// 刷新配置信息。将本地的配置信息重新加载到内存中
///// </summary>
//public static void UpdateConfig()
//{
// if (File.Exists(ConfigPath))
// lock (lockConfig)
// config = JsonConvert.DeserializeObject<JsConfig>(File.ReadAllText(ConfigPath, Encoding.UTF8));
// else
// config = null;
//}
///// <summary>
///// 保存配置信息。将内存中的配置信息保存到本地
///// </summary>
//public static void SaveConfig()
//{
// try
// {
// lock (lockConfig)
// File.WriteAllText(ConfigPath, JsonConvert.SerializeObject(Config, Formatting.Indented), Encoding.UTF8);
// }
// catch (Exception ex)
// {
// UpdateConfig();
// throw ex;
// }
//}
}
}

View File

@ -0,0 +1,117 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.DAL.DbModels;
namespace WCS.BLL.DbModels
{
/// <summary>
/// 库存明细表
/// </summary>
[SugarTable("inventory_detail")]
public class InventoryDetail
{
/// <summary>
/// 主键 自增Id
/// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)]
public int Id { get; set; }
#region
/// <summary>
/// 入库的库位表ID
/// </summary>
[SugarColumn(ColumnName = "store_id", IsNullable = false, ColumnDescription = "库位ID")]
public int StoreId { get; set; }
/// <summary>
/// 入库的库位编码
/// </summary>
[SugarColumn(ColumnName = "store_code", Length = 50, IsNullable = false, ColumnDescription = "库位编码")]
public string StoreCode { get; set; }
[Navigate(NavigateType.OneToOne, nameof(StoreId))]
public StoreInfo StoreInfo { get; set; }
#endregion
#region
/// <summary>
/// 物料编码SN
/// </summary>
[SugarColumn(ColumnName = "mat_sn", Length = 200, IsNullable = false, ColumnDescription = "物料SN")]
public string MatSN { get; set; }
/// <summary>
/// 物料编码
/// </summary>
[SugarColumn(ColumnName = "mat_code", Length = 100, IsNullable = true, ColumnDescription = "物料编号")]
public string MatCode { get; set; }
/// <summary>
/// 物料名称
/// </summary>
[SugarColumn(ColumnName = "mat_name", Length = 150, IsNullable = true, ColumnDescription = "物料名称")]
public string MatName { get; set; }
/// <summary>
/// 物料规格
/// </summary>
[SugarColumn(ColumnName = "mat_spec", Length = 150, IsNullable = true, ColumnDescription = "物料规格")]
public string MatSpec { get; set; }
/// <summary>
/// 物料批次
/// </summary>
[SugarColumn(ColumnName = "mat_batch", Length = 150, IsNullable = true, ColumnDescription = "物料批次")]
public string MatBatch { get; set; }
/// <summary>
/// 物料数量
/// </summary>
[SugarColumn(ColumnName = "mat_qty", IsNullable = false, ColumnDescription = "物料数量")]
public int MatQty { get; set; }
/// <summary>
/// 物料供应商
/// </summary>
[SugarColumn(ColumnName = "mat_supplier", Length = 150, IsNullable = true, ColumnDescription = "物料供应商")]
public string? MatSupplier { get; set; }
/// <summary>
/// 物料客户
/// </summary>
[SugarColumn(ColumnName = "mat_customer", Length = 150, IsNullable = true, ColumnDescription = "物料客户")]
public string? MatCustomer { get; set; }
#endregion
/// <summary>
/// 入库时间
/// </summary>
[SugarColumn(ColumnName = "instore_time", IsNullable = false, ColumnDescription = "入库时间")]
public DateTime InstoreTime { get; set; } = DateTime.Now;
/// <summary>
/// 入库操作人
/// </summary>
[SugarColumn(ColumnName = "instore_user", Length = 100, IsNullable = true, ColumnDescription = "操作员")]
public string InstoreUser { get; set; }
/// <summary>
/// 物料是否已被锁定
/// </summary>
[SugarColumn(ColumnName = "is_locked", IsNullable = false, ColumnDescription = "物料是否已被锁定")]
public bool IsLocked { get; set; } = false;
/// <summary>
/// 序号
/// </summary>
[SugarColumn(IsIgnore = true)]
public int RowNumber { get; set; }
/// <summary>
/// 是否已经选择
/// </summary>
[SugarColumn(IsIgnore = true)]
public bool IsSelected { get; set; }
}
}

View File

@ -0,0 +1,121 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS.BLL.DbModels
{
///<summary>
///物料基础信息
///</summary>
[SugarTable("mat_base_info")]
public partial class MatBaseInfo
{
/// <summary>
/// Desc:
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 物料编码
/// </summary>
[SugarColumn(ColumnName = "mat_code", Length = 100, IsNullable = false, ColumnDescription = "物料编号")]
public string MatCode { get; set; }
/// <summary>
/// 物料名称
/// </summary>
[SugarColumn(ColumnName = "mat_name", Length = 150, IsNullable = false, ColumnDescription = "物料名称")]
public string MatName { get; set; }
/// <summary>
/// 物料规格
/// </summary>
[SugarColumn(ColumnName = "mat_spec", Length = 150, IsNullable = true, ColumnDescription = "物料规格")]
public string? MatSpec { get; set; }
/// <summary>
/// Desc:物料单位
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "mat_unit", Length = 100, IsNullable = true, ColumnDescription = "物料单位")]
public string? MatUnit { get; set; }
/// <summary>
/// 物料批次
/// </summary>
[SugarColumn(ColumnName = "mat_batch", Length = 150, IsNullable = true, ColumnDescription = "物料批次")]
public string? MatBatch { get; set; }
/// <summary>
/// 物料供应商
/// </summary>
[SugarColumn(ColumnName = "mat_supplier", Length = 150, IsNullable = true, ColumnDescription = "物料供应商")]
public string? MatSupplier { get; set; }
/// <summary>
/// 物料客户
/// </summary>
[SugarColumn(ColumnName = "mat_customer", Length = 150, IsNullable = true, ColumnDescription = "物料客户")]
public string? MatCustomer { get; set; }
/// <summary>
/// 物料数量
/// </summary>
[SugarColumn(ColumnName = "mat_qty", IsNullable = false, ColumnDescription = "物料数量")]
public int MatQty { get; set; } = 100;
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "modify_user", IsNullable = true, Length = 50, ColumnDescription = "更新人")]
public string? ModifyUser { get; set; }
/// <summary>
/// Desc:更新时间
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "modify_time", IsNullable = true, ColumnDescription = "更新时间")]
public DateTime? ModifyTime { get; set; } = DateTime.Now;
/// <summary>
/// 是否启用
/// </summary>
[SugarColumn(ColumnName = "is_enable", ColumnDescription = "是否启用")]
public bool IsEnable { get; set; } = true;
[SugarColumn(IsIgnore = true)]
public string IsEnableStr
{
get
{
if (IsEnable)
return "启用";
else
return "禁用";
}
}
/// <summary>
/// 用于绑定DataGrid中是否选择
/// </summary>
[SugarColumn(IsIgnore = true)]
public bool IsSelected { get; set; }
/// <summary>
/// 用于绑定中显示序号
/// </summary>
[SugarColumn(IsIgnore = true)]
public int RowNumber { get; set; }
}
}

View File

@ -0,0 +1,94 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS.BLL.DbModels
{
///<summary>
///物料信息表
///</summary>
[SugarTable("mat_info")]
public class MatInfo
{
/// <summary>
/// 主键 Id 自增
/// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 物料编码
/// </summary>
[SugarColumn(ColumnName = "mat_Sn", Length = 200, IsNullable = false, ColumnDescription = "物料唯一码")]
public string MatSn { get; set; }
/// <summary>
/// 物料编码
/// </summary>
[SugarColumn(ColumnName = "mat_code", Length = 100, IsNullable = false, ColumnDescription = "物料编号")]
public string MatCode { get; set; }
/// <summary>
/// 物料名称
/// </summary>
[SugarColumn(ColumnName = "mat_name", Length = 150, IsNullable = false, ColumnDescription = "物料名称")]
public string MatName { get; set; }
/// <summary>
/// 物料规格
/// </summary>
[SugarColumn(ColumnName = "mat_spec", Length = 150, IsNullable = true, ColumnDescription = "物料规格")]
public string? MatSpec { get; set; }
[SugarColumn(ColumnName = "mat_unit", Length = 100, IsNullable = true, ColumnDescription = "物料单位")]
public string? MatUnit { get; set; }
/// <summary>
/// 物料批次
/// </summary>
[SugarColumn(ColumnName = "mat_batch", Length = 150, IsNullable = true, ColumnDescription = "物料批次")]
public string? MatBatch { get; set; }
/// <summary>
/// 物料供应商
/// </summary>
[SugarColumn(ColumnName = "mat_supplier", Length = 150, IsNullable = true, ColumnDescription = "物料供应商")]
public string? MatSupplier { get; set; }
/// <summary>
/// 物料客户
/// </summary>
[SugarColumn(ColumnName = "mat_customer", Length = 150, IsNullable = true, ColumnDescription = "物料客户")]
public string? MatCustomer { get; set; }
/// <summary>
/// 物料数量
/// </summary>
[SugarColumn(ColumnName = "mat_qty", IsNullable = false, ColumnDescription = "物料数量")]
public int MatQty { get; set; }
/// <summary>
/// 是否启用
/// </summary>
[SugarColumn(ColumnName = "is_printed", ColumnDescription = "是否已打印")]
public bool IsPrinted { get; set; } = true;
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "modify_user", IsNullable = true, Length = 50, ColumnDescription = "更新人")]
public string? ModifyUser { get; set; }
/// <summary>
/// Desc:更新时间
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "modify_time", IsNullable = true, ColumnDescription = "更新时间")]
public DateTime? ModifyTime { get; set; } = DateTime.Now;
}
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.BLL.HardWare;
namespace WCS.DAL.DbModels
{
public partial class ModuleInfo
{
/// <summary>
/// 模组Id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 模组编码
/// </summary>
public string ModuleCode { get; set; }
/// <summary>
/// 货架Id
/// </summary>
public int ShelfId { get; set; }
/// <summary>
/// 货架编码
/// </summary>
public string ShelfCode { get; set; }
/// <summary>
/// 板子的Id
/// </summary>
public int BoardId { get; set; }
/// <summary>
/// 板子上有几个灯
/// </summary>
public int LightCount { get; set; }
/// <summary>
/// 板子所连接模块的Ip
/// </summary>
public string CleintIp { get; set; }
/// <summary>
/// 第几行
/// </summary>
public string R { get; set; }
/// <summary>
/// 第几列
/// </summary>
public string C { get; set; }
/// <summary>
/// 串联后大货架编码;大货架编码:未串联时是与货架编码是一对一的关系;串联后与货架编码是一对多
/// </summary>
public string Bigshelfcode { get; set; }
/// <summary>
/// 是否被禁用
/// </summary>
public bool IsEnable { get; set; }
public Mode CurentMode { get; set; } = Mode.;
}
}

View File

@ -0,0 +1,61 @@
using SqlSugar;
namespace WCS.BLL.DbModels
{
/// <summary>
/// 出库单据
/// </summary>
[SugarTable("out_order")]
public class OutOrder
{
/// <summary>
/// 主键 自增Id
/// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 出库单据号
/// </summary>
[SugarColumn(ColumnName = "order_number", Length = 50, IsNullable = false, ColumnDescription = "出库单据号")]
public string OrderNumber { get; set; }
/// <summary>
/// 单据状态
/// </summary>
[SugarColumn(ColumnName = "order_status", IsNullable = false, ColumnDescription = "单据状态")]
public OutOrderStatus OrderStatus { get; set; } = OutOrderStatus.;
/// <summary>
/// 单据来源
/// </summary>
[SugarColumn(ColumnName = "order_source", Length = 50, IsNullable = true, ColumnDescription = "单据来源")]
public string OrderSource { get; set; }
/// <summary>
/// 单据类型
/// </summary>
[SugarColumn(ColumnName = "order_type", Length = 50, IsNullable = true, ColumnDescription = "单据类型")]
public string OrderType { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(ColumnName = "create_time", IsNullable = false, ColumnDescription = "入库时间")]
public DateTime CreateTime { get; set; } = DateTime.Now;
/// <summary>
/// 创建人
/// </summary>
[SugarColumn(ColumnName = "create_user", Length = 100, IsNullable = true, ColumnDescription = "操作员")]
public string CreateUser { get; set; }
}
public enum OutOrderStatus
{
= 0,
= 1,
= 2
}
}

View File

@ -0,0 +1,60 @@
using SqlSugar;
namespace WCS.BLL.DbModels
{
/// <summary>
/// 出库单据明细表
/// </summary>
[SugarTable("out_order_detail")]
public class OutOrderDetail
{
/// <summary>
/// 主键 自增Id
/// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 出库单据的主键ID
/// </summary>
[SugarColumn(ColumnName = "order_id", IsNullable = false)]
public int OrderId { get; set; }
/// <summary>
/// 出库单据号
/// </summary>
[SugarColumn(ColumnName = "order_number", Length = 50, IsNullable = false, ColumnDescription = "出库单据号")]
public string OrderNumber { get; set; }
/// <summary>
/// 物料编码
/// </summary>
[SugarColumn(ColumnName = "mat_code", Length = 100, IsNullable = true, ColumnDescription = "物料编号")]
public string MatCode { get; set; }
/// <summary>
/// 物料批次
/// </summary>
[SugarColumn(ColumnName = "mat_batch", Length = 150, IsNullable = true, ColumnDescription = "物料批次")]
public string MatBatch { get; set; }
/// <summary>
/// 物料需求数量
/// </summary>
[SugarColumn(ColumnName = "req_qty", IsNullable = false, ColumnDescription = "物料需求数量")]
public int ReqQty { get; set; }
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(ColumnName = "create_time", IsNullable = false, ColumnDescription = "入库时间")]
public DateTime CreateTime { get; set; } = DateTime.Now;
/// <summary>
/// 创建人
/// </summary>
[SugarColumn(ColumnName = "create_user", Length = 100, IsNullable = true, ColumnDescription = "操作员")]
public string CreateUser { get; set; }
}
}

View File

@ -0,0 +1,130 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.DAL.DbModels;
namespace WCS.BLL.DbModels
{
/// <summary>
/// 出库物料明细(库存数据加锁后缓存对应的数据并记录状态)
/// </summary>
[SugarTable("out_order_mat_detail")]
public class OutOrderMatDetail
{
/// <summary>
/// 主键 自增Id
/// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 出库单据的主键ID
/// </summary>
[SugarColumn(ColumnName = "order_id", IsNullable = false)]
public int OrderId { get; set; }
/// <summary>
/// 出库单据号
/// </summary>
[SugarColumn(ColumnName = "order_number", Length = 50, IsNullable = false, ColumnDescription = "出库单据号")]
public string OrderNumber { get; set; }
/// <summary>
/// 出库单据明细的ID
/// </summary>
[SugarColumn(ColumnName = "out_order_detail_id", IsNullable = true)]
public int OutOrderDetailId { get; set; }
/// <summary>
/// 库存的ID
/// </summary>
[SugarColumn(ColumnName = "inventory_detail_id", IsNullable = true)]
public int InventoryDetailId { get; set; }
#region
/// <summary>
/// 入库的库位表ID
/// </summary>
[SugarColumn(ColumnName = "store_id", IsNullable = false, ColumnDescription = "库位ID")]
public int StoreId { get; set; }
/// <summary>
/// 入库的库位编码
/// </summary>
[SugarColumn(ColumnName = "store_code", Length = 50, IsNullable = false, ColumnDescription = "库位编码")]
public string StoreCode { get; set; }
[Navigate(NavigateType.OneToOne, nameof(StoreId))]
public StoreInfo StoreInfo { get; set; }
#endregion
#region
/// <summary>
/// 物料编码SN
/// </summary>
[SugarColumn(ColumnName = "mat_sn", Length = 200, IsNullable = false, ColumnDescription = "物料SN")]
public string MatSN { get; set; }
/// <summary>
/// 物料编码
/// </summary>
[SugarColumn(ColumnName = "mat_code", Length = 100, IsNullable = true, ColumnDescription = "物料编号")]
public string MatCode { get; set; }
/// <summary>
/// 物料名称
/// </summary>
[SugarColumn(ColumnName = "mat_name", Length = 150, IsNullable = true, ColumnDescription = "物料名称")]
public string MatName { get; set; }
/// <summary>
/// 物料规格
/// </summary>
[SugarColumn(ColumnName = "mat_spec", Length = 150, IsNullable = true, ColumnDescription = "物料规格")]
public string MatSpec { get; set; }
/// <summary>
/// 物料批次
/// </summary>
[SugarColumn(ColumnName = "mat_batch", Length = 150, IsNullable = true, ColumnDescription = "物料批次")]
public string MatBatch { get; set; }
/// <summary>
/// 物料数量
/// </summary>
[SugarColumn(ColumnName = "mat_qty", IsNullable = false, ColumnDescription = "物料数量")]
public int MatQty { get; set; }
/// <summary>
/// 物料供应商
/// </summary>
[SugarColumn(ColumnName = "mat_supplier", Length = 150, IsNullable = true, ColumnDescription = "物料供应商")]
public string? MatSupplier { get; set; }
/// <summary>
/// 物料客户
/// </summary>
[SugarColumn(ColumnName = "mat_customer", Length = 150, IsNullable = true, ColumnDescription = "物料客户")]
public string? MatCustomer { get; set; }
#endregion
/// <summary>
/// 该物料是否已出库
/// </summary>
[SugarColumn(ColumnName = "is_sended", IsNullable = false, ColumnDescription = "该物料是否已出库")]
public bool IsSended { get; set; } = false;
/// <summary>
/// 创建时间
/// </summary>
[SugarColumn(ColumnName = "create_time", IsNullable = false, ColumnDescription = "入库时间")]
public DateTime CreateTime { get; set; } = DateTime.Now;
/// <summary>
/// 创建人
/// </summary>
[SugarColumn(ColumnName = "create_user", Length = 100, IsNullable = true, ColumnDescription = "操作员")]
public string CreateUser { get; set; }
}
}

View File

@ -0,0 +1,99 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.BLL.HardWare;
namespace WCS.DAL.DbModels
{
[SugarTable("shelf_info")]
public class ShelfInfo
{
/// <summary>
/// 主键 自增Id
/// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 货架编码;货架一般按照报警灯来区分 一个报警灯指示的是一个货架
/// </summary>
[SugarColumn(ColumnName = "shelf_code", Length = 50, IsNullable = false, ColumnDescription = "货架编码;货架一般按照报警灯来区分 一个报警灯指示的是一个货架")]
public string ShelfCode { get; set; }
/// <summary>
/// 货架类型Id
/// </summary>
[SugarColumn(ColumnName = "shelf_type_id", IsNullable = false, ColumnDescription = "货架类型Id")]
public int ShelfTypeId { get; set; }
/// <summary>
/// 货架类型名称
/// </summary>
[SugarColumn(ColumnName = "shelf_type_name", Length = 50, IsNullable = false, ColumnDescription = "货架类型名称")]
public string ShelfTypeName { get; set; }
/// <summary>
/// 货架当前状态
/// </summary>
[SugarColumn(ColumnName = "current_mode", IsNullable = false, ColumnDescription = "货架当前状态")]
public Mode CurrentMode { get; set; }
/// <summary>
/// 货架行数
/// </summary>
[SugarColumn(ColumnName = "row_counts", IsNullable = false, ColumnDescription = "货架行数")]
public int Rowcounts { get; set; }
/// <summary>
/// 货架列数
/// </summary>
[SugarColumn(ColumnName = "column_counts", IsNullable = false, ColumnDescription = "货架列数")]
public int Columncounts { get; set; }
/// <summary>
/// 货架对应警示灯的Id
/// </summary>
[SugarColumn(ColumnName = "light_id", IsNullable = false, ColumnDescription = "货架对应警示灯的Id")]
public int LightId { get; set; }
/// <summary>
/// 货架对应Can模块的Ip
/// </summary>
[SugarColumn(ColumnName = "client_ip", Length = 50, IsNullable = false, ColumnDescription = "货架对应Can模块的Ip")]
public string ClientIp { get; set; }
/// <summary>
/// 货架的组别、区域(区分单个软件管哪些货架的,前端的配置文件配置一个组别,查询时只显示当前组别的货架)
/// </summary>
[SugarColumn(ColumnName = "group_name", Length = 50, IsNullable = false, ColumnDescription = "货架的组别、区域(区分单个软件管哪些货架的,前端的配置文件配置一个组别,查询时只显示当前组别的货架)")]
public string GroupName { get; set; }
/// <summary>
/// 是否串联绑定
/// </summary>
[SugarColumn(ColumnName = "is_bind", IsNullable = false, ColumnDescription = "是否串联绑定")]
public bool IsBind { get; set; }
/// <summary>
/// 串联绑定后的大货架编码
/// </summary>
[SugarColumn(ColumnName = "Bind_shelf_code", IsNullable = true, ColumnDescription = "串联绑定后的大货架编码")]
public string? BindShelfCode { get; set; } = string.Empty;
/// <summary>
/// 序号
/// </summary>
[SugarColumn(IsIgnore = true)]
public int RowNumber { get; set; }
/// <summary>
/// 是否已经选择
/// </summary>
[SugarColumn(IsIgnore = true)]
public bool IsSelected { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS.BLL.DbModels
{
/// <summary>
/// 货架类型
/// </summary>
[SugarTable("shelf_type")]
public class ShelfTypeInfo
{
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)]
public int Id { get; set; }
[SugarColumn(ColumnName = "shelf_type_name", Length = 50, IsNullable = true, ColumnDescription = "货架类型名称")]
public string ShelfTypeName { get; set; }
}
}

View File

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS.DAL.DbModels
{
public partial class StoreInfo
{
/// <summary>
/// 库位Id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 库位编码
/// </summary>
public string StoreCode { get; set; }
/// <summary>
/// 模组Id
/// </summary>
public int ModuleId { get; set; }
/// <summary>
/// 模组编号
/// </summary>
public string ModuleCode { get; set; }
/// <summary>
/// 货架Id
/// </summary>
public int ShelfId { get; set; }
/// <summary>
/// 货架号
/// </summary>
public string ShelfCode { get; set; }
/// <summary>
/// 板子的Id
/// </summary>
public int BoardId { get; set; }
/// <summary>
/// 板子上第几个灯
/// </summary>
public int LightNumber { get; set; }
/// <summary>
/// 优先级;为钢网柜推荐库位预留
/// </summary>
public int Priority { get; set; }
/// <summary>
/// 当前物料;货架这种一对一且带检测的就给这个赋值,方便出入库时的查询
/// </summary>
public string CurrentMatSn { get; set; }
/// <summary>
/// 当前电压;当前电压,调试排查问题用
/// </summary>
public decimal CurrentVoltage { get; set; }
/// <summary>
/// 标准电压;标准电压,调试排查问题用
/// </summary>
public decimal StandardVoltage { get; set; }
/// <summary>
/// 偏差电压;偏差电压,调试排查问题用
/// </summary>
public decimal OffsetVoltage { get; set; }
}
}

View File

@ -0,0 +1,102 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS.BLL.DbModels
{
/// <summary>
/// 系统接口日志记录
/// </summary>
[SugarTable("system_api_log_record")]
public class SystemApiLogRecord
{
/// <summary>
/// 主键Id
/// </summary>
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsNullable = false, IsIdentity = true)]
public int Id { get; set; }
[SugarColumn(ColumnName = "request_type", IsNullable = false, ColumnDescription = "调用/被调用 0 = 被调用,1 = 调用")]
/// <summary>
/// 调用/被调用 0 = 被调用 1 = 调用
/// </summary>
public string RequestType { get; set; } = "被调用";
/// <summary>
/// 用户名称
/// </summary>
[SugarColumn(ColumnName = "user_name", IsNullable = true, ColumnDescription = "用户名称")]
public string UserName { get; set; }
/// <summary>
/// 设备类型
/// </summary>
[SugarColumn(ColumnName = "device_type", IsNullable = true, ColumnDescription = "用户名称")]
public string DeviceType { get; set; }
/// <summary>
/// 设备Ip
/// </summary>
[SugarColumn(ColumnName = "device_ip", IsNullable = true, ColumnDescription = "设备Ip")]
public string DeviceIp { get; set; }
/// <summary>
/// 请求地址
/// </summary>
[SugarColumn(ColumnName = "request_url", IsNullable = true, ColumnDescription = "请求地址")]
public string RequestUrl { get; set; }
/// <summary>
/// 请求Body
/// </summary>
[SugarColumn(ColumnName = "request_body", IsNullable = true, ColumnDescription = "请求Body")]
public string RequestBody { get; set; }
/// <summary>
/// 请求Body
/// </summary>
[SugarColumn(ColumnName = "query_string", IsNullable = true, ColumnDescription = "请求Body")]
public string QueryString { get; set; }
/// <summary>
/// 是否响应
/// </summary>
[SugarColumn(ColumnName = "is_response", IsNullable = true, ColumnDescription = "是否响应")]
public bool IsResponse { get; set; }
/// <summary>
/// 响应返回内容
/// </summary>
[SugarColumn(ColumnName = "response_json", IsNullable = true, ColumnDescription = "响应返回内容")]
public string ResponseJson { get; set; }
/// <summary>
/// 开始请求时间
/// </summary>
[SugarColumn(ColumnName = "request_time", IsNullable = true, ColumnDescription = "开始请求时间")]
public DateTime RequestTime { get; set; }
/// <summary>
/// 响应时间
/// </summary>
[SugarColumn(ColumnName = "response_time", IsNullable = true, ColumnDescription = "响应时间")]
public DateTime ResponseTime { get; set; }
/// <summary>
/// 请求处理时长ms
/// </summary>
[SugarColumn(ColumnName = "execution_time", IsNullable = true, ColumnDescription = "请求处理时长ms")]
public long ExecutionTime { get; set; }
/// <summary>
/// 序号
/// </summary>
[SugarColumn(IsIgnore = true)]
public int RowNumber { get; set; }
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS.BLL.HardWare
{
public interface IModuleBase
{
/// <summary>
/// 模组Id
/// </summary>
int ModuleId { get; set; }
/// <summary>
/// 是否启用
/// </summary>
bool IsEnable { get; set; }
/// <summary>
/// 当前模式
/// </summary>
Mode CurrentMode { get; set; }
/// <summary>
/// 设置当前模式
/// </summary>
void SetCurrentMode();
}
}

View File

@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.Model;
namespace WCS.BLL.HardWare
{
/// <summary>
/// 货架基类
/// </summary>
public interface IShelfBase
{
/// <summary>
/// 货架ID 数据库中那个
/// </summary>
public int ShelfId { get; set; }
/// <summary>
/// 货架编码
/// </summary>
public string ShelfCode { get; set; }
/// <summary>
/// 货架模组行数
/// </summary>
public int RowCounts { get; set; }
/// <summary>
/// 货架模组列数
/// </summary>
public int ColumnCounts { get; set; }
/// <summary>
/// 货架当前模式
/// </summary>
public Mode CurentMode { get; set; }
public MatInfoModel InStoreData { get; set; }
public string OutOrderNumber { get; set; }//出库模式中的单据
public string ModulesStr { get; set; }
/// <summary>
/// 货架组别
/// </summary>
public string GroupName { get; set; }
/// <summary>
/// 模组
/// </summary>
//public List<IModuleBase> Modules { get; set; }
/// <summary>
/// 设置货架模式
/// </summary>
public void SetCurrentMode();
/// <summary>
/// 货架进入入库模式
/// </summary>
public void GoInInstore(string? IPAdress);
/// <summary>
/// 货架退出入库模式
/// </summary>
public void GoOutInstore();
/// <summary>
/// 货架进入出库模式
/// </summary>
public void GoInOutstore();
/// <summary>
/// 货架退出出库模式
/// </summary>
public void GoOutOutstore();
/// <summary>
/// 货架进入盘点模式
/// </summary>
public void GoInStocktaking();
/// <summary>
/// 货架退出盘点模式
/// </summary>
public void GoOutStocktaking();
/// <summary>
/// 货架报警
/// </summary>
public void Warning();
/// <summary>
/// 货架复位
/// </summary>
public void Reset();
}
public enum Mode
{
= 0,
= 1,
= 2,
= 3
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS.BLL.HardWare
{
public interface IWarningLightBase
{
public void BlueLight();
}
}

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.Model;
namespace WCS.BLL.HardWare
{
public class SingleLightShelf : IShelfBase
{
public int ShelfId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string ShelfCode { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int RowCounts { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int ColumnCounts { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public Mode CurentMode { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string ModulesStr { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string GroupName { get; set; }
public MatInfoModel InStoreData { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string OutOrderNumber { get; set; }
public void GoInInstore(string IPAdress)
{
throw new NotImplementedException();
}
public void GoInOutstore()
{
throw new NotImplementedException();
}
public void GoInStocktaking()
{
throw new NotImplementedException();
}
public void GoOutInstore()
{
throw new NotImplementedException();
}
public void GoOutOutstore()
{
throw new NotImplementedException();
}
public void GoOutStocktaking()
{
throw new NotImplementedException();
}
public void Reset()
{
throw new NotImplementedException();
}
public void SetCurrentMode()
{
throw new NotImplementedException();
}
public void Warning()
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,210 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core;
using WCS.DAL;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
namespace WCS.BLL.HardWare
{
/// <summary>
/// 智能货架
/// </summary>
public class SmartShelf : IShelfBase
{
public SmartShelf(ShelfInfo shelfInfo)
{
ShelfId = shelfInfo.Id;
ShelfCode = shelfInfo.ShelfCode;
RowCounts = shelfInfo.Rowcounts;
ColumnCounts = shelfInfo.Columncounts;
CurentMode = shelfInfo.CurrentMode;
//初始化Module
Task.Run(() =>
{
var modules = DbHelp.db.Queryable<ModuleInfo>().Where(t => t.ShelfId == ShelfId).ToList();
foreach (var module in modules)
{
Modules.Add(new SmartShelfModule()
{
ModuleId = module.Id,
ModuleCode = module.ModuleCode,
IsEnable = module.IsEnable,
CurrentMode = module.CurentMode
});
}
ModulesStr = string.Join(";", Modules.Select(t => t.ModuleCode));
});
//初始化TCPCleint
TcpCleint = new TCPClient("127.0.0.1:20002", "127.0.0.1:20003");
TcpCleint.Connect();
TcpCleint.tcpClient.Received += (client, e) =>
{
var data = e.ByteBlock.Buffer.Take((int)e.ByteBlock.Length).ToArray();
e.ByteBlock.Clear();
var len = data.Length;
for (int index = 0; index < data.Length - TcpCleint.PreFixLength; index++)
{
//协议拆包 通过前缀校验是否为完整数据包
var prefixInData = data.Skip(index).Take(TcpCleint.PreFixLength);
var isEqual = prefixInData.SequenceEqual(TcpCleint.Prefix);
if (isEqual)
{
var dataTemp = data.Skip(index).Take(TcpCleint.PreFixLength + TcpCleint.DataLength).ToArray();
if (dataTemp.Length < TcpCleint.PreFixLength + TcpCleint.DataLength)//拆包后不满足一条指令的长度
{
continue;
}
index += (TcpCleint.PreFixLength + TcpCleint.DataLength - 1);//每次循环index会+1 所以这里-1
//获取板子ID
var boardId = (data[TcpCleint.PreFixLength + 0] << 8) + data[TcpCleint.PreFixLength + 1];
//协议处理 判断功能位
switch (dataTemp[TcpCleint.PreFixLength + 2])
{
case 0x01:
;
break;
default:
;
break;
}
}
}
return EasyTask.CompletedTask;
};
}
public int ShelfId { get; set; }
public string ShelfCode { get; set; }
public int RowCounts { get; set; }
public int ColumnCounts { get; set; }
public Mode CurentMode { get; set; }
public string ModulesStr { get; set; }//当前货架所有模组的Str
public string GroupName { get; set; }
public List<SmartShelfModule> Modules { get; set; } = new List<SmartShelfModule>();
public TCPClient TcpCleint { get; set; }
public IWarningLightBase WarningLight { get; set; }
public List<string> ExceptionMessages { get; set; } = new List<string>();
public string? InstoreIpAddress { get; set; } = string.Empty;
public MatInfoModel InStoreData { get; set; }
public string OutOrderNumber { get; set; }
public void GoInInstore(string? IPAddress)
{
//判断当前模式是否为待机模式
if (this.CurentMode != Mode.)
{
return;
}
else
{
this.CurentMode = Mode.;
}
//货架所有模组发送指令进入入库模式
foreach (var module in Modules.Where(t => t.IsEnable).ToList())
{
module.GoInInstoreMode(TcpCleint);
}
//延时获取异常
var timeOut = 3000;
var timeSpan = TimeSpan.FromMilliseconds(0);
var beginTime = DateTime.Now;
while (timeSpan <= TimeSpan.FromMilliseconds(timeOut))
{
timeSpan = DateTime.Now - beginTime;
//接收到第一个异常就不继续循环了
if (ExceptionMessages.Count() > 0)
{
var deficientTime = timeOut - (int)timeSpan.TotalMilliseconds;
if (deficientTime > 0)
Thread.Sleep(deficientTime);
//出现异常的未进入入库模式,有红灯进行指引
//未出现异常的需要退出入库模式
GoOutInstore();
return;
}
//延时处理
Thread.Sleep(50);
}
//警示灯亮起
//WarningLight.BlueLight();
//绑定当前入库PDA的IP
InstoreIpAddress = IPAddress;
//返回成功
return;
}
public void GoInInstoreReturn()
{
}
public void GoOutInstore()
{
//看货架是否为入库模式
if (CurentMode != Mode.)
{
return;
}
else
{
this.CurentMode = Mode.;
}
//货架所有模组发送指令退出入库模式
foreach (var module in Modules.Where(t => t.IsEnable)
.Where(t => t.CurrentMode == Mode.)
.ToList())
{
module.GoOutInstoreMode(TcpCleint);
}
}
public void GoInOutstore()
{
throw new NotImplementedException();
}
public void GoInStocktaking()
{
throw new NotImplementedException();
}
public void GoOutOutstore()
{
throw new NotImplementedException();
}
public void GoOutStocktaking()
{
throw new NotImplementedException();
}
void IShelfBase.Reset()
{
throw new NotImplementedException();
}
void IShelfBase.SetCurrentMode()
{
throw new NotImplementedException();
}
void IShelfBase.Warning()
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
namespace WCS.BLL.HardWare
{
public class SmartShelfModule : IModuleBase
{
#region
/// <summary>
/// 进入入库模式
/// </summary>
public byte[] GoInInstoreData = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
/// <summary>
/// 退出入库模式
/// </summary>
public byte[] GoOutInstoreData = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
#endregion
public int ModuleId { get; set; }
public string ModuleCode { get; set; }
public bool IsEnable { get; set; }
public Mode CurrentMode { get; set; }
public void SetCurrentMode()
{
}
public void GoInInstoreMode(TCPClient tcpCleint)
{
if (CurrentMode != Mode.)
{
//退出对应的模式 然后再发送进入入库模式
}
var storeInfos = DbHelp.db.Queryable<StoreInfo>()
.Where(t => t.BoardId == ModuleId)
.OrderBy(t => t.LightNumber)
.ToList();
char[] data = "0000000000000000".ToCharArray();
var boardStoreNumber = storeInfos.Count();
foreach (var storeInfo in storeInfos)
{
if (!string.IsNullOrEmpty(storeInfo.CurrentMatSn) && storeInfo.LightNumber > 0 && storeInfo.LightNumber <= boardStoreNumber)
{
data[storeInfo.LightNumber - 1] = '1';
}
}
var dataStr = string.Join("", data.Reverse());
var data1 = dataStr.Substring(8, 8);
var data2 = dataStr.Substring(0, 8);
GoInInstoreData[1] = Convert.ToByte(data1, 2);
GoInInstoreData[2] = Convert.ToByte(data2, 2);
tcpCleint.Send(tcpCleint.GenerateMessage(ModuleId, GoInInstoreData));
}
public void GoOutInstoreMode(TCPClient tcpCleint)
{
if (CurrentMode == Mode.)
{
tcpCleint.Send(tcpCleint.GenerateMessage(ModuleId, GoOutInstoreData));
}
else
{
//退出对应的模式 回到待机状态 并记录对应的状态日志(这个分支肯定是异常了)
//记录错误日志
}
}
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.BLL.DbModels;
using WCS.BLL.HardWare;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
namespace WCS.BLL.Manager
{
public static class ShelfManager
{
public static List<IShelfBase> Shelves { get; set; } = new List<IShelfBase>();
static ShelfManager()
{
}
public static void InitShelves()
{
DbHelp.db.CodeFirst.InitTables(typeof(ModuleInfo), typeof(ShelfInfo), typeof(StoreInfo)
, typeof(InventoryDetail), typeof(OutOrder), typeof(OutOrderDetail), typeof(OutOrderMatDetail)
, typeof(ShelfTypeInfo), typeof(MatBaseInfo), typeof(MatInfo)
);
DbHelp.dbLog.CodeFirst.InitTables(typeof(SystemApiLogRecord));
var shelvesInDb = DbHelp.db.Queryable<ShelfInfo>().ToList();
foreach (var shelfInDb in shelvesInDb)
{
Shelves.Add(InitShelf(shelfInDb));
}
}
public static IShelfBase InitShelf(ShelfInfo shelfInDb)
{
switch (shelfInDb.ShelfTypeId)
{
case 1:
return new SmartShelf(shelfInDb)
{
ShelfId = shelfInDb.Id,
ShelfCode = shelfInDb.ShelfCode,
GroupName = shelfInDb.GroupName,
};
default:
return null;
}
}
public static void GoInInstore()
{
}
}
}

View File

@ -0,0 +1,8 @@

namespace WCS.BLL.Services.IService
{
public interface IHomerService
{
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.Model;
namespace WCS.BLL.Services.IService
{
public interface IInstoreService
{
public ResponseBase shelfGoInInStore(ShelfGoInInstoreRequest request);
public ResponseBase shelfGoOutInStore(ShelfGoOutInStoreRequest request);
public ResponseBase queryByMatSn(QueryByMatSnRequest request);
public Task<ResponseBase> queryInstoreStatus(QueryByMatSnRequest request);
}
}

View File

@ -0,0 +1,17 @@

using WCS.BLL.DbModels;
using WCS.DAL.AuthDbModel;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.User;
namespace WCS.BLL.Services.IService
{
public interface IInterfaceRecordService
{
public Task<PageQueryResponse<SystemApiLogRecord>> getInterfaceRecord(GetInterfaceRecordsRequest request);
public Task<PageQueryResponse<SystemApiLogRecord>> exportInterfaceRecord(GetInterfaceRecordsRequest request);
}
}

View File

@ -0,0 +1,26 @@

using WCS.BLL.DbModels;
using WCS.DAL.AuthDbModel;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.MatBaseInfo;
using WCS.Model.ApiModel.User;
namespace WCS.BLL.Services.IService
{
public interface IMatBaseInfoService
{
public Task<PageQueryResponse<MatBaseInfo>> getMatBaseInfo(GetMatBaseInfoRequest request);
public Task<PageQueryResponse<MatBaseInfo>> exportMatBaseInfo(GetMatBaseInfoRequest request);
public Task<ResponseCommon<List<string>>> importMatBaseInfo(List<MatBaseInfoImportModel> lists,string userName,string deviceType);
public Task<ResponseCommon<object>> addOrUpdateMatBaseInfo(AddMatBaseInfoRequest<MatBaseInfo> request);
public Task<ResponseCommon<object>> deleteMatBaseInfo(DeleteMatBaseInfosRequest request);
public Task<ResponseCommon<List<string>>> getMatCodeList(GetMatCodeListRequest request);
}
}

View File

@ -0,0 +1,18 @@

using WCS.BLL.DbModels;
using WCS.DAL.AuthDbModel;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.MatInventoryDetail;
using WCS.Model.ApiModel.User;
namespace WCS.BLL.Services.IService
{
public interface IMatInventoryDetailService
{
public Task<PageQueryResponse<InventoryDetail>> getMatInventoryDetail(GetMatInventoryDetailRequest request);
public Task<PageQueryResponse<InventoryDetail>> exportMatInventoryDetail(GetMatInventoryDetailRequest request);
}
}

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.Model;
namespace WCS.BLL.Services.IService
{
public interface IOutstoreService
{
public Task<ResponseBase> SysOutOrderByMatCode(SysOutOrderByMatCodeRequest request);
public Task<ResponseBase> SysOutOrderByMatSn(SysOutOrderByMatSnRequest request);
public Task<ResponseBase> GetOutOrderList(GetOutOrderListRequest request);
public Task<ResponseBase> GetOutOrderDetail(GetOutOrderDetailRequest request);
public Task<ResponseBase> GoInOutstore(GetOutOrderDetailRequest request);
public Task<ResponseBase> GoOutOutstore(GetOutOrderDetailRequest request);
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.DAL.AuthDbModel;
using WCS.Model.ApiModel.User;
using WCS.Model;
using WCS.DAL.DbModels;
using WCS.Model.ApiModel.StoreInfo;
using WCS.BLL.DbModels;
using WCS.Model.ApiModel.MatBaseInfo;
namespace WCS.BLL.Services.IService
{
public interface IStoreInfoService
{
/// <summary>
/// 查询货架列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public Task<PageQueryResponse<ShelfInfo>> GetShelves(GetShelvesRequest request);
/// <summary>
/// 添加、更新、删除货架
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public Task<ResponseCommon<object>> addOrUpdateShelfInfo(AddShelfInfoRequest<ShelfInfo> request);
}
}

View File

@ -0,0 +1,29 @@

using WCS.DAL.AuthDbModel;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.User;
namespace WCS.BLL.Services.IService
{
/// <summary>
/// 权限用户所有的后台处理方法
/// </summary>
public interface IUserService
{
/// <summary>
/// 模糊查询用户列表
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public Task<ResponseCommon<List<UserBase>>> GetUsers(GetUsersRequest request);
public Task<ResponseCommon<object>> AddUser(AddUserRequest<UserModel> request);
public Task<ResponseCommon<UserBase>> UserLogin(UserLoginRequest request);
public Task<ResponseCommon<List<RoleBase>>> GetRoles(GetUsersRequest request);
public Task<ResponseCommon<object>> AddRole(AddRoleRequest<RoleModel> request);
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.BLL.Services.IService;
namespace WCS.BLL.Services.Service
{
public class HomerService: IHomerService
{
public HomerService() { }
}
}

View File

@ -0,0 +1,170 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WCS.BLL.Config;
using WCS.BLL.HardWare;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.DAL.Db;
using WCS.Model;
namespace WCS.BLL.Services.Service
{
public class InstoreService : IInstoreService
{
public InstoreService() { }
public ResponseBase shelfGoInInStore(ShelfGoInInstoreRequest request)
{
//校验货架编码规则
bool isValid = Regex.IsMatch(request.ModuleCode, LocalFile.ModuleCodePattern);
if (!isValid)
{
return new ResponseBase()
{
Code = 202,
Message = $"模组编码{request.ModuleCode}不满足模组编码规则!",
};
}
//找到模组对应的货架
var shelf = ShelfManager.Shelves.Where(t => t.ModulesStr.Contains(request.ModuleCode)).FirstOrDefault();
if (shelf == null)//未找到
{
return new ResponseBase()
{
Code = 201,
Message = "未找到模组对应的货架",
};
}
//已找到模组对应货架
shelf.GoInInstore(request.IpAdress);
//成功进入入库模式
return new ShelfGoInInstoreResponse()
{
Code = 200,
Message = "货架进入入库模式成功!",
Data = new ShelfGoInInstoreDto()
{
ShelfCode = shelf.ShelfCode,
ModulesStr = shelf.ModulesStr,
}
};
}
public ResponseBase shelfGoOutInStore(ShelfGoOutInStoreRequest request)
{
//获取货架
var shelf = ShelfManager.Shelves.Where(t => t.ShelfCode == request.ShelfCode).FirstOrDefault();
if (shelf == null)//货架不存在
{
return new ResponseCommon()
{
Code = 201,
Message = $"退出入库模式失败:货架[{request.ShelfCode}]不存在!",
};
}
//TO DO 判断扫码枪 是否被其他扫码枪所占用 如果占用 直接退出入库模式 不发指令
//两个扫码枪互相占用入库会有问题
shelf.GoOutInstore();
return new ResponseCommon()
{
Code = 200,
Message = $"货架[{request.ShelfCode}]已退出入库模式!",
};
}
public ResponseBase queryByMatSn(QueryByMatSnRequest request)
{
//获取货架
var shelf = ShelfManager.Shelves.Where(t => t.ShelfCode == request.ShelfCode).FirstOrDefault();
if (shelf == null)//货架不存在
{
return new QueryByMatSnResponse()
{
Code = 201,
Message = $"操作失败:货架[{request.ShelfCode}]不存在!",
};
}
//判断当前是否是入库模式
if (shelf.CurentMode != Mode.)
{
return new QueryByMatSnResponse()
{
Code = 201,
Message = $"操作失败:货架[{request.ShelfCode}]不在入库模式!\r\n当前为{shelf.CurentMode}",
};
}
//调用接口或者直接查询数据库
if (1 == 1)
{
}
//查询数据库
else
{
}
return new QueryByMatSnResponse()
{
Code = 200,
Data = new MatInfoModel(),
Message = "success"
};
}
public async Task<ResponseBase> queryInstoreStatus(QueryByMatSnRequest request)
{
//获取货架
var shelf = ShelfManager.Shelves.Where(t => t.ShelfCode == request.ShelfCode).FirstOrDefault();
if (shelf == null)//货架不存在
{
return new ResponseCommon()
{
Code = 201,
Message = $"操作失败:货架[{request.ShelfCode}]不存在!",
};
}
//判断当前是否是入库模式
if (shelf.CurentMode != Mode.)
{
return new ResponseCommon()
{
Code = 201,
Message = $"操作失败:货架[{request.ShelfCode}]不在入库模式!\r\n当前为{shelf.CurentMode}",
};
}
//这个时间相当于需要入库扫码后需要等待的时间
var timeOut = 5000;
var timeSpan = TimeSpan.FromMilliseconds(0);
var beginTime = DateTime.Now;
while (timeSpan <= TimeSpan.FromMilliseconds(timeOut))
{
timeSpan = DateTime.Now - beginTime;
//已入库当前扫码的物料时 查询数据库
if (shelf.InStoreData == null || (shelf.InStoreData as object) == null)
{
await Task.Delay(50);
//var inventoryDetail = DbHelp.db.Queryable<InventoryDetail>().Where(t => t.MatSN == dto.matSn).First();
//if (inventoryDetail != null)
//{
// return Json(HttpResponseCommon.GetSuccessResponse($"{inventoryDetail.StoreCode}", null));
//}
}
//延时处理
Thread.Sleep(50);
}
return new ResponseCommon()
{
Code = 200,
Message = $"success",
};
}
}
}

View File

@ -0,0 +1,128 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TouchSocket.Core;
using WCS.BLL.DbModels;
using WCS.BLL.Services.IService;
using WCS.DAL;
using WCS.DAL.AuthDbModel;
using WCS.DAL.Db;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.User;
namespace WCS.BLL.Services.Service
{
public class InterfaceRecordService : IInterfaceRecordService
{
public InterfaceRecordService() { }
public async Task<PageQueryResponse<SystemApiLogRecord>> getInterfaceRecord(GetInterfaceRecordsRequest request)
{
try
{
var recordsQueryable = DbHelp.dbLog.Queryable<SystemApiLogRecord>()
.WhereIF(!string.IsNullOrEmpty(request.RequestType), t => t.RequestType == request.RequestType)
.WhereIF(!string.IsNullOrEmpty(request.RequestUrl), t => t.RequestUrl.Contains(request.RequestUrl))
.WhereIF(!string.IsNullOrEmpty(request.RequestBody), t => t.RequestBody.Contains(request.RequestBody));
if (request.TimeType == TimeType.)
{
recordsQueryable = recordsQueryable.WhereIF(request.StartTime != null, t => request.StartTime <= t.RequestTime);
recordsQueryable = recordsQueryable.WhereIF(request.StartTime != null, t => request.EndTime >= t.RequestTime);
}
else if (request.TimeType == TimeType.)
{
recordsQueryable = recordsQueryable.WhereIF(request.StartTime != null, t => request.StartTime <= t.ResponseTime);
recordsQueryable = recordsQueryable.WhereIF(request.StartTime != null, t => request.EndTime >= t.ResponseTime);
}
var totalCount = await recordsQueryable.CountAsync();
var records = await recordsQueryable
.Skip((request.PageNumber - 1) * request.PageSize).Take(request.PageSize)
.ToListAsync();
//生成序号
for (int i = 0; i < records.Count; i++)
{
records[i].RowNumber = (request.PageNumber - 1) * 10 + i + 1;
}
//Task.WaitAll(new Task[] { recordsTask, totalCountTask });
//var records = recordsTask.Result;
//var totalCount = totalCountTask.Result;
return new PageQueryResponse<SystemApiLogRecord>()
{
Code = 200,
Message = $"success",
Data = new PageQueryResponseData<SystemApiLogRecord>()
{
TotalCount = totalCount,
MaxPage = request.PageSize == 0 ? 0 : (int)Math.Ceiling((decimal)totalCount / request.PageSize),
Count = records.Count,
Lists = records.ToList()
}
};
}
catch (Exception ex)
{
return new PageQueryResponse<SystemApiLogRecord>()
{
Code = 300,
Message = $"操作失败:{ex.Message}",
};
}
}
public async Task<PageQueryResponse<SystemApiLogRecord>> exportInterfaceRecord(GetInterfaceRecordsRequest request)
{
try
{
var recordsQueryable = DbHelp.dbLog.Queryable<SystemApiLogRecord>()
.WhereIF(!string.IsNullOrEmpty(request.RequestType), t => t.RequestType == request.RequestType)
.WhereIF(!string.IsNullOrEmpty(request.RequestUrl), t => t.RequestUrl.Contains(request.RequestUrl))
.WhereIF(!string.IsNullOrEmpty(request.RequestBody), t => t.RequestBody.Contains(request.RequestBody));
if (request.TimeType == TimeType.)
{
recordsQueryable = recordsQueryable.WhereIF(request.StartTime != null, t => request.StartTime <= t.RequestTime);
recordsQueryable = recordsQueryable.WhereIF(request.StartTime != null, t => request.EndTime >= t.RequestTime);
}
else if (request.TimeType == TimeType.)
{
recordsQueryable = recordsQueryable.WhereIF(request.StartTime != null, t => request.StartTime <= t.ResponseTime);
recordsQueryable = recordsQueryable.WhereIF(request.StartTime != null, t => request.EndTime >= t.ResponseTime);
}
var records = await recordsQueryable.ToListAsync();
//生成序号
var index = 1;
records.ForEach(r =>
{
r.RowNumber = index++;
});
return new PageQueryResponse<SystemApiLogRecord>()
{
Code = 200,
Message = $"success",
Data = new PageQueryResponseData<SystemApiLogRecord>()
{
Lists = records
}
};
}
catch (Exception ex)
{
return new PageQueryResponse<SystemApiLogRecord>()
{
Code = 300,
Message = $"操作失败:{ex.Message}",
};
}
}
}
}

View File

@ -0,0 +1,416 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TouchSocket.Core;
using WCS.BLL.DbModels;
using WCS.BLL.Services.IService;
using WCS.DAL;
using WCS.DAL.AuthDbModel;
using WCS.DAL.Db;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.MatBaseInfo;
using WCS.Model.ApiModel.User;
namespace WCS.BLL.Services.Service
{
/// <summary>
/// 物料基础信息
/// </summary>
public class MatBaseInfoService : IMatBaseInfoService
{
public MatBaseInfoService() { }
public async Task<PageQueryResponse<MatBaseInfo>> getMatBaseInfo(GetMatBaseInfoRequest request)
{
try
{
var recordsQueryable = DbHelp.db.Queryable<MatBaseInfo>()
.WhereIF(!string.IsNullOrEmpty(request.MatCode), t => t.MatCode.Contains(request.MatCode))
.WhereIF(!string.IsNullOrEmpty(request.MatName), t => t.MatName.Contains(request.MatName))
.WhereIF(!string.IsNullOrEmpty(request.MatSpec), t => t.MatSpec.Contains(request.MatSpec))
.WhereIF(request.IsEnable != null, t => t.IsEnable == request.IsEnable.GetValueOrDefault());
var totalCount = await recordsQueryable.CountAsync();
var records = await recordsQueryable
.Skip((request.PageNumber - 1) * request.PageSize).Take(request.PageSize)
.ToListAsync();
//生成序号
for (int i = 0; i < records.Count; i++)
{
records[i].RowNumber = (request.PageNumber - 1) * 10 + i + 1;
}
return new PageQueryResponse<MatBaseInfo>()
{
Code = 200,
Message = $"success",
Data = new PageQueryResponseData<MatBaseInfo>()
{
TotalCount = totalCount,
MaxPage = request.PageSize == 0 ? 0 : (int)Math.Ceiling((decimal)totalCount / request.PageSize),
Count = records.Count,
Lists = records.ToList()
}
};
}
catch (Exception ex)
{
return new PageQueryResponse<MatBaseInfo>()
{
Code = 300,
Message = $"操作失败:{ex.Message}",
};
}
}
public async Task<PageQueryResponse<MatBaseInfo>> exportMatBaseInfo(GetMatBaseInfoRequest request)
{
try
{
var recordsQueryable = DbHelp.db.Queryable<MatBaseInfo>()
.WhereIF(!string.IsNullOrEmpty(request.MatCode), t => t.MatCode.Contains(request.MatCode))
.WhereIF(!string.IsNullOrEmpty(request.MatName), t => t.MatName.Contains(request.MatName))
.WhereIF(!string.IsNullOrEmpty(request.MatSpec), t => t.MatSpec.Contains(request.MatSpec))
.WhereIF(request.IsEnable != null, t => t.IsEnable == request.IsEnable.GetValueOrDefault());
var records = await recordsQueryable.ToListAsync();
//生成序号
var index = 1;
records.ForEach(r =>
{
r.RowNumber = index++;
});
return new PageQueryResponse<MatBaseInfo>()
{
Code = 200,
Message = $"success",
Data = new PageQueryResponseData<MatBaseInfo>()
{
Lists = records
}
};
}
catch (Exception ex)
{
return new PageQueryResponse<MatBaseInfo>()
{
Code = 300,
Message = $"操作失败:{ex.Message}",
};
}
}
public async Task<ResponseCommon<List<string>>> importMatBaseInfo(List<MatBaseInfoImportModel> lists, string userName, string deviceType)
{
//获取数据
#region
var matCodes = lists.Select(t => t.)
.ToList();
var duplicates = matCodes.GroupBy(x => x)
.Where(g => g.Count() > 1)
.Select(g => g.Key).ToList();
//有重复的情况
if (duplicates.Count > 0)
{
return new ResponseCommon<List<string>>()
{
Code = 201,
Message = "导入失败:文件中存在物料编码重复",
Data = duplicates
};
}
#endregion
#region
duplicates = await DbHelp.db.Queryable<MatBaseInfo>()
.Where(t => matCodes.Contains(t.MatCode))
.Select(t => t.MatCode)
.ToListAsync();
//有重复的情况
if (duplicates.Count > 0)
{
return new ResponseCommon<List<string>>()
{
Code = 201,
Message = "导入失败:以下物料编码已存在",
Data = duplicates
};
}
#endregion
#region
try
{
await DbHelp.db.BeginTranAsync();
foreach (var mat in lists)
{
var matBaseInfo = new MatBaseInfo()
{
MatCode = mat.,
MatName = mat.,
MatSpec = mat.,
MatUnit = mat.,
MatCustomer = mat.,
IsEnable = mat. == "启用" ? true : false,
};
await DbHelp.db.Insertable(matBaseInfo).ExecuteCommandAsync();
}
await DbHelp.db.CommitTranAsync();
return new ResponseCommon<List<string>>()
{
Code = 200,
Message = "导入数据成功",
Data = null
};
}
catch (Exception ex)
{
await DbHelp.db.RollbackTranAsync();
var ErrList = new List<string>
{
ex.Message
};
return new ResponseCommon<List<string>>()
{
Code = 200,
Message = "导入失败",
Data = ErrList
};
}
#endregion
}
public async Task<ResponseCommon<object>> addOrUpdateMatBaseInfo(AddMatBaseInfoRequest<MatBaseInfo> request)
{
try
{
var matBaseInfo = await DbHelp.db.Queryable<MatBaseInfo>()
.Where(t => t.MatCode == request.MatBaseInfo.MatCode)
.FirstAsync();
//修改物料基础数据
if (request.AddOrUpdate == AddOrUpdate.Update)
{
if (matBaseInfo == null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"更新物料基础数据失败:物料{request.MatBaseInfo}不存在!",
Data = null
};
}
else
{
matBaseInfo.MatName = request.MatBaseInfo.MatName;
matBaseInfo.MatSpec = request.MatBaseInfo.MatSpec;
matBaseInfo.MatUnit = request.MatBaseInfo.MatUnit;
matBaseInfo.MatCustomer = request.MatBaseInfo.MatCustomer;
matBaseInfo.IsEnable = request.MatBaseInfo.IsEnable;
matBaseInfo.ModifyTime = request.MatBaseInfo.ModifyTime;
matBaseInfo.ModifyUser = request.MatBaseInfo.ModifyUser;
var rowNum = await DbHelp.db.Updateable(matBaseInfo).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"更新物料基础数据失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"更新物料基础数据成功!",
Data = null
};
}
}
}
else if (request.AddOrUpdate == AddOrUpdate.Add)
{
if (matBaseInfo != null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"物料基础数据失败:物料{request.MatBaseInfo.MatCode}已存在",
Data = null
};
}
else
{
var newMatBaseInfo = new MatBaseInfo()
{
MatCode = request.MatBaseInfo.MatCode,
MatName = request.MatBaseInfo.MatName,
MatSpec = request.MatBaseInfo.MatSpec,
MatUnit = request.MatBaseInfo.MatUnit,
MatCustomer = request.MatBaseInfo.MatCustomer,
IsEnable = request.MatBaseInfo.IsEnable,
ModifyTime = request.MatBaseInfo.ModifyTime,
ModifyUser = request.MatBaseInfo.ModifyUser,
};
var rowNum = await DbHelp.db.Insertable(newMatBaseInfo).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"添加物料基础数据失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"添加物料基础数据成功!",
Data = null
};
}
}
}
//else if (request.AddOrUpdate == AddOrUpdate.Delete)
//{
// if (matBaseInfo == null)
// {
// return new ResponseCommon<Object>
// {
// Code = 201,
// Message = $"删除物料基础数据失败:物料{request.MatBaseInfo}不存在!",
// Data = null
// };
// }
// else
// {
// var rowNum = await AuthDbHelp.db.Deleteable(matBaseInfo).ExecuteCommandAsync();
// if (rowNum == 0)
// {
// return new ResponseCommon<Object>
// {
// Code = 201,
// Message = $"删除物料基础数据失败:请重试!",
// Data = null
// };
// }
// else
// {
// return new ResponseCommon<Object>
// {
// Code = 200,
// Message = $"删除物料基础数据成功!",
// Data = null
// };
// }
// }
//}
else
{
var response = new ResponseCommon<Object>
{
Code = 300,
Message = "不支持的操作!",
Data = null
};
return response;
}
}
catch (Exception ex)
{
var response = new ResponseCommon<Object>
{
Code = 300,
Message = $"操作失败:{ex.Message}",
Data = null
};
return response;
}
}
public async Task<ResponseCommon<object>> deleteMatBaseInfo(DeleteMatBaseInfosRequest request)
{
//先查询出具体的Id
var matBaseInfos = await DbHelp.db.Queryable<MatBaseInfo>()
.Where(t => request.MatBaseInfoIds.Contains(t.Id))
.ToListAsync();
//执行删除
try
{
var deleteRows = await DbHelp.db.Deleteable(matBaseInfos).ExecuteCommandAsync();
return new ResponseCommon<Object>
{
Code = 200,
Message = $"已删除{deleteRows}条数据!",
Data = null
};
}
catch (Exception ex)
{
var response = new ResponseCommon<Object>
{
Code = 300,
Message = $"操作失败:{ex.Message}",
Data = null
};
return response;
}
}
public async Task<ResponseCommon<List<string>>> getMatCodeList(GetMatCodeListRequest request)
{
try
{
List<string> matCodeList = null;
if (request.IsFromBaseData)
{
matCodeList = await DbHelp.db.Queryable<MatBaseInfo>()
.Select(t => t.MatCode)
.Distinct()
.ToListAsync();
}
else
{
matCodeList = await DbHelp.db.Queryable<InventoryDetail>()
.Select(t => t.MatCode)
.Distinct()
.ToListAsync();
}
return new ResponseCommon<List<string>>()
{
Code = 200,
Message = "success",
Data = matCodeList
};
}
catch (Exception e)
{
return new ResponseCommon<List<string>>()
{
Code = 201,
Message = $"获取失败:{e.Message}",
Data = null
};
}
}
}
}

View File

@ -0,0 +1,126 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TouchSocket.Core;
using WCS.BLL.DbModels;
using WCS.BLL.Services.IService;
using WCS.DAL;
using WCS.DAL.AuthDbModel;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.MatInventoryDetail;
using WCS.Model.ApiModel.User;
namespace WCS.BLL.Services.Service
{
public class MatInventoryDetailService : IMatInventoryDetailService
{
public async Task<PageQueryResponse<InventoryDetail>> getMatInventoryDetail(GetMatInventoryDetailRequest request)
{
try
{
var recordsQueryable = DbHelp.db.Queryable<InventoryDetail>()
.LeftJoin<StoreInfo>((id, si) => id.StoreId == si.Id)
.WhereIF(!string.IsNullOrEmpty(request.MatSN), (id, si) => id.MatSN.Contains(request.MatSN))
.WhereIF(!string.IsNullOrEmpty(request.MatCode), (id, si) => id.MatCode.Contains(request.MatCode))
.WhereIF(!string.IsNullOrEmpty(request.MatName), (id, si) => id.MatName.Contains(request.MatName))
.WhereIF(!string.IsNullOrEmpty(request.MatBatch), (id, si) => id.MatBatch.Contains(request.MatBatch))
.WhereIF(!string.IsNullOrEmpty(request.MatSpec), (id, si) => id.MatSpec.Contains(request.MatSpec))
.WhereIF(!string.IsNullOrEmpty(request.MatSupplier), (id, si) => id.MatSpec.Contains(request.MatSupplier))
.WhereIF(!string.IsNullOrEmpty(request.MatCustomer), (id, si) => id.MatSpec.Contains(request.MatCustomer))
.WhereIF(request.StoreId != 0, (id, si) => id.StoreId == request.StoreId)
.WhereIF(!string.IsNullOrEmpty(request.StoreCode), (id, si) => id.StoreCode.Contains(request.StoreCode))
;
var totalCount = await recordsQueryable.CountAsync();
var records = await recordsQueryable
.Skip((request.PageNumber - 1) * request.PageSize).Take(request.PageSize)
.Select<InventoryDetail>()
.ToListAsync();
//生成序号
for (int i = 0; i < records.Count; i++)
{
records[i].RowNumber = (request.PageNumber - 1) * 10 + i + 1;
}
return new PageQueryResponse<InventoryDetail>()
{
Code = 200,
Message = $"success",
Data = new PageQueryResponseData<InventoryDetail>()
{
TotalCount = totalCount,
MaxPage = request.PageSize == 0 ? 0 : (int)Math.Ceiling((decimal)totalCount / request.PageSize),
Count = records.Count,
Lists = records.ToList()
}
};
}
catch (Exception ex)
{
return new PageQueryResponse<InventoryDetail>()
{
Code = 300,
Message = $"操作失败:{ex.Message}",
};
}
}
public async Task<PageQueryResponse<InventoryDetail>> exportMatInventoryDetail(GetMatInventoryDetailRequest request)
{
try
{
var recordsQueryable = DbHelp.db.Queryable<InventoryDetail>()
.LeftJoin<StoreInfo>((id, si) => id.StoreId == si.Id)
.WhereIF(!string.IsNullOrEmpty(request.MatSN), (id, si) => id.MatSN.Contains(request.MatSN))
.WhereIF(!string.IsNullOrEmpty(request.MatCode), (id, si) => id.MatCode.Contains(request.MatCode))
.WhereIF(!string.IsNullOrEmpty(request.MatName), (id, si) => id.MatName.Contains(request.MatName))
.WhereIF(!string.IsNullOrEmpty(request.MatBatch), (id, si) => id.MatBatch.Contains(request.MatBatch))
.WhereIF(!string.IsNullOrEmpty(request.MatSpec), (id, si) => id.MatSpec.Contains(request.MatSpec))
.WhereIF(!string.IsNullOrEmpty(request.MatSupplier), (id, si) => id.MatSpec.Contains(request.MatSupplier))
.WhereIF(!string.IsNullOrEmpty(request.MatCustomer), (id, si) => id.MatSpec.Contains(request.MatCustomer))
.WhereIF(request.StoreId != 0, (id, si) => id.StoreId == request.StoreId)
.WhereIF(!string.IsNullOrEmpty(request.StoreCode), (id, si) => id.StoreCode.Contains(request.StoreCode))
;
var records = await recordsQueryable
.Skip((request.PageNumber - 1) * request.PageSize).Take(request.PageSize)
.Select<InventoryDetail>()
.ToListAsync();
//生成序号
var index = 1;
records.ForEach(r =>
{
r.RowNumber = index++;
});
return new PageQueryResponse<InventoryDetail>()
{
Code = 200,
Message = $"success",
Data = new PageQueryResponseData<InventoryDetail>()
{
Lists = records
}
};
}
catch (Exception ex)
{
return new PageQueryResponse<InventoryDetail>()
{
Code = 300,
Message = $"操作失败:{ex.Message}",
};
}
}
}
}

View File

@ -0,0 +1,328 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.BLL.DbModels;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.DAL.Db;
using WCS.Model;
namespace WCS.BLL.Services.Service
{
public class OutstoreService : IOutstoreService
{
public OutstoreService()
{
}
public async Task<ResponseBase> SysOutOrderByMatCode(SysOutOrderByMatCodeRequest request)
{
//参数合法性校验
if (request.ItemList == null || request.ItemList.Count == 0)
{
return new ResponseBase()
{
Code = 201,
Message = "单据同步失败:缺少需要出库的物料类型!"
};
}
//判断是否有单据号 没有单据号系统自动生成一个
if (string.IsNullOrEmpty(request.OrderNumber))
{
request.OrderNumber = GetOrderNumber();
}
Console.WriteLine(DateTime.Now);
//保存数据
await DbHelp.db.BeginTranAsync();
try
{
var order = new OutOrder()
{
OrderNumber = request.OrderNumber,
OrderSource = request.OrderSource,
OrderType = request.OrderType,
CreateUser = request.UserName,
};
order.Id = await DbHelp.db.Insertable(order).ExecuteReturnIdentityAsync();
request.ItemList.ForEach(async item =>
{
var orderDetail = new OutOrderDetail()
{
OrderId = order.Id,
OrderNumber = order.OrderNumber,
MatCode = item.MatCode,
MatBatch = item.MatBatch,
ReqQty = item.ReqQty,
CreateUser = request.UserName
};
await DbHelp.db.Insertable(orderDetail).ExecuteCommandAsync();
});
await DbHelp.db.CommitTranAsync();
return new ResponseCommon()
{
Code = 200,
Message = "单据同步成功!"
}; ;
}
catch (Exception ex)
{
await DbHelp.db.RollbackTranAsync();
Console.WriteLine(ex.Message);
return new ResponseBase()
{
Code = 200,
Message = $"单据同步失败:{ex.Message}"
};
}
}
public async Task<ResponseBase> SysOutOrderByMatSn(SysOutOrderByMatSnRequest request)
{
//参数合法性校验
if (request.SnList == null || request.SnList.Count == 0)
{
return new ResponseBase()
{
Code = 201,
Message = "单据同步失败:缺少物料明细!"
};
}
//库存有无校验 & 库存已锁校验
try
{
await DbHelp.db.BeginTranAsync();
var inventoryDetails = await DbHelp.db.Queryable<InventoryDetail>()
.Where(t => request.SnList.Contains(t.MatSN))
.TranLock(DbLockType.Wait)
.ToListAsync();
if (inventoryDetails.Count < request.SnList.Count)//库存的物料少于需求的物料数量
{
var existsSns = inventoryDetails.Select(t => t.MatSN).ToList();
request.SnList.RemoveAll(t => existsSns.Contains(t));
await DbHelp.db.RollbackTranAsync();
//返回提示哪些物料库存不存在
return new ResponseCommon()
{
Code = 201,
Message = "单据同步失败:存在物料不在库存中!",
Data = request.SnList
};
}
else if (inventoryDetails.Where(t => t.IsLocked).Any())
{
await DbHelp.db.RollbackTranAsync();
//返回提示哪些物料库存已被锁定
return new ResponseCommon()
{
Code = 201,
Message = "单据同步失败:存在物料被锁定!",
Data = inventoryDetails.Where(t => t.IsLocked).Select(t => t.MatSN).ToList()
};
}
//判断是否有单据号 没有单据号系统自动生成一个
if (string.IsNullOrEmpty(request.OrderNumber))
{
request.OrderNumber = GetOrderNumber();
}
#region
//锁库存
inventoryDetails.ForEach(t =>
{
t.IsLocked = false;
});
var lockTask = DbHelp.db.Updateable(inventoryDetails).ExecuteCommandAsync();
//保存数据
var order = new OutOrder()
{
OrderNumber = request.OrderNumber,
OrderSource = request.OrderSource,
OrderType = request.OrderType,
CreateUser = request.UserName,
};
order.Id = await DbHelp.db.Insertable(order).ExecuteReturnIdentityAsync();
//通过库存数据保存出库物料明细表
var matDetailTasks = inventoryDetails.Select(async t =>
{
var orderMatDetail = new OutOrderMatDetail()
{
OrderId = order.Id,
OrderNumber = order.OrderNumber,
InventoryDetailId = t.Id,
StoreId = t.StoreId,
StoreCode = t.StoreCode,
MatSN = t.MatSN,
MatCode = t.MatCode,
MatName = t.MatName,
MatSpec = t.MatSpec,
MatBatch = t.MatBatch,
MatQty = t.MatQty,
MatSupplier = t.MatSupplier,
MatCustomer = t.MatCustomer,
CreateUser = request.UserName
};
await DbHelp.db.Insertable(orderMatDetail).ExecuteCommandAsync();
}).ToList();
await lockTask;
await Task.WhenAll(matDetailTasks);
await DbHelp.db.CommitTranAsync();
return new ResponseCommon()
{
Code = 200,
Message = $"单据同步成功!",
Data = order.Id
};
#endregion
}
catch (Exception ex)
{
await DbHelp.db.RollbackTranAsync();
return new ResponseBase()
{
Code = 201,
Message = $"单据同步失败:{ex.Message}"
};
}
}
public async Task<ResponseBase> GetOutOrderList(GetOutOrderListRequest request)
{
//直接查询
var outOrderList = await DbHelp.db.Queryable<OutOrder>()
.WhereIF(!string.IsNullOrEmpty(request.OrderNumber), t => t.OrderNumber.Contains(request.OrderNumber))
.Skip((request.PageNumber - 1) * request.PageSize).Take(request.PageSize)
.ToListAsync();
return new PageQueryResponse<OutOrder>()
{
Code = 200,
Message = "success",
Data = new PageQueryResponseData<OutOrder>()
{
Lists = outOrderList,
Count = outOrderList.Count
}
};
}
public async Task<ResponseBase> GetOutOrderDetail(GetOutOrderDetailRequest request)
{
OutOrder outOrder = null;
#region
if (request.OrderId != 0)
{
outOrder = await DbHelp.db.Queryable<OutOrder>().Where(t => t.Id == request.OrderId).FirstAsync();
if (outOrder == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"查询失败不存在Id为{request.OrderId}的出库单!",
};
}
}
else if (string.IsNullOrEmpty(request.OrderNumber))
{
outOrder = await DbHelp.db.Queryable<OutOrder>().Where(t => t.OrderNumber == request.OrderNumber)
.FirstAsync();
if (outOrder == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"查询失败:不存在单据号为{request.OrderNumber}的出库单!",
};
}
}
else
{
return new ResponseCommon()
{
Code = 201,
Message = $"查询失败:缺少必要参数!",
};
}
#endregion
#region
var orderDetailTask = DbHelp.db.Queryable<OutOrderDetail>()
.Where(t => t.OrderId == outOrder.Id)
.ToListAsync();
#endregion
#region
var orderMatDetailTask = DbHelp.db.Queryable<OutOrderMatDetail>()
.Where(t => t.OrderId == outOrder.Id)
.ToListAsync();
#endregion
var orderDetail = await orderDetailTask;
var orderMatDetail = await orderMatDetailTask;
return new ResponseCommon()
{
Code = 200,
Message = "Success",
Data = new
{
OrderDetailLists = orderDetail,
OrderMatDetailLists = orderMatDetail,
}
};
}
private string GetOrderNumber()
{
var orderNumber = "PD" + DateTime.Now.ToString("yyyyMMddHHmmss");
return orderNumber;
}
public async Task<ResponseBase> GoInOutstore(GetOutOrderDetailRequest request)
{
//先找到所有物料
//分组 按物料找到对应得货架编码
//对应的货架进入出库模式 亮灯
//返回
return new ResponseCommon()
{
Code = 200,
Message = "Success",
Data = null
};
}
public async Task<ResponseBase> GoOutOutstore(GetOutOrderDetailRequest request)
{
//找到出库单号一致的货架列表
var shelves = ShelfManager.Shelves.Where(t => t.OutOrderNumber == request.OrderNumber)
.ToList();
//退出出库模式
shelves.ForEach(t =>
{
t.GoOutOutstore();
});
return new ResponseCommon()
{
Code = 200,
Message = "Success",
Data = null
};
}
}
}

View File

@ -0,0 +1,240 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TouchSocket.Core;
using WCS.BLL.DbModels;
using WCS.BLL.Services.IService;
using WCS.DAL;
using WCS.DAL.AuthDbModel;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.StoreInfo;
using WCS.Model.ApiModel.User;
namespace WCS.BLL.Services.Service
{
public class StoreInfoService : IStoreInfoService
{
public StoreInfoService() { }
public async Task<PageQueryResponse<ShelfInfo>> GetShelves(GetShelvesRequest request)
{
try
{
var recordsQueryable = DbHelp.db.Queryable<ShelfInfo>()
.WhereIF(request.ShelfTypeId != 0, t => t.ShelfTypeId == request.ShelfTypeId)
.WhereIF(!string.IsNullOrEmpty(request.ShelfCode), t => t.ShelfCode.Contains(request.ShelfCode));
var totalCount = await recordsQueryable.CountAsync();
var records = await recordsQueryable
.Skip((request.PageNumber - 1) * request.PageSize).Take(request.PageSize)
.ToListAsync();
//生成序号
for (int i = 0; i < records.Count; i++)
{
records[i].RowNumber = (request.PageNumber - 1) * 10 + i + 1;
}
return new PageQueryResponse<ShelfInfo>()
{
Code = 200,
Message = $"success",
Data = new PageQueryResponseData<ShelfInfo>()
{
TotalCount = totalCount,
MaxPage = request.PageSize == 0 ? 0 : (int)Math.Ceiling((decimal)totalCount / request.PageSize),
Count = records.Count,
Lists = records.ToList()
}
};
}
catch (Exception ex)
{
return new PageQueryResponse<ShelfInfo>()
{
Code = 300,
Message = $"操作失败:{ex.Message}",
};
}
}
public async Task<ResponseCommon<object>> addOrUpdateShelfInfo(AddShelfInfoRequest<ShelfInfo> request)
{
try
{
var shelfnfo = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.ShelfCode == request.ShelfInfo.ShelfCode)
.FirstAsync();
//修改货架信息
if (request.AddOrUpdate == AddOrUpdate.Update)
{
var existId = shelfnfo == null ? 0 : shelfnfo.Id;
shelfnfo = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.Id == request.ShelfInfo.Id)
.FirstAsync();
if (shelfnfo == null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"更新货架信息失败:货架{request.ShelfInfo.ShelfCode}不存在!",
Data = null
};
}
else if (existId != shelfnfo.Id)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"更新货架信息失败:已存在货架编码{request.ShelfInfo.ShelfCode}",
Data = null
};
}
else
{
shelfnfo.ShelfCode = request.ShelfInfo.ShelfCode;
shelfnfo.ShelfTypeId = request.ShelfInfo.ShelfTypeId;
shelfnfo.ShelfTypeName = request.ShelfInfo.ShelfTypeName;
shelfnfo.Rowcounts = request.ShelfInfo.Rowcounts;
shelfnfo.Columncounts = request.ShelfInfo.Columncounts;
shelfnfo.LightId = request.ShelfInfo.LightId;
shelfnfo.ClientIp = request.ShelfInfo.ClientIp;
shelfnfo.GroupName = request.ShelfInfo.GroupName;
shelfnfo.IsBind = request.ShelfInfo.IsBind;
shelfnfo.BindShelfCode = request.ShelfInfo.BindShelfCode;
var rowNum = await DbHelp.db.Updateable(shelfnfo).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"更新货架信息失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"更新货架信息成功!",
Data = null
};
}
}
}
else if (request.AddOrUpdate == AddOrUpdate.Add)
{
if (shelfnfo != null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"货架信息失败:货架{request.ShelfInfo.ShelfCode}已存在!",
Data = null
};
}
else
{
var newShelfInfo = new ShelfInfo()
{
ShelfCode = request.ShelfInfo.ShelfCode,
ShelfTypeId = request.ShelfInfo.ShelfTypeId,
ShelfTypeName = request.ShelfInfo.ShelfTypeName,
Rowcounts = request.ShelfInfo.Rowcounts,
Columncounts = request.ShelfInfo.Columncounts,
LightId = request.ShelfInfo.LightId,
ClientIp = request.ShelfInfo.ClientIp,
GroupName = request.ShelfInfo.GroupName,
IsBind = request.ShelfInfo.IsBind,
BindShelfCode = request.ShelfInfo.BindShelfCode,
};
var rowNum = await DbHelp.db.Insertable(newShelfInfo).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"添加货架信息失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"添加货架信息成功!",
Data = null
};
}
}
}
else if (request.AddOrUpdate == AddOrUpdate.Delete)
{
shelfnfo = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.Id == request.ShelfInfo.Id)
.FirstAsync();
if (shelfnfo == null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"删除货架信息失败:货架{request.ShelfInfo}不存在!",
Data = null
};
}
else
{
var rowNum = await DbHelp.db.Deleteable(shelfnfo).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"删除货架信息失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"删除货架信息成功!",
Data = null
};
}
}
}
else
{
var response = new ResponseCommon<Object>
{
Code = 300,
Message = "不支持的操作!",
Data = null
};
return response;
}
}
catch (Exception ex)
{
var response = new ResponseCommon<Object>
{
Code = 300,
Message = $"操作失败:{ex.Message}",
Data = null
};
return response;
}
}
}
}

View File

@ -0,0 +1,464 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TouchSocket.Core;
using WCS.BLL.Services.IService;
using WCS.DAL;
using WCS.DAL.AuthDbModel;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.User;
namespace WCS.BLL.Services.Service
{
public class UserService : IUserService
{
public UserService() { }
public async Task<ResponseCommon<List<UserBase>>> GetUsers(GetUsersRequest request)
{
try
{
var users = await AuthDbHelp.db.Queryable<UserBase>()
.WhereIF(!string.IsNullOrWhiteSpace(request.Info), o => o.LoginName.Contains(request.Info.Trim()))
.OrderBy(o => o.Id)
.ToListAsync();
//返回内容密码处理
if (users != null && users.Count > 0)
{
users.ForEach(t =>
{
t.Password = "******";
});
}
var response = new ResponseCommon<List<UserBase>>()
{
Code = 200,
Message = "success",
Data = users
};
return response;
}
catch (Exception ex)
{
var response = new ResponseCommon<List<UserBase>>()
{
Code = 200,
Message = "success",
Data = null
};
return response;
}
}
public async Task<ResponseCommon<object>> AddUser(AddUserRequest<UserModel> request)
{
try
{
var user = await AuthDbHelp.db.Queryable<UserBase>()
.Where(t => t.LoginName == request.User.LoginName)
.FirstAsync();
if (request.AddOrUpdate == AddOrUpdate.Update)
{
if (user == null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"更新用户信息失败:用户{user.LoginName}不存在!",
Data = null
};
}
else
{
user.Password = request.User.Password;
user.LoginName = request.User.LoginName;
user.RoleIds = request.User.RoleIds;
var rowNum = await AuthDbHelp.db.Updateable(user).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"更新用户信息失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"更新用户信息成功!",
Data = null
};
}
}
}
else if (request.AddOrUpdate == AddOrUpdate.Add)
{
if (user != null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"添加用户失败:用户{request.User.LoginName}已存在",
Data = null
};
}
else
{
var newUser = new UserBase()
{
LoginName = request.User.LoginName,
Password = request.User.Password,
RoleIds = request.User.RoleIds,
IsAdmin = request.User.IsAdmin,
Time = request.User.Time
};
var rowNum = await AuthDbHelp.db.Insertable(newUser).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"添加用户失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"添加用户成功!",
Data = null
};
}
}
}
else if (request.AddOrUpdate == AddOrUpdate.Delete)
{
if (user == null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"删除用户失败:用户{request.User.LoginName}不存在",
Data = null
};
}
else
{
var rowNum = await AuthDbHelp.db.Deleteable(user).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"删除用户失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"删除用户成功!",
Data = null
};
}
}
}
else
{
var response = new ResponseCommon<Object>
{
Code = 300,
Message = "不支持的操作!",
Data = null
};
return response;
}
}
catch (Exception ex)
{
var response = new ResponseCommon<Object>
{
Code = 300,
Message = $"操作失败:{ex.Message}",
Data = null
};
return response;
}
}
public async Task<ResponseCommon<List<RoleBase>>> GetRoles(GetUsersRequest request)
{
try
{
var users = await AuthDbHelp.db.Queryable<RoleBase>()
.WhereIF(!string.IsNullOrWhiteSpace(request.Info), o => o.Name.Contains(request.Info.Trim()))
.OrderBy(o => o.Id)
.ToListAsync();
var response = new ResponseCommon<List<RoleBase>>()
{
Code = 200,
Message = "success",
Data = users
};
return response;
}
catch (Exception ex)
{
var response = new ResponseCommon<List<RoleBase>>()
{
Code = 200,
Message = "success",
Data = null
};
return response;
}
}
public async Task<ResponseCommon<object>> AddRole(AddRoleRequest<RoleModel> request)
{
try
{
var Role = await AuthDbHelp.db.Queryable<RoleBase>()
.Where(t => t.Name == request.Role.Name)
.FirstAsync();
if (request.AddOrUpdate == AddOrUpdate.Update)
{
if (Role == null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"更新角色信息失败:角色{Role.Name}不存在!",
Data = null
};
}
else
{
Role.IsAdmin = request.Role.IsAdmin;
Role.Name = request.Role.Name;
Role.Auths = request.Role.Auths;
Role.Time = request.Role.Time;
var rowNum = await AuthDbHelp.db.Updateable(Role).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"更新角色信息失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"更新角色信息成功!",
Data = null
};
}
}
}
else if (request.AddOrUpdate == AddOrUpdate.Add)
{
if (Role != null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"添加角色失败:角色{request.Role.Name}已存在",
Data = null
};
}
else
{
var newRole = new RoleBase()
{
Name = request.Role.Name,
Auths = request.Role.Auths,
IsAdmin = request.Role.IsAdmin,
Time = request.Role.Time
};
var rowNum = await AuthDbHelp.db.Insertable(newRole).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"添加角色失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"添加角色成功!",
Data = null
};
}
}
}
else if (request.AddOrUpdate == AddOrUpdate.Delete)
{
if (Role == null)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"删除角色失败:角色{request.Role.Name}不存在",
Data = null
};
}
else
{
var isContains = AuthDbHelp.db.Queryable<UserBase>().Select(o => o.RoleIds).ToList().SelectMany(o => o).Contains(Role.Id);
if (isContains)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"删除角色失败:角色{request.Role.Name}已被用户使用!",
Data = null
};
}
var rowNum = await AuthDbHelp.db.Deleteable(Role).ExecuteCommandAsync();
if (rowNum == 0)
{
return new ResponseCommon<Object>
{
Code = 201,
Message = $"删除角色失败:请重试!",
Data = null
};
}
else
{
return new ResponseCommon<Object>
{
Code = 200,
Message = $"删除角色成功!",
Data = null
};
}
}
}
else
{
var response = new ResponseCommon<Object>
{
Code = 300,
Message = "不支持的操作!",
Data = null
};
return response;
}
}
catch (Exception ex)
{
var response = new ResponseCommon<Object>
{
Code = 300,
Message = $"操作失败:{ex.Message}",
Data = null
};
return response;
}
}
public async Task<ResponseCommon<UserBase>> UserLogin(UserLoginRequest request)
{
try
{
UserBase user = null;
if (request.IsNoLogin)//不登录模式 不校验密码
{
user = await AuthDbHelp.db.Queryable<UserBase>()
.Where(t => t.LoginName == "admin")
.FirstAsync();
}
else//登录模式需要校验密码
{
user = await AuthDbHelp.db.Queryable<UserBase>()
.Where(t => t.LoginName == request.UserName)
.FirstAsync();
if (user == null)
{
return new ResponseCommon<UserBase>()
{
Code = 201,
Message = $"登录失败:用户名[{request.UserName}]不存在!",
Data = null
};
}
else if (user.Password != request.PassWord)
{
return new ResponseCommon<UserBase>()
{
Code = 201,
Message = $"登录失败:密码错误!",
Data = null
};
}
}
//加载用户的权限
if (user != null)
{
if (user.IsAdmin)
{
user.GetRoles = await AuthDbHelp.db.Queryable<RoleBase>()
.OrderBy(o => o.Id)
.ToListAsync();
}
else if (user.RoleIds == null || !user.RoleIds.Any())
{
user.GetRoles = new List<RoleBase>();
}
else
{
user.GetRoles = await AuthDbHelp.db.Queryable<RoleBase>()
.Where(t => user.RoleIds.Contains(t.Id))
.OrderBy(o => o.Id)
.ToListAsync();
}
}
//返回字串不返回密码
user.Password = "***";
var response = new ResponseCommon<UserBase>()
{
Code = 200,
Message = "success",
Data = user
};
return response;
}
catch (Exception ex)
{
var response = new ResponseCommon<UserBase>()
{
Code = 300,
Message = $"登录失败:{ex.Message}",
Data = null
};
return response;
}
}
}
}

182
WCS.BLL/Tool/Api/ApiHelp.cs Normal file
View File

@ -0,0 +1,182 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using WCS.BLL.Tool.Api.Models;
namespace WCS.BLL.Tool.Api
{
public static class ApiHelp
{
public static HttpClient httpClient;
static ApiHelp()
{
httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromSeconds(5);
httpClient.DefaultRequestHeaders.Add("User-Agent", "Chrome/95.0.4638.69 Safari/537.36");
//ServicePointManager.Expect100Continue = false;
}
public static ApiResult Get(string uri, object? query = null, object? body = null)
{
return Send(HttpMethod.Get, uri, query, body);
}
public static ApiResult Get(IEnumerable<object> uri, object? query = null, object? body = null)
{
return Send(HttpMethod.Get, uri, query, body);
}
public static ApiResult<T> Get<T>(string uri, object? query = null, object? body = null)
{
return Send<T>(HttpMethod.Get, uri, query, body);
}
public static ApiResult<T> Get<T>(IEnumerable<object> uri, object? query = null, object? body = null)
{
return Send<T>(HttpMethod.Get, uri, query, body);
}
public static ApiResult Post(string uri, object? body = null, object? query = null)
{
return Send(HttpMethod.Post, uri, query, body);
}
public static ApiResult Post(IEnumerable<object> uri, object? body = null, object? query = null)
{
return Send(HttpMethod.Post, uri, query, body);
}
public static ApiResult<T> Post<T>(string uri, object? body = null, object? query = null)
{
return Send<T>(HttpMethod.Post, uri, query, body);
}
public static ApiResult<T> Post<T>(IEnumerable<object> uri, object? body = null, object? query = null)
{
return Send<T>(HttpMethod.Post, uri, query, body);
}
public static ApiResult Send(HttpMethod method, string uri, object? query = null, object? body = null)
{
return Send(method, new string[] { uri }, query, body);
}
public static ApiResult Send(HttpMethod method, IEnumerable<object> uri, object? query = null, object? body = null)
{
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, "".AppendPathSegments(uri).SetQueryParams(query));
if (body != null)
{
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
httpRequestMessage.Content = content;
}
var re = httpClient.SendAsync(httpRequestMessage).Result;
if (!re.IsSuccessStatusCode)
return new ApiResult() { Code = ((int)re.StatusCode).ToString() };
var con = re.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<ApiResult>(con) ?? new ApiResult();
}
public static ApiResult<T> Send<T>(HttpMethod method, string uri, object? query = null, object? body = null)
{
return Send<T>(method, new string[] { uri }, query, body);
}
public static ApiResult<T> Send<T>(HttpMethod method, IEnumerable<object> uri, object? query = null, object? body = null)
{
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(method, "".AppendPathSegments(uri).SetQueryParams(query));
if (body != null)
{
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
httpRequestMessage.Content = content;
}
var re = httpClient.SendAsync(httpRequestMessage).Result;
if (!re.IsSuccessStatusCode)
return new ApiResult<T>() { Code = ((int)re.StatusCode).ToString() };
var con = re.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<ApiResult<T>>(con) ?? new ApiResult<T>();
}
/// <summary>
/// 追加路径片段有更高要求可以使用Flurl库
/// </summary>
/// <param name="url">地址,如 https://www.baidu.com</param>
/// <param name="segments">路径片段</param>
/// <returns>地址</returns>
public static string AppendPathSegments(this string url, IEnumerable<object> segments)
{
string urlStr = url;
foreach (var segment in segments)
{
var val = segment?.ToString();
if (string.IsNullOrWhiteSpace(val))
continue;
if (urlStr.EndsWith("/"))
urlStr = urlStr.Substring(0, urlStr.Length - 1);
urlStr += val!.StartsWith("/") ? val : $"/{val}";
}
return urlStr;
}
/// <summary>
/// 设置Query参数有更高要求可以使用Flurl库
/// </summary>
/// <param name="url">地址,如 https://www.baidu.com/s</param>
/// <param name="values">参数,支持字典和对象</param>
/// <returns>地址</returns>
public static string SetQueryParams(this string url, object? values)
{
string urlStr = url;
if (values == null)
return urlStr;
List<string> kv = new List<string>();
if (values is IEnumerable jh)
{
if (jh is IDictionary dict)
{
foreach (DictionaryEntry item in dict)
kv.Add($"{item.Key?.ToString()}={item.Value?.ToString()}");
}
}
else
{
foreach (var item in values.GetType().GetProperties())
{
if (item.CanRead)
kv.Add($"{item.Name}={item.GetValue(values)?.ToString()}");
}
}
if (kv.Any())
{
if (!urlStr.Contains("?"))
urlStr += "?";
else
{
if (!urlStr.EndsWith("&"))
urlStr += "&";
}
urlStr += string.Join("&", kv);
}
return urlStr;
}
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCS.BLL.Tool.Api.Models
{
public class ApiResult
{
public string Code { get; set; }
public string Message { get; set; }
}
public class ApiResult<T> : ApiResult
{
public T Data { get; set; }
}
}

161
WCS.BLL/Tool/Logs.cs Normal file
View File

@ -0,0 +1,161 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using WCS.BLL.Config;
using WCS.DAL;
using WCS.Model;
namespace WCS.BLL
{
/// <summary>
/// 日志类型
/// </summary>
public enum LogsType
{
/// <summary>
/// 信息
/// </summary>
Info,
/// <summary>
/// 警告
/// </summary>
Warning,
/// <summary>
/// 错误
/// </summary>
Err,
/// <summary>
/// 数据库错误
/// </summary>
DbErr,
}
/// <summary>
/// 日志
/// </summary>
public static class Logs
{
static object obj = new object();
const string logExtension = ".log";
/// <summary>
/// 写入日志失败
/// </summary>
public static Action<IEnumerable<string>, DateTime, LogsType, Exception> WriteErr = null;
/// <summary>
/// 写入日志
/// </summary>
/// <param name="content">内容</param>
/// <param name="type">类型</param>
/// <returns>是否写入成功</returns>
public static void Write(IEnumerable<string> content, LogsType type = LogsType.Info)
{
if (content == null || !content.Any())
return;
var dt = DateTime.Now;
string hms = dt.ToString("HH:mm:ss.fff");
List<string> lines = new List<string>(content.Count());
try
{
string path = Path.Combine(Config.LocalFile.LogDir, type.ToString(), $"{(dt.ToString("yyyyMMdd"))}{logExtension}");
foreach (var item in content)
lines.AddRange($"[{hms}]{item}".Split(new string[] { Environment.NewLine }, StringSplitOptions.None));
lock (obj)
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
File.AppendAllLines(path, lines, Encoding.UTF8);
}
}
catch (Exception ex)
{
WriteErr?.Invoke(content, dt, type, ex);
}
}
/// <summary>
/// 写入日志
/// </summary>
/// <param name="content">内容对象</param>
/// <param name="type">类型</param>
/// <returns>是否写入成功</returns>
public static void Write(string content, LogsType type = LogsType.Info)
{
Write(new string[] { content }, type);
}
/// <summary>
/// 写入日志
/// </summary>
/// <param name="content">内容对象</param>
/// <param name="type">类型</param>
/// <returns>是否写入成功</returns>
public static void Write(object content, LogsType type = LogsType.Info)
{
Write(JsonConvert.SerializeObject(content), type);
}
/// <summary>
/// 写入日志
/// </summary>
/// <param name="content">内容</param>
/// <param name="contentTitle">内容标题</param>
/// <param name="type">类型</param>
/// <returns>是否写入成功</returns>
public static void Write(object content, string contentTitle, LogsType type = LogsType.Info)
{
Write($"{contentTitle} {JsonConvert.SerializeObject(content)}", type);
}
/// <summary>
/// 写入日志
/// </summary>
/// <param name="ex">错误</param>
/// <returns>是否写入成功</returns>
public static void Write(Exception ex, LogsType type = LogsType.Err)
{
Write(ex.ToString(), type);
}
/// <summary>
/// 清除日志
/// </summary>
/// <param name="time">保留时间</param>
/// <returns>清理的大小(字节)</returns>
public static long Clear(TimeSpan time)
{
long size = 0;
var rs = EnumHelps.GetEnumList(typeof(LogsType));
foreach (var item in rs)
{
try
{
var path = Path.Combine(Config.LocalFile.LogDir, item);
DirectoryInfo directoryInfo = new DirectoryInfo(path);
if (!directoryInfo.Exists)
continue;
var files = directoryInfo.GetFiles($"**{logExtension}", SearchOption.TopDirectoryOnly);
var fileDel = files.Where(o => o.CreationTime < (DateTime.Now - time));
foreach (var item2 in fileDel)
{
size += item2.Length;
item2.Delete();
}
}
catch (Exception)
{
}
}
return size;
}
}
}

223
WCS.BLL/Tool/TCPClient.cs Normal file
View File

@ -0,0 +1,223 @@
using System.Collections.Concurrent;
using System.Text;
using TouchSocket.Core;
using TouchSocket.Sockets;
namespace WCS.BLL
{
/// <summary>
/// 对TouchSocket的封装 主要完成TCP的连接 状态更新 发送接收通信
/// </summary>
public class TCPClient
{
public string RemoteIPHost { get; set; } = "127.0.0.1:20002";
public string BindIPHost { get; set; } = "127.0.0.1:20003";
public bool IsOnline { get; set; } = false;
//can模块协议前缀
public readonly byte[] Prefix = new byte[] { 0x08, 0x00, 0x00 };
//can模块协议前缀长度
public readonly int PreFixLength = 3;
//协议数据部分长度
public readonly int DataLength = 10;
public ConcurrentDictionary<int, MessageDto> MessageList { get; set; } = new ConcurrentDictionary<int, MessageDto>();
public TcpClient tcpClient { get; set; }
public object receivdLockObject = new object();
public object sendLockObject = new object();
public bool Connect()
{
try
{
tcpClient.Connect();//调用连接,当连接不成功时,会抛出异常。
return true;
}
catch (Exception e)
{
//连接失败
return false;
}
}
/// <summary>
/// 初始化配置连接
/// </summary>
/// <param name="remoteIPHost"></param>
public TCPClient(string remoteIPHost, string bindIPHost)
{
try
{
RemoteIPHost = remoteIPHost;
BindIPHost = bindIPHost;
tcpClient = new TcpClient();
//载入配置
tcpClient.Setup(new TouchSocketConfig()
.SetRemoteIPHost(RemoteIPHost)
.SetBindIPHost(BindIPHost)
.ConfigurePlugins(a =>
{
//配置断线重连
a.UseReconnection(-1, true, 1000);
})
.ConfigureContainer(a =>
{
//添加控制台日志注入
a.AddConsoleLogger();
}));
//添加接收事件 匹配已发送的指令
tcpClient.Received += (client, e) =>
{
var data = e.ByteBlock.Buffer.Take((int)e.ByteBlock.Length).ToArray();
e.ByteBlock.Clear();
var len = data.Length;
for (int index = 0; index < data.Length - PreFixLength; index++)
{
//协议拆包 通过前缀校验是否为完整数据包
var prefixInData = data.Skip(index).Take(PreFixLength);
var isEqual = prefixInData.SequenceEqual(Prefix);
if (isEqual)
{
var dataTemp = data.Skip(index).Take(PreFixLength + DataLength).ToArray();
if (dataTemp.Length < PreFixLength + DataLength)//拆包后不满足一条指令的长度
{
continue;
}
//获取返回指令的板子ID
var boardId = (data[PreFixLength + 0] << 8) + data[PreFixLength + 1];
//查询当前板子是否有待验证的指令
var message = new MessageDto();
MessageList.TryGetValue(boardId, out message);
//功能位校验 功能位相同视为已响应指令 删除对应的指令
if (message?.Message[PreFixLength + 2] == dataTemp[PreFixLength + 2])
{
MessageList.TryRemove(boardId, out message);
}
index += (PreFixLength + DataLength - 1);//每次循环index会+1 所以这里-1
}
}
return null;
};
tcpClient.Connected += (client, e) =>
{
this.IsOnline = true;
return EasyTask.CompletedTask;
};
tcpClient.Disconnected += (client, e) =>
{
this.IsOnline = false;
return EasyTask.CompletedTask;
};
//配置数据重发机制
Task.Run(async () =>
{
while (true)
{
try
{
//TO DO如果指令未回应n次 则取消重发
Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
await Task.Delay(3000);
if (MessageList.Count > 0)
{
Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
foreach (var item in MessageList)
{
if (item.Value.LastSendTime < DateTime.Now.AddSeconds(3))
{
tcpClient.Send(item.Value.Message);
item.Value.SendTimes++;
item.Value.LastSendTime = DateTime.Now;
await Task.Delay(10);
}
}
}
}
catch
{
}
}
});
}
catch (Exception ex)
{
}
}
public void Send(byte[] message)
{
var boardId = (message[3] << 8) + message[4];
//记录发送指令 用于通信校验 同Id只校验最后一个指令
////MessageList.AddOrUpdate(boardId, new MessageDto()
////{
//// ID = boardId,
//// Message = message,
////}, (key, oldValue) => oldValue = new MessageDto()
////{
//// ID = boardId,
//// Message = message,
////});
lock (sendLockObject)
{
tcpClient.Send(message);
//发送自带10ms间隔
Thread.Sleep(10);
}
}
//生成协议明细
public byte[] GenerateMessage(int boardId, byte[] data)
{
var message = new byte[Prefix.Length + 2 + data.Length];
var boardIdData = BitConverter.GetBytes(unchecked((short)boardId));
// 检查是否需要交换字节
if (BitConverter.IsLittleEndian)
{
// 如果是小端序系统,则交换字节
byte temp = boardIdData[0];
boardIdData[0] = boardIdData[1];
boardIdData[1] = temp;
}
Buffer.BlockCopy(Prefix, 0, message, 0, Prefix.Length);
Buffer.BlockCopy(boardIdData, 0, message, Prefix.Length, boardIdData.Length);
Buffer.BlockCopy(data, 0, message, Prefix.Length + boardIdData.Length, data.Length);
return message;
}
}
//发送指令的记录
public class MessageDto
{
public int ID { get; set; }
/// <summary>
/// 最后一次发送时间
/// </summary>
public DateTime LastSendTime { get; set; } = DateTime.Now;
/// <summary>
/// 发送内容
/// </summary>
public byte[] Message { get; set; }
/// <summary>
/// 发送次数
/// </summary>
public int SendTimes { get; set; } = 0;//第几次发送
}
}

18
WCS.BLL/WCS.BLL.csproj Normal file
View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TouchSocket" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WCS.DAL\WCS.DAL.csproj" />
<ProjectReference Include="..\WCS.Model\WCS.Model.csproj" />
</ItemGroup>
</Project>