schangxiang@126.com
2025-09-17 ab9d9126ced7d6dac0e14c3ede5a49fdb7fc94df
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
using iWareCommon.Common.EnumType;
using iWareCommon.Common.Service;
using iWareCommon.Utils;
using iWareDataCore.BASE.Dao;
using iWareDataCore.BASE.Entity;
using iWareDataCore.BASE.EnumType;
using iWareDataCore.ORM;
using iWareDataCore.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareDataCore.BASE.Service
{
    public class PlaceService : CommonService<PlaceEntity, BASEPlace, DbModelCore>
    {
        private static object Lock = new object();
        private PlaceService() : base(PlaceDao.GetInstance()) { }
 
        private static PlaceService Instance = null;
 
        /// <summary>
        /// 获取单例的方法
        /// </summary>
        /// <returns>角色服务的单例实体</returns>
        public static PlaceService GetInstance()
        {
 
            if (Instance == null)
            {
                lock (Lock)
                {
                    if (Instance == null)
                    {
                        Instance = new PlaceService();
                    }
                }
            }
            return Instance;
        }
 
        /// <summary>
        /// 获取指定字符串开头的库位列表
        /// </summary>
        /// <param name="term">指定字符串</param>
        /// <param name="size">返回的最大条数</param>
        /// <param name="msg">异常错误消息</param>
        /// <returns>订单号列表</returns>
        public List<string> GetCodes(string term, int size, out string msg)
        {
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    msg = "";
                    if (string.IsNullOrEmpty(term)) { return new List<string>(); }
                    var places = dbModel.BASEPlaces.Select(x => new { x.id, x.code }).OrderBy(x => x.code).Where(x => x.code.StartsWith(term)).Skip(0).Take(size).ToList();
                    return places.Select(x => x.code).Distinct().ToList();
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetCodes", ex.Message);
                    return new List<string>();
                }
            }
        }
 
       /// <summary>
       /// 获取空库位和出入库口
       /// </summary>
       /// <returns></returns>
        public List<PlaceViewEntity> GetEmptyAndInOutGate()
        {
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    List<PlaceViewEntity> placelst = new List<PlaceViewEntity>();
                    var places = dbModel.BASEPlaceViews.Where(x => x.placetypename == "gate11" || x.placetypename == "gate22" || x.placetypename == EPlaceType.普通库位.ToString() && x.status == 0 && x.placetypename != EPlaceType.不合格缓存位.ToString()).ToList();
                    places.ForEach(x =>{
                      placelst.Add(new PlaceViewEntity(x));
                    });
                  return placelst;
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetEmptyAndInOutGate", ex.Message);
                    return new List<PlaceViewEntity>();
                }
            }
        }
 
        /// <summary>
        /// 库位状态重置
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public  int PlaceReset(List<int> ids, out string msg)
        {
            msg = "";
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    var placelst = dbModel.BASEPlaces.Where(x => ids.Contains(x.id)).ToList();
                    placelst.ForEach(x =>
                    {
                        x.status=(int)EPlaceStatus.空库位;
                        x.islock = (int)EYesOrNo.否;
                        x.isexecute = (int)EYesOrNo.否;
                    });
                   return dbModel.SaveChanges();
                }
                catch (Exception ex)
                {
                    msg = "更新失败";
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "PlaceReset", ex.Message);
                    return 0;
                }
            }
        }
        /// <summary>
        /// 库位解锁
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public int PlaceUnLock(List<int> ids, out string msg)
        {
            msg = "";
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    var placelst = dbModel.BASEPlaces.Where(x => ids.Contains(x.id)).ToList();
                    placelst.ForEach(x =>
                    {
                        x.islock = (int)EYesOrNo.否;
                        x.isexecute = (int)EYesOrNo.否;
                    });
                   return dbModel.SaveChanges();
                }
                catch (Exception ex)
                {
                    msg = "更新失败";
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "PlaceReset", ex.Message);
                    return 0;
                }
            }
        }
 
        /// <summary>
        /// 库位锁定
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public int PlaceLock(List<int> ids, out string msg)
        {
            msg = "";
            using (var dbModel = new DbModelCore())
            {
                try
                {
                    var placelst = dbModel.BASEPlaces.Where(x => ids.Contains(x.id)).ToList();
                    placelst.ForEach(x =>
                    {
                        x.islock = (int)EYesOrNo.是;
                    });
                    return dbModel.SaveChanges();
                }
                catch (Exception ex)
                {
                    msg = "更新失败";
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "库位锁定", ex.Message);
                    return 0;
                }
            }
        }
    }
}