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.

272 lines
11 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.EquipmentMgt;
using ibk.IPD.Entity.IPD_MR.EquipmentMgt.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日
* 创建者: SunH
* Copy Right: 北京科技大学设计研究院有限公司
********************************************************/
namespace ibk.IPD.Controller.IPD_MR.EquipmentMgt
{
[RoutePrefix("ipd/ipdps")]
public class BofWorkTimeController : 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(BOF_WORK_TIME cncs, RequestEntity result)
{
#region 参数判断
if (string.IsNullOrEmpty(cncs.PLT) || CommonUtils.GetLength(cncs.PLT) > 2)
{
result.msg = "工厂代码不可为空且长度不可超过2";
result.code = "0";
return false;
}
if (string.IsNullOrEmpty(cncs.FUR_NUM) || CommonUtils.GetLength(cncs.FUR_NUM) > 20)
{
result.msg = "炉座号不可为空且长度不可超过20";
result.code = "0";
return false;
}
if (string.IsNullOrEmpty(cncs.STEEL_GRADE) || CommonUtils.GetLength(cncs.STEEL_GRADE) > 200)
{
result.msg = "钢种不可为空且长度不可超过200";
result.code = "0";
return false;
}
if (string.IsNullOrEmpty(cncs.SMELTING_CYCLE_MIN) || CommonUtils.GetLength(cncs.SMELTING_CYCLE_MIN) > 200)
{
result.msg = "冶炼周期最小值不可为空且长度不可超过8";
result.code = "0";
return false;
}
if (string.IsNullOrEmpty(cncs.SMELTING_CYCLE_MAX) || CommonUtils.GetLength(cncs.SMELTING_CYCLE_MAX) > 200)
{
result.msg = "冶炼周期最大值不可为空且长度不可超过8";
result.code = "0";
return false;
}
return true;
#endregion
}
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("EquipmentMgt/getBofWorkTime")]
public RequestEntity GetBofWorkTime(BofWorkTimeQueryArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
DataTable dtCheck = new DataTable();
//查询
//PK , PLT , PLATE_THK_MIN , PLATE_THK_MAX , COILING_TIME
strSql.AppendLine("SELECT PK , PLT , FUR_NUM, STEEL_GRADE, SMELTING_CYCLE_MIN,SMELTING_CYCLE_MAX,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 FROM BOF_WORK_TIME WHERE 1 = 1 ");
if (queryArgs != null)
{
if (!string.IsNullOrWhiteSpace(queryArgs.PLT)) strSql.AppendLine(" AND PLT LIKE '%" + queryArgs.PLT + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.FUR_NUM)) strSql.AppendLine(" AND FUR_NUM LIKE '%" + queryArgs.FUR_NUM + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STEEL_GRADE)) strSql.AppendLine(" AND STEEL_GRADE LIKE '%" + queryArgs.STEEL_GRADE + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.SMELTING_CYCLE_MIN)) strSql.AppendLine(" AND SMELTING_CYCLE_MIN = '" + queryArgs.SMELTING_CYCLE_MIN + "'");
if (!string.IsNullOrWhiteSpace(queryArgs.SMELTING_CYCLE_MAX)) strSql.AppendLine(" AND SMELTING_CYCLE_MAX = '" + queryArgs.SMELTING_CYCLE_MAX + "'");
if (!string.IsNullOrWhiteSpace(queryArgs.STEEL_GRADE)) strSql.AppendLine(" AND STEEL_GRADE LIKE '%" + queryArgs.STEEL_GRADE + "%'");
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 ,'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 ,'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<BOF_WORK_TIME>(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("GetBofWorkTime 报错", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("EquipmentMgt/addBofWorkTime")]
public RequestEntity AddBofWorkTime(BOF_WORK_TIME insertModel)
{
RequestEntity result = new RequestEntity();
DateTime dtNow = DateTime.Now;
try
{
#region 参数判断
if (!ParameterCalibration(insertModel, result))
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<BOF_WORK_TIME>(insertModel) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddBofWorkTime 报错 : ", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("EquipmentMgt/updBofWorkTime")]
public RequestEntity UpdBofWorkTime(IList<BOF_WORK_TIME> 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;
requestData[1].UPD_DATE = dtNow.ToString("yyyyMMdd");
requestData[1].UPD_TIME = dtNow.ToString("HHmmss");
#region 参数判断
if (!ParameterCalibration(requestData[1], result))
return result;
#endregion
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
//更新哪些字段
//PLT , PLATE_THK_MIN , PLATE_THK_MAX , COILING_TIME
if (db.Execute("UPDATE BOF_WORK_TIME SET " + string.Format(" PLT = '{0}' , FUR_NUM = '{1}' , STEEL_GRADE = '{2}' ,SMELTING_CYCLE_MIN = '{3}' , SMELTING_CYCLE_MAX = '{4}' , UPD_DATE = '{5}' , UPD_TIME='{6}',UPD_EMP = '{7}' WHERE 1 = 1 ",
requestData[1].PLT, requestData[1].FUR_NUM, requestData[1].STEEL_GRADE, requestData[1].SMELTING_CYCLE_MIN, requestData[1].SMELTING_CYCLE_MAX, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP) +
//根据主键字段可以确定唯一数据即要修改的数据
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("UpdBofWorkTime 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("EquipmentMgt/delBofWorkTime")]
public RequestEntity DelBofWorkTime(BOF_WORK_TIME delModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
try
{
strSql.AppendLine("DELETE FROM BOF_WORK_TIME 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("DelBofWorkTime 报错", ex);
}
return result;
}
}
}