yanjinhui
2025-03-19 2632d69e3a6364b2d32c00a1526bc745aaa4bb58
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_ITelescopicService;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_TelescopicService
{
    public class MaintenanceService : ServiceBase<Dt_Maintenance, IRepository<Dt_Maintenance>>, IMaintenanceService
    {
        public IRepository<Dt_Maintenance> Repository => BaseDal;
        private readonly IRepository<Sys_User> _user;
 
        public MaintenanceService(IRepository<Dt_Maintenance> BaseDal, IRepository<Sys_User> user) : base(BaseDal)
        {
            _user = user;
        }
 
        public WebResponseContent ShowMaintence()
        {
            try
            {
                var sys = _user.QueryData();
                var main = BaseDal.QueryData();
 
                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 };
            }
            catch (Exception ex)
            {
 
                return new WebResponseContent { Status = false, Data = ex };
            }
        }
 
        public WebResponseContent PersonnelMonitoring(bool ispossible)
        {
            try
            {
                var sys = _user.QueryData();
                var main = BaseDal.QueryData();
 
                var result = sys.Join(main,
                    u => u.UserName,
                    m => m.UserAccount,
                    (u, m) => new
                    {
                        u.UserTrueName,
                        u.RoleName,
                        u.HeadImageUrl,
                        m.MaintenanceStatus,
                        m.MaintenanceDate,
                        m.IsPossible,
                    }).Where(x=>x.IsPossible== ispossible);
                return new WebResponseContent { Status = true, Data = result };
            }
            catch (Exception ex)
            {
 
                return new WebResponseContent { Status = false, Data = ex };
            }
        }
 
        public WebResponseContent RunOperation(int id)
        {
            try
            {
                var mon = BaseDal.QueryFirst(x => x.ID == id);
                mon.IsPossible = true;
                BaseDal.UpdateData(mon);
                return new WebResponseContent { Status = true, Data = mon };
            }
            catch (Exception ex)
            {
 
                return new WebResponseContent { Status = false, Message = "失败:" + ex };
            }
        }
 
        public WebResponseContent ChangeTasState(int id)
        {
            try
            {
                var change = BaseDal.QueryFirst(x => x.ID == id);
                //将数据库中的int 值转为 枚举型
                if (!Enum.IsDefined(typeof(Maint), change.MaintenanceStatus))
                {
                    return new WebResponseContent { Status = false, Message = "当前状态不合法,无法更新" };
                }
 
                Maint Status = (Maint)change.MaintenanceStatus; //int ->枚举
 
                switch (Status)
                {
                    case Maint.待开始:
                        change.MaintenanceStatus = (int)Maint.检修中;
                        change.MaintenancStartTime = DateTime.Now;
                        break;
                    case Maint.检修中:
                        change.MaintenanceStatus = (int)Maint.已完成;
                        break;
                    case Maint.已完成:
                        change.MaintenancEendTime = DateTime.Now;
                        return new WebResponseContent { Status = false, Message = "当前任务已完成" };
                    default:
                        return new WebResponseContent { Status = false, Message = "更新失败" };
                }
                return new WebResponseContent { Status = true, Data = change };
            }
            catch (Exception ex)
            {
 
                return new WebResponseContent { Status = false, Message = "错误:" + ex };
            }
 
 
        }
 
        /// <summary>
        /// 状态枚举
        /// </summary>
        private enum Maint
        {
            //待检修=0,
            待开始=0,
            检修中=1,
            已完成=2
 
        }
 
    }
}