You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
18 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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月08日
* 创建者: 李跃升
* Copy Right: 北京科技大学设计研究院有限公司
********************************************************/
namespace ibk.IPD.Controller.IPD_MR.HotRoll
{
[RoutePrefix("ipd/ipdMr")]
public class SlabHeapCoolingController : ApiController
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/getSlabHeapCooling")]
public RequestEntity GetSlabHeapCooling(CpPrcCoolDateQueryArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
DataTable dtCheck = new DataTable();
//查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss
//PLT , SLAB_MIN_THK , SLAB_MAX_THK , STLGRD , PROD_MIN_THK , PROD_MAX_THK , SLAB_COOL_TIME , INS_EMP_CD , UPD_EMP_CD
strSql.AppendLine("SELECT PLT,SLAB_MIN_THK,SLAB_MAX_THK,STLGRD,PROD_MIN_THK,PROD_MAX_THK,SLAB_COOL_TIME,to_date(UPD_DATE ,'yyyy-mm-dd hh24:mi:ss') as UPD_DATE,UPD_EMP_CD,to_date(INS_DATE ,'yyyy-mm-dd hh24:mi:ss') as INS_DATE,INS_EMP_CD FROM CP_PRC_COOL_DATE WHERE 1=1");
if (queryArgs != null)
{
if (!string.IsNullOrWhiteSpace(queryArgs.PLT)) strSql.AppendLine(" AND PLT LIKE '%" + queryArgs.PLT + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.SLAB_MIN_THK) && CommonUtils.IsNumber(queryArgs.SLAB_MIN_THK)) strSql.AppendLine(" AND SLAB_MIN_THK >=" + queryArgs.SLAB_MIN_THK);
if (!string.IsNullOrWhiteSpace(queryArgs.SLAB_MAX_THK) && CommonUtils.IsNumber(queryArgs.SLAB_MAX_THK)) strSql.AppendLine(" AND SLAB_MAX_THK <=" + queryArgs.SLAB_MAX_THK);
if (!string.IsNullOrWhiteSpace(queryArgs.STLGRD)) strSql.AppendLine(" AND STLGRD LIKE '%" + queryArgs.STLGRD + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.PROD_MIN_THK) && CommonUtils.IsNumber(queryArgs.PROD_MIN_THK)) strSql.AppendLine(" AND PROD_MIN_THK >= " + queryArgs.PROD_MIN_THK);
if (!string.IsNullOrWhiteSpace(queryArgs.PROD_MAX_THK) && CommonUtils.IsNumber(queryArgs.PROD_MAX_THK)) strSql.AppendLine(" AND PROD_MAX_THK <= " + queryArgs.PROD_MAX_THK);
if (!string.IsNullOrWhiteSpace(queryArgs.START_SLAB_COOL_TIME) && CommonUtils.IsNumber(queryArgs.START_SLAB_COOL_TIME)) strSql.AppendLine(" AND SLAB_COOL_TIME >= " + queryArgs.START_SLAB_COOL_TIME);
if (!string.IsNullOrWhiteSpace(queryArgs.END_SLAB_COOL_TIME) && CommonUtils.IsNumber(queryArgs.END_SLAB_COOL_TIME)) strSql.AppendLine(" AND SLAB_COOL_TIME <= " + queryArgs.END_SLAB_COOL_TIME);
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<CP_PRC_COOL_DATE>(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("GetSlabHeapCooling 报错 : ", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/addSlabHeapCooling")]
public RequestEntity AddSlabHeapCooling(CP_PRC_COOL_DATE insertModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
DateTime dtNow = DateTime.Now;
try
{
#region 参数判断
//PLT , SLAB_MIN_THK , SLAB_MAX_THK , STLGRD , PROD_MIN_THK , PROD_MAX_THK , SLAB_COOL_TIME ,
if (string.IsNullOrEmpty(insertModel.PLT) || insertModel.PLT.Length > 2)
{
result.msg = "工厂不可为空且长度不可超过2";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.SLAB_MIN_THK) || !CommonUtils.IsNumber(insertModel.SLAB_MIN_THK) || insertModel.SLAB_MIN_THK.Length > 6)
{
result.msg = "坯料厚度下限 不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.SLAB_MAX_THK) || !CommonUtils.IsNumber(insertModel.SLAB_MAX_THK) || insertModel.SLAB_MAX_THK.Length > 6)
{
result.msg = "坯料厚度上限 不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.STLGRD) || insertModel.STLGRD.Length > 11)
{
result.msg = "钢种不可为空且长度不可超过11";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.PROD_MIN_THK) || !CommonUtils.IsNumber(insertModel.PROD_MIN_THK) || insertModel.PROD_MIN_THK.Length > 6)
{
result.msg = "坯料厚度上限 不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.PROD_MAX_THK) || !CommonUtils.IsNumber(insertModel.PROD_MAX_THK) || insertModel.PROD_MAX_THK.Length > 6)
{
result.msg = "坯料厚度上限 不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.SLAB_COOL_TIME) || !CommonUtils.IsNumber(insertModel.SLAB_COOL_TIME) || insertModel.SLAB_COOL_TIME.Length > 2)
{
result.msg = "板坯堆冷时间 不可为空且长度不可超过2或不是数字";
result.code = "0";
return result;
}
#endregion
// 拼接主键重复check查询语句
//PLT , SLAB_MIN_THK , SLAB_MAX_THK , STLGRD , PROD_MIN_THK , PROD_MAX_THK
strSql.AppendLine("SELECT * FROM CP_PRC_COOL_DATE WHERE 1=1 ");
strSql.AppendLine(string.Format("AND PLT = '{0}' AND SLAB_MIN_THK = '{1}' AND SLAB_MAX_THK = '{2}' AND STLGRD = '{3}' AND PROD_MIN_THK = '{4}' AND PROD_MAX_THK = '{5}' ",
insertModel.PLT, insertModel.SLAB_MIN_THK, insertModel.SLAB_MAX_THK, insertModel.STLGRD, insertModel.PROD_MIN_THK, insertModel.PROD_MAX_THK));
insertModel.INS_DATE = dtNow.ToString("yyyyMMddHHmmss");
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<CP_PRC_COOL_DATE>(insertModel) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddSlabHeapCooling 报错 : ", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/updSlabHeapCooling")]
public RequestEntity UpdSlabHeapCooling(IList<CP_PRC_COOL_DATE> 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("yyyyMMddHHmmss");
#region 参数判断
//PLT , SLAB_MIN_THK , SLAB_MAX_THK , STLGRD , PROD_MIN_THK , PROD_MAX_THK , SLAB_COOL_TIME ,
if (string.IsNullOrEmpty(requestData[1].PLT) || requestData[1].PLT.Length > 2)
{
result.msg = "工厂不可为空且长度不可超过2";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].SLAB_MIN_THK) || !CommonUtils.IsNumber(requestData[1].SLAB_MIN_THK) || requestData[1].SLAB_MIN_THK.Length > 6)
{
result.msg = "坯料厚度下限 不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].SLAB_MAX_THK) || !CommonUtils.IsNumber(requestData[1].SLAB_MAX_THK) || requestData[1].SLAB_MAX_THK.Length > 6)
{
result.msg = "坯料厚度上限 不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].STLGRD) || requestData[1].STLGRD.Length > 11)
{
result.msg = "钢种不可为空且长度不可超过11";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].PROD_MIN_THK) || !CommonUtils.IsNumber(requestData[1].PROD_MIN_THK) || requestData[1].PROD_MIN_THK.Length > 6)
{
result.msg = "坯料厚度上限 不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].PROD_MAX_THK) || !CommonUtils.IsNumber(requestData[1].PROD_MAX_THK) || requestData[1].PROD_MAX_THK.Length > 6)
{
result.msg = "坯料厚度上限 不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].SLAB_COOL_TIME) || !CommonUtils.IsNumber(requestData[1].SLAB_COOL_TIME) || requestData[1].SLAB_COOL_TIME.Length > 2)
{
result.msg = "板坯堆冷时间 不可为空且长度不可超过2或不是数字";
result.code = "0";
return result;
}
#endregion
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
// 拼接主键重复check查询语句
//PLT , SLAB_MIN_THK , SLAB_MAX_THK , STLGRD , PROD_MIN_THK , PROD_MAX_THK
strSql.AppendLine("SELECT * FROM CP_PRC_COOL_DATE WHERE 1=1 ");
strSql.AppendLine(string.Format("AND PLT = '{0}' AND SLAB_MIN_THK = '{1}' AND SLAB_MAX_THK = '{2}' AND STLGRD = '{3}' AND PROD_MIN_THK = '{4}' AND PROD_MAX_THK = '{5}' ",
requestData[1].PLT, requestData[1].SLAB_MIN_THK, requestData[1].SLAB_MAX_THK, requestData[1].STLGRD, requestData[1].PROD_MIN_THK, requestData[1].PROD_MAX_THK));
strSqlSelf.AppendLine("SELECT * FROM CP_PRC_COOL_DATE WHERE 1=1 ");
strSqlSelf.AppendLine(string.Format("AND PLT = '{0}' AND SLAB_MIN_THK = '{1}' AND SLAB_MAX_THK = '{2}' AND STLGRD = '{3}' AND PROD_MIN_THK = '{4}' AND PROD_MAX_THK = '{5}' ",
requestData[0].PLT, requestData[0].SLAB_MIN_THK, requestData[0].SLAB_MAX_THK, requestData[0].STLGRD, requestData[0].PROD_MIN_THK, requestData[0].PROD_MAX_THK));
// 执行主键重复查询
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
{
//更新哪些字段
//PLT , SLAB_MIN_THK , SLAB_MAX_THK , STLGRD , PROD_MIN_THK , PROD_MAX_THK , SLAB_COOL_TIME ,
if (db.Execute("UPDATE CP_PRC_COOL_DATE SET " + string.Format(" PLT = '{0}' , SLAB_MIN_THK = '{1}' , SLAB_MAX_THK = '{2}' , STLGRD = '{3}' , PROD_MIN_THK = '{4}',PROD_MAX_THK = '{5}' ,SLAB_COOL_TIME = '{6}', UPD_DATE = '{7}',UPD_EMP_CD = '{8}' ",
requestData[1].PLT, requestData[1].SLAB_MIN_THK, requestData[1].SLAB_MAX_THK, requestData[1].STLGRD, requestData[1].PROD_MIN_THK, requestData[1].PROD_MAX_THK, requestData[1].SLAB_COOL_TIME, requestData[1].UPD_DATE, requestData[1].UPD_EMP_CD) +
//根据主键字段可以确定唯一数据即要修改的数据
//PLT , SLAB_MIN_THK , SLAB_MAX_THK , STLGRD , PROD_MIN_THK , PROD_MAX_THK
string.Format("WHERE 1=1 AND PLT = '{0}' AND SLAB_MIN_THK = '{1}' AND SLAB_MAX_THK = '{2}' AND STLGRD = '{3}' AND PROD_MIN_THK = '{4}' AND PROD_MAX_THK = '{5}' ",
requestData[0].PLT, requestData[0].SLAB_MIN_THK, requestData[0].SLAB_MAX_THK, requestData[0].STLGRD, requestData[0].PROD_MIN_THK, requestData[0].PROD_MAX_THK)) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
else
{
result.msg = "数据未发生改变,请确认后重试!";
result.code = "0";
}
}
return result;
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("UpdSlabHeapCooling 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/delSlabHeapCooling")]
public RequestEntity DelSlabHeapCooling(CP_PRC_COOL_DATE delModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
try
{
//PLT , SLAB_MIN_THK , SLAB_MAX_THK , STLGRD , PROD_MIN_THK , PROD_MAX_THK
strSql.AppendLine("DELETE FROM CP_PRC_COOL_DATE WHERE 1=1 ");
strSql.AppendLine(string.Format("AND PLT = '{0}' AND SLAB_MIN_THK = '{1}' AND SLAB_MAX_THK = '{2}' AND STLGRD = '{3}' AND PROD_MIN_THK = '{4}' AND PROD_MAX_THK = '{5}' " ,
delModel.PLT, delModel.SLAB_MIN_THK, delModel.SLAB_MAX_THK, delModel.STLGRD, delModel.PROD_MIN_THK, delModel.PROD_MAX_THK));
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("DelSlabHeapCooling 报错", ex);
}
return result;
}
}
}