yanjinhui
2025-05-27 f1a841f056fe4d7be16f39d6fe169667f743d00a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_DTO.Telescopic;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_ITelescopicService
{
    public class MaintenanceTeamService : ServiceBase<Dt_MaintenanceTeam, IRepository<Dt_MaintenanceTeam>>, IMaintenanceTeamService
    {
        public IRepository<Dt_MaintenanceTeam> Repository => BaseDal;
        private readonly IRepository<Sys_User> _user;
 
        public MaintenanceTeamService(IRepository<Dt_MaintenanceTeam> BaseDal,IRepository<Sys_User> user) : base(BaseDal)
        {
            _user = user;
        }
 
 
        /// <summary>
        /// 检修设置记录
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WebResponseContent MaintenanceSettingRecord(PaginationDTO pagination)
        {
            try
            {
                int totalCount = 0;
 
                var sys = _user.Db.Queryable<Sys_User>();
                var main = Db.Queryable<Dt_MaintenanceTeam>();
 
 
                //模糊查询
                var query = sys.InnerJoin<Dt_MaintenanceTeam>((a, b) => a.UserTrueName == b.OperatorName);
                if (!string .IsNullOrEmpty(pagination.searchKeyword))
                {
                   
                    query = query.Where((a, b) =>
                       b.OperatorName.Contains(pagination.searchKeyword) ||
                       b.TeamName.Contains(pagination.searchKeyword) ||
                       b.Modifier.Contains(pagination.searchKeyword)
                   );
                }
                //时间查询
                if (pagination.startDate.HasValue&&pagination.endDate.HasValue)
                {
                    query = query.Where((a, b) => b.DistributionTime >= pagination.startDate && b.DistributionTime <= pagination.endDate);
                }
                //排序
                if (!string.IsNullOrEmpty(pagination.sortField))
                {
                    var isAsc = pagination.sortOrder?.ToLower() == "asc";
                    query = pagination.sortField.ToLower() switch
                    {
                        //"OperatorName" => isAsc ? query.OrderBy((a, b) => b.OperatorName) : query.OrderByDescending((a, b) => b.OperatorName),
 
                        //"TeamName" => isAsc ? query.OrderBy((a, b) => b.TeamName) : query.OrderByDescending((a, b) => b.TeamName),
 
                        "distributiontime" => isAsc ? query.OrderBy((a, b) => b.DistributionTime) : query.OrderByDescending((a, b) => b.DistributionTime),
 
                        //"Modifier" => isAsc ? query.OrderBy((a, b) => b.Modifier) : query.OrderByDescending((a, b) => b.Modifier),
 
                        _ => query.OrderByDescending((a, b) => b.Creater), // 默认按创建时间降序
                    };
 
                }
                else
                {
                    //默认按创建时间降序排序
                    query = query.OrderByDescending((a, b) => b.Creater);
                }
 
                //返回结果
                var result=query
                .Select((a, b) => new
                {
 
                    a.User_Id,
                    a.Dept_Id,//轨道站
                    a.IsLeader,//是否是班长
                    a.RoleName,
                    a.Role_Id,
                    b.IPAddress,//电脑ip地址
                    b.OperatorName,
                    b.TeamName,
                    b.Creater,
                    a.HeadImageUrl,
                    b.DistributionTime,
                    b.Modifier,
 
                }).ToPageList(pagination.pageIndex, pagination.pageSize, ref totalCount);
                return new WebResponseContent
                {
                    Status = true,
                    Data = new
                    {
                        TotalCount = totalCount,//总数
                        PageIndex = pagination.pageIndex,//页数
                        PageSize = pagination.pageSize,//一页多少个数据
                        Items = result
                    }
                };
 
            }
            catch (Exception ex)
            {
 
                return new WebResponseContent { Status = false,Message="错误信息:"+ex.Message };
            }
 
        }
 
    }
}