xiazhengtongxue
2026-04-07 b0b5deb5825684bca5b3fa7c2ab59f60ce0e799f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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;
 
namespace WIDESEA_StockService
{
    public partial class StockInfoService : ServiceBase<Dt_StockInfo, IRepository<Dt_StockInfo>>, IStockInfoService
    {
        private readonly IMapper _mapper;
 
        public IRepository<Dt_StockInfo> Repository => BaseDal;
 
        public StockInfoService(IRepository<Dt_StockInfo> BaseDal, IMapper mapper) : base(BaseDal)
        {
            _mapper = mapper;
        }
 
        /*public WebResponseContent AddStockInfo(string PalletCode, int PalletType, int WarehouseId)
        {
            WebResponseContent webResponse=new WebResponseContent();
            try
            {
                Dt_StockInfo dt_StockInfo = new Dt_StockInfo();
                dt_StockInfo.PalletCode = PalletCode;
                dt_StockInfo.PalletType = PalletType;
                dt_StockInfo.WarehouseId = WarehouseId;
                dt_StockInfo.StockStatus = (int)StockStatusEmun.入库中;
                dt_StockInfo.Creater = "MWS";
                dt_StockInfo.CreateDate = DateTime.Now;
                BaseDal.AddData(dt_StockInfo);
                return webResponse.OK();
            }
            catch (Exception ex)
            {
                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();
        }
    }
}