hwh
2024-08-16 7865b72aa43b2f24150f7c815f6dbcf2e8f2f283
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
 
namespace WCS.Application;
 
/// <summary>
/// 设备工位服务
/// </summary>
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
public class WcsStationService : IDynamicApiController, ITransient
{
    private readonly SqlSugarRepository<WcsStation> _wcsStationRep;
    public WcsStationService(SqlSugarRepository<WcsStation> wcsStationRep)
    {
        _wcsStationRep = wcsStationRep;
    }
 
    /// <summary>
    /// 分页查询设备工位
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Page")]
    [DisplayName("分页查询设备工位")]
    public async Task<SqlSugarPagedList<WcsStationOutput>> Page(PageWcsStationInput input)
    {
        if (input.Field.IsNullOrEmpty())
        {
            input.Field = "u.Id";
            input.Order = "desc";
        }
        input.SearchKey = input.SearchKey?.Trim();
        var query = _wcsStationRep.AsQueryable()
            .WhereIF(!string.IsNullOrEmpty(input.SearchKey), u =>
                u.Text.Contains(input.SearchKey)
            )
            .WhereIF(input.DeviceId>0, u => u.DeviceId == input.DeviceId)
            .WhereIF(!string.IsNullOrWhiteSpace(input.Text), u => u.Text.Contains(input.Text.Trim()))
            //处理外键和TreeSelector相关字段的连接
            .LeftJoin<WcsDevice>((u, deviceid) => u.DeviceId == deviceid.Id )
            .Select((u, deviceid) => new WcsStationOutput
            {
                Id = u.Id,
                DeviceId = u.DeviceId, 
                DeviceIdText = deviceid.Text,
                StationNum = u.StationNum,
                PlcPos = u.PlcPos,
                PosType = u.PosType,
                LedIP = u.LedIP,
                Text = u.Text,
            });
        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(AddWcsStationInput input)
    {
        var entity = input.Adapt<WcsStation>();
        await _wcsStationRep.InsertAsync(entity);
        return entity.Id;
    }
 
    /// <summary>
    /// 删除设备工位
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Delete")]
    [DisplayName("删除设备工位")]
    public async Task Delete(DeleteWcsStationInput input)
    {
        var entity = await _wcsStationRep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
        await _wcsStationRep.FakeDeleteAsync(entity);   //假删除
        //await _wcsStationRep.DeleteAsync(entity);   //真删除
    }
 
    /// <summary>
    /// 更新设备工位
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    [ApiDescriptionSettings(Name = "Update")]
    [DisplayName("更新设备工位")]
    public async Task Update(UpdateWcsStationInput input)
    {
        var entity = input.Adapt<WcsStation>();
        await _wcsStationRep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
    }
 
    /// <summary>
    /// 获取设备工位
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "Detail")]
    [DisplayName("获取设备工位")]
    public async Task<WcsStation> Detail([FromQuery] QueryByIdWcsStationInput input)
    {
        return await _wcsStationRep.GetFirstAsync(u => u.Id == input.Id);
    }
 
    /// <summary>
    /// 获取设备工位列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    [ApiDescriptionSettings(Name = "List")]
    [DisplayName("获取设备工位列表")]
    public async Task<List<WcsStationOutput>> List([FromQuery] PageWcsStationInput input)
    {
        return await _wcsStationRep.AsQueryable().Select<WcsStationOutput>().ToListAsync();
    }
 
    /// <summary>
    /// 获取设备ID列表
    /// </summary>
    /// <returns></returns>
    [ApiDescriptionSettings(Name = "WcsDeviceDeviceIdDropdown"), HttpGet]
    [DisplayName("获取设备ID列表")]
    public async Task<dynamic> WcsDeviceDeviceIdDropdown()
    {
        return await _wcsStationRep.Context.Queryable<WcsDevice>()
                .Select(u => new
                {
                    Label = u.Text,
                    Value = u.Id
                }
                ).ToListAsync();
    }
 
 
 
 
}