服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-05-30 1ae7b5a517aaa0f3a45f0b31b0c5173c35558318
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
using Tiger.Model;
using Rhea.Common;
using Tiger.IBusiness;
using static Tiger.Business.Biz;
using Microsoft.AspNetCore.Http;
 
namespace Tiger.Business.MES
{
    /// <summary>
    /// 车间
    /// </summary>
    public partial class BizMesWs : IMES_WORKSHOP
    {
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="ws"></param>
        /// <returns></returns>
        public async Task<ApiAction> SaveMesWs(MES_WORKSHOP ws)
        {
            var result = new ApiAction();
            try
            {
                if (Db.Queryable<MES_WORKSHOP>().Where(x => x.WS_CODE == ws.WS_CODE && x.ID != ws.ID).Any())
                {
                    result.IsSuccessed = false;
                    result.LocaleMsg = new($"车间已经存在,不能新增!");
                    return result;
                }
                var db = Db;
                var dbTran = db.UseTran(() =>
                {
                    var y = db.Storageable(ws)
                       .WhereColumns(t => new { t.WS_CODE, t.GHOST_ROW })
                       .ToStorage();
                    y.AsInsertable.ExecuteCommand();
                    y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                });
                if (!dbTran.IsSuccess)
                {
                    result.IsSuccessed = false;
                    result.Message = $"保存车间异常";
                }
            }
            catch (Exception ex)
            {
                result.CatchExceptionWithLog(ex, "保存车间异常");
            }
            return await Task.FromResult(result);
        }
 
        /// <summary>
        /// 删除车间
        /// </summary>
        /// <param name="wsId"></param>
        /// <returns></returns>
        public async Task<ApiAction> DeleteMesWs(string wsId)
        {
            var result = new ApiAction();
            try
            {
                //查询是否已经有车间在用
                var db = Db;
                var dbTran = db.UseTran(() =>
                {
                    db.Deleteable<MES_WORKSHOP>().Where(x => x.ID == wsId).ExecuteCommand();
                });
                if (!dbTran.IsSuccess)
                {
                    result.IsSuccessed = false;
                    result.LocaleMsg = new($"删除车间异常");
                }
            }
            catch (Exception ex)
            {
                result.CatchExceptionWithLog(ex, "删除车间异常");
            }
            return await Task.FromResult(result);
        }
    }
}