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

504 lines
19 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.MD.Entity;
using QMFrameWork.Data;
using QMFrameWork.Log;
using System.Data;
using QMAPP.DAL;
namespace QMAPP.MD.DAL
{
/// <summary>
/// 作 用:班组成员
/// 作 者:周晓东
/// 编写日期:2017年11月21日
/// </summary>
public class ScheduleDAL : BaseDAL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>*信息</returns>
public ScheduleEntity Get(ScheduleEntity model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//获取信息
model = session.Get<ScheduleEntity>(model);
}
return model;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "数据层 - 获取信息");
throw ex;
}
}
public ScheduleEntity GetEntity(ScheduleEntity model)
{
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
var sql = "SELECT S.*,T.TEAM_NAME,SH.PRODUCESHIFTNAME AS SHIFT_NAME FROM T_QT_SCHEDULE S ";
sql += "LEFT JOIN T_QT_TEAM T ON T.TEAM_CODE=S.TEAM_CODE AND T.FACTORY_CODE=S.FACTORY_CODE ";
sql += "LEFT JOIN T_BD_PRODUCESHIFT SH ON SH.PRODUCESHIFTTCODE=S.SHIFT_CODE ";
sql += "WHERE S.PID='" + model .PID+ "'";
//获取信息
model = session.Get<ScheduleEntity>(sql, new List<DataParameter>().ToArray());
}
return model;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "数据层 - 获取信息");
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(ScheduleEntity condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
#region 排序
//分页关键字段及排序
page.KeyName = "PID";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "FACTORY_CODE DESC";
}
#endregion
using (IDataSession session = AppDataFactory.CreateMainSession())
{
// 对应多种数据库
//string sqlChange = this.ChangeSqlByDB(sql, session);
page = session.GetDataPage<ScheduleEntity>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班组信息数据层 - 获取列表");
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(ScheduleEntity condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
// sqlBuilder.AppendLine(@" SELECT T.PID
// ,T.FACTORY_CODE
// ,F.FACTORY_NAME
// ,T.DEPT_CODE
// ,T.TEAM_CODE
// ,T.TEAM_NAME
// ,T.TEAM_LEADER
// ,T.REMARK
// ,T.CREATEUSER
// ,T.CREATEDATE
// ,T.UPDATEUSER
// ,T.UPDATEDATE
// ,T.FLGDEL
// FROM T_QT_TEAM T
// LEFT JOIN T_MD_FACTORY F
// ON T.FACTORY_CODE = F.FACTORY_CODE
// ");
sqlBuilder.AppendLine(@" SELECT S.* FROM T_QT_SCHEDULE S ");
sqlBuilder.AppendLine(@" LEFT JOIN T_QT_TEAM T ");
sqlBuilder.AppendLine(@" ON T.TEAM_CODE = S.TEAM_CODE ");
//查询条件
//whereBuilder.Append(" AND T.FLGDEL = '0'");
//工厂
if (string.IsNullOrEmpty(condition.FACTORY_CODE) == false)
{
whereBuilder.Append(" AND S.FACTORY_CODE = @FACTORY_CODE");
parameters.Add(new DataParameter { ParameterName = "FACTORY_CODE", DataType = DbType.String, Value = condition.FACTORY_CODE });
}
//班组
if (string.IsNullOrEmpty(condition.TEAM_CODE) == false)
{
whereBuilder.Append(" AND S.TEAM_CODE = @TEAM_CODE");
parameters.Add(new DataParameter { ParameterName = "TEAM_CODE", DataType = DbType.String, Value = condition.TEAM_CODE });
}
//班组类型
if (string.IsNullOrEmpty(condition.TEAM_TYPE) == false)
{
whereBuilder.Append(" AND T.DEPT_CODE = @TEAM_TYPE");
parameters.Add(new DataParameter { ParameterName = "TEAM_TYPE", DataType = DbType.String, Value = condition.TEAM_TYPE });
}
//班次
if (string.IsNullOrEmpty(condition.SHIFT_CODE) == false)
{
whereBuilder.Append(" AND S.SHIFT_CODE = @SHIFT_CODE");
parameters.Add(new DataParameter { ParameterName = "SHIFT_CODE", DataType = DbType.String, Value = condition.SHIFT_CODE });
}
//当前日期
if (condition.NOW_DATE!=DateTime.MinValue)
{
whereBuilder.Append(" AND (S.START_DATE <@NOW_DATE AND S.END_DATE >@NOW_DATE)");
parameters.Add(new DataParameter { ParameterName = "NOW_DATE", DataType = DbType.DateTime, Value = condition.NOW_DATE });
}
//结束
//if (condition.END_DATE != DateTime.MinValue)
//{
// whereBuilder.Append(" AND END_DATE <@END_DATE");
// parameters.Add(new DataParameter { ParameterName = "END_DATE", DataType = DbType.DateTime, Value = condition.END_DATE });
//}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
/// <summary>
/// 获取全部用户
/// </summary>
/// <param name="condition">获取条件</param>
/// <returns>用户信息列表</returns>
public List<ScheduleEntity> GetAllSchedule(ScheduleEntity condition)
{
string sql = null;
List<ScheduleEntity> list = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = GetQuerySql(condition, ref parameters);
list = session.GetList<ScheduleEntity>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw;
}
}
#region 判断班组是否存在
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;false:不存在。</returns>
//public bool ExistsTeam(ScheduleEntity model)
//{
// string PID = "";
// int count = 0;
// string sql = null;
// try
// {
// if (string.IsNullOrEmpty(model.PID) == false)
// {
// PID = model.PID;
// }
// sql = "SELECT COUNT(*) FROM T_QT_TEAM WHERE PID <> @PID AND TEAM_CODE=@TEAM_CODE ";
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// // 对应多种数据库
// string sqlChange = this.ChangeSqlByDB(sql, session);
// count = Convert.ToInt32(session.ExecuteSqlScalar(sqlChange, new DataParameter("PID", PID),
// new DataParameter { ParameterName = "TEAM_CODE", Value = model.TEAM_CODE }));
// }
// if (count > 0)
// {
// return true;
// }
// else
// {
// return false;
// }
// }
// catch (Exception ex)
// {
// RecordExceptionLog(ex, "班组信息数据层-判断班组是否存在");
// throw ex;
// }
//}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name=model"">班组信息</param>
/// <returns>插入行数</returns>
public int Insert(ScheduleEntity model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//插入基本信息
count = session.Insert<ScheduleEntity>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "数据层-插入信息");
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name="model">信息</param>
/// <returns>更新行数</returns>
public int Update(ScheduleEntity model)
{
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//更新基本信息
count = session.Update<ScheduleEntity>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "数据层 - 更新信息");
throw ex;
}
}
#endregion
#region 删除信息
/// <summary>
/// 删除信息
/// </summary>
/// <param name="model">班信息(ID)</param>
/// <returns>删除个数</returns>
public int Delete(ScheduleEntity model)
{
StringBuilder sqlBuilder = new StringBuilder();
List<DataParameter> parameters = new List<DataParameter>();
int count = 0;
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//删除基本信息
count = session.Delete<ScheduleEntity>(model);
}
return count;
}
catch (Exception ex)
{
RecordExceptionLog(ex, "班组信息数据层 - 删除信息");
throw ex;
}
}
#endregion
// #region 班组是否使用
// /// <summary>
// /// 班组是否使用
// /// </summary>
// /// <param name="info"></param>
// /// <returns>true:已使用;fasel:未使用。</returns>
// public bool IsUsing(ScheduleEntity model)
// {
// int count = 0;
// StringBuilder sqlBuilder = new StringBuilder();
// try
// {
// sqlBuilder.AppendLine(" SELECT COUNT(*) FROM T_QT_TEAM_MEMBER T WHERE T.TEAM_PID=@TEAMID ");
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// count = Convert.ToInt32(session.ExecuteSqlScalar(sqlBuilder.ToString(),
// new DataParameter { ParameterName = "TEAMID", Value = model.PID }));
// }
// if (count > 0)
// {
// return true;
// }
// else
// {
// return false;
// }
// }
// catch (Exception ex)
// {
// throw ex;
// }
// }
// #endregion
// #region 获取班组人员列表
// /// <summary>
// /// 获取班组人员列表
// /// </summary>
// /// <param name="condition">条件</param>
// /// <param name="page">数据页</param>
// /// <returns>数据页</returns>
// public DataPage GetTeamWorkerList(TeamMember condition, DataPage page)
// {
// string sql = null;
// List<DataParameter> parameters = new List<DataParameter>();
// try
// {
// sql = this.GetTeamWorkerQuerySql(condition, ref parameters);
// #region 排序
// //分页关键字段及排序
// page.KeyName = "PID";
// if (string.IsNullOrEmpty(page.SortExpression))
// {
// page.SortExpression = "UPDATEDATE DESC";
// }
// #endregion
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// page = session.GetDataPage<TeamMember>(sql, parameters.ToArray(), page);
// }
// return page;
// }
// catch (Exception ex)
// {
// throw ex;
// }
// }
// /// <summary>
// /// 获取列表
// /// </summary>
// /// <param name="condition">条件</param>
// /// <returns>全部集合</returns>
// public List<TeamMember> GetTeamWorker(TeamMember condition)
// {
// List<TeamMember> list = new List<TeamMember>();
// string sql = null;
// List<DataParameter> parameters = new List<DataParameter>();
// try
// {
// sql = this.GetTeamWorkerQuerySql(condition, ref parameters);
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// list = session.GetList<TeamMember>(sql, parameters.ToArray()).ToList();
// }
// return list;
// }
// catch (Exception ex)
// {
// LogManager.LogHelper.Error(new LogInfo()
// {
// ErrorInfo = ex,
// Tag = ex.StackTrace,
// Info = "班组信息数据层-获取班组人员列表"
// });
// throw;
// }
// }
// #endregion
// #region 获取班组成员查询语句
// /// <summary>
// /// 获取班组成员查询语句
// /// </summary>
// /// <param name="user">查询条件</param>
// /// <param name="parameters">参数</param>
// /// <returns>查询语句</returns>
// private string GetTeamWorkerQuerySql(TeamMember condition, ref List<DataParameter> parameters)
// {
// StringBuilder sqlBuilder = new StringBuilder();
// StringBuilder whereBuilder = new StringBuilder();
// try
// {
// sqlBuilder.AppendLine(@" SELECT T.PID
// ,T.MEMBER_CODE
// ,T.MEMBER_NAME
// ,T.WORK_STATION
// ,T.TEAM_PID
// ,T.CREATEUSR
// ,T.CREATEDATE
// ,T.UPDATEDATE
// ,T.FLAGDEL
// FROM T_QT_TEAM_MEMBER T ");
// //查询条件
// //班组主键
// if (string.IsNullOrEmpty(condition.TEAM_PID) == false)
// {
// whereBuilder.Append(" AND T.TEAM_PID = @TEAMID ");
// parameters.Add(new DataParameter { ParameterName = "TEAMID", DataType = DbType.String, Value = condition.TEAM_PID });
// }
// if (whereBuilder.Length > 0)
// {
// sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
// }
// return sqlBuilder.ToString();
// }
// catch (Exception ex)
// {
// throw ex;
// }
// }
// #endregion
}
}