1
This commit is contained in:
@@ -0,0 +1,338 @@
|
||||
using System;
|
||||
using Model;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
/// <summary>
|
||||
/// 企业级检查明细服务
|
||||
/// </summary>
|
||||
public static class UnitHazardRegisterItemService
|
||||
{
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// 添加明细记录
|
||||
/// </summary>
|
||||
/// <param name="item">明细记录</param>
|
||||
public static void AddUnitHazardRegisterItem(Model.Supervise_UnitHazardRegisterItem item)
|
||||
{
|
||||
Funs.DB.Supervise_UnitHazardRegisterItem.InsertOnSubmit(item);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据主表ID删除所有明细
|
||||
/// </summary>
|
||||
/// <param name="registerId">主表ID</param>
|
||||
public static void DeleteItemsByRegisterId(string registerId)
|
||||
{
|
||||
var items = (from x in Funs.DB.Supervise_UnitHazardRegisterItem
|
||||
where x.UnitHazardRegisterId == registerId
|
||||
select x).ToList();
|
||||
if (items.Count > 0)
|
||||
{
|
||||
Funs.DB.Supervise_UnitHazardRegisterItem.DeleteAllOnSubmit(items);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除明细记录
|
||||
/// </summary>
|
||||
/// <param name="itemId">明细ID</param>
|
||||
public static void DeleteUnitHazardRegisterItemById(string itemId)
|
||||
{
|
||||
Model.Supervise_UnitHazardRegisterItem item =
|
||||
Funs.DB.Supervise_UnitHazardRegisterItem.FirstOrDefault(e => e.UnitHazardRegisterItemId == itemId);
|
||||
if (item != null)
|
||||
{
|
||||
Funs.DB.Supervise_UnitHazardRegisterItem.DeleteOnSubmit(item);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据风险级别获取明细数量
|
||||
/// </summary>
|
||||
/// <param name="registerId">主表ID</param>
|
||||
/// <param name="riskLevel">风险级别</param>
|
||||
/// <returns>明细数量</returns>
|
||||
public static int GetCountByRiskLevel(string registerId, string riskLevel)
|
||||
{
|
||||
return (from x in Funs.DB.Supervise_UnitHazardRegisterItem
|
||||
where x.UnitHazardRegisterId == registerId && x.RiskLevel == riskLevel
|
||||
select x).Count();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取已完成的明细数量
|
||||
/// </summary>
|
||||
/// <param name="registerId">主表ID</param>
|
||||
/// <returns>已完成数量</returns>
|
||||
public static int GetFinishedCount(string registerId)
|
||||
{
|
||||
return (from x in Funs.DB.Supervise_UnitHazardRegisterItem
|
||||
where x.UnitHazardRegisterId == registerId && x.CompleteStatus == 1
|
||||
select x).Count();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据主表ID获取明细列表
|
||||
/// </summary>
|
||||
/// <param name="registerId">主表ID</param>
|
||||
/// <returns>明细列表</returns>
|
||||
public static List<Model.Supervise_UnitHazardRegisterItem> GetItemsByRegisterId(string registerId)
|
||||
{
|
||||
return (from x in Funs.DB.Supervise_UnitHazardRegisterItem
|
||||
where x.UnitHazardRegisterId == registerId
|
||||
orderby x.SortIndex
|
||||
select x).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取主单的整改状态
|
||||
/// </summary>
|
||||
/// <param name="registerId">主单ID</param>
|
||||
/// <returns>整改状态:0=全部未整改,1=部分整改,2=全部整改</returns>
|
||||
public static int GetRectifyStatus(string registerId)
|
||||
{
|
||||
var items = GetItemsByRegisterId(registerId);
|
||||
|
||||
if (items.Count == 0)
|
||||
{
|
||||
return 0; // 无明细,视为全部未整改
|
||||
}
|
||||
|
||||
int finishedCount = items.Count(x => x.CompleteStatus == 1);
|
||||
int totalCount = items.Count;
|
||||
|
||||
if (finishedCount == 0)
|
||||
{
|
||||
return 0; // 全部未整改
|
||||
}
|
||||
else if (finishedCount < totalCount)
|
||||
{
|
||||
return 1; // 部分整改
|
||||
}
|
||||
else
|
||||
{
|
||||
return 2; // 全部整改
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取整改状态文本
|
||||
/// </summary>
|
||||
/// <param name="registerId">主单ID</param>
|
||||
/// <returns>状态文本</returns>
|
||||
public static string GetRectifyStatusText(string registerId)
|
||||
{
|
||||
int status = GetRectifyStatus(registerId);
|
||||
switch (status)
|
||||
{
|
||||
case 0:
|
||||
return "全部未整改";
|
||||
|
||||
case 1:
|
||||
return "部分整改";
|
||||
|
||||
case 2:
|
||||
return "全部整改";
|
||||
|
||||
default:
|
||||
return "未知";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取未完成的明细数量
|
||||
/// </summary>
|
||||
/// <param name="registerId">主表ID</param>
|
||||
/// <returns>未完成数量</returns>
|
||||
public static int GetUnfinishedCount(string registerId)
|
||||
{
|
||||
return (from x in Funs.DB.Supervise_UnitHazardRegisterItem
|
||||
where x.UnitHazardRegisterId == registerId && (x.CompleteStatus == null || x.CompleteStatus == 0)
|
||||
select x).Count();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据明细ID获取明细记录
|
||||
/// </summary>
|
||||
/// <param name="itemId">明细ID</param>
|
||||
/// <returns>明细记录</returns>
|
||||
public static Model.Supervise_UnitHazardRegisterItem GetUnitHazardRegisterItemById(string itemId)
|
||||
{
|
||||
return Funs.DB.Supervise_UnitHazardRegisterItem.FirstOrDefault(e => e.UnitHazardRegisterItemId == itemId);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取企业级检查明细列表(使用input对象,返回总数)
|
||||
/// </summary>
|
||||
/// <param name="input">查询条件</param>
|
||||
/// <param name="pageIndex">页码(从0开始)</param>
|
||||
/// <param name="pageSize">每页大小</param>
|
||||
/// <param name="returnAll">是否返回所有数据(不分页)</param>
|
||||
/// <param name="totalCount">总记录数</param>
|
||||
/// <returns>检查明细列表</returns>
|
||||
public static List<UnitHazardRegisterItemOutput> GetUnitHazardRegisterItems(
|
||||
UnitHazardRegisterItemInput input,
|
||||
int pageIndex,
|
||||
int pageSize,
|
||||
bool returnAll,
|
||||
out int totalCount)
|
||||
{
|
||||
var db = Funs.DB;
|
||||
var query = from i in db.Supervise_UnitHazardRegisterItem
|
||||
join r in db.Supervise_UnitHazardRegister
|
||||
on i.UnitHazardRegisterId equals r.UnitHazardRegisterId
|
||||
join ct in db.Base_SuperviseCheckType
|
||||
on new { MainType = r.CheckMainType, TypeCode = r.CheckType }
|
||||
equals new { MainType = ct.CheckMainType, TypeCode = ct.CheckTypeCode } into ctGroup
|
||||
from ct in ctGroup.DefaultIfEmpty()
|
||||
join u in db.Base_Unit
|
||||
on r.CheckUnitId equals u.UnitId into uGroup
|
||||
from u in uGroup.DefaultIfEmpty()
|
||||
join user in db.Person_Persons on r.InsResponsibleUserId equals user.PersonId into userGroup
|
||||
from user in userGroup.DefaultIfEmpty()
|
||||
select new UnitHazardRegisterItemOutput
|
||||
{
|
||||
UnitHazardRegisterItemId = i.UnitHazardRegisterItemId,
|
||||
UnitHazardRegisterCode = r.UnitHazardRegisterCode,
|
||||
CheckDate = r.CheckDate,
|
||||
CheckMainTypeName = r.CheckMainType == "0" ? "安全" : "质量",
|
||||
CheckTypeName = ct.CheckTypeName,
|
||||
ProblemDescription = i.ProblemDescription,
|
||||
ProblemType = i.ProblemType,
|
||||
RiskLevel = i.RiskLevel,
|
||||
RectifyRequirement = i.RectifyRequirement,
|
||||
StatesName = UnitHazardRegisterService.ConvertState(r.States.Value),
|
||||
CheckTeam = r.CheckTeam,
|
||||
ProjectId = r.ProjectId,
|
||||
CheckUnitName = u.UnitName,
|
||||
States = r.States,
|
||||
ProblemStatesName = i.CompleteStatus==1 ? "已整改":"未整改",
|
||||
ProblemStates = i.CompleteStatus,
|
||||
InsResponsibleUserId = r.InsResponsibleUserId,
|
||||
InsResponsibleUserName= user.PersonName
|
||||
};
|
||||
|
||||
// 应用检查大类过滤
|
||||
if (input != null && !string.IsNullOrEmpty(input.CheckMainType))
|
||||
{
|
||||
query = query.Where(x => x.CheckMainTypeName.Contains(input.CheckMainType == "0" ? "安全" : "质量"));
|
||||
}
|
||||
// 项目id过滤
|
||||
if (input != null && !string.IsNullOrEmpty(input.ProjectId))
|
||||
{
|
||||
query = query.Where(x => x.ProjectId.Contains(input.ProjectId));
|
||||
}
|
||||
// 检查组/人搜索
|
||||
if (input != null && !string.IsNullOrEmpty(input.CheckTeam))
|
||||
{
|
||||
query = query.Where(x => x.CheckTeam.Contains(input.CheckTeam));
|
||||
}
|
||||
|
||||
// 检查类别搜索
|
||||
if (input != null && !string.IsNullOrEmpty(input.CheckType))
|
||||
{
|
||||
query = query.Where(x => x.CheckTypeName != null && x.CheckTypeName.Contains(input.CheckType));
|
||||
}
|
||||
|
||||
// 问题描述搜索
|
||||
if (input != null && !string.IsNullOrEmpty(input.Problem))
|
||||
{
|
||||
query = query.Where(x => x.ProblemDescription.Contains(input.Problem));
|
||||
}
|
||||
|
||||
// 检查时间范围
|
||||
if (input != null && input.StartTime.HasValue)
|
||||
{
|
||||
query = query.Where(x => x.CheckDate >= input.StartTime.Value);
|
||||
}
|
||||
|
||||
if (input != null && input.EndTime.HasValue)
|
||||
{
|
||||
query = query.Where(x => x.CheckDate <= input.EndTime.Value);
|
||||
}
|
||||
|
||||
// 风险级别过滤
|
||||
if (input != null && !string.IsNullOrEmpty(input.RiskLevel) && input.RiskLevel != "null")
|
||||
{
|
||||
query = query.Where(x => x.RiskLevel == input.RiskLevel);
|
||||
}
|
||||
|
||||
// 状态过滤
|
||||
if (input != null && input.States != null)
|
||||
{
|
||||
query = query.Where(x => x.States == input.States);
|
||||
}
|
||||
// 问题整改状态过滤
|
||||
if (input != null && input.ProblemStates != null)
|
||||
{
|
||||
query = query.Where(x => x.ProblemStates == input.ProblemStates);
|
||||
}
|
||||
// 单位权限过滤
|
||||
if (input != null && !string.IsNullOrEmpty(input.UnitId))
|
||||
{
|
||||
var thisUnit = BLL.CommonService.GetIsThisUnit();
|
||||
if (thisUnit.UnitId != input.UnitId)
|
||||
{
|
||||
// 先获取用户有权限的项目ID列表
|
||||
var projectIds = (from p in Funs.DB.Base_Project
|
||||
where p.UnitId == input.UnitId
|
||||
select p.ProjectId).ToList();
|
||||
|
||||
// 过滤查询结果
|
||||
query = query.Where(x => Funs.DB.Supervise_UnitHazardRegister
|
||||
.Any(r => Funs.DB.Supervise_UnitHazardRegisterItem
|
||||
.Any(i => i.UnitHazardRegisterItemId == x.UnitHazardRegisterItemId &&
|
||||
i.UnitHazardRegisterId == r.UnitHazardRegisterId &&
|
||||
projectIds.Contains(r.ProjectId))));
|
||||
}
|
||||
}
|
||||
|
||||
// 获取总数
|
||||
totalCount = query.Count();
|
||||
|
||||
// 排序和分页
|
||||
var orderedQuery = query.OrderByDescending(x => x.CheckDate);
|
||||
|
||||
if (returnAll)
|
||||
{
|
||||
return orderedQuery.ToList();
|
||||
}
|
||||
|
||||
return orderedQuery
|
||||
.Skip(pageIndex * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新明细记录
|
||||
/// </summary>
|
||||
/// <param name="item">明细记录</param>
|
||||
public static void UpdateUnitHazardRegisterItem(Model.Supervise_UnitHazardRegisterItem item)
|
||||
{
|
||||
Model.Supervise_UnitHazardRegisterItem oldItem =
|
||||
Funs.DB.Supervise_UnitHazardRegisterItem.FirstOrDefault(e => e.UnitHazardRegisterItemId == item.UnitHazardRegisterItemId);
|
||||
if (oldItem != null)
|
||||
{
|
||||
oldItem.ProblemDescription = item.ProblemDescription;
|
||||
oldItem.ProblemType = item.ProblemType;
|
||||
oldItem.RiskLevel = item.RiskLevel;
|
||||
oldItem.RectifyRequirement = item.RectifyRequirement;
|
||||
oldItem.CompleteStatus = item.CompleteStatus;
|
||||
oldItem.CompletedDate = item.CompletedDate;
|
||||
oldItem.SortIndex = item.SortIndex;
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
using System;
|
||||
using Model;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
/// <summary>
|
||||
/// 企业级检查主表服务
|
||||
/// </summary>
|
||||
public static class UnitHazardRegisterService
|
||||
{
|
||||
#region Fields
|
||||
|
||||
public static Dictionary<string, int> StateMap = new Dictionary<string, int>
|
||||
{
|
||||
{ "待提交" ,(int)StateInt.待提交},
|
||||
{ "待整改" ,(int)StateInt.待整改},
|
||||
{ "部分整改" ,(int)StateInt.部分整改},
|
||||
{ "已闭环" ,(int)StateInt.已闭环},
|
||||
};
|
||||
|
||||
#endregion Fields
|
||||
|
||||
#region Enums
|
||||
|
||||
public enum StateInt : int
|
||||
{
|
||||
待提交 = 0,
|
||||
待整改= 1,
|
||||
部分整改 = 2,
|
||||
已闭环 = 3,
|
||||
}
|
||||
|
||||
#endregion Enums
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// 添加企业级检查记录
|
||||
/// </summary>
|
||||
/// <param name="register">企业级检查记录</param>
|
||||
public static void AddUnitHazardRegister(Model.Supervise_UnitHazardRegister register)
|
||||
{
|
||||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||||
{
|
||||
Model.Supervise_UnitHazardRegister newRegister = new Model.Supervise_UnitHazardRegister
|
||||
{
|
||||
UnitHazardRegisterId = register.UnitHazardRegisterId,
|
||||
UnitHazardRegisterCode = register.UnitHazardRegisterCode,
|
||||
CheckDate = register.CheckDate,
|
||||
CheckMainType = register.CheckMainType,
|
||||
CheckType = register.CheckType,
|
||||
ProjectId = register.ProjectId,
|
||||
CheckUnitId = register.CheckUnitId,
|
||||
CheckTeam = register.CheckTeam,
|
||||
CheckManIds = register.CheckManIds,
|
||||
CheckManNames = register.CheckManNames,
|
||||
InsResponsibleUserId = register.InsResponsibleUserId,
|
||||
EvaluationResult = register.EvaluationResult,
|
||||
AttachUrl = register.AttachUrl,
|
||||
States = register.States??0,
|
||||
CompileMan = register.CompileMan,
|
||||
CreateDate = DateTime.Now
|
||||
};
|
||||
db.Supervise_UnitHazardRegister.InsertOnSubmit(newRegister);
|
||||
db.SubmitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public static string ConvertState(int state)
|
||||
{
|
||||
string result = string.Empty;
|
||||
result = StateMap.First(c => c.Value == state).Key;
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除企业级检查记录
|
||||
/// </summary>
|
||||
/// <param name="registerId">检查记录ID</param>
|
||||
public static void DeleteUnitHazardRegisterById(string registerId)
|
||||
{
|
||||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||||
{
|
||||
var register = db.Supervise_UnitHazardRegister.FirstOrDefault(e => e.UnitHazardRegisterId == registerId);
|
||||
if (register != null)
|
||||
{
|
||||
// 删除附件
|
||||
if (!string.IsNullOrEmpty(register.AttachUrl))
|
||||
{
|
||||
BLL.UploadFileService.DeleteFile(Funs.AttachRootPath, register.AttachUrl);
|
||||
}
|
||||
// 删除编码记录
|
||||
BLL.CodeRecordsService.DeleteCodeRecordsByDataId(registerId);
|
||||
// 删除附件
|
||||
BLL.CommonService.DeleteAttachFileById(registerId);
|
||||
// 删除流程
|
||||
BLL.CommonService.DeleteFlowOperateByID(registerId);
|
||||
|
||||
db.Supervise_UnitHazardRegister.DeleteOnSubmit(register);
|
||||
db.SubmitChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据项目和时间段获取检查数量
|
||||
/// </summary>
|
||||
/// <param name="projectId">项目ID</param>
|
||||
/// <param name="startTime">开始时间</param>
|
||||
/// <param name="endTime">结束时间</param>
|
||||
/// <returns>检查数量</returns>
|
||||
public static int GetCount(string projectId, DateTime startTime, DateTime endTime)
|
||||
{
|
||||
return (from x in Funs.DB.Supervise_UnitHazardRegister
|
||||
where x.ProjectId == projectId && x.CheckDate >= startTime && x.CheckDate <= endTime
|
||||
select x).Count();
|
||||
}
|
||||
public static int GetCount(string checkMainType)
|
||||
{
|
||||
return (from x in Funs.DB.Supervise_UnitHazardRegister
|
||||
where x.CheckMainType ==checkMainType
|
||||
select x.UnitHazardRegisterId).Count();
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据ID获取企业级检查记录
|
||||
/// </summary>
|
||||
/// <param name="registerId">检查记录ID</param>
|
||||
/// <returns>企业级检查记录</returns>
|
||||
public static Model.Supervise_UnitHazardRegister GetUnitHazardRegisterById(string registerId)
|
||||
{
|
||||
return Funs.DB.Supervise_UnitHazardRegister.FirstOrDefault(e => e.UnitHazardRegisterId == registerId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否可以删除检查记录
|
||||
/// </summary>
|
||||
/// <param name="registerId">检查记录ID</param>
|
||||
/// <returns>true=可以删除,false=不能删除</returns>
|
||||
public static bool CanDeleteRegister(string registerId)
|
||||
{
|
||||
var register = GetUnitHazardRegisterById(registerId);
|
||||
if (register == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// 只有"待提交"状态可以删除,其他状态不能删除
|
||||
return register.States <= (int)StateInt.待提交;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取企业级检查列表(使用input对象,返回总数)
|
||||
/// </summary>
|
||||
/// <param name="input">查询条件</param>
|
||||
/// <param name="pageIndex">页码(从0开始)</param>
|
||||
/// <param name="pageSize">每页大小</param>
|
||||
/// <param name="returnAll">是否返回所有数据(不分页)</param>
|
||||
/// <param name="totalCount">总记录数</param>
|
||||
/// <returns>检查记录列表</returns>
|
||||
public static List<UnitHazardRegisterOutput> GetUnitHazardRegisters(
|
||||
UnitHazardRegisterInput input,
|
||||
int pageIndex,
|
||||
int pageSize,
|
||||
bool returnAll,
|
||||
out int totalCount)
|
||||
{
|
||||
var db = Funs.DB;
|
||||
// 使用JOIN一次性获取所有数据,解决N+1查询问题
|
||||
var query = from x in db.Supervise_UnitHazardRegister
|
||||
join ct in db.Base_SuperviseCheckType
|
||||
on new { MainType = x.CheckMainType, TypeCode = x.CheckType }
|
||||
equals new { MainType = ct.CheckMainType, TypeCode = ct.CheckTypeCode } into ctGroup
|
||||
from ct in ctGroup.DefaultIfEmpty()
|
||||
join u in db.Base_Unit
|
||||
on x.CheckUnitId equals u.UnitId into uGroup
|
||||
from u in uGroup.DefaultIfEmpty()
|
||||
join p in db.Base_Project on x.ProjectId equals p.ProjectId into pGroup
|
||||
from p in pGroup.DefaultIfEmpty()
|
||||
select new UnitHazardRegisterOutput
|
||||
{
|
||||
UnitHazardRegisterId = x.UnitHazardRegisterId,
|
||||
UnitHazardRegisterCode = x.UnitHazardRegisterCode,
|
||||
CheckDate = x.CheckDate,
|
||||
ProjectId = x.ProjectId,
|
||||
CheckMainTypeName = x.CheckMainType == "0" ? "安全" : "质量",
|
||||
CheckType = x.CheckType,
|
||||
CheckTypeName = ct.CheckTypeName,
|
||||
CheckObjectText = p.ProjectName,
|
||||
CheckUnitName = u.UnitName,
|
||||
CheckTeam = x.CheckTeam,
|
||||
EvaluationResult = x.EvaluationResult,
|
||||
StatesName = ConvertState(x.States.Value),
|
||||
AttachUrl = x.AttachUrl,
|
||||
};
|
||||
|
||||
// 应用检查大类过滤
|
||||
if (input != null && !string.IsNullOrEmpty(input.CheckMainType))
|
||||
{
|
||||
query = query.Where(x => x.CheckMainTypeName.Contains(input.CheckMainType == "0" ? "安全" : "质量"));
|
||||
}
|
||||
|
||||
// 应用文本搜索
|
||||
if (input != null && !string.IsNullOrEmpty(input.SearchText))
|
||||
{
|
||||
query = query.Where(x => x.UnitHazardRegisterCode.Contains(input.SearchText) ||
|
||||
x.CheckObjectText.Contains(input.SearchText) ||
|
||||
x.CheckTeam.Contains(input.SearchText) ||
|
||||
x.EvaluationResult.Contains(input.SearchText));
|
||||
}
|
||||
|
||||
// 应用检查类别过滤
|
||||
if (input != null && !string.IsNullOrEmpty(input.CheckType) && input.CheckType != BLL.Const._Null)
|
||||
{
|
||||
query = query.Where(x => x.CheckType == input.CheckType);
|
||||
}
|
||||
|
||||
// 项目权限过滤
|
||||
if (input != null && !string.IsNullOrEmpty(input.ProjectId))
|
||||
{
|
||||
query = query.Where(x => x.ProjectId != null && x.ProjectId == input.ProjectId);
|
||||
}
|
||||
|
||||
// 获取总数
|
||||
totalCount = query.Count();
|
||||
|
||||
// 排序和分页
|
||||
var orderedQuery = query.OrderByDescending(x => x.CheckDate);
|
||||
|
||||
if (returnAll)
|
||||
{
|
||||
return orderedQuery.ToList();
|
||||
}
|
||||
|
||||
return orderedQuery
|
||||
.Skip(pageIndex * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新企业级检查记录
|
||||
/// </summary>
|
||||
/// <param name="register">企业级检查记录</param>
|
||||
public static void UpdateUnitHazardRegister(Model.Supervise_UnitHazardRegister register)
|
||||
{
|
||||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||||
{
|
||||
Model.Supervise_UnitHazardRegister newRegister =
|
||||
db.Supervise_UnitHazardRegister.FirstOrDefault(e => e.UnitHazardRegisterId == register.UnitHazardRegisterId);
|
||||
if (newRegister != null)
|
||||
{
|
||||
newRegister.UnitHazardRegisterCode = register.UnitHazardRegisterCode;
|
||||
newRegister.CheckDate = register.CheckDate;
|
||||
newRegister.CheckMainType = register.CheckMainType;
|
||||
newRegister.CheckType = register.CheckType;
|
||||
newRegister.ProjectId = register.ProjectId;
|
||||
newRegister.CheckUnitId = register.CheckUnitId;
|
||||
newRegister.CheckTeam = register.CheckTeam;
|
||||
newRegister.CheckManIds = register.CheckManIds;
|
||||
newRegister.CheckManNames = register.CheckManNames;
|
||||
newRegister.EvaluationResult = register.EvaluationResult;
|
||||
newRegister.AttachUrl = register.AttachUrl;
|
||||
newRegister.States = register.States;
|
||||
newRegister.InsResponsibleUserId = register.InsResponsibleUserId;
|
||||
newRegister.UpdateDate = DateTime.Now;
|
||||
db.SubmitChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新主单状态(根据明细的整改情况)
|
||||
/// </summary>
|
||||
public static void UpdateRegisterStatus(string registerId)
|
||||
{
|
||||
// 获取主单的所有明细的整改状态
|
||||
int rectifyStatus = BLL.UnitHazardRegisterItemService.GetRectifyStatus(registerId);
|
||||
|
||||
var register = BLL.UnitHazardRegisterService.GetUnitHazardRegisterById(registerId);
|
||||
if (register != null)
|
||||
{
|
||||
// 根据整改状态更新主单状态
|
||||
switch (rectifyStatus)
|
||||
{
|
||||
case 0: // 全部未整改
|
||||
register.States = (int)UnitHazardRegisterService.StateInt.待整改; // 待整改
|
||||
break;
|
||||
case 1: // 部分整改
|
||||
register.States = (int)UnitHazardRegisterService.StateInt.部分整改; ; // 待整改
|
||||
break;
|
||||
case 2: // 全部整改
|
||||
register.States = (int)UnitHazardRegisterService.StateInt.已闭环; ; // 已完成
|
||||
break;
|
||||
}
|
||||
|
||||
BLL.UnitHazardRegisterService.UpdateUnitHazardRegister(register);
|
||||
}
|
||||
}
|
||||
#endregion Methods
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user