358 lines
16 KiB
C#
358 lines
16 KiB
C#
using FineUIPro;
|
||
using Model;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace BLL
|
||
{
|
||
public class SitePerson_DayReportService
|
||
{
|
||
/// <summary>
|
||
/// 获取工作日报信息
|
||
/// </summary>
|
||
/// <param name="dayReportId">工作日报Id</param>
|
||
/// <returns></returns>
|
||
public static Model.SitePerson_DayReport GetDayReportByDayReportId(string dayReportId)
|
||
{
|
||
return Funs.DB.SitePerson_DayReport.FirstOrDefault(x => x.DayReportId == dayReportId);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 增加工作日报信息
|
||
/// </summary>
|
||
/// <param name="dayReport">工作日报实体</param>
|
||
public static void AddDayReport(Model.SitePerson_DayReport dayReport)
|
||
{
|
||
Model.SUBQHSEDB db = Funs.DB;
|
||
Model.SitePerson_DayReport newDayReport = new Model.SitePerson_DayReport
|
||
{
|
||
DayReportId = dayReport.DayReportId,
|
||
ProjectId = dayReport.ProjectId,
|
||
CompileMan = dayReport.CompileMan,
|
||
CompileDate = dayReport.CompileDate,
|
||
States = dayReport.States
|
||
};
|
||
db.SitePerson_DayReport.InsertOnSubmit(newDayReport);
|
||
db.SubmitChanges();
|
||
|
||
////增加一条编码记录
|
||
BLL.CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId(BLL.Const.DayReportMenuId, dayReport.ProjectId, null, dayReport.DayReportId, dayReport.CompileDate);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改工作日报信息
|
||
/// </summary>
|
||
/// <param name="dayReport">工作日报实体</param>
|
||
public static void UpdateDayReport(Model.SitePerson_DayReport dayReport)
|
||
{
|
||
Model.SUBQHSEDB db = Funs.DB;
|
||
Model.SitePerson_DayReport newDayReport = db.SitePerson_DayReport.First(e => e.DayReportId == dayReport.DayReportId);
|
||
newDayReport.ProjectId = dayReport.ProjectId;
|
||
newDayReport.CompileMan = dayReport.CompileMan;
|
||
newDayReport.CompileDate = dayReport.CompileDate;
|
||
newDayReport.States = dayReport.States;
|
||
|
||
db.SubmitChanges();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据工作日报主键删除一个工作日报信息
|
||
/// </summary>
|
||
/// <param name="dayReportId">工作日报主键</param>
|
||
public static void DeleteDayReportByDayReportId(string dayReportId)
|
||
{
|
||
Model.SUBQHSEDB db = Funs.DB;
|
||
Model.SitePerson_DayReport dayReport = db.SitePerson_DayReport.FirstOrDefault(e => e.DayReportId == dayReportId);
|
||
if (dayReport != null)
|
||
{
|
||
///删除编码表记录
|
||
BLL.CodeRecordsService.DeleteCodeRecordsByDataId(dayReportId);
|
||
BLL.CommonService.DeleteFlowOperateByID(dayReportId);
|
||
db.SitePerson_DayReport.DeleteOnSubmit(dayReport);
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 判断人工月报是否存在
|
||
/// </summary>
|
||
/// <param name="monthDate"></param>
|
||
/// <param name="projectId"></param>
|
||
/// <returns>true 存在;false:不存在</returns>
|
||
public static bool IsExistDayReport(DateTime compileDate, string projectId)
|
||
{
|
||
var q = from x in Funs.DB.SitePerson_DayReport
|
||
where x.CompileDate == compileDate && x.ProjectId == projectId
|
||
select x;
|
||
if (q.Count() > 0)
|
||
{
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据时间获取工作日报信息
|
||
/// </summary>
|
||
/// <param name="startTime">开始时间</param>
|
||
/// <param name="endTime">结束时间</param>
|
||
/// <returns>工作日报信息</returns>
|
||
public static List<Model.SitePerson_DayReport> GetDayReportsByCompileDate(DateTime startTime, DateTime endTime, string projectId)
|
||
{
|
||
return (from x in Funs.DB.SitePerson_DayReport where x.CompileDate >= startTime && x.CompileDate < endTime && x.ProjectId == projectId && x.States == BLL.Const.State_2 select x).ToList();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据时间获取工作日报信息
|
||
/// </summary>
|
||
/// <param name="startTime">开始时间</param>
|
||
/// <param name="endTime">结束时间</param>
|
||
/// <returns>工作日报信息</returns>
|
||
public static List<Model.SitePerson_DayReport> GetDayReportsByCompileDate2(DateTime startTime, string projectId)
|
||
{
|
||
return (from x in Funs.DB.SitePerson_DayReport where x.CompileDate >= startTime && x.ProjectId == projectId && x.States == BLL.Const.State_2 select x).ToList();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取工作日报信息
|
||
/// </summary>
|
||
/// <param name="startTime">开始时间</param>
|
||
/// <param name="endTime">结束时间</param>
|
||
/// <returns>工作日报信息</returns>
|
||
public static List<Model.SitePerson_DayReport> GetDayReports(string projectId)
|
||
{
|
||
return (from x in Funs.DB.SitePerson_DayReport where x.ProjectId == projectId && x.States == BLL.Const.State_2 select x).ToList();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据时间获取工作日报信息
|
||
/// </summary>
|
||
/// <param name="startTime">开始时间</param>
|
||
/// <param name="endTime">结束时间</param>
|
||
/// <returns>工作日报信息</returns>
|
||
public static List<Model.SitePerson_DayReport> GetDayReportsByCompileDateAndUnitId(DateTime startTime, DateTime endTime, string projectId, string unitId)
|
||
{
|
||
using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString))
|
||
{
|
||
return (from x in db.SitePerson_DayReport
|
||
join y in db.SitePerson_DayReportDetail
|
||
on x.DayReportId equals y.DayReportId
|
||
where x.CompileDate >= startTime && x.CompileDate < endTime && x.ProjectId == projectId && x.States == BLL.Const.State_2
|
||
&& y.UnitId == unitId
|
||
select x).Distinct().ToList();
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取出入记录人工时
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static List<Model.SitePerson_DayReport> getDayReports(string projectId, DateTime? sDate)
|
||
{
|
||
Model.SUBQHSEDB db = Funs.DB;
|
||
List<Model.SitePerson_DayReport> reports = new List<Model.SitePerson_DayReport>();
|
||
var getAllPersonInOutList = from x in db.SitePerson_PersonInOutNumber
|
||
where x.ProjectId == projectId
|
||
select x;
|
||
if (getAllPersonInOutList.Count() > 0)
|
||
{
|
||
var getInOutDates = getAllPersonInOutList.Select(x => x.InOutDate);
|
||
if (sDate.HasValue)
|
||
{
|
||
getInOutDates = getInOutDates.Where(x => x.Year == sDate.Value.Year && x.Month == sDate.Value.Month && x.Day == sDate.Value.Day);
|
||
}
|
||
|
||
foreach (var item in getInOutDates)
|
||
{
|
||
var getNow = getAllPersonInOutList.FirstOrDefault(x => x.InOutDate.Year == item.Year && x.InOutDate.Month == item.Month && x.InOutDate.Day == item.Day);
|
||
if (getNow != null)
|
||
{
|
||
Model.SitePerson_DayReport reportItem = new Model.SitePerson_DayReport
|
||
{
|
||
DayReportId = SQLHelper.GetNewID(),
|
||
ProjectId = projectId,
|
||
CompileDate = item,
|
||
TotalPersonWorkTime = getNow.WorkHours,
|
||
};
|
||
|
||
var getMax = getAllPersonInOutList.Where(x => x.InOutDate < item).Max(x => x.WorkHours) ?? 0;
|
||
reportItem.DayWorkTime = (getNow.WorkHours ?? 0) - getMax;
|
||
reports.Add(reportItem);
|
||
}
|
||
|
||
}
|
||
}
|
||
return reports;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取当月时间汇总
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static List<object> getMonthChart()
|
||
{
|
||
Model.SUBQHSEDB db = Funs.DB;
|
||
|
||
var sDate = DateTime.Now.AddMonths(-6);
|
||
var eDate = DateTime.Now;
|
||
var sitePerson = db.SitePerson_DayReport
|
||
.Where(c => c.CompileDate >= sDate && c.CompileDate <= eDate)
|
||
.Select(c => new
|
||
{
|
||
c.DayReportId,
|
||
c.CompileDate,
|
||
PersonWorkTime = db.SitePerson_DayReportDetail.Where(x => x.DayReportId == c.DayReportId).Sum(x => x.PersonWorkTime),
|
||
TotalPersonWorkTime = db.SitePerson_DayReportDetail.Where(x => x.DayReportId == c.DayReportId).Sum(x => x.TotalPersonWorkTime)
|
||
}).ToList();
|
||
|
||
return sitePerson.GroupBy(c => new { c.CompileDate.Value.Year, c.CompileDate.Value.Month }).Select(c => new
|
||
{
|
||
Date = c.Key.Year + "-" + c.Key.Month,
|
||
DayWorkTime = c.Sum(t => t.PersonWorkTime),
|
||
TotalPersonWorkTime = c.Sum(t => t.TotalPersonWorkTime),
|
||
}).ToList<object>();
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
public static void SyncReport(string projectid)
|
||
{
|
||
|
||
var db = Funs.DB;
|
||
var datetime = DateTime.Now.ToString();
|
||
var dataStart = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
|
||
var dataEnd = DateTime.Now.ToString("yyyy-MM-dd 23:59:59");
|
||
|
||
//1.根据日期获取当天所有考勤
|
||
//var resultList = db.SitePerson_PersonInOut.Where(x => x.ProjectId == projectid && x.ChangeTime >= Convert.ToDateTime(dataStart)
|
||
//&& x.ChangeTime <= Convert.ToDateTime(dataEnd)).ToList();
|
||
var resultList = db.SitePerson_Person.Where(x => x.ProjectId == projectid && x.IsUsed==true).ToList();
|
||
//添加到人工时日报
|
||
if (resultList.Count > 0)
|
||
{
|
||
//resultList人员去重
|
||
resultList = resultList.GroupBy(x => x.IdentityCard).Select(item => item.First()).ToList();
|
||
|
||
#region 人工时日报
|
||
var q =( from x in Funs.DB.SitePerson_DayReport
|
||
where x.CompileDate.Value.Date == DateTime.Now.Date && x.ProjectId == projectid
|
||
select x).FirstOrDefault();
|
||
if (q!=null)
|
||
{
|
||
SitePerson_DayReportDetailService.DeleteDayReportDetailsByDayReportId(q.DayReportId);
|
||
DeleteDayReportByDayReportId(q.DayReportId);
|
||
}
|
||
|
||
|
||
var DayReportId = SQLHelper.GetNewID(typeof(Model.SitePerson_DayReport));
|
||
Model.SitePerson_DayReport newDayReport = new Model.SitePerson_DayReport
|
||
{
|
||
DayReportId = DayReportId,
|
||
ProjectId = projectid,
|
||
|
||
CompileDate = DateTime.Now,
|
||
States = BLL.Const.State_0 //待提交
|
||
};
|
||
if (!string.IsNullOrEmpty(datetime))
|
||
{
|
||
newDayReport.CompileDate = Convert.ToDateTime(DateTime.Now);
|
||
}
|
||
BLL.SitePerson_DayReportService.AddDayReport(newDayReport);
|
||
|
||
var units = from x in Funs.DB.Project_ProjectUnit
|
||
where x.ProjectId == projectid && (x.UnitType == BLL.Const.ProjectUnitType_1 || x.UnitType == BLL.Const.ProjectUnitType_2 || x.UnitType == BLL.Const.ProjectUnitType_0)
|
||
select x; //1为总包,2为施工分包 0为其他
|
||
if (units.Count() > 0)
|
||
{
|
||
foreach (var item in units)
|
||
{
|
||
var d = DateTime.Now.Date;
|
||
if (!string.IsNullOrEmpty(datetime))
|
||
{
|
||
d = Convert.ToDateTime(datetime).Date;
|
||
}
|
||
if (item.OutTime == null || item.OutTime >= d)
|
||
{
|
||
Model.SitePerson_DayReportDetail newDayReportDetail = new Model.SitePerson_DayReportDetail();
|
||
string newKeyID = SQLHelper.GetNewID(typeof(Model.SitePerson_DayReportDetail));
|
||
newDayReportDetail.DayReportDetailId = newKeyID;
|
||
newDayReportDetail.DayReportId = DayReportId;
|
||
newDayReportDetail.UnitId = item.UnitId;
|
||
newDayReportDetail.WorkTime = 10;
|
||
//根据unitid获取实际人数
|
||
var RealPersonNum = resultList.Where(x => x.UnitId == item.UnitId).Count() ;
|
||
if (RealPersonNum > 0)
|
||
{
|
||
newDayReportDetail.RealPersonNum = RealPersonNum ;
|
||
newDayReportDetail.PersonWorkTime = 10 * RealPersonNum;
|
||
}else
|
||
{
|
||
newDayReportDetail.RealPersonNum = 0;
|
||
newDayReportDetail.PersonWorkTime = 0;
|
||
}
|
||
//newDayReportDetail.StaffData = this.GetStaffData(item.UnitId, item.UnitType, compileDate.Value);
|
||
BLL.SitePerson_DayReportDetailService.AddDayReportDetail(newDayReportDetail);
|
||
var posts = (from x in Funs.DB.Base_WorkPost
|
||
join y in Funs.DB.SitePerson_Person
|
||
on x.WorkPostId equals y.WorkPostId
|
||
where y.UnitId == item.UnitId && y.ProjectId == projectid
|
||
orderby x.WorkPostCode
|
||
select x).Distinct().ToList();
|
||
foreach (var postItem in posts)
|
||
{
|
||
Model.SitePerson_DayReportUnitDetail newDayReportUnitDetail = new Model.SitePerson_DayReportUnitDetail
|
||
{
|
||
DayReportDetailId = newKeyID,
|
||
PostId = postItem.WorkPostId,
|
||
CheckPersonNum = GetCheckingCout(postItem.WorkPostId, DateTime.Now, projectid)
|
||
};
|
||
if (!string.IsNullOrEmpty(datetime))
|
||
{
|
||
newDayReportUnitDetail.CheckPersonNum = GetCheckingCout(postItem.WorkPostId, Convert.ToDateTime(datetime), projectid);
|
||
}
|
||
newDayReportUnitDetail.RealPersonNum = newDayReportUnitDetail.CheckPersonNum;
|
||
newDayReportUnitDetail.PersonWorkTime = newDayReportUnitDetail.RealPersonNum * newDayReportDetail.WorkTime;
|
||
BLL.SitePerson_DayReportUnitDetailService.AddDayReportUnitDetail(newDayReportUnitDetail);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
}
|
||
|
||
#region 得到当前岗位考勤人数
|
||
/// <summary>
|
||
/// 得到当前岗位考勤人数
|
||
/// </summary>
|
||
/// <param name="postId"></param>
|
||
/// <returns></returns>
|
||
private static int GetCheckingCout(string workPostId, DateTime txtCompileDate, string projectid)
|
||
{
|
||
int count = 0;
|
||
DateTime? nowMont = txtCompileDate;
|
||
if (nowMont.HasValue)
|
||
{
|
||
var checks = from x in Funs.DB.SitePerson_Checking
|
||
join y in Funs.DB.SitePerson_Person on x.PersonId equals y.PersonId
|
||
join z in Funs.DB.Base_WorkPost on y.WorkPostId equals z.WorkPostId
|
||
where x.IntoOutTime > nowMont.Value.AddDays(-1) && x.IntoOutTime < nowMont.Value.AddDays(1) && y.ProjectId == projectid
|
||
&& z.WorkPostId == workPostId
|
||
select x;
|
||
count = checks.Count();
|
||
}
|
||
|
||
return count;
|
||
}
|
||
#endregion
|
||
}
|
||
}
|