using ibk.IPD.Common; using ibk.IPD.Entity; using ibk.IPD.Entity.IPD_MR.HotRoll; using ibk.IPD.Entity.IPD_MR.HotRoll.QueryArgs; using ibk.IPD.Entity.IpdMr.Basic; 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年10月28日 * 创建者: xuqilin * Copy Right: 北京科技大学设计研究院有限公司 ********************************************************/ namespace ibk.IPD.Controller.IPD_MR.HotRoll { [RoutePrefix("ipd/ipdMr")] public class ThkToleranceController : ApiController { private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); /// /// 查询接口 /// /// /// [HttpPost, Route("hotRoll/getThkToler")] public RequestEntity GetThkToler(ThkTolerQueryArgs queryArgs) { RequestEntity result = new RequestEntity(); //声明返回参数实体类 StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量 DataTable dtCheck = new DataTable(); //查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss //PK 10, WAREH_MANAGE_CLASS 8 ,DELI_PERI 4 int , SUBSI_RATE 4 int strSql.AppendLine("SELECT PK" + ", PLT" + ", INS_TIME" + ", INS_EMP" + ", UPD_TIME" + ", UPD_EMP" + ", INTER_RANGE" + ",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,LOWER_LIMIT_EXCEEDING,THK_MAX,THK_MIN " + "FROM THK_TOLER_INTER WHERE 1=1"); if (queryArgs != null) { 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 PLT"); 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("GetThkToler 报错", ex); } return result; } /// /// 添加接口 /// /// /// [HttpPost, Route("hotRoll/addThkToler")] public RequestEntity AddThkToler(THK_TOLER_INTER insertModel) { RequestEntity result = new RequestEntity(); StringBuilder strSql = new StringBuilder(); DateTime dtNow = DateTime.Now; try { #region 参数判断 //PK 10, WAREH_MANAGE_CLASS 8 ,DELI_PERI 4 int , SUBSI_RATE 4 int if (string.IsNullOrEmpty(insertModel.PLT) || insertModel.PLT.Length > 2) { result.msg = "工厂不可为空且长度不可超过2!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(insertModel.INTER_RANGE) || !CommonUtils.IsNumber(insertModel.INTER_RANGE) || insertModel.INTER_RANGE.Length > 3) { result.msg = "交集范围不可为空且是长度不超过3的数字!"; result.code = "0"; return result; } #endregion // 拼接主键重复check查询语句 //WAREH_MANAGE_CLASS 8 ,DELI_PERI 4 int , SUBSI_RATE 4 int //strSql.AppendLine("SELECT * FROM THK_TOLER_INTER WHERE 1=1 "); //strSql.AppendLine(string.Format("AND WAREH_MANAGE_CLASS = '{0}' AND DELI_PERI = '{1}' AND SUBSI_RATE = '{2}' ", insertModel.WAREH_MANAGE_CLASS, insertModel.DELI_PERI, insertModel.SUBSI_RATE)); //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("AddThkToler 报错 : ", ex); } return result; } /// /// 更新接口 /// /// /// [HttpPost, Route("hotRoll/updThkToler")] public RequestEntity UpdThkToler(IList requestData) { RequestEntity result = new RequestEntity(); DataTable dtCheck = new DataTable(); StringBuilder strSql = new StringBuilder(); DateTime dtNow = DateTime.Now; requestData[1].UPD_DATE = dtNow.ToString("yyyyMMdd"); requestData[1].UPD_TIME = dtNow.ToString("HHmmss"); #region 参数判断 if (string.IsNullOrEmpty(requestData[1].PLT) || requestData[1].PLT.Length > 2) { result.msg = "工厂不可为空且长度不可超过2!"; result.code = "0"; return result; } if (string.IsNullOrEmpty(requestData[1].INTER_RANGE) || !CommonUtils.IsNumber(requestData[1].INTER_RANGE) || requestData[1].INTER_RANGE.Length > 3) { result.msg = "交集范围不可为空且是长度不超过3的数字!"; result.code = "0"; return result; } #endregion try { using (IDbContext db = ObjectContainer.GetObject("db")) { // 查询是否有主键相同数据 //PK 10, //WAREH_MANAGE_CLASS 8 ,DELI_PERI 4 int , SUBSI_RATE 4 int //strSql.AppendLine("SELECT * FROM THK_TOLER_INTER WHERE 1=1 "); //strSql.AppendLine(string.Format("AND WAREH_MANAGE_CLASS = '{0}' AND DELI_PERI = '{1}' AND SUBSI_RATE = '{2}' ", requestData[1].WAREH_MANAGE_CLASS, requestData[1].DELI_PERI, requestData[1].SUBSI_RATE)); //// 执行主键重复查询 //dtCheck = db.Query(strSql.ToString()); //if (dtCheck.Rows.Count > 0 ) // 若数据库中存在则返回错误码0并msg提示用户 //{ // result.msg = "数据已存在,请确认后重试!"; // result.code = "0"; //} //else //{ //更新哪些字段 //WAREH_MANAGE_CLASS 8 ,DELI_PERI 4 int , SUBSI_RATE 4 int if (db.Execute("UPDATE THK_TOLER_INTER SET " + string.Format(" PLT = '{0}', INTER_RANGE ='{1}',UPD_DATE ='{2}',UPD_TIME='{3}',UPD_EMP = '{4}',LOWER_LIMIT_EXCEEDING = '{5}',THK_MAX = '{6}',THK_MIN = '{7}' " , requestData[1].PLT , requestData[1].INTER_RANGE , requestData[1].UPD_DATE , requestData[1].UPD_TIME , requestData[1].UPD_EMP , requestData[1].LOWER_LIMIT_EXCEEDING , requestData[1].THK_MAX , requestData[1].THK_MIN) + //根据主键字段可以确定唯一数据即要修改的数据 //PK string.Format("WHERE 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("UpdThkToler 报错", ex); return result; } } /// /// 删除接口 /// /// /// [HttpPost, Route("hotRoll/delThkToler")] public RequestEntity DelThkToler(THK_TOLER_INTER delModel) { RequestEntity result = new RequestEntity(); StringBuilder strSql = new StringBuilder(); try { //PK strSql.AppendLine("DELETE FROM THK_TOLER_INTER WHERE 1=1 "); strSql.AppendLine(string.Format("AND PK = '{0}' ", delModel.PK)); 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("DelThkToler 报错", ex); } return result; } } }