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.

330 lines
14 KiB
C#

7 months ago
using ibk.IPD.Common;
using ibk.IPD.Entity;
using ibk.IPD.Entity.IPD_MR.HotRoll;
using ibk.IPD.Entity.IPD_MR.HotRoll.QueryArgs;
using ibk.IPD.Entity.IPD_MR.HotRoll.RequestArgs;
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
* 20220415
* :
* Copy Right:
********************************************************/
namespace ibk.IPD.Controller.IPD_MR.HotRoll
{
[RoutePrefix("ipd/ipdMr")]
public class SlabDesignController : 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(EP_SLABDESIGN cncs, RequestEntity result)
{
#region 参数判断
if (string.IsNullOrEmpty(cncs.PLT) || cncs.PLT.Length > 2)
{
result.msg = "工厂不可为空且长度不可超过2";
result.code = "0";
return false;
}
if (string.IsNullOrEmpty(cncs.APLY_ITEM) || cncs.APLY_ITEM.Length > 15)
{
result.msg = "适用项目不可为空且长度不可超过15";
result.code = "0";
return false;
}
if (string.IsNullOrEmpty(cncs.PRC_LINE) || cncs.PRC_LINE.Length > 1)
{
result.msg = "机号不可为空且长度不可超过1";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.APLY_FL))
if (cncs.APLY_FL.Length > 1)
{
result.msg = "适用代码长度不可超过1";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.MINI))
if (!CommonUtils.IsNumber(cncs.MINI) || cncs.MINI.Length > 15)
{
result.msg = "下限是长度不可超过15的数字";
result.code = "0";
return false;
}
if (!string.IsNullOrEmpty(cncs.MAXI))
if (!CommonUtils.IsNumber(cncs.MAXI) || cncs.MAXI.Length > 15)
{
result.msg = "上限是长度不可超过15的数字";
result.code = "0";
return false;
}
return true;
#endregion
}
/// <summary>
/// 获取主键的条件
/// </summary>
/// <param name="primaryKeyEntity"></param>
/// <returns>AND 开头的 主键条件字符串</returns>
public string GetPrimaryKeyString(EP_SLABDESIGN primaryKeyEntity)
{
StringBuilder strSql = new StringBuilder();
strSql.AppendLine(" AND PLT = '" + primaryKeyEntity.PLT + "'");
strSql.AppendLine(" AND APLY_ITEM = '" + primaryKeyEntity.APLY_ITEM + "'");
strSql.AppendLine(" AND PRC_LINE = '" + primaryKeyEntity.PRC_LINE + "'");
return strSql.ToString();
}
/// <summary>
/// 获取主键查询的sql
/// </summary>
/// <param name="checkEntity"></param>
/// <returns>主键查询sql</returns>
public string GetCheckString(EP_SLABDESIGN checkEntity)
{
string strSql = "SELECT * FROM EP_SLABDESIGN WHERE 1=1 " + GetPrimaryKeyString(checkEntity);
return strSql;
}
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/getSlabDesign")]
public RequestEntity GetSlabDesign(EpSlabdesignQueryaArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
DataTable dtCheck = new DataTable();
DataTable aIdtCheck = new DataTable();
//查询sql
//PLT , APLY_ITEM , PRC_LINE , APLY_FL , MINI , MAXI
strSql.AppendLine("SELECT A.PLT , A.APLY_ITEM , A.PRC_LINE , A.APLY_FL , A.MINI , A.MAXI ,to_date(A.INS_DATE || A.INS_TIME ,'yyyy-mm-dd hh24:mi:ss') as INS_DATE,A.INS_TIME,A.INS_EMP , to_date(A.UPD_DATE || A.UPD_TIME ,'yyyy-mm-dd hh24:mi:ss') as UPD_DATE, A.UPD_TIME, A.UPD_EMP , B.APLY_ITEM_NAME FROM EP_SLABDESIGN A LEFT JOIN ZP_APLY_ITEM B ON A.APLY_ITEM = B.APLY_ITEM WHERE 1 = 1 ");
if (queryArgs != null)
{
if (!string.IsNullOrWhiteSpace(queryArgs.PLT)) strSql.AppendLine(" AND A.PLT LIKE '%" + queryArgs.PLT + "%'");
//查询适用项目 传入的是中文, 因为A表没有中文字段, 所以用B表的数据约束
if (!string.IsNullOrWhiteSpace(queryArgs.APLY_ITEM)) strSql.AppendLine(" AND B.APLY_ITEM_NAME LIKE '%" + queryArgs.APLY_ITEM + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.PRC_LINE)) strSql.AppendLine(" AND A.PRC_LINE LIKE '%" + queryArgs.PRC_LINE + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.APLY_FL)) strSql.AppendLine(" AND A.APLY_FL LIKE '%" + queryArgs.APLY_FL + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.MINI) && CommonUtils.IsNumber(queryArgs.MINI)) strSql.AppendLine(" AND A.MINI >=" + queryArgs.MINI);
if (!string.IsNullOrWhiteSpace(queryArgs.MAXI) && CommonUtils.IsNumber(queryArgs.MAXI)) strSql.AppendLine(" AND A.MAXI <=" + queryArgs.MAXI);
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 A.PLT");
dtCheck = db.Query(strSql.ToString());
result.data = db.Query<EpSlabdesignZpAplyItemRequestArgs>(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("GetSlabDesign 报错", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/addSlabDesign")]
public RequestEntity AddSlabDesign(EP_SLABDESIGN 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<EP_SLABDESIGN>(insertModel) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddSlabDesign 报错 : ", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/updSlabDesign")]
public RequestEntity UpdSlabDesign(IList<EP_SLABDESIGN> 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
{
//更新哪些字段
//PLT , APLY_ITEM , PRC_LINE , APLY_FL , MINI , MAXI
if (db.Execute("UPDATE EP_SLABDESIGN SET " + string.Format(" PLT = '{0}' , APLY_ITEM = '{1}' , PRC_LINE = '{2}' , APLY_FL = '{3}' , MINI = '{4}',MAXI = '{5}' , UPD_DATE = '{6}' , UPD_TIME='{7}',UPD_EMP = '{8}' WHERE 1 = 1 ",
requestData[1].PLT, requestData[1].APLY_ITEM, requestData[1].PRC_LINE, requestData[1].APLY_FL, requestData[1].MINI, requestData[1].MAXI, 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("UpdSlabDesign 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/delSlabDesign")]
public RequestEntity DelSlabDesign(EP_SLABDESIGN delModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
try
{
strSql.AppendLine("DELETE FROM EP_SLABDESIGN 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("DelSlabDesign 报错", ex);
}
return result;
}
}
}