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.

366 lines
16 KiB
C#

7 months ago
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
* 20220323
* :
* Copy Right:
********************************************************/
namespace ibk.IPD.Controller.IPD_MR.StdMgt
{
[RoutePrefix("ipd/ipdMr")]
public class MultiGroupFurnaceController : ApiController
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/getMultiGroupFurnace")]
public RequestEntity GetMultiGroupFurnace(CpNiscoChmcNewQueryArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
//查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss
//STLGRD , STLGRD_GRP , STEEL_GRD_DETAIL , STL_SEQ , , STLGRD_FL , STL_LQUID_TEMP
strSql.AppendLine("SELECT t.STLGRD,t.STLGRD_GRP, qnc.STEEL_GRD_DETAIL,t.STL_SEQ,to_date(t.INS_DATE || t.INS_TIME,'yyyy-mm-dd hh24:mi:ss') as INS_DATE,t.INS_TIME,t.INS_EMP,to_date(t.UPD_DATE || t.UPD_TIME,'yyyy-mm-dd hh24:mi:ss') as UPD_DATE,t.UPD_TIME,t.UPD_EMP , t.STLGRD_FL , t.STL_LQUID_TEMP FROM CP_NISCO_CHMC_NEW t left join qp_nisco_chmc qnc on qnc.stlgrd=t.stlgrd 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(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");
result.data = db.Query<CP_NISCO_CHMC_NEW>(strSql.ToString());
DataTable dtCheck = 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("GetMultiGroupFurnace 报错 : ", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/addMultiGroupFurnace")]
public RequestEntity AddMultiGroupFurnace(CP_NISCO_CHMC_NEW insertModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
DataTable dtCheck = new DataTable();
DateTime dtNow = DateTime.Now;
try
{
#region 参数校验
//STLGRD , STLGRD_GRP , STEEL_GRD_DETAIL , STL_SEQ , , STLGRD_FL , STL_LQUID_TEMP
if (string.IsNullOrEmpty(insertModel.STLGRD))
{
result.msg = "钢种不可为空!";
result.code = "0";
return result;
}
if (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 != "N" && insertModel.STLGRD_FL != "H")
{
result.msg = "是否在用只能是 N 或 H ";
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;
}
#endregion
// 拼接主键重复check查询语句
//STLGRD
strSql.AppendLine("SELECT * FROM CP_NISCO_CHMC_NEW 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<CP_NISCO_CHMC_NEW>(insertModel) > 0) // 执行插入数据操作
{
result.msg = "操作成功";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddMultiGroupFurnace 报错", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/updMultiGroupFurnace")]
public RequestEntity UpdMultiGroupFurnace(IList<CP_NISCO_CHMC_NEW> 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;
try
{
#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
if (string.IsNullOrEmpty(requestData[1].STLGRD))
{
result.msg = "钢种不可为空!";
result.code = "0";
return result;
}
if (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 = "是否在用只能是 N 或 H ";
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;
}
#endregion
requestData[1].INS_DATE = dtNow.ToString("yyyyMMdd");
requestData[1].INS_TIME = dtNow.ToString("HHmmss");
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
//查询数据是否存在
//STLGRD , STLGRD_GRP , STEEL_GRD_DETAIL , STL_SEQ , , STLGRD_FL , STL_LQUID_TEMP
strSql.AppendLine("SELECT * FROM CP_NISCO_CHMC_NEW WHERE 1=1 ");
strSql.AppendLine(string.Format("AND STLGRD = '{0}' ", requestData[1].STLGRD));
strSqlSelf.AppendLine("SELECT * FROM CP_NISCO_CHMC_NEW 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
if (db.Execute("UPDATE CP_NISCO_CHMC_NEW SET " + string.Format("STLGRD = '{0}' , STLGRD_GRP = '{1}' , STEEL_GRD_DETAIL = '{2}' , STL_SEQ = '{3}', UPD_DATE = '{4}',UPD_TIME='{5}',UPD_EMP = '{6}',STLGRD_FL = '{7}',STL_LQUID_TEMP='{8}' ",
requestData[1].STLGRD, requestData[1].STLGRD_GRP, requestData[1].STEEL_GRD_DETAIL, requestData[1].STL_SEQ, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP, requestData[1].STLGRD_FL, requestData[1].STL_LQUID_TEMP) +
//根据主键字段可以确定唯一数据即要修改的数据
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("UpdMultiGroupFurnace 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/delMultiGroupFurnace")]
public RequestEntity DelMultiGroupFurnace(CP_NISCO_CHMC_NEW delModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
try
{
//STLGRD
strSql.AppendLine("DELETE FROM CP_NISCO_CHMC_NEW WHERE 1=1 ");
strSql.AppendLine(string.Format("AND STLGRD = '{0}' ", delModel.STLGRD));
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("DelMultiGroupFurnace 报错", ex);
}
return result;
}
}
}