1
xiazhengtongxue
2026-02-07 4f2fb79143f0545e96f114c92e1da733b2d9716a
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs
@@ -1,8 +1,13 @@
using AutoMapper;
using Org.BouncyCastle.Crypto;
using SqlSugar;
using StackExchange.Profiling.Internal;
using WIDESEA_Common.Log;
using WIDESEA_Common.StockEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Utilities;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
@@ -39,5 +44,62 @@
                return webResponse.Error($"库存添加错误:原因:{ex.Message}");
            }
        }*/
        public virtual WebResponseContent DeleteData(object[] keys)
        {
            List<Dt_StockInfo> stodata = new List<Dt_StockInfo>();
            try
            {
                if (typeof(Dt_StockInfo).GetNavigatePro() == null)
                    return BaseDal.DeleteDataByIds(keys) ? WebResponseContent.Instance.OK() : WebResponseContent.Instance.Error();
                else
                {
                    if (keys != null)
                    {
                        Type detailType = typeof(Dt_StockInfo).GetDetailType();
                        string name = typeof(Dt_StockInfo).GetMainIdByDetail();
                        List<object> dynamicDelKeys = new List<object>();
                        for (int i = 0; i < keys.Length; i++)
                        {
                            dynamicDelKeys.Add(keys[i]);
                        }
                        ((SqlSugarClient)BaseDal.Db).BeginTran();
                        foreach (var key in keys)
                        {
                            int idt = int.Parse(key.ToString());
                            stodata.Add(BaseDal.QueryData(x => x.Id == idt).FirstOrDefault());
                        }
                        if (dynamicDelKeys.Count > 0)
                            WriteLog.Write_Log("WMS_删除库存", $"删除信息", "成功", $"参数:{stodata.ToJson()}");
                            BaseDal.Db.Deleteable<object>().AS(detailType.Name).Where($"{name} in (@id)", new { id = dynamicDelKeys.ToArray() }).ExecuteCommandHasChange();
                        BaseDal.DeleteDataByIds(keys);
                        ((SqlSugarClient)BaseDal.Db).CommitTran();
                        return WebResponseContent.Instance.OK();
                    }
                    else
                    {
                        return WebResponseContent.Instance.Error("参数错误");
                    }
                }
            }
            catch (Exception ex)
            {
                ((SqlSugarClient)BaseDal.Db).RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        public bool IsContainerNoExist(string containerNo)
        {
            // ç›´æŽ¥åˆ¤æ–­æ˜¯å¦å­˜åœ¨æ»¡è¶³æ¡ä»¶çš„记录
            return BaseDal.QueryData(x => x.PalletCode == containerNo).Any();
        }
    }
}