From 76eef0389848065963a295c66163a630697054fa Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期日, 07 七月 2024 09:47:01 +0800
Subject: [PATCH] PDA
---
代码管理/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/VV_DispatchService.cs | 171 ++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 138 insertions(+), 33 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/VV_DispatchService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/VV_DispatchService.cs"
index d1723f7..7a78eac 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/VV_DispatchService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/Services/WCS/Partial/VV_DispatchService.cs"
@@ -1,11 +1,15 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using Quartz.Impl.Matchers;
+using System.Diagnostics;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Core.Extensions;
using WIDESEA_Core.Extensions.AutofacManager;
using WIDESEA_Core.FreeDB;
+using WIDESEA_Core.ManageUser;
+using WIDESEA_Core.Services;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.IRepositories;
@@ -59,24 +63,29 @@
{
if (!scheduler.IsRun())
{
+ WIDESEA.Helper.GetToken();
+
var cooRes = CoonPLC();
var startRes = SrartScheduler();
if (startRes.Status)
{
if (cooRes.Status)
{
+ WriteDBLog.Success($"寮�鍚湇鍔�", new { 鏁版嵁 = "鏈嶅姟鍚姩鎴愬姛锛�" }, "PCS", UserContext.Current.UserName);
return webResponse.OK("鏈嶅姟鍚姩鎴愬姛锛�");
}
else
{
//杩斿洖PLC寮傚父
+ WriteDBLog.Error($"寮�鍚湇鍔�", new { 鏁版嵁 = cooRes }, "PCS", UserContext.Current.UserName);
return cooRes;
}
}
else
{
//璋冨害鍚姩澶辫触锛屽叧闂叏閮�
- WriteLog.Write_Log("鏈嶅姟", "鏈嶅姟", "鍚姩鏈嶅姟\n[璋冨害寮傚父]" + startRes.Message);
+ //WriteLog.Write_Log("鏈嶅姟", "鏈嶅姟", "鍚姩鏈嶅姟\n[璋冨害寮傚父]" + startRes.Message);
+ WriteDBLog.Error($"寮�鍚湇鍔�", new { 鏁版嵁 = startRes.Message }, "PCS", UserContext.Current.UserName);
return startRes;
}
}
@@ -87,7 +96,8 @@
}
catch (Exception ex)
{
- WriteLog.Write_Log("鏈嶅姟", "鏈嶅姟", "鍚姩鏈嶅姟\n[寮傚父]" + ex.Message);
+ //WriteLog.Write_Log("鏈嶅姟", "鏈嶅姟", "鍚姩鏈嶅姟\n[寮傚父]" + ex.Message);
+ WriteDBLog.Error($"寮�鍚湇鍔�", new { 鏁版嵁 = ex.Message }, "PCS", UserContext.Current.UserTrueName);
return webResponse.Error($"寮傚父锛寋ex.Message}");
}
}
@@ -125,7 +135,8 @@
var plcList = freeDB.Select<dt_plcinfohead>().Where("EXISTS (select * from dt_equipmentinfo where equipment_state='Enable' and equipment_name=a.plcinfo_name)").ToList();
if (plcList.Count == 0)
{
- throw new Exception("鏈厤缃换浣昉LC杩炴帴瀵硅薄锛�");
+ return content.OK();
+ //throw new Exception("鏈厤缃换浣昉LC杩炴帴瀵硅薄锛�");
}
var detialList = freeDB.Select<dt_plcinfodetail>().ToList();
@@ -140,7 +151,7 @@
PLCClient client = null;
if (plc.plcinfo_type == "Simene")
{
- client = new SiemensPLCClient()
+ client = new SiemensPLCClient(plc.plcinfo_model)
{
PLCName = plc.plcinfo_name,
Ip = plc.plcinfo_ip,
@@ -227,6 +238,9 @@
{
order.dbAddress = item.plcdetail_db + "." + item.plcdetail_value;
}
+ order.opratortype = item.plcdetail_opratortype;
+ order.dataLen = item.plcdetail_len;
+ order.Methods = item.plcdetail_number;//
itmes.Add(order);
}
return itmes;
@@ -252,10 +266,13 @@
scheduler.Shutdown();
Console.WriteLine("鏈嶅姟鍏抽棴鎴愬姛锛�");
WriteLog.Write_Log("鏈嶅姟", "鏈嶅姟", "鏈嶅姟鍏抽棴鎴愬姛!");
+ WriteDBLog.Success($"鍏抽棴鏈嶅姟", new { 鏁版嵁 = "鏈嶅姟鍏抽棴鎴愬姛锛�" }, "PCS", UserContext.Current.UserTrueName);
}
catch (Exception ex)
{
WriteLog.Write_Log("鏈嶅姟", "鏈嶅姟", "鍏抽棴鏈嶅姟\n[寮傚父]" + ex.Message);
+ WriteDBLog.Error($"鍏抽棴鏈嶅姟", new { 鏁版嵁 = ex.Message }, "PCS", UserContext.Current.UserTrueName);
+ return webResponse.Error(ex.Message);
}
return webResponse.OK("鏈嶅姟鍏抽棴鎴愬姛锛�");
}
@@ -268,28 +285,40 @@
public WebResponseContent StartJob(string jobName)
{
WebResponseContent webResponse = new WebResponseContent();
- if (!scheduler.IsRun())
+ try
{
- return webResponse.Error("璇峰厛鍚姩鏈嶅姟锛�");
- }
- var jobData = freeDB.Select<VV_Dispatch>().Where(t => t.JobName == jobName).First();
- if (jobData == null)
- {
- webResponse.Error($"璋冨害{jobName}涓嶅瓨鍦紒");
- }
- else
- {
- var job = scheduler.GetJobByJobName(jobName);
- if (job != null)
+ if (!scheduler.IsRun())
{
- webResponse.Error($"璋冨害{jobName}宸叉槸鎵ц鐘舵�侊紒");
+ throw new Exception("璇峰厛鍚姩鏈嶅姟锛�");
+ //return webResponse.Error("璇峰厛鍚姩鏈嶅姟锛�");
+ }
+ var jobData = freeDB.Select<VV_Dispatch>().Where(t => t.JobName == jobName).First();
+ if (jobData == null)
+ {
+ throw new Exception($"璋冨害{jobName}涓嶅瓨鍦紒");
+ //webResponse.Error($"璋冨害{jobName}涓嶅瓨鍦紒");
}
else
{
- scheduler.AddJob(jobData);
- webResponse.OK("璋冨害娣诲姞鎴愬姛");
+ var job = scheduler.GetJobByJobName(jobName);
+ if (job != null)
+ {
+ throw new Exception($"璋冨害{jobName}宸叉槸鎵ц鐘舵�侊紒");
+ //webResponse.Error($"璋冨害{jobName}宸叉槸鎵ц鐘舵�侊紒");
+ }
+ else
+ {
+ scheduler.AddJob(jobData);
+ webResponse.OK($"璋冨害{jobName}鎵ц鎴愬姛锛�");
+ }
}
}
+ catch (Exception ex)
+ {
+ WriteDBLog.Error($"鎵ц{jobName}璋冨害", new { 鏁版嵁 = ex.Message }, "PCS", UserContext.Current.UserTrueName);
+ return webResponse.Error(ex.Message);
+ }
+ WriteDBLog.Success($"鎵ц{jobName}璋冨害", new { 鏁版嵁 = jobName + "鎵ц鎴愬姛锛�" }, "PCS", UserContext.Current.UserTrueName);
return webResponse;
}
@@ -302,25 +331,37 @@
public WebResponseContent CloseJob(string jobName)
{
WebResponseContent webResponse = new WebResponseContent();
- if (!scheduler.IsRun())
+ try
{
- return webResponse.Error("璇峰厛鍚姩鏈嶅姟锛�");
- }
+ if (!scheduler.IsRun())
+ {
+ throw new Exception("璇峰厛鍚姩鏈嶅姟锛�");
+ //return webResponse.Error("璇峰厛鍚姩鏈嶅姟锛�");
+ }
- var job = scheduler.GetJobByJobName(jobName);
- if (job == null)
- {
- return webResponse.Error($"浠诲姟{jobName},涓嶅瓨鍦紒");
+ var job = scheduler.GetJobByJobName(jobName);
+ if (job == null)
+ {
+ throw new Exception($"浠诲姟{jobName},涓嶅瓨鍦紒");
+ //return webResponse.Error($"浠诲姟{jobName},涓嶅瓨鍦紒");
+ }
+ var res = scheduler.RemoveJob(job);
+ if (res)
+ {
+ webResponse.OK($"璋冨害{jobName}鏆傚仠鎴愬姛锛�");
+ }
+ else
+ {
+ throw new Exception($"璋冨害{jobName}鏆傚仠澶辫触锛�");
+ //webResponse.Error($"璋冨害{jobName}鍏抽棴澶辫触锛�");
+ }
}
- var res = scheduler.RemoveJob(job);
- if (res)
+ catch (Exception ex)
{
- webResponse.OK($"璋冨害{jobName}鍏抽棴鎴愬姛锛�");
+ WriteDBLog.Error($"鏆傚仠{jobName}璋冨害", new { 鏁版嵁 = ex.Message }, "PCS", UserContext.Current.UserTrueName);
+ return webResponse.Error(ex.Message);
}
- else
- {
- webResponse.Error($"璋冨害{jobName}鍏抽棴澶辫触锛�");
- }
+ WriteDBLog.Success($"鏆傚仠{jobName}璋冨害", new { 鏁版嵁 = jobName + "鏆傚仠鎴愬姛锛�" }, "PCS", UserContext.Current.UserTrueName);
return webResponse;
}
@@ -365,5 +406,69 @@
}
return data;
}
+
+ public override WebResponseContent Upload(List<IFormFile> files)
+ {
+ #region
+ WebResponseContent Response = new WebResponseContent();
+ if (files == null || files.Count == 0) return Response.Error("璇蜂笂浼犳枃浠�");
+
+ string msg = "";
+ string IP = "\\\\" + "192.168.1.35" + "\\ipc$";
+ string password = "971204";
+ string User = "dell";
+
+ int i = 0;
+ string filePath = $"\\\\192.168.1.35\\TextTest";
+ string fullPath = filePath.MapPath(true);
+ Process process = new Process();
+ try
+ {
+ process.StartInfo.FileName = "cmd.exe";
+ process.StartInfo.UseShellExecute = false;
+ process.StartInfo.RedirectStandardInput = true;
+ process.StartInfo.RedirectStandardOutput = true;
+ process.StartInfo.RedirectStandardError = true;
+ process.StartInfo.CreateNoWindow = true;
+ process.Start();
+ string dosLine = "net use " + IP + " " + password + " /user:" + User;
+ process.StandardInput.WriteLine(dosLine);
+ process.StandardInput.WriteLine("exit");
+ while (!process.HasExited)
+ {
+ process.WaitForExit(1000);
+ }
+ msg = process.StandardError.ReadToEnd();
+ process.StandardError.Close();
+ if (msg != "")
+ throw new Exception(msg);
+ if (!Directory.Exists(fullPath)) Directory.CreateDirectory(fullPath);
+ for (i = 0; i < files.Count; i++)
+ {
+ string fileName = files[i].FileName;
+ fullPath = fullPath + "/" + fileName;
+ using (var stream = new FileStream(fullPath, FileMode.Create))
+ {
+ files[i].CopyTo(stream);
+ }
+ //FileStream outFileStream = new FileStream(fullPath, FileMode.Create);
+ //files[i].CopyTo(outFileStream);
+ }
+ return Response.OK("鏂囦欢涓婁紶鎴愬姛", filePath);
+ }
+ catch (Exception ex)
+ {
+ //return Response.Error(ex.Message);
+ Logger.Error($"涓婁紶鏂囦欢澶辫触锛歿typeof(T).GetEntityTableCnName()},璺緞锛歿filePath},澶辫触鏂囦欢:{files[i]},{ex.Message + ex.StackTrace}");
+ return Response.Error("鏂囦欢涓婁紶澶辫触");
+ }
+ finally
+ {
+ process.Close();
+ process.Dispose();
+ }
+
+ #endregion
+ }
}
}
--
Gitblit v1.9.3