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.JJGZ;
|
|
[ApiGroup(ApiGroupNames.JJGZ)]
|
public class MesJjgzTimeTypeController : IRomteService
|
{
|
private readonly IHttpContextAccessor _http;
|
private readonly string _userCode, _userGuid, _orgFids;
|
|
public MesJjgzTimeTypeController(IHttpContextAccessor httpContextAccessor)
|
{
|
_http = httpContextAccessor;
|
(_userCode, _userGuid, _orgFids) =
|
GetUserGuidAndOrgGuid(_http);
|
}
|
|
/// <summary>
|
/// 读取列表,支持分页
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<ExpandoObject> GetListPage([FromBody] dynamic model)
|
{
|
var dset = new DataSet();
|
dynamic m = new ExpandoObject();
|
m.list = new List<dynamic>();
|
try
|
{
|
string sqlMain = $"SELECT * FROM MES_JJGZ_TIMETYPE";
|
var dsMain = DbHelperSQL.Query(sqlMain);
|
if (dsMain != null && dsMain.Tables.Count > 0 &&
|
dsMain.Tables[0].Rows.Count > 0)
|
{
|
//var dr = dset.Tables[0].Rows[0];
|
//m = dr.RowToDynamic();
|
var _tb = dsMain.Tables[0].TableToDynamicList();
|
m.list = _tb;
|
}
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Debug(ToString(), ex.Message);
|
return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
|
}
|
return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success,
|
"读取成功!");
|
}
|
|
/// <summary>
|
/// 读取
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<ExpandoObject> GetModel([FromBody] dynamic model)
|
{
|
string guid = model.guid.ToString();
|
dynamic m = new ExpandoObject();
|
string mainTable = "MES_JJGZ_TIMETYPE";
|
try
|
{
|
string sqlMain = $"SELECT * FROM {mainTable} WHERE guid='{guid}'";
|
var dsMain = DbHelperSQL.Query(sqlMain);
|
if (dsMain != null && dsMain.Tables.Count > 0 && dsMain.Tables[0].Rows.Count > 0)
|
{
|
var dr = dsMain.Tables[0].Rows[0];
|
m = dr.RowToDynamic();
|
}
|
}
|
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>
|
/// 提交审核反审核
|
/// </summary>
|
/// <param name="mode"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<ExpandoObject> EditModelSubmit([FromBody] dynamic mode)
|
{
|
string _guid = mode.guid;
|
string _inFieldValue = mode.inFieldValue;
|
dynamic m = new ExpandoObject();
|
m.outSum = -1;
|
m.outMsg = "";
|
try
|
{
|
string sql = $"UPDATE MES_JJGZ_TIMETYPE SET check_status='{_inFieldValue}',check_date = getdate(), check_user='{_userGuid}' WHERE guid='{_guid}'";
|
int rows = DbHelperSQL.ExecuteSql(sql);
|
m.outSum = rows;
|
m.outMsg = rows > 0 ? "操作成功!" : "未更新任何数据";
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Debug(ToString(), "EditModelSubmit error:" + ex.Message);
|
m.outMsg = ex.Message;
|
m.outSum = -1;
|
return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, ex.Message);
|
}
|
return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "操作成功!");
|
}
|
|
/// <summary>
|
/// 增加或编辑实体
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<ExpandoObject> EditModel([FromBody] dynamic model)
|
{
|
Guid? guid = model.guid; //主键
|
string name = model.name;
|
dynamic mObj = new ExpandoObject();
|
mObj.outMsg = "";
|
mObj.outSum = -1;
|
mObj.outGuid = "";
|
mObj.outNo = "";
|
try
|
{
|
string sql;
|
if (CheckGuid(guid))
|
{
|
sql = $"UPDATE MES_JJGZ_TIMETYPE SET Name='{name}' WHERE guid='{guid}'";
|
}
|
else
|
{
|
guid = Guid.NewGuid();
|
sql = $" declare @userBy nvarchar(20); select top 1 @userBy=[ACCOUNT] from [dbo].[SYS_USER] where guid='{_userGuid}' " +
|
$"INSERT INTO MES_JJGZ_TIMETYPE (guid, CREATE_BY, CREATE_DATE, Name) VALUES ('{guid}',@userBy,GETDATE(), '{name}')";
|
}
|
int rows = DbHelperSQL.ExecuteSql(sql);
|
mObj.outSum = rows;
|
mObj.outGuid = guid.ToString();
|
mObj.outMsg = rows > 0 ? "操作成功!" : "未更新任何数据";
|
}
|
catch (Exception ex)
|
{
|
string msg = ex.Message;
|
if (msg.Contains("UNIQUE KEY") || msg.Contains("重复键值"))
|
{
|
mObj.outMsg = $"类型名称“{name}”已存在,请勿重复添加!";
|
}
|
else
|
{
|
mObj.outMsg = msg;
|
}
|
LogHelper.Debug(ToString(), "EditModel error:" + msg);
|
mObj.outSum = -1;
|
}
|
if (mObj.outSum <= 0)
|
return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Exception, mObj.outMsg);
|
return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Success, mObj.outMsg);
|
}
|
|
/// <summary>
|
/// 删除主表
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<int?> DeleteModel([FromBody] dynamic model)
|
{
|
int? rtnInt = (int)ReturnCode.Default;
|
Guid? guid = model.guid;
|
var _outMsg = "";
|
var _outSum = -1;
|
try
|
{
|
if (CheckGuid(guid))
|
{
|
string sql = $"DELETE FROM MES_JJGZ_TIMETYPE WHERE guid='{guid}'";
|
_outSum = DbHelperSQL.ExecuteSql(sql);
|
_outMsg = _outSum > 0 ? "删除成功!" : "未删除任何数据";
|
}
|
else
|
{
|
_outMsg = "主键不能为空!";
|
_outSum = -1;
|
}
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Debug(ToString(), "DeleteModel error:" + ex.Message);
|
_outMsg = ex.Message;
|
_outSum = -1;
|
}
|
if (_outSum <= 0)
|
return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception, _outMsg);
|
return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Success, _outMsg);
|
}
|
}
|