刘磊
2024-12-17 58a5a9af83492c5bbb4fba88b4443f08fa4becfc
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
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_Tasks.ConveyorLineJob;
 
namespace WIDESEAWCS_Tasks
{
    public class GetStationService : ServiceBase<Dt_StationManager, IDt_StationManagerRepository>, IGetStationService
    {
        //private readonly IDt_StationManagerRepository _stationManagerRepository;
 
        public GetStationService(IDt_StationManagerRepository BaseDal, ISys_ConfigService sys_ConfigService) : base(BaseDal)
        {
        }
 
        public WebResponseContent GetStationHasPallet(List<string> stations)
        {
            var content = new WebResponseContent();
 
            try
            {
                int palletCount = 0; // 用于记录没有托盘的站点数量
                var stationManagers = BaseDal.QueryData(s => stations.Contains(s.stationChildCode)); // 查询相关站点管理信息
 
                foreach (var station in stationManagers)
                {
                    if (IsStationValid(station))
                    {
                        var hasPallet = ReadPalletStatus(station); // 获取托盘状态
                        if (hasPallet == 0) // 如果没有托盘
                        {
                            palletCount++;
                        }
                    }
                }
 
                content.OK(data: palletCount); // 返回结果
            }
            catch (Exception ex)
            {
                content.Error(ex.Message); // 捕获并返回错误信息
            }
 
            return content;
        }
 
        // 验证站点是否有效
        private bool IsStationValid(Dt_StationManager station)
        {
            return Convert.ToInt32(station.stationPLC) > 1010;
        }
 
        // 读取托盘状态
        private int ReadPalletStatus(Dt_StationManager station)
        {
            var commonConveyorLine_GW = Storage.Devices.FirstOrDefault(device => device.DeviceCode == station.stationPLC) as CommonConveyorLine_GW;
            return Convert.ToInt32(commonConveyorLine_GW.ReadValue(ConveyorLineDBName_After.HasPallet, station.stationChildCode));
        }
    }
}