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 System.Data;
|
using System.Data.SqlClient;
|
using System.Dynamic;
|
using System.Text;
|
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);
|
}
|
|
|
/// <summary>
|
/// 读取列表,支持分页
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<PageList<dynamic>> 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<dynamic>
|
{
|
total = 0,
|
everyPageSize = 0,
|
pages = 0,
|
list = new List<dynamic>()
|
};
|
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<PageList<dynamic>>.QuickReturn(_pglist,
|
ReturnCode.Exception, ex.Message);
|
}
|
return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist,
|
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();
|
m.list = new List<dynamic>();
|
m.list2 = new List<dynamic>();
|
// 假设主表为MES_JJGZ_JS_SALARY,明细表为MES_JJGZ_JS_SALARY_DETAIL
|
string mainTable = "MES_JJGZ_ERRORJS";
|
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();
|
}
|
|
string 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<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_ERRORJS 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 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<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; //到货单主键
|
string mxGuid = model.mxGuid;
|
var _outMsg = "";
|
var _outSum = -1;
|
try
|
{
|
if (CheckGuid(guid))
|
{
|
string 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<int>.QuickReturn(rtnInt, ReturnCode.Exception, _outMsg);
|
return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Success, _outMsg);
|
}
|
|
/// <summary>
|
/// 获取计时类型
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<ExpandoObject> GetTimeType([FromBody] dynamic model)
|
{
|
dynamic m = new ExpandoObject();
|
string mainTable = "MES_JJGZ_TIMETYPE";
|
try
|
{
|
string 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<dynamic>.QuickReturn(m, ReturnCode.Success, "读取成功!");
|
return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
|
}
|
|
/// <summary>
|
/// 获取工单
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<ExpandoObject> GetWOMDAAInfo([FromBody] dynamic model)
|
{
|
dynamic m = new ExpandoObject();
|
try
|
{
|
string 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<dynamic>.QuickReturn(m, ReturnCode.Success, "读取成功!");
|
return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
|
}
|
|
/// <summary>
|
/// 获取工单
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<ExpandoObject> GetWORKSHOPLINE([FromBody] dynamic model)
|
{
|
dynamic m = new ExpandoObject();
|
try
|
{
|
string 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<dynamic>.QuickReturn(m, ReturnCode.Success, "读取成功!");
|
return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
|
}
|
|
/// <summary>
|
/// 根据用户选择的采购明细guid,读取需要作入库到货单的明细
|
/// </summary>
|
/// <param name="query"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<ExpandoObject> SelectPbaToView(JArray guidList)
|
{
|
dynamic m = new ExpandoObject();
|
try
|
{
|
var intArray = guidList.ToObject<string[]>();
|
var sbLine = new StringBuilder();
|
foreach (var str in intArray)
|
{
|
if (sbLine.Length > 0)
|
sbLine.Append(",");
|
sbLine.Append(str);
|
}
|
string 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.ToString()}',','))";
|
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<dynamic>.QuickReturn(m, ReturnCode.Success, "读取成功!");
|
return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
|
}
|
|
/// <summary>
|
/// 根据用户选择的采购明细guid,读取需要作入库到货单的明细
|
/// </summary>
|
/// <param name="query"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<PageList<dynamic>> 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<PageList<dynamic>>.QuickReturn(
|
default(PageList<dynamic>), ReturnCode.Exception, "读取失败");
|
}
|
|
var _pglist = new PageList<dynamic>
|
{
|
total = 0,
|
everyPageSize = 0,
|
pages = 0,
|
list = new List<dynamic>()
|
};
|
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<PageList<dynamic>>.QuickReturn(_pglist,
|
ReturnCode.Success, "读取成功");
|
}
|
}
|