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.
508 lines
30 KiB
508 lines
30 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 CompleteStatisticsDAL : BaseDAL
|
|
{
|
|
public DataPage GetList(CompleteStatisticsEntity 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<CompleteStatisticsEntity>(sql, parameters, page);
|
|
}
|
|
return page;
|
|
|
|
}
|
|
|
|
public List<CompleteStatisticsEntity> GetList(CompleteStatisticsEntity condition)
|
|
{
|
|
DataParameter[] parameters;
|
|
string sql = this.GetQuerySql(condition, out parameters);
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetList<CompleteStatisticsEntity>(sql, parameters).ToList();
|
|
}
|
|
}
|
|
|
|
public CompleteStatisticsEntity Get(CompleteStatisticsEntity model)
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession()) {
|
|
return session.Get(model);
|
|
}
|
|
}
|
|
|
|
public int Insert(CompleteStatisticsEntity model)
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession()) {
|
|
return session.Insert(model);
|
|
}
|
|
}
|
|
|
|
public bool ExistCompleteStatistics(CompleteStatisticsEntity 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(CompleteStatisticsEntity model)
|
|
{
|
|
using (IDataSession session = AppDataFactory.CreateMainSession()) {
|
|
return session.Update(model);
|
|
}
|
|
}
|
|
|
|
public int GenericCompleteStatistics(DateTime starTime, DateTime endTime)
|
|
{
|
|
int count;
|
|
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);
|
|
}
|
|
}
|
|
|
|
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_STATISTICS");
|
|
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_STATISTICS");
|
|
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_STATISTICS ");
|
|
// 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_STATISTICS ");
|
|
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_STATISTICS ");
|
|
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(CompleteStatisticsEntity 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_STATISTICS 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<CompleteStatisticsEntity> GetExportData(CompleteStatisticsEntity model, IDataSession session)
|
|
{
|
|
DataParameter[] parameters;
|
|
string sql = this.GetExportSql(model, out parameters);
|
|
DataParameter[] unableParameters;
|
|
//数据上传状态回填
|
|
string unableSql = this.unableExportDataString(model, out unableParameters);
|
|
|
|
List<CompleteStatisticsEntity> rtn = session.GetList<CompleteStatisticsEntity>(sql, parameters).ToList();
|
|
session.ExecuteSql(unableSql, unableParameters);
|
|
return rtn;
|
|
}
|
|
|
|
private string unableExportDataString(CompleteStatisticsEntity condition, out DataParameter[] parameters)
|
|
{
|
|
List<DataParameter> parametersList = new List<DataParameter>();
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.AppendLine("UPDATE T_AW_COMPLETE_STATISTICS");
|
|
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(CompleteStatisticsEntity 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_STATISTICS 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(CompleteStatisticsEntity condition, out DataParameter[] parameters)
|
|
{
|
|
List<DataParameter> parametersList = new List<DataParameter>();
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.AppendLine("SELECT C.MFG_USERCODE AS EMPLOYEE, ");
|
|
sql.AppendLine(" C.MFG_LOCATIONCODE AS SITE, ");
|
|
sql.AppendLine(" '' AS SHIFT, ");
|
|
sql.AppendLine(" T.MATERIALNO, ");
|
|
sql.AppendLine(" C.PRODUCELINECODE AS PRODUCTLINE, ");
|
|
sql.AppendLine(" '' AS EDIMAT, ");
|
|
sql.AppendLine(" '' AS SERIAL, ");
|
|
sql.AppendLine(" C.USERID, ");
|
|
sql.AppendLine(" T.ORDERNO, ");
|
|
sql.AppendLine(" T.COMPLETECOUNT,");
|
|
sql.AppendLine(" T.STARTTIME,");
|
|
sql.AppendLine(" T.ENDTIME");
|
|
sql.AppendLine(" FROM T_AW_COMPLETE_STATISTICS T");
|
|
sql.AppendLine(" LEFT JOIN T_AW_COMPLETE_MFG_CONFIG C");
|
|
sql.AppendLine(" ON T.MATERIALNO = C.MFG_MATERIAL_CODE");
|
|
|
|
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(CompleteStatisticsEntity model)
|
|
{
|
|
DataParameter[] parameters;
|
|
string sql = this.GetQuerySql(model, out parameters);
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetTable(sql, parameters);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|