Files
wcs/WCS.BLL/Services/Service/StoreInfoService.cs

869 lines
40 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TouchSocket.Core;
using WCS.BLL.Config;
using WCS.BLL.DbModels;
using WCS.BLL.HardWare;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.DAL;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.InOutRecord;
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) * request.PageSize + 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.BigShelfCode = request.ShelfInfo.BigShelfCode;
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,
BigShelfCode = request.ShelfInfo.BigShelfCode,
};
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;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public async Task<ResponseCommon<object>> GenerateStoreInfo()
{
//var shelfInfos = DbHelp.db.Queryable<ShelfInfo>().ToList();
//foreach (var shelfInfo in shelfInfos)
//{
var ModuleInfos = await DbHelp.db.Queryable<ModuleInfo>().ToListAsync();
ModuleInfos.ForEach(moduleInfo =>
{
for (int i = 1; i <= moduleInfo.LightCount; i++)
{
var storeInfo = new StoreInfo()
{
StoreCode = moduleInfo.ModuleCode + "-" + i.ToString(),
ShelfTypeId = 1,
ModuleId = moduleInfo.Id,
ModuleCode = moduleInfo.ModuleCode,
ShelfId = moduleInfo.ShelfId,
ShelfCode = moduleInfo.ShelfCode,
BoardId = moduleInfo.BoardId,
LightNumber = i,
Priority = 1,
CurrentMatSn = string.Empty,
BigShelfCode = moduleInfo.Bigshelfcode,
R = moduleInfo.R,
C = moduleInfo.C,
Wei = i.ToString(),
GroupName = moduleInfo.GroupName,
};
DbHelp.db.Insertable(storeInfo).ExecuteCommand();
}
});
//}
return new ResponseCommon<object>() { Message = "111" };
}
#region
public async Task<PageQueryResponse<ModuleInfo>> GetModules(GetModulesRequest request)
{
try
{
var recordsQueryable = DbHelp.db.Queryable<ModuleInfo>()
.WhereIF(!string.IsNullOrEmpty(request.ModuleCode), t => t.ModuleCode.Contains(request.ModuleCode))
.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) * request.PageSize + i + 1;
}
return new PageQueryResponse<ModuleInfo>()
{
Code = 200,
Message = $"success",
Data = new PageQueryResponseData<ModuleInfo>()
{
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<ModuleInfo>()
{
Code = 300,
Message = $"操作失败:{ex.Message}",
};
}
}
/// <summary>
/// 禁用或启用模组
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<ResponseCommon> disableOrEnableModule(DisableOrEnableModuleRequest request)
{
//找到库位
var moduleInfo = await DbHelp.db.Queryable<ModuleInfo>()
.Where(t => t.Id == request.ModuleId)
.FirstAsync();
//库位不存在
if (moduleInfo == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"操作失败:模组{request.ModuleCode}不存在!"
};
}
try
{
DbHelp.db.BeginTran();
//禁用
if (request.DisableOrEnable == DisableOrEnableEnum.Disable)
{
moduleInfo.IsEnable = false;
//盟讯公司发送钉钉消息
if (LocalFile.Config.IsMx)
{
var DingDing = string.Empty;
MXBackgroundThread.SendDingDingMsg($"【智能货架】模组{moduleInfo.ModuleCode}被屏蔽(模组管理),请及时调查或维保硬件!", new List<string> { "104379", "103595" }, ref DingDing);
Logs.Write($"【智能货架】模组{moduleInfo.ModuleCode}被屏蔽(模组管理),请及时调查或维保硬件!");
#region
Task.Run(() =>
{
var disabledStore = DbHelp.db.Queryable<StoreInfo>()
.Where(t => t.CurrentMatSn == "禁用")
.ToList();
var allStore = DbHelp.db.Queryable<StoreInfo>()
.ToList();
var disabledCount = disabledStore.Count();
var allCount = allStore.Count();
var disabledACount = disabledStore.Where(t => t.ShelfCode.Contains("A")).ToList().Count();
var allACount = allStore.Where(t => t.ShelfCode.Contains("A")).ToList().Count();
var disabledCCount = disabledStore.Where(t => t.ShelfCode.Contains("C")).ToList().Count();
var allCCount = allStore.Where(t => t.ShelfCode.Contains("C")).ToList().Count();
var disabledModule = DbHelp.db.Queryable<ModuleInfo>()
.Where(t => t.IsEnable == false)
.ToList();
var allModule = DbHelp.db.Queryable<ModuleInfo>()
.ToList();
var disabledModuleCount = disabledModule.Count();
var allModuleCount = allModule.Count();
var disabledAModuleCount = disabledModule.Where(t => t.ShelfCode.Contains("A")).ToList().Count();
var allAModuleCount = allModule.Where(t => t.ShelfCode.Contains("A")).ToList().Count();
var disabledCModuleCount = disabledModule.Where(t => t.ShelfCode.Contains("C")).ToList().Count();
var allCModuleCount = allModule.Where(t => t.ShelfCode.Contains("C")).ToList().Count();
var message = $"【智能货架】当前库位总数{allCount},禁用总数{disabledCount},禁用率{((double)disabledCount / allCount).ToString("P")}" +
$"其中A区库位总数{allACount},禁用数{disabledACount},禁用率{((double)disabledACount / allACount).ToString("P")}" +
$"C区库位总数{allCCount},禁用数{disabledCCount},禁用率{((double)disabledCCount / allCCount).ToString("P")}。\r\n" +
$"当前模组总数{allModuleCount},禁用总数{disabledModuleCount},禁用率{((double)disabledModuleCount / allModuleCount).ToString("P")}" +
$"其中A区模组总数{allAModuleCount},禁用数{disabledAModuleCount},禁用率{((double)disabledAModuleCount / allAModuleCount).ToString("P")}" +
$"C区模组总数{allCModuleCount},禁用数{disabledCModuleCount},禁用率{((double)disabledCModuleCount / allCModuleCount).ToString("P")}。";
Logs.Write(message);
var dd = string.Empty;
MXBackgroundThread.SendDingDingMsg(message, new List<string> { "104379", "103595" }, ref dd);
});
#endregion
}
}
else
{
moduleInfo.IsEnable = true;
}
DbHelp.db.Updateable(moduleInfo).ExecuteCommand();
DbHelp.db.CommitTran();
#region /
try
{
var shelf = ShelfManager.Shelves.Where(t => t.ShelfId == moduleInfo.ShelfId)
.FirstOrDefault();
if (shelf != null)
{
var moduleInPc = shelf.Modules.Where(t => t.ModuleId == moduleInfo.Id)
.First();
if (moduleInPc != null)
moduleInPc.IsEnable = request.DisableOrEnable == DisableOrEnableEnum.Enable;
}
}
catch
{
}
#endregion
return new ResponseCommon()
{
Code = 200,
Message = $"Success"
};
}
catch (Exception ex)
{
DbHelp.db.RollbackTran();
return new ResponseCommon()
{
Code = 300,
Message = $"操作失败:异常{ex.Message}"
};
}
}
/// <summary>
/// 发送指令获取模组的电压值
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<ResponseCommon> queryModuleVoltage(QueryModuleVoltageRequest request)
{
try
{
var modules = await DbHelp.db.Queryable<ModuleInfo>().Where(t => request.MouduleIds.Contains(t.Id)).ToListAsync();
var isSend = false;
foreach (var module in modules)
{
var shelf = ShelfManager.Shelves.Where(t => t.ShelfId == module.ShelfId).FirstOrDefault();
if (shelf != null && shelf is SmartShelf)
{
var smartShelf = (SmartShelf)shelf;
smartShelf.QueryVoltage(module.Id);
isSend = true;
}
}
if (isSend)
return new ResponseCommon()
{
Code = 200,
Message = "Success"
};
else
return new ResponseCommon()
{
Code = 201,
Message = "操作失败:未找到对应模组"
};
}
catch (Exception ex)
{
return new ResponseCommon()
{
Code = 300,
Message = "操作失败:" + ex.Message
};
}
}
/// <summary>
/// 发送指令获取模组的电压值
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<ResponseCommon> queryStoreInfoHistoryVoltage(QueryStoreInfoHistoryVoltageRequest request)
{
try
{
//获取数据
var list = await DbHelp.db.Queryable<StoreInfoHistoryVoltage>()
.Where(t => request.StoreIds.Contains(t.StoreId))
.OrderByDescending(t => t.Id)
.ToListAsync();
return new ResponseCommon()
{
Code = 200,
Message = "Success",
Data = list
};
}
catch (Exception ex)
{
return new ResponseCommon()
{
Code = 300,
Message = "操作失败:" + ex.Message
};
}
}
public async Task<ResponseCommon> calibrationSetOffset(CalibrationSetOffsetRequest request)
{
try
{
var modules = await DbHelp.db.Queryable<ModuleInfo>().Where(t => request.MouduleIds.Contains(t.Id)).ToListAsync();
var isSend = false;
foreach (var module in modules)
{
var shelf = ShelfManager.Shelves.Where(t => t.ShelfId == module.ShelfId).FirstOrDefault();
if (shelf != null && shelf is SmartShelf)
{
var smartShelf = (SmartShelf)shelf;
#region
//2024/11/11 程心怡说刘一科长喊加的
//需求来源:微信
//软件加光衰标定值,观察光衰数据
//相当于就是你那边软件要记录一下上一次标定的值
//相当于,到时候我们这边板子上完了,我会手动用你的软件标定一次,你那边就记录数据。
var time = DateTime.Now;
var historyList = new List<StoreInfoHistoryVoltage>();
var storeInfos = DbHelp.db.Queryable<StoreInfo>()
.Where(t => t.ModuleId == module.Id)
.Where(t => t.BoardId == module.BoardId)
.OrderBy(t => t.LightNumber)
.ToList();
storeInfos.ForEach(t =>
{
historyList.Add(new StoreInfoHistoryVoltage()
{
StoreId = t.Id,
StoreCode = t.StoreCode,
ShelfTypeId = t.ShelfTypeId,
ModuleId = module.Id,
ModuleCode = t.ModuleCode,
ShelfId = t.ShelfId,
ShelfCode = t.ShelfCode,
BoardId = t.BoardId,
LightNumber = t.LightNumber,
Priority = t.Priority,
CurrentMatSn = t.CurrentMatSn,
CurrentVoltage = t.CurrentVoltage,
StandardVoltage = t.StandardVoltage,
OffsetVoltage = t.OffsetVoltage,
BigShelfCode = t.BigShelfCode,
R = t.R,
C = t.C,
Wei = t.Wei,
GroupName = t.GroupName,
CreateTime = time,
});
});
DbHelp.db.Insertable(historyList).ExecuteCommand();
#endregion
smartShelf.CalibrationSetOffset(module.Id, request.OffSet);
isSend = true;
}
}
if (isSend)
{
return new ResponseCommon()
{
Code = 200,
Message = "Success"
};
}
else
{
return new ResponseCommon()
{
Code = 201,
Message = "操作失败:未找到对应模组"
};
}
}
catch (Exception ex)
{
return new ResponseCommon()
{
Code = 300,
Message = "操作失败:" + ex.Message
};
}
}
#endregion
#region
public async Task<PageQueryResponse<StoreInfo>> GetStores(GetStoresRequest request)
{
try
{
var recordsQueryable = DbHelp.db.Queryable<StoreInfo>()
.WhereIF(!string.IsNullOrEmpty(request.ShelfCode), t => t.ShelfCode.Contains(request.ShelfCode))
.WhereIF(!string.IsNullOrEmpty(request.ModuleCode), t => t.ModuleCode.Contains(request.ModuleCode))
.WhereIF(!string.IsNullOrEmpty(request.StoreCode), t => t.StoreCode.Contains(request.StoreCode))
.WhereIF(!string.IsNullOrEmpty(request.CurrentMatSN), t => t.CurrentMatSn.Contains(request.CurrentMatSN))
;
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) * request.PageSize + i + 1;
}
return new PageQueryResponse<StoreInfo>()
{
Code = 200,
Message = $"success",
Data = new PageQueryResponseData<StoreInfo>()
{
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<StoreInfo>()
{
Code = 300,
Message = $"操作失败:{ex.Message}",
};
}
}
public async Task<ResponseCommon> disableOrEnableStore(DisableOrEnableStoreRequest request)
{
//找到库位
var storeInfo = await DbHelp.db.Queryable<StoreInfo>()
.Where(t => t.Id == request.StoreId)
.FirstAsync();
//库位不存在
if (storeInfo == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"操作失败:库位{request.SroreCode}不存在!"
};
}
try
{
DbHelp.db.BeginTran();
//禁用需要删除当前库存数据
if (request.DisableOrEnable == DisableOrEnableEnum.Disable)
{
//盟讯公司发送钉钉消息
if (LocalFile.Config.IsMx)
{
var DingDing = string.Empty;
MXBackgroundThread.SendDingDingMsg($"【智能货架】库位{storeInfo.StoreCode}被屏蔽(库位管理),请及时调查或维保硬件!", new List<string> { "104379", "103595" }, ref DingDing);
Logs.Write($"【智能货架】库位{storeInfo.StoreCode}被屏蔽(库位管理),请及时调查或维保硬件!");
#region
Task.Run(() =>
{
var disabledStore = DbHelp.db.Queryable<StoreInfo>()
.Where(t => t.CurrentMatSn == "禁用")
.ToList();
var allStore = DbHelp.db.Queryable<StoreInfo>()
.ToList();
var disabledCount = disabledStore.Count();
var allCount = allStore.Count();
var disabledACount = disabledStore.Where(t => t.ShelfCode.Contains("A")).ToList().Count();
var allACount = allStore.Where(t => t.ShelfCode.Contains("A")).ToList().Count();
var disabledCCount = disabledStore.Where(t => t.ShelfCode.Contains("C")).ToList().Count();
var allCCount = allStore.Where(t => t.ShelfCode.Contains("C")).ToList().Count();
var disabledModule = DbHelp.db.Queryable<ModuleInfo>()
.Where(t => t.IsEnable == false)
.ToList();
var allModule = DbHelp.db.Queryable<ModuleInfo>()
.ToList();
var disabledModuleCount = disabledModule.Count();
var allModuleCount = allModule.Count();
var disabledAModuleCount = disabledModule.Where(t => t.ShelfCode.Contains("A")).ToList().Count();
var allAModuleCount = allModule.Where(t => t.ShelfCode.Contains("A")).ToList().Count();
var disabledCModuleCount = disabledModule.Where(t => t.ShelfCode.Contains("C")).ToList().Count();
var allCModuleCount = allModule.Where(t => t.ShelfCode.Contains("C")).ToList().Count();
var message = $"【智能货架】当前库位总数{allCount},禁用总数{disabledCount},禁用率{((double)disabledCount / allCount).ToString("P")}" +
$"其中A区库位总数{allACount},禁用数{disabledACount},禁用率{((double)disabledACount / allACount).ToString("P")}" +
$"C区库位总数{allCCount},禁用数{disabledCCount},禁用率{((double)disabledCCount / allCCount).ToString("P")}。\r\n" +
$"当前模组总数{allModuleCount},禁用总数{disabledModuleCount},禁用率{((double)disabledModuleCount / allModuleCount).ToString("P")}" +
$"其中A区模组总数{allAModuleCount},禁用数{disabledAModuleCount},禁用率{((double)disabledAModuleCount / allAModuleCount).ToString("P")}" +
$"C区模组总数{allCModuleCount},禁用数{disabledCModuleCount},禁用率{((double)disabledCModuleCount / allCModuleCount).ToString("P")}。";
Logs.Write(message);
var dd = string.Empty;
MXBackgroundThread.SendDingDingMsg(message, new List<string> { "104379", "103595" }, ref dd);
});
#endregion
}
//库位
storeInfo.CurrentMatSn = "禁用";
//库存数据处理
var inventorys = DbHelp.db.Queryable<InventoryDetail>()
.Where(t => t.StoreId == storeInfo.Id)
.ToList();
if (inventorys != null && inventorys.Count > 0)
{
//删除并进行出入库记录
foreach (var inventory in inventorys)
{
var inOutRecord = new InOutRecord()
{
StoreCode = storeInfo.StoreCode,
StoreId = storeInfo.Id,
StoreInfo = storeInfo,
R = storeInfo.R,
C = storeInfo.C,
Wei = storeInfo.Wei,
BigShelfCode = storeInfo.BigShelfCode,
GroupName = storeInfo.GroupName,
MatSN = inventory.MatSN,
MatCode = inventory.MatCode,
MatName = inventory.MatName,
MatSpec = inventory.MatSpec,
MatBatch = inventory.MatBatch,
MatQty = inventory.MatQty,
MatCustomer = inventory.MatCustomer,
MatSupplier = inventory.MatSupplier,
OperateUser = request.UserName + "(禁用库位)",
Direction = DirectionEnum.,
};
DbHelp.db.Insertable(inOutRecord).ExecuteCommand();
DbHelp.db.Deleteable(inventory).ExecuteCommand();
}
}
}
else
{
storeInfo.CurrentMatSn = string.Empty;
}
DbHelp.db.Updateable(storeInfo).ExecuteCommand();
DbHelp.db.CommitTran();
return new ResponseCommon()
{
Code = 200,
Message = $"Success"
};
}
catch (Exception ex)
{
DbHelp.db.RollbackTran();
return new ResponseCommon()
{
Code = 300,
Message = $"操作失败:异常{ex.Message}"
};
}
}
public async Task<ResponseCommon> getDisablePercent()
{
try
{
#region
var disabledStore = DbHelp.db.Queryable<StoreInfo>()
.Where(t => t.CurrentMatSn == "禁用")
.ToList();
var allStore = DbHelp.db.Queryable<StoreInfo>()
.ToList();
var disabledCount = disabledStore.Count();
var allCount = allStore.Count();
var disabledACount = disabledStore.Where(t => t.ShelfCode.Contains("A")).ToList().Count();
var allACount = allStore.Where(t => t.ShelfCode.Contains("A")).ToList().Count();
var disabledCCount = disabledStore.Where(t => t.ShelfCode.Contains("C")).ToList().Count();
var allCCount = allStore.Where(t => t.ShelfCode.Contains("C")).ToList().Count();
var disabledModule = DbHelp.db.Queryable<ModuleInfo>()
.Where(t => t.IsEnable == false)
.ToList();
var allModule = DbHelp.db.Queryable<ModuleInfo>()
.ToList();
var disabledModuleCount = disabledModule.Count();
var allModuleCount = allModule.Count();
var disabledAModuleCount = disabledModule.Where(t => t.ShelfCode.Contains("A")).ToList().Count();
var allAModuleCount = allModule.Where(t => t.ShelfCode.Contains("A")).ToList().Count();
var disabledCModuleCount = disabledModule.Where(t => t.ShelfCode.Contains("C")).ToList().Count();
var allCModuleCount = allModule.Where(t => t.ShelfCode.Contains("C")).ToList().Count();
var message = $"【智能货架】当前库位总数{allCount},禁用总数{disabledCount},禁用率{((double)disabledCount / allCount).ToString("P")}" +
$"其中A区库位总数{allACount},禁用数{disabledACount},禁用率{((double)disabledACount / allACount).ToString("P")}" +
$"C区库位总数{allCCount},禁用数{disabledCCount},禁用率{((double)disabledCCount / allCCount).ToString("P")}。\r\n" +
$"当前模组总数{allModuleCount},禁用总数{disabledModuleCount},禁用率{((double)disabledModuleCount / allModuleCount).ToString("P")}" +
$"其中A区模组总数{allAModuleCount},禁用数{disabledAModuleCount},禁用率{((double)disabledAModuleCount / allAModuleCount).ToString("P")}" +
$"C区模组总数{allCModuleCount},禁用数{disabledCModuleCount},禁用率{((double)disabledCModuleCount / allCModuleCount).ToString("P")}。";
#endregion
//非盟讯公司的展示
if (LocalFile.Config.IsMx == false)
{
message = $"【智能货架】当前库位总数{allCount},禁用总数{disabledCount},禁用率{((double)disabledCount / allCount).ToString("P")}。";
}
return new ResponseCommon()
{
Code = 200,
Message = $"Success",
Data = message,
};
}
catch (Exception ex)
{
DbHelp.db.RollbackTran();
return new ResponseCommon()
{
Code = 300,
Message = $"操作失败:异常{ex.Message}"
};
}
}
#endregion
}
}