yanjinhui
2025-03-11 cdd170dd9008d8124d63c76ba186e34cfe61a619
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using SqlSugar;
using WIDESEA_ISerialPortRepository;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_DTO.SerialPort;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_TaskInfoService
{
    public class ProcessServer : ServiceBase<Dt_Process, IProcessRepository>, IProcessServer
    { 
        
        private IUnitOfWorkManage _unitOfWorkManage;
        public ProcessServer(IProcessRepository BaseDal, IUnitOfWorkManage unitOfWorkManage) : base(BaseDal)
        {
            _unitOfWorkManage=unitOfWorkManage;
        }
 
     
 
        public WebResponseContent GetProcess(string gruop)
        {
            try
            {
                _unitOfWorkManage.BeginTran();
                var proce = BaseDal.QueryData(i => i.CraftType == gruop);
 
 
                _unitOfWorkManage.CommitTran();
                if (proce != null)
                {
                    return new WebResponseContent { Status = true, Data = proce };
                }
                else
                {
                    return new WebResponseContent{ Status = false, Message = "数据为空"};
                }
 
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return new WebResponseContent { Status = false, Message = "失败" + ex.Message };
            }
        }
 
        public WebResponseContent GetSleeveandStep(string gruops)
        {
            try
            {
                _unitOfWorkManage.BeginTran();
                var result = BaseDal.QueryData(x => x.CraftType == gruops) // 先筛选 CraftType
                    .GroupBy(x => x.CraftType) // 按 CraftType 分组
                    .Select(g => new
                    {
                       maxNodal = g.Max(a=>a.Nodal),
                        sumTorqueSum = g.Sum(a=>a.TorqueSum)
                    }).ToList();
                _unitOfWorkManage.CommitTran() ;
                return new WebResponseContent { Status = true, Data = result };
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return new WebResponseContent { Status = false, Message = "查询失败:" + ex.Message };
            }
        }
 
 
        public WebResponseContent AddProcess(AddProcessDTO addProcessDTO)
        {
            try
            {
                var proces = new Dt_Process();
                proces.Nodal=addProcessDTO.nodal;
                proces.CraftType=addProcessDTO.craftstype;
                proces.CraftsStep=addProcessDTO.craftsstep;
                proces.CraftContent=addProcessDTO.craftcontent;
                proces.TorqueSum = addProcessDTO.sleeveNum;
                proces.Tools=addProcessDTO.tools;
                _unitOfWorkManage.BeginTran() ;
                BaseDal.AddData(proces);
                _unitOfWorkManage.CommitTran();
                return new WebResponseContent { Status = true,Data=proces};
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran() ;
                return new WebResponseContent { Status = false, Message = "查询失败:" + ex.Message };
            }
        }
 
        public WebResponseContent Upprocess(PutProcessDTO addProcessDTO)
        {
            try
            {
                var proces = BaseDal.QueryData(x => x.CraftID == addProcessDTO.id).FirstOrDefault();
                    if (proces == null)
                {
                    return new WebResponseContent { Status = false,Message="没有找到"};
                }
                proces.Nodal = addProcessDTO.nodal;
                proces.CraftType = addProcessDTO.craftstype;
                proces.CraftsStep = addProcessDTO.craftsstep;
                proces.CraftContent = addProcessDTO.craftcontent;
                proces.TorqueSum = addProcessDTO.sleeveNum;
                proces.Tools = addProcessDTO.tools;
                _unitOfWorkManage.BeginTran();
                BaseDal.UpdateData(proces);
                _unitOfWorkManage.CommitTran();
                return new WebResponseContent { Status = true, Data = proces };
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return new WebResponseContent { Status = false, Message = "查询失败:" + ex.Message };
            }
        }
 
        public WebResponseContent Getcircuit(string groups)
        {
            try
            {
                List<Dt_Process> results = new List<Dt_Process>();
                int step = 1;
 
                while (true)
                {
                    // 查询当前步骤的数据
                    var circuit = BaseDal.QueryData(x => x.CraftType == groups && x.SetpNum == step)
                                         .FirstOrDefault();
 
                    // 如果查询结果为空,则停止循环
                    if (circuit == null)
                    {
                        break;
                    }
 
                    // 加入结果列表
                    results.Add(circuit);
 
                    // 递增 step,继续查询下一个步骤
                    step++;
                }
 
                return new WebResponseContent { Status = true, Data = results };
            }
            catch (Exception ex)
            {
                return new WebResponseContent { Status = false, Message = "查询失败:" + ex.Message };
            }
        }
 
       
 
    }
}