|
|
|
|
using ibk.IPD.Common;
|
|
|
|
|
using ibk.IPD.Entity;
|
|
|
|
|
using ibk.IPD.Entity.IPD_MR.InspectionCycle;
|
|
|
|
|
using ibk.IPD.Entity.IPD_MR.InspectionCycle.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年05月24日
|
|
|
|
|
* 创建者: 李跃升
|
|
|
|
|
* Copy Right: 北京科技大学设计研究院有限公司
|
|
|
|
|
********************************************************/
|
|
|
|
|
namespace ibk.IPD.Controller.IPD_MR.InspectionCycle
|
|
|
|
|
{
|
|
|
|
|
[RoutePrefix("ipd/ipdMr")]
|
|
|
|
|
public class TestEquWarnTimeController : 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(TEST_EQU_WARN_TIME cncs, RequestEntity result)
|
|
|
|
|
{
|
|
|
|
|
#region 参数判断
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(cncs.STEEL_GRADE) || CommonUtils.GetLength(cncs.STEEL_GRADE) > 200)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "钢种不可为空且长度不可超过200!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(cncs.IMPACT_TIME) || !CommonUtils.IsNumber(cncs.IMPACT_TIME) || CommonUtils.GetLength(cncs.IMPACT_TIME) > 6)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "冲击时间是长度不可超过6的数字!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(cncs.OUTTURN_SHEET_TIME) || !CommonUtils.IsNumber(cncs.OUTTURN_SHEET_TIME) || CommonUtils.GetLength(cncs.OUTTURN_SHEET_TIME) > 6)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "送样时间是长度不可超过6的数字!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(cncs.STRETCH_TIME) || !CommonUtils.IsNumber(cncs.STRETCH_TIME) || CommonUtils.GetLength(cncs.STRETCH_TIME) > 6)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "拉伸时间是长度不可超过6的数字!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(cncs.WARN_TIME) || !CommonUtils.IsNumber(cncs.WARN_TIME) || CommonUtils.GetLength(cncs.WARN_TIME) > 6)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "总预警时间是长度不可超过6的数字!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取主键的条件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="primaryKeyEntity"></param>
|
|
|
|
|
/// <returns>AND 开头的 主键条件字符串</returns>
|
|
|
|
|
public string GetPrimaryKeyString(TEST_EQU_WARN_TIME primaryKeyEntity)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
//if (!string.IsNullOrWhiteSpace(primaryKeyEntity.APLY_ITEM))
|
|
|
|
|
//因为主键是自增主键, 所以将判断主键重复换成重复数据判断
|
|
|
|
|
strSql.AppendLine(" AND STEEL_GRADE = '" + primaryKeyEntity.STEEL_GRADE + "'");
|
|
|
|
|
strSql.AppendLine(" AND IMPACT_TIME = '" + primaryKeyEntity.IMPACT_TIME + "'");
|
|
|
|
|
strSql.AppendLine(" AND STRETCH_TIME = '" + primaryKeyEntity.STRETCH_TIME + "'");
|
|
|
|
|
strSql.AppendLine(" AND OUTTURN_SHEET_TIME = '" + primaryKeyEntity.OUTTURN_SHEET_TIME + "'");
|
|
|
|
|
strSql.AppendLine(" AND WARN_TIME = '" + primaryKeyEntity.WARN_TIME + "'");
|
|
|
|
|
|
|
|
|
|
return strSql.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取主键查询的sql
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="checkEntity"></param>
|
|
|
|
|
/// <returns>主键查询sql</returns>
|
|
|
|
|
public string GetCheckString(TEST_EQU_WARN_TIME checkEntity)
|
|
|
|
|
{
|
|
|
|
|
string strSql = "SELECT * FROM TEST_EQU_WARN_TIME WHERE 1=1 " + GetPrimaryKeyString(checkEntity);
|
|
|
|
|
return strSql;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="queryArgs"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("inspectionCycle/getTestEquWarnTime")]
|
|
|
|
|
public RequestEntity GetTestEquWarnTime(TestEquWarnTimeQueryArgs queryArgs)
|
|
|
|
|
{
|
|
|
|
|
RequestEntity result = new RequestEntity(); //声明返回参数实体类
|
|
|
|
|
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
|
|
|
|
|
DataTable dtCheck = new DataTable();
|
|
|
|
|
|
|
|
|
|
//查询
|
|
|
|
|
//PK , STEEL_GRADE , IMPACT_TIME , OUTTURN_SHEET_TIME , STRETCH_TIME , WARN_TIME
|
|
|
|
|
strSql.AppendLine("SELECT PK , STEEL_GRADE , IMPACT_TIME , OUTTURN_SHEET_TIME , STRETCH_TIME , WARN_TIME ,to_date(INS_DATE || INS_TIME ,'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 TEST_EQU_WARN_TIME WHERE 1 = 1 ");
|
|
|
|
|
if (queryArgs != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.STEEL_GRADE)) strSql.AppendLine(" AND STEEL_GRADE LIKE '%" + queryArgs.STEEL_GRADE + "%'");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.START_IMPACT_TIME) && CommonUtils.IsNumber(queryArgs.START_IMPACT_TIME)) strSql.AppendLine(" AND IMPACT_TIME >=" + queryArgs.START_IMPACT_TIME);
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.END_IMPACT_TIME) && CommonUtils.IsNumber(queryArgs.END_IMPACT_TIME)) strSql.AppendLine(" AND IMPACT_TIME <=" + queryArgs.END_IMPACT_TIME);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.START_OUTTURN_SHEET_TIME) && CommonUtils.IsNumber(queryArgs.START_OUTTURN_SHEET_TIME)) strSql.AppendLine(" AND OUTTURN_SHEET_TIME >=" + queryArgs.START_OUTTURN_SHEET_TIME);
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.END_OUTTURN_SHEET_TIME) && CommonUtils.IsNumber(queryArgs.END_OUTTURN_SHEET_TIME)) strSql.AppendLine(" AND OUTTURN_SHEET_TIME <=" + queryArgs.END_OUTTURN_SHEET_TIME);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.START_STRETCH_TIME) && CommonUtils.IsNumber(queryArgs.START_STRETCH_TIME)) strSql.AppendLine(" AND STRETCH_TIME >=" + queryArgs.START_STRETCH_TIME);
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.END_STRETCH_TIME) && CommonUtils.IsNumber(queryArgs.END_STRETCH_TIME)) strSql.AppendLine(" AND STRETCH_TIME <=" + queryArgs.END_STRETCH_TIME);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.START_WARN_TIME) && CommonUtils.IsNumber(queryArgs.START_WARN_TIME)) strSql.AppendLine(" AND WARN_TIME >=" + queryArgs.START_WARN_TIME);
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.END_WARN_TIME) && CommonUtils.IsNumber(queryArgs.END_WARN_TIME)) strSql.AppendLine(" AND WARN_TIME <=" + queryArgs.END_WARN_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<TEST_EQU_WARN_TIME>(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("GetTestEquWarnTime 报错", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="insertModel"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("inspectionCycle/addTestEquWarnTime")]
|
|
|
|
|
public RequestEntity AddTestEquWarnTime(TEST_EQU_WARN_TIME 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<TEST_EQU_WARN_TIME>(insertModel) > 0)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "操作成功";
|
|
|
|
|
result.code = "1";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "数据库错误!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
logger.Error("AddTestEquWarnTime 报错 : ", ex);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="requestData"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("inspectionCycle/updTestEquWarnTime")]
|
|
|
|
|
public RequestEntity UpdTestEquWarnTime(IList<TEST_EQU_WARN_TIME> 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
|
|
|
|
|
{
|
|
|
|
|
//更新哪些字段
|
|
|
|
|
//PK , STEEL_GRADE , IMPACT_TIME , OUTTURN_SHEET_TIME , STRETCH_TIME , WARN_TIME
|
|
|
|
|
if (db.Execute("UPDATE TEST_EQU_WARN_TIME SET " + string.Format(" STEEL_GRADE = '{0}' , IMPACT_TIME = '{1}' , OUTTURN_SHEET_TIME = '{2}' ,STRETCH_TIME = '{3}' , WARN_TIME = '{4}' , UPD_DATE = '{5}' , UPD_TIME='{6}',UPD_EMP = '{7}' WHERE 1 = 1 ",
|
|
|
|
|
requestData[1].STEEL_GRADE, requestData[1].IMPACT_TIME, requestData[1].OUTTURN_SHEET_TIME, requestData[1].STRETCH_TIME, requestData[1].WARN_TIME, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP) +
|
|
|
|
|
//根据主键字段可以确定唯一数据即要修改的数据
|
|
|
|
|
string.Format(" AND 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("UpdTestEquWarnTime 报错", ex);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="delModel"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("inspectionCycle/delTestEquWarnTime")]
|
|
|
|
|
public RequestEntity DelTestEquWarnTime(TEST_EQU_WARN_TIME delModel)
|
|
|
|
|
{
|
|
|
|
|
RequestEntity result = new RequestEntity();
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
strSql.AppendLine("DELETE FROM TEST_EQU_WARN_TIME WHERE 1=1 AND");
|
|
|
|
|
strSql.AppendLine(string.Format("PK = {0}", delModel.PK));
|
|
|
|
|
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("DelTestEquWarnTime 报错", ex);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|