From d3091b37a593885877f4ed4180d49e5ce259b657 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期一, 04 八月 2025 10:27:55 +0800
Subject: [PATCH] 优化接口
---
项目代码/后端/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs | 127 +++++++++++++++++++++++++++---------------
1 files changed, 81 insertions(+), 46 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/\345\220\216\347\253\257/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/\345\220\216\347\253\257/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs"
index 26e2834..d2cf37b 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/\345\220\216\347\253\257/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/\345\220\216\347\253\257/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs"
@@ -26,11 +26,13 @@
public IRepository<Dt_Parameters> Repository => BaseDal;
private readonly IRepository<Sys_User> _user;
private readonly IRepository<Dt_AlarmResetHsy> _alarm;
+ private readonly IRepository<Dt_CustomIPaddress> _cunstomip;
- public ParametersService(IRepository<Dt_Parameters> BaseDal, IRepository<Sys_User> user, IRepository<Dt_AlarmResetHsy> alarm) : base(BaseDal)
+ public ParametersService(IRepository<Dt_Parameters> BaseDal, IRepository<Sys_User> user, IRepository<Dt_AlarmResetHsy> alarm, IRepository<Dt_CustomIPaddress> cunstomip) : base(BaseDal)
{
_user = user;
_alarm = alarm;
+ _cunstomip = cunstomip;
}
@@ -39,21 +41,30 @@
/// </summary>
/// <param name="ExtendedState">浼�/鍑虹姸鎬�</param>
/// <returns></returns>
- public WebResponseContent automation(string ExtendedState)
+ public WebResponseContent automation(string ExtendedState, string LocalIP)
{
try
{
- //鏍规嵁int.TryParse(AppSettings.Get("DepartmentID")璇诲彇鍒板綋鍓嶆槸杞ㄩ亾鍑狅紝鎵�鏈変汉閮藉彧鑳芥搷浣滃綋鍓�
- if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+ ////鏍规嵁int.TryParse(AppSettings.Get("DepartmentID")璇诲彇鍒板綋鍓嶆槸杞ㄩ亾鍑狅紝鎵�鏈変汉閮藉彧鑳芥搷浣滃綋鍓�
+ //if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+ //{
+ // return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+ //};
+
+ //var devices = GetDevicesByDeptId(deid);
+ //鍏堟煡璇㈣澶噄p閰嶇疆琛紙Dt_CustomIPaddress锛夛紝鐪嬫槸鍚︽湁閰嶇疆锛屾病鏈夊氨鎻愮ず浠栭厤缃�
+ var customip=_cunstomip.QueryData(x=>x.IPaddress==LocalIP).FirstOrDefault();
+ if (customip == null)
{
- return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
- };
+ return new WebResponseContent { Status = false, Message = "浣犺繕娌℃湁閰嶇疆璇ヨ建閬撶珯鐨処P鍦板潃,璇峰厛閰嶇疆鍦ㄦ搷浣�" };
+ }
+ var deid = customip.StationID;
var devices = GetDevicesByDeptId(deid);
-
-
+
+
//鎵惧埌Dt_Parameters涓殑鏈�鏂颁竴鏉℃暟鎹�
var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault();
@@ -206,14 +217,16 @@
/// <param name="ExtendedState">浼�/缂╃姸鎬�</param>
/// <returns></returns>
///
- public WebResponseContent ManualOperation(string position, string ExtendedState)
+ public WebResponseContent ManualOperation(string position, string ExtendedState, string LocalIP)
{
try
{
- if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+ var customip = _cunstomip.QueryData(x => x.IPaddress == LocalIP).FirstOrDefault();
+ if (customip == null)
{
- return new WebResponseContent { Status = true, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+ return new WebResponseContent { Status = false, Message = "浣犺繕娌℃湁閰嶇疆璇ヨ建閬撶珯鐨処P鍦板潃,璇峰厛閰嶇疆鍦ㄦ搷浣�" };
}
+ var deid = customip.StationID;
var devices = GetDevicesByDeptId(deid);
//淇╀釜plc宸﹀彸鍚勪竴涓�
@@ -365,39 +378,46 @@
/// <summary>
- /// 鏍规嵁鐢ㄦ埛娣诲姞閫熷害
+ /// 鏍规嵁褰撳墠鏈烘ip鍦板潃鏉ユ坊鍔犻�熷害
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
- public WebResponseContent AddSpeed(SpeedDTO entity)
+ public WebResponseContent AddSpeed(SpeedDTO entity,string LocalIP)
{
try
{
- // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛
- var user = _user.QueryData(x => x.UserName == entity.account).FirstOrDefault();
- // 鍒ゆ柇锛氬鏋滀笉鏄鐞嗗憳 && Dept_Id 涓虹┖锛屽垯鎻愮ず閿欒
- if (user.UserName != "admin" && user.Dept_Id == null)
+ // // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛
+ // var user = _user.QueryData(x => x.UserName == entity.account).FirstOrDefault();
+ //// 鍒ゆ柇锛氬鏋滀笉鏄鐞嗗憳 && Dept_Id 涓虹┖锛屽垯鎻愮ず閿欒
+ // if (user.UserName != "admin" && user.Dept_Id == null)
+ // {
+ // return new WebResponseContent { Status = false, Message = "浣犵殑璐﹀彿娌℃湁璁剧疆杞ㄩ亾绔欏彿锛屾棤娉曟坊鍔狅紝璇疯仈绯荤鐞嗗憳" };
+ // }
+
+ //var dept = user.Dept_Id;
+
+ //// 鑾峰彇閰嶇疆鏂囦欢涓殑 DepartmentID锛堢鐞嗗憳涓撶敤锛�
+ //if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+ //{
+ // return new WebResponseContent
+ // {
+ // Status = false,
+ // Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�"
+ // };
+ //}
+
+
+ //// 鍒ゆ柇鏄惁涓虹鐞嗗憳璐﹀彿
+ //bool isAdmin = user?.UserName?.Equals("admin") == true; //濡傛灉褰撳墠鐢ㄦ埛涓嶄负绌猴紝涓旂敤鎴峰悕鏄� "admin"锛屽氨璁や负杩欎釜鐢ㄦ埛鏄鐞嗗憳
+
+ //鍘昏鍙栧搴旇澶囩殑ip鍦板潃
+ var customip = _cunstomip.QueryData(x => x.IPaddress == LocalIP).FirstOrDefault();
+ if (customip == null)
{
- return new WebResponseContent { Status = false, Message = "浣犵殑璐﹀彿娌℃湁璁剧疆杞ㄩ亾绔欏彿锛屾棤娉曟坊鍔狅紝璇疯仈绯荤鐞嗗憳" };
+ return new WebResponseContent { Status = false, Message = "浣犺繕娌℃湁閰嶇疆璇ヨ建閬撶珯鐨処P鍦板潃,璇峰厛閰嶇疆鍦ㄦ搷浣�" };
}
-
- var dept = user.Dept_Id;
+ var deid = customip.StationID;
- // 鑾峰彇閰嶇疆鏂囦欢涓殑 DepartmentID锛堢鐞嗗憳涓撶敤锛�
- if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
- {
- return new WebResponseContent
- {
- Status = false,
- Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�"
- };
- }
-
-
- // 鍒ゆ柇鏄惁涓虹鐞嗗憳璐﹀彿
- bool isAdmin = user?.UserName?.Equals("admin") == true; //濡傛灉褰撳墠鐢ㄦ埛涓嶄负绌猴紝涓旂敤鎴峰悕鏄� "admin"锛屽氨璁や负杩欎釜鐢ㄦ埛鏄鐞嗗憳
-
- // 鏍规嵁鏄惁鏄鐞嗗憳鍐冲畾浣跨敤鍝釜 Deptid
var parmet = new Dt_Parameters
{
ExtendSpeed = entity.ExtendSpeed,
@@ -405,8 +425,9 @@
ManualExtend = entity.ManualExtend,
ManualRetraction = entity.ManualRetraction,
LeftPosition = entity.LeftPosition,
- RightPosition = entity.RightPosition,
- Deptid = isAdmin ? deid : dept.GetValueOrDefault()//濡傛灉褰撳墠鐢ㄦ埛鏄鐞嗗憳锛屽氨鐢ㄩ厤缃枃浠朵腑鐨� DepartmentID锛屽惁鍒欑敤浼犲叆鐨� entity 鍙傛暟涓殑 Deptid
+ RightPosition = entity.RightPosition,
+ //Deptid = isAdmin ? deid : dept.GetValueOrDefault()//濡傛灉褰撳墠鐢ㄦ埛鏄鐞嗗憳锛屽氨鐢ㄩ厤缃枃浠朵腑鐨� DepartmentID锛屽惁鍒欑敤浼犲叆鐨� entity 鍙傛暟涓殑 Deptid
+ Deptid = deid
};
// 娣诲姞鏁版嵁
AddData(parmet);
@@ -431,16 +452,24 @@
///褰撹嚜鍔ㄤ几鍑洪渶瑕佹殏鍋滄椂锛屾殏鍋滄寜閽�
/// </summary>
/// <returns></returns>
- public WebResponseContent PauseButton()
+ public WebResponseContent PauseButton(string LocalIP)
{
try
{
- //鏍规嵁int.TryParse(AppSettings.Get("DepartmentID")璇诲彇鍒板綋鍓嶆槸杞ㄩ亾鍑狅紝鎵�鏈変汉閮藉彧鑳芥搷浣滃綋鍓�
- if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+ ////鏍规嵁int.TryParse(AppSettings.Get("DepartmentID")璇诲彇鍒板綋鍓嶆槸杞ㄩ亾鍑狅紝鎵�鏈変汉閮藉彧鑳芥搷浣滃綋鍓�
+ //if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+ //{
+ // return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+ //};
+ //var devices = GetDevicesByDeptId(deid);
+ var customip = _cunstomip.QueryData(x => x.IPaddress == LocalIP).FirstOrDefault();
+ if (customip == null)
{
- return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
- };
+ return new WebResponseContent { Status = false, Message = "浣犺繕娌℃湁閰嶇疆璇ヨ建閬撶珯鐨処P鍦板潃,璇峰厛閰嶇疆鍦ㄦ搷浣�" };
+ }
+ var deid = customip.StationID;
var devices = GetDevicesByDeptId(deid);
+
try
{
devices.Value.left.Communicator.Write<bool>("M104", true);
@@ -475,15 +504,21 @@
/// 鑾峰彇褰撳墠绋嬪簭鏈�鏂扮殑璀︽儠鏈烘瀯閫熷害
/// </summary>
/// <returns></returns>
- public WebResponseContent BackfillSpeed()
+ public WebResponseContent BackfillSpeed(string LocalIP)
{
try
{
- if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
- {
- return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+ //if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+ //{
+ // return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+ //}
+ var customip = _cunstomip.QueryData(x => x.IPaddress == LocalIP).FirstOrDefault();
+ if (customip == null)
+ {
+ return new WebResponseContent { Status = false, Message = "浣犺繕娌℃湁閰嶇疆璇ヨ建閬撶珯鐨処P鍦板潃,璇峰厛閰嶇疆鍦ㄦ搷浣�" };
}
+ var deid = customip.StationID;
var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault();
if (para == null)
{
--
Gitblit v1.9.3