新框架PC后端代码(祈禧6月初版本)
南骏 池
3 天以前 72449a1b8699b65712e57fba8abce5a8240e9465
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
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);
        }
    }
}