|
|
|
|
using ibk.IPD.Common;
|
|
|
|
|
using ibk.IPD.Entity;
|
|
|
|
|
using ibk.IPD.Entity.IPD_MR.HotRoll;
|
|
|
|
|
using ibk.IPD.Entity.IPD_MR.HotRoll.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年04月12日
|
|
|
|
|
* 创建者: 李跃升
|
|
|
|
|
* Copy Right: 北京科技大学设计研究院有限公司
|
|
|
|
|
********************************************************/
|
|
|
|
|
namespace ibk.IPD.Controller.IPD_MR.HotRoll
|
|
|
|
|
{
|
|
|
|
|
[RoutePrefix("ipd/ipdMr")]
|
|
|
|
|
public class AgreementOrdersController : ApiController
|
|
|
|
|
{
|
|
|
|
|
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="queryArgs"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("hotRoll/getAgreementOrders")]
|
|
|
|
|
public RequestEntity GetAgreementOrders(BpOderXyQueryArgs queryArgs)
|
|
|
|
|
{
|
|
|
|
|
RequestEntity result = new RequestEntity(); //声明返回参数实体类
|
|
|
|
|
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
|
|
|
|
|
DataTable dtCheck = new DataTable();
|
|
|
|
|
|
|
|
|
|
//查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss
|
|
|
|
|
//ORDER_NO ORDER_ITEM ORD_XY5 ORD_XY6
|
|
|
|
|
strSql.AppendLine("SELECT ORDER_NO , ORDER_ITEM , ORD_XY5 , ORD_XY6 FROM BP_ODER_XY WHERE 1 = 1 ");
|
|
|
|
|
if (queryArgs != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.ORDER_NO)) strSql.AppendLine(" AND ORDER_NO LIKE '%" + queryArgs.ORDER_NO + "%'");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.ORDER_ITEM)) strSql.AppendLine(" AND ORDER_ITEM LIKE '%" + queryArgs.ORDER_ITEM + "%'");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.ORD_XY5)) strSql.AppendLine(" AND ORD_XY5 LIKE '%" + queryArgs.ORD_XY5 + "%'");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(queryArgs.ORD_XY6)) strSql.AppendLine(" AND ORD_XY6 LIKE '%" + queryArgs.ORD_XY6 + "%'");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//开启数据库连接查询数据
|
|
|
|
|
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
|
|
|
|
|
{
|
|
|
|
|
strSql.AppendLine("ORDER BY ORD_XY6 ");
|
|
|
|
|
dtCheck = db.Query(strSql.ToString());
|
|
|
|
|
result.data = db.Query<BP_ODER_XY>(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("GetAgreementOrders 报错", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="insertModel"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("hotRoll/addAgreementOrders")]
|
|
|
|
|
public RequestEntity AddAgreementOrders(BP_ODER_XY insertModel)
|
|
|
|
|
{
|
|
|
|
|
RequestEntity result = new RequestEntity();
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
#region 参数判断
|
|
|
|
|
if (!ParameterCalibration(insertModel, result))
|
|
|
|
|
return result;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
//insertModel.INS_DATE_TIME = dtNow.ToString("yyyyMMdd 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<BP_ODER_XY>(insertModel) > 0)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "操作成功";
|
|
|
|
|
result.code = "1";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "数据库错误!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
logger.Error("AddAgreementOrders 报错 : ", ex);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="requestData"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("hotRoll/updAgreementOrders")]
|
|
|
|
|
public RequestEntity UpdAgreementOrders(IList<BP_ODER_XY> 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
|
|
|
|
|
{
|
|
|
|
|
//更新哪些字段
|
|
|
|
|
//ORDER_NO ORDER_ITEM ORD_XY5 ORD_XY6
|
|
|
|
|
if (db.Execute("UPDATE BP_ODER_XY SET " + string.Format(" ORDER_NO = '{0}' , ORDER_ITEM = '{1}' , ORD_XY5 = '{2}' , ORD_XY6 = '{3}' WHERE 1 = 1 ",
|
|
|
|
|
requestData[1].ORDER_NO, requestData[1].ORDER_ITEM, requestData[1].ORD_XY5, requestData[1].ORD_XY6) +
|
|
|
|
|
//根据主键字段可以确定唯一数据即要修改的数据
|
|
|
|
|
GetPrimaryKeyString(requestData[0])) > 0)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "操作成功";
|
|
|
|
|
result.code = "1";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.msg = "数据未发生改变,请确认后重试!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "数据库错误!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
logger.Error("UpdAgreementOrders 报错", ex);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="delModel"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("hotRoll/delAgreementOrders")]
|
|
|
|
|
public RequestEntity DelAgreementOrders(BP_ODER_XY delModel)
|
|
|
|
|
{
|
|
|
|
|
RequestEntity result = new RequestEntity();
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//PLT , PROD_CD , TRIM_FL , THK_MIN , THK_MAX , WID_MIN , WID_MAX ,STLGRD
|
|
|
|
|
strSql.AppendLine("DELETE FROM BP_ODER_XY WHERE 1=1 ");
|
|
|
|
|
strSql.AppendLine(GetPrimaryKeyString(delModel));
|
|
|
|
|
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("DelAgreementOrders 报错", ex);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 参数校验
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cncs"></param>
|
|
|
|
|
/// /// <param name="result"></param>
|
|
|
|
|
/// <returns>是否通过参数校验</returns>
|
|
|
|
|
public bool ParameterCalibration(BP_ODER_XY cncs, RequestEntity result)
|
|
|
|
|
{
|
|
|
|
|
if(!string.IsNullOrEmpty(cncs.ORDER_NO))
|
|
|
|
|
if ( cncs.ORDER_NO.Length > 20)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "订单号长度不可超过20!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.ORDER_ITEM))
|
|
|
|
|
if (cncs.ORDER_ITEM.Length > 20)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "订单类别长度不可超过20!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.ORD_XY5))
|
|
|
|
|
if (cncs.ORD_XY5.Length > 20 )
|
|
|
|
|
{
|
|
|
|
|
result.msg = "ORD_XY5长度不可超过20!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(cncs.ORD_XY6))
|
|
|
|
|
if (cncs.ORD_XY6.Length > 20)
|
|
|
|
|
{
|
|
|
|
|
result.msg = "ORD_XY6长度不可超过20!";
|
|
|
|
|
result.code = "0";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取主键的条件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="primaryKeyEntity"></param>
|
|
|
|
|
/// <returns>AND 开头的 主键条件字符串</returns>
|
|
|
|
|
public string GetPrimaryKeyString(BP_ODER_XY primaryKeyEntity)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(primaryKeyEntity.ORDER_NO)) strSql.AppendLine(" AND ORDER_NO = '" + primaryKeyEntity.ORDER_NO + "'");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(primaryKeyEntity.ORDER_ITEM)) strSql.AppendLine(" AND ORDER_ITEM = '" + primaryKeyEntity.ORDER_ITEM + "'");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(primaryKeyEntity.ORD_XY5)) strSql.AppendLine(" AND ORD_XY5 = '" + primaryKeyEntity.ORD_XY5 + "'");
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(primaryKeyEntity.ORD_XY6)) strSql.AppendLine(" AND ORD_XY6 = '" + primaryKeyEntity.ORD_XY6 + "'");
|
|
|
|
|
//ORDER_NO ORDER_ITEM ORD_XY5 ORD_XY6
|
|
|
|
|
return strSql.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取主键查询的sql
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="checkEntity"></param>
|
|
|
|
|
/// <returns>主键查询sql</returns>
|
|
|
|
|
public string GetCheckString(BP_ODER_XY checkEntity)
|
|
|
|
|
{
|
|
|
|
|
string strSql = "SELECT * FROM BP_ODER_XY WHERE 1=1 " + GetPrimaryKeyString(checkEntity);
|
|
|
|
|
return strSql;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|