using ibk.IPD.Common; using ibk.IPD.Entity; using ibk.IPD.Entity.IPD_MR.StdMgt.QueryArgs; using ibk.IPD.Entity.IpdMr.StdMgt; using ibk.IPD.Entity.StdMgt.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年03月29日 * 创建者: 李跃升 * Copy Right: 北京科技大学设计研究院有限公司 ********************************************************/ namespace ibk.IPD.Controller.IPD_MR.StdMgt { [RoutePrefix("ipd/ipdMr")] public class CastingOperationTimeController : ApiController { private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); /// /// 查询接口 /// /// /// [HttpPost, Route("stdMgt/getCastingOperationTime")] public RequestEntity GetCastingOperationTime(EpCcmTimeQueryArgs queryArgs) { RequestEntity result = new RequestEntity(); //声明返回参数实体类 StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量 DataTable dtCheck = new DataTable(); //查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss //PLT , PRC_LINE , SLAB_WID_MIN 板坯宽度下限, SLAB_WID_MAX 板坯宽度上限, STLGRD_GRP 钢种组 SLAB_THK ,CCM_SPEED strSql.AppendLine("SELECT PLT,PRC_LINE,SLAB_WID_MIN,SLAB_WID_MAX,STLGRD_GRP , SLAB_THK, CCM_SPEED ,to_date(UPD_DATE || UPD_TIME,'yyyy-mm-dd hh24:mi:ss') as UPD_DATE,UPD_TIME,UPD_EMP,to_date(INS_DATE || INS_TIME,'yyyy-mm-dd hh24:mi:ss') as INS_DATE,INS_TIME,INS_EMP FROM EP_CCM_TIME 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.SLAB_WID_MIN) && CommonUtils.IsNumber(queryArgs.SLAB_WID_MIN)) strSql.AppendLine(" AND SLAB_WID_MIN >=" + queryArgs.SLAB_WID_MIN); if (!string.IsNullOrWhiteSpace(queryArgs.SLAB_WID_MAX) && CommonUtils.IsNumber(queryArgs.SLAB_WID_MAX)) strSql.AppendLine(" AND SLAB_WID_MAX <=" + queryArgs.SLAB_WID_MAX); if (!string.IsNullOrWhiteSpace(queryArgs.STLGRD_GRP)) strSql.AppendLine(" AND STLGRD_GRP LIKE '%" + queryArgs.STLGRD_GRP + "%'"); if (!string.IsNullOrWhiteSpace(queryArgs.START_SLAB_THK) && CommonUtils.IsNumber(queryArgs.START_SLAB_THK)) strSql.AppendLine(" AND SLAB_THK >= " + queryArgs.START_SLAB_THK); if (!string.IsNullOrWhiteSpace(queryArgs.END_SLAB_THK) && CommonUtils.IsNumber(queryArgs.END_SLAB_THK)) strSql.AppendLine(" AND SLAB_THK <= " + queryArgs.END_SLAB_THK); 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("db")) { strSql.AppendLine("Order By INS_DATE DESC"); 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("GetCastingOperationTime 报错 : ", ex); } return result; } /// /// 添加接口 /// /// /// [HttpPost, Route("stdMgt/addCastingOperationTime")] public RequestEntity AddCastingOperationTime(EP_CCM_TIME insertModel) { RequestEntity result = new RequestEntity(); StringBuilder strSql = new StringBuilder(); DateTime dtNow = DateTime.Now; try { #region 参数判断 //PLT , PRC_LINE , SLAB_WID_MIN 板坯宽度下限, SLAB_WID_MAX 板坯宽度上限, STLGRD_GRP 钢种组 SLAB_THK 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.SLAB_WID_MIN) || insertModel.SLAB_WID_MIN.Length > 6) { result.msg = "板坯宽度下限不可为空且长度不可超过6!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(insertModel.SLAB_WID_MAX) || insertModel.SLAB_WID_MAX.Length > 6) { result.msg = "板坯宽度上限不可为空且长度不可超过6!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(insertModel.STLGRD_GRP) || insertModel.STLGRD_GRP.Length > 11) { result.msg = "钢种组不可为空且长度不可超过11!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(insertModel.SLAB_THK) || insertModel.SLAB_THK.Length > 6 || !CommonUtils.IsNumber(insertModel.SLAB_THK)) { result.msg = "板坯厚度不可为空且是长度不可超过6的数字!"; result.code = "0"; return result; } if (!string.IsNullOrEmpty(insertModel.CCM_SPEED)) if (insertModel.CCM_SPEED.Length > 4 || !CommonUtils.IsNumber(insertModel.CCM_SPEED)) { result.msg = "浇铸时间长度不可超过4或不是数字!"; result.code = "0"; return result; } #endregion // 拼接主键重复check查询语句 //PLT , PRC_LINE , SLAB_WID_MIN 板坯宽度下限, SLAB_WID_MAX 板坯宽度上限, STLGRD_GRP 钢种组 SLAB_THK strSql.AppendLine("SELECT * FROM EP_CCM_TIME WHERE 1=1 "); strSql.AppendLine(string.Format("AND PLT = '{0}' AND PRC_LINE = '{1}' AND SLAB_WID_MIN = '{2}' AND SLAB_WID_MAX = '{3}' AND STLGRD_GRP = '{4}' AND SLAB_THK = '{5}' ", insertModel.PLT, insertModel.PRC_LINE, insertModel.SLAB_WID_MIN, insertModel.SLAB_WID_MAX, insertModel.STLGRD_GRP, insertModel.SLAB_THK)); insertModel.INS_DATE = dtNow.ToString("yyyyMMdd"); insertModel.INS_TIME = dtNow.ToString("HHmmss"); insertModel.UPD_DATE = dtNow.ToString("yyyyMMdd"); insertModel.UPD_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("AddCastingOperationTime 报错 : ", ex); } return result; } /// /// 更新接口 /// /// /// [HttpPost, Route("stdMgt/updCastingOperationTime")] public RequestEntity UpdCastingOperationTime(IList 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 , SLAB_WID_MIN 板坯宽度下限, SLAB_WID_MAX 板坯宽度上限, STLGRD_GRP 钢种组 SLAB_THK ,CCM_SPEED 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].SLAB_WID_MIN) || requestData[1].SLAB_WID_MIN.Length > 6) { result.msg = "板坯宽度下限不可为空且长度不可超过6!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(requestData[1].SLAB_WID_MAX) || requestData[1].SLAB_WID_MAX.Length > 6) { result.msg = "板坯宽度上限不可为空且长度不可超过6!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(requestData[1].STLGRD_GRP) || requestData[1].STLGRD_GRP.Length > 11) { result.msg = "钢种组不可为空且长度不可超过11!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(requestData[1].SLAB_THK) || requestData[1].SLAB_THK.Length > 6 || !CommonUtils.IsNumber(requestData[1].SLAB_THK)) { result.msg = "板坯厚度不可为空且是长度不可超过6的数字!"; result.code = "0"; return result; } if (!string.IsNullOrEmpty(requestData[1].CCM_SPEED)) if (requestData[1].CCM_SPEED.Length > 4 || !CommonUtils.IsNumber(requestData[1].CCM_SPEED)) { result.msg = "浇铸时间长度不可超过4或不是数字!"; result.code = "0"; return result; } #endregion try { using (IDbContext db = ObjectContainer.GetObject("db")) { // 拼接主键重复check查询语句 //PLT , PRC_LINE , SLAB_WID_MIN 板坯宽度下限, SLAB_WID_MAX 板坯宽度上限, STLGRD_GRP 钢种组 SLAB_THK strSql.AppendLine("SELECT * FROM EP_CCM_TIME WHERE 1=1 "); strSql.AppendLine(string.Format("AND PLT = '{0}' AND PRC_LINE = '{1}' AND SLAB_WID_MIN = '{2}' AND SLAB_WID_MAX = '{3}' AND STLGRD_GRP = '{4}' AND SLAB_THK = '{5}' ", requestData[1].PLT, requestData[1].PRC_LINE, requestData[1].SLAB_WID_MIN, requestData[1].SLAB_WID_MAX, requestData[1].STLGRD_GRP, requestData[1].SLAB_THK)); // 拼接主键重复check查询语句 //PLT , PRC_LINE , SLAB_WID_MIN 板坯宽度下限, SLAB_WID_MAX 板坯宽度上限, STLGRD_GRP 钢种组 SLAB_THK strSqlSelf.AppendLine("SELECT * FROM EP_CCM_TIME WHERE 1=1 "); strSqlSelf.AppendLine(string.Format("AND PLT = '{0}' AND PRC_LINE = '{1}' AND SLAB_WID_MIN = '{2}' AND SLAB_WID_MAX = '{3}' AND STLGRD_GRP = '{4}' AND SLAB_THK = '{5}' ", requestData[0].PLT, requestData[0].PRC_LINE, requestData[0].SLAB_WID_MIN, requestData[0].SLAB_WID_MAX, requestData[0].STLGRD_GRP, requestData[0].SLAB_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 , PRC_LINE , SLAB_WID_MIN 板坯宽度下限, SLAB_WID_MAX 板坯宽度上限, STLGRD_GRP 钢种组 SLAB_THK , CCM_SPEED if (db.Execute("UPDATE EP_CCM_TIME SET " + string.Format(" PLT = '{0}' , PRC_LINE = '{1}' , SLAB_WID_MIN = '{2}' , SLAB_WID_MAX = '{3}' , STLGRD_GRP = '{4}' , SLAB_THK = '{5}' , CCM_SPEED = '{6}' , UPD_DATE = '{7}',UPD_TIME='{8}',UPD_EMP = '{9}' ", requestData[1].PLT, requestData[1].PRC_LINE, requestData[1].SLAB_WID_MIN, requestData[1].SLAB_WID_MAX, requestData[1].STLGRD_GRP, requestData[1].SLAB_THK, requestData[1].CCM_SPEED, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP) + //根据主键字段可以确定唯一数据即要修改的数据 //PLT , PRC_LINE , SLAB_WID_MIN 板坯宽度下限, SLAB_WID_MAX 板坯宽度上限, STLGRD_GRP 钢种组 SLAB_THK string.Format("WHERE PLT = '{0}' AND PRC_LINE = '{1}' AND SLAB_WID_MIN = '{2}' AND SLAB_WID_MAX = '{3}' AND STLGRD_GRP = '{4}' AND SLAB_THK = '{5}' ", requestData[0].PLT, requestData[0].PRC_LINE, requestData[0].SLAB_WID_MIN, requestData[0].SLAB_WID_MAX, requestData[0].STLGRD_GRP, requestData[0].SLAB_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("UpdCastingOperationTime 报错", ex); return result; } } /// /// 删除接口 /// /// /// [HttpPost, Route("stdMgt/delCastingOperationTime")] public RequestEntity DelCastingOperationTime(EP_CCM_TIME delModel) { RequestEntity result = new RequestEntity(); StringBuilder strSql = new StringBuilder(); try { // 拼接主键重复check查询语句 //PLT , PRC_LINE , SLAB_WID_MIN 板坯宽度下限, SLAB_WID_MAX 板坯宽度上限, STLGRD_GRP 钢种组 SLAB_THK strSql.AppendLine("DELETE FROM EP_CCM_TIME WHERE 1=1 "); strSql.AppendLine(string.Format("AND PLT = '{0}' AND PRC_LINE = '{1}' AND SLAB_WID_MIN = '{2}' AND SLAB_WID_MAX = '{3}' AND STLGRD_GRP = '{4}' AND SLAB_THK = '{5}' ", delModel.PLT, delModel.PRC_LINE, delModel.SLAB_WID_MIN, delModel.SLAB_WID_MAX, delModel.STLGRD_GRP, delModel.SLAB_THK)); 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("DelCastingOperationTime 报错", ex); } return result; } } }