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 Newtonsoft.Json.Linq;
using static Gs.Toolbox.UtilityHelper;
namespace Gs.JJGZ;
[ApiGroup(ApiGroupNames.JJGZ)]
public class MesJjgzErrorJsController : IRomteService
{
private readonly IHttpContextAccessor _http;
private readonly string _userCode, _userGuid, _orgFids;
public MesJjgzErrorJsController(IHttpContextAccessor httpContextAccessor)
{
_http = httpContextAccessor;
(_userCode, _userGuid, _orgFids) =
GetUserGuidAndOrgGuid(_http);
}
///
/// 读取列表,支持分页
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto> GetListPage([FromBody] dynamic model)
{
int currentPage = model.currentPage;
int everyPageSize = model.everyPageSize;
string sortName = model.sortName;
string keyWhere = model.keyWhere;
SqlParameter[] parameters =
{
new("@inCurrentPage", currentPage),
new("@inEveryPageSize", everyPageSize),
new("@inSortName", sortName),
new("@inSortOrder", ""),
new("@inQueryWhere", keyWhere),
new("@inFid", ""),
new("@inP1", ""),
new("@inP2", ""),
new("@inP3", ""),
new("@inP4", "")
};
var dset = new DataSet();
var _pglist = new PageList
{
total = 0,
everyPageSize = 0,
pages = 0,
list = new List()
};
try
{
dset = DbHelperSQL.RunProcedure("prc_ERRORJS_lst", parameters, "0");
if (dset != null && dset.Tables.Count > 0 &&
dset.Tables[0].Rows.Count > 0) //有数据
{
var intTotal =
int.Parse(dset.Tables[1].Rows[0]["intTotal"].ToString());
var pages = intTotal % everyPageSize != 0
? intTotal / everyPageSize + 1
: intTotal / everyPageSize;
_pglist.total = intTotal;
_pglist.everyPageSize = everyPageSize;
_pglist.pages = pages;
var _dy = dset.Tables[0].TableToDynamicList();
_pglist.list = _dy;
}
}
catch (Exception ex)
{
LogHelper.Debug(ToString(), ex.Message);
return ReturnDto>.QuickReturn(_pglist,
ReturnCode.Exception, ex.Message);
}
return ReturnDto>.QuickReturn(_pglist,
ReturnCode.Success, "读取成功");
}
///
/// 读取
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto GetModel([FromBody] dynamic model)
{
string guid = model.guid.ToString();
dynamic m = new ExpandoObject();
m.list = new List();
m.list2 = new List();
// 假设主表为MES_JJGZ_JS_SALARY,明细表为MES_JJGZ_JS_SALARY_DETAIL
var mainTable = "MES_JJGZ_ERRORJS";
try
{
var 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();
}
var sqlMain1 =
$"SELECT * FROM MES_JJGZ_ERRORJS_DETAIL WHERE pid='{guid}'";
var _tb = DbHelperSQL.Query(sqlMain1);
m.list = _tb.Tables[0].TableToDynamicList();
}
catch (Exception ex)
{
LogHelper.Debug(ToString(), ex.Message);
}
if (m != null)
return ReturnDto.QuickReturn(m, ReturnCode.Success,
"读取成功!");
return ReturnDto.QuickReturn(m, ReturnCode.Default, "读取失败!");
}
///
/// 提交审核反审核
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto EditModelSubmit([FromBody] dynamic mode)
{
string _guid = mode.guid;
string _inFieldValue = mode.inFieldValue;
dynamic m = new ExpandoObject();
m.outSum = -1;
m.outMsg = "";
try
{
// 假设提交就是更新某个字段
var sql =
$"UPDATE MES_JJGZ_ERRORJS SET check_status='{_inFieldValue}',check_date = getdate(), check_user='{_userGuid}' WHERE guid='{_guid}'";
var 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.QuickReturn(m, ReturnCode.Default,
ex.Message);
}
return ReturnDto.QuickReturn(m, ReturnCode.Success, "操作成功!");
}
///
/// 增加或编辑实体
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto EditModel([FromBody] dynamic model)
{
{
Guid? guid = model.guid; //主键
string hourlyType = model.hourlyType; //原因
string errorType = model.errorType; //工单
string errorTime = model.errorTime; //组织
string hourlySalary = model.hourlySalary; //组织
string remark = model.remark; //组织
string DAA001 = model.DAA001; //组织
string DAAType = model.DAAType; //组织
string OrgId = model.OrgId; //组织
var _sb = new StringBuilder();
var _split = "|";
foreach (var m in model.list)
{
string _guid = m.Guid.ToString();
var _line = m.ID + _split
+ m.Staff_Id + _split
+ m.Staff_No + _split
+ m.Staff_Name + _split
+ m.Hour + _split
+ m.Line_No + _split
+ m.Line_Name + _split
+ m.Salary + _split
+ m.Remark + _split
+ (CheckGuid(_guid)
? _guid
: Guid.Empty.ToString());
if (_sb.Length > 0)
_sb.Append("~");
_sb.Append(_line);
}
dynamic mObj = new ExpandoObject();
mObj.outMsg = "";
mObj.outSum = -1;
mObj.outGuid = "";
mObj.outNo = "";
using (var conn = new SqlConnection(DbHelperSQL.strConn))
{
using (var cmd = new SqlCommand("[prc_ERRORJS_edt]", conn))
{
try
{
conn.Open();
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] parameters =
{
new("@outMsg", SqlDbType.NVarChar, 300),
new("@outSum", SqlDbType.Int),
new("@outGuid", SqlDbType.UniqueIdentifier),
new("@outNo", SqlDbType.NVarChar, 300),
new("@inOrderGuid",
CheckGuid(guid) ? guid : DBNull.Value),
new("@inErrorTime", errorTime),
new("@inErrorType", errorType),
new("@inHourlyType", hourlyType),
new("@inHourlySalary", hourlySalary),
new("@inRemark", remark),
new("@inDAA001", DAA001),
new("@inDAAType", DAAType),
new("@inOrgId", OrgId),
new("@inEdtUserGuid", _userGuid),
new("@inLineList", _sb.ToString())
};
parameters[0].Direction = ParameterDirection.Output;
parameters[1].Direction = ParameterDirection.Output;
parameters[2].Direction = ParameterDirection.Output;
parameters[3].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());
mObj.outGuid = parameters[2].Value.ToString();
mObj.outNo = parameters[3].Value.ToString();
}
catch (Exception ex)
{
LogHelper.Debug(ToString(),
"prc_ERRORJS_edt error:" + ex.Message);
mObj.outMsg = ex.Message;
mObj.outSum = -1;
}
finally
{
conn.Close();
}
}
}
if (mObj.outSum <= 0)
return ReturnDto.QuickReturn(mObj,
ReturnCode.Exception, mObj.outMsg);
return ReturnDto.QuickReturn(mObj, ReturnCode.Success,
mObj.outMsg);
}
}
///
/// 删除主表或明细
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto DeleteModel([FromBody] dynamic model)
{
int? rtnInt = (int)ReturnCode.Default;
Guid? guid = model.guid; //到货单主键
string mxGuid = model.mxGuid;
var _outMsg = "";
var _outSum = -1;
try
{
if (CheckGuid(guid))
{
var sql =
$"DELETE FROM MES_JJGZ_ERRORJS WHERE guid='{guid}' DELETE FROM MES_JJGZ_ERRORJS_DETAIL WHERE pid='{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.QuickReturn(rtnInt, ReturnCode.Exception,
_outMsg);
return ReturnDto.QuickReturn(rtnInt, ReturnCode.Success, _outMsg);
}
///
/// 获取计时类型
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto GetTimeType([FromBody] dynamic model)
{
dynamic m = new ExpandoObject();
var mainTable = "MES_JJGZ_TIMETYPE";
try
{
var sqlMain =
"SELECT HourlyType 计时类型,HourlySalary 计时单价 FROM MES_JJGZ_JSSALARY WHERE CHECK_STATUS = 1";
var dsMain = DbHelperSQL.Query(sqlMain);
if (dsMain != null && dsMain.Tables.Count > 0 &&
dsMain.Tables[0].Rows.Count > 0)
{
var _tb = dsMain.Tables[0].TableToDynamicList();
m.list = _tb;
}
}
catch (Exception ex)
{
LogHelper.Debug(ToString(), ex.Message);
}
if (m != null)
return ReturnDto.QuickReturn(m, ReturnCode.Success,
"读取成功!");
return ReturnDto.QuickReturn(m, ReturnCode.Default, "读取失败!");
}
///
/// 获取工单
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto GetWOMDAAInfo([FromBody] dynamic model)
{
dynamic m = new ExpandoObject();
try
{
var sqlMain =
"select daa001 工单号,daa002 产品编码,daa003 产品名称,daa004 产品规格,daa025 工单类型 from WOMDAA";
var dsMain = DbHelperSQL.Query(sqlMain);
if (dsMain != null && dsMain.Tables.Count > 0 &&
dsMain.Tables[0].Rows.Count > 0)
{
var _tb = dsMain.Tables[0].TableToDynamicList();
m.list = _tb;
}
}
catch (Exception ex)
{
LogHelper.Debug(ToString(), ex.Message);
}
if (m != null)
return ReturnDto.QuickReturn(m, ReturnCode.Success,
"读取成功!");
return ReturnDto.QuickReturn(m, ReturnCode.Default, "读取失败!");
}
///
/// 获取工单
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto GetWORKSHOPLINE([FromBody] dynamic model)
{
dynamic m = new ExpandoObject();
try
{
var sqlMain = "select line_no 产线,name 产线名称 from MES_WORKSHOP_LINE";
var dsMain = DbHelperSQL.Query(sqlMain);
if (dsMain != null && dsMain.Tables.Count > 0 &&
dsMain.Tables[0].Rows.Count > 0)
{
var _tb = dsMain.Tables[0].TableToDynamicList();
m.list = _tb;
}
}
catch (Exception ex)
{
LogHelper.Debug(ToString(), ex.Message);
}
if (m != null)
return ReturnDto.QuickReturn(m, ReturnCode.Success,
"读取成功!");
return ReturnDto.QuickReturn(m, ReturnCode.Default, "读取失败!");
}
///
/// 根据用户选择的采购明细guid,读取需要作入库到货单的明细
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto SelectPbaToView(JArray guidList)
{
dynamic m = new ExpandoObject();
try
{
var intArray = guidList.ToObject();
var sbLine = new StringBuilder();
foreach (var str in intArray)
{
if (sbLine.Length > 0)
sbLine.Append(",");
sbLine.Append(str);
}
var sqlMain =
$"select a.id as Staff_Id,Staff_No ,Staff_Name,0 Hour ,d.Line_No Line_No , d.Line_Name Line_Name,0 Salary,''Remark,'' Id from MES_STAFF a left join OA_User b on a.staff_no = b.jobnumber left join Mes_DepartmentToLine d on d.DepartmentId = b.department where a.id in (select line from dbo.fn_split('{sbLine}',','))";
var dsMain = DbHelperSQL.Query(sqlMain);
if (dsMain != null && dsMain.Tables.Count > 0 &&
dsMain.Tables[0].Rows.Count > 0)
{
var _tb = dsMain.Tables[0].TableToDynamicList();
m.list = _tb;
}
}
catch (Exception ex)
{
LogHelper.Debug(ToString(), ex.Message);
}
if (m != null)
return ReturnDto.QuickReturn(m, ReturnCode.Success,
"读取成功!");
return ReturnDto.QuickReturn(m, ReturnCode.Default, "读取失败!");
}
///
/// 根据用户选择的采购明细guid,读取需要作入库到货单的明细
///
///
///
[RequestMethod(RequestMethods.POST)]
public ReturnDto> SelectPba([FromBody] dynamic model)
{
int currentPage = model.currentPage;
int everyPageSize = model.everyPageSize;
string sortName = model.sortName;
string keyWhere = model.keyWhere;
string orgId = model.orgId;
var dset = new DataSet();
try
{
using (var conn = new SqlConnection(DbHelperSQL.strConn))
{
using (var cmd =
new SqlCommand("[prc_item_staff_select]", conn))
{
conn.Open();
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] parameters =
{
new("@inCurrentPage", currentPage),
new("@inEveryPageSize", everyPageSize),
new("@inSortName", sortName),
new("@inSortOrder", ""),
new("@inQueryWhere", keyWhere),
new("@inOrgId", orgId),
new("@inP1", ""),
new("@inP2", "")
};
foreach (var parameter in parameters)
cmd.Parameters.Add(parameter);
using (var dt = new SqlDataAdapter(cmd))
{
dt.Fill(dset, "0");
}
}
conn.Close();
}
}
catch (Exception ex)
{
LogHelper.Debug(ToString(),
"prc_item_staff_select error:" + ex.Message);
return ReturnDto>.QuickReturn(
default(PageList), ReturnCode.Exception, "读取失败");
}
var _pglist = new PageList
{
total = 0,
everyPageSize = 0,
pages = 0,
list = new List()
};
if (dset != null && dset.Tables.Count > 0 &&
dset.Tables[0].Rows.Count > 0) //有数据
{
var intTotal =
int.Parse(dset.Tables[1].Rows[0]["intTotal"].ToString());
var pages = intTotal % everyPageSize != 0
? intTotal / everyPageSize + 1
: intTotal / everyPageSize;
_pglist.total = intTotal;
_pglist.everyPageSize = everyPageSize;
_pglist.pages = pages;
var _dy = dset.Tables[0].TableToDynamicList();
_pglist.list = _dy;
}
return ReturnDto>.QuickReturn(_pglist,
ReturnCode.Success, "读取成功");
}
}