新框架PC后端代码(祈禧6月初版本)
lg
7 天以前 9818c99cf8b660d5cc29c4f404b642c2f361df3c
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
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 System.Data;
using System.Data.SqlClient;
using System.Dynamic;
using static Gs.Toolbox.UtilityHelper;
 
namespace Gs.Wom.BaoGong
{
 
    /// <summary>
    /// 报工
    /// </summary>
    [ApiGroup(ApiGroupNames.WOM)]
    public class BaoGongController : IRomteService
    {
        private readonly IHttpContextAccessor _http;
        private readonly string _userCode, _userGuid, _orgFids;
        public BaoGongController(IHttpContextAccessor httpContextAccessor)
        {
            _http = httpContextAccessor;
            (_userCode, _userGuid, _orgFids) =
                GetUserGuidAndOrgGuid(_http);
        }
 
        /// <summary>
        /// 读取产线列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<List<dynamic>> GetLineList([FromBody] dynamic model)
        {
            string inCjId = model.inCjId;
            var lst = new List<dynamic>();
            var dset = new DataSet();
            SqlParameter[] parameters =
            {
                new("@inCjId", inCjId),
             };
            try
            {
                dset = DbHelperSQL.RunProcedure("bg_line_list", parameters, "0");
            }
            catch (Exception ex)
            {
                LogHelper.Debug(ToString(), ex.Message);
            }
            string strMsg = "";
            if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)
            {
                lst = dset.Tables[0].TableToDynamicList();
                strMsg = dset.Tables[1].Rows[0]["dptName"].ToString();
            }
            return ReturnDto<List<dynamic>>.QuickReturn(lst, ReturnCode.Success,
                strMsg);
        }
 
        /// <summary>
        /// 读取工单列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<List<dynamic>> GetDaaList([FromBody] dynamic model)
        {
            string inLineId = model.inLineId;
            var lst = new List<dynamic>();
            var dset = new DataSet();
            SqlParameter[] parameters =
            {
                new("@inLineId", inLineId),
             };
            try
            {
                dset = DbHelperSQL.RunProcedure("bg_daa_list", parameters, "0");
            }
            catch (Exception ex)
            {
                LogHelper.Debug(ToString(), ex.Message);
            }
            if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)
                lst = dset.Tables[0].TableToDynamicList();
            return ReturnDto<List<dynamic>>.QuickReturn(lst, ReturnCode.Success,
                "读取成功!");
        }
 
 
        /// <summary>
        /// 读取员工列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<List<dynamic>> GetYgList([FromBody] dynamic model)
        {
            string inCjId = model.inCjId;
            var lst = new List<dynamic>();
            var dset = new DataSet();
            SqlParameter[] parameters =
            {
                new("@inCjId", inCjId),
             };
            try
            {
                dset = DbHelperSQL.RunProcedure("bg_yg_list", parameters, "0");
            }
            catch (Exception ex)
            {
                LogHelper.Debug(ToString(), ex.Message);
            }
            if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)
                lst = dset.Tables[0].TableToDynamicList();
            return ReturnDto<List<dynamic>>.QuickReturn(lst, ReturnCode.Success,
                "读取成功!");
        }
 
 
        /// <summary>
        ///     读取工单信息
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<ExpandoObject> GetModel([FromBody] dynamic model)
        {
            string inDaaGuid = model.inDaaGuid.ToString();
            dynamic m = new ExpandoObject();
            m.list = new List<dynamic>();
            SqlParameter[] parameters =
            {
            new("@inDaaGuid", inDaaGuid),
            new("@inUserGuid", _userGuid)
        };
            var dset = new DataSet();
            try
            {
                dset = DbHelperSQL.RunProcedure("bg_daa_info", parameters,
                    "0");
                if (dset != null && dset.Tables.Count > 0 &&
                    dset.Tables[0].Rows.Count > 0)
                {
                    var dr = dset.Tables[0].Rows[0];
                    m = dr.RowToDynamic();
                    var _tb = dset.Tables[1].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, "读取失败!");
        }
 
        /// <summary>
        ///   打码报工,先调用 rpt_daa,再调用 prc_pda_scbg
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<ExpandoObject> DaaDmbg([FromBody] dynamic model)
        {
            string _inEdtUserGuid = _userGuid;
            string _inOrderGuid = model.inDaaGuid.ToString();
            string _isDesign = "0";//100重打,1是设计
            string _in4 = "1";//扩展用,张数(打印张数)
            string _in5 = model.bzsl.ToString();//扩展用,数量(内包装数量)
            dynamic m = new ExpandoObject();
            m.outSum = -1;
            m.outMsg = "";
            SqlParameter[] parameters =
            {
            new("@inOrderGuid", _inOrderGuid),
            new("@isDesign", _isDesign),
            new("@in1", ""),
            new("@in2", ""),
            new("@in3", 0),
            new("@in4", _in4),
            new("@in5", _in5),
            new("@in6", "")
        };
            var dset = new DataSet();
            try
            {
                //1先调用 rpt_daa
                dset = DbHelperSQL.RunProcedure("rpt_daa", parameters, "0");
                if (dset != null && dset.Tables.Count > 0 &&
                    dset.Tables[0].Rows.Count > 0)
                {
                    if (dset.Tables.Count != 3)
                    {
                        m.outSum = -1;
                        m.outMsg = dset.Tables[0].Rows[0]["msgTxt"].ToString();
                        return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, m.outMsg);
                    }
                    #region 再调用 prc_pda_scbg
                    string pi_barcode = dset.Tables[1].Rows[0]["ITEM_BARCODE"].ToString();
                    using (var conn = new SqlConnection(DbHelperSQL.strConn))
                    {
                        using (var cmd = new SqlCommand("prc_pda_scbg", conn))
                        {
                            try
                            {
                                conn.Open();
                                cmd.CommandType = CommandType.StoredProcedure;
                                SqlParameter[] parameters2 =
                                  {
                                    new("@pi_user", _userCode),
                                    new("@pi_barcode", pi_barcode),
                                    new("@pi_inp1", ""),
                                    new("@pi_inp2", ""),
                                    new("@po_outMsg", SqlDbType.NVarChar, 300),
                                    new("@po_outSum", SqlDbType.NVarChar, 300),
                                    new("@po_womInBarSum",SqlDbType.NVarChar, 300),
                                };
                                parameters2[4].Direction = ParameterDirection.Output;
                                parameters2[5].Direction = ParameterDirection.Output;
                                parameters2[6].Direction = ParameterDirection.Output;
                                foreach (var parameter in parameters2)
                                    cmd.Parameters.Add(parameter);
                                cmd.ExecuteNonQuery();
                                m.outMsg = parameters2[4].Value.ToString();
                                m.outSum = int.Parse(parameters2[5].Value.ToString());
                            }
                            catch (Exception ex)
                            {
                                LogHelper.Debug(ToString(),
                                    "prc_pda_scbg error:" + ex.Message);
                                m.outMsg = ex.Message;
                                return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default,
                                    ex.Message);
                            }
                            finally
                            {
                                conn.Close();
                            }
                        }
                    }
                    #endregion
                }
                return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "打码失败!");
            }
            catch (Exception ex)
            {
                m.outSum = -1;
                m.outMsg = ex.Message.ToString();
                LogHelper.Debug(ToString(), ex.Message);
            }
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, m.outMsg);
        }
    }
}