master
ZR20090193-陈敬勇 1 year ago
parent f4a1c76080
commit cda4bf0099

@ -5,17 +5,18 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup>
<!--//预定义配置节-->
<appSettings>
<add key="RedisStr" value="192.168.1.11:6379,defaultDatabase=1,poolsize=50,ssl=false,writeBuffer=10240"/>
<!--<add key="RedisStr" value="192.168.1.11:6379,defaultDatabase=1,poolsize=50,ssl=false,writeBuffer=10240"/>-->
<!--<add key="RedisStr" value="127.0.0.1:6379,defaultDatabase=1,poolsize=50,ssl=false,writeBuffer=10240"/>-->
<add key="RedisKey" value="EnterRecord"/>
<add key="pIP" value="192.168.1.98"/>
<!--<add key="RedisKey" value="EnterRecord"/>-->
<add key="pIP" value="10.115.246.150"/>
<add key="pIPUser" value="1"/>
<add key="SqlServerStr" value="Data Source=192.168.1.11;Initial Catalog=ShippingWeb_DJZ;Persist Security Info=True;User ID=sa;Password=Ds20040201;Connect Timeout=500;"/>
<add key="AccessStr" value="Provider = Microsoft.ACE.OLEDB.12.0;Data Source='//192.168.1.3/con-ocr/CONLOG.mdb';"/>
<add key="SqlServerStr" value="Data Source=10.112.6.193;Initial Catalog=ShippingWeb_DJZ;Persist Security Info=True;User ID=sa;Password=Ds20040201;Connect Timeout=500;"/>
<add key="AccessStr" value="Provider = Microsoft.ACE.OLEDB.12.0;Data Source='//10.115.246.138/con-ocr/CONLOG.mdb';"/>
<!--<add key="AccessStr" value="Provider = Microsoft.ACE.OLEDB.12.0;Data Source='//192.168.1.3/con-ocr/CONLOG.mdb';"/>-->
<!--<add key="AccessStr" value="Provider = Microsoft.ACE.OLEDB.12.0;Data Source='//192.168.1.11/con-ocr/CONLOG.mdb';"/>-->
<!--<add key="AccessStr" value="Provider = Microsoft.ACE.OLEDB.12.0;Data Source='//127.0.0.1/ModelGeneration/CONLOG.mdb';"/>-->
<!--<add key="AccessStr1" value="Provider = Microsoft.ACE.OLEDB.12.0;Data Source='//192.168.1.11/con-ocr/CONLOG.mdb';"/>-->
<add key="PostUrl" value="http://192.168.1.11:9991/api/OP_YARD_CTNMNG/PublicFunc"/>
<add key="PostUrl" value="http://10.112.6.193:9991/server/api/OP_YARD_CTNMNG/PublicFunc"/>
<!--<add key="RedisKey" value="OutWeight"/>-->
</appSettings>
<runtime>

@ -157,8 +157,8 @@ namespace PlatformScalePortReadData
serialPort.BaudRate = iBaudRate;//波特率
serialPort.DataBits = iDataBit;//数据位
//获取配置
key = ConfigurationManager.AppSettings["RedisKey"];
////获取配置
//key = ConfigurationManager.AppSettings["RedisKey"];
switch (strStopBit) //停止位
@ -286,15 +286,15 @@ namespace PlatformScalePortReadData
//thrRecv.Start();
redis = CsRedisHelper.GetInstance();
//redis = CsRedisHelper.GetInstance();
}
#region 相机识别结果回调函数
private void OnDataEx2Callback(ref CLIENT_LPRC_PLATE_RESULTEX recResultEx, uint dwUser)
{
//var redis = CsRedisHelper.GetInstance();
var key = ConfigurationManager.AppSettings["RedisKey"];
redis = CsRedisHelper.GetInstance();
//var key = ConfigurationManager.AppSettings["RedisKey"];
//redis = CsRedisHelper.GetInstance();
var result = string.Empty;
if (dwUser == 1)
{
@ -305,67 +305,76 @@ namespace PlatformScalePortReadData
{
decimal weight = ReadPortWeright();
textBoxReceive.AppendText("获取磅秤数据:" + weight);
textBoxReceive.AppendText("开始获取箱号:");
//获取箱号信息
var CTNNO = CONLOGService.GetCTNNO();
TimeSpan ts = (TimeSpan)(DateTime.Now - CTNNO.EntryTime);
if (ts.Minutes > 3)// 超时3分钟即为箱号为空
var res = CONLOGService.GetBoxNo();
if (res.Succeeded)
{
CTNNO = new Combined();
}
textBoxReceive.AppendText("获取箱号结果:" + JsonConvert.SerializeObject(res));
var CTNNO = res.Data as Combined;
TimeSpan ts = (TimeSpan)(DateTime.Now - CTNNO.EntryTime);
if (ts.Minutes > 3)// 超时3分钟即为箱号为空
{
CTNNO = new Combined();
}
var record = new TurnOverRecord();
record.BILLTYPE = false;
record.TRUCKNO = recRes1.chLicense;
record.BoxWeigth = weight;
record.ISTwoBox = false;
if (CTNNO.ConID1 != null && CTNNO.ConID2 == null)
{
record.BoxCode = CTNNO.ConID1;
}
else if (CTNNO.ConID1 == null && CTNNO.ConID2 != null)
{
record.BoxCode = CTNNO.ConID2;
}
else if (CTNNO.ConID1 == null && CTNNO.ConID1 == CTNNO.ConID2)
{
//空箱或者识别不出来
record.BoxCode = CTNNO.ConID1;
}
else if (CTNNO.ConID1 != null && CTNNO.ConID2 != null && CTNNO.ConID1 != CTNNO.ConID2)
{
//双背进
record.BoxCode = CTNNO.ConID1;
record.BoxCode2 = CTNNO.ConID2;
record.ISTwoBox = true;
}
textBoxReceive.AppendText("推送数据:车牌 " + record.TRUCKNO + " 箱号:" + record.BoxCode + " 箱号2:" + record.BoxCode2 + " 磅秤:" + record.BoxWeigth);
//缓存redis
redis.RPush(key, JsonConvert.SerializeObject(record));
if (redis.LLen(key) > 1000)
{
redis.LPop(key);
}
var record = new TurnOverRecord();
record.BILLTYPE = false;
record.TRUCKNO = recRes1.chLicense;
record.BoxWeigth = weight;
record.ISTwoBox = false;
if (CTNNO.ConID1 != null && CTNNO.ConID2 == null)
{
record.BoxCode = CTNNO.ConID1;
}
else if (CTNNO.ConID1 == null && CTNNO.ConID2 != null)
{
record.BoxCode = CTNNO.ConID2;
}
else if (CTNNO.ConID1 == null && CTNNO.ConID1 == CTNNO.ConID2)
{
//空箱或者识别不出来
record.BoxCode = CTNNO.ConID1;
}
else if (CTNNO.ConID1 != null && CTNNO.ConID2 != null && CTNNO.ConID1 != CTNNO.ConID2)
{
//双背进
record.BoxCode = CTNNO.ConID1;
record.BoxCode2 = CTNNO.ConID2;
record.ISTwoBox = true;
}
textBoxReceive.AppendText("推送数据:车牌 " + record.TRUCKNO + " 箱号:" + record.BoxCode + " 箱号2:" + record.BoxCode2 + " 磅秤:" + record.BoxWeigth);
if (YARDService.CheckBook(record.TRUCKNO, record.BoxCode))
{
result = YARDService.PublicFunc(record);
//抬杠
if (NativeMethods.CLIENT_LPRC_SetRelayClose(this.pIP, 8080) == 0)
////缓存redis
//redis.RPush(key, JsonConvert.SerializeObject(record));
//if (redis.LLen(key) > 1000)
//{
// redis.LPop(key);
//}
if (YARDService.CheckBook(record.TRUCKNO, record.BoxCode))
{
textBoxReceive.AppendText("自动抬杆成功!");
result = YARDService.PublicFunc(record);
//抬杠
if (NativeMethods.CLIENT_LPRC_SetRelayClose(this.pIP, 8080) == 0)
{
textBoxReceive.AppendText("自动抬杆成功!");
}
else
{
textBoxReceive.AppendText("自动抬杆失败!");
}
}
else
{
textBoxReceive.AppendText("自动抬杆失败!");
textBoxReceive.AppendText("未检测到预约数据:车牌 " + record.TRUCKNO + " 箱号:" + record.BoxCode + " 箱号2:" + record.BoxCode2 + ",请及时在客户端预约! ");
}
}
else
{
textBoxReceive.AppendText("未检测到预约数据:车牌 " + record.TRUCKNO + " 箱号:" + record.BoxCode + " 箱号2:" + record.BoxCode2 + ",请及时在客户端预约! " );
{
textBoxReceive.AppendText("获取箱号结果失败:" + JsonConvert.SerializeObject(res));
}
}
@ -393,7 +402,7 @@ namespace PlatformScalePortReadData
// }
//}
//while (a == true);
//获取箱号信息
var CTNNO = CONLOGService.GetCTNNO();
@ -430,12 +439,12 @@ namespace PlatformScalePortReadData
}
textBoxReceive.AppendText("推送数据:车牌 " + record.TRUCKNO + " 箱号:" + record.BoxCode + " 箱号2:" + record.BoxCode2 + " 磅秤:" + record.BoxWeigth);
//缓存redis
redis.RPush(key, JsonConvert.SerializeObject(record));
if (redis.LLen(key) > 1000)
{
redis.LPop(key);
}
////缓存redis
//redis.RPush(key, JsonConvert.SerializeObject(record));
//if (redis.LLen(key) > 1000)
//{
// redis.LPop(key);
//}
result = YARDService.PublicFunc(record);
//textBoxReceive.AppendText("出站返回结果: " + result);
@ -668,6 +677,7 @@ namespace PlatformScalePortReadData
/// <returns></returns>
public decimal ReadPortWeright()
{
textBoxReceive.AppendText("开始获取磅秤数据0");
//清空 buffer 缓存
buffer.Clear();
decimal weight = 0M;
@ -683,6 +693,7 @@ namespace PlatformScalePortReadData
serialPort.Read(byteData, 0, byteData.Length);
buffer.AddRange(byteData); //数据缓存
//textBoxReceive.AppendText("开始获取磅秤数据1:"+ buffer);
while (buffer.Count >= 17)
{
if (buffer[0] == 2 && buffer[1] == 49 && buffer[2] == 48 && buffer[16] == 13)// && buffer[13] == 48 && buffer[14] == 48

@ -0,0 +1,249 @@
using PlatformScalePortReadData.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlatformScalePortReadData.Model
{
/// <summary>
/// 业务操作结果信息类,对操作结果进行封装
/// </summary>
public class DataResult : DataResult<object>
{
static DataResult()
{
Success = new DataResult(ResultCode.Success);
NoChanged = new DataResult(ResultCode.NoChanged);
}
/// <summary>
/// 初始化一个<see cref="DataResult"/>类型的新实例
/// </summary>
public DataResult() : this(ResultCode.NoChanged)
{
}
/// <summary>
/// 初始化一个<see cref="DataResult"/>类型的新实例
/// </summary>
public DataResult(ResultCode resultType) : this(resultType, null, null)
{
}
/// <summary>
/// 初始化一个<see cref="DataResult"/>类型的新实例
/// </summary>
public DataResult(ResultCode resultType, string message) : this(resultType, message, null)
{
}
/// <summary>
/// 初始化一个<see cref="DataResult"/>类型的新实例
/// </summary>
public DataResult(ResultCode type, string message, object data) : base(type, message, data)
{
}
/// <summary>
/// 获取 成功的操作结果
/// </summary>
public static DataResult Success { get; private set; }
/// <summary>
/// 获取 未变更的操作结果
/// </summary>
public new static DataResult NoChanged { get; private set; }
/// <summary>
/// 将<see cref="DataResult{TData}"/>转换为<see cref="DataResult"/>
/// </summary>
/// <returns></returns>
public DataResult<T> ToDataResult<T>()
{
T data = default(T);
if (Data is T variable)
{
data = variable;
}
return new DataResult<T>(ResultCode.Success, Message, data);
}
/// <summary>
/// 返回成功的结果
/// </summary>
/// <param name="message">消息</param>
/// <param name="data">结果</param>
/// <returns></returns>
public static DataResult Successed(string message, object data)
{
return new DataResult(ResultCode.Success, message, data);
}
public static DataResult Successed(string message)
{
return new DataResult(ResultCode.Success, message, null);
}
/// <summary>
/// 其他操作
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public static DataResult Other(string message)
{
return new DataResult(ResultCode.Other, message, null);
}
/// <summary>
/// 返回失败的结果
/// </summary>
/// <param name="message">消息</param>
/// <returns></returns>
public static DataResult Failed(string message)
{
return new DataResult(ResultCode.Error, message);
}
}
public class DataResult<TData> : IDataResult<ResultCode, TData>
{
static DataResult()
{
NoChanged = new DataResult<TData>(ResultCode.NoChanged);
}
/// <summary>
/// 初始化一个<see cref="DataResult"/>类型的新实例
/// </summary>
public DataResult() : this(ResultCode.NoChanged)
{
}
/// <summary>
/// 初始化一个<see cref="DataResult{TData}"/>类型的新实例
/// </summary>
public DataResult(ResultCode resultType) : this(resultType, null, default(TData))
{
}
/// <summary>
/// 初始化一个<see cref="DataResult{TData}"/>类型的新实例
/// </summary>
public DataResult(ResultCode resultType, string message) : this(resultType, message, default(TData))
{
}
/// <summary>
/// 初始化一个<see cref="DataResult{TResultType,TData}"/>类型的新实例
/// </summary>
public DataResult(ResultCode type, string message, TData data, int count = 0)
{
if (message == null)
{
message = (type as Enum)?.EnumDescription();
}
Code = type;
_message = message;
Data = data;
Count = count;
}
/// <summary>
/// 结果码
/// </summary>
public ResultCode Code { get; set; }
private string _message;
/// <summary>
/// 总记录数
/// </summary>
public int Count { get; set; }
/// <summary>
/// 获取 未变更的操作结果
/// </summary>
public virtual string Message
{
get => _message ?? Code.EnumDescription();
set => _message = value;
}
/// <summary>
/// 获取 未变更的操作结果
/// </summary>
public static DataResult<TData> NoChanged { get; private set; }
/// <summary>
/// 获取 是否成功
/// </summary>
public bool Succeeded => Code == ResultCode.Success;
public TData Data { get; set; }
/// <summary>
/// 返回成功的结果
/// </summary>
/// <param name="message">消息</param>
/// <param name="data">结果</param>
/// <returns></returns>
public static DataResult<TData> Success(string message, TData data)
{
return new DataResult<TData>(ResultCode.Success, message, data);
}
/// <summary>
/// 返回成功的结果
/// </summary>
/// <param name="data">结果</param>
/// <returns></returns>
public static DataResult<TData> Success(TData data)
{
return new DataResult<TData>(ResultCode.Success, string.Empty, data);
}
/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <param name="ResultCode"></param>
/// <returns></returns>
public static DataResult<TData> Failed(string message, ResultCode ResultCode = ResultCode.Error)
{
return new DataResult<TData>(ResultCode, message);
}
/// <summary>
///
/// </summary>
/// <param name="count"></param>
/// <param name="data"></param>
/// <returns></returns>
public static DataResult<TData> PageList(int count, TData data)
{
return new DataResult<TData>(ResultCode.Success, string.Empty, data, count);
}
/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public static DataResult<TData> Error(string message)
{
return new DataResult<TData>(ResultCode.Error, message, default(TData));
}
/// <summary>
/// 异常的DataResult
/// </summary>
public static DataResult<TData> Exception()
{
return new DataResult<TData>(ResultCode.Error, "程序异常,请联系管理员!", default(TData));
}
}
}

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlatformScalePortReadData.Model
{
/// <summary>
/// 操作结果类
/// </summary>
/// <typeparam name="TResultCode"></typeparam>
public interface IDataResult<TResultCode> : IDataResult<TResultCode, object>
{
}
/// <summary>
/// 操作结果类
/// </summary>
/// <typeparam name="TResultCode"></typeparam>
/// <typeparam name="TData"></typeparam>
public interface IDataResult<TResultCode, TData>
{
/// <summary>
/// 获取或设置结果类型
/// </summary>
TResultCode Code { get; set; }
/// <summary>
/// 获取或设置 返回消息
/// </summary>
string Message { get; set; }
/// <summary>
/// 获取或设置 结果数据
/// </summary>
TData Data { get; set; }
}
}

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PlatformScalePortReadData.Model
{
/// <summary>
/// 返回结果枚举
/// </summary>
public enum ResultCode
{
/// <summary>
/// 成功结果类型
/// </summary>
[Description("操作成功")]
Success = 0,
/// <summary>
/// 操作取消或操作没引发任何变化
/// </summary>
[Description("操作没引发任何变化")]
NoChanged = 1,
/// <summary>
/// 失败结果类型
/// </summary>
[Description("操作失败")]
Fail = -1,
/// <summary>
/// 异常结果类型
/// </summary>
[Description("操作异常")]
Error = -2,
/// <summary>
/// 其他
/// </summary>
[Description("其他")]
Other = -3,
}
}

@ -166,7 +166,11 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Model\DataResult.cs" />
<Compile Include="Model\IDataResult.cs" />
<Compile Include="Model\ResultCode.cs" />
<Compile Include="Model\VW_OP_YARD_CTNMNG_DJZ.cs" />
<Compile Include="Utils\EnumUtil.cs" />
<Compile Include="Utils\StringUtil.cs" />
<Compile Include="Utils\CsRedisHelper.cs" />
<Compile Include="Form1.cs">
@ -212,7 +216,9 @@
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="App.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">

@ -28,5 +28,28 @@ namespace PlatformScalePortReadData.Service
return CTNNO;
}
public static DataResult GetBoxNo()
{
var CTNNO = new Combined();
try
{
//获取进站箱号信息
using (var db = SqlSugarFactory.GetInstance("2"))
{
//.Where(x => x.ConID1 != null)
CTNNO = db.Queryable<Combined>().OrderByDescending(x => x.EntryTime).First();
}
return DataResult.Successed("获取成功!",CTNNO);
}
catch (Exception ex)
{
return DataResult.Failed(ex.ToString());
//throw;
}
}
}
}

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace PlatformScalePortReadData.Utils
{
/// <summary>
/// 枚举工具类
/// </summary>
public static class EnumUtil
{
/// <summary>
/// 字符串转Enum
/// </summary>
/// <typeparam name="T">枚举</typeparam>
/// <param name="str">字符串</param>
/// <returns>转换的枚举</returns>
public static T ToEnum<T>(this string str)
{
try
{
return (T)Enum.Parse(typeof(T), str);
}
catch
{
return default(T);
}
}
/// <summary>
/// 获取到对应枚举的描述-没有描述信息,返回枚举值
/// </summary>
/// <param name="enum"></param>
/// <returns></returns>
public static string EnumDescription(this Enum @enum)
{
Type type = @enum.GetType();
string name = Enum.GetName(type, @enum);
if (name == null)
{
return null;
}
FieldInfo field = type.GetField(name);
if (!(Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute attribute))
{
return name;
}
return attribute?.Description;
}
public static int ToEnumInt(this Enum e)
{
try
{
return e.GetHashCode();
}
catch (Exception)
{
return 0;
}
}
}
}
Loading…
Cancel
Save