using System.Data;
|
using System.Data.SqlClient;
|
using System.Dynamic;
|
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.Wom.WorkService
|
{
|
|
[ApiGroup(ApiGroupNames.WOM)]
|
public class WorkWeightController : IRomteService
|
{
|
private readonly IHttpContextAccessor _http;
|
private readonly string _userCode, _userGuid, _orgFids;
|
|
public WorkWeightController(IHttpContextAccessor httpContextAccessor)
|
{
|
_http = httpContextAccessor;
|
(_userCode, _userGuid, _orgFids) =
|
GetUserGuidAndOrgGuid(_http);
|
}
|
|
|
/// <summary>
|
/// 读取称重列表
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<List<dynamic>> GetModelList([FromBody] dynamic model)
|
{
|
string lineId = model.lineId;
|
List<dynamic> lst = new List<dynamic>();
|
var dset = new DataSet();
|
try
|
{
|
SqlParameter[] parameters =
|
{
|
new("@inLineId",lineId)
|
};
|
dset = DbHelperSQL.RunProcedure("work_weight_lst", parameters, "0");
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Debug(ToString(),
|
"work_weight_lst error:" + ex.Message);
|
}
|
if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)
|
lst = dset.Tables[0].TableToDynamicList();
|
return ReturnDto<List<dynamic>>.QuickReturn(lst, ReturnCode.Success,
|
"读取成功!");
|
}
|
|
|
/// <summary>
|
/// 增加或编辑实体
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
[RequestMethod(RequestMethods.POST)]
|
public ReturnDto<ExpandoObject> EditModel([FromBody] dynamic model)
|
{
|
string lineId = model.lineId;
|
string realWeight = model.realWeight;
|
string realWeightTxt=model.realWeightTxt;
|
dynamic mObj = new ExpandoObject();
|
mObj.outMsg = "";
|
mObj.outSum = -1;
|
using (var conn = new SqlConnection(DbHelperSQL.strConn))
|
{
|
using (var cmd = new SqlCommand("[work_weight_add]", conn))
|
{
|
try
|
{
|
conn.Open();
|
cmd.CommandType = CommandType.StoredProcedure;
|
SqlParameter[] parameters =
|
{
|
new("@outMsg", SqlDbType.NVarChar, 300),
|
new("@outSum", SqlDbType.Int),
|
new("@lineId", lineId),
|
new("@realWeight", realWeight),
|
new("@realWeightTxt", realWeightTxt),
|
new("@inEdtUserGuid", _userGuid),
|
};
|
parameters[0].Direction = ParameterDirection.Output;
|
parameters[1].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());
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Debug(ToString(),
|
"work_weight_add 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);
|
}
|
}
|
}
|