hwh
2024-08-22 a8029953301875e30b4dfcfc599a6fb4ebcd0c0c
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
 
namespace WCS.Application;
 
/// <summary>
/// 设备信息服务
/// </summary>
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
public class WcsDeviceService : IDynamicApiController, ITransient
{
    private readonly SqlSugarRepository<WcsDevice> _wcsDeviceRep;
    public WcsDeviceService(SqlSugarRepository<WcsDevice> wcsDeviceRep)
    {
        _wcsDeviceRep = wcsDeviceRep;
    }
 
    /// <summary>
    /// 分页查询设备信息
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Page")]
    [DisplayName("分页查询设备信息")]
    public async Task<SqlSugarPagedList<WcsDeviceOutput>> Page(PageWcsDeviceInput input)
    {
        if (input.Field.IsNullOrEmpty())
        {
            input.Field = "u.Id";
            input.Order = "desc";
        }
        input.SearchKey = input.SearchKey?.Trim();
        var query = _wcsDeviceRep.AsQueryable()
            .WhereIF(!string.IsNullOrEmpty(input.SearchKey), u =>
                u.Text.Contains(input.SearchKey)
            )
            .WhereIF(input.PlcId>0, u => u.PlcId == input.PlcId)
            .WhereIF(!string.IsNullOrWhiteSpace(input.Text), u => u.Text.Contains(input.Text.Trim()))
            //处理外键和TreeSelector相关字段的连接
            .LeftJoin<WcsPlc>((u, plcid) => u.PlcId == plcid.Id )
            .Select((u, plcid) => new WcsDeviceOutput
            {
                Id = u.Id,
                PlcId = u.PlcId, 
                PlcIdIP = plcid.IP,
                Level = (DeviceLevelEnum)u.Level,
                DbNumber = u.DbNumber,
                StationNum = u.StationNum,
                PlcPos = u.PlcPos,
                WcsPos = u.WcsPos,
                PosType = u.PosType,
                LedIP = u.LedIP,
                Text = u.Text,
                CreateTime = u.CreateTime,
                UpdateTime = u.UpdateTime,
                CreateUserId = u.CreateUserId,
                CreateUserName = u.CreateUserName,
                UpdateUserId = u.UpdateUserId,
                UpdateUserName = u.UpdateUserName,
                CreateOrgId = u.CreateOrgId,
                CreateOrgName = u.CreateOrgName,
                IsDelete = u.IsDelete,
            });
        return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
    }
 
    /// <summary>
    /// 增加设备信息
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Add")]
    [DisplayName("增加设备信息")]
    public async Task<long> Add(AddWcsDeviceInput input)
    {
        var entity = input.Adapt<WcsDevice>();
        await _wcsDeviceRep.InsertAsync(entity);
        return entity.Id;
    }
 
    /// <summary>
    /// 删除设备信息
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Delete")]
    [DisplayName("删除设备信息")]
    public async Task Delete(DeleteWcsDeviceInput input)
    {
        var entity = await _wcsDeviceRep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
        await _wcsDeviceRep.FakeDeleteAsync(entity);   //假删除
        //await _wcsDeviceRep.DeleteAsync(entity);   //真删除
    }
 
    /// <summary>
    /// 更新设备信息
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Update")]
    [DisplayName("更新设备信息")]
    public async Task Update(UpdateWcsDeviceInput input)
    {
        var entity = input.Adapt<WcsDevice>();
        await _wcsDeviceRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
    }
 
    /// <summary>
    /// 获取设备信息
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "Detail")]
    [DisplayName("获取设备信息")]
    public async Task<WcsDevice> Detail([FromQuery] QueryByIdWcsDeviceInput input)
    {
        return await _wcsDeviceRep.GetFirstAsync(u => u.Id == input.Id);
    }
 
    /// <summary>
    /// 获取设备信息列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "List")]
    [DisplayName("获取设备信息列表")]
    public async Task<List<WcsDeviceOutput>> List([FromQuery] PageWcsDeviceInput input)
    {
        return await _wcsDeviceRep.AsQueryable().Select<WcsDeviceOutput>().ToListAsync();
    }
 
    /// <summary>
    /// 获取PlcId列表
    /// </summary>
    /// <returns></returns>
    [ApiDescriptionSettings(Name = "WcsPlcPlcIdDropdown"), HttpGet]
    [DisplayName("获取PlcId列表")]
    public async Task<dynamic> WcsPlcPlcIdDropdown()
    {
        return await _wcsDeviceRep.Context.Queryable<WcsPlc>()
                .Select(u => new
                {
                    Label = u.IP,
                    Value = u.Id
                }
                ).ToListAsync();
    }
 
 
 
 
}