年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

427 lines
13 KiB

using KGIS.Framework.ThreadManager;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.PluginServiceInterface;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace Kingo.Plugin.DataCheck
{
public abstract class DataCheckHelper : BaseNotifyProperty, IStartCheck, ICheckStatistic
{
public string ActiveTitle { get; set; }
public string DataCheckName { get; set; }
public virtual List<DataCheckRuleGroup> CheckGroup { get; set; }
public abstract int ErrorNum { get; }
public abstract int WaringNum { get; }
public abstract int ExceptionNum { get; }
public EnumCheckState CheckState
{
get
{
if (CheckGroup.FirstOrDefault(f => f.CheckState == EnumCheckState.) != null)
return EnumCheckState.;
List<DataCheckRuleGroup> all = CheckGroup.FindAll(f => f.CheckState == EnumCheckState.);
List<DataCheckRuleGroup> all2 = CheckGroup.FindAll(f => f.IsChecked);
if (all != null && all2 != null && all.Count == all2.Count)
{
return EnumCheckState.;
}
return EnumCheckState.;
}
}
public List<DataCheckResult> CheckResults
{
get { return CheckGroup.SelectMany(s => s.CheckResults).ToList(); }
}
public void StartCheck(object pParm)
{
foreach (var group in CheckGroup)
{
if (group.IsChecked)
group.StartCheck(pParm);
}
}
public void StartCheckForThread(object pParam)
{
try
{
bool ischeck = false;
foreach (var item in CheckGroup)
{
var checkCount = item.CheckRules.Where(x => x.IsChecked == true).ToList();
if (checkCount.Count > 0)
{
ischeck = true;
break;
}
}
if (ischeck)
{
foreach (var group in CheckGroup)
{
if (!group.IsChecked) continue;
var checkCount = group.CheckRules.Where(x => x.IsChecked == true).ToList();
if (checkCount.Count == 0) continue;
ActiveTitle = $"正在进行【{group.GroupName}】数据检查……";
base.NotifyProperty(this, "ActiveTitle");
group.StartCheckForThread(pParam);
ActiveTitle = $"【{group.GroupName}】检查完成.";
base.NotifyProperty(this, "ActiveTitle");
}
MessageHelper.ShowTips(ActiveTitle);
}
else
{
ActiveTitle = "请选择检查规则.";
base.NotifyProperty(this, "ActiveTitle");
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
}
/// <summary>
/// 加载视图数据
/// </summary>
/// <param name="pParm"></param>
public void StartLoadData(object pParm)
{
foreach (var group in CheckGroup)
{
group.StartLoadData(pParm);
}
}
public void StartRepair(object pParm)
{
bool ischeck = false;
foreach (var item in CheckGroup)
{
var checkCount = item.CheckRules.Where(x => x.IsChecked == true).ToList();
if (checkCount.Count > 0)
{
ischeck = true;
break;
}
}
if (ischeck)
{
foreach (var group in CheckGroup)
{
if (group.IsChecked)
{
var checkCount = group.CheckRules.Where(x => x.IsChecked == true).ToList();
if (checkCount.Count == 0) continue;
ActiveTitle = "正在进行数据修复……";
base.NotifyProperty(this, "ActiveTitle");
group.StartRepair(pParm);
}
}
ActiveTitle = "数据修复完成.";
base.NotifyProperty(this, "ActiveTitle");
}
else
{
ActiveTitle = "请选择检查规则.";
base.NotifyProperty(this, "ActiveTitle");
}
}
public void StartSingleRepair(object pParm)
{
foreach (var group in CheckGroup)
{
group.StartRepair(pParm);
}
}
}
public interface IStartCheck : IDataRepair
{
void StartCheck(object pParm);
void StartCheckForThread(object pParam);
}
public interface IDataRepair
{
void StartRepair(object pParm);
void StartSingleRepair(object pParm);
}
/// <summary>
/// 检查统计接口
/// </summary>
public interface ICheckStatistic
{
int ErrorNum { get; }
int WaringNum { get; }
int ExceptionNum { get; }
List<DataCheckResult> CheckResults { get; }
}
/// <summary>
/// 规则接口
/// </summary>
public interface IRule : ICheckStatistic, IStartCheck
{
string RuleName { get; set; }
string RuleDesc { get; set; }
bool IsChecked { get; set; }
EnumCheckState CheckState { get; set; }
}
/// <summary>
/// 检查规则分组
/// </summary>
public abstract class DataCheckRuleGroup : BaseNotifyProperty, ICheckStatistic, IStartCheck
{
private bool _IsChecked = true;
public bool IsChecked
{
get => _IsChecked;
set
{
_IsChecked = value;
base.NotifyProperty(this, "IsChecked");
}
}
public virtual string GroupName { get; set; }
public virtual string GroupDesc { get; set; }
public List<DataCheckRule> CheckRules { get; set; }
public DataCheckRule CurrentCheckingRule { get; set; }
public int ErrorNum
{
get
{
lock (CheckRules)
{
return CheckRules.Sum(s => s.ErrorNum);
}
}
}
public int WaringNum
{
get
{
return CheckRules.Sum(s => s.WaringNum);
}
}
public int ExceptionNum
{
get
{
return CheckRules.Sum(s => s.ExceptionNum);
}
}
public EnumCheckState CheckState
{
get
{
if (CheckRules.FirstOrDefault(f => f.CheckState == EnumCheckState.) != null)
return EnumCheckState.;
List<DataCheckRule> all = CheckRules.FindAll(f => f.CheckState == EnumCheckState.);
List<DataCheckRule> all2 = CheckRules.FindAll(f => f.IsChecked);
if (all != null && all2 != null && all.Count == all2.Count)
{
return EnumCheckState.;
}
return EnumCheckState.;
}
}
public List<DataCheckResult> CheckResults
{
get
{
return CheckRules.SelectMany(s => s.CheckResults).ToList();
}
}
public DataCheckRuleGroup()
{
CheckRules = new List<DataCheckRule>();
}
public void StartCheck(object pParm)
{
foreach (var item in CheckRules)
{
if (!item.IsChecked) continue;
item.CheckResults.Clear();
item.StartCheck(pParm);
UpdateInfo(null);
base.NotifyProperty(this, "CheckResults");
}
}
public void StartLoadData(object pParm)
{
//foreach (var item in CheckRules)
//{
// item.CheckResults.Clear();
// item.StartLoadData(pParm);
// //UpdateInfo(null);
// //base.NotifyProperty(this, "CheckResults");
//}
foreach (var item in CheckRules)
{
//if (!item.IsChecked) continue;
//if (CurrentCheckingRule == null)
// CurrentCheckingRule = item;
item.CheckResults.Clear();
ThreadManager2.QueueUserWorkItem(new System.Threading.WaitCallback(item.StartLoadData), item, new System.Threading.WaitCallback(UpdateInfo));
//CurrentCheckingRule = item;
//base.NotifyProperty(this, "CurrentCheckingRule");
//UpdateInfo(item);
}
}
public abstract void UpdateInfo(object obj);
public void StartRepair(object pParm)
{
foreach (var item in CheckRules)
{
item.CheckResults.Clear();
item.StartRepair(pParm);
UpdateInfo(null);
base.NotifyProperty(this, "CheckResults");
}
}
public void StartSingleRepair(object pParm)
{
//foreach (var item in CheckRules)
//{
// item.CheckResults.Clear();
// item.StartRepair(pParm);
// UpdateInfo(null);
// //base.NotifyProperty(this, "CheckResults");
//}
}
public void StartCheckForThread(object pParam)
{
try
{
foreach (var item in CheckRules)
{
if (!item.IsChecked) continue;
item.CheckResults.Clear();
UpdateInfo(null);
item.StartCheck(pParam);
UpdateInfo(null);
//ThreadManager2.QueueUserWorkItem(new System.Threading.WaitCallback(item.StartCheck), item, new System.Threading.WaitCallback(UpdateInfo));
}
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
}
}
}
/// <summary>
/// 数据检查规则
/// </summary>
public abstract class DataCheckRule : BaseNotifyProperty, IRule
{
#region 属性
public virtual string RuleName { get; set; }
public virtual string RuleDesc { get; set; }
//public bool IsChecked { get; set; }
private bool _IsChecked = true;
public bool IsChecked
{
get => _IsChecked;
set
{
_IsChecked = value;
base.NotifyProperty(this, "IsChecked");
}
}
/// <summary>
/// 错误个数
/// </summary>
public int ErrorNum
{
get
{
lock (this)
{
return CheckResults.Count(c => c.ErrorType == EnumErrorType.);
}
}
}
/// <summary>
/// 警告个数
/// </summary>
public int WaringNum
{
get
{
lock (CheckResults)
{
return CheckResults.Count(c => c.ErrorType == EnumErrorType.);
}
}
}
/// <summary>
/// 例外个数
/// </summary>
public int ExceptionNum
{
get
{
lock (CheckResults)
{
return CheckResults.Count(c => c.ErrorType == EnumErrorType.);
}
}
}
public List<DataCheckResult> CheckResults { get; }
public EnumCheckState CheckState { get; set; }
#endregion
public DataCheckRule()
{
CheckResults = new List<DataCheckResult>();
IsChecked = true;
CheckState = EnumCheckState.;
}
public abstract void StartCheck(object pParm);
public abstract void StartCheckForThread(object pParam);
public abstract void StartLoadData(object pParm);
public abstract void StartRepair(object pParm);
public abstract void StartSingleRepair(object pParm);
}
public enum EnumCheckState
{
= 0,
= 1,
= 2,
= 3,
= 4
}
public class BaseNotifyProperty : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyProperty(object obj, string PropertyName)
{
PropertyChanged?.Invoke(obj, new PropertyChangedEventArgs(PropertyName));
}
}
}