268 lines
11 KiB
C#
268 lines
11 KiB
C#
using BLL;
|
|
using Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web.Services;
|
|
using System.Linq;
|
|
using System.Web.UI.WebControls;
|
|
using System.Threading.Tasks;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace FineUIPro.Web.DataShow
|
|
{
|
|
public partial class kq : PageBase
|
|
{
|
|
public static string userId;
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
userId = this.CurrUser.UserId;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据身份证号计算年龄
|
|
/// </summary>
|
|
private static int? CalculateAgeFromIdCard(string idCard)
|
|
{
|
|
if (string.IsNullOrEmpty(idCard) || idCard.Length < 17)
|
|
return null;
|
|
|
|
try
|
|
{
|
|
string birthDateStr = idCard.Substring(6, 8);
|
|
DateTime birthDate = DateTime.ParseExact(birthDateStr, "yyyyMMdd", null);
|
|
|
|
int age = DateTime.Now.Year - birthDate.Year;
|
|
if (DateTime.Now.Month < birthDate.Month ||
|
|
(DateTime.Now.Month == birthDate.Month && DateTime.Now.Day < birthDate.Day))
|
|
{
|
|
age--;
|
|
}
|
|
|
|
return age > 0 ? age : (int?)null;
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 看板数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[WebMethod]
|
|
public static object GetData()
|
|
{
|
|
try
|
|
{
|
|
var db = Funs.DB;
|
|
var projectList = (from project in db.Base_Project
|
|
where (project.ProjectAttribute == "GONGCHENG" || project.ProjectAttribute == null)
|
|
&& (project.IsDelete == null || project.IsDelete == false) && project.ProjectState == "1"
|
|
select new
|
|
{
|
|
project.UnitId,
|
|
project.ProjectId,
|
|
ProjectName = string.IsNullOrEmpty(project.ShortName) ? project.ProjectName : project.ShortName,
|
|
project.ProjectAddress,
|
|
project.MapCoordinates,
|
|
}).ToList();
|
|
|
|
int unitType = CommonService.GetUnitTypeByUserId(userId);
|
|
if (unitType == 1)
|
|
{
|
|
projectList = projectList.Where(x => x.UnitId == userId).ToList();
|
|
}
|
|
|
|
var chinaMapData = projectList
|
|
.Where(x => !string.IsNullOrEmpty(x.MapCoordinates))
|
|
.Select(x =>
|
|
{
|
|
var coords = x.MapCoordinates.Split(',');
|
|
return new
|
|
{
|
|
id = x.ProjectId,
|
|
name = x.ProjectName,
|
|
address = x.ProjectAddress,
|
|
value = coords.Length >= 2
|
|
? new[] { Convert.ToDouble(coords[0]), Convert.ToDouble(coords[1]) }
|
|
: new double[] { 0, 0 }
|
|
};
|
|
}).ToList();
|
|
|
|
|
|
// 获取在建项目id列表
|
|
List<string> beUnderConstructionList = projectList.Select(p => p.ProjectId).ToList();
|
|
//获取所有人员列表
|
|
var persons = db.View_SitePerson_Person.Where(x => beUnderConstructionList.Contains(x.ProjectId)).ToList();
|
|
|
|
var onDutyNum = persons.Where(x => x.IsUsedType == "1").Count();
|
|
|
|
//获取今天所有出入场记录
|
|
DateTime todayStart = DateTime.Now.Date;
|
|
DateTime todayEnd = todayStart.AddDays(1).AddSeconds(-1);
|
|
var outOuts = db.SitePerson_PersonInOut.Where(x =>
|
|
x.ChangeTime.HasValue && x.ChangeTime.Value.Date >= todayStart &&
|
|
x.ChangeTime.Value.Date <= todayEnd && beUnderConstructionList.Contains(x.ProjectId)).ToList();
|
|
|
|
var inNum = outOuts.Where(x => x.IsIn == true)
|
|
.GroupBy(x => x.PersonId)
|
|
.Select(grp => grp.First())
|
|
.Count(); //入场数量
|
|
|
|
var inRate = "0.00%";
|
|
if (onDutyNum > 0)
|
|
{
|
|
inRate = (inNum * 100.0 / onDutyNum).ToString("F2") + "%";
|
|
}
|
|
|
|
var attendanceStats = (from p in persons
|
|
join proj in projectList on p.ProjectId equals proj.ProjectId
|
|
group p by new { p.ProjectId, proj.ProjectName } into g
|
|
let todayInCount = outOuts.Where(x => x.ProjectId == g.Key.ProjectId && x.IsIn == true)
|
|
.GroupBy(x => x.PersonId)
|
|
.Select(grp => grp.First())
|
|
.Count()
|
|
orderby g.Count() descending
|
|
select new
|
|
{
|
|
projectId = g.Key.ProjectId,
|
|
projectName = g.Key.ProjectName,
|
|
allNum = g.Count(),
|
|
onDutyNum = g.Count(x => x.IsUsedType == "1"),
|
|
todayAttendanceNum = todayInCount
|
|
}).ToList();
|
|
|
|
var workTypeStats = (from p in persons
|
|
where !string.IsNullOrEmpty(p.WorkPostId)
|
|
group p by new {p.WorkPostId,p.WorkPostName} into g
|
|
orderby g.Count() descending
|
|
select new
|
|
{
|
|
id = g.Key.WorkPostId,
|
|
name = g.Key.WorkPostName,
|
|
value = g.Count()
|
|
}).Take(10).ToList();
|
|
|
|
var personWithAge = persons
|
|
.Where(x => !string.IsNullOrEmpty(x.IdentityCard))
|
|
.Select(x => new
|
|
{
|
|
Person = x,
|
|
Age = CalculateAgeFromIdCard(x.IdentityCard)
|
|
}).Where(x => x.Age.HasValue).ToList();
|
|
|
|
var ageStats = personWithAge
|
|
.Where(x => x.Age.Value >= 16 && x.Age.Value <= 55)
|
|
.GroupBy(x =>
|
|
{
|
|
int age = x.Age.Value;
|
|
if (age >= 16 && age <= 25) return "16-25";
|
|
if (age >= 26 && age <= 35) return "26-35";
|
|
if (age >= 36 && age <= 45) return "36-45";
|
|
return "46-55";
|
|
})
|
|
.Select(g => new { name = g.Key, value = g.Count() })
|
|
.OrderByDescending(x => x.value)
|
|
.ToList();
|
|
|
|
var genderStats = persons.Where(x => !string.IsNullOrEmpty(x.Sex))
|
|
.GroupBy(x => x.Sex)
|
|
.Select(g => new {
|
|
name = g.Key == "1" ? "男" : (g.Key == "2" ? "女" : g.Key),
|
|
value = g.Count()
|
|
})
|
|
.ToList();
|
|
|
|
var lwInOutList = (from o in outOuts
|
|
join p in db.View_SitePerson_Person on o.PersonId equals p.PersonId into personGroup
|
|
from p in personGroup.DefaultIfEmpty()
|
|
where p != null
|
|
orderby o.ChangeTime descending
|
|
select new
|
|
{
|
|
PhotoUrl = p.PhotoUrl,
|
|
PersonName = o.PersonName ?? string.Empty,
|
|
WorkPostName = o.WorkPostName ?? string.Empty,
|
|
ChangeTime = o.ChangeTime.HasValue ? o.ChangeTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : string.Empty,
|
|
IsIn = o.IsIn.HasValue && o.IsIn.Value ? "in" : "out"
|
|
}).Take(200).ToList();
|
|
|
|
//先获取管理人员的数据
|
|
var projectUserList = (from a in db.Project_ProjectUser
|
|
join b in db.Sys_User on a.UserId equals b.UserId into userJoin
|
|
from b in userJoin.DefaultIfEmpty()
|
|
where beUnderConstructionList.Contains(a.ProjectId)
|
|
select new
|
|
{
|
|
ProjectId = a.ProjectId,
|
|
IdentityCard = b.IdentityCard,
|
|
}).ToList();
|
|
//获取管理人员身份证
|
|
var managerIdentityCards = projectUserList.Where(x => x.IdentityCard != null)
|
|
.Select(x => x.IdentityCard).ToList();
|
|
|
|
var managerData = new List<int>();
|
|
var workerData = new List<int>();
|
|
|
|
for (int hour = 0; hour < 24; hour++)
|
|
{
|
|
DateTime hourStart = todayStart.AddHours(hour);
|
|
DateTime hourEnd = hourStart.AddHours(1).AddSeconds(-1);
|
|
|
|
var hourRecords = outOuts.Where(x => x.ChangeTime.HasValue &&
|
|
x.ChangeTime.Value >= hourStart &&
|
|
x.ChangeTime.Value <= hourEnd).ToList();
|
|
|
|
int managerCount = 0;
|
|
int workerCount = 0;
|
|
if (hourRecords.Count > 0)
|
|
{
|
|
managerCount = hourRecords.Count(x => managerIdentityCards.Contains(x.IdentityCard));
|
|
workerCount = hourRecords.Count - managerCount;
|
|
}
|
|
managerData.Add(managerCount);
|
|
workerData.Add(workerCount);
|
|
}
|
|
|
|
|
|
var returnData = new
|
|
{
|
|
success = true,
|
|
data = new
|
|
{
|
|
person = new
|
|
{
|
|
allNum = persons.Count, //总在册数
|
|
onDutyNum = onDutyNum, //总在场数
|
|
todayAttendanceNum = inNum, //今日出勤数
|
|
todayAttendanceRate = inRate, //今日出勤率
|
|
},
|
|
attendanceCurve = new
|
|
{
|
|
managerData = managerData,
|
|
workerData = workerData
|
|
},
|
|
attendanceStats = attendanceStats,
|
|
workTypeStats = workTypeStats,
|
|
ageStats = ageStats,
|
|
genderStats = genderStats,
|
|
lwInOutList = lwInOutList,
|
|
chinaMapData = chinaMapData,
|
|
}
|
|
};
|
|
|
|
return returnData;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new { success = false, msg = ex.Message };
|
|
}
|
|
}
|
|
}
|
|
} |