using System;
using System.Collections.Generic;
using System.Linq;
namespace BLL.OfficeCheck.Inspect
{
public class Inspect_InspectionService
{
///
/// 添加安全专项检查
///
///
public static Model.Inspect_Inspection SaveInspection(Model.Inspect_Inspection Inspection)
{
Model.SGGLDB db = Funs.DB;
int count = (from x in db.Inspect_Inspection where x.InspectType == Inspection.InspectType select x).Count();
if (Inspection.InspectionId == null)
{
Inspection.InspectionId = SQLHelper.GetNewID();
}
Model.Inspect_Inspection newInspection = new Model.Inspect_Inspection
{
InspectionId = Inspection.InspectionId,
InspectionCode = Inspection.InspectType+"-" + count.ToString("D6"),
ProjectId = Inspection.ProjectId,
Description = Inspection.Description,
States = Inspection.States,
CreateMan = Inspection.CreateMan,
CreateTime = DateTime.Today,
CheckMan = Inspection.CheckMan,
PersonResponsible = Inspection.PersonResponsible,
InspectType = Inspection.InspectType,
ProblemTypeId = Inspection.ProblemTypeId,
ProblemTypeName = Inspection.ProblemTypeName,
Place = Inspection.Place,
};
db.Inspect_Inspection.InsertOnSubmit(newInspection);
db.SubmitChanges();
return newInspection;
}
#region 更新专检主项
public static void UpdateInspection(Model.Inspect_Inspection Inspection)
{
Model.SGGLDB db = Funs.DB;
Model.Inspect_Inspection newInspection =
db.Inspect_Inspection.FirstOrDefault(e => e.InspectionId == Inspection.InspectionId);
if (newInspection != null)
{
newInspection.States = Inspection.States;
db.SubmitChanges();
ClosedInspection(Inspection.InspectionId);
}
}
#endregion
#region 根据专项检查ID获取专项信息
public static Object GetInspectionById(string InspectionId)
{
return (from x in Funs.DB.Inspect_Inspection
where x.InspectionId == InspectionId
select new
{
InspectionId = x.InspectionId,
InspectionCode = x.InspectionCode,
ProjectId = x.ProjectId,
ProjectName = (from y in Funs.DB.Base_Project where y.ProjectId == x.ProjectId select y).First().ProjectName,
Description = x.Description,
States = x.States,
PersonResponsible = x.PersonResponsible,
PersonResponsibleName = (from y in Funs.DB.Sys_User where y.UserId == x.PersonResponsible select y.UserName).FirstOrDefault(),
CreateTime = x.CreateTime,
CreateMan = x.CreateMan,
CheckMan = x.CheckMan,
CreateManName = (from y in Funs.DB.Sys_User where y.UserId == x.CreateMan select y.UserName).FirstOrDefault(),
ProblemTypeId = x.ProblemTypeId,
ProblemTypeName = x.ProblemTypeName,
InspectType = x.InspectType,
Place = x.Place,
children = (from a in Funs.DB.Inspect_InspectionItem
where a.InspectionId == x.InspectionId
orderby a.CompileTime descending
select new
{
InspectionItemId = a.InspectionItemId,
InspectionId = a.InspectionId,
ProjectId = a.ProjectId,
BeforelUrl = a.BeforelUrl,
States = a.States,
CompileTime = a.CompileTime,
AfterUrl = a.AfterUrl,
RectificationDate = a.RectificationDate,
EvaluateResults = a.EvaluateResults,
WorkAreaName = a.WorkAreaName,
RectificationDescription = a.RectificationDescription,
ProblemDetial = a.ProblemDetial
}).ToList()
}).FirstOrDefault(e => e.InspectionId == InspectionId);
}
#endregion
///
/// 添加安全专项子项检查
///
///
public static void SaveInspectionItem(Model.Inspect_InspectionItem InspectionItem)
{
Model.SGGLDB db = Funs.DB;
InspectionItem.InspectionItemId = SQLHelper.GetNewID();
Model.Inspect_InspectionItem newInspectionItem = new Model.Inspect_InspectionItem
{
InspectionItemId = InspectionItem.InspectionItemId,
InspectionId = InspectionItem.InspectionId,
ProblemDetial = InspectionItem.ProblemDetial,
ProjectId = InspectionItem.ProjectId,
ProblemTypeId = InspectionItem.ProblemTypeId,
BeforelUrl = InspectionItem.BeforelUrl,
EvaluateResults = InspectionItem.EvaluateResults,
TimeLimited = InspectionItem.TimeLimited,
RectificationDescription = InspectionItem.RectificationDescription,
RectificationResults = InspectionItem.RectificationResults,
States = InspectionItem.States,
CreateMan = InspectionItem.CreateMan,
CompileTime = InspectionItem.CompileTime,
AfterUrl = InspectionItem.AfterUrl,
ResponsiblePersonId = InspectionItem.ResponsiblePersonId,
RectificationDate = InspectionItem.RectificationDate,
Level = InspectionItem.Level,
WorkAreaName = InspectionItem.WorkAreaName,
};
db.Inspect_InspectionItem.InsertOnSubmit(newInspectionItem);
db.SubmitChanges();
ClosedInspection(InspectionItem.InspectionId);
}
#region 专检主项闭环
public static void ClosedInspection(string InspectionId)
{
int count = Funs.DB.Inspect_InspectionItem.Count(x=>x.InspectionId == InspectionId && x.States != "3");
if(count == 0)
{
Model.SGGLDB db = Funs.DB;
Model.Inspect_Inspection newInspection =
db.Inspect_Inspection.FirstOrDefault(e => e.InspectionId == InspectionId);
newInspection.States = "3";
db.SubmitChanges();
}
}
#endregion
#region 获取专检子项详细
public static Object GetInspectItemsById(string InspectionItemId)
{
return (from x in Funs.DB.Inspect_InspectionItem
join y in Funs.DB.Inspect_Inspection on x.InspectionId equals y.InspectionId
//join b in Funs.DB.Technique_Rectify on x.ProblemTypeId equals b.RectifyId
where x.InspectionItemId == InspectionItemId
select new
{
InspectionItemId = x.InspectionItemId,
InspectionId = x.InspectionId,
ProjectId = x.ProjectId,
ProjectName = Funs.DB.Base_Project.FirstOrDefault(p => p.ProjectId == x.ProjectId).ProjectName,
CreateTime = x.CompileTime,
CreateMan = x.CreateMan,
CreateManName = Funs.DB.Sys_User.FirstOrDefault(u => u.UserId == x.CreateMan).UserName,
CheckMan = y.CheckMan,
EvaluateResults = x.EvaluateResults,
WorkAreaName = x.WorkAreaName,
States = x.States,
BeforelUrl = x.BeforelUrl,
RectificationResults = x.RectificationResults,
AfterUrl = x.AfterUrl,
RectificationDate = x.RectificationDate,
InspectionCode = y.InspectionCode,
Description = y.Description,
InspectType = y.InspectType,
ProblemTypeId = y.ProblemTypeId,
ProblemTypeName = y.ProblemTypeName,
Place = y.Place,
ProblemDetial = x.ProblemDetial,
RectificationDescription = x.RectificationDescription,
}
).FirstOrDefault(e => e.InspectionItemId == InspectionItemId);
}
#endregion
///
/// 根据专项检查ID获取专项信息
///
///
///
public static Model.Inspect_Inspection GetInspectionByInspectionId(string InspectionId)
{
return Funs.DB.Inspect_Inspection.FirstOrDefault(e => e.InspectionId == InspectionId);
}
///
/// 修改安全专项检查状态信息
///
///
public static void UpdateInspectionStates(string InspectionId, string States)
{
Model.SGGLDB db = Funs.DB;
Model.Inspect_Inspection newInspection =
db.Inspect_Inspection.FirstOrDefault(e => e.InspectionId == InspectionId);
if (newInspection != null)
{
newInspection.States = States;
db.SubmitChanges();
}
}
///
/// 修改安全专项检查明细
///
///
public static void UpdateInspectionItem(Model.Inspect_InspectionItem InspectionItem)
{
Model.SGGLDB db = Funs.DB;
Model.Inspect_InspectionItem newInspectionItem =
db.Inspect_InspectionItem.FirstOrDefault(e => e.InspectionItemId == InspectionItem.InspectionItemId);
if (newInspectionItem != null)
{
newInspectionItem.InspectionItemId = InspectionItem.InspectionItemId;
newInspectionItem.InspectionId = InspectionItem.InspectionId;
newInspectionItem.EvaluateResults = InspectionItem.EvaluateResults;
newInspectionItem.BeforelUrl = InspectionItem.BeforelUrl;
newInspectionItem.States = InspectionItem.States;
newInspectionItem.RectificationResults = InspectionItem.RectificationResults;
newInspectionItem.AfterUrl = InspectionItem.AfterUrl;
newInspectionItem.AuditTime = InspectionItem.AuditTime;
newInspectionItem.AuditMan = InspectionItem.AuditMan;
newInspectionItem.ProblemDetial = InspectionItem.ProblemDetial;
newInspectionItem.RectificationDescription = InspectionItem.RectificationDescription;
newInspectionItem.BeforelUrl = InspectionItem.BeforelUrl;
newInspectionItem.RectificationResults = InspectionItem.RectificationResults;
newInspectionItem.States = InspectionItem.States;
newInspectionItem.ResponsiblePersonId = InspectionItem.ResponsiblePersonId;
newInspectionItem.RectificationDate = InspectionItem.RectificationDate;
newInspectionItem.WorkAreaName = InspectionItem.WorkAreaName;
db.SubmitChanges();
ClosedInspection(InspectionItem.InspectionId);
}
}
///
/// 根据专项检查ID删除对应专项检查记录信息
///
///
public static void DeleteInspectionById(string InspectionId)
{
Model.SGGLDB db = Funs.DB;
var q = (from x in db.Inspect_Inspection where x.InspectionId == InspectionId select x).FirstOrDefault();
if (q != null)
{
///删除编码表记录
BLL.CodeRecordsService.DeleteCodeRecordsByDataId(q.InspectionId);
////删除附件表
BLL.CommonService.DeleteAttachFileById(q.InspectionId);
////删除审核流程表
BLL.CommonService.DeleteFlowOperateByID(q.InspectionId);
//删除明细
var list = (from x in db.Inspect_InspectionItem where x.InspectionId == InspectionId select x).ToList();
list.ForEach(e => { db.Inspect_InspectionItem.DeleteOnSubmit(e); });
db.Inspect_Inspection.DeleteOnSubmit(q);
}
db.SubmitChanges();
}
///
/// 根据专项明细ID删除对应信息
///
///
public static void DeleteInspectItemsById(string InspectionItemId)
{
Model.SGGLDB db = Funs.DB;
var q = (from x in db.Inspect_InspectionItem where x.InspectionItemId == InspectionItemId select x).FirstOrDefault();
if (q != null)
{
db.Inspect_InspectionItem.DeleteOnSubmit(q);
}
db.SubmitChanges();
}
///
/// 根据专项检查ID删除对应专项检查明细记录信息
///
///
public static void DeleteInspectionItemsByInspectionId(string InspectionId)
{
Model.SGGLDB db = Funs.DB;
var list = (from x in db.Inspect_InspectionItem where x.InspectionId == InspectionId select x).ToList();
list.ForEach(e => { db.Inspect_InspectionItem.DeleteOnSubmit(e); });
db.SubmitChanges();
}
///
/// 获取专检集合
///
///
///
public static List GetInspectionList(string ProjectId,string type, string States, int PageNumber, int PageSize)
{
var getDataLists = (from x in Funs.DB.Inspect_Inspection
select new InspectionDto
{
InspectionId = x.InspectionId,
InspectionCode = x.InspectionCode,
ProjectId = x.ProjectId,
ProjectName = Funs.DB.Base_Project.FirstOrDefault(p=>p.ProjectId == x.ProjectId).ProjectName,
PersonResponsible = x.PersonResponsible,
PersonResponsibleName = Funs.DB.Sys_User.FirstOrDefault(u => u.UserId == x.PersonResponsible).UserName,
Description = x.Description,
States = x.States,
CreateManName = Funs.DB.Sys_User.FirstOrDefault(u=>u.UserId == x.CreateMan).UserName,
CreateMan = x.CreateMan,
CreateTime = x.CreateTime,
CheckMan = x.CheckMan,
InspectType = x.InspectType,
ProblemTypeId = x.ProblemTypeId,
ProblemTypeName = x.ProblemTypeName,
Place = x.Place,
ChildsCount = Funs.DB.Inspect_InspectionItem.Count(itm=>itm.InspectionId == x.InspectionId).ToString()
}).Where(x=> x.InspectType == type);
if (!string.IsNullOrEmpty(ProjectId))
{
getDataLists = getDataLists.Where(q => q.ProjectId == ProjectId);
}
if (!string.IsNullOrEmpty(States))
{
getDataLists = getDataLists.Where(q => q.States == States);
}
if (PageNumber > 0 && PageSize > 0)
{
getDataLists = getDataLists.Skip((PageNumber - 1) * PageSize).Take(PageSize);
}
return getDataLists.ToList();
}
///
/// 获取专检明细集合
///
///
///
public static List GetInspectionItemList(string InspectionId, int PageNumber, int PageSize)
{
List getDataLists = (from x in Funs.DB.Inspect_InspectionItem
join p in Funs.DB.Base_Project on x.ProjectId equals p.ProjectId into project
from pro in project.DefaultIfEmpty()
where x.InspectionId == InspectionId
select new InspectionItemDto
{
//InspectionItemId = x.InspectionItemId,
//InspectionId = x.InspectionId,
//InspectionItemCode = x.InspectionItemCode,
//ProjectId = x.ProjectId,
//ProjectName = pro.ProjectName,
//InspectionDescribe = x.InspectionDescribe,
//PhotoUrl = x.PhotoUrl,
//VideoUrl = x.VideoUrl,
//EvaluateResults = x.EvaluateResults,
//TimeLimited = x.TimeLimited,
//RectificationDescription = x.RectificationDescription,
//RectificationResults = x.RectificationResults,
//States = x.States,
//CompileMan = subUser1.UserName,
//CompileTime = x.CompileTime,
}).ToList();
if (PageNumber > 0 && PageSize > 0)
{
getDataLists = getDataLists.Skip((PageNumber - 1) * PageSize).Take(PageSize).ToList();
}
return getDataLists;
}
///
/// 根据专项检查ID获取专项明细检查信息
///
///
///
public static List GetInspectItemsByInspectionId(string InspectionId)
{
var list = (from x in Funs.DB.Inspect_InspectionItem
where x.InspectionId == InspectionId
orderby x.CompileTime descending
select x).ToList();
return list;
}
public class InspectionDto
{
public string InspectionId
{
get;
set;
}
public string InspectionCode
{
get;
set;
}
public string ProjectId
{
get;
set;
}
public string ProjectName
{
get;
set;
}
public string PersonResponsible
{
get;
set;
}
public string PersonResponsibleName
{
get;
set;
}
public string Description
{
get;
set;
}
public string States
{
get;
set;
}
public string InspectManId
{
get;
set;
}
public string InspectType
{
get;
set;
}
public string CreateMan
{
get;
set;
}
public string CreateManName
{
get;
set;
}
public System.Nullable CreateTime
{
get;
set;
}
public string ProblemTypeId { get; set; }
public string ProblemTypeName { get; set; }
public string Place { get; set; }
public string CheckMan
{
get;
set;
}
public string ChildsCount
{
get;
set;
}
}
public class InspectionItemDto
{
public string InspectionItemId
{
get;
set;
}
public string InspectionId
{
get;
set;
}
public string InspectionItemCode
{
get;
set;
}
public string ProjectId
{
get;
set;
}
public string ProjectName
{
get;
set;
}
public string InspectionDescribe
{
get;
set;
}
public string PhotoUrl
{
get;
set;
}
public string VideoUrl
{
get;
set;
}
public string EvaluateResults
{
get;
set;
}
public System.Nullable TimeLimited
{
get;
set;
}
public string RectificationDescription
{
get;
set;
}
public string RectificationResults
{
get;
set;
}
public string RectificationPhotoUrl
{
get;
set;
}
public string RectificationVideoUrl
{
get;
set;
}
public string States
{
get;
set;
}
public string CompileMan
{
get;
set;
}
public System.Nullable CompileTime
{
get;
set;
}
}
}
}