Commit 6c3db362 by Seniorious

1

parent 633f8b75
using APIs.Common; using APIs.Common;
using APIs.Dto; using APIs.Dto;
using APIs.Req; using APIs.Req;
using APIs.TimedTasks;
using Autofac.Core; using Autofac.Core;
using AutoMapper; using AutoMapper;
using Common; using Common;
...@@ -36,6 +37,8 @@ using static Common.HttpHelper; ...@@ -36,6 +37,8 @@ using static Common.HttpHelper;
using static Dm.net.buffer.ByteArrayBuffer; using static Dm.net.buffer.ByteArrayBuffer;
using static Microsoft.AspNetCore.Razor.Language.TagHelperMetadata; using static Microsoft.AspNetCore.Razor.Language.TagHelperMetadata;
using static System.Net.Mime.MediaTypeNames; using static System.Net.Mime.MediaTypeNames;
using static JmpDehumidifierLib.Dehumidifier;
using JmpDehumidifierLib;
namespace APIs.Controllers namespace APIs.Controllers
{ {
...@@ -44,6 +47,7 @@ namespace APIs.Controllers ...@@ -44,6 +47,7 @@ namespace APIs.Controllers
public class BaseInfoController : ControllerBase public class BaseInfoController : ControllerBase
{ {
public IMapper Mapper { get; } public IMapper Mapper { get; }
private readonly IPoliceService _policeService; private readonly IPoliceService _policeService;
private readonly IEquipmentTypeService _equipmentTypeService; private readonly IEquipmentTypeService _equipmentTypeService;
private readonly IEquipmentSizeService _equipmentSizeService; private readonly IEquipmentSizeService _equipmentSizeService;
...@@ -64,14 +68,16 @@ namespace APIs.Controllers ...@@ -64,14 +68,16 @@ namespace APIs.Controllers
private readonly IBussinessInventoryService _bussinessInventoryService; private readonly IBussinessInventoryService _bussinessInventoryService;
private readonly IBussinessInventoryDetailService _bussinessInventoryDetailService; private readonly IBussinessInventoryDetailService _bussinessInventoryDetailService;
private readonly IChannelService _channelService; private readonly IChannelService _channelService;
private readonly DehumidifierHelper _dehumidifierHelper;
public BaseInfoController(IMapper mapper,IPoliceService policeService, IEquipmentTypeService equipmentTypeService, public BaseInfoController(IMapper mapper, DehumidifierHelper dehumidifierHelper, IPoliceService policeService, IEquipmentTypeService equipmentTypeService,
IEquipmentSizeService equipmentSizeService,ICarService carService, IInventoryService inventoryService, IEquipmentSizeService equipmentSizeService,ICarService carService, IInventoryService inventoryService,
IInvService invService, IUsersService usersService, ILogService logService, IDevHistoryService devHistoryService, IInvService invService, IUsersService usersService, ILogService logService, IDevHistoryService devHistoryService,
IDevService devService, IWarehouseService warehouseService, IOrderService orderService, ISupplierService supplierService, IDevService devService, IWarehouseService warehouseService, IOrderService orderService, ISupplierService supplierService,
IThisInfoService thisInfoService, IPrintService printService, IPoliceFingerService policeFingerService, IPoliceInfoService policeInfoService, IThisInfoService thisInfoService, IPrintService printService, IPoliceFingerService policeFingerService, IPoliceInfoService policeInfoService,
IBussinessInventoryService bussinessInventoryService, IBussinessInventoryDetailService bussinessInventoryDetailService, IChannelService channelService) IBussinessInventoryService bussinessInventoryService, IBussinessInventoryDetailService bussinessInventoryDetailService, IChannelService channelService)
{ {
_dehumidifierHelper = dehumidifierHelper;
_carService = carService; _carService = carService;
_equipmentSizeService = equipmentSizeService; _equipmentSizeService = equipmentSizeService;
_equipmentTypeService = equipmentTypeService; _equipmentTypeService = equipmentTypeService;
...@@ -96,6 +102,68 @@ namespace APIs.Controllers ...@@ -96,6 +102,68 @@ namespace APIs.Controllers
} }
/// <summary> /// <summary>
/// 设定除湿机
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult> SetDehumidifier([FromBody] SetDehumidifierReq req)
{
try
{
if (string.IsNullOrEmpty(req.devId) ||
req.setState == null)
{
return new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "参数不正确",
};
}
Dev myDev = await _devService.QueryOne(s => s.id.Equals(req.devId));
if (myDev != null)
{
if (!string.IsNullOrEmpty(req.setHumid))
{
myDev.setSd = req.setHumid;
}
if (req.setState != null)
{
myDev.setState = req.setState;
}
myDev.updateTime = DateTime.Now;
}
else
{
return new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = "无设备信息",
};
}
_dehumidifierHelper.SetDehumidifier(myDev);
await _devService.Update(myDev);
return new ApiResult
{
code = ResultCode.OPERATE_SUCCESS.Code,
msg = ResultCode.OPERATE_SUCCESS.Msg,
};
}
catch (Exception ex)
{
var error = new ApiResult
{
code = ResultCode.OPERATE_FAILED.Code,
msg = ex.Message,
};
return error;
}
}
/// <summary>
/// 手持机获取盘点单据 /// 手持机获取盘点单据
/// </summary> /// </summary>
/// <param name="req"></param> /// <param name="req"></param>
...@@ -152,7 +220,7 @@ namespace APIs.Controllers ...@@ -152,7 +220,7 @@ namespace APIs.Controllers
detailList = rs.DetailList detailList = rs.DetailList
}); });
var json = HttpHelper.HttpPost(AdminGlobalContext.jyzbConfig.Url + "BussinessInventory/Start", param); var json = HttpHelper.HttpPost(AdminGlobalContext.jyzbConfig.Url + "/BussinessInventory/Start", param);
if (string.IsNullOrEmpty(json)) if (string.IsNullOrEmpty(json))
{ {
await _bussinessInventoryService.OrderRollBack(rs); await _bussinessInventoryService.OrderRollBack(rs);
...@@ -811,7 +879,7 @@ namespace APIs.Controllers ...@@ -811,7 +879,7 @@ namespace APIs.Controllers
}; };
}else }else
{ {
var json = HttpHelper.HttpPost(AdminGlobalContext.jyzbConfig.Url + "BussinessInventory/UpdateFinger", JsonConvert.SerializeObject(req)); var json = HttpHelper.HttpPost(AdminGlobalContext.jyzbConfig.Url + "/PolicemanFinger/insertOrUpdateFingerInfo", JsonConvert.SerializeObject(req));
var httprs = JsonConvert.DeserializeObject<HttpHelper.res<string>>(json); var httprs = JsonConvert.DeserializeObject<HttpHelper.res<string>>(json);
if(httprs != null && httprs.code == "9920") if(httprs != null && httprs.code == "9920")
......
...@@ -38,4 +38,11 @@ namespace APIs.Req ...@@ -38,4 +38,11 @@ namespace APIs.Req
public string policeId { get; set; } public string policeId { get; set; }
public List<PoliceFinger> fingerList { get; set; } public List<PoliceFinger> fingerList { get; set; }
} }
public class SetDehumidifierReq
{
public string devId { get; set; }
public int? setState { get; set; }
public string setHumid { get; set; }
}
} }
\ No newline at end of file
...@@ -21,6 +21,7 @@ using Microsoft.AspNetCore.Mvc; ...@@ -21,6 +21,7 @@ using Microsoft.AspNetCore.Mvc;
using Quartz.Impl; using Quartz.Impl;
using Quartz; using Quartz;
using APIs.TimedTasks; using APIs.TimedTasks;
using Common;
namespace APIs namespace APIs
{ {
...@@ -78,6 +79,7 @@ namespace APIs ...@@ -78,6 +79,7 @@ namespace APIs
services.AddScoped<IBussinessInventoryService, BussinessInventoryService>(); services.AddScoped<IBussinessInventoryService, BussinessInventoryService>();
services.AddScoped<IBussinessInventoryDetailService, BussinessInventoryDetailService>(); services.AddScoped<IBussinessInventoryDetailService, BussinessInventoryDetailService>();
services.AddScoped<IChannelService, ChannelService>(); services.AddScoped<IChannelService, ChannelService>();
#endregion #endregion
#region Repository #region Repository
...@@ -112,12 +114,9 @@ namespace APIs ...@@ -112,12 +114,9 @@ namespace APIs
#endregion #endregion
#region 定时任务 #region 除湿机
//注册ISchedulerFactory的实例
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
#endregion
#region 后台常驻任务
services.AddSingleton<IHostedService, DehumidifierTask>(); services.AddSingleton<IHostedService, DehumidifierTask>();
services.AddSingleton<DehumidifierHelper>();
#endregion #endregion
#region 初始化全局配置信息 #region 初始化全局配置信息
......
...@@ -5,157 +5,39 @@ using Services.Interface; ...@@ -5,157 +5,39 @@ using Services.Interface;
using JmpDehumidifierLib; using JmpDehumidifierLib;
using Models.Table; using Models.Table;
using static JmpDehumidifierLib.Dehumidifier; using static JmpDehumidifierLib.Dehumidifier;
using Newtonsoft.Json;
using Common.Global;
using Microsoft.AspNetCore.Mvc.ViewComponents;
namespace APIs.TimedTasks namespace APIs.TimedTasks
{ {
public class DehumidifierTask : IHostedService public class DehumidifierTask : IHostedService
{ {
//private readonly ILogger<DehumidifierTask> _logger;
public IMapper Mapper { get; } public IMapper Mapper { get; }
private readonly IDevHistoryService _devHistoryService; private readonly DehumidifierHelper _dehumidifierHelper;
private readonly IDevService _devService;
public DehumidifierTask(IMapper mapper, IDevHistoryService devHistoryService, IDevService devService/*ILogger<DehumidifierTask> logger*/) public DehumidifierTask(IMapper mapper, DehumidifierHelper dehumidifierHelper)
{ {
_devHistoryService = devHistoryService; _dehumidifierHelper = dehumidifierHelper;
_devService = devService;
Mapper = mapper; Mapper = mapper;
//_logger = logger;
} }
Dictionary<string, Dehumidifier> devList = new Dictionary<string, Dehumidifier>(); public async Task StartAsync(CancellationToken cancellationToken)
public Task StartAsync(CancellationToken cancellationToken)
{ {
//_logger.LogInformation("订阅事件开始");
//开启本组织机构下所有除湿机并订阅温湿度变化事件
try try
{ {
List<Dev>? devs = _devService.Query().Result; _dehumidifierHelper.StartDehumidifier();
if (devs != null)
{
devList = devs.Select(s => new { Key = s.devIp, Value = new Dehumidifier(s.devIp, Convert.ToInt32(s.devPort)) })
.ToDictionary(s => s.Key, s => s.Value);
var openIpList = devs.Where(s => s.setState == 1).Select(s => s.devIp).ToList();
foreach (var item in devList)
{
if (openIpList.Contains(item.Key))
{
if (item.Value.Open())
{
try//避免影响设备温湿度获取
{
var mySetSd = devs.FirstOrDefault(s => s.devIp.Equals(item.Key))?.setSd;
if (!string.IsNullOrEmpty(mySetSd))
{
item.Value.SetHumid((byte)Convert.ToInt32(mySetSd));
}
}catch (Exception ex) { }
item.Value.OnStatusChanged += new Dehumidifier.StatusChanged(OnStatusChanged);
}
}
else
{
item.Value.Close();
}
}
}
} }
catch (Exception ex) catch (Exception ex)
{ {
//异常处理 //异常处理
} }
return Task.CompletedTask;
}
private Dictionary<string, DevHistory> DevHistoryDic = new Dictionary<string, DevHistory>();
private async void OnStatusChanged(MachineStatus args)
{
if (args.ErrorCode == 0)
{
var devIp = args.ip;
var warehouseWd = args.Temp.ToString(); // 室内温度
var warehouseSd = args.Humid.ToString(); // 室内湿度
var devState = args.IsWorking ? 1 : 0;
var devPort = args.port.ToString();
var myDev = (await _devService.Query()).FirstOrDefault(s => s.devIp.Equals(devIp));
if (myDev != null)
{
DevHistory record = new DevHistory()
{
warehouseId = myDev.warehouseId,
devCode = myDev.devCode,
devIp = devIp,
devPort = devPort,
devName = myDev.devName,
devId = myDev.id,
devState = devState,
warehouseSd = warehouseSd,
warehouseWd = warehouseWd,
setSd = myDev.setSd,
createTime = DateTime.Now,
};
if (DevHistoryDic.TryGetValue(devIp, out DevHistory thisHistory))
{
if(thisHistory.warehouseWd.Equals(record.warehouseWd)
&& thisHistory.warehouseSd.Equals(record.warehouseSd)
&& thisHistory.devState == record.devState)
{
return;
}
else
{
DevHistoryDic[devIp] = record;
}
}
else
{
DevHistoryDic.Add(record.devIp, record);
} }
await _devHistoryService.Add(record);
myDev.updateTime = DateTime.Now;
myDev.devState = devState;
myDev.warehouseSd = warehouseSd;
myDev.warehouseWd = warehouseWd;
await _devService.Update(myDev);
}
Thread.Sleep(10000);
}
else
{
foreach (var item in devList)
{
if (item.Key.Equals(args.ip))
{
Dehumidifier dev = new Dehumidifier(args.ip, args.port);
devList.Remove(item.Key);
devList.Add(args.ip, dev);
if (dev.Open())
{
dev.OnStatusChanged += new Dehumidifier.StatusChanged(OnStatusChanged);
}
}
}
}
}
public Task StopAsync(CancellationToken cancellationToken) public Task StopAsync(CancellationToken cancellationToken)
{ {
//_logger.LogInformation("订阅事件结束");
// TODO: 在这里取消订阅事件
return Task.CompletedTask; return Task.CompletedTask;
} }
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
"Launch": "http://*:5233;http://*:5243", "Launch": "http://*:5233;http://*:5243",
"AllowedHosts": "*", "AllowedHosts": "*",
"ConnectionStrings": { "ConnectionStrings": {
"MySQL": "server=192.168.3.128;port=3306;Database=pw;Uid=root;Pwd=123456;" "MySQL": "server=192.168.3.128;port=3306;Database=pw1;Uid=root;Pwd=123456;"
//RabbitMQ配置 //RabbitMQ配置
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论