新框架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
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
using System.Collections;
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.Sys.Services;
 
[ApiGroup(ApiGroupNames.Sys)]
public class GeneralController : IRomteService
{
    private readonly IHttpContextAccessor _http;
    private readonly string _userCode, _userGuid, _orgFids;
 
    public GeneralController(IHttpContextAccessor httpContextAccessor)
    {
        _http = httpContextAccessor;
        (_userCode, _userGuid, _orgFids) =
            GetUserGuidAndOrgGuid(_http);
    }
 
    /// <summary>
    ///     审核,形如:mes_HOLIDAY,check_date,check_status,check_by,prc_test
    ///     (如果存储过程前面有000,则直接执行存储过程 0,0,0,0,000chk_mes_CHECKITEM)
    /// </summary>
    /// <param name="mode"></param>
    /// <returns></returns>
    [RequestMethod(RequestMethods.POST)]
    public ReturnDto<ExpandoObject> GeneralCheck([FromBody] dynamic mode)
    {
        string _parameter = mode.parameter;
        string _guid = mode.guid;
        string _ck_value = mode.ckValue; //0或1
        var _parameterAry = _parameter.Split(",");
        var _table = _parameterAry[0]; //表名
        var check_date = _parameterAry[1]; //字段时间
        var check_status = _parameterAry[2]; //字段状态
        var check_by = _parameterAry[3]; //字段人
        //存储过程,有可能有,有可能没有,审核完之后执行
        var check_prc = "";
        if (_parameterAry.Length > 4)
            check_prc = _parameterAry[4];
        dynamic m = new ExpandoObject();
        m.outIt = 0;
        m.outMsg = "";
        var _sbMsg = new StringBuilder();
        try
        {
            if (!check_prc.StartsWith("000"))
            {
                //不能重复审核
                var cont = 0;
                var _sbCont = new StringBuilder();
                if (_ck_value == "1")
                {
                    _sbCont.Append("select count(1) from " + _table +
                                   " where guid='" + _guid + "' and " +
                                   check_status + "=" + _ck_value);
                    cont = int.Parse(DbHelperSQL.GetSingle(_sbCont.ToString())
                        .ToString());
                    if (cont > 0)
                    {
                        m.outMsg = "操作失败,该单据已审核,请勿重复操作!";
                        return ReturnDto<dynamic>.QuickReturn(m,
                            ReturnCode.Exception, "操作失败!");
                    }
                }
                else
                {
                    cont = 0;
                    _sbCont = new StringBuilder();
                    _sbCont.Append("select count(1) from " + _table +
                                   " where guid='" + _guid + "' and " +
                                   check_status + "=1");
                    cont = int.Parse(DbHelperSQL.GetSingle(_sbCont.ToString()).ToString());
                    if (cont <= 0)
                    {
                        m.outMsg = "操作失败,该单据并没有被审核!";
                        return ReturnDto<dynamic>.QuickReturn(m,
                            ReturnCode.Exception, "操作失败,该单据并没有被审核!");
                    }
                }
 
                //开始审核
                var _ary = new ArrayList();
                var _strSql1 = new StringBuilder();
                _strSql1.Append(" update " + _table + " set " + check_date +
                                "=getdate()," + check_status + "=" + _ck_value +
                                "," + check_by + "='" + _userCode +
                                "' where guid='" + _guid + "'");
                _ary.Add(_strSql1);
                _ary.Add(BuildLog(_userGuid, _guid, _table, '【'+ _userCode+'】'+  "审核了【" + _guid+'】'));
                DbHelperSQL.ExecuteSqlTran(_ary);
                _sbMsg.Append("操作成功!");
                m.outGuid = _guid;
            }
 
            check_prc = check_prc.Replace("000", "");
            //如果有存储过程,
            if (!string.IsNullOrEmpty(check_prc))
                using (var conn = new SqlConnection(DbHelperSQL.strConn))
                {
                    using (var cmd = new SqlCommand(check_prc, conn))
                    {
                        try
                        {
                            conn.Open();
                            cmd.CommandType = CommandType.StoredProcedure;
                            SqlParameter[] parameters =
                            {
                                new("@outMsg", SqlDbType.NVarChar, 300),
                                new("@outSum", SqlDbType.Int),
                                new("@inEdtUserGuid", _userGuid),
                                new("@inOrderGuid", _guid),
                                new("@inFieldName", check_date),
                                new("@inFieldValue", _ck_value),
                                new("@in1", ""),
                                new("@in2", "")
                            };
                            parameters[0].Direction = ParameterDirection.Output;
                            parameters[1].Direction = ParameterDirection.Output;
                            foreach (var parameter in parameters)
                                cmd.Parameters.Add(parameter);
                            var rtnInt = cmd.ExecuteNonQuery();
                            _sbMsg.Append("," + parameters[0].Value);
                            m.outIt = parameters[1].Value.ToString();
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Debug(ToString(),
                                "DeleteModel error:" + ex.Message);
                            _sbMsg.Append(",存储过程执行失败," + ex.Message);
                        }
                        finally
                        {
                            conn.Close();
                        }
                    }
                }
        }
        catch (Exception ex)
        {
            LogHelper.Debug(ToString(), ex.Message);
            m.outMsg = "操作失败," + ex.Message;
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Exception,
                "操作失败:" + ex.Message);
        }
 
        m.outMsg = _sbMsg.ToString();
        return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "操作成功!");
    }
}