|
|
|
|
using ibk.IPD.Common;
|
|
|
|
|
using ibk.IPD.Entity;
|
|
|
|
|
using ibk.IPD.Entity.IpdMr.StdMgt;
|
|
|
|
|
using log4net;
|
|
|
|
|
using SOA.Objects;
|
|
|
|
|
using SOA.Persistent;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Web.Http;
|
|
|
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
|
* 简 介:南钢炼钢制造规范管理
|
|
|
|
|
* 炉次编制量标准维护后端接口
|
|
|
|
|
* 版本号:V1.0
|
|
|
|
|
* 日 期:2022年03月10日
|
|
|
|
|
* 创建者: 李跃升
|
|
|
|
|
* Copy Right: 北京科技大学设计研究院有限公司
|
|
|
|
|
********************************************************/
|
|
|
|
|
namespace ibk.IPD.Controller
|
|
|
|
|
{
|
|
|
|
|
[RoutePrefix("ipd/ipdMr")]
|
|
|
|
|
public class MeltOrgController : ApiController
|
|
|
|
|
{
|
|
|
|
|
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="queryArgs"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("stdMgt/getMeltOrg")]
|
|
|
|
|
public RequestEntity GetMeltOrg(EpChargeS2QueryArgs queryArgs)
|
|
|
|
|
{
|
|
|
|
|
RequestEntity result = new RequestEntity(); //声明返回参数实体类
|
|
|
|
|
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
|
|
|
|
|
|
|
|
|
|
//查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss
|
|
|
|
|
strSql.AppendLine("SELECT PLT,PRC_LINE,MLT_TOT_PROC_CD,MINI,MAXI,RETURN_RATIO,to_date(INS_DATE || INS_TIME,'yyyy-mm-dd hh24:mi:ss') as INS_DATE,INS_TIME,INS_EMP,to_date(UPD_DATE || UPD_TIME,'yyyy-mm-dd hh24:mi:ss') as UPD_DATE,UPD_TIME,UPD_EMP FROM EP_CHARGE_S2 WHERE 1=1");
|
|
|
|
|
if (queryArgs != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.PLT)) strSql.AppendLine(" AND PLT LIKE '%" + queryArgs.PLT + "%'");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.PRC_LINE)) strSql.AppendLine(" AND PRC_LINE LIKE '%" + queryArgs.PRC_LINE + "%'");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.MLT_TOT_PROC_CD)) strSql.AppendLine(" AND MLT_TOT_PROC_CD LIKE '%" + queryArgs.MLT_TOT_PROC_CD + "%'");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.MINI) && CommonUtils.IsNumber(queryArgs.MINI)) strSql.AppendLine(" AND MINI >= " + queryArgs.MINI );
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.MAXI) && CommonUtils.IsNumber(queryArgs.MAXI)) strSql.AppendLine(" AND MAXI <= " + queryArgs.MAXI );
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.START_RETURN_RATIO) &&CommonUtils.IsNumber(queryArgs.START_RETURN_RATIO) ) strSql.AppendLine(" AND RETURN_RATIO >= " + queryArgs.START_RETURN_RATIO);
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.END_RETURN_RATIO)&& CommonUtils.IsNumber(queryArgs.END_RETURN_RATIO)) strSql.AppendLine(" AND RETURN_RATIO <= " + queryArgs.END_RETURN_RATIO);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(CommonUtils.ObjectToStr(queryArgs.START_TIME)) && CommonUtils.ObjectToStr(queryArgs.START_TIME) != "0001/1/1 0:00:00") strSql.AppendLine(" AND to_date(INS_DATE || INS_TIME,'yyyy-mm-dd hh24:mi:ss') >= to_date('" + CommonUtils.ObjectToStr(queryArgs.START_TIME) + "','yyyy-mm-dd hh24:mi:ss')");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(CommonUtils.ObjectToStr(queryArgs.END_TIME)) && CommonUtils.ObjectToStr(queryArgs.END_TIME) != "0001/1/1 0:00:00") strSql.AppendLine(" AND to_date(INS_DATE || INS_TIME,'yyyy-mm-dd hh24:mi:ss') <= to_date('" + CommonUtils.ObjectToStr(queryArgs.END_TIME) + "','yyyy-mm-dd hh24:mi:ss')");
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//开启数据库连接查询数据
|
|
|
|
|
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
|
|
|
|
|
{
|
|
|
|
|
strSql.AppendLine("Order By PRC_LINE ");
|
|
|
|
|
result.data = db.Query<EP_CHARGE_S2>(strSql.ToString());
|
|
|
|
|
DataTable dtCheck = db.Query(strSql.ToString());
|
|
|
|
|
if (dtCheck.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "操作成功!";
|
|
|
|
|
result.code = "1";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.msg = "未找到查询所需数据!";
|
|
|
|
|
result.code = "1";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "数据库错误!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
logger.Error("GetMeltOrg 报错 : ", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="insertModel"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("stdMgt/addMeltOrg")]
|
|
|
|
|
public RequestEntity AddMeltOrg(EP_CHARGE_S2 insertModel)
|
|
|
|
|
{
|
|
|
|
|
RequestEntity result = new RequestEntity();
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#region 不可为空字段判断
|
|
|
|
|
//PLT, PRC_LINE, MLT_TOT_PROC_CD, MINI, MAXI, RETURN_RATIO
|
|
|
|
|
if (string.IsNullOrEmpty(insertModel.PLT) || insertModel.PLT.Length > 2)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "工厂不可为空且长度不可超过2!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(insertModel.PRC_LINE) || insertModel.PRC_LINE.Length > 1)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "机号不可为空且长度不可超过1!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(insertModel.MLT_TOT_PROC_CD) || insertModel.MLT_TOT_PROC_CD.Length > 8)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "炼钢工艺流程不可为空且长度不可超过8!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(insertModel.MINI))
|
|
|
|
|
if (insertModel.MINI.Length > 15 || !CommonUtils.IsNumber(insertModel.MINI))
|
|
|
|
|
{
|
|
|
|
|
result.msg = "下限长度不可超过15或不是数字!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(insertModel.MAXI))
|
|
|
|
|
if (insertModel.MAXI.Length > 15 || !CommonUtils.IsNumber(insertModel.MAXI))
|
|
|
|
|
{
|
|
|
|
|
result.msg = "上限长度不可超过15或不是数字!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(insertModel.RETURN_RATIO))
|
|
|
|
|
if (insertModel.RETURN_RATIO.Length > 5 || !CommonUtils.IsNumber(insertModel.RETURN_RATIO))
|
|
|
|
|
{
|
|
|
|
|
result.msg = "收得率长度不可超过5或不是数字!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
// 拼接主键重复check查询语句
|
|
|
|
|
strSql.AppendLine("SELECT * FROM EP_CHARGE_S2 WHERE 1=1 ");
|
|
|
|
|
strSql.AppendLine(string.Format("AND PLT = '{0}' AND PRC_LINE = '{1}' AND MLT_TOT_PROC_CD = '{2}' ", insertModel.PLT, insertModel.PRC_LINE, insertModel.MLT_TOT_PROC_CD));
|
|
|
|
|
|
|
|
|
|
insertModel.INS_DATE = dtNow.ToString("yyyyMMdd");
|
|
|
|
|
insertModel.INS_TIME = dtNow.ToString("HHmmss");
|
|
|
|
|
|
|
|
|
|
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
|
|
|
|
|
{
|
|
|
|
|
// 执行主键重复查询
|
|
|
|
|
DataTable dtCheck = db.Query(strSql.ToString());
|
|
|
|
|
|
|
|
|
|
if (dtCheck.Rows.Count > 0) // 若数据库中存在则返回错误码0并msg提示用户
|
|
|
|
|
{
|
|
|
|
|
result.msg = "数据已存在,请确认后重试!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (db.Insert<EP_CHARGE_S2>( insertModel) > 0)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "操作成功";
|
|
|
|
|
result.code = "1";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "数据库错误!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
logger.Error("AddMeltOrg 报错 : ", ex);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="requestData"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("stdMgt/updMeltOrg")]
|
|
|
|
|
public RequestEntity UpdMeltOrg(IList<EP_CHARGE_S2> requestData)
|
|
|
|
|
{
|
|
|
|
|
RequestEntity result = new RequestEntity();
|
|
|
|
|
DataTable dtCheck = new DataTable();
|
|
|
|
|
DataTable dtCheckSelf = new DataTable();
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
StringBuilder strSqlSelf = new StringBuilder();
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
requestData[1].UPD_DATE = dtNow.ToString("yyyyMMdd");
|
|
|
|
|
requestData[1].UPD_TIME = dtNow.ToString("HHmmss");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 不可为空字段判断
|
|
|
|
|
//PLT, PRC_LINE, MLT_TOT_PROC_CD, MINI, MAXI, RETURN_RATIO
|
|
|
|
|
if (string.IsNullOrEmpty(requestData[1].PLT) || requestData[1].PLT.Length > 2)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "工厂不可为空且长度不可超过2!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(requestData[1].PRC_LINE) || requestData[1].PRC_LINE.Length > 1)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "机号不可为空且长度不可超过1!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(requestData[1].MLT_TOT_PROC_CD) || requestData[1].MLT_TOT_PROC_CD.Length > 8)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "炼钢工艺流程不可为空且长度不可超过8!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(requestData[1].MINI))
|
|
|
|
|
if (requestData[1].MINI.Length > 15 || !CommonUtils.IsNumber(requestData[1].MINI))
|
|
|
|
|
{
|
|
|
|
|
result.msg = "下限长度不可超过15或不是数字!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(requestData[1].MAXI))
|
|
|
|
|
if (requestData[1].MAXI.Length > 15 || !CommonUtils.IsNumber(requestData[1].MAXI))
|
|
|
|
|
{
|
|
|
|
|
result.msg = "上限长度不可超过15或不是数字!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(requestData[1].RETURN_RATIO))
|
|
|
|
|
if (requestData[1].RETURN_RATIO.Length > 5 || !CommonUtils.IsNumber(requestData[1].RETURN_RATIO))
|
|
|
|
|
{
|
|
|
|
|
result.msg = "收得率长度不可超过5或不是数字!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// 查询是否有主键相同数据
|
|
|
|
|
//PLT, PRC_LINE, MLT_TOT_PROC_CD
|
|
|
|
|
//, MINI , MAXI , RETURN_RATIO
|
|
|
|
|
strSql.AppendLine("SELECT * FROM EP_CHARGE_S2 WHERE 1=1 ");
|
|
|
|
|
strSql.AppendLine(string.Format("AND PLT = '{0}' AND PRC_LINE = '{1}' AND MLT_TOT_PROC_CD = '{2}' ", requestData[1].PLT, requestData[1].PRC_LINE, requestData[1].MLT_TOT_PROC_CD));
|
|
|
|
|
|
|
|
|
|
strSqlSelf.AppendLine("SELECT * FROM EP_CHARGE_S2 WHERE 1=1 ");
|
|
|
|
|
strSqlSelf.AppendLine(string.Format("AND PLT = '{0}' AND PRC_LINE = '{1}' AND MLT_TOT_PROC_CD = '{2}' ", requestData[0].PLT, requestData[0].PRC_LINE, requestData[0].MLT_TOT_PROC_CD));
|
|
|
|
|
// 执行主键重复查询
|
|
|
|
|
dtCheck = db.Query(strSql.ToString());
|
|
|
|
|
dtCheckSelf = db.Query(strSqlSelf.ToString());
|
|
|
|
|
|
|
|
|
|
if (dtCheck.Rows.Count > 0 && !CommonUtils.CompareDataTable(dtCheck, dtCheckSelf)) // 若数据库中存在则返回错误码0并msg提示用户
|
|
|
|
|
{
|
|
|
|
|
result.msg = "数据已存在,请确认后重试!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//更新哪些字段
|
|
|
|
|
if (db.Execute("UPDATE EP_CHARGE_S2 SET " + string.Format(" PLT = '{0}' , PRC_LINE = '{1}' , MLT_TOT_PROC_CD = '{2}' , MINI = '{3}' , MAXI = '{4}' , RETURN_RATIO = '{5}', UPD_DATE = '{6}',UPD_TIME='{7}',UPD_EMP = '{8}' ", requestData[1].PLT, requestData[1].PRC_LINE, requestData[1].MLT_TOT_PROC_CD, requestData[1].MINI, requestData[1].MAXI, requestData[1].RETURN_RATIO, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP) +
|
|
|
|
|
//根据主键字段可以确定唯一数据即要修改的数据
|
|
|
|
|
string.Format("WHERE 1=1 AND PLT = '{0}' AND PRC_LINE = '{1}' AND MLT_TOT_PROC_CD = '{2}' ", requestData[0].PLT, requestData[0].PRC_LINE, requestData[0].MLT_TOT_PROC_CD)) > 0)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "操作成功";
|
|
|
|
|
result.code = "1";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.msg = "数据未发生改变,请确认后重试!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "数据库错误!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
logger.Error("UpdMeltOrg 报错", ex);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="delModel"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("stdMgt/delMeltOrg")]
|
|
|
|
|
public RequestEntity DelMeltOrg(EP_CHARGE_S2 delModel)
|
|
|
|
|
{
|
|
|
|
|
RequestEntity result = new RequestEntity();
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 拼接主键
|
|
|
|
|
//PLT, PRC_LINE, MLT_TOT_PROC_CD
|
|
|
|
|
strSql.AppendLine("DELETE FROM EP_CHARGE_S2 WHERE 1=1 ");
|
|
|
|
|
strSql.AppendLine(string.Format("AND PLT = '{0}' AND PRC_LINE = '{1}' AND MLT_TOT_PROC_CD = '{2}' ", delModel.PLT, delModel.PRC_LINE, delModel.MLT_TOT_PROC_CD));
|
|
|
|
|
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
|
|
|
|
|
{
|
|
|
|
|
// 执行删除数据操作
|
|
|
|
|
if (db.Execute(strSql.ToString()) > 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
result.msg = "操作成功";
|
|
|
|
|
result.code = "1";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
result.msg = "数据未删除";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "数据库错误!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
logger.Error("DelMeltOrg 报错", ex);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|