214 lines
8.2 KiB
C#
214 lines
8.2 KiB
C#
|
|
using System;
|
||
|
|
using Model;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Linq;
|
||
|
|
|
||
|
|
namespace BLL
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 安全不符合项清单
|
||
|
|
/// </summary>
|
||
|
|
public static class CheckProblemSafetyService
|
||
|
|
{
|
||
|
|
#region Fields
|
||
|
|
|
||
|
|
public static Dictionary<string, int> StateMap = new Dictionary<string, int>
|
||
|
|
{
|
||
|
|
{ "整改中" ,(int)StateInt.整改中},
|
||
|
|
{ "已闭环" ,(int)StateInt.已闭环},
|
||
|
|
};
|
||
|
|
|
||
|
|
#endregion Fields
|
||
|
|
|
||
|
|
#region Enums
|
||
|
|
|
||
|
|
public enum StateInt : int
|
||
|
|
{
|
||
|
|
整改中 = 1,
|
||
|
|
已闭环 = 0
|
||
|
|
}
|
||
|
|
|
||
|
|
#endregion Enums
|
||
|
|
|
||
|
|
#region Methods
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 根据ID获取检查记录
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="checkId">检查记录ID</param>
|
||
|
|
/// <returns>检查记录</returns>
|
||
|
|
public static Model.CheckProblem_Safety GetCheckProblemById(string checkId)
|
||
|
|
{
|
||
|
|
return Funs.DB.CheckProblem_Safety.FirstOrDefault(e => e.CheckId == checkId);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 添加检查记录
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="model">检查记录</param>
|
||
|
|
public static void AddCheckProblem(Model.CheckProblem_Safety model)
|
||
|
|
{
|
||
|
|
using (Model.CNPCDB db = new Model.CNPCDB(Funs.ConnString))
|
||
|
|
{
|
||
|
|
Model.CheckProblem_Safety newModel = new Model.CheckProblem_Safety
|
||
|
|
{
|
||
|
|
CheckId = model.CheckId,
|
||
|
|
UnitId = model.UnitId,
|
||
|
|
UnitName = model.UnitName,
|
||
|
|
ProjectId = model.ProjectId,
|
||
|
|
ProjectName = model.ProjectName,
|
||
|
|
State = model.State,
|
||
|
|
Address = model.Address,
|
||
|
|
Description = model.Description,
|
||
|
|
UnitType = model.UnitType,
|
||
|
|
AssemblyName = model.AssemblyName,
|
||
|
|
//CheckUserId = model.CheckUserId,
|
||
|
|
//CheckUserName = model.CheckUserName,
|
||
|
|
CheckTeamUser = model.CheckTeamUser,
|
||
|
|
CheckDate = model.CheckDate,
|
||
|
|
LimitDate = model.LimitDate,
|
||
|
|
CloseTime = model.CloseTime,
|
||
|
|
RectificationUserId = model.RectificationUserId,
|
||
|
|
RectificationUserName = model.RectificationUserName,
|
||
|
|
PMUserId = model.PMUserId,
|
||
|
|
PMUserName = model.PMUserName,
|
||
|
|
ClassifyId = model.ClassifyId,
|
||
|
|
ClassifyItemId = model.ClassifyItemId,
|
||
|
|
NatureId = model.NatureId,
|
||
|
|
NatureItemId = model.NatureItemId,
|
||
|
|
AttachUrl = model.AttachUrl,
|
||
|
|
RectificationUrl = model.RectificationUrl,
|
||
|
|
Remark = model.Remark,
|
||
|
|
CompileMan = model.CompileMan,
|
||
|
|
CompileManName = model.CompileManName,
|
||
|
|
CompileDate = DateTime.Now
|
||
|
|
};
|
||
|
|
db.CheckProblem_Safety.InsertOnSubmit(newModel);
|
||
|
|
db.SubmitChanges();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 更新检查记录
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="model">检查记录</param>
|
||
|
|
public static void UpdateCheckProblem(Model.CheckProblem_Safety model)
|
||
|
|
{
|
||
|
|
using (Model.CNPCDB db = new Model.CNPCDB(Funs.ConnString))
|
||
|
|
{
|
||
|
|
Model.CheckProblem_Safety newModel = db.CheckProblem_Safety.FirstOrDefault(e => e.CheckId == model.CheckId);
|
||
|
|
if (newModel != null)
|
||
|
|
{
|
||
|
|
newModel.CheckDate = model.CheckDate;
|
||
|
|
newModel.UnitId = model.UnitId;
|
||
|
|
newModel.UnitName = model.UnitName;
|
||
|
|
newModel.ProjectId = model.ProjectId;
|
||
|
|
newModel.ProjectName = model.ProjectName;
|
||
|
|
newModel.State = model.State;
|
||
|
|
newModel.Address = model.Address;
|
||
|
|
newModel.Description = model.Description;
|
||
|
|
newModel.UnitType = model.UnitType;
|
||
|
|
newModel.AssemblyName = model.AssemblyName;
|
||
|
|
//newModel.CheckUserId = model.CheckUserId;
|
||
|
|
//newModel.CheckUserName = model.CheckUserName;
|
||
|
|
newModel.CheckTeamUser = model.CheckTeamUser;
|
||
|
|
newModel.CheckDate = model.CheckDate;
|
||
|
|
newModel.LimitDate = model.LimitDate;
|
||
|
|
newModel.CloseTime = model.CloseTime;
|
||
|
|
newModel.RectificationUserId = model.RectificationUserId;
|
||
|
|
newModel.RectificationUserName = model.RectificationUserName;
|
||
|
|
newModel.PMUserId = model.PMUserId;
|
||
|
|
newModel.PMUserName = model.PMUserName;
|
||
|
|
newModel.ClassifyId = model.ClassifyId;
|
||
|
|
newModel.ClassifyItemId = model.ClassifyItemId;
|
||
|
|
newModel.NatureId = model.NatureId;
|
||
|
|
newModel.NatureItemId = model.NatureItemId;
|
||
|
|
newModel.AttachUrl = model.AttachUrl;
|
||
|
|
newModel.RectificationUrl = model.RectificationUrl;
|
||
|
|
newModel.Remark = model.Remark;
|
||
|
|
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="checkId">检查记录ID</param>
|
||
|
|
public static void DeleteCheckProblemById(string checkId)
|
||
|
|
{
|
||
|
|
using (Model.CNPCDB db = new Model.CNPCDB(Funs.ConnString))
|
||
|
|
{
|
||
|
|
var model = db.CheckProblem_Safety.FirstOrDefault(e => e.CheckId == checkId);
|
||
|
|
if (model != null)
|
||
|
|
{
|
||
|
|
// 删除附件
|
||
|
|
if (!string.IsNullOrEmpty(model.AttachUrl))
|
||
|
|
{
|
||
|
|
BLL.UploadFileService.DeleteFile(Funs.RootPath, model.AttachUrl);
|
||
|
|
}
|
||
|
|
// 删除附件
|
||
|
|
if (!string.IsNullOrEmpty(model.RectificationUrl))
|
||
|
|
{
|
||
|
|
BLL.UploadFileService.DeleteFile(Funs.RootPath, model.RectificationUrl);
|
||
|
|
}
|
||
|
|
//// 删除编码记录
|
||
|
|
//BLL.CodeRecordsService.DeleteCodeRecordsByDataId(checkId);
|
||
|
|
// 删除附件
|
||
|
|
BLL.CommonService.DeleteAttachFileById(checkId);
|
||
|
|
|
||
|
|
db.CheckProblem_Safety.DeleteOnSubmit(model);
|
||
|
|
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.CheckProblem_Safety
|
||
|
|
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.CheckProblem_Safety
|
||
|
|
// where x.CheckMainType == checkMainType
|
||
|
|
// select x.CheckProblemId).Count();
|
||
|
|
//}
|
||
|
|
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 判断是否可以删除检查记录
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="checkId">检查记录ID</param>
|
||
|
|
/// <returns>true=可以删除,false=不能删除</returns>
|
||
|
|
public static bool CanDeleteCheckProblem(string checkId)
|
||
|
|
{
|
||
|
|
var model = GetCheckProblemById(checkId);
|
||
|
|
if (model == null)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
// 只有"整改中"状态可以删除,其他状态不能删除
|
||
|
|
return model.State == (int)StateInt.整改中;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
#endregion Methods
|
||
|
|
}
|
||
|
|
}
|