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.

420 lines
19 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.StdMgt.QueryArgs;
using ibk.IPD.Entity.IpdMr.StdMgt;
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月22日
* 创建者: 李跃升
* Copy Right: 北京科技大学设计研究院有限公司
********************************************************/
namespace ibk.IPD.Controller.IPD_MR.StdMgt
{
[RoutePrefix("ipd/ipdMr")]
public class FurnaceContinuousCastController : ApiController
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/getFurnaceContinuousCast")]
public RequestEntity GetFurnaceContinuousCast(QpNiscoChmcQueryArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
DataTable dtCheck = new DataTable();
//查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss
// STLGRD STLGRD_GRP , STEEL_GRD_DETAIL , STL_SEQ , STLGRD_FL , STL_LQUID_TEMP , STEELCATE , STEELCATECNH , DEPNO
strSql.AppendLine("SELECT STLGRD,STLGRD_GRP,STEEL_GRD_DETAIL,STL_SEQ,STLGRD_FL,STL_LQUID_TEMP,STEELCATE,STEELCATECNH,DEPNO,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 QP_NISCO_CHMC WHERE 1=1");
if (queryArgs != null)
{
if (!string.IsNullOrWhiteSpace(queryArgs.STLGRD)) strSql.AppendLine(" AND STLGRD LIKE '%" + queryArgs.STLGRD + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STLGRD_GRP)) strSql.AppendLine(" AND STLGRD_GRP LIKE '%" + queryArgs.STLGRD_GRP + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STEEL_GRD_DETAIL)) strSql.AppendLine(" AND STEEL_GRD_DETAIL LIKE '%" + queryArgs.STEEL_GRD_DETAIL + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.START_STL_SEQ) && CommonUtils.IsNumber(queryArgs.START_STL_SEQ)) strSql.AppendLine(" AND STL_SEQ >= " + queryArgs.START_STL_SEQ);
if (!string.IsNullOrWhiteSpace(queryArgs.END_STL_SEQ) && CommonUtils.IsNumber(queryArgs.END_STL_SEQ)) strSql.AppendLine(" AND STL_SEQ <= " + queryArgs.END_STL_SEQ);
if (!string.IsNullOrWhiteSpace(queryArgs.STLGRD_FL)) strSql.AppendLine(" AND STLGRD_FL LIKE '%" + queryArgs.STLGRD_FL + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.START_STL_LQUID_TEMP) && CommonUtils.IsNumber(queryArgs.START_STL_LQUID_TEMP)) strSql.AppendLine(" AND STL_LQUID_TEMP >= " + queryArgs.START_STL_LQUID_TEMP);
if (!string.IsNullOrWhiteSpace(queryArgs.END_STL_LQUID_TEMP) && CommonUtils.IsNumber(queryArgs.END_STL_LQUID_TEMP)) strSql.AppendLine(" AND STL_LQUID_TEMP <= " + queryArgs.END_STL_LQUID_TEMP);
if (!string.IsNullOrWhiteSpace(queryArgs.STEELCATE)) strSql.AppendLine(" AND STEELCATE LIKE '%" + queryArgs.STEELCATE + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STEELCATECNH)) strSql.AppendLine(" AND STEELCATECNH LIKE '%" + queryArgs.STEELCATECNH + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.DEPNO)) strSql.AppendLine(" AND DEPNO LIKE '%" + queryArgs.DEPNO + "%'");
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<IDbContext>("db"))
{
strSql.AppendLine("Order By STLGRD_GRP,STL_SEQ ");
dtCheck = db.Query(strSql.ToString());
result.data = db.Query<QP_NISCO_CHMC>(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("GetFurnaceContinuousCast 报错 : ", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/addFurnaceContinuousCast")]
public RequestEntity AddFurnaceContinuousCast(QP_NISCO_CHMC insertModel)
{
RequestEntity result = new RequestEntity();
DataTable dtCheck = new DataTable();
StringBuilder strSql = new StringBuilder();
DateTime dtNow = DateTime.Now;
try
{
#region 参数校验
// STLGRD
// STLGRD_GRP , STEEL_GRD_DETAIL , STL_SEQ , STLGRD_FL , STL_LQUID_TEMP , STEELCATE , STEELCATECNH , DEPNO
if (string.IsNullOrEmpty(insertModel.STLGRD) || insertModel.STLGRD.Length > 11)
{
result.msg = "钢种不可为空且长度不可超过11";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.STLGRD_GRP))
if (insertModel.STLGRD_GRP.Length > 11)
{
result.msg = "钢种组长度不可超过11";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.STEEL_GRD_DETAIL))
if (insertModel.STEEL_GRD_DETAIL.Length > 200)
{
result.msg = "钢种描述长度不可超过200";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.STL_SEQ))
if (insertModel.STL_SEQ.Length > 3 || !CommonUtils.IsNumber(insertModel.STL_SEQ))
{
result.msg = "连浇顺序长度不可超过3或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.STLGRD_FL))
if (!insertModel.STLGRD_FL.Equals("H") && !insertModel.STLGRD_FL.Equals("N"))
{
result.msg = "是否在用只能是H 或 N";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.STL_LQUID_TEMP))
if (insertModel.STL_LQUID_TEMP.Length > 4 || !CommonUtils.IsNumber(insertModel.STL_LQUID_TEMP))
{
result.msg = "STL_LQUID_TEMP 长度不可超过4或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.STEELCATE))
if (insertModel.STEELCATE.Length > 3)
{
result.msg = "钢种分类 长度不可超过3";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.STEELCATECNH))
if (insertModel.STEELCATECNH.Length > 50)
{
result.msg = "钢种分类中文 长度不可超过50";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.DEPNO))
if (insertModel.DEPNO.Length > 2)
{
result.msg = "管理科室 长度不可超过2";
result.code = "0";
return result;
}
#endregion
// 拼接主键重复check查询语句
//STLGRD
strSql.AppendLine("SELECT * FROM QP_NISCO_CHMC WHERE 1=1 ");
strSql.AppendLine(string.Format("AND STLGRD = '{0}'", insertModel.STLGRD));
insertModel.INS_DATE = dtNow.ToString("yyyyMMdd");
insertModel.INS_TIME = dtNow.ToString("HHmmss");
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
// 执行主键重复查询
dtCheck = db.Query(strSql.ToString());
if (dtCheck.Rows.Count > 0) // 若数据库中存在则返回错误码0并msg提示用户
{
result.msg = "主键数据已存在,请确认后重试!";
result.code = "0";
return result;
}
if (db.Insert<QP_NISCO_CHMC>(insertModel) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddFurnaceContinuousCast 报错 : ", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/updFurnaceContinuousCast")]
public RequestEntity UpdFurnaceContinuousCast(IList<QP_NISCO_CHMC> 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;
#region 参数校验
if (requestData == null)
{
result.msg = "传入的参数与需求参数不一致!";
result.code = "0";
return result;
}
if (requestData.Count != 2)
{
result.msg = "数组类型参数不一致,应为2";
result.code = "0";
return result;
}
// STLGRD
// STLGRD_GRP , STEEL_GRD_DETAIL , STL_SEQ , STLGRD_FL , STL_LQUID_TEMP , STEELCATE , STEELCATECNH , DEPNO
if (string.IsNullOrEmpty(requestData[1].STLGRD) || requestData[1].STLGRD.Length > 11)
{
result.msg = "钢种不可为空且长度不可超过11";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].STLGRD_GRP))
if (requestData[1].STLGRD_GRP.Length > 11)
{
result.msg = "钢种组长度不可超过11";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].STEEL_GRD_DETAIL))
if (requestData[1].STEEL_GRD_DETAIL.Length > 200)
{
result.msg = "钢种描述长度不可超过200";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].STL_SEQ))
if (requestData[1].STL_SEQ.Length > 3 || !CommonUtils.IsNumber(requestData[1].STL_SEQ))
{
result.msg = "连浇顺序长度不可超过3或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].STLGRD_FL))
if (!requestData[1].STLGRD_FL.Equals("H") && !requestData[1].STLGRD_FL.Equals("N"))
{
result.msg = "是否在用只能是H 或 N";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].STL_LQUID_TEMP))
if (requestData[1].STL_LQUID_TEMP.Length > 4 || !CommonUtils.IsNumber(requestData[1].STL_LQUID_TEMP))
{
result.msg = "STL_LQUID_TEMP 长度不可超过4或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].STEELCATE))
if (requestData[1].STEELCATE.Length > 3)
{
result.msg = "钢种分类 长度不可超过3";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].STEELCATECNH))
if (requestData[1].STEELCATECNH.Length > 50)
{
result.msg = "钢种分类中文 长度不可超过50";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].DEPNO))
if (requestData[1].DEPNO.Length > 2)
{
result.msg = "管理科室 长度不可超过2";
result.code = "0";
return result;
}
#endregion
requestData[1].UPD_DATE = dtNow.ToString("yyyyMMdd");
requestData[1].UPD_TIME = dtNow.ToString("HHmmss");
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
// 查询是否有主键相同数据
// STLGRD
// STLGRD_GRP , STEEL_GRD_DETAIL , STL_SEQ , STLGRD_FL , STL_LQUID_TEMP , STEELCATE , STEELCATECNH , DEPNO
strSql.AppendLine("SELECT * FROM QP_NISCO_CHMC WHERE 1=1 ");
strSql.AppendLine(string.Format("AND STLGRD = '{0}' ", requestData[1].STLGRD));
strSqlSelf.AppendLine("SELECT * FROM QP_NISCO_CHMC WHERE 1=1 ");
strSqlSelf.AppendLine(string.Format("AND STLGRD = '{0}' ", requestData[0].STLGRD));
// 执行主键重复查询
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
{
//更新哪些字段
// STLGRD
// STLGRD_GRP , STEEL_GRD_DETAIL , STL_SEQ , STLGRD_FL , STL_LQUID_TEMP , STEELCATE , STEELCATECNH , DEPNO
if (db.Execute("UPDATE QP_NISCO_CHMC SET " + string.Format(" STLGRD = '{0}' , STLGRD_GRP = '{1}' , STEEL_GRD_DETAIL = '{2}' , STL_SEQ = '{3}' , STLGRD_FL = '{4}' , STL_LQUID_TEMP = '{5}' , STEELCATE = '{6}' , STEELCATECNH = '{7}' , DEPNO = '{8}', UPD_DATE = '{9}',UPD_TIME='{10}',UPD_EMP = '{11}' ",
requestData[1].STLGRD, requestData[1].STLGRD_GRP, requestData[1].STEEL_GRD_DETAIL, requestData[1].STL_SEQ, requestData[1].STLGRD_FL, requestData[1].STL_LQUID_TEMP, requestData[1].STEELCATE, requestData[1].STEELCATECNH, requestData[1].DEPNO, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP) +
//根据主键字段可以确定唯一数据即要修改的数据
string.Format("WHERE 1=1 AND STLGRD = '{0}' ", requestData[0].STLGRD)) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
else
{
result.msg = "数据未发生改变,请确认后重试!";
result.code = "0";
}
}
return result;
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("UpdFurnaceContinuousCast 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/delFurnaceContinuousCast")]
public RequestEntity DelFurnaceContinuousCast(QP_NISCO_CHMC delModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
try
{
// 拼接主键
//STLGRD
strSql.AppendLine("DELETE FROM QP_NISCO_CHMC WHERE 1=1 ");
strSql.AppendLine(string.Format("AND STLGRD = '{0}'", delModel.STLGRD));
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
// 执行删除数据操作
if (db.Execute(strSql.ToString()) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
else
{
result.msg = "数据未删除";
result.code = "0";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("DelFurnaceContinuousCast 报错", ex);
}
return result;
}
}
}