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.

346 lines
15 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月12日
* 创建者: 李跃升
* Copy Right: 北京科技大学设计研究院有限公司
********************************************************/
namespace ibk.IPD.Controller.IPD_MR.HotRoll
{
[RoutePrefix("ipd/ipdMr")]
public class MultipleStandardsController : ApiController
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/getMultipleStandards")]
public RequestEntity GetMultipleStandards(CpNiscoChmcSlQueryArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
DataTable dtCheck = new DataTable();
//查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss
//STLGRD , STEEL_GRD_DETAIL , STL_SEQ , STDSPEC , THK_MIN , THK_MAX , STLGRD_FL , ZZ_PLT , ZZ_PLT_DESP
strSql.AppendLine("SELECT STLGRD , STEEL_GRD_DETAIL ,STL_SEQ , STDSPEC , THK_MIN , THK_MAX , STLGRD_FL , ZZ_PLT , ZZ_PLT_DESP , to_date(UPD_DATE || UPD_TIME ,'yyyy-mm-dd hh24:mi:ss') as UPD_DATE, UPD_TIME,UPD_EMP,TO_DATE(NVL(INS_DATE, '19910101') || NVL(INS_TIME, '000000'), 'yyyy-mm-dd hh24:mi:ss') as INS_DATE,INS_TIME,INS_EMP FROM CP_NISCO_CHMC_SL WHERE 1 = 1 ");
if (queryArgs != null)
{
if (!string.IsNullOrWhiteSpace(queryArgs.STLGRD)) strSql.AppendLine(" AND STLGRD LIKE '%" + queryArgs.STLGRD + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STEEL_GRD_DETAIL)) strSql.AppendLine(" AND STEEL_GRD_DETAIL LIKE '%" + queryArgs.STEEL_GRD_DETAIL + "%'");
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.STL_SEQ) && CommonUtils.IsNumber(queryArgs.STL_SEQ)) strSql.AppendLine(" AND STL_SEQ >=" + queryArgs.STL_SEQ);
if (!string.IsNullOrWhiteSpace(queryArgs.STLGRD)) strSql.AppendLine(" AND STLGRD LIKE '%" + queryArgs.STLGRD + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STDSPEC)) strSql.AppendLine(" AND STDSPEC LIKE '%" + queryArgs.STDSPEC + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.ZZ_PLT)) strSql.AppendLine(" AND ZZ_PLT LIKE '%" + queryArgs.ZZ_PLT + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.STLGRD_FL)) strSql.AppendLine(" AND STLGRD_FL LIKE '%" + queryArgs.STLGRD_FL + "%'");
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 ZZ_PLT,STL_SEQ");
dtCheck = db.Query(strSql.ToString());
result.data = db.Query<CP_NISCO_CHMC_SL>(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("GetMultipleStandards 报错", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/addMultipleStandards")]
public RequestEntity AddMultipleStandards(CP_NISCO_CHMC_SL 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"))
{
// 执行主键重复查询
DataTable dtCheck = db.Query(GetCheckString(insertModel));
if (dtCheck.Rows.Count > 0) // 若数据库中存在则返回错误码0并msg提示用户
{
result.msg = "数据已存在,请确认后重试!";
result.code = "0";
return result;
}
if (db.Insert<CP_NISCO_CHMC_SL>(insertModel) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddMultipleStandards 报错 : ", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/updMultipleStandards")]
public RequestEntity UpdMultipleStandards(IList<CP_NISCO_CHMC_SL> 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"))
{
// 执行主键重复查询
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
{
//更新哪些字段
//
if (db.Execute("UPDATE CP_NISCO_CHMC_SL SET " + string.Format(" STLGRD = '{0}' , STEEL_GRD_DETAIL = '{1}' , STL_SEQ = '{2}' , THK_MIN = '{3}' , THK_MAX = '{4}',STDSPEC = '{5}' ,STLGRD_FL = '{6}' , ZZ_PLT = '{7}' , ZZ_PLT_DESP = '{8}' , UPD_DATE = '{9}' , UPD_TIME='{10}',UPD_EMP = '{11}' WHERE 1 = 1 ",
requestData[1].STLGRD, requestData[1].STEEL_GRD_DETAIL, requestData[1].STL_SEQ, requestData[1].THK_MIN, requestData[1].THK_MAX, requestData[1].STDSPEC, requestData[1].STLGRD_FL, requestData[1].ZZ_PLT, requestData[1].ZZ_PLT_DESP, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP) +
//根据主键字段可以确定唯一数据即要修改的数据
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("UpdMultipleStandards 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/delMultipleStandards")]
public RequestEntity DelMultipleStandards(CP_NISCO_CHMC_SL 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 CP_NISCO_CHMC_SL 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("DelMultipleStandards 报错", ex);
}
return result;
}
/// <summary>
/// 参数校验
/// </summary>
/// <param name="cncs"></param>
/// /// <param name="result"></param>
/// <returns>是否通过参数校验</returns>
public bool ParameterCalibration(CP_NISCO_CHMC_SL cncs , RequestEntity result)
{
if (string.IsNullOrEmpty(cncs.STLGRD) || cncs.STLGRD.Length > 11)
{
result.msg = "钢种不可为空且长度不可超过11";
result.code = "0";
return false;
}
if(!string.IsNullOrEmpty(cncs.STEEL_GRD_DETAIL))
if ( cncs.STEEL_GRD_DETAIL.Length > 200)
{
result.msg = "钢种描述长度不可超过200";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.STL_SEQ))
if (cncs.STL_SEQ.Length > 3 || !CommonUtils.IsNumber(cncs.STL_SEQ))
{
result.msg = "优先顺序长度不可超过3 或不是数字!";
result.code = "0";
return false;
}
if (string.IsNullOrEmpty(cncs.STDSPEC) || cncs.STDSPEC.Length > 60)
{
result.msg = "替代标准不可为空且长度不可超过60";
result.code = "0";
return false;
}
if (string.IsNullOrEmpty(cncs.THK_MIN) || cncs.THK_MIN.Length > 6 || !CommonUtils.IsNumber(cncs.THK_MIN))
{
result.msg = "厚度最小 ( > ) 不可为空且长度不可超过6";
result.code = "0";
return false;
}
if (string.IsNullOrEmpty(cncs.THK_MAX) || cncs.THK_MAX.Length > 6 || !CommonUtils.IsNumber(cncs.THK_MAX))
{
result.msg = "厚度最大 ( <= ) 不可为空且长度不可超过6";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.STLGRD_FL))
if (!"Y".Equals(cncs.STLGRD_FL) && !"N".Equals(cncs.STLGRD_FL))
{
result.msg = "是否在用只能是 Y 或 N ";
result.code = "0";
return false;
}
if (string.IsNullOrEmpty(cncs.ZZ_PLT) || cncs.ZZ_PLT.Length > 30)
{
result.msg = "轧制工厂代码不可为空且长度不可超过30";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.ZZ_PLT_DESP))
if (cncs.ZZ_PLT_DESP.Length > 80)
{
result.msg = "轧制工厂简称长度不可超过80";
result.code = "0";
return false;
}
return true;
}
/// <summary>
/// 获取主键的条件
/// </summary>
/// <param name="primaryKeyEntity"></param>
/// <returns>AND 开头的 主键条件字符串</returns>
public string GetPrimaryKeyString(CP_NISCO_CHMC_SL primaryKeyEntity)
{
//STLGRD , STDSPEC , THK_MIN , THK_MAX , ZZ_PLT
return string.Format("AND STLGRD = '{0}' AND STDSPEC = '{1}' AND THK_MIN = '{2}' AND THK_MAX = '{3}' AND ZZ_PLT = '{4}' ",
primaryKeyEntity.STLGRD, primaryKeyEntity.STDSPEC, primaryKeyEntity.THK_MIN, primaryKeyEntity.THK_MAX, primaryKeyEntity.ZZ_PLT);
}
/// <summary>
/// 获取主键查询的sql
/// </summary>
/// <param name="checkEntity"></param>
/// <returns>主键查询sql</returns>
public string GetCheckString(CP_NISCO_CHMC_SL checkEntity)
{
string strSql = "SELECT * FROM CP_NISCO_CHMC_SL WHERE 1=1 " + GetPrimaryKeyString(checkEntity);
return strSql;
}
}
}