Files
wcs/WCS.WebApi/Controllers/SingleLightController.cs
hehaibing-1996 78f476ec9c 报警灯
2025-04-16 18:48:50 +08:00

256 lines
9.9 KiB
C#

using Microsoft.AspNetCore.Mvc;
using WCS.BLL.Services.IService;
using WCS.BLL.Services.Service;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.SelfCheck;
using WCS.Model.ApiModel.SingleLight;
using WCS.Model.ApiModel.Stocktaking;
using WCS.Model.ApiModel.User;
using WCS.Model.WebSocketModel;
namespace WCS.WebApi.Controllers
{
/// <summary>
/// 单灯单独控制亮灯接口 煤科院钻探分院项目
/// </summary>
[ApiController]
[Route("[controller]")]
public class SingleLightController : ControllerBase
{
public ISingleLightService _singleLightService { get; set; }
public SingleLightController(ISingleLightService singleLightService)
{
_singleLightService = singleLightService;
}
[Route("singleLightControl")]
[HttpPost(Name = "singleLightControl")]
public async Task<ResponseBase> SingleLightControl(SingleLightControlRequest request)
{
try
{
return await _singleLightService.SingleLightControl(request);
}
catch (Exception ex)
{
return new ResponseBase()
{
Code = 300,
Message = "操作失败:" + ex.Message,
};
}
}
[Route("turnoffLightByArea")]
[HttpPost(Name = "turnoffLightByArea")]
public async Task<ResponseBase> TurnoffLightByArea(TurnoffLightByAreaRequest request)
{
try
{
return await _singleLightService.TurnoffLightByArea(request);
}
catch (Exception ex)
{
return new ResponseBase()
{
Code = 300,
Message = "操作失败:" + ex.Message,
};
}
}
[Route("GetKanBanData")]
[HttpGet(Name = "GetKanBanData")]
public async Task<ResponseBase> GetKanBanData()
{
try
{
//获取单灯类型的库位
var stores = DbHelp.db.Queryable<StoreInfo>()
.Where(t => t.ShelfTypeId == 2)
.OrderBy(t => t.Area)
.OrderBy(t => t.StoreCode)
.Select(t => new
{
Area = t.Area,
StoreCode = t.StoreCode,
LightMode = t.LightMode,
ColorMode = t.ColorMode,
})
.ToList();
return new ResponseCommon()
{
Code = 200,
Message = "success",
Data = stores
};
}
catch (Exception ex)
{
return new ResponseBase()
{
Code = 300,
Message = "操作失败:" + ex.Message,
};
}
}
[Route("GenerateSingleLightStoreInfo")]
[HttpGet(Name = "GenerateSingleLightStoreInfo")]
public async Task<ResponseBase> GenerateSingleLightStoreInfo()
{
try
{
//获取单灯类型的货架
var shelfInfo = DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.ShelfTypeName == "信息化货架")
.OrderBy(t => t.ShelfCode)
.ToList();
var storesToSave = new List<StoreInfo>();
var modulesToSave = new List<ModuleInfo>();
foreach (var shelf in shelfInfo)
{
if (shelf.ShelfCode == "C07-4")
;
var row = shelf.Rowcounts % 2;
//如果是奇数行
if (row == 1)
{
//之前已经占用的id
var id = (shelf.Rowcounts - 1) * (shelf.Columncounts + 6);
//奇数行 灯Id是最后一个灯
for (int i = shelf.Columncounts; i > 0; i--)
{
var storeInfo = new StoreInfo()
{
StoreCode = shelf.ShelfCode + "-" + i.ToString(),
ShelfTypeId = shelf.ShelfTypeId,
ModuleId = 0,
ModuleCode = shelf.ShelfCode + "-" + i.ToString(),
ShelfId = shelf.Id,
ShelfCode = shelf.ShelfCode,
BoardId = ++id,
LightNumber = 1,
Priority = 0,
R = shelf.Rowcounts.ToString(),
C = i.ToString(),
Wei = "1",
SingleLightNumber = 1,
LightMode = 0,
ColorMode = 0,
GroupName = shelf.GroupName,
Area = shelf.ShelfCode.Substring(0, 1),
};
storesToSave.Add(storeInfo);
var moduleInfo = new ModuleInfo()
{
ModuleCode = shelf.ShelfCode + "-" + i.ToString(),
ShelfTypeId = shelf.ShelfTypeId,
ShelfId = shelf.Id,
ShelfCode = shelf.ShelfCode,
BoardId = storeInfo.BoardId,
LightCount = 1,
CleintIp = shelf.ClientIp,
GroupName = shelf.GroupName,
R = storeInfo.R,
C = storeInfo.C,
Bigshelfcode = "",
IsEnable = true,
CurrentMode = BLL.DbModels.Task.TaskModeEnum.,
};
modulesToSave.Add(moduleInfo);
}
shelf.LightId = ++id;
}
//偶数行
else
{
//之前已经占用的id
var id = (shelf.Rowcounts - 1) * (shelf.Columncounts + 6);
shelf.LightId = ++id;
//灯占6个ID
id = id + 5;
//奇数行 灯Id是最后一个灯
for (int i = 1; i <= shelf.Columncounts; i++)
{
var storeInfo = new StoreInfo()
{
StoreCode = shelf.ShelfCode + "-" + i.ToString(),
ShelfTypeId = shelf.ShelfTypeId,
ModuleId = 0,
ModuleCode = shelf.ShelfCode + "-" + i.ToString(),
ShelfId = shelf.Id,
ShelfCode = shelf.ShelfCode,
BoardId = ++id,
LightNumber = 1,
Priority = 0,
R = shelf.Rowcounts.ToString(),
C = i.ToString(),
Wei = "1",
SingleLightNumber = 1,
LightMode = 0,
ColorMode = 0,
GroupName = shelf.GroupName,
Area = shelf.ShelfCode.Substring(0, 1),
};
storesToSave.Add(storeInfo);
var moduleInfo = new ModuleInfo()
{
ModuleCode = shelf.ShelfCode + "-" + i.ToString(),
ShelfTypeId = shelf.ShelfTypeId,
ShelfId = shelf.Id,
ShelfCode = shelf.ShelfCode,
BoardId = storeInfo.BoardId,
LightCount = 1,
CleintIp = shelf.ClientIp,
GroupName = shelf.GroupName,
R = storeInfo.R,
C = storeInfo.C,
Bigshelfcode = "",
IsEnable = true,
CurrentMode = BLL.DbModels.Task.TaskModeEnum.,
};
modulesToSave.Add(moduleInfo);
}
}
}
DbHelp.db.Insertable(storesToSave).ExecuteCommand();
DbHelp.db.Insertable(modulesToSave).ExecuteCommand();
DbHelp.db.Updateable(shelfInfo).ExecuteCommand();
return new ResponseCommon()
{
Code = 200,
Message = "success",
Data = null
};
}
catch (Exception ex)
{
return new ResponseBase()
{
Code = 300,
Message = "操作失败:" + ex.Message,
};
}
}
}
}