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.

399 lines
18 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 System;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Http;
using System.Data;
using log4net;
using ibk.IPD.Entity;
using SOA.Expression.Data;
using SOA.Persistent;
using SOA.Objects;
using ibk.IPD.Common;
using ibk.IPD.Entity.IpdMr.StdMgt;
/********************************************************
* 简 介:南钢炼钢制造规范管理
* 板坯尺寸标准后端接口
* 版本号V1.0
* 日 期2022年03月11日
* 创建者: 李跃升
* Copy Right: 北京科技大学设计研究院有限公司
********************************************************/
namespace ibk.IPD.Controller
{
[RoutePrefix("ipd/ipdMr")]
public class SlabDimensionsController : ApiController
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/getSlabDimensions")]
public RequestEntity GetSlabDimensions(EpSlabSizeQueryArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
//查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss
strSql.AppendLine("SELECT PLT" +
",PRC_LINE" +
",THK_MIN" +
",THK_MAX" +
",CON_THK_MAX" +
",WID_MIN" +
",WID_MAX" +
",LEN_MIN" +
",LEN_MAX" +
",WGT_MIN" +
",WGT_MAX" +
",CON_WID_MIN" +
",CON_WID_MAX" +
",CON_LEN_MIN" +
",CON_LEN_MAX" +
",BAN_LEN_MIN_1" +
",BAN_LEN_MAX_1" +
",USE_FL" +
",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 " +
", ID FROM EP_SLAB_SIZE" +
" 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.THK_MIN) && CommonUtils.IsNumber(queryArgs.THK_MIN)) strSql.AppendLine(" AND THK_MIN >= " + queryArgs.THK_MIN );
if (!string.IsNullOrWhiteSpace(queryArgs.THK_MAX) && CommonUtils.IsNumber(queryArgs.THK_MAX)) strSql.AppendLine(" AND THK_MAX <= " + queryArgs.THK_MAX );
if (!string.IsNullOrWhiteSpace(queryArgs.WID_MIN) && CommonUtils.IsNumber(queryArgs.WID_MIN)) strSql.AppendLine(" AND WID_MIN >= " + queryArgs.WID_MIN );
if (!string.IsNullOrWhiteSpace(queryArgs.WID_MAX) && CommonUtils.IsNumber(queryArgs.WID_MAX)) strSql.AppendLine(" AND WID_MAX <= " + queryArgs.WID_MAX);
if (!string.IsNullOrWhiteSpace(queryArgs.LEN_MIN) && CommonUtils.IsNumber(queryArgs.LEN_MIN)) strSql.AppendLine(" AND LEN_MIN >= " + queryArgs.LEN_MIN );
if (!string.IsNullOrWhiteSpace(queryArgs.LEN_MAX) && CommonUtils.IsNumber(queryArgs.LEN_MAX)) strSql.AppendLine(" AND LEN_MAX <= " + queryArgs.LEN_MAX );
if (!string.IsNullOrWhiteSpace(queryArgs.WGT_MIN) && CommonUtils.IsNumber(queryArgs.WGT_MIN)) strSql.AppendLine(" AND WGT_MIN >= " + queryArgs.WGT_MIN );
if (!string.IsNullOrWhiteSpace(queryArgs.WGT_MAX) && CommonUtils.IsNumber(queryArgs.WGT_MAX)) strSql.AppendLine(" AND WGT_MAX <= " + queryArgs.WGT_MAX );
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 PLT ASC");
result.data = db.Query<EP_SLAB_SIZE>(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("getSlabDimensions 报错 : ", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/addSlabDimensions")]
public RequestEntity AddSlabDimensions(EP_SLAB_SIZE insertModel)
{
RequestEntity result = new RequestEntity();
DataTable dtCheck = new DataTable();
DateTime dtNow = DateTime.Now;
try
{
//获取随机主键ID并设置
insertModel.ID = CommonUtils.getGuid();
#region 不可为空字段判断
//PLT, PRC_LINE, THK_MIN, THK_MAX, WID_MIN, WID_MAX, LEN_MIN, LEN_MAX, WGT_MIN, WGT_MAX , ID
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.THK_MIN))
if (!CommonUtils.IsNumber(insertModel.THK_MIN) || insertModel.THK_MIN.Length > 6)
{
result.msg = "厚度下限长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.THK_MAX))
if (!CommonUtils.IsNumber(insertModel.THK_MAX) || insertModel.THK_MAX.Length > 6)
{
result.msg = "厚度上限长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.WID_MIN))
if (!CommonUtils.IsNumber(insertModel.WID_MIN) || insertModel.WID_MIN.Length > 6)
{
result.msg = "宽度下限长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.WID_MAX))
if (!CommonUtils.IsNumber(insertModel.WID_MAX) || insertModel.WID_MAX.Length > 6)
{
result.msg = "宽度上限长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.LEN_MIN))
if (!CommonUtils.IsNumber(insertModel.LEN_MIN) || insertModel.LEN_MIN.Length > 8)
{
result.msg = "长度下限长度不可超过8或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.LEN_MAX))
if (!CommonUtils.IsNumber(insertModel.LEN_MAX) || insertModel.LEN_MAX.Length > 8)
{
result.msg = "长度上限长度不可超过8或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.WGT_MIN))
if (!CommonUtils.IsNumber(insertModel.WGT_MIN) || insertModel.WGT_MIN.Length > 15)
{
result.msg = "重量下限长度不可超过15或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(insertModel.WGT_MAX))
if (!CommonUtils.IsNumber(insertModel.WGT_MAX) || insertModel.WGT_MAX.Length > 15)
{
result.msg = "重量上限长度不可超过15或不是数字";
result.code = "0";
return result;
}
#endregion
insertModel.INS_DATE = dtNow.ToString("yyyyMMdd");
insertModel.INS_TIME = dtNow.ToString("HHmmss");
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
if (db.Insert<EP_SLAB_SIZE>(insertModel) > 0) // 执行插入数据操作
{
result.msg = "操作成功";
result.code = "1";
}
else
{
result.msg = "操作失败";
result.code = "0";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddSlabDimensions 报错", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/updSlabDimensions")]
public RequestEntity UpdSlabDimensions(IList<EP_SLAB_SIZE> requestData)
{
RequestEntity result = new RequestEntity();
DateTime dtNow = DateTime.Now;
requestData[1].UPD_DATE = dtNow.ToString("yyyyMMdd");
requestData[1].UPD_TIME = dtNow.ToString("HHmmss");
#region 不可为空字段判断
//PLT, PRC_LINE, THK_MIN, THK_MAX, WID_MIN, WID_MAX, LEN_MIN, LEN_MAX, WGT_MIN, WGT_MAX
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].THK_MIN))
if (!CommonUtils.IsNumber(requestData[1].THK_MIN) || requestData[1].THK_MIN.Length > 6)
{
result.msg = "厚度下限长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].THK_MAX))
if (!CommonUtils.IsNumber(requestData[1].THK_MAX) || requestData[1].THK_MAX.Length > 6)
{
result.msg = "厚度上限长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].WID_MIN))
if (!CommonUtils.IsNumber(requestData[1].WID_MIN) || requestData[1].WID_MIN.Length > 6)
{
result.msg = "宽度下限长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].WID_MAX))
if (!CommonUtils.IsNumber(requestData[1].WID_MAX) || requestData[1].WID_MAX.Length > 6)
{
result.msg = "宽度上限长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].LEN_MIN))
if (!CommonUtils.IsNumber(requestData[1].LEN_MIN) || requestData[1].LEN_MIN.Length > 8)
{
result.msg = "长度下限长度不可超过8或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].LEN_MAX))
if (!CommonUtils.IsNumber(requestData[1].LEN_MAX) || requestData[1].LEN_MAX.Length > 8)
{
result.msg = "长度上限长度不可超过8或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].WGT_MIN))
if (!CommonUtils.IsNumber(requestData[1].WGT_MIN) || requestData[1].WGT_MIN.Length > 15)
{
result.msg = "重量下限长度不可超过15或不是数字";
result.code = "0";
return result;
}
if (!string.IsNullOrEmpty(requestData[1].WGT_MAX))
if (!CommonUtils.IsNumber(requestData[1].WGT_MAX) || requestData[1].WGT_MAX.Length > 15)
{
result.msg = "重量上限长度不可超过15或不是数字";
result.code = "0";
return result;
}
#endregion
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
//更新哪些字段
if (db.Execute("UPDATE EP_SLAB_SIZE SET " + string.Format(" PLT = '{0}' , PRC_LINE = '{1}' , THK_MIN = '{2}' , THK_MAX = '{3}' , WID_MIN = '{4}' , WID_MAX = '{5}' , LEN_MIN = '{6}' , LEN_MAX = '{7}',WGT_MIN = '{8}', WGT_MAX = '{9}', UPD_DATE = '{10}',UPD_TIME='{11}',UPD_EMP = '{12}' ", requestData[1].PLT, requestData[1].PRC_LINE, requestData[1].THK_MIN, requestData[1].THK_MAX, requestData[1].WID_MIN, requestData[1].WID_MAX, requestData[1].LEN_MIN, requestData[1].LEN_MAX, requestData[1].WGT_MIN, requestData[1].WGT_MAX, requestData[1].UPD_DATE, requestData[1].UPD_TIME,requestData[1].UPD_EMP) +
//根据主键字段可以确定唯一数据即要修改的数据
string.Format("WHERE 1=1 AND ID = '{0}' ", requestData[0].ID)) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
else
{
result.msg = "数据未发生改变,请确认后重试!";
result.code = "0";
}
}
return result;
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("UpdStdMgtInfos 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/delSlabDimensions")]
public RequestEntity DelSlabDimensions(EP_SLAB_SIZE delModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
DataTable dtCheck = new DataTable();
DateTime dtNow = DateTime.Now;
try
{
// 拼接主键,重复check查询语句
strSql.AppendLine("DELETE FROM EP_SLAB_SIZE WHERE 1=1 ");
strSql.AppendLine(string.Format("AND ID = '{0}' ", delModel.ID));
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("AddStdMgtInfos 报错", ex);
}
return result;
}
}
}