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.

289 lines
13 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.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月01日
* 创建者: 李跃升
* Copy Right: 北京科技大学设计研究院有限公司
********************************************************/
namespace ibk.IPD.Controller.IPD_MR.HotRoll
{
[RoutePrefix("ipd/ipdMr")]
public class ReplaceableOnWaySteelPlateController : ApiController
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/getReplaceableOnWaySteelPlate")]
public RequestEntity GetReplaceableOnWaySteelPlate(OnwayPlaFungibleSpeciQueryArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
DataTable dtCheck = new DataTable();
//查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss
//PK 10, START_LIBRARY 10 ,END_LIBRARY 10 , CUT_ABILITY 2
strSql.AppendLine("SELECT START_LIBRARY,END_LIBRARY,CUT_ABILITY,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 ,case SUB_TYPE when 'C' then '完全替代' else '部分替代' end SUB_TYPE from ONWAY_PLA_FUNGIBLE_SPECI WHERE 1=1");
if (queryArgs != null)
{
//if()
if (!string.IsNullOrEmpty(queryArgs.START_LIBRARY))
strSql.AppendLine(" AND START_LIBRARY LIKE '%" + queryArgs.START_LIBRARY + "%'");
if (!string.IsNullOrEmpty(queryArgs.END_LIBRARY))
strSql.AppendLine(" AND END_LIBRARY LIKE '%" + queryArgs.END_LIBRARY + "%'");
if (!string.IsNullOrEmpty(queryArgs.CUT_ABILITY))
strSql.AppendLine(" AND CUT_ABILITY LIKE '%" + queryArgs.CUT_ABILITY + "%'");
//if (queryArgs.START_TIME == DateTime.MinValue && queryArgs.END_TIME == DateTime.MinValue )
//{
// queryArgs.START_TIME = DateTime.Now.AddDays(-2);
// queryArgs.END_TIME = DateTime.Now;
// strSql.AppendLine(" AND to_date(a.SUB_DATE ,'yyyy-mm-dd hh24:mi:ss') >= to_date('" + CommonUtils.ObjectToStr(queryArgs.START_TIME.ToString("yyyy-MM-dd")) + "','yyyy-mm-dd hh24:mi:ss')");
// strSql.AppendLine(" AND to_date(a.SUB_DATE ,'yyyy-mm-dd hh24:mi:ss') < to_date('" + CommonUtils.ObjectToStr(queryArgs.END_TIME.AddDays(1)) + "','yyyy-mm-dd hh24:mi:ss')");
//}
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");
dtCheck = db.Query(strSql.ToString());
//result.data = db.Query<ONWAY_PLA_FUNGIBLE_SPECI>(strSql.ToString());
if (dtCheck.Rows.Count > 0)
{
result.data = dtCheck;
result.msg = "操作成功!";
result.code = "1";
}
else
{
result.msg = "未找到查询所需数据!";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("GetReplaceableOnWaySteelPlate 报错", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/addReplaceableOnWaySteelPlate")]
public RequestEntity AddReplaceableOnWaySteelPlate(ONWAY_PLA_FUNGIBLE_SPECI insertModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
DateTime dtNow = DateTime.Now;
try
{
#region 参数判断
//PK 10, START_LIBRARY 10 ,END_LIBRARY 10 , CUT_ABILITY 2
if (string.IsNullOrEmpty(insertModel.START_LIBRARY) || insertModel.START_LIBRARY.Length > 10)
{
result.msg = "起始库不可为空且长度不可超过10";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.END_LIBRARY) || insertModel.END_LIBRARY.Length > 10 )
{
result.msg = "目标库不可为空且长度不可超过10";
result.code = "0";
return result;
}
//if (string.IsNullOrEmpty(insertModel.CUT_ABILITY) || (!"Y".Equals(insertModel.CUT_ABILITY )&& !"N".Equals(insertModel.CUT_ABILITY)))
//{
// result.msg = "切割能力不可为空且只能是 Y(有) 或 N(无) ";
// result.code = "0";
// return result;
//}
#endregion
// 拼接主键重复check查询语句
//PK 10, START_LIBRARY 10 ,END_LIBRARY 10 , CUT_ABILITY 2
strSql.AppendLine("SELECT * FROM ONWAY_PLA_FUNGIBLE_SPECI WHERE 1=1 ");
strSql.AppendLine(string.Format("AND START_LIBRARY = '{0}' AND END_LIBRARY = '{1}' AND CUT_ABILITY = '{2}' ", insertModel.START_LIBRARY, insertModel.END_LIBRARY, insertModel.CUT_ABILITY));
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<ONWAY_PLA_FUNGIBLE_SPECI>(insertModel) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddReplaceableOnWaySteelPlate 报错 : ", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/updReplaceableOnWaySteelPlate")]
public RequestEntity UpdReplaceableOnWaySteelPlate(IList<ONWAY_PLA_FUNGIBLE_SPECI> requestData)
{
RequestEntity result = new RequestEntity();
DataTable dtCheck = new DataTable();
StringBuilder strSql = new StringBuilder();
DateTime dtNow = DateTime.Now;
requestData[1].UPD_DATE = dtNow.ToString("yyyyMMdd");
requestData[1].UPD_TIME = dtNow.ToString("HHmmss");
#region 参数判断
//PK 10, START_LIBRARY 10 ,END_LIBRARY 10 , CUT_ABILITY 2
if (string.IsNullOrEmpty(requestData[1].START_LIBRARY) || requestData[1].START_LIBRARY.Length > 10)
{
result.msg = "起始库不可为空且长度不可超过10";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].END_LIBRARY) || requestData[1].END_LIBRARY.Length > 10)
{
result.msg = "目标库不可为空且长度不可超过10";
result.code = "0";
return result;
}
#endregion
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
// 查询是否有主键相同数据
//PK 10,
//START_LIBRARY 10 ,END_LIBRARY 10 , CUT_ABILITY 2
strSql.AppendLine("SELECT * FROM ONWAY_PLA_FUNGIBLE_SPECI WHERE 1=1 ");
strSql.AppendLine(string.Format("AND START_LIBRARY = '{0}' AND END_LIBRARY = '{1}' ", requestData[1].START_LIBRARY, requestData[1].END_LIBRARY));
// 执行主键重复查询
//dtCheck = db.Query(strSql.ToString());
//if (dtCheck.Rows.Count > 0) // 若数据库中存在则返回错误码0并msg提示用户
//{
// result.msg = "数据已存在,请确认后重试!";
// result.code = "0";
//}
//else
//{
string str = "UPDATE ONWAY_PLA_FUNGIBLE_SPECI SET "
+ string.Format(" START_LIBRARY = '{0}' , END_LIBRARY = '{1}' , UPD_DATE = '{2}',UPD_TIME='{3}',UPD_EMP = '{4}',SUB_TYPE = '{5}' ", requestData[1].START_LIBRARY, requestData[1].END_LIBRARY, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP, requestData[1].SUB_TYPE == "完全替代" ? "C" : "P") + string.Format("WHERE PK = '{0}' ", requestData[0].PK) ;
//+string.Format("WHERE PK = '{0}' ", requestData[0].PK);
//更新哪些字段
//START_LIBRARY 10 ,END_LIBRARY 10 , CUT_ABILITY 2
if (db.Execute(str) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
else
{
result.msg = "数据未发生改变,请确认后重试!";
result.code = "0";
}
//}
return result;
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("UpdReplaceableOnWaySteelPlate 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/delReplaceableOnWaySteelPlate")]
public RequestEntity DelReplaceableOnWaySteelPlate(ONWAY_PLA_FUNGIBLE_SPECI delModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
try
{
//PK
strSql.AppendLine("DELETE FROM ONWAY_PLA_FUNGIBLE_SPECI WHERE 1=1 ");
strSql.AppendLine(string.Format("AND 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("DelReplaceableOnWaySteelPlate 报错", ex);
}
return result;
}
}
}