yanjinhui
2025-03-12 0a430c14f3e3ceb4ba63462c4f2c92768fc79e87
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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 WIDESEA_SerialPortRepository;
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 IPutakeRepository _putakeRepository;
        private IUnitOfWorkManage _unitOfWorkManage;
        private ITorqueOpRepository _torqueOpRepository;
        public ProcessServer(IProcessRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IPutakeRepository putakeRepository, ITorqueOpRepository torqueOpRepository) : base(BaseDal)
        {
            _putakeRepository = putakeRepository;
            _unitOfWorkManage = unitOfWorkManage;
            _torqueOpRepository = torqueOpRepository;
        }
 
        public override PageGridData<Dt_Process> GetPageData(PageDataOptions options)
        {
            OrderByParameters = new Dictionary<string, OrderByType> 
            { 
                { nameof(Dt_Process.ArticleOne), OrderByType.Asc },//按什么字段排序
            };
            return base.GetPageData(options);
        }
 
        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 group, string takeid)
        {
            try
            {
                ///如果这个存值表中没有步骤一这么搞?我这么显示给前端看
              
 
                // 先查到这条任务
                var putake = _putakeRepository.QueryData(x => x.Njtakeid == takeid && x.Grouptype == group).OrderBy(x => x.Dispatchtime).FirstOrDefault();
                if (putake==null)
                {
                    return new WebResponseContent { Status = false, Message = "没有找到" };
                }
                //获取到当前完成的步骤
                var nowNum = _torqueOpRepository.QueryData(x => x.GroupOp == group && x.TakeId == takeid).Max(x => x.ProcessSte);
 
               
 
                //根据分组和步骤找到该条数据
                var process = BaseDal.QueryData(x => x.CraftType == group&&x.SetpNum== nowNum).FirstOrDefault();
 
 
                //返回当前工艺的最大步骤
                var maxproce = BaseDal.QueryData(x => x.CraftType == group).Max(x => x.SetpNum);
 
                //一共要有多少条数据(目标数量)
                int TargetCount = process.TorqueOneQuantity + process.TorqueTwoQuantity;
 
 
 
                // 查询当前步骤的 TorqueOp 记录,匹配 ProcessSte和组,任务号,检查是否达到要求(实际数量)
                int practiceCount = _torqueOpRepository.QueryData(x =>  x.GroupOp == group&&x.TakeId== takeid).Count();
 
 
 
                if (practiceCount < TargetCount)
                {
                    return new WebResponseContent { Status = false, Message = "没有完成当前步骤",Data= process };
                }
                if (maxproce== nowNum)
                {
                    return new WebResponseContent { Status = false, Message = "你完成了当前作业" };
                }
                int num = nowNum + 1;
 
                var nex = BaseDal.QueryFirst(x => x.CraftType == group && x.SetpNum == num);
 
                return new WebResponseContent { Status = true, Data = nex };
            }
            catch (Exception ex)
            {
                return new WebResponseContent { Status = false, Message = "查询失败:" + ex.Message };
            }
        }
    }
       
 
    }