wankeda
2025-03-13 a6a33f6916afbf1fc629baecb772939cda2ee981
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
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Basic;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_Model.Models;
 
namespace WIDESEA_BasicService
{
    public partial class CachePointService : ServiceBase<Dt_CachePoint, ICachePointRepository>, ICachePointService
    {
 
        private readonly Dictionary<string, OrderByType> _emptyAssignOrderBy = new()
        {
            { nameof(Dt_CachePoint.Depth), OrderByType.Desc },
            { nameof(Dt_CachePoint.Column), OrderByType.Asc },
            { nameof(Dt_CachePoint.Row), OrderByType.Asc },
        };
 
        public Dt_CachePoint? AssignCachePoint(int areaId)
        {
            List<CachePointGroupDTO> cachePointGroups = Repository.GetCachePointGroups(areaId, LocationStatusEnum.InStock, LocationStatusEnum.Free);
            if (cachePointGroups != null && cachePointGroups.Count > 0)
            {
                CachePointGroupDTO? pointGroupDTO = cachePointGroups.FirstOrDefault(x => x.EnableStatusB == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatusB == EnableStatusEnum.Normal.ObjToInt());
                int id = pointGroupDTO?.IdB ?? 0;
                return BaseDal.QueryFirst(x => x.Id == id);
            }
            cachePointGroups = Repository.GetCachePointGroups(areaId, LocationStatusEnum.Free, LocationStatusEnum.Free);
            if (cachePointGroups != null && cachePointGroups.Count > 0)
            {
                CachePointGroupDTO? pointGroupDTO = cachePointGroups.FirstOrDefault(x => x.EnableStatusA == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatusA == EnableStatusEnum.Normal.ObjToInt());
                int id = pointGroupDTO?.IdA ?? 0;
                return BaseDal.QueryFirst(x => x.Id == id);
            }
 
            return BaseDal.QueryFirst(x => x.PointStatus == LocationStatusEnum.Free.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt() && x.AreaId == areaId), _emptyAssignOrderBy);
        }
 
        public Dt_CachePoint? EmptyCachePoint(string toaddress)
        {
            List<Dt_CachePoint> cachePoints = BaseDal.QueryData(x => x.PointName.Contains(toaddress) && x.EnableStatus == 0 && x.PointStatus == LocationStatusEnum.Free.ObjToInt()).ToList();
            var point = cachePoints.FirstOrDefault();
            return point;
        }
 
        public Dt_CachePoint? GetIbStockCachePoint(int areaId)
        {
            List<CachePointGroupDTO> cachePointGroups = Repository.GetCachePointGroups(areaId, LocationStatusEnum.InStock, LocationStatusEnum.Free);
            if (cachePointGroups != null && cachePointGroups.Count > 0)
            {
                CachePointGroupDTO? pointGroupDTO = cachePointGroups.FirstOrDefault(x => x.EnableStatusA == EnableStatusEnum.OnlyOut.ObjToInt() || x.EnableStatusA == EnableStatusEnum.Normal.ObjToInt());
                int id = pointGroupDTO?.IdA ?? 0;
                return BaseDal.QueryFirst(x => x.Id == id);
            }
            cachePointGroups = Repository.GetCachePointGroups(areaId, LocationStatusEnum.InStock, LocationStatusEnum.InStock);
            if (cachePointGroups != null && cachePointGroups.Count > 0)
            {
                CachePointGroupDTO? pointGroupDTO = cachePointGroups.FirstOrDefault(x => x.EnableStatusB == EnableStatusEnum.OnlyOut.ObjToInt() || x.EnableStatusB == EnableStatusEnum.Normal.ObjToInt());
                int id = pointGroupDTO?.IdB ?? 0;
                return BaseDal.QueryFirst(x => x.Id == id);
            }
 
            return BaseDal.QueryFirst(x => x.PointStatus == LocationStatusEnum.InStock.ObjToInt() && (x.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt() || x.EnableStatus == EnableStatusEnum.Normal.ObjToInt() && x.AreaId == areaId), _emptyAssignOrderBy);
        }
 
        public WebResponseContent GetEndPoints()
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<Dt_CachePoint> cachePoints = BaseDal.QueryData(x => x.PointName.Contains("区"));
                List<object> list = new List<object>();
                for (int i = 0; i < cachePoints.Count; i++)
                {
                    object option = new { value = cachePoints[i].PointName, text = cachePoints[i].PointName };
                    list.Add(option);
                }
                content = WebResponseContent.Instance.OK(data: list);
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            return content;
        }
 
        //查询缓存架状态
        public WebResponseContent GetHCJStaue(string stationcode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<Dt_CachePoint> cachePoints = BaseDal.QueryData(x => x.PointName.Contains("区"));
                List<object> list = new List<object>();
                for (int i = 0; i < cachePoints.Count; i++)
                {
                    object option = new { value = cachePoints[i].PointName, text = cachePoints[i].PointName };
                    list.Add(option);
                }
                content = WebResponseContent.Instance.OK(data: list);
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            return content;
        }
    }
}