using ibk.IPD.Common ;
using ibk.IPD.Entity ;
using ibk.IPD.Entity.IPD_PS ;
using ibk.IPD.Entity.IPD_PS.QueryArgs ;
using ibk.IPD.Entity.IPD_PS.RequestArgs ;
using ibk.IPD.Entity.IpdPs ;
using ibk.IPD.Service ;
using log4net ;
using SOA.Objects ;
using SOA.Persistent ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.IO ;
using System.Linq ;
using System.Net.Http ;
using System.Net ;
using System.Reflection ;
using System.Runtime.Remoting.Contexts ;
using System.Text ;
using System.Threading.Tasks ;
using System.Web.Http ;
using NPOI.XSSF.UserModel ;
using NPOI.SS.UserModel ;
using NPOI.SS.Formula.Functions ;
using static NPOI . HSSF . Util . HSSFColor ;
//using Org.BouncyCastle.Utilities.Zlib;
using Confluent.Kafka ;
using NPOI.Util ;
using System.Security.Cryptography ;
using System.Windows.Forms ;
namespace ibk.IPD.Controller.IPD_PS
{
[RoutePrefix("ipd/ipdPs")]
public class SurplusMaterialSubstitutionController : ApiController
{
private static readonly ILog logger = LogManager . GetLogger ( MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
private static SurplusMaterialSelectionService surplusMaterialSelectionService = new SurplusMaterialSelectionService ( ) ;
private static SurMatSubController surMatSub = new SurMatSubController ( ) ;
//设置一个加锁对象
//private 防止外面访问, static 静态 readonly只读 避免地址被修改 引用失效影响锁
private static readonly object LOCK = new object ( ) ;
//可用订单集合
private static IList < BP_ORDER_ITEM > orderEntities = new List < BP_ORDER_ITEM > ( ) ;
//可用余材集合
private static IList < GP_PLATE > gP_PLATEs = new List < GP_PLATE > ( ) ;
object lockObject = new object ( ) ;
/// <summary>
/// 查询所有原始可用余材(前端需求接口)
/// </summary>
/// <returns></returns>
[HttpPost, Route("getSurplusMaterials")]
public RequestEntity GetSurplusMaterials ( GpPlateQueryArgs queryArgs )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
if ( queryArgs ! = null )
{
//钢板号
if ( ! string . IsNullOrWhiteSpace ( queryArgs . PLATE_NO ) ) strSql . AppendLine ( " AND GP.PLATE_NO LIKE '" + queryArgs . PLATE_NO + "%'" ) ;
//进程号
if ( ! string . IsNullOrWhiteSpace ( queryArgs . PROC_CD ) ) strSql . AppendLine ( " AND GP.PROC_CD LIKE '" + queryArgs . PROC_CD + "%'" ) ;
//订单号
if ( ! string . IsNullOrWhiteSpace ( queryArgs . ORD_NO ) ) strSql . AppendLine ( " AND GP.ORD_NO LIKE '" + queryArgs . ORD_NO + "%'" ) ;
//订单序列号
if ( ! string . IsNullOrWhiteSpace ( queryArgs . ORD_ITEM ) ) strSql . AppendLine ( " AND GP.ORD_ITEM LIKE '" + queryArgs . ORD_ITEM + "%'" ) ;
if ( ! string . IsNullOrWhiteSpace ( CommonUtils . ObjectToStr ( queryArgs . START_TIME ) ) & & CommonUtils . ObjectToStr ( queryArgs . START_TIME ) ! = "0001/1/1 0:00:00" ) strSql . AppendLine ( " AND to_date(GP.PROD_DATE || ' ' || GP.PROD_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(GP.PROD_DATE || ' ' || GP.PROD_TIME ,'yyyy-mm-dd hh24:mi:ss') <= to_date('" + CommonUtils . ObjectToStr ( queryArgs . END_TIME ) + "','yyyy-mm-dd hh24:mi:ss')" ) ;
}
result . data = surMatSub . GetSurplusMaterials ( strSql . ToString ( ) ) . data ;
result . msg = "操作成功!" ;
result . code = "1" ;
}
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "GetSurplusMaterials 报错 : " , ex ) ;
}
return result ;
}
/// <summary>
/// 查询按钮
/// 查询(SUPERSEDE 表)
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("getSupersede")]
public RequestEntity GetSupersede ( SupersedeQueryArgs queryArgs )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
//PLATE_NO , APLY_STDSPEC , PROC_CD , THK , WID , LEN , WGT , REDO_HOT , SIZE_KND , TRIMMING , ORD_NO , SUB_RATE , ORD_ITEM
strSql . AppendLine ( "SELECT PLATE_NO , APLY_STDSPEC ,PROC_CD , THK , WID , LEN , WGT , REDO_HOT , SIZE_KND , TRIMMING , ORD_NO , SUB_RATE , ORD_ITEM , STLGRD , TRIMMING_WID , TRIMMING_LEN , SURPLUS_WID , SURPLUS_LEN , PLATE_SIZE FROM SUPERSEDE WHERE 1 = 1 " ) ;
if ( queryArgs ! = null )
{
//标准号
if ( ! string . IsNullOrWhiteSpace ( queryArgs . APLY_STDSPEC ) ) strSql . AppendLine ( " AND APLY_STDSPEC LIKE '%" + queryArgs . APLY_STDSPEC + "%'" ) ;
//厚度上下限
if ( ! string . IsNullOrWhiteSpace ( queryArgs . START_THK ) & & CommonUtils . IsNumber ( queryArgs . START_THK ) ) strSql . AppendLine ( " AND THK >=" + queryArgs . START_THK ) ;
if ( ! string . IsNullOrWhiteSpace ( queryArgs . END_THK ) & & CommonUtils . IsNumber ( queryArgs . END_THK ) ) strSql . AppendLine ( " AND THK <=" + queryArgs . END_THK ) ;
//钢板号
if ( ! string . IsNullOrWhiteSpace ( queryArgs . PLATE_NO ) ) strSql . AppendLine ( " AND PLATE_NO LIKE '%" + queryArgs . PLATE_NO + "%'" ) ;
//钢种
if ( ! string . IsNullOrWhiteSpace ( queryArgs . STLGRD ) ) strSql . AppendLine ( " AND STLGRD LIKE '%" + queryArgs . STLGRD + "%'" ) ;
}
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
dtCheck = db . Query ( strSql . ToString ( ) ) ;
result . data = db . Query < SUPERSEDE > ( 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 ( "GetSupersede 报错" , ex ) ;
}
return result ;
}
/// <summary>
/// 确认替代 STATE = Y 或拒绝替代 STATE = N 按钮
/// 点击确认或拒绝按钮则删除supersede表中确认记录,添加到SUPERSEDE_CONFIRAM表
/// </summary>
/// <param name="delModel"></param>
/// <returns></returns>
[HttpPost, Route("delSupAddSupersedeConfiram")]
public RequestEntity DelSupAddSupersedeConfiram ( SupersedeRequestArgs delAddModel )
{
lock ( LOCK )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
DataTable dtCheck = new DataTable ( ) ;
string strSql = string . Format ( "DELETE FROM SUPERSEDE WHERE PLATE_NO = '{0}' AND APLY_STDSPEC = '{1}' AND ORD_NO = '{2}' AND ORD_ITEM = '{3}'" , delAddModel . PLATE_NO , delAddModel . APLY_STDSPEC , delAddModel . ORD_NO , delAddModel . ORD_ITEM ) ;
//将匹配表的记录信息复制给历史记录表
SUPERSEDE_CONFIRAM sc = new SUPERSEDE_CONFIRAM
{
PLATE_NO = delAddModel . PLATE_NO ,
PROC_CD = delAddModel . PROC_CD ,
THK = delAddModel . THK ,
WID = delAddModel . WID ,
LEN = delAddModel . LEN ,
SURPLUS_THK = delAddModel . THK ,
SURPLUS_WID = delAddModel . WID ,
SURPLUS_LEN = delAddModel . LEN ,
ORD_NO = delAddModel . ORD_NO ,
ORD_ITEM = delAddModel . ORD_ITEM ,
INS_DATE = DateTime . Now . ToString ( "yyyyMMdd" ) ,
INS_TIME = DateTime . Now . ToString ( "HHmmss" ) ,
//替代状态
STATE = delAddModel . STATE
} ;
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
try
{
//因为是同时操作两个表, 所以开启事务
db . BeginTransaction ( ) ;
if ( db . Execute ( strSql ) > 0 )
{
if ( db . Insert < SUPERSEDE_CONFIRAM > ( sc ) > 0 )
{
result . msg = "操作成功!" ;
result . code = "1" ;
//数据操作成功则保存数据
db . Commit ( ) ;
}
else
{
result . msg = "操作失败!" ;
result . code = "0" ;
//操作失败回滚数据到初始状态
db . Rollback ( ) ;
}
}
else
{
result . msg = "操作失败!" ;
result . code = "0" ;
//操作失败回滚数据到初始状态
db . Rollback ( ) ;
}
}
catch ( Exception ex )
{
//数据如果发生错误则回滚
db . Rollback ( ) ;
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "DelSupAddSupersedeConfiram 报错" , ex ) ;
}
}
return result ;
}
}
/// <summary>
/// 历史信息查询按钮
/// 查询(SUPERSEDE_CONFIRAM 表)
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("getSupersedeConfiram")]
public RequestEntity GetSupersedeConfiram ( SupersedeConfiramQueryArgs queryArgs )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
//PLATE_NO , PROC_CD , THK , WID , LEN , SURPLUS_THK , SURPLUS_WID , SURPLUS_LEN , SURPLUS_PER , ORD_NO , ORD_ITEM , STATE
strSql . AppendLine ( "SELECT * FROM SUPERSEDE_HISTORY WHERE 1 = 1 " ) ;
if ( queryArgs ! = null )
{
//钢板号
if ( ! string . IsNullOrWhiteSpace ( queryArgs . PLATE_NO ) ) strSql . AppendLine ( " AND PLATE_NO LIKE '%" + queryArgs . PLATE_NO + "%'" ) ;
//进程号
if ( ! string . IsNullOrWhiteSpace ( queryArgs . PROC_CD ) ) strSql . AppendLine ( " AND PROC_CD LIKE '%" + queryArgs . PROC_CD + "%'" ) ;
//订单号
if ( ! string . IsNullOrWhiteSpace ( queryArgs . ORD_NO ) ) strSql . AppendLine ( " AND ORD_NO LIKE '%" + queryArgs . ORD_NO + "%'" ) ;
//订单序列号
if ( ! string . IsNullOrWhiteSpace ( queryArgs . ORD_ITEM ) ) strSql . AppendLine ( " AND ORD_ITEM LIKE '%" + queryArgs . ORD_ITEM + "%'" ) ;
//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 < SUPERSEDE_CONFIRAM > ( 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 ( "GetSupersedeConfiram 报错" , ex ) ;
}
return result ;
}
/// <summary>
/// 查询所有原始可用余材(后台获取接口)
/// </summary>
/// <returns></returns>
/// 方法如果被static修饰, 则在接口中无法被发现(原因不详)
[HttpPost, Route("getSurplusMaterial")]
public static RequestEntity GetSurplusMaterial ( GpPlateQueryArgs queryArgs )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
//gP_PLATEs = surplusMaterialSelectionService.GetXACSurplusMaterialSelection(queryArgs);
SurplusMaterialSubstitutionController . gP_PLATEs = surplusMaterialSelectionService . GetQABSurplusMaterialSelection ( queryArgs ) ;
result . data = SurplusMaterialSubstitutionController . gP_PLATEs ;
result . msg = "操作成功!" ;
result . code = "1" ;
}
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "GetSurplusMaterial 报错 : " , ex ) ;
}
return result ;
}
/// <summary>
/// 查询所有原始可用订单
/// </summary>
/// <returns></returns>
/// 方法如果被static修饰, 则在接口中无法被发现(原因不详)
[HttpPost, Route("getOrders")]
public static RequestEntity GetOrders ( )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
//gP_PLATEs = surplusMaterialSelectionService.GetXACSurplusMaterialSelection(queryArgs);
SurplusMaterialSubstitutionController . orderEntities = surplusMaterialSelectionService . GetOrder ( ) ;
//result.data = SurMatSubController.GetOrders();
result . data = orderEntities ;
result . msg = "操作成功!" ;
result . code = "1" ;
}
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "GetSurplusMaterial 报错 : " , ex ) ;
}
return result ;
}
/// <summary>
/// 查询所有余材的化学成分
/// </summary>
/// <returns>对应的化学成分集合</returns>
/// 方法如果被static修饰, 则在接口中无法被发现(原因不详)
[HttpPost, Route("getChemistry")]
public static RequestEntity GetChemistry ( GP_PLATE plate )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
//strSql.AppendLine(string.Format("SELECT * FROM QP_CHEM_RSLT WHERE HEAT_NO = (SELECT HEAT_NO FROM FP_SLAB WHERE SLAB_NO = '{0}')", plate.SLAB_NO));
try
{
//开启数据库连接查询数据
//using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
// {
// IList<string> chemistrys = new List<string>();
// foreach (QP_CHEM_RSLT item in db.Query<QP_CHEM_RSLT>(strSql.ToString()))
// {
// chemistrys.Add(item.CHEM_COMP_CD);
// }
// result.data = chemistrys;
// result.msg = "操作成功!";
// result.code = "1";
//}
result . data = SurplusMaterialSubstitutionController . GetChemistry ( null ) ;
result . msg = "操作成功!" ;
result . code = "1" ;
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "GetSurplusMaterial 报错 : " , ex ) ;
}
return result ;
}
/// <summary>
/// 查询所有订单的化学成分
/// </summary>
/// <returns>对应的化学成分集合</returns>
/// 方法如果被static修饰, 则在接口中无法被发现(原因不详)
[HttpPost, Route("getOrderChemistry")]
public static RequestEntity GetOrderChemistry ( BP_ORDER_ITEM order )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
//strSql.AppendLine(string.Format("select * from QP_QLTY_CHEM where ORD_NO = '{0}' and ORD_ITEM = '{1}'", order.ORD_NO, order.ORD_ITEM));
try
{
//开启数据库连接查询数据
//using (IDbContext db = ObjectContainer.GetObject<IDbContext>("db"))
//{
// IList<string> orderChemistrys = new List<string>();
// foreach (QP_QLTY_CHEM item in db.Query<QP_QLTY_CHEM>(strSql.ToString()))
// {
// orderChemistrys.Add(item.CHEM_COMP_CD);
// }
// result.data = orderChemistrys;
// result.msg = "操作成功!";
// result.code = "1";
//}
result . data = SurplusMaterialSubstitutionController . GetOrderChemistry ( null ) ;
result . msg = "操作成功!" ;
result . code = "1" ;
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "GetSurplusMaterial 报错 : " , ex ) ;
}
return result ;
}
/// <summary>
/// 对所有余材订单信息做匹配并存入SUPERSEDE表中
/// 且排除SUPERSEDE_CONFIRAM表中已经完成操作的数据
/// </summary>
/// 因为定时器方法必须有一个object类型的参数, 所以随意添加一个参数 , 方法内部并未用到
/// 因为定时器方法必须是静态的所以添加static
/// /// <param name="stateInfo"></param>
/// <returns></returns>
/// 方法如果被static修饰, 则在接口中无法被发现(原因不详)
[HttpPost, Route("addSupersede")]
public static void AddSupersede ( Object stateInfo )
{
lock ( LOCK )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
//获取所有可用余材
GetSurplusMaterial ( null ) ;
//获取所有可用订单
GetOrders ( ) ;
//声明匹配后数据集
IList < SUPERSEDE > supersedes = new List < SUPERSEDE > ( ) ;
//定义需要删除的数据集
IList < SUPERSEDE > delsupersedes = new List < SUPERSEDE > ( ) ;
//判断哪些是匹配数据
foreach ( GP_PLATE plate in gP_PLATEs )
{
foreach ( BP_ORDER_ITEM order in orderEntities )
{
//声明一个匹配后的实体类
SUPERSEDE sup = new SUPERSEDE ( ) ;
////判断钢种是否一致
//if (plate.STLGRD == order.STLGRD)
//{
// //标准
// //APLY_STDSPEC 标准号 , STDSPEC 标准代码
// if (plate.APLY_STDSPEC == order.STDSPEC)
// {
// //化学成分比对先比对钢板的化学成分集合与订单化学成分集合是否一致
// //然后比对钢板的化学成分实绩值是否再订单上下限范围内
// //获取该钢板的化学成分集合
// IList<string> chemistry = (IList<string>)GetChemistry(plate).data;
// //获取该订单的化学成分
// IList<string> orderChemistry = (IList<string>)GetOrderChemistry(order).data;
// //判断订单的化学成分要求是否包含钢板的实际化学成分
// bool isContainFlag = !chemistry.Except(orderChemistry).Any();
// if (isContainFlag)
// {
// //化学成分满足
// }
// //探伤
// //UST_FL 超声波探伤代码 UST_FL 是否超声波探伤(值分为X 和 探伤代码)
// if (plate.UST_FL == order.UST_FL)
// {
// }
// //热处理
// //热处理方法1 热处理方法2 热处理方法3
// if (plate.HTM_METH1 == order.HTM_METH1 && plate.HTM_METH2 == order.HTM_METH2 && plate.HTM_METH3 == order.HTM_METH3)
// {
// }
// //用途
// //APLY_ENDUSE_CD 钢板用途 ENDUSE_CD 订单用途
// if (plate.APLY_ENDUSE_CD == order.ENDUSE_CD)
// {
// //切边
// //切边代码 切边代码
// if (plate.TRIM_FL == order.TRIM_FL)
// {
// }
// }
// }
//}
////判断订单厚度是否一致
//if (plate.THK == order.ORD_THK)
//{
// sup.THK = plate.THK;
//}
////宽度
//if (!(plate.WID == order.ORD_WID))
//{
// //先将数据转换成double进行运算操作, 在将结果转换成string进行赋值操作
// sup.TRIMMING_WID = Convert.ToString(double.Parse(plate.WID) - double.Parse(order.ORD_WID));
//}
////不管宽度符不符合要求, 把原宽度值赋值
//sup.WID = plate.WID;
//判断订单厚度是否一致
if ( plate . THK = = ( order . ORD_THK ) )
{
//订单宽度
if ( plate . WID = = ( order . ORD_WID ) )
{
//订单长度
if ( plate . LEN = = ( order . ORD_LEN ) )
{
//声明匹配实体类
SUPERSEDE supersede = new SUPERSEDE
{
//不需要切边
TRIMMING = "N" ,
//替代率
SUB_RATE = "100%" ,
TRIMMING_WID = "0" ,
TRIMMING_LEN = "0" ,
REDO_HOT = "N" ,
SIZE_KND = plate . SIZE_KND ,
SURPLUS_WID = plate . WID ,
SURPLUS_LEN = plate . LEN ,
WGT = plate . WGT ,
STLGRD = plate . STLGRD ,
PLATE_NO = plate . PLATE_NO ,
APLY_STDSPEC = plate . APLY_STDSPEC ,
PROC_CD = plate . PROC_CD ,
THK = plate . THK ,
WID = plate . WID ,
LEN = plate . LEN ,
PLATE_SIZE = plate . THK + "*" + plate . WID + "*" + plate . LEN ,
ORD_NO = order . ORD_NO ,
ORD_ITEM = order . ORD_ITEM
} ;
//将匹配过的订单从符合条件的订单中删掉确保不会出现匹配重复订单
//orderEntities.Remove(order);
//将匹配信息加入替代表中
supersedes . Add ( supersede ) ;
break ;
}
}
}
}
}
//查询历史记录表中哪些钢板已经做过操作
strSql . AppendLine ( "SELECT * FROM SUPERSEDE_CONFIRAM" ) ;
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
//查询SUPERSEDE_CONFIRAM表中 PLATE_NO 字段的值
IList < SUPERSEDE_CONFIRAM > supersedeConfirams = db . Query < SUPERSEDE_CONFIRAM > ( strSql . ToString ( ) ) ;
//将匹配记录删除历史记录表中的数据, 因为历史记录表中的数据已经做完操作了
foreach ( SUPERSEDE_CONFIRAM sc in supersedeConfirams )
{
foreach ( SUPERSEDE item in supersedes )
{
//根据钢板号确定唯一数据
if ( sc . PLATE_NO = = item . PLATE_NO )
{
//因为索引问题, 所以将要删除的数据存储起来,而不是直接删除
delsupersedes . Add ( item ) ;
}
}
}
//遍历需要删除的集
foreach ( SUPERSEDE item in delsupersedes )
{
//从匹配数据集中删除需要删除的数据
supersedes . Remove ( item ) ;
}
//删除SUPERSEDE表中旧记录
db . Execute ( "Truncate table SUPERSEDE reuse storage" ) ;
//将去掉数据后的新匹配信息插入SUPERSEDE 表中
foreach ( SUPERSEDE item in supersedes )
{
try
{
db . Insert < SUPERSEDE > ( item ) ;
}
catch
{
logger . Info ( "记录插入失败" ) ;
}
}
result . msg = "操作成功!" ;
result . code = "1" ;
}
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "GetSurplusMaterial 报错 : " , ex ) ;
}
}
}
/// <summary>
/// 新增余材(外部需要调用的接口)
/// </summary>
/// <param name="gP_PLATE"></param>
/// <returns></returns>
[HttpPost, Route("addSurplusMaterial")]
public RequestEntity AddSurplusMaterial ( GP_PLATE gP_PLATE )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
try
{
//不管该余材是否可用都需要添加到表中
db . Insert < GP_PLATE > ( gP_PLATE ) ;
}
catch
{
logger . Info ( "余材插入失败了: " + gP_PLATE . ToString ( ) ) ;
}
//判断新增的余材是不是可用余材
if ( gP_PLATE . CUR_INV = = "HB" )
if ( gP_PLATE . PROD_CD = = "PP" )
if ( gP_PLATE . REC_STS = = "2" )
if ( gP_PLATE . PROC_CD = = "QAB" )
if ( gP_PLATE . SURF_GRD = = "1" )
{
//给该操作加锁
lock ( LOCK )
{
//调用所有数据匹配, 因为出现新余材, 所以重新匹配
AddSupersede ( null ) ;
}
}
result . msg = "操作成功!" ;
result . code = "1" ;
}
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "AddSurplusMaterial 报错 : " , ex ) ;
}
return result ;
}
[HttpPost, Route("GetTB_INVENTORY_ANALYSIS")]
public RequestEntity GetTB_INVENTORY_ANALYSIS ( GpPlateQueryArgs QAGP )
{
Dictionary < string , string > columnMapping = new Dictionary < string , string >
{
{ "INVENTORY_TYPE" , "评估结果" } ,
{ "HALF_NUM" , "半年内可替代次数" } ,
{ "TYPE" , "分类" } ,
{ "PLATE_NO" , "钢板号" } ,
{ "OUT_SHEET_NO" , "轧批号" } ,
{ "MARKING_FL" , "是否标印" } ,
{ "PROC_CD" , "进程状态" } ,
{ "DEL_TO_DATE" , "客户交货日期" } ,
{ "APLY_STDSPEC" , "标准号" } ,
{ "THK" , "厚度" } ,
{ "WID" , "宽度" } ,
{ "LEN" , "长度" } ,
{ "THK_TOL_MIN" , "厚度公差最小值" } ,
{ "THK_TOL_MAX" , "厚度公差最大值" } ,
{ "WGT" , "重量" } ,
{ "LOAD_WGT" , "过磅重量" } ,
{ "PROD_GRD" , "产品等级" } ,
{ "SURF_GRD" , "表面等级" } ,
{ "SMP_FL" , "试样代码" } ,
{ "TEST_PIECE_NUMBER" , "试样号" } ,
{ "SMP_SEND_NO" , "委托单号" } ,
{ "TRIM_FL" , "切边代码" } ,
{ "SIZE_KND" , "定尺代码" } ,
{ "PLT" , "生产厂" } ,
{ "PROD_DATE" , "生产日期" } ,
{ "MILL_END_DATE" , "轧制日期" } ,
{ "AGGREGATE_TIME" , "综判时间" } ,
{ "WAREHOUSE_TIME" , "入库日期" } ,
{ "OUT_PLT_DATE" , "出库日期" } ,
{ "WAREHOUSE" , "仓库" } ,
{ "LOC" , "垛位号" } ,
{ "ORD_NO" , "订单号" } ,
{ "ORD_ITEM" , "订单序列号" } ,
{ "ORG_ORD_NO" , "原始订单号" } ,
{ "ORG_ORD_ITEM" , "原始订单序列号" } ,
{ "ORD_FL" , "订单材/余材" } ,
{ "WOO_RSN" , "余材原因代码" } ,
{ "WOO_RSN_CHG_GRD_DEP" , "责任单位" } ,
{ "JET_PRINTING" , "喷印" } ,
{ "PAINTNUM" , "标识次数" } ,
{ "PROCESSING" , "冲印" } ,
{ "LATERAL_JET" , "侧喷" } ,
{ "ENDUSE_CD" , "订单用途" } ,
{ "IS_PERFORMANCE" , "是否保性能" } ,
{ "CUST_CD" , "客户" } ,
{ "CUST_SPEC_NO" , "客户特殊要求" } ,
{ "CUTTING" , "切割" } ,
{ "STRAIGHTENING" , "矫直" } ,
{ "SHOT" , "抛丸" } ,
{ "HEAT_TREATMENT" , "热处理" } ,
{ "CERT_RPT_FL" , "是否已打印质保书" } ,
{ "PRICE_GRD_DATE" , "设定日期" } ,
{ "IS_PERSONNEL" , "设定人员" } ,
{ "STLGRD" , "钢种" } ,
{ "R_IDENT" , "认证标识" } ,
{ "VESSEL_NO" , "加喷内容" } ,
{ "SIDEMARK" , "侧喷加喷" } ,
{ "SEALMEMO" , "冲印加喷" } ,
{ "BEIZHU_MEMO" , "订单备注" } ,
{ "INSP_WGT_GRD" , "尺寸是否合格" } ,
{ "BAOXIN_IF_DATE" , "寄仓时间" } ,
{ "SPECIFICATION" , "订单规格" } ,
{ "ORD_WID" , "订单宽度" } ,
{ "ORD_THK" , "订单厚度" } ,
{ "ORD_LEN" , "订单长度" } ,
{ "RELEASE_DATE" , "订单投入日期" } ,
{ "URGNT_FL" , "否紧急订单" } ,
{ "IMP_CONT" , "重点合同" } ,
{ "CFM_MILL_PLT" , "订单轧制工厂" } ,
{ "CR_CD" , "控制号" } ,
{ "SAMPLE_MEMO" , "试样备注" } ,
{ "SIZE_MEMO" , "尺寸备注" } ,
{ "PACK_MEMO" , "打包备注" } ,
{ "SURFACE_REQUESTS" , "表面客户要求" } ,
{ "LEN_UP" , "长度公差上限" } ,
{ "LEN_DOWN" , "长度公差下限" } ,
{ "CAL_FLOOR" , "下限" } ,
{ "FLT_UNIT_MAX" , "钢板不平度1" } ,
{ "FLT_LEN" , "测量长度1" } ,
{ "FLT_UNIT_MAX2" , "钢板不平度2" } ,
{ "FLT_LEN2" , "测量长度2" } ,
{ "CUST_CLASS" , "客户分类" } ,
{ "CUST_LEVEL" , "客户分级" } ,
{ "WID_UP" , "宽度公差上限" } ,
{ "WID_DOWN" , "宽度公差下限" } ,
{ "SPECIAL_OPR_REQ" , "特殊作业要求" } ,
{ "GP_PERFORMANCE" , "钢板性能" } ,
{ "GPYD_UPD_DATE" , "移垛时间" } ,
{ "GPYD_UPD_EMP_CD" , "移跺人员" } ,
{ "EMP_CD1" , "最后表判人员" } ,
{ "CERT_RPT_NO" , "质保书编号" } ,
{ "STEEL_SPRAY" , "钢板喷涂" } ,
{ "STEEL_SHOTBLAST" , "钢板抛丸" } ,
{ "STEEL_PACK" , "钢板打包" }
} ;
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
strSql . AppendLine ( "SELECT " ) ;
strSql . AppendLine ( " PLATE_NO," ) ;
strSql . AppendLine ( " CASE INVENTORY_TYPE" ) ;
strSql . AppendLine ( " WHEN '1' THEN '判现'" ) ;
strSql . AppendLine ( " WHEN '2' THEN '判废'" ) ;
strSql . AppendLine ( " WHEN '3' THEN '待定'" ) ;
strSql . AppendLine ( " WHEN '4' THEN '保留'" ) ;
strSql . AppendLine ( " END AS INVENTORY_TYPE," ) ;
strSql . AppendLine ( " TO_DATE(INS_DATE, 'yyyy-mm-dd hh24:mi:ss') INS_DATE," ) ;
strSql . AppendLine ( " CASE" ) ;
strSql . AppendLine ( " WHEN ADD_MONTHS(TO_DATE(a.PROD_DATE, 'YYYYMMDD'), 12) <= SYSDATE THEN '一年以上'" ) ;
strSql . AppendLine ( " WHEN ADD_MONTHS(TO_DATE(a.PROD_DATE, 'YYYYMMDD'), 6) <= SYSDATE THEN '6~12个月'" ) ;
strSql . AppendLine ( " WHEN ADD_MONTHS(TO_DATE(a.PROD_DATE, 'YYYYMMDD'), 3) <= SYSDATE THEN '3~6个月'" ) ;
strSql . AppendLine ( " ELSE '3个月以内'" ) ;
strSql . AppendLine ( " END AS TYPE," ) ;
strSql . AppendLine ( " a.* " ) ;
strSql . AppendLine ( " FROM TB_INVENTORY_ANALYSIS a " ) ;
strSql . AppendLine ( " where 1=1 " ) ;
if ( ! string . IsNullOrEmpty ( QAGP . PLATE_NO ) )
{
strSql . AppendLine ( " AND a.PLATE_NO='" + QAGP . PLATE_NO + "'" ) ;
}
//工厂
if ( ! string . IsNullOrWhiteSpace ( QAGP . PLT ) )
{
strSql . AppendLine ( " AND a.PLT = '" + QAGP . PLT + "'" ) ;
}
//判定结果
if ( ! string . IsNullOrEmpty ( QAGP . INVENTORY_TYPE ) )
{
if ( QAGP . INVENTORY_TYPE = = "判现" )
{
strSql . AppendLine ( " AND a.INVENTORY_TYPE = '1' " ) ;
}
if ( QAGP . INVENTORY_TYPE = = "判废" )
{
strSql . AppendLine ( " AND a.INVENTORY_TYPE = '2'" ) ;
}
if ( QAGP . INVENTORY_TYPE = = "待定" )
{
strSql . AppendLine ( " AND a.INVENTORY_TYPE = '3'" ) ;
}
if ( QAGP . INVENTORY_TYPE = = "保留" )
{
strSql . AppendLine ( " AND a.INVENTORY_TYPE = '4'" ) ;
}
//strSql.AppendLine(" AND INVENTORY_TYPE = '" + QAGP.INVENTORY_TYPE + "'");
}
//if (QAGP.START_TIME != DateTime.MinValue)
//{
// strSql.AppendLine(" AND TO_DATE(a.INS_DATE,'yyyy-MM-dd HH24:mi:ss') >= TO_DATE('" + QAGP.START_TIME + "','yyyy-MM-dd HH24:mi:ss')");
//}
//if (QAGP.END_TIME != DateTime.MinValue)
//{
// strSql.AppendLine(" AND TO_DATE(a.INS_DATE,'yyyy-MM-dd HH24:mi:ss') <= TO_DATE('" + QAGP.END_TIME + "','yyyy-MM-dd HH24:mi:ss')");
//}
if ( ! string . IsNullOrWhiteSpace ( CommonUtils . ObjectToStr ( QAGP . START_TIME ) ) & & CommonUtils . ObjectToStr ( QAGP . START_TIME ) ! = "0001/1/1 0:00:00" )
strSql . AppendLine ( " AND TO_DATE(a.INS_DATE,'yyyy-MM-dd HH24:mi:ss') >= to_date('" + CommonUtils . ObjectToStr ( QAGP . START_TIME ) + "','yyyy-mm-dd hh24:mi:ss')" ) ;
if ( ! string . IsNullOrWhiteSpace ( CommonUtils . ObjectToStr ( QAGP . END_TIME ) ) & & CommonUtils . ObjectToStr ( QAGP . END_TIME ) ! = "0001/1/1 0:00:00" )
strSql . AppendLine ( " AND TO_DATE(a.INS_DATE,'yyyy-MM-dd HH24:mi:ss') < to_date('" + CommonUtils . ObjectToStr ( QAGP . END_TIME . AddDays ( 1 ) ) + "','yyyy-mm-dd hh24:mi:ss')" ) ;
if ( QAGP . START_TIME = = DateTime . MinValue & & QAGP . END_TIME = = DateTime . MinValue )
{
QAGP . START_TIME = DateTime . Now . AddDays ( - 7 ) ;
QAGP . END_TIME = DateTime . Now ;
strSql . AppendLine ( " AND TO_DATE(a.INS_DATE,'yyyy-MM-dd HH24:mi:ss') >= to_date('" + CommonUtils . ObjectToStr ( QAGP . START_TIME . ToString ( "yyyy-MM-dd" ) ) + "','yyyy-mm-dd hh24:mi:ss')" ) ;
strSql . AppendLine ( " AND TO_DATE(a.INS_DATE,'yyyy-MM-dd HH24:mi:ss') < to_date('" + CommonUtils . ObjectToStr ( QAGP . END_TIME . AddDays ( 1 ) ) + "','yyyy-mm-dd hh24:mi:ss')" ) ;
}
strSql . AppendLine ( " ORDER BY a.INS_DATE DESC " ) ;
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
dtCheck = db . Query ( strSql . ToString ( ) ) ;
result . data = dtCheck ;
if ( dtCheck . Rows . Count > 0 )
{
string directoryPath = "D:\\Test\\nginx\\html\\assets" ;
string filePath = Path . Combine ( directoryPath , "库存分析.xlsx" ) ; // 设置文件保存路径
// 检查目标文件夹是否存在,如果不存在则创建
if ( ! Directory . Exists ( directoryPath ) )
{
Directory . CreateDirectory ( directoryPath ) ;
}
ExportToExcel ( dtCheck , columnMapping , filePath ) ;
result . msg = "操作成功!" ;
result . code = "1" ;
}
else
{
result . msg = "未找到查询所需数据!" ;
result . code = "1" ;
}
}
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "GetTrendAnalysis 报错" , ex ) ;
}
return result ;
}
public void ExportToExcel ( DataTable fullDataTable , Dictionary < string , string > columnMapping , string filePath )
{
IWorkbook workbook = new XSSFWorkbook ( ) ;
ISheet sheet = workbook . CreateSheet ( "Sheet1" ) ;
// 写入表头
IRow headerRow = sheet . CreateRow ( 0 ) ;
int colIndex = 0 ;
foreach ( string columnName in columnMapping . Keys )
{
string columnDisplayName = columnMapping [ columnName ] ;
headerRow . CreateCell ( colIndex ) . SetCellValue ( columnDisplayName ) ;
// 设置列宽
sheet . SetColumnWidth ( colIndex , 15 * 256 ) ;
colIndex + + ;
}
//// 写入数据行
//int n = fullDataTable.Rows.Count;
//Task[] tasks = new Task[n];
//for (int row = 0; row < fullDataTable.Rows.Count; row++)
//{
// int rowIndex = row;
// tasks[row] = Task.Factory.StartNew(() =>
// {
// lock (lockObject) // 加锁
// {
// IRow dataRow = sheet.CreateRow(rowIndex + 1);
// int localColIndex = 0;
// foreach (string columnName in columnMapping.Keys)
// {
// if (fullDataTable.Columns.Contains(columnName))
// {
// object cellValue = fullDataTable.Rows[rowIndex][columnName];
// ICell dataCell = dataRow.CreateCell(localColIndex);
// dataCell.SetCellValue(cellValue.ToString());
// localColIndex++;
// }
// }
// }
// });
//}
//Task.WaitAll(tasks);
// 写入数据行
for ( int row = 0 ; row < fullDataTable . Rows . Count ; row + + )
{
IRow dataRow = sheet . CreateRow ( row + 1 ) ;
colIndex = 0 ;
foreach ( string columnName in columnMapping . Keys )
{
if ( fullDataTable . Columns . Contains ( columnName ) )
{
object cellValue = fullDataTable . Rows [ row ] [ columnName ] ;
ICell dataCell = dataRow . CreateCell ( colIndex ) ;
dataCell . SetCellValue ( cellValue . ToString ( ) ) ;
colIndex + + ;
}
}
}
// 保存 Excel 文件
using ( FileStream fileStream = new FileStream ( filePath , FileMode . Create , FileAccess . Write ) )
{
workbook . Write ( fileStream ) ;
}
}
[HttpPost, Route("GetPDI_SMP_NO")]
public RequestEntity GetPDI_SMP_NO ( GpPlateQueryArgs QAGP )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
DataTable dtPlate = new DataTable ( ) ;
//PLATE_NO , STLGRD , SUPERSED_TIME , PLATE_SIZE , ORD_WGT , AVE_SUP_RATE , SUP_NUM , YIELD_RATIO
//strSql.AppendLine(" select to_date('1970-01-01 08:00:00','yyyy-mm-dd hh24:mi:ss')+t.timestamp/86400000 send_date,PLATE_NO,SMP_NO,NVL(COSTS, 0) COSTS,case DISPOSE when '1' then '并号' when '2' then '不符标准' when '3' then '无试样' else '并样' end types, case SYNOPSIS when 2 then '不发送' else '发送' end IS_PDI, t.* FROM PDI_SMP_NO t");
//strSql.AppendLine(" where 1=1 ");
//strSql.AppendLine(" AND IS_STATE='1' ");
strSql . AppendLine ( " select " ) ;
strSql . AppendLine ( " to_date(INS_DATE, 'yyyy-mm-dd hh24:mi:ss') SEND_DATE " ) ;
strSql . AppendLine ( " ,PLATE_NO,SMP_NO,NVL(COSTS, 0) COSTS " ) ;
strSql . AppendLine ( " ,case DISPOSE when '1' then '并号' when '2' then '不符标准' when '3' then '无试样' else '并样' end types " ) ;
strSql . AppendLine ( " , case SYNOPSIS when 2 then '不发送' else '发送' end IS_PDI " ) ;
strSql . AppendLine ( " , t.*FROM PDI_SMP_NO t " ) ;
strSql . AppendLine ( " where 1 = 1 " ) ;
strSql . AppendLine ( " AND IS_STATE = '1' " ) ;
//strSql.AppendLine(" AND to_date(INS_DATE,'yyyy-mm-dd hh24:mi:ss') >= TO_DATE('2024-04-01 0:00:00', 'yyyy-MM-dd HH24:mi:ss') ");
//strSql.AppendLine(" AND to_date(INS_DATE,'yyyy-mm-dd hh24:mi:ss') <= TO_DATE('2024-04-18 0:00:00', 'yyyy-MM-dd HH24:mi:ss') ");
#region where条件
if ( ! string . IsNullOrEmpty ( QAGP . DIVISION ) )
{
if ( QAGP . DIVISION = = "是" )
{
strSql . AppendLine ( " AND t.SYNOPSIS <> 2" ) ;
}
else
{
strSql . AppendLine ( " AND t.SYNOPSIS = 2" ) ;
}
}
//状态
if ( ! string . IsNullOrEmpty ( QAGP . PROC_CD ) )
{
strSql . AppendLine ( " AND t.PROC_CD='" + QAGP . PROC_CD + "'" ) ;
}
//堆放仓库
if ( QAGP . CUR_INV ! = null & & QAGP . CUR_INV . Length > 0 )
{
int i = 0 ;
string CUR_INV = string . Empty ;
foreach ( string inv in QAGP . CUR_INV )
{
if ( i > 0 )
{
CUR_INV + = "," ;
}
CUR_INV + = inv ;
i + + ;
}
CUR_INV = CUR_INV . Replace ( "," , "','" ) ;
strSql . AppendLine ( " AND t.CUR_INV in ('" + CUR_INV + "')" ) ;
//string CUR_INV = QAGP.CUR_INV.ToString();
}
if ( ! string . IsNullOrEmpty ( QAGP . PLATE_NO ) )
{
strSql . AppendLine ( " AND t.PLATE_NO='" + QAGP . PLATE_NO + "'" ) ;
}
//订单号
if ( ! string . IsNullOrEmpty ( QAGP . ORD_NO ) )
{
strSql . AppendLine ( " AND t.ORD_NO='" + QAGP . ORD_NO + "'" ) ;
}
//项次号
if ( ! string . IsNullOrEmpty ( QAGP . ORD_ITEM ) )
{
strSql . AppendLine ( " AND t.ORD_ITEM='" + QAGP . ORD_ITEM + "'" ) ;
}
//原始订单号
if ( ! string . IsNullOrEmpty ( QAGP . ORG_ORD_NO ) )
{
strSql . AppendLine ( " AND t.ORG_ORD_NO='" + QAGP . ORG_ORD_NO + "'" ) ;
}
//原始项次号
if ( ! string . IsNullOrEmpty ( QAGP . ORG_ORD_ITEM ) )
{
strSql . AppendLine ( " AND t.ORG_ORD_ITEM='" + QAGP . ORG_ORD_ITEM + "'" ) ;
}
////轧批号
//if (!string.IsNullOrEmpty(QAGP.OUT_SHEET_NO))
//{
// strSql.AppendLine(" AND t.OUT_SHEET_NO='" + QAGP.OUT_SHEET_NO + "'");
//}
//钢板号
if ( ! string . IsNullOrEmpty ( QAGP . PLATE_NO ) )
{
strSql . AppendLine ( " AND t.PLATE_NO='" + QAGP . PLATE_NO + "'" ) ;
}
if ( ! string . IsNullOrEmpty ( QAGP . SMP_NO_TYPE ) )
{
strSql . AppendLine ( " AND t.CD_NAME='" + QAGP . SMP_NO_TYPE + "'" ) ;
}
//试样处理方式
if ( ! string . IsNullOrEmpty ( QAGP . TYPES ) )
{
if ( QAGP . TYPES = = "并号" )
{
strSql . AppendLine ( " AND t.DISPOSE='1'" ) ;
}
if ( QAGP . TYPES = = "不符标准" )
{
strSql . AppendLine ( " AND t.DISPOSE='2'" ) ;
}
if ( QAGP . TYPES = = "无试样" )
{
strSql . AppendLine ( " AND t.DISPOSE='3'" ) ;
}
if ( QAGP . TYPES = = "并样" )
{
strSql . AppendLine ( " AND t.SYNOPSIS = 2" ) ;
}
//strSql.AppendLine(" AND t.DISPOSE='" + QAGP.TYPES + "'");
}
//生产厂
if ( ! string . IsNullOrEmpty ( QAGP . PLT ) )
{
strSql . AppendLine ( " AND t.PLT='" + QAGP . PLT + "'" ) ;
}
//订单号
if ( ! string . IsNullOrEmpty ( QAGP . PLATE_NO ) )
{
strSql . AppendLine ( " AND t.PLATE_NO='" + QAGP . PLATE_NO + "'" ) ;
}
//并号检索结果
if ( ! string . IsNullOrEmpty ( QAGP . RETRIEVAL ) )
{
strSql . AppendLine ( " AND t.RETRIEVAL LIKE '%" + QAGP . RETRIEVAL + "%'" ) ;
}
//标准号
if ( ! string . IsNullOrEmpty ( QAGP . APLY_STDSPEC ) )
{
strSql . AppendLine ( " AND t.APLY_STDSPEC LIKE '%" + QAGP . APLY_STDSPEC + "%'" ) ;
}
//生产日期
if ( QAGP . START_TIME ! = DateTime . MinValue )
{
//strSql.AppendLine(" AND TO_DATE('1970-01-01 08:00:00','yyyy-mm-dd hh24:mi:ss')+t.timestamp/86400000 >= TO_DATE('" + QAGP.START_TIME + "','yyyy-MM-dd HH24:mi:ss')");
//AND to_date(SUBSTR(INS_DATE,0,8) ,'YYYY-MM-DD HH24:MI:SS') >= TO_DATE('2024/4/25 0:00:00', 'YYYY-MM-DD HH24:MI:SS')
strSql . AppendLine ( " AND to_date(SUBSTR( INS_DATE,0,8) ,'YYYY-MM-DD HH24:MI:SS') >= TO_DATE('" + QAGP . START_TIME . ToString ( ) + "', 'YYYY-MM-DD HH24:MI:SS') " ) ;
}
if ( QAGP . END_TIME ! = DateTime . MinValue )
{
////strSql.AppendLine(" AND TO_DATE('1970-01-01 08:00:00','yyyy-mm-dd hh24:mi:ss')+t.timestamp/86400000 <= TO_DATE('" + QAGP.END_TIME + "','yyyy-MM-dd HH24:mi:ss')");
//strSql.AppendLine(" AND to_date(SUBSTR( INS_DATE,0,8) ,'yyyy-mm-dd') <= TO_DATE('" + QAGP.END_TIME.ToString().Substring(0, 10) + "', 'yyyy-MM-dd') ");
strSql . AppendLine ( " AND to_date(SUBSTR( INS_DATE,0,8) ,'YYYY-MM-DD HH24:MI:SS') <= TO_DATE('" + QAGP . END_TIME . ToString ( ) + "', 'YYYY-MM-DD HH24:MI:SS') " ) ;
}
strSql . AppendLine ( "ORDER BY INS_DATE" ) ;
# endregion
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
logger . InfoFormat ( "GetPDI_SMP_NO 报错SQL {0} " , QAGP . START_TIME . ToString ( ) ) ;
logger . InfoFormat ( "GetPDI_SMP_NO 报错SQL {0} " , QAGP . END_TIME . ToString ( ) ) ;
logger . InfoFormat ( "GetPDI_SMP_NO 报错SQL {0} " , strSql . ToString ( ) ) ;
dtCheck = db . Query ( strSql . ToString ( ) ) ;
dtCheck . Columns . Add ( "PROC_CD_NOW" ) ;
dtCheck . Columns . Add ( "SMP_NO_NOW" ) ;
dtCheck . Columns . Add ( "ACT_SMP_FL_NOW" ) ;
string plate_no = " select PLATE_NO,PROC_CD,SMP_NO,ACT_SMP_FL from NISCO.GP_PLATE where PLATE_NO in ('" ;
if ( dtCheck . Rows . Count > 0 )
{
int n = 0 ;
foreach ( DataRow row in dtCheck . Rows )
{
if ( n = = 0 )
{
plate_no + = row [ "PLATE_NO" ] . ToString ( ) ;
}
else
{
plate_no + = "','" + row [ "PLATE_NO" ] . ToString ( ) ;
}
//多条1000会报错 截取城 多列sql 查询
if ( n > 900 )
{
n = n - 900 ;
plate_no + = "') or PLATE_NO in ('" + row [ "PLATE_NO" ] . ToString ( ) ;
}
n + + ;
}
plate_no + = "')" ;
using ( IDbContext db_sur = ObjectContainer . GetObject < IDbContext > ( "db_sur" ) )
{
dtPlate = db_sur . Query ( plate_no . ToString ( ) ) ;
}
if ( dtPlate . Rows . Count > 0 )
{
foreach ( DataRow row in dtCheck . Rows )
{
DataRow [ ] rw = dtPlate . Select ( " PLATE_NO='" + row [ "PLATE_NO" ] . ToString ( ) + "'" ) ;
if ( rw . Length > 0 )
{
string PROC_CD_NOW = rw [ 0 ] [ "PROC_CD" ] . ToString ( ) ;
string SMP_NO_NOW = rw [ 0 ] [ "SMP_NO" ] . ToString ( ) ;
string ACT_SMP_FL_NOW = rw [ 0 ] [ "ACT_SMP_FL" ] . ToString ( ) ;
row [ "PROC_CD_NOW" ] = PROC_CD_NOW ;
row [ "SMP_NO_NOW" ] = SMP_NO_NOW ;
row [ "ACT_SMP_FL_NOW" ] = ACT_SMP_FL_NOW ;
}
}
}
}
result . data = dtCheck ;
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 ( "GetPDI_SMP_NO 报错" , ex ) ;
}
return result ;
}
[HttpPost, Route("GetPDI_QAE")]
public RequestEntity GetPDI_QAE ( GpPlateQueryArgs QAGP )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
//PLATE_NO , STLGRD , SUPERSED_TIME , PLATE_SIZE , ORD_WGT , AVE_SUP_RATE , SUP_NUM , YIELD_RATIO
strSql . AppendLine ( " SELECT to_date('1970-01-01 08:00:00','yyyy-mm-dd hh24:mi:ss')+t.timestamp/86400000 send_date,PLATE_NO,SMP_NO,SUB_LACK_CON,t.* FROM PDI_QAE t " ) ;
strSql . AppendLine ( " where 1=1 " ) ;
if ( ! string . IsNullOrEmpty ( QAGP . PLATE_NO ) )
{
strSql . AppendLine ( " AND t.PLATE_NO='" + QAGP . PLATE_NO + "'" ) ;
}
if ( ! string . IsNullOrEmpty ( QAGP . APLY_STDSPEC ) )
{
strSql . AppendLine ( " AND t.APLY_STDSPEC='" + QAGP . APLY_STDSPEC + "'" ) ;
}
if ( ! string . IsNullOrEmpty ( QAGP . ORD_NO ) )
{
strSql . AppendLine ( " AND t.ORD_NO='" + QAGP . ORD_NO + "'" ) ;
}
if ( ! string . IsNullOrEmpty ( QAGP . ORD_ITEM ) )
{
strSql . AppendLine ( " AND t.ORD_ITEM='" + QAGP . ORD_ITEM + "'" ) ;
}
if ( ! string . IsNullOrEmpty ( QAGP . PLT ) )
{
strSql . AppendLine ( " AND t.PLT='" + QAGP . PLT + "'" ) ;
}
if ( QAGP . START_TIME ! = DateTime . MinValue )
{
strSql . AppendLine ( " AND TO_DATE('1970-01-01 08:00:00','yyyy-mm-dd hh24:mi:ss')+t.timestamp/86400000 >= TO_DATE('" + QAGP . START_TIME + "','yyyy-MM-dd HH24:mi:ss')" ) ;
}
if ( QAGP . END_TIME ! = DateTime . MinValue )
{
strSql . AppendLine ( " AND TO_DATE('1970-01-01 08:00:00','yyyy-mm-dd hh24:mi:ss')+t.timestamp/86400000 <= TO_DATE('" + QAGP . END_TIME + "','yyyy-MM-dd HH24:mi:ss')" ) ;
}
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
dtCheck = db . Query ( strSql . ToString ( ) ) ;
result . data = dtCheck ;
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 ( "GetTrendAnalysis 报错" , ex ) ;
}
return result ;
}
/// <summary>
/// 获取手动并样数据
/// </summary>
/// <param name="QAGP"></param>
/// <returns></returns>
[HttpPost, Route("GetCONFIRMSMPNO")]
public RequestEntity GetCONFIRMSMPNO ( GpPlateQueryArgs QAGP )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
DataTable dtPlate = new DataTable ( ) ;
strSql . AppendLine ( " SELECT * FROM CONFIRMSMPNO " ) ;
strSql . AppendLine ( " where 1=1 " ) ;
//strSql.AppendLine(" AND IS_BING ='0' ");
//试样号
if ( ! string . IsNullOrWhiteSpace ( QAGP . SMP_NO ) )
{
strSql . AppendLine ( " AND SMP_NO = '" + QAGP . SMP_NO + "'" ) ;
}
//钢板号
if ( ! string . IsNullOrWhiteSpace ( QAGP . PLATE_NO ) )
{
strSql . AppendLine ( " AND PLATE_NO = '" + QAGP . PLATE_NO + "'" ) ;
}
if ( ! string . IsNullOrEmpty ( QAGP . CERT_TYPE ) )
{
if ( QAGP . CERT_TYPE = = "船板" )
{
strSql . AppendLine ( " AND CERT_TYPE = 'S' " ) ;
}
if ( QAGP . CERT_TYPE = = "非船板" )
{
strSql . AppendLine ( " AND CERT_TYPE <> 'S'" ) ;
}
}
//工厂
if ( ! string . IsNullOrWhiteSpace ( QAGP . PLT ) )
{
strSql . AppendLine ( " AND PLT = '" + QAGP . PLT + "'" ) ;
}
strSql . AppendLine ( " ORDER BY INS_DATE DESC " ) ;
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
dtCheck = db . Query ( strSql . ToString ( ) ) ;
dtCheck . Columns . Add ( "PRC_LINE_NOW" ) ;
string plate_no = " select PLATE_NO,PRC_LINE from NISCO.GP_PLATE where PLATE_NO in ('" ;
if ( dtCheck . Rows . Count > 0 )
{
int n = 0 ;
foreach ( DataRow row in dtCheck . Rows )
{
if ( n = = 0 )
{
plate_no + = row [ "PLATE_NO" ] . ToString ( ) ;
}
else
{
plate_no + = "','" + row [ "PLATE_NO" ] . ToString ( ) ;
}
//多条1000会报错 截取城 多列sql 查询
if ( n > 900 )
{
n = n - 900 ;
plate_no + = "') or PLATE_NO in ('" + row [ "PLATE_NO" ] . ToString ( ) ;
}
n + + ;
}
plate_no + = "')" ;
using ( IDbContext db_sur = ObjectContainer . GetObject < IDbContext > ( "db_sur" ) )
{
dtPlate = db_sur . Query ( plate_no . ToString ( ) ) ;
}
if ( dtPlate . Rows . Count > 0 )
{
foreach ( DataRow row in dtCheck . Rows )
{
DataRow [ ] rw = dtPlate . Select ( " PLATE_NO='" + row [ "PLATE_NO" ] . ToString ( ) + "'" ) ;
if ( rw . Length > 0 )
{
string PRC_LINE_NOW = rw [ 0 ] [ "PRC_LINE" ] . ToString ( ) ;
row [ "PRC_LINE_NOW" ] = PRC_LINE_NOW ;
}
}
}
}
result . data = dtCheck ;
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 ( "GetPDI_SMP_NO 报错" , ex ) ;
}
return result ;
}
/// <summary>
/// 手动并样存储PDO
/// </summary>
/// <param name="QAGP"></param>
/// <returns></returns>
[HttpPost, Route("ADDPDO_CONFIRMSMPNO")]
public RequestEntity ADDPDO_CONFIRMSMPNO ( IList < CONFIRMSMPNO > delModel )
{
RequestEntity result = new RequestEntity ( ) ;
StringBuilder strSql = new StringBuilder ( ) ;
StringBuilder strSql2 = new StringBuilder ( ) ;
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
try
{
db . BeginTransaction ( ) ;
bool b = true ;
foreach ( var model in delModel )
{
TBDIPDO InsertPDO = GetPDO ( model ) ;
if ( InsertPDO ! = null )
{
db . Insert < TBDIPDO > ( InsertPDO ) ;
}
else
{
b = false ;
}
//strSql.AppendLine("DELETE FROM CONFIRMSMPNO WHERE 1=1 ");
strSql . AppendLine ( " UPDATE CONFIRMSMPNO SET IS_BING = '1' " ) ;
strSql . AppendLine ( string . Format ( " WHERE 1 = 1 " ) ) ;
strSql . AppendLine ( string . Format ( "AND PLATE_NO = '{0}' " , model . PLATE_NO ) ) ;
strSql . AppendLine ( string . Format ( "AND ORD_NO = '{0}' " , model . ORD_NO ) ) ;
strSql . AppendLine ( string . Format ( "AND ORD_ITEM = '{0}' " , model . ORD_ITEM ) ) ;
db . Execute ( strSql . ToString ( ) ) ; // 执行删除数据操作
strSql2 . AppendLine ( " UPDATE PDI_SMP_NO SET IS_STATE = '1', " ) ;
strSql2 . AppendLine ( string . Format ( " INS_DATE='{0}' " , DateTime . Now . ToString ( "yyyyMMddHHmmss" ) ) ) ;
strSql2 . AppendLine ( string . Format ( " WHERE 1 = 1 " ) ) ;
strSql2 . AppendLine ( string . Format ( "AND PLATE_NO = '{0}' " , model . PLATE_NO ) ) ;
strSql2 . AppendLine ( string . Format ( "AND ORD_NO = '{0}' " , model . ORD_NO ) ) ;
strSql2 . AppendLine ( string . Format ( "AND ORD_ITEM = '{0}' " , model . ORD_ITEM ) ) ;
strSql2 . AppendLine ( string . Format ( "AND SMP_NO = '{0}' " , model . SMP_NO ) ) ;
//strSql2.AppendLine(string.Format("AND INS_DATE = '{0}' ", model.INS_DATE));
db . Execute ( strSql2 . ToString ( ) ) ; // 执行删除数据操作
strSql . Length = 0 ;
strSql2 . Length = 0 ;
}
if ( b )
{
db . Commit ( ) ;
}
else
{
db . Rollback ( ) ;
}
result . msg = "操作成功" ;
result . code = "1" ;
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "ADDPDO_CONFIRMSMPNO 报错" , ex ) ;
}
}
return result ;
}
/// <summary>
/// 获取手动替代WG仓库钢板信息
/// </summary>
/// <param name="QAGP"></param>
/// <returns></returns>
[HttpPost, Route("GetConfirmWG")]
public RequestEntity GetConfirmWG ( GpPlateQueryArgs QAGP )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
strSql . AppendLine ( " SELECT * FROM REMA_LOC_WG " ) ;
strSql . AppendLine ( " where 1=1 " ) ;
//钢板号
if ( ! string . IsNullOrWhiteSpace ( QAGP . PLATE_NO ) )
{
strSql . AppendLine ( " AND PLATE_NO = '" + QAGP . PLATE_NO + "'" ) ;
}
strSql . AppendLine ( " ORDER BY INS_DATE DESC " ) ;
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
dtCheck = db . Query ( strSql . ToString ( ) ) ;
result . data = dtCheck ;
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 ( "GetTrendAnalysis 报错" , ex ) ;
}
return result ;
}
/// <summary>
/// 手动确认WG仓库可替代余材, 存储PDO
/// </summary>
/// <param name="QAGP"></param>
/// <returns></returns>
[HttpPost, Route("ADDPDO_REMA_LOC_WG")]
public RequestEntity ADDPDO_REMA_LOC_WG ( IList < REMA_LOC_WG > delModel )
{
RequestEntity result = new RequestEntity ( ) ;
StringBuilder strSql = new StringBuilder ( ) ;
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
try
{
db . BeginTransaction ( ) ;
bool b = true ;
foreach ( var model in delModel )
{
TBDIPDO InsertPDO = GetWGPDO ( model ) ;
if ( InsertPDO ! = null )
{
db . Insert < TBDIPDO > ( InsertPDO ) ;
}
else
{
b = false ;
}
strSql . AppendLine ( " DELETE FROM REMA_LOC_WG WHERE 1=1 " ) ;
strSql . AppendLine ( string . Format ( "AND PLATE_NO = '{0}' " , model . PLATE_NO ) ) ;
strSql . AppendLine ( string . Format ( "AND ORD_NO = '{0}' " , model . ORD_NO ) ) ;
strSql . AppendLine ( string . Format ( "AND ORD_ITEM = '{0}' " , model . ORD_ITEM ) ) ;
db . Execute ( strSql . ToString ( ) ) ; // 执行删除数据操作
strSql . Length = 0 ;
}
if ( b )
{
db . Commit ( ) ;
}
else
{
db . Rollback ( ) ;
}
result . msg = "操作成功" ;
result . code = "1" ;
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "ADDPDO_REMA_LOC_WG 报错" , ex ) ;
}
}
return result ;
}
/// <summary>
/// 获取未存储标准维护数据
/// </summary>
/// <param name="QAGP"></param>
/// <returns></returns>
[HttpPost, Route("GetYCTD_WH_NO")]
public RequestEntity GetYCTD_WH_NO ( GpPlateQueryArgs QAGP )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
//strSql.AppendLine(" SELECT STANDARD_NO, TD_STANDARD_NO, INS_DATE, UPD_DATE ");
//strSql.AppendLine("FROM ( ");
//strSql.AppendLine(" SELECT ");
//strSql.AppendLine(" STANDARD_NO, ");
//strSql.AppendLine(" TD_STANDARD_NO, ");
//strSql.AppendLine(" INS_DATE, ");
//strSql.AppendLine(" UPD_DATE, ");
//strSql.AppendLine(" ROW_NUMBER() OVER(PARTITION BY STANDARD_NO, TD_STANDARD_NO ORDER BY INS_DATE DESC) AS rn ");
//strSql.AppendLine(" FROM YCTD_WH_NO ");
//strSql.AppendLine(" ) WHERE rn = 1 ");
strSql . AppendLine ( "SELECT * FROM( " ) ;
strSql . AppendLine ( " SELECT STANDARD_NO, TD_STANDARD_NO, INS_DATE, UPD_DATE, TD_FL,THK_TOL_MIN,THK_TOL_MAX,REMARK " ) ;
strSql . AppendLine ( "FROM ( " ) ;
strSql . AppendLine ( " SELECT " ) ;
strSql . AppendLine ( " STANDARD_NO, " ) ;
strSql . AppendLine ( " TD_STANDARD_NO, " ) ;
strSql . AppendLine ( "INS_DATE, " ) ;
strSql . AppendLine ( "UPD_DATE, " ) ;
strSql . AppendLine ( "TD_FL, THK_TOL_MIN,THK_TOL_MAX ,REMARK, " ) ;
strSql . AppendLine ( " ROW_NUMBER() OVER(PARTITION BY STANDARD_NO, TD_STANDARD_NO ORDER BY INS_DATE DESC) AS rn " ) ;
strSql . AppendLine ( " FROM YCTD_WH_NO " ) ;
strSql . AppendLine ( " ) WHERE rn = 1 " ) ;
strSql . AppendLine ( " UNION ALL " ) ;
strSql . AppendLine ( " SELECT * FROM YCTD_WH_NO_COPY ) " ) ;
strSql . AppendLine ( " WHERE 1 = 1 " ) ;
//标准号
if ( ! string . IsNullOrWhiteSpace ( QAGP . STANDARD_NO ) )
{
strSql . AppendLine ( " AND STANDARD_NO LIKE '%" + QAGP . STANDARD_NO + "%'" ) ;
}
//可替代标准
if ( ! string . IsNullOrWhiteSpace ( QAGP . TD_STANDARD_NO ) )
{
strSql . AppendLine ( " AND TD_STANDARD_NO LIKE '%" + QAGP . TD_STANDARD_NO + "%'" ) ;
}
if ( ! string . IsNullOrWhiteSpace ( QAGP . TD_FL ) )
{
strSql . AppendLine ( " AND TD_FL = '" + QAGP . TD_FL + "'" ) ;
}
//厚度公差最小值
if ( ! string . IsNullOrWhiteSpace ( QAGP . THK_TOL_MIN ) )
{
strSql . AppendLine ( " AND THK_TOL_MIN <= '" + QAGP . THK_TOL_MIN + "'" ) ;
}
//厚度公差最最大值
if ( ! string . IsNullOrWhiteSpace ( QAGP . THK_TOL_MAX ) )
{
strSql . AppendLine ( " AND THK_TOL_MAX >= '" + QAGP . THK_TOL_MAX + "'" ) ;
}
strSql . AppendLine ( " ORDER BY INS_DATE DESC " ) ;
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
dtCheck = db . Query ( strSql . ToString ( ) ) ;
result . data = dtCheck ;
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 ( "GetYCTD_WH_NO 报错" , ex ) ;
}
return result ;
}
[HttpPost, Route("Del_YCTD_WH_NO")]
public RequestEntity Del_YCTD_WH_NO ( IList < YCTD_WH_NO > delModel )
{
RequestEntity result = new RequestEntity ( ) ;
StringBuilder strSql = new StringBuilder ( ) ;
StringBuilder strSql2 = new StringBuilder ( ) ;
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
try
{
db . BeginTransaction ( ) ;
//bool b = true;
foreach ( var model in delModel )
{
strSql . AppendLine ( " INSERT INTO YCTD_WH_NO_COPY (STANDARD_NO, TD_STANDARD_NO, INS_DATE, UPD_DATE, TD_FL,THK_TOL_MIN,THK_TOL_MAX,REMARK) VALUES ( " ) ;
strSql . AppendLine ( string . Format ( " '{0}', " , model . STANDARD_NO ) ) ;
strSql . AppendLine ( string . Format ( " '{0}', " , model . TD_STANDARD_NO ) ) ;
strSql . AppendLine ( string . Format ( " '{0}', " , DateTime . Now . ToString ( "yyyyMMddHHmmss" ) ) ) ;
strSql . AppendLine ( string . Format ( " '{0}', " , DateTime . Now . ToString ( "yyyyMMddHHmmss" ) ) ) ;
strSql . AppendLine ( string . Format ( " '{0}', " , "不维护" ) ) ;
strSql . AppendLine ( string . Format ( " '{0}', " , model . THK_TOL_MIN ) ) ;
strSql . AppendLine ( string . Format ( " '{0}' " , model . THK_TOL_MAX ) ) ;
strSql . AppendLine ( string . Format ( " '{0}' " , model . REMARK ) ) ;
strSql . AppendLine ( string . Format ( " ) " ) ) ;
db . Execute ( strSql . ToString ( ) ) ;
strSql2 . AppendLine ( " DELETE FROM YCTD_WH_NO WHERE 1 = 1 " ) ;
strSql2 . AppendLine ( string . Format ( "AND STANDARD_NO = '{0}' " , model . STANDARD_NO ) ) ;
strSql2 . AppendLine ( string . Format ( "AND TD_STANDARD_NO = '{0}' " , model . TD_STANDARD_NO ) ) ;
db . Execute ( strSql2 . ToString ( ) ) ; // 执行删除数据操作
strSql . Length = 0 ;
strSql2 . Length = 0 ;
}
db . Commit ( ) ;
result . msg = "操作成功" ;
result . code = "1" ;
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "Del_YCTD_WH_NO 报错" , ex ) ;
}
}
return result ;
}
[HttpPost, Route("Del_YCTD_WH_NO2")]
public RequestEntity Del_YCTD_WH_NO2 ( IList < YCTD_WH_NO > delModel )
{
RequestEntity result = new RequestEntity ( ) ;
StringBuilder strSql2 = new StringBuilder ( ) ;
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
try
{
db . BeginTransaction ( ) ;
//bool b = true;
foreach ( var model in delModel )
{
strSql2 . AppendLine ( " DELETE FROM YCTD_WH_NO_COPY WHERE 1 = 1 " ) ;
strSql2 . AppendLine ( string . Format ( "AND STANDARD_NO = '{0}' " , model . STANDARD_NO ) ) ;
strSql2 . AppendLine ( string . Format ( "AND TD_STANDARD_NO = '{0}' " , model . TD_STANDARD_NO ) ) ;
strSql2 . AppendLine ( string . Format ( "AND TD_FL = '不维护' " ) ) ;
db . Execute ( strSql2 . ToString ( ) ) ; // 执行删除数据操作
strSql2 . Length = 0 ;
}
db . Commit ( ) ;
result . msg = "操作成功" ;
result . code = "1" ;
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "Del_YCTD_WH_NO 报错" , ex ) ;
}
}
return result ;
}
/// <summary>
/// 获取时间戳
/// </summary>
/// <returns></returns>
public static string GetTimeStamp ( )
{
TimeSpan ts = DateTime . UtcNow - new DateTime ( 1970 , 1 , 1 , 8 , 0 , 0 , 0 ) ;
return Convert . ToInt64 ( ts . TotalMilliseconds ) . ToString ( ) ;
}
//并样PDO
public static TBDIPDO GetPDO ( CONFIRMSMPNO pdi )
{
TBDIPDO Result = new TBDIPDO ( ) ;
Result . TIMESTAMP = GetTimeStamp ( ) ; //TIMESTAMP: 1970.1.1 8:00:00 至当前时间的毫秒数
Result . SERIALNO = "0" ; //Serialno : 默认0, 对于TIMESTAMP: 重复时的区分号
Result . QUEUEID = "BKDMES000" ; //: 主键, BKDYC0001 , 有时序先后顺序的必须用同一个QUEUEID
Result . HEADER = "" ; // 未使用
//Result.DATA = "";// 前10位记录FORMID(例如: BKD001 / BKD002)
Result . STATUS = "N" ; // 发送方写入N, 读取成功后变0, 异常变1
Result . PROCESSTIME = DateTime . Now . ToString ( "yyyyMMddHHmmss" ) ; //:读取时间
Result . DESCRIPTION = "" ; //:读取异常备注
//StringBuilder strData = new StringBuilder();
//strData.Append(("BKDMESMP").PadRight(10));//FORMID: 10位 , BKDERP001 固定
//strData.Append(("").PadRight(12)); // 业务ID号 NUMBER(12) 流水号,需要再应答中带回
//strData.Append((pdi.PLATE_NO).PadRight(14));// 钢板号: VARCHAR2(14)
//strData.Append((pdi.SMP_NO).PadRight(14));// 试样号: VARCHAR2(14)
//strData.Append((pdi.SYNOPSIS.ToString()).PadRight(1));// 标记: VARCHAR2(14)
Result . DATA = pdi . DATA ;
return Result ;
}
//手动确认WG仓库可替代余材, 存储PDO
public static TBDIPDO GetWGPDO ( REMA_LOC_WG pdi )
{
TBDIPDO Result = new TBDIPDO ( ) ;
Result . TIMESTAMP = GetTimeStamp ( ) ; //TIMESTAMP: 1970.1.1 8:00:00 至当前时间的毫秒数
Result . SERIALNO = "0" ; //Serialno : 默认0, 对于TIMESTAMP: 重复时的区分号
Result . QUEUEID = pdi . QUEUEID ; //: 主键, BKDYC0001 , 有时序先后顺序的必须用同一个QUEUEID
Result . HEADER = "" ; // 未使用
Result . DATA = pdi . DATA ;
Result . STATUS = "N" ; // 发送方写入N, 读取成功后变0, 异常变1
Result . PROCESSTIME = DateTime . Now . ToString ( "yyyyMMddHHmmss" ) ; //:读取时间
Result . DESCRIPTION = "" ; //:读取异常备注
return Result ;
}
/// <summary>
/// 新增订单(外部需要调用的接口)
/// </summary>
/// <param name="gP_PLATE"></param>
/// <returns></returns>
[HttpPost, Route("addOrder")]
public RequestEntity AddOrder ( BP_ORDER_ITEM boi )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
try
{
//不管该订单是否可用都需要添加到表中
db . Insert < BP_ORDER_ITEM > ( boi ) ;
}
catch
{
logger . Info ( "订单插入失败了: " + boi . ToString ( ) ) ;
}
//判断新增的订单是不是可用订单
if ( boi . PROD_CD = = "PP" )
if ( boi . REC_STS = = "2" )
if ( boi . ORD_STS = = "E" | | boi . ORD_STS = = "D" )
if ( boi . ORD_KND = = "A" )
{
lock ( LOCK )
{
//调用所有数据匹配, 因为出现新余材, 所以重新匹配
AddSupersede ( null ) ;
}
}
result . msg = "操作成功!" ;
result . code = "1" ;
}
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "AddOrder 报错 : " , ex ) ;
}
return result ;
}
/// <summary>
/// 根据余材查询第一个可用订单
/// </summary>
/// <param name="gP_PLATE"></param>
/// <returns></returns>
[HttpPost, Route("getOrder")]
public RequestEntity GetOrder ( GP_PLATE gP_PLATE )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
//因为前端如果返回状态码 1 则需要data有值, 不能为null , 所以给个初始值
result . data = new List < BP_ORDER_ITEM > ( ) ;
//查询所有可用订单以及常用字段
strSql . AppendLine ( "SELECT T.* from BP_ORDER_ITEM T " +
// " LEFT JOIN CP_PRC F ON T.ORD_NO = F.ORD_NO" +
// " LEFT JOIN QP_QLTY_DELV C ON T.ORD_NO = C.ORD_NO" +
" WHERE 1=1" ) ;
strSql . AppendLine ( " AND T.PROD_CD = 'PP'" ) ;
strSql . AppendLine ( " AND T.REC_STS = '2'" ) ;
//订单状态
strSql . AppendLine ( " AND T.ORD_STS IN('E', 'D') " ) ;
//订单种类
strSql . AppendLine ( " AND T.ORD_KND = 'A' " ) ;
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
//查询所有可用订单
//SurplusMaterialSubstitutionController.orderEntities = db.Query<BP_ORDER_ITEM>(strSql.ToString());
IList < BP_ORDER_ITEM > bpOrderItems = db . Query < BP_ORDER_ITEM > ( strSql . ToString ( ) ) ;
foreach ( BP_ORDER_ITEM item in bpOrderItems )
{
if ( gP_PLATE . THK = = ( item . ORD_THK ) )
{
if ( gP_PLATE . WID = = ( item . ORD_WID ) )
{
if ( gP_PLATE . LEN = = ( item . ORD_LEN ) )
{
//符合条件的订单号
strSql . AppendLine ( " AND T.ORD_NO = '" + item . ORD_NO + "' " ) ;
//符合条件的订单序列号
strSql . AppendLine ( " AND T.ORD_ITEM = '" + item . ORD_ITEM + "' " ) ;
result . data = db . Query < BP_ORDER_ITEM > ( strSql . ToString ( ) ) ;
break ;
}
}
}
}
if ( result . data = = null )
{
result . msg = "操作成功未找到符合条件的数据!" ;
result . code = "1" ;
}
else
{
result . msg = "操作成功!" ;
result . code = "1" ;
}
}
}
catch ( Exception ex )
{
result . msg = "数据库错误!" ;
result . code = "0" ;
logger . Error ( "GetOrder 报错 : " , ex ) ;
}
return result ;
}
/// <summary>
/// 趋势查询按钮
/// 查询(TREND_ANALYSIS 表) 趋势表
/// </summary>
/// <param name="queryArgs"></param>
/// <returns></returns>
[HttpPost, Route("getTrendAnalysis")]
public RequestEntity GetTrendAnalysis ( )
{
RequestEntity result = new RequestEntity ( ) ; //声明返回参数实体类
StringBuilder strSql = new StringBuilder ( ) ; //声明拼接Sql语句变量
DataTable dtCheck = new DataTable ( ) ;
//PLATE_NO , STLGRD , SUPERSED_TIME , PLATE_SIZE , ORD_WGT , AVE_SUP_RATE , SUP_NUM , YIELD_RATIO
strSql . AppendLine ( "SELECT PLATE_NO , STLGRD , to_date(SUPERSED_TIME ,'yyyy-mm-dd hh24:mi:ss') as SUPERSED_TIME , PLATE_SIZE , ORD_WGT , AVE_SUP_RATE , SUP_NUM , YIELD_RATIO FROM TREND_ANALYSIS " ) ;
try
{
//开启数据库连接查询数据
using ( IDbContext db = ObjectContainer . GetObject < IDbContext > ( "db" ) )
{
dtCheck = db . Query ( strSql . ToString ( ) ) ;
result . data = db . Query < TREND_ANALYSIS > ( 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 ( "GetTrendAnalysis 报错" , ex ) ;
}
return result ;
}
}
}