From dce06906b2757824ad6ecfd02c1ff04ee8e9ad20 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期四, 08 五月 2025 14:19:19 +0800
Subject: [PATCH] 1111

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs |  309 +++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 236 insertions(+), 73 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs"
index c4de149..0219037 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs"
@@ -4,56 +4,40 @@
 using System.Text;
 using System.Threading.Tasks;
 using AutoMapper;
+using SqlSugar;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.BaseRepository;
 using WIDESEAWCS_Core.BaseServices;
 using WIDESEAWCS_ITelescopicService;
 using WIDESEAWCS_Model.Models;
-<<<<<<< Updated upstream
-=======
 using WIDESEAWCS_DTO;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
 using WIDESEAWCS_DTO.Telescopic;
->>>>>>> Stashed changes
+using Microsoft.AspNetCore.Mvc.ModelBinding;
 
 namespace WIDESEAWCS_TelescopicService
 {
     public class MaintenanceService : ServiceBase<Dt_Maintenance, IRepository<Dt_Maintenance>>, IMaintenanceService
     {
         public IRepository<Dt_Maintenance> Repository => BaseDal;
+        public readonly IRepository<Dt_MaintenanceTeam> _team;
         private readonly IRepository<Sys_User> _user;
 
-        public MaintenanceService(IRepository<Dt_Maintenance> BaseDal, IRepository<Sys_User> user) : base(BaseDal)
+        public MaintenanceService(IRepository<Dt_Maintenance> BaseDal, IRepository<Sys_User> user, IRepository<Dt_MaintenanceTeam> team) : base(BaseDal)
         {
             _user = user;
+            _team = team;   
         }
-<<<<<<< Updated upstream
 
-        public WebResponseContent ShowMaintence()
-=======
+
         public WebResponseContent ShowMaintence(PaginationDTO pagination)
->>>>>>> Stashed changes
         {
             try
             {
-                var sys = _user.QueryData();
-                var main = BaseDal.QueryData();
+                int totalCount = 0;
+                var sys = _user.Db.Queryable<Sys_User>();
+                var main = Db.Queryable<Dt_Maintenance>();
 
-<<<<<<< Updated upstream
-                var result = sys.Join(main,
-                    u => u.UserName,
-                    m => m.UserAccount,
-                    (u, m) => new
-                    {
-                        u.UserTrueName,
-                        u.UserName,
-                        u.CardNumber,
-                        u.RoleName,
-                        u.HeadImageUrl,
-                        m.IsPossible,
-                    });
-                return new WebResponseContent { Status = true, Data = result };
-=======
                 var query = sys.InnerJoin<Dt_Maintenance>((a, b) => a.UserName == b.UserAccount);
                 if (!string.IsNullOrEmpty(pagination.searchKeyword))
                 {
@@ -72,7 +56,10 @@
                                a.CardNumber,
                                a.Userteam,
                                a.HeadImageUrl,
-                               b.IsPossible
+                               a.Dept_Id,
+                               b.IsPossible,
+                              
+                               
                            }).ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount);
                 return new WebResponseContent
                 {
@@ -85,67 +72,69 @@
                         Items = result
                     }
                 };
->>>>>>> Stashed changes
             }
             catch (Exception ex)
             {
-
-                return new WebResponseContent { Status = false, Data = ex };
+                return new WebResponseContent { Status = false, Data = ex.Message };
             }
         }
 
-<<<<<<< Updated upstream
-        public WebResponseContent PersonnelMonitoring(bool ispossible)
-=======
 
 
 
         /// <summary>
-        /// 妯$硦鏌ヨ
+        /// 浜哄憳鐩戞帶
         /// </summary>
         /// <param name="pageIndex"></param>
         /// <param name="pageSize"></param>
         /// <param name="searchKeyword"></param>
         /// <returns></returns>
         public WebResponseContent PersonnelMonitoring(PaginationDTO pagination)
->>>>>>> Stashed changes
         {
             try
             {
-                var sys = _user.QueryData();
-                var main = BaseDal.QueryData();
+                // 绗竴姝ワ細鑷姩娓呯悊杩囨湡妫�淇姸鎬�
+                var today = DateTime.Today;
+                var recordsToUpdate = Db.Queryable<Dt_Maintenance>()
+                    .Where(b => b.MaintenancStartTime != null &&
+                                b.MaintenancStartTime.Value.Date < today) // Assuming 0 is false
+                    .ToList();
 
-<<<<<<< Updated upstream
-                var result = sys.Join(main,
-                    u => u.UserName,
-                    m => m.UserAccount,
-                    (u, m) => new
+                if (recordsToUpdate.Count > 0)
+                {
+                    foreach (var record in recordsToUpdate)//鏇存柊
                     {
-                        u.UserTrueName,
-                        u.RoleName,
-                        u.HeadImageUrl,
-                        m.MaintenanceStatus,
-                        m.MaintenanceDate,
-                        m.IsPossible,
-                    }).Where(x=>x.IsPossible== ispossible);
-                return new WebResponseContent { Status = true, Data = result };
-=======
-                var query = sys.InnerJoin<Dt_Maintenance>((a, b) => a.UserName == b.UserAccount)
-                               .Where((a, b) => b.IsPossible == "true"); // 鍏堢瓫閫� IsPossible 涓� true 鐨勬暟鎹�
+                        record.MaintenancStartTime = null;//娓呯┖寮�濮嬫椂闂�
+                        record.MaintenancEendTime = null;//娓呯┖缁撴潫鏃堕棿
+                        record.MaintenanceStatus = 0; // Set to false
+                        record.IsPossible = "NULL"; //鏇存敼鐘舵�佷负false涓嶈繍琛屾淇�//榛樿涓篘ULL
+                    }
+                    Db.Updateable(recordsToUpdate).ExecuteCommand();
+                    
+                }
 
-                // 濡傛灉鎻愪緵浜嗘悳绱㈠叧閿瓧锛屽垯杩涜妯$硦鏌ヨ
+                int totalCount = 0;
+                var sys = _user.Db.Queryable<Sys_User>();
+                var main = Db.Queryable<Dt_Maintenance>();
+
+                var query = sys.InnerJoin<Dt_Maintenance>((a, b) => a.UserName == b.UserAccount)
+                              .Where((a, b) => b.IsPossible == "true"); // Filter IsPossible true first
+
+                // 鎼滅储鍏抽敭瀛�
                 if (!string.IsNullOrEmpty(pagination.searchKeyword))
                 {
                     query = query.Where((a, b) =>
-                        a.UserTrueName.Contains(pagination.searchKeyword) ||   // 鎸夌湡瀹炲鍚嶆ā绯婃悳绱�
-                        a.Userteam.Contains(pagination.searchKeyword));        // 鎸夌敤鎴风彮缁勬ā绯婃悳绱�
+                        a.UserTrueName.Contains(pagination.searchKeyword) ||
+                        a.Userteam.Contains(pagination.searchKeyword));
                 }
 
-                // 濡傛灉鎻愪緵浜� status 鍙傛暟锛屽垯鎸夌姸鎬佺瓫閫�
-                if (pagination.status.HasValue)//绛変环if锛坰tatus锛�=null锛�
+                // 鐘舵�佸弬鏁�
+                if (pagination.status.HasValue)
                 {
                     query = query.Where((a, b) => b.MaintenanceStatus == pagination.status.Value);
                 }
+
+                
 
                 var result = query
                     .Select((a, b) => new
@@ -157,35 +146,70 @@
                         b.MaintenanceDate,
                         b.IsPossible,
                     })
-                    .ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount); // 鍒嗛〉
+                    .ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount);
 
                 return new WebResponseContent
                 {
                     Status = true,
                     Data = new
                     {
-                        TotalCount = totalCount, // 鎬绘暟
-                        PageIndex = pagination.pageIndex,   // 褰撳墠椤电爜
-                        PageSize = pagination.pageSize,     // 姣忛〉鏁版嵁閲�
+                        TotalCount = totalCount,
+                        PageIndex = pagination.pageIndex,
+                        PageSize = pagination.pageSize,
                         Items = result
                     }
                 };
->>>>>>> Stashed changes
             }
             catch (Exception ex)
             {
-
-                return new WebResponseContent { Status = false, Data = ex };
+                return new WebResponseContent { Status = false, Data = ex.Message };
             }
         }
 
-        public WebResponseContent RunOperation(int id)
+
+
+
+
+        /// <summary>
+        /// 鏇存柊鐘舵�佹槸鍚﹀厑璁歌繘鍏ユ淇�
+        /// </summary>
+        /// <param name="id"></param>
+        /// <param name="ispossible"></param>
+        /// <returns></returns>
+        public WebResponseContent RunOperation(int id, string  ispossible)
         {
             try
             {
                 var mon = BaseDal.QueryFirst(x => x.ID == id);
-                mon.IsPossible = true;
-                BaseDal.UpdateData(mon);
+                if (mon==null)
+                {
+                    return new WebResponseContent { Status = false, Message = "鏃犳硶鏇存敼锛屾病鏈夋壘鍒拌鐢ㄦ埛" };
+                }
+                var sysuer = _user.QueryData(x => x.UserName == mon.UserAccount).FirstOrDefault();
+
+                if (ispossible == "true")
+                {
+                    mon.IsPossible = "true";
+                    mon.MaintenanceDate = DateTime.Now;
+                    BaseDal.UpdateData(mon);
+                    var recording = new Dt_MaintenanceTeam
+                    {
+                        OperatorName = sysuer.UserTrueName,
+                        TeamName = sysuer.RoleName,
+                        DistributionTime = DateTime.Now,
+                        Creater = "admin",
+                        CreateDate = DateTime.Now,
+                        
+                    };
+                    _team.AddData(recording);
+                }
+                else
+                {
+                    mon.IsPossible = "false";
+                    BaseDal.UpdateData(mon);
+                }
+
+
                 return new WebResponseContent { Status = true, Data = mon };
             }
             catch (Exception ex)
@@ -195,6 +219,12 @@
             }
         }
 
+
+        /// <summary>
+        /// 鏇存敼鐘舵��
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
         public WebResponseContent ChangeTasState(int id)
         {
             try
@@ -235,8 +265,6 @@
         }
 
         /// <summary>
-<<<<<<< Updated upstream
-=======
         /// 妫�淇搷浣滆褰�
         /// </summary>
         /// <param name="pageIndex">椤垫暟</param>
@@ -250,8 +278,8 @@
                 var sys = _user.Db.Queryable<Sys_User>();
                 var main = Db.Queryable<Dt_Maintenance>();
 
+                //妯$硦鏌ヨ
                 var query = sys.InnerJoin<Dt_Maintenance>((a, b) => a.UserName == b.UserAccount);
-
                 if (!string.IsNullOrEmpty(pagination.searchKeyword))
                 {
                     query = query.Where((a, b) =>
@@ -260,12 +288,33 @@
                         a.HeadImageUrl.Contains(pagination.searchKeyword)
                     );
                 }
-
+                //鏃堕棿鏌ヨ
                 if (pagination.startDate.HasValue && pagination.endDate.HasValue)
                 {
                     query = query.Where((a, b) => b.MaintenancStartTime >= pagination.startDate.Value && b.MaintenancStartTime <= pagination.endDate.Value);
                 }
+                //鎺掑簭
+                if (!string.IsNullOrEmpty(pagination.sortField))
+                {
+                    var isAcs = pagination.sortOrder?.ToLower() == "asc";
+                    query = pagination.sortField.ToLower() switch
+                    {
+                       
 
+                        "maintenancstarttime" => isAcs ? query.OrderBy((a, b) => b.MaintenancStartTime) : query.OrderByDescending((a, b) => b.MaintenancStartTime),
+
+                        "maintenancenendtime" => isAcs ? query.OrderBy((a, b) => b.MaintenancEendTime) : query.OrderByDescending((a, b) => b.MaintenancEendTime),
+
+                        _ => query.OrderByDescending((a, b) => b.Creater) // 榛樿鎸夊垱寤烘椂闂撮檷搴�
+                    };
+
+                }
+                else
+                {
+                  query=query.OrderByDescending((a, b) => b.Creater);
+                }
+
+                //杩斿洖缁撴灉
                 var result = query.Select((a, b) => new
                 {
                     a.UserTrueName,
@@ -294,10 +343,124 @@
             }
         }
 
-      
 
         /// <summary>
->>>>>>> Stashed changes
+        /// 鐪嬩粖澶╃殑妫�淇换鍔�
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public WebResponseContent MaintenanceTasksOfTheDay(string account)
+        {
+            try
+            {
+                var today = DateTime.Today;               // 浠婂ぉ鐨勯浂鐐�
+                var tomorrow = today.AddDays(1);         // 鏄庡ぉ鐨勯浂鐐�
+
+                var query = _user.Db.Queryable<Sys_User>()
+                    .InnerJoin<Dt_Maintenance>((a, b) => a.UserName == b.UserAccount)
+                    .Where((a, b) => b.IsPossible == "true" && b.UserAccount == account &&
+                    b.MaintenanceDate >= today && b.MaintenanceDate < tomorrow).Select((a, b) => new
+                    {
+                        b.ID,
+                        a.UserTrueName,
+                        a.UserName,
+                        a.CardNumber,
+                        a.Userteam,
+                        a.HeadImageUrl,
+                        b.IsPossible,
+                        b.MaintenanceDate,
+                        b.MaintenancStartTime,
+                        b.MaintenancEendTime,
+                    }).ToList();
+                if (query==null)
+                {
+                    return new WebResponseContent { Status = false, Message = "浣犱粖澶╂病鏈夋淇换鍔�" };
+                }
+                
+
+
+                return new WebResponseContent { Status=true, Data = query };
+            }
+            catch (Exception ex)
+            {
+
+                return new WebResponseContent { Status = false, Message = "閿欒淇℃伅锛�" + ex.Message };
+            }
+                    
+        }
+
+        /// <summary>
+        /// 寮�濮嬫淇�
+        /// </summary>
+        /// <param name="account"></param>
+        /// <returns></returns>
+        public WebResponseContent StartMaintenceTask(string account)
+        {
+            try
+            {
+                var today = DateTime.Today;               // 浠婂ぉ鐨勯浂鐐�
+                var tomorrow = today.AddDays(1);         // 鏄庡ぉ鐨勯浂鐐�
+
+
+                var maint = BaseDal.QueryData(x =>
+                    x.UserAccount == account &&
+                    x.IsPossible == "true" &&
+                    x.MaintenanceDate >= today &&
+                    x.MaintenanceDate < tomorrow
+                ).FirstOrDefault();
+
+                if (maint == null)
+                {
+                    return new WebResponseContent { Status = false, Message = "鏈壘鍒颁粖鏃ョ殑缁存姢浠诲姟璁板綍" };
+                }
+
+                maint.MaintenancStartTime = DateTime.Now;
+                BaseDal.UpdateData(maint);
+
+                return new WebResponseContent { Status = true, Data = maint };
+            }
+            catch (Exception ex)
+            {
+                return new WebResponseContent { Status = false, Message = "閿欒淇℃伅锛�" + ex.Message };
+            }
+        }
+
+
+        /// <summary>
+        /// 缁撴潫妫�淇�
+        /// </summary>
+        /// <param name="account"></param>
+        /// <returns></returns>
+        public WebResponseContent StopMaintenanceTask(string account)
+        {
+            try
+            {
+                var today = DateTime.Today;               // 浠婂ぉ鐨勯浂鐐�
+                var tomorrow = today.AddDays(1);         // 鏄庡ぉ鐨勯浂鐐�
+
+                var maint = BaseDal.QueryData(x => x.UserAccount == account && x.IsPossible == "true"
+                && x.MaintenanceDate >= today &&x.MaintenanceDate < tomorrow).FirstOrDefault();
+                if (maint == null)
+                {
+                    return new WebResponseContent { Status = false, Message = "鏈壘鍒板彲鐢ㄧ殑缁存姢浠诲姟璁板綍" };
+                }
+                // 淇敼鍏剁粨鏉熸椂闂�
+                maint.MaintenancEendTime = DateTime.Now;
+                maint.IsPossible = "ok";//ok灏变唬琛ㄥ畬鎴愪簡
+                BaseDal.UpdateData(maint);
+                return new WebResponseContent { Status = true, Data = maint };
+
+            }
+            catch (Exception ex)
+            {
+
+                return new WebResponseContent { Status = false, Message = "閿欒淇℃伅锛�" + ex.Message };
+            }
+        }
+
+
+
+        /// <summary>
         /// 鐘舵�佹灇涓�
         /// </summary>
         private enum Maint

--
Gitblit v1.9.3