1
z8018
2025-05-08 b2e04d15e8284aa23af89200075b6fd52a77477e
project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/MaintenanceService.cs
@@ -13,20 +13,30 @@
using WIDESEAWCS_DTO;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using WIDESEAWCS_DTO.Telescopic;
using SqlSugar.DistributedSystem.Snowflake;
using System.IO;
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;
        }
        /// <summary>
        /// 设置检修权限
        /// </summary>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public WebResponseContent ShowMaintence(PaginationDTO pagination)
        {
            try
@@ -110,28 +120,47 @@
        {
            try
            {
                // 第一步:自动清理过期检修状态
                var today = DateTime.Today;
                var recordsToUpdate = Db.Queryable<Dt_Maintenance>()
                    .Where(b => b.MaintenancStartTime != null &&
                                b.MaintenancStartTime.Value.Date < today  )
                    .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"); // 展示运行检修的
                // 如果提供了搜索关键字,则进行模糊查询
                // 搜索关键字
                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);
                }
                // 如果不是管理员,根据部门过滤
                // 如果不是管理员,请按部门过滤
                if (pagination.account != "admin")
                {
                    var currentUser = _user.Db.Queryable<Sys_User>()
@@ -144,7 +173,6 @@
                    }
                    int? deptId = currentUser.Dept_Id;
                    query = query.Where((a, b) => a.Dept_Id == deptId);
                }
@@ -158,16 +186,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
                    }
                };
@@ -193,11 +221,26 @@
            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
                {