啊鑫
2 天以前 b9f57af428b55be059d9d8bb4adc9c0692b2dc8e
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
using System.Data;
using System.Data.SqlClient;
using System.Dynamic;
using System.Text;
using Gs.Toolbox;
using Gs.Toolbox.ApiCore.Abstract.Mvc;
using Gs.Toolbox.ApiCore.Common.Mvc;
using Gs.Toolbox.ApiCore.Group;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using static Gs.Toolbox.UtilityHelper;
 
namespace Gs.JJGZ;
 
[ApiGroup(ApiGroupNames.JJGZ)]
public class MesJjgzJssalaryController : IRomteService
{
    private readonly IHttpContextAccessor _http;
 
    private readonly string _userCode, _userGuid, _orgFids;
    public MesJjgzJssalaryController(IHttpContextAccessor httpContextAccessor)
    {
        _http = httpContextAccessor;
        (_userCode, _userGuid, _orgFids) =
            GetUserGuidAndOrgGuid(_http);
    }
 
 
    /// <summary>
    ///     读取列表,支持分页
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<PageList<dynamic>> GetListPage([FromBody] dynamic model)
    {
        int currentPage = model.currentPage;
        int everyPageSize = model.everyPageSize;
        string sortName = model.sortName;
        string keyWhere = model.keyWhere;
        SqlParameter[] parameters =
        {
            new("@inCurrentPage", currentPage),
            new("@inEveryPageSize", everyPageSize),
            new("@inSortName", sortName),
            new("@inSortOrder", ""),
            new("@inQueryWhere", keyWhere),
            new("@inFid", ""),
            new("@inP1", ""),
            new("@inP2", ""),
            new("@inP3", ""),
            new("@inP4", "")
        };
        var dset = new DataSet();
        var _pglist = new PageList<dynamic>
        {
            total = 0,
            everyPageSize = 0,
            pages = 0,
            list = new List<dynamic>()
        };
        try
        {
            dset = DbHelperSQL.RunProcedure("prc_JSSALARY_lst", parameters, "0");
            if (dset != null && dset.Tables.Count > 0 &&
                dset.Tables[0].Rows.Count > 0) //有数据
            {
                var intTotal =
                    int.Parse(dset.Tables[1].Rows[0]["intTotal"].ToString());
                var pages = intTotal % everyPageSize != 0
                    ? intTotal / everyPageSize + 1
                    : intTotal / everyPageSize;
                _pglist.total = intTotal;
                _pglist.everyPageSize = everyPageSize;
                _pglist.pages = pages;
                var _dy = dset.Tables[0].TableToDynamicList();
                _pglist.list = _dy;
            }
        }
        catch (Exception ex)
        {
            LogHelper.Debug(ToString(), ex.Message);
            return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist,
          ReturnCode.Exception, ex.Message);
        }
        return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist,
            ReturnCode.Success, "读取成功");
    }
 
    /// <summary>
    ///     读取
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<ExpandoObject> GetModel([FromBody] dynamic model)
    {
        string guid = model.guid.ToString();
        dynamic m = new ExpandoObject();
        m.list = new List<dynamic>();
        m.list2 = new List<dynamic>();
        // 假设主表为MES_JJGZ_JS_SALARY,明细表为MES_JJGZ_JS_SALARY_DETAIL
        string mainTable = "MES_JJGZ_JSSALARY";
        try
        {
            string sqlMain = $"SELECT * FROM {mainTable} WHERE guid='{guid}'";
            var dsMain = DbHelperSQL.Query(sqlMain);
            if (dsMain != null && dsMain.Tables.Count > 0 && dsMain.Tables[0].Rows.Count > 0)
            {
                var dr = dsMain.Tables[0].Rows[0];
                m = dr.RowToDynamic();
            }
        }
        catch (Exception ex)
        {
            LogHelper.Debug(ToString(), ex.Message);
        }
        if (m != null)
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "读取成功!");
        return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
    }
 
    /// <summary>
    ///     提交审核反审核
    /// </summary>
    /// <param name="mode"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<ExpandoObject> EditModelSubmit([FromBody] dynamic mode)
    {
        string _guid = mode.guid;
        string _inFieldValue = mode.inFieldValue;
        dynamic m = new ExpandoObject();
        m.outSum = -1;
        m.outMsg = "";
        try
        {
            // 假设提交就是更新某个字段
            string sql = $"UPDATE MES_JJGZ_JSSALARY SET check_status='{_inFieldValue}',check_date = getdate(), check_user='{_userGuid}' WHERE guid='{_guid}'";
            int rows = DbHelperSQL.ExecuteSql(sql);
            m.outSum = rows;
            m.outMsg = rows > 0 ? "操作成功!" : "未更新任何数据";
        }
        catch (Exception ex)
        {
            LogHelper.Debug(ToString(), "EditModelSubmit error:" + ex.Message);
            m.outMsg = ex.Message;
            m.outSum = -1;
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, ex.Message);
        }
        return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "操作成功!");
    }
 
    /// <summary>
    ///     增加或编辑实体
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<ExpandoObject> EditModel([FromBody] dynamic model)
    {
        Guid? guid = model.guid; //主键
        string hourlyType = model.hourlyType;
        string hourlySalary = model.hourlySalary;
        string remark = model.remark;
        string salaryType = model.salaryType;
        string beginTime = model.beginTime;
        string endTime = model.endTime;
 
        dynamic mObj = new ExpandoObject();
        mObj.outMsg = "";
        mObj.outSum = -1;
        mObj.outGuid = "";
        mObj.outNo = "";
        try
        {
            string sql;
            if (CheckGuid(guid))
            {
                sql = $"UPDATE MES_JJGZ_JSSALARY SET HourlyType='{hourlyType}', HourlySalary='{hourlySalary}', Remark='{remark}', SalaryType='{salaryType}', BeginTime='{beginTime}', EndTime='{endTime}' WHERE guid='{guid}'";
            }
            else
            {
                guid = Guid.NewGuid();
                sql = $" declare @userBy nvarchar(20); select top 1 @userBy=[ACCOUNT] from [dbo].[SYS_USER] where guid='{_userGuid}' " +
                    $"INSERT INTO MES_JJGZ_JSSALARY (guid, CREATE_BY, CREATE_DATE, HourlyType, HourlySalary, Remark, SalaryType, BeginTime, EndTime) VALUES ('{guid}',@userBy,GETDATE(), '{hourlyType}', '{hourlySalary}', '{remark}', '{salaryType}', '{beginTime}', '{endTime}' )";
            }
            int rows = DbHelperSQL.ExecuteSql(sql);
            mObj.outSum = rows;
            mObj.outGuid = guid.ToString();
            mObj.outMsg = rows > 0 ? "操作成功!" : "未更新任何数据";
        }
        catch (Exception ex)
        {
            LogHelper.Debug(ToString(), "EditModel error:" + ex.Message);
            mObj.outMsg = ex.Message;
            mObj.outSum = -1;
        }
        if (mObj.outSum <= 0)
            return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Exception, mObj.outMsg);
        return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Success, mObj.outMsg);
    }
 
    /// <summary>
    ///     删除主表或明细
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<int?> DeleteModel([FromBody] dynamic model)
    {
        int? rtnInt = (int)ReturnCode.Default;
        Guid? guid = model.guid; //到货单主键
        string mxGuid = model.mxGuid;
        var _outMsg = "";
        var _outSum = -1;
        try
        {
            if (CheckGuid(guid))
            {
                string sql = $"DELETE FROM MES_JJGZ_JSSALARY WHERE guid='{guid}'";
                _outSum = DbHelperSQL.ExecuteSql(sql);
                _outMsg = _outSum > 0 ? "删除成功!" : "未删除任何数据";
            }
            else
            {
                _outMsg = "主键不能为空!";
                _outSum = -1;
            }
        }
        catch (Exception ex)
        {
            LogHelper.Debug(ToString(), "DeleteModel error:" + ex.Message);
            _outMsg = ex.Message;
            _outSum = -1;
        }
        if (_outSum <= 0)
            return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception, _outMsg);
        return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Success, _outMsg);
    }
 
    /// <summary>
    ///     读取
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<ExpandoObject> GetTimeType([FromBody] dynamic model)
    {
        dynamic m = new ExpandoObject();
        string mainTable = "MES_JJGZ_TIMETYPE";
        try
        {
            string sqlMain = $"SELECT * FROM {mainTable} WHERE CHECK_STATUS = 1";
            var dsMain = DbHelperSQL.Query(sqlMain);
            if (dsMain != null && dsMain.Tables.Count > 0 && dsMain.Tables[0].Rows.Count > 0)
            {
                var _tb = dsMain.Tables[0].TableToDynamicList();
                m.list = _tb;
            }
        }
        catch (Exception ex)
        {
            LogHelper.Debug(ToString(), ex.Message);
        }
        if (m != null)
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "读取成功!");
        return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
    }
 
}