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.

412 lines
18 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 ibk.IPD.Entity.IpdMr.Basic;
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年03月29日
* 创建者: 李跃升
* Copy Right: 北京科技大学设计研究院有限公司
********************************************************/
namespace ibk.IPD.Controller.IPD_MR.HotRoll
{
[RoutePrefix("ipd/ipdMr")]
public class WarehouseManagementController : ApiController
{
private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 查询接口
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/getWarehouseManagement")]
public RequestEntity GetRemainingSteelWarehouse(RemaPlaSubsiWarehManageQueryArgs queryArgs)
{
RequestEntity result = new RequestEntity(); //声明返回参数实体类
StringBuilder strSql = new StringBuilder(); //声明拼接Sql语句变量
DataTable dtCheck = new DataTable();
//查询语句日期时间拼接起来格式化成yyyy-mm-dd hh24:mi:ss
//PK 10, WAREH_MANAGE_CLASS 8 ,DELI_PERI 4 int , SUBSI_RATE 4 int
strSql.AppendLine("SELECT PK" +
", WAREH_MANAGE_CLASS" +
", PRIORITY" +
", RATE,SPECIAL_RATE" +
", EXP_DATE" +
", INS_TIME" +
", INS_EMP" +
//", UPD_DATE" +
", UPD_TIME" +
", UPD_EMP" +
", case SUB_KND when 'C' then '完全替代' when 'P' then '部分替代' else '' end SUB_KND" +
", BEF_DEL_DIFF" +
",PROC_CD, AFT_DEL_DIFF" +
",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 " +
"FROM REMA_PLA_SUBSI_WAREH_MANAGE WHERE 1=1");
if (queryArgs != null)
{
//if (!string.IsNullOrWhiteSpace(queryArgs.WAREH_MANAGE_CLASS)) strSql.AppendLine(" AND WAREH_MANAGE_CLASS LIKE '%" + queryArgs.WAREH_MANAGE_CLASS + "%'");
//if (!string.IsNullOrWhiteSpace(queryArgs.START_DELI_PERI) && CommonUtils.IsNumber(queryArgs.START_DELI_PERI)) strSql.AppendLine(" AND DELI_PERI >=" + queryArgs.START_DELI_PERI);
//if (!string.IsNullOrWhiteSpace(queryArgs.END_DELI_PERI) && CommonUtils.IsNumber(queryArgs.END_DELI_PERI)) strSql.AppendLine(" AND DELI_PERI <=" + queryArgs.END_DELI_PERI);
//if (!string.IsNullOrWhiteSpace(queryArgs.START_SUBSI_RATE) && CommonUtils.IsNumber(queryArgs.START_SUBSI_RATE)) strSql.AppendLine(" AND SUBSI_RATE >= " + queryArgs.START_SUBSI_RATE);
//if (!string.IsNullOrWhiteSpace(queryArgs.END_SUBSI_RATE) && CommonUtils.IsNumber(queryArgs.END_SUBSI_RATE)) strSql.AppendLine(" AND SUBSI_RATE <= " + queryArgs.END_SUBSI_RATE);
if (!string.IsNullOrWhiteSpace(queryArgs.SUB_KND))
{
if (queryArgs.SUB_KND == "完全替代")
{
strSql.AppendLine(" AND SUB_KND = '" + "C" + "'");
}
if (queryArgs.SUB_KND == "部分替代")
{
strSql.AppendLine(" AND SUB_KND = '" + "P" + "'");
}
}
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<REMA_PLA_SUBSI_WAREH_MANAGE>(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("GetWarehouseManagement 报错", ex);
}
return result;
}
/// <summary>
/// 添加接口
/// </summary>
/// <param name="insertModel"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/addWarehouseManagement")]
public RequestEntity AddRemainingSteelWarehouse(REMA_PLA_SUBSI_WAREH_MANAGE insertModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
DateTime dtNow = DateTime.Now;
try
{
#region 参数判断
//PK 10, WAREH_MANAGE_CLASS 8 ,DELI_PERI 4 int , SUBSI_RATE 4 int
if (string.IsNullOrEmpty(insertModel.WAREH_MANAGE_CLASS) || insertModel.WAREH_MANAGE_CLASS.Length > 100)
{
result.msg = "仓库类别不可为空且长度不可超过100";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.SUB_KND) || insertModel.SUB_KND.Length > 9 )
{
result.msg = "替代类型不可为空且长度不可超过9";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.BEF_DEL_DIFF) || insertModel.BEF_DEL_DIFF.Length > 6 || !CommonUtils.IsNumber(insertModel.BEF_DEL_DIFF))
{
result.msg = "最早交货期偏移量不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(insertModel.AFT_DEL_DIFF) || insertModel.AFT_DEL_DIFF.Length > 6 || !CommonUtils.IsNumber(insertModel.AFT_DEL_DIFF))
{
result.msg = "最晚交货期偏移量不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
if ( insertModel.PRIORITY.Length > 1 )
{
result.msg = "优先级长度不可超过1";
result.code = "0";
return result;
}
if (!string.IsNullOrWhiteSpace(insertModel.SUB_KND))
{
if (insertModel.SUB_KND == "完全替代")
{
insertModel.SUB_KND = "C";
}
if (insertModel.SUB_KND == "部分替代")
{
insertModel.SUB_KND = "P";
}
}
#endregion
// 拼接主键重复check查询语句
//WAREH_MANAGE_CLASS 8 ,DELI_PERI 4 int , SUBSI_RATE 4 int
//strSql.AppendLine("SELECT * FROM REMA_PLA_SUBSI_WAREH_MANAGE WHERE 1=1 ");
//strSql.AppendLine(string.Format("AND WAREH_MANAGE_CLASS = '{0}' AND DELI_PERI = '{1}' AND SUBSI_RATE = '{2}' ", insertModel.WAREH_MANAGE_CLASS, insertModel.DELI_PERI, insertModel.SUBSI_RATE));
//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<REMA_PLA_SUBSI_WAREH_MANAGE>(insertModel) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("AddWarehouseManagement 报错 : ", ex);
}
return result;
}
/// <summary>
/// 更新接口
/// </summary>
/// <param name="requestData"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/updWarehouseManagement")]
public RequestEntity UpdRemainingSteelWarehouse(IList<REMA_PLA_SUBSI_WAREH_MANAGE> 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, WAREH_MANAGE_CLASS 8 ,DELI_PERI 4 int , SUBSI_RATE 4 int
if (string.IsNullOrEmpty(requestData[1].WAREH_MANAGE_CLASS) || requestData[1].WAREH_MANAGE_CLASS.Length > 100)
{
result.msg = "仓库类别不可为空且长度不可超过100";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].SUB_KND) || requestData[1].SUB_KND.Length > 9)
{
result.msg = "替代类型不可为空且长度不可超过9";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].BEF_DEL_DIFF) || requestData[1].BEF_DEL_DIFF.Length > 6 || !CommonUtils.IsNumber(requestData[1].BEF_DEL_DIFF))
{
result.msg = "最早交货期偏移量不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].AFT_DEL_DIFF) || requestData[1].AFT_DEL_DIFF.Length > 6 || !CommonUtils.IsNumber(requestData[1].AFT_DEL_DIFF))
{
result.msg = "最晚交货期偏移量不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
if ( requestData[1].PRIORITY.Length > 1)
{
result.msg = "优先级长度不可超过!";
result.code = "0";
return result;
}
if (string.IsNullOrEmpty(requestData[1].RATE) || requestData[1].RATE.Length > 6 || !CommonUtils.IsNumber(requestData[1].RATE))
{
result.msg = "替代率不可为空且长度不可超过6或不是数字";
result.code = "0";
return result;
}
//if (string.IsNullOrEmpty(requestData[1].SPECIAL_RATE) || requestData[1].SPECIAL_RATE.Length > 6 || !CommonUtils.IsNumber(requestData[1].SPECIAL_RATE))
//{
// result.msg = "特殊替代率不可为空且长度不可超过6或不是数字";
// result.code = "0";
// return result;
//}
#endregion
try
{
using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
{
// 查询是否有主键相同数据
//PK 10,
//WAREH_MANAGE_CLASS 8 ,DELI_PERI 4 int , SUBSI_RATE 4 int
//strSql.AppendLine("SELECT * FROM REMA_PLA_SUBSI_WAREH_MANAGE WHERE 1=1 ");
//strSql.AppendLine(string.Format("AND WAREH_MANAGE_CLASS = '{0}' AND DELI_PERI = '{1}' AND SUBSI_RATE = '{2}' ", requestData[1].WAREH_MANAGE_CLASS, requestData[1].DELI_PERI, requestData[1].SUBSI_RATE));
//// 执行主键重复查询
//dtCheck = db.Query(strSql.ToString());
//if (dtCheck.Rows.Count > 0 ) // 若数据库中存在则返回错误码0并msg提示用户
//{
// result.msg = "数据已存在,请确认后重试!";
// result.code = "0";
//}
//else
//{
//更新哪些字段
//WAREH_MANAGE_CLASS 8 ,DELI_PERI 4 int , SUBSI_RATE 4 int
if (!string.IsNullOrWhiteSpace(requestData[1].SUB_KND))
{
if (requestData[1].SUB_KND == "完全替代")
{
requestData[1].SUB_KND = "C";
}
if (requestData[1].SUB_KND == "部分替代")
{
requestData[1].SUB_KND = "P";
}
}
string sqlStr = " UPDATE REMA_PLA_SUBSI_WAREH_MANAGE SET " +
string.Format(" WAREH_MANAGE_CLASS = '{0}', SUB_KND ='{1}', BEF_DEL_DIFF ='{2}', AFT_DEL_DIFF ='{3}',UPD_DATE ='{4}',UPD_TIME='{5}',UPD_EMP = '{6}',PRIORITY='{7}',RATE='{8}',EXP_DATE='{9}'SPECIAL_RATE='{10}' PROC_CD='{11}'"
, requestData[1].WAREH_MANAGE_CLASS
, requestData[1].SUB_KND
, requestData[1].BEF_DEL_DIFF
, requestData[1].AFT_DEL_DIFF
, requestData[1].UPD_DATE
, requestData[1].UPD_TIME
, requestData[1].UPD_EMP
, requestData[1].PRIORITY
, requestData[1].RATE
, requestData[1].EXP_DATE, requestData[1].SPECIAL_RATE, requestData[1].PROC_CD) +
//根据主键字段可以确定唯一数据即要修改的数据
//PK
string.Format("WHERE PK = '{0}' ", requestData[0].PK);
//if (db.Execute("UPDATE REMA_PLA_SUBSI_WAREH_MANAGE SET " +
// string.Format(" WAREH_MANAGE_CLASS = '{0}', SUB_KND ='{1}', BEF_DEL_DIFF ='{2}', AFT_DEL_DIFF ='{3}',UPD_DATE ='{4}',UPD_TIME='{5}',UPD_EMP = '{6}',PRIORITY={7},RATE={8},EXP_DATE={9} "
// , requestData[1].WAREH_MANAGE_CLASS
// , requestData[1].SUB_KND
// , requestData[1].BEF_DEL_DIFF
// , requestData[1].AFT_DEL_DIFF
// , requestData[1].UPD_DATE
// , requestData[1].UPD_TIME
// , requestData[1].UPD_EMP
// , requestData[1].PRIORITY
// , requestData[1].RATE
// , requestData[1].EXP_DATE) +
// //根据主键字段可以确定唯一数据即要修改的数据
// //PK
// string.Format("WHERE PK = '{0}' ", requestData[0].PK)) > 0)
if (db.Execute(sqlStr) > 0)
{
result.msg = "操作成功";
result.code = "1";
}
else
{
result.msg = "数据未发生改变,请确认后重试!";
result.code = "0";
}
//}
return result;
}
}
catch (Exception ex)
{
result.msg = "数据库错误!";
result.code = "0";
logger.Error("UpdWarehouseManagement 报错", ex);
return result;
}
}
/// <summary>
/// 删除接口
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("hotRoll/delWarehouseManagement")]
public RequestEntity DelRemainingSteelWarehouse(REMA_PLA_SUBSI_WAREH_MANAGE delModel)
{
RequestEntity result = new RequestEntity();
StringBuilder strSql = new StringBuilder();
try
{
//PK
strSql.AppendLine("DELETE FROM REMA_PLA_SUBSI_WAREH_MANAGE 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("DelWarehouseManagement 报错", ex);
}
return result;
}
}
}