yanjinhui
2025-05-08 dce06906b2757824ad6ecfd02c1ff04ee8e9ad20
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs
@@ -13,17 +13,20 @@
using WIDESEAWCS_DTO;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using WIDESEAWCS_DTO.Telescopic;
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;
        }
@@ -53,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
                {
@@ -87,26 +93,48 @@
        {
            try
            {
                // ç¬¬ä¸€æ­¥ï¼šè‡ªåŠ¨æ¸…ç†è¿‡æœŸæ£€ä¿®çŠ¶æ€
                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();
                if (recordsToUpdate.Count > 0)
                {
                    foreach (var record in recordsToUpdate)//更新
                    {
                        record.MaintenancStartTime = null;//清空开始时间
                        record.MaintenancEendTime = null;//清空结束时间
                        record.MaintenanceStatus = 0; // Set to false
                        record.IsPossible = "NULL"; //更改状态为false不运行检修//默认为NULL
                    }
                    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"); // å…ˆç­›é€‰ IsPossible ä¸º true çš„æ•°æ®
                              .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(status!=null)
                // çŠ¶æ€å‚æ•°
                if (pagination.status.HasValue)
                {
                    query = query.Where((a, b) => b.MaintenanceStatus == pagination.status.Value);
                }
                var result = query
                    .Select((a, b) => new
@@ -118,16 +146,16 @@
                        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
                    }
                };
@@ -153,17 +181,35 @@
            try
            {
                var mon = BaseDal.QueryFirst(x => x.ID == id);
                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)