diff --git a/vol-net6/VOL.Core/BaseProvider/ServiceBase.cs b/vol-net6/VOL.Core/BaseProvider/ServiceBase.cs index d9978e7..1f79f5f 100644 --- a/vol-net6/VOL.Core/BaseProvider/ServiceBase.cs +++ b/vol-net6/VOL.Core/BaseProvider/ServiceBase.cs @@ -73,7 +73,7 @@ namespace VOL.Core.BaseProvider protected virtual void Init(IRepository repository) { - + IsMultiTenancy = true; // 开启租户隔离 } protected virtual Type GetRealDetailType() diff --git a/vol-net6/VOL.Core/Tenancy/TenancyManager.cs b/vol-net6/VOL.Core/Tenancy/TenancyManager.cs index 6d714cc..40fd8c7 100644 --- a/vol-net6/VOL.Core/Tenancy/TenancyManager.cs +++ b/vol-net6/VOL.Core/Tenancy/TenancyManager.cs @@ -16,16 +16,16 @@ namespace VOL.Core.Tenancy { string multiTenancyString = $"select * from {tableName}"; //超级管理员不限制 - //if (UserContext.Current.IsSuperAdmin) - //{ - // return multiTenancyString; - //} + if (UserContext.Current.IsSuperAdmin) + { + return multiTenancyString; + } switch (tableName) { //例如:指定用户表指定查询条件 - //case "Sys_User": - // multiTenancyString += $" where UserId='{UserContext.Current.UserId}'"; - // break; + case "Sys_User": + multiTenancyString += $" where UserId='{UserContext.Current.UserId}'"; + break; default: //开启数租户数据隔离,用户只能看到自己的表数据(自己根据需要写条件做租户数据隔离) multiTenancyString += $" where CreateID='{UserContext.Current.UserId}'"; diff --git a/vol-net6/VOL.Data/IServices/config/Partial/IData_ConfigService.cs b/vol-net6/VOL.Data/IServices/config/Partial/IData_ConfigService.cs index 8090314..655874a 100644 --- a/vol-net6/VOL.Data/IServices/config/Partial/IData_ConfigService.cs +++ b/vol-net6/VOL.Data/IServices/config/Partial/IData_ConfigService.cs @@ -11,5 +11,9 @@ namespace VOL.Data.IServices { // 获取设备配置列表 List getConfigList(); + + // 根据主键查询设备 + + Data_Config GetConfigById(int id); } } diff --git a/vol-net6/VOL.Data/IServices/modbus/IDataProcessing.cs b/vol-net6/VOL.Data/IServices/modbus/IDataProcessing.cs index 4cf2b05..0381af9 100644 --- a/vol-net6/VOL.Data/IServices/modbus/IDataProcessing.cs +++ b/vol-net6/VOL.Data/IServices/modbus/IDataProcessing.cs @@ -20,6 +20,9 @@ namespace VOL.Data.IServices.modbus Dictionary> readGSKData(IModbusService modbus); + // 获取设备配置信息 + Data_Config GetDataConfig(int deviceId); + // 保存设备数据 bool saveMachineData(Data_Machine machine, out string message); diff --git a/vol-net6/VOL.Data/Services/config/Partial/Data_ConfigService.cs b/vol-net6/VOL.Data/Services/config/Partial/Data_ConfigService.cs index ce52b68..4428e07 100644 --- a/vol-net6/VOL.Data/Services/config/Partial/Data_ConfigService.cs +++ b/vol-net6/VOL.Data/Services/config/Partial/Data_ConfigService.cs @@ -35,14 +35,18 @@ namespace VOL.Data.Services _httpContextAccessor = httpContextAccessor; _repository = dbRepository; //多租户会用到这init代码,其他情况可以不用 - //base.Init(dbRepository); + base.Init(dbRepository); } public List getConfigList() { - var list = _repository.DbContext.Set().Select(x => new Data_Config(){ + var list = _repository.DbContext.Set().Select(x => new Data_Config() { id = x.id, name = x.name, type = x.type, device_ip = x.device_ip, com_ip = x.com_ip - }).OrderBy(x=> x.id).ToList(); + }).OrderBy(x => x.id).ToList(); return list; } + + public Data_Config GetConfigById(int id) { + return _repository.DbContext.Set().FirstOrDefault(e => e.id == id); + } } } diff --git a/vol-net6/VOL.Data/Services/machine/Partial/Data_MachineService.cs b/vol-net6/VOL.Data/Services/machine/Partial/Data_MachineService.cs index f1eec00..4359bad 100644 --- a/vol-net6/VOL.Data/Services/machine/Partial/Data_MachineService.cs +++ b/vol-net6/VOL.Data/Services/machine/Partial/Data_MachineService.cs @@ -43,7 +43,7 @@ namespace VOL.Data.Services _httpContextAccessor = httpContextAccessor; _repository = dbRepository; //多租户会用到这init代码,其他情况可以不用 - //base.Init(dbRepository); + base.Init(dbRepository); } public Dictionary GetMachineData() diff --git a/vol-net6/VOL.Data/Services/modbus/DataProcessing.cs b/vol-net6/VOL.Data/Services/modbus/DataProcessing.cs index 904b6ef..5a79708 100644 --- a/vol-net6/VOL.Data/Services/modbus/DataProcessing.cs +++ b/vol-net6/VOL.Data/Services/modbus/DataProcessing.cs @@ -23,7 +23,6 @@ namespace VOL.Data.Services.modbus // 生产数据 Dictionary map1 = new Dictionary { - { "config_id", 1}, { "com_status",modbus.readData(1, 6430, "int16") }, // 通讯状态 5:通讯正常 15:通讯断线 { "run_time", (int)modbus.readData(1, 6435, "int16") }, // 运行时长 分钟 { "turnout_1",(int)modbus.readData(1, 6436, "int16") }, // 工单1产量 件 @@ -45,18 +44,17 @@ namespace VOL.Data.Services.modbus { // 操作模式 0:JOG 1:AUTO 2:AUTO + TEACHIN 3:JOG + REPOIN 4:JOG + REPOS // 5:MDA 6:MDA + REPOS 7:MDA + REPOS + TEAHIN8:MDA + TEACHIN - { "config_id", 1}, { "com_status", modbus.readData(1, 6430, "int16") }, // 通讯状态 5:通讯正常 15:通讯断线 { "smode", modbus.readData(1, 6099, "int16") }, { "state", modbus.readData(1, 6429, "int16") }, // 运行状态 0:待机 1:故障 2:运行 3:暂停 { "temperature", (decimal)modbus.readData(1, 1201, "single")}, // 电机温度 ℃ { "potential", (decimal)modbus.readData(1, 1203, "single")}, // 母线电压 V { "current", (decimal)modbus.readData(1, 1205, "single")}, // 实际电流 A - { "quantity", (long)modbus.readData(1, 1215, "single")}, // 加工数 次 { "cut_rate", (decimal)modbus.readData(1, 1225, "single")}, // 切削倍率 { "main_rate", (decimal)modbus.readData(1, 1231, "single")}, // 主轴倍率 { "run_program_no", modbus.readData(1, 6689, "string", 26)}, // 加工程序号 length = 52 { "run_time_total", (long)modbus.readData(1, 6435, "int16")}, // 累计运行时长 分钟 + { "quantity_total", (long)modbus.readData(1, 1215, "single")}, // 累计加工数 次 }; // 组装Map返回 @@ -72,7 +70,6 @@ namespace VOL.Data.Services.modbus // 生产数据 Dictionary map1 = new Dictionary { - { "config_id", 2}, // 枚举todo { "program_no", (int)modbus.readData(1, 6429, "int16") }, // 程序编号 { "com_status", modbus.readData(1, 6430, "int16") }, // 通讯状态 5:通讯正常 15:通讯断线 { "run_time", (int)modbus.readData(1, 6435, "int16") }, // 运行时长 分钟 @@ -93,18 +90,17 @@ namespace VOL.Data.Services.modbus // 机床数据 Dictionary map2 = new Dictionary { - { "config_id", 2}, { "com_status", modbus.readData(1, 6430, "int16") }, // 通讯状态 5:通讯正常 15:通讯断线 { "gmode", modbus.readData(1, 6099, "int16") }, // 工作方式 0:编辑 1:自动 2:MDI 3:DNC 4:手动 5:手轮 6:回参考点 { "state", modbus.readData(1, 6100, "int16") }, // 运行状态 0:复位 1:停止 2:运行 3:暂停 - { "quantity", (long)modbus.readData(1, 1199, "int32")}, // 加工数量 次 + { "quantity", (long)modbus.readData(1, 4117, "int32")}, // 当天加工数量 次 { "on_time", (long)modbus.readData(1, 1201, "int32")}, // 开机时间 秒 { "run_time", (long)modbus.readData(1, 1203, "int32")}, // 运行时间 秒 - { "feed_rate", (decimal)modbus.readData(1, 1242, "single")}, // 进给倍率 - { "main_rate", (decimal)modbus.readData(1, 1248, "single")}, // 主轴倍率 + { "feed_rate", (decimal)modbus.readData(1, 1241, "single")}, // 进给倍率 + { "main_rate", (decimal)modbus.readData(1, 1247, "single")}, // 主轴倍率 { "run_program_no", modbus.readData(1, 6299, "string", 4)}, // 运行程序编号 length = 8 { "run_time_total", (long)modbus.readData(1, 4115, "int32")}, // 累计运行时长 分钟 - { "quantity_total", (long)modbus.readData(1, 4117, "int32")} // 累计加工数 次 + { "quantity_total", (long)modbus.readData(1, 1199, "int32")} // 累计加工数 次 }; // 组装Map返回 @@ -114,6 +110,12 @@ namespace VOL.Data.Services.modbus return map; } + // 查询设备信息 + + public Data_Config GetDataConfig(int deviceId) { + return Data_ConfigService.Instance.GetConfigById(deviceId); + } + // 保存机床数据 public bool saveMachineData(Data_Machine machine, out string message) { diff --git a/vol-net6/VOL.Data/Services/produce/Partial/Data_ProduceService.cs b/vol-net6/VOL.Data/Services/produce/Partial/Data_ProduceService.cs index 6d8064c..782b805 100644 --- a/vol-net6/VOL.Data/Services/produce/Partial/Data_ProduceService.cs +++ b/vol-net6/VOL.Data/Services/produce/Partial/Data_ProduceService.cs @@ -37,7 +37,7 @@ namespace VOL.Data.Services _httpContextAccessor = httpContextAccessor; _repository = dbRepository; //多租户会用到这init代码,其他情况可以不用 - //base.Init(dbRepository); + base.Init(dbRepository); } diff --git a/vol-net6/VOL.System/IServices/System/Partial/ISys_DepartmentService.cs b/vol-net6/VOL.System/IServices/System/Partial/ISys_DepartmentService.cs index cdf6107..6831766 100644 --- a/vol-net6/VOL.System/IServices/System/Partial/ISys_DepartmentService.cs +++ b/vol-net6/VOL.System/IServices/System/Partial/ISys_DepartmentService.cs @@ -5,9 +5,12 @@ using VOL.Core.BaseProvider; using VOL.Entity.DomainModels; using VOL.Core.Utilities; using System.Linq.Expressions; +using System.Threading.Tasks; namespace VOL.System.IServices { public partial interface ISys_DepartmentService { + // 获取用户关联根部门 + Task GetUserDepartment(int userId); } } diff --git a/vol-net6/VOL.System/Services/System/Partial/Sys_DepartmentService.cs b/vol-net6/VOL.System/Services/System/Partial/Sys_DepartmentService.cs index 8083de3..a350de3 100644 --- a/vol-net6/VOL.System/Services/System/Partial/Sys_DepartmentService.cs +++ b/vol-net6/VOL.System/Services/System/Partial/Sys_DepartmentService.cs @@ -20,6 +20,8 @@ using VOL.System.IRepositories; using System.Collections.Generic; using VOL.Core.ManageUser; using VOL.Core.UserManager; +using VOL.Core.DBManager; +using System.Threading.Tasks; namespace VOL.System.Services { @@ -96,6 +98,22 @@ namespace VOL.System.Services { return base.Del(keys, delList).Reload(); } + + + public async Task GetUserDepartment(int userId) { + var dapper = DBServerProvider.SqlDapper; + string sql = @"SELECT + d.DepartmentId, + d.DepartmentCode, + d.DepartmentName + FROM + sys_department AS d + LEFT JOIN sys_userdepartment AS ud ON ud.DepartmentId = d.DepartmentId + WHERE + ud.UserId = @userId + AND d.ParentId IS NULL;"; + return await dapper.QueryFirstAsync(sql, new { userId }); ; + } } } diff --git a/vol-net6/VOL.WebApi/Controllers/Data/DataCaptureController.cs b/vol-net6/VOL.WebApi/Controllers/Data/DataCaptureController.cs deleted file mode 100644 index 98671c9..0000000 --- a/vol-net6/VOL.WebApi/Controllers/Data/DataCaptureController.cs +++ /dev/null @@ -1,148 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Authorization; -using System; -using VOL.Core.Filters; -using VOL.Data.IServices.modbus; -using VOL.Data.Services.modbus; -using Microsoft.Extensions.DependencyInjection; -using VOL.WebApi.Utils; -using VOL.Entity.DomainModels; -using System.Collections.Generic; -using Confluent.Kafka; - -namespace VOL.WebApi.Controllers.Data -{ - /// - /// 数据采集API类 - /// - [Route("api/Data_Capture")] - [AllowAnonymous] - public class DataCaptureController : Controller - { - private ModbusTcpService _service; // 静态字段 - - private readonly IHttpContextAccessor _httpContextAccessor; - - private readonly IDataProcessing _dataService; // 业务处理 - - - [ActivatorUtilitiesConstructor] - public DataCaptureController( - IDataProcessing dataService, - IHttpContextAccessor httpContextAccessor - ) - { - _dataService = dataService; - _httpContextAccessor = httpContextAccessor; - } - - - /// - /// 采集西门子设备 - /// - /// IActionResult - [ApiTask] - [HttpGet, HttpPost, Route("gatherSiemens")] - public IActionResult gatherSiemens() - { - try - { - _service = new ModbusTcpService("192.168.1.99", 502); - Console.WriteLine("siemens modbus tcp connected..."); - } - catch (Exception) - { - Console.WriteLine("siemens modbus tcp connect failed!"); - return Content("siemens modbus tcp connect failed!"); - } - if (!_service.isConnected) - { - Console.WriteLine("siemens modbus tcp disconnect!"); - return Content("siemens modbus tcp disconnect!"); - } - string message = ""; - try { - Dictionary> dataMap = _dataService.readSiemensData(_service); - message = saveSourceData(dataMap); - } catch (Exception ex) { - Console.WriteLine(ex.Message); - message = "read data error: " + ex.Message; - } finally { - _service.disConnent(); - } - return Content(message); - } - - - /// - /// 采集广数设备 - /// - /// IActionResult - [ApiTask] - [HttpGet, HttpPost, Route("gatherGSK")] - public IActionResult gatherGSK() - { - try - { - _service = new ModbusTcpService("192.168.1.100", 502); - Console.WriteLine("siemens modbus tcp connected..."); - } - catch (Exception) - { - Console.WriteLine("siemens modbus tcp connect failed!"); - return Content("siemens modbus tcp connect failed!"); - } - if (!_service.isConnected) - { - Console.WriteLine("siemens modbus tcp disconnect!"); - return Content("siemens modbus tcp disconnect!"); - } - string message = ""; - try - { - Dictionary> dataMap = _dataService.readGSKData(_service); - message = saveSourceData(dataMap); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - message = "read data error: " + ex.Message; - } - finally - { - _service.disConnent(); - } - return Content(message); - } - - - [HttpGet, HttpPost, Route("testSave")] - public IActionResult testSave() - { - Dictionary> dataMap = new(); - dataMap.Add("machine", new Dictionary() { { "config_id", 666 } }); - dataMap.Add("produce", new Dictionary() { { "config_id", 666 } }); - string message = saveSourceData(dataMap); - return Content(message); - } - - - private string saveSourceData(Dictionary> dataMap) { - // 获取当前系统时间, 保证插入时间一致 - DateTime now = DateTime.Now; - - Dictionary machineData = dataMap["machine"]; - Data_Machine data_Machine = CommonUtil.ConvertToObject(machineData); - data_Machine.CreateDate = now; - bool result1 = _dataService.saveMachineData(data_Machine, out string message1); - - Dictionary produceData = dataMap["produce"]; - Data_Produce data_Produce = CommonUtil.ConvertToObject(produceData); - data_Produce.CreateDate = now; - bool result2 = _dataService.saveProduceData(data_Produce, out string message2); - - return (result1 && result2) ? "OK" : "save machine: " + message1 + "; save produce" + message2 + ";"; - } - } -} diff --git a/vol-net6/VOL.WebApi/Controllers/Data/NKNCaptureController.cs b/vol-net6/VOL.WebApi/Controllers/Data/NKNCaptureController.cs new file mode 100644 index 0000000..f2b516f --- /dev/null +++ b/vol-net6/VOL.WebApi/Controllers/Data/NKNCaptureController.cs @@ -0,0 +1,244 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using System; +using VOL.Core.Filters; +using VOL.Data.IServices.modbus; +using VOL.Data.Services.modbus; +using Microsoft.Extensions.DependencyInjection; +using VOL.WebApi.Utils; +using VOL.Entity.DomainModels; +using System.Collections.Generic; +using Microsoft.Extensions.Primitives; + +/// +// 尼可尼数据采集 +/// +namespace VOL.WebApi.Controllers.Data +{ + /// + /// 数据采集API类 + /// + [Route("api/NKNCapture")] + [AllowAnonymous] + public class NKNCaptureController : Controller + { + private ModbusTcpService _service; // 静态字段 + + private readonly IHttpContextAccessor _httpContextAccessor; + + private readonly IDataProcessing _dataService; // 业务处理 + + + [ActivatorUtilitiesConstructor] + public NKNCaptureController( + IDataProcessing dataService, + IHttpContextAccessor httpContextAccessor + ) + { + _dataService = dataService; + _httpContextAccessor = httpContextAccessor; + } + + + /// + /// 采集西门子设备 + /// + /// IActionResult + [ApiTask] + [HttpGet, HttpPost, Route("gatherSiemens")] + public IActionResult gatherSiemens() + { + var headers = _httpContextAccessor.HttpContext.Request.Headers; + headers.TryGetValue("USER-DEVICE-ID", out StringValues deviceIdStr); + try + { + _service = new ModbusTcpService("192.168.1.99", 502); + Console.WriteLine("siemens modbus tcp connected..."); + } + catch (Exception) + { + Console.WriteLine("siemens modbus tcp connect failed!"); + return Content("siemens modbus tcp connect failed!"); + } + if (!_service.isConnected) + { + Console.WriteLine("siemens modbus tcp disconnect!"); + return Content("siemens modbus tcp disconnect!"); + } + // 切削倍率 17136 1 + //_service.readData(1, 6435, "int16"); // 运行时长 分钟 + //_service.readData(1, 6436, "int16"); // 工单1产量 件 + //_service.readData(1, 6437, "int16"); // 工单2产量 件 + //_service.readData(1, 6438, "int16"); // 工单3产量 件 + //_service.readData(1, 6439, "int16"); // 当班产量 件 + //_service.readData(1, 6440, "int16"); // 运行状态 0:待机 1:运行 2:故障 + //_service.readData(1, 1315, "single"); // 工单1任务进度 % + //_service.readData(1, 1317, "single"); // 工单2任务进度 % + //_service.readData(1, 1319, "single"); // 工单3任务进度 % + //_service.readData(1, 1321, "single"); // 工单1良品率 % 真实值 *= 100 + //_service.readData(1, 1323, "single"); // 工单2良品率 % 真实值 *= 100 + //_service.readData(1, 1325, "single"); // 工单3良品率 % 真实值 *= 100 + //_service.readData(1, 1339, "single"); // 设备综合效率 % 真实值 *= 100 + + //dynamic d1 = _service.readData(1, 1201, "single"); // 电机温度 ℃ + //dynamic d2 = _service.readData(1, 1203, "single"); // 母线电压 V + //dynamic d3 = _service.readData(1, 1205, "single"); // 实际电流 A + //dynamic d4 = _service.readData(1, 1215, "single"); // 累计加工次数 + //dynamic d5 = _service.readData(1, 1225, "single"); // 切削倍率 + //dynamic d6 = _service.readData(1, 1231, "single"); // 主轴倍率 + //dynamic d7 = _service.readData(1, 6689, "string", 50); // 运行程序编号 length = 8 + //dynamic d8 = _service.readData(1, 6435, "int16"); // 累计运行时长 分钟 + string message = ""; + bool success = int.TryParse(deviceIdStr, out int deviceId); + try + { + if (success) + { + Dictionary> dataMap = _dataService.readSiemensData(_service); + message = saveSourceData(dataMap, deviceId); + } + else + { + message = "设备非法或已下线"; + } + + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + message = "read data error: " + ex.Message; + } + finally + { + _service.disConnent(); + } + return Content(message); + } + + + /// + /// 采集广数设备 + /// + /// IActionResult + [ApiTask] + [HttpGet, HttpPost, Route("gatherGSK")] + public IActionResult gatherGSK() + { + var headers = _httpContextAccessor.HttpContext.Request.Headers; + headers.TryGetValue("USER-DEVICE-ID", out StringValues deviceIdStr); + try + { + _service = new ModbusTcpService("192.168.1.100", 502); + Console.WriteLine("GSK modbus tcp connected..."); + } + catch (Exception) + { + Console.WriteLine("GSK modbus tcp connect failed!"); + return Content("GSK modbus tcp connect failed!"); + } + if (!_service.isConnected) + { + Console.WriteLine("GSK modbus tcp disconnect!"); + return Content("GSK modbus tcp disconnect!"); + } + + //_service.readData(1, 6429, "int16"); // 程序编号 + //_service.readData(1, 6435, "int16"); // 通讯状态 5:通讯正常 15:通讯断线 + //_service.readData(1, 6430, "int16"); + //_service.readData(1, 6435, "int16"); // 运行时长 分钟 + //_service.readData(1, 6436, "int16"); // 工单1产量 件 + //_service.readData(1, 6437, "int16"); // 工单2产量 件 + //_service.readData(1, 6438, "int16"); // 工单3产量 件 + //_service.readData(1, 6439, "int16"); // 当班产量 件 + //_service.readData(1, 6440, "int16"); // 运行状态 0:待机 1:运行 2:故障 + //_service.readData(1, 1315, "single"); // 工单1任务进度 % + //_service.readData(1, 1317, "single"); // 工单2任务进度 % + //_service.readData(1, 1319, "single"); // 工单3任务进度 % + //_service.readData(1, 1321, "single"); // 工单1良品率 % 真实值 *= 100 + //_service.readData(1, 1323, "single"); // 工单2良品率 % 真实值 *= 100 + //_service.readData(1, 1325, "single"); // 工单3良品率 % 真实值 *= 100 + //_service.readData(1, 1331, "single"); // 设备综合效率 % 真实值 *= 100 + + //_service.readData(1, 6430, "int16"); // 通讯状态 5:通讯正常 15:通讯断线 + //_service.readData(1, 6099, "int16"); // 工作方式 0:编辑 1:自动 2:MDI 3:DNC 4:手动 5:手轮 6:回参考点 + //_service.readData(1, 6100, "int16"); // 运行状态 0:复位 1:停止 2:运行 3:暂停 + //dynamic d1 = _service.readData(1, 4117, "int32"); // 当天加工数量 次 + //dynamic d2 = _service.readData(1, 1201, "int32"); // 开机时间 秒 + //dynamic d3 = _service.readData(1, 1203, "int32"); // 运行时间 秒 + //dynamic d4 = _service.readData(1, 1241, "single"); // 进给倍率 + //dynamic d5 = _service.readData(1, 1247, "single"); // 主轴倍率 + //dynamic d6 = _service.readData(1, 6299, "string", 8); // 运行程序编号 length = 8 + //dynamic d7 = _service.readData(1, 4115, "int32"); // 累计运行时长 分钟 + //dynamic d8 = _service.readData(1, 1199, "int32"); // 累计加工数 次 + + string message = ""; + bool success = int.TryParse(deviceIdStr, out int deviceId); + try + { + if (success) + { + Dictionary> dataMap = _dataService.readGSKData(_service); + message = saveSourceData(dataMap, deviceId); + } + else + { + message = "设备非法或已下线"; + } + } + catch (Exception ex) + { + Console.WriteLine(ex.StackTrace); + message = "read data error: " + ex.Message; + } + finally + { + _service.disConnent(); + } + return Content(message); + } + + + [HttpGet, HttpPost, Route("testSave")] + public IActionResult testSave() + { + Dictionary> dataMap = new(); + dataMap.Add("machine", new Dictionary() { { "config_id", 666 } }); + dataMap.Add("produce", new Dictionary() { { "config_id", 666 } }); + string message = saveSourceData(dataMap, 1); + return Content(message); + } + + + /// + /// 保存采集数据 + /// + /// IActionResult + private string saveSourceData(Dictionary> dataMap, int deviceId) + { + // 获取当前系统时间, 保证插入时间一致 + DateTime now = DateTime.Now; + // 设备关联的用户信息 + Data_Config dataConfig = _dataService.GetDataConfig(deviceId); + if (dataConfig == null) { + return "设备不存在!"; + } + int userId = dataConfig.CreateID ?? 1; // 默认超管 + Dictionary machineData = dataMap["machine"]; + Data_Machine data_Machine = CommonUtil.ConvertToObject(machineData); + data_Machine.config_id = deviceId; + data_Machine.CreateDate = now; + data_Machine.CreateID = userId; + bool result1 = _dataService.saveMachineData(data_Machine, out string message1); + + Dictionary produceData = dataMap["produce"]; + Data_Produce data_Produce = CommonUtil.ConvertToObject(produceData); + data_Produce.config_id = deviceId; + data_Produce.CreateDate = now; + data_Produce.CreateID = userId; + bool result2 = _dataService.saveProduceData(data_Produce, out string message2); + + return (result1 && result2) ? "OK" : "save machine: " + message1 + "; save produce: " + message2 + ";"; + } + } +} diff --git a/vol-net6/VOL.WebApi/Controllers/System/Partial/Sys_DepartmentController.cs b/vol-net6/VOL.WebApi/Controllers/System/Partial/Sys_DepartmentController.cs index a800825..7848355 100644 --- a/vol-net6/VOL.WebApi/Controllers/System/Partial/Sys_DepartmentController.cs +++ b/vol-net6/VOL.WebApi/Controllers/System/Partial/Sys_DepartmentController.cs @@ -125,6 +125,20 @@ namespace VOL.System.Controllers }).ToListAsync(); return JsonNormal(new { rows }); } + + /// + /// 获取用户根部门 + /// + /// + [HttpGet, Route("getUserDepartment")] + [ApiActionPermission()] + public async Task GetUserDepartment() + { + int useId = UserContext.Current.UserId; + var sysDepartment = await _service.GetUserDepartment(useId); + + return JsonNormal(new { sysDepartment.DepartmentName, sysDepartment.DepartmentId }); + } } } diff --git a/vol-net6/VOL.WebApi/Controllers/System/Partial/Sys_QuartzOptionsController.cs b/vol-net6/VOL.WebApi/Controllers/System/Partial/Sys_QuartzOptionsController.cs index 38f185e..b2aa628 100644 --- a/vol-net6/VOL.WebApi/Controllers/System/Partial/Sys_QuartzOptionsController.cs +++ b/vol-net6/VOL.WebApi/Controllers/System/Partial/Sys_QuartzOptionsController.cs @@ -13,6 +13,7 @@ using VOL.Entity.DomainModels; using VOL.System.IServices; using VOL.Core.Filters; using VOL.Core.Enums; +using Microsoft.Extensions.Primitives; namespace VOL.System.Controllers { @@ -40,6 +41,8 @@ namespace VOL.System.Controllers [HttpGet, HttpPost, Route("test")] public IActionResult Test() { + //var headers = _httpContextAccessor.HttpContext.Request.Headers; + //headers.TryGetValue("USER-DEVICE-ID", out StringValues val); //AuthKey return Content(DateTime.Now.ToString("yyyy-MM-dd HH:mm:sss")); } diff --git a/vol-net6/VOL.WebApi/Utils/DataConvertUtil.cs b/vol-net6/VOL.WebApi/Utils/DataConvertUtil.cs index 2bfb7c9..eb0f2dd 100644 --- a/vol-net6/VOL.WebApi/Utils/DataConvertUtil.cs +++ b/vol-net6/VOL.WebApi/Utils/DataConvertUtil.cs @@ -65,15 +65,16 @@ namespace VOL.WebApi.Utils try { ushort[] temp = new ushort[2]; + for (int i = 0; i < 2; i++) { temp[i] = src[i + start]; } - byte[] bytesTemp = Ushorts2Bytes(temp,false); - Array.Reverse(bytesTemp); + Array.Reverse(temp); // !!!BitConverter默认是小端转换,如果是大端字节顺序数组接收,需要先反序字节顺序 - float res = BitConverter.ToSingle(bytesTemp, 0); - return res; + byte[] bytesTemp = Ushorts2Bytes(temp,false); + float f = BitConverter.ToSingle(bytesTemp, 0); + return float.Parse(f.ToString("F2")); // 保留两位小数 } catch (Exception e) { return 0; @@ -148,7 +149,7 @@ namespace VOL.WebApi.Utils temp[0] = src[start]; temp[1] = src[start + 1]; // 0 100 Array.Reverse(temp); // 100 0 地址低位存储低字节数据(小端) - byte[] bytesTemp = Ushorts2Bytes(temp); + byte[] bytesTemp = Ushorts2Bytes(temp,false); int res = BitConverter.ToInt32(bytesTemp, 0); return res; } catch (Exception e) diff --git a/vol-net6/VOL.WebApi/wwwroot/Upload/Tables/Sys_User/202309270810424470/yz.png b/vol-net6/VOL.WebApi/wwwroot/Upload/Tables/Sys_User/202309270810424470/yz.png new file mode 100644 index 0000000..aa891a0 Binary files /dev/null and b/vol-net6/VOL.WebApi/wwwroot/Upload/Tables/Sys_User/202309270810424470/yz.png differ diff --git a/vol-vue3/src/views/Index.vue b/vol-vue3/src/views/Index.vue index 301a815..683d740 100644 --- a/vol-vue3/src/views/Index.vue +++ b/vol-vue3/src/views/Index.vue @@ -20,7 +20,7 @@
-
上海尼可尼泵业有限公司
+
{{departName}}