天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

490 lines
19 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.FIS;
using QMFrameWork.Log;
using System.Data;
using QMAPP.FJC.Entity;
using QMAPP.FJC.Entity.FileCopy.FIS;
namespace QMAPP.FJC.DAL.FIS
{
public class FISOrderSendDAL
{
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(FISOrder condition, DataPage page)
{
string sql = null;
string countSql = null;
List<DataParameter> parameters = new List<DataParameter>();
List<FISOrder> list = new List<FISOrder>();
try
{
//分页关键字段及排序
page.KeyName = "PID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "CP5A DESC";
}
sql = this.GetPageQuerySql(condition, ref parameters, page);
countSql = this.GetCountQuerySql(condition);
int sum = 0;
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<FISOrder>(sql, parameters.ToArray()).ToList<FISOrder>();
sum = Convert.ToInt32(session.ExecuteSqlScalar(countSql, parameters.ToArray()));
}
page.RecordCount = sum;
page.Result = list;
#region 设置分页属性
if (page.RecordCount == 0)
{
page.PageIndex = 1;
return page;
}
if (page.RecordCount % page.PageSize != 0)
{
page.PageCount = page.RecordCount / page.PageSize + 1;
if (page.PageCount < page.PageIndex)
{
page.PageIndex = page.PageCount;
}
}
else
{
page.PageCount = page.RecordCount / page.PageSize;
}
if (page.PageCount < page.PageIndex)
{
page.PageIndex = page.PageCount;
}
#endregion
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "FIS 计划信息数据层-获取列表"
});
throw;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(FISOrder condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT F.PID, ");
sqlBuilder.AppendLine(" F.VWSEQ, ");
sqlBuilder.AppendLine(" F.KIN, ");
sqlBuilder.AppendLine(" F.VIN, ");
sqlBuilder.AppendLine(" F.PRODNO, ");
sqlBuilder.AppendLine(" F.CARSETDESC_CN, ");
sqlBuilder.AppendLine(" F.CP5A, ");
sqlBuilder.AppendLine(" F.SCANSTATE, ");
sqlBuilder.AppendLine(" F.[LINENO], ");
sqlBuilder.AppendLine(" F.CREATETIME, ");
sqlBuilder.AppendLine(" F.FLAGDEL, ");
sqlBuilder.AppendLine(" FD.SHIPMENT_NO, ");
sqlBuilder.AppendLine(" FD.STATE, ");
sqlBuilder.AppendLine(" FD.MATERIAL_CODE, ");
sqlBuilder.AppendLine(" FD.FACTORY_CODE, ");
sqlBuilder.AppendLine(" FD.WORKCENTER_CODE, ");
sqlBuilder.AppendLine(" SL.SENDCODE, ");
sqlBuilder.AppendLine(" SL.PRODUCT_SN, ");
sqlBuilder.AppendLine(" SL.QTY ");
sqlBuilder.AppendLine(" FROM T_PP_FISORDER F ");
sqlBuilder.AppendLine(" LEFT JOIN T_PP_FISORDERSENDDETAIL FD ON FD.FIS_PID=F.PID ");
sqlBuilder.AppendLine(" LEFT JOIN T_AW_SENDLIST SL ON SL.FIS_PID=F.PID ");
//查询条件
//大众顺序号
if (string.IsNullOrEmpty(condition.VWSEQ) == false)
{
whereBuilder.Append(" AND VWSEQ = @VWSEQ");
parameters.Add(new DataParameter { ParameterName = "VWSEQ", DataType = DbType.String, Value = condition.VWSEQ });
}
//KIN号
if (string.IsNullOrEmpty(condition.KIN) == false)
{
whereBuilder.Append(" AND KIN LIKE '%'+" + "@KIN" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "KIN", DataType = DbType.String, Value = condition.KIN });
}
//VIN号
if (string.IsNullOrEmpty(condition.VIN) == false)
{
whereBuilder.Append(" AND VIN LIKE '%'+" + "@VIN " + "+'%'");
parameters.Add(new DataParameter { ParameterName = "VIN", DataType = DbType.String, Value = condition.VIN });
}
//产品号
if (string.IsNullOrEmpty(condition.PRODNO) == false)
{
whereBuilder.Append(" AND PRODNO = @PRODNO");
parameters.Add(new DataParameter { ParameterName = "PRODNO", DataType = DbType.String, Value = condition.PRODNO });
}
//扫描状态
if (string.IsNullOrEmpty(condition.SCANSTATE) == false)
{
whereBuilder.Append(" AND SCANSTATE = @SCANSTATE");
parameters.Add(new DataParameter { ParameterName = "SCANSTATE", DataType = DbType.String, Value = condition.SCANSTATE });
}
//上线时间
if (condition.ONLINETIMESTART != DateTime.MinValue)
{
whereBuilder.Append(" AND CREATETIME >= @ONLINETIMESTART");
parameters.Add(new DataParameter { ParameterName = "ONLINETIMESTART", DataType = DbType.String, Value = condition.ONLINETIMESTART });
}
if (condition.ONLINETIMEEND != DateTime.MinValue)
{
whereBuilder.Append(" AND CREATETIME <= @ONLINETIMEEND");
parameters.Add(new DataParameter { ParameterName = "ONLINETIMEEND", DataType = DbType.String, Value = condition.ONLINETIMEEND });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 框架外的分页语句
/// </summary>
/// <param name="condition"></param>
/// <param name="parameters"></param>
/// <param name="page"></param>
/// <returns></returns>
private string GetPageQuerySql(FISOrder condition, ref List<DataParameter> parameters, DataPage page)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append("SELECT * FROM (");
sqlBuilder.AppendFormat(@"SELECT top {0} ROW_NUMBER() OVER (ORDER BY {1} ) AS ROWINDEX,", (page.PageIndex * page.PageSize).ToString(), page.SortExpression);
sqlBuilder.AppendLine(@" F.PID, ");
sqlBuilder.AppendLine(" F.VWSEQ, ");
sqlBuilder.AppendLine(" F.KIN, ");
sqlBuilder.AppendLine(" F.VIN, ");
sqlBuilder.AppendLine(" F.PRODNO, ");
sqlBuilder.AppendLine(" F.CARSETDESC_CN, ");
sqlBuilder.AppendLine(" F.CP5A, ");
sqlBuilder.AppendLine(" F.SCANSTATE, ");
sqlBuilder.AppendLine(" F.[LINENO], ");
sqlBuilder.AppendLine(" F.CREATETIME, ");
sqlBuilder.AppendLine(" F.FLAGDEL ");
sqlBuilder.AppendLine(" FROM T_PP_FISORDER F ");
#region 查询条件
//大众顺序号
if (string.IsNullOrEmpty(condition.VWSEQ) == false)
{
whereBuilder.Append(" AND VWSEQ = '" + condition.VWSEQ + "'");
}
//KIN号
if (string.IsNullOrEmpty(condition.KIN) == false)
{
whereBuilder.Append(" AND KIN LIKE '%" + condition.KIN + "%'");
}
//VIN号
if (string.IsNullOrEmpty(condition.VIN) == false)
{
whereBuilder.Append(" AND VIN LIKE '%" + condition.VIN + "%'");
}
//产品号
if (string.IsNullOrEmpty(condition.PRODNO) == false)
{
whereBuilder.Append(" AND PRODNO = '" + condition.PRODNO + "'");
}
//扫描状态
if (string.IsNullOrEmpty(condition.SCANSTATE) == false)
{
whereBuilder.Append(" AND SCANSTATE = '" + condition.SCANSTATE + "'");
}
//上线时间
if (condition.ONLINETIMESTART != DateTime.MinValue)
{
whereBuilder.Append(" AND CREATETIME >= '" + condition.ONLINETIMESTART.ToString("yyyy-MM-dd HH:mm:ss") + "'");
}
if (condition.ONLINETIMEEND != DateTime.MinValue)
{
whereBuilder.Append(" AND CREATETIME < '" + condition.ONLINETIMEEND.ToString("yyyy-MM-dd HH:mm:ss") + "'");
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
#endregion
sqlBuilder.AppendFormat(") QMDATAPAGE1 WHERE ROWINDEX BETWEEN {0} AND {1}", Convert.ToString(page.PageSize * (page.PageIndex - 1) + 1), Convert.ToString(page.PageSize * page.PageIndex));
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取求和语句
/// </summary>
/// <param name="condition"></param>
/// <param name="parameters"></param>
/// <returns></returns>
private string GetCountQuerySql(FISOrder condition)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
sqlBuilder.Append("SELECT count(1) FROM (");
sqlBuilder.AppendLine(@"SELECT ");
sqlBuilder.AppendLine(" F.VWSEQ, ");
sqlBuilder.AppendLine(" F.KIN, ");
sqlBuilder.AppendLine(" F.VIN, ");
sqlBuilder.AppendLine(" F.PRODNO, ");
sqlBuilder.AppendLine(" F.CARSETDESC_CN, ");
sqlBuilder.AppendLine(" F.CP5A, ");
sqlBuilder.AppendLine(" F.SCANSTATE, ");
sqlBuilder.AppendLine(" F.[LINENO], ");
sqlBuilder.AppendLine(" F.CREATETIME, ");
sqlBuilder.AppendLine(" F.FLAGDEL ");
sqlBuilder.AppendLine(" FROM T_PP_FISORDER F ");
#region 查询条件
//大众顺序号
if (string.IsNullOrEmpty(condition.VWSEQ) == false)
{
whereBuilder.Append(" AND VWSEQ = '" + condition.VWSEQ + "'");
}
//KIN号
if (string.IsNullOrEmpty(condition.KIN) == false)
{
whereBuilder.Append(" AND KIN LIKE '%" + condition.KIN + "%'");
}
//VIN号
if (string.IsNullOrEmpty(condition.VIN) == false)
{
whereBuilder.Append(" AND VIN LIKE '%" + condition.VIN + "%'");
}
//产品号
if (string.IsNullOrEmpty(condition.PRODNO) == false)
{
whereBuilder.Append(" AND PRODNO = '" + condition.PRODNO + "'");
}
//扫描状态
if (string.IsNullOrEmpty(condition.SCANSTATE) == false)
{
whereBuilder.Append(" AND SCANSTATE = '" + condition.SCANSTATE + "'");
}
//上线时间
if (condition.ONLINETIMESTART != DateTime.MinValue)
{
whereBuilder.Append(" AND CREATETIME >= '" + condition.ONLINETIMESTART.ToString("yyyy-MM-dd HH:mm:ss") + "'");
}
if (condition.ONLINETIMEEND != DateTime.MinValue)
{
whereBuilder.Append(" AND CREATETIME < '" + condition.ONLINETIMEEND.ToString("yyyy-MM-dd HH:mm:ss") + "'");
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
sqlBuilder.Append(" )temp1");
#endregion
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(FISOrder model)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//构成查询语句
sql = this.GetQuerySql(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "FISOrderSendExp";
}
return dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "FIS计划查询信息导出获取数据错误!"
});
throw ex;
}
}
#endregion
#region 获取FIS发货详细信息列表
/// <summary>
/// 获取FIS发货详细信息列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public List<FISOrederSendDetial> GetFISOrederSendDetialList(string id)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
List<FISOrederSendDetial> list = new List<FISOrederSendDetial>();
try
{
sql = this.GetProductInfectionQuerySql(id, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<FISOrederSendDetial>(sql, parameters.ToArray()).ToList<FISOrederSendDetial>();
}
return list;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "表皮信息投料信息查询错误!"
});
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetProductInfectionQuerySql(string id, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT F.PID, ");
sqlBuilder.AppendLine(" F.FIS_PID, ");
sqlBuilder.AppendLine(" F.SHIPMENT_NO, ");
sqlBuilder.AppendLine(" F.STATE, ");
sqlBuilder.AppendLine(" F.MATERIAL_CODE, ");
sqlBuilder.AppendLine(" M.MATERIAL_NAME, ");
sqlBuilder.AppendLine(" F.FACTORY_CODE, ");
sqlBuilder.AppendLine(" A.FACTORY_NAME, ");
sqlBuilder.AppendLine(" F.WORKCENTER_CODE, ");
sqlBuilder.AppendLine(" W.WORKCENTER_NAME, ");
sqlBuilder.AppendLine(" PC.PASTECARDNO AS SENDCODE, ");
sqlBuilder.AppendLine(" SL.SCANDATE, ");
sqlBuilder.AppendLine(" SL.SANBARCODE AS PRODUCT_SN, ");
sqlBuilder.AppendLine(" PC.OPERATOR, ");
sqlBuilder.AppendLine(" 1 AS QTY ");
sqlBuilder.AppendLine(" FROM T_PP_FISORDERSENDDETAIL F ");
sqlBuilder.AppendLine(" LEFT JOIN T_PP_FISORDER R ON R.PID=F.FIS_PID ");
sqlBuilder.AppendLine(" LEFT JOIN T_PP_PASCARDDETAILS SL ON SL.FISDETAILID=F.FIS_PID ");
sqlBuilder.AppendLine(" LEFT JOIN T_PP_PASTECARD AS PC ON PC.PID=SL.PASTECARDID ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_FACTORY A ON A.FACTORY_CODE=F.FACTORY_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL M ON M.MATERIAL_CODE=F.MATERIAL_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_WORKCENTER W ON W.WORKCENTER_CODE=F.WORKCENTER_CODE ");
#region 查询条件
if (string.IsNullOrEmpty(id) == false)
{
whereBuilder.Append(" AND R.PID = @id");
whereBuilder.Append(" AND F.FIS_PID = @id");
parameters.Add(new DataParameter { ParameterName = "id", DataType = DbType.String, Value = id });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
#endregion
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}