|
|
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年04月22日
|
|
|
* 创建者: 李跃升
|
|
|
* Copy Right: 北京科技大学设计研究院有限公司
|
|
|
********************************************************/
|
|
|
namespace ibk.IPD.Controller.IPD_MR.HotRoll
|
|
|
{
|
|
|
[RoutePrefix("ipd/ipdMr")]
|
|
|
public class CompressionRatioController : 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(QP_PROD_RATIO 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.STDSPEC) || cncs.STDSPEC.Length > 60)
|
|
|
{
|
|
|
result.msg = "标准编号不可为空且长度不可超过60!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(cncs.DELIVERY_STATUS) || cncs.DELIVERY_STATUS.Length > 15)
|
|
|
{
|
|
|
result.msg = "交货状态不可为空且长度不可超过15!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.IMPACT_TMP_MIN))
|
|
|
if (!CommonUtils.IsNumber(cncs.IMPACT_TMP_MIN) || cncs.IMPACT_TMP_MIN.Length > 3)
|
|
|
{
|
|
|
result.msg = "冲击温度下限是长度不可超过3的数字!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.IMPACT_TMP_MAX))
|
|
|
if (!CommonUtils.IsNumber(cncs.IMPACT_TMP_MAX) || cncs.IMPACT_TMP_MAX.Length > 3)
|
|
|
{
|
|
|
result.msg = "冲击温度上线是长度不可超过3的数字!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(cncs.ORD_THK_MIN) || !CommonUtils.IsNumber(cncs.ORD_THK_MIN) || cncs.ORD_THK_MIN.Length > 6)
|
|
|
{
|
|
|
result.msg = "订单厚度下限不可为空且长度不可超过6 或者不是数字!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(cncs.ORD_THK_MAX) || !CommonUtils.IsNumber(cncs.ORD_THK_MAX) || cncs.ORD_THK_MAX.Length > 6)
|
|
|
{
|
|
|
result.msg = "订单厚度上限不可为空且长度不可超过6 或者不是数字!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.THK_MIN))
|
|
|
if (!CommonUtils.IsNumber(cncs.THK_MIN) || cncs.THK_MIN.Length > 3)
|
|
|
{
|
|
|
result.msg = "坯料厚度下限是长度不可超过3的数字!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.THK_MAX))
|
|
|
if (!CommonUtils.IsNumber(cncs.THK_MAX) || cncs.THK_MAX.Length > 3)
|
|
|
{
|
|
|
result.msg = "坯料厚度上限是长度不可超过3的数字!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.IF_ROLL))
|
|
|
if (!"Y".Equals( cncs.IF_ROLL) && !"N".Equals(cncs.IF_ROLL))
|
|
|
{
|
|
|
result.msg = "是否允许倍宽轧制 只能是 Y(允许) 或 N(不允许) !";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.RATE))
|
|
|
if (!CommonUtils.IsNumber(cncs.RATE) || cncs.RATE.Length > 10)
|
|
|
{
|
|
|
result.msg = "有效压缩比是长度不可超过10的数字!";
|
|
|
result.code = "0";
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取主键的条件
|
|
|
/// </summary>
|
|
|
/// <param name="primaryKeyEntity"></param>
|
|
|
/// <returns>AND 开头的 主键条件字符串</returns>
|
|
|
public string GetPrimaryKeyString(QP_PROD_RATIO primaryKeyEntity)
|
|
|
{
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
//if (!string.IsNullOrWhiteSpace(primaryKeyEntity.APLY_ITEM))
|
|
|
strSql.AppendLine(" AND PLT = '" + primaryKeyEntity.PLT + "'");
|
|
|
strSql.AppendLine(" AND STDSPEC = '" + primaryKeyEntity.STDSPEC + "'");
|
|
|
strSql.AppendLine(" AND DELIVERY_STATUS = '" + primaryKeyEntity.DELIVERY_STATUS + "'");
|
|
|
strSql.AppendLine(" AND ORD_THK_MIN = '" + primaryKeyEntity.ORD_THK_MIN + "'");
|
|
|
strSql.AppendLine(" AND ORD_THK_MAX = '" + primaryKeyEntity.ORD_THK_MAX + "'");
|
|
|
return strSql.ToString();
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取主键查询的sql
|
|
|
/// </summary>
|
|
|
/// <param name="checkEntity"></param>
|
|
|
/// <returns>主键查询sql</returns>
|
|
|
public string GetCheckString(QP_PROD_RATIO checkEntity)
|
|
|
{
|
|
|
string strSql = "SELECT * FROM QP_PROD_RATIO WHERE 1=1 " + GetPrimaryKeyString(checkEntity);
|
|
|
return strSql;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询接口
|
|
|
/// </summary>
|
|
|
/// <param name="queryArgs"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("hotRoll/getCompressionRatio")]
|
|
|
public RequestEntity GetCompressionRatio(QpProdRatioQueryArgs queryArgs)
|
|
|
{
|
|
|
RequestEntity result = new RequestEntity(); //声明返回参数实体类
|
|
|
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
|
|
|
DataTable dtCheck = new DataTable();
|
|
|
|
|
|
//查询字段
|
|
|
//PLT , STDSPEC , DELIVERY_STATUS , IMPACT_TMP_MIN , IMPACT_TMP_MAX , ORD_THK_MIN , ORD_THK_MAX , THK_MIN , THK_MAX , IF_ROLL , RATE
|
|
|
strSql.AppendLine("SELECT PLT , STDSPEC , DELIVERY_STATUS , IMPACT_TMP_MIN , IMPACT_TMP_MAX , ORD_THK_MIN , ORD_THK_MAX , THK_MIN , THK_MAX , IF_ROLL , RATE ,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 QP_PROD_RATIO WHERE 1 = 1 ");
|
|
|
if (queryArgs != null)
|
|
|
{
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.PLT)) strSql.AppendLine(" AND PLT LIKE '%" + queryArgs.PLT + "%'");
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.STDSPEC)) strSql.AppendLine(" AND STDSPEC LIKE '%" + queryArgs.STDSPEC + "%'");
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.DELIVERY_STATUS)) strSql.AppendLine(" AND DELIVERY_STATUS LIKE '%" + queryArgs.DELIVERY_STATUS + "%'");
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.IMPACT_TMP_MIN) && CommonUtils.IsNumber(queryArgs.IMPACT_TMP_MIN)) strSql.AppendLine(" AND IMPACT_TMP_MIN >=" + queryArgs.IMPACT_TMP_MIN);
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.IMPACT_TMP_MAX) && CommonUtils.IsNumber(queryArgs.IMPACT_TMP_MAX)) strSql.AppendLine(" AND IMPACT_TMP_MAX <=" + queryArgs.IMPACT_TMP_MAX);
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.ORD_THK_MIN) && CommonUtils.IsNumber(queryArgs.ORD_THK_MIN)) strSql.AppendLine(" AND ORD_THK_MIN >=" + queryArgs.ORD_THK_MIN);
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.ORD_THK_MAX) && CommonUtils.IsNumber(queryArgs.ORD_THK_MAX)) strSql.AppendLine(" AND ORD_THK_MAX <=" + queryArgs.ORD_THK_MAX);
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.THK_MIN) && CommonUtils.IsNumber(queryArgs.THK_MIN)) strSql.AppendLine(" AND THK_MIN >=" + queryArgs.THK_MIN);
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.THK_MAX) && CommonUtils.IsNumber(queryArgs.THK_MAX)) strSql.AppendLine(" AND THK_MAX <=" + queryArgs.THK_MAX);
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.IF_ROLL)) strSql.AppendLine(" AND IF_ROLL LIKE '%" + queryArgs.IF_ROLL + "%'");
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.START_RATE) && CommonUtils.IsNumber(queryArgs.START_RATE)) strSql.AppendLine(" AND RATE >=" + queryArgs.START_RATE);
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.END_RATE) && CommonUtils.IsNumber(queryArgs.END_RATE)) strSql.AppendLine(" AND RATE <=" + queryArgs.END_RATE);
|
|
|
|
|
|
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 PLT ");
|
|
|
dtCheck = db.Query(strSql.ToString());
|
|
|
result.data = db.Query<QP_PROD_RATIO>(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("GetCompressionRatio 报错", ex);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 添加接口
|
|
|
/// </summary>
|
|
|
/// <param name="insertModel"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("hotRoll/addCompressionRatio")]
|
|
|
public RequestEntity AddCompressionRatio(QP_PROD_RATIO 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<QP_PROD_RATIO>(insertModel) > 0)
|
|
|
{
|
|
|
result.msg = "操作成功";
|
|
|
result.code = "1";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
result.msg = "数据库错误!";
|
|
|
result.code = "0";
|
|
|
logger.Error("AddCompressionRatio 报错 : ", ex);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新接口
|
|
|
/// </summary>
|
|
|
/// <param name="requestData"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("hotRoll/updCompressionRatio")]
|
|
|
public RequestEntity UpdCompressionRatio(IList<QP_PROD_RATIO> 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 , STDSPEC , DELIVERY_STATUS , IMPACT_TMP_MIN , IMPACT_TMP_MAX , ORD_THK_MIN , ORD_THK_MAX , THK_MIN , THK_MAX , IF_ROLL , RATE
|
|
|
if (db.Execute("UPDATE QP_PROD_RATIO SET " + string.Format(" PLT = '{0}' , STDSPEC = '{1}' , DELIVERY_STATUS = '{2}' , IMPACT_TMP_MIN = '{3}' , IMPACT_TMP_MAX = '{4}',ORD_THK_MIN = '{5}',ORD_THK_MAX = '{6}', THK_MIN = '{7}', THK_MAX = '{8}', IF_ROLL = '{9}', RATE = '{10}' , UPD_DATE = '{11}' , UPD_TIME='{12}',UPD_EMP = '{13}' WHERE 1 = 1 ",
|
|
|
requestData[1].PLT, requestData[1].STDSPEC, requestData[1].DELIVERY_STATUS, requestData[1].IMPACT_TMP_MIN, requestData[1].IMPACT_TMP_MAX, requestData[1].ORD_THK_MIN, requestData[1].ORD_THK_MAX, requestData[1].THK_MIN, requestData[1].THK_MAX, requestData[1].IF_ROLL, requestData[1].RATE, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP) +
|
|
|
//根据主键字段可以确定唯一数据即要修改的数据
|
|
|
GetPrimaryKeyString(requestData[0])) > 0)
|
|
|
{
|
|
|
result.msg = "操作成功";
|
|
|
result.code = "1";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.msg = "数据未发生改变,请确认后重试!";
|
|
|
result.code = "0";
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
result.msg = "数据库错误!";
|
|
|
result.code = "0";
|
|
|
logger.Error("UpdCompressionRatio 报错", ex);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除接口
|
|
|
/// </summary>
|
|
|
/// <param name="delModel"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("hotRoll/delCompressionRatio")]
|
|
|
public RequestEntity DelCompressionRatio(QP_PROD_RATIO delModel)
|
|
|
{
|
|
|
RequestEntity result = new RequestEntity();
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
strSql.AppendLine("DELETE FROM QP_PROD_RATIO WHERE 1=1 ");
|
|
|
strSql.AppendLine(GetPrimaryKeyString(delModel));
|
|
|
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("DelCompressionRatio 报错", ex);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
}
|