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.

354 lines
17 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月25日
* 创建者: 李跃升
* Copy Right: 北京科技大学设计研究院有限公司
********************************************************/
namespace ibk.IPD.Controller.IPD_MR.StdMgt
{
[RoutePrefix("ipd/ipdMr")]
public class TopEndCutController : ApiController
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/getTopEndCut")]
public RequestEntity GetTopEndCut(EpTopEndStdQueryArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
//查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss
//PLT 工厂 , PRC_LINE 机号 , STLGRD 钢种 , BASIC_CUT_LEN 标准切割长度 , TOP_CUT_LEN 头坯切割长度 , BOTTOM_CUT_LEN 尾坯切割长度
strSql.AppendLine("SELECT PLT,PRC_LINE,STLGRD,STLGRD,BASIC_CUT_LEN ,TOP_CUT_LEN ,BOTTOM_CUT_LEN ,to_date(UPD_DATE || UPD_TIME,'yyyy-mm-dd hh24:mi:ss') as UPD_DATE,UPD_TIME,UPD_EMP,to_date(INS_DATE || INS_TIME,'yyyy-mm-dd hh24:mi:ss') as INS_DATE,INS_TIME,INS_EMP FROM EP_TOP_END_STD WHERE 1=1");
if (queryArgs != null)
{
if (!string.IsNullOrWhiteSpace(queryArgs.PLT)) strSql.AppendLine(" AND PLT LIKE '%" + queryArgs.PLT + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.PRC_LINE)) strSql.AppendLine(" AND PRC_LINE LIKE '%" + queryArgs.PRC_LINE + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.START_BASIC_CUT_LEN) && CommonUtils.IsNumber(queryArgs.START_BASIC_CUT_LEN)) strSql.AppendLine(" AND BASIC_CUT_LEN >=" + queryArgs.START_BASIC_CUT_LEN);
if (!string.IsNullOrWhiteSpace(queryArgs.END_BASIC_CUT_LEN) && CommonUtils.IsNumber(queryArgs.END_BASIC_CUT_LEN)) strSql.AppendLine(" AND BASIC_CUT_LEN <=" + queryArgs.END_BASIC_CUT_LEN);
if (!string.IsNullOrWhiteSpace(queryArgs.STLGRD)) strSql.AppendLine(" AND STLGRD LIKE '%" + queryArgs.STLGRD + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.START_TOP_CUT_LEN) && CommonUtils.IsNumber(queryArgs.START_TOP_CUT_LEN)) strSql.AppendLine(" AND TOP_CUT_LEN >= " + queryArgs.START_TOP_CUT_LEN);
if (!string.IsNullOrWhiteSpace(queryArgs.END_TOP_CUT_LEN) && CommonUtils.IsNumber(queryArgs.END_TOP_CUT_LEN)) strSql.AppendLine(" AND TOP_CUT_LEN <= " + queryArgs.END_TOP_CUT_LEN);
if (!string.IsNullOrWhiteSpace(queryArgs.START_BOTTOM_CUT_LEN) && CommonUtils.IsNumber(queryArgs.START_BOTTOM_CUT_LEN)) strSql.AppendLine(" AND BOTTOM_CUT_LEN >= " + queryArgs.START_BOTTOM_CUT_LEN);
if (!string.IsNullOrWhiteSpace(queryArgs.END_BOTTOM_CUT_LEN) && CommonUtils.IsNumber(queryArgs.END_BOTTOM_CUT_LEN)) strSql.AppendLine(" AND BOTTOM_CUT_LEN <= " + queryArgs.END_BOTTOM_CUT_LEN);
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 INS_DATE DESC");
result.data = db.Query<EP_TOP_END_STD>(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("GetTopEndCut 报错 : ", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/addTopEndCut")]
public RequestEntity AddTopEndCut(EP_TOP_END_STD insertModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
DateTime dtNow = DateTime.Now;
try
{
#region 参数判断
//PLT 工厂 , PRC_LINE 机号 , STLGRD 钢种 , BASIC_CUT_LEN 标准切割长度 , TOP_CUT_LEN 头坯切割长度 , BOTTOM_CUT_LEN 尾坯切割长度
if (string.IsNullOrEmpty(insertModel.PLT) || insertModel.PLT.Length > 2)
{
result.msg = "工厂不可为空且长度不可超过2";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.PRC_LINE) || insertModel.PRC_LINE.Length > 1)
{
result.msg = "连铸机号不可为空且长度不可超过1";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.STLGRD) || insertModel.STLGRD.Length > 11)
{
result.msg = "钢种不可为空且长度不可超过11或不是数字";
result.code = "0";
return result;
}
//--------------------------------------------------------------------------
if (!string.IsNullOrEmpty(insertModel.BASIC_CUT_LEN))
if (insertModel.BASIC_CUT_LEN.Length > 6 || !CommonUtils.IsNumber(insertModel.BASIC_CUT_LEN))
{
result.msg = "标准切割长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.TOP_CUT_LEN))
if (insertModel.TOP_CUT_LEN.Length > 4 || !CommonUtils.IsNumber(insertModel.TOP_CUT_LEN))
{
result.msg = "头坯切割长度不可超过4或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.BOTTOM_CUT_LEN))
if (insertModel.BOTTOM_CUT_LEN.Length > 4 || !CommonUtils.IsNumber(insertModel.BOTTOM_CUT_LEN))
{
result.msg = "尾坯切割长度不可超过4或不是数字";
result.code = "0";
return result;
}
//--------------------------------------------------------------------------
#endregion
// 拼接主键重复check查询语句
////PLT 工厂 , PRC_LINE 机号 , STLGRD 钢种 ,
///BASIC_CUT_LEN 标准切割长度 , TOP_CUT_LEN 头坯切割长度 , BOTTOM_CUT_LEN 尾坯切割长度
strSql.AppendLine("SELECT * FROM EP_TOP_END_STD WHERE 1=1 ");
strSql.AppendLine(string.Format("AND PLT = '{0}' AND PRC_LINE = '{1}' AND STLGRD = '{2}' ", insertModel.PLT, insertModel.PRC_LINE, insertModel.STLGRD));
insertModel.INS_DATE = dtNow.ToString("yyyyMMdd");
insertModel.INS_TIME = dtNow.ToString("HHmmss");
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
// 执行主键重复查询
DataTable dtCheck = db.Query(strSql.ToString());
if (dtCheck.Rows.Count > 0) // 若数据库中存在则返回错误码0并msg提示用户
{
result.msg = "数据已存在,请确认后重试!";
result.code = "0";
return result;
}
if (db.Insert<EP_TOP_END_STD>(insertModel) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddTopEndCut 报错 : ", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/updTopEndCut")]
public RequestEntity UpdTopEndCut(IList<EP_TOP_END_STD> 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;
}
//PLT 工厂 , PRC_LINE 机号 , STLGRD 钢种 , BASIC_CUT_LEN 标准切割长度 , TOP_CUT_LEN 头坯切割长度 , BOTTOM_CUT_LEN 尾坯切割长度
if (string.IsNullOrEmpty(requestData[1].PLT) || requestData[1].PLT.Length > 2)
{
result.msg = "工厂不可为空且长度不可超过2";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].PRC_LINE) || requestData[1].PRC_LINE.Length > 1)
{
result.msg = "机号不可为空且长度不可超过1";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].STLGRD) || requestData[1].STLGRD.Length > 11)
{
result.msg = "钢种不可为空且长度不可超过11或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].BASIC_CUT_LEN))
if (requestData[1].BASIC_CUT_LEN.Length > 15 || !CommonUtils.IsNumber(requestData[1].BASIC_CUT_LEN))
{
result.msg = "标准切割长度不可超过15或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].TOP_CUT_LEN))
if (requestData[1].TOP_CUT_LEN.Length > 15 || !CommonUtils.IsNumber(requestData[1].TOP_CUT_LEN))
{
result.msg = "头坯切割长度不可超过15或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].BOTTOM_CUT_LEN))
if (requestData[1].BOTTOM_CUT_LEN.Length > 15 || !CommonUtils.IsNumber(requestData[1].BOTTOM_CUT_LEN))
{
result.msg = "尾坯切割长度不可超过15或不是数字";
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"))
{
// 查询是否有相同数据
////PLT 工厂 , PRC_LINE 机号 , STLGRD 钢种 ,
///BASIC_CUT_LEN 标准切割长度 , TOP_CUT_LEN 头坯切割长度 , BOTTOM_CUT_LEN 尾坯切割长度
strSql.AppendLine("SELECT * FROM EP_TOP_END_STD WHERE 1=1 ");
strSql.AppendLine(string.Format("AND PLT = '{0}' AND PRC_LINE = '{1}' AND STLGRD = '{2}' ", requestData[1].PLT, requestData[1].PRC_LINE, requestData[1].STLGRD));
strSqlSelf.AppendLine("SELECT * FROM EP_TOP_END_STD WHERE 1=1 ");
strSqlSelf.AppendLine(string.Format("AND PLT = '{0}' AND PRC_LINE = '{1}' AND STLGRD = '{2}' ", requestData[0].PLT, requestData[0].PRC_LINE, 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
{
//更新哪些字段
//PLT 工厂 , PRC_LINE 机号 , STLGRD 钢种 ,
//BASIC_CUT_LEN 标准切割长度 , TOP_CUT_LEN 头坯切割长度 , BOTTOM_CUT_LEN 尾坯切割长度
if (db.Execute("UPDATE EP_TOP_END_STD SET " + string.Format(" PLT = '{0}' , PRC_LINE = '{1}', STLGRD = '{2}' , BASIC_CUT_LEN = '{3}', TOP_CUT_LEN = '{4}', BOTTOM_CUT_LEN = '{5}' , UPD_DATE = '{6}',UPD_TIME='{7}',UPD_EMP = '{8}' ", requestData[1].PLT, requestData[1].PRC_LINE, requestData[1].STLGRD, requestData[1].BASIC_CUT_LEN, requestData[1].TOP_CUT_LEN, requestData[1].BOTTOM_CUT_LEN, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP) +
//根据主键字段可以确定唯一数据即要修改的数据
//PLT, PRC_LINE, THK, STLGRD
string.Format("WHERE 1=1 AND PLT = '{0}' AND PRC_LINE = '{1}' AND STLGRD = '{2}' ", requestData[0].PLT, requestData[0].PRC_LINE, 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("UpdTopEndCut 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/delTopEndCut")]
public RequestEntity DelCcmLossStd(EP_TOP_END_STD delModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
try
{
//PLT, PRC_LINE, THK, STLGRD
strSql.AppendLine("DELETE FROM EP_TOP_END_STD WHERE 1=1 ");
strSql.AppendLine(string.Format("AND PLT = '{0}' AND PRC_LINE = '{1}' AND STLGRD = '{2}' ", delModel.PLT, delModel.PRC_LINE, 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("DelTopEndCut 报错", ex);
}
return result;
}
}
}