天津投入产出系统后端
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.
 
 
 
 
 
 

613 lines
36 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using QMAPP.DAL;
using QMAPP.FJC.Entity.Common.Constants;
using QMAPP.FJC.Entity.CompleteStatistics;
using QMFrameWork.Data;
namespace QMAPP.FJC.DAL.CompleteStatistics
{
public class TJCompleteStatisticsDAL : BaseDAL
{
public DataPage GetList(TJCompleteStatisticsEntity condition, DataPage page)
{
DataParameter[] parameters;
string sql = this.GetQuerySql(condition, out parameters);
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "ORDERNO ASC";
using (IDataSession session = AppDataFactory.CreateMainSession()) {
page = session.GetDataPage<TJCompleteStatisticsEntity>(sql, parameters, page);
}
return page;
}
public List<TJCompleteStatisticsEntity> GetList(TJCompleteStatisticsEntity condition)
{
DataParameter[] parameters;
string sql = this.GetQuerySql(condition, out parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList<TJCompleteStatisticsEntity>(sql, parameters).ToList();
}
}
public TJCompleteStatisticsEntity Get(TJCompleteStatisticsEntity model)
{
using (IDataSession session = AppDataFactory.CreateMainSession()) {
return session.Get(model);
}
}
public int Insert(TJCompleteStatisticsEntity model)
{
using (IDataSession session = AppDataFactory.CreateMainSession()) {
return session.Insert(model);
}
}
public int Select_Get(string ProductCode)
{
var sql = $"select * from T_AW_COMPLETE_TJSTATISTICS where ORDERNO = '{ProductCode}' and DELFLAG = '0'";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList<TJCompleteStatisticsEntity>(sql, new DataParameter[] { }).ToList().Count;
}
}
public bool ExistCompleteStatistics(TJCompleteStatisticsEntity model)
{
throw new NotImplementedException();
}
protected string ExistQureySql()
{
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT *");
sql.AppendLine(" FROM T_AW_MAINOPERATION T");
sql.AppendLine(" WHERE INFO.BARCODEIDENTIFY IS NOT NULL");
sql.AppendLine(" AND T.OPERATEDDATE > @StartTime");
sql.AppendLine(" AND T.OPERATEDDATE <= @EndTime");
return sql.ToString();
}
public int Update(TJCompleteStatisticsEntity model)
{
using (IDataSession session = AppDataFactory.CreateMainSession()) {
return session.Update(model);
}
}
public int GenericCompleteStatistics(DateTime starTime, DateTime endTime)
{
int count = 0;
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//DataParameter[] parameters = {
// new DataParameter {ParameterName = "StartTime", DataType = DbType.DateTime, Value = starTime},
// new DataParameter {ParameterName = "EndTime", DataType = DbType.DateTime, Value = endTime}
//};
try {
session.OpenTs();
//string location = this.GetSystemConfig(CompleteStatisticsConstants.COMP_STATIS_SITE).CODEVALUE;
//string sql = location.Equals("080121") ? this.GetGenericStatisticsSqlForCC() : this.GetGenericStatisticsSqlForCD();
//成品
//string sql = GetGenericStatisticsSqlForBORA();
//count = session.ExecuteSql(sql, parameters);
////注塑件
//sql = GetGenericStatisticsSqlForINJECT();
//count += session.ExecuteSql(sql, parameters);
this.UpdateLastGenericTime(endTime, session);
session.CommitTs();
}
catch (Exception) {
session.RollbackTs();
throw;
}
}
return count;
}
public int FrmPlaceCompleteStatistics(DateTime starTime, DateTime endTime)
{
int count = 0;
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//DataParameter[] parameters = {
// new DataParameter {ParameterName = "StartTime", DataType = DbType.DateTime, Value = starTime},
// new DataParameter {ParameterName = "EndTime", DataType = DbType.DateTime, Value = endTime}
//};
try
{
session.OpenTs();
//string location = this.GetSystemConfig(CompleteStatisticsConstants.COMP_STATIS_SITE).CODEVALUE;
//string sql = location.Equals("080121") ? this.GetGenericStatisticsSqlForCC() : this.GetGenericStatisticsSqlForCD();
//成品
//string sql = GetGenericStatisticsSqlForBORA();
//count = session.ExecuteSql(sql, parameters);
////注塑件
//sql = GetGenericStatisticsSqlForINJECT();
//count += session.ExecuteSql(sql, parameters);
this.UpdateLastGenericTime(endTime, session);
session.CommitTs();
}
catch (Exception)
{
session.RollbackTs();
throw;
}
}
return count;
}
public SystemConfig GetSystemConfig(string codeType)
{
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT *");
sql.AppendLine(" FROM T_SYSTEM_CONFIG");
sql.AppendLine(" WHERE CODETYPE = @CodeType");
DataParameter[] parameters = {
new DataParameter {ParameterName = "CodeType", DataType = DbType.String, Value = codeType}
};
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.Get<SystemConfig>(sql.ToString(), parameters);
}
}
public string GetMFGMaterialCode(string MaterialCode)
{
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT *");
sql.AppendLine(" FROM T_PP_TJFY_ExchangeType");
sql.AppendLine(" WHERE MaterialCode = @MaterialCode");
DataParameter[] parameters = {
new DataParameter {ParameterName = "MaterialCode", DataType = DbType.String, Value = MaterialCode}
};
using (IDataSession session = AppDataFactory.CreateMainSession())
{
var date = session.GetTable(sql.ToString(), parameters);
if (date.Rows.Count > 0)
{
return date.Rows[0]["MFGMaterialCode"].ToString();
}
else
return "";
}
}
protected int UpdateLastGenericTime(DateTime endTime, IDataSession session)
{
StringBuilder sql = new StringBuilder();
sql.AppendLine("UPDATE T_SYSTEM_CONFIG");
sql.AppendLine(" SET CODEVALUE = @EndTime");
sql.AppendLine(" WHERE CODETYPE = @CodeType");
DataParameter[] parameters =
{
new DataParameter {ParameterName = "EndTime", DataType = DbType.String, Value = endTime.ToString("yyyy/MM/dd HH:mm:ss")},
new DataParameter {ParameterName = "CodeType", DataType = DbType.String, Value = CompleteStatisticsConstants.COMP_STATIS_LSTTIME}
};
return session.ExecuteSql(sql.ToString(), parameters);
}
/// <summary>
/// 成都工厂适用SQL
/// </summary>
/// <returns></returns>
protected string GetGenericStatisticsSqlForCD()
{
StringBuilder sql = new StringBuilder();
sql.AppendLine("INSERT INTO T_AW_COMPLETE_TJSTATISTICS");
sql.AppendLine("SELECT NEWID(),");
sql.AppendLine(" REPLACE(T.CUSTOMERSPAREPARTS, ' ', '') AS MATERIALNO,");
sql.AppendLine(" COUNT(*) AS SYSCOMPLETECOUNT,");
sql.AppendLine(" COUNT(*) AS COMPLETECOUNT,");
sql.AppendLine(" @StartTime AS STARTTIME,");
sql.AppendLine(" @EndTime AS ENDTIME,");
sql.AppendLine(" CNFG.CODEVALUE + ");
sql.AppendLine(" REPLACE(CONVERT(VARCHAR(100), GETDATE(), 112) +");
sql.AppendLine(" CONVERT(VARCHAR(100), GETDATE(), 8),':','') + ");
sql.AppendLine(" REPLICATE('0', 2 - LEN(ROW_NUMBER() OVER (ORDER BY T.CUSTOMERSPAREPARTS))) + CAST (ROW_NUMBER() OVER (ORDER BY T.CUSTOMERSPAREPARTS) AS VARCHAR) AS ORDERNO,");
sql.AppendLine(" GETDATE() AS CREATETIME,");
sql.AppendLine(" USR.USERID AS CREATEUSER,");
sql.AppendLine(" GETDATE() AS UPDATETIME,");
sql.AppendLine(" USR.USERID AS UPDATEUSER,");
sql.AppendLine(" '0' AS DELFLAG");
sql.AppendLine(" FROM T_DAS_BARCODEVIBPAR T");
sql.AppendLine(" LEFT JOIN T_QM_USER USR");
sql.AppendLine(" ON USR.USERID = 'SYSTEM'");
sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG CNFG");
sql.AppendLine(" ON CNFG.CODETYPE = 'COMP_STATIS_ORDER'");
sql.AppendLine(" WHERE T.SCANTIME > @StartTime");
sql.AppendLine(" AND T.SCANTIME <= @EndTime");
sql.AppendLine(" AND SUBSTRING(T.ABARCODE, 9, 2) <> '99'");
sql.AppendLine(" GROUP BY T.CUSTOMERSPAREPARTS, USR.USERID, CNFG.CODEVALUE");
return sql.ToString();
}
//长春
protected string GetGenericStatisticsSqlForCC()
{
StringBuilder sql = new StringBuilder();
sql.AppendLine("INSERT INTO T_AW_COMPLETE_TJSTATISTICS");
sql.AppendLine("SELECT NEWID(),");
sql.AppendLine(" INFO.MATERIALNO AS MATERIALNO,");
sql.AppendLine(" COUNT(*) AS SYSCOMPLETECOUNT,");
sql.AppendLine(" COUNT(*) AS COMPLETECOUNT,");
sql.AppendLine(" @StartTime AS STARTTIME,");
sql.AppendLine(" @EndTime AS ENDTIME,");
sql.AppendLine(" CNFG.CODEVALUE + ");
sql.AppendLine(" REPLACE(CONVERT(VARCHAR(100), GETDATE(), 112) +");
sql.AppendLine(" CONVERT(VARCHAR(100), GETDATE(), 8),':','') + ");
sql.AppendLine(" REPLICATE('0', 2 - LEN(ROW_NUMBER() OVER (ORDER BY INFO.MATERIALNO))) + CAST (ROW_NUMBER() OVER (ORDER BY INFO.MATERIALNO) AS VARCHAR) AS ORDERNO,");
sql.AppendLine(" GETDATE() AS CREATETIME,");
sql.AppendLine(" USR.USERID AS CREATEUSER,");
sql.AppendLine(" GETDATE() AS UPDATETIME,");
sql.AppendLine(" USR.USERID AS UPDATEUSER,");
sql.AppendLine(" '0' AS DELFLAG");
sql.AppendLine(" FROM T_AW_MAINOPERATION T");
sql.AppendLine(" LEFT JOIN T_BD_BARCODE_PRODUCT_RELATION RELATION");
sql.AppendLine(" ON T.PRODUCTTYPE = RELATION.PRODUCTTYPE");
sql.AppendLine(" AND T.PROCESSTYPE = RELATION.PROCESSTYPE");
sql.AppendLine(" LEFT JOIN T_BD_MATERIAL_BARCODE_INFO INFO");
sql.AppendLine(" ON INFO.PROCESSTYPE = RELATION.PROCESSTYPE");
sql.AppendLine(" AND INFO.PRODUCTTYPE = RELATION.PRODUCTTYPE");
sql.AppendLine(" AND SUBSTRING(T.PRODUCTCODE, RELATION.STARTINDEX, RELATION.SUBLENGTH) = INFO.BARCODEIDENTIFY");
sql.AppendLine(" LEFT JOIN T_QM_USER USR");
sql.AppendLine(" ON USR.USERNAME = 'SYSTEM'");
sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG CNFG");
sql.AppendLine(" ON CNFG.CODETYPE = 'COMP_STATIS_ORDER'");
sql.AppendLine(" WHERE INFO.BARCODEIDENTIFY IS NOT NULL");
sql.AppendLine(" AND T.OPERATEDDATE > @StartTime");
sql.AppendLine(" AND T.OPERATEDDATE <= @EndTime");
sql.AppendLine(" GROUP BY INFO.MATERIALNO, USR.USERID, CNFG.CODEVALUE");
return sql.ToString();
}
//青岛仪表板/门板的成品
//protected string GetGenericStatisticsSqlForBORA()
//{
// StringBuilder sql = new StringBuilder();
// sql.AppendLine(" INSERT INTO T_AW_COMPLETE_TJSTATISTICS ");
// sql.AppendLine(" SELECT NEWID(), ");
// sql.AppendLine(" T.MATERIAL_CODE AS MATERIALNO, ");
// sql.AppendLine(" COUNT(*) AS SYSCOMPLETECOUNT, ");
// sql.AppendLine(" COUNT(*) AS COMPLETECOUNT, ");
// sql.AppendLine(" @StartTime AS STARTTIME, ");
// sql.AppendLine(" @EndTime AS ENDTIME, ");
// sql.AppendLine(" CNFG.CODEVALUE + ");
// sql.AppendLine(" REPLACE(CONVERT(VARCHAR(100), GETDATE(), 112) + ");
// sql.AppendLine(" CONVERT(VARCHAR(100), GETDATE(), 8),':','') + ");
// sql.AppendLine(" REPLICATE('0', 2 - LEN(ROW_NUMBER() OVER (ORDER BY T.MATERIAL_CODE))) + CAST (ROW_NUMBER() OVER (ORDER BY T.MATERIAL_CODE) AS VARCHAR) AS ORDERNO, ");
// sql.AppendLine(" GETDATE() AS CREATETIME, ");
// sql.AppendLine(" USR.USERID AS CREATEUSER, ");
// sql.AppendLine(" GETDATE() AS UPDATETIME, ");
// sql.AppendLine(" USR.USERID AS UPDATEUSER, ");
// sql.AppendLine(" '0' AS DELFLAG ");
// sql.AppendLine(" FROM T_AW_MAINOPERATION T ");
// sql.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS C ON C.MATERIAL_TYPE_CODE=T.MATERIAL_TYPE_CODE ");
// sql.AppendLine(" LEFT JOIN T_QM_USER USR ");
// sql.AppendLine(" ON USR.USERNAME = 'SYSTEM' ");
// sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG CNFG ");
// sql.AppendLine(" ON CNFG.CODETYPE = 'COMP_STATIS_ORDER' ");
// sql.AppendLine(" WHERE T.OPERATEDDATE > @StartTime ");
// sql.AppendLine(" AND T.OPERATEDDATE <= @EndTime ");
// sql.AppendLine(" AND C.MATERIAL_ATTRIBUTE='2' ");
// sql.AppendLine(" GROUP BY T.MATERIAL_CODE, USR.USERID, CNFG.CODEVALUE ");
// return sql.ToString();
//}
//青岛注塑件
protected string GetGenericStatisticsSqlForBORA()
{
StringBuilder sql = new StringBuilder();
sql.AppendLine(" INSERT INTO T_AW_COMPLETE_TJSTATISTICS ");
sql.AppendLine(" SELECT NEWID(),");
sql.AppendLine(" C.MFG_MATERIAL_CODE AS MATERIALNO,");
sql.AppendLine(" COUNT(*) AS SYSCOMPLETECOUNT,");
sql.AppendLine(" COUNT(*) AS COMPLETECOUNT,");
sql.AppendLine(" @StartTime AS STARTTIME,");
sql.AppendLine(" @EndTime AS ENDTIME,");
sql.AppendLine(" C.ORDERIDENTITY + ");
sql.AppendLine(" REPLACE(substring(CONVERT(VARCHAR(100), GETDATE(), 112),3,6) + ");
sql.AppendLine(" CONVERT(VARCHAR(100), GETDATE(), 8),':','') + ");
sql.AppendLine(" REPLICATE('0', 2 - LEN(ROW_NUMBER() OVER (ORDER BY C.MFG_MATERIAL_CODE))) + CAST (ROW_NUMBER() OVER (ORDER BY C.MFG_MATERIAL_CODE) AS VARCHAR) AS ORDERNO, ");
sql.AppendLine(" GETDATE() AS CREATETIME, ");
sql.AppendLine(" USR.USERID AS CREATEUSER, ");
sql.AppendLine(" GETDATE() AS UPDATETIME, ");
sql.AppendLine(" USR.USERID AS UPDATEUSER, ");
sql.AppendLine(" '0' AS DELFLAG ");
sql.AppendLine(" FROM T_AW_PRODUCT T ");
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS S ON S.MATERIAL_TYPE_CODE=T.MATERIAL_TYPE ");
sql.AppendLine(" LEFT JOIN T_AW_COMPLETE_MFG_CONFIG C ON C.MES_MATERIAL_CODE = T.MATERIAL_CODE ");
sql.AppendLine(" LEFT JOIN T_QM_USER USR ");
sql.AppendLine(" ON USR.USERNAME = 'SYSTEM' ");
sql.AppendLine(" WHERE S.MATERIAL_ATTRIBUTE='2' ");
sql.AppendLine(" AND C.MFG_MATERIAL_CODE IS NOT NULL ");
sql.AppendLine(" AND T.CREATEDATE > @StartTime ");
sql.AppendLine(" AND T.CREATEDATE <= @EndTime ");
sql.AppendLine(" AND T.MACHINECODDE IS NOT NULL ");
sql.AppendLine(" GROUP BY C.MFG_MATERIAL_CODE, USR.USERID, C.ORDERIDENTITY ");
return sql.ToString();
}
//天津770发运 MFG回冲
protected string GetFrmPlaceStatisticsSql()
{
StringBuilder sql = new StringBuilder();
sql.AppendLine(" INSERT INTO T_AW_COMPLETE_TJSTATISTICS ");
sql.AppendLine(" SELECT NEWID(),");
sql.AppendLine(" C.MFG_MATERIAL_CODE AS MATERIALNO,");
sql.AppendLine(" COUNT(*) AS SYSCOMPLETECOUNT,");
sql.AppendLine(" COUNT(*) AS COMPLETECOUNT,");
sql.AppendLine(" @StartTime AS STARTTIME,");
sql.AppendLine(" @EndTime AS ENDTIME,");
sql.AppendLine(" C.ORDERIDENTITY + ");
sql.AppendLine(" REPLACE(substring(CONVERT(VARCHAR(100), GETDATE(), 112),3,6) + ");
sql.AppendLine(" CONVERT(VARCHAR(100), GETDATE(), 8),':','') + ");
sql.AppendLine(" REPLICATE('0', 2 - LEN(ROW_NUMBER() OVER (ORDER BY C.MFG_MATERIAL_CODE))) + CAST (ROW_NUMBER() OVER (ORDER BY C.MFG_MATERIAL_CODE) AS VARCHAR) AS ORDERNO, ");
sql.AppendLine(" GETDATE() AS CREATETIME, ");
sql.AppendLine(" USR.USERID AS CREATEUSER, ");
sql.AppendLine(" GETDATE() AS UPDATETIME, ");
sql.AppendLine(" USR.USERID AS UPDATEUSER, ");
sql.AppendLine(" '0' AS DELFLAG ");
sql.AppendLine(" FROM T_AW_PRODUCT T ");
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS S ON S.MATERIAL_TYPE_CODE=T.MATERIAL_TYPE ");
sql.AppendLine(" LEFT JOIN T_AW_COMPLETE_MFG_CONFIG C ON C.MES_MATERIAL_CODE = T.MATERIAL_CODE ");
sql.AppendLine(" LEFT JOIN T_QM_USER USR ");
sql.AppendLine(" ON USR.USERNAME = 'SYSTEM' ");
sql.AppendLine(" WHERE S.MATERIAL_ATTRIBUTE='2' ");
sql.AppendLine(" AND C.MFG_MATERIAL_CODE IS NOT NULL ");
sql.AppendLine(" AND T.CREATEDATE > @StartTime ");
sql.AppendLine(" AND T.CREATEDATE <= @EndTime ");
sql.AppendLine(" AND T.MACHINECODDE IS NOT NULL ");
sql.AppendLine(" GROUP BY C.MFG_MATERIAL_CODE, USR.USERID, C.ORDERIDENTITY ");
return sql.ToString();
}
protected string GetGenericStatisticsSqlForINJECT()
{
StringBuilder sql = new StringBuilder();
sql.AppendLine(" INSERT INTO T_AW_COMPLETE_TJSTATISTICS ");
sql.AppendLine(" SELECT NEWID(), ");
sql.AppendLine(" C.MFG_MATERIAL_CODE AS MATERIALNO, ");
sql.AppendLine(" COUNT(*) AS SYSCOMPLETECOUNT, ");
sql.AppendLine(" COUNT(*) AS COMPLETECOUNT, ");
sql.AppendLine(" @StartTime AS STARTTIME, ");
sql.AppendLine(" @EndTime AS ENDTIME, ");
sql.AppendLine(" C.ORDERIDENTITY + ");
sql.AppendLine(" REPLACE(substring(CONVERT(VARCHAR(100), GETDATE(), 112),3,6) + ");
sql.AppendLine(" CONVERT(VARCHAR(100), GETDATE(), 8),':','') + ");
sql.AppendLine(" REPLICATE('0', 2 - LEN(ROW_NUMBER() OVER (ORDER BY C.MFG_MATERIAL_CODE))) + ");
sql.AppendLine(" CAST (ROW_NUMBER() OVER (ORDER BY C.MFG_MATERIAL_CODE) AS VARCHAR) AS ORDERNO, ");
sql.AppendLine(" GETDATE() AS CREATETIME, ");
sql.AppendLine(" USR.USERID AS CREATEUSER, ");
sql.AppendLine(" GETDATE() AS UPDATETIME, ");
sql.AppendLine(" USR.USERID AS UPDATEUSER, ");
sql.AppendLine(" '0' AS DELFLAG ");
sql.AppendLine(" FROM T_TM_MonitorCode T ");
sql.AppendLine(" LEFT JOIN T_AW_COMPLETE_MFG_CONFIG C ");
sql.AppendLine(" ON C.MES_MATERIAL_CODE = T.MATERIAL_CODE ");
sql.AppendLine(" LEFT JOIN T_QM_USER USR ");
sql.AppendLine(" ON USR.USERNAME = 'SYSTEM' ");
sql.AppendLine(" WHERE T.CurrentMode='3' ");
sql.AppendLine(" AND C.MFG_MATERIAL_CODE IS NOT NULL ");
sql.AppendLine(" AND T.CREATEDATE > @StartTime ");
sql.AppendLine(" AND T.CREATEDATE <= @EndTime ");
sql.AppendLine(" GROUP BY C.MFG_MATERIAL_CODE, USR.USERID, C.ORDERIDENTITY ");
return sql.ToString();
}
protected string GetQuerySql(TJCompleteStatisticsEntity condition, out DataParameter[] parameters)
{
List<DataParameter> parametersList = new List<DataParameter>();
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT T.PID, ");
sql.AppendLine(" T.MATERIALNO, ");
sql.AppendLine(" MAT.MATERIALNAME, ");
sql.AppendLine(" MAT.PRODUCTLINE, ");
sql.AppendLine(" T.SYSCOMPLETECOUNT,");
sql.AppendLine(" T.COMPLETECOUNT,");
sql.AppendLine(" T.STARTTIME, ");
sql.AppendLine(" T.ENDTIME, ");
sql.AppendLine(" T.ORDERNO, ");
sql.AppendLine(" T.CREATETIME,");
sql.AppendLine(" T.CREATEUSER,");
sql.AppendLine(" T.UPDATETIME,");
sql.AppendLine(" T.UPDATEUSER,");
sql.AppendLine(" T.DELFLAG,");
sql.AppendLine(" CUSER.USERNAME AS CREATEUSER_DISPLAY,");
sql.AppendLine(" UUSER.USERNAME AS UPDATEUSER_DISPLAY");
sql.AppendLine(" FROM T_AW_COMPLETE_TJSTATISTICS T");
sql.AppendLine(" LEFT JOIN T_QM_USER CUSER");
sql.AppendLine(" ON T.CREATEUSER = CUSER.USERID");
sql.AppendLine(" LEFT JOIN T_QM_USER UUSER");
sql.AppendLine(" ON T.UPDATEUSER = UUSER.USERID");
sql.AppendLine(" INNER JOIN T_BD_MATERIAL_BARCODE_INFO MAT");
sql.AppendLine(" ON T.MATERIALNO = MAT.MATERIALNO");
sql.AppendLine(" WHERE 1 = 1");
if (!string.IsNullOrWhiteSpace(condition.MATERIALNO))
{
sql.AppendLine(" AND T.MATERIALNO LIKE @MaterialNo");
parametersList.Add(new DataParameter { ParameterName = "MaterialNo", DataType = DbType.String, Value = string.Format("%{0}%", condition.MATERIALNO) });
}
if (!string.IsNullOrWhiteSpace(condition.DELFLAG))
{
if(condition.DELFLAG == "是")
sql.AppendLine(" AND T.DELFLAG = '1'");
else if(condition.DELFLAG == "否")
sql.AppendLine(" AND T.DELFLAG = '0'");
}
if (!string.IsNullOrWhiteSpace(condition.SENDTIME))
{
sql.AppendLine(" AND T.ENDTIME >= @SEndTime");
parametersList.Add(new DataParameter { ParameterName = "SEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.SENDTIME) });
}
if (!string.IsNullOrWhiteSpace(condition.EENDTIME))
{
sql.AppendLine(" AND T.ENDTIME <= @EEndTime");
parametersList.Add(new DataParameter { ParameterName = "EEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.EENDTIME) });
}
parameters = parametersList.ToArray();
return sql.ToString();
}
public List<TJCompleteStatisticsEntity> GetExportData(TJCompleteStatisticsEntity model, IDataSession session)
{
DataParameter[] parameters;
string sql = this.GetExportSql(model, out parameters);
DataParameter[] unableParameters;
//数据上传状态回填
string unableSql = this.unableExportDataString(model, out unableParameters);
List<TJCompleteStatisticsEntity> rtn = session.GetList<TJCompleteStatisticsEntity>(sql, parameters).ToList();
//var count = session.ExecuteSql(unableSql, unableParameters);
using (IDataSession session2 = AppDataFactory.CreateMainSession())
{
var count = session2.ExecuteSql(unableSql, unableParameters);
}
return rtn;
}
private string unableExportDataString(TJCompleteStatisticsEntity condition, out DataParameter[] parameters)
{
List<DataParameter> parametersList = new List<DataParameter>();
StringBuilder sql = new StringBuilder();
sql.AppendLine("UPDATE [dbo].[T_AW_COMPLETE_TJSTATISTICS] ");
sql.AppendLine(" SET DELFLAG = '1'");
sql.AppendLine(" WHERE DELFLAG = '0'");
if (!string.IsNullOrWhiteSpace(condition.MATERIALNO))
{
sql.AppendLine(" AND MATERIALNO LIKE @MaterialNo");
parametersList.Add(new DataParameter { ParameterName = "MaterialNo", DataType = DbType.String, Value = string.Format("%{0}%", condition.MATERIALNO) });
}
//20211214重传后DELFLAG状态修改
//if (!string.IsNullOrWhiteSpace(condition.SENDTIME))
//{
// sql.AppendLine(" AND ENDTIME >= @SEndTime");
// parametersList.Add(new DataParameter { ParameterName = "SEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.SENDTIME) });
//}
if (!string.IsNullOrWhiteSpace(condition.EENDTIME))
{
sql.AppendLine(" AND ENDTIME <= @EEndTime");
parametersList.Add(new DataParameter { ParameterName = "EEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.EENDTIME) });
}
parameters = parametersList.ToArray();
return sql.ToString();
}
//protected string GetExportSql(TJCompleteStatisticsEntity condition, out DataParameter[] parameters)
//{
// List<DataParameter> parametersList = new List<DataParameter>();
// StringBuilder sql = new StringBuilder();
// sql.AppendLine("SELECT EM.CODEVALUE AS EMPLOYEE, ");
// sql.AppendLine(" SI.CODEVALUE AS SITE, ");
// sql.AppendLine(" '' AS SHIFT, ");
// sql.AppendLine(" T.MATERIALNO, ");
// sql.AppendLine(" MAT.PRODUCTLINE, ");
// sql.AppendLine(" '' AS EDIMAT, ");
// sql.AppendLine(" '' AS SERIAL, ");
// sql.AppendLine(" USR.CODEVALUE AS USERID, ");
// sql.AppendLine(" T.ORDERNO, ");
// sql.AppendLine(" T.COMPLETECOUNT,");
// sql.AppendLine(" T.STARTTIME");
// sql.AppendLine(" FROM T_AW_COMPLETE_TJSTATISTICS T");
// sql.AppendLine(" INNER JOIN T_BD_MATERIAL_BARCODE_INFO MAT");
// sql.AppendLine(" ON T.MATERIALNO = MAT.MATERIALNO");
// sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG EM");
// sql.AppendLine(" ON EM.CODETYPE = @Employee");
// parametersList.Add(new DataParameter { ParameterName = "Employee", DataType = DbType.String, Value = CompleteStatisticsConstants.COMP_STATIS_EMPLOYEE });
// sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG SI");
// sql.AppendLine(" ON SI.CODETYPE = @Site");
// parametersList.Add(new DataParameter { ParameterName = "Site", DataType = DbType.String, Value = CompleteStatisticsConstants.COMP_STATIS_SITE });
// sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG USR");
// sql.AppendLine(" ON USR.CODETYPE = @UserId");
// parametersList.Add(new DataParameter { ParameterName = "UserId", DataType = DbType.String, Value = CompleteStatisticsConstants.COMP_STATIS_USER });
// sql.AppendLine(" LEFT JOIN T_SYSTEM_CONFIG ORD");
// sql.AppendLine(" ON ORD.CODETYPE = @OrderNo");
// parametersList.Add(new DataParameter { ParameterName = "OrderNo", DataType = DbType.String, Value = CompleteStatisticsConstants.COMP_STATIS_ORDER });
// sql.AppendLine(" WHERE T.DELFLAG = '0'");
// if (!string.IsNullOrWhiteSpace(condition.MATERIALNO))
// {
// sql.AppendLine(" AND T.MATERIALNO LIKE @MaterialNo");
// parametersList.Add(new DataParameter { ParameterName = "MaterialNo", DataType = DbType.String, Value = string.Format("%{0}%", condition.MATERIALNO) });
// }
// if (!string.IsNullOrWhiteSpace(condition.SENDTIME))
// {
// sql.AppendLine(" AND T.ENDTIME >= @SEndTime");
// parametersList.Add(new DataParameter { ParameterName = "SEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.SENDTIME) });
// }
// if (!string.IsNullOrWhiteSpace(condition.EENDTIME))
// {
// sql.AppendLine(" AND T.ENDTIME <= @EEndTime");
// parametersList.Add(new DataParameter { ParameterName = "EEndTime", DataType = DbType.DateTime, Value = string.Format("{0}", condition.EENDTIME) });
// }
// sql.AppendLine(" ORDER BY T.ORDERNO ASC");
// parameters = parametersList.ToArray();
// return sql.ToString();
//}
protected string GetExportSql(TJCompleteStatisticsEntity condition, out DataParameter[] parameters)
{
List<DataParameter> parametersList = new List<DataParameter>();
StringBuilder sql = new StringBuilder();
sql.AppendLine("SELECT (select top 1 MFG_USERCODE from T_AW_COMPLETE_MFG_CONFIG where MFG_MATERIAL_CODE = T.MATERIALNO) AS EMPLOYEE, ");
sql.AppendLine(" (select top 1 MFG_LOCATIONCODE from T_AW_COMPLETE_MFG_CONFIG where MFG_MATERIAL_CODE = T.MATERIALNO) AS SITE, ");
sql.AppendLine(" '' AS SHIFT, ");
sql.AppendLine(" T.MATERIALNO, ");
sql.AppendLine(" (select top 1 PRODUCELINECODE from T_AW_COMPLETE_MFG_CONFIG where MFG_MATERIAL_CODE = T.MATERIALNO) AS PRODUCTLINE, ");
sql.AppendLine(" '' AS EDIMAT, ");
sql.AppendLine(" '' AS SERIAL, ");
sql.AppendLine(" (select top 1 USERID from T_AW_COMPLETE_MFG_CONFIG where MFG_MATERIAL_CODE = T.MATERIALNO), ");
sql.AppendLine(" T.ORDERNO, ");
sql.AppendLine(" T.COMPLETECOUNT,");
sql.AppendLine(" T.STARTTIME,");
sql.AppendLine(" T.ENDTIME");
sql.AppendLine(" FROM T_AW_COMPLETE_TJSTATISTICS T");
sql.AppendLine(" WHERE T.DELFLAG = '0'");
if (!string.IsNullOrWhiteSpace(condition.MATERIALNO))
{
sql.AppendLine(" AND T.MATERIALNO LIKE @MaterialNo");
parametersList.Add(new DataParameter { ParameterName = "MaterialNo", DataType = DbType.String, Value = string.Format("%{0}%", condition.MATERIALNO) });
}
//20211214如网络中断,重连后数据重传
//if (!string.IsNullOrWhiteSpace(condition.SENDTIME))
//{
// sql.AppendLine(" AND T.ENDTIME >= @SEndTime");
// parametersList.Add(new DataParameter { ParameterName = "SEndTime", DataType = DbType.DateTime, Value = Convert.ToDateTime(condition.SENDTIME) });
//}
if (!string.IsNullOrWhiteSpace(condition.EENDTIME))
{
sql.AppendLine(" AND T.ENDTIME <= @EEndTime");
parametersList.Add(new DataParameter { ParameterName = "EEndTime", DataType = DbType.DateTime, Value = string.Format("{0}", condition.EENDTIME) });
}
sql.AppendLine(" ORDER BY T.ORDERNO ASC");
parameters = parametersList.ToArray();
return sql.ToString();
}
public DataTable ExportExcelData(TJCompleteStatisticsEntity model)
{
DataParameter[] parameters;
string sql = this.GetQuerySql(model, out parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetTable(sql, parameters);
}
}
}
}