MES登录接口设置

This commit is contained in:
liming 蔡
2026-07-15 15:21:17 +08:00
parent 0218c38cd5
commit bbfb08a24a
13 changed files with 362 additions and 31 deletions
+55 -7
View File
@@ -1,4 +1,9 @@
using System;
using JY.Inspection.Enums;
using JY.Inspection.Mes;
using JY.MES.Entity;
using JY.MES.MES;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
@@ -36,14 +41,11 @@ namespace JY.Inspection.Common
///
[Display(Name = "密码")]
public string PassWord { get; set; }
/// <summary>
/// 权限
/// </summary>
///
[Display(Name = "权限")]
public Autuority Level { get; set; }
}
/// <summary>
/// 权限枚举
/// </summary>
@@ -54,7 +56,6 @@ namespace JY.Inspection.Common
操作员,//操作员
Empty,
}
public class UserHelper
{
private string filePath = string.Empty;
@@ -292,5 +293,52 @@ namespace JY.Inspection.Common
}
return user;
}
/// <summary>
/// 使用MES员工信息接口校验登录信息
/// </summary>
/// <returns></returns>
public User CheckMesUserLogin(string userName, string passWord, ref string strErr)
{
User user = null;
ReqLoginMes req = new ReqLoginMes()
{
SiteCode = Global.systemConfig.siteCode,
LineCode = Global.systemConfig.lineCode,
EquipNum = Global.systemConfig.equipCode,
UserName = userName,
PassWord = passWord,
UserCardID = string.Empty
};
string strJson = JsonConvert.SerializeObject(req);
MesCallResult<RespLoginMes> result = new MESDataCombin().LoginMes(req);
if (result.IsSuccess && result.OriResponse?.Rows.Length == 1)
{
// TODO 权限转化
string levelStr = result.OriResponse.Rows[0].PermissionLevel;
bool resultLevel = Int32.TryParse(levelStr, out int level);
if (!resultLevel)
{
strErr = $"权限转化失败,权限值为:{levelStr}";
return user;
}
user = new User() {
UserName = result.OriResponse.Rows[0].Username,
Level = level.ToEnum<EnumAutority>().MapperEnum()
};
}
else
{
strErr = string.IsNullOrEmpty(result.OriResponse?.Message) ? result.ErrorMessage : result.OriResponse?.Message;
}
return user;
}
}
}
+35
View File
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JY.Inspection.Enums
{
/// <summary>
/// 用户权限
/// </summary>
public enum EnumAutority
{
/// <summary>
/// 管理员
/// </summary>
[Description("管理员")]
Administrator = 1,
/// <summary>
/// 工程师
/// </summary>
[Description("工程师")]
Engineer = 2,
/// <summary>
/// 操作员
/// </summary>
[Description("操作员")]
Operator = 3,
None = 4
}
}
+56
View File
@@ -0,0 +1,56 @@
using JY.Inspection.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace JY.Inspection.Enums
{
public static class EnumExtension
{
// 输入枚举,获取其Description属性对应的名称
public static string GetDescription(this Enum value)
{
FieldInfo field = value.GetType().GetField(value.ToString());
if (field != null)
{
DescriptionAttribute attribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
if (attribute != null)
{
return attribute.Description;
}
}
return value.ToString();
}
// 输入数字,转化成对应的枚举
public static T ToEnum<T>(this int value)
{
return (T)Enum.ToObject(typeof(T), value);
}
public static Autuority MapperEnum(this EnumAutority srcEnum)
{
switch (srcEnum)
{
case EnumAutority.Administrator:
return Autuority.管理员;
case EnumAutority.Engineer:
return Autuority.工程师;
case EnumAutority.Operator:
return Autuority.操作员;
case EnumAutority.None:
return Autuority.Empty;
default:
return Autuority.Empty;
}
}
}
}
+20 -3
View File
@@ -43,7 +43,6 @@ namespace JY.Inspection.Frm
TimeSpan ts = _tempDt.Subtract(_dt);
if (ts.Milliseconds > 100)
{
txtPassword2.Text = "";//清空
}
else
@@ -75,7 +74,6 @@ namespace JY.Inspection.Frm
}
private void btLogin_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtUserID.Text) | string.IsNullOrEmpty(txtPassWord.Text))
{
txtUserID.Focus();
@@ -84,12 +82,31 @@ namespace JY.Inspection.Frm
}
UserHelper helper = new UserHelper("");
string strErr = "";
var res = helper.CheckUserLogin("user.pt", txtUserID.Text.Trim(), txtPassWord.Text.Trim(), ref strErr);
User res = null;
if (check_isMesLogin.Checked)
{
res = helper.CheckMesUserLogin(txtUserID.Text.Trim(), txtPassWord.Text.Trim(), ref strErr);
}
else
{
res = helper.CheckUserLogin("user.pt", txtUserID.Text.Trim(), txtPassWord.Text.Trim(), ref strErr);
}
if (res == null)
{
txtPassWord.Focus();
loginFailedCount++;
if (check_isMesLogin.Checked)
{
MessageBox.Show($"使用MES账户登录失败,错误信息: {strErr}!", "系统提示");
}
else
{
MessageBox.Show($"用户名或密码不正确,登录失败({loginFailedCount})次!", "系统提示");
}
return;
}
+29 -13
View File
@@ -42,6 +42,7 @@ namespace JY.Inspection.Frm
this.pLogin_card = new System.Windows.Forms.Panel();
this.lblICCard = new MetroFramework.Controls.MetroLabel();
this.txtPassword2 = new MetroFramework.Controls.MetroTextBox();
this.check_isMesLogin = new MetroFramework.Controls.MetroCheckBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.pLogin_pwd.SuspendLayout();
this.pLogin_card.SuspendLayout();
@@ -51,7 +52,7 @@ namespace JY.Inspection.Frm
//
this.chkIsSK.AutoSize = true;
this.chkIsSK.Location = new System.Drawing.Point(237, 390);
this.chkIsSK.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.chkIsSK.Margin = new System.Windows.Forms.Padding(4);
this.chkIsSK.Name = "chkIsSK";
this.chkIsSK.Size = new System.Drawing.Size(168, 17);
this.chkIsSK.TabIndex = 20;
@@ -61,7 +62,7 @@ namespace JY.Inspection.Frm
// btExit
//
this.btExit.Location = new System.Drawing.Point(279, 428);
this.btExit.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.btExit.Margin = new System.Windows.Forms.Padding(4);
this.btExit.Name = "btExit";
this.btExit.Size = new System.Drawing.Size(127, 46);
this.btExit.TabIndex = 22;
@@ -72,7 +73,7 @@ namespace JY.Inspection.Frm
// btLogin
//
this.btLogin.Location = new System.Drawing.Point(81, 428);
this.btLogin.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.btLogin.Margin = new System.Windows.Forms.Padding(4);
this.btLogin.Name = "btLogin";
this.btLogin.Size = new System.Drawing.Size(127, 46);
this.btLogin.TabIndex = 21;
@@ -83,7 +84,7 @@ namespace JY.Inspection.Frm
//
this.pictureBox1.Image = global::JY.Inspection.Properties.Resources.登录;
this.pictureBox1.Location = new System.Drawing.Point(153, 55);
this.pictureBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.pictureBox1.Margin = new System.Windows.Forms.Padding(4);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(168, 165);
this.pictureBox1.TabIndex = 18;
@@ -95,10 +96,10 @@ namespace JY.Inspection.Frm
//
//
this.txtUserID.CustomButton.Image = null;
this.txtUserID.CustomButton.Location = new System.Drawing.Point(236, 1);
this.txtUserID.CustomButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.txtUserID.CustomButton.Location = new System.Drawing.Point(177, 1);
this.txtUserID.CustomButton.Margin = new System.Windows.Forms.Padding(4);
this.txtUserID.CustomButton.Name = "";
this.txtUserID.CustomButton.Size = new System.Drawing.Size(36, 34);
this.txtUserID.CustomButton.Size = new System.Drawing.Size(27, 27);
this.txtUserID.CustomButton.Style = MetroFramework.MetroColorStyle.Blue;
this.txtUserID.CustomButton.TabIndex = 1;
this.txtUserID.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light;
@@ -107,7 +108,7 @@ namespace JY.Inspection.Frm
this.txtUserID.Lines = new string[] {
"Admin"};
this.txtUserID.Location = new System.Drawing.Point(108, 16);
this.txtUserID.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.txtUserID.Margin = new System.Windows.Forms.Padding(4);
this.txtUserID.MaxLength = 32767;
this.txtUserID.Name = "txtUserID";
this.txtUserID.PasswordChar = '\0';
@@ -131,10 +132,10 @@ namespace JY.Inspection.Frm
//
//
this.txtPassWord.CustomButton.Image = null;
this.txtPassWord.CustomButton.Location = new System.Drawing.Point(236, 1);
this.txtPassWord.CustomButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.txtPassWord.CustomButton.Location = new System.Drawing.Point(177, 1);
this.txtPassWord.CustomButton.Margin = new System.Windows.Forms.Padding(4);
this.txtPassWord.CustomButton.Name = "";
this.txtPassWord.CustomButton.Size = new System.Drawing.Size(36, 34);
this.txtPassWord.CustomButton.Size = new System.Drawing.Size(27, 27);
this.txtPassWord.CustomButton.Style = MetroFramework.MetroColorStyle.Blue;
this.txtPassWord.CustomButton.TabIndex = 1;
this.txtPassWord.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light;
@@ -143,7 +144,7 @@ namespace JY.Inspection.Frm
this.txtPassWord.Lines = new string[] {
"Admin"};
this.txtPassWord.Location = new System.Drawing.Point(108, 60);
this.txtPassWord.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.txtPassWord.Margin = new System.Windows.Forms.Padding(4);
this.txtPassWord.MaxLength = 32767;
this.txtPassWord.Name = "txtPassWord";
this.txtPassWord.PasswordChar = '*';
@@ -246,11 +247,25 @@ namespace JY.Inspection.Frm
this.txtPassword2.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109)))));
this.txtPassword2.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel);
//
// check_isMesLogin
//
this.check_isMesLogin.AutoSize = true;
this.check_isMesLogin.Checked = true;
this.check_isMesLogin.CheckState = System.Windows.Forms.CheckState.Checked;
this.check_isMesLogin.Location = new System.Drawing.Point(81, 390);
this.check_isMesLogin.Margin = new System.Windows.Forms.Padding(4);
this.check_isMesLogin.Name = "check_isMesLogin";
this.check_isMesLogin.Size = new System.Drawing.Size(114, 17);
this.check_isMesLogin.TabIndex = 28;
this.check_isMesLogin.Text = "MES员工登录";
this.check_isMesLogin.UseSelectable = true;
//
// LoginForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(472, 529);
this.Controls.Add(this.check_isMesLogin);
this.Controls.Add(this.pLogin_pwd);
this.Controls.Add(this.pLogin_card);
this.Controls.Add(this.chkIsSK);
@@ -258,7 +273,7 @@ namespace JY.Inspection.Frm
this.Controls.Add(this.btLogin);
this.Controls.Add(this.pictureBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.Margin = new System.Windows.Forms.Padding(4);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "LoginForm";
@@ -290,5 +305,6 @@ namespace JY.Inspection.Frm
private System.Windows.Forms.Panel pLogin_card;
private MetroFramework.Controls.MetroLabel lblICCard;
private MetroFramework.Controls.MetroTextBox txtPassword2;
private MetroFramework.Controls.MetroCheckBox check_isMesLogin;
}
}
-2
View File
@@ -137,8 +137,6 @@ namespace JY.Inspection.Frm
/// <param name="e"></param>
private void btAdd_Click(object sender, EventArgs e)
{
User user = GetUser(ListUser);
var res = helper.AddUser("user.pt", ListUser, user);
if (res)
+6 -5
View File
@@ -8,6 +8,7 @@ using JY.DAL.Repository;
using JY.DAL.Service;
using JY.Inspection.Common;
using JY.Inspection.Entity;
using JY.Inspection.Enums;
using JY.Inspection.Frm;
using JY.Inspection.Mes;
using JY.MES;
@@ -1235,11 +1236,11 @@ namespace JY.Inspection
/// <param name="e"></param>
private void tsmiUserConfig_Click(object sender, EventArgs e)
{
if (!CheckAdmin())
{
MessageBox.Show("权限不足", "系统提示");
return;
}
//if (!CheckAdmin())
//{
// MessageBox.Show("权限不足", "系统提示");
// return;
//}
SetForm setForm = new SetForm();
setForm.ShowDialog();
}
+2
View File
@@ -190,6 +190,8 @@
<Compile Include="Common\DGShowMsg.cs" />
<Compile Include="Common\DateTimeSynchronization.cs" />
<Compile Include="Entity\AlarmStatus.cs" />
<Compile Include="Enums\EnumAutority.cs" />
<Compile Include="Enums\EnumExtension.cs" />
<Compile Include="Frm\FormMesGradingSet.cs">
<SubType>Form</SubType>
</Compile>
+46
View File
@@ -45,6 +45,8 @@ namespace JY.Inspection.Mes
/// <param name="req"></param>
/// <returns></returns>
RespExitStation PostProductExitStationData(ReqExitStation req);
MesCallResult<RespLoginMes> LoginMes(ReqLoginMes req);
}
public class MESDataCombin : IMes
@@ -310,5 +312,49 @@ namespace JY.Inspection.Mes
return resp;
}
public MesCallResult<RespLoginMes> LoginMes(ReqLoginMes req)
{
if (req == null)
{
throw new ArgumentNullException("MES员工登录请求信息为空");
}
// TODO MES登录请求地址
DateTime currentTime = DateTime.Now;
string reqUrl = string.Empty;
MesCallResult<RespLoginMes> resp = new MesCallResult<RespLoginMes>();
try
{
string reqJsonStr = JsonConvert.SerializeObject(req);
var sw = new Stopwatch();
sw.Start();
string mesRes = MESApiHelper.HttpPostJsonAPI(
reqUrl,
reqJsonStr,
Global.systemConfig.MesRequestTime
);
resp = MESApiHelper.HttpPostJsonAPI<RespLoginMes>(reqUrl, reqJsonStr, Global.systemConfig.MesRequestTime);
sw.Stop();
if (resp?.OriResponse != null && resp?.OriResponse.Success != true)
{
resp.IsSuccess = false;
resp.ErrorType = MesErrorType.BusinessError;
resp.ErrorMessage = resp?.OriResponse?.Message ?? "MES业务处理失败, 错误消息为空";
}
new MesLog().LogLoginMes(currentTime, reqJsonStr, resp.OriRespJsonStr, sw.ElapsedMilliseconds);
}
catch (Exception ex)
{
resp.IsSuccess = false;
resp.ErrorType = MesErrorType.ClientError;
resp.ErrorMessage = "获取MES员工登录信息异常:" + ex.Message;
}
return resp;
}
}
}
+9
View File
@@ -15,6 +15,8 @@ namespace JY.Inspection.Mes
void LogArrivalStation(DateTime curTime, string reqJsonStr, string respMes, long costTime);
void LogExitStation(DateTime curTime, string reqJsonStr, string respMes, long costTime);
void LogLoginMes(DateTime curTime, string reqJsonStr, string respMes, long costTime);
}
public class MesLog : IMesLog
@@ -62,5 +64,12 @@ namespace JY.Inspection.Mes
LogoutAction(actionName, curTime, reqJsonStr, respMes, costTime);
}
public void LogLoginMes(DateTime curTime, string reqJsonStr, string respMes, long costTime)
{
string actionName = "Mes员工登录";
LogoutAction(actionName, curTime, reqJsonStr, respMes, costTime);
}
}
}
+2
View File
@@ -73,9 +73,11 @@
<Compile Include="MES\ProductResultParameters.cs" />
<Compile Include="MES\ReqArrivalStation.cs" />
<Compile Include="MES\ReqExitStation.cs" />
<Compile Include="MES\ReqLoginMes.cs" />
<Compile Include="MES\RespArrivalStation.cs" />
<Compile Include="MES\RespBase.cs" />
<Compile Include="MES\RespExitStation.cs" />
<Compile Include="MES\RespLoginMes.cs" />
<Compile Include="MES\RespProductResult.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
+44
View File
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JY.MES.MES
{
/// <summary>
/// 登录MES
/// </summary>
public class ReqLoginMes
{
/// <summary>
/// 工厂代码
/// </summary>
public string SiteCode { get; set; }
/// <summary>
/// 产线编号
/// </summary>
public string LineCode { get; set; }
/// <summary>
/// 设备编号
/// </summary>
public string EquipNum { get; set; }
/// <summary>
/// 员工账号 账号登录时,账号,密码必填
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 员工密码
/// </summary>
public string PassWord { get; set; }
/// <summary>
/// 员工卡号 刷卡时,卡号必填
/// </summary>
public string UserCardID { get; set; }
}
}
+57
View File
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JY.MES.MES
{
/// <summary>
/// MES登录响应
/// </summary>
public class RespLoginMes
{
/// <summary>
/// 错误代码,成功不返回
/// </summary>
public string ErrorCode { get; set; }
/// <summary>
/// 成功标识 (false失败 true 成功)
/// </summary>
public bool Success { get; set; }
/// <summary>
/// 数据处理消息,成功不返回
/// </summary>
public string Message { get; set; }
/// <summary>
/// 报错消息类型
/// </summary>
public string Category { get; set; }
/// <summary>
/// 员工账号&权限等级
/// </summary>
public MesUserInfo[] Rows { get; set; }
/// <summary>
/// 条数,统一返回1
/// </summary>
public int Total { get; set; }
}
public class MesUserInfo
{
/// <summary>
/// 员工账号
/// </summary>
public string Username { get; set; }
/// <summary>
/// 权限等级
/// </summary>
public string PermissionLevel { get; set; }
}
}