2023-09-26

This commit is contained in:
2023-09-26 15:20:47 +08:00
parent 1c28e4069e
commit d5d459bf1c
77 changed files with 10228 additions and 3160 deletions
@@ -1,38 +1,39 @@
using FineUIPro;
using Microsoft.SqlServer.Dts.Runtime;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
namespace BLL
{
public static class Project_HJGLData_DefectService
{
public static Model.SGGLDB db = Funs.DB;
public static SGGLDB db = Funs.DB;
#region
/// <summary>
/// 记录数
/// </summary>
public static int count
{
get;
set;
}
public static List<Model.Project_HJGLData_Defect> GetProject_HJGLData_DefectByModle(Model.Project_HJGLData_Defect table)
public static int count { get; set; }
public static List<Project_HJGLData_Defect> GetProject_HJGLData_DefectByModle(Project_HJGLData_Defect table)
{
var q = from x in db.Project_HJGLData_Defect
where
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
(string.IsNullOrEmpty(table.ProjectId) || x.Id.Contains(table.ProjectId)) &&
(string.IsNullOrEmpty(table.UnitId) || x.UnitId.Contains(table.UnitId)) &&
(string.IsNullOrEmpty(table.CollCropCode) || x.CollCropCode.Contains(table.CollCropCode)) &&
(string.IsNullOrEmpty(table.UnitName) || x.UnitName.Contains(table.UnitName)) &&
(string.IsNullOrEmpty(table.DefectName) || x.DefectName.Contains(table.DefectName))
(string.IsNullOrEmpty(table.Id) || x.Id.Contains(table.Id)) &&
(string.IsNullOrEmpty(table.ProjectId) || x.Id.Contains(table.ProjectId)) &&
(string.IsNullOrEmpty(table.UnitId) || x.UnitId.Contains(table.UnitId)) &&
(string.IsNullOrEmpty(table.CollCropCode) || x.CollCropCode.Contains(table.CollCropCode)) &&
(string.IsNullOrEmpty(table.UnitName) || x.UnitName.Contains(table.UnitName)) &&
(string.IsNullOrEmpty(table.DefectName) || x.DefectName.Contains(table.DefectName))
select x
;
;
return q.ToList();
}
@@ -42,53 +43,51 @@ namespace BLL
/// <param name="PageIndex">页码</param>
/// <param name="PageSize">每页数量</param>
/// <returns></returns>
public static IEnumerable getListData(Model.Project_HJGLData_Defect table, Grid Grid1)
public static IEnumerable getListData(Project_HJGLData_Defect table, Grid Grid1)
{
var q = GetProject_HJGLData_DefectByModle(table);
count = q.Count();
if (count == 0)
{
return null;
}
if (count == 0) return null;
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
return from x in q
select new
{
x.Id,
x.ProjectId,
x.UnitId,
x.CollCropCode,
x.UnitName,
x.ReportDate,
x.DefectName,
x.DefectNum,
};
select new
{
x.Id,
x.ProjectId,
x.UnitId,
x.CollCropCode,
x.UnitName,
x.ReportDate,
x.DefectName,
x.DefectNum
};
}
#endregion
public static Model.Project_HJGLData_Defect GetProject_HJGLData_DefectById(string Id)
public static Project_HJGLData_Defect GetProject_HJGLData_DefectById(string Id)
{
return db.Project_HJGLData_Defect.FirstOrDefault(x => x.Id == Id);
}
/// <summary>
/// 获取项目该日期的缺陷分析数据
/// </summary>
/// <param name="reportDate"></param>
/// <param name="projectid"></param>
/// <returns></returns>
public static List<Model.Project_HJGLData_Defect> GetProject_HJGLData_DefectByDate(DateTime? reportDate, string projectid)
public static List<Project_HJGLData_Defect> GetProject_HJGLData_DefectByDate(DateTime? reportDate,
string projectid)
{
var q = from x in db.Project_HJGLData_Defect
where x.ReportDate.Value.Date.CompareTo(reportDate.Value.Date) == 0 && x.ProjectId == projectid
select x;
where x.ReportDate.Value.Date.CompareTo(reportDate.Value.Date) == 0 && x.ProjectId == projectid
select x;
return q.ToList();
}
public static void AddProject_HJGLData_Defect(Model.Project_HJGLData_Defect newtable)
public static void AddProject_HJGLData_Defect(Project_HJGLData_Defect newtable)
{
Model.Project_HJGLData_Defect table = new Model.Project_HJGLData_Defect
var table = new Project_HJGLData_Defect
{
Id = newtable.Id,
ProjectId = newtable.ProjectId,
@@ -97,16 +96,21 @@ namespace BLL
UnitName = newtable.UnitName,
ReportDate = newtable.ReportDate,
DefectName = newtable.DefectName,
DefectNum = newtable.DefectNum,
DefectNum = newtable.DefectNum
};
db.Project_HJGLData_Defect.InsertOnSubmit(table);
db.SubmitChanges();
}
public static void UpdateProject_HJGLData_Defect(Model.Project_HJGLData_Defect newtable)
public static void AddBulkProject_HJGLData_Defect(List<Project_HJGLData_Defect> newtables)
{
db.Project_HJGLData_Defect.InsertAllOnSubmit(newtables);
db.SubmitChanges();
}
Model.Project_HJGLData_Defect table = db.Project_HJGLData_Defect.FirstOrDefault(x => x.Id == newtable.Id);
public static void UpdateProject_HJGLData_Defect(Project_HJGLData_Defect newtable)
{
var table = db.Project_HJGLData_Defect.FirstOrDefault(x => x.Id == newtable.Id);
if (table != null)
{
table.Id = newtable.Id;
@@ -119,31 +123,40 @@ namespace BLL
table.DefectNum = newtable.DefectNum;
db.SubmitChanges();
}
}
public static void DeleteProject_HJGLData_DefectById(string Id)
{
Model.Project_HJGLData_Defect table = db.Project_HJGLData_Defect.FirstOrDefault(x => x.Id == Id);
var table = db.Project_HJGLData_Defect.FirstOrDefault(x => x.Id == Id);
if (table != null)
{
db.Project_HJGLData_Defect.DeleteOnSubmit(table);
db.SubmitChanges();
}
}
public static void DeleteProject_HJGLData_DefectByDate(DateTime? reportDate, string projectid)
{
var table = db.Project_HJGLData_Defect.Where(x => x.ReportDate.Value.Date.CompareTo(reportDate.Value.Date) == 0 && x.ProjectId == projectid);
public static void DeleteProject_HJGLData_DefectByDate(DateTime? reportDate)
{
var table = db.Project_HJGLData_Defect.Where(x =>
x.ReportDate.Value.Date.CompareTo(reportDate.Value.Date) == 0);
if (table != null)
{
db.Project_HJGLData_Defect.DeleteAllOnSubmit(table);
db.SubmitChanges();
}
}
public static void DeleteProject_HJGLData_DefectByDate(DateTime? reportDate, string projectid)
{
var table = db.Project_HJGLData_Defect.Where(x =>
x.ReportDate.Value.Date.CompareTo(reportDate.Value.Date) == 0 && x.ProjectId == projectid);
if (table != null)
{
db.Project_HJGLData_Defect.DeleteAllOnSubmit(table);
db.SubmitChanges();
}
}
/// <summary>
/// 判断当天是否已统计数据
/// </summary>
@@ -152,68 +165,110 @@ namespace BLL
{
var result = false;
var q = (from x in Funs.DB.Project_HJGLData_Defect
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date && x.ProjectId == projectid && x.DefectName == type
select x).ToList();
if (q != null && q.Count > 0)
{
result = true;
}
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date &&
x.ProjectId == projectid && x.DefectName == type
select x).ToList();
if (q != null && q.Count > 0) result = true;
return result;
}
/// <summary>
/// 根据projectid,获取当天的统计后的数据
/// </summary>
/// <param name="projectid"></param>
/// <returns></returns>
public static Model.Project_HJGLData_Defect getTodayProject_HJGLData_Defect(string projectid, string type)
public static Project_HJGLData_Defect getTodayProject_HJGLData_Defect(string projectid, string type)
{
var q = (from x in Funs.DB.Project_HJGLData_Defect
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date && x.ProjectId == projectid && x.DefectName == type
select x).FirstOrDefault();
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date &&
x.ProjectId == projectid && x.DefectName == type
select x).FirstOrDefault();
return q;
}
public static List<Model.HJGLDataDefectItems> getTodayProject_HJGLData_Defect()
public static List<HJGLDataDefectItems> getTodayProject_HJGLData_Defect()
{
var q = (from x in Funs.DB.Project_HJGLData_Defect
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date
group x by x.DefectName into g
select new Model.HJGLDataDefectItems
{
Id = SQLHelper.GetNewID(),
DefectName = g.Key,
DefectNum=g.Sum (p=>p.DefectNum)
}).ToList();
where x.ReportDate < DateTime.Now.AddDays(1).Date && x.ReportDate >= DateTime.Now.Date
group x by x.DefectName
into g
select new HJGLDataDefectItems
{
Id = SQLHelper.GetNewID(),
DefectName = g.Key,
DefectNum = g.Sum(p => p.DefectNum)
}).ToList();
return q;
}
/// <summary>
/// 统计所有在建项目数据
/// </summary>
public static void StatisticalAllProjectData()
{
var projectlist = ProjectService.GetProjectWorkList();
foreach (var item in projectlist)
var db = Funs.DB;
var projectids = ProjectService.GetProjectWorkList().Select(x => x.ProjectId).ToList();
var thisUnitId = string.Empty;
var thisUnit = CommonService.GetIsThisUnit();
if (thisUnit != null) thisUnitId = thisUnit.UnitId;
var baseUnit = UnitService.GetUnitByUnitId(thisUnitId);
var data = (from x in db.CH_CheckItem
join y in db.CH_Check on x.CHT_CheckID equals y.CHT_CheckID
where projectids.Contains(y.ProjectId)
group x by new { x.Defects_Definition, y.ProjectId }
into g
select new
{
UnitId = thisUnitId,
CollCropCode = baseUnit.CollCropCode,
UnitName = baseUnit.UnitName,
ProjectId = g.Key.ProjectId,
ReportDate = DateTime.Now.Date,
DefectName = g.Key.Defects_Definition,
DefectNum = g.Count(x => x.Defects_Definition == g.Key.Defects_Definition)
}).ToList();
DeleteProject_HJGLData_DefectByDate(DateTime.Now.Date); //删除当前所有
var projectHjglDataDefect = new List<Project_HJGLData_Defect>();
foreach (var item in data
)
{
StatisticalData(item.ProjectId);
var table = new Project_HJGLData_Defect
{
Id = SQLHelper.GetNewID(),
UnitId = item.UnitId,
CollCropCode = item.CollCropCode,
UnitName = item.UnitName,
ProjectId = item.ProjectId,
ReportDate = item.ReportDate,
DefectName = item.DefectName,
DefectNum = item.DefectNum
};
projectHjglDataDefect.Add(table);
}
AddBulkProject_HJGLData_Defect(projectHjglDataDefect); //批量增加
}
/// <summary>
/// 统计数据
/// </summary>
/// <param name="projectid"></param>
public static void StatisticalData(string projectid)
{
string thisUnitId = BLL.Const.UnitId_CD;
var base_Unit = BLL.UnitService.GetUnitByUnitId(thisUnitId);
var thisUnitId = string.Empty;
var thisUnit = CommonService.GetIsThisUnit();
if (thisUnit != null) thisUnitId = thisUnit.UnitId;
var base_Unit = UnitService.GetUnitByUnitId(thisUnitId);
var list = from x in db.CH_CheckItem
join y in db.CH_Check on x.CHT_CheckID equals y.CHT_CheckID
where y.ProjectId == projectid
select x;
join y in db.CH_Check on x.CHT_CheckID equals y.CHT_CheckID
where y.ProjectId == projectid
select x;
var types = (from x in list select x.Defects_Definition).Distinct().ToList();
foreach (var t in types)
{
if (!string.IsNullOrEmpty(t))
{
Model.Project_HJGLData_Defect table = new Model.Project_HJGLData_Defect
var table = new Project_HJGLData_Defect
{
UnitId = thisUnitId,
CollCropCode = base_Unit.CollCropCode,
@@ -221,7 +276,7 @@ namespace BLL
ProjectId = projectid,
ReportDate = DateTime.Now.Date,
DefectName = t,
DefectNum = list.Count(x => x.Defects_Definition == t),
DefectNum = list.Count(x => x.Defects_Definition == t)
};
if (IsReportByToday(projectid, t))
{
@@ -234,27 +289,26 @@ namespace BLL
AddProject_HJGLData_Defect(table);
}
}
}
}
/// <summary>
/// 获取缺陷名称
/// </summary>
/// <returns></returns>
public static string GetDefectName(string projectid)
{
string result = "";
var result = "";
return result;
}
/// <summary>
/// 获取缺陷数量
/// </summary>
/// <returns></returns>
public static int GetDefectNum(string projectid)
{
int result = 0;
var result = 0;
return result;
}
}
}