|
|
using ibk.IPD.Common;
|
|
|
using ibk.IPD.Entity;
|
|
|
using ibk.IPD.Entity.IPD_MR.HotRoll;
|
|
|
using ibk.IPD.Entity.IPD_MR.HotRoll.QueryArgs;
|
|
|
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年05月06日
|
|
|
* 创建者: 李跃升
|
|
|
* Copy Right: 北京科技大学设计研究院有限公司
|
|
|
********************************************************/
|
|
|
namespace ibk.IPD.Controller.IPD_MR.HotRoll
|
|
|
{
|
|
|
[RoutePrefix("ipd/ipdMr")]
|
|
|
public class LongTransRollingLimitController : ApiController
|
|
|
{
|
|
|
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 参数校验
|
|
|
/// </summary>
|
|
|
/// <param name="cncs"></param>
|
|
|
/// /// <param name="result"></param>
|
|
|
/// <returns>是否通过参数校验</returns>
|
|
|
public bool ParameterCalibration(LONG_TRANS_ROLLING_LIMIT cncs, RequestEntity result)
|
|
|
{
|
|
|
#region 参数判断
|
|
|
|
|
|
if (string.IsNullOrEmpty(cncs.PLT) || cncs.PLT.Length > 2)
|
|
|
{
|
|
|
result.msg = "工厂代码不可为空且长度不可超过2!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.SLAB_THICK))
|
|
|
if (!CommonUtils.IsNumber(cncs.SLAB_THICK) || cncs.SLAB_THICK.Length > 8)
|
|
|
{
|
|
|
result.msg = "板坯厚度是长度不可超过8的数字!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.SLAB_WIDTH_MIN))
|
|
|
if (!CommonUtils.IsNumber(cncs.SLAB_WIDTH_MIN) || cncs.SLAB_WIDTH_MIN.Length > 6)
|
|
|
{
|
|
|
result.msg = "板坯最小宽度是长度不可超过6的数字!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.SLAB_WIDTH_MAX))
|
|
|
if (!CommonUtils.IsNumber(cncs.SLAB_WIDTH_MAX) || cncs.SLAB_WIDTH_MAX.Length > 6)
|
|
|
{
|
|
|
result.msg = "板坯最大宽度是长度不可超过6的数字!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.THK_MAX_ALLOW))
|
|
|
if (!CommonUtils.IsNumber(cncs.THK_MAX_ALLOW) || cncs.THK_MAX_ALLOW.Length > 8)
|
|
|
{
|
|
|
result.msg = "允许轧制最大厚度是长度不可超过8的数字!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取主键的条件
|
|
|
/// </summary>
|
|
|
/// <param name="primaryKeyEntity"></param>
|
|
|
/// <returns>AND 开头的 主键条件字符串</returns>
|
|
|
public string GetPrimaryKeyString(LONG_TRANS_ROLLING_LIMIT primaryKeyEntity)
|
|
|
{
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
//if (!string.IsNullOrWhiteSpace(primaryKeyEntity.APLY_ITEM))
|
|
|
//因为主键自增不会出现主键重复的情况,所以将主键判断修改为数据重复
|
|
|
strSql.AppendLine(" AND PLT = '" + primaryKeyEntity.PLT + "'");
|
|
|
strSql.AppendLine(" AND SLAB_THICK = '" + primaryKeyEntity.SLAB_THICK + "'");
|
|
|
strSql.AppendLine(" AND SLAB_WIDTH_MIN = '" + primaryKeyEntity.SLAB_WIDTH_MIN + "'");
|
|
|
strSql.AppendLine(" AND SLAB_WIDTH_MAX = '" + primaryKeyEntity.SLAB_WIDTH_MAX + "'");
|
|
|
strSql.AppendLine(" AND THK_MAX_ALLOW = '" + primaryKeyEntity.THK_MAX_ALLOW + "'");
|
|
|
return strSql.ToString();
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取主键查询的sql
|
|
|
/// </summary>
|
|
|
/// <param name="checkEntity"></param>
|
|
|
/// <returns>主键查询sql</returns>
|
|
|
public string GetCheckString(LONG_TRANS_ROLLING_LIMIT checkEntity)
|
|
|
{
|
|
|
string strSql = "SELECT * FROM LONG_TRANS_ROLLING_LIMIT WHERE 1=1 " + GetPrimaryKeyString(checkEntity);
|
|
|
return strSql;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询接口
|
|
|
/// </summary>
|
|
|
/// <param name="queryArgs"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("hotRoll/getLongTransRollingLimit")]
|
|
|
public RequestEntity GetLongTransRollingLimit(LongTransRollingLimitQueryArgs queryArgs)
|
|
|
{
|
|
|
RequestEntity result = new RequestEntity(); //声明返回参数实体类
|
|
|
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
|
|
|
DataTable dtCheck = new DataTable();
|
|
|
|
|
|
//查询字段
|
|
|
//PLT , SLAB_THICK , SLAB_WIDTH_MIN , SLAB_WIDTH_MAX , THK_MAX_ALLOW
|
|
|
strSql.AppendLine("SELECT PK ,PLT , SLAB_THICK , SLAB_WIDTH_MIN , SLAB_WIDTH_MAX , THK_MAX_ALLOW ,TO_DATE(NVL(INS_DATE, '19910101') || NVL(INS_TIME, '000000'), '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 LONG_TRANS_ROLLING_LIMIT WHERE 1 = 1 ");
|
|
|
if (queryArgs != null)
|
|
|
{
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.PLT)) strSql.AppendLine(" AND PLT LIKE '%" + queryArgs.PLT + "%'");
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.START_SLAB_THICK) && CommonUtils.IsNumber(queryArgs.START_SLAB_THICK)) strSql.AppendLine(" AND SLAB_THICK >=" + queryArgs.START_SLAB_THICK);
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.END_SLAB_THICK) && CommonUtils.IsNumber(queryArgs.END_SLAB_THICK)) strSql.AppendLine(" AND SLAB_THICK <=" + queryArgs.END_SLAB_THICK);
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.SLAB_WIDTH_MIN) && CommonUtils.IsNumber(queryArgs.SLAB_WIDTH_MIN)) strSql.AppendLine(" AND SLAB_WIDTH_MIN >=" + queryArgs.SLAB_WIDTH_MIN);
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.SLAB_WIDTH_MAX) && CommonUtils.IsNumber(queryArgs.SLAB_WIDTH_MAX)) strSql.AppendLine(" AND SLAB_WIDTH_MAX <=" + queryArgs.SLAB_WIDTH_MAX);
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.START_THK_MAX_ALLOW) && CommonUtils.IsNumber(queryArgs.START_THK_MAX_ALLOW)) strSql.AppendLine(" AND THK_MAX_ALLOW >=" + queryArgs.START_THK_MAX_ALLOW);
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.END_THK_MAX_ALLOW) && CommonUtils.IsNumber(queryArgs.END_THK_MAX_ALLOW)) strSql.AppendLine(" AND THK_MAX_ALLOW <=" + queryArgs.END_THK_MAX_ALLOW);
|
|
|
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 ,'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 ,'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 INS_DATE DESC ");
|
|
|
dtCheck = db.Query(strSql.ToString());
|
|
|
result.data = db.Query<LONG_TRANS_ROLLING_LIMIT>(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("GetLongTransRollingLimit 报错", ex);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 添加接口
|
|
|
/// </summary>
|
|
|
/// <param name="insertModel"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("hotRoll/addLongTransRollingLimit")]
|
|
|
public RequestEntity AddLongTransRollingLimit(LONG_TRANS_ROLLING_LIMIT insertModel)
|
|
|
{
|
|
|
RequestEntity result = new RequestEntity();
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
try
|
|
|
{
|
|
|
#region 参数判断
|
|
|
if (!ParameterCalibration(insertModel, result))
|
|
|
return result;
|
|
|
#endregion
|
|
|
|
|
|
insertModel.INS_DATE = dtNow.ToString("yyyyMMdd");
|
|
|
insertModel.INS_TIME = dtNow.ToString("HHmmss");
|
|
|
|
|
|
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
|
|
|
{
|
|
|
// 执行数据重复查询
|
|
|
DataTable dtCheck = db.Query(GetCheckString(insertModel));
|
|
|
|
|
|
if (dtCheck.Rows.Count > 0) // 若数据库中存在则返回错误码0并msg提示用户
|
|
|
{
|
|
|
result.msg = "数据已存在,请确认后重试!";
|
|
|
result.code = "0";
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
if (db.Insert<LONG_TRANS_ROLLING_LIMIT>(insertModel) > 0)
|
|
|
{
|
|
|
result.msg = "操作成功";
|
|
|
result.code = "1";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
result.msg = "数据库错误!";
|
|
|
result.code = "0";
|
|
|
logger.Error("AddLongTransRollingLimit 报错 : ", ex);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新接口
|
|
|
/// </summary>
|
|
|
/// <param name="requestData"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("hotRoll/updLongTransRollingLimit")]
|
|
|
public RequestEntity UpdLongTransRollingLimit(IList<LONG_TRANS_ROLLING_LIMIT> 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 参数判断
|
|
|
if (!ParameterCalibration(requestData[1], result))
|
|
|
return result;
|
|
|
#endregion
|
|
|
try
|
|
|
{
|
|
|
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
|
|
|
{
|
|
|
// 执行主键重复查询
|
|
|
dtCheck = db.Query(GetCheckString(requestData[1]));
|
|
|
dtCheckSelf = db.Query(GetCheckString(requestData[0]));
|
|
|
|
|
|
if (dtCheck.Rows.Count > 0 && !CommonUtils.CompareDataTable(dtCheck, dtCheckSelf)) // 若数据库中存在则返回错误码0并msg提示用户
|
|
|
{
|
|
|
result.msg = "相同数据已存在,请确认后重试!";
|
|
|
result.code = "0";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//更新哪些字段
|
|
|
//PLT , SLAB_THICK , SLAB_WIDTH_MIN , SLAB_WIDTH_MAX , THK_MAX_ALLOW
|
|
|
if (db.Execute("UPDATE LONG_TRANS_ROLLING_LIMIT SET " + string.Format(" PLT = '{0}' , SLAB_THICK = '{1}' , SLAB_WIDTH_MIN = '{2}' ,SLAB_WIDTH_MAX = '{3}',THK_MAX_ALLOW = '{4}' , UPD_DATE = '{5}' , UPD_TIME='{6}',UPD_EMP = '{7}' WHERE 1 = 1 ",
|
|
|
requestData[1].PLT, requestData[1].SLAB_THICK, requestData[1].SLAB_WIDTH_MIN, requestData[1].SLAB_WIDTH_MAX, requestData[1].THK_MAX_ALLOW, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP) +
|
|
|
//根据主键字段可以确定唯一数据即要修改的数据
|
|
|
string.Format(" AND PK = {0}", requestData[0].PK)) > 0)
|
|
|
{
|
|
|
result.msg = "操作成功";
|
|
|
result.code = "1";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.msg = "数据未发生改变,请确认后重试!";
|
|
|
result.code = "0";
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
result.msg = "数据库错误!";
|
|
|
result.code = "0";
|
|
|
logger.Error("UpdLongTransRollingLimit 报错", ex);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除接口
|
|
|
/// </summary>
|
|
|
/// <param name="delModel"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("hotRoll/delLongTransRollingLimit")]
|
|
|
public RequestEntity DelLongTransRollingLimit(LONG_TRANS_ROLLING_LIMIT delModel)
|
|
|
{
|
|
|
RequestEntity result = new RequestEntity();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
strSql.AppendLine("DELETE FROM LONG_TRANS_ROLLING_LIMIT WHERE 1=1 AND");
|
|
|
strSql.AppendLine(string.Format("PK = {0}", delModel.PK));
|
|
|
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
|
|
|
{
|
|
|
db.Execute(strSql.ToString()); // 执行删除数据操作
|
|
|
result.msg = "操作成功";
|
|
|
result.code = "1";
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
result.msg = "数据库错误!";
|
|
|
result.code = "0";
|
|
|
logger.Error("DelLongTransRollingLimit 报错", ex);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
}
|