| | |
| | | var entity = input.Adapt<WmsConfigDeviceWarning>(); |
| | | |
| | | //重复性验证 |
| | | await CheckExist(entity,true); |
| | | await CheckExist(entity, true); |
| | | |
| | | await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); |
| | | } |
| | |
| | | |
| | | |
| | | #region 导入 |
| | | |
| | | |
| | | /// <summary> |
| | | /// Excel模板导入配置设备报警功能 |
| | | /// </summary> |
| | |
| | | [ApiDescriptionSettings(Name = "ImportExcel")] |
| | | [Description("WmsConfigDeviceWarning/ImportExcel")] |
| | | public async Task<int> ImportExcelAsync(IFormFile file) |
| | | { |
| | | { |
| | | int _HeadStartLine = 2;//第1行是说明,第2行是列名 |
| | | int _DataStartLine = 3;//第3行开始是数据 |
| | | DataTable importDataTable = ExcelUtil.ImportExcelToDataTable(file, _HeadStartLine, _DataStartLine); |
| | | var addList =await CommonImport(importDataTable, _DataStartLine); |
| | | var addList = await CommonImport(importDataTable, _DataStartLine); |
| | | await _rep.InsertRangeAsync(addList); |
| | | return addList.Count; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// DataTable转换实体对象列表 |
| | | /// </summary> |
| | |
| | | { |
| | | var details = new List<WmsConfigDeviceWarning>(); |
| | | int index = dataStartLine;//模版列名开始行 |
| | | decimal offset = 0.0M; |
| | | decimal intValue = 0.0M; |
| | | string my_DeviceAreaCode = ""; |
| | | foreach (System.Data.DataRow row in dataTable.Rows) |
| | | { |
| | | index++; |
| | | //导入模版定制化代码(替换模版使用) |
| | | |
| | | var addItem = new WmsConfigDeviceWarning(); |
| | | #region 定义变量 |
| | | var _DeviceAreaCode = "";//设备区域 |
| | | var _DeviceWarningType = "";//报警类型 |
| | | var _WarningCode = "";//报警代码 |
| | | var _WarningContent = "";//报警内容 |
| | | #endregion |
| | | |
| | | |
| | | #region 取值 |
| | | _DeviceAreaCode = row["设备区域"]?.ToString() ; |
| | | _DeviceWarningType = row["报警类型"]?.ToString() ; |
| | | _WarningCode = row["报警代码"]?.ToString() ; |
| | | _WarningContent = row["报警内容"]?.ToString() ; |
| | | #endregion |
| | | |
| | | |
| | | #region 验证 |
| | | |
| | | if (string.IsNullOrEmpty(_DeviceAreaCode)) |
| | | { |
| | | throw Oops.Oh($"第{index}行[设备区域]{_DeviceAreaCode}不能为空!"); |
| | | } |
| | | |
| | | if(!string.IsNullOrEmpty(_DeviceAreaCode)) |
| | | { |
| | | Admin.NET.Application.DeviceAreaCodeEnum enumDeviceAreaCode = default(Admin.NET.Application.DeviceAreaCodeEnum); |
| | | |
| | | if(!Enum.TryParse<Admin.NET.Application.DeviceAreaCodeEnum>(_DeviceAreaCode, out enumDeviceAreaCode)&&!string.IsNullOrEmpty(_DeviceAreaCode)) |
| | | { |
| | | throw Oops.Oh($"第{index}行[设备区域]{_DeviceAreaCode}值不正确!"); |
| | | } |
| | | else |
| | | { |
| | | addItem.DeviceAreaCode = enumDeviceAreaCode; |
| | | } |
| | | |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(_DeviceWarningType)) |
| | | { |
| | | throw Oops.Oh($"第{index}行[报警类型]{_DeviceWarningType}不能为空!"); |
| | | } |
| | | |
| | | if(!string.IsNullOrEmpty(_DeviceWarningType)) |
| | | { |
| | | Admin.NET.Application.DeviceWarningTypeEnum enumDeviceWarningType = default(Admin.NET.Application.DeviceWarningTypeEnum); |
| | | |
| | | if(!Enum.TryParse<Admin.NET.Application.DeviceWarningTypeEnum>(_DeviceWarningType, out enumDeviceWarningType)&&!string.IsNullOrEmpty(_DeviceWarningType)) |
| | | { |
| | | throw Oops.Oh($"第{index}行[报警类型]{_DeviceWarningType}值不正确!"); |
| | | } |
| | | else |
| | | { |
| | | addItem.DeviceWarningType = enumDeviceWarningType; |
| | | } |
| | | |
| | | } |
| | | if(!string.IsNullOrEmpty(_WarningCode)) |
| | | { |
| | | addItem.WarningCode = (string)(_WarningCode.Trim()); |
| | | } |
| | | if(!string.IsNullOrEmpty(_WarningContent)) |
| | | { |
| | | addItem.WarningContent = (string)(_WarningContent.Trim()); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | var addItem = new WmsConfigDeviceWarning(); |
| | | #region 定义变量 |
| | | var _DeviceAreaCode = "";//设备区域 |
| | | var _DeviceWarningType = "";//报警类型 |
| | | var _WarningCode = "";//报警代码 |
| | | var _WarningContent = "";//报警内容 |
| | | #endregion |
| | | |
| | | |
| | | #region 取值 |
| | | _DeviceAreaCode = row["设备区域"]?.ToString(); |
| | | _DeviceWarningType = row["报警类型"]?.ToString(); |
| | | _WarningCode = row["报警代码"]?.ToString(); |
| | | _WarningContent = row["报警内容"]?.ToString(); |
| | | #endregion |
| | | |
| | | if (!string.IsNullOrEmpty(my_DeviceAreaCode) && _DeviceAreaCode != my_DeviceAreaCode) |
| | | { |
| | | throw Oops.Oh($"第{index}行一次只能导入一个设备区域!"); |
| | | } |
| | | my_DeviceAreaCode = _DeviceAreaCode; |
| | | |
| | | #region 验证 |
| | | |
| | | if (string.IsNullOrEmpty(_DeviceAreaCode)) |
| | | { |
| | | throw Oops.Oh($"第{index}行[设备区域]{_DeviceAreaCode}不能为空!"); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(_DeviceAreaCode)) |
| | | { |
| | | Admin.NET.Application.DeviceAreaCodeEnum enumDeviceAreaCode = default(Admin.NET.Application.DeviceAreaCodeEnum); |
| | | |
| | | if (!Enum.TryParse<Admin.NET.Application.DeviceAreaCodeEnum>(_DeviceAreaCode, out enumDeviceAreaCode) && !string.IsNullOrEmpty(_DeviceAreaCode)) |
| | | { |
| | | throw Oops.Oh($"第{index}行[设备区域]{_DeviceAreaCode}值不正确!"); |
| | | } |
| | | else |
| | | { |
| | | addItem.DeviceAreaCode = enumDeviceAreaCode; |
| | | } |
| | | |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(_DeviceWarningType)) |
| | | { |
| | | throw Oops.Oh($"第{index}行[报警类型]{_DeviceWarningType}不能为空!"); |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(_DeviceWarningType)) |
| | | { |
| | | Admin.NET.Application.DeviceWarningTypeEnum enumDeviceWarningType = default(Admin.NET.Application.DeviceWarningTypeEnum); |
| | | |
| | | if (!Enum.TryParse<Admin.NET.Application.DeviceWarningTypeEnum>(_DeviceWarningType, out enumDeviceWarningType) && !string.IsNullOrEmpty(_DeviceWarningType)) |
| | | { |
| | | throw Oops.Oh($"第{index}行[报警类型]{_DeviceWarningType}值不正确!"); |
| | | } |
| | | else |
| | | { |
| | | addItem.DeviceWarningType = enumDeviceWarningType; |
| | | } |
| | | |
| | | } |
| | | |
| | | if (!string.IsNullOrEmpty(_WarningContent)) |
| | | { |
| | | addItem.WarningContent = (string)(_WarningContent.Trim()); |
| | | } |
| | | #endregion |
| | | |
| | | addItem.WarningCode = SysHelper.GetDBForDeviceWarning(_DeviceAreaCode) + "|" + intValue.ToString("0.0"); |
| | | |
| | | if (offset == 0.7M) |
| | | { |
| | | offset = 0.0M; |
| | | intValue += 0.3M; |
| | | } |
| | | else |
| | | { |
| | | offset += 0.1M; |
| | | intValue += 0.1M; |
| | | } |
| | | |
| | | |
| | | details.Add(addItem); |
| | | } |
| | |
| | | await CheckExisitForImport(details); |
| | | return details; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 根据版本下载配置设备报警的Excel导入模板 |
| | | /// </summary> |
| | |
| | | var fileName = HttpUtility.UrlEncode($"导入模板(配置设备报警).xlsx", Encoding.GetEncoding("UTF-8")); |
| | | return new FileStreamResult(new FileStream(_path, FileMode.Open), "application/octet-stream") { FileDownloadName = fileName }; |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region 私有方法 |
| | |
| | | .WhereIF(!string.IsNullOrWhiteSpace(input.WarningCode), u => u.WarningCode.Contains(input.WarningCode.Trim())) |
| | | .WhereIF(!string.IsNullOrWhiteSpace(input.WarningContent), u => u.WarningContent.Contains(input.WarningContent.Trim())) |
| | | .Select<WmsConfigDeviceWarningOutput>(); |
| | | if(input.CreateTimeRange != null && input.CreateTimeRange.Count >0) |
| | | if (input.CreateTimeRange != null && input.CreateTimeRange.Count > 0) |
| | | { |
| | | DateTime? start= input.CreateTimeRange[0].Value; |
| | | DateTime? start = input.CreateTimeRange[0].Value; |
| | | query = query.WhereIF(start.HasValue, u => u.CreateTime >= start); |
| | | if (input.CreateTimeRange.Count >1 && input.CreateTimeRange[1].HasValue) |
| | | if (input.CreateTimeRange.Count > 1 && input.CreateTimeRange[1].HasValue) |
| | | { |
| | | var end = input.CreateTimeRange[1].Value; |
| | | query = query.Where(u => u.CreateTime <= end); |
| | | } |
| | | } |
| | | return query; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 重复性验证 |
| | | /// </summary> |
| | | /// <param name="input">验证对象</param> |
| | | /// <param name="isEdit">是否是编辑</param> |
| | | /// <returns></returns> |
| | | private async Task CheckExist( WmsConfigDeviceWarning input,bool isEdit=false) |
| | | { |
| | | |
| | | |
| | | |
| | | //没有配置组合校验,不需要验重 |
| | | |
| | | |
| | | bool isExistForSingle_WarningCode = false; |
| | | if (!isEdit)//新增 |
| | | { |
| | | //数据是否单独存在重复-报警代码 |
| | | isExistForSingle_WarningCode = await _rep.AsQueryable().AnyAsync(u => |
| | | u.WarningCode.Equals(input.WarningCode)); |
| | | } |
| | | else//编辑 |
| | | { |
| | | //当前编辑数据以外是否单独存在重复-报警代码 |
| | | isExistForSingle_WarningCode = await _rep.AsQueryable().AnyAsync(u => |
| | | u.Id != input.Id |
| | | && u.WarningCode.Equals(input.WarningCode)); |
| | | } |
| | | if (isExistForSingle_WarningCode) throw Oops.Oh($"验证失败,报警代码[" + input.WarningCode + "]已存在"); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据组合校验和单独校验验证数据是否已存在-导入时验证 |
| | | /// </summary> |
| | | /// <param name="inputs"></param> |
| | | /// <returns></returns> |
| | | private async Task CheckExisitForImport(List<WmsConfigDeviceWarning> inputs) |
| | | { |
| | | if (inputs?.Count <= 0) |
| | | { |
| | | throw Oops.Oh($"导入数据不能为空"); |
| | | } |
| | | //根据组合校验验证表格中中是否已存在相同数据 |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //根据单独校验验证表格中中是否已存在相同数据 |
| | | var existExcelItemForSingle_WarningCode = inputs.GroupBy(g => new { g.WarningCode}).Where(g => g.Count() > 1).ToList(); |
| | | if(existExcelItemForSingle_WarningCode != null && existExcelItemForSingle_WarningCode.Count > 0){ |
| | | var item= existExcelItemForSingle_WarningCode.First().ToList().First(); |
| | | throw Oops.Oh($"验证失败,导入的表格中,报警代码[" + item.WarningCode + "]已重复存在"); |
| | | } |
| | | |
| | | //根据单独校验验证数据库中是否已存在相同数据 |
| | | var existDBItemList = await _rep.GetListAsync(w=> |
| | | inputs.Select(s=>s.WarningCode).ToList().Contains(w.WarningCode) |
| | | ); |
| | | var db_ForSingle_WarningCode = existDBItemList.FirstOrDefault(g => inputs.Select(s=>s.WarningCode).ToList().Contains(g.WarningCode)); |
| | | if(db_ForSingle_WarningCode != null) throw Oops.Oh($"验证失败,系统中,报警代码[" + db_ForSingle_WarningCode.WarningCode + "]已重复存在"); |
| | | |
| | | |
| | | |
| | | } |
| | | #endregion |
| | | return query; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 重复性验证 |
| | | /// </summary> |
| | | /// <param name="input">验证对象</param> |
| | | /// <param name="isEdit">是否是编辑</param> |
| | | /// <returns></returns> |
| | | private async Task CheckExist(WmsConfigDeviceWarning input, bool isEdit = false) |
| | | { |
| | | |
| | | |
| | | |
| | | //没有配置组合校验,不需要验重 |
| | | |
| | | |
| | | bool isExistForSingle_WarningCode = false; |
| | | if (!isEdit)//新增 |
| | | { |
| | | //数据是否单独存在重复-报警代码 |
| | | isExistForSingle_WarningCode = await _rep.AsQueryable().AnyAsync(u => |
| | | u.WarningCode.Equals(input.WarningCode)); |
| | | } |
| | | else//编辑 |
| | | { |
| | | //当前编辑数据以外是否单独存在重复-报警代码 |
| | | isExistForSingle_WarningCode = await _rep.AsQueryable().AnyAsync(u => |
| | | u.Id != input.Id |
| | | && u.WarningCode.Equals(input.WarningCode)); |
| | | } |
| | | if (isExistForSingle_WarningCode) throw Oops.Oh($"验证失败,报警代码[" + input.WarningCode + "]已存在"); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据组合校验和单独校验验证数据是否已存在-导入时验证 |
| | | /// </summary> |
| | | /// <param name="inputs"></param> |
| | | /// <returns></returns> |
| | | private async Task CheckExisitForImport(List<WmsConfigDeviceWarning> inputs) |
| | | { |
| | | if (inputs?.Count <= 0) |
| | | { |
| | | throw Oops.Oh($"导入数据不能为空"); |
| | | } |
| | | //根据组合校验验证表格中中是否已存在相同数据 |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | //根据单独校验验证表格中中是否已存在相同数据 |
| | | var existExcelItemForSingle_WarningCode = inputs.GroupBy(g => new { g.WarningCode }).Where(g => g.Count() > 1).ToList(); |
| | | if (existExcelItemForSingle_WarningCode != null && existExcelItemForSingle_WarningCode.Count > 0) |
| | | { |
| | | var item = existExcelItemForSingle_WarningCode.First().ToList().First(); |
| | | throw Oops.Oh($"验证失败,导入的表格中,报警代码[" + item.WarningCode + "]已重复存在"); |
| | | } |
| | | |
| | | //根据单独校验验证数据库中是否已存在相同数据 |
| | | var existDBItemList = await _rep.GetListAsync(w => |
| | | inputs.Select(s => s.WarningCode).ToList().Contains(w.WarningCode) |
| | | ); |
| | | var db_ForSingle_WarningCode = existDBItemList.FirstOrDefault(g => inputs.Select(s => s.WarningCode).ToList().Contains(g.WarningCode)); |
| | | if (db_ForSingle_WarningCode != null) throw Oops.Oh($"验证失败,系统中,报警代码[" + db_ForSingle_WarningCode.WarningCode + "]已重复存在"); |
| | | |
| | | |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | } |
| | | |