276 lines
11 KiB
C#
276 lines
11 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
||
using WCS.BLL.Services.IService;
|
||
using WCS.BLL.Services.Service;
|
||
using WCS.Model.ApiModel.MatInventoryDetail;
|
||
using WCS.Model;
|
||
using WCS.Model.ApiModel.StoreInfo;
|
||
using WCS.BLL.DbModels;
|
||
using WCS.Model.ApiModel.MatBaseInfo;
|
||
using WCS.DAL.DbModels;
|
||
using WCS.DAL.Db;
|
||
using WCS.BLL.Config;
|
||
|
||
namespace WCS.WebApi.Controllers
|
||
{
|
||
/// <summary>
|
||
/// 货架管理、模组管理、库位管理的接口
|
||
/// </summary>
|
||
[ApiController]
|
||
[Route("[controller]")]
|
||
public class StoreInfoController : ControllerBase
|
||
{
|
||
public IStoreInfoService _storeInfoService { get; set; }
|
||
public StoreInfoController(IStoreInfoService storeInfoService)
|
||
{
|
||
_storeInfoService = storeInfoService;
|
||
}
|
||
|
||
#region 货架管理
|
||
[Route("getShelves")]
|
||
[HttpPost(Name = "getShelves")]
|
||
public async Task<ResponseBase> getShelves(GetShelvesRequest request)
|
||
{
|
||
return await _storeInfoService.GetShelves(request);
|
||
}
|
||
|
||
[HttpPost("addOrUpdateShelfInfo")]
|
||
public async Task<ResponseCommon<object>> addOrUpdateShelfInfo(AddShelfInfoRequest<ShelfInfo> request)
|
||
{
|
||
return await _storeInfoService.addOrUpdateShelfInfo(request);
|
||
}
|
||
|
||
[HttpPost("GenerateStoreInfo")]
|
||
public async Task<ResponseCommon<object>> GenerateStoreInfo()
|
||
{
|
||
return await _storeInfoService.GenerateStoreInfo();
|
||
}
|
||
#endregion
|
||
|
||
#region 模组管理
|
||
[Route("getModules")]
|
||
[HttpPost(Name = "getModules")]
|
||
public async Task<ResponseBase> getModules(GetModulesRequest request)
|
||
{
|
||
return await _storeInfoService.GetModules(request);
|
||
}
|
||
|
||
[Route("disableOrEnableModule")]
|
||
[HttpPost(Name = "disableOrEnableModule")]
|
||
public async Task<ResponseBase> disableOrEnableModule(DisableOrEnableModuleRequest request)
|
||
{
|
||
return await _storeInfoService.disableOrEnableModule(request);
|
||
}
|
||
|
||
[Route("queryModuleVoltage")]
|
||
[HttpPost(Name = "queryModuleVoltage")]
|
||
public async Task<ResponseBase> queryModuleVoltage(QueryModuleVoltageRequest request)
|
||
{
|
||
return await _storeInfoService.queryModuleVoltage(request);
|
||
}
|
||
|
||
[Route("queryStoreInfoHistoryVoltage")]
|
||
[HttpPost(Name = "queryStoreInfoHistoryVoltage")]
|
||
public async Task<ResponseBase> queryStoreInfoHistoryVoltage(QueryStoreInfoHistoryVoltageRequest request)
|
||
{
|
||
return await _storeInfoService.queryStoreInfoHistoryVoltage(request);
|
||
}
|
||
|
||
[Route("calibrationSetOffset")]
|
||
[HttpPost(Name = "calibrationSetOffset")]
|
||
public async Task<ResponseBase> calibrationSetOffset(CalibrationSetOffsetRequest request)
|
||
{
|
||
return await _storeInfoService.calibrationSetOffset(request);
|
||
}
|
||
#endregion
|
||
|
||
#region 库位管理
|
||
[Route("getStores")]
|
||
[HttpPost(Name = "getStores")]
|
||
public async Task<ResponseBase> getStores(GetStoresRequest request)
|
||
{
|
||
return await _storeInfoService.GetStores(request);
|
||
}
|
||
|
||
[Route("disableOrEnableStore")]
|
||
[HttpPost(Name = "disableOrEnableStore")]
|
||
public async Task<ResponseBase> disableOrEnableStore(DisableOrEnableStoreRequest request)
|
||
{
|
||
return await _storeInfoService.disableOrEnableStore(request);
|
||
}
|
||
|
||
[Route("getDisablePercent")]
|
||
[HttpPost(Name = "getDisablePercent")]
|
||
public async Task<ResponseBase> getDisablePercent(DisableOrEnableStoreRequest request)
|
||
{
|
||
return await _storeInfoService.getDisablePercent();
|
||
}
|
||
|
||
|
||
|
||
[Route("genModuleStoreInfos")]
|
||
[HttpPost(Name = "genModuleStoreInfos")]
|
||
public async Task<ResponseBase> genModuleStoreInfos(RequestBase request)
|
||
{
|
||
try
|
||
{
|
||
if (request.UserName != "aaa")
|
||
{
|
||
return new ResponseBase()
|
||
{
|
||
Code = 300,
|
||
Message = "用户名不对头!无法生成模组库位"
|
||
};
|
||
}
|
||
//获取货架 此组后端管的货架
|
||
var shelfInfos = DbHelp.db.Queryable<ShelfInfo>()
|
||
.Where(t => t.GroupName == LocalFile.Config.GroupName)
|
||
.OrderBy(t => t.BigShelfCode)
|
||
.OrderBy(t => t.ShelfCode)
|
||
.ToList();
|
||
|
||
var lastBindBigShelfCode = string.Empty;
|
||
var lastColumnCount = 1;
|
||
|
||
List<ModuleInfo> moduleInfos = new List<ModuleInfo>();
|
||
//生成模组
|
||
foreach (var shelfInfo in shelfInfos)
|
||
{
|
||
var modulePreFix = shelfInfo.IsBind ? shelfInfo.BigShelfCode : shelfInfo.ShelfCode;
|
||
//不绑定或者绑定换了面 重新从1开始计数
|
||
if (shelfInfo.BigShelfCode != lastBindBigShelfCode)
|
||
{
|
||
lastColumnCount = 1;
|
||
}
|
||
lastBindBigShelfCode = shelfInfo.BigShelfCode;
|
||
for (int rowIndex = 0; rowIndex < shelfInfo.Rowcounts; rowIndex++)
|
||
{
|
||
for (int columnIndex = 0; columnIndex < shelfInfo.Columncounts; columnIndex++)
|
||
{
|
||
var moduleCode = modulePreFix + "-R" + (rowIndex + 1).ToString() + "C" + (lastColumnCount + columnIndex).ToString();
|
||
var moduleInfo = new ModuleInfo()
|
||
{
|
||
ModuleCode = moduleCode,
|
||
ShelfTypeId = shelfInfo.ShelfTypeId,
|
||
ShelfId = shelfInfo.Id,
|
||
ShelfCode = shelfInfo.ShelfCode,
|
||
BoardId = shelfInfo.FirtstBoardId++,
|
||
LightCount = shelfInfo.LightCount,
|
||
CleintIp = shelfInfo.ClientIp,
|
||
GroupName = shelfInfo.GroupName,
|
||
R = (rowIndex + 1).ToString(),
|
||
C = (lastColumnCount + columnIndex).ToString(),
|
||
Bigshelfcode = shelfInfo.BigShelfCode,
|
||
IsEnable = true,
|
||
CurrentMode = BLL.HardWare.Mode.待机模式,
|
||
};
|
||
moduleInfos.Add(moduleInfo);
|
||
}
|
||
}
|
||
lastColumnCount = lastColumnCount + shelfInfo.Columncounts;
|
||
}
|
||
DbHelp.db.Insertable(moduleInfos).ExecuteCommand();
|
||
//生成库位
|
||
moduleInfos = DbHelp.db.Queryable<ModuleInfo>()
|
||
.Where(t => t.GroupName == LocalFile.Config.GroupName)
|
||
.OrderBy(t => t.Id)
|
||
.ToList();
|
||
List<StoreInfo> storeInfos = new List<StoreInfo>();
|
||
|
||
foreach (var moduleInfo in moduleInfos)
|
||
{
|
||
for (int wei = 0; wei < moduleInfo.LightCount; wei++)
|
||
{
|
||
var storeCode = moduleInfo.ModuleCode + "-" + (wei + 1).ToString();
|
||
var stroreInfo = new StoreInfo()
|
||
{
|
||
StoreCode = storeCode,
|
||
ShelfTypeId = moduleInfo.ShelfTypeId,
|
||
ModuleId = moduleInfo.Id,
|
||
ModuleCode = moduleInfo.ModuleCode,
|
||
ShelfId = moduleInfo.ShelfId,
|
||
ShelfCode = moduleInfo.ShelfCode,
|
||
BoardId = moduleInfo.BoardId,
|
||
LightNumber = wei + 1,
|
||
Priority = 0,
|
||
CurrentMatSn = string.Empty,
|
||
CurrentVoltage = 0,
|
||
StandardVoltage = 0,
|
||
OffsetVoltage = 0,
|
||
BigShelfCode = moduleInfo.Bigshelfcode,
|
||
R = moduleInfo.R,
|
||
C = moduleInfo.C,
|
||
Wei = (wei + 1).ToString(),
|
||
GroupName = moduleInfo.GroupName
|
||
};
|
||
storeInfos.Add(stroreInfo);
|
||
|
||
}
|
||
}
|
||
DbHelp.db.Insertable(storeInfos).ExecuteCommand();
|
||
|
||
return new ResponseBase()
|
||
{
|
||
Code = 200,
|
||
Message = "生成库位成功"
|
||
};
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new ResponseBase()
|
||
{
|
||
Code = 300,
|
||
Message = ex.Message
|
||
};
|
||
}
|
||
}
|
||
|
||
|
||
[Route("updateClientIp")]
|
||
[HttpPost(Name = "updateClientIp")]
|
||
public async Task<ResponseBase> updateClientIp(RequestBase request)
|
||
{
|
||
try
|
||
{
|
||
if (request.UserName != "aaa")
|
||
{
|
||
return new ResponseBase()
|
||
{
|
||
Code = 300,
|
||
Message = "用户名不对头!修改货架的IP。"
|
||
};
|
||
}
|
||
|
||
//获取货架 此组后端管的货架
|
||
var shelfInfos = DbHelp.db.Queryable<ShelfInfo>()
|
||
.Where(t => t.ClientIp.Contains(".225."))
|
||
.ToList();
|
||
shelfInfos.ForEach(t => t.ClientIp = t.ClientIp.Replace(".225.", ".210."));
|
||
|
||
|
||
var moduleInfos = DbHelp.db.Queryable<ModuleInfo>()
|
||
.Where(t => t.CleintIp.Contains(".225."))
|
||
.ToList();
|
||
moduleInfos.ForEach(t => t.CleintIp = t.CleintIp.Replace(".225.", ".210."));
|
||
|
||
DbHelp.db.Updateable(moduleInfos).UpdateColumns(t => new { t.CleintIp }).ExecuteCommand();
|
||
DbHelp.db.Updateable(shelfInfos).UpdateColumns(t => new { t.ClientIp }).ExecuteCommand();
|
||
|
||
return new ResponseBase()
|
||
{
|
||
Code = 200,
|
||
Message = "更新库位成功"
|
||
};
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new ResponseBase()
|
||
{
|
||
Code = 300,
|
||
Message = ex.Message
|
||
};
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
}
|