啊鑫
5 天以前 eb65436c2312821e3e513ab9ada41dd486d6d7cf
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
using System.Data;
using System.Data.SqlClient;
using System.Dynamic;
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.Wom.WorkService
{
 
    [ApiGroup(ApiGroupNames.WOM)]
    public class WorkWeightController : IRomteService
    {
        private readonly IHttpContextAccessor _http;
        private readonly string _userCode, _userGuid, _orgFids;
 
        public WorkWeightController(IHttpContextAccessor httpContextAccessor)
        {
            _http = httpContextAccessor;
            (_userCode, _userGuid, _orgFids) =
                GetUserGuidAndOrgGuid(_http);
        }
 
 
        /// <summary>
        /// 读取称重列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<List<dynamic>> GetModelList([FromBody] dynamic model)
        {
            string lineId = model.lineId;
            List<dynamic> lst = new List<dynamic>();
            var dset = new DataSet();
            try
            {
                SqlParameter[] parameters =
                      {
                        new("@inLineId",lineId)
                    };
                dset = DbHelperSQL.RunProcedure("work_weight_lst", parameters, "0");
            }
            catch (Exception ex)
            {
                LogHelper.Debug(ToString(), "work_weight_lst error:" + 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<ExpandoObject> EditModel([FromBody] dynamic model)
        {
            string lineId = model.lineId;
            string realWeight = model.realWeight;
            string realWeightTxt = model.realWeightTxt;
            dynamic mObj = new ExpandoObject();
            mObj.outMsg = "";
            mObj.outSum = -1;
            using (var conn = new SqlConnection(DbHelperSQL.strConn))
            {
                using (var cmd = new SqlCommand("[work_weight_add]", conn))
                {
                    try
                    {
                        conn.Open();
                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter[] parameters =
                        {
                        new("@outMsg", SqlDbType.NVarChar, 300),
                        new("@outSum", SqlDbType.Int),
                        new("@lineId", lineId),
                        new("@realWeight", realWeight),
                        new("@realWeightTxt", realWeightTxt),
                        new("@inEdtUserGuid", _userGuid),
                    };
                        parameters[0].Direction = ParameterDirection.Output;
                        parameters[1].Direction = ParameterDirection.Output;
                        foreach (var parameter in parameters)
                            cmd.Parameters.Add(parameter);
                        cmd.ExecuteNonQuery();
                        mObj.outMsg = parameters[0].Value.ToString();
                        mObj.outSum = int.Parse(parameters[1].Value.ToString());
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Debug(ToString(),
                            "work_weight_add error:" + ex.Message);
                        mObj.outMsg = ex.Message;
                        mObj.outSum = -1;
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            if (mObj.outSum <= 0)
                return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Exception, mObj.outMsg);
            return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Success, mObj.outMsg);
        }
 
 
        /// <summary>
        ///    读取iqc称重
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<string?> GetIqcWeight([FromBody] dynamic model)
        {
            string? rtnInt = "";
            var dset = new DataSet();
            try
            {
                SqlParameter[] parameters =
                      {
                        new("@inLineId","")
                    };
                dset = DbHelperSQL.RunProcedure("iqc_detect01_get_weight", parameters, "0");
            }
            catch (Exception ex)
            {
                LogHelper.Debug(ToString(), "GetIqcWeight error:" + ex.Message);
            }
            if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)
            {
                rtnInt = dset.Tables[0].Rows[0]["realWeight"].ToString();
            }
            return ReturnDto<string>.QuickReturn(rtnInt, ReturnCode.Success, "读取成功!");
        }
 
 
        /// <summary>
        ///   编辑iqc重量
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [RequestMethod(RequestMethods.POST)]
        public ReturnDto<ExpandoObject> EditIqcWeight([FromBody] dynamic model)
        {
            string iqcGuid = model.iqcGuid;
            string weightType = model.weightType;
            string weight = model.weight;
            dynamic mObj = new ExpandoObject();
            mObj.outMsg = "";
            mObj.outSum = -1;
            using (var conn = new SqlConnection(DbHelperSQL.strConn))
            {
                using (var cmd = new SqlCommand("[iqc_detect01_edt_weight]", conn))
                {
                    try
                    {
                        conn.Open();
                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter[] parameters =
                        {
                        new("@outMsg", SqlDbType.NVarChar, 300),
                        new("@outSum", SqlDbType.Int),
                        new("@weightType", weightType),
                        new("@weight", weight),
                        new("@iqcGuid", iqcGuid),
                        new("@inEdtUserGuid", _userGuid),
                    };
                        parameters[0].Direction = ParameterDirection.Output;
                        parameters[1].Direction = ParameterDirection.Output;
                        foreach (var parameter in parameters)
                            cmd.Parameters.Add(parameter);
                        cmd.ExecuteNonQuery();
                        mObj.outMsg = parameters[0].Value.ToString();
                        mObj.outSum = int.Parse(parameters[1].Value.ToString());
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Debug(ToString(), "iqc_detect01_edt_weight error:" + ex.Message);
                        mObj.outMsg = ex.Message;
                        mObj.outSum = -1;
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            if (mObj.outSum <= 0)
                return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Exception, mObj.outMsg);
            return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Success, mObj.outMsg);
        }
    }
}