Admin
6 小时以前 1cd9280bbecf557f8978ad3839f14827ff9f4d34
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
 *所有关于Dt_locationinfo类的业务代码应在此处编写
*可使用repository.调用常用方法,获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Dt_locationinfoService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
 
using WIDESEA.Core.BaseProvider;
using WIDESEA.Core.Extensions.AutofacManager;
using WIDESEA.Entity.DomainModels;
using System.Linq;
using WIDESEA.Core.Utilities;
using System.Linq.Expressions;
using WIDESEA.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using WIDESEA.Services.IRepositories;
using System.Threading.Tasks;
using System.Collections.Generic;
using Newtonsoft.Json;
using System;
using WIDESEA.Common.CustomModels;
using WIDESEA.Core.Enums;
using WIDESEA.Core.Services;
using WIDESEA.Common;
using WIDESEA.Services.Repositories;
using WIDESEA.Core.EFDbContext;
 
namespace WIDESEA.Services.Services
{
    public partial class Dt_locationinfoService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IDt_locationinfoRepository _repository;//访问数据库
 
        [ActivatorUtilitiesConstructor]
        public Dt_locationinfoService(
            IDt_locationinfoRepository dbRepository,
            IHttpContextAccessor httpContextAccessor
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            //多租户会用到这init代码,其他情况可以不用
            //base.Init(dbRepository);
        }
 
 
        /// <summary>
        /// 给入库请求分配货位(获取指定的层)
        /// </summary>
        /// <returns></returns>
        public WebResponseContent GetEmptyLocation(WIDESEAContext dbcontext, string desLayer)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_locationinfoRepository locationinfoRepository = new Dt_locationinfoRepository(dbcontext);
 
                List<Dt_locationinfo> locationinfos = locationinfoRepository.Find(
                    x => x.location_state == LocationState.LocationState_Empty.ToString() &&
                    x.location_islocked == false && x.location_layer == int.Parse(desLayer))
                    .OrderBy(x => x.location_column)
                    .ToList();
 
                if (locationinfos.Count() > 0)
                {
                    return content.OK(data: locationinfos[0]);
                }
                else
                {
                    content.Error("暂无货位可分配");
                }
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
 
            return content;
        }
 
 
        /// <summary>
        /// 锁定或者取消锁定货位
        /// </summary>
        /// <param name="locationId">货位Id</param>
        /// <param name="lockFlag">是否锁定</param>
        /// <returns></returns>
        public WebResponseContent DoLocationLockOperate(SaveModel saveModel)
        {
            WebResponseContent responseContent = repository.DbContextBeginTransaction(() =>
            {
                WebResponseContent content = new WebResponseContent();
                try
                {
                    List<Dt_locationinfo> locationinfos = new List<Dt_locationinfo>();
                    for (int i = 0; i < saveModel.DelKeys.Count(); i++)
                    {
 
                        Dt_locationinfo locationinfo = new Dt_locationinfo();
                        Guid id = new Guid(saveModel.DelKeys[i].ToString());
                        locationinfo = repository.FindFirst(a => a.location_pkid == id);
                        locationinfo.location_islocked = Convert.ToBoolean(saveModel.Extra);
                        locationinfos.Add(locationinfo);
                    }
                    Expression<Func<Dt_locationinfo, object>> expression;
                    expression = a => a.location_islocked;
                    content = repository.UpdateRange(locationinfos, expression, true) > 0 ? content.OK() : content.Error("修改失败");
                    Logger.Info(LoggerType.EditUserInfo, saveModel.ToString(), content.ToString(), "解锁成功");
                }
                catch (Exception ex)
                {
                    content.Status = false;
                    content.Message = ex.Message;
                    Logger.Info(LoggerType.EditUserInfo, saveModel.ToString(), content.ToString(), "解锁失败");
                }
                return content;
            });
            return responseContent;
        }
 
 
        public override PageGridData<Dt_locationinfo> GetPageData(PageDataOptions options)
        {
 
 
            PageGridData<Dt_locationinfo> queryData = new PageGridData<Dt_locationinfo>();
            List<SearchParameters> searchParametersList = new List<SearchParameters>();
            int[] col = {  };
            if (!string.IsNullOrEmpty(options.Wheres))
            {
                try
                {
                    searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
                    List<Dt_locationinfo> listLocation = repository.Find(r => !(r.location_line == 1 && (col.Contains(r.location_column))));
                    //int[] rightCol = { 48, 49 };
                    int[] rightCol = { 50, 51 };
                    listLocation= listLocation.FindAll(r => !(r.location_line == 2 && (rightCol.Contains(r.location_column))));
                    if (searchParametersList.Count > 0)
                    {
                        SearchParameters searchParameters = searchParametersList.Find(r => r.Name == "location_id");
                        if (null != searchParameters)
                            listLocation = listLocation.FindAll(r => r.location_id.Contains(searchParameters.Value));
 
                        searchParameters = searchParametersList.Find(r => r.Name == "location_state");
                        if (null != searchParameters)
                            listLocation = listLocation.FindAll(r => r.location_state.Contains(searchParameters.Value));
 
                        searchParameters = searchParametersList.Find(r => r.Name == "location_islocked");
                        if (null != searchParameters)
                            listLocation = listLocation.FindAll(r => r.location_islocked == bool.Parse(searchParameters.Value));
 
                        searchParameters = searchParametersList.Find(r => r.Name == "location_line");
                        if (null != searchParameters)
                            listLocation = listLocation.FindAll(r => r.location_line == int.Parse(searchParameters.Value));
 
                        searchParameters = searchParametersList.Find(r => r.Name == "location_column");
                        if (null != searchParameters)
                            listLocation = listLocation.FindAll(r => r.location_column == int.Parse(searchParameters.Value));
 
                        searchParameters = searchParametersList.Find(r => r.Name == "location_layer");
                        if (null != searchParameters)
                            listLocation = listLocation.FindAll(r => r.location_layer == int.Parse(searchParameters.Value));
                    }
                    IQueryable<Dt_locationinfo> queryable = listLocation.FindAll(r => true).AsQueryable();
 
                    string sort = string.IsNullOrEmpty(options.Sort) ? "location_id" : options.Sort;
                    string order = options.Order;
                    IOrderedQueryable<Dt_locationinfo> queryableOrderBy = null;
                    //    Dictionary<string, QueryOrderBy> orderBySelector = new Dictionary<string, QueryOrderBy>() {{
                    //    options.Sort, options.Order?.ToLower() == "asc"? QueryOrderBy.Asc: QueryOrderBy.Desc
                    //} };
                    queryableOrderBy = options.Order?.ToLower() == "desc" ? queryable.OrderByDescending(sort.GetExpression<Dt_locationinfo>()) :
                         queryable.OrderBy(sort.GetExpression<Dt_locationinfo>());
 
                    queryData.total = listLocation.Count;
                    queryData.rows = queryableOrderBy.Skip((options.Page - 1) * options.Rows).Take(options.Rows).ToList();
                }
                catch
                {
 
 
                }
            }
            return queryData;
        }
    }
}