using ibk.IPD.Common; using ibk.IPD.Entity; using ibk.IPD.Entity.IPD_MR.HotRoll.QueryArgs; using ibk.IPD.Entity.IPD_MR.HotRoll.RequestArgs; using ibk.IPD.Entity.IPD_PS; 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月06日 * 创建者: 李跃升 * Copy Right: 北京科技大学设计研究院有限公司 ********************************************************/ namespace ibk.IPD.Controller.IPD_MR.HotRoll { [RoutePrefix("ipd/ipdMr")] public class DifferentSteelGradeController : ApiController { private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); /// /// 查询接口 /// /// /// [HttpPost, Route("hotRoll/getDifferentSteelGrade")] public RequestEntity GetDifferentSteelGrade(QpQltyTechReplaceQueryArgs queryArgs) { RequestEntity result = new RequestEntity(); //声明返回参数实体类 StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量 DataTable dtCheck = new DataTable(); //查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss //分页查询 //strSql.AppendLine("SELECT * FROM ( " + // "SELECT ROWNUM AS rowno,q.* FROM QP_QLTY_TECH_REPLACE q WHERE 1=1 "); //普通查询 strSql.AppendLine("SELECT MILL_PLT , ORESTLGRD ,TGT_STLGRD , SLAB_THK_MIN , SLAB_THK_MAX , ORD_THK_MIN , ORD_THK_MAX , HEAT_TGT_TMP , HEAT_TGT_TMP_MAX , HEAT_TGT_TMP_MIN, AVGH_TGT_TMP , AVGH_TGT_TMP_MAX , AVGH_TGT_TMP_MIN , MILL_TMP_MIN , MILL_TMP_MAX , MILL_TMP_TGT , AVG_HEAT_TIME_MIN, COOL_TMP_MIN , COOL_TMP_MAX , COOL_TMP_TGT ,UST_FL , HOT_LVL_USE , COOL_TMP_RATE , COOL_BED_TMP_TGT , CR_CD , HEAT_TIME_MAX , HEAT_TIME_MIN , COOL_WAY , HCR_KND_1 , CR_MILL_TMPT1 , CR_MILL_RATET1 ,COOL_CTL_TYP ,DEL_STATE , CR_MILL_TMPT2 ,CR_MILL_RATET2,MILL_STD_EDT_NO,AVG_HEAT_TIME_MAX ,CR_MILL_TMPT2_MIN , CR_MILL_TMPT2_MAX ,COOLHOT_LOAD , DIFFER_CODE , FLG , TAP_TMP_TGT , TAP_TMP_MIN , TAP_TMP_MAX , COOL_RATE , MES_STDSPEC , DIFFER_CODE , to_date(UPD_DATE ,'yyyy-mm-dd') as UPD_DATE, UPD_TIME,UPD_EMP,to_date(INS_DATE ,'yyyy-mm-dd') as INS_DATE,INS_TIME,INS_EMP FROM QP_QLTY_TECH_REPLACE WHERE 1 = 1 "); if (queryArgs != null) { if (!string.IsNullOrWhiteSpace(queryArgs.MILL_PLT)) strSql.AppendLine(" AND MILL_PLT LIKE '%" + queryArgs.MILL_PLT + "%'"); if (!string.IsNullOrWhiteSpace(queryArgs.ORESTLGRD)) strSql.AppendLine(" AND ORESTLGRD LIKE '%" + queryArgs.ORESTLGRD + "%'"); if (!string.IsNullOrWhiteSpace(queryArgs.TGT_STLGRD)) strSql.AppendLine(" AND TGT_STLGRD LIKE '%" + queryArgs.TGT_STLGRD + "%'"); if (!string.IsNullOrWhiteSpace(queryArgs.SLAB_THK_MIN) && CommonUtils.IsNumber(queryArgs.SLAB_THK_MIN)) strSql.AppendLine(" AND SLAB_THK_MIN >=" + queryArgs.SLAB_THK_MIN); if (!string.IsNullOrWhiteSpace(queryArgs.SLAB_THK_MAX) && CommonUtils.IsNumber(queryArgs.SLAB_THK_MAX)) strSql.AppendLine(" AND SLAB_THK_MAX <=" + queryArgs.SLAB_THK_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.HEAT_TGT_TMP) && CommonUtils.IsNumber(queryArgs.HEAT_TGT_TMP)) strSql.AppendLine(" AND HEAT_TGT_TMP =" + queryArgs.HEAT_TGT_TMP); if (!string.IsNullOrWhiteSpace(queryArgs.HEAT_TGT_TMP_MIN) && CommonUtils.IsNumber(queryArgs.HEAT_TGT_TMP_MIN)) strSql.AppendLine(" AND HEAT_TGT_TMP_MIN >=" + queryArgs.HEAT_TGT_TMP_MIN); if (!string.IsNullOrWhiteSpace(queryArgs.HEAT_TGT_TMP_MAX) && CommonUtils.IsNumber(queryArgs.HEAT_TGT_TMP_MAX)) strSql.AppendLine(" AND HEAT_TGT_TMP_MAX <=" + queryArgs.HEAT_TGT_TMP_MAX); 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')"); } //SELECT * FROM (SELECT ROWNUM AS rowno,MILL_PLT FROM QP_QLTY_TECH_REPLACE WHERE ROWNUM <= 20) WHERE rowno > 10 try { //开启数据库连接查询数据 using (IDbContext db = ObjectContainer.GetObject("db")) { //strSql.AppendLine(" AND ROWNUM <= 20) WHERE rowno > 10 "); dtCheck = db.Query(strSql.ToString()); result.data = 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("GetDifferentSteelGrade 报错", ex); } return result; } /// /// 添加接口 /// /// /// [HttpPost, Route("hotRoll/addDifferentSteelGrade")] public RequestEntity AddDifferentSteelGrade(QP_QLTY_TECH_REPLACE insertModel) { RequestEntity result = new RequestEntity(); StringBuilder strSql = new StringBuilder(); DateTime dtNow = DateTime.Now; try { #region 参数判断 //非空参数 //MILL_PLT , ORESTLGRD , TGT_STLGRD , SLAB_THK_MIN 柸料厚度最小 , SLAB_THK_MAX 柸料厚度最大 , ORD_THK_MIN 订单厚度最小值 , ORD_THK_MAX 订单厚度最大值 , DIFFER_CODE 区分代码(0非热处理/1热处理) if (string.IsNullOrEmpty(insertModel.MILL_PLT) || insertModel.MILL_PLT.Length > 2) { result.msg = "轧钢工厂不可为空且长度不可超过2!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(insertModel.ORESTLGRD) || insertModel.ORESTLGRD.Length > 200) { result.msg = "原始钢种不可为空且长度不可超过200!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(insertModel.TGT_STLGRD) || insertModel.TGT_STLGRD.Length > 60) { result.msg = "目标钢种不可为空且长度不可超过60!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(insertModel.SLAB_THK_MIN) || !CommonUtils.IsNumber(insertModel.SLAB_THK_MIN) || insertModel.SLAB_THK_MIN.Length > 6) { result.msg = "柸料厚度最小是不可为空且长度不可超过6的数字!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(insertModel.SLAB_THK_MAX) || !CommonUtils.IsNumber(insertModel.SLAB_THK_MAX) || insertModel.SLAB_THK_MAX.Length > 6) { result.msg = "柸料厚度最大是不可为空且长度不可超过6的数字!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(insertModel.ORD_THK_MIN) || !CommonUtils.IsNumber(insertModel.ORD_THK_MIN) || insertModel.ORD_THK_MIN.Length > 6) { result.msg = "订单厚度最小值是不可为空且长度不可超过6的数字!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(insertModel.ORD_THK_MAX) || !CommonUtils.IsNumber(insertModel.ORD_THK_MAX) || insertModel.ORD_THK_MAX.Length > 6) { result.msg = "订单厚度最大值是不可为空且长度不可超过6的数字!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(insertModel.DIFFER_CODE) || (!"0".Equals(insertModel.DIFFER_CODE) && !"1".Equals(insertModel.DIFFER_CODE) )) { result.msg = "区分代码(0非热处理/1热处理)不可为空且只能是 0 或 1!"; result.code = "0"; return result; } #endregion // 拼接主键重复check查询语句 //MILL_PLT , ORESTLGRD , TGT_STLGRD , SLAB_THK_MIN 柸料厚度最小 , SLAB_THK_MAX 柸料厚度最大 , ORD_THK_MIN 订单厚度最小值 , ORD_THK_MAX 订单厚度最大值 strSql.AppendLine("SELECT MILL_PLT FROM QP_QLTY_TECH_REPLACE WHERE 1=1 "); strSql.AppendLine(string.Format("AND MILL_PLT = '{0}' AND ORESTLGRD = '{1}' AND TGT_STLGRD = '{2}' AND SLAB_THK_MIN = '{3}' AND SLAB_THK_MAX = '{4}' AND ORD_THK_MIN = '{5}' AND ORD_THK_MAX = '{6}'", insertModel.MILL_PLT, insertModel.ORESTLGRD, insertModel.TGT_STLGRD, insertModel.SLAB_THK_MIN, insertModel.SLAB_THK_MAX, insertModel.ORD_THK_MIN, insertModel.ORD_THK_MAX)); insertModel.INS_DATE = dtNow.ToString("yyyyMMdd"); insertModel.INS_TIME = dtNow.ToString("HHmmss"); using (IDbContext db = ObjectContainer.GetObject("db")) { // 执行主键重复查询 DataTable dtCheck = db.Query(strSql.ToString()); if (dtCheck.Rows.Count > 0) // 若数据库中存在则返回错误码0并msg提示用户 { result.msg = "数据已存在,请确认后重试!"; result.code = "0"; return result; } if (db.Insert(insertModel) > 0) { result.msg = "操作成功"; result.code = "1"; } } } catch (Exception ex) { result.msg = "数据库错误!"; result.code = "0"; logger.Error("AddDifferentSteelGrade 报错 : ", ex); } return result; } /// /// 更新接口 /// /// /// [HttpPost, Route("hotRoll/updDifferentSteelGrade")] public RequestEntity UpdDifferentSteelGrade(IList requestData) { RequestEntity result = new RequestEntity(); DateTime dtNow = DateTime.Now; requestData[1].UPD_DATE = dtNow.ToString("yyyyMMdd"); requestData[1].UPD_TIME = dtNow.ToString("HHmmss"); #region 参数判断 //非空参数 //MILL_PLT , ORESTLGRD , TGT_STLGRD , SLAB_THK_MIN 柸料厚度最小 , SLAB_THK_MAX 柸料厚度最大 , ORD_THK_MIN 订单厚度最小值 , ORD_THK_MAX 订单厚度最大值 , DIFFER_CODE 区分代码(0非热处理/1热处理) if (string.IsNullOrEmpty(requestData[1].MILL_PLT) || requestData[1].MILL_PLT.Length > 2) { result.msg = "轧钢工厂不可为空且长度不可超过2!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(requestData[1].ORESTLGRD) || requestData[1].ORESTLGRD.Length > 200) { result.msg = "原始钢种不可为空且长度不可超过200!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(requestData[1].TGT_STLGRD) || requestData[1].TGT_STLGRD.Length > 60) { result.msg = "目标钢种不可为空且长度不可超过60!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(requestData[1].SLAB_THK_MIN) || !CommonUtils.IsNumber(requestData[1].SLAB_THK_MIN) || requestData[1].SLAB_THK_MIN.Length > 6) { result.msg = "柸料厚度最小是不可为空且长度不可超过6的数字!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(requestData[1].SLAB_THK_MAX) || !CommonUtils.IsNumber(requestData[1].SLAB_THK_MAX) || requestData[1].SLAB_THK_MAX.Length > 6) { result.msg = "柸料厚度最大是不可为空且长度不可超过6的数字!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(requestData[1].ORD_THK_MIN) || !CommonUtils.IsNumber(requestData[1].ORD_THK_MIN) || requestData[1].ORD_THK_MIN.Length > 6) { result.msg = "订单厚度最小值是不可为空且长度不可超过6的数字!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(requestData[1].ORD_THK_MAX) || !CommonUtils.IsNumber(requestData[1].ORD_THK_MAX) || requestData[1].ORD_THK_MAX.Length > 6) { result.msg = "订单厚度最大值是不可为空且长度不可超过6的数字!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(requestData[1].DIFFER_CODE) || (!"0".Equals(requestData[1].DIFFER_CODE) && !"1".Equals(requestData[1].DIFFER_CODE))) { result.msg = "区分代码(0非热处理/1热处理)不可为空且只能是 0 或 1!"; result.code = "0"; return result; } #endregion try { using (IDbContext db = ObjectContainer.GetObject("db")) { //更新哪些字段 //MILL_PLT , ORESTLGRD , TGT_STLGRD , SLAB_THK_MIN 柸料厚度最小 , SLAB_THK_MAX 柸料厚度最大 , ORD_THK_MIN 订单厚度最小值 , ORD_THK_MAX 订单厚度最大值 , DIFFER_CODE 区分代码(0非热处理/1热处理) if (db.Execute("UPDATE QP_QLTY_TECH_REPLACE SET " + string.Format(" MILL_PLT = '{0}' , ORESTLGRD = '{1}' , TGT_STLGRD = '{2}' , SLAB_THK_MIN = '{3}' , SLAB_THK_MAX = '{4}' ,ORD_THK_MIN = '{5}' , ORD_THK_MAX = '{6}' , DIFFER_CODE = '{7}', UPD_DATE = '{8}',UPD_TIME='{9}',UPD_EMP = '{10}' ", requestData[1].MILL_PLT, requestData[1].ORESTLGRD, requestData[1].TGT_STLGRD, requestData[1].SLAB_THK_MIN, requestData[1].SLAB_THK_MAX, requestData[1].ORD_THK_MIN, requestData[1].ORD_THK_MAX, requestData[1].DIFFER_CODE, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP) + //根据主键字段可以确定唯一数据即要修改的数据 //MILL_PLT , ORESTLGRD , TGT_STLGRD , SLAB_THK_MIN 柸料厚度最小 , SLAB_THK_MAX 柸料厚度最大 , ORD_THK_MIN 订单厚度最小值 , ORD_THK_MAX 订单厚度最大值 , DIFFER_CODE 区分代码(0非热处理/1热处理) string.Format("WHERE MILL_PLT = '{0}' AND ORESTLGRD = '{1}' AND TGT_STLGRD = '{2}' AND SLAB_THK_MIN = '{3}' AND SLAB_THK_MAX = '{4}' AND ORD_THK_MIN = '{5}' AND ORD_THK_MAX = '{6}' AND DIFFER_CODE = '{7}'", requestData[0].MILL_PLT, requestData[0].ORESTLGRD, requestData[0].TGT_STLGRD, requestData[0].SLAB_THK_MIN, requestData[0].SLAB_THK_MAX, requestData[0].ORD_THK_MIN, requestData[0].ORD_THK_MAX, requestData[0].DIFFER_CODE)) > 0) { result.msg = "操作成功"; result.code = "1"; } else { result.msg = "数据未发生改变,请确认后重试!"; result.code = "0"; } return result; } } catch (Exception ex) { result.msg = "数据库错误!"; result.code = "0"; logger.Error("UpdDifferentSteelGrade 报错", ex); return result; } } /// /// 删除接口 /// /// /// [HttpPost, Route("hotRoll/delDifferentSteelGrade")] public RequestEntity DelDifferentSteelGrade(QP_QLTY_TECH_REPLACE delModel) { RequestEntity result = new RequestEntity(); StringBuilder strSql = new StringBuilder(); try { //MILL_PLT , ORESTLGRD , TGT_STLGRD , SLAB_THK_MIN 柸料厚度最小 , SLAB_THK_MAX 柸料厚度最大 , ORD_THK_MIN 订单厚度最小值 , ORD_THK_MAX 订单厚度最大值 , DIFFER_CODE 区分代码(0非热处理/1热处理) strSql.AppendLine("DELETE FROM QP_QLTY_TECH_REPLACE WHERE 1=1 "); strSql.AppendLine(string.Format("AND MILL_PLT = '{0}' AND ORESTLGRD = '{1}' AND TGT_STLGRD = '{2}' AND SLAB_THK_MIN = '{3}' AND SLAB_THK_MAX = '{4}' AND ORD_THK_MIN = '{5}' AND ORD_THK_MAX = '{6}' AND DIFFER_CODE = '{7}' ", delModel.MILL_PLT, delModel.ORESTLGRD, delModel.TGT_STLGRD, delModel.SLAB_THK_MIN, delModel.SLAB_THK_MAX, delModel.ORD_THK_MIN, delModel.ORD_THK_MAX, delModel.DIFFER_CODE)); using (IDbContext db = ObjectContainer.GetObject("db")) { db.Execute(strSql.ToString()); // 执行删除数据操作 result.msg = "操作成功"; result.code = "1"; } } catch (Exception ex) { result.msg = "数据库错误!"; result.code = "0"; logger.Error("DelDifferentSteelGrade 报错", ex); } return result; } } }