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.

329 lines
12 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.CapacityAndTime;
using ibk.IPD.Entity.IPD_MR.CapacityAndTime.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月16日
* 创建者: 李跃升
* Copy Right: 北京科技大学设计研究院有限公司
********************************************************/
namespace ibk.IPD.Controller.IPD_MR.CapacityAndTime
{
[RoutePrefix("ipd/ipdMr")]
public class SteelProcessRouteController : 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(PRO_ROUTE cncs, RequestEntity result)
{
#region 参数判断
if (!string.IsNullOrEmpty(cncs.KR))
if (CommonUtils.GetLength(cncs.KR) > 1)
{
result.msg = "脱硫长度不可超过1";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.BOF))
if (CommonUtils.GetLength(cncs.BOF) > 1)
{
result.msg = "转炉长度不可超过1";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.LF))
if (CommonUtils.GetLength(cncs.LF) > 1)
{
result.msg = "精炼长度不可超过1";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.RH))
if (CommonUtils.GetLength(cncs.RH) > 1)
{
result.msg = "RH长度不可超过1";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.CC))
if (CommonUtils.GetLength(cncs.CC) > 1)
{
result.msg = "连铸长度不可超过1";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.STLGRD))
if (CommonUtils.GetLength(cncs.STLGRD) > 100)
{
result.msg = "钢种长度不可超过100";
result.code = "0";
return false;
}
return true;
#endregion
}
/// <summary>
/// 获取主键的条件
/// </summary>
/// <param name="primaryKeyEntity"></param>
/// <returns>AND 开头的 主键条件字符串</returns>
public string GetPrimaryKeyString(PRO_ROUTE primaryKeyEntity)
{
StringBuilder strSql = new StringBuilder();
//if (!string.IsNullOrWhiteSpace(primaryKeyEntity.APLY_ITEM))
//因为主键是自增主键, 所以将判断主键重复换成重复数据判断
strSql.AppendLine(" AND KR = '" + primaryKeyEntity.KR + "'");
strSql.AppendLine(" AND BOF = '" + primaryKeyEntity.BOF + "'");
strSql.AppendLine(" AND LF = '" + primaryKeyEntity.LF + "'");
strSql.AppendLine(" AND RH = '" + primaryKeyEntity.RH + "'");
strSql.AppendLine(" AND CC = '" + primaryKeyEntity.CC + "'");
strSql.AppendLine(" AND STLGRD = '" + primaryKeyEntity.STLGRD + "'");
return strSql.ToString();
}
/// <summary>
/// 获取主键查询的sql
/// </summary>
/// <param name="checkEntity"></param>
/// <returns>主键查询sql</returns>
public string GetCheckString(PRO_ROUTE checkEntity)
{
string strSql = "SELECT * FROM PRO_ROUTE WHERE 1=1 " + GetPrimaryKeyString(checkEntity);
return strSql;
}
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("capacityAndTime/getSteelProcessRoute")]
public RequestEntity GetSteelProcessRoute(ProRouteQueryArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
DataTable dtCheck = new DataTable();
//查询
//PK , KR , BOF , LF , RH , CC
strSql.AppendLine("SELECT PK , KR , BOF , LF , RH , CC , STLGRD FROM PRO_ROUTE WHERE 1 = 1 ");
if (queryArgs != null)
{
if (!string.IsNullOrWhiteSpace(queryArgs.KR)) strSql.AppendLine(" AND KR LIKE '%" + queryArgs.KR + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.BOF)) strSql.AppendLine(" AND BOF LIKE '%" + queryArgs.BOF + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.LF)) strSql.AppendLine(" AND LF LIKE '%" + queryArgs.LF + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.RH)) strSql.AppendLine(" AND RH LIKE '%" + queryArgs.RH + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.CC)) strSql.AppendLine(" AND CC LIKE '%" + queryArgs.CC + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STLGRD)) strSql.AppendLine(" AND STLGRD LIKE '%" + queryArgs.STLGRD + "%'");
}
try
{
//开启数据库连接查询数据
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
dtCheck = db.Query(strSql.ToString());
result.data = db.Query<PRO_ROUTE>(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("GetSteelProcessRoute 报错", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("capacityAndTime/addSteelProcessRoute")]
public RequestEntity AddSteelProcessRoute(PRO_ROUTE insertModel)
{
RequestEntity result = new RequestEntity();
try
{
#region 参数判断
if (!ParameterCalibration(insertModel, result))
return result;
#endregion
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<PRO_ROUTE>(insertModel) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddSteelProcessRoute 报错 : ", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("capacityAndTime/updSteelProcessRoute")]
public RequestEntity UpdSteelProcessRoute(IList<PRO_ROUTE> 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 (!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 , KR , BOF , LF , RH , CC , STLGRD
if (db.Execute("UPDATE PRO_ROUTE SET " + string.Format(" KR = '{0}' , BOF = '{1}' , LF = '{2}', RH = '{3}', CC = '{4}' , STLGRD = '{5}' WHERE 1 = 1 ",
requestData[1].KR, requestData[1].BOF, requestData[1].LF, requestData[1].RH, requestData[1].CC, requestData[1].STLGRD) +
//根据主键字段可以确定唯一数据即要修改的数据
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("UpdSteelProcessRoute 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("capacityAndTime/delSteelProcessRoute")]
public RequestEntity DelSteelProcessRoute(PRO_ROUTE delModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
try
{
strSql.AppendLine("DELETE FROM PRO_ROUTE 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("DelSteelProcessRoute 报错", ex);
}
return result;
}
}
}