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.

305 lines
13 KiB
C#

7 months ago
using ibk.IPD.Common;
using ibk.IPD.Entity;
using ibk.IPD.Entity.IPD_MR.StdMgt;
using ibk.IPD.Entity.IPD_MR.StdMgt.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
* 20220330
* :
* Copy Right:
********************************************************/
namespace ibk.IPD.Controller.IPD_MR.StdMgt
{
[RoutePrefix("ipd/ipdMr")]
public class MoldLifeController : ApiController
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/getMoldLife")]
public RequestEntity GetMoldLife(MoldLifeQueryArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
DataTable dtCheck = new DataTable();
//查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss
//PRC_LINE 1 , SECTION_THICK 6 int , REPLACE_TIME 6 , DURATION 8
strSql.AppendLine("SELECT PK,PRC_LINE,SECTION_THICK,REPLACE_TIME,DURATION,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 MOLD_LIFE WHERE 1=1");
if (queryArgs != null)
{
if (!string.IsNullOrWhiteSpace(queryArgs.PRC_LINE)) strSql.AppendLine(" AND PRC_LINE LIKE '%" + queryArgs.PRC_LINE + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.REPLACE_TIME)) strSql.AppendLine(" AND REPLACE_TIME LIKE '%" + queryArgs.REPLACE_TIME + "%'");
if (!string.IsNullOrWhiteSpace(queryArgs.START_SECTION_THICK) && CommonUtils.IsNumber(queryArgs.START_SECTION_THICK)) strSql.AppendLine(" AND SECTION_THICK >=" + queryArgs.START_SECTION_THICK);
if (!string.IsNullOrWhiteSpace(queryArgs.END_SECTION_THICK) && CommonUtils.IsNumber(queryArgs.END_SECTION_THICK)) strSql.AppendLine(" AND SECTION_THICK <=" + queryArgs.END_SECTION_THICK);
if (!string.IsNullOrWhiteSpace(queryArgs.DURATION)) strSql.AppendLine(" AND DURATION LIKE '%" + queryArgs.DURATION + "%'");
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<MOLD_LIFE>(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("GetMoldLife 报错 : ", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/addMoldLife")]
public RequestEntity AddMoldLife(MOLD_LIFE insertModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
DateTime dtNow = DateTime.Now;
try
{
#region 参数判断
//PRC_LINE 1 , SECTION_THICK 6 int , REPLACE_TIME 6 , DURATION 8
if (string.IsNullOrEmpty(insertModel.PRC_LINE) || insertModel.PRC_LINE.Length > 1)
{
result.msg = "机号不可为空且长度不可超过1";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.SECTION_THICK) || insertModel.SECTION_THICK.Length > 6 || !CommonUtils.IsNumber(insertModel.SECTION_THICK))
{
result.msg = "结晶器断面厚度不可为空长度不可超过6且必须是数字";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.REPLACE_TIME) || insertModel.REPLACE_TIME.Length > 6)
{
result.msg = "更换次数不可为空长度不可超过6";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.DURATION) || insertModel.DURATION.Length > 8)
{
result.msg = "使用时长不可为空长度不可超过8";
result.code = "0";
return result;
}
#endregion
// 拼接主键重复check查询语句
//PRC_LINE 1 , SECTION_THICK 6 int , REPLACE_TIME 6 , DURATION 8
strSql.AppendLine("SELECT * FROM MOLD_LIFE WHERE 1=1 ");
strSql.AppendLine(string.Format("AND PRC_LINE = '{0}' AND SECTION_THICK = '{1}' AND REPLACE_TIME = '{2}' AND DURATION = '{3}' ", insertModel.PRC_LINE, insertModel.SECTION_THICK, insertModel.REPLACE_TIME, insertModel.DURATION));
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<MOLD_LIFE>(insertModel) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddMoldLife 报错 : ", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/updMoldLife")]
public RequestEntity UpdMoldLife(IList<MOLD_LIFE> 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 参数判断
//PRC_LINE 1 , SECTION_THICK 6 int , REPLACE_TIME 6 , DURATION 8
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].SECTION_THICK) || requestData[1].SECTION_THICK.Length > 6 || !CommonUtils.IsNumber(requestData[1].SECTION_THICK))
{
result.msg = "结晶器断面厚度不可为空长度不可超过6且必须是数字";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].REPLACE_TIME) || requestData[1].REPLACE_TIME.Length > 6)
{
result.msg = "更换次数不可为空长度不可超过6";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].DURATION) || requestData[1].DURATION.Length > 8)
{
result.msg = "使用时长不可为空长度不可超过8";
result.code = "0";
return result;
}
#endregion
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
// 拼接主键重复check查询语句
//PRC_LINE 1 , SECTION_THICK 6 int , REPLACE_TIME 6 , DURATION 8
strSql.AppendLine("SELECT * FROM MOLD_LIFE WHERE 1=1 ");
strSql.AppendLine(string.Format("AND PRC_LINE = '{0}' AND SECTION_THICK = '{1}' AND REPLACE_TIME = '{2}' AND DURATION = '{3}' ", requestData[1].PRC_LINE, requestData[1].SECTION_THICK, requestData[1].REPLACE_TIME, requestData[1].DURATION));
// 执行主键重复查询
dtCheck = db.Query(strSql.ToString());
if (dtCheck.Rows.Count > 0) // 若数据库中存在则返回错误码0并msg提示用户
{
result.msg = "数据已存在,请确认后重试!";
result.code = "0";
}
else
{
//更新哪些字段
//PRC_LINE 1 , SECTION_THICK 6 int , REPLACE_TIME 6 , DURATION 8
if (db.Execute("UPDATE MOLD_LIFE SET " + string.Format(" PRC_LINE = '{0}' , SECTION_THICK = '{1}' , REPLACE_TIME = '{2}' , DURATION = '{3}' , UPD_DATE = '{4}',UPD_TIME='{5}',UPD_EMP = '{6}' ", requestData[1].PRC_LINE, requestData[1].SECTION_THICK, requestData[1].REPLACE_TIME, requestData[1].DURATION, requestData[1].UPD_DATE, requestData[1].UPD_TIME, requestData[1].UPD_EMP) +
//根据主键字段可以确定唯一数据即要修改的数据
//PK
string.Format("WHERE 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("UpdMoldLife 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("stdMgt/delMoldLife")]
public RequestEntity DelMoldLife(MOLD_LIFE delModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
try
{
// 拼接主键重复check查询语句
//PK
strSql.AppendLine("DELETE FROM MOLD_LIFE 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("DelMoldLife 报错", ex);
}
return result;
}
}
}