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

484 lines
17 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.BLL;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.DAL.Basic;
using QMFrameWork.Data;
using QMAPP.FJC.Entity;
using QMAPP.Entity;
using QMFrameWork.Log;
namespace QMAPP.FJC.BLL.Basic
{
/// <summary>
/// 模块编号:M2-3
/// 作 用:班次信息逻辑层
/// 作 者:王丹丹
/// 编写日期:2015年05月28日
///</summary>
public class ProduceShiftBLL : BaseBLL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public DataResult<ProduceShift> Get(ProduceShift model)
{
DataResult<ProduceShift> result = new DataResult<ProduceShift>();
try
{
result.Result = new ProduceShiftDAL().Get(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "班次信息逻辑层-获取信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取列表(分页)
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<DataPage> GetList(ProduceShift condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
//获取物料信息列表
DataPage dataPage = new ProduceShiftDAL().GetList(condition, page);
result.Result = dataPage;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "班次信息逻辑层-获取列表!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public List<ProduceShift> GetAllList(ProduceShift condition)
{
try
{
//获取物料信息列表
return new ProduceShiftDAL().GetList(condition);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 信息是否重复
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsProduceShift(ProduceShift model)
{
try
{
return new ProduceShiftDAL().ExistsProduceShift(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public DataResult<int> Insert(ProduceShift model)
{
DataResult<int> result = new DataResult<int>();
ProduceShiftDAL cmdDAL = new ProduceShiftDAL();
//基本信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
//model.PRODUCELINE = EnumGeter.PRODUCELINE.B9.ToString();
try
{
if (ExistsProduceShift(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.ProduceShiftCodeIsHave;
return result;
}
result.Result = new ProduceShiftDAL().Insert(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "班次信息逻辑层-插入信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public DataResult<int> Update(ProduceShift model)
{
DataResult<int> result = new DataResult<int>();
//基本信息
model.UPDATEUSER = this.LoginUser.UserID;
try
{
if (ExistsProduceShift(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.ProduceShiftCodeIsHave;
return result;
}
result.Result = new ProduceShiftDAL().Update(model);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "班次信息逻辑层-更新信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public DataResult<int> Delete(string strs)
{
DataResult<int> result = new DataResult<int>();
string[] list = strs.Split(":".ToCharArray());
try
{
foreach (string str in list)
{
result.Result += this.DeleteProduceShift(new ProduceShift { PID = str });
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "班次信息逻辑层-删除!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public int DeleteProduceShift(ProduceShift model)
{
int count = 0;
try
{
count = new ProduceShiftDAL().Delete(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 校验时间
/// <summary>
/// 校验时间
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public DataResult<bool> ExistsProduceShiftTime(ProduceShift model)
{
ProduceShiftDAL psDal = new ProduceShiftDAL();
ProduceShift condition = new ProduceShift();
condition.PRODUCELINE = model.PRODUCELINE;
IList<ProduceShift> psList = new List<ProduceShift>();
DateTime psStart = new DateTime();
DateTime psEnd = new DateTime();
DateTime startTime = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + model.PSSTART.ToLongTimeString());
DateTime endTime = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + model.PSEND.ToLongTimeString());
DataResult<bool> result = new DataResult<bool>();
try
{
//获取所有班次信息
condition.isNoPID = model.PID;
psList = psDal.GetList(condition);
//遍历所有班次信息,校验输入班次信息时间在数据库中是否已存在
if (psList != null || psList.Count() != 0)
{
foreach (var item in psList)
{
psStart = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + item.PSSTART.ToLongTimeString());
psEnd = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + item.PSEND.ToLongTimeString());
#region 时间校验
if (psStart < psEnd)
{
if (startTime < endTime)
{
if ((psStart < startTime && startTime < psEnd) || (psStart < endTime && endTime < psEnd))
{
result.IsSuccess = false;
result.Msg = Resource.ProductShiftTimeIsExist;
return result;
}
}
else
{
if (psStart < startTime && startTime < psEnd)
{
result.IsSuccess = false;
result.Msg = Resource.ProductShiftTimeIsExist;
return result;
}
if (psStart < endTime && endTime < psEnd)
{
result.IsSuccess = false;
result.Msg = Resource.ProductShiftTimeIsExist;
return result;
}
}
}
else
{
if (psStart < startTime && startTime < Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + "23:59:59"))
{
result.IsSuccess = false;
result.Msg = Resource.ProductShiftTimeIsExist;
return result;
}
if (psStart < endTime && endTime < Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + "23:59:59"))
{
result.IsSuccess = false;
result.Msg = Resource.ProductShiftTimeIsExist;
return result;
}
if (Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + "00:00:00") < startTime && startTime < psEnd)
{
result.IsSuccess = false;
result.Msg = Resource.ProductShiftTimeIsExist;
return result;
}
if (Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + "00:00:00") < endTime && endTime < psEnd)
{
result.IsSuccess = false;
result.Msg = Resource.ProductShiftTimeIsExist;
return result;
}
}
#endregion
}
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "班次信息逻辑层-校验时间!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 获取班次列表(下拉列表使用)
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部集合</returns>
public DataResult<List<ProduceShift>> GetProduceShiftList(ProduceShift condition)
{
DataResult<List<ProduceShift>> result = new DataResult<List<ProduceShift>>();
try
{
result.Result = new ProduceShiftDAL().GetProduceShiftList(condition);
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "班次信息逻辑层-获取班次列表(绑定下拉列表使用)!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
public ProduceShift GetWorkingShift(string workcentercode)
{
try
{
DateTime time = DateTime.Now;
//获取物料信息列表
var shiftlist = this.GetWorkcenterShifts(workcentercode);
foreach (var shift in shiftlist)
{
DateTime start = shift.PSSTART;
DateTime end = shift.PSEND;
var shiftstart = start - start.Date;
var shiftend = end - end.Date;
var nowtime = time - time.Date;
if (InTimeSector(shiftstart, shiftend, nowtime))
{
return shift;
}
}
return null;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 判断当前时间是否在指定时间区域内
/// </summary>
/// <param name="begin">开始时间</param>
/// <param name="end">结束时间</param>
/// <param name="now">当前时间</param>
/// <returns></returns>
private static bool InTimeSector(TimeSpan begin, TimeSpan end, TimeSpan now)
{
var t_begin = begin.Ticks;
var t_end = end.Ticks;
var t_hour = TimeSpan.TicksPerHour;
var t_day = TimeSpan.TicksPerDay;
var t_now = now.Ticks;
var offset = (12 * t_hour - t_begin) >= 0 ? 0 - t_begin : t_day - t_begin;
var offset_now = (t_now + offset) % t_day;
var offset_end = (t_end + offset) % t_day;
if (offset_now >= 0 && offset_now < offset_end)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 获取工作中心下的班次信息
/// </summary>
/// <param name="workcentercode"></param>
/// <returns></returns>
public List<ProduceShift> GetWorkcenterShifts(string workcentercode)
{
QMFrameWork.Cache.CacheManager cm = new QMFrameWork.Cache.CacheManager("ProduceShiftBLL");
var obj = cm.Get(string.Format("GetWorkcenterShifts({0})", workcentercode));
if (obj != null)
{
return obj as List<ProduceShift>;
}
else
{
var dal = new ProduceShiftDAL();
var shifts = dal.GetList(new ProduceShift { PRODUCELINE = workcentercode });
if (shifts.Count == 0)
{
shifts = dal.GetList(new ProduceShift { PRODUCELINE = "" });
}
cm.Add(string.Format("GetWorkcenterShifts({0})", workcentercode), shifts);
return shifts;
}
}
}
}