pan
2025-11-15 4476740c214edb7ab667c48fcab00488fbdd9879
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_IBasicService;
using WIDESEA_Model.Models;
using WIDESEA_Core.Helper;
using WIDESEA_Common.CommonEnum;
using WIDESEA_Core.Caches;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Model.Models.Basic;
using WIDESEA_DTO.Basic;
 
namespace WIDESEA_BasicService
{
    public partial class WarehouseService : ServiceBase<Dt_Warehouse, IRepository<Dt_Warehouse>>, IWarehouseService
    {
        private readonly ICacheService _cacheService;
        private readonly IRepository<Dt_WarehouseArea> _warehouseArearepository;
        public WarehouseService(IRepository<Dt_Warehouse> BaseDal, ICacheService cacheService, IRepository<Dt_WarehouseArea> warehouseArearepository) : base(BaseDal)
        {
            _cacheService = cacheService;
            _warehouseArearepository = warehouseArearepository;
        }
 
        public IRepository<Dt_Warehouse> Repository => BaseDal;
 
        /// <summary>
        /// 批量启用仓库
        /// </summary>
        /// <param name="keys">仓库主键数组</param>
        /// <returns></returns>
        public WebResponseContent WarehouseEnableStatus(int[] keys)
        {
            List<Dt_Warehouse> warehouses = Repository.QueryData(x => keys.Contains(x.WarehouseId));
            warehouses.ForEach(x =>
            {
                x.WarehouseStatus = EnableEnum.Enable.ObjToInt();
            });
            Repository.UpdateData(warehouses);
 
            return WebResponseContent.Instance.OK();
        }
 
        /// <summary>
        /// 批量禁用仓库
        /// </summary>
        /// <param name="keys">仓库主键数组</param>
        /// <returns></returns>
        public WebResponseContent WarehouseDisableStatus(int[] keys)
        {
            List<Dt_Warehouse> warehouses = Repository.QueryData(x => keys.Contains(x.WarehouseId));
            warehouses.ForEach(x =>
            {
                x.WarehouseStatus = EnableEnum.Disable.ObjToInt();
            });
            Repository.UpdateData(warehouses);
 
            return WebResponseContent.Instance.OK();
        }
 
        /// <summary>
        /// 单个启用仓库
        /// </summary>
        /// <param name="key">仓库主键</param>
        /// <returns></returns>
        public WebResponseContent WarehouseEnableStatus(int key)
        {
            return WarehouseEnableStatus(new int[] { key });
        }
 
        /// <summary>
        /// 单个禁用仓库
        /// </summary>
        /// <param name="key">仓库主键</param>
        /// <returns></returns>
        public WebResponseContent WarehouseDisableStatus(int key)
        {
            return WarehouseDisableStatus(new int[] { key });
        }
 
        public async Task<WebResponseContent> ReceiveWarehouseArea(List<WarehouseAreaDto> models)
        {
 
            var lists = _warehouseArearepository.Db.Queryable<Dt_WarehouseArea>().ToList();
            foreach (var item in models)
            {
                if (item.IsDelete == 1)
                {
                  var first=  _warehouseArearepository.Db.Queryable<Dt_WarehouseArea>().First(x => x.Code == item.Code);
                    if(first != null)
                    {
                        _warehouseArearepository.DeleteData(first);
                    }
                }
                else
                {
                    var dbfirst = lists.FirstOrDefault(x => x.Code == item.Code);
                    if (dbfirst != null)
                    {
                        dbfirst.Code = item.Code;
                        dbfirst.Name = item.Name;
                        dbfirst.FactoryArea = item.FactoryArea;
                        _warehouseArearepository.UpdateData(dbfirst);
                    }
                    else
                    {
                        _warehouseArearepository.AddData(new Dt_WarehouseArea { Code = item.Code, Name = item.Name, FactoryArea = item.FactoryArea });
                    }
                }
            }
            return WebResponseContent.Instance.OK();
 
        }
    }
 
}