179 lines
8.0 KiB
C#
179 lines
8.0 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace BLL
|
|||
|
{
|
|||
|
public class PersonStarLevelService
|
|||
|
{
|
|||
|
public static Model.SGGLDB db = Funs.DB;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 设置人员星级
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public static string SetPersonStarLevel(string projectId, string userId, int? starLevelValue, string starLevelId)
|
|||
|
{
|
|||
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|||
|
{
|
|||
|
string levelId = starLevelId;
|
|||
|
var getPersons = db.Sys_User.FirstOrDefault(x => x.UserId == userId);
|
|||
|
if (getPersons != null)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(levelId) && starLevelValue.HasValue)
|
|||
|
{
|
|||
|
levelId = StarLevelService.GetStarLevelIdByValue(starLevelValue.Value);
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(levelId))
|
|||
|
{
|
|||
|
starLevelValue = StarLevelService.GetStarLevelValueById(starLevelId);
|
|||
|
}
|
|||
|
|
|||
|
var getCloseItem = from x in db.Person_StarLevelItem
|
|||
|
where x.PersonId == userId
|
|||
|
&& (x.NextIsClosed == null || x.NextIsClosed == false)
|
|||
|
select x;
|
|||
|
if (getCloseItem.Count() > 0)
|
|||
|
{
|
|||
|
foreach (var item in getCloseItem)
|
|||
|
{
|
|||
|
item.NextIsClosed = true;
|
|||
|
}
|
|||
|
db.SubmitChanges();
|
|||
|
}
|
|||
|
|
|||
|
if (2 <= starLevelValue && starLevelValue <= 5)
|
|||
|
{
|
|||
|
getPersons.StarLevelId = levelId;
|
|||
|
getPersons.GetStarTime = DateTime.Now;
|
|||
|
Model.Person_StarLevelItem newItem = new Model.Person_StarLevelItem
|
|||
|
{
|
|||
|
StarLevelItemId = SQLHelper.GetNewID(),
|
|||
|
PersonId = userId,
|
|||
|
UnitId = getPersons.UnitId,
|
|||
|
ProjectId = projectId,
|
|||
|
StarLevelId = starLevelId,
|
|||
|
LevelValue = starLevelValue,
|
|||
|
GetStarTime = DateTime.Now,
|
|||
|
NextStarCount = 0,
|
|||
|
NextStarTime = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1),
|
|||
|
NextIsClosed = false,
|
|||
|
};
|
|||
|
|
|||
|
db.SubmitChanges();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return levelId;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 人员升星
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public static string UpPersonStarLevel(string projectId, string userId)
|
|||
|
{
|
|||
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|||
|
{
|
|||
|
string levelId = string.Empty;
|
|||
|
var getPersons = db.Sys_User.FirstOrDefault(x => x.UserId == userId);
|
|||
|
if (getPersons != null && !string.IsNullOrEmpty(getPersons.StarLevelId))
|
|||
|
{
|
|||
|
int starValue = 2;
|
|||
|
var getBaseStar = StarLevelService.GetStarLevelById(getPersons.StarLevelId);
|
|||
|
if (getBaseStar != null)
|
|||
|
{
|
|||
|
starValue = getBaseStar.LevelValue ?? 2; ///当前人星级
|
|||
|
int cycle = getBaseStar.Cycle ?? 2; ////评价周期
|
|||
|
var getMax = db.Person_StarLevelItem.FirstOrDefault(x => x.PersonId == userId && (x.NextIsClosed == null || x.NextIsClosed == false));
|
|||
|
if (getMax != null && getMax.NextStarCount.HasValue && getMax.NextStarCount >= cycle)
|
|||
|
{
|
|||
|
int getLevel = starValue + 1;
|
|||
|
SetPersonStarLevel(projectId, userId, getLevel, null);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return levelId;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="projectId"></param>
|
|||
|
/// <param name="personId"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static string collectLog(string projectId, string personId)
|
|||
|
{
|
|||
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|||
|
{
|
|||
|
string starMark = string.Empty;
|
|||
|
///已经存在星级的人员 才能升星
|
|||
|
var getPerson = db.Sys_User.FirstOrDefault(x => x.UserId == personId && x.StarLevelId != null);
|
|||
|
if (getPerson != null)
|
|||
|
{
|
|||
|
//// 获取人员星级id
|
|||
|
string starLevelId = getPerson.StarLevelId;
|
|||
|
///根据id 获取星级值
|
|||
|
int? starLevelValue;
|
|||
|
var getStarLevel = db.Base_StarLevel.FirstOrDefault(x => x.StarLevelId == starLevelId);
|
|||
|
if (getStarLevel != null && getStarLevel.LevelValue.HasValue)
|
|||
|
{
|
|||
|
starMark = getStarLevel.StarMark;
|
|||
|
starLevelValue = getStarLevel.LevelValue;
|
|||
|
///获取当前时间内 需要升星的标准
|
|||
|
var getStarLevelItem = db.Base_StarLevelItem.Where(x => x.StarLevelId == starLevelId);
|
|||
|
if (getStarLevelItem.Count() > 0)
|
|||
|
{
|
|||
|
/////评星开始时间
|
|||
|
DateTime starDate = DateTime.Now.AddDays(1 - DateTime.Now.Day);
|
|||
|
var getGetStarDate = db.Person_StarLevelItem.FirstOrDefault(x => x.PersonId == personId && (x.NextIsClosed == null || x.NextIsClosed == false));
|
|||
|
if (getGetStarDate != null && getGetStarDate.NextStarTime.HasValue && getGetStarDate.NextStarTime > starDate)
|
|||
|
{
|
|||
|
DateTime d = getGetStarDate.NextStarTime.Value;
|
|||
|
starDate = d.AddDays(1 - d.Day).AddMonths(1);
|
|||
|
}
|
|||
|
|
|||
|
DateTime endDate = starDate.AddMonths(1);
|
|||
|
////获取当前周期内是否达标
|
|||
|
var getLogs = from x in db.InformationProject_ConstructionLog
|
|||
|
join y in db.InformationProject_ConstructionLogItem on x.ConstructionLogId equals y.ConstructionLogId
|
|||
|
where x.PersonId == personId && x.WorkDate >= starDate && x.WorkDate <= endDate
|
|||
|
select y;
|
|||
|
if (getLogs.Count() > 0)
|
|||
|
{
|
|||
|
int i = 0;
|
|||
|
foreach (var item in getStarLevelItem)
|
|||
|
{
|
|||
|
var getCount = getLogs.Where(x => x.ExamTypeId == item.ExamType).Sum(x => x.Frequency ?? 0);
|
|||
|
if (getCount >= (item.Frequency ?? 0))
|
|||
|
{
|
|||
|
i++;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
i = 0;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (i > 0)
|
|||
|
{
|
|||
|
///可以升星
|
|||
|
starMark = StarLevelService.GetStarStarMarkById(UpPersonStarLevel(projectId, personId));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return starMark;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|