| | |
| | | /// </summary> |
| | | private bool InsertBarcode(BarcodeInformation entity) |
| | | { |
| | | // 检查条码是否已存在 |
| | | if (IsBarcodeExists(entity)) |
| | | { |
| | | throw new InvalidOperationException($"条码已存在,无法重复插入:SmallBarcode={entity.SmallBarcode}, OuterBarcode={entity.OuterBarcode}"); |
| | | } |
| | | |
| | | var isInsertSuccess = base.Insert(entity); |
| | | return isInsertSuccess ? true : throw new NotImplementedException("条码新增失败:数据库插入操作未执行成功"); |
| | | } |
| | |
| | | /// </summary> |
| | | private bool InsertBarcodeBatch(List<BarcodeInformation> entityList) |
| | | { |
| | | // 检查批量条码中是否有重复 |
| | | var duplicateBarcodes = new List<string>(); |
| | | foreach (var entity in entityList) |
| | | { |
| | | if (IsBarcodeExists(entity)) |
| | | { |
| | | duplicateBarcodes.Add($"SmallBarcode={entity.SmallBarcode}, OuterBarcode={entity.OuterBarcode}"); |
| | | } |
| | | } |
| | | |
| | | if (duplicateBarcodes.Any()) |
| | | { |
| | | throw new InvalidOperationException($"发现重复条码,无法批量插入:{string.Join("; ", duplicateBarcodes)}"); |
| | | } |
| | | |
| | | var isBatchInsertSuccess = base.InsertRange(entityList); |
| | | return isBatchInsertSuccess ? true : throw new NotImplementedException($"批量条码新增失败:共{entityList.Count}条记录"); |
| | | } |
| | |
| | | return deleteRowCount > 0 ? true : throw new NotImplementedException($"批量条码删除失败:共{ids.Length}个Id"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检查条码是否已存在 |
| | | /// </summary> |
| | | /// <param name="entity">条码实体</param> |
| | | /// <returns>true=已存在,false=不存在</returns> |
| | | private bool IsBarcodeExists(BarcodeInformation entity) |
| | | { |
| | | // 根据SmallBarcode或OuterBarcode检查是否存在重复条码 |
| | | return Db.Queryable<BarcodeInformation>() |
| | | .Any(x => (!string.IsNullOrEmpty(entity.SmallBarcode) && x.SmallBarcode == entity.SmallBarcode) || |
| | | (!string.IsNullOrEmpty(entity.OuterBarcode) && x.OuterBarcode == entity.OuterBarcode)); |
| | | } |
| | | |
| | | #endregion |
| | | } |