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);
}
///
/// 审核,形如:mes_HOLIDAY,check_date,check_status,check_by,prc_test
/// (如果存储过程前面有000,则直接执行存储过程 0,0,0,0,000chk_mes_CHECKITEM)
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto 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.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.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.QuickReturn(m, ReturnCode.Exception,
"操作失败:" + ex.Message);
}
m.outMsg = _sbMsg.ToString();
return ReturnDto.QuickReturn(m, ReturnCode.Success, "操作成功!");
}
}