|
|
// ***********************************************************************
|
|
|
// Assembly : Construction
|
|
|
// Author : zjx
|
|
|
// Created : 09-01-2020
|
|
|
//
|
|
|
// Last Modified By : zjx
|
|
|
// Last Modified On : 09-01-2020
|
|
|
// ***********************************************************************
|
|
|
// <copyright file="DataHelp.cs" company="jindongfang">
|
|
|
// Copyright (c) jindongfang. All rights reserved.
|
|
|
// </copyright>
|
|
|
// <summary></summary>
|
|
|
// ***********************************************************************
|
|
|
namespace WellWorkDataUI
|
|
|
{
|
|
|
// using DQ.Construction.NewLook.Utility;
|
|
|
using Newtonsoft.Json;
|
|
|
using SqlSugar;
|
|
|
using System;
|
|
|
using System.Collections.Concurrent;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.Diagnostics;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Linq.Expressions;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using WorkData;
|
|
|
using WorkData.Entity;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取文件字符编码
|
|
|
/// </summary>
|
|
|
public class EncodingType
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 给定文件的路径,读取文件的二进制数据,判断文件的编码类型
|
|
|
/// </summary>
|
|
|
/// <param name="fileName">文件路径</param>
|
|
|
/// <returns>文件的编码类型</returns>
|
|
|
public static System.Text.Encoding GetType(string fileName)
|
|
|
{
|
|
|
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
|
|
|
Encoding r = GetType(fs);
|
|
|
fs.Close();
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 通过给定的文件流,判断文件的编码类型
|
|
|
/// </summary>
|
|
|
/// <param name="fs">文件流</param>
|
|
|
/// <returns>文件的编码类型</returns>
|
|
|
public static System.Text.Encoding GetType(FileStream fs)
|
|
|
{
|
|
|
byte[] unicode = new byte[] { 0xFF, 0xFE, 0x41 };
|
|
|
byte[] unicodeBIG = new byte[] { 0xFE, 0xFF, 0x00 };
|
|
|
byte[] uTF8 = new byte[] { 0xEF, 0xBB, 0xBF }; // 带BOM
|
|
|
|
|
|
BinaryReader r = new BinaryReader(fs, System.Text.Encoding.Default);
|
|
|
int i;
|
|
|
int.TryParse(fs.Length.ToString(), out i);
|
|
|
byte[] ss = r.ReadBytes(i);
|
|
|
Encoding reVal = GetType(ss);
|
|
|
r.Close();
|
|
|
return reVal;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获得格式编码
|
|
|
/// </summary>
|
|
|
/// <param name="data">数据内容</param>
|
|
|
/// <returns>编码</returns>
|
|
|
public static System.Text.Encoding GetType(byte[] data)
|
|
|
{
|
|
|
Encoding reVal = Encoding.Default;
|
|
|
if (IsUTF8Bytes(data) || (data[0] == 0xEF && data[1] == 0xBB && data[2] == 0xBF))
|
|
|
{
|
|
|
reVal = Encoding.UTF8;
|
|
|
}
|
|
|
else if (data[0] == 0xFE && data[1] == 0xFF && data[2] == 0x00)
|
|
|
{
|
|
|
reVal = Encoding.BigEndianUnicode;
|
|
|
}
|
|
|
else if (data[0] == 0xFF && data[1] == 0xFE && data[2] == 0x41)
|
|
|
{
|
|
|
reVal = Encoding.Unicode;
|
|
|
}
|
|
|
return reVal;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 判断是否是不带 BOM 的 UTF8 格式
|
|
|
/// </summary>
|
|
|
/// <param name="data">数据</param>
|
|
|
/// <returns>是否UTF8</returns>
|
|
|
private static bool IsUTF8Bytes(byte[] data)
|
|
|
{
|
|
|
int charByteCounter = 1;
|
|
|
// 计算当前正分析的字符应还有的字节数
|
|
|
byte curByte; // 当前分析的字节.
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
{
|
|
|
curByte = data[i];
|
|
|
if (charByteCounter == 1)
|
|
|
{
|
|
|
if (curByte >= 0x80)
|
|
|
{
|
|
|
// 判断当前
|
|
|
while (((curByte <<= 1) & 0x80) != 0)
|
|
|
{
|
|
|
charByteCounter++;
|
|
|
}
|
|
|
// 标记位首位若为非0 则至少以2个1开始 如:110XXXXX...........1111110X
|
|
|
if (charByteCounter == 1 || charByteCounter > 6)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// 若是UTF-8 此时第一位必须为1
|
|
|
if ((curByte & 0xC0) != 0x80)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
charByteCounter--;
|
|
|
}
|
|
|
}
|
|
|
if (charByteCounter > 1)
|
|
|
{
|
|
|
throw new Exception("非预期的byte格式");
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 全局数据类(不变数据), 一次加载, 全局调用
|
|
|
/// </summary>
|
|
|
public static class DataHelp
|
|
|
{
|
|
|
private static ConcurrentDictionary<string, List<WellDeflection>> dictWellDeflection = new ConcurrentDictionary<string, List<WellDeflection>>();
|
|
|
private static ConcurrentDictionary<string, List<InterpretDrillWellLayered>> dictWellLayer = new ConcurrentDictionary<string, List<InterpretDrillWellLayered>>();
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets the list system data tree.
|
|
|
/// </summary>
|
|
|
/// <value>The list system data tree.</value>
|
|
|
public static List<GeologicalStratification> ListGeoLayer { get; } = new List<GeologicalStratification>();
|
|
|
/// <summary>
|
|
|
/// Gets the list system data tree.
|
|
|
/// </summary>
|
|
|
/// <value>The list system data tree.</value>
|
|
|
public static List<SysDataTree> ListSysDataTree { get; } = new List<SysDataTree>();
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets the list table information.
|
|
|
/// </summary>
|
|
|
/// <value>The list table information.</value>
|
|
|
public static List<TableInfo> ListTableInfo { get; } = new List<TableInfo>();
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets the list system dictionary.
|
|
|
/// </summary>
|
|
|
/// <value>The list system dictionary.</value>
|
|
|
public static List<SysDictionary> ListSysDictionary { get; } = new List<SysDictionary>();
|
|
|
|
|
|
/// <summary>
|
|
|
/// 储层数据是否按(层位/井号)分组
|
|
|
/// </summary>
|
|
|
public static bool IsReservoirDataGroupByLayer { get; set; } = false;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 井分层是否按(层位/井号)分组.
|
|
|
/// </summary>
|
|
|
public static bool IsDrillwelllayeredGroupByLayer { get; set; } = false;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 井斜采样点大小, 为0表示不更新采样值
|
|
|
/// </summary>
|
|
|
public static double WellDeflectionCollectCount { get; set; } = 0d;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 储层数据是否累加计算
|
|
|
/// </summary>
|
|
|
public static bool IsReservoirDataStat { get; set; } = true;
|
|
|
|
|
|
/// <summary>
|
|
|
/// ListColumnSearchWellName
|
|
|
/// </summary>
|
|
|
public static List<string> ListColumnSearchWellName { get; } = DBHelp.GetEntityColumnInfo(typeof(SearchWellName)).Select(o => o.DbColumnName).ToList();
|
|
|
/// <summary>
|
|
|
/// 工区边界缓存
|
|
|
/// </summary>
|
|
|
// public static (DrawerRange range, string path) workBorder { get; set; } = (null, string.Empty);
|
|
|
/// <summary>
|
|
|
/// Resets the.
|
|
|
/// </summary>
|
|
|
public static void Reset()
|
|
|
{
|
|
|
dictWellDeflection.Clear();
|
|
|
dictWellLayer.Clear();
|
|
|
ListGeoLayer.Clear();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// Clones the table.
|
|
|
/// </summary>
|
|
|
/// <param name="source">The source.</param>
|
|
|
/// <param name="dest">The dest.</param>
|
|
|
/// <param name="firstRowAsColumn">if set to <c>true</c> [first row as column].</param>
|
|
|
/// <param name="count">The count.</param>
|
|
|
public static void CloneTable(
|
|
|
DataTable source,
|
|
|
DataTable dest,
|
|
|
bool firstRowAsColumn = false,
|
|
|
int? count = null)
|
|
|
{
|
|
|
dest.Columns.Clear();
|
|
|
dest.Rows.Clear();
|
|
|
|
|
|
for (int i = 0; i < source.Columns.Count; i++)
|
|
|
{
|
|
|
string colName = firstRowAsColumn ? source.Rows[0][i].ToString() : source.Columns[i].ColumnName;
|
|
|
|
|
|
while (dest.Columns.Contains(colName))
|
|
|
{
|
|
|
colName += "_";
|
|
|
}
|
|
|
|
|
|
dest.Columns.Add(colName);
|
|
|
}
|
|
|
|
|
|
int startRow = firstRowAsColumn ? 1 : 0;
|
|
|
int endRow = count == null ? source.Rows.Count : Math.Min(startRow + count.Value, source.Rows.Count);
|
|
|
|
|
|
for (int i = startRow; i < endRow; i++)
|
|
|
{
|
|
|
dest.Rows.Add(source.Rows[i].ItemArray);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Loads the data.
|
|
|
/// </summary>
|
|
|
/// <returns>Task</returns>
|
|
|
public static async Task LoadData()
|
|
|
{
|
|
|
await LoadDataSysDataTree();
|
|
|
|
|
|
await LoadDataTableInfo();
|
|
|
|
|
|
await LoadDataSysDictionary();
|
|
|
|
|
|
await LoadGeoLayer();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Loads the data system dictionary.
|
|
|
/// </summary>
|
|
|
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|
|
internal static async Task LoadDataSysDictionary()
|
|
|
{
|
|
|
ListSysDictionary.Clear();
|
|
|
ListSysDictionary.AddRange(await DBHelp.NewDb.Queryable<SysDictionary>().ToListAsync());
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// Loads the data system data tree.
|
|
|
/// </summary>
|
|
|
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|
|
public static async Task LoadDataSysDataTree()
|
|
|
{
|
|
|
ListSysDataTree.Clear();
|
|
|
ListSysDataTree.AddRange(await DBHelp.NewDb.Queryable<SysDataTree>().ToListAsync());
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Loads the data system data tree.
|
|
|
/// </summary>
|
|
|
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|
|
public static async Task LoadGeoLayer()
|
|
|
{
|
|
|
ListGeoLayer.Clear();
|
|
|
ListGeoLayer.AddRange(await DBHelp.NewDb.Queryable<GeologicalStratification>().ToListAsync());
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// Loads the data table information.
|
|
|
/// </summary>
|
|
|
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
|
|
internal static async Task LoadDataTableInfo()
|
|
|
{
|
|
|
ListTableInfo.Clear();
|
|
|
var list = await DBHelp.NewDb.Queryable<TableInfo>().ToListAsync();
|
|
|
ListTableInfo.AddRange(list);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 同步井索引
|
|
|
/// </summary>
|
|
|
public static void SyncSearchWellName()
|
|
|
{
|
|
|
DBHelp.NewDb.UseTran(
|
|
|
db =>
|
|
|
{
|
|
|
db.Ado.ExecuteCommand(
|
|
|
@"insert into searchwellname(WellName, wellbase)
|
|
|
select JH,1 from well_base a where not EXISTS(select wellname from searchwellname b where a.jh==b.wellname)");
|
|
|
|
|
|
db.Ado.ExecuteCommand(
|
|
|
@"delete from searchwellname where wellname is null");
|
|
|
|
|
|
db.Ado.ExecuteCommand(
|
|
|
@"update searchwellname as a set wellbase=(select count(*) from well_base b where a.wellname=b.jh)");
|
|
|
|
|
|
//曲线索引
|
|
|
List<string> wellCurves = db.Queryable<WellCurve>().Select(c => c.JH).ToList().Distinct().ToList();
|
|
|
db.Updateable<SearchWellName>().SetColumns(x => x.WellCurve == 1).Where(x => wellCurves.Contains(x.WellName)).ExecuteCommand();
|
|
|
db.Updateable<SearchWellName>().SetColumns(x => x.WellCurve == 0).Where(x => !wellCurves.Contains(x.WellName)).ExecuteCommand();
|
|
|
|
|
|
UpdateAllSearchWellNameCore(db);
|
|
|
|
|
|
// 清理全为0的井索引
|
|
|
db.Deleteable<SearchWellName>().Where(o => o.InterpretDrillWellLayered == 0
|
|
|
&& o.WellBase == 0
|
|
|
&& o.WellBreakPoint == 0
|
|
|
&& o.WellCurve == 0
|
|
|
&& o.WellTimeDepth == 0
|
|
|
&& o.WellDeflection == 0
|
|
|
&& o.CcsjYxhd == 0
|
|
|
&& o.CcsjSyhd == 0
|
|
|
&& o.CcsjBhd == 0
|
|
|
&& o.CcsjKxd == 0
|
|
|
&& o.CcsjStl == 0
|
|
|
&& o.WellPerforation == 0).ExecuteCommand();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新井索引
|
|
|
/// </summary>
|
|
|
/// <typeparam name="T">更新的列类型</typeparam>
|
|
|
public static void UpdateSearchWellName<T>()
|
|
|
{
|
|
|
UpdateSearchWellNameCore<T>(DBHelp.NewDb);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Updates the name of the search well.
|
|
|
/// </summary>
|
|
|
/// <param name="t">The t.</param>
|
|
|
public static void UpdateSearchWellName(Type t)
|
|
|
{
|
|
|
UpdateSearchWellNameCore(DBHelp.NewDb, t);
|
|
|
}
|
|
|
|
|
|
private static void UpdateSearchWellNameCore<T>(CustomSqlSugarClient db)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
string columnname = typeof(T).Name;
|
|
|
|
|
|
if (columnname.Equals("WellCurveFile"))
|
|
|
{
|
|
|
columnname = "WellCurve";
|
|
|
}//因为后面导入测井曲线都存到WellCurveFile表里去了,但是这个表里的字段名仍然为WellCurve
|
|
|
|
|
|
string tablename = DBHelp.GetTableName<T>();
|
|
|
|
|
|
string sql = string.Format(
|
|
|
@"update searchwellname as a set {0} = (select count(*) from {1} b where a.wellname=b.jh)",
|
|
|
columnname,
|
|
|
tablename);
|
|
|
|
|
|
db.Ado.ExecuteCommand(sql);
|
|
|
}
|
|
|
catch (Exception /*ex*/)
|
|
|
{
|
|
|
// ex
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private static void UpdateSearchWellNameCore(CustomSqlSugarClient db, Type t)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
string columnname = t.Name;
|
|
|
string tablename = DBHelp.GetTableName(t);
|
|
|
|
|
|
if (ListColumnSearchWellName.Any(o => string.Equals(o, columnname, StringComparison.CurrentCultureIgnoreCase)))
|
|
|
{
|
|
|
string sql = string.Format(
|
|
|
@"update searchwellname as a set {0} = (select count(*) from {1} b where a.wellname=b.jh)",
|
|
|
columnname,
|
|
|
tablename);
|
|
|
|
|
|
db.Ado.ExecuteCommand(sql);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception /*ex*/)
|
|
|
{
|
|
|
// ex
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private static void UpdateAllSearchWellNameCore(CustomSqlSugarClient db)
|
|
|
{
|
|
|
Type tIdentify = typeof(IIdentifierEntity);
|
|
|
|
|
|
List<SqlSugar.EntityInfo> list = EntityHelp.AllEntity
|
|
|
.Where(o => tIdentify.IsAssignableFrom(o.Type))
|
|
|
.ToList();
|
|
|
|
|
|
foreach (SqlSugar.EntityInfo item in list)
|
|
|
{
|
|
|
UpdateSearchWellNameCore(db, item.Type);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新井索引
|
|
|
/// </summary>
|
|
|
public static void UpdateAllSearchWellName()
|
|
|
{
|
|
|
UpdateAllSearchWellNameCore(DBHelp.NewDb);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新和同步层位名.
|
|
|
/// </summary>
|
|
|
/// <param name="id">The identifier.</param>
|
|
|
/// <param name="name">The name.</param>
|
|
|
public static void UpdateLayerName(int id, string name)
|
|
|
{
|
|
|
DBHelp.NewDb.UseTran(db =>
|
|
|
{
|
|
|
db.Updateable<InterpretLayer>(o => new InterpretLayer { CW = name })
|
|
|
.Where(o => o.ID == id)
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
db.Updateable<InterpretTimeLayer>(o => new InterpretTimeLayer { CW = name })
|
|
|
.Where(o => o.CWID == id)
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
db.Updateable<InterpretDepthLayer>(o => new InterpretDepthLayer { CW = name })
|
|
|
.Where(o => o.CWID == id)
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
db.Updateable<InterpretBoundary>(o => new InterpretBoundary { CW = name })
|
|
|
.Where(o => o.CWID == id)
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
db.Updateable<InterpretFault>(o => new InterpretFault { CW = name })
|
|
|
.Where(o => o.CWID == id)
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
db.Updateable<InterpretAttribute>(o => new InterpretAttribute { CW = name })
|
|
|
.Where(o => o.CWID == id)
|
|
|
.ExecuteCommand();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新和同步层顺序.
|
|
|
/// </summary>
|
|
|
/// <param name="order">The order.</param>
|
|
|
public static void UpdateLayerOrder(List<string> order)
|
|
|
{
|
|
|
DBHelp.NewDb.UseTran(db =>
|
|
|
{
|
|
|
for (int i = 0; i < order.Count; i++)
|
|
|
{
|
|
|
db.Updateable<InterpretTimeLayer>(o => new InterpretTimeLayer { XHID = i })
|
|
|
.Where(o => o.CW == order[i])
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
db.Updateable<InterpretDepthLayer>(o => new InterpretDepthLayer { XHID = i })
|
|
|
.Where(o => o.CW == order[i])
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
db.Updateable<InterpretBoundary>(o => new InterpretBoundary { XHID = i })
|
|
|
.Where(o => o.CW == order[i])
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
db.Updateable<InterpretFault>(o => new InterpretFault { XHID = i })
|
|
|
.Where(o => o.CW == order[i])
|
|
|
.ExecuteCommand();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 同步储层数据 (有效厚度发生变化)
|
|
|
/// </summary>
|
|
|
//public static void SyncReservoirData<T>(string v_jh, ProgressCallbackThree progressCallback = null)
|
|
|
//{
|
|
|
// try
|
|
|
// {
|
|
|
// List<string> arys = new List<string>();
|
|
|
// if (typeof(T) == typeof(CcsjKxd))
|
|
|
// {
|
|
|
// arys = new List<string>() { "kxd", "bhd" };
|
|
|
// }
|
|
|
// else if (typeof(T) == typeof(CcsjBhd))
|
|
|
// {
|
|
|
// arys = new List<string>() { "bhd" };
|
|
|
// }
|
|
|
// else if (typeof(T) == typeof(CcsjStl))
|
|
|
// {
|
|
|
// arys = new List<string>() { "stl" };
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// arys = new List<string>() { "kxd", "bhd", "stl" };
|
|
|
// }
|
|
|
|
|
|
// //获取有效厚度
|
|
|
// List<CcsjYxhd> yxhds = DBHelp.NewDb.Queryable<CcsjYxhd>().WhereIF(!string.IsNullOrWhiteSpace(v_jh), x => x.JH == v_jh).ToList();
|
|
|
|
|
|
// Dictionary<string, List<CcsjYxhd>> dict_yxhds = yxhds.GroupBy(x => x.JH).ToDictionary(x => x.Key, x => x.ToList());
|
|
|
|
|
|
// List<CcsjKxd> kxds = DBHelp.NewDb.Queryable<CcsjKxd>().WhereIF(!string.IsNullOrWhiteSpace(v_jh), x => x.JH == v_jh).ToList();
|
|
|
// if (arys.Contains("kxd"))
|
|
|
// {
|
|
|
// int processedCount = 0;
|
|
|
// int totalCount = kxds.Count;
|
|
|
// Parallel.ForEach(kxds, kxd =>
|
|
|
// {
|
|
|
// if (dict_yxhds.TryGetValue(kxd.JH, out List<CcsjYxhd> hds))
|
|
|
// {
|
|
|
// var hd = hds.Where(x => x.CW == kxd.CW);
|
|
|
// if (kxd.DJSD1.HasValue)
|
|
|
// {
|
|
|
// hd = hd.Where(x => x.DJSD1 == kxd.DJSD1);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// hd = hd.Where(x => x.YXCS_T == kxd.YXCS_T);
|
|
|
// }
|
|
|
// if (hd.Count() > 0)
|
|
|
// {
|
|
|
// if (kxd.YXHD == null)
|
|
|
// {
|
|
|
// kxd.YXHD = hd.Average(x => x.YXHD);
|
|
|
// }
|
|
|
|
|
|
// if (kxd.YXHD_CS == null)
|
|
|
// {
|
|
|
// kxd.YXHD_CS = hd.Average(x => x.YXCS_HD);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// Interlocked.Increment(ref processedCount);
|
|
|
// progressCallback?.Invoke("同步有效到孔隙度", processedCount, totalCount);
|
|
|
// });
|
|
|
// DBHelp.NewDb.Fastest<CcsjKxd>().BulkUpdateAsync(kxds, new string[] { "JH", "CW", "ID" }, new string[] { "YXHD", "YXHD_CS" });
|
|
|
// }
|
|
|
// List<CcsjBhd> bhds = new List<CcsjBhd>();
|
|
|
// if (arys.Contains("bhd"))
|
|
|
// {
|
|
|
// bhds = DBHelp.NewDb.Queryable<CcsjBhd>().WhereIF(!string.IsNullOrWhiteSpace(v_jh), x => x.JH == v_jh).ToList();
|
|
|
// int processedCount = 0;
|
|
|
// int totalCount = bhds.Count;
|
|
|
// Parallel.ForEach(bhds, bhd =>
|
|
|
// {
|
|
|
// if (dict_yxhds.TryGetValue(bhd.JH, out List<CcsjYxhd> hds))
|
|
|
// {
|
|
|
// var hd = hds.Where(x => x.CW == bhd.CW);
|
|
|
// if (bhd.DJSD1.HasValue)
|
|
|
// {
|
|
|
// hd = hd.Where(x => x.DJSD1 == bhd.DJSD1);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// hd = hd.Where(x => x.YXCS_T == bhd.YXCS_T);
|
|
|
// }
|
|
|
// if (hd.Count() > 0)
|
|
|
// {
|
|
|
// if (bhd.YXHD == null)
|
|
|
// {
|
|
|
// bhd.YXHD = hd.Average(x => x.YXHD);
|
|
|
// }
|
|
|
|
|
|
// if (bhd.YXHD_CS == null)
|
|
|
// {
|
|
|
// bhd.YXHD_CS = hd.Average(x => x.YXCS_HD);
|
|
|
// }
|
|
|
|
|
|
// var kx = kxds.Where(x => x.JH == bhd.JH && x.CW == bhd.CW);
|
|
|
// if (bhd.DJSD1.HasValue)
|
|
|
// {
|
|
|
// kx = kx.Where(x => x.DJSD1 == bhd.DJSD1);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// kx = kx.Where(x => x.YXCS_T == bhd.YXCS_T);
|
|
|
// }
|
|
|
// if (kx.Count() > 0)
|
|
|
// {
|
|
|
// bhd.KXD = kx.Average(x => x.KXD);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// Interlocked.Increment(ref processedCount);
|
|
|
// progressCallback?.Invoke("同步有效和孔隙度到饱和度", processedCount, totalCount);
|
|
|
// });
|
|
|
// DBHelp.NewDb.Fastest<CcsjBhd>().BulkUpdateAsync(bhds, new string[] { "JH", "CW", "ID" }, new string[] { "YXHD", "YXHD_CS", "KXD" });
|
|
|
// }
|
|
|
// List<CcsjStl> stls = new List<CcsjStl>();
|
|
|
// if (arys.Contains("stl"))
|
|
|
// {
|
|
|
// stls = DBHelp.NewDb.Queryable<CcsjStl>().WhereIF(!string.IsNullOrWhiteSpace(v_jh), x => x.JH == v_jh).ToList();
|
|
|
// int processedCount = 0;
|
|
|
// int totalCount = stls.Count;
|
|
|
// Parallel.ForEach(stls, stl =>
|
|
|
// {
|
|
|
// if (dict_yxhds.TryGetValue(stl.JH, out List<CcsjYxhd> hds))
|
|
|
// {
|
|
|
// var hd = hds.Where(x => x.CW == stl.CW);
|
|
|
// if (stl.DJSD1.HasValue)
|
|
|
// {
|
|
|
// hd = hd.Where(x => x.DJSD1 == stl.DJSD1);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// hd = hd.Where(x => x.YXCS_T == stl.YXCS_T);
|
|
|
// }
|
|
|
// if (hd.Count() > 0)
|
|
|
// {
|
|
|
// if (stl.YXHD == null)
|
|
|
// {
|
|
|
// stl.YXHD = hd.Average(x => x.YXHD);
|
|
|
// }
|
|
|
|
|
|
// if (stl.YXHD_CS == null)
|
|
|
// {
|
|
|
// stl.YXHD_CS = hd.Average(x => x.YXCS_HD);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// Interlocked.Increment(ref processedCount);
|
|
|
// progressCallback?.Invoke("同步有效到渗透率", processedCount, totalCount);
|
|
|
// });
|
|
|
// DBHelp.NewDb.Fastest<CcsjStl>().BulkUpdateAsync(stls, new string[] { "JH", "CW", "ID" }, new string[] { "YXHD", "YXHD_CS" });
|
|
|
// }
|
|
|
// }
|
|
|
// catch (Exception)
|
|
|
// {
|
|
|
// // ignore Exception
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取工区边界静态存储,如果导入新边界请清空此值
|
|
|
/// </summary>
|
|
|
public static object locker = new object();
|
|
|
/// <summary>
|
|
|
/// 获取工区边界对象
|
|
|
/// </summary>
|
|
|
/// <returns>工区边界及路径</returns>
|
|
|
//public static (DrawerRange range, string path) GetWorkAreaOutLineRange()
|
|
|
//{
|
|
|
// if (workBorder.range != null)
|
|
|
// {
|
|
|
// return workBorder;
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// lock (locker) // 存在并行调用,写入时加锁
|
|
|
// {
|
|
|
// WorkArea areaBorder = DBHelp.NewDb.Queryable<WorkArea>().First();
|
|
|
// if (areaBorder != null)
|
|
|
// {
|
|
|
// string workOutLinePath = Config.ProjectPath + areaBorder.PATH + "\\" + areaBorder.OUTFILENAME;
|
|
|
// if (File.Exists(workOutLinePath))
|
|
|
// {
|
|
|
// CsharpFileUtility.DecodeOverrideFile(workOutLinePath);
|
|
|
// Xy xy = new Xy();
|
|
|
// xy.DfdRead(workOutLinePath);
|
|
|
// var range = xy.GetCoordinateRange();
|
|
|
// CsharpFileUtility.EncodeFile(workOutLinePath);
|
|
|
// workBorder = (range, workOutLinePath);
|
|
|
// return workBorder;
|
|
|
// }
|
|
|
// }
|
|
|
// return (null, string.Empty);
|
|
|
// }
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
|
// 更新序号
|
|
|
// </summary>
|
|
|
/// <param name="table">表</param>
|
|
|
/// <param name="idColumn">序号列</param>
|
|
|
/// <param name="orderColumn">排序列</param>
|
|
|
public static void UpdateTableOrder(string table, string idColumn, string orderColumn)
|
|
|
{
|
|
|
DBHelp.NewDb.Ado.ExecuteCommandAsync($@"
|
|
|
with tmp as (select {idColumn}, row_number() over (order by {idColumn}) rn from {table} )
|
|
|
|
|
|
update {table}
|
|
|
set {orderColumn} = (
|
|
|
select rn from tmp
|
|
|
where tmp.{idColumn} = {table}.{idColumn}
|
|
|
);
|
|
|
");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 更新井斜xy
|
|
|
/// </summary>
|
|
|
public static void UpdateWellDeflectionXY()
|
|
|
{
|
|
|
DBHelp.NewDb.Ado.ExecuteCommandAsync($@"
|
|
|
with tmp as (select x,y,jh from well_base where jh in (select jh from well_deflection))
|
|
|
|
|
|
update well_deflection
|
|
|
set (x, y) = (
|
|
|
select
|
|
|
x + well_deflection.DZB,
|
|
|
y + well_deflection.BZB
|
|
|
from tmp
|
|
|
where tmp.jh == well_deflection.jh
|
|
|
);
|
|
|
");
|
|
|
// KEPDataManager.NotifyChange<WellDeflection>();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Gets the column to rows.
|
|
|
/// </summary>
|
|
|
/// <param name="tableData">表名</param>
|
|
|
/// <param name="columnNamesToReturn">返回值</param>
|
|
|
/// <returns>A Dictionary.</returns>
|
|
|
public static Dictionary<string, Dictionary<string, string>> GetCustomTableToRows(List<TableInfoValue> tableData, List<string> columnNamesToReturn = null)
|
|
|
{
|
|
|
// 并行将 List 转换为字典
|
|
|
Dictionary<string, Dictionary<string, string>> dictionary = tableData
|
|
|
.AsParallel()
|
|
|
.GroupBy(data => data.RowGuid)
|
|
|
.ToDictionary(
|
|
|
group => group.Key,
|
|
|
group => group.Where(data => columnNamesToReturn != null ? columnNamesToReturn.Contains(data.ColumnName) : true).ToDictionary(data => data.ColumnName, data => data.ColumnValue));
|
|
|
|
|
|
return dictionary;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取动态表的压裂段
|
|
|
/// </summary>
|
|
|
/// <param name="expression">条件</param>
|
|
|
/// <param name="columnNamesToReturn">返回列</param>
|
|
|
/// <returns>返回对象压裂段</returns>
|
|
|
public static List<T> GetCustomTable<T>(Expression<Func<T, bool>> expression = null, List<string> columnNamesToReturn = null)
|
|
|
{
|
|
|
//获取表名称
|
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
|
stopwatch.Start();
|
|
|
var tb = DBHelp.NewDb.Queryable<T>();
|
|
|
if (expression != null)
|
|
|
{
|
|
|
tb = tb.Where(expression);
|
|
|
}
|
|
|
List<T> results = tb.ToList();
|
|
|
stopwatch.Stop();
|
|
|
Console.WriteLine($"曲线获取耗时:{stopwatch.Elapsed.TotalMilliseconds},条数:{results.Count}");
|
|
|
if (typeof(T) == typeof(HoriWellFracturParameter))
|
|
|
{
|
|
|
List<HoriWellFracturParameter> specificResults = results.Cast<HoriWellFracturParameter>().ToList();
|
|
|
specificResults.AsParallel().ForAll(x => x.ColumnValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(x.ColumnValue));
|
|
|
return specificResults.Cast<T>().ToList();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
List<WellCurve> specificResults = results.Cast<WellCurve>().ToList();
|
|
|
specificResults.AsParallel().ForAll(x => x.ColumnValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(x.ColumnValue));
|
|
|
return specificResults.Cast<T>().ToList();
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// Gets the column to rows.
|
|
|
/// </summary>
|
|
|
/// <param name="expression">条件</param>
|
|
|
/// <param name="columnNamesToReturn">返回值</param>
|
|
|
/// <returns>A Dictionary.</returns>
|
|
|
//public static List<WellCurve> GetCustomTableWellCurveT(Expression<Func<TableInfoValue, bool>> expression = null, List<string> columnNamesToReturn = null)
|
|
|
//{
|
|
|
// Stopwatch stopwatch = new Stopwatch();
|
|
|
// stopwatch.Start();
|
|
|
// string tableName = DBHelp.GetTableName<WellCurve>();
|
|
|
// var tb = DBHelp.NewDb.Queryable<TableInfoValue>().Where(x => x.TableName == tableName);
|
|
|
// if (expression != null)
|
|
|
// {
|
|
|
// tb = tb.Where(expression);
|
|
|
// }
|
|
|
// List<TableInfoValue> tableData = tb.ToList();
|
|
|
// Console.WriteLine($"曲线获取耗时:{stopwatch.Elapsed.TotalMilliseconds},条数:{tableData.Count}");
|
|
|
// List<WellCurve> wellCurves = tableData
|
|
|
// .AsParallel()
|
|
|
// .GroupBy(data => new { data.RowGuid, data.RowID })
|
|
|
// .Select(group => new WellCurve() { RowID = group.Key.RowID, RowGuid = group.Key.RowGuid, DEPTH = Convert.ToDouble(group.FirstOrDefault(x => x.ColumnName == "DEPTH").ColumnValue), JH = group.FirstOrDefault(x => x.ColumnName == "JH").ColumnValue, ColumnValues = group.Where(data => columnNamesToReturn != null ? columnNamesToReturn.Contains(data.ColumnName) : true).ToDictionary(data => data.ColumnName, data => data.ColumnValue) }).ToList();
|
|
|
|
|
|
// stopwatch.Stop();
|
|
|
// Console.WriteLine($"列曲线转行耗时:{stopwatch.Elapsed.TotalMilliseconds},条数:{wellCurves.Count}");
|
|
|
// return wellCurves;
|
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 自定义表格行
|
|
|
/// </summary>
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
/// <param name="dictionary">传入数据</param>
|
|
|
/// <param name="columnNamesToReturn">返回</param>
|
|
|
/// <param name="columnName">列名</param>
|
|
|
/// <param name="searchValues">搜索值</param>
|
|
|
/// <returns>返回字典</returns>
|
|
|
public static List<Dictionary<string, string>> SearchCustomTableToRows(Dictionary<string, Dictionary<string, string>> dictionary, List<string> columnNamesToReturn, string columnName, List<string> searchValues)
|
|
|
{
|
|
|
// 在字典中搜索并返回满足条件的所有行
|
|
|
List<Dictionary<string, string>> searchResults = dictionary.AsParallel()
|
|
|
.Where(kv => kv.Value.ContainsKey(columnName) && searchValues.Contains(kv.Value[columnName]))
|
|
|
.Select(kv => kv.Value)
|
|
|
.ToList();
|
|
|
|
|
|
return searchResults;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 自定义表格行
|
|
|
/// </summary>
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
/// <param name="dictionary">字典</param>
|
|
|
/// <param name="searchKeyValues">搜索值</param>
|
|
|
/// <returns>List</returns>
|
|
|
public static List<Dictionary<string, string>> SearchCustomTableToRows(Dictionary<int, Dictionary<string, string>> dictionary, Dictionary<string, string> searchKeyValues)
|
|
|
{
|
|
|
// 在字典中搜索并返回满足条件的所有行
|
|
|
List<Dictionary<string, string>> searchResults = dictionary.AsParallel()
|
|
|
.Where(kv => kv.Value.Keys.Intersect(searchKeyValues.Keys).Count() == searchKeyValues.Keys.Count)
|
|
|
.Where(kv => searchKeyValues.All(entry => kv.Value.ContainsKey(entry.Key) && searchKeyValues[entry.Key] == entry.Value))
|
|
|
.Select(kv => kv.Value)
|
|
|
.ToList();
|
|
|
return searchResults;
|
|
|
}
|
|
|
|
|
|
///// <summary>
|
|
|
///// 获取压裂段坐标数据
|
|
|
///// </summary>
|
|
|
///// <returns>List<StagePointParameterData></returns>
|
|
|
//public static List<StagePointParameterData> CalcHoriWellFracturCoord()
|
|
|
//{
|
|
|
// List<StagePointParameterData> stageParamtersResult = new List<StagePointParameterData>();
|
|
|
// try
|
|
|
// {
|
|
|
// string tableName = DBHelp.GetTableName<HoriWellFracturParameter>();
|
|
|
// var columnNames = DBHelp.NewDb.Queryable<TableInfo>().Where(x => x.TableName == tableName).Select(x => new { En = x.ColumnName, CH = x.ChineseName }).ToList();
|
|
|
// var lst_coords = DBHelp.NewDb.Queryable<HoriWellFracturCoord>().ToList();
|
|
|
// List<HoriWellFracturParameter> list = GetCustomTable<HoriWellFracturParameter>();
|
|
|
|
|
|
// var lst_jhs = list.GroupBy(x => x.JH).Select(x => x.Key).ToList();
|
|
|
|
|
|
// string[] notColumns = { "ID", "XHID", "SYWZ1", "SYWZ2", "JH" };
|
|
|
|
|
|
// ConcurrentBag<StagePointParameterData> stageParamters = new ConcurrentBag<StagePointParameterData>();
|
|
|
// List<WellStagePoint> wellStagePoint = new List<WellStagePoint>();
|
|
|
// lst_coords.Select(x => new WellStagePoint()
|
|
|
// {
|
|
|
// JH = x.JH,
|
|
|
// Point = new DfPoint(x.X, x.Y),
|
|
|
// StageNo = x.XHID,
|
|
|
// });
|
|
|
|
|
|
// var lst_coord = lst_coords.GroupBy(x => new { x.JH, x.XHID }).Select(x => new { x.Key.JH, x.Key.XHID });
|
|
|
// //循环 压力段坐标分组井号和段序
|
|
|
// Parallel.ForEach(lst_coord, (coord) =>
|
|
|
// {
|
|
|
// var stageData = new StagePointParameterData()
|
|
|
// {
|
|
|
// JH = coord.JH,
|
|
|
// StageNo = coord.XHID,
|
|
|
// };
|
|
|
// var coords = lst_coords.Where(x => x.JH == coord.JH && x.XHID == coord.XHID).Select(x => new DfPoint() { X = x.X, Y = x.Y }).ToList();
|
|
|
// //需要判断2个以上
|
|
|
// stageData.StagePointRange = coords;
|
|
|
// //匹配压力段参数
|
|
|
// List<HoriWellFracturParameter> lstResult = list.Where(x => x.JH == coord.JH && x.XHID == coord.XHID).ToList();
|
|
|
// foreach (var pairs in lstResult)
|
|
|
// {
|
|
|
// //行
|
|
|
// ConcurrentDictionary<string, double> dicts = new ConcurrentDictionary<string, double>();
|
|
|
// Parallel.ForEach(pairs.ColumnValues, (prop) =>
|
|
|
// {
|
|
|
// string dictName = prop.Key;
|
|
|
// if (!notColumns.Contains(dictName))
|
|
|
// {
|
|
|
// if (columnNames.Any(x => x.En == prop.Key))
|
|
|
// {
|
|
|
// dictName = columnNames.FirstOrDefault(x => x.En == prop.Key).CH;
|
|
|
// }
|
|
|
// double d = 0;
|
|
|
// string v = prop.Value.ToString();
|
|
|
// if (v.Contains("-"))
|
|
|
// {
|
|
|
// string[] ary = v.Split('-');
|
|
|
// double total = 0;
|
|
|
// int count = 0;
|
|
|
// foreach (var a in ary)
|
|
|
// {
|
|
|
// if (string.IsNullOrWhiteSpace(a))
|
|
|
// {
|
|
|
// continue;
|
|
|
// }
|
|
|
// else if (double.TryParse(a, out double d1))
|
|
|
// {
|
|
|
// count++;
|
|
|
// total += d1;
|
|
|
// }
|
|
|
// }
|
|
|
// d = total / count;
|
|
|
// dicts.TryAdd(dictName, d);
|
|
|
// }
|
|
|
// else if (v.Contains("~"))
|
|
|
// {
|
|
|
// string[] ary = v.Split('~');
|
|
|
// double total = 0;
|
|
|
// int count = 0;
|
|
|
// foreach (var a in ary)
|
|
|
// {
|
|
|
// if (string.IsNullOrWhiteSpace(a))
|
|
|
// {
|
|
|
// continue;
|
|
|
// }
|
|
|
// else if (double.TryParse(a, out double d1))
|
|
|
// {
|
|
|
// count++;
|
|
|
// total += d1;
|
|
|
// }
|
|
|
// }
|
|
|
// d = total / count;
|
|
|
// dicts.TryAdd(dictName, d);
|
|
|
// }
|
|
|
// else if (double.TryParse(v, out d))
|
|
|
// {
|
|
|
// dicts.TryAdd(dictName, d);
|
|
|
// }
|
|
|
// }
|
|
|
// });
|
|
|
// stageData.ParamData = dicts.ToDictionary(x => x.Key, x => x.Value);
|
|
|
// stageParamters.Add(stageData);
|
|
|
// }
|
|
|
// });
|
|
|
// var lst_jh = list.Where(x => !lst_coords.Any(c => c.JH == x.JH)).ToList();
|
|
|
// stageParamtersResult = stageParamters.ToList();
|
|
|
// if (lst_jh != null)
|
|
|
// {
|
|
|
// stageParamtersResult.AddRange(lst_jh.Select(x => new StagePointParameterData() { JH = x.JH, StageNo = "0", ParamData = new Dictionary<string, double>(), StagePointRange = new List<DfPoint>() }));
|
|
|
// }
|
|
|
// }
|
|
|
// catch
|
|
|
// {
|
|
|
// }
|
|
|
// return stageParamtersResult;
|
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取水平井的井支轨迹
|
|
|
/// </summary>
|
|
|
//private static void CalcHoriALLWellBranchTracksAsync(Action<List<WellStageTrack>> callback)
|
|
|
//{
|
|
|
// Task.Run(() =>
|
|
|
// {
|
|
|
// List<WellStageTrack> wellStageTracks = new List<WellStageTrack>();
|
|
|
// var wellDeflections = DBHelp.NewDb.Queryable<WellDeflection>().Select(x => new { x.JH, x.X, x.Y }).ToList();
|
|
|
// foreach (var item in wellDeflections.GroupBy(x => new { x.JH }).Select(x => new { x.Key.JH }))
|
|
|
// {
|
|
|
// var stageTrack = new WellStageTrack { JH = item.JH };
|
|
|
// var coords = wellDeflections.Where(x => x.JH == item.JH && x.X.HasValue && x.Y.HasValue).Select(x => new DfPoint() { X = x.X.Value, Y = x.Y.Value }).ToList();
|
|
|
// stageTrack.Points = coords;
|
|
|
// wellStageTracks.Add(stageTrack);
|
|
|
// }
|
|
|
// callback(wellStageTracks);
|
|
|
// });
|
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取井斜
|
|
|
/// </summary>
|
|
|
/// <param name="wells">井号数据</param>
|
|
|
/// <returns>获取井斜LIST</returns>
|
|
|
public static List<WellDeflection> GetWellDeflections(List<string> wells)
|
|
|
{
|
|
|
List<WellDeflection> wellDeflections = new List<WellDeflection>();
|
|
|
object obj = new object();
|
|
|
wells = wells.Distinct().ToList();
|
|
|
List<Task> tasks = new List<Task>();
|
|
|
foreach (var jh in wells)
|
|
|
{
|
|
|
bool isSearch = false;
|
|
|
lock (obj)
|
|
|
{
|
|
|
if (!dictWellDeflection.ContainsKey(jh))
|
|
|
{
|
|
|
isSearch = true;
|
|
|
}
|
|
|
}
|
|
|
if (isSearch)
|
|
|
{
|
|
|
tasks.Add(Task.Run(() =>
|
|
|
{
|
|
|
// 多线程访问db,使用新实例
|
|
|
using (var db = DBHelp.NewDb)
|
|
|
{
|
|
|
var lstDeflection = db.Queryable<WellDeflection>()
|
|
|
.Where(it => it.JH == jh && it.JS.HasValue)
|
|
|
.Select(x => new WellDeflection() { X = x.X, Y = x.Y, JS = x.JS, JH = x.JH }).ToList();
|
|
|
lock (obj)
|
|
|
{
|
|
|
dictWellDeflection.TryAdd(jh, lstDeflection);
|
|
|
wellDeflections.AddRange(lstDeflection);
|
|
|
}
|
|
|
}
|
|
|
}));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
lock (obj)
|
|
|
{
|
|
|
var lst = new List<WellDeflection>();
|
|
|
dictWellDeflection.TryGetValue(jh, out lst);
|
|
|
wellDeflections.AddRange(lst);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Task.WaitAll(tasks.ToArray());
|
|
|
Console.WriteLine(string.Join(string.Empty, wells) + "OK");
|
|
|
return wellDeflections.ToList();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取井斜
|
|
|
/// </summary>
|
|
|
/// <param name="wells">井号数据</param>
|
|
|
/// <returns>获取井斜LIST</returns>
|
|
|
public static List<WellDeflection> GetWellDeflectionsAll(List<string> wells)
|
|
|
{
|
|
|
List<WellDeflection> wellDeflections = new List<WellDeflection>();
|
|
|
object obj = new object();
|
|
|
wells = wells.Distinct().ToList();
|
|
|
List<Task> tasks = new List<Task>();
|
|
|
foreach (var jh in wells)
|
|
|
{
|
|
|
bool isSearch = false;
|
|
|
lock (obj)
|
|
|
{
|
|
|
if (!dictWellDeflection.ContainsKey(jh))
|
|
|
{
|
|
|
isSearch = true;
|
|
|
}
|
|
|
}
|
|
|
if (isSearch)
|
|
|
{
|
|
|
tasks.Add(Task.Run(() =>
|
|
|
{
|
|
|
// 多线程访问db,使用新实例
|
|
|
using (var db = DBHelp.NewDb)
|
|
|
{
|
|
|
var lstDeflection = db.Queryable<WellDeflection>()
|
|
|
.Where(it => it.JH == jh && it.JS.HasValue).ToList();
|
|
|
lock (obj)
|
|
|
{
|
|
|
dictWellDeflection.TryAdd(jh, lstDeflection);
|
|
|
wellDeflections.AddRange(lstDeflection);
|
|
|
}
|
|
|
}
|
|
|
}));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
lock (obj)
|
|
|
{
|
|
|
var lst = new List<WellDeflection>();
|
|
|
dictWellDeflection.TryGetValue(jh, out lst);
|
|
|
wellDeflections.AddRange(lst);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Task.WaitAll(tasks.ToArray());
|
|
|
Console.WriteLine(string.Join(string.Empty, wells) + "OK");
|
|
|
return wellDeflections.ToList();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取所有井井斜数据
|
|
|
/// </summary>
|
|
|
/// <returns>井斜LIST</returns>
|
|
|
public static List<WellDeflection> GetWellDeflectionsAllWell()
|
|
|
{
|
|
|
List<WellDeflection> wellDeflections = new List<WellDeflection>();
|
|
|
// 多线程访问db,使用新实例
|
|
|
using (var db = DBHelp.NewDb)
|
|
|
{
|
|
|
var lstDeflection = db.Queryable<WellDeflection>()
|
|
|
.Where(it => it.JS.HasValue).ToList();
|
|
|
wellDeflections.AddRange(lstDeflection);
|
|
|
}
|
|
|
return wellDeflections.ToList();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取井分层数据
|
|
|
/// </summary>
|
|
|
/// <param name="wells">井号数据</param>
|
|
|
/// <returns>分层井数据LIST</returns>
|
|
|
public static List<InterpretDrillWellLayered> GetWellLayers(List<string> wells)
|
|
|
{
|
|
|
List<InterpretDrillWellLayered> wellLayereds = new List<InterpretDrillWellLayered>();
|
|
|
using (var db1 = DBHelp.NewDb)
|
|
|
{
|
|
|
object obj = new object();
|
|
|
wells = wells.Distinct().ToList();
|
|
|
List<Task> tasks = new List<Task>();
|
|
|
foreach (var jh in wells)
|
|
|
{
|
|
|
bool isSearch = false;
|
|
|
lock (obj)
|
|
|
{
|
|
|
if (!dictWellLayer.ContainsKey(jh))
|
|
|
{
|
|
|
isSearch = true;
|
|
|
}
|
|
|
}
|
|
|
if (isSearch)
|
|
|
{
|
|
|
tasks.Add(Task.Run(() =>
|
|
|
{
|
|
|
var lstDeflection = db1.Queryable<InterpretDrillWellLayered>().Where(it => it.JH == jh && it.SD.HasValue).ToList();
|
|
|
lock (obj)
|
|
|
{
|
|
|
dictWellLayer.TryAdd(jh, lstDeflection);
|
|
|
wellLayereds.AddRange(lstDeflection);
|
|
|
}
|
|
|
}));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
lock (obj)
|
|
|
{
|
|
|
var lst = new List<InterpretDrillWellLayered>();
|
|
|
dictWellLayer.TryGetValue(jh, out lst);
|
|
|
wellLayereds.AddRange(lst);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Task.WaitAll(tasks.ToArray());
|
|
|
}
|
|
|
return wellLayereds.ToList();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取所有层位
|
|
|
/// </summary>
|
|
|
/// <returns>层位数据LIST</returns>
|
|
|
public static List<string> GetDistinctCWStrings()
|
|
|
{
|
|
|
using (var db = DBHelp.NewDb)
|
|
|
{
|
|
|
return db.Queryable<InterpretDrillWellLayered>()
|
|
|
.Where(it => it.CW != null)
|
|
|
.Select(it => it.CW)
|
|
|
.Distinct()
|
|
|
.ToList();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取井分层数据
|
|
|
/// </summary>
|
|
|
/// <param name="wells">井号数据</param>
|
|
|
/// <returns>分层井数据LIST</returns>
|
|
|
public static List<InterpretDrillWellLayered> GetWellLayersNew(List<string> wells)
|
|
|
{
|
|
|
List<InterpretDrillWellLayered> wellLayereds = new List<InterpretDrillWellLayered>();
|
|
|
|
|
|
object obj = new object();
|
|
|
wells = wells.Distinct().ToList();
|
|
|
List<Task> tasks = new List<Task>();
|
|
|
foreach (var jh in wells)
|
|
|
{
|
|
|
bool isSearch = false;
|
|
|
lock (obj)
|
|
|
{
|
|
|
if (!dictWellLayer.ContainsKey(jh))
|
|
|
{
|
|
|
isSearch = true;
|
|
|
}
|
|
|
}
|
|
|
if (isSearch)
|
|
|
{
|
|
|
tasks.Add(Task.Run(() =>
|
|
|
{
|
|
|
using (var db1 = DBHelp.NewDb)
|
|
|
{
|
|
|
var lstDeflection = db1.Queryable<InterpretDrillWellLayered>().Where(it => it.JH == jh && it.SD.HasValue).ToList();
|
|
|
lock (obj)
|
|
|
{
|
|
|
dictWellLayer.TryAdd(jh, lstDeflection);
|
|
|
wellLayereds.AddRange(lstDeflection);
|
|
|
}
|
|
|
}
|
|
|
}));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
lock (obj)
|
|
|
{
|
|
|
var lst = new List<InterpretDrillWellLayered>();
|
|
|
dictWellLayer.TryGetValue(jh, out lst);
|
|
|
wellLayereds.AddRange(lst);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Task.WaitAll(tasks.ToArray());
|
|
|
|
|
|
return wellLayereds.ToList();
|
|
|
}
|
|
|
|
|
|
public class WellCurveData
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 井号
|
|
|
/// </summary>
|
|
|
public string JH { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 曲线列表
|
|
|
/// </summary>
|
|
|
public List<CurveData> CurveList { get; set; }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 曲线数据
|
|
|
/// </summary>
|
|
|
public class CurveData
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 曲线名称
|
|
|
/// </summary>
|
|
|
public string CurveName { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 深度
|
|
|
/// </summary>
|
|
|
public double Depth { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 曲线浮度点
|
|
|
/// </summary>
|
|
|
public double Point { get; set; }
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取测井曲线数据
|
|
|
/// </summary>
|
|
|
/// <returns>List<StagePointParameterData></returns>
|
|
|
///
|
|
|
public static List<WellCurveData> GetWellCurveDatas()
|
|
|
{
|
|
|
string tableName = DBHelp.GetTableName<WellCurve>();
|
|
|
List<WellCurveData> wellCurveDatas = new List<WellCurveData>();
|
|
|
List<TableInfo> lstColNames = DBHelp.NewDb.Queryable<TableInfo>().Where(x => x.TableName == tableName).ToList();
|
|
|
List<WellCurve> list = GetCustomTable<WellCurve>();
|
|
|
var lst_jh = list.GroupBy(x => x.JH).Select(x => x.Key).ToList();
|
|
|
Parallel.ForEach(lst_jh, (jh) =>
|
|
|
{
|
|
|
var tableDatas = list.Where(x => x.JH == jh).ToList();
|
|
|
WellCurveData wellCurveData = new WellCurveData() { JH = jh, CurveList = new List<CurveData>() };
|
|
|
foreach (var row in tableDatas)
|
|
|
{
|
|
|
var rowData = row.ColumnValue;
|
|
|
if (row.DEPTH < 0)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
Dictionary<string, string> dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(rowData);
|
|
|
foreach (var data in dict)
|
|
|
{
|
|
|
if (double.TryParse(data.Value.ToString(), out double point))
|
|
|
{
|
|
|
string colName = data.Key;
|
|
|
if (lstColNames.Any(x => x.ColumnName == colName))
|
|
|
{
|
|
|
colName = lstColNames.FirstOrDefault(x => x.ColumnName == colName).ChineseName;
|
|
|
}
|
|
|
wellCurveData.CurveList.Add(new CurveData() { Depth = row.DEPTH, CurveName = colName, Point = point });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
wellCurveDatas.Add(wellCurveData);
|
|
|
});
|
|
|
return wellCurveDatas;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 从曲线文件表里获取测井曲线数据
|
|
|
/// </summary>
|
|
|
/// <returns>List<StagePointParameterData></returns>
|
|
|
public static List<WellCurveData> GetWellCurveDatasFromFile()
|
|
|
{
|
|
|
List<WellCurveData> wellCurveDatas = new List<WellCurveData>();
|
|
|
//拿到每一口井的路径
|
|
|
List<WellCurveFile> wellCurveFiles = DBHelp.NewDb.Queryable<WellCurveFile>().ToList();
|
|
|
//拿到路径后读文件 得到datatable
|
|
|
foreach (var file in wellCurveFiles)
|
|
|
{
|
|
|
WellCurveData wellCurveData = new WellCurveData
|
|
|
{
|
|
|
JH = file.JH, // 井号
|
|
|
CurveList = new List<CurveData>()
|
|
|
};
|
|
|
|
|
|
List<CurveData> curveDatas = new List<CurveData>();
|
|
|
wellCurveData.JH = file.JH;
|
|
|
|
|
|
string filename = FileHelp.Convert2AbsolutePath(file.FilePath);
|
|
|
DataTable dataTable = new DataTable();
|
|
|
LasHelper.LasFileToDataTable(ref dataTable, filename, EncodingType.GetType(filename)?.BodyName, 0);
|
|
|
|
|
|
if (dataTable.Rows.Count > 0 && dataTable.Columns.Count > 1)
|
|
|
{
|
|
|
for (int i = 0; i < dataTable.Rows.Count; i++)
|
|
|
{
|
|
|
// 拿到这一行的 DEPTH 值(即第 0 列)
|
|
|
double depthVal = Convert.ToDouble(dataTable.Rows[i][0]);
|
|
|
|
|
|
// 从第 1 列开始,后续每一列的列名都是一个 CurveName
|
|
|
for (int j = 1; j < dataTable.Columns.Count; j++)
|
|
|
{
|
|
|
string curveName = dataTable.Columns[j].ColumnName;
|
|
|
// 当前行、当前列对应的数值
|
|
|
double pointVal = Convert.ToDouble(dataTable.Rows[i][j]);
|
|
|
|
|
|
// 构建 CurveData 并添加到列表
|
|
|
var curveData = new CurveData
|
|
|
{
|
|
|
CurveName = curveName,
|
|
|
Depth = depthVal,
|
|
|
Point = pointVal
|
|
|
};
|
|
|
wellCurveData.CurveList.Add(curveData);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
wellCurveDatas.Add(wellCurveData);
|
|
|
}
|
|
|
|
|
|
return wellCurveDatas;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 通过井号获取 WellCurve 数据
|
|
|
/// </summary>
|
|
|
/// <param name="jh">井号</param>
|
|
|
/// <returns>WellCurveData</returns>
|
|
|
public static List<WellCurve> GetWellCurvesByJH(string jh)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(jh))
|
|
|
{
|
|
|
return new List<WellCurve>();
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
// 获取井对应的文件信息
|
|
|
var wellCurveFile = DBHelp.NewDb.Queryable<WellCurveFile>().First(item => item.JH == jh);
|
|
|
if (wellCurveFile == null)
|
|
|
{
|
|
|
return new List<WellCurve>();
|
|
|
}
|
|
|
|
|
|
// 获取文件路径
|
|
|
string filename = FileHelp.Convert2AbsolutePath(wellCurveFile.FilePath);
|
|
|
if (!File.Exists(filename))
|
|
|
{
|
|
|
return new List<WellCurve>();
|
|
|
}
|
|
|
|
|
|
// 读取 LAS 文件并转换为 DataTable
|
|
|
DataTable dataTable = new DataTable();
|
|
|
LasHelper.LasFileToDataTable(ref dataTable, filename, EncodingType.GetType(filename)?.BodyName, 0);
|
|
|
if (dataTable.Rows.Count == 0 || dataTable.Columns.Count <= 1)
|
|
|
{
|
|
|
return new List<WellCurve>();
|
|
|
}
|
|
|
|
|
|
// 解析 DataTable 数据
|
|
|
return dataTable.AsEnumerable()
|
|
|
.Select(row => new WellCurve
|
|
|
{
|
|
|
JH = jh,
|
|
|
DEPTH = Convert.ToDouble(row[0]),
|
|
|
ColumnValues = dataTable.Columns.Cast<DataColumn>()
|
|
|
.Skip(1)
|
|
|
.ToDictionary(col => col.ColumnName, col => row[col].ToString()),
|
|
|
})
|
|
|
.ToList();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine($"读取井曲线数据出错: {ex.Message}");
|
|
|
return new List<WellCurve>();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 列表转DataTable,用于自定义表
|
|
|
/// </summary>
|
|
|
/// <param name="list">The list.</param>
|
|
|
/// <returns>A DataTable.</returns>
|
|
|
public static DataTable ResTableByList<T>(List<T> list)
|
|
|
{
|
|
|
List<IDictionary<string, object>> lst_pairs = new List<IDictionary<string, object>>();
|
|
|
//转换
|
|
|
if (typeof(T) == typeof(HoriWellFracturParameter))
|
|
|
{
|
|
|
List<HoriWellFracturParameter> specificResults = list.Cast<HoriWellFracturParameter>().ToList();
|
|
|
foreach (var item in specificResults)
|
|
|
{
|
|
|
item.ColumnValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(item.ColumnValue);
|
|
|
var dic = item.ColumnValues;
|
|
|
Dictionary<string, object> dynamicDictionary = new Dictionary<string, object>
|
|
|
{
|
|
|
{ "JH", item.JH },
|
|
|
{ "XHID", item.XHID },
|
|
|
{ "SYWZ1", item.SYWZ1 },
|
|
|
{ "SYWZ2", item.SYWZ2 },
|
|
|
{ "RowID",item.RowID },
|
|
|
};
|
|
|
foreach (var k in dic)
|
|
|
{
|
|
|
if (!dynamicDictionary.ContainsKey(k.Key))
|
|
|
{
|
|
|
dynamicDictionary.Add(k.Key, k.Value);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dynamicDictionary[k.Key] = k.Value;
|
|
|
//这里存在错误,理论不应该出现此情况
|
|
|
}
|
|
|
}
|
|
|
lst_pairs.Add(dynamicDictionary);
|
|
|
}
|
|
|
}
|
|
|
else if (typeof(T) == typeof(WellCurve))
|
|
|
{
|
|
|
List<WellCurve> specificResults = list.Cast<WellCurve>().ToList();
|
|
|
foreach (var item in specificResults)
|
|
|
{
|
|
|
item.ColumnValues = JsonConvert.DeserializeObject<Dictionary<string, string>>(item.ColumnValue);
|
|
|
var dic = item.ColumnValues;
|
|
|
Dictionary<string, object> dynamicDictionary = new Dictionary<string, object>
|
|
|
{
|
|
|
{ "JH", item.JH },
|
|
|
{ "DEPTH", item.DEPTH },
|
|
|
{ "RowID",item.RowID },
|
|
|
};
|
|
|
|
|
|
foreach (var k in dic)
|
|
|
{
|
|
|
dynamicDictionary.Add(k.Key, k.Value);
|
|
|
}
|
|
|
lst_pairs.Add(dynamicDictionary);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
}
|
|
|
// 创建一个包含所有可能键的 HashSet(用于去重)
|
|
|
HashSet<string> allKeys = new HashSet<string>();
|
|
|
// 遍历每个字典来收集所有可能的键
|
|
|
foreach (var dict in lst_pairs)
|
|
|
{
|
|
|
foreach (var key in dict.Keys)
|
|
|
{
|
|
|
allKeys.Add(key);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 创建一个新的 DataTable
|
|
|
DataTable dataTable = new DataTable();
|
|
|
|
|
|
// 添加所有可能的列
|
|
|
foreach (var key in allKeys)
|
|
|
{
|
|
|
dataTable.Columns.Add(key, typeof(string));
|
|
|
}
|
|
|
|
|
|
// 将字典中的每个键值对添加到表中
|
|
|
foreach (var dict in lst_pairs)
|
|
|
{
|
|
|
DataRow row = dataTable.NewRow();
|
|
|
|
|
|
foreach (var kvp in dict)
|
|
|
{
|
|
|
row[kvp.Key] = kvp.Value;
|
|
|
}
|
|
|
dataTable.Rows.Add(row);
|
|
|
}
|
|
|
return dataTable;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 通过井号获取 WellCurve 数据
|
|
|
/// </summary>
|
|
|
/// <param name="jh">井号</param>
|
|
|
/// <returns>WellCurveData</returns>
|
|
|
public static List<WellCurve> GetWellCurvesStream(string jh)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(jh))
|
|
|
{
|
|
|
return new List<WellCurve>();
|
|
|
}
|
|
|
|
|
|
// 获取井对应的文件信息
|
|
|
var wellCurveFile = DBHelp.NewDb.Queryable<WellCurveFile>().First(item => item.JH == jh);
|
|
|
if (wellCurveFile == null)
|
|
|
{
|
|
|
return new List<WellCurve>();
|
|
|
}
|
|
|
|
|
|
// 获取文件路径
|
|
|
string filename = FileHelp.Convert2AbsolutePath(wellCurveFile.FilePath);
|
|
|
if (!File.Exists(filename))
|
|
|
{
|
|
|
return new List<WellCurve>();
|
|
|
}
|
|
|
|
|
|
return LasHelper.LasFileToList(jh, filename, EncodingType.GetType(filename)?.BodyName).ToList();
|
|
|
}
|
|
|
|
|
|
public static Dictionary<string, DataTable> SplitDataTableByColumn(DataTable originalTable, string columnName)
|
|
|
{
|
|
|
Dictionary<string, DataTable> groupedTables = new Dictionary<string, DataTable>();
|
|
|
|
|
|
foreach (DataRow row in originalTable.Rows)
|
|
|
{
|
|
|
string columnValue = row[columnName].ToString();
|
|
|
|
|
|
if (!groupedTables.ContainsKey(columnValue))
|
|
|
{
|
|
|
DataTable newTable = originalTable.Clone();
|
|
|
groupedTables[columnValue] = newTable;
|
|
|
}
|
|
|
|
|
|
groupedTables[columnValue].ImportRow(row);
|
|
|
}
|
|
|
|
|
|
return groupedTables;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 同步储层数据 (有效厚度发生变化)
|
|
|
/// </summary>
|
|
|
public static void SyncReservoirData<T>(string v_jh, ProgressCallbackThree progressCallback = null)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
List<string> arys = new List<string>();
|
|
|
if (typeof(T) == typeof(CcsjKxd))
|
|
|
{
|
|
|
arys = new List<string>() { "kxd", "bhd" };
|
|
|
}
|
|
|
else if (typeof(T) == typeof(CcsjBhd))
|
|
|
{
|
|
|
arys = new List<string>() { "bhd" };
|
|
|
}
|
|
|
else if (typeof(T) == typeof(CcsjStl))
|
|
|
{
|
|
|
arys = new List<string>() { "stl" };
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
arys = new List<string>() { "kxd", "bhd", "stl" };
|
|
|
}
|
|
|
|
|
|
//获取有效厚度
|
|
|
List<CcsjYxhd> yxhds = DBHelp.NewDb.Queryable<CcsjYxhd>().WhereIF(!string.IsNullOrWhiteSpace(v_jh), x => x.JH == v_jh).ToList();
|
|
|
|
|
|
Dictionary<string, List<CcsjYxhd>> dict_yxhds = yxhds.GroupBy(x => x.JH).ToDictionary(x => x.Key, x => x.ToList());
|
|
|
|
|
|
List<CcsjKxd> kxds = DBHelp.NewDb.Queryable<CcsjKxd>().WhereIF(!string.IsNullOrWhiteSpace(v_jh), x => x.JH == v_jh).ToList();
|
|
|
if (arys.Contains("kxd"))
|
|
|
{
|
|
|
int processedCount = 0;
|
|
|
int totalCount = kxds.Count;
|
|
|
Parallel.ForEach(kxds, kxd =>
|
|
|
{
|
|
|
if (dict_yxhds.TryGetValue(kxd.JH, out List<CcsjYxhd> hds))
|
|
|
{
|
|
|
var hd = hds.Where(x => x.CW == kxd.CW);
|
|
|
if (kxd.DJSD1.HasValue)
|
|
|
{
|
|
|
hd = hd.Where(x => x.DJSD1 == kxd.DJSD1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
hd = hd.Where(x => x.YXCS_T == kxd.YXCS_T);
|
|
|
}
|
|
|
if (hd.Count() > 0)
|
|
|
{
|
|
|
if (kxd.YXHD == null)
|
|
|
{
|
|
|
kxd.YXHD = hd.Average(x => x.YXHD);
|
|
|
}
|
|
|
|
|
|
if (kxd.YXHD_CS == null)
|
|
|
{
|
|
|
kxd.YXHD_CS = hd.Average(x => x.YXCS_HD);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Interlocked.Increment(ref processedCount);
|
|
|
progressCallback?.Invoke("同步有效到孔隙度", processedCount, totalCount);
|
|
|
});
|
|
|
DBHelp.NewDb.Fastest<CcsjKxd>().BulkUpdateAsync(kxds, new string[] { "JH", "CW", "ID" }, new string[] { "YXHD", "YXHD_CS" });
|
|
|
}
|
|
|
List<CcsjBhd> bhds = new List<CcsjBhd>();
|
|
|
if (arys.Contains("bhd"))
|
|
|
{
|
|
|
bhds = DBHelp.NewDb.Queryable<CcsjBhd>().WhereIF(!string.IsNullOrWhiteSpace(v_jh), x => x.JH == v_jh).ToList();
|
|
|
int processedCount = 0;
|
|
|
int totalCount = bhds.Count;
|
|
|
Parallel.ForEach(bhds, bhd =>
|
|
|
{
|
|
|
if (dict_yxhds.TryGetValue(bhd.JH, out List<CcsjYxhd> hds))
|
|
|
{
|
|
|
var hd = hds.Where(x => x.CW == bhd.CW);
|
|
|
if (bhd.DJSD1.HasValue)
|
|
|
{
|
|
|
hd = hd.Where(x => x.DJSD1 == bhd.DJSD1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
hd = hd.Where(x => x.YXCS_T == bhd.YXCS_T);
|
|
|
}
|
|
|
if (hd.Count() > 0)
|
|
|
{
|
|
|
if (bhd.YXHD == null)
|
|
|
{
|
|
|
bhd.YXHD = hd.Average(x => x.YXHD);
|
|
|
}
|
|
|
|
|
|
if (bhd.YXHD_CS == null)
|
|
|
{
|
|
|
bhd.YXHD_CS = hd.Average(x => x.YXCS_HD);
|
|
|
}
|
|
|
|
|
|
var kx = kxds.Where(x => x.JH == bhd.JH && x.CW == bhd.CW);
|
|
|
if (bhd.DJSD1.HasValue)
|
|
|
{
|
|
|
kx = kx.Where(x => x.DJSD1 == bhd.DJSD1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
kx = kx.Where(x => x.YXCS_T == bhd.YXCS_T);
|
|
|
}
|
|
|
if (kx.Count() > 0)
|
|
|
{
|
|
|
bhd.KXD = kx.Average(x => x.KXD);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Interlocked.Increment(ref processedCount);
|
|
|
progressCallback?.Invoke("同步有效和孔隙度到饱和度", processedCount, totalCount);
|
|
|
});
|
|
|
DBHelp.NewDb.Fastest<CcsjBhd>().BulkUpdateAsync(bhds, new string[] { "JH", "CW", "ID" }, new string[] { "YXHD", "YXHD_CS", "KXD" });
|
|
|
}
|
|
|
List<CcsjStl> stls = new List<CcsjStl>();
|
|
|
if (arys.Contains("stl"))
|
|
|
{
|
|
|
stls = DBHelp.NewDb.Queryable<CcsjStl>().WhereIF(!string.IsNullOrWhiteSpace(v_jh), x => x.JH == v_jh).ToList();
|
|
|
int processedCount = 0;
|
|
|
int totalCount = stls.Count;
|
|
|
Parallel.ForEach(stls, stl =>
|
|
|
{
|
|
|
if (dict_yxhds.TryGetValue(stl.JH, out List<CcsjYxhd> hds))
|
|
|
{
|
|
|
var hd = hds.Where(x => x.CW == stl.CW);
|
|
|
if (stl.DJSD1.HasValue)
|
|
|
{
|
|
|
hd = hd.Where(x => x.DJSD1 == stl.DJSD1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
hd = hd.Where(x => x.YXCS_T == stl.YXCS_T);
|
|
|
}
|
|
|
if (hd.Count() > 0)
|
|
|
{
|
|
|
if (stl.YXHD == null)
|
|
|
{
|
|
|
stl.YXHD = hd.Average(x => x.YXHD);
|
|
|
}
|
|
|
|
|
|
if (stl.YXHD_CS == null)
|
|
|
{
|
|
|
stl.YXHD_CS = hd.Average(x => x.YXCS_HD);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Interlocked.Increment(ref processedCount);
|
|
|
progressCallback?.Invoke("同步有效到渗透率", processedCount, totalCount);
|
|
|
});
|
|
|
DBHelp.NewDb.Fastest<CcsjStl>().BulkUpdateAsync(stls, new string[] { "JH", "CW", "ID" }, new string[] { "YXHD", "YXHD_CS" });
|
|
|
}
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|
|
|
// ignore Exception
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |