zhao
2021-06-04 c7ec496f9e41c2227103b3ef776e4a3f91bce6b2
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using HH.WMS.BLL;
using HH.WMS.Common;
using HH.WMS.Entitys;
using HH.WMS.WebApi.Areas.Common.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
 
namespace HH.WMS.WebApi.Areas.Sys.Controllers
{
    public class PageSetController : BaseController
    {
        #region 获取所有配置
        /// <summary>
        /// 获取所有配置
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public OperateResult GetPageSetList()
        {
            return ValidateToken(t =>
            {
                var powerEnabledMstList = BLLCreator.CreateDapper<TN_WM_POWER_ENABLED_MSTEntity>().GetList();
                var powerEnabledDtlList = BLLCreator.CreateDapper<TN_WM_POWER_ENABLED_DTLEntity>().GetList(new
                {
                    CN_B_ENABLED = true
                }).Select(x =>
                {
                    var currentPowerEnableMst = powerEnabledMstList.Find(f => f.CN_GUID == x.CN_S_PARENTID) ?? new TN_WM_POWER_ENABLED_MSTEntity();
                    return new
                    {
                        CN_GUID = x.CN_GUID,
                        CN_S_POWER = currentPowerEnableMst.CN_S_POWER,
                        CN_B_READONLY = currentPowerEnableMst.CN_B_READONLY,
                        x.CN_S_POWER_CODE,
                        x.CN_S_POWER_NAME,
                        x.CN_B_ENABLED,
                        x.CN_F_WIDTH,
                        x.CN_S_ALIGN,
                        x.CN_S_METHOD_NAME,
                        x.CN_S_REMARK,
                        x.CN_N_ORDER
                    };
                }).OrderBy(o => o.CN_N_ORDER);
                return OperateResult.Succeed(null, powerEnabledDtlList);
            });
        }
        #endregion
 
        #region 根据id获取
        /// <summary>
        /// 根据id获取
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public OperateResult GetById(string id)
        {
            return ValidateToken(t =>
            {
                var entity = BLLCreator.CreateDapper<TN_WM_POWER_ENABLED_DTLEntity>().GetSingleEntity(new
                {
                    CN_GUID = id
                });
                return OperateResult.Succeed(null, entity);
            });
        }
        #endregion
 
        #region 获取配置模块
        /// <summary>
        /// 获取配置模块
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public OperateResult GetPowerType()
        {
            return ValidateToken(t =>
            {
                var powers = BLLCreator.CreateDapper<TN_WM_POWER_ENABLED_MSTEntity>().GetList();
                return OperateResult.Succeed(null, powers);
            });
        }
        #endregion
 
        #region 获取功能配置信息
        /// <summary>
        /// 获取功能配置信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public OperateResult GetPowerEnabled(string power, string code, string name)
        {
            return ValidateToken(t =>
            {
                var powers = BLLCreator.CreateDapper<TN_WM_POWER_ENABLED_MSTEntity>().GetList();
                var currentPower = powers.Find(x => x.CN_GUID == power);
                var powerEnabledList = BLLCreator.CreateDapper<TN_WM_POWER_ENABLED_DTLEntity>().GetList(new
                {
                    CN_S_PARENTID = power,
                    CN_S_POWER_CODE = Util.ToLike(code),
                    CN_S_POWER_NAME = Util.ToLike(name)
                });
                var result = powerEnabledList.Select(x =>
                {
                    currentPower = (powers.Find(f => f.CN_GUID == x.CN_S_PARENTID)) ?? new TN_WM_POWER_ENABLED_MSTEntity();
                    return new
                    {
                        CN_GUID = x.CN_GUID,
                        CN_S_POWER = currentPower.CN_S_POWER,
                        x.CN_S_POWER_CODE,
                        x.CN_S_POWER_NAME,
                        x.CN_B_ENABLED,
                        x.CN_F_WIDTH,
                        x.CN_S_ALIGN,
                        x.CN_S_METHOD_NAME,
                        x.CN_S_REMARK,
                        x.CN_N_ORDER
                    };
                }).OrderBy(o => o.CN_N_ORDER);
                return OperateResult.Succeed(null, result);
            });
        }
        #endregion
 
        #region 设置启用状态
        /// <summary>
        /// 新增编辑
        /// </summary>
        /// <param name="postEntity"></param>
        /// <returns></returns>
        [HttpPost]
        public OperateResult SetEnabled(PostEntity postEntity)
        {
            return ValidateToken(postEntity.TokenId, t =>
            {
                TN_WM_POWER_ENABLED_DTLEntity entity = postEntity.GetPostData<TN_WM_POWER_ENABLED_DTLEntity>();
                if (entity == null)
                    return OperateResult.Error("参数不正确");
                return BLLCreator.CreateDapper<TN_WM_POWER_ENABLED_DTLEntity>().Update(
                    new
                    {
                        CN_B_ENABLED = entity.CN_B_ENABLED,
                        CN_S_REMARK = entity.CN_S_REMARK,
                        CN_N_ORDER = entity.CN_N_ORDER
                    },
                    new
                    {
                        CN_GUID = entity.CN_GUID
                    });
            });
        }
        #endregion
 
        #region 新增编辑
        /// <summary>
        /// 新增编辑
        /// </summary>
        /// <param name="postEntity"></param>
        /// <returns></returns>
        public OperateResult Edit(PostEntity postEntity)
        {
            return ValidateToken(postEntity.TokenId, t =>
            {
                var entity = postEntity.GetPostData<TN_WM_POWER_ENABLED_DTLEntity>();
                if (entity == null)
                    return OperateResult.Error("参数不正确");
                if (string.IsNullOrEmpty(entity.CN_GUID))//新增
                {
                    entity.CN_GUID = Guid.NewGuid().ToString();
                    return BLLCreator.CreateDapper<TN_WM_POWER_ENABLED_DTLEntity>().Add(entity);
                }
                else//编辑
                {
                    return BLLCreator.CreateDapper<TN_WM_POWER_ENABLED_DTLEntity>().Update(entity, new
                    {
                        CN_GUID = entity.CN_GUID
                    });
                }
            });
        }
        #endregion
 
        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public OperateResult Delete(string id)
        {
            return ValidateToken(t =>
            {
                return BLLCreator.CreateDapper<TN_WM_POWER_ENABLED_DTLEntity>().Delete(new
                {
                    CN_GUID = id
                });
            });
        }
        #endregion
    }
}