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.Wom.Service; [ApiGroup(ApiGroupNames.WOM)] public class WompbaGxManager : IRomteService { private readonly IHttpContextAccessor _http; private readonly string _userCode, _userGuid, _orgFids; public WompbaGxManager(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_wom_pba_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(); SqlParameter[] parameters = { new("@inMainGuid", guid), new("@inP1", ""), new("@inP2", ""), new("@inP3", ""), new("@inP4", "") }; var dset = new DataSet(); try { dset = DbHelperSQL.RunProcedure("[prc_wom_pbagx_mx]", parameters, "0"); if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0) { var dr = dset.Tables[0].Rows[0]; m = dr.RowToDynamic(); var _tb = dset.Tables[1].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 EditModel([FromBody] dynamic model) { Guid? guid = model.guid; //主键 string bz = model.bz; //备注 string cjId = model.cjId; //车间 string cxId = ""; //产线,用不到了 string jhrs = ""; //计划人数,用不到了 var _sb = new StringBuilder(); var _split = "|"; foreach (var m in model.list) { string _guid = m.Guid.ToString(); var _line = m.AboutGuid + _split + m.LineId + _split + m.Yjkgsj + _split + m.Jhrs + _split + m.Hxsj + _split + m.Bz + _split + m.Blsj + _split + m.Pcsl + _split + m.Yjwgsj + _split + m.GxId + _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_wom_pbagx_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("@inBz", bz), new("@inCjId", cjId), new("@inCxId", cxId), new("@inJhrs", jhrs), 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_wom_pbagx_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); } /// /// 根据物料id获取对应工序 /// /// /// [RequestMethod(RequestMethods.POST)] public ReturnDto> SelectPbaGx([FromBody] dynamic model) { int currentPage = model.Paging.currentPage; int everyPageSize = model.Paging.everyPageSize; string sortName = model.Paging.sortName; string keyWhere = model.Paging.keyWhere; string itemid = model.ItemInfo.itemid; SqlParameter[] parameters = { new("@inCurrentPage", currentPage), new("@inEveryPageSize", everyPageSize), new("@inSortName", sortName), new("@inSortOrder", ""), new("@inQueryWhere", keyWhere), new("@itemID", itemid), new("@inP1", ""), new("@inP2", "") }; var dset = new DataSet(); var _pglist = new PageList { total = 0, everyPageSize = 0, pages = 0, list = new List() }; try { dset = DbHelperSQL.RunProcedure("prc_wom_pba_selectGX", 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, "读取成功"); } /// /// 根据供应商id 读取退货物料 /// /// /// [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 workId = model.workId; var dset = new DataSet(); try { using (var conn = new SqlConnection(DbHelperSQL.strConn)) { using (var cmd = new SqlCommand("[prc_wom_pba_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("@workId", workId), 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_wom_pba_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, "读取成功"); } /// /// 根据用户选择的采购明细guid,读取需要作入库到货单的明细 /// /// /// [RequestMethod(RequestMethods.POST)] public ReturnDto> SelectPbaToView( JArray guidList) { var intArray = guidList.ToObject(); var sbLine = new StringBuilder(); foreach (var str in intArray) { if (sbLine.Length > 0) sbLine.Append(","); sbLine.Append(str); } var lst = new List(); var dset = new DataSet(); using (var conn = new SqlConnection(DbHelperSQL.strConn)) { using (var cmd = new SqlCommand("[prc_wom_pba_select_to_grid]", conn)) { try { conn.Open(); cmd.CommandType = CommandType.StoredProcedure; SqlParameter[] parameters = { new("@inP1", sbLine.ToString()) }; foreach (var parameter in parameters) cmd.Parameters.Add(parameter); using (var dt = new SqlDataAdapter(cmd)) { dt.Fill(dset, "0"); } } catch (Exception ex) { LogHelper.Debug(ToString(), "prc_wom_pba_select_to_grid error:" + ex.Message); } finally { conn.Close(); } } } if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0) //有数据 lst = dset.Tables[0].TableToDynamicList(); return ReturnDto>.QuickReturn(lst, ReturnCode.Success, "读取成功!"); } /// /// 删除主表或明细 /// /// /// [RequestMethod(RequestMethods.POST)] public ReturnDto DeleteModelOrMx([FromBody] dynamic model) { int? rtnInt = (int)ReturnCode.Default; Guid? guid = model.guid; //到货单主键 string mxGuid = model.mxGuid; var _outMsg = ""; var _outSum = -1; using (var conn = new SqlConnection(DbHelperSQL.strConn)) { using (var cmd = new SqlCommand("[prc_wom_pba_del]", conn)) { try { conn.Open(); cmd.CommandType = CommandType.StoredProcedure; SqlParameter[] parameters = { new("@outMsg", SqlDbType.NVarChar, 300), new("@outSum", SqlDbType.Int), new("@inOrderGuid", CheckGuid(guid) ? guid : DBNull.Value), new("@inEdtUserGuid", _userGuid), new("@inMxGuid", mxGuid) }; parameters[0].Direction = ParameterDirection.Output; parameters[1].Direction = ParameterDirection.Output; foreach (var parameter in parameters) cmd.Parameters.Add(parameter); cmd.ExecuteNonQuery(); _outMsg = parameters[0].Value.ToString(); _outSum = int.Parse(parameters[1].Value.ToString()); } catch (Exception ex) { LogHelper.Debug(ToString(), "prc_wom_pba_del error:" + ex.Message); _outMsg = ex.Message; _outSum = -1; } finally { conn.Close(); } } } if (_outSum <= 0) return ReturnDto.QuickReturn(rtnInt, ReturnCode.Exception, _outMsg); return ReturnDto.QuickReturn(rtnInt, ReturnCode.Success, _outMsg); } /// /// 审核 /// /// /// [RequestMethod(RequestMethods.POST)] public ReturnDto EditModelSubmit([FromBody] dynamic mode) { string _guid = mode.guid; dynamic m = new ExpandoObject(); m.outSum = -1; m.outMsg = ""; using (var conn = new SqlConnection(DbHelperSQL.strConn)) { using (var cmd = new SqlCommand("prc_wom_pba_submit", 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("@inFieldValue", 1), new("@in1", ""), new("@in2", "") }; parameters[0].Direction = ParameterDirection.Output; parameters[1].Direction = ParameterDirection.Output; foreach (var parameter in parameters) cmd.Parameters.Add(parameter); cmd.ExecuteNonQuery(); m.outMsg = parameters[0].Value.ToString(); m.outSum = int.Parse(parameters[1].Value.ToString()); } catch (Exception ex) { LogHelper.Debug(ToString(), "prc_wom_pba_submit error:" + ex.Message); m.outMsg = ex.Message; return ReturnDto.QuickReturn(m, ReturnCode.Default, ex.Message); } finally { conn.Close(); } } } return ReturnDto.QuickReturn(m, ReturnCode.Success, "操作成功!"); } /// /// 反审核 /// /// /// [RequestMethod(RequestMethods.POST)] public ReturnDto EditModelSubmitFSH([FromBody] dynamic mode) { string _guid = mode.guid; dynamic m = new ExpandoObject(); m.outSum = -1; m.outMsg = ""; using (var conn = new SqlConnection(DbHelperSQL.strConn)) { using (var cmd = new SqlCommand("Prc_WOM_PBA_FSH", conn)) { try { conn.Open(); cmd.CommandType = CommandType.StoredProcedure; SqlParameter[] parameters = { new("@outMsg", SqlDbType.NVarChar, 300), new("@outSum", SqlDbType.Int), new("@inEdtUserGuid", _userGuid), new("@PI_ID", _guid), //new("@inFieldValue", 1), //new("@in1", ""), //new("@in2", "") }; parameters[0].Direction = ParameterDirection.Output; parameters[1].Direction = ParameterDirection.Output; foreach (var parameter in parameters) cmd.Parameters.Add(parameter); cmd.ExecuteNonQuery(); m.outMsg = parameters[0].Value.ToString(); m.outSum = int.Parse(parameters[1].Value.ToString()); } catch (Exception ex) { LogHelper.Debug(ToString(), "Prc_WOM_PBA_FSH error:" + ex.Message); m.outMsg = ex.Message; return ReturnDto.QuickReturn(m, ReturnCode.Default, ex.Message); } finally { conn.Close(); } } } return ReturnDto.QuickReturn(m, ReturnCode.Success, "操作成功!"); } /// /// 批量处理明细数据 /// /// /// [RequestMethod(RequestMethods.POST)] public ReturnDto BatchProcessDetails([FromBody] dynamic model) { dynamic result = new ExpandoObject(); result.outSum = 0; result.outMsg = ""; try { // 获取请求参数 string operatorGuid = model.operatorGuid?.ToString() ?? ""; string operationType = model.operationType?.ToString() ?? "BatchProcess"; var selectedDetails = model.selectedDetails; if (selectedDetails == null) { result.outMsg = "未接收到要处理的明细数据!"; return ReturnDto.QuickReturn(result, ReturnCode.Default, result.outMsg); } // 构建明细数据字符串,用于传递给存储过程 var _sb = new StringBuilder(); var _split = "|"; int processCount = 0; foreach (var detail in selectedDetails) { string detailGuid = detail.guid?.ToString() ?? ""; string daa002 = detail.daa002?.ToString() ?? ""; string daa003 = detail.daa003?.ToString() ?? ""; string daa005 = detail.daa005?.ToString() ?? ""; string daa010 = detail.daa010?.ToString() ?? ""; // 验证必要字段 if (string.IsNullOrEmpty(detailGuid)) continue; // 构建明细行数据字符串 var _line = detailGuid + _split + daa002 + _split + daa003 + _split + daa005 + _split + daa010 + _split + operationType + _split + _userCode + _split + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if (_sb.Length > 0) _sb.Append("~"); _sb.Append(_line); processCount++; } if (processCount == 0) { result.outMsg = "没有有效的明细数据需要处理!"; return ReturnDto.QuickReturn(result, ReturnCode.Default, result.outMsg); } // 调用存储过程进行批量处理 SqlParameter[] parameters = { new("@inOperatorGuid", operatorGuid), new("@inOperationType", operationType), new("@inDetailsData", _sb.ToString()), new("@inUserCode", _userCode), new("@inUserGuid", _userGuid), new("@inOrgFids", _orgFids), new("@outSum", SqlDbType.Int) { Direction = ParameterDirection.Output }, new("@outMsg", SqlDbType.NVarChar, 500) { Direction = ParameterDirection.Output } }; var dset = new DataSet(); dset = DbHelperSQL.RunProcedure("prc_wom_pbagx_batch_process", parameters, "0"); // 获取输出参数 int outSum = Convert.ToInt32(parameters[6].Value ?? 0); string outMsg = parameters[7].Value?.ToString() ?? ""; result.outSum = outSum; result.outMsg = outMsg; if (outSum > 0) { return ReturnDto.QuickReturn(result, ReturnCode.Success, outMsg); } else { return ReturnDto.QuickReturn(result, ReturnCode.Default, outMsg); } } catch (Exception ex) { result.outMsg = "批量处理明细时发生异常:" + ex.Message; return ReturnDto.QuickReturn(result, ReturnCode.Exception, result.outMsg); } } }