Commit 756731fe LN

增加富士接口对接:registerNewDid

1 个父辈 36ed10ef
......@@ -154,6 +154,7 @@
</Compile>
<Compile Include="MonitorMouseKeyboard.cs" />
<Compile Include="NamedPipeClient.cs" />
<Compile Include="Nexim\NeximApiUtil.cs" />
<Compile Include="PaddleOCRHelper.cs" />
<Compile Include="PrinterHelper.cs" />
<Compile Include="PrintLabelEdit.cs" />
......
......@@ -16,6 +16,8 @@ namespace BLL
public static LightSource lightSource;
public static ServerCommunication SCMM;
public static NeximApiUtil neximApiUtils;
public static List<string> macroKey;
public static List<string> macroKeyValue;
public static List<string> extraKey=new List<string>();
......
......@@ -362,6 +362,21 @@ namespace BLL
public static MyConfig<bool> Func_UseIDCamera=true;
[MyConfigComment("隐藏软件logo")]
public static MyConfig<bool> AppUI_HideLogo=false;
/// <summary>
/// Nexim参数, 授权地址不为空时启用Nexim功能
/// </summary>
public static MyConfig<string> Nexim_AuthUrl="";
public static MyConfig<string> Nexim_UserName = "";
public static MyConfig<string> Nexim_Password = "";
public static MyConfig<string> Nexim_RegisterDidInfoUrl = "";
/// <summary>
/// Nexim参数,key=需要的参数,value=对应的关键字
/// </summary>
public static MyConfig<string[]> Nexim_ParamKeyMap = new string[] {"RI=RI","QTY=QTY","SP=SP","BATCH=BATCH","PRODATE=PRODATE" };
// 在BLLCommon.config类中添加
public string CharacterTypeKeywords
{
......
......@@ -211,6 +211,87 @@ namespace BLL
key.Add("DateTime", DateTime.Now.ToString(ConfigHelper.Config.Get("Ex_UserDataRule", "dd-MM-yyyy")));
}
}
LogNet.log.Info($"OnKeySet1");
OnKeySet(templateName, originalCode, key, hasMatch);
// 添加或替换自增ID
string reelIdKeyWord = config.ReelIDKeyWord;
if (!string.IsNullOrEmpty(config.ReelIDKeyWord) && isdisplay)
{
var Reelidstr = GetReelid();
if (key.ContainsKey(config.ReelIDKeyWord))
{
key[config.ReelIDKeyWord] = Reelidstr;
}
else
{
key.Add(config.ReelIDKeyWord, Reelidstr);
}
}
// 如果有字段更新,则再次调用OnKeySet更新WPF界面
LogNet.log.Info($"OnKeySet2");
OnKeySet(templateName, originalCode, key, hasMatch);
if (lastKeys == null && !islast && BLLCommon.config.CheckFunction)
{
lastKeys = new Dictionary<string, string>(key); // 更新 lastKey
}
//第二次刷新界面
for (int i = 0; i < extensions.Count; i++)
{
#region 如果是下拉框加载内容
if (extensions[i].Type == "ComboBox")
{
var s = extensions[i].Control as Asa.FaceControl.FaceComboBox;
s.Items.Clear();
var data = ExtraFileData.DataTitle
.Where(a => a.Contains(extensions[i].Control.Text))
.Distinct()
.OrderBy(tit => tit)
.ToArray();
s.Items.AddRange(data);
s.Text = "";
s.SelectedIndex = -1;
s.Enabled = true;
}
#endregion
extensions[i].Control.ForeColor = System.Drawing.Color.White;
if (key.ContainsKey(extensions[i].Key))
{
extensions[i].Control.Text = key[extensions[i].Key].Replace("<OCR>", "");
}
if (extensions[i].LinkName == "ischeckresult")
{
extensions[i].Control.Text = BLLCommon.extension.labelText;
}
}
//if (BLLCommon.config.CheckFunction)
//{
// if (isFirstCapture)
// {
// if (!updatereelid(key, out errmsg))
// return false;
// }
//}
//else
//{
if (!updatereelid(key, out errmsg))
{
LogNet.log.Info($"updatereelid false");
return false;
}
// }
if (extensions != null && !extensions[0].Control.InvokeRequired)
{
//使用key填充时,请处理字段开头的<OCR>字段
......@@ -305,86 +386,12 @@ namespace BLL
}
LogNet.log.Info($"OnKeySet1");
OnKeySet(templateName, originalCode, key, hasMatch);
// 添加或替换自增ID
string reelIdKeyWord = config.ReelIDKeyWord;
if (!string.IsNullOrEmpty(config.ReelIDKeyWord) && isdisplay)
{
var Reelidstr = GetReelid();
if (key.ContainsKey(config.ReelIDKeyWord))
{
key[config.ReelIDKeyWord] = Reelidstr;
}
else
{
key.Add(config.ReelIDKeyWord, Reelidstr);
}
}
// 如果有字段更新,则再次调用OnKeySet更新WPF界面
LogNet.log.Info($"OnKeySet2");
OnKeySet(templateName, originalCode, key, hasMatch);
if (lastKeys == null && !islast && BLLCommon.config.CheckFunction)
{
lastKeys = new Dictionary<string, string>(key); // 更新 lastKey
}
//第二次刷新界面
for (int i = 0; i < extensions.Count; i++)
{
#region 如果是下拉框加载内容
if (extensions[i].Type == "ComboBox")
{
var s = extensions[i].Control as Asa.FaceControl.FaceComboBox;
s.Items.Clear();
var data = ExtraFileData.DataTitle
.Where(a => a.Contains(extensions[i].Control.Text))
.Distinct()
.OrderBy(tit => tit)
.ToArray();
s.Items.AddRange(data);
s.Text = "";
s.SelectedIndex = -1;
s.Enabled = true;
}
#endregion
extensions[i].Control.ForeColor = System.Drawing.Color.White;
if (key.ContainsKey(extensions[i].Key))
{
extensions[i].Control.Text = key[extensions[i].Key].Replace("<OCR>", "");
}
if (extensions[i].LinkName == "ischeckresult")
{
extensions[i].Control.Text = BLLCommon.extension.labelText;
}
}
//if (BLLCommon.config.CheckFunction)
//{
// if (isFirstCapture)
// {
// if (!updatereelid(key, out errmsg))
// return false;
// }
//}
//else
//{
if (!updatereelid(key, out errmsg))
{
LogNet.log.Info($"updatereelid false");
return false;
}
// }
Application.DoEvents();
Application.DoEvents();
//禁用打印按钮
bool close = ConfigHelper.Config.Get("isprinclose", false);
......@@ -453,6 +460,11 @@ namespace BLL
LogNet.log.Info("ex" + ex.ToString());
}
if(!DidRegisterValidate(key, out errmsg))
{
return false;
}
//SaveRetrospect?.Invoke(key);
return true;
......@@ -460,6 +472,30 @@ namespace BLL
}
private bool DidRegisterValidate(Dictionary<string, string> content, out string errmsg)
{
errmsg = "";
try
{
if (BLLCommon.neximApiUtils.registerNewDid(content, out string msg))
{
return true;
}
else
{
errmsg = msg;
MessageboxNeo.Show("RegisterDidError", errmsg, "NEO SCAN", true);
return false;
}
}
catch (Exception ex)
{
LogNet.log.Info("DidRegisterValidate" + ex.ToString());
}
return false;
}
public void Update()
{
}
......@@ -600,7 +636,7 @@ namespace BLL
}
return reelID;
}
private void GetHttpReelID(object sender, EventArgs e)
{
updatereelid(lastkey, out _);
......@@ -832,7 +868,6 @@ namespace BLL
else
return false;
}
// 定义动态按钮点击事件处理方法
/// <summary>
/// 通过http获取数据替换关键字内容
......

using Model;
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Configuration;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
using Http = Model.Http;
namespace BLL
{
public class NeximApiUtil
{
public bool IsEnalbe()
{
//判断 Nexim_AuthUrl 是否为空
if (string.IsNullOrEmpty(Config.Nexim_AuthUrl))
{
return false;
}
return true;
}
private string OK = "ok";
private string ERROE = "error";
/**
* 获取登录的token
* @return
*/
private string getAccessToken()
{
Dictionary<string, object> paramMap = new Dictionary<string, object>();
paramMap.Add("userName", Config.Nexim_UserName);
paramMap.Add("password", Config.Nexim_Password);
//string paramStr = JsonConvert.ToString(paramMap);
//LogNet.log.Info("获取Fuji的token参数为:" + paramStr);
string apiUrl = Config.Nexim_AuthUrl;
string accessToken = "";
string result = "";
try
{
result = Model.Http.PostWithHeader(apiUrl, paramMap, new Dictionary<string, string>());
LogNet.log.Info("获取Fuji的token结果为:" + result);
Dictionary<string, object> resultObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(result);
if (resultObj != null && resultObj.ContainsKey("accessToken"))
{
accessToken = resultObj["accessToken"].ToString();
}
}
catch (Exception e)
{
LogNet.log.Info("获取Fuji的token异常:", e);
accessToken = "";
}
string status = "";
if (String.IsNullOrEmpty(accessToken))
{
status = ERROE;
}
return accessToken;
}
private string getReelInfo(Dictionary<string, string> reelData, string key)
{
string dataKey = key;
Dictionary<string, string> paramKeyM = GetParamMap();
if (paramKeyM.ContainsKey(key))
{
dataKey = paramKeyM[key];
}
if (reelData.ContainsKey(dataKey))
{
return reelData[dataKey];
}
return "";
}
private string RI = "RI";
private string PN = "PN";
private string QTY = "QTY";
private string SP = "SP";
private string BATCH = "BATCH";
private string PRODATE = "PRODATE";
private Dictionary<string, string> _paramKeyMap = null;
private Dictionary<string, string> GetParamMap()
{
if (_paramKeyMap == null)
{
_paramKeyMap = new Dictionary<string, string>();
string[] configMap = Config.Nexim_ParamKeyMap; ;
foreach (string key in configMap)
{
string[] arrys = key.Trim().Split('=');
if (arrys.Length == 2 && arrys[0] != "" && arrys[1] != "")
{
_paramKeyMap.Add(arrys[0], arrys[1]);
}
}
}
return _paramKeyMap;
}
public bool registerNewDid(Dictionary<string, string> reelData, out string msg)
{
msg = "";
if (!IsEnalbe())
{
return true;
}
Dictionary<string, string> headerMap = new Dictionary<string, string>();
string token = getAccessToken();
if (String.IsNullOrEmpty(token))
{
//获取token为空
msg = "getAccessToken fail";
LogNet.log.Info("getAccessToken fail");
return false;
}
headerMap.Add("fujiAccessToken", getAccessToken());
Dictionary<string, Object> paramsMap = new Dictionary<string, object>();
paramsMap.Add("did", getReelInfo(reelData, RI));
paramsMap.Add("partBarcode", getReelInfo(reelData, PN));
paramsMap.Add("quantity", getReelInfo(reelData, QTY));
paramsMap.Add("packageType", "paper"); //默认是paper,
paramsMap.Add("partsoutWarning", getReelInfo(reelData, QTY));
paramsMap.Add("splicingWarning", getReelInfo(reelData, QTY));
paramsMap.Add("partNumber", getReelInfo(reelData, PN));
paramsMap.Add("vendorName", getReelInfo(reelData, SP));
paramsMap.Add("lotName", getReelInfo(reelData, BATCH));
paramsMap.Add("dateCode", getReelInfo(reelData, PRODATE));
paramsMap.Add("location", "");
paramsMap.Add("memo", "");
paramsMap.Add("note1", "");
paramsMap.Add("note2", "");
paramsMap.Add("note3", "");
paramsMap.Add("note4", "");
paramsMap.Add("useSplicing", true);
paramsMap.Add("useTrayPackage", true);
paramsMap.Add("trayStackCount", 1);
paramsMap.Add("trayPickupPositionX", 1);
paramsMap.Add("trayPickupPositionY", 1);
paramsMap.Add("traySizeX", 0);
paramsMap.Add("traySizeY", 0);
//string paramStr = JSON.toJSONstring(params);
//LogNet.log.Info("注册Fuji的did参数为:" + paramStr);
string result = "";
string apiUrl = Config.Nexim_RegisterDidInfoUrl;
try
{
result = Http.PostWithHeader(apiUrl, paramsMap, headerMap);
LogNet.log.Info("注册Fuji的did结果为:" + result);
Dictionary<string, object> resultObj = JsonConvert.DeserializeObject<Dictionary<string, object>>(result);
if (resultObj != null && resultObj.ContainsKey("addedCount"))
{
int addedCount = Convert.ToInt32(resultObj["addedCount"]);
if (addedCount > 0)
{
return true;
}
}
if (resultObj != null && resultObj.ContainsKey("details"))
{
string details = resultObj["details"].ToString();
msg ="Register new did failed: "+ details;
}
else
{
msg = "Register new did failed, result is null or not contains details ";
}
}
catch (Exception e)
{
//改为英文提示
msg = "Register new did failed, exception message:" + e.ToString();
LogNet.log.Info("注册Fuji的did失败:", e);
}
return false;
}
}
}
......@@ -46,7 +46,7 @@ namespace Model
return FormatContent(s);
}
public static string Post(string url, Dictionary<string, string> param)
public static string Post(string url, Dictionary<string, string > param)
{
List<string> body = new();
foreach (string key in param.Keys)
......@@ -114,6 +114,31 @@ namespace Model
LogNet.log.Info($"[GET][URL:{url}][Return:{s}]");
return FormatContent(s);
}
public static string PostWithHeader(string url, Dictionary<string, object> param, Dictionary<string, string> headerMap)
{
List<string> body = new();
foreach (string key in param.Keys)
body.Add(string.Format("{0}={1}", key, param[key]));
LogNet.log.Info("[Post]URL:" + url + " Body:" + string.Join(",", body));
RestClient client = new(url) { Timeout = 10000 };
RestRequest request = new(Method.POST);
//增加header
if (headerMap != null && headerMap.Count > 0)
{
foreach (var head in headerMap)
{
request.AddHeader(head.Key, head.Value);
}
}
request.AddHeader("Content-Type", "application/json;charset=utf-8");
foreach (string key in param.Keys)
request.AddParameter(key, param[key]);
IRestResponse response = client.Execute(request);
string s = response.Content;
LogNet.log.Info("[Post]URL:" + url + "Return:" + s);
return FormatContent(s);
}
}
public class CustSerialize : RestSharp.Serialization.IRestSerializer
{
......
......@@ -56,6 +56,7 @@ namespace SmartScan
BLLCommon.extension = new(BLLCommon.config);
BLLCommon.labelEdit = new();
BLLCommon.mateEdit = new();
BLLCommon.neximApiUtils = new();
//如果是直接启动ns100就不需要开启条码规则服务
//WebService.Open();
ReadMacro();
......
......@@ -848,10 +848,13 @@ namespace SmartScan
LoadingScreen.Instance.Hide();
Common.frmMain.Showlogs("");
// 通过检查结果状态来判断是否需要打印
if (!a)
{
Check2s?.Invoke("NG");
}
// 检查结果是否为"等待中"/"Waiting"/"待機中",以判断是否是第一次拍照
if (BLLCommon.extension.labelText != null)
if (BLLCommon.extension.labelText != null && a)
{
string status = BLLCommon.extension.labelText;
WaitLabelRecheck = (status == "等待中" || status == "Waiting" || status == "待機中");
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!